@logicflow/extension 1.1.12 → 1.2.0-alpha.1
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 +8 -8
- package/cjs/NodeResize/Control/Util.js +11 -11
- package/cjs/bpmn-adapter/index.js +124 -76
- package/cjs/bpmn-adapter/json2xml.js +5 -2
- package/cjs/bpmn-adapter/xml2json.js +38 -284
- package/cjs/components/context-menu/index.js +2 -2
- package/cjs/components/menu/index.js +23 -23
- package/cjs/components/mini-map/index.js +2 -2
- package/cjs/components/selection-select/index.js +5 -5
- package/cjs/insert-node-in-polyline/edge.js +4 -4
- package/cjs/insert-node-in-polyline/index.js +1 -1
- package/cjs/materials/group/GroupNode.js +2 -2
- package/cjs/materials/group/index.js +3 -3
- package/cjs/tools/auto-layout/index.js +9 -9
- package/cjs/tools/snapshot/index.js +47 -46
- package/cjs/turbo-adapter/index.js +2 -2
- package/es/NodeResize/Control/Control.d.ts +1 -1
- package/es/NodeResize/Control/Control.js +9 -9
- package/es/NodeResize/Control/Util.d.ts +3 -3
- package/es/NodeResize/Control/Util.js +7 -7
- package/es/bpmn-adapter/index.d.ts +41 -33
- package/es/bpmn-adapter/index.js +124 -76
- package/es/bpmn-adapter/json2xml.js +5 -2
- package/es/bpmn-adapter/xml2json.js +38 -284
- package/es/components/context-menu/index.js +2 -2
- package/es/components/menu/index.js +23 -23
- package/es/components/mini-map/index.js +2 -2
- package/es/components/selection-select/index.d.ts +1 -1
- package/es/components/selection-select/index.js +5 -5
- package/es/insert-node-in-polyline/edge.d.ts +3 -3
- package/es/insert-node-in-polyline/edge.js +3 -3
- package/es/insert-node-in-polyline/index.js +2 -2
- package/es/materials/group/GroupNode.d.ts +1 -1
- package/es/materials/group/GroupNode.js +2 -2
- package/es/materials/group/index.d.ts +1 -1
- package/es/materials/group/index.js +3 -3
- package/es/tools/auto-layout/index.d.ts +2 -2
- package/es/tools/auto-layout/index.js +9 -9
- package/es/tools/snapshot/index.d.ts +15 -7
- package/es/tools/snapshot/index.js +47 -46
- package/es/turbo-adapter/index.js +2 -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/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/package.json +2 -2
- package/types/NodeResize/Control/Control.d.ts +1 -1
- package/types/NodeResize/Control/Util.d.ts +3 -3
- package/types/bpmn-adapter/index.d.ts +41 -33
- package/types/components/selection-select/index.d.ts +1 -1
- package/types/insert-node-in-polyline/edge.d.ts +3 -3
- package/types/materials/group/GroupNode.d.ts +1 -1
- package/types/materials/group/index.d.ts +1 -1
- package/types/tools/auto-layout/index.d.ts +2 -2
- package/types/tools/snapshot/index.d.ts +15 -7
|
@@ -174,8 +174,8 @@ var ContextMenu = /** @class */ (function () {
|
|
|
174
174
|
var leftTopY = y - node.y / 2 - 20;
|
|
175
175
|
var rightBottomX = node.x + nodeModel.width + NEXT_X_DISTANCE;
|
|
176
176
|
var rightBottomY = y + node.y / 2 + 20;
|
|
177
|
-
var
|
|
178
|
-
if (
|
|
177
|
+
var existElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
|
|
178
|
+
if (existElements.length) {
|
|
179
179
|
y = y + NEXT_Y_DISTANCE;
|
|
180
180
|
this.addNode(node, y);
|
|
181
181
|
return;
|
|
@@ -18,10 +18,10 @@ var __spread = (this && this.__spread) || function () {
|
|
|
18
18
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
19
19
|
return ar;
|
|
20
20
|
};
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
21
|
+
var DefaultNodeMenuKey = 'lf:defaultNodeMenu';
|
|
22
|
+
var DefaultEdgeMenuKey = 'lf:defaultEdgeMenu';
|
|
23
|
+
var DefaultGraphMenuKey = 'lf:defaultGraphMenu';
|
|
24
|
+
var DefaultSelectionMenuKey = 'lf:defaultSelectionMenu';
|
|
25
25
|
var Menu = /** @class */ (function () {
|
|
26
26
|
function Menu(_a) {
|
|
27
27
|
var _this = this;
|
|
@@ -45,7 +45,7 @@ var Menu = /** @class */ (function () {
|
|
|
45
45
|
*/
|
|
46
46
|
Menu.prototype.init = function () {
|
|
47
47
|
var _this = this;
|
|
48
|
-
var
|
|
48
|
+
var defaultNodeMenu = [
|
|
49
49
|
{
|
|
50
50
|
text: '删除',
|
|
51
51
|
callback: function (node) {
|
|
@@ -65,7 +65,7 @@ var Menu = /** @class */ (function () {
|
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
67
|
];
|
|
68
|
-
this.menuTypeMap.set(
|
|
68
|
+
this.menuTypeMap.set(DefaultNodeMenuKey, defaultNodeMenu);
|
|
69
69
|
var defaultEdgeMenu = [
|
|
70
70
|
{
|
|
71
71
|
text: '删除',
|
|
@@ -80,9 +80,9 @@ var Menu = /** @class */ (function () {
|
|
|
80
80
|
},
|
|
81
81
|
},
|
|
82
82
|
];
|
|
83
|
-
this.menuTypeMap.set(
|
|
84
|
-
this.menuTypeMap.set(
|
|
85
|
-
var
|
|
83
|
+
this.menuTypeMap.set(DefaultEdgeMenuKey, defaultEdgeMenu);
|
|
84
|
+
this.menuTypeMap.set(DefaultGraphMenuKey, []);
|
|
85
|
+
var DefaultSelectionMenu = [
|
|
86
86
|
{
|
|
87
87
|
text: '删除',
|
|
88
88
|
callback: function (elements) {
|
|
@@ -92,7 +92,7 @@ var Menu = /** @class */ (function () {
|
|
|
92
92
|
},
|
|
93
93
|
},
|
|
94
94
|
];
|
|
95
|
-
this.menuTypeMap.set(
|
|
95
|
+
this.menuTypeMap.set(DefaultSelectionMenuKey, DefaultSelectionMenu);
|
|
96
96
|
};
|
|
97
97
|
Menu.prototype.render = function (lf, container) {
|
|
98
98
|
var _this = this;
|
|
@@ -139,7 +139,7 @@ var Menu = /** @class */ (function () {
|
|
|
139
139
|
menuList = typeMenus;
|
|
140
140
|
}
|
|
141
141
|
else { // 最后取全局默认
|
|
142
|
-
menuList = _this.menuTypeMap.get(
|
|
142
|
+
menuList = _this.menuTypeMap.get(DefaultNodeMenuKey);
|
|
143
143
|
}
|
|
144
144
|
_this.__currentData = data;
|
|
145
145
|
_this.showMenu(x, y, menuList);
|
|
@@ -159,20 +159,20 @@ var Menu = /** @class */ (function () {
|
|
|
159
159
|
menuList = typeMenus;
|
|
160
160
|
}
|
|
161
161
|
else { // 最后取全局默认
|
|
162
|
-
menuList = _this.menuTypeMap.get(
|
|
162
|
+
menuList = _this.menuTypeMap.get(DefaultEdgeMenuKey);
|
|
163
163
|
}
|
|
164
164
|
_this.__currentData = data;
|
|
165
165
|
_this.showMenu(x, y, menuList);
|
|
166
166
|
});
|
|
167
167
|
this.lf.on('blank:contextmenu', function (_a) {
|
|
168
168
|
var position = _a.position;
|
|
169
|
-
var menuList = _this.menuTypeMap.get(
|
|
169
|
+
var menuList = _this.menuTypeMap.get(DefaultGraphMenuKey);
|
|
170
170
|
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
|
171
171
|
_this.showMenu(x, y, menuList);
|
|
172
172
|
});
|
|
173
173
|
this.lf.on('selection:contextmenu', function (_a) {
|
|
174
174
|
var data = _a.data, position = _a.position;
|
|
175
|
-
var menuList = _this.menuTypeMap.get(
|
|
175
|
+
var menuList = _this.menuTypeMap.get(DefaultSelectionMenuKey);
|
|
176
176
|
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
|
177
177
|
_this.__currentData = data;
|
|
178
178
|
_this.showMenu(x, y, menuList);
|
|
@@ -253,13 +253,13 @@ var Menu = /** @class */ (function () {
|
|
|
253
253
|
}
|
|
254
254
|
// node
|
|
255
255
|
config.nodeMenu !== undefined
|
|
256
|
-
&& this.menuTypeMap.set(
|
|
256
|
+
&& this.menuTypeMap.set(DefaultNodeMenuKey, config.nodeMenu ? config.nodeMenu : []);
|
|
257
257
|
// edge
|
|
258
258
|
config.edgeMenu !== undefined
|
|
259
|
-
&& this.menuTypeMap.set(
|
|
259
|
+
&& this.menuTypeMap.set(DefaultEdgeMenuKey, config.edgeMenu ? config.edgeMenu : []);
|
|
260
260
|
// graph
|
|
261
261
|
config.graphMenu !== undefined
|
|
262
|
-
&& this.menuTypeMap.set(
|
|
262
|
+
&& this.menuTypeMap.set(DefaultGraphMenuKey, config.graphMenu ? config.graphMenu : []);
|
|
263
263
|
};
|
|
264
264
|
// 在默认菜单后面追加菜单项
|
|
265
265
|
Menu.prototype.addMenuConfig = function (config) {
|
|
@@ -268,16 +268,16 @@ var Menu = /** @class */ (function () {
|
|
|
268
268
|
}
|
|
269
269
|
// 追加项时,只支持数组类型,对false不做操作
|
|
270
270
|
if (Array.isArray(config.nodeMenu)) {
|
|
271
|
-
var menuList = this.menuTypeMap.get(
|
|
272
|
-
this.menuTypeMap.set(
|
|
271
|
+
var menuList = this.menuTypeMap.get(DefaultNodeMenuKey);
|
|
272
|
+
this.menuTypeMap.set(DefaultNodeMenuKey, menuList.concat(config.nodeMenu));
|
|
273
273
|
}
|
|
274
274
|
if (Array.isArray(config.edgeMenu)) {
|
|
275
|
-
var menuList = this.menuTypeMap.get(
|
|
276
|
-
this.menuTypeMap.set(
|
|
275
|
+
var menuList = this.menuTypeMap.get(DefaultEdgeMenuKey);
|
|
276
|
+
this.menuTypeMap.set(DefaultEdgeMenuKey, menuList.concat(config.edgeMenu));
|
|
277
277
|
}
|
|
278
278
|
if (Array.isArray(config.graphMenu)) {
|
|
279
|
-
var menuList = this.menuTypeMap.get(
|
|
280
|
-
this.menuTypeMap.set(
|
|
279
|
+
var menuList = this.menuTypeMap.get(DefaultGraphMenuKey);
|
|
280
|
+
this.menuTypeMap.set(DefaultGraphMenuKey, menuList.concat(config.graphMenu));
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
/**
|
|
@@ -167,11 +167,11 @@ var MiniMap = /** @class */ (function () {
|
|
|
167
167
|
nodes.forEach(function (_a) {
|
|
168
168
|
var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
|
|
169
169
|
var nodeLeft = x - width / 2;
|
|
170
|
-
var
|
|
170
|
+
var nodeRight = x + width / 2;
|
|
171
171
|
var nodeTop = y - height / 2;
|
|
172
172
|
var nodeBottom = y + height / 2;
|
|
173
173
|
left = nodeLeft < left ? nodeLeft : left;
|
|
174
|
-
right =
|
|
174
|
+
right = nodeRight > right ? nodeRight : right;
|
|
175
175
|
top = nodeTop < top ? nodeTop : top;
|
|
176
176
|
bottom = nodeBottom > bottom ? nodeBottom : bottom;
|
|
177
177
|
});
|
|
@@ -3,7 +3,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
3
3
|
var _this = this;
|
|
4
4
|
var lf = _a.lf;
|
|
5
5
|
this.__disabled = false;
|
|
6
|
-
this.
|
|
6
|
+
this.isDefaultStopMoveGraph = false;
|
|
7
7
|
this.isWholeNode = true;
|
|
8
8
|
this.isWholeEdge = true;
|
|
9
9
|
this.__draw = function (ev) {
|
|
@@ -47,9 +47,9 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
47
47
|
_this.lf.emit('selection:selected', elements);
|
|
48
48
|
};
|
|
49
49
|
this.lf = lf;
|
|
50
|
-
// 初始化
|
|
50
|
+
// 初始化isDefaultStopMoveGraph取值
|
|
51
51
|
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
|
|
52
|
-
this.
|
|
52
|
+
this.isDefaultStopMoveGraph = stopMoveGraph;
|
|
53
53
|
lf.openSelectionSelect = function () {
|
|
54
54
|
_this.openSelectionSelect();
|
|
55
55
|
};
|
|
@@ -97,7 +97,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
97
97
|
SelectionSelect.prototype.openSelectionSelect = function () {
|
|
98
98
|
var stopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
|
|
99
99
|
if (!stopMoveGraph) {
|
|
100
|
-
this.
|
|
100
|
+
this.isDefaultStopMoveGraph = false;
|
|
101
101
|
this.lf.updateEditConfig({
|
|
102
102
|
stopMoveGraph: true,
|
|
103
103
|
});
|
|
@@ -108,7 +108,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
108
108
|
* 关闭选区
|
|
109
109
|
*/
|
|
110
110
|
SelectionSelect.prototype.closeSelectionSelect = function () {
|
|
111
|
-
if (!this.
|
|
111
|
+
if (!this.isDefaultStopMoveGraph) {
|
|
112
112
|
this.lf.updateEditConfig({
|
|
113
113
|
stopMoveGraph: false,
|
|
114
114
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Point, PolylineEdgeModel, BaseNodeModel } from '@logicflow/core';
|
|
2
2
|
export declare const isInSegment: (point: any, start: any, end: any) => boolean;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const crossPointInSegment: (node: BaseNodeModel, start: Point, end: Point) => {
|
|
4
4
|
startCrossPoint: {
|
|
5
5
|
x: number;
|
|
6
6
|
y: number;
|
|
@@ -10,12 +10,12 @@ export declare const corssPointInSegement: (node: BaseNodeModel, start: Point, e
|
|
|
10
10
|
y: number;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
interface
|
|
13
|
+
interface SegmentCross {
|
|
14
14
|
crossIndex: number;
|
|
15
15
|
crossPoints: {
|
|
16
16
|
startCrossPoint: Point;
|
|
17
17
|
endCrossPoint: Point;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const isNodeInSegment: (node: BaseNodeModel, polyline: PolylineEdgeModel) => SegmentCross;
|
|
21
21
|
export {};
|
|
@@ -42,7 +42,7 @@ var segmentDirection = function (start, end) {
|
|
|
42
42
|
return direction;
|
|
43
43
|
};
|
|
44
44
|
// 节点是够在线段内,求出节点与线段的交点
|
|
45
|
-
export var
|
|
45
|
+
export var crossPointInSegment = function (node, start, end) {
|
|
46
46
|
var bBox = getNodeBBox(node);
|
|
47
47
|
var direction = segmentDirection(start, end);
|
|
48
48
|
var maxX = Math.max(start.x, end.x);
|
|
@@ -83,12 +83,12 @@ export var corssPointInSegement = function (node, start, end) {
|
|
|
83
83
|
};
|
|
84
84
|
// 节点是否在线段内
|
|
85
85
|
// eslint-disable-next-line max-len
|
|
86
|
-
export var
|
|
86
|
+
export var isNodeInSegment = function (node, polyline) {
|
|
87
87
|
var x = node.x, y = node.y;
|
|
88
88
|
var pointsList = polyline.pointsList;
|
|
89
89
|
for (var i = 0; i < pointsList.length - 1; i++) {
|
|
90
90
|
if (isInSegment({ x: x, y: y }, pointsList[i], pointsList[i + 1])) {
|
|
91
|
-
var bBoxCross =
|
|
91
|
+
var bBoxCross = crossPointInSegment(node, pointsList[i], pointsList[i + 1]);
|
|
92
92
|
if (bBoxCross) {
|
|
93
93
|
return {
|
|
94
94
|
crossIndex: i + 1,
|
|
@@ -18,7 +18,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
18
18
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
19
19
|
return ar;
|
|
20
20
|
};
|
|
21
|
-
import {
|
|
21
|
+
import { isNodeInSegment } from './edge';
|
|
22
22
|
var InsertNodeInPolyline = /** @class */ (function () {
|
|
23
23
|
function InsertNodeInPolyline(_a) {
|
|
24
24
|
var lf = _a.lf;
|
|
@@ -59,7 +59,7 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
59
59
|
var nodeModel = this._lf.getNodeModelById(nodeData.id);
|
|
60
60
|
for (var i = 0; i < edges.length; i++) {
|
|
61
61
|
// eslint-disable-next-line max-len
|
|
62
|
-
var _a =
|
|
62
|
+
var _a = isNodeInSegment(nodeModel, edges[i]), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
|
|
63
63
|
if (crossIndex >= 0) {
|
|
64
64
|
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
|
|
65
65
|
this._lf.addEdge({
|
|
@@ -101,7 +101,7 @@ declare class GroupNodeModel extends RectResize.model {
|
|
|
101
101
|
}
|
|
102
102
|
declare class GroupNode extends RectResize.view {
|
|
103
103
|
getControlGroup(): h.JSX.Element;
|
|
104
|
-
|
|
104
|
+
getAddAbleShape(): import("preact").VNode<any>;
|
|
105
105
|
getFoldIcon(): import("preact").VNode<any>;
|
|
106
106
|
getResizeShape(): import("preact").VNode<any>;
|
|
107
107
|
}
|
|
@@ -293,7 +293,7 @@ var GroupNode = /** @class */ (function (_super) {
|
|
|
293
293
|
var _a = this.props.model, resizable = _a.resizable, properties = _a.properties;
|
|
294
294
|
return resizable && !properties.isFolded ? _super.prototype.getControlGroup.call(this) : null;
|
|
295
295
|
};
|
|
296
|
-
GroupNode.prototype.
|
|
296
|
+
GroupNode.prototype.getAddAbleShape = function () {
|
|
297
297
|
var _a = this.props.model, width = _a.width, height = _a.height, x = _a.x, y = _a.y, radius = _a.radius, properties = _a.properties;
|
|
298
298
|
if (!properties.groupAddable)
|
|
299
299
|
return null;
|
|
@@ -339,7 +339,7 @@ var GroupNode = /** @class */ (function (_super) {
|
|
|
339
339
|
};
|
|
340
340
|
GroupNode.prototype.getResizeShape = function () {
|
|
341
341
|
return h('g', {}, [
|
|
342
|
-
this.
|
|
342
|
+
this.getAddAbleShape(),
|
|
343
343
|
_super.prototype.getResizeShape.call(this),
|
|
344
344
|
this.getFoldIcon(),
|
|
345
345
|
]);
|
|
@@ -36,7 +36,7 @@ var Group = /** @class */ (function () {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
this.
|
|
39
|
+
this.appendNodeToGroup = function (_a) {
|
|
40
40
|
var data = _a.data;
|
|
41
41
|
// 如果这个节点之前已经在group中了,则将其从之前的group中移除
|
|
42
42
|
var preGroupId = _this.nodeGroupMap.get(data.id);
|
|
@@ -110,9 +110,9 @@ var Group = /** @class */ (function () {
|
|
|
110
110
|
return true;
|
|
111
111
|
});
|
|
112
112
|
lf.graphModel.group = this;
|
|
113
|
-
lf.on('node:add', this.
|
|
113
|
+
lf.on('node:add', this.appendNodeToGroup);
|
|
114
114
|
lf.on('node:delete', this.deleteGroupChild);
|
|
115
|
-
lf.on('node:drop', this.
|
|
115
|
+
lf.on('node:drop', this.appendNodeToGroup);
|
|
116
116
|
lf.on('node:dnd-drag', this.setActiveGroup);
|
|
117
117
|
lf.on('node:drag', this.setActiveGroup);
|
|
118
118
|
lf.on('graph:rendered', this.graphRendered);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 自动布局插件
|
|
3
|
-
* 依赖
|
|
3
|
+
* 依赖flow-path插件
|
|
4
4
|
* 未完善
|
|
5
5
|
*/
|
|
6
6
|
import LogicFlow from '@logicflow/core';
|
|
@@ -26,7 +26,7 @@ declare class AutoLayout {
|
|
|
26
26
|
* source一定在target左边。
|
|
27
27
|
* 1. 如果source和target在同一x, y坐标内容。
|
|
28
28
|
* 2. 如果source在target左上方。
|
|
29
|
-
* 3. 如果
|
|
29
|
+
* 3. 如果source在target左下方。
|
|
30
30
|
*/
|
|
31
31
|
private getRelativePosition;
|
|
32
32
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 自动布局插件
|
|
3
|
-
* 依赖
|
|
3
|
+
* 依赖flow-path插件
|
|
4
4
|
* 未完善
|
|
5
5
|
*/
|
|
6
6
|
var __assign = (this && this.__assign) || function () {
|
|
@@ -138,7 +138,7 @@ var AutoLayout = /** @class */ (function () {
|
|
|
138
138
|
var target = this.newNodeMap.get(targetNodeId);
|
|
139
139
|
var _a = this.getShape(sourceNodeId), width = _a.width, height = _a.height;
|
|
140
140
|
var _b = this.getShape(targetNodeId), targetWidth = _b.width, targetHeight = _b.height;
|
|
141
|
-
var
|
|
141
|
+
var positionType = this.getRelativePosition(source, target);
|
|
142
142
|
var startPoint = {
|
|
143
143
|
x: source.x,
|
|
144
144
|
y: source.y,
|
|
@@ -147,7 +147,7 @@ var AutoLayout = /** @class */ (function () {
|
|
|
147
147
|
x: target.x,
|
|
148
148
|
y: target.y,
|
|
149
149
|
};
|
|
150
|
-
switch (
|
|
150
|
+
switch (positionType) {
|
|
151
151
|
case POSITION_TYPE.LEFT:
|
|
152
152
|
startPoint.x = source.x + width / 2;
|
|
153
153
|
endPoint.x = target.x - targetWidth / 2;
|
|
@@ -173,22 +173,22 @@ var AutoLayout = /** @class */ (function () {
|
|
|
173
173
|
* source一定在target左边。
|
|
174
174
|
* 1. 如果source和target在同一x, y坐标内容。
|
|
175
175
|
* 2. 如果source在target左上方。
|
|
176
|
-
* 3. 如果
|
|
176
|
+
* 3. 如果source在target左下方。
|
|
177
177
|
*/
|
|
178
178
|
AutoLayout.prototype.getRelativePosition = function (source, target) {
|
|
179
179
|
var y = source.y;
|
|
180
180
|
var y1 = target.y;
|
|
181
|
-
var
|
|
181
|
+
var positionType;
|
|
182
182
|
if (y < y1) {
|
|
183
|
-
|
|
183
|
+
positionType = -1;
|
|
184
184
|
}
|
|
185
185
|
else if (y === y1) {
|
|
186
|
-
|
|
186
|
+
positionType = 0;
|
|
187
187
|
}
|
|
188
188
|
else {
|
|
189
|
-
|
|
189
|
+
positionType = 1;
|
|
190
190
|
}
|
|
191
|
-
return
|
|
191
|
+
return positionType;
|
|
192
192
|
};
|
|
193
193
|
/**
|
|
194
194
|
* 获取边节点图形的宽高。
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 快照插件,生成视图
|
|
3
3
|
*/
|
|
4
|
-
declare
|
|
5
|
-
pluginName: string;
|
|
6
|
-
|
|
4
|
+
declare class Snapshot {
|
|
5
|
+
static pluginName: string;
|
|
6
|
+
lf: any;
|
|
7
|
+
offsetX: number;
|
|
8
|
+
offsetY: number;
|
|
9
|
+
fileName: string;
|
|
10
|
+
customCssRules: string;
|
|
11
|
+
useGlobalRules: boolean;
|
|
12
|
+
constructor({ lf }: {
|
|
13
|
+
lf: any;
|
|
14
|
+
});
|
|
7
15
|
getSvgRootElement(lf: any): any;
|
|
8
16
|
triggerDownload(imgURI: string): void;
|
|
9
17
|
removeAnchor(element: any): void;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
getSnapshot(fileName: string, backgroundColor: string): void;
|
|
19
|
+
getSnapshotBase64(backgroundColor: string): Promise<unknown>;
|
|
20
|
+
getSnapshotBlob(backgroundColor: string): Promise<unknown>;
|
|
13
21
|
getClassRules(): string;
|
|
14
22
|
getCanvasData(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
|
|
15
|
-
}
|
|
23
|
+
}
|
|
16
24
|
export default Snapshot;
|
|
17
25
|
export { Snapshot, };
|
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 快照插件,生成视图
|
|
3
3
|
*/
|
|
4
|
-
var Snapshot = {
|
|
5
|
-
|
|
6
|
-
install: function (lf) {
|
|
4
|
+
var Snapshot = /** @class */ (function () {
|
|
5
|
+
function Snapshot(_a) {
|
|
7
6
|
var _this = this;
|
|
7
|
+
var lf = _a.lf;
|
|
8
8
|
this.lf = lf;
|
|
9
|
+
this.customCssRules = '';
|
|
10
|
+
this.useGlobalRules = true;
|
|
9
11
|
/* 下载快照 */
|
|
10
12
|
lf.getSnapshot = function (fileName, backgroundColor) {
|
|
11
|
-
_this.
|
|
12
|
-
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
13
|
-
_this.fileName = fileName || "logic-flow." + Date.now() + ".png";
|
|
14
|
-
var svgRootElement = _this.getSvgRootElement(lf);
|
|
15
|
-
_this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
|
|
13
|
+
_this.getSnapshot(fileName, backgroundColor);
|
|
16
14
|
};
|
|
17
15
|
/* 获取Blob对象,用户图片上传 */
|
|
18
|
-
lf.getSnapshotBlob = function (backgroundColor) {
|
|
19
|
-
_this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
20
|
-
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
21
|
-
var svgRootElement = _this.getSvgRootElement(lf);
|
|
22
|
-
return _this.getBlob(svgRootElement, backgroundColor);
|
|
23
|
-
};
|
|
16
|
+
lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(backgroundColor); };
|
|
24
17
|
/* 获取Base64对象,用户图片上传 */
|
|
25
|
-
lf.getSnapshotBase64 = function (backgroundColor) {
|
|
26
|
-
|
|
27
|
-
_this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
28
|
-
var svgRootElement = _this.getSvgRootElement(lf);
|
|
29
|
-
return _this.getBase64(svgRootElement, backgroundColor);
|
|
30
|
-
};
|
|
31
|
-
},
|
|
18
|
+
lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
|
|
19
|
+
}
|
|
32
20
|
/* 获取svgRoot对象 */
|
|
33
|
-
getSvgRootElement
|
|
21
|
+
Snapshot.prototype.getSvgRootElement = function (lf) {
|
|
34
22
|
var _this = this;
|
|
23
|
+
this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
24
|
+
this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
35
25
|
lf.graphModel.nodes.forEach(function (item) {
|
|
36
26
|
var x = item.x, width = item.width, y = item.y, height = item.height;
|
|
37
27
|
var offsetX = x - width / 2;
|
|
@@ -58,8 +48,8 @@ var Snapshot = {
|
|
|
58
48
|
});
|
|
59
49
|
var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
|
|
60
50
|
return svgRootElement;
|
|
61
|
-
}
|
|
62
|
-
triggerDownload
|
|
51
|
+
};
|
|
52
|
+
Snapshot.prototype.triggerDownload = function (imgURI) {
|
|
63
53
|
var evt = new MouseEvent('click', {
|
|
64
54
|
view: window,
|
|
65
55
|
bubbles: false,
|
|
@@ -70,8 +60,8 @@ var Snapshot = {
|
|
|
70
60
|
a.setAttribute('href', imgURI);
|
|
71
61
|
a.setAttribute('target', '_blank');
|
|
72
62
|
a.dispatchEvent(evt);
|
|
73
|
-
}
|
|
74
|
-
removeAnchor
|
|
63
|
+
};
|
|
64
|
+
Snapshot.prototype.removeAnchor = function (element) {
|
|
75
65
|
var childNodes = element.childNodes;
|
|
76
66
|
var childLength = element.childNodes && element.childNodes.length;
|
|
77
67
|
for (var i = 0; i < childLength; i++) {
|
|
@@ -83,20 +73,22 @@ var Snapshot = {
|
|
|
83
73
|
i--;
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
|
-
}
|
|
76
|
+
};
|
|
87
77
|
/* 下载图片 */
|
|
88
|
-
|
|
78
|
+
Snapshot.prototype.getSnapshot = function (fileName, backgroundColor) {
|
|
89
79
|
var _this = this;
|
|
80
|
+
this.fileName = fileName || "logic-flow." + Date.now() + ".png";
|
|
81
|
+
var svg = this.getSvgRootElement(this.lf);
|
|
90
82
|
this.getCanvasData(svg, backgroundColor).then(function (canvas) {
|
|
91
|
-
var imgURI = canvas
|
|
92
|
-
.toDataURL('image/png')
|
|
83
|
+
var imgURI = canvas.toDataURL('image/png')
|
|
93
84
|
.replace('image/png', 'image/octet-stream');
|
|
94
|
-
_this.triggerDownload(imgURI
|
|
85
|
+
_this.triggerDownload(imgURI);
|
|
95
86
|
});
|
|
96
|
-
}
|
|
87
|
+
};
|
|
97
88
|
/* 获取base64对象 */
|
|
98
|
-
|
|
89
|
+
Snapshot.prototype.getSnapshotBase64 = function (backgroundColor) {
|
|
99
90
|
var _this = this;
|
|
91
|
+
var svg = this.getSvgRootElement(this.lf);
|
|
100
92
|
return new Promise(function (resolve) {
|
|
101
93
|
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
|
|
102
94
|
var base64 = canvas.toDataURL('image/png');
|
|
@@ -104,10 +96,11 @@ var Snapshot = {
|
|
|
104
96
|
resolve({ data: base64, width: canvas.width, height: canvas.height });
|
|
105
97
|
});
|
|
106
98
|
});
|
|
107
|
-
}
|
|
99
|
+
};
|
|
108
100
|
/* 获取Blob对象 */
|
|
109
|
-
|
|
101
|
+
Snapshot.prototype.getSnapshotBlob = function (backgroundColor) {
|
|
110
102
|
var _this = this;
|
|
103
|
+
var svg = this.getSvgRootElement(this.lf);
|
|
111
104
|
return new Promise(function (resolve) {
|
|
112
105
|
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
|
|
113
106
|
canvas.toBlob(function (blob) {
|
|
@@ -116,20 +109,25 @@ var Snapshot = {
|
|
|
116
109
|
}, 'image/png');
|
|
117
110
|
});
|
|
118
111
|
});
|
|
119
|
-
}
|
|
120
|
-
getClassRules
|
|
112
|
+
};
|
|
113
|
+
Snapshot.prototype.getClassRules = function () {
|
|
121
114
|
var rules = '';
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
if (this.useGlobalRules) {
|
|
116
|
+
var styleSheets = document.styleSheets;
|
|
117
|
+
for (var i = 0; i < styleSheets.length; i++) {
|
|
118
|
+
var sheet = styleSheets[i];
|
|
119
|
+
for (var j = 0; j < sheet.cssRules.length; j++) {
|
|
120
|
+
rules += sheet.cssRules[j].cssText;
|
|
121
|
+
}
|
|
127
122
|
}
|
|
128
123
|
}
|
|
124
|
+
if (this.customCssRules) {
|
|
125
|
+
rules += this.customCssRules;
|
|
126
|
+
}
|
|
129
127
|
return rules;
|
|
130
|
-
}
|
|
128
|
+
};
|
|
131
129
|
// 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
|
|
132
|
-
getCanvasData
|
|
130
|
+
Snapshot.prototype.getCanvasData = function (svg, backgroundColor) {
|
|
133
131
|
var _this = this;
|
|
134
132
|
var copy = svg.cloneNode(true);
|
|
135
133
|
var graph = copy.lastChild;
|
|
@@ -201,12 +199,15 @@ var Snapshot = {
|
|
|
201
199
|
因为svg中存在dom存放在foreignObject元素中
|
|
202
200
|
SVG图形转成img对象
|
|
203
201
|
todo: 会导致一些清晰度问题这个需要再解决
|
|
202
|
+
fixme: XMLSerializer的中的css background url不会下载图片
|
|
204
203
|
*/
|
|
205
204
|
var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
|
|
206
205
|
var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
|
|
207
206
|
img.src = imgSrc;
|
|
208
207
|
});
|
|
209
|
-
}
|
|
210
|
-
|
|
208
|
+
};
|
|
209
|
+
Snapshot.pluginName = 'snapshot';
|
|
210
|
+
return Snapshot;
|
|
211
|
+
}());
|
|
211
212
|
export default Snapshot;
|
|
212
213
|
export { Snapshot, };
|
|
@@ -51,7 +51,7 @@ function convertNodeToTurboElement(node) {
|
|
|
51
51
|
key: id,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
// 将LogicFlow中的
|
|
54
|
+
// 将LogicFlow中的Edge数据转换为Turbo元素数据
|
|
55
55
|
function convertEdgeToTurboElement(edge) {
|
|
56
56
|
var id = edge.id, type = edge.type, sourceNodeId = edge.sourceNodeId, targetNodeId = edge.targetNodeId, startPoint = edge.startPoint, endPoint = edge.endPoint, pointsList = edge.pointsList, _a = edge.text, text = _a === void 0 ? '' : _a, properties = edge.properties;
|
|
57
57
|
return {
|
|
@@ -87,7 +87,7 @@ export function toTurboData(data) {
|
|
|
87
87
|
});
|
|
88
88
|
return turboData;
|
|
89
89
|
}
|
|
90
|
-
// 将Turbo元素数据转换为LogicFlow中的
|
|
90
|
+
// 将Turbo元素数据转换为LogicFlow中的Edge数据
|
|
91
91
|
function convertFlowElementToEdge(element) {
|
|
92
92
|
var incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key;
|
|
93
93
|
var text = properties.text, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList, logicFlowType = properties.logicFlowType;
|