wendang-react 0.6.3 → 0.6.5

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 (120) hide show
  1. package/NOTICE.md +1 -1
  2. package/README.md +133 -1
  3. package/dist/bindings/yjs.js +1 -5
  4. package/dist/chunks/AnchoredPanel-C7jMoPze.js +1 -0
  5. package/dist/chunks/DocumentExportMenu-CUMsgq3w.js +2 -0
  6. package/dist/chunks/Dropdown-D98tXfe0.js +3 -0
  7. package/dist/chunks/MindMapCanvas-C46Q5JBU.js +163 -0
  8. package/dist/chunks/MindMapViewer-C9zxZIW8.js +13 -0
  9. package/dist/chunks/SpreadsheetViewer-CoQ4VIgj.js +23 -0
  10. package/dist/chunks/code-highlight-BmaqTe1m.js +1 -30
  11. package/dist/chunks/code-highlight-engine-BFDzDPzy.js +1 -40
  12. package/dist/chunks/comment-hint-BhUxKjKK.js +14 -0
  13. package/dist/chunks/composition-state-Bl-U1R_2.js +1 -40
  14. package/dist/chunks/extensions-BefQ1tDm.js +14 -0
  15. package/dist/chunks/fuzzy-match-DYQR-4w2.js +1 -89
  16. package/dist/chunks/hooks-C53Dp0pr.js +1 -35
  17. package/dist/chunks/i18n-B0kCsIjc.js +2 -0
  18. package/dist/chunks/index-COeA2QcQ.js +15 -0
  19. package/dist/chunks/katex-WjrodtTU.js +1 -71
  20. package/dist/chunks/locale-DWpIJ_9X.js +1 -0
  21. package/dist/chunks/mind-map-controller-Ce76mETT.js +1 -0
  22. package/dist/chunks/mind-map-delete-CVsxdXfs.js +1 -31
  23. package/dist/chunks/mind-map-input-CEWRz_t6.js +1 -43
  24. package/dist/chunks/mind-topic-text-BHXkxexr.js +30 -0
  25. package/dist/chunks/popover-placement-D3xVYdkt.js +1 -47
  26. package/dist/chunks/worksheet-engine-c84sdD4N.js +1 -0
  27. package/dist/chunks/worksheet-preview-DsDVWxIM.js +1 -129
  28. package/dist/document/viewer.js +30 -289
  29. package/dist/document.js +120 -3811
  30. package/dist/export/json.js +1 -5
  31. package/dist/export/markdown.js +1 -2
  32. package/dist/export/mindmap.js +1 -2
  33. package/dist/export/pdf.js +1 -6
  34. package/dist/export/word.js +1 -2
  35. package/dist/export.js +1 -2
  36. package/dist/i18n.js +1 -0
  37. package/dist/index.js +1 -8
  38. package/dist/locales/en-US.js +1 -0
  39. package/dist/locales/es-ES.js +1 -0
  40. package/dist/locales/ja-JP.js +1 -0
  41. package/dist/locales/ko-KR.js +1 -0
  42. package/dist/locales/zh-CN.js +1 -0
  43. package/dist/locales/zh-TW.js +1 -0
  44. package/dist/mindmap/viewer.js +1 -6
  45. package/dist/mindmap.js +3 -123
  46. package/dist/shared.js +1 -52
  47. package/dist/spreadsheet/viewer.js +1 -5
  48. package/dist/spreadsheet/xlsx.js +1 -299
  49. package/dist/spreadsheet.js +2 -120
  50. package/dist/styles/callout.css +1 -34
  51. package/dist/styles/code-block.css +1 -58
  52. package/dist/styles/content-style.css +1 -619
  53. package/dist/styles/content-tokens.css +1 -29
  54. package/dist/styles/editor-interaction.css +1 -621
  55. package/dist/styles/file-video.css +1 -12
  56. package/dist/styles/image-preview.css +1 -103
  57. package/dist/styles/mind-map-block.css +1 -14
  58. package/dist/styles/mind-map-canvas.css +1 -80
  59. package/dist/styles/mind-map-comments.css +1 -93
  60. package/dist/styles/mind-map-details.css +1 -7
  61. package/dist/styles/mind-map-preview.css +1 -7
  62. package/dist/styles/mind-map-topic.css +1 -112
  63. package/dist/styles/page-picker.css +1 -47
  64. package/dist/styles/renderer.css +1 -45
  65. package/dist/styles/spreadsheet-editor.css +1 -3
  66. package/dist/styles/tokens.css +1 -142
  67. package/dist/styles/video-dialog.css +1 -41
  68. package/dist/styles/video-embed.css +1 -35
  69. package/dist/styles.css +1 -2655
  70. package/dist/types/editor/BlockAffordance.d.ts +5 -2
  71. package/dist/types/editor/CalloutView.d.ts +2 -1
  72. package/dist/types/editor/ImagePreview.d.ts +1 -1
  73. package/dist/types/editor/PagePicker.d.ts +1 -1
  74. package/dist/types/editor/extensions.d.ts +4 -1
  75. package/dist/types/engine/editor/block-commands.d.ts +1 -1
  76. package/dist/types/engine/editor/block-menu-hover.d.ts +16 -0
  77. package/dist/types/engine/editor/extensions/locale.d.ts +3 -0
  78. package/dist/types/engine/editor/nodes/image-nodeview.d.ts +1 -1
  79. package/dist/types/engine/editor/video-block-controls.d.ts +13 -0
  80. package/dist/types/engine/host.d.ts +60 -2
  81. package/dist/types/engine/renderer/attachments.d.ts +3 -3
  82. package/dist/types/engine/shared/video-feedback.d.ts +1 -1
  83. package/dist/types/engine/worksheets/worksheet-engine.d.ts +1 -0
  84. package/dist/types/engine/worksheets/worksheet-xlsx.d.ts +6 -1
  85. package/dist/types/host-types.d.ts +2 -60
  86. package/dist/types/host.d.ts +8 -1
  87. package/dist/types/i18n.d.ts +3 -0
  88. package/dist/types/index.d.ts +2 -0
  89. package/dist/types/locales/en-US.d.ts +1 -0
  90. package/dist/types/locales/es-ES.d.ts +1 -0
  91. package/dist/types/locales/ja-JP.d.ts +1 -0
  92. package/dist/types/locales/ko-KR.d.ts +1 -0
  93. package/dist/types/locales/zh-CN.d.ts +1 -0
  94. package/dist/types/locales/zh-TW.d.ts +1 -0
  95. package/dist/types/renderer/media.d.ts +2 -1
  96. package/dist/types/spreadsheet/xlsx.d.ts +1 -1
  97. package/dist/types/wui/Dropdown.d.ts +2 -1
  98. package/dist/types/wui/index.d.ts +2 -1
  99. package/integrity.json +3140 -0
  100. package/package.json +15 -5
  101. package/verify-integrity.mjs +138 -0
  102. package/dist/chunks/AnchoredPanel-Cv4RURwF.js +0 -68
  103. package/dist/chunks/DocumentExportMenu-BrGipZ59.js +0 -75
  104. package/dist/chunks/MindMapCanvas-tkFBBs4g.js +0 -2090
  105. package/dist/chunks/MindMapViewer-DJrryb2Y.js +0 -180
  106. package/dist/chunks/SpreadsheetViewer-DxCxIUx_.js +0 -163
  107. package/dist/chunks/comment-hint-B9qcrqvn.js +0 -296
  108. package/dist/chunks/extensions-ByORRoRa.js +0 -4210
  109. package/dist/chunks/host-C-V688Rq.js +0 -197
  110. package/dist/chunks/index-DdfMnva8.js +0 -726
  111. package/dist/chunks/mind-map-controller-B6SxK3GZ.js +0 -479
  112. package/dist/chunks/mind-topic-text-DSyb95vL.js +0 -446
  113. package/dist/chunks/nodes-iKqTGr_N.js +0 -291
  114. package/dist/chunks/worksheet-engine-TJ54m0KC.js +0 -125
  115. package/third-party-notices/wendang-export@0.6.0-NOTICE.md.txt +0 -51
  116. package/third-party-notices/wendang-export@0.6.1-LICENSE.txt +0 -21
  117. package/third-party-notices/wendang-export@0.6.2-LICENSE.txt +0 -21
  118. package/third-party-notices/wendang-export@0.6.2-NOTICE.md.txt +0 -70
  119. /package/third-party-notices/{wendang-export@0.6.0-LICENSE.txt → wendang-export@0.6.4-LICENSE.txt} +0 -0
  120. /package/third-party-notices/{wendang-export@0.6.1-NOTICE.md.txt → wendang-export@0.6.4-NOTICE.md.txt} +0 -0
@@ -1,2090 +0,0 @@
1
- "use client";
2
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
- import { useState, useRef, useEffect, useMemo } from "react";
4
- import { textDifference, mindMapTree, layoutMindMap, MIND_MAP_PALETTE, mindMapDescendants as mindMapDescendants$1, projectMindSideMove, mindMapBranchSides, mindMapOutline, mindRelationPaths, mindMapMarkdown, mindMapSvg, mindMapToJson, MIND_MAP_MAX_TOPICS } from "wendang/mindmap";
5
- import { TEXT_COLORS, HIGHLIGHT_COLORS, mindTopicLineHeight, MIND_TOPIC_FONT, readableTextColor } from "wendang/shared";
6
- import { MIND_ICONS, MIND_COLORS, MIND_BACKGROUNDS, branchModel, searchMindMap, parseMindMapImport, importBranch, mindMapTemplate, parseMindBranch, ancestorIds } from "wendang/internal/mind-map-phase2";
7
- import { normalizeMindFolds, firstLevelMindFolds } from "wendang/internal/mind-map-folding";
8
- import { p as planMindTopicDeletion } from "./mind-map-delete-CVsxdXfs.js";
9
- import { mindMapDescendants } from "wendang/internal/mind-map";
10
- import { m as mindCanvasShortcut, s as selectMindTopic } from "./mind-map-input-CEWRz_t6.js";
11
- import { b as useContentHost, a as useContentContext } from "./host-C-V688Rq.js";
12
- import { createPortal } from "react-dom";
13
- import { u as useLatest } from "./hooks-C53Dp0pr.js";
14
- import { a as WButton, c as WDialog, W as WSelect, d as WAlert } from "./index-DdfMnva8.js";
15
- import { T as TopicLabel, A as AttachmentImage } from "./mind-topic-text-DSyb95vL.js";
16
- import { A as AnchoredPanel } from "./AnchoredPanel-Cv4RURwF.js";
17
- function mindMapDrop(model, drawing, id, point, allowSide = true) {
18
- const source = drawing.nodes.find((t) => t.id === id), root = drawing.nodes.find((t) => t.id === model.rootId);
19
- if (!source || !root || id === model.rootId) return null;
20
- const excluded = mindMapDescendants(model, id), { x, y } = point;
21
- const candidates = drawing.nodes.filter((t) => !excluded.has(t.id)).map((t) => ({
22
- t,
23
- distance: Math.hypot(x - t.x - t.width / 2, y - t.y - t.height / 2)
24
- })).sort((a, b) => a.distance - b.distance);
25
- const best = candidates[0];
26
- const side = x < root.x + root.width / 2 - 24 ? -1 : x > root.x + root.width / 2 + 24 ? 1 : null;
27
- const crossing = allowSide && model.layout !== "down" && side !== null && side !== source.side;
28
- const nearNode = best && best.t.id !== root.id && x >= best.t.x - 18 && x <= best.t.x + best.t.width + 18 && y >= best.t.y - 18 && y <= best.t.y + best.t.height + 18;
29
- if (nearNode || !crossing && best && best.distance < Math.max(best.t.width, 130)) {
30
- return { kind: "node", id: best.t.id, mode: best.t.id === root.id ? "child" : y < best.t.y + 10 ? "before" : y > best.t.y + best.t.height - 10 ? "after" : "child" };
31
- }
32
- if (allowSide && model.layout !== "down" && side !== null && (crossing || source.parentId === root.id && model.layout === "both")) {
33
- const before = drawing.nodes.filter((t) => t.parentId === root.id && t.id !== id && t.side === side).find((t) => y < t.y + t.height / 2);
34
- return { kind: "side", id: root.id, mode: "side", side, ...before ? { beforeId: before.id } : {} };
35
- }
36
- return null;
37
- }
38
- function topicsInMarquee(topics, rect, previous = []) {
39
- const visible = new Set(topics.map((topic) => topic.id));
40
- const selected = new Set([...previous].filter((id) => visible.has(id)));
41
- if (rect.width <= 0 || rect.height <= 0) return selected;
42
- for (const topic of topics) {
43
- if (topic.x < rect.x + rect.width && topic.x + topic.width > rect.x && topic.y < rect.y + rect.height && topic.y + topic.height > rect.y) selected.add(topic.id);
44
- }
45
- return selected;
46
- }
47
- function MindMapComments({ pageId, blockId, topicId, topicLabel, canComment, onClose, onChanged }) {
48
- const host = useContentHost(), [items, setItems] = useState([]), [draft, setDraft] = useState(""), [error, setError] = useState(""), [busy, setBusy] = useState(false), [loading, setLoading] = useState(true);
49
- const [composer, setComposer] = useState(null), [confirmId, setConfirmId] = useState(null), [epoch, setEpoch] = useState(0);
50
- const alive = useRef(true), running = useRef(false);
51
- useEffect(() => {
52
- alive.current = true;
53
- return () => {
54
- alive.current = false;
55
- };
56
- }, []);
57
- useEffect(() => {
58
- let active = true;
59
- setDraft("");
60
- setComposer(null);
61
- setConfirmId(null);
62
- setError("");
63
- setLoading(true);
64
- if (!host.comments) {
65
- setLoading(false);
66
- return;
67
- }
68
- void host.comments.list(pageId).then((result) => {
69
- if (active) setItems(result.items.filter((item) => {
70
- var _a, _b;
71
- return ((_a = item.anchor) == null ? void 0 : _a.prefix) === `mind:${blockId}` && ((_b = item.anchor) == null ? void 0 : _b.suffix) === topicId;
72
- }));
73
- }).catch((error2) => {
74
- if (active) setError(String(error2));
75
- }).finally(() => {
76
- if (active) setLoading(false);
77
- });
78
- return () => {
79
- active = false;
80
- };
81
- }, [host.comments, pageId, blockId, topicId, epoch]);
82
- async function perform(action) {
83
- if (running.current) return;
84
- running.current = true;
85
- setBusy(true);
86
- setError("");
87
- try {
88
- await action();
89
- onChanged == null ? void 0 : onChanged();
90
- if (alive.current) {
91
- setDraft("");
92
- setComposer(null);
93
- setEpoch((value) => value + 1);
94
- }
95
- } catch (error2) {
96
- if (alive.current) setError(String(error2));
97
- } finally {
98
- running.current = false;
99
- if (alive.current) setBusy(false);
100
- }
101
- }
102
- const title = topicLabel.trim() ? `「${topicLabel.trim()}」` : "当前主题";
103
- const time = (value) => {
104
- const date = new Date(value);
105
- return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
106
- };
107
- function compose(item) {
108
- if (!composer || composer.id !== item.id) return null;
109
- const editing = composer.kind === "edit";
110
- return /* @__PURE__ */ jsxs("form", { className: "mind-comment__compose", onSubmit: (event) => {
111
- event.preventDefault();
112
- if (!composer.text.trim() || !editing && !canComment) return;
113
- void perform(() => editing ? host.comments.update(composer.id, composer.text.trim()) : host.comments.create(pageId, composer.text.trim(), composer.id));
114
- }, children: [
115
- /* @__PURE__ */ jsx("label", { className: "mind-comment__label", children: editing ? "正在编辑评论" : `回复 ${item.authorName}` }),
116
- /* @__PURE__ */ jsx("textarea", { "aria-label": editing ? "编辑主题讨论" : "回复主题讨论", rows: editing ? 3 : 2, maxLength: 5e3, value: composer.text, onChange: (event) => setComposer({ ...composer, text: event.target.value }) }),
117
- /* @__PURE__ */ jsxs("div", { className: "mind-comment__actions", children: [
118
- /* @__PURE__ */ jsx(WButton, { variant: "primary", loading: busy, disabled: !composer.text.trim(), htmlType: "submit", children: editing ? "保存" : "发表回复" }),
119
- /* @__PURE__ */ jsx(WButton, { onClick: () => setComposer(null), children: "取消" })
120
- ] })
121
- ] });
122
- }
123
- function comment(item, reply = false) {
124
- var _a, _b;
125
- const editing = (composer == null ? void 0 : composer.kind) === "edit" && composer.id === item.id;
126
- return /* @__PURE__ */ jsxs("article", { className: reply ? "mind-comment__reply" : "mind-comment", children: [
127
- /* @__PURE__ */ jsxs("header", { className: "mind-comment__head", children: [
128
- /* @__PURE__ */ jsx("strong", { children: item.authorName || "用户" }),
129
- /* @__PURE__ */ jsxs("span", { children: [
130
- time(item.createdAt),
131
- item.resolved ? " · 已解决" : ""
132
- ] })
133
- ] }),
134
- editing ? compose(item) : /* @__PURE__ */ jsx("p", { className: "mind-comment__body", children: item.deleted ? reply ? "回复已删除" : "评论已删除" : item.body }),
135
- !editing && /* @__PURE__ */ jsxs("div", { className: "mind-comment__actions", children: [
136
- item.canResolve && !reply && /* @__PURE__ */ jsx(WButton, { variant: "text", disabled: busy, onClick: () => void perform(() => host.comments.resolve(item.id, !item.resolved)), children: item.resolved ? "重新打开" : "标记解决" }),
137
- canComment && !item.deleted && !reply && /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => setComposer({ kind: "reply", id: item.id, text: "" }), children: "回复" }),
138
- ((_a = host.comments) == null ? void 0 : _a.update) && item.canEdit && /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => setComposer({ kind: "edit", id: item.id, text: item.body }), children: "编辑" }),
139
- item.canDelete && /* @__PURE__ */ jsx(WButton, { variant: "text", disabled: busy, onClick: () => setConfirmId(item.id), children: "删除" })
140
- ] }),
141
- !reply && ((_b = item.replies) == null ? void 0 : _b.map((child) => comment(child, true))),
142
- !editing && compose(item)
143
- ] }, item.id);
144
- }
145
- return /* @__PURE__ */ jsxs("aside", { className: "mind-comments", "aria-label": "主题讨论", children: [
146
- /* @__PURE__ */ jsxs("header", { className: "mind-comments__head", children: [
147
- /* @__PURE__ */ jsxs("div", { className: "mind-comments__intro", children: [
148
- /* @__PURE__ */ jsxs("strong", { children: [
149
- title,
150
- "的讨论"
151
- ] }),
152
- /* @__PURE__ */ jsx("p", { children: "讨论跟随这个主题移动;复制分支时不会复制。" })
153
- ] }),
154
- /* @__PURE__ */ jsxs("div", { className: "mind-comments__head-actions", children: [
155
- /* @__PURE__ */ jsx(WButton, { variant: "text", disabled: busy, onClick: () => setEpoch((value) => value + 1), children: "刷新" }),
156
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: onClose, children: "关闭" })
157
- ] })
158
- ] }),
159
- error && /* @__PURE__ */ jsx("p", { className: "mind-comments__error", role: "alert", children: error }),
160
- /* @__PURE__ */ jsxs("div", { className: "mind-comments__list", children: [
161
- loading && /* @__PURE__ */ jsx("p", { role: "status", children: "正在加载讨论…" }),
162
- !loading && !error && !items.length && /* @__PURE__ */ jsxs("p", { className: "mind-comments__empty", children: [
163
- "这个主题还没有讨论。",
164
- canComment ? "在下方写下第一条即可。" : ""
165
- ] }),
166
- items.map((item) => comment(item))
167
- ] }),
168
- canComment ? /* @__PURE__ */ jsxs("form", { className: "mind-comments__compose", onSubmit: (event) => {
169
- event.preventDefault();
170
- if (!draft.trim()) return;
171
- void perform(() => host.comments.create(pageId, draft.trim(), void 0, { blockId, topicId }));
172
- }, children: [
173
- /* @__PURE__ */ jsxs("label", { className: "mind-comment__label", children: [
174
- "对",
175
- title,
176
- "发表讨论"
177
- ] }),
178
- /* @__PURE__ */ jsx("textarea", { "aria-label": "主题评论内容", rows: 3, maxLength: 5e3, placeholder: "写下你的想法…", value: draft, onChange: (event) => setDraft(event.target.value) }),
179
- /* @__PURE__ */ jsx("div", { className: "mind-comment__actions", children: /* @__PURE__ */ jsx(WButton, { variant: "primary", loading: busy, disabled: !draft.trim(), htmlType: "submit", children: "发表讨论" }) })
180
- ] }) : /* @__PURE__ */ jsx("p", { className: "mind-comments__empty", children: "你没有在这个空间发表讨论的权限。" }),
181
- confirmId && /* @__PURE__ */ jsxs(WDialog, { title: "删除评论", onClose: () => setConfirmId(null), children: [
182
- /* @__PURE__ */ jsx("p", { children: "确定删除这条评论?" }),
183
- /* @__PURE__ */ jsxs("div", { className: "wr-toolbar", children: [
184
- /* @__PURE__ */ jsx(WButton, { onClick: () => setConfirmId(null), children: "取消" }),
185
- /* @__PURE__ */ jsx(WButton, { variant: "primary", onClick: () => {
186
- const id = confirmId;
187
- setConfirmId(null);
188
- void perform(() => host.comments.remove(id));
189
- }, children: "删除" })
190
- ] })
191
- ] })
192
- ] });
193
- }
194
- function MindMapField({ id, field, value, controller, label, onFocus, onCommand }) {
195
- const input = useRef(null), composing = useRef(false), focused = useRef(false);
196
- const [draft, setDraft] = useState(value), draftRef = useRef(value);
197
- draftRef.current = draft;
198
- useEffect(() => {
199
- if (composing.current || draftRef.current === value) return;
200
- const el = input.current, start = (el == null ? void 0 : el.selectionStart) ?? 0, end = (el == null ? void 0 : el.selectionEnd) ?? start;
201
- const diff = textDifference(draftRef.current, value), shift = diff.text.length - diff.to + diff.from;
202
- const map = (pos) => pos <= diff.from ? pos : pos >= diff.to ? pos + shift : diff.from + diff.text.length;
203
- setDraft(value);
204
- if (focused.current) queueMicrotask(() => el == null ? void 0 : el.setSelectionRange(map(start), map(end)));
205
- }, [value]);
206
- useEffect(() => () => {
207
- controller == null ? void 0 : controller.composition(false);
208
- controller == null ? void 0 : controller.endText(id, field);
209
- }, [controller, id, field]);
210
- function apply(next) {
211
- if (controller == null ? void 0 : controller.text(id, next, field)) setDraft(next);
212
- }
213
- return /* @__PURE__ */ jsx(
214
- "textarea",
215
- {
216
- ref: input,
217
- "aria-label": label,
218
- value: draft,
219
- readOnly: !(controller == null ? void 0 : controller.editable()),
220
- maxLength: field === "title" ? 2e3 : 4e3,
221
- rows: field === "title" ? 1 : field === "note" ? 4 : 3,
222
- onFocus: () => {
223
- focused.current = true;
224
- controller == null ? void 0 : controller.beginText(id, field);
225
- onFocus == null ? void 0 : onFocus();
226
- },
227
- onBlur: () => {
228
- focused.current = false;
229
- controller == null ? void 0 : controller.composition(false);
230
- controller == null ? void 0 : controller.endText(id, field);
231
- },
232
- onChange: (event) => apply(event.target.value),
233
- onCompositionStart: () => {
234
- composing.current = true;
235
- controller == null ? void 0 : controller.composition(true);
236
- },
237
- onCompositionEnd: (event) => {
238
- apply(event.currentTarget.value);
239
- composing.current = false;
240
- controller == null ? void 0 : controller.composition(false);
241
- controller == null ? void 0 : controller.beginText(id, field);
242
- },
243
- onKeyDown: (event) => {
244
- event.stopPropagation();
245
- if (event.nativeEvent.isComposing || composing.current || event.keyCode === 229) return;
246
- if ((event.metaKey || event.ctrlKey) && ["z", "y"].includes(event.key.toLowerCase())) {
247
- event.preventDefault();
248
- event.shiftKey || event.key.toLowerCase() === "y" ? controller == null ? void 0 : controller.redo() : controller == null ? void 0 : controller.undo();
249
- } else onCommand == null ? void 0 : onCommand(event);
250
- }
251
- }
252
- );
253
- }
254
- const COLORS = MIND_COLORS.map((value, index) => ({ value, label: ["默认", "深灰", "白色", "蓝色", "青绿", "紫色", "棕色", "红色"][index] }));
255
- const BACKGROUNDS = MIND_BACKGROUNDS.map((value, index) => ({ value, label: ["默认", "浅灰", "浅蓝", "浅绿", "浅紫", "浅黄", "浅红", "深蓝"][index] }));
256
- function MindMapDetails({ model, id, controller, range, onClose, onNotice }) {
257
- var _a;
258
- const topic = model.topics.find((item) => item.id === id);
259
- const writable = (controller == null ? void 0 : controller.editable()) ?? false;
260
- const [href, setHref] = useState(""), [busy, setBusy] = useState(false);
261
- const [relationTarget, setRelationTarget] = useState(""), [relationLabel, setRelationLabel] = useState("");
262
- const [relationKind, setRelationKind] = useState("related");
263
- const [relationId, setRelationId] = useState(void 0);
264
- const imageInput = useRef(null);
265
- if (!topic) return null;
266
- const patch = (key, value) => {
267
- if (writable) controller == null ? void 0 : controller.patch(id, { [key]: value || null });
268
- };
269
- function format(mark, attrs) {
270
- const from = range.from, to = range.to;
271
- if (to <= from) {
272
- onNotice == null ? void 0 : onNotice("请先在主题文字中选中要设置格式的文字。");
273
- return;
274
- }
275
- if (mark === "link" && attrs && !attrs.href) {
276
- controller == null ? void 0 : controller.clearFormat(id, from, to, ["link"]);
277
- return;
278
- }
279
- controller == null ? void 0 : controller.format(id, from, to, mark, attrs);
280
- }
281
- async function upload(file) {
282
- var _a2;
283
- if (!file || !(controller == null ? void 0 : controller.context.uploadImage) || !writable) return;
284
- if (!["image/png", "image/jpeg", "image/webp", "image/gif"].includes(file.type)) {
285
- onNotice == null ? void 0 : onNotice("请选择 PNG、JPEG、WebP 或 GIF 图片");
286
- return;
287
- }
288
- setBusy(true);
289
- try {
290
- const uploaded = await controller.context.uploadImage(file);
291
- if (controller.editable() && ((_a2 = controller.snapshot()) == null ? void 0 : _a2.topics.some((item) => item.id === id))) controller.patch(id, { attachmentId: uploaded.id });
292
- } catch (error) {
293
- onNotice == null ? void 0 : onNotice(error instanceof Error ? error.message : "图片上传失败");
294
- } finally {
295
- setBusy(false);
296
- if (imageInput.current) imageInput.current.value = "";
297
- }
298
- }
299
- function addRelation() {
300
- if (controller == null ? void 0 : controller.relation({ id: relationId, source: id, target: relationTarget, kind: relationKind, label: relationLabel })) {
301
- setRelationLabel("");
302
- setRelationId(void 0);
303
- onNotice == null ? void 0 : onNotice("已保存主题关系");
304
- } else onNotice == null ? void 0 : onNotice("请选择不同的目标主题");
305
- }
306
- const relations = ((_a = model.relations) == null ? void 0 : _a.filter((relation) => relation.source === id || relation.target === id)) ?? [];
307
- return /* @__PURE__ */ jsxs("aside", { className: "mind-details", "aria-label": "主题属性", children: [
308
- /* @__PURE__ */ jsxs("header", { children: [
309
- /* @__PURE__ */ jsx("strong", { children: "主题属性" }),
310
- /* @__PURE__ */ jsx(WButton, { size: "small", variant: "text", onClick: onClose, children: "关闭" })
311
- ] }),
312
- /* @__PURE__ */ jsx("p", { className: "mind-details-title", children: topic.text || "未命名主题" }),
313
- writable && /* @__PURE__ */ jsxs(Fragment, { children: [
314
- /* @__PURE__ */ jsxs("fieldset", { children: [
315
- /* @__PURE__ */ jsx("legend", { children: "选中文字格式" }),
316
- /* @__PURE__ */ jsxs("div", { className: "mind-format-buttons", onMouseDown: (event) => event.preventDefault(), children: [
317
- /* @__PURE__ */ jsx(WButton, { size: "small", "aria-label": "主题文字加粗", onClick: () => format("bold"), children: /* @__PURE__ */ jsx("b", { children: "B" }) }),
318
- /* @__PURE__ */ jsx(WButton, { size: "small", "aria-label": "主题文字斜体", onClick: () => format("italic"), children: /* @__PURE__ */ jsx("i", { children: "I" }) }),
319
- /* @__PURE__ */ jsx(WButton, { size: "small", "aria-label": "主题文字删除线", onClick: () => format("strike"), children: /* @__PURE__ */ jsx("s", { children: "S" }) })
320
- ] }),
321
- /* @__PURE__ */ jsx("span", { children: "选区文字色" }),
322
- /* @__PURE__ */ jsx("div", { className: "mind-color-grid", onMouseDown: (event) => event.preventDefault(), children: TEXT_COLORS.filter((color) => color.value).map((color) => /* @__PURE__ */ jsx(
323
- WButton,
324
- {
325
- size: "small",
326
- variant: "outline",
327
- narrow: true,
328
- "aria-label": `选区字体:${color.name}`,
329
- title: color.name,
330
- onClick: () => format("textStyle", { color: color.value }),
331
- children: /* @__PURE__ */ jsx("span", { style: { color: color.value }, children: "A" })
332
- },
333
- color.value
334
- )) }),
335
- /* @__PURE__ */ jsx("span", { children: "选区高亮" }),
336
- /* @__PURE__ */ jsx("div", { className: "mind-color-grid", onMouseDown: (event) => event.preventDefault(), children: HIGHLIGHT_COLORS.filter((color) => color.value).map((color) => /* @__PURE__ */ jsx(
337
- WButton,
338
- {
339
- size: "small",
340
- variant: "outline",
341
- narrow: true,
342
- "aria-label": `选区高亮:${color.name}`,
343
- title: color.name,
344
- style: { background: color.value },
345
- onClick: () => format("highlight", { color: color.value })
346
- },
347
- color.value
348
- )) }),
349
- /* @__PURE__ */ jsxs("label", { children: [
350
- "选区链接",
351
- /* @__PURE__ */ jsx("input", { value: href, type: "url", placeholder: "https://… 或站内路径", "aria-label": "主题选区链接", onChange: (event) => setHref(event.target.value) })
352
- ] }),
353
- /* @__PURE__ */ jsx(WButton, { size: "small", onClick: () => format("link", { href }), children: "应用链接" }),
354
- /* @__PURE__ */ jsx(WButton, { size: "small", onClick: () => controller == null ? void 0 : controller.clearFormat(id, range.from, range.to), children: "清除选区格式" })
355
- ] }),
356
- /* @__PURE__ */ jsxs("fieldset", { children: [
357
- /* @__PURE__ */ jsx("legend", { children: "外观" }),
358
- /* @__PURE__ */ jsxs("label", { children: [
359
- "形状",
360
- /* @__PURE__ */ jsx(
361
- WSelect,
362
- {
363
- label: "主题形状",
364
- ariaLabel: "主题形状",
365
- value: topic.shape ?? "round",
366
- onChange: (value) => patch("shape", value),
367
- options: [{ value: "round", label: "圆角矩形" }, { value: "pill", label: "胶囊" }, { value: "text", label: "文本" }]
368
- }
369
- )
370
- ] }),
371
- /* @__PURE__ */ jsxs("label", { children: [
372
- "字号",
373
- /* @__PURE__ */ jsx(
374
- WSelect,
375
- {
376
- label: "主题字号",
377
- ariaLabel: "主题字号",
378
- value: topic.fontSize ?? 14,
379
- onChange: (value) => patch("fontSize", Number(value)),
380
- options: [12, 14, 16, 18, 20].map((value) => ({ value, label: String(value) }))
381
- }
382
- )
383
- ] }),
384
- /* @__PURE__ */ jsxs("label", { children: [
385
- "对齐",
386
- /* @__PURE__ */ jsx(
387
- WSelect,
388
- {
389
- label: "主题对齐",
390
- ariaLabel: "主题对齐",
391
- value: topic.align ?? "center",
392
- onChange: (value) => patch("align", value),
393
- options: [{ value: "left", label: "左对齐" }, { value: "center", label: "居中" }, { value: "right", label: "右对齐" }]
394
- }
395
- )
396
- ] }),
397
- /* @__PURE__ */ jsx("span", { children: "节点文字色" }),
398
- /* @__PURE__ */ jsx("div", { className: "mind-color-grid", onMouseDown: (event) => event.preventDefault(), children: COLORS.map((color) => /* @__PURE__ */ jsx(
399
- WButton,
400
- {
401
- size: "small",
402
- variant: "outline",
403
- narrow: true,
404
- "aria-label": `节点字体:${color.label}`,
405
- title: color.label,
406
- onClick: () => patch("color", color.value),
407
- children: /* @__PURE__ */ jsx("span", { style: color.value ? { color: color.value } : void 0, children: "A" })
408
- },
409
- color.label
410
- )) }),
411
- /* @__PURE__ */ jsx("span", { children: "节点背景" }),
412
- /* @__PURE__ */ jsx("div", { className: "mind-color-grid", onMouseDown: (event) => event.preventDefault(), children: BACKGROUNDS.map((color) => /* @__PURE__ */ jsx(
413
- WButton,
414
- {
415
- size: "small",
416
- variant: "outline",
417
- narrow: true,
418
- "aria-label": `节点背景:${color.label}`,
419
- title: color.label,
420
- style: color.value ? { background: color.value } : void 0,
421
- onClick: () => patch("background", color.value),
422
- children: color.value ? "" : "/"
423
- },
424
- color.label
425
- )) }),
426
- /* @__PURE__ */ jsxs("label", { children: [
427
- "图标",
428
- /* @__PURE__ */ jsx(
429
- WSelect,
430
- {
431
- label: "主题图标",
432
- ariaLabel: "主题图标",
433
- value: topic.icon ?? "",
434
- onChange: (value) => patch("icon", value),
435
- options: MIND_ICONS.map((value) => ({ value, label: value || "无图标" }))
436
- }
437
- )
438
- ] }),
439
- /* @__PURE__ */ jsx(WButton, { size: "small", onClick: () => controller == null ? void 0 : controller.patch(id, { done: !topic.done }), children: topic.done ? "取消完成" : "标记完成" })
440
- ] })
441
- ] }),
442
- /* @__PURE__ */ jsxs("fieldset", { children: [
443
- /* @__PURE__ */ jsx("legend", { children: "描述" }),
444
- /* @__PURE__ */ jsx(MindMapField, { id, field: "description", value: topic.description ?? "", controller, label: "主题描述" })
445
- ] }),
446
- /* @__PURE__ */ jsxs("fieldset", { children: [
447
- /* @__PURE__ */ jsx("legend", { children: "备注" }),
448
- /* @__PURE__ */ jsx(MindMapField, { id, field: "note", value: topic.note ?? "", controller, label: "主题备注" })
449
- ] }),
450
- writable && (controller == null ? void 0 : controller.context.uploadImage) && /* @__PURE__ */ jsxs("fieldset", { children: [
451
- /* @__PURE__ */ jsx("legend", { children: "节点图片" }),
452
- /* @__PURE__ */ jsx("input", { ref: imageInput, hidden: true, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", onChange: (event) => {
453
- var _a2;
454
- return void upload((_a2 = event.target.files) == null ? void 0 : _a2[0]);
455
- } }),
456
- /* @__PURE__ */ jsx(WButton, { size: "small", loading: busy, onClick: () => {
457
- var _a2;
458
- return (_a2 = imageInput.current) == null ? void 0 : _a2.click();
459
- }, children: topic.attachmentId ? "替换图片" : "添加图片" }),
460
- topic.attachmentId && /* @__PURE__ */ jsx(WButton, { size: "small", onClick: () => patch("attachmentId", null), children: "移除图片" })
461
- ] }),
462
- /* @__PURE__ */ jsxs("fieldset", { children: [
463
- /* @__PURE__ */ jsx("legend", { children: "主题关系" }),
464
- relations.map((relation) => {
465
- var _a2;
466
- return /* @__PURE__ */ jsxs("div", { className: "mind-relation-item", children: [
467
- /* @__PURE__ */ jsxs("span", { children: [
468
- relation.label || { related: "相关", depends: "依赖", reference: "参考" }[relation.kind],
469
- " → ",
470
- ((_a2 = model.topics.find((item) => item.id === (relation.source === id ? relation.target : relation.source))) == null ? void 0 : _a2.text) || "已移除主题"
471
- ] }),
472
- writable && relation.source === id && /* @__PURE__ */ jsx(WButton, { variant: "text", size: "small", onClick: () => {
473
- setRelationId(relation.id);
474
- setRelationTarget(relation.target);
475
- setRelationKind(relation.kind);
476
- setRelationLabel(relation.label);
477
- }, children: "编辑" }),
478
- writable && /* @__PURE__ */ jsx(WButton, { variant: "text", size: "small", onClick: () => controller == null ? void 0 : controller.deleteRelation(relation.id), children: "删除" })
479
- ] }, relation.id);
480
- }),
481
- writable && /* @__PURE__ */ jsxs(Fragment, { children: [
482
- /* @__PURE__ */ jsx(
483
- WSelect,
484
- {
485
- label: "关系目标主题",
486
- ariaLabel: "关系目标主题",
487
- value: relationTarget,
488
- onChange: setRelationTarget,
489
- options: model.topics.filter((item) => item.id !== id).map((item) => ({ value: item.id, label: item.text || "未命名主题" })),
490
- searchable: true
491
- }
492
- ),
493
- /* @__PURE__ */ jsx(
494
- WSelect,
495
- {
496
- label: "主题关系类型",
497
- ariaLabel: "主题关系类型",
498
- value: relationKind,
499
- onChange: (value) => setRelationKind(value),
500
- options: [{ value: "related", label: "相关" }, { value: "depends", label: "依赖" }, { value: "reference", label: "参考" }]
501
- }
502
- ),
503
- /* @__PURE__ */ jsx("input", { "aria-label": "关系说明", placeholder: "关系说明(可选)", maxLength: 200, value: relationLabel, onChange: (event) => setRelationLabel(event.target.value) }),
504
- /* @__PURE__ */ jsx(WButton, { size: "small", disabled: !relationTarget, onClick: addRelation, children: relationId ? "保存关系" : "添加关系" })
505
- ] })
506
- ] })
507
- ] });
508
- }
509
- function WDropdown({ label, groups, onSelect, buttonProps }) {
510
- const [open, setOpen] = useState(false), trigger = useRef(null), menu = useRef(null);
511
- function keydown(event) {
512
- var _a, _b;
513
- if (!open || event.nativeEvent.isComposing) return;
514
- const items = Array.from(((_a = menu.current) == null ? void 0 : _a.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])')) ?? []);
515
- const index = items.indexOf(document.activeElement);
516
- if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key) && items.length) {
517
- event.preventDefault();
518
- event.stopPropagation();
519
- (_b = items[event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : index < 0 ? event.key === "ArrowUp" ? items.length - 1 : 0 : (index + (event.key === "ArrowUp" ? -1 : 1) + items.length) % items.length]) == null ? void 0 : _b.focus();
520
- }
521
- }
522
- function select(item) {
523
- if (!item.disabled) {
524
- setOpen(false);
525
- onSelect(item.value);
526
- }
527
- }
528
- return /* @__PURE__ */ jsxs(Fragment, { children: [
529
- /* @__PURE__ */ jsx(WButton, { ...buttonProps, ref: trigger, "aria-haspopup": "menu", "aria-expanded": open, onClick: () => setOpen(!open), onKeyDown: keydown, children: label }),
530
- open && /* @__PURE__ */ jsx(
531
- AnchoredPanel,
532
- {
533
- anchor: trigger.current,
534
- align: "center",
535
- gap: 6,
536
- role: "menu",
537
- className: "mind-dropdown-popup",
538
- label: typeof label === "string" ? label : void 0,
539
- onClose: () => setOpen(false),
540
- onKeyDown: keydown,
541
- children: /* @__PURE__ */ jsx("div", { ref: menu, className: "w-dropdown", children: groups.map((group, index) => /* @__PURE__ */ jsxs("div", { className: "w-dropdown-group", role: "group", "aria-label": group.title, children: [
542
- group.title && /* @__PURE__ */ jsx("div", { className: "w-dropdown-group__title", children: group.title }),
543
- group.items.map((item) => /* @__PURE__ */ jsxs(
544
- "div",
545
- {
546
- className: `w-dropdown-option${item.disabled ? " is-disabled" : ""}`,
547
- role: "menuitem",
548
- tabIndex: item.disabled ? void 0 : -1,
549
- "aria-disabled": item.disabled || void 0,
550
- onClick: () => select(item),
551
- onKeyDown: (event) => {
552
- if (event.key === "Enter" || event.key === " ") {
553
- event.preventDefault();
554
- select(item);
555
- }
556
- },
557
- children: [
558
- item.label,
559
- item.shortcut && /* @__PURE__ */ jsx("span", { className: "mind-menu-key", children: item.shortcut })
560
- ]
561
- },
562
- item.value
563
- ))
564
- ] }, index)) })
565
- }
566
- )
567
- ] });
568
- }
569
- function WTooltip({ children, content }) {
570
- var _a;
571
- const [open, setOpen] = useState(false), anchor = useRef(null), timer = useRef(void 0);
572
- function close() {
573
- clearTimeout(timer.current);
574
- setOpen(false);
575
- }
576
- function show() {
577
- clearTimeout(timer.current);
578
- timer.current = setTimeout(() => setOpen(true), 200);
579
- }
580
- useEffect(() => () => clearTimeout(timer.current), []);
581
- useEffect(() => {
582
- if (!open) return;
583
- window.addEventListener("scroll", close, true);
584
- return () => window.removeEventListener("scroll", close, true);
585
- }, [open]);
586
- return /* @__PURE__ */ jsxs("span", { ref: anchor, style: { display: "contents" }, onMouseEnter: show, onMouseLeave: close, onFocus: show, onBlur: close, children: [
587
- children,
588
- open && /* @__PURE__ */ jsx(AnchoredPanel, { anchor: ((_a = anchor.current) == null ? void 0 : _a.firstElementChild) ?? null, align: "center", prefer: "above", gap: 8, role: "tooltip", onClose: close, className: "code-tooltip-popup", children: /* @__PURE__ */ jsx("div", { className: "w-tooltip", children: content }) })
589
- ] });
590
- }
591
- function MindMapCanvas(props) {
592
- var _a, _b, _c, _d, _e, _f, _g;
593
- const { host, portal } = useContentContext(), c = props.controller, [, update] = useState(0);
594
- useEffect(() => {
595
- const unsubscribe = c == null ? void 0 : c.subscribe(() => update((value) => value + 1));
596
- return () => {
597
- unsubscribe == null ? void 0 : unsubscribe();
598
- };
599
- }, [c]);
600
- const model = (c == null ? void 0 : c.snapshot()) ?? props.model, editable = (c == null ? void 0 : c.editable()) ?? false;
601
- const saved = useRef((_a = c == null ? void 0 : c.context.viewState) == null ? void 0 : _a.maps[model.id]).current;
602
- const [selected, setSelected] = useState(() => new Set((saved == null ? void 0 : saved.selectedIds) ?? [(saved == null ? void 0 : saved.selectedId) ?? model.rootId]));
603
- const [active, setActive] = useState((saved == null ? void 0 : saved.selectedId) ?? model.rootId);
604
- const [editing, setEditing] = useState(null), [text, setText] = useState("");
605
- const composing = useRef(false);
606
- const [folds, setFolds] = useState(() => normalizeMindFolds(model, (saved == null ? void 0 : saved.collapsed) ?? []));
607
- const [zoom, setZoom] = useState(((_b = saved == null ? void 0 : saved.viewport) == null ? void 0 : _b.zoom) ?? 1);
608
- const [origin, setPan] = useState({ x: ((_c = saved == null ? void 0 : saved.viewport) == null ? void 0 : _c.x) ?? 0, y: ((_d = saved == null ? void 0 : saved.viewport) == null ? void 0 : _d.y) ?? 0 });
609
- const [moving, setMoving] = useState((saved == null ? void 0 : saved.panMode) ?? false), space = useRef(false), [outline, setOutline] = useState(false), [grid, setGrid] = useState((saved == null ? void 0 : saved.showGrid) ?? true);
610
- const [spaceHeld, setSpaceHeld] = useState(false);
611
- const [quickControls, setQuickControls] = useState((saved == null ? void 0 : saved.showQuickControls) ?? true);
612
- const [settingsOpen, setSettingsOpen] = useState(false), settingsTrigger = useRef(null);
613
- const [busy, setBusy] = useState(false), exportRunning = useRef(false);
614
- const [showSearch, setShowSearch] = useState(false), [query, setQuery] = useState(""), [replacement, setReplacement] = useState("");
615
- const [hitIndex, setHitIndex] = useState(0), [following, setFollowing] = useState(null);
616
- const [details, setDetails] = useState(false), [comments, setComments] = useState(!!props.openComments);
617
- const [selectedRange, setSelectedRange] = useState({ from: 0, to: 0 });
618
- const [notice, setNotice] = useState(""), [focusId, setFocusId] = useState(null);
619
- const [confirmDelete, setConfirmDelete] = useState(null);
620
- const deletionSelection = useRef([]), deletionActive = useRef(active);
621
- const [importOpen, setImportOpen] = useState(false), [importText, setImportText] = useState(""), [importError, setImportError] = useState("");
622
- const [exportBranch, setExportBranch] = useState(false), [transparent, setTransparent] = useState(false), [imageScale, setImageScale] = useState(2);
623
- const [box, setBox] = useState(null), [drop, setDrop] = useState(null);
624
- const [contextMenu, setContextMenu] = useState(null);
625
- const menuRef = useRef(null);
626
- const [dragPreview, setDragPreview] = useState(null);
627
- const [pasting, setPasting] = useState(false), pastingRef = useRef(false), alive = useRef(true);
628
- const root = useRef(null), stage = useRef(null), input = useRef(null);
629
- const gesture = useRef(null), copied = useRef([]), [size, setSize] = useState({ width: 0, height: 0 });
630
- const tree = mindMapTree(model), current = tree.find((topic) => topic.id === active) ?? tree[0];
631
- const viewModel = focusId && tree.some((topic) => topic.id === focusId) ? branchModel(model, focusId) : model;
632
- const drawing = layoutMindMap(viewModel, normalizeMindFolds(viewModel, folds)), color = MIND_MAP_PALETTE[model.theme];
633
- const currentRef = useLatest({ model, editable, c, active });
634
- const draggedIds = dragPreview ? mindMapDescendants$1(model, dragPreview.id) : /* @__PURE__ */ new Set();
635
- const projected = (drop == null ? void 0 : drop.kind) === "side" && dragPreview ? projectMindSideMove(model, dragPreview.id, drop.side, drop.beforeId) : null;
636
- const projection = projected ? layoutMindMap(projected, folds) : null;
637
- const hits = query ? searchMindMap(model, query) : [];
638
- const importPreview = useMemo(() => {
639
- try {
640
- return importText.trim() ? parseMindMapImport(importText) : null;
641
- } catch {
642
- return null;
643
- }
644
- }, [importText]);
645
- const status = props.saveStatus ?? (c == null ? void 0 : c.status()) ?? "", pageId = props.pageId ?? (c == null ? void 0 : c.context.pageId);
646
- const canExport = c ? c.canExport() : props.allowExport === true;
647
- const title = ((_e = model.topics.find((topic) => topic.id === model.rootId)) == null ? void 0 : _e.text) || "思维导图";
648
- useEffect(() => {
649
- const node = stage.current;
650
- if (!node) return;
651
- const observer = new ResizeObserver(() => setSize({ width: node.clientWidth, height: node.clientHeight }));
652
- const wheel = (event) => event.preventDefault();
653
- node.addEventListener("wheel", wheel, { passive: false });
654
- observer.observe(node);
655
- return () => {
656
- observer.disconnect();
657
- node.removeEventListener("wheel", wheel);
658
- };
659
- }, []);
660
- useEffect(() => {
661
- const keyup = (event) => {
662
- if (event.code === "Space") {
663
- space.current = false;
664
- setSpaceHeld(false);
665
- }
666
- };
667
- const blur = () => {
668
- cancelGesture();
669
- space.current = false;
670
- setSpaceHeld(false);
671
- setContextMenu(null);
672
- };
673
- window.addEventListener("keyup", keyup);
674
- window.addEventListener("blur", blur);
675
- return () => {
676
- window.removeEventListener("keyup", keyup);
677
- window.removeEventListener("blur", blur);
678
- };
679
- }, []);
680
- useEffect(() => {
681
- alive.current = true;
682
- return () => {
683
- alive.current = false;
684
- c == null ? void 0 : c.composition(false);
685
- };
686
- }, [c]);
687
- useEffect(() => {
688
- const close = (event) => {
689
- var _a2;
690
- if (!((_a2 = menuRef.current) == null ? void 0 : _a2.contains(event.target))) setContextMenu(null);
691
- };
692
- const key = (event) => {
693
- var _a2;
694
- if (event.isComposing || event.key !== "Escape") return;
695
- if (gesture.current || contextMenu) {
696
- event.preventDefault();
697
- event.stopImmediatePropagation();
698
- cancelGesture();
699
- setContextMenu(null);
700
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
701
- }
702
- };
703
- document.addEventListener("pointerdown", close, true);
704
- window.addEventListener("keydown", key, true);
705
- return () => {
706
- document.removeEventListener("pointerdown", close, true);
707
- window.removeEventListener("keydown", key, true);
708
- };
709
- }, [contextMenu]);
710
- useEffect(() => {
711
- const menu = menuRef.current;
712
- if (!menu || !contextMenu) return;
713
- const rect = menu.getBoundingClientRect();
714
- menu.style.left = `${Math.max(8, Math.min(contextMenu.x, innerWidth - rect.width - 8))}px`;
715
- menu.style.top = `${Math.max(8, Math.min(contextMenu.y, innerHeight - rect.height - 8))}px`;
716
- menu.focus();
717
- }, [contextMenu, portal]);
718
- useEffect(() => {
719
- const g = gesture.current;
720
- if (g && (g.doc !== JSON.stringify(model) || !editable && g.kind === "node")) cancelGesture();
721
- }, [model, editable]);
722
- useEffect(() => {
723
- var _a2, _b2;
724
- if (editing) {
725
- (_a2 = input.current) == null ? void 0 : _a2.focus();
726
- (_b2 = input.current) == null ? void 0 : _b2.select();
727
- }
728
- }, [editing]);
729
- useEffect(() => {
730
- if (!editing) return;
731
- const topic = model.topics.find((topic2) => topic2.id === editing), element = input.current;
732
- if (!topic || !editable) {
733
- c == null ? void 0 : c.endText(editing);
734
- setEditing(null);
735
- return;
736
- }
737
- if (composing.current || topic.text === text) return;
738
- const start = (element == null ? void 0 : element.selectionStart) ?? 0, end = (element == null ? void 0 : element.selectionEnd) ?? start, diff = textDifference(text, topic.text);
739
- const shift = diff.text.length - diff.to + diff.from;
740
- const map = (pos) => pos <= diff.from ? pos : pos >= diff.to ? pos + shift : diff.from + diff.text.length;
741
- setText(topic.text);
742
- queueMicrotask(() => {
743
- if (element === document.activeElement) element == null ? void 0 : element.setSelectionRange(map(start), map(end));
744
- });
745
- }, [model, editable, editing]);
746
- useEffect(() => {
747
- const element = input.current;
748
- if (!editing || !element) return;
749
- element.style.height = "0px";
750
- element.style.height = `${Math.max(mindTopicLineHeight(current.fontSize || 14), element.scrollHeight)}px`;
751
- }, [editing, text, current.fontSize]);
752
- useEffect(() => {
753
- const ids = new Set(drawing.nodes.map((topic) => topic.id));
754
- setSelected((previous) => {
755
- const next = new Set([...previous].filter((id) => ids.has(id)));
756
- return next.size === previous.size ? previous : next;
757
- });
758
- if (!ids.has(active)) setActive(model.rootId);
759
- }, [model, active, focusId, folds]);
760
- const viewStateRef = useRef({ zoom, pan: origin, grid, quickControls, moving, folds, active, selected });
761
- viewStateRef.current = { zoom, pan: origin, grid, quickControls, moving, folds, active, selected };
762
- useEffect(() => () => {
763
- const state = c == null ? void 0 : c.context.viewState;
764
- if (!state) return;
765
- const current2 = viewStateRef.current;
766
- state.maps[model.id] = {
767
- selectedId: current2.active,
768
- selectedIds: [...current2.selected],
769
- showGrid: current2.grid,
770
- showQuickControls: current2.quickControls,
771
- panMode: current2.moving,
772
- collapsed: [...current2.folds],
773
- viewport: { x: current2.pan.x, y: current2.pan.y, zoom: current2.zoom }
774
- };
775
- }, [c, model.id]);
776
- const awareness = c == null ? void 0 : c.context.awareness;
777
- const [peerEpoch, bumpPeers] = useState(0);
778
- useEffect(() => {
779
- if (!awareness) return;
780
- const change = () => bumpPeers((value) => value + 1);
781
- awareness.on("change", change);
782
- return () => {
783
- awareness.off("change", change);
784
- };
785
- }, [awareness]);
786
- useEffect(() => {
787
- var _a2;
788
- const local = (_a2 = awareness == null ? void 0 : awareness.getLocalState()) == null ? void 0 : _a2.mindMap;
789
- if (awareness && ((local == null ? void 0 : local.blockId) === model.id || !local)) {
790
- awareness.setLocalStateField("mindMap", { blockId: model.id, topicId: active, editing: !!editing, viewport: { ...origin, zoom } });
791
- }
792
- }, [awareness, model.id, active, editing, origin.x, origin.y, zoom]);
793
- useEffect(() => () => {
794
- var _a2, _b2;
795
- if (((_b2 = (_a2 = awareness == null ? void 0 : awareness.getLocalState()) == null ? void 0 : _a2.mindMap) == null ? void 0 : _b2.blockId) === model.id) awareness.setLocalStateField("mindMap", null);
796
- }, [awareness, model.id]);
797
- useEffect(() => {
798
- var _a2;
799
- if (!awareness || following === null) return;
800
- const peer = (_a2 = awareness.getStates().get(following)) == null ? void 0 : _a2.mindMap;
801
- if ((peer == null ? void 0 : peer.blockId) !== model.id || !peer.viewport || ![peer.viewport.x, peer.viewport.y, peer.viewport.zoom].every(Number.isFinite)) return;
802
- const nextZoom = Math.min(2.5, Math.max(5e-3, peer.viewport.zoom));
803
- setPan({ x: peer.viewport.x, y: peer.viewport.y });
804
- setZoom(nextZoom);
805
- }, [awareness, following, model.id, peerEpoch]);
806
- const peers = useMemo(() => {
807
- return Array.from((awareness == null ? void 0 : awareness.getStates().entries()) ?? []).flatMap(([client, state]) => {
808
- var _a2, _b2;
809
- const data = state.mindMap;
810
- if (client === (awareness == null ? void 0 : awareness.clientID) || (data == null ? void 0 : data.blockId) !== model.id) return [];
811
- return [{ client, name: String(((_a2 = state.user) == null ? void 0 : _a2.name) || ((_b2 = state.user) == null ? void 0 : _b2.displayName) || "协作者"), topicId: String(data.topicId || ""), editing: !!data.editing }];
812
- });
813
- }, [awareness, model.id, peerEpoch]);
814
- function fit(target = viewModel) {
815
- var _a2, _b2;
816
- const bounds = layoutMindMap(target, normalizeMindFolds(target, folds)).bounds;
817
- const width = ((_a2 = stage.current) == null ? void 0 : _a2.clientWidth) ?? size.width, height = ((_b2 = stage.current) == null ? void 0 : _b2.clientHeight) ?? size.height;
818
- const nextZoom = Math.min(1.15, Math.max(5e-3, Math.min((width - 110) / bounds.width, (height - 150) / bounds.height)));
819
- setZoom(nextZoom);
820
- setPan({ x: width / 2 - (bounds.x + bounds.width / 2) * nextZoom, y: height / 2 - (bounds.y + bounds.height / 2) * nextZoom });
821
- }
822
- const autoFitted = useRef(false);
823
- const lastLayout = useRef(model.layout), lastPanels = useRef({ details, comments, outline });
824
- useEffect(() => {
825
- const panels = lastPanels.current;
826
- if (autoFitted.current && (lastLayout.current !== model.layout || panels.details !== details || panels.comments !== comments || panels.outline !== outline) && following === null) fit();
827
- lastLayout.current = model.layout;
828
- lastPanels.current = { details, comments, outline };
829
- }, [model.layout, details, comments, outline, size.width, size.height]);
830
- useEffect(() => {
831
- if (autoFitted.current) return;
832
- if (!size.width || !size.height || !stage.current) return;
833
- autoFitted.current = true;
834
- if (saved == null ? void 0 : saved.viewport) {
835
- setPan({ x: saved.viewport.x, y: saved.viewport.y });
836
- } else fit();
837
- }, [size.width, size.height]);
838
- const point = (x, y) => {
839
- const rect = stage.current.getBoundingClientRect();
840
- return { x: (x - rect.left - origin.x) / zoom, y: (y - rect.top - origin.y) / zoom };
841
- };
842
- function select(id, additive = false) {
843
- var _a2;
844
- const next = selectMindTopic(selected, id, additive);
845
- setFollowing(null);
846
- setSelected(next);
847
- setActive(next.has(id) ? id : [...next].at(-1) ?? model.rootId);
848
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
849
- }
850
- function locateHit(hit) {
851
- locate(hit.id);
852
- if (hit.field !== "title") {
853
- setDetails(true);
854
- setComments(false);
855
- }
856
- }
857
- function locate(id) {
858
- const live = (c == null ? void 0 : c.snapshot()) ?? model;
859
- if (!live.topics.some((topic2) => topic2.id === id)) return;
860
- const next = new Set(folds);
861
- for (const ancestor of ancestorIds(live, id)) next.delete(ancestor);
862
- const drawing2 = layoutMindMap(live, next), topic = drawing2.nodes.find((topic2) => topic2.id === id);
863
- setFolds(next);
864
- setFocusId(null);
865
- select(id);
866
- if (topic) setPan({ x: size.width / 2 - (topic.x + topic.width / 2) * zoom, y: size.height / 2 - (topic.y + topic.height / 2) * zoom });
867
- }
868
- useEffect(() => {
869
- setSelectedRange({ from: 0, to: 0 });
870
- }, [active]);
871
- useEffect(() => {
872
- if (!host.location) return;
873
- const linked = () => {
874
- const params = new URLSearchParams(host.location.current().replace(/^#/, ""));
875
- const id = params.get("topic");
876
- if (params.get("mind") === model.id && id) locate(id);
877
- };
878
- linked();
879
- return host.location.subscribe(linked);
880
- }, [host.location, model.id]);
881
- function jumpHit(delta) {
882
- if (!hits.length) return;
883
- const next = (hitIndex + delta + hits.length) % hits.length;
884
- setHitIndex(next);
885
- locateHit(hits[next]);
886
- }
887
- function edit(id) {
888
- if (id && editable) {
889
- const topic = model.topics.find((topic2) => topic2.id === id);
890
- if (!topic) return;
891
- setActive(id);
892
- setSelected(/* @__PURE__ */ new Set([id]));
893
- c == null ? void 0 : c.beginText(id);
894
- setText(topic.text);
895
- setEditing(id);
896
- } else {
897
- if (editing) c == null ? void 0 : c.endText(editing);
898
- setEditing(null);
899
- queueMicrotask(() => {
900
- var _a2;
901
- return (_a2 = stage.current) == null ? void 0 : _a2.focus();
902
- });
903
- }
904
- }
905
- function add(kind, side, targetId = active) {
906
- if (!c || !editable) return;
907
- if (model.topics.length >= MIND_MAP_MAX_TOPICS) {
908
- setNotice("单张导图最多支持 500 个主题。");
909
- return;
910
- }
911
- const id = kind === "parent" ? c.addParent(targetId) : side !== void 0 && targetId === model.rootId ? c.addRootChild(side) : kind === "sibling" ? c.addSibling(targetId, "after") : c.add(targetId);
912
- if (id) {
913
- setFolds((previous) => {
914
- const next = new Set(previous);
915
- next.delete(targetId);
916
- return next;
917
- });
918
- setSelected(/* @__PURE__ */ new Set([id]));
919
- setActive(id);
920
- c.beginText(id);
921
- setText("新主题");
922
- setEditing(id);
923
- }
924
- }
925
- function addSiblingAt(id, placement) {
926
- if (!c || !editable) return;
927
- if (model.topics.length >= MIND_MAP_MAX_TOPICS) {
928
- setNotice("单张导图最多支持 500 个主题。");
929
- return;
930
- }
931
- const next = c.addSibling(id, placement);
932
- if (next) {
933
- setFolds((previous) => {
934
- const nextFolds = new Set(previous);
935
- nextFolds.delete(id);
936
- return nextFolds;
937
- });
938
- setSelected(/* @__PURE__ */ new Set([next]));
939
- setActive(next);
940
- c.beginText(next);
941
- setText("新主题");
942
- setEditing(next);
943
- }
944
- }
945
- function remove(targetId = active, targetSelection = selected) {
946
- if (!c || !editable) return;
947
- const plan = planMindTopicDeletion(model, targetSelection, targetId);
948
- if (!plan) return;
949
- deletionSelection.current = [...targetSelection];
950
- deletionActive.current = targetId;
951
- if (plan.ids.size > plan.roots.length) setConfirmDelete(plan);
952
- else performDelete(plan, targetId);
953
- }
954
- function performDelete(plan, targetId = deletionActive.current) {
955
- const next = planMindTopicDeletion((c == null ? void 0 : c.snapshot()) ?? model, deletionSelection.current, targetId);
956
- if (!next || next.ids.size !== plan.ids.size || [...next.ids].some((id) => !plan.ids.has(id)) || !(c == null ? void 0 : c.removeMany(deletionSelection.current))) {
957
- setNotice("主题或权限已变化,请重新选择");
958
- return;
959
- }
960
- setSelected(/* @__PURE__ */ new Set([next.nextId]));
961
- setActive(next.nextId);
962
- setEditing(null);
963
- setConfirmDelete(null);
964
- setNotice(`已删除 ${plan.ids.size} 个主题,可撤销。`);
965
- queueMicrotask(() => {
966
- var _a2;
967
- return (_a2 = stage.current) == null ? void 0 : _a2.focus();
968
- });
969
- }
970
- function fold(id) {
971
- if (!mindMapDescendants$1(model, id).size || id === model.rootId) return;
972
- setFolds((previous) => {
973
- const next = new Set(previous);
974
- if (next.has(id)) next.delete(id);
975
- else next.add(id);
976
- return next;
977
- });
978
- }
979
- function copy(targetId = active) {
980
- var _a2;
981
- if (!c) return;
982
- copied.current = c.copyBranch(targetId);
983
- setNotice("分支已复制,选择目标主题后粘贴。");
984
- if (canExport) void ((_a2 = navigator.clipboard) == null ? void 0 : _a2.writeText(`YWIKI_MINDMAP_BRANCH_V1
985
- ${JSON.stringify(copied.current)}`).catch(() => {
986
- }));
987
- }
988
- async function materializeImages(source) {
989
- var _a2, _b2;
990
- const prepared = structuredClone(source);
991
- const known = new Set(model.topics.flatMap((topic) => topic.attachmentId ? [topic.attachmentId] : []));
992
- const clones = /* @__PURE__ */ new Map();
993
- for (const node of prepared) {
994
- const id = (_a2 = node.attrs) == null ? void 0 : _a2.attachmentId;
995
- if (typeof id !== "string" || !id || known.has(id)) continue;
996
- if (!(c == null ? void 0 : c.context.uploadImage)) throw new Error("当前文档不支持图片复制,请移除图片后导入");
997
- if (!clones.has(id)) {
998
- const fetcher = c.context.fetchAttachment ?? props.fetchAttachment ?? ((_b2 = host.attachments) == null ? void 0 : _b2.fetch);
999
- if (!fetcher) throw new Error("当前文档未配置图片读取服务");
1000
- const blob = await fetcher(id);
1001
- const uploaded = await c.context.uploadImage(new File([blob], "导图主题图片.png", { type: blob.type || "image/png" }));
1002
- clones.set(id, uploaded.id);
1003
- }
1004
- node.attrs.attachmentId = clones.get(id);
1005
- }
1006
- return prepared;
1007
- }
1008
- async function paste(targetId = active) {
1009
- if (!editable || !c || pastingRef.current) return;
1010
- pastingRef.current = true;
1011
- setPasting(true);
1012
- try {
1013
- let value = copied.current;
1014
- if (canExport) try {
1015
- const raw = await Promise.race([navigator.clipboard.readText(), new Promise((_, reject) => setTimeout(() => reject(new Error("剪贴板读取超时")), 1500))]);
1016
- if (raw.length < 2e6 && raw.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")) value = parseMindBranch(raw);
1017
- } catch {
1018
- }
1019
- await insertBranch(value, targetId);
1020
- } catch (error) {
1021
- if (alive.current) setNotice(error instanceof Error ? error.message : "图片复制失败");
1022
- } finally {
1023
- pastingRef.current = false;
1024
- if (alive.current) setPasting(false);
1025
- }
1026
- }
1027
- async function insertBranch(value, targetId) {
1028
- var _a2;
1029
- if (value.filter((node) => node.type === "mindMapTopic").length + model.topics.length > MIND_MAP_MAX_TOPICS) throw new Error("粘贴后主题超过 500 个,本次未修改");
1030
- const prepared = await materializeImages(value), live = currentRef.current;
1031
- if (!alive.current || live.c !== c || !live.editable || live.model.id !== model.id) return;
1032
- if (!((_a2 = c == null ? void 0 : c.snapshot()) == null ? void 0 : _a2.topics.some((topic) => topic.id === targetId))) throw new Error("目标主题已移除,请重新选择");
1033
- const id = c.pasteBranch(targetId, prepared);
1034
- if (!id) throw new Error("没有可粘贴的分支,或主题容量超过上限");
1035
- setNotice("已粘贴分支。");
1036
- setFolds((previous) => {
1037
- const next = new Set(previous);
1038
- next.delete(targetId);
1039
- return next;
1040
- });
1041
- locate(id);
1042
- }
1043
- async function nativePaste(event) {
1044
- var _a2;
1045
- if (!editable || event.target.closest('input,textarea,[contenteditable="true"]')) return;
1046
- const raw = ((_a2 = event.clipboardData) == null ? void 0 : _a2.getData("text/plain")) ?? "";
1047
- if (!raw.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")) return;
1048
- event.preventDefault();
1049
- event.stopPropagation();
1050
- try {
1051
- if (pastingRef.current) return;
1052
- pastingRef.current = true;
1053
- setPasting(true);
1054
- await insertBranch(parseMindBranch(raw), active);
1055
- } catch (error) {
1056
- setNotice(error instanceof Error ? error.message : "分支格式无效");
1057
- } finally {
1058
- pastingRef.current = false;
1059
- if (alive.current) setPasting(false);
1060
- }
1061
- }
1062
- function moveSide(side, targetId = active) {
1063
- var _a2;
1064
- if (c == null ? void 0 : c.moveToSide(targetId, side)) {
1065
- setNotice(`已移到${side === -1 ? "左" : "右"}侧`);
1066
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
1067
- }
1068
- }
1069
- function openContextMenu(id, event) {
1070
- event.preventDefault();
1071
- event.stopPropagation();
1072
- if (id) select(id);
1073
- setContextMenu({ id, x: event.clientX, y: event.clientY });
1074
- }
1075
- function menuKeydown(event) {
1076
- var _a2, _b2;
1077
- const items = Array.from(((_a2 = menuRef.current) == null ? void 0 : _a2.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])')) ?? []);
1078
- if (!items.length || !["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
1079
- event.preventDefault();
1080
- event.stopPropagation();
1081
- const index = items.indexOf(document.activeElement);
1082
- (_b2 = items[event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : index < 0 ? event.key === "ArrowUp" ? items.length - 1 : 0 : (index + (event.key === "ArrowUp" ? -1 : 1) + items.length) % items.length]) == null ? void 0 : _b2.focus();
1083
- }
1084
- function contextAction(action) {
1085
- const id = (contextMenu == null ? void 0 : contextMenu.id) ?? active;
1086
- setContextMenu(null);
1087
- if (!id) return;
1088
- setActive(id);
1089
- if (action === "child" || action === "sibling" || action === "parent") add(action, void 0, id);
1090
- else if (action === "rename") edit(id);
1091
- else if (action === "properties") {
1092
- setDetails(true);
1093
- setComments(false);
1094
- } else if (action === "fold") fold(id);
1095
- else if (action === "focus") {
1096
- setFocusId(id);
1097
- fit(branchModel(model, id));
1098
- } else if (action === "left") moveSide(-1, id);
1099
- else if (action === "right") moveSide(1, id);
1100
- else if (action === "copy") copy(id);
1101
- else if (action === "paste") void paste((contextMenu == null ? void 0 : contextMenu.id) ? id : selected.size === 1 ? active : viewModel.rootId);
1102
- else if (action === "delete") remove(id, /* @__PURE__ */ new Set([id]));
1103
- else paneCommand(action);
1104
- }
1105
- function paneCommand(action) {
1106
- var _a2;
1107
- setFollowing(null);
1108
- if (action === "quick") setQuickControls((value) => !value);
1109
- else if (action === "grid") setGrid((value) => !value);
1110
- else if (action === "comments") {
1111
- setComments((value) => !value);
1112
- setDetails(false);
1113
- } else if (action === "zoom-in") zoomTo(zoom * 1.2);
1114
- else if (action === "zoom-out") zoomTo(zoom / 1.2);
1115
- else if (action === "reset-zoom") zoomTo(1);
1116
- else if (action === "fit") fit();
1117
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
1118
- }
1119
- function followPeer(client) {
1120
- cancelGesture();
1121
- edit(null);
1122
- setFollowing(client);
1123
- }
1124
- function zoomTo(value, at = { x: size.width / 2, y: size.height / 2 }) {
1125
- const next = Math.max(5e-3, Math.min(2.5, value)), ratio = next / zoom;
1126
- const x = at.x - (at.x - origin.x) * ratio, y = at.y - (at.y - origin.y) * ratio;
1127
- setZoom(next);
1128
- setPan({ x, y });
1129
- }
1130
- async function copyTopicLink() {
1131
- var _a2, _b2;
1132
- const link = (_b2 = (_a2 = host.location) == null ? void 0 : _a2.createLink) == null ? void 0 : _b2.call(_a2, { blockId: model.id, topicId: active });
1133
- if (!link) {
1134
- setNotice("宿主未提供主题定位链接");
1135
- return;
1136
- }
1137
- try {
1138
- await navigator.clipboard.writeText(link);
1139
- setNotice("已复制主题定位链接");
1140
- } catch {
1141
- setNotice(link);
1142
- }
1143
- }
1144
- function keydown(event) {
1145
- var _a2, _b2, _c2, _d2;
1146
- if (!((_a2 = root.current) == null ? void 0 : _a2.contains(event.target)) || event.defaultPrevented || event.nativeEvent.isComposing || event.keyCode === 229 || event.target.closest("input,textarea,[contenteditable=true]")) return;
1147
- const command = event.ctrlKey || event.metaKey;
1148
- const view = mindCanvasShortcut(event);
1149
- if (event.target.closest("button,select,[role=combobox]") && !view && !command) return;
1150
- if (event.code === "Space") {
1151
- event.preventDefault();
1152
- space.current = true;
1153
- setSpaceHeld(true);
1154
- return;
1155
- }
1156
- if (event.key === "Escape") {
1157
- if (!props.inline && !details && !comments && !showSearch) return;
1158
- event.preventDefault();
1159
- event.stopPropagation();
1160
- cancelGesture();
1161
- setContextMenu(null);
1162
- setSelected(/* @__PURE__ */ new Set());
1163
- setDetails(false);
1164
- setComments(false);
1165
- setShowSearch(false);
1166
- return;
1167
- }
1168
- if (command && event.key.toLowerCase() === "z" && editable) {
1169
- event.preventDefault();
1170
- event.shiftKey ? c == null ? void 0 : c.redo() : c == null ? void 0 : c.undo();
1171
- return;
1172
- }
1173
- if (command && event.key.toLowerCase() === "y" && editable) {
1174
- event.preventDefault();
1175
- c == null ? void 0 : c.redo();
1176
- return;
1177
- }
1178
- if (command && event.key.toLowerCase() === "f") {
1179
- event.preventDefault();
1180
- setShowSearch(true);
1181
- return;
1182
- }
1183
- if (command && event.key.toLowerCase() === "c" && editable && selected.size === 1) {
1184
- event.preventDefault();
1185
- copy();
1186
- return;
1187
- }
1188
- if (command && event.key.toLowerCase() === "v" && editable) {
1189
- event.preventDefault();
1190
- void paste();
1191
- return;
1192
- }
1193
- if ((command || event.altKey) && event.key === ".") {
1194
- event.preventDefault();
1195
- fold(active);
1196
- return;
1197
- }
1198
- if (view) {
1199
- event.preventDefault();
1200
- paneCommand(view);
1201
- return;
1202
- }
1203
- if ((event.key === "Delete" || event.key === "Backspace") && editable && !command && !event.altKey && selected.size) {
1204
- event.preventDefault();
1205
- if (!event.repeat) remove();
1206
- return;
1207
- }
1208
- if (!editable || selected.size !== 1) return;
1209
- if (event.key === "Tab") {
1210
- event.preventDefault();
1211
- add(event.shiftKey ? "parent" : "child");
1212
- } else if (event.key === "Enter") {
1213
- event.preventDefault();
1214
- add("sibling");
1215
- } else if (event.key === "F2") {
1216
- event.preventDefault();
1217
- edit(active);
1218
- } else if (event.altKey && ["ArrowUp", "ArrowDown"].includes(event.key)) {
1219
- const siblings = tree.filter((topic) => topic.parentId === current.parentId), index = siblings.findIndex((topic) => topic.id === active), target = siblings[index + (event.key === "ArrowUp" ? -1 : 1)];
1220
- if (target) c == null ? void 0 : c.move(active, target.id, event.key === "ArrowUp" ? "before" : "after");
1221
- event.preventDefault();
1222
- } else if (event.key.startsWith("Arrow")) {
1223
- event.preventDefault();
1224
- const branchSide = ((_b2 = drawing.nodes.find((topic) => topic.id === active)) == null ? void 0 : _b2.side) ?? 1;
1225
- const inward = model.layout === "down" ? "ArrowUp" : branchSide === 1 ? "ArrowLeft" : "ArrowRight";
1226
- const outward = model.layout === "down" ? "ArrowDown" : branchSide === 1 ? "ArrowRight" : "ArrowLeft";
1227
- const siblings = drawing.nodes.filter((topic) => topic.parentId === current.parentId), index = siblings.findIndex((topic) => topic.id === active);
1228
- const target = event.key === inward ? current.parentId : event.key === outward ? (_c2 = drawing.nodes.find((topic) => topic.parentId === active)) == null ? void 0 : _c2.id : (_d2 = siblings[index + (event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : 1)]) == null ? void 0 : _d2.id;
1229
- if (target) select(target);
1230
- }
1231
- }
1232
- function cancelGesture(restore = true) {
1233
- const current2 = gesture.current;
1234
- if (restore && (current2 == null ? void 0 : current2.kind) === "box") {
1235
- setSelected(current2.selected);
1236
- setActive(current2.active);
1237
- }
1238
- gesture.current = null;
1239
- setBox(null);
1240
- setDrop(null);
1241
- setDragPreview(null);
1242
- }
1243
- function pointerDown(event, id) {
1244
- var _a2, _b2;
1245
- if (!((_a2 = stage.current) == null ? void 0 : _a2.contains(event.target))) return;
1246
- if (event.target.closest("button,input,textarea,a")) return;
1247
- setFollowing(null);
1248
- setContextMenu(null);
1249
- const base = { x: event.clientX, y: event.clientY, lastX: event.clientX, lastY: event.clientY, doc: JSON.stringify(model), count: selected.size, selected: new Set(selected), active };
1250
- if (id && event.button === 0 && !moving && !space.current) {
1251
- const additive = event.shiftKey || event.metaKey || event.ctrlKey;
1252
- const next = selected.has(id) && selected.size > 1 && !additive ? selected : selectMindTopic(selected, id, additive);
1253
- setSelected(next);
1254
- setActive(next.has(id) ? id : [...next].at(-1) ?? model.rootId);
1255
- gesture.current = { ...base, kind: "node", id, count: next.size, additive };
1256
- } else if (event.button === 1 || event.button === 0 && (moving || space.current)) gesture.current = { ...base, kind: "pan" };
1257
- else if (!id && event.button === 0) {
1258
- gesture.current = { ...base, kind: "box", additive: event.shiftKey || event.metaKey || event.ctrlKey };
1259
- if (!gesture.current.additive) setSelected(/* @__PURE__ */ new Set());
1260
- } else return;
1261
- event.currentTarget.setPointerCapture(event.pointerId);
1262
- (_b2 = stage.current) == null ? void 0 : _b2.focus();
1263
- event.preventDefault();
1264
- }
1265
- function pointerMove(event) {
1266
- const g = gesture.current;
1267
- if (!g) return;
1268
- if (g.doc !== JSON.stringify(currentRef.current.model)) {
1269
- cancelGesture();
1270
- return;
1271
- }
1272
- if (g.kind === "pan") {
1273
- const dx = event.clientX - g.lastX, dy = event.clientY - g.lastY;
1274
- setPan((previous) => ({ x: previous.x + dx, y: previous.y + dy }));
1275
- } else if (g.kind === "box") {
1276
- const from = point(g.x, g.y), to = point(event.clientX, event.clientY);
1277
- g.box = { x: Math.min(from.x, to.x), y: Math.min(from.y, to.y), w: Math.abs(to.x - from.x), h: Math.abs(to.y - from.y) };
1278
- setBox(g.box);
1279
- setSelected(topicsInMarquee(drawing.nodes, { x: g.box.x, y: g.box.y, width: g.box.w, height: g.box.h }, g.additive ? g.selected : []));
1280
- } else if (editable && g.id && g.id !== model.rootId && g.count === 1 && Math.hypot(event.clientX - g.x, event.clientY - g.y) > 8) {
1281
- g.drop = mindMapDrop(viewModel, drawing, g.id, point(event.clientX, event.clientY), !focusId);
1282
- setDrop(g.drop);
1283
- setDragPreview({ id: g.id, dx: (event.clientX - g.x) / zoom, dy: (event.clientY - g.y) / zoom });
1284
- }
1285
- g.lastX = event.clientX;
1286
- g.lastY = event.clientY;
1287
- }
1288
- function pointerUp() {
1289
- const g = gesture.current;
1290
- if (!g) return;
1291
- cancelGesture(false);
1292
- if (g.doc !== JSON.stringify(currentRef.current.model)) return;
1293
- const bounds = g.box;
1294
- if (g.kind === "box" && bounds) {
1295
- const ids = topicsInMarquee(drawing.nodes, { x: bounds.x, y: bounds.y, width: bounds.w, height: bounds.h }, g.additive ? g.selected : []);
1296
- setSelected(ids);
1297
- if (ids.size) setActive([...ids].at(-1));
1298
- } else if (g.kind === "node" && g.id && g.drop && editable) {
1299
- if (g.drop.kind === "side") c == null ? void 0 : c.moveToSide(g.id, g.drop.side, g.drop.beforeId);
1300
- else c == null ? void 0 : c.move(g.id, g.drop.id, g.drop.mode);
1301
- } else if (g.kind === "node" && g.id && g.count > 1 && !g.additive && Math.hypot(g.lastX - g.x, g.lastY - g.y) < 8) {
1302
- setSelected(/* @__PURE__ */ new Set([g.id]));
1303
- setActive(g.id);
1304
- }
1305
- }
1306
- async function exportAs(kind) {
1307
- var _a2, _b2;
1308
- if (!canExport || exportRunning.current) return;
1309
- if (host.exports && kind !== "copy" && kind !== "copy-image") {
1310
- exportRunning.current = true;
1311
- setBusy(true);
1312
- try {
1313
- await host.exports.request({
1314
- kind: "mindmap",
1315
- format: kind === "md" ? "markdown" : kind === "print" ? "pdf" : kind,
1316
- resourceId: props.pageId ?? (c == null ? void 0 : c.context.pageId),
1317
- blockId: model.id
1318
- });
1319
- } catch (error) {
1320
- setNotice(error instanceof Error ? error.message : "导出失败");
1321
- } finally {
1322
- exportRunning.current = false;
1323
- setBusy(false);
1324
- }
1325
- return;
1326
- }
1327
- exportRunning.current = true;
1328
- setBusy(true);
1329
- const target = exportBranch ? branchModel(model, active) : model;
1330
- const printWindow = kind === "print" ? window.open("", "_blank") : null;
1331
- try {
1332
- if (kind === "copy") {
1333
- await navigator.clipboard.writeText(mindMapMarkdown(target));
1334
- return;
1335
- }
1336
- const images = {};
1337
- for (const topic of target.topics) if (topic.attachmentId) {
1338
- const fetcher = props.fetchAttachment ?? (c == null ? void 0 : c.context.fetchAttachment) ?? ((_a2 = host.attachments) == null ? void 0 : _a2.fetch);
1339
- if (!fetcher) throw new Error("未配置主题图片读取服务");
1340
- const blob = await fetcher(topic.attachmentId);
1341
- images[topic.attachmentId] = await new Promise((resolve, reject) => {
1342
- const reader = new FileReader();
1343
- reader.onload = () => resolve(String(reader.result));
1344
- reader.onerror = reject;
1345
- reader.readAsDataURL(blob);
1346
- });
1347
- }
1348
- const svg = mindMapSvg(target, { transparent, images }), download = (blob, ext) => {
1349
- const url = URL.createObjectURL(blob), a = document.createElement("a");
1350
- a.href = url;
1351
- a.download = `思维导图.${ext}`;
1352
- a.click();
1353
- setTimeout(() => URL.revokeObjectURL(url), 1e3);
1354
- };
1355
- if (kind === "svg") download(new Blob([svg], { type: "image/svg+xml" }), "svg");
1356
- else if (kind === "md") download(new Blob([mindMapMarkdown(target)], { type: "text/markdown" }), "md");
1357
- else if (kind === "json") download(new Blob([JSON.stringify(mindMapToJson(target), null, 2)], { type: "application/json" }), "json");
1358
- else if (kind === "png" || kind === "copy-image" || kind === "print") {
1359
- const image = new Image(), url = URL.createObjectURL(new Blob([svg], { type: "image/svg+xml" }));
1360
- try {
1361
- await new Promise((resolve, reject) => {
1362
- image.onload = () => resolve();
1363
- image.onerror = reject;
1364
- image.src = url;
1365
- });
1366
- const canvas = document.createElement("canvas");
1367
- canvas.width = image.width * imageScale;
1368
- canvas.height = image.height * imageScale;
1369
- (_b2 = canvas.getContext("2d")) == null ? void 0 : _b2.drawImage(image, 0, 0, canvas.width, canvas.height);
1370
- const blob = await new Promise((resolve, reject) => canvas.toBlob((value) => value ? resolve(value) : reject(new Error("图片生成失败"))));
1371
- if (kind === "copy-image") await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
1372
- else if (kind === "print") {
1373
- if (!printWindow) throw new Error("打印窗口被浏览器拦截");
1374
- const img = printWindow.document.createElement("img");
1375
- img.src = canvas.toDataURL();
1376
- img.style.maxWidth = "100%";
1377
- printWindow.document.body.append(img);
1378
- img.onload = () => printWindow.print();
1379
- } else download(blob, "png");
1380
- } finally {
1381
- URL.revokeObjectURL(url);
1382
- }
1383
- }
1384
- } catch (error) {
1385
- printWindow == null ? void 0 : printWindow.close();
1386
- setNotice(String(error));
1387
- } finally {
1388
- exportRunning.current = false;
1389
- if (alive.current) setBusy(false);
1390
- }
1391
- }
1392
- const directions = mindMapBranchSides(model), firstLevel = current.parentId === model.rootId;
1393
- const menuTopic = tree.find((topic) => topic.id === (contextMenu == null ? void 0 : contextMenu.id));
1394
- const modifier = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform) ? "⌘" : "Ctrl";
1395
- const contextGroups = (contextMenu == null ? void 0 : contextMenu.id) ? [{ items: [
1396
- ...editable ? [
1397
- { value: "child", label: "添加子主题" },
1398
- { value: "sibling", label: "添加同级主题" },
1399
- ...contextMenu.id !== model.rootId ? [{ value: "parent", label: "插入父主题" }] : [],
1400
- { value: "rename", label: "修改文字" }
1401
- ] : [],
1402
- { value: "properties", label: "主题属性" },
1403
- ...contextMenu.id !== model.rootId && mindMapDescendants$1(model, contextMenu.id).size > 1 ? [{ value: "fold", label: folds.has(contextMenu.id) ? "展开分支" : "收起分支" }] : [],
1404
- ...editable && (menuTopic == null ? void 0 : menuTopic.parentId) === model.rootId && model.layout !== "down" ? [
1405
- { value: "left", label: "移到左侧", disabled: directions.get(contextMenu.id) === -1 },
1406
- { value: "right", label: "移到右侧", disabled: directions.get(contextMenu.id) === 1 }
1407
- ] : [],
1408
- { value: "focus", label: "聚焦分支" },
1409
- ...editable ? [
1410
- { value: "copy", label: "复制分支" },
1411
- { value: "paste", label: "粘贴分支", disabled: pasting },
1412
- ...contextMenu.id !== model.rootId ? [{ value: "delete", label: "删除分支" }] : []
1413
- ] : []
1414
- ] }] : [
1415
- ...editable ? [{ items: [{ value: "paste", label: "粘贴", disabled: pasting, shortcut: "⌘ / Ctrl+V" }] }] : [],
1416
- { items: [
1417
- ...pageId ? [{ value: "comments", label: comments ? "隐藏评论" : "显示评论", shortcut: "Shift+C" }] : [],
1418
- ...editable ? [{ value: "quick", label: quickControls ? "隐藏快捷创建" : "显示快捷创建", shortcut: "Shift+Q" }] : [],
1419
- { value: "grid", label: grid ? "隐藏网格" : "显示网格", shortcut: "Shift+G" }
1420
- ] },
1421
- { items: [
1422
- { value: "zoom-in", label: "放大", shortcut: `${modifier} + +` },
1423
- { value: "zoom-out", label: "缩小", shortcut: `${modifier} + −` },
1424
- { value: "reset-zoom", label: "缩放至 100%", shortcut: `${modifier} + 0` },
1425
- { value: "fit", label: "画布全览", shortcut: "Shift+1" }
1426
- ] }
1427
- ];
1428
- const workspace = /* @__PURE__ */ jsxs("div", { className: "mind-map-workspace", ref: root, onKeyDown: keydown, onPaste: nativePaste, style: { "--mind-color": color }, children: [
1429
- editable && !status && props.showSaveHint !== false && /* @__PURE__ */ jsx(WAlert, { closable: true, closeLabel: "关闭保存提示", className: "mind-save-hint", children: "编辑完成后,请确认已保存再离开。" }),
1430
- /* @__PURE__ */ jsxs("header", { className: "mind-canvas-toolbar", children: [
1431
- /* @__PURE__ */ jsxs("div", { className: "mind-canvas-tools", children: [
1432
- !props.inline && props.onClose && /* @__PURE__ */ jsx(WButton, { onClick: props.onClose, children: "返回文档" }),
1433
- /* @__PURE__ */ jsx(
1434
- WDropdown,
1435
- {
1436
- label: "展开与收起",
1437
- groups: [{ items: [{ value: "expand", label: "全部展开" }, { value: "first-level", label: "收起至一级" }] }],
1438
- onSelect: (value) => setFolds(value === "expand" ? /* @__PURE__ */ new Set() : firstLevelMindFolds(viewModel))
1439
- }
1440
- ),
1441
- /* @__PURE__ */ jsx(WButton, { ref: settingsTrigger, "aria-expanded": settingsOpen, onClick: () => setSettingsOpen(!settingsOpen), children: "视图与导出设置" }),
1442
- settingsOpen && /* @__PURE__ */ jsx(AnchoredPanel, { anchor: settingsTrigger.current, onClose: () => setSettingsOpen(false), align: "center", gap: 6, label: "视图与导出设置", className: "mind-dropdown-popup", children: /* @__PURE__ */ jsxs("div", { className: "mind-settings-menu", children: [
1443
- peers.map((peer) => {
1444
- var _a2, _b2;
1445
- return /* @__PURE__ */ jsxs("span", { className: "mind-peer", children: [
1446
- /* @__PURE__ */ jsxs("span", { children: [
1447
- peer.name,
1448
- peer.editing ? " 正在编辑" : " 正在查看",
1449
- " ",
1450
- (_b2 = (_a2 = model.topics.find((topic) => topic.id === peer.topicId)) == null ? void 0 : _a2.text) == null ? void 0 : _b2.slice(0, 12)
1451
- ] }),
1452
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => followPeer(peer.client), children: "跟随" })
1453
- ] }, peer.client);
1454
- }),
1455
- following !== null && /* @__PURE__ */ jsx(WButton, { onClick: () => followPeer(null), children: "停止跟随" }),
1456
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => {
1457
- const id = focusId ? null : active;
1458
- setFocusId(id);
1459
- fit(id ? branchModel(model, id) : model);
1460
- }, children: focusId ? "返回全图" : "聚焦分支" }),
1461
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => void copyTopicLink(), children: "复制主题链接" }),
1462
- editable && /* @__PURE__ */ jsx(WSelect, { label: "分支线型", ariaLabel: "分支线型", width: 95, value: model.branchStyle ?? "curve", onChange: (value) => c == null ? void 0 : c.settings({ branchStyle: value }), options: ["curve", "straight", "step"].map((value, i) => ({ value, label: ["曲线", "直线", "折线"][i] })) }),
1463
- canExport && /* @__PURE__ */ jsxs(Fragment, { children: [
1464
- /* @__PURE__ */ jsxs("label", { children: [
1465
- /* @__PURE__ */ jsx("input", { type: "checkbox", checked: exportBranch, onChange: (event) => setExportBranch(event.target.checked) }),
1466
- "仅导出选中分支"
1467
- ] }),
1468
- /* @__PURE__ */ jsxs("label", { children: [
1469
- /* @__PURE__ */ jsx("input", { type: "checkbox", checked: transparent, onChange: (event) => setTransparent(event.target.checked) }),
1470
- "透明背景"
1471
- ] }),
1472
- /* @__PURE__ */ jsx(WSelect, { label: "图片分辨率", ariaLabel: "图片分辨率", width: 90, value: imageScale, onChange: (value) => setImageScale(Number(value)), options: [1, 2, 3].map((value) => ({ value, label: `${value} 倍图片` })) })
1473
- ] }),
1474
- canExport && /* @__PURE__ */ jsxs(Fragment, { children: [
1475
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => void exportAs("copy-image"), children: "复制图片" }),
1476
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => void exportAs("print"), children: host.exports ? "导出 PDF" : "打印 / PDF" })
1477
- ] })
1478
- ] }) }),
1479
- peers.length > 0 && /* @__PURE__ */ jsx(
1480
- WDropdown,
1481
- {
1482
- label: `协作(${peers.length})`,
1483
- buttonProps: { variant: "text" },
1484
- groups: [{ items: peers.map((peer) => ({ value: String(peer.client), label: `${peer.name}${peer.editing ? " 正在编辑" : " 正在查看"} · 跟随` })) }],
1485
- onSelect: (value) => followPeer(Number(value))
1486
- }
1487
- )
1488
- ] }),
1489
- /* @__PURE__ */ jsxs("div", { className: "mind-canvas-tools mind-canvas-options", children: [
1490
- status || !editable ? /* @__PURE__ */ jsx("span", { className: "mind-canvas-status", role: "status", "aria-label": "保存状态", children: status || "只读" }) : null,
1491
- editable && /* @__PURE__ */ jsxs(Fragment, { children: [
1492
- /* @__PURE__ */ jsx(WSelect, { label: "导图布局", ariaLabel: "导图布局", width: 94, value: model.layout, onChange: (value) => c == null ? void 0 : c.settings({ layout: value }), options: ["right", "left", "both", "down"].map((value, i) => ({ value, label: ["向右", "向左", "双侧", "向下"][i] })) }),
1493
- /* @__PURE__ */ jsx(WSelect, { label: "导图主题", ariaLabel: "导图主题", width: 94, value: model.theme, onChange: (value) => c == null ? void 0 : c.settings({ theme: value }), options: ["blue", "teal", "violet", "amber"].map((value, i) => ({ value, label: ["靛蓝", "青绿", "紫藤", "琥珀"][i] })) }),
1494
- /* @__PURE__ */ jsx(WSelect, { label: "正文预览高度", ariaLabel: "正文预览高度", width: 114, value: model.height, onChange: (value) => c == null ? void 0 : c.settings({ height: Number(value) }), options: [280, 380, 520].map((value, index) => ({ value, label: ["预览 · 紧凑", "预览 · 标准", "预览 · 宽松"][index] })) })
1495
- ] }),
1496
- /* @__PURE__ */ jsx(WButton, { onClick: () => setShowSearch(!showSearch), children: "查找替换" }),
1497
- !editable && host.comments && pageId && /* @__PURE__ */ jsx(WButton, { variant: comments ? "primary" : "default", "aria-pressed": comments, onClick: () => {
1498
- setComments(!comments);
1499
- setDetails(false);
1500
- }, children: comments ? "收起讨论" : "查看讨论" }),
1501
- /* @__PURE__ */ jsx(WDropdown, { label: "更多", groups: [{ items: [
1502
- { value: "outline", label: outline ? "隐藏文字大纲" : "显示文字大纲" },
1503
- { value: "details", label: "主题属性" },
1504
- ...host.comments && pageId ? [{ value: "comments", label: comments ? "隐藏主题讨论" : "主题讨论" }] : [],
1505
- ...editable ? [{ value: "import", label: "导入" }] : []
1506
- ] }], onSelect: (value) => {
1507
- if (value === "outline") setOutline(!outline);
1508
- else if (value === "details") {
1509
- setDetails(!details);
1510
- setComments(false);
1511
- } else if (value === "comments") {
1512
- setComments(!comments);
1513
- setDetails(false);
1514
- } else if (value === "import") setImportOpen(true);
1515
- } }),
1516
- canExport && /* @__PURE__ */ jsx(
1517
- WSelect,
1518
- {
1519
- label: "导出",
1520
- ariaLabel: "导出思维导图",
1521
- width: 105,
1522
- value: "",
1523
- disabled: busy,
1524
- onChange: (value) => void exportAs(value),
1525
- options: [{ value: "png", label: "PNG 图片" }, { value: "svg", label: "SVG 图片" }, { value: "md", label: "文字大纲" }, { value: "json", label: "结构 JSON" }]
1526
- }
1527
- )
1528
- ] })
1529
- ] }),
1530
- showSearch && /* @__PURE__ */ jsxs("div", { className: "mind-search", "aria-label": "图内查找替换", children: [
1531
- /* @__PURE__ */ jsx("input", { "aria-label": "查找导图文字", placeholder: "查找主题、描述和备注", value: query, onChange: (event) => {
1532
- setQuery(event.target.value);
1533
- setHitIndex(0);
1534
- }, onKeyDown: (event) => {
1535
- if (event.key === "Enter") {
1536
- event.preventDefault();
1537
- jumpHit(1);
1538
- }
1539
- } }),
1540
- /* @__PURE__ */ jsxs("span", { children: [
1541
- hits.length > 5e3 ? "5000+" : hits.length,
1542
- " 处"
1543
- ] }),
1544
- /* @__PURE__ */ jsx(WButton, { disabled: !hits.length, onClick: () => jumpHit(-1), children: "上一处" }),
1545
- /* @__PURE__ */ jsx(WButton, { disabled: !hits.length, onClick: () => jumpHit(1), children: "下一处" }),
1546
- hits.length > 0 && /* @__PURE__ */ jsx(
1547
- WSelect,
1548
- {
1549
- label: "导图搜索结果",
1550
- ariaLabel: "导图搜索结果",
1551
- width: 180,
1552
- value: hitIndex,
1553
- options: hits.slice(0, 500).map((hit, index) => {
1554
- var _a2, _b2;
1555
- return { value: index, label: `${index + 1}. ${((_b2 = (_a2 = tree.find((topic) => topic.id === hit.id)) == null ? void 0 : _a2.text) == null ? void 0 : _b2.slice(0, 24)) ?? ""} · ${hit.field === "title" ? "标题" : hit.field === "note" ? "备注" : "描述"}` };
1556
- }),
1557
- onChange: (value) => {
1558
- const index = Number(value);
1559
- const hit = hits[index];
1560
- if (hit) {
1561
- setHitIndex(index);
1562
- locateHit(hit);
1563
- }
1564
- }
1565
- }
1566
- ),
1567
- editable && /* @__PURE__ */ jsxs(Fragment, { children: [
1568
- /* @__PURE__ */ jsx("input", { "aria-label": "替换为", placeholder: "替换为", value: replacement, onChange: (event) => setReplacement(event.target.value) }),
1569
- /* @__PURE__ */ jsx(WButton, { disabled: !hits.length, onClick: () => {
1570
- const count = c == null ? void 0 : c.replace(query, replacement, hits[hitIndex]);
1571
- setNotice(count === -1 ? "匹配超过 5000 处,请缩小查找范围" : count === -2 ? "替换后文字超过上限,本次未修改" : `已替换 ${count ?? 0} 处`);
1572
- }, children: "替换当前" }),
1573
- /* @__PURE__ */ jsx(WButton, { disabled: !hits.length, onClick: () => {
1574
- const count = c == null ? void 0 : c.replace(query, replacement);
1575
- setNotice(count === -1 ? "匹配超过 5000 处,请缩小查找范围" : count === -2 ? "替换后文字超过上限,本次未修改" : `已替换 ${count ?? 0} 处`);
1576
- }, children: "全部替换" })
1577
- ] }),
1578
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => setShowSearch(false), children: "关闭" })
1579
- ] }),
1580
- /* @__PURE__ */ jsxs("div", { className: "mind-canvas-body", children: [
1581
- outline && /* @__PURE__ */ jsx("aside", { className: "mind-canvas-outline", "aria-label": "导图文字大纲", children: mindMapOutline(model).map((topic) => /* @__PURE__ */ jsxs("div", { className: `mind-outline-row${topic.id === active ? " current" : ""}`, style: { paddingLeft: 8 + Math.min(12, topic.depth) * 14 }, children: [
1582
- editable ? /* @__PURE__ */ jsx(
1583
- MindMapField,
1584
- {
1585
- id: topic.id,
1586
- field: "title",
1587
- value: topic.text,
1588
- controller: c,
1589
- label: `大纲主题 ${topic.text || "未命名"}`,
1590
- onFocus: () => {
1591
- setActive(topic.id);
1592
- setSelected(/* @__PURE__ */ new Set([topic.id]));
1593
- },
1594
- onCommand: (event) => {
1595
- if (event.key === "Tab") {
1596
- event.preventDefault();
1597
- c == null ? void 0 : c.indent(topic.id, event.shiftKey);
1598
- } else if (event.key === "Enter" && !event.shiftKey) {
1599
- event.preventDefault();
1600
- add("sibling", void 0, topic.id);
1601
- }
1602
- }
1603
- }
1604
- ) : /* @__PURE__ */ jsx("button", { type: "button", onClick: () => locate(topic.id), children: topic.text }),
1605
- /* @__PURE__ */ jsx("button", { type: "button", title: "定位主题", "aria-label": `定位大纲主题:${topic.text}`, onClick: () => locate(topic.id), children: "⌖" })
1606
- ] }, topic.id)) }),
1607
- /* @__PURE__ */ jsxs(
1608
- "div",
1609
- {
1610
- ref: stage,
1611
- tabIndex: 0,
1612
- "aria-label": "思维导图画布",
1613
- className: `mind-canvas-stage${grid ? "" : " mind-grid-hidden"}${moving || spaceHeld ? " mind-space-pan" : ""}`,
1614
- onPointerDown: (event) => pointerDown(event),
1615
- onPointerMove: pointerMove,
1616
- onPointerUp: pointerUp,
1617
- onPointerCancel: () => cancelGesture(),
1618
- onLostPointerCapture: () => cancelGesture(),
1619
- onContextMenu: (event) => {
1620
- var _a2;
1621
- const id = ((_a2 = event.target.closest("[data-topic-id]")) == null ? void 0 : _a2.dataset.topicId) ?? null;
1622
- openContextMenu(id, event);
1623
- },
1624
- onWheel: (event) => {
1625
- setFollowing(null);
1626
- if (event.ctrlKey || event.metaKey) {
1627
- const rect = stage.current.getBoundingClientRect();
1628
- zoomTo(zoom * Math.exp(-event.deltaY * 2e-3), { x: event.clientX - rect.left, y: event.clientY - rect.top });
1629
- } else setPan((value) => ({ x: value.x - event.deltaX, y: value.y - event.deltaY }));
1630
- },
1631
- children: [
1632
- /* @__PURE__ */ jsx("div", { className: "mind-canvas-surface", children: /* @__PURE__ */ jsxs("div", { className: "mind-canvas-layers", style: { transform: `translate(${origin.x}px,${origin.y}px) scale(${zoom})` }, children: [
1633
- /* @__PURE__ */ jsxs("svg", { className: "mind-canvas-edges", children: [
1634
- drawing.edges.map((edge) => /* @__PURE__ */ jsx("path", { d: edge.path, className: draggedIds.has(edge.target) ? "mind-drag-branch-edge" : void 0, stroke: color, strokeWidth: 2, fill: "none" }, edge.id)),
1635
- mindRelationPaths(model, drawing).map((relation) => /* @__PURE__ */ jsxs("g", { children: [
1636
- /* @__PURE__ */ jsx("path", { d: relation.path, stroke: "#9a68d4", strokeWidth: 2, strokeDasharray: "6 4", fill: "none" }),
1637
- /* @__PURE__ */ jsx("text", { x: relation.x, y: relation.y, fill: "var(--color-text)", fontSize: 12, children: relation.label || { related: "相关", depends: "依赖", reference: "参考" }[relation.kind] })
1638
- ] }, relation.id)),
1639
- projection && /* @__PURE__ */ jsxs("g", { className: "mind-side-projection", children: [
1640
- projection.edges.filter((edge) => draggedIds.has(edge.source) || draggedIds.has(edge.target)).map((edge) => /* @__PURE__ */ jsx("path", { d: edge.path, stroke: color, fill: "none", strokeWidth: 2, strokeDasharray: "5 4" }, edge.id)),
1641
- projection.nodes.filter((topic) => draggedIds.has(topic.id)).map((topic) => /* @__PURE__ */ jsxs("g", { children: [
1642
- /* @__PURE__ */ jsx("rect", { x: topic.x, y: topic.y, width: topic.width, height: topic.height, rx: 8, fill: "var(--color-accent-soft)", stroke: color, strokeDasharray: "5 4" }),
1643
- /* @__PURE__ */ jsx("text", { x: topic.x + topic.width / 2, y: topic.y + topic.height / 2 + 5, textAnchor: "middle", fontSize: 14, fill: "var(--color-text)", children: topic.text.slice(0, 24) })
1644
- ] }, topic.id))
1645
- ] })
1646
- ] }),
1647
- drawing.nodes.map((topic) => {
1648
- const hasChildren = tree.some((child) => child.parentId === topic.id);
1649
- const quick = quickControls && !moving && !spaceHeld && !dragPreview && !box && editable && selected.has(topic.id) && selected.size === 1 && editing !== topic.id;
1650
- const side = topic.side ?? 1;
1651
- const grows = model.layout === "down" ? "grows-down" : side === -1 ? "grows-left" : "";
1652
- return /* @__PURE__ */ jsxs(
1653
- "div",
1654
- {
1655
- "data-topic-id": topic.id,
1656
- className: `mind-topic-shell${topic.id === model.rootId ? " root" : ""}${selected.has(topic.id) ? " is-selected" : ""}${hasChildren ? " has-children" : ""}${grows ? ` ${grows}` : ""}${folds.has(topic.id) ? " is-collapsed" : ""}`,
1657
- style: { position: "absolute", left: topic.x, top: topic.y, width: topic.width, height: topic.height, transform: dragPreview && draggedIds.has(topic.id) ? `translate(${dragPreview.dx}px,${dragPreview.dy}px)` : void 0, opacity: dragPreview && draggedIds.has(topic.id) ? 0.35 : void 0 },
1658
- children: [
1659
- /* @__PURE__ */ jsxs(
1660
- "div",
1661
- {
1662
- className: `mind-topic${topic.id === model.rootId ? " root" : ""}${selected.has(topic.id) ? " active" : ""}${editing === topic.id ? " editing" : ""}${grows ? ` ${grows}` : ""}${(drop == null ? void 0 : drop.id) === topic.id ? ` drop mind-drop-${drop.mode}` : ""}`,
1663
- style: {
1664
- width: "100%",
1665
- minHeight: topic.height,
1666
- fontFamily: MIND_TOPIC_FONT,
1667
- "--mind-topic-line-height": `${mindTopicLineHeight(topic.fontSize || 14)}px`,
1668
- color: topic.color || (topic.shape === "text" ? "var(--color-text)" : topic.background ? readableTextColor(topic.background) : void 0),
1669
- background: topic.shape === "text" ? "transparent" : topic.background || void 0,
1670
- borderRadius: topic.shape === "pill" ? 28 : void 0,
1671
- border: topic.shape === "text" ? 0 : void 0,
1672
- fontSize: topic.fontSize || 14,
1673
- textAlign: topic.align || "center"
1674
- },
1675
- onPointerDown: (event) => {
1676
- event.stopPropagation();
1677
- pointerDown(event, topic.id);
1678
- },
1679
- onDoubleClick: () => edit(topic.id),
1680
- onContextMenu: (event) => openContextMenu(topic.id, event),
1681
- children: [
1682
- (topic.icon || topic.done) && /* @__PURE__ */ jsxs("span", { className: "mind-topic-icon", children: [
1683
- topic.done ? "☑ " : "",
1684
- topic.icon
1685
- ] }),
1686
- editing === topic.id ? /* @__PURE__ */ jsx(
1687
- "textarea",
1688
- {
1689
- ref: input,
1690
- className: "mind-topic-input",
1691
- "aria-label": "主题文字",
1692
- rows: Math.max(1, topic.lines.length),
1693
- maxLength: 2e3,
1694
- value: text,
1695
- onChange: (event) => {
1696
- if (c == null ? void 0 : c.text(topic.id, event.target.value)) setText(event.target.value);
1697
- },
1698
- onSelect: (event) => {
1699
- const target = event.currentTarget;
1700
- setSelectedRange({ from: target.selectionStart ?? 0, to: target.selectionEnd ?? 0 });
1701
- },
1702
- onKeyUp: (event) => {
1703
- const target = event.currentTarget;
1704
- setSelectedRange({ from: target.selectionStart ?? 0, to: target.selectionEnd ?? 0 });
1705
- },
1706
- onCompositionStart: () => {
1707
- composing.current = true;
1708
- c == null ? void 0 : c.composition(true);
1709
- },
1710
- onCompositionEnd: (event) => {
1711
- c == null ? void 0 : c.text(topic.id, event.currentTarget.value);
1712
- composing.current = false;
1713
- c == null ? void 0 : c.composition(false);
1714
- c == null ? void 0 : c.beginText(topic.id);
1715
- },
1716
- onKeyDown: (event) => {
1717
- event.stopPropagation();
1718
- if (event.nativeEvent.isComposing || composing.current || event.keyCode === 229) return;
1719
- if ((event.metaKey || event.ctrlKey) && ["z", "y"].includes(event.key.toLowerCase())) {
1720
- event.preventDefault();
1721
- event.shiftKey || event.key.toLowerCase() === "y" ? c == null ? void 0 : c.redo() : c == null ? void 0 : c.undo();
1722
- return;
1723
- }
1724
- if (event.key === "Escape" || event.key === "Enter" && !event.shiftKey) {
1725
- event.preventDefault();
1726
- edit(null);
1727
- } else if (event.key === "Tab") {
1728
- event.preventDefault();
1729
- c == null ? void 0 : c.endText(topic.id);
1730
- add("child", void 0, topic.id);
1731
- }
1732
- },
1733
- onBlur: () => {
1734
- c == null ? void 0 : c.composition(false);
1735
- c == null ? void 0 : c.endText(topic.id);
1736
- setEditing(null);
1737
- }
1738
- }
1739
- ) : /* @__PURE__ */ jsx("div", { className: "mind-topic-label", style: { textAlign: topic.align || "center", minHeight: topic.lines.length * mindTopicLineHeight(topic.fontSize || 14) }, children: /* @__PURE__ */ jsx(TopicLabel, { topic }) }),
1740
- topic.description && /* @__PURE__ */ jsx("div", { className: "mind-topic-description", style: topic.shape === "text" ? { color: "var(--color-text-muted)" } : topic.background ? { color: readableTextColor(topic.background) } : void 0, children: topic.description }),
1741
- topic.note && /* @__PURE__ */ jsx("div", { className: "mind-topic-note", title: "此主题有备注", onClick: (event) => {
1742
- event.stopPropagation();
1743
- select(topic.id);
1744
- setDetails(true);
1745
- }, children: "▤ 备注" }),
1746
- topic.attachmentId && /* @__PURE__ */ jsx("div", { className: "mind-topic-image", children: /* @__PURE__ */ jsx(AttachmentImage, { id: topic.attachmentId, alt: "主题图片", fetcher: props.fetchAttachment }) }),
1747
- peers.filter((peer) => peer.topicId === topic.id).map((peer) => /* @__PURE__ */ jsx("span", { className: "mind-peer-badge", title: `${peer.name}${peer.editing ? " 正在编辑" : ""}`, "aria-label": `${peer.name}${peer.editing ? " 正在编辑此主题" : " 正在查看此主题"}`, children: peer.name.slice(0, 2) }, peer.client))
1748
- ]
1749
- }
1750
- ),
1751
- quick && topic.id !== model.rootId && /* @__PURE__ */ jsx(
1752
- "button",
1753
- {
1754
- type: "button",
1755
- className: "mind-topic-sibling before",
1756
- "aria-label": model.layout === "down" ? "在左侧添加同级主题" : "在上方添加同级主题",
1757
- title: model.layout === "down" ? "在左侧添加同级主题" : "在上方添加同级主题",
1758
- onPointerDown: (event) => event.stopPropagation(),
1759
- onClick: (event) => {
1760
- event.stopPropagation();
1761
- addSiblingAt(topic.id, "before");
1762
- },
1763
- children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "+" })
1764
- }
1765
- ),
1766
- quick && topic.id === model.rootId && model.layout !== "down" && /* @__PURE__ */ jsxs(Fragment, { children: [
1767
- /* @__PURE__ */ jsx(
1768
- "button",
1769
- {
1770
- type: "button",
1771
- className: "mind-topic-add root-left",
1772
- "aria-label": "在中心主题左侧添加子主题",
1773
- title: "在左侧添加子主题",
1774
- onPointerDown: (event) => event.stopPropagation(),
1775
- onClick: (event) => {
1776
- event.stopPropagation();
1777
- add("child", -1);
1778
- },
1779
- children: "+"
1780
- }
1781
- ),
1782
- /* @__PURE__ */ jsx(
1783
- "button",
1784
- {
1785
- type: "button",
1786
- className: "mind-topic-add root-right",
1787
- "aria-label": "在中心主题右侧添加子主题",
1788
- title: "在右侧添加子主题",
1789
- onPointerDown: (event) => event.stopPropagation(),
1790
- onClick: (event) => {
1791
- event.stopPropagation();
1792
- add("child", 1);
1793
- },
1794
- children: "+"
1795
- }
1796
- )
1797
- ] }),
1798
- quick && (topic.id !== model.rootId || model.layout === "down") && /* @__PURE__ */ jsx(
1799
- "button",
1800
- {
1801
- type: "button",
1802
- className: "mind-topic-add",
1803
- "aria-label": "为当前主题添加子主题",
1804
- title: "添加子主题",
1805
- onPointerDown: (event) => event.stopPropagation(),
1806
- onClick: (event) => {
1807
- event.stopPropagation();
1808
- add("child");
1809
- },
1810
- children: "+"
1811
- }
1812
- ),
1813
- quick && topic.id !== model.rootId && /* @__PURE__ */ jsx(
1814
- "button",
1815
- {
1816
- type: "button",
1817
- className: "mind-topic-sibling after",
1818
- "aria-label": model.layout === "down" ? "在右侧添加同级主题" : "在下方添加同级主题",
1819
- title: model.layout === "down" ? "在右侧添加同级主题" : "在下方添加同级主题",
1820
- onPointerDown: (event) => event.stopPropagation(),
1821
- onClick: (event) => {
1822
- event.stopPropagation();
1823
- addSiblingAt(topic.id, "after");
1824
- },
1825
- children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "+" })
1826
- }
1827
- ),
1828
- hasChildren && topic.id !== model.rootId && editing !== topic.id && /* @__PURE__ */ jsx(
1829
- "button",
1830
- {
1831
- type: "button",
1832
- className: "mind-topic-fold",
1833
- "aria-label": folds.has(topic.id) ? `展开分支:${topic.text}(隐藏 ${mindMapDescendants$1(model, topic.id).size - 1} 个主题)` : `收起分支:${topic.text}`,
1834
- title: folds.has(topic.id) ? `展开分支,共 ${mindMapDescendants$1(model, topic.id).size - 1} 个后代主题` : "收起子分支",
1835
- "aria-expanded": !folds.has(topic.id),
1836
- onClick: (event) => {
1837
- event.stopPropagation();
1838
- fold(topic.id);
1839
- },
1840
- children: folds.has(topic.id) ? /* @__PURE__ */ jsx("span", { className: "mind-fold-count", children: mindMapDescendants$1(model, topic.id).size - 1 }) : /* @__PURE__ */ jsx("svg", { className: "mind-fold-chevron", width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m10 4-4 4 4 4", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) })
1841
- }
1842
- )
1843
- ]
1844
- },
1845
- topic.id
1846
- );
1847
- })
1848
- ] }) }),
1849
- box && /* @__PURE__ */ jsx("div", { className: "mind-marquee", "aria-hidden": "true", style: {
1850
- left: origin.x + box.x * zoom,
1851
- top: origin.y + box.y * zoom,
1852
- width: box.w * zoom,
1853
- height: box.h * zoom
1854
- } }),
1855
- editable && selected.size === 1 && !editing && !dragPreview && !box && /* @__PURE__ */ jsxs("div", { className: "mind-node-actions", "aria-label": "主题操作", children: [
1856
- /* @__PURE__ */ jsx(WButton, { variant: "primary", onClick: () => add("child"), children: "+ 子主题" }),
1857
- /* @__PURE__ */ jsx(WButton, { onClick: () => add("sibling"), children: "同级主题" }),
1858
- /* @__PURE__ */ jsx(WButton, { disabled: active === model.rootId, onClick: () => add("parent"), children: "父主题" }),
1859
- /* @__PURE__ */ jsx(WDropdown, { label: "调整层级", groups: [
1860
- { items: [{ value: "out", label: "提升一级" }, { value: "in", label: "缩进一级" }] },
1861
- ...firstLevel && model.layout !== "down" ? [{ title: "分支方向", items: [
1862
- { value: "left", label: "移到左侧", disabled: directions.get(active) === -1 },
1863
- { value: "right", label: "移到右侧", disabled: directions.get(active) === 1 }
1864
- ] }] : []
1865
- ], onSelect: (value) => value === "left" ? moveSide(-1) : value === "right" ? moveSide(1) : c == null ? void 0 : c.indent(active, value === "out") }),
1866
- /* @__PURE__ */ jsx(WButton, { onClick: () => edit(active), children: "改名" }),
1867
- /* @__PURE__ */ jsx(WButton, { onClick: () => copy(), children: "复制" }),
1868
- /* @__PURE__ */ jsx(WButton, { loading: pasting, onClick: () => void paste(), children: "粘贴" }),
1869
- host.comments && pageId && /* @__PURE__ */ jsx(WButton, { variant: comments ? "primary" : "default", "aria-pressed": comments, "aria-label": "主题讨论", onClick: () => {
1870
- setComments(!comments);
1871
- setDetails(false);
1872
- }, children: "讨论" }),
1873
- /* @__PURE__ */ jsx(WButton, { disabled: active === model.rootId, title: "删除主题(Delete / Backspace)", onClick: () => remove(), children: "删除" })
1874
- ] }),
1875
- selected.size > 1 && /* @__PURE__ */ jsxs("div", { className: "mind-selection-summary", role: "status", children: [
1876
- "已选择 ",
1877
- selected.size,
1878
- " 个主题",
1879
- editable && /* @__PURE__ */ jsx(WButton, { title: "删除所选主题(Delete / Backspace)", onClick: () => remove(), children: "删除所选" }),
1880
- /* @__PURE__ */ jsx(WButton, { variant: "text", onClick: () => setSelected(/* @__PURE__ */ new Set()), children: "取消选择" })
1881
- ] }),
1882
- /* @__PURE__ */ jsxs("div", { className: "mind-canvas-bottom", children: [
1883
- /* @__PURE__ */ jsxs("span", { className: "mind-canvas-hint", children: [
1884
- moving ? "移动模式:左键拖动画布" : "选择模式:左键选择 / 空白处框选",
1885
- " · 中键或空格+拖动平移 · 双指平移 / 捏合缩放 · 右键菜单"
1886
- ] }),
1887
- /* @__PURE__ */ jsxs("div", { className: "mind-canvas-viewport", children: [
1888
- editable && /* @__PURE__ */ jsxs(Fragment, { children: [
1889
- /* @__PURE__ */ jsx(WButton, { disabled: !(c == null ? void 0 : c.canUndo()), onClick: () => c == null ? void 0 : c.undo(), children: "撤销" }),
1890
- /* @__PURE__ */ jsx(WButton, { disabled: !(c == null ? void 0 : c.canRedo()), onClick: () => c == null ? void 0 : c.redo(), children: "重做" })
1891
- ] }),
1892
- /* @__PURE__ */ jsx("span", { className: "mind-viewport-divider", "aria-hidden": "true" }),
1893
- /* @__PURE__ */ jsx(WTooltip, { content: /* @__PURE__ */ jsxs("span", { className: "mind-viewport-tip", children: [
1894
- moving ? "切换为选择模式,左键点选或拖动框选" : "切换为移动模式,左键拖动画布",
1895
- /* @__PURE__ */ jsx("kbd", { children: "中键拖动" }),
1896
- /* @__PURE__ */ jsx("kbd", { children: "空格+拖动" }),
1897
- /* @__PURE__ */ jsx("kbd", { children: "双指平移" })
1898
- ] }), children: /* @__PURE__ */ jsx(WButton, { variant: moving ? "primary" : "text", "aria-pressed": moving, "aria-label": moving ? "切换为选择模式" : "切换为移动模式", onClick: () => {
1899
- var _a2;
1900
- setMoving(!moving);
1901
- edit(null);
1902
- cancelGesture();
1903
- setFollowing(null);
1904
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
1905
- }, children: moving ? /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M8 12V5a1.5 1.5 0 0 1 3 0v6-8a1.5 1.5 0 0 1 3 0v8-6a1.5 1.5 0 0 1 3 0v7-4a1.5 1.5 0 0 1 3 0v7c0 5-3 7-7 7-3 0-5-2-7-5l-3-5a1.5 1.5 0 0 1 2.5-1.6L8 14" }) }) : /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m5 3 14 10-7 1-3 7z" }) }) }) }),
1906
- /* @__PURE__ */ jsx(WTooltip, { content: /* @__PURE__ */ jsxs("span", { className: "mind-viewport-tip", children: [
1907
- "缩小 ",
1908
- /* @__PURE__ */ jsxs("kbd", { children: [
1909
- modifier,
1910
- " −"
1911
- ] }),
1912
- /* @__PURE__ */ jsxs("kbd", { children: [
1913
- modifier,
1914
- "+鼠标滚轮"
1915
- ] }),
1916
- /* @__PURE__ */ jsx("kbd", { children: "捏合手势" })
1917
- ] }), children: /* @__PURE__ */ jsx(WButton, { "aria-label": "缩小导图", onClick: () => paneCommand("zoom-out"), children: "−" }) }),
1918
- /* @__PURE__ */ jsx(WTooltip, { content: /* @__PURE__ */ jsxs("span", { className: "mind-viewport-tip", children: [
1919
- "缩放至 100% ",
1920
- /* @__PURE__ */ jsxs("kbd", { children: [
1921
- modifier,
1922
- " 0"
1923
- ] })
1924
- ] }), children: /* @__PURE__ */ jsxs(WButton, { variant: "text", "aria-label": "缩放至 100%", className: "mind-zoom-percent", onClick: () => paneCommand("reset-zoom"), children: [
1925
- Math.round(zoom * 100),
1926
- "%"
1927
- ] }) }),
1928
- /* @__PURE__ */ jsx(WTooltip, { content: /* @__PURE__ */ jsxs("span", { className: "mind-viewport-tip", children: [
1929
- "放大 ",
1930
- /* @__PURE__ */ jsxs("kbd", { children: [
1931
- modifier,
1932
- " +"
1933
- ] }),
1934
- /* @__PURE__ */ jsxs("kbd", { children: [
1935
- modifier,
1936
- "+鼠标滚轮"
1937
- ] }),
1938
- /* @__PURE__ */ jsx("kbd", { children: "捏合手势" })
1939
- ] }), children: /* @__PURE__ */ jsx(WButton, { "aria-label": "放大导图", onClick: () => paneCommand("zoom-in"), children: "+" }) }),
1940
- /* @__PURE__ */ jsx(WTooltip, { content: /* @__PURE__ */ jsxs("span", { className: "mind-viewport-tip", children: [
1941
- "画布全览 ",
1942
- /* @__PURE__ */ jsx("kbd", { children: "Shift+1" })
1943
- ] }), children: /* @__PURE__ */ jsx(WButton, { onClick: () => paneCommand("fit"), children: "适应画布" }) })
1944
- ] })
1945
- ] }),
1946
- (notice || drop) && /* @__PURE__ */ jsx("p", { className: "mind-canvas-notice", role: "status", children: drop ? drop.kind === "side" ? `松开后移到中心主题${drop.side === -1 ? "左" : "右"}侧,保留整条子分支` : `松开后${drop.mode === "child" ? "移入目标主题" : drop.mode === "before" ? "放到目标上方" : "放到目标下方"}` : notice })
1947
- ]
1948
- }
1949
- ),
1950
- comments && pageId && host.comments && /* @__PURE__ */ jsx(
1951
- MindMapComments,
1952
- {
1953
- pageId,
1954
- blockId: model.id,
1955
- topicId: active,
1956
- topicLabel: current.text,
1957
- canComment: props.canComment ?? ((_g = c == null ? void 0 : (_f = c.context).canComment) == null ? void 0 : _g.call(_f)),
1958
- onClose: () => setComments(false),
1959
- onChanged: props.onCommentsChanged
1960
- },
1961
- `${pageId}:${model.id}:${active}`
1962
- ),
1963
- details && /* @__PURE__ */ jsx(MindMapDetails, { model, id: active, controller: c, range: selectedRange, onClose: () => setDetails(false), onNotice: setNotice }, active)
1964
- ] }),
1965
- contextMenu && portal && createPortal(/* @__PURE__ */ jsx("div", { ref: menuRef, className: "mind-context-menu", role: "menu", tabIndex: -1, "aria-label": contextMenu.id ? "主题操作菜单" : "画布操作菜单", onKeyDown: menuKeydown, style: { left: contextMenu.x, top: contextMenu.y }, children: /* @__PURE__ */ jsx("div", { className: "w-dropdown", children: contextGroups.map((group, index) => /* @__PURE__ */ jsxs("div", { className: "w-dropdown-group", role: "group", "aria-label": group.title, children: [
1966
- group.title && /* @__PURE__ */ jsx("div", { className: "w-dropdown-group__title", children: group.title }),
1967
- group.items.map((item) => /* @__PURE__ */ jsxs(
1968
- "div",
1969
- {
1970
- role: "menuitem",
1971
- tabIndex: item.disabled ? void 0 : -1,
1972
- "aria-disabled": item.disabled || void 0,
1973
- className: `w-dropdown-option${item.disabled ? " is-disabled" : ""}`,
1974
- onClick: () => {
1975
- if (!item.disabled) contextAction(item.value);
1976
- },
1977
- onKeyDown: (event) => {
1978
- if (!item.disabled && (event.key === "Enter" || event.key === " ")) {
1979
- event.preventDefault();
1980
- contextAction(item.value);
1981
- }
1982
- },
1983
- children: [
1984
- item.label,
1985
- item.shortcut && /* @__PURE__ */ jsx("span", { className: "mind-menu-key", children: item.shortcut })
1986
- ]
1987
- },
1988
- item.value
1989
- ))
1990
- ] }, index)) }) }), portal),
1991
- confirmDelete && /* @__PURE__ */ jsxs(WDialog, { title: "删除分支", onClose: () => {
1992
- var _a2;
1993
- setConfirmDelete(null);
1994
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
1995
- }, children: [
1996
- /* @__PURE__ */ jsxs("p", { children: [
1997
- "将删除 ",
1998
- confirmDelete.ids.size,
1999
- " 个主题(包含子主题),可以撤销。中心主题保留。"
2000
- ] }),
2001
- /* @__PURE__ */ jsxs("div", { className: "wr-toolbar", children: [
2002
- /* @__PURE__ */ jsx(WButton, { onClick: () => {
2003
- var _a2;
2004
- setConfirmDelete(null);
2005
- (_a2 = stage.current) == null ? void 0 : _a2.focus();
2006
- }, children: "取消" }),
2007
- /* @__PURE__ */ jsx(WButton, { variant: "primary", onClick: () => performDelete(confirmDelete), children: "删除分支" })
2008
- ] })
2009
- ] }),
2010
- importOpen && /* @__PURE__ */ jsxs(WDialog, { title: "导入导图或列表", onClose: () => setImportOpen(false), footer: /* @__PURE__ */ jsxs(Fragment, { children: [
2011
- /* @__PURE__ */ jsx(WButton, { onClick: () => setImportOpen(false), children: "取消" }),
2012
- /* @__PURE__ */ jsx(WButton, { variant: "primary", loading: pasting, disabled: !importPreview, onClick: () => {
2013
- if (pastingRef.current || !importPreview) return;
2014
- pastingRef.current = true;
2015
- setPasting(true);
2016
- setImportError("");
2017
- void (async () => {
2018
- try {
2019
- await insertBranch(importBranch(importPreview), active);
2020
- if (alive.current) setImportOpen(false);
2021
- } catch (error) {
2022
- if (alive.current) setImportError(error instanceof Error ? error.message : "导入失败");
2023
- } finally {
2024
- pastingRef.current = false;
2025
- if (alive.current) setPasting(false);
2026
- }
2027
- })();
2028
- }, children: "导入分支" })
2029
- ] }), children: [
2030
- /* @__PURE__ */ jsx("p", { className: "mind-import-hint", children: "导入为当前主题的子分支;支持 JSON 和缩进列表。不会替换现有导图。" }),
2031
- /* @__PURE__ */ jsx("input", { "aria-label": "选择导图文件", type: "file", accept: ".json,.md,.txt", onChange: (event) => {
2032
- var _a2;
2033
- const file = (_a2 = event.target.files) == null ? void 0 : _a2[0];
2034
- if (!file) return;
2035
- if (file.size > 2e6) {
2036
- setImportError("文件超过 2 MB");
2037
- return;
2038
- }
2039
- void file.text().then((value) => {
2040
- if (alive.current) {
2041
- setImportText(value);
2042
- setImportError("");
2043
- }
2044
- }).catch(() => {
2045
- if (alive.current) setImportError("文件读取失败");
2046
- });
2047
- } }),
2048
- /* @__PURE__ */ jsx("textarea", { "aria-label": "导入内容", rows: 10, placeholder: "粘贴缩进列表或导图 JSON", style: { marginTop: 12 }, value: importText, onChange: (event) => {
2049
- setImportText(event.target.value);
2050
- setImportError("");
2051
- } }),
2052
- importPreview && /* @__PURE__ */ jsxs("p", { children: [
2053
- "识别到 ",
2054
- importPreview.topics.length,
2055
- " 个主题"
2056
- ] }),
2057
- importError && /* @__PURE__ */ jsx("p", { role: "alert", children: importError }),
2058
- /* @__PURE__ */ jsx("div", { className: "wr-toolbar", children: ["project", "meeting", "knowledge"].map((kind, index) => /* @__PURE__ */ jsx(WButton, { onClick: () => {
2059
- const id = c == null ? void 0 : c.pasteBranch(active, importBranch(mindMapTemplate(kind)));
2060
- if (id) {
2061
- select(id);
2062
- setImportOpen(false);
2063
- }
2064
- }, children: ["项目模板", "会议模板", "知识模板"][index] }, kind)) })
2065
- ] })
2066
- ] });
2067
- return props.inline ? /* @__PURE__ */ jsx("section", { className: "mind-canvas-shell mind-inline", children: workspace }) : /* @__PURE__ */ jsx(
2068
- WDialog,
2069
- {
2070
- workspace: true,
2071
- fullscreen: true,
2072
- hideFooter: true,
2073
- className: "mind-canvas-shell mind-canvas-fullscreen",
2074
- ariaLabel: "思维导图",
2075
- title: /* @__PURE__ */ jsxs("span", { className: "mind-canvas-title", children: [
2076
- "思维导图 ",
2077
- /* @__PURE__ */ jsx("span", { children: title })
2078
- ] }),
2079
- escToClose: !editing && !contextMenu && !settingsOpen && !importOpen && !confirmDelete,
2080
- onClose: () => {
2081
- var _a2;
2082
- return (_a2 = props.onClose) == null ? void 0 : _a2.call(props);
2083
- },
2084
- children: workspace
2085
- }
2086
- );
2087
- }
2088
- export {
2089
- MindMapCanvas
2090
- };