refactor: extract editor command persistence runtime

This commit is contained in:
lix-2026
2026-05-24 23:12:29 +08:00
parent 0a03572601
commit b4c74bbb81
7 changed files with 282 additions and 198 deletions
@@ -120,13 +120,16 @@ rust/spikes/leptos-tiptap-spike/src/
### P2:抽出 command sync / persistence
- [ ] 新增 `editor_runtime/command_sync.rs`
- [ ] 迁出:
- [x] 新增 `editor_runtime/command_sync.rs`
- [x] 新增 `editor_runtime/persistence.rs`
- [x] 迁出:
- `read_editor_snapshot`
- `sync_editor_outputs`
- `sync_persisted_editor_command`
- change/status event dispatch 的编辑器侧包装
- [ ] 明确 `set_content` 只允许用于:
- `apply_document_update`(当前保持零调用者现状)
- [ ] 迁出 change/status event dispatch 的编辑器侧包装。
- 2026-05-24 复核:`apply_html_update` 仍依赖 `ChangePayload` / `ChangeMetaPayload``dispatch_change_event``dispatch_runtime_state``HoveredBlockState` 和 toolbar overlay state,暂留 `lib.rs`,等待 P4 `bridge_events.rs` / `overlays.rs` 后再迁。
- [x] 明确 `set_content` 只允许用于:
- 初始加载
- host 替换文档
- 外部同步/恢复
@@ -193,6 +196,8 @@ rust/spikes/leptos-tiptap-spike/src/
允许读取/修改:
- rust/spikes/leptos-tiptap-spike/src/editor_runtime/attachment_links.rs
- rust/spikes/leptos-tiptap-spike/src/editor_runtime/history_safe_commands.rs
- rust/spikes/leptos-tiptap-spike/src/editor_runtime/command_sync.rs
- rust/spikes/leptos-tiptap-spike/src/editor_runtime/persistence.rs
- scripts/task488-local-attachment-link-delete-undo-smoke.js
禁止:
@@ -290,6 +295,12 @@ Codex 主控复核修正:
- `cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`35 个既有 warning
- `cargo build --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml --target wasm32-unknown-unknown --release`
- `wasm-bindgen rust/spikes/leptos-tiptap-spike/target/wasm32-unknown-unknown/release/mnote_leptos_tiptap_spike.wasm --target web --out-dir rust/spikes/leptos-tiptap-spike/generated/island --out-name mnote-leptos-tiptap-spike-island`
- `node scripts/task488-local-attachment-link-delete-undo-smoke.js`
- 结果:`ok=true`
- 证据:`tmp/task488-local-attachment-link-delete-undo-smoke/result.json`
- `node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
- 结果:`ok=true`
- 证据:命令 stdout JSON,覆盖 `editor-upload-to-page-resource-dir``filetree-folder-drop-to-target``broken-link-after-real-file-delete``direct-attach-open-without-active-md``editor-delete-one-attachment-preserves-adjacent` 等检查。
- `node scripts/task488-local-attachment-link-delete-undo-smoke.js`
- 结果:`ok=true`
- 步骤:`uploaded -> selected -> deleted -> undo -> redo`
@@ -301,6 +312,41 @@ Codex 主控复核修正:
- 结果:索引 318 个文件,状态 up to date。
- 复核:`delete_selected_attachment_link_with_history``selected_local_attachment_link_text``is_local_attachment_link_selected` 均可通过 CodeGraph 搜索定位到 `editor_runtime/*`
### 10.3 Batch 2 执行记录(2026-05-24
Reasonix read-only audit
- run id: `reasonix-2026-05-24T15-01-33-138Z-dc32246a`
- worker worktree: `/mnt/Data1T/mnote-wt-5-28-command-sync-b2`
- handoff: `/home/lix/.codex/runtime/reasonix-coding-worker/reasonix-2026-05-24T15-01-33-138Z-dc32246a/process-handoff.md`
- 类型:只读审计,主控已读取 Hindsight recall、`process-handoff.md``process-handoff.json`
采纳内容:
- 新增 `editor_runtime/command_sync.rs`,迁出 `read_editor_snapshot``sync_editor_outputs``sync_persisted_editor_command`
- 新增 `editor_runtime/persistence.rs`,迁出 `PersistedSpikeDocument``PersistedDocumentIdentity`、identity normalization、storage key、localStorage load/persist。
- `apply_document_update` 迁入 `command_sync.rs`,保持迁移前零调用者现状。
- `apply_html_update` 暂留 `lib.rs`:它仍强依赖 host change/status event、`HoveredBlockState` 和 toolbar overlay state;后续等 `bridge_events.rs` / `overlays.rs` 拆出后再迁。
Codex 主控复核:
- `persist_document_state` 的 payload、storage key、`localStorage` 写入错误文案保持不变。
- `sync_persisted_editor_command` 现在委托 `persist_current_editor_snapshot(...)`dirty count、自身快照读取、HTML/JSON output 更新和反馈文案顺序保持不变。
- `normalize_identity_value` 改为 `pub(crate)`,用于 mindmap draft identity`persisted_document_storage_key` 只在 `#[cfg(test)]` 下导入。
已通过验证:
- `cargo fmt --manifest-path rust/Cargo.toml --all --check`
- `cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`35 个既有 warning
- `cargo build --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml --target wasm32-unknown-unknown --release`35 个既有 warning
- `wasm-bindgen rust/spikes/leptos-tiptap-spike/target/wasm32-unknown-unknown/release/mnote_leptos_tiptap_spike.wasm --target web --out-dir rust/spikes/leptos-tiptap-spike/generated/island --out-name mnote-leptos-tiptap-spike-island`
受阻验证:
- `cargo test --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml persisted_document_storage_key_isolated_per_document_identity`
- `cargo test --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml standalone_mindmap_object_uses_isolated_draft_identity`
- 阻塞原因:lib test 编译阶段命中既有 `slash_menu_css_uses_viewport_overlay_layer``STYLE` 未定义;HEAD 中该测试已引用 `STYLE`,而实际常量名为 `SPIKE_STYLE`。该问题不属于本批拆分,已记录为后续单独处理。
## 11. 测试与验收
### Rust 检查