diff --git a/resources/js/components/form/Editor.vue b/resources/js/components/form/Editor.vue index 1862299b..a7726451 100644 --- a/resources/js/components/form/Editor.vue +++ b/resources/js/components/form/Editor.vue @@ -1,12 +1,25 @@ @@ -39,6 +52,11 @@ const props = defineProps({ id: { required: true, }, + conditions: { + required: false, + type: Boolean, + default: () => false, + }, hint: { default: null, }, @@ -54,51 +72,140 @@ const props = defineProps({ }); const editor = ref(null); +const condition = ref(null); + +async function openPopup(conditions) { + return new Promise((resolve, reject) => { + new Promise((innerResolve, innerReject) => { + condition.value = { + resolve: innerResolve, + reject: innerReject, + data: conditions, + }; + }).then((data) => { + resolve(data); + condition.value = null; + }); + }); +} + +class ConditionTune { + constructor({api, data, config, block}) { + this.api = api; + this.data = data || { + conditions: [], + }; + this.config = config; + this.block = block; + this.wrapper = null; + } + + static get isTune() { + return true; + } + + wrap(blockContent) { + this.wrapper = document.createElement('div'); + this.wrapper.appendChild(blockContent); + this.styleWrapper(); + return this.wrapper; + } + + styleWrapper() { + if (this.data.conditions.length > 0) { + this.wrapper.className = 'relative mt-6 mb-6 p-1 border border-blue-200 rounded'; + if (!this.wrapper.querySelector('.condition-description')) { + var tooltip = document.createElement('div'); + tooltip.className = 'condition-description absolute top-0 left-0 -mt-4 ml-1 h-4 flex px-2 items-center text-xs leading-none bg-blue-200 text-blue-900 rounded-t-lg'; + tooltip.innerHTML = 'Bedingung'; + this.wrapper.appendChild(tooltip); + } + } else { + this.wrapper.className = ''; + if (this.wrapper.querySelector('.condition-description')) { + this.wrapper.removeChild(this.wrapper.querySelector('.condition-description')); + } + } + } + + render() { + return { + label: 'Bedingungen', + closeOnActivate: true, + toggle: true, + onActivate: async () => { + this.data.conditions = await openPopup(this.data.conditions); + this.styleWrapper(); + this.block.dispatchChange(); + }, + }; + } + + save() { + return this.data; + } +} onMounted(async () => { + var tools = { + paragraph: { + class: Paragraph, + shortcut: 'CTRL+P', + inlineToolbar: true, + config: { + preserveBlank: true, + placeholder: 'Absatz', + }, + }, + alert: { + class: Alert, + inlineToolbar: true, + config: { + defaultType: 'primary', + }, + }, + heading: { + class: Header, + shortcut: 'CTRL+H', + inlineToolbar: true, + config: { + placeholder: 'Überschrift', + levels: [2, 3, 4], + defaultLevel: 2, + }, + }, + list: { + class: NestedList, + shortcut: 'CTRL+L', + inlineToolbar: true, + }, + }; + + var tunes = []; + + if (props.conditions) { + tools.condition = { + class: ConditionTune, + }; + tunes.push('condition'); + } + editor.value = new EditorJS({ placeholder: props.placeholder, holder: props.id, minHeight: 0, defaultBlock: 'paragraph', data: JSON.parse(JSON.stringify(props.modelValue)), - tools: { - paragraph: { - class: Paragraph, - shortcut: 'CTRL+P', - inlineToolbar: true, - config: { - preserveBlank: true, - placeholder: 'Absatz', - }, - }, - alert: { - class: Alert, - inlineToolbar: true, - config: { - defaultType: 'primary', - }, - }, - heading: { - class: Header, - shortcut: 'CTRL+H', - inlineToolbar: true, - config: { - placeholder: 'Überschrift', - levels: [2, 3, 4], - defaultLevel: 2, - }, - }, - list: { - class: NestedList, - shortcut: 'CTRL+L', - inlineToolbar: true, - }, - }, + tunes: tunes, + tools: tools, onChange: debounce(async (api, event) => { const data = await editor.value.save(); + console.log(data); emit('update:modelValue', data); }, 500), + onPopup: () => { + console.log('opened'); + }, }); await editor.value.isReady; console.log('Editor is ready'); diff --git a/resources/js/views/form/FileSettings.vue b/resources/js/views/form/Conditions.vue similarity index 90% rename from resources/js/views/form/FileSettings.vue rename to resources/js/views/form/Conditions.vue index 7aedf035..00d3d12a 100644 --- a/resources/js/views/form/FileSettings.vue +++ b/resources/js/views/form/Conditions.vue @@ -5,7 +5,6 @@
-
Datei: {{ value.name }}
Bedingung einfügen
@@ -44,7 +43,7 @@