@flowgram.ai/free-layout-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/chunk-CGOMTQ3G.js +1 -0
- package/dist/esm/chunk-CGOMTQ3G.js.map +1 -0
- package/dist/esm/chunk-DDJTYHXN.js +1 -0
- package/dist/esm/chunk-DDJTYHXN.js.map +1 -0
- package/dist/esm/chunk-DE4324TR.js +7 -0
- package/dist/esm/chunk-DE4324TR.js.map +1 -0
- package/dist/esm/chunk-EUXUH3YW.js +15 -0
- package/dist/esm/chunk-EUXUH3YW.js.map +1 -0
- package/dist/esm/chunk-J5FVRRUV.js +16 -0
- package/dist/esm/chunk-J5FVRRUV.js.map +1 -0
- package/dist/esm/chunk-KAL7YCC2.js +20 -0
- package/dist/esm/chunk-KAL7YCC2.js.map +1 -0
- package/dist/esm/chunk-KNYZRMIO.js +1 -0
- package/dist/esm/chunk-KNYZRMIO.js.map +1 -0
- package/dist/esm/chunk-NU6G5HF4.js +1 -0
- package/dist/esm/chunk-NU6G5HF4.js.map +1 -0
- package/dist/esm/index.js +3432 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/typings/index.js +22 -0
- package/dist/esm/typings/index.js.map +1 -0
- package/dist/esm/typings/workflow-edge.js +2 -0
- package/dist/esm/typings/workflow-edge.js.map +1 -0
- package/dist/esm/typings/workflow-json.js +8 -0
- package/dist/esm/typings/workflow-json.js.map +1 -0
- package/dist/esm/typings/workflow-line.js +10 -0
- package/dist/esm/typings/workflow-line.js.map +1 -0
- package/dist/esm/typings/workflow-node.js +2 -0
- package/dist/esm/typings/workflow-node.js.map +1 -0
- package/dist/esm/typings/workflow-registry.js +2 -0
- package/dist/esm/typings/workflow-registry.js.map +1 -0
- package/dist/esm/typings/workflow-sub-canvas.js +2 -0
- package/dist/esm/typings/workflow-sub-canvas.js.map +1 -0
- package/dist/index.d.mts +463 -0
- package/dist/index.d.ts +463 -0
- package/dist/index.js +3483 -0
- package/dist/index.js.map +1 -0
- package/dist/typings/index.d.mts +18 -0
- package/dist/typings/index.d.ts +18 -0
- package/dist/typings/index.js +66 -0
- package/dist/typings/index.js.map +1 -0
- package/dist/typings/workflow-edge.d.mts +11 -0
- package/dist/typings/workflow-edge.d.ts +11 -0
- package/dist/typings/workflow-edge.js +19 -0
- package/dist/typings/workflow-edge.js.map +1 -0
- package/dist/typings/workflow-json.d.mts +9 -0
- package/dist/typings/workflow-json.d.ts +9 -0
- package/dist/typings/workflow-json.js +40 -0
- package/dist/typings/workflow-json.js.map +1 -0
- package/dist/typings/workflow-line.d.mts +27 -0
- package/dist/typings/workflow-line.d.ts +27 -0
- package/dist/typings/workflow-line.js +45 -0
- package/dist/typings/workflow-line.js.map +1 -0
- package/dist/typings/workflow-node.d.mts +9 -0
- package/dist/typings/workflow-node.d.ts +9 -0
- package/dist/typings/workflow-node.js +19 -0
- package/dist/typings/workflow-node.js.map +1 -0
- package/dist/typings/workflow-registry.d.mts +26 -0
- package/dist/typings/workflow-registry.d.ts +26 -0
- package/dist/typings/workflow-registry.js +19 -0
- package/dist/typings/workflow-registry.js.map +1 -0
- package/dist/typings/workflow-sub-canvas.d.mts +2 -0
- package/dist/typings/workflow-sub-canvas.d.ts +2 -0
- package/dist/typings/workflow-sub-canvas.js +19 -0
- package/dist/typings/workflow-sub-canvas.js.map +1 -0
- package/dist/workflow-line-entity-1qT4aXVU.d.mts +619 -0
- package/dist/workflow-line-entity-CG_8mknJ.d.ts +619 -0
- package/dist/workflow-sub-canvas-DOVla1mw.d.mts +15 -0
- package/dist/workflow-sub-canvas-DOVla1mw.d.ts +15 -0
- package/package.json +72 -0
|
@@ -0,0 +1,3432 @@
|
|
|
1
|
+
import {
|
|
2
|
+
URLParams
|
|
3
|
+
} from "./chunk-DE4324TR.js";
|
|
4
|
+
import "./chunk-CGOMTQ3G.js";
|
|
5
|
+
import {
|
|
6
|
+
WorkflowContentChangeType
|
|
7
|
+
} from "./chunk-J5FVRRUV.js";
|
|
8
|
+
import {
|
|
9
|
+
LineColors,
|
|
10
|
+
LineType
|
|
11
|
+
} from "./chunk-KAL7YCC2.js";
|
|
12
|
+
import {
|
|
13
|
+
__decorateClass
|
|
14
|
+
} from "./chunk-EUXUH3YW.js";
|
|
15
|
+
import "./chunk-DDJTYHXN.js";
|
|
16
|
+
import "./chunk-KNYZRMIO.js";
|
|
17
|
+
import "./chunk-NU6G5HF4.js";
|
|
18
|
+
|
|
19
|
+
// src/workflow-commands.ts
|
|
20
|
+
var WorkflowCommands = /* @__PURE__ */ ((WorkflowCommands2) => {
|
|
21
|
+
WorkflowCommands2["DELETE_NODES"] = "DELETE_NODES";
|
|
22
|
+
WorkflowCommands2["COPY_NODES"] = "COPY_NODES";
|
|
23
|
+
WorkflowCommands2["PASTE_NODES"] = "PASTE_NODES";
|
|
24
|
+
WorkflowCommands2["ZOOM_IN"] = "ZOOM_IN";
|
|
25
|
+
WorkflowCommands2["ZOOM_OUT"] = "ZOOM_OUT";
|
|
26
|
+
WorkflowCommands2["UNDO"] = "UNDO";
|
|
27
|
+
WorkflowCommands2["REDO"] = "REDO";
|
|
28
|
+
return WorkflowCommands2;
|
|
29
|
+
})(WorkflowCommands || {});
|
|
30
|
+
|
|
31
|
+
// src/hooks/index.ts
|
|
32
|
+
import {
|
|
33
|
+
useConfigEntity,
|
|
34
|
+
useService as useService3,
|
|
35
|
+
usePlayground as usePlayground2,
|
|
36
|
+
useListenEvents as useListenEvents2,
|
|
37
|
+
usePlaygroundContainer,
|
|
38
|
+
usePlaygroundContext,
|
|
39
|
+
useEntities,
|
|
40
|
+
useEntityFromContext as useEntityFromContext3,
|
|
41
|
+
useEntityDataFromContext,
|
|
42
|
+
useRefresh as useRefresh2,
|
|
43
|
+
usePlaygroundLatest
|
|
44
|
+
} from "@flowgram.ai/core";
|
|
45
|
+
|
|
46
|
+
// src/hooks/use-node-render.tsx
|
|
47
|
+
import { useCallback, useEffect as useEffect2, useRef, useState, useContext, useMemo } from "react";
|
|
48
|
+
import { useObserve } from "@flowgram.ai/reactive";
|
|
49
|
+
import { getNodeForm } from "@flowgram.ai/node";
|
|
50
|
+
import { FlowNodeRenderData as FlowNodeRenderData2 } from "@flowgram.ai/document";
|
|
51
|
+
import { PlaygroundEntityContext, useListenEvents, useService } from "@flowgram.ai/core";
|
|
52
|
+
|
|
53
|
+
// src/service/workflow-select-service.ts
|
|
54
|
+
import { inject, injectable } from "inversify";
|
|
55
|
+
import {
|
|
56
|
+
Playground,
|
|
57
|
+
SelectionService,
|
|
58
|
+
TransformData as TransformData4
|
|
59
|
+
} from "@flowgram.ai/core";
|
|
60
|
+
import { Rectangle as Rectangle7, SizeSchema } from "@flowgram.ai/utils";
|
|
61
|
+
|
|
62
|
+
// src/utils/index.ts
|
|
63
|
+
import { bindConfigEntity } from "@flowgram.ai/core";
|
|
64
|
+
import { delay } from "@flowgram.ai/utils";
|
|
65
|
+
|
|
66
|
+
// src/utils/fold-line.ts
|
|
67
|
+
import { Point, Rectangle } from "@flowgram.ai/utils";
|
|
68
|
+
function pointLineDistance(p1, p2, p3) {
|
|
69
|
+
let len;
|
|
70
|
+
if (p1.x - p2.x === 0) {
|
|
71
|
+
len = Math.abs(p3.x - p1.x);
|
|
72
|
+
} else {
|
|
73
|
+
const A = (p1.y - p2.y) / (p1.x - p2.x);
|
|
74
|
+
const B = p1.y - A * p1.x;
|
|
75
|
+
len = Math.abs((A * p3.x + B - p3.y) / Math.sqrt(A * A + 1));
|
|
76
|
+
}
|
|
77
|
+
return len;
|
|
78
|
+
}
|
|
79
|
+
var FoldLine;
|
|
80
|
+
((FoldLine2) => {
|
|
81
|
+
const EDGE_RADIUS = 5;
|
|
82
|
+
const OFFSET = 20;
|
|
83
|
+
function getEdgeCenter({ source, target }) {
|
|
84
|
+
const xOffset = Math.abs(target.x - source.x) / 2;
|
|
85
|
+
const centerX = target.x < source.x ? target.x + xOffset : target.x - xOffset;
|
|
86
|
+
const yOffset = Math.abs(target.y - source.y) / 2;
|
|
87
|
+
const centerY = target.y < source.y ? target.y + yOffset : target.y - yOffset;
|
|
88
|
+
return [centerX, centerY];
|
|
89
|
+
}
|
|
90
|
+
const getDirection = ({ source, target }) => source.x < target.x ? { x: 1, y: 0 } : { x: -1, y: 0 };
|
|
91
|
+
function getPoints({ source, target }) {
|
|
92
|
+
const sourceDir = { x: 1, y: 0 };
|
|
93
|
+
const targetDir = { x: -1, y: 0 };
|
|
94
|
+
const sourceGapped = {
|
|
95
|
+
x: source.x + sourceDir.x * OFFSET,
|
|
96
|
+
y: source.y + sourceDir.y * OFFSET
|
|
97
|
+
};
|
|
98
|
+
const targetGapped = {
|
|
99
|
+
x: target.x + targetDir.x * OFFSET,
|
|
100
|
+
y: target.y + targetDir.y * OFFSET
|
|
101
|
+
};
|
|
102
|
+
const dir = getDirection({
|
|
103
|
+
source: sourceGapped,
|
|
104
|
+
target: targetGapped
|
|
105
|
+
});
|
|
106
|
+
const dirAccessor = dir.x !== 0 ? "x" : "y";
|
|
107
|
+
const currDir = dir[dirAccessor];
|
|
108
|
+
let points = [];
|
|
109
|
+
let centerX, centerY;
|
|
110
|
+
const [defaultCenterX, defaultCenterY] = getEdgeCenter({
|
|
111
|
+
source,
|
|
112
|
+
target
|
|
113
|
+
});
|
|
114
|
+
if (sourceDir[dirAccessor] * targetDir[dirAccessor] === -1) {
|
|
115
|
+
centerX = defaultCenterX;
|
|
116
|
+
centerY = defaultCenterY;
|
|
117
|
+
const verticalSplit = [
|
|
118
|
+
{ x: centerX, y: sourceGapped.y },
|
|
119
|
+
{ x: centerX, y: targetGapped.y }
|
|
120
|
+
];
|
|
121
|
+
const horizontalSplit = [
|
|
122
|
+
{ x: sourceGapped.x, y: centerY },
|
|
123
|
+
{ x: targetGapped.x, y: centerY }
|
|
124
|
+
];
|
|
125
|
+
if (sourceDir[dirAccessor] === currDir) {
|
|
126
|
+
points = dirAccessor === "x" ? verticalSplit : horizontalSplit;
|
|
127
|
+
} else {
|
|
128
|
+
points = dirAccessor === "x" ? horizontalSplit : verticalSplit;
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
const sourceTarget = [{ x: sourceGapped.x, y: targetGapped.y }];
|
|
132
|
+
const targetSource = [{ x: targetGapped.x, y: sourceGapped.y }];
|
|
133
|
+
if (dirAccessor === "x") {
|
|
134
|
+
points = sourceDir.x === currDir ? targetSource : sourceTarget;
|
|
135
|
+
} else {
|
|
136
|
+
points = sourceDir.y === currDir ? sourceTarget : targetSource;
|
|
137
|
+
}
|
|
138
|
+
const dirAccessorOpposite = dirAccessor === "x" ? "y" : "x";
|
|
139
|
+
const isSameDir = sourceDir[dirAccessor] === targetDir[dirAccessorOpposite];
|
|
140
|
+
const sourceGtTargetOppo = sourceGapped[dirAccessorOpposite] > targetGapped[dirAccessorOpposite];
|
|
141
|
+
const sourceLtTargetOppo = sourceGapped[dirAccessorOpposite] < targetGapped[dirAccessorOpposite];
|
|
142
|
+
const flipSourceTarget = sourceDir[dirAccessor] === 1 && (!isSameDir && sourceGtTargetOppo || isSameDir && sourceLtTargetOppo) || sourceDir[dirAccessor] !== 1 && (!isSameDir && sourceLtTargetOppo || isSameDir && sourceGtTargetOppo);
|
|
143
|
+
if (flipSourceTarget) {
|
|
144
|
+
points = dirAccessor === "x" ? sourceTarget : targetSource;
|
|
145
|
+
}
|
|
146
|
+
const sourceGapPoint = { x: sourceGapped.x, y: sourceGapped.y };
|
|
147
|
+
const targetGapPoint = { x: targetGapped.x, y: targetGapped.y };
|
|
148
|
+
const maxXDistance = Math.max(
|
|
149
|
+
Math.abs(sourceGapPoint.x - points[0].x),
|
|
150
|
+
Math.abs(targetGapPoint.x - points[0].x)
|
|
151
|
+
);
|
|
152
|
+
const maxYDistance = Math.max(
|
|
153
|
+
Math.abs(sourceGapPoint.y - points[0].y),
|
|
154
|
+
Math.abs(targetGapPoint.y - points[0].y)
|
|
155
|
+
);
|
|
156
|
+
if (maxXDistance >= maxYDistance) {
|
|
157
|
+
centerX = (sourceGapPoint.x + targetGapPoint.x) / 2;
|
|
158
|
+
centerY = points[0].y;
|
|
159
|
+
} else {
|
|
160
|
+
centerX = points[0].x;
|
|
161
|
+
centerY = (sourceGapPoint.y + targetGapPoint.y) / 2;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const pathPoints = [
|
|
165
|
+
source,
|
|
166
|
+
{ x: sourceGapped.x, y: sourceGapped.y },
|
|
167
|
+
...points,
|
|
168
|
+
{ x: targetGapped.x, y: targetGapped.y },
|
|
169
|
+
target
|
|
170
|
+
];
|
|
171
|
+
return pathPoints;
|
|
172
|
+
}
|
|
173
|
+
FoldLine2.getPoints = getPoints;
|
|
174
|
+
function getBend(a, b, c) {
|
|
175
|
+
const bendSize = Math.min(
|
|
176
|
+
Point.getDistance(a, b) / 2,
|
|
177
|
+
Point.getDistance(b, c) / 2,
|
|
178
|
+
EDGE_RADIUS
|
|
179
|
+
);
|
|
180
|
+
const { x, y } = b;
|
|
181
|
+
if (a.x === x && x === c.x || a.y === y && y === c.y) {
|
|
182
|
+
return `L${x} ${y}`;
|
|
183
|
+
}
|
|
184
|
+
if (a.y === y) {
|
|
185
|
+
const xDir2 = a.x < c.x ? -1 : 1;
|
|
186
|
+
const yDir2 = a.y < c.y ? 1 : -1;
|
|
187
|
+
return `L ${x + bendSize * xDir2},${y}Q ${x},${y} ${x},${y + bendSize * yDir2}`;
|
|
188
|
+
}
|
|
189
|
+
const xDir = a.x < c.x ? 1 : -1;
|
|
190
|
+
const yDir = a.y < c.y ? -1 : 1;
|
|
191
|
+
return `L ${x},${y + bendSize * yDir}Q ${x},${y} ${x + bendSize * xDir},${y}`;
|
|
192
|
+
}
|
|
193
|
+
function getSmoothStepPath(points) {
|
|
194
|
+
const path = points.reduce((res, p, i) => {
|
|
195
|
+
let segment = "";
|
|
196
|
+
if (i > 0 && i < points.length - 1) {
|
|
197
|
+
segment = getBend(points[i - 1], p, points[i + 1]);
|
|
198
|
+
} else {
|
|
199
|
+
segment = `${i === 0 ? "M" : "L"}${p.x} ${p.y}`;
|
|
200
|
+
}
|
|
201
|
+
res += segment;
|
|
202
|
+
return res;
|
|
203
|
+
}, "");
|
|
204
|
+
return path;
|
|
205
|
+
}
|
|
206
|
+
FoldLine2.getSmoothStepPath = getSmoothStepPath;
|
|
207
|
+
function getBounds(points) {
|
|
208
|
+
const xList = points.map((p) => p.x);
|
|
209
|
+
const yList = points.map((p) => p.y);
|
|
210
|
+
const left = Math.min(...xList);
|
|
211
|
+
const right = Math.max(...xList);
|
|
212
|
+
const top = Math.min(...yList);
|
|
213
|
+
const bottom = Math.max(...yList);
|
|
214
|
+
return Rectangle.createRectangleWithTwoPoints(
|
|
215
|
+
{
|
|
216
|
+
x: left,
|
|
217
|
+
y: top
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
x: right,
|
|
221
|
+
y: bottom
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
FoldLine2.getBounds = getBounds;
|
|
226
|
+
function getFoldLineToPointDistance(points, pos) {
|
|
227
|
+
const bounds = getBounds(points);
|
|
228
|
+
if (bounds.contains(pos.x, pos.y)) {
|
|
229
|
+
const lines = points.reduce((res, point, index) => {
|
|
230
|
+
if (index === 0) {
|
|
231
|
+
return res;
|
|
232
|
+
}
|
|
233
|
+
res.push([points[index - 1], point]);
|
|
234
|
+
return res;
|
|
235
|
+
}, []);
|
|
236
|
+
return Math.min(...lines.map((l) => pointLineDistance(...l, pos)));
|
|
237
|
+
}
|
|
238
|
+
return Math.min(...points.map((p) => Point.getDistance(p, pos)));
|
|
239
|
+
}
|
|
240
|
+
FoldLine2.getFoldLineToPointDistance = getFoldLineToPointDistance;
|
|
241
|
+
})(FoldLine || (FoldLine = {}));
|
|
242
|
+
|
|
243
|
+
// src/utils/bezier.ts
|
|
244
|
+
import { Rectangle as Rectangle2 } from "@flowgram.ai/utils";
|
|
245
|
+
var BezierControlType = /* @__PURE__ */ ((BezierControlType2) => {
|
|
246
|
+
BezierControlType2[BezierControlType2["RIGHT_TOP"] = 0] = "RIGHT_TOP";
|
|
247
|
+
BezierControlType2[BezierControlType2["RIGHT_BOTTOM"] = 1] = "RIGHT_BOTTOM";
|
|
248
|
+
BezierControlType2[BezierControlType2["LEFT_TOP"] = 2] = "LEFT_TOP";
|
|
249
|
+
BezierControlType2[BezierControlType2["LEFT_BOTTOM"] = 3] = "LEFT_BOTTOM";
|
|
250
|
+
return BezierControlType2;
|
|
251
|
+
})(BezierControlType || {});
|
|
252
|
+
var CONTROL_MAX = 300;
|
|
253
|
+
function getBezierHorizontalControlPoints(fromPos, toPos) {
|
|
254
|
+
const rect = Rectangle2.createRectangleWithTwoPoints(fromPos, toPos);
|
|
255
|
+
let type;
|
|
256
|
+
if (fromPos.x <= toPos.x) {
|
|
257
|
+
type = fromPos.y <= toPos.y ? 1 /* RIGHT_BOTTOM */ : 0 /* RIGHT_TOP */;
|
|
258
|
+
} else {
|
|
259
|
+
type = fromPos.y <= toPos.y ? 3 /* LEFT_BOTTOM */ : 2 /* LEFT_TOP */;
|
|
260
|
+
}
|
|
261
|
+
let controls;
|
|
262
|
+
switch (type) {
|
|
263
|
+
case 0 /* RIGHT_TOP */:
|
|
264
|
+
controls = [
|
|
265
|
+
{
|
|
266
|
+
x: rect.rightBottom.x - rect.width / 2,
|
|
267
|
+
y: rect.rightBottom.y
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
x: rect.leftTop.x + rect.width / 2,
|
|
271
|
+
y: rect.leftTop.y
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
break;
|
|
275
|
+
case 1 /* RIGHT_BOTTOM */:
|
|
276
|
+
controls = [
|
|
277
|
+
{
|
|
278
|
+
x: rect.rightTop.x - rect.width / 2,
|
|
279
|
+
y: rect.rightTop.y
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
x: rect.leftBottom.x + rect.width / 2,
|
|
283
|
+
y: rect.leftBottom.y
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
break;
|
|
287
|
+
case 2 /* LEFT_TOP */:
|
|
288
|
+
controls = [
|
|
289
|
+
{
|
|
290
|
+
x: rect.rightBottom.x + Math.min(rect.width, CONTROL_MAX),
|
|
291
|
+
y: rect.rightBottom.y
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
x: rect.leftTop.x - Math.min(rect.width, CONTROL_MAX),
|
|
295
|
+
y: rect.leftTop.y
|
|
296
|
+
}
|
|
297
|
+
];
|
|
298
|
+
break;
|
|
299
|
+
case 3 /* LEFT_BOTTOM */:
|
|
300
|
+
controls = [
|
|
301
|
+
{
|
|
302
|
+
x: rect.rightTop.x + Math.min(rect.width, CONTROL_MAX),
|
|
303
|
+
y: rect.rightTop.y
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
x: rect.leftBottom.x - Math.min(rect.width, CONTROL_MAX),
|
|
307
|
+
y: rect.leftBottom.y
|
|
308
|
+
}
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
return controls;
|
|
312
|
+
}
|
|
313
|
+
function getBezierVerticalControlPoints(fromPos, toPos) {
|
|
314
|
+
const rect = Rectangle2.createRectangleWithTwoPoints(fromPos, toPos);
|
|
315
|
+
let type;
|
|
316
|
+
if (fromPos.y <= toPos.y) {
|
|
317
|
+
type = fromPos.x <= toPos.x ? 1 /* RIGHT_BOTTOM */ : 3 /* LEFT_BOTTOM */;
|
|
318
|
+
} else {
|
|
319
|
+
type = fromPos.x <= toPos.x ? 0 /* RIGHT_TOP */ : 2 /* LEFT_TOP */;
|
|
320
|
+
}
|
|
321
|
+
let controls;
|
|
322
|
+
switch (type) {
|
|
323
|
+
case 1 /* RIGHT_BOTTOM */:
|
|
324
|
+
controls = [
|
|
325
|
+
{
|
|
326
|
+
x: rect.leftTop.x,
|
|
327
|
+
y: rect.leftTop.y + rect.height / 2
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
x: rect.rightBottom.x,
|
|
331
|
+
y: rect.rightBottom.y - rect.height / 2
|
|
332
|
+
}
|
|
333
|
+
];
|
|
334
|
+
break;
|
|
335
|
+
case 3 /* LEFT_BOTTOM */:
|
|
336
|
+
controls = [
|
|
337
|
+
{
|
|
338
|
+
x: rect.rightTop.x,
|
|
339
|
+
y: rect.rightTop.y + rect.height / 2
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
x: rect.leftBottom.x,
|
|
343
|
+
y: rect.leftBottom.y - rect.height / 2
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
break;
|
|
347
|
+
case 0 /* RIGHT_TOP */:
|
|
348
|
+
controls = [
|
|
349
|
+
{
|
|
350
|
+
x: rect.leftBottom.x,
|
|
351
|
+
y: rect.leftBottom.y + Math.min(rect.height, CONTROL_MAX)
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
x: rect.rightTop.x,
|
|
355
|
+
y: rect.rightTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
356
|
+
}
|
|
357
|
+
];
|
|
358
|
+
break;
|
|
359
|
+
case 2 /* LEFT_TOP */:
|
|
360
|
+
controls = [
|
|
361
|
+
{
|
|
362
|
+
x: rect.rightBottom.x,
|
|
363
|
+
y: rect.rightBottom.y + Math.min(rect.height, CONTROL_MAX)
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
x: rect.leftTop.x,
|
|
367
|
+
y: rect.leftTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
368
|
+
}
|
|
369
|
+
];
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
return controls;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/utils/nanoid.ts
|
|
376
|
+
import { nanoid as nanoidOrigin } from "nanoid";
|
|
377
|
+
function nanoid(n) {
|
|
378
|
+
return nanoidOrigin(n);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/utils/compose.ts
|
|
382
|
+
import { compose, composeAsync } from "@flowgram.ai/utils";
|
|
383
|
+
|
|
384
|
+
// src/utils/fit-view.ts
|
|
385
|
+
import { TransformData } from "@flowgram.ai/core";
|
|
386
|
+
import { Rectangle as Rectangle3 } from "@flowgram.ai/utils";
|
|
387
|
+
var fitView = (doc, playgroundConfig, easing = true) => {
|
|
388
|
+
const bounds = Rectangle3.enlarge(
|
|
389
|
+
doc.getAllNodes().map((node) => node.getData(TransformData).bounds)
|
|
390
|
+
);
|
|
391
|
+
return playgroundConfig.fitView(bounds, easing, 30);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// src/utils/get-anti-overlap-position.ts
|
|
395
|
+
import { TransformData as TransformData2 } from "@flowgram.ai/core";
|
|
396
|
+
function getAntiOverlapPosition(doc, position, containerNode) {
|
|
397
|
+
let { x, y } = position;
|
|
398
|
+
const nodes = containerNode ? containerNode.collapsedChildren : doc.getAllNodes();
|
|
399
|
+
const positions = nodes.map((n) => {
|
|
400
|
+
const transform = n.getData(TransformData2);
|
|
401
|
+
return { x: transform.position.x, y: transform.position.y };
|
|
402
|
+
}).sort((a, b) => a.y - b.y);
|
|
403
|
+
const minDistance = 3;
|
|
404
|
+
for (const pos of positions) {
|
|
405
|
+
const { x: posX, y: posY } = pos;
|
|
406
|
+
if (y - posY < -minDistance) {
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
const deltaX = Math.abs(x - posX);
|
|
410
|
+
const deltaY = Math.abs(y - posY);
|
|
411
|
+
if (deltaX <= minDistance && deltaY <= minDistance) {
|
|
412
|
+
x += 30;
|
|
413
|
+
y += 30;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return { x, y };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/utils/statics.ts
|
|
420
|
+
import { Rectangle as Rectangle4 } from "@flowgram.ai/utils";
|
|
421
|
+
var getPortEntityId = (node, portType, portID = "") => `port_${portType}_${node.id}_${portID}`;
|
|
422
|
+
var WORKFLOW_LINE_ENTITY = "WorkflowLineEntity";
|
|
423
|
+
function domReactToBounds(react) {
|
|
424
|
+
return new Rectangle4(react.x, react.y, react.width, react.height);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/entities/workflow-node-entity.ts
|
|
428
|
+
import { FlowNodeEntity } from "@flowgram.ai/document";
|
|
429
|
+
var WorkflowNodeEntity = FlowNodeEntity;
|
|
430
|
+
|
|
431
|
+
// src/entities/workflow-line-entity.ts
|
|
432
|
+
import { isEqual as isEqual2 } from "lodash-es";
|
|
433
|
+
import { Bezier } from "bezier-js";
|
|
434
|
+
import { domUtils, Point as Point2, Rectangle as Rectangle6 } from "@flowgram.ai/utils";
|
|
435
|
+
import { Entity as Entity2 } from "@flowgram.ai/core";
|
|
436
|
+
|
|
437
|
+
// src/entity-datas/workflow-node-ports-data.ts
|
|
438
|
+
import { isEqual } from "lodash-es";
|
|
439
|
+
import { FlowNodeRenderData } from "@flowgram.ai/document";
|
|
440
|
+
import { EntityData, SizeData } from "@flowgram.ai/core";
|
|
441
|
+
|
|
442
|
+
// src/entities/workflow-port-entity.ts
|
|
443
|
+
import { Rectangle as Rectangle5, Emitter } from "@flowgram.ai/utils";
|
|
444
|
+
import {
|
|
445
|
+
Entity,
|
|
446
|
+
PlaygroundConfigEntity,
|
|
447
|
+
TransformData as TransformData3
|
|
448
|
+
} from "@flowgram.ai/core";
|
|
449
|
+
var PORT_SIZE = 24;
|
|
450
|
+
var WorkflowPortEntity = class extends Entity {
|
|
451
|
+
// relativePosition
|
|
452
|
+
constructor(opts) {
|
|
453
|
+
super(opts);
|
|
454
|
+
this.portID = "";
|
|
455
|
+
this._disabled = false;
|
|
456
|
+
this._hasError = false;
|
|
457
|
+
this._onErrorChangedEmitter = new Emitter();
|
|
458
|
+
this.onErrorChanged = this._onErrorChangedEmitter.event;
|
|
459
|
+
this.portID = opts.portID || "";
|
|
460
|
+
this.portType = opts.type;
|
|
461
|
+
this._disabled = opts.disabled ?? false;
|
|
462
|
+
this.node = opts.node;
|
|
463
|
+
this.updateTargetElement(opts.targetElement);
|
|
464
|
+
this.toDispose.push(this.node.getData(TransformData3).onDataChange(() => this.fireChange()));
|
|
465
|
+
this.toDispose.push(this.node.onDispose(this.dispose.bind(this)));
|
|
466
|
+
}
|
|
467
|
+
static getPortEntityId(node, portType, portID = "") {
|
|
468
|
+
return getPortEntityId(node, portType, portID);
|
|
469
|
+
}
|
|
470
|
+
// 获取连线是否为错误态
|
|
471
|
+
get hasError() {
|
|
472
|
+
return this._hasError;
|
|
473
|
+
}
|
|
474
|
+
// 设置连线的错误态,外部应使用 validate 进行更新
|
|
475
|
+
set hasError(hasError) {
|
|
476
|
+
this._hasError = hasError;
|
|
477
|
+
this._onErrorChangedEmitter.fire();
|
|
478
|
+
}
|
|
479
|
+
validate() {
|
|
480
|
+
const anyLineHasError = this.allLines.some((line) => {
|
|
481
|
+
if (line.disposed || line.isHidden) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
line.validateSelf();
|
|
485
|
+
return line.hasError;
|
|
486
|
+
});
|
|
487
|
+
const isPortHasError = this.node.document.isErrorPort(this);
|
|
488
|
+
this.hasError = anyLineHasError || isPortHasError;
|
|
489
|
+
}
|
|
490
|
+
isErrorPort() {
|
|
491
|
+
return this.node.document.isErrorPort(this);
|
|
492
|
+
}
|
|
493
|
+
get point() {
|
|
494
|
+
const { targetElement } = this;
|
|
495
|
+
const { bounds } = this.node.getData(TransformData3);
|
|
496
|
+
if (targetElement) {
|
|
497
|
+
const pos = domReactToBounds(targetElement.getBoundingClientRect()).center;
|
|
498
|
+
return this.entityManager.getEntity(PlaygroundConfigEntity).getPosFromMouseEvent({
|
|
499
|
+
clientX: pos.x,
|
|
500
|
+
clientY: pos.y
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (this.portType === "input") {
|
|
504
|
+
return bounds.leftCenter;
|
|
505
|
+
}
|
|
506
|
+
return bounds.rightCenter;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* 点的区域
|
|
510
|
+
*/
|
|
511
|
+
get bounds() {
|
|
512
|
+
const { point } = this;
|
|
513
|
+
const halfSize = PORT_SIZE / 2;
|
|
514
|
+
return new Rectangle5(point.x - halfSize, point.y - halfSize, PORT_SIZE, PORT_SIZE);
|
|
515
|
+
}
|
|
516
|
+
isHovered(x, y) {
|
|
517
|
+
return this.bounds.contains(x, y);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* 相对节点左上角的位置
|
|
521
|
+
*/
|
|
522
|
+
get relativePosition() {
|
|
523
|
+
const { point } = this;
|
|
524
|
+
const { bounds } = this.node.getData(TransformData3);
|
|
525
|
+
return {
|
|
526
|
+
x: point.x - bounds.x,
|
|
527
|
+
y: point.y - bounds.y
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
updateTargetElement(el) {
|
|
531
|
+
if (el !== this.targetElement) {
|
|
532
|
+
this.targetElement = el;
|
|
533
|
+
this.fireChange();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* 是否被禁用
|
|
538
|
+
*/
|
|
539
|
+
get disabled() {
|
|
540
|
+
const document2 = this.node.document;
|
|
541
|
+
if (typeof document2.options.isDisabledPort === "function") {
|
|
542
|
+
return document2.options.isDisabledPort(this);
|
|
543
|
+
}
|
|
544
|
+
if (this._disabled) {
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
const meta = this.node.getNodeMeta();
|
|
548
|
+
if (this.portType === "input") {
|
|
549
|
+
return !!meta.inputDisable;
|
|
550
|
+
}
|
|
551
|
+
return !!meta.outputDisable;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 当前点位上连接的线条
|
|
555
|
+
*/
|
|
556
|
+
get lines() {
|
|
557
|
+
return this.allLines.filter((line) => !line.isDrawing);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* 当前点位上连接的线条(包含 isDrawing === true 的线条)
|
|
561
|
+
*/
|
|
562
|
+
get allLines() {
|
|
563
|
+
const lines = [];
|
|
564
|
+
const allLines = this.entityManager.getEntities({
|
|
565
|
+
type: WORKFLOW_LINE_ENTITY
|
|
566
|
+
});
|
|
567
|
+
allLines.forEach((line) => {
|
|
568
|
+
if (line.toPort === this || line.fromPort === this) {
|
|
569
|
+
lines.push(line);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
return lines;
|
|
573
|
+
}
|
|
574
|
+
dispose() {
|
|
575
|
+
this.lines.forEach((l) => l.dispose());
|
|
576
|
+
super.dispose();
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
WorkflowPortEntity.type = "WorkflowPortEntity";
|
|
580
|
+
|
|
581
|
+
// src/entity-datas/workflow-node-ports-data.ts
|
|
582
|
+
var WorkflowNodePortsData = class extends EntityData {
|
|
583
|
+
constructor(entity) {
|
|
584
|
+
super(entity);
|
|
585
|
+
/** 静态的 ports 数据 */
|
|
586
|
+
this._staticPorts = [];
|
|
587
|
+
/** 存储 port 实体的 id,用于判断 port 是否存在 */
|
|
588
|
+
this._portIDSet = /* @__PURE__ */ new Set();
|
|
589
|
+
this.entity = entity;
|
|
590
|
+
const meta = entity.getNodeMeta();
|
|
591
|
+
const defaultPorts = meta.useDynamicPort ? [] : [{ type: "input" }, { type: "output" }];
|
|
592
|
+
this._staticPorts = meta.defaultPorts?.slice() || defaultPorts;
|
|
593
|
+
this.updatePorts(this._staticPorts);
|
|
594
|
+
if (meta.useDynamicPort) {
|
|
595
|
+
this.toDispose.push(
|
|
596
|
+
// 只需要监听节点的大小,因为算的是相对位置
|
|
597
|
+
entity.getData(SizeData).onDataChange(() => {
|
|
598
|
+
if (entity.getData(SizeData).width && entity.getData(SizeData).height) {
|
|
599
|
+
this.updateDynamicPorts();
|
|
600
|
+
}
|
|
601
|
+
})
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
this.onDispose(() => {
|
|
605
|
+
this.allPorts.forEach((port) => port.dispose());
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
getDefaultData() {
|
|
609
|
+
return {};
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* 更新静态的 ports 数据
|
|
613
|
+
*/
|
|
614
|
+
updateStaticPorts(ports) {
|
|
615
|
+
const meta = this.entity.getNodeMeta();
|
|
616
|
+
this._staticPorts = ports;
|
|
617
|
+
if (meta.useDynamicPort) {
|
|
618
|
+
this.updateDynamicPorts();
|
|
619
|
+
} else {
|
|
620
|
+
this.updatePorts(this._staticPorts);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* 动态计算点位,通过 dom 的 data-port-key
|
|
625
|
+
*/
|
|
626
|
+
updateDynamicPorts() {
|
|
627
|
+
const domNode = this.entity.getData(FlowNodeRenderData).node;
|
|
628
|
+
const elements = domNode.querySelectorAll("[data-port-id]");
|
|
629
|
+
const staticPorts = this._staticPorts;
|
|
630
|
+
const dynamicPorts = [];
|
|
631
|
+
if (elements.length > 0) {
|
|
632
|
+
dynamicPorts.push(
|
|
633
|
+
...Array.from(elements).map((element) => ({
|
|
634
|
+
portID: element.getAttribute("data-port-id"),
|
|
635
|
+
type: element.getAttribute("data-port-type"),
|
|
636
|
+
targetElement: element
|
|
637
|
+
}))
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
this.updatePorts(staticPorts.concat(dynamicPorts));
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* 根据 key 获取 port 实体
|
|
644
|
+
*/
|
|
645
|
+
getPortEntityByKey(portType, portKey) {
|
|
646
|
+
const entity = this.getOrCreatePortEntity({
|
|
647
|
+
type: portType,
|
|
648
|
+
portID: portKey
|
|
649
|
+
});
|
|
650
|
+
return entity;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* 更新 ports 数据
|
|
654
|
+
*/
|
|
655
|
+
updatePorts(ports) {
|
|
656
|
+
if (!isEqual(this._prePorts, ports)) {
|
|
657
|
+
const portKeys = ports.map((port) => this.getPortId(port.type, port.portID));
|
|
658
|
+
this._portIDSet.forEach((portId) => {
|
|
659
|
+
if (!portKeys.includes(portId)) {
|
|
660
|
+
this.getPortEntity(portId)?.dispose();
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
ports.forEach((port) => this.updatePortEntity(port));
|
|
664
|
+
this._prePorts = ports;
|
|
665
|
+
this.fireChange();
|
|
666
|
+
}
|
|
667
|
+
this.allPorts.forEach((port) => {
|
|
668
|
+
port.allLines.forEach((line) => {
|
|
669
|
+
line.validate();
|
|
670
|
+
});
|
|
671
|
+
port.validate();
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* 获取所有 port entities
|
|
676
|
+
*/
|
|
677
|
+
get allPorts() {
|
|
678
|
+
return Array.from(this._portIDSet).map((portId) => this.getPortEntity(portId)).filter(Boolean);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* 获取输入点位
|
|
682
|
+
*/
|
|
683
|
+
get inputPorts() {
|
|
684
|
+
return this.allPorts.filter((port) => port.portType === "input");
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* 获取输出点位
|
|
688
|
+
*/
|
|
689
|
+
get outputPorts() {
|
|
690
|
+
return this.allPorts.filter((port) => port.portType === "output");
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* 获取输入点位置
|
|
694
|
+
*/
|
|
695
|
+
get inputPoints() {
|
|
696
|
+
return this.inputPorts.map((port) => port.point);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* 获取输出点位置
|
|
700
|
+
*/
|
|
701
|
+
get outputPoints() {
|
|
702
|
+
return this.inputPorts.map((port) => port.point);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 根据 key 获取 输入点位置
|
|
706
|
+
*/
|
|
707
|
+
getInputPoint(key) {
|
|
708
|
+
return this.getPortEntityByKey("input", key).point;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* 根据 key 获取输出点位置
|
|
712
|
+
*/
|
|
713
|
+
getOutputPoint(key) {
|
|
714
|
+
return this.getPortEntityByKey("output", key).point;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* 获取 port 实体
|
|
718
|
+
*/
|
|
719
|
+
getPortEntity(portId) {
|
|
720
|
+
if (!this._portIDSet.has(portId)) {
|
|
721
|
+
return void 0;
|
|
722
|
+
}
|
|
723
|
+
return this.entity.entityManager.getEntityById(portId);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* 拼接 port 实体的 id
|
|
727
|
+
*/
|
|
728
|
+
getPortId(portType, portKey = "") {
|
|
729
|
+
return getPortEntityId(this.entity, portType, portKey);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* 创建 port 实体
|
|
733
|
+
*/
|
|
734
|
+
createPortEntity(portInfo) {
|
|
735
|
+
const id = this.getPortId(portInfo.type, portInfo.portID);
|
|
736
|
+
let portEntity = this.entity.entityManager.getEntityById(id);
|
|
737
|
+
if (!portEntity) {
|
|
738
|
+
portEntity = this.entity.entityManager.createEntity(WorkflowPortEntity, {
|
|
739
|
+
id,
|
|
740
|
+
node: this.entity,
|
|
741
|
+
...portInfo
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
portEntity.onDispose(() => {
|
|
745
|
+
this._portIDSet.delete(id);
|
|
746
|
+
});
|
|
747
|
+
this._portIDSet.add(id);
|
|
748
|
+
return portEntity;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* 获取或创建 port 实体
|
|
752
|
+
*/
|
|
753
|
+
getOrCreatePortEntity(portInfo) {
|
|
754
|
+
const id = this.getPortId(portInfo.type, portInfo.portID);
|
|
755
|
+
return this.getPortEntity(id) ?? this.createPortEntity(portInfo);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* 更新 port 实体
|
|
759
|
+
*/
|
|
760
|
+
updatePortEntity(portInfo) {
|
|
761
|
+
const portEntity = this.getOrCreatePortEntity(portInfo);
|
|
762
|
+
if (portInfo.targetElement) {
|
|
763
|
+
portEntity.updateTargetElement(portInfo.targetElement);
|
|
764
|
+
}
|
|
765
|
+
return portEntity;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
WorkflowNodePortsData.type = "WorkflowNodePortsData";
|
|
769
|
+
|
|
770
|
+
// src/entities/workflow-line-entity.ts
|
|
771
|
+
var LINE_HOVER_DISTANCE = 8;
|
|
772
|
+
var POINT_RADIUS = 10;
|
|
773
|
+
var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
774
|
+
constructor(opts) {
|
|
775
|
+
super(opts);
|
|
776
|
+
this._processing = false;
|
|
777
|
+
this._hasError = false;
|
|
778
|
+
/**
|
|
779
|
+
* 线条数据
|
|
780
|
+
*/
|
|
781
|
+
this.info = {
|
|
782
|
+
from: ""
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* 贝塞尔线条版本
|
|
786
|
+
*/
|
|
787
|
+
this._bezierVersion = "";
|
|
788
|
+
this.document = opts.document;
|
|
789
|
+
this.linesManager = opts.linesManager;
|
|
790
|
+
this.initInfo({
|
|
791
|
+
from: opts.from,
|
|
792
|
+
to: opts.to,
|
|
793
|
+
drawingTo: opts.drawingTo,
|
|
794
|
+
fromPort: opts.fromPort,
|
|
795
|
+
toPort: opts.toPort
|
|
796
|
+
});
|
|
797
|
+
if (opts.drawingTo) {
|
|
798
|
+
this.isDrawing = true;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* 转成线条 id
|
|
803
|
+
* @param info
|
|
804
|
+
*/
|
|
805
|
+
static portInfoToLineId(info) {
|
|
806
|
+
const { from, to, fromPort, toPort } = info;
|
|
807
|
+
return `${from}_${fromPort || ""}-${to || ""}_${toPort || ""}`;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* 获取线条的前置节点
|
|
811
|
+
*/
|
|
812
|
+
get from() {
|
|
813
|
+
return this._from;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* 获取线条的后置节点
|
|
817
|
+
*/
|
|
818
|
+
get to() {
|
|
819
|
+
return this._to;
|
|
820
|
+
}
|
|
821
|
+
get isHidden() {
|
|
822
|
+
return this.highlightColor === this.linesManager.lineColor.hidden;
|
|
823
|
+
}
|
|
824
|
+
get inContainer() {
|
|
825
|
+
const nodeInContainer = (node) => !!node?.parent && node.parent.flowNodeType !== "root";
|
|
826
|
+
return nodeInContainer(this.from) || nodeInContainer(this.to);
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* 获取是否 testrun processing
|
|
830
|
+
*/
|
|
831
|
+
get processing() {
|
|
832
|
+
return this._processing;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* 设置 testrun processing 状态
|
|
836
|
+
*/
|
|
837
|
+
set processing(status) {
|
|
838
|
+
if (this._processing !== status) {
|
|
839
|
+
this._processing = status;
|
|
840
|
+
this.fireChange();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
// 获取连线是否为错误态
|
|
844
|
+
get hasError() {
|
|
845
|
+
return this._hasError;
|
|
846
|
+
}
|
|
847
|
+
// 设置连线的错误态
|
|
848
|
+
set hasError(hasError) {
|
|
849
|
+
if (this._hasError !== hasError) {
|
|
850
|
+
this._hasError = hasError;
|
|
851
|
+
this.fireChange();
|
|
852
|
+
}
|
|
853
|
+
if (this._node) {
|
|
854
|
+
this._node.dataset.hasError = this.hasError ? "true" : "false";
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* 设置线条的后置节点
|
|
859
|
+
*/
|
|
860
|
+
setToPort(toPort) {
|
|
861
|
+
if (!this.isDrawing) {
|
|
862
|
+
throw new Error("[setToPort] only support drawing line.");
|
|
863
|
+
}
|
|
864
|
+
if (this.toPort === toPort) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
if (toPort && toPort.portType === "input" && this.linesManager.canAddLine(this.fromPort, toPort, true)) {
|
|
868
|
+
const { node, portID } = toPort;
|
|
869
|
+
this._to = node;
|
|
870
|
+
this.info.drawingTo = void 0;
|
|
871
|
+
this.info.isDefaultLine = false;
|
|
872
|
+
this.info.to = node.id;
|
|
873
|
+
this.info.toPort = portID;
|
|
874
|
+
} else {
|
|
875
|
+
this._to = void 0;
|
|
876
|
+
this.info.to = void 0;
|
|
877
|
+
this.info.toPort = "";
|
|
878
|
+
}
|
|
879
|
+
this.fireChange();
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* 设置线条画线时的目标位置
|
|
883
|
+
*/
|
|
884
|
+
set drawingTo(pos) {
|
|
885
|
+
const oldDrawingTo = this.info.drawingTo;
|
|
886
|
+
if (!pos) {
|
|
887
|
+
this.info.drawingTo = void 0;
|
|
888
|
+
this.fireChange();
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (!oldDrawingTo || pos.x !== oldDrawingTo.x || pos.y !== oldDrawingTo.y) {
|
|
892
|
+
this.info.to = void 0;
|
|
893
|
+
this.info.isDefaultLine = false;
|
|
894
|
+
this.info.drawingTo = pos;
|
|
895
|
+
this.fireChange();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* 获取线条正在画线的位置
|
|
900
|
+
*/
|
|
901
|
+
get drawingTo() {
|
|
902
|
+
return this.info.drawingTo;
|
|
903
|
+
}
|
|
904
|
+
get highlightColor() {
|
|
905
|
+
return this.info.highlightColor || "";
|
|
906
|
+
}
|
|
907
|
+
set highlightColor(color) {
|
|
908
|
+
if (this.info.highlightColor !== color) {
|
|
909
|
+
this.info.highlightColor = color;
|
|
910
|
+
this.fireChange();
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* 创建贝塞尔线条
|
|
915
|
+
* @param fromPos 前置节点位置
|
|
916
|
+
* @param toPos 后置节点位置
|
|
917
|
+
* @returns 贝塞尔线条数据
|
|
918
|
+
*/
|
|
919
|
+
createBezier(fromPos, toPos) {
|
|
920
|
+
const controls = this.vertical ? getBezierVerticalControlPoints(fromPos, toPos) : getBezierHorizontalControlPoints(fromPos, toPos);
|
|
921
|
+
const bezier = new Bezier([fromPos, ...controls, toPos]);
|
|
922
|
+
const bbox = bezier.bbox();
|
|
923
|
+
const bboxBounds = new Rectangle6(
|
|
924
|
+
bbox.x.min,
|
|
925
|
+
bbox.y.min,
|
|
926
|
+
bbox.x.max - bbox.x.min,
|
|
927
|
+
bbox.y.max - bbox.y.min
|
|
928
|
+
);
|
|
929
|
+
const foldPoints = FoldLine.getPoints({
|
|
930
|
+
source: {
|
|
931
|
+
x: fromPos.x + POINT_RADIUS,
|
|
932
|
+
y: fromPos.y
|
|
933
|
+
},
|
|
934
|
+
target: {
|
|
935
|
+
x: toPos.x - POINT_RADIUS,
|
|
936
|
+
y: toPos.y
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
const foldPath = FoldLine.getSmoothStepPath(foldPoints);
|
|
940
|
+
this._bezier = {
|
|
941
|
+
fromPos,
|
|
942
|
+
toPos,
|
|
943
|
+
bezier,
|
|
944
|
+
bbox: bboxBounds,
|
|
945
|
+
controls,
|
|
946
|
+
foldPath,
|
|
947
|
+
foldPoints,
|
|
948
|
+
foldBounds: FoldLine.getBounds(foldPoints)
|
|
949
|
+
};
|
|
950
|
+
return this._bezier;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* 获取线条的边框位置大小
|
|
954
|
+
*/
|
|
955
|
+
get bounds() {
|
|
956
|
+
return this.bezier.bbox;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* 获取点和线最接近的距离
|
|
960
|
+
*/
|
|
961
|
+
getHoverDist(pos, lineType = 0 /* BEZIER */) {
|
|
962
|
+
if (lineType === 0 /* BEZIER */) {
|
|
963
|
+
return Point2.getDistance(pos, this.bezier.bezier.project(pos));
|
|
964
|
+
}
|
|
965
|
+
return FoldLine.getFoldLineToPointDistance(this.bezier.foldPoints, pos);
|
|
966
|
+
}
|
|
967
|
+
get fromPort() {
|
|
968
|
+
return this.from.getData(WorkflowNodePortsData).getPortEntityByKey("output", this.info.fromPort);
|
|
969
|
+
}
|
|
970
|
+
get toPort() {
|
|
971
|
+
if (!this.to) {
|
|
972
|
+
return void 0;
|
|
973
|
+
}
|
|
974
|
+
return this.to.getData(WorkflowNodePortsData).getPortEntityByKey("input", this.info.toPort);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* 获取线条真实的输入输出节点坐标
|
|
978
|
+
*/
|
|
979
|
+
get position() {
|
|
980
|
+
const { bezier } = this;
|
|
981
|
+
return {
|
|
982
|
+
from: bezier.fromPos,
|
|
983
|
+
to: bezier.toPos
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* 获取贝塞尔数据
|
|
988
|
+
* 根据两边节点的位置信息创建贝塞尔曲线
|
|
989
|
+
*/
|
|
990
|
+
get bezier() {
|
|
991
|
+
if (!this._bezier) {
|
|
992
|
+
this.refreshBezier();
|
|
993
|
+
}
|
|
994
|
+
return this._bezier;
|
|
995
|
+
}
|
|
996
|
+
refreshBezier() {
|
|
997
|
+
const fromPos = this.from.getData(WorkflowNodePortsData).getOutputPoint(this.info.fromPort);
|
|
998
|
+
const toPos = this.info.drawingTo || this.to.getData(WorkflowNodePortsData).getInputPoint(this.info.toPort);
|
|
999
|
+
const bezierVersion = [fromPos.x, fromPos.y, toPos.x, toPos.y].join("-");
|
|
1000
|
+
if (this._bezier && this._bezierVersion === bezierVersion) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
this._bezierVersion = bezierVersion;
|
|
1004
|
+
this._bezier = this.createBezier(fromPos, toPos);
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* 可以用于判断线条点位信息是否变化
|
|
1008
|
+
*/
|
|
1009
|
+
get bezierDataVersion() {
|
|
1010
|
+
return this._bezierVersion;
|
|
1011
|
+
}
|
|
1012
|
+
/** 是否反转箭头 */
|
|
1013
|
+
get reverse() {
|
|
1014
|
+
return this.linesManager.isReverseLine(this);
|
|
1015
|
+
}
|
|
1016
|
+
/** 是否隐藏箭头 */
|
|
1017
|
+
get hideArrow() {
|
|
1018
|
+
return this.linesManager.isHideArrowLine(this);
|
|
1019
|
+
}
|
|
1020
|
+
/** 是否流动 */
|
|
1021
|
+
get flowing() {
|
|
1022
|
+
return this.linesManager.isFlowingLine(this);
|
|
1023
|
+
}
|
|
1024
|
+
/** 是否禁用 */
|
|
1025
|
+
get disabled() {
|
|
1026
|
+
return this.linesManager.isDisabledLine(this);
|
|
1027
|
+
}
|
|
1028
|
+
/** 是否竖向 */
|
|
1029
|
+
get vertical() {
|
|
1030
|
+
return this.linesManager.isVerticalLine(this);
|
|
1031
|
+
}
|
|
1032
|
+
get color() {
|
|
1033
|
+
return this.linesManager.getLineColor(this);
|
|
1034
|
+
}
|
|
1035
|
+
// get defaultToPos(): IPoint {
|
|
1036
|
+
// const fromPos = this.from.getData(TransformComponent)!.toBounds.center;
|
|
1037
|
+
//
|
|
1038
|
+
// return {
|
|
1039
|
+
// x: fromPos.x + DEFAULT_LINE_LENGTH,
|
|
1040
|
+
// y: fromPos.y,
|
|
1041
|
+
// };
|
|
1042
|
+
// }
|
|
1043
|
+
/**
|
|
1044
|
+
* 初始化线条
|
|
1045
|
+
* @param info 线条信息
|
|
1046
|
+
*/
|
|
1047
|
+
initInfo(info) {
|
|
1048
|
+
if (!isEqual2(info, this.info)) {
|
|
1049
|
+
this.info = info;
|
|
1050
|
+
this._from = this.document.getNode(info.from);
|
|
1051
|
+
this._to = info.to ? this.document.getNode(info.to) : void 0;
|
|
1052
|
+
this.fireChange();
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
// 校验连线是否为错误态
|
|
1056
|
+
validate() {
|
|
1057
|
+
const { fromPort, toPort } = this;
|
|
1058
|
+
this.validateSelf();
|
|
1059
|
+
fromPort?.validate();
|
|
1060
|
+
toPort?.validate();
|
|
1061
|
+
}
|
|
1062
|
+
validateSelf() {
|
|
1063
|
+
const { fromPort, toPort } = this;
|
|
1064
|
+
if (fromPort) {
|
|
1065
|
+
this.hasError = this.linesManager.isErrorLine(fromPort, toPort);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
is(line) {
|
|
1069
|
+
if (line instanceof _WorkflowLineEntity) {
|
|
1070
|
+
return this === line;
|
|
1071
|
+
}
|
|
1072
|
+
return _WorkflowLineEntity.portInfoToLineId(line) === this.id;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* 框选 贝塞尔曲线
|
|
1076
|
+
* TODO 这个方法可能有性能问题,后续看看有没有更好的方式
|
|
1077
|
+
* @param rect
|
|
1078
|
+
*/
|
|
1079
|
+
intersectsRectangle(rect) {
|
|
1080
|
+
const dots = this.bezier.bezier.getLUT(50);
|
|
1081
|
+
return dots.some((dot) => rect.contains(dot.x, dot.y));
|
|
1082
|
+
}
|
|
1083
|
+
canRemove(newLineInfo) {
|
|
1084
|
+
return this.linesManager.canRemove(this, newLineInfo);
|
|
1085
|
+
}
|
|
1086
|
+
get node() {
|
|
1087
|
+
if (this._node) return this._node;
|
|
1088
|
+
this._node = domUtils.createDivWithClass("gedit-flow-activity-line");
|
|
1089
|
+
this._node.dataset.testid = "sdk.workflow.canvas.line";
|
|
1090
|
+
this._node.dataset.lineId = this.id;
|
|
1091
|
+
this._node.dataset.fromNodeId = this.from.id;
|
|
1092
|
+
this._node.dataset.fromPortId = this.fromPort?.id ?? "";
|
|
1093
|
+
this._node.dataset.toNodeId = this.to?.id ?? "";
|
|
1094
|
+
this._node.dataset.toPortId = this.toPort?.id ?? "";
|
|
1095
|
+
this._node.dataset.hasError = this.hasError ? "true" : "false";
|
|
1096
|
+
return this._node;
|
|
1097
|
+
}
|
|
1098
|
+
toJSON() {
|
|
1099
|
+
const json = {
|
|
1100
|
+
sourceNodeID: this.info.from,
|
|
1101
|
+
targetNodeID: this.info.to,
|
|
1102
|
+
sourcePortID: this.info.fromPort,
|
|
1103
|
+
targetPortID: this.info.toPort
|
|
1104
|
+
};
|
|
1105
|
+
if (!json.sourcePortID) {
|
|
1106
|
+
delete json.sourcePortID;
|
|
1107
|
+
}
|
|
1108
|
+
if (!json.targetPortID) {
|
|
1109
|
+
delete json.targetPortID;
|
|
1110
|
+
}
|
|
1111
|
+
return json;
|
|
1112
|
+
}
|
|
1113
|
+
/** 触发线条渲染 */
|
|
1114
|
+
fireRender() {
|
|
1115
|
+
this.fireChange();
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
_WorkflowLineEntity.type = WORKFLOW_LINE_ENTITY;
|
|
1119
|
+
var WorkflowLineEntity = _WorkflowLineEntity;
|
|
1120
|
+
|
|
1121
|
+
// src/service/workflow-select-service.ts
|
|
1122
|
+
var WorkflowSelectService = class {
|
|
1123
|
+
get onSelectionChanged() {
|
|
1124
|
+
return this.selectionService.onSelectionChanged;
|
|
1125
|
+
}
|
|
1126
|
+
get selection() {
|
|
1127
|
+
return this.selectionService.selection;
|
|
1128
|
+
}
|
|
1129
|
+
set selection(entities) {
|
|
1130
|
+
this.selectionService.selection = entities;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* 当前激活的节点只能有一个
|
|
1134
|
+
*/
|
|
1135
|
+
get activatedNode() {
|
|
1136
|
+
const { selectedNodes } = this;
|
|
1137
|
+
if (selectedNodes.length !== 1) {
|
|
1138
|
+
return void 0;
|
|
1139
|
+
}
|
|
1140
|
+
return selectedNodes[0];
|
|
1141
|
+
}
|
|
1142
|
+
isSelected(id) {
|
|
1143
|
+
return this.selectionService.selection.some((s) => s.id === id);
|
|
1144
|
+
}
|
|
1145
|
+
isActivated(id) {
|
|
1146
|
+
return this.activatedNode?.id === id;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* 选中的节点
|
|
1150
|
+
*/
|
|
1151
|
+
get selectedNodes() {
|
|
1152
|
+
return this.selectionService.selection.filter(
|
|
1153
|
+
(n) => n instanceof WorkflowNodeEntity
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* 选中
|
|
1158
|
+
* @param node
|
|
1159
|
+
*/
|
|
1160
|
+
selectNode(node) {
|
|
1161
|
+
this.selectionService.selection = [node];
|
|
1162
|
+
}
|
|
1163
|
+
toggleSelect(node) {
|
|
1164
|
+
if (this.selectionService.selection.includes(node)) {
|
|
1165
|
+
this.selectionService.selection = this.selectionService.selection.filter((n) => n !== node);
|
|
1166
|
+
} else {
|
|
1167
|
+
this.selectionService.selection = this.selectionService.selection.concat(node);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
select(node) {
|
|
1171
|
+
this.selectionService.selection = [node];
|
|
1172
|
+
}
|
|
1173
|
+
clear() {
|
|
1174
|
+
this.selectionService.selection = [];
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* 选中并滚动到节点
|
|
1178
|
+
* @param node
|
|
1179
|
+
*/
|
|
1180
|
+
async selectNodeAndScrollToView(node, fitView2) {
|
|
1181
|
+
this.selectNodeAndFocus(node);
|
|
1182
|
+
const DELAY_TIME = 30;
|
|
1183
|
+
await delay(DELAY_TIME);
|
|
1184
|
+
const scrollConfig = {
|
|
1185
|
+
entities: [node]
|
|
1186
|
+
};
|
|
1187
|
+
if (fitView2) {
|
|
1188
|
+
const bounds = Rectangle7.enlarge([node.getData(TransformData4).bounds]).pad(
|
|
1189
|
+
30,
|
|
1190
|
+
30
|
|
1191
|
+
);
|
|
1192
|
+
const viewport = this.playground.config.getViewport(false);
|
|
1193
|
+
const zoom = SizeSchema.fixSize(bounds, viewport);
|
|
1194
|
+
scrollConfig.zoom = zoom;
|
|
1195
|
+
scrollConfig.scrollToCenter = true;
|
|
1196
|
+
scrollConfig.easing = true;
|
|
1197
|
+
}
|
|
1198
|
+
return this.playground.config.scrollToView(scrollConfig);
|
|
1199
|
+
}
|
|
1200
|
+
selectNodeAndFocus(node) {
|
|
1201
|
+
this.select(node);
|
|
1202
|
+
this.playground.node.focus();
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
__decorateClass([
|
|
1206
|
+
inject(SelectionService)
|
|
1207
|
+
], WorkflowSelectService.prototype, "selectionService", 2);
|
|
1208
|
+
__decorateClass([
|
|
1209
|
+
inject(Playground)
|
|
1210
|
+
], WorkflowSelectService.prototype, "playground", 2);
|
|
1211
|
+
WorkflowSelectService = __decorateClass([
|
|
1212
|
+
injectable()
|
|
1213
|
+
], WorkflowSelectService);
|
|
1214
|
+
|
|
1215
|
+
// src/service/workflow-hover-service.ts
|
|
1216
|
+
import { inject as inject2, injectable as injectable2 } from "inversify";
|
|
1217
|
+
import { EntityManager } from "@flowgram.ai/core";
|
|
1218
|
+
import { Emitter as Emitter2 } from "@flowgram.ai/utils";
|
|
1219
|
+
var WorkflowHoverService = class {
|
|
1220
|
+
constructor() {
|
|
1221
|
+
this.onHoveredChangeEmitter = new Emitter2();
|
|
1222
|
+
this.onHoveredChange = this.onHoveredChangeEmitter.event;
|
|
1223
|
+
// 当前鼠标 hover 位置
|
|
1224
|
+
this.hoveredPos = { x: 0, y: 0 };
|
|
1225
|
+
/**
|
|
1226
|
+
* 当前 hovered 的 节点或者线条或者点
|
|
1227
|
+
* 1: nodeId / lineId (节点 / 线条)
|
|
1228
|
+
* 2: nodeId:portKey (节点连接点)
|
|
1229
|
+
*/
|
|
1230
|
+
this.hoveredKey = "";
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* 更新 hover 的内容
|
|
1234
|
+
* @param hoveredKey hovered key
|
|
1235
|
+
*/
|
|
1236
|
+
updateHoveredKey(hoveredKey) {
|
|
1237
|
+
if (this.hoveredKey !== hoveredKey) {
|
|
1238
|
+
this.hoveredKey = hoveredKey;
|
|
1239
|
+
this.onHoveredChangeEmitter.fire(hoveredKey);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* 清空 hover 内容
|
|
1244
|
+
*/
|
|
1245
|
+
clearHovered() {
|
|
1246
|
+
this.updateHoveredKey("");
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* 判断是否 hover
|
|
1250
|
+
* @param nodeId hoveredKey
|
|
1251
|
+
* @returns 是否 hover
|
|
1252
|
+
*/
|
|
1253
|
+
isHovered(nodeId) {
|
|
1254
|
+
return nodeId === this.hoveredKey;
|
|
1255
|
+
}
|
|
1256
|
+
isSomeHovered() {
|
|
1257
|
+
return !!this.hoveredKey;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* 获取被 hover 的节点或线条
|
|
1261
|
+
*/
|
|
1262
|
+
get hoveredNode() {
|
|
1263
|
+
return this.entityManager.getEntityById(this.hoveredKey);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
__decorateClass([
|
|
1267
|
+
inject2(EntityManager)
|
|
1268
|
+
], WorkflowHoverService.prototype, "entityManager", 2);
|
|
1269
|
+
WorkflowHoverService = __decorateClass([
|
|
1270
|
+
injectable2()
|
|
1271
|
+
], WorkflowHoverService);
|
|
1272
|
+
|
|
1273
|
+
// src/service/workflow-drag-service.ts
|
|
1274
|
+
import { nanoid as nanoid3 } from "nanoid";
|
|
1275
|
+
import { inject as inject6, injectable as injectable6, postConstruct as postConstruct2 } from "inversify";
|
|
1276
|
+
import {
|
|
1277
|
+
domUtils as domUtils2,
|
|
1278
|
+
PromiseDeferred,
|
|
1279
|
+
Emitter as Emitter5,
|
|
1280
|
+
DisposableCollection as DisposableCollection2,
|
|
1281
|
+
Rectangle as Rectangle9,
|
|
1282
|
+
delay as delay2
|
|
1283
|
+
} from "@flowgram.ai/utils";
|
|
1284
|
+
import {
|
|
1285
|
+
FlowNodeTransformData as FlowNodeTransformData5,
|
|
1286
|
+
FlowOperationBaseService
|
|
1287
|
+
} from "@flowgram.ai/document";
|
|
1288
|
+
import { FlowNodeBaseType as FlowNodeBaseType2 } from "@flowgram.ai/document";
|
|
1289
|
+
import {
|
|
1290
|
+
CommandService,
|
|
1291
|
+
PlaygroundConfigEntity as PlaygroundConfigEntity5,
|
|
1292
|
+
PlaygroundDrag,
|
|
1293
|
+
TransformData as TransformData9
|
|
1294
|
+
} from "@flowgram.ai/core";
|
|
1295
|
+
|
|
1296
|
+
// src/workflow-lines-manager.ts
|
|
1297
|
+
import { last } from "lodash-es";
|
|
1298
|
+
import { inject as inject3, injectable as injectable3 } from "inversify";
|
|
1299
|
+
import { Disposable as Disposable2, DisposableCollection, Emitter as Emitter3 } from "@flowgram.ai/utils";
|
|
1300
|
+
import { FlowNodeTransformData as FlowNodeTransformData2 } from "@flowgram.ai/document";
|
|
1301
|
+
import { EntityManager as EntityManager2, PlaygroundConfigEntity as PlaygroundConfigEntity2, TransformData as TransformData6 } from "@flowgram.ai/core";
|
|
1302
|
+
|
|
1303
|
+
// src/workflow-document-option.ts
|
|
1304
|
+
import { FlowNodeErrorData } from "@flowgram.ai/form-core";
|
|
1305
|
+
import { FlowNodeTransformData } from "@flowgram.ai/document";
|
|
1306
|
+
import { TransformData as TransformData5 } from "@flowgram.ai/core";
|
|
1307
|
+
|
|
1308
|
+
// src/utils/flow-node-form-data.ts
|
|
1309
|
+
import { FlowNodeFormData } from "@flowgram.ai/form-core";
|
|
1310
|
+
function getFlowNodeFormData(node) {
|
|
1311
|
+
return node.getData(FlowNodeFormData);
|
|
1312
|
+
}
|
|
1313
|
+
function toFormJSON(node) {
|
|
1314
|
+
const formData = node.getData(FlowNodeFormData);
|
|
1315
|
+
if (!formData || !node.getNodeRegistry().formMeta) return void 0;
|
|
1316
|
+
return formData.toJSON();
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// src/workflow-document-option.ts
|
|
1320
|
+
var WorkflowDocumentOptions = Symbol("WorkflowDocumentOptions");
|
|
1321
|
+
var WorkflowDocumentOptionsDefault = {
|
|
1322
|
+
cursors: {
|
|
1323
|
+
grab: 'url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMCAyMSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMC40ODczIDIuNjIzNzhDOS45MDczMSAyLjYyMzc4IDkuNDM3MTMgMy4wOTM5NiA5LjQzNzEzIDMuNjczOTZWNS4xNDM3NkM5LjM5NDI4IDQuNDAyNzQgOC43Nzk3OCAzLjgxNTA0IDguMDI4MDIgMy44MTUwNEM3LjI0ODQ4IDMuODE1MDQgNi42MTY1MyA0LjQ0Njk5IDYuNjE2NTMgNS4yMjY1M1YxMS44Mjg5TDUuNjc0MTggMTEuMDA0OUM1LjE1NDg3IDEwLjU1MDkgNC40MDk1IDEwLjQ2MzYgMy43OTkzOCAxMC43ODU1TDMuNjk2OTQgMTAuODM5NkMzLjA2MjE3IDExLjE3NDUgMi45MjI2IDEyLjAyMjggMy40MTY2MiAxMi41NDM0TDcuMzM5NTkgMTYuNjc3NVYxNy4zMjU5QzcuMzM5NTkgMTcuNzg2MiA3LjcxMjY5IDE4LjE1OTMgOC4xNzI5MiAxOC4xNTkzSDEzLjgwODRDMTQuMjY4NyAxOC4xNTkzIDE0LjY0MTcgMTcuNzg2MiAxNC42NDE3IDE3LjMyNTlWMTYuNzkzNUMxNS44MDk0IDE1LjY0ODUgMTYuNDY3MyAxNC4wODE5IDE2LjQ2NzMgMTIuNDQ2NVYxMS40OTY3TDE2LjQ2NzEgNi42MzY4NUMxNi40NjcxIDUuOTU2MyAxNS45MTU0IDUuNDA0NjEgMTUuMjM0OCA1LjQwNDYxQzE0LjU1NDMgNS40MDQ2MSAxNC4wMDI2IDUuOTU2MyAxNC4wMDI2IDYuNjM2ODVMMTQuMDAyMSA1LjA0NzI4QzE0LjAwMjEgNC4zNjY3MyAxMy40NTA0IDMuODE1MDQgMTIuNzY5OCAzLjgxNTA0QzEyLjA4OTMgMy44MTUwNCAxMS41Mzc2IDQuMzY2NzMgMTEuNTM3NiA1LjA0NzI4TDExLjUzNzUgMy42NzM5NUMxMS41Mzc1IDMuMDkzOTYgMTEuMDY3MyAyLjYyMzc4IDEwLjQ4NzMgMi42MjM3OFoiIGZpbGw9IndoaXRlIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTAuNDg3NCAxLjM3NDAyQzExLjM2MTIgMS4zNzQwMiAxMi4xMjExIDEuODYxMTggMTIuNTEwNSAyLjU3ODY4QzEyLjU5NTggMi41Njk4MyAxMi42ODIzIDIuNTY1MjggMTIuNzcgMi41NjUyOEMxMy44Mjc4IDIuNTY1MjggMTQuNzMxMSAzLjIyNzAxIDE1LjA4ODUgNC4xNTkxMUMxNS4xMzcgNC4xNTYyOSAxNS4xODU4IDQuMTU0ODYgMTUuMjM1IDQuMTU0ODZDMTYuNjA1OSA0LjE1NDg2IDE3LjcxNzIgNS4yNjYxOSAxNy43MTcyIDYuNjM3MDlMMTcuNzE3NCAxMi40NDY3QzE3LjcxNzQgMTQuMjM1NSAxNy4wNjQ0IDE1Ljk1NTkgMTUuODkxOSAxNy4yOTA0VjE3LjMyNjJDMTUuODkxOSAxOC40NzY4IDE0Ljk1OTEgMTkuNDA5NSAxMy44MDg1IDE5LjQwOTVIOC4xNzMwNkM3LjAyMjQ3IDE5LjQwOTUgNi4wODk3MyAxOC40NzY4IDYuMDg5NzMgMTcuMzI2MlYxNy4xNzY0TDIuNTEwMDMgMTMuNDA0MUMxLjQ0NTk5IDEyLjI4MjggMS43NDY2IDEwLjQ1NTUgMy4xMTM3OSA5LjczNDI0TDMuMjE2MjQgOS42ODAxOUMzLjg5MTY4IDkuMzIzODMgNC42NjE4NSA5LjI1NDAxIDUuMzY2NjYgOS40NTE5OFY1LjIyNjc4QzUuMzY2NjYgMy43NTY4NyA2LjU1ODI2IDIuNTY1MjggOC4wMjgxNiAyLjU2NTI4QzguMTcyOTMgMi41NjUyOCA4LjMxNDk5IDIuNTc2ODQgOC40NTM0NyAyLjU5OTA3QzguODM5NDMgMS44NzA0MiA5LjYwNTQ2IDEuMzc0MDIgMTAuNDg3NCAxLjM3NDAyWk0xMi40NDc2IDMuODU3ODdWOS40NzY0NkMxMi40NDc2IDkuNzI4NTIgMTIuMjQzMyA5LjkzMjg1IDExLjk5MTMgOS45MzI4NUMxMS43MzkyIDkuOTMyODUgMTEuNTM0OSA5LjcyODUyIDExLjUzNDkgOS40NzY0NlYzLjc5NjU1QzExLjUzNDkgMy43Nzk1NiAxMS41MzU4IDMuNzYyNzcgMTEuNTM3NiAzLjc0NjI2VjMuNjc0MkMxMS41Mzc2IDMuNDMyODIgMTEuNDU2MiAzLjIxMDQ2IDExLjMxOTMgMy4wMzMwOUMxMS4xMjcyIDIuNzg0MjggMTAuODI2MSAyLjYyNDAyIDEwLjQ4NzQgMi42MjQwMkMxMC4xMjM4IDIuNjI0MDIgOS44MDMzMiAyLjgwODg2IDkuNjE0ODMgMy4wODk3QzkuNTAyNjkgMy4yNTY3OSA5LjQzNzI2IDMuNDU3ODUgOS40MzcyNiAzLjY3NDJWMy43ODU3M0M5LjQzNzM1IDMuNzg5MzMgOS40MzczOSAzLjc5Mjk0IDkuNDM3MzkgMy43OTY1NVY5LjkwMTdDOS40MzczOSAxMC4xNTM3IDkuMjMzMDYgMTAuMzU4MSA4Ljk4MTAxIDEwLjM1ODFDOC43Mjg5NSAxMC4zNTgxIDguNTI0NjIgMTAuMTUzNyA4LjUyNDYyIDkuOTAxN1YzLjkwNTA3QzguNDE3NzMgMy44NjQ5IDguMzA0NjggMy44MzczMiA4LjE4NzI2IDMuODI0MTVDOC4xMzUwNCAzLjgxODI5IDguMDgxOTUgMy44MTUyOCA4LjAyODE2IDMuODE1MjhDNy4yNDg2MSAzLjgxNTI4IDYuNjE2NjYgNC40NDcyMyA2LjYxNjY2IDUuMjI2NzhWMTEuODI5Mkw1LjY3NDMxIDExLjAwNTJDNS41Nzg2OCAxMC45MjE2IDUuNDc1MzcgMTAuODUwNCA1LjM2NjY2IDEwLjc5MTlDNC44ODUwNiAxMC41MzI5IDQuMjk3MjggMTAuNTIzMSAzLjc5OTUyIDEwLjc4NThMMy42OTcwNyAxMC44Mzk4QzMuMDYyMzEgMTEuMTc0NyAyLjkyMjczIDEyLjAyMzEgMy40MTY3NSAxMi41NDM3TDcuMzM5NzMgMTYuNjc3N1YxNy4zMjYyQzcuMzM5NzMgMTcuNzg2NCA3LjcxMjgyIDE4LjE1OTUgOC4xNzMwNiAxOC4xNTk1SDEzLjgwODVDMTQuMjY4OCAxOC4xNTk1IDE0LjY0MTkgMTcuNzg2NCAxNC42NDE5IDE3LjMyNjJWMTYuNzkzOEMxNS43Mzc5IDE1LjcxOSAxNi4zODQ3IDE0LjI3MjggMTYuNDYgMTIuNzQ3QzE2LjQ2NDEgMTIuNjY0MSAxNi40NjY1IDEyLjU4MDkgMTYuNDY3MiAxMi40OTc1TDE2LjQ2NzQgMTIuNDQ2N0wxNi40NjcyIDYuNjM3MDlDMTYuNDY3MiA1Ljk2MjMgMTUuOTI0OCA1LjQxNDE5IDE1LjI1MjIgNS40MDQ5N0wxNS4yMzUgNS40MDQ4NkMxNS4xMjQ2IDUuNDA0ODYgMTUuMDE3NyA1LjQxOTM2IDE0LjkxNTkgNS40NDY1NlY5LjYwMjI2QzE0LjkxNTkgOS44NTQzMSAxNC43MTE2IDEwLjA1ODYgMTQuNDU5NSAxMC4wNTg2QzE0LjIwNzUgMTAuMDU4NiAxNC4wMDMxIDkuODU0MzEgMTQuMDAzMSA5LjYwMjI2VjYuNjA1MTRDMTQuMDAyOSA2LjYxNTc2IDE0LjAwMjcgNi42MjY0MSAxNC4wMDI3IDYuNjM3MDlWOS4yNzcwNUwxNC4wMDIyIDUuMDQ3NTJDMTQuMDAyMiA0Ljg2OTEzIDEzLjk2NDMgNC42OTk2IDEzLjg5NjEgNC41NDY1M0MxMy43MDY0IDQuMTIwNzIgMTMuMjgyMiAzLjgyMjM1IDEyLjc4NzYgMy44MTU0MUwxMi43NyAzLjgxNTI4QzEyLjY1ODQgMy44MTUyOCAxMi41NTA0IDMuODMwMSAxMi40NDc2IDMuODU3ODdaIiBmaWxsPSIjMUQxQzIzIi8+Cjwvc3ZnPg=="), auto',
|
|
1324
|
+
grabbing: 'url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMCAyMSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02LjYxODE3IDUuNTk4NzVDNi42MTgxNyA0LjgxOTIgNy4yNTAxMiA0LjE4NzI2IDguMDI5NjcgNC4xODcyNkM4Ljc3ODczIDQuMTg3MjYgOS4zOTE1MiA0Ljc3MDc1IDkuNDM4MjkgNS41MDgwMUM5LjQ1OTkyIDQuOTQ3MSA5LjkyMTQ3IDQuNDk5MDIgMTAuNDg3NyA0LjQ5OTAyQzExLjA2NzcgNC40OTkwMiAxMS41Mzc4IDQuOTY5MiAxMS41Mzc4IDUuNTQ5MTlWOC43NjI0NkwxMS41Mzc5IDYuNzExNUMxMS41Mzc5IDYuMDMwOTUgMTIuMDg5NiA1LjQ3OTI2IDEyLjc3MDIgNS40NzkyNkMxMy40NTA3IDUuNDc5MjYgMTQuMDAyNCA2LjAzMDk1IDE0LjAwMjQgNi43MTE1TDE0LjAwMjQgOC43NjI0NkwxNC4wMDI5IDguMDE5ODNDMTQuMDAyOSA3LjMzOTI5IDE0LjU1NDYgNi43ODc1OSAxNS4yMzUyIDYuNzg3NTlDMTUuOTE1NyA2Ljc4NzU5IDE2LjQ2NzQgNy4zMzkyOCAxNi40Njc0IDguMDE5ODNWMTEuNDk3TDE2LjQ2NzUgMTIuNDQ2N0MxNi40Njc1IDE0LjA4MjEgMTUuODA5NiAxNS42NDg3IDE0LjY0MiAxNi43OTM4VjE3LjMyNjJDMTQuNjQyIDE3Ljc4NjQgMTQuMjY4OSAxOC4xNTk1IDEzLjgwODcgMTguMTU5NUg4LjE3MzE3QzcuNzEyOTMgMTguMTU5NSA3LjMzOTg0IDE3Ljc4NjQgNy4zMzk4NCAxNy4zMjYyVjE1Ljk0MjRMNS4zNDU2MiAxNC43NTM0QzQuNTg5MjQgMTQuMzAyNCA0LjEyNTkxIDEzLjQ4NjcgNC4xMjU4OSAxMi42MDYxTDQuMTI1ODMgOS4yODM4M0M0LjEyNTgyIDguOTU0MjcgNC4zMjAwMyA4LjY1NTY2IDQuNjIxMjkgOC41MjIwNUw2LjYxODE3IDcuNjM2MzRWNS41OTg3NVoiIGZpbGw9IndoaXRlIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTAuNDg3OCAzLjI0OTAyQzExLjI3OTYgMy4yNDkwMiAxMS45Nzc4IDMuNjQ5MDIgMTIuMzkxNyA0LjI1Nzk2QzEyLjUxNTEgNC4yMzkwNiAxMi42NDE2IDQuMjI5MjYgMTIuNzcwMyA0LjIyOTI2QzEzLjcyMjQgNC4yMjkyNiAxNC41NDkzIDQuNzY1MzEgMTQuOTY1NyA1LjU1MjA3QzE1LjA1NDMgNS41NDI1IDE1LjE0NDIgNS41Mzc1OSAxNS4yMzUzIDUuNTM3NTlDMTYuNjA2MiA1LjUzNzU5IDE3LjcxNzYgNi42NDg5MyAxNy43MTc2IDguMDE5ODNMMTcuNzE3NyAxMi40NDY3QzE3LjcxNzcgMTQuMjM1NSAxNy4wNjQ3IDE1Ljk1NTkgMTUuODkyMSAxNy4yOTA0VjE3LjMyNjJDMTUuODkyMSAxOC40NzY4IDE0Ljk1OTQgMTkuNDA5NSAxMy44MDg4IDE5LjQwOTVIOC4xNzMzMkM3LjAyMjczIDE5LjQwOTUgNi4wODk5OCAxOC40NzY4IDYuMDg5OTggMTcuMzI2MlYxNi42NTI0TDQuNzA1NjMgMTUuODI3QzMuNTcxMDYgMTUuMTUwNSAyLjg3NjA3IDEzLjkyNzEgMi44NzYwNCAxMi42MDYxTDIuODc1OTggOS4yODM4NUMyLjg3NTk2IDguNDU5OTYgMy4zNjE0OSA3LjcxMzQ1IDQuMTE0NjIgNy4zNzk0TDUuMzY4MzIgNi44MjMzM1Y1LjU5ODc1QzUuMzY4MzIgNC4xMjg4NSA2LjU1OTkxIDIuOTM3MjYgOC4wMjk4MiAyLjkzNzI2QzguNjA4MzEgMi45MzcyNiA5LjE0MzU1IDMuMTIxNyA5LjU4MDA1IDMuNDM1MDVDOS44NTg1MyAzLjMxNTMyIDEwLjE2NTQgMy4yNDkwMiAxMC40ODc4IDMuMjQ5MDJaTTEyLjQ0NzkgNS41MjE4NlY5LjQ3NTU3QzEyLjQ0NzkgOS43Mjc2MiAxMi4yNDM2IDkuOTMxOTUgMTEuOTkxNiA5LjkzMTk1QzExLjc1NjggOS45MzE5NSAxMS41NjM0IDkuNzU0NjUgMTEuNTM4IDkuNTI2NjNDMTEuNTM2MSA5LjUwOTg3IDExLjUzNTIgOS40OTI4MyAxMS41MzUyIDkuNDc1NTdWNS40NzE1OEMxMS41MTU0IDUuMjAwODMgMTEuMzkzIDQuOTU4NTggMTEuMjA2NiA0Ljc4MzU4QzExLjAxODggNC42MDcxMSAxMC43NjU5IDQuNDk5MDIgMTAuNDg3OCA0LjQ5OTAyQzEwLjQ3NjYgNC40OTkwMiAxMC40NjU0IDQuNDk5MTkgMTAuNDU0MiA0LjQ5OTU0QzkuOTAzNDcgNC41MTY4NCA5LjQ1OTY0IDQuOTU4MjQgOS40Mzg0NCA1LjUwODAxQzkuNDM4MiA1LjUwNDMgOS40Mzc5NSA1LjUwMDU4IDkuNDM3NjkgNS40OTY4OFY5LjkwMjQzQzkuNDM3NjkgMTAuMTU0NSA5LjIzMzM2IDEwLjM1ODggOC45ODEzMSAxMC4zNTg4QzguNzI5MjUgMTAuMzU4OCA4LjUyNDkyIDEwLjE1NDUgOC41MjQ5MiA5LjkwMjQzVjQuMjc2NTNDOC4zNzA4NiA0LjIxODgyIDguMjA0MDIgNC4xODcyNiA4LjAyOTgyIDQuMTg3MjZDNy4yNTAyNyA0LjE4NzI2IDYuNjE4MzIgNC44MTkyIDYuNjE4MzIgNS41OTg3NUw2LjYxODI3IDkuOTc1OTlDNi42MTgyNyAxMC4yMjggNi40MTM5NCAxMC40MzI0IDYuMTYxODkgMTAuNDMyNEM1LjkwOTgzIDEwLjQzMjQgNS43MDU1IDEwLjIyOCA1LjcwNTUgOS45NzU5OVY4LjA0MTIyTDQuNjIxNDQgOC41MjIwNUM0LjMyMDE4IDguNjU1NjYgNC4xMjU5NyA4Ljk1NDI3IDQuMTI1OTggOS4yODM4M0w0LjEyNjA0IDEyLjYwNjFDNC4xMjYwNiAxMy40ODY3IDQuNTg5MzkgMTQuMzAyNCA1LjM0NTc2IDE0Ljc1MzRMNy4zMzk5OCAxNS45NDI0VjE3LjMyNjJDNy4zMzk5OCAxNy43ODY0IDcuNzEzMDggMTguMTU5NSA4LjE3MzMyIDE4LjE1OTVIMTMuODA4OEMxNC4yNjkgMTguMTU5NSAxNC42NDIxIDE3Ljc4NjQgMTQuNjQyMSAxNy4zMjYyVjE2Ljc5MzhDMTUuNzM4MSAxNS43MTkgMTYuMzg1IDE0LjI3MjggMTYuNDYwMyAxMi43NDdDMTYuNDY0NiAxMi42NiAxNi40NjcgMTIuNTcyOCAxNi40Njc2IDEyLjQ4NTRMMTYuNDY3NyAxMi40NDY3TDE2LjQ2NzYgOC4wMTk4M0MxNi40Njc2IDcuMzQ1MDQgMTUuOTI1MiA2Ljc5NjkzIDE1LjI1MjUgNi43ODc3MUwxNS4yMzUzIDYuNzg3NTlDMTUuMTI1IDYuNzg3NTkgMTUuMDE4IDYuODAyMSAxNC45MTYyIDYuODI5MzFWOS42MDEzNkMxNC45MTYyIDkuODUzNDIgMTQuNzExOSAxMC4wNTc3IDE0LjQ1OTggMTAuMDU3N0MxNC4yMDc4IDEwLjA1NzcgMTQuMDAzNCA5Ljg1MzQxIDE0LjAwMzQgOS42MDEzNlY3Ljk4OTg1QzE0LjAwMzIgNy45OTk4MiAxNC4wMDMxIDguMDA5ODEgMTQuMDAzMSA4LjAxOTgzTDE0LjAwMzQgOS42MDEzNkwxNC4wMDI1IDYuNzExNUMxNC4wMDI1IDYuNDQ5NzQgMTMuOTIwOSA2LjIwNzA1IDEzLjc4MTggNi4wMDc0OEMxMy41NjIgNS42OTI0MiAxMy4xOTg5IDUuNDg0ODMgMTIuNzg3IDUuNDc5MzdMMTIuNzcwMyA1LjQ3OTI2QzEyLjY1ODggNS40NzkyNiAxMi41NTA3IDUuNDk0MDggMTIuNDQ3OSA1LjUyMTg2WiIgZmlsbD0iIzFEMUMyMyIvPgo8L3N2Zz4="), auto'
|
|
1325
|
+
},
|
|
1326
|
+
toNodeJSON(node) {
|
|
1327
|
+
const nodeError = node.getData(FlowNodeErrorData)?.getError();
|
|
1328
|
+
if (nodeError) {
|
|
1329
|
+
throw nodeError;
|
|
1330
|
+
}
|
|
1331
|
+
const transform = node.getData(TransformData5);
|
|
1332
|
+
let formJSON = toFormJSON(node);
|
|
1333
|
+
const metaData = {};
|
|
1334
|
+
const nodeMeta = node.getNodeMeta();
|
|
1335
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
1336
|
+
if (subCanvas?.isCanvas === false) {
|
|
1337
|
+
const canvasNodeTransform = subCanvas.canvasNode.getData(FlowNodeTransformData);
|
|
1338
|
+
const { x, y } = canvasNodeTransform.transform.position;
|
|
1339
|
+
metaData.canvasPosition = { x, y };
|
|
1340
|
+
}
|
|
1341
|
+
const json = {
|
|
1342
|
+
id: node.id,
|
|
1343
|
+
type: node.flowNodeType,
|
|
1344
|
+
meta: {
|
|
1345
|
+
position: { x: transform.position.x, y: transform.position.y },
|
|
1346
|
+
...metaData
|
|
1347
|
+
},
|
|
1348
|
+
data: formJSON
|
|
1349
|
+
};
|
|
1350
|
+
return json;
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
|
|
1354
|
+
// src/entity-datas/workflow-node-lines-data.ts
|
|
1355
|
+
import { Disposable } from "@flowgram.ai/utils";
|
|
1356
|
+
import { EntityData as EntityData2 } from "@flowgram.ai/core";
|
|
1357
|
+
var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
|
|
1358
|
+
getDefaultData() {
|
|
1359
|
+
return {
|
|
1360
|
+
inputLines: [],
|
|
1361
|
+
outputLines: []
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
constructor(entity) {
|
|
1365
|
+
super(entity);
|
|
1366
|
+
this.entity = entity;
|
|
1367
|
+
this.toDispose.push(
|
|
1368
|
+
Disposable.create(() => {
|
|
1369
|
+
this.inputLines.slice().forEach((line) => line.dispose());
|
|
1370
|
+
this.outputLines.slice().forEach((line) => line.dispose());
|
|
1371
|
+
})
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* 输入线条
|
|
1376
|
+
*/
|
|
1377
|
+
get inputLines() {
|
|
1378
|
+
return this.data.inputLines;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* 输出线条
|
|
1382
|
+
*/
|
|
1383
|
+
get outputLines() {
|
|
1384
|
+
return this.data.outputLines;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* 输入节点
|
|
1388
|
+
*/
|
|
1389
|
+
get inputNodes() {
|
|
1390
|
+
return this.inputLines.map((l) => l.from).filter(Boolean);
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* 所有输入节点
|
|
1394
|
+
*/
|
|
1395
|
+
get allInputNodes() {
|
|
1396
|
+
const nodeSet = /* @__PURE__ */ new Set();
|
|
1397
|
+
const handleNode = (node) => {
|
|
1398
|
+
if (nodeSet.has(node)) {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
nodeSet.add(node);
|
|
1402
|
+
const { inputNodes } = node.getData(_WorkflowNodeLinesData);
|
|
1403
|
+
if (!inputNodes || !inputNodes.length) {
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
inputNodes.forEach((inputNode) => {
|
|
1407
|
+
if (inputNode?.parent === node || node?.parent === inputNode) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
handleNode(inputNode);
|
|
1411
|
+
});
|
|
1412
|
+
};
|
|
1413
|
+
handleNode(this.entity);
|
|
1414
|
+
nodeSet.delete(this.entity);
|
|
1415
|
+
return Array.from(nodeSet);
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* 输出节点
|
|
1419
|
+
*/
|
|
1420
|
+
get outputNodes() {
|
|
1421
|
+
return this.outputLines.map((l) => l.to).filter(Boolean);
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* 输入输出节点
|
|
1425
|
+
*/
|
|
1426
|
+
get allOutputNodes() {
|
|
1427
|
+
const nodeSet = /* @__PURE__ */ new Set();
|
|
1428
|
+
const handleNode = (node) => {
|
|
1429
|
+
if (nodeSet.has(node)) {
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
nodeSet.add(node);
|
|
1433
|
+
const { outputNodes } = node.getData(_WorkflowNodeLinesData);
|
|
1434
|
+
if (!outputNodes || !outputNodes.length) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
outputNodes.forEach((outputNode) => {
|
|
1438
|
+
if (outputNode?.parent === node || node?.parent === outputNode) {
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
handleNode(outputNode);
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1444
|
+
handleNode(this.entity);
|
|
1445
|
+
nodeSet.delete(this.entity);
|
|
1446
|
+
return Array.from(nodeSet);
|
|
1447
|
+
}
|
|
1448
|
+
addLine(line) {
|
|
1449
|
+
if (line.from === this.entity) {
|
|
1450
|
+
this.outputLines.push(line);
|
|
1451
|
+
} else {
|
|
1452
|
+
this.inputLines.push(line);
|
|
1453
|
+
}
|
|
1454
|
+
this.fireChange();
|
|
1455
|
+
}
|
|
1456
|
+
removeLine(line) {
|
|
1457
|
+
const { inputLines, outputLines } = this;
|
|
1458
|
+
const inputIndex = inputLines.indexOf(line);
|
|
1459
|
+
const outputIndex = outputLines.indexOf(line);
|
|
1460
|
+
if (inputIndex !== -1) {
|
|
1461
|
+
inputLines.splice(inputIndex, 1);
|
|
1462
|
+
this.fireChange();
|
|
1463
|
+
}
|
|
1464
|
+
if (outputIndex !== -1) {
|
|
1465
|
+
outputLines.splice(outputIndex, 1);
|
|
1466
|
+
this.fireChange();
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
_WorkflowNodeLinesData.type = "WorkflowNodeLinesData";
|
|
1471
|
+
var WorkflowNodeLinesData = _WorkflowNodeLinesData;
|
|
1472
|
+
|
|
1473
|
+
// src/workflow-lines-manager.ts
|
|
1474
|
+
var WorkflowLinesManager = class {
|
|
1475
|
+
constructor() {
|
|
1476
|
+
this.toDispose = new DisposableCollection();
|
|
1477
|
+
// 线条类型
|
|
1478
|
+
this._lineType = 0 /* BEZIER */;
|
|
1479
|
+
this.onAvailableLinesChangeEmitter = new Emitter3();
|
|
1480
|
+
this.onForceUpdateEmitter = new Emitter3();
|
|
1481
|
+
/**
|
|
1482
|
+
* 有效的线条被添加或者删除时候触发,未连上的线条不算
|
|
1483
|
+
*/
|
|
1484
|
+
this.onAvailableLinesChange = this.onAvailableLinesChangeEmitter.event;
|
|
1485
|
+
/**
|
|
1486
|
+
* 强制渲染 lines
|
|
1487
|
+
*/
|
|
1488
|
+
this.onForceUpdate = this.onForceUpdateEmitter.event;
|
|
1489
|
+
/**
|
|
1490
|
+
* 是否在调整线条
|
|
1491
|
+
*/
|
|
1492
|
+
this.isDrawing = false;
|
|
1493
|
+
}
|
|
1494
|
+
init(doc) {
|
|
1495
|
+
this.document = doc;
|
|
1496
|
+
}
|
|
1497
|
+
forceUpdate() {
|
|
1498
|
+
this.onForceUpdateEmitter.fire();
|
|
1499
|
+
}
|
|
1500
|
+
get lineType() {
|
|
1501
|
+
return this._lineType;
|
|
1502
|
+
}
|
|
1503
|
+
get lineColor() {
|
|
1504
|
+
const color = {
|
|
1505
|
+
default: "#4d53e8" /* DEFUALT */,
|
|
1506
|
+
error: "red" /* ERROR */,
|
|
1507
|
+
hidden: "transparent" /* HIDDEN */,
|
|
1508
|
+
drawing: "#5DD6E3" /* DRAWING */,
|
|
1509
|
+
hovered: "#37d0ff" /* HOVER */,
|
|
1510
|
+
selected: "#37d0ff" /* HOVER */
|
|
1511
|
+
};
|
|
1512
|
+
if (this.options.lineColor) {
|
|
1513
|
+
Object.assign(color, this.options.lineColor);
|
|
1514
|
+
}
|
|
1515
|
+
return color;
|
|
1516
|
+
}
|
|
1517
|
+
switchLineType(newType) {
|
|
1518
|
+
if (newType === void 0) {
|
|
1519
|
+
if (this._lineType === 0 /* BEZIER */) {
|
|
1520
|
+
newType = 1 /* LINE_CHART */;
|
|
1521
|
+
} else {
|
|
1522
|
+
newType = 0 /* BEZIER */;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
if (newType !== this._lineType) {
|
|
1526
|
+
this._lineType = newType;
|
|
1527
|
+
this.entityManager.fireEntityChanged(WorkflowLineEntity.type);
|
|
1528
|
+
}
|
|
1529
|
+
return this._lineType;
|
|
1530
|
+
}
|
|
1531
|
+
getAllLines() {
|
|
1532
|
+
return this.entityManager.getEntities(WorkflowLineEntity);
|
|
1533
|
+
}
|
|
1534
|
+
hasLine(portInfo) {
|
|
1535
|
+
return !!this.entityManager.getEntityById(
|
|
1536
|
+
WorkflowLineEntity.portInfoToLineId(portInfo)
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
getLine(portInfo) {
|
|
1540
|
+
return this.entityManager.getEntityById(
|
|
1541
|
+
WorkflowLineEntity.portInfoToLineId(portInfo)
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
replaceLine(oldPortInfo, newPortInfo) {
|
|
1545
|
+
const oldLine = this.getLine(oldPortInfo);
|
|
1546
|
+
if (oldLine) {
|
|
1547
|
+
oldLine.dispose();
|
|
1548
|
+
}
|
|
1549
|
+
return this.createLine(newPortInfo);
|
|
1550
|
+
}
|
|
1551
|
+
createLine(options) {
|
|
1552
|
+
const { from, to, drawingTo, fromPort, toPort } = options;
|
|
1553
|
+
const available = Boolean(from && to);
|
|
1554
|
+
const key = options.key || WorkflowLineEntity.portInfoToLineId(options);
|
|
1555
|
+
let line = this.entityManager.getEntityById(key);
|
|
1556
|
+
if (line) {
|
|
1557
|
+
line.highlightColor = "";
|
|
1558
|
+
line.validate();
|
|
1559
|
+
return line;
|
|
1560
|
+
}
|
|
1561
|
+
const fromNode = this.entityManager.getEntityById(from)?.getData(WorkflowNodeLinesData);
|
|
1562
|
+
const toNode = to ? this.entityManager.getEntityById(to).getData(WorkflowNodeLinesData) : void 0;
|
|
1563
|
+
if (!fromNode) {
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
this.isDrawing = Boolean(drawingTo);
|
|
1567
|
+
line = this.entityManager.createEntity(WorkflowLineEntity, {
|
|
1568
|
+
id: key,
|
|
1569
|
+
document: this.document,
|
|
1570
|
+
linesManager: this,
|
|
1571
|
+
from,
|
|
1572
|
+
fromPort,
|
|
1573
|
+
toPort,
|
|
1574
|
+
to,
|
|
1575
|
+
drawingTo
|
|
1576
|
+
});
|
|
1577
|
+
fromNode.addLine(line);
|
|
1578
|
+
toNode?.addLine(line);
|
|
1579
|
+
line.onDispose(() => {
|
|
1580
|
+
if (drawingTo) {
|
|
1581
|
+
this.isDrawing = false;
|
|
1582
|
+
}
|
|
1583
|
+
fromNode.removeLine(line);
|
|
1584
|
+
toNode?.removeLine(line);
|
|
1585
|
+
line.validate();
|
|
1586
|
+
});
|
|
1587
|
+
line.toDispose.push(
|
|
1588
|
+
Disposable2.create(() => {
|
|
1589
|
+
if (available) {
|
|
1590
|
+
this.onAvailableLinesChangeEmitter.fire({
|
|
1591
|
+
type: "DELETE_LINE" /* DELETE_LINE */,
|
|
1592
|
+
toJSON: () => line.toJSON(),
|
|
1593
|
+
entity: line
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
})
|
|
1597
|
+
);
|
|
1598
|
+
if (available) {
|
|
1599
|
+
this.onAvailableLinesChangeEmitter.fire({
|
|
1600
|
+
type: "ADD_LINE" /* ADD_LINE */,
|
|
1601
|
+
toJSON: () => line.toJSON(),
|
|
1602
|
+
entity: line
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
line.validate();
|
|
1606
|
+
return line;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* 获取线条中距离鼠标位置最近的线条和距离
|
|
1610
|
+
* @param mousePos 鼠标位置
|
|
1611
|
+
* @param minDistance 最小检测距离
|
|
1612
|
+
* @returns 距离鼠标位置最近的线条 以及距离
|
|
1613
|
+
*/
|
|
1614
|
+
getCloseInLineFromMousePos(mousePos, minDistance = LINE_HOVER_DISTANCE) {
|
|
1615
|
+
let targetLine, targetLineDist;
|
|
1616
|
+
this.getAllLines().forEach((line) => {
|
|
1617
|
+
const dist = line.getHoverDist(mousePos, this.lineType);
|
|
1618
|
+
if (dist <= minDistance && (!targetLineDist || targetLineDist >= dist)) {
|
|
1619
|
+
targetLineDist = dist;
|
|
1620
|
+
targetLine = line;
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
return targetLine;
|
|
1624
|
+
}
|
|
1625
|
+
dispose() {
|
|
1626
|
+
this.toDispose.dispose();
|
|
1627
|
+
}
|
|
1628
|
+
get disposed() {
|
|
1629
|
+
return this.toDispose.disposed;
|
|
1630
|
+
}
|
|
1631
|
+
isErrorLine(fromPort, toPort) {
|
|
1632
|
+
if (this.options.isErrorLine) {
|
|
1633
|
+
return this.options.isErrorLine(fromPort, toPort, this);
|
|
1634
|
+
}
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
isReverseLine(line) {
|
|
1638
|
+
if (this.options.isReverseLine) {
|
|
1639
|
+
return this.options.isReverseLine(line);
|
|
1640
|
+
}
|
|
1641
|
+
return false;
|
|
1642
|
+
}
|
|
1643
|
+
isHideArrowLine(line) {
|
|
1644
|
+
if (this.options.isHideArrowLine) {
|
|
1645
|
+
return this.options.isHideArrowLine(line);
|
|
1646
|
+
}
|
|
1647
|
+
return false;
|
|
1648
|
+
}
|
|
1649
|
+
isFlowingLine(line) {
|
|
1650
|
+
if (this.options.isFlowingLine) {
|
|
1651
|
+
return this.options.isFlowingLine(line);
|
|
1652
|
+
}
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
isDisabledLine(line) {
|
|
1656
|
+
if (this.options.isDisabledLine) {
|
|
1657
|
+
return this.options.isDisabledLine(line);
|
|
1658
|
+
}
|
|
1659
|
+
return false;
|
|
1660
|
+
}
|
|
1661
|
+
isVerticalLine(line) {
|
|
1662
|
+
if (this.options.isVerticalLine) {
|
|
1663
|
+
return this.options.isVerticalLine(line);
|
|
1664
|
+
}
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
getLineColor(line) {
|
|
1668
|
+
if (line.isHidden) {
|
|
1669
|
+
return this.lineColor.hidden;
|
|
1670
|
+
}
|
|
1671
|
+
if (line.hasError) {
|
|
1672
|
+
return this.lineColor.error;
|
|
1673
|
+
}
|
|
1674
|
+
if (line.highlightColor) {
|
|
1675
|
+
return line.highlightColor;
|
|
1676
|
+
}
|
|
1677
|
+
if (line.drawingTo) {
|
|
1678
|
+
return this.lineColor.drawing;
|
|
1679
|
+
}
|
|
1680
|
+
if (this.hoverService.isHovered(line.id)) {
|
|
1681
|
+
return this.lineColor.hovered;
|
|
1682
|
+
}
|
|
1683
|
+
if (this.selectService.isSelected(line.id)) {
|
|
1684
|
+
return this.lineColor.selected;
|
|
1685
|
+
}
|
|
1686
|
+
return this.lineColor.default;
|
|
1687
|
+
}
|
|
1688
|
+
canAddLine(fromPort, toPort, silent) {
|
|
1689
|
+
if (fromPort === toPort || fromPort.node === toPort.node || fromPort.portType !== "output" || toPort.portType !== "input" || toPort.disabled) {
|
|
1690
|
+
return false;
|
|
1691
|
+
}
|
|
1692
|
+
if (this.options.canAddLine) {
|
|
1693
|
+
return this.options.canAddLine(fromPort, toPort, this, silent);
|
|
1694
|
+
}
|
|
1695
|
+
return fromPort.node !== toPort.node;
|
|
1696
|
+
}
|
|
1697
|
+
toJSON() {
|
|
1698
|
+
return this.getAllLines().filter((l) => !l.isDrawing).map((l) => l.toJSON());
|
|
1699
|
+
}
|
|
1700
|
+
getPortById(portId) {
|
|
1701
|
+
return this.entityManager.getEntityById(portId);
|
|
1702
|
+
}
|
|
1703
|
+
canRemove(line, newLineInfo, silent) {
|
|
1704
|
+
if (this.options && this.options.canDeleteLine && !this.options.canDeleteLine(line, newLineInfo, silent)) {
|
|
1705
|
+
return false;
|
|
1706
|
+
}
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
canReset(fromPort, oldToPort, newToPort) {
|
|
1710
|
+
if (this.options && this.options.canResetLine && !this.options.canResetLine(fromPort, oldToPort, newToPort, this)) {
|
|
1711
|
+
return false;
|
|
1712
|
+
}
|
|
1713
|
+
return true;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* 根据鼠标位置找到 port
|
|
1717
|
+
* @param pos
|
|
1718
|
+
*/
|
|
1719
|
+
getPortFromMousePos(pos) {
|
|
1720
|
+
const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
|
|
1721
|
+
const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
|
|
1722
|
+
if (targetPort) {
|
|
1723
|
+
const targetNode = this.document.getAllNodes().slice().reverse().filter((node) => targetPort.node?.parent?.id !== node.id).find((node) => node.getData(TransformData6).contains(pos.x, pos.y));
|
|
1724
|
+
if (targetNode && targetNode !== targetPort.node) {
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return targetPort;
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* 根据鼠标位置找到 node
|
|
1732
|
+
* @param pos - 鼠标位置
|
|
1733
|
+
*/
|
|
1734
|
+
getNodeFromMousePos(pos) {
|
|
1735
|
+
const allNodes = this.document.getAllNodes();
|
|
1736
|
+
const containNodes = [];
|
|
1737
|
+
const { selection } = this.selectService;
|
|
1738
|
+
const zoom = this.entityManager.getEntity(PlaygroundConfigEntity2)?.config?.zoom || 1;
|
|
1739
|
+
allNodes.forEach((node) => {
|
|
1740
|
+
const { bounds } = node.getData(FlowNodeTransformData2);
|
|
1741
|
+
if (bounds.clone().pad(4 / zoom).contains(pos.x, pos.y)) {
|
|
1742
|
+
containNodes.push(node);
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
if (selection?.length) {
|
|
1746
|
+
const filteredNodes = containNodes.filter(
|
|
1747
|
+
(node) => selection.some((_node) => node.id === _node.id)
|
|
1748
|
+
);
|
|
1749
|
+
if (filteredNodes?.length) {
|
|
1750
|
+
return last(filteredNodes);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
return last(containNodes);
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
__decorateClass([
|
|
1757
|
+
inject3(WorkflowHoverService)
|
|
1758
|
+
], WorkflowLinesManager.prototype, "hoverService", 2);
|
|
1759
|
+
__decorateClass([
|
|
1760
|
+
inject3(WorkflowSelectService)
|
|
1761
|
+
], WorkflowLinesManager.prototype, "selectService", 2);
|
|
1762
|
+
__decorateClass([
|
|
1763
|
+
inject3(EntityManager2)
|
|
1764
|
+
], WorkflowLinesManager.prototype, "entityManager", 2);
|
|
1765
|
+
__decorateClass([
|
|
1766
|
+
inject3(WorkflowDocumentOptions)
|
|
1767
|
+
], WorkflowLinesManager.prototype, "options", 2);
|
|
1768
|
+
WorkflowLinesManager = __decorateClass([
|
|
1769
|
+
injectable3()
|
|
1770
|
+
], WorkflowLinesManager);
|
|
1771
|
+
|
|
1772
|
+
// src/workflow-document.ts
|
|
1773
|
+
import { customAlphabet } from "nanoid";
|
|
1774
|
+
import { inject as inject5, injectable as injectable5, optional, postConstruct } from "inversify";
|
|
1775
|
+
import { Disposable as Disposable3, Emitter as Emitter4 } from "@flowgram.ai/utils";
|
|
1776
|
+
import { NodeEngineContext } from "@flowgram.ai/form-core";
|
|
1777
|
+
import { FlowDocument, FlowNodeBaseType, FlowNodeTransformData as FlowNodeTransformData4 } from "@flowgram.ai/document";
|
|
1778
|
+
import {
|
|
1779
|
+
injectPlaygroundContext,
|
|
1780
|
+
PlaygroundConfigEntity as PlaygroundConfigEntity4,
|
|
1781
|
+
PositionData,
|
|
1782
|
+
TransformData as TransformData8
|
|
1783
|
+
} from "@flowgram.ai/core";
|
|
1784
|
+
|
|
1785
|
+
// src/layout/free-layout.ts
|
|
1786
|
+
import { inject as inject4, injectable as injectable4 } from "inversify";
|
|
1787
|
+
import {
|
|
1788
|
+
FlowDocumentProvider,
|
|
1789
|
+
FlowNodeTransformData as FlowNodeTransformData3
|
|
1790
|
+
} from "@flowgram.ai/document";
|
|
1791
|
+
import { PlaygroundConfigEntity as PlaygroundConfigEntity3, TransformData as TransformData7 } from "@flowgram.ai/core";
|
|
1792
|
+
import {
|
|
1793
|
+
PaddingSchema,
|
|
1794
|
+
Rectangle as Rectangle8,
|
|
1795
|
+
SizeSchema as SizeSchema2
|
|
1796
|
+
} from "@flowgram.ai/utils";
|
|
1797
|
+
var FREE_LAYOUT_KEY = "free-layout";
|
|
1798
|
+
var FreeLayout = class {
|
|
1799
|
+
constructor() {
|
|
1800
|
+
this.name = FREE_LAYOUT_KEY;
|
|
1801
|
+
}
|
|
1802
|
+
get document() {
|
|
1803
|
+
return this.documentProvider();
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* 更新布局
|
|
1807
|
+
*/
|
|
1808
|
+
update() {
|
|
1809
|
+
if (this.document.root.getData(FlowNodeTransformData3)?.localDirty) {
|
|
1810
|
+
this.document.root.clearMemoGlobal();
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
syncTransform(node) {
|
|
1814
|
+
const transform = node.getData(FlowNodeTransformData3);
|
|
1815
|
+
if (!transform.localDirty) {
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
node.clearMemoGlobal();
|
|
1819
|
+
node.clearMemoLocal();
|
|
1820
|
+
transform.transform.update({
|
|
1821
|
+
size: transform.data.size
|
|
1822
|
+
});
|
|
1823
|
+
if (!node.parent) {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
node.parent.clearMemoGlobal();
|
|
1827
|
+
node.parent.clearMemoLocal();
|
|
1828
|
+
const parentTransform = node.parent.getData(FlowNodeTransformData3);
|
|
1829
|
+
parentTransform.transform.fireChange();
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* 获取节点的 padding 数据
|
|
1833
|
+
* @param node
|
|
1834
|
+
*/
|
|
1835
|
+
getPadding(node) {
|
|
1836
|
+
const { padding } = node.getNodeMeta();
|
|
1837
|
+
const transform = node.getData(FlowNodeTransformData3);
|
|
1838
|
+
if (padding) {
|
|
1839
|
+
return typeof padding === "function" ? padding(transform) : padding;
|
|
1840
|
+
}
|
|
1841
|
+
return PaddingSchema.empty();
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* 默认滚动到 fitview 区域
|
|
1845
|
+
* @param contentSize
|
|
1846
|
+
*/
|
|
1847
|
+
getInitScroll(contentSize) {
|
|
1848
|
+
const bounds = Rectangle8.enlarge(
|
|
1849
|
+
this.document.getAllNodes().map((node) => node.getData(TransformData7).bounds)
|
|
1850
|
+
).pad(30, 30);
|
|
1851
|
+
const viewport = this.playgroundConfig.getViewport(false);
|
|
1852
|
+
const zoom = SizeSchema2.fixSize(bounds, viewport);
|
|
1853
|
+
return {
|
|
1854
|
+
scrollX: (bounds.x + bounds.width / 2) * zoom - this.playgroundConfig.config.width / 2,
|
|
1855
|
+
scrollY: (bounds.y + bounds.height / 2) * zoom - this.playgroundConfig.config.height / 2
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* 获取默认输入点
|
|
1860
|
+
*/
|
|
1861
|
+
getDefaultInputPoint(node) {
|
|
1862
|
+
return node.getData(TransformData7).bounds.leftCenter;
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* 获取默认输出点
|
|
1866
|
+
*/
|
|
1867
|
+
getDefaultOutputPoint(node) {
|
|
1868
|
+
return node.getData(TransformData7).bounds.rightCenter;
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* 水平中心点
|
|
1872
|
+
*/
|
|
1873
|
+
getDefaultNodeOrigin() {
|
|
1874
|
+
return { x: 0.5, y: 0 };
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
__decorateClass([
|
|
1878
|
+
inject4(PlaygroundConfigEntity3)
|
|
1879
|
+
], FreeLayout.prototype, "playgroundConfig", 2);
|
|
1880
|
+
__decorateClass([
|
|
1881
|
+
inject4(FlowDocumentProvider)
|
|
1882
|
+
], FreeLayout.prototype, "documentProvider", 2);
|
|
1883
|
+
FreeLayout = __decorateClass([
|
|
1884
|
+
injectable4()
|
|
1885
|
+
], FreeLayout);
|
|
1886
|
+
|
|
1887
|
+
// src/workflow-document.ts
|
|
1888
|
+
var nanoid2 = customAlphabet("1234567890", 5);
|
|
1889
|
+
var WorkflowDocumentProvider = Symbol("WorkflowDocumentProvider");
|
|
1890
|
+
var WorkflowDocument = class extends FlowDocument {
|
|
1891
|
+
constructor() {
|
|
1892
|
+
super(...arguments);
|
|
1893
|
+
this._onContentChangeEmitter = new Emitter4();
|
|
1894
|
+
this.onLoadedEmitter = new Emitter4();
|
|
1895
|
+
this.onContentChange = this._onContentChangeEmitter.event;
|
|
1896
|
+
this._onReloadEmitter = new Emitter4();
|
|
1897
|
+
this.onReload = this._onReloadEmitter.event;
|
|
1898
|
+
this.disposed = false;
|
|
1899
|
+
/**
|
|
1900
|
+
* 数据加载完成
|
|
1901
|
+
*/
|
|
1902
|
+
this.onLoaded = this.onLoadedEmitter.event;
|
|
1903
|
+
this._loading = false;
|
|
1904
|
+
this.options = {};
|
|
1905
|
+
}
|
|
1906
|
+
get loading() {
|
|
1907
|
+
return this._loading;
|
|
1908
|
+
}
|
|
1909
|
+
async fitView(easing) {
|
|
1910
|
+
return fitView(this, this.playgroundConfig, easing).then(() => {
|
|
1911
|
+
this.linesManager.forceUpdate();
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
init() {
|
|
1915
|
+
super.init();
|
|
1916
|
+
this.currentLayoutKey = this.options.defaultLayout || FREE_LAYOUT_KEY;
|
|
1917
|
+
this.linesManager.init(this);
|
|
1918
|
+
this.playgroundConfig.getCursors = () => this.options.cursors;
|
|
1919
|
+
this.linesManager.onAvailableLinesChange((e) => this.fireContentChange(e));
|
|
1920
|
+
this.playgroundConfig.onReadonlyOrDisabledChange(({ readonly }) => {
|
|
1921
|
+
if (this.nodeEngineContext) {
|
|
1922
|
+
this.nodeEngineContext.readonly = readonly;
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
async load() {
|
|
1927
|
+
this._loading = true;
|
|
1928
|
+
await super.load();
|
|
1929
|
+
this._loading = false;
|
|
1930
|
+
this.onLoadedEmitter.fire();
|
|
1931
|
+
}
|
|
1932
|
+
async reload(json, delayTime = 0) {
|
|
1933
|
+
this._loading = true;
|
|
1934
|
+
this.clear();
|
|
1935
|
+
this.fromJSON(json);
|
|
1936
|
+
await delay(delayTime);
|
|
1937
|
+
this._loading = false;
|
|
1938
|
+
this._onReloadEmitter.fire(this);
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* 从数据加载
|
|
1942
|
+
* @param json
|
|
1943
|
+
*/
|
|
1944
|
+
fromJSON(json, fireRender = true) {
|
|
1945
|
+
const { flattenJSON, nodeBlocks, nodeEdges } = this.flatJSON(json);
|
|
1946
|
+
const nestedJSON = this.nestJSON(flattenJSON, nodeBlocks, nodeEdges);
|
|
1947
|
+
this.entityManager.changeEntityLocked = true;
|
|
1948
|
+
this.renderJSON(nestedJSON);
|
|
1949
|
+
this.entityManager.changeEntityLocked = false;
|
|
1950
|
+
this.transformer.loading = false;
|
|
1951
|
+
if (fireRender) {
|
|
1952
|
+
this.fireRender();
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* 清空画布
|
|
1957
|
+
*/
|
|
1958
|
+
clear() {
|
|
1959
|
+
this.getAllNodes().map((node) => node.dispose());
|
|
1960
|
+
this.linesManager.getAllLines().map((line) => line.dispose());
|
|
1961
|
+
this.getAllPorts().map((port) => port.dispose());
|
|
1962
|
+
this.selectServices.clear();
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* 创建流程节点
|
|
1966
|
+
* @param json
|
|
1967
|
+
*/
|
|
1968
|
+
createWorkflowNode(json, isClone = false, parentId) {
|
|
1969
|
+
const isExistedNode = this.getNode(json.id);
|
|
1970
|
+
const parent = this.getNode(parentId ?? this.root.id) ?? this.root;
|
|
1971
|
+
const node = this.addNode(
|
|
1972
|
+
{
|
|
1973
|
+
...json,
|
|
1974
|
+
parent
|
|
1975
|
+
},
|
|
1976
|
+
void 0,
|
|
1977
|
+
true
|
|
1978
|
+
);
|
|
1979
|
+
const registry = node.getNodeRegistry();
|
|
1980
|
+
const { formMeta } = registry;
|
|
1981
|
+
const meta = node.getNodeMeta();
|
|
1982
|
+
const formData = getFlowNodeFormData(node);
|
|
1983
|
+
const transform = node.getData(FlowNodeTransformData4);
|
|
1984
|
+
const freeLayout = this.layout;
|
|
1985
|
+
transform.onDataChange(() => {
|
|
1986
|
+
freeLayout.syncTransform(node);
|
|
1987
|
+
});
|
|
1988
|
+
let { position } = meta;
|
|
1989
|
+
if (!position) {
|
|
1990
|
+
position = this.getNodeDefaultPosition(json.type);
|
|
1991
|
+
}
|
|
1992
|
+
node.getData(TransformData8).update({
|
|
1993
|
+
position
|
|
1994
|
+
});
|
|
1995
|
+
if (formMeta && formData) {
|
|
1996
|
+
formData.createForm(formMeta, json.data);
|
|
1997
|
+
formData.onDataChange(() => {
|
|
1998
|
+
this.fireContentChange({
|
|
1999
|
+
type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
|
|
2000
|
+
toJSON: () => formData.toJSON(),
|
|
2001
|
+
entity: node
|
|
2002
|
+
});
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
const positionData = node.getData(PositionData);
|
|
2006
|
+
positionData.onDataChange(() => {
|
|
2007
|
+
this.fireContentChange({
|
|
2008
|
+
type: "MOVE_NODE" /* MOVE_NODE */,
|
|
2009
|
+
toJSON: () => positionData.toJSON(),
|
|
2010
|
+
entity: node
|
|
2011
|
+
});
|
|
2012
|
+
});
|
|
2013
|
+
const subCanvas = this.getNodeSubCanvas(node);
|
|
2014
|
+
if (!isExistedNode && !subCanvas?.isCanvas) {
|
|
2015
|
+
this.fireContentChange({
|
|
2016
|
+
type: "ADD_NODE" /* ADD_NODE */,
|
|
2017
|
+
entity: node,
|
|
2018
|
+
toJSON: () => this.toNodeJSON(node)
|
|
2019
|
+
});
|
|
2020
|
+
node.toDispose.push(
|
|
2021
|
+
Disposable3.create(() => {
|
|
2022
|
+
this.fireContentChange({
|
|
2023
|
+
type: "DELETE_NODE" /* DELETE_NODE */,
|
|
2024
|
+
entity: node,
|
|
2025
|
+
toJSON: () => this.toNodeJSON(node)
|
|
2026
|
+
});
|
|
2027
|
+
})
|
|
2028
|
+
);
|
|
2029
|
+
node.toDispose.push(
|
|
2030
|
+
Disposable3.create(() => {
|
|
2031
|
+
if (!node.parent || node.parent.flowNodeType === FlowNodeBaseType.ROOT) {
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
const parentTransform = node.parent.getData(FlowNodeTransformData4);
|
|
2035
|
+
setTimeout(() => {
|
|
2036
|
+
parentTransform.fireChange();
|
|
2037
|
+
}, 0);
|
|
2038
|
+
})
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
if (json.blocks) {
|
|
2042
|
+
this.renderJSON(
|
|
2043
|
+
{ nodes: json.blocks, edges: json.edges ?? [] },
|
|
2044
|
+
{
|
|
2045
|
+
parent: node,
|
|
2046
|
+
isClone
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2050
|
+
if (subCanvas) {
|
|
2051
|
+
const canvasTransform = subCanvas.canvasNode.getData(TransformData8);
|
|
2052
|
+
canvasTransform.update({
|
|
2053
|
+
position: subCanvas.parentNode.getNodeMeta()?.canvasPosition
|
|
2054
|
+
});
|
|
2055
|
+
subCanvas.parentNode.onDispose(() => {
|
|
2056
|
+
subCanvas.canvasNode.dispose();
|
|
2057
|
+
});
|
|
2058
|
+
subCanvas.canvasNode.onDispose(() => {
|
|
2059
|
+
subCanvas.parentNode.dispose();
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
this.onNodeCreateEmitter.fire({
|
|
2063
|
+
node,
|
|
2064
|
+
data: json
|
|
2065
|
+
});
|
|
2066
|
+
return node;
|
|
2067
|
+
}
|
|
2068
|
+
/**
|
|
2069
|
+
* 获取默认的 x y 坐标, 默认为当前画布可视区域中心
|
|
2070
|
+
* @param type
|
|
2071
|
+
* @protected
|
|
2072
|
+
*/
|
|
2073
|
+
getNodeDefaultPosition(type) {
|
|
2074
|
+
const { size } = this.getNodeRegistry(type).meta || {};
|
|
2075
|
+
let position = this.playgroundConfig.getViewport(true).center;
|
|
2076
|
+
if (size) {
|
|
2077
|
+
position = {
|
|
2078
|
+
x: position.x,
|
|
2079
|
+
y: position.y - size.height / 2
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
return getAntiOverlapPosition(this, position);
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* 通过类型创建节点, 如果没有提供position 则直接放在画布中间
|
|
2086
|
+
* @param type
|
|
2087
|
+
*/
|
|
2088
|
+
createWorkflowNodeByType(type, position, json = {}, parentID) {
|
|
2089
|
+
let id = json.id;
|
|
2090
|
+
if (id === void 0) {
|
|
2091
|
+
do {
|
|
2092
|
+
id = `1${nanoid2()}`;
|
|
2093
|
+
} while (this.entityManager.getEntityById(id));
|
|
2094
|
+
} else {
|
|
2095
|
+
if (this.entityManager.getEntityById(id)) {
|
|
2096
|
+
throw new Error(`[WorkflowDocument.createWorkflowNodeByType] Node Id "${id}" duplicated.`);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
return this.createWorkflowNode(
|
|
2100
|
+
{
|
|
2101
|
+
id,
|
|
2102
|
+
type,
|
|
2103
|
+
meta: { position, ...json?.meta },
|
|
2104
|
+
// TODO title 和 meta 要从注册数据去拿
|
|
2105
|
+
data: json?.data,
|
|
2106
|
+
blocks: json?.blocks,
|
|
2107
|
+
edges: json?.edges
|
|
2108
|
+
},
|
|
2109
|
+
false,
|
|
2110
|
+
parentID
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
2113
|
+
getAllNodes() {
|
|
2114
|
+
return this.entityManager.getEntities(WorkflowNodeEntity).filter((n) => n.id !== FlowNodeBaseType.ROOT);
|
|
2115
|
+
}
|
|
2116
|
+
getAllPorts() {
|
|
2117
|
+
return this.entityManager.getEntities(WorkflowPortEntity).filter((p) => p.node.id !== FlowNodeBaseType.ROOT);
|
|
2118
|
+
}
|
|
2119
|
+
/**
|
|
2120
|
+
* 获取画布中的非游离节点
|
|
2121
|
+
* 1. 开始节点
|
|
2122
|
+
* 2. 从开始节点出发能走到的节点
|
|
2123
|
+
* 3. 结束节点
|
|
2124
|
+
* 4. 默认所有子画布内节点为游离节点
|
|
2125
|
+
*/
|
|
2126
|
+
getAssociatedNodes() {
|
|
2127
|
+
const allNode = this.getAllNodes();
|
|
2128
|
+
const allLines = this.linesManager.getAllLines().filter((line) => line.from && line.to).map((line) => ({
|
|
2129
|
+
from: line.from.id,
|
|
2130
|
+
to: line.to.id
|
|
2131
|
+
}));
|
|
2132
|
+
const startNodeId = allNode.find((node) => node.isStart).id;
|
|
2133
|
+
const endNodeId = allNode.find((node) => node.isNodeEnd).id;
|
|
2134
|
+
const nodeInSubCanvas = allNode.filter((node) => node.parent?.flowNodeType === FlowNodeBaseType.SUB_CANVAS).map((node) => node.id);
|
|
2135
|
+
const associatedCache = /* @__PURE__ */ new Set([endNodeId, ...nodeInSubCanvas]);
|
|
2136
|
+
const bfs = (nodeId) => {
|
|
2137
|
+
if (associatedCache.has(nodeId)) {
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
associatedCache.add(nodeId);
|
|
2141
|
+
const nextNodes = allLines.reduce((ids, { from, to }) => {
|
|
2142
|
+
if (from === nodeId && !associatedCache.has(to)) {
|
|
2143
|
+
ids.push(to);
|
|
2144
|
+
}
|
|
2145
|
+
return ids;
|
|
2146
|
+
}, []);
|
|
2147
|
+
nextNodes.forEach(bfs);
|
|
2148
|
+
};
|
|
2149
|
+
bfs(startNodeId);
|
|
2150
|
+
const associatedNodes = allNode.filter((node) => associatedCache.has(node.id));
|
|
2151
|
+
return associatedNodes;
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* 触发渲染
|
|
2155
|
+
*/
|
|
2156
|
+
fireRender() {
|
|
2157
|
+
this.entityManager.fireEntityChanged(WorkflowNodeEntity.type);
|
|
2158
|
+
this.entityManager.fireEntityChanged(WorkflowLineEntity.type);
|
|
2159
|
+
this.entityManager.fireEntityChanged(WorkflowPortEntity.type);
|
|
2160
|
+
}
|
|
2161
|
+
fireContentChange(event) {
|
|
2162
|
+
if (this._loading || this.disposed || this.entityManager.changeEntityLocked) {
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
this._onContentChangeEmitter.fire(event);
|
|
2166
|
+
}
|
|
2167
|
+
toNodeJSON(node) {
|
|
2168
|
+
const subCanvas = this.getNodeSubCanvas(node);
|
|
2169
|
+
if (subCanvas?.isCanvas === true) {
|
|
2170
|
+
return this.toNodeJSON(subCanvas.parentNode);
|
|
2171
|
+
}
|
|
2172
|
+
const json = this.toNodeJSONFromOptions(node);
|
|
2173
|
+
const children = this.getNodeChildren(node);
|
|
2174
|
+
const blocks = children.map((child) => this.toNodeJSON(child));
|
|
2175
|
+
const linesMap = /* @__PURE__ */ new Map();
|
|
2176
|
+
children.forEach((child) => {
|
|
2177
|
+
const childLinesData = child.getData(WorkflowNodeLinesData);
|
|
2178
|
+
[...childLinesData.inputLines, ...childLinesData.outputLines].filter(Boolean).forEach((line) => {
|
|
2179
|
+
const lineJSON = this.toLineJSON(line);
|
|
2180
|
+
if (!lineJSON || linesMap.has(line.id)) {
|
|
2181
|
+
return;
|
|
2182
|
+
}
|
|
2183
|
+
linesMap.set(line.id, lineJSON);
|
|
2184
|
+
});
|
|
2185
|
+
});
|
|
2186
|
+
const edges = Array.from(linesMap.values());
|
|
2187
|
+
if (blocks.length > 0) json.blocks = blocks;
|
|
2188
|
+
if (edges.length > 0) json.edges = edges;
|
|
2189
|
+
return json;
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* 节点转换为JSON, 没有format的过程
|
|
2193
|
+
* @param node
|
|
2194
|
+
* @returns
|
|
2195
|
+
*/
|
|
2196
|
+
toNodeJSONFromOptions(node) {
|
|
2197
|
+
if (this.options.toNodeJSON) {
|
|
2198
|
+
return this.options.toNodeJSON(node);
|
|
2199
|
+
}
|
|
2200
|
+
return WorkflowDocumentOptionsDefault.toNodeJSON(node);
|
|
2201
|
+
}
|
|
2202
|
+
copyNode(node, newNodeId, format, position) {
|
|
2203
|
+
let json = this.toNodeJSON(node);
|
|
2204
|
+
if (format) {
|
|
2205
|
+
json = format(json);
|
|
2206
|
+
}
|
|
2207
|
+
position = position || {
|
|
2208
|
+
x: json.meta.position.x + 30,
|
|
2209
|
+
y: json.meta.position.y + 30
|
|
2210
|
+
};
|
|
2211
|
+
return this.createWorkflowNode(
|
|
2212
|
+
{
|
|
2213
|
+
id: newNodeId || `1${nanoid2()}`,
|
|
2214
|
+
type: node.flowNodeType,
|
|
2215
|
+
meta: {
|
|
2216
|
+
...json.meta,
|
|
2217
|
+
position
|
|
2218
|
+
},
|
|
2219
|
+
data: json.data,
|
|
2220
|
+
blocks: json.blocks,
|
|
2221
|
+
edges: json.edges
|
|
2222
|
+
},
|
|
2223
|
+
true,
|
|
2224
|
+
node.parent?.id
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position, parentId) {
|
|
2228
|
+
position = position || {
|
|
2229
|
+
x: nodeJSON.meta.position.x + 30,
|
|
2230
|
+
y: nodeJSON.meta.position.y + 30
|
|
2231
|
+
};
|
|
2232
|
+
return this.createWorkflowNode(
|
|
2233
|
+
{
|
|
2234
|
+
id: newNodeId || `1${nanoid2()}`,
|
|
2235
|
+
type: flowNodeType,
|
|
2236
|
+
meta: {
|
|
2237
|
+
...nodeJSON.meta,
|
|
2238
|
+
position
|
|
2239
|
+
},
|
|
2240
|
+
data: nodeJSON.data,
|
|
2241
|
+
blocks: nodeJSON.blocks,
|
|
2242
|
+
edges: nodeJSON.edges
|
|
2243
|
+
},
|
|
2244
|
+
true,
|
|
2245
|
+
parentId
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
canRemove(node, silent) {
|
|
2249
|
+
const meta = node.getNodeMeta();
|
|
2250
|
+
if (meta.deleteDisable) {
|
|
2251
|
+
return false;
|
|
2252
|
+
}
|
|
2253
|
+
if (this.options.canDeleteNode && !this.options.canDeleteNode(node, silent)) {
|
|
2254
|
+
return false;
|
|
2255
|
+
}
|
|
2256
|
+
return true;
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* 判断端口是否为错误态
|
|
2260
|
+
*/
|
|
2261
|
+
isErrorPort(port) {
|
|
2262
|
+
if (typeof this.options.isErrorPort === "function") {
|
|
2263
|
+
return this.options.isErrorPort(port);
|
|
2264
|
+
}
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* 导出数据
|
|
2269
|
+
*/
|
|
2270
|
+
toJSON() {
|
|
2271
|
+
const rootJSON = this.toNodeJSON(this.root);
|
|
2272
|
+
return {
|
|
2273
|
+
nodes: rootJSON.blocks ?? [],
|
|
2274
|
+
edges: rootJSON.edges ?? []
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
dispose() {
|
|
2278
|
+
if (this.disposed) {
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
super.dispose();
|
|
2282
|
+
this.disposed = true;
|
|
2283
|
+
this._onReloadEmitter.dispose();
|
|
2284
|
+
}
|
|
2285
|
+
getEdgeID(edge) {
|
|
2286
|
+
return WorkflowLineEntity.portInfoToLineId({
|
|
2287
|
+
from: edge.sourceNodeID,
|
|
2288
|
+
to: edge.targetNodeID,
|
|
2289
|
+
fromPort: edge.sourcePortID,
|
|
2290
|
+
toPort: edge.targetPortID
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* 拍平树形json结构,将结构信息提取到map
|
|
2295
|
+
*/
|
|
2296
|
+
flatJSON(json = { nodes: [], edges: [] }) {
|
|
2297
|
+
const nodeBlocks = /* @__PURE__ */ new Map();
|
|
2298
|
+
const nodeEdges = /* @__PURE__ */ new Map();
|
|
2299
|
+
const rootNodes = json.nodes ?? [];
|
|
2300
|
+
const rootEdges = json.edges ?? [];
|
|
2301
|
+
const flattenNodeJSONs = [...rootNodes];
|
|
2302
|
+
const flattenEdgeJSONs = [...rootEdges];
|
|
2303
|
+
const rootBlockIDs = rootNodes.map((node) => node.id);
|
|
2304
|
+
const rootEdgeIDs = rootEdges.map((edge) => this.getEdgeID(edge));
|
|
2305
|
+
nodeBlocks.set(FlowNodeBaseType.ROOT, rootBlockIDs);
|
|
2306
|
+
nodeEdges.set(FlowNodeBaseType.ROOT, rootEdgeIDs);
|
|
2307
|
+
rootNodes.forEach((nodeJSON) => {
|
|
2308
|
+
const { blocks, edges } = nodeJSON;
|
|
2309
|
+
if (blocks) {
|
|
2310
|
+
flattenNodeJSONs.push(...blocks);
|
|
2311
|
+
const blockIDs = [];
|
|
2312
|
+
blocks.forEach((block) => {
|
|
2313
|
+
blockIDs.push(block.id);
|
|
2314
|
+
});
|
|
2315
|
+
nodeBlocks.set(nodeJSON.id, blockIDs);
|
|
2316
|
+
delete nodeJSON.blocks;
|
|
2317
|
+
}
|
|
2318
|
+
if (edges) {
|
|
2319
|
+
flattenEdgeJSONs.push(...edges);
|
|
2320
|
+
const edgeIDs = [];
|
|
2321
|
+
edges.forEach((edge) => {
|
|
2322
|
+
const edgeID = this.getEdgeID(edge);
|
|
2323
|
+
edgeIDs.push(edgeID);
|
|
2324
|
+
});
|
|
2325
|
+
nodeEdges.set(nodeJSON.id, edgeIDs);
|
|
2326
|
+
delete nodeJSON.edges;
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
const flattenJSON = {
|
|
2330
|
+
nodes: flattenNodeJSONs,
|
|
2331
|
+
edges: flattenEdgeJSONs
|
|
2332
|
+
};
|
|
2333
|
+
return {
|
|
2334
|
+
flattenJSON,
|
|
2335
|
+
nodeBlocks,
|
|
2336
|
+
nodeEdges
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* 对JSON进行分层
|
|
2341
|
+
*/
|
|
2342
|
+
nestJSON(flattenJSON, nodeBlocks, nodeEdges) {
|
|
2343
|
+
const nestJSON = {
|
|
2344
|
+
nodes: [],
|
|
2345
|
+
edges: []
|
|
2346
|
+
};
|
|
2347
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
2348
|
+
const edgeMap = /* @__PURE__ */ new Map();
|
|
2349
|
+
const rootBlockSet = new Set(nodeBlocks.get(FlowNodeBaseType.ROOT) ?? []);
|
|
2350
|
+
const rootEdgeSet = new Set(nodeEdges.get(FlowNodeBaseType.ROOT) ?? []);
|
|
2351
|
+
flattenJSON.nodes.forEach((nodeJSON) => {
|
|
2352
|
+
nodeMap.set(nodeJSON.id, nodeJSON);
|
|
2353
|
+
});
|
|
2354
|
+
flattenJSON.edges.forEach((edgeJSON) => {
|
|
2355
|
+
const edgeID = this.getEdgeID(edgeJSON);
|
|
2356
|
+
edgeMap.set(edgeID, edgeJSON);
|
|
2357
|
+
});
|
|
2358
|
+
flattenJSON.nodes.forEach((nodeJSON) => {
|
|
2359
|
+
if (rootBlockSet.has(nodeJSON.id)) {
|
|
2360
|
+
nestJSON.nodes.push(nodeJSON);
|
|
2361
|
+
}
|
|
2362
|
+
if (nodeBlocks.has(nodeJSON.id)) {
|
|
2363
|
+
const blockIDs = nodeBlocks.get(nodeJSON.id);
|
|
2364
|
+
const blockJSONs = blockIDs.map((blockID) => nodeMap.get(blockID)).filter(Boolean);
|
|
2365
|
+
nodeJSON.blocks = blockJSONs;
|
|
2366
|
+
}
|
|
2367
|
+
if (nodeEdges.has(nodeJSON.id)) {
|
|
2368
|
+
const edgeIDs = nodeEdges.get(nodeJSON.id);
|
|
2369
|
+
const edgeJSONs = edgeIDs.map((edgeID) => edgeMap.get(edgeID)).filter(Boolean);
|
|
2370
|
+
nodeJSON.edges = edgeJSONs;
|
|
2371
|
+
}
|
|
2372
|
+
});
|
|
2373
|
+
flattenJSON.edges.forEach((edgeJSON) => {
|
|
2374
|
+
const edgeID = this.getEdgeID(edgeJSON);
|
|
2375
|
+
if (rootEdgeSet.has(edgeID)) {
|
|
2376
|
+
nestJSON.edges.push(edgeJSON);
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
return nestJSON;
|
|
2380
|
+
}
|
|
2381
|
+
/**
|
|
2382
|
+
* 逐层创建节点和线条
|
|
2383
|
+
*/
|
|
2384
|
+
renderJSON(json, options) {
|
|
2385
|
+
const { parent = this.root, isClone = false } = options ?? {};
|
|
2386
|
+
const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
|
|
2387
|
+
json.nodes.forEach((nodeJSON) => {
|
|
2388
|
+
this.createWorkflowNode(nodeJSON, isClone, containerID);
|
|
2389
|
+
}), // 创建线条
|
|
2390
|
+
json.edges.forEach((edge) => this.createWorkflowLine(edge, containerID));
|
|
2391
|
+
}
|
|
2392
|
+
getNodeSubCanvas(node) {
|
|
2393
|
+
if (!node) return;
|
|
2394
|
+
const nodeMeta = node.getNodeMeta();
|
|
2395
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
2396
|
+
return subCanvas;
|
|
2397
|
+
}
|
|
2398
|
+
getNodeChildren(node) {
|
|
2399
|
+
if (!node) return [];
|
|
2400
|
+
const subCanvas = this.getNodeSubCanvas(node);
|
|
2401
|
+
const childrenWithCanvas = subCanvas ? subCanvas.canvasNode.collapsedChildren : node.collapsedChildren;
|
|
2402
|
+
const children = childrenWithCanvas.filter((child) => {
|
|
2403
|
+
const childMeta = child.getNodeMeta();
|
|
2404
|
+
return !childMeta.subCanvas?.(node)?.isCanvas;
|
|
2405
|
+
}).filter(Boolean);
|
|
2406
|
+
return children;
|
|
2407
|
+
}
|
|
2408
|
+
toLineJSON(line) {
|
|
2409
|
+
const lineJSON = line.toJSON();
|
|
2410
|
+
if (!line.to || !line.info.to || !line.toPort) {
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
const fromSubCanvas = this.getNodeSubCanvas(line.from);
|
|
2414
|
+
const toSubCanvas = this.getNodeSubCanvas(line.to);
|
|
2415
|
+
if (fromSubCanvas && !fromSubCanvas.isCanvas && toSubCanvas && toSubCanvas.isCanvas) {
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
if (line.from === line.to.parent && fromSubCanvas) {
|
|
2419
|
+
return {
|
|
2420
|
+
...lineJSON,
|
|
2421
|
+
sourceNodeID: fromSubCanvas.parentNode.id
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
if (line.to === line.from.parent && toSubCanvas) {
|
|
2425
|
+
return {
|
|
2426
|
+
...lineJSON,
|
|
2427
|
+
targetNodeID: toSubCanvas.parentNode.id
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
return lineJSON;
|
|
2431
|
+
}
|
|
2432
|
+
createWorkflowLine(json, parentId) {
|
|
2433
|
+
const fromNode = this.getNode(json.sourceNodeID);
|
|
2434
|
+
const toNode = this.getNode(json.targetNodeID);
|
|
2435
|
+
if (!fromNode || !toNode) {
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
const lineInfo = {
|
|
2439
|
+
from: json.sourceNodeID,
|
|
2440
|
+
fromPort: json.sourcePortID,
|
|
2441
|
+
to: json.targetNodeID,
|
|
2442
|
+
toPort: json.targetPortID
|
|
2443
|
+
};
|
|
2444
|
+
if (!parentId) {
|
|
2445
|
+
return this.linesManager.createLine(lineInfo);
|
|
2446
|
+
}
|
|
2447
|
+
const canvasNode = this.getNode(parentId);
|
|
2448
|
+
if (!canvasNode) {
|
|
2449
|
+
return this.linesManager.createLine(lineInfo);
|
|
2450
|
+
}
|
|
2451
|
+
const parentSubCanvas = this.getNodeSubCanvas(canvasNode);
|
|
2452
|
+
if (!parentSubCanvas) {
|
|
2453
|
+
return this.linesManager.createLine(lineInfo);
|
|
2454
|
+
}
|
|
2455
|
+
if (lineInfo.from === parentSubCanvas.parentNode.id) {
|
|
2456
|
+
return this.linesManager.createLine({
|
|
2457
|
+
...lineInfo,
|
|
2458
|
+
from: parentSubCanvas.canvasNode.id
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
if (lineInfo.to === parentSubCanvas.parentNode.id) {
|
|
2462
|
+
return this.linesManager.createLine({
|
|
2463
|
+
...lineInfo,
|
|
2464
|
+
to: parentSubCanvas.canvasNode.id
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
return this.linesManager.createLine(lineInfo);
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
__decorateClass([
|
|
2471
|
+
inject5(WorkflowLinesManager)
|
|
2472
|
+
], WorkflowDocument.prototype, "linesManager", 2);
|
|
2473
|
+
__decorateClass([
|
|
2474
|
+
inject5(PlaygroundConfigEntity4)
|
|
2475
|
+
], WorkflowDocument.prototype, "playgroundConfig", 2);
|
|
2476
|
+
__decorateClass([
|
|
2477
|
+
injectPlaygroundContext()
|
|
2478
|
+
], WorkflowDocument.prototype, "playgroundContext", 2);
|
|
2479
|
+
__decorateClass([
|
|
2480
|
+
inject5(WorkflowDocumentOptions)
|
|
2481
|
+
], WorkflowDocument.prototype, "options", 2);
|
|
2482
|
+
__decorateClass([
|
|
2483
|
+
inject5(NodeEngineContext),
|
|
2484
|
+
optional()
|
|
2485
|
+
], WorkflowDocument.prototype, "nodeEngineContext", 2);
|
|
2486
|
+
__decorateClass([
|
|
2487
|
+
inject5(WorkflowSelectService)
|
|
2488
|
+
], WorkflowDocument.prototype, "selectServices", 2);
|
|
2489
|
+
__decorateClass([
|
|
2490
|
+
postConstruct()
|
|
2491
|
+
], WorkflowDocument.prototype, "init", 1);
|
|
2492
|
+
WorkflowDocument = __decorateClass([
|
|
2493
|
+
injectable5()
|
|
2494
|
+
], WorkflowDocument);
|
|
2495
|
+
|
|
2496
|
+
// src/service/workflow-drag-service.ts
|
|
2497
|
+
var DRAG_TIMEOUT = 100;
|
|
2498
|
+
var DRAG_MIN_DELTA = 5;
|
|
2499
|
+
function checkDragSuccess(time, e, originLine) {
|
|
2500
|
+
if (!originLine || time > DRAG_TIMEOUT || Math.abs(e.endPos.x - e.startPos.x) >= DRAG_MIN_DELTA || Math.abs(e.endPos.y - e.startPos.y) >= DRAG_MIN_DELTA) {
|
|
2501
|
+
return true;
|
|
2502
|
+
}
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
var WorkflowDragService = class {
|
|
2506
|
+
constructor() {
|
|
2507
|
+
this._onDragLineEventEmitter = new Emitter5();
|
|
2508
|
+
this.onDragLineEventChange = this._onDragLineEventEmitter.event;
|
|
2509
|
+
this.isDragging = false;
|
|
2510
|
+
this._nodesDragEmitter = new Emitter5();
|
|
2511
|
+
this.onNodesDrag = this._nodesDragEmitter.event;
|
|
2512
|
+
this._toDispose = new DisposableCollection2();
|
|
2513
|
+
this._droppableTransforms = [];
|
|
2514
|
+
this.posAdjusters = /* @__PURE__ */ new Set();
|
|
2515
|
+
this._onDragLineEndCallbacks = /* @__PURE__ */ new Map();
|
|
2516
|
+
}
|
|
2517
|
+
init() {
|
|
2518
|
+
this._toDispose.pushAll([this._onDragLineEventEmitter, this._nodesDragEmitter]);
|
|
2519
|
+
}
|
|
2520
|
+
dispose() {
|
|
2521
|
+
this._toDispose.dispose();
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* 拖拽选中节点
|
|
2525
|
+
* @param event
|
|
2526
|
+
*/
|
|
2527
|
+
startDragSelectedNodes(event) {
|
|
2528
|
+
let { selectedNodes } = this.selectService;
|
|
2529
|
+
if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
|
|
2530
|
+
return Promise.resolve(false);
|
|
2531
|
+
}
|
|
2532
|
+
const sameParent = this.childrenOfContainer(selectedNodes);
|
|
2533
|
+
if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType2.ROOT) {
|
|
2534
|
+
selectedNodes = [sameParent];
|
|
2535
|
+
}
|
|
2536
|
+
const { altKey } = event;
|
|
2537
|
+
let startPosition = this.getNodesPosition(selectedNodes);
|
|
2538
|
+
let startPositions = selectedNodes.map((node) => {
|
|
2539
|
+
const transform = node.getData(TransformData9);
|
|
2540
|
+
return { x: transform.position.x, y: transform.position.y };
|
|
2541
|
+
});
|
|
2542
|
+
let dragSuccess = false;
|
|
2543
|
+
const startTime = Date.now();
|
|
2544
|
+
const dragger = new PlaygroundDrag({
|
|
2545
|
+
onDragStart: () => {
|
|
2546
|
+
this.isDragging = true;
|
|
2547
|
+
},
|
|
2548
|
+
onDrag: (e) => {
|
|
2549
|
+
if (!dragSuccess && checkDragSuccess(Date.now() - startTime, e)) {
|
|
2550
|
+
dragSuccess = true;
|
|
2551
|
+
if (altKey) {
|
|
2552
|
+
const tryCopyNodes = selectedNodes;
|
|
2553
|
+
if (tryCopyNodes.length > 0) {
|
|
2554
|
+
this.commandService.executeCommand("PASTE_NODES" /* PASTE_NODES */, tryCopyNodes, true).then((newNodes) => {
|
|
2555
|
+
if (newNodes && Array.isArray(newNodes) && newNodes.length > 0) {
|
|
2556
|
+
selectedNodes = newNodes;
|
|
2557
|
+
startPosition = this.getNodesPosition(tryCopyNodes);
|
|
2558
|
+
startPositions = tryCopyNodes.filter((n) => !n.getNodeMeta().copyDisable).map((node) => {
|
|
2559
|
+
const transform = node.getData(TransformData9);
|
|
2560
|
+
return {
|
|
2561
|
+
x: transform.position.x,
|
|
2562
|
+
y: transform.position.y
|
|
2563
|
+
};
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
const offset = this.getDragPosOffset({
|
|
2571
|
+
event: e,
|
|
2572
|
+
selectedNodes,
|
|
2573
|
+
startPosition
|
|
2574
|
+
});
|
|
2575
|
+
selectedNodes.forEach((node, index) => {
|
|
2576
|
+
const transform = node.getData(TransformData9);
|
|
2577
|
+
const nodeStartPosition = startPositions[index];
|
|
2578
|
+
const newPosition = {
|
|
2579
|
+
x: nodeStartPosition.x + offset.x,
|
|
2580
|
+
y: nodeStartPosition.y + offset.y
|
|
2581
|
+
};
|
|
2582
|
+
if (node.collapsedChildren?.length > 0) {
|
|
2583
|
+
node.collapsedChildren.forEach((childNode) => {
|
|
2584
|
+
const childNodeTransformData = childNode.getData(FlowNodeTransformData5);
|
|
2585
|
+
childNodeTransformData.fireChange();
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
transform.update({
|
|
2589
|
+
position: newPosition
|
|
2590
|
+
});
|
|
2591
|
+
});
|
|
2592
|
+
},
|
|
2593
|
+
onDragEnd: () => {
|
|
2594
|
+
this.isDragging = false;
|
|
2595
|
+
this._nodesDragEmitter.fire({
|
|
2596
|
+
type: "onDragEnd",
|
|
2597
|
+
nodes: selectedNodes,
|
|
2598
|
+
startPositions,
|
|
2599
|
+
altKey
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
});
|
|
2603
|
+
return dragger.start(event.clientX, event.clientY, this.playgroundConfig).then(() => dragSuccess);
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* 通过拖入卡片添加
|
|
2607
|
+
* @param type
|
|
2608
|
+
* @param event
|
|
2609
|
+
* @param data 节点数据
|
|
2610
|
+
*/
|
|
2611
|
+
async dropCard(type, event, data, parent) {
|
|
2612
|
+
const mousePos = this.playgroundConfig.getPosFromMouseEvent(event);
|
|
2613
|
+
if (!this.playgroundConfig.getViewport().contains(mousePos.x, mousePos.y)) {
|
|
2614
|
+
return;
|
|
2615
|
+
}
|
|
2616
|
+
const position = this.adjustSubNodePosition(type, parent, mousePos);
|
|
2617
|
+
const node = await this.document.createWorkflowNodeByType(
|
|
2618
|
+
type,
|
|
2619
|
+
position,
|
|
2620
|
+
data,
|
|
2621
|
+
parent?.id
|
|
2622
|
+
);
|
|
2623
|
+
return node;
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
* 拖拽卡片到画布
|
|
2627
|
+
* 返回创建结果
|
|
2628
|
+
* @param type
|
|
2629
|
+
* @param event
|
|
2630
|
+
*/
|
|
2631
|
+
async startDragCard(type, event, data, cloneNode) {
|
|
2632
|
+
let domNode;
|
|
2633
|
+
let startPos = { x: 0, y: 0 };
|
|
2634
|
+
const deferred = new PromiseDeferred();
|
|
2635
|
+
const dragger = new PlaygroundDrag({
|
|
2636
|
+
onDragStart: (e) => {
|
|
2637
|
+
const targetNode = event.currentTarget;
|
|
2638
|
+
domNode = cloneNode ? cloneNode(e) : targetNode.cloneNode(true);
|
|
2639
|
+
const bounds = targetNode.getBoundingClientRect();
|
|
2640
|
+
startPos = { x: bounds.left, y: bounds.top };
|
|
2641
|
+
domUtils2.setStyle(domNode, {
|
|
2642
|
+
zIndex: 1e3,
|
|
2643
|
+
position: "absolute",
|
|
2644
|
+
left: startPos.x,
|
|
2645
|
+
top: startPos.y,
|
|
2646
|
+
boxShadow: "0 6px 8px 0 rgba(28, 31, 35, .2)"
|
|
2647
|
+
});
|
|
2648
|
+
document.body.appendChild(domNode);
|
|
2649
|
+
this.updateDroppableTransforms();
|
|
2650
|
+
},
|
|
2651
|
+
onDrag: (e) => {
|
|
2652
|
+
const deltaX = e.endPos.x - e.startPos.x;
|
|
2653
|
+
const deltaY = e.endPos.y - e.startPos.y;
|
|
2654
|
+
const left = startPos.x + deltaX;
|
|
2655
|
+
const right = startPos.y + deltaY;
|
|
2656
|
+
domNode.style.left = `${left}px`;
|
|
2657
|
+
domNode.style.top = `${right}px`;
|
|
2658
|
+
const { x, y } = this.playgroundConfig.getPosFromMouseEvent(e);
|
|
2659
|
+
const draggingRect = new Rectangle9(x, y, 170, 90);
|
|
2660
|
+
const collisionTransform = this._droppableTransforms.find((transform) => {
|
|
2661
|
+
const { bounds, entity } = transform;
|
|
2662
|
+
const padding = this.document.layout.getPadding(entity);
|
|
2663
|
+
const transformRect = new Rectangle9(
|
|
2664
|
+
bounds.x + padding.left + padding.right,
|
|
2665
|
+
bounds.y,
|
|
2666
|
+
bounds.width,
|
|
2667
|
+
bounds.height
|
|
2668
|
+
);
|
|
2669
|
+
return Rectangle9.intersects(draggingRect, transformRect);
|
|
2670
|
+
});
|
|
2671
|
+
this.updateDropNode(collisionTransform?.entity);
|
|
2672
|
+
},
|
|
2673
|
+
onDragEnd: async (e) => {
|
|
2674
|
+
const dropNode = this._dropNode;
|
|
2675
|
+
const dragNode = await this.dropCard(type, e, data, dropNode);
|
|
2676
|
+
this.clearDrop();
|
|
2677
|
+
if (dragNode) {
|
|
2678
|
+
domNode.remove();
|
|
2679
|
+
deferred.resolve(dragNode);
|
|
2680
|
+
} else {
|
|
2681
|
+
domNode.style.transition = "all ease .2s";
|
|
2682
|
+
domNode.style.left = `${startPos.x}px`;
|
|
2683
|
+
domNode.style.top = `${startPos.y}px`;
|
|
2684
|
+
const TIMEOUT = 200;
|
|
2685
|
+
await delay2(TIMEOUT);
|
|
2686
|
+
domNode.remove();
|
|
2687
|
+
deferred.resolve();
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
await dragger.start(event.clientX, event.clientY);
|
|
2692
|
+
return deferred.promise;
|
|
2693
|
+
}
|
|
2694
|
+
/**
|
|
2695
|
+
* 如果存在容器节点,且传入鼠标坐标,需要用容器的坐标减去传入的鼠标坐标
|
|
2696
|
+
*/
|
|
2697
|
+
adjustSubNodePosition(subNodeType, containerNode, mousePos, resetEmptyPos = true) {
|
|
2698
|
+
if (!mousePos) {
|
|
2699
|
+
return { x: 0, y: 0 };
|
|
2700
|
+
}
|
|
2701
|
+
if (!subNodeType || !containerNode || containerNode.flowNodeType === FlowNodeBaseType2.ROOT) {
|
|
2702
|
+
return mousePos;
|
|
2703
|
+
}
|
|
2704
|
+
const isParentEmpty = !containerNode.children || containerNode.children.length === 0;
|
|
2705
|
+
const parentPadding = this.document.layout.getPadding(containerNode);
|
|
2706
|
+
const parentTransform = containerNode.getData(TransformData9);
|
|
2707
|
+
if (isParentEmpty && resetEmptyPos) {
|
|
2708
|
+
return {
|
|
2709
|
+
x: 0,
|
|
2710
|
+
y: parentPadding.top
|
|
2711
|
+
};
|
|
2712
|
+
} else {
|
|
2713
|
+
return {
|
|
2714
|
+
x: mousePos.x - parentTransform.position.x,
|
|
2715
|
+
y: mousePos.y - parentTransform.position.y
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
/**
|
|
2720
|
+
* 注册位置调整
|
|
2721
|
+
*/
|
|
2722
|
+
registerPosAdjuster(adjuster) {
|
|
2723
|
+
this.posAdjusters.add(adjuster);
|
|
2724
|
+
return {
|
|
2725
|
+
dispose: () => this.posAdjusters.delete(adjuster)
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
/**
|
|
2729
|
+
* 获取拖拽偏移
|
|
2730
|
+
*/
|
|
2731
|
+
getDragPosOffset(params) {
|
|
2732
|
+
const { event, selectedNodes, startPosition } = params;
|
|
2733
|
+
const { finalScale } = this.playgroundConfig;
|
|
2734
|
+
const mouseOffset = {
|
|
2735
|
+
x: (event.endPos.x - event.startPos.x) / finalScale,
|
|
2736
|
+
y: (event.endPos.y - event.startPos.y) / finalScale
|
|
2737
|
+
};
|
|
2738
|
+
const wholePosition = {
|
|
2739
|
+
x: startPosition.x + mouseOffset.x,
|
|
2740
|
+
y: startPosition.y + mouseOffset.y
|
|
2741
|
+
};
|
|
2742
|
+
const adjustedOffsets = Array.from(this.posAdjusters.values()).map(
|
|
2743
|
+
(adjuster) => adjuster({
|
|
2744
|
+
selectedNodes,
|
|
2745
|
+
position: wholePosition
|
|
2746
|
+
})
|
|
2747
|
+
);
|
|
2748
|
+
const offset = adjustedOffsets.reduce(
|
|
2749
|
+
(offset2, adjustOffset) => ({
|
|
2750
|
+
x: offset2.x + adjustOffset.x,
|
|
2751
|
+
y: offset2.y + adjustOffset.y
|
|
2752
|
+
}),
|
|
2753
|
+
mouseOffset
|
|
2754
|
+
);
|
|
2755
|
+
return offset;
|
|
2756
|
+
}
|
|
2757
|
+
updateDroppableTransforms() {
|
|
2758
|
+
this._droppableTransforms = this.document.getRenderDatas(FlowNodeTransformData5, false).filter((transform) => {
|
|
2759
|
+
const { entity } = transform;
|
|
2760
|
+
if (entity.originParent) {
|
|
2761
|
+
return this.nodeSelectable(entity) && this.nodeSelectable(entity.originParent);
|
|
2762
|
+
}
|
|
2763
|
+
return this.nodeSelectable(entity);
|
|
2764
|
+
}).filter((transform) => {
|
|
2765
|
+
const { entity } = transform;
|
|
2766
|
+
return entity.flowNodeType === FlowNodeBaseType2.SUB_CANVAS;
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* 获取节点整体位置
|
|
2771
|
+
*/
|
|
2772
|
+
getNodesPosition(nodes) {
|
|
2773
|
+
const selectedBounds = Rectangle9.enlarge(
|
|
2774
|
+
nodes.map((n) => n.getData(FlowNodeTransformData5).bounds)
|
|
2775
|
+
);
|
|
2776
|
+
const position = {
|
|
2777
|
+
x: selectedBounds.x,
|
|
2778
|
+
y: selectedBounds.y
|
|
2779
|
+
};
|
|
2780
|
+
return position;
|
|
2781
|
+
}
|
|
2782
|
+
nodeSelectable(node) {
|
|
2783
|
+
const selectable = node.getNodeMeta().selectable;
|
|
2784
|
+
if (typeof selectable === "function") {
|
|
2785
|
+
return selectable(node);
|
|
2786
|
+
} else {
|
|
2787
|
+
return selectable;
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
updateDropNode(node) {
|
|
2791
|
+
if (this._dropNode) {
|
|
2792
|
+
if (this._dropNode.id === node?.id) {
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
this.selectService.clear();
|
|
2796
|
+
}
|
|
2797
|
+
if (node) {
|
|
2798
|
+
this.selectService.selectNode(node);
|
|
2799
|
+
}
|
|
2800
|
+
this._dropNode = node;
|
|
2801
|
+
}
|
|
2802
|
+
clearDrop() {
|
|
2803
|
+
if (this._dropNode) {
|
|
2804
|
+
this.selectService.clear();
|
|
2805
|
+
}
|
|
2806
|
+
this._dropNode = void 0;
|
|
2807
|
+
this._droppableTransforms = [];
|
|
2808
|
+
}
|
|
2809
|
+
setLineColor(line, color) {
|
|
2810
|
+
line.highlightColor = color;
|
|
2811
|
+
this.hoverService.clearHovered();
|
|
2812
|
+
}
|
|
2813
|
+
handleDragOnNode(toNode, fromPort, line, toPort, originLine) {
|
|
2814
|
+
if (toPort && (originLine?.toPort === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
|
|
2815
|
+
this.hoverService.updateHoveredKey(toPort.id);
|
|
2816
|
+
line.setToPort(toPort);
|
|
2817
|
+
this._onDragLineEventEmitter.fire({
|
|
2818
|
+
type: "onDrag",
|
|
2819
|
+
onDragNodeId: toNode.id
|
|
2820
|
+
});
|
|
2821
|
+
return {
|
|
2822
|
+
hasError: false
|
|
2823
|
+
};
|
|
2824
|
+
} else if (toNode.flowNodeType === FlowNodeBaseType2.SUB_CANVAS) {
|
|
2825
|
+
return {
|
|
2826
|
+
hasError: false
|
|
2827
|
+
};
|
|
2828
|
+
} else {
|
|
2829
|
+
this.setLineColor(line, this.linesManager.lineColor.error);
|
|
2830
|
+
return {
|
|
2831
|
+
hasError: true
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
childrenOfContainer(nodes) {
|
|
2836
|
+
if (nodes.length === 0) {
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2839
|
+
const sourceContainer = nodes[0]?.parent;
|
|
2840
|
+
if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
const valid = nodes.every((node) => node?.parent === sourceContainer);
|
|
2844
|
+
if (!valid) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
return sourceContainer;
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* 绘制线条
|
|
2851
|
+
* @param opts
|
|
2852
|
+
* @param event
|
|
2853
|
+
*/
|
|
2854
|
+
async startDrawingLine(fromPort, event, originLine) {
|
|
2855
|
+
const isFromInActivePort = !originLine && fromPort.isErrorPort() && fromPort.disabled;
|
|
2856
|
+
if (originLine?.disabled || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
|
|
2857
|
+
return { dragSuccess: false, newLine: void 0 };
|
|
2858
|
+
}
|
|
2859
|
+
const config = this.playgroundConfig;
|
|
2860
|
+
const deferred = new PromiseDeferred();
|
|
2861
|
+
const preCursor = config.cursor;
|
|
2862
|
+
let line, toPort, toNode, lineErrorReset = false;
|
|
2863
|
+
const startTime = Date.now();
|
|
2864
|
+
let dragSuccess = false;
|
|
2865
|
+
const dragger = new PlaygroundDrag({
|
|
2866
|
+
onDrag: (e) => {
|
|
2867
|
+
if (!line && checkDragSuccess(Date.now() - startTime, e, originLine)) {
|
|
2868
|
+
if (originLine) {
|
|
2869
|
+
originLine.highlightColor = this.linesManager.lineColor.hidden;
|
|
2870
|
+
}
|
|
2871
|
+
dragSuccess = true;
|
|
2872
|
+
line = this.linesManager.createLine({
|
|
2873
|
+
from: fromPort.node.id,
|
|
2874
|
+
fromPort: fromPort.portID,
|
|
2875
|
+
drawingTo: config.getPosFromMouseEvent(event)
|
|
2876
|
+
});
|
|
2877
|
+
if (!line) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
config.updateCursor("grab");
|
|
2881
|
+
line.highlightColor = this.linesManager.lineColor.drawing;
|
|
2882
|
+
this.hoverService.updateHoveredKey("");
|
|
2883
|
+
}
|
|
2884
|
+
if (!line) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
lineErrorReset = false;
|
|
2888
|
+
const dragPos = config.getPosFromMouseEvent(e);
|
|
2889
|
+
toNode = this.linesManager.getNodeFromMousePos(dragPos);
|
|
2890
|
+
toPort = this.linesManager.getPortFromMousePos(dragPos);
|
|
2891
|
+
if (!toPort) {
|
|
2892
|
+
line.setToPort(void 0);
|
|
2893
|
+
} else if (!this.linesManager.canAddLine(fromPort, toPort, true)) {
|
|
2894
|
+
line.highlightColor = this.linesManager.lineColor.error;
|
|
2895
|
+
lineErrorReset = true;
|
|
2896
|
+
line.setToPort(void 0);
|
|
2897
|
+
} else {
|
|
2898
|
+
line.setToPort(toPort);
|
|
2899
|
+
}
|
|
2900
|
+
this._onDragLineEventEmitter.fire({
|
|
2901
|
+
type: "onDrag"
|
|
2902
|
+
});
|
|
2903
|
+
this.setLineColor(line, this.linesManager.lineColor.drawing);
|
|
2904
|
+
if (toNode && toNode.flowNodeType !== FlowNodeBaseType2.SUB_CANVAS) {
|
|
2905
|
+
const portsData = toNode.getData(WorkflowNodePortsData);
|
|
2906
|
+
toPort = portsData.inputPorts[0];
|
|
2907
|
+
const { hasError } = this.handleDragOnNode(toNode, fromPort, line, toPort, originLine);
|
|
2908
|
+
lineErrorReset = hasError;
|
|
2909
|
+
}
|
|
2910
|
+
if (line.toPort) {
|
|
2911
|
+
line.drawingTo = { x: line.toPort.point.x, y: line.toPort.point.y };
|
|
2912
|
+
} else {
|
|
2913
|
+
line.drawingTo = { x: dragPos.x, y: dragPos.y };
|
|
2914
|
+
}
|
|
2915
|
+
originLine?.validate();
|
|
2916
|
+
line.validate();
|
|
2917
|
+
},
|
|
2918
|
+
// eslint-disable-next-line complexity
|
|
2919
|
+
onDragEnd: async (e) => {
|
|
2920
|
+
const dragPos = config.getPosFromMouseEvent(e);
|
|
2921
|
+
const onDragLineEndCallbacks = Array.from(this._onDragLineEndCallbacks.values());
|
|
2922
|
+
config.updateCursor(preCursor);
|
|
2923
|
+
await Promise.all(
|
|
2924
|
+
onDragLineEndCallbacks.map(
|
|
2925
|
+
(callback) => callback({
|
|
2926
|
+
fromPort,
|
|
2927
|
+
toPort,
|
|
2928
|
+
mousePos: dragPos,
|
|
2929
|
+
line,
|
|
2930
|
+
originLine,
|
|
2931
|
+
event: e
|
|
2932
|
+
})
|
|
2933
|
+
)
|
|
2934
|
+
);
|
|
2935
|
+
line?.dispose();
|
|
2936
|
+
this._onDragLineEventEmitter.fire({
|
|
2937
|
+
type: "onDragEnd"
|
|
2938
|
+
});
|
|
2939
|
+
if (originLine) {
|
|
2940
|
+
originLine.highlightColor = "";
|
|
2941
|
+
}
|
|
2942
|
+
const end = () => {
|
|
2943
|
+
originLine?.validate();
|
|
2944
|
+
deferred.resolve({ dragSuccess });
|
|
2945
|
+
};
|
|
2946
|
+
if (dragSuccess) {
|
|
2947
|
+
if (originLine && originLine.toPort === toPort) {
|
|
2948
|
+
return end();
|
|
2949
|
+
}
|
|
2950
|
+
if (toPort && toPort.portType !== "input") {
|
|
2951
|
+
return end();
|
|
2952
|
+
}
|
|
2953
|
+
const newLineInfo = toPort ? {
|
|
2954
|
+
from: fromPort.node.id,
|
|
2955
|
+
fromPort: fromPort.portID,
|
|
2956
|
+
to: toPort.node.id,
|
|
2957
|
+
toPort: toPort.portID
|
|
2958
|
+
} : void 0;
|
|
2959
|
+
const isReset = originLine && toPort;
|
|
2960
|
+
if (isReset && !this.linesManager.canReset(
|
|
2961
|
+
originLine.fromPort,
|
|
2962
|
+
originLine.toPort,
|
|
2963
|
+
toPort
|
|
2964
|
+
)) {
|
|
2965
|
+
return end();
|
|
2966
|
+
}
|
|
2967
|
+
if (originLine && (!this.linesManager.canRemove(originLine, newLineInfo, false) || lineErrorReset)) {
|
|
2968
|
+
return end();
|
|
2969
|
+
} else {
|
|
2970
|
+
originLine?.dispose();
|
|
2971
|
+
}
|
|
2972
|
+
if (!toPort || !this.linesManager.canAddLine(fromPort, toPort, false)) {
|
|
2973
|
+
return end();
|
|
2974
|
+
}
|
|
2975
|
+
const newLine = this.linesManager.createLine(newLineInfo);
|
|
2976
|
+
if (!newLine) {
|
|
2977
|
+
end();
|
|
2978
|
+
}
|
|
2979
|
+
deferred.resolve({
|
|
2980
|
+
dragSuccess,
|
|
2981
|
+
newLine
|
|
2982
|
+
});
|
|
2983
|
+
} else {
|
|
2984
|
+
end();
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
await dragger.start(event.clientX, event.clientY, config);
|
|
2989
|
+
return deferred.promise;
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2992
|
+
* 重新连接线条
|
|
2993
|
+
* @param line
|
|
2994
|
+
* @param e
|
|
2995
|
+
*/
|
|
2996
|
+
async resetLine(line, e) {
|
|
2997
|
+
const { fromPort } = line;
|
|
2998
|
+
const { dragSuccess } = await this.startDrawingLine(fromPort, e, line);
|
|
2999
|
+
if (!dragSuccess) {
|
|
3000
|
+
this.selectService.select(line);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
/** 线条拖拽结束 */
|
|
3004
|
+
onDragLineEnd(callback) {
|
|
3005
|
+
const id = nanoid3();
|
|
3006
|
+
this._onDragLineEndCallbacks.set(id, callback);
|
|
3007
|
+
return {
|
|
3008
|
+
dispose: () => {
|
|
3009
|
+
this._onDragLineEndCallbacks.delete(id);
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
__decorateClass([
|
|
3015
|
+
inject6(PlaygroundConfigEntity5)
|
|
3016
|
+
], WorkflowDragService.prototype, "playgroundConfig", 2);
|
|
3017
|
+
__decorateClass([
|
|
3018
|
+
inject6(WorkflowHoverService)
|
|
3019
|
+
], WorkflowDragService.prototype, "hoverService", 2);
|
|
3020
|
+
__decorateClass([
|
|
3021
|
+
inject6(WorkflowDocument)
|
|
3022
|
+
], WorkflowDragService.prototype, "document", 2);
|
|
3023
|
+
__decorateClass([
|
|
3024
|
+
inject6(WorkflowLinesManager)
|
|
3025
|
+
], WorkflowDragService.prototype, "linesManager", 2);
|
|
3026
|
+
__decorateClass([
|
|
3027
|
+
inject6(CommandService)
|
|
3028
|
+
], WorkflowDragService.prototype, "commandService", 2);
|
|
3029
|
+
__decorateClass([
|
|
3030
|
+
inject6(WorkflowSelectService)
|
|
3031
|
+
], WorkflowDragService.prototype, "selectService", 2);
|
|
3032
|
+
__decorateClass([
|
|
3033
|
+
inject6(FlowOperationBaseService)
|
|
3034
|
+
], WorkflowDragService.prototype, "operationService", 2);
|
|
3035
|
+
__decorateClass([
|
|
3036
|
+
postConstruct2()
|
|
3037
|
+
], WorkflowDragService.prototype, "init", 1);
|
|
3038
|
+
WorkflowDragService = __decorateClass([
|
|
3039
|
+
injectable6()
|
|
3040
|
+
], WorkflowDragService);
|
|
3041
|
+
|
|
3042
|
+
// src/service/workflow-reset-layout-service.ts
|
|
3043
|
+
import { inject as inject7, injectable as injectable7, postConstruct as postConstruct3 } from "inversify";
|
|
3044
|
+
import { PlaygroundConfigEntity as PlaygroundConfigEntity6 } from "@flowgram.ai/core";
|
|
3045
|
+
import { EntityManager as EntityManager3 } from "@flowgram.ai/core";
|
|
3046
|
+
import { DisposableCollection as DisposableCollection3, Emitter as Emitter6 } from "@flowgram.ai/utils";
|
|
3047
|
+
|
|
3048
|
+
// src/utils/layout-to-positions.ts
|
|
3049
|
+
import { FlowNodeTransformData as FlowNodeTransformData6 } from "@flowgram.ai/document";
|
|
3050
|
+
import { TransformData as TransformData10, startTween } from "@flowgram.ai/core";
|
|
3051
|
+
var layoutToPositions = async (nodes, nodePositionMap) => {
|
|
3052
|
+
const newNodePositionMap = {};
|
|
3053
|
+
nodes.forEach((node) => {
|
|
3054
|
+
const transform = node.getData(TransformData10);
|
|
3055
|
+
const nodeTransform = node.getData(FlowNodeTransformData6);
|
|
3056
|
+
newNodePositionMap[node.id] = {
|
|
3057
|
+
x: transform.position.x,
|
|
3058
|
+
y: transform.position.y + nodeTransform.bounds.height / 2
|
|
3059
|
+
};
|
|
3060
|
+
});
|
|
3061
|
+
return new Promise((resolve) => {
|
|
3062
|
+
startTween({
|
|
3063
|
+
from: { d: 0 },
|
|
3064
|
+
to: { d: 100 },
|
|
3065
|
+
duration: 300,
|
|
3066
|
+
onUpdate: (v) => {
|
|
3067
|
+
nodes.forEach((node) => {
|
|
3068
|
+
const transform = node.getData(TransformData10);
|
|
3069
|
+
const deltaX = (nodePositionMap[node.id].x - transform.position.x) * v.d / 100;
|
|
3070
|
+
const deltaY = (nodePositionMap[node.id].y - transform.bounds.height / 2 - transform.position.y) * v.d / 100;
|
|
3071
|
+
if (node.collapsedChildren?.length > 0) {
|
|
3072
|
+
node.collapsedChildren.forEach((childNode) => {
|
|
3073
|
+
const childNodeTransformData = childNode.getData(FlowNodeTransformData6);
|
|
3074
|
+
childNodeTransformData.fireChange();
|
|
3075
|
+
});
|
|
3076
|
+
}
|
|
3077
|
+
transform.update({
|
|
3078
|
+
position: {
|
|
3079
|
+
x: transform.position.x + deltaX,
|
|
3080
|
+
y: transform.position.y + deltaY
|
|
3081
|
+
}
|
|
3082
|
+
});
|
|
3083
|
+
});
|
|
3084
|
+
},
|
|
3085
|
+
onComplete: () => {
|
|
3086
|
+
resolve(newNodePositionMap);
|
|
3087
|
+
}
|
|
3088
|
+
});
|
|
3089
|
+
});
|
|
3090
|
+
};
|
|
3091
|
+
|
|
3092
|
+
// src/service/workflow-reset-layout-service.ts
|
|
3093
|
+
var WorkflowResetLayoutService = class {
|
|
3094
|
+
constructor() {
|
|
3095
|
+
this._resetLayoutEmitter = new Emitter6();
|
|
3096
|
+
/**
|
|
3097
|
+
* reset layout事件
|
|
3098
|
+
*/
|
|
3099
|
+
this.onResetLayout = this._resetLayoutEmitter.event;
|
|
3100
|
+
this._toDispose = new DisposableCollection3();
|
|
3101
|
+
}
|
|
3102
|
+
init() {
|
|
3103
|
+
this._toDispose.push(this._resetLayoutEmitter);
|
|
3104
|
+
}
|
|
3105
|
+
/**
|
|
3106
|
+
* 触发重置布局
|
|
3107
|
+
* @param nodeIds 节点id
|
|
3108
|
+
* @param positionMap 新布局数据
|
|
3109
|
+
* @param oldPositionMap 老布局数据
|
|
3110
|
+
*/
|
|
3111
|
+
fireResetLayout(nodeIds, positionMap, oldPositionMap) {
|
|
3112
|
+
this._resetLayoutEmitter.fire({
|
|
3113
|
+
nodeIds,
|
|
3114
|
+
positionMap,
|
|
3115
|
+
oldPositionMap
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* 根据数据重新布局
|
|
3120
|
+
* @param positionMap
|
|
3121
|
+
* @returns
|
|
3122
|
+
*/
|
|
3123
|
+
async layoutToPositions(nodeIds, positionMap) {
|
|
3124
|
+
const nodes = nodeIds.map((id) => this._entityManager.getEntityById(id)).filter(Boolean);
|
|
3125
|
+
const positions = await layoutToPositions(nodes, positionMap);
|
|
3126
|
+
fitView(this._document, this._config, true);
|
|
3127
|
+
return positions;
|
|
3128
|
+
}
|
|
3129
|
+
/**
|
|
3130
|
+
* 销毁
|
|
3131
|
+
*/
|
|
3132
|
+
dispose() {
|
|
3133
|
+
this._toDispose.dispose();
|
|
3134
|
+
}
|
|
3135
|
+
};
|
|
3136
|
+
__decorateClass([
|
|
3137
|
+
inject7(PlaygroundConfigEntity6)
|
|
3138
|
+
], WorkflowResetLayoutService.prototype, "_config", 2);
|
|
3139
|
+
__decorateClass([
|
|
3140
|
+
inject7(WorkflowDocument)
|
|
3141
|
+
], WorkflowResetLayoutService.prototype, "_document", 2);
|
|
3142
|
+
__decorateClass([
|
|
3143
|
+
inject7(EntityManager3)
|
|
3144
|
+
], WorkflowResetLayoutService.prototype, "_entityManager", 2);
|
|
3145
|
+
__decorateClass([
|
|
3146
|
+
postConstruct3()
|
|
3147
|
+
], WorkflowResetLayoutService.prototype, "init", 1);
|
|
3148
|
+
WorkflowResetLayoutService = __decorateClass([
|
|
3149
|
+
injectable7()
|
|
3150
|
+
], WorkflowResetLayoutService);
|
|
3151
|
+
|
|
3152
|
+
// src/hooks/use-playground-readonly-state.ts
|
|
3153
|
+
import { useEffect } from "react";
|
|
3154
|
+
import { usePlayground, useRefresh } from "@flowgram.ai/core";
|
|
3155
|
+
function usePlaygroundReadonlyState(listenChange) {
|
|
3156
|
+
const playground = usePlayground();
|
|
3157
|
+
const refresh = useRefresh();
|
|
3158
|
+
useEffect(() => {
|
|
3159
|
+
let dispose = void 0;
|
|
3160
|
+
if (listenChange) {
|
|
3161
|
+
dispose = playground.config.onReadonlyOrDisabledChange(() => refresh());
|
|
3162
|
+
}
|
|
3163
|
+
return () => dispose?.dispose();
|
|
3164
|
+
}, [listenChange]);
|
|
3165
|
+
return playground.config.readonly;
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
// src/hooks/use-node-render.tsx
|
|
3169
|
+
function checkTargetDraggable(el) {
|
|
3170
|
+
return el && el.tagName !== "INPUT" && el.tagName !== "TEXTAREA" && !el.closest(".flow-canvas-not-draggable");
|
|
3171
|
+
}
|
|
3172
|
+
function useNodeRender(nodeFromProps) {
|
|
3173
|
+
const node = nodeFromProps || useContext(PlaygroundEntityContext);
|
|
3174
|
+
const renderData = node.getData(FlowNodeRenderData2);
|
|
3175
|
+
const portsData = node.getData(WorkflowNodePortsData);
|
|
3176
|
+
const readonly = usePlaygroundReadonlyState();
|
|
3177
|
+
const dragService = useService(WorkflowDragService);
|
|
3178
|
+
const selectionService = useService(WorkflowSelectService);
|
|
3179
|
+
const isDragging = useRef(false);
|
|
3180
|
+
const nodeRef = useRef(null);
|
|
3181
|
+
const [linkingNodeId, setLinkingNodeId] = useState("");
|
|
3182
|
+
useEffect2(() => {
|
|
3183
|
+
const disposable = dragService.onDragLineEventChange(({ type, onDragNodeId }) => {
|
|
3184
|
+
if (type === "onDrag") {
|
|
3185
|
+
setLinkingNodeId(onDragNodeId || "");
|
|
3186
|
+
} else {
|
|
3187
|
+
setLinkingNodeId("");
|
|
3188
|
+
}
|
|
3189
|
+
});
|
|
3190
|
+
return () => {
|
|
3191
|
+
disposable.dispose();
|
|
3192
|
+
};
|
|
3193
|
+
}, []);
|
|
3194
|
+
const startDrag = useCallback(
|
|
3195
|
+
(e) => {
|
|
3196
|
+
e.preventDefault();
|
|
3197
|
+
if (!selectionService.isSelected(node.id)) {
|
|
3198
|
+
selectNode(e);
|
|
3199
|
+
}
|
|
3200
|
+
if (!checkTargetDraggable(e.target) || !checkTargetDraggable(document.activeElement)) {
|
|
3201
|
+
return;
|
|
3202
|
+
}
|
|
3203
|
+
isDragging.current = true;
|
|
3204
|
+
dragService.startDragSelectedNodes(e).finally(
|
|
3205
|
+
() => setTimeout(() => {
|
|
3206
|
+
isDragging.current = false;
|
|
3207
|
+
})
|
|
3208
|
+
);
|
|
3209
|
+
},
|
|
3210
|
+
[dragService, node]
|
|
3211
|
+
);
|
|
3212
|
+
const selectNode = useCallback(
|
|
3213
|
+
(e) => {
|
|
3214
|
+
if (isDragging.current) {
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
if (e.metaKey || e.shiftKey || e.ctrlKey) {
|
|
3218
|
+
selectionService.toggleSelect(node);
|
|
3219
|
+
} else {
|
|
3220
|
+
selectionService.selectNode(node);
|
|
3221
|
+
}
|
|
3222
|
+
if (e.target) {
|
|
3223
|
+
e.target.focus();
|
|
3224
|
+
}
|
|
3225
|
+
},
|
|
3226
|
+
[node]
|
|
3227
|
+
);
|
|
3228
|
+
const deleteNode = useCallback(() => node.dispose(), [node]);
|
|
3229
|
+
useListenEvents(selectionService.onSelectionChanged, portsData.onDataChange);
|
|
3230
|
+
const isFirefox = navigator?.userAgent?.includes?.("Firefox");
|
|
3231
|
+
const onFocus = useCallback(() => {
|
|
3232
|
+
if (isFirefox) {
|
|
3233
|
+
nodeRef.current?.setAttribute("draggable", "false");
|
|
3234
|
+
}
|
|
3235
|
+
}, []);
|
|
3236
|
+
const onBlur = useCallback(() => {
|
|
3237
|
+
if (isFirefox) {
|
|
3238
|
+
nodeRef.current?.setAttribute("draggable", "true");
|
|
3239
|
+
}
|
|
3240
|
+
}, []);
|
|
3241
|
+
const getExtInfo = useCallback(() => node.getExtInfo(), [node]);
|
|
3242
|
+
const updateExtInfo = useCallback(
|
|
3243
|
+
(data) => {
|
|
3244
|
+
node.updateExtInfo(data);
|
|
3245
|
+
},
|
|
3246
|
+
[node]
|
|
3247
|
+
);
|
|
3248
|
+
const form = useMemo(() => getNodeForm(node), [node]);
|
|
3249
|
+
const formState = useObserve(form?.state || {});
|
|
3250
|
+
const toggleExpand = useCallback(() => {
|
|
3251
|
+
renderData.toggleExpand();
|
|
3252
|
+
}, [renderData]);
|
|
3253
|
+
return {
|
|
3254
|
+
node,
|
|
3255
|
+
selected: selectionService.isSelected(node.id),
|
|
3256
|
+
activated: selectionService.isActivated(node.id),
|
|
3257
|
+
expanded: renderData.expanded,
|
|
3258
|
+
startDrag,
|
|
3259
|
+
ports: portsData.allPorts,
|
|
3260
|
+
deleteNode,
|
|
3261
|
+
selectNode,
|
|
3262
|
+
readonly,
|
|
3263
|
+
linkingNodeId,
|
|
3264
|
+
nodeRef,
|
|
3265
|
+
onFocus,
|
|
3266
|
+
onBlur,
|
|
3267
|
+
getExtInfo,
|
|
3268
|
+
updateExtInfo,
|
|
3269
|
+
toggleExpand,
|
|
3270
|
+
get form() {
|
|
3271
|
+
if (!form) return void 0;
|
|
3272
|
+
return {
|
|
3273
|
+
...form,
|
|
3274
|
+
get values() {
|
|
3275
|
+
return form.values;
|
|
3276
|
+
},
|
|
3277
|
+
get state() {
|
|
3278
|
+
return formState;
|
|
3279
|
+
}
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// src/hooks/use-current-dom-node.ts
|
|
3286
|
+
import { FlowNodeRenderData as FlowNodeRenderData3 } from "@flowgram.ai/document";
|
|
3287
|
+
import { useEntityFromContext } from "@flowgram.ai/core";
|
|
3288
|
+
function useCurrentDomNode() {
|
|
3289
|
+
const entity = useEntityFromContext();
|
|
3290
|
+
const renderData = entity.getData(FlowNodeRenderData3);
|
|
3291
|
+
return renderData.node;
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
// src/hooks/use-current-entity.ts
|
|
3295
|
+
import { useEntityFromContext as useEntityFromContext2 } from "@flowgram.ai/core";
|
|
3296
|
+
function useCurrentEntity() {
|
|
3297
|
+
return useEntityFromContext2();
|
|
3298
|
+
}
|
|
3299
|
+
|
|
3300
|
+
// src/hooks/use-workflow-document.ts
|
|
3301
|
+
import { useService as useService2 } from "@flowgram.ai/core";
|
|
3302
|
+
function useWorkflowDocument() {
|
|
3303
|
+
return useService2(WorkflowDocument);
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
// src/constants.ts
|
|
3307
|
+
var EditorCursorState = /* @__PURE__ */ ((EditorCursorState2) => {
|
|
3308
|
+
EditorCursorState2["GRAB"] = "GRAB";
|
|
3309
|
+
EditorCursorState2["SELECT"] = "SELECT";
|
|
3310
|
+
return EditorCursorState2;
|
|
3311
|
+
})(EditorCursorState || {});
|
|
3312
|
+
var InteractiveType = /* @__PURE__ */ ((InteractiveType2) => {
|
|
3313
|
+
InteractiveType2["MOUSE"] = "MOUSE";
|
|
3314
|
+
InteractiveType2["PAD"] = "PAD";
|
|
3315
|
+
return InteractiveType2;
|
|
3316
|
+
})(InteractiveType || {});
|
|
3317
|
+
|
|
3318
|
+
// src/workflow-document-container-module.ts
|
|
3319
|
+
import { ContainerModule } from "inversify";
|
|
3320
|
+
import { FlowDocument as FlowDocument2, FlowDocumentContribution } from "@flowgram.ai/document";
|
|
3321
|
+
import { bindContributions } from "@flowgram.ai/utils";
|
|
3322
|
+
|
|
3323
|
+
// src/workflow-document-contribution.ts
|
|
3324
|
+
import { injectable as injectable8, inject as inject8 } from "inversify";
|
|
3325
|
+
import {
|
|
3326
|
+
FlowNodeRenderData as FlowNodeRenderData4,
|
|
3327
|
+
FlowNodeTransformData as FlowNodeTransformData7
|
|
3328
|
+
} from "@flowgram.ai/document";
|
|
3329
|
+
var WorkflowDocumentContribution = class {
|
|
3330
|
+
registerDocument(document2) {
|
|
3331
|
+
document2.registerNodeDatas(
|
|
3332
|
+
FlowNodeTransformData7,
|
|
3333
|
+
FlowNodeRenderData4,
|
|
3334
|
+
WorkflowNodePortsData,
|
|
3335
|
+
WorkflowNodeLinesData
|
|
3336
|
+
);
|
|
3337
|
+
document2.registerLayout(this.freeLayout);
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
__decorateClass([
|
|
3341
|
+
inject8(FreeLayout)
|
|
3342
|
+
], WorkflowDocumentContribution.prototype, "freeLayout", 2);
|
|
3343
|
+
WorkflowDocumentContribution = __decorateClass([
|
|
3344
|
+
injectable8()
|
|
3345
|
+
], WorkflowDocumentContribution);
|
|
3346
|
+
|
|
3347
|
+
// src/utils/get-url-params.ts
|
|
3348
|
+
function getUrlParams() {
|
|
3349
|
+
return location.search.replace(/^\?/, "").split("&").reduce((res, key) => {
|
|
3350
|
+
const [k, v] = key.split("=");
|
|
3351
|
+
res[k] = v;
|
|
3352
|
+
return res;
|
|
3353
|
+
}, {});
|
|
3354
|
+
}
|
|
3355
|
+
|
|
3356
|
+
// src/workflow-document-container-module.ts
|
|
3357
|
+
var WorkflowDocumentContainerModule = new ContainerModule(
|
|
3358
|
+
(bind, unbind, isBound, rebind) => {
|
|
3359
|
+
bind(WorkflowDocument).toSelf().inSingletonScope();
|
|
3360
|
+
bind(WorkflowLinesManager).toSelf().inSingletonScope();
|
|
3361
|
+
bind(FreeLayout).toSelf().inSingletonScope();
|
|
3362
|
+
bind(WorkflowDragService).toSelf().inSingletonScope();
|
|
3363
|
+
bind(WorkflowSelectService).toSelf().inSingletonScope();
|
|
3364
|
+
bind(WorkflowHoverService).toSelf().inSingletonScope();
|
|
3365
|
+
bind(WorkflowResetLayoutService).toSelf().inSingletonScope();
|
|
3366
|
+
bind(URLParams).toDynamicValue(() => getUrlParams()).inSingletonScope();
|
|
3367
|
+
bindContributions(bind, WorkflowDocumentContribution, [FlowDocumentContribution]);
|
|
3368
|
+
bind(WorkflowDocumentOptions).toConstantValue({
|
|
3369
|
+
...WorkflowDocumentOptionsDefault
|
|
3370
|
+
});
|
|
3371
|
+
rebind(FlowDocument2).toService(WorkflowDocument);
|
|
3372
|
+
bind(WorkflowDocumentProvider).toDynamicValue((ctx) => () => ctx.container.get(WorkflowDocument)).inSingletonScope();
|
|
3373
|
+
}
|
|
3374
|
+
);
|
|
3375
|
+
export {
|
|
3376
|
+
BezierControlType,
|
|
3377
|
+
EditorCursorState,
|
|
3378
|
+
FoldLine,
|
|
3379
|
+
InteractiveType,
|
|
3380
|
+
LINE_HOVER_DISTANCE,
|
|
3381
|
+
LineColors,
|
|
3382
|
+
LineType,
|
|
3383
|
+
POINT_RADIUS,
|
|
3384
|
+
PORT_SIZE,
|
|
3385
|
+
URLParams,
|
|
3386
|
+
WORKFLOW_LINE_ENTITY,
|
|
3387
|
+
WorkflowCommands,
|
|
3388
|
+
WorkflowContentChangeType,
|
|
3389
|
+
WorkflowDocument,
|
|
3390
|
+
WorkflowDocumentContainerModule,
|
|
3391
|
+
WorkflowDocumentOptions,
|
|
3392
|
+
WorkflowDocumentOptionsDefault,
|
|
3393
|
+
WorkflowDocumentProvider,
|
|
3394
|
+
WorkflowDragService,
|
|
3395
|
+
WorkflowHoverService,
|
|
3396
|
+
WorkflowLineEntity,
|
|
3397
|
+
WorkflowLinesManager,
|
|
3398
|
+
WorkflowNodeEntity,
|
|
3399
|
+
WorkflowNodeLinesData,
|
|
3400
|
+
WorkflowNodePortsData,
|
|
3401
|
+
WorkflowPortEntity,
|
|
3402
|
+
WorkflowResetLayoutService,
|
|
3403
|
+
WorkflowSelectService,
|
|
3404
|
+
bindConfigEntity,
|
|
3405
|
+
compose,
|
|
3406
|
+
composeAsync,
|
|
3407
|
+
delay,
|
|
3408
|
+
domReactToBounds,
|
|
3409
|
+
fitView,
|
|
3410
|
+
getAntiOverlapPosition,
|
|
3411
|
+
getBezierHorizontalControlPoints,
|
|
3412
|
+
getBezierVerticalControlPoints,
|
|
3413
|
+
getPortEntityId,
|
|
3414
|
+
nanoid,
|
|
3415
|
+
useConfigEntity,
|
|
3416
|
+
useCurrentDomNode,
|
|
3417
|
+
useCurrentEntity,
|
|
3418
|
+
useEntities,
|
|
3419
|
+
useEntityDataFromContext,
|
|
3420
|
+
useEntityFromContext3 as useEntityFromContext,
|
|
3421
|
+
useListenEvents2 as useListenEvents,
|
|
3422
|
+
useNodeRender,
|
|
3423
|
+
usePlayground2 as usePlayground,
|
|
3424
|
+
usePlaygroundContainer,
|
|
3425
|
+
usePlaygroundContext,
|
|
3426
|
+
usePlaygroundLatest,
|
|
3427
|
+
usePlaygroundReadonlyState,
|
|
3428
|
+
useRefresh2 as useRefresh,
|
|
3429
|
+
useService3 as useService,
|
|
3430
|
+
useWorkflowDocument
|
|
3431
|
+
};
|
|
3432
|
+
//# sourceMappingURL=index.js.map
|