@logicflow/extension 1.1.29 → 1.1.30

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.
Files changed (49) hide show
  1. package/cjs/NodeResize/Control/Control.js +72 -13
  2. package/cjs/NodeResize/Node/DiamondResize.js +16 -0
  3. package/cjs/NodeResize/Node/EllipseResize.js +16 -0
  4. package/cjs/NodeResize/Node/HtmlResize.js +16 -0
  5. package/cjs/NodeResize/Node/RectResize.js +16 -0
  6. package/cjs/materials/group/GroupNode.js +11 -4
  7. package/cjs/materials/group/index.js +75 -19
  8. package/es/NodeResize/Control/Control.d.ts +4 -1
  9. package/es/NodeResize/Control/Control.js +72 -13
  10. package/es/NodeResize/Node/DiamondResize.d.ts +2 -0
  11. package/es/NodeResize/Node/DiamondResize.js +16 -0
  12. package/es/NodeResize/Node/EllipseResize.d.ts +2 -0
  13. package/es/NodeResize/Node/EllipseResize.js +16 -0
  14. package/es/NodeResize/Node/HtmlResize.d.ts +2 -0
  15. package/es/NodeResize/Node/HtmlResize.js +16 -0
  16. package/es/NodeResize/Node/RectResize.d.ts +2 -0
  17. package/es/NodeResize/Node/RectResize.js +16 -0
  18. package/es/materials/group/GroupNode.d.ts +5 -1
  19. package/es/materials/group/GroupNode.js +11 -4
  20. package/es/materials/group/index.d.ts +13 -1
  21. package/es/materials/group/index.js +75 -19
  22. package/lib/AutoLayout.js +1 -1
  23. package/lib/BpmnAdapter.js +1 -1
  24. package/lib/BpmnElement.js +1 -1
  25. package/lib/ContextMenu.js +1 -1
  26. package/lib/Control.js +1 -1
  27. package/lib/CurvedEdge.js +1 -1
  28. package/lib/DndPanel.js +1 -1
  29. package/lib/FlowPath.js +1 -1
  30. package/lib/Group.js +1 -1
  31. package/lib/Highlight.js +1 -1
  32. package/lib/InsertNodeInPolyline.js +1 -1
  33. package/lib/Menu.js +1 -1
  34. package/lib/MiniMap.js +1 -1
  35. package/lib/NodeResize.js +1 -1
  36. package/lib/RectLabelNode.js +1 -1
  37. package/lib/SelectionSelect.js +1 -1
  38. package/lib/Snapshot.js +1 -1
  39. package/lib/TurboAdapter.js +1 -1
  40. package/lib/lfJson2Xml.js +1 -1
  41. package/lib/lfXml2Json.js +1 -1
  42. package/package.json +2 -2
  43. package/types/NodeResize/Control/Control.d.ts +4 -1
  44. package/types/NodeResize/Node/DiamondResize.d.ts +2 -0
  45. package/types/NodeResize/Node/EllipseResize.d.ts +2 -0
  46. package/types/NodeResize/Node/HtmlResize.d.ts +2 -0
  47. package/types/NodeResize/Node/RectResize.d.ts +2 -0
  48. package/types/materials/group/GroupNode.d.ts +5 -1
  49. package/types/materials/group/index.d.ts +13 -1
@@ -59,8 +59,64 @@ var Control = /** @class */ (function (_super) {
59
59
  };
60
60
  // 计算control拖动后,节点的宽高
61
61
  _this.getResize = function (_a) {
62
- var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
63
- var resize = { width: width, height: height };
62
+ var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, PCTResizeInfo = _a.PCTResizeInfo, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
63
+ var resize = { width: width, height: height, deltaX: deltaX, deltaY: deltaY };
64
+ if (PCTResizeInfo) {
65
+ var sensitivity = 4; // 越低越灵敏
66
+ var deltaScale = 0;
67
+ var combineDleta = 0;
68
+ switch (index) {
69
+ case 0:
70
+ combineDleta = (deltaX * -1 - deltaY) / sensitivity;
71
+ break;
72
+ case 1:
73
+ combineDleta = (deltaX - deltaY) / sensitivity;
74
+ break;
75
+ case 2:
76
+ combineDleta = (deltaX + deltaY) / sensitivity;
77
+ break;
78
+ case 3:
79
+ combineDleta = (deltaX * -1 + deltaY) / sensitivity;
80
+ break;
81
+ default:
82
+ break;
83
+ }
84
+ if (combineDleta !== 0) {
85
+ deltaScale = Math.round((combineDleta / PCTResizeInfo.ResizeBasis.basisHeight)
86
+ * 100000) / 1000;
87
+ }
88
+ PCTResizeInfo.ResizePCT.widthPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.widthPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
89
+ PCTResizeInfo.ResizePCT.hightPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.hightPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
90
+ var spcWidth = Math.round((PCTResizeInfo.ResizePCT.widthPCT
91
+ * PCTResizeInfo.ResizeBasis.basisWidth) / 100);
92
+ var spcHeight = Math.round((PCTResizeInfo.ResizePCT.hightPCT
93
+ * PCTResizeInfo.ResizeBasis.basisHeight) / 100);
94
+ switch (index) {
95
+ case 0:
96
+ deltaX = width - spcWidth;
97
+ deltaY = height - spcHeight;
98
+ break;
99
+ case 1:
100
+ deltaX = spcWidth - width;
101
+ deltaY = height - spcHeight;
102
+ break;
103
+ case 2:
104
+ deltaX = spcWidth - width;
105
+ deltaY = spcHeight - height;
106
+ break;
107
+ case 3:
108
+ deltaX = width - spcWidth;
109
+ deltaY = spcHeight - height;
110
+ break;
111
+ default:
112
+ break;
113
+ }
114
+ resize.width = spcWidth;
115
+ resize.height = spcHeight;
116
+ resize.deltaX = deltaX / pct;
117
+ resize.deltaY = deltaY / pct;
118
+ return resize;
119
+ }
64
120
  switch (index) {
65
121
  case 0:
66
122
  resize.width = width - deltaX * pct;
@@ -71,7 +127,7 @@ var Control = /** @class */ (function (_super) {
71
127
  resize.height = height - deltaY * pct;
72
128
  break;
73
129
  case 2:
74
- resize.width = width + deltaX;
130
+ resize.width = width + deltaX * pct;
75
131
  resize.height = height + deltaY * pct;
76
132
  break;
77
133
  case 3:
@@ -86,7 +142,7 @@ var Control = /** @class */ (function (_super) {
86
142
  // 矩形更新
87
143
  _this.updateRect = function (_a) {
88
144
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
89
- var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius;
145
+ var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius, PCTResizeInfo = _b.PCTResizeInfo;
90
146
  // 更新中心点位置,更新文案位置
91
147
  var index = _this.index;
92
148
  var size = _this.getResize({
@@ -95,6 +151,7 @@ var Control = /** @class */ (function (_super) {
95
151
  deltaY: deltaY,
96
152
  width: width,
97
153
  height: height,
154
+ PCTResizeInfo: PCTResizeInfo,
98
155
  pct: 1,
99
156
  });
100
157
  // 限制放大缩小的最大最小范围
@@ -107,7 +164,7 @@ var Control = /** @class */ (function (_super) {
107
164
  _this.dragHandler.cancelDrag();
108
165
  return;
109
166
  }
110
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
167
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
111
168
  // 更新宽高
112
169
  _this.nodeModel.width = size.width;
113
170
  _this.nodeModel.height = size.height;
@@ -154,7 +211,7 @@ var Control = /** @class */ (function (_super) {
154
211
  // 椭圆更新
155
212
  _this.updateEllipse = function (_a) {
156
213
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
157
- var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
214
+ var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
158
215
  var index = _this.index;
159
216
  var width = rx;
160
217
  var height = ry;
@@ -164,6 +221,7 @@ var Control = /** @class */ (function (_super) {
164
221
  deltaY: deltaY,
165
222
  width: width,
166
223
  height: height,
224
+ PCTResizeInfo: PCTResizeInfo,
167
225
  pct: 1 / 2,
168
226
  });
169
227
  // 限制放大缩小的最大最小范围
@@ -176,12 +234,12 @@ var Control = /** @class */ (function (_super) {
176
234
  return;
177
235
  }
178
236
  // 更新中心点位置,更新文案位置
179
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
237
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
180
238
  // 更新rx ry,宽高为计算属性自动更新
181
239
  // @ts-ignore
182
- _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
240
+ _this.nodeModel.rx = size.width;
183
241
  // @ts-ignore
184
- _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
242
+ _this.nodeModel.ry = size.height;
185
243
  _this.nodeModel.setProperties({
186
244
  nodeSize: {
187
245
  rx: size.width,
@@ -218,7 +276,7 @@ var Control = /** @class */ (function (_super) {
218
276
  // 菱形更新
219
277
  _this.updateDiamond = function (_a) {
220
278
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
221
- var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
279
+ var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
222
280
  var index = _this.index;
223
281
  var width = rx;
224
282
  var height = ry;
@@ -228,6 +286,7 @@ var Control = /** @class */ (function (_super) {
228
286
  deltaY: deltaY,
229
287
  width: width,
230
288
  height: height,
289
+ PCTResizeInfo: PCTResizeInfo,
231
290
  pct: 1 / 2,
232
291
  });
233
292
  // 限制放大缩小的最大最小范围
@@ -240,12 +299,12 @@ var Control = /** @class */ (function (_super) {
240
299
  return;
241
300
  }
242
301
  // 更新中心点位置,更新文案位置
243
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
302
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
244
303
  // 更新rx ry,宽高为计算属性自动更新
245
304
  // @ts-ignore
246
- _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
305
+ _this.nodeModel.rx = size.width;
247
306
  // @ts-ignore
248
- _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
307
+ _this.nodeModel.ry = size.height;
249
308
  _this.nodeModel.setProperties({
250
309
  nodeSize: {
251
310
  rx: size.width,
@@ -72,6 +72,22 @@ var DiamondResizeModel = /** @class */ (function (_super) {
72
72
  stroke: '#000000',
73
73
  };
74
74
  };
75
+ // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
76
+ DiamondResizeModel.prototype.enableProportionResize = function (turnOn) {
77
+ if (turnOn === void 0) { turnOn = true; }
78
+ if (turnOn) {
79
+ var ResizePCT = { widthPCT: 100, hightPCT: 100 };
80
+ var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
81
+ var ScaleLimit = {
82
+ maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
83
+ minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
84
+ };
85
+ this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
86
+ }
87
+ else {
88
+ delete this.PCTResizeInfo;
89
+ }
90
+ };
75
91
  return DiamondResizeModel;
76
92
  }(core_1.DiamondNodeModel));
77
93
  var DiamondResizeView = /** @class */ (function (_super) {
@@ -59,6 +59,22 @@ var EllipseResizeModel = /** @class */ (function (_super) {
59
59
  stroke: '#000000',
60
60
  };
61
61
  };
62
+ // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
63
+ EllipseResizeModel.prototype.enableProportionResize = function (turnOn) {
64
+ if (turnOn === void 0) { turnOn = true; }
65
+ if (turnOn) {
66
+ var ResizePCT = { widthPCT: 100, hightPCT: 100 };
67
+ var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
68
+ var ScaleLimit = {
69
+ maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
70
+ minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
71
+ };
72
+ this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
73
+ }
74
+ else {
75
+ delete this.PCTResizeInfo;
76
+ }
77
+ };
62
78
  return EllipseResizeModel;
63
79
  }(core_1.EllipseNodeModel));
64
80
  var EllipseResizeView = /** @class */ (function (_super) {
@@ -59,6 +59,22 @@ var HtmlResizeModel = /** @class */ (function (_super) {
59
59
  stroke: '#000000',
60
60
  };
61
61
  };
62
+ // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
63
+ HtmlResizeModel.prototype.enableProportionResize = function (turnOn) {
64
+ if (turnOn === void 0) { turnOn = true; }
65
+ if (turnOn) {
66
+ var ResizePCT = { widthPCT: 100, hightPCT: 100 };
67
+ var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
68
+ var ScaleLimit = {
69
+ maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
70
+ minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
71
+ };
72
+ this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
73
+ }
74
+ else {
75
+ delete this.PCTResizeInfo;
76
+ }
77
+ };
62
78
  return HtmlResizeModel;
63
79
  }(core_1.HtmlNodeModel));
64
80
  var HtmlResizeView = /** @class */ (function (_super) {
@@ -63,6 +63,22 @@ var RectResizeModel = /** @class */ (function (_super) {
63
63
  RectResizeModel.prototype.resize = function (deltaX, deltaY) {
64
64
  console.log(deltaX, deltaY);
65
65
  };
66
+ // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
67
+ RectResizeModel.prototype.enableProportionResize = function (turnOn) {
68
+ if (turnOn === void 0) { turnOn = true; }
69
+ if (turnOn) {
70
+ var ResizePCT = { widthPCT: 100, hightPCT: 100 };
71
+ var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
72
+ var ScaleLimit = {
73
+ maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
74
+ minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
75
+ };
76
+ this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
77
+ }
78
+ else {
79
+ delete this.PCTResizeInfo;
80
+ }
81
+ };
66
82
  return RectResizeModel;
67
83
  }(core_1.RectNodeModel));
68
84
  var RectResizeView = /** @class */ (function (_super) {
@@ -48,6 +48,7 @@ var core_1 = require("@logicflow/core");
48
48
  var NodeResize_1 = require("../../NodeResize");
49
49
  var defaultWidth = 500;
50
50
  var defaultHeight = 300;
51
+ var DEFAULT_BOTTOM_Z_INDEX = -10000;
51
52
  var GroupNodeModel = /** @class */ (function (_super) {
52
53
  __extends(GroupNodeModel, _super);
53
54
  function GroupNodeModel() {
@@ -70,8 +71,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
70
71
  this.height = defaultHeight;
71
72
  this.foldedWidth = 80;
72
73
  this.foldedHeight = 60;
73
- // todo: 参考bpmn.js, 分组和未加入分组的节点重合时,未加入分组的节点在分组之下。方便标识。
74
- this.zIndex = -1;
74
+ this.zIndex = DEFAULT_BOTTOM_Z_INDEX;
75
75
  this.radius = 0;
76
76
  this.text.editable = false;
77
77
  this.text.draggable = false;
@@ -276,6 +276,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
276
276
  GroupNodeModel.prototype.getHistoryData = function () {
277
277
  var data = _super.prototype.getData.call(this);
278
278
  data.children = __spread(this.children);
279
+ data.isGroup = true;
279
280
  var properties = data.properties;
280
281
  delete properties.groupAddable;
281
282
  if (properties.isFolded) { // 如果分组被折叠
@@ -290,6 +291,12 @@ var GroupNodeModel = /** @class */ (function (_super) {
290
291
  GroupNodeModel.prototype.isAllowAppendIn = function (nodeData) {
291
292
  return true;
292
293
  };
294
+ /**
295
+ * 当groupA被添加到groupB中时,将groupB及groupB所属的group的zIndex减1
296
+ */
297
+ GroupNodeModel.prototype.toBack = function () {
298
+ this.zIndex--;
299
+ };
293
300
  return GroupNodeModel;
294
301
  }(NodeResize_1.RectResize.model));
295
302
  var GroupNode = /** @class */ (function (_super) {
@@ -301,7 +308,7 @@ var GroupNode = /** @class */ (function (_super) {
301
308
  var _a = this.props.model, resizable = _a.resizable, properties = _a.properties;
302
309
  return resizable && !properties.isFolded ? _super.prototype.getControlGroup.call(this) : null;
303
310
  };
304
- GroupNode.prototype.getAddedableShape = function () {
311
+ GroupNode.prototype.getAddableShape = function () {
305
312
  var _a = this.props.model, width = _a.width, height = _a.height, x = _a.x, y = _a.y, radius = _a.radius, properties = _a.properties;
306
313
  if (!properties.groupAddable)
307
314
  return null;
@@ -347,7 +354,7 @@ var GroupNode = /** @class */ (function (_super) {
347
354
  };
348
355
  GroupNode.prototype.getResizeShape = function () {
349
356
  return core_1.h('g', {}, [
350
- this.getAddedableShape(),
357
+ this.getAddableShape(),
351
358
  _super.prototype.getResizeShape.call(this),
352
359
  this.getFoldIcon(),
353
360
  ]);
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupNode = exports.Group = void 0;
4
4
  var GroupNode_1 = require("./GroupNode");
5
5
  exports.GroupNode = GroupNode_1.default;
6
+ var DEFAULT_TOP_Z_INDEX = -1000;
7
+ var DEFAULT_BOTTOM_Z_INDEX = -10000;
6
8
  var Group = /** @class */ (function () {
7
9
  function Group(_a) {
8
10
  var _this = this;
9
11
  var lf = _a.lf;
12
+ this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
10
13
  this.nodeGroupMap = new Map();
11
14
  this.graphRendered = function (data) {
12
15
  // 如果节点
@@ -31,8 +34,9 @@ var Group = /** @class */ (function () {
31
34
  preGroup.setAllowAppendChild(false);
32
35
  }
33
36
  // 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
34
- var bounds = _this.lf.getNodeModelById(data.id).getBounds();
35
- var group = _this.getGroup(bounds);
37
+ var nodeModel = _this.lf.getNodeModelById(data.id);
38
+ var bounds = nodeModel.getBounds();
39
+ var group = _this.getGroup(bounds, data);
36
40
  if (!group)
37
41
  return;
38
42
  var isAllowAppendIn = group.isAllowAppendIn(data);
@@ -43,20 +47,26 @@ var Group = /** @class */ (function () {
43
47
  });
44
48
  return;
45
49
  }
46
- if (data.id !== group.id) {
47
- group.addChild(data.id);
48
- _this.nodeGroupMap.set(data.id, group.id);
49
- group.setAllowAppendChild(false);
50
- }
51
- else if (data.children && data.children.length > 0) {
52
- // 表示当前添加的节点是一个新增的group
50
+ group.addChild(data.id);
51
+ _this.nodeGroupMap.set(data.id, group.id);
52
+ group.setAllowAppendChild(false);
53
+ // 如果这个节点是分组,那么将其子节点也记录下来
54
+ if (nodeModel.isGroup) {
53
55
  data.children.forEach(function (nodeId) {
54
56
  _this.nodeGroupMap.set(nodeId, data.id);
55
57
  });
58
+ _this.nodeSelected({ data: data });
56
59
  }
57
60
  };
58
61
  this.deleteGroupChild = function (_a) {
59
62
  var data = _a.data;
63
+ // 如果删除的是分组节点,则同时删除分组的子节点
64
+ if (data.children) {
65
+ data.children.forEach(function (nodeId) {
66
+ _this.nodeGroupMap.delete(nodeId);
67
+ _this.lf.deleteNode(nodeId);
68
+ });
69
+ }
60
70
  var groupId = _this.nodeGroupMap.get(data.id);
61
71
  if (groupId) {
62
72
  var group = _this.lf.getNodeModelById(groupId);
@@ -68,7 +78,7 @@ var Group = /** @class */ (function () {
68
78
  var data = _a.data;
69
79
  var nodeModel = _this.lf.getNodeModelById(data.id);
70
80
  var bounds = nodeModel.getBounds();
71
- var newGroup = _this.getGroup(bounds);
81
+ var newGroup = _this.getGroup(bounds, data);
72
82
  if (_this.activeGroup) {
73
83
  _this.activeGroup.setAllowAppendChild(false);
74
84
  }
@@ -81,6 +91,46 @@ var Group = /** @class */ (function () {
81
91
  _this.activeGroup = newGroup;
82
92
  _this.activeGroup.setAllowAppendChild(true);
83
93
  };
94
+ /**
95
+ * 1. 分组节点默认在普通节点下面。
96
+ * 2. 分组节点被选中后,会将分组节点以及其内部的其他分组节点放到其余分组节点的上面。
97
+ * 3. 分组节点取消选中后,不会将分组节点重置为原来的高度。
98
+ * 4. 由于LogicFlow核心目标是支持用户手动绘制流程图,所以不考虑一张流程图超过1000个分组节点的情况。
99
+ */
100
+ this.nodeSelected = function (_a) {
101
+ var data = _a.data;
102
+ var nodeModel = _this.lf.getNodeModelById(data.id);
103
+ _this.toFrontGroup(nodeModel);
104
+ // 重置所有的group zIndex,防止group节点zIndex增长为正。
105
+ if (_this.topGroupZIndex > DEFAULT_TOP_Z_INDEX) {
106
+ _this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
107
+ var allGroups = _this.lf.graphModel.nodes
108
+ .filter(function (node) { return node.isGroup; })
109
+ .sort(function (a, b) { return a.zIndex - b.zIndex; });
110
+ var preZIndex = 0;
111
+ for (var i = 0; i < allGroups.length; i++) {
112
+ var group = allGroups[i];
113
+ if (group.zIndex !== preZIndex) {
114
+ _this.topGroupZIndex++;
115
+ preZIndex = group.zIndex;
116
+ }
117
+ group.setZIndex(_this.topGroupZIndex);
118
+ }
119
+ }
120
+ };
121
+ this.toFrontGroup = function (model) {
122
+ if (!model || !model.isGroup) {
123
+ return;
124
+ }
125
+ _this.topGroupZIndex++;
126
+ model.setZIndex(_this.topGroupZIndex);
127
+ if (model.children) {
128
+ model.children.forEach(function (nodeId) {
129
+ var node = _this.lf.getNodeModelById(nodeId);
130
+ _this.toFrontGroup(node);
131
+ });
132
+ }
133
+ };
84
134
  lf.register(GroupNode_1.default);
85
135
  this.lf = lf;
86
136
  lf.graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
@@ -103,11 +153,10 @@ var Group = /** @class */ (function () {
103
153
  return true;
104
154
  });
105
155
  lf.graphModel.group = this;
106
- lf.on('node:add', this.appendNodeToGroup);
156
+ lf.on('node:add,node:drop', this.appendNodeToGroup);
107
157
  lf.on('node:delete', this.deleteGroupChild);
108
- lf.on('node:drop', this.appendNodeToGroup);
109
- lf.on('node:dnd-drag', this.setActiveGroup);
110
- lf.on('node:drag', this.setActiveGroup);
158
+ lf.on('node:dnd-drag,node:drag', this.setActiveGroup);
159
+ lf.on('node:click', this.nodeSelected);
111
160
  lf.on('graph:rendered', this.graphRendered);
112
161
  }
113
162
  /**
@@ -129,15 +178,22 @@ var Group = /** @class */ (function () {
129
178
  };
130
179
  /**
131
180
  * 获取自定位置其所属分组
181
+ * 当分组重合时,优先返回最上层的分组
132
182
  */
133
- Group.prototype.getGroup = function (bounds) {
183
+ Group.prototype.getGroup = function (bounds, nodeData) {
134
184
  var nodes = this.lf.graphModel.nodes;
135
- for (var i = 0; i < nodes.length; i++) {
136
- var model = nodes[i];
137
- if (model.isGroup && model.isInRange(bounds)) {
138
- return model;
185
+ var groups = nodes.filter(function (node) { return node.isGroup && node.isInRange(bounds) && node.id !== nodeData.id; });
186
+ if (groups.length === 0)
187
+ return;
188
+ if (groups.length === 1)
189
+ return groups[0];
190
+ var topGroup = groups[groups.length - 1];
191
+ for (var i = groups.length - 2; i >= 0; i--) {
192
+ if (groups[i].zIndex > topGroup.zIndex) {
193
+ topGroup = groups[i];
139
194
  }
140
195
  }
196
+ return topGroup;
141
197
  };
142
198
  /**
143
199
  * 获取某个节点所属的groupModel
@@ -22,16 +22,19 @@ declare class Control extends Component<IProps> {
22
22
  deltaX: any;
23
23
  deltaY: any;
24
24
  }) => void;
25
- getResize: ({ index, deltaX, deltaY, width, height, pct }: {
25
+ getResize: ({ index, deltaX, deltaY, width, height, PCTResizeInfo, pct }: {
26
26
  index: any;
27
27
  deltaX: any;
28
28
  deltaY: any;
29
29
  width: any;
30
30
  height: any;
31
+ PCTResizeInfo: any;
31
32
  pct?: number;
32
33
  }) => {
33
34
  width: any;
34
35
  height: any;
36
+ deltaX: any;
37
+ deltaY: any;
35
38
  };
36
39
  updateRect: ({ deltaX, deltaY }: {
37
40
  deltaX: any;
@@ -57,8 +57,64 @@ var Control = /** @class */ (function (_super) {
57
57
  };
58
58
  // 计算control拖动后,节点的宽高
59
59
  _this.getResize = function (_a) {
60
- var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
61
- var resize = { width: width, height: height };
60
+ var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, PCTResizeInfo = _a.PCTResizeInfo, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
61
+ var resize = { width: width, height: height, deltaX: deltaX, deltaY: deltaY };
62
+ if (PCTResizeInfo) {
63
+ var sensitivity = 4; // 越低越灵敏
64
+ var deltaScale = 0;
65
+ var combineDleta = 0;
66
+ switch (index) {
67
+ case 0:
68
+ combineDleta = (deltaX * -1 - deltaY) / sensitivity;
69
+ break;
70
+ case 1:
71
+ combineDleta = (deltaX - deltaY) / sensitivity;
72
+ break;
73
+ case 2:
74
+ combineDleta = (deltaX + deltaY) / sensitivity;
75
+ break;
76
+ case 3:
77
+ combineDleta = (deltaX * -1 + deltaY) / sensitivity;
78
+ break;
79
+ default:
80
+ break;
81
+ }
82
+ if (combineDleta !== 0) {
83
+ deltaScale = Math.round((combineDleta / PCTResizeInfo.ResizeBasis.basisHeight)
84
+ * 100000) / 1000;
85
+ }
86
+ PCTResizeInfo.ResizePCT.widthPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.widthPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
87
+ PCTResizeInfo.ResizePCT.hightPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.hightPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
88
+ var spcWidth = Math.round((PCTResizeInfo.ResizePCT.widthPCT
89
+ * PCTResizeInfo.ResizeBasis.basisWidth) / 100);
90
+ var spcHeight = Math.round((PCTResizeInfo.ResizePCT.hightPCT
91
+ * PCTResizeInfo.ResizeBasis.basisHeight) / 100);
92
+ switch (index) {
93
+ case 0:
94
+ deltaX = width - spcWidth;
95
+ deltaY = height - spcHeight;
96
+ break;
97
+ case 1:
98
+ deltaX = spcWidth - width;
99
+ deltaY = height - spcHeight;
100
+ break;
101
+ case 2:
102
+ deltaX = spcWidth - width;
103
+ deltaY = spcHeight - height;
104
+ break;
105
+ case 3:
106
+ deltaX = width - spcWidth;
107
+ deltaY = spcHeight - height;
108
+ break;
109
+ default:
110
+ break;
111
+ }
112
+ resize.width = spcWidth;
113
+ resize.height = spcHeight;
114
+ resize.deltaX = deltaX / pct;
115
+ resize.deltaY = deltaY / pct;
116
+ return resize;
117
+ }
62
118
  switch (index) {
63
119
  case 0:
64
120
  resize.width = width - deltaX * pct;
@@ -69,7 +125,7 @@ var Control = /** @class */ (function (_super) {
69
125
  resize.height = height - deltaY * pct;
70
126
  break;
71
127
  case 2:
72
- resize.width = width + deltaX;
128
+ resize.width = width + deltaX * pct;
73
129
  resize.height = height + deltaY * pct;
74
130
  break;
75
131
  case 3:
@@ -84,7 +140,7 @@ var Control = /** @class */ (function (_super) {
84
140
  // 矩形更新
85
141
  _this.updateRect = function (_a) {
86
142
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
87
- var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius;
143
+ var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius, PCTResizeInfo = _b.PCTResizeInfo;
88
144
  // 更新中心点位置,更新文案位置
89
145
  var index = _this.index;
90
146
  var size = _this.getResize({
@@ -93,6 +149,7 @@ var Control = /** @class */ (function (_super) {
93
149
  deltaY: deltaY,
94
150
  width: width,
95
151
  height: height,
152
+ PCTResizeInfo: PCTResizeInfo,
96
153
  pct: 1,
97
154
  });
98
155
  // 限制放大缩小的最大最小范围
@@ -105,7 +162,7 @@ var Control = /** @class */ (function (_super) {
105
162
  _this.dragHandler.cancelDrag();
106
163
  return;
107
164
  }
108
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
165
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
109
166
  // 更新宽高
110
167
  _this.nodeModel.width = size.width;
111
168
  _this.nodeModel.height = size.height;
@@ -152,7 +209,7 @@ var Control = /** @class */ (function (_super) {
152
209
  // 椭圆更新
153
210
  _this.updateEllipse = function (_a) {
154
211
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
155
- var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
212
+ var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
156
213
  var index = _this.index;
157
214
  var width = rx;
158
215
  var height = ry;
@@ -162,6 +219,7 @@ var Control = /** @class */ (function (_super) {
162
219
  deltaY: deltaY,
163
220
  width: width,
164
221
  height: height,
222
+ PCTResizeInfo: PCTResizeInfo,
165
223
  pct: 1 / 2,
166
224
  });
167
225
  // 限制放大缩小的最大最小范围
@@ -174,12 +232,12 @@ var Control = /** @class */ (function (_super) {
174
232
  return;
175
233
  }
176
234
  // 更新中心点位置,更新文案位置
177
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
235
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
178
236
  // 更新rx ry,宽高为计算属性自动更新
179
237
  // @ts-ignore
180
- _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
238
+ _this.nodeModel.rx = size.width;
181
239
  // @ts-ignore
182
- _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
240
+ _this.nodeModel.ry = size.height;
183
241
  _this.nodeModel.setProperties({
184
242
  nodeSize: {
185
243
  rx: size.width,
@@ -216,7 +274,7 @@ var Control = /** @class */ (function (_super) {
216
274
  // 菱形更新
217
275
  _this.updateDiamond = function (_a) {
218
276
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
219
- var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
277
+ var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
220
278
  var index = _this.index;
221
279
  var width = rx;
222
280
  var height = ry;
@@ -226,6 +284,7 @@ var Control = /** @class */ (function (_super) {
226
284
  deltaY: deltaY,
227
285
  width: width,
228
286
  height: height,
287
+ PCTResizeInfo: PCTResizeInfo,
229
288
  pct: 1 / 2,
230
289
  });
231
290
  // 限制放大缩小的最大最小范围
@@ -238,12 +297,12 @@ var Control = /** @class */ (function (_super) {
238
297
  return;
239
298
  }
240
299
  // 更新中心点位置,更新文案位置
241
- _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
300
+ _this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
242
301
  // 更新rx ry,宽高为计算属性自动更新
243
302
  // @ts-ignore
244
- _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
303
+ _this.nodeModel.rx = size.width;
245
304
  // @ts-ignore
246
- _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
305
+ _this.nodeModel.ry = size.height;
247
306
  _this.nodeModel.setProperties({
248
307
  nodeSize: {
249
308
  rx: size.width,