@flowgram.ai/free-node-panel-plugin 0.1.0-alpha.10
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/index.js +614 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +238 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +644 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
30
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
31
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
32
|
+
if (decorator = decorators[i])
|
|
33
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
34
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/index.ts
|
|
39
|
+
var src_exports = {};
|
|
40
|
+
__export(src_exports, {
|
|
41
|
+
WorkflowNodePanelService: () => WorkflowNodePanelService,
|
|
42
|
+
WorkflowNodePanelUtils: () => WorkflowNodePanelUtils,
|
|
43
|
+
createFreeNodePanelPlugin: () => createFreeNodePanelPlugin
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
46
|
+
|
|
47
|
+
// src/create-plugin.ts
|
|
48
|
+
var import_core4 = require("@flowgram.ai/core");
|
|
49
|
+
|
|
50
|
+
// src/service.ts
|
|
51
|
+
var import_inversify = require("inversify");
|
|
52
|
+
var import_utils4 = require("@flowgram.ai/utils");
|
|
53
|
+
var import_free_layout_core3 = require("@flowgram.ai/free-layout-core");
|
|
54
|
+
var import_free_layout_core4 = require("@flowgram.ai/free-layout-core");
|
|
55
|
+
var import_free_history_plugin2 = require("@flowgram.ai/free-history-plugin");
|
|
56
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
57
|
+
|
|
58
|
+
// src/utils/wait-node-render.ts
|
|
59
|
+
var import_free_layout_core = require("@flowgram.ai/free-layout-core");
|
|
60
|
+
var waitNodeRender = async () => {
|
|
61
|
+
await (0, import_free_layout_core.delay)(20);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/utils/update-sub-nodes-position.ts
|
|
65
|
+
var import_free_history_plugin = require("@flowgram.ai/free-history-plugin");
|
|
66
|
+
var import_core = require("@flowgram.ai/core");
|
|
67
|
+
|
|
68
|
+
// src/utils/get-port-box.ts
|
|
69
|
+
var import_utils = require("@flowgram.ai/utils");
|
|
70
|
+
var import_document = require("@flowgram.ai/document");
|
|
71
|
+
|
|
72
|
+
// src/utils/is-container.ts
|
|
73
|
+
var isContainer = (node) => node?.getNodeMeta().isContainer ?? false;
|
|
74
|
+
|
|
75
|
+
// src/utils/get-port-box.ts
|
|
76
|
+
var getPortBox = (port, offset = { x: 0, y: 0 }) => {
|
|
77
|
+
const node = port.node;
|
|
78
|
+
if (isContainer(node)) {
|
|
79
|
+
const { point } = port;
|
|
80
|
+
if (port.portType === "input") {
|
|
81
|
+
return new import_utils.Rectangle(point.x + offset.x, point.y - 50 + offset.y, 300, 100);
|
|
82
|
+
}
|
|
83
|
+
return new import_utils.Rectangle(point.x - 300, point.y - 50, 300, 100);
|
|
84
|
+
}
|
|
85
|
+
const box = node.getData(import_document.FlowNodeTransformData).bounds;
|
|
86
|
+
return box;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/utils/update-sub-nodes-position.ts
|
|
90
|
+
var updateSubSequentNodesPosition = (params) => {
|
|
91
|
+
const {
|
|
92
|
+
node,
|
|
93
|
+
subsequentNodes,
|
|
94
|
+
fromPort,
|
|
95
|
+
toPort,
|
|
96
|
+
containerNode,
|
|
97
|
+
offset,
|
|
98
|
+
historyService,
|
|
99
|
+
dragService
|
|
100
|
+
} = params;
|
|
101
|
+
if (!offset || !toPort) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const subsequentNodesPositions = subsequentNodes.map((node2) => {
|
|
105
|
+
const nodeTrans2 = node2.getData(import_core.TransformData);
|
|
106
|
+
return {
|
|
107
|
+
x: nodeTrans2.position.x,
|
|
108
|
+
y: nodeTrans2.position.y
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
historyService.pushOperation({
|
|
112
|
+
type: import_free_history_plugin.FreeOperationType.dragNodes,
|
|
113
|
+
value: {
|
|
114
|
+
ids: subsequentNodes.map((node2) => node2.id),
|
|
115
|
+
value: subsequentNodesPositions.map((position) => ({
|
|
116
|
+
x: position.x + offset.x,
|
|
117
|
+
y: position.y + offset.y
|
|
118
|
+
})),
|
|
119
|
+
oldValue: subsequentNodesPositions
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const fromBox = getPortBox(fromPort);
|
|
123
|
+
const toBox = getPortBox(toPort, offset);
|
|
124
|
+
const nodeTrans = node.getData(import_core.TransformData);
|
|
125
|
+
let nodePos = {
|
|
126
|
+
x: (fromBox.center.x + toBox.center.x) / 2,
|
|
127
|
+
y: (fromBox.y + toBox.y) / 2
|
|
128
|
+
};
|
|
129
|
+
if (containerNode) {
|
|
130
|
+
nodePos = dragService.adjustSubNodePosition(
|
|
131
|
+
node.flowNodeType,
|
|
132
|
+
containerNode,
|
|
133
|
+
nodePos
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
historyService.pushOperation({
|
|
137
|
+
type: import_free_history_plugin.FreeOperationType.dragNodes,
|
|
138
|
+
value: {
|
|
139
|
+
ids: [node.id],
|
|
140
|
+
value: [nodePos],
|
|
141
|
+
oldValue: [
|
|
142
|
+
{
|
|
143
|
+
x: nodeTrans.position.x,
|
|
144
|
+
y: nodeTrans.position.y
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/utils/sub-position-offset.ts
|
|
152
|
+
var import_utils3 = require("@flowgram.ai/utils");
|
|
153
|
+
var import_document2 = require("@flowgram.ai/document");
|
|
154
|
+
|
|
155
|
+
// src/utils/rect-distance.ts
|
|
156
|
+
var import_utils2 = require("@flowgram.ai/utils");
|
|
157
|
+
var rectDistance = (rectA, rectB) => {
|
|
158
|
+
const distanceX = Math.abs(Math.min(rectA.right, rectB.right) - Math.max(rectA.left, rectB.left));
|
|
159
|
+
const distanceY = Math.abs(Math.min(rectA.bottom, rectB.bottom) - Math.max(rectA.top, rectB.top));
|
|
160
|
+
if (import_utils2.Rectangle.intersects(rectA, rectB)) {
|
|
161
|
+
return {
|
|
162
|
+
x: -distanceX,
|
|
163
|
+
y: -distanceY
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
x: distanceX,
|
|
168
|
+
y: distanceY
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/utils/greater-or-less.ts
|
|
173
|
+
var isGreaterThan = (a, b) => {
|
|
174
|
+
if (a === void 0 || b === void 0) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const EPSILON = 1e-5;
|
|
178
|
+
return a - b > EPSILON;
|
|
179
|
+
};
|
|
180
|
+
var isLessThan = (a, b) => {
|
|
181
|
+
if (a === void 0 || b === void 0) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const EPSILON = 1e-5;
|
|
185
|
+
return b - a > EPSILON;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/utils/sub-position-offset.ts
|
|
189
|
+
var subPositionOffset = (params) => {
|
|
190
|
+
const { node, fromPort, toPort, padding } = params;
|
|
191
|
+
const fromBox = getPortBox(fromPort);
|
|
192
|
+
const toBox = getPortBox(toPort);
|
|
193
|
+
const nodeTrans = node.getData(import_document2.FlowNodeTransformData);
|
|
194
|
+
const nodeSize = node.getNodeMeta()?.size ?? {
|
|
195
|
+
width: nodeTrans.bounds.width,
|
|
196
|
+
height: nodeTrans.bounds.height
|
|
197
|
+
};
|
|
198
|
+
const minDistance = {
|
|
199
|
+
x: nodeSize.width + padding.x,
|
|
200
|
+
y: nodeSize.height + padding.y
|
|
201
|
+
};
|
|
202
|
+
const boxDistance = rectDistance(fromBox, toBox);
|
|
203
|
+
const neededOffset = {
|
|
204
|
+
x: isGreaterThan(boxDistance.x, minDistance.x) ? 0 : minDistance.x - boxDistance.x,
|
|
205
|
+
y: isGreaterThan(boxDistance.y, minDistance.y) ? 0 : minDistance.y - boxDistance.y
|
|
206
|
+
};
|
|
207
|
+
if (neededOffset.x === 0 || neededOffset.y === 0) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const intersection = {
|
|
211
|
+
// 这里没有写反,Rectangle内置的算法是反的
|
|
212
|
+
vertical: import_utils3.Rectangle.intersects(fromBox, toBox, "horizontal"),
|
|
213
|
+
horizontal: import_utils3.Rectangle.intersects(fromBox, toBox, "vertical")
|
|
214
|
+
};
|
|
215
|
+
let offsetX = 0;
|
|
216
|
+
let offsetY = 0;
|
|
217
|
+
if (!intersection.horizontal) {
|
|
218
|
+
if (isGreaterThan(toBox.center.y, fromBox.center.y)) {
|
|
219
|
+
offsetY = neededOffset.y;
|
|
220
|
+
} else if (isLessThan(toBox.center.y, fromBox.center.y)) {
|
|
221
|
+
offsetY = -neededOffset.y;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!intersection.vertical) {
|
|
225
|
+
if (isGreaterThan(toBox.center.x, fromBox.center.x)) {
|
|
226
|
+
offsetX = neededOffset.x;
|
|
227
|
+
} else if (isLessThan(toBox.center.x, fromBox.center.x)) {
|
|
228
|
+
offsetX = -neededOffset.x;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
x: offsetX,
|
|
233
|
+
y: offsetY
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/utils/get-sub-nodes.ts
|
|
238
|
+
var getSubsequentNodes = (params) => {
|
|
239
|
+
const { node, linesManager } = params;
|
|
240
|
+
if (isContainer(node)) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
const brothers = node.parent?.blocks ?? [];
|
|
244
|
+
const linkedBrothers = /* @__PURE__ */ new Set();
|
|
245
|
+
const linesMap = /* @__PURE__ */ new Map();
|
|
246
|
+
linesManager.getAllLines().forEach((line) => {
|
|
247
|
+
if (!linesMap.has(line.from.id)) {
|
|
248
|
+
linesMap.set(line.from.id, []);
|
|
249
|
+
}
|
|
250
|
+
if (!line.to?.id || isContainer(line.to)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
linesMap.get(line.from.id)?.push(line.to.id);
|
|
254
|
+
});
|
|
255
|
+
const bfs = (nodeId) => {
|
|
256
|
+
if (linkedBrothers.has(nodeId)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
linkedBrothers.add(nodeId);
|
|
260
|
+
const nextNodes = linesMap.get(nodeId) ?? [];
|
|
261
|
+
nextNodes.forEach(bfs);
|
|
262
|
+
};
|
|
263
|
+
bfs(node.id);
|
|
264
|
+
const subsequentNodes = brothers.filter((node2) => linkedBrothers.has(node2.id));
|
|
265
|
+
return subsequentNodes;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// src/utils/sub-nodes-auto-offset.ts
|
|
269
|
+
var subNodesAutoOffset = (params) => {
|
|
270
|
+
const {
|
|
271
|
+
node,
|
|
272
|
+
fromPort,
|
|
273
|
+
toPort,
|
|
274
|
+
linesManager,
|
|
275
|
+
historyService,
|
|
276
|
+
dragService,
|
|
277
|
+
containerNode,
|
|
278
|
+
padding = {
|
|
279
|
+
x: 100,
|
|
280
|
+
y: 100
|
|
281
|
+
}
|
|
282
|
+
} = params;
|
|
283
|
+
const subOffset = subPositionOffset({
|
|
284
|
+
node,
|
|
285
|
+
fromPort,
|
|
286
|
+
toPort,
|
|
287
|
+
padding
|
|
288
|
+
});
|
|
289
|
+
const subsequentNodes = getSubsequentNodes({
|
|
290
|
+
node: toPort.node,
|
|
291
|
+
linesManager
|
|
292
|
+
});
|
|
293
|
+
updateSubSequentNodesPosition({
|
|
294
|
+
node,
|
|
295
|
+
subsequentNodes,
|
|
296
|
+
fromPort,
|
|
297
|
+
toPort,
|
|
298
|
+
containerNode,
|
|
299
|
+
offset: subOffset,
|
|
300
|
+
historyService,
|
|
301
|
+
dragService
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/utils/get-container-node.ts
|
|
306
|
+
var getContainerNode = (params) => {
|
|
307
|
+
const { fromPort, containerNode } = params;
|
|
308
|
+
if (containerNode) {
|
|
309
|
+
return containerNode;
|
|
310
|
+
}
|
|
311
|
+
const fromNode = fromPort?.node;
|
|
312
|
+
const fromContainer = fromNode?.parent;
|
|
313
|
+
if (isContainer(fromNode)) {
|
|
314
|
+
return fromNode;
|
|
315
|
+
}
|
|
316
|
+
return fromContainer;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// src/utils/build-line.ts
|
|
320
|
+
var import_free_layout_core2 = require("@flowgram.ai/free-layout-core");
|
|
321
|
+
var buildLine = (params) => {
|
|
322
|
+
const { fromPort, node, toPort, linesManager } = params;
|
|
323
|
+
const portsData = node.getData(import_free_layout_core2.WorkflowNodePortsData);
|
|
324
|
+
if (!portsData) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const shouldBuildFromLine = portsData.inputPorts?.length > 0;
|
|
328
|
+
if (fromPort && shouldBuildFromLine) {
|
|
329
|
+
const toTargetPort = portsData.inputPorts[0];
|
|
330
|
+
linesManager.createLine({
|
|
331
|
+
from: fromPort.node.id,
|
|
332
|
+
fromPort: fromPort.portID,
|
|
333
|
+
to: node.id,
|
|
334
|
+
toPort: toTargetPort.portID
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const shouldBuildToLine = portsData.outputPorts?.length > 0;
|
|
338
|
+
if (toPort && shouldBuildToLine) {
|
|
339
|
+
const fromTargetPort = portsData.outputPorts[0];
|
|
340
|
+
linesManager.createLine({
|
|
341
|
+
from: node.id,
|
|
342
|
+
fromPort: fromTargetPort.portID,
|
|
343
|
+
to: toPort.node.id,
|
|
344
|
+
toPort: toPort.portID
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/utils/adjust-node-position.ts
|
|
350
|
+
var adjustNodePosition = (params) => {
|
|
351
|
+
const { nodeType, position, fromPort, toPort, containerNode, document, dragService } = params;
|
|
352
|
+
const register = document.getNodeRegistry(nodeType);
|
|
353
|
+
const size = register?.meta?.size;
|
|
354
|
+
let adjustedPosition = position;
|
|
355
|
+
if (!size) {
|
|
356
|
+
adjustedPosition = position;
|
|
357
|
+
} else if (fromPort && toPort) {
|
|
358
|
+
adjustedPosition = {
|
|
359
|
+
x: position.x,
|
|
360
|
+
y: position.y - size.height / 2
|
|
361
|
+
};
|
|
362
|
+
} else if (fromPort && !toPort) {
|
|
363
|
+
adjustedPosition = {
|
|
364
|
+
x: position.x + size.width / 2,
|
|
365
|
+
y: position.y - size.height / 2
|
|
366
|
+
};
|
|
367
|
+
} else if (!fromPort && toPort) {
|
|
368
|
+
adjustedPosition = {
|
|
369
|
+
x: position.x - size.width / 2,
|
|
370
|
+
y: position.y - size.height / 2
|
|
371
|
+
};
|
|
372
|
+
} else {
|
|
373
|
+
adjustedPosition = position;
|
|
374
|
+
}
|
|
375
|
+
return dragService.adjustSubNodePosition(nodeType, containerNode, adjustedPosition);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/utils/index.ts
|
|
379
|
+
var WorkflowNodePanelUtils = {
|
|
380
|
+
adjustNodePosition,
|
|
381
|
+
buildLine,
|
|
382
|
+
getPortBox,
|
|
383
|
+
getSubsequentNodes,
|
|
384
|
+
getContainerNode,
|
|
385
|
+
rectDistance,
|
|
386
|
+
subNodesAutoOffset,
|
|
387
|
+
subPositionOffset,
|
|
388
|
+
updateSubSequentNodesPosition,
|
|
389
|
+
waitNodeRender
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/service.ts
|
|
393
|
+
var WorkflowNodePanelService = class {
|
|
394
|
+
constructor() {
|
|
395
|
+
this.toDispose = new import_utils4.DisposableCollection();
|
|
396
|
+
this.callNodePanel = async () => void 0;
|
|
397
|
+
}
|
|
398
|
+
/** 销毁 */
|
|
399
|
+
dispose() {
|
|
400
|
+
this.toDispose.dispose();
|
|
401
|
+
}
|
|
402
|
+
setCallNodePanel(callNodePanel) {
|
|
403
|
+
this.callNodePanel = callNodePanel;
|
|
404
|
+
}
|
|
405
|
+
/** 唤起节点面板 */
|
|
406
|
+
async call(callParams) {
|
|
407
|
+
const {
|
|
408
|
+
panelPosition,
|
|
409
|
+
fromPort,
|
|
410
|
+
enableMultiAdd = false,
|
|
411
|
+
panelProps = {},
|
|
412
|
+
containerNode,
|
|
413
|
+
afterAddNode
|
|
414
|
+
} = callParams;
|
|
415
|
+
if (!panelPosition || this.playgroundConfig.readonly) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const nodes = [];
|
|
419
|
+
return new Promise((resolve) => {
|
|
420
|
+
this.callNodePanel({
|
|
421
|
+
position: panelPosition,
|
|
422
|
+
enableMultiAdd,
|
|
423
|
+
panelProps,
|
|
424
|
+
containerNode: WorkflowNodePanelUtils.getContainerNode({
|
|
425
|
+
fromPort,
|
|
426
|
+
containerNode
|
|
427
|
+
}),
|
|
428
|
+
onSelect: async (panelParams) => {
|
|
429
|
+
const node = await this.addNode(callParams, panelParams);
|
|
430
|
+
afterAddNode?.(node);
|
|
431
|
+
if (!enableMultiAdd) {
|
|
432
|
+
resolve(node);
|
|
433
|
+
} else if (node) {
|
|
434
|
+
nodes.push(node);
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
onClose: () => {
|
|
438
|
+
resolve(enableMultiAdd ? nodes : void 0);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* 唤起单选面板
|
|
445
|
+
*/
|
|
446
|
+
async singleSelectNodePanel(params) {
|
|
447
|
+
return new Promise((resolve) => {
|
|
448
|
+
this.callNodePanel({
|
|
449
|
+
...params,
|
|
450
|
+
enableMultiAdd: false,
|
|
451
|
+
onSelect: async (panelParams) => {
|
|
452
|
+
resolve(panelParams);
|
|
453
|
+
},
|
|
454
|
+
onClose: () => {
|
|
455
|
+
resolve(void 0);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/** 添加节点 */
|
|
461
|
+
async addNode(callParams, panelParams) {
|
|
462
|
+
const {
|
|
463
|
+
panelPosition,
|
|
464
|
+
fromPort,
|
|
465
|
+
toPort,
|
|
466
|
+
canAddNode,
|
|
467
|
+
autoOffsetPadding = {
|
|
468
|
+
x: 100,
|
|
469
|
+
y: 100
|
|
470
|
+
},
|
|
471
|
+
enableBuildLine = false,
|
|
472
|
+
enableSelectPosition = false,
|
|
473
|
+
enableAutoOffset = false,
|
|
474
|
+
enableDragNode = false
|
|
475
|
+
} = callParams;
|
|
476
|
+
if (!panelPosition || !panelParams) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const { nodeType, selectEvent, nodeJSON } = panelParams;
|
|
480
|
+
const containerNode = WorkflowNodePanelUtils.getContainerNode({
|
|
481
|
+
fromPort,
|
|
482
|
+
containerNode: callParams.containerNode
|
|
483
|
+
});
|
|
484
|
+
if (canAddNode) {
|
|
485
|
+
const canAdd = canAddNode({ nodeType, containerNode });
|
|
486
|
+
if (!canAdd) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const selectPosition = this.playgroundConfig.getPosFromMouseEvent(selectEvent);
|
|
491
|
+
const nodePosition = callParams.customPosition ? callParams.customPosition({ nodeType, selectPosition }) : WorkflowNodePanelUtils.adjustNodePosition({
|
|
492
|
+
nodeType,
|
|
493
|
+
position: enableSelectPosition ? selectPosition : panelPosition,
|
|
494
|
+
fromPort,
|
|
495
|
+
toPort,
|
|
496
|
+
containerNode,
|
|
497
|
+
document: this.document,
|
|
498
|
+
dragService: this.dragService
|
|
499
|
+
});
|
|
500
|
+
const node = this.document.createWorkflowNodeByType(
|
|
501
|
+
nodeType,
|
|
502
|
+
nodePosition,
|
|
503
|
+
nodeJSON ?? {},
|
|
504
|
+
containerNode?.id
|
|
505
|
+
);
|
|
506
|
+
if (!node) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (enableAutoOffset && fromPort && toPort) {
|
|
510
|
+
WorkflowNodePanelUtils.subNodesAutoOffset({
|
|
511
|
+
node,
|
|
512
|
+
fromPort,
|
|
513
|
+
toPort,
|
|
514
|
+
padding: autoOffsetPadding,
|
|
515
|
+
containerNode,
|
|
516
|
+
historyService: this.historyService,
|
|
517
|
+
dragService: this.dragService,
|
|
518
|
+
linesManager: this.linesManager
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (!enableBuildLine && !enableDragNode) {
|
|
522
|
+
return node;
|
|
523
|
+
}
|
|
524
|
+
await WorkflowNodePanelUtils.waitNodeRender();
|
|
525
|
+
if (enableBuildLine) {
|
|
526
|
+
WorkflowNodePanelUtils.buildLine({
|
|
527
|
+
fromPort,
|
|
528
|
+
node,
|
|
529
|
+
toPort,
|
|
530
|
+
linesManager: this.linesManager
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (enableDragNode) {
|
|
534
|
+
this.selectService.selectNode(node);
|
|
535
|
+
this.dragService.startDragSelectedNodes(selectEvent);
|
|
536
|
+
}
|
|
537
|
+
return node;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
__decorateClass([
|
|
541
|
+
(0, import_inversify.inject)(import_free_layout_core3.WorkflowDocument)
|
|
542
|
+
], WorkflowNodePanelService.prototype, "document", 2);
|
|
543
|
+
__decorateClass([
|
|
544
|
+
(0, import_inversify.inject)(import_free_layout_core3.WorkflowDragService)
|
|
545
|
+
], WorkflowNodePanelService.prototype, "dragService", 2);
|
|
546
|
+
__decorateClass([
|
|
547
|
+
(0, import_inversify.inject)(import_free_layout_core4.WorkflowSelectService)
|
|
548
|
+
], WorkflowNodePanelService.prototype, "selectService", 2);
|
|
549
|
+
__decorateClass([
|
|
550
|
+
(0, import_inversify.inject)(import_free_layout_core3.WorkflowLinesManager)
|
|
551
|
+
], WorkflowNodePanelService.prototype, "linesManager", 2);
|
|
552
|
+
__decorateClass([
|
|
553
|
+
(0, import_inversify.inject)(import_core2.PlaygroundConfigEntity)
|
|
554
|
+
], WorkflowNodePanelService.prototype, "playgroundConfig", 2);
|
|
555
|
+
__decorateClass([
|
|
556
|
+
(0, import_inversify.inject)(import_free_history_plugin2.HistoryService)
|
|
557
|
+
], WorkflowNodePanelService.prototype, "historyService", 2);
|
|
558
|
+
WorkflowNodePanelService = __decorateClass([
|
|
559
|
+
(0, import_inversify.injectable)()
|
|
560
|
+
], WorkflowNodePanelService);
|
|
561
|
+
|
|
562
|
+
// src/layer.tsx
|
|
563
|
+
var import_react = __toESM(require("react"));
|
|
564
|
+
var import_inversify2 = require("inversify");
|
|
565
|
+
var import_utils6 = require("@flowgram.ai/utils");
|
|
566
|
+
var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
|
|
567
|
+
var import_core3 = require("@flowgram.ai/core");
|
|
568
|
+
var WorkflowNodePanelLayer = class extends import_core3.Layer {
|
|
569
|
+
constructor() {
|
|
570
|
+
super();
|
|
571
|
+
this.node = import_utils6.domUtils.createDivWithClass("gedit-playground-layer gedit-node-panel-layer");
|
|
572
|
+
this.node.style.zIndex = "9999";
|
|
573
|
+
this.renderList = /* @__PURE__ */ new Map();
|
|
574
|
+
}
|
|
575
|
+
onReady() {
|
|
576
|
+
this.service.setCallNodePanel(this.call.bind(this));
|
|
577
|
+
}
|
|
578
|
+
onZoom(zoom) {
|
|
579
|
+
this.node.style.transform = `scale(${zoom})`;
|
|
580
|
+
}
|
|
581
|
+
render() {
|
|
582
|
+
const NodePanelRender = this.options.renderer;
|
|
583
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, Array.from(this.renderList.keys()).map((taskId) => {
|
|
584
|
+
const renderProps = this.renderList.get(taskId);
|
|
585
|
+
return /* @__PURE__ */ import_react.default.createElement(NodePanelRender, { key: taskId, ...renderProps });
|
|
586
|
+
}));
|
|
587
|
+
}
|
|
588
|
+
async call(params) {
|
|
589
|
+
const taskId = (0, import_free_layout_core5.nanoid)();
|
|
590
|
+
const { onSelect, onClose, enableMultiAdd = false, panelProps = {} } = params;
|
|
591
|
+
return new Promise((resolve) => {
|
|
592
|
+
const unmount = () => {
|
|
593
|
+
this.renderList.delete(taskId);
|
|
594
|
+
this.render();
|
|
595
|
+
resolve();
|
|
596
|
+
};
|
|
597
|
+
const handleClose = () => {
|
|
598
|
+
unmount();
|
|
599
|
+
onClose();
|
|
600
|
+
};
|
|
601
|
+
const handleSelect = (params2) => {
|
|
602
|
+
onSelect(params2);
|
|
603
|
+
if (!enableMultiAdd) {
|
|
604
|
+
unmount();
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
const renderProps = {
|
|
608
|
+
...params,
|
|
609
|
+
panelProps,
|
|
610
|
+
onSelect: handleSelect,
|
|
611
|
+
onClose: handleClose
|
|
612
|
+
};
|
|
613
|
+
this.renderList.set(taskId, renderProps);
|
|
614
|
+
this.render();
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
WorkflowNodePanelLayer.type = "WorkflowNodePanelLayer";
|
|
619
|
+
__decorateClass([
|
|
620
|
+
(0, import_inversify2.inject)(WorkflowNodePanelService)
|
|
621
|
+
], WorkflowNodePanelLayer.prototype, "service", 2);
|
|
622
|
+
|
|
623
|
+
// src/create-plugin.ts
|
|
624
|
+
var createFreeNodePanelPlugin = (0, import_core4.definePluginCreator)({
|
|
625
|
+
onBind({ bind }) {
|
|
626
|
+
bind(WorkflowNodePanelService).toSelf().inSingletonScope();
|
|
627
|
+
},
|
|
628
|
+
onInit: (ctx, opts) => {
|
|
629
|
+
ctx.playground.registerLayer(WorkflowNodePanelLayer, {
|
|
630
|
+
renderer: opts.renderer
|
|
631
|
+
});
|
|
632
|
+
},
|
|
633
|
+
onDispose: (ctx) => {
|
|
634
|
+
const nodePanelService = ctx.get(WorkflowNodePanelService);
|
|
635
|
+
nodePanelService.dispose();
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
639
|
+
0 && (module.exports = {
|
|
640
|
+
WorkflowNodePanelService,
|
|
641
|
+
WorkflowNodePanelUtils,
|
|
642
|
+
createFreeNodePanelPlugin
|
|
643
|
+
});
|
|
644
|
+
//# sourceMappingURL=index.js.map
|