@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.
@@ -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
@@ -224,6 +224,62 @@ var DynamicGroup = /** @class */ (function () {
224
224
  }
225
225
  }
226
226
  };
227
+ this.onNodeMove = function (_a) {
228
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, data = _a.data;
229
+ var id = data.id, x = data.x, y = data.y, properties = data.properties;
230
+ if (!properties) {
231
+ return;
232
+ }
233
+ var width = properties.width, height = properties.height;
234
+ var groupId = _this.nodeGroupMap.get(id);
235
+ if (!groupId) {
236
+ return;
237
+ }
238
+ var groupModel = _this.lf.getNodeModelById(groupId);
239
+ if (!groupModel || !groupModel.isRestrict || !groupModel.autoResize) {
240
+ return;
241
+ }
242
+ // 当父节点isRestrict=true & autoResize=true
243
+ // 子节点在父节点中移动时,父节点会自动调整大小
244
+ // step1: 计算出当前child的bounds
245
+ var newX = x + deltaX / 2;
246
+ var newY = y + deltaY / 2;
247
+ var minX = newX - width / 2;
248
+ var minY = newY - height / 2;
249
+ var maxX = newX + width / 2;
250
+ var maxY = newY + height / 2;
251
+ // step2:比较当前child.bounds与parent.bounds的差异,比如child.minX<parent.minX,那么parent.minX=child.minX
252
+ var hasChange = false;
253
+ var groupBounds = groupModel.getBounds();
254
+ var newGroupBounds = Object.assign({}, groupBounds);
255
+ if (minX < newGroupBounds.minX) {
256
+ newGroupBounds.minX = minX;
257
+ hasChange = true;
258
+ }
259
+ if (minY < newGroupBounds.minY) {
260
+ newGroupBounds.minY = minY;
261
+ hasChange = true;
262
+ }
263
+ if (maxX > newGroupBounds.maxX) {
264
+ newGroupBounds.maxX = maxX;
265
+ hasChange = true;
266
+ }
267
+ if (maxY > newGroupBounds.maxY) {
268
+ newGroupBounds.maxY = maxY;
269
+ hasChange = true;
270
+ }
271
+ if (!hasChange) {
272
+ return;
273
+ }
274
+ // step3: 根据当前parent.bounds去计算出最新的x、y、width、height
275
+ var newGroupX = newGroupBounds.minX + (newGroupBounds.maxX - newGroupBounds.minX) / 2;
276
+ var newGroupY = newGroupBounds.minY + (newGroupBounds.maxY - newGroupBounds.minY) / 2;
277
+ var newGroupWidth = newGroupBounds.maxX - newGroupBounds.minX;
278
+ var newGroupHeight = newGroupBounds.maxY - newGroupBounds.minY;
279
+ groupModel.moveTo(newGroupX, newGroupY);
280
+ groupModel.width = newGroupWidth;
281
+ groupModel.height = newGroupHeight;
282
+ };
227
283
  this.onGraphRendered = function (_a) {
228
284
  var data = _a.data;
229
285
  console.log('data', data);
@@ -244,24 +300,6 @@ var DynamicGroup = /** @class */ (function () {
244
300
  // 初始化插件,从监听事件开始及设置规则开始
245
301
  this.init();
246
302
  }
247
- /**
248
- * 获取分组内的节点
249
- * @param groupModel
250
- */
251
- DynamicGroup.prototype.getNodesInGroup = function (groupModel) {
252
- var _this = this;
253
- var nodeIds = [];
254
- if (groupModel.isGroup) {
255
- (0, lodash_es_1.forEach)(Array.from(groupModel.children), function (nodeId) {
256
- nodeIds.push(nodeId);
257
- var nodeModel = _this.lf.getNodeModelById(nodeId);
258
- if (nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.isGroup) {
259
- nodeIds = nodeIds.concat(_this.getNodesInGroup(nodeModel));
260
- }
261
- });
262
- }
263
- return nodeIds;
264
- };
265
303
  /**
266
304
  * 获取节点所属的分组
267
305
  * @param nodeId
@@ -442,6 +480,46 @@ var DynamicGroup = /** @class */ (function () {
442
480
  }
443
481
  return this.lf.graphModel.addEdge(__assign(__assign({}, newEdgeConfig), { sourceNodeId: sourceId, targetNodeId: targetId }));
444
482
  };
483
+ /**
484
+ * 检测group:resize后的bounds是否会小于children的bounds
485
+ * 限制group进行resize时不能小于内部的占地面积
486
+ * @param groupModel
487
+ * @param deltaX
488
+ * @param deltaY
489
+ * @param newWidth
490
+ * @param newHeight
491
+ */
492
+ DynamicGroup.prototype.checkGroupBoundsWithChildren = function (groupModel, deltaX, deltaY, newWidth, newHeight) {
493
+ if (groupModel.children) {
494
+ var children = groupModel.children, x = groupModel.x, y = groupModel.y;
495
+ // 根据deltaX和deltaY计算出当前model的bounds
496
+ var newX = x + deltaX / 2;
497
+ var newY = y + deltaY / 2;
498
+ var groupMinX = newX - newWidth / 2;
499
+ var groupMinY = newY - newHeight / 2;
500
+ var groupMaxX = newX + newWidth / 2;
501
+ var groupMaxY = newY + newHeight / 2;
502
+ var childrenArray = Array.from(children);
503
+ for (var i = 0; i < childrenArray.length; i++) {
504
+ var childId = childrenArray[i];
505
+ var child = this.lf.getNodeModelById(childId);
506
+ if (!child) {
507
+ continue;
508
+ }
509
+ var childBounds = child.getBounds();
510
+ var minX = childBounds.minX, minY = childBounds.minY, maxX = childBounds.maxX, maxY = childBounds.maxY;
511
+ // parent:resize后的bounds不能小于child:bounds,否则阻止其resize
512
+ var canResize = groupMinX <= minX &&
513
+ groupMinY <= minY &&
514
+ groupMaxX >= maxX &&
515
+ groupMaxY >= maxY;
516
+ if (!canResize) {
517
+ return false;
518
+ }
519
+ }
520
+ }
521
+ return true;
522
+ };
445
523
  /**
446
524
  * Group 插件的初始化方法
447
525
  * TODO:1. 待讨论,可能之前插件分类是有意义的 components, material, tools
@@ -463,16 +541,38 @@ var DynamicGroup = /** @class */ (function () {
463
541
  graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
464
542
  // 判断如果是 group,移动时需要同时移动组内的所有节点
465
543
  if (model.isGroup) {
466
- var nodeIds = _this.getNodesInGroup(model);
467
- graphModel.moveNodes(nodeIds, deltaX, deltaY, true);
544
+ // https://github.com/didi/LogicFlow/issues/1826
545
+ // 这里不应该触发移动子节点的逻辑,这里是判断是否可以移动,而不是触发移动逻辑
546
+ // 而且这里触发移动,会导致resize操作的this.x变动也会触发子item的this.x变动
547
+ // resize时的deltaX跟正常移动的deltaX是不同的
548
+ // const nodeIds = this.getNodesInGroup(model as DynamicGroupNodeModel)
549
+ // graphModel.moveNodes(nodeIds, deltaX, deltaY, true)
468
550
  return true;
469
551
  }
470
552
  var groupId = _this.nodeGroupMap.get(model.id);
471
553
  var groupModel = _this.lf.getNodeModelById(groupId);
472
554
  if (groupModel && groupModel.isRestrict) {
473
- // 如果移动的节点存在与分组中,且这个分组禁止子节点移出去
474
- var groupBounds = groupModel.getBounds();
475
- return (0, utils_1.isAllowMoveTo)(groupBounds, model, deltaX, deltaY);
555
+ if (groupModel.autoResize) {
556
+ // 子节点在父节点中移动时,父节点会自动调整大小
557
+ // 在node:mousemove中进行父节点的调整
558
+ return true;
559
+ }
560
+ else {
561
+ // 如果移动的节点存在于某个分组中,且这个分组禁止子节点移出去
562
+ var groupBounds = groupModel.getBounds();
563
+ return (0, utils_1.isAllowMoveTo)(groupBounds, model, deltaX, deltaY);
564
+ }
565
+ }
566
+ return true;
567
+ });
568
+ // https://github.com/didi/LogicFlow/issues/1442
569
+ // https://github.com/didi/LogicFlow/issues/937
570
+ // 添加分组节点resize规则
571
+ // isRestrict限制模式下,当前model resize时不能小于children的占地面积
572
+ // 并且在isRestrict限制模式下,transformWidthContainer即使设置为true,也无效
573
+ graphModel.addNodeResizeRules(function (model, deltaX, deltaY, width, height) {
574
+ if (model.isGroup && model.isRestrict) {
575
+ return _this.checkGroupBoundsWithChildren(model, deltaX, deltaY, width, height);
476
576
  }
477
577
  return true;
478
578
  });
@@ -481,6 +581,7 @@ var DynamicGroup = /** @class */ (function () {
481
581
  lf.on('node:delete', this.removeNodeFromGroup);
482
582
  lf.on('node:drag,node:dnd-drag', this.setActiveGroup);
483
583
  lf.on('node:click', this.onNodeSelect);
584
+ lf.on('node:mousemove', this.onNodeMove);
484
585
  lf.on('graph:rendered', this.onGraphRendered);
485
586
  lf.on('graph:updated', function (_a) {
486
587
  var data = _a.data;
@@ -538,6 +639,7 @@ var DynamicGroup = /** @class */ (function () {
538
639
  this.lf.off('node:delete', this.removeNodeFromGroup);
539
640
  this.lf.off('node:drag,node:dnd-drag', this.setActiveGroup);
540
641
  this.lf.off('node:click', this.onNodeSelect);
642
+ this.lf.off('node:mousemove', this.onNodeMove);
541
643
  this.lf.off('graph:rendered', this.onGraphRendered);
542
644
  // 还原 lf.addElements 方法?
543
645
  // 移除 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;
@@ -74,6 +74,8 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
74
74
  _this.isGroup = true;
75
75
  // 是否限制组内节点的移动范围。默认不限制 TODO: 完善该功能
76
76
  _this.isRestrict = false;
77
+ // isRestrict 模式启用时,如果同时设置 autoResize 为 true,那么子节点在父节点中移动时,父节点会自动调整大小
78
+ _this.autoResize = false;
77
79
  // 分组节点是否可以折叠
78
80
  _this.collapsible = true;
79
81
  // 当前组是否收起状态
@@ -81,7 +83,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
81
83
  // 当前分组是否在可添加状态 - 实时状态
82
84
  _this.groupAddable = false;
83
85
  // 缩放或旋转容器时,是否缩放或旋转组内节点
84
- _this.transformWidthContainer = true;
86
+ _this.transformWithContainer = false;
85
87
  _this.childrenLastCollapseStateDict = new Map();
86
88
  _this.childrenLastCollapseStateDict = new Map();
87
89
  _this.initNodeData(data);
@@ -91,7 +93,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
91
93
  DynamicGroupNodeModel.prototype.initNodeData = function (data) {
92
94
  var _a;
93
95
  _super.prototype.initNodeData.call(this, data);
94
- 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;
96
+ 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;
95
97
  this.children = children ? new Set(children) : new Set();
96
98
  this.zIndex = zIndex !== null && zIndex !== void 0 ? zIndex : DEFAULT_BOTTOM_Z_INDEX;
97
99
  this.isCollapsed = isCollapsed !== null && isCollapsed !== void 0 ? isCollapsed : false;
@@ -105,6 +107,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
105
107
  this.collapsedWidth = collapsedWidth !== null && collapsedWidth !== void 0 ? collapsedWidth : DEFAULT_GROUP_COLLAPSE_WIDTH;
106
108
  this.collapsedHeight = collapsedHeight !== null && collapsedHeight !== void 0 ? collapsedHeight : DEFAULT_GROUP_COLLAPSE_HEIGHT;
107
109
  this.isRestrict = isRestrict !== null && isRestrict !== void 0 ? isRestrict : false;
110
+ this.transformWithContainer = transformWithContainer !== null && transformWithContainer !== void 0 ? transformWithContainer : false;
108
111
  this.autoResize = autoResize !== null && autoResize !== void 0 ? autoResize : false;
109
112
  this.collapsible = collapsible !== null && collapsible !== void 0 ? collapsible : true;
110
113
  this.autoToFront = autoToFront !== null && autoToFront !== void 0 ? autoToFront : false;
@@ -114,10 +117,6 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
114
117
  };
115
118
  DynamicGroupNodeModel.prototype.setAttributes = function () {
116
119
  _super.prototype.setAttributes.call(this);
117
- // 初始化时,如果 this.isCollapsed 为 true,则主动触发一次折叠操作
118
- if (this.isCollapsed) {
119
- this.toggleCollapse(true);
120
- }
121
120
  };
122
121
  DynamicGroupNodeModel.prototype.getData = function () {
123
122
  var _this = this;
@@ -145,8 +144,15 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
145
144
  data.isGroup = true;
146
145
  var _a = this, x = _a.x, y = _a.y, collapsedWidth = _a.collapsedWidth, collapsedHeight = _a.collapsedHeight, expandWidth = _a.expandWidth, expandHeight = _a.expandHeight, isCollapsed = _a.isCollapsed;
147
146
  if (isCollapsed) {
147
+ // 如果当前是折叠模式
148
+ // 存入history的时候,将坐标恢复到未折叠前的坐标数据
149
+ // 因为拿出history数据的时候,会触发collapse()进行坐标的折叠计算
148
150
  data.x = x + expandWidth / 2 - collapsedWidth / 2;
149
151
  data.y = y + expandHeight / 2 - collapsedHeight / 2;
152
+ if (data.text) {
153
+ data.text.x = data.text.x + expandWidth / 2 - collapsedWidth / 2;
154
+ data.text.y = data.text.y + expandHeight / 2 - collapsedHeight / 2;
155
+ }
150
156
  }
151
157
  return data;
152
158
  };
@@ -335,8 +341,8 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
335
341
  * TODO: 如何重写该方法呢?
336
342
  * @param _nodeData
337
343
  */
344
+ // eslint-disable-next-line
338
345
  DynamicGroupNodeModel.prototype.isAllowAppendIn = function (_nodeData) {
339
- console.info('_nodeData', _nodeData);
340
346
  // TODO: 此处使用 this.properties.groupAddable 还是 this.groupAddable
341
347
  // this.groupAddable 是否存在更新不及时的问题
342
348
  return true;
@@ -411,7 +417,7 @@ var DynamicGroupNodeModel = /** @class */ (function (_super) {
411
417
  ], DynamicGroupNodeModel.prototype, "groupAddable", void 0);
412
418
  __decorate([
413
419
  core_1.observable
414
- ], DynamicGroupNodeModel.prototype, "transformWidthContainer", void 0);
420
+ ], DynamicGroupNodeModel.prototype, "transformWithContainer", void 0);
415
421
  return DynamicGroupNodeModel;
416
422
  }(core_1.RectNodeModel));
417
423
  exports.DynamicGroupNodeModel = 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;
@@ -25,25 +25,55 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
+ var __read = (this && this.__read) || function (o, n) {
29
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
30
+ if (!m) return o;
31
+ var i = m.call(o), r, ar = [], e;
32
+ try {
33
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
+ }
35
+ catch (error) { e = { error: error }; }
36
+ finally {
37
+ try {
38
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
+ }
40
+ finally { if (e) throw e.error; }
41
+ }
42
+ return ar;
43
+ };
44
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
46
+ if (ar || !(i in from)) {
47
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
48
+ ar[i] = from[i];
49
+ }
50
+ }
51
+ return to.concat(ar || Array.prototype.slice.call(from));
52
+ };
28
53
  Object.defineProperty(exports, "__esModule", { value: true });
29
54
  exports.DynamicGroupNode = void 0;
30
55
  var core_1 = require("@logicflow/core");
31
56
  var lodash_es_1 = require("lodash-es");
32
- var resize_1 = require("@logicflow/core/es/util/resize");
33
57
  var utils_1 = require("../tools/label/utils");
34
58
  var DynamicGroupNode = /** @class */ (function (_super) {
35
59
  __extends(DynamicGroupNode, _super);
36
60
  function DynamicGroupNode() {
37
- return _super !== null && _super.apply(this, arguments) || this;
38
- }
39
- DynamicGroupNode.prototype.componentDidMount = function () {
40
- _super.prototype.componentDidMount.call(this);
41
- var _a = this.props, curGroup = _a.model, graphModel = _a.graphModel;
42
- var eventCenter = graphModel.eventCenter;
43
- var childrenPositionMap = new Map();
44
- // 在 group 旋转时,对组内的所有子节点也进行对应的旋转计算
45
- eventCenter.on('node:rotate', function (_a) {
61
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
62
+ _this.childrenPositionMap = new Map();
63
+ _this.onNodeRotate = function (_a) {
46
64
  var model = _a.model;
65
+ var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
66
+ var transformWithContainer = curGroup.transformWithContainer, isRestrict = curGroup.isRestrict;
67
+ var childrenPositionMap = _this.childrenPositionMap;
68
+ if (!transformWithContainer || isRestrict) {
69
+ // isRestrict限制模式下,当前model resize时不能小于占地面积
70
+ // 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
71
+ // 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
72
+ // 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
73
+ // 由于transformWidthContainer是控制rotate+resize,为保持transformWidthContainer本来的含义
74
+ // parent:resize=>child:resize不支持,那么parent:rotate=>child:rotate也不支持
75
+ return;
76
+ }
47
77
  // DONE: 目前操作是对分组内节点以节点中心旋转节点本身,而按照正常逻辑,应该是以分组中心,旋转节点(跟 Label 旋转操作逻辑一致)
48
78
  if (model.id === curGroup.id) {
49
79
  var center_1 = { x: curGroup.x, y: curGroup.y };
@@ -68,19 +98,33 @@ var DynamicGroupNode = /** @class */ (function (_super) {
68
98
  }
69
99
  });
70
100
  }
71
- });
72
- // group 缩放时,对组内的所有子节点也进行对应的缩放计算
73
- eventCenter.on('node:resize', function (_a) {
74
- var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, model = _a.model;
75
- // TODO: 目前 Resize 的比例值有问题,导致缩放时,节点会变形,需要修复
101
+ };
102
+ _this.onNodeResize = function (_a) {
103
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, model = _a.model, preData = _a.preData;
104
+ var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
105
+ var transformWithContainer = curGroup.transformWithContainer, isRestrict = curGroup.isRestrict;
106
+ if (!transformWithContainer || isRestrict) {
107
+ // isRestrict限制模式下,当前model resize时不能小于占地面积
108
+ // 由于parent:resize=>child:resize计算复杂,需要根据child:resize的判定结果来递归判断parent能否resize
109
+ // 不符合目前 parent:resize成功后emit事件 -> 触发child:resize 的代码交互模式
110
+ // 因此isRestrict限制模式下不支持联动(parent:resize=>child:resize)
111
+ return;
112
+ }
76
113
  if (model.id === curGroup.id) {
114
+ // node:resize是group已经改变width和height后的回调
115
+ // 因此这里一定得用preData(没resize改变width之前的值),而不是data/model
116
+ var properties = preData.properties;
117
+ var _c = properties || {}, groupWidth_1 = _c.width, groupHeight_1 = _c.height;
77
118
  (0, lodash_es_1.forEach)(Array.from(curGroup.children), function (childId) {
78
119
  var child = graphModel.getNodeModelById(childId);
79
120
  if (child) {
121
+ // 根据比例去控制缩放dx和dy
122
+ var childDx = (child.width / groupWidth_1) * deltaX;
123
+ var childDy = (child.height / groupHeight_1) * deltaY;
80
124
  // child.rotate = model.rotate
81
- (0, resize_1.handleResize)({
82
- deltaX: deltaX,
83
- deltaY: deltaY,
125
+ (0, core_1.handleResize)({
126
+ deltaX: childDx,
127
+ deltaY: childDy,
84
128
  index: index,
85
129
  nodeModel: child,
86
130
  graphModel: graphModel,
@@ -89,7 +133,79 @@ var DynamicGroupNode = /** @class */ (function (_super) {
89
133
  }
90
134
  });
91
135
  }
92
- });
136
+ };
137
+ _this.onNodeMouseMove = function (_a) {
138
+ var deltaX = _a.deltaX, deltaY = _a.deltaY, data = _a.data;
139
+ var _b = _this.props, curGroup = _b.model, graphModel = _b.graphModel;
140
+ var transformModel = graphModel.transformModel;
141
+ var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y;
142
+ if (data.id === curGroup.id) {
143
+ var nodeIds = _this.getNodesInGroup(curGroup, graphModel);
144
+ // https://github.com/didi/LogicFlow/issues/1914
145
+ // 当调用lf.fitView()时,会改变整体的SCALE_X和SCALE_Y
146
+ // 由于group的mousemove是在drag.ts的this.onDragging()处理的,在onDragging()里面进行SCALE的处理
147
+ // 而"node:mousemove"emit出来跟onDragging()是同时的,也就是emit出来的数据是没有经过SCALE处理的坐标
148
+ // 因此这里需要增加SCALE的处理
149
+ graphModel.moveNodes(nodeIds, deltaX / SCALE_X, deltaY / SCALE_Y, true);
150
+ }
151
+ };
152
+ _this.graphRendered = function () {
153
+ var model = _this.props.model;
154
+ // 初始化时,如果 this.isCollapsed 为 true,则主动触发一次折叠操作
155
+ if (model.isCollapsed) {
156
+ // https://github.com/didi/LogicFlow/issues/1918
157
+ // 当lf.render({nodes:[{分组节点}, {普通节点}]})时,由于是顺序遍历
158
+ // 会先触发分组Group节点的new Model => toggleCollapse()
159
+ // => 此时在graphModel.elementsModelMap找不到它的children,因为还没初始化,因此无法正确折叠子元素
160
+ // --------------------
161
+ // 当lf.render({nodes:[{普通节点}, {分组节点}]})时,
162
+ // 会先触发普通节点的new Model => graphModel.elementsModelMap.set(id, new Model())
163
+ // 然后再触发分组Group节点的new Model => toggleCollapse() =>
164
+ // 此时在graphModel.elementsModelMap能找到它的children了,因此可以正确折叠子元素
165
+ // --------------------
166
+ // 因此将整个初始化判断是否【主动触发一次折叠操作】放在"graph:rendered"全部渲染完成后再执行
167
+ model.toggleCollapse(true);
168
+ }
169
+ };
170
+ return _this;
171
+ }
172
+ DynamicGroupNode.prototype.componentDidMount = function () {
173
+ _super.prototype.componentDidMount.call(this);
174
+ var eventCenter = this.props.graphModel.eventCenter;
175
+ // 在 group 旋转时,对组内的所有子节点也进行对应的旋转计算
176
+ eventCenter.on('node:rotate', this.onNodeRotate);
177
+ // 在 group 缩放时,对组内的所有子节点也进行对应的缩放计算
178
+ eventCenter.on('node:resize', this.onNodeResize);
179
+ // 在 group 移动时,对组内的所有子节点也进行对应的移动计算
180
+ eventCenter.on('node:mousemove', this.onNodeMouseMove);
181
+ // 全部渲染完成后,判断是否【主动触发一次折叠操作】
182
+ eventCenter.on('graph:rendered', this.graphRendered);
183
+ };
184
+ DynamicGroupNode.prototype.componentWillUnmount = function () {
185
+ _super.prototype.componentWillUnmount.call(this);
186
+ var eventCenter = this.props.graphModel.eventCenter;
187
+ eventCenter.off('node:rotate', this.onNodeRotate);
188
+ eventCenter.off('node:resize', this.onNodeResize);
189
+ eventCenter.off('node:mousemove', this.onNodeMouseMove);
190
+ eventCenter.off('graph:rendered', this.graphRendered);
191
+ };
192
+ /**
193
+ * 获取分组内的节点
194
+ * @param groupModel
195
+ */
196
+ DynamicGroupNode.prototype.getNodesInGroup = function (groupModel, graphModel) {
197
+ var _this = this;
198
+ var nodeIds = [];
199
+ if (groupModel.isGroup) {
200
+ (0, lodash_es_1.forEach)(Array.from(groupModel.children), function (nodeId) {
201
+ nodeIds.push(nodeId);
202
+ var nodeModel = graphModel.getNodeModelById(nodeId);
203
+ if (nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.isGroup) {
204
+ nodeIds = nodeIds.concat(_this.getNodesInGroup(nodeModel, graphModel));
205
+ }
206
+ });
207
+ }
208
+ return nodeIds;
93
209
  };
94
210
  DynamicGroupNode.prototype.getResizeControl = function () {
95
211
  var _a = this.props.model, resizable = _a.resizable, isCollapsed = _a.isCollapsed;
@@ -81,7 +81,7 @@ var Label = /** @class */ (function () {
81
81
  }
82
82
  else if (typeof curLabelConfig === 'string' || !curLabelConfig) {
83
83
  // 3. 字符串或者为空的话就是 string 类型,基于 text 的数据合成 LabelConfig 信息(主要复用 text 的 x,y 信息)
84
- var config = __assign(__assign({}, text), { content: curLabelConfig || text.value, draggable: element.BaseType === 'edge' ? edgeTextDraggable : nodeTextDraggable });
84
+ var config = __assign(__assign({}, text), { content: curLabelConfig || (text === null || text === void 0 ? void 0 : text.value), draggable: element.BaseType === 'edge' ? edgeTextDraggable : nodeTextDraggable });
85
85
  formatConfig = config.value ? [config] : [];
86
86
  }
87
87
  // TODO: 针对 Edge,在 edge 更新时 重新计算 Label 的位置
@@ -239,7 +239,7 @@ var Label = /** @class */ (function () {
239
239
  model.setProperty('_label', newLabelConfig);
240
240
  });
241
241
  // 监听元素新增事件,元素label格式化
242
- eventCenter.on('node:add,edge:add', function (_a) {
242
+ eventCenter.on('node:dnd-add,node:add,edge:add', function (_a) {
243
243
  var data = _a.data;
244
244
  var element = graphModel.getElement(data.id);
245
245
  if (element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -20,7 +20,7 @@
20
20
  "author": "Logicflow-Team",
21
21
  "license": "Apache-2.0",
22
22
  "peerDependencies": {
23
- "@logicflow/core": "2.0.5"
23
+ "@logicflow/core": "2.0.7"
24
24
  },
25
25
  "dependencies": {
26
26
  "@antv/hierarchy": "^0.6.11",
@@ -31,7 +31,7 @@
31
31
  "preact": "^10.17.1",
32
32
  "rangy": "^1.3.1",
33
33
  "vanilla-picker": "^2.12.3",
34
- "@logicflow/core": "2.0.5"
34
+ "@logicflow/core": "2.0.7"
35
35
  },
36
36
  "devDependencies": {
37
37
  "less": "^4.1.1",