@logicflow/extension 1.1.7-alpha.0 → 1.1.8-alpha.0

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 (52) hide show
  1. package/cjs/NodeResize/Control/Control.js +14 -7
  2. package/cjs/NodeResize/Node/DiamondResize.js +15 -14
  3. package/cjs/NodeResize/Node/EllipseResize.js +12 -14
  4. package/cjs/NodeResize/Node/HtmlResize.js +14 -14
  5. package/cjs/NodeResize/Node/RectResize.js +15 -15
  6. package/cjs/insert-node-in-polyline/index.js +20 -19
  7. package/cjs/materials/group/GroupNode.js +119 -53
  8. package/cjs/materials/group/index.js +20 -8
  9. package/es/NodeResize/Control/Control.d.ts +2 -2
  10. package/es/NodeResize/Control/Control.js +14 -7
  11. package/es/NodeResize/Node/DiamondResize.d.ts +2 -5
  12. package/es/NodeResize/Node/DiamondResize.js +15 -14
  13. package/es/NodeResize/Node/EllipseResize.d.ts +1 -5
  14. package/es/NodeResize/Node/EllipseResize.js +12 -14
  15. package/es/NodeResize/Node/HtmlResize.d.ts +2 -5
  16. package/es/NodeResize/Node/HtmlResize.js +14 -14
  17. package/es/NodeResize/Node/RectResize.d.ts +2 -5
  18. package/es/NodeResize/Node/RectResize.js +15 -15
  19. package/es/insert-node-in-polyline/index.d.ts +8 -5
  20. package/es/insert-node-in-polyline/index.js +20 -19
  21. package/es/materials/group/GroupNode.d.ts +43 -4
  22. package/es/materials/group/GroupNode.js +119 -53
  23. package/es/materials/group/index.d.ts +7 -1
  24. package/es/materials/group/index.js +20 -8
  25. package/lib/AutoLayout.js +1 -1
  26. package/lib/BpmnAdapter.js +1 -1
  27. package/lib/BpmnElement.js +1 -1
  28. package/lib/ContextMenu.js +1 -1
  29. package/lib/Control.js +1 -1
  30. package/lib/CurvedEdge.js +1 -1
  31. package/lib/DndPanel.js +1 -1
  32. package/lib/FlowPath.js +1 -1
  33. package/lib/Group.js +1 -1
  34. package/lib/InsertNodeInPolyline.js +1 -1
  35. package/lib/Menu.js +1 -1
  36. package/lib/MiniMap.js +1 -1
  37. package/lib/NodeResize.js +1 -1
  38. package/lib/RectLabelNode.js +1 -1
  39. package/lib/SelectionSelect.js +1 -1
  40. package/lib/Snapshot.js +1 -1
  41. package/lib/TurboAdapter.js +1 -1
  42. package/lib/lfJson2Xml.js +1 -1
  43. package/lib/lfXml2Json.js +1 -1
  44. package/package.json +2 -2
  45. package/types/NodeResize/Control/Control.d.ts +2 -2
  46. package/types/NodeResize/Node/DiamondResize.d.ts +2 -5
  47. package/types/NodeResize/Node/EllipseResize.d.ts +1 -5
  48. package/types/NodeResize/Node/HtmlResize.d.ts +2 -5
  49. package/types/NodeResize/Node/RectResize.d.ts +2 -5
  50. package/types/insert-node-in-polyline/index.d.ts +8 -5
  51. package/types/materials/group/GroupNode.d.ts +43 -4
  52. package/types/materials/group/index.d.ts +7 -1
@@ -28,7 +28,7 @@ var preact_1 = require("preact");
28
28
  var core_1 = require("@logicflow/core");
29
29
  var Rect_1 = require("../BasicShape/Rect");
30
30
  var Util_1 = require("./Util");
31
- var createDrag = core_1.LogicFlowUtil.createDrag;
31
+ var StepDrag = core_1.LogicFlowUtil.StepDrag;
32
32
  var Control = /** @class */ (function (_super) {
33
33
  __extends(Control, _super);
34
34
  function Control(props) {
@@ -87,6 +87,8 @@ var Control = /** @class */ (function (_super) {
87
87
  || size.width > maxWidth
88
88
  || size.height < minHeight
89
89
  || size.height > maxHeight) {
90
+ // 为了避免放到和缩小位置和鼠标不一致的问题
91
+ _this.dragHandler.cancelDrag();
90
92
  return;
91
93
  }
92
94
  _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
@@ -154,15 +156,16 @@ var Control = /** @class */ (function (_super) {
154
156
  || size.width > (maxWidth / 2)
155
157
  || size.height < (minHeight / 2)
156
158
  || size.height > (maxHeight / 2)) {
159
+ _this.dragHandler.cancelDrag();
157
160
  return;
158
161
  }
159
162
  // 更新中心点位置,更新文案位置
160
163
  _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
161
164
  // 更新rx ry,宽高为计算属性自动更新
162
165
  // @ts-ignore
163
- _this.nodeModel.rx = size.width;
166
+ _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
164
167
  // @ts-ignore
165
- _this.nodeModel.ry = size.height;
168
+ _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
166
169
  _this.nodeModel.setProperties({
167
170
  nodeSize: {
168
171
  rx: size.width,
@@ -217,15 +220,16 @@ var Control = /** @class */ (function (_super) {
217
220
  || size.width > (maxWidth / 2)
218
221
  || size.height < (minHeight / 2)
219
222
  || size.height > (maxHeight / 2)) {
223
+ _this.dragHandler.cancelDrag();
220
224
  return;
221
225
  }
222
226
  // 更新中心点位置,更新文案位置
223
227
  _this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
224
228
  // 更新rx ry,宽高为计算属性自动更新
225
229
  // @ts-ignore
226
- _this.nodeModel.rx = size.width;
230
+ _this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
227
231
  // @ts-ignore
228
- _this.nodeModel.ry = size.height;
232
+ _this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
229
233
  _this.nodeModel.setProperties({
230
234
  nodeSize: {
231
235
  rx: size.width,
@@ -291,8 +295,11 @@ var Control = /** @class */ (function (_super) {
291
295
  if (gridSize > 1) {
292
296
  step = 2 * gridSize;
293
297
  }
298
+ if (_this.nodeModel.gridSize) {
299
+ step = 2 * _this.nodeModel.gridSize;
300
+ }
294
301
  _this.state = {};
295
- _this.dragHandler = createDrag({
302
+ _this.dragHandler = new StepDrag({
296
303
  onDraging: _this.onDraging,
297
304
  step: step,
298
305
  });
@@ -318,7 +325,7 @@ var Control = /** @class */ (function (_super) {
318
325
  var _a = this.props, x = _a.x, y = _a.y, index = _a.index, model = _a.model;
319
326
  var style = model.getControlPointStyle();
320
327
  return (preact_1.h("g", { className: "lf-resize-control-" + index },
321
- preact_1.h(Rect_1.default, __assign({ className: "lf-node-control" }, { x: x, y: y }, style, { onMouseDown: this.dragHandler }))));
328
+ preact_1.h(Rect_1.default, __assign({ className: "lf-node-control" }, { x: x, y: y }, style, { onMouseDown: this.dragHandler.handleMouseDown }))));
322
329
  };
323
330
  return Control;
324
331
  }(preact_1.Component));
@@ -29,14 +29,23 @@ var ControlGroup_1 = require("../Control/ControlGroup");
29
29
  var Polygon_1 = require("../BasicShape/Polygon");
30
30
  var DiamondResizeModel = /** @class */ (function (_super) {
31
31
  __extends(DiamondResizeModel, _super);
32
- function DiamondResizeModel() {
33
- var _this = _super !== null && _super.apply(this, arguments) || this;
34
- _this.minWidth = 30;
35
- _this.minHeight = 30;
36
- _this.maxWidth = 2000;
37
- _this.maxHeight = 2000;
32
+ function DiamondResizeModel(data, graphModel) {
33
+ var _this = _super.call(this, data, graphModel) || this;
34
+ var nodeSize = _this.properties.nodeSize;
35
+ if (nodeSize) {
36
+ _this.rx = nodeSize.rx;
37
+ _this.ry = nodeSize.ry;
38
+ }
38
39
  return _this;
39
40
  }
41
+ DiamondResizeModel.prototype.initNodeData = function (data) {
42
+ _super.prototype.initNodeData.call(this, data);
43
+ this.minWidth = 30;
44
+ this.minHeight = 30;
45
+ this.maxWidth = 2000;
46
+ this.maxHeight = 2000;
47
+ this.gridSize = 1;
48
+ };
40
49
  DiamondResizeModel.prototype.getOutlineStyle = function () {
41
50
  var style = _super.prototype.getOutlineStyle.call(this);
42
51
  style.stroke = 'none';
@@ -60,14 +69,6 @@ var DiamondResizeModel = /** @class */ (function (_super) {
60
69
  stroke: '#000000',
61
70
  };
62
71
  };
63
- DiamondResizeModel.prototype.setAttributes = function () {
64
- // @ts-ignore
65
- var nodeSize = this.properties.nodeSize;
66
- if (nodeSize) {
67
- this.rx = nodeSize.rx;
68
- this.ry = nodeSize.ry;
69
- }
70
- };
71
72
  return DiamondResizeModel;
72
73
  }(core_1.DiamondNodeModel));
73
74
  var DiamondResizeView = /** @class */ (function (_super) {
@@ -19,14 +19,20 @@ var EllipseResizeModel = /** @class */ (function (_super) {
19
19
  __extends(EllipseResizeModel, _super);
20
20
  function EllipseResizeModel(data, graphModel) {
21
21
  var _this = _super.call(this, data, graphModel) || this;
22
- _this.minWidth = 30;
23
- _this.minHeight = 30;
24
- _this.maxWidth = 2000;
25
- _this.maxHeight = 2000;
26
- _this.rx = 50;
27
- _this.ry = 50;
22
+ var nodeSize = _this.properties.nodeSize;
23
+ if (nodeSize) {
24
+ _this.rx = nodeSize.rx;
25
+ _this.ry = nodeSize.ry;
26
+ }
28
27
  return _this;
29
28
  }
29
+ EllipseResizeModel.prototype.initNodeData = function (data) {
30
+ _super.prototype.initNodeData.call(this, data);
31
+ this.minWidth = 30;
32
+ this.minHeight = 30;
33
+ this.maxWidth = 2000;
34
+ this.maxHeight = 2000;
35
+ };
30
36
  EllipseResizeModel.prototype.getOutlineStyle = function () {
31
37
  var style = _super.prototype.getOutlineStyle.call(this);
32
38
  style.stroke = 'none';
@@ -50,14 +56,6 @@ var EllipseResizeModel = /** @class */ (function (_super) {
50
56
  stroke: '#000000',
51
57
  };
52
58
  };
53
- EllipseResizeModel.prototype.setAttributes = function () {
54
- // @ts-ignore
55
- var nodeSize = this.properties.nodeSize;
56
- if (nodeSize) {
57
- this.rx = nodeSize.rx;
58
- this.ry = nodeSize.ry;
59
- }
60
- };
61
59
  return EllipseResizeModel;
62
60
  }(core_1.EllipseNodeModel));
63
61
  var EllipseResizeView = /** @class */ (function (_super) {
@@ -17,14 +17,22 @@ var core_1 = require("@logicflow/core");
17
17
  var ControlGroup_1 = require("../Control/ControlGroup");
18
18
  var HtmlResizeModel = /** @class */ (function (_super) {
19
19
  __extends(HtmlResizeModel, _super);
20
- function HtmlResizeModel() {
21
- var _this = _super !== null && _super.apply(this, arguments) || this;
22
- _this.minWidth = 30;
23
- _this.minHeight = 30;
24
- _this.maxWidth = 2000;
25
- _this.maxHeight = 2000;
20
+ function HtmlResizeModel(data, graphModel) {
21
+ var _this = _super.call(this, data, graphModel) || this;
22
+ var nodeSize = _this.properties.nodeSize;
23
+ if (nodeSize) {
24
+ _this.width = nodeSize.width;
25
+ _this.height = nodeSize.height;
26
+ }
26
27
  return _this;
27
28
  }
29
+ HtmlResizeModel.prototype.initNodeData = function (data) {
30
+ _super.prototype.initNodeData.call(this, data);
31
+ this.minWidth = 30;
32
+ this.minHeight = 30;
33
+ this.maxWidth = 2000;
34
+ this.maxHeight = 2000;
35
+ };
28
36
  HtmlResizeModel.prototype.getOutlineStyle = function () {
29
37
  var style = _super.prototype.getOutlineStyle.call(this);
30
38
  style.stroke = 'none';
@@ -48,14 +56,6 @@ var HtmlResizeModel = /** @class */ (function (_super) {
48
56
  stroke: '#000000',
49
57
  };
50
58
  };
51
- HtmlResizeModel.prototype.setAttributes = function () {
52
- // @ts-ignore
53
- var nodeSize = this.properties.nodeSize;
54
- if (nodeSize) {
55
- this.width = nodeSize.width;
56
- this.height = nodeSize.height;
57
- }
58
- };
59
59
  return HtmlResizeModel;
60
60
  }(core_1.HtmlNodeModel));
61
61
  var HtmlResizeView = /** @class */ (function (_super) {
@@ -17,14 +17,22 @@ var core_1 = require("@logicflow/core");
17
17
  var ControlGroup_1 = require("../Control/ControlGroup");
18
18
  var RectResizeModel = /** @class */ (function (_super) {
19
19
  __extends(RectResizeModel, _super);
20
- function RectResizeModel() {
21
- var _this = _super !== null && _super.apply(this, arguments) || this;
22
- _this.minWidth = 30;
23
- _this.minHeight = 30;
24
- _this.maxWidth = 2000;
25
- _this.maxHeight = 2000;
20
+ function RectResizeModel(data, graphModel) {
21
+ var _this = _super.call(this, data, graphModel) || this;
22
+ var nodeSize = _this.properties.nodeSize;
23
+ if (nodeSize) {
24
+ _this.width = nodeSize.width;
25
+ _this.height = nodeSize.height;
26
+ }
26
27
  return _this;
27
28
  }
29
+ RectResizeModel.prototype.initNodeData = function (data) {
30
+ _super.prototype.initNodeData.call(this, data);
31
+ this.minWidth = 30;
32
+ this.minHeight = 30;
33
+ this.maxWidth = 2000;
34
+ this.maxHeight = 2000;
35
+ };
28
36
  RectResizeModel.prototype.getOutlineStyle = function () {
29
37
  var style = _super.prototype.getOutlineStyle.call(this);
30
38
  style.stroke = 'none';
@@ -36,7 +44,7 @@ var RectResizeModel = /** @class */ (function (_super) {
36
44
  RectResizeModel.prototype.getResizeOutlineStyle = function () {
37
45
  return {
38
46
  fill: 'none',
39
- stroke: '#000000',
47
+ stroke: 'transparent',
40
48
  strokeWidth: 1,
41
49
  strokeDasharray: '3,3',
42
50
  };
@@ -49,14 +57,6 @@ var RectResizeModel = /** @class */ (function (_super) {
49
57
  stroke: '#000000',
50
58
  };
51
59
  };
52
- RectResizeModel.prototype.setAttributes = function () {
53
- // @ts-ignore
54
- var nodeSize = this.properties.nodeSize;
55
- if (nodeSize) {
56
- this.width = nodeSize.width;
57
- this.height = nodeSize.height;
58
- }
59
- };
60
60
  RectResizeModel.prototype.resize = function (deltaX, deltaY) {
61
61
  console.log(deltaX, deltaY);
62
62
  };
@@ -22,26 +22,25 @@ var __spread = (this && this.__spread) || function () {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.InsertNodeInPolyline = void 0;
24
24
  var edge_1 = require("./edge");
25
- var InsertNodeInPolyline = {
26
- pluginName: 'insertNodeInPolyline',
27
- _lf: null,
28
- dndAdd: true,
29
- dropAdd: true,
30
- install: function (lf) {
31
- InsertNodeInPolyline._lf = lf;
25
+ var InsertNodeInPolyline = /** @class */ (function () {
26
+ function InsertNodeInPolyline(_a) {
27
+ var lf = _a.lf;
28
+ this._lf = lf;
29
+ this.dndAdd = true;
30
+ this.dropAdd = true;
32
31
  this.eventHandler();
33
- },
34
- eventHandler: function () {
32
+ }
33
+ InsertNodeInPolyline.prototype.eventHandler = function () {
35
34
  var _this = this;
36
35
  // 监听事件
37
- if (InsertNodeInPolyline.dndAdd) {
38
- InsertNodeInPolyline._lf.on('node:dnd-add', function (_a) {
36
+ if (this.dndAdd) {
37
+ this._lf.on('node:dnd-add', function (_a) {
39
38
  var data = _a.data;
40
- InsertNodeInPolyline.insetNode(data);
39
+ _this.insetNode(data);
41
40
  });
42
41
  }
43
- if (InsertNodeInPolyline.dropAdd) {
44
- InsertNodeInPolyline._lf.on('node:drop', function (_a) {
42
+ if (this.dropAdd) {
43
+ this._lf.on('node:drop', function (_a) {
45
44
  var data = _a.data;
46
45
  var edges = _this._lf.graphModel.edges;
47
46
  var id = data.id;
@@ -53,12 +52,12 @@ var InsertNodeInPolyline = {
53
52
  }
54
53
  }
55
54
  if (pureNode) {
56
- InsertNodeInPolyline.insetNode(data);
55
+ _this.insetNode(data);
57
56
  }
58
57
  });
59
58
  }
60
- },
61
- insetNode: function (nodeData) {
59
+ };
60
+ InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
62
61
  var edges = this._lf.graphModel.edges;
63
62
  var nodeModel = this._lf.getNodeModelById(nodeData.id);
64
63
  for (var i = 0; i < edges.length; i++) {
@@ -82,7 +81,9 @@ var InsertNodeInPolyline = {
82
81
  break;
83
82
  }
84
83
  }
85
- },
86
- };
84
+ };
85
+ InsertNodeInPolyline.pluginName = 'insertNodeInPolyline';
86
+ return InsertNodeInPolyline;
87
+ }());
87
88
  exports.InsertNodeInPolyline = InsertNodeInPolyline;
88
89
  exports.default = InsertNodeInPolyline;
@@ -58,6 +58,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
58
58
  return _this;
59
59
  }
60
60
  GroupNodeModel.prototype.initNodeData = function (data) {
61
+ var _this = this;
61
62
  _super.prototype.initNodeData.call(this, data);
62
63
  var children = [];
63
64
  if (Array.isArray(data.children)) {
@@ -78,18 +79,33 @@ var GroupNodeModel = /** @class */ (function (_super) {
78
79
  this.resizable = false;
79
80
  this.autoToFront = false;
80
81
  this.foldable = false;
81
- this.properties.isFolded = false;
82
+ if (this.properties.isFolded === undefined) {
83
+ this.properties.isFolded = false;
84
+ }
82
85
  this.isFolded = this.properties.isFolded;
86
+ // fixme: 虽然默认保存的分组不会收起,但是如果重写保存数据分组了,
87
+ // 此处代码会导致多一个history记录
88
+ setTimeout(function () {
89
+ _this.isFolded && _this.foldGroup(_this.isFolded);
90
+ });
91
+ // this.foldGroup(this.isFolded);
83
92
  };
84
93
  GroupNodeModel.prototype.getResizeOutlineStyle = function () {
85
94
  var style = _super.prototype.getResizeOutlineStyle.call(this);
86
95
  style.stroke = 'none';
87
96
  return style;
88
97
  };
98
+ /**
99
+ * 折叠分组
100
+ * 1. 折叠分组的宽高
101
+ * 2. 处理分组子节点
102
+ * 3. 处理连线
103
+ */
89
104
  GroupNodeModel.prototype.foldGroup = function (isFolded) {
90
105
  var _this = this;
91
106
  this.setProperty('isFolded', isFolded);
92
107
  this.isFolded = isFolded;
108
+ // step 1
93
109
  if (isFolded) {
94
110
  this.x = this.x - this.width / 2 + this.foldedWidth / 2;
95
111
  this.y = this.y - this.height / 2 + this.foldedHeight / 2;
@@ -104,70 +120,109 @@ var GroupNodeModel = /** @class */ (function (_super) {
104
120
  this.x = this.x + this.width / 2 - this.foldedWidth / 2;
105
121
  this.y = this.y + this.height / 2 - this.foldedHeight / 2;
106
122
  }
107
- // 移动分组上的连线
108
- var inCommingEdges = this.graphModel.getNodeIncomingEdge(this.id);
109
- var outgoingEdges = this.graphModel.getNodeOutgoingEdge(this.id);
110
- inCommingEdges.concat(outgoingEdges).forEach(function (edgeModel) {
111
- _this.graphModel.deleteEdgeById(edgeModel.id);
112
- if (!edgeModel.isFoldedEdge) {
113
- var isCommingEdge = edgeModel.targetNodeId === _this.id;
114
- var data = edgeModel.getData();
115
- if (isCommingEdge) {
116
- data.endPoint = undefined;
117
- }
118
- else {
119
- data.startPoint = undefined;
120
- }
121
- data.pointsList = undefined;
122
- _this.graphModel.addEdge(data);
123
- }
124
- });
123
+ // step 2
124
+ var allEdges = this.incoming.edges.concat(this.outgoing.edges);
125
125
  this.children.forEach(function (elementId) {
126
126
  var nodeModel = _this.graphModel.getElement(elementId);
127
127
  nodeModel.visible = !isFolded;
128
- _this.foldEdge(elementId, isFolded);
128
+ allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
129
129
  });
130
+ // step 3
131
+ this.foldEdge(isFolded, allEdges);
132
+ };
133
+ GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
134
+ var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
135
+ style.stroke = 'transparent';
136
+ style.fill = 'transparent';
137
+ style.hover.fill = 'transparent';
138
+ style.hover.stroke = 'transparent';
139
+ return style;
130
140
  };
131
141
  /**
132
- * 折叠分组的时候,处理分组内部子节点上的连线
133
- * 1. 为了保证校验规则不被打乱,所以只隐藏子节点上面的连线。
134
- * 2. 重新创建一个属性一样的边。
135
- * 3. 这个边拥有virtual=true的属性,表示不支持直接修改此边内容。
142
+ * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
143
+ * 边的分类:
144
+ * - 虚拟边:分组被收起时,表示分组本身与外部节点关系的边。
145
+ * - 真实边:分组本身或者分组内部节点与外部节点节点(非收起分组)关系的边。
146
+ * 如果一个分组,本身与外部节点有M条连线,且内部N个子节点与外部节点有连线,那么这个分组收起时会生成M+N条连线。
147
+ * 折叠分组时:
148
+ * - 原有的虚拟边删除;
149
+ * - 创建一个虚拟边;
150
+ * - 真实边则隐藏;
151
+ * 展开分组是:
152
+ * - 原有的虚拟边删除;
153
+ * - 如果目外部点是收起的分组,则创建虚拟边;
154
+ * - 如果外部节点是普通节点,则显示真实边;
136
155
  */
137
- GroupNodeModel.prototype.foldEdge = function (nodeId, isFolded) {
156
+ GroupNodeModel.prototype.foldEdge = function (isFolded, allEdges) {
138
157
  var _this = this;
139
- var inCommingEdges = this.graphModel.getNodeIncomingEdge(nodeId);
140
- var outgoingEdges = this.graphModel.getNodeOutgoingEdge(nodeId);
141
- inCommingEdges.concat(outgoingEdges).forEach(function (edgeModel, index) {
142
- var _a;
143
- edgeModel.visible = !isFolded;
144
- if (isFolded
145
- && (!_this.children.has(edgeModel.targetNodeId)
146
- || !_this.children.has(edgeModel.sourceNodeId))) {
147
- var isCommingEdge = edgeModel.targetNodeId === nodeId;
148
- if (isFolded) {
149
- var data = edgeModel.getData();
150
- data.id = data.id + "__" + index;
151
- if (isCommingEdge) {
152
- data.endPoint = undefined;
153
- data.targetNodeId = _this.id;
154
- }
155
- else {
156
- data.startPoint = undefined;
157
- data.sourceNodeId = _this.id;
158
- }
159
- data.text = (_a = data.text) === null || _a === void 0 ? void 0 : _a.value;
160
- data.pointsList = undefined;
161
- var model = _this.graphModel.addEdge(data);
162
- model.virtual = true;
163
- // 强制不保存group连线数据
164
- model.getData = function () { return null; };
165
- model.text.editable = false;
166
- model.isFoldedEdge = true;
158
+ allEdges.forEach(function (edgeModel, index) {
159
+ var id = edgeModel.id, sourceNodeId = edgeModel.sourceNodeId, targetNodeId = edgeModel.targetNodeId, startPoint = edgeModel.startPoint, endPoint = edgeModel.endPoint, type = edgeModel.type, properties = edgeModel.properties, text = edgeModel.text;
160
+ var data = {
161
+ id: id + "__" + index,
162
+ sourceNodeId: sourceNodeId,
163
+ targetNodeId: targetNodeId,
164
+ startPoint: startPoint,
165
+ endPoint: endPoint,
166
+ type: type,
167
+ properties: properties,
168
+ text: text === null || text === void 0 ? void 0 : text.value,
169
+ };
170
+ if (edgeModel.virtual) {
171
+ _this.graphModel.deleteEdgeById(edgeModel.id);
172
+ }
173
+ // 折叠时,处理未被隐藏的边的逻辑
174
+ if (isFolded && edgeModel.visible !== false) {
175
+ // 需要确认此分组节点是新连线的起点还是终点
176
+ // 创建一个虚拟边,虚拟边相对真实边,起点或者终点从一起分组内部的节点成为了分组,
177
+ // 如果需要被隐藏的边的起点在需要折叠的分组中,那么设置虚拟边的开始节点为此分组
178
+ if (_this.children.has(sourceNodeId) || _this.id === sourceNodeId) {
179
+ data.startPoint = undefined;
180
+ data.sourceNodeId = _this.id;
181
+ }
182
+ else {
183
+ data.endPoint = undefined;
184
+ data.targetNodeId = _this.id;
185
+ }
186
+ _this.createVirtualEdge(data);
187
+ edgeModel.visible = false;
188
+ }
189
+ // 展开时,处理被隐藏的边的逻辑
190
+ if (!isFolded && edgeModel.visible === false) {
191
+ // 展开分组时:判断真实边的起点和终点是否有任一节点在已折叠分组中,如果不是,则显示真实边。如果是,这修改这个边的对应目标节点id来创建虚拟边。
192
+ var targetNodeIdGroup = _this.graphModel.group.getNodeGroup(targetNodeId);
193
+ // 考虑目标节点本来就是分组的情况
194
+ if (!targetNodeIdGroup) {
195
+ targetNodeIdGroup = _this.graphModel.getNodeModelById(targetNodeId);
196
+ }
197
+ var sourceNodeIdGroup = _this.graphModel.group.getNodeGroup(sourceNodeId);
198
+ if (!sourceNodeIdGroup) {
199
+ sourceNodeIdGroup = _this.graphModel.getNodeModelById(sourceNodeId);
200
+ }
201
+ if (targetNodeIdGroup && targetNodeIdGroup.isGroup && targetNodeIdGroup.isFolded) {
202
+ data.targetNodeId = targetNodeIdGroup.id;
203
+ data.endPoint = undefined;
204
+ _this.createVirtualEdge(data);
205
+ }
206
+ else if (sourceNodeIdGroup && sourceNodeIdGroup.isGroup && sourceNodeIdGroup.isFolded) {
207
+ data.sourceNodeId = sourceNodeIdGroup.id;
208
+ data.startPoint = undefined;
209
+ _this.createVirtualEdge(data);
210
+ }
211
+ else {
212
+ edgeModel.visible = true;
167
213
  }
168
214
  }
169
215
  });
170
216
  };
217
+ GroupNodeModel.prototype.createVirtualEdge = function (edgeData) {
218
+ edgeData.pointsList = undefined;
219
+ var model = this.graphModel.addEdge(edgeData);
220
+ model.virtual = true;
221
+ // 强制不保存group连线数据
222
+ model.getData = function () { return null; };
223
+ model.text.editable = false;
224
+ model.isFoldedEdge = true;
225
+ };
171
226
  GroupNodeModel.prototype.isInRange = function (_a) {
172
227
  var x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
173
228
  return x1 >= (this.x - this.width / 2)
@@ -208,6 +263,17 @@ var GroupNodeModel = /** @class */ (function (_super) {
208
263
  delete properties.isFolded;
209
264
  return data;
210
265
  };
266
+ GroupNodeModel.prototype.getHistoryData = function () {
267
+ var data = _super.prototype.getData.call(this);
268
+ data.children = __spread(this.children);
269
+ var properties = data.properties;
270
+ delete properties.groupAddable;
271
+ if (properties.isFolded) { // 如果分组被折叠
272
+ data.x = data.x + this.unfoldedWidth / 2 - this.foldedWidth / 2;
273
+ data.y = data.y + this.unfoldedHight / 2 - this.foldedHeight / 2;
274
+ }
275
+ return data;
276
+ };
211
277
  return GroupNodeModel;
212
278
  }(NodeResize_1.RectResize.model));
213
279
  var GroupNode = /** @class */ (function (_super) {
@@ -59,6 +59,15 @@ var Group = /** @class */ (function () {
59
59
  group.setAllowAppendChild(false);
60
60
  }
61
61
  };
62
+ this.deleteGroupChild = function (_a) {
63
+ var data = _a.data;
64
+ var groupId = _this.nodeGroupMap.get(data.id);
65
+ if (groupId) {
66
+ var group = _this.lf.getNodeModelById(groupId);
67
+ group.removeChild(data.id);
68
+ _this.nodeGroupMap.delete(data.id);
69
+ }
70
+ };
62
71
  this.setActiveGroup = function (_a) {
63
72
  var data = _a.data;
64
73
  var nodeModel = _this.lf.getNodeModelById(data.id);
@@ -96,20 +105,14 @@ var Group = /** @class */ (function () {
96
105
  }
97
106
  return true;
98
107
  });
108
+ lf.graphModel.group = this;
99
109
  lf.on('node:add', this.appendNodeToGrop);
110
+ lf.on('node:delete', this.deleteGroupChild);
100
111
  lf.on('node:drop', this.appendNodeToGrop);
101
112
  lf.on('node:dnd-drag', this.setActiveGroup);
102
113
  lf.on('node:drag', this.setActiveGroup);
103
114
  lf.on('graph:rendered', this.graphRendered);
104
115
  }
105
- Group.prototype.getGroups = function () {
106
- var groups = [];
107
- this.lf.graphModel.nodes.forEach(function (nodeModel) {
108
- if (nodeModel.isGroup) {
109
- groups.push(nodeModel);
110
- }
111
- });
112
- };
113
116
  /**
114
117
  * 获取自定位置其所属分组
115
118
  */
@@ -122,6 +125,15 @@ var Group = /** @class */ (function () {
122
125
  }
123
126
  }
124
127
  };
128
+ /**
129
+ * 获取某个节点所属的groupModel
130
+ */
131
+ Group.prototype.getNodeGroup = function (nodeId) {
132
+ var groupId = this.nodeGroupMap.get(nodeId);
133
+ if (groupId) {
134
+ return this.lf.getNodeModelById(groupId);
135
+ }
136
+ };
125
137
  Group.pluginName = 'group';
126
138
  return Group;
127
139
  }());
@@ -1,5 +1,5 @@
1
1
  import { h, Component } from 'preact';
2
- import { BaseNodeModel, GraphModel } from '@logicflow/core';
2
+ import { BaseNodeModel, GraphModel, LogicFlowUtil } from '@logicflow/core';
3
3
  interface IProps {
4
4
  index: number;
5
5
  x: number;
@@ -9,10 +9,10 @@ interface IProps {
9
9
  style?: CSSStyleDeclaration;
10
10
  }
11
11
  declare class Control extends Component<IProps> {
12
- dragHandler: Function;
13
12
  index: number;
14
13
  nodeModel: BaseNodeModel;
15
14
  graphModel: GraphModel;
15
+ dragHandler: LogicFlowUtil.StepDrag;
16
16
  constructor(props: any);
17
17
  getNodeEdges(nodeId: any): {
18
18
  sourceEdges: any[];