dishui 0.0.56 → 0.0.59

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