dsh-mindmap 0.18.6 → 0.18.9

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 (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/client.js +307 -93
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -38,6 +38,10 @@ All notable changes to this project are documented here. Release-specific notes
38
38
 
39
39
  ### Fixed
40
40
 
41
+ - PNG export now fits text to its card and stops breaking English words apart. The export lays out its own SVG instead of reusing one fixed box width: every node sizes itself to its content (clamped between 72px and 380px), so a short title such as 阶段三 no longer leaves a mostly empty card while a long work item is squeezed into three cramped lines. Text width is measured with the browser's real font metrics (`canvas.measureText`, using the same font stack as the drawing) rather than a per-character guess, so each line is laid out against the card's content width and keeps its inner padding instead of hugging the card edge; environments without a canvas keep the character estimate as a fallback. Line breaking is word-aware: `Apollo`, `RabbitMQ` and `CICD` stay in one piece, Chinese still breaks per character, explicit newlines are honoured, and overlong tokens (long URLs) are still hard-broken so no text is dropped or truncated. The break decision also counts the gap that precedes it, so a line never spills into the inner padding, and the original whitespace order is preserved — leading and trailing spaces stay where the author wrote them, even when a long token is hard-broken. Nodes on the same level keep a shared left edge, so the tree still reads as aligned columns, and the canvas size/pixel safety limits, full text, tables and multi-line content stay as they were. Both 导出图片 and the node context menu's 复制图片 share this export chain, so both are fixed together.
42
+
43
+ - Standalone panels now portal their fixed host to `document.body` instead of rendering inside the conversation header actions slot, preventing host header overflow from clipping the entire panel on DSH 0.2.2 (issue #5). Closing still keeps the workspace mounted with `display:none`; Better Sidebar tabs, layout-push behavior, resizing, and panel visuals remain unchanged.
44
+
41
45
  - Focus synchronization no longer oscillates between two open mindmaps (issue #4). The AI-focus baseline is now event-driven — the document last created, opened, or updated by a tool result (read-only `mindmap_get` never moves it) — instead of the creation-order tail, which stayed pinned to the newer file so the comparison could never converge. Auto-sent `mindmap_open` messages are gated three ways: at most one per document per mount, a module-level per-session memory of sent display/focus pairs that survives tab remounts and dual windows, and a hard cap of 5 automatic opens per session that stops silently with a single notice (shown in both directory and mindmap views). Restored mount state (an out-of-sync display/focus pair established by the mount-time auto-open) is no longer a trigger, so a remounted tab or a reloaded page never sends a spontaneous message, and cwd arrival after a remount only changes the message's relative-path text instead of re-arming the effect. The sync effect now depends on values (displayed document, AI focus, visibility, session) rather than snapshot object identity, so remounts and unrelated tool results no longer re-fire it. Regression tests cover the two-document idle scenario (at most one message, then convergence), remount memory survival, and the hard-cap silent stop with a one-time notice.
42
46
 
43
47
  - Extend the full-file-access compatibility fix to root renames, clearing content, and broad rewrites: when the host's live `sandboxPolicy.resolve({ session })` explicitly returns `danger-full-access`, these operations no longer request an extra plugin approval that the full-access preset would automatically reject. This supersedes the high-risk exception in the earlier ordinary-write fix below. Non-full-access policies still gate high-risk writes, and disabling approval prompts alone grants no file access. Upstream approval decisions, path containment, collision checks, size limits, revision conflicts, and session-grant isolation are preserved; guidance, settings help, and security documentation now describe the same boundary.
package/client.js CHANGED
@@ -2,11 +2,11 @@
2
2
  //
3
3
  // 职责:
4
4
  // - 「思维脑图」按钮:挂 conversation.session.header.actions(list 槽,追加式),
5
- // 点击切换右侧悬浮脑图面板的开/合;面板宿主层(fixed)与按钮同槽位渲染,
6
- // 会话能力(useSession/sessionId/inputActions)经 props 直给面板组件。
7
- // - 脑图面板:014 起注册在 shell.overlay(list 槽、root scope、点击穿透层),
8
- // 右缘贴边全高悬浮、左缘拖拽调宽(280~80% 视口,localStorage 持久化);
9
- // details 槽已归还官方(原生「工具详情」栏恢复,003 的顶替方案退役)。
5
+ // 点击切换右侧悬浮脑图面板的开/合;会话能力(useSession/sessionId/inputActions)
6
+ // 经 props 直给面板组件。
7
+ // - 独立脑图面板:通过 react-dom portal 挂到 document.body,避开头部祖先的
8
+ // overflow 裁剪;右缘贴边全高悬浮、左缘拖拽调宽(280~80% 视口,
9
+ // localStorage 持久化)。details 槽已归还官方(003 的顶替方案退役)。
10
10
  // - 实时数据通路:消费会话快照里 mindmap_* 工具的 ToolResultNode,重放出各文档
11
11
  // 的最新内容并渲染(002/003:无自定义事件通道,工具调用本身就是事件流)。
12
12
  // 023 双代:useChat → ChatSnapshot.legacy.nodes(dsh 0.1.2-rc.1+)优先,
@@ -25,6 +25,7 @@ window.__ModuleLoader__.load({
25
25
  var exports = module.exports;
26
26
  let react_jsx_runtime = require("react/jsx-runtime");
27
27
  let react = require("react");
28
+ let react_dom = require("react-dom");
28
29
 
29
30
  const inject = ["slots"];
30
31
 
@@ -1342,9 +1343,23 @@ window.__ModuleLoader__.load({
1342
1343
  // 布局契约不变——叶子自上而下占行、父节点垂直居中于其子块。
1343
1344
  // 导出拥有独立的 SVG 度量:13px 正文、12px 表格、18px 行高;不随画布
1344
1345
  // 的 NODE_FONT_SIZE 或 CSS zoom 改动,否则预估盒高与导出绘制会失配。
1346
+ // 039 导出版式修复(断词 / 贴边 / 疏密失衡):
1347
+ // - 度量:改用真实字体宽度(canvas measureText,与绘制同一字体串);
1348
+ // 无 canvas 的环境退回字符估算兜底。测量与绘制共用同一套宽度,
1349
+ // 文字不再贴边或溢出卡片。
1350
+ // - 折行:按词优先——英文/数字词不从中间拆开;超长词(长 URL)才逐字
1351
+ // 硬断,全量文字不缩减、不截断(003 §5.5 / §7 契约不变)。
1352
+ // - 盒宽:按内容自适应(min/max 钳制);同层左缘对齐、按层成列——
1353
+ // 短标题不再空一大块,长正文不再被挤成多行。
1345
1354
  const EXPORT = {
1346
- nodeW: 220, padX: 12, padY: 8, hGap: 48, vGap: 12, pad: 20,
1355
+ // 039 节点宽度按内容自适应:短标题收窄、长正文放宽。
1356
+ minNodeW: 72,
1357
+ maxNodeW: 380,
1358
+ padX: 12, padY: 8, hGap: 48, vGap: 12, pad: 20,
1347
1359
  fontSize: 13, lineHeight: 18,
1360
+ // 测量与绘制共用同一字体串:估宽与实际字形一致。
1361
+ fontFamily: "-apple-system, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif",
1362
+ monoFamily: "Menlo, Consolas, 'Courier New', monospace",
1348
1363
  tableCellW: 110, tableCellPad: 8, tableMinW: 140, tableMaxW: 480,
1349
1364
  // 单元格折行宽下限 = 导出字号 12px 的全角宽:极宽表(如 60 列)
1350
1365
  // 列盒窄于内距时 cellInner 可能为负,钳到至少容纳一个全角字符;
@@ -1377,29 +1392,178 @@ window.__ModuleLoader__.load({
1377
1392
  .replace(/\*([^*\n]+)\*/g, "$1");
1378
1393
  }
1379
1394
 
1380
- /** 字符宽度估算:CJK 按一个字号宽,其余按 0.55 折算。 */
1395
+ /** 导出字体串:测量(canvas)与绘制(SVG)共用,字宽与字形一致。 */
1396
+ function exportFontSpec(fontSize, weight, mono) {
1397
+ return `${weight} ${fontSize}px ${mono ? EXPORT.monoFamily : EXPORT.fontFamily}`;
1398
+ }
1399
+
1400
+ let exportMeasureCtx;
1401
+ let exportMeasureReady = false;
1402
+
1403
+ /** 惰性取 canvas 2d 上下文:有则用真实字形度量,没有则走字符估算兜底。 */
1404
+ function exportMeasureContext() {
1405
+ if (!exportMeasureReady) {
1406
+ exportMeasureReady = true;
1407
+ try {
1408
+ if (typeof document !== "undefined" && document && typeof document.createElement === "function") {
1409
+ const canvas = document.createElement("canvas");
1410
+ const ctx = canvas && typeof canvas.getContext === "function" ? canvas.getContext("2d") : null;
1411
+ if (ctx && typeof ctx.measureText === "function") exportMeasureCtx = ctx;
1412
+ }
1413
+ } catch (error) {
1414
+ // 度量不可用不是致命错误:退回字符估算,导出照常出图。
1415
+ }
1416
+ }
1417
+ return exportMeasureCtx;
1418
+ }
1419
+
1420
+ /** 字符宽度估算(无 canvas 时的兜底):CJK 按一个字号宽,其余按 0.55 折算。 */
1381
1421
  function charW(ch, fontSize) {
1382
1422
  return ch.charCodeAt(0) > 0x2e7f ? fontSize : fontSize * 0.55;
1383
1423
  }
1384
1424
 
1385
- /** 按可用宽度贪心折行(尊重显式换行;长串硬折——长 URL 完整呈现不截断)。 */
1386
- function wrapExportText(text, maxWidth, fontSize) {
1425
+ function estimateExportText(text, fontSize, mono) {
1426
+ const s = String(text ?? "");
1427
+ if (mono) return [...s].length * fontSize * 0.6;
1428
+ let w = 0;
1429
+ for (const ch of s) w += charW(ch, fontSize);
1430
+ return w;
1431
+ }
1432
+
1433
+ /** 文字宽度:浏览器走真实字形,其余走估算兜底。 */
1434
+ function measureExportText(text, fontSize, weight = 400, mono = false) {
1435
+ const ctx = exportMeasureContext();
1436
+ if (ctx) {
1437
+ try {
1438
+ ctx.font = exportFontSpec(fontSize, weight, mono);
1439
+ return ctx.measureText(String(text ?? "")).width;
1440
+ } catch (error) {
1441
+ // 落回字符估算。
1442
+ }
1443
+ }
1444
+ return estimateExportText(text, fontSize, mono);
1445
+ }
1446
+
1447
+ const EXPORT_WORD_CHAR = /[0-9A-Za-z]/;
1448
+ const EXPORT_WORD_JOIN = /[-_.+/#@&']/;
1449
+
1450
+ /**
1451
+ * 039 折行原子:CJK 逐字可断;拉丁/数字词整体不可断(不从中间拆词);
1452
+ * 空白单独成块(行尾空白保留在行末,渲染时被折叠、字符不丢)。
1453
+ */
1454
+ function exportAtoms(segment) {
1455
+ const chars = [...String(segment ?? "")];
1456
+ const atoms = [];
1457
+ let i = 0;
1458
+ while (i < chars.length) {
1459
+ const ch = chars[i];
1460
+ if (ch === " " || ch === "\t") {
1461
+ atoms.push({ text: ch, space: true });
1462
+ i += 1;
1463
+ continue;
1464
+ }
1465
+ if (ch.charCodeAt(0) > 0x2e7f) {
1466
+ atoms.push({ text: ch, space: false });
1467
+ i += 1;
1468
+ continue;
1469
+ }
1470
+ if (EXPORT_WORD_CHAR.test(ch)) {
1471
+ let j = i + 1;
1472
+ while (j < chars.length) {
1473
+ const c = chars[j];
1474
+ if (EXPORT_WORD_CHAR.test(c)) { j += 1; continue; }
1475
+ // 词内连接符(- _ . / # + @ & ')跟随后面的词字符一起算一个词。
1476
+ if (EXPORT_WORD_JOIN.test(c) && j + 1 < chars.length && EXPORT_WORD_CHAR.test(chars[j + 1])) { j += 1; continue; }
1477
+ break;
1478
+ }
1479
+ atoms.push({ text: chars.slice(i, j).join(""), space: false });
1480
+ i = j;
1481
+ continue;
1482
+ }
1483
+ atoms.push({ text: ch, space: false });
1484
+ i += 1;
1485
+ }
1486
+ return atoms;
1487
+ }
1488
+
1489
+ /**
1490
+ * 按可用宽度折行(尊重显式换行;优先按词断行,英文词不从中间拆开;
1491
+ * 超长词/长 URL 才逐字硬断——长串完整呈现不截断)。
1492
+ *
1493
+ * 空白契约(039 复查修正):
1494
+ * - 原文顺序不变:行首空白留在行首、行尾空白留在行末,中间空白留在词间;
1495
+ * 逐行拼回恒等于原文(字符一个不丢、不搬家)。
1496
+ * - 断行决策必须把「即将插入的空白」算进去:词本身放得下、连同词间空白
1497
+ * 放不下时照样要断,否则这一行会顶破内容区、吃掉右内距。
1498
+ * - 宽度口径与渲染一致:行首空白渲染时被裁掉、不占宽度;词间空白在行内
1499
+ * 可见,按实宽计入(保守,宁可早断不越界)。
1500
+ */
1501
+ function wrapExportText(text, maxWidth, fontSize, options = {}) {
1502
+ const weight = options.weight || 400;
1503
+ const mono = options.mono === true;
1504
+ const measure = (value) => measureExportText(value, fontSize, weight, mono);
1387
1505
  const lines = [];
1388
1506
  for (const segment of String(text ?? "").split("\n")) {
1389
- let cur = "";
1390
- let w = 0;
1391
- for (const ch of segment) {
1392
- const cw = charW(ch, fontSize);
1393
- if (w + cw > maxWidth && cur) {
1394
- lines.push(cur);
1395
- cur = ch;
1396
- w = cw;
1397
- } else {
1398
- cur += ch;
1399
- w += cw;
1507
+ const atoms = exportAtoms(segment);
1508
+ let cur = ""; // 本行已定稿的文字(不含行首空白)
1509
+ let curW = 0; // 本行宽度(不含行首空白)
1510
+ let lead = ""; // 行首空白:渲染时被裁掉,不占宽度
1511
+ let pending = ""; // 词间空白:尚未插入下一个词
1512
+ let pendingW = 0;
1513
+ const flush = () => {
1514
+ lines.push(lead + cur + pending);
1515
+ cur = "";
1516
+ curW = 0;
1517
+ lead = "";
1518
+ pending = "";
1519
+ pendingW = 0;
1520
+ };
1521
+ for (const atom of atoms) {
1522
+ if (atom.space) {
1523
+ if (cur) {
1524
+ pending += atom.text;
1525
+ pendingW += measure(atom.text);
1526
+ } else {
1527
+ lead += atom.text;
1528
+ }
1529
+ continue;
1400
1530
  }
1531
+ const aw = measure(atom.text);
1532
+ // 断行决策要算上即将插入的词间空白。
1533
+ if (cur && curW + pendingW + aw > maxWidth) flush();
1534
+ if (!cur && aw > maxWidth) {
1535
+ // 超长词(长 URL 等):逐字硬断,字符一个不丢。
1536
+ // 先于该词的空白属于第一片(保持原文顺序)。
1537
+ const pieces = [];
1538
+ let piece = "";
1539
+ let pieceW = 0;
1540
+ for (const ch of atom.text) {
1541
+ const cw = measure(ch);
1542
+ if (pieceW > 0 && pieceW + cw > maxWidth) {
1543
+ pieces.push(piece);
1544
+ piece = "";
1545
+ pieceW = 0;
1546
+ }
1547
+ piece += ch;
1548
+ pieceW += cw;
1549
+ }
1550
+ if (piece) pieces.push(piece);
1551
+ for (let i = 0; i < pieces.length - 1; i += 1) {
1552
+ lines.push(i === 0 ? lead + pieces[0] : pieces[i]);
1553
+ }
1554
+ cur = pieces.length ? pieces[pieces.length - 1] : "";
1555
+ curW = measure(cur);
1556
+ lead = "";
1557
+ pending = "";
1558
+ pendingW = 0;
1559
+ continue;
1560
+ }
1561
+ cur += pending + atom.text;
1562
+ curW += pendingW + aw;
1563
+ pending = "";
1564
+ pendingW = 0;
1401
1565
  }
1402
- lines.push(cur);
1566
+ lines.push(lead + cur + pending);
1403
1567
  }
1404
1568
  return lines.length > 0 ? lines : [""];
1405
1569
  }
@@ -1416,120 +1580,167 @@ window.__ModuleLoader__.load({
1416
1580
  return { text: stripInlineForExport(node.topic), lines: null };
1417
1581
  }
1418
1582
 
1419
- /** 019 盒尺寸估算:文本按折行行数生长;表格按行列数算网格尺寸。
1583
+ /** 039 导出字形样式:字重/等宽与绘制一致,测量必须按同一套样式算宽度。 */
1584
+ function exportTextStyle(node, isRoot) {
1585
+ return {
1586
+ weight: isRoot ? 700 : node.kind === "heading" ? 600 : 400,
1587
+ mono: node.kind === "code",
1588
+ };
1589
+ }
1590
+
1591
+ /**
1592
+ * 019/039 盒尺寸:宽度按内容自适应(短标题收窄、长正文放宽),
1593
+ * 文本按该宽度折行后定高。
1420
1594
  * 022:测量与渲染必须共用钳制后的列宽——先算盒宽再按 w/cols 折行,
1421
- * 否则宽表(钳到 tableMaxW)按 110px 估行、渲染按更窄列宽折行,盒高不足。 */
1422
- function measureExportBox(node) {
1595
+ * 否则宽表(钳到 tableMaxW)按 110px 估行、渲染按更窄列宽折行,盒高不足。
1596
+ */
1597
+ function exportBoxSize(node, options = {}) {
1598
+ const style = exportTextStyle(node, options.root === true);
1423
1599
  if (node.kind === "table") {
1424
1600
  const rows = (node.data && node.data.rows) || [];
1425
1601
  const cols = rows.reduce((mx, row) => Math.max(mx, row.length), 0) || 1;
1426
1602
  const w = Math.min(EXPORT.tableMaxW, Math.max(EXPORT.tableMinW, cols * EXPORT.tableCellW));
1427
1603
  const cellInner = Math.max(w / cols - EXPORT.tableCellPad * 2, EXPORT.tableCellMinInner);
1428
- const rowLines = rows.map((row) => row.reduce((mx, cell) => Math.max(mx, wrapExportText(stripInlineForExport(cell), cellInner, EXPORT.fontSize - 1).length), 1));
1429
- const h = Math.max(EXPORT.lineHeight, rowLines.reduce((a, b) => a + b, 0) * EXPORT.lineHeight);
1430
- return { w, h };
1604
+ const cellLines = rows.map((row, ri) => row.map((cell) => wrapExportText(stripInlineForExport(cell), cellInner, EXPORT.fontSize - 1, { weight: ri === 0 ? 600 : 400 })));
1605
+ const rowH = cellLines.map((cells) => Math.max(1, ...cells.map((lines) => lines.length)) * EXPORT.lineHeight);
1606
+ const h = Math.max(EXPORT.lineHeight, rowH.reduce((a, b) => a + b, 0));
1607
+ return { w, h, style, table: { rows, cols, cellInner, cellLines, rowH } };
1431
1608
  }
1432
- const text = exportBlock(node).text;
1433
- const inner = EXPORT.nodeW - EXPORT.padX * 2;
1434
- const lines = node.kind === "code" ? [text] : wrapExportText(text, inner, EXPORT.fontSize);
1435
- return { w: EXPORT.nodeW, h: EXPORT.padY * 2 + lines.length * EXPORT.lineHeight };
1609
+ const label = node.kind === "placeholder" ? "待填写" : exportBlock(node).text;
1610
+ const widest = Math.max(0, ...String(label).split("\n").map((line) => measureExportText(line, EXPORT.fontSize, style.weight, style.mono)));
1611
+ // 左右内距 + 引用块的竖条;+2 是测量与光栅化的安全余量。
1612
+ const chrome = EXPORT.padX * 2 + (node.kind === "quote" ? 3 : 0);
1613
+ const w = Math.min(EXPORT.maxNodeW, Math.max(EXPORT.minNodeW, Math.ceil(widest) + chrome + 2));
1614
+ const inner = w - chrome;
1615
+ const lines = wrapExportText(label, inner, EXPORT.fontSize, { weight: style.weight, mono: style.mono });
1616
+ return { w, h: EXPORT.padY * 2 + lines.length * EXPORT.lineHeight, style, lines };
1617
+ }
1618
+
1619
+ /** 019 盒尺寸估算(对外只暴露尺寸,测量与渲染同源)。 */
1620
+ function measureExportBox(node, options = {}) {
1621
+ const size = exportBoxSize(node, options);
1622
+ return { w: size.w, h: size.h };
1623
+ }
1624
+
1625
+ /** 导出节点条目:一次算好样式、盒尺寸与子树,后续布局/绘制共用。 */
1626
+ function exportEntryOf(node, depth, parent) {
1627
+ const size = exportBoxSize(node, { root: depth === 0 });
1628
+ const entry = {
1629
+ node,
1630
+ depth,
1631
+ parent,
1632
+ style: size.style,
1633
+ table: size.table,
1634
+ lines: size.lines,
1635
+ text: node.kind === "placeholder" ? "待填写" : exportBlock(node).text,
1636
+ w: size.w,
1637
+ h: size.h,
1638
+ children: [],
1639
+ };
1640
+ entry.children = (node.children || []).map((child) => exportEntryOf(child, depth + 1, entry));
1641
+ return entry;
1436
1642
  }
1437
1643
 
1438
1644
  /**
1439
- * 布局 + 生成导出用 SVG 字符串。左→右分层:x = 父盒右缘 + 间距(可变盒宽),
1440
- * 叶子自上而下占行,父节点垂直居中于其子块;连线为水平贝塞尔。
1645
+ * 布局 + 生成导出用 SVG 字符串。左→右分层:同层节点左缘对齐成列
1646
+ * (列位由层号决定,盒宽仍按内容自适应),叶子自上而下占行,
1647
+ * 父节点垂直居中于其子块;连线为水平贝塞尔。
1441
1648
  * 019:盒高随内容生长(表格/引用画专属形态);色值取主题静态亮色快照
1442
1649
  *(导出 SVG 走 data-URL,宿主 CSS 变量不可用)。
1443
1650
  */
1444
1651
  function buildExportSvg(tree, themeName) {
1445
1652
  const palette = exportPalette(themeName);
1446
- const placed = [];
1447
- const edges = [];
1448
- let cursor = EXPORT.pad;
1449
- const place = (node, parentEntry) => {
1450
- const size = measureExportBox(node);
1451
- const entry = {
1452
- node,
1453
- size,
1454
- x: parentEntry ? parentEntry.x + parentEntry.size.w + EXPORT.hGap : EXPORT.pad,
1455
- y: 0,
1456
- };
1457
- placed.push(entry);
1458
- if (parentEntry) edges.push({ from: parentEntry, to: entry });
1459
- if (node.children && node.children.length > 0) {
1460
- let first = null;
1461
- let last = null;
1462
- for (const child of node.children) {
1463
- const childEntry = place(child, entry);
1464
- if (!first) first = childEntry;
1465
- last = childEntry;
1466
- }
1467
- entry.y = (first.y + last.y) / 2;
1468
- } else {
1469
- entry.y = cursor + size.h / 2;
1470
- cursor += size.h + EXPORT.vGap;
1653
+ const entries = [];
1654
+ const root = exportEntryOf(tree, 0, null);
1655
+ const collect = (entry) => {
1656
+ entries.push(entry);
1657
+ for (const child of entry.children) collect(child);
1658
+ };
1659
+ collect(root);
1660
+ // 列宽:同层取最宽者;列位由层号决定——各层左缘对齐,盒宽可各不相同。
1661
+ const colW = [];
1662
+ for (const entry of entries) colW[entry.depth] = Math.max(colW[entry.depth] || 0, entry.w);
1663
+ const colX = [];
1664
+ let cursorX = EXPORT.pad;
1665
+ for (let depth = 0; depth < colW.length; depth += 1) {
1666
+ colX[depth] = cursorX;
1667
+ cursorX += colW[depth] + EXPORT.hGap;
1668
+ }
1669
+ // 高度:自底向上算块高(子块叠放 + 间距);父盒比子块高时以父盒为准。
1670
+ const computeBlock = (entry) => {
1671
+ let stack = 0;
1672
+ for (const child of entry.children) stack += computeBlock(child);
1673
+ if (entry.children.length) stack += EXPORT.vGap * (entry.children.length - 1);
1674
+ entry.stackH = stack;
1675
+ entry.blockH = Math.max(stack, entry.h);
1676
+ return entry.blockH;
1677
+ };
1678
+ computeBlock(root);
1679
+ // 放置:自顶向下分块顶,节点竖直居中于自己的块。
1680
+ const place = (entry, blockTop) => {
1681
+ entry.x = colX[entry.depth];
1682
+ entry.y = blockTop + entry.blockH / 2;
1683
+ if (!entry.children.length) return;
1684
+ const offset = (entry.blockH - entry.stackH) / 2;
1685
+ let top = blockTop + offset;
1686
+ for (const child of entry.children) {
1687
+ place(child, top);
1688
+ top += child.blockH + EXPORT.vGap;
1471
1689
  }
1472
- return entry;
1473
1690
  };
1474
- place(tree, null);
1475
- const width = placed.reduce((mx, p) => Math.max(mx, p.x + p.size.w), 0) + EXPORT.pad;
1476
- const height = Math.max(EXPORT.pad * 2 + EXPORT.lineHeight, cursor - EXPORT.vGap + EXPORT.pad);
1691
+ place(root, EXPORT.pad);
1692
+ const width = colX[colX.length - 1] + colW[colW.length - 1] + EXPORT.pad;
1693
+ const height = root.blockH + EXPORT.pad * 2;
1477
1694
  const parts = [];
1478
- parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" font-family="-apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif">`);
1695
+ parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" font-family="${EXPORT.fontFamily}">`);
1479
1696
  parts.push(`<rect x="0" y="0" width="${width}" height="${height}" fill="${palette.canvasBg}"/>`);
1480
- for (const e of edges) {
1481
- const x1 = e.from.x + e.from.size.w;
1482
- const y1 = e.from.y;
1483
- const x2 = e.to.x;
1484
- const y2 = e.to.y;
1697
+ for (const entry of entries) {
1698
+ if (!entry.parent) continue;
1699
+ const x1 = entry.parent.x + entry.parent.w;
1700
+ const y1 = entry.parent.y;
1701
+ const x2 = entry.x;
1702
+ const y2 = entry.y;
1485
1703
  const mid = (x1 + x2) / 2;
1486
1704
  parts.push(`<path d="M ${x1} ${y1} C ${mid} ${y1}, ${mid} ${y2}, ${x2} ${y2}" fill="none" stroke="${palette.connector}" stroke-width="1.5"/>`);
1487
1705
  }
1488
- for (const p of placed) {
1489
- const node = p.node;
1706
+ for (const entry of entries) {
1707
+ const node = entry.node;
1490
1708
  const kind = node.kind;
1491
- const isRoot = !edges.some((e) => e.to === p);
1709
+ const isRoot = entry.depth === 0;
1492
1710
  const isPlaceholder = kind === "placeholder";
1493
1711
  const isCode = kind === "code";
1494
1712
  const isQuote = kind === "quote";
1495
1713
  const isTable = kind === "table";
1496
- const boxY = p.y - p.size.h / 2;
1714
+ const boxY = entry.y - entry.h / 2;
1497
1715
  const fill = isRoot ? palette.rootBg : isCode ? palette.surfaceCode : palette.surface;
1498
- parts.push(`<rect x="${p.x}" y="${boxY}" width="${p.size.w}" height="${p.size.h}" rx="7" fill="${isPlaceholder ? "none" : fill}" stroke="${isRoot ? palette.rootBorder : isPlaceholder ? palette.border : palette.border}" stroke-width="${isRoot ? 1.6 : 1}"${isPlaceholder ? ' stroke-dasharray="5,4"' : ""}/>`);
1716
+ parts.push(`<rect x="${entry.x}" y="${boxY}" width="${entry.w}" height="${entry.h}" rx="7" fill="${isPlaceholder ? "none" : fill}" stroke="${isRoot ? palette.rootBorder : palette.border}" stroke-width="${isRoot ? 1.6 : 1}"${isPlaceholder ? ' stroke-dasharray="5,4"' : ""}/>`);
1499
1717
  if (isQuote) {
1500
- parts.push(`<rect x="${p.x}" y="${boxY}" width="3" height="${p.size.h}" fill="${palette.quote}"/>`);
1718
+ parts.push(`<rect x="${entry.x}" y="${boxY}" width="3" height="${entry.h}" fill="${palette.quote}"/>`);
1501
1719
  }
1502
1720
  if (isTable) {
1503
1721
  // 表格块:完整网格(全量行列、单元格换行、不缩减,003 §5.5)。
1504
- const rows = (node.data && node.data.rows) || [];
1505
- const cols = rows.reduce((mx, row) => Math.max(mx, row.length), 0) || 1;
1506
- const colW = p.size.w / cols;
1507
- const innerW = Math.max(colW - EXPORT.tableCellPad * 2, EXPORT.tableCellMinInner);
1508
- const rowLines = rows.map((row) => row.reduce((mx, cell) => Math.max(mx, wrapExportText(stripInlineForExport(cell), innerW, EXPORT.fontSize - 1).length), 1));
1509
- const rowH = rowLines.map((n) => n * EXPORT.lineHeight);
1722
+ const table = entry.table;
1723
+ const cellBoxW = entry.w / table.cols;
1510
1724
  let ry = boxY;
1511
- rows.forEach((row, ri) => {
1725
+ table.rows.forEach((row, ri) => {
1512
1726
  row.forEach((cell, ci) => {
1513
- const cx = p.x + ci * colW;
1514
- parts.push(`<rect x="${cx}" y="${ry}" width="${colW}" height="${rowH[ri]}" fill="${ri === 0 ? palette.surfaceCode : "none"}" stroke="${palette.borderSubtle}" stroke-width="1"/>`);
1515
- const cellLines = wrapExportText(stripInlineForExport(cell), innerW, EXPORT.fontSize - 1);
1516
- cellLines.forEach((ln, li) => {
1727
+ const cx = entry.x + ci * cellBoxW;
1728
+ parts.push(`<rect x="${cx}" y="${ry}" width="${cellBoxW}" height="${table.rowH[ri]}" fill="${ri === 0 ? palette.surfaceCode : "none"}" stroke="${palette.borderSubtle}" stroke-width="1"/>`);
1729
+ table.cellLines[ri][ci].forEach((ln, li) => {
1517
1730
  const ty = ry + (li + 0.5) * EXPORT.lineHeight + (EXPORT.fontSize - 1) * 0.35;
1518
1731
  parts.push(`<text x="${cx + EXPORT.tableCellPad}" y="${ty.toFixed(1)}" font-size="${EXPORT.fontSize - 1}" font-weight="${ri === 0 ? 600 : 400}" fill="${palette.text}">${escapeXml(ln)}</text>`);
1519
1732
  });
1520
1733
  });
1521
- ry += rowH[ri];
1734
+ ry += table.rowH[ri];
1522
1735
  });
1523
1736
  continue;
1524
1737
  }
1525
- const label = isPlaceholder ? "待填写" : exportBlock(node).text;
1526
1738
  const color = isPlaceholder ? palette.muted : isRoot ? palette.rootText : kind === "heading" ? palette.heading : palette.text;
1527
- const weight = isRoot ? 700 : kind === "heading" ? 600 : 400;
1528
- const inner = p.size.w - EXPORT.padX * 2 - (isQuote ? 3 : 0);
1529
- const lines = isCode ? [label] : wrapExportText(label, inner, EXPORT.fontSize);
1530
- const startY = p.y - (lines.length - 1) * EXPORT.lineHeight / 2 + EXPORT.fontSize * 0.35;
1739
+ const lines = entry.lines;
1740
+ const textX = entry.x + EXPORT.padX + (isQuote ? 3 : 0);
1741
+ const startY = entry.y - (lines.length - 1) * EXPORT.lineHeight / 2 + EXPORT.fontSize * 0.35;
1531
1742
  lines.forEach((ln, li) => {
1532
- parts.push(`<text x="${p.x + EXPORT.padX + (isQuote ? 3 : 0)}" y="${(startY + li * EXPORT.lineHeight).toFixed(1)}" font-size="${EXPORT.fontSize}" font-weight="${weight}" font-family="${isCode ? "Menlo, monospace" : "inherit"}" fill="${color}">${escapeXml(ln)}</text>`);
1743
+ parts.push(`<text x="${textX}" y="${(startY + li * EXPORT.lineHeight).toFixed(1)}" font-size="${EXPORT.fontSize}" font-weight="${entry.style.weight}" font-family="${isCode ? EXPORT.monoFamily : EXPORT.fontFamily}" fill="${color}">${escapeXml(ln)}</text>`);
1533
1744
  });
1534
1745
  }
1535
1746
  parts.push("</svg>");
@@ -4613,6 +4824,7 @@ window.__ModuleLoader__.load({
4613
4824
 
4614
4825
  /**
4615
4826
  * 独立 fixed 壳(026 拆分):仅 Better Sidebar 未安装或服务不可用时使用。
4827
+ * 通过 portal 挂到 document.body,避免被头部槽位祖先的 overflow 裁剪。
4616
4828
  * 管理壳特有几何——右缘贴边悬浮、左缘拖拽调宽(localStorage 持久化)、
4617
4829
  * 头部高度对齐聊天区、layout-push CSS 变量(--dsh-mindmap-width)。
4618
4830
  * 壳内始终挂载 MindmapWorkspace(visible=open):收起时 display:none 隐藏,
@@ -4776,10 +4988,11 @@ window.__ModuleLoader__.load({
4776
4988
  headerHeight,
4777
4989
  variant: "standalone",
4778
4990
  });
4779
- return (0, react_jsx_runtime.jsx)("div", { style: open ? S.panelHost : { display: "none" }, children: (0, react_jsx_runtime.jsxs)("div", { ref: panelRootRef, style: open ? { ...S.overlayRoot, width: panelWidth } : { display: "none" }, children: [
4991
+ const host = (0, react_jsx_runtime.jsx)("div", { style: open ? S.panelHost : { display: "none" }, children: (0, react_jsx_runtime.jsxs)("div", { ref: panelRootRef, style: open ? { ...S.overlayRoot, width: panelWidth } : { display: "none" }, children: [
4780
4992
  open ? (0, react_jsx_runtime.jsx)("div", { style: S.overlayHandle, onMouseDown: startResize }) : null,
4781
4993
  workspace,
4782
4994
  ] }) });
4995
+ return react_dom.createPortal(host, document.body);
4783
4996
  }
4784
4997
 
4785
4998
  /**
@@ -5534,6 +5747,7 @@ window.__ModuleLoader__.load({
5534
5747
  MindmapSidebarTab,
5535
5748
  // 027 内嵌头部视觉对齐:壳无关工作区组件 + 样式表(供测试验证 variant 分支)。
5536
5749
  MindmapWorkspace,
5750
+ MindmapDetailsPanel,
5537
5751
  S,
5538
5752
  // 029 会话清理组件测试:MindmapSlot 直接调用(供测试验证 store 清理)。
5539
5753
  MindmapSlot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.18.6",
3
+ "version": "0.18.9",
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",