@blueking/flow-canvas 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,24 +1,26 @@
1
- import { ref as O, computed as F, onScopeDispose as et, defineComponent as ge, onBeforeUnmount as ze, createElementBlock as S, openBlock as M, normalizeStyle as _e, createElementVNode as B, createVNode as tt, createCommentVNode as U, normalizeClass as ee, Transition as ot, withCtx as je, withModifiers as rt, createTextVNode as Ve, renderSlot as ke, onMounted as at, watch as fe, createBlock as De, Fragment as pe, renderList as Pe, toDisplayString as me, unref as lt, resolveDynamicComponent as dt, inject as ct } from "vue";
2
- import { Graph as ut } from "@antv/x6";
3
- import { register as ft } from "@antv/x6-vue-shape";
4
- function Mo() {
1
+ import { ref as q, computed as j, onScopeDispose as Je, defineComponent as fe, h as Re, watch as pe, onBeforeUnmount as Me, createElementBlock as R, openBlock as D, normalizeStyle as we, createElementVNode as U, createVNode as et, createCommentVNode as Y, normalizeClass as se, Transition as tt, withCtx as He, withModifiers as rt, createTextVNode as Le, renderSlot as Ee, onMounted as ot, createBlock as be, Fragment as me, renderList as Ie, toDisplayString as ge, unref as le, reactive as at, resolveDynamicComponent as lt, Teleport as dt, nextTick as Oe, inject as ct, createApp as ut } from "vue";
2
+ import { Graph as ft } from "@antv/x6";
3
+ import { register as gt } from "@antv/x6-vue-shape";
4
+ import { Selection as pt } from "@antv/x6-plugin-selection";
5
+ import { MiniMap as ht } from "@antv/x6-plugin-minimap";
6
+ function fn() {
5
7
  return {
6
8
  version: "1.0",
7
9
  nodes: {},
8
10
  edges: {}
9
11
  };
10
12
  }
11
- class ne extends Error {
13
+ class ue extends Error {
12
14
  constructor(e) {
13
15
  super(e), this.name = "CanvasConstraintError";
14
16
  }
15
17
  }
16
- class pt extends Error {
18
+ class vt extends Error {
17
19
  constructor(e) {
18
20
  super(e), this.name = "CanvasSchemaError";
19
21
  }
20
22
  }
21
- function Ae(s, e, t) {
23
+ function Ne(s, e, t) {
22
24
  if (e.length === 0) {
23
25
  if (t === void 0) return;
24
26
  if (typeof t != "object" || t === null || Array.isArray(t))
@@ -27,196 +29,196 @@ function Ae(s, e, t) {
27
29
  }
28
30
  const o = s ? { ...s } : {};
29
31
  let n = o;
30
- for (let i = 0; i < e.length - 1; i++) {
31
- const l = e[i], a = n[l];
32
+ for (let r = 0; r < e.length - 1; r++) {
33
+ const l = e[r], a = n[l];
32
34
  a && typeof a == "object" && !Array.isArray(a) ? n[l] = { ...a } : n[l] = {}, n = n[l];
33
35
  }
34
- const r = e[e.length - 1];
35
- return t === void 0 ? delete n[r] : n[r] = t, o;
36
+ const i = e[e.length - 1];
37
+ return t === void 0 ? delete n[i] : n[i] = t, o;
36
38
  }
37
- function Ge(s, e) {
39
+ function $e(s, e) {
38
40
  switch (e.type) {
39
41
  case "node.add":
40
- return gt(s, e.node);
42
+ return yt(s, e.node);
41
43
  case "node.move":
42
- return ht(s, e.nodeId, e.position);
44
+ return mt(s, e.nodeId, e.position);
43
45
  case "node.remove":
44
- return vt(s, e.nodeId);
46
+ return wt(s, e.nodeId);
45
47
  case "node.update":
46
- return yt(s, e.nodeId, e.patch);
48
+ return bt(s, e.nodeId, e.patch);
47
49
  case "node.set-payload":
48
- return mt(s, e.nodeId, e.path, e.value);
50
+ return xt(s, e.nodeId, e.path, e.value);
49
51
  case "node.set-extensions":
50
- return bt(s, e.nodeId, e.path, e.value);
52
+ return Et(s, e.nodeId, e.path, e.value);
51
53
  case "edge.add":
52
- return wt(s, e.edge);
54
+ return It(s, e.edge);
53
55
  case "edge.remove":
54
- return xt(s, e.edgeId);
56
+ return Ct(s, e.edgeId);
55
57
  case "edge.reconnect":
56
58
  return kt(s, e.edgeId, e.source, e.target);
57
59
  case "edge.update":
58
- return Ct(s, e.edgeId, e.patch);
60
+ return St(s, e.edgeId, e.patch);
59
61
  case "edge.set-payload":
60
- return Et(s, e.edgeId, e.path, e.value);
62
+ return Mt(s, e.edgeId, e.path, e.value);
61
63
  case "edge.label.update":
62
- return It(s, e.edgeId, e.labelId, e.patch);
64
+ return Nt(s, e.edgeId, e.labelId, e.patch);
63
65
  case "model.set-meta":
64
- return Mt(s, e.path, e.value);
66
+ return _t(s, e.path, e.value);
65
67
  default:
66
- throw new ne(`Unknown command type: ${e.type}`);
68
+ throw new ue(`Unknown command type: ${e.type}`);
67
69
  }
68
70
  }
69
71
  function Ce(s, e) {
70
72
  const t = s.nodes[e];
71
- if (!t) throw new ne(`Node "${e}" does not exist`);
73
+ if (!t) throw new ue(`Node "${e}" does not exist`);
72
74
  return t;
73
75
  }
74
- function Ee(s, e) {
76
+ function ke(s, e) {
75
77
  const t = s.edges[e];
76
- if (!t) throw new ne(`Edge "${e}" does not exist`);
78
+ if (!t) throw new ue(`Edge "${e}" does not exist`);
77
79
  return t;
78
80
  }
79
- function be(s, e, t) {
81
+ function xe(s, e, t) {
80
82
  const o = s.nodes[e.nodeId];
81
83
  if (!o)
82
- throw new ne(`${t} node "${e.nodeId}" does not exist`);
83
- if (e.portId && o.ports && !o.ports.some((r) => r.id === e.portId))
84
- throw new ne(`${t} port "${e.portId}" not found on node "${e.nodeId}"`);
84
+ throw new ue(`${t} node "${e.nodeId}" does not exist`);
85
+ if (e.portId && o.ports && !o.ports.some((i) => i.id === e.portId))
86
+ throw new ue(`${t} port "${e.portId}" not found on node "${e.nodeId}"`);
85
87
  }
86
- function Te(s, e, t) {
88
+ function _e(s, e, t) {
87
89
  return { ...s, nodes: { ...s.nodes, [e]: t } };
88
90
  }
89
- function Re(s, e, t) {
91
+ function De(s, e, t) {
90
92
  return { ...s, edges: { ...s.edges, [e]: t } };
91
93
  }
92
- function gt(s, e) {
94
+ function yt(s, e) {
93
95
  if (s.nodes[e.id])
94
- throw new ne(`Node id "${e.id}" already exists`);
96
+ throw new ue(`Node id "${e.id}" already exists`);
95
97
  return { ...s, nodes: { ...s.nodes, [e.id]: e } };
96
98
  }
97
- function ht(s, e, t) {
99
+ function mt(s, e, t) {
98
100
  const o = Ce(s, e);
99
- return Te(s, e, { ...o, position: t });
101
+ return _e(s, e, { ...o, position: t });
100
102
  }
101
- function vt(s, e) {
103
+ function wt(s, e) {
102
104
  Ce(s, e);
103
105
  const { [e]: t, ...o } = s.nodes, n = {};
104
- for (const [r, i] of Object.entries(s.edges))
105
- i.source.nodeId !== e && i.target.nodeId !== e && (n[r] = i);
106
+ for (const [i, r] of Object.entries(s.edges))
107
+ r.source.nodeId !== e && r.target.nodeId !== e && (n[i] = r);
106
108
  return { ...s, nodes: o, edges: n };
107
109
  }
108
- function yt(s, e, t) {
110
+ function bt(s, e, t) {
109
111
  const o = Ce(s, e);
110
- return Te(s, e, { ...o, ...t, id: o.id });
112
+ return _e(s, e, { ...o, ...t, id: o.id });
111
113
  }
112
- function mt(s, e, t, o) {
113
- const n = Ce(s, e), r = Ae(n.payload, t, o);
114
- return Te(s, e, { ...n, payload: r });
114
+ function xt(s, e, t, o) {
115
+ const n = Ce(s, e), i = Ne(n.payload, t, o);
116
+ return _e(s, e, { ...n, payload: i });
115
117
  }
116
- function bt(s, e, t, o) {
117
- const n = Ce(s, e), r = Ae(n.extensions, t, o);
118
- return Te(s, e, { ...n, extensions: r });
118
+ function Et(s, e, t, o) {
119
+ const n = Ce(s, e), i = Ne(n.extensions, t, o);
120
+ return _e(s, e, { ...n, extensions: i });
119
121
  }
120
- function wt(s, e) {
122
+ function It(s, e) {
121
123
  if (s.edges[e.id])
122
- throw new ne(`Edge id "${e.id}" already exists`);
123
- if (be(s, e.source, "Source"), be(s, e.target, "Target"), e.labels) {
124
+ throw new ue(`Edge id "${e.id}" already exists`);
125
+ if (xe(s, e.source, "Source"), xe(s, e.target, "Target"), e.labels) {
124
126
  const t = /* @__PURE__ */ new Set();
125
127
  for (const o of e.labels) {
126
128
  if (t.has(o.id))
127
- throw new ne(`Duplicate label id "${o.id}" in edge "${e.id}"`);
129
+ throw new ue(`Duplicate label id "${o.id}" in edge "${e.id}"`);
128
130
  t.add(o.id);
129
131
  }
130
132
  }
131
133
  return { ...s, edges: { ...s.edges, [e.id]: e } };
132
134
  }
133
- function xt(s, e) {
134
- Ee(s, e);
135
+ function Ct(s, e) {
136
+ ke(s, e);
135
137
  const { [e]: t, ...o } = s.edges;
136
138
  return { ...s, edges: o };
137
139
  }
138
140
  function kt(s, e, t, o) {
139
- const n = Ee(s, e), r = t ?? n.source, i = o ?? n.target;
140
- return be(s, r, "Source"), be(s, i, "Target"), Re(s, e, { ...n, source: r, target: i });
141
+ const n = ke(s, e), i = t ?? n.source, r = o ?? n.target;
142
+ return xe(s, i, "Source"), xe(s, r, "Target"), De(s, e, { ...n, source: i, target: r });
141
143
  }
142
- function Ct(s, e, t) {
143
- const o = Ee(s, e), n = { ...o, ...t, id: o.id };
144
- return t.source && be(s, n.source, "Source"), t.target && be(s, n.target, "Target"), Re(s, e, n);
144
+ function St(s, e, t) {
145
+ const o = ke(s, e), n = { ...o, ...t, id: o.id };
146
+ return t.source && xe(s, n.source, "Source"), t.target && xe(s, n.target, "Target"), De(s, e, n);
145
147
  }
146
- function Et(s, e, t, o) {
147
- const n = Ee(s, e), r = Ae(n.payload, t, o);
148
- return Re(s, e, { ...n, payload: r });
148
+ function Mt(s, e, t, o) {
149
+ const n = ke(s, e), i = Ne(n.payload, t, o);
150
+ return De(s, e, { ...n, payload: i });
149
151
  }
150
- function It(s, e, t, o) {
151
- const n = Ee(s, e);
152
+ function Nt(s, e, t, o) {
153
+ const n = ke(s, e);
152
154
  if (!n.labels)
153
- throw new ne(`Edge "${e}" has no labels`);
154
- const r = n.labels.findIndex((l) => l.id === t);
155
- if (r === -1)
156
- throw new ne(`Label "${t}" not found in edge "${e}"`);
157
- const i = [...n.labels];
158
- return i[r] = { ...i[r], ...o, id: t }, Re(s, e, { ...n, labels: i });
159
- }
160
- function Mt(s, e, t) {
161
- const o = Ae(s.meta, e, t);
155
+ throw new ue(`Edge "${e}" has no labels`);
156
+ const i = n.labels.findIndex((l) => l.id === t);
157
+ if (i === -1)
158
+ throw new ue(`Label "${t}" not found in edge "${e}"`);
159
+ const r = [...n.labels];
160
+ return r[i] = { ...r[i], ...o, id: t }, De(s, e, { ...n, labels: r });
161
+ }
162
+ function _t(s, e, t) {
163
+ const o = Ne(s.meta, e, t);
162
164
  return { ...s, meta: o };
163
165
  }
164
- function Nt(s, e) {
165
- const t = e?.maxHistorySize ?? 100, o = O(s), n = [], r = [], i = O(!1), l = O(!1);
166
+ function Dt(s, e) {
167
+ const t = e?.maxHistorySize ?? 100, o = q(s), n = [], i = [], r = q(!1), l = q(!1);
166
168
  function a() {
167
- i.value = n.length > 0, l.value = r.length > 0;
168
- }
169
- function g(w) {
170
- const N = o.value;
171
- let m = N;
172
- for (const D of w.commands)
173
- m = Ge(m, D);
174
- return n.push({ snapshot: N, envelope: w }), n.length > t && n.shift(), r.length = 0, o.value = m, a(), m;
169
+ r.value = n.length > 0, l.value = i.length > 0;
175
170
  }
176
- function d() {
177
- const w = n.pop();
178
- return w ? (r.push({ snapshot: o.value, envelope: w.envelope }), o.value = w.snapshot, a(), w.snapshot) : null;
171
+ function h(k) {
172
+ const S = o.value;
173
+ let T = S;
174
+ for (const P of k.commands)
175
+ T = $e(T, P);
176
+ return n.push({ snapshot: S, envelope: k }), n.length > t && n.shift(), i.length = 0, o.value = T, a(), T;
179
177
  }
180
- function v() {
181
- const w = r.pop();
182
- if (!w) return null;
183
- n.push({ snapshot: o.value, envelope: w.envelope });
184
- let N = o.value;
185
- for (const m of w.envelope.commands)
186
- N = Ge(N, m);
187
- return o.value = N, a(), N;
178
+ function u() {
179
+ const k = n.pop();
180
+ return k ? (i.push({ snapshot: o.value, envelope: k.envelope }), o.value = k.snapshot, a(), k.snapshot) : null;
188
181
  }
189
- function f() {
190
- n.length = 0, r.length = 0, a();
182
+ function g() {
183
+ const k = i.pop();
184
+ if (!k) return null;
185
+ n.push({ snapshot: o.value, envelope: k.envelope });
186
+ let S = o.value;
187
+ for (const T of k.envelope.commands)
188
+ S = $e(S, T);
189
+ return o.value = S, a(), S;
191
190
  }
192
191
  function p() {
192
+ n.length = 0, i.length = 0, a();
193
+ }
194
+ function x() {
193
195
  return o.value;
194
196
  }
195
- function E(w) {
196
- o.value = w, f();
197
+ function m(k) {
198
+ o.value = k, p();
197
199
  }
198
200
  return {
199
201
  currentFlowModel: o,
200
- execute: g,
201
- undo: d,
202
- redo: v,
203
- canUndo: i,
202
+ execute: h,
203
+ undo: u,
204
+ redo: g,
205
+ canUndo: r,
204
206
  canRedo: l,
205
207
  get undoStack() {
206
- return n.map((w) => w.envelope);
208
+ return n.map((k) => k.envelope);
207
209
  },
208
210
  get redoStack() {
209
- return r.map((w) => w.envelope);
211
+ return i.map((k) => k.envelope);
210
212
  },
211
- clear: f,
212
- createSnapshot: p,
213
- replaceFlowModel: E
213
+ clear: p,
214
+ createSnapshot: x,
215
+ replaceFlowModel: m
214
216
  };
215
217
  }
216
- function St(s) {
218
+ function At(s) {
217
219
  return s !== null && typeof s == "object" && s.rejected === !0;
218
220
  }
219
- class Dt {
221
+ class Pt {
220
222
  plugins = [];
221
223
  editorContext = null;
222
224
  runtimeCtx = null;
@@ -251,11 +253,11 @@ class Dt {
251
253
  */
252
254
  createSafeRuntimeContext(e, t) {
253
255
  const o = this, n = new Proxy(e.graph, {
254
- get(r, i, l) {
255
- const a = Reflect.get(r, i, l);
256
- return i === "use" && typeof a == "function" ? function(...d) {
256
+ get(i, r, l) {
257
+ const a = Reflect.get(i, r, l);
258
+ return r === "use" && typeof a == "function" ? function(...u) {
257
259
  if (o.runtimeVersion === t)
258
- return a.apply(r, d);
260
+ return a.apply(i, u);
259
261
  } : a;
260
262
  }
261
263
  });
@@ -271,8 +273,8 @@ class Dt {
271
273
  let t = e;
272
274
  for (const o of this.plugins) {
273
275
  if (!o.transformCommand) continue;
274
- const n = this.createPreview(t), r = o.transformCommand(t, n, this.editorContext);
275
- if (r === null)
276
+ const n = this.createPreview(t), i = o.transformCommand(t, n, this.editorContext);
277
+ if (i === null)
276
278
  return {
277
279
  rejected: !0,
278
280
  error: {
@@ -281,16 +283,16 @@ class Dt {
281
283
  source: o.name
282
284
  }
283
285
  };
284
- if (St(r))
286
+ if (At(i))
285
287
  return {
286
288
  rejected: !0,
287
289
  error: {
288
- code: r.code ?? "plugin_rejected",
289
- reason: r.reason,
290
+ code: i.code ?? "plugin_rejected",
291
+ reason: i.reason,
290
292
  source: o.name
291
293
  }
292
294
  };
293
- t = r;
295
+ t = i;
294
296
  }
295
297
  return { envelope: t };
296
298
  }
@@ -372,150 +374,154 @@ class Dt {
372
374
  return {
373
375
  previewFlowModel(o) {
374
376
  const n = o ?? e.commands;
375
- let r = t.flowModel.value;
376
- for (const i of n)
377
- r = Ge(r, i);
378
- return r;
377
+ let i = t.flowModel.value;
378
+ for (const r of n)
379
+ i = $e(i, r);
380
+ return i;
379
381
  }
380
382
  };
381
383
  }
382
384
  }
383
- let Pt = 0;
384
- function W() {
385
+ let Tt = 0;
386
+ function te() {
385
387
  const s = Date.now().toString(36), e = Math.random().toString(36).substring(2, 8);
386
- return `${s}-${e}-${++Pt}`;
388
+ return `${s}-${e}-${++Tt}`;
387
389
  }
388
- const He = () => W();
389
- function No(s) {
390
- const { schema: e, plugins: t = [], historyOptions: o } = s, n = s.idGenerator ?? He, r = { version: "1.0", ...s.initialFlowModel }, i = Nt(r, o), l = O(s.mode ?? "edit"), a = O(!1), g = O(null), d = O([]), v = {}, f = new Dt();
391
- function p(m, D, z, X = "user:toolbar") {
392
- const j = {
390
+ const Ge = () => te();
391
+ function gn(s) {
392
+ const { schema: e, plugins: t = [], historyOptions: o } = s, n = s.idGenerator ?? Ge, i = { version: "1.0", ...s.initialFlowModel }, r = Dt(i, o), l = q(s.mode ?? "edit"), a = q(!1), h = q(null), u = q([]), g = {}, p = new Pt();
393
+ function x(T, P, G, K = "user:toolbar") {
394
+ const O = {
393
395
  id: `history-${Date.now()}`,
394
- source: X,
395
- label: m,
396
+ source: K,
397
+ label: T,
396
398
  timestamp: Date.now(),
397
399
  commands: []
398
400
  };
399
- f.afterCommand(j, D, z), d.value = f.collectToolbarItems(), s.onCommandResult?.({
401
+ p.afterCommand(O, P, G), u.value = p.collectToolbarItems(), s.onCommandResult?.({
400
402
  status: "applied",
401
- envelope: j,
402
- flowModel: z
403
+ envelope: O,
404
+ flowModel: G
403
405
  }), s.onFlowModelChange?.({
404
- flowModel: z,
405
- prevFlowModel: D,
406
- envelope: j,
407
- source: X
406
+ flowModel: G,
407
+ prevFlowModel: P,
408
+ envelope: O,
409
+ source: K
408
410
  });
409
411
  }
410
- const E = {
411
- execute: i.execute,
412
+ const m = {
413
+ execute: r.execute,
412
414
  undo() {
413
- const m = i.currentFlowModel.value, D = i.undo();
414
- return D && p("撤销", m, D), D;
415
+ const T = r.currentFlowModel.value, P = r.undo();
416
+ return P && x("撤销", T, P), P;
415
417
  },
416
418
  redo() {
417
- const m = i.currentFlowModel.value, D = i.redo();
418
- return D && p("重做", m, D), D;
419
+ const T = r.currentFlowModel.value, P = r.redo();
420
+ return P && x("重做", T, P), P;
419
421
  },
420
422
  get canUndo() {
421
- return i.canUndo;
423
+ return r.canUndo;
422
424
  },
423
425
  get canRedo() {
424
- return i.canRedo;
426
+ return r.canRedo;
425
427
  },
426
428
  get undoStack() {
427
- return i.undoStack;
429
+ return r.undoStack;
428
430
  },
429
431
  get redoStack() {
430
- return i.redoStack;
432
+ return r.redoStack;
431
433
  },
432
- clear: i.clear,
433
- createSnapshot: i.createSnapshot,
434
- replaceFlowModel(m) {
435
- const D = i.currentFlowModel.value;
436
- i.replaceFlowModel(m), p("替换 FlowModel", D, m, "system:replace");
437
- }
438
- }, w = {
439
- flowModel: F(() => i.currentFlowModel.value),
440
- history: E,
434
+ clear: r.clear,
435
+ createSnapshot: r.createSnapshot,
436
+ replaceFlowModel(T) {
437
+ const P = r.currentFlowModel.value;
438
+ r.replaceFlowModel(T), x("替换 FlowModel", P, T, "system:replace");
439
+ }
440
+ }, k = {
441
+ flowModel: j(() => r.currentFlowModel.value),
442
+ history: m,
441
443
  schema: e,
442
444
  mode: l,
443
445
  idGenerator: n,
444
- executeCommand: N,
445
- replaceFlowModel(m) {
446
- E.replaceFlowModel(m);
446
+ executeCommand: S,
447
+ replaceFlowModel(T) {
448
+ m.replaceFlowModel(T);
447
449
  },
448
- setMode(m) {
449
- l.value = m;
450
+ setMode(T) {
451
+ l.value = T;
450
452
  },
451
453
  selectionMode: a,
452
- setSelectionMode(m) {
453
- a.value = m;
454
+ setSelectionMode(T) {
455
+ a.value = T;
454
456
  },
455
- api: g,
456
- toolbarItems: d,
457
- extendedApi: v,
458
- _pluginManager: f
457
+ api: h,
458
+ toolbarItems: u,
459
+ extendedApi: g,
460
+ _pluginManager: p,
461
+ _emitUiEvent: (T) => {
462
+ p.dispatchUiEvent(T);
463
+ }
459
464
  };
460
- f.install(t, {
461
- flowModel: w.flowModel,
462
- history: E,
465
+ p.install(t, {
466
+ flowModel: k.flowModel,
467
+ history: m,
463
468
  schema: e,
464
469
  mode: l,
465
470
  idGenerator: n,
466
- executeCommand: N
467
- }), d.value = f.collectToolbarItems(), et(() => {
468
- f.dispose();
471
+ executeCommand: S
472
+ }), u.value = p.collectToolbarItems(), Je(() => {
473
+ p.dispose();
469
474
  });
470
- function N(m) {
471
- const D = f.transformCommand(m);
472
- if ("rejected" in D) {
473
- const j = {
475
+ function S(T) {
476
+ const P = p.transformCommand(T);
477
+ if ("rejected" in P) {
478
+ const O = {
474
479
  status: "rejected",
475
- envelope: m,
476
- error: D.error
480
+ envelope: T,
481
+ error: P.error
477
482
  };
478
- return s.onCommandResult?.(j), j;
483
+ return s.onCommandResult?.(O), O;
479
484
  }
480
- const z = D.envelope, X = i.currentFlowModel.value;
485
+ const G = P.envelope, K = r.currentFlowModel.value;
481
486
  try {
482
- const j = i.execute(z), oe = {
487
+ const O = r.execute(G), W = {
483
488
  status: "applied",
484
- envelope: z,
485
- flowModel: j
489
+ envelope: G,
490
+ flowModel: O
486
491
  };
487
- return f.afterCommand(z, X, j), d.value = f.collectToolbarItems(), s.onCommandResult?.(oe), s.onFlowModelChange?.({
488
- flowModel: j,
489
- prevFlowModel: X,
490
- envelope: z,
491
- source: z.source
492
- }), oe;
493
- } catch (j) {
494
- if (j instanceof ne) {
495
- const oe = {
492
+ return p.afterCommand(G, K, O), u.value = p.collectToolbarItems(), s.onCommandResult?.(W), s.onFlowModelChange?.({
493
+ flowModel: O,
494
+ prevFlowModel: K,
495
+ envelope: G,
496
+ source: G.source
497
+ }), W;
498
+ } catch (O) {
499
+ if (O instanceof ue) {
500
+ const W = {
496
501
  status: "invalid",
497
- envelope: z,
502
+ envelope: G,
498
503
  error: {
499
504
  code: "constraint_violated",
500
- reason: j.message,
505
+ reason: O.message,
501
506
  source: "engine"
502
507
  }
503
508
  };
504
- return s.onCommandResult?.(oe), oe;
509
+ return s.onCommandResult?.(W), W;
505
510
  }
506
- throw j;
511
+ throw O;
507
512
  }
508
513
  }
509
- return w;
514
+ return k;
510
515
  }
511
- const _t = ["top", "right", "bottom", "left"];
516
+ const Rt = ["top", "right", "bottom", "left"];
512
517
  function nt() {
513
- return _t.map((s) => ({ id: s, group: s }));
518
+ return Rt.map((s) => ({ id: s, group: s }));
514
519
  }
515
- function Fe(s, e) {
520
+ function qe(s, e) {
516
521
  return e?.(s) ?? s.ports ?? nt();
517
522
  }
518
- class At {
523
+ const Te = -1, Lt = "flow-canvas-node-ring-target", Fe = "flow-canvas-node-ring-target--decorated", Ue = "flow-canvas-node-ring-target--pulse", Ot = "linear-gradient(135deg, #cadcfa 0%, #cee0ff 100%)";
524
+ class $t {
519
525
  graph;
520
526
  schema;
521
527
  shapeRegistry;
@@ -540,8 +546,8 @@ class At {
540
546
  /** x6EdgeConfig 中 attrs.line 的基线值,清理时恢复而非删除 */
541
547
  edgeDefaultAttrs = /* @__PURE__ */ new Map();
542
548
  lastModel = null;
543
- constructor(e, t, o, n, r, i) {
544
- this.graph = e, this.schema = t, this.shapeRegistry = o, this.resolveNodeDecoration = n, this.resolveEdgeDecoration = r, this.resolveCanvasContext = i;
549
+ constructor(e, t, o, n, i, r) {
550
+ this.graph = e, this.schema = t, this.shapeRegistry = o, this.resolveNodeDecoration = n, this.resolveEdgeDecoration = i, this.resolveCanvasContext = r;
545
551
  }
546
552
  syncFlowModel(e) {
547
553
  if (!this.syncing) {
@@ -564,9 +570,9 @@ class At {
564
570
  saveNodeDefaultAttrs(e, t) {
565
571
  const n = t.x6CellConfig?.attrs?.body;
566
572
  if (!n) return;
567
- const r = {};
568
- let i = !1;
569
- n.stroke !== void 0 && (r.stroke = n.stroke, i = !0), n.strokeWidth !== void 0 && (r.strokeWidth = n.strokeWidth, i = !0), i && this.nodeDefaultAttrs.set(e, r);
573
+ const i = {};
574
+ let r = !1;
575
+ n.stroke !== void 0 && (i.stroke = n.stroke, r = !0), n.strokeWidth !== void 0 && (i.strokeWidth = n.strokeWidth, r = !0), r && this.nodeDefaultAttrs.set(e, i);
570
576
  }
571
577
  /**
572
578
  * 从 x6EdgeConfig.attrs.line 中提取基线描边,用于管理层清理时恢复。
@@ -574,24 +580,45 @@ class At {
574
580
  saveEdgeDefaultAttrs(e, t) {
575
581
  const n = t?.x6EdgeConfig?.attrs?.line;
576
582
  if (!n) return;
577
- const r = {};
578
- let i = !1;
579
- n.stroke !== void 0 && (r.stroke = n.stroke, i = !0), n.strokeWidth !== void 0 && (r.strokeWidth = n.strokeWidth, i = !0), n.strokeDasharray !== void 0 && (r.strokeDasharray = n.strokeDasharray, i = !0), i && this.edgeDefaultAttrs.set(e, r);
583
+ const i = {};
584
+ let r = !1;
585
+ n.stroke !== void 0 && (i.stroke = n.stroke, r = !0), n.strokeWidth !== void 0 && (i.strokeWidth = n.strokeWidth, r = !0), n.strokeDasharray !== void 0 && (i.strokeDasharray = n.strokeDasharray, r = !0), r && this.edgeDefaultAttrs.set(e, i);
580
586
  }
581
- /** 恢复节点 attr 到基线值;无基线时移除。 */
587
+ /**
588
+ * 恢复节点 attr 到基线值;无基线时设为安全默认值。
589
+ * 不使用 removeAttrByPath,因为对 Vue Shape 节点执行 remove 会触发 X6
590
+ * 完整的 cell view 重渲染,可能导致 foreignObject 尺寸被瞬间重置,
591
+ * 使得内部 Vue 组件 (width/height: 100%) 折叠后无法恢复。
592
+ */
582
593
  restoreNodeAttr(e, t, o) {
583
594
  const n = this.nodeDefaultAttrs.get(e.id)?.[o];
584
- n !== void 0 ? e.setAttrByPath(t, n) : e.removeAttrByPath(t);
595
+ if (n !== void 0)
596
+ e.setAttrByPath(t, n);
597
+ else {
598
+ const i = o === "stroke" ? "none" : 0;
599
+ e.setAttrByPath(t, i);
600
+ }
585
601
  }
586
602
  /** 恢复边 attr 到基线值;无基线时移除。 */
587
603
  restoreEdgeAttr(e, t, o) {
588
604
  const n = this.edgeDefaultAttrs.get(e.id)?.[o];
589
- n !== void 0 ? e.setAttrByPath(t, n) : e.removeAttrByPath(t);
605
+ n !== void 0 ? this.setEdgeAttrIfChanged(e, t, n) : e.attr(t) !== void 0 && e.removeAttrByPath(t);
606
+ }
607
+ /**
608
+ * 仅在值实际变化时调用 setAttrByPath。
609
+ * X6 的 setAttrByPath 每次都会创建新的 attrs 对象引用并触发 change:attrs 事件,
610
+ * 即使值相同也会导致 EdgeView.update() → updateConnection() → 路由器全量重算。
611
+ */
612
+ setEdgeAttrIfChanged(e, t, o) {
613
+ e.attr(t) !== o && e.setAttrByPath(t, o);
614
+ }
615
+ getNodeRingTarget(e) {
616
+ return e ? e.querySelector(".flow-canvas-highlight-target") ?? e.querySelector(".flow-canvas-node-surface > :first-child") : null;
590
617
  }
591
618
  /** 让正式边接管交互式预览边时,恢复 schema 定义的端点 marker。 */
592
619
  syncEdgeMarker(e, t, o) {
593
- const r = t?.x6EdgeConfig?.attrs?.line?.[o], i = `line/${o}`;
594
- e.removeAttrByPath(i), r !== void 0 && e.setAttrByPath(i, r);
620
+ const i = t?.x6EdgeConfig?.attrs?.line?.[o], r = `line/${o}`;
621
+ e.removeAttrByPath(r), i !== void 0 && e.setAttrByPath(r, i);
595
622
  }
596
623
  dispose() {
597
624
  this.knownNodeIds.clear(), this.knownEdgeIds.clear();
@@ -599,21 +626,21 @@ class At {
599
626
  resolveNodes(e) {
600
627
  const t = /* @__PURE__ */ new Map();
601
628
  for (const [o, n] of Object.entries(e.nodes)) {
602
- const r = this.schema.nodeTypes[n.type];
603
- if (!r)
604
- throw new pt(
629
+ const i = this.schema.nodeTypes[n.type];
630
+ if (!i)
631
+ throw new vt(
605
632
  `Unknown node type "${n.type}" for node "${o}". Registered types: [${Object.keys(this.schema.nodeTypes).join(", ")}]. Register the type in CanvasSchema.nodeTypes before using it in a FlowModel.`
606
633
  );
607
- const i = this.shapeRegistry.registerNodeType(n.type, r.component), l = r.getSize(n), a = Fe(n, r.getPorts);
608
- t.set(o, { model: n, definition: r, shapeName: i, size: l, ports: a });
634
+ const r = this.shapeRegistry.registerNodeType(n.type, i.component), l = i.getSize(n), a = qe(n, i.getPorts);
635
+ t.set(o, { model: n, definition: i, shapeName: r, size: l, ports: a });
609
636
  }
610
637
  return t;
611
638
  }
612
639
  resolveEdges(e) {
613
640
  const t = /* @__PURE__ */ new Map();
614
641
  for (const [o, n] of Object.entries(e.edges)) {
615
- const r = n.type ?? this.schema.defaultEdgeType ?? "default", i = this.schema.edgeTypes?.[r];
616
- t.set(o, { model: n, definition: i });
642
+ const i = n.type ?? this.schema.defaultEdgeType ?? "default", r = this.schema.edgeTypes?.[i];
643
+ t.set(o, { model: n, definition: r });
617
644
  }
618
645
  return t;
619
646
  }
@@ -625,36 +652,36 @@ class At {
625
652
  n && this.graph.removeCell(n), this.knownNodeIds.delete(o), this.defaultHighlightedNodeIds.delete(o), this.prevNodeDecorationClasses.delete(o), this.prevNodeDecorationColors.delete(o), this.nodeDefaultAttrs.delete(o);
626
653
  }
627
654
  for (const [o, n] of e) {
628
- const r = this.graph.getCellById(o);
629
- r ? this.updateExistingNode(r, n) : this.addNewNode(o, n);
655
+ const i = this.graph.getCellById(o);
656
+ i ? this.updateExistingNode(i, n) : this.addNewNode(o, n);
630
657
  }
631
658
  }
632
659
  updateExistingNode(e, t) {
633
- const { model: o, size: n, ports: r, definition: i } = t;
660
+ const { model: o, size: n, ports: i, definition: r } = t;
634
661
  if (e.getData()?.type !== o.type) {
635
662
  this.graph.removeCell(e), this.addNewNode(e.id, t);
636
663
  return;
637
664
  }
638
665
  const a = e.getPosition();
639
666
  (a.x !== o.position.x || a.y !== o.position.y) && e.setPosition(o.position.x, o.position.y);
640
- const g = e.getSize();
641
- (g.width !== n.width || g.height !== n.height) && e.setSize(n.width, n.height, { silent: !0 }), this.syncNodePorts(e, r), e.setData({ ...o }), this.applyNodeBehavior(e, o, i), this.applyNodeHighlightAndDecoration(e, o);
667
+ const h = e.getSize();
668
+ (h.width !== n.width || h.height !== n.height) && e.setSize(n.width, n.height, { silent: !0 }), this.syncNodePorts(e, i), e.setData({ ...o }), this.applyNodeBehavior(e, o, r), this.applyNodeHighlightAndDecoration(e, o);
642
669
  }
643
670
  syncNodePorts(e, t) {
644
- const o = e.getPorts(), n = new Set(t.map((i) => i.id)), r = new Set(o.map((i) => i.id));
645
- for (const i of o)
646
- i.id && !n.has(i.id) && e.removePort(i.id);
647
- for (const i of t)
648
- r.has(i.id) || e.addPort({ id: i.id, group: i.group, ...i.x6PortConfig });
671
+ const o = e.getPorts(), n = new Set(t.map((r) => r.id)), i = new Set(o.map((r) => r.id));
672
+ for (const r of o)
673
+ r.id && !n.has(r.id) && e.removePort(r.id);
674
+ for (const r of t)
675
+ i.has(r.id) || e.addPort({ id: r.id, group: r.group, ...r.x6PortConfig });
649
676
  }
650
677
  addNewNode(e, t) {
651
- const { model: o, shapeName: n, size: r, ports: i, definition: l } = t, a = {
678
+ const { model: o, shapeName: n, size: i, ports: r, definition: l } = t, a = {
652
679
  id: o.id,
653
680
  shape: n,
654
681
  x: o.position.x,
655
682
  y: o.position.y,
656
- width: r.width,
657
- height: r.height,
683
+ width: i.width,
684
+ height: i.height,
658
685
  data: { ...o },
659
686
  ports: {
660
687
  groups: {
@@ -683,20 +710,23 @@ class At {
683
710
  }
684
711
  }
685
712
  },
686
- items: i.map((d) => ({ id: d.id, group: d.group, ...d.x6PortConfig }))
713
+ items: r.map((u) => ({ id: u.id, group: u.group, ...u.x6PortConfig }))
687
714
  },
688
715
  ...l.x6CellConfig
689
716
  };
690
717
  this.graph.addNode(a), this.knownNodeIds.add(e), this.saveNodeDefaultAttrs(e, l);
691
- const g = this.graph.getCellById(e);
692
- g && (this.applyNodeBehavior(g, o, l), this.applyNodeHighlightAndDecoration(g, o));
718
+ const h = this.graph.getCellById(e);
719
+ h && (this.applyNodeBehavior(h, o, l), this.applyNodeHighlightAndDecoration(h, o));
693
720
  }
694
721
  /**
695
722
  * 将 schema 定义的 getBehavior 映射到 X6 节点属性。
696
723
  * NodeBehaviorConfig 的每个字段都映射到 X6 Cell 对应能力:
697
724
  * - draggable → 是否可拖拽移动
698
725
  * - selectable → 是否可被选中(注意:X6 Selection 插件也有全局控制)
699
- * - connectable → ports 的 magnet 属性,控制是否可从该节点发起连线
726
+ * - connectable / targetable → ports 的 magnet 属性
727
+ * true → 可发起,也可作为目标
728
+ * 'passive' → 不可发起,但仍可作为目标(如结束节点)
729
+ * false → 不可发起,也不可作为目标
700
730
  * - showPorts → ports 的可见性
701
731
  * - deletable → 存入 cell data,由删除操作(插件/快捷键)自行读取判断
702
732
  */
@@ -704,30 +734,30 @@ class At {
704
734
  if (!o.getBehavior) return;
705
735
  const n = this.resolveCanvasContext?.();
706
736
  if (!n) return;
707
- const r = o.getBehavior(t, n);
708
- if (r.draggable !== void 0 && e.setProp("draggable", r.draggable, { silent: !0 }), r.connectable !== void 0) {
709
- const l = r.connectable;
737
+ const i = o.getBehavior(t, n);
738
+ if (i.draggable !== void 0 && e.setProp("draggable", i.draggable, { silent: !0 }), i.connectable !== void 0) {
739
+ const l = i.connectable ? !0 : i.targetable === !1 ? !1 : "passive";
710
740
  for (const a of e.getPorts())
711
741
  e.setPortProp(a.id, "attrs/circle/magnet", l, { silent: !0 });
712
742
  }
713
- if (r.showPorts !== void 0) {
714
- const l = r.showPorts;
743
+ if (i.showPorts !== void 0) {
744
+ const l = i.showPorts;
715
745
  for (const a of e.getPorts())
716
746
  e.setPortProp(a.id, "attrs/circle/visibility", l ? "visible" : "hidden", { silent: !0 });
717
747
  }
718
- const i = e.getData() ?? {};
719
- r.deletable !== void 0 && i._deletable !== r.deletable && e.setData({ ...i, _deletable: r.deletable }, { silent: !0 }), r.selectable !== void 0 && i._selectable !== r.selectable && e.setData({ ...e.getData(), _selectable: r.selectable }, { silent: !0 });
748
+ const r = e.getData() ?? {};
749
+ i.deletable !== void 0 && r._deletable !== i.deletable && e.setData({ ...r, _deletable: i.deletable }, { silent: !0 }), i.selectable !== void 0 && r._selectable !== i.selectable && e.setData({ ...e.getData(), _selectable: i.selectable }, { silent: !0 });
720
750
  }
721
751
  syncEdges(e, t) {
722
752
  const o = new Set(e.keys());
723
753
  for (const n of this.knownEdgeIds)
724
754
  if (!o.has(n)) {
725
- const r = this.graph.getCellById(n);
726
- r && this.graph.removeCell(r), this.knownEdgeIds.delete(n), this.defaultHighlightedEdgeIds.delete(n), this.prevEdgeDecorationClasses.delete(n), this.prevEdgeDecorationColors.delete(n), this.prevEdgeStyleIds.delete(n), this.edgeDefaultAttrs.delete(n);
755
+ const i = this.graph.getCellById(n);
756
+ i && this.graph.removeCell(i), this.knownEdgeIds.delete(n), this.defaultHighlightedEdgeIds.delete(n), this.prevEdgeDecorationClasses.delete(n), this.prevEdgeDecorationColors.delete(n), this.prevEdgeStyleIds.delete(n), this.edgeDefaultAttrs.delete(n);
727
757
  }
728
- for (const [n, r] of e) {
729
- const i = this.graph.getCellById(n), { model: l, definition: a } = r;
730
- i ? (this.updateExistingEdge(i, l, a, t), this.knownEdgeIds.has(n) || (this.knownEdgeIds.add(n), this.saveEdgeDefaultAttrs(n, a))) : this.addNewEdge(n, l, a);
758
+ for (const [n, i] of e) {
759
+ const r = this.graph.getCellById(n), { model: l, definition: a } = i;
760
+ r ? (this.updateExistingEdge(r, l, a, t), this.knownEdgeIds.has(n) || (this.knownEdgeIds.add(n), this.saveEdgeDefaultAttrs(n, a))) : this.addNewEdge(n, l, a);
731
761
  }
732
762
  }
733
763
  /**
@@ -736,16 +766,20 @@ class At {
736
766
  * 需要用 (currentSource as any).cell 来比较。
737
767
  */
738
768
  updateExistingEdge(e, t, o, n) {
739
- const r = e.getSource(), i = e.getTarget();
740
- if ((r.cell !== t.source.nodeId || r.port !== t.source.portId) && e.setSource({ cell: t.source.nodeId, port: t.source.portId }), (i.cell !== t.target.nodeId || i.port !== t.target.portId) && e.setTarget({ cell: t.target.nodeId, port: t.target.portId }), o?.router) {
741
- const l = typeof o.router == "string" ? { name: o.router } : o.router;
742
- e.setRouter(l);
743
- }
744
- if (o?.connector) {
745
- const l = typeof o.connector == "string" ? { name: o.connector } : o.connector;
746
- e.setConnector(l);
769
+ const i = e.getSource(), r = e.getTarget(), l = i.cell !== t.source.nodeId || i.port !== t.source.portId, a = r.cell !== t.target.nodeId || r.port !== t.target.portId;
770
+ l && e.setSource({ cell: t.source.nodeId, port: t.source.portId }), a && e.setTarget({ cell: t.target.nodeId, port: t.target.portId });
771
+ const u = (e.getData()?.type ?? void 0) !== (t.type ?? void 0);
772
+ if (u) {
773
+ if (o?.router) {
774
+ const g = typeof o.router == "string" ? { name: o.router } : o.router;
775
+ e.setRouter(g);
776
+ }
777
+ if (o?.connector) {
778
+ const g = typeof o.connector == "string" ? { name: o.connector } : o.connector;
779
+ e.setConnector(g);
780
+ }
747
781
  }
748
- this.syncEdgeMarker(e, o, "sourceMarker"), this.syncEdgeMarker(e, o, "targetMarker"), this.syncEdgeLabels(e, t), e.setData({ ...t }, { silent: !0 }), this.applyEdgeStyleAndDecoration(e, t, o);
782
+ (u || l || a) && (this.syncEdgeMarker(e, o, "sourceMarker"), this.syncEdgeMarker(e, o, "targetMarker")), this.syncEdgeLabels(e, t), e.getZIndex() !== Te && e.setZIndex(Te), e.setData({ ...t }, { silent: !0 }), this.applyEdgeStyleAndDecoration(e, t, o);
749
783
  }
750
784
  syncEdgeLabels(e, t) {
751
785
  if (!t.labels?.length) {
@@ -766,29 +800,41 @@ class At {
766
800
  source: { cell: t.source.nodeId, port: t.source.portId },
767
801
  target: { cell: t.target.nodeId, port: t.target.portId },
768
802
  data: { ...t },
769
- zIndex: -1
803
+ zIndex: Te
770
804
  };
771
- o?.router && (n.router = typeof o.router == "string" ? { name: o.router } : o.router), o?.connector && (n.connector = typeof o.connector == "string" ? { name: o.connector } : o.connector), o?.x6EdgeConfig && Object.assign(n, o.x6EdgeConfig), t.labels?.length && (n.labels = t.labels.map((i) => ({
772
- attrs: { label: { text: i.text ?? "" } },
773
- position: i.position != null ? { distance: i.position } : void 0
805
+ o?.router && (n.router = typeof o.router == "string" ? { name: o.router } : o.router), o?.connector && (n.connector = typeof o.connector == "string" ? { name: o.connector } : o.connector), o?.x6EdgeConfig && Object.assign(n, o.x6EdgeConfig), t.labels?.length && (n.labels = t.labels.map((r) => ({
806
+ attrs: { label: { text: r.text ?? "" } },
807
+ position: r.position != null ? { distance: r.position } : void 0
774
808
  }))), this.graph.addEdge(n), this.knownEdgeIds.add(e), this.saveEdgeDefaultAttrs(e, o);
775
- const r = this.graph.getCellById(e);
776
- r && this.applyEdgeStyleAndDecoration(r, t, o);
809
+ const i = this.graph.getCellById(e);
810
+ i && this.applyEdgeStyleAndDecoration(i, t, o);
777
811
  }
778
812
  /**
779
- * 外部通知选区、高亮或 hover 变化时,重算所有边的视觉样式。
780
- * 每条边走统一分层管道 applyEdgeStyleAndDecoration,
781
- * 保证 defaultHighlight → schema style() → plugin decoration 的覆盖顺序。
813
+ * 重算所有边的视觉样式。
814
+ * 仅在需要全量刷新的场景使用(如高亮批量变更、选区批量变更)。
782
815
  */
783
816
  refreshEdgeStyles() {
784
817
  if (this.lastModel)
785
818
  for (const [e, t] of Object.entries(this.lastModel.edges)) {
786
819
  const o = this.graph.getCellById(e);
787
820
  if (!o?.isEdge()) continue;
788
- const n = t.type ?? this.schema.defaultEdgeType ?? "default", r = this.schema.edgeTypes?.[n];
789
- this.applyEdgeStyleAndDecoration(o, t, r);
821
+ const n = t.type ?? this.schema.defaultEdgeType ?? "default", i = this.schema.edgeTypes?.[n];
822
+ this.applyEdgeStyleAndDecoration(o, t, i);
790
823
  }
791
824
  }
825
+ /**
826
+ * 仅刷新单条边的视觉样式。
827
+ * 用于 hover 等只影响个别边的场景,避免对无关边触发 change:attrs → 路由重算。
828
+ */
829
+ refreshSingleEdgeStyle(e) {
830
+ if (!this.lastModel) return;
831
+ const t = this.lastModel.edges[e];
832
+ if (!t) return;
833
+ const o = this.graph.getCellById(e);
834
+ if (!o?.isEdge()) return;
835
+ const n = t.type ?? this.schema.defaultEdgeType ?? "default", i = this.schema.edgeTypes?.[n];
836
+ this.applyEdgeStyleAndDecoration(o, t, i);
837
+ }
792
838
  /**
793
839
  * 重算所有节点的高亮 + 装饰视觉。
794
840
  */
@@ -803,18 +849,25 @@ class At {
803
849
  * 单节点的高亮 + 装饰统一管道。
804
850
  * 所有路径(FlowModel 同步更新/新增节点/显式刷新高亮)必须走此方法。
805
851
  *
806
- * body/stroke 的分层优先级(低 → 高):
852
+ * 可见高亮的分层优先级(低 → 高):
807
853
  * 1. 默认高亮 (#3a84ff) — 节点在 highlightedNodeIds 中时兜底
808
854
  * 2. 插件装饰 (decorateNode().borderColor) — 始终覆盖高亮
809
855
  *
810
856
  * 最终值 = decorationColor ?? highlightColor ?? (清除)。
811
- * 只在"曾经设过 现在无值"时执行 removeAttrByPath,避免误删 X6 原始样式。
857
+ * Vue Shape 节点,真正可见的 ring 通过节点高亮目标元素的独立装饰态 / 脉冲态 / 选中态 class 呈现;
858
+ * body/stroke 仅作为普通 SVG shape 的兜底同步。
812
859
  */
813
860
  applyNodeHighlightAndDecoration(e, t) {
814
- const o = this.highlightedNodeIds.has(e.id), n = this.resolveNodeDecoration?.(t), r = this.prevNodeDecorationClasses.get(e.id);
815
- r && (this.graph.findViewByCell(e)?.container?.classList.remove(r), this.prevNodeDecorationClasses.delete(e.id)), n?.className && (this.graph.findViewByCell(e)?.container?.classList.add(n.className), this.prevNodeDecorationClasses.set(e.id, n.className));
816
- const i = n?.borderColor, a = i ?? (o ? "#3a84ff" : void 0), g = this.prevNodeDecorationColors.has(e.id) || this.defaultHighlightedNodeIds.has(e.id);
817
- a ? (e.setAttrByPath("body/stroke", a), e.setAttrByPath("body/strokeWidth", 2)) : g && (this.restoreNodeAttr(e, "body/stroke", "stroke"), this.restoreNodeAttr(e, "body/strokeWidth", "strokeWidth")), i ? this.prevNodeDecorationColors.add(e.id) : this.prevNodeDecorationColors.delete(e.id), o && !i ? this.defaultHighlightedNodeIds.add(e.id) : this.defaultHighlightedNodeIds.delete(e.id);
861
+ const o = this.highlightedNodeIds.has(e.id), n = this.resolveNodeDecoration?.(t), i = this.graph.findViewByCell(e)?.container, r = this.getNodeRingTarget(i), l = this.prevNodeDecorationClasses.get(e.id);
862
+ l && (i?.classList.remove(l), this.prevNodeDecorationClasses.delete(e.id)), n?.className && (i?.classList.add(n.className), this.prevNodeDecorationClasses.set(e.id, n.className));
863
+ const a = n?.borderColor, u = a ?? (o ? "#3a84ff" : void 0), g = this.prevNodeDecorationColors.has(e.id) || this.defaultHighlightedNodeIds.has(e.id);
864
+ u ? (e.setAttrByPath("body/stroke", u), e.setAttrByPath("body/strokeWidth", 2)) : g && (this.restoreNodeAttr(e, "body/stroke", "stroke"), this.restoreNodeAttr(e, "body/strokeWidth", "strokeWidth")), r && (r.classList.add(Lt), a ? (r.classList.add(Fe), r.style.setProperty("--flow-canvas-node-decoration-ring-background", a), r.style.setProperty("--flow-canvas-node-decoration-ring-opacity", "0.95")) : (r.classList.remove(Fe), r.style.removeProperty("--flow-canvas-node-decoration-ring-background"), r.style.removeProperty("--flow-canvas-node-decoration-ring-opacity")), o ? (r.classList.add(Ue), r.style.setProperty(
865
+ "--flow-canvas-node-pulse-ring-background",
866
+ a ?? Ot
867
+ ), r.style.setProperty("--flow-canvas-node-pulse-ring-opacity", "0.95")) : (r.classList.remove(Ue), r.style.removeProperty("--flow-canvas-node-pulse-ring-background"), r.style.removeProperty("--flow-canvas-node-pulse-ring-opacity"))), a ? this.prevNodeDecorationColors.add(e.id) : this.prevNodeDecorationColors.delete(e.id), o && !a ? this.defaultHighlightedNodeIds.add(e.id) : this.defaultHighlightedNodeIds.delete(e.id);
868
+ }
869
+ getHoveredEdgeId() {
870
+ return this.hoveredEdgeId;
818
871
  }
819
872
  setHoveredEdge(e) {
820
873
  this.hoveredEdgeId = e;
@@ -823,7 +876,8 @@ class At {
823
876
  this.highlightedNodeIds = new Set(e);
824
877
  }
825
878
  setHighlightedEdges(e) {
826
- this.highlightedEdgeIds = new Set(e);
879
+ const t = this.highlightedEdgeIds;
880
+ return this.highlightedEdgeIds = new Set(e), t;
827
881
  }
828
882
  /**
829
883
  * 单条边的 style + highlight + decoration 统一管道。
@@ -837,46 +891,53 @@ class At {
837
891
  * 最终值 = decorationStroke ?? styleStroke ?? defaultHighlightStroke ?? (清除)。
838
892
  */
839
893
  applyEdgeStyleAndDecoration(e, t, o) {
840
- const n = this.highlightedEdgeIds.has(e.id), r = this.resolveEdgeDecoration?.(t), i = this.prevEdgeDecorationClasses.get(e.id);
841
- i && (this.graph.findViewByCell(e)?.container?.classList.remove(i), this.prevEdgeDecorationClasses.delete(e.id)), r?.className && (this.graph.findViewByCell(e)?.container?.classList.add(r.className), this.prevEdgeDecorationClasses.set(e.id, r.className));
842
- let l, a, g;
894
+ const n = this.highlightedEdgeIds.has(e.id), i = this.resolveEdgeDecoration?.(t), r = this.prevEdgeDecorationClasses.get(e.id);
895
+ r && (this.graph.findViewByCell(e)?.container?.classList.remove(r), this.prevEdgeDecorationClasses.delete(e.id)), i?.className && (this.graph.findViewByCell(e)?.container?.classList.add(i.className), this.prevEdgeDecorationClasses.set(e.id, i.className));
896
+ let l, a, h;
843
897
  if (o?.style) {
844
- const E = this.graph.isSelected?.(e) ?? !1, w = this.hoveredEdgeId === e.id, N = o.style(t, { selected: E, highlighted: n, hovered: w });
845
- l = N.stroke, a = N.strokeWidth, g = N.strokeDasharray;
898
+ const m = this.graph.isSelected?.(e) ?? !1, k = this.hoveredEdgeId === e.id, S = o.style(t, { selected: m, highlighted: n, hovered: k });
899
+ l = S.stroke, a = S.strokeWidth, h = S.strokeDasharray;
846
900
  }
847
- const d = !o?.style && n ? "#3a84ff" : void 0, v = r?.strokeColor, f = v ?? l ?? d, p = !!o?.style || this.prevEdgeDecorationColors.has(e.id) || this.defaultHighlightedEdgeIds.has(e.id) || this.prevEdgeStyleIds.has(e.id);
848
- f ? e.setAttrByPath("line/stroke", f) : p && this.restoreEdgeAttr(e, "line/stroke", "stroke"), o?.style ? (this.prevEdgeStyleIds.add(e.id), a ? e.setAttrByPath("line/strokeWidth", a) : this.restoreEdgeAttr(e, "line/strokeWidth", "strokeWidth"), g ? e.setAttrByPath("line/strokeDasharray", g) : this.restoreEdgeAttr(e, "line/strokeDasharray", "strokeDasharray")) : this.prevEdgeStyleIds.has(e.id) && (this.restoreEdgeAttr(e, "line/strokeWidth", "strokeWidth"), this.restoreEdgeAttr(e, "line/strokeDasharray", "strokeDasharray"), this.prevEdgeStyleIds.delete(e.id)), v ? this.prevEdgeDecorationColors.add(e.id) : this.prevEdgeDecorationColors.delete(e.id), d ? this.defaultHighlightedEdgeIds.add(e.id) : this.defaultHighlightedEdgeIds.delete(e.id);
901
+ const u = !o?.style && n ? "#3a84ff" : void 0, g = i?.strokeColor, p = g ?? l ?? u, x = !!o?.style || this.prevEdgeDecorationColors.has(e.id) || this.defaultHighlightedEdgeIds.has(e.id) || this.prevEdgeStyleIds.has(e.id);
902
+ p ? this.setEdgeAttrIfChanged(e, "line/stroke", p) : x && this.restoreEdgeAttr(e, "line/stroke", "stroke"), o?.style ? (this.prevEdgeStyleIds.add(e.id), a ? this.setEdgeAttrIfChanged(e, "line/strokeWidth", a) : this.restoreEdgeAttr(e, "line/strokeWidth", "strokeWidth"), h ? this.setEdgeAttrIfChanged(e, "line/strokeDasharray", h) : this.restoreEdgeAttr(e, "line/strokeDasharray", "strokeDasharray")) : this.prevEdgeStyleIds.has(e.id) && (this.restoreEdgeAttr(e, "line/strokeWidth", "strokeWidth"), this.restoreEdgeAttr(e, "line/strokeDasharray", "strokeDasharray"), this.prevEdgeStyleIds.delete(e.id)), g ? this.prevEdgeDecorationColors.add(e.id) : this.prevEdgeDecorationColors.delete(e.id), u ? this.defaultHighlightedEdgeIds.add(e.id) : this.defaultHighlightedEdgeIds.delete(e.id);
849
903
  }
850
904
  }
851
- class Tt {
852
- instanceId = W();
905
+ class Bt {
906
+ instanceId = te();
853
907
  registeredShapes = /* @__PURE__ */ new Map();
908
+ wrappedComponents = /* @__PURE__ */ new Map();
854
909
  getShapeName(e) {
855
910
  let t = this.registeredShapes.get(e);
856
911
  return t || (t = `flow-node-${this.instanceId}-${e}`, this.registeredShapes.set(e, t)), t;
857
912
  }
858
913
  registerNodeType(e, t) {
859
914
  const o = this.getShapeName(e);
860
- return ft({
915
+ let n = this.wrappedComponents.get(e);
916
+ return n || (n = fe({
917
+ name: `FlowCanvasNodeShape${e.replace(/(^|[-_])(\w)/g, (i, r, l) => l.toUpperCase())}`,
918
+ setup() {
919
+ return () => Re("div", { class: "flow-canvas-node-surface" }, [Re(t)]);
920
+ }
921
+ }), this.wrappedComponents.set(e, n)), gt({
861
922
  shape: o,
862
- component: t,
923
+ component: n,
863
924
  width: 100,
864
925
  height: 40
865
926
  }), o;
866
927
  }
867
928
  dispose() {
868
- this.registeredShapes.clear();
929
+ this.registeredShapes.clear(), this.wrappedComponents.clear();
869
930
  }
870
931
  }
871
- class Rt {
932
+ class Ht {
872
933
  graph;
873
934
  onUiEvent;
874
935
  onCommand;
875
936
  flowModelRef;
876
937
  idGenerator;
877
938
  disposers = [];
878
- constructor(e, t, o, n, r) {
879
- this.graph = e, this.onUiEvent = t, this.onCommand = o, this.flowModelRef = n, this.idGenerator = r ?? He, this.bindEvents();
939
+ constructor(e, t, o, n, i) {
940
+ this.graph = e, this.onUiEvent = t, this.onCommand = o, this.flowModelRef = n, this.idGenerator = i ?? Ge, this.bindEvents();
880
941
  }
881
942
  dispose() {
882
943
  for (const e of this.disposers) e();
@@ -896,11 +957,11 @@ class Rt {
896
957
  }), this.on("edge:click", ({ edge: e, e: t }) => {
897
958
  const n = t.target?.closest?.(".x6-edge-label");
898
959
  if (n) {
899
- const i = e.getData?.()?.labels ?? [], l = n.parentElement?.querySelectorAll(".x6-edge-label"), a = l ? Array.from(l).indexOf(n) : 0, g = i[Math.max(0, a)];
960
+ const r = e.getData?.()?.labels ?? [], l = n.parentElement?.querySelectorAll(".x6-edge-label"), a = l ? Array.from(l).indexOf(n) : 0, h = r[Math.max(0, a)];
900
961
  this.onUiEvent({
901
962
  type: "edge.label.click",
902
963
  edgeId: e.id,
903
- labelId: g?.id ?? `label-${a}`
964
+ labelId: h?.id ?? `label-${a}`
904
965
  });
905
966
  return;
906
967
  }
@@ -916,7 +977,7 @@ class Rt {
916
977
  }), this.on("node:moved", ({ node: e }) => {
917
978
  const t = e.getPosition();
918
979
  this.onCommand({
919
- id: W(),
980
+ id: te(),
920
981
  source: "user:drag",
921
982
  label: "移动节点",
922
983
  timestamp: Date.now(),
@@ -925,9 +986,9 @@ class Rt {
925
986
  }), this.on("edge:connected", ({ edge: e, isNew: t }) => {
926
987
  const o = e.getSourceCell(), n = e.getTargetCell();
927
988
  if (!o || !n) return;
928
- const r = e.getSourcePortId(), i = e.getTargetPortId(), l = e.id in this.flowModelRef.value.edges;
989
+ const i = e.getSourcePortId(), r = e.getTargetPortId(), l = e.id in this.flowModelRef.value.edges;
929
990
  t && !l ? (this.graph.removeCell(e), this.onCommand({
930
- id: W(),
991
+ id: te(),
931
992
  source: "user:drag",
932
993
  label: "连线",
933
994
  timestamp: Date.now(),
@@ -936,13 +997,13 @@ class Rt {
936
997
  type: "edge.add",
937
998
  edge: {
938
999
  id: this.idGenerator("edge"),
939
- source: { nodeId: o.id, portId: r ?? void 0 },
940
- target: { nodeId: n.id, portId: i ?? void 0 }
1000
+ source: { nodeId: o.id, portId: i ?? void 0 },
1001
+ target: { nodeId: n.id, portId: r ?? void 0 }
941
1002
  }
942
1003
  }
943
1004
  ]
944
1005
  })) : this.onCommand({
945
- id: W(),
1006
+ id: te(),
946
1007
  source: "user:drag",
947
1008
  label: "重连",
948
1009
  timestamp: Date.now(),
@@ -950,32 +1011,32 @@ class Rt {
950
1011
  {
951
1012
  type: "edge.reconnect",
952
1013
  edgeId: e.id,
953
- source: { nodeId: o.id, portId: r ?? void 0 },
954
- target: { nodeId: n.id, portId: i ?? void 0 }
1014
+ source: { nodeId: o.id, portId: i ?? void 0 },
1015
+ target: { nodeId: n.id, portId: r ?? void 0 }
955
1016
  }
956
1017
  ]
957
1018
  });
958
1019
  }), this.on("edge:change:labels", ({ edge: e, current: t }) => {
959
1020
  const n = e.getData?.()?.labels ?? [];
960
1021
  if (!n.length || !t?.length) return;
961
- const r = [];
962
- for (let i = 0; i < Math.min(n.length, t.length); i++) {
963
- const l = t[i], a = n[i];
1022
+ const i = [];
1023
+ for (let r = 0; r < Math.min(n.length, t.length); r++) {
1024
+ const l = t[r], a = n[r];
964
1025
  if (!a?.id) continue;
965
- const g = typeof l.position == "object" ? l.position?.distance : l.position;
966
- g != null && r.push({
1026
+ const h = typeof l.position == "object" ? l.position?.distance : l.position;
1027
+ h != null && i.push({
967
1028
  type: "edge.label.update",
968
1029
  edgeId: e.id,
969
1030
  labelId: a.id,
970
- patch: { position: g }
1031
+ patch: { position: h }
971
1032
  });
972
1033
  }
973
- r.length && this.onCommand({
974
- id: W(),
1034
+ i.length && this.onCommand({
1035
+ id: te(),
975
1036
  source: "user:drag",
976
1037
  label: "拖动标签",
977
1038
  timestamp: Date.now(),
978
- commands: r
1039
+ commands: i
979
1040
  });
980
1041
  });
981
1042
  }
@@ -983,122 +1044,155 @@ class Rt {
983
1044
  this.graph.on(e, t), this.disposers.push(() => this.graph.off(e, t));
984
1045
  }
985
1046
  }
986
- function $t(s) {
1047
+ function Gt(s) {
987
1048
  function e(t) {
988
1049
  const o = s.getCellById(t);
989
1050
  if (!o || !o.isNode()) return null;
990
- const n = o, r = n.getPosition(), i = n.getSize(), l = { x: r.x, y: r.y, width: i.width, height: i.height }, a = s.localToGraph(l);
1051
+ const n = o, i = n.getPosition(), r = n.getSize(), l = { x: i.x, y: i.y, width: r.width, height: r.height }, a = s.localToGraph(l);
991
1052
  return new DOMRect(a.x, a.y, a.width, a.height);
992
1053
  }
993
1054
  return {
994
1055
  getNodeScreenRect: e
995
1056
  };
996
1057
  }
997
- const Lt = 100;
998
- function Bt({
1058
+ function st(s) {
1059
+ return {
1060
+ nodeIds: s.filter((e) => e.isNode()).map((e) => e.id),
1061
+ edgeIds: s.filter((e) => e.isEdge()).map((e) => e.id)
1062
+ };
1063
+ }
1064
+ function qt(s, e) {
1065
+ const t = [
1066
+ ...e.nodeIds.map((i) => s.getCellById(i)),
1067
+ ...e.edgeIds.map((i) => s.getCellById(i))
1068
+ ].filter((i) => !!i);
1069
+ if (t.length === 0) return null;
1070
+ const o = s.getCellsBBox(t);
1071
+ if (!o) return null;
1072
+ const n = s.localToGraph(o);
1073
+ return new DOMRect(n.x, n.y, n.width, n.height);
1074
+ }
1075
+ function it(s, e, t) {
1076
+ const o = s.nodeIds.filter((r) => {
1077
+ const l = e.nodes[r];
1078
+ if (!l) return !1;
1079
+ const a = t(l);
1080
+ return a.deletable !== !1 && a.deleteDisabled !== !0;
1081
+ }), n = new Set(o), i = s.edgeIds.filter((r) => {
1082
+ const l = e.edges[r];
1083
+ return l ? !n.has(l.source.nodeId) && !n.has(l.target.nodeId) : !1;
1084
+ });
1085
+ return { nodeIds: o, edgeIds: i };
1086
+ }
1087
+ function Ft(s) {
1088
+ return [
1089
+ ...s.edgeIds.map((e) => ({ type: "edge.remove", edgeId: e })),
1090
+ ...s.nodeIds.map((e) => ({ type: "node.remove", nodeId: e }))
1091
+ ];
1092
+ }
1093
+ const Ut = 100;
1094
+ function zt({
999
1095
  graph: s,
1000
1096
  overlayManager: e,
1001
1097
  executeCommand: t,
1002
1098
  schema: o,
1003
1099
  flowModel: n,
1100
+ getNodeBehavior: i,
1004
1101
  idGenerator: r,
1005
- defaultInsertGap: i,
1006
- getContextMenuItems: l,
1007
- onHighlightChange: a,
1008
- resolveNodeShape: g
1102
+ defaultInsertGap: l,
1103
+ getContextMenuItems: a,
1104
+ onHighlightChange: h,
1105
+ resolveNodeShape: u
1009
1106
  }) {
1010
- const d = r ?? He;
1011
- let v = [], f = [], p = null, E = !1, w = null, N = !1;
1012
- async function m() {
1013
- if (E) return p;
1014
- E = !0;
1107
+ const g = r ?? Ge;
1108
+ let p = [], x = [], m = null, k = !1, S = null;
1109
+ async function T() {
1110
+ if (k) return m;
1111
+ k = !0;
1015
1112
  try {
1016
- const h = await import("@antv/x6-plugin-dnd"), b = h.Dnd ?? h.default;
1017
- return b ? (p = new b({
1113
+ const f = await import("@antv/x6-plugin-dnd"), d = f.Dnd ?? f.default;
1114
+ return d ? (m = new d({
1018
1115
  target: s,
1019
1116
  scaled: !0,
1020
1117
  animation: !0,
1021
- getDragNode: (C) => C.clone(),
1022
- getDropNode: (C) => C.clone()
1023
- }), p) : null;
1118
+ getDragNode: (c) => c.clone(),
1119
+ getDropNode: (c) => c.clone()
1120
+ }), m) : null;
1024
1121
  } catch {
1025
1122
  return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"), null;
1026
1123
  }
1027
1124
  }
1028
- async function D() {
1029
- if (!N) {
1030
- N = !0;
1031
- try {
1032
- const h = await import("@antv/x6-plugin-export"), b = h.Export ?? h.default;
1033
- b && s.use(new b());
1034
- } catch {
1035
- console.warn("[flow-canvas] @antv/x6-plugin-export not available, add it to your dependencies");
1036
- }
1037
- }
1125
+ function P() {
1126
+ return new Promise((f) => {
1127
+ requestAnimationFrame(() => requestAnimationFrame(() => f()));
1128
+ });
1038
1129
  }
1039
- const z = ({ node: h }) => {
1040
- const b = h.getData?.();
1041
- if (!b?._dndSessionId || b._dndSessionId !== w) return;
1042
- w = null;
1043
- const C = h.getPosition();
1044
- s.removeNode(h.id);
1045
- const { _dndSessionId: L, ...R } = b, q = R.id || d("node");
1130
+ const G = ({ node: f }) => {
1131
+ const d = f.getData?.();
1132
+ if (!d?._dndSessionId || d._dndSessionId !== S) return;
1133
+ S = null;
1134
+ const c = f.getPosition();
1135
+ s.removeNode(f.id);
1136
+ const { _dndSessionId: v, ...b } = d, E = b.id || g("node");
1046
1137
  t({
1047
- id: W(),
1138
+ id: te(),
1048
1139
  source: "user:drag",
1049
1140
  label: "拖入节点",
1050
1141
  timestamp: Date.now(),
1051
1142
  commands: [
1052
1143
  {
1053
1144
  type: "node.add",
1054
- node: { ...R, id: q, position: { x: C.x, y: C.y } }
1145
+ node: { ...b, id: E, position: { x: c.x, y: c.y } }
1055
1146
  }
1056
1147
  ]
1057
1148
  });
1058
1149
  };
1059
- s.on("node:added", z);
1060
- function X(h) {
1061
- const b = o.nodeTypes[h.type];
1062
- return Fe(h, b?.getPorts);
1150
+ s.on("node:added", G);
1151
+ function K(f) {
1152
+ const d = o.nodeTypes[f.type];
1153
+ return qe(f, d?.getPorts);
1154
+ }
1155
+ function O(f) {
1156
+ return f ?? st(s.getSelectedCells?.() ?? []);
1063
1157
  }
1064
- function j(h, b, C, L, R) {
1065
- switch (h) {
1158
+ function W(f, d, c, v, b) {
1159
+ switch (f) {
1066
1160
  case "left":
1067
1161
  return {
1068
- x: b.position.x - R - L.width,
1069
- y: b.position.y + (C.height - L.height) / 2
1162
+ x: d.position.x - b - v.width,
1163
+ y: d.position.y + (c.height - v.height) / 2
1070
1164
  };
1071
1165
  case "top":
1072
1166
  return {
1073
- x: b.position.x + (C.width - L.width) / 2,
1074
- y: b.position.y - R - L.height
1167
+ x: d.position.x + (c.width - v.width) / 2,
1168
+ y: d.position.y - b - v.height
1075
1169
  };
1076
1170
  case "bottom":
1077
1171
  return {
1078
- x: b.position.x + (C.width - L.width) / 2,
1079
- y: b.position.y + C.height + R
1172
+ x: d.position.x + (c.width - v.width) / 2,
1173
+ y: d.position.y + c.height + b
1080
1174
  };
1081
1175
  default:
1082
1176
  return {
1083
- x: b.position.x + C.width + R,
1084
- y: b.position.y + (C.height - L.height) / 2
1177
+ x: d.position.x + c.width + b,
1178
+ y: d.position.y + (c.height - v.height) / 2
1085
1179
  };
1086
1180
  }
1087
1181
  }
1088
- function oe(h, b, C) {
1089
- switch (h) {
1182
+ function z(f, d, c) {
1183
+ switch (f) {
1090
1184
  case "left":
1091
- return { x: -(b.width + C), y: 0 };
1185
+ return { x: -(d.width + c), y: 0 };
1092
1186
  case "top":
1093
- return { x: 0, y: -(b.height + C) };
1187
+ return { x: 0, y: -(d.height + c) };
1094
1188
  case "bottom":
1095
- return { x: 0, y: b.height + C };
1189
+ return { x: 0, y: d.height + c };
1096
1190
  default:
1097
- return { x: b.width + C, y: 0 };
1191
+ return { x: d.width + c, y: 0 };
1098
1192
  }
1099
1193
  }
1100
- function G(h) {
1101
- switch (h) {
1194
+ function M(f) {
1195
+ switch (f) {
1102
1196
  case "left":
1103
1197
  return "right";
1104
1198
  case "top":
@@ -1109,15 +1203,15 @@ function Bt({
1109
1203
  return "left";
1110
1204
  }
1111
1205
  }
1112
- return {
1206
+ const y = {
1113
1207
  zoomIn() {
1114
1208
  s.zoom(0.1);
1115
1209
  },
1116
1210
  zoomOut() {
1117
1211
  s.zoom(-0.1);
1118
1212
  },
1119
- zoomTo(h) {
1120
- s.zoomTo(h);
1213
+ zoomTo(f) {
1214
+ s.zoomTo(f);
1121
1215
  },
1122
1216
  zoomToFit() {
1123
1217
  s.zoomToFit({ padding: 40, maxScale: 1.5 });
@@ -1131,233 +1225,252 @@ function Bt({
1131
1225
  scrollToOrigin() {
1132
1226
  s.translate(0, 0);
1133
1227
  },
1134
- scrollToNode(h) {
1135
- const b = s.getCellById(h);
1136
- b && s.centerCell(b);
1228
+ scrollToNode(f) {
1229
+ const d = s.getCellById(f);
1230
+ d && s.centerCell(d);
1137
1231
  },
1138
1232
  getSelection() {
1139
- const h = s.getSelectedCells?.() ?? [];
1140
- return {
1141
- nodeIds: h.filter((b) => b.isNode()).map((b) => b.id),
1142
- edgeIds: h.filter((b) => b.isEdge()).map((b) => b.id)
1143
- };
1233
+ return O();
1144
1234
  },
1145
- selectNodes(h) {
1146
- const b = h.map((C) => s.getCellById(C)).filter(Boolean);
1147
- s.select?.(b);
1235
+ getSelectionBounds(f) {
1236
+ return qt(s, O(f));
1148
1237
  },
1149
- selectEdges(h) {
1150
- const b = h.map((C) => s.getCellById(C)).filter(Boolean);
1151
- s.select?.(b);
1238
+ selectNodes(f) {
1239
+ const d = f.map((c) => s.getCellById(c)).filter(Boolean);
1240
+ s.select?.(d);
1241
+ },
1242
+ selectEdges(f) {
1243
+ const d = f.map((c) => s.getCellById(c)).filter(Boolean);
1244
+ s.select?.(d);
1152
1245
  },
1153
1246
  clearSelection() {
1154
- const h = s.getSelectedCells?.();
1155
- h?.length && s.unselect?.(h);
1247
+ const f = s.getSelectedCells?.();
1248
+ f?.length && s.unselect?.(f);
1249
+ },
1250
+ deleteSelection(f) {
1251
+ const d = O(f?.selection), c = it(d, n.value, i ?? (() => ({}))), v = Ft(c);
1252
+ if (v.length === 0) return null;
1253
+ const b = t({
1254
+ id: te(),
1255
+ source: f?.source ?? "user:toolbar",
1256
+ label: f?.label ?? "删除选中",
1257
+ timestamp: Date.now(),
1258
+ commands: v
1259
+ });
1260
+ return b.status === "applied" && f?.clearSelectionAfterApply !== !1 && y.clearSelection(), b;
1156
1261
  },
1157
- registerDndSource(h, b) {
1158
- const C = async (L) => {
1159
- const R = await m();
1160
- if (!R) return;
1161
- const q = W();
1162
- w = q;
1163
- const Y = b(), H = g?.(Y.type), Q = s.createNode({
1164
- width: H?.width ?? 154,
1165
- height: H?.height ?? 54,
1166
- shape: H?.shapeName ?? "rect",
1167
- data: { ...Y, _dndSessionId: q }
1262
+ registerDndSource(f, d) {
1263
+ const c = async (v) => {
1264
+ const b = await T();
1265
+ if (!b) return;
1266
+ const E = te();
1267
+ S = E;
1268
+ const B = d(), X = u?.(B.type), C = s.createNode({
1269
+ width: X?.width ?? 154,
1270
+ height: X?.height ?? 54,
1271
+ shape: X?.shapeName ?? "rect",
1272
+ data: { ...B, _dndSessionId: E }
1168
1273
  });
1169
- R.start(Q, L);
1274
+ b.start(C, v);
1170
1275
  };
1171
- return h.addEventListener("mousedown", C), () => {
1172
- h.removeEventListener("mousedown", C);
1276
+ return f.addEventListener("mousedown", c), () => {
1277
+ f.removeEventListener("mousedown", c);
1173
1278
  };
1174
1279
  },
1175
1280
  /**
1176
1281
  * 通过编程方式发起连线:直接命中真实 port 元素,
1177
1282
  * 复用 X6 原生的连线拖拽流程与 connecting.createEdge 配置。
1178
1283
  */
1179
- startConnection(h, b) {
1180
- const C = s.getCellById(h);
1181
- if (!C?.isNode()) return;
1182
- const L = C, R = s.findViewByCell(L);
1183
- if (!R) return;
1184
- const q = R.findPortElem(b, "circle") ?? R.findPortElem(b);
1185
- if (!q) return;
1186
- const H = (q.matches?.("[magnet]") ? q : q.querySelector?.("[magnet]")) ?? q, Q = H.getBoundingClientRect(), de = Q.left + Q.width / 2, re = Q.top + Q.height / 2, ce = new MouseEvent("mousedown", {
1187
- clientX: de,
1188
- clientY: re,
1284
+ startConnection(f, d) {
1285
+ const c = s.getCellById(f);
1286
+ if (!c?.isNode()) return;
1287
+ const v = c, b = s.findViewByCell(v);
1288
+ if (!b) return;
1289
+ const E = b.findPortElem(d, "circle") ?? b.findPortElem(d);
1290
+ if (!E) return;
1291
+ const X = (E.matches?.("[magnet]") ? E : E.querySelector?.("[magnet]")) ?? E, C = X.getBoundingClientRect(), L = C.left + C.width / 2, w = C.top + C.height / 2, A = new MouseEvent("mousedown", {
1292
+ clientX: L,
1293
+ clientY: w,
1189
1294
  button: 0,
1190
1295
  buttons: 1,
1191
1296
  bubbles: !0,
1192
1297
  cancelable: !0
1193
1298
  });
1194
- H.dispatchEvent(ce);
1299
+ X.dispatchEvent(A);
1195
1300
  },
1196
- async exportAsImage(h) {
1197
- await D();
1198
- const b = s;
1199
- return typeof b.toPNG != "function" ? (console.warn("[flow-canvas] exportAsImage requires @antv/x6-plugin-export, add it to your dependencies"), new Blob()) : new Promise((C) => {
1200
- b.toPNG(
1201
- (L) => {
1202
- fetch(L).then((R) => R.blob()).then(C).catch(() => C(new Blob()));
1203
- },
1204
- {
1205
- backgroundColor: h?.backgroundColor ?? "#ffffff",
1206
- padding: h?.padding ?? 20,
1207
- quality: h?.quality,
1208
- copyStyles: !0
1301
+ async exportAsImage(f) {
1302
+ const { domToBlob: d } = await import("modern-screenshot"), c = f?.padding ?? 20, v = f?.backgroundColor ?? s.options.background?.color ?? "#ffffff", b = s.zoom(), E = s.translate(), B = s.getContentBBox(), X = B.width / b, C = B.height / b;
1303
+ if (X === 0 || C === 0)
1304
+ return new Blob();
1305
+ const L = (B.x - E.tx) / b, w = (B.y - E.ty) / b, A = Math.ceil(X + c * 2), H = Math.ceil(C + c * 2), Z = document.createElement("div");
1306
+ Z.style.cssText = "position:fixed;left:-99999px;top:0;pointer-events:none;";
1307
+ const V = s.container.cloneNode(!0);
1308
+ V.style.width = `${A}px`, V.style.height = `${H}px`, V.style.overflow = "visible";
1309
+ const ee = V.querySelector("svg");
1310
+ ee && (ee.setAttribute("width", String(A)), ee.setAttribute("height", String(H)), ee.style.width = `${A}px`, ee.style.height = `${H}px`), V.querySelector(".x6-graph-svg-viewport")?.setAttribute("transform", `matrix(1,0,0,1,${-L + c},${-w + c})`), Z.appendChild(V), document.body.appendChild(Z);
1311
+ try {
1312
+ return await P(), await d(V, {
1313
+ width: A,
1314
+ height: H,
1315
+ backgroundColor: v,
1316
+ scale: f?.scale ?? window.devicePixelRatio,
1317
+ filter: (oe) => {
1318
+ if (oe instanceof Element) {
1319
+ const ie = oe.getAttribute("class") ?? "";
1320
+ if (ie.includes("x6-widget-selection") || ie.includes("x6-widget-transform") || ie.includes("x6-graph-grid") || ie.includes("x6-graph-background"))
1321
+ return !1;
1322
+ }
1323
+ return !0;
1209
1324
  }
1210
- );
1211
- });
1212
- },
1213
- async exportAsSVG() {
1214
- await D();
1215
- const h = s;
1216
- return typeof h.toSVG != "function" ? (console.warn("[flow-canvas] exportAsSVG requires @antv/x6-plugin-export, add it to your dependencies"), "") : new Promise((b) => {
1217
- h.toSVG((C) => b(C));
1218
- });
1325
+ });
1326
+ } catch (oe) {
1327
+ return console.warn("[flow-canvas] Export failed:", oe), new Blob();
1328
+ } finally {
1329
+ Z.remove();
1330
+ }
1219
1331
  },
1220
- highlightNodes(h) {
1221
- v = h, a?.(v, f);
1332
+ highlightNodes(f) {
1333
+ p = f, h?.(p, x);
1222
1334
  },
1223
- highlightEdges(h) {
1224
- f = h, a?.(v, f);
1335
+ highlightEdges(f) {
1336
+ x = f, h?.(p, x);
1225
1337
  },
1226
1338
  clearHighlight() {
1227
- v = [], f = [], a?.([], []);
1339
+ p = [], x = [], h?.([], []);
1228
1340
  },
1229
1341
  overlay: e,
1230
- getContextMenuItems(h) {
1231
- return l?.(h) ?? [];
1342
+ getContextMenuItems(f) {
1343
+ return a?.(f) ?? [];
1232
1344
  },
1233
- insertNodeToRight(h, b, C) {
1234
- const L = n.value, R = L.nodes[h];
1235
- if (!R)
1345
+ insertNodeToRight(f, d, c) {
1346
+ const v = n.value, b = v.nodes[f];
1347
+ if (!b)
1236
1348
  return {
1237
1349
  status: "invalid",
1238
1350
  envelope: { id: "", source: "user:toolbar", timestamp: Date.now(), commands: [] },
1239
- error: { code: "constraint_violated", reason: `Source node "${h}" not found`, source: "api" }
1351
+ error: { code: "constraint_violated", reason: `Source node "${f}" not found`, source: "api" }
1240
1352
  };
1241
- const q = C?.gap ?? i ?? Lt, Y = C?.direction ?? "right", H = o.nodeTypes[R.type], Q = o.nodeTypes[b.type], de = H?.getSize(R) ?? { width: 154, height: 54 }, re = Q?.getSize({ ...b, position: { x: 0, y: 0 } }) ?? {
1353
+ const E = c?.gap ?? l ?? Ut, B = c?.direction ?? "right", X = o.nodeTypes[b.type], C = o.nodeTypes[d.type], L = X?.getSize(b) ?? { width: 154, height: 54 }, w = C?.getSize({ ...d, position: { x: 0, y: 0 } }) ?? {
1242
1354
  width: 154,
1243
1355
  height: 54
1244
- }, ce = j(Y, R, de, re, q), ue = b.id || d("node"), Ie = { ...b, id: ue, position: ce }, se = [{ type: "node.add", node: Ie }], Me = oe(Y, re, q), ie = { x: ce.x, y: ce.y, width: re.width, height: re.height };
1245
- for (const [ae, Z] of Object.entries(L.nodes)) {
1246
- if (ae === h || ae === ue) continue;
1247
- const ve = o.nodeTypes[Z.type]?.getSize(Z) ?? { width: 154, height: 54 }, te = ie.x < Z.position.x + ve.width && ie.x + ie.width > Z.position.x, ye = ie.y < Z.position.y + ve.height && ie.y + ie.height > Z.position.y;
1248
- te && ye && se.push({
1356
+ }, A = W(B, b, L, w, E), H = d.id || g("node"), Z = { ...d, id: H, position: A }, V = [{ type: "node.add", node: Z }], ee = z(B, w, E), Q = { x: A.x, y: A.y, width: w.width, height: w.height };
1357
+ for (const [ie, ne] of Object.entries(v.nodes)) {
1358
+ if (ie === f || ie === H) continue;
1359
+ const I = o.nodeTypes[ne.type]?.getSize(ne) ?? { width: 154, height: 54 }, _ = Q.x < ne.position.x + I.width && Q.x + Q.width > ne.position.x, F = Q.y < ne.position.y + I.height && Q.y + Q.height > ne.position.y;
1360
+ _ && F && V.push({
1249
1361
  type: "node.move",
1250
- nodeId: ae,
1251
- position: { x: Z.position.x + Me.x, y: Z.position.y + Me.y }
1362
+ nodeId: ie,
1363
+ position: { x: ne.position.x + ee.x, y: ne.position.y + ee.y }
1252
1364
  });
1253
1365
  }
1254
- if (C?.autoWireEdges) {
1255
- const ae = X(R), Z = X(Ie), we = Y, ve = G(Y), te = ae.find((K) => K.group === we), ye = Z.find((K) => K.group === ve), Ne = Z.find((K) => K.group === we), xe = te ? Object.values(L.edges).find(
1256
- (K) => K.source.nodeId === h && K.source.portId === te.id
1257
- ) : Object.values(L.edges).find((K) => K.source.nodeId === h);
1258
- if (xe) {
1259
- const K = xe.target;
1260
- se.push({ type: "edge.remove", edgeId: xe.id }), se.push({
1366
+ if (c?.autoWireEdges) {
1367
+ const ie = K(b), ne = K(Z), N = B, I = M(B), _ = ie.find((J) => J.group === N), F = ne.find((J) => J.group === I), ae = ne.find((J) => J.group === N), de = _ ? Object.values(v.edges).find(
1368
+ (J) => J.source.nodeId === f && J.source.portId === _.id
1369
+ ) : Object.values(v.edges).find((J) => J.source.nodeId === f);
1370
+ if (de) {
1371
+ const J = de.target;
1372
+ V.push({ type: "edge.remove", edgeId: de.id }), V.push({
1261
1373
  type: "edge.add",
1262
1374
  edge: {
1263
- id: d("edge"),
1264
- source: { nodeId: h, portId: te?.id },
1265
- target: { nodeId: ue, portId: ye?.id }
1375
+ id: g("edge"),
1376
+ source: { nodeId: f, portId: _?.id },
1377
+ target: { nodeId: H, portId: F?.id }
1266
1378
  }
1267
- }), se.push({
1379
+ }), V.push({
1268
1380
  type: "edge.add",
1269
1381
  edge: {
1270
- id: d("edge"),
1271
- source: { nodeId: ue, portId: Ne?.id },
1272
- target: K
1382
+ id: g("edge"),
1383
+ source: { nodeId: H, portId: ae?.id },
1384
+ target: J
1273
1385
  }
1274
1386
  });
1275
1387
  } else
1276
- se.push({
1388
+ V.push({
1277
1389
  type: "edge.add",
1278
1390
  edge: {
1279
- id: d("edge"),
1280
- source: { nodeId: h, portId: te?.id },
1281
- target: { nodeId: ue, portId: ye?.id }
1391
+ id: g("edge"),
1392
+ source: { nodeId: f, portId: _?.id },
1393
+ target: { nodeId: H, portId: F?.id }
1282
1394
  }
1283
1395
  });
1284
1396
  }
1285
- const $e = {
1286
- id: W(),
1287
- source: C?.source ?? "user:toolbar",
1288
- label: C?.label ?? "插入节点",
1397
+ const oe = {
1398
+ id: te(),
1399
+ source: c?.source ?? "user:toolbar",
1400
+ label: c?.label ?? "插入节点",
1289
1401
  timestamp: Date.now(),
1290
- commands: se
1402
+ commands: V
1291
1403
  };
1292
- return t($e);
1404
+ return t(oe);
1293
1405
  },
1294
- onGraphEvent(h, b) {
1295
- return s.on(h, b), () => s.off(h, b);
1406
+ onGraphEvent(f, d) {
1407
+ return s.on(f, d), () => s.off(f, d);
1296
1408
  },
1297
1409
  unsafeGetGraph() {
1298
1410
  return s;
1299
1411
  }
1300
1412
  };
1413
+ return y;
1301
1414
  }
1302
- function Ot() {
1303
- const s = O(null), e = O(!1);
1415
+ function jt() {
1416
+ const s = q(null), e = q(!1);
1304
1417
  let t = null, o = !1;
1305
- function n(v) {
1306
- t && (clearTimeout(t), t = null), s.value = v;
1418
+ function n(g) {
1419
+ t && (clearTimeout(t), t = null), s.value = g;
1307
1420
  }
1308
- function r(v = 100) {
1421
+ function i(g = 100) {
1309
1422
  o || (t && clearTimeout(t), t = setTimeout(() => {
1310
1423
  s.value = null, t = null;
1311
- }, v));
1424
+ }, g));
1312
1425
  }
1313
- function i() {
1426
+ function r() {
1314
1427
  o = !0, t && (clearTimeout(t), t = null);
1315
1428
  }
1316
- function l(v = 100) {
1317
- o = !1, r(v);
1429
+ function l(g = 100) {
1430
+ o = !1, i(g);
1318
1431
  }
1319
1432
  function a() {
1320
1433
  t && (clearTimeout(t), t = null);
1321
1434
  }
1322
- function g() {
1435
+ function h() {
1323
1436
  a(), o = !1, s.value = null;
1324
1437
  }
1325
- function d() {
1438
+ function u() {
1326
1439
  t && clearTimeout(t);
1327
1440
  }
1328
- return { hoveredNodeId: s, isDraggingNode: e, enter: n, leave: r, enterOverlay: i, leaveOverlay: l, cancelLeave: a, reset: g, cleanup: d };
1441
+ return { hoveredNodeId: s, isDraggingNode: e, enter: n, leave: i, enterOverlay: r, leaveOverlay: l, cancelLeave: a, reset: h, cleanup: u };
1329
1442
  }
1330
- const We = 10, Se = 12;
1331
- function Qe(s, e) {
1443
+ const ze = 10, Se = 12;
1444
+ function je(s, e) {
1332
1445
  const t = s.getTotalLength();
1333
1446
  if (t === 0) return { ...e, length: 0, totalLength: 0 };
1334
1447
  let o = s.getPointAtLength(0), n = 1 / 0;
1335
- const r = 50, i = t / r;
1448
+ const i = 50, r = t / i;
1336
1449
  let l = 0;
1337
- for (let v = 0; v <= r; v++) {
1338
- const f = v * i, p = s.getPointAtLength(f), E = (p.x - e.x) ** 2 + (p.y - e.y) ** 2;
1339
- E < n && (n = E, o = p, l = f);
1450
+ for (let g = 0; g <= i; g++) {
1451
+ const p = g * r, x = s.getPointAtLength(p), m = (x.x - e.x) ** 2 + (x.y - e.y) ** 2;
1452
+ m < n && (n = m, o = x, l = p);
1340
1453
  }
1341
- const a = Math.max(0, l - i), g = Math.min(t, l + i), d = (g - a) / 20;
1342
- for (let v = a; v <= g; v += d) {
1343
- const f = s.getPointAtLength(v), p = (f.x - e.x) ** 2 + (f.y - e.y) ** 2;
1344
- p < n && (n = p, o = f, l = v);
1454
+ const a = Math.max(0, l - r), h = Math.min(t, l + r), u = (h - a) / 20;
1455
+ for (let g = a; g <= h; g += u) {
1456
+ const p = s.getPointAtLength(g), x = (p.x - e.x) ** 2 + (p.y - e.y) ** 2;
1457
+ x < n && (n = x, o = p, l = g);
1345
1458
  }
1346
1459
  return { x: o.x, y: o.y, length: l, totalLength: t };
1347
1460
  }
1348
- function Xe(s, e) {
1349
- return s < We || s > e - We;
1461
+ function We(s, e) {
1462
+ return s < ze || s > e - ze;
1350
1463
  }
1351
- function Ye(s, e, t) {
1464
+ function Ve(s, e, t) {
1352
1465
  const o = s.querySelectorAll(".x6-edge-label");
1353
1466
  for (const n of o) {
1354
- const r = n.getBoundingClientRect();
1355
- if (e >= r.left - Se && e <= r.right + Se && t >= r.top - Se && t <= r.bottom + Se)
1467
+ const i = n.getBoundingClientRect();
1468
+ if (e >= i.left - Se && e <= i.right + Se && t >= i.top - Se && t <= i.bottom + Se)
1356
1469
  return !0;
1357
1470
  }
1358
1471
  return !1;
1359
1472
  }
1360
- function Ke() {
1473
+ function Xe() {
1361
1474
  const s = "http://www.w3.org/2000/svg", e = document.createElementNS(s, "g");
1362
1475
  e.setAttribute("class", "flow-canvas-edge-delete-tool"), e.style.cursor = "pointer";
1363
1476
  const t = document.createElementNS(s, "rect");
@@ -1365,20 +1478,20 @@ function Ke() {
1365
1478
  const o = document.createElementNS(s, "text");
1366
1479
  return o.setAttribute("font-family", "flow-canvas"), o.setAttribute("font-size", "16"), o.setAttribute("fill", "#ffffff"), o.setAttribute("text-anchor", "middle"), o.setAttribute("dominant-baseline", "central"), o.textContent = "", e.appendChild(o), e;
1367
1480
  }
1368
- function Gt(s) {
1481
+ function Wt(s) {
1369
1482
  let e = null, t = null;
1370
1483
  function o(l, a) {
1371
- if (r(), t = l, a.target?.closest?.(".x6-edge-label")) return;
1372
- const d = s.getCellById(l);
1373
- if (!d?.isEdge()) return;
1374
- const v = s.findViewByCell(d);
1375
- if (!v) return;
1376
- const f = v.container.querySelector("path");
1377
- if (!f) return;
1378
- const p = s.clientToLocal(a.clientX, a.clientY), E = Qe(f, p);
1379
- if (Xe(E.length, E.totalLength) || Ye(v.container, a.clientX, a.clientY)) return;
1380
- const w = Ke();
1381
- w.setAttribute("transform", `translate(${E.x}, ${E.y})`), v.container.appendChild(w), e = w;
1484
+ if (i(), t = l, a.target?.closest?.(".x6-edge-label")) return;
1485
+ const u = s.getCellById(l);
1486
+ if (!u?.isEdge()) return;
1487
+ const g = s.findViewByCell(u);
1488
+ if (!g) return;
1489
+ const p = g.container.querySelector("path");
1490
+ if (!p) return;
1491
+ const x = s.clientToLocal(a.clientX, a.clientY), m = je(p, x);
1492
+ if (We(m.length, m.totalLength) || Ve(g.container, a.clientX, a.clientY)) return;
1493
+ const k = Xe();
1494
+ k.setAttribute("transform", `translate(${m.x}, ${m.y})`), g.container.appendChild(k), e = k;
1382
1495
  }
1383
1496
  function n(l) {
1384
1497
  if (!t) return;
@@ -1386,55 +1499,55 @@ function Gt(s) {
1386
1499
  e && e.setAttribute("display", "none");
1387
1500
  return;
1388
1501
  }
1389
- const g = s.getCellById(t);
1390
- if (!g?.isEdge()) return;
1391
- const d = s.findViewByCell(g);
1392
- if (!d) return;
1393
- const v = d.container.querySelector("path");
1394
- if (!v) return;
1395
- const f = s.clientToLocal(l.clientX, l.clientY), p = Qe(v, f);
1396
- if (Xe(p.length, p.totalLength) || Ye(d.container, l.clientX, l.clientY))
1502
+ const h = s.getCellById(t);
1503
+ if (!h?.isEdge()) return;
1504
+ const u = s.findViewByCell(h);
1505
+ if (!u) return;
1506
+ const g = u.container.querySelector("path");
1507
+ if (!g) return;
1508
+ const p = s.clientToLocal(l.clientX, l.clientY), x = je(g, p);
1509
+ if (We(x.length, x.totalLength) || Ve(u.container, l.clientX, l.clientY))
1397
1510
  e && e.setAttribute("display", "none");
1398
1511
  else if (e)
1399
- e.removeAttribute("display"), e.setAttribute("transform", `translate(${p.x}, ${p.y})`);
1512
+ e.removeAttribute("display"), e.setAttribute("transform", `translate(${x.x}, ${x.y})`);
1400
1513
  else {
1401
- const E = Ke();
1402
- E.setAttribute("transform", `translate(${p.x}, ${p.y})`), d.container.appendChild(E), e = E;
1514
+ const m = Xe();
1515
+ m.setAttribute("transform", `translate(${x.x}, ${x.y})`), u.container.appendChild(m), e = m;
1403
1516
  }
1404
1517
  }
1405
- function r() {
1518
+ function i() {
1406
1519
  e && (e.remove(), e = null), t = null;
1407
1520
  }
1408
- function i(l) {
1521
+ function r(l) {
1409
1522
  l === t && (e = null, t = null);
1410
1523
  }
1411
- return { show: o, move: n, remove: r, handleEdgeRemoved: i };
1524
+ return { show: o, move: n, remove: i, handleEdgeRemoved: r };
1412
1525
  }
1413
- function zt(s) {
1526
+ function Vt(s) {
1414
1527
  let e = null, t = 0;
1415
- function o(d) {
1416
- const v = d ? "visible" : "hidden";
1417
- for (const f of s.getNodes())
1418
- for (const p of f.getPorts())
1419
- f.setPortProp(p.id, "attrs/circle/visibility", v);
1528
+ function o(u) {
1529
+ const g = u ? "visible" : "hidden";
1530
+ for (const p of s.getNodes())
1531
+ for (const x of p.getPorts())
1532
+ p.setPortProp(x.id, "attrs/circle/visibility", g);
1420
1533
  }
1421
- function n(d) {
1534
+ function n(u) {
1422
1535
  if (!e)
1423
- for (const v of d.getPorts())
1424
- d.setPortProp(v.id, "attrs/circle/visibility", "visible");
1536
+ for (const g of u.getPorts())
1537
+ u.setPortProp(g.id, "attrs/circle/visibility", "visible");
1425
1538
  }
1426
- function r(d) {
1539
+ function i(u) {
1427
1540
  if (!e)
1428
- for (const v of d.getPorts())
1429
- d.setPortProp(v.id, "attrs/circle/visibility", "hidden");
1430
- }
1431
- function i(d, v) {
1432
- if (!d.getTargetCell())
1433
- if (e = d.id, v?.size)
1434
- for (const f of s.getNodes()) {
1435
- const p = v.has(f.id) ? "hidden" : "visible";
1436
- for (const E of f.getPorts())
1437
- f.setPortProp(E.id, "attrs/circle/visibility", p);
1541
+ for (const g of u.getPorts())
1542
+ u.setPortProp(g.id, "attrs/circle/visibility", "hidden");
1543
+ }
1544
+ function r(u, g) {
1545
+ if (!u.getTargetCell())
1546
+ if (e = u.id, g?.size)
1547
+ for (const p of s.getNodes()) {
1548
+ const x = g.has(p.id) ? "hidden" : "visible";
1549
+ for (const m of p.getPorts())
1550
+ p.setPortProp(m.id, "attrs/circle/visibility", x);
1438
1551
  }
1439
1552
  else
1440
1553
  o(!0);
@@ -1442,22 +1555,523 @@ function zt(s) {
1442
1555
  function l() {
1443
1556
  e = null, o(!1), t = Date.now() + 300;
1444
1557
  }
1445
- function a(d) {
1446
- d === e && (e = null, o(!1));
1558
+ function a(u) {
1559
+ u === e && (e = null, o(!1));
1447
1560
  }
1448
- function g() {
1561
+ function h() {
1449
1562
  return !e && Date.now() >= t;
1450
1563
  }
1451
1564
  return {
1452
1565
  showNodePorts: n,
1453
- hideNodePorts: r,
1454
- handleEdgeAdded: i,
1566
+ hideNodePorts: i,
1567
+ handleEdgeAdded: r,
1455
1568
  handleEdgeConnected: l,
1456
1569
  handleEdgeRemoved: a,
1457
- canShowEdgeTool: g
1570
+ canShowEdgeTool: h
1571
+ };
1572
+ }
1573
+ function Ye(s) {
1574
+ return s === "top" || s === "right" || s === "bottom" || s === "left";
1575
+ }
1576
+ function Xt(s) {
1577
+ const { editor: e, nodeHover: t, isSelectionModeActive: o, viewportVersion: n, getNodeBehavior: i, getInsertGap: r } = s, { isDraggingNode: l } = s, a = q(null), h = q(!1);
1578
+ let u = null, g = null, p = null;
1579
+ const x = j(() => ({
1580
+ enabled: !0,
1581
+ portGroup: "right",
1582
+ ...s.quickAddProp.value
1583
+ }));
1584
+ function m() {
1585
+ u && (clearTimeout(u), u = null);
1586
+ }
1587
+ function k() {
1588
+ u && clearTimeout(u), u = setTimeout(() => {
1589
+ a.value = null, u = null;
1590
+ }, 150);
1591
+ }
1592
+ function S(C) {
1593
+ return h.value ? !0 : (m(), y(C) ? (a.value = C, !0) : (a.value = null, !1));
1594
+ }
1595
+ function T() {
1596
+ m(), t.enterOverlay();
1597
+ }
1598
+ function P() {
1599
+ k(), t.leaveOverlay();
1600
+ }
1601
+ function G(C) {
1602
+ const L = e.schema.nodeTypes[C.type];
1603
+ return qe(C, L?.getPorts);
1604
+ }
1605
+ function K(C, L) {
1606
+ const w = x.value.getPort?.(C, L);
1607
+ if (!w) return null;
1608
+ const A = typeof w == "string" ? w : w.id;
1609
+ return L.find((H) => H.id === A) ?? null;
1610
+ }
1611
+ function O(C, L) {
1612
+ const w = e.api.value?.overlay.getNodeScreenRect(C);
1613
+ if (!w) return null;
1614
+ switch (L) {
1615
+ case "top":
1616
+ return { x: w.x + w.width / 2, y: w.y };
1617
+ case "bottom":
1618
+ return { x: w.x + w.width / 2, y: w.y + w.height };
1619
+ case "left":
1620
+ return { x: w.x, y: w.y + w.height / 2 };
1621
+ case "right":
1622
+ return { x: w.x + w.width, y: w.y + w.height / 2 };
1623
+ default:
1624
+ return null;
1625
+ }
1626
+ }
1627
+ function W(C, L, w) {
1628
+ if (!g) return O(C, w);
1629
+ const A = g.getCellById(C);
1630
+ if (A?.isNode()) {
1631
+ const H = A, Z = g.findViewByCell(H), V = Z?.findPortElem(L, "circle") ?? Z?.findPortElem(L);
1632
+ if (V) {
1633
+ const ee = g.container.getBoundingClientRect(), Q = V.getBoundingClientRect();
1634
+ return {
1635
+ x: Q.left - ee.left + Q.width / 2,
1636
+ y: Q.top - ee.top + Q.height / 2
1637
+ };
1638
+ }
1639
+ }
1640
+ return O(C, w);
1641
+ }
1642
+ function z(C) {
1643
+ const L = G(C), w = K(C, L) ?? L.find((H) => H.group === x.value.portGroup) ?? null;
1644
+ if (!w) return null;
1645
+ const A = W(C.id, w.id, w.group);
1646
+ return A ? { portId: w.id, portGroup: w.group, portPosition: A } : null;
1647
+ }
1648
+ function M(C) {
1649
+ const L = z(C), w = x.value.insertDirection;
1650
+ if (typeof w == "function") {
1651
+ const A = w(C, L ? { id: L.portId, group: L.portGroup } : null);
1652
+ if (A) return A;
1653
+ } else if (w)
1654
+ return w;
1655
+ return L && Ye(L.portGroup) ? L.portGroup : Ye(x.value.portGroup) ? x.value.portGroup : "right";
1656
+ }
1657
+ function y(C) {
1658
+ if (!x.value.enabled || e.mode.value !== "edit") return !1;
1659
+ const w = e.flowModel.value.nodes[C];
1660
+ return !w || i(w).quickAddEnabled === !1 ? !1 : !!z(w);
1661
+ }
1662
+ const f = j(() => {
1663
+ if (n.value, !x.value.enabled) return null;
1664
+ const C = a.value;
1665
+ if (!C || l.value || !e.api.value || e.mode.value !== "edit" || o.value)
1666
+ return null;
1667
+ const w = e.flowModel.value.nodes[C];
1668
+ if (!w) return null;
1669
+ const A = i(w);
1670
+ if (A.quickAddEnabled === !1) return null;
1671
+ const H = z(w);
1672
+ return H ? { node: w, ...H, behavior: A } : null;
1673
+ });
1674
+ function d(C) {
1675
+ h.value = !0, f.value && e._emitUiEvent({ type: "node.quick-add", nodeId: C, position: f.value.portPosition });
1676
+ }
1677
+ function c() {
1678
+ h.value = !1;
1679
+ }
1680
+ function v(C) {
1681
+ const L = e.api.value;
1682
+ if (!L) return;
1683
+ const w = e.flowModel.value.nodes[C];
1684
+ if (!w) return;
1685
+ const A = z(w);
1686
+ A && L.startConnection(C, A.portId);
1687
+ }
1688
+ function b(C, L) {
1689
+ const w = e.api.value;
1690
+ if (!w) return;
1691
+ const A = L.id || e.idGenerator("node"), H = { ...L, id: A }, Z = e.flowModel.value.nodes[C];
1692
+ if (!Z) return;
1693
+ w.insertNodeToRight(C, H, {
1694
+ autoWireEdges: !0,
1695
+ direction: M(Z),
1696
+ gap: r(),
1697
+ source: "user:quick-add",
1698
+ label: "快捷插入节点"
1699
+ }).status === "applied" && e._emitUiEvent({ type: "node.action.quick-insert", sourceNodeId: C, newNodeId: A }), s.closePopover();
1700
+ }
1701
+ function E(C) {
1702
+ if (!g) return;
1703
+ const L = g.getCellById(C);
1704
+ if (!L?.isNode()) return;
1705
+ const w = L, A = e.flowModel.value.nodes[C];
1706
+ if (!A) return;
1707
+ const H = z(A);
1708
+ let Z = !0;
1709
+ i(A).hidePortForQuickAdd === !1 && (Z = !1);
1710
+ const ee = Z && !l.value && !!H && y(C);
1711
+ for (const Q of w.getPorts()) {
1712
+ const oe = ee && Q.id === H?.portId ? "hidden" : "visible";
1713
+ w.setPortProp(Q.id, "attrs/circle/visibility", oe);
1714
+ }
1715
+ }
1716
+ function B(C, L) {
1717
+ p?.(), g = C, p = pe(
1718
+ [a, l],
1719
+ ([w], [A]) => {
1720
+ if (A && A !== w) {
1721
+ const H = C.getCellById(A);
1722
+ H?.isNode() && L(H);
1723
+ }
1724
+ w && E(w);
1725
+ },
1726
+ { flush: "sync" }
1727
+ );
1728
+ }
1729
+ pe(f, (C) => {
1730
+ C || (h.value = !1);
1731
+ });
1732
+ function X() {
1733
+ u && clearTimeout(u), p?.(), p = null, g = null;
1734
+ }
1735
+ return {
1736
+ quickAddNodeId: a,
1737
+ quickAddPopoverOpen: h,
1738
+ mergedConfig: x,
1739
+ data: f,
1740
+ enter: S,
1741
+ leave: k,
1742
+ cancelLeave: m,
1743
+ handleOverlayEnter: T,
1744
+ handleOverlayLeave: P,
1745
+ handleOpen: d,
1746
+ handleClose: c,
1747
+ handleStartDrag: v,
1748
+ handleInsert: b,
1749
+ isActiveForNode: y,
1750
+ syncNodePorts: E,
1751
+ attachRuntime: B,
1752
+ cleanup: X
1753
+ };
1754
+ }
1755
+ const Yt = 15, Kt = 10;
1756
+ function Zt(s) {
1757
+ const { editor: e } = s;
1758
+ let t = null, o = null, n = null, i = null;
1759
+ const r = [];
1760
+ let l = null;
1761
+ const a = j(() => ({
1762
+ enabled: !1,
1763
+ bufferMargin: Yt,
1764
+ incomingPortGroup: "left",
1765
+ outgoingPortGroup: "right",
1766
+ ...s.edgeDropProp.value
1767
+ }));
1768
+ function h(y) {
1769
+ if (!t) return null;
1770
+ const f = t.getCellById(y);
1771
+ if (!f?.isEdge()) return null;
1772
+ const d = t.findViewByCell(f)?.container;
1773
+ if (!d) return null;
1774
+ const c = d.querySelectorAll("path");
1775
+ for (const v of c)
1776
+ if (v.getAttribute("stroke") !== "transparent") return v;
1777
+ return null;
1778
+ }
1779
+ function u(y) {
1780
+ const f = h(y);
1781
+ f && (f.style.stroke = "#3a84ff", i = y);
1782
+ }
1783
+ function g() {
1784
+ if (!i) return;
1785
+ const y = h(i);
1786
+ y && (y.style.stroke = ""), i = null;
1787
+ }
1788
+ function p(y, f, d) {
1789
+ if (t) {
1790
+ const c = t.getCellById(y);
1791
+ if (c?.isNode()) {
1792
+ const v = c.getPorts().find((b) => b.group === d);
1793
+ if (v?.id) return v.id;
1794
+ }
1795
+ }
1796
+ if (f.ports?.length) {
1797
+ const c = f.ports.find((v) => v.group === d);
1798
+ if (c) return c.id;
1799
+ }
1800
+ return d;
1801
+ }
1802
+ function x(y) {
1803
+ const f = y.getTotalLength();
1804
+ if (f === 0) return [];
1805
+ const d = [];
1806
+ for (let v = 0; v <= f; v += Kt) {
1807
+ const b = y.getPointAtLength(v);
1808
+ d.push({ x: b.x, y: b.y });
1809
+ }
1810
+ const c = y.getPointAtLength(f);
1811
+ return d.push({ x: c.x, y: c.y }), d;
1812
+ }
1813
+ function m(y, f, d) {
1814
+ if (!t) return null;
1815
+ const c = a.value, v = c.bufferMargin, b = {
1816
+ x: y.x + v,
1817
+ y: y.y + v,
1818
+ width: Math.max(0, y.width - v * 2),
1819
+ height: Math.max(0, y.height - v * 2)
1820
+ };
1821
+ if (b.width <= 0 || b.height <= 0) return null;
1822
+ const E = b.x + b.width, B = b.y + b.height;
1823
+ let X = null;
1824
+ const C = y.x + y.width / 2, L = y.y + y.height / 2;
1825
+ for (const w of t.getEdges()) {
1826
+ const A = f.edges[w.id];
1827
+ if (!A || d && (A.source.nodeId === d || A.target.nodeId === d) || c.isEdgeDropTarget && !c.isEdgeDropTarget(A, f)) continue;
1828
+ const H = t.findViewByCell(w);
1829
+ if (!H) continue;
1830
+ const Z = H.findOne?.("path");
1831
+ if (!Z || typeof Z.getTotalLength != "function") continue;
1832
+ const V = x(Z);
1833
+ if (!V.length) continue;
1834
+ let ee = !1, Q = 1 / 0;
1835
+ for (const oe of V)
1836
+ if (oe.x >= b.x && oe.x <= E && oe.y >= b.y && oe.y <= B) {
1837
+ const ie = oe.x - C, ne = oe.y - L, N = ie * ie + ne * ne;
1838
+ N < Q && (Q = N), ee = !0;
1839
+ }
1840
+ ee && (!X || Q < X.distSq) && (X = { edgeId: w.id, edge: A, distSq: Q });
1841
+ }
1842
+ return X ? { edgeId: X.edgeId, edge: X.edge } : null;
1843
+ }
1844
+ function k(y, f) {
1845
+ if (!a.value.enabled) return;
1846
+ const c = e.flowModel.value, v = m(y, c, f);
1847
+ v ? o !== v.edgeId && (g(), o = v.edgeId, u(v.edgeId)) : o && (g(), o = null);
1848
+ }
1849
+ let S = !0;
1850
+ function T({ node: y }) {
1851
+ if (o = null, !a.value.enabled) return;
1852
+ const f = e.flowModel.value, d = f.nodes[y.id];
1853
+ if (!d) {
1854
+ S = !1;
1855
+ return;
1856
+ }
1857
+ const c = a.value;
1858
+ S = !c.isNodeInsertable || c.isNodeInsertable(d, f);
1859
+ }
1860
+ function P({ node: y }) {
1861
+ !a.value.enabled || !S || n === null && (n = requestAnimationFrame(() => {
1862
+ if (n = null, !t) return;
1863
+ const f = y.getPosition(), d = y.getSize();
1864
+ k({ x: f.x, y: f.y, width: d.width, height: d.height }, y.id);
1865
+ }));
1866
+ }
1867
+ function G() {
1868
+ n !== null && (cancelAnimationFrame(n), n = null), g(), S = !0;
1869
+ }
1870
+ function K() {
1871
+ if (!t) return;
1872
+ let y = !1;
1873
+ l = () => {
1874
+ if (!a.value.enabled) return;
1875
+ const f = document.querySelector(".x6-widget-dnd");
1876
+ if (!f) {
1877
+ y && (y = !1, g(), o = null);
1878
+ return;
1879
+ }
1880
+ y = !0, n === null && (n = requestAnimationFrame(() => {
1881
+ if (n = null, !t) return;
1882
+ const d = f.getBoundingClientRect(), c = t.clientToLocal(d.left, d.top), v = t.clientToLocal(d.right, d.bottom), b = {
1883
+ x: c.x,
1884
+ y: c.y,
1885
+ width: v.x - c.x,
1886
+ height: v.y - c.y
1887
+ };
1888
+ k(b);
1889
+ }));
1890
+ }, document.addEventListener("mousemove", l), r.push(() => {
1891
+ l && (document.removeEventListener("mousemove", l), l = null);
1892
+ });
1893
+ }
1894
+ function O() {
1895
+ g(), o = null, n !== null && (cancelAnimationFrame(n), n = null);
1896
+ }
1897
+ function W(y) {
1898
+ if (!o || y.source !== "user:drag") return y;
1899
+ const f = o;
1900
+ o = null, g();
1901
+ const d = e.flowModel.value, c = d.edges[f];
1902
+ if (!c) return y;
1903
+ const v = y.commands.find((H) => H.type === "node.add" || H.type === "node.move");
1904
+ if (!v) return y;
1905
+ const b = v.type === "node.add" ? v.node.id : v.nodeId, E = v.type === "node.add" ? v.node : d.nodes[v.nodeId];
1906
+ if (!E) return y;
1907
+ const B = a.value;
1908
+ if (B.isNodeInsertable && !B.isNodeInsertable(E, d))
1909
+ return y;
1910
+ const X = p(b, E, B.incomingPortGroup), C = p(b, E, B.outgoingPortGroup), L = e.idGenerator("edge"), w = e.idGenerator("edge"), A = [
1911
+ { type: "edge.remove", edgeId: f },
1912
+ {
1913
+ type: "edge.add",
1914
+ edge: {
1915
+ id: L,
1916
+ type: c.type,
1917
+ source: { nodeId: c.source.nodeId, portId: c.source.portId },
1918
+ target: { nodeId: b, portId: X }
1919
+ }
1920
+ },
1921
+ {
1922
+ type: "edge.add",
1923
+ edge: {
1924
+ id: w,
1925
+ type: c.type,
1926
+ source: { nodeId: b, portId: C },
1927
+ target: { nodeId: c.target.nodeId, portId: c.target.portId }
1928
+ }
1929
+ }
1930
+ ];
1931
+ return {
1932
+ ...y,
1933
+ source: "user:edge-drop",
1934
+ commands: [...y.commands, ...A]
1935
+ };
1936
+ }
1937
+ function z(y) {
1938
+ t = y;
1939
+ const f = (d, c) => {
1940
+ y.on(d, c), r.push(() => y.off(d, c));
1941
+ };
1942
+ f("node:move", T), f("node:change:position", P), f("node:moved", G), K();
1943
+ }
1944
+ function M() {
1945
+ O();
1946
+ for (const y of r) y();
1947
+ r.length = 0, t = null, S = !0;
1948
+ }
1949
+ return {
1950
+ attachRuntime: z,
1951
+ tryExpandForEdgeDrop: W,
1952
+ cleanup: M
1953
+ };
1954
+ }
1955
+ function Qt(s) {
1956
+ function e(n) {
1957
+ return {
1958
+ id: s.idGenerator("node"),
1959
+ type: n.type,
1960
+ label: n.label,
1961
+ ports: n.ports ? JSON.parse(JSON.stringify(n.ports)) : void 0,
1962
+ payload: n.payload ? JSON.parse(JSON.stringify(n.payload)) : void 0,
1963
+ extensions: n.extensions ? JSON.parse(JSON.stringify(n.extensions)) : void 0
1964
+ };
1965
+ }
1966
+ function t(n, i, r) {
1967
+ const l = s.api.value;
1968
+ switch (n) {
1969
+ case "delete":
1970
+ return s.executeCommand({
1971
+ id: te(),
1972
+ source: "user:toolbar",
1973
+ label: "删除节点",
1974
+ timestamp: Date.now(),
1975
+ commands: [{ type: "node.remove", nodeId: i }]
1976
+ }), s._emitUiEvent({ type: "node.action.delete", nodeId: i }), !0;
1977
+ case "copy": {
1978
+ if (!l) break;
1979
+ const a = s.flowModel.value.nodes[i];
1980
+ if (!a) break;
1981
+ const h = e(a);
1982
+ l.insertNodeToRight(i, h, {
1983
+ autoWireEdges: !1,
1984
+ gap: r,
1985
+ label: "复制节点"
1986
+ }), s._emitUiEvent({ type: "node.action.copy", sourceNodeId: i, newNodeId: h.id });
1987
+ break;
1988
+ }
1989
+ case "copy-insert": {
1990
+ if (!l) break;
1991
+ const a = s.flowModel.value.nodes[i];
1992
+ if (!a) break;
1993
+ const h = e(a);
1994
+ l.insertNodeToRight(i, h, {
1995
+ autoWireEdges: !0,
1996
+ gap: r,
1997
+ label: "复制并插入节点"
1998
+ }), s._emitUiEvent({ type: "node.action.copy-insert", sourceNodeId: i, newNodeId: h.id });
1999
+ break;
2000
+ }
2001
+ case "disconnect": {
2002
+ const a = s.flowModel.value, h = Object.entries(a.edges).filter(([, u]) => {
2003
+ const g = u;
2004
+ return g.source.nodeId === i || g.target.nodeId === i;
2005
+ }).map(([u]) => u);
2006
+ if (h.length === 0) break;
2007
+ s.executeCommand({
2008
+ id: te(),
2009
+ source: "user:toolbar",
2010
+ label: "断开连线",
2011
+ timestamp: Date.now(),
2012
+ commands: h.map((u) => ({ type: "edge.remove", edgeId: u }))
2013
+ }), s._emitUiEvent({ type: "node.action.disconnect", nodeId: i, edgeIds: h });
2014
+ break;
2015
+ }
2016
+ case "debug": {
2017
+ s._emitUiEvent({ type: "node.action.debug", nodeId: i });
2018
+ break;
2019
+ }
2020
+ }
2021
+ return !1;
2022
+ }
2023
+ function o(n) {
2024
+ s.api.value?.deleteSelection({
2025
+ selection: n,
2026
+ source: "user:toolbar",
2027
+ label: "批量删除选中"
2028
+ });
2029
+ }
2030
+ return { handleNodeAction: t, deleteSelection: o };
2031
+ }
2032
+ function Jt() {
2033
+ return {
2034
+ refX: 0,
2035
+ children: [
2036
+ {
2037
+ tagName: "path",
2038
+ d: "M -16 -5 L -8 0 L -16 5 Z",
2039
+ transform: "rotate(0)"
2040
+ },
2041
+ {
2042
+ tagName: "circle",
2043
+ cx: 0,
2044
+ cy: 0,
2045
+ r: 8,
2046
+ fill: "#3a84ff",
2047
+ stroke: "#3a84ff",
2048
+ transform: "rotate(0)"
2049
+ }
2050
+ ]
2051
+ };
2052
+ }
2053
+ function eo(s, e) {
2054
+ const t = e.defaultEdgeType ?? "default", o = e.edgeTypes?.[t], n = {
2055
+ zIndex: -1,
2056
+ attrs: {
2057
+ line: {
2058
+ stroke: "#abb5cc",
2059
+ strokeWidth: 2,
2060
+ targetMarker: { name: "block", width: 8, height: 8 }
2061
+ }
2062
+ }
1458
2063
  };
2064
+ o?.router && (n.router = typeof o.router == "string" ? { name: o.router } : o.router), o?.connector && (n.connector = typeof o.connector == "string" ? { name: o.connector } : o.connector), o?.x6EdgeConfig && Object.assign(n, o.x6EdgeConfig);
2065
+ const i = n.attrs ?? {}, r = i.line ?? {};
2066
+ return n.attrs = {
2067
+ ...i,
2068
+ line: {
2069
+ ...r,
2070
+ targetMarker: Jt()
2071
+ }
2072
+ }, s.createEdge(n);
1459
2073
  }
1460
- const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
2074
+ const to = { class: "flow-canvas-node-actions__bar" }, oo = /* @__PURE__ */ fe({
1461
2075
  __name: "node-actions-toolbar",
1462
2076
  props: {
1463
2077
  node: {},
@@ -1468,14 +2082,14 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
1468
2082
  },
1469
2083
  emits: ["action"],
1470
2084
  setup(s, { emit: e }) {
1471
- const t = s, o = F(() => {
1472
- const v = t.actionsOffset?.x ?? 0, f = t.actionsOffset?.y ?? 0, p = v !== 0 || f !== 0;
2085
+ const t = s, o = j(() => {
2086
+ const g = t.actionsOffset?.x ?? 0, p = t.actionsOffset?.y ?? 0, x = g !== 0 || p !== 0;
1473
2087
  return {
1474
2088
  left: `${t.position.x}px`,
1475
2089
  top: `${t.position.y}px`,
1476
- transform: p ? `translate(${v}px, ${f}px)` : "translateX(-100%)"
2090
+ transform: x ? `translate(${g}px, ${p}px)` : "translateX(-100%)"
1477
2091
  };
1478
- }), n = e, r = F(() => ({
2092
+ }), n = e, i = j(() => ({
1479
2093
  debug: {
1480
2094
  visible: t.config.showDebug && t.behavior.debuggable !== !1,
1481
2095
  disabled: t.behavior.debugDisabled === !0
@@ -1496,75 +2110,75 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
1496
2110
  visible: t.config.showDisconnect && t.behavior.disconnectable !== !1,
1497
2111
  disabled: t.behavior.disconnectDisabled === !0
1498
2112
  }
1499
- })), i = F(() => r.value.copy.visible || r.value.copyInsert.visible || r.value.disconnect.visible), l = O(!1);
2113
+ })), r = j(() => i.value.copy.visible || i.value.copyInsert.visible || i.value.disconnect.visible), l = q(!1);
1500
2114
  let a = null;
1501
- function g() {
2115
+ function h() {
1502
2116
  a && (clearTimeout(a), a = null), l.value = !0;
1503
2117
  }
1504
- function d() {
2118
+ function u() {
1505
2119
  a = setTimeout(() => {
1506
2120
  l.value = !1, a = null;
1507
2121
  }, 100);
1508
2122
  }
1509
- return ze(() => {
2123
+ return Me(() => {
1510
2124
  a && clearTimeout(a);
1511
- }), (v, f) => (M(), S("div", {
2125
+ }), (g, p) => (D(), R("div", {
1512
2126
  class: "flow-canvas-node-actions",
1513
- style: _e(o.value)
2127
+ style: we(o.value)
1514
2128
  }, [
1515
- B("div", jt, [
1516
- r.value.debug.visible ? (M(), S("i", {
2129
+ U("div", to, [
2130
+ i.value.debug.visible ? (D(), R("i", {
1517
2131
  key: 0,
1518
- class: ee(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon", { "is-disabled": r.value.debug.disabled }]),
1519
- onClick: f[0] || (f[0] = (p) => !r.value.debug.disabled && n("action", "debug", s.node.id))
1520
- }, null, 2)) : U("", !0),
1521
- r.value.delete.visible ? (M(), S("i", {
2132
+ class: se(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon", { "is-disabled": i.value.debug.disabled }]),
2133
+ onClick: p[0] || (p[0] = (x) => !i.value.debug.disabled && n("action", "debug", s.node.id))
2134
+ }, null, 2)) : Y("", !0),
2135
+ i.value.delete.visible ? (D(), R("i", {
1522
2136
  key: 1,
1523
- class: ee(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon", { "is-disabled": r.value.delete.disabled }]),
1524
- onClick: f[1] || (f[1] = (p) => !r.value.delete.disabled && n("action", "delete", s.node.id))
1525
- }, null, 2)) : U("", !0),
1526
- i.value ? (M(), S("div", {
2137
+ class: se(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon", { "is-disabled": i.value.delete.disabled }]),
2138
+ onClick: p[1] || (p[1] = (x) => !i.value.delete.disabled && n("action", "delete", s.node.id))
2139
+ }, null, 2)) : Y("", !0),
2140
+ r.value ? (D(), R("div", {
1527
2141
  key: 2,
1528
2142
  class: "flow-canvas-node-actions__more-wrapper",
1529
- onMouseenter: g,
1530
- onMouseleave: d
1531
- }, [...f[5] || (f[5] = [
1532
- B("i", { class: "flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon" }, null, -1)
1533
- ])], 32)) : U("", !0)
2143
+ onMouseenter: h,
2144
+ onMouseleave: u
2145
+ }, [...p[5] || (p[5] = [
2146
+ U("i", { class: "flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon" }, null, -1)
2147
+ ])], 32)) : Y("", !0)
1534
2148
  ]),
1535
- tt(ot, { name: "flow-canvas-fade" }, {
1536
- default: je(() => [
1537
- l.value && i.value ? (M(), S("div", {
2149
+ et(tt, { name: "flow-canvas-fade" }, {
2150
+ default: He(() => [
2151
+ l.value && r.value ? (D(), R("div", {
1538
2152
  key: 0,
1539
2153
  class: "flow-canvas-node-actions__dropdown",
1540
- onMouseenter: g,
1541
- onMouseleave: d
2154
+ onMouseenter: h,
2155
+ onMouseleave: u
1542
2156
  }, [
1543
- r.value.copy.visible ? (M(), S("div", {
2157
+ i.value.copy.visible ? (D(), R("div", {
1544
2158
  key: 0,
1545
- class: ee(["flow-canvas-node-actions__dropdown-item", { "is-disabled": r.value.copy.disabled }]),
1546
- onClick: f[2] || (f[2] = (p) => !r.value.copy.disabled && n("action", "copy", s.node.id))
1547
- }, [...f[6] || (f[6] = [
1548
- B("i", { class: "flow-canvas-icon canvas-copy-fuzhi-2" }, null, -1),
1549
- B("span", null, "复制", -1)
1550
- ])], 2)) : U("", !0),
1551
- r.value.copyInsert.visible ? (M(), S("div", {
2159
+ class: se(["flow-canvas-node-actions__dropdown-item", { "is-disabled": i.value.copy.disabled }]),
2160
+ onClick: p[2] || (p[2] = (x) => !i.value.copy.disabled && n("action", "copy", s.node.id))
2161
+ }, [...p[6] || (p[6] = [
2162
+ U("i", { class: "flow-canvas-icon canvas-copy-fuzhi-2" }, null, -1),
2163
+ U("span", null, "复制", -1)
2164
+ ])], 2)) : Y("", !0),
2165
+ i.value.copyInsert.visible ? (D(), R("div", {
1552
2166
  key: 1,
1553
- class: ee(["flow-canvas-node-actions__dropdown-item", { "is-disabled": r.value.copyInsert.disabled }]),
1554
- onClick: f[3] || (f[3] = (p) => !r.value.copyInsert.disabled && n("action", "copy-insert", s.node.id))
1555
- }, [...f[7] || (f[7] = [
1556
- B("i", { class: "flow-canvas-icon canvas-fuzhibingcharu" }, null, -1),
1557
- B("span", null, "复制并插入", -1)
1558
- ])], 2)) : U("", !0),
1559
- r.value.disconnect.visible ? (M(), S("div", {
2167
+ class: se(["flow-canvas-node-actions__dropdown-item", { "is-disabled": i.value.copyInsert.disabled }]),
2168
+ onClick: p[3] || (p[3] = (x) => !i.value.copyInsert.disabled && n("action", "copy-insert", s.node.id))
2169
+ }, [...p[7] || (p[7] = [
2170
+ U("i", { class: "flow-canvas-icon canvas-fuzhibingcharu" }, null, -1),
2171
+ U("span", null, "复制并插入", -1)
2172
+ ])], 2)) : Y("", !0),
2173
+ i.value.disconnect.visible ? (D(), R("div", {
1560
2174
  key: 2,
1561
- class: ee(["flow-canvas-node-actions__dropdown-item", { "is-disabled": r.value.disconnect.disabled }]),
1562
- onClick: f[4] || (f[4] = (p) => !r.value.disconnect.disabled && n("action", "disconnect", s.node.id))
1563
- }, [...f[8] || (f[8] = [
1564
- B("i", { class: "flow-canvas-icon canvas-unlock-jiebang" }, null, -1),
1565
- B("span", null, "断开连线", -1)
1566
- ])], 2)) : U("", !0)
1567
- ], 32)) : U("", !0)
2175
+ class: se(["flow-canvas-node-actions__dropdown-item", { "is-disabled": i.value.disconnect.disabled }]),
2176
+ onClick: p[4] || (p[4] = (x) => !i.value.disconnect.disabled && n("action", "disconnect", s.node.id))
2177
+ }, [...p[8] || (p[8] = [
2178
+ U("i", { class: "flow-canvas-icon canvas-unlock-jiebang" }, null, -1),
2179
+ U("span", null, "断开连线", -1)
2180
+ ])], 2)) : Y("", !0)
2181
+ ], 32)) : Y("", !0)
1568
2182
  ]),
1569
2183
  _: 1
1570
2184
  })
@@ -1575,160 +2189,158 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
1575
2189
  for (const [o, n] of e)
1576
2190
  t[o] = n;
1577
2191
  return t;
1578
- }, Ft = /* @__PURE__ */ he(Ht, [["__scopeId", "data-v-3b39dab5"]]), qt = {
2192
+ }, no = /* @__PURE__ */ he(oo, [["__scopeId", "data-v-3b39dab5"]]), so = {
1579
2193
  key: 0,
1580
2194
  class: "flow-canvas-quick-add__tooltip"
1581
- }, Ut = 5, Vt = /* @__PURE__ */ ge({
2195
+ }, io = 5, ro = /* @__PURE__ */ fe({
1582
2196
  __name: "node-quick-add-popover",
1583
2197
  props: {
1584
2198
  node: {},
1585
- portPosition: {},
1586
- tooltipText: {}
2199
+ portPosition: {}
1587
2200
  },
1588
2201
  emits: ["open", "close", "start-drag", "mouseenter", "mouseleave"],
1589
2202
  setup(s, { expose: e, emit: t }) {
1590
- const o = s, n = t, r = O(), i = O(), l = O(!1), a = O(!1);
1591
- let g = null, d = !1, v = null;
1592
- function f(G) {
1593
- G.preventDefault(), G.stopPropagation(), g = { x: G.clientX, y: G.clientY }, d = !1, document.addEventListener("mousemove", p), document.addEventListener("mouseup", E);
2203
+ const o = s, n = t, i = q(), r = q(), l = q(!1), a = q(!1);
2204
+ let h = null, u = !1, g = null;
2205
+ function p(z) {
2206
+ z.preventDefault(), z.stopPropagation(), h = { x: z.clientX, y: z.clientY }, u = !1, document.addEventListener("mousemove", x), document.addEventListener("mouseup", m);
1594
2207
  }
1595
- function p(G) {
1596
- if (!g) return;
1597
- const T = G.clientX - g.x, h = G.clientY - g.y;
1598
- Math.sqrt(T * T + h * h) >= Ut && (d = !0, w(), n("start-drag", o.node.id));
2208
+ function x(z) {
2209
+ if (!h) return;
2210
+ const M = z.clientX - h.x, y = z.clientY - h.y;
2211
+ Math.sqrt(M * M + y * y) >= io && (u = !0, k(), n("start-drag", o.node.id));
1599
2212
  }
1600
- function E() {
1601
- w(), d || N(), g = null, d = !1;
2213
+ function m() {
2214
+ k(), u || S(), h = null, u = !1;
1602
2215
  }
1603
- function w() {
1604
- document.removeEventListener("mousemove", p), document.removeEventListener("mouseup", E);
2216
+ function k() {
2217
+ document.removeEventListener("mousemove", x), document.removeEventListener("mouseup", m);
1605
2218
  }
1606
- function N() {
1607
- a.value ? D() : m();
2219
+ function S() {
2220
+ a.value ? P() : T();
1608
2221
  }
1609
- function m() {
2222
+ function T() {
1610
2223
  a.value = !0, n("open", o.node.id), requestAnimationFrame(() => {
1611
- document.addEventListener("mousedown", z);
2224
+ document.addEventListener("mousedown", G);
1612
2225
  });
1613
2226
  }
1614
- function D() {
1615
- a.value = !1, n("close"), document.removeEventListener("mousedown", z);
2227
+ function P() {
2228
+ a.value = !1, n("close"), document.removeEventListener("mousedown", G);
1616
2229
  }
1617
- function z(G) {
1618
- const T = G.target;
1619
- r.value?.contains(T) || i.value?.contains(T) || D();
2230
+ function G(z) {
2231
+ const M = z.target;
2232
+ i.value?.contains(M) || r.value?.contains(M) || P();
1620
2233
  }
1621
- function X() {
2234
+ function K() {
1622
2235
  a.value || n("mouseleave");
1623
2236
  }
1624
- function j() {
1625
- v && (clearTimeout(v), v = null), n("mouseenter");
2237
+ function O() {
2238
+ g && (clearTimeout(g), g = null), n("mouseenter");
1626
2239
  }
1627
- function oe() {
1628
- v = setTimeout(() => {
1629
- D(), n("mouseleave"), v = null;
2240
+ function W() {
2241
+ g = setTimeout(() => {
2242
+ P(), n("mouseleave"), g = null;
1630
2243
  }, 150);
1631
2244
  }
1632
- return ze(() => {
1633
- w(), v && clearTimeout(v), document.removeEventListener("mousedown", z);
1634
- }), e({ closePopover: D }), (G, T) => (M(), S("div", {
2245
+ return Me(() => {
2246
+ k(), g && clearTimeout(g), document.removeEventListener("mousedown", G);
2247
+ }), e({ closePopover: P }), (z, M) => (D(), R("div", {
1635
2248
  class: "flow-canvas-quick-add",
1636
- style: _e({ left: `${s.portPosition.x}px`, top: `${s.portPosition.y}px` }),
1637
- onMouseenter: T[2] || (T[2] = (h) => n("mouseenter")),
1638
- onMouseleave: X,
1639
- onClick: T[3] || (T[3] = rt(() => {
2249
+ style: we({ left: `${s.portPosition.x}px`, top: `${s.portPosition.y}px` }),
2250
+ onMouseenter: M[2] || (M[2] = (y) => n("mouseenter")),
2251
+ onMouseleave: K,
2252
+ onClick: M[3] || (M[3] = rt(() => {
1640
2253
  }, ["stop"]))
1641
2254
  }, [
1642
- B("div", {
2255
+ U("div", {
1643
2256
  ref_key: "btnRef",
1644
- ref: r,
1645
- class: ee(["flow-canvas-quick-add__btn", { "is-hovered": l.value, "is-active": a.value }]),
1646
- onMouseenter: T[0] || (T[0] = (h) => l.value = !0),
1647
- onMouseleave: T[1] || (T[1] = (h) => l.value = !1),
1648
- onMousedown: f
1649
- }, [...T[4] || (T[4] = [
1650
- B("i", { class: "flow-canvas-icon canvas-zoom-add" }, null, -1)
2257
+ ref: i,
2258
+ class: se(["flow-canvas-quick-add__btn", { "is-hovered": l.value, "is-active": a.value }]),
2259
+ onMouseenter: M[0] || (M[0] = (y) => l.value = !0),
2260
+ onMouseleave: M[1] || (M[1] = (y) => l.value = !1),
2261
+ onMousedown: p
2262
+ }, [...M[4] || (M[4] = [
2263
+ U("i", { class: "flow-canvas-icon canvas-zoom-add" }, null, -1)
1651
2264
  ])], 34),
1652
- l.value && !a.value ? (M(), S("div", qt, [...T[5] || (T[5] = [
1653
- B("div", null, [
1654
- B("b", null, "点击"),
1655
- Ve(" 添加节点")
2265
+ l.value && !a.value ? (D(), R("div", so, [...M[5] || (M[5] = [
2266
+ U("div", null, [
2267
+ U("b", null, "点击"),
2268
+ Le(" 添加节点")
1656
2269
  ], -1),
1657
- B("div", null, [
1658
- B("b", null, "拖拽"),
1659
- Ve(" 连接节点")
2270
+ U("div", null, [
2271
+ U("b", null, "拖拽"),
2272
+ Le(" 连接节点")
1660
2273
  ], -1)
1661
- ])])) : U("", !0),
1662
- tt(ot, { name: "flow-canvas-fade" }, {
1663
- default: je(() => [
1664
- a.value ? (M(), S("div", {
2274
+ ])])) : Y("", !0),
2275
+ et(tt, { name: "flow-canvas-fade" }, {
2276
+ default: He(() => [
2277
+ a.value ? (D(), R("div", {
1665
2278
  key: 0,
1666
2279
  ref_key: "popoverRef",
1667
- ref: i,
2280
+ ref: r,
1668
2281
  class: "flow-canvas-quick-add__popover",
1669
- onMouseenter: j,
1670
- onMouseleave: oe
2282
+ onMouseenter: O,
2283
+ onMouseleave: W
1671
2284
  }, [
1672
- ke(G.$slots, "default", {}, () => [
1673
- T[6] || (T[6] = B("div", { class: "flow-canvas-quick-add__default-content" }, "节点快捷操作面板", -1))
2285
+ Ee(z.$slots, "default", {}, () => [
2286
+ M[6] || (M[6] = U("div", { class: "flow-canvas-quick-add__default-content" }, "节点快捷操作面板", -1))
1674
2287
  ], !0)
1675
- ], 544)) : U("", !0)
2288
+ ], 544)) : Y("", !0)
1676
2289
  ]),
1677
2290
  _: 3
1678
2291
  })
1679
2292
  ], 36));
1680
2293
  }
1681
- }), Wt = /* @__PURE__ */ he(Vt, [["__scopeId", "data-v-b98695cf"]]), Qt = { class: "flow-canvas-runtime-core__overlay" }, Xt = /* @__PURE__ */ ge({
2294
+ }), ao = /* @__PURE__ */ he(ro, [["__scopeId", "data-v-336cc3b4"]]), lo = { class: "flow-canvas-selection-actions__bar" }, co = /* @__PURE__ */ fe({
2295
+ __name: "selection-actions-toolbar",
2296
+ props: {
2297
+ position: {},
2298
+ canDelete: { type: Boolean }
2299
+ },
2300
+ emits: ["action"],
2301
+ setup(s, { emit: e }) {
2302
+ const t = s, o = e, n = j(() => ({
2303
+ left: `${t.position.x}px`,
2304
+ top: `${t.position.y}px`,
2305
+ transform: "translateX(-100%)"
2306
+ }));
2307
+ return (i, r) => (D(), R("div", {
2308
+ class: "flow-canvas-selection-actions",
2309
+ style: we(n.value)
2310
+ }, [
2311
+ U("div", lo, [
2312
+ U("i", {
2313
+ class: se(["flow-canvas-icon canvas-shanchu flow-canvas-selection-actions__icon", { "is-disabled": !s.canDelete }]),
2314
+ onClick: r[0] || (r[0] = (l) => s.canDelete && o("action", "delete"))
2315
+ }, null, 2)
2316
+ ])
2317
+ ], 4));
2318
+ }
2319
+ }), uo = /* @__PURE__ */ he(co, [["__scopeId", "data-v-25eb8b79"]]), fo = { class: "flow-canvas-runtime-core__overlay" }, go = /* @__PURE__ */ fe({
1682
2320
  __name: "canvas-runtime-core",
1683
2321
  props: {
1684
2322
  editor: {},
1685
2323
  graphOptions: {},
1686
2324
  nodeActions: {},
1687
2325
  quickAdd: {},
2326
+ edgeDrop: {},
1688
2327
  getConnectionExcludedNodeIds: { type: Function }
1689
2328
  },
1690
2329
  emits: ["ui-event"],
1691
2330
  setup(s, { emit: e }) {
1692
- const t = s, o = e, n = O(), r = O();
1693
- let i, l, a, g;
1694
- const d = Ot(), { hoveredNodeId: v, isDraggingNode: f } = d, p = d.enterOverlay, E = () => d.leaveOverlay(), w = O(null), N = O(!1);
1695
- let m = null;
1696
- function D(y) {
1697
- return N.value ? !0 : (X(), ie(y) ? (w.value = y, !0) : (w.value = null, !1));
1698
- }
1699
- function z() {
1700
- m && clearTimeout(m), m = setTimeout(() => {
1701
- w.value = null, m = null;
1702
- }, 150);
1703
- }
1704
- function X() {
1705
- m && (clearTimeout(m), m = null);
1706
- }
1707
- function j() {
1708
- X(), d.enterOverlay();
1709
- }
1710
- function oe() {
1711
- z(), d.leaveOverlay();
2331
+ const t = s, o = e, n = q(), i = q();
2332
+ let r, l, a, h, u = null, g = null, p = null, x = null;
2333
+ const m = jt(), { hoveredNodeId: k, isDraggingNode: S } = m, T = m.enterOverlay, P = () => m.leaveOverlay(), G = q(0), K = q({ nodeIds: [], edgeIds: [] });
2334
+ function O(N) {
2335
+ const I = t.editor.api.value;
2336
+ return I ? t.editor.schema.nodeTypes[N.type]?.getBehavior?.(N, {
2337
+ api: I,
2338
+ flowModel: t.editor.flowModel.value,
2339
+ history: t.editor.history,
2340
+ mode: t.editor.mode.value
2341
+ }) ?? {} : {};
1712
2342
  }
1713
- let G = null, T = null, h = null, b = null, C = null;
1714
- const L = O(0), R = F(
1715
- () => {
1716
- if (L.value, !t.editor.api.value) return [];
1717
- const y = t.editor.flowModel.value, x = t.editor.api.value.overlay, c = [];
1718
- for (const [I, P] of Object.entries(y.nodes)) {
1719
- const _ = t.editor._pluginManager.collectNodeDecorations(P);
1720
- if (!_?.badge) continue;
1721
- const $ = x.getNodeScreenRect(I);
1722
- $ && c.push({
1723
- nodeId: I,
1724
- x: $.x + $.width - 4,
1725
- y: $.y - 8,
1726
- badge: _.badge
1727
- });
1728
- }
1729
- return c;
1730
- }
1731
- ), q = F(() => ({
2343
+ const W = j(() => t.editor.mode.value === "edit" && t.editor.selectionMode.value), z = j(() => ({
1732
2344
  showDebug: !1,
1733
2345
  showDelete: !0,
1734
2346
  showCopy: !0,
@@ -1736,301 +2348,188 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
1736
2348
  showDisconnect: !0,
1737
2349
  insertGap: 100,
1738
2350
  ...t.nodeActions
1739
- })), Y = F(() => {
1740
- L.value;
1741
- const y = v.value;
1742
- if (!y || f.value || !t.editor.api.value || t.editor.mode.value !== "edit") return null;
1743
- const x = t.editor.flowModel.value, c = x.nodes[y];
1744
- if (!c) return null;
1745
- const I = t.editor.api.value.overlay.getNodeScreenRect(y);
2351
+ })), M = j(
2352
+ () => {
2353
+ if (G.value, !t.editor.api.value) return [];
2354
+ const N = t.editor.flowModel.value, I = t.editor.api.value.overlay, _ = [];
2355
+ for (const [F, ae] of Object.entries(N.nodes)) {
2356
+ const de = t.editor._pluginManager.collectNodeDecorations(ae);
2357
+ if (!de?.badge) continue;
2358
+ const J = I.getNodeScreenRect(F);
2359
+ J && _.push({
2360
+ nodeId: F,
2361
+ x: J.x + J.width - 4,
2362
+ y: J.y - 8,
2363
+ badge: de.badge
2364
+ });
2365
+ }
2366
+ return _;
2367
+ }
2368
+ ), y = j(() => {
2369
+ G.value;
2370
+ const N = k.value;
2371
+ if (!N || S.value || !t.editor.api.value || t.editor.mode.value !== "edit" || W.value)
2372
+ return null;
2373
+ const _ = t.editor.flowModel.value.nodes[N];
2374
+ if (!_) return null;
2375
+ const F = t.editor.api.value.overlay.getNodeScreenRect(N);
2376
+ if (!F) return null;
2377
+ const ae = O(_);
2378
+ return ae.showActions === !1 ? null : {
2379
+ node: _,
2380
+ position: { x: F.x + F.width, y: F.y + F.height + 4 },
2381
+ behavior: ae
2382
+ };
2383
+ }), f = j(() => {
2384
+ if (G.value, !t.editor.api.value || t.editor.mode.value !== "edit") return null;
2385
+ const N = K.value;
2386
+ if (N.nodeIds.length + N.edgeIds.length <= 1) return null;
2387
+ const I = t.editor.api.value.getSelectionBounds(N);
1746
2388
  if (!I) return null;
1747
- const _ = t.editor.schema.nodeTypes[c.type]?.getBehavior?.(c, {
1748
- api: t.editor.api.value,
1749
- flowModel: x,
1750
- history: t.editor.history,
1751
- mode: t.editor.mode.value
1752
- }) ?? {};
1753
- return _.showActions === !1 ? null : {
1754
- node: c,
2389
+ const _ = it(N, t.editor.flowModel.value, O);
2390
+ return {
1755
2391
  position: { x: I.x + I.width, y: I.y + I.height + 4 },
1756
- behavior: _
2392
+ canDelete: _.nodeIds.length > 0 || _.edgeIds.length > 0
1757
2393
  };
1758
- }), H = F(
1759
- () => ({
1760
- enabled: !0,
1761
- tooltipText: "",
1762
- portGroup: "right",
1763
- ...t.quickAdd
1764
- })
1765
- ), Q = F(() => {
1766
- if (L.value, !H.value.enabled) return null;
1767
- const y = w.value;
1768
- if (!y || f.value || !t.editor.api.value || t.editor.mode.value !== "edit") return null;
1769
- const x = t.editor.flowModel.value, c = x.nodes[y];
1770
- if (!c) return null;
1771
- const P = t.editor.schema.nodeTypes[c.type]?.getBehavior?.(c, {
1772
- api: t.editor.api.value,
1773
- flowModel: x,
1774
- history: t.editor.history,
1775
- mode: t.editor.mode.value
1776
- }) ?? {};
1777
- if (P.quickAddEnabled === !1) return null;
1778
- const _ = te(c);
1779
- return _ ? {
1780
- node: c,
1781
- portId: _.portId,
1782
- portGroup: _.portGroup,
1783
- portPosition: _.portPosition,
1784
- behavior: P
1785
- } : null;
1786
- }), de = O();
1787
- function re(y) {
1788
- N.value = !0;
1789
- const x = Q.value;
1790
- x && o("ui-event", {
1791
- type: "node.quick-add",
1792
- nodeId: y,
1793
- position: x.portPosition
1794
- });
2394
+ }), d = q(), c = Xt({
2395
+ editor: t.editor,
2396
+ quickAddProp: j(() => t.quickAdd),
2397
+ isDraggingNode: S,
2398
+ nodeHover: m,
2399
+ isSelectionModeActive: W,
2400
+ viewportVersion: G,
2401
+ getNodeBehavior: O,
2402
+ getInsertGap: () => z.value.insertGap,
2403
+ closePopover: () => d.value?.closePopover()
2404
+ }), v = c.data, b = c.handleOpen, E = c.handleClose, B = c.handleStartDrag, X = c.handleOverlayEnter, C = c.handleOverlayLeave, L = c.handleInsert, w = Zt({
2405
+ editor: t.editor,
2406
+ edgeDropProp: j(() => t.edgeDrop)
2407
+ }), A = Qt(t.editor);
2408
+ function H(N, I) {
2409
+ A.handleNodeAction(N, I, z.value.insertGap) && (k.value = null);
2410
+ }
2411
+ function Z(N) {
2412
+ N === "delete" && A.deleteSelection(K.value);
2413
+ }
2414
+ function V(N) {
2415
+ if (t.editor.mode.value !== "edit") return;
2416
+ t.editor._pluginManager.dispatchKeyboardShortcut(N) && (N.preventDefault(), N.stopPropagation());
1795
2417
  }
1796
- function ce() {
1797
- N.value = !1;
1798
- }
1799
- function ue(y) {
1800
- const x = t.editor.api.value;
1801
- if (!x) return;
1802
- const I = t.editor.flowModel.value.nodes[y];
1803
- if (!I) return;
1804
- const P = te(I);
1805
- P && x.startConnection(y, P.portId);
1806
- }
1807
- function Ie(y, x) {
1808
- const c = t.editor.api.value;
1809
- if (!c) return;
1810
- const I = x.id || t.editor.idGenerator("node"), P = { ...x, id: I }, _ = t.editor.flowModel.value.nodes[y];
1811
- if (!_) return;
1812
- c.insertNodeToRight(y, P, {
1813
- autoWireEdges: !0,
1814
- direction: ye(_),
1815
- gap: q.value.insertGap,
1816
- source: "user:quick-add",
1817
- label: "快捷插入节点"
1818
- }).status === "applied" && o("ui-event", { type: "node.action.quick-insert", sourceNodeId: y, newNodeId: I }), de.value?.closePopover();
1819
- }
1820
- function se(y) {
1821
- return {
1822
- id: t.editor.idGenerator("node"),
1823
- type: y.type,
1824
- label: y.label,
1825
- ports: y.ports ? JSON.parse(JSON.stringify(y.ports)) : void 0,
1826
- payload: y.payload ? JSON.parse(JSON.stringify(y.payload)) : void 0,
1827
- extensions: y.extensions ? JSON.parse(JSON.stringify(y.extensions)) : void 0
2418
+ function ee(N, I) {
2419
+ const _ = r, F = (ae) => {
2420
+ const de = _.isRubberbandEnabled?.() ?? !1;
2421
+ de && _.disableRubberband?.(), ae ? r.enablePanning() : r.disablePanning(), de && _.enableRubberband?.();
1828
2422
  };
1829
- }
1830
- function Me(y, x) {
1831
- const c = t.editor, I = c.api.value;
1832
- switch (y) {
1833
- case "delete": {
1834
- c.executeCommand({
1835
- id: W(),
1836
- source: "user:toolbar",
1837
- label: "删除节点",
1838
- timestamp: Date.now(),
1839
- commands: [{ type: "node.remove", nodeId: x }]
1840
- }), o("ui-event", { type: "node.action.delete", nodeId: x }), v.value = null;
1841
- break;
1842
- }
1843
- case "copy": {
1844
- if (!I) break;
1845
- const P = c.flowModel.value.nodes[x];
1846
- if (!P) break;
1847
- const _ = se(P);
1848
- I.insertNodeToRight(x, _, {
1849
- autoWireEdges: !1,
1850
- gap: q.value.insertGap,
1851
- label: "复制节点"
1852
- }), o("ui-event", { type: "node.action.copy", sourceNodeId: x, newNodeId: _.id });
1853
- break;
1854
- }
1855
- case "copy-insert": {
1856
- if (!I) break;
1857
- const P = c.flowModel.value.nodes[x];
1858
- if (!P) break;
1859
- const _ = se(P);
1860
- I.insertNodeToRight(x, _, {
1861
- autoWireEdges: !0,
1862
- gap: q.value.insertGap,
1863
- label: "复制并插入节点"
1864
- }), o("ui-event", { type: "node.action.copy-insert", sourceNodeId: x, newNodeId: _.id });
1865
- break;
1866
- }
1867
- case "disconnect": {
1868
- const P = c.flowModel.value, _ = Object.entries(P.edges).filter(([, $]) => {
1869
- const J = $;
1870
- return J.source.nodeId === x || J.target.nodeId === x;
1871
- }).map(([$]) => $);
1872
- if (_.length === 0) break;
1873
- c.executeCommand({
1874
- id: W(),
1875
- source: "user:toolbar",
1876
- label: "断开连线",
1877
- timestamp: Date.now(),
1878
- commands: _.map(($) => ({ type: "edge.remove", edgeId: $ }))
1879
- }), o("ui-event", { type: "node.action.disconnect", nodeId: x, edgeIds: _ });
1880
- break;
2423
+ N && I ? (_.enableSelection?.(), m.reset(), c.quickAddNodeId.value = null, c.quickAddPopoverOpen.value = !1, u?.remove(), F(!1), _.enableRubberband?.()) : (_.disableRubberband?.(), F(!0), _.disableSelection?.(), _.cleanSelection?.());
2424
+ }
2425
+ function Q(N) {
2426
+ r.on("node:move", ({ node: I }) => {
2427
+ S.value = !0;
2428
+ const _ = t.editor.flowModel.value.nodes[I.id];
2429
+ _ && O(_).bringToFrontOnDrag === !1 || I.toFront?.();
2430
+ }), r.on("node:moved", () => {
2431
+ S.value = !1;
2432
+ }), r.on("node:mouseenter", ({ node: I }) => {
2433
+ if (W.value) {
2434
+ k.value = null, c.quickAddNodeId.value = null, N.hideNodePorts(I);
2435
+ return;
1881
2436
  }
1882
- case "debug": {
1883
- o("ui-event", { type: "node.action.debug", nodeId: x });
1884
- break;
2437
+ m.enter(I.id);
2438
+ const _ = t.editor.flowModel.value.nodes[I.id];
2439
+ if (_ && O(_).showPorts === !1) {
2440
+ c.mergedConfig.value.enabled && c.enter(I.id);
2441
+ return;
1885
2442
  }
1886
- }
1887
- }
1888
- function ie(y) {
1889
- if (!H.value.enabled || t.editor.mode.value !== "edit") return !1;
1890
- const x = t.editor.flowModel.value, c = x.nodes[y];
1891
- return !c || (t.editor.schema.nodeTypes[c.type]?.getBehavior?.(c, {
1892
- api: t.editor.api.value,
1893
- flowModel: x,
1894
- history: t.editor.history,
1895
- mode: t.editor.mode.value
1896
- }) ?? {}).quickAddEnabled === !1 ? !1 : !!te(c);
1897
- }
1898
- function $e(y) {
1899
- const x = t.editor.schema.nodeTypes[y.type];
1900
- return Fe(y, x?.getPorts);
1901
- }
1902
- function ae(y) {
1903
- return y === "top" || y === "right" || y === "bottom" || y === "left";
1904
- }
1905
- function Z(y, x) {
1906
- const c = H.value.getPort?.(y, x);
1907
- if (!c) return null;
1908
- const I = typeof c == "string" ? c : c.id;
1909
- return x.find((P) => P.id === I) ?? null;
1910
- }
1911
- function we(y, x) {
1912
- const c = t.editor.api.value?.overlay.getNodeScreenRect(y);
1913
- if (!c) return null;
1914
- switch (x) {
1915
- case "top":
1916
- return { x: c.x + c.width / 2, y: c.y };
1917
- case "bottom":
1918
- return { x: c.x + c.width / 2, y: c.y + c.height };
1919
- case "left":
1920
- return { x: c.x, y: c.y + c.height / 2 };
1921
- case "right":
1922
- return { x: c.x + c.width, y: c.y + c.height / 2 };
1923
- default:
1924
- return null;
1925
- }
1926
- }
1927
- function ve(y, x, c) {
1928
- const I = i.getCellById(y);
1929
- if (I?.isNode()) {
1930
- const P = I, _ = i.findViewByCell(P), $ = _?.findPortElem(x, "circle") ?? _?.findPortElem(x);
1931
- if ($) {
1932
- const J = i.container.getBoundingClientRect(), le = $.getBoundingClientRect();
1933
- return {
1934
- x: le.left - J.left + le.width / 2,
1935
- y: le.top - J.top + le.height / 2
1936
- };
2443
+ c.mergedConfig.value.enabled && c.enter(I.id) || N.showNodePorts(I);
2444
+ }), r.on("node:mouseleave", ({ node: I }) => {
2445
+ if (W.value) {
2446
+ N.hideNodePorts(I);
2447
+ return;
1937
2448
  }
1938
- }
1939
- return we(y, c);
1940
- }
1941
- function te(y) {
1942
- const x = $e(y), c = Z(y, x) ?? x.find((P) => P.group === H.value.portGroup) ?? null;
1943
- if (!c) return null;
1944
- const I = ve(y.id, c.id, c.group);
1945
- return I ? {
1946
- portId: c.id,
1947
- portGroup: c.group,
1948
- portPosition: I
1949
- } : null;
1950
- }
1951
- function ye(y) {
1952
- const x = te(y), c = H.value.insertDirection;
1953
- if (typeof c == "function") {
1954
- const I = c(
1955
- y,
1956
- x ? { id: x.portId, group: x.portGroup } : null
1957
- );
1958
- if (I) return I;
1959
- } else if (c)
1960
- return c;
1961
- return x && ae(x.portGroup) ? x.portGroup : ae(H.value.portGroup) ? H.value.portGroup : "right";
1962
- }
1963
- function Ne(y) {
1964
- if (t.editor.mode.value !== "edit") return;
1965
- t.editor._pluginManager.dispatchKeyboardShortcut(y) && (y.preventDefault(), y.stopPropagation());
1966
- }
1967
- function xe() {
1968
- return {
1969
- refX: 0,
1970
- children: [
1971
- {
1972
- tagName: "path",
1973
- d: "M -16 -5 L -8 0 L -16 5 Z",
1974
- transform: "rotate(0)"
1975
- },
1976
- {
1977
- tagName: "circle",
1978
- cx: 0,
1979
- cy: 0,
1980
- r: 8,
1981
- fill: "#3a84ff",
1982
- stroke: "#3a84ff",
1983
- transform: "rotate(0)"
1984
- }
1985
- ]
1986
- };
2449
+ const _ = t.editor.flowModel.value.nodes[I.id];
2450
+ let F = 100;
2451
+ _ && O(_).actionsOffset && (F = 300), m.leave(F), c.mergedConfig.value.enabled ? c.quickAddNodeId.value === I.id && !c.quickAddPopoverOpen.value ? c.leave() : c.quickAddNodeId.value !== I.id && N.hideNodePorts(I) : N.hideNodePorts(I);
2452
+ });
1987
2453
  }
1988
- function K(y) {
1989
- const x = t.editor.schema.defaultEdgeType ?? "default", c = t.editor.schema.edgeTypes?.[x], I = {
1990
- zIndex: -1,
1991
- attrs: {
1992
- line: {
1993
- stroke: "#abb5cc",
1994
- strokeWidth: 2,
1995
- targetMarker: { name: "block", width: 8, height: 8 }
2454
+ function oe(N) {
2455
+ r.on("edge:added", ({ edge: I }) => {
2456
+ let _;
2457
+ if (t.getConnectionExcludedNodeIds && !I.getTargetCell()) {
2458
+ const F = I.getSourceCell();
2459
+ if (F) {
2460
+ const ae = t.getConnectionExcludedNodeIds(F.id);
2461
+ _ = ae instanceof Set ? ae : new Set(ae);
1996
2462
  }
1997
2463
  }
1998
- };
1999
- c?.router && (I.router = typeof c.router == "string" ? { name: c.router } : c.router), c?.connector && (I.connector = typeof c.connector == "string" ? { name: c.connector } : c.connector), c?.x6EdgeConfig && Object.assign(I, c.x6EdgeConfig);
2000
- const P = I.attrs ?? {}, _ = P.line ?? {};
2001
- return I.attrs = {
2002
- ...P,
2003
- line: {
2004
- ..._,
2005
- targetMarker: xe()
2464
+ N.handleEdgeAdded(I, _);
2465
+ }), r.on("edge:connected", () => {
2466
+ N.handleEdgeConnected();
2467
+ }), r.on("edge:removed", ({ edge: I }) => {
2468
+ N.handleEdgeRemoved(I.id), u.handleEdgeRemoved(I.id);
2469
+ }), r.on("edge:mouseenter", ({ edge: I, e: _ }) => {
2470
+ const F = l.getHoveredEdgeId();
2471
+ l.setHoveredEdge(I.id), F && F !== I.id && l.refreshSingleEdgeStyle(F), l.refreshSingleEdgeStyle(I.id), t.editor.mode.value === "edit" && !W.value && N.canShowEdgeTool() && u.show(I.id, _);
2472
+ }), r.on("edge:mouseleave", ({ edge: I }) => {
2473
+ l.setHoveredEdge(null), l.refreshSingleEdgeStyle(I.id), u.remove();
2474
+ }), r.on("edge:click", ({ edge: I, e: _ }) => {
2475
+ _.target?.closest?.(".flow-canvas-edge-delete-tool") && t.editor.mode.value === "edit" && (u.remove(), t.editor.executeCommand({
2476
+ id: te(),
2477
+ source: "user:toolbar",
2478
+ label: "删除连线",
2479
+ timestamp: Date.now(),
2480
+ commands: [{ type: "edge.remove", edgeId: I.id }]
2481
+ }));
2482
+ }), g = (I) => u.move(I), r.container.addEventListener("mousemove", g);
2483
+ }
2484
+ function ie() {
2485
+ p = (N) => {
2486
+ if (!k.value && !c.quickAddNodeId.value) return;
2487
+ const I = N.target;
2488
+ if (I?.closest?.(".x6-node") || I?.closest?.(".flow-canvas-node-actions") || I?.closest?.(".flow-canvas-quick-add")) {
2489
+ m.cancelLeave(), c.cancelLeave();
2490
+ return;
2006
2491
  }
2007
- }, y.createEdge(I);
2492
+ m.leave(180), c.quickAddPopoverOpen.value || c.leave();
2493
+ }, n.value?.addEventListener("mousemove", p), x = () => {
2494
+ m.reset(), c.quickAddPopoverOpen.value || (c.quickAddNodeId.value = null);
2495
+ }, n.value?.addEventListener("mouseleave", x), n.value?.addEventListener("keydown", V);
2008
2496
  }
2009
- return at(() => {
2010
- if (!r.value) return;
2011
- const y = /* @__PURE__ */ new Set(["model", "container"]), x = {};
2497
+ function ne() {
2498
+ pe(
2499
+ () => t.editor.flowModel.value,
2500
+ (N) => l.syncFlowModel(N)
2501
+ ), pe(
2502
+ [() => t.editor.mode.value, () => t.editor.selectionMode.value],
2503
+ ([N, I]) => {
2504
+ ee(N === "edit", I);
2505
+ },
2506
+ { immediate: !0 }
2507
+ );
2508
+ }
2509
+ return ot(() => {
2510
+ if (!i.value) return;
2511
+ const N = /* @__PURE__ */ new Set(["model", "container"]), I = {};
2012
2512
  if (t.graphOptions)
2013
- for (const [u, k] of Object.entries(t.graphOptions)) {
2014
- if (y.has(u)) {
2015
- console.warn(`[flow-canvas] graphOptions.${u} is managed by the engine and will be ignored`);
2513
+ for (const [$, re] of Object.entries(t.graphOptions)) {
2514
+ if (N.has($)) {
2515
+ console.warn(`[flow-canvas] graphOptions.${$} is managed by the engine and will be ignored`);
2016
2516
  continue;
2017
2517
  }
2018
- x[u] = k;
2518
+ I[$] = re;
2019
2519
  }
2020
- i = new ut({
2021
- container: r.value,
2520
+ r = new ft({
2521
+ container: i.value,
2022
2522
  autoResize: !0,
2023
2523
  background: { color: "#edf2fc" },
2024
2524
  grid: { visible: !0, size: 20, type: "dot" },
2025
2525
  highlighting: {
2026
- // 连接吸附到 port 时不再叠加 X6 默认橙色高亮,由业务层自行控制端口视觉。
2027
2526
  magnetAdsorbed: { name: "className", args: { className: "flow-canvas-magnet-adsorbed" } }
2028
2527
  },
2029
2528
  panning: { enabled: !0 },
2030
2529
  mousewheel: { enabled: !0, modifiers: ["ctrl", "meta"] },
2031
2530
  interacting: {
2032
- nodeMovable(u) {
2033
- return u.cell.getProp("draggable") !== !1;
2531
+ nodeMovable($) {
2532
+ return $.cell.getProp("draggable") !== !1;
2034
2533
  }
2035
2534
  },
2036
2535
  connecting: {
@@ -2044,16 +2543,16 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
2044
2543
  connectionPoint: "anchor",
2045
2544
  snap: { radius: 30 },
2046
2545
  createEdge() {
2047
- return K(this);
2546
+ return eo(this, t.editor.schema);
2048
2547
  }
2049
2548
  },
2050
- ...x
2051
- }), a = new Tt(), l = new At(
2052
- i,
2549
+ ...I
2550
+ }), a = new Bt(), l = new $t(
2551
+ r,
2053
2552
  t.editor.schema,
2054
2553
  a,
2055
- (u) => t.editor._pluginManager.collectNodeDecorations(u),
2056
- (u) => t.editor._pluginManager.collectEdgeDecorations(u),
2554
+ ($) => t.editor._pluginManager.collectNodeDecorations($),
2555
+ ($) => t.editor._pluginManager.collectEdgeDecorations($),
2057
2556
  () => t.editor.api.value ? {
2058
2557
  api: t.editor.api.value,
2059
2558
  flowModel: t.editor.flowModel.value,
@@ -2061,313 +2560,210 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
2061
2560
  mode: t.editor.mode.value
2062
2561
  } : null
2063
2562
  );
2064
- const c = $t(i), I = Bt({
2065
- graph: i,
2066
- overlayManager: c,
2067
- executeCommand: (u) => t.editor.executeCommand(u),
2563
+ const _ = Gt(r), F = zt({
2564
+ graph: r,
2565
+ overlayManager: _,
2566
+ executeCommand: ($) => t.editor.executeCommand($),
2068
2567
  schema: t.editor.schema,
2069
2568
  flowModel: t.editor.flowModel,
2569
+ getNodeBehavior: O,
2070
2570
  idGenerator: t.editor.idGenerator,
2071
2571
  defaultInsertGap: t.nodeActions?.insertGap,
2072
- getContextMenuItems: (u) => t.editor._pluginManager.collectContextMenuItems(u),
2073
- onHighlightChange: (u, k) => {
2074
- l.setHighlightedNodes(u), l.setHighlightedEdges(k), l.refreshNodeHighlights(), l.refreshEdgeStyles();
2572
+ getContextMenuItems: ($) => t.editor._pluginManager.collectContextMenuItems($),
2573
+ onHighlightChange: ($, re) => {
2574
+ l.setHighlightedNodes($);
2575
+ const ce = l.setHighlightedEdges(re);
2576
+ l.refreshNodeHighlights();
2577
+ const ve = new Set(re);
2578
+ for (const ye of ce)
2579
+ ve.has(ye) || l.refreshSingleEdgeStyle(ye);
2580
+ for (const ye of ve)
2581
+ ce.has(ye) || l.refreshSingleEdgeStyle(ye);
2075
2582
  },
2076
- resolveNodeShape: (u) => {
2077
- const k = t.editor.schema.nodeTypes[u];
2078
- if (!k) return null;
2079
- const A = a.registerNodeType(u, k.component), V = k.getSize({ id: "", type: u, position: { x: 0, y: 0 } });
2080
- return { shapeName: A, width: V.width, height: V.height };
2583
+ resolveNodeShape: ($) => {
2584
+ const re = t.editor.schema.nodeTypes[$];
2585
+ if (!re) return null;
2586
+ const ce = a.registerNodeType($, re.component), ve = re.getSize({ id: "", type: $, position: { x: 0, y: 0 } });
2587
+ return { shapeName: ce, width: ve.width, height: ve.height };
2081
2588
  }
2082
2589
  });
2083
- t.editor.api.value = I;
2084
- const P = {
2590
+ t.editor.api.value = F;
2591
+ const ae = {
2085
2592
  flowModel: t.editor.flowModel,
2086
2593
  history: t.editor.history,
2087
2594
  schema: t.editor.schema,
2088
2595
  mode: t.editor.mode,
2089
2596
  idGenerator: t.editor.idGenerator,
2090
2597
  executeCommand: t.editor.executeCommand,
2091
- api: I,
2092
- overlay: c,
2093
- graph: i
2598
+ selectionMode: t.editor.selectionMode,
2599
+ api: F,
2600
+ overlay: _,
2601
+ graph: r
2094
2602
  };
2095
- t.editor._pluginManager.attachRuntime(P);
2096
- const _ = t.editor._pluginManager.collectExtendedApi();
2097
- Object.assign(t.editor.extendedApi, _), g = new Rt(
2098
- i,
2099
- (u) => {
2100
- (u.type === "node.click" || u.type === "node.dblclick" || u.type === "node.contextmenu") && d.enter(u.nodeId), t.editor._pluginManager.dispatchUiEvent(u), o("ui-event", u);
2603
+ t.editor._pluginManager.attachRuntime(ae);
2604
+ const de = t.editor._pluginManager.collectExtendedApi();
2605
+ Object.assign(t.editor.extendedApi, de), t.editor._emitUiEvent = ($) => {
2606
+ t.editor._pluginManager.dispatchUiEvent($), o("ui-event", $);
2607
+ }, h = new Ht(
2608
+ r,
2609
+ ($) => {
2610
+ ($.type === "node.click" || $.type === "node.dblclick" || $.type === "node.contextmenu") && m.enter($.nodeId), t.editor._emitUiEvent($);
2101
2611
  },
2102
- (u) => {
2612
+ ($) => {
2103
2613
  if (l.isSyncing) return;
2104
- if (t.editor.executeCommand(u).status !== "applied") {
2105
- for (const A of u.commands)
2106
- if (A.type === "edge.add") {
2107
- const V = i.getCellById(A.edge.id);
2108
- V && i.removeCell(V);
2614
+ const re = w.tryExpandForEdgeDrop($);
2615
+ if (t.editor.executeCommand(re).status !== "applied") {
2616
+ for (const ve of re.commands)
2617
+ if (ve.type === "edge.add") {
2618
+ const ye = r.getCellById(ve.edge.id);
2619
+ ye && r.removeCell(ye);
2109
2620
  }
2110
2621
  }
2111
2622
  },
2112
2623
  t.editor.flowModel,
2113
2624
  t.editor.idGenerator
2114
- ), G = Gt(i);
2115
- const $ = zt(i), J = i, le = (u) => {
2116
- const k = J.isRubberbandEnabled?.() ?? !1;
2117
- k && J.disableRubberband?.(), u ? i.enablePanning() : i.disablePanning(), k && J.enableRubberband?.();
2118
- }, Le = () => {
2119
- L.value++;
2120
- };
2121
- i.on("translate", Le), i.on("scale", Le), i.on("resize", Le), i.on("node:move", ({ node: u }) => {
2122
- f.value = !0;
2123
- const k = t.editor.flowModel.value.nodes[u.id];
2124
- k && t.editor.api.value && t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k, {
2125
- api: t.editor.api.value,
2126
- flowModel: t.editor.flowModel.value,
2127
- history: t.editor.history,
2128
- mode: t.editor.mode.value
2129
- })?.bringToFrontOnDrag === !1 || u.toFront?.();
2130
- }), i.on("node:moved", () => {
2131
- f.value = !1;
2132
- }), i.on("node:mouseenter", ({ node: u }) => {
2133
- d.enter(u.id);
2134
- const k = t.editor.flowModel.value.nodes[u.id];
2135
- if (k && t.editor.api.value && t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k, {
2136
- api: t.editor.api.value,
2137
- flowModel: t.editor.flowModel.value,
2138
- history: t.editor.history,
2139
- mode: t.editor.mode.value
2140
- })?.showPorts === !1) {
2141
- H.value.enabled && D(u.id);
2142
- return;
2143
- }
2144
- H.value.enabled && D(u.id) || $.showNodePorts(u);
2145
- }), i.on("node:mouseleave", ({ node: u }) => {
2146
- const k = t.editor.flowModel.value.nodes[u.id];
2147
- let A = 100;
2148
- k && t.editor.api.value && t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k, {
2149
- api: t.editor.api.value,
2150
- flowModel: t.editor.flowModel.value,
2151
- history: t.editor.history,
2152
- mode: t.editor.mode.value
2153
- })?.actionsOffset && (A = 300), d.leave(A), H.value.enabled ? w.value === u.id && !N.value ? z() : w.value !== u.id && $.hideNodePorts(u) : $.hideNodePorts(u);
2154
- });
2155
- function st(u) {
2156
- const k = i.getCellById(u);
2157
- if (!k?.isNode()) return;
2158
- const A = k, V = t.editor.flowModel.value.nodes[u];
2159
- if (!V) return;
2160
- const Be = te(V);
2161
- let qe = !0;
2162
- t.editor.api.value && t.editor.schema.nodeTypes[V.type]?.getBehavior?.(V, {
2163
- api: t.editor.api.value,
2164
- flowModel: t.editor.flowModel.value,
2165
- history: t.editor.history,
2166
- mode: t.editor.mode.value
2167
- })?.hidePortForQuickAdd === !1 && (qe = !1);
2168
- const it = qe && !f.value && !!Be && ie(u);
2169
- for (const Oe of A.getPorts()) {
2170
- const Ue = it && Oe.id === Be?.portId ? "hidden" : "visible";
2171
- A.setPortProp(Oe.id, "attrs/circle/visibility", Ue);
2172
- }
2173
- }
2174
- fe(
2175
- [w, f],
2176
- ([u], [k]) => {
2177
- if (k && k !== u) {
2178
- const A = i.getCellById(k);
2179
- A?.isNode() && $.hideNodePorts(A);
2180
- }
2181
- u && st(u);
2182
- },
2183
- { flush: "sync" }
2184
- ), fe(Q, (u) => {
2185
- u || (N.value = !1);
2186
- }), i.on("edge:added", ({ edge: u }) => {
2187
- let k;
2188
- if (t.getConnectionExcludedNodeIds && !u.getTargetCell()) {
2189
- const A = u.getSourceCell();
2190
- if (A) {
2191
- const V = t.getConnectionExcludedNodeIds(A.id);
2192
- k = V instanceof Set ? V : new Set(V);
2193
- }
2194
- }
2195
- $.handleEdgeAdded(u, k);
2196
- }), i.on("edge:connected", () => {
2197
- $.handleEdgeConnected();
2198
- }), i.on("edge:removed", ({ edge: u }) => {
2199
- $.handleEdgeRemoved(u.id), G.handleEdgeRemoved(u.id);
2200
- }), i.on("selection:changed", () => {
2201
- const u = i.getSelectedCells?.() ?? [], k = {
2202
- nodeIds: u.filter((A) => A.isNode()).map((A) => A.id),
2203
- edgeIds: u.filter((A) => A.isEdge()).map((A) => A.id)
2204
- };
2205
- t.editor._pluginManager.dispatchSelectionChange(k), o("ui-event", {
2625
+ ), u = Wt(r);
2626
+ const J = Vt(r);
2627
+ c.attachRuntime(r, ($) => J.hideNodePorts($)), w.attachRuntime(r), Q(J), oe(J);
2628
+ let Ae = /* @__PURE__ */ new Set();
2629
+ r.on("selection:changed", () => {
2630
+ const $ = st(r.getSelectedCells?.() ?? []);
2631
+ K.value = $, t.editor._pluginManager.dispatchSelectionChange($), o("ui-event", {
2206
2632
  type: "selection.change",
2207
- nodeIds: k.nodeIds,
2208
- edgeIds: k.edgeIds
2209
- }), l.refreshEdgeStyles();
2210
- }), i.on("edge:mouseenter", ({ edge: u, e: k }) => {
2211
- l.setHoveredEdge(u.id), l.refreshEdgeStyles(), t.editor.mode.value === "edit" && $.canShowEdgeTool() && G.show(u.id, k);
2212
- }), T = (u) => G.move(u), i.container.addEventListener("mousemove", T), h = (u) => {
2213
- if (!v.value && !w.value) return;
2214
- const k = u.target;
2215
- if (k?.closest?.(".x6-node") || k?.closest?.(".flow-canvas-node-actions") || k?.closest?.(".flow-canvas-quick-add")) {
2216
- d.cancelLeave(), X();
2217
- return;
2218
- }
2219
- d.leave(180), N.value || z();
2220
- }, n.value?.addEventListener("mousemove", h), b = () => {
2221
- d.reset(), N.value || (w.value = null);
2222
- }, n.value?.addEventListener("mouseleave", b), i.on("edge:mouseleave", () => {
2223
- l.setHoveredEdge(null), l.refreshEdgeStyles(), G.remove();
2224
- }), i.on("edge:click", ({ edge: u, e: k }) => {
2225
- k.target?.closest?.(".flow-canvas-edge-delete-tool") && t.editor.mode.value === "edit" && (G.remove(), t.editor.executeCommand({
2226
- id: W(),
2227
- source: "user:toolbar",
2228
- label: "删除连线",
2229
- timestamp: Date.now(),
2230
- commands: [{ type: "edge.remove", edgeId: u.id }]
2231
- }));
2232
- }), n.value?.addEventListener("keydown", Ne), l.syncFlowModel(t.editor.flowModel.value), fe(
2233
- () => t.editor.flowModel.value,
2234
- (u) => l.syncFlowModel(u)
2235
- ), fe(
2236
- () => t.editor.selectionMode.value,
2237
- (u) => {
2238
- if (C?.(), C = null, u) {
2239
- le(!1), J.enableRubberband?.();
2240
- const k = () => {
2241
- i.container.removeEventListener("mouseup", k), C = null, setTimeout(() => {
2242
- t.editor.selectionMode.value && t.editor.setSelectionMode(!1);
2243
- }, 50);
2244
- };
2245
- i.container.addEventListener("mouseup", k), C = () => i.container.removeEventListener("mouseup", k);
2246
- } else
2247
- J.disableRubberband?.(), le(!0);
2248
- }
2249
- ), fe(
2250
- () => t.editor.mode.value,
2251
- (u) => {
2252
- const k = u === "edit";
2253
- le(!0), k ? J.enableSelection?.() : J.disableSelection?.();
2254
- }
2255
- );
2256
- }), ze(() => {
2257
- d.cleanup(), m && clearTimeout(m), G?.remove(), C?.(), T && i?.container?.removeEventListener("mousemove", T), h && n.value?.removeEventListener("mousemove", h), b && n.value?.removeEventListener("mouseleave", b), n.value?.removeEventListener("keydown", Ne), t.editor._pluginManager.detachRuntime(), t.editor.api.value = null;
2258
- for (const y of Object.keys(t.editor.extendedApi))
2259
- delete t.editor.extendedApi[y];
2260
- g?.dispose(), l?.dispose(), a?.dispose(), i?.dispose();
2261
- }), (y, x) => (M(), S("div", {
2633
+ nodeIds: $.nodeIds,
2634
+ edgeIds: $.edgeIds
2635
+ }), l.refreshNodeHighlights();
2636
+ const re = new Set($.edgeIds);
2637
+ for (const ce of Ae)
2638
+ re.has(ce) || l.refreshSingleEdgeStyle(ce);
2639
+ for (const ce of re)
2640
+ Ae.has(ce) || l.refreshSingleEdgeStyle(ce);
2641
+ Ae = re;
2642
+ });
2643
+ const Pe = () => {
2644
+ G.value++;
2645
+ };
2646
+ r.on("translate", Pe), r.on("scale", Pe), r.on("resize", Pe), ie(), l.syncFlowModel(t.editor.flowModel.value), ne();
2647
+ }), Me(() => {
2648
+ m.cleanup(), c.cleanup(), w.cleanup(), u?.remove(), g && r?.container?.removeEventListener("mousemove", g), p && n.value?.removeEventListener("mousemove", p), x && n.value?.removeEventListener("mouseleave", x), n.value?.removeEventListener("keydown", V), t.editor._pluginManager.detachRuntime(), t.editor.api.value = null;
2649
+ for (const N of Object.keys(t.editor.extendedApi))
2650
+ delete t.editor.extendedApi[N];
2651
+ h?.dispose(), l?.dispose(), a?.dispose(), r?.dispose();
2652
+ }), (N, I) => (D(), R("div", {
2262
2653
  ref_key: "rootRef",
2263
2654
  ref: n,
2264
- class: "flow-canvas-runtime-core",
2655
+ class: se(["flow-canvas-runtime-core", { "flow-canvas-runtime-core--selection-mode": W.value }]),
2265
2656
  tabindex: "0"
2266
2657
  }, [
2267
- B("div", {
2658
+ U("div", {
2268
2659
  ref_key: "containerRef",
2269
- ref: r,
2660
+ ref: i,
2270
2661
  class: "flow-canvas-runtime-core__graph"
2271
2662
  }, null, 512),
2272
- B("div", Qt, [
2273
- (M(!0), S(pe, null, Pe(R.value, (c) => (M(), S("div", {
2274
- key: `badge-${c.nodeId}`,
2663
+ U("div", fo, [
2664
+ (D(!0), R(me, null, Ie(M.value, (_) => (D(), R("div", {
2665
+ key: `badge-${_.nodeId}`,
2275
2666
  class: "flow-canvas-runtime-core__badge",
2276
- style: _e({ left: `${c.x}px`, top: `${c.y}px`, backgroundColor: c.badge.color })
2277
- }, me(c.badge.text), 5))), 128)),
2278
- Q.value ? (M(), De(Wt, {
2667
+ style: we({ left: `${_.x}px`, top: `${_.y}px`, backgroundColor: _.badge.color })
2668
+ }, ge(_.badge.text), 5))), 128)),
2669
+ le(v) ? (D(), be(ao, {
2279
2670
  key: 0,
2280
2671
  ref_key: "quickAddPopoverRef",
2281
- ref: de,
2282
- node: Q.value.node,
2283
- "port-position": Q.value.portPosition,
2284
- "tooltip-text": H.value.tooltipText,
2285
- onOpen: re,
2286
- onClose: ce,
2287
- onStartDrag: ue,
2288
- onMouseenter: j,
2289
- onMouseleave: oe
2672
+ ref: d,
2673
+ node: le(v).node,
2674
+ "port-position": le(v).portPosition,
2675
+ onOpen: le(b),
2676
+ onClose: le(E),
2677
+ onStartDrag: le(B),
2678
+ onMouseenter: le(X),
2679
+ onMouseleave: le(C)
2290
2680
  }, {
2291
- default: je(() => [
2292
- ke(y.$slots, "quick-add-panel", {
2293
- node: Q.value.node,
2681
+ default: He(() => [
2682
+ Ee(N.$slots, "quick-add-panel", {
2683
+ node: le(v).node,
2294
2684
  api: s.editor.api.value,
2295
- insertNodeToRight: (c) => Ie(Q.value.node.id, c),
2296
- closePopover: () => de.value?.closePopover()
2685
+ insertNodeToRight: (_) => le(L)(le(v).node.id, _),
2686
+ closePopover: () => d.value?.closePopover()
2297
2687
  }, void 0, !0)
2298
2688
  ]),
2299
2689
  _: 3
2300
- }, 8, ["node", "port-position", "tooltip-text"])) : U("", !0),
2301
- Y.value ? (M(), De(Ft, {
2690
+ }, 8, ["node", "port-position", "onOpen", "onClose", "onStartDrag", "onMouseenter", "onMouseleave"])) : Y("", !0),
2691
+ y.value ? (D(), be(no, {
2302
2692
  key: 1,
2303
- node: Y.value.node,
2304
- position: Y.value.position,
2305
- config: q.value,
2306
- behavior: Y.value.behavior,
2307
- "actions-offset": Y.value.behavior.actionsOffset,
2308
- onAction: Me,
2309
- onMouseenter: lt(p),
2310
- onMouseleave: E
2311
- }, null, 8, ["node", "position", "config", "behavior", "actions-offset", "onMouseenter"])) : U("", !0)
2693
+ node: y.value.node,
2694
+ position: y.value.position,
2695
+ config: z.value,
2696
+ behavior: y.value.behavior,
2697
+ "actions-offset": y.value.behavior.actionsOffset,
2698
+ onAction: H,
2699
+ onMouseenter: le(T),
2700
+ onMouseleave: P
2701
+ }, null, 8, ["node", "position", "config", "behavior", "actions-offset", "onMouseenter"])) : Y("", !0),
2702
+ f.value ? (D(), be(uo, {
2703
+ key: 2,
2704
+ position: f.value.position,
2705
+ "can-delete": f.value.canDelete,
2706
+ onAction: Z
2707
+ }, null, 8, ["position", "can-delete"])) : Y("", !0)
2312
2708
  ])
2313
- ], 512));
2709
+ ], 2));
2314
2710
  }
2315
- }), So = /* @__PURE__ */ he(Xt, [["__scopeId", "data-v-b37732f8"]]), Yt = { class: "flow-canvas-node-palette" }, Kt = ["data-node-type"], Zt = { class: "flow-canvas-node-palette__item-label" }, Jt = /* @__PURE__ */ ge({
2711
+ }), pn = /* @__PURE__ */ he(go, [["__scopeId", "data-v-ef705b28"]]), po = { class: "flow-canvas-node-palette" }, ho = ["data-node-type"], vo = { class: "flow-canvas-node-palette__item-label" }, yo = /* @__PURE__ */ fe({
2316
2712
  __name: "canvas-node-palette",
2317
2713
  props: {
2318
2714
  editor: {},
2319
2715
  items: {}
2320
2716
  },
2321
2717
  setup(s) {
2322
- const e = s, t = O(), o = F(() => e.items ? e.items : Object.keys(e.editor.schema.nodeTypes).map((n) => ({
2718
+ const e = s, t = q(), o = j(() => e.items ? e.items : Object.keys(e.editor.schema.nodeTypes).map((n) => ({
2323
2719
  type: n,
2324
2720
  label: n.charAt(0).toUpperCase() + n.slice(1)
2325
2721
  })));
2326
- return fe(
2722
+ return pe(
2327
2723
  [() => e.editor.api.value, o, t],
2328
- ([n, r, i], l, a) => {
2329
- if (!n || !i) return;
2330
- const g = [];
2331
- for (const d of r) {
2332
- const v = i.querySelector(`[data-node-type="${d.type}"]`);
2333
- if (!v) continue;
2334
- const f = n.registerDndSource(v, () => ({
2335
- id: W(),
2336
- type: d.type,
2337
- label: d.label,
2724
+ ([n, i, r], l, a) => {
2725
+ if (!n || !r) return;
2726
+ const h = [];
2727
+ for (const u of i) {
2728
+ const g = r.querySelector(`[data-node-type="${u.type}"]`);
2729
+ if (!g) continue;
2730
+ const p = n.registerDndSource(g, () => ({
2731
+ id: te(),
2732
+ type: u.type,
2733
+ label: u.label,
2338
2734
  position: { x: 0, y: 0 }
2339
2735
  }));
2340
- g.push(f);
2736
+ h.push(p);
2341
2737
  }
2342
2738
  a(() => {
2343
- for (const d of g) d();
2739
+ for (const u of h) u();
2344
2740
  });
2345
2741
  },
2346
2742
  { flush: "post" }
2347
- ), (n, r) => (M(), S("div", Yt, [
2348
- B("div", {
2743
+ ), (n, i) => (D(), R("div", po, [
2744
+ U("div", {
2349
2745
  ref_key: "listRef",
2350
2746
  ref: t,
2351
2747
  class: "flow-canvas-node-palette__list"
2352
2748
  }, [
2353
- (M(!0), S(pe, null, Pe(o.value, (i) => (M(), S("div", {
2354
- key: i.type,
2749
+ (D(!0), R(me, null, Ie(o.value, (r) => (D(), R("div", {
2750
+ key: r.type,
2355
2751
  class: "flow-canvas-node-palette__item",
2356
- "data-node-type": i.type
2752
+ "data-node-type": r.type
2357
2753
  }, [
2358
- i.icon ? (M(), S("i", {
2754
+ r.icon ? (D(), R("i", {
2359
2755
  key: 0,
2360
- class: ee([i.icon, "flow-canvas-node-palette__item-icon"])
2361
- }, null, 2)) : U("", !0),
2362
- B("span", Zt, me(i.label), 1)
2363
- ], 8, Kt))), 128))
2756
+ class: se([r.icon, "flow-canvas-node-palette__item-icon"])
2757
+ }, null, 2)) : Y("", !0),
2758
+ U("span", vo, ge(r.label), 1)
2759
+ ], 8, ho))), 128))
2364
2760
  ], 512)
2365
2761
  ]));
2366
2762
  }
2367
- }), eo = /* @__PURE__ */ he(Jt, [["__scopeId", "data-v-300314b7"]]), to = { class: "flow-canvas-layout" }, oo = { class: "flow-canvas-layout__main" }, no = { class: "flow-canvas-layout__content" }, so = {
2763
+ }), mo = /* @__PURE__ */ he(yo, [["__scopeId", "data-v-300314b7"]]), wo = { class: "flow-canvas-layout" }, bo = { class: "flow-canvas-layout__main" }, xo = { class: "flow-canvas-layout__content" }, Eo = {
2368
2764
  key: 0,
2369
2765
  class: "flow-canvas-layout__footer"
2370
- }, io = /* @__PURE__ */ ge({
2766
+ }, Io = /* @__PURE__ */ fe({
2371
2767
  __name: "canvas-layout",
2372
2768
  props: {
2373
2769
  sidebarCollapsed: { type: Boolean, default: !1 },
@@ -2379,33 +2775,33 @@ const jt = { class: "flow-canvas-node-actions__bar" }, Ht = /* @__PURE__ */ ge({
2379
2775
  },
2380
2776
  emits: ["update:sidebarCollapsed"],
2381
2777
  setup(s) {
2382
- return (e, t) => (M(), S("div", to, [
2383
- !s.hideSidebar && (e.$slots.sidebar || s.editor) ? (M(), S("aside", {
2778
+ return (e, t) => (D(), R("div", wo, [
2779
+ !s.hideSidebar && (e.$slots.sidebar || s.editor) ? (D(), R("aside", {
2384
2780
  key: 0,
2385
- class: ee(["flow-canvas-layout__sidebar", { "is-collapsed": s.sidebarCollapsed }]),
2386
- style: _e({ width: s.sidebarCollapsed ? "0px" : `${s.sidebarWidth}px` })
2781
+ class: se(["flow-canvas-layout__sidebar", { "is-collapsed": s.sidebarCollapsed }]),
2782
+ style: we({ width: s.sidebarCollapsed ? "0px" : `${s.sidebarWidth}px` })
2387
2783
  }, [
2388
- ke(e.$slots, "sidebar", {}, () => [
2389
- s.editor ? (M(), De(eo, {
2784
+ Ee(e.$slots, "sidebar", {}, () => [
2785
+ s.editor ? (D(), be(mo, {
2390
2786
  key: 0,
2391
2787
  editor: s.editor,
2392
2788
  items: s.paletteItems
2393
- }, null, 8, ["editor", "items"])) : U("", !0)
2789
+ }, null, 8, ["editor", "items"])) : Y("", !0)
2394
2790
  ], !0)
2395
- ], 6)) : U("", !0),
2396
- B("div", oo, [
2397
- B("div", no, [
2398
- ke(e.$slots, "default", {}, void 0, !0)
2791
+ ], 6)) : Y("", !0),
2792
+ U("div", bo, [
2793
+ U("div", xo, [
2794
+ Ee(e.$slots, "default", {}, void 0, !0)
2399
2795
  ]),
2400
- !s.hideFooter && e.$slots.footer ? (M(), S("div", so, [
2401
- ke(e.$slots, "footer", {}, void 0, !0)
2402
- ])) : U("", !0)
2796
+ !s.hideFooter && e.$slots.footer ? (D(), R("div", Eo, [
2797
+ Ee(e.$slots, "footer", {}, void 0, !0)
2798
+ ])) : Y("", !0)
2403
2799
  ])
2404
2800
  ]));
2405
2801
  }
2406
- }), Do = /* @__PURE__ */ he(io, [["__scopeId", "data-v-26f35b6b"]]), ro = ["undo", "redo"];
2407
- function ao(s) {
2408
- const e = new Set(s?.include), t = /* @__PURE__ */ new Set([...ro.filter((a) => !e.has(a)), ...s?.exclude ?? []]), o = [
2802
+ }), hn = /* @__PURE__ */ he(Io, [["__scopeId", "data-v-26f35b6b"]]), Co = ["undo", "redo"];
2803
+ function ko(s) {
2804
+ const e = new Set(s?.include), t = new Set(Co.filter((a) => !e.has(a))), o = [
2409
2805
  {
2410
2806
  id: "undo",
2411
2807
  type: "undo",
@@ -2439,22 +2835,6 @@ function ao(s) {
2439
2835
  description: "自动排版",
2440
2836
  order: 21
2441
2837
  },
2442
- {
2443
- id: "search",
2444
- type: "search",
2445
- group: "tools",
2446
- icon: "flow-canvas-icon canvas-search",
2447
- description: "搜索节点",
2448
- order: 22
2449
- },
2450
- {
2451
- id: "minimap",
2452
- type: "minimap",
2453
- group: "tools",
2454
- icon: "flow-canvas-icon canvas-map",
2455
- description: "缩略图",
2456
- order: 23
2457
- },
2458
2838
  {
2459
2839
  id: "export",
2460
2840
  type: "export",
@@ -2463,7 +2843,7 @@ function ao(s) {
2463
2843
  description: "导出为图片",
2464
2844
  order: 24
2465
2845
  }
2466
- ], r = [
2846
+ ], i = [
2467
2847
  {
2468
2848
  id: "zoom-out",
2469
2849
  type: "zoom-out",
@@ -2481,7 +2861,7 @@ function ao(s) {
2481
2861
  description: "放大画布",
2482
2862
  order: 32
2483
2863
  }
2484
- ], i = [
2864
+ ], r = [
2485
2865
  {
2486
2866
  id: "reset",
2487
2867
  type: "reset",
@@ -2493,15 +2873,15 @@ function ao(s) {
2493
2873
  ];
2494
2874
  return [...[...o, ...n].filter(
2495
2875
  (a) => !t.has(a.type)
2496
- ), ...r, ...i];
2876
+ ), ...i, ...r];
2497
2877
  }
2498
- const lo = { class: "flow-canvas-toolbar" }, co = {
2878
+ const So = { class: "flow-canvas-toolbar" }, Mo = {
2499
2879
  key: 0,
2500
2880
  class: "flow-canvas-toolbar__separator"
2501
- }, uo = { class: "flow-canvas-toolbar__group" }, fo = {
2881
+ }, No = { class: "flow-canvas-toolbar__group" }, _o = {
2502
2882
  key: 0,
2503
2883
  class: "flow-canvas-toolbar__zoom-display"
2504
- }, po = ["data-description", "disabled", "onClick"], go = ["textContent"], ho = /* @__PURE__ */ ge({
2884
+ }, Do = ["data-toolbar-id", "data-toolbar-type", "disabled", "onClick", "onMouseenter"], Ao = ["textContent"], Po = /* @__PURE__ */ fe({
2505
2885
  __name: "canvas-toolbar",
2506
2886
  props: {
2507
2887
  items: {},
@@ -2509,162 +2889,250 @@ const lo = { class: "flow-canvas-toolbar" }, co = {
2509
2889
  editor: {}
2510
2890
  },
2511
2891
  setup(s) {
2512
- const e = s, t = F(() => e.items ? e.items : ao({ exclude: e.exclude })), o = O(1);
2513
- let n = null;
2514
- fe(
2515
- () => e.editor.api.value,
2516
- (p) => {
2517
- n?.(), n = null, p && (o.value = p.getZoom(), n = p.onGraphEvent("scale", () => {
2518
- o.value = p.getZoom();
2892
+ const e = /* @__PURE__ */ new Set([
2893
+ "undo",
2894
+ "redo",
2895
+ "select",
2896
+ "auto-layout",
2897
+ "search",
2898
+ "minimap",
2899
+ "export"
2900
+ ]), t = /* @__PURE__ */ new Set(["select", "search", "minimap"]);
2901
+ function o(d) {
2902
+ return d.id.startsWith("plugin:") || d.type === "custom";
2903
+ }
2904
+ function n(d) {
2905
+ return d !== "custom" && t.has(d);
2906
+ }
2907
+ const i = s, r = j(() => {
2908
+ if (i.items) return i.items;
2909
+ const d = ko(), c = i.editor.toolbarItems.value, v = new Set(i.exclude ?? []), b = /* @__PURE__ */ new Map();
2910
+ for (const E of d)
2911
+ b.set(E.id, E);
2912
+ for (const E of c) {
2913
+ const B = b.get(E.id);
2914
+ B ? b.set(E.id, { ...B, ...E, order: B.order, group: B.group }) : o(E) && b.set(E.id, E);
2915
+ }
2916
+ return [...b.values()].filter((E) => E.type === "custom" || !e.has(E.type) ? !0 : !v.has(E.type)).sort((E, B) => (E.order ?? 0) - (B.order ?? 0));
2917
+ }), l = q(1), a = q(null), h = q(null), u = q(!1);
2918
+ let g = null;
2919
+ pe(
2920
+ () => i.editor.api.value,
2921
+ (d) => {
2922
+ g?.(), g = null, d && (l.value = d.getZoom(), g = d.onGraphEvent("scale", () => {
2923
+ l.value = d.getZoom();
2519
2924
  }));
2520
2925
  },
2521
2926
  { immediate: !0 }
2522
- ), et(() => {
2523
- n?.();
2927
+ );
2928
+ const p = at({ visible: !1, text: "", x: 0, y: 0 });
2929
+ function x(d, c) {
2930
+ if (!c.description) return;
2931
+ const b = d.currentTarget.getBoundingClientRect();
2932
+ p.text = c.description, p.visible = !0, Oe(() => {
2933
+ const E = a.value?.offsetWidth ?? 0, B = a.value?.offsetHeight ?? 0;
2934
+ p.x = b.left + b.width / 2 - E / 2, p.y = b.top - B - 6;
2935
+ });
2936
+ }
2937
+ function m() {
2938
+ p.visible = !1, a.value = null;
2939
+ }
2940
+ Je(() => {
2941
+ g?.();
2524
2942
  });
2525
- const r = F(() => `${Math.round(o.value * 100)}%`), i = F(() => e.editor.api.value ? {
2526
- api: e.editor.api.value,
2527
- flowModel: e.editor.flowModel.value,
2528
- history: e.editor.history,
2529
- mode: e.editor.mode.value
2943
+ const k = j(() => `${Math.round(l.value * 100)}%`), S = j(() => i.editor.api.value ? {
2944
+ api: i.editor.api.value,
2945
+ flowModel: i.editor.flowModel.value,
2946
+ history: i.editor.history,
2947
+ mode: i.editor.mode.value
2530
2948
  } : null);
2531
- function l(p) {
2532
- return p.visible === !1 ? !1 : typeof p.visible == "function" ? i.value ? p.visible(i.value) : !1 : !0;
2949
+ function T(d) {
2950
+ return d.visible === !1 ? !1 : typeof d.visible == "function" ? S.value ? d.visible(S.value) : !1 : !0;
2533
2951
  }
2534
- function a(p) {
2535
- return p.type === "select" ? e.editor.selectionMode.value : !1;
2952
+ function P(d) {
2953
+ return typeof d.active == "function" ? S.value ? d.active(S.value) : !1 : d.active !== void 0 ? d.active : d.type === "select" ? i.editor.selectionMode.value : !1;
2954
+ }
2955
+ const G = j(() => {
2956
+ const d = y.value.filter(
2957
+ (v) => n(v.type) && P(v)
2958
+ );
2959
+ if (d.length === 0) return null;
2960
+ const c = h.value;
2961
+ return c && d.some((v) => v.type === c) ? c : d[0]?.type ?? null;
2962
+ });
2963
+ function K(d) {
2964
+ return n(d.type) ? G.value === d.type : P(d);
2536
2965
  }
2537
- function g(p) {
2538
- return !i.value || p.disabled === !0 ? !0 : typeof p.disabled == "function" ? p.disabled(i.value) : p.type === "undo" ? !e.editor.history.canUndo.value : p.type === "redo" ? !e.editor.history.canRedo.value : !1;
2966
+ function O(d) {
2967
+ return !S.value || d.disabled === !0 ? !0 : typeof d.disabled == "function" ? d.disabled(S.value) : d.type === "undo" ? !i.editor.history.canUndo.value : d.type === "redo" ? !i.editor.history.canRedo.value : d.type === "export" ? u.value : !1;
2539
2968
  }
2540
- function d(p) {
2541
- if (!i.value || g(p)) return;
2542
- if (p.onClick) {
2543
- p.onClick(i.value);
2969
+ function W(d) {
2970
+ if (!(!S.value || !n(d.type) || !P(d))) {
2971
+ if (d.type === "select") {
2972
+ i.editor.setSelectionMode(!1);
2973
+ return;
2974
+ }
2975
+ d.onClick?.(S.value);
2976
+ }
2977
+ }
2978
+ function z(d) {
2979
+ if (n(d.type))
2980
+ for (const c of y.value)
2981
+ !n(c.type) || c.id === d.id || W(c);
2982
+ }
2983
+ function M(d) {
2984
+ if (!S.value || O(d)) return;
2985
+ if (n(d.type) && (h.value = d.type, z(d)), d.onClick) {
2986
+ d.onClick(S.value);
2544
2987
  return;
2545
2988
  }
2546
- const { api: E } = i.value;
2547
- switch (p.type) {
2989
+ const { api: c } = S.value;
2990
+ switch (d.type) {
2548
2991
  case "undo":
2549
- e.editor.history.undo();
2992
+ i.editor.history.undo();
2550
2993
  break;
2551
2994
  case "redo":
2552
- e.editor.history.redo();
2995
+ i.editor.history.redo();
2553
2996
  break;
2554
2997
  case "zoom-in":
2555
- E.zoomIn(), o.value = E.getZoom();
2998
+ c.zoomIn(), l.value = c.getZoom();
2556
2999
  break;
2557
3000
  case "zoom-out":
2558
- E.zoomOut(), o.value = E.getZoom();
3001
+ c.zoomOut(), l.value = c.getZoom();
2559
3002
  break;
2560
3003
  case "fit":
2561
- E.zoomToFit();
3004
+ c.zoomToFit();
2562
3005
  break;
2563
3006
  case "reset":
2564
- E.zoomTo(1), E.scrollToOrigin(), o.value = 1;
3007
+ c.zoomTo(1), c.scrollToOrigin(), l.value = 1;
2565
3008
  break;
2566
3009
  case "export":
2567
- E.exportAsImage().then((w) => {
2568
- const N = URL.createObjectURL(w), m = document.createElement("a");
2569
- m.href = N, m.download = "canvas-export.png", m.click(), URL.revokeObjectURL(N);
2570
- }).catch((w) => {
2571
- console.warn("[flow-canvas] Export failed:", w);
3010
+ if (u.value) break;
3011
+ u.value = !0, c.exportAsImage().then((v) => {
3012
+ const b = URL.createObjectURL(v), E = document.createElement("a");
3013
+ E.href = b, E.download = "canvas-export.png", E.click(), URL.revokeObjectURL(b);
3014
+ }).catch((v) => {
3015
+ console.warn("[flow-canvas] Export failed:", v);
3016
+ }).finally(() => {
3017
+ u.value = !1;
2572
3018
  });
2573
3019
  break;
2574
3020
  case "select":
2575
- e.editor.setSelectionMode(!e.editor.selectionMode.value);
3021
+ i.editor.setSelectionMode(!i.editor.selectionMode.value);
2576
3022
  break;
2577
- case "search":
2578
3023
  case "auto-layout":
3024
+ i.editor._emitUiEvent({ type: "toolbar.auto-layout" });
3025
+ break;
3026
+ case "search":
2579
3027
  case "minimap":
2580
- console.warn(`[flow-canvas] "${p.type}" toolbar item has no built-in handler. Provide an onClick callback.`);
3028
+ console.warn(`[flow-canvas] "${d.type}" toolbar item has no built-in handler. Provide an onClick callback.`);
2581
3029
  break;
2582
3030
  default:
2583
- p.type !== "custom" && console.warn(`[flow-canvas] No default handler for toolbar type "${p.type}". Provide an onClick handler.`);
3031
+ d.type !== "custom" && console.warn(`[flow-canvas] No default handler for toolbar type "${d.type}". Provide an onClick handler.`);
2584
3032
  break;
2585
3033
  }
2586
3034
  }
2587
- const v = F(() => t.value.filter(l)), f = F(() => {
2588
- const p = /* @__PURE__ */ new Map(), E = [];
2589
- for (const w of v.value) {
2590
- const N = w.group ?? "default";
2591
- p.has(N) || (p.set(N, []), E.push(N)), p.get(N).push(w);
3035
+ const y = j(() => r.value.filter(T)), f = j(() => {
3036
+ const d = /* @__PURE__ */ new Map(), c = [];
3037
+ for (const v of y.value) {
3038
+ const b = v.group ?? "default";
3039
+ d.has(b) || (d.set(b, []), c.push(b)), d.get(b).push(v);
2592
3040
  }
2593
- return E.map((w) => ({ name: w, items: p.get(w) })).filter((w) => w.items.length > 0);
3041
+ return c.map((v) => ({ name: v, items: d.get(v) })).filter((v) => v.items.length > 0);
2594
3042
  });
2595
- return (p, E) => (M(), S("div", lo, [
2596
- (M(!0), S(pe, null, Pe(f.value, (w, N) => (M(), S(pe, {
2597
- key: w.name
3043
+ return (d, c) => (D(), R("div", So, [
3044
+ (D(!0), R(me, null, Ie(f.value, (v, b) => (D(), R(me, {
3045
+ key: v.name
2598
3046
  }, [
2599
- N > 0 ? (M(), S("div", co)) : U("", !0),
2600
- B("div", uo, [
2601
- (M(!0), S(pe, null, Pe(w.items, (m) => (M(), S(pe, {
2602
- key: m.id
3047
+ b > 0 ? (D(), R("div", Mo)) : Y("", !0),
3048
+ U("div", No, [
3049
+ (D(!0), R(me, null, Ie(v.items, (E) => (D(), R(me, {
3050
+ key: E.id
2603
3051
  }, [
2604
- m.type === "zoom-display" ? (M(), S("span", fo, me(r.value), 1)) : (M(), S("button", {
3052
+ E.type === "zoom-display" ? (D(), R("span", _o, ge(k.value), 1)) : (D(), R("button", {
2605
3053
  key: 1,
2606
- class: ee(["flow-canvas-toolbar__btn", { "is-disabled": g(m), "is-active": a(m) }]),
2607
- "data-description": m.description,
2608
- disabled: g(m),
2609
- onClick: (D) => d(m)
3054
+ type: "button",
3055
+ class: se(["flow-canvas-toolbar__btn", {
3056
+ "is-disabled": O(E),
3057
+ "is-active": K(E),
3058
+ "is-exporting": E.type === "export" && u.value
3059
+ }]),
3060
+ "data-toolbar-id": E.id,
3061
+ "data-toolbar-type": E.type,
3062
+ disabled: O(E),
3063
+ onClick: (B) => M(E),
3064
+ onMouseenter: (B) => x(B, E),
3065
+ onMouseleave: m
2610
3066
  }, [
2611
- m.component ? (M(), De(dt(m.component), { key: 0 })) : m.icon ? (M(), S("i", {
3067
+ E.component ? (D(), be(lt(E.component), { key: 0 })) : E.icon ? (D(), R("i", {
2612
3068
  key: 1,
2613
- class: ee(m.icon)
2614
- }, null, 2)) : (M(), S("span", {
3069
+ class: se(E.icon)
3070
+ }, null, 2)) : (D(), R("span", {
2615
3071
  key: 2,
2616
3072
  class: "flow-canvas-toolbar__text",
2617
- textContent: me(m.text ?? m.description ?? m.id)
2618
- }, null, 8, go))
2619
- ], 10, po))
3073
+ textContent: ge(E.text ?? E.description ?? E.id)
3074
+ }, null, 8, Ao))
3075
+ ], 42, Do))
2620
3076
  ], 64))), 128))
2621
3077
  ])
2622
- ], 64))), 128))
3078
+ ], 64))), 128)),
3079
+ (D(), be(dt, { to: "body" }, [
3080
+ p.visible ? (D(), R("div", {
3081
+ key: 0,
3082
+ ref_key: "tooltipRef",
3083
+ ref: a,
3084
+ class: "flow-canvas-toolbar-tooltip",
3085
+ style: we({ left: `${p.x}px`, top: `${p.y}px` })
3086
+ }, [
3087
+ Le(ge(p.text) + " ", 1),
3088
+ c[0] || (c[0] = U("div", { class: "flow-canvas-toolbar-tooltip__arrow" }, null, -1))
3089
+ ], 4)) : Y("", !0)
3090
+ ]))
2623
3091
  ]));
2624
3092
  }
2625
- }), Po = /* @__PURE__ */ he(ho, [["__scopeId", "data-v-51b5c98a"]]), vo = { class: "flow-canvas-default-node__ep-label" }, yo = {
3093
+ }), vn = /* @__PURE__ */ he(Po, [["__scopeId", "data-v-77d4afbb"]]), To = { class: "flow-canvas-default-node__ep-label" }, Ro = {
2626
3094
  key: 1,
2627
- class: "flow-canvas-default-node__diamond"
2628
- }, mo = {
3095
+ class: "flow-canvas-default-node__diamond flow-canvas-highlight-target"
3096
+ }, Lo = {
2629
3097
  key: 2,
2630
3098
  class: "flow-canvas-default-node__task-label"
2631
- }, bo = /* @__PURE__ */ ge({
3099
+ }, Oo = /* @__PURE__ */ fe({
2632
3100
  __name: "default-node",
2633
3101
  setup(s) {
2634
- const t = ct("getNode")?.(), o = F(() => t?.getData?.() ?? null), n = F(() => o.value?.label || o.value?.type || ""), r = {
3102
+ const t = ct("getNode")?.(), o = j(() => t?.getData?.() ?? null), n = j(() => o.value?.label || o.value?.type || ""), i = {
2635
3103
  start: "canvas-kaishi",
2636
3104
  end: "canvas-stop",
2637
3105
  "parallel-gateway": "canvas-bingxingwangguan",
2638
3106
  "branch-gateway": "canvas-fenzhiwangguan",
2639
3107
  "converge-gateway": "canvas-huijuwangguan",
2640
3108
  "conditional-parallel-gateway": "canvas-tiaojianbingxingwangguan"
2641
- }, i = /* @__PURE__ */ new Set(["start", "end"]), l = /* @__PURE__ */ new Set([
3109
+ }, r = /* @__PURE__ */ new Set(["start", "end"]), l = /* @__PURE__ */ new Set([
2642
3110
  "parallel-gateway",
2643
3111
  "branch-gateway",
2644
3112
  "converge-gateway",
2645
3113
  "conditional-parallel-gateway"
2646
- ]), a = F(() => {
2647
- const d = o.value?.type ?? "";
2648
- return i.has(d) ? "endpoint" : l.has(d) ? "gateway" : "task";
2649
- }), g = F(() => r[o.value?.type ?? ""] ?? "");
2650
- return (d, v) => (M(), S("div", {
2651
- class: ee(["flow-canvas-default-node", `is-${a.value}`])
3114
+ ]), a = j(() => {
3115
+ const u = o.value?.type ?? "";
3116
+ return r.has(u) ? "endpoint" : l.has(u) ? "gateway" : "task";
3117
+ }), h = j(() => i[o.value?.type ?? ""] ?? "");
3118
+ return (u, g) => (D(), R("div", {
3119
+ class: se(["flow-canvas-default-node", [`is-${a.value}`, { "flow-canvas-highlight-target": a.value !== "gateway" }]])
2652
3120
  }, [
2653
- a.value === "endpoint" ? (M(), S(pe, { key: 0 }, [
2654
- g.value ? (M(), S("i", {
3121
+ a.value === "endpoint" ? (D(), R(me, { key: 0 }, [
3122
+ h.value ? (D(), R("i", {
2655
3123
  key: 0,
2656
- class: ee([["flow-canvas-icon", g.value], "flow-canvas-default-node__ep-icon"])
2657
- }, null, 2)) : U("", !0),
2658
- B("span", vo, me(n.value), 1)
2659
- ], 64)) : a.value === "gateway" ? (M(), S("div", yo, [
2660
- g.value ? (M(), S("i", {
3124
+ class: se([["flow-canvas-icon", h.value], "flow-canvas-default-node__ep-icon"])
3125
+ }, null, 2)) : Y("", !0),
3126
+ U("span", To, ge(n.value), 1)
3127
+ ], 64)) : a.value === "gateway" ? (D(), R("div", Ro, [
3128
+ h.value ? (D(), R("i", {
2661
3129
  key: 0,
2662
- class: ee([["flow-canvas-icon", g.value], "flow-canvas-default-node__gw-icon"])
2663
- }, null, 2)) : U("", !0)
2664
- ])) : (M(), S("span", mo, me(n.value), 1))
3130
+ class: se([["flow-canvas-icon", h.value], "flow-canvas-default-node__gw-icon"])
3131
+ }, null, 2)) : Y("", !0)
3132
+ ])) : (D(), R("span", Lo, ge(n.value), 1))
2665
3133
  ], 2));
2666
3134
  }
2667
- }), wo = /* @__PURE__ */ he(bo, [["__scopeId", "data-v-c88cdae7"]]), xo = {
3135
+ }), $o = /* @__PURE__ */ he(Oo, [["__scopeId", "data-v-f0e24a9f"]]), Bo = {
2668
3136
  start: { label: "开始", icon: "flow-canvas-icon canvas-kaishi", width: 88, height: 40 },
2669
3137
  end: { label: "结束", icon: "flow-canvas-icon canvas-stop", width: 88, height: 40 },
2670
3138
  empty: { label: "空节点", icon: "flow-canvas-icon canvas-jiedi", width: 240, height: 48 },
@@ -2677,11 +3145,11 @@ const lo = { class: "flow-canvas-toolbar" }, co = {
2677
3145
  width: 64,
2678
3146
  height: 64
2679
3147
  }
2680
- }, Ze = (s, e) => ({
3148
+ }, Ke = (s, e) => ({
2681
3149
  stroke: e.hovered ? "#3a84ff" : "#abb5cc",
2682
3150
  strokeWidth: 2
2683
3151
  });
2684
- function Je() {
3152
+ function Ze() {
2685
3153
  return {
2686
3154
  attrs: {
2687
3155
  line: {
@@ -2692,67 +3160,72 @@ function Je() {
2692
3160
  }
2693
3161
  };
2694
3162
  }
2695
- function ko() {
3163
+ function Ho() {
2696
3164
  return {
2697
3165
  manhattan: {
2698
3166
  router: { name: "manhattan", args: { padding: 10, maxDirectionChange: 90 } },
2699
3167
  connector: { name: "rounded", args: { radius: 8 } },
2700
- style: Ze,
2701
- x6EdgeConfig: Je()
3168
+ style: Ke,
3169
+ x6EdgeConfig: Ze()
2702
3170
  },
2703
3171
  bezier: {
2704
3172
  connector: { name: "smooth" },
2705
- style: Ze,
2706
- x6EdgeConfig: Je()
3173
+ style: Ke,
3174
+ x6EdgeConfig: Ze()
2707
3175
  }
2708
3176
  };
2709
3177
  }
2710
- function _o(s) {
2711
- const e = s?.nodeTypes ?? xo, t = {}, o = [];
2712
- for (const [i, l] of Object.entries(e)) {
2713
- const a = l.width ?? 150, g = l.height ?? 50;
2714
- t[i] = {
2715
- component: wo,
2716
- getSize: () => ({ width: a, height: g }),
3178
+ function yn(s) {
3179
+ const e = s?.nodeTypes ?? Bo, t = {}, o = [];
3180
+ for (const [r, l] of Object.entries(e)) {
3181
+ const a = l.width ?? 150, h = l.height ?? 50;
3182
+ t[r] = {
3183
+ component: $o,
3184
+ getSize: () => ({ width: a, height: h }),
2717
3185
  getPorts: () => nt()
2718
3186
  }, o.push({
2719
- type: i,
2720
- label: l.label ?? i,
3187
+ type: r,
3188
+ label: l.label ?? r,
2721
3189
  icon: l.icon
2722
3190
  });
2723
3191
  }
2724
3192
  const n = {
2725
- ...ko(),
3193
+ ...Ho(),
2726
3194
  ...s?.edgeTypes
2727
- }, r = s?.defaultEdgeType ?? "manhattan";
3195
+ }, i = s?.defaultEdgeType ?? "manhattan";
2728
3196
  return {
2729
- schema: { nodeTypes: t, defaultEdgeType: r, edgeTypes: n },
3197
+ schema: { nodeTypes: t, defaultEdgeType: i, edgeTypes: n },
2730
3198
  paletteItems: o
2731
3199
  };
2732
3200
  }
2733
- function Ao(s) {
3201
+ function mn(s) {
2734
3202
  return {
2735
3203
  name: "connection-validator",
2736
3204
  priority: 10,
2737
3205
  transformCommand(e, t, o) {
2738
- for (const n of e.commands) {
2739
- if (n.type !== "edge.add" && n.type !== "edge.reconnect") continue;
2740
- const r = o.flowModel.value, i = n.type === "edge.add" ? n.edge.source.nodeId : n.source?.nodeId, l = n.type === "edge.add" ? n.edge.target.nodeId : n.target?.nodeId;
2741
- if (!i || !l) continue;
2742
- const a = r.nodes[i], g = r.nodes[l];
2743
- if (!a || !g) continue;
2744
- const d = n.type === "edge.add" ? n.edge.source.portId : n.source?.portId, v = n.type === "edge.add" ? n.edge.target.portId : n.target?.portId, f = d ? a.ports?.find((m) => m.id === d) : void 0, p = v ? g.ports?.find((m) => m.id === v) : void 0, E = n.type === "edge.reconnect" ? n.edgeId : void 0, w = Object.values(r.edges).filter((m) => m.id !== E), N = s({
3206
+ const n = /* @__PURE__ */ new Set();
3207
+ for (const i of e.commands)
3208
+ i.type === "edge.remove" && n.add(i.edgeId);
3209
+ for (const i of e.commands) {
3210
+ if (i.type !== "edge.add" && i.type !== "edge.reconnect") continue;
3211
+ const r = o.flowModel.value, l = i.type === "edge.add" ? i.edge.source.nodeId : i.source?.nodeId, a = i.type === "edge.add" ? i.edge.target.nodeId : i.target?.nodeId;
3212
+ if (!l || !a) continue;
3213
+ const h = r.nodes[l], u = r.nodes[a];
3214
+ if (!h || !u) continue;
3215
+ const g = i.type === "edge.add" ? i.edge.source.portId : i.source?.portId, p = i.type === "edge.add" ? i.edge.target.portId : i.target?.portId, x = g ? h.ports?.find((P) => P.id === g) : void 0, m = p ? u.ports?.find((P) => P.id === p) : void 0, k = i.type === "edge.reconnect" ? i.edgeId : void 0, S = Object.values(r.edges).filter(
3216
+ (P) => P.id !== k && !n.has(P.id)
3217
+ ), T = s({
2745
3218
  flowModel: r,
2746
- sourceNode: a,
2747
- targetNode: g,
2748
- sourcePort: f,
2749
- targetPort: p,
2750
- existingEdges: w
3219
+ sourceNode: h,
3220
+ targetNode: u,
3221
+ sourcePort: x,
3222
+ targetPort: m,
3223
+ existingEdges: S
2751
3224
  });
2752
- if (!N.valid)
3225
+ if (!T.valid)
2753
3226
  return {
2754
3227
  rejected: !0,
2755
- reason: N.reason ?? "Connection validation failed",
3228
+ reason: T.reason ?? "Connection validation failed",
2756
3229
  code: "validation_failed"
2757
3230
  };
2758
3231
  }
@@ -2760,36 +3233,36 @@ function Ao(s) {
2760
3233
  }
2761
3234
  };
2762
3235
  }
2763
- function To(s) {
3236
+ function wn(s) {
2764
3237
  const { rubberband: e = !0, multiple: t = !0, movable: o = !0 } = s ?? {};
2765
3238
  return {
2766
3239
  name: "selection",
2767
3240
  priority: 90,
2768
- async attachRuntime(n) {
2769
- const { Selection: r } = await import("@antv/x6-plugin-selection");
3241
+ attachRuntime(n) {
2770
3242
  n.graph.use(
2771
- new r({
3243
+ new pt({
2772
3244
  enabled: !0,
2773
3245
  rubberband: e,
2774
3246
  multiple: t,
2775
3247
  movable: o,
3248
+ pointerEvents: "none",
2776
3249
  showNodeSelectionBox: !0,
2777
- filter: (i) => !(i.isNode() && (!n.graph.isRubberbandEnabled?.() || (i.getData?.() ?? {})._selectable === !1))
3250
+ filter: (i) => !(i.isNode() && (i.getData?.() ?? {})._selectable === !1)
2778
3251
  })
2779
3252
  );
2780
3253
  }
2781
3254
  };
2782
3255
  }
2783
- function Ro(s) {
3256
+ function bn(s) {
2784
3257
  const { tolerance: e = 10, color: t = "#3a84ff" } = s ?? {};
2785
3258
  let o = null;
2786
3259
  return {
2787
3260
  name: "snapline",
2788
3261
  priority: 90,
2789
3262
  async attachRuntime(n) {
2790
- const { Snapline: r } = await import("@antv/x6-plugin-snapline");
3263
+ const { Snapline: i } = await import("@antv/x6-plugin-snapline");
2791
3264
  n.graph.use(
2792
- new r({
3265
+ new i({
2793
3266
  enabled: !0,
2794
3267
  tolerance: e,
2795
3268
  className: "flow-canvas-snapline"
@@ -2801,45 +3274,365 @@ function Ro(s) {
2801
3274
  }
2802
3275
  };
2803
3276
  }
2804
- function $o(s) {
3277
+ const Go = { class: "flow-canvas-search-popover__input" }, qo = ["value", "placeholder"], Fo = ["onMouseenter", "onClick"], Uo = { class: "flow-canvas-search-popover__item-label" }, zo = {
3278
+ key: 0,
3279
+ class: "flow-canvas-search-popover__item-subtitle"
3280
+ }, jo = {
3281
+ key: 1,
3282
+ class: "flow-canvas-search-popover__empty"
3283
+ }, Wo = /* @__PURE__ */ fe({
3284
+ __name: "search-popover",
3285
+ props: {
3286
+ open: { type: Boolean },
3287
+ position: {},
3288
+ query: {},
3289
+ results: {},
3290
+ placeholder: { default: "搜索节点名称" },
3291
+ emptyText: { default: "暂无匹配节点" },
3292
+ isAnchorTarget: { type: Function, default: void 0 }
3293
+ },
3294
+ emits: ["update:query", "select", "close"],
3295
+ setup(s, { emit: e }) {
3296
+ const t = s, o = e, n = q(null), i = q(null), r = q(-1);
3297
+ pe(
3298
+ () => t.open,
3299
+ (m) => {
3300
+ m && (r.value = -1, Oe(() => {
3301
+ n.value?.focus(), n.value?.select();
3302
+ }));
3303
+ }
3304
+ ), pe(
3305
+ () => t.query,
3306
+ () => {
3307
+ r.value = -1;
3308
+ }
3309
+ ), pe(
3310
+ () => t.results.length,
3311
+ (m) => {
3312
+ if (!m) {
3313
+ r.value = -1;
3314
+ return;
3315
+ }
3316
+ r.value >= m && (r.value = -1);
3317
+ }
3318
+ );
3319
+ function l(m) {
3320
+ o("update:query", m.target.value);
3321
+ }
3322
+ function a(m) {
3323
+ r.value = m;
3324
+ }
3325
+ function h() {
3326
+ r.value = -1;
3327
+ }
3328
+ function u() {
3329
+ o("update:query", ""), Oe(() => {
3330
+ n.value?.focus();
3331
+ });
3332
+ }
3333
+ function g() {
3334
+ const m = t.results[r.value] ?? t.results[0];
3335
+ m && o("select", m.id);
3336
+ }
3337
+ function p(m) {
3338
+ if (m.key === "Escape") {
3339
+ m.preventDefault(), o("close");
3340
+ return;
3341
+ }
3342
+ if (m.key === "ArrowDown") {
3343
+ if (m.preventDefault(), !t.results.length) return;
3344
+ r.value = r.value < t.results.length - 1 ? r.value + 1 : 0;
3345
+ return;
3346
+ }
3347
+ if (m.key === "ArrowUp") {
3348
+ if (m.preventDefault(), !t.results.length) return;
3349
+ r.value = r.value > 0 ? r.value - 1 : t.results.length - 1;
3350
+ return;
3351
+ }
3352
+ m.key === "Enter" && (m.preventDefault(), g());
3353
+ }
3354
+ function x(m) {
3355
+ if (!t.open) return;
3356
+ const k = m.target;
3357
+ k && i.value?.contains(k) || t.isAnchorTarget?.(m.target) || o("close");
3358
+ }
3359
+ return ot(() => {
3360
+ document.addEventListener("mousedown", x);
3361
+ }), Me(() => {
3362
+ document.removeEventListener("mousedown", x);
3363
+ }), (m, k) => s.open ? (D(), R("div", {
3364
+ key: 0,
3365
+ ref_key: "panelRef",
3366
+ ref: i,
3367
+ class: "flow-canvas-search-popover",
3368
+ style: we({ left: `${s.position.x}px`, top: `${s.position.y}px`, width: `${s.position.width}px` })
3369
+ }, [
3370
+ U("div", Go, [
3371
+ k[1] || (k[1] = U("i", { class: "flow-canvas-icon canvas-search" }, null, -1)),
3372
+ U("input", {
3373
+ ref_key: "inputRef",
3374
+ ref: n,
3375
+ value: s.query,
3376
+ placeholder: s.placeholder,
3377
+ onInput: l,
3378
+ onKeydown: p
3379
+ }, null, 40, qo),
3380
+ s.query ? (D(), R("button", {
3381
+ key: 0,
3382
+ type: "button",
3383
+ class: "flow-canvas-search-popover__clear",
3384
+ "aria-label": "清空搜索",
3385
+ onClick: u
3386
+ }, [...k[0] || (k[0] = [
3387
+ U("i", { class: "flow-canvas-icon canvas-close-circle-shape" }, null, -1)
3388
+ ])])) : Y("", !0)
3389
+ ]),
3390
+ s.results.length ? (D(), R("div", {
3391
+ key: 0,
3392
+ class: "flow-canvas-search-popover__list",
3393
+ onMouseleave: h
3394
+ }, [
3395
+ (D(!0), R(me, null, Ie(s.results, (S, T) => (D(), R("button", {
3396
+ key: S.id,
3397
+ type: "button",
3398
+ class: se(["flow-canvas-search-popover__item", { "is-active": T === r.value }]),
3399
+ onMouseenter: (P) => a(T),
3400
+ onClick: (P) => o("select", S.id)
3401
+ }, [
3402
+ U("span", Uo, ge(S.label), 1),
3403
+ S.subtitle ? (D(), R("span", zo, ge(S.subtitle), 1)) : Y("", !0)
3404
+ ], 42, Fo))), 128))
3405
+ ], 32)) : (D(), R("div", jo, ge(s.emptyText), 1))
3406
+ ], 4)) : Y("", !0);
3407
+ }
3408
+ }), Vo = /* @__PURE__ */ he(Wo, [["__scopeId", "data-v-c80f6b26"]]), Qe = 282, Xo = 4, Yo = 300, Ko = 360, Be = 100, Zo = Ko * 4 - Be;
3409
+ function Qo(s) {
3410
+ return s !== null;
3411
+ }
3412
+ function Jo(s) {
3413
+ const e = /* @__PURE__ */ new Set();
3414
+ return s.map((t) => t?.trim()).filter((t) => !!t).filter((t) => {
3415
+ const o = t.toLowerCase();
3416
+ return e.has(o) ? !1 : (e.add(o), !0);
3417
+ });
3418
+ }
3419
+ function en(s, e) {
3420
+ const t = Math.max(8, window.innerWidth - e - 8);
3421
+ return Math.min(Math.max(8, s), t);
3422
+ }
3423
+ function tn(s, e) {
3424
+ const t = e?.getNodeMeta?.(s);
3425
+ if (t === null) return null;
3426
+ const o = t?.label?.trim() || s.label?.trim() || s.id, n = t?.subtitle?.trim() || void 0, i = Jo(t?.keywords ?? [s.label, n]);
3427
+ return i.length ? {
3428
+ id: s.id,
3429
+ label: o,
3430
+ subtitle: n,
3431
+ keywords: i
3432
+ } : null;
3433
+ }
3434
+ function xn(s) {
3435
+ let e = null, t = null, o = null, n = null, i = null, r = [];
3436
+ const l = q(!1), a = q(""), h = q({ x: 0, y: 0, width: Qe }), u = j(() => e ? Object.values(e.flowModel.value.nodes).map((M) => tn(M, s)).filter(Qo) : []), g = j(() => {
3437
+ const M = a.value.trim().toLowerCase(), y = Math.max(1, s?.maxResults ?? Yo);
3438
+ return M ? u.value.filter((f) => f.keywords.some((d) => d.toLowerCase().includes(M))).slice(0, y) : u.value.slice(0, y);
3439
+ });
3440
+ function p() {
3441
+ return o?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="search"]');
3442
+ }
3443
+ function x() {
3444
+ return p()?.closest(".flow-canvas-toolbar");
3445
+ }
3446
+ function m() {
3447
+ const M = x(), y = o?.getBoundingClientRect(), f = M?.getBoundingClientRect() ?? y;
3448
+ if (!f) return;
3449
+ const d = Math.max(Qe, Math.round(f.width));
3450
+ h.value = {
3451
+ x: en(f.left, d),
3452
+ y: f.bottom + Xo,
3453
+ width: d
3454
+ };
3455
+ }
3456
+ function k() {
3457
+ r.forEach((M) => clearTimeout(M)), r = [], t?.api.clearHighlight();
3458
+ }
3459
+ function S(M) {
3460
+ k();
3461
+ const y = setTimeout(() => {
3462
+ t?.api.highlightNodes([M]);
3463
+ }, Be), f = setTimeout(() => {
3464
+ t?.api.clearHighlight(), r = [];
3465
+ }, Be + Zo);
3466
+ r.push(y, f);
3467
+ }
3468
+ function T(M) {
3469
+ t && (t.api.scrollToNode(M), S(M));
3470
+ }
3471
+ function P() {
3472
+ t && (l.value = !0, m(), requestAnimationFrame(() => m()));
3473
+ }
3474
+ function G() {
3475
+ l.value = !1, a.value = "";
3476
+ }
3477
+ function K() {
3478
+ if (l.value) {
3479
+ G();
3480
+ return;
3481
+ }
3482
+ P();
3483
+ }
3484
+ function O(M) {
3485
+ const y = p();
3486
+ return !!(y && M instanceof Node && y.contains(M));
3487
+ }
3488
+ function W() {
3489
+ l.value && m();
3490
+ }
3491
+ const z = fe({
3492
+ name: "FlowCanvasSearchHost",
3493
+ setup() {
3494
+ return () => Re(Vo, {
3495
+ open: l.value,
3496
+ position: h.value,
3497
+ query: a.value,
3498
+ results: g.value,
3499
+ placeholder: s?.placeholder ?? "搜索节点名称",
3500
+ emptyText: s?.emptyText ?? "暂无匹配节点",
3501
+ isAnchorTarget: O,
3502
+ "onUpdate:query": (M) => {
3503
+ a.value = M;
3504
+ },
3505
+ onSelect: T,
3506
+ onClose: G
3507
+ });
3508
+ }
3509
+ });
3510
+ return {
3511
+ name: "search",
3512
+ priority: 90,
3513
+ install(M) {
3514
+ e = M;
3515
+ },
3516
+ attachRuntime(M) {
3517
+ t = M, o = M.graph.container.closest(".flow-canvas-layout__content") ?? M.graph.container.parentElement, n = document.createElement("div"), n.className = "flow-canvas-search-host", document.body.append(n), i = ut(z), i.mount(n), window.addEventListener("resize", W), window.addEventListener("scroll", W, !0);
3518
+ },
3519
+ detachRuntime() {
3520
+ G(), k(), window.removeEventListener("resize", W), window.removeEventListener("scroll", W, !0), i?.unmount(), i = null, n?.remove(), n = null, o = null, t = null;
3521
+ },
3522
+ dispose() {
3523
+ G(), k(), e = null;
3524
+ },
3525
+ provideToolbarItems() {
3526
+ return [
3527
+ {
3528
+ id: "plugin:search",
3529
+ type: "search",
3530
+ icon: "flow-canvas-icon canvas-search",
3531
+ description: "搜索节点",
3532
+ group: "tools",
3533
+ order: 22,
3534
+ active: () => l.value,
3535
+ onClick: K
3536
+ }
3537
+ ];
3538
+ }
3539
+ };
3540
+ }
3541
+ const on = 52, nn = 16, sn = 40;
3542
+ function rn(s) {
3543
+ const e = document.createElement("div");
3544
+ e.className = "flow-canvas-minimap", s.floating !== !1 && e.classList.add("flow-canvas-minimap--floating");
3545
+ const t = document.createElement("div");
3546
+ t.className = "flow-canvas-minimap__host", e.append(t), Object.assign(e.style, {
3547
+ width: `${s.width}px`,
3548
+ height: `${s.height}px`
3549
+ }), s.floating !== !1 && Object.assign(e.style, {
3550
+ top: `${on}px`,
3551
+ left: `${nn}px`
3552
+ });
3553
+ let o = null, n = s.defaultOpen ?? !1, i = null;
3554
+ function r() {
3555
+ !s.onClickOutside || i || (i = (p) => {
3556
+ const x = p.target;
3557
+ x && e.contains(x) || p.target?.closest('[data-toolbar-type="minimap"]') || s.onClickOutside();
3558
+ }, document.addEventListener("mousedown", i));
3559
+ }
3560
+ function l() {
3561
+ i && (document.removeEventListener("mousedown", i), i = null);
3562
+ }
3563
+ function a() {
3564
+ o || (o = new ht({
3565
+ container: t,
3566
+ width: s.width,
3567
+ height: s.height,
3568
+ padding: s.contentPadding ?? sn,
3569
+ scalable: !1
3570
+ }), s.sourceGraph.use(o));
3571
+ }
3572
+ function h(p) {
3573
+ n = p, e.style.display = n ? "" : "none", n ? (a(), r()) : l();
3574
+ }
3575
+ function u() {
3576
+ h(n), s.mountTarget.appendChild(e);
3577
+ }
3578
+ function g() {
3579
+ l(), o?.dispose(), o = null, e.remove();
3580
+ }
3581
+ return u(), {
3582
+ element: e,
3583
+ isOpen: () => n,
3584
+ setOpen: h,
3585
+ toggle() {
3586
+ const p = !n;
3587
+ return h(p), p;
3588
+ },
3589
+ destroy: g
3590
+ };
3591
+ }
3592
+ function En(s) {
2805
3593
  let e = null;
3594
+ const t = q(!1);
3595
+ function o(i) {
3596
+ e?.setOpen(i), t.value = i;
3597
+ }
3598
+ function n() {
3599
+ e && (t.value = e.toggle());
3600
+ }
2806
3601
  return {
2807
3602
  name: "minimap",
2808
3603
  priority: 90,
2809
- async attachRuntime(t) {
2810
- if (!s?.container) return;
2811
- e = s.container;
2812
- const { MiniMap: o } = await import("@antv/x6-plugin-minimap");
2813
- t.graph.use(
2814
- new o({
2815
- container: s.container,
2816
- width: s.width ?? 200,
2817
- height: s.height ?? 160
2818
- })
2819
- );
3604
+ attachRuntime(i) {
3605
+ const r = s?.width ?? 334, l = s?.height ?? 180, a = s?.container ?? i.graph.container.closest(".flow-canvas-layout__content") ?? i.graph.container.parentElement;
3606
+ a && (e = rn({
3607
+ sourceGraph: i.graph,
3608
+ mountTarget: a,
3609
+ width: r,
3610
+ height: l,
3611
+ floating: !s?.container,
3612
+ defaultOpen: !1,
3613
+ onClickOutside: () => o(!1)
3614
+ }), o(!1));
2820
3615
  },
2821
3616
  detachRuntime() {
2822
- e = null;
3617
+ e?.destroy(), e = null, t.value = !1;
2823
3618
  },
2824
3619
  provideToolbarItems() {
2825
3620
  return [
2826
3621
  {
2827
- id: "minimap",
3622
+ id: "plugin:minimap",
2828
3623
  type: "minimap",
2829
- tooltip: "小地图",
2830
- order: 100,
2831
- visible: !!s?.container,
2832
- onClick() {
2833
- if (!e) return;
2834
- const t = e.style.display === "none";
2835
- e.style.display = t ? "" : "none";
2836
- }
3624
+ icon: "flow-canvas-icon canvas-map",
3625
+ description: "缩略图",
3626
+ group: "tools",
3627
+ order: 23,
3628
+ active: () => t.value,
3629
+ onClick: n
2837
3630
  }
2838
3631
  ];
2839
3632
  }
2840
3633
  };
2841
3634
  }
2842
- function Lo() {
3635
+ function In() {
2843
3636
  let s = null, e = 0;
2844
3637
  return {
2845
3638
  name: "clipboard",
@@ -2847,29 +3640,29 @@ function Lo() {
2847
3640
  onKeyboardShortcut(t, o) {
2848
3641
  const n = t.metaKey || t.ctrlKey;
2849
3642
  if (n && t.key === "c") {
2850
- const r = o.graph.getSelectedCells?.() ?? [];
2851
- if (!r.length) return !1;
2852
- const i = o.flowModel.value, l = new Set(r.filter((d) => d.isNode()).map((d) => d.id)), a = [...l].map((d) => i.nodes[d]).filter(Boolean);
3643
+ const i = o.graph.getSelectedCells?.() ?? [];
3644
+ if (!i.length) return !1;
3645
+ const r = o.flowModel.value, l = new Set(i.filter((u) => u.isNode()).map((u) => u.id)), a = [...l].map((u) => r.nodes[u]).filter(Boolean);
2853
3646
  if (!a.length) return !1;
2854
- const g = Object.values(i.edges).filter(
2855
- (d) => l.has(d.source.nodeId) && l.has(d.target.nodeId)
3647
+ const h = Object.values(r.edges).filter(
3648
+ (u) => l.has(u.source.nodeId) && l.has(u.target.nodeId)
2856
3649
  );
2857
- return s = { nodes: a, edges: g }, e = 0, !0;
3650
+ return s = { nodes: a, edges: h }, e = 0, !0;
2858
3651
  }
2859
3652
  if (n && t.key === "v") {
2860
3653
  if (!s?.nodes.length) return !1;
2861
3654
  e++;
2862
- const r = e * 30, i = /* @__PURE__ */ new Map(), l = [];
3655
+ const i = e * 30, r = /* @__PURE__ */ new Map(), l = [];
2863
3656
  for (const a of s.nodes) {
2864
- const g = `${a.id}_cp${W().slice(0, 6)}`;
2865
- i.set(a.id, g), l.push({
3657
+ const h = `${a.id}_cp${te().slice(0, 6)}`;
3658
+ r.set(a.id, h), l.push({
2866
3659
  type: "node.add",
2867
3660
  node: {
2868
3661
  ...a,
2869
- id: g,
3662
+ id: h,
2870
3663
  position: {
2871
- x: a.position.x + r,
2872
- y: a.position.y + r
3664
+ x: a.position.x + i,
3665
+ y: a.position.y + i
2873
3666
  },
2874
3667
  payload: a.payload ? { ...a.payload } : {},
2875
3668
  extensions: a.extensions ? { ...a.extensions } : void 0
@@ -2877,21 +3670,21 @@ function Lo() {
2877
3670
  });
2878
3671
  }
2879
3672
  for (const a of s.edges) {
2880
- const g = i.get(a.source.nodeId), d = i.get(a.target.nodeId);
2881
- !g || !d || l.push({
3673
+ const h = r.get(a.source.nodeId), u = r.get(a.target.nodeId);
3674
+ !h || !u || l.push({
2882
3675
  type: "edge.add",
2883
3676
  edge: {
2884
3677
  ...a,
2885
- id: `${a.id}_cp${W().slice(0, 6)}`,
2886
- source: { ...a.source, nodeId: g },
2887
- target: { ...a.target, nodeId: d },
2888
- labels: a.labels?.map((v) => ({ ...v, id: `${v.id}_cp${W().slice(0, 6)}` })),
3678
+ id: `${a.id}_cp${te().slice(0, 6)}`,
3679
+ source: { ...a.source, nodeId: h },
3680
+ target: { ...a.target, nodeId: u },
3681
+ labels: a.labels?.map((g) => ({ ...g, id: `${g.id}_cp${te().slice(0, 6)}` })),
2889
3682
  payload: a.payload ? { ...a.payload } : {}
2890
3683
  }
2891
3684
  });
2892
3685
  }
2893
3686
  return l.length && o.executeCommand({
2894
- id: W(),
3687
+ id: te(),
2895
3688
  source: "user:keyboard",
2896
3689
  label: "粘贴",
2897
3690
  timestamp: Date.now(),
@@ -2903,26 +3696,27 @@ function Lo() {
2903
3696
  };
2904
3697
  }
2905
3698
  export {
2906
- ne as CanvasConstraintError,
2907
- Do as CanvasLayout,
2908
- eo as CanvasNodePalette,
2909
- So as CanvasRuntime,
2910
- pt as CanvasSchemaError,
2911
- Po as CanvasToolbar,
2912
- wo as DefaultNode,
2913
- Ft as NodeActionsToolbar,
2914
- Wt as NodeQuickAddPopover,
2915
- Ge as applyCanvasCommand,
2916
- Lo as clipboardPlugin,
2917
- Ao as connectionValidatorPlugin,
2918
- ko as createBuiltinEdgeTypes,
2919
- Nt as createCanvasHistory,
2920
- _o as createDefaultSchema,
2921
- ao as createDefaultToolbarItems,
2922
- Mo as createEmptyFlowModel,
2923
- W as generateId,
2924
- $o as minimapPlugin,
2925
- To as selectionPlugin,
2926
- Ro as snaplinePlugin,
2927
- No as useCanvasEditor
3699
+ ue as CanvasConstraintError,
3700
+ hn as CanvasLayout,
3701
+ mo as CanvasNodePalette,
3702
+ pn as CanvasRuntime,
3703
+ vt as CanvasSchemaError,
3704
+ vn as CanvasToolbar,
3705
+ $o as DefaultNode,
3706
+ no as NodeActionsToolbar,
3707
+ ao as NodeQuickAddPopover,
3708
+ $e as applyCanvasCommand,
3709
+ In as clipboardPlugin,
3710
+ mn as connectionValidatorPlugin,
3711
+ Ho as createBuiltinEdgeTypes,
3712
+ Dt as createCanvasHistory,
3713
+ yn as createDefaultSchema,
3714
+ ko as createDefaultToolbarItems,
3715
+ fn as createEmptyFlowModel,
3716
+ te as generateId,
3717
+ En as minimapPlugin,
3718
+ xn as searchPlugin,
3719
+ wn as selectionPlugin,
3720
+ bn as snaplinePlugin,
3721
+ gn as useCanvasEditor
2928
3722
  };