@logicflow/extension 2.0.8 → 2.0.10

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.
@@ -47,19 +47,19 @@ function poolEvent(lf) {
47
47
  }
48
48
  });
49
49
  lf.on('node:resize', function (_a) {
50
- var oldNodeSize = _a.oldNodeSize, newNodeSize = _a.newNodeSize;
51
- var id = oldNodeSize.id, type = oldNodeSize.type;
52
- var deltaHeight = newNodeSize.height - oldNodeSize.height;
53
- // const resizeDir = newNodeSize.y - oldNodeSize.y > 0 ? 'below': 'above'
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 && newNodeSize.y - oldNodeSize.y < 0) {
59
+ if (deltaHeight > 0 && data.y - preData.y < 0) {
60
60
  resizeDir = 'above';
61
61
  }
62
- else if (deltaHeight < 0 && newNodeSize.y - oldNodeSize.y > 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, newNodeSize);
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
- (_b = (_a = e
66
- .stopPropagation()(model)).foldGroup) === null || _b === void 0 ? void 0 : _b.call(_a, !properties.isFolded);
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
- var nodeIds = _this.getNodesInGroup(model);
450
- graphModel.moveNodes(nodeIds, deltaX, deltaY, true);
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
- var groupBounds = groupModel.getBounds();
458
- return isAllowMoveTo(groupBounds, model, deltaX, deltaY);
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
- transformWidthContainer: boolean;
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.transformWidthContainer = true;
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;
@@ -142,8 +145,15 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
142
145
  data.isGroup = true;
143
146
  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
147
  if (isCollapsed) {
148
+ // 如果当前是折叠模式
149
+ // 存入history的时候,将坐标恢复到未折叠前的坐标数据
150
+ // 因为拿出history数据的时候,会触发collapse()进行坐标的折叠计算
145
151
  data.x = x + expandWidth / 2 - collapsedWidth / 2;
146
152
  data.y = y + expandHeight / 2 - collapsedHeight / 2;
153
+ if (data.text) {
154
+ data.text.x = data.text.x + expandWidth / 2 - collapsedWidth / 2;
155
+ data.text.y = data.text.y + expandHeight / 2 - collapsedHeight / 2;
156
+ }
147
157
  }
148
158
  return data;
149
159
  };
@@ -408,7 +418,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
408
418
  ], DynamicGroupNodeModel.prototype, "groupAddable", void 0);
409
419
  __decorate([
410
420
  observable
411
- ], DynamicGroupNodeModel.prototype, "transformWidthContainer", void 0);
421
+ ], DynamicGroupNodeModel.prototype, "transformWithContainer", void 0);
412
422
  return DynamicGroupNodeModel;
413
423
  }(RectNodeModel));
414
424
  export { DynamicGroupNodeModel };
@@ -6,6 +6,11 @@ export interface IDynamicGroupNodeProps {
6
6
  }
7
7
  export declare class DynamicGroupNode<P extends IDynamicGroupNodeProps = IDynamicGroupNodeProps> extends RectNode<P> {
8
8
  componentDidMount(): void;
9
+ /**
10
+ * 获取分组内的节点
11
+ * @param groupModel
12
+ */
13
+ getNodesInGroup(groupModel: DynamicGroupNodeModel, graphModel: GraphModel): string[];
9
14
  getResizeControl(): h.JSX.Element | null;
10
15
  getAppendAreaShape(): h.JSX.Element | null;
11
16
  getCollapseIcon(sx: number, sy: number): string;
@@ -24,9 +24,8 @@ var __assign = (this && this.__assign) || function () {
24
24
  };
25
25
  return __assign.apply(this, arguments);
26
26
  };
27
- import { h, RectNode } from '@logicflow/core';
27
+ import { h, RectNode, handleResize, } from '@logicflow/core';
28
28
  import { forEach } from 'lodash-es';
29
- import { handleResize } from '@logicflow/core/es/util/resize';
30
29
  import { rotatePointAroundCenter } from '../tools/label/utils';
31
30
  var DynamicGroupNode = /** @class */ (function (_super) {
32
31
  __extends(DynamicGroupNode, _super);
@@ -34,6 +33,7 @@ var DynamicGroupNode = /** @class */ (function (_super) {
34
33
  return _super !== null && _super.apply(this, arguments) || this;
35
34
  }
36
35
  DynamicGroupNode.prototype.componentDidMount = function () {
36
+ var _this = this;
37
37
  _super.prototype.componentDidMount.call(this);
38
38
  var _a = this.props, curGroup = _a.model, graphModel = _a.graphModel;
39
39
  var eventCenter = graphModel.eventCenter;
@@ -41,6 +41,16 @@ var DynamicGroupNode = /** @class */ (function (_super) {
41
41
  // 在 group 旋转时,对组内的所有子节点也进行对应的旋转计算
42
42
  eventCenter.on('node:rotate', function (_a) {
43
43
  var model = _a.model;
44
+ var _b = _this.props.model, transformWithContainer = _b.transformWithContainer, isRestrict = _b.isRestrict;
45
+ if (!transformWithContainer || isRestrict) {
46
+ // isRestrict限制模式下,当前model resize时不能小于占地面积
47
+ // 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
48
+ // 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
49
+ // 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
50
+ // 由于transformWidthContainer是控制rotate+resize,为保持transformWidthContainer本来的含义
51
+ // parent:resize=>child:resize不支持,那么parent:rotate=>child:rotate也不支持
52
+ return;
53
+ }
44
54
  // DONE: 目前操作是对分组内节点以节点中心旋转节点本身,而按照正常逻辑,应该是以分组中心,旋转节点(跟 Label 旋转操作逻辑一致)
45
55
  if (model.id === curGroup.id) {
46
56
  var center_1 = { x: curGroup.x, y: curGroup.y };
@@ -68,16 +78,30 @@ var DynamicGroupNode = /** @class */ (function (_super) {
68
78
  });
69
79
  // 在 group 缩放时,对组内的所有子节点也进行对应的缩放计算
70
80
  eventCenter.on('node:resize', function (_a) {
71
- var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, model = _a.model;
72
- // TODO: 目前 Resize 的比例值有问题,导致缩放时,节点会变形,需要修复
81
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, model = _a.model, preData = _a.preData;
82
+ var _b = _this.props.model, transformWithContainer = _b.transformWithContainer, isRestrict = _b.isRestrict;
83
+ if (!transformWithContainer || isRestrict) {
84
+ // isRestrict限制模式下,当前model resize时不能小于占地面积
85
+ // 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
86
+ // 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
87
+ // 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
88
+ return;
89
+ }
73
90
  if (model.id === curGroup.id) {
91
+ // node:resize是group已经改变width和height后的回调
92
+ // 因此这里一定得用preData(没resize改变width之前的值),而不是data/model
93
+ var properties = preData.properties;
94
+ var _c = properties || {}, groupWidth_1 = _c.width, groupHeight_1 = _c.height;
74
95
  forEach(Array.from(curGroup.children), function (childId) {
75
96
  var child = graphModel.getNodeModelById(childId);
76
97
  if (child) {
98
+ // 根据比例去控制缩放dx和dy
99
+ var childDx = (child.width / groupWidth_1) * deltaX;
100
+ var childDy = (child.height / groupHeight_1) * deltaY;
77
101
  // child.rotate = model.rotate
78
102
  handleResize({
79
- deltaX: deltaX,
80
- deltaY: deltaY,
103
+ deltaX: childDx,
104
+ deltaY: childDy,
81
105
  index: index,
82
106
  nodeModel: child,
83
107
  graphModel: graphModel,
@@ -87,6 +111,33 @@ var DynamicGroupNode = /** @class */ (function (_super) {
87
111
  });
88
112
  }
89
113
  });
114
+ // 在 group 移动时,对组内的所有子节点也进行对应的移动计算
115
+ eventCenter.on('node:mousemove', function (_a) {
116
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, data = _a.data;
117
+ if (data.id === curGroup.id) {
118
+ var _b = _this.props, curGroup_1 = _b.model, graphModel_1 = _b.graphModel;
119
+ var nodeIds = _this.getNodesInGroup(curGroup_1, graphModel_1);
120
+ graphModel_1.moveNodes(nodeIds, deltaX, deltaY, true);
121
+ }
122
+ });
123
+ };
124
+ /**
125
+ * 获取分组内的节点
126
+ * @param groupModel
127
+ */
128
+ DynamicGroupNode.prototype.getNodesInGroup = function (groupModel, graphModel) {
129
+ var _this = this;
130
+ var nodeIds = [];
131
+ if (groupModel.isGroup) {
132
+ forEach(Array.from(groupModel.children), function (nodeId) {
133
+ nodeIds.push(nodeId);
134
+ var nodeModel = graphModel.getNodeModelById(nodeId);
135
+ if (nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.isGroup) {
136
+ nodeIds = nodeIds.concat(_this.getNodesInGroup(nodeModel, graphModel));
137
+ }
138
+ });
139
+ }
140
+ return nodeIds;
90
141
  };
91
142
  DynamicGroupNode.prototype.getResizeControl = function () {
92
143
  var _a = this.props.model, resizable = _a.resizable, isCollapsed = _a.isCollapsed;
@@ -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 oldNodeSize = _a.oldNodeSize, newNodeSize = _a.newNodeSize;
59
- var id = oldNodeSize.id, type = oldNodeSize.type;
60
- var deltaHeight = newNodeSize.height - oldNodeSize.height;
61
- // const resizeDir = newNodeSize.y - oldNodeSize.y > 0 ? 'below': 'above'
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 && newNodeSize.y - oldNodeSize.y < 0) {
67
+ if (deltaHeight > 0 && data.y - preData.y < 0) {
68
68
  resizeDir = 'above';
69
69
  }
70
- else if (deltaHeight < 0 && newNodeSize.y - oldNodeSize.y > 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, newNodeSize);
84
+ lf.getNodeModelById(groupId).resize(id, data);
85
85
  }
86
86
  }
87
87
  });
@@ -65,8 +65,8 @@ function SubProcessFactory() {
65
65
  y: y - height / 2 + 5,
66
66
  onClick: function (e) {
67
67
  var _a, _b;
68
- (_b = (_a = e
69
- .stopPropagation()(model)).foldGroup) === null || _b === void 0 ? void 0 : _b.call(_a, !properties.isFolded);
68
+ e.stopPropagation();
69
+ (_b = (_a = model).foldGroup) === null || _b === void 0 ? void 0 : _b.call(_a, !properties.isFolded);
70
70
  },
71
71
  }),
72
72
  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