@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
@@ -29,10 +29,6 @@ var DiamondResizeModel = /** @class */ (function (_super) {
29
29
  __extends(DiamondResizeModel, _super);
30
30
  function DiamondResizeModel(data, graphModel) {
31
31
  var _this = _super.call(this, data, graphModel) || this;
32
- _this.minWidth = 30;
33
- _this.minHeight = 30;
34
- _this.maxWidth = 2000;
35
- _this.maxHeight = 2000;
36
32
  var nodeSize = _this.properties.nodeSize;
37
33
  if (nodeSize) {
38
34
  _this.rx = nodeSize.rx;
@@ -40,6 +36,14 @@ var DiamondResizeModel = /** @class */ (function (_super) {
40
36
  }
41
37
  return _this;
42
38
  }
39
+ DiamondResizeModel.prototype.initNodeData = function (data) {
40
+ _super.prototype.initNodeData.call(this, data);
41
+ this.minWidth = 30;
42
+ this.minHeight = 30;
43
+ this.maxWidth = 2000;
44
+ this.maxHeight = 2000;
45
+ this.gridSize = 1;
46
+ };
43
47
  DiamondResizeModel.prototype.getOutlineStyle = function () {
44
48
  var style = _super.prototype.getOutlineStyle.call(this);
45
49
  style.stroke = 'none';
@@ -1,10 +1,7 @@
1
1
  import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
2
2
  declare class EllipseResizeModel extends EllipseNodeModel {
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;
@@ -17,10 +17,6 @@ var EllipseResizeModel = /** @class */ (function (_super) {
17
17
  __extends(EllipseResizeModel, _super);
18
18
  function EllipseResizeModel(data, graphModel) {
19
19
  var _this = _super.call(this, data, graphModel) || this;
20
- _this.minWidth = 30;
21
- _this.minHeight = 30;
22
- _this.maxWidth = 2000;
23
- _this.maxHeight = 2000;
24
20
  var nodeSize = _this.properties.nodeSize;
25
21
  if (nodeSize) {
26
22
  _this.rx = nodeSize.rx;
@@ -28,6 +24,13 @@ var EllipseResizeModel = /** @class */ (function (_super) {
28
24
  }
29
25
  return _this;
30
26
  }
27
+ EllipseResizeModel.prototype.initNodeData = function (data) {
28
+ _super.prototype.initNodeData.call(this, data);
29
+ this.minWidth = 30;
30
+ this.minHeight = 30;
31
+ this.maxWidth = 2000;
32
+ this.maxHeight = 2000;
33
+ };
31
34
  EllipseResizeModel.prototype.getOutlineStyle = function () {
32
35
  var style = _super.prototype.getOutlineStyle.call(this);
33
36
  style.stroke = 'none';
@@ -1,10 +1,7 @@
1
1
  import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
2
2
  declare class HtmlResizeModel extends HtmlNodeModel {
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;
@@ -17,10 +17,6 @@ var HtmlResizeModel = /** @class */ (function (_super) {
17
17
  __extends(HtmlResizeModel, _super);
18
18
  function HtmlResizeModel(data, graphModel) {
19
19
  var _this = _super.call(this, data, graphModel) || this;
20
- _this.minWidth = 30;
21
- _this.minHeight = 30;
22
- _this.maxWidth = 2000;
23
- _this.maxHeight = 2000;
24
20
  var nodeSize = _this.properties.nodeSize;
25
21
  if (nodeSize) {
26
22
  _this.width = nodeSize.width;
@@ -28,6 +24,13 @@ var HtmlResizeModel = /** @class */ (function (_super) {
28
24
  }
29
25
  return _this;
30
26
  }
27
+ HtmlResizeModel.prototype.initNodeData = function (data) {
28
+ _super.prototype.initNodeData.call(this, data);
29
+ this.minWidth = 30;
30
+ this.minHeight = 30;
31
+ this.maxWidth = 2000;
32
+ this.maxHeight = 2000;
33
+ };
31
34
  HtmlResizeModel.prototype.getOutlineStyle = function () {
32
35
  var style = _super.prototype.getOutlineStyle.call(this);
33
36
  style.stroke = 'none';
@@ -1,10 +1,7 @@
1
1
  import { h, RectNode, RectNodeModel } from '@logicflow/core';
2
2
  declare class RectResizeModel extends RectNodeModel {
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
  fill: string;
@@ -17,10 +17,6 @@ var RectResizeModel = /** @class */ (function (_super) {
17
17
  __extends(RectResizeModel, _super);
18
18
  function RectResizeModel(data, graphModel) {
19
19
  var _this = _super.call(this, data, graphModel) || this;
20
- _this.minWidth = 30;
21
- _this.minHeight = 30;
22
- _this.maxWidth = 2000;
23
- _this.maxHeight = 2000;
24
20
  var nodeSize = _this.properties.nodeSize;
25
21
  if (nodeSize) {
26
22
  _this.width = nodeSize.width;
@@ -28,6 +24,13 @@ var RectResizeModel = /** @class */ (function (_super) {
28
24
  }
29
25
  return _this;
30
26
  }
27
+ RectResizeModel.prototype.initNodeData = function (data) {
28
+ _super.prototype.initNodeData.call(this, data);
29
+ this.minWidth = 30;
30
+ this.minHeight = 30;
31
+ this.maxWidth = 2000;
32
+ this.maxHeight = 2000;
33
+ };
31
34
  RectResizeModel.prototype.getOutlineStyle = function () {
32
35
  var style = _super.prototype.getOutlineStyle.call(this);
33
36
  style.stroke = 'none';
@@ -39,7 +42,7 @@ var RectResizeModel = /** @class */ (function (_super) {
39
42
  RectResizeModel.prototype.getResizeOutlineStyle = function () {
40
43
  return {
41
44
  fill: 'none',
42
- stroke: '#000000',
45
+ stroke: 'transparent',
43
46
  strokeWidth: 1,
44
47
  strokeDasharray: '3,3',
45
48
  };
@@ -1,11 +1,14 @@
1
- declare const InsertNodeInPolyline: {
2
- pluginName: string;
3
- _lf: any;
1
+ import LogicFlow from '@logicflow/core';
2
+ declare class InsertNodeInPolyline {
3
+ static pluginName: string;
4
+ _lf: LogicFlow;
4
5
  dndAdd: boolean;
5
6
  dropAdd: boolean;
6
- install(lf: any): void;
7
+ constructor({ lf }: {
8
+ lf: any;
9
+ });
7
10
  eventHandler(): void;
8
11
  insetNode(nodeData: any): void;
9
- };
12
+ }
10
13
  export { InsertNodeInPolyline };
11
14
  export default InsertNodeInPolyline;
@@ -19,26 +19,25 @@ var __spread = (this && this.__spread) || function () {
19
19
  return ar;
20
20
  };
21
21
  import { isNodeInSegement } from './edge';
22
- var InsertNodeInPolyline = {
23
- pluginName: 'insertNodeInPolyline',
24
- _lf: null,
25
- dndAdd: true,
26
- dropAdd: true,
27
- install: function (lf) {
28
- InsertNodeInPolyline._lf = lf;
22
+ var InsertNodeInPolyline = /** @class */ (function () {
23
+ function InsertNodeInPolyline(_a) {
24
+ var lf = _a.lf;
25
+ this._lf = lf;
26
+ this.dndAdd = true;
27
+ this.dropAdd = true;
29
28
  this.eventHandler();
30
- },
31
- eventHandler: function () {
29
+ }
30
+ InsertNodeInPolyline.prototype.eventHandler = function () {
32
31
  var _this = this;
33
32
  // 监听事件
34
- if (InsertNodeInPolyline.dndAdd) {
35
- InsertNodeInPolyline._lf.on('node:dnd-add', function (_a) {
33
+ if (this.dndAdd) {
34
+ this._lf.on('node:dnd-add', function (_a) {
36
35
  var data = _a.data;
37
- InsertNodeInPolyline.insetNode(data);
36
+ _this.insetNode(data);
38
37
  });
39
38
  }
40
- if (InsertNodeInPolyline.dropAdd) {
41
- InsertNodeInPolyline._lf.on('node:drop', function (_a) {
39
+ if (this.dropAdd) {
40
+ this._lf.on('node:drop', function (_a) {
42
41
  var data = _a.data;
43
42
  var edges = _this._lf.graphModel.edges;
44
43
  var id = data.id;
@@ -50,12 +49,12 @@ var InsertNodeInPolyline = {
50
49
  }
51
50
  }
52
51
  if (pureNode) {
53
- InsertNodeInPolyline.insetNode(data);
52
+ _this.insetNode(data);
54
53
  }
55
54
  });
56
55
  }
57
- },
58
- insetNode: function (nodeData) {
56
+ };
57
+ InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
59
58
  var edges = this._lf.graphModel.edges;
60
59
  var nodeModel = this._lf.getNodeModelById(nodeData.id);
61
60
  for (var i = 0; i < edges.length; i++) {
@@ -79,7 +78,9 @@ var InsertNodeInPolyline = {
79
78
  break;
80
79
  }
81
80
  }
82
- },
83
- };
81
+ };
82
+ InsertNodeInPolyline.pluginName = 'insertNodeInPolyline';
83
+ return InsertNodeInPolyline;
84
+ }());
84
85
  export { InsertNodeInPolyline };
85
86
  export default InsertNodeInPolyline;
@@ -2,12 +2,33 @@ import { h } from '@logicflow/core';
2
2
  import { RectResize } from '../../NodeResize';
3
3
  declare class GroupNodeModel extends RectResize.model {
4
4
  readonly isGroup = true;
5
+ /**
6
+ * 此分组的子节点Id
7
+ */
5
8
  children: Set<string>;
9
+ /**
10
+ * 其子节点是否被禁止通过拖拽移出分组。 默认false,允许拖拽移除分组。
11
+ */
6
12
  isRestrict: boolean;
13
+ /**
14
+ * 分组节点是否允许调整大小。
15
+ */
7
16
  resizable: boolean;
17
+ /**
18
+ * 分组节点是否允许折叠
19
+ */
8
20
  foldable: boolean;
21
+ /**
22
+ * 折叠后的宽度
23
+ */
9
24
  foldedWidth: number;
25
+ /**
26
+ * 折叠后的高度
27
+ */
10
28
  foldedHeight: number;
29
+ /**
30
+ * 分组折叠状态
31
+ */
11
32
  isFolded: boolean;
12
33
  unfoldedWidth: number;
13
34
  unfoldedHight: number;
@@ -18,14 +39,31 @@ declare class GroupNodeModel extends RectResize.model {
18
39
  strokeWidth: number;
19
40
  strokeDasharray: string;
20
41
  };
42
+ /**
43
+ * 折叠分组
44
+ * 1. 折叠分组的宽高
45
+ * 2. 处理分组子节点
46
+ * 3. 处理连线
47
+ */
21
48
  foldGroup(isFolded: any): void;
49
+ getAnchorStyle(anchorInfo: any): Record<string, any>;
22
50
  /**
23
- * 折叠分组的时候,处理分组内部子节点上的连线
24
- * 1. 为了保证校验规则不被打乱,所以只隐藏子节点上面的连线。
25
- * 2. 重新创建一个属性一样的边。
26
- * 3. 这个边拥有virtual=true的属性,表示不支持直接修改此边内容。
51
+ * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
52
+ * 边的分类:
53
+ * - 虚拟边:分组被收起时,表示分组本身与外部节点关系的边。
54
+ * - 真实边:分组本身或者分组内部节点与外部节点节点(非收起分组)关系的边。
55
+ * 如果一个分组,本身与外部节点有M条连线,且内部N个子节点与外部节点有连线,那么这个分组收起时会生成M+N条连线。
56
+ * 折叠分组时:
57
+ * - 原有的虚拟边删除;
58
+ * - 创建一个虚拟边;
59
+ * - 真实边则隐藏;
60
+ * 展开分组是:
61
+ * - 原有的虚拟边删除;
62
+ * - 如果目外部点是收起的分组,则创建虚拟边;
63
+ * - 如果外部节点是普通节点,则显示真实边;
27
64
  */
28
65
  private foldEdge;
66
+ createVirtualEdge(edgeData: any): void;
29
67
  isInRange({ x1, y1, x2, y2 }: {
30
68
  x1: any;
31
69
  y1: any;
@@ -50,6 +88,7 @@ declare class GroupNodeModel extends RectResize.model {
50
88
  fill: string;
51
89
  };
52
90
  getData(): import("@logicflow/core").NodeData;
91
+ getHistoryData(): import("@logicflow/core").NodeData;
53
92
  }
54
93
  declare class GroupNode extends RectResize.view {
55
94
  getControlGroup(): h.JSX.Element;
@@ -56,6 +56,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
56
56
  return _this;
57
57
  }
58
58
  GroupNodeModel.prototype.initNodeData = function (data) {
59
+ var _this = this;
59
60
  _super.prototype.initNodeData.call(this, data);
60
61
  var children = [];
61
62
  if (Array.isArray(data.children)) {
@@ -76,18 +77,34 @@ var GroupNodeModel = /** @class */ (function (_super) {
76
77
  this.resizable = false;
77
78
  this.autoToFront = false;
78
79
  this.foldable = false;
79
- this.properties.isFolded = false;
80
+ if (this.properties.isFolded === undefined) {
81
+ this.properties.isFolded = false;
82
+ }
80
83
  this.isFolded = this.properties.isFolded;
84
+ // fixme: 虽然默认保存的分组不会收起,但是如果重写保存数据分组了,
85
+ // 此处代码会导致多一个history记录
86
+ setTimeout(function () {
87
+ _this.isFolded && _this.foldGroup(_this.isFolded);
88
+ });
89
+ // this.foldGroup(this.isFolded);
81
90
  };
82
91
  GroupNodeModel.prototype.getResizeOutlineStyle = function () {
83
92
  var style = _super.prototype.getResizeOutlineStyle.call(this);
84
93
  style.stroke = 'none';
85
94
  return style;
86
95
  };
96
+ /**
97
+ * 折叠分组
98
+ * 1. 折叠分组的宽高
99
+ * 2. 处理分组子节点
100
+ * 3. 处理连线
101
+ */
87
102
  GroupNodeModel.prototype.foldGroup = function (isFolded) {
88
103
  var _this = this;
89
104
  this.setProperty('isFolded', isFolded);
90
105
  this.isFolded = isFolded;
106
+ console.log(44);
107
+ // step 1
91
108
  if (isFolded) {
92
109
  this.x = this.x - this.width / 2 + this.foldedWidth / 2;
93
110
  this.y = this.y - this.height / 2 + this.foldedHeight / 2;
@@ -102,70 +119,112 @@ var GroupNodeModel = /** @class */ (function (_super) {
102
119
  this.x = this.x + this.width / 2 - this.foldedWidth / 2;
103
120
  this.y = this.y + this.height / 2 - this.foldedHeight / 2;
104
121
  }
105
- // 移动分组上的连线
106
- var inCommingEdges = this.graphModel.getNodeIncomingEdge(this.id);
107
- var outgoingEdges = this.graphModel.getNodeOutgoingEdge(this.id);
108
- inCommingEdges.concat(outgoingEdges).forEach(function (edgeModel) {
109
- _this.graphModel.deleteEdgeById(edgeModel.id);
110
- if (!edgeModel.isFoldedEdge) {
111
- var isCommingEdge = edgeModel.targetNodeId === _this.id;
112
- var data = edgeModel.getData();
113
- if (isCommingEdge) {
114
- data.endPoint = undefined;
115
- }
116
- else {
117
- data.startPoint = undefined;
118
- }
119
- data.pointsList = undefined;
120
- _this.graphModel.addEdge(data);
121
- }
122
- });
122
+ // step 2
123
+ var allEdges = this.incoming.edges.concat(this.outgoing.edges);
123
124
  this.children.forEach(function (elementId) {
124
125
  var nodeModel = _this.graphModel.getElement(elementId);
125
126
  nodeModel.visible = !isFolded;
126
- _this.foldEdge(elementId, isFolded);
127
+ allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
127
128
  });
129
+ // step 3
130
+ this.foldEdge(isFolded, allEdges);
131
+ };
132
+ GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
133
+ var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
134
+ style.stroke = 'transparent';
135
+ style.fill = 'transparent';
136
+ style.hover.fill = 'transparent';
137
+ style.hover.stroke = 'transparent';
138
+ return style;
128
139
  };
129
140
  /**
130
- * 折叠分组的时候,处理分组内部子节点上的连线
131
- * 1. 为了保证校验规则不被打乱,所以只隐藏子节点上面的连线。
132
- * 2. 重新创建一个属性一样的边。
133
- * 3. 这个边拥有virtual=true的属性,表示不支持直接修改此边内容。
141
+ * 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
142
+ * 边的分类:
143
+ * - 虚拟边:分组被收起时,表示分组本身与外部节点关系的边。
144
+ * - 真实边:分组本身或者分组内部节点与外部节点节点(非收起分组)关系的边。
145
+ * 如果一个分组,本身与外部节点有M条连线,且内部N个子节点与外部节点有连线,那么这个分组收起时会生成M+N条连线。
146
+ * 折叠分组时:
147
+ * - 原有的虚拟边删除;
148
+ * - 创建一个虚拟边;
149
+ * - 真实边则隐藏;
150
+ * 展开分组是:
151
+ * - 原有的虚拟边删除;
152
+ * - 如果目外部点是收起的分组,则创建虚拟边;
153
+ * - 如果外部节点是普通节点,则显示真实边;
134
154
  */
135
- GroupNodeModel.prototype.foldEdge = function (nodeId, isFolded) {
155
+ GroupNodeModel.prototype.foldEdge = function (isFolded, allEdges) {
136
156
  var _this = this;
137
- var inCommingEdges = this.graphModel.getNodeIncomingEdge(nodeId);
138
- var outgoingEdges = this.graphModel.getNodeOutgoingEdge(nodeId);
139
- inCommingEdges.concat(outgoingEdges).forEach(function (edgeModel, index) {
140
- var _a;
141
- edgeModel.visible = !isFolded;
142
- if (isFolded
143
- && (!_this.children.has(edgeModel.targetNodeId)
144
- || !_this.children.has(edgeModel.sourceNodeId))) {
145
- var isCommingEdge = edgeModel.targetNodeId === nodeId;
146
- if (isFolded) {
147
- var data = edgeModel.getData();
148
- data.id = data.id + "__" + index;
149
- if (isCommingEdge) {
150
- data.endPoint = undefined;
151
- data.targetNodeId = _this.id;
152
- }
153
- else {
154
- data.startPoint = undefined;
155
- data.sourceNodeId = _this.id;
156
- }
157
- data.text = (_a = data.text) === null || _a === void 0 ? void 0 : _a.value;
158
- data.pointsList = undefined;
159
- var model = _this.graphModel.addEdge(data);
160
- model.virtual = true;
161
- // 强制不保存group连线数据
162
- model.getData = function () { return null; };
163
- model.text.editable = false;
164
- model.isFoldedEdge = true;
157
+ allEdges.forEach(function (edgeModel, index) {
158
+ 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;
159
+ var data = {
160
+ id: id + "__" + index,
161
+ sourceNodeId: sourceNodeId,
162
+ targetNodeId: targetNodeId,
163
+ startPoint: startPoint,
164
+ endPoint: endPoint,
165
+ type: type,
166
+ properties: properties,
167
+ text: text === null || text === void 0 ? void 0 : text.value,
168
+ };
169
+ if (edgeModel.virtual) {
170
+ _this.graphModel.deleteEdgeById(edgeModel.id);
171
+ }
172
+ var targetNodeIdGroup = _this.graphModel.group.getNodeGroup(targetNodeId);
173
+ // 考虑目标节点本来就是分组的情况
174
+ if (!targetNodeIdGroup) {
175
+ targetNodeIdGroup = _this.graphModel.getNodeModelById(targetNodeId);
176
+ }
177
+ var sourceNodeIdGroup = _this.graphModel.group.getNodeGroup(sourceNodeId);
178
+ if (!sourceNodeIdGroup) {
179
+ sourceNodeIdGroup = _this.graphModel.getNodeModelById(sourceNodeId);
180
+ }
181
+ // 折叠时,处理未被隐藏的边的逻辑
182
+ if (isFolded && edgeModel.visible !== false) {
183
+ // 需要确认此分组节点是新连线的起点还是终点
184
+ // 创建一个虚拟边,虚拟边相对真实边,起点或者终点从一起分组内部的节点成为了分组,
185
+ // 如果需要被隐藏的边的起点在需要折叠的分组中,那么设置虚拟边的开始节点为此分组
186
+ if (_this.children.has(sourceNodeId) || _this.id === sourceNodeId) {
187
+ data.startPoint = undefined;
188
+ data.sourceNodeId = _this.id;
189
+ }
190
+ else {
191
+ data.endPoint = undefined;
192
+ data.targetNodeId = _this.id;
193
+ }
194
+ // 如果边的起点和终点都在分组内部,则不创建新的虚拟边
195
+ if (targetNodeIdGroup.id !== _this.id || sourceNodeIdGroup.id !== _this.id) {
196
+ _this.createVirtualEdge(data);
197
+ }
198
+ edgeModel.visible = false;
199
+ }
200
+ // 展开时,处理被隐藏的边的逻辑
201
+ if (!isFolded && edgeModel.visible === false) {
202
+ // 展开分组时:判断真实边的起点和终点是否有任一节点在已折叠分组中,如果不是,则显示真实边。如果是,这修改这个边的对应目标节点id来创建虚拟边。
203
+ if (targetNodeIdGroup && targetNodeIdGroup.isGroup && targetNodeIdGroup.isFolded) {
204
+ data.targetNodeId = targetNodeIdGroup.id;
205
+ data.endPoint = undefined;
206
+ _this.createVirtualEdge(data);
207
+ }
208
+ else if (sourceNodeIdGroup && sourceNodeIdGroup.isGroup && sourceNodeIdGroup.isFolded) {
209
+ data.sourceNodeId = sourceNodeIdGroup.id;
210
+ data.startPoint = undefined;
211
+ _this.createVirtualEdge(data);
212
+ }
213
+ else {
214
+ edgeModel.visible = true;
165
215
  }
166
216
  }
167
217
  });
168
218
  };
219
+ GroupNodeModel.prototype.createVirtualEdge = function (edgeData) {
220
+ edgeData.pointsList = undefined;
221
+ var model = this.graphModel.addEdge(edgeData);
222
+ model.virtual = true;
223
+ // 强制不保存group连线数据
224
+ model.getData = function () { return null; };
225
+ model.text.editable = false;
226
+ model.isFoldedEdge = true;
227
+ };
169
228
  GroupNodeModel.prototype.isInRange = function (_a) {
170
229
  var x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
171
230
  return x1 >= (this.x - this.width / 2)
@@ -206,6 +265,17 @@ var GroupNodeModel = /** @class */ (function (_super) {
206
265
  delete properties.isFolded;
207
266
  return data;
208
267
  };
268
+ GroupNodeModel.prototype.getHistoryData = function () {
269
+ var data = _super.prototype.getData.call(this);
270
+ data.children = __spread(this.children);
271
+ var properties = data.properties;
272
+ delete properties.groupAddable;
273
+ if (properties.isFolded) { // 如果分组被折叠
274
+ data.x = data.x + this.unfoldedWidth / 2 - this.foldedWidth / 2;
275
+ data.y = data.y + this.unfoldedHight / 2 - this.foldedHeight / 2;
276
+ }
277
+ return data;
278
+ };
209
279
  return GroupNodeModel;
210
280
  }(RectResize.model));
211
281
  var GroupNode = /** @class */ (function (_super) {
@@ -20,13 +20,19 @@ declare class Group {
20
20
  appendNodeToGrop: ({ data }: {
21
21
  data: any;
22
22
  }) => void;
23
+ deleteGroupChild: ({ data }: {
24
+ data: any;
25
+ }) => void;
23
26
  setActiveGroup: ({ data }: {
24
27
  data: any;
25
28
  }) => void;
26
- getGroups(): void;
27
29
  /**
28
30
  * 获取自定位置其所属分组
29
31
  */
30
32
  getGroup(bounds: Bounds): BaseNodeModel | undefined;
33
+ /**
34
+ * 获取某个节点所属的groupModel
35
+ */
36
+ getNodeGroup(nodeId: any): BaseNodeModel;
31
37
  }
32
38
  export { Group, GroupNode, };
@@ -49,11 +49,28 @@ var Group = /** @class */ (function () {
49
49
  // 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
50
50
  var bounds = _this.lf.getNodeModelById(data.id).getBounds();
51
51
  var group = _this.getGroup(bounds);
52
- if (group && data.id !== group.id) {
52
+ if (!group)
53
+ return;
54
+ if (data.id !== group.id) {
53
55
  group.addChild(data.id);
54
56
  _this.nodeGroupMap.set(data.id, group.id);
55
57
  group.setAllowAppendChild(false);
56
58
  }
59
+ else if (data.children && data.children.length > 0) {
60
+ // 表示当前添加的节点是一个新增的group
61
+ data.children.forEach(function (nodeId) {
62
+ _this.nodeGroupMap.set(nodeId, data.id);
63
+ });
64
+ }
65
+ };
66
+ this.deleteGroupChild = function (_a) {
67
+ var data = _a.data;
68
+ var groupId = _this.nodeGroupMap.get(data.id);
69
+ if (groupId) {
70
+ var group = _this.lf.getNodeModelById(groupId);
71
+ group.removeChild(data.id);
72
+ _this.nodeGroupMap.delete(data.id);
73
+ }
57
74
  };
58
75
  this.setActiveGroup = function (_a) {
59
76
  var data = _a.data;
@@ -92,20 +109,14 @@ var Group = /** @class */ (function () {
92
109
  }
93
110
  return true;
94
111
  });
112
+ lf.graphModel.group = this;
95
113
  lf.on('node:add', this.appendNodeToGrop);
114
+ lf.on('node:delete', this.deleteGroupChild);
96
115
  lf.on('node:drop', this.appendNodeToGrop);
97
116
  lf.on('node:dnd-drag', this.setActiveGroup);
98
117
  lf.on('node:drag', this.setActiveGroup);
99
118
  lf.on('graph:rendered', this.graphRendered);
100
119
  }
101
- Group.prototype.getGroups = function () {
102
- var groups = [];
103
- this.lf.graphModel.nodes.forEach(function (nodeModel) {
104
- if (nodeModel.isGroup) {
105
- groups.push(nodeModel);
106
- }
107
- });
108
- };
109
120
  /**
110
121
  * 获取自定位置其所属分组
111
122
  */
@@ -118,6 +129,15 @@ var Group = /** @class */ (function () {
118
129
  }
119
130
  }
120
131
  };
132
+ /**
133
+ * 获取某个节点所属的groupModel
134
+ */
135
+ Group.prototype.getNodeGroup = function (nodeId) {
136
+ var groupId = this.nodeGroupMap.get(nodeId);
137
+ if (groupId) {
138
+ return this.lf.getNodeModelById(groupId);
139
+ }
140
+ };
121
141
  Group.pluginName = 'group';
122
142
  return Group;
123
143
  }());