@logicflow/extension 1.1.0-alpha.0 → 1.1.0-alpha.4
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.
- package/cjs/NodeResize/Control/Control.js +2 -1
- package/cjs/NodeResize/Control/Util.js +1 -0
- package/cjs/NodeResize/Node/EllipseResize.js +1 -17
- package/cjs/NodeResize/Node/HtmlResize.js +72 -0
- package/cjs/NodeResize/index.js +6 -0
- package/cjs/components/context-menu/index.js +4 -1
- package/cjs/components/menu/index.js +3 -3
- package/cjs/group-shrink/index.js +213 -0
- package/cjs/index.js +1 -0
- package/cjs/materials/group/GroupNode.js +186 -23
- package/cjs/materials/group/index.js +28 -9
- package/cjs/style/index.css +3 -2
- package/cjs/tools/snapshot/index.js +7 -2
- package/es/NodeResize/Control/Control.js +2 -1
- package/es/NodeResize/Control/Util.d.ts +1 -0
- package/es/NodeResize/Control/Util.js +1 -0
- package/es/NodeResize/Node/EllipseResize.js +1 -17
- package/es/NodeResize/Node/HtmlResize.d.ts +20 -0
- package/es/NodeResize/Node/HtmlResize.js +70 -0
- package/es/NodeResize/index.js +6 -0
- package/es/components/context-menu/index.d.ts +1 -0
- package/es/components/context-menu/index.js +4 -1
- package/es/components/menu/index.js +3 -3
- package/es/group-shrink/index.d.ts +28 -0
- package/es/group-shrink/index.js +210 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/materials/group/GroupNode.d.ts +35 -11
- package/es/materials/group/GroupNode.js +187 -24
- package/es/materials/group/index.d.ts +3 -1
- package/es/materials/group/index.js +27 -9
- package/es/style/index.css +3 -2
- package/es/tools/snapshot/index.js +7 -2
- package/lib/AutoLayout.js +1 -1
- package/lib/BpmnAdapter.js +1 -1
- package/lib/BpmnElement.js +1 -1
- package/lib/ContextMenu.js +1 -1
- package/lib/Control.js +1 -1
- package/lib/CurvedEdge.js +1 -1
- package/lib/DndPanel.js +1 -1
- package/lib/FlowPath.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/GroupShrink.js +1 -0
- package/lib/InsertNodeInPolyline.js +1 -1
- package/lib/Menu.js +1 -1
- package/lib/MiniMap.js +1 -1
- package/lib/NodeResize.js +1 -1
- package/lib/RectLabelNode.js +1 -1
- package/lib/SelectionSelect.js +1 -1
- package/lib/Snapshot.js +1 -1
- package/lib/TurboAdapter.js +1 -1
- package/lib/lfJson2Xml.js +1 -1
- package/lib/lfXml2Json.js +1 -1
- package/lib/style/index.css +3 -2
- package/package.json +2 -2
- package/types/NodeResize/Control/Util.d.ts +1 -0
- package/types/NodeResize/Node/HtmlResize.d.ts +20 -0
- package/types/components/context-menu/index.d.ts +1 -0
- package/types/group-shrink/index.d.ts +28 -0
- package/types/index.d.ts +1 -0
- package/types/materials/group/GroupNode.d.ts +35 -11
- package/types/materials/group/index.d.ts +3 -1
- package/cjs/NodeResize/BasicShape/Ellipse.js +0 -21
- package/es/NodeResize/BasicShape/Ellipse.d.ts +0 -2
- package/es/NodeResize/BasicShape/Ellipse.js +0 -18
|
@@ -20,13 +20,26 @@ var __spread = (this && this.__spread) || function () {
|
|
|
20
20
|
return ar;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.Group = void 0;
|
|
23
|
+
exports.GroupNode = exports.Group = void 0;
|
|
24
24
|
var GroupNode_1 = require("./GroupNode");
|
|
25
|
+
exports.GroupNode = GroupNode_1.default;
|
|
25
26
|
var Group = /** @class */ (function () {
|
|
26
27
|
function Group(_a) {
|
|
27
28
|
var _this = this;
|
|
28
29
|
var lf = _a.lf;
|
|
29
30
|
this.nodeGroupMap = new Map();
|
|
31
|
+
this.graphRendered = function (data) {
|
|
32
|
+
// 如果节点
|
|
33
|
+
if (data && data.nodes) {
|
|
34
|
+
data.nodes.forEach(function (node) {
|
|
35
|
+
if (node.children) {
|
|
36
|
+
node.children.forEach(function (nodeId) {
|
|
37
|
+
_this.nodeGroupMap.set(nodeId, node.id);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
30
43
|
this.appendNodeToGrop = function (_a) {
|
|
31
44
|
var data = _a.data;
|
|
32
45
|
// 如果这个节点之前已经在group中了,则将其从之前的group中移除
|
|
@@ -48,14 +61,19 @@ var Group = /** @class */ (function () {
|
|
|
48
61
|
};
|
|
49
62
|
this.setActiveGroup = function (_a) {
|
|
50
63
|
var data = _a.data;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
var nodeModel = _this.lf.getNodeModelById(data.id);
|
|
65
|
+
if (nodeModel.isGroup)
|
|
66
|
+
return;
|
|
67
|
+
var bounds = nodeModel.getBounds();
|
|
68
|
+
var newGroup = _this.getGroup(bounds);
|
|
69
|
+
if (newGroup || newGroup !== _this.activeGroup) {
|
|
70
|
+
if (_this.activeGroup) {
|
|
71
|
+
_this.activeGroup.setAllowAppendChild(false);
|
|
72
|
+
}
|
|
73
|
+
if (newGroup) {
|
|
74
|
+
_this.activeGroup = newGroup;
|
|
75
|
+
_this.activeGroup.setAllowAppendChild(true);
|
|
76
|
+
}
|
|
59
77
|
}
|
|
60
78
|
};
|
|
61
79
|
lf.register(GroupNode_1.default);
|
|
@@ -82,6 +100,7 @@ var Group = /** @class */ (function () {
|
|
|
82
100
|
lf.on('node:drop', this.appendNodeToGrop);
|
|
83
101
|
lf.on('node:dnd-move', this.setActiveGroup);
|
|
84
102
|
lf.on('node:drag', this.setActiveGroup);
|
|
103
|
+
lf.on('graph:rendered', this.graphRendered);
|
|
85
104
|
}
|
|
86
105
|
Group.prototype.getGroups = function () {
|
|
87
106
|
var groups = [];
|
package/cjs/style/index.css
CHANGED
|
@@ -9,21 +9,25 @@ var Snapshot = {
|
|
|
9
9
|
install: function (lf) {
|
|
10
10
|
var _this = this;
|
|
11
11
|
this.lf = lf;
|
|
12
|
-
this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
13
|
-
this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
14
12
|
/* 下载快照 */
|
|
15
13
|
lf.getSnapshot = function (fileName, backgroundColor) {
|
|
14
|
+
_this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
15
|
+
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
16
16
|
_this.fileName = fileName || "logic-flow." + Date.now() + ".png";
|
|
17
17
|
var svgRootElement = _this.getSvgRootElement(lf);
|
|
18
18
|
_this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
|
|
19
19
|
};
|
|
20
20
|
/* 获取Blob对象,用户图片上传 */
|
|
21
21
|
lf.getSnapshotBlob = function (backgroundColor) {
|
|
22
|
+
_this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
23
|
+
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
22
24
|
var svgRootElement = _this.getSvgRootElement(lf);
|
|
23
25
|
return _this.getBlob(svgRootElement, backgroundColor);
|
|
24
26
|
};
|
|
25
27
|
/* 获取Base64对象,用户图片上传 */
|
|
26
28
|
lf.getSnapshotBase64 = function (backgroundColor) {
|
|
29
|
+
_this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
30
|
+
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
27
31
|
var svgRootElement = _this.getSvgRootElement(lf);
|
|
28
32
|
return _this.getBase64(svgRootElement, backgroundColor);
|
|
29
33
|
};
|
|
@@ -175,6 +179,7 @@ var Snapshot = {
|
|
|
175
179
|
canvas.width = bboxWidth * dpr + 80;
|
|
176
180
|
canvas.height = bboxHeight * dpr + 80;
|
|
177
181
|
var ctx = canvas.getContext('2d');
|
|
182
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
178
183
|
ctx.scale(dpr, dpr);
|
|
179
184
|
// 如果有背景色,设置流程图导出的背景色
|
|
180
185
|
if (backgroundColor) {
|
|
@@ -268,7 +268,8 @@ var Control = /** @class */ (function (_super) {
|
|
|
268
268
|
_this.onDraging = function (_a) {
|
|
269
269
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
270
270
|
var modelType = _this.nodeModel.modelType;
|
|
271
|
-
|
|
271
|
+
// html和矩形的计算方式是一样的,共用一个方法
|
|
272
|
+
if (modelType === ModelType.RECT_NODE || modelType === ModelType.HTML_NODE) {
|
|
272
273
|
_this.updateRect({ deltaX: deltaX, deltaY: deltaY });
|
|
273
274
|
}
|
|
274
275
|
else if (modelType === ModelType.ELLIPSE_NODE) {
|
|
@@ -4,6 +4,7 @@ export var ModelType;
|
|
|
4
4
|
ModelType["CIRCLE_NODE"] = "circle-node";
|
|
5
5
|
ModelType["POLYGON_NODE"] = "polygon-node";
|
|
6
6
|
ModelType["RECT_NODE"] = "rect-node";
|
|
7
|
+
ModelType["HTML_NODE"] = "html-node";
|
|
7
8
|
ModelType["TEXT_NODE"] = "text-node";
|
|
8
9
|
ModelType["ELLIPSE_NODE"] = "ellipse-node";
|
|
9
10
|
ModelType["DIAMOND_NODE"] = "diamond-node";
|
|
@@ -11,20 +11,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
11
11
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
12
|
};
|
|
13
13
|
})();
|
|
14
|
-
var __assign = (this && this.__assign) || function () {
|
|
15
|
-
__assign = Object.assign || function(t) {
|
|
16
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
-
s = arguments[i];
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
-
t[p] = s[p];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
return __assign.apply(this, arguments);
|
|
24
|
-
};
|
|
25
14
|
import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
|
|
26
15
|
import ControlGroup from '../Control/ControlGroup';
|
|
27
|
-
import Ellipse from '../BasicShape/Ellipse';
|
|
28
16
|
var EllipseResizeModel = /** @class */ (function (_super) {
|
|
29
17
|
__extends(EllipseResizeModel, _super);
|
|
30
18
|
function EllipseResizeModel(data, graphModel) {
|
|
@@ -66,11 +54,7 @@ var EllipseResizeView = /** @class */ (function (_super) {
|
|
|
66
54
|
};
|
|
67
55
|
// getResizeShape绘制图形,功能等同于基础椭圆的getShape功能,可以通过复写此方法,进行节点自定义
|
|
68
56
|
EllipseResizeView.prototype.getResizeShape = function () {
|
|
69
|
-
|
|
70
|
-
var rx = model.rx, ry = model.ry, x = model.x, y = model.y;
|
|
71
|
-
var style = model.getNodeStyle();
|
|
72
|
-
return (h("g", null,
|
|
73
|
-
h(Ellipse, __assign({}, style, { rx: rx, ry: ry, x: x, y: y }))));
|
|
57
|
+
return _super.prototype.getShape.call(this);
|
|
74
58
|
};
|
|
75
59
|
EllipseResizeView.prototype.getShape = function () {
|
|
76
60
|
var model = this.props.model;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
|
|
2
|
+
declare class HtmlResizeModel extends HtmlNodeModel {
|
|
3
|
+
minWidth: number;
|
|
4
|
+
minHeight: number;
|
|
5
|
+
maxWidth: number;
|
|
6
|
+
maxHeight: number;
|
|
7
|
+
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
|
|
8
|
+
setAttributes(): void;
|
|
9
|
+
}
|
|
10
|
+
declare class HtmlResizeView extends HtmlNode {
|
|
11
|
+
getControlGroup(): h.JSX.Element;
|
|
12
|
+
getResizeShape(): h.JSX.Element;
|
|
13
|
+
getShape(): h.JSX.Element;
|
|
14
|
+
}
|
|
15
|
+
declare const HtmlResize: {
|
|
16
|
+
type: string;
|
|
17
|
+
view: typeof HtmlResizeView;
|
|
18
|
+
model: typeof HtmlResizeModel;
|
|
19
|
+
};
|
|
20
|
+
export default HtmlResize;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
|
|
15
|
+
import ControlGroup from '../Control/ControlGroup';
|
|
16
|
+
var HtmlResizeModel = /** @class */ (function (_super) {
|
|
17
|
+
__extends(HtmlResizeModel, _super);
|
|
18
|
+
function HtmlResizeModel() {
|
|
19
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
20
|
+
_this.minWidth = 30;
|
|
21
|
+
_this.minHeight = 30;
|
|
22
|
+
_this.maxWidth = 2000;
|
|
23
|
+
_this.maxHeight = 2000;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
HtmlResizeModel.prototype.getOutlineStyle = function () {
|
|
27
|
+
var style = _super.prototype.getOutlineStyle.call(this);
|
|
28
|
+
style.stroke = 'none';
|
|
29
|
+
if (style.hover) {
|
|
30
|
+
style.hover.stroke = 'none';
|
|
31
|
+
}
|
|
32
|
+
return style;
|
|
33
|
+
};
|
|
34
|
+
HtmlResizeModel.prototype.setAttributes = function () {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
var nodeSize = this.properties.nodeSize;
|
|
37
|
+
if (nodeSize) {
|
|
38
|
+
this.width = nodeSize.width;
|
|
39
|
+
this.height = nodeSize.height;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return HtmlResizeModel;
|
|
43
|
+
}(HtmlNodeModel));
|
|
44
|
+
var HtmlResizeView = /** @class */ (function (_super) {
|
|
45
|
+
__extends(HtmlResizeView, _super);
|
|
46
|
+
function HtmlResizeView() {
|
|
47
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
48
|
+
}
|
|
49
|
+
HtmlResizeView.prototype.getControlGroup = function () {
|
|
50
|
+
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
|
|
51
|
+
return (h(ControlGroup, { model: model, graphModel: graphModel }));
|
|
52
|
+
};
|
|
53
|
+
// getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
|
|
54
|
+
HtmlResizeView.prototype.getResizeShape = function () {
|
|
55
|
+
return _super.prototype.getShape.call(this);
|
|
56
|
+
};
|
|
57
|
+
HtmlResizeView.prototype.getShape = function () {
|
|
58
|
+
var isSelected = this.props.model.isSelected;
|
|
59
|
+
return (h("g", null,
|
|
60
|
+
this.getResizeShape(),
|
|
61
|
+
isSelected ? this.getControlGroup() : ''));
|
|
62
|
+
};
|
|
63
|
+
return HtmlResizeView;
|
|
64
|
+
}(HtmlNode));
|
|
65
|
+
var HtmlResize = {
|
|
66
|
+
type: 'html',
|
|
67
|
+
view: HtmlResizeView,
|
|
68
|
+
model: HtmlResizeModel,
|
|
69
|
+
};
|
|
70
|
+
export default HtmlResize;
|
package/es/NodeResize/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import RectResize from './Node/RectResize';
|
|
2
2
|
import EllipseResize from './Node/EllipseResize';
|
|
3
3
|
import DiamondResize from './Node/DiamondResize';
|
|
4
|
+
import HtmlResize from './Node/HtmlResize';
|
|
4
5
|
var NodeResize = {
|
|
5
6
|
pluginName: 'nodeResize',
|
|
6
7
|
// 拖动step
|
|
@@ -56,6 +57,11 @@ var NodeResize = {
|
|
|
56
57
|
view: DiamondResize.view,
|
|
57
58
|
model: DiamondResize.model,
|
|
58
59
|
});
|
|
60
|
+
lf.register({
|
|
61
|
+
type: HtmlResize.type,
|
|
62
|
+
view: HtmlResize.view,
|
|
63
|
+
model: HtmlResize.model,
|
|
64
|
+
});
|
|
59
65
|
},
|
|
60
66
|
};
|
|
61
67
|
export default NodeResize;
|
|
@@ -30,7 +30,7 @@ var ContextMenu = /** @class */ (function () {
|
|
|
30
30
|
this.__menuDOM.className = 'lf-inner-context';
|
|
31
31
|
this.menuTypeMap.set(COMMON_TYPE_KEY, []);
|
|
32
32
|
this.lf.setContextMenuByType = function (type, menus) {
|
|
33
|
-
_this.
|
|
33
|
+
_this.setContextMenuByType(type, menus);
|
|
34
34
|
};
|
|
35
35
|
this.lf.setContextMenuItems = function (menus) {
|
|
36
36
|
_this.setContextMenuItems(menus);
|
|
@@ -60,6 +60,9 @@ var ContextMenu = /** @class */ (function () {
|
|
|
60
60
|
_this.hideContextMenu();
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
+
ContextMenu.prototype.setContextMenuByType = function (type, menus) {
|
|
64
|
+
this.menuTypeMap.set(type, menus);
|
|
65
|
+
};
|
|
63
66
|
/**
|
|
64
67
|
* 隐藏菜单
|
|
65
68
|
*/
|
|
@@ -30,13 +30,13 @@ var Menu = /** @class */ (function () {
|
|
|
30
30
|
this.lf = lf;
|
|
31
31
|
this.menuTypeMap = new Map();
|
|
32
32
|
this.init();
|
|
33
|
-
this.lf.
|
|
33
|
+
this.lf.setMenuConfig = function (config) {
|
|
34
34
|
_this.setMenuConfig(config);
|
|
35
35
|
};
|
|
36
|
-
this.lf.
|
|
36
|
+
this.lf.addMenuConfig = function (config) {
|
|
37
37
|
_this.addMenuConfig(config);
|
|
38
38
|
};
|
|
39
|
-
this.lf.
|
|
39
|
+
this.lf.setMenuByType = function (config) {
|
|
40
40
|
_this.setMenuByType(config);
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare class GroupShrink {
|
|
2
|
+
static pluginName: string;
|
|
3
|
+
group: any;
|
|
4
|
+
lf: any;
|
|
5
|
+
shrinkWidth: number;
|
|
6
|
+
shrinkHeight: number;
|
|
7
|
+
constructor({ lf }: {
|
|
8
|
+
lf: any;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* 收缩
|
|
12
|
+
*/
|
|
13
|
+
startShrink(group: any): void;
|
|
14
|
+
/**
|
|
15
|
+
* 展开
|
|
16
|
+
*/
|
|
17
|
+
startExpand(group: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* 获取分组内的节点上的所有边,以及计算新的分组节点需要连接的边,之后删除原来的边
|
|
20
|
+
*/
|
|
21
|
+
private getGroupEdges;
|
|
22
|
+
/**
|
|
23
|
+
* 获取分组内的节点和左上角节点,获取到有效信息后,删除节点
|
|
24
|
+
*/
|
|
25
|
+
private getGroupNodes;
|
|
26
|
+
private getGraphDataWithGroup;
|
|
27
|
+
}
|
|
28
|
+
export { GroupShrink, };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spread = (this && this.__spread) || function () {
|
|
29
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
import { remove } from 'lodash-es';
|
|
33
|
+
var GroupShrink = /** @class */ (function () {
|
|
34
|
+
function GroupShrink(_a) {
|
|
35
|
+
var _this = this;
|
|
36
|
+
var lf = _a.lf;
|
|
37
|
+
var _b;
|
|
38
|
+
this.group = null; // group节点
|
|
39
|
+
this.lf = null; // lf 实例
|
|
40
|
+
this.shrinkWidth = 100; // 收缩后节点宽度
|
|
41
|
+
this.shrinkHeight = 60; // 收缩后节点高度
|
|
42
|
+
this.getGraphDataWithGroup = function () {
|
|
43
|
+
var _a = _this.lf.graphModel.modelToGraphData(), nodes = _a.nodes, edges = _a.edges;
|
|
44
|
+
var groupNodes = [];
|
|
45
|
+
var groupEdges = [];
|
|
46
|
+
var shrinkedGroupIds = [];
|
|
47
|
+
nodes.forEach(function (node) {
|
|
48
|
+
if (node.type === 'group' && node.properties.shrinkProperty && node.properties.shrinkProperty) {
|
|
49
|
+
var _a = node.properties.shrinkProperty, shrinked = _a.shrinked, groupNode = _a.groupNode, innerNodes = _a.innerNodes, innerEdges = _a.innerEdges;
|
|
50
|
+
if (shrinked) {
|
|
51
|
+
// 是收缩状态下的分组节点,需要恢复原来的节点和边
|
|
52
|
+
node = groupNode;
|
|
53
|
+
groupNodes = __spread(groupNodes, innerNodes);
|
|
54
|
+
groupEdges = __spread(groupEdges, innerEdges);
|
|
55
|
+
shrinkedGroupIds.push(groupNode.id);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// 移除与收缩分组节点相连的边
|
|
60
|
+
if (shrinkedGroupIds.length) {
|
|
61
|
+
remove(edges, function (edge) {
|
|
62
|
+
var sourceNodeId = edge.sourceNodeId, targetNodeId = edge.targetNodeId;
|
|
63
|
+
return shrinkedGroupIds.indexOf(sourceNodeId) > -1
|
|
64
|
+
|| shrinkedGroupIds.indexOf(targetNodeId) > -1;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
nodes: __spread(nodes, groupNodes),
|
|
69
|
+
edges: __spread(edges, groupEdges),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
this.lf = lf;
|
|
73
|
+
this.lf.extension = __assign(__assign({}, ((_b = this.lf.extension) !== null && _b !== void 0 ? _b : {})), { groupShrink: this });
|
|
74
|
+
this.lf.getGraphData = this.getGraphDataWithGroup;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 收缩
|
|
78
|
+
*/
|
|
79
|
+
GroupShrink.prototype.startShrink = function (group) {
|
|
80
|
+
var _this = this;
|
|
81
|
+
if (group.type !== 'group') {
|
|
82
|
+
throw new Error('Only groupNode can be shrinked!');
|
|
83
|
+
}
|
|
84
|
+
this.group = group;
|
|
85
|
+
var nodeModel = this.lf.getNodeModelById(group.id);
|
|
86
|
+
var shrinkConfig = nodeModel.getProperties().shrinkProperty;
|
|
87
|
+
if (shrinkConfig && shrinkConfig.shrinked) {
|
|
88
|
+
throw new Error('GroupNode which is shrinked cannot be shrinked again!');
|
|
89
|
+
}
|
|
90
|
+
var shrinkProperty = {
|
|
91
|
+
shrinked: true,
|
|
92
|
+
groupNode: __assign({}, this.group),
|
|
93
|
+
innerNodes: [],
|
|
94
|
+
innerEdges: [],
|
|
95
|
+
};
|
|
96
|
+
var newEdges = []; // 需要重新生成的边
|
|
97
|
+
var innerNodes = []; // 分组内节点
|
|
98
|
+
var innerEdges = []; // 分组内部边
|
|
99
|
+
var minX = null;
|
|
100
|
+
var minY = null;
|
|
101
|
+
// 处理分组内的节点和边
|
|
102
|
+
if (this.group && this.group.children && this.group.children.length) {
|
|
103
|
+
var edgesInfo = this.getGroupEdges();
|
|
104
|
+
newEdges = edgesInfo.newEdges;
|
|
105
|
+
innerEdges = edgesInfo.innerEdges;
|
|
106
|
+
var nodesInfo = this.getGroupNodes();
|
|
107
|
+
innerNodes = nodesInfo.innerNodes; // 分组内节点信息
|
|
108
|
+
minX = nodesInfo.minX; // 左上角节点的x
|
|
109
|
+
minY = nodesInfo.minY; // 左上角节点的y
|
|
110
|
+
}
|
|
111
|
+
shrinkProperty.innerNodes = innerNodes;
|
|
112
|
+
shrinkProperty.innerEdges = innerEdges;
|
|
113
|
+
this.lf.setProperties(this.group.id, { shrinkProperty: shrinkProperty }); // 分组节点收缩前状态、分组内节点、分组内边存入properties
|
|
114
|
+
// 收缩后的分组节点移动到分组内左上角的节点位置
|
|
115
|
+
nodeModel.x = minX || this.group.x;
|
|
116
|
+
nodeModel.y = minY || this.group.y;
|
|
117
|
+
// 收缩,调整节点大小
|
|
118
|
+
nodeModel.width = this.shrinkWidth;
|
|
119
|
+
nodeModel.height = this.shrinkHeight;
|
|
120
|
+
// 生成与分组节点相连的边
|
|
121
|
+
newEdges.forEach(function (edgeConfig) {
|
|
122
|
+
_this.lf.addEdge(edgeConfig);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 展开
|
|
127
|
+
*/
|
|
128
|
+
GroupShrink.prototype.startExpand = function (group) {
|
|
129
|
+
var _this = this;
|
|
130
|
+
this.group = group;
|
|
131
|
+
var nodeModel = this.lf.getNodeModelById(group.id);
|
|
132
|
+
var _a = nodeModel.getProperties().shrinkProperty, shrinkProperty = _a === void 0 ? {} : _a;
|
|
133
|
+
var shrinked = shrinkProperty.shrinked, groupNode = shrinkProperty.groupNode, innerNodes = shrinkProperty.innerNodes, innerEdges = shrinkProperty.innerEdges;
|
|
134
|
+
if (!shrinked) {
|
|
135
|
+
throw new Error('GroupNode which is not shrinked cannot be expanded');
|
|
136
|
+
}
|
|
137
|
+
// 重新渲染分组节点
|
|
138
|
+
this.lf.deleteNode(group.id);
|
|
139
|
+
this.lf.addNode(groupNode);
|
|
140
|
+
// 恢复分组内的节点
|
|
141
|
+
innerNodes.forEach(function (item) {
|
|
142
|
+
_this.lf.addNode(item);
|
|
143
|
+
});
|
|
144
|
+
// 恢复分组内的节点上所有边
|
|
145
|
+
innerEdges.forEach(function (item) {
|
|
146
|
+
_this.lf.addEdge(item);
|
|
147
|
+
});
|
|
148
|
+
// 修改properties
|
|
149
|
+
this.lf.setProperties(group.id, { shrinkProperty: { shrinked: false } });
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* 获取分组内的节点上的所有边,以及计算新的分组节点需要连接的边,之后删除原来的边
|
|
153
|
+
*/
|
|
154
|
+
GroupShrink.prototype.getGroupEdges = function () {
|
|
155
|
+
var _this = this;
|
|
156
|
+
var edges = this.lf.graphModel.modelToGraphData().edges;
|
|
157
|
+
var children = this.group.children;
|
|
158
|
+
var innerEdges = [];
|
|
159
|
+
var newEdges = [];
|
|
160
|
+
edges.forEach(function (item) {
|
|
161
|
+
var startInGroup = children.indexOf(item.sourceNodeId) > -1;
|
|
162
|
+
var endInGroup = children.indexOf(item.targetNodeId) > -1;
|
|
163
|
+
if (startInGroup || endInGroup) {
|
|
164
|
+
innerEdges.push(item);
|
|
165
|
+
if (startInGroup && !endInGroup) {
|
|
166
|
+
// 从分组内向外的边
|
|
167
|
+
newEdges.push({
|
|
168
|
+
sourceNodeId: _this.group.id,
|
|
169
|
+
targetNodeId: item.targetNodeId,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (!startInGroup && endInGroup) {
|
|
173
|
+
// 从外部指向分组内的
|
|
174
|
+
newEdges.push({
|
|
175
|
+
sourceNodeId: item.sourceNodeId,
|
|
176
|
+
targetNodeId: _this.group.id,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
_this.lf.deleteEdge(item.id);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return { innerEdges: innerEdges, newEdges: newEdges };
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* 获取分组内的节点和左上角节点,获取到有效信息后,删除节点
|
|
186
|
+
*/
|
|
187
|
+
GroupShrink.prototype.getGroupNodes = function () {
|
|
188
|
+
var _this = this;
|
|
189
|
+
var innerNodes = [];
|
|
190
|
+
var nodes = this.lf.graphModel.modelToGraphData().nodes;
|
|
191
|
+
var children = this.group.children;
|
|
192
|
+
var minX = null;
|
|
193
|
+
var minY = null;
|
|
194
|
+
// 遍历所有节点,在分组内的, 暂存&删除
|
|
195
|
+
nodes.forEach(function (item) {
|
|
196
|
+
if (children.indexOf(item.id) > -1) {
|
|
197
|
+
innerNodes.push(item);
|
|
198
|
+
if ((!minX || item.x < minX) && (!minY || item.y < minY)) {
|
|
199
|
+
minX = item.x;
|
|
200
|
+
minY = item.y;
|
|
201
|
+
}
|
|
202
|
+
_this.lf.deleteNode(item.id);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return { innerNodes: innerNodes, minX: minX, minY: minY };
|
|
206
|
+
};
|
|
207
|
+
GroupShrink.pluginName = 'group-shrink';
|
|
208
|
+
return GroupShrink;
|
|
209
|
+
}());
|
|
210
|
+
export { GroupShrink, };
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { h } from '@logicflow/core';
|
|
2
|
+
import { RectResize } from '../../NodeResize';
|
|
3
|
+
declare class GroupNodeModel extends RectResize.model {
|
|
3
4
|
readonly isGroup = true;
|
|
4
|
-
children: Set<
|
|
5
|
+
children: Set<string>;
|
|
5
6
|
isRestrict: boolean;
|
|
6
|
-
|
|
7
|
+
resizable: boolean;
|
|
8
|
+
foldedWidth: number;
|
|
9
|
+
foldedHeight: number;
|
|
10
|
+
unfoldedWidth: number;
|
|
11
|
+
unfoldedHight: number;
|
|
12
|
+
initNodeData(data: any): void;
|
|
13
|
+
foldGroup(isFolded: any): void;
|
|
7
14
|
/**
|
|
8
|
-
*
|
|
15
|
+
* 折叠分组的时候,处理分组内部子节点上的连线
|
|
16
|
+
* 1. 为了保证校验规则不被打乱,所以只隐藏子节点上面的连线。
|
|
17
|
+
* 2. 重新创建一个属性一样的边。
|
|
18
|
+
* 3. 这个边拥有virtual=true的属性,表示不支持直接修改此边内容。
|
|
9
19
|
*/
|
|
10
|
-
|
|
20
|
+
private foldEdge;
|
|
11
21
|
isInRange({ x1, y1, x2, y2 }: {
|
|
12
22
|
x1: any;
|
|
13
23
|
y1: any;
|
|
@@ -15,15 +25,29 @@ declare class GroupNodeModel extends RectNodeModel {
|
|
|
15
25
|
y2: any;
|
|
16
26
|
}): boolean;
|
|
17
27
|
setAllowAppendChild(isAllow: any): void;
|
|
28
|
+
/**
|
|
29
|
+
* 添加分组子节点
|
|
30
|
+
* @param id 节点id
|
|
31
|
+
*/
|
|
18
32
|
addChild(id: any): void;
|
|
33
|
+
/**
|
|
34
|
+
* 删除分组子节点
|
|
35
|
+
* @param id 节点id
|
|
36
|
+
*/
|
|
19
37
|
removeChild(id: any): void;
|
|
38
|
+
getAddableOutlineStyle(): {
|
|
39
|
+
stroke: string;
|
|
40
|
+
strokeWidth: number;
|
|
41
|
+
strokeDasharray: string;
|
|
42
|
+
fill: string;
|
|
43
|
+
};
|
|
20
44
|
getData(): import("@logicflow/core").NodeData;
|
|
21
45
|
}
|
|
22
|
-
declare class GroupNode extends
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
declare class GroupNode extends RectResize.view {
|
|
47
|
+
getControlGroup(): h.JSX.Element;
|
|
48
|
+
getAddedableShape(): import("preact").VNode<any>;
|
|
49
|
+
getFoldIcon(): import("preact").VNode<any>;
|
|
50
|
+
getResizeShape(): import("preact").VNode<any>;
|
|
27
51
|
}
|
|
28
52
|
declare const _default: {
|
|
29
53
|
type: string;
|