@flowgram.ai/free-layout-core 1.0.10 → 1.0.11
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 +125 -49
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +124 -43
- 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/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-node.d.mts +1 -1
- package/dist/typings/workflow-node.d.ts +1 -1
- package/dist/typings/workflow-operation.d.mts +1 -1
- package/dist/typings/workflow-operation.d.ts +1 -1
- package/dist/typings/workflow-registry.d.mts +1 -1
- package/dist/typings/workflow-registry.d.ts +1 -1
- package/dist/typings/workflow-sub-canvas.d.mts +1 -1
- package/dist/typings/workflow-sub-canvas.d.ts +1 -1
- package/dist/{workflow-node-entity-C_A53MW2.d.ts → workflow-node-entity-03Q7Fvv6.d.ts} +10 -1
- package/dist/{workflow-node-entity-BpXZTWZe.d.mts → workflow-node-entity-C6bFzfXc.d.mts} +10 -1
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -155,7 +155,8 @@ function getAntiOverlapPosition(doc, position, containerNode) {
|
|
|
155
155
|
|
|
156
156
|
// src/utils/statics.ts
|
|
157
157
|
import { Rectangle as Rectangle2 } from "@flowgram.ai/utils";
|
|
158
|
-
var
|
|
158
|
+
var getPortEntityIdByNodeId = (nodeId, portType, portID = "") => `port_${portType}_${nodeId}_${portID}`;
|
|
159
|
+
var getPortEntityId = (node, portType, portID = "") => getPortEntityIdByNodeId(node.id, portType, portID);
|
|
159
160
|
var WORKFLOW_LINE_ENTITY = "WorkflowLineEntity";
|
|
160
161
|
function domReactToBounds(react) {
|
|
161
162
|
return new Rectangle2(react.x, react.y, react.width, react.height);
|
|
@@ -167,7 +168,7 @@ var WorkflowNodeEntity = FlowNodeEntity;
|
|
|
167
168
|
|
|
168
169
|
// src/entities/workflow-line-entity.ts
|
|
169
170
|
import { isEqual as isEqual2 } from "lodash-es";
|
|
170
|
-
import { domUtils, Emitter as Emitter2 } from "@flowgram.ai/utils";
|
|
171
|
+
import { domUtils, Emitter as Emitter2, Disposable as Disposable2 } from "@flowgram.ai/utils";
|
|
171
172
|
import { Entity as Entity2 } from "@flowgram.ai/core";
|
|
172
173
|
|
|
173
174
|
// src/entity-datas/workflow-node-ports-data.ts
|
|
@@ -178,11 +179,7 @@ import { EntityData, SizeData } from "@flowgram.ai/core";
|
|
|
178
179
|
// src/entities/workflow-port-entity.ts
|
|
179
180
|
import { Rectangle as Rectangle3, Emitter, Compare } from "@flowgram.ai/utils";
|
|
180
181
|
import { FlowNodeTransformData } from "@flowgram.ai/document";
|
|
181
|
-
import {
|
|
182
|
-
Entity,
|
|
183
|
-
PlaygroundConfigEntity,
|
|
184
|
-
TransformData as TransformData3
|
|
185
|
-
} from "@flowgram.ai/core";
|
|
182
|
+
import { Entity, PlaygroundConfigEntity, TransformData as TransformData3 } from "@flowgram.ai/core";
|
|
186
183
|
|
|
187
184
|
// src/utils/location-config-to-point.ts
|
|
188
185
|
function locationConfigToPoint(bounds, config, _offset = { x: 0, y: 0 }) {
|
|
@@ -374,16 +371,8 @@ var WorkflowPortEntity = class extends Entity {
|
|
|
374
371
|
* 当前点位上连接的线条(包含 isDrawing === true 的线条)
|
|
375
372
|
*/
|
|
376
373
|
get allLines() {
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
type: WORKFLOW_LINE_ENTITY
|
|
380
|
-
});
|
|
381
|
-
allLines.forEach((line) => {
|
|
382
|
-
if (line.toPort === this || line.fromPort === this) {
|
|
383
|
-
lines.push(line);
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
return lines;
|
|
374
|
+
const document2 = this.node.document;
|
|
375
|
+
return document2.linesManager.getLinesByPortId(this.id);
|
|
387
376
|
}
|
|
388
377
|
update(data) {
|
|
389
378
|
let changed = false;
|
|
@@ -893,6 +882,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
893
882
|
this.toPort?.validate();
|
|
894
883
|
});
|
|
895
884
|
this.toDispose.push(this._onLineDataChangeEmitter);
|
|
885
|
+
this.preDispose.push(
|
|
886
|
+
Disposable2.create(() => this.linesManager.rebindLinePorts(this, this.info, void 0))
|
|
887
|
+
);
|
|
896
888
|
}
|
|
897
889
|
/**
|
|
898
890
|
* 转成线条 id
|
|
@@ -1002,19 +994,20 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1002
994
|
const prePort = this.toPort;
|
|
1003
995
|
if (toPort && toPort.portType === "input" && this.linesManager.canAddLine(this.fromPort, toPort, true)) {
|
|
1004
996
|
const { node, portID } = toPort;
|
|
1005
|
-
this.
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
997
|
+
this.updateInfo((nextInfo) => {
|
|
998
|
+
nextInfo.drawingTo = void 0;
|
|
999
|
+
nextInfo.to = node.id;
|
|
1000
|
+
nextInfo.toPort = portID;
|
|
1001
|
+
});
|
|
1009
1002
|
} else {
|
|
1010
|
-
this.
|
|
1011
|
-
|
|
1012
|
-
|
|
1003
|
+
this.updateInfo((nextInfo) => {
|
|
1004
|
+
nextInfo.to = void 0;
|
|
1005
|
+
nextInfo.toPort = "";
|
|
1006
|
+
});
|
|
1013
1007
|
}
|
|
1014
1008
|
if (prePort) {
|
|
1015
1009
|
prePort.validate();
|
|
1016
1010
|
}
|
|
1017
|
-
this.fireChange();
|
|
1018
1011
|
}
|
|
1019
1012
|
setFromPort(fromPort) {
|
|
1020
1013
|
if (!this.isDrawing) {
|
|
@@ -1026,19 +1019,20 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1026
1019
|
const prePort = this.fromPort;
|
|
1027
1020
|
if (fromPort && fromPort.portType === "output" && this.linesManager.canAddLine(fromPort, this.toPort, true)) {
|
|
1028
1021
|
const { node, portID } = fromPort;
|
|
1029
|
-
this.
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1022
|
+
this.updateInfo((nextInfo) => {
|
|
1023
|
+
nextInfo.drawingFrom = void 0;
|
|
1024
|
+
nextInfo.from = node.id;
|
|
1025
|
+
nextInfo.fromPort = portID;
|
|
1026
|
+
});
|
|
1033
1027
|
} else {
|
|
1034
|
-
this.
|
|
1035
|
-
|
|
1036
|
-
|
|
1028
|
+
this.updateInfo((nextInfo) => {
|
|
1029
|
+
nextInfo.from = void 0;
|
|
1030
|
+
nextInfo.fromPort = "";
|
|
1031
|
+
});
|
|
1037
1032
|
}
|
|
1038
1033
|
if (prePort) {
|
|
1039
1034
|
prePort.validate();
|
|
1040
1035
|
}
|
|
1041
|
-
this.fireChange();
|
|
1042
1036
|
}
|
|
1043
1037
|
/**
|
|
1044
1038
|
* 设置线条画线时的目标位置
|
|
@@ -1046,27 +1040,41 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1046
1040
|
set drawingTo(pos) {
|
|
1047
1041
|
const oldDrawingTo = this.info.drawingTo;
|
|
1048
1042
|
if (!pos) {
|
|
1049
|
-
|
|
1050
|
-
|
|
1043
|
+
if (oldDrawingTo === void 0) {
|
|
1044
|
+
this.fireChange();
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
this.updateInfo((nextInfo) => {
|
|
1048
|
+
nextInfo.drawingTo = void 0;
|
|
1049
|
+
});
|
|
1051
1050
|
return;
|
|
1052
1051
|
}
|
|
1053
1052
|
if (!oldDrawingTo || pos.x !== oldDrawingTo.x || pos.y !== oldDrawingTo.y) {
|
|
1054
|
-
this.
|
|
1055
|
-
|
|
1056
|
-
|
|
1053
|
+
this.updateInfo((nextInfo) => {
|
|
1054
|
+
nextInfo.to = void 0;
|
|
1055
|
+
nextInfo.toPort = "";
|
|
1056
|
+
nextInfo.drawingTo = pos;
|
|
1057
|
+
});
|
|
1057
1058
|
}
|
|
1058
1059
|
}
|
|
1059
1060
|
set drawingFrom(pos) {
|
|
1060
1061
|
const oldDrawingFrom = this.info.drawingFrom;
|
|
1061
1062
|
if (!pos) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1063
|
+
if (oldDrawingFrom === void 0) {
|
|
1064
|
+
this.fireChange();
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
this.updateInfo((nextInfo) => {
|
|
1068
|
+
nextInfo.drawingFrom = void 0;
|
|
1069
|
+
});
|
|
1064
1070
|
return;
|
|
1065
1071
|
}
|
|
1066
1072
|
if (!oldDrawingFrom || pos.x !== oldDrawingFrom.x || pos.y !== oldDrawingFrom.y) {
|
|
1067
|
-
this.
|
|
1068
|
-
|
|
1069
|
-
|
|
1073
|
+
this.updateInfo((nextInfo) => {
|
|
1074
|
+
nextInfo.from = void 0;
|
|
1075
|
+
nextInfo.fromPort = "";
|
|
1076
|
+
nextInfo.drawingFrom = pos;
|
|
1077
|
+
});
|
|
1070
1078
|
}
|
|
1071
1079
|
}
|
|
1072
1080
|
get drawingFrom() {
|
|
@@ -1177,13 +1185,26 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1177
1185
|
* @param info 线条信息
|
|
1178
1186
|
*/
|
|
1179
1187
|
initInfo(info) {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
this.
|
|
1185
|
-
|
|
1188
|
+
this.applyInfo(info);
|
|
1189
|
+
}
|
|
1190
|
+
updateInfo(mutator) {
|
|
1191
|
+
const nextInfo = {
|
|
1192
|
+
...this.info
|
|
1193
|
+
};
|
|
1194
|
+
mutator(nextInfo);
|
|
1195
|
+
this.applyInfo(nextInfo);
|
|
1196
|
+
}
|
|
1197
|
+
applyInfo(nextInfo) {
|
|
1198
|
+
if (isEqual2(nextInfo, this.info)) {
|
|
1199
|
+
return;
|
|
1186
1200
|
}
|
|
1201
|
+
const prevInfo = this.info;
|
|
1202
|
+
this.info = nextInfo;
|
|
1203
|
+
this._from = nextInfo.from ? this.document.getNode(nextInfo.from) : void 0;
|
|
1204
|
+
this._to = nextInfo.to ? this.document.getNode(nextInfo.to) : void 0;
|
|
1205
|
+
this._lineData = nextInfo.data;
|
|
1206
|
+
this.linesManager.rebindLinePorts(this, prevInfo, nextInfo);
|
|
1207
|
+
this.fireChange();
|
|
1187
1208
|
}
|
|
1188
1209
|
// 校验连线是否为错误态
|
|
1189
1210
|
validate() {
|
|
@@ -1522,6 +1543,7 @@ var WorkflowDocumentOptionsDefault = {
|
|
|
1522
1543
|
var WorkflowLinesManager = class {
|
|
1523
1544
|
constructor() {
|
|
1524
1545
|
this.toDispose = new DisposableCollection();
|
|
1546
|
+
this.portLineMap = /* @__PURE__ */ new Map();
|
|
1525
1547
|
// 线条类型
|
|
1526
1548
|
this._lineType = 0 /* BEZIER */;
|
|
1527
1549
|
this.onAvailableLinesChangeEmitter = new Emitter4();
|
|
@@ -1586,6 +1608,58 @@ var WorkflowLinesManager = class {
|
|
|
1586
1608
|
getAllLines() {
|
|
1587
1609
|
return this.entityManager.getEntities(WorkflowLineEntity);
|
|
1588
1610
|
}
|
|
1611
|
+
getLinesByPortId(portId) {
|
|
1612
|
+
return Array.from(this.portLineMap.get(portId) || []);
|
|
1613
|
+
}
|
|
1614
|
+
rebindLinePorts(line, prevInfo, nextInfo) {
|
|
1615
|
+
const prevFromPortId = this.getLinePortId(prevInfo, "output");
|
|
1616
|
+
const prevToPortId = this.getLinePortId(prevInfo, "input");
|
|
1617
|
+
const nextFromPortId = this.getLinePortId(nextInfo, "output");
|
|
1618
|
+
const nextToPortId = this.getLinePortId(nextInfo, "input");
|
|
1619
|
+
if (prevFromPortId !== nextFromPortId) {
|
|
1620
|
+
this.detachLineFromPortId(line, prevFromPortId);
|
|
1621
|
+
this.attachLineToPortId(line, nextFromPortId);
|
|
1622
|
+
}
|
|
1623
|
+
if (prevToPortId !== nextToPortId) {
|
|
1624
|
+
this.detachLineFromPortId(line, prevToPortId);
|
|
1625
|
+
this.attachLineToPortId(line, nextToPortId);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
attachLineToPortId(line, portId) {
|
|
1629
|
+
if (!portId) {
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
let lines = this.portLineMap.get(portId);
|
|
1633
|
+
if (!lines) {
|
|
1634
|
+
lines = /* @__PURE__ */ new Set();
|
|
1635
|
+
this.portLineMap.set(portId, lines);
|
|
1636
|
+
}
|
|
1637
|
+
lines.add(line);
|
|
1638
|
+
}
|
|
1639
|
+
detachLineFromPortId(line, portId) {
|
|
1640
|
+
if (!portId) {
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
const lines = this.portLineMap.get(portId);
|
|
1644
|
+
if (!lines) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
lines.delete(line);
|
|
1648
|
+
if (!lines.size) {
|
|
1649
|
+
this.portLineMap.delete(portId);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
getLinePortId(info, portType) {
|
|
1653
|
+
if (!info) {
|
|
1654
|
+
return void 0;
|
|
1655
|
+
}
|
|
1656
|
+
const nodeId = portType === "output" ? info.from : info.to;
|
|
1657
|
+
if (!nodeId) {
|
|
1658
|
+
return void 0;
|
|
1659
|
+
}
|
|
1660
|
+
const portId = portType === "output" ? info.fromPort : info.toPort;
|
|
1661
|
+
return getPortEntityIdByNodeId(nodeId, portType, portId);
|
|
1662
|
+
}
|
|
1589
1663
|
getAllAvailableLines() {
|
|
1590
1664
|
return this.getAllLines().filter((l) => !l.isDrawing && !l.isHidden);
|
|
1591
1665
|
}
|
|
@@ -1690,6 +1764,7 @@ var WorkflowLinesManager = class {
|
|
|
1690
1764
|
return targetLine;
|
|
1691
1765
|
}
|
|
1692
1766
|
dispose() {
|
|
1767
|
+
this.portLineMap.clear();
|
|
1693
1768
|
this.toDispose.dispose();
|
|
1694
1769
|
}
|
|
1695
1770
|
get disposed() {
|
|
@@ -3991,6 +4066,7 @@ export {
|
|
|
3991
4066
|
getAntiOverlapPosition,
|
|
3992
4067
|
getLineCenter,
|
|
3993
4068
|
getPortEntityId,
|
|
4069
|
+
getPortEntityIdByNodeId,
|
|
3994
4070
|
nanoid,
|
|
3995
4071
|
useConfigEntity,
|
|
3996
4072
|
useCurrentDomNode,
|