@xiangfa/mindmap 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,16 +12,17 @@ import { useNewNodeAnimation as pe } from "./hooks/useNewNodeAnimation.js";
12
12
  import { MindMapNode as me } from "./components/MindMapNode.js";
13
13
  import { MindMapControls as he } from "./components/MindMapControls.js";
14
14
  import { MindMapContextMenu as ge } from "./components/MindMapContextMenu.js";
15
+ import { MindMapAIInput as _e } from "./components/MindMapAIInput.js";
15
16
  /* empty css */
16
- import { forwardRef as l, useCallback as u, useEffect as d, useImperativeHandle as _e, useMemo as f, useRef as p, useState as m } from "react";
17
- import { Fragment as ve, jsx as h, jsxs as g } from "react/jsx-runtime";
17
+ import { forwardRef as l, useCallback as u, useEffect as d, useImperativeHandle as ve, useMemo as f, useRef as p, useState as m } from "react";
18
+ import { Fragment as ye, jsx as h, jsxs as g } from "react/jsx-runtime";
18
19
  //#region src/components/MindMap/MindMap.tsx
19
- function ye(e, t) {
20
+ function be(e, t) {
20
21
  let n = URL.createObjectURL(e), r = document.createElement("a");
21
22
  r.href = n, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
22
23
  }
23
- var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme: xe = "auto", locale: Se, messages: Ce, readonly: v = !1, toolbar: y = !0, onDataChange: we, onEvent: Te, plugins: Ee }, De) {
24
- let Oe = p(null), b = p(null), x = Ee && Ee.length > 0 ? Ee : void 0, ke = f(() => {
24
+ var _ = l(function({ data: l, markdown: _, defaultDirection: xe = "both", theme: Se = "auto", locale: Ce, messages: we, readonly: v = !1, toolbar: y = !0, ai: Te, onDataChange: Ee, onEvent: De, plugins: Oe }, ke) {
25
+ let Ae = p(null), b = p(null), x = Oe && Oe.length > 0 ? Oe : void 0, S = f(() => {
25
26
  if (l || _ === void 0) return null;
26
27
  if (x) {
27
28
  let e = s(_, x), t = e.frontMatter.direction, n = e.frontMatter.theme;
@@ -36,307 +37,307 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
36
37
  direction: void 0,
37
38
  theme: void 0
38
39
  };
39
- }, []), [S, C] = m(() => l ? oe(l) : ke ? ke.roots : [{
40
+ }, []), [C, w] = m(() => l ? oe(l) : S ? S.roots : [{
40
41
  id: "md-0",
41
42
  text: "Root"
42
- }]), [w, Ae] = m(() => ke?.direction ?? be), [T, E] = m({}), [D, O] = m(null), [k, je] = m(null), [Me, Ne] = m({}), Pe = p(null), [Fe, Ie] = m("view"), [Le, Re] = m(!1), [ze, A] = m(""), [Be, Ve] = m(null), [He, Ue] = m({}), [We, Ge] = m(null), [Ke, qe] = m(() => ke?.theme);
43
+ }]), [T, je] = m(() => S?.direction ?? xe), [E, D] = m({}), [O, k] = m(null), [A, Me] = m(null), [j, Ne] = m({}), M = p(null), [Pe, Fe] = m("view"), [Ie, Le] = m(!1), [N, P] = m(""), [Re, ze] = m(null), [Be, Ve] = m({}), [He, Ue] = m(null), [We, Ge] = m(() => S?.theme);
43
44
  d(() => {
44
- l && C(oe(l));
45
+ l && w(oe(l));
45
46
  }, [l]), d(() => {
46
47
  if (_ !== void 0) if (x) {
47
48
  let { roots: e, frontMatter: t } = s(_, x);
48
- if (C(e), t.direction) {
49
+ if (w(e), t.direction) {
49
50
  let e = t.direction;
50
- (e === "left" || e === "right" || e === "both") && Ae(e);
51
+ (e === "left" || e === "right" || e === "both") && je(e);
51
52
  }
52
53
  if (t.theme) {
53
54
  let e = t.theme;
54
- (e === "light" || e === "dark" || e === "auto") && qe(e);
55
+ (e === "light" || e === "dark" || e === "auto") && Ge(e);
55
56
  }
56
- } else C(o(_));
57
+ } else w(o(_));
57
58
  }, [_, x]);
58
- let j = u((e) => {
59
- C((t) => {
59
+ let F = u((e) => {
60
+ w((t) => {
60
61
  let n = e(t);
61
- return we?.(n), n;
62
+ return Ee?.(n), n;
62
63
  });
63
- }, [we]), Je = p(Te);
64
- Je.current = Te;
65
- let M = u((e) => {
66
- Je.current?.(e);
67
- }, []), N = le(Ke ?? xe), P = f(() => te(Se ?? ee(), Ce), [Se, Ce]), Ye = f(() => y === !1 ? { zoom: !1 } : y === !0 || y === void 0 ? { zoom: !0 } : { zoom: y.zoom ?? !0 }, [y]), { nodes: F, edges: I } = f(() => n(S, w, Me, T, x, v, He), [
68
- S,
69
- w,
70
- Me,
64
+ }, [Ee]), Ke = p(De);
65
+ Ke.current = De;
66
+ let I = u((e) => {
67
+ Ke.current?.(e);
68
+ }, []), L = le(We ?? Se), R = f(() => te(Ce ?? ee(), we), [Ce, we]), qe = f(() => y === !1 ? { zoom: !1 } : y === !0 || y === void 0 ? { zoom: !0 } : { zoom: y.zoom ?? !0 }, [y]), { nodes: z, edges: B } = f(() => n(C, T, j, E, x, v, Be), [
69
+ C,
71
70
  T,
71
+ j,
72
+ E,
72
73
  x,
73
74
  v,
74
- He
75
+ Be
75
76
  ]);
76
77
  d(() => {
77
78
  let e = {}, t = !1;
78
- for (let n of F) n.depth === 1 && !Me[n.id] && (e[n.id] = n.color, t = !0);
79
+ for (let n of z) n.depth === 1 && !j[n.id] && (e[n.id] = n.color, t = !0);
79
80
  t && Ne((t) => ({
80
81
  ...t,
81
82
  ...e
82
83
  }));
83
- }, [F, Me]);
84
- let L = f(() => {
84
+ }, [z, j]);
85
+ let V = f(() => {
85
86
  let e = {};
86
- for (let t of F) e[t.id] = t;
87
+ for (let t of z) e[t.id] = t;
87
88
  return e;
88
- }, [F]), Xe = f(() => {
89
- if (!We) return {};
89
+ }, [z]), Je = f(() => {
90
+ if (!He) return {};
90
91
  let e = {}, t = [];
91
- for (let e of F) e.parentId === We && t.push({
92
+ for (let e of z) e.parentId === He && t.push({
92
93
  id: e.id,
93
94
  depth: 1
94
95
  });
95
96
  for (; t.length > 0;) {
96
97
  let { id: n, depth: r } = t.shift();
97
98
  e[n] = r * 100;
98
- for (let e of F) e.parentId === n && t.push({
99
+ for (let e of z) e.parentId === n && t.push({
99
100
  id: e.id,
100
101
  depth: r + 1
101
102
  });
102
103
  }
103
104
  return e;
104
- }, [We, F]), { pan: R, setPan: z, zoom: B, setZoom: V, animateTo: H, autoFit: Ze, zoomIn: Qe, zoomOut: $e, contentCenter: et, panToNode: tt } = ue(b, F), { draggingCanvas: nt, floatingNodeId: U, floatingPos: W, floatingSubtreeIds: G, didDragRef: K, handleCanvasMouseDown: rt, handleMouseMove: it, handleMouseUp: at, handleNodeMouseDown: ot } = de({
105
+ }, [He, z]), { pan: H, setPan: Ye, zoom: U, setZoom: Xe, animateTo: Ze, autoFit: Qe, zoomIn: $e, zoomOut: et, contentCenter: tt, panToNode: nt } = ue(b, z), { draggingCanvas: rt, floatingNodeId: W, floatingPos: G, floatingSubtreeIds: K, didDragRef: it, handleCanvasMouseDown: at, handleMouseMove: ot, handleMouseUp: st, handleNodeMouseDown: ct } = de({
105
106
  svgRef: b,
106
- zoom: B,
107
- pan: R,
108
- setPan: z,
109
- setZoom: V,
110
- nodeMap: L,
111
- nodes: F,
112
- updateData: j,
113
- direction: w,
114
- splitIndices: T,
115
- setSplitIndices: E,
116
- mapData: S,
117
- contentCenter: et
118
- }), { editingId: st, editText: ct, setEditText: q, pendingEditId: J, setPendingEditId: Y, handleNodeDoubleClick: lt, commitEdit: ut, cancelEdit: dt } = fe({
119
- nodeMap: L,
120
- updateData: j,
107
+ zoom: U,
108
+ pan: H,
109
+ setPan: Ye,
110
+ setZoom: Xe,
111
+ nodeMap: V,
112
+ nodes: z,
113
+ updateData: F,
114
+ direction: T,
115
+ splitIndices: E,
116
+ setSplitIndices: D,
117
+ mapData: C,
118
+ contentCenter: tt
119
+ }), { editingId: lt, editText: ut, setEditText: q, pendingEditId: J, setPendingEditId: Y, handleNodeDoubleClick: dt, commitEdit: ft, cancelEdit: pt } = fe({
120
+ nodeMap: V,
121
+ updateData: F,
121
122
  onTextChange: (e, t, n) => {
122
- M({
123
+ I({
123
124
  type: "nodeTextChange",
124
125
  nodeId: e,
125
126
  oldText: t,
126
127
  newText: n
127
128
  });
128
129
  }
129
- }), ft = pe(F), [X, pt] = m(!1);
130
+ }), mt = pe(z), [X, ht] = m(!1);
130
131
  d(() => {
131
- if (U || J) return;
132
- let e = Ze();
133
- e ? X ? (V(e.zoom), z({
132
+ if (W || J) return;
133
+ let e = Qe();
134
+ e ? X ? (Xe(e.zoom), Ye({
134
135
  x: e.panX,
135
136
  y: e.panY
136
- })) : (V(e.zoom * .92), z({
137
+ })) : (Xe(e.zoom * .92), Ye({
137
138
  x: e.panX,
138
139
  y: e.panY
139
140
  }), requestAnimationFrame(() => {
140
- pt(!0), H(e.zoom, e.panX, e.panY);
141
- })) : X || requestAnimationFrame(() => pt(!0));
141
+ ht(!0), Ze(e.zoom, e.panX, e.panY);
142
+ })) : X || requestAnimationFrame(() => ht(!0));
142
143
  }, [
143
- F,
144
- Ze,
145
- U,
146
- J,
147
- V,
148
144
  z,
145
+ Qe,
146
+ W,
147
+ J,
148
+ Xe,
149
+ Ye,
149
150
  X,
150
- H
151
+ Ze
151
152
  ]), d(() => {
152
- J && L[J] && tt(J);
153
+ J && V[J] && nt(J);
153
154
  }, [
154
155
  J,
155
- L,
156
- tt
156
+ V,
157
+ nt
157
158
  ]);
158
- let mt = u((e) => {
159
- je(null), rt(e);
160
- }, [rt]), ht = u((e, t) => {
161
- e.stopPropagation(), K.current || (O(t), M({
159
+ let gt = u((e) => {
160
+ Me(null), at(e);
161
+ }, [at]), _t = u((e, t) => {
162
+ e.stopPropagation(), it.current || (k(t), I({
162
163
  type: "nodeSelect",
163
164
  nodeId: t
164
165
  }));
165
- }, [K, M]), gt = u(() => {
166
- K.current || (O(null), M({
166
+ }, [it, I]), vt = u(() => {
167
+ it.current || (k(null), I({
167
168
  type: "nodeSelect",
168
169
  nodeId: null
169
170
  }));
170
- }, [K, M]), _t = u((e) => {
171
+ }, [it, I]), yt = u((e) => {
171
172
  e.preventDefault(), e.stopPropagation();
172
- let t = Oe.current;
173
+ let t = Ae.current;
173
174
  if (!t) return;
174
175
  let n = t.getBoundingClientRect();
175
- je({
176
+ Me({
176
177
  x: e.clientX - n.left,
177
178
  y: e.clientY - n.top
178
179
  });
179
180
  }, []), Z = u(() => {
180
- je(null);
181
- }, []), vt = u((e) => {
181
+ Me(null);
182
+ }, []), bt = u((e) => {
182
183
  if (!e) {
183
- Ve(null);
184
+ ze(null);
184
185
  return;
185
186
  }
186
- let t = L[e];
187
+ let t = V[e];
187
188
  if (!t || !t.remark) {
188
- Ve(null);
189
+ ze(null);
189
190
  return;
190
191
  }
191
192
  let n = b.current;
192
193
  if (!n) return;
193
- let r = n.getBoundingClientRect(), i = (t.x + t.width / 2) * B + R.x, a = (t.y - t.height / 2) * B + R.y;
194
- Ve({
194
+ let r = n.getBoundingClientRect(), i = (t.x + t.width / 2) * U + H.x, a = (t.y - t.height / 2) * U + H.y;
195
+ ze({
195
196
  nodeId: e,
196
197
  text: t.remark,
197
198
  x: Math.min(i, r.width - 300),
198
199
  y: a - 8
199
200
  });
200
201
  }, [
201
- L,
202
- B,
203
- R
204
- ]), yt = u((e, t, n) => {
202
+ V,
203
+ U,
204
+ H
205
+ ]), xt = u((e, t, n) => {
205
206
  if (e.stopPropagation(), v) return;
206
207
  let r = ae(), i = {
207
208
  id: r,
208
- text: P.newNode
209
+ text: R.newNode
209
210
  };
210
- S.some((e) => e.id === t) && n && w === "both" ? j((e) => e.map((e) => {
211
+ C.some((e) => e.id === t) && n && T === "both" ? F((e) => e.map((e) => {
211
212
  if (e.id !== t) return e;
212
- let r = e.children || [], a = T[t] ?? Math.ceil(r.length / 2), o = a, s = r.length - a, c = n;
213
+ let r = e.children || [], a = E[t] ?? Math.ceil(r.length / 2), o = a, s = r.length - a, c = n;
213
214
  n === "right" && o >= 3 * Math.max(s, 1) ? c = "left" : n === "left" && s >= 3 * Math.max(o, 1) && (c = "right");
214
215
  let ee = re(e, i, c, a);
215
- return E((e) => ({
216
+ return D((e) => ({
216
217
  ...e,
217
218
  [t]: ee.newSplitIndex
218
219
  })), ee.data;
219
- })) : j((e) => ne(e, t, i)), M({
220
+ })) : F((e) => ne(e, t, i)), I({
220
221
  type: "nodeAdd",
221
222
  node: i,
222
223
  parentId: t
223
224
  }), Y(r), q("");
224
225
  }, [
225
- j,
226
- S,
227
- w,
226
+ F,
227
+ C,
228
228
  T,
229
+ E,
229
230
  Y,
230
231
  q,
231
- P,
232
+ R,
232
233
  v,
233
- M
234
- ]), bt = u(() => {
234
+ I
235
+ ]), St = u(() => {
235
236
  if (v) return;
236
237
  let e = ae(), t = {
237
238
  id: e,
238
- text: P.newNode
239
+ text: R.newNode
239
240
  };
240
- j((e) => [...e, t]), M({
241
+ F((e) => [...e, t]), I({
241
242
  type: "nodeAdd",
242
243
  node: t,
243
244
  parentId: null
244
245
  }), Y(e), q(""), Z();
245
246
  }, [
246
- j,
247
+ F,
247
248
  Z,
248
249
  Y,
249
250
  q,
250
- P,
251
+ R,
251
252
  v,
252
- M
253
- ]), xt = u(() => {
254
- let e = r(F, I, {}, N, x);
255
- ye(new Blob([e], { type: "image/svg+xml;charset=utf-8" }), "mindmap.svg"), Z();
253
+ I
254
+ ]), Ct = u(() => {
255
+ let e = r(z, B, {}, L, x);
256
+ be(new Blob([e], { type: "image/svg+xml;charset=utf-8" }), "mindmap.svg"), Z();
256
257
  }, [
257
- F,
258
- I,
259
- N,
258
+ z,
259
+ B,
260
+ L,
260
261
  Z,
261
262
  x
262
- ]), St = u(async () => {
263
- ye(await a(i(F, I, { pngSafe: !0 }, N, x)), "mindmap.png"), Z();
263
+ ]), wt = u(async () => {
264
+ be(await a(i(z, B, { pngSafe: !0 }, L, x)), "mindmap.png"), Z();
264
265
  }, [
265
- F,
266
- I,
267
- N,
266
+ z,
267
+ B,
268
+ L,
268
269
  Z,
269
270
  x
270
- ]), Ct = u(() => {
271
- let e = c(S, x);
272
- ye(new Blob([e], { type: "text/markdown;charset=utf-8" }), "mindmap.md"), Z();
271
+ ]), Tt = u(() => {
272
+ let e = c(C, x);
273
+ be(new Blob([e], { type: "text/markdown;charset=utf-8" }), "mindmap.md"), Z();
273
274
  }, [
274
- S,
275
+ C,
275
276
  Z,
276
277
  x
277
278
  ]), Q = u(() => {
278
- let e = Ze();
279
- e && H(e.zoom, e.panX, e.panY);
280
- }, [Ze, H]), $ = u((e) => {
281
- Ae(e), E({}), M({
279
+ let e = Qe();
280
+ e && Ze(e.zoom, e.panX, e.panY);
281
+ }, [Qe, Ze]), $ = u((e) => {
282
+ je(e), D({}), I({
282
283
  type: "directionChange",
283
284
  direction: e
284
285
  });
285
- }, [M]), wt = u(() => {
286
- Ie((e) => {
287
- if (e === "view") return A(c(S, x)), M({
286
+ }, [I]), Et = u(() => {
287
+ Fe((e) => {
288
+ if (e === "view") return P(c(C, x)), I({
288
289
  type: "modeChange",
289
290
  mode: "text"
290
291
  }), "text";
291
292
  {
292
- let e = x ? s(ze, x).roots : o(ze);
293
- return j(() => e), E({}), M({
293
+ let e = x ? s(N, x).roots : o(N);
294
+ return F(() => e), D({}), I({
294
295
  type: "modeChange",
295
296
  mode: "view"
296
297
  }), "view";
297
298
  }
298
299
  });
299
300
  }, [
300
- S,
301
- ze,
302
- j,
301
+ C,
302
+ N,
303
+ F,
303
304
  x,
304
- M
305
- ]), Tt = u(() => {
306
- let e = Oe.current;
305
+ I
306
+ ]), Dt = u(() => {
307
+ let e = Ae.current;
307
308
  e && (document.fullscreenElement ? document.exitFullscreen() : e.requestFullscreen());
308
309
  }, []);
309
310
  d(() => {
310
311
  let e = () => {
311
312
  let e = !!document.fullscreenElement;
312
- Re(e), M({
313
+ Le(e), I({
313
314
  type: "fullscreenChange",
314
315
  fullscreen: e
315
316
  });
316
317
  };
317
318
  return document.addEventListener("fullscreenchange", e), () => document.removeEventListener("fullscreenchange", e);
318
- }, [M]);
319
- let Et = p(B);
319
+ }, [I]);
320
+ let Ot = p(U);
320
321
  d(() => {
321
- B !== Et.current && (Et.current = B, M({
322
+ U !== Ot.current && (Ot.current = U, I({
322
323
  type: "zoomChange",
323
- zoom: B
324
+ zoom: U
324
325
  }));
325
- }, [B, M]);
326
- let Dt = u((e) => {
327
- if (e.key === "Escape" && k) {
326
+ }, [U, I]);
327
+ let kt = u((e) => {
328
+ if (e.key === "Escape" && A) {
328
329
  e.preventDefault(), Z();
329
330
  return;
330
331
  }
331
- if (st) return;
332
+ if (lt) return;
332
333
  let t = e.metaKey || e.ctrlKey;
333
334
  if (e.shiftKey && !t) {
334
335
  if (e.code === "Equal") {
335
- e.preventDefault(), Qe();
336
+ e.preventDefault(), $e();
336
337
  return;
337
338
  }
338
339
  if (e.code === "Minus") {
339
- e.preventDefault(), $e();
340
+ e.preventDefault(), et();
340
341
  return;
341
342
  }
342
343
  if (e.code === "Digit0") {
@@ -356,93 +357,93 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
356
357
  return;
357
358
  }
358
359
  }
359
- if (e.key === "Enter" && !t && D && !v) {
360
+ if (e.key === "Enter" && !t && O && !v) {
360
361
  e.preventDefault();
361
362
  let t = ae(), n = {
362
363
  id: t,
363
- text: P.newNode
364
+ text: R.newNode
364
365
  };
365
- S.some((e) => e.id === D) && w === "both" ? j((e) => e.map((e) => {
366
- if (e.id !== D) return e;
367
- let t = e.children || [], r = re(e, n, "right", T[D] ?? Math.ceil(t.length / 2));
368
- return E((e) => ({
366
+ C.some((e) => e.id === O) && T === "both" ? F((e) => e.map((e) => {
367
+ if (e.id !== O) return e;
368
+ let t = e.children || [], r = re(e, n, "right", E[O] ?? Math.ceil(t.length / 2));
369
+ return D((e) => ({
369
370
  ...e,
370
- [D]: r.newSplitIndex
371
+ [O]: r.newSplitIndex
371
372
  })), r.data;
372
- })) : j((e) => ne(e, D, n)), Y(t), q(""), M({
373
+ })) : F((e) => ne(e, O, n)), Y(t), q(""), I({
373
374
  type: "nodeAdd",
374
375
  node: n,
375
- parentId: D
376
+ parentId: O
376
377
  });
377
378
  return;
378
379
  }
379
- if ((e.key === "Delete" || e.key === "Backspace") && D && !v) {
380
- if (e.preventDefault(), S.some((e) => e.id === D) && S.length <= 1) return;
381
- M({
380
+ if ((e.key === "Delete" || e.key === "Backspace") && O && !v) {
381
+ if (e.preventDefault(), C.some((e) => e.id === O) && C.length <= 1) return;
382
+ I({
382
383
  type: "nodeDelete",
383
- nodeId: D
384
- }), j((e) => ce(e, D)), O(null);
384
+ nodeId: O
385
+ }), F((e) => ce(e, O)), k(null);
385
386
  return;
386
387
  }
387
- if (t && e.key === "c" && D) {
388
- e.preventDefault(), Pe.current = ie(S, D);
388
+ if (t && e.key === "c" && O) {
389
+ e.preventDefault(), M.current = ie(C, O);
389
390
  return;
390
391
  }
391
- if (t && e.key === "x" && D && !v) {
392
- if (e.preventDefault(), Pe.current = ie(S, D), S.some((e) => e.id === D) && S.length <= 1) return;
393
- M({
392
+ if (t && e.key === "x" && O && !v) {
393
+ if (e.preventDefault(), M.current = ie(C, O), C.some((e) => e.id === O) && C.length <= 1) return;
394
+ I({
394
395
  type: "nodeDelete",
395
- nodeId: D
396
- }), j((e) => ce(e, D)), O(null);
396
+ nodeId: O
397
+ }), F((e) => ce(e, O)), k(null);
397
398
  return;
398
399
  }
399
- if (t && e.key === "v" && D && Pe.current && !v) {
400
+ if (t && e.key === "v" && O && M.current && !v) {
400
401
  e.preventDefault();
401
- let t = se(Pe.current);
402
- j((e) => ne(e, D, t)), M({
402
+ let t = se(M.current);
403
+ F((e) => ne(e, O, t)), I({
403
404
  type: "nodeAdd",
404
405
  node: t,
405
- parentId: D
406
+ parentId: O
406
407
  });
407
408
  return;
408
409
  }
409
410
  }, [
410
- st,
411
- D,
412
- S,
413
- w,
411
+ lt,
412
+ O,
413
+ C,
414
414
  T,
415
- j,
416
- k,
415
+ E,
416
+ F,
417
+ A,
417
418
  Z,
418
419
  Y,
419
420
  q,
420
- P,
421
- Qe,
421
+ R,
422
422
  $e,
423
+ et,
423
424
  Q,
424
425
  $,
425
426
  v,
426
- M
427
+ I
427
428
  ]);
428
- _e(De, () => ({
429
+ ve(ke, () => ({
429
430
  exportToSVG() {
430
- return r(F, I, {}, N, x);
431
+ return r(z, B, {}, L, x);
431
432
  },
432
433
  async exportToPNG() {
433
- return a(i(F, I, {}, N, x));
434
+ return a(i(z, B, {}, L, x));
434
435
  },
435
436
  exportToOutline() {
436
- return c(S, x);
437
+ return c(C, x);
437
438
  },
438
439
  getData() {
439
- return S;
440
+ return C;
440
441
  },
441
442
  setData(e) {
442
- C(oe(e)), E({});
443
+ w(oe(e)), D({});
443
444
  },
444
445
  setMarkdown(e) {
445
- C(x ? s(e, x).roots : o(e)), E({});
446
+ w(x ? s(e, x).roots : o(e)), D({});
446
447
  },
447
448
  fitView() {
448
449
  Q();
@@ -451,19 +452,23 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
451
452
  $(e);
452
453
  }
453
454
  }), [
454
- F,
455
- I,
456
- S,
455
+ z,
456
+ B,
457
+ C,
457
458
  x,
458
459
  Q,
459
460
  $,
460
- N
461
+ L
461
462
  ]), d(() => {
462
- if (!k) return;
463
+ if (!A) return;
463
464
  let e = () => Z();
464
465
  return window.addEventListener("click", e), () => window.removeEventListener("click", e);
465
- }, [k, Z]);
466
- let Ot = u((e) => {
466
+ }, [A, Z]);
467
+ let At = u((e) => {
468
+ w(x ? s(e, x).roots : o(e)), D({});
469
+ }, [x]), jt = u(() => {
470
+ setTimeout(() => Q(), 100);
471
+ }, [Q]), Mt = u(() => {}, []), Nt = u((e) => {
467
472
  if (e.key !== "Tab") return;
468
473
  e.preventDefault();
469
474
  let t = e.currentTarget, { selectionStart: n, selectionEnd: r, value: i } = t;
@@ -473,7 +478,7 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
473
478
  let a = i.slice(e, r), o = a.match(/^ {1,2}/);
474
479
  if (!o) return;
475
480
  let s = o[0].length;
476
- A(i.slice(0, e) + a.slice(s) + i.slice(r)), requestAnimationFrame(() => {
481
+ P(i.slice(0, e) + a.slice(s) + i.slice(r)), requestAnimationFrame(() => {
477
482
  t.selectionStart = t.selectionEnd = Math.max(e, n - s);
478
483
  });
479
484
  } else {
@@ -481,60 +486,60 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
481
486
  let n = e.match(/^ {1,2}/), r = n ? n[0].length : 0;
482
487
  return o += r, t === 0 && (s = r), e.slice(r);
483
488
  }).join("\n");
484
- A(i.slice(0, e) + c + i.slice(r)), requestAnimationFrame(() => {
489
+ P(i.slice(0, e) + c + i.slice(r)), requestAnimationFrame(() => {
485
490
  t.selectionStart = n - s, t.selectionEnd = r - o;
486
491
  });
487
492
  }
488
- } else if (n === r) A(i.slice(0, n) + " " + i.slice(r)), requestAnimationFrame(() => {
493
+ } else if (n === r) P(i.slice(0, n) + " " + i.slice(r)), requestAnimationFrame(() => {
489
494
  t.selectionStart = t.selectionEnd = n + 2;
490
495
  });
491
496
  else {
492
497
  let e = i.lastIndexOf("\n", n - 1) + 1, a = i.slice(e, r).split("\n"), o = a.map((e) => " " + e).join("\n");
493
- A(i.slice(0, e) + o + i.slice(r)), requestAnimationFrame(() => {
498
+ P(i.slice(0, e) + o + i.slice(r)), requestAnimationFrame(() => {
494
499
  t.selectionStart = n + 2, t.selectionEnd = r + a.length * 2;
495
500
  });
496
501
  }
497
502
  }, []);
498
503
  return /* @__PURE__ */ g("div", {
499
- ref: Oe,
504
+ ref: Ae,
500
505
  className: "mindmap-container",
501
506
  children: [
502
- Fe === "text" && /* @__PURE__ */ h("textarea", {
507
+ Pe === "text" && /* @__PURE__ */ h("textarea", {
503
508
  className: "mindmap-text-editor",
504
- value: ze,
505
- onChange: (e) => A(e.target.value),
506
- onKeyDown: Ot,
509
+ value: N,
510
+ onChange: (e) => P(e.target.value),
511
+ onKeyDown: Nt,
507
512
  readOnly: v,
508
513
  style: {
509
- background: N.canvas.bgColor,
510
- color: N.node.textColor,
514
+ background: L.canvas.bgColor,
515
+ color: L.node.textColor,
511
516
  opacity: v ? .7 : 1
512
517
  }
513
518
  }),
514
519
  /* @__PURE__ */ h("svg", {
515
520
  ref: b,
516
- className: `mindmap-svg ${nt ? "dragging-canvas" : ""} ${U ? "dragging-node" : ""}`,
521
+ className: `mindmap-svg ${rt ? "dragging-canvas" : ""} ${W ? "dragging-node" : ""}`,
517
522
  style: {
518
- background: N.canvas.bgColor,
519
- display: Fe === "text" ? "none" : "block"
523
+ background: L.canvas.bgColor,
524
+ display: Pe === "text" ? "none" : "block"
520
525
  },
521
526
  tabIndex: 0,
522
- onMouseDown: mt,
523
- onMouseMove: it,
524
- onMouseUp: at,
525
- onMouseLeave: at,
526
- onClick: gt,
527
- onKeyDown: Dt,
528
- onContextMenu: _t,
527
+ onMouseDown: gt,
528
+ onMouseMove: ot,
529
+ onMouseUp: st,
530
+ onMouseLeave: st,
531
+ onClick: vt,
532
+ onKeyDown: kt,
533
+ onContextMenu: yt,
529
534
  children: /* @__PURE__ */ g("g", {
530
535
  className: "mindmap-canvas",
531
- transform: `translate(${R.x}, ${R.y}) scale(${B})`,
536
+ transform: `translate(${H.x}, ${H.y}) scale(${U})`,
532
537
  opacity: X ? 1 : 0,
533
538
  style: { transition: X ? "opacity 0.4s ease-out" : "none" },
534
539
  children: [
535
540
  /* @__PURE__ */ g("g", {
536
541
  className: "mindmap-edges",
537
- children: [I.some((e) => e.isCrossLink) && /* @__PURE__ */ h("defs", { children: /* @__PURE__ */ h("marker", {
542
+ children: [B.some((e) => e.isCrossLink) && /* @__PURE__ */ h("defs", { children: /* @__PURE__ */ h("marker", {
538
543
  id: "mindmap-arrowhead",
539
544
  markerWidth: "8",
540
545
  markerHeight: "6",
@@ -547,12 +552,12 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
547
552
  stroke: "currentColor",
548
553
  strokeWidth: 1.5
549
554
  })
550
- }) }), I.map((e) => {
551
- let t = Xe[e.toId], n = t !== void 0;
555
+ }) }), B.map((e) => {
556
+ let t = Je[e.toId], n = t !== void 0;
552
557
  return /* @__PURE__ */ g("g", { children: [/* @__PURE__ */ h("path", {
553
558
  d: e.path,
554
559
  stroke: e.color,
555
- strokeWidth: N.connection.strokeWidth,
560
+ strokeWidth: L.connection.strokeWidth,
556
561
  strokeLinecap: "round",
557
562
  strokeDasharray: n ? void 0 : e.strokeDasharray,
558
563
  markerEnd: e.isCrossLink ? "url(#mindmap-arrowhead)" : void 0,
@@ -561,11 +566,11 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
561
566
  className: [
562
567
  "mindmap-edge",
563
568
  e.isCrossLink ? "mindmap-edge-cross-link" : "",
564
- n ? "mindmap-edge-expanding" : nt || G.has(e.fromId) || G.has(e.toId) ? "" : "mindmap-edge-animated"
569
+ n ? "mindmap-edge-expanding" : rt || K.has(e.fromId) || K.has(e.toId) ? "" : "mindmap-edge-animated"
565
570
  ].filter(Boolean).join(" "),
566
571
  style: n ? { animationDelay: `${t}ms` } : void 0
567
572
  }), e.label && (() => {
568
- let t = L[e.fromId], n = L[e.toId];
573
+ let t = V[e.fromId], n = V[e.toId];
569
574
  return !t || !n ? null : /* @__PURE__ */ h("text", {
570
575
  className: "mindmap-edge-label",
571
576
  x: (t.x + n.x) / 2,
@@ -574,7 +579,7 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
574
579
  fontSize: 11,
575
580
  fill: e.color,
576
581
  opacity: .8,
577
- fontFamily: N.node.fontFamily,
582
+ fontFamily: L.node.fontFamily,
578
583
  style: { pointerEvents: "none" },
579
584
  children: e.label
580
585
  });
@@ -583,48 +588,48 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
583
588
  }),
584
589
  /* @__PURE__ */ h("g", {
585
590
  className: "mindmap-nodes",
586
- children: F.map((e) => {
587
- let t = G.has(e.id), n = t || nt ? "" : "mindmap-node-animated";
591
+ children: z.map((e) => {
592
+ let t = K.has(e.id), n = t || rt ? "" : "mindmap-node-animated";
588
593
  return /* @__PURE__ */ h(me, {
589
594
  node: e,
590
- isEditing: st === e.id,
595
+ isEditing: lt === e.id,
591
596
  isPendingEdit: J === e.id,
592
- isSelected: D === e.id,
593
- isNew: ft.has(e.id),
597
+ isSelected: O === e.id,
598
+ isNew: mt.has(e.id),
594
599
  isGhost: t,
595
600
  animClass: n,
596
- editText: ct,
597
- theme: N,
598
- direction: w,
599
- onMouseDown: ot,
600
- onClick: ht,
601
- onDoubleClick: v ? () => {} : lt,
601
+ editText: ut,
602
+ theme: L,
603
+ direction: T,
604
+ onMouseDown: ct,
605
+ onClick: _t,
606
+ onDoubleClick: v ? () => {} : dt,
602
607
  onEditChange: q,
603
- onEditCommit: ut,
604
- onEditCancel: dt,
605
- onAddChild: yt,
606
- onRemarkHover: vt,
608
+ onEditCommit: ft,
609
+ onEditCancel: pt,
610
+ onAddChild: xt,
611
+ onRemarkHover: bt,
607
612
  onFoldToggle: x ? (e) => {
608
- He[e] || (Ge(e), setTimeout(() => Ge(null), 800)), Ue((t) => ({
613
+ Be[e] || (Ue(e), setTimeout(() => Ue(null), 800)), Ve((t) => ({
609
614
  ...t,
610
615
  [e]: !t[e]
611
616
  }));
612
617
  } : void 0,
613
- expandDelay: Xe[e.id],
618
+ expandDelay: Je[e.id],
614
619
  readonly: v,
615
620
  plugins: x
616
621
  }, e.id);
617
622
  })
618
623
  }),
619
- U && W && (() => {
620
- let e = L[U];
624
+ W && G && (() => {
625
+ let e = V[W];
621
626
  if (!e) return null;
622
- let n = W.x - e.x, r = W.y - e.y, i = e.parentId ? L[e.parentId] : null;
623
- return /* @__PURE__ */ g(ve, { children: [i && /* @__PURE__ */ h("path", {
627
+ let n = G.x - e.x, r = G.y - e.y, i = e.parentId ? V[e.parentId] : null;
628
+ return /* @__PURE__ */ g(ye, { children: [i && /* @__PURE__ */ h("path", {
624
629
  className: "mindmap-floating-edge",
625
- d: t(i.x, i.y, i.width, W.x, W.y, e.width, e.side),
630
+ d: t(i.x, i.y, i.width, G.x, G.y, e.width, e.side),
626
631
  stroke: e.color,
627
- strokeWidth: N.connection.strokeWidth,
632
+ strokeWidth: L.connection.strokeWidth,
628
633
  strokeLinecap: "round",
629
634
  fill: "none",
630
635
  style: { pointerEvents: "none" }
@@ -632,14 +637,14 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
632
637
  className: "mindmap-floating",
633
638
  transform: `translate(${n}, ${r})`,
634
639
  style: { pointerEvents: "none" },
635
- children: [I.filter((e) => G.has(e.fromId) && G.has(e.toId)).map((e) => /* @__PURE__ */ h("path", {
640
+ children: [B.filter((e) => K.has(e.fromId) && K.has(e.toId)).map((e) => /* @__PURE__ */ h("path", {
636
641
  className: "mindmap-floating-edge",
637
642
  d: e.path,
638
643
  stroke: e.color,
639
- strokeWidth: N.connection.strokeWidth,
644
+ strokeWidth: L.connection.strokeWidth,
640
645
  strokeLinecap: "round",
641
646
  fill: "none"
642
- }, `fl-${e.key}`)), F.filter((e) => G.has(e.id)).map((e) => /* @__PURE__ */ h(me, {
647
+ }, `fl-${e.key}`)), z.filter((e) => K.has(e.id)).map((e) => /* @__PURE__ */ h(me, {
643
648
  node: e,
644
649
  isEditing: !1,
645
650
  isPendingEdit: !1,
@@ -647,8 +652,8 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
647
652
  isNew: !1,
648
653
  animClass: "",
649
654
  editText: "",
650
- theme: N,
651
- direction: w,
655
+ theme: L,
656
+ direction: T,
652
657
  onMouseDown: () => {},
653
658
  onClick: () => {},
654
659
  onDoubleClick: () => {},
@@ -660,7 +665,7 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
660
665
  }, `fl-${e.id}`))]
661
666
  })] });
662
667
  })(),
663
- x && e(x, F, I, N).map((e, t) => /* @__PURE__ */ h("g", {
668
+ x && e(x, z, B, L).map((e, t) => /* @__PURE__ */ h("g", {
664
669
  className: "mindmap-plugin-overlay",
665
670
  children: e
666
671
  }, `plugin-overlay-${t}`))
@@ -668,43 +673,52 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
668
673
  })
669
674
  }),
670
675
  /* @__PURE__ */ h(he, {
671
- zoom: B,
672
- theme: N,
673
- messages: P,
674
- showZoom: Ye.zoom,
675
- mode: Fe,
676
- isFullscreen: Le,
677
- onZoomIn: Qe,
678
- onZoomOut: $e,
676
+ zoom: U,
677
+ theme: L,
678
+ messages: R,
679
+ showZoom: qe.zoom,
680
+ mode: Pe,
681
+ isFullscreen: Ie,
682
+ onZoomIn: $e,
683
+ onZoomOut: et,
679
684
  onAutoFit: Q,
680
- onModeToggle: wt,
681
- onFullscreenToggle: Tt
685
+ onModeToggle: Et,
686
+ onFullscreenToggle: Dt
687
+ }),
688
+ Te && /* @__PURE__ */ h(_e, {
689
+ config: Te,
690
+ theme: L,
691
+ messages: R,
692
+ currentMarkdown: c(C, x),
693
+ onMarkdownStream: At,
694
+ onComplete: jt,
695
+ onError: Mt
682
696
  }),
683
- k && /* @__PURE__ */ h(ge, {
684
- position: k,
685
- theme: N,
686
- messages: P,
687
- direction: w,
697
+ A && /* @__PURE__ */ h(ge, {
698
+ position: A,
699
+ theme: L,
700
+ messages: R,
701
+ direction: T,
688
702
  readonly: v,
689
- onNewRootNode: bt,
690
- onExportSVG: xt,
691
- onExportPNG: St,
692
- onExportMarkdown: Ct,
703
+ onNewRootNode: St,
704
+ onExportSVG: Ct,
705
+ onExportPNG: wt,
706
+ onExportMarkdown: Tt,
693
707
  onDirectionChange: $,
694
708
  onClose: Z
695
709
  }),
696
- Be && /* @__PURE__ */ h("div", {
710
+ Re && /* @__PURE__ */ h("div", {
697
711
  className: "mindmap-remark-tooltip",
698
712
  style: {
699
- left: Be.x,
700
- top: Be.y,
713
+ left: Re.x,
714
+ top: Re.y,
701
715
  transform: "translateY(-100%)",
702
- background: N.contextMenu.bgColor,
703
- color: N.contextMenu.textColor,
704
- borderColor: N.contextMenu.borderColor,
705
- border: `1px solid ${N.contextMenu.borderColor}`
716
+ background: L.contextMenu.bgColor,
717
+ color: L.contextMenu.textColor,
718
+ borderColor: L.contextMenu.borderColor,
719
+ border: `1px solid ${L.contextMenu.borderColor}`
706
720
  },
707
- children: Be.text
721
+ children: Re.text
708
722
  })
709
723
  ]
710
724
  });