nx-kv 0.25.0 → 0.26.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 (36) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/assets/kv-get/SKILL.md +7 -11
  3. package/package.json +1 -1
  4. package/src/modules/localtask/index.js +36 -15
  5. package/src/modules/localtask/task-lifecycle.js +128 -55
  6. package/src/modules/localtask/task-view.js +89 -12
  7. package/src/web/frontend/components/md/sel-menu.jsx +112 -19
  8. package/src/web/frontend/components/md/task-chain.jsx +75 -0
  9. package/src/web/frontend/components/md/tool-bar.jsx +6 -0
  10. package/src/web/frontend/modules/board/ack-nodes.js +2 -2
  11. package/src/web/frontend/modules/md/style.css +44 -0
  12. package/src/web/frontend/page/dir/index.jsx +32 -15
  13. package/src/web/frontend/page/dir/landing.jsx +2 -2
  14. package/src/web/frontend/page/dir/task.jsx +300 -89
  15. package/src/web/frontend/panels.jsx +13 -3
  16. package/src/web/public/assets/{Introduction-VfytFhtV.js → Introduction-ka0UxW_S.js} +1 -1
  17. package/src/web/public/assets/{cloud-DolkshAI.js → cloud-y1mZIdlN.js} +1 -1
  18. package/src/web/public/assets/{dag-C-E5GoLz.js → dag-CiMSs7uT.js} +1 -1
  19. package/src/web/public/assets/dir-DKzzrY8P.js +3 -0
  20. package/src/web/public/assets/{group-BQTuoGyZ.js → group-DOLdLkaj.js} +1 -1
  21. package/src/web/public/assets/{index-BryAyn_9.js → index-CbZfbzqr.js} +2 -2
  22. package/src/web/public/assets/{index-B48b_WIl.css → index-DUvCgdUV.css} +1 -1
  23. package/src/web/public/assets/{md-history-vwtmQsFJ.js → md-history-Ddk04A_2.js} +1 -1
  24. package/src/web/public/assets/{member-picker-DwJAdKTe.js → member-picker-Dsy1GH0E.js} +1 -1
  25. package/src/web/public/assets/{overview-Crnguaek.js → overview-ty9m-bCh.js} +1 -1
  26. package/src/web/public/assets/{progress-ijTyMRPT.js → progress-BQJhISlF.js} +1 -1
  27. package/src/web/public/assets/{repos-C_dN0b6h.js → repos-Di5InllN.js} +1 -1
  28. package/src/web/public/assets/{route-crumb-DZw2J3Nx.js → route-crumb-g3leiQhY.js} +1 -1
  29. package/src/web/public/assets/{settings-C7zGy-xI.js → settings-CE-rlcXr.js} +1 -1
  30. package/src/web/public/assets/task-D97dEZdc.js +6 -0
  31. package/src/web/public/assets/{template-slots-DhPGCIqW.js → template-slots-D40ponA2.js} +1 -1
  32. package/src/web/public/assets/{templates-xXPow5BD.js → templates-Ca1jXhnO.js} +1 -1
  33. package/src/web/public/assets/{upload-uBhGCTZ2.js → upload-BeiJetbd.js} +1 -1
  34. package/src/web/public/index.html +2 -2
  35. package/src/web/public/assets/dir-kBhfKX8r.js +0 -3
  36. package/src/web/public/assets/task-CqoiXFKL.js +0 -5
@@ -13,7 +13,11 @@ import { api } from '../../api/client.js';
13
13
  import { useToast } from '../../components/toast/index.jsx';
14
14
  import { Modal, useDialog } from '../../components/popup/index.jsx';
15
15
  import { GLOBAL_KEY } from '../../modules/board/board-view.js';
16
- import { buildReopenText } from '../../modules/board/reopen-text.js';
16
+ import {
17
+ buildReopenText,
18
+ FEEDBACK_HEADING,
19
+ PLAIN_FEEDBACK_HEADING,
20
+ } from '../../modules/board/reopen-text.js';
17
21
  import { extractAckNodes } from '../../modules/board/ack-nodes.js';
18
22
  import ToolBar from '../../components/md/tool-bar.jsx';
19
23
  import { MdPanes } from '../../components/md/md-panes.jsx';
@@ -21,6 +25,7 @@ import AckRail from '../../components/md/ack-rail.jsx';
21
25
  import AttachBar from '../../components/md/attach-bar.jsx';
22
26
  import SelMenu from '../../components/md/sel-menu.jsx';
23
27
  import ShortcutSheet from '../../components/md/shortcut-sheet.jsx';
28
+ import { TaskChainModal } from '../../components/md/task-chain.jsx';
24
29
  import { useApp } from '../../app-context.jsx';
25
30
  import { openBesideMain, openPanel } from '../../workspace.js';
26
31
  import { filesToAttachments, persistAtt } from '../../components/md/attachments.js';
@@ -47,7 +52,7 @@ import {
47
52
  useDocs,
48
53
  } from '../../modules/md/doc-store.js';
49
54
 
50
- export default function PagePanel({ dirKey, task, beside = false, tabId, model }) {
55
+ export default function PagePanel({ dirKey, task, beside = false, tabId, model, historyId = null }) {
51
56
  const app = useApp() || {};
52
57
  const toast = useToast();
53
58
  const { dialog, node: dialogNode } = useDialog();
@@ -85,9 +90,10 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
85
90
  const goal = goalDraft || { duration: declaredGoal?.duration || '', prompt: declaredGoal?.prompt || '' };
86
91
  const goalEditable = isDraft || (!!taskRow && taskRow.status !== 'consumed');
87
92
 
88
- // ─── 验收条(完成任务):agent 的完成总结(ack)+ 用户回复(通行 / 重做 / 划线评论提详细问题)───
93
+ // ─── 验收条(完成任务):agent 的完成总结(ack)+ 用户回复(通行 / 反馈 / 划线评论)───
89
94
  // 「通行」只在本机记一笔(localStorage,per-viewer 的轻量状态):done 本身已是终态,
90
95
  // 验收与否不进队列 schema——「无更新则直接结束」的口径里,通行 = 不需要再做什么。
96
+ // 「反馈」(#75):**新开一条任务**(不是重做/就地重开),原完成任务留档不动。
91
97
  const reviewAckKey = `nx-kv/review/${scope}/${task}`;
92
98
  const [reviewAcked, setReviewAcked] = useState(() => {
93
99
  try {
@@ -114,10 +120,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
114
120
  setReviewAcked(true);
115
121
  toast('已验收');
116
122
  };
117
- /** 重做:走**正常评论模式**(不再弹窗输入框)——评论框开在正文末尾,
118
- 提交即把这条任务重开,反馈文字(加粗)带进正文。 */
119
- const redoTask = () => {
120
- // 浮层是 .mdw 内的绝对定位 → 坐标要相对容器(用条带相对容器的偏移)
123
+ /** 反馈:开评论框写意见;提交后**新建一条任务**(forkOf 指回本条),原任务不动。 */
124
+ const openFeedback = () => {
121
125
  const bar = reviewBarRef.current;
122
126
  const host = bar?.closest?.('.mdw');
123
127
  const b = bar?.getBoundingClientRect();
@@ -126,39 +130,98 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
126
130
  const y = b && h ? b.top - h.top - 190 : 120;
127
131
  setSelMenu({
128
132
  kind: 'task',
129
- text: '', // 重做针对整条任务,不锚定选区
133
+ text: '',
130
134
  comment: true,
131
- mode: 'redo',
135
+ mode: 'feedback',
132
136
  x: Math.min(window.innerWidth - 320, Math.max(8, x)),
133
137
  y: Math.min(window.innerHeight - 260, Math.max(8, y)),
134
138
  });
135
139
  };
136
- /** 评论框提交:重做模式 → 重开本任务(反馈加粗进正文);普通划线评论 → 开新任务 */
137
- const onCommentSubmit = (q) => {
138
- if (selMenu?.mode === 'redo') {
139
- submitRedo(q);
140
+ /** 统一提交入口:feedback → 新开任务;comment → 就地回写原任务(可带附件)。 */
141
+ const onCommentSubmit = (payload) => {
142
+ const p =
143
+ payload && typeof payload === 'object'
144
+ ? payload
145
+ : {
146
+ text: String(payload || ''),
147
+ mode: selMenu?.mode === 'feedback' || selMenu?.mode === 'redo' ? 'feedback' : 'comment',
148
+ quote: lastSel.current || '',
149
+ };
150
+ if (p.mode === 'feedback' || p.mode === 'redo' || selMenu?.mode === 'feedback' || selMenu?.mode === 'redo') {
151
+ spawnFeedbackTask(p);
140
152
  return;
141
153
  }
142
- spawnComment(q);
154
+ submitCommentInPlace(p);
143
155
  };
144
- const submitRedo = (feedback) => {
145
- const fb = String(feedback || '').trim();
156
+ /** 验收反馈 → 新开任务(#75):正文 = 原正文 + 上轮总结 + 本轮反馈;forkOf 指回本条。 */
157
+ const spawnFeedbackTask = ({ text: fbRaw, attachments = [], inserts = '' } = {}) => {
158
+ const fb = String(fbRaw || '').trim();
146
159
  closeSelMenu();
147
- if (!fb) {
148
- toast('写一下要改的地方');
160
+ if (!fb && !(attachments && attachments.length)) {
161
+ toast('写一下反馈');
149
162
  return;
150
163
  }
151
164
  const title = doc?.title || `#${task}`;
152
165
  guard(async () => {
153
- // 反馈是**追加**不是替换:reopen 的 text 是整段新正文,直接把反馈当正文发
154
- // 会把原任务丢掉。拼成「原正文 + 上一轮 ack 完成总结 + 验收反馈」——
155
- // 重做后验收条会消失,上轮总结若不落进正文就没人看得见了(agent 下一轮
156
- // 同样看不见:它只拿到正文)。反馈逐行加粗(用户口径:重开的任务要携带着
157
- // 反馈文字在正文中,最好加粗)。
166
+ let feedbackBody = fb || '(见附件)';
167
+ if (inserts) feedbackBody = `${feedbackBody}${inserts}`;
158
168
  const text = buildReopenText({
159
169
  base: doc?.body || '',
160
- feedback: fb,
170
+ feedback: feedbackBody,
161
171
  ackSummary: taskRow?.roundSummary || '',
172
+ feedbackHeading: FEEDBACK_HEADING,
173
+ bold: true,
174
+ });
175
+ const linkFields =
176
+ !isDraft && task != null && !/^draft/i.test(String(task))
177
+ ? { forkOf: String(task), forkKind: 'reopen' }
178
+ : {};
179
+ const res = await api('/api/localtasks', {
180
+ method: 'POST',
181
+ body: isGlobal
182
+ ? { global: true, text, ...linkFields }
183
+ : { cwd: topic?.cwd, text, ...linkFields },
184
+ });
185
+ const newId = String(res?.task?.id ?? res?.id ?? '');
186
+ if (!newId) {
187
+ toast('反馈已提交,但未拿到新任务编号');
188
+ refreshLocal();
189
+ return;
190
+ }
191
+ const landedKey = res?.key || dirKey;
192
+ saveDoc(docIdOf(scopeOf(landedKey), newId), { title: titleFromMd(text), body: text });
193
+ if (attachments?.length) persistAtt(newId, attachments);
194
+ toast(`已反馈「${title}」→ 新任务 #${newId}`);
195
+ refreshLocal();
196
+ if (app.openPage) app.openPage({ dirKey: landedKey, task: newId, name: `${title.slice(0, 24)}(反馈)` });
197
+ });
198
+ };
199
+ /** 划选评论 → 就地回写原任务(#74),可带附件。 */
200
+ const submitCommentInPlace = ({ text: fbRaw, attachments = [], inserts = '', quote } = {}) => {
201
+ const fb = String(fbRaw || '').trim();
202
+ const quoteText = String(quote || lastSel.current || '').trim();
203
+ closeSelMenu();
204
+ if (!fb && !(attachments && attachments.length)) {
205
+ toast('写一下要提的问题');
206
+ return;
207
+ }
208
+ if (!quoteText && !fb) {
209
+ toast('先划选一段再评论');
210
+ return;
211
+ }
212
+ const title = doc?.title || `#${task}`;
213
+ guard(async () => {
214
+ let feedbackBody = fb;
215
+ if (quoteText) {
216
+ feedbackBody = `> 锚定:\n> ${quoteText.replace(/\n/g, '\n> ')}\n\n${fb || '(见附件)'}`;
217
+ }
218
+ if (inserts) feedbackBody = `${feedbackBody || ''}${inserts}`;
219
+ const text = buildReopenText({
220
+ base: doc?.body || '',
221
+ feedback: feedbackBody,
222
+ ackSummary: '',
223
+ feedbackHeading: PLAIN_FEEDBACK_HEADING,
224
+ bold: false,
162
225
  });
163
226
  const res = await api('/api/localtasks/reopen', {
164
227
  method: 'POST',
@@ -166,25 +229,27 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
166
229
  ...(isGlobal ? { key: GLOBAL_KEY } : { cwd: topic?.cwd }),
167
230
  id: Number(task),
168
231
  text,
232
+ kind: 'comment',
233
+ quote: quoteText,
234
+ feedback: fb,
235
+ attachments: (attachments || []).map((a) => ({
236
+ id: a.id,
237
+ name: a.name,
238
+ type: a.type,
239
+ size: a.size,
240
+ url: a.url || '',
241
+ })),
169
242
  },
170
243
  });
171
- // 重开 = **新建一条任务**(新 md),旧任务归档留档(#59:状态单向)。
172
- // 所以:旧文档**不动**(那是历史),新正文写进**新任务自己的文档**,
173
- // 页签切到新任务——用户接着看的就是「这一轮要干的活」。
174
- // text 是拿 doc.body 拼的,未保存的编辑原样带在里面,不会被抹掉。
175
- // 归属改了会搬家(同保存路径,任务 #43)——文档与页签跟到新队列新号。
176
244
  const landedKey = res?.key || dirKey;
177
- const newId = String(res?.task?.id ?? task);
178
- const newDocId = docIdOf(scopeOf(landedKey), newId);
179
- saveDoc(newDocId, { title: titleFromMd(text), body: text });
180
- if (model && tabId) {
181
- model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: newId } }));
245
+ const sameId = String(res?.task?.id ?? task);
246
+ saveDoc(docIdOf(scopeOf(landedKey), sameId), { title: titleFromMd(text), body: text });
247
+ if (attachments?.length) persistAtt(sameId, [...(doc?.attachments || []), ...attachments]);
248
+ if (model && tabId && landedKey !== dirKey) {
249
+ model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: sameId } }));
182
250
  }
183
251
  setDirty(false);
184
- toast(
185
- `已重开「${title}」→ 新任务 #${newId}(旧任务归档留档)` +
186
- (res?.moved && res.name ? `;归属迁到「${res.name}」` : ''),
187
- );
252
+ toast(`已回写评论「${title}」#${sameId}`);
188
253
  refreshLocal();
189
254
  });
190
255
  };
@@ -236,6 +301,7 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
236
301
 
237
302
  const [selMenu, setSelMenu] = useState(null);
238
303
  const [showShortcuts, setShowShortcuts] = useState(false);
304
+ const [chainOpen, setChainOpen] = useState(false);
239
305
  const fileMdRef = useRef(null);
240
306
  const fileAttRef = useRef(null);
241
307
  const articleRef = useRef(null);
@@ -352,12 +418,154 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
352
418
  });
353
419
  }, [parentRef, model, app.model, toast]);
354
420
 
421
+ /** 任务链节点 → 旁路查看:history 快照 / 祖先或子任务正文 */
422
+ const openHistoryBeside = useCallback(
423
+ (node) => {
424
+ const m = model || app.model;
425
+ if (!m || isDraft) return;
426
+ if (node?.current) {
427
+ toast('当前节点就是本页');
428
+ return;
429
+ }
430
+ // 同任务 history 快照
431
+ if (node?.historyId != null) {
432
+ openBesideMain(m, {
433
+ component: 'page',
434
+ name: `链 #${task} · ${node.kind || node.historyId}`,
435
+ config: {
436
+ dirKey: dirKey || GLOBAL_KEY,
437
+ task: String(task),
438
+ historyId: Number(node.historyId),
439
+ },
440
+ });
441
+ return;
442
+ }
443
+ // fork 祖先 / 子任务:打开对应任务页(旁路)
444
+ if (node?.taskId != null && node?.dirKey) {
445
+ openBesideMain(m, {
446
+ component: 'page',
447
+ name: node.excerpt ? String(node.excerpt).slice(0, 24) : `#${node.taskId}`,
448
+ config: { dirKey: String(node.dirKey), task: String(node.taskId) },
449
+ });
450
+ return;
451
+ }
452
+ toast('这个节点没有可打开的内容');
453
+ },
454
+ [model, app.model, isDraft, dirKey, task, toast],
455
+ );
456
+
355
457
  const closeBesideSelf = useCallback(() => {
356
458
  const m = model || app.model;
357
459
  if (!m || !tabId) return;
358
460
  m.doAction(Actions.deleteTab(tabId));
359
461
  }, [model, app.model, tabId]);
360
462
 
463
+ // 任务链:优先 history;无 history 时用 forkOf 祖先/子任务(#76 反馈「看不到链」)
464
+ const [chainApi, setChainApi] = useState(null);
465
+ useEffect(() => {
466
+ if (isDraft || task == null || /^draft/i.test(String(task))) {
467
+ setChainApi(null);
468
+ return undefined;
469
+ }
470
+ let cancelled = false;
471
+ const q = isGlobal
472
+ ? `key=${encodeURIComponent(GLOBAL_KEY)}&id=${Number(task)}`
473
+ : `cwd=${encodeURIComponent(topic?.cwd || '')}&id=${Number(task)}`;
474
+ api(`/api/localtasks/chain?${q}`)
475
+ .then((d) => {
476
+ if (!cancelled) setChainApi(d);
477
+ })
478
+ .catch(() => {
479
+ if (!cancelled) setChainApi(null);
480
+ });
481
+ return () => {
482
+ cancelled = true;
483
+ };
484
+ }, [isDraft, task, isGlobal, topic?.cwd, taskRow?.history?.length, taskRow?.forkOf, taskRow?.reopenCount]);
485
+
486
+ const chainNodes = useMemo(() => {
487
+ if (isDraft || !taskRow) return [];
488
+ const tip =
489
+ String(taskRow.text || '')
490
+ .split('\n')
491
+ .map((l) => l.trim())
492
+ .find(Boolean) || '';
493
+ const tipEx = tip.replace(/^#+\s*/, '').slice(0, 100);
494
+
495
+ // 1) 同任务 history 链
496
+ const hist = Array.isArray(taskRow.history) ? taskRow.history : [];
497
+ if (hist.length) {
498
+ const nodes = hist.map((h) => ({
499
+ historyId: h.id,
500
+ kind: h.kind,
501
+ at: h.at,
502
+ excerpt: h.excerpt || h.feedback || '',
503
+ feedback: h.feedback,
504
+ quote: h.quote,
505
+ attachmentCount: (h.attachments || []).length,
506
+ current: false,
507
+ }));
508
+ nodes.push({
509
+ historyId: null,
510
+ kind: 'current',
511
+ at: taskRow.lastReopenedAt || taskRow.createdAt || '',
512
+ excerpt: tipEx,
513
+ attachmentCount: 0,
514
+ current: true,
515
+ });
516
+ return nodes;
517
+ }
518
+
519
+ // 2) fork 派生链(祖先 → 本条 → 子任务)
520
+ const ancestors = Array.isArray(chainApi?.ancestors) ? [...chainApi.ancestors].reverse() : [];
521
+ const children = Array.isArray(chainApi?.children) ? chainApi.children : [];
522
+ if (!ancestors.length && !children.length && !taskRow.forkOf) return [];
523
+ const nodes = [];
524
+ for (const a of ancestors) {
525
+ if (a.missing) continue;
526
+ nodes.push({
527
+ historyId: null,
528
+ kind: a.forkKind || 'origin',
529
+ at: a.createdAt || '',
530
+ excerpt: a.excerpt || `#${a.id}`,
531
+ attachmentCount: 0,
532
+ current: false,
533
+ taskId: a.id,
534
+ dirKey: a.key,
535
+ });
536
+ }
537
+ nodes.push({
538
+ historyId: null,
539
+ kind: 'current',
540
+ at: taskRow.createdAt || '',
541
+ excerpt: tipEx,
542
+ attachmentCount: 0,
543
+ current: true,
544
+ taskId: Number(task),
545
+ dirKey: dirKey || GLOBAL_KEY,
546
+ });
547
+ for (const c of children) {
548
+ nodes.push({
549
+ historyId: null,
550
+ kind: c.forkKind || 'comment',
551
+ at: c.createdAt || '',
552
+ excerpt: c.excerpt || `#${c.id}`,
553
+ attachmentCount: 0,
554
+ current: false,
555
+ taskId: c.id,
556
+ dirKey: c.key,
557
+ });
558
+ }
559
+ // 弹窗里即使只有当前节点也展示(说明这是链的尖)
560
+ return nodes;
561
+ }, [isDraft, taskRow, chainApi, task, dirKey]);
562
+
563
+ const historyNode = useMemo(() => {
564
+ if (historyId == null || !taskRow) return null;
565
+ const want = Number(historyId);
566
+ return (taskRow.history || []).find((h) => Number(h.id) === want) || null;
567
+ }, [historyId, taskRow]);
568
+
361
569
  const markDirty = useCallback(() => setDirty(true), []);
362
570
 
363
571
  /** 标题 + frontmatter 拼装(提交/贴图同步共用)——标题行永远在 FM 之后。 */
@@ -654,53 +862,6 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
654
862
  });
655
863
  };
656
864
 
657
- /** 划线评论 → **直接提交**成新任务:锚定选区原文,正文就是提出的问题。
658
- *
659
- * 两条口径(用户验收反馈 2026-11-04):
660
- * 1. 原任务带工作组语义(frontmatter 里的 board / project)→ 评论出的新任务
661
- * **也归该组**。不继承的话,这条问题会从组面板里掉出去——用户是在组里
662
- * 提问的,闭环断在半路。正文整块继承原 frontmatter(归属 + 介绍引用)。
663
- * 2. 评论**直接提交**,不再先落成草稿、让人再点一次提交。评论是提问不是
664
- * 写作,多一道编辑页就多一次流失;提交完再打开新任务页(看得到提交了什么)。
665
- */
666
- const spawnComment = (question) => {
667
- const quote = lastSel.current || '';
668
- const q = String(question || '').trim();
669
- if (!quote) {
670
- toast('先划选一段再评论');
671
- return;
672
- }
673
- if (!q) {
674
- toast('写一下要提的问题');
675
- return;
676
- }
677
- const parent = doc?.title || topic?.name || '';
678
- const t = `问题:${q.slice(0, 28)}`;
679
- const raw = `# ${t}\n\n> 锚定自「${parent}」:\n> ${quote.replace(/\n/g, '\n> ')}\n\n## 问题\n${q}\n\n## 要做什么\n- [ ] …\n`;
680
- // 工作组语义继承 + 原文锚点(parent/parentDir):评论页可一键并排打开原文。
681
- // 任务链(#69):forkOf/forkKind 进 store schema——frontmatter 只是正文锚点,
682
- // 链条本体在队列行上,CLI 的 localtask chain 靠它才能查(正文可被编辑,schema 不会)。
683
- const isRealTask = !isDraft && task != null && !/^draft/i.test(String(task));
684
- const parentFields = isRealTask ? { parent: String(task), parentDir: dirKey || '' } : {};
685
- const linkFields = isRealTask ? { forkOf: String(task), forkKind: 'comment' } : {};
686
- const b = withFrontmatter(raw, { ...docFm, ...parentFields });
687
- guard(async () => {
688
- // 落点 = 原任务所在队列(显式给 cwd:尊重当前落点,不被归属推导挪走);
689
- // 归属由正文 frontmatter 决定(服务端 fail-open 补介绍引用)。
690
- const res = await api('/api/localtasks', {
691
- method: 'POST',
692
- body: isGlobal
693
- ? { global: true, text: b, ...linkFields }
694
- : { cwd: topic?.cwd, text: b, ...linkFields },
695
- });
696
- closeSelMenu();
697
- toast('已提交问题(评论)');
698
- refreshLocal();
699
- const newId = res?.task?.id ?? res?.id;
700
- if (newId != null && app.openPage) app.openPage({ dirKey, task: String(newId), name: t });
701
- });
702
- };
703
-
704
865
  /** 工具栏「评论」:只用当前可见选区;浮层已开时沿用其原文(正写评论) */
705
866
  const openCommentFromToolbar = () => {
706
867
  const live = String(window.getSelection() || '').trim();
@@ -831,6 +992,49 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
831
992
  return () => window.removeEventListener('keydown', onKey);
832
993
  }, [parentRef, beside, openParentBeside]);
833
994
 
995
+ // 链节点旁路:只读展示 history 快照(不占编辑文档)
996
+ if (historyId != null) {
997
+ const kindLab = { origin: '起点', reopen: '反馈', comment: '评论' }[historyNode?.kind] || '节点';
998
+ const html = historyNode
999
+ ? renderMarkdownHtml(historyNode.text || '', historyNode.attachments || [])
1000
+ : '';
1001
+ return (
1002
+ <div className="mdw is-beside">
1003
+ <div className="mdw-beside-h">
1004
+ <span className="mdw-beside-lab">链节点 · {kindLab} #{historyId}</span>
1005
+ <span className="grow" />
1006
+ <button
1007
+ type="button"
1008
+ className="iconbtn"
1009
+ title="关闭"
1010
+ aria-label="关闭"
1011
+ onClick={closeBesideSelf}
1012
+ >
1013
+ ×
1014
+ </button>
1015
+ </div>
1016
+ <div className="mdw-hist-ro">
1017
+ {!historyNode ? (
1018
+ <div className="muted">找不到链节点 #{historyId}</div>
1019
+ ) : (
1020
+ <>
1021
+ <div className="mdw-hist-meta">
1022
+ <span>{historyNode.at || '—'}</span>
1023
+ {historyNode.quote ? <span>锚定:{historyNode.quote.slice(0, 80)}</span> : null}
1024
+ {historyNode.feedback ? <span>反馈:{historyNode.feedback.slice(0, 80)}</span> : null}
1025
+ {historyNode.summary ? <span>上轮总结:{historyNode.summary.slice(0, 80)}</span> : null}
1026
+ </div>
1027
+ <article
1028
+ className="md-body"
1029
+ dangerouslySetInnerHTML={{ __html: html || '<p class="muted">(空)</p>' }}
1030
+ />
1031
+ </>
1032
+ )}
1033
+ </div>
1034
+ </div>
1035
+ );
1036
+ }
1037
+
834
1038
  // 读不到文档分两种:**还在读**(队列首轮没回来)与**确实没有这一条**(被删 / 深链写错)。
835
1039
  // 后者不该永远转圈——给一句实话 + 一个出口(回目录)。
836
1040
  if (!doc) {
@@ -859,6 +1063,12 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
859
1063
  <div className={`mdw${beside ? ' is-beside' : ''}`} data-mode={doc.mode || 'split'} onMouseUp={onPreviewMouseUp}>
860
1064
  {dialogNode}
861
1065
  {preview && <PreviewModal state={preview} onClose={() => setPreview(null)} />}
1066
+ <TaskChainModal
1067
+ open={chainOpen}
1068
+ nodes={chainNodes}
1069
+ onOpenNode={openHistoryBeside}
1070
+ onClose={() => setChainOpen(false)}
1071
+ />
862
1072
  {beside && (
863
1073
  <div className="mdw-beside-h">
864
1074
  <span className="mdw-beside-lab">原文(旁路)</span>
@@ -976,6 +1186,7 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
976
1186
  onOverview={() => app.onNavigate && app.onNavigate('#/overview')}
977
1187
  onFormat={(op) => editorApiRef.current?.format?.(op)}
978
1188
  onTurn={(id2) => editorApiRef.current?.turn?.(id2)}
1189
+ onChain={isDraft ? null : () => setChainOpen(true)}
979
1190
  />
980
1191
 
981
1192
  <MdPanes
@@ -1008,8 +1219,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
1008
1219
  />
1009
1220
 
1010
1221
  {/* 验收条:已完成任务的 ack 卡——放在**正文末尾**(用户口径):读完正文
1011
- 正好看到 agent 的完成总结,等你回复——划选正文评论 = 提详细问题(生成
1012
- 新任务);重做 = 评论模式下带反馈重开;通行 = 验收通过。 */}
1222
+ 正好看到 agent 的完成总结,等你回复——反馈 = 新开任务;划选评论 = 回写
1223
+ 本任务;通行 = 验收通过。 */}
1013
1224
  {!isDraft && taskRow?.completedAt && (
1014
1225
  <div className="mdw-review" ref={reviewBarRef}>
1015
1226
  <div className="mdw-review-main">
@@ -1040,8 +1251,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
1040
1251
  <span className="mdw-review-ok">已验收</span>
1041
1252
  ) : (
1042
1253
  <>
1043
- <button type="button" className="ghost" onClick={redoTask}>
1044
- 重做(带反馈)
1254
+ <button type="button" className="ghost" onClick={openFeedback} title="新开一条任务携带反馈(原任务不动)">
1255
+ 反馈
1045
1256
  </button>
1046
1257
  <button type="button" className="primary" onClick={ackReview}>
1047
1258
  通行
@@ -44,9 +44,18 @@ function DirPanelView({ dirKey }) {
44
44
  return wrap(<DirPanel dirKey={dirKey} />);
45
45
  }
46
46
 
47
- /** 一个 MD 页(编辑器):页签在工作区里,内容在会话内存里;beside=旁路原文(可关) */
48
- function PagePanelView({ dirKey, task, beside, tabId, model }) {
49
- return wrap(<PagePanel dirKey={dirKey} task={task} beside={!!beside} tabId={tabId} model={model} />);
47
+ /** 一个 MD 页(编辑器):页签在工作区里,内容在会话内存里;beside=旁路原文(可关);historyId=链节点只读 */
48
+ function PagePanelView({ dirKey, task, beside, tabId, model, historyId }) {
49
+ return wrap(
50
+ <PagePanel
51
+ dirKey={dirKey}
52
+ task={task}
53
+ beside={!!beside}
54
+ tabId={tabId}
55
+ model={model}
56
+ historyId={historyId != null ? Number(historyId) : null}
57
+ />,
58
+ );
50
59
  }
51
60
 
52
61
  /** 并发进程面板:独立成块,可拖到任意一边;task = 当前主区任务,用于高亮。
@@ -101,6 +110,7 @@ export const PANELS = {
101
110
  dirKey={cfg && cfg.dirKey}
102
111
  task={cfg && cfg.task}
103
112
  beside={cfg && cfg.beside}
113
+ historyId={cfg && cfg.historyId}
104
114
  tabId={ctx && ctx.tabId}
105
115
  model={ctx && ctx.model}
106
116
  />
@@ -1 +1 @@
1
- import{d as e,f as t,h as n,m as r,o as i,u as a}from"./attach-v8BxRJ7p.js";import{A as o,E as s,K as c,S as l,U as u,f as d,v as f,y as p}from"./index-BryAyn_9.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./md-history-vwtmQsFJ.js";var b=r({default:()=>w,useWikiNav:()=>C}),x=n(t(),1),S=e();function C(e){let t=u()||{},n=a(),r=e||t.model,i=(0,x.useRef)(null),l=(0,x.useCallback)(async()=>{if(!i.current)try{i.current=(await c(`/api/docs/index`)).index||[]}catch{i.current=[]}return i.current},[]),d=(0,x.useCallback)(async(e,t,n={})=>{let i=(t||await l()).find(t=>t.docId===e);o(r,{component:`doc`,name:i?i.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[r,l]),f=(0,x.useCallback)(async e=>{let t=await l(),r=s(e,t);if(r&&r.docId)return d(r.docId,t);if(r&&r.candidates)return n(`「${e}」同名文档多份:${r.candidates.join(`、`)}`);n(`未找到「${e}」——可用 nx-kv docs add <rel> 创建`)},[l,d,n]);return{nav:f,onClick:(0,x.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),f(t.getAttribute(`data-wl`)))},[f]),ensureIndex:l,openByDocId:d}}function w({docId:e,repoKey:t,boardKey:n,boardName:r,model:o}){let s=a(),{dialog:u,node:b}=i(),w=(0,x.useRef)(new Map),E=(0,x.useRef)(null),D=(0,x.useRef)(null),{onClick:O,openByDocId:k}=C(o),A=t?`repo`:n?`board`:``,j=t||n||``,M=(0,x.useMemo)(()=>t?{repoKey:t}:n?{boardKey:n,boardName:r||``}:{},[t,n,r]),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(``),[te,L]=(0,x.useState)(!1),[R,z]=(0,x.useState)(`split`),[B,V]=(0,x.useState)([]),[H,U]=(0,x.useState)(null),W=(0,x.useCallback)(async()=>{I(``);try{let t=await c(`/api/docs/item?ref=`+encodeURIComponent(e||``));P(t),L(!1)}catch(e){I(String(e.message||e)),P(null)}},[e]);(0,x.useEffect)(()=>{P(null),W()},[W]);let G=(0,x.useCallback)(()=>{if(!j){V([]);return}if(A===`repo`){c(`/api/repos/docs?id=`+encodeURIComponent(j)).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/${j}.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}),V(n)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}c(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===j||e.key===j),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})}V(r)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[j,A,e]);(0,x.useEffect)(()=>{G()},[G]);let[K,q]=(0,x.useState)(null);(0,x.useEffect)(()=>{c(`/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());q(t)}).catch(()=>{})},[]);let J=!!(N&&N.writable),Y=(0,x.useMemo)(()=>N?f(N.body,[],J?K:null):``,[N,K,J]),X=(0,x.useMemo)(()=>N?d(N.body):[],[N]);(0,x.useEffect)(()=>{let e=D.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;U(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>U(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[N,R,Y]);let Z=e=>e().catch(e=>s(String(e.message||e))),ne=(0,x.useCallback)(e=>k(e,null,M),[k,M]),re=()=>{j&&Z(async()=>{let t=await u({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=p(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?T(e):A===`repo`?`repo/${j}`:`board/${r||j}`}/reference/${n}.md`;await c(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{A===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:j,rel:i}}):await c(`/api/docs/link`,{method:`POST`,body:{board:j,doc:i}})}catch{}s(`已补充:${i}`),G(),k(`rel:`+i,null,M)})},Q=()=>Z(async()=>{if(!N||!J)return;let t=await c(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:N.body}});P(e=>({...e,body:N.body,summary:t.summary})),L(!1),y(w.current,e),s(t.summary?`已保存,摘要已回写`:`已保存`)}),ie=(t,n=`op`)=>{N&&(g(w.current,e,{body:N.body},n),L(!0),P(e=>({...e,body:t,title:l(t,e.title)})))},ae=(t,n=`typing`)=>{if(!N)return;g(w.current,e,{body:N.body},n),L(!0);let r=/^#\s+/m.test(N.body)?N.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${N.body}`;P(e=>({...e,body:r,title:t}))},oe=()=>{if(!N)return;let t=h(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:l(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},se=()=>{if(!N)return;let t=v(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:l(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},ce=()=>Z(async()=>{let t=String(e||``).startsWith(`rel:`)?e.slice(4):String(e||``).startsWith(`path:`)?``:String(e||``);if(!t)return;let n=t.replace(/\.md$/i,``).split(`/`).pop()||`未命名文档`;await c(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),s(`已创建:${t}`),await W()});if(N&&N.dir)return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.path}),(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,S.jsxs)(`div`,{className:`docp-files`,children:[N.files.map(e=>(0,S.jsx)(`button`,{className:`docp-file`,onClick:()=>k(`path:`+e,null),children:e},e)),!N.files.length&&(0,S.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(F)return(0,S.jsx)(`div`,{className:`mdw docp`,children:(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档打开失败`})}),(0,S.jsx)(`div`,{className:`hint`,children:F})]})});if(!N)return(0,S.jsx)(`div`,{className:`mdw`,children:(0,S.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(N.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsx)(`div`,{className:`docp-head`,children:(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.rel||N.path||e})}),(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,S.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,S.jsx)(`div`,{children:(0,S.jsx)(`button`,{className:`btn sm`,onClick:ce,children:`创建骨架`})})]})]})}let $=J?R:`preview`;return(0,S.jsxs)(`div`,{className:`mdw docp`,"data-mode":$,onClick:O,ref:D,children:[(0,S.jsxs)(`div`,{className:`mdw-main`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,title:N.rel||N.path,children:N.rel||N.path}),te&&(0,S.jsx)(`span`,{className:`docp-dirty`,children:`未保存`}),!J&&(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部绑定 · 只读`}),(0,S.jsx)(`span`,{className:`grow`}),J&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_,{mode:$,onChange:z}),(0,S.jsx)(`button`,{className:`btn sm docp-save`,onClick:Q,children:`保存`})]})]}),N.summary&&J&&(0,S.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,N.summary]}),(0,S.jsx)(m,{mode:$,title:N.title,body:N.body,previewHtml:Y,onTitle:J?ae:null,onBody:J?ie:null,attachments:[],docKey:e,editorApiRef:E,onSave:J?Q:null,onUndo:J?oe:null,onRedo:J?se:null}),(0,S.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,S.jsx)(ee,{headings:X,scrollRoot:H,links:B,activeDocId:e,onOpenDoc:j?ne:null,onAddRef:j?re:null}),b]})}function T(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 E(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 D(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function O({kind:e,owner:t,model:n}){let{openByDocId:r}=C(n),i=e===`board`?`组介绍`:`项目介绍`,a=e===`board`?t&&(t.id||t.key):t&&t.key,o=t&&t.name,s=(0,x.useMemo)(()=>E(t,e),[t,e]),[l,u]=(0,x.useState)([]),[d,f]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=(0,x.useCallback)(()=>h(e=>e+1),[]);(0,x.useEffect)(()=>{let n=!0;if(!a){u([]);return}if(e===`repo`)c(`/api/repos/docs?id=`+encodeURIComponent(a)).then(e=>{if(!n)return;let t=[],r=D(e.main);f(r||s),r&&t.push({docId:r,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=D(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=D(n);e&&t.push({docId:e,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}u(t)}).catch(()=>{n&&(u([]),f(s))});else{let e=()=>{let e=[];s&&e.push({docId:s,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=D(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};c(`/api/boards/`+encodeURIComponent(String(a))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),f(s);return}let i=[],a=D(t&&t.introMain)||s;f(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=D(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 r){let t=D(e);t&&i.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}u(i)}).catch(()=>{n&&(u(e()),f(s))})}return()=>{n=!1}},[e,a,t,s,m]);let _=(0,x.useMemo)(()=>e===`repo`&&a?{repoKey:a}:e===`board`&&a?{boardKey:a,boardName:o||``}:{},[e,a,o]);return{kind:e,label:i,ownerKey:a,docRef:s,mainDocId:d,links:l,openMain:(0,x.useCallback)(()=>{let e=d||s;e&&r(e,null,_)},[d,s,r,_]),openDoc:(0,x.useCallback)(e=>r(e,null,_),[r,_]),addRef:(0,x.useCallback)(async(t,n)=>{if(!a||!s.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let i=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(i===null)return null;let l=typeof i==`string`?i:i&&i.value||``,u=typeof i==`object`&&i&&i.tag||``,d=p(String(l).trim()||`note`).replace(/\.md$/i,``),f=`${T(s)||(e===`repo`?`repo/${a}`:`board/${o||a}`)}/reference/${d}.md`;await c(`/api/docs/item`,{method:`POST`,body:{rel:f,body:`# ${String(l).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:a,rel:f,tag:u||void 0}}):await c(`/api/docs/link`,{method:`POST`,body:{board:a,doc:f,tag:u||void 0}})}catch{}return n&&n(`已补充:${f}${u?` [${u}]`:``}`),g(),r(`rel:`+f,null,_),f},[a,s,e,o,r,_,g]),setLinkTag:(0,x.useCallback)(async(t,n,r)=>{if(!a)throw Error(`缺少归属`);let i=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},o=r&&r.note||``;e===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:a,...i,note:o||void 0,tag:n||void 0}}):await c(`/api/docs/link`,{method:`POST`,body:{board:a,doc:i.path||i.rel,note:o||void 0,tag:n||void 0}}),g()},[a,e,g]),reload:g,canEdit:!!s}}function k(e){return e<=1?18:e===2?12:8}function ee({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(``),u=(0,x.useMemo)(()=>e||[],[e]),d=(0,x.useMemo)(()=>n||[],[n]);(0,x.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,x.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,S.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${k(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,S.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,S.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,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,S.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,S.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function A({kind:e,owner:t,model:n}){let r=a(),{dialog:o,node:s}=i(),{label:c,docRef:l,links:u,openMain:d,openDoc:f,addRef:p,setLinkTag:m,canEdit:h}=O({kind:e,owner:t,model:n});if(!t||!l)return null;let g=u.find(e=>e.main),_=g?g.docId:l,v=_.startsWith(`rel:`)?_.slice(4):_,y=u.filter(e=>!e.main),b=()=>p(o,r).catch(e=>r(String(e.message||e))),x=e=>{(async()=>{let t=await o({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 m(e.docId,n,e),r(n?`标签已设为 [${n}]`:`标签已清除`)})().catch(e=>r(String(e.message||e)))};return(0,S.jsxs)(`div`,{className:`nx-intro`,children:[(0,S.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${c}(新页签阅读 / 编辑)`,onClick:d,children:c}),(0,S.jsx)(`span`,{className:`nx-intro-path mono`,children:v}),(0,S.jsx)(`span`,{className:`nx-intro-spacer`}),h&&l.startsWith(`rel:`)&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-btn`,title:`补充一篇介绍文档(reference)`,onClick:b,children:`+ ref`})]}),y.length>0&&(0,S.jsxs)(`div`,{className:`nx-intro-links`,children:[(0,S.jsx)(`span`,{className:`nx-intro-links-lab`,children:`补充`}),y.map(e=>(0,S.jsxs)(`span`,{className:`nx-intro-link-item`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`nx-intro-link`+(e.docId.startsWith(`path:`)?` ext`:``),title:e.note?`${e.label} — ${e.note}`:e.label,onClick:()=>f(e.docId),children:[(0,S.jsx)(`span`,{className:`nx-intro-link-label`,children:e.label}),e.tag?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,title:`标签:${e.tag}`,children:e.tag}):null,e.note?(0,S.jsx)(`span`,{className:`nx-intro-link-note`,children:e.note}):null,e.docId.startsWith(`path:`)?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,children:`外部`}):null]}),h&&!e.ref&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-tag-btn`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,"aria-label":`标签:${e.label}`,onClick:()=>x(e),children:`#`})]},e.docId))]}),s]})}export{b as n,C as r,A as t};
1
+ import{d as e,f as t,h as n,m as r,o as i,u as a}from"./attach-v8BxRJ7p.js";import{A as o,E as s,K as c,S as l,U as u,f as d,v as f,y as p}from"./index-CbZfbzqr.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./md-history-Ddk04A_2.js";var b=r({default:()=>w,useWikiNav:()=>C}),x=n(t(),1),S=e();function C(e){let t=u()||{},n=a(),r=e||t.model,i=(0,x.useRef)(null),l=(0,x.useCallback)(async()=>{if(!i.current)try{i.current=(await c(`/api/docs/index`)).index||[]}catch{i.current=[]}return i.current},[]),d=(0,x.useCallback)(async(e,t,n={})=>{let i=(t||await l()).find(t=>t.docId===e);o(r,{component:`doc`,name:i?i.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[r,l]),f=(0,x.useCallback)(async e=>{let t=await l(),r=s(e,t);if(r&&r.docId)return d(r.docId,t);if(r&&r.candidates)return n(`「${e}」同名文档多份:${r.candidates.join(`、`)}`);n(`未找到「${e}」——可用 nx-kv docs add <rel> 创建`)},[l,d,n]);return{nav:f,onClick:(0,x.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),f(t.getAttribute(`data-wl`)))},[f]),ensureIndex:l,openByDocId:d}}function w({docId:e,repoKey:t,boardKey:n,boardName:r,model:o}){let s=a(),{dialog:u,node:b}=i(),w=(0,x.useRef)(new Map),E=(0,x.useRef)(null),D=(0,x.useRef)(null),{onClick:O,openByDocId:k}=C(o),A=t?`repo`:n?`board`:``,j=t||n||``,M=(0,x.useMemo)(()=>t?{repoKey:t}:n?{boardKey:n,boardName:r||``}:{},[t,n,r]),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(``),[te,L]=(0,x.useState)(!1),[R,z]=(0,x.useState)(`split`),[B,V]=(0,x.useState)([]),[H,U]=(0,x.useState)(null),W=(0,x.useCallback)(async()=>{I(``);try{let t=await c(`/api/docs/item?ref=`+encodeURIComponent(e||``));P(t),L(!1)}catch(e){I(String(e.message||e)),P(null)}},[e]);(0,x.useEffect)(()=>{P(null),W()},[W]);let G=(0,x.useCallback)(()=>{if(!j){V([]);return}if(A===`repo`){c(`/api/repos/docs?id=`+encodeURIComponent(j)).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/${j}.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}),V(n)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}c(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===j||e.key===j),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})}V(r)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[j,A,e]);(0,x.useEffect)(()=>{G()},[G]);let[K,q]=(0,x.useState)(null);(0,x.useEffect)(()=>{c(`/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());q(t)}).catch(()=>{})},[]);let J=!!(N&&N.writable),Y=(0,x.useMemo)(()=>N?f(N.body,[],J?K:null):``,[N,K,J]),X=(0,x.useMemo)(()=>N?d(N.body):[],[N]);(0,x.useEffect)(()=>{let e=D.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;U(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>U(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[N,R,Y]);let Z=e=>e().catch(e=>s(String(e.message||e))),ne=(0,x.useCallback)(e=>k(e,null,M),[k,M]),re=()=>{j&&Z(async()=>{let t=await u({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=p(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?T(e):A===`repo`?`repo/${j}`:`board/${r||j}`}/reference/${n}.md`;await c(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{A===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:j,rel:i}}):await c(`/api/docs/link`,{method:`POST`,body:{board:j,doc:i}})}catch{}s(`已补充:${i}`),G(),k(`rel:`+i,null,M)})},Q=()=>Z(async()=>{if(!N||!J)return;let t=await c(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:N.body}});P(e=>({...e,body:N.body,summary:t.summary})),L(!1),y(w.current,e),s(t.summary?`已保存,摘要已回写`:`已保存`)}),ie=(t,n=`op`)=>{N&&(g(w.current,e,{body:N.body},n),L(!0),P(e=>({...e,body:t,title:l(t,e.title)})))},ae=(t,n=`typing`)=>{if(!N)return;g(w.current,e,{body:N.body},n),L(!0);let r=/^#\s+/m.test(N.body)?N.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${N.body}`;P(e=>({...e,body:r,title:t}))},oe=()=>{if(!N)return;let t=h(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:l(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},se=()=>{if(!N)return;let t=v(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:l(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},ce=()=>Z(async()=>{let t=String(e||``).startsWith(`rel:`)?e.slice(4):String(e||``).startsWith(`path:`)?``:String(e||``);if(!t)return;let n=t.replace(/\.md$/i,``).split(`/`).pop()||`未命名文档`;await c(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),s(`已创建:${t}`),await W()});if(N&&N.dir)return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.path}),(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,S.jsxs)(`div`,{className:`docp-files`,children:[N.files.map(e=>(0,S.jsx)(`button`,{className:`docp-file`,onClick:()=>k(`path:`+e,null),children:e},e)),!N.files.length&&(0,S.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(F)return(0,S.jsx)(`div`,{className:`mdw docp`,children:(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档打开失败`})}),(0,S.jsx)(`div`,{className:`hint`,children:F})]})});if(!N)return(0,S.jsx)(`div`,{className:`mdw`,children:(0,S.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(N.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsx)(`div`,{className:`docp-head`,children:(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.rel||N.path||e})}),(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,S.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,S.jsx)(`div`,{children:(0,S.jsx)(`button`,{className:`btn sm`,onClick:ce,children:`创建骨架`})})]})]})}let $=J?R:`preview`;return(0,S.jsxs)(`div`,{className:`mdw docp`,"data-mode":$,onClick:O,ref:D,children:[(0,S.jsxs)(`div`,{className:`mdw-main`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,title:N.rel||N.path,children:N.rel||N.path}),te&&(0,S.jsx)(`span`,{className:`docp-dirty`,children:`未保存`}),!J&&(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部绑定 · 只读`}),(0,S.jsx)(`span`,{className:`grow`}),J&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_,{mode:$,onChange:z}),(0,S.jsx)(`button`,{className:`btn sm docp-save`,onClick:Q,children:`保存`})]})]}),N.summary&&J&&(0,S.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,N.summary]}),(0,S.jsx)(m,{mode:$,title:N.title,body:N.body,previewHtml:Y,onTitle:J?ae:null,onBody:J?ie:null,attachments:[],docKey:e,editorApiRef:E,onSave:J?Q:null,onUndo:J?oe:null,onRedo:J?se:null}),(0,S.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,S.jsx)(ee,{headings:X,scrollRoot:H,links:B,activeDocId:e,onOpenDoc:j?ne:null,onAddRef:j?re:null}),b]})}function T(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 E(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 D(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function O({kind:e,owner:t,model:n}){let{openByDocId:r}=C(n),i=e===`board`?`组介绍`:`项目介绍`,a=e===`board`?t&&(t.id||t.key):t&&t.key,o=t&&t.name,s=(0,x.useMemo)(()=>E(t,e),[t,e]),[l,u]=(0,x.useState)([]),[d,f]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=(0,x.useCallback)(()=>h(e=>e+1),[]);(0,x.useEffect)(()=>{let n=!0;if(!a){u([]);return}if(e===`repo`)c(`/api/repos/docs?id=`+encodeURIComponent(a)).then(e=>{if(!n)return;let t=[],r=D(e.main);f(r||s),r&&t.push({docId:r,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=D(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=D(n);e&&t.push({docId:e,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}u(t)}).catch(()=>{n&&(u([]),f(s))});else{let e=()=>{let e=[];s&&e.push({docId:s,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=D(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};c(`/api/boards/`+encodeURIComponent(String(a))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),f(s);return}let i=[],a=D(t&&t.introMain)||s;f(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=D(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 r){let t=D(e);t&&i.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}u(i)}).catch(()=>{n&&(u(e()),f(s))})}return()=>{n=!1}},[e,a,t,s,m]);let _=(0,x.useMemo)(()=>e===`repo`&&a?{repoKey:a}:e===`board`&&a?{boardKey:a,boardName:o||``}:{},[e,a,o]);return{kind:e,label:i,ownerKey:a,docRef:s,mainDocId:d,links:l,openMain:(0,x.useCallback)(()=>{let e=d||s;e&&r(e,null,_)},[d,s,r,_]),openDoc:(0,x.useCallback)(e=>r(e,null,_),[r,_]),addRef:(0,x.useCallback)(async(t,n)=>{if(!a||!s.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let i=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(i===null)return null;let l=typeof i==`string`?i:i&&i.value||``,u=typeof i==`object`&&i&&i.tag||``,d=p(String(l).trim()||`note`).replace(/\.md$/i,``),f=`${T(s)||(e===`repo`?`repo/${a}`:`board/${o||a}`)}/reference/${d}.md`;await c(`/api/docs/item`,{method:`POST`,body:{rel:f,body:`# ${String(l).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:a,rel:f,tag:u||void 0}}):await c(`/api/docs/link`,{method:`POST`,body:{board:a,doc:f,tag:u||void 0}})}catch{}return n&&n(`已补充:${f}${u?` [${u}]`:``}`),g(),r(`rel:`+f,null,_),f},[a,s,e,o,r,_,g]),setLinkTag:(0,x.useCallback)(async(t,n,r)=>{if(!a)throw Error(`缺少归属`);let i=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},o=r&&r.note||``;e===`repo`?await c(`/api/repos/docs`,{method:`POST`,body:{id:a,...i,note:o||void 0,tag:n||void 0}}):await c(`/api/docs/link`,{method:`POST`,body:{board:a,doc:i.path||i.rel,note:o||void 0,tag:n||void 0}}),g()},[a,e,g]),reload:g,canEdit:!!s}}function k(e){return e<=1?18:e===2?12:8}function ee({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(``),u=(0,x.useMemo)(()=>e||[],[e]),d=(0,x.useMemo)(()=>n||[],[n]);(0,x.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,x.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,S.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${k(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,S.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,S.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,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,S.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,S.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function A({kind:e,owner:t,model:n}){let r=a(),{dialog:o,node:s}=i(),{label:c,docRef:l,links:u,openMain:d,openDoc:f,addRef:p,setLinkTag:m,canEdit:h}=O({kind:e,owner:t,model:n});if(!t||!l)return null;let g=u.find(e=>e.main),_=g?g.docId:l,v=_.startsWith(`rel:`)?_.slice(4):_,y=u.filter(e=>!e.main),b=()=>p(o,r).catch(e=>r(String(e.message||e))),x=e=>{(async()=>{let t=await o({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 m(e.docId,n,e),r(n?`标签已设为 [${n}]`:`标签已清除`)})().catch(e=>r(String(e.message||e)))};return(0,S.jsxs)(`div`,{className:`nx-intro`,children:[(0,S.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${c}(新页签阅读 / 编辑)`,onClick:d,children:c}),(0,S.jsx)(`span`,{className:`nx-intro-path mono`,children:v}),(0,S.jsx)(`span`,{className:`nx-intro-spacer`}),h&&l.startsWith(`rel:`)&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-btn`,title:`补充一篇介绍文档(reference)`,onClick:b,children:`+ ref`})]}),y.length>0&&(0,S.jsxs)(`div`,{className:`nx-intro-links`,children:[(0,S.jsx)(`span`,{className:`nx-intro-links-lab`,children:`补充`}),y.map(e=>(0,S.jsxs)(`span`,{className:`nx-intro-link-item`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`nx-intro-link`+(e.docId.startsWith(`path:`)?` ext`:``),title:e.note?`${e.label} — ${e.note}`:e.label,onClick:()=>f(e.docId),children:[(0,S.jsx)(`span`,{className:`nx-intro-link-label`,children:e.label}),e.tag?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,title:`标签:${e.tag}`,children:e.tag}):null,e.note?(0,S.jsx)(`span`,{className:`nx-intro-link-note`,children:e.note}):null,e.docId.startsWith(`path:`)?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,children:`外部`}):null]}),h&&!e.ref&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-tag-btn`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,"aria-label":`标签:${e.label}`,onClick:()=>x(e),children:`#`})]},e.docId))]}),s]})}export{b as n,C as r,A as t};