sage-mem 2.10.1 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +29 -8
- package/README.md +29 -8
- package/lib/autodream/audit.js +2 -2
- package/lib/autodream/prompt.js +5 -4
- package/lib/autodream/report.js +2 -2
- package/lib/autodream/size-tools.js +1 -1
- package/lib/client.js +1127 -0
- package/lib/index.js +9 -4
- package/lib/memory/experimental.js +11 -2
- package/lib/memory/size-policy.js +5 -5
- package/lib/memory/write-protocol.js +2 -2
- package/lib/shared/limits.js +22 -2
- package/lib/typert.host.js +4 -4
- package/package.json +1 -1
- package/skills/sage-mem/SKILL.md +15 -3
package/lib/client.js
CHANGED
|
@@ -2796,6 +2796,55 @@ const StarmapRuntime = (function (require, _react) {
|
|
|
2796
2796
|
".smem-conf-label{font-size:11.5px;font-weight:600;color:var(--dsw-alias-label-secondary);}",
|
|
2797
2797
|
".smem-conf-pre{margin:0;max-height:220px;overflow:auto;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--dsw-alias-label-primary);}",
|
|
2798
2798
|
".smem-conf-warn{font-size:11.5px;color:var(--dsw-alias-state-warn-primary,#d97706);}",
|
|
2799
|
+
|
|
2800
|
+
// ── 2.11.0 待办清单看板(右侧栏页签)──────────────────────────
|
|
2801
|
+
// 宿主把页签正文放进一个 `overflow:hidden` 的固定高度盒子里(实测 797px),
|
|
2802
|
+
// 正文自己不设高度就会长到内容高(1924px)然后被裁掉 —— 手指够不到下面。
|
|
2803
|
+
// 所以根节点必须**自己吃满高度并滚**,不能指望宿主代滚。
|
|
2804
|
+
".smem-todo{height:100%;max-height:100%;min-height:0;flex:1 1 auto;box-sizing:border-box;overflow-y:auto;overflow-x:hidden;display:flex;flex-direction:column;gap:8px;padding:0 10px 12px;font-size:12.5px;line-height:1.55;color:var(--dsw-alias-label-primary);}",
|
|
2805
|
+
// 顶部统计条吸顶:滚到第 20 条时仍然知道总数。
|
|
2806
|
+
".smem-todo-head{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:11.5px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-l1);backdrop-filter:blur(8px);padding:10px 0 8px;border-bottom:1px solid var(--dsw-alias-border-l1);}",
|
|
2807
|
+
".smem-todo-stat{font-variant-numeric:tabular-nums;}",
|
|
2808
|
+
".smem-todo-head > span[data-spring]{flex:1;}",
|
|
2809
|
+
".smem-todo-mini{font-size:11.5px;background:none;border:0;padding:0;cursor:pointer;color:var(--dsw-alias-brand-primary,#3b82f6);}",
|
|
2810
|
+
".smem-todo-mini:disabled{opacity:.45;cursor:default;}",
|
|
2811
|
+
".smem-todo-groups{display:flex;flex-direction:column;gap:10px;}",
|
|
2812
|
+
".smem-todo-search-row{display:flex;align-items:center;gap:8px;padding:0 0 2px;}",
|
|
2813
|
+
".smem-todo-search{flex:1;min-width:0;font-size:12px;}",
|
|
2814
|
+
".smem-todo-group{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:8px 9px;display:flex;flex-direction:column;gap:6px;flex:0 0 auto;}",
|
|
2815
|
+
// 待删除块整块走红色系:它是**队列**不是结论,看得见的红提醒「这些该搬走了」。
|
|
2816
|
+
".smem-todo-group-done{border-color:var(--dsw-alias-state-danger-primary,#ef4444);}",
|
|
2817
|
+
".smem-todo-group-done .smem-todo-group-title{color:var(--dsw-alias-state-danger-primary,#ef4444);}",
|
|
2818
|
+
// 2.11.1:标题行改成「行」—— 右侧要放「清空全部」,按钮不能套按钮。
|
|
2819
|
+
".smem-todo-group-head{display:flex;align-items:center;gap:6px;width:100%;min-width:0;}",
|
|
2820
|
+
".smem-todo-group-toggle{flex:1;min-width:0;display:flex;align-items:center;gap:6px;background:none;border:0;padding:0;cursor:pointer;color:inherit;text-align:left;}",
|
|
2821
|
+
".smem-todo-del{color:var(--dsw-alias-state-danger-primary,#ef4444);}",
|
|
2822
|
+
".smem-todo-chev{color:var(--dsw-alias-label-secondary);font-size:10px;width:10px;}",
|
|
2823
|
+
".smem-todo-group-title{font-weight:600;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}",
|
|
2824
|
+
".smem-todo-count{font-size:11px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary);}",
|
|
2825
|
+
// 顶部统计条右侧的图标按钮(撤销 / 重做):无边框、跟文字同色、栈空时半透明。
|
|
2826
|
+
".smem-todo-icon-btn{display:inline-flex;align-items:center;justify-content:center;width:22px;height:20px;padding:0;border:0;border-radius:6px;background:none;color:currentColor;cursor:pointer;}",
|
|
2827
|
+
".smem-todo-icon-btn:hover:not(:disabled){background:var(--dsw-alias-bg-l2);}",
|
|
2828
|
+
".smem-todo-icon-btn:disabled{opacity:.35;cursor:default;}",
|
|
2829
|
+
".smem-todo-list{display:flex;flex-direction:column;gap:6px;}",
|
|
2830
|
+
".smem-todo-item{display:flex;gap:8px;align-items:flex-start;border-radius:8px;padding:4px 2px;}",
|
|
2831
|
+
".smem-todo-item:hover{background:var(--dsw-alias-bg-l2);}",
|
|
2832
|
+
".smem-todo-box{flex:0 0 auto;width:16px;height:16px;margin-top:1px;border-radius:5px;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:transparent;font-size:11px;line-height:1;display:flex;align-items:center;justify-content:center;cursor:pointer;padding:0;}",
|
|
2833
|
+
".smem-todo-box-on{background:var(--dsw-alias-brand-primary,#3b82f6);border-color:transparent;color:#fff;}",
|
|
2834
|
+
".smem-todo-body{min-width:0;flex:1;display:flex;flex-direction:column;gap:2px;}",
|
|
2835
|
+
".smem-todo-title{font-weight:600;overflow-wrap:anywhere;}",
|
|
2836
|
+
".smem-todo-text{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;white-space:pre-wrap;}",
|
|
2837
|
+
".smem-todo-ref{border-radius:4px;padding:0 3px;background:var(--dsw-alias-bg-l2);color:var(--dsw-alias-label-secondary);font-size:11.5px;}",
|
|
2838
|
+
".smem-todo-code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;border-radius:4px;padding:0 3px;background:var(--dsw-alias-bg-l2);}",
|
|
2839
|
+
".smem-todo-item-done .smem-todo-title{text-decoration:line-through;opacity:.6;}",
|
|
2840
|
+
".smem-todo-item-done .smem-todo-text{opacity:.6;}",
|
|
2841
|
+
".smem-todo-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;}",
|
|
2842
|
+
".smem-todo-edit{width:100%;resize:vertical;font-size:12px;}",
|
|
2843
|
+
".smem-todo-add{padding-top:2px;}",
|
|
2844
|
+
".smem-todo-add-input{width:100%;font-size:12px;}",
|
|
2845
|
+
".smem-todo-empty{font-size:11.5px;color:var(--dsw-alias-label-secondary);padding:4px 0;}",
|
|
2846
|
+
".smem-todo-done-state{display:flex;flex-direction:column;gap:6px;padding:16px 12px;}",
|
|
2847
|
+
".smem-todo-done-title{font-weight:600;}",
|
|
2799
2848
|
].join("\n");
|
|
2800
2849
|
|
|
2801
2850
|
/**
|
|
@@ -4672,6 +4721,61 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
4672
4721
|
"prompt.copyFailedTitle": "复制没成功 —— 手动复制这段提示词",
|
|
4673
4722
|
"prompt.copyFailedHint": "点一下文本框全选,再按 Ctrl+C 复制",
|
|
4674
4723
|
"prompt.close": "关闭",
|
|
4724
|
+
|
|
4725
|
+
// ── 2.11.0 待办清单看板(右侧栏页签 + 实验性页那张卡)──
|
|
4726
|
+
"todo.tabTitle": "待办清单",
|
|
4727
|
+
"todo.guide.title": "待办清单",
|
|
4728
|
+
"todo.guide.desc": "跨会话待办:勾选、补一条、改一句",
|
|
4729
|
+
"todo.fallbackSection": "未分节",
|
|
4730
|
+
"todo.stat": "{open} 条未完成 · {done} 条已完成 · {sections} 节",
|
|
4731
|
+
"todo.refresh": "刷新",
|
|
4732
|
+
"todo.expandAll": "全部展开",
|
|
4733
|
+
"todo.search.placeholder": "在清单里搜…",
|
|
4734
|
+
"todo.search.count": "{count} 条匹配",
|
|
4735
|
+
"todo.search.none": "没有匹配的条目",
|
|
4736
|
+
"todo.collapseAll": "全部收起",
|
|
4737
|
+
"todo.more": "展开",
|
|
4738
|
+
"todo.less": "收起",
|
|
4739
|
+
"todo.empty.file": "没找到 {file}。这份看板只读它 —— 先让它在记忆目录里生成。",
|
|
4740
|
+
"todo.empty.section": "这一节还没有条目",
|
|
4741
|
+
"todo.empty.done": "待删除块是空的:勾选一条,它就会搬到这里",
|
|
4742
|
+
"todo.add.placeholder": "加一条,回车保存",
|
|
4743
|
+
"todo.doneGroup": "已完成,待删除",
|
|
4744
|
+
"todo.action.check": "标记完成(搬进「已完成,待删除」块)",
|
|
4745
|
+
"todo.action.uncheck": "取消完成(搬回原组末尾)",
|
|
4746
|
+
"todo.action.edit": "编辑",
|
|
4747
|
+
"todo.action.save": "保存",
|
|
4748
|
+
"todo.action.cancel": "取消",
|
|
4749
|
+
"todo.action.delete": "删除",
|
|
4750
|
+
"todo.action.clearDone": "清空全部({count})",
|
|
4751
|
+
"todo.action.undo": "撤销",
|
|
4752
|
+
"todo.action.redo": "重做",
|
|
4753
|
+
"todo.notice.added": "已添加",
|
|
4754
|
+
"todo.notice.edited": "已保存",
|
|
4755
|
+
"todo.notice.movedToDone": "已完成,已搬进「{group}」",
|
|
4756
|
+
"todo.notice.restored": "已搬回原组",
|
|
4757
|
+
"todo.notice.deleted": "已删除该条",
|
|
4758
|
+
"todo.notice.redone": "已重做",
|
|
4759
|
+
"todo.notice.cleared": "已清空 {count} 条待删除",
|
|
4760
|
+
"todo.notice.stale": "文件刚被别处改过,已重新加载;这次改动没保存",
|
|
4761
|
+
"todo.notice.degraded": "宿主还是升级前的版本:这次写入没有版本校验,请确认内容正确",
|
|
4762
|
+
"todo.notice.undo": "已撤销上一步",
|
|
4763
|
+
"todo.err.noRemote": "宿主没有记忆 remote,读不了待办文件",
|
|
4764
|
+
"todo.err.read": "读不到待办文件:{error}",
|
|
4765
|
+
"todo.err.write": "写入被拒:{error}",
|
|
4766
|
+
"todo.disabled.title": "待办看板已在「实验性」里关闭",
|
|
4767
|
+
"todo.disabled.hint": "打开:设置 → 记忆管理 → 实验性 → 待办清单看板",
|
|
4768
|
+
"todo.lab.title": "待办清单看板(实验性)",
|
|
4769
|
+
"todo.lab.switch": "启用待办清单看板",
|
|
4770
|
+
"todo.lab.switch.title": "在右侧栏加一个「待办清单」页签",
|
|
4771
|
+
"todo.lab.what": "把记忆目录里的 project_session-state.md(跨会话代办清单)画成卡片:勾选 = 把那条搬进「已完成,待删除」块,新增 / 编辑 / 删除只改那一行,别的字节原样不动。",
|
|
4772
|
+
"todo.lab.live": "改完立刻生效,不用重启(与上面的 MMR 不同)。文件本身仍是唯一真相:AI 直接改它,看板 4 秒内跟上。",
|
|
4773
|
+
"todo.lab.unsupported": "当前宿主没有右侧栏(sidebarRightTabs),这个开关在这里不生效。",
|
|
4774
|
+
"todo.lab.status.on": "已开启",
|
|
4775
|
+
"todo.lab.status.off": "关闭(默认)",
|
|
4776
|
+
"todo.lab.onNotice": "已开启:右侧栏「+」里能看到待办清单",
|
|
4777
|
+
"todo.lab.offNotice": "已关闭:卡片已移除,已打开的页签会显示为关闭态",
|
|
4778
|
+
"todo.lab.rejected": "宿主拒绝了这次设置",
|
|
4675
4779
|
};
|
|
4676
4780
|
|
|
4677
4781
|
const EN = {
|
|
@@ -5223,6 +5327,61 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
5223
5327
|
"prompt.copyFailedTitle": "Copy failed — copy this prompt by hand",
|
|
5224
5328
|
"prompt.copyFailedHint": "Click the box to select it all, then press Ctrl+C",
|
|
5225
5329
|
"prompt.close": "Close",
|
|
5330
|
+
|
|
5331
|
+
// ── 2.11.0 to-do board (right-sidebar tab + its lab card) ──
|
|
5332
|
+
"todo.tabTitle": "To-dos",
|
|
5333
|
+
"todo.guide.title": "To-dos",
|
|
5334
|
+
"todo.guide.desc": "Cross-session to-dos: tick, add, edit",
|
|
5335
|
+
"todo.fallbackSection": "Unsorted",
|
|
5336
|
+
"todo.stat": "{open} open · {done} done · {sections} groups",
|
|
5337
|
+
"todo.refresh": "Refresh",
|
|
5338
|
+
"todo.expandAll": "Expand all",
|
|
5339
|
+
"todo.search.placeholder": "Search the list…",
|
|
5340
|
+
"todo.search.count": "{count} match(es)",
|
|
5341
|
+
"todo.search.none": "No matching item",
|
|
5342
|
+
"todo.collapseAll": "Collapse all",
|
|
5343
|
+
"todo.more": "More",
|
|
5344
|
+
"todo.less": "Less",
|
|
5345
|
+
"todo.empty.file": "{file} is not in the memory directory yet — this board reads that one file.",
|
|
5346
|
+
"todo.empty.section": "Nothing in this group yet",
|
|
5347
|
+
"todo.empty.done": "Nothing pending deletion: tick an item and it moves here",
|
|
5348
|
+
"todo.add.placeholder": "Add an item, Enter to save",
|
|
5349
|
+
"todo.doneGroup": "Done, pending deletion",
|
|
5350
|
+
"todo.action.check": "Mark done (moves the item into the pending-deletion block)",
|
|
5351
|
+
"todo.action.uncheck": "Undo done (moves it back to its group)",
|
|
5352
|
+
"todo.action.edit": "Edit",
|
|
5353
|
+
"todo.action.save": "Save",
|
|
5354
|
+
"todo.action.cancel": "Cancel",
|
|
5355
|
+
"todo.action.delete": "Delete",
|
|
5356
|
+
"todo.action.clearDone": "Clear all ({count})",
|
|
5357
|
+
"todo.action.undo": "Undo",
|
|
5358
|
+
"todo.action.redo": "Redo",
|
|
5359
|
+
"todo.notice.added": "Added",
|
|
5360
|
+
"todo.notice.edited": "Saved",
|
|
5361
|
+
"todo.notice.movedToDone": "Done: moved into {group}",
|
|
5362
|
+
"todo.notice.restored": "Moved back to its group",
|
|
5363
|
+
"todo.notice.deleted": "Deleted",
|
|
5364
|
+
"todo.notice.redone": "Redone",
|
|
5365
|
+
"todo.notice.cleared": "Cleared {count} pending-deletion item(s)",
|
|
5366
|
+
"todo.notice.stale": "The file changed elsewhere; reloaded. This edit was not saved.",
|
|
5367
|
+
"todo.notice.degraded": "Host predates this version: the write had no revision check — verify the content.",
|
|
5368
|
+
"todo.notice.undo": "Reverted the last edit",
|
|
5369
|
+
"todo.err.noRemote": "This host exposes no memory remote, so the to-do file cannot be read",
|
|
5370
|
+
"todo.err.read": "Cannot read the to-do file: {error}",
|
|
5371
|
+
"todo.err.write": "Write rejected: {error}",
|
|
5372
|
+
"todo.disabled.title": "The to-do board is switched off in the lab settings",
|
|
5373
|
+
"todo.disabled.hint": "Turn it on: Settings → Memory management → Lab → To-do board",
|
|
5374
|
+
"todo.lab.title": "To-do board (experimental)",
|
|
5375
|
+
"todo.lab.switch": "Enable the to-do board",
|
|
5376
|
+
"todo.lab.switch.title": "Adds a To-dos tab to the right sidebar",
|
|
5377
|
+
"todo.lab.what": "Renders project_session-state.md (the cross-session to-do list) as cards: ticking moves the item into the pending-deletion block; adding, editing and deleting touch that line only — every other byte stays as it is.",
|
|
5378
|
+
"todo.lab.live": "Takes effect immediately, no restart (unlike MMR above). The file stays the only source of truth: edit it directly and the board follows within 4 seconds.",
|
|
5379
|
+
"todo.lab.unsupported": "This host has no right sidebar (sidebarRightTabs), so the switch does nothing here.",
|
|
5380
|
+
"todo.lab.status.on": "On",
|
|
5381
|
+
"todo.lab.status.off": "Off (default)",
|
|
5382
|
+
"todo.lab.onNotice": "On: the to-do board is in the right sidebar's + menu",
|
|
5383
|
+
"todo.lab.offNotice": "Off: the card is gone; an open tab now shows the closed state",
|
|
5384
|
+
"todo.lab.rejected": "The host rejected the setting",
|
|
5226
5385
|
};
|
|
5227
5386
|
|
|
5228
5387
|
/**
|
|
@@ -6749,6 +6908,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
6749
6908
|
h("div", { key: "c" }, t("lab.declare.default")),
|
|
6750
6909
|
]),
|
|
6751
6910
|
|
|
6911
|
+
// ── 2.11.0 新增:待办清单看板(界面入口类开关,改完立刻生效)──
|
|
6912
|
+
h(TodoBoardLabCard, { key: "todos", ctx: props.ctx }),
|
|
6913
|
+
|
|
6752
6914
|
// 错误与回执留在最后:不管在哪按的,结果都得看得见。
|
|
6753
6915
|
err ? h("div", { className: "smem-err", key: "err" }, "⚠ " + err) : null,
|
|
6754
6916
|
notice ? h("div", { className: "smem-ok", key: "ok" }, "✓ " + notice) : null,
|
|
@@ -9232,6 +9394,953 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
9232
9394
|
]);
|
|
9233
9395
|
}));
|
|
9234
9396
|
}
|
|
9397
|
+
// ── 待办清单看板(2.11.0 · 实验性 / 2.11.1 勾选改「搬家」)─────────────
|
|
9398
|
+
//
|
|
9399
|
+
// 数据源**唯一**:`memory/project_session-state.md`(跨会话代办清单,baseline 每场注入)。
|
|
9400
|
+
// 面板只做**行级手术**:勾选 = 把那一行从原组删掉、搬进「已完成,待删除」块;
|
|
9401
|
+
// 新增 / 编辑 / 删除只动那几行,其余字节(frontmatter、引用块、空行、别的节)原样带走。
|
|
9402
|
+
//
|
|
9403
|
+
// 为什么勾选是**搬家**而不是加 `[x]`(2.11.1,用户反馈 2026-11-17):完成项留在原组里,
|
|
9404
|
+
// 原组就越读越长,而「已完成」本来只该是**待清理的队列**。搬进单独一块之后,
|
|
9405
|
+
// agent 收尾时一眼就能看见该搬哪几条进 `session-log.md`、搬完从这块删掉。
|
|
9406
|
+
// 这也把「谁来删」从模型自觉变成了一个显式位置 —— 见 `skills/sage-mem/SKILL.md`。
|
|
9407
|
+
//
|
|
9408
|
+
// 为什么不建自己的存储:用户要的是「AI 直接在 md 里调试」—— 同一个文件是唯一真相,
|
|
9409
|
+
// 面板只是它的另一种视图。第二份状态一定会漂移,而漂移的代价是「看板说做完了、文件里还在」。
|
|
9410
|
+
//
|
|
9411
|
+
// 承载面走**官方**注册表(`sidebarRightTabs`):
|
|
9412
|
+
// 1. 给 tab 类型 `sage-mem:todo` + 一条 guide 条目(开始页卡片自动出现,better-sidebar 也读这张表);
|
|
9413
|
+
// 2. 正文注册进键控槽 `sidebar.right.pane.tab`,标题注册进 `sidebar.right.pane.tab.title`;
|
|
9414
|
+
// 3. **definition + body 常驻,只有 guide 随开关变** —— 关掉开关时已打开的页签不会变成孤儿,
|
|
9415
|
+
// 它只是切到「已关闭」态。热开关靠的就是这条:注销 → 下一拍重注册(Phase 0 已实测)。
|
|
9416
|
+
|
|
9417
|
+
/** 看板认的那一个文件(唯一真相源:改这个名字只改这里)。 */
|
|
9418
|
+
const TODO_FILE = "project_session-state.md";
|
|
9419
|
+
const TODO_TAB_ID = "sage-mem-todo";
|
|
9420
|
+
const TODO_TAB_KIND = "sage-mem:todo";
|
|
9421
|
+
const TODO_GUIDE_ID = "sage-mem-todo";
|
|
9422
|
+
/** 轮询间隔:AI 用普通编辑工具改文件后,面板最多这么久就该跟上。 */
|
|
9423
|
+
const TODO_POLL_MS = 4000;
|
|
9424
|
+
/** 卡片正文折叠阈值(字符数;右栏很窄,两三行就够看了)。 */
|
|
9425
|
+
const TODO_DETAIL_CHARS = 150;
|
|
9426
|
+
/** 没有 `##` 节时条目落进这个兜底组。 */
|
|
9427
|
+
const TODO_SECTION_FALLBACK = "todo.fallbackSection";
|
|
9428
|
+
/** 「已完成,待删除」块:标题匹配它就算 done 组(`kind: "done"`)。 */
|
|
9429
|
+
const TODO_DONE_PATTERN = /已完成|待删除/;
|
|
9430
|
+
/**
|
|
9431
|
+
* 文件里还没有这个块时,第一次勾选按这行标题建块。
|
|
9432
|
+
* **字面量写进文件,不跟界面语言走** —— 它是文件格式的一部分,不是 UI 文案。
|
|
9433
|
+
*/
|
|
9434
|
+
const TODO_DONE_HEADING = "## 已完成,待删除";
|
|
9435
|
+
/** 撤销 / 重做各留几步(用户要两步;再多会让人误以为能回滚一整天)。 */
|
|
9436
|
+
const TODO_UNDO_DEPTH = 2;
|
|
9437
|
+
|
|
9438
|
+
/** 开关状态(模块级:设置卡与页签共享)。 */
|
|
9439
|
+
let todoBoardEnabled = false;
|
|
9440
|
+
/** 当前 definition 是否带着 guide 卡片(避免每次 apply 都白重注册一次)。 */
|
|
9441
|
+
let todoBoardGuideShown = false;
|
|
9442
|
+
let todoBoardCtx = null;
|
|
9443
|
+
let todoBoardRegistryDispose = null;
|
|
9444
|
+
let todoBoardBodyDispose = null;
|
|
9445
|
+
let todoBoardTitleDispose = null;
|
|
9446
|
+
const todoBoardListeners = new Set();
|
|
9447
|
+
|
|
9448
|
+
/** 无条件调用的钩子替身(宿主没给 `useTabInfo` 时用,避免条件调 hook)。 */
|
|
9449
|
+
function todoBoardNoTabInfo() { return null; }
|
|
9450
|
+
|
|
9451
|
+
function todoBoardNotify() {
|
|
9452
|
+
todoBoardListeners.forEach(function (fn) {
|
|
9453
|
+
try { fn(); } catch (e) { /* 单个订阅者坏掉不影响别的 */ }
|
|
9454
|
+
});
|
|
9455
|
+
}
|
|
9456
|
+
|
|
9457
|
+
/** 订阅开关变化(页签正文与设置卡都靠它重渲染)。 */
|
|
9458
|
+
function useTodoBoardEnabled() {
|
|
9459
|
+
const s = react.useState(todoBoardEnabled);
|
|
9460
|
+
const setV = s[1];
|
|
9461
|
+
react.useEffect(function () {
|
|
9462
|
+
const fn = function () { setV(todoBoardEnabled); };
|
|
9463
|
+
todoBoardListeners.add(fn);
|
|
9464
|
+
fn();
|
|
9465
|
+
return function () { todoBoardListeners.delete(fn); };
|
|
9466
|
+
}, []);
|
|
9467
|
+
return s[0];
|
|
9468
|
+
}
|
|
9469
|
+
|
|
9470
|
+
// ── 解析:markdown → 节 + 条目(纯函数,不碰 IO)────────────────────
|
|
9471
|
+
|
|
9472
|
+
/**
|
|
9473
|
+
* 条目标题:`**…**` 里的那一截;没有就用 null(渲染时不画标题行,正文自己说话)。
|
|
9474
|
+
* @param {string} text 条目正文(`- ` 之后,已剥掉 `[x]`)
|
|
9475
|
+
*/
|
|
9476
|
+
function todoItemTitle(text) {
|
|
9477
|
+
const bold = /\*\*(.+?)\*\*/.exec(text);
|
|
9478
|
+
return bold ? bold[1].trim() : null;
|
|
9479
|
+
}
|
|
9480
|
+
|
|
9481
|
+
/**
|
|
9482
|
+
* 条目正文:去掉开头那段 `**标题**` 与紧随的分隔符 —— 标题已经在上面单独画了一行,
|
|
9483
|
+
* 正文再带一遍就是同一句话说两次(第一次真机截图就是这么发现的)。
|
|
9484
|
+
*/
|
|
9485
|
+
function todoItemDetail(text) {
|
|
9486
|
+
const body = String(text == null ? "" : text);
|
|
9487
|
+
const m = /^\s*\*\*(?:.+?)\*\*/.exec(body);
|
|
9488
|
+
if (!m) return body.trim();
|
|
9489
|
+
return body.slice(m[0].length).replace(/^[\s—–\-::、,,。]+/, "").trim();
|
|
9490
|
+
}
|
|
9491
|
+
|
|
9492
|
+
/**
|
|
9493
|
+
* 极简内联渲染:`**加粗**` / `` `代码` `` / `[[记忆]]`。其余原样。
|
|
9494
|
+
* 不引 markdown 解析器:这里只显示,不需要块级语法。
|
|
9495
|
+
*/
|
|
9496
|
+
function todoInline(text) {
|
|
9497
|
+
const out = [];
|
|
9498
|
+
const re = /(\*\*[^*]+\*\*|`[^`]+`|\[\[[^\]]+\]\])/g;
|
|
9499
|
+
let last = 0;
|
|
9500
|
+
let m;
|
|
9501
|
+
let i = 0;
|
|
9502
|
+
while ((m = re.exec(text)) !== null) {
|
|
9503
|
+
if (m.index > last) out.push(text.slice(last, m.index));
|
|
9504
|
+
const tok = m[0];
|
|
9505
|
+
if (tok.startsWith("**")) out.push(h("strong", { key: "b" + i }, tok.slice(2, -2)));
|
|
9506
|
+
else if (tok.startsWith("[[")) out.push(h("span", { key: "l" + i, className: "smem-todo-ref" }, tok.slice(2, -2)));
|
|
9507
|
+
else out.push(h("code", { key: "c" + i, className: "smem-todo-code" }, tok.slice(1, -1)));
|
|
9508
|
+
last = m.index + tok.length;
|
|
9509
|
+
i += 1;
|
|
9510
|
+
}
|
|
9511
|
+
if (last < text.length) out.push(text.slice(last));
|
|
9512
|
+
return out;
|
|
9513
|
+
}
|
|
9514
|
+
|
|
9515
|
+
/**
|
|
9516
|
+
* 拆一份代办清单。**只读**:`lines` 原样保留,条目只记「行号 + 内容」,
|
|
9517
|
+
* 写回时按行号替换,所以任何没被操作的字节都不会变。
|
|
9518
|
+
*
|
|
9519
|
+
* @param {string} text
|
|
9520
|
+
* @returns {{lines: string[], sections: Array<object>, open: number, done: number}}
|
|
9521
|
+
*/
|
|
9522
|
+
function parseTodoList(text) {
|
|
9523
|
+
const lines = String(text == null ? "" : text).split("\n");
|
|
9524
|
+
const sections = [];
|
|
9525
|
+
let current = null;
|
|
9526
|
+
let lastItem = null;
|
|
9527
|
+
let inFront = false;
|
|
9528
|
+
let seenContent = false;
|
|
9529
|
+
let open = 0;
|
|
9530
|
+
let done = 0;
|
|
9531
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9532
|
+
// 分析用去掉行尾 `\r`(CRLF 文件读得懂);`lines` 本身原样留着,写回不动没碰过的行。
|
|
9533
|
+
const rawLine = lines[i];
|
|
9534
|
+
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
9535
|
+
if (!seenContent && /^---\s*$/.test(line)) { inFront = true; seenContent = true; continue; }
|
|
9536
|
+
if (inFront) {
|
|
9537
|
+
if (/^---\s*$/.test(line)) inFront = false;
|
|
9538
|
+
continue;
|
|
9539
|
+
}
|
|
9540
|
+
if (line.trim() !== "") seenContent = true;
|
|
9541
|
+
const heading = /^##\s+(.*)$/.exec(line);
|
|
9542
|
+
if (heading) {
|
|
9543
|
+
const title = heading[1].trim();
|
|
9544
|
+
// 三档:done(「已完成,待删除」块,勾选搬进这里)/ constraint(长期约束,别删)/ 普通待办。
|
|
9545
|
+
const kind = TODO_DONE_PATTERN.test(title) ? "done" : (/长期约束|不是待办|别删/.test(title) ? "constraint" : "todo");
|
|
9546
|
+
current = { title: title, kind: kind, items: [], insertAt: i + 1, headingIndex: i };
|
|
9547
|
+
sections.push(current);
|
|
9548
|
+
lastItem = null;
|
|
9549
|
+
continue;
|
|
9550
|
+
}
|
|
9551
|
+
const bullet = /^(\s*)-\s+(.*)$/.exec(line);
|
|
9552
|
+
if (bullet && bullet[1] !== "" && lastItem !== null) {
|
|
9553
|
+
// 缩进的 `- ` 是上一条的子项(真文件里只有缩进续行):并进 cont,**不**算新条目。
|
|
9554
|
+
let sub = bullet[2];
|
|
9555
|
+
const subBox = /^\[([ xX])\]\s*(.*)$/.exec(sub);
|
|
9556
|
+
if (subBox) sub = subBox[2];
|
|
9557
|
+
lastItem.cont += (lastItem.cont ? " " : "") + sub;
|
|
9558
|
+
continue;
|
|
9559
|
+
}
|
|
9560
|
+
if (bullet) {
|
|
9561
|
+
let body = bullet[2];
|
|
9562
|
+
let isDone = false;
|
|
9563
|
+
const box = /^\[([ xX])\]\s*(.*)$/.exec(body);
|
|
9564
|
+
if (box) { isDone = box[1].toLowerCase() === "x"; body = box[2]; }
|
|
9565
|
+
if (current === null) {
|
|
9566
|
+
current = { title: "", kind: "todo", items: [], insertAt: i, headingIndex: -1 };
|
|
9567
|
+
sections.push(current);
|
|
9568
|
+
}
|
|
9569
|
+
// 待删除块里的条目按语义就是「已完成」,不靠行首 `[x]` 自证(手写的也算)。
|
|
9570
|
+
const inDone = current.kind === "done";
|
|
9571
|
+
const item = {
|
|
9572
|
+
line: i, done: isDone || inDone, inDone: inDone,
|
|
9573
|
+
text: body, title: todoItemTitle(body), detail: todoItemDetail(body), cont: "",
|
|
9574
|
+
};
|
|
9575
|
+
current.items.push(item);
|
|
9576
|
+
// 插入点 = 本条之后:节尾最后一条的下方,不会被后面的空行 / 下一节吃掉。
|
|
9577
|
+
current.insertAt = i + 1;
|
|
9578
|
+
if (item.done) done += 1; else open += 1;
|
|
9579
|
+
lastItem = item;
|
|
9580
|
+
continue;
|
|
9581
|
+
}
|
|
9582
|
+
// 续行(两个空格以上缩进、不是 `- `):并进上一条的正文,只用于显示。
|
|
9583
|
+
if (lastItem !== null && /^\s{2,}\S/.test(line)) {
|
|
9584
|
+
lastItem.cont += (lastItem.cont ? " " : "") + line.trim();
|
|
9585
|
+
} else if (line.trim() !== "") {
|
|
9586
|
+
lastItem = null;
|
|
9587
|
+
}
|
|
9588
|
+
}
|
|
9589
|
+
return { lines: lines, sections: sections, open: open, done: done };
|
|
9590
|
+
}
|
|
9591
|
+
|
|
9592
|
+
// ── 行级手术(纯函数:输入旧全文 → 输出新全文,不改入参)────────────
|
|
9593
|
+
|
|
9594
|
+
/**
|
|
9595
|
+
* 把一行拆成 `- ` 条目的三段。行不认识(不是 `- ` 开头)就回 null。
|
|
9596
|
+
* ⚠️ 先把行尾 `\r` 摘掉再匹配:JS 的 `.` 与 `$` 都不吃 `\r`,
|
|
9597
|
+
* 带着它匹配 `/^(\s*)-\s+(.*)$/` 一律不中 —— CRLF 文件会一条都认不出来。
|
|
9598
|
+
* @returns {{indent: string, body: string, done: boolean}|null} body 已剥掉 `[x]`
|
|
9599
|
+
*/
|
|
9600
|
+
function todoBullet(line) {
|
|
9601
|
+
const raw = String(line == null ? "" : line).replace(/\r+$/, "");
|
|
9602
|
+
const m = /^(\s*)-\s+(.*)$/.exec(raw);
|
|
9603
|
+
if (!m) return null;
|
|
9604
|
+
let body = m[2];
|
|
9605
|
+
let done = false;
|
|
9606
|
+
const box = /^\[([ xX])\]\s*(.*)$/.exec(body);
|
|
9607
|
+
if (box) { done = box[1].toLowerCase() === "x"; body = box[2]; }
|
|
9608
|
+
return { indent: m[1], body: body.replace(/\s+$/, ""), done: done };
|
|
9609
|
+
}
|
|
9610
|
+
|
|
9611
|
+
/** 文件用的行尾:CRLF 文件里插的新行也带 `\r`,免得一份文件两种换行。 */
|
|
9612
|
+
function todoEol(text) {
|
|
9613
|
+
return String(text == null ? "" : text).indexOf("\r\n") >= 0 ? "\r" : "";
|
|
9614
|
+
}
|
|
9615
|
+
|
|
9616
|
+
/**
|
|
9617
|
+
* 找「已完成,待删除」块的行区间。
|
|
9618
|
+
* @returns {{start: number, end: number}|null} `[start, end)`:`start` 是标题行,`end` 是下一个 `##` 或文件尾
|
|
9619
|
+
*/
|
|
9620
|
+
function todoDoneRange(lines) {
|
|
9621
|
+
const heading = /^##\s+(.*)$/;
|
|
9622
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9623
|
+
// 先摘 `\r`:CRLF 文件里带 `\r` 的行用 `.` / `$` 匹配不到(见 todoBullet 那条注释)。
|
|
9624
|
+
const m = heading.exec(String(lines[i]).replace(/\r+$/, ""));
|
|
9625
|
+
if (!m || !TODO_DONE_PATTERN.test(m[1].trim())) continue;
|
|
9626
|
+
let end = lines.length;
|
|
9627
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
9628
|
+
if (heading.exec(String(lines[j]).replace(/\r+$/, ""))) { end = j; break; }
|
|
9629
|
+
}
|
|
9630
|
+
return { start: i, end: end };
|
|
9631
|
+
}
|
|
9632
|
+
return null;
|
|
9633
|
+
}
|
|
9634
|
+
|
|
9635
|
+
/**
|
|
9636
|
+
* 勾选 = **搬家**:从原组删掉第 line 行,在「已完成,待删除」块末尾追加 `- [x] <正文>`。
|
|
9637
|
+
*
|
|
9638
|
+
* - 文件里还没有那个块时,在**文件末尾**追加 `\n## 已完成,待删除\n` 再写条目,其余字节不动。
|
|
9639
|
+
* - 只搬**顶层**条目(缩进行是上一条的续行,跟着它自己留在原处,不在此处重构)。
|
|
9640
|
+
* - 正文只带原正文:不带原行首 `- `,也剥掉已有的 `[x]` 前缀。
|
|
9641
|
+
*
|
|
9642
|
+
* @returns {string|null} 新全文;不认识的行 / 空正文回 null(调用方据此不写盘)
|
|
9643
|
+
*/
|
|
9644
|
+
function todoMoveToDone(text, line) {
|
|
9645
|
+
const src = String(text == null ? "" : text);
|
|
9646
|
+
const lines = src.split("\n");
|
|
9647
|
+
if (line < 0 || line >= lines.length) return null;
|
|
9648
|
+
const bullet = todoBullet(lines[line]);
|
|
9649
|
+
if (!bullet || bullet.indent !== "" || bullet.body === "") return null;
|
|
9650
|
+
const eol = todoEol(src);
|
|
9651
|
+
const next = lines.slice();
|
|
9652
|
+
next.splice(line, 1);
|
|
9653
|
+
const range = todoDoneRange(next);
|
|
9654
|
+
if (!range) {
|
|
9655
|
+
if (next.length > 0 && next[next.length - 1] === "") next.pop();
|
|
9656
|
+
const tail = next.length > 0 ? [""] : [];
|
|
9657
|
+
return next.concat(tail, [TODO_DONE_HEADING + eol, "- [x] " + bullet.body + eol, ""]).join("\n");
|
|
9658
|
+
}
|
|
9659
|
+
// 块末尾 = 块内**最后一条条目**的下一行;块里一条都没有就紧贴标题。
|
|
9660
|
+
let at = range.start + 1;
|
|
9661
|
+
for (let i = range.start + 1; i < range.end; i++) {
|
|
9662
|
+
if (todoBullet(next[i])) at = i + 1;
|
|
9663
|
+
}
|
|
9664
|
+
next.splice(at, 0, "- [x] " + bullet.body + eol);
|
|
9665
|
+
return next.join("\n");
|
|
9666
|
+
}
|
|
9667
|
+
|
|
9668
|
+
/**
|
|
9669
|
+
* 取消完成 = **反向搬家**:从待删除块删掉第 line 行,回到它原来所在组的末尾。
|
|
9670
|
+
*
|
|
9671
|
+
* 「原来在哪一组」只存在内存里(`rememberTodoOrigin`)—— 文件里不留标记,因为
|
|
9672
|
+
* 那会把看板的私有状态写进用户的数据。记不住时(换了个页面 / 手写的条目)退而求其次:
|
|
9673
|
+
* 第一个普通待办组的末尾,再不行就文件末尾。
|
|
9674
|
+
*
|
|
9675
|
+
* @param {string} originTitle 原组标题(空 = 不知道)
|
|
9676
|
+
*/
|
|
9677
|
+
function todoRestore(text, line, originTitle) {
|
|
9678
|
+
const src = String(text == null ? "" : text);
|
|
9679
|
+
const lines = src.split("\n");
|
|
9680
|
+
if (line < 0 || line >= lines.length) return null;
|
|
9681
|
+
const bullet = todoBullet(lines[line]);
|
|
9682
|
+
if (!bullet || bullet.indent !== "" || bullet.body === "") return null;
|
|
9683
|
+
const eol = todoEol(src);
|
|
9684
|
+
const next = lines.slice();
|
|
9685
|
+
next.splice(line, 1);
|
|
9686
|
+
const parsed = parseTodoList(next.join("\n"));
|
|
9687
|
+
const want = String(originTitle == null ? "" : originTitle).trim();
|
|
9688
|
+
const byTitle = want === "" ? null : parsed.sections.find(function (sec) {
|
|
9689
|
+
return sec.kind !== "done" && sec.title === want;
|
|
9690
|
+
});
|
|
9691
|
+
const fallback = byTitle || parsed.sections.find(function (sec) {
|
|
9692
|
+
return sec.kind === "todo" && sec.items.length > 0;
|
|
9693
|
+
}) || parsed.sections.find(function (sec) { return sec.kind === "todo"; });
|
|
9694
|
+
if (!fallback) {
|
|
9695
|
+
if (next.length > 0 && next[next.length - 1] === "") next.pop();
|
|
9696
|
+
return next.concat(["- " + bullet.body + eol, ""]).join("\n");
|
|
9697
|
+
}
|
|
9698
|
+
next.splice(fallback.insertAt, 0, "- " + bullet.body + eol);
|
|
9699
|
+
return next.join("\n");
|
|
9700
|
+
}
|
|
9701
|
+
|
|
9702
|
+
/** 在第 at 行插入一条 `- <body>`。 */
|
|
9703
|
+
function todoInsert(text, at, body) {
|
|
9704
|
+
const lines = String(text).split("\n");
|
|
9705
|
+
const clean = String(body == null ? "" : body).replace(/\r?\n/g, " ").trim();
|
|
9706
|
+
if (clean === "") return null;
|
|
9707
|
+
const index = Math.max(0, Math.min(at, lines.length));
|
|
9708
|
+
lines.splice(index, 0, "- " + clean);
|
|
9709
|
+
return lines.join("\n");
|
|
9710
|
+
}
|
|
9711
|
+
|
|
9712
|
+
/** 替换第 line 行的正文(保留 `[x]` 标记与缩进)。 */
|
|
9713
|
+
function todoReplace(text, line, body) {
|
|
9714
|
+
const lines = String(text).split("\n");
|
|
9715
|
+
const raw = lines[line];
|
|
9716
|
+
if (raw === undefined) return null;
|
|
9717
|
+
const m = /^(\s*)-\s+(.*)$/.exec(raw);
|
|
9718
|
+
if (!m) return null;
|
|
9719
|
+
const clean = String(body == null ? "" : body).replace(/\r?\n/g, " ").trim();
|
|
9720
|
+
if (clean === "") return null;
|
|
9721
|
+
const box = /^\[([ xX])\]\s*/.exec(m[2]);
|
|
9722
|
+
lines[line] = m[1] + "- " + (box ? box[0] : "") + clean;
|
|
9723
|
+
return lines.join("\n");
|
|
9724
|
+
}
|
|
9725
|
+
|
|
9726
|
+
/** 删掉若干行(从大到小删,行号不互相错位)。 */
|
|
9727
|
+
function todoRemove(text, lineNumbers) {
|
|
9728
|
+
const lines = String(text).split("\n");
|
|
9729
|
+
const sorted = lineNumbers.slice().sort(function (a, b) { return b - a; });
|
|
9730
|
+
sorted.forEach(function (n) { if (n >= 0 && n < lines.length) lines.splice(n, 1); });
|
|
9731
|
+
return lines.join("\n");
|
|
9732
|
+
}
|
|
9733
|
+
|
|
9734
|
+
/**
|
|
9735
|
+
* 清空「已完成,待删除」块:删掉块内**全部条目行**,`## 标题` 留着(块还要继续接下一次勾选)。
|
|
9736
|
+
* @returns {{next: string|null, count: number}} count=0 → next 为 null(不白写一次盘)
|
|
9737
|
+
*/
|
|
9738
|
+
function todoClearDoneBlock(text) {
|
|
9739
|
+
const src = String(text == null ? "" : text);
|
|
9740
|
+
const lines = src.split("\n");
|
|
9741
|
+
const range = todoDoneRange(lines);
|
|
9742
|
+
if (!range) return { next: null, count: 0 };
|
|
9743
|
+
const hits = [];
|
|
9744
|
+
for (let i = range.start + 1; i < range.end; i++) {
|
|
9745
|
+
if (todoBullet(lines[i])) hits.push(i);
|
|
9746
|
+
}
|
|
9747
|
+
if (hits.length === 0) return { next: null, count: 0 };
|
|
9748
|
+
return { next: todoRemove(src, hits), count: hits.length };
|
|
9749
|
+
}
|
|
9750
|
+
|
|
9751
|
+
/**
|
|
9752
|
+
* 「这条原来在哪一组」的内存账本 —— 取消完成要靠它把条目送回原组。
|
|
9753
|
+
* 只活在这个页面里(不落盘);键是正文归一化后的文本,最多留 200 条。
|
|
9754
|
+
*/
|
|
9755
|
+
const todoOrigins = new Map();
|
|
9756
|
+
|
|
9757
|
+
function rememberTodoOrigin(text, title) {
|
|
9758
|
+
const key = String(text == null ? "" : text).trim();
|
|
9759
|
+
if (key === "") return;
|
|
9760
|
+
if (todoOrigins.size > 200) todoOrigins.clear();
|
|
9761
|
+
todoOrigins.set(key, String(title == null ? "" : title));
|
|
9762
|
+
}
|
|
9763
|
+
|
|
9764
|
+
function recallTodoOrigin(text) {
|
|
9765
|
+
return todoOrigins.get(String(text == null ? "" : text).trim()) || "";
|
|
9766
|
+
}
|
|
9767
|
+
|
|
9768
|
+
// ── 视图 ──────────────────────────────────────────────────────────
|
|
9769
|
+
|
|
9770
|
+
/**
|
|
9771
|
+
* 撤销 / 重做图标:**内联 SVG**(不引图标库、不外链、不靠字体)。
|
|
9772
|
+
* 撤销 = 一条水平基线 + 从右上绕回的弧形箭头,箭头尖在左端;重做是它的左右镜像
|
|
9773
|
+
* (x → 16-x,圆弧的 sweep 反过来)。
|
|
9774
|
+
* @param {"undo"|"redo"} dir
|
|
9775
|
+
*/
|
|
9776
|
+
function todoArrowIcon(dir) {
|
|
9777
|
+
const paths = dir === "redo"
|
|
9778
|
+
? ["M13.5 6.5h-7a4 4 0 0 0 0 8h3", "M10.5 3.5l3 3-3 3"]
|
|
9779
|
+
: ["M2.5 6.5h7a4 4 0 0 1 0 8h-3", "M5.5 3.5l-3 3 3 3"];
|
|
9780
|
+
return h("svg", {
|
|
9781
|
+
viewBox: "0 0 16 16", width: 14, height: 14, fill: "none",
|
|
9782
|
+
stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round",
|
|
9783
|
+
"aria-hidden": "true",
|
|
9784
|
+
}, paths.map(function (d, i) { return h("path", { key: "p" + i, d: d }); }));
|
|
9785
|
+
}
|
|
9786
|
+
|
|
9787
|
+
/** 一条待办的卡片:勾选 + 标题 + 折叠正文 + 行内编辑(待删除块里还有「删除」)。 */
|
|
9788
|
+
function TodoItemRow(props) {
|
|
9789
|
+
const item = props.item;
|
|
9790
|
+
const sOpen = react.useState(false);
|
|
9791
|
+
const expanded = sOpen[0], setExpanded = sOpen[1];
|
|
9792
|
+
const sDraft = react.useState(null);
|
|
9793
|
+
const draft = sDraft[0], setDraft = sDraft[1];
|
|
9794
|
+
const editing = draft !== null;
|
|
9795
|
+
const body = item.detail + (item.cont ? " " + item.cont : "");
|
|
9796
|
+
const long = body.length > TODO_DETAIL_CHARS;
|
|
9797
|
+
const shown = long && !expanded ? body.slice(0, TODO_DETAIL_CHARS) + "…" : body;
|
|
9798
|
+
return h("div", { className: "smem-todo-item" + (item.done ? " smem-todo-item-done" : "") }, [
|
|
9799
|
+
h("button", {
|
|
9800
|
+
key: "box",
|
|
9801
|
+
type: "button",
|
|
9802
|
+
className: "smem-todo-box" + (item.done ? " smem-todo-box-on" : ""),
|
|
9803
|
+
title: item.done ? t("todo.action.uncheck") : t("todo.action.check"),
|
|
9804
|
+
disabled: props.busy,
|
|
9805
|
+
onClick: function () { props.onToggle(item, !item.done); },
|
|
9806
|
+
}, item.done ? "✓" : ""),
|
|
9807
|
+
h("div", { key: "body", className: "smem-todo-body" }, [
|
|
9808
|
+
item.title ? h("div", { key: "title", className: "smem-todo-title" }, todoInline(item.title)) : null,
|
|
9809
|
+
editing
|
|
9810
|
+
? h("textarea", {
|
|
9811
|
+
key: "edit",
|
|
9812
|
+
className: "smem-input smem-todo-edit",
|
|
9813
|
+
value: draft,
|
|
9814
|
+
rows: 3,
|
|
9815
|
+
onChange: function (e) { setDraft(e.target.value); },
|
|
9816
|
+
})
|
|
9817
|
+
: (shown ? h("div", { key: "text", className: "smem-todo-text" }, todoInline(shown)) : null),
|
|
9818
|
+
h("div", { key: "act", className: "smem-todo-actions" }, editing
|
|
9819
|
+
? [
|
|
9820
|
+
h("button", { key: "s", type: "button", className: "smem-btn smem-btn-primary smem-todo-mini", disabled: props.busy, onClick: function () { props.onEdit(item, draft); setDraft(null); } }, t("todo.action.save")),
|
|
9821
|
+
h("button", { key: "c", type: "button", className: "smem-btn smem-todo-mini", onClick: function () { setDraft(null); } }, t("todo.action.cancel")),
|
|
9822
|
+
]
|
|
9823
|
+
: [
|
|
9824
|
+
long ? h("button", { key: "m", type: "button", className: "smem-link smem-todo-mini", onClick: function () { setExpanded(!expanded); } }, expanded ? t("todo.less") : t("todo.more")) : null,
|
|
9825
|
+
h("button", { key: "e", type: "button", className: "smem-link smem-todo-mini", disabled: props.busy, onClick: function () { setDraft(item.text); } }, t("todo.action.edit")),
|
|
9826
|
+
// 「删除」只在待删除块里出现:别的位置删条目等于绕过「搬进流水」这一步。
|
|
9827
|
+
props.onDelete
|
|
9828
|
+
? h("button", { key: "d", type: "button", className: "smem-link smem-todo-mini smem-todo-del", disabled: props.busy, onClick: function () { props.onDelete(item); } }, t("todo.action.delete"))
|
|
9829
|
+
: null,
|
|
9830
|
+
]),
|
|
9831
|
+
]),
|
|
9832
|
+
]);
|
|
9833
|
+
}
|
|
9834
|
+
|
|
9835
|
+
/** 一组(一个 `##` 节):标题 + 计数 + 条目 + 新增框;待删除块另有「清空全部」。 */
|
|
9836
|
+
function TodoSectionGroup(props) {
|
|
9837
|
+
const sec = props.section;
|
|
9838
|
+
const isDone = sec.kind === "done";
|
|
9839
|
+
// 2.11.1(用户 2026-11-17 反馈):**所有组默认收起**,一屏先看见「有几组、各组几条」,
|
|
9840
|
+
// 想看的组自己点开。原来只收「长期约束」,长清单照样一屏铺满。
|
|
9841
|
+
const sCollapsed = react.useState(true);
|
|
9842
|
+
const collapsed = sCollapsed[0], setCollapsed = sCollapsed[1];
|
|
9843
|
+
// 上层「全部展开 / 全部收起」:allOpen 为 null 时不管(各组各管各的)。
|
|
9844
|
+
react.useEffect(function () {
|
|
9845
|
+
if (props.allOpen === null || props.allOpen === undefined) return;
|
|
9846
|
+
setCollapsed(!props.allOpen);
|
|
9847
|
+
}, [props.allOpen]);
|
|
9848
|
+
const sDraft = react.useState("");
|
|
9849
|
+
const draft = sDraft[0], setDraft = sDraft[1];
|
|
9850
|
+
const openCount = sec.items.filter(function (it) { return !it.done; }).length;
|
|
9851
|
+
const doneCount = sec.items.length - openCount;
|
|
9852
|
+
// 「清空全部」清的是**整个块**(不是当前筛出来的这几条),所以按钮上的数字要取块的真实条数。
|
|
9853
|
+
const blockCount = typeof props.doneCount === "number" ? props.doneCount : sec.items.length;
|
|
9854
|
+
return h("section", { className: "smem-todo-group" + (isDone ? " smem-todo-group-done" : "") }, [
|
|
9855
|
+
// 标题行是**行**不是按钮:右边还要放「清空全部」,按钮套按钮在浏览器里会互相吃掉。
|
|
9856
|
+
h("div", { key: "head", className: "smem-todo-group-head" }, [
|
|
9857
|
+
h("button", {
|
|
9858
|
+
key: "toggle",
|
|
9859
|
+
type: "button",
|
|
9860
|
+
className: "smem-todo-group-toggle",
|
|
9861
|
+
onClick: function () { setCollapsed(!collapsed); },
|
|
9862
|
+
}, [
|
|
9863
|
+
h("span", { key: "chev", className: "smem-todo-chev" }, collapsed ? "▸" : "▾"),
|
|
9864
|
+
h("span", { key: "t", className: "smem-todo-group-title" }, sec.title || (isDone ? t("todo.doneGroup") : t(TODO_SECTION_FALLBACK))),
|
|
9865
|
+
h("span", { key: "n", className: "smem-todo-count" }, String(openCount) + (doneCount > 0 ? " / " + String(doneCount) : "")),
|
|
9866
|
+
]),
|
|
9867
|
+
isDone && blockCount > 0
|
|
9868
|
+
? h("button", {
|
|
9869
|
+
key: "clear",
|
|
9870
|
+
type: "button",
|
|
9871
|
+
className: "smem-todo-mini smem-todo-del",
|
|
9872
|
+
title: t("todo.action.clearDone", { count: blockCount }),
|
|
9873
|
+
disabled: props.busy,
|
|
9874
|
+
onClick: function () { props.onClearDone(sec); },
|
|
9875
|
+
}, t("todo.action.clearDone", { count: blockCount }))
|
|
9876
|
+
: null,
|
|
9877
|
+
]),
|
|
9878
|
+
collapsed ? null : h("div", { key: "list", className: "smem-todo-list" }, sec.items.length === 0
|
|
9879
|
+
? [h("div", { key: "empty", className: "smem-todo-empty" }, isDone ? t("todo.empty.done") : t("todo.empty.section"))]
|
|
9880
|
+
: sec.items.map(function (it) {
|
|
9881
|
+
return h(TodoItemRow, {
|
|
9882
|
+
key: "i" + it.line, item: it, busy: props.busy,
|
|
9883
|
+
onToggle: props.onToggle, onEdit: props.onEdit,
|
|
9884
|
+
onDelete: isDone ? props.onDelete : null,
|
|
9885
|
+
});
|
|
9886
|
+
})),
|
|
9887
|
+
// 待删除块不给「加一条」:那一块只能由勾选搬进来,手写进去等于无来源的条目。
|
|
9888
|
+
collapsed || isDone ? null : h("div", { key: "add", className: "smem-todo-add" }, [
|
|
9889
|
+
h("input", {
|
|
9890
|
+
key: "in",
|
|
9891
|
+
className: "smem-input smem-todo-add-input",
|
|
9892
|
+
placeholder: t("todo.add.placeholder"),
|
|
9893
|
+
value: draft,
|
|
9894
|
+
disabled: props.busy,
|
|
9895
|
+
onChange: function (e) { setDraft(e.target.value); },
|
|
9896
|
+
onKeyDown: function (e) {
|
|
9897
|
+
if (e.key === "Enter") {
|
|
9898
|
+
const body = String(draft).trim();
|
|
9899
|
+
if (body === "") return;
|
|
9900
|
+
props.onAdd(sec, body);
|
|
9901
|
+
setDraft("");
|
|
9902
|
+
}
|
|
9903
|
+
},
|
|
9904
|
+
}),
|
|
9905
|
+
]),
|
|
9906
|
+
]);
|
|
9907
|
+
}
|
|
9908
|
+
|
|
9909
|
+
/** 页签正文。承载全部读写状态(宿主只给 ctx / sessionId / 标准 hooks)。 */
|
|
9910
|
+
function TodoBoard(props) {
|
|
9911
|
+
const ctx = props.ctx;
|
|
9912
|
+
const remote = stableRemote(ctx, "remote.memory");
|
|
9913
|
+
const enabled = useTodoBoardEnabled();
|
|
9914
|
+
const useTabInfo = typeof props.useTabInfo === "function" ? props.useTabInfo : todoBoardNoTabInfo;
|
|
9915
|
+
const tabInfo = useTabInfo();
|
|
9916
|
+
const visible = !(tabInfo && tabInfo.tab && tabInfo.tab.visible === false);
|
|
9917
|
+
|
|
9918
|
+
const sDoc = react.useState(null); const doc = sDoc[0], setDoc = sDoc[1];
|
|
9919
|
+
const sErr = react.useState(null); const err = sErr[0], setErr = sErr[1];
|
|
9920
|
+
const sNotice = react.useState(""); const notice = sNotice[0], setNotice = sNotice[1];
|
|
9921
|
+
const sBusy = react.useState(false); const busy = sBusy[0], setBusy = sBusy[1];
|
|
9922
|
+
// 撤销 / 重做:两步栈,元素是写入前的 `{content, revision}`。只在内存里,不落盘。
|
|
9923
|
+
// 任何**新**写入都清空 redoStack —— 从历史里分叉出去之后,原来那条「未来」就不成立了。
|
|
9924
|
+
const sUndo = react.useState([]); const undoStack = sUndo[0], setUndoStack = sUndo[1];
|
|
9925
|
+
const sRedo = react.useState([]); const redoStack = sRedo[0], setRedoStack = sRedo[1];
|
|
9926
|
+
// 「全部展开」是**一次性动作**而不是持久状态:默认 null(各组按自己的默认走 = 收起)。
|
|
9927
|
+
const sAll = react.useState(null); const allOpen = sAll[0], setAllOpen = sAll[1];
|
|
9928
|
+
// 搜索:只过滤**显示**,绝不改文件;有查询时匹配的组强制展开,没匹配的组整组隐掉。
|
|
9929
|
+
const sQuery = react.useState(""); const rawQuery = sQuery[0], setQuery = sQuery[1];
|
|
9930
|
+
const query = String(rawQuery).trim().toLowerCase();
|
|
9931
|
+
|
|
9932
|
+
/** 读一次文件。`quiet` = 轮询调用(出错不弹条,避免每 4 秒闪一次)。 */
|
|
9933
|
+
const load = react.useCallback(function (quiet) {
|
|
9934
|
+
if (!remote || typeof remote.readFile !== "function") {
|
|
9935
|
+
if (!quiet) setErr(t("todo.err.noRemote"));
|
|
9936
|
+
return;
|
|
9937
|
+
}
|
|
9938
|
+
return Promise.resolve(remote.readFile(TODO_FILE)).then(function (res) {
|
|
9939
|
+
const data = unwrap(res);
|
|
9940
|
+
if (data && data.ok === false) {
|
|
9941
|
+
setDoc({ missing: true, content: "", revision: null, parsed: parseTodoList("") });
|
|
9942
|
+
if (!quiet) setErr(data.error || t("todo.err.read", { error: String(data.code || "error") }));
|
|
9943
|
+
return;
|
|
9944
|
+
}
|
|
9945
|
+
const content = (data && data.content) || "";
|
|
9946
|
+
const revision = data && typeof data.revision === "string" ? data.revision : null;
|
|
9947
|
+
// quiet 轮询里 revision 没变就什么都不做 —— 否则每 4 秒整棵树重渲染一次。
|
|
9948
|
+
setDoc(function (prev) {
|
|
9949
|
+
if (quiet && prev && !prev.missing && prev.revision === revision) return prev;
|
|
9950
|
+
return { missing: false, content: content, revision: revision, parsed: parseTodoList(content) };
|
|
9951
|
+
});
|
|
9952
|
+
}, function (e) {
|
|
9953
|
+
if (!quiet) setErr(String((e && e.message) || e));
|
|
9954
|
+
});
|
|
9955
|
+
}, [remote]);
|
|
9956
|
+
|
|
9957
|
+
react.useEffect(function () { load(false); }, [load]);
|
|
9958
|
+
|
|
9959
|
+
// 轮询:只在页签可见时跑;切走(不可见)就停,别在后台白读盘。
|
|
9960
|
+
react.useEffect(function () {
|
|
9961
|
+
if (!visible || !enabled) return undefined;
|
|
9962
|
+
const id = setInterval(function () {
|
|
9963
|
+
if (typeof document !== "undefined" && document.hidden) return;
|
|
9964
|
+
load(true);
|
|
9965
|
+
}, TODO_POLL_MS);
|
|
9966
|
+
return function () { clearInterval(id); };
|
|
9967
|
+
}, [visible, enabled, load]);
|
|
9968
|
+
|
|
9969
|
+
/**
|
|
9970
|
+
* 一次写入:带上读到的 revision(盘上变了宿主回 stale_revision,我们只重读、不覆盖)。
|
|
9971
|
+
* @param {string} label 回执文案(已翻译)
|
|
9972
|
+
* @param {string} next 新全文
|
|
9973
|
+
*/
|
|
9974
|
+
function mutate(label, next) {
|
|
9975
|
+
if (!next || next === doc.content) return;
|
|
9976
|
+
// 写入前的快照先抓住:新写入一律清空 redoStack(历史分叉了)。
|
|
9977
|
+
const snapshot = { content: doc.content, revision: doc.revision };
|
|
9978
|
+
setBusy(true); setErr(null); setNotice("");
|
|
9979
|
+
const revision = doc.revision;
|
|
9980
|
+
const opts = revision ? { expectedRevision: revision } : undefined;
|
|
9981
|
+
writeWithFallback(remote, "writeFile", [TODO_FILE, next], opts, null)
|
|
9982
|
+
.then(function (out) {
|
|
9983
|
+
const r = out.result;
|
|
9984
|
+
if (r && r.ok === false) {
|
|
9985
|
+
if (r.code === "stale_revision") {
|
|
9986
|
+
setNotice(t("todo.notice.stale"));
|
|
9987
|
+
return load(false);
|
|
9988
|
+
}
|
|
9989
|
+
setErr(r.error || t("todo.err.write", { error: String(r.code || "error") }));
|
|
9990
|
+
return;
|
|
9991
|
+
}
|
|
9992
|
+
setUndoStack(function (prev) { return prev.concat([snapshot]).slice(-TODO_UNDO_DEPTH); });
|
|
9993
|
+
setRedoStack([]);
|
|
9994
|
+
setNotice(out.degraded ? t("todo.notice.degraded") : label);
|
|
9995
|
+
return load(false);
|
|
9996
|
+
}, function (e) { setErr(String((e && e.message) || e)); })
|
|
9997
|
+
.then(function () { setBusy(false); });
|
|
9998
|
+
}
|
|
9999
|
+
|
|
10000
|
+
/**
|
|
10001
|
+
* 写回一份历史快照(撤销 / 重做共用)。**只有写成功才动栈** ——
|
|
10002
|
+
* 失败时界面不该显示「已经挪过一步」。
|
|
10003
|
+
* @param {{content: string, revision: string|null}} target 要写回的快照
|
|
10004
|
+
* @param {string} label 回执文案
|
|
10005
|
+
* @param {function} onDone 成功后的栈操作
|
|
10006
|
+
*/
|
|
10007
|
+
function writeSnapshot(target, label, onDone) {
|
|
10008
|
+
if (!target || typeof target.content !== "string") return;
|
|
10009
|
+
const revision = doc.revision;
|
|
10010
|
+
setBusy(true); setErr(null); setNotice("");
|
|
10011
|
+
writeWithFallback(remote, "writeFile", [TODO_FILE, target.content], revision ? { expectedRevision: revision } : undefined, null)
|
|
10012
|
+
.then(function (out) {
|
|
10013
|
+
const r = out && (out.result || out);
|
|
10014
|
+
if (r && r.ok === false) {
|
|
10015
|
+
if (r.code === "stale_revision") { setNotice(t("todo.notice.stale")); return load(false); }
|
|
10016
|
+
setErr(r.error || t("todo.err.write", { error: String(r.code || "error") }));
|
|
10017
|
+
return;
|
|
10018
|
+
}
|
|
10019
|
+
if (typeof onDone === "function") onDone();
|
|
10020
|
+
setNotice(label);
|
|
10021
|
+
return load(false);
|
|
10022
|
+
}, function (e) { setErr(String((e && e.message) || e)); })
|
|
10023
|
+
.then(function () { setBusy(false); });
|
|
10024
|
+
}
|
|
10025
|
+
|
|
10026
|
+
/** 当前盘上内容的快照(撤销 / 重做要把它推到另一侧的栈里)。 */
|
|
10027
|
+
function currentPoint() {
|
|
10028
|
+
return { content: doc.content, revision: doc.revision };
|
|
10029
|
+
}
|
|
10030
|
+
|
|
10031
|
+
/**
|
|
10032
|
+
* 勾选 / 取消完成:**搬家**与**反向搬家**。
|
|
10033
|
+
* 勾选 → 从原组删行、追加到「已完成,待删除」块;取消 → 删掉、送回原组末尾。
|
|
10034
|
+
*/
|
|
10035
|
+
function onToggle(item, done, originTitle) {
|
|
10036
|
+
if (done) {
|
|
10037
|
+
const next = todoMoveToDone(doc.content, item.line);
|
|
10038
|
+
if (!next) return;
|
|
10039
|
+
// 记住它原来在哪一组,取消完成时靠这条回到原位(只在内存里)。
|
|
10040
|
+
rememberTodoOrigin(item.text, originTitle);
|
|
10041
|
+
mutate(t("todo.notice.movedToDone", { group: t("todo.doneGroup") }), next);
|
|
10042
|
+
return;
|
|
10043
|
+
}
|
|
10044
|
+
mutate(t("todo.notice.restored"), todoRestore(doc.content, item.line, recallTodoOrigin(item.text)));
|
|
10045
|
+
}
|
|
10046
|
+
|
|
10047
|
+
function onAdd(section, body) {
|
|
10048
|
+
mutate(t("todo.notice.added"), todoInsert(doc.content, section.insertAt, body));
|
|
10049
|
+
}
|
|
10050
|
+
|
|
10051
|
+
function onEdit(item, body) {
|
|
10052
|
+
mutate(t("todo.notice.edited"), todoReplace(doc.content, item.line, body));
|
|
10053
|
+
}
|
|
10054
|
+
|
|
10055
|
+
/** 删掉待删除块里的一条(只删那一行)。 */
|
|
10056
|
+
function onDelete(item) {
|
|
10057
|
+
mutate(t("todo.notice.deleted"), todoRemove(doc.content, [item.line]));
|
|
10058
|
+
}
|
|
10059
|
+
|
|
10060
|
+
/** 清空待删除块的**全部条目行**,`## 标题` 留着。 */
|
|
10061
|
+
function onClearDone() {
|
|
10062
|
+
const out = todoClearDoneBlock(doc.content);
|
|
10063
|
+
if (out.count === 0) return;
|
|
10064
|
+
mutate(t("todo.notice.cleared", { count: out.count }), out.next);
|
|
10065
|
+
}
|
|
10066
|
+
|
|
10067
|
+
function onUndo() {
|
|
10068
|
+
if (undoStack.length === 0) return;
|
|
10069
|
+
const target = undoStack[undoStack.length - 1];
|
|
10070
|
+
const point = currentPoint();
|
|
10071
|
+
writeSnapshot(target, t("todo.notice.undo"), function () {
|
|
10072
|
+
setUndoStack(function (prev) { return prev.slice(0, -1); });
|
|
10073
|
+
setRedoStack(function (prev) { return prev.concat([point]).slice(-TODO_UNDO_DEPTH); });
|
|
10074
|
+
});
|
|
10075
|
+
}
|
|
10076
|
+
|
|
10077
|
+
function onRedo() {
|
|
10078
|
+
if (redoStack.length === 0) return;
|
|
10079
|
+
const target = redoStack[redoStack.length - 1];
|
|
10080
|
+
const point = currentPoint();
|
|
10081
|
+
writeSnapshot(target, t("todo.notice.redone"), function () {
|
|
10082
|
+
setRedoStack(function (prev) { return prev.slice(0, -1); });
|
|
10083
|
+
setUndoStack(function (prev) { return prev.concat([point]).slice(-TODO_UNDO_DEPTH); });
|
|
10084
|
+
});
|
|
10085
|
+
}
|
|
10086
|
+
|
|
10087
|
+
if (!enabled) {
|
|
10088
|
+
return h("div", { className: "smem-todo-done-state" }, [
|
|
10089
|
+
h("div", { key: "t", className: "smem-todo-done-title" }, t("todo.disabled.title")),
|
|
10090
|
+
h("div", { key: "h", className: "smem-muted" }, t("todo.disabled.hint")),
|
|
10091
|
+
]);
|
|
10092
|
+
}
|
|
10093
|
+
|
|
10094
|
+
const parsed = doc && doc.parsed ? doc.parsed : parseTodoList("");
|
|
10095
|
+
const missing = doc && doc.missing;
|
|
10096
|
+
// 匹配口径:标题 + 正文 + 续行里任一处包含子串(大小写不敏感;不解释正则,免得用户被自己的输入坑)。
|
|
10097
|
+
const sections = query === "" ? parsed.sections : parsed.sections
|
|
10098
|
+
.map(function (sec) {
|
|
10099
|
+
const hit = sec.items.filter(function (it) {
|
|
10100
|
+
const hay = ((it.title || "") + " " + it.text + " " + (it.cont || "")).toLowerCase();
|
|
10101
|
+
return hay.indexOf(query) >= 0;
|
|
10102
|
+
});
|
|
10103
|
+
return { sec: sec, hit: hit };
|
|
10104
|
+
})
|
|
10105
|
+
.filter(function (row) { return row.hit.length > 0; })
|
|
10106
|
+
.map(function (row) { return Object.assign({}, row.sec, { items: row.hit }); });
|
|
10107
|
+
const matchCount = sections.reduce(function (n, sec) { return n + sec.items.length; }, 0);
|
|
10108
|
+
const stats = t("todo.stat", { open: parsed.open, done: parsed.done, sections: parsed.sections.length });
|
|
10109
|
+
// 「清空全部」清的是整个待删除块,数字取块的真实条数(搜索过滤后也一样)。
|
|
10110
|
+
const doneBlock = parsed.sections.find(function (sec) { return sec.kind === "done"; });
|
|
10111
|
+
const doneBlockCount = doneBlock ? doneBlock.items.length : 0;
|
|
10112
|
+
|
|
10113
|
+
return h("div", { className: "smem-todo" }, [
|
|
10114
|
+
h("div", { key: "head", className: "smem-todo-head" }, [
|
|
10115
|
+
h("span", { key: "s", className: "smem-todo-stat" }, query === "" ? stats : t("todo.search.count", { count: matchCount })),
|
|
10116
|
+
h("span", { key: "sp", "data-spring": "" }),
|
|
10117
|
+
h("button", {
|
|
10118
|
+
key: "u", type: "button", className: "smem-todo-icon-btn",
|
|
10119
|
+
title: t("todo.action.undo"), "aria-label": t("todo.action.undo"),
|
|
10120
|
+
disabled: busy || undoStack.length === 0,
|
|
10121
|
+
onClick: onUndo,
|
|
10122
|
+
}, todoArrowIcon("undo")),
|
|
10123
|
+
h("button", {
|
|
10124
|
+
key: "d", type: "button", className: "smem-todo-icon-btn",
|
|
10125
|
+
title: t("todo.action.redo"), "aria-label": t("todo.action.redo"),
|
|
10126
|
+
disabled: busy || redoStack.length === 0,
|
|
10127
|
+
onClick: onRedo,
|
|
10128
|
+
}, todoArrowIcon("redo")),
|
|
10129
|
+
h("button", { key: "a", type: "button", className: "smem-link smem-todo-mini", onClick: function () { setAllOpen(allOpen === true ? false : true); } }, allOpen === true ? t("todo.collapseAll") : t("todo.expandAll")),
|
|
10130
|
+
h("button", { key: "r", type: "button", className: "smem-link smem-todo-mini", disabled: busy, onClick: function () { load(false); } }, t("todo.refresh")),
|
|
10131
|
+
]),
|
|
10132
|
+
// 搜索框放统计条下面一行:右栏很窄,塞进同一行会把按钮挤没。
|
|
10133
|
+
h("div", { key: "search", className: "smem-todo-search-row" }, [
|
|
10134
|
+
h("input", {
|
|
10135
|
+
key: "q",
|
|
10136
|
+
className: "smem-input smem-todo-search",
|
|
10137
|
+
type: "search",
|
|
10138
|
+
placeholder: t("todo.search.placeholder"),
|
|
10139
|
+
value: rawQuery,
|
|
10140
|
+
onChange: function (e) { setQuery(e.target.value); },
|
|
10141
|
+
}),
|
|
10142
|
+
rawQuery === "" ? null : h("button", { key: "x", type: "button", className: "smem-link smem-todo-mini", onClick: function () { setQuery(""); } }, t("todo.action.cancel")),
|
|
10143
|
+
]),
|
|
10144
|
+
err ? h("div", { key: "err", className: "smem-err" }, "⚠ " + err) : null,
|
|
10145
|
+
notice ? h("div", { key: "ok", className: "smem-ok" }, "✓ " + notice) : null,
|
|
10146
|
+
missing
|
|
10147
|
+
? h("div", { key: "miss", className: "smem-todo-empty" }, t("todo.empty.file", { file: TODO_FILE }))
|
|
10148
|
+
: (query !== "" && sections.length === 0
|
|
10149
|
+
? h("div", { key: "nomatch", className: "smem-todo-empty" }, t("todo.search.none"))
|
|
10150
|
+
: h("div", { key: "groups", className: "smem-todo-groups" }, sections.map(function (sec, i) {
|
|
10151
|
+
return h(TodoSectionGroup, {
|
|
10152
|
+
key: "s" + i, section: sec, busy: busy, allOpen: query === "" ? allOpen : true,
|
|
10153
|
+
doneCount: doneBlockCount,
|
|
10154
|
+
onToggle: function (it, d) { onToggle(it, d, sec.title); },
|
|
10155
|
+
onAdd: onAdd, onEdit: onEdit, onDelete: onDelete, onClearDone: onClearDone,
|
|
10156
|
+
});
|
|
10157
|
+
}))),
|
|
10158
|
+
]);
|
|
10159
|
+
}
|
|
10160
|
+
|
|
10161
|
+
// ── 注册与热开关 ──────────────────────────────────────────────────
|
|
10162
|
+
|
|
10163
|
+
/** guide 条目(开始页那张卡片)。关掉开关时整条不给 —— 卡片随之消失。 */
|
|
10164
|
+
function todoBoardGuideEntry() {
|
|
10165
|
+
return {
|
|
10166
|
+
id: TODO_GUIDE_ID,
|
|
10167
|
+
order: 30,
|
|
10168
|
+
title: function () { return t("todo.guide.title"); },
|
|
10169
|
+
description: function () { return t("todo.guide.desc"); },
|
|
10170
|
+
};
|
|
10171
|
+
}
|
|
10172
|
+
|
|
10173
|
+
/**
|
|
10174
|
+
* 注册 / 重注册 tab 定义。**body 与 title 槽不在这里**(它们常驻,见 applyTodoBoard)。
|
|
10175
|
+
* @param {boolean} withGuide 是否带开始页卡片
|
|
10176
|
+
*/
|
|
10177
|
+
function registerTodoBoardDefinition(withGuide) {
|
|
10178
|
+
const ctx = todoBoardCtx;
|
|
10179
|
+
const tabs = ctx && typeof ctx.get === "function" ? ctx.get("sidebarRightTabs") : null;
|
|
10180
|
+
if (!tabs || typeof tabs.register !== "function") return false;
|
|
10181
|
+
if (todoBoardRegistryDispose !== null) {
|
|
10182
|
+
try { todoBoardRegistryDispose(); } catch (e) { /* 已经注销过就忽略 */ }
|
|
10183
|
+
todoBoardRegistryDispose = null;
|
|
10184
|
+
}
|
|
10185
|
+
try {
|
|
10186
|
+
todoBoardRegistryDispose = tabs.register({
|
|
10187
|
+
id: TODO_TAB_ID,
|
|
10188
|
+
kind: TODO_TAB_KIND,
|
|
10189
|
+
priority: "extension",
|
|
10190
|
+
title: function () { return t("todo.tabTitle"); },
|
|
10191
|
+
guide: withGuide ? [todoBoardGuideEntry()] : undefined,
|
|
10192
|
+
});
|
|
10193
|
+
return true;
|
|
10194
|
+
} catch (e) {
|
|
10195
|
+
todoBoardRegistryDispose = null;
|
|
10196
|
+
return false;
|
|
10197
|
+
}
|
|
10198
|
+
}
|
|
10199
|
+
|
|
10200
|
+
/** 打开一次页签(失败静默:宿主可能不支持程序化打开,用户点卡片也一样)。 */
|
|
10201
|
+
function openTodoBoardTab() {
|
|
10202
|
+
try {
|
|
10203
|
+
const nav = todoBoardCtx && typeof todoBoardCtx.get === "function" ? todoBoardCtx.get("sidebarRight") : null;
|
|
10204
|
+
if (nav && typeof nav.openTab === "function") nav.openTab(TODO_TAB_KIND);
|
|
10205
|
+
} catch (e) { /* 打不开不是错,卡片还在 */ }
|
|
10206
|
+
}
|
|
10207
|
+
|
|
10208
|
+
/**
|
|
10209
|
+
* 热开关的唯一入口:设置卡拨开关、apply 启动时都走这里。
|
|
10210
|
+
*
|
|
10211
|
+
* - 开:body / title 槽先注册好,再注册 definition(带 guide),最后试着开一次页签;
|
|
10212
|
+
* - 关:**只**重注册 definition(不带 guide)—— body 常驻,已开的页签切到「已关闭」态,
|
|
10213
|
+
* 不会变成孤儿页签,也不需要刷新页面。
|
|
10214
|
+
* @param {boolean} on
|
|
10215
|
+
*/
|
|
10216
|
+
function applyTodoBoard(on) {
|
|
10217
|
+
const next = !!on;
|
|
10218
|
+
todoBoardEnabled = next;
|
|
10219
|
+
const ctx = todoBoardCtx;
|
|
10220
|
+
if (ctx === null) { todoBoardNotify(); return; }
|
|
10221
|
+
if (next) {
|
|
10222
|
+
if (todoBoardBodyDispose === null) {
|
|
10223
|
+
try {
|
|
10224
|
+
todoBoardBodyDispose = ctx.slots.inject("sidebar.right.pane.tab", function () {
|
|
10225
|
+
return ctx.slots.register({ name: "sidebar.right.pane.tab", key: TODO_TAB_ID }, function (props) {
|
|
10226
|
+
// 把 ctx 传进正文:正文只用标准 hooks + 我们自己的 remote,不额外依赖宿主内部。
|
|
10227
|
+
return react.createElement(TodoBoard, Object.assign({}, props, { ctx: ctx }));
|
|
10228
|
+
});
|
|
10229
|
+
});
|
|
10230
|
+
todoBoardTitleDispose = ctx.slots.inject("sidebar.right.pane.tab.title", function () {
|
|
10231
|
+
return ctx.slots.register({ name: "sidebar.right.pane.tab.title", key: TODO_TAB_ID }, function () {
|
|
10232
|
+
return h("span", null, t("todo.tabTitle"));
|
|
10233
|
+
});
|
|
10234
|
+
});
|
|
10235
|
+
} catch (e) {
|
|
10236
|
+
todoBoardBodyDispose = null;
|
|
10237
|
+
todoBoardTitleDispose = null;
|
|
10238
|
+
}
|
|
10239
|
+
}
|
|
10240
|
+
if (!todoBoardGuideShown) {
|
|
10241
|
+
if (registerTodoBoardDefinition(true)) {
|
|
10242
|
+
todoBoardGuideShown = true;
|
|
10243
|
+
openTodoBoardTab();
|
|
10244
|
+
}
|
|
10245
|
+
}
|
|
10246
|
+
} else if (todoBoardBodyDispose !== null && todoBoardGuideShown) {
|
|
10247
|
+
// body 常驻、只摘掉 guide:已打开的页签留下,正文切到「已关闭」态。
|
|
10248
|
+
if (registerTodoBoardDefinition(false)) todoBoardGuideShown = false;
|
|
10249
|
+
}
|
|
10250
|
+
todoBoardNotify();
|
|
10251
|
+
}
|
|
10252
|
+
|
|
10253
|
+
/** 宿主有没有右侧栏能力(设置卡据此置灰 / 解释)。 */
|
|
10254
|
+
function todoBoardHostSupported(ctx) {
|
|
10255
|
+
try {
|
|
10256
|
+
const tabs = ctx && typeof ctx.get === "function" ? ctx.get("sidebarRightTabs") : null;
|
|
10257
|
+
return !!(tabs && typeof tabs.register === "function");
|
|
10258
|
+
} catch (e) { return false; }
|
|
10259
|
+
}
|
|
10260
|
+
|
|
10261
|
+
/** 实验性页里的那张卡:开关 + 三句话(这是什么 / 立刻生效 / 宿主不支持时置灰)。 */ function TodoBoardLabCard(props) {
|
|
10262
|
+
const ctx = props.ctx;
|
|
10263
|
+
const remote = stableRemote(ctx, "remote.memory");
|
|
10264
|
+
const supported = todoBoardHostSupported(ctx);
|
|
10265
|
+
const sOn = react.useState(todoBoardEnabled);
|
|
10266
|
+
const on = sOn[0], setOn = sOn[1];
|
|
10267
|
+
const sBusy = react.useState(false); const busy = sBusy[0], setBusy = sBusy[1];
|
|
10268
|
+
const sErr = react.useState(null); const err = sErr[0], setErr = sErr[1];
|
|
10269
|
+
const sNotice = react.useState(""); const notice = sNotice[0], setNotice = sNotice[1];
|
|
10270
|
+
|
|
10271
|
+
// 初次挂载:以宿主设置里的值为准(模块加载时那份 + 待生效那份对 live 开关是一致的)。
|
|
10272
|
+
react.useEffect(function () {
|
|
10273
|
+
const m = stableRemote(ctx, "remote.memory");
|
|
10274
|
+
if (!m || typeof m.getSettings !== "function") return;
|
|
10275
|
+
Promise.resolve(m.getSettings()).then(function (res) {
|
|
10276
|
+
const d = unwrap(res) || {};
|
|
10277
|
+
const value = d.pendingExperimental && typeof d.pendingExperimental.todoBoard === "number"
|
|
10278
|
+
? d.pendingExperimental.todoBoard
|
|
10279
|
+
: (d.experimental && d.experimental.todoBoard) || 0;
|
|
10280
|
+
setOn(value > 0);
|
|
10281
|
+
applyTodoBoard(value > 0);
|
|
10282
|
+
}, function () { /* 读不到就按当前内存态显示 */ });
|
|
10283
|
+
}, [ctx]);
|
|
10284
|
+
|
|
10285
|
+
function toggle() {
|
|
10286
|
+
const next = on ? 0 : 1;
|
|
10287
|
+
setBusy(true); setErr(null); setNotice("");
|
|
10288
|
+
Promise.resolve(remote.setSettings({ experimental: { todoBoard: next } })).then(function (out) {
|
|
10289
|
+
setBusy(false);
|
|
10290
|
+
// setSettings 自带 {ok, settings, restartRequired}:直接读,不要 unwrap。
|
|
10291
|
+
if (out && out.ok === false) { setErr(out.error || t("todo.lab.rejected")); return; }
|
|
10292
|
+
setOn(next > 0);
|
|
10293
|
+
applyTodoBoard(next > 0);
|
|
10294
|
+
setNotice(t(next > 0 ? "todo.lab.onNotice" : "todo.lab.offNotice"));
|
|
10295
|
+
}, function (e) { setBusy(false); setErr(String((e && e.message) || e)); });
|
|
10296
|
+
}
|
|
10297
|
+
|
|
10298
|
+
return h("div", { className: "smem-todo-lab smem-module-card" }, [
|
|
10299
|
+
h("div", { className: "smem-modcard-head", key: "head" }, [
|
|
10300
|
+
h(Switch, {
|
|
10301
|
+
key: "sw",
|
|
10302
|
+
on: on,
|
|
10303
|
+
label: t("todo.lab.switch"),
|
|
10304
|
+
title: supported ? t("todo.lab.switch.title") : t("todo.lab.unsupported"),
|
|
10305
|
+
disabled: busy || !supported,
|
|
10306
|
+
onClick: toggle,
|
|
10307
|
+
}),
|
|
10308
|
+
h("span", { className: "smem-modcard-title", key: "t" }, t("todo.lab.title")),
|
|
10309
|
+
h("span", { className: "smem-modcard-status", key: "s" }, on ? t("todo.lab.status.on") : t("todo.lab.status.off")),
|
|
10310
|
+
]),
|
|
10311
|
+
h("div", { className: "smem-autodream-sec", key: "what" }, [
|
|
10312
|
+
h("div", { className: "smem-autodream-note", key: "p1" }, t("todo.lab.what")),
|
|
10313
|
+
h("div", { className: "smem-autodream-note", key: "p2" }, t("todo.lab.live")),
|
|
10314
|
+
supported ? null : h("div", { className: "smem-autodream-note", key: "p3" }, t("todo.lab.unsupported")),
|
|
10315
|
+
]),
|
|
10316
|
+
err ? h("div", { className: "smem-err", key: "err" }, "⚠ " + err) : null,
|
|
10317
|
+
notice ? h("div", { className: "smem-ok", key: "ok" }, "✓ " + notice) : null,
|
|
10318
|
+
]);
|
|
10319
|
+
}
|
|
10320
|
+
|
|
10321
|
+
// 测试缝:解析与行级手术是纯函数,而在 factory 闭包里外面拿不到 ——
|
|
10322
|
+
// 只给 `test/todo-board-test.mjs` 用,运行期没有任何代码读它(宿主只认 apply / inject)。
|
|
10323
|
+
exports.todoBoardInternals = {
|
|
10324
|
+
FILE: TODO_FILE,
|
|
10325
|
+
TAB_KIND: TODO_TAB_KIND,
|
|
10326
|
+
DONE_HEADING: TODO_DONE_HEADING,
|
|
10327
|
+
UNDO_DEPTH: TODO_UNDO_DEPTH,
|
|
10328
|
+
parse: parseTodoList,
|
|
10329
|
+
titleOf: todoItemTitle,
|
|
10330
|
+
bullet: todoBullet,
|
|
10331
|
+
doneRange: todoDoneRange,
|
|
10332
|
+
moveToDone: todoMoveToDone,
|
|
10333
|
+
restore: todoRestore,
|
|
10334
|
+
insert: todoInsert,
|
|
10335
|
+
replace: todoReplace,
|
|
10336
|
+
remove: todoRemove,
|
|
10337
|
+
clearDoneBlock: todoClearDoneBlock,
|
|
10338
|
+
rememberOrigin: rememberTodoOrigin,
|
|
10339
|
+
recallOrigin: recallTodoOrigin,
|
|
10340
|
+
arrowIcon: todoArrowIcon,
|
|
10341
|
+
isEnabled: function () { return todoBoardEnabled; },
|
|
10342
|
+
notify: todoBoardNotify,
|
|
10343
|
+
};
|
|
9235
10344
|
// ⚠️ 不把 `layout` 写进 inject:它是**可选**依赖(官方 inspect:optional access =
|
|
9236
10345
|
// `ctx.get("layout")` + 判空;hardDependency 才是 inject)。写进 inject 会让旧外壳
|
|
9237
10346
|
// 缺这个服务时整个 client 插件不 apply —— 连带丢掉设置页。返回会话优先用宿主给的
|
|
@@ -9273,6 +10382,24 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
9273
10382
|
}
|
|
9274
10383
|
applyEntryMode(initialMode);
|
|
9275
10384
|
|
|
10385
|
+
// ── 2.11.0 实验性「待办清单」看板 ────────────────────────────────
|
|
10386
|
+
// 开关住在设置页「实验性」,但**消费方是 client**(右侧栏注册)→ 启动读一次,
|
|
10387
|
+
// 之后由设置卡调 applyTodoBoard 热切换,不参与 restartRequired
|
|
10388
|
+
// (宿主 `EXPERIMENTAL_SPECS.todoBoard` 标了 `live: true`)。
|
|
10389
|
+
todoBoardCtx = ctx;
|
|
10390
|
+
try {
|
|
10391
|
+
const memBoard = typeof ctx.get === "function" ? ctx.get("remote.memory") : null;
|
|
10392
|
+
let boardOn = false;
|
|
10393
|
+
if (memBoard && typeof memBoard.getSettings === "function") {
|
|
10394
|
+
const loadedBoard = unwrap(await memBoard.getSettings()) || {};
|
|
10395
|
+
const lab = loadedBoard.pendingExperimental || loadedBoard.experimental || {};
|
|
10396
|
+
boardOn = typeof lab.todoBoard === "number" && lab.todoBoard > 0;
|
|
10397
|
+
}
|
|
10398
|
+
applyTodoBoard(boardOn);
|
|
10399
|
+
} catch (e) {
|
|
10400
|
+
applyTodoBoard(false);
|
|
10401
|
+
}
|
|
10402
|
+
|
|
9276
10403
|
// ── 1.8.2 / 2.7.0 插件详情页的「界面入口」折叠行 ────────────────────
|
|
9277
10404
|
// `plugins.bundle.config` 是 keyed 槽,key = 本 bundle 的 **package name**(sage-mem)。
|
|
9278
10405
|
// 宿主在插件页的 description 与「包含的组件」行之间渲染它;ownerProps 形如
|