@flowgram.ai/free-layout-core 0.4.18 → 0.5.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/index.js +253 -108
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +45 -44
- package/dist/index.d.ts +45 -44
- package/dist/index.js +251 -107
- 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-drag.js.map +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-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-GyY_PHY6.d.ts → workflow-node-entity-Cnte2phX.d.ts} +27 -13
- package/dist/{workflow-node-entity-DtPEYn6-.d.mts → workflow-node-entity-lKu00Aj4.d.mts} +27 -13
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -818,16 +818,8 @@ var WorkflowLineRenderData = class extends import_core7.EntityData {
|
|
|
818
818
|
* WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
|
|
819
819
|
*/
|
|
820
820
|
updatePosition() {
|
|
821
|
-
this.data.position.from = this.entity.
|
|
822
|
-
|
|
823
|
-
this.data.position.to = this.entity.info.drawingTo;
|
|
824
|
-
} else {
|
|
825
|
-
this.data.position.to = this.entity.to?.ports?.getInputPoint(this.entity.info.toPort) ?? {
|
|
826
|
-
x: this.data.position.from.x,
|
|
827
|
-
y: this.data.position.from.y,
|
|
828
|
-
location: this.data.position.from.location === "right" ? "left" : "top"
|
|
829
|
-
};
|
|
830
|
-
}
|
|
821
|
+
this.data.position.from = this.entity.drawingFrom || this.entity.fromPort.point;
|
|
822
|
+
this.data.position.to = this.entity.drawingTo || this.entity.toPort.point;
|
|
831
823
|
this.data.version = [
|
|
832
824
|
this.lineType,
|
|
833
825
|
this.data.position.from.x,
|
|
@@ -892,10 +884,11 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
892
884
|
to: opts.to,
|
|
893
885
|
drawingTo: opts.drawingTo,
|
|
894
886
|
fromPort: opts.fromPort,
|
|
887
|
+
drawingFrom: opts.drawingFrom,
|
|
895
888
|
toPort: opts.toPort,
|
|
896
889
|
data: opts.data
|
|
897
890
|
});
|
|
898
|
-
if (opts.drawingTo) {
|
|
891
|
+
if (opts.drawingTo || opts.drawingFrom) {
|
|
899
892
|
this.isDrawing = true;
|
|
900
893
|
}
|
|
901
894
|
this.onEntityChange(() => {
|
|
@@ -1030,6 +1023,30 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1030
1023
|
}
|
|
1031
1024
|
this.fireChange();
|
|
1032
1025
|
}
|
|
1026
|
+
setFromPort(fromPort) {
|
|
1027
|
+
if (!this.isDrawing) {
|
|
1028
|
+
throw new Error("[setFromPort] only support drawing line.");
|
|
1029
|
+
}
|
|
1030
|
+
if (this.fromPort === fromPort) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
const prePort = this.fromPort;
|
|
1034
|
+
if (fromPort && fromPort.portType === "output" && this.linesManager.canAddLine(fromPort, this.toPort, true)) {
|
|
1035
|
+
const { node, portID } = fromPort;
|
|
1036
|
+
this._from = node;
|
|
1037
|
+
this.info.drawingFrom = void 0;
|
|
1038
|
+
this.info.from = node.id;
|
|
1039
|
+
this.info.fromPort = portID;
|
|
1040
|
+
} else {
|
|
1041
|
+
this._from = void 0;
|
|
1042
|
+
this.info.from = void 0;
|
|
1043
|
+
this.info.fromPort = "";
|
|
1044
|
+
}
|
|
1045
|
+
if (prePort) {
|
|
1046
|
+
prePort.validate();
|
|
1047
|
+
}
|
|
1048
|
+
this.fireChange();
|
|
1049
|
+
}
|
|
1033
1050
|
/**
|
|
1034
1051
|
* 设置线条画线时的目标位置
|
|
1035
1052
|
*/
|
|
@@ -1046,6 +1063,22 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1046
1063
|
this.fireChange();
|
|
1047
1064
|
}
|
|
1048
1065
|
}
|
|
1066
|
+
set drawingFrom(pos) {
|
|
1067
|
+
const oldDrawingFrom = this.info.drawingFrom;
|
|
1068
|
+
if (!pos) {
|
|
1069
|
+
this.info.drawingFrom = void 0;
|
|
1070
|
+
this.fireChange();
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (!oldDrawingFrom || pos.x !== oldDrawingFrom.x || pos.y !== oldDrawingFrom.y) {
|
|
1074
|
+
this.info.from = void 0;
|
|
1075
|
+
this.info.drawingFrom = pos;
|
|
1076
|
+
this.fireChange();
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
get drawingFrom() {
|
|
1080
|
+
return this.info.drawingFrom;
|
|
1081
|
+
}
|
|
1049
1082
|
/**
|
|
1050
1083
|
* 获取线条正在画线的位置
|
|
1051
1084
|
*/
|
|
@@ -1084,6 +1117,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1084
1117
|
return this.getData(WorkflowLineRenderData).calcDistance(pos);
|
|
1085
1118
|
}
|
|
1086
1119
|
get fromPort() {
|
|
1120
|
+
if (!this.from) {
|
|
1121
|
+
return void 0;
|
|
1122
|
+
}
|
|
1087
1123
|
return this.from.ports.getPortEntityByKey("output", this.info.fromPort);
|
|
1088
1124
|
}
|
|
1089
1125
|
get toPort() {
|
|
@@ -1124,7 +1160,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1124
1160
|
* @deprecated
|
|
1125
1161
|
*/
|
|
1126
1162
|
get vertical() {
|
|
1127
|
-
const fromLocation = this.fromPort
|
|
1163
|
+
const fromLocation = this.fromPort?.location;
|
|
1128
1164
|
const toLocation = this.toPort?.location;
|
|
1129
1165
|
if (toLocation) {
|
|
1130
1166
|
return toLocation === "top";
|
|
@@ -1150,7 +1186,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1150
1186
|
initInfo(info) {
|
|
1151
1187
|
if (!(0, import_lodash_es2.isEqual)(info, this.info)) {
|
|
1152
1188
|
this.info = info;
|
|
1153
|
-
this._from = this.document.getNode(info.from);
|
|
1189
|
+
this._from = info.from ? this.document.getNode(info.from) : void 0;
|
|
1154
1190
|
this._to = info.to ? this.document.getNode(info.to) : void 0;
|
|
1155
1191
|
this._lineData = info.data;
|
|
1156
1192
|
this.fireChange();
|
|
@@ -1184,7 +1220,7 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
|
|
|
1184
1220
|
this._node = import_utils8.domUtils.createDivWithClass("gedit-flow-activity-line");
|
|
1185
1221
|
this._node.dataset.testid = "sdk.workflow.canvas.line";
|
|
1186
1222
|
this._node.dataset.lineId = this.id;
|
|
1187
|
-
this._node.dataset.fromNodeId = this.from
|
|
1223
|
+
this._node.dataset.fromNodeId = this.from?.id ?? "";
|
|
1188
1224
|
this._node.dataset.fromPortId = this.fromPort?.id ?? "";
|
|
1189
1225
|
this._node.dataset.toNodeId = this.to?.id ?? "";
|
|
1190
1226
|
this._node.dataset.toPortId = this.toPort?.id ?? "";
|
|
@@ -1366,10 +1402,17 @@ var WorkflowHoverService = class {
|
|
|
1366
1402
|
}
|
|
1367
1403
|
/**
|
|
1368
1404
|
* 获取被 hover 的节点或线条
|
|
1405
|
+
* @deprecated use 'someHovered' instead
|
|
1369
1406
|
*/
|
|
1370
1407
|
get hoveredNode() {
|
|
1371
1408
|
return this.entityManager.getEntityById(this.hoveredKey);
|
|
1372
1409
|
}
|
|
1410
|
+
/**
|
|
1411
|
+
* 获取被 hover 的节点或线条
|
|
1412
|
+
*/
|
|
1413
|
+
get someHovered() {
|
|
1414
|
+
return this.entityManager.getEntityById(this.hoveredKey);
|
|
1415
|
+
}
|
|
1373
1416
|
};
|
|
1374
1417
|
__decorateClass([
|
|
1375
1418
|
(0, import_inversify2.inject)(import_core10.EntityManager)
|
|
@@ -1574,6 +1617,9 @@ var WorkflowLinesManager = class {
|
|
|
1574
1617
|
getAllLines() {
|
|
1575
1618
|
return this.entityManager.getEntities(WorkflowLineEntity);
|
|
1576
1619
|
}
|
|
1620
|
+
getAllAvailableLines() {
|
|
1621
|
+
return this.getAllLines().filter((l) => !l.isDrawing && !l.isHidden);
|
|
1622
|
+
}
|
|
1577
1623
|
hasLine(portInfo) {
|
|
1578
1624
|
return !!this.entityManager.getEntityById(
|
|
1579
1625
|
WorkflowLineEntity.portInfoToLineId(portInfo)
|
|
@@ -1595,7 +1641,7 @@ var WorkflowLinesManager = class {
|
|
|
1595
1641
|
return this.createLine(newPortInfo);
|
|
1596
1642
|
}
|
|
1597
1643
|
createLine(options) {
|
|
1598
|
-
const { from, to, drawingTo, fromPort, toPort, data } = options;
|
|
1644
|
+
const { from, to, drawingTo, fromPort, drawingFrom, toPort, data } = options;
|
|
1599
1645
|
const available = Boolean(from && to);
|
|
1600
1646
|
const key = options.key || WorkflowLineEntity.portInfoToLineId(options);
|
|
1601
1647
|
let line = this.entityManager.getEntityById(key);
|
|
@@ -1604,12 +1650,12 @@ var WorkflowLinesManager = class {
|
|
|
1604
1650
|
line.validate();
|
|
1605
1651
|
return line;
|
|
1606
1652
|
}
|
|
1607
|
-
const fromNode = this.entityManager.getEntityById(from)
|
|
1653
|
+
const fromNode = from ? this.entityManager.getEntityById(from).getData(WorkflowNodeLinesData) : void 0;
|
|
1608
1654
|
const toNode = to ? this.entityManager.getEntityById(to).getData(WorkflowNodeLinesData) : void 0;
|
|
1609
|
-
if (!fromNode) {
|
|
1655
|
+
if (!fromNode && !toNode) {
|
|
1610
1656
|
return;
|
|
1611
1657
|
}
|
|
1612
|
-
this.isDrawing = Boolean(drawingTo);
|
|
1658
|
+
this.isDrawing = Boolean(drawingTo || drawingFrom);
|
|
1613
1659
|
line = this.entityManager.createEntity(WorkflowLineEntity, {
|
|
1614
1660
|
id: key,
|
|
1615
1661
|
document: this.document,
|
|
@@ -1619,16 +1665,15 @@ var WorkflowLinesManager = class {
|
|
|
1619
1665
|
toPort,
|
|
1620
1666
|
to,
|
|
1621
1667
|
drawingTo,
|
|
1668
|
+
drawingFrom,
|
|
1622
1669
|
data
|
|
1623
1670
|
});
|
|
1624
1671
|
this.registerData(line);
|
|
1625
|
-
fromNode
|
|
1672
|
+
fromNode?.addLine(line);
|
|
1626
1673
|
toNode?.addLine(line);
|
|
1627
1674
|
line.onDispose(() => {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
}
|
|
1631
|
-
fromNode.removeLine(line);
|
|
1675
|
+
this.isDrawing = false;
|
|
1676
|
+
fromNode?.removeLine(line);
|
|
1632
1677
|
toNode?.removeLine(line);
|
|
1633
1678
|
});
|
|
1634
1679
|
line.onDispose(() => {
|
|
@@ -1751,7 +1796,7 @@ var WorkflowLinesManager = class {
|
|
|
1751
1796
|
return this.lineColor.default;
|
|
1752
1797
|
}
|
|
1753
1798
|
canAddLine(fromPort, toPort, silent) {
|
|
1754
|
-
if (fromPort === toPort || fromPort.node === toPort.node || fromPort.portType !== "output" || toPort.portType !== "input" || toPort.disabled) {
|
|
1799
|
+
if (fromPort === toPort || fromPort.node === toPort.node || fromPort.portType !== "output" || toPort.portType !== "input" || fromPort.disabled || toPort.disabled) {
|
|
1755
1800
|
return false;
|
|
1756
1801
|
}
|
|
1757
1802
|
const fromCanAdd = fromPort.node.getNodeRegistry().canAddLine;
|
|
@@ -1779,8 +1824,8 @@ var WorkflowLinesManager = class {
|
|
|
1779
1824
|
}
|
|
1780
1825
|
return true;
|
|
1781
1826
|
}
|
|
1782
|
-
canReset(
|
|
1783
|
-
if (this.options && this.options.canResetLine && !this.options.canResetLine(
|
|
1827
|
+
canReset(oldLine, newLineInfo) {
|
|
1828
|
+
if (this.options && this.options.canResetLine && !this.options.canResetLine(oldLine, newLineInfo, this)) {
|
|
1784
1829
|
return false;
|
|
1785
1830
|
}
|
|
1786
1831
|
return true;
|
|
@@ -1789,9 +1834,14 @@ var WorkflowLinesManager = class {
|
|
|
1789
1834
|
* 根据鼠标位置找到 port
|
|
1790
1835
|
* @param pos
|
|
1791
1836
|
*/
|
|
1792
|
-
getPortFromMousePos(pos) {
|
|
1837
|
+
getPortFromMousePos(pos, portType) {
|
|
1793
1838
|
const allNodes = this.getSortedNodes().reverse();
|
|
1794
|
-
const allPorts = allNodes.map((node) =>
|
|
1839
|
+
const allPorts = allNodes.map((node) => {
|
|
1840
|
+
if (!portType) {
|
|
1841
|
+
return node.ports.allPorts;
|
|
1842
|
+
}
|
|
1843
|
+
return portType === "input" ? node.ports.inputPorts : node.ports.outputPorts;
|
|
1844
|
+
}).flat();
|
|
1795
1845
|
const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
|
|
1796
1846
|
if (targetPort) {
|
|
1797
1847
|
const containNodes = this.getContainNodesFromMousePos(pos);
|
|
@@ -2995,18 +3045,30 @@ var WorkflowDragService = class {
|
|
|
2995
3045
|
line.highlightColor = color;
|
|
2996
3046
|
this.hoverService.clearHovered();
|
|
2997
3047
|
}
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3048
|
+
checkDraggingPort(isDrawingTo, line, draggingNode, draggingPort, originLine) {
|
|
3049
|
+
let successDrawing = false;
|
|
3050
|
+
if (isDrawingTo) {
|
|
3051
|
+
successDrawing = !!(draggingPort && // 同一条线条则不用在判断 canAddLine
|
|
3052
|
+
(originLine?.toPort === draggingPort || draggingPort.portType === "input" && this.linesManager.canAddLine(line.fromPort, draggingPort, true)));
|
|
3053
|
+
} else {
|
|
3054
|
+
successDrawing = !!(draggingPort && // 同一条线条则不用在判断 canAddLine
|
|
3055
|
+
(originLine?.fromPort === draggingPort || draggingPort.portType === "output" && this.linesManager.canAddLine(draggingPort, line.toPort, true)));
|
|
3056
|
+
}
|
|
3057
|
+
if (successDrawing) {
|
|
3058
|
+
this.hoverService.updateHoveredKey(draggingPort.id);
|
|
3059
|
+
if (isDrawingTo) {
|
|
3060
|
+
line.setToPort(draggingPort);
|
|
3061
|
+
} else {
|
|
3062
|
+
line.setFromPort(draggingPort);
|
|
3063
|
+
}
|
|
3002
3064
|
this._onDragLineEventEmitter.fire({
|
|
3003
3065
|
type: "onDrag",
|
|
3004
|
-
onDragNodeId:
|
|
3066
|
+
onDragNodeId: draggingNode.id
|
|
3005
3067
|
});
|
|
3006
3068
|
return {
|
|
3007
3069
|
hasError: false
|
|
3008
3070
|
};
|
|
3009
|
-
} else if (this.isContainer(
|
|
3071
|
+
} else if (this.isContainer(draggingNode)) {
|
|
3010
3072
|
return {
|
|
3011
3073
|
hasError: false
|
|
3012
3074
|
};
|
|
@@ -3058,7 +3120,7 @@ var WorkflowDragService = class {
|
|
|
3058
3120
|
return;
|
|
3059
3121
|
}
|
|
3060
3122
|
const sourceContainer = nodes[0]?.parent;
|
|
3061
|
-
if (!sourceContainer) {
|
|
3123
|
+
if (!sourceContainer || sourceContainer.flowNodeType === import_document10.FlowNodeBaseType.ROOT) {
|
|
3062
3124
|
return;
|
|
3063
3125
|
}
|
|
3064
3126
|
const valid = nodes.every((node) => node?.parent === sourceContainer);
|
|
@@ -3072,16 +3134,18 @@ var WorkflowDragService = class {
|
|
|
3072
3134
|
* @param opts
|
|
3073
3135
|
* @param event
|
|
3074
3136
|
*/
|
|
3075
|
-
async startDrawingLine(
|
|
3076
|
-
const
|
|
3077
|
-
|
|
3137
|
+
async startDrawingLine(port, event, originLine) {
|
|
3138
|
+
const isDrawingTo = port.portType === "output";
|
|
3139
|
+
const isInActivePort = !originLine && port.isErrorPort() && port.disabled;
|
|
3140
|
+
if (originLine?.disabled || isInActivePort || this.playgroundConfig.readonly || this.playgroundConfig.disabled) {
|
|
3078
3141
|
return { dragSuccess: false, newLine: void 0 };
|
|
3079
3142
|
}
|
|
3080
3143
|
this.selectService.clear();
|
|
3081
3144
|
const config = this.playgroundConfig;
|
|
3082
3145
|
const deferred = new import_utils16.PromiseDeferred();
|
|
3083
3146
|
const preCursor = config.cursor;
|
|
3084
|
-
let line
|
|
3147
|
+
let line;
|
|
3148
|
+
let newLineInfo;
|
|
3085
3149
|
const startTime = Date.now();
|
|
3086
3150
|
let dragSuccess = false;
|
|
3087
3151
|
const dragger = new import_core15.PlaygroundDrag({
|
|
@@ -3092,16 +3156,29 @@ var WorkflowDragService = class {
|
|
|
3092
3156
|
}
|
|
3093
3157
|
dragSuccess = true;
|
|
3094
3158
|
const pos = config.getPosFromMouseEvent(event);
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3159
|
+
if (isDrawingTo) {
|
|
3160
|
+
line = this.linesManager.createLine({
|
|
3161
|
+
from: port.node.id,
|
|
3162
|
+
fromPort: port.portID,
|
|
3163
|
+
data: originLine?.lineData,
|
|
3164
|
+
drawingTo: {
|
|
3165
|
+
x: pos.x,
|
|
3166
|
+
y: pos.y,
|
|
3167
|
+
location: port.location === "right" ? "left" : "top"
|
|
3168
|
+
}
|
|
3169
|
+
});
|
|
3170
|
+
} else {
|
|
3171
|
+
line = this.linesManager.createLine({
|
|
3172
|
+
to: port.node.id,
|
|
3173
|
+
toPort: port.portID,
|
|
3174
|
+
data: originLine?.lineData,
|
|
3175
|
+
drawingFrom: {
|
|
3176
|
+
x: pos.x,
|
|
3177
|
+
y: pos.y,
|
|
3178
|
+
location: port.location === "left" ? "right" : "bottom"
|
|
3179
|
+
}
|
|
3180
|
+
});
|
|
3181
|
+
}
|
|
3105
3182
|
if (!line) {
|
|
3106
3183
|
return;
|
|
3107
3184
|
}
|
|
@@ -3112,49 +3189,15 @@ var WorkflowDragService = class {
|
|
|
3112
3189
|
if (!line) {
|
|
3113
3190
|
return;
|
|
3114
3191
|
}
|
|
3115
|
-
lineErrorReset = false;
|
|
3116
3192
|
const dragPos = config.getPosFromMouseEvent(e);
|
|
3117
|
-
|
|
3118
|
-
toPort = this.linesManager.getPortFromMousePos(dragPos);
|
|
3119
|
-
if (!toPort) {
|
|
3120
|
-
line.setToPort(void 0);
|
|
3121
|
-
} else if (!this.linesManager.canAddLine(fromPort, toPort, true)) {
|
|
3122
|
-
line.highlightColor = this.linesManager.lineColor.error;
|
|
3123
|
-
lineErrorReset = true;
|
|
3124
|
-
line.setToPort(void 0);
|
|
3125
|
-
} else {
|
|
3126
|
-
line.setToPort(toPort);
|
|
3127
|
-
}
|
|
3128
|
-
this._onDragLineEventEmitter.fire({
|
|
3129
|
-
type: "onDrag"
|
|
3130
|
-
});
|
|
3131
|
-
this.setLineColor(line, originLine?.lockedColor || this.linesManager.lineColor.drawing);
|
|
3132
|
-
if (toNode && this.canBuildContainerLine(toNode, dragPos)) {
|
|
3133
|
-
toPort = this.getNearestPort(toNode, dragPos);
|
|
3134
|
-
const { hasError } = this.handleDragOnNode(toNode, fromPort, line, toPort, originLine);
|
|
3135
|
-
lineErrorReset = hasError;
|
|
3136
|
-
}
|
|
3137
|
-
if (line.toPort) {
|
|
3138
|
-
line.drawingTo = {
|
|
3139
|
-
x: line.toPort.point.x,
|
|
3140
|
-
y: line.toPort.point.y,
|
|
3141
|
-
location: line.toPort.location
|
|
3142
|
-
};
|
|
3143
|
-
} else {
|
|
3144
|
-
line.drawingTo = {
|
|
3145
|
-
x: dragPos.x,
|
|
3146
|
-
y: dragPos.y,
|
|
3147
|
-
location: reverseLocation(line.fromPort.location)
|
|
3148
|
-
};
|
|
3149
|
-
}
|
|
3150
|
-
originLine?.validate();
|
|
3151
|
-
line.validate();
|
|
3193
|
+
newLineInfo = this.updateDrawingLine(isDrawingTo, line, dragPos, originLine);
|
|
3152
3194
|
},
|
|
3153
3195
|
// eslint-disable-next-line complexity
|
|
3154
3196
|
onDragEnd: async (e) => {
|
|
3155
3197
|
const dragPos = config.getPosFromMouseEvent(e);
|
|
3156
3198
|
const onDragLineEndCallbacks = Array.from(this._onDragLineEndCallbacks.values());
|
|
3157
3199
|
config.updateCursor(preCursor);
|
|
3200
|
+
const { fromPort, toPort, hasError } = newLineInfo || {};
|
|
3158
3201
|
await Promise.all(
|
|
3159
3202
|
onDragLineEndCallbacks.map(
|
|
3160
3203
|
(callback) => callback({
|
|
@@ -3179,36 +3222,32 @@ var WorkflowDragService = class {
|
|
|
3179
3222
|
deferred.resolve({ dragSuccess });
|
|
3180
3223
|
};
|
|
3181
3224
|
if (dragSuccess) {
|
|
3182
|
-
if (originLine && originLine.toPort === toPort) {
|
|
3225
|
+
if (originLine && originLine.toPort === toPort && originLine.fromPort === fromPort) {
|
|
3183
3226
|
return end();
|
|
3184
3227
|
}
|
|
3185
|
-
if (toPort && toPort.portType !== "input") {
|
|
3228
|
+
if (toPort && toPort.portType !== "input" || fromPort && fromPort.portType !== "output") {
|
|
3186
3229
|
return end();
|
|
3187
3230
|
}
|
|
3188
|
-
const
|
|
3231
|
+
const newLinePortInfo = toPort && fromPort ? {
|
|
3189
3232
|
from: fromPort.node.id,
|
|
3190
3233
|
fromPort: fromPort.portID,
|
|
3191
3234
|
to: toPort.node.id,
|
|
3192
3235
|
toPort: toPort.portID,
|
|
3193
3236
|
data: originLine?.lineData
|
|
3194
3237
|
} : void 0;
|
|
3195
|
-
const isReset = originLine &&
|
|
3196
|
-
if (isReset && !this.linesManager.canReset(
|
|
3197
|
-
originLine.fromPort,
|
|
3198
|
-
originLine.toPort,
|
|
3199
|
-
toPort
|
|
3200
|
-
)) {
|
|
3238
|
+
const isReset = originLine && newLinePortInfo;
|
|
3239
|
+
if (isReset && !this.linesManager.canReset(originLine, newLinePortInfo)) {
|
|
3201
3240
|
return end();
|
|
3202
3241
|
}
|
|
3203
|
-
if (originLine && (!this.linesManager.canRemove(originLine,
|
|
3242
|
+
if (originLine && (!this.linesManager.canRemove(originLine, newLinePortInfo, false) || hasError)) {
|
|
3204
3243
|
return end();
|
|
3205
3244
|
} else {
|
|
3206
3245
|
originLine?.dispose();
|
|
3207
3246
|
}
|
|
3208
|
-
if (!
|
|
3247
|
+
if (!newLinePortInfo || !this.linesManager.canAddLine(fromPort, toPort, false)) {
|
|
3209
3248
|
return end();
|
|
3210
3249
|
}
|
|
3211
|
-
const newLine = this.linesManager.createLine(
|
|
3250
|
+
const newLine = this.linesManager.createLine(newLinePortInfo);
|
|
3212
3251
|
if (!newLine) {
|
|
3213
3252
|
end();
|
|
3214
3253
|
}
|
|
@@ -3225,14 +3264,109 @@ var WorkflowDragService = class {
|
|
|
3225
3264
|
await dragger.start(clientX, clientY, config);
|
|
3226
3265
|
return deferred.promise;
|
|
3227
3266
|
}
|
|
3267
|
+
updateDrawingLine(isDrawingTo, line, dragPos, originLine) {
|
|
3268
|
+
let hasError = false;
|
|
3269
|
+
const mouseNode = this.linesManager.getNodeFromMousePos(dragPos);
|
|
3270
|
+
let toNode;
|
|
3271
|
+
let toPort;
|
|
3272
|
+
let fromPort;
|
|
3273
|
+
let fromNode;
|
|
3274
|
+
if (isDrawingTo) {
|
|
3275
|
+
fromPort = line.fromPort;
|
|
3276
|
+
toNode = mouseNode;
|
|
3277
|
+
toPort = this.linesManager.getPortFromMousePos(dragPos, "input");
|
|
3278
|
+
if (toNode && this.canBuildContainerLine(toNode, dragPos)) {
|
|
3279
|
+
toPort = this.getNearestPort(toNode, dragPos, "input");
|
|
3280
|
+
hasError = this.checkDraggingPort(isDrawingTo, line, toNode, toPort, originLine).hasError;
|
|
3281
|
+
}
|
|
3282
|
+
if (!toPort) {
|
|
3283
|
+
line.setToPort(void 0);
|
|
3284
|
+
} else if (!this.linesManager.canAddLine(fromPort, toPort, true)) {
|
|
3285
|
+
hasError = true;
|
|
3286
|
+
line.setToPort(void 0);
|
|
3287
|
+
} else {
|
|
3288
|
+
line.setToPort(toPort);
|
|
3289
|
+
}
|
|
3290
|
+
if (line.toPort) {
|
|
3291
|
+
line.drawingTo = {
|
|
3292
|
+
x: line.toPort.point.x,
|
|
3293
|
+
y: line.toPort.point.y,
|
|
3294
|
+
location: line.toPort.location
|
|
3295
|
+
};
|
|
3296
|
+
} else {
|
|
3297
|
+
line.drawingTo = {
|
|
3298
|
+
x: dragPos.x,
|
|
3299
|
+
y: dragPos.y,
|
|
3300
|
+
location: reverseLocation(line.fromPort.location)
|
|
3301
|
+
};
|
|
3302
|
+
}
|
|
3303
|
+
} else {
|
|
3304
|
+
toPort = line.toPort;
|
|
3305
|
+
fromNode = mouseNode;
|
|
3306
|
+
fromPort = this.linesManager.getPortFromMousePos(dragPos, "output");
|
|
3307
|
+
if (fromNode && this.canBuildContainerLine(fromNode, dragPos)) {
|
|
3308
|
+
fromPort = this.getNearestPort(fromNode, dragPos, "output");
|
|
3309
|
+
hasError = this.checkDraggingPort(
|
|
3310
|
+
isDrawingTo,
|
|
3311
|
+
line,
|
|
3312
|
+
fromNode,
|
|
3313
|
+
fromPort,
|
|
3314
|
+
originLine
|
|
3315
|
+
).hasError;
|
|
3316
|
+
}
|
|
3317
|
+
if (!fromPort) {
|
|
3318
|
+
line.setFromPort(void 0);
|
|
3319
|
+
} else if (!this.linesManager.canAddLine(fromPort, toPort, true)) {
|
|
3320
|
+
hasError = true;
|
|
3321
|
+
line.setFromPort(void 0);
|
|
3322
|
+
} else {
|
|
3323
|
+
line.setFromPort(fromPort);
|
|
3324
|
+
}
|
|
3325
|
+
if (line.fromPort) {
|
|
3326
|
+
line.drawingFrom = {
|
|
3327
|
+
x: line.fromPort.point.x,
|
|
3328
|
+
y: line.fromPort.point.y,
|
|
3329
|
+
location: line.fromPort.location
|
|
3330
|
+
};
|
|
3331
|
+
} else {
|
|
3332
|
+
line.drawingFrom = {
|
|
3333
|
+
x: dragPos.x,
|
|
3334
|
+
y: dragPos.y,
|
|
3335
|
+
location: reverseLocation(line.toPort.location)
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
this._onDragLineEventEmitter.fire({
|
|
3340
|
+
type: "onDrag"
|
|
3341
|
+
});
|
|
3342
|
+
if (hasError) {
|
|
3343
|
+
this.setLineColor(line, this.linesManager.lineColor.error);
|
|
3344
|
+
} else {
|
|
3345
|
+
this.setLineColor(line, originLine?.lockedColor || this.linesManager.lineColor.drawing);
|
|
3346
|
+
}
|
|
3347
|
+
originLine?.validate();
|
|
3348
|
+
line.validate();
|
|
3349
|
+
return {
|
|
3350
|
+
fromPort,
|
|
3351
|
+
toPort,
|
|
3352
|
+
hasError
|
|
3353
|
+
};
|
|
3354
|
+
}
|
|
3228
3355
|
/**
|
|
3229
3356
|
* 重新连接线条
|
|
3230
3357
|
* @param line
|
|
3231
3358
|
* @param e
|
|
3232
3359
|
*/
|
|
3233
3360
|
async resetLine(line, e) {
|
|
3234
|
-
const { fromPort } = line;
|
|
3235
|
-
const
|
|
3361
|
+
const { fromPort, toPort } = line;
|
|
3362
|
+
const mousePos = this.playgroundConfig.getPosFromMouseEvent(e);
|
|
3363
|
+
const distanceFrom = import_utils16.Point.getDistance(fromPort.point, mousePos);
|
|
3364
|
+
const distanceTo = import_utils16.Point.getDistance(toPort.point, mousePos);
|
|
3365
|
+
const { dragSuccess } = await this.startDrawingLine(
|
|
3366
|
+
distanceTo <= distanceFrom || !this.document.options.twoWayConnection ? fromPort : toPort,
|
|
3367
|
+
e,
|
|
3368
|
+
line
|
|
3369
|
+
);
|
|
3236
3370
|
if (!dragSuccess) {
|
|
3237
3371
|
this.selectService.select(line);
|
|
3238
3372
|
}
|
|
@@ -3254,17 +3388,27 @@ var WorkflowDragService = class {
|
|
|
3254
3388
|
return true;
|
|
3255
3389
|
}
|
|
3256
3390
|
const { padding, bounds } = node.transform;
|
|
3257
|
-
const
|
|
3258
|
-
|
|
3391
|
+
const DEFAULT_DELTA = 10;
|
|
3392
|
+
const leftDelta = padding.left * 2 / 3 || DEFAULT_DELTA;
|
|
3393
|
+
const rightDelta = padding.right * 2 / 3 || DEFAULT_DELTA;
|
|
3394
|
+
const bottomDelta = padding.bottom * 2 / 3 || DEFAULT_DELTA;
|
|
3395
|
+
const topDelta = padding.top * 2 / 3 || DEFAULT_DELTA;
|
|
3396
|
+
const rectangles = [
|
|
3397
|
+
new import_utils16.Rectangle(bounds.x, bounds.y, leftDelta, bounds.height),
|
|
3398
|
+
// left
|
|
3399
|
+
new import_utils16.Rectangle(bounds.x, bounds.y, bounds.width, topDelta),
|
|
3400
|
+
// top
|
|
3401
|
+
new import_utils16.Rectangle(bounds.x, bounds.y + bounds.height - bottomDelta, bounds.width, bottomDelta),
|
|
3402
|
+
// bottom
|
|
3403
|
+
new import_utils16.Rectangle(bounds.x + bounds.width - rightDelta, bounds.y, rightDelta, bounds.height)
|
|
3404
|
+
// right
|
|
3405
|
+
];
|
|
3406
|
+
return rectangles.some((rect) => rect.contains(mousePos.x, mousePos.y));
|
|
3259
3407
|
}
|
|
3260
3408
|
/** 获取最近的 port */
|
|
3261
|
-
getNearestPort(node, mousePos) {
|
|
3409
|
+
getNearestPort(node, mousePos, portType = "input") {
|
|
3262
3410
|
const portsData = node.ports;
|
|
3263
|
-
const distanceSortedPorts = portsData.inputPorts.sort((a, b) =>
|
|
3264
|
-
const aDistance = Math.abs(mousePos.y - a.point.y);
|
|
3265
|
-
const bDistance = Math.abs(mousePos.y - b.point.y);
|
|
3266
|
-
return aDistance - bDistance;
|
|
3267
|
-
});
|
|
3411
|
+
const distanceSortedPorts = (portType === "input" ? portsData.inputPorts : portsData.outputPorts).sort((a, b) => import_utils16.Point.getDistance(mousePos, a.point) - import_utils16.Point.getDistance(mousePos, b.point));
|
|
3268
3412
|
return distanceSortedPorts[0];
|
|
3269
3413
|
}
|
|
3270
3414
|
};
|