|
@@ -821,7 +821,7 @@ onMounted(() => {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
getBlockIds() {
|
|
getBlockIds() {
|
|
|
- return Array.from(blockRefs.keys())
|
|
|
|
|
|
|
+ return blocks.value.map((b) => b.id)
|
|
|
},
|
|
},
|
|
|
insertText(blockId: string, text: string) {
|
|
insertText(blockId: string, text: string) {
|
|
|
const api = blockRefs.get(blockId) as any
|
|
const api = blockRefs.get(blockId) as any
|
|
@@ -893,6 +893,24 @@ onMounted(() => {
|
|
|
if (!firstApi?.view) return ""
|
|
if (!firstApi?.view) return ""
|
|
|
return (firstApi.view as EditorView).state.doc.toString()
|
|
return (firstApi.view as EditorView).state.doc.toString()
|
|
|
},
|
|
},
|
|
|
|
|
+ reorderBlocks(fromIndex: number, toIndex: number) {
|
|
|
|
|
+ if (fromIndex === toIndex) return
|
|
|
|
|
+ const moved = blocks.value[fromIndex]
|
|
|
|
|
+ if (!moved) return
|
|
|
|
|
+ blocks.value = moveBlock(blocks.value, fromIndex, toIndex)
|
|
|
|
|
+ void history.execute({
|
|
|
|
|
+ type: "move-block",
|
|
|
|
|
+ fromIndex,
|
|
|
|
|
+ toIndex,
|
|
|
|
|
+ blockId: moved.id,
|
|
|
|
|
+ content: moved.content,
|
|
|
|
|
+ depth: moved.depth,
|
|
|
|
|
+ timestamp: Date.now(),
|
|
|
|
|
+ })
|
|
|
|
|
+ canUndo.value = history.canUndo
|
|
|
|
|
+ canRedo.value = history.canRedo
|
|
|
|
|
+ onBlockContentChange()
|
|
|
|
|
+ },
|
|
|
setTimeSource(fakeMs: number) {
|
|
setTimeSource(fakeMs: number) {
|
|
|
;(window as any).__testTimeSource = fakeMs
|
|
;(window as any).__testTimeSource = fakeMs
|
|
|
},
|
|
},
|
|
@@ -938,6 +956,7 @@ defineExpose({
|
|
|
<template v-for="(block, i) in blocks" :key="block.id">
|
|
<template v-for="(block, i) in blocks" :key="block.id">
|
|
|
<EditorInsertionZone
|
|
<EditorInsertionZone
|
|
|
:ref="(el: any) => { if (el) zoneRefs.set(i, el); else zoneRefs.delete(i) }"
|
|
:ref="(el: any) => { if (el) zoneRefs.set(i, el); else zoneRefs.delete(i) }"
|
|
|
|
|
+ :zone-index="i"
|
|
|
:class="dropZoneIndex === i ? 'bg-(--ui-primary) rounded' : ''"
|
|
:class="dropZoneIndex === i ? 'bg-(--ui-primary) rounded' : ''"
|
|
|
@activate="(content: string) => onZoneActivate(i, content)"
|
|
@activate="(content: string) => onZoneActivate(i, content)"
|
|
|
@focus="onZoneFocus(i)"
|
|
@focus="onZoneFocus(i)"
|
|
@@ -1010,6 +1029,7 @@ defineExpose({
|
|
|
</template>
|
|
</template>
|
|
|
<EditorInsertionZone
|
|
<EditorInsertionZone
|
|
|
:ref="(el: any) => { if (el) zoneRefs.set(blocks.length, el); else zoneRefs.delete(blocks.length) }"
|
|
:ref="(el: any) => { if (el) zoneRefs.set(blocks.length, el); else zoneRefs.delete(blocks.length) }"
|
|
|
|
|
+ :zone-index="blocks.length"
|
|
|
:class="dropZoneIndex === blocks.length ? 'bg-(--ui-primary) rounded' : ''"
|
|
:class="dropZoneIndex === blocks.length ? 'bg-(--ui-primary) rounded' : ''"
|
|
|
@activate="(content: string) => onZoneActivate(blocks.length, content)"
|
|
@activate="(content: string) => onZoneActivate(blocks.length, content)"
|
|
|
@focus="onZoneFocus(blocks.length)"
|
|
@focus="onZoneFocus(blocks.length)"
|