dsh-mindmap 0.11.0 → 0.13.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.
package/client.js CHANGED
@@ -62,6 +62,9 @@ window.__ModuleLoader__.load({
62
62
  "color.accent.code": { default: "#3b5bdb", fallback: "color.accent.root" },
63
63
  "color.accent.quote": { default: "#5c7cfa", fallback: "color.accent.heading.medium" },
64
64
  "color.state.selected": { default: "var(--dsw-alias-state-business-primary)" },
65
+ // 035 搜索命中:普通命中用品牌色浅色调(tertiary)描边,活动命中共用
66
+ // 选中环主色(primary)——同色系靠层数/宽度分强度,主题换肤自动跟随。
67
+ "color.state.match": { default: "var(--dsw-alias-state-business-tertiary)" },
65
68
  "color.state.hovered": { default: "var(--dsw-alias-interactive-bg-hover)" },
66
69
  "connector.color": { default: "var(--dsw-alias-border-l2)", fallback: "color.border.default" },
67
70
  "connector.width": { default: 1.5 },
@@ -184,6 +187,19 @@ window.__ModuleLoader__.load({
184
187
  if (states.hovered && kind !== "placeholder") {
185
188
  style.boxShadow = resolveToken("effect.shadow.hovered", overrides);
186
189
  }
190
+ // 035 搜索命中态:普通命中 = 浅色调 2px 描边环;活动命中 = 主色描边 +
191
+ // 3px 外扩阴影(双层强调)。outline 不占布局,相邻盒间隙(8px)内放得下。
192
+ // 置于 selected 之前——选中环仍是最高优先级,两者并存时各自可见。
193
+ if (states.matched && !states.matchActive) {
194
+ style.outline = `2px solid ${resolveToken("color.state.match", overrides)}`;
195
+ style.outlineOffset = 1;
196
+ }
197
+ if (states.matchActive) {
198
+ const ring = resolveToken("color.state.selected", overrides);
199
+ style.outline = `2px solid ${ring}`;
200
+ style.outlineOffset = 2;
201
+ style.boxShadow = `0 0 0 3px ${ring}${style.boxShadow && style.boxShadow !== "none" ? `, ${style.boxShadow}` : ""}`;
202
+ }
187
203
  if (states.selected) {
188
204
  const ring = resolveToken("color.state.selected", overrides);
189
205
  style.boxShadow = `0 0 0 2px ${ring}${style.boxShadow && style.boxShadow !== "none" ? `, ${style.boxShadow}` : ""}`;
@@ -1027,6 +1043,79 @@ window.__ModuleLoader__.load({
1027
1043
  }
1028
1044
  //#endregion
1029
1045
 
1046
+ //#region 035 节点搜索:命中计算 / 下标步进 / 命中保持 / 祖先展开(纯函数,经 internals 供测试)
1047
+ /**
1048
+ * 在当前树里搜节点可见文字(topic):大小写不敏感子串匹配,先序遍历
1049
+ * 返回命中节点 id 列表(含根)。空/纯空白查询返回空数组。不搜整个
1050
+ * workspace、不做正则/模糊——第一版只要简单可靠。
1051
+ */
1052
+ function searchTreeMatches(tree, query) {
1053
+ const q = String(query ?? "").trim().toLowerCase();
1054
+ if (!q) return [];
1055
+ const out = [];
1056
+ const walk = (node) => {
1057
+ if (!node) return;
1058
+ if (String(node.topic ?? "").toLowerCase().includes(q)) out.push(node.id);
1059
+ for (const child of node.children ?? []) walk(child);
1060
+ };
1061
+ walk(tree);
1062
+ return out;
1063
+ }
1064
+
1065
+ /**
1066
+ * 下标步进(delta = +1 下一个 / −1 上一个),双向环绕(末尾→开头、
1067
+ * 开头→末尾)。当前下标越界(AI 改写后命中列表已变)先归零再步进;
1068
+ * 无命中返回 −1。
1069
+ */
1070
+ function stepMatchIndex(index, count, delta) {
1071
+ if (!(count > 0)) return -1;
1072
+ const base = Number.isInteger(index) && index >= 0 && index < count ? index : 0;
1073
+ const step = delta >= 0 ? 1 : -1;
1074
+ return (base + step + count) % count;
1075
+ }
1076
+
1077
+ /**
1078
+ * 命中列表重算后的当前项保持(AI 更改 mindmap 后):优先按稳定结构 id
1079
+ * 找回原命中节点;找不到则钳制到最近的有效下标;再不行回落第一个。
1080
+ * 无命中返回 −1。返回值是 matches 里的下标。
1081
+ */
1082
+ function reconcileActiveMatch(prevId, prevIndex, matches) {
1083
+ if (!Array.isArray(matches) || matches.length === 0) return -1;
1084
+ if (prevId != null) {
1085
+ const idx = matches.indexOf(prevId);
1086
+ if (idx >= 0) return idx;
1087
+ }
1088
+ if (Number.isInteger(prevIndex) && prevIndex >= 0 && prevIndex < matches.length) return prevIndex;
1089
+ return 0;
1090
+ }
1091
+
1092
+ /**
1093
+ * 定位命中前展开其祖先路径:把「根 → 目标」链上的折叠 id 全部移出
1094
+ *(不含目标自身——自身折叠只藏子树,盒子仍可见),无关折叠保留。
1095
+ * 无需变化 / 目标不存在时原样返回入参集合(引用不变,React 免重渲染)。
1096
+ */
1097
+ function expandAncestorsFor(collapsed, tree, nodeId) {
1098
+ if (!collapsed || collapsed.size === 0 || !tree || nodeId == null) return collapsed;
1099
+ const ancestors = [];
1100
+ const walk = (node, chain) => {
1101
+ if (!node) return false;
1102
+ if (node.id === nodeId) {
1103
+ for (const id of chain) ancestors.push(id);
1104
+ return true;
1105
+ }
1106
+ for (const child of node.children ?? []) {
1107
+ if (walk(child, chain.concat(node.id))) return true;
1108
+ }
1109
+ return false;
1110
+ };
1111
+ walk(tree, []);
1112
+ if (!ancestors.some((id) => collapsed.has(id))) return collapsed;
1113
+ const next = new Set(collapsed);
1114
+ for (const id of ancestors) next.delete(id);
1115
+ return next;
1116
+ }
1117
+ //#endregion
1118
+
1030
1119
  //#region PNG 导出(SVG 序列化 → canvas → 下载 / 剪贴板)
1031
1120
  // 019 可变盒高布局:盒高按内容估行数(全量换行的导出形态),表格节点加宽;
1032
1121
  // 布局契约不变——叶子自上而下占行、父节点垂直居中于其子块。
@@ -1426,7 +1515,10 @@ window.__ModuleLoader__.load({
1426
1515
  canvasWrap: { flex: "1 1 auto", minHeight: 0, minWidth: 0, position: "relative", display: "flex", flexDirection: "column" },
1427
1516
  // 021 平移:空白处抓手光标(节点盒自带 pointer 覆盖);overscroll
1428
1517
  // contain 让画布滚到边时不把滚动链传给宿主页面(聊天区不跟着动)。
1429
- canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain" },
1518
+ // 033 scrollbar-gutter 常驻滚动条槽位:滚动条出现/消失不再改变
1519
+ // clientWidth——从源头掐掉「适配→滚动条出现→视口变窄→再适配」的
1520
+ // 抖动循环(老保险丝降级为兜底;不支持该属性的宿主优雅退化)。
1521
+ canvasScroll: { flex: "1 1 auto", minHeight: 0, minWidth: 0, overflow: "auto", cursor: "grab", overscrollBehavior: "contain", scrollbarGutter: "stable" },
1430
1522
  // 居中层:内容小则铺满视口(100%),大则撑到内容尺寸(max-content);
1431
1523
  // 子项用 margin:auto——空间充足双向居中,溢出时 margin 归零、从滚动
1432
1524
  // 原点排布(flexbox 溢出居中裁剪的标准解法,无左/上侧裁剪)。
@@ -1439,10 +1531,15 @@ window.__ModuleLoader__.load({
1439
1531
  // 百分比标签:tabular-nums 防数字抖动。
1440
1532
  zoomLabel: { flex: "none", minWidth: "38px", textAlign: "center", fontSize: "11px", lineHeight: "20px", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums", userSelect: "none" },
1441
1533
  zoomFitBtn: { border: "none", background: "none", cursor: "pointer", font: "inherit", fontSize: "12px", lineHeight: "20px", height: "22px", padding: "0 8px", borderRadius: "6px", color: "var(--dsw-alias-label-secondary)", flex: "none" },
1534
+ // 035 节点搜索:缩放条同款浮层容器,挂在缩放条正下方(顶 44px),
1535
+ // 全部复用宿主主题变量,亮暗/换肤自动跟随。
1536
+ searchBar: { position: "absolute", top: "44px", right: "12px", zIndex: 5, display: "inline-flex", alignItems: "center", gap: "2px", padding: "3px", borderRadius: "8px", background: "var(--dsw-alias-bg-layer-3)", border: "1px solid var(--dsw-alias-border-l2)", boxShadow: "var(--dsw-shadow-l2)" },
1537
+ searchInput: { flex: "none", width: "108px", height: "22px", boxSizing: "border-box", padding: "0 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-base)", color: "var(--dsw-alias-label-primary)", font: "inherit", fontSize: "12px", outline: "none" },
1538
+ searchCount: { flex: "none", minWidth: "38px", textAlign: "center", fontSize: "11px", lineHeight: "20px", color: "var(--dsw-alias-label-secondary)", fontVariantNumeric: "tabular-nums", userSelect: "none", whiteSpace: "nowrap" },
1442
1539
  // 027 内嵌头部(sidebar 模式):BS 外层已有 Tab 头部,内嵌只保留一行
1443
1540
  // 紧凑工具栏——脑图列表标签 + 当前脑图标签 + 导出按钮(行尾)。
1444
1541
  // 上下内距比 standalone 的 header(12px 14px 0)更紧凑,行间距更小。
1445
- sbToolbar: { display: "flex", alignItems: "center", gap: "6px", padding: "6px 10px", boxSizing: "border-box", borderBottom: "1px solid var(--dsw-alias-border-l2)", flex: "none", minWidth: 0 },
1542
+ sbToolbar: { display: "flex", alignItems: "center", gap: "6px", padding: "6px 10px 7px", boxSizing: "border-box", borderBottom: "1px solid var(--dsw-alias-border-l2)", flex: "none", minWidth: 0 },
1446
1543
  // 紧凑标签:比 standalone 的 tab(3px 12px)更小,贴合单行工具栏。
1447
1544
  sbTab: { border: "none", background: "none", cursor: "pointer", padding: "2px 8px", lineHeight: "20px", borderRadius: "6px", font: "inherit", fontSize: "12px", color: "var(--dsw-alias-label-secondary)", whiteSpace: "nowrap", maxWidth: "120px", overflow: "hidden", textOverflow: "ellipsis", transition: "background 0.08s ease, color 0.08s ease" },
1448
1545
  sbTabActive: { background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)" },
@@ -1502,7 +1599,7 @@ window.__ModuleLoader__.load({
1502
1599
  /**
1503
1600
  * 015 设置面板(settings.section 页面,root scope):读写 host 的
1504
1601
  * settings namespace "mindmap"。节点主题三件套(线/卡片/颜色)+ 面板宽度;
1505
- * requireApproval 按作者要求隐藏(功能保留,经 config/API 仍可设)。
1602
+ * 写入确认策略在这里可见;当前会话的授权状态由脑图工作区显示。
1506
1603
  */
1507
1604
  function SettingsPanel(props) {
1508
1605
  const { mindmapFace } = props;
@@ -1519,6 +1616,7 @@ window.__ModuleLoader__.load({
1519
1616
  if (!alive) return;
1520
1617
  if (v === null) setError("设置服务不可用:settings namespace 未注册或 connection 缺失");
1521
1618
  setValue({
1619
+ approvalMode: v && v.requireApproval === false ? "off" : v && ["per-operation", "session", "off"].includes(v.approvalMode) ? v.approvalMode : "session",
1522
1620
  lineStyle: v && v.lineStyle === "curve" ? "curve" : "elbow",
1523
1621
  cardStyle: v && v.cardStyle === "square" ? "square" : "rounded",
1524
1622
  colorTheme: v && COLOR_THEMES[v.colorTheme] ? v.colorTheme : "ocean",
@@ -1544,8 +1642,10 @@ window.__ModuleLoader__.load({
1544
1642
  await mindmapFace.updateSettings(patch);
1545
1643
  settingsBus.bump(); // 通知脑图面板重读主题(面板常驻,open 不变)
1546
1644
  setNotice("已保存");
1645
+ return true;
1547
1646
  } catch (err) {
1548
1647
  setError(String(err?.message ?? err));
1648
+ return false;
1549
1649
  } finally {
1550
1650
  setSaving(false);
1551
1651
  }
@@ -1569,7 +1669,6 @@ window.__ModuleLoader__.load({
1569
1669
  const commitWidth = () => {
1570
1670
  save({ defaultPanelWidth: value.defaultPanelWidth });
1571
1671
  };
1572
-
1573
1672
  return (0, react_jsx_runtime.jsxs)("div", { style: S.settingsWrap, children: [
1574
1673
  (0, react_jsx_runtime.jsx)("p", { style: S.settingsGroupTitle, children: "节点主题" }),
1575
1674
  (0, react_jsx_runtime.jsxs)("div", { style: S.settingsGroup, children: [
@@ -1643,6 +1742,24 @@ window.__ModuleLoader__.load({
1643
1742
  ] }),
1644
1743
  (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "开启后,脑图每次更新的新增/变化节点会逐个渐显长出(总时长不超过 2 秒);关闭则整棵树立刻完整显示。" }),
1645
1744
  ] }),
1745
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsGroupTitle, children: "写入确认" }),
1746
+ (0, react_jsx_runtime.jsxs)("div", { style: S.settingsGroup, children: [
1747
+ (0, react_jsx_runtime.jsxs)("div", { style: S.settingsRow, children: [
1748
+ (0, react_jsx_runtime.jsx)("span", { style: S.settingsLabel, children: "确认频率" }),
1749
+ (0, react_jsx_runtime.jsx)(Segmented, {
1750
+ options: [
1751
+ { value: "per-operation", label: "每次确认" },
1752
+ { value: "session", label: "本会话一次" },
1753
+ { value: "off", label: "关闭普通确认" },
1754
+ ],
1755
+ value: value.approvalMode,
1756
+ disabled: saving,
1757
+ onChange: (v) => setField({ approvalMode: v }),
1758
+ }),
1759
+ ] }),
1760
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: value.approvalMode === "session" ? "本会话首次写入当前脑图后,后续普通更新无需重复确认。切换文件或会话会重新确认。" : value.approvalMode === "off" ? "普通更新不再弹窗;重命名、删除和大范围重写仍需确认。" : "每次写入都会弹窗确认。" }),
1761
+ value.approvalMode === "session" ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "授权状态显示在当前脑图工作区;可在那里撤销当前会话的普通写入授权。" }) : null,
1762
+ ] }),
1646
1763
  saving ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "保存中…" }) : null,
1647
1764
  notice ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsNotice, children: notice }) : null,
1648
1765
  error ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsError, children: error }) : null,
@@ -1765,8 +1882,8 @@ window.__ModuleLoader__.load({
1765
1882
  //#endregion
1766
1883
 
1767
1884
  function NodeBox(props) {
1768
- const { node, theme, revealDelay, selectedId, onCodePanel } = props;
1769
- const [hovered, setHovered] = react.useState(false);
1885
+ const { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId } = props;
1886
+ const [hovered, setHovered] = react.useState(false);
1770
1887
  const boxRef = react.useRef(null);
1771
1888
  // 020 长度治理:散文类块(text/md/list/quote)套 6 行截断;clamped = 实测
1772
1889
  // 真的溢出了(scrollHeight>clientHeight),悬停浮层看全文(复用代码浮层)。
@@ -1788,7 +1905,13 @@ window.__ModuleLoader__.load({
1788
1905
  ...resolveNodeStyle(node, {
1789
1906
  colorTheme: theme && theme.colorTheme,
1790
1907
  cardStyle: theme && theme.cardStyle,
1791
- states: { hovered, selected: selectedId === node.id },
1908
+ states: {
1909
+ hovered,
1910
+ selected: selectedId === node.id,
1911
+ // 035 搜索命中:普通命中轻描边,活动命中的命中节点双层强调环。
1912
+ matched: Boolean(matchIds && matchIds.has(node.id)),
1913
+ matchActive: activeMatchId === node.id,
1914
+ },
1792
1915
  }),
1793
1916
  };
1794
1917
  // 020 表格块不参与散文 320px 宽上限:完整网格需要更宽书写面,
@@ -1829,7 +1952,7 @@ window.__ModuleLoader__.load({
1829
1952
 
1830
1953
  /** 左→右递归树:节点盒 + 右侧子节点列 + 连线层(015 支持折线/曲线两种线型)。 */
1831
1954
  function TreeRow(props) {
1832
- const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse } = props;
1955
+ const { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId } = props;
1833
1956
  // 025 折叠:纯视图态——markdown 资产不变,导出仍取完整子树。
1834
1957
  const hasChildren = Boolean(node.children && node.children.length > 0);
1835
1958
  const isCollapsed = hasChildren && Boolean(collapsed && collapsed.has(node.id));
@@ -1946,7 +2069,7 @@ window.__ModuleLoader__.load({
1946
2069
  e.stopPropagation();
1947
2070
  onNodeContextMenu(e, node);
1948
2071
  } : undefined,
1949
- children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel }),
2072
+ children: (0, react_jsx_runtime.jsx)(NodeBox, { node, theme, revealDelay, selectedId, onCodePanel, matchIds, activeMatchId }),
1950
2073
  }),
1951
2074
  // 025 折叠开关:坐在盒与子列之间的连线起点上(有子节点才出现)。
1952
2075
  // stopPropagation 保证点它不触发画布的「点节点聚焦 / 点空白取消选中」。
@@ -1971,7 +2094,7 @@ window.__ModuleLoader__.load({
1971
2094
  ref: (el) => {
1972
2095
  childRefs.current[idx] = el;
1973
2096
  },
1974
- children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse }),
2097
+ children: (0, react_jsx_runtime.jsx)(TreeRow, { node: child, theme, onNodeContextMenu, reveal, selectedId, onCodePanel, collapsed, onToggleCollapse, matchIds, activeMatchId }),
1975
2098
  }, child.id)) })
1976
2099
  : null,
1977
2100
  ] });
@@ -1981,7 +2104,15 @@ window.__ModuleLoader__.load({
1981
2104
  // 缩放契约:范围 [0.25, 3],每级 ×1.2;适配计算四周留 48px 余量
1982
2105
  //(16px 视觉内距 + 经典滚动条占位,避免「适配→滚动条出现→视口变
1983
2106
  // 窄→再适配」的抖动循环)。
1984
- const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1 };
2107
+ // 033 focusJump:点击聚焦单次跳变上限(相对当前比例最多 ×2 / ÷2),
2108
+ // 巨图点叶子不再一步怼到 100%,连点渐进 drill。narrowView:视口宽
2109
+ // 低于该值(sidebar 最窄 280px)时改按高度适配——横向适配在窄面板
2110
+ // 永远占主导会把子树压得过小,宽度溢出交给平移(横向本就一等公民)。
2111
+ // animMs:033 平滑过渡时长上限(限长、可中断、熔断后退化瞬时)。
2112
+ const ZOOM = { min: 0.25, max: 3, step: 1.2, padding: 48, focusMax: 1, focusJump: 2, narrowView: 400, animMs: 250 };
2113
+ // 034 聚焦锚位(视口比例):树向右生长,节点压在左侧 1/4 处、
2114
+ // 垂直居中,右侧 3/4 视野铺开子级。动画从点击位置插值到此锚位。
2115
+ const FOCUS_ANCHOR = { x: 0.25, y: 0.5 };
1985
2116
 
1986
2117
  /** 缩放夹取:非有限值/≤0 回退 1,否则夹到 [min, max]。 */
1987
2118
  function clampZoom(value) {
@@ -1998,18 +2129,59 @@ window.__ModuleLoader__.load({
1998
2129
  /** 适配比例:min((view-padding)/tree, 1) 再夹取——小图不放大、巨图夹下限;零/非法尺寸返回 1。 */
1999
2130
  function fitZoom(treeW, treeH, viewW, viewH) {
2000
2131
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2132
+ // 033 窄视口(sidebar):按高度适配,宽度溢出靠平移。
2133
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, 1));
2001
2134
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, 1));
2002
2135
  }
2003
2136
 
2004
2137
  /**
2005
2138
  * 子树聚焦比例:适配整棵子树(区别于全局适配,允许放大到 focusMax),
2006
2139
  * 叶子/小子树不会怼脸、巨子树夹下限;零/非法尺寸返回 1。
2140
+ * 033 窄视口同 fitZoom:按高度适配(子树行通常宽而扁,窄面板里
2141
+ * 横向适配会把整行压到不可读)。
2007
2142
  */
2008
2143
  function focusZoom(treeW, treeH, viewW, viewH) {
2009
2144
  if (!(treeW > 0) || !(treeH > 0) || !(viewW > 0) || !(viewH > 0)) return 1;
2145
+ if (viewW < ZOOM.narrowView) return clampZoom(Math.min((viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2010
2146
  return clampZoom(Math.min((viewW - ZOOM.padding) / treeW, (viewH - ZOOM.padding) / treeH, ZOOM.focusMax));
2011
2147
  }
2012
2148
 
2149
+ /**
2150
+ * 033 点击聚焦跳变钳制:目标比例相对当前值单次最多变化 focusJump 倍
2151
+ *(放大 ×2 / 缩小 ÷2),超出则截到边界。放置在调用点而非 focusZoom
2152
+ * 内——focusZoom 保持「无状态适配计算」语义(测试直测),跳变限制
2153
+ * 需要知道当前值,属交互层策略。连续点击逐步逼近,方向不变。
2154
+ */
2155
+ function clampFocusJump(target, current) {
2156
+ const value = clampZoom(target);
2157
+ const base = clampZoom(current);
2158
+ return Math.min(base * ZOOM.focusJump, Math.max(base / ZOOM.focusJump, value));
2159
+ }
2160
+
2161
+ /** 033 项3:按结构 id 找当前树里的节点盒(遍历比对属性值,不做选择器
2162
+ * 拼接——结构 id 虽是数字路径,这里不依赖该假设)。找不到返回 null。 */
2163
+ function findBoxByNodeId(scroller, id) {
2164
+ if (!scroller || typeof scroller.querySelectorAll !== "function") return null;
2165
+ const boxes = scroller.querySelectorAll("[data-mindmap-node-id]");
2166
+ for (const el of boxes) {
2167
+ if (el.getAttribute("data-mindmap-node-id") === id) return el;
2168
+ }
2169
+ return null;
2170
+ }
2171
+
2172
+ /** 033 项3:把完全离开视口的盒子拉回最近边的最小滚动位移(视口坐标
2173
+ * 系,正 = 向右/下滚)。部分可见或在内返回 0——不打扰用户视角。
2174
+ * margin = 拉回后与视口边保留的呼吸余量。 */
2175
+ function edgePullOffsets(box, view, margin) {
2176
+ let dx = 0;
2177
+ let dy = 0;
2178
+ if (box.right < view.left) dx = box.left - (view.left + margin);
2179
+ else if (box.left > view.right) dx = box.right - (view.right - margin);
2180
+ if (box.bottom < view.top) dy = box.top - (view.top + margin);
2181
+ else if (box.top > view.bottom) dy = box.bottom - (view.bottom - margin);
2182
+ return { x: dx, y: dy };
2183
+ }
2184
+
2013
2185
  //#region 021 画布平移:拖拽手势(中键 / 空白处左键 / 空格+左键)
2014
2186
  // 平移契约(三条手指路径,覆盖鼠标与 Mac 触摸板):
2015
2187
  // 中键拖动 —— 画布惯例,任何位置都拖(压节点上也拖)
@@ -2107,7 +2279,7 @@ window.__ModuleLoader__.load({
2107
2279
  // 016 熔断器:观察器触发的适配时间戳。1.5s 内第 5 次 → 判定
2108
2280
  // 反馈循环,自动停手(保险丝,任何未知循环都最多闪几下)。
2109
2281
  const fitStampRef = react.useRef([]);
2110
- const [zoom, setZoomState] = react.useState(1);
2282
+ const [zoom, setZoomState] = react.useState(1);
2111
2283
  const [hover, setHover] = react.useState(null);
2112
2284
  // 017 节点右键菜单:{x, y, node};null = 关闭。busy = "copy" |
2113
2285
  // "export" 表示对应动作进行中(两项都禁用),error 展示失败原因。
@@ -2120,6 +2292,24 @@ window.__ModuleLoader__.load({
2120
2292
  // 025 折叠子树:纯视图态(不写回 markdown,导出仍取完整子树)。
2121
2293
  // 切换文档时全部展开;AI 改写后清掉已消失节点的折叠标记。
2122
2294
  const [collapsed, setCollapsed] = react.useState(() => new Set());
2295
+ // 035 节点搜索:开箱态 / 查询词 / 当前命中下标 / 待定位 id。
2296
+ // 命中列表由 useMemo 按 [node, searchQuery] 现算——O(n) 子串
2297
+ // 匹配(上千节点也是微秒级),不重 parse、不重建 DOM。
2298
+ const [searchOpen, setSearchOpen] = react.useState(false);
2299
+ const [searchQuery, setSearchQuery] = react.useState("");
2300
+ const [searchIndex, setSearchIndex] = react.useState(-1);
2301
+ const [searchReveal, setSearchReveal] = react.useState(null);
2302
+ const searchInputRef = react.useRef(null);
2303
+ // 当前命中的稳定结构 id:AI 改写树后按它找回原命中节点。
2304
+ const searchActiveIdRef = react.useRef(null);
2305
+ const searchMatches = react.useMemo(() => searchTreeMatches(node, searchQuery), [node, searchQuery]);
2306
+ const searchMatchIds = searchMatches.length > 0 ? new Set(searchMatches) : null;
2307
+ // 渲染期先钳一次:AI 改写后命中列表变短,[node] 协调 effect
2308
+ // 生效前的那一帧若沿用旧下标会显示「4 / 3」这类越界计数。
2309
+ const searchIndexSafe = searchMatches.length > 0
2310
+ ? (searchIndex >= 0 && searchIndex < searchMatches.length ? searchIndex : 0)
2311
+ : -1;
2312
+ const searchActiveId = searchIndexSafe >= 0 ? searchMatches[searchIndexSafe] : null;
2123
2313
  // 019 代码块悬停浮层:{node, anchor};null = 关闭。延迟关闭(150ms
2124
2314
  // 宽限)让鼠标能从节点盒移到面板上滚动全文,不闪灭。
2125
2315
  const [codePanel, setCodePanel] = react.useState(null);
@@ -2151,6 +2341,94 @@ window.__ModuleLoader__.load({
2151
2341
  // 021 指针是否悬在画布上(空格键要不要拦默认行为的门控;纯
2152
2342
  // 读取,不参与渲染)。
2153
2343
  const hoverRef = react.useRef(false);
2344
+ // 033 平滑过渡:在飞的 zoom 动画句柄 { id, from, to, start };
2345
+ // animDisabled = 熔断器触发过(本轮 fitKey 内动画退化为瞬时,
2346
+ // 切文档/点适配时复位)。
2347
+ // 034 动画期间绕过 React(根因二:每帧 setZoomState 整树重渲染,
2348
+ // 大图掉帧):每帧直写内容层 style.zoom + 滚动校正,不进 state;
2349
+ // 结束帧一次性 setZoomState(target) 同步 UI(百分比/边界按钮/
2350
+ // committedZoomRef)。测量基准不受影响——动画只在点击后飞,
2351
+ // 此时 userZoomedRef 已置位,ResizeObserver 不会再调 applyFit。
2352
+ const zoomAnimRef = react.useRef(null);
2353
+ const animDisabledRef = react.useRef(false);
2354
+
2355
+ // 034 仅停帧:取消 rAF + 同步 committed/state,保留 focusRef
2356
+ //(animateZoomTo 替换旧动画时用——调用方随后会覆盖 focusRef,
2357
+ // 不能让它把新聚焦也清掉)。中断时 DOM 已被直写到中间值——
2358
+ // 立即把 committedZoomRef 对齐该值(applyFit 的自然尺寸测量基准
2359
+ // 必须等于 DOM 实际 zoom),并用 setZoomState 把 React state
2360
+ // 兜底同步(防后续 re-render 把 style.zoom 打回动画前的旧值)。
2361
+ function stopZoomAnimFrames() {
2362
+ const anim = zoomAnimRef.current;
2363
+ if (!anim) return;
2364
+ zoomAnimRef.current = null;
2365
+ if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(anim.id);
2366
+ committedZoomRef.current = zoomRef.current;
2367
+ setZoomState(zoomRef.current);
2368
+ }
2369
+
2370
+ // 033 截停在飞动画(任何新交互都先调):停帧 + 顺手清掉
2371
+ // focusRef(否则下一次 zoom 提交会被过期聚焦劫持定位)。
2372
+ function cancelZoomAnim() {
2373
+ if (!zoomAnimRef.current) return;
2374
+ stopZoomAnimFrames();
2375
+ focusRef.current = null;
2376
+ }
2377
+
2378
+ // 034 期望锚位插值:点击位置 → FOCUS_ANCHOR,与 zoom 同一
2379
+ // eased 进度——第一帧期望位置 = 点击时位置(零瞬移,根因一),
2380
+ // 节点被「牵着」滑向锚位。
2381
+ function lerpFocusAnchor(start, k) {
2382
+ return {
2383
+ x: start.x + (FOCUS_ANCHOR.x - start.x) * k,
2384
+ y: start.y + (FOCUS_ANCHOR.y - start.y) * k,
2385
+ };
2386
+ }
2387
+
2388
+ // 033/034 平滑 zoom:from → to,限长 animMs、easeOutQuad,并行
2389
+ // 上限 1(新动画先截停旧动画)。每帧:直写 style.zoom、同步
2390
+ // zoomRef、按插值锚位滚动校正(applyFocusAnchor);结束帧精确落
2391
+ // 在 to 并 setZoomState 触发最后一次 [zoom] effect(positionFocus
2392
+ // 消费 focusRef、全量锚位终校——此刻 ≈ no-op)。禁用/无 rAF 环
2393
+ // 境瞬时应用,行为与 033 之前完全一致。
2394
+ function animateZoomTo(to) {
2395
+ stopZoomAnimFrames();
2396
+ const target = clampZoom(to);
2397
+ const from = zoomRef.current;
2398
+ if (from === target) return;
2399
+ const scroller = scrollRef.current;
2400
+ const content = contentRef.current;
2401
+ const canAnimate = animDisabledRef.current !== true
2402
+ && scroller
2403
+ && content
2404
+ && typeof requestAnimationFrame === "function";
2405
+ if (!canAnimate) {
2406
+ zoomRef.current = target;
2407
+ setZoomState(target);
2408
+ return;
2409
+ }
2410
+ const anim = { id: 0, from, to: target, start: Date.now() };
2411
+ zoomAnimRef.current = anim;
2412
+ const frame = () => {
2413
+ if (zoomAnimRef.current !== anim) return; // 已被截停/替换
2414
+ const t = Math.min(1, (Date.now() - anim.start) / ZOOM.animMs);
2415
+ const eased = 1 - (1 - t) * (1 - t);
2416
+ const value = t >= 1 ? target : from + (target - from) * eased;
2417
+ zoomRef.current = value;
2418
+ content.style.zoom = value; // 034:直写 DOM,绕过 React
2419
+ const focus = focusRef.current;
2420
+ if (focus && focus.boxEl && focus.boxEl.isConnected) {
2421
+ applyFocusAnchor(focus.boxEl, lerpFocusAnchor(focus.startAnchor, eased));
2422
+ }
2423
+ if (t >= 1) {
2424
+ zoomAnimRef.current = null;
2425
+ setZoomState(target);
2426
+ return;
2427
+ }
2428
+ anim.id = requestAnimationFrame(frame);
2429
+ };
2430
+ anim.id = requestAnimationFrame(frame);
2431
+ }
2154
2432
 
2155
2433
  // 测量并适配:自然尺寸 = getBoundingClientRect ÷ 已提交 zoom(与
2156
2434
  // DOM 实际状态严格同步,无竞态)。值不变不动 state(bail-out),
@@ -2159,6 +2437,9 @@ window.__ModuleLoader__.load({
2159
2437
  const scroller = scrollRef.current;
2160
2438
  const content = contentRef.current;
2161
2439
  if (!scroller || !content) return;
2440
+ // 033:适配前截停在飞动画(观察器/适配按钮不能被旧动画
2441
+ // 的后续帧反向覆盖)。
2442
+ cancelZoomAnim();
2162
2443
  resetPanOffset();
2163
2444
  const rect = content.getBoundingClientRect();
2164
2445
  if (!(rect.width > 0) || !(rect.height > 0)) return;
@@ -2178,14 +2459,27 @@ window.__ModuleLoader__.load({
2178
2459
  }
2179
2460
 
2180
2461
  // 挂载 / 文档切换:清除「用户已手动缩放」标记与熔断计数,
2181
- // 布局稳定后(rAF)适配一次。
2462
+ // 布局稳定后(rAF)适配一次。033:同时复位动画禁用位与
2463
+ // 选中态(新文档不该继承旧文档的选中环——结构 id 跨文档
2464
+ // 可能撞名,会让保视野逻辑锚错节点);清理时截停在飞动画。
2182
2465
  react.useLayoutEffect(() => {
2183
2466
  userZoomedRef.current = false;
2184
2467
  lastNaturalRef.current = null;
2185
2468
  fitStampRef.current = [];
2469
+ animDisabledRef.current = false;
2470
+ setSelectedId(null);
2186
2471
  setCollapsed((prev) => (prev.size > 0 ? new Set() : prev));
2472
+ // 035:切文档重置搜索——上一张图的 query/命中不污染新图。
2473
+ setSearchOpen(false);
2474
+ setSearchQuery("");
2475
+ setSearchIndex(-1);
2476
+ setSearchReveal(null);
2477
+ searchActiveIdRef.current = null;
2187
2478
  const id = requestAnimationFrame(applyFit);
2188
- return () => cancelAnimationFrame(id);
2479
+ return () => {
2480
+ cancelAnimationFrame(id);
2481
+ cancelZoomAnim();
2482
+ };
2189
2483
  }, [fitKey]);
2190
2484
 
2191
2485
  // 内容 / 画布尺寸变化(AI 编辑、面板拖宽)→ 未手动缩放则再适配。
@@ -2214,6 +2508,9 @@ window.__ModuleLoader__.load({
2214
2508
  const stamps = fitStampRef.current = fitStampRef.current.filter((t) => now - t < 1500);
2215
2509
  if (stamps.length >= 5) {
2216
2510
  userZoomedRef.current = true;
2511
+ // 033:熔断判定成立 → 本轮 fitKey 内动画也停用(反馈
2512
+ // 循环环境里再引入中间态提交只会火上浇油)。
2513
+ animDisabledRef.current = true;
2217
2514
  return;
2218
2515
  }
2219
2516
  stamps.push(now);
@@ -2277,6 +2574,9 @@ window.__ModuleLoader__.load({
2277
2574
  // 否则上轮手势留下的 true 会粘到下一次点击上——例:拖完画布后再
2278
2575
  // 触摸点按(touch 路径不启动平移就早退了),那次点击会被白吞一次。
2279
2576
  suppressClickRef.current = false;
2577
+ // 033:平移起手即截停缩放动画——聚焦动画每帧把节点钉回锚位,
2578
+ // 会和用户拖拽的方向对着干。
2579
+ cancelZoomAnim();
2280
2580
  const scroller = scrollRef.current;
2281
2581
  if (!scroller || panRef.current) return;
2282
2582
  const target = e.target;
@@ -2365,7 +2665,11 @@ window.__ModuleLoader__.load({
2365
2665
  // DOM 已提交到该 zoom,测量换算基准同步(applyFit 依赖)。
2366
2666
  committedZoomRef.current = zoom;
2367
2667
  if (focusRef.current) {
2368
- positionFocus();
2668
+ // 034:动画在飞时既不定位也不消费——帧回调自己管锚位插值;
2669
+ // 动画中再点击时,cancel 的 setZoomState 也会路过这里,
2670
+ // 提前消费/全量锚位都会造成闪跳。瞬时聚焦与动画结束帧
2671
+ //(anim 先清再 setState)才做全量终校(结束时 ≈ no-op)。
2672
+ if (!zoomAnimRef.current) positionFocus();
2369
2673
  return;
2370
2674
  }
2371
2675
  const scroller = scrollRef.current;
@@ -2380,11 +2684,13 @@ window.__ModuleLoader__.load({
2380
2684
 
2381
2685
  function zoomIn() {
2382
2686
  userZoomedRef.current = true;
2687
+ cancelZoomAnim();
2383
2688
  setZoom(stepZoom(zoomRef.current, 1), true);
2384
2689
  }
2385
2690
 
2386
2691
  function zoomOut() {
2387
2692
  userZoomedRef.current = true;
2693
+ cancelZoomAnim();
2388
2694
  setZoom(stepZoom(zoomRef.current, -1), true);
2389
2695
  }
2390
2696
 
@@ -2398,6 +2704,8 @@ window.__ModuleLoader__.load({
2398
2704
  // 左侧锚点让子级铺满右侧视野),缩放比例取 focusZoom(整棵子树适配、
2399
2705
  // 上限 focusMax)。事件委托:closest 找节点盒与所在子树 row,无需给
2400
2706
  // 递归 TreeRow 传回调。聚焦视为用户手动缩放(停自动再适配)。
2707
+ // 033:目标比例经 clampFocusJump 单次最多 ×2/÷2(巨图点叶子不再一步
2708
+ // 怼到 100%,连点渐进 drill);zoom 变化经 animateZoomTo 平滑过渡。
2401
2709
  function onCanvasClick(e) {
2402
2710
  // 021:刚拖过画布(平移)的这次 click 不是点击,直接吞掉——
2403
2711
  // 否则每次平移松手都会顺手把选中环清掉。
@@ -2421,34 +2729,173 @@ window.__ModuleLoader__.load({
2421
2729
  if (!scroller) return;
2422
2730
  const current = zoomRef.current;
2423
2731
  const rowRect = rowEl.getBoundingClientRect();
2424
- const focus = focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight);
2732
+ // 033 跳变钳制:相对当前比例单次最多 ×2 / ÷2。
2733
+ const focus = clampFocusJump(
2734
+ focusZoom(rowRect.width / current, rowRect.height / current, scroller.clientWidth, scroller.clientHeight),
2735
+ current,
2736
+ );
2737
+ // 034:记录点击时节点中心的视口比例位置——动画锚位插值起点
2738
+ //(第一帧期望位置 = 点击时位置,消除首帧滚动瞬移)。
2739
+ const boxRect = boxEl.getBoundingClientRect();
2740
+ const scrollerRect = scroller.getBoundingClientRect();
2741
+ const startAnchor = {
2742
+ x: (boxRect.left + boxRect.width / 2 - scrollerRect.left) / scroller.clientWidth,
2743
+ y: (boxRect.top + boxRect.height / 2 - scrollerRect.top) / scroller.clientHeight,
2744
+ };
2425
2745
  userZoomedRef.current = true;
2426
- focusRef.current = { boxEl };
2427
2746
  if (focus !== current) {
2428
2747
  anchorRef.current = null;
2429
- zoomRef.current = focus;
2430
- setZoomState(focus);
2748
+ // 034:先完整截停旧动画(清过期 focusRef + 同步中间值),
2749
+ // 再登记本次聚焦——顺序不能反(cancel 会清 focusRef)。
2750
+ cancelZoomAnim();
2751
+ focusRef.current = { boxEl, startAnchor };
2752
+ animateZoomTo(focus);
2431
2753
  } else {
2754
+ cancelZoomAnim();
2755
+ focusRef.current = { boxEl, startAnchor };
2432
2756
  positionFocus();
2433
2757
  }
2434
2758
  }
2435
2759
 
2436
- // 聚焦定位:DOM 更新后量节点盒当前位置,滚动增量 = 当前位置 − 期望位置
2437
- //(scroll 增量与视口位移 1:1,浏览器自动钳制滚动范围;比例不变时同步调用)。
2438
- function positionFocus() {
2439
- const focus = focusRef.current;
2440
- focusRef.current = null;
2760
+ // 034 锚位应用:把节点盒中心滚到指定视口比例锚位(滚动增量与视口
2761
+ // 位移 1:1,浏览器自动钳制滚动范围)。positionFocus(固定锚位)与
2762
+ // 聚焦动画帧(插值锚位)共用。
2763
+ function applyFocusAnchor(boxEl, anchor) {
2441
2764
  const scroller = scrollRef.current;
2442
- if (!scroller || !focus || !focus.boxEl || !focus.boxEl.isConnected) return;
2765
+ if (!scroller || !boxEl || !boxEl.isConnected) return;
2443
2766
  resetPanOffset();
2444
- const boxRect = focus.boxEl.getBoundingClientRect();
2767
+ const boxRect = boxEl.getBoundingClientRect();
2445
2768
  const scrollerRect = scroller.getBoundingClientRect();
2446
2769
  const curX = boxRect.left + boxRect.width / 2 - scrollerRect.left;
2447
2770
  const curY = boxRect.top + boxRect.height / 2 - scrollerRect.top;
2448
- scroller.scrollLeft += curX - scroller.clientWidth * 0.25;
2449
- scroller.scrollTop += curY - scroller.clientHeight / 2;
2771
+ scroller.scrollLeft += curX - scroller.clientWidth * anchor.x;
2772
+ scroller.scrollTop += curY - scroller.clientHeight * anchor.y;
2773
+ }
2774
+
2775
+ // 聚焦定位:DOM 更新后把节点盒滚到 FOCUS_ANCHOR(全量校正)。
2776
+ // 034:consume = false 时保留 focusRef——瞬时聚焦路径不再逐帧,仅
2777
+ // 动画结束帧(zoomAnimRef 已清空)与同步调用消费。
2778
+ function positionFocus(consume = true) {
2779
+ const focus = focusRef.current;
2780
+ if (!focus || !focus.boxEl || !focus.boxEl.isConnected) {
2781
+ focusRef.current = null;
2782
+ return;
2783
+ }
2784
+ if (consume) focusRef.current = null;
2785
+ applyFocusAnchor(focus.boxEl, FOCUS_ANCHOR);
2786
+ }
2787
+
2788
+ //#region 035 节点搜索:输入即搜 + 匹配间跳转 + 自动展开祖先 + 滚动定位
2789
+ // 打开搜索(Cmd/Ctrl+F 或缩放条 🔍)。关闭 = 清 query/命中/高亮;
2790
+ // 为定位展开的祖先保持展开——用户下一步多半还要看上下文。
2791
+ function openSearch() {
2792
+ setSearchOpen(true);
2793
+ }
2794
+ function closeSearch() {
2795
+ setSearchOpen(false);
2796
+ setSearchQuery("");
2797
+ setSearchIndex(-1);
2798
+ searchActiveIdRef.current = null;
2799
+ }
2800
+
2801
+ // 输入即搜:每次按键 O(n) 现算命中并跳到第一个(VS Code find 同款手感)。
2802
+ // 直接调纯函数拿新查询的结果(本渲染的 memo 还是旧 query 的)。
2803
+ function onQueryChange(e) {
2804
+ const query = e && e.target ? e.target.value : "";
2805
+ const matches = searchTreeMatches(node, query);
2806
+ setSearchQuery(query);
2807
+ if (matches.length > 0) {
2808
+ setSearchIndex(0);
2809
+ searchActiveIdRef.current = matches[0];
2810
+ revealSearchMatch(matches[0]);
2811
+ } else {
2812
+ setSearchIndex(-1);
2813
+ searchActiveIdRef.current = null;
2814
+ }
2815
+ }
2816
+
2817
+ // 上一个/下一个:双向环绕(末尾→开头、开头→末尾)。
2818
+ function stepSearch(delta) {
2819
+ if (searchMatches.length === 0) return;
2820
+ const next = stepMatchIndex(searchIndex, searchMatches.length, delta);
2821
+ setSearchIndex(next);
2822
+ searchActiveIdRef.current = searchMatches[next];
2823
+ revealSearchMatch(searchMatches[next]);
2824
+ }
2825
+
2826
+ // 定位一个命中:先展开它的祖先路径(折叠分支里的结果也真正可见),
2827
+ // 再登记待定位 id——[searchReveal] layout effect 在 DOM 提交后按结构
2828
+ // id 找盒、滚到聚焦锚位。不动 zoom(保留用户当前缩放,只改必要滚动)。
2829
+ function revealSearchMatch(id) {
2830
+ setCollapsed((prev) => expandAncestorsFor(prev, node, id));
2831
+ setSearchReveal(id);
2450
2832
  }
2451
2833
 
2834
+ // 搜索定位提交后的滚动:与展开祖先同批 setState,此 effect 运行时
2835
+ // 展开的子树已挂载。搜索定位 = 显式视角意图:与点击聚焦一样停自动
2836
+ // 再适配,并截停在飞聚焦动画(其帧回调会把节点钉回旧锚位对着干)。
2837
+ react.useLayoutEffect(() => {
2838
+ if (!searchReveal) return;
2839
+ const scroller = scrollRef.current;
2840
+ const boxEl = scroller ? findBoxByNodeId(scroller, searchReveal) : null;
2841
+ if (boxEl) {
2842
+ userZoomedRef.current = true;
2843
+ cancelZoomAnim();
2844
+ applyFocusAnchor(boxEl, FOCUS_ANCHOR);
2845
+ }
2846
+ setSearchReveal(null);
2847
+ }, [searchReveal]);
2848
+
2849
+ // 开箱聚焦输入框(全选既有词——当前实现关闭即清空,习惯上仍全选)。
2850
+ react.useLayoutEffect(() => {
2851
+ if (!searchOpen) return;
2852
+ const input = searchInputRef.current;
2853
+ if (!input || typeof input.focus !== "function") return;
2854
+ input.focus();
2855
+ if (typeof input.select === "function") input.select();
2856
+ }, [searchOpen]);
2857
+
2858
+ // AI 更新后重算命中:保留 query;优先按稳定 id 找回原命中节点,
2859
+ // 找不到回落最近有效下标/第一个;无命中显示 0。只调下标不滚动——
2860
+ // AI 每次编辑都拽走视口会与「视角归用户」冲突,滚动只由导航触发。
2861
+ react.useEffect(() => {
2862
+ if (searchQuery === "") return;
2863
+ const next = reconcileActiveMatch(searchActiveIdRef.current, searchIndex, searchMatches);
2864
+ if (next !== searchIndex) setSearchIndex(next);
2865
+ if (next >= 0) searchActiveIdRef.current = searchMatches[next];
2866
+ }, [node]);
2867
+
2868
+ // Cmd/Ctrl+F 打开搜索。拦截范围 = 画布挂载(脑图 tab 可见且激活;
2869
+ // 面板收起/切目录树即卸载,无僵尸监听)且目标不是别人的文本输入
2870
+ //(聊天框里的 Cmd+F 留给宿主);已有人处理过(defaultPrevented)不抢。
2871
+ react.useEffect(() => {
2872
+ const onKeyDown = (e) => {
2873
+ if (e.defaultPrevented || e.altKey) return;
2874
+ if (!(e.metaKey || e.ctrlKey)) return;
2875
+ if (!e.key || e.key.toLowerCase() !== "f") return;
2876
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2877
+ e.preventDefault();
2878
+ setSearchOpen(true);
2879
+ };
2880
+ window.addEventListener("keydown", onKeyDown);
2881
+ return () => window.removeEventListener("keydown", onKeyDown);
2882
+ }, []);
2883
+
2884
+ // Escape 关闭搜索:仅搜索打开期间注册(closeSearch 只调常参 setter,
2885
+ // 闭包过期无害);目标在他人输入框时不抢 Escape。
2886
+ react.useEffect(() => {
2887
+ if (!searchOpen) return;
2888
+ const onKeyDown = (e) => {
2889
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2890
+ if (isTextEntry(e.target) && e.target !== searchInputRef.current) return;
2891
+ e.preventDefault();
2892
+ closeSearch();
2893
+ };
2894
+ window.addEventListener("keydown", onKeyDown);
2895
+ return () => window.removeEventListener("keydown", onKeyDown);
2896
+ }, [searchOpen]);
2897
+ //#endregion
2898
+
2452
2899
  // 017 右键菜单开合:点其它地方/失焦/改窗口即关闭(目录树菜单同款);
2453
2900
  // 点菜单内部(复制/导出按钮)不关——菜单里要展示「复制中…」与失败
2454
2901
  // 原因。节点右键经 stopPropagation 不会触发这里的 contextmenu 关闭,
@@ -2477,6 +2924,29 @@ window.__ModuleLoader__.load({
2477
2924
  setCodePanel(null);
2478
2925
  // 025:树重解析后丢弃已消失节点的折叠标记(无变化时保持原引用)。
2479
2926
  setCollapsed((prev) => pruneCollapsed(prev, node));
2927
+ // 033 项3:AI 编辑后保住选中节点在视野内。仅在用户已定视角
2928
+ //(userZoomedRef,自动再适配已停)且选中节点**完全**离开视口时,
2929
+ // 以最小滚动量把它带回最近的边(部分可见不打扰)。只动 scroll:
2930
+ // 不改缩放、不碰 userZoomedRef/熔断器(滚动不触发 ResizeObserver
2931
+ // 的内容尺寸变化),「面板跟随 AI 实时变化」与「视角归用户」两个
2932
+ // 承诺同时成立。id 失效(节点被删/重写)→ 查不到盒,自然跳过。
2933
+ if (userZoomedRef.current && selectedId) {
2934
+ const scroller = scrollRef.current;
2935
+ const boxEl = scroller && typeof scroller.querySelectorAll === "function"
2936
+ ? findBoxByNodeId(scroller, selectedId)
2937
+ : null;
2938
+ if (boxEl && typeof boxEl.getBoundingClientRect === "function") {
2939
+ const box = boxEl.getBoundingClientRect();
2940
+ const view = scroller.getBoundingClientRect();
2941
+ const MARGIN = 24;
2942
+ const pull = edgePullOffsets(box, view, MARGIN);
2943
+ if (pull.x !== 0 || pull.y !== 0) {
2944
+ resetPanOffset();
2945
+ scroller.scrollLeft += pull.x;
2946
+ scroller.scrollTop += pull.y;
2947
+ }
2948
+ }
2949
+ }
2480
2950
  }, [node]);
2481
2951
 
2482
2952
  function toggleCollapse(id) {
@@ -2546,12 +3016,44 @@ window.__ModuleLoader__.load({
2546
3016
  },
2547
3017
  children:
2548
3018
  (0, react_jsx_runtime.jsx)("div", { style: S.canvasCenter, children:
2549
- (0, react_jsx_runtime.jsx)("div", { ref: contentRef, style: { margin: "auto", zoom }, children:
2550
- (0, react_jsx_runtime.jsx)(TreeRow, { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel: handleCodePanel, collapsed, onToggleCollapse: toggleCollapse })
3019
+ // 034:动画期间 zoom 走 DOM 直写(style.zoom),React state
3020
+ // 停在动画前的旧值——动画中任何 re-render(AI 改树、hover)
3021
+ // 若按 state 渲染会把 DOM 打回旧值造成跳变。渲染值在动画
3022
+ // 在飞时改读 zoomRef(恒等于 DOM 当前值),style diff 后
3023
+ // 不覆盖;动画结束 state 已同步,两种取值一致。
3024
+ (0, react_jsx_runtime.jsx)("div", { ref: contentRef, style: { margin: "auto", zoom: zoomAnimRef.current ? zoomRef.current : zoom }, children:
3025
+ (0, react_jsx_runtime.jsx)(TreeRow, { node, theme, onNodeContextMenu, reveal, selectedId, onCodePanel: handleCodePanel, collapsed, onToggleCollapse: toggleCollapse, matchIds: searchMatchIds, activeMatchId: searchActiveId })
2551
3026
  })
2552
3027
  })
2553
3028
  }),
2554
3029
  (0, react_jsx_runtime.jsxs)("div", { style: S.zoomBar, children: [
3030
+ // 035 搜索入口:缩放条内一个轻量 🔍(线框图标与 M 按钮同风格),
3031
+ // 两模式(BS Tab / 独立面板)共用画布,一处实现双模式生效。
3032
+ (0, react_jsx_runtime.jsx)("button", {
3033
+ type: "button",
3034
+ title: "搜索节点(⌘/Ctrl+F)",
3035
+ "aria-label": "搜索节点",
3036
+ "aria-expanded": searchOpen ? "true" : "false",
3037
+ style: zoomBtnStyle("search", false),
3038
+ onClick: () => (searchOpen ? closeSearch() : openSearch()),
3039
+ onMouseEnter: () => setHover("search"),
3040
+ onMouseLeave: () => setHover((h) => (h === "search" ? null : h)),
3041
+ children: (0, react_jsx_runtime.jsx)("svg", {
3042
+ width: 13,
3043
+ height: 13,
3044
+ viewBox: "0 0 14 14",
3045
+ fill: "none",
3046
+ stroke: "currentColor",
3047
+ strokeWidth: 1.4,
3048
+ strokeLinecap: "round",
3049
+ "aria-hidden": "true",
3050
+ style: { display: "block" },
3051
+ children: [
3052
+ (0, react_jsx_runtime.jsx)("circle", { cx: 6, cy: 6, r: 4 }),
3053
+ (0, react_jsx_runtime.jsx)("path", { d: "M9.2 9.2 L12.5 12.5" }),
3054
+ ],
3055
+ }),
3056
+ }),
2555
3057
  (0, react_jsx_runtime.jsx)("button", {
2556
3058
  type: "button",
2557
3059
  title: "缩小",
@@ -2583,6 +3085,68 @@ window.__ModuleLoader__.load({
2583
3085
  children: "适配",
2584
3086
  }),
2585
3087
  ] }),
3088
+ // 035 节点搜索条:缩放条正下方的紧凑浮层(同款容器/主题变量)。
3089
+ // 输入即搜;Enter/↓ 下一个、Shift+Enter/↑ 上一个(双向环绕);
3090
+ // 无命中显示「未找到」。纯视图态——不碰 markdown/revision。
3091
+ searchOpen ? (0, react_jsx_runtime.jsxs)("div", { style: S.searchBar, children: [
3092
+ (0, react_jsx_runtime.jsx)("input", {
3093
+ ref: searchInputRef,
3094
+ type: "text",
3095
+ value: searchQuery,
3096
+ placeholder: "搜索节点…",
3097
+ "aria-label": "搜索当前脑图的节点文字",
3098
+ title: "搜索当前脑图的节点文字(Enter 下一个,Shift+Enter 上一个,Esc 关闭)",
3099
+ style: S.searchInput,
3100
+ onChange: onQueryChange,
3101
+ onKeyDown: (e) => {
3102
+ if (e.key === "Enter") {
3103
+ e.preventDefault();
3104
+ stepSearch(e.shiftKey ? -1 : 1);
3105
+ } else if (e.key === "ArrowDown") {
3106
+ e.preventDefault();
3107
+ stepSearch(1);
3108
+ } else if (e.key === "ArrowUp") {
3109
+ e.preventDefault();
3110
+ stepSearch(-1);
3111
+ }
3112
+ },
3113
+ }),
3114
+ (0, react_jsx_runtime.jsx)("span", { style: S.searchCount, "aria-live": "polite", children: searchMatches.length === 0
3115
+ ? (searchQuery.trim() ? "未找到" : "0 / 0")
3116
+ : `${searchIndexSafe >= 0 ? searchIndexSafe + 1 : 0} / ${searchMatches.length}` }),
3117
+ (0, react_jsx_runtime.jsx)("button", {
3118
+ type: "button",
3119
+ title: "上一个匹配(Shift+Enter)",
3120
+ "aria-label": "上一个匹配",
3121
+ style: zoomBtnStyle("sprev", searchMatches.length === 0),
3122
+ disabled: searchMatches.length === 0,
3123
+ onClick: () => stepSearch(-1),
3124
+ onMouseEnter: () => setHover("sprev"),
3125
+ onMouseLeave: () => setHover((h) => (h === "sprev" ? null : h)),
3126
+ children: "↑",
3127
+ }),
3128
+ (0, react_jsx_runtime.jsx)("button", {
3129
+ type: "button",
3130
+ title: "下一个匹配(Enter)",
3131
+ "aria-label": "下一个匹配",
3132
+ style: zoomBtnStyle("snext", searchMatches.length === 0),
3133
+ disabled: searchMatches.length === 0,
3134
+ onClick: () => stepSearch(1),
3135
+ onMouseEnter: () => setHover("snext"),
3136
+ onMouseLeave: () => setHover((h) => (h === "snext" ? null : h)),
3137
+ children: "↓",
3138
+ }),
3139
+ (0, react_jsx_runtime.jsx)("button", {
3140
+ type: "button",
3141
+ title: "关闭搜索(Esc)",
3142
+ "aria-label": "关闭搜索",
3143
+ style: zoomBtnStyle("sclose", false),
3144
+ onClick: closeSearch,
3145
+ onMouseEnter: () => setHover("sclose"),
3146
+ onMouseLeave: () => setHover((h) => (h === "sclose" ? null : h)),
3147
+ children: "✕",
3148
+ }),
3149
+ ] }) : null,
2586
3150
  // 017 节点右键菜单:标题行(节点主题)+ 复制全文/复制为图片/导出为
2587
3151
  // 图片三动作 + 错误行。复用目录树菜单容器样式(fixed 定位,left/top = 视口坐标)。
2588
3152
  nodeMenu ? (0, react_jsx_runtime.jsxs)("div", {
@@ -2692,6 +3256,7 @@ window.__ModuleLoader__.load({
2692
3256
  // settings——面板常驻不卸载,光靠 visible 变化会漏掉「开着面板改设置」。
2693
3257
  const settingsStamp = react.useSyncExternalStore(settingsBus.subscribe, settingsBus.get);
2694
3258
  const [theme, setTheme] = react.useState({ lineStyle: "elbow", cardStyle: "rounded", colorTheme: "ocean", growthAnimation: true });
3259
+ const [approvalState, setApprovalState] = react.useState(null);
2695
3260
  react.useEffect(() => {
2696
3261
  if (!visible) return;
2697
3262
  if (!mindmapFace || typeof mindmapFace.readSettings !== "function") return;
@@ -2708,6 +3273,26 @@ window.__ModuleLoader__.load({
2708
3273
  // 读设置失败:保持当前主题
2709
3274
  });
2710
3275
  }, [visible, settingsStamp, mindmapFace]);
3276
+ react.useEffect(() => {
3277
+ let alive = true;
3278
+ setApprovalState(null);
3279
+ if (!visible || !sessionId || !mindmapFace || typeof mindmapFace.readApprovalStatus !== "function") return () => { alive = false; };
3280
+ mindmapFace.readApprovalStatus(sessionId).then((value) => {
3281
+ if (alive) setApprovalState(value);
3282
+ }).catch(() => {
3283
+ if (alive) setApprovalState(null);
3284
+ });
3285
+ return () => { alive = false; };
3286
+ }, [visible, sessionId, mindmapFace, settingsStamp, nodesVersion]);
3287
+ async function revokeApproval() {
3288
+ if (!sessionId || !mindmapFace || typeof mindmapFace.revokeApproval !== "function") return;
3289
+ try {
3290
+ const value = await mindmapFace.revokeApproval(sessionId);
3291
+ setApprovalState(value);
3292
+ } catch {
3293
+ // 撤销失败不改变当前状态,避免给出虚假的成功提示。
3294
+ }
3295
+ }
2711
3296
 
2712
3297
  // 013 目录树 tab:常驻第一个 tab(TREE_TAB 哨兵,永不与绝对路径撞名)。
2713
3298
  const TREE_TAB = "__tree__";
@@ -2719,6 +3304,10 @@ window.__ModuleLoader__.load({
2719
3304
  const [exporting, setExporting] = react.useState(false);
2720
3305
  const [exportError, setExportError] = react.useState("");
2721
3306
  const [filledHint, setFilledHint] = react.useState("");
3307
+ // 032 复制全文:copying = 写剪贴板进行中;copiedOk = 成功短反馈
3308
+ //(按钮文案短暂变「已复制 ✓」约 2s;失败复用 exportError 展示位)。
3309
+ const [copying, setCopying] = react.useState(false);
3310
+ const [copiedOk, setCopiedOk] = react.useState(false);
2722
3311
  // fsTree:nodes = {path → 节点}, expanded = {path → true}, loading = {path → true}。
2723
3312
  const [fsTree, setFsTree] = react.useState({ nodes: {}, expanded: {}, loading: {}, cwd: null, error: null });
2724
3313
  // 会话切换时递增,使旧请求的异步回包不能写入新会话的目录树。
@@ -2784,27 +3373,15 @@ window.__ModuleLoader__.load({
2784
3373
  ? matchDocError(merged, doc.path, localErrorBaseRef.current)
2785
3374
  : null;
2786
3375
 
2787
- // AI 自动打开:create/open 代表用户明确的「创建 / 打开 / 查看」意图。
2788
- // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
2789
- // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
2790
- const seen = react.useRef(null);
2791
- react.useEffect(() => {
2792
- const targetPath = autoOpenTarget(merged, seen.current);
2793
- seen.current = openingEventKeys(merged);
2794
- if (targetPath) {
2795
- onAutoOpen();
2796
- setHiddenPath(null);
2797
- setCurrentPath(targetPath);
2798
- setView("mindmap");
2799
- }
2800
- }, [merged]);
2801
-
2802
3376
  // 013「所见即所编」焦点同步:AI 焦点 = 快照里最新工具结果的文档路径;
2803
3377
  // 脑图视图激活且其文档 ≠ 焦点时,仅在草稿为空时自动发送,让 AI
2804
3378
  // 跟上用户眼睛看的那颗脑图,又不覆盖用户正在编辑的消息。
2805
3379
  const focusPath = docs.order.length > 0 ? docs.order[docs.order.length - 1] : null;
2806
3380
  const focusSentRef = react.useRef(null);
2807
3381
  // 所有这些状态都属于会话,不得让 A 会话的在途打开/目录结果遗留到 B。
3382
+ // 这个 effect 必须先于自动打开 effect 声明:React 会按声明顺序运行同一轮
3383
+ // effect,否则清理会把刚自动选中的脑图又切回「目录」。
3384
+ const seen = react.useRef(null);
2808
3385
  react.useEffect(() => {
2809
3386
  setLocalDocs({});
2810
3387
  setCurrentPath(null);
@@ -2816,8 +3393,24 @@ window.__ModuleLoader__.load({
2816
3393
  setFilledHint("");
2817
3394
  localErrorBaseRef.current = null;
2818
3395
  focusSentRef.current = null;
3396
+ seen.current = null;
2819
3397
  prevIdsRef.current = { path: null, ids: null };
2820
3398
  }, [sessionId]);
3399
+
3400
+ // AI 自动打开:create/open 代表用户明确的「创建 / 打开 / 查看」意图。
3401
+ // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
3402
+ // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
3403
+ react.useEffect(() => {
3404
+ const targetPath = autoOpenTarget(merged, seen.current);
3405
+ seen.current = openingEventKeys(merged);
3406
+ if (targetPath) {
3407
+ onAutoOpen();
3408
+ setHiddenPath(null);
3409
+ setCurrentPath(targetPath);
3410
+ setView("mindmap");
3411
+ }
3412
+ }, [merged, sessionId]);
3413
+
2821
3414
  react.useEffect(() => {
2822
3415
  if (!visible) return; // 面板/Tab 不可见时不自动发消息
2823
3416
  if (!sessionId) return;
@@ -2843,6 +3436,24 @@ window.__ModuleLoader__.load({
2843
3436
  setExporting(false);
2844
3437
  }
2845
3438
  }
3439
+
3440
+ // 032 复制全文:当前脑图的 Markdown 原文写入系统剪贴板。内容直接取
3441
+ // doc.content(tree 即由它解析而来),不从树结构反向序列化——零信息
3442
+ // 损失(标题/列表/表格/原文空白原样保留),与参考实现实测路径一致。
3443
+ async function onCopyText() {
3444
+ if (!doc || doc.op === "local" || copying) return;
3445
+ setCopying(true);
3446
+ setExportError("");
3447
+ try {
3448
+ await copyPlainText(doc.content);
3449
+ setCopiedOk(true);
3450
+ setTimeout(() => setCopiedOk(false), 2000);
3451
+ } catch (error) {
3452
+ setExportError(String(error?.message ?? error));
3453
+ } finally {
3454
+ setCopying(false);
3455
+ }
3456
+ }
2846
3457
  //#region 013 目录树 tab:懒加载树 + 把指令填进聊天输入框
2847
3458
  // 草稿保护:确实读到非空草稿才让路(改走剪贴板),读不到就按既有
2848
3459
  // 行为直填直发——宿主不暴露草稿时不能把功能整个卡死。
@@ -2893,26 +3504,14 @@ window.__ModuleLoader__.load({
2893
3504
  });
2894
3505
  }
2895
3506
 
2896
- // 左键点 .md(013 作者定稿):① tab 秒建(本地占位,不显示内容,body
2897
- // 显示加载动效);② 同时填「用 mindmap_open 打开 <rel>」并 submit 让 AI
2898
- // 就位——AI 工具结果到达后同 path 覆盖占位,节点才渲染;随后用户接着
2899
- // 说即可继续编辑(002 数据流不变:内容只来自 AI 工具结果)。
2900
- function openMindmap(entry) {
3507
+ // 左键点 .md:先通过只读 document 路由显示文件,再在草稿为空时提交
3508
+ // mindmap_open 让 AI 接管编辑;已有草稿永不被覆盖。
3509
+ async function openMindmap(entry) {
2901
3510
  const text = `用 mindmap_open 打开 ${relPathWithin(fsTree.cwd, entry.path, entry.name)}`;
2902
- // 有未发送草稿:不建占位、不抢输入框,改把指令交给用户自己发。
2903
- if (draftBlocked()) {
2904
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2905
- navigator.clipboard.writeText(text).catch(() => {});
2906
- setFilledHint("检测到未发送的草稿,已保留;打开指令已复制到剪贴板,粘贴发送即可");
2907
- } else {
2908
- setFilledHint(`检测到未发送的草稿,已保留。请手动发送:${text}`);
2909
- }
2910
- return;
2911
- }
2912
3511
  // 016:记录点击时刻的错误基线(errorByPath 与 latestError 的全部
2913
3512
  // 事件键)——只有其后新出现的错误才归因本次打开,旧错误不打扰。
2914
3513
  localErrorBaseRef.current = errorEventKeys(merged);
2915
- // ① 本地占位:脑图 tab 立即切过去、内容为空(op:"local" 触发加载态);
3514
+ // ① 本地占位:脑图 tab 立即切过去,随后由只读路由填充内容;
2916
3515
  // 新打开的脑图替换旧的那颗(单脑图模式)。
2917
3516
  setHiddenPath(null);
2918
3517
  setCurrentPath(entry.path);
@@ -2928,19 +3527,34 @@ window.__ModuleLoader__.load({
2928
3527
  renamedFrom: null,
2929
3528
  },
2930
3529
  }));
2931
- // ② AI 就位:填指令并直接提交(失败降级剪贴板)。
2932
- if (submitChatCommand(text)) {
2933
- // 标记已发,避免焦点同步 effect 对同一路径重复发送。
3530
+ try {
3531
+ if (!mindmapFace || typeof mindmapFace.readDocument !== "function") throw new Error("只读文档能力不可用");
3532
+ const loaded = await mindmapFace.readDocument(sessionId, relPathWithin(fsTree.cwd, entry.path, entry.name));
3533
+ setLocalDocs((prev) => {
3534
+ const current = prev[entry.path];
3535
+ if (!current || current.op !== "local") return prev;
3536
+ return { ...prev, [entry.path]: { ...current, op: "local-read", content: String(loaded.content ?? ""), revision: loaded.revision ?? null } };
3537
+ });
3538
+ setFilledHint(`已直接打开「${entry.name}」;需要 AI 编辑时可继续发送打开指令`);
3539
+ } catch (error) {
3540
+ setLocalDocs((prev) => {
3541
+ const current = prev[entry.path];
3542
+ if (!current || current.op !== "local") return prev;
3543
+ return { ...prev, [entry.path]: { ...current, error: String(error?.message ?? error) } };
3544
+ });
3545
+ setFilledHint("直接读取失败,可重试或让 AI 打开该文件");
3546
+ }
3547
+ // ② 草稿为空时再让 AI 接管焦点;已有草稿绝不覆盖。
3548
+ if (!draftBlocked() && submitChatCommand(text)) {
2934
3549
  focusSentRef.current = entry.path;
2935
- setFilledHint(`已让 AI 打开「${entry.name}」,在聊天里继续说就能继续编辑`);
2936
3550
  return;
2937
3551
  }
2938
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2939
- navigator.clipboard.writeText(text).catch(() => {});
2940
- setFilledHint("已复制指令到剪贴板,请粘贴到聊天输入框");
2941
- return;
3552
+ if (draftBlocked()) {
3553
+ if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
3554
+ navigator.clipboard.writeText(text).catch(() => {});
3555
+ setFilledHint("检测到未发送的草稿,文件已打开;打开指令已复制到剪贴板");
3556
+ } else setFilledHint(`文件已打开,请手动发送:${text}`);
2942
3557
  }
2943
- setFilledHint(text);
2944
3558
  }
2945
3559
 
2946
3560
  /** 016 加载态恢复:错误/超时后重试——重发打开指令并重启看门狗。 */
@@ -3194,9 +3808,12 @@ window.__ModuleLoader__.load({
3194
3808
  function renderLoading() {
3195
3809
  // 016 三态流转:加载中 →(错误 | 超时)——错误优先于超时;失败态
3196
3810
  // 提供「重试」一键重发打开指令(openMindmap 同款通路 + 降级链)。
3197
- const failed = Boolean(docError) || openTimedOut;
3811
+ const localReadError = doc && doc.op === "local" && doc.error ? doc.error : null;
3812
+ const failed = Boolean(docError || localReadError) || openTimedOut;
3198
3813
  const message = docError
3199
3814
  ? `AI 打开失败:${docError.message}`
3815
+ : localReadError
3816
+ ? `读取失败:${localReadError}`
3200
3817
  : openTimedOut
3201
3818
  ? "等待 AI 打开超时(约 30 秒无结果)"
3202
3819
  : "AI 正在打开脑图…";
@@ -3308,9 +3925,25 @@ window.__ModuleLoader__.load({
3308
3925
  onClick: onExport,
3309
3926
  children: exporting ? "导出中…" : "导出图片",
3310
3927
  });
3928
+ // 032 复制全文按钮(两种模式共用):整篇 Markdown 原文写系统剪贴板,插在
3929
+ // 导出按钮左侧;disabled 语义与导出一致(无树/复制中/本地占位不可复制)。
3930
+ const copyBtn = (0, react_jsx_runtime.jsx)("button", {
3931
+ type: "button",
3932
+ style: S.action,
3933
+ disabled: !tree || copying || (doc && doc.op === "local"),
3934
+ onClick: onCopyText,
3935
+ title: "把当前脑图的 Markdown 原文复制到剪贴板",
3936
+ children: copying ? "复制中…" : copiedOk ? "已复制 ✓" : "复制全文",
3937
+ });
3311
3938
  const exportErrorSpan = exportError
3312
3939
  ? (0, react_jsx_runtime.jsx)("span", { style: { color: "var(--dsw-alias-label-error)", fontSize: "12px" }, children: exportError })
3313
3940
  : null;
3941
+ const approvalControls = approvalState && approvalState.mode === "session"
3942
+ ? (0, react_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px", color: "var(--dsw-alias-label-tertiary)", fontSize: "12px" }, children: [
3943
+ (0, react_jsx_runtime.jsx)("span", { title: "授权按当前会话与脑图文件隔离", children: approvalState.grantedDocuments > 0 ? "本会话已允许写入" : "本会话尚未授权" }),
3944
+ (0, react_jsx_runtime.jsx)("button", { type: "button", style: S.action, disabled: approvalState.grantedDocuments === 0, onClick: revokeApproval, children: "撤销授权" }),
3945
+ ] })
3946
+ : null;
3314
3947
 
3315
3948
  // 027 目录/列表标签文案:sidebar 模式叫「脑图列表」,standalone 模式叫「目录」。
3316
3949
  const treeTabLabel = variant === "sidebar" ? "脑图列表" : "目录";
@@ -3361,9 +3994,11 @@ window.__ModuleLoader__.load({
3361
3994
  }),
3362
3995
  ],
3363
3996
  }, shown) : null,
3364
- // 导出按钮 + 错误推到行尾。
3997
+ // 复制/导出按钮 + 错误推到行尾。
3365
3998
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3999
+ approvalControls,
3366
4000
  exportErrorSpan,
4001
+ copyBtn,
3367
4002
  exportBtn,
3368
4003
  ] }),
3369
4004
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
@@ -3398,6 +4033,8 @@ window.__ModuleLoader__.load({
3398
4033
  const wsHeaderChildren = [
3399
4034
  (0, react_jsx_runtime.jsxs)("div", { style: S.headerTop, children: [
3400
4035
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
4036
+ approvalControls,
4037
+ copyBtn,
3401
4038
  exportBtn,
3402
4039
  exportErrorSpan,
3403
4040
  // 关闭按钮:仅独立 fixed 壳提供 onClose(BS Tab 自带关闭)。
@@ -3500,17 +4137,21 @@ window.__ModuleLoader__.load({
3500
4137
  const [panelWidth, setPanelWidth] = react.useState(() => {
3501
4138
  try {
3502
4139
  const saved = Number(localStorage.getItem(WIDTH_KEY));
3503
- if (Number.isFinite(saved) && saved >= 280) return Math.min(saved, Math.round(window.innerWidth * 0.8));
4140
+ const max = Math.round(window.innerWidth * 0.8);
4141
+ const min = Math.min(280, max);
4142
+ if (Number.isFinite(saved)) return Math.min(max, Math.max(min, saved));
3504
4143
  } catch {
3505
4144
  // localStorage 不可用:走默认
3506
4145
  }
3507
- return Math.round(window.innerWidth * 0.42);
4146
+ const max = Math.round(window.innerWidth * 0.8);
4147
+ return Math.min(max, Math.max(Math.min(280, max), Math.round(window.innerWidth * 0.42)));
3508
4148
  });
3509
4149
  react.useEffect(() => {
3510
4150
  const clamp = () => {
3511
4151
  setPanelWidth((prev) => {
3512
4152
  const max = Math.round(window.innerWidth * 0.8);
3513
- return prev > max ? max : prev;
4153
+ const min = Math.min(280, max);
4154
+ return Math.min(max, Math.max(min, prev));
3514
4155
  });
3515
4156
  };
3516
4157
  clamp();
@@ -3529,7 +4170,9 @@ window.__ModuleLoader__.load({
3529
4170
  if (!mindmapFace || typeof mindmapFace.readSettings !== "function") return;
3530
4171
  mindmapFace.readSettings().then((v) => {
3531
4172
  const pct = v && typeof v.defaultPanelWidth === "number" ? Math.min(80, Math.max(20, v.defaultPanelWidth)) : 42;
3532
- const px = Math.round(window.innerWidth * pct / 100);
4173
+ const max = Math.round(window.innerWidth * 0.8);
4174
+ const min = Math.min(280, max);
4175
+ const px = Math.min(max, Math.max(min, Math.round(window.innerWidth * pct / 100)));
3533
4176
  setPanelWidth((prev) => (Math.abs(prev - px) < 2 ? prev : px));
3534
4177
  }).catch(() => {
3535
4178
  // 读设置失败:保持 42% 默认
@@ -3543,7 +4186,8 @@ window.__ModuleLoader__.load({
3543
4186
  const onMove = (ev) => {
3544
4187
  if (!dragStateRef.current) return;
3545
4188
  const max = Math.round(window.innerWidth * 0.8);
3546
- const next = Math.min(max, Math.max(280, dragStateRef.current.startWidth + (dragStateRef.current.startX - ev.clientX)));
4189
+ const min = Math.min(280, max);
4190
+ const next = Math.min(max, Math.max(min, dragStateRef.current.startWidth + (dragStateRef.current.startX - ev.clientX)));
3547
4191
  dragStateRef.current.latestWidth = next;
3548
4192
  setPanelWidth(next);
3549
4193
  };
@@ -4097,6 +4741,45 @@ window.__ModuleLoader__.load({
4097
4741
  }
4098
4742
  return parsed.value;
4099
4743
  };
4744
+ // Read-only fast path for directory clicks. Rendering a document must not
4745
+ // wait for a model turn just to fetch bytes; the empty-draft path may still
4746
+ // ask the AI to take over editing after the document is visible.
4747
+ face.readDocument = async (sessionId, path) => {
4748
+ const response = await fetch("/mindmap/api/document", {
4749
+ method: "POST",
4750
+ headers: { "content-type": "application/json" },
4751
+ body: JSON.stringify({ sessionId, path }),
4752
+ });
4753
+ const parsed = await response.json().catch(() => null);
4754
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4755
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4756
+ }
4757
+ return parsed.value;
4758
+ };
4759
+ face.readApprovalStatus = async (sessionId) => {
4760
+ const response = await fetch("/mindmap/api/approval", {
4761
+ method: "POST",
4762
+ headers: { "content-type": "application/json" },
4763
+ body: JSON.stringify({ sessionId, action: "status" }),
4764
+ });
4765
+ const parsed = await response.json().catch(() => null);
4766
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4767
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4768
+ }
4769
+ return parsed.value;
4770
+ };
4771
+ face.revokeApproval = async (sessionId) => {
4772
+ const response = await fetch("/mindmap/api/approval", {
4773
+ method: "POST",
4774
+ headers: { "content-type": "application/json" },
4775
+ body: JSON.stringify({ sessionId, action: "revoke" }),
4776
+ });
4777
+ const parsed = await response.json().catch(() => null);
4778
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4779
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4780
+ }
4781
+ return parsed.value;
4782
+ };
4100
4783
 
4101
4784
  // 015 设置面板:connection/remote 在客户端插件启动后才可能就绪,不能在
4102
4785
  // apply 时捕获一次 undefined;每次读写前重新查取,服务晚到也能恢复。
@@ -4143,10 +4826,16 @@ window.__ModuleLoader__.load({
4143
4826
  if (!api) {
4144
4827
  throw new Error("settings service unavailable");
4145
4828
  }
4829
+ // 引擎侧 legacy 开关 requireApproval:false 等价于「关闭普通确认」,优先级
4830
+ // 高于 approvalMode。面板显式选择「每次确认」或「本会话一次」时同时解除
4831
+ // 它,否则该选择会被 host config 里的开关静默覆盖(保存后弹回 off)。
4832
+ const payload = patch && typeof patch === "object" && patch.approvalMode && patch.approvalMode !== "off"
4833
+ ? { ...patch, requireApproval: true }
4834
+ : patch;
4146
4835
  if (api.kind === "remote" || api.settings.update.length !== 1) {
4147
- await api.settings.update("mindmap", patch, undefined);
4836
+ await api.settings.update("mindmap", payload, undefined);
4148
4837
  } else {
4149
- await api.settings.update({ ns: "mindmap", patch });
4838
+ await api.settings.update({ ns: "mindmap", patch: payload });
4150
4839
  }
4151
4840
  };
4152
4841
 
@@ -4205,6 +4894,11 @@ window.__ModuleLoader__.load({
4205
4894
  countDescendants,
4206
4895
  pruneCollapsed,
4207
4896
  TreeRow,
4897
+ // 035 节点搜索:命中计算 / 下标步进(环绕)/ 命中保持 / 祖先展开(供测试)。
4898
+ searchTreeMatches,
4899
+ stepMatchIndex,
4900
+ reconcileActiveMatch,
4901
+ expandAncestorsFor,
4208
4902
  // 019 皮肤层与血肉层纯函数(供测试)。
4209
4903
  resolveToken,
4210
4904
  resolveNodeStyle,
@@ -4224,6 +4918,9 @@ window.__ModuleLoader__.load({
4224
4918
  stepZoom,
4225
4919
  fitZoom,
4226
4920
  focusZoom,
4921
+ // 033 点击聚焦跳变钳制 + 保视野拉回位移(供测试)。
4922
+ clampFocusJump,
4923
+ edgePullOffsets,
4227
4924
  // 021 画布平移手势判定(供测试)。
4228
4925
  PAN,
4229
4926
  shouldStartPan,