|
@@ -1,5 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div ref="rootRef" class="group relative overflow-x-hiddenx">
|
|
|
|
|
|
+ <div id="block-base" class="group relative">
|
|
<div
|
|
<div
|
|
class="
|
|
class="
|
|
z-10
|
|
z-10
|
|
@@ -13,19 +13,17 @@
|
|
"
|
|
"
|
|
>
|
|
>
|
|
<span
|
|
<span
|
|
- :class="categories[state.blockDetails.category]?.color"
|
|
|
|
|
|
+ :class="block.category.color"
|
|
class="inline-block p-2 mr-2 rounded-lg bg-green-200"
|
|
class="inline-block p-2 mr-2 rounded-lg bg-green-200"
|
|
>
|
|
>
|
|
- <v-remixicon
|
|
|
|
- :path="icons[state.blockDetails.icon] || icons.riGlobalLine"
|
|
|
|
- />
|
|
|
|
|
|
+ <v-remixicon :path="icons[block.details.icon] || icons.riGlobalLine" />
|
|
</span>
|
|
</span>
|
|
<div style="max-width: 200px">
|
|
<div style="max-width: 200px">
|
|
<p class="font-semibold leading-none whitespace-nowrap">
|
|
<p class="font-semibold leading-none whitespace-nowrap">
|
|
- {{ state.blockDetails.name }}
|
|
|
|
|
|
+ {{ block.details.name }}
|
|
</p>
|
|
</p>
|
|
<p class="text-gray-600 text-overflow leading-tight">
|
|
<p class="text-gray-600 text-overflow leading-tight">
|
|
- {{ state.blockData.description }}
|
|
|
|
|
|
+ {{ block.data.description }}
|
|
</p>
|
|
</p>
|
|
<input
|
|
<input
|
|
type="text"
|
|
type="text"
|
|
@@ -52,10 +50,7 @@
|
|
<v-remixicon size="20" :path="icons.riPencilLine" />
|
|
<v-remixicon size="20" :path="icons.riPencilLine" />
|
|
</button>
|
|
</button>
|
|
<hr class="border-r border-gray-600 h-5 mx-3" />
|
|
<hr class="border-r border-gray-600 h-5 mx-3" />
|
|
- <button
|
|
|
|
- class="-mr-1"
|
|
|
|
- @click="editor.removeNodeId(`node-${state.blockId}`)"
|
|
|
|
- >
|
|
|
|
|
|
+ <button class="-mr-1" @click="editor.removeNodeId(`node-${block.id}`)">
|
|
<v-remixicon size="20" :path="icons.riDeleteBin7Line" />
|
|
<v-remixicon size="20" :path="icons.riDeleteBin7Line" />
|
|
</button>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
@@ -63,11 +58,10 @@
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script setup>
|
|
<script setup>
|
|
-import { ref, nextTick, reactive } from 'vue';
|
|
|
|
import { VRemixIcon as VRemixicon } from 'v-remixicon';
|
|
import { VRemixIcon as VRemixicon } from 'v-remixicon';
|
|
import emitter from 'tiny-emitter/instance';
|
|
import emitter from 'tiny-emitter/instance';
|
|
import { icons } from '@/lib/v-remixicon';
|
|
import { icons } from '@/lib/v-remixicon';
|
|
-import { tasks, categories } from '@/utils/shared';
|
|
|
|
|
|
+import { useEditorBlock } from '@/composable/editorBlock';
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
editor: {
|
|
editor: {
|
|
@@ -76,40 +70,18 @@ const props = defineProps({
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
-const rootRef = ref(null);
|
|
|
|
-const state = reactive({
|
|
|
|
- blockId: '',
|
|
|
|
- blockDetails: {},
|
|
|
|
- blockData: {},
|
|
|
|
-});
|
|
|
|
|
|
+const block = useEditorBlock('#block-base', props.editor);
|
|
|
|
|
|
function editBlock() {
|
|
function editBlock() {
|
|
emitter.emit('editor:edit-block', {
|
|
emitter.emit('editor:edit-block', {
|
|
- ...state.blockDetails,
|
|
|
|
- data: state.blockData,
|
|
|
|
- blockId: state.blockId,
|
|
|
|
|
|
+ ...block.details,
|
|
|
|
+ data: block.data,
|
|
|
|
+ blockId: block.id,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
function handleDataChange() {
|
|
function handleDataChange() {
|
|
- const { data } = props.editor.getNodeFromId(state.blockId);
|
|
|
|
|
|
+ const { data } = props.editor.getNodeFromId(block.id);
|
|
|
|
|
|
- state.blockData = data;
|
|
|
|
|
|
+ block.data = data;
|
|
}
|
|
}
|
|
-
|
|
|
|
-nextTick(() => {
|
|
|
|
- if (state.blockId) return;
|
|
|
|
-
|
|
|
|
- state.blockId = rootRef.value?.parentElement.parentElement.id.replace(
|
|
|
|
- 'node-',
|
|
|
|
- ''
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- if (state.blockId) {
|
|
|
|
- const { name, data } = props.editor.getNodeFromId(state.blockId);
|
|
|
|
- const details = tasks[name];
|
|
|
|
-
|
|
|
|
- state.blockDetails = { id: name, ...details };
|
|
|
|
- state.blockData = data || details.data;
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
</script>
|
|
</script>
|