@logicflow/extension 2.0.9 → 2.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/.turbo/turbo-build.log +34 -61
- package/CHANGELOG.md +33 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/bpmn-elements/presets/Pool/index.js +7 -7
- package/es/bpmn-elements/presets/Task/subProcess.js +2 -2
- package/es/dynamic-group/index.d.ts +11 -5
- package/es/dynamic-group/index.js +125 -23
- package/es/dynamic-group/model.d.ts +6 -1
- package/es/dynamic-group/model.js +14 -8
- package/es/dynamic-group/node.d.ts +13 -1
- package/es/dynamic-group/node.js +135 -19
- package/es/tools/label/index.js +2 -2
- package/lib/bpmn-elements/presets/Pool/index.js +7 -7
- package/lib/bpmn-elements/presets/Task/subProcess.js +2 -2
- package/lib/dynamic-group/index.d.ts +11 -5
- package/lib/dynamic-group/index.js +125 -23
- package/lib/dynamic-group/model.d.ts +6 -1
- package/lib/dynamic-group/model.js +14 -8
- package/lib/dynamic-group/node.d.ts +13 -1
- package/lib/dynamic-group/node.js +135 -19
- package/lib/tools/label/index.js +2 -2
- package/package.json +3 -3
- package/src/dynamic-group/index.ts +146 -3
- package/src/dynamic-group/model.ts +18 -7
- package/src/dynamic-group/node.ts +137 -68
- package/stats.html +1 -1
|
@@ -47,19 +47,19 @@ function poolEvent(lf) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
lf.on('node:resize', function (_a) {
|
|
50
|
-
var
|
|
51
|
-
var id =
|
|
52
|
-
var deltaHeight =
|
|
53
|
-
// const resizeDir =
|
|
50
|
+
var preData = _a.preData, data = _a.data;
|
|
51
|
+
var id = preData.id, type = preData.type;
|
|
52
|
+
var deltaHeight = data.height - preData.height;
|
|
53
|
+
// const resizeDir = data.y - preData.y > 0 ? 'below': 'above'
|
|
54
54
|
// 节点高度变高,y下移, 方向为below
|
|
55
55
|
// 节点高度变高, y上移, 方向为above
|
|
56
56
|
// 节点高度变小, y下移, 方向为above
|
|
57
57
|
// 节点高度变小, y上移,方向为below
|
|
58
58
|
var resizeDir = 'below';
|
|
59
|
-
if (deltaHeight > 0 &&
|
|
59
|
+
if (deltaHeight > 0 && data.y - preData.y < 0) {
|
|
60
60
|
resizeDir = 'above';
|
|
61
61
|
}
|
|
62
|
-
else if (deltaHeight < 0 &&
|
|
62
|
+
else if (deltaHeight < 0 && data.y - preData.y > 0) {
|
|
63
63
|
resizeDir = 'above';
|
|
64
64
|
}
|
|
65
65
|
if (type === 'pool') {
|
|
@@ -73,7 +73,7 @@ function poolEvent(lf) {
|
|
|
73
73
|
// 泳道缩放, 调整泳池
|
|
74
74
|
var groupId = lf.extension.group.nodeGroupMap.get(id);
|
|
75
75
|
if (groupId) {
|
|
76
|
-
lf.getNodeModelById(groupId).resize(id,
|
|
76
|
+
lf.getNodeModelById(groupId).resize(id, data);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -62,8 +62,8 @@ export function SubProcessFactory() {
|
|
|
62
62
|
y: y - height / 2 + 5,
|
|
63
63
|
onClick: function (e) {
|
|
64
64
|
var _a, _b;
|
|
65
|
-
(
|
|
66
|
-
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
(_b = (_a = model).foldGroup) === null || _b === void 0 ? void 0 : _b.call(_a, !properties.isFolded);
|
|
67
67
|
},
|
|
68
68
|
}),
|
|
69
69
|
iconIcon,
|
|
@@ -20,11 +20,6 @@ export declare class DynamicGroup {
|
|
|
20
20
|
activeGroup?: DynamicGroupNodeModel;
|
|
21
21
|
nodeGroupMap: Map<string, string>;
|
|
22
22
|
constructor({ lf, options }: LogicFlow.IExtensionProps);
|
|
23
|
-
/**
|
|
24
|
-
* 获取分组内的节点
|
|
25
|
-
* @param groupModel
|
|
26
|
-
*/
|
|
27
|
-
getNodesInGroup(groupModel: DynamicGroupNodeModel): string[];
|
|
28
23
|
/**
|
|
29
24
|
* 获取节点所属的分组
|
|
30
25
|
* @param nodeId
|
|
@@ -66,6 +61,7 @@ export declare class DynamicGroup {
|
|
|
66
61
|
* @param isSelected
|
|
67
62
|
*/
|
|
68
63
|
onNodeSelect: ({ data: node, isMultiple, isSelected, }: Omit<CallbackArgs<'node:click'>, 'e' | 'position'>) => void;
|
|
64
|
+
onNodeMove: ({ deltaX, deltaY, data, }: Omit<CallbackArgs<'node:mousemove'>, 'e' | 'position'>) => void;
|
|
69
65
|
onGraphRendered: ({ data }: CallbackArgs<'graph:rendered'>) => void;
|
|
70
66
|
/**
|
|
71
67
|
* 创建一个 Group 类型节点内部所有子节点的副本
|
|
@@ -79,6 +75,16 @@ export declare class DynamicGroup {
|
|
|
79
75
|
* @param distance
|
|
80
76
|
*/
|
|
81
77
|
createEdge(edge: EdgeConfig | EdgeData, nodeIdMap: Record<string, string>, distance: number): BaseEdgeModel<LogicFlow.PropertiesType>;
|
|
78
|
+
/**
|
|
79
|
+
* 检测group:resize后的bounds是否会小于children的bounds
|
|
80
|
+
* 限制group进行resize时不能小于内部的占地面积
|
|
81
|
+
* @param groupModel
|
|
82
|
+
* @param deltaX
|
|
83
|
+
* @param deltaY
|
|
84
|
+
* @param newWidth
|
|
85
|
+
* @param newHeight
|
|
86
|
+
*/
|
|
87
|
+
checkGroupBoundsWithChildren(groupModel: DynamicGroupNodeModel, deltaX: number, deltaY: number, newWidth: number, newHeight: number): boolean;
|
|
82
88
|
/**
|
|
83
89
|
* Group 插件的初始化方法
|
|
84
90
|
* TODO:1. 待讨论,可能之前插件分类是有意义的 components, material, tools
|
|
@@ -207,6 +207,62 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
|
+
this.onNodeMove = function (_a) {
|
|
211
|
+
var deltaX = _a.deltaX, deltaY = _a.deltaY, data = _a.data;
|
|
212
|
+
var id = data.id, x = data.x, y = data.y, properties = data.properties;
|
|
213
|
+
if (!properties) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
var width = properties.width, height = properties.height;
|
|
217
|
+
var groupId = _this.nodeGroupMap.get(id);
|
|
218
|
+
if (!groupId) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
var groupModel = _this.lf.getNodeModelById(groupId);
|
|
222
|
+
if (!groupModel || !groupModel.isRestrict || !groupModel.autoResize) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
// 当父节点isRestrict=true & autoResize=true
|
|
226
|
+
// 子节点在父节点中移动时,父节点会自动调整大小
|
|
227
|
+
// step1: 计算出当前child的bounds
|
|
228
|
+
var newX = x + deltaX / 2;
|
|
229
|
+
var newY = y + deltaY / 2;
|
|
230
|
+
var minX = newX - width / 2;
|
|
231
|
+
var minY = newY - height / 2;
|
|
232
|
+
var maxX = newX + width / 2;
|
|
233
|
+
var maxY = newY + height / 2;
|
|
234
|
+
// step2:比较当前child.bounds与parent.bounds的差异,比如child.minX<parent.minX,那么parent.minX=child.minX
|
|
235
|
+
var hasChange = false;
|
|
236
|
+
var groupBounds = groupModel.getBounds();
|
|
237
|
+
var newGroupBounds = Object.assign({}, groupBounds);
|
|
238
|
+
if (minX < newGroupBounds.minX) {
|
|
239
|
+
newGroupBounds.minX = minX;
|
|
240
|
+
hasChange = true;
|
|
241
|
+
}
|
|
242
|
+
if (minY < newGroupBounds.minY) {
|
|
243
|
+
newGroupBounds.minY = minY;
|
|
244
|
+
hasChange = true;
|
|
245
|
+
}
|
|
246
|
+
if (maxX > newGroupBounds.maxX) {
|
|
247
|
+
newGroupBounds.maxX = maxX;
|
|
248
|
+
hasChange = true;
|
|
249
|
+
}
|
|
250
|
+
if (maxY > newGroupBounds.maxY) {
|
|
251
|
+
newGroupBounds.maxY = maxY;
|
|
252
|
+
hasChange = true;
|
|
253
|
+
}
|
|
254
|
+
if (!hasChange) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// step3: 根据当前parent.bounds去计算出最新的x、y、width、height
|
|
258
|
+
var newGroupX = newGroupBounds.minX + (newGroupBounds.maxX - newGroupBounds.minX) / 2;
|
|
259
|
+
var newGroupY = newGroupBounds.minY + (newGroupBounds.maxY - newGroupBounds.minY) / 2;
|
|
260
|
+
var newGroupWidth = newGroupBounds.maxX - newGroupBounds.minX;
|
|
261
|
+
var newGroupHeight = newGroupBounds.maxY - newGroupBounds.minY;
|
|
262
|
+
groupModel.moveTo(newGroupX, newGroupY);
|
|
263
|
+
groupModel.width = newGroupWidth;
|
|
264
|
+
groupModel.height = newGroupHeight;
|
|
265
|
+
};
|
|
210
266
|
this.onGraphRendered = function (_a) {
|
|
211
267
|
var data = _a.data;
|
|
212
268
|
console.log('data', data);
|
|
@@ -227,24 +283,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
227
283
|
// 初始化插件,从监听事件开始及设置规则开始
|
|
228
284
|
this.init();
|
|
229
285
|
}
|
|
230
|
-
/**
|
|
231
|
-
* 获取分组内的节点
|
|
232
|
-
* @param groupModel
|
|
233
|
-
*/
|
|
234
|
-
DynamicGroup.prototype.getNodesInGroup = function (groupModel) {
|
|
235
|
-
var _this = this;
|
|
236
|
-
var nodeIds = [];
|
|
237
|
-
if (groupModel.isGroup) {
|
|
238
|
-
forEach(Array.from(groupModel.children), function (nodeId) {
|
|
239
|
-
nodeIds.push(nodeId);
|
|
240
|
-
var nodeModel = _this.lf.getNodeModelById(nodeId);
|
|
241
|
-
if (nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.isGroup) {
|
|
242
|
-
nodeIds = nodeIds.concat(_this.getNodesInGroup(nodeModel));
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
return nodeIds;
|
|
247
|
-
};
|
|
248
286
|
/**
|
|
249
287
|
* 获取节点所属的分组
|
|
250
288
|
* @param nodeId
|
|
@@ -425,6 +463,46 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
425
463
|
}
|
|
426
464
|
return this.lf.graphModel.addEdge(__assign(__assign({}, newEdgeConfig), { sourceNodeId: sourceId, targetNodeId: targetId }));
|
|
427
465
|
};
|
|
466
|
+
/**
|
|
467
|
+
* 检测group:resize后的bounds是否会小于children的bounds
|
|
468
|
+
* 限制group进行resize时不能小于内部的占地面积
|
|
469
|
+
* @param groupModel
|
|
470
|
+
* @param deltaX
|
|
471
|
+
* @param deltaY
|
|
472
|
+
* @param newWidth
|
|
473
|
+
* @param newHeight
|
|
474
|
+
*/
|
|
475
|
+
DynamicGroup.prototype.checkGroupBoundsWithChildren = function (groupModel, deltaX, deltaY, newWidth, newHeight) {
|
|
476
|
+
if (groupModel.children) {
|
|
477
|
+
var children = groupModel.children, x = groupModel.x, y = groupModel.y;
|
|
478
|
+
// 根据deltaX和deltaY计算出当前model的bounds
|
|
479
|
+
var newX = x + deltaX / 2;
|
|
480
|
+
var newY = y + deltaY / 2;
|
|
481
|
+
var groupMinX = newX - newWidth / 2;
|
|
482
|
+
var groupMinY = newY - newHeight / 2;
|
|
483
|
+
var groupMaxX = newX + newWidth / 2;
|
|
484
|
+
var groupMaxY = newY + newHeight / 2;
|
|
485
|
+
var childrenArray = Array.from(children);
|
|
486
|
+
for (var i = 0; i < childrenArray.length; i++) {
|
|
487
|
+
var childId = childrenArray[i];
|
|
488
|
+
var child = this.lf.getNodeModelById(childId);
|
|
489
|
+
if (!child) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
var childBounds = child.getBounds();
|
|
493
|
+
var minX = childBounds.minX, minY = childBounds.minY, maxX = childBounds.maxX, maxY = childBounds.maxY;
|
|
494
|
+
// parent:resize后的bounds不能小于child:bounds,否则阻止其resize
|
|
495
|
+
var canResize = groupMinX <= minX &&
|
|
496
|
+
groupMinY <= minY &&
|
|
497
|
+
groupMaxX >= maxX &&
|
|
498
|
+
groupMaxY >= maxY;
|
|
499
|
+
if (!canResize) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return true;
|
|
505
|
+
};
|
|
428
506
|
/**
|
|
429
507
|
* Group 插件的初始化方法
|
|
430
508
|
* TODO:1. 待讨论,可能之前插件分类是有意义的 components, material, tools
|
|
@@ -446,16 +524,38 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
446
524
|
graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
|
|
447
525
|
// 判断如果是 group,移动时需要同时移动组内的所有节点
|
|
448
526
|
if (model.isGroup) {
|
|
449
|
-
|
|
450
|
-
|
|
527
|
+
// https://github.com/didi/LogicFlow/issues/1826
|
|
528
|
+
// 这里不应该触发移动子节点的逻辑,这里是判断是否可以移动,而不是触发移动逻辑
|
|
529
|
+
// 而且这里触发移动,会导致resize操作的this.x变动也会触发子item的this.x变动
|
|
530
|
+
// resize时的deltaX跟正常移动的deltaX是不同的
|
|
531
|
+
// const nodeIds = this.getNodesInGroup(model as DynamicGroupNodeModel)
|
|
532
|
+
// graphModel.moveNodes(nodeIds, deltaX, deltaY, true)
|
|
451
533
|
return true;
|
|
452
534
|
}
|
|
453
535
|
var groupId = _this.nodeGroupMap.get(model.id);
|
|
454
536
|
var groupModel = _this.lf.getNodeModelById(groupId);
|
|
455
537
|
if (groupModel && groupModel.isRestrict) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
538
|
+
if (groupModel.autoResize) {
|
|
539
|
+
// 子节点在父节点中移动时,父节点会自动调整大小
|
|
540
|
+
// 在node:mousemove中进行父节点的调整
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
// 如果移动的节点存在于某个分组中,且这个分组禁止子节点移出去
|
|
545
|
+
var groupBounds = groupModel.getBounds();
|
|
546
|
+
return isAllowMoveTo(groupBounds, model, deltaX, deltaY);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
});
|
|
551
|
+
// https://github.com/didi/LogicFlow/issues/1442
|
|
552
|
+
// https://github.com/didi/LogicFlow/issues/937
|
|
553
|
+
// 添加分组节点resize规则
|
|
554
|
+
// isRestrict限制模式下,当前model resize时不能小于children的占地面积
|
|
555
|
+
// 并且在isRestrict限制模式下,transformWidthContainer即使设置为true,也无效
|
|
556
|
+
graphModel.addNodeResizeRules(function (model, deltaX, deltaY, width, height) {
|
|
557
|
+
if (model.isGroup && model.isRestrict) {
|
|
558
|
+
return _this.checkGroupBoundsWithChildren(model, deltaX, deltaY, width, height);
|
|
459
559
|
}
|
|
460
560
|
return true;
|
|
461
561
|
});
|
|
@@ -464,6 +564,7 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
464
564
|
lf.on('node:delete', this.removeNodeFromGroup);
|
|
465
565
|
lf.on('node:drag,node:dnd-drag', this.setActiveGroup);
|
|
466
566
|
lf.on('node:click', this.onNodeSelect);
|
|
567
|
+
lf.on('node:mousemove', this.onNodeMove);
|
|
467
568
|
lf.on('graph:rendered', this.onGraphRendered);
|
|
468
569
|
lf.on('graph:updated', function (_a) {
|
|
469
570
|
var data = _a.data;
|
|
@@ -521,6 +622,7 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
521
622
|
this.lf.off('node:delete', this.removeNodeFromGroup);
|
|
522
623
|
this.lf.off('node:drag,node:dnd-drag', this.setActiveGroup);
|
|
523
624
|
this.lf.off('node:click', this.onNodeSelect);
|
|
625
|
+
this.lf.off('node:mousemove', this.onNodeMove);
|
|
524
626
|
this.lf.off('graph:rendered', this.onGraphRendered);
|
|
525
627
|
// 还原 lf.addElements 方法?
|
|
526
628
|
// 移除 graphModel 上重写的 addNodeMoveRules 方法?
|
|
@@ -31,6 +31,10 @@ export type IGroupNodeProperties = {
|
|
|
31
31
|
*/
|
|
32
32
|
collapsedWidth?: number;
|
|
33
33
|
collapsedHeight?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 缩放或旋转容器时,是否缩放或旋转组内节点
|
|
36
|
+
*/
|
|
37
|
+
transformWithContainer?: boolean;
|
|
34
38
|
/**
|
|
35
39
|
* 当前分组元素的 zIndex
|
|
36
40
|
*/
|
|
@@ -45,6 +49,7 @@ export declare class DynamicGroupNodeModel extends RectNodeModel<IGroupNodePrope
|
|
|
45
49
|
readonly isGroup = true;
|
|
46
50
|
children: Set<string>;
|
|
47
51
|
isRestrict: boolean;
|
|
52
|
+
autoResize: boolean;
|
|
48
53
|
collapsible: boolean;
|
|
49
54
|
expandWidth: number;
|
|
50
55
|
expandHeight: number;
|
|
@@ -52,7 +57,7 @@ export declare class DynamicGroupNodeModel extends RectNodeModel<IGroupNodePrope
|
|
|
52
57
|
collapsedHeight: number;
|
|
53
58
|
isCollapsed: boolean;
|
|
54
59
|
groupAddable: boolean;
|
|
55
|
-
|
|
60
|
+
transformWithContainer: boolean;
|
|
56
61
|
childrenLastCollapseStateDict: Map<string, boolean>;
|
|
57
62
|
constructor(data: NodeConfig<IGroupNodeProperties>, graphModel: GraphModel);
|
|
58
63
|
initNodeData(data: LogicFlow.NodeConfig<IGroupNodeProperties>): void;
|
|
@@ -71,6 +71,8 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
71
71
|
_this.isGroup = true;
|
|
72
72
|
// 是否限制组内节点的移动范围。默认不限制 TODO: 完善该功能
|
|
73
73
|
_this.isRestrict = false;
|
|
74
|
+
// isRestrict 模式启用时,如果同时设置 autoResize 为 true,那么子节点在父节点中移动时,父节点会自动调整大小
|
|
75
|
+
_this.autoResize = false;
|
|
74
76
|
// 分组节点是否可以折叠
|
|
75
77
|
_this.collapsible = true;
|
|
76
78
|
// 当前组是否收起状态
|
|
@@ -78,7 +80,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
78
80
|
// 当前分组是否在可添加状态 - 实时状态
|
|
79
81
|
_this.groupAddable = false;
|
|
80
82
|
// 缩放或旋转容器时,是否缩放或旋转组内节点
|
|
81
|
-
_this.
|
|
83
|
+
_this.transformWithContainer = false;
|
|
82
84
|
_this.childrenLastCollapseStateDict = new Map();
|
|
83
85
|
_this.childrenLastCollapseStateDict = new Map();
|
|
84
86
|
_this.initNodeData(data);
|
|
@@ -88,7 +90,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
88
90
|
DynamicGroupNodeModel.prototype.initNodeData = function (data) {
|
|
89
91
|
var _a;
|
|
90
92
|
_super.prototype.initNodeData.call(this, data);
|
|
91
|
-
var _b = (_a = data.properties) !== null && _a !== void 0 ? _a : {}, children = _b.children, width = _b.width, height = _b.height, collapsedWidth = _b.collapsedWidth, collapsedHeight = _b.collapsedHeight, collapsible = _b.collapsible, isCollapsed = _b.isCollapsed, zIndex = _b.zIndex, isRestrict = _b.isRestrict, autoResize = _b.autoResize, autoToFront = _b.autoToFront;
|
|
93
|
+
var _b = (_a = data.properties) !== null && _a !== void 0 ? _a : {}, children = _b.children, width = _b.width, height = _b.height, collapsedWidth = _b.collapsedWidth, collapsedHeight = _b.collapsedHeight, collapsible = _b.collapsible, isCollapsed = _b.isCollapsed, zIndex = _b.zIndex, isRestrict = _b.isRestrict, autoResize = _b.autoResize, autoToFront = _b.autoToFront, transformWithContainer = _b.transformWithContainer;
|
|
92
94
|
this.children = children ? new Set(children) : new Set();
|
|
93
95
|
this.zIndex = zIndex !== null && zIndex !== void 0 ? zIndex : DEFAULT_BOTTOM_Z_INDEX;
|
|
94
96
|
this.isCollapsed = isCollapsed !== null && isCollapsed !== void 0 ? isCollapsed : false;
|
|
@@ -102,6 +104,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
102
104
|
this.collapsedWidth = collapsedWidth !== null && collapsedWidth !== void 0 ? collapsedWidth : DEFAULT_GROUP_COLLAPSE_WIDTH;
|
|
103
105
|
this.collapsedHeight = collapsedHeight !== null && collapsedHeight !== void 0 ? collapsedHeight : DEFAULT_GROUP_COLLAPSE_HEIGHT;
|
|
104
106
|
this.isRestrict = isRestrict !== null && isRestrict !== void 0 ? isRestrict : false;
|
|
107
|
+
this.transformWithContainer = transformWithContainer !== null && transformWithContainer !== void 0 ? transformWithContainer : false;
|
|
105
108
|
this.autoResize = autoResize !== null && autoResize !== void 0 ? autoResize : false;
|
|
106
109
|
this.collapsible = collapsible !== null && collapsible !== void 0 ? collapsible : true;
|
|
107
110
|
this.autoToFront = autoToFront !== null && autoToFront !== void 0 ? autoToFront : false;
|
|
@@ -111,10 +114,6 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
111
114
|
};
|
|
112
115
|
DynamicGroupNodeModel.prototype.setAttributes = function () {
|
|
113
116
|
_super.prototype.setAttributes.call(this);
|
|
114
|
-
// 初始化时,如果 this.isCollapsed 为 true,则主动触发一次折叠操作
|
|
115
|
-
if (this.isCollapsed) {
|
|
116
|
-
this.toggleCollapse(true);
|
|
117
|
-
}
|
|
118
117
|
};
|
|
119
118
|
DynamicGroupNodeModel.prototype.getData = function () {
|
|
120
119
|
var _this = this;
|
|
@@ -142,8 +141,15 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
142
141
|
data.isGroup = true;
|
|
143
142
|
var _a = this, x = _a.x, y = _a.y, collapsedWidth = _a.collapsedWidth, collapsedHeight = _a.collapsedHeight, expandWidth = _a.expandWidth, expandHeight = _a.expandHeight, isCollapsed = _a.isCollapsed;
|
|
144
143
|
if (isCollapsed) {
|
|
144
|
+
// 如果当前是折叠模式
|
|
145
|
+
// 存入history的时候,将坐标恢复到未折叠前的坐标数据
|
|
146
|
+
// 因为拿出history数据的时候,会触发collapse()进行坐标的折叠计算
|
|
145
147
|
data.x = x + expandWidth / 2 - collapsedWidth / 2;
|
|
146
148
|
data.y = y + expandHeight / 2 - collapsedHeight / 2;
|
|
149
|
+
if (data.text) {
|
|
150
|
+
data.text.x = data.text.x + expandWidth / 2 - collapsedWidth / 2;
|
|
151
|
+
data.text.y = data.text.y + expandHeight / 2 - collapsedHeight / 2;
|
|
152
|
+
}
|
|
147
153
|
}
|
|
148
154
|
return data;
|
|
149
155
|
};
|
|
@@ -332,8 +338,8 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
332
338
|
* TODO: 如何重写该方法呢?
|
|
333
339
|
* @param _nodeData
|
|
334
340
|
*/
|
|
341
|
+
// eslint-disable-next-line
|
|
335
342
|
DynamicGroupNodeModel.prototype.isAllowAppendIn = function (_nodeData) {
|
|
336
|
-
console.info('_nodeData', _nodeData);
|
|
337
343
|
// TODO: 此处使用 this.properties.groupAddable 还是 this.groupAddable
|
|
338
344
|
// this.groupAddable 是否存在更新不及时的问题
|
|
339
345
|
return true;
|
|
@@ -408,7 +414,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
|
|
|
408
414
|
], DynamicGroupNodeModel.prototype, "groupAddable", void 0);
|
|
409
415
|
__decorate([
|
|
410
416
|
observable
|
|
411
|
-
], DynamicGroupNodeModel.prototype, "
|
|
417
|
+
], DynamicGroupNodeModel.prototype, "transformWithContainer", void 0);
|
|
412
418
|
return DynamicGroupNodeModel;
|
|
413
419
|
}(RectNodeModel));
|
|
414
420
|
export { DynamicGroupNodeModel };
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { GraphModel, h, RectNode } from '@logicflow/core';
|
|
1
|
+
import LogicFlow, { GraphModel, h, RectNode, CallbackArgs } from '@logicflow/core';
|
|
2
2
|
import { DynamicGroupNodeModel } from './model';
|
|
3
|
+
import Position = LogicFlow.Position;
|
|
3
4
|
export interface IDynamicGroupNodeProps {
|
|
4
5
|
model: DynamicGroupNodeModel;
|
|
5
6
|
graphModel: GraphModel;
|
|
6
7
|
}
|
|
7
8
|
export declare class DynamicGroupNode<P extends IDynamicGroupNodeProps = IDynamicGroupNodeProps> extends RectNode<P> {
|
|
9
|
+
childrenPositionMap: Map<string, Position>;
|
|
10
|
+
onNodeRotate: ({ model, }: Omit<CallbackArgs<'node:rotate'>, 'e' | 'position'>) => void;
|
|
11
|
+
onNodeResize: ({ deltaX, deltaY, index, model, preData, }: Omit<CallbackArgs<'node:resize'>, 'e' | 'position'>) => void;
|
|
12
|
+
onNodeMouseMove: ({ deltaX, deltaY, data, }: Omit<CallbackArgs<'node:mousemove'>, 'e' | 'position'>) => void;
|
|
13
|
+
graphRendered: () => void;
|
|
8
14
|
componentDidMount(): void;
|
|
15
|
+
componentWillUnmount(): void;
|
|
16
|
+
/**
|
|
17
|
+
* 获取分组内的节点
|
|
18
|
+
* @param groupModel
|
|
19
|
+
*/
|
|
20
|
+
getNodesInGroup(groupModel: DynamicGroupNodeModel, graphModel: GraphModel): string[];
|
|
9
21
|
getResizeControl(): h.JSX.Element | null;
|
|
10
22
|
getAppendAreaShape(): h.JSX.Element | null;
|
|
11
23
|
getCollapseIcon(sx: number, sy: number): string;
|
package/es/dynamic-group/node.js
CHANGED
|
@@ -24,23 +24,53 @@ var __assign = (this && this.__assign) || function () {
|
|
|
24
24
|
};
|
|
25
25
|
return __assign.apply(this, arguments);
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
28
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29
|
+
if (!m) return o;
|
|
30
|
+
var i = m.call(o), r, ar = [], e;
|
|
31
|
+
try {
|
|
32
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
33
|
+
}
|
|
34
|
+
catch (error) { e = { error: error }; }
|
|
35
|
+
finally {
|
|
36
|
+
try {
|
|
37
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
38
|
+
}
|
|
39
|
+
finally { if (e) throw e.error; }
|
|
40
|
+
}
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
44
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
+
if (ar || !(i in from)) {
|
|
46
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
+
ar[i] = from[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
|
+
};
|
|
52
|
+
import { h, RectNode, handleResize, } from '@logicflow/core';
|
|
28
53
|
import { forEach } from 'lodash-es';
|
|
29
|
-
import { handleResize } from '@logicflow/core/es/util/resize';
|
|
30
54
|
import { rotatePointAroundCenter } from '../tools/label/utils';
|
|
31
55
|
var DynamicGroupNode = /** @class */ (function (_super) {
|
|
32
56
|
__extends(DynamicGroupNode, _super);
|
|
33
57
|
function DynamicGroupNode() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_super.prototype.componentDidMount.call(this);
|
|
38
|
-
var _a = this.props, curGroup = _a.model, graphModel = _a.graphModel;
|
|
39
|
-
var eventCenter = graphModel.eventCenter;
|
|
40
|
-
var childrenPositionMap = new Map();
|
|
41
|
-
// 在 group 旋转时,对组内的所有子节点也进行对应的旋转计算
|
|
42
|
-
eventCenter.on('node:rotate', function (_a) {
|
|
58
|
+
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
59
|
+
_this.childrenPositionMap = new Map();
|
|
60
|
+
_this.onNodeRotate = function (_a) {
|
|
43
61
|
var model = _a.model;
|
|
62
|
+
var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
|
|
63
|
+
var transformWithContainer = curGroup.transformWithContainer, isRestrict = curGroup.isRestrict;
|
|
64
|
+
var childrenPositionMap = _this.childrenPositionMap;
|
|
65
|
+
if (!transformWithContainer || isRestrict) {
|
|
66
|
+
// isRestrict限制模式下,当前model resize时不能小于占地面积
|
|
67
|
+
// 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
|
|
68
|
+
// 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
|
|
69
|
+
// 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
|
|
70
|
+
// 由于transformWidthContainer是控制rotate+resize,为保持transformWidthContainer本来的含义
|
|
71
|
+
// parent:resize=>child:resize不支持,那么parent:rotate=>child:rotate也不支持
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
44
74
|
// DONE: 目前操作是对分组内节点以节点中心旋转节点本身,而按照正常逻辑,应该是以分组中心,旋转节点(跟 Label 旋转操作逻辑一致)
|
|
45
75
|
if (model.id === curGroup.id) {
|
|
46
76
|
var center_1 = { x: curGroup.x, y: curGroup.y };
|
|
@@ -65,19 +95,33 @@ var DynamicGroupNode = /** @class */ (function (_super) {
|
|
|
65
95
|
}
|
|
66
96
|
});
|
|
67
97
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
98
|
+
};
|
|
99
|
+
_this.onNodeResize = function (_a) {
|
|
100
|
+
var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, model = _a.model, preData = _a.preData;
|
|
101
|
+
var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
|
|
102
|
+
var transformWithContainer = curGroup.transformWithContainer, isRestrict = curGroup.isRestrict;
|
|
103
|
+
if (!transformWithContainer || isRestrict) {
|
|
104
|
+
// isRestrict限制模式下,当前model resize时不能小于占地面积
|
|
105
|
+
// 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
|
|
106
|
+
// 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
|
|
107
|
+
// 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
73
110
|
if (model.id === curGroup.id) {
|
|
111
|
+
// node:resize是group已经改变width和height后的回调
|
|
112
|
+
// 因此这里一定得用preData(没resize改变width之前的值),而不是data/model
|
|
113
|
+
var properties = preData.properties;
|
|
114
|
+
var _c = properties || {}, groupWidth_1 = _c.width, groupHeight_1 = _c.height;
|
|
74
115
|
forEach(Array.from(curGroup.children), function (childId) {
|
|
75
116
|
var child = graphModel.getNodeModelById(childId);
|
|
76
117
|
if (child) {
|
|
118
|
+
// 根据比例去控制缩放dx和dy
|
|
119
|
+
var childDx = (child.width / groupWidth_1) * deltaX;
|
|
120
|
+
var childDy = (child.height / groupHeight_1) * deltaY;
|
|
77
121
|
// child.rotate = model.rotate
|
|
78
122
|
handleResize({
|
|
79
|
-
deltaX:
|
|
80
|
-
deltaY:
|
|
123
|
+
deltaX: childDx,
|
|
124
|
+
deltaY: childDy,
|
|
81
125
|
index: index,
|
|
82
126
|
nodeModel: child,
|
|
83
127
|
graphModel: graphModel,
|
|
@@ -86,7 +130,79 @@ var DynamicGroupNode = /** @class */ (function (_super) {
|
|
|
86
130
|
}
|
|
87
131
|
});
|
|
88
132
|
}
|
|
89
|
-
}
|
|
133
|
+
};
|
|
134
|
+
_this.onNodeMouseMove = function (_a) {
|
|
135
|
+
var deltaX = _a.deltaX, deltaY = _a.deltaY, data = _a.data;
|
|
136
|
+
var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
|
|
137
|
+
var transformModel = graphModel.transformModel;
|
|
138
|
+
var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y;
|
|
139
|
+
if (data.id === curGroup.id) {
|
|
140
|
+
var nodeIds = _this.getNodesInGroup(curGroup, graphModel);
|
|
141
|
+
// https://github.com/didi/LogicFlow/issues/1914
|
|
142
|
+
// 当调用lf.fitView()时,会改变整体的SCALE_X和SCALE_Y
|
|
143
|
+
// 由于group的mousemove是在drag.ts的this.onDragging()处理的,在onDragging()里面进行SCALE的处理
|
|
144
|
+
// 而"node:mousemove"emit出来跟onDragging()是同时的,也就是emit出来的数据是没有经过SCALE处理的坐标
|
|
145
|
+
// 因此这里需要增加SCALE的处理
|
|
146
|
+
graphModel.moveNodes(nodeIds, deltaX / SCALE_X, deltaY / SCALE_Y, true);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
_this.graphRendered = function () {
|
|
150
|
+
var model = _this.props.model;
|
|
151
|
+
// 初始化时,如果 this.isCollapsed 为 true,则主动触发一次折叠操作
|
|
152
|
+
if (model.isCollapsed) {
|
|
153
|
+
// https://github.com/didi/LogicFlow/issues/1918
|
|
154
|
+
// 当lf.render({nodes:[{分组节点}, {普通节点}]})时,由于是顺序遍历
|
|
155
|
+
// 会先触发分组Group节点的new Model => toggleCollapse()
|
|
156
|
+
// => 此时在graphModel.elementsModelMap找不到它的children,因为还没初始化,因此无法正确折叠子元素
|
|
157
|
+
// --------------------
|
|
158
|
+
// 当lf.render({nodes:[{普通节点}, {分组节点}]})时,
|
|
159
|
+
// 会先触发普通节点的new Model => graphModel.elementsModelMap.set(id, new Model())
|
|
160
|
+
// 然后再触发分组Group节点的new Model => toggleCollapse() =>
|
|
161
|
+
// 此时在graphModel.elementsModelMap能找到它的children了,因此可以正确折叠子元素
|
|
162
|
+
// --------------------
|
|
163
|
+
// 因此将整个初始化判断是否【主动触发一次折叠操作】放在"graph:rendered"全部渲染完成后再执行
|
|
164
|
+
model.toggleCollapse(true);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return _this;
|
|
168
|
+
}
|
|
169
|
+
DynamicGroupNode.prototype.componentDidMount = function () {
|
|
170
|
+
_super.prototype.componentDidMount.call(this);
|
|
171
|
+
var eventCenter = this.props.graphModel.eventCenter;
|
|
172
|
+
// 在 group 旋转时,对组内的所有子节点也进行对应的旋转计算
|
|
173
|
+
eventCenter.on('node:rotate', this.onNodeRotate);
|
|
174
|
+
// 在 group 缩放时,对组内的所有子节点也进行对应的缩放计算
|
|
175
|
+
eventCenter.on('node:resize', this.onNodeResize);
|
|
176
|
+
// 在 group 移动时,对组内的所有子节点也进行对应的移动计算
|
|
177
|
+
eventCenter.on('node:mousemove', this.onNodeMouseMove);
|
|
178
|
+
// 全部渲染完成后,判断是否【主动触发一次折叠操作】
|
|
179
|
+
eventCenter.on('graph:rendered', this.graphRendered);
|
|
180
|
+
};
|
|
181
|
+
DynamicGroupNode.prototype.componentWillUnmount = function () {
|
|
182
|
+
_super.prototype.componentWillUnmount.call(this);
|
|
183
|
+
var eventCenter = this.props.graphModel.eventCenter;
|
|
184
|
+
eventCenter.off('node:rotate', this.onNodeRotate);
|
|
185
|
+
eventCenter.off('node:resize', this.onNodeResize);
|
|
186
|
+
eventCenter.off('node:mousemove', this.onNodeMouseMove);
|
|
187
|
+
eventCenter.off('graph:rendered', this.graphRendered);
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* 获取分组内的节点
|
|
191
|
+
* @param groupModel
|
|
192
|
+
*/
|
|
193
|
+
DynamicGroupNode.prototype.getNodesInGroup = function (groupModel, graphModel) {
|
|
194
|
+
var _this = this;
|
|
195
|
+
var nodeIds = [];
|
|
196
|
+
if (groupModel.isGroup) {
|
|
197
|
+
forEach(Array.from(groupModel.children), function (nodeId) {
|
|
198
|
+
nodeIds.push(nodeId);
|
|
199
|
+
var nodeModel = graphModel.getNodeModelById(nodeId);
|
|
200
|
+
if (nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.isGroup) {
|
|
201
|
+
nodeIds = nodeIds.concat(_this.getNodesInGroup(nodeModel, graphModel));
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return nodeIds;
|
|
90
206
|
};
|
|
91
207
|
DynamicGroupNode.prototype.getResizeControl = function () {
|
|
92
208
|
var _a = this.props.model, resizable = _a.resizable, isCollapsed = _a.isCollapsed;
|
package/es/tools/label/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var Label = /** @class */ (function () {
|
|
|
75
75
|
}
|
|
76
76
|
else if (typeof curLabelConfig === 'string' || !curLabelConfig) {
|
|
77
77
|
// 3. 字符串或者为空的话就是 string 类型,基于 text 的数据合成 LabelConfig 信息(主要复用 text 的 x,y 信息)
|
|
78
|
-
var config = __assign(__assign({}, text), { content: curLabelConfig || text.value, draggable: element.BaseType === 'edge' ? edgeTextDraggable : nodeTextDraggable });
|
|
78
|
+
var config = __assign(__assign({}, text), { content: curLabelConfig || (text === null || text === void 0 ? void 0 : text.value), draggable: element.BaseType === 'edge' ? edgeTextDraggable : nodeTextDraggable });
|
|
79
79
|
formatConfig = config.value ? [config] : [];
|
|
80
80
|
}
|
|
81
81
|
// TODO: 针对 Edge,在 edge 更新时 重新计算 Label 的位置
|
|
@@ -233,7 +233,7 @@ var Label = /** @class */ (function () {
|
|
|
233
233
|
model.setProperty('_label', newLabelConfig);
|
|
234
234
|
});
|
|
235
235
|
// 监听元素新增事件,元素label格式化
|
|
236
|
-
eventCenter.on('node:add,edge:add', function (_a) {
|
|
236
|
+
eventCenter.on('node:dnd-add,node:add,edge:add', function (_a) {
|
|
237
237
|
var data = _a.data;
|
|
238
238
|
var element = graphModel.getElement(data.id);
|
|
239
239
|
if (element) {
|
|
@@ -55,19 +55,19 @@ function poolEvent(lf) {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
lf.on('node:resize', function (_a) {
|
|
58
|
-
var
|
|
59
|
-
var id =
|
|
60
|
-
var deltaHeight =
|
|
61
|
-
// const resizeDir =
|
|
58
|
+
var preData = _a.preData, data = _a.data;
|
|
59
|
+
var id = preData.id, type = preData.type;
|
|
60
|
+
var deltaHeight = data.height - preData.height;
|
|
61
|
+
// const resizeDir = data.y - preData.y > 0 ? 'below': 'above'
|
|
62
62
|
// 节点高度变高,y下移, 方向为below
|
|
63
63
|
// 节点高度变高, y上移, 方向为above
|
|
64
64
|
// 节点高度变小, y下移, 方向为above
|
|
65
65
|
// 节点高度变小, y上移,方向为below
|
|
66
66
|
var resizeDir = 'below';
|
|
67
|
-
if (deltaHeight > 0 &&
|
|
67
|
+
if (deltaHeight > 0 && data.y - preData.y < 0) {
|
|
68
68
|
resizeDir = 'above';
|
|
69
69
|
}
|
|
70
|
-
else if (deltaHeight < 0 &&
|
|
70
|
+
else if (deltaHeight < 0 && data.y - preData.y > 0) {
|
|
71
71
|
resizeDir = 'above';
|
|
72
72
|
}
|
|
73
73
|
if (type === 'pool') {
|
|
@@ -81,7 +81,7 @@ function poolEvent(lf) {
|
|
|
81
81
|
// 泳道缩放, 调整泳池
|
|
82
82
|
var groupId = lf.extension.group.nodeGroupMap.get(id);
|
|
83
83
|
if (groupId) {
|
|
84
|
-
lf.getNodeModelById(groupId).resize(id,
|
|
84
|
+
lf.getNodeModelById(groupId).resize(id, data);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
});
|