@flowgram.ai/free-layout-core 0.1.0-alpha.8 → 0.1.0-alpha.9
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-6DKK25L7.js +21 -0
- package/dist/esm/chunk-6DKK25L7.js.map +1 -0
- package/dist/esm/index.js +142 -119
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/typings/index.js +1 -1
- package/dist/esm/typings/workflow-line.js +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +142 -122
- package/dist/index.js.map +1 -1
- package/dist/typings/index.d.mts +1 -1
- package/dist/typings/index.d.ts +1 -1
- package/dist/typings/index.js +6 -5
- package/dist/typings/index.js.map +1 -1
- package/dist/typings/workflow-drag.d.mts +1 -1
- package/dist/typings/workflow-drag.d.ts +1 -1
- package/dist/typings/workflow-json.d.mts +1 -1
- package/dist/typings/workflow-json.d.ts +1 -1
- package/dist/typings/workflow-line.d.mts +1 -1
- package/dist/typings/workflow-line.d.ts +1 -1
- package/dist/typings/workflow-line.js +6 -5
- package/dist/typings/workflow-line.js.map +1 -1
- package/dist/typings/workflow-node.d.mts +1 -1
- package/dist/typings/workflow-node.d.ts +1 -1
- package/dist/typings/workflow-registry.d.mts +1 -1
- package/dist/typings/workflow-registry.d.ts +1 -1
- package/dist/{workflow-line-entity-DSMjQU0t.d.mts → workflow-line-entity-BcD7CpoN.d.mts} +13 -6
- package/dist/{workflow-line-entity-VNz8dyPS.d.ts → workflow-line-entity-CXh_ddVD.d.ts} +13 -6
- package/package.json +9 -9
- package/dist/esm/chunk-PT4ZVDZZ.js +0 -20
- package/dist/esm/chunk-PT4ZVDZZ.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
LineColors,
|
|
13
13
|
LineType
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6DKK25L7.js";
|
|
15
15
|
import "./chunk-DDJTYHXN.js";
|
|
16
16
|
import {
|
|
17
17
|
WorkflowOperationBaseService
|
|
@@ -145,7 +145,6 @@ var PORT_SIZE = 24;
|
|
|
145
145
|
var WorkflowPortEntity = class extends Entity {
|
|
146
146
|
// relativePosition
|
|
147
147
|
constructor(opts) {
|
|
148
|
-
var _a;
|
|
149
148
|
super(opts);
|
|
150
149
|
this.portID = "";
|
|
151
150
|
this._disabled = false;
|
|
@@ -154,7 +153,7 @@ var WorkflowPortEntity = class extends Entity {
|
|
|
154
153
|
this.onErrorChanged = this._onErrorChangedEmitter.event;
|
|
155
154
|
this.portID = opts.portID || "";
|
|
156
155
|
this.portType = opts.type;
|
|
157
|
-
this._disabled =
|
|
156
|
+
this._disabled = opts.disabled ?? false;
|
|
158
157
|
this.node = opts.node;
|
|
159
158
|
this.updateTargetElement(opts.targetElement);
|
|
160
159
|
this.toDispose.push(this.node.getData(TransformData3).onDataChange(() => this.fireChange()));
|
|
@@ -284,7 +283,6 @@ WorkflowPortEntity.type = "WorkflowPortEntity";
|
|
|
284
283
|
// src/entity-datas/workflow-node-ports-data.ts
|
|
285
284
|
var WorkflowNodePortsData = class extends EntityData {
|
|
286
285
|
constructor(entity) {
|
|
287
|
-
var _a;
|
|
288
286
|
super(entity);
|
|
289
287
|
/** 静态的 ports 数据 */
|
|
290
288
|
this._staticPorts = [];
|
|
@@ -293,7 +291,7 @@ var WorkflowNodePortsData = class extends EntityData {
|
|
|
293
291
|
this.entity = entity;
|
|
294
292
|
const meta = entity.getNodeMeta();
|
|
295
293
|
const defaultPorts = meta.useDynamicPort ? [] : [{ type: "input" }, { type: "output" }];
|
|
296
|
-
this._staticPorts =
|
|
294
|
+
this._staticPorts = meta.defaultPorts?.slice() || defaultPorts;
|
|
297
295
|
this.updatePorts(this._staticPorts);
|
|
298
296
|
if (meta.useDynamicPort) {
|
|
299
297
|
this.toDispose.push(
|
|
@@ -360,9 +358,8 @@ var WorkflowNodePortsData = class extends EntityData {
|
|
|
360
358
|
if (!isEqual(this._prePorts, ports)) {
|
|
361
359
|
const portKeys = ports.map((port) => this.getPortId(port.type, port.portID));
|
|
362
360
|
this._portIDSet.forEach((portId) => {
|
|
363
|
-
var _a;
|
|
364
361
|
if (!portKeys.includes(portId)) {
|
|
365
|
-
|
|
362
|
+
this.getPortEntity(portId)?.dispose();
|
|
366
363
|
}
|
|
367
364
|
});
|
|
368
365
|
ports.forEach((port) => this.updatePortEntity(port));
|
|
@@ -456,9 +453,8 @@ var WorkflowNodePortsData = class extends EntityData {
|
|
|
456
453
|
* 获取或创建 port 实体
|
|
457
454
|
*/
|
|
458
455
|
getOrCreatePortEntity(portInfo) {
|
|
459
|
-
var _a;
|
|
460
456
|
const id = this.getPortId(portInfo.type, portInfo.portID);
|
|
461
|
-
return
|
|
457
|
+
return this.getPortEntity(id) ?? this.createPortEntity(portInfo);
|
|
462
458
|
}
|
|
463
459
|
/**
|
|
464
460
|
* 更新 port 实体
|
|
@@ -526,7 +522,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
|
|
|
526
522
|
return;
|
|
527
523
|
}
|
|
528
524
|
inputNodes.forEach((inputNode) => {
|
|
529
|
-
if (
|
|
525
|
+
if (inputNode?.parent === node || node?.parent === inputNode) {
|
|
530
526
|
return;
|
|
531
527
|
}
|
|
532
528
|
handleNode(inputNode);
|
|
@@ -557,7 +553,7 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
|
|
|
557
553
|
return;
|
|
558
554
|
}
|
|
559
555
|
outputNodes.forEach((outputNode) => {
|
|
560
|
-
if (
|
|
556
|
+
if (outputNode?.parent === node || node?.parent === outputNode) {
|
|
561
557
|
return;
|
|
562
558
|
}
|
|
563
559
|
handleNode(outputNode);
|
|
@@ -617,23 +613,19 @@ var WorkflowLineRenderData = class extends EntityData3 {
|
|
|
617
613
|
return this.data.position;
|
|
618
614
|
}
|
|
619
615
|
get path() {
|
|
620
|
-
|
|
621
|
-
return (_b = (_a = this.currentLine) == null ? void 0 : _a.path) != null ? _b : "";
|
|
616
|
+
return this.currentLine?.path ?? "";
|
|
622
617
|
}
|
|
623
618
|
calcDistance(pos) {
|
|
624
|
-
|
|
625
|
-
return (_b = (_a = this.currentLine) == null ? void 0 : _a.calcDistance(pos)) != null ? _b : Number.MAX_SAFE_INTEGER;
|
|
619
|
+
return this.currentLine?.calcDistance(pos) ?? Number.MAX_SAFE_INTEGER;
|
|
626
620
|
}
|
|
627
621
|
get bounds() {
|
|
628
|
-
|
|
629
|
-
return (_b = (_a = this.currentLine) == null ? void 0 : _a.bounds) != null ? _b : new Rectangle4();
|
|
622
|
+
return this.currentLine?.bounds ?? new Rectangle4();
|
|
630
623
|
}
|
|
631
624
|
/**
|
|
632
625
|
* 更新数据
|
|
633
626
|
* WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
|
|
634
627
|
*/
|
|
635
628
|
update() {
|
|
636
|
-
var _a;
|
|
637
629
|
this.syncContributions();
|
|
638
630
|
const oldVersion = this.data.version;
|
|
639
631
|
this.updatePosition();
|
|
@@ -642,23 +634,21 @@ var WorkflowLineRenderData = class extends EntityData3 {
|
|
|
642
634
|
return;
|
|
643
635
|
}
|
|
644
636
|
this.data.version = newVersion;
|
|
645
|
-
|
|
637
|
+
this.currentLine?.update({
|
|
646
638
|
fromPos: this.data.position.from,
|
|
647
639
|
toPos: this.data.position.to
|
|
648
640
|
});
|
|
649
641
|
}
|
|
650
642
|
get lineType() {
|
|
651
|
-
|
|
652
|
-
return (_a = this.entity.renderType) != null ? _a : this.entity.linesManager.lineType;
|
|
643
|
+
return this.entity.renderType ?? this.entity.linesManager.lineType;
|
|
653
644
|
}
|
|
654
645
|
/**
|
|
655
646
|
* 更新版本
|
|
656
647
|
* WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
|
|
657
648
|
*/
|
|
658
649
|
updatePosition() {
|
|
659
|
-
var _a, _b, _c, _d;
|
|
660
650
|
this.data.position.from = this.entity.from.getData(WorkflowNodePortsData).getOutputPoint(this.entity.info.fromPort);
|
|
661
|
-
this.data.position.to =
|
|
651
|
+
this.data.position.to = this.entity.info.drawingTo ?? this.entity.to?.getData(WorkflowNodePortsData)?.getInputPoint(this.entity.info.toPort) ?? {
|
|
662
652
|
x: this.data.position.from.x,
|
|
663
653
|
y: this.data.position.from.y
|
|
664
654
|
};
|
|
@@ -742,7 +732,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
742
732
|
return this.highlightColor === this.linesManager.lineColor.hidden;
|
|
743
733
|
}
|
|
744
734
|
get inContainer() {
|
|
745
|
-
const nodeInContainer = (node) => !!
|
|
735
|
+
const nodeInContainer = (node) => !!node?.parent && node.parent.flowNodeType !== "root";
|
|
746
736
|
return nodeInContainer(this.from) || nodeInContainer(this.to);
|
|
747
737
|
}
|
|
748
738
|
/**
|
|
@@ -883,8 +873,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
883
873
|
}
|
|
884
874
|
/** 获取线条样式 */
|
|
885
875
|
get className() {
|
|
886
|
-
|
|
887
|
-
return (_a = this.linesManager.setLineClassName(this)) != null ? _a : "";
|
|
876
|
+
return this.linesManager.setLineClassName(this) ?? "";
|
|
888
877
|
}
|
|
889
878
|
get color() {
|
|
890
879
|
return this.linesManager.getLineColor(this);
|
|
@@ -905,8 +894,8 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
905
894
|
validate() {
|
|
906
895
|
const { fromPort, toPort } = this;
|
|
907
896
|
this.validateSelf();
|
|
908
|
-
fromPort
|
|
909
|
-
toPort
|
|
897
|
+
fromPort?.validate();
|
|
898
|
+
toPort?.validate();
|
|
910
899
|
}
|
|
911
900
|
validateSelf() {
|
|
912
901
|
const { fromPort, toPort } = this;
|
|
@@ -924,15 +913,14 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
924
913
|
return this.linesManager.canRemove(this, newLineInfo);
|
|
925
914
|
}
|
|
926
915
|
get node() {
|
|
927
|
-
var _a, _b, _c, _d, _e, _f;
|
|
928
916
|
if (this._node) return this._node;
|
|
929
917
|
this._node = domUtils.createDivWithClass("gedit-flow-activity-line");
|
|
930
918
|
this._node.dataset.testid = "sdk.workflow.canvas.line";
|
|
931
919
|
this._node.dataset.lineId = this.id;
|
|
932
920
|
this._node.dataset.fromNodeId = this.from.id;
|
|
933
|
-
this._node.dataset.fromPortId =
|
|
934
|
-
this._node.dataset.toNodeId =
|
|
935
|
-
this._node.dataset.toPortId =
|
|
921
|
+
this._node.dataset.fromPortId = this.fromPort?.id ?? "";
|
|
922
|
+
this._node.dataset.toNodeId = this.to?.id ?? "";
|
|
923
|
+
this._node.dataset.toPortId = this.toPort?.id ?? "";
|
|
936
924
|
this._node.dataset.hasError = this.hasError ? "true" : "false";
|
|
937
925
|
return this._node;
|
|
938
926
|
}
|
|
@@ -984,8 +972,7 @@ var WorkflowSelectService = class {
|
|
|
984
972
|
return this.selectionService.selection.some((s) => s.id === id);
|
|
985
973
|
}
|
|
986
974
|
isActivated(id) {
|
|
987
|
-
|
|
988
|
-
return ((_a = this.activatedNode) == null ? void 0 : _a.id) === id;
|
|
975
|
+
return this.activatedNode?.id === id;
|
|
989
976
|
}
|
|
990
977
|
/**
|
|
991
978
|
* 选中的节点
|
|
@@ -1189,8 +1176,7 @@ var WorkflowDocumentOptionsDefault = {
|
|
|
1189
1176
|
return;
|
|
1190
1177
|
},
|
|
1191
1178
|
toNodeJSON(node) {
|
|
1192
|
-
|
|
1193
|
-
const nodeError = (_a = node.getData(FlowNodeErrorData)) == null ? void 0 : _a.getError();
|
|
1179
|
+
const nodeError = node.getData(FlowNodeErrorData)?.getError();
|
|
1194
1180
|
if (nodeError) {
|
|
1195
1181
|
throw nodeError;
|
|
1196
1182
|
}
|
|
@@ -1198,8 +1184,8 @@ var WorkflowDocumentOptionsDefault = {
|
|
|
1198
1184
|
let formJSON = toFormJSON(node);
|
|
1199
1185
|
const metaData = {};
|
|
1200
1186
|
const nodeMeta = node.getNodeMeta();
|
|
1201
|
-
const subCanvas =
|
|
1202
|
-
if (
|
|
1187
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
1188
|
+
if (subCanvas?.isCanvas === false) {
|
|
1203
1189
|
const canvasNodeTransform = subCanvas.canvasNode.getData(FlowNodeTransformData2);
|
|
1204
1190
|
const { x, y } = canvasNodeTransform.transform.position;
|
|
1205
1191
|
metaData.canvasPosition = { x, y };
|
|
@@ -1250,12 +1236,12 @@ var WorkflowLinesManager = class {
|
|
|
1250
1236
|
}
|
|
1251
1237
|
get lineColor() {
|
|
1252
1238
|
const color = {
|
|
1253
|
-
default: "
|
|
1254
|
-
error: "red" /* ERROR */,
|
|
1255
|
-
hidden: "transparent" /* HIDDEN */,
|
|
1256
|
-
drawing: "#5DD6E3" /* DRAWING */,
|
|
1257
|
-
hovered: "
|
|
1258
|
-
selected: "
|
|
1239
|
+
default: "var(--g-line-color-default,#4d53e8)" /* DEFUALT */,
|
|
1240
|
+
error: "var(--g-line-color-error,red)" /* ERROR */,
|
|
1241
|
+
hidden: "var(--g-line-color-hidden,transparent)" /* HIDDEN */,
|
|
1242
|
+
drawing: "var(--g-line-color-drawing, #5DD6E3)" /* DRAWING */,
|
|
1243
|
+
hovered: "var(--g-line-color-hover,#37d0ff)" /* HOVER */,
|
|
1244
|
+
selected: "var(--g-line-color-selected,#37d0ff)" /* SELECTED */
|
|
1259
1245
|
};
|
|
1260
1246
|
if (this.options.lineColor) {
|
|
1261
1247
|
Object.assign(color, this.options.lineColor);
|
|
@@ -1302,7 +1288,6 @@ var WorkflowLinesManager = class {
|
|
|
1302
1288
|
return this.createLine(newPortInfo);
|
|
1303
1289
|
}
|
|
1304
1290
|
createLine(options) {
|
|
1305
|
-
var _a;
|
|
1306
1291
|
const { from, to, drawingTo, fromPort, toPort } = options;
|
|
1307
1292
|
const available = Boolean(from && to);
|
|
1308
1293
|
const key = options.key || WorkflowLineEntity.portInfoToLineId(options);
|
|
@@ -1312,7 +1297,7 @@ var WorkflowLinesManager = class {
|
|
|
1312
1297
|
line.validate();
|
|
1313
1298
|
return line;
|
|
1314
1299
|
}
|
|
1315
|
-
const fromNode =
|
|
1300
|
+
const fromNode = this.entityManager.getEntityById(from)?.getData(WorkflowNodeLinesData);
|
|
1316
1301
|
const toNode = to ? this.entityManager.getEntityById(to).getData(WorkflowNodeLinesData) : void 0;
|
|
1317
1302
|
if (!fromNode) {
|
|
1318
1303
|
return;
|
|
@@ -1330,13 +1315,13 @@ var WorkflowLinesManager = class {
|
|
|
1330
1315
|
});
|
|
1331
1316
|
this.registerData(line);
|
|
1332
1317
|
fromNode.addLine(line);
|
|
1333
|
-
toNode
|
|
1318
|
+
toNode?.addLine(line);
|
|
1334
1319
|
line.onDispose(() => {
|
|
1335
1320
|
if (drawingTo) {
|
|
1336
1321
|
this.isDrawing = false;
|
|
1337
1322
|
}
|
|
1338
1323
|
fromNode.removeLine(line);
|
|
1339
|
-
toNode
|
|
1324
|
+
toNode?.removeLine(line);
|
|
1340
1325
|
line.validate();
|
|
1341
1326
|
});
|
|
1342
1327
|
line.onDispose(() => {
|
|
@@ -1485,10 +1470,7 @@ var WorkflowLinesManager = class {
|
|
|
1485
1470
|
const allPorts = this.entityManager.getEntities(WorkflowPortEntity).filter((port) => port.node.flowNodeType !== "root");
|
|
1486
1471
|
const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
|
|
1487
1472
|
if (targetPort) {
|
|
1488
|
-
const targetNode = this.document.getAllNodes().slice().reverse().filter((node) =>
|
|
1489
|
-
var _a, _b;
|
|
1490
|
-
return ((_b = (_a = targetPort.node) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) !== node.id;
|
|
1491
|
-
}).find((node) => node.getData(TransformData6).contains(pos.x, pos.y));
|
|
1473
|
+
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));
|
|
1492
1474
|
if (targetNode && targetNode !== targetPort.node) {
|
|
1493
1475
|
return;
|
|
1494
1476
|
}
|
|
@@ -1500,22 +1482,21 @@ var WorkflowLinesManager = class {
|
|
|
1500
1482
|
* @param pos - 鼠标位置
|
|
1501
1483
|
*/
|
|
1502
1484
|
getNodeFromMousePos(pos) {
|
|
1503
|
-
var _a, _b;
|
|
1504
1485
|
const allNodes = this.document.getAllNodes().sort((a, b) => this.getNodeIndex(a) - this.getNodeIndex(b));
|
|
1505
1486
|
const containNodes = [];
|
|
1506
1487
|
const { selection } = this.selectService;
|
|
1507
|
-
const zoom =
|
|
1488
|
+
const zoom = this.entityManager.getEntity(PlaygroundConfigEntity2)?.config?.zoom || 1;
|
|
1508
1489
|
allNodes.forEach((node) => {
|
|
1509
1490
|
const { bounds } = node.getData(FlowNodeTransformData3);
|
|
1510
1491
|
if (bounds.clone().pad(4 / zoom).contains(pos.x, pos.y)) {
|
|
1511
1492
|
containNodes.push(node);
|
|
1512
1493
|
}
|
|
1513
1494
|
});
|
|
1514
|
-
if (selection
|
|
1495
|
+
if (selection?.length) {
|
|
1515
1496
|
const filteredNodes = containNodes.filter(
|
|
1516
1497
|
(node) => selection.some((_node) => node.id === _node.id)
|
|
1517
1498
|
);
|
|
1518
|
-
if (filteredNodes
|
|
1499
|
+
if (filteredNodes?.length) {
|
|
1519
1500
|
return last(filteredNodes);
|
|
1520
1501
|
}
|
|
1521
1502
|
}
|
|
@@ -1554,7 +1535,11 @@ import { customAlphabet } from "nanoid";
|
|
|
1554
1535
|
import { inject as inject5, injectable as injectable5, optional, postConstruct } from "inversify";
|
|
1555
1536
|
import { Emitter as Emitter4 } from "@flowgram.ai/utils";
|
|
1556
1537
|
import { NodeEngineContext } from "@flowgram.ai/form-core";
|
|
1557
|
-
import {
|
|
1538
|
+
import {
|
|
1539
|
+
FlowDocument,
|
|
1540
|
+
FlowNodeBaseType,
|
|
1541
|
+
FlowNodeTransformData as FlowNodeTransformData5
|
|
1542
|
+
} from "@flowgram.ai/document";
|
|
1558
1543
|
import {
|
|
1559
1544
|
injectPlaygroundContext,
|
|
1560
1545
|
PlaygroundConfigEntity as PlaygroundConfigEntity4,
|
|
@@ -1586,8 +1571,7 @@ var FreeLayout = class {
|
|
|
1586
1571
|
* 更新布局
|
|
1587
1572
|
*/
|
|
1588
1573
|
update() {
|
|
1589
|
-
|
|
1590
|
-
if ((_a = this.document.root.getData(FlowNodeTransformData4)) == null ? void 0 : _a.localDirty) {
|
|
1574
|
+
if (this.document.root.getData(FlowNodeTransformData4)?.localDirty) {
|
|
1591
1575
|
this.document.root.clearMemoGlobal();
|
|
1592
1576
|
}
|
|
1593
1577
|
}
|
|
@@ -1685,8 +1669,8 @@ var FreeLayout = class {
|
|
|
1685
1669
|
);
|
|
1686
1670
|
}
|
|
1687
1671
|
fireChange(node) {
|
|
1688
|
-
const transformData = node
|
|
1689
|
-
if (!node || !
|
|
1672
|
+
const transformData = node?.transform;
|
|
1673
|
+
if (!node || !transformData?.localDirty) {
|
|
1690
1674
|
return;
|
|
1691
1675
|
}
|
|
1692
1676
|
node.clearMemoGlobal();
|
|
@@ -1763,11 +1747,10 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1763
1747
|
* @param json
|
|
1764
1748
|
*/
|
|
1765
1749
|
fromJSON(json, fireRender = true) {
|
|
1766
|
-
var _a, _b;
|
|
1767
1750
|
if (this.disposed) return;
|
|
1768
1751
|
const workflowJSON = {
|
|
1769
|
-
nodes:
|
|
1770
|
-
edges:
|
|
1752
|
+
nodes: json.nodes ?? [],
|
|
1753
|
+
edges: json.edges ?? []
|
|
1771
1754
|
};
|
|
1772
1755
|
this.entityManager.changeEntityLocked = true;
|
|
1773
1756
|
this.renderJSON(workflowJSON);
|
|
@@ -1791,16 +1774,14 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1791
1774
|
* @param json
|
|
1792
1775
|
*/
|
|
1793
1776
|
createWorkflowNode(json, isClone = false, parentId) {
|
|
1794
|
-
var _a, _b, _c;
|
|
1795
1777
|
const isExistedNode = this.getNode(json.id);
|
|
1796
|
-
const parent =
|
|
1778
|
+
const parent = this.getNode(parentId ?? this.root.id) ?? this.root;
|
|
1797
1779
|
const node = this.addNode(
|
|
1798
1780
|
{
|
|
1799
1781
|
...json,
|
|
1800
1782
|
parent
|
|
1801
1783
|
},
|
|
1802
1784
|
void 0,
|
|
1803
|
-
true,
|
|
1804
1785
|
true
|
|
1805
1786
|
);
|
|
1806
1787
|
const registry = node.getNodeRegistry();
|
|
@@ -1842,7 +1823,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1842
1823
|
});
|
|
1843
1824
|
}
|
|
1844
1825
|
const subCanvas = this.getNodeSubCanvas(node);
|
|
1845
|
-
if (!isExistedNode && !
|
|
1826
|
+
if (!isExistedNode && !subCanvas?.isCanvas) {
|
|
1846
1827
|
this.fireContentChange({
|
|
1847
1828
|
type: "ADD_NODE" /* ADD_NODE */,
|
|
1848
1829
|
entity: node,
|
|
@@ -1869,7 +1850,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1869
1850
|
}
|
|
1870
1851
|
if (json.blocks) {
|
|
1871
1852
|
this.renderJSON(
|
|
1872
|
-
{ nodes: json.blocks, edges:
|
|
1853
|
+
{ nodes: json.blocks, edges: json.edges ?? [] },
|
|
1873
1854
|
{
|
|
1874
1855
|
parent: node,
|
|
1875
1856
|
isClone
|
|
@@ -1879,7 +1860,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1879
1860
|
if (subCanvas) {
|
|
1880
1861
|
const canvasTransform = subCanvas.canvasNode.getData(TransformData8);
|
|
1881
1862
|
canvasTransform.update({
|
|
1882
|
-
position:
|
|
1863
|
+
position: subCanvas.parentNode.getNodeMeta()?.canvasPosition
|
|
1883
1864
|
});
|
|
1884
1865
|
if (!isExistedNode) {
|
|
1885
1866
|
subCanvas.parentNode.onDispose(() => {
|
|
@@ -1905,6 +1886,64 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1905
1886
|
}
|
|
1906
1887
|
return node;
|
|
1907
1888
|
}
|
|
1889
|
+
/**
|
|
1890
|
+
* 添加节点,如果节点已经存在则不会重复创建
|
|
1891
|
+
* @param data
|
|
1892
|
+
* @param addedNodes
|
|
1893
|
+
*/
|
|
1894
|
+
addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
|
|
1895
|
+
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1896
|
+
let node = this.getNode(id);
|
|
1897
|
+
let isNew = false;
|
|
1898
|
+
const register = this.getNodeRegistry(type, data.originParent);
|
|
1899
|
+
if (node && node.flowNodeType !== data.type) {
|
|
1900
|
+
node.dispose();
|
|
1901
|
+
node = void 0;
|
|
1902
|
+
}
|
|
1903
|
+
if (!node) {
|
|
1904
|
+
const { dataRegistries } = register;
|
|
1905
|
+
node = this.entityManager.createEntity(WorkflowNodeEntity, {
|
|
1906
|
+
id,
|
|
1907
|
+
document: this,
|
|
1908
|
+
flowNodeType: type,
|
|
1909
|
+
originParent,
|
|
1910
|
+
meta
|
|
1911
|
+
});
|
|
1912
|
+
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
1913
|
+
node.addInitializeData(datas);
|
|
1914
|
+
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
1915
|
+
this.options.fromNodeJSON?.(node, data, true);
|
|
1916
|
+
isNew = true;
|
|
1917
|
+
} else {
|
|
1918
|
+
this.options.fromNodeJSON?.(node, data, false);
|
|
1919
|
+
}
|
|
1920
|
+
node.initData({
|
|
1921
|
+
originParent,
|
|
1922
|
+
parent,
|
|
1923
|
+
meta,
|
|
1924
|
+
hidden,
|
|
1925
|
+
index
|
|
1926
|
+
});
|
|
1927
|
+
addedNodes?.push(node);
|
|
1928
|
+
if (register.onCreate) {
|
|
1929
|
+
const extendNodes = register.onCreate(node, data);
|
|
1930
|
+
if (extendNodes && addedNodes) {
|
|
1931
|
+
addedNodes.push(...extendNodes);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
if (!ignoreCreateAndUpdateEvent) {
|
|
1935
|
+
if (isNew) {
|
|
1936
|
+
this.onNodeCreateEmitter.fire({
|
|
1937
|
+
node,
|
|
1938
|
+
data,
|
|
1939
|
+
json: data
|
|
1940
|
+
});
|
|
1941
|
+
} else {
|
|
1942
|
+
this.onNodeUpdateEmitter.fire({ node, data, json: data });
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
return node;
|
|
1946
|
+
}
|
|
1908
1947
|
get layout() {
|
|
1909
1948
|
const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
|
|
1910
1949
|
if (!layout) {
|
|
@@ -1948,11 +1987,11 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1948
1987
|
...json,
|
|
1949
1988
|
id,
|
|
1950
1989
|
type,
|
|
1951
|
-
meta: { position, ...json
|
|
1990
|
+
meta: { position, ...json?.meta },
|
|
1952
1991
|
// TODO title 和 meta 要从注册数据去拿
|
|
1953
|
-
data: json
|
|
1954
|
-
blocks: json
|
|
1955
|
-
edges: json
|
|
1992
|
+
data: json?.data,
|
|
1993
|
+
blocks: json?.blocks,
|
|
1994
|
+
edges: json?.edges
|
|
1956
1995
|
},
|
|
1957
1996
|
false,
|
|
1958
1997
|
parentID
|
|
@@ -1979,10 +2018,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
1979
2018
|
}));
|
|
1980
2019
|
const startNodeId = allNode.find((node) => node.isStart).id;
|
|
1981
2020
|
const endNodeId = allNode.find((node) => node.isNodeEnd).id;
|
|
1982
|
-
const nodeInContainer = allNode.filter((node) =>
|
|
1983
|
-
var _a;
|
|
1984
|
-
return (_a = node.parent) == null ? void 0 : _a.getNodeMeta().isContainer;
|
|
1985
|
-
}).map((node) => node.id);
|
|
2021
|
+
const nodeInContainer = allNode.filter((node) => node.parent?.getNodeMeta().isContainer).map((node) => node.id);
|
|
1986
2022
|
const associatedCache = /* @__PURE__ */ new Set([endNodeId, ...nodeInContainer]);
|
|
1987
2023
|
const bfs = (nodeId) => {
|
|
1988
2024
|
if (associatedCache.has(nodeId)) {
|
|
@@ -2017,7 +2053,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2017
2053
|
}
|
|
2018
2054
|
toNodeJSON(node) {
|
|
2019
2055
|
const subCanvas = this.getNodeSubCanvas(node);
|
|
2020
|
-
if (
|
|
2056
|
+
if (subCanvas?.isCanvas === true) {
|
|
2021
2057
|
return this.toNodeJSON(subCanvas.parentNode);
|
|
2022
2058
|
}
|
|
2023
2059
|
const json = this.toNodeJSONFromOptions(node);
|
|
@@ -2051,7 +2087,6 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2051
2087
|
return WorkflowDocumentOptionsDefault.toNodeJSON(node);
|
|
2052
2088
|
}
|
|
2053
2089
|
copyNode(node, newNodeId, format, position) {
|
|
2054
|
-
var _a;
|
|
2055
2090
|
let json = this.toNodeJSON(node);
|
|
2056
2091
|
if (format) {
|
|
2057
2092
|
json = format(json);
|
|
@@ -2073,7 +2108,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2073
2108
|
edges: json.edges
|
|
2074
2109
|
},
|
|
2075
2110
|
true,
|
|
2076
|
-
|
|
2111
|
+
node.parent?.id
|
|
2077
2112
|
);
|
|
2078
2113
|
}
|
|
2079
2114
|
copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position, parentId) {
|
|
@@ -2120,11 +2155,10 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2120
2155
|
* 导出数据
|
|
2121
2156
|
*/
|
|
2122
2157
|
toJSON() {
|
|
2123
|
-
var _a, _b;
|
|
2124
2158
|
const rootJSON = this.toNodeJSON(this.root);
|
|
2125
2159
|
return {
|
|
2126
|
-
nodes:
|
|
2127
|
-
edges:
|
|
2160
|
+
nodes: rootJSON.blocks ?? [],
|
|
2161
|
+
edges: rootJSON.edges ?? []
|
|
2128
2162
|
};
|
|
2129
2163
|
}
|
|
2130
2164
|
dispose() {
|
|
@@ -2135,9 +2169,8 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2135
2169
|
* 逐层创建节点和线条
|
|
2136
2170
|
*/
|
|
2137
2171
|
renderJSON(json, options) {
|
|
2138
|
-
|
|
2139
|
-
const
|
|
2140
|
-
const containerID = (_b = (_a = this.getNodeSubCanvas(parent)) == null ? void 0 : _a.canvasNode.id) != null ? _b : parent.id;
|
|
2172
|
+
const { parent = this.root, isClone = false } = options ?? {};
|
|
2173
|
+
const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
|
|
2141
2174
|
const nodes = json.nodes.map(
|
|
2142
2175
|
(nodeJSON) => this.createWorkflowNode(nodeJSON, isClone, containerID)
|
|
2143
2176
|
);
|
|
@@ -2145,10 +2178,9 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2145
2178
|
return { nodes, edges };
|
|
2146
2179
|
}
|
|
2147
2180
|
getNodeSubCanvas(node) {
|
|
2148
|
-
var _a;
|
|
2149
2181
|
if (!node) return;
|
|
2150
2182
|
const nodeMeta = node.getNodeMeta();
|
|
2151
|
-
const subCanvas =
|
|
2183
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
2152
2184
|
return subCanvas;
|
|
2153
2185
|
}
|
|
2154
2186
|
getNodeChildren(node) {
|
|
@@ -2156,9 +2188,8 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2156
2188
|
const subCanvas = this.getNodeSubCanvas(node);
|
|
2157
2189
|
const childrenWithCanvas = subCanvas ? subCanvas.canvasNode.collapsedChildren : node.collapsedChildren;
|
|
2158
2190
|
const children = childrenWithCanvas.filter((child) => {
|
|
2159
|
-
var _a, _b;
|
|
2160
2191
|
const childMeta = child.getNodeMeta();
|
|
2161
|
-
return !
|
|
2192
|
+
return !childMeta.subCanvas?.(node)?.isCanvas;
|
|
2162
2193
|
}).filter(Boolean);
|
|
2163
2194
|
return children;
|
|
2164
2195
|
}
|
|
@@ -2285,7 +2316,6 @@ var WorkflowDragService = class {
|
|
|
2285
2316
|
* @param triggerEvent
|
|
2286
2317
|
*/
|
|
2287
2318
|
async startDragSelectedNodes(triggerEvent) {
|
|
2288
|
-
var _a;
|
|
2289
2319
|
let { selectedNodes } = this.selectService;
|
|
2290
2320
|
if (selectedNodes.length === 0 || this.playgroundConfig.readonly || this.playgroundConfig.disabled || this.isDragging) {
|
|
2291
2321
|
return Promise.resolve(false);
|
|
@@ -2358,7 +2388,7 @@ var WorkflowDragService = class {
|
|
|
2358
2388
|
});
|
|
2359
2389
|
}
|
|
2360
2390
|
});
|
|
2361
|
-
return
|
|
2391
|
+
return dragger.start(triggerEvent.clientX, triggerEvent.clientY, this.playgroundConfig)?.then(() => dragSuccess);
|
|
2362
2392
|
}
|
|
2363
2393
|
/**
|
|
2364
2394
|
* 通过拖入卡片添加
|
|
@@ -2376,7 +2406,7 @@ var WorkflowDragService = class {
|
|
|
2376
2406
|
type,
|
|
2377
2407
|
position,
|
|
2378
2408
|
data,
|
|
2379
|
-
parent
|
|
2409
|
+
parent?.id
|
|
2380
2410
|
);
|
|
2381
2411
|
return node;
|
|
2382
2412
|
}
|
|
@@ -2426,7 +2456,7 @@ var WorkflowDragService = class {
|
|
|
2426
2456
|
);
|
|
2427
2457
|
return Rectangle8.intersects(draggingRect, transformRect);
|
|
2428
2458
|
});
|
|
2429
|
-
this.updateDropNode(collisionTransform
|
|
2459
|
+
this.updateDropNode(collisionTransform?.entity);
|
|
2430
2460
|
},
|
|
2431
2461
|
onDragEnd: async (e) => {
|
|
2432
2462
|
const dropNode = this._dropNode;
|
|
@@ -2543,8 +2573,7 @@ var WorkflowDragService = class {
|
|
|
2543
2573
|
}
|
|
2544
2574
|
/** 是否容器节点 */
|
|
2545
2575
|
isContainer(node) {
|
|
2546
|
-
|
|
2547
|
-
return (_a = node == null ? void 0 : node.getNodeMeta().isContainer) != null ? _a : false;
|
|
2576
|
+
return node?.getNodeMeta().isContainer ?? false;
|
|
2548
2577
|
}
|
|
2549
2578
|
/**
|
|
2550
2579
|
* 获取节点整体位置
|
|
@@ -2569,7 +2598,7 @@ var WorkflowDragService = class {
|
|
|
2569
2598
|
}
|
|
2570
2599
|
updateDropNode(node) {
|
|
2571
2600
|
if (this._dropNode) {
|
|
2572
|
-
if (this._dropNode.id ===
|
|
2601
|
+
if (this._dropNode.id === node?.id) {
|
|
2573
2602
|
return;
|
|
2574
2603
|
}
|
|
2575
2604
|
this.selectService.clear();
|
|
@@ -2591,7 +2620,7 @@ var WorkflowDragService = class {
|
|
|
2591
2620
|
this.hoverService.clearHovered();
|
|
2592
2621
|
}
|
|
2593
2622
|
handleDragOnNode(toNode, fromPort, line, toPort, originLine) {
|
|
2594
|
-
if (toPort && (
|
|
2623
|
+
if (toPort && (originLine?.toPort === toPort || toPort.portType === "input" && this.linesManager.canAddLine(fromPort, toPort, true))) {
|
|
2595
2624
|
this.hoverService.updateHoveredKey(toPort.id);
|
|
2596
2625
|
line.setToPort(toPort);
|
|
2597
2626
|
this._onDragLineEventEmitter.fire({
|
|
@@ -2613,15 +2642,14 @@ var WorkflowDragService = class {
|
|
|
2613
2642
|
}
|
|
2614
2643
|
}
|
|
2615
2644
|
childrenOfContainer(nodes) {
|
|
2616
|
-
var _a;
|
|
2617
2645
|
if (nodes.length === 0) {
|
|
2618
2646
|
return;
|
|
2619
2647
|
}
|
|
2620
|
-
const sourceContainer =
|
|
2648
|
+
const sourceContainer = nodes[0]?.parent;
|
|
2621
2649
|
if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
|
|
2622
2650
|
return;
|
|
2623
2651
|
}
|
|
2624
|
-
const valid = nodes.every((node) =>
|
|
2652
|
+
const valid = nodes.every((node) => node?.parent === sourceContainer);
|
|
2625
2653
|
if (!valid) {
|
|
2626
2654
|
return;
|
|
2627
2655
|
}
|
|
@@ -2634,7 +2662,7 @@ var WorkflowDragService = class {
|
|
|
2634
2662
|
*/
|
|
2635
2663
|
async startDrawingLine(fromPort, event, originLine) {
|
|
2636
2664
|
const isFromInActivePort = !originLine && fromPort.isErrorPort() && fromPort.disabled;
|
|
2637
|
-
if (
|
|
2665
|
+
if (originLine?.disabled || isFromInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
|
|
2638
2666
|
return { dragSuccess: false, newLine: void 0 };
|
|
2639
2667
|
}
|
|
2640
2668
|
this.selectService.clear();
|
|
@@ -2697,7 +2725,7 @@ var WorkflowDragService = class {
|
|
|
2697
2725
|
} else {
|
|
2698
2726
|
line.drawingTo = { x: dragPos.x, y: dragPos.y };
|
|
2699
2727
|
}
|
|
2700
|
-
originLine
|
|
2728
|
+
originLine?.validate();
|
|
2701
2729
|
line.validate();
|
|
2702
2730
|
},
|
|
2703
2731
|
// eslint-disable-next-line complexity
|
|
@@ -2717,7 +2745,7 @@ var WorkflowDragService = class {
|
|
|
2717
2745
|
})
|
|
2718
2746
|
)
|
|
2719
2747
|
);
|
|
2720
|
-
line
|
|
2748
|
+
line?.dispose();
|
|
2721
2749
|
this._onDragLineEventEmitter.fire({
|
|
2722
2750
|
type: "onDragEnd"
|
|
2723
2751
|
});
|
|
@@ -2725,7 +2753,7 @@ var WorkflowDragService = class {
|
|
|
2725
2753
|
originLine.highlightColor = "";
|
|
2726
2754
|
}
|
|
2727
2755
|
const end = () => {
|
|
2728
|
-
originLine
|
|
2756
|
+
originLine?.validate();
|
|
2729
2757
|
deferred.resolve({ dragSuccess });
|
|
2730
2758
|
};
|
|
2731
2759
|
if (dragSuccess) {
|
|
@@ -2752,7 +2780,7 @@ var WorkflowDragService = class {
|
|
|
2752
2780
|
if (originLine && (!this.linesManager.canRemove(originLine, newLineInfo, false) || lineErrorReset)) {
|
|
2753
2781
|
return end();
|
|
2754
2782
|
} else {
|
|
2755
|
-
originLine
|
|
2783
|
+
originLine?.dispose();
|
|
2756
2784
|
}
|
|
2757
2785
|
if (!toPort || !this.linesManager.canAddLine(fromPort, toPort, false)) {
|
|
2758
2786
|
return end();
|
|
@@ -2979,7 +3007,7 @@ function usePlaygroundReadonlyState(listenChange) {
|
|
|
2979
3007
|
if (listenChange) {
|
|
2980
3008
|
dispose = playground.config.onReadonlyOrDisabledChange(() => refresh());
|
|
2981
3009
|
}
|
|
2982
|
-
return () => dispose
|
|
3010
|
+
return () => dispose?.dispose();
|
|
2983
3011
|
}, [listenChange]);
|
|
2984
3012
|
return playground.config.readonly;
|
|
2985
3013
|
}
|
|
@@ -2989,7 +3017,6 @@ function checkTargetDraggable(el) {
|
|
|
2989
3017
|
return el && el.tagName !== "INPUT" && el.tagName !== "TEXTAREA" && !el.closest(".flow-canvas-not-draggable");
|
|
2990
3018
|
}
|
|
2991
3019
|
function useNodeRender(nodeFromProps) {
|
|
2992
|
-
var _a, _b;
|
|
2993
3020
|
const node = nodeFromProps || useContext(PlaygroundEntityContext);
|
|
2994
3021
|
const renderData = node.getData(FlowNodeRenderData3);
|
|
2995
3022
|
const portsData = node.getData(WorkflowNodePortsData);
|
|
@@ -3013,7 +3040,6 @@ function useNodeRender(nodeFromProps) {
|
|
|
3013
3040
|
}, []);
|
|
3014
3041
|
const startDrag = useCallback(
|
|
3015
3042
|
(e) => {
|
|
3016
|
-
var _a2;
|
|
3017
3043
|
e.preventDefault();
|
|
3018
3044
|
if (!selectionService.isSelected(node.id)) {
|
|
3019
3045
|
selectNode(e);
|
|
@@ -3022,7 +3048,7 @@ function useNodeRender(nodeFromProps) {
|
|
|
3022
3048
|
return;
|
|
3023
3049
|
}
|
|
3024
3050
|
isDragging.current = true;
|
|
3025
|
-
|
|
3051
|
+
dragService.startDragSelectedNodes(e)?.finally(
|
|
3026
3052
|
() => setTimeout(() => {
|
|
3027
3053
|
isDragging.current = false;
|
|
3028
3054
|
})
|
|
@@ -3048,17 +3074,15 @@ function useNodeRender(nodeFromProps) {
|
|
|
3048
3074
|
);
|
|
3049
3075
|
const deleteNode = useCallback(() => node.dispose(), [node]);
|
|
3050
3076
|
useListenEvents(portsData.onDataChange);
|
|
3051
|
-
const isFirefox =
|
|
3077
|
+
const isFirefox = navigator?.userAgent?.includes?.("Firefox");
|
|
3052
3078
|
const onFocus = useCallback(() => {
|
|
3053
|
-
var _a2;
|
|
3054
3079
|
if (isFirefox) {
|
|
3055
|
-
|
|
3080
|
+
nodeRef.current?.setAttribute("draggable", "false");
|
|
3056
3081
|
}
|
|
3057
3082
|
}, []);
|
|
3058
3083
|
const onBlur = useCallback(() => {
|
|
3059
|
-
var _a2;
|
|
3060
3084
|
if (isFirefox) {
|
|
3061
|
-
|
|
3085
|
+
nodeRef.current?.setAttribute("draggable", "true");
|
|
3062
3086
|
}
|
|
3063
3087
|
}, []);
|
|
3064
3088
|
const getExtInfo = useCallback(() => node.getExtInfo(), [node]);
|
|
@@ -3069,7 +3093,7 @@ function useNodeRender(nodeFromProps) {
|
|
|
3069
3093
|
[node]
|
|
3070
3094
|
);
|
|
3071
3095
|
const form = useMemo(() => getNodeForm(node), [node]);
|
|
3072
|
-
const formState = useObserve(form
|
|
3096
|
+
const formState = useObserve(form?.state);
|
|
3073
3097
|
const toggleExpand = useCallback(() => {
|
|
3074
3098
|
renderData.toggleExpand();
|
|
3075
3099
|
}, [renderData]);
|
|
@@ -3205,8 +3229,7 @@ var WorkflowSimpleLineContribution = class {
|
|
|
3205
3229
|
this.entity = entity;
|
|
3206
3230
|
}
|
|
3207
3231
|
get path() {
|
|
3208
|
-
|
|
3209
|
-
return (_b = (_a = this.data) == null ? void 0 : _a.path) != null ? _b : "";
|
|
3232
|
+
return this.data?.path ?? "";
|
|
3210
3233
|
}
|
|
3211
3234
|
calcDistance(pos) {
|
|
3212
3235
|
if (!this.data) {
|