Quellcode durchsuchen

feat(editor): expose getHistoryState and applyHistory on Editor shell

- Add getHistoryState() to defineExpose returning { canUndo, canRedo }
- Add applyHistory(op) to push arbitrary EditorOperation into history
  stack, enabling external orchestration from Tauri or collab systems
Zander Hawke vor 3 Tagen
Ursprung
Commit
2b1a85c336
2 geänderte Dateien mit 31 neuen und 2 gelöschten Zeilen
  1. 16 1
      packages/editor/README.md
  2. 15 1
      packages/editor/src/components/Editor.vue

+ 16 - 1
packages/editor/README.md

@@ -126,10 +126,25 @@ The editor forwards a `#toolbar` slot with bindings from the focused block:
 ### Exposed methods
 
 ```ts
-const editorRef = ref<{ undo: () => void; redo: () => void; canUndo: Ref<boolean>; canRedo: Ref<boolean> }>()
+const editorRef = ref<{
+  undo: () => void
+  redo: () => void
+  canUndo: Ref<boolean>
+  canRedo: Ref<boolean>
+  getHistoryState: () => { canUndo: boolean; canRedo: boolean }
+  applyHistory: (op: EditorOperation) => void
+}>()
 
 editorRef.value?.undo()
 editorRef.value?.redo()
+editorRef.value?.getHistoryState()           // inspect undo/redo availability
+editorRef.value?.applyHistory({              // push an operation into the history stack
+  type: "set-block-content",
+  blockId: "abc",
+  previousContent: "old",
+  newContent: "new",
+  timestamp: Date.now(),
+})
 ```
 
 ## Architecture

+ 15 - 1
packages/editor/src/components/Editor.vue

@@ -688,7 +688,21 @@ function onZoneActivate(index: number, content: string) {
   }
 }
 
-defineExpose({ undo, redo, canUndo, canRedo })
+defineExpose({
+  undo,
+  redo,
+  canUndo,
+  canRedo,
+  getHistoryState: () => ({
+    canUndo: history.canUndo,
+    canRedo: history.canRedo,
+  }),
+  applyHistory: (op: EditorOperation) => {
+    history.execute(op)
+    canUndo.value = history.canUndo
+    canRedo.value = history.canRedo
+  },
+})
 </script>
 
 <template>