dsh-mindmap 0.13.1 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,6 +18,7 @@ A DeepSeek Harness plugin that turns a plain Markdown file into a live mindmap.
18
18
  - **Four tools** (`mindmap_create` / `mindmap_open` / `mindmap_get` / `mindmap_update`) — plain Markdown files in the session working directory; the root node title is the filename and stays in sync both ways (`renameRoot` renames the file, collisions are rejected).
19
19
  - **Live panel with zero extra channels** — the panel consumes the session snapshot (`mindmap_*` tool results), so every AI edit re-renders immediately.
20
20
  - **Reliable open, recoverable loading state** — AI create/open results always expand the panel (a structural-fingerprint selector drives snapshot recomputation even when the host reuses the nodes array reference); clicking a `.md` first reads it through the local read-only route, while AI fallback loading still recovers from case-only path mismatches, inline tool errors, and a ~30s watchdog timeout with one-click retry.
21
+ - **Graceful parse failure** — if a document's Markdown ever breaks the parser, the panel never crashes: the mindmap area shows an explicit parse-failed state with the error, the original file is left untouched, and you can switch back to the directory tab or let the AI fix the content and reopen. Normal documents never reach this path.
21
22
  - **Floating right panel or native sidebar tab** — when `dsh-better-sidebar` is installed, the mindmap registers as a native single-instance tab (`dsh-mindmap:mindmap`) inside Better Sidebar, with a compact one-row toolbar (mindmap list, current mindmap, and export on the same line); the header 思维脑图 button opens or focuses that tab. When Better Sidebar is absent, the panel falls back to a standalone floating right panel toggled by the 思维脑图 button — drag-resizable (280px ~ 80% viewport), persisted, and pushing the chat left (layout-push) so the two never overlap. AI create/open/view intents always open or focus the panel/tab and switch to the target document, including when it is currently closed or the same document is opened again. The mode switch is fully reversible: if Better Sidebar is unloaded mid-session, the standalone panel and layout-push CSS are restored automatically.
22
23
  - **Directory tree tab** — a persistent tree of the session working directory (served by plugin-owned read-only routes), lazy-loaded per directory; right-click to create a mindmap in the inbox or inside a directory; left-click a `.md` renders it through the read-only route first, then hands it to the AI for editing when the draft is empty. Labeled 目录 in standalone mode and 脑图列表 in sidebar mode.
23
24
  - **Single-mindmap mode** — two tabs only: the tree/list tab and 脑图 (the current mindmap); opening another `.md` replaces the previous one.
package/README.zh-CN.md CHANGED
@@ -18,6 +18,7 @@
18
18
  - **四个工具**(`mindmap_create` / `mindmap_open` / `mindmap_get` / `mindmap_update`)——会话工作目录里的普通 `.md` 文件;根节点标题 = 文件名,双向同步(`renameRoot` 触发文件重命名,撞名报错不覆盖)。
19
19
  - **零通道实时面板**——面板直接消费会话快照里的 `mindmap_*` 工具结果,AI 每改一步面板即渲染一次。
20
20
  - **打开必达 + 加载态可恢复**——AI create/open 结果落地,面板必展开(节点结构指纹驱动快照重算,不受宿主数组引用稳定性影响);点目录树 `.md` 会先走本地只读路由直接显示,AI fallback 加载态仍支持大小写路径自动匹配、工具错误提示、约 30 秒超时和一键重试。
21
+ - **解析失败显式成态**——文档 Markdown 万一让解析器崩掉,面板绝不整体炸:脑图区显示明确的解析失败态并带错误信息,原文件内容原样未动,可切回目录 tab 查看,或让 AI 修正后重新打开。正常文档永远走不到这里。
21
22
  - **原生侧栏 Tab 或右侧悬浮面板**——安装了 `dsh-better-sidebar` 时,脑图注册为 Better Sidebar 内的原生单实例 Tab(`dsh-mindmap:mindmap`),工具栏只有一行(脑图列表、当前脑图、导出图片在同一行);头部「思维脑图」按钮打开或聚焦该 Tab。未安装时回退为独立的右侧悬浮面板——会话头部按钮开合,宽度可拖(280px ~ 80% 视口)并持久化,打开时**聊天区向左让位**(布局推挤,互不遮挡)。AI 创建、打开或查看脑图时自动展开或聚焦面板/Tab 并切换到目标文档,即使当前收起或重复打开同一文档也能接续跟随。模式切换完全可逆:Better Sidebar 运行中卸载后,独立面板与布局推挤 CSS 自动恢复。
22
23
  - **常驻目录树 tab**——工作目录结构懒加载树(插件自建只读路由);空白处右键新建到脑图收件箱、目录右键新建到该目录;左键点 `.md` 先通过只读路由直接显示,再在草稿为空时交给 AI 对话编辑。独立面板模式标签为「目录」,侧栏模式标签为「脑图列表」。
23
24
  - **单脑图模式**——面板只有树/列表和「脑图」两个 tab,打开新脑图替换旧的那颗。
package/client.js CHANGED
@@ -284,6 +284,14 @@ window.__ModuleLoader__.load({
284
284
  const MAX_TABLE_COLUMNS = 100;
285
285
  const MAX_TABLE_ROWS = 1000;
286
286
  const MAX_TABLE_CELLS = 10000;
287
+ // 引用块递归深度上限:一行内海量 > 逐层剥前缀递归(实测 2000 层即栈溢出),
288
+ // 超限后剩余引用标记按普通段落文本处理——病理内容不炸面板,树始终可解析。
289
+ const MAX_QUOTE_DEPTH = 32;
290
+ // 链接 URL 允许一层括号嵌套(维基式 (bar)):配平的 () 属于 URL,未配平则整体不命中。
291
+ // 四处共用(render INLINE_PATTERN / 此处 hasInlineFormat / export 剥离 / render 切片契约),
292
+ // 任一处亲缘度被改歪,drift guard 测试即断言失败。JS 正则字面量不支持插值,
293
+ // 故抽成字符串片段,各处用 new RegExp 拼接——source 经脚本验证与原字面量逐字符一致。
294
+ const LINK_URL = "(?:[^()]|\\([^()]*\\))*";
287
295
 
288
296
  /** 缩进宽度:tab 按 4 空格折算。 */
289
297
  function indentWidth(raw) {
@@ -299,7 +307,14 @@ window.__ModuleLoader__.load({
299
307
  * 否则是 text 块。
300
308
  */
301
309
  function hasInlineFormat(text) {
302
- return /(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*)|(~~[^~]+~~)|(`[^`]+`)|(!?\[[^\]]*\]\([^)]*\))/.test(String(text ?? ""));
310
+ // 链接 URL 的嵌套括号亲缘度见 LINK_URL(与 render.js / export.js 四处同源)。
311
+ return new RegExp(
312
+ "(\\*\\*[^*]+\\*\\*)" +
313
+ "|(\\*[^*\\s][^*]*\\*)" +
314
+ "|(~~[^~]+~~)" +
315
+ "|(`[^`]+`)" +
316
+ "|(!?\\[[^\\]]*\\]\\(" + LINK_URL + "\\))"
317
+ ).test(String(text ?? ""));
303
318
  }
304
319
 
305
320
  /** 表格分隔行:由 | - : 空白组成且至少含一个 -。 */
@@ -332,11 +347,100 @@ window.__ModuleLoader__.load({
332
347
  // data.rows 不含分隔行(解析时剔除);复制时补回,粘回 Markdown 仍是合法表格。
333
348
  const escapeCell = (cell) => String(cell ?? "").replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
334
349
  const lines = data.rows.map((row) => `| ${row.map(escapeCell).join(" | ")} |`);
335
- if (data.rows.length > 1) lines.splice(1, 0, `| ${data.rows[0].map(() => "---").join(" | ")} |`);
350
+ // 只要有表头就补分隔行(含表头-only 表格)——粘回 Markdown 仍是合法表格。
351
+ if (data.rows.length >= 1) lines.splice(1, 0, `| ${data.rows[0].map(() => "---").join(" | ")} |`);
336
352
  return lines.join("\n");
337
353
  }
338
354
  return data.raw || node.topic || "";
339
355
  }
356
+
357
+ // 037 节点焦点上下文:空节点必须保留在路径里,不能被当成缺失节点。
358
+ const EMPTY_NODE_MARKER = "(这是一个空节点,节点客观存在,但节点容器内没有内容)";
359
+ const PATH_SEPARATOR = " >>> ";
360
+
361
+ /** 路径展示专用转义:不改节点原文,只避免分段包裹符破坏定位边界。 */
362
+ function escapePathSegment(text) {
363
+ return String(text ?? "")
364
+ .replace(/\r?\n/g, " ")
365
+ .replace(/【/g, "〔")
366
+ .replace(/】/g, "〕");
367
+ }
368
+
369
+ /** 节点在路径中的显示段;空 topic 用明确的空节点语义占位。 */
370
+ function nodePathLabel(node) {
371
+ const topic = String((node && node.topic) ?? "").trim();
372
+ return `【${escapePathSegment(topic || EMPTY_NODE_MARKER)}】`;
373
+ }
374
+
375
+ /** 找到根到目标节点的路径;目标不在当前树时退回目标自身,避免丢失焦点。 */
376
+ function nodePathTo(root, target) {
377
+ if (!target) return [];
378
+ const targetId = target.id;
379
+ const path = [];
380
+ const visit = (node) => {
381
+ if (!node) return false;
382
+ path.push(node);
383
+ if (node === target || (targetId != null && node.id === targetId)) return true;
384
+ for (const child of node.children || []) {
385
+ if (visit(child)) return true;
386
+ }
387
+ path.pop();
388
+ return false;
389
+ };
390
+ if (visit(root)) return path;
391
+ return [target];
392
+ }
393
+
394
+ /**
395
+ * 037 复制节点及子节点为文本:每个节点一行,每层 2 个半角空格。
396
+ * 多行节点内容的每一行都带同一层级前缀,空节点用明确标记保留其存在性。
397
+ */
398
+ function nodeTreeText(root) {
399
+ if (!root) return "";
400
+ const lines = [];
401
+ const visit = (node, depth) => {
402
+ const prefix = " ".repeat(Math.max(0, depth) * 2);
403
+ const own = String(nodeFullText(node) || "");
404
+ const body = own || EMPTY_NODE_MARKER;
405
+ for (const line of body.split(/\r?\n/)) lines.push(`${prefix}${line}`);
406
+ for (const child of node.children || []) visit(child, depth + 1);
407
+ };
408
+ visit(root, 0);
409
+ return lines.join("\n");
410
+ }
411
+
412
+ /**
413
+ * 037 围绕节点聊天:只发送当前节点自身与根→当前节点路径,绝不展开子树。
414
+ * 末尾协议要求模型完成一次短握手后等待用户继续,不让模型先复述上下文。
415
+ */
416
+ function nodeFocusPrompt(root, target) {
417
+ if (!target) return "";
418
+ const path = nodePathTo(root, target).map(nodePathLabel).join(PATH_SEPARATOR);
419
+ const own = String(nodeFullText(target) || "") || EMPTY_NODE_MARKER;
420
+ return [
421
+ "【插件功能声明】",
422
+ "你正在接收的是思维脑图插件发起的一次“节点焦点对齐”请求。",
423
+ "这是插件功能的一部分,不是用户普通聊天内容。",
424
+ "",
425
+ "【功能意图】",
426
+ "用户在思维脑图中选中了一个节点。插件现在要把你的注意力定位到这个节点上,后续对话将围绕这个节点继续进行。",
427
+ "",
428
+ "【定位路径】",
429
+ "以下路径表示从根节点到当前选中节点的完整父子关系;每个节点用【】包裹,使用“>>>”表示向下定位:",
430
+ path,
431
+ "",
432
+ "【当前选中节点内容】",
433
+ own,
434
+ "",
435
+ "【范围限制】",
436
+ "本次只提供当前选中节点及其定位路径,不展开当前节点的子节点、孙子节点或其他下级内容。",
437
+ "",
438
+ "【严格回复协议】",
439
+ "如果你已经理解上述插件功能意图和定位路径,你的下一条回复必须且只能是下面这一句话:",
440
+ "已理解和对齐您选中的节点,我们开始聊吧~",
441
+ "不得输出任何其他字符,不得添加解释、前缀、后缀、Markdown、表情或其他句子。回复完这句话后,等待用户继续提问。",
442
+ ].join("\n");
443
+ }
340
444
  //#endregion
341
445
 
342
446
  /**
@@ -381,7 +485,8 @@ window.__ModuleLoader__.load({
381
485
  * 块级解析循环(标题/列表/代码/引用/表格/段落)。引用块内容递归走本函数,
382
486
  * echoRoot=false 时不参与根标题回声。节点挂入 container(顶层 = root.children)。
383
487
  */
384
- function parseBlockLines(container, lineList, echoRoot) {
488
+ function parseBlockLines(container, lineList, echoRoot, depth) {
489
+ const quoteDepth = depth || 0;
385
490
  const headingStack = [];
386
491
  let listStack = [];
387
492
  const parentRec = () => (headingStack.length ? headingStack[headingStack.length - 1] : null);
@@ -545,6 +650,11 @@ window.__ModuleLoader__.load({
545
650
  // 递归走同一套块规则;首个 text/md 段提升为自身内容(001 §3.1),
546
651
  // 其余内容成为子节点。
547
652
  if (/^\s*>/.test(line)) {
653
+ // 深度上限见 MAX_QUOTE_DEPTH:超限后剩余 > 前缀按字面文本处理,不再递归。
654
+ if (quoteDepth >= MAX_QUOTE_DEPTH) {
655
+ paraBuffer.push(line.trim());
656
+ continue;
657
+ }
548
658
  flushParagraph();
549
659
  listStack = [];
550
660
  const inner = [];
@@ -552,7 +662,7 @@ window.__ModuleLoader__.load({
552
662
  for (; j < lineList.length && /^\s*>/.test(lineList[j]); j++) inner.push(lineList[j].replace(/^\s*>\s?/, ""));
553
663
  i = j - 1;
554
664
  const innerNodes = [];
555
- parseBlockLines(innerNodes, inner, false);
665
+ parseBlockLines(innerNodes, inner, false, quoteDepth + 1);
556
666
  let topic = "";
557
667
  const promoteIdx = innerNodes.findIndex((n) => n.kind === "text" || n.kind === "md");
558
668
  if (promoteIdx >= 0) {
@@ -595,6 +705,26 @@ window.__ModuleLoader__.load({
595
705
  dedupe(root);
596
706
  return root;
597
707
  }
708
+
709
+ /**
710
+ * 038 解析兜底:把 parseMarkdownToTree 包成「永不抛」的结果对。
711
+ * 病理内容或畸形入参(宿主给了非字符串)都不该炸掉整个面板;
712
+ * 出错时留痕(console.warn,供排查)+ 回传 error 让 UI 显示显式失败态——
713
+ * 旧版直接返回 null,渲染层随即静默走目录分支,tab 与内容自相矛盾且无迹可查。
714
+ * 调用方据 `error` 判定,不做静默降级。返回 { tree, error } 结果对。
715
+ */
716
+ function parseTreeResult(content, rootTitle) {
717
+ if (content === null || content === undefined) return { tree: null, error: null };
718
+ try {
719
+ return { tree: parseMarkdownToTree(content, rootTitle), error: null };
720
+ } catch (error) {
721
+ // 沙箱/宿主环境可能没有 console,防御后再留痕。
722
+ if (typeof console !== "undefined" && console && typeof console.warn === "function") {
723
+ console.warn("[dsh-mindmap] markdown 解析失败:", error);
724
+ }
725
+ return { tree: null, error: String((error && error.message) || error) };
726
+ }
727
+ }
598
728
  //#endregion
599
729
 
600
730
  //#region 018 生长动画:树 id 收集 + 渐显计划(纯函数,经 internals 供测试)
@@ -1025,6 +1155,19 @@ window.__ModuleLoader__.load({
1025
1155
  const draft = readDraftText(inputActions);
1026
1156
  return typeof draft === "string" && draft.trim() !== "";
1027
1157
  }
1158
+
1159
+ /** 037 节点焦点消息:保护现有草稿后,原子地写入并提交到当前 DSH 对话。 */
1160
+ function submitNodeFocusMessage(inputActions, text) {
1161
+ if (draftBlocksAutoSend(inputActions)) {
1162
+ throw new Error("当前聊天框已有未发送内容,请先处理后再围绕节点聊天");
1163
+ }
1164
+ if (!inputActions || typeof inputActions.setDraft !== "function" || typeof inputActions.submit !== "function") {
1165
+ throw new Error("当前对话不支持自动发送节点焦点消息");
1166
+ }
1167
+ inputActions.setDraft(String(text ?? ""));
1168
+ inputActions.submit();
1169
+ return true;
1170
+ }
1028
1171
  //#endregion
1029
1172
 
1030
1173
  //#region 025 子树折叠:画布视图态纯函数(不进 markdown 资产,只影响呈现)
@@ -1167,9 +1310,10 @@ window.__ModuleLoader__.load({
1167
1310
 
1168
1311
  /** 019 行内格式剥离:导出为纯文本(URL 原样保留——完整不缩减,003 §7)。 */
1169
1312
  function stripInlineForExport(text) {
1313
+ // 链接 URL 的嵌套括号亲缘度见 markdown.js 的 LINK_URL(四处同源)。
1170
1314
  return String(text ?? "")
1171
- .replace(/!\[([^\]]*)\]\(([^)]*)\)/g, "$2")
1172
- .replace(/\[([^\]]*)\]\(([^)]*)\)/g, (m, label, url) => (label ? `${label}(${url})` : url))
1315
+ .replace(new RegExp("!\\[([^\\]]*)\\]\\((" + LINK_URL + ")\\)", "g"), "$2")
1316
+ .replace(new RegExp("\\[([^\\]]*)\\]\\((" + LINK_URL + ")\\)", "g"), (m, label, url) => (label ? `${label}(${url})` : url))
1173
1317
  .replace(/`([^`]+)`/g, "$1")
1174
1318
  .replace(/\*\*([^*]+)\*\*/g, "$1")
1175
1319
  .replace(/~~([^~]+)~~/g, "$1")
@@ -1469,7 +1613,8 @@ window.__ModuleLoader__.load({
1469
1613
  treeRefreshHover: { background: "var(--dsw-alias-interactive-bg-hover)", color: "var(--dsw-alias-label-primary)" },
1470
1614
  treeError: { color: "var(--dsw-alias-label-error)", fontSize: "12px", lineHeight: 1.6, margin: "0" },
1471
1615
  treeMenu: { position: "fixed", zIndex: 60, minWidth: "210px", background: "var(--dsw-alias-bg-layer-3)", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "6px", boxShadow: "var(--dsw-shadow-lv2)" },
1472
- treeMenuItem: { display: "block", width: "100%", boxSizing: "border-box", textAlign: "left", border: "none", background: "none", cursor: "pointer", padding: "7px 12px", borderRadius: "8px", font: "inherit", fontSize: "13px", color: "var(--dsw-alias-label-primary)" },
1616
+ treeMenuItem: { display: "block", width: "100%", boxSizing: "border-box", textAlign: "left", border: "none", background: "none", cursor: "pointer", padding: "7px 12px", borderRadius: "8px", font: "inherit", fontSize: "13px", color: "var(--dsw-alias-label-primary)", transition: "background 0.08s ease, color 0.08s ease" },
1617
+ treeMenuItemHover: { background: "var(--dsw-alias-interactive-bg-hover)", color: "var(--dsw-alias-label-primary)" },
1473
1618
  // 017 画布节点右键菜单:标题行(节点主题)+ 错误行 + 菜单项禁用态。
1474
1619
  nodeMenuHeader: { padding: "4px 12px 6px", fontSize: "12px", color: "var(--dsw-alias-label-tertiary)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", maxWidth: "220px", boxSizing: "border-box" },
1475
1620
  // 020:标题(节点主题)与动作项之间的分隔线,拉开层次。
@@ -1794,7 +1939,16 @@ window.__ModuleLoader__.load({
1794
1939
  // 先命中先生效,裸链接放最后,避免吞掉已被 [文字](url) 消费的 URL。
1795
1940
  // 裸链接字符类排除 CJK 标点与全角符号(,。、;()……),
1796
1941
  // 否则中文句读被吞进 URL;ASCII 括号放行,由配平裁剪兜底。
1797
- const INLINE_PATTERN = /(!?\[[^\]]*\]\([^)]*\))|(`[^`]+`)|(\*\*[^*]+\*\*)|(~~[^~]+~~)|(\*[^*\s][^*]*\*)|(https?:\/\/[^\s\u3000-\u303f\uff00-\uffef]+)/g;
1942
+ // 链接 URL 的嵌套括号亲缘度见 markdown.js 的 LINK_URL(四处同源)。
1943
+ const INLINE_PATTERN = new RegExp(
1944
+ "(!?\\[[^\\]]*\\]\\(" + LINK_URL + "\\))" +
1945
+ "|(`[^`]+`)" +
1946
+ "|(\\*\\*[^*]+\\*\\*)" +
1947
+ "|(~~[^~]+~~)" +
1948
+ "|(\\*[^*\\s][^*]*\\*)" +
1949
+ "|(https?:\\/\\/[^\\s\\u3000-\\u303f\\uff00-\\uffef]+)",
1950
+ "g"
1951
+ );
1798
1952
 
1799
1953
  /** 大一统链接点击:在机器浏览器打开(新标签页),不触发画布聚焦缩放。 */
1800
1954
  function openLink(event, url) {
@@ -1813,6 +1967,23 @@ window.__ModuleLoader__.load({
1813
1967
  event.preventDefault();
1814
1968
  }
1815
1969
 
1970
+ /**
1971
+ * 038 行内链接 token 拆解:`[文字](url)` / `![alt](url)` → { bang, label, url }。
1972
+ * token 形态由 INLINE_PATTERN 第 1 组保证(label 不含 `]`、以 `)` 收尾),这里做
1973
+ * 纯切片而不重复解析:旧版用**第二个正则**重解析 token,两处正则一旦不同步
1974
+ * (实测:只改一处)parsed 为 null,`parsed[3]` 直接 TypeError 炸整个渲染。
1975
+ * 契约失配时返回 null,调用方原样退化为纯文本——不抛异常、不丢字符。
1976
+ */
1977
+ function parseInlineLinkToken(token) {
1978
+ if (typeof token !== "string" || token.length < 4) return null;
1979
+ const bang = token[0] === "!";
1980
+ const open = token.indexOf("](");
1981
+ // open 必须正好是标签的收尾方括号:更早/未命中说明 label 里混了 `]`,
1982
+ // 形态与 INLINE_PATTERN 的 `[^\]]*` 契约不符。
1983
+ if (open < 0 || open !== token.indexOf("]") || !token.endsWith(")")) return null;
1984
+ return { bang, label: token.slice(bang ? 2 : 1, open), url: token.slice(open + 2, -1) };
1985
+ }
1986
+
1816
1987
  /**
1817
1988
  * 零依赖行内渲染器:任何块(文本/Markdown/列表/表格单元格)的内容都走这里。
1818
1989
  * 链接完整呈现、永不缩减(缩减=阉割信息,003 §7);无预览、无加载态。
@@ -1832,24 +2003,27 @@ window.__ModuleLoader__.load({
1832
2003
  if (m[1]) {
1833
2004
  // [文字](url) 或 ![alt](url)。图片块暂缓(003 §9):图语法退化为
1834
2005
  // 指向原图的链接,同时把 alt 与原图地址都完整呈现(不缩减)。
1835
- const parsed = /^(!?)\[([^\]]*)\]\(([^)]*)\)$/.exec(token);
2006
+ // URL 的括号嵌套由 INLINE_PATTERN 负责识别,这里只做切片(契约见
2007
+ // parseInlineLinkToken)。
2008
+ const parsed = parseInlineLinkToken(token);
1836
2009
  // scheme 白名单:只放行 http/https/mailto。javascript:/data:
1837
2010
  // 等不进 href,整串原样退化为纯文本(不缩减,也不可执行)。
1838
- if (!/^\s*(https?:|mailto:)/i.test(parsed[3])) {
2011
+ // parsed 为 null(token 形态意外)同样退化为纯文本,不炸渲染。
2012
+ if (!parsed || !/^\s*(https?:|mailto:)/i.test(parsed.url)) {
1839
2013
  out.push(token);
1840
2014
  } else {
1841
2015
  // 普通链接标签取文字(无文字显地址);图语法带 alt 时两者都完整呈现。
1842
- const label = parsed[1]
1843
- ? (parsed[2] ? `${parsed[2]} (${parsed[3]})` : parsed[3])
1844
- : (parsed[2] || parsed[3]);
2016
+ const label = parsed.bang
2017
+ ? (parsed.label ? `${parsed.label} (${parsed.url})` : parsed.url)
2018
+ : (parsed.label || parsed.url);
1845
2019
  out.push((0, react_jsx_runtime.jsx)("a", {
1846
2020
  key,
1847
- href: parsed[3],
2021
+ href: parsed.url,
1848
2022
  target: "_blank",
1849
2023
  rel: "noopener noreferrer",
1850
2024
  style: S.inlineLink,
1851
- title: parsed[3],
1852
- onClick: (e) => openLink(e, parsed[3]),
2025
+ title: parsed.url,
2026
+ onClick: (e) => openLink(e, parsed.url),
1853
2027
  children: label,
1854
2028
  }, key));
1855
2029
  }
@@ -2123,6 +2297,24 @@ window.__ModuleLoader__.load({
2123
2297
  ] });
2124
2298
  }
2125
2299
 
2300
+ //#region 038 脑图区主体模式:目录 / 加载中 / 解析失败 / 画布(纯函数,经 internals 供测试)
2301
+ /**
2302
+ * 解析失败必须显式成态:旧版把解析异常吞成 null,渲染层随即走目录分支——
2303
+ * tab 停在脑图上、内容区却是目录列表,用户看不到任何提示(038 评审发现)。
2304
+ * 抽成纯函数让四个分支都能单测,组件只按返回值分派。
2305
+ */
2306
+ // 四态枚举:workspacerender.js 的分派与测试断言都引用这份常量,
2307
+ // 避免裸串散落、拼写失配静默走错分支。
2308
+ const BODY_MODE = Object.freeze({ tree: "tree", loading: "loading", error: "error", canvas: "canvas" });
2309
+ function mindmapBodyMode(active, treeTab, doc, tree, parseError) {
2310
+ if (active === treeTab) return BODY_MODE.tree;
2311
+ if (doc && doc.op === "local") return BODY_MODE.loading;
2312
+ if (parseError) return BODY_MODE.error;
2313
+ if (!tree) return BODY_MODE.tree;
2314
+ return BODY_MODE.canvas;
2315
+ }
2316
+ //#endregion
2317
+
2126
2318
  //#region 016 脑图画布:居中呈现 + 缩放控制(右上角)
2127
2319
  // 缩放契约:范围 [0.25, 3],每级 ×1.2;适配计算四周留 48px 余量
2128
2320
  //(16px 视觉内距 + 经典滚动条占位,避免「适配→滚动条出现→视口变
@@ -2280,7 +2472,7 @@ window.__ModuleLoader__.load({
2280
2472
  * 修正 scroll,视图不跳变(内容回到视口内时浏览器会自动钳制回 0)。
2281
2473
  */
2282
2474
  function MindmapCanvas(props) {
2283
- const { node, theme, fitKey, reveal } = props;
2475
+ const { node, theme, fitKey, reveal, inputActions } = props;
2284
2476
  const scrollRef = react.useRef(null);
2285
2477
  const contentRef = react.useRef(null);
2286
2478
  const zoomRef = react.useRef(1);
@@ -2304,11 +2496,12 @@ window.__ModuleLoader__.load({
2304
2496
  const fitStampRef = react.useRef([]);
2305
2497
  const [zoom, setZoomState] = react.useState(1);
2306
2498
  const [hover, setHover] = react.useState(null);
2307
- // 017 节点右键菜单:{x, y, node};null = 关闭。busy = "copy" |
2308
- // "export" 表示对应动作进行中(两项都禁用),error 展示失败原因。
2499
+ // 037 节点右键菜单:{x, y, node};null = 关闭。busy 标记 chat/text/
2500
+ // copy/export 中的当前动作;任一动作在途时整张菜单禁用。
2309
2501
  const [nodeMenu, setNodeMenu] = react.useState(null);
2310
2502
  const [nodeMenuBusy, setNodeMenuBusy] = react.useState(null);
2311
2503
  const [nodeMenuError, setNodeMenuError] = react.useState("");
2504
+ const [nodeMenuHover, setNodeMenuHover] = react.useState(null);
2312
2505
  const nodeMenuRef = react.useRef(null);
2313
2506
  // 019 选中态:点击聚焦的节点下选选中环(002 §6 状态体系)。
2314
2507
  const [selectedId, setSelectedId] = react.useState(null);
@@ -2729,36 +2922,19 @@ window.__ModuleLoader__.load({
2729
2922
  // 递归 TreeRow 传回调。聚焦视为用户手动缩放(停自动再适配)。
2730
2923
  // 033:目标比例经 clampFocusJump 单次最多 ×2/÷2(巨图点叶子不再一步
2731
2924
  // 怼到 100%,连点渐进 drill);zoom 变化经 animateZoomTo 平滑过渡。
2732
- function onCanvasClick(e) {
2733
- // 021:刚拖过画布(平移)的这次 click 不是点击,直接吞掉——
2734
- // 否则每次平移松手都会顺手把选中环清掉。
2735
- if (suppressClickRef.current) {
2736
- suppressClickRef.current = false;
2737
- return;
2738
- }
2739
- const target = e.target;
2740
- if (!target || typeof target.closest !== "function") return;
2741
- const boxEl = target.closest("[data-mindmap-node]");
2742
- if (!boxEl || !boxEl.isConnected) {
2743
- // 019 空白处点击:取消选中环(链接点击已 stopPropagation,不走这里)。
2744
- setSelectedId(null);
2745
- return;
2746
- }
2747
- // 019:聚焦同时记选中态(盒包裹上挂了 data-mindmap-node-id)。
2925
+ function focusNodeBox(boxEl) {
2926
+ if (!boxEl || !boxEl.isConnected) return false;
2748
2927
  setSelectedId(boxEl.getAttribute("data-mindmap-node-id"));
2749
2928
  const rowEl = boxEl.closest("[data-mindmap-row]");
2750
- if (!rowEl) return;
2929
+ if (!rowEl) return false;
2751
2930
  const scroller = scrollRef.current;
2752
- if (!scroller) return;
2931
+ if (!scroller) return false;
2753
2932
  const current = zoomRef.current;
2754
2933
  const rowRect = rowEl.getBoundingClientRect();
2755
- // 033 跳变钳制:相对当前比例单次最多 ×2 / ÷2。
2756
2934
  const focus = clampFocusJump(
2757
2935
  focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight),
2758
2936
  current,
2759
2937
  );
2760
- // 034:记录点击时节点中心的视口比例位置——动画锚位插值起点
2761
- //(第一帧期望位置 = 点击时位置,消除首帧滚动瞬移)。
2762
2938
  const boxRect = boxEl.getBoundingClientRect();
2763
2939
  const scrollerRect = scroller.getBoundingClientRect();
2764
2940
  const startAnchor = {
@@ -2768,8 +2944,6 @@ window.__ModuleLoader__.load({
2768
2944
  userZoomedRef.current = true;
2769
2945
  if (focus !== current) {
2770
2946
  anchorRef.current = null;
2771
- // 034:先完整截停旧动画(清过期 focusRef + 同步中间值),
2772
- // 再登记本次聚焦——顺序不能反(cancel 会清 focusRef)。
2773
2947
  cancelZoomAnim();
2774
2948
  focusRef.current = { boxEl, startAnchor };
2775
2949
  animateZoomTo(focus);
@@ -2778,6 +2952,26 @@ window.__ModuleLoader__.load({
2778
2952
  focusRef.current = { boxEl, startAnchor };
2779
2953
  positionFocus();
2780
2954
  }
2955
+ return true;
2956
+ }
2957
+
2958
+ function onCanvasClick(e) {
2959
+ // 021:刚拖过画布(平移)的这次 click 不是点击,直接吞掉——
2960
+ // 否则每次平移松手都会顺手把选中环清掉。
2961
+ if (suppressClickRef.current) {
2962
+ suppressClickRef.current = false;
2963
+ return;
2964
+ }
2965
+ const target = e.target;
2966
+ if (!target || typeof target.closest !== "function") return;
2967
+ const boxEl = target.closest("[data-mindmap-node]");
2968
+ if (!boxEl || !boxEl.isConnected) {
2969
+ // 019 空白处点击:取消选中环(链接点击已 stopPropagation,不走这里)。
2970
+ setSelectedId(null);
2971
+ return;
2972
+ }
2973
+ // 019:聚焦同时记选中态(盒包裹上挂了 data-mindmap-node-id)。
2974
+ focusNodeBox(boxEl);
2781
2975
  }
2782
2976
 
2783
2977
  // 034 锚位应用:把节点盒中心滚到指定视口比例锚位(滚动增量与视口
@@ -2976,14 +3170,24 @@ window.__ModuleLoader__.load({
2976
3170
  setCollapsed((prev) => toggleCollapsed(prev, id));
2977
3171
  }
2978
3172
 
2979
- // 017 右键节点:记录菜单锚点与目标子树(清掉上次的忙碌/错误态)。
3173
+ // 037 节点焦点聊天:沿用目录树的自动发送能力,但不覆盖用户已有草稿。
3174
+ function submitNodeChat(text) {
3175
+ return submitNodeFocusMessage(inputActions, text);
3176
+ }
3177
+
3178
+ // 037 右键节点:先完成与左键相同的注意力聚焦,再记录菜单锚点。
2980
3179
  function onNodeContextMenu(e, target) {
3180
+ const boxEl = e && e.currentTarget && typeof e.currentTarget.closest === "function"
3181
+ ? e.currentTarget
3182
+ : (e && e.target && typeof e.target.closest === "function" ? e.target.closest("[data-mindmap-node]") : null);
3183
+ focusNodeBox(boxEl);
2981
3184
  setNodeMenuBusy(null);
2982
3185
  setNodeMenuError("");
3186
+ setNodeMenuHover(null);
2983
3187
  setNodeMenu({ x: e.clientX, y: e.clientY, node: target });
2984
3188
  }
2985
3189
 
2986
- // 017 菜单动作:text = 节点全文写剪贴板(020);copy = PNG 写系统剪贴板
3190
+ // 037 菜单动作:chat = 节点焦点上下文自动发送;text = 子树文本写剪贴板;copy = PNG 写系统剪贴板
2987
3191
  // (可粘贴到聊天/文档);export = PNG 下载为文件。图片范围 = 该节点
2988
3192
  // 及其全部子孙(buildExportSvg 以任意节点为根重排布局,根样式随深度判定)。
2989
3193
  async function onNodeMenuAction(mode) {
@@ -2992,7 +3196,8 @@ window.__ModuleLoader__.load({
2992
3196
  setNodeMenuBusy(mode);
2993
3197
  setNodeMenuError("");
2994
3198
  try {
2995
- if (mode === "text") await copyPlainText(nodeFullText(target));
3199
+ if (mode === "chat") submitNodeChat(nodeFocusPrompt(node, target));
3200
+ else if (mode === "text") await copyPlainText(nodeTreeText(target));
2996
3201
  else if (mode === "copy") await copyPng(target, theme && theme.colorTheme);
2997
3202
  else await exportPng(target, target.topic, theme && theme.colorTheme);
2998
3203
  setNodeMenu(null);
@@ -3009,6 +3214,13 @@ window.__ModuleLoader__.load({
3009
3214
  const zoomBtnStyle = (key, disabled) => (disabled
3010
3215
  ? { ...S.zoomBtn, ...S.zoomBtnDisabled }
3011
3216
  : (hover === key ? { ...S.zoomBtn, ...S.zoomBtnHover } : S.zoomBtn));
3217
+ const nodeMenuItemStyle = (key) => (nodeMenuBusy
3218
+ ? { ...S.treeMenuItem, ...S.treeMenuItemDisabled }
3219
+ : (nodeMenuHover === key ? { ...S.treeMenuItem, ...S.treeMenuItemHover } : S.treeMenuItem));
3220
+ const nodeMenuHoverProps = (key) => ({
3221
+ onMouseEnter: () => setNodeMenuHover(key),
3222
+ onMouseLeave: () => setNodeMenuHover((current) => (current === key ? null : current)),
3223
+ });
3012
3224
 
3013
3225
  return (0, react_jsx_runtime.jsxs)("div", {
3014
3226
  style: S.canvasWrap,
@@ -3170,8 +3382,7 @@ window.__ModuleLoader__.load({
3170
3382
  children: "✕",
3171
3383
  }),
3172
3384
  ] }) : null,
3173
- // 017 节点右键菜单:标题行(节点主题)+ 复制全文/复制为图片/导出为
3174
- // 图片三动作 + 错误行。复用目录树菜单容器样式(fixed 定位,left/top = 视口坐标)。
3385
+ // 037 节点右键菜单:标题 + 核心聊天入口 + 分隔线 + 文本/图片动作。
3175
3386
  nodeMenu ? (0, react_jsx_runtime.jsxs)("div", {
3176
3387
  ref: nodeMenuRef,
3177
3388
  style: { ...S.treeMenu, left: nodeMenu.x, top: nodeMenu.y },
@@ -3182,28 +3393,40 @@ window.__ModuleLoader__.load({
3182
3393
  title: nodeMenu.node.topic || "待填写",
3183
3394
  children: truncateForExport(nodeMenu.node.topic, 18) || "待填写",
3184
3395
  }),
3396
+ (0, react_jsx_runtime.jsx)("button", {
3397
+ type: "button",
3398
+ style: nodeMenuItemStyle("chat"),
3399
+ disabled: Boolean(nodeMenuBusy),
3400
+ ...nodeMenuHoverProps("chat"),
3401
+ title: "把当前节点的定位路径与自身内容发送到当前对话,围绕该节点继续聊天",
3402
+ onClick: () => onNodeMenuAction("chat"),
3403
+ children: nodeMenuBusy === "chat" ? "发送中…" : "围绕该节点与 AI 聊天",
3404
+ }),
3185
3405
  // 020:标题与动作项之间拉一根分隔线。
3186
3406
  (0, react_jsx_runtime.jsx)("div", { style: S.nodeMenuDivider }),
3187
3407
  (0, react_jsx_runtime.jsx)("button", {
3188
3408
  type: "button",
3189
- style: nodeMenuBusy ? { ...S.treeMenuItem, ...S.treeMenuItemDisabled } : S.treeMenuItem,
3409
+ style: nodeMenuItemStyle("text"),
3190
3410
  disabled: Boolean(nodeMenuBusy),
3191
- title: "把该节点自身内容的完整文本复制到剪贴板(截断块/代码块/表格块均取全文)",
3411
+ ...nodeMenuHoverProps("text"),
3412
+ title: "把该节点及其全部子节点按层级缩进复制为文本",
3192
3413
  onClick: () => onNodeMenuAction("text"),
3193
- children: nodeMenuBusy === "text" ? "复制中…" : "复制全文",
3414
+ children: nodeMenuBusy === "text" ? "复制中…" : "复制节点及子节点为文本",
3194
3415
  }),
3195
3416
  (0, react_jsx_runtime.jsx)("button", {
3196
3417
  type: "button",
3197
- style: nodeMenuBusy ? { ...S.treeMenuItem, ...S.treeMenuItemDisabled } : S.treeMenuItem,
3418
+ style: nodeMenuItemStyle("copy"),
3198
3419
  disabled: Boolean(nodeMenuBusy),
3420
+ ...nodeMenuHoverProps("copy"),
3199
3421
  title: "把该节点及其全部子孙渲染为 PNG 并复制到剪贴板",
3200
3422
  onClick: () => onNodeMenuAction("copy"),
3201
3423
  children: nodeMenuBusy === "copy" ? "复制中…" : "复制为图片",
3202
3424
  }),
3203
3425
  (0, react_jsx_runtime.jsx)("button", {
3204
3426
  type: "button",
3205
- style: nodeMenuBusy ? { ...S.treeMenuItem, ...S.treeMenuItemDisabled } : S.treeMenuItem,
3427
+ style: nodeMenuItemStyle("export"),
3206
3428
  disabled: Boolean(nodeMenuBusy),
3429
+ ...nodeMenuHoverProps("export"),
3207
3430
  title: "把该节点及其全部子孙渲染为 PNG 并下载为文件",
3208
3431
  onClick: () => onNodeMenuAction("export"),
3209
3432
  children: nodeMenuBusy === "export" ? "导出中…" : "导出为图片",
@@ -3350,10 +3573,14 @@ window.__ModuleLoader__.load({
3350
3573
  : (lastPath && lastPath !== hiddenPath ? lastPath : null);
3351
3574
  const active = view === "mindmap" && shown ? shown : TREE_TAB;
3352
3575
  const doc = active !== TREE_TAB && merged.byPath[active] ? merged.byPath[active] : null;
3353
- const tree = react.useMemo(
3354
- () => (doc ? parseMarkdownToTree(doc.content, doc.rootTitle) : null),
3576
+ const parsed = react.useMemo(
3577
+ () => parseTreeResult(doc && doc.content, doc && doc.rootTitle),
3355
3578
  [doc && doc.content, doc && doc.rootTitle],
3356
3579
  );
3580
+ const tree = parsed.tree;
3581
+ // 038 解析失败不再静默:error 非空时脑图区显示显式失败态(见 mindmapBodyMode),
3582
+ // 而不是渲染层悄悄退回目录、tab 与内容自相矛盾(旧版吞异常返 null)。
3583
+ const parseError = parsed.error;
3357
3584
 
3358
3585
  // 018 生长动画调度:新树与上一版(同 path)的稳定 id 集做 diff,只对新增/
3359
3586
  // 变化节点出渐显计划(planGrowthReveal 广度优先错峰、总时长 ≤ 2s);播完定时清空,
@@ -3969,6 +4196,17 @@ window.__ModuleLoader__.load({
3969
4196
 
3970
4197
  // 027 目录/列表标签文案:sidebar 模式叫「脑图列表」,standalone 模式叫「目录」。
3971
4198
  const treeTabLabel = variant === "sidebar" ? "脑图列表" : "目录";
4199
+ // 038 脑图区主体模式(目录 / 加载中 / 解析失败 / 画布):判定抽成纯函数,两个 variant
4200
+ // 共用同一份分派,不再各写一遍三元链;解析失败有独立分支,不再静默走目录。
4201
+ // 四态常量见 render.js 的 BODY_MODE(mindmapBodyMode 返回值与其同源)。
4202
+ const bodyMode = mindmapBodyMode(active, TREE_TAB, doc, tree, parseError);
4203
+ const parseErrorView = bodyMode === BODY_MODE.error
4204
+ ? (0, react_jsx_runtime.jsxs)("div", { style: S.loadingWrap, children: [
4205
+ (0, react_jsx_runtime.jsx)("span", { style: S.loadingFailMark, children: "⚠" }),
4206
+ (0, react_jsx_runtime.jsx)("p", { style: S.loadingErrorText, children: `脑图解析失败:${parseError}` }),
4207
+ (0, react_jsx_runtime.jsx)("p", { style: S.loadingText, children: "原文件内容未改动;可切回目录查看,或让 AI 修正后重新打开。" }),
4208
+ ] })
4209
+ : null;
3972
4210
 
3973
4211
  if (variant === "sidebar") {
3974
4212
  // 027 sidebar 模式:单行紧凑工具栏。BS 外层已有 Tab 头部与关闭按钮,
@@ -4025,13 +4263,13 @@ window.__ModuleLoader__.load({
4025
4263
  ] }),
4026
4264
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4027
4265
  // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4028
- active === TREE_TAB || (doc && doc.op === "local") || !tree
4029
- ? (0, react_jsx_runtime.jsx)("div", { style: S.body, children: active === TREE_TAB
4266
+ bodyMode === BODY_MODE.canvas
4267
+ ? (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal, inputActions })
4268
+ : (0, react_jsx_runtime.jsx)("div", { style: S.body, children: bodyMode === BODY_MODE.tree
4030
4269
  ? renderTree()
4031
- : (doc && doc.op === "local")
4270
+ : bodyMode === BODY_MODE.loading
4032
4271
  ? renderLoading()
4033
- : renderTree() })
4034
- : (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal }),
4272
+ : parseErrorView }),
4035
4273
  tabMenu ? (0, react_jsx_runtime.jsxs)("div", {
4036
4274
  style: { ...S.treeMenu, left: tabMenu.x, top: tabMenu.y },
4037
4275
  onContextMenu: (e) => e.preventDefault(),
@@ -4122,7 +4360,7 @@ window.__ModuleLoader__.load({
4122
4360
  : (doc && doc.op === "local")
4123
4361
  ? renderLoading()
4124
4362
  : renderTree() })
4125
- : (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal }),
4363
+ : (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal, inputActions }),
4126
4364
  tabMenu ? (0, react_jsx_runtime.jsxs)("div", {
4127
4365
  style: { ...S.treeMenu, left: tabMenu.x, top: tabMenu.y },
4128
4366
  onContextMenu: (e) => e.preventDefault(),
@@ -4891,6 +5129,8 @@ window.__ModuleLoader__.load({
4891
5129
  exports.inject = inject;
4892
5130
  exports.internals = Object.freeze({
4893
5131
  parseMarkdownToTree,
5132
+ // 038 解析兜底:永不抛的结果对 { tree, error }(供测试验证失败态分支)。
5133
+ parseTreeResult,
4894
5134
  reduceDocuments,
4895
5135
  mergeDocuments,
4896
5136
  autoOpenTarget,
@@ -4916,6 +5156,7 @@ window.__ModuleLoader__.load({
4916
5156
  // 025 草稿保护:宿主草稿读取面的能力探测(供测试)。
4917
5157
  readDraftText,
4918
5158
  draftBlocksAutoSend,
5159
+ submitNodeFocusMessage,
4919
5160
  // 025 子树折叠:视图态纯函数 + 节点行组件(供测试)。
4920
5161
  toggleCollapsed,
4921
5162
  countDescendants,
@@ -4934,7 +5175,17 @@ window.__ModuleLoader__.load({
4934
5175
  isTableSeparator,
4935
5176
  parseTableRow,
4936
5177
  nodeFullText,
5178
+ nodeTreeText,
5179
+ nodeFocusPrompt,
5180
+ EMPTY_NODE_MARKER,
5181
+ PATH_SEPARATOR,
5182
+ escapePathSegment,
5183
+ nodePathTo,
5184
+ nodePathLabel,
4937
5185
  renderInline,
5186
+ // 038 行内链接 token 拆解 + 脑图区主体模式判定(纯函数,供测试)。
5187
+ parseInlineLinkToken,
5188
+ mindmapBodyMode,
4938
5189
  // 链接点击:供测试验证开窗成功才拦默认行为(宿主拦截时退回原生导航)。
4939
5190
  openLink,
4940
5191
  stripInlineForExport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "description": "Mindmap plugin for DeepSeek Harness: a plain markdown file in the working directory IS the mindmap; the chat edits it step by step and the right-side panel follows live.",
5
5
  "repository": {
6
6
  "type": "git",