@logicflow/extension 1.1.28 → 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 (55) 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/curved-edge/index.js +47 -40
  7. package/cjs/materials/group/GroupNode.js +11 -4
  8. package/cjs/materials/group/index.js +75 -19
  9. package/cjs/turbo-adapter/index.js +4 -6
  10. package/es/NodeResize/Control/Control.d.ts +4 -1
  11. package/es/NodeResize/Control/Control.js +72 -13
  12. package/es/NodeResize/Node/DiamondResize.d.ts +2 -0
  13. package/es/NodeResize/Node/DiamondResize.js +16 -0
  14. package/es/NodeResize/Node/EllipseResize.d.ts +2 -0
  15. package/es/NodeResize/Node/EllipseResize.js +16 -0
  16. package/es/NodeResize/Node/HtmlResize.d.ts +2 -0
  17. package/es/NodeResize/Node/HtmlResize.js +16 -0
  18. package/es/NodeResize/Node/RectResize.d.ts +2 -0
  19. package/es/NodeResize/Node/RectResize.js +16 -0
  20. package/es/materials/curved-edge/index.d.ts +7 -6
  21. package/es/materials/curved-edge/index.js +47 -39
  22. package/es/materials/group/GroupNode.d.ts +5 -1
  23. package/es/materials/group/GroupNode.js +11 -4
  24. package/es/materials/group/index.d.ts +13 -1
  25. package/es/materials/group/index.js +75 -19
  26. package/es/turbo-adapter/index.js +4 -6
  27. package/lib/AutoLayout.js +1 -1
  28. package/lib/BpmnAdapter.js +1 -1
  29. package/lib/BpmnElement.js +1 -1
  30. package/lib/ContextMenu.js +1 -1
  31. package/lib/Control.js +1 -1
  32. package/lib/CurvedEdge.js +1 -1
  33. package/lib/DndPanel.js +1 -1
  34. package/lib/FlowPath.js +1 -1
  35. package/lib/Group.js +1 -1
  36. package/lib/Highlight.js +1 -1
  37. package/lib/InsertNodeInPolyline.js +1 -1
  38. package/lib/Menu.js +1 -1
  39. package/lib/MiniMap.js +1 -1
  40. package/lib/NodeResize.js +1 -1
  41. package/lib/RectLabelNode.js +1 -1
  42. package/lib/SelectionSelect.js +1 -1
  43. package/lib/Snapshot.js +1 -1
  44. package/lib/TurboAdapter.js +1 -1
  45. package/lib/lfJson2Xml.js +1 -1
  46. package/lib/lfXml2Json.js +1 -1
  47. package/package.json +2 -2
  48. package/types/NodeResize/Control/Control.d.ts +4 -1
  49. package/types/NodeResize/Node/DiamondResize.d.ts +2 -0
  50. package/types/NodeResize/Node/EllipseResize.d.ts +2 -0
  51. package/types/NodeResize/Node/HtmlResize.d.ts +2 -0
  52. package/types/NodeResize/Node/RectResize.d.ts +2 -0
  53. package/types/materials/curved-edge/index.d.ts +7 -6
  54. package/types/materials/group/GroupNode.d.ts +5 -1
  55. 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) {
@@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () {
12
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
13
  };
14
14
  })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
15
26
  var __read = (this && this.__read) || function (o, n) {
16
27
  var m = typeof Symbol === "function" && o[Symbol.iterator];
17
28
  if (!m) return o;
@@ -29,17 +40,36 @@ var __read = (this && this.__read) || function (o, n) {
29
40
  return ar;
30
41
  };
31
42
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.CurvedEdge = void 0;
43
+ exports.CurvedEdgeModel = exports.CurvedEdge = void 0;
33
44
  var core_1 = require("@logicflow/core");
34
- var CurvedEdgeView = /** @class */ (function (_super) {
35
- __extends(CurvedEdgeView, _super);
36
- function CurvedEdgeView() {
45
+ var CurvedEdge = /** @class */ (function (_super) {
46
+ __extends(CurvedEdge, _super);
47
+ function CurvedEdge() {
37
48
  return _super !== null && _super.apply(this, arguments) || this;
38
49
  }
39
- CurvedEdgeView.prototype.getEdge = function () {
40
- var _a = this.props.model.getEdgeStyle(), strokeWidth = _a.strokeWidth, stroke = _a.stroke, strokeDashArray = _a.strokeDashArray;
41
- var points = this.props.model.points;
42
- var points2 = points.split(' ').map(function (p) { return p.split(',').map(function (a) { return Number(a); }); });
50
+ CurvedEdge.prototype.pointFilter = function (points) {
51
+ var allPoints = points;
52
+ var i = 1;
53
+ while (i < allPoints.length - 1) {
54
+ var _a = __read(allPoints[i - 1], 2), x = _a[0], y = _a[1];
55
+ var _b = __read(allPoints[i], 2), x1 = _b[0], y1 = _b[1];
56
+ var _c = __read(allPoints[i + 1], 2), x2 = _c[0], y2 = _c[1];
57
+ if ((x === x1 && x1 === x2)
58
+ || (y === y1 && y1 === y2)) {
59
+ allPoints.splice(i, 1);
60
+ }
61
+ else {
62
+ i++;
63
+ }
64
+ }
65
+ return allPoints;
66
+ };
67
+ CurvedEdge.prototype.getEdge = function () {
68
+ var model = this.props.model;
69
+ var points = model.points, isAnimation = model.isAnimation, arrowConfig = model.arrowConfig, _a = model.radius, radius = _a === void 0 ? 5 : _a;
70
+ var style = model.getEdgeStyle();
71
+ var animationStyle = model.getEdgeAnimationStyle();
72
+ var points2 = this.pointFilter(points.split(' ').map(function (p) { return p.split(',').map(function (a) { return Number(a); }); }));
43
73
  var _b = __read(points2[0], 2), startX = _b[0], startY = _b[1];
44
74
  var d = "M" + startX + " " + startY;
45
75
  // 1) 如果一个点不为开始和结束,则在这个点的前后增加弧度开始和结束点。
@@ -47,43 +77,36 @@ var CurvedEdgeView = /** @class */ (function (_super) {
47
77
  // 如果x相同则前一个点的x也不变,
48
78
  // y为(这个点的y 大于前一个点的y, 则 为 这个点的y - 5;小于前一个点的y, 则为这个点的y+5)
49
79
  // 同理,判断这个点与后一个点的x,y是否相同,如果x相同,则y进行加减,如果y相同,则x进行加减
50
- // todo: 好丑,看看怎么优化下
51
- var space = 5;
52
80
  for (var i = 1; i < points2.length - 1; i++) {
53
81
  var _c = __read(points2[i - 1], 2), preX = _c[0], preY = _c[1];
54
82
  var _d = __read(points2[i], 2), currentX = _d[0], currentY = _d[1];
55
83
  var _e = __read(points2[i + 1], 2), nextX = _e[0], nextY = _e[1];
56
84
  if (currentX === preX && currentY !== preY) {
57
- var y = currentY > preY ? currentY - space : currentY + space;
85
+ var y = currentY > preY ? currentY - radius : currentY + radius;
58
86
  d = d + " L " + currentX + " " + y;
59
87
  }
60
88
  if (currentY === preY && currentX !== preX) {
61
- var x = currentX > preX ? currentX - space : currentX + space;
89
+ var x = currentX > preX ? currentX - radius : currentX + radius;
62
90
  d = d + " L " + x + " " + currentY;
63
91
  }
64
92
  d = d + " Q " + currentX + " " + currentY;
65
93
  if (currentX === nextX && currentY !== nextY) {
66
- var y = currentY > nextY ? currentY - space : currentY + space;
94
+ var y = currentY > nextY ? currentY - radius : currentY + radius;
67
95
  d = d + " " + currentX + " " + y;
68
96
  }
69
97
  if (currentY === nextY && currentX !== nextX) {
70
- var x = currentX > nextX ? currentX - space : currentX + space;
98
+ var x = currentX > nextX ? currentX - radius : currentX + radius;
71
99
  d = d + " " + x + " " + currentY;
72
100
  }
73
101
  }
74
102
  var _f = __read(points2[points2.length - 1], 2), endX = _f[0], endY = _f[1];
75
103
  d = d + " L " + endX + " " + endY;
76
- return core_1.h('path', {
77
- d: d,
78
- strokeWidth: strokeWidth,
79
- stroke: stroke,
80
- fill: 'none',
81
- strokeDashArray: strokeDashArray,
82
- });
104
+ var attrs = __assign(__assign(__assign({ d: d, style: isAnimation ? animationStyle : {} }, style), arrowConfig), { fill: 'none' });
105
+ return core_1.h('path', __assign({ d: d }, attrs));
83
106
  };
84
- CurvedEdgeView.extendKey = 'curvedEdge';
85
- return CurvedEdgeView;
107
+ return CurvedEdge;
86
108
  }(core_1.PolylineEdge));
109
+ exports.CurvedEdge = CurvedEdge;
87
110
  var CurvedEdgeModel = /** @class */ (function (_super) {
88
111
  __extends(CurvedEdgeModel, _super);
89
112
  function CurvedEdgeModel() {
@@ -91,20 +114,4 @@ var CurvedEdgeModel = /** @class */ (function (_super) {
91
114
  }
92
115
  return CurvedEdgeModel;
93
116
  }(core_1.PolylineEdgeModel));
94
- var CurvedEdge = {
95
- pluginName: 'curved-edge',
96
- curvedSpace: 5,
97
- init: function (_a) {
98
- var curvedSpace = _a.curvedSpace;
99
- CurvedEdge.curvedSpace = curvedSpace;
100
- },
101
- install: function (lf) {
102
- lf.register({
103
- type: 'curved-edge',
104
- view: CurvedEdgeView,
105
- model: CurvedEdgeModel,
106
- });
107
- },
108
- };
109
- exports.CurvedEdge = CurvedEdge;
110
- exports.default = CurvedEdge;
117
+ exports.CurvedEdgeModel = CurvedEdgeModel;
@@ -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
@@ -84,7 +84,7 @@ function convertEdgeToTurboElement(edge) {
84
84
  outgoing: [targetNodeId],
85
85
  type: getTurboType(type),
86
86
  dockers: [],
87
- properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text, startPoint: JSON.stringify(startPoint), endPoint: JSON.stringify(endPoint), pointsList: JSON.stringify(text) }),
87
+ properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text, startPoint: JSON.stringify(startPoint), endPoint: JSON.stringify(endPoint), pointsList: JSON.stringify(pointsList) }),
88
88
  key: id,
89
89
  };
90
90
  }
@@ -123,16 +123,13 @@ function convertFlowElementToEdge(element) {
123
123
  properties: {},
124
124
  };
125
125
  if (startPoint) {
126
- // @ts-ignore
127
126
  edge.startPoint = JSON.parse(startPoint);
128
127
  }
129
128
  if (endPoint) {
130
- // @ts-ignore
131
129
  edge.endPoint = JSON.parse(endPoint);
132
130
  }
133
131
  if (pointsList) {
134
- // @ts-ignore
135
- edge.endPoint = JSON.parse(pointsList);
132
+ edge.pointsList = JSON.parse(pointsList);
136
133
  }
137
134
  // 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
138
135
  var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text'];
@@ -147,6 +144,7 @@ function convertFlowElementToEdge(element) {
147
144
  function convertFlowElementToNode(element) {
148
145
  var properties = element.properties, key = element.key, type = element.type, bounds = element.bounds;
149
146
  var x = properties.x, y = properties.y;
147
+ var text = properties.text;
150
148
  if (x === undefined) {
151
149
  var _a = __read(bounds, 2), _b = _a[0], x1 = _b.x, y1 = _b.y, _c = _a[1], x2 = _c.x, y2 = _c.y;
152
150
  x = (x1 + x2) / 2;
@@ -157,7 +155,7 @@ function convertFlowElementToNode(element) {
157
155
  type: TurboTypeMap[type],
158
156
  x: x,
159
157
  y: y,
160
- text: properties.text,
158
+ text: text,
161
159
  properties: {},
162
160
  };
163
161
  // 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失