@flowgram.ai/document 0.1.0-alpha.3 → 0.1.0-alpha.31
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 +718 -547
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +268 -74
- package/dist/index.d.ts +268 -74
- package/dist/index.js +722 -551
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/esm/index.js
CHANGED
|
@@ -22,11 +22,19 @@ var FlowNodeBaseType = /* @__PURE__ */ ((FlowNodeBaseType2) => {
|
|
|
22
22
|
FlowNodeBaseType2["BLOCK_ORDER_ICON"] = "blockOrderIcon";
|
|
23
23
|
FlowNodeBaseType2["GROUP"] = "group";
|
|
24
24
|
FlowNodeBaseType2["END"] = "end";
|
|
25
|
+
FlowNodeBaseType2["BREAK"] = "break";
|
|
25
26
|
FlowNodeBaseType2["CONDITION"] = "condition";
|
|
26
27
|
FlowNodeBaseType2["SUB_CANVAS"] = "subCanvas";
|
|
28
|
+
FlowNodeBaseType2["MULTI_INPUTS"] = "multiInputs";
|
|
29
|
+
FlowNodeBaseType2["MULTI_OUTPUTS"] = "multiOutputs";
|
|
30
|
+
FlowNodeBaseType2["INPUT"] = "input";
|
|
31
|
+
FlowNodeBaseType2["OUTPUT"] = "output";
|
|
32
|
+
FlowNodeBaseType2["SLOT"] = "slot";
|
|
33
|
+
FlowNodeBaseType2["SLOT_BLOCK"] = "slotBlock";
|
|
27
34
|
return FlowNodeBaseType2;
|
|
28
35
|
})(FlowNodeBaseType || {});
|
|
29
36
|
var FlowNodeSplitType = /* @__PURE__ */ ((FlowNodeSplitType2) => {
|
|
37
|
+
FlowNodeSplitType2["SIMPLE_SPLIT"] = "simpleSplit";
|
|
30
38
|
FlowNodeSplitType2["DYNAMIC_SPLIT"] = "dynamicSplit";
|
|
31
39
|
FlowNodeSplitType2["STATIC_SPLIT"] = "staticSplit";
|
|
32
40
|
return FlowNodeSplitType2;
|
|
@@ -82,6 +90,14 @@ var DefaultSpacingKey = {
|
|
|
82
90
|
* 普通节点间距。垂直 / 水平
|
|
83
91
|
*/
|
|
84
92
|
NODE_SPACING: "SPACING",
|
|
93
|
+
/**
|
|
94
|
+
* 分支节点间距
|
|
95
|
+
*/
|
|
96
|
+
BRANCH_SPACING: "BRANCH_SPACING",
|
|
97
|
+
/**
|
|
98
|
+
* 圆弧线条拐角 radius
|
|
99
|
+
*/
|
|
100
|
+
ROUNDED_LINE_RADIUS: "ROUNDED_LINE_RADIUS",
|
|
85
101
|
/**
|
|
86
102
|
* 圆弧线条 x radius
|
|
87
103
|
*/
|
|
@@ -108,13 +124,19 @@ var DEFAULT_SPACING = {
|
|
|
108
124
|
NULL: 0,
|
|
109
125
|
[DefaultSpacingKey.NODE_SPACING]: 32,
|
|
110
126
|
// 普通节点间距。垂直 / 水平
|
|
127
|
+
[DefaultSpacingKey.BRANCH_SPACING]: 20,
|
|
128
|
+
// 分支节点间距
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated use 'BRANCH_SPACING' instead
|
|
131
|
+
*/
|
|
111
132
|
MARGIN_RIGHT: 20,
|
|
112
|
-
//
|
|
133
|
+
// 分支节点右边间距
|
|
113
134
|
INLINE_BLOCK_PADDING_BOTTOM: 16,
|
|
114
135
|
// block 底部留白
|
|
115
136
|
INLINE_BLOCKS_PADDING_TOP: 30,
|
|
116
137
|
// block list 上部留白间距
|
|
117
|
-
|
|
138
|
+
// JS 浮点数有误差,1046.6 -1006.6 = 39.9999999,会导致 间距/20 < 2 导致布局计算问题,因此需要额外增加 0.1 像素
|
|
139
|
+
[DefaultSpacingKey.INLINE_BLOCKS_PADDING_BOTTOM]: 40.1,
|
|
118
140
|
// block lit 下部留白间距,因为有两个拐弯,所以翻一倍
|
|
119
141
|
MIN_INLINE_BLOCK_SPACING: 200,
|
|
120
142
|
// 分支间最小边距 (垂直布局)
|
|
@@ -122,6 +144,8 @@ var DEFAULT_SPACING = {
|
|
|
122
144
|
// 分支间最小边距 (水平布局)
|
|
123
145
|
[DefaultSpacingKey.COLLAPSED_SPACING]: 12,
|
|
124
146
|
// 复合节点距离上个节点的距离
|
|
147
|
+
[DefaultSpacingKey.ROUNDED_LINE_RADIUS]: 16,
|
|
148
|
+
// 圆弧线条拐角 radius
|
|
125
149
|
[DefaultSpacingKey.ROUNDED_LINE_X_RADIUS]: 16,
|
|
126
150
|
// 圆弧线条 x radius
|
|
127
151
|
[DefaultSpacingKey.ROUNDED_LINE_Y_RADIUS]: 20,
|
|
@@ -149,8 +173,6 @@ var DEFAULT_FLOW_NODE_META = (nodeType, document) => {
|
|
|
149
173
|
isStart: nodeType === "start",
|
|
150
174
|
hidden,
|
|
151
175
|
defaultExpanded: document.options.allNodesDefaultExpanded,
|
|
152
|
-
expandedSize: { width: 520, height: 300 },
|
|
153
|
-
// 展开后的大小
|
|
154
176
|
size: DEFAULT_SIZE,
|
|
155
177
|
origin: document.layout.getDefaultNodeOrigin(),
|
|
156
178
|
isInlineBlocks: nodeType === "inlineBlocks" /* INLINE_BLOCKS */,
|
|
@@ -170,13 +192,37 @@ var DEFAULT_FLOW_NODE_META = (nodeType, document) => {
|
|
|
170
192
|
};
|
|
171
193
|
var FlowNodeRegistry;
|
|
172
194
|
((FlowNodeRegistry4) => {
|
|
195
|
+
function mergeChildRegistries(r1 = [], r2 = []) {
|
|
196
|
+
if (r1.length === 0 || r2.length === 0) {
|
|
197
|
+
return [...r1, ...r2];
|
|
198
|
+
}
|
|
199
|
+
const r1Filter = r1.map((r1Current) => {
|
|
200
|
+
const r2Current = r2.find((n) => n.type === r1Current.type);
|
|
201
|
+
if (r2Current) {
|
|
202
|
+
return merge(r1Current, r2Current, r1Current.type);
|
|
203
|
+
}
|
|
204
|
+
return r1Current;
|
|
205
|
+
});
|
|
206
|
+
const r2Filter = r2.filter((n) => !r1.some((r) => r.type === n.type));
|
|
207
|
+
return [...r1Filter, ...r2Filter];
|
|
208
|
+
}
|
|
209
|
+
FlowNodeRegistry4.mergeChildRegistries = mergeChildRegistries;
|
|
173
210
|
function merge(registry1, registry2, finalType) {
|
|
211
|
+
const extendKeys = registry1.__extends__ ? registry1.__extends__.slice() : [];
|
|
212
|
+
if (registry1.type !== registry2.type) {
|
|
213
|
+
extendKeys.unshift(registry1.type);
|
|
214
|
+
}
|
|
174
215
|
return {
|
|
175
216
|
...registry1,
|
|
176
217
|
...registry2,
|
|
218
|
+
extendChildRegistries: mergeChildRegistries(
|
|
219
|
+
registry1.extendChildRegistries,
|
|
220
|
+
registry2.extendChildRegistries
|
|
221
|
+
),
|
|
177
222
|
meta: { ...registry1.meta, ...registry2.meta },
|
|
178
223
|
extend: void 0,
|
|
179
|
-
type: finalType
|
|
224
|
+
type: finalType,
|
|
225
|
+
__extends__: extendKeys
|
|
180
226
|
};
|
|
181
227
|
}
|
|
182
228
|
FlowNodeRegistry4.merge = merge;
|
|
@@ -200,7 +246,6 @@ var OperationType = /* @__PURE__ */ ((OperationType2) => {
|
|
|
200
246
|
OperationType2["moveChildNodes"] = "moveChildNodes";
|
|
201
247
|
OperationType2["addNodes"] = "addNodes";
|
|
202
248
|
OperationType2["deleteNodes"] = "deleteNodes";
|
|
203
|
-
OperationType2["changeNode"] = "changeNode";
|
|
204
249
|
OperationType2["addChildNode"] = "addChildNode";
|
|
205
250
|
OperationType2["deleteChildNode"] = "deleteChildNode";
|
|
206
251
|
OperationType2["addNode"] = "addNode";
|
|
@@ -245,16 +290,18 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends EntityData {
|
|
|
245
290
|
expanded: defaultExpanded || false,
|
|
246
291
|
activated: false,
|
|
247
292
|
hovered: false,
|
|
248
|
-
dragging: false
|
|
293
|
+
dragging: false,
|
|
294
|
+
stackIndex: 0
|
|
249
295
|
};
|
|
250
296
|
}
|
|
251
|
-
updateExtInfo(info) {
|
|
252
|
-
|
|
253
|
-
|
|
297
|
+
updateExtInfo(info, fullUpdate) {
|
|
298
|
+
const oldInfo = this.data.extInfo;
|
|
299
|
+
const newInfo = fullUpdate ? info : { ...oldInfo, ...info };
|
|
300
|
+
if (Compare.isChanged(oldInfo, newInfo)) {
|
|
254
301
|
this.update({
|
|
255
|
-
extInfo:
|
|
302
|
+
extInfo: newInfo
|
|
256
303
|
});
|
|
257
|
-
this.onExtInfoChangeEmitter.fire({ oldInfo, newInfo
|
|
304
|
+
this.onExtInfoChangeEmitter.fire({ oldInfo, newInfo });
|
|
258
305
|
}
|
|
259
306
|
}
|
|
260
307
|
getExtInfo() {
|
|
@@ -351,6 +398,12 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends EntityData {
|
|
|
351
398
|
}
|
|
352
399
|
return this.data.activated;
|
|
353
400
|
}
|
|
401
|
+
get stackIndex() {
|
|
402
|
+
return this.data.stackIndex;
|
|
403
|
+
}
|
|
404
|
+
set stackIndex(index) {
|
|
405
|
+
this.data.stackIndex = index;
|
|
406
|
+
}
|
|
354
407
|
get lineActivated() {
|
|
355
408
|
const { activated } = this;
|
|
356
409
|
if (!activated) return false;
|
|
@@ -400,10 +453,9 @@ var _FlowNodeTransformData = class _FlowNodeTransformData extends EntityData2 {
|
|
|
400
453
|
return this.entity.id;
|
|
401
454
|
}
|
|
402
455
|
getDefaultData() {
|
|
403
|
-
const { size,
|
|
404
|
-
const defaultSize = defaultExpanded ? expandedSize : size;
|
|
456
|
+
const { size, hidden } = this.entity.getNodeMeta();
|
|
405
457
|
return {
|
|
406
|
-
size: !hidden ? { ...
|
|
458
|
+
size: !hidden ? { ...size } : { width: 0, height: 0 }
|
|
407
459
|
};
|
|
408
460
|
}
|
|
409
461
|
/**
|
|
@@ -434,6 +486,11 @@ var _FlowNodeTransformData = class _FlowNodeTransformData extends EntityData2 {
|
|
|
434
486
|
y: position.y
|
|
435
487
|
};
|
|
436
488
|
}
|
|
489
|
+
set position(position) {
|
|
490
|
+
this.transform.update({
|
|
491
|
+
position
|
|
492
|
+
});
|
|
493
|
+
}
|
|
437
494
|
set size(size) {
|
|
438
495
|
const { width, height } = this.data.size;
|
|
439
496
|
if (this.isContainer) return;
|
|
@@ -642,8 +699,9 @@ var drawLineToNext = (transition) => {
|
|
|
642
699
|
var drawLineToBottom = (transition) => {
|
|
643
700
|
const { transform } = transition;
|
|
644
701
|
const currentOutput = transform.outputPoint;
|
|
702
|
+
const isParentRoot = transform.parent?.entity.flowNodeType === "root" /* ROOT */;
|
|
645
703
|
const parentOutput = transform.parent?.outputPoint;
|
|
646
|
-
if (!transform.next && parentOutput && !new Point().copyFrom(currentOutput).equals(parentOutput) && !transition.isNodeEnd) {
|
|
704
|
+
if (!isParentRoot && !transform.next && parentOutput && !new Point().copyFrom(currentOutput).equals(parentOutput) && !transition.isNodeEnd) {
|
|
647
705
|
return [
|
|
648
706
|
{
|
|
649
707
|
type: 0 /* STRAIGHT_LINE */,
|
|
@@ -981,37 +1039,7 @@ var FlowNodeEntity = class extends Entity {
|
|
|
981
1039
|
* @param newId
|
|
982
1040
|
*/
|
|
983
1041
|
toJSON() {
|
|
984
|
-
|
|
985
|
-
return this.document.options.toNodeJSON(this);
|
|
986
|
-
}
|
|
987
|
-
const nodesMap = {};
|
|
988
|
-
let startNodeJSON;
|
|
989
|
-
this.document.traverse((node) => {
|
|
990
|
-
const isSystemNode = node.id.startsWith("$");
|
|
991
|
-
if (isSystemNode) return;
|
|
992
|
-
const nodeJSONData = this.getJSONData();
|
|
993
|
-
const nodeJSON = {
|
|
994
|
-
id: node.id,
|
|
995
|
-
type: node.flowNodeType
|
|
996
|
-
};
|
|
997
|
-
if (nodeJSONData !== void 0) {
|
|
998
|
-
nodeJSON.data = nodeJSONData;
|
|
999
|
-
}
|
|
1000
|
-
if (!startNodeJSON) startNodeJSON = nodeJSON;
|
|
1001
|
-
let { parent } = node;
|
|
1002
|
-
if (parent && parent.id.startsWith("$")) {
|
|
1003
|
-
parent = parent.originParent;
|
|
1004
|
-
}
|
|
1005
|
-
const parentJSON = parent ? nodesMap[parent.id] : void 0;
|
|
1006
|
-
if (parentJSON) {
|
|
1007
|
-
if (!parentJSON.blocks) {
|
|
1008
|
-
parentJSON.blocks = [];
|
|
1009
|
-
}
|
|
1010
|
-
parentJSON.blocks.push(nodeJSON);
|
|
1011
|
-
}
|
|
1012
|
-
nodesMap[node.id] = nodeJSON;
|
|
1013
|
-
}, this);
|
|
1014
|
-
return startNodeJSON;
|
|
1042
|
+
return this.document.toNodeJSON(this);
|
|
1015
1043
|
}
|
|
1016
1044
|
get isVertical() {
|
|
1017
1045
|
return this.document.layout.name === "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
|
|
@@ -1020,8 +1048,8 @@ var FlowNodeEntity = class extends Entity {
|
|
|
1020
1048
|
* 修改节点扩展信息
|
|
1021
1049
|
* @param info
|
|
1022
1050
|
*/
|
|
1023
|
-
updateExtInfo(extInfo) {
|
|
1024
|
-
this.getData(FlowNodeRenderData).updateExtInfo(extInfo);
|
|
1051
|
+
updateExtInfo(extInfo, fullUpdate) {
|
|
1052
|
+
this.getData(FlowNodeRenderData).updateExtInfo(extInfo, fullUpdate);
|
|
1025
1053
|
}
|
|
1026
1054
|
/**
|
|
1027
1055
|
* 获取节点扩展信息
|
|
@@ -1050,6 +1078,19 @@ var FlowNodeEntity = class extends Entity {
|
|
|
1050
1078
|
get bounds() {
|
|
1051
1079
|
return this.transform.bounds;
|
|
1052
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Check node extend type
|
|
1083
|
+
*/
|
|
1084
|
+
isExtend(parentType) {
|
|
1085
|
+
return this.document.isExtend(this.flowNodeType, parentType);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Check node type
|
|
1089
|
+
* @param parentType
|
|
1090
|
+
*/
|
|
1091
|
+
isTypeOrExtendType(parentType) {
|
|
1092
|
+
return this.document.isTypeOrExtendType(this.flowNodeType, parentType);
|
|
1093
|
+
}
|
|
1053
1094
|
};
|
|
1054
1095
|
FlowNodeEntity.type = "FlowNodeEntity";
|
|
1055
1096
|
((FlowNodeEntity2) => {
|
|
@@ -1143,7 +1184,7 @@ var FlowDocumentTransformerEntity = class extends ConfigEntity {
|
|
|
1143
1184
|
FlowDocumentTransformerEntity.type = "FlowDocumentTransformerEntity";
|
|
1144
1185
|
|
|
1145
1186
|
// src/entities/flow-renderer-state-entity.ts
|
|
1146
|
-
import { debounce } from "lodash";
|
|
1187
|
+
import { debounce } from "lodash-es";
|
|
1147
1188
|
import { ConfigEntity as ConfigEntity2 } from "@flowgram.ai/core";
|
|
1148
1189
|
var FlowRendererStateEntity = class extends ConfigEntity2 {
|
|
1149
1190
|
getDefaultConfig() {
|
|
@@ -1160,6 +1201,22 @@ var FlowRendererStateEntity = class extends ConfigEntity2 {
|
|
|
1160
1201
|
nodeHoveredId: node?.id
|
|
1161
1202
|
});
|
|
1162
1203
|
}
|
|
1204
|
+
get dragging() {
|
|
1205
|
+
return this.config.dragging;
|
|
1206
|
+
}
|
|
1207
|
+
setDragging(dragging) {
|
|
1208
|
+
this.updateConfig({
|
|
1209
|
+
dragging
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
get isBranch() {
|
|
1213
|
+
return this.config.isBranch;
|
|
1214
|
+
}
|
|
1215
|
+
setIsBranch(isBranch) {
|
|
1216
|
+
this.updateConfig({
|
|
1217
|
+
isBranch
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1163
1220
|
getDragLabelSide() {
|
|
1164
1221
|
return this.config.dragLabelSide;
|
|
1165
1222
|
}
|
|
@@ -1204,7 +1261,7 @@ var FlowRendererStateEntity = class extends ConfigEntity2 {
|
|
|
1204
1261
|
FlowRendererStateEntity.type = "FlowRendererStateEntity";
|
|
1205
1262
|
|
|
1206
1263
|
// src/flow-document.ts
|
|
1207
|
-
import { omit } from "lodash";
|
|
1264
|
+
import { omit } from "lodash-es";
|
|
1208
1265
|
import { inject as inject2, injectable as injectable2, multiInject, optional as optional2, postConstruct } from "inversify";
|
|
1209
1266
|
import { Emitter as Emitter5 } from "@flowgram.ai/utils";
|
|
1210
1267
|
import { EntityManager } from "@flowgram.ai/core";
|
|
@@ -1382,13 +1439,15 @@ var FlowVirtualTree = class _FlowVirtualTree {
|
|
|
1382
1439
|
get size() {
|
|
1383
1440
|
return this.map.size;
|
|
1384
1441
|
}
|
|
1385
|
-
toString() {
|
|
1442
|
+
toString(showType) {
|
|
1386
1443
|
const ret = [];
|
|
1387
1444
|
this.traverse((node, depth) => {
|
|
1388
1445
|
if (depth === 0) {
|
|
1389
1446
|
ret.push(node.id);
|
|
1390
1447
|
} else {
|
|
1391
|
-
ret.push(
|
|
1448
|
+
ret.push(
|
|
1449
|
+
`|${new Array(depth).fill("--").join("")} ${showType ? `${node.flowNodeType}(${node.id})` : node.id}`
|
|
1450
|
+
);
|
|
1392
1451
|
}
|
|
1393
1452
|
});
|
|
1394
1453
|
return `${ret.join("\n")}`;
|
|
@@ -1594,7 +1653,12 @@ var ConstantKeys = {
|
|
|
1594
1653
|
/***
|
|
1595
1654
|
* 线条、label 激活后的颜色
|
|
1596
1655
|
*/
|
|
1597
|
-
BASE_ACTIVATED_COLOR: "BASE_ACTIVATED_COLOR"
|
|
1656
|
+
BASE_ACTIVATED_COLOR: "BASE_ACTIVATED_COLOR",
|
|
1657
|
+
/**
|
|
1658
|
+
* Branch bottom margin
|
|
1659
|
+
* 分支下边距
|
|
1660
|
+
*/
|
|
1661
|
+
INLINE_BLOCKS_PADDING_TOP: "INLINE_BLOCKS_PADDING_TOP"
|
|
1598
1662
|
};
|
|
1599
1663
|
|
|
1600
1664
|
// src/flow-document-contribution.ts
|
|
@@ -1649,6 +1713,13 @@ var FlowDocument = class {
|
|
|
1649
1713
|
this.onNodeCreate = this.onNodeCreateEmitter.event;
|
|
1650
1714
|
this.onNodeDispose = this.onNodeDisposeEmitter.event;
|
|
1651
1715
|
this.onLayoutChange = this.onLayoutChangeEmitter.event;
|
|
1716
|
+
this._disposed = false;
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
*
|
|
1720
|
+
*/
|
|
1721
|
+
get disposed() {
|
|
1722
|
+
return this._disposed;
|
|
1652
1723
|
}
|
|
1653
1724
|
init() {
|
|
1654
1725
|
if (!this.options) this.options = FlowDocumentOptionsDefault;
|
|
@@ -1674,6 +1745,7 @@ var FlowDocument = class {
|
|
|
1674
1745
|
* @param fireRender 是否要触发渲染,默认 true
|
|
1675
1746
|
*/
|
|
1676
1747
|
fromJSON(json, fireRender = true) {
|
|
1748
|
+
if (this._disposed) return;
|
|
1677
1749
|
this.originTree.clear();
|
|
1678
1750
|
this.renderTree.clear();
|
|
1679
1751
|
this.entityManager.changeEntityLocked = true;
|
|
@@ -1742,7 +1814,7 @@ var FlowDocument = class {
|
|
|
1742
1814
|
* @param data
|
|
1743
1815
|
* @param addedNodes
|
|
1744
1816
|
*/
|
|
1745
|
-
addNode(data, addedNodes
|
|
1817
|
+
addNode(data, addedNodes) {
|
|
1746
1818
|
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1747
1819
|
let node = this.getNode(id);
|
|
1748
1820
|
let isNew = false;
|
|
@@ -1760,13 +1832,14 @@ var FlowDocument = class {
|
|
|
1760
1832
|
originParent,
|
|
1761
1833
|
meta
|
|
1762
1834
|
});
|
|
1835
|
+
this.options.preNodeCreate?.(node);
|
|
1763
1836
|
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
1764
1837
|
node.addInitializeData(datas);
|
|
1765
1838
|
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
1766
|
-
|
|
1767
|
-
this.options.fromNodeJSON(node, data);
|
|
1768
|
-
}
|
|
1839
|
+
this.options.fromNodeJSON?.(node, data, true);
|
|
1769
1840
|
isNew = true;
|
|
1841
|
+
} else {
|
|
1842
|
+
this.options.fromNodeJSON?.(node, data, false);
|
|
1770
1843
|
}
|
|
1771
1844
|
node.initData({
|
|
1772
1845
|
originParent,
|
|
@@ -1778,7 +1851,6 @@ var FlowDocument = class {
|
|
|
1778
1851
|
if (node.isStart) {
|
|
1779
1852
|
this.root.addChild(node);
|
|
1780
1853
|
}
|
|
1781
|
-
this.onNodeUpdateEmitter.fire({ node, data });
|
|
1782
1854
|
addedNodes?.push(node);
|
|
1783
1855
|
if (register.onCreate) {
|
|
1784
1856
|
const extendNodes = register.onCreate(node, data);
|
|
@@ -1792,11 +1864,14 @@ var FlowDocument = class {
|
|
|
1792
1864
|
this.addBlocksAsChildren(node, data.blocks, addedNodes);
|
|
1793
1865
|
}
|
|
1794
1866
|
}
|
|
1795
|
-
if (isNew
|
|
1867
|
+
if (isNew) {
|
|
1796
1868
|
this.onNodeCreateEmitter.fire({
|
|
1797
1869
|
node,
|
|
1798
|
-
data
|
|
1870
|
+
data,
|
|
1871
|
+
json: data
|
|
1799
1872
|
});
|
|
1873
|
+
} else {
|
|
1874
|
+
this.onNodeUpdateEmitter.fire({ node, data, json: data });
|
|
1800
1875
|
}
|
|
1801
1876
|
return node;
|
|
1802
1877
|
}
|
|
@@ -1832,18 +1907,16 @@ var FlowDocument = class {
|
|
|
1832
1907
|
parent: node
|
|
1833
1908
|
});
|
|
1834
1909
|
addedNodes.push(blockIconNode);
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
});
|
|
1846
|
-
}
|
|
1910
|
+
const inlineBlocksNode = this.addNode({
|
|
1911
|
+
id: `$inlineBlocks$${node.id}`,
|
|
1912
|
+
type: "inlineBlocks" /* INLINE_BLOCKS */,
|
|
1913
|
+
originParent: node,
|
|
1914
|
+
parent: node
|
|
1915
|
+
});
|
|
1916
|
+
addedNodes.push(inlineBlocksNode);
|
|
1917
|
+
blocks.forEach((blockData) => {
|
|
1918
|
+
this.addBlock(node, blockData, addedNodes);
|
|
1919
|
+
});
|
|
1847
1920
|
return addedNodes;
|
|
1848
1921
|
}
|
|
1849
1922
|
/**
|
|
@@ -1908,14 +1981,39 @@ var FlowDocument = class {
|
|
|
1908
1981
|
meta: {
|
|
1909
1982
|
...preRegistry?.meta,
|
|
1910
1983
|
...newRegistry?.meta
|
|
1911
|
-
}
|
|
1984
|
+
},
|
|
1985
|
+
extendChildRegistries: FlowNodeRegistry.mergeChildRegistries(
|
|
1986
|
+
preRegistry?.extendChildRegistries,
|
|
1987
|
+
newRegistry?.extendChildRegistries
|
|
1988
|
+
)
|
|
1912
1989
|
});
|
|
1913
1990
|
});
|
|
1914
1991
|
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Check node extend
|
|
1994
|
+
* @param currentType
|
|
1995
|
+
* @param extendType
|
|
1996
|
+
*/
|
|
1997
|
+
isExtend(currentType, extendType) {
|
|
1998
|
+
return (this.getNodeRegistry(currentType).__extends__ || []).includes(extendType);
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Check node type
|
|
2002
|
+
* @param currentType
|
|
2003
|
+
* @param extendType
|
|
2004
|
+
*/
|
|
2005
|
+
isTypeOrExtendType(currentType, extendType) {
|
|
2006
|
+
return currentType === extendType || this.isExtend(currentType, extendType);
|
|
2007
|
+
}
|
|
1915
2008
|
/**
|
|
1916
2009
|
* 导出数据,可以重载
|
|
1917
2010
|
*/
|
|
1918
2011
|
toJSON() {
|
|
2012
|
+
if (this.disposed) {
|
|
2013
|
+
throw new Error(
|
|
2014
|
+
"The FlowDocument has been disposed and it is no longer possible to call toJSON."
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
1919
2017
|
return {
|
|
1920
2018
|
nodes: this.root.toJSON().blocks
|
|
1921
2019
|
};
|
|
@@ -1935,6 +2033,7 @@ var FlowDocument = class {
|
|
|
1935
2033
|
const customDefaultRegistry = this.options.getNodeDefaultRegistry?.(type);
|
|
1936
2034
|
let register = this.registers.get(type) || { type };
|
|
1937
2035
|
const extendRegisters = [];
|
|
2036
|
+
const extendKey = register.extend;
|
|
1938
2037
|
if (register.extend && this.registers.has(register.extend)) {
|
|
1939
2038
|
register = FlowNodeRegistry.merge(
|
|
1940
2039
|
this.getNodeRegistry(register.extend),
|
|
@@ -1965,6 +2064,9 @@ var FlowDocument = class {
|
|
|
1965
2064
|
...register.meta
|
|
1966
2065
|
}
|
|
1967
2066
|
};
|
|
2067
|
+
if (extendKey) {
|
|
2068
|
+
res.extend = extendKey;
|
|
2069
|
+
}
|
|
1968
2070
|
this.nodeRegistryCache.set(typeKey, res);
|
|
1969
2071
|
return res;
|
|
1970
2072
|
}
|
|
@@ -2015,8 +2117,8 @@ var FlowDocument = class {
|
|
|
2015
2117
|
getAllNodes() {
|
|
2016
2118
|
return this.entityManager.getEntities(FlowNodeEntity);
|
|
2017
2119
|
}
|
|
2018
|
-
toString() {
|
|
2019
|
-
return this.originTree.toString();
|
|
2120
|
+
toString(showType) {
|
|
2121
|
+
return this.originTree.toString(showType);
|
|
2020
2122
|
}
|
|
2021
2123
|
/**
|
|
2022
2124
|
* 返回需要渲染的数据
|
|
@@ -2029,6 +2131,39 @@ var FlowDocument = class {
|
|
|
2029
2131
|
});
|
|
2030
2132
|
return result;
|
|
2031
2133
|
}
|
|
2134
|
+
toNodeJSON(node) {
|
|
2135
|
+
if (this.options.toNodeJSON) {
|
|
2136
|
+
return this.options.toNodeJSON(node);
|
|
2137
|
+
}
|
|
2138
|
+
const nodesMap = {};
|
|
2139
|
+
let startNodeJSON;
|
|
2140
|
+
this.traverse((node2) => {
|
|
2141
|
+
const isSystemNode = node2.id.startsWith("$");
|
|
2142
|
+
if (isSystemNode) return;
|
|
2143
|
+
const nodeJSONData = node2.getJSONData();
|
|
2144
|
+
const nodeJSON = {
|
|
2145
|
+
id: node2.id,
|
|
2146
|
+
type: node2.flowNodeType
|
|
2147
|
+
};
|
|
2148
|
+
if (nodeJSONData !== void 0) {
|
|
2149
|
+
nodeJSON.data = nodeJSONData;
|
|
2150
|
+
}
|
|
2151
|
+
if (!startNodeJSON) startNodeJSON = nodeJSON;
|
|
2152
|
+
let { parent } = node2;
|
|
2153
|
+
if (parent && parent.id.startsWith("$")) {
|
|
2154
|
+
parent = parent.originParent;
|
|
2155
|
+
}
|
|
2156
|
+
const parentJSON = parent ? nodesMap[parent.id] : void 0;
|
|
2157
|
+
if (parentJSON) {
|
|
2158
|
+
if (!parentJSON.blocks) {
|
|
2159
|
+
parentJSON.blocks = [];
|
|
2160
|
+
}
|
|
2161
|
+
parentJSON.blocks.push(nodeJSON);
|
|
2162
|
+
}
|
|
2163
|
+
nodesMap[node2.id] = nodeJSON;
|
|
2164
|
+
}, node);
|
|
2165
|
+
return startNodeJSON;
|
|
2166
|
+
}
|
|
2032
2167
|
/**
|
|
2033
2168
|
* 移动节点
|
|
2034
2169
|
* @param param0
|
|
@@ -2111,6 +2246,7 @@ var FlowDocument = class {
|
|
|
2111
2246
|
);
|
|
2112
2247
|
}
|
|
2113
2248
|
dispose() {
|
|
2249
|
+
if (this._disposed) return;
|
|
2114
2250
|
this.registers.clear();
|
|
2115
2251
|
this.nodeRegistryCache.clear();
|
|
2116
2252
|
this.originTree.dispose();
|
|
@@ -2119,6 +2255,7 @@ var FlowDocument = class {
|
|
|
2119
2255
|
this.onNodeCreateEmitter.dispose();
|
|
2120
2256
|
this.onNodeDisposeEmitter.dispose();
|
|
2121
2257
|
this.onLayoutChangeEmitter.dispose();
|
|
2258
|
+
this._disposed = true;
|
|
2122
2259
|
}
|
|
2123
2260
|
};
|
|
2124
2261
|
__decorateClass([
|
|
@@ -2146,113 +2283,427 @@ FlowDocument = __decorateClass([
|
|
|
2146
2283
|
import { ContainerModule } from "inversify";
|
|
2147
2284
|
|
|
2148
2285
|
// src/services/flow-drag-service.ts
|
|
2149
|
-
import { inject as
|
|
2150
|
-
import {
|
|
2151
|
-
import { Emitter as Emitter7 } from "@flowgram.ai/utils";
|
|
2152
|
-
|
|
2153
|
-
// src/services/flow-operation-base-service.ts
|
|
2154
|
-
import { inject as inject3, injectable as injectable3, postConstruct as postConstruct2 } from "inversify";
|
|
2155
|
-
import { DisposableCollection, Emitter as Emitter6 } from "@flowgram.ai/utils";
|
|
2286
|
+
import { inject as inject3, injectable as injectable3 } from "inversify";
|
|
2287
|
+
import { Emitter as Emitter6 } from "@flowgram.ai/utils";
|
|
2156
2288
|
import { EntityManager as EntityManager2 } from "@flowgram.ai/core";
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
this.
|
|
2289
|
+
|
|
2290
|
+
// src/services/flow-group-service/flow-group-controller.ts
|
|
2291
|
+
var FlowGroupController = class _FlowGroupController {
|
|
2292
|
+
constructor(groupNode) {
|
|
2293
|
+
this.groupNode = groupNode;
|
|
2162
2294
|
}
|
|
2163
|
-
|
|
2164
|
-
this.
|
|
2295
|
+
get nodes() {
|
|
2296
|
+
return this.groupNode.collapsedChildren || [];
|
|
2165
2297
|
}
|
|
2166
|
-
|
|
2167
|
-
const
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2298
|
+
get collapsed() {
|
|
2299
|
+
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2300
|
+
return groupTransformData.collapsed;
|
|
2301
|
+
}
|
|
2302
|
+
collapse() {
|
|
2303
|
+
this.collapsed = true;
|
|
2304
|
+
}
|
|
2305
|
+
expand() {
|
|
2306
|
+
this.collapsed = false;
|
|
2307
|
+
}
|
|
2308
|
+
/** 获取分组外围的最大边框 */
|
|
2309
|
+
get bounds() {
|
|
2310
|
+
const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
|
|
2311
|
+
return groupNodeBounds;
|
|
2312
|
+
}
|
|
2313
|
+
/** 是否是开始节点 */
|
|
2314
|
+
isStartNode(node) {
|
|
2315
|
+
if (!node) {
|
|
2316
|
+
return false;
|
|
2171
2317
|
}
|
|
2172
|
-
|
|
2173
|
-
if (
|
|
2174
|
-
|
|
2318
|
+
const nodes = this.nodes;
|
|
2319
|
+
if (!nodes[0]) {
|
|
2320
|
+
return false;
|
|
2175
2321
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
parent: parentEntity,
|
|
2183
|
-
index,
|
|
2184
|
-
hidden
|
|
2185
|
-
};
|
|
2186
|
-
let added;
|
|
2187
|
-
if (parentEntity && register?.addChild) {
|
|
2188
|
-
added = register.addChild(parentEntity, addJSON, {
|
|
2189
|
-
index,
|
|
2190
|
-
hidden
|
|
2191
|
-
});
|
|
2192
|
-
} else {
|
|
2193
|
-
added = this.document.addNode(addNodeData);
|
|
2322
|
+
return node.id === nodes[0].id;
|
|
2323
|
+
}
|
|
2324
|
+
/** 是否是结束节点 */
|
|
2325
|
+
isEndNode(node) {
|
|
2326
|
+
if (!node) {
|
|
2327
|
+
return false;
|
|
2194
2328
|
}
|
|
2195
|
-
this.
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
}
|
|
2199
|
-
return
|
|
2329
|
+
const nodes = this.nodes;
|
|
2330
|
+
if (!nodes[nodes.length - 1]) {
|
|
2331
|
+
return false;
|
|
2332
|
+
}
|
|
2333
|
+
return node.id === nodes[nodes.length - 1].id;
|
|
2200
2334
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2335
|
+
set note(note) {
|
|
2336
|
+
this.groupNode.getNodeMeta().note = note;
|
|
2203
2337
|
}
|
|
2204
|
-
|
|
2205
|
-
this.
|
|
2338
|
+
get note() {
|
|
2339
|
+
return this.groupNode.getNodeMeta().note || "";
|
|
2206
2340
|
}
|
|
2207
|
-
|
|
2208
|
-
(
|
|
2209
|
-
this.deleteNode(node);
|
|
2210
|
-
});
|
|
2341
|
+
set noteHeight(height) {
|
|
2342
|
+
this.groupNode.getNodeMeta().noteHeight = height;
|
|
2211
2343
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
return this.document.addBlock(target, blockJSON, void 0, parent, index);
|
|
2344
|
+
get noteHeight() {
|
|
2345
|
+
return this.groupNode.getNodeMeta().noteHeight || 0;
|
|
2215
2346
|
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2347
|
+
get positionConfig() {
|
|
2348
|
+
return this.groupNode.getNodeMeta().positionConfig;
|
|
2349
|
+
}
|
|
2350
|
+
set collapsed(collapsed) {
|
|
2351
|
+
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2352
|
+
groupTransformData.collapsed = collapsed;
|
|
2353
|
+
groupTransformData.localDirty = true;
|
|
2354
|
+
if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
|
|
2355
|
+
if (groupTransformData.parent?.firstChild)
|
|
2356
|
+
groupTransformData.parent.firstChild.localDirty = true;
|
|
2357
|
+
}
|
|
2358
|
+
set hovered(hovered) {
|
|
2359
|
+
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2360
|
+
if (hovered) {
|
|
2361
|
+
groupRenderData.toggleMouseEnter();
|
|
2362
|
+
} else {
|
|
2363
|
+
groupRenderData.toggleMouseLeave();
|
|
2222
2364
|
}
|
|
2223
|
-
|
|
2224
|
-
if (!newParentEntity) {
|
|
2225
|
-
console.warn("no new parent found", newParent);
|
|
2365
|
+
if (groupRenderData.hovered === hovered) {
|
|
2226
2366
|
return;
|
|
2227
2367
|
}
|
|
2228
|
-
|
|
2229
|
-
return this.doMoveNode(entity, newParentEntity, toIndex);
|
|
2368
|
+
groupRenderData.hovered = hovered;
|
|
2230
2369
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
if (nodes.length === 0) {
|
|
2370
|
+
get hovered() {
|
|
2371
|
+
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2372
|
+
return groupRenderData.hovered;
|
|
2373
|
+
}
|
|
2374
|
+
static create(groupNode) {
|
|
2375
|
+
if (!groupNode) {
|
|
2238
2376
|
return;
|
|
2239
2377
|
}
|
|
2240
|
-
|
|
2241
|
-
const fromParent = startNode.parent;
|
|
2242
|
-
const toParent = dropNode.parent;
|
|
2243
|
-
if (!fromParent || !toParent) {
|
|
2378
|
+
if (!FlowGroupUtils.isGroupNode(groupNode)) {
|
|
2244
2379
|
return;
|
|
2245
2380
|
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2381
|
+
return new _FlowGroupController(groupNode);
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
|
|
2385
|
+
// src/services/flow-group-service/flow-group-utils.ts
|
|
2386
|
+
var FlowGroupUtils;
|
|
2387
|
+
((FlowGroupUtils2) => {
|
|
2388
|
+
const findNodeParents = (node) => {
|
|
2389
|
+
const parents = [];
|
|
2390
|
+
let parent = node.parent;
|
|
2391
|
+
while (parent) {
|
|
2392
|
+
parents.push(parent);
|
|
2393
|
+
parent = parent.parent;
|
|
2394
|
+
}
|
|
2395
|
+
return parents;
|
|
2396
|
+
};
|
|
2397
|
+
const isNodeInGroup = (node) => {
|
|
2398
|
+
if (node?.parent?.flowNodeType === "group" /* GROUP */) {
|
|
2399
|
+
return true;
|
|
2400
|
+
}
|
|
2401
|
+
return false;
|
|
2402
|
+
};
|
|
2403
|
+
FlowGroupUtils2.validate = (nodes) => {
|
|
2404
|
+
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2405
|
+
return false;
|
|
2406
|
+
}
|
|
2407
|
+
const isGroupRelatedNode = nodes.some((node) => (0, FlowGroupUtils2.isGroupNode)(node));
|
|
2408
|
+
if (isGroupRelatedNode) return false;
|
|
2409
|
+
const hasGroup = nodes.some((node) => node && isNodeInGroup(node));
|
|
2410
|
+
if (hasGroup) return false;
|
|
2411
|
+
const parent = nodes[0].parent;
|
|
2412
|
+
const isSameParent = nodes.every((node) => node.parent === parent);
|
|
2413
|
+
if (!isSameParent) return false;
|
|
2414
|
+
const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
|
|
2415
|
+
const isIndexContinuous = indexes.every((index, i, arr) => {
|
|
2416
|
+
if (i === 0) {
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2419
|
+
return index === arr[i - 1] + 1;
|
|
2420
|
+
});
|
|
2421
|
+
if (!isIndexContinuous) return false;
|
|
2422
|
+
const parents = findNodeParents(nodes[0]);
|
|
2423
|
+
const parentsInGroup = parents.some((parent2) => isNodeInGroup(parent2));
|
|
2424
|
+
if (parentsInGroup) return false;
|
|
2425
|
+
return true;
|
|
2426
|
+
};
|
|
2427
|
+
FlowGroupUtils2.getNodeGroupController = (node) => {
|
|
2428
|
+
if (!node) {
|
|
2429
|
+
return;
|
|
2430
|
+
}
|
|
2431
|
+
if (!isNodeInGroup(node)) {
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
const groupNode = node?.parent;
|
|
2435
|
+
return FlowGroupController.create(groupNode);
|
|
2436
|
+
};
|
|
2437
|
+
FlowGroupUtils2.getNodeRecursionGroupController = (node) => {
|
|
2438
|
+
if (!node) {
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
const group = (0, FlowGroupUtils2.getNodeGroupController)(node);
|
|
2442
|
+
if (group) {
|
|
2443
|
+
return group;
|
|
2444
|
+
}
|
|
2445
|
+
if (node.parent) {
|
|
2446
|
+
return (0, FlowGroupUtils2.getNodeRecursionGroupController)(node.parent);
|
|
2447
|
+
}
|
|
2448
|
+
return;
|
|
2449
|
+
};
|
|
2450
|
+
FlowGroupUtils2.isGroupNode = (group) => group.flowNodeType === "group" /* GROUP */;
|
|
2451
|
+
})(FlowGroupUtils || (FlowGroupUtils = {}));
|
|
2452
|
+
|
|
2453
|
+
// src/services/flow-drag-service.ts
|
|
2454
|
+
var FlowDragService = class {
|
|
2455
|
+
constructor() {
|
|
2456
|
+
this.onDropEmitter = new Emitter6();
|
|
2457
|
+
this.onDrop = this.onDropEmitter.event;
|
|
2458
|
+
}
|
|
2459
|
+
get renderState() {
|
|
2460
|
+
return this.document.renderState;
|
|
2461
|
+
}
|
|
2462
|
+
// 拖拽所有节点中的首个节点
|
|
2463
|
+
get dragStartNode() {
|
|
2464
|
+
return this.renderState.getDragStartEntity();
|
|
2465
|
+
}
|
|
2466
|
+
// 拖拽的所有节点
|
|
2467
|
+
get dragNodes() {
|
|
2468
|
+
return this.renderState.getDragEntities();
|
|
2469
|
+
}
|
|
2470
|
+
// 放置的区域
|
|
2471
|
+
get dropNodeId() {
|
|
2472
|
+
return this.renderState.getNodeDroppingId();
|
|
2473
|
+
}
|
|
2474
|
+
// 是否在拖拽分支
|
|
2475
|
+
get isDragBranch() {
|
|
2476
|
+
return this.renderState.isBranch || this.dragStartNode?.isInlineBlock;
|
|
2477
|
+
}
|
|
2478
|
+
// 拖拽的所有节点及其自节点
|
|
2479
|
+
get nodeDragIdsWithChildren() {
|
|
2480
|
+
return this.renderState.config.nodeDragIdsWithChildren || [];
|
|
2481
|
+
}
|
|
2482
|
+
get dragging() {
|
|
2483
|
+
return !!this.renderState.dragging;
|
|
2484
|
+
}
|
|
2485
|
+
get labelSide() {
|
|
2486
|
+
return this.renderState.config.dragLabelSide;
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* 放置到目标分支
|
|
2490
|
+
*/
|
|
2491
|
+
dropBranch() {
|
|
2492
|
+
this.dropNode();
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* 移动并且创建节点
|
|
2496
|
+
* Move and create node
|
|
2497
|
+
*/
|
|
2498
|
+
async dropCreateNode(json, onCreateNode) {
|
|
2499
|
+
const dropEntity = this.document.getNode(this.dropNodeId);
|
|
2500
|
+
if (!dropEntity) {
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
if (json) {
|
|
2504
|
+
const dragNodes = await onCreateNode?.(json, dropEntity);
|
|
2505
|
+
this.onDropEmitter.fire({
|
|
2506
|
+
dropNode: dropEntity,
|
|
2507
|
+
dragNodes: dragNodes ? [dragNodes] : [],
|
|
2508
|
+
dragJSON: json
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* 移动到目标节点
|
|
2514
|
+
*/
|
|
2515
|
+
dropNode() {
|
|
2516
|
+
const dropEntity = this.document.getNode(this.dropNodeId);
|
|
2517
|
+
if (!dropEntity) {
|
|
2518
|
+
return;
|
|
2519
|
+
}
|
|
2520
|
+
const sortNodes = [];
|
|
2521
|
+
let curr = this.dragStartNode;
|
|
2522
|
+
while (curr && this.dragNodes.includes(curr)) {
|
|
2523
|
+
sortNodes.push(curr);
|
|
2524
|
+
curr = curr.next;
|
|
2525
|
+
}
|
|
2526
|
+
this.operationService.dragNodes({
|
|
2527
|
+
dropNode: dropEntity,
|
|
2528
|
+
nodes: sortNodes
|
|
2529
|
+
});
|
|
2530
|
+
if (sortNodes.length > 0) {
|
|
2531
|
+
this.onDropEmitter.fire({
|
|
2532
|
+
dropNode: dropEntity,
|
|
2533
|
+
dragNodes: sortNodes
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
/**
|
|
2538
|
+
* 拖拽是否可以释放在该节点后面
|
|
2539
|
+
*/
|
|
2540
|
+
isDroppableNode(node) {
|
|
2541
|
+
if (!this.dragging || this.isDragBranch) {
|
|
2542
|
+
return false;
|
|
2543
|
+
}
|
|
2544
|
+
if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
|
|
2545
|
+
return false;
|
|
2546
|
+
}
|
|
2547
|
+
if (node.isInlineBlocks || node.isInlineBlock) {
|
|
2548
|
+
return false;
|
|
2549
|
+
}
|
|
2550
|
+
const hasGroupNode = this.dragNodes.some(
|
|
2551
|
+
(node2) => node2.flowNodeType === "group" /* GROUP */
|
|
2552
|
+
);
|
|
2553
|
+
if (hasGroupNode) {
|
|
2554
|
+
const group = FlowGroupUtils.getNodeRecursionGroupController(node);
|
|
2555
|
+
if (group) {
|
|
2556
|
+
return false;
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
return true;
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* 拖拽分支是否可以释放在该分支
|
|
2563
|
+
* @param node 拖拽的分支节点
|
|
2564
|
+
* @param side 分支的前面还是后面
|
|
2565
|
+
*/
|
|
2566
|
+
isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
|
|
2567
|
+
if (this.renderState.isBranch) {
|
|
2568
|
+
return true;
|
|
2569
|
+
}
|
|
2570
|
+
if (this.isDragBranch) {
|
|
2571
|
+
if (
|
|
2572
|
+
// 拖拽到分支
|
|
2573
|
+
!node.isInlineBlock || // 只能在同一分支条件下
|
|
2574
|
+
node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
|
|
2575
|
+
node === this.dragStartNode
|
|
2576
|
+
) {
|
|
2577
|
+
return false;
|
|
2578
|
+
}
|
|
2579
|
+
if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
|
|
2580
|
+
return true;
|
|
2581
|
+
}
|
|
2582
|
+
if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
|
|
2583
|
+
return true;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
return false;
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
__decorateClass([
|
|
2590
|
+
inject3(FlowDocument)
|
|
2591
|
+
], FlowDragService.prototype, "document", 2);
|
|
2592
|
+
__decorateClass([
|
|
2593
|
+
inject3(FlowOperationBaseService)
|
|
2594
|
+
], FlowDragService.prototype, "operationService", 2);
|
|
2595
|
+
__decorateClass([
|
|
2596
|
+
inject3(EntityManager2)
|
|
2597
|
+
], FlowDragService.prototype, "entityManager", 2);
|
|
2598
|
+
FlowDragService = __decorateClass([
|
|
2599
|
+
injectable3()
|
|
2600
|
+
], FlowDragService);
|
|
2601
|
+
|
|
2602
|
+
// src/services/flow-operation-base-service.ts
|
|
2603
|
+
import { inject as inject4, injectable as injectable4, postConstruct as postConstruct2 } from "inversify";
|
|
2604
|
+
import { DisposableCollection, Emitter as Emitter7 } from "@flowgram.ai/utils";
|
|
2605
|
+
import { EntityManager as EntityManager3 } from "@flowgram.ai/core";
|
|
2606
|
+
var FlowOperationBaseServiceImpl = class {
|
|
2607
|
+
constructor() {
|
|
2608
|
+
this.onNodeAddEmitter = new Emitter7();
|
|
2609
|
+
this.onNodeAdd = this.onNodeAddEmitter.event;
|
|
2610
|
+
this.toDispose = new DisposableCollection();
|
|
2611
|
+
this.onNodeMoveEmitter = new Emitter7();
|
|
2612
|
+
this.onNodeMove = this.onNodeMoveEmitter.event;
|
|
2613
|
+
}
|
|
2614
|
+
init() {
|
|
2615
|
+
this.toDispose.pushAll([this.onNodeAddEmitter, this.onNodeMoveEmitter]);
|
|
2616
|
+
}
|
|
2617
|
+
addNode(nodeJSON, config = {}) {
|
|
2618
|
+
const { parent, index, hidden } = config;
|
|
2619
|
+
let parentEntity;
|
|
2620
|
+
if (parent) {
|
|
2621
|
+
parentEntity = this.toNodeEntity(parent);
|
|
2622
|
+
}
|
|
2623
|
+
let register;
|
|
2624
|
+
if (parentEntity) {
|
|
2625
|
+
register = parentEntity.getNodeRegistry();
|
|
2626
|
+
}
|
|
2627
|
+
const addJSON = {
|
|
2628
|
+
...nodeJSON,
|
|
2629
|
+
type: nodeJSON.type || "block" /* BLOCK */
|
|
2630
|
+
};
|
|
2631
|
+
const addNodeData = {
|
|
2632
|
+
...addJSON,
|
|
2633
|
+
parent: parentEntity,
|
|
2634
|
+
index,
|
|
2635
|
+
hidden
|
|
2636
|
+
};
|
|
2637
|
+
let added;
|
|
2638
|
+
if (parentEntity && register?.addChild) {
|
|
2639
|
+
added = register.addChild(parentEntity, addJSON, {
|
|
2640
|
+
index,
|
|
2641
|
+
hidden
|
|
2642
|
+
});
|
|
2643
|
+
} else {
|
|
2644
|
+
added = this.document.addNode(addNodeData);
|
|
2645
|
+
}
|
|
2646
|
+
this.onNodeAddEmitter.fire({
|
|
2647
|
+
node: added,
|
|
2648
|
+
data: addNodeData
|
|
2649
|
+
});
|
|
2650
|
+
return added;
|
|
2651
|
+
}
|
|
2652
|
+
addFromNode(fromNode, nodeJSON) {
|
|
2653
|
+
return this.document.addFromNode(fromNode, nodeJSON);
|
|
2654
|
+
}
|
|
2655
|
+
deleteNode(node) {
|
|
2656
|
+
this.document.removeNode(node);
|
|
2657
|
+
}
|
|
2658
|
+
deleteNodes(nodes) {
|
|
2659
|
+
(nodes || []).forEach((node) => {
|
|
2660
|
+
this.deleteNode(node);
|
|
2661
|
+
});
|
|
2662
|
+
}
|
|
2663
|
+
addBlock(target, blockJSON, config = {}) {
|
|
2664
|
+
const { parent, index } = config;
|
|
2665
|
+
return this.document.addBlock(target, blockJSON, void 0, parent, index);
|
|
2666
|
+
}
|
|
2667
|
+
moveNode(node, config = {}) {
|
|
2668
|
+
const { parent: newParent, index } = config;
|
|
2669
|
+
const entity = this.toNodeEntity(node);
|
|
2670
|
+
const parent = entity?.parent;
|
|
2671
|
+
if (!parent) {
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2674
|
+
const newParentEntity = newParent ? this.toNodeEntity(newParent) : parent;
|
|
2675
|
+
if (!newParentEntity) {
|
|
2676
|
+
console.warn("no new parent found", newParent);
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2679
|
+
let toIndex = typeof index === "undefined" ? newParentEntity.collapsedChildren.length : index;
|
|
2680
|
+
return this.doMoveNode(entity, newParentEntity, toIndex);
|
|
2681
|
+
}
|
|
2682
|
+
/**
|
|
2683
|
+
* 拖拽节点
|
|
2684
|
+
* @param param0
|
|
2685
|
+
* @returns
|
|
2686
|
+
*/
|
|
2687
|
+
dragNodes({ dropNode, nodes }) {
|
|
2688
|
+
if (nodes.length === 0) {
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
const startNode = nodes[0];
|
|
2692
|
+
const fromParent = startNode.parent;
|
|
2693
|
+
const toParent = dropNode.parent;
|
|
2694
|
+
if (!fromParent || !toParent) {
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2697
|
+
const fromIndex = fromParent.children.findIndex((child) => child === startNode);
|
|
2698
|
+
const dropIndex = toParent.children.findIndex((child) => child === dropNode);
|
|
2699
|
+
let toIndex = dropIndex + 1;
|
|
2700
|
+
if (fromParent === toParent && fromIndex < dropIndex) {
|
|
2701
|
+
toIndex = toIndex - nodes.length;
|
|
2702
|
+
}
|
|
2703
|
+
const value = {
|
|
2704
|
+
nodeIds: nodes.map((node) => node.id),
|
|
2705
|
+
fromParentId: fromParent.id,
|
|
2706
|
+
toParentId: toParent.id,
|
|
2256
2707
|
fromIndex,
|
|
2257
2708
|
toIndex
|
|
2258
2709
|
};
|
|
@@ -2369,418 +2820,138 @@ var FlowOperationBaseServiceImpl = class {
|
|
|
2369
2820
|
toNodeEntity(node) {
|
|
2370
2821
|
return typeof node === "string" ? this.document.getNode(node) : node;
|
|
2371
2822
|
}
|
|
2372
|
-
getNodeIndex(node) {
|
|
2373
|
-
const entity = this.toNodeEntity(node);
|
|
2374
|
-
const parent = entity?.parent;
|
|
2375
|
-
if (!parent) {
|
|
2376
|
-
return -1;
|
|
2377
|
-
}
|
|
2378
|
-
return parent.children.findIndex((child) => child === entity);
|
|
2379
|
-
}
|
|
2380
|
-
doMoveNode(node, newParent, index) {
|
|
2381
|
-
return this.document.moveChildNodes({
|
|
2382
|
-
nodeIds: [this.toId(node)],
|
|
2383
|
-
toParentId: this.toId(newParent),
|
|
2384
|
-
toIndex: index
|
|
2385
|
-
});
|
|
2386
|
-
}
|
|
2387
|
-
};
|
|
2388
|
-
__decorateClass([
|
|
2389
|
-
inject3(EntityManager2)
|
|
2390
|
-
], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
|
|
2391
|
-
__decorateClass([
|
|
2392
|
-
inject3(FlowDocument)
|
|
2393
|
-
], FlowOperationBaseServiceImpl.prototype, "document", 2);
|
|
2394
|
-
__decorateClass([
|
|
2395
|
-
postConstruct2()
|
|
2396
|
-
], FlowOperationBaseServiceImpl.prototype, "init", 1);
|
|
2397
|
-
FlowOperationBaseServiceImpl = __decorateClass([
|
|
2398
|
-
injectable3()
|
|
2399
|
-
], FlowOperationBaseServiceImpl);
|
|
2400
|
-
|
|
2401
|
-
// src/services/flow-group-service.ts
|
|
2402
|
-
import { nanoid } from "nanoid";
|
|
2403
|
-
import { inject as inject4, injectable as injectable4 } from "inversify";
|
|
2404
|
-
import { EntityManager as EntityManager3 } from "@flowgram.ai/core";
|
|
2405
|
-
var FlowGroupService = class {
|
|
2406
|
-
/** 创建分组节点 */
|
|
2407
|
-
createGroup(nodes) {
|
|
2408
|
-
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2409
|
-
return;
|
|
2410
|
-
}
|
|
2411
|
-
if (!FlowGroupController.validate(nodes)) {
|
|
2412
|
-
return;
|
|
2413
|
-
}
|
|
2414
|
-
const sortedNodes = nodes.sort((a, b) => a.index - b.index);
|
|
2415
|
-
const fromNode = sortedNodes[0];
|
|
2416
|
-
const groupId = `group_${nanoid(5)}`;
|
|
2417
|
-
this.operationService.apply({
|
|
2418
|
-
type: "createGroup" /* createGroup */,
|
|
2419
|
-
value: {
|
|
2420
|
-
targetId: fromNode.id,
|
|
2421
|
-
groupId,
|
|
2422
|
-
nodeIds: nodes.map((node) => node.id)
|
|
2423
|
-
}
|
|
2424
|
-
});
|
|
2425
|
-
const groupNode = this.entityManager.getEntityById(groupId);
|
|
2426
|
-
if (!groupNode) {
|
|
2427
|
-
return;
|
|
2428
|
-
}
|
|
2429
|
-
const group = this.groupController(groupNode);
|
|
2430
|
-
if (!group) {
|
|
2431
|
-
return;
|
|
2432
|
-
}
|
|
2433
|
-
group.expand();
|
|
2434
|
-
return groupNode;
|
|
2435
|
-
}
|
|
2436
|
-
/** 删除分组 */
|
|
2437
|
-
deleteGroup(groupNode) {
|
|
2438
|
-
const json = groupNode.toJSON();
|
|
2439
|
-
if (!groupNode.pre || !json) {
|
|
2440
|
-
return;
|
|
2441
|
-
}
|
|
2442
|
-
this.operationService.apply({
|
|
2443
|
-
type: "deleteNodes" /* deleteNodes */,
|
|
2444
|
-
value: {
|
|
2445
|
-
fromId: groupNode.pre.id,
|
|
2446
|
-
nodes: [json]
|
|
2447
|
-
}
|
|
2448
|
-
});
|
|
2449
|
-
}
|
|
2450
|
-
/** 取消分组 */
|
|
2451
|
-
ungroup(groupNode) {
|
|
2452
|
-
const group = this.groupController(groupNode);
|
|
2453
|
-
if (!group) {
|
|
2454
|
-
return;
|
|
2455
|
-
}
|
|
2456
|
-
const nodes = group.nodes;
|
|
2457
|
-
if (!groupNode.pre) {
|
|
2458
|
-
return;
|
|
2459
|
-
}
|
|
2460
|
-
group.collapse();
|
|
2461
|
-
this.operationService.apply({
|
|
2462
|
-
type: "ungroup" /* ungroup */,
|
|
2463
|
-
value: {
|
|
2464
|
-
groupId: groupNode.id,
|
|
2465
|
-
targetId: groupNode.pre.id,
|
|
2466
|
-
nodeIds: nodes.map((node) => node.id)
|
|
2467
|
-
}
|
|
2468
|
-
});
|
|
2469
|
-
}
|
|
2470
|
-
/** 返回所有分组节点 */
|
|
2471
|
-
getAllGroups() {
|
|
2472
|
-
const allNodes = this.entityManager.getEntities(FlowNodeEntity);
|
|
2473
|
-
const groupNodes = allNodes.filter((node) => node.flowNodeType === "group" /* GROUP */);
|
|
2474
|
-
return groupNodes.map((node) => this.groupController(node)).filter(Boolean);
|
|
2475
|
-
}
|
|
2476
|
-
/** 获取分组控制器*/
|
|
2477
|
-
groupController(group) {
|
|
2478
|
-
return FlowGroupController.create(group);
|
|
2479
|
-
}
|
|
2480
|
-
static validate(nodes) {
|
|
2481
|
-
return FlowGroupController.validate(nodes);
|
|
2482
|
-
}
|
|
2483
|
-
};
|
|
2484
|
-
__decorateClass([
|
|
2485
|
-
inject4(EntityManager3)
|
|
2486
|
-
], FlowGroupService.prototype, "entityManager", 2);
|
|
2487
|
-
__decorateClass([
|
|
2488
|
-
inject4(FlowOperationBaseService)
|
|
2489
|
-
], FlowGroupService.prototype, "operationService", 2);
|
|
2490
|
-
FlowGroupService = __decorateClass([
|
|
2491
|
-
injectable4()
|
|
2492
|
-
], FlowGroupService);
|
|
2493
|
-
var FlowGroupController = class _FlowGroupController {
|
|
2494
|
-
constructor(groupNode) {
|
|
2495
|
-
this.groupNode = groupNode;
|
|
2496
|
-
}
|
|
2497
|
-
get nodes() {
|
|
2498
|
-
return this.groupNode.collapsedChildren || [];
|
|
2499
|
-
}
|
|
2500
|
-
get collapsed() {
|
|
2501
|
-
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2502
|
-
return groupTransformData.collapsed;
|
|
2503
|
-
}
|
|
2504
|
-
collapse() {
|
|
2505
|
-
this.collapsed = true;
|
|
2506
|
-
}
|
|
2507
|
-
expand() {
|
|
2508
|
-
this.collapsed = false;
|
|
2509
|
-
}
|
|
2510
|
-
/** 获取分组外围的最大边框 */
|
|
2511
|
-
get bounds() {
|
|
2512
|
-
const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
|
|
2513
|
-
return groupNodeBounds;
|
|
2514
|
-
}
|
|
2515
|
-
/** 是否是开始节点 */
|
|
2516
|
-
isStartNode(node) {
|
|
2517
|
-
if (!node) {
|
|
2518
|
-
return false;
|
|
2519
|
-
}
|
|
2520
|
-
const nodes = this.nodes;
|
|
2521
|
-
if (!nodes[0]) {
|
|
2522
|
-
return false;
|
|
2523
|
-
}
|
|
2524
|
-
return node.id === nodes[0].id;
|
|
2525
|
-
}
|
|
2526
|
-
/** 是否是结束节点 */
|
|
2527
|
-
isEndNode(node) {
|
|
2528
|
-
if (!node) {
|
|
2529
|
-
return false;
|
|
2530
|
-
}
|
|
2531
|
-
const nodes = this.nodes;
|
|
2532
|
-
if (!nodes[nodes.length - 1]) {
|
|
2533
|
-
return false;
|
|
2534
|
-
}
|
|
2535
|
-
return node.id === nodes[nodes.length - 1].id;
|
|
2536
|
-
}
|
|
2537
|
-
set note(note) {
|
|
2538
|
-
this.groupNode.getNodeMeta().note = note;
|
|
2539
|
-
}
|
|
2540
|
-
get note() {
|
|
2541
|
-
return this.groupNode.getNodeMeta().note || "";
|
|
2542
|
-
}
|
|
2543
|
-
set noteHeight(height) {
|
|
2544
|
-
this.groupNode.getNodeMeta().noteHeight = height;
|
|
2545
|
-
}
|
|
2546
|
-
get noteHeight() {
|
|
2547
|
-
return this.groupNode.getNodeMeta().noteHeight || 0;
|
|
2548
|
-
}
|
|
2549
|
-
get positionConfig() {
|
|
2550
|
-
return this.groupNode.getNodeMeta().positionConfig;
|
|
2551
|
-
}
|
|
2552
|
-
set collapsed(collapsed) {
|
|
2553
|
-
const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
|
|
2554
|
-
groupTransformData.collapsed = collapsed;
|
|
2555
|
-
groupTransformData.localDirty = true;
|
|
2556
|
-
if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
|
|
2557
|
-
if (groupTransformData.parent?.firstChild)
|
|
2558
|
-
groupTransformData.parent.firstChild.localDirty = true;
|
|
2559
|
-
}
|
|
2560
|
-
set hovered(hovered) {
|
|
2561
|
-
const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
|
|
2562
|
-
if (hovered) {
|
|
2563
|
-
groupRenderData.toggleMouseEnter();
|
|
2564
|
-
} else {
|
|
2565
|
-
groupRenderData.toggleMouseLeave();
|
|
2566
|
-
}
|
|
2567
|
-
if (groupRenderData.hovered === hovered) {
|
|
2568
|
-
return;
|
|
2823
|
+
getNodeIndex(node) {
|
|
2824
|
+
const entity = this.toNodeEntity(node);
|
|
2825
|
+
const parent = entity?.parent;
|
|
2826
|
+
if (!parent) {
|
|
2827
|
+
return -1;
|
|
2569
2828
|
}
|
|
2570
|
-
|
|
2829
|
+
return parent.children.findIndex((child) => child === entity);
|
|
2571
2830
|
}
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2831
|
+
doMoveNode(node, newParent, index) {
|
|
2832
|
+
if (!node.parent) {
|
|
2833
|
+
throw new Error("root node cannot move");
|
|
2834
|
+
}
|
|
2835
|
+
const event = {
|
|
2836
|
+
node,
|
|
2837
|
+
fromParent: node.parent,
|
|
2838
|
+
toParent: newParent,
|
|
2839
|
+
fromIndex: this.getNodeIndex(node),
|
|
2840
|
+
toIndex: index
|
|
2841
|
+
};
|
|
2842
|
+
this.document.moveChildNodes({
|
|
2843
|
+
nodeIds: [this.toId(node)],
|
|
2844
|
+
toParentId: this.toId(newParent),
|
|
2845
|
+
toIndex: index
|
|
2846
|
+
});
|
|
2847
|
+
this.onNodeMoveEmitter.fire(event);
|
|
2575
2848
|
}
|
|
2576
|
-
|
|
2577
|
-
|
|
2849
|
+
};
|
|
2850
|
+
__decorateClass([
|
|
2851
|
+
inject4(EntityManager3)
|
|
2852
|
+
], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
|
|
2853
|
+
__decorateClass([
|
|
2854
|
+
inject4(FlowDocument)
|
|
2855
|
+
], FlowOperationBaseServiceImpl.prototype, "document", 2);
|
|
2856
|
+
__decorateClass([
|
|
2857
|
+
postConstruct2()
|
|
2858
|
+
], FlowOperationBaseServiceImpl.prototype, "init", 1);
|
|
2859
|
+
FlowOperationBaseServiceImpl = __decorateClass([
|
|
2860
|
+
injectable4()
|
|
2861
|
+
], FlowOperationBaseServiceImpl);
|
|
2862
|
+
|
|
2863
|
+
// src/services/flow-group-service/flow-group-service.ts
|
|
2864
|
+
import { nanoid } from "nanoid";
|
|
2865
|
+
import { inject as inject5, injectable as injectable5 } from "inversify";
|
|
2866
|
+
import { EntityManager as EntityManager4 } from "@flowgram.ai/core";
|
|
2867
|
+
var FlowGroupService = class {
|
|
2868
|
+
/** 创建分组节点 */
|
|
2869
|
+
createGroup(nodes) {
|
|
2870
|
+
if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
|
|
2578
2871
|
return;
|
|
2579
2872
|
}
|
|
2580
|
-
if (!
|
|
2873
|
+
if (!FlowGroupUtils.validate(nodes)) {
|
|
2581
2874
|
return;
|
|
2582
2875
|
}
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
const hasGroup = nodes.some((node) => node && this.isNodeInGroup(node));
|
|
2593
|
-
if (hasGroup) return false;
|
|
2594
|
-
const parent = nodes[0].parent;
|
|
2595
|
-
const isSameParent = nodes.every((node) => node.parent === parent);
|
|
2596
|
-
if (!isSameParent) return false;
|
|
2597
|
-
const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
|
|
2598
|
-
const isIndexContinuous = indexes.every((index, i, arr) => {
|
|
2599
|
-
if (i === 0) {
|
|
2600
|
-
return true;
|
|
2876
|
+
const sortedNodes = nodes.sort((a, b) => a.index - b.index);
|
|
2877
|
+
const fromNode = sortedNodes[0];
|
|
2878
|
+
const groupId = `group_${nanoid(5)}`;
|
|
2879
|
+
this.operationService.apply({
|
|
2880
|
+
type: "createGroup" /* createGroup */,
|
|
2881
|
+
value: {
|
|
2882
|
+
targetId: fromNode.id,
|
|
2883
|
+
groupId,
|
|
2884
|
+
nodeIds: nodes.map((node) => node.id)
|
|
2601
2885
|
}
|
|
2602
|
-
return index === arr[i - 1] + 1;
|
|
2603
2886
|
});
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
const parentsInGroup = parents.some((parent2) => this.isNodeInGroup(parent2));
|
|
2607
|
-
if (parentsInGroup) return false;
|
|
2608
|
-
return true;
|
|
2609
|
-
}
|
|
2610
|
-
/** 获取节点分组控制 */
|
|
2611
|
-
static getNodeGroupController(node) {
|
|
2612
|
-
if (!node) {
|
|
2887
|
+
const groupNode = this.entityManager.getEntityById(groupId);
|
|
2888
|
+
if (!groupNode) {
|
|
2613
2889
|
return;
|
|
2614
2890
|
}
|
|
2615
|
-
|
|
2891
|
+
const group = this.groupController(groupNode);
|
|
2892
|
+
if (!group) {
|
|
2616
2893
|
return;
|
|
2617
2894
|
}
|
|
2618
|
-
|
|
2619
|
-
return
|
|
2895
|
+
group.expand();
|
|
2896
|
+
return groupNode;
|
|
2620
2897
|
}
|
|
2621
|
-
/**
|
|
2622
|
-
|
|
2623
|
-
|
|
2898
|
+
/** 删除分组 */
|
|
2899
|
+
deleteGroup(groupNode) {
|
|
2900
|
+
const json = groupNode.toJSON();
|
|
2901
|
+
if (!groupNode.pre || !json) {
|
|
2624
2902
|
return;
|
|
2625
2903
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
}
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
/** 是否分组节点 */
|
|
2636
|
-
static isGroupNode(group) {
|
|
2637
|
-
return group.flowNodeType === "group" /* GROUP */;
|
|
2638
|
-
}
|
|
2639
|
-
/** 找到节点所有上级 */
|
|
2640
|
-
static findNodeParents(node) {
|
|
2641
|
-
const parents = [];
|
|
2642
|
-
let parent = node.parent;
|
|
2643
|
-
while (parent) {
|
|
2644
|
-
parents.push(parent);
|
|
2645
|
-
parent = parent.parent;
|
|
2646
|
-
}
|
|
2647
|
-
return parents;
|
|
2648
|
-
}
|
|
2649
|
-
/** 节点是否处于分组中 */
|
|
2650
|
-
static isNodeInGroup(node) {
|
|
2651
|
-
if (node?.parent?.flowNodeType === "group" /* GROUP */) {
|
|
2652
|
-
return true;
|
|
2653
|
-
}
|
|
2654
|
-
return false;
|
|
2655
|
-
}
|
|
2656
|
-
};
|
|
2657
|
-
|
|
2658
|
-
// src/services/flow-drag-service.ts
|
|
2659
|
-
var FlowDragService = class {
|
|
2660
|
-
constructor() {
|
|
2661
|
-
this.onDropEmitter = new Emitter7();
|
|
2662
|
-
this.onDrop = this.onDropEmitter.event;
|
|
2663
|
-
}
|
|
2664
|
-
get renderState() {
|
|
2665
|
-
return this.document.renderState;
|
|
2666
|
-
}
|
|
2667
|
-
// 拖拽所有节点中的首个节点
|
|
2668
|
-
get dragStartNode() {
|
|
2669
|
-
return this.renderState.getDragStartEntity();
|
|
2670
|
-
}
|
|
2671
|
-
// 拖拽的所有节点
|
|
2672
|
-
get dragNodes() {
|
|
2673
|
-
return this.renderState.getDragEntities();
|
|
2674
|
-
}
|
|
2675
|
-
// 放置的区域
|
|
2676
|
-
get dropNodeId() {
|
|
2677
|
-
return this.renderState.getNodeDroppingId();
|
|
2678
|
-
}
|
|
2679
|
-
// 是否在拖拽分支
|
|
2680
|
-
get isDragBranch() {
|
|
2681
|
-
return this.dragStartNode?.isInlineBlock;
|
|
2682
|
-
}
|
|
2683
|
-
// 拖拽的所有节点及其自节点
|
|
2684
|
-
get nodeDragIdsWithChildren() {
|
|
2685
|
-
return this.renderState.config.nodeDragIdsWithChildren || [];
|
|
2686
|
-
}
|
|
2687
|
-
get dragging() {
|
|
2688
|
-
const renderData = this.dragStartNode?.getData(FlowNodeRenderData);
|
|
2689
|
-
return !!renderData?.dragging;
|
|
2690
|
-
}
|
|
2691
|
-
get labelSide() {
|
|
2692
|
-
return this.renderState.config.dragLabelSide;
|
|
2693
|
-
}
|
|
2694
|
-
/**
|
|
2695
|
-
* 放置到目标分支
|
|
2696
|
-
*/
|
|
2697
|
-
dropBranch() {
|
|
2698
|
-
this.dropNode();
|
|
2904
|
+
this.operationService.apply({
|
|
2905
|
+
type: "deleteNodes" /* deleteNodes */,
|
|
2906
|
+
value: {
|
|
2907
|
+
fromId: groupNode.pre.id,
|
|
2908
|
+
nodes: [json]
|
|
2909
|
+
}
|
|
2910
|
+
});
|
|
2699
2911
|
}
|
|
2700
|
-
/**
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
const dropEntity = this.document.getNode(this.dropNodeId);
|
|
2705
|
-
if (!dropEntity) {
|
|
2912
|
+
/** 取消分组 */
|
|
2913
|
+
ungroup(groupNode) {
|
|
2914
|
+
const group = this.groupController(groupNode);
|
|
2915
|
+
if (!group) {
|
|
2706
2916
|
return;
|
|
2707
2917
|
}
|
|
2708
|
-
const
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
sortNodes.push(curr);
|
|
2712
|
-
curr = curr.next;
|
|
2918
|
+
const nodes = group.nodes;
|
|
2919
|
+
if (!groupNode.pre) {
|
|
2920
|
+
return;
|
|
2713
2921
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2922
|
+
group.collapse();
|
|
2923
|
+
this.operationService.apply({
|
|
2924
|
+
type: "ungroup" /* ungroup */,
|
|
2925
|
+
value: {
|
|
2926
|
+
groupId: groupNode.id,
|
|
2927
|
+
targetId: groupNode.pre.id,
|
|
2928
|
+
nodeIds: nodes.map((node) => node.id)
|
|
2929
|
+
}
|
|
2717
2930
|
});
|
|
2718
|
-
if (sortNodes.length > 0) {
|
|
2719
|
-
this.onDropEmitter.fire({
|
|
2720
|
-
dropNode: dropEntity,
|
|
2721
|
-
dragNodes: sortNodes
|
|
2722
|
-
});
|
|
2723
|
-
}
|
|
2724
2931
|
}
|
|
2725
|
-
/**
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
return false;
|
|
2731
|
-
}
|
|
2732
|
-
if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
|
|
2733
|
-
return false;
|
|
2734
|
-
}
|
|
2735
|
-
if (node.isInlineBlocks || node.isInlineBlock) {
|
|
2736
|
-
return false;
|
|
2737
|
-
}
|
|
2738
|
-
const hasGroupNode = this.dragNodes.some((node2) => node2.flowNodeType === "group" /* GROUP */);
|
|
2739
|
-
if (hasGroupNode) {
|
|
2740
|
-
const group = FlowGroupController.getNodeRecursionGroupController(node);
|
|
2741
|
-
if (group) {
|
|
2742
|
-
return false;
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
return true;
|
|
2932
|
+
/** 返回所有分组节点 */
|
|
2933
|
+
getAllGroups() {
|
|
2934
|
+
const allNodes = this.entityManager.getEntities(FlowNodeEntity);
|
|
2935
|
+
const groupNodes = allNodes.filter((node) => node.flowNodeType === "group" /* GROUP */);
|
|
2936
|
+
return groupNodes.map((node) => this.groupController(node)).filter(Boolean);
|
|
2746
2937
|
}
|
|
2747
|
-
/**
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
if (this.isDragBranch) {
|
|
2754
|
-
if (
|
|
2755
|
-
// 拖拽到分支
|
|
2756
|
-
!node.isInlineBlock || // 只能在同一分支条件下
|
|
2757
|
-
node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
|
|
2758
|
-
node === this.dragStartNode
|
|
2759
|
-
) {
|
|
2760
|
-
return false;
|
|
2761
|
-
}
|
|
2762
|
-
if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
|
|
2763
|
-
return true;
|
|
2764
|
-
}
|
|
2765
|
-
if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
|
|
2766
|
-
return true;
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
return false;
|
|
2938
|
+
/** 获取分组控制器*/
|
|
2939
|
+
groupController(group) {
|
|
2940
|
+
return FlowGroupController.create(group);
|
|
2941
|
+
}
|
|
2942
|
+
static validate(nodes) {
|
|
2943
|
+
return FlowGroupUtils.validate(nodes);
|
|
2770
2944
|
}
|
|
2771
2945
|
};
|
|
2772
2946
|
__decorateClass([
|
|
2773
|
-
inject5(
|
|
2774
|
-
],
|
|
2947
|
+
inject5(EntityManager4)
|
|
2948
|
+
], FlowGroupService.prototype, "entityManager", 2);
|
|
2775
2949
|
__decorateClass([
|
|
2776
2950
|
inject5(FlowOperationBaseService)
|
|
2777
|
-
],
|
|
2778
|
-
__decorateClass([
|
|
2779
|
-
inject5(EntityManager4)
|
|
2780
|
-
], FlowDragService.prototype, "entityManager", 2);
|
|
2781
|
-
FlowDragService = __decorateClass([
|
|
2951
|
+
], FlowGroupService.prototype, "operationService", 2);
|
|
2952
|
+
FlowGroupService = __decorateClass([
|
|
2782
2953
|
injectable5()
|
|
2783
|
-
],
|
|
2954
|
+
], FlowGroupService);
|
|
2784
2955
|
|
|
2785
2956
|
// src/layout/vertical-fixed-layout.ts
|
|
2786
2957
|
import { injectable as injectable6, inject as inject6, multiInject as multiInject2, optional as optional3 } from "inversify";
|