dishui 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/pro/Flow/Flow.js +419 -407
- package/dist/components/pro/Flow/Flow.js.map +1 -1
- package/dist/components/pro/Flow/archify/build.d.ts +74 -0
- package/dist/components/pro/Flow/archify/build.js +103 -0
- package/dist/components/pro/Flow/archify/build.js.map +1 -0
- package/dist/components/pro/Flow/archify/convert.d.ts +14 -0
- package/dist/components/pro/Flow/archify/convert.js +534 -0
- package/dist/components/pro/Flow/archify/convert.js.map +1 -0
- package/dist/components/pro/Flow/archify/index.d.ts +12 -0
- package/dist/components/pro/Flow/archify/palette.d.ts +64 -0
- package/dist/components/pro/Flow/archify/palette.js +112 -0
- package/dist/components/pro/Flow/archify/palette.js.map +1 -0
- package/dist/components/pro/Flow/archify/presets.d.ts +26 -0
- package/dist/components/pro/Flow/archify/presets.js +43 -0
- package/dist/components/pro/Flow/archify/presets.js.map +1 -0
- package/dist/components/pro/Flow/archify/spec.d.ts +283 -0
- package/dist/components/pro/Flow/archify/spec.js +10 -0
- package/dist/components/pro/Flow/archify/spec.js.map +1 -0
- package/dist/components/pro/Flow/constants.js +14 -0
- package/dist/components/pro/Flow/constants.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useClipboard.d.ts +5 -0
- package/dist/components/pro/Flow/hooks/useClipboard.js +129 -73
- package/dist/components/pro/Flow/hooks/useClipboard.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useFlowImportExport.d.ts +1 -0
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js +108 -93
- package/dist/components/pro/Flow/hooks/useFlowImportExport.js.map +1 -1
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.d.ts +1 -0
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js +7 -7
- package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js.map +1 -1
- package/dist/components/pro/Flow/index.d.ts +2 -0
- package/dist/components/pro/Flow/nodes/DataNodeView.d.ts +4 -1
- package/dist/components/pro/Flow/nodes/DataNodeView.js +127 -115
- package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js +72 -67
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/NodeRenderer.d.ts +5 -0
- package/dist/components/pro/Flow/nodes/NodeRenderer.js +216 -115
- package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
- package/dist/components/pro/Flow/panels/FlowToolbar.js +208 -169
- package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
- package/dist/components/pro/Flow/panels/InspectorPanel.js +602 -369
- package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
- package/dist/components/pro/Flow/panels/ShapePalette.js +50 -39
- package/dist/components/pro/Flow/panels/ShapePalette.js.map +1 -1
- package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +1 -0
- package/dist/components/pro/Flow/panels/toolbarIcons.js +36 -8
- package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
- package/dist/components/pro/Flow/types.d.ts +30 -0
- package/dist/components/pro/Flow/types.js.map +1 -1
- package/dist/dishui.css +1 -1
- package/dist/flow.js +73 -56
- package/package.json +18 -17
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DEFAULT_NODE_DATA as
|
|
3
|
-
import { FlowProvider as
|
|
4
|
-
import { FlowUIProvider as
|
|
5
|
-
import { FlowAIProvider as
|
|
1
|
+
import ue from "../CodeEditor/editors/CodeEditor.js";
|
|
2
|
+
import { DEFAULT_NODE_DATA as oe, ROOT_CANVAS_ID as fe, createEmptyDocument as he } from "./constants.js";
|
|
3
|
+
import { FlowProvider as pe, useFlowContext as Q } from "./context/FlowContext.js";
|
|
4
|
+
import { FlowUIProvider as me, useFlowUI as X } from "./context/FlowUIContext.js";
|
|
5
|
+
import { FlowAIProvider as ge } from "./context/FlowAIContext.js";
|
|
6
6
|
import { generateId as q } from "./nodes/nodeUtils.js";
|
|
7
|
-
import { normalizeEdgeHandles as
|
|
8
|
-
import
|
|
9
|
-
import { downloadDataURL as
|
|
10
|
-
import
|
|
11
|
-
import { MediaStampContent as
|
|
12
|
-
import { InspectorPanelContent as
|
|
13
|
-
import { OutlinePanelContent as
|
|
14
|
-
import { AIPanelContent as
|
|
15
|
-
import { PresentationMode as
|
|
16
|
-
import { MediaOverlay as
|
|
7
|
+
import { normalizeEdgeHandles as we } from "./edges/edgePaths.js";
|
|
8
|
+
import Ie from "./FlowCanvas.js";
|
|
9
|
+
import { downloadDataURL as ve, safeFileBaseName as ye } from "./hooks/useFlowImportExport.js";
|
|
10
|
+
import xe, { FlowZoomControls as be } from "./panels/FlowToolbar.js";
|
|
11
|
+
import { MediaStampContent as Se, ShapePaletteContent as Ce, SvgStampContent as Me } from "./panels/ShapePalette.js";
|
|
12
|
+
import { InspectorPanelContent as Pe } from "./panels/InspectorPanel.js";
|
|
13
|
+
import { OutlinePanelContent as ze } from "./panels/OutlinePanel.js";
|
|
14
|
+
import { AIPanelContent as Ee } from "./panels/AIPanel.js";
|
|
15
|
+
import { PresentationMode as De } from "./panels/PresentationMode.js";
|
|
16
|
+
import { MediaOverlay as Ae } from "./nodes/MediaOverlay.js";
|
|
17
17
|
import j from "./panels/FlowPanelGroup.js";
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import { MiniMapRenderer as
|
|
21
|
-
import { useUndoRedo as
|
|
22
|
-
import { useClipboard as
|
|
18
|
+
import Ne from "./panels/Breadcrumb.js";
|
|
19
|
+
import Te from "./panels/ContextMenu.js";
|
|
20
|
+
import { MiniMapRenderer as Re } from "./canvas/MiniMapRenderer.js";
|
|
21
|
+
import { useUndoRedo as Le } from "./hooks/useUndoRedo.js";
|
|
22
|
+
import { useClipboard as re } from "./hooks/useClipboard.js";
|
|
23
23
|
import { usePdfExport as ke } from "./hooks/usePdfExport.js";
|
|
24
24
|
import { useKeyboardShortcuts as Fe } from "./hooks/useKeyboardShortcuts.js";
|
|
25
25
|
import { useMindMap as Ge } from "./hooks/useMindMap.js";
|
|
26
26
|
/* empty css */
|
|
27
|
-
import { forwardRef as Oe, useCallback as
|
|
27
|
+
import { forwardRef as Oe, useCallback as A, useEffect as Y, useImperativeHandle as We, useMemo as ie, useRef as G, useState as $ } from "react";
|
|
28
28
|
import { jsx as h, jsxs as V } from "react/jsx-runtime";
|
|
29
29
|
import { EditorView as Ke } from "@codemirror/view";
|
|
30
30
|
function Ue(n) {
|
|
31
31
|
let p = !1;
|
|
32
32
|
const u = { ...n.canvases };
|
|
33
|
-
for (const [
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
...
|
|
33
|
+
for (const [I, s] of Object.entries(u)) {
|
|
34
|
+
const r = s.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,
|
|
39
39
|
data: {
|
|
40
|
-
...
|
|
41
|
-
labelPlacement:
|
|
40
|
+
...d.data,
|
|
41
|
+
labelPlacement: g
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
}), f = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const
|
|
46
|
-
const e =
|
|
47
|
-
(
|
|
48
|
-
...
|
|
49
|
-
nodes:
|
|
45
|
+
for (const d of r) f.set(d.id, d);
|
|
46
|
+
const e = we(s.edges, f);
|
|
47
|
+
(r !== s.nodes || e !== s.edges) && (u[I] = {
|
|
48
|
+
...s,
|
|
49
|
+
nodes: r,
|
|
50
50
|
edges: e
|
|
51
|
-
}, e !==
|
|
51
|
+
}, e !== s.edges && (p = !0));
|
|
52
52
|
}
|
|
53
53
|
return p ? {
|
|
54
54
|
...n,
|
|
55
55
|
canvases: u
|
|
56
56
|
} : n;
|
|
57
57
|
}
|
|
58
|
-
var
|
|
58
|
+
var ae = {
|
|
59
59
|
nodeIds: /* @__PURE__ */ new Set(),
|
|
60
60
|
edgeIds: /* @__PURE__ */ new Set(),
|
|
61
61
|
lineIds: /* @__PURE__ */ new Set()
|
|
62
62
|
};
|
|
63
|
-
function He({ onUndo: n, onRedo: p, groupRef: u, geoGroupRef:
|
|
64
|
-
const { selection:
|
|
65
|
-
const { nodeIds:
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return
|
|
69
|
-
...
|
|
63
|
+
function He({ onUndo: n, onRedo: p, groupRef: u, geoGroupRef: I, ungroupRef: s }) {
|
|
64
|
+
const { selection: r, setSelection: f, currentCanvas: e, setDoc: d, currentCanvasId: o } = Q(), { viewport: g } = X(), { copy: l, cut: P, paste: t, duplicate: w } = re(), S = A(() => {
|
|
65
|
+
const { nodeIds: c, edgeIds: m, lineIds: C } = r;
|
|
66
|
+
c.size === 0 && m.size === 0 && C.size === 0 || c.size > 1 && !window.confirm(`确定要删除选中的 ${c.size} 个节点吗?`) || (d((M) => {
|
|
67
|
+
const i = M.canvases[o];
|
|
68
|
+
return i ? {
|
|
69
|
+
...M,
|
|
70
70
|
canvases: {
|
|
71
|
-
...
|
|
72
|
-
[
|
|
73
|
-
...
|
|
74
|
-
nodes:
|
|
75
|
-
...
|
|
71
|
+
...M.canvases,
|
|
72
|
+
[o]: {
|
|
73
|
+
...i,
|
|
74
|
+
nodes: i.nodes.filter((a) => !c.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
|
|
75
|
+
...a,
|
|
76
76
|
parentId: void 0
|
|
77
|
-
} :
|
|
78
|
-
edges:
|
|
79
|
-
lines:
|
|
80
|
-
...
|
|
77
|
+
} : a),
|
|
78
|
+
edges: i.edges.filter((a) => !m.has(a.id) && !c.has(a.source) && !c.has(a.target)),
|
|
79
|
+
lines: i.lines.filter((a) => !C.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
|
|
80
|
+
...a,
|
|
81
81
|
parentId: void 0
|
|
82
|
-
} :
|
|
82
|
+
} : a)
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
} :
|
|
86
|
-
}), f(
|
|
85
|
+
} : M;
|
|
86
|
+
}), f(ae));
|
|
87
87
|
}, [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
r,
|
|
89
|
+
d,
|
|
90
|
+
o,
|
|
91
91
|
f
|
|
92
|
-
]), v =
|
|
92
|
+
]), v = A(() => {
|
|
93
93
|
f({
|
|
94
|
-
nodeIds: new Set(e.nodes.map((
|
|
95
|
-
edgeIds: new Set(e.edges.map((
|
|
96
|
-
lineIds: new Set(e.lines.map((
|
|
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))
|
|
97
97
|
});
|
|
98
|
-
}, [e, f]),
|
|
99
|
-
const m =
|
|
100
|
-
if (m.size +
|
|
101
|
-
const
|
|
102
|
-
let y = 1 / 0,
|
|
103
|
-
for (const
|
|
104
|
-
y = Math.min(y,
|
|
105
|
-
for (const
|
|
106
|
-
y = Math.min(y,
|
|
107
|
-
const
|
|
108
|
-
id:
|
|
109
|
-
type:
|
|
98
|
+
}, [e, f]), z = A((c) => {
|
|
99
|
+
const m = r.nodeIds, C = r.lineIds;
|
|
100
|
+
if (m.size + C.size < 2) return;
|
|
101
|
+
const M = e.nodes.filter((b) => m.has(b.id)), i = e.lines.filter((b) => C.has(b.id)), a = 20;
|
|
102
|
+
let y = 1 / 0, L = 1 / 0, R = -1 / 0, k = -1 / 0;
|
|
103
|
+
for (const b of M)
|
|
104
|
+
y = Math.min(y, b.position.x), L = Math.min(L, b.position.y), R = Math.max(R, b.position.x + b.width), k = Math.max(k, b.position.y + b.height);
|
|
105
|
+
for (const b of i) for (const N of b.points)
|
|
106
|
+
y = Math.min(y, N.x), L = Math.min(L, N.y), R = Math.max(R, N.x), k = Math.max(k, N.y);
|
|
107
|
+
const W = c === "geometryGroup", K = q("group"), x = {
|
|
108
|
+
id: K,
|
|
109
|
+
type: c,
|
|
110
110
|
position: {
|
|
111
|
-
x: y -
|
|
112
|
-
y:
|
|
111
|
+
x: y - a,
|
|
112
|
+
y: L - a
|
|
113
113
|
},
|
|
114
|
-
width:
|
|
115
|
-
height:
|
|
114
|
+
width: R - y + a * 2,
|
|
115
|
+
height: k - L + a * 2,
|
|
116
116
|
data: {
|
|
117
|
-
...
|
|
118
|
-
label:
|
|
119
|
-
fill:
|
|
117
|
+
...oe,
|
|
118
|
+
label: W ? "Geo Group" : "Group",
|
|
119
|
+
fill: W ? "#fefce8" : "#f0f9ff",
|
|
120
120
|
stroke: "#9ca3af",
|
|
121
121
|
strokeWidth: 1.5,
|
|
122
|
-
borderStyle:
|
|
122
|
+
borderStyle: W ? "dashed" : "dotted",
|
|
123
123
|
isGroup: !0
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
return
|
|
129
|
-
...
|
|
126
|
+
d((b) => {
|
|
127
|
+
const N = b.canvases[o];
|
|
128
|
+
return N ? {
|
|
129
|
+
...b,
|
|
130
130
|
canvases: {
|
|
131
|
-
...
|
|
132
|
-
[
|
|
133
|
-
...
|
|
134
|
-
nodes:
|
|
131
|
+
...b.canvases,
|
|
132
|
+
[o]: {
|
|
133
|
+
...N,
|
|
134
|
+
nodes: W ? [x, ...N.nodes] : [x, ...N.nodes.map((H) => m.has(H.id) ? {
|
|
135
135
|
...H,
|
|
136
|
-
parentId:
|
|
136
|
+
parentId: K
|
|
137
137
|
} : H)],
|
|
138
|
-
lines:
|
|
138
|
+
lines: W ? N.lines : N.lines.map((H) => C.has(H.id) ? {
|
|
139
139
|
...H,
|
|
140
|
-
parentId:
|
|
140
|
+
parentId: K
|
|
141
141
|
} : H)
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
} :
|
|
144
|
+
} : b;
|
|
145
145
|
}), f({
|
|
146
|
-
nodeIds: /* @__PURE__ */ new Set([
|
|
146
|
+
nodeIds: /* @__PURE__ */ new Set([K]),
|
|
147
147
|
edgeIds: /* @__PURE__ */ new Set(),
|
|
148
148
|
lineIds: /* @__PURE__ */ new Set()
|
|
149
149
|
});
|
|
150
150
|
}, [
|
|
151
|
-
|
|
151
|
+
r,
|
|
152
152
|
e,
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
d,
|
|
154
|
+
o,
|
|
155
155
|
f
|
|
156
|
-
]),
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const m = /* @__PURE__ */ new Set(),
|
|
160
|
-
for (const
|
|
156
|
+
]), Z = A(() => z("flowGroup"), [z]), O = A(() => z("geometryGroup"), [z]), B = A(() => {
|
|
157
|
+
const c = r.nodeIds;
|
|
158
|
+
if (c.size === 0) return;
|
|
159
|
+
const m = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Set();
|
|
160
|
+
for (const i of e.nodes) c.has(i.id) && (i.type === "flowGroup" || i.type === "geometryGroup" || i.data.isGroup) && m.add(i.id);
|
|
161
161
|
if (m.size !== 0) {
|
|
162
|
-
for (const
|
|
163
|
-
for (const
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
...
|
|
162
|
+
for (const i of e.nodes) i.parentId && m.has(i.parentId) && C.add(i.id);
|
|
163
|
+
for (const i of e.lines) i.parentId && m.has(i.parentId) && M.add(i.id);
|
|
164
|
+
d((i) => {
|
|
165
|
+
const a = i.canvases[o];
|
|
166
|
+
return a ? {
|
|
167
|
+
...i,
|
|
168
168
|
canvases: {
|
|
169
|
-
...
|
|
170
|
-
[
|
|
171
|
-
...
|
|
172
|
-
nodes:
|
|
169
|
+
...i.canvases,
|
|
170
|
+
[o]: {
|
|
171
|
+
...a,
|
|
172
|
+
nodes: a.nodes.filter((y) => !m.has(y.id)).map((y) => C.has(y.id) ? {
|
|
173
173
|
...y,
|
|
174
174
|
parentId: void 0
|
|
175
175
|
} : y),
|
|
176
|
-
lines:
|
|
176
|
+
lines: a.lines.map((y) => M.has(y.id) ? {
|
|
177
177
|
...y,
|
|
178
178
|
parentId: void 0
|
|
179
179
|
} : y)
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
} :
|
|
182
|
+
} : i;
|
|
183
183
|
}), f({
|
|
184
|
-
nodeIds:
|
|
184
|
+
nodeIds: C,
|
|
185
185
|
edgeIds: /* @__PURE__ */ new Set(),
|
|
186
|
-
lineIds:
|
|
186
|
+
lineIds: M
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
}, [
|
|
190
|
-
|
|
190
|
+
r,
|
|
191
191
|
e,
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
d,
|
|
193
|
+
o,
|
|
194
194
|
f
|
|
195
195
|
]);
|
|
196
|
-
u.current =
|
|
197
|
-
const
|
|
198
|
-
const m =
|
|
199
|
-
m.size === 0 &&
|
|
200
|
-
const
|
|
201
|
-
if (!
|
|
202
|
-
const
|
|
196
|
+
u.current = Z, I.current = O, s.current = B;
|
|
197
|
+
const E = A((c) => {
|
|
198
|
+
const m = r.nodeIds, C = r.lineIds;
|
|
199
|
+
m.size === 0 && C.size === 0 || d((M) => {
|
|
200
|
+
const i = M.canvases[o];
|
|
201
|
+
if (!i) return M;
|
|
202
|
+
const a = i.nodes.map((x) => x.zIndex ?? 0), y = a.length > 0 ? Math.max(...a) : 0, L = a.length > 0 ? Math.min(...a) : 0, R = i.lines.map((x) => x.zIndex ?? 0), k = R.length > 0 ? Math.max(...R) : 0, W = R.length > 0 ? Math.min(...R) : 0, K = (x, b, N) => c === "front" ? b + 1 : c === "back" ? N - 1 : c === "up" ? x + 1 : x - 1;
|
|
203
203
|
return {
|
|
204
|
-
...
|
|
204
|
+
...M,
|
|
205
205
|
canvases: {
|
|
206
|
-
...
|
|
207
|
-
[
|
|
208
|
-
...
|
|
209
|
-
nodes:
|
|
210
|
-
...
|
|
211
|
-
zIndex:
|
|
212
|
-
} :
|
|
213
|
-
lines:
|
|
214
|
-
...
|
|
215
|
-
zIndex:
|
|
216
|
-
} :
|
|
206
|
+
...M.canvases,
|
|
207
|
+
[o]: {
|
|
208
|
+
...i,
|
|
209
|
+
nodes: i.nodes.map((x) => m.has(x.id) ? {
|
|
210
|
+
...x,
|
|
211
|
+
zIndex: K(x.zIndex ?? 0, y, L)
|
|
212
|
+
} : x),
|
|
213
|
+
lines: i.lines.map((x) => C.has(x.id) ? {
|
|
214
|
+
...x,
|
|
215
|
+
zIndex: K(x.zIndex ?? 0, k, W)
|
|
216
|
+
} : x)
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
};
|
|
220
220
|
});
|
|
221
221
|
}, [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
r,
|
|
223
|
+
d,
|
|
224
|
+
o
|
|
225
225
|
]);
|
|
226
226
|
return Y(() => {
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
227
|
+
const c = (m) => {
|
|
228
|
+
const C = m.target;
|
|
229
|
+
if (C?.tagName === "INPUT" || C?.tagName === "TEXTAREA" || C?.isContentEditable) return;
|
|
230
|
+
const M = Array.from(m.clipboardData?.items ?? []).find((y) => y.type.startsWith("image/"));
|
|
231
|
+
if (!M) {
|
|
232
232
|
m.preventDefault(), t();
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
|
-
const
|
|
236
|
-
if (!
|
|
235
|
+
const i = M.getAsFile();
|
|
236
|
+
if (!i) return;
|
|
237
237
|
m.preventDefault();
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
if (typeof
|
|
241
|
-
const y =
|
|
238
|
+
const a = new FileReader();
|
|
239
|
+
a.onload = () => {
|
|
240
|
+
if (typeof a.result != "string") return;
|
|
241
|
+
const y = r.nodeIds.size === 1 ? e.nodes.find((T) => r.nodeIds.has(T.id) && T.type === "mediaNode" && T.data.mediaKind === "image") : void 0;
|
|
242
242
|
if (y) {
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
return
|
|
246
|
-
...
|
|
243
|
+
d((T) => {
|
|
244
|
+
const J = T.canvases[o];
|
|
245
|
+
return J ? {
|
|
246
|
+
...T,
|
|
247
247
|
canvases: {
|
|
248
|
-
...
|
|
249
|
-
[
|
|
250
|
-
...
|
|
251
|
-
nodes:
|
|
252
|
-
...
|
|
248
|
+
...T.canvases,
|
|
249
|
+
[o]: {
|
|
250
|
+
...J,
|
|
251
|
+
nodes: J.nodes.map((D) => D.id === y.id ? {
|
|
252
|
+
...D,
|
|
253
253
|
data: {
|
|
254
|
-
...
|
|
255
|
-
mediaContent:
|
|
254
|
+
...D.data,
|
|
255
|
+
mediaContent: a.result
|
|
256
256
|
}
|
|
257
|
-
} :
|
|
257
|
+
} : D)
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
} :
|
|
260
|
+
} : T;
|
|
261
261
|
});
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
-
const
|
|
265
|
-
id:
|
|
264
|
+
const L = q("node"), R = 320, k = 220, W = window.innerWidth, K = window.innerHeight, x = (W / 2 - g.x) / g.zoom, b = (K / 2 - g.y) / g.zoom, N = Math.max(0, ...e.nodes.map((T) => T.zIndex ?? 0)), H = {
|
|
265
|
+
id: L,
|
|
266
266
|
type: "mediaNode",
|
|
267
267
|
position: {
|
|
268
|
-
x:
|
|
269
|
-
y:
|
|
268
|
+
x: x - R / 2,
|
|
269
|
+
y: b - k / 2
|
|
270
270
|
},
|
|
271
|
-
width:
|
|
272
|
-
height:
|
|
273
|
-
zIndex:
|
|
271
|
+
width: R,
|
|
272
|
+
height: k,
|
|
273
|
+
zIndex: N + 1,
|
|
274
274
|
data: {
|
|
275
|
-
...
|
|
276
|
-
label:
|
|
275
|
+
...oe,
|
|
276
|
+
label: i.name || "Image",
|
|
277
277
|
fill: "theme:base-100",
|
|
278
278
|
stroke: "theme:base-content",
|
|
279
279
|
strokeWidth: 1.5,
|
|
@@ -281,173 +281,175 @@ function He({ onUndo: n, onRedo: p, groupRef: u, geoGroupRef: w, ungroupRef: i }
|
|
|
281
281
|
fontSize: 13,
|
|
282
282
|
borderStyle: "solid",
|
|
283
283
|
mediaKind: "image",
|
|
284
|
-
mediaContent:
|
|
284
|
+
mediaContent: a.result
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
return
|
|
290
|
-
...
|
|
287
|
+
d((T) => {
|
|
288
|
+
const J = T.canvases[o];
|
|
289
|
+
return J ? {
|
|
290
|
+
...T,
|
|
291
291
|
canvases: {
|
|
292
|
-
...
|
|
293
|
-
[
|
|
294
|
-
...
|
|
295
|
-
nodes: [...
|
|
292
|
+
...T.canvases,
|
|
293
|
+
[o]: {
|
|
294
|
+
...J,
|
|
295
|
+
nodes: [...J.nodes, H]
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
} :
|
|
298
|
+
} : T;
|
|
299
299
|
}), f({
|
|
300
|
-
nodeIds: /* @__PURE__ */ new Set([
|
|
300
|
+
nodeIds: /* @__PURE__ */ new Set([L]),
|
|
301
301
|
edgeIds: /* @__PURE__ */ new Set(),
|
|
302
302
|
lineIds: /* @__PURE__ */ new Set()
|
|
303
303
|
});
|
|
304
|
-
},
|
|
304
|
+
}, a.readAsDataURL(i);
|
|
305
305
|
};
|
|
306
|
-
return window.addEventListener("paste",
|
|
306
|
+
return window.addEventListener("paste", c), () => window.removeEventListener("paste", c);
|
|
307
307
|
}, [
|
|
308
308
|
e,
|
|
309
|
-
|
|
309
|
+
o,
|
|
310
310
|
t,
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
r,
|
|
312
|
+
d,
|
|
313
313
|
f,
|
|
314
|
-
|
|
315
|
-
]), Fe(
|
|
314
|
+
g
|
|
315
|
+
]), Fe(ie(() => ({
|
|
316
316
|
undo: n,
|
|
317
317
|
redo: p,
|
|
318
318
|
copy: l,
|
|
319
319
|
cut: P,
|
|
320
320
|
paste: t,
|
|
321
|
+
duplicate: w,
|
|
321
322
|
deleteSelected: S,
|
|
322
323
|
selectAll: v,
|
|
323
|
-
group:
|
|
324
|
-
geoGroup:
|
|
325
|
-
ungroup:
|
|
326
|
-
bringToFront: () =>
|
|
327
|
-
bringForward: () =>
|
|
328
|
-
sendBackward: () =>
|
|
329
|
-
sendToBack: () =>
|
|
324
|
+
group: Z,
|
|
325
|
+
geoGroup: O,
|
|
326
|
+
ungroup: B,
|
|
327
|
+
bringToFront: () => E("front"),
|
|
328
|
+
bringForward: () => E("up"),
|
|
329
|
+
sendBackward: () => E("down"),
|
|
330
|
+
sendToBack: () => E("back")
|
|
330
331
|
}), [
|
|
331
332
|
n,
|
|
332
333
|
p,
|
|
333
334
|
l,
|
|
334
335
|
P,
|
|
335
336
|
t,
|
|
337
|
+
w,
|
|
336
338
|
S,
|
|
337
339
|
v,
|
|
338
|
-
z,
|
|
339
340
|
Z,
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
O,
|
|
342
|
+
B,
|
|
343
|
+
E
|
|
342
344
|
])), Ge(), null;
|
|
343
345
|
}
|
|
344
346
|
function Ze({ pixiRef: n, exportPdfRef: p }) {
|
|
345
347
|
return p.current = ke(n), null;
|
|
346
348
|
}
|
|
347
|
-
var An = Oe(function({ initialDocument: p, onChange: u, width:
|
|
348
|
-
const [z, Z] = $(() => Ue(p ??
|
|
349
|
-
|
|
350
|
-
const x =
|
|
351
|
-
x.current = z, We(
|
|
352
|
-
exportPNG: async (
|
|
353
|
-
const
|
|
354
|
-
return !
|
|
349
|
+
var An = Oe(function({ initialDocument: p, onChange: u, width: I, height: s, readOnly: r = !1, onBack: f, onExportPNG: e, onPublish: d, showMiniMap: o = !0, showGrid: g = !0, gridSize: l = 20, className: P, showAI: t = !0, showAIConfig: w = !0, aiConfig: S }, v) {
|
|
350
|
+
const [z, Z] = $(() => Ue(p ?? he())), [O, B] = $(ae), E = G(null), c = G(null), m = G(null), { wrappedSetDoc: C, undo: M, redo: i, canUndo: a, canRedo: y } = Le(z, Z), L = G(null), R = G(null), k = G(null), W = G(null), K = G(u);
|
|
351
|
+
K.current = u;
|
|
352
|
+
const x = G(z);
|
|
353
|
+
x.current = z, We(v, () => ({
|
|
354
|
+
exportPNG: async (D) => {
|
|
355
|
+
const F = E.current;
|
|
356
|
+
return !F || F.destroyed ? null : F.exportPNG(D);
|
|
355
357
|
},
|
|
356
358
|
getDocument: () => x.current
|
|
357
359
|
}), []);
|
|
358
|
-
const
|
|
359
|
-
C((
|
|
360
|
-
const _ = typeof
|
|
361
|
-
return queueMicrotask(() =>
|
|
360
|
+
const b = A((D) => {
|
|
361
|
+
C((F) => {
|
|
362
|
+
const _ = typeof D == "function" ? D(F) : D;
|
|
363
|
+
return queueMicrotask(() => K.current?.(_)), _;
|
|
362
364
|
});
|
|
363
|
-
}, [C]),
|
|
364
|
-
|
|
365
|
-
}, []),
|
|
365
|
+
}, [C]), N = A((D) => {
|
|
366
|
+
E.current = D, c.current && !m.current && (m.current = new Re(c.current));
|
|
367
|
+
}, []), H = A(async () => {
|
|
366
368
|
if (e) return void e();
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
}, [e]),
|
|
369
|
+
const D = E.current;
|
|
370
|
+
if (!D || D.destroyed) return;
|
|
371
|
+
const F = await D.exportPNG(16777215);
|
|
372
|
+
F && ve(F, `${ye(x.current.title)}.png`);
|
|
373
|
+
}, [e]), T = A(async () => {
|
|
372
374
|
await W.current?.();
|
|
373
375
|
}, []);
|
|
374
376
|
Y(() => {
|
|
375
|
-
let
|
|
377
|
+
let D = !1, F = null;
|
|
376
378
|
const _ = () => {
|
|
377
|
-
const
|
|
378
|
-
if (!
|
|
379
|
-
const
|
|
380
|
-
x:
|
|
381
|
-
y:
|
|
382
|
-
zoom:
|
|
383
|
-
},
|
|
384
|
-
te && ne.update(te.nodes,
|
|
379
|
+
const U = E.current, ne = m.current;
|
|
380
|
+
if (!U || U.destroyed || !ne) return;
|
|
381
|
+
const de = {
|
|
382
|
+
x: U.world.position.x,
|
|
383
|
+
y: U.world.position.y,
|
|
384
|
+
zoom: U.world.scale.x
|
|
385
|
+
}, le = z.stack[z.stack.length - 1] ?? "root", te = z.canvases[le];
|
|
386
|
+
te && ne.update(te.nodes, de, U.app.screen.width, U.app.screen.height);
|
|
385
387
|
}, ee = () => {
|
|
386
|
-
if (
|
|
387
|
-
const
|
|
388
|
-
|
|
388
|
+
if (D) return;
|
|
389
|
+
const U = E.current;
|
|
390
|
+
U && !U.destroyed && m.current ? (U.app.ticker.add(_), F = U) : requestAnimationFrame(ee);
|
|
389
391
|
};
|
|
390
392
|
return ee(), () => {
|
|
391
|
-
|
|
393
|
+
D = !0, F && !F.destroyed && F.app.ticker.remove(_);
|
|
392
394
|
};
|
|
393
395
|
}, [z]);
|
|
394
396
|
const J = {
|
|
395
|
-
width:
|
|
396
|
-
height:
|
|
397
|
+
width: I ?? "100%",
|
|
398
|
+
height: s ?? "100%"
|
|
397
399
|
};
|
|
398
400
|
return /* @__PURE__ */ h("div", {
|
|
399
401
|
className: `flow-container ${P ?? ""}`,
|
|
400
402
|
style: J,
|
|
401
|
-
children: /* @__PURE__ */ h(
|
|
403
|
+
children: /* @__PURE__ */ h(pe, {
|
|
402
404
|
doc: z,
|
|
403
|
-
setDoc:
|
|
404
|
-
selection:
|
|
405
|
-
setSelection:
|
|
406
|
-
children: /* @__PURE__ */ h(
|
|
407
|
-
showMiniMap:
|
|
408
|
-
showGrid:
|
|
405
|
+
setDoc: b,
|
|
406
|
+
selection: O,
|
|
407
|
+
setSelection: B,
|
|
408
|
+
children: /* @__PURE__ */ h(me, {
|
|
409
|
+
showMiniMap: o,
|
|
410
|
+
showGrid: g,
|
|
409
411
|
gridSize: l,
|
|
410
412
|
showAI: t,
|
|
411
|
-
children: /* @__PURE__ */ V(
|
|
412
|
-
initialConfig:
|
|
413
|
-
showAIConfig:
|
|
413
|
+
children: /* @__PURE__ */ V(ge, {
|
|
414
|
+
initialConfig: S,
|
|
415
|
+
showAIConfig: w,
|
|
414
416
|
children: [
|
|
415
417
|
/* @__PURE__ */ h(He, {
|
|
416
|
-
onUndo:
|
|
417
|
-
onRedo:
|
|
418
|
-
groupRef:
|
|
419
|
-
geoGroupRef:
|
|
420
|
-
ungroupRef:
|
|
418
|
+
onUndo: M,
|
|
419
|
+
onRedo: i,
|
|
420
|
+
groupRef: L,
|
|
421
|
+
geoGroupRef: R,
|
|
422
|
+
ungroupRef: k
|
|
421
423
|
}),
|
|
422
424
|
/* @__PURE__ */ h(Ze, {
|
|
423
|
-
pixiRef:
|
|
425
|
+
pixiRef: E,
|
|
424
426
|
exportPdfRef: W
|
|
425
427
|
}),
|
|
426
428
|
/* @__PURE__ */ V(_e, {
|
|
427
|
-
toolbar:
|
|
429
|
+
toolbar: r ? null : /* @__PURE__ */ h(xe, {
|
|
428
430
|
onBack: f,
|
|
429
|
-
onUndo:
|
|
430
|
-
onRedo:
|
|
431
|
-
canUndo:
|
|
432
|
-
canRedo:
|
|
433
|
-
onGroup: () =>
|
|
434
|
-
onGeoGroup: () =>
|
|
435
|
-
onUngroup: () =>
|
|
436
|
-
onExportPNG:
|
|
437
|
-
onExportPDF:
|
|
438
|
-
onPublish:
|
|
431
|
+
onUndo: M,
|
|
432
|
+
onRedo: i,
|
|
433
|
+
canUndo: a,
|
|
434
|
+
canRedo: y,
|
|
435
|
+
onGroup: () => L.current?.(),
|
|
436
|
+
onGeoGroup: () => R.current?.(),
|
|
437
|
+
onUngroup: () => k.current?.(),
|
|
438
|
+
onExportPNG: H,
|
|
439
|
+
onExportPDF: T,
|
|
440
|
+
onPublish: d
|
|
439
441
|
}),
|
|
440
442
|
children: [
|
|
441
|
-
/* @__PURE__ */ h(
|
|
442
|
-
/* @__PURE__ */ h(
|
|
443
|
-
/* @__PURE__ */ V(Be, { children: [!
|
|
443
|
+
/* @__PURE__ */ h(Ie, { onPixiReady: N }),
|
|
444
|
+
/* @__PURE__ */ h(Ae, {}),
|
|
445
|
+
/* @__PURE__ */ V(Be, { children: [!r && /* @__PURE__ */ h(be, {}), /* @__PURE__ */ h(Ne, {})] }),
|
|
444
446
|
/* @__PURE__ */ h(qe, {}),
|
|
445
447
|
/* @__PURE__ */ h(Xe, {
|
|
446
|
-
canvasRef:
|
|
447
|
-
pixiRef:
|
|
448
|
-
miniMapRef:
|
|
448
|
+
canvasRef: c,
|
|
449
|
+
pixiRef: E,
|
|
450
|
+
miniMapRef: m
|
|
449
451
|
}),
|
|
450
|
-
/* @__PURE__ */ h(
|
|
452
|
+
/* @__PURE__ */ h(De, {})
|
|
451
453
|
]
|
|
452
454
|
})
|
|
453
455
|
]
|
|
@@ -518,38 +520,38 @@ var Je = [
|
|
|
518
520
|
function Ve(n) {
|
|
519
521
|
switch (n) {
|
|
520
522
|
case "shapes":
|
|
521
|
-
return /* @__PURE__ */ h(Se, {});
|
|
522
|
-
case "icons":
|
|
523
523
|
return /* @__PURE__ */ h(Ce, {});
|
|
524
|
+
case "icons":
|
|
525
|
+
return /* @__PURE__ */ h(Me, {});
|
|
524
526
|
case "media":
|
|
525
|
-
return /* @__PURE__ */ h(
|
|
527
|
+
return /* @__PURE__ */ h(Se, {});
|
|
526
528
|
case "inspector":
|
|
527
|
-
return /* @__PURE__ */ h(Me, {});
|
|
528
|
-
case "outline":
|
|
529
529
|
return /* @__PURE__ */ h(Pe, {});
|
|
530
|
+
case "outline":
|
|
531
|
+
return /* @__PURE__ */ h(ze, {});
|
|
530
532
|
case "json":
|
|
531
533
|
return /* @__PURE__ */ h(je, {});
|
|
532
534
|
case "ai":
|
|
533
|
-
return /* @__PURE__ */ h(
|
|
535
|
+
return /* @__PURE__ */ h(Ee, {});
|
|
534
536
|
default:
|
|
535
537
|
return null;
|
|
536
538
|
}
|
|
537
539
|
}
|
|
538
540
|
function _e({ children: n, toolbar: p }) {
|
|
539
|
-
const u = X(), { detachedTabs:
|
|
541
|
+
const u = X(), { detachedTabs: I, toggleDetach: s, presentation: r } = u, f = Je.filter((t) => !t.showKey || u[t.showKey]), e = (t) => ({
|
|
540
542
|
id: t.id,
|
|
541
543
|
label: t.label,
|
|
542
544
|
icon: t.icon,
|
|
543
545
|
content: Ve(t.id)
|
|
544
|
-
}),
|
|
546
|
+
}), d = f.filter((t) => t.side === "left" && !I.has(t.id)).map(e), o = f.filter((t) => t.side === "right" && !I.has(t.id)).map(e), g = f.filter((t) => I.has(t.id)), l = A((t) => s(t), [s]), P = A((t) => s(t), [s]);
|
|
545
547
|
return /* @__PURE__ */ V("div", {
|
|
546
548
|
className: "flow-workspace",
|
|
547
|
-
children: [!
|
|
549
|
+
children: [!r && p, /* @__PURE__ */ V("div", {
|
|
548
550
|
className: "flow-workspace-main",
|
|
549
551
|
children: [
|
|
550
|
-
!
|
|
551
|
-
tabs:
|
|
552
|
-
defaultTab:
|
|
552
|
+
!r && d.length > 0 && /* @__PURE__ */ h(j, {
|
|
553
|
+
tabs: d,
|
|
554
|
+
defaultTab: d[0]?.id,
|
|
553
555
|
resizeEdge: "right",
|
|
554
556
|
defaultWidth: 132,
|
|
555
557
|
onDetach: l
|
|
@@ -558,20 +560,20 @@ function _e({ children: n, toolbar: p }) {
|
|
|
558
560
|
className: "flow-stage",
|
|
559
561
|
children: n
|
|
560
562
|
}),
|
|
561
|
-
!
|
|
562
|
-
tabs:
|
|
563
|
-
defaultTab:
|
|
563
|
+
!r && o.length > 0 && /* @__PURE__ */ h(j, {
|
|
564
|
+
tabs: o,
|
|
565
|
+
defaultTab: o[0]?.id,
|
|
564
566
|
resizeEdge: "left",
|
|
565
567
|
defaultWidth: 220,
|
|
566
568
|
onDetach: l
|
|
567
569
|
}),
|
|
568
|
-
!
|
|
570
|
+
!r && g.map((t, w) => /* @__PURE__ */ h(j, {
|
|
569
571
|
tabs: [e(t)],
|
|
570
572
|
resizeEdge: "right",
|
|
571
573
|
defaultWidth: 220,
|
|
572
574
|
style: {
|
|
573
|
-
top: 48 +
|
|
574
|
-
left: 24 +
|
|
575
|
+
top: 48 + w * 40,
|
|
576
|
+
left: 24 + w * 30
|
|
575
577
|
},
|
|
576
578
|
isDetached: !0,
|
|
577
579
|
onAttach: P
|
|
@@ -581,29 +583,29 @@ function _e({ children: n, toolbar: p }) {
|
|
|
581
583
|
});
|
|
582
584
|
}
|
|
583
585
|
function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
|
|
584
|
-
const { showMiniMap:
|
|
585
|
-
const t = n.current,
|
|
586
|
-
if (!t || !
|
|
587
|
-
const
|
|
588
|
-
if (
|
|
589
|
-
const { width: z, height: Z } =
|
|
590
|
-
if (!
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
x:
|
|
594
|
-
y: C / 2 -
|
|
595
|
-
zoom:
|
|
586
|
+
const { showMiniMap: I, setViewport: s, presentation: r } = X(), f = G(!1), e = A((l, P) => {
|
|
587
|
+
const t = n.current, w = p.current, S = u.current;
|
|
588
|
+
if (!t || !w || w.destroyed || !S) return;
|
|
589
|
+
const v = t.getBoundingClientRect();
|
|
590
|
+
if (v.width === 0 || v.height === 0) return;
|
|
591
|
+
const { width: z, height: Z } = S.size, O = (l - v.left) / v.width * z, B = (P - v.top) / v.height * Z, E = S.minimapToWorld(O, B);
|
|
592
|
+
if (!E) return;
|
|
593
|
+
const c = w.world.scale.x || 1, m = w.app.screen.width, C = w.app.screen.height;
|
|
594
|
+
s({
|
|
595
|
+
x: m / 2 - E.x * c,
|
|
596
|
+
y: C / 2 - E.y * c,
|
|
597
|
+
zoom: c
|
|
596
598
|
});
|
|
597
599
|
}, [
|
|
598
600
|
n,
|
|
599
601
|
p,
|
|
600
602
|
u,
|
|
601
|
-
|
|
602
|
-
]),
|
|
603
|
+
s
|
|
604
|
+
]), d = A((l) => {
|
|
603
605
|
l.preventDefault(), l.currentTarget.setPointerCapture(l.pointerId), f.current = !0, e(l.clientX, l.clientY);
|
|
604
|
-
}, [e]),
|
|
606
|
+
}, [e]), o = A((l) => {
|
|
605
607
|
f.current && e(l.clientX, l.clientY);
|
|
606
|
-
}, [e]),
|
|
608
|
+
}, [e]), g = A((l) => {
|
|
607
609
|
f.current = !1;
|
|
608
610
|
try {
|
|
609
611
|
l.currentTarget.releasePointerCapture(l.pointerId);
|
|
@@ -613,12 +615,12 @@ function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
|
|
|
613
615
|
return /* @__PURE__ */ h("div", {
|
|
614
616
|
className: "flow-minimap",
|
|
615
617
|
style: {
|
|
616
|
-
display:
|
|
618
|
+
display: I && !r ? void 0 : "none",
|
|
617
619
|
cursor: "pointer"
|
|
618
620
|
},
|
|
619
|
-
onPointerDown:
|
|
620
|
-
onPointerMove:
|
|
621
|
-
onPointerUp:
|
|
621
|
+
onPointerDown: d,
|
|
622
|
+
onPointerMove: o,
|
|
623
|
+
onPointerUp: g,
|
|
622
624
|
title: "点击或拖动以移动画布",
|
|
623
625
|
children: /* @__PURE__ */ h("canvas", {
|
|
624
626
|
ref: n,
|
|
@@ -633,93 +635,93 @@ function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
|
|
|
633
635
|
});
|
|
634
636
|
}
|
|
635
637
|
function Ye(n, p) {
|
|
636
|
-
const u = `"id": "${p}"`,
|
|
637
|
-
if (
|
|
638
|
-
let
|
|
639
|
-
for (let e =
|
|
640
|
-
if (n[e] === "}" &&
|
|
641
|
-
if (
|
|
642
|
-
|
|
638
|
+
const u = `"id": "${p}"`, I = n.indexOf(u);
|
|
639
|
+
if (I === -1) return null;
|
|
640
|
+
let s = 0, r = -1;
|
|
641
|
+
for (let e = I; e >= 0; e--)
|
|
642
|
+
if (n[e] === "}" && s++, n[e] === "{") {
|
|
643
|
+
if (s === 0) {
|
|
644
|
+
r = e;
|
|
643
645
|
break;
|
|
644
646
|
}
|
|
645
|
-
|
|
647
|
+
s--;
|
|
646
648
|
}
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
+
if (r === -1) return null;
|
|
650
|
+
s = 0;
|
|
649
651
|
let f = -1;
|
|
650
|
-
for (let e =
|
|
651
|
-
if (n[e] === "{" &&
|
|
652
|
+
for (let e = r; e < n.length; e++)
|
|
653
|
+
if (n[e] === "{" && s++, n[e] === "}" && (s--, s === 0)) {
|
|
652
654
|
f = e;
|
|
653
655
|
break;
|
|
654
656
|
}
|
|
655
657
|
return f === -1 ? null : {
|
|
656
|
-
startLine: n.slice(0,
|
|
658
|
+
startLine: n.slice(0, r).split(`
|
|
657
659
|
`).length,
|
|
658
660
|
endLine: n.slice(0, f + 1).split(`
|
|
659
661
|
`).length
|
|
660
662
|
};
|
|
661
663
|
}
|
|
662
|
-
function
|
|
664
|
+
function se(n) {
|
|
663
665
|
n.querySelectorAll(".cm-line.flow-json-hl").forEach((p) => p.classList.remove("flow-json-hl"));
|
|
664
666
|
}
|
|
665
667
|
function $e(n, p, u) {
|
|
666
|
-
const
|
|
667
|
-
if (
|
|
668
|
-
for (let
|
|
669
|
-
const
|
|
668
|
+
const I = n.getView();
|
|
669
|
+
if (I)
|
|
670
|
+
for (let s = p; s <= u; s++) try {
|
|
671
|
+
const r = I.state.doc.line(s), f = I.domAtPos(r.from), e = f.node instanceof HTMLElement ? f.node.closest(".cm-line") : f.node.parentElement?.closest(".cm-line");
|
|
670
672
|
e && e.classList.add("flow-json-hl");
|
|
671
673
|
} catch {
|
|
672
674
|
}
|
|
673
675
|
}
|
|
674
676
|
function je() {
|
|
675
|
-
const { setDoc: n, currentCanvasId: p, selection: u, currentCanvas:
|
|
677
|
+
const { setDoc: n, currentCanvasId: p, selection: u, currentCanvas: I } = Q(), [s, r] = $(""), [f, e] = $(null), d = G(!1), o = G(null), g = G(null), l = ie(() => u.nodeIds.size + u.edgeIds.size + u.lineIds.size !== 1 ? null : u.nodeIds.size === 1 ? [...u.nodeIds][0] : u.edgeIds.size === 1 ? [...u.edgeIds][0] : u.lineIds.size === 1 ? [...u.lineIds][0] : null, [u]);
|
|
676
678
|
Y(() => {
|
|
677
|
-
if (
|
|
678
|
-
|
|
679
|
+
if (d.current) {
|
|
680
|
+
d.current = !1;
|
|
679
681
|
return;
|
|
680
682
|
}
|
|
681
|
-
|
|
682
|
-
}, [
|
|
683
|
-
const
|
|
684
|
-
if (
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
if (!
|
|
688
|
-
const z =
|
|
683
|
+
r(JSON.stringify(I, null, 2)), e(null);
|
|
684
|
+
}, [I]), Y(() => {
|
|
685
|
+
const w = g.current;
|
|
686
|
+
if (w && se(w), !l) return;
|
|
687
|
+
const S = setTimeout(() => {
|
|
688
|
+
const v = Ye(s, l);
|
|
689
|
+
if (!v || !g.current) return;
|
|
690
|
+
const z = o.current?.getView();
|
|
689
691
|
if (!z) return;
|
|
690
|
-
const Z =
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
z.dispatch({ effects: Ke.scrollIntoView(
|
|
692
|
+
const Z = g.current, O = z.scrollDOM;
|
|
693
|
+
O.style.scrollBehavior = "smooth";
|
|
694
|
+
const B = z.state.doc.line(v.startLine);
|
|
695
|
+
z.dispatch({ effects: Ke.scrollIntoView(B.from, {
|
|
694
696
|
y: "start",
|
|
695
697
|
yMargin: 0
|
|
696
698
|
}) });
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
+
const E = () => {
|
|
700
|
+
O.style.scrollBehavior = "", se(Z), $e(o.current, v.startLine, v.endLine);
|
|
699
701
|
};
|
|
700
|
-
let
|
|
701
|
-
const
|
|
702
|
-
clearTimeout(
|
|
702
|
+
let c;
|
|
703
|
+
const m = () => {
|
|
704
|
+
clearTimeout(c), c = setTimeout(E, 100);
|
|
703
705
|
};
|
|
704
|
-
|
|
705
|
-
|
|
706
|
+
O.addEventListener("scroll", m), c = setTimeout(() => {
|
|
707
|
+
O.removeEventListener("scroll", m), E();
|
|
706
708
|
}, 800);
|
|
707
709
|
}, 120);
|
|
708
|
-
return () => clearTimeout(
|
|
709
|
-
}, [l,
|
|
710
|
-
const P =
|
|
711
|
-
|
|
710
|
+
return () => clearTimeout(S);
|
|
711
|
+
}, [l, s]);
|
|
712
|
+
const P = A((w) => {
|
|
713
|
+
r(w);
|
|
712
714
|
try {
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
...
|
|
715
|
+
const S = JSON.parse(w);
|
|
716
|
+
S && Array.isArray(S.nodes) && Array.isArray(S.edges) && Array.isArray(S.lines) ? (e(null), d.current = !0, n((v) => ({
|
|
717
|
+
...v,
|
|
716
718
|
canvases: {
|
|
717
|
-
...
|
|
718
|
-
[p]:
|
|
719
|
+
...v.canvases,
|
|
720
|
+
[p]: S
|
|
719
721
|
}
|
|
720
722
|
}))) : e("JSON must have nodes, edges, lines arrays");
|
|
721
|
-
} catch (
|
|
722
|
-
e(
|
|
723
|
+
} catch (S) {
|
|
724
|
+
e(S.message?.slice(0, 60) ?? "Invalid JSON");
|
|
723
725
|
}
|
|
724
726
|
}, [n, p]), t = l ? u.nodeIds.has(l) ? "Node" : u.edgeIds.has(l) ? "Edge" : "Line" : null;
|
|
725
727
|
return /* @__PURE__ */ V("div", {
|
|
@@ -747,14 +749,14 @@ function je() {
|
|
|
747
749
|
children: f
|
|
748
750
|
}),
|
|
749
751
|
/* @__PURE__ */ h("div", {
|
|
750
|
-
ref:
|
|
752
|
+
ref: g,
|
|
751
753
|
style: {
|
|
752
754
|
flex: 1,
|
|
753
755
|
minHeight: 0
|
|
754
756
|
},
|
|
755
|
-
children: /* @__PURE__ */ h(
|
|
756
|
-
ref:
|
|
757
|
-
value:
|
|
757
|
+
children: /* @__PURE__ */ h(ue, {
|
|
758
|
+
ref: o,
|
|
759
|
+
value: s,
|
|
758
760
|
onChange: P,
|
|
759
761
|
language: "json",
|
|
760
762
|
lineNumbers: !1,
|
|
@@ -766,40 +768,50 @@ function je() {
|
|
|
766
768
|
});
|
|
767
769
|
}
|
|
768
770
|
function qe() {
|
|
769
|
-
const { contextMenu: n, setContextMenu: p } = X(), { doc: u, setDoc:
|
|
771
|
+
const { contextMenu: n, setContextMenu: p } = X(), { doc: u, setDoc: I, currentCanvasId: s, pushCanvas: r, setSelection: f } = Q(), { duplicate: e } = re();
|
|
770
772
|
if (!n) return null;
|
|
771
|
-
const
|
|
772
|
-
if (!
|
|
773
|
+
const d = u.canvases[s];
|
|
774
|
+
if (!d)
|
|
773
775
|
return p(null), null;
|
|
774
|
-
const
|
|
775
|
-
return
|
|
776
|
+
const o = n.nodeId ? d.nodes.find((l) => l.id === n.nodeId) : null, g = [];
|
|
777
|
+
return o && (g.push({
|
|
778
|
+
label: "Duplicate",
|
|
779
|
+
icon: "⧉",
|
|
780
|
+
action: () => {
|
|
781
|
+
e(24, 24, { nodeIds: /* @__PURE__ */ new Set([o.id]) });
|
|
782
|
+
}
|
|
783
|
+
}), g.push({
|
|
784
|
+
label: "---",
|
|
785
|
+
action: () => {
|
|
786
|
+
}
|
|
787
|
+
}), o.data.childCanvasId ? (g.push({
|
|
776
788
|
label: "Enter Sub-canvas",
|
|
777
789
|
icon: "↓",
|
|
778
790
|
action: () => {
|
|
779
|
-
|
|
791
|
+
r(o.data.childCanvasId), f({
|
|
780
792
|
nodeIds: /* @__PURE__ */ new Set(),
|
|
781
793
|
edgeIds: /* @__PURE__ */ new Set(),
|
|
782
794
|
lineIds: /* @__PURE__ */ new Set()
|
|
783
795
|
});
|
|
784
796
|
}
|
|
785
|
-
}),
|
|
797
|
+
}), g.push({
|
|
786
798
|
label: "---",
|
|
787
799
|
action: () => {
|
|
788
800
|
}
|
|
789
|
-
}),
|
|
801
|
+
}), g.push({
|
|
790
802
|
label: "Delete Sub-canvas",
|
|
791
803
|
icon: "🗑",
|
|
792
804
|
danger: !0,
|
|
793
805
|
action: () => {
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
const
|
|
799
|
-
if (!
|
|
800
|
-
|
|
801
|
-
...
|
|
802
|
-
nodes:
|
|
806
|
+
const l = o.data.childCanvasId;
|
|
807
|
+
I((P) => {
|
|
808
|
+
const t = { ...P.canvases };
|
|
809
|
+
ce(t, l);
|
|
810
|
+
const w = t[s];
|
|
811
|
+
if (!w) return P;
|
|
812
|
+
t[s] = {
|
|
813
|
+
...w,
|
|
814
|
+
nodes: w.nodes.map((v) => v.id === o.id ? {
|
|
803
815
|
...v,
|
|
804
816
|
data: {
|
|
805
817
|
...v.data,
|
|
@@ -807,55 +819,55 @@ function qe() {
|
|
|
807
819
|
}
|
|
808
820
|
} : v)
|
|
809
821
|
};
|
|
810
|
-
const S =
|
|
811
|
-
return S.length === 0 && S.push(
|
|
812
|
-
...
|
|
813
|
-
canvases:
|
|
822
|
+
const S = P.stack.filter((v) => t[v]);
|
|
823
|
+
return S.length === 0 && S.push(fe), {
|
|
824
|
+
...P,
|
|
825
|
+
canvases: t,
|
|
814
826
|
stack: S
|
|
815
827
|
};
|
|
816
828
|
});
|
|
817
829
|
}
|
|
818
|
-
})) :
|
|
830
|
+
})) : g.push({
|
|
819
831
|
label: "Create Sub-canvas",
|
|
820
832
|
icon: "⊞",
|
|
821
833
|
action: () => {
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
return
|
|
826
|
-
...
|
|
834
|
+
const l = q("canvas");
|
|
835
|
+
I((P) => {
|
|
836
|
+
const t = P.canvases[s];
|
|
837
|
+
return t ? {
|
|
838
|
+
...P,
|
|
827
839
|
canvases: {
|
|
828
|
-
...
|
|
829
|
-
[
|
|
830
|
-
...
|
|
831
|
-
nodes:
|
|
832
|
-
...
|
|
840
|
+
...P.canvases,
|
|
841
|
+
[s]: {
|
|
842
|
+
...t,
|
|
843
|
+
nodes: t.nodes.map((w) => w.id === o.id ? {
|
|
844
|
+
...w,
|
|
833
845
|
data: {
|
|
834
|
-
...
|
|
835
|
-
childCanvasId:
|
|
846
|
+
...w.data,
|
|
847
|
+
childCanvasId: l
|
|
836
848
|
}
|
|
837
|
-
} :
|
|
849
|
+
} : w)
|
|
838
850
|
},
|
|
839
|
-
[
|
|
851
|
+
[l]: {
|
|
840
852
|
nodes: [],
|
|
841
853
|
edges: [],
|
|
842
854
|
lines: []
|
|
843
855
|
}
|
|
844
856
|
}
|
|
845
|
-
} :
|
|
846
|
-
}),
|
|
857
|
+
} : P;
|
|
858
|
+
}), r(l);
|
|
847
859
|
}
|
|
848
|
-
})),
|
|
860
|
+
})), g.length === 0 ? null : /* @__PURE__ */ h(Te, {
|
|
849
861
|
x: n.x,
|
|
850
862
|
y: n.y,
|
|
851
|
-
items:
|
|
863
|
+
items: g,
|
|
852
864
|
onClose: () => p(null)
|
|
853
865
|
});
|
|
854
866
|
}
|
|
855
|
-
function
|
|
867
|
+
function ce(n, p) {
|
|
856
868
|
const u = n[p];
|
|
857
869
|
if (u) {
|
|
858
|
-
for (const
|
|
870
|
+
for (const I of u.nodes) I.data.childCanvasId && ce(n, I.data.childCanvasId);
|
|
859
871
|
delete n[p];
|
|
860
872
|
}
|
|
861
873
|
}
|