dishui 0.0.61 → 0.0.62

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.
@@ -8,7 +8,7 @@ import { generateId as Q } from "./nodes/nodeUtils.js";
8
8
  import { normalizeEdgeHandles as xe } from "./edges/edgePaths.js";
9
9
  import { useDeleteSelection as Se } from "./hooks/useDeleteSelection.js";
10
10
  import Ce from "./FlowCanvas.js";
11
- import { downloadDataURL as Me, safeFileBaseName as Pe } from "./hooks/useFlowImportExport.js";
11
+ import { downloadDataURL as Pe, safeFileBaseName as Me } from "./hooks/useFlowImportExport.js";
12
12
  import Ne, { FlowZoomControls as ke } from "./panels/FlowToolbar.js";
13
13
  import { MediaStampContent as De, ShapePaletteContent as Ee, SvgStampContent as Ae } from "./panels/ShapePalette.js";
14
14
  import { InspectorPanelContent as ze } from "./panels/InspectorPanel.js";
@@ -27,43 +27,43 @@ import { usePdfExport as Ze } from "./hooks/usePdfExport.js";
27
27
  import { useKeyboardShortcuts as Je } from "./hooks/useKeyboardShortcuts.js";
28
28
  import { useMindMap as Oe } from "./hooks/useMindMap.js";
29
29
  /* empty css */
30
- import { forwardRef as _e, useCallback as D, useEffect as X, useImperativeHandle as $e, useMemo as le, useRef as R, useState as j } from "react";
30
+ import { forwardRef as _e, useCallback as E, useEffect as X, useImperativeHandle as $e, useMemo as le, useRef as F, useState as j } from "react";
31
31
  import { jsx as r, jsxs as _ } from "react/jsx-runtime";
32
32
  import { EditorView as Be } from "@codemirror/view";
33
33
  function Ve(o) {
34
34
  let p = !1;
35
35
  const a = { ...o.canvases };
36
- for (const [w, u] of Object.entries(a)) {
36
+ for (const [v, u] of Object.entries(a)) {
37
37
  const s = u.nodes.map((e) => {
38
38
  if (e.type !== "shapeSvg") return e;
39
- const h = e.data.labelPlacement, c = h === "above" ? "top" : h === "center" ? "middle" : h === "below" ? "bottom" : e.data.labelPlacement;
40
- return c === e.data.labelPlacement ? e : (p = !0, {
39
+ const I = e.data.labelPlacement, m = I === "above" ? "top" : I === "center" ? "middle" : I === "below" ? "bottom" : e.data.labelPlacement;
40
+ return m === e.data.labelPlacement ? e : (p = !0, {
41
41
  ...e,
42
42
  data: {
43
43
  ...e.data,
44
- labelPlacement: c
44
+ labelPlacement: m
45
45
  }
46
46
  });
47
47
  });
48
48
  let l = !1;
49
49
  const n = s.map((e) => {
50
50
  if (!e.data.isMindMapNode) return e;
51
- const h = e.data.fill === "#ffffff" || e.data.fill === "#eef2ff" ? "theme:base-100" : e.data.fill, c = e.data.stroke === "#6366f1" ? "theme:base-content" : e.data.stroke === "#4f46e5" ? "theme:primary" : e.data.stroke;
52
- return h === e.data.fill && c === e.data.stroke ? e : (l = !0, {
51
+ const I = e.data.fill === "#ffffff" || e.data.fill === "#eef2ff" ? "theme:base-100" : e.data.fill, m = e.data.stroke === "#6366f1" ? "theme:base-content" : e.data.stroke === "#4f46e5" ? "theme:primary" : e.data.stroke;
52
+ return I === e.data.fill && m === e.data.stroke ? e : (l = !0, {
53
53
  ...e,
54
54
  data: {
55
55
  ...e.data,
56
- fill: h,
57
- stroke: c
56
+ fill: I,
57
+ stroke: m
58
58
  }
59
59
  });
60
- }), y = /* @__PURE__ */ new Map();
61
- for (const e of n) y.set(e.id, e);
62
- let d = !1;
63
- const I = xe(u.edges, y).map((e) => {
60
+ }), b = /* @__PURE__ */ new Map();
61
+ for (const e of n) b.set(e.id, e);
62
+ let c = !1;
63
+ const y = xe(u.edges, b).map((e) => {
64
64
  if (e.data.strokeColor !== "#94a3b8") return e;
65
- const h = y.get(e.source), c = y.get(e.target);
66
- return !h?.data.isMindMapNode || !c?.data.isMindMapNode ? e : (d = !0, {
65
+ const I = b.get(e.source), m = b.get(e.target);
66
+ return !I?.data.isMindMapNode || !m?.data.isMindMapNode ? e : (c = !0, {
67
67
  ...e,
68
68
  data: {
69
69
  ...e.data,
@@ -71,10 +71,10 @@ function Ve(o) {
71
71
  }
72
72
  });
73
73
  });
74
- (l || d) && (p = !0), (n !== s || I !== u.edges) && (a[w] = {
74
+ (l || c) && (p = !0), (n !== s || y !== u.edges) && (a[v] = {
75
75
  ...u,
76
76
  nodes: n,
77
- edges: I
77
+ edges: y
78
78
  });
79
79
  }
80
80
  return p ? {
@@ -87,171 +87,171 @@ var je = {
87
87
  edgeIds: /* @__PURE__ */ new Set(),
88
88
  lineIds: /* @__PURE__ */ new Set()
89
89
  };
90
- function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: w, ungroupRef: u }) {
91
- const { selection: s, setSelection: l, currentCanvas: n, setDoc: y, currentCanvasId: d } = ee(), { viewport: I } = Y(), { copy: e, cut: h, paste: c, duplicate: v } = ae(), b = Se(), g = D(() => {
90
+ function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: v, ungroupRef: u }) {
91
+ const { selection: s, setSelection: l, currentCanvas: n, setDoc: b, currentCanvasId: c } = ee(), { viewport: y } = Y(), { copy: e, cut: I, paste: m, duplicate: h } = ae(), x = Se(), g = E(() => {
92
92
  l({
93
93
  nodeIds: new Set(n.nodes.map((f) => f.id)),
94
94
  edgeIds: new Set(n.edges.map((f) => f.id)),
95
95
  lineIds: new Set(n.lines.map((f) => f.id))
96
96
  });
97
- }, [n, l]), S = D((f) => {
98
- const m = s.nodeIds, N = s.lineIds;
99
- if (m.size + N.size < 2) return;
100
- const E = n.nodes.filter((P) => m.has(P.id)), t = n.lines.filter((P) => N.has(P.id)), i = 20;
101
- let x = 1 / 0, W = 1 / 0, T = -1 / 0, H = -1 / 0;
102
- for (const P of E)
103
- x = Math.min(x, P.position.x), W = Math.min(W, P.position.y), T = Math.max(T, P.position.x + P.width), H = Math.max(H, P.position.y + P.height);
104
- for (const P of t) for (const k of P.points)
105
- x = Math.min(x, k.x), W = Math.min(W, k.y), T = Math.max(T, k.x), H = Math.max(H, k.y);
106
- const U = f === "geometryGroup", Z = Q("group"), M = {
107
- id: Z,
97
+ }, [n, l]), S = E((f) => {
98
+ const w = s.nodeIds, N = s.lineIds;
99
+ if (w.size + N.size < 2) return;
100
+ const k = n.nodes.filter((M) => w.has(M.id)), d = n.lines.filter((M) => N.has(M.id)), t = 20;
101
+ let i = 1 / 0, R = 1 / 0, L = -1 / 0, W = -1 / 0;
102
+ for (const M of k)
103
+ i = Math.min(i, M.position.x), R = Math.min(R, M.position.y), L = Math.max(L, M.position.x + M.width), W = Math.max(W, M.position.y + M.height);
104
+ for (const M of d) for (const D of M.points)
105
+ i = Math.min(i, D.x), R = Math.min(R, D.y), L = Math.max(L, D.x), W = Math.max(W, D.y);
106
+ const H = f === "geometryGroup", U = Q("group"), P = {
107
+ id: U,
108
108
  type: f,
109
109
  position: {
110
- x: x - i,
111
- y: W - i
110
+ x: i - t,
111
+ y: R - t
112
112
  },
113
- width: T - x + i * 2,
114
- height: H - W + i * 2,
113
+ width: L - i + t * 2,
114
+ height: W - R + t * 2,
115
115
  data: {
116
116
  ...se,
117
- label: U ? "Geo Group" : "Group",
118
- fill: U ? "#fefce8" : "#f0f9ff",
117
+ label: H ? "Geo Group" : "Group",
118
+ fill: H ? "#fefce8" : "#f0f9ff",
119
119
  stroke: "#9ca3af",
120
120
  strokeWidth: 1.5,
121
- borderStyle: U ? "dashed" : "dotted",
121
+ borderStyle: H ? "dashed" : "dotted",
122
122
  isGroup: !0
123
123
  }
124
124
  };
125
- y((P) => {
126
- const k = P.canvases[d];
127
- return k ? {
128
- ...P,
125
+ b((M) => {
126
+ const D = M.canvases[c];
127
+ return D ? {
128
+ ...M,
129
129
  canvases: {
130
- ...P.canvases,
131
- [d]: {
132
- ...k,
133
- nodes: U ? [M, ...k.nodes] : [M, ...k.nodes.map((O) => m.has(O.id) ? {
130
+ ...M.canvases,
131
+ [c]: {
132
+ ...D,
133
+ nodes: H ? [P, ...D.nodes] : [P, ...D.nodes.map((O) => w.has(O.id) ? {
134
134
  ...O,
135
- parentId: Z
135
+ parentId: U
136
136
  } : O)],
137
- lines: U ? k.lines : k.lines.map((O) => N.has(O.id) ? {
137
+ lines: H ? D.lines : D.lines.map((O) => N.has(O.id) ? {
138
138
  ...O,
139
- parentId: Z
139
+ parentId: U
140
140
  } : O)
141
141
  }
142
142
  }
143
- } : P;
143
+ } : M;
144
144
  }), l({
145
- nodeIds: /* @__PURE__ */ new Set([Z]),
145
+ nodeIds: /* @__PURE__ */ new Set([U]),
146
146
  edgeIds: /* @__PURE__ */ new Set(),
147
147
  lineIds: /* @__PURE__ */ new Set()
148
148
  });
149
149
  }, [
150
150
  s,
151
151
  n,
152
- y,
153
- d,
152
+ b,
153
+ c,
154
154
  l
155
- ]), G = D(() => S("flowGroup"), [S]), L = D(() => S("geometryGroup"), [S]), K = D(() => {
155
+ ]), K = E(() => S("flowGroup"), [S]), z = E(() => S("geometryGroup"), [S]), J = E(() => {
156
156
  const f = s.nodeIds;
157
157
  if (f.size === 0) return;
158
- const m = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set();
159
- for (const t of n.nodes) f.has(t.id) && (t.type === "flowGroup" || t.type === "geometryGroup" || t.data.isGroup) && m.add(t.id);
160
- if (m.size !== 0) {
161
- for (const t of n.nodes) t.parentId && m.has(t.parentId) && N.add(t.id);
162
- for (const t of n.lines) t.parentId && m.has(t.parentId) && E.add(t.id);
163
- y((t) => {
164
- const i = t.canvases[d];
165
- return i ? {
166
- ...t,
158
+ const w = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Set();
159
+ for (const d of n.nodes) f.has(d.id) && (d.type === "flowGroup" || d.type === "geometryGroup" || d.data.isGroup) && w.add(d.id);
160
+ if (w.size !== 0) {
161
+ for (const d of n.nodes) d.parentId && w.has(d.parentId) && N.add(d.id);
162
+ for (const d of n.lines) d.parentId && w.has(d.parentId) && k.add(d.id);
163
+ b((d) => {
164
+ const t = d.canvases[c];
165
+ return t ? {
166
+ ...d,
167
167
  canvases: {
168
- ...t.canvases,
169
- [d]: {
170
- ...i,
171
- nodes: i.nodes.filter((x) => !m.has(x.id)).map((x) => N.has(x.id) ? {
172
- ...x,
168
+ ...d.canvases,
169
+ [c]: {
170
+ ...t,
171
+ nodes: t.nodes.filter((i) => !w.has(i.id)).map((i) => N.has(i.id) ? {
172
+ ...i,
173
173
  parentId: void 0
174
- } : x),
175
- lines: i.lines.map((x) => E.has(x.id) ? {
176
- ...x,
174
+ } : i),
175
+ lines: t.lines.map((i) => k.has(i.id) ? {
176
+ ...i,
177
177
  parentId: void 0
178
- } : x)
178
+ } : i)
179
179
  }
180
180
  }
181
- } : t;
181
+ } : d;
182
182
  }), l({
183
183
  nodeIds: N,
184
184
  edgeIds: /* @__PURE__ */ new Set(),
185
- lineIds: E
185
+ lineIds: k
186
186
  });
187
187
  }
188
188
  }, [
189
189
  s,
190
190
  n,
191
- y,
192
- d,
191
+ b,
192
+ c,
193
193
  l
194
194
  ]);
195
- a.current = G, w.current = L, u.current = K;
196
- const C = D((f) => {
197
- const m = s.nodeIds, N = s.lineIds;
198
- m.size === 0 && N.size === 0 || y((E) => {
199
- const t = E.canvases[d];
200
- if (!t) return E;
201
- const i = t.nodes.map((M) => M.zIndex ?? 0), x = i.length > 0 ? Math.max(...i) : 0, W = i.length > 0 ? Math.min(...i) : 0, T = t.lines.map((M) => M.zIndex ?? 0), H = T.length > 0 ? Math.max(...T) : 0, U = T.length > 0 ? Math.min(...T) : 0, Z = (M, P, k) => f === "front" ? P + 1 : f === "back" ? k - 1 : f === "up" ? M + 1 : M - 1;
195
+ a.current = K, v.current = z, u.current = J;
196
+ const C = E((f) => {
197
+ const w = s.nodeIds, N = s.lineIds;
198
+ w.size === 0 && N.size === 0 || b((k) => {
199
+ const d = k.canvases[c];
200
+ if (!d) return k;
201
+ const t = d.nodes.map((P) => P.zIndex ?? 0), i = t.length > 0 ? Math.max(...t) : 0, R = t.length > 0 ? Math.min(...t) : 0, L = d.lines.map((P) => P.zIndex ?? 0), W = L.length > 0 ? Math.max(...L) : 0, H = L.length > 0 ? Math.min(...L) : 0, U = (P, M, D) => f === "front" ? M + 1 : f === "back" ? D - 1 : f === "up" ? P + 1 : P - 1;
202
202
  return {
203
- ...E,
203
+ ...k,
204
204
  canvases: {
205
- ...E.canvases,
206
- [d]: {
207
- ...t,
208
- nodes: t.nodes.map((M) => m.has(M.id) ? {
209
- ...M,
210
- zIndex: Z(M.zIndex ?? 0, x, W)
211
- } : M),
212
- lines: t.lines.map((M) => N.has(M.id) ? {
213
- ...M,
214
- zIndex: Z(M.zIndex ?? 0, H, U)
215
- } : M)
205
+ ...k.canvases,
206
+ [c]: {
207
+ ...d,
208
+ nodes: d.nodes.map((P) => w.has(P.id) ? {
209
+ ...P,
210
+ zIndex: U(P.zIndex ?? 0, i, R)
211
+ } : P),
212
+ lines: d.lines.map((P) => N.has(P.id) ? {
213
+ ...P,
214
+ zIndex: U(P.zIndex ?? 0, W, H)
215
+ } : P)
216
216
  }
217
217
  }
218
218
  };
219
219
  });
220
220
  }, [
221
221
  s,
222
- y,
223
- d
222
+ b,
223
+ c
224
224
  ]);
225
225
  return X(() => {
226
- const f = (m) => {
227
- const N = m.target;
226
+ const f = (w) => {
227
+ const N = w.target;
228
228
  if (N?.tagName === "INPUT" || N?.tagName === "TEXTAREA" || N?.isContentEditable) return;
229
- const E = Array.from(m.clipboardData?.items ?? []).find((x) => x.type.startsWith("image/"));
230
- if (!E) {
231
- m.preventDefault(), c();
229
+ const k = Array.from(w.clipboardData?.items ?? []).find((i) => i.type.startsWith("image/"));
230
+ if (!k) {
231
+ w.preventDefault(), m();
232
232
  return;
233
233
  }
234
- const t = E.getAsFile();
235
- if (!t) return;
236
- m.preventDefault();
237
- const i = new FileReader();
238
- i.onload = () => {
239
- if (typeof i.result != "string") return;
240
- const x = s.nodeIds.size === 1 ? n.nodes.find((A) => s.nodeIds.has(A.id) && A.type === "mediaNode" && A.data.mediaKind === "image") : void 0;
241
- if (x) {
242
- y((A) => {
243
- const $ = A.canvases[d];
234
+ const d = k.getAsFile();
235
+ if (!d) return;
236
+ w.preventDefault();
237
+ const t = new FileReader();
238
+ t.onload = () => {
239
+ if (typeof t.result != "string") return;
240
+ const i = s.nodeIds.size === 1 ? n.nodes.find((A) => s.nodeIds.has(A.id) && A.type === "mediaNode" && A.data.mediaKind === "image") : void 0;
241
+ if (i) {
242
+ b((A) => {
243
+ const $ = A.canvases[c];
244
244
  return $ ? {
245
245
  ...A,
246
246
  canvases: {
247
247
  ...A.canvases,
248
- [d]: {
248
+ [c]: {
249
249
  ...$,
250
- nodes: $.nodes.map((V) => V.id === x.id ? {
250
+ nodes: $.nodes.map((V) => V.id === i.id ? {
251
251
  ...V,
252
252
  data: {
253
253
  ...V.data,
254
- mediaContent: i.result
254
+ mediaContent: t.result
255
255
  }
256
256
  } : V)
257
257
  }
@@ -260,19 +260,19 @@ function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: w, ungroupRef: u }
260
260
  });
261
261
  return;
262
262
  }
263
- const W = Q("node"), T = 320, H = 220, U = window.innerWidth, Z = window.innerHeight, M = (U / 2 - I.x) / I.zoom, P = (Z / 2 - I.y) / I.zoom, k = Math.max(0, ...n.nodes.map((A) => A.zIndex ?? 0)), O = {
264
- id: W,
263
+ const R = Q("node"), L = 320, W = 220, H = window.innerWidth, U = window.innerHeight, P = (H / 2 - y.x) / y.zoom, M = (U / 2 - y.y) / y.zoom, D = Math.max(0, ...n.nodes.map((A) => A.zIndex ?? 0)), O = {
264
+ id: R,
265
265
  type: "mediaNode",
266
266
  position: {
267
- x: M - T / 2,
268
- y: P - H / 2
267
+ x: P - L / 2,
268
+ y: M - W / 2
269
269
  },
270
- width: T,
271
- height: H,
272
- zIndex: k + 1,
270
+ width: L,
271
+ height: W,
272
+ zIndex: D + 1,
273
273
  data: {
274
274
  ...se,
275
- label: t.name || "Image",
275
+ label: d.name || "Image",
276
276
  fill: "theme:base-100",
277
277
  stroke: "theme:base-content",
278
278
  strokeWidth: 1.5,
@@ -280,49 +280,49 @@ function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: w, ungroupRef: u }
280
280
  fontSize: 13,
281
281
  borderStyle: "solid",
282
282
  mediaKind: "image",
283
- mediaContent: i.result
283
+ mediaContent: t.result
284
284
  }
285
285
  };
286
- y((A) => {
287
- const $ = A.canvases[d];
286
+ b((A) => {
287
+ const $ = A.canvases[c];
288
288
  return $ ? {
289
289
  ...A,
290
290
  canvases: {
291
291
  ...A.canvases,
292
- [d]: {
292
+ [c]: {
293
293
  ...$,
294
294
  nodes: [...$.nodes, O]
295
295
  }
296
296
  }
297
297
  } : A;
298
298
  }), l({
299
- nodeIds: /* @__PURE__ */ new Set([W]),
299
+ nodeIds: /* @__PURE__ */ new Set([R]),
300
300
  edgeIds: /* @__PURE__ */ new Set(),
301
301
  lineIds: /* @__PURE__ */ new Set()
302
302
  });
303
- }, i.readAsDataURL(t);
303
+ }, t.readAsDataURL(d);
304
304
  };
305
305
  return window.addEventListener("paste", f), () => window.removeEventListener("paste", f);
306
306
  }, [
307
307
  n,
308
- d,
309
308
  c,
309
+ m,
310
310
  s,
311
- y,
311
+ b,
312
312
  l,
313
- I
313
+ y
314
314
  ]), Je(le(() => ({
315
315
  undo: o,
316
316
  redo: p,
317
317
  copy: e,
318
- cut: h,
319
- paste: c,
320
- duplicate: v,
321
- deleteSelected: b,
318
+ cut: I,
319
+ paste: m,
320
+ duplicate: h,
321
+ deleteSelected: x,
322
322
  selectAll: g,
323
- group: G,
324
- geoGroup: L,
325
- ungroup: K,
323
+ group: K,
324
+ geoGroup: z,
325
+ ungroup: J,
326
326
  bringToFront: () => C("front"),
327
327
  bringForward: () => C("up"),
328
328
  sendBackward: () => C("down"),
@@ -331,130 +331,130 @@ function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: w, ungroupRef: u }
331
331
  o,
332
332
  p,
333
333
  e,
334
+ I,
335
+ m,
334
336
  h,
335
- c,
336
- v,
337
- b,
337
+ x,
338
338
  g,
339
- G,
340
- L,
341
339
  K,
340
+ z,
341
+ J,
342
342
  C
343
343
  ])), Oe(), null;
344
344
  }
345
345
  function Ye({ pixiRef: o, exportPdfRef: p }) {
346
346
  return p.current = Ze(o), null;
347
347
  }
348
- var Ht = _e(function({ initialDocument: p, onChange: a, width: w, height: u, readOnly: s = !1, onBack: l, onExportPNG: n, onPublish: y, showMiniMap: d = !0, showGrid: I = !0, gridSize: e = 20, className: h, showAI: c = !0, showAIConfig: v = !0, aiConfig: b }, g) {
349
- const [S, G] = j(() => Ve(p ?? Ie())), [L, K] = j(je), C = R(null), f = R(null), m = R(null), N = R(null), E = Ue(N), { wrappedSetDoc: t, undo: i, redo: x, canUndo: W, canRedo: T } = He(S, G), H = R(null), U = R(null), Z = R(null), M = R(null), P = R(a);
350
- P.current = a;
351
- const k = R(S);
352
- k.current = S, $e(g, () => ({
353
- exportPNG: async (F) => {
354
- const z = C.current;
355
- return !z || z.destroyed ? null : z.exportPNG(F);
348
+ var Ht = _e(function({ initialDocument: p, onChange: a, width: v, height: u, readOnly: s = !1, onBack: l, onExportPNG: n, onPublish: b, showMiniMap: c = !0, showGrid: y = !0, gridSize: e = 20, className: I, showAI: m = !0, showAIConfig: h = !0, aiConfig: x }, g) {
349
+ const [S, K] = j(() => Ve(p ?? Ie())), [z, J] = j(je), C = F(null), f = F(null), w = F(null), N = F(null), k = Ue(N), { wrappedSetDoc: d, undo: t, redo: i, canUndo: R, canRedo: L } = He(S, K), W = F(null), H = F(null), U = F(null), P = F(null), M = F(a);
350
+ M.current = a;
351
+ const D = F(S);
352
+ D.current = S, $e(g, () => ({
353
+ exportPNG: async (G) => {
354
+ const T = C.current;
355
+ return !T || T.destroyed ? null : T.exportPNG(G);
356
356
  },
357
- getDocument: () => k.current
357
+ getDocument: () => D.current
358
358
  }), []);
359
- const O = D((F) => {
360
- t((z) => {
361
- const B = typeof F == "function" ? F(z) : F;
362
- return s ? B.canvases === z.canvases && B.title === z.title ? B : z : (queueMicrotask(() => P.current?.(B)), B);
359
+ const O = E((G) => {
360
+ d((T) => {
361
+ const B = typeof G == "function" ? G(T) : G;
362
+ return s ? B.canvases === T.canvases && B.title === T.title ? B : T : (queueMicrotask(() => M.current?.(B)), B);
363
363
  });
364
- }, [t, s]), A = D(() => {
364
+ }, [d, s]), A = E(() => {
365
+ s || t();
366
+ }, [s, t]), $ = E(() => {
365
367
  s || i();
366
- }, [s, i]), $ = D(() => {
367
- s || x();
368
- }, [s, x]), V = D((F) => {
369
- C.current = F, f.current && !m.current && (m.current = new We(f.current));
370
- }, []), de = D(async () => {
368
+ }, [s, i]), V = E((G) => {
369
+ C.current = G, f.current && !w.current && (w.current = new We(f.current));
370
+ }, []), de = E(async () => {
371
371
  if (n) return void n();
372
- const F = C.current;
373
- if (!F || F.destroyed) return;
374
- const z = await F.exportPNG(16777215);
375
- z && Me(z, `${Pe(k.current.title)}.png`);
376
- }, [n]), ue = D(async () => {
377
- await M.current?.();
372
+ const G = C.current;
373
+ if (!G || G.destroyed) return;
374
+ const T = await G.exportPNG(16777215);
375
+ T && Pe(T, `${Me(D.current.title)}.png`);
376
+ }, [n]), ue = E(async () => {
377
+ await P.current?.();
378
378
  }, []);
379
379
  X(() => {
380
- let F = !1, z = null;
380
+ let G = !1, T = null;
381
381
  const B = () => {
382
- const J = C.current, ne = m.current;
383
- if (!J || J.destroyed || !ne) return;
382
+ const Z = C.current, ne = w.current;
383
+ if (!Z || Z.destroyed || !ne) return;
384
384
  const pe = {
385
- x: J.world.position.x,
386
- y: J.world.position.y,
387
- zoom: J.world.scale.x
385
+ x: Z.world.position.x,
386
+ y: Z.world.position.y,
387
+ zoom: Z.world.scale.x
388
388
  }, me = S.stack[S.stack.length - 1] ?? "root", oe = S.canvases[me];
389
- oe && ne.update(oe.nodes, pe, J.app.screen.width, J.app.screen.height);
389
+ oe && ne.update(oe.nodes, pe, Z.app.screen.width, Z.app.screen.height);
390
390
  }, te = () => {
391
- if (F) return;
392
- const J = C.current;
393
- J && !J.destroyed && m.current ? (J.app.ticker.add(B), z = J) : requestAnimationFrame(te);
391
+ if (G) return;
392
+ const Z = C.current;
393
+ Z && !Z.destroyed && w.current ? (Z.app.ticker.add(B), T = Z) : requestAnimationFrame(te);
394
394
  };
395
395
  return te(), () => {
396
- F = !0, z && !z.destroyed && z.app.ticker.remove(B);
396
+ G = !0, T && !T.destroyed && T.app.ticker.remove(B);
397
397
  };
398
398
  }, [S]);
399
399
  const fe = {
400
- width: w ?? "100%",
400
+ width: v ?? "100%",
401
401
  height: u ?? "100%"
402
402
  };
403
403
  return /* @__PURE__ */ r("div", {
404
404
  ref: N,
405
- className: `flow-container ${h ?? ""}`,
405
+ className: `flow-container ${I ?? ""}`,
406
406
  style: fe,
407
407
  children: /* @__PURE__ */ r(ve, {
408
408
  doc: S,
409
409
  setDoc: O,
410
- selection: L,
411
- setSelection: K,
410
+ selection: z,
411
+ setSelection: J,
412
412
  children: /* @__PURE__ */ r(ye, {
413
- showMiniMap: d,
414
- showGrid: I,
413
+ showMiniMap: c,
414
+ showGrid: y,
415
415
  gridSize: e,
416
- showAI: c,
416
+ showAI: m,
417
417
  readOnly: s,
418
418
  children: /* @__PURE__ */ _(be, {
419
- initialConfig: b,
420
- showAIConfig: v,
419
+ initialConfig: x,
420
+ showAIConfig: h,
421
421
  children: [
422
422
  /* @__PURE__ */ r(Xe, {
423
423
  onUndo: A,
424
424
  onRedo: $,
425
- groupRef: H,
426
- geoGroupRef: U,
427
- ungroupRef: Z
425
+ groupRef: W,
426
+ geoGroupRef: H,
427
+ ungroupRef: U
428
428
  }),
429
429
  /* @__PURE__ */ r(Ye, {
430
430
  pixiRef: C,
431
- exportPdfRef: M
431
+ exportPdfRef: P
432
432
  }),
433
433
  /* @__PURE__ */ _(tt, {
434
- compact: E,
434
+ compact: k,
435
435
  toolbar: s ? null : /* @__PURE__ */ r(Ne, {
436
- compact: E,
436
+ compact: k,
437
437
  onBack: l,
438
438
  onUndo: A,
439
439
  onRedo: $,
440
- canUndo: W,
441
- canRedo: T,
442
- onGroup: () => H.current?.(),
443
- onGeoGroup: () => U.current?.(),
444
- onUngroup: () => Z.current?.(),
440
+ canUndo: R,
441
+ canRedo: L,
442
+ onGroup: () => W.current?.(),
443
+ onGeoGroup: () => H.current?.(),
444
+ onUngroup: () => U.current?.(),
445
445
  onExportPNG: de,
446
446
  onExportPDF: ue,
447
- onPublish: y
447
+ onPublish: b
448
448
  }),
449
449
  children: [
450
450
  /* @__PURE__ */ r(Ce, { onPixiReady: V }),
451
451
  /* @__PURE__ */ r(Fe, {}),
452
452
  /* @__PURE__ */ _(qe, { children: [!s && /* @__PURE__ */ r(ke, {}), /* @__PURE__ */ r(Ge, {})] }),
453
- !s && /* @__PURE__ */ r(it, {}),
453
+ !s && /* @__PURE__ */ r(rt, {}),
454
454
  /* @__PURE__ */ r(nt, {
455
455
  canvasRef: f,
456
456
  pixiRef: C,
457
- miniMapRef: m
457
+ miniMapRef: w
458
458
  }),
459
459
  /* @__PURE__ */ r(Le, {})
460
460
  ]
@@ -517,7 +517,7 @@ var Qe = [
517
517
  showKey: "showAI"
518
518
  }
519
519
  ];
520
- function re(o) {
520
+ function ie(o) {
521
521
  switch (o) {
522
522
  case "shapes":
523
523
  return /* @__PURE__ */ r(Ee, {});
@@ -530,7 +530,7 @@ function re(o) {
530
530
  case "outline":
531
531
  return /* @__PURE__ */ r(Te, {});
532
532
  case "json":
533
- return /* @__PURE__ */ r(rt, {});
533
+ return /* @__PURE__ */ r(it, {});
534
534
  case "ai":
535
535
  return /* @__PURE__ */ r(Re, {});
536
536
  default:
@@ -543,49 +543,51 @@ var et = /* @__PURE__ */ new Set([
543
543
  "media"
544
544
  ]);
545
545
  function tt({ children: o, toolbar: p, compact: a }) {
546
- const w = Y(), { panelDocks: u, setPanelDock: s, presentation: l, readOnly: n } = w, { setShowPalette: y, setShowInspector: d, setShowOutline: I, setShowJson: e, setShowAI: h } = w, c = n ? [] : Qe.filter((t) => !t.showKey || w[t.showKey]), v = (t) => ({
546
+ const v = Y(), { panelDocks: u, setPanelDock: s, presentation: l, readOnly: n, setPendingPlacement: b } = v, { setShowPalette: c, setShowInspector: y, setShowOutline: e, setShowJson: I, setShowAI: m } = v, h = n ? [] : Qe.filter((t) => !t.showKey || v[t.showKey]), x = (t) => ({
547
547
  id: t.id,
548
548
  label: t.label,
549
549
  icon: t.icon,
550
- content: re(t.id)
551
- }), [b, g] = j(null), S = R(null);
550
+ content: ie(t.id)
551
+ }), [g, S] = j(null), K = F(null);
552
552
  X(() => {
553
553
  if (!a) {
554
- S.current = null;
554
+ K.current = null;
555
555
  return;
556
556
  }
557
- const t = w.pendingPlacement, i = t ? `${t.type}:${t.data?.svgId ?? ""}:${t.data?.mediaKind ?? ""}` : null, x = S.current;
558
- S.current = i, i && i !== x && b && et.has(b) && g(null);
557
+ const t = v.pendingPlacement, i = t ? `${t.type}:${t.data?.svgId ?? ""}:${t.data?.mediaKind ?? ""}` : null, R = K.current;
558
+ K.current = i, i && i !== R && g && et.has(g) && S(null);
559
559
  }, [
560
- w.pendingPlacement,
560
+ v.pendingPlacement,
561
561
  a,
562
- b
562
+ g
563
563
  ]);
564
- const [G, L] = j(null), K = D((t, i) => s(t, i), [s]), C = D((t) => {
565
- t === "inspector" ? d(!1) : t === "outline" ? I(!1) : t === "json" ? e(!1) : t === "ai" ? h(!1) : y(!1);
564
+ const [z, J] = j(null), C = E((t, i) => s(t, i), [s]), f = E((t) => {
565
+ t === "inspector" ? y(!1) : t === "outline" ? e(!1) : t === "json" ? I(!1) : t === "ai" ? m(!1) : c(!1);
566
566
  }, [
567
- d,
568
- I,
567
+ y,
569
568
  e,
570
- h,
571
- y
569
+ I,
570
+ m,
571
+ c
572
572
  ]);
573
573
  if (a && !l) {
574
- const t = c.find((i) => i.id === b) ?? null;
574
+ const t = h.find((i) => i.id === g) ?? null;
575
575
  return /* @__PURE__ */ _("div", {
576
576
  className: "flow-workspace",
577
577
  children: [
578
578
  p,
579
- c.length > 0 && /* @__PURE__ */ r("div", {
579
+ h.length > 0 && /* @__PURE__ */ r("div", {
580
580
  className: "flow-mobile-panel-bar",
581
581
  children: /* @__PURE__ */ r(he, {
582
582
  placeholder: "选择面板…",
583
- options: c.map((i) => ({
583
+ options: h.map((i) => ({
584
584
  value: i.id,
585
585
  label: i.label
586
586
  })),
587
- value: b ?? void 0,
588
- onChange: (i) => g(String(i))
587
+ value: g ?? void 0,
588
+ onChange: (i) => {
589
+ b(null), S(String(i));
590
+ }
589
591
  })
590
592
  }),
591
593
  /* @__PURE__ */ _("div", {
@@ -607,48 +609,48 @@ function tt({ children: o, toolbar: p, compact: a }) {
607
609
  type: "button",
608
610
  className: "flow-mobile-panel-close",
609
611
  "aria-label": "关闭面板",
610
- onClick: () => g(null),
612
+ onClick: () => S(null),
611
613
  children: "✕"
612
614
  })]
613
615
  }), /* @__PURE__ */ r("div", {
614
616
  className: "flow-mobile-panel-body",
615
- children: re(t.id)
617
+ children: ie(t.id)
616
618
  })]
617
619
  })]
618
620
  })
619
621
  ]
620
622
  });
621
623
  }
622
- const f = (t) => u[t] ?? "left", m = c.filter((t) => f(t.id) === "left").map(v), N = c.filter((t) => f(t.id) === "right").map(v), E = c.filter((t) => f(t.id) === "float");
624
+ const w = (t) => u[t] ?? "left", N = h.filter((t) => w(t.id) === "left").map(x), k = h.filter((t) => w(t.id) === "right").map(x), d = h.filter((t) => w(t.id) === "float");
623
625
  return /* @__PURE__ */ _("div", {
624
626
  className: "flow-workspace",
625
627
  children: [!l && p, /* @__PURE__ */ _("div", {
626
628
  className: "flow-workspace-main",
627
629
  children: [
628
- !l && m.length > 0 && /* @__PURE__ */ r(q, {
629
- tabs: m,
630
- defaultTab: m[0]?.id,
630
+ !l && N.length > 0 && /* @__PURE__ */ r(q, {
631
+ tabs: N,
632
+ defaultTab: N[0]?.id,
631
633
  resizeEdge: "right",
632
634
  defaultWidth: 220,
633
635
  dock: "left",
634
- onDock: K,
635
- onClose: C
636
+ onDock: C,
637
+ onClose: f
636
638
  }),
637
639
  /* @__PURE__ */ r("div", {
638
640
  className: "flow-stage",
639
641
  children: o
640
642
  }),
641
- !l && N.length > 0 && /* @__PURE__ */ r(q, {
642
- tabs: N,
643
- defaultTab: N[0]?.id,
643
+ !l && k.length > 0 && /* @__PURE__ */ r(q, {
644
+ tabs: k,
645
+ defaultTab: k[0]?.id,
644
646
  resizeEdge: "left",
645
647
  defaultWidth: 220,
646
648
  dock: "right",
647
- onDock: K,
648
- onClose: C
649
+ onDock: C,
650
+ onClose: f
649
651
  }),
650
- !l && E.map((t, i) => /* @__PURE__ */ r(q, {
651
- tabs: [v(t)],
652
+ !l && d.map((t, i) => /* @__PURE__ */ r(q, {
653
+ tabs: [x(t)],
652
654
  resizeEdge: "right",
653
655
  defaultWidth: 220,
654
656
  dock: "float",
@@ -656,29 +658,29 @@ function tt({ children: o, toolbar: p, compact: a }) {
656
658
  top: 48 + i * 40,
657
659
  left: 24 + i * 30
658
660
  },
659
- onDock: K,
660
- onClose: C,
661
- onDragHintChange: L
661
+ onDock: C,
662
+ onClose: f,
663
+ onDragHintChange: J
662
664
  }, t.id)),
663
- !l && G && /* @__PURE__ */ r("div", {
664
- className: `flow-dock-dropzone flow-dock-dropzone--${G}`,
665
- children: /* @__PURE__ */ r("span", { children: G === "left" ? "⇤ 停靠左侧" : "停靠右侧 ⇥" })
665
+ !l && z && /* @__PURE__ */ r("div", {
666
+ className: `flow-dock-dropzone flow-dock-dropzone--${z}`,
667
+ children: /* @__PURE__ */ r("span", { children: z === "left" ? "⇤ 停靠左侧" : "停靠右侧 ⇥" })
666
668
  })
667
669
  ]
668
670
  })]
669
671
  });
670
672
  }
671
673
  function nt({ canvasRef: o, pixiRef: p, miniMapRef: a }) {
672
- const { showMiniMap: w, setViewport: u, presentation: s } = Y(), l = R(!1), n = D((e, h) => {
673
- const c = o.current, v = p.current, b = a.current;
674
- if (!c || !v || v.destroyed || !b) return;
675
- const g = c.getBoundingClientRect();
674
+ const { showMiniMap: v, setViewport: u, presentation: s } = Y(), l = F(!1), n = E((e, I) => {
675
+ const m = o.current, h = p.current, x = a.current;
676
+ if (!m || !h || h.destroyed || !x) return;
677
+ const g = m.getBoundingClientRect();
676
678
  if (g.width === 0 || g.height === 0) return;
677
- const { width: S, height: G } = b.size, L = (e - g.left) / g.width * S, K = (h - g.top) / g.height * G, C = b.minimapToWorld(L, K);
679
+ const { width: S, height: K } = x.size, z = (e - g.left) / g.width * S, J = (I - g.top) / g.height * K, C = x.minimapToWorld(z, J);
678
680
  if (!C) return;
679
- const f = v.world.scale.x || 1, m = v.app.screen.width, N = v.app.screen.height;
681
+ const f = h.world.scale.x || 1, w = h.app.screen.width, N = h.app.screen.height;
680
682
  u({
681
- x: m / 2 - C.x * f,
683
+ x: w / 2 - C.x * f,
682
684
  y: N / 2 - C.y * f,
683
685
  zoom: f
684
686
  });
@@ -687,11 +689,11 @@ function nt({ canvasRef: o, pixiRef: p, miniMapRef: a }) {
687
689
  p,
688
690
  a,
689
691
  u
690
- ]), y = D((e) => {
692
+ ]), b = E((e) => {
691
693
  e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), l.current = !0, n(e.clientX, e.clientY);
692
- }, [n]), d = D((e) => {
694
+ }, [n]), c = E((e) => {
693
695
  l.current && n(e.clientX, e.clientY);
694
- }, [n]), I = D((e) => {
696
+ }, [n]), y = E((e) => {
695
697
  l.current = !1;
696
698
  try {
697
699
  e.currentTarget.releasePointerCapture(e.pointerId);
@@ -701,12 +703,12 @@ function nt({ canvasRef: o, pixiRef: p, miniMapRef: a }) {
701
703
  return /* @__PURE__ */ r("div", {
702
704
  className: "flow-minimap",
703
705
  style: {
704
- display: w && !s ? void 0 : "none",
706
+ display: v && !s ? void 0 : "none",
705
707
  cursor: "pointer"
706
708
  },
707
- onPointerDown: y,
708
- onPointerMove: d,
709
- onPointerUp: I,
709
+ onPointerDown: b,
710
+ onPointerMove: c,
711
+ onPointerUp: y,
710
712
  title: "点击或拖动以移动画布",
711
713
  children: /* @__PURE__ */ r("canvas", {
712
714
  ref: o,
@@ -721,10 +723,10 @@ function nt({ canvasRef: o, pixiRef: p, miniMapRef: a }) {
721
723
  });
722
724
  }
723
725
  function ot(o, p) {
724
- const a = `"id": "${p}"`, w = o.indexOf(a);
725
- if (w === -1) return null;
726
+ const a = `"id": "${p}"`, v = o.indexOf(a);
727
+ if (v === -1) return null;
726
728
  let u = 0, s = -1;
727
- for (let n = w; n >= 0; n--)
729
+ for (let n = v; n >= 0; n--)
728
730
  if (o[n] === "}" && u++, o[n] === "{") {
729
731
  if (u === 0) {
730
732
  s = n;
@@ -747,69 +749,69 @@ function ot(o, p) {
747
749
  `).length
748
750
  };
749
751
  }
750
- function ie(o) {
752
+ function re(o) {
751
753
  o.querySelectorAll(".cm-line.flow-json-hl").forEach((p) => p.classList.remove("flow-json-hl"));
752
754
  }
753
755
  function st(o, p, a) {
754
- const w = o.getView();
755
- if (w)
756
+ const v = o.getView();
757
+ if (v)
756
758
  for (let u = p; u <= a; u++) try {
757
- const s = w.state.doc.line(u), l = w.domAtPos(s.from), n = l.node instanceof HTMLElement ? l.node.closest(".cm-line") : l.node.parentElement?.closest(".cm-line");
759
+ const s = v.state.doc.line(u), l = v.domAtPos(s.from), n = l.node instanceof HTMLElement ? l.node.closest(".cm-line") : l.node.parentElement?.closest(".cm-line");
758
760
  n && n.classList.add("flow-json-hl");
759
761
  } catch {
760
762
  }
761
763
  }
762
- function rt() {
763
- const { setDoc: o, currentCanvasId: p, selection: a, currentCanvas: w } = ee(), [u, s] = j(""), [l, n] = j(null), y = R(!1), d = R(null), I = R(null), e = le(() => a.nodeIds.size + a.edgeIds.size + a.lineIds.size !== 1 ? null : a.nodeIds.size === 1 ? [...a.nodeIds][0] : a.edgeIds.size === 1 ? [...a.edgeIds][0] : a.lineIds.size === 1 ? [...a.lineIds][0] : null, [a]);
764
+ function it() {
765
+ const { setDoc: o, currentCanvasId: p, selection: a, currentCanvas: v } = ee(), [u, s] = j(""), [l, n] = j(null), b = F(!1), c = F(null), y = F(null), e = le(() => a.nodeIds.size + a.edgeIds.size + a.lineIds.size !== 1 ? null : a.nodeIds.size === 1 ? [...a.nodeIds][0] : a.edgeIds.size === 1 ? [...a.edgeIds][0] : a.lineIds.size === 1 ? [...a.lineIds][0] : null, [a]);
764
766
  X(() => {
765
- if (y.current) {
766
- y.current = !1;
767
+ if (b.current) {
768
+ b.current = !1;
767
769
  return;
768
770
  }
769
- s(JSON.stringify(w, null, 2)), n(null);
770
- }, [w]), X(() => {
771
- const v = I.current;
772
- if (v && ie(v), !e) return;
773
- const b = setTimeout(() => {
771
+ s(JSON.stringify(v, null, 2)), n(null);
772
+ }, [v]), X(() => {
773
+ const h = y.current;
774
+ if (h && re(h), !e) return;
775
+ const x = setTimeout(() => {
774
776
  const g = ot(u, e);
775
- if (!g || !I.current) return;
776
- const S = d.current?.getView();
777
+ if (!g || !y.current) return;
778
+ const S = c.current?.getView();
777
779
  if (!S) return;
778
- const G = I.current, L = S.scrollDOM;
779
- L.style.scrollBehavior = "smooth";
780
- const K = S.state.doc.line(g.startLine);
781
- S.dispatch({ effects: Be.scrollIntoView(K.from, {
780
+ const K = y.current, z = S.scrollDOM;
781
+ z.style.scrollBehavior = "smooth";
782
+ const J = S.state.doc.line(g.startLine);
783
+ S.dispatch({ effects: Be.scrollIntoView(J.from, {
782
784
  y: "start",
783
785
  yMargin: 0
784
786
  }) });
785
787
  const C = () => {
786
- L.style.scrollBehavior = "", ie(G), st(d.current, g.startLine, g.endLine);
788
+ z.style.scrollBehavior = "", re(K), st(c.current, g.startLine, g.endLine);
787
789
  };
788
790
  let f;
789
- const m = () => {
791
+ const w = () => {
790
792
  clearTimeout(f), f = setTimeout(C, 100);
791
793
  };
792
- L.addEventListener("scroll", m), f = setTimeout(() => {
793
- L.removeEventListener("scroll", m), C();
794
+ z.addEventListener("scroll", w), f = setTimeout(() => {
795
+ z.removeEventListener("scroll", w), C();
794
796
  }, 800);
795
797
  }, 120);
796
- return () => clearTimeout(b);
798
+ return () => clearTimeout(x);
797
799
  }, [e, u]);
798
- const h = D((v) => {
799
- s(v);
800
+ const I = E((h) => {
801
+ s(h);
800
802
  try {
801
- const b = JSON.parse(v);
802
- b && Array.isArray(b.nodes) && Array.isArray(b.edges) && Array.isArray(b.lines) ? (n(null), y.current = !0, o((g) => ({
803
+ const x = JSON.parse(h);
804
+ x && Array.isArray(x.nodes) && Array.isArray(x.edges) && Array.isArray(x.lines) ? (n(null), b.current = !0, o((g) => ({
803
805
  ...g,
804
806
  canvases: {
805
807
  ...g.canvases,
806
- [p]: b
808
+ [p]: x
807
809
  }
808
810
  }))) : n("JSON must have nodes, edges, lines arrays");
809
- } catch (b) {
810
- n(b.message?.slice(0, 60) ?? "Invalid JSON");
811
+ } catch (x) {
812
+ n(x.message?.slice(0, 60) ?? "Invalid JSON");
811
813
  }
812
- }, [o, p]), c = e ? a.nodeIds.has(e) ? "Node" : a.edgeIds.has(e) ? "Edge" : "Line" : null;
814
+ }, [o, p]), m = e ? a.nodeIds.has(e) ? "Node" : a.edgeIds.has(e) ? "Edge" : "Line" : null;
813
815
  return /* @__PURE__ */ _("div", {
814
816
  style: {
815
817
  display: "flex",
@@ -822,7 +824,7 @@ function rt() {
822
824
  className: "flow-json-header",
823
825
  children: /* @__PURE__ */ r("span", {
824
826
  className: "flow-json-scope",
825
- children: c ? `${c}: ${e.slice(0, 8)}` : "Canvas"
827
+ children: m ? `${m}: ${e.slice(0, 8)}` : "Canvas"
826
828
  })
827
829
  }),
828
830
  l && /* @__PURE__ */ r("div", {
@@ -835,15 +837,15 @@ function rt() {
835
837
  children: l
836
838
  }),
837
839
  /* @__PURE__ */ r("div", {
838
- ref: I,
840
+ ref: y,
839
841
  style: {
840
842
  flex: 1,
841
843
  minHeight: 0
842
844
  },
843
845
  children: /* @__PURE__ */ r(ge, {
844
- ref: d,
846
+ ref: c,
845
847
  value: u,
846
- onChange: h,
848
+ onChange: I,
847
849
  language: "json",
848
850
  lineNumbers: !1,
849
851
  height: "100%",
@@ -853,51 +855,51 @@ function rt() {
853
855
  ]
854
856
  });
855
857
  }
856
- function it() {
857
- const { contextMenu: o, setContextMenu: p } = Y(), { doc: a, setDoc: w, currentCanvasId: u, pushCanvas: s, setSelection: l } = ee(), { duplicate: n } = ae();
858
+ function rt() {
859
+ const { contextMenu: o, setContextMenu: p } = Y(), { doc: a, setDoc: v, currentCanvasId: u, pushCanvas: s, setSelection: l } = ee(), { duplicate: n } = ae();
858
860
  if (!o) return null;
859
- const y = a.canvases[u];
860
- if (!y)
861
+ const b = a.canvases[u];
862
+ if (!b)
861
863
  return p(null), null;
862
- const d = o.nodeId ? y.nodes.find((e) => e.id === o.nodeId) : null, I = [];
863
- return d && (I.push({
864
+ const c = o.nodeId ? b.nodes.find((e) => e.id === o.nodeId) : null, y = [];
865
+ return c && (y.push({
864
866
  label: "Duplicate",
865
867
  icon: "⧉",
866
868
  action: () => {
867
- n(24, 24, { nodeIds: /* @__PURE__ */ new Set([d.id]) });
869
+ n(24, 24, { nodeIds: /* @__PURE__ */ new Set([c.id]) });
868
870
  }
869
- }), I.push({
871
+ }), y.push({
870
872
  label: "---",
871
873
  action: () => {
872
874
  }
873
- }), d.data.childCanvasId ? (I.push({
875
+ }), c.data.childCanvasId ? (y.push({
874
876
  label: "Enter Sub-canvas",
875
877
  icon: "↓",
876
878
  action: () => {
877
- s(d.data.childCanvasId), l({
879
+ s(c.data.childCanvasId), l({
878
880
  nodeIds: /* @__PURE__ */ new Set(),
879
881
  edgeIds: /* @__PURE__ */ new Set(),
880
882
  lineIds: /* @__PURE__ */ new Set()
881
883
  });
882
884
  }
883
- }), I.push({
885
+ }), y.push({
884
886
  label: "---",
885
887
  action: () => {
886
888
  }
887
- }), I.push({
889
+ }), y.push({
888
890
  label: "Delete Sub-canvas",
889
891
  icon: "🗑",
890
892
  danger: !0,
891
893
  action: () => {
892
- const e = d.data.childCanvasId;
893
- w((h) => {
894
- const c = { ...h.canvases };
895
- ce(c, e);
896
- const v = c[u];
897
- if (!v) return h;
898
- c[u] = {
899
- ...v,
900
- nodes: v.nodes.map((g) => g.id === d.id ? {
894
+ const e = c.data.childCanvasId;
895
+ v((I) => {
896
+ const m = { ...I.canvases };
897
+ ce(m, e);
898
+ const h = m[u];
899
+ if (!h) return I;
900
+ m[u] = {
901
+ ...h,
902
+ nodes: h.nodes.map((g) => g.id === c.id ? {
901
903
  ...g,
902
904
  data: {
903
905
  ...g.data,
@@ -905,34 +907,34 @@ function it() {
905
907
  }
906
908
  } : g)
907
909
  };
908
- const b = h.stack.filter((g) => c[g]);
909
- return b.length === 0 && b.push(we), {
910
- ...h,
911
- canvases: c,
912
- stack: b
910
+ const x = I.stack.filter((g) => m[g]);
911
+ return x.length === 0 && x.push(we), {
912
+ ...I,
913
+ canvases: m,
914
+ stack: x
913
915
  };
914
916
  });
915
917
  }
916
- })) : I.push({
918
+ })) : y.push({
917
919
  label: "Create Sub-canvas",
918
920
  icon: "⊞",
919
921
  action: () => {
920
922
  const e = Q("canvas");
921
- w((h) => {
922
- const c = h.canvases[u];
923
- return c ? {
924
- ...h,
923
+ v((I) => {
924
+ const m = I.canvases[u];
925
+ return m ? {
926
+ ...I,
925
927
  canvases: {
926
- ...h.canvases,
928
+ ...I.canvases,
927
929
  [u]: {
928
- ...c,
929
- nodes: c.nodes.map((v) => v.id === d.id ? {
930
- ...v,
930
+ ...m,
931
+ nodes: m.nodes.map((h) => h.id === c.id ? {
932
+ ...h,
931
933
  data: {
932
- ...v.data,
934
+ ...h.data,
933
935
  childCanvasId: e
934
936
  }
935
- } : v)
937
+ } : h)
936
938
  },
937
939
  [e]: {
938
940
  nodes: [],
@@ -940,20 +942,20 @@ function it() {
940
942
  lines: []
941
943
  }
942
944
  }
943
- } : h;
945
+ } : I;
944
946
  }), s(e);
945
947
  }
946
- })), I.length === 0 ? null : /* @__PURE__ */ r(Ke, {
948
+ })), y.length === 0 ? null : /* @__PURE__ */ r(Ke, {
947
949
  x: o.x,
948
950
  y: o.y,
949
- items: I,
951
+ items: y,
950
952
  onClose: () => p(null)
951
953
  });
952
954
  }
953
955
  function ce(o, p) {
954
956
  const a = o[p];
955
957
  if (a) {
956
- for (const w of a.nodes) w.data.childCanvasId && ce(o, w.data.childCanvasId);
958
+ for (const v of a.nodes) v.data.childCanvasId && ce(o, v.data.childCanvasId);
957
959
  delete o[p];
958
960
  }
959
961
  }