nx-kv 0.36.0 → 0.39.0

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/package.json +1 -1
  3. package/src/modules/tasktool/delivery-text.js +6 -1
  4. package/src/modules/tasktool/wait.js +4 -1
  5. package/src/shared/feedback-text.js +70 -0
  6. package/src/web/frontend/components/md/attach-modal.jsx +3 -2
  7. package/src/web/frontend/components/md/composer-panel.jsx +190 -3
  8. package/src/web/frontend/components/md/md-panes.jsx +7 -3
  9. package/src/web/frontend/modules/md/md-history.js +3 -2
  10. package/src/web/frontend/page/dir/task.jsx +3 -2
  11. package/src/web/public/assets/Introduction-CeSTbmC_.js +1 -0
  12. package/src/web/public/assets/{bar-P_ky_qA9.js → bar-0vbv5yFz.js} +1 -1
  13. package/src/web/public/assets/{cloud-Bl7EJoQ_.js → cloud-DGXxRwk4.js} +1 -1
  14. package/src/web/public/assets/composer-launch-aakss0WJ.js +1 -0
  15. package/src/web/public/assets/composer-panel-B6T-BghV.js +1 -0
  16. package/src/web/public/assets/{dag-NSMkkWrt.js → dag-V_76Nqrc.js} +1 -1
  17. package/src/web/public/assets/{dir-ClkYDLql.js → dir-CEeSaei-.js} +1 -1
  18. package/src/web/public/assets/{group-DqBGGAEA.js → group-BUXDWN7i.js} +1 -1
  19. package/src/web/public/assets/{index-CLsU9Lad.js → index-LxDjPSPW.js} +2 -2
  20. package/src/web/public/assets/md-history-fHJjXhD5.js +28 -0
  21. package/src/web/public/assets/{overview-CFGcpG_m.js → overview-TZ3xgLjh.js} +1 -1
  22. package/src/web/public/assets/{progress-B0fipz7a.js → progress-C-W4pFvn.js} +1 -1
  23. package/src/web/public/assets/{refs-DLThlN46.js → refs-DIe203qP.js} +1 -1
  24. package/src/web/public/assets/{repos-BygXrPSp.js → repos-Bn96_hfN.js} +1 -1
  25. package/src/web/public/assets/{route-crumb-Cyesq6KK.js → route-crumb-D8gsnddf.js} +1 -1
  26. package/src/web/public/assets/{settings-KHM4F3Sy.js → settings-Ckh48Wyt.js} +1 -1
  27. package/src/web/public/assets/{status-tag-Bts7p2cp.js → status-tag-QcrMsfsV.js} +1 -1
  28. package/src/web/public/assets/task-C6oOO9CS.js +11 -0
  29. package/src/web/public/assets/templates-CMH9LARB.js +1 -0
  30. package/src/web/public/assets/tool-bar-DwWOMBqs.js +1 -0
  31. package/src/web/public/index.html +1 -1
  32. package/src/web/public/assets/Introduction-EDM3eqXe.js +0 -1
  33. package/src/web/public/assets/composer-launch-DOB0Hm0B.js +0 -1
  34. package/src/web/public/assets/composer-panel-DCV7JGNt.js +0 -1
  35. package/src/web/public/assets/md-history-Uo6U7hYS.js +0 -1
  36. package/src/web/public/assets/md-panes-DMs3KANu.js +0 -28
  37. package/src/web/public/assets/task-BoJGRYpA.js +0 -11
  38. package/src/web/public/assets/templates-CdPNcDxd.js +0 -1
  39. package/src/web/public/assets/tool-bar-Bh3XH8MU.js +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.39.0] - 2026-11-09 交付上下文「倒序聚焦 + 历史精简」
6
+
7
+ ### Changed
8
+
9
+ - **交付提示词轮次重排(#157)**:多轮任务交付给 agent 的正文原本按时间**正序**
10
+ 平铺轮次 callout——最新一轮的验收反馈被压在最底(LLM 对首尾注意力最高),
11
+ 历史轮次全文占大量 token。交付渲染时(CLI get/preview 与面板预览同一份
12
+ `buildTaskDelivery`/`deliveryBodyText`)重排为:任务骨架置顶 → **最新一轮**
13
+ 验收反馈 + 完成总结完整呈现 → **历史轮次各一行摘要**(反馈「…」;总结「…」,
14
+ 截 60 字,标注仅供追溯)。无轮次段的正文原样返回,零影响;面板正文/定位轨
15
+ 等人读视图不受影响(只动交付渲染)。
16
+
17
+ ## [0.38.0] - 2026-11-09 编辑器撤销修复
18
+
19
+ ### Fixed
20
+
21
+ - **编辑器 Ctrl+Z 撤销失效(#156)**,两个叠加的根因:
22
+ 1. **typing 合并语义错误**——合并窗口内用「每个键的前置快照」覆盖栈顶,段内
23
+ 逐键覆盖后栈顶只剩最后一个字符的前置快照:Ctrl+Z 一次只退一个字符、再按
24
+ 就卡死。改为合并窗口**不动 past**(保留段首快照),撤销一次回退整段输入;
25
+ 2. **反馈/评论编辑页没接撤销栈**——composer 的 MdPanes 未传 onUndo/onRedo,
26
+ 而按键拦截无条件 preventDefault 原生撤销再调 null:连原生 textarea 撤销
27
+ 都被拦死。composer 接入 md-history(自己的撤销栈 + Ctrl+Z/Ctrl+⇧Z),
28
+ 按键拦截改为只在页面接了自定义历史时才拦截(其余页面回落浏览器原生)。
29
+ 新增 tests/unit/md-history.test.mjs(5 条钉子:整段撤销/分段/op 独立条/
30
+ redo/空栈)。
31
+
32
+ ## [0.37.0] - 2026-11-09 反馈/评论编辑页附件 dock
33
+
34
+ ### Added
35
+
36
+ - **反馈 / 评论编辑页底部附件框(#155)**:composer 页补上与任务页同款的
37
+ `mdw-dock` 信息面板——「附件」tab(计数徽标 + AttachBar 列表 + 「+」添加
38
+ 文件 + 拖高/最大化/关闭)+ 底部状态栏开关,高度与开关独立存
39
+ (`nxkv.cmpDock*`);附件随提交走原通道(新任务/回写正文)。
40
+
41
+ ### Fixed
42
+
43
+ - **隐藏文件输入的 FileList 清空 bug(随 #155 发现)**:`e.target.value = ''`
44
+ 会清空活的 FileList(先拿引用再清 → `length` 归零,一个文件都拿不到)——
45
+ 反馈/评论页「+」、任务页「添加附件」、附件弹窗三处改为先拷贝再清。
46
+
5
47
  ## [0.36.0] - 2026-11-09 仓库表操作列钉宽
6
48
 
7
49
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.36.0",
3
+ "version": "0.39.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,11 +9,16 @@
9
9
  //
10
10
  // 排版口径:instruction 自包含正文(模板含 {{task.text}},服务端给出 coversBody)
11
11
  // 时直接替掉正文块(否则正文会出现两遍);否则「正文 + ── 收尾指令 ──」两段。
12
+ // 正文交给阅读方前统一做「倒序聚焦 + 历史精简」重排(#157,shared/feedback-text.js)。
13
+ import { reorderRoundsForDelivery } from '../../shared/feedback-text.js';
14
+
12
15
  export function deliveryBodyText(r) {
13
16
  const indent = (s) => String(s).replace(/\n/g, '\n ');
14
17
  const taskText = (r && r.task && r.task.text) || '';
15
18
  if (r && r.instruction && r.coversBody) return ` ${indent(r.instruction)}`;
16
- const body = ` ${indent(taskText)}`;
19
+ // 正文交给阅读方前做「倒序聚焦 + 历史精简」重排(#157):最新轮反馈/总结置顶,
20
+ // 历史轮次一行摘要——无轮次段的正文原样返回,零影响。
21
+ const body = ` ${indent(reorderRoundsForDelivery(taskText))}`;
17
22
  return r && r.instruction ? `${body}\n ── 收尾指令 ──\n ${indent(r.instruction)}` : body;
18
23
  }
19
24
 
@@ -12,6 +12,7 @@ import { DEFAULT_PORT } from '../../core/paths.js';
12
12
  import { formatGoalTiming, renderInstruction } from '../../core/instruction-template.js';
13
13
  import { buildDeliveryCtx } from './delivery-template.js';
14
14
  import { parseFrontmatter } from '../../shared/frontmatter.js';
15
+ import { reorderRoundsForDelivery } from '../../shared/feedback-text.js';
15
16
  import {
16
17
  BLOCK_DEFS,
17
18
  resolveBlockTemplates,
@@ -206,7 +207,9 @@ export async function buildTaskDelivery(task, { source, summary, cwd, name, topi
206
207
  ? { ...goal, check: goalCheck || '', statusLine: goalStatus || '' }
207
208
  : null,
208
209
  ...attachCtx,
209
- task: task ? { id: task.id, text: String(task.text || '') } : null,
210
+ // task.text 交给模板前做「倒序聚焦 + 历史精简」重排(#157):最新轮反馈
211
+ // 与总结置顶、历史轮次一行摘要——无轮次段的正文原样返回,零影响。
212
+ task: task ? { id: task.id, text: reorderRoundsForDelivery(String(task.text || '')) } : null,
210
213
  // 「持续 get」指令模板自身也能用 {{getloop.waitMinutes}}:先把阻塞窗口放进
211
214
  // 同一份 ctx,外层 getloop 区块再补 text(同一个对象口径,前后不分裂)。
212
215
  getloop: { text: '', waitMinutes: Number(getLoopWaitMinutes) || 0 },
@@ -173,3 +173,73 @@ export function appendAckFeedback({ base, ack, quote, feedback, bold = true, rou
173
173
  if (!parts.length) return '';
174
174
  return `${parts.join('\n\n')}\n`;
175
175
  }
176
+
177
+ // ─── 交付侧上下文重排(#157「倒序聚焦 + 历史精简」)──────────────────
178
+ //
179
+ // 正文里的轮次 callout 按时间**正序**追加在末尾——agent 收到的提示词里最新
180
+ // 一轮的验收反馈被压在最底,而 LLM 对首尾内容的注意力最高;历史轮次的总结
181
+ // 保留全文占大量 token 且干扰当前决策。交付渲染时重排为:
182
+ //
183
+ // 1. 任务骨架(frontmatter + 原始需求等非轮次内容,保持原位)
184
+ // 2. 最新一轮**完整内容**:验收反馈(当前要改什么)→ 完成总结(上轮做到哪)
185
+ // 3. 历史轮次各一行摘要(反馈「…」;总结「…」——仅供追溯)
186
+ //
187
+ // 纯函数、零依赖;无轮次段时原样返回(老任务 / 单轮任务零影响)。
188
+
189
+ const DELIVERY_ROUND_RE = /^>\s*\[![A-Za-z][\w-]*\][^\n]*第\s*(\d+)\s*轮[^\n]*(完成总结|验收反馈)/;
190
+
191
+ const truncLine = (s, n = 60) => {
192
+ const t = String(s || '').trim();
193
+ return t.length > n ? `${t.slice(0, n)}…` : t;
194
+ };
195
+
196
+ /** callout 块里剥掉标题行 / `>` 前缀 / 加粗记号后的首个非空行(历史摘要用) */
197
+ function firstContentLine(block) {
198
+ const line = String(block || '')
199
+ .split('\n')
200
+ .filter((l) => l.trim() && !CALLOUT_TITLE_RE.test(l))
201
+ .map((l) => l.replace(/^>\s?/, '').replace(/\*\*/g, '').trim())
202
+ .find((l) => l);
203
+ return line || '';
204
+ }
205
+
206
+ export function reorderRoundsForDelivery(body) {
207
+ const text = String(body ?? '');
208
+ if (!text) return text;
209
+ const blocks = text.split(/\n{2,}/);
210
+ const rounds = new Map(); // n → { ack, fb }
211
+ const plain = [];
212
+ for (const b of blocks) {
213
+ const m = b.match(DELIVERY_ROUND_RE);
214
+ if (m) {
215
+ const n = Number(m[1]);
216
+ const r = rounds.get(n) || {};
217
+ if (m[2] === '完成总结') r.ack = b;
218
+ else r.fb = b;
219
+ rounds.set(n, r);
220
+ continue;
221
+ }
222
+ plain.push(b);
223
+ }
224
+ if (!rounds.size) return text;
225
+ const nums = [...rounds.keys()].sort((a, b) => a - b);
226
+ const latest = nums[nums.length - 1];
227
+ const out = [];
228
+ if (plain.length) out.push(plain.join('\n\n'));
229
+ const lr = rounds.get(latest) || {};
230
+ // 最新一轮:反馈(当前要改什么)在前,总结(上轮做到哪)随后
231
+ if (lr.fb) out.push(lr.fb);
232
+ if (lr.ack) out.push(lr.ack);
233
+ const older = nums.filter((n) => n !== latest);
234
+ if (older.length) {
235
+ const lines = older.map((n) => {
236
+ const r = rounds.get(n) || {};
237
+ const parts = [];
238
+ if (r.fb) parts.push(`反馈「${truncLine(firstContentLine(r.fb))}」`);
239
+ if (r.ack) parts.push(`总结「${truncLine(firstContentLine(r.ack))}」`);
240
+ return `· 第 ${n} 轮 ${parts.join(';') || '(空)'}`;
241
+ });
242
+ out.push(`—— 历史轮次(已按最新反馈推进,仅供追溯)——\n${lines.join('\n')}`);
243
+ }
244
+ return `${out.join('\n\n')}\n`;
245
+ }
@@ -275,9 +275,10 @@ export default function AttachModal({
275
275
  multiple
276
276
  hidden
277
277
  onChange={(e) => {
278
- const f = e.target.files;
278
+ // ⚠️ 先拷贝再清 value:FileList 是活引用,`value = ''` 会把它清空
279
+ const files = Array.from(e.target.files || []);
279
280
  e.target.value = '';
280
- addFiles(f);
281
+ addFiles(files);
281
282
  }}
282
283
  />
283
284
  </div>
@@ -5,16 +5,23 @@
5
5
  // 底部:提交(评论 = 回写本任务;反馈 = 新开一条任务)。
6
6
  //
7
7
  // 提交逻辑在任务页那边(带会话状态),这里按 token 取回回调——见 composer-launch.js。
8
- import { useRef, useState } from 'react';
8
+ import { useEffect, useRef, useState } from 'react';
9
9
  import { MdPanes } from './md-panes.jsx';
10
+ import AttachBar from './attach-bar.jsx';
11
+ import { Icon } from '../icons.jsx';
10
12
  import { filesToAttachments } from './attachments.js';
11
13
  import { insertAttachmentSnippet } from '../../modules/md/md-parse.js';
12
14
  import { composerOf, restoreComposerSource } from './composer-launch.js';
15
+ import { pushHistory, undoHistory, redoHistory, clearHistory } from '../../modules/md/md-history.js';
13
16
  import { useApp } from '../../app-context.jsx';
14
17
  import { useToast } from '../toast/index.jsx';
15
18
  import { openBesideMain } from '../../workspace.js';
16
19
  import '../../modules/md/style.css';
17
20
 
21
+ // 底部附件 dock(#155):与任务页 mdw-dock 同一套视觉;高度/开关单独存
22
+ // (nxkv.cmpDock*,不与任务页的 nxkv.taskDock* 串台)。
23
+ const DOCK_MIN = 96;
24
+
18
25
  export default function ComposePanel({
19
26
  token,
20
27
  mode = 'comment',
@@ -31,13 +38,34 @@ export default function ComposePanel({
31
38
  const [busy, setBusy] = useState(false);
32
39
  const editorApiRef = useRef(null);
33
40
  const isFeedback = mode === 'feedback';
41
+ // 撤销栈(#156):composer 自己一份——MdPanes 的按键拦截会吃掉 Ctrl+Z 再调
42
+ // onUndo;不接历史的话原生撤销也一起被拦死(「编辑器无法撤回」的根因)。
43
+ const histRef = useRef(new Map());
44
+ const histId = 'compose-' + token;
34
45
 
35
46
  // 收尾:把**来源面板**放回主区(#106)——主区是单面板位,评论页把任务页
36
- // 顶掉了;不放回去主区就空掉,只剩侧边栏。
47
+ // 顶掉了;不放回去主区就空掉,只剩侧边栏。撤销栈一并销号(防泄漏)。
37
48
  const finish = () => {
49
+ clearHistory(histRef.current, histId);
38
50
  restoreComposerSource(app.model, token);
39
51
  };
40
52
 
53
+ // 正文写入统一走这里:先记历史再改状态(Ctrl+Z / Ctrl+⇧Z 走同一份栈)
54
+ const onBody = (next, kind = 'op') => {
55
+ pushHistory(histRef.current, histId, { title: '', body }, kind);
56
+ setBody(next);
57
+ };
58
+ const undo = () => {
59
+ const snap = undoHistory(histRef.current, histId, { title: '', body });
60
+ if (!snap) return;
61
+ setBody(snap.body);
62
+ };
63
+ const redo = () => {
64
+ const snap = redoHistory(histRef.current, histId, { title: '', body });
65
+ if (!snap) return;
66
+ setBody(snap.body);
67
+ };
68
+
41
69
  const submit = async () => {
42
70
  const text = String(body || '').trim();
43
71
  if (!text && !attachments.length) {
@@ -69,6 +97,55 @@ export default function ComposePanel({
69
97
  if (items.length) setAttachments((a) => [...a, ...items]);
70
98
  };
71
99
 
100
+ // ─── 底部附件 dock(#155):任务页同款信息面板,附件收进去不再占编辑区 ───
101
+ const fileRef = useRef(null);
102
+ const [dockOpen, setDockOpen] = useState(() => localStorage.getItem('nxkv.cmpDockOpen') !== '0');
103
+ const [dockH, setDockH] = useState(() => {
104
+ const v = Number(localStorage.getItem('nxkv.cmpDockH'));
105
+ return Number.isFinite(v) && v >= DOCK_MIN ? v : 176;
106
+ });
107
+ const dockHRef = useRef(dockH);
108
+ dockHRef.current = dockH;
109
+ const [dockMax, setDockMax] = useState(false);
110
+ const dockPrevHRef = useRef(176);
111
+ useEffect(() => {
112
+ localStorage.setItem('nxkv.cmpDockOpen', dockOpen ? '1' : '0');
113
+ }, [dockOpen]);
114
+ const toggleDockMax = () => {
115
+ if (dockMax) {
116
+ setDockH(dockPrevHRef.current);
117
+ setDockMax(false);
118
+ return;
119
+ }
120
+ dockPrevHRef.current = dockH;
121
+ const hostH = document.querySelector('.cmp')?.clientHeight || window.innerHeight;
122
+ setDockH(Math.max(DOCK_MIN, Math.round(hostH * 0.62)));
123
+ setDockMax(true);
124
+ };
125
+ const onDockDragStart = (e) => {
126
+ if (!dockOpen) return;
127
+ e.preventDefault();
128
+ setDockMax(false);
129
+ const startY = e.clientY;
130
+ const startH = dockHRef.current;
131
+ const clamp = (h) => Math.max(DOCK_MIN, Math.min(Math.round(h), Math.round((document.querySelector('.cmp')?.clientHeight || window.innerHeight) * 0.62)));
132
+ const move = (ev) => {
133
+ dockHRef.current = clamp(startH - (ev.clientY - startY));
134
+ setDockH(dockHRef.current);
135
+ };
136
+ const up = () => {
137
+ window.removeEventListener('mousemove', move);
138
+ window.removeEventListener('mouseup', up);
139
+ document.body.style.userSelect = '';
140
+ document.body.style.cursor = '';
141
+ localStorage.setItem('nxkv.cmpDockH', String(dockHRef.current));
142
+ };
143
+ document.body.style.userSelect = 'none';
144
+ document.body.style.cursor = 'row-resize';
145
+ window.addEventListener('mousemove', move);
146
+ window.addEventListener('mouseup', up);
147
+ };
148
+
72
149
  // 点引用区 → 主区右侧并排打开**原文**(旁路原文面板),方便对照(#107)
73
150
  const openOriginal = () => {
74
151
  const m = app.model;
@@ -153,15 +230,125 @@ export default function ComposePanel({
153
230
  title=""
154
231
  body={body}
155
232
  onTitle={() => {}}
156
- onBody={setBody}
233
+ onBody={onBody}
157
234
  attachments={attachments}
158
235
  docKey={'compose-' + token}
159
236
  editorApiRef={editorApiRef}
160
237
  onFiles={onFiles}
161
238
  onSave={submit}
239
+ onUndo={undo}
240
+ onRedo={redo}
162
241
  hideTitle
163
242
  />
164
243
  </div>
244
+
245
+ {/* ─── 底部附件 dock(#155):反馈/评论页与任务页同款信息面板 ─── */}
246
+ {dockOpen && (
247
+ <div className="mdw-dock" style={{ height: `${dockH}px` }}>
248
+ <div
249
+ className="mdw-dock-drag"
250
+ role="separator"
251
+ aria-orientation="horizontal"
252
+ title="上下拖动调整信息面板高度(双击最大化 / 还原)"
253
+ onMouseDown={onDockDragStart}
254
+ onDoubleClick={toggleDockMax}
255
+ />
256
+ <div className="mdw-dock-head">
257
+ <div className="mdw-dock-tabs" role="tablist" aria-label="信息面板">
258
+ <button
259
+ type="button"
260
+ role="tab"
261
+ aria-selected="true"
262
+ className="mdw-dock-tab is-on"
263
+ onClick={() => setDockOpen(true)}
264
+ >
265
+ 附件
266
+ {attachments.length ? <span className="mdw-dock-tab-num">{attachments.length}</span> : null}
267
+ </button>
268
+ </div>
269
+ <div className="mdw-dock-acts">
270
+ <button
271
+ type="button"
272
+ className="mdw-dock-act"
273
+ title="添加附件"
274
+ aria-label="添加附件"
275
+ onClick={() => fileRef.current?.click()}
276
+ >
277
+ <Icon name="plus" />
278
+ </button>
279
+ <button
280
+ type="button"
281
+ className="mdw-dock-act"
282
+ onClick={toggleDockMax}
283
+ title={dockMax ? '还原面板高度' : '最大化面板高度'}
284
+ aria-label={dockMax ? '还原面板高度' : '最大化面板高度'}
285
+ >
286
+ <Icon name={dockMax ? 'collapse' : 'expand'} />
287
+ </button>
288
+ <button
289
+ type="button"
290
+ className="mdw-dock-act"
291
+ onClick={() => setDockOpen(false)}
292
+ title="关闭面板(底部状态栏仍保留入口)"
293
+ aria-label="关闭面板"
294
+ >
295
+ <Icon name="x" />
296
+ </button>
297
+ </div>
298
+ </div>
299
+ <div className="mdw-dock-body">
300
+ {attachments.length ? (
301
+ <AttachBar
302
+ attachments={attachments}
303
+ onRemove={(aid) => setAttachments((a) => a.filter((x) => x.id !== aid))}
304
+ />
305
+ ) : (
306
+ <div className="mdw-dock-empty">
307
+ 还没有附件——粘贴 / 拖图片进正文即附件,或点右上「+」添加文件。
308
+ </div>
309
+ )}
310
+ </div>
311
+ </div>
312
+ )}
313
+
314
+ {/* ─── 底部状态栏:附件入口 + 面板开关(dock 关了仍能从这打开) ─── */}
315
+ <div className="mdw-sbar">
316
+ <button
317
+ type="button"
318
+ className={`mdw-sbar-item${dockOpen ? ' is-on' : ''}`}
319
+ onClick={() => setDockOpen((v) => !v)}
320
+ title="附件(点击展开/收起信息面板)"
321
+ >
322
+ <Icon name="list" />
323
+ <span className="mdw-sbar-lab">附件</span>
324
+ {attachments.length ? <span className="mdw-sbar-num">{attachments.length}</span> : null}
325
+ </button>
326
+ <span className="mdw-sbar-grow" />
327
+ <button
328
+ type="button"
329
+ className={`mdw-sbar-chev${dockOpen ? ' is-open' : ''}`}
330
+ onClick={() => setDockOpen((v) => !v)}
331
+ title={dockOpen ? '收起信息面板' : '展开信息面板'}
332
+ aria-expanded={dockOpen}
333
+ aria-label={dockOpen ? '收起信息面板' : '展开信息面板'}
334
+ >
335
+ <Icon name="chevron" />
336
+ </button>
337
+ </div>
338
+
339
+ <input
340
+ ref={fileRef}
341
+ type="file"
342
+ multiple
343
+ hidden
344
+ onChange={(e) => {
345
+ // ⚠️ 先拷贝再清 value:`e.target.files` 是活的 FileList,`value = ''`
346
+ // 会把它清空(引用还在、length 归零)——先清后读就一个文件都拿不到。
347
+ const files = Array.from(e.target.files || []);
348
+ e.target.value = '';
349
+ if (files.length) onFiles(files);
350
+ }}
351
+ />
165
352
  </div>
166
353
  );
167
354
  }
@@ -1588,14 +1588,18 @@ export const MdPanes = forwardRef(function MdPanes(
1588
1588
  return;
1589
1589
  }
1590
1590
  if (k === 'z') {
1591
+ // 只在页面接了自定义历史时拦截(#156)——没接的页面(如外部只读视图)
1592
+ // 回落浏览器原生撤销,别把原生 textarea 撤销也一起 preventDefault 掉
1593
+ const h = e.shiftKey ? onRedo : onUndo;
1594
+ if (!h) return;
1591
1595
  e.preventDefault();
1592
- if (e.shiftKey) onRedo?.();
1593
- else onUndo?.();
1596
+ h();
1594
1597
  return;
1595
1598
  }
1596
1599
  if (k === 'y') {
1600
+ if (!onRedo) return;
1597
1601
  e.preventDefault();
1598
- onRedo?.();
1602
+ onRedo();
1599
1603
  }
1600
1604
  };
1601
1605
  window.addEventListener('keydown', onKey, true);
@@ -26,8 +26,9 @@ export function pushHistory(store, id, snap, kind = 'op') {
26
26
  const typing = kind === 'typing';
27
27
  const merge = typing && now - h.lastAt < TYPING_MERGE_MS && h.past.length > 0;
28
28
  if (merge) {
29
- // 合并进上一条:撤销回到这段输入开始前的状态
30
- h.past[h.past.length - 1] = snap;
29
+ // 合并窗口内**不动 past**:段首快照已经在栈顶,撤销一次回退整段输入。
30
+ // (曾错写成用本键前置快照覆盖栈顶——段内逐键覆盖后栈顶只剩最后一个
31
+ // 字符的前置快照,Ctrl+Z 一次只退一个字符、再按就卡死,#156 实测。)
31
32
  } else {
32
33
  h.past.push(snap);
33
34
  // 栈上限:防止长文档编辑把内存吃满
@@ -1826,9 +1826,10 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
1826
1826
  multiple
1827
1827
  hidden
1828
1828
  onChange={(e) => {
1829
- const f = e.target.files;
1829
+ // ⚠️ 先拷贝再清 value:FileList 是活引用,`value = ''` 会把它清空
1830
+ const files = Array.from(e.target.files || []);
1830
1831
  e.target.value = '';
1831
- if (f && f.length) addFiles(f);
1832
+ if (files.length) addFiles(files);
1832
1833
  }}
1833
1834
  />
1834
1835
  <input
@@ -0,0 +1 @@
1
+ import{S as e,_ as t,f as n,g as r,l as i,v as a,x as o,y as s}from"./task-status-BP6y8MVu.js";import{d as c,h as l,i as u,r as d,u as f,y as p}from"./md-parse-C2bDc3IZ.js";import{M as m,N as h,O as g,k as _}from"./index-LxDjPSPW.js";import{a as v,i as y,n as b,r as x,t as S,u as C}from"./md-history-fHJjXhD5.js";import{a as w,i as ee}from"./upload-L1g-pfvZ.js";import{t as T}from"./route-crumb-D8gsnddf.js";import{a as E,c as D,i as O,l as k,o as A,r as j,s as M,t as N,u as te}from"./tool-bar-DwWOMBqs.js";var P=e(s(),1),F=h(),I=a(),L=`doc`,R=[{id:`edit`,label:`编辑`},{id:`doc`,label:`文档`},{id:`view`,label:`查看`}];function ne({crumb:e=null,title:t,pathLabel:n=``,dirty:r=!1,writable:i=!1,onSave:a=null,onSaveLabel:o=`保存`,menuGroups:s=[],saving:c=!1,external:l=!1,afterTitle:u=null}){let d=O(),{layout:f,setLayout:p}=A(L),[m,h]=(0,P.useState)(!1),g={};for(let e of s||[])for(let t of e?.items||[])t&&t.id&&(g[t.id]=t);g.save=a&&{id:`save`,label:c?`保存中…`:o,run:a,primary:!0,disabled:c||!r};let _=e=>e===`more`||!!g[e],v=f.filter(e=>k(L,e)&&_(e.id)),y=f.filter(e=>M(L,e)&&_(e.id)),b=e=>{g[e]?.run?.(),d.setOpen(!1)},x=e=>{if(e===`more`)return(0,I.jsx)(`div`,{className:`docp-more`,ref:d.ref,children:(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm${d.open?` on`:``}`,title:`更多操作`,"aria-haspopup":`menu`,"aria-expanded":d.open,onClick:e=>j(d,e,`right`),children:`更多`})},`more`);let t=g[e];return t?(0,I.jsx)(`button`,{type:`button`,className:t.primary||e===`save`?`btn sm primary docp-save`:`btn ghost sm`,disabled:!!t.disabled,onClick:()=>b(e),children:t.label||D(L,e).label||e},e):null},S=R.map(e=>({...e,items:y.filter(t=>D(L,t.id).menuGroup===e.id)})).filter(e=>e.items.length),C=y.filter(e=>!D(L,e.id).menuGroup);return i?(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsxs)(`div`,{className:`docp-actions`,children:[v.map(e=>x(e.id)),(0,I.jsxs)(N,{menu:d,className:`mdw-act-menu`,children:[S.map(e=>(0,I.jsxs)(`div`,{className:`mdw-fmt-menu-group`,role:`group`,"aria-label":e.label,children:[(0,I.jsx)(`div`,{className:`mdw-fmt-menu-cap`,children:e.label}),e.items.map(e=>{let t=g[e.id],n=t?.danger||D(L,e.id).danger;return(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(n?` danger`:``),onClick:()=>b(e.id),children:[t?.label||D(L,e.id).label||e.id,t?.hint?(0,I.jsx)(`span`,{className:`hint`,children:t.hint}):null]},e.id)})]},e.id)),C.map(e=>{let t=g[e.id];return(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(t?.danger||D(L,e.id).danger?` danger`:``),onClick:()=>b(e.id),children:t?.label||D(L,e.id).label||e.id},e.id)}),(0,I.jsx)(`div`,{className:`mdw-fmt-menu-sep`,role:`separator`}),(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`,onClick:()=>{d.setOpen(!1),h(!0)},children:`自定义工具栏…`})]})]})]}),m&&(0,F.createPortal)((0,I.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>h(!1),children:(0,I.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,I.jsx)(E,{kind:L,layout:f,setLayout:p,onClose:()=>h(!1)})})}),document.body)]}):(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsx)(`div`,{className:`docp-actions`,children:(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`只读`})})]})]})}function re(e,t,n){return{id:e,label:t,items:n.filter(Boolean)}}var z=o({default:()=>V,useWikiNav:()=>B});function B(e){let n=_()||{},i=r(),a=e||n.model,o=(0,P.useRef)(null),s=(0,P.useCallback)(async()=>{if(!o.current)try{o.current=(await t(`/api/docs/index`)).index||[]}catch{o.current=[]}return o.current},[]),c=(0,P.useCallback)(async(e,t,n={})=>{let r=(t||await s()).find(t=>t.docId===e);g(a,{component:`doc`,name:r?r.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[a,s]),l=(0,P.useCallback)(async e=>{let t=await s(),n=p(e,t);if(n&&n.docId)return c(n.docId,t);if(n&&n.candidates)return i(`「${e}」同名文档多份:${n.candidates.join(`、`)}`);i(`未找到「${e}」——可用 nx-kv docs add <rel> 创建`)},[s,c,i]);return{nav:l,onClick:(0,P.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),l(t.getAttribute(`data-wl`)))},[l]),ensureIndex:s,openByDocId:c}}function V({docId:e,repoKey:i,boardKey:a,boardName:o,model:s,tabId:p}){let h=r(),{dialog:_,node:E}=n(),D=(0,P.useRef)(new Map),O=(0,P.useRef)(null),k=(0,P.useRef)(null),{onClick:A,openByDocId:j}=B(s),M=i?`repo`:a?`board`:``,N=i||a||``,F=(0,P.useMemo)(()=>i?{repoKey:i}:a?{boardKey:a,boardName:o||``}:{},[i,a,o]),[L,R]=(0,P.useState)(null),[z,V]=(0,P.useState)(``),[ie,U]=(0,P.useState)(!1),[W,G]=(0,P.useState)(`split`),[K,q]=(0,P.useState)([]),[ae,J]=(0,P.useState)(null),Y=(0,P.useRef)(null);(0,P.useEffect)(()=>{Y.current=L},[L]);let X=(0,P.useCallback)(async()=>{V(``);try{let n=await t(`/api/docs/item?ref=`+encodeURIComponent(e||``));R(n),U(!1)}catch(e){V(String(e.message||e)),R(null)}},[e]);(0,P.useEffect)(()=>{R(null),X()},[X]);let Z=(0,P.useCallback)(()=>{if(!N){q([]);return}if(M===`repo`){t(`/api/repos/docs?id=`+encodeURIComponent(N)).then(t=>{let n=[],r=(e,t)=>{if(!e)return;let r=e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``;r&&n.push({docId:r,label:e.rel||e.path||(t?`主篇`:`补充`),note:e.note||``,main:t})};r(t.main||{rel:`repo/${N}.md`},!0);for(let e of t.links||[])r(e,!1);e&&!n.some(t=>t.docId===e)&&n.push({docId:e,label:`当前`,note:``,main:!0}),q(n)}).catch(()=>q(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}t(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===N||e.key===N),r=[];e&&r.push({docId:e,label:`当前`,note:``,main:!0});for(let e of n&&n.docLinks||[]){let t=e.rel?`rel:${e.rel}`:e.path?`path:${e.path}`:``;t&&!r.some(e=>e.docId===t)&&r.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,main:!1})}q(r)}).catch(()=>q(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[N,M,e]);(0,P.useEffect)(()=>{Z()},[Z]);let[se,ce]=(0,P.useState)(null);(0,P.useEffect)(()=>{t(`/api/docs/index`).then(e=>{let t=new Set;for(let n of e.index||[])t.add(n.name),n.rel&&t.add(String(n.rel).toLowerCase()),n.path&&t.add(String(n.path).replace(/\\/g,`/`).toLowerCase());ce(t)}).catch(()=>{})},[]);let Q=!!(L&&L.writable),le=(0,P.useMemo)(()=>L?f(L.body,[],Q?se:null):``,[L,se,Q]),ue=(0,P.useMemo)(()=>L?d(L.body):[],[L]);(0,P.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;J(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>J(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[L,W,le]);let $=e=>e().catch(e=>h(String(e.message||e))),de=(0,P.useCallback)(e=>j(e,null,F),[j,F]),fe=(0,P.useCallback)(()=>{let e=s;e&&N&&g(e,{component:`refs`,name:`文档列表`,config:i?{repoKey:i}:{boardKey:a,boardName:o||``},location:`right`})},[s,N,i,a,o]),pe=()=>{N&&$(async()=>{let n=await _({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(n===null)return;let r=c(String(n).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?H(e):M===`repo`?`repo/${N}`:`board/${o||N}`}/reference/${r}.md`;await t(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(n).trim()||r}\n\n(待补)\n`}});try{M===`repo`?await t(`/api/repos/docs`,{method:`POST`,body:{id:N,rel:i}}):await t(`/api/docs/link`,{method:`POST`,body:{board:N,doc:i}})}catch{}h(`已补充:${i}`),Z(),j(`rel:`+i,null,F)})},me=()=>$(async()=>{if(!L||!Q)return;let n=await t(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:L.body}});R(e=>({...e,body:L.body,summary:n.summary})),U(!1),S(D.current,e),h(n.summary?`已保存,摘要已回写`:`已保存`)}),he=(t,n=`op`)=>{L&&(b(D.current,e,{body:L.body},n),U(!0),R(e=>({...e,body:t,title:l(t,e.title)})))},ge=(t,n=`typing`)=>{if(!L)return;b(D.current,e,{body:L.body},n),U(!0);let r=/^#\s+/m.test(L.body)?L.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${L.body}`;R(e=>({...e,body:r,title:t}))},_e=()=>{if(!L)return;let t=y(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:l(t.body,e.title)})),U(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ve=()=>{if(!L)return;let t=x(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:l(t.body,e.title)})),U(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ye=async(t,n={})=>{if(!Q)return;let r=[...t||[]];if(r.length)try{let t=await w(r,{local:!0,onProgress:(e,t,n)=>h(`正在上传 ${e}/${t}:${n.name}`)}),i=ee(t);if(!i)return;let a=Y.current||L;if(!a)return;let o=u(a.body,i,n);b(D.current,e,{body:a.body}),U(!0),R(e=>e&&{...e,body:o.body,title:l(o.body,e.title)}),h(`已插入 ${t.length} 个附件`)}catch(e){h(`附件上传失败:${String(e.message||e)}`)}},be=()=>{L&&L.rel&&$(async()=>{let n=await _({title:`重命名文档`,input:!0,value:L.rel,placeholder:`新路径(相对 docs 根,以 .md 结尾)`});if(n===null)return;let r=String(n).trim();if(r&&r!==L.rel){if(!/\.md$/i.test(r))return h(`文档路径必须以 .md 结尾`);try{await t(`/api/docs/item`,{method:`POST`,body:{rel:r,body:L.body}})}catch(e){h(`重命名失败:${String(e.message||e)}`);return}await t(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),S(D.current,e),h(`已重命名为:${r}`),j(`rel:`+r,null,F)}})},xe=()=>{L&&$(async()=>{await _({title:`删除文档「${L.title||L.rel||e}」`,message:`磁盘上的 ${L.rel||e} 会被一并删除,不可恢复。`,danger:!0,okText:`删除`})&&(await t(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),h(`已删除:${L.rel||e}`),s&&p&&s.doAction(m.deleteTab(p)))})},Se=()=>$(async()=>{let n=String(e||``).startsWith(`rel:`)?e.slice(4):String(e||``).startsWith(`path:`)?``:String(e||``);if(!n)return;let r=n.replace(/\.md$/i,``).split(`/`).pop()||`未命名文档`;await t(`/api/docs/item`,{method:`POST`,body:{rel:n,body:`# ${r}\n\n(待补)\n`}}),h(`已创建:${n}`),await X()});if(L&&L.dir)return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsxs)(`div`,{className:`docp-head`,children:[(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.path}),(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,I.jsxs)(`div`,{className:`docp-files`,children:[L.files.map(e=>(0,I.jsx)(`button`,{className:`docp-file`,onClick:()=>j(`path:`+e,null),children:e},e)),!L.files.length&&(0,I.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(z)return(0,I.jsx)(`div`,{className:`mdw docp`,children:(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档打开失败`})}),(0,I.jsx)(`div`,{className:`hint`,children:z})]})});if(!L)return(0,I.jsx)(`div`,{className:`mdw`,children:(0,I.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(L.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsx)(`div`,{className:`docp-head`,children:(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.rel||L.path||e})}),(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,I.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{className:`btn sm`,onClick:Se,children:`创建骨架`})})]})]})}let Ce=Q?W:`read`;return(0,I.jsxs)(`div`,{className:`mdw docp`,"data-mode":Ce,onClick:A,ref:k,children:[(0,I.jsxs)(`div`,{className:`mdw-main`,children:[(0,I.jsx)(ne,{crumb:(0,I.jsx)(T,{}),title:L.title||L.rel||L.path||`文档`,pathLabel:L.rel||L.path||``,dirty:ie,writable:Q,external:!!L.external,menuGroups:[re(`edit`,`编辑`,[{id:`mode`,label:W===`edit`?`返回实时预览`:`源码模式`,hint:W===`edit`?`当前`:``,run:()=>G(W===`edit`?`split`:`edit`)}]),re(`doc`,`文档`,[{id:`rename`,label:`重命名`,run:be},{id:`delete`,label:`删除`,run:xe,danger:!0}]),re(`view`,`查看`,[N&&{id:`list`,label:`文字列表`,hint:`右侧边栏`,run:fe}])],onSave:me}),L.summary&&Q&&(0,I.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,L.summary]}),(0,I.jsx)(v,{mode:Ce,title:L.title,body:L.body,previewHtml:le,onTitle:Q?ge:null,onBody:Q?he:null,onFiles:Q?ye:null,attachments:[],docKey:e,editorApiRef:O,onSave:Q?me:null,onUndo:Q?_e:null,onRedo:Q?ve:null}),(0,I.jsx)(te,{host:`ref`,refId:e,allow:{file:!0,url:!0,task:!1,ref:!0},disabled:!Q,disabledText:`只读文档不能添加附件。`,onOpenDoc:e=>{let t=C(e);t&&j(t,null,F)}}),(0,I.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,I.jsx)(oe,{headings:ue,scrollRoot:ae,links:K,activeDocId:e,onOpenDoc:N?de:null,onAddRef:N?pe:null}),E]})}function H(e){let t=String(e||``).startsWith(`rel:`)?String(e).slice(4):``;return t?/\/index\.md$/i.test(t)?t.replace(/\/index\.md$/i,``):/\.md$/i.test(t)?t.replace(/\.md$/i,``):t.replace(/\/+$/,``):``}function ie(e,t){return e?e.doc&&e.doc.path?`path:`+e.doc.path:e.doc&&e.doc.rel?`rel:`+e.doc.rel:e.docPath?`path:`+e.docPath:e.docRel?`rel:`+e.docRel:t===`repo`&&e.key?`rel:repo/`+e.key+`.md`:``:``}function U(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function W({kind:e,owner:n,model:r}){let{openByDocId:i}=B(r),a=e===`board`?`组介绍`:`项目介绍`,o=e===`board`?n&&(n.id||n.key):n&&n.key,s=n&&n.name,l=(0,P.useMemo)(()=>ie(n,e),[n,e]),[u,d]=(0,P.useState)([]),[f,p]=(0,P.useState)(``),[m,h]=(0,P.useState)(0),g=(0,P.useCallback)(()=>h(e=>e+1),[]);(0,P.useEffect)(()=>{let r=!0;if(!o){d([]);return}if(e===`repo`)t(`/api/repos/docs?id=`+encodeURIComponent(o)).then(e=>{if(!r)return;let t=[],n=U(e.main);p(n||l),n&&t.push({docId:n,label:e.main.rel||e.main.path||`主篇`,note:e.main.note||``,tag:e.main.tag||``,main:!0,ref:e.main.ref||``});for(let n of e.extras||[]){let e=U(n);e&&t.push({docId:e,label:n.name||n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}for(let n of e.links||[]){let e=U(n);e&&t.push({docId:e,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}d(t)}).catch(()=>{r&&(d([]),p(l))});else{let e=()=>{let e=[];l&&e.push({docId:l,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let t of n?.docLinks||[]){let n=U(t);n&&e.push({docId:n,label:t.rel||t.path||`补充`,note:t.note||``,tag:t.tag||``,main:!1,ref:t.ref||``})}return e};t(`/api/boards/`+encodeURIComponent(String(o))).then(t=>{if(!r)return;let n=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!n){d(e()),p(l);return}let i=[],a=U(t&&t.introMain)||l;p(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=U(e);t&&i.push({docId:t,label:e.name||e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}for(let e of n){let t=U(e);t&&i.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}d(i)}).catch(()=>{r&&(d(e()),p(l))})}return()=>{r=!1}},[e,o,n,l,m]);let _=(0,P.useMemo)(()=>e===`repo`&&o?{repoKey:o}:e===`board`&&o?{boardKey:o,boardName:s||``}:{},[e,o,s]);return{kind:e,label:a,ownerKey:o,docRef:l,mainDocId:f,links:u,openMain:(0,P.useCallback)(()=>{let e=f||l;e&&i(e,null,_)},[f,l,i,_]),openDoc:(0,P.useCallback)(e=>i(e,null,_),[i,_]),addRef:(0,P.useCallback)(async(n,r)=>{if(!o||!l.startsWith(`rel:`))return r&&r(`当前简介无法补充(需要自有树路径)`),null;let a=await n({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(a===null)return null;let u=typeof a==`string`?a:a&&a.value||``,d=typeof a==`object`&&a&&a.tag||``,f=c(String(u).trim()||`note`).replace(/\.md$/i,``),p=`${H(l)||(e===`repo`?`repo/${o}`:`board/${s||o}`)}/reference/${f}.md`;await t(`/api/docs/item`,{method:`POST`,body:{rel:p,body:`# ${String(u).trim()||f}\n\n(待补)\n`}});try{e===`repo`?await t(`/api/repos/docs`,{method:`POST`,body:{id:o,rel:p,tag:d||void 0}}):await t(`/api/docs/link`,{method:`POST`,body:{board:o,doc:p,tag:d||void 0}})}catch{}return r&&r(`已补充:${p}${d?` [${d}]`:``}`),g(),i(`rel:`+p,null,_),p},[o,l,e,s,i,_,g]),setLinkTag:(0,P.useCallback)(async(n,r,i)=>{if(!o)throw Error(`缺少归属`);let a=String(n||``).startsWith(`path:`)?{path:String(n).slice(5)}:{rel:String(n||``).startsWith(`rel:`)?String(n).slice(4):String(n||``)},s=i&&i.note||``;e===`repo`?await t(`/api/repos/docs`,{method:`POST`,body:{id:o,...a,note:s||void 0,tag:r||void 0}}):await t(`/api/docs/link`,{method:`POST`,body:{board:o,doc:a.path||a.rel,note:s||void 0,tag:r||void 0}}),g()},[o,e,g]),reload:g,canEdit:!!l}}function G(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function K(e){let t=e.rel||e.path||``;return String(t).replace(/[\\/]+$/,``).split(/[\\/]/).pop()||t||`未命名`}function q(e,t,n){let r=[],i=e&&(e.main||e.introMain);i&&r.push({id:G(i),kind:`main`,label:`主篇`,sub:i.rel||i.path||``,tag:``,note:``,docId:G(i),removable:n===`repo`&&!!(t&&t.doc),removeTip:`摘除主篇自定义绑定(回退约定路径,文档不删)`,taggable:!1});for(let t of e&&(e.extras||e.introExtras)||[]){let e=G(t);e&&r.push({id:e,kind:`extra`,label:K(t),sub:t.rel||t.path||``,tag:``,note:``,docId:e,removable:!1,taggable:String(e).startsWith(`rel:`)})}(e&&(e.links||e.docLinks)||[]).forEach((e,t)=>{let i=G(e);i&&r.push({id:i,kind:`link`,label:K(e),sub:e.rel||e.path||``,tag:e.tag||``,note:e.note||``,docId:i,removeIndex:n===`repo`?t+2:t+1,removable:!0,taggable:!0})});for(let e of n===`repo`&&t&&t.boards||[]){let t=e.noteDocPath||``,n=e.noteDocRel||``,i=t?`path:`+t:n?`rel:`+n:``;i&&r.push({id:i,kind:`scoped`,label:`${e.name} · 组内描述`,sub:t||n,tag:``,note:e.note||``,docId:i,removable:!1,taggable:!1})}return r.filter(e=>e.docId)}var ae={main:`● `,scoped:`◇ `,extra:`○ `,link:`○ `};function J({kind:e,owner:a,model:o,onClose:s,onChanged:l}){let u=r(),{dialog:d,node:f}=n(),p=_()||{},m=o||p.model,h=W({kind:e,owner:a,model:m}),v=h.ownerKey,y=a&&a.name,[b,x]=(0,P.useState)([]),[S,C]=(0,P.useState)(!0),[w,ee]=(0,P.useState)(``),T=(0,P.useCallback)(async()=>{if(!v){x([]),C(!1);return}C(!0);try{let n=e===`repo`?await t(`/api/repos/docs?id=`+encodeURIComponent(v)):await t(`/api/boards/`+encodeURIComponent(String(v)));x(q(n,a,e)),ee(``)}catch(e){x([]),ee(String(e.message||e))}finally{C(!1)}},[e,v,a]);(0,P.useEffect)(()=>{T()},[T]);let E=t=>{if(!t)return;let n=m;if(!n){u(`工作区不可用,无法打开文档`);return}g(n,{component:`doc`,name:t.label||t.sub||t.docId,config:{docId:t.docId,...e===`repo`?{repoKey:v}:{boardKey:v,boardName:y||``}},location:`center`}),s()},D=e=>e().catch(e=>u(String(e.message||e))),O=n=>D(async()=>{await d({message:`摘除「${n.label}」?${n.kind===`main`?`(只拆绑定,文档不删)`:`(文档不删,仅移出列表)`}`,danger:!0})&&(e===`repo`?await t(`/api/repos/docs`,{method:`DELETE`,body:{id:v,index:n.removeIndex}}):await t(`/api/docs/link`,{method:`POST`,body:{board:v,remove:n.removeIndex}}),u(`已摘除`),T(),l&&l())}),k=e=>D(async()=>{let t=await d({title:`标签 · ${e.label}`,input:!0,placeholder:`标签(如 qa;留空 = 清掉)`,value:e.tag||``,okText:`保存标签`});if(t===null)return;let n=typeof t==`string`?t:t&&t.tag||``;await h.setLinkTag(e.docId,n,e),u(n?`标签已设为 [${n}]`:`标签已清除`),T(),l&&l()}),A=()=>D(async()=>{if(!v||!String(h.docRef||``).startsWith(`rel:`)){u(`当前简介无法补充(需要自有树路径)`);return}let n=await d({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(n===null)return;let r=typeof n==`string`?n:n&&n.value||``,i=typeof n==`object`&&n&&n.tag||``,a=c(String(r).trim()||`note`).replace(/\.md$/i,``),o=`${H(h.docRef)||(e===`repo`?`repo/${v}`:`board/${y||v}`)}/reference/${a}.md`;await t(`/api/docs/item`,{method:`POST`,body:{rel:o,body:`# ${String(r).trim()||a}\n\n(待补)\n`}});try{e===`repo`?await t(`/api/repos/docs`,{method:`POST`,body:{id:v,rel:o,tag:i||void 0}}):await t(`/api/docs/link`,{method:`POST`,body:{board:v,doc:o,tag:i||void 0}})}catch{}u(`已补充:${o}${i?` [${i}]`:``}`),await T(),l&&l(),E({docId:`rel:`+o,label:String(r).trim()||a,sub:o})}),j=!!String(h.docRef||``).startsWith(`rel:`)&&v,M=b.length,N=`文档列表 · ${y||``}${e===`board`?`(项目组)`:``}`;return(0,I.jsxs)(i,{size:`md`,title:N,onClose:s,children:[(0,I.jsxs)(`div`,{className:`nx-dl`,children:[(0,I.jsxs)(`div`,{className:`nx-dl-head`,children:[(0,I.jsx)(`span`,{className:`nx-dl-count`,children:M?`${M} 篇`:`还没有文档`}),(0,I.jsx)(`span`,{className:`nx-dl-hint`,children:`点标题在主内容区打开`}),(0,I.jsx)(`span`,{className:`grow`}),j&&(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm nx-dl-add`,title:`补充一篇介绍文档(reference)`,onClick:A,children:`+ 补充`})]}),w?(0,I.jsx)(`div`,{className:`rpd-err`,children:w}):null,!w&&S&&M===0?(0,I.jsx)(`div`,{className:`rpd-empty`,children:`载入中…`}):null,!w&&!S&&M===0?(0,I.jsx)(`div`,{className:`rpd-none`,children:`还没有文档 —— 点「+ 补充」写第一篇`}):null,(0,I.jsx)(`div`,{className:`nx-dl-list`,children:b.map(e=>(0,I.jsxs)(`div`,{className:`nx-dl-row-wrap`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`nx-dl-row`,title:`${e.sub||e.label}\n点击在主内容区打开(可编辑)`,onClick:()=>E(e),children:[(0,I.jsxs)(`span`,{className:`nx-dl-row-title`,children:[ae[e.kind]||`○ `,e.label]}),e.tag?(0,I.jsx)(`span`,{className:`rpd-badge`,children:e.tag}):null]}),(0,I.jsxs)(`span`,{className:`nx-docs-modal-item-acts`,children:[e.taggable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,onClick:()=>k(e),children:`#`}),e.removable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini danger`,title:e.removeTip||`摘除「${e.label}」(文档不删)`,onClick:()=>O(e),children:`×`})]})]},e.id))})]}),f]})}function Y(e){return e<=1?18:e===2?12:8}function oe({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),u=(0,P.useMemo)(()=>e||[],[e]),d=(0,P.useMemo)(()=>n||[],[n]);(0,P.useEffect)(()=>{let e=t;if(!e||!u.length)return;let n=()=>u.map(t=>{let n=e.querySelector(`#${CSS.escape(t.id)}`);if(!n)return null;let r=n.getBoundingClientRect(),i=e.getBoundingClientRect();return{id:t.id,y:r.top-i.top}}).filter(Boolean),r=()=>{let e=n();if(!e.length)return;let t=e[0].id;for(let n of e)n.y<=28&&(t=n.id);l(t)};return r(),e.addEventListener(`scroll`,r,{passive:!0}),()=>e.removeEventListener(`scroll`,r)},[t,u]);let f=(0,P.useCallback)(e=>{let n=t;if(!n)return;let r=n.querySelector(`#${CSS.escape(e)}`);if(!r){n.scrollTo({top:0,behavior:`smooth`}),l(e);return}r.scrollIntoView({behavior:`smooth`,block:`start`}),l(e)},[t]);return!u.length&&!d.length&&!a?null:(0,I.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{})]}),(0,I.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,I.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${Y(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,I.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,I.jsx)(`button`,{type:`button`,className:`doc-rail-row`+(c===e.id?` on`:``),"data-lv":e.level,onClick:()=>f(e.id),children:e.text},e.id))]}),(d.length>0||a)&&(0,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,I.jsxs)(`button`,{type:`button`,className:`doc-rail-row`+(e.docId===r?` on`:``),title:e.note||e.label,disabled:!i,onClick:()=>i&&i(e.docId),children:[e.main?`● `:`○ `,e.label]},e.docId)),a&&(0,I.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function X({kind:e,owner:t,model:n}){let{label:r,docRef:i,links:a,openMain:o}=W({kind:e,owner:t,model:n}),[s,c]=(0,P.useState)(!1);if(!t||!i)return null;let l=a.find(e=>e.main),u=l?l.docId:i,d=u.startsWith(`rel:`)?u.slice(4):u,f=a.filter(e=>!e.main).length;return(0,I.jsxs)(`div`,{className:`nx-intro`,children:[(0,I.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,I.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${r}(在主内容区阅读 / 编辑)`,onClick:o,children:r}),(0,I.jsx)(`span`,{className:`nx-intro-path mono`,children:d}),(0,I.jsx)(`span`,{className:`nx-intro-spacer`}),(0,I.jsxs)(`button`,{type:`button`,className:`nx-intro-btn`,title:`查看${r}的全部文章(点标题在主内容区打开,可编辑)`,onClick:()=>c(!0),children:[`查看详情`,f>0?` ${f}`:``]})]}),s&&(0,I.jsx)(J,{kind:e,owner:t,model:n,onClose:()=>c(!1)})]})}export{B as i,J as n,z as r,X as t};
@@ -1 +1 @@
1
- import{S as e,v as t,y as n}from"./task-status-BP6y8MVu.js";import{N as r}from"./index-CLsU9Lad.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-Bh3XH8MU.js";var l=e(n(),1),u=r(),d=t();function f({kind:e,renderers:t={},actions:n={},titles:r={},disabled:f={},labels:p={},className:m=``}){let{layout:h,setLayout:g}=s(e),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(!1),C=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!_)return;let e=e=>{C.current?.contains(e.target)||w.current?.contains(e.target)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]);let T=h.filter(t=>o(e,t)),E=h.filter(t=>c(e,t)),D=t=>p[t]||a(e,t).label||t,O=(e,t={})=>(0,d.jsx)(`button`,{type:`button`,className:t.primary?`btn small primary`:`btn small ghost`,title:r[e]||D(e),disabled:!!f[e],onClick:()=>n[e]&&n[e](),children:D(e)},e),k=n=>n===`more`?(0,d.jsxs)(`button`,{ref:C,type:`button`,className:`btn small ghost`+(_?` is-open`:``),title:r.more||`更多操作`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();b({top:t.bottom+6,right:Math.max(8,window.innerWidth-t.right)}),v(e=>!e)},children:[D(`more`),` ▾`]},`more`):t[n]?(0,d.jsx)(`span`,{className:`ta-slot`,children:t[n]({open:_})},n):O(n,{primary:a(e,n).section===`primary`});return(0,d.jsxs)(`div`,{className:`ta-bar`+(m?` ${m}`:``),children:[T.map(e=>k(e.id)),_&&y&&(0,u.createPortal)((0,d.jsxs)(`div`,{ref:w,className:`ta-more-menu`,role:`menu`,style:{top:y.top,right:y.right},children:[E.length===0&&(0,d.jsx)(`div`,{className:`ta-more-empty`,children:`没有收纳的工具——可在编排里把按钮收入更多`}),E.map(e=>(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it`,disabled:!!f[e.id],title:r[e.id]||D(e.id),onClick:()=>{v(!1),n[e.id]&&n[e.id]()},children:D(e.id)},e.id)),(0,d.jsx)(`div`,{className:`ta-more-sep`}),(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it ta-more-cfg`,onClick:()=>{v(!1),S(!0)},children:`自定义工具栏…`})]}),document.body),x&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>S(!1),children:(0,d.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,d.jsx)(i,{kind:e,layout:h,setLayout:g,onClose:()=>S(!1)})})}),document.body)]})}export{f as t};
1
+ import{S as e,v as t,y as n}from"./task-status-BP6y8MVu.js";import{N as r}from"./index-LxDjPSPW.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-DwWOMBqs.js";var l=e(n(),1),u=r(),d=t();function f({kind:e,renderers:t={},actions:n={},titles:r={},disabled:f={},labels:p={},className:m=``}){let{layout:h,setLayout:g}=s(e),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(!1),C=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!_)return;let e=e=>{C.current?.contains(e.target)||w.current?.contains(e.target)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]);let T=h.filter(t=>o(e,t)),E=h.filter(t=>c(e,t)),D=t=>p[t]||a(e,t).label||t,O=(e,t={})=>(0,d.jsx)(`button`,{type:`button`,className:t.primary?`btn small primary`:`btn small ghost`,title:r[e]||D(e),disabled:!!f[e],onClick:()=>n[e]&&n[e](),children:D(e)},e),k=n=>n===`more`?(0,d.jsxs)(`button`,{ref:C,type:`button`,className:`btn small ghost`+(_?` is-open`:``),title:r.more||`更多操作`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();b({top:t.bottom+6,right:Math.max(8,window.innerWidth-t.right)}),v(e=>!e)},children:[D(`more`),` ▾`]},`more`):t[n]?(0,d.jsx)(`span`,{className:`ta-slot`,children:t[n]({open:_})},n):O(n,{primary:a(e,n).section===`primary`});return(0,d.jsxs)(`div`,{className:`ta-bar`+(m?` ${m}`:``),children:[T.map(e=>k(e.id)),_&&y&&(0,u.createPortal)((0,d.jsxs)(`div`,{ref:w,className:`ta-more-menu`,role:`menu`,style:{top:y.top,right:y.right},children:[E.length===0&&(0,d.jsx)(`div`,{className:`ta-more-empty`,children:`没有收纳的工具——可在编排里把按钮收入更多`}),E.map(e=>(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it`,disabled:!!f[e.id],title:r[e.id]||D(e.id),onClick:()=>{v(!1),n[e.id]&&n[e.id]()},children:D(e.id)},e.id)),(0,d.jsx)(`div`,{className:`ta-more-sep`}),(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it ta-more-cfg`,onClick:()=>{v(!1),S(!0)},children:`自定义工具栏…`})]}),document.body),x&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>S(!1),children:(0,d.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,d.jsx)(i,{kind:e,layout:h,setLayout:g,onClose:()=>S(!1)})})}),document.body)]})}export{f as t};