@logicflow/extension 1.2.0-alpha.12 → 1.2.0-alpha.15

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 (40) hide show
  1. package/cjs/bpmn-adapter/json2xml.js +0 -1
  2. package/cjs/components/mini-map/index.js +24 -4
  3. package/cjs/components/selection-select/index.js +4 -0
  4. package/cjs/materials/group/GroupNode.js +41 -13
  5. package/cjs/materials/group/index.js +37 -15
  6. package/cjs/tools/snapshot/index.js +1 -1
  7. package/es/bpmn-adapter/json2xml.js +0 -1
  8. package/es/components/mini-map/index.d.ts +1 -0
  9. package/es/components/mini-map/index.js +24 -4
  10. package/es/components/selection-select/index.js +4 -0
  11. package/es/materials/group/GroupNode.d.ts +6 -0
  12. package/es/materials/group/GroupNode.js +41 -13
  13. package/es/materials/group/index.d.ts +1 -7
  14. package/es/materials/group/index.js +37 -15
  15. package/es/tools/snapshot/index.js +1 -1
  16. package/lib/AutoLayout.js +1 -1
  17. package/lib/BpmnAdapter.js +1 -1
  18. package/lib/BpmnElement.js +1 -1
  19. package/lib/ContextMenu.js +1 -1
  20. package/lib/Control.js +1 -1
  21. package/lib/CurvedEdge.js +1 -1
  22. package/lib/DndPanel.js +1 -1
  23. package/lib/EnLocale.js +1 -1
  24. package/lib/FlowPath.js +1 -1
  25. package/lib/Group.js +1 -1
  26. package/lib/Highlight.js +1 -1
  27. package/lib/InsertNodeInPolyline.js +1 -1
  28. package/lib/Menu.js +1 -1
  29. package/lib/MiniMap.js +1 -1
  30. package/lib/NodeResize.js +1 -1
  31. package/lib/RectLabelNode.js +1 -1
  32. package/lib/SelectionSelect.js +1 -1
  33. package/lib/Snapshot.js +1 -1
  34. package/lib/TurboAdapter.js +1 -1
  35. package/lib/lfJson2Xml.js +1 -1
  36. package/lib/lfXml2Json.js +1 -1
  37. package/package.json +4 -4
  38. package/types/components/mini-map/index.d.ts +1 -0
  39. package/types/materials/group/GroupNode.d.ts +6 -0
  40. package/types/materials/group/index.d.ts +1 -7
@@ -26,7 +26,6 @@ function toXml(v, name, ind, deep) {
26
26
  xml += addIndSpace(ind, deep) + "<" + name;
27
27
  for (var m in v) {
28
28
  if (m.charAt(0) == "-") {
29
- console.log(m, v[m]);
30
29
  xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
31
30
  }
32
31
  else {
@@ -64,12 +64,17 @@ var MiniMap = /** @class */ (function () {
64
64
  y: e.y,
65
65
  };
66
66
  };
67
- this.__drag = function (e) {
67
+ this.moveViewport = function (top, left) {
68
68
  var viewStyle = _this.__viewport.style;
69
- _this.__viewPortTop += e.y - _this.__startPosition.y;
70
- _this.__viewPortLeft += e.x - _this.__startPosition.x;
69
+ _this.__viewPortTop = top;
70
+ _this.__viewPortLeft = left;
71
71
  viewStyle.top = _this.__viewPortTop + "px";
72
72
  viewStyle.left = _this.__viewPortLeft + "px";
73
+ };
74
+ this.__drag = function (e) {
75
+ var top = _this.__viewPortTop + e.y - _this.__startPosition.y;
76
+ var left = _this.__viewPortLeft + e.x - _this.__startPosition.x;
77
+ _this.moveViewport(top, left);
73
78
  _this.__startPosition = {
74
79
  x: e.x,
75
80
  y: e.y,
@@ -88,6 +93,21 @@ var MiniMap = /** @class */ (function () {
88
93
  this.__drop = function () {
89
94
  document.removeEventListener('mousemove', _this.__drag);
90
95
  document.removeEventListener('mouseup', _this.__drop);
96
+ var top = _this.__viewPortTop;
97
+ var left = _this.__viewPortLeft;
98
+ if (_this.__viewPortLeft > _this.__width) {
99
+ left = _this.__width - _this.__viewPortWidth;
100
+ }
101
+ if (_this.__viewPortTop > _this.__height) {
102
+ top = _this.__height - _this.__viewPortHeight;
103
+ }
104
+ if (_this.__viewPortLeft < -_this.__width) {
105
+ left = 0;
106
+ }
107
+ if (_this.__viewPortTop < -_this.__height) {
108
+ top = 0;
109
+ }
110
+ _this.moveViewport(top, left);
91
111
  };
92
112
  this.__lf = lf;
93
113
  this.__miniMapWidth = lf.graphModel.width;
@@ -311,7 +331,7 @@ var MiniMap = /** @class */ (function () {
311
331
  var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
312
332
  var realViewPortHeight = realViewPortWidth / graphRatio;
313
333
  this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
314
- this.__viewPortLeft = -TRANSLATE_X * scale;
334
+ this.__viewPortLeft = TRANSLATE_X > 0 ? 0 : -TRANSLATE_X * scale;
315
335
  this.__viewPortWidth = realViewPortWidth;
316
336
  this.__viewPortHeight = realViewPortHeight;
317
337
  viewStyle.top = this.__viewPortTop + "px";
@@ -34,6 +34,7 @@ var SelectionSelect = /** @class */ (function () {
34
34
  this.__drawOff = function () {
35
35
  document.removeEventListener('mousemove', _this.__draw);
36
36
  document.removeEventListener('mouseup', _this.__drawOff);
37
+ _this.wrapper.oncontextmenu = null;
37
38
  _this.__domContainer.removeChild(_this.wrapper);
38
39
  var _a = _this.startPoint, x = _a.x, y = _a.y;
39
40
  var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
@@ -77,6 +78,9 @@ var SelectionSelect = /** @class */ (function () {
77
78
  _this.endPoint = { x: x, y: y };
78
79
  var wrapper = document.createElement('div');
79
80
  wrapper.className = 'lf-selection-select';
81
+ wrapper.oncontextmenu = function prevent(ev) {
82
+ ev.preventDefault();
83
+ };
80
84
  wrapper.style.top = _this.startPoint.y + "px";
81
85
  wrapper.style.left = _this.startPoint.x + "px";
82
86
  domContainer.appendChild(wrapper);
@@ -79,6 +79,8 @@ var GroupNodeModel = /** @class */ (function (_super) {
79
79
  this.resizable = false;
80
80
  this.autoToFront = false;
81
81
  this.foldable = false;
82
+ // 是否可以被嵌套
83
+ this.nestable = false;
82
84
  if (this.properties.isFolded === undefined) {
83
85
  this.properties.isFolded = false;
84
86
  }
@@ -102,10 +104,25 @@ var GroupNodeModel = /** @class */ (function (_super) {
102
104
  * 3. 处理连线
103
105
  */
104
106
  GroupNodeModel.prototype.foldGroup = function (isFolded) {
105
- var _this = this;
106
107
  this.setProperty('isFolded', isFolded);
107
108
  this.isFolded = isFolded;
108
109
  // step 1
110
+ this.foldRect(isFolded);
111
+ // step 2
112
+ var allEdges = this.foldChildren(isFolded);
113
+ // step 3
114
+ console.log({ allEdges: allEdges });
115
+ this.foldEdge(isFolded, allEdges);
116
+ };
117
+ GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
118
+ var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
119
+ style.stroke = 'transparent';
120
+ style.fill = 'transparent';
121
+ style.hover.fill = 'transparent';
122
+ style.hover.stroke = 'transparent';
123
+ return style;
124
+ };
125
+ GroupNodeModel.prototype.foldRect = function (isFolded) {
109
126
  if (isFolded) {
110
127
  this.unfoldedWidth = this.width;
111
128
  this.unfoldedHight = this.height;
@@ -124,25 +141,23 @@ var GroupNodeModel = /** @class */ (function (_super) {
124
141
  y: this.y + this.unfoldedHight / 2 - this.foldedHeight / 2,
125
142
  });
126
143
  }
127
- // step 2
144
+ };
145
+ GroupNodeModel.prototype.foldChildren = function (isFolded) {
146
+ var _this = this;
128
147
  var allEdges = this.incoming.edges.concat(this.outgoing.edges);
129
148
  this.children.forEach(function (elementId) {
130
149
  var nodeModel = _this.graphModel.getElement(elementId);
150
+ if (nodeModel.isGroup) {
151
+ var childEdges = nodeModel.foldChildren(isFolded || nodeModel.isFolded);
152
+ allEdges = allEdges.concat(childEdges);
153
+ nodeModel.foldEdge(isFolded, childEdges);
154
+ }
155
+ allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
131
156
  nodeModel.updateAttributes({
132
157
  visible: !isFolded,
133
158
  });
134
- allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
135
159
  });
136
- // step 3
137
- this.foldEdge(isFolded, allEdges);
138
- };
139
- GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
140
- var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
141
- style.stroke = 'transparent';
142
- style.fill = 'transparent';
143
- style.hover.fill = 'transparent';
144
- style.hover.stroke = 'transparent';
145
- return style;
160
+ return allEdges;
146
161
  };
147
162
  /**
148
163
  * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
@@ -267,6 +282,19 @@ var GroupNodeModel = /** @class */ (function (_super) {
267
282
  GroupNodeModel.prototype.removeChild = function (id) {
268
283
  this.children.delete(id);
269
284
  };
285
+ /**
286
+ * 获得包含嵌套组的所有子节点
287
+ */
288
+ GroupNodeModel.prototype.getChildren = function () {
289
+ var _this = this;
290
+ return __spread(this.children).flatMap(function (child) {
291
+ var model = _this.graphModel.getElement(child);
292
+ if (model.isGroup) {
293
+ return __spread([child], model.getChildren());
294
+ }
295
+ return child;
296
+ });
297
+ };
270
298
  GroupNodeModel.prototype.getAddableOutlineStyle = function () {
271
299
  return {
272
300
  stroke: '#FEB663',
@@ -51,8 +51,7 @@ var Group = /** @class */ (function () {
51
51
  preGroup.setAllowAppendChild(false);
52
52
  }
53
53
  // 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
54
- var bounds = _this.lf.getNodeModelById(data.id).getBounds();
55
- var group = _this.getGroup(bounds);
54
+ var group = _this.getGroup(_this.lf.getNodeModelById(data.id));
56
55
  if (!group)
57
56
  return;
58
57
  if (data.id !== group.id) {
@@ -81,8 +80,7 @@ var Group = /** @class */ (function () {
81
80
  var nodeModel = _this.lf.getNodeModelById(data.id);
82
81
  if (nodeModel.isGroup)
83
82
  return;
84
- var bounds = nodeModel.getBounds();
85
- var newGroup = _this.getGroup(bounds);
83
+ var newGroup = _this.getGroup(nodeModel);
86
84
  if (newGroup || newGroup !== _this.activeGroup) {
87
85
  if (_this.activeGroup) {
88
86
  _this.activeGroup.setAllowAppendChild(false);
@@ -96,22 +94,28 @@ var Group = /** @class */ (function () {
96
94
  lf.register(GroupNode_1.default);
97
95
  this.lf = lf;
98
96
  lf.graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
99
- if (model.isGroup) { // 如果移动的是分组,那么分组的子节点也跟着移动。
100
- lf.graphModel.moveNodes(__spread(model.children), deltaX, deltaY, true);
101
- return true;
102
- }
103
97
  var groupModel = lf.getNodeModelById(_this.nodeGroupMap.get(model.id));
104
- if (groupModel && groupModel.isRestrict) { // 如果移动的节点存在分组中,且这个分组禁止子节点移出去。
98
+ var allowMove = true;
99
+ if (groupModel && groupModel.isRestrict) {
100
+ // 如果移动的节点存在分组中,且这个分组禁止子节点移出去。
105
101
  var _a = model.getBounds(), x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
106
- var r = groupModel.isAllowMoveTo({
102
+ allowMove = groupModel.isAllowMoveTo({
107
103
  x1: x1 + deltaX,
108
104
  y1: y1 + deltaY,
109
105
  x2: x2 + deltaX,
110
106
  y2: y2 + deltaY,
111
107
  });
112
- return r;
113
108
  }
114
- return true;
109
+ if (model.isGroup) {
110
+ // 如果移动的是分组,那么分组的子节点也跟着移动。
111
+ if (allowMove === true) {
112
+ lf.graphModel.moveNodes(__spread(model.getChildren()), deltaX, deltaY, true);
113
+ }
114
+ else if (typeof allowMove !== 'boolean') {
115
+ lf.graphModel.moveNodes(__spread(model.getChildren()), allowMove.x ? deltaX : 0, allowMove.y ? deltaY : 0, true);
116
+ }
117
+ }
118
+ return allowMove;
115
119
  });
116
120
  lf.graphModel.group = this;
117
121
  lf.on('node:add', this.appendNodeToGroup);
@@ -124,14 +128,32 @@ var Group = /** @class */ (function () {
124
128
  /**
125
129
  * 获取自定位置其所属分组
126
130
  */
127
- Group.prototype.getGroup = function (bounds) {
131
+ Group.prototype.getGroup = function (nodeModel) {
132
+ if (nodeModel.nestable === false) {
133
+ return null;
134
+ }
135
+ var bounds = nodeModel.getBounds();
128
136
  var nodes = this.lf.graphModel.nodes;
137
+ var selectedModel = null;
129
138
  for (var i = 0; i < nodes.length; i++) {
130
139
  var model = nodes[i];
131
- if (model.isGroup && model.isInRange(bounds)) {
132
- return model;
140
+ if (model !== nodeModel && model.isGroup && model.isInRange(bounds)) {
141
+ if (selectedModel) {
142
+ if (selectedModel.zIndex > model.zIndex) {
143
+ selectedModel = model;
144
+ }
145
+ else if (selectedModel.zIndex === model.zIndex) {
146
+ if (!model.isInRange(selectedModel.getBounds())) {
147
+ selectedModel = model;
148
+ }
149
+ }
150
+ }
151
+ else {
152
+ selectedModel = model;
153
+ }
133
154
  }
134
155
  }
156
+ return selectedModel;
135
157
  };
136
158
  /**
137
159
  * 获取某个节点所属的groupModel
@@ -164,7 +164,7 @@ var Snapshot = /** @class */ (function () {
164
164
  真实dom存在缩放影响其宽高数值
165
165
  在得到真实宽高后除以缩放比例即可得到正常宽高
166
166
  */
167
- var base = document.getElementsByClassName('lf-base')[0];
167
+ var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
168
168
  var bbox = base.getBoundingClientRect();
169
169
  var graphModel = this.lf.graphModel;
170
170
  var transformModel = graphModel.transformModel;
@@ -23,7 +23,6 @@ function toXml(v, name, ind, deep) {
23
23
  xml += addIndSpace(ind, deep) + "<" + name;
24
24
  for (var m in v) {
25
25
  if (m.charAt(0) == "-") {
26
- console.log(m, v[m]);
27
26
  xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
28
27
  }
29
28
  else {
@@ -68,6 +68,7 @@ declare class MiniMap {
68
68
  }): void;
69
69
  __createViewPort(): void;
70
70
  __startDrag: (e: any) => void;
71
+ moveViewport: (top: any, left: any) => void;
71
72
  __drag: (e: any) => void;
72
73
  __drop: () => void;
73
74
  }
@@ -61,12 +61,17 @@ var MiniMap = /** @class */ (function () {
61
61
  y: e.y,
62
62
  };
63
63
  };
64
- this.__drag = function (e) {
64
+ this.moveViewport = function (top, left) {
65
65
  var viewStyle = _this.__viewport.style;
66
- _this.__viewPortTop += e.y - _this.__startPosition.y;
67
- _this.__viewPortLeft += e.x - _this.__startPosition.x;
66
+ _this.__viewPortTop = top;
67
+ _this.__viewPortLeft = left;
68
68
  viewStyle.top = _this.__viewPortTop + "px";
69
69
  viewStyle.left = _this.__viewPortLeft + "px";
70
+ };
71
+ this.__drag = function (e) {
72
+ var top = _this.__viewPortTop + e.y - _this.__startPosition.y;
73
+ var left = _this.__viewPortLeft + e.x - _this.__startPosition.x;
74
+ _this.moveViewport(top, left);
70
75
  _this.__startPosition = {
71
76
  x: e.x,
72
77
  y: e.y,
@@ -85,6 +90,21 @@ var MiniMap = /** @class */ (function () {
85
90
  this.__drop = function () {
86
91
  document.removeEventListener('mousemove', _this.__drag);
87
92
  document.removeEventListener('mouseup', _this.__drop);
93
+ var top = _this.__viewPortTop;
94
+ var left = _this.__viewPortLeft;
95
+ if (_this.__viewPortLeft > _this.__width) {
96
+ left = _this.__width - _this.__viewPortWidth;
97
+ }
98
+ if (_this.__viewPortTop > _this.__height) {
99
+ top = _this.__height - _this.__viewPortHeight;
100
+ }
101
+ if (_this.__viewPortLeft < -_this.__width) {
102
+ left = 0;
103
+ }
104
+ if (_this.__viewPortTop < -_this.__height) {
105
+ top = 0;
106
+ }
107
+ _this.moveViewport(top, left);
88
108
  };
89
109
  this.__lf = lf;
90
110
  this.__miniMapWidth = lf.graphModel.width;
@@ -308,7 +328,7 @@ var MiniMap = /** @class */ (function () {
308
328
  var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
309
329
  var realViewPortHeight = realViewPortWidth / graphRatio;
310
330
  this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
311
- this.__viewPortLeft = -TRANSLATE_X * scale;
331
+ this.__viewPortLeft = TRANSLATE_X > 0 ? 0 : -TRANSLATE_X * scale;
312
332
  this.__viewPortWidth = realViewPortWidth;
313
333
  this.__viewPortHeight = realViewPortHeight;
314
334
  viewStyle.top = this.__viewPortTop + "px";
@@ -31,6 +31,7 @@ var SelectionSelect = /** @class */ (function () {
31
31
  this.__drawOff = function () {
32
32
  document.removeEventListener('mousemove', _this.__draw);
33
33
  document.removeEventListener('mouseup', _this.__drawOff);
34
+ _this.wrapper.oncontextmenu = null;
34
35
  _this.__domContainer.removeChild(_this.wrapper);
35
36
  var _a = _this.startPoint, x = _a.x, y = _a.y;
36
37
  var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
@@ -74,6 +75,9 @@ var SelectionSelect = /** @class */ (function () {
74
75
  _this.endPoint = { x: x, y: y };
75
76
  var wrapper = document.createElement('div');
76
77
  wrapper.className = 'lf-selection-select';
78
+ wrapper.oncontextmenu = function prevent(ev) {
79
+ ev.preventDefault();
80
+ };
77
81
  wrapper.style.top = _this.startPoint.y + "px";
78
82
  wrapper.style.left = _this.startPoint.x + "px";
79
83
  domContainer.appendChild(wrapper);
@@ -47,6 +47,8 @@ declare class GroupNodeModel extends RectResize.model {
47
47
  */
48
48
  foldGroup(isFolded: any): void;
49
49
  getAnchorStyle(anchorInfo: any): Record<string, any>;
50
+ foldRect(isFolded: any): void;
51
+ foldChildren(isFolded: any): import("@logicflow/core/types/model/edge/BaseEdgeModel").BaseEdgeModel[];
50
52
  /**
51
53
  * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
52
54
  * 边的分类:
@@ -90,6 +92,10 @@ declare class GroupNodeModel extends RectResize.model {
90
92
  * @param id 节点id
91
93
  */
92
94
  removeChild(id: any): void;
95
+ /**
96
+ * 获得包含嵌套组的所有子节点
97
+ */
98
+ getChildren(): any[];
93
99
  getAddableOutlineStyle(): {
94
100
  stroke: string;
95
101
  strokeWidth: number;
@@ -77,6 +77,8 @@ var GroupNodeModel = /** @class */ (function (_super) {
77
77
  this.resizable = false;
78
78
  this.autoToFront = false;
79
79
  this.foldable = false;
80
+ // 是否可以被嵌套
81
+ this.nestable = false;
80
82
  if (this.properties.isFolded === undefined) {
81
83
  this.properties.isFolded = false;
82
84
  }
@@ -100,10 +102,25 @@ var GroupNodeModel = /** @class */ (function (_super) {
100
102
  * 3. 处理连线
101
103
  */
102
104
  GroupNodeModel.prototype.foldGroup = function (isFolded) {
103
- var _this = this;
104
105
  this.setProperty('isFolded', isFolded);
105
106
  this.isFolded = isFolded;
106
107
  // step 1
108
+ this.foldRect(isFolded);
109
+ // step 2
110
+ var allEdges = this.foldChildren(isFolded);
111
+ // step 3
112
+ console.log({ allEdges: allEdges });
113
+ this.foldEdge(isFolded, allEdges);
114
+ };
115
+ GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
116
+ var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
117
+ style.stroke = 'transparent';
118
+ style.fill = 'transparent';
119
+ style.hover.fill = 'transparent';
120
+ style.hover.stroke = 'transparent';
121
+ return style;
122
+ };
123
+ GroupNodeModel.prototype.foldRect = function (isFolded) {
107
124
  if (isFolded) {
108
125
  this.unfoldedWidth = this.width;
109
126
  this.unfoldedHight = this.height;
@@ -122,25 +139,23 @@ var GroupNodeModel = /** @class */ (function (_super) {
122
139
  y: this.y + this.unfoldedHight / 2 - this.foldedHeight / 2,
123
140
  });
124
141
  }
125
- // step 2
142
+ };
143
+ GroupNodeModel.prototype.foldChildren = function (isFolded) {
144
+ var _this = this;
126
145
  var allEdges = this.incoming.edges.concat(this.outgoing.edges);
127
146
  this.children.forEach(function (elementId) {
128
147
  var nodeModel = _this.graphModel.getElement(elementId);
148
+ if (nodeModel.isGroup) {
149
+ var childEdges = nodeModel.foldChildren(isFolded || nodeModel.isFolded);
150
+ allEdges = allEdges.concat(childEdges);
151
+ nodeModel.foldEdge(isFolded, childEdges);
152
+ }
153
+ allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
129
154
  nodeModel.updateAttributes({
130
155
  visible: !isFolded,
131
156
  });
132
- allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
133
157
  });
134
- // step 3
135
- this.foldEdge(isFolded, allEdges);
136
- };
137
- GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
138
- var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
139
- style.stroke = 'transparent';
140
- style.fill = 'transparent';
141
- style.hover.fill = 'transparent';
142
- style.hover.stroke = 'transparent';
143
- return style;
158
+ return allEdges;
144
159
  };
145
160
  /**
146
161
  * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
@@ -265,6 +280,19 @@ var GroupNodeModel = /** @class */ (function (_super) {
265
280
  GroupNodeModel.prototype.removeChild = function (id) {
266
281
  this.children.delete(id);
267
282
  };
283
+ /**
284
+ * 获得包含嵌套组的所有子节点
285
+ */
286
+ GroupNodeModel.prototype.getChildren = function () {
287
+ var _this = this;
288
+ return __spread(this.children).flatMap(function (child) {
289
+ var model = _this.graphModel.getElement(child);
290
+ if (model.isGroup) {
291
+ return __spread([child], model.getChildren());
292
+ }
293
+ return child;
294
+ });
295
+ };
268
296
  GroupNodeModel.prototype.getAddableOutlineStyle = function () {
269
297
  return {
270
298
  stroke: '#FEB663',
@@ -2,12 +2,6 @@ import LogicFlow, { BaseNodeModel } from '@logicflow/core';
2
2
  import GroupNode from './GroupNode';
3
3
  declare type BaseNodeId = string;
4
4
  declare type GroupId = string;
5
- declare type Bounds = {
6
- x1: number;
7
- y1: number;
8
- x2: number;
9
- y2: number;
10
- };
11
5
  declare class Group {
12
6
  static pluginName: string;
13
7
  lf: LogicFlow;
@@ -29,7 +23,7 @@ declare class Group {
29
23
  /**
30
24
  * 获取自定位置其所属分组
31
25
  */
32
- getGroup(bounds: Bounds): BaseNodeModel | undefined;
26
+ getGroup(nodeModel: BaseNodeModel): BaseNodeModel | undefined;
33
27
  /**
34
28
  * 获取某个节点所属的groupModel
35
29
  */
@@ -47,8 +47,7 @@ var Group = /** @class */ (function () {
47
47
  preGroup.setAllowAppendChild(false);
48
48
  }
49
49
  // 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
50
- var bounds = _this.lf.getNodeModelById(data.id).getBounds();
51
- var group = _this.getGroup(bounds);
50
+ var group = _this.getGroup(_this.lf.getNodeModelById(data.id));
52
51
  if (!group)
53
52
  return;
54
53
  if (data.id !== group.id) {
@@ -77,8 +76,7 @@ var Group = /** @class */ (function () {
77
76
  var nodeModel = _this.lf.getNodeModelById(data.id);
78
77
  if (nodeModel.isGroup)
79
78
  return;
80
- var bounds = nodeModel.getBounds();
81
- var newGroup = _this.getGroup(bounds);
79
+ var newGroup = _this.getGroup(nodeModel);
82
80
  if (newGroup || newGroup !== _this.activeGroup) {
83
81
  if (_this.activeGroup) {
84
82
  _this.activeGroup.setAllowAppendChild(false);
@@ -92,22 +90,28 @@ var Group = /** @class */ (function () {
92
90
  lf.register(GroupNode);
93
91
  this.lf = lf;
94
92
  lf.graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
95
- if (model.isGroup) { // 如果移动的是分组,那么分组的子节点也跟着移动。
96
- lf.graphModel.moveNodes(__spread(model.children), deltaX, deltaY, true);
97
- return true;
98
- }
99
93
  var groupModel = lf.getNodeModelById(_this.nodeGroupMap.get(model.id));
100
- if (groupModel && groupModel.isRestrict) { // 如果移动的节点存在分组中,且这个分组禁止子节点移出去。
94
+ var allowMove = true;
95
+ if (groupModel && groupModel.isRestrict) {
96
+ // 如果移动的节点存在分组中,且这个分组禁止子节点移出去。
101
97
  var _a = model.getBounds(), x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
102
- var r = groupModel.isAllowMoveTo({
98
+ allowMove = groupModel.isAllowMoveTo({
103
99
  x1: x1 + deltaX,
104
100
  y1: y1 + deltaY,
105
101
  x2: x2 + deltaX,
106
102
  y2: y2 + deltaY,
107
103
  });
108
- return r;
109
104
  }
110
- return true;
105
+ if (model.isGroup) {
106
+ // 如果移动的是分组,那么分组的子节点也跟着移动。
107
+ if (allowMove === true) {
108
+ lf.graphModel.moveNodes(__spread(model.getChildren()), deltaX, deltaY, true);
109
+ }
110
+ else if (typeof allowMove !== 'boolean') {
111
+ lf.graphModel.moveNodes(__spread(model.getChildren()), allowMove.x ? deltaX : 0, allowMove.y ? deltaY : 0, true);
112
+ }
113
+ }
114
+ return allowMove;
111
115
  });
112
116
  lf.graphModel.group = this;
113
117
  lf.on('node:add', this.appendNodeToGroup);
@@ -120,14 +124,32 @@ var Group = /** @class */ (function () {
120
124
  /**
121
125
  * 获取自定位置其所属分组
122
126
  */
123
- Group.prototype.getGroup = function (bounds) {
127
+ Group.prototype.getGroup = function (nodeModel) {
128
+ if (nodeModel.nestable === false) {
129
+ return null;
130
+ }
131
+ var bounds = nodeModel.getBounds();
124
132
  var nodes = this.lf.graphModel.nodes;
133
+ var selectedModel = null;
125
134
  for (var i = 0; i < nodes.length; i++) {
126
135
  var model = nodes[i];
127
- if (model.isGroup && model.isInRange(bounds)) {
128
- return model;
136
+ if (model !== nodeModel && model.isGroup && model.isInRange(bounds)) {
137
+ if (selectedModel) {
138
+ if (selectedModel.zIndex > model.zIndex) {
139
+ selectedModel = model;
140
+ }
141
+ else if (selectedModel.zIndex === model.zIndex) {
142
+ if (!model.isInRange(selectedModel.getBounds())) {
143
+ selectedModel = model;
144
+ }
145
+ }
146
+ }
147
+ else {
148
+ selectedModel = model;
149
+ }
129
150
  }
130
151
  }
152
+ return selectedModel;
131
153
  };
132
154
  /**
133
155
  * 获取某个节点所属的groupModel
@@ -161,7 +161,7 @@ var Snapshot = /** @class */ (function () {
161
161
  真实dom存在缩放影响其宽高数值
162
162
  在得到真实宽高后除以缩放比例即可得到正常宽高
163
163
  */
164
- var base = document.getElementsByClassName('lf-base')[0];
164
+ var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
165
165
  var bbox = base.getBoundingClientRect();
166
166
  var graphModel = this.lf.graphModel;
167
167
  var transformModel = graphModel.transformModel;