refactor: externalize filetree runtime helpers
This commit is contained in:
@@ -537,6 +537,60 @@ Reasonix read-only audit:
|
||||
- `type="module"` 自带作用域,`tree-shell-runtime.js` 已移除外层 IIFE,并只 hoist P3 关键函数;其他 DOM runtime 仍按原局部闭包组织,避免扩大改动。
|
||||
- debug tree shell runtime 与主壳 `SIDEBAR_TREE_JS` 仍是两套 runtime,后续 P4/P5 继续拆主壳 filetree runtime 和 document pane host adapter。
|
||||
|
||||
### 9.7 Batch 6 执行记录(2026-05-25)
|
||||
|
||||
Reasonix read-only audit:
|
||||
|
||||
- run id: `reasonix-2026-05-24T16-11-49-842Z-94562749`
|
||||
- worktree: `/mnt/Data1T/mnote-worktrees/p4-filetree-audit`
|
||||
- handoff: `/home/lix/.codex/runtime/reasonix-coding-worker/reasonix-2026-05-24T16-11-49-842Z-94562749/process-handoff.md`
|
||||
- 类型:只读审计,主控已读取 Hindsight recall、`process-handoff.md`、工作区 diff 与验证结果。
|
||||
- 采纳结论:主壳 filetree 第一批应优先迁纯 DOM/字符串读取 helper、path 解析和下载详情构造;DND、paste、菜单 DOM、上传执行链继续留在后续批次。
|
||||
|
||||
采纳内容:
|
||||
|
||||
- 新增 `rust/crates/mnote-web/browser/filetree-runtime.js`。
|
||||
- 新增固定 asset route:`GET /api/mnote-browser-runtime/filetree-runtime.js`。
|
||||
- `PageLayout` 在 `SIDEBAR_TREE_JS` 前注入 `type="module"` 外置脚本。
|
||||
- `SIDEBAR_TREE_JS` 中以下 helper 先做 runtime 代理,保留原实现 fallback:
|
||||
- `fileTreeRowDocumentId`
|
||||
- `fileTreeRowAssetId`
|
||||
- `decodeLocalEncodedPath`
|
||||
- `fileTreeRowLocalRelativePath`
|
||||
- `fileTreeRowLocalUploadTargetRelativePath`
|
||||
- `fileTreeRowKind`
|
||||
- `isFileTreeDownloadableAssetRow`
|
||||
- `isFileTreeDownloadableRow`
|
||||
- `fileTreeAssetDownloadDetail`
|
||||
- `fileTreeRowsByRowIds`
|
||||
- `fileTreeChildCount`
|
||||
- 新增 `rust/crates/mnote-web/browser/filetree-context-menu-runtime.js`,先承接 `buildSidebarFileTreeContext` 与 `evaluateSidebarFileTreeWhen` 的 CommandContext / when 表达式求值;菜单 DOM 构建仍留在 `SIDEBAR_TREE_JS`。
|
||||
|
||||
采纳边界:
|
||||
|
||||
- 本批次不迁移 `selectFileTreeRow`、`openFileTreeContextMenu`、`pasteSidebarFileTreeClipboard`、`downloadSelectedFileTreeAssetRows`、内部/外部 DND、上传执行链。
|
||||
- `fileTreeChildCount` 虽与 paste sortOrder 有关,但本批仅做同构 runtime 代理并保留 inline fallback,未改变 paste 命令语义。
|
||||
- filetree context menu 本批只迁 CommandContext/when evaluator,不迁 menu item DOM、事件绑定或右键定位逻辑。
|
||||
|
||||
已通过验证:
|
||||
|
||||
- `node --check rust/crates/mnote-web/browser/filetree-runtime.js`
|
||||
- `node --check rust/crates/mnote-web/browser/filetree-context-menu-runtime.js`
|
||||
- `cargo fmt --manifest-path rust/Cargo.toml --all --check`
|
||||
- `cargo check --manifest-path rust/Cargo.toml -p mnote-web`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web filetree_runtime -- --test-threads=1`
|
||||
- 结果:9 个相关测试通过。
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web filetree_context_menu -- --test-threads=1`
|
||||
- 结果:2 个相关测试通过。
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web mnote_browser_runtime_assets_are_explicitly_mounted -- --test-threads=1`
|
||||
- 结果:runtime asset route 测试通过。
|
||||
- 真实浏览器轻量验收:
|
||||
- dev server: `npm run dev:hot`
|
||||
- 登录后访问 `http://127.0.0.1:3000/`
|
||||
- `document.scripts` 包含 `/api/mnote-browser-runtime/filetree-runtime.js` 与 `/api/mnote-browser-runtime/filetree-context-menu-runtime.js`
|
||||
- `window.__mnoteFileTreeRuntime.fileTreeRowLocalRelativePath` 和 `window.__mnoteFileTreeContextMenuRuntime.evaluateSidebarFileTreeWhen` 均为函数。
|
||||
- 两个 runtime asset 均返回 `200`,`content-type=application/javascript; charset=utf-8`。
|
||||
|
||||
## 10. 分阶段执行清单
|
||||
|
||||
### P0:定位辅助与基线保护
|
||||
@@ -600,7 +654,9 @@ Reasonix read-only audit:
|
||||
### P4:抽出主壳 filetree runtime
|
||||
|
||||
- [ ] 从 `SIDEBAR_TREE_JS` 中拆出文件树选择、keyboard、clipboard、DND、context menu。
|
||||
- [ ] 先拆纯函数和 reducer bridge,再拆 DOM 绑定。
|
||||
- [x] 先拆纯函数和 reducer bridge,再拆 DOM 绑定。
|
||||
- 2026-05-25 / Batch 6 已迁:filetree 行 accessor、local relative path、download detail、row lookup、child count wrapper,以及 context menu CommandContext / when evaluator。
|
||||
- 暂不迁:selection、keyboard、clipboard、DND、菜单 DOM、上传执行链。
|
||||
- [ ] 主壳保留 `window.__mnoteSidebarTreeRuntimeStarted` 一类启动防重保护,但启动函数迁到外置模块。
|
||||
- [ ] 与 Rust `FileTreeSelectionState` 合同对齐,不在前端新增第二套选择真相。
|
||||
- [ ] 覆盖:
|
||||
|
||||
Reference in New Issue
Block a user