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