- 归档 OnlyOffice live bridge、Page AI、mindmap、design governance 与相关 bug 条目 - 补齐 MinerU OCR 后端 runtime 合同与 smoke/test 基线 - 收口 ChatOnly/Doubao、ObjectIdentity、Page Aggregate compat 与 runtime owner 文档口径 验证: - cargo test --manifest-path rust/Cargo.toml -p mnote-web local_ocr -- --test-threads=1 - cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice_bridge -- --test-threads=1 - git diff --check - git diff --cached --check - codegraph index . --force && codegraph status . - codegraph sync . && codegraph status .
6.1 KiB
6.1 KiB
5-35 Office 编辑模式菜单与保护
状态
- 状态:done
目标
Office 文件默认只读打开;在正文附件三点菜单和文件树资源右键菜单中增加“使用编辑模式打开”入口。保存闭环未完成前,编辑入口必须有 guard 或明确实验标记。
原因
ONLYOFFICE mode=edit 只是编辑器初始化模式。若 MNote 没有完成 callback 写回,默认 edit 会让用户误以为修改已经保存到本地文件。
允许修改
rust/crates/mnote-web/src/ssr/pages/layout.rsrust/crates/mnote-web/src/routes/onlyoffice.rs中与 view/edit 初始化事件相关的最小补充- 相关
mnote-web单测
禁止事项
- 不默认 edit。
- 不声称 edit/save 已完整支持。
- 不改动 ACP / Hermes 无关代码。
Checklist
buildOnlyOfficeAssetOpenUrl/ local Office 默认输出mode=view。- 正文附件菜单增加“使用编辑模式打开”。
- 文件树 Office asset 菜单增加“使用编辑模式打开”。
- 编辑模式入口明确使用
mode=edit打开到主 resource tab 或新窗口,行为与现有打开目标一致。 - 在 local-folder save callback 未闭环时,编辑入口有 guard:可提示“编辑保存仍在实验中”,或通过 data/status 标记便于测试识别。
- 已存在 Office resource tab 从
mode=view切到显式mode=edit时,刷新同一 tab 的 iframe URL,而不是只激活旧 tab。 - 若启用
onRequestEditRights,必须重新初始化为 edit URL,不只 reload 当前 view。
验收
cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_tree_runtime_opens_office_assets_through_resource_shell -- --test-threads=1cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice -- --test-threads=1cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice_page -- --test-threads=1- 浏览器截图:默认打开是只读;菜单中存在编辑入口;点击编辑入口后的页面 URL / debug state 包含
mode=edit或 guard 提示。
本轮执行记录
-
2026-06-01:Codex 补齐
onRequestEditRightsP1。/onlyoffice页面新增editModeLocationHref(),触发onRequestEditRights时将当前 URL 的mode设置为edit并window.location.replace(editHref),避免只 reload 当前 view。- 新增
onlyoffice_page_reinitializes_edit_url_on_request_edit_rights契约测试,断言事件处理、debug 标记和 edit URL replacement 存在。 - 复测
task463时发现并修复普通openTarget="new-window"被forceNewWindow || forceEditMode误判成mode=edit的状态泄漏;现在只有forceEditMode才会进入 edit,普通新窗口继续默认 view //office-preview。 - 验证通过:
cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice_page -- --test-threads=1cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice -- --test-threads=1cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_tree_runtime_opens_office_assets_through_resource_shell -- --test-threads=1node --check scripts/task463-onlyoffice-resolver-smoke.jsMNOTE_UI_BASE_URL=http://127.0.0.1:3301 MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3301 node scripts/task463-onlyoffice-resolver-smoke.jsnode --check scripts/task518-onlyoffice-real-iframe-session-scope-smoke.jsMNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3301 node scripts/task518-onlyoffice-real-iframe-session-scope-smoke.js
-
2026-05-21:Reasonix worker B 卡在计划阶段后由 Codex 终止;本条实现来自其它 Reasonix 结果与 Codex 复核修正。
buildOnlyOfficeOpenUrl默认 mode 从'edit'改为'view'。buildOnlyOfficeOpenPath默认 mode 从'edit'改为'view'。buildLocalOnlyOfficeOpenUrl默认 mode 从'edit'改为'view'。normalizeOnlyOfficeAttachmentHref默认 mode 从'edit'改为'view'。detailFromEditorAttachmentLink默认 mode 从'edit'改为'view'。enhanceEditorAttachmentLink默认 mode 从'edit'改为'view'。- 正文附件菜单(
openTreeContextMenuisAttachment分支)增加菜单项{ action: 'open-edit-mode', icon: 'edit_note', label: '使用编辑模式打开' },放置于"在新窗口打开"之前。 - 文件树 asset 菜单(
isAsset分支)增加相同的open-edit-mode菜单项。 - 新增
withOfficeEditModeGuard()守卫函数:- 设置
data-mnote-last-office-edit-mode-requested="true"和data-mnote-last-office-edit-mode-guard="shown"以支持浏览器测试识别。 - 弹出
window.confirm('编辑保存仍在实验中,建议先备份文件。是否继续?')对话框,用户确认后才继续。
- 设置
handleTreeContextMenuAction中 attachment 和 isAsset 分支分别处理open-edit-mode动作,调用 guard 后再以mode=edit打开。- Codex 修正:普通“在新窗口打开”保持
mode=view;只有“使用编辑模式打开”才传入mode=edit。 - Codex 补充
sidebar_tree_runtime_opens_office_assets_through_resource_shell契约测试,覆盖默认 view、显式 edit、guard 标记和 edit URL 重写。 cargo test -p mnote-web sidebar_tree_runtime_opens_office_assets_through_resource_shell -- --test-threads=1通过。cargo test -p mnote-web onlyoffice -- --test-threads=1通过。
-
2026-05-21:Codex 浏览器复核发现并修复“已有 Office tab 切 edit 不刷新”。
- 根因:
openResourceInActiveTab()遇到已存在objectIdentity时只调用activateMainEditorTab(objectIdentity),没有更新旧 iframe 的officeUrl。 - 修复:
web_shell.rs新增refreshExistingOfficeResourceTab(),仅对entry.kind === 'office'且新旧href/officeUrl不一致时重建 passive iframe。 - 回归:
scripts/task463-onlyoffice-resolver-smoke.js新增 Test 1b,断言同一 docx tab 从mode=view刷新到mode=edit,且不会创建第二个 Office tab。 - Codex clean browser 自测通过:中文 docx 默认 view;同 tab edit 后 iframe URL
mode=edit;证据见tmp/codex-office-view-edit-plugin-2026-05-21/result.json。
- 根因: