@logicflow/extension 1.1.19 → 1.1.22
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/components/highlight/index.js +187 -0
- package/cjs/components/mini-map/index.js +24 -4
- package/cjs/components/selection-select/index.js +4 -0
- package/cjs/index.js +1 -0
- package/cjs/tools/snapshot/index.js +1 -1
- package/es/components/highlight/index.d.ts +21 -0
- package/es/components/highlight/index.js +184 -0
- package/es/components/mini-map/index.d.ts +1 -0
- package/es/components/mini-map/index.js +24 -4
- package/es/components/selection-select/index.js +4 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/tools/snapshot/index.js +1 -1
- 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/Highlight.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/package.json +4 -4
- package/types/components/highlight/index.d.ts +21 -0
- package/types/components/mini-map/index.d.ts +1 -0
- package/types/index.d.ts +1 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spread = (this && this.__spread) || function () {
|
|
30
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.Highlight = void 0;
|
|
35
|
+
// 后续并入FlowPath
|
|
36
|
+
var getPath = function (id, lf) {
|
|
37
|
+
var el = lf.getModelById(id);
|
|
38
|
+
return getNodePath(el.BaseType === 'node' ? el : el.targetNode, lf);
|
|
39
|
+
};
|
|
40
|
+
// dfs + 动态规划
|
|
41
|
+
// todo 算法优化
|
|
42
|
+
var getNodePath = function (node, lf) {
|
|
43
|
+
var incomingPaths = [];
|
|
44
|
+
var outgoingPaths = [];
|
|
45
|
+
var getIncomingPaths = function (curNode, path, prevNode) {
|
|
46
|
+
if (prevNode === void 0) { prevNode = null; }
|
|
47
|
+
if (prevNode) {
|
|
48
|
+
// * 上个节点和当前节点中间边
|
|
49
|
+
path.unshift.apply(path, __spread(lf
|
|
50
|
+
.getEdgeModels({
|
|
51
|
+
sourceNodeId: curNode.id,
|
|
52
|
+
targetNodeId: prevNode.id,
|
|
53
|
+
})
|
|
54
|
+
.map(function (item) { return item.id; })));
|
|
55
|
+
}
|
|
56
|
+
// * 路径中存在节点,则不再继续查找,说明出现环情况
|
|
57
|
+
if (path.includes(curNode.id)) {
|
|
58
|
+
incomingPaths.push(path);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// * 路径中当前加入节点
|
|
62
|
+
path.unshift(curNode.id);
|
|
63
|
+
if (!curNode.incoming.nodes.length) {
|
|
64
|
+
incomingPaths.push(path);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// * 往下找
|
|
68
|
+
curNode.incoming.nodes.forEach(function (nextNode) {
|
|
69
|
+
getIncomingPaths(nextNode, path.slice(), curNode);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
// * 同上逻辑
|
|
73
|
+
var getOutgoingPaths = function (curNode, path, prevNode) {
|
|
74
|
+
if (prevNode === void 0) { prevNode = null; }
|
|
75
|
+
if (prevNode) {
|
|
76
|
+
path.push.apply(path, __spread(lf
|
|
77
|
+
.getEdgeModels({
|
|
78
|
+
sourceNodeId: prevNode.id,
|
|
79
|
+
targetNodeId: curNode.id,
|
|
80
|
+
})
|
|
81
|
+
.map(function (item) { return item.id; })));
|
|
82
|
+
}
|
|
83
|
+
if (path.includes(curNode.id)) {
|
|
84
|
+
outgoingPaths.push(path);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
path.push(curNode.id);
|
|
88
|
+
if (!curNode.outgoing.nodes.length) {
|
|
89
|
+
outgoingPaths.push(path);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
curNode.outgoing.nodes.forEach(function (nextNode) {
|
|
93
|
+
getOutgoingPaths(nextNode, path.slice(), curNode);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
getIncomingPaths(node, []);
|
|
97
|
+
getOutgoingPaths(node, []);
|
|
98
|
+
return __spread(new Set(__spread(incomingPaths.flat(), outgoingPaths.flat())));
|
|
99
|
+
};
|
|
100
|
+
var Highlight = /** @class */ (function () {
|
|
101
|
+
function Highlight(_a) {
|
|
102
|
+
var lf = _a.lf;
|
|
103
|
+
this.mode = 'path';
|
|
104
|
+
this.manual = false;
|
|
105
|
+
this.tempStyles = {};
|
|
106
|
+
this.lf = lf;
|
|
107
|
+
}
|
|
108
|
+
Highlight.prototype.setMode = function (mode) {
|
|
109
|
+
this.mode = mode;
|
|
110
|
+
};
|
|
111
|
+
Highlight.prototype.setManual = function (manual) {
|
|
112
|
+
this.manual = manual;
|
|
113
|
+
};
|
|
114
|
+
Highlight.prototype.highlightSingle = function (id) {
|
|
115
|
+
var model = this.lf.getModelById(id);
|
|
116
|
+
if (model.BaseType === 'node') {
|
|
117
|
+
// 高亮节点
|
|
118
|
+
model.updateStyles(this.tempStyles[id]);
|
|
119
|
+
}
|
|
120
|
+
else if (model.BaseType === 'edge') {
|
|
121
|
+
// 高亮边及对应的节点
|
|
122
|
+
model.updateStyles(this.tempStyles[id]);
|
|
123
|
+
model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id]);
|
|
124
|
+
model.targetNode.updateStyles(this.tempStyles[model.targetNode.id]);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
Highlight.prototype.highlightPath = function (id) {
|
|
128
|
+
var _this = this;
|
|
129
|
+
var path = getPath(id, this.lf);
|
|
130
|
+
path.forEach(function (_id) {
|
|
131
|
+
// 高亮路径上所有的边和节点
|
|
132
|
+
_this.lf.getModelById(_id).updateStyles(_this.tempStyles[_id]);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
Highlight.prototype.highlight = function (id, mode) {
|
|
136
|
+
var _this = this;
|
|
137
|
+
if (mode === void 0) { mode = this.mode; }
|
|
138
|
+
if (this.manual)
|
|
139
|
+
return;
|
|
140
|
+
if (Object.keys(this.tempStyles).length) {
|
|
141
|
+
this.restoreHighlight();
|
|
142
|
+
}
|
|
143
|
+
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
|
|
144
|
+
// 所有节点样式都进行备份
|
|
145
|
+
// eslint-disable-next-line operator-linebreak
|
|
146
|
+
var oStyle = item.BaseType === 'node' ? item.getNodeStyle() : item.getEdgeStyle();
|
|
147
|
+
_this.tempStyles[item.id] = __assign({}, oStyle);
|
|
148
|
+
// 所有节点都设置透明度为0.1
|
|
149
|
+
item.setStyles({ opacity: 0.1 });
|
|
150
|
+
});
|
|
151
|
+
var modeTrigger = {
|
|
152
|
+
single: this.highlightSingle.bind(this),
|
|
153
|
+
path: this.highlightPath.bind(this),
|
|
154
|
+
};
|
|
155
|
+
modeTrigger[mode](id);
|
|
156
|
+
};
|
|
157
|
+
Highlight.prototype.restoreHighlight = function () {
|
|
158
|
+
var _this = this;
|
|
159
|
+
// 恢复所有节点的样式
|
|
160
|
+
if (!Object.keys(this.tempStyles).length)
|
|
161
|
+
return;
|
|
162
|
+
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
|
|
163
|
+
var _a;
|
|
164
|
+
var oStyle = (_a = _this.tempStyles[item.id]) !== null && _a !== void 0 ? _a : {};
|
|
165
|
+
item.updateStyles(__assign({}, oStyle));
|
|
166
|
+
});
|
|
167
|
+
this.tempStyles = {};
|
|
168
|
+
};
|
|
169
|
+
Highlight.prototype.render = function (lf, domContainer) {
|
|
170
|
+
var _this = this;
|
|
171
|
+
this.lf.on('node:mouseenter', function (_a) {
|
|
172
|
+
var data = _a.data;
|
|
173
|
+
return _this.highlight(data.id);
|
|
174
|
+
});
|
|
175
|
+
this.lf.on('edge:mouseenter', function (_a) {
|
|
176
|
+
var data = _a.data;
|
|
177
|
+
return _this.highlight(data.id);
|
|
178
|
+
});
|
|
179
|
+
this.lf.on('node:mouseleave', this.restoreHighlight.bind(this));
|
|
180
|
+
this.lf.on('edge:mouseleave', this.restoreHighlight.bind(this));
|
|
181
|
+
this.lf.on('history:change', this.restoreHighlight.bind(this));
|
|
182
|
+
};
|
|
183
|
+
Highlight.prototype.destroy = function () { };
|
|
184
|
+
Highlight.pluginName = 'highlight';
|
|
185
|
+
return Highlight;
|
|
186
|
+
}());
|
|
187
|
+
exports.Highlight = Highlight;
|
|
@@ -64,12 +64,17 @@ var MiniMap = /** @class */ (function () {
|
|
|
64
64
|
y: e.y,
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
-
this.
|
|
67
|
+
this.moveViewport = function (top, left) {
|
|
68
68
|
var viewStyle = _this.__viewport.style;
|
|
69
|
-
_this.__viewPortTop
|
|
70
|
-
_this.__viewPortLeft
|
|
69
|
+
_this.__viewPortTop = top;
|
|
70
|
+
_this.__viewPortLeft = left;
|
|
71
71
|
viewStyle.top = _this.__viewPortTop + "px";
|
|
72
72
|
viewStyle.left = _this.__viewPortLeft + "px";
|
|
73
|
+
};
|
|
74
|
+
this.__drag = function (e) {
|
|
75
|
+
var top = _this.__viewPortTop + e.y - _this.__startPosition.y;
|
|
76
|
+
var left = _this.__viewPortLeft + e.x - _this.__startPosition.x;
|
|
77
|
+
_this.moveViewport(top, left);
|
|
73
78
|
_this.__startPosition = {
|
|
74
79
|
x: e.x,
|
|
75
80
|
y: e.y,
|
|
@@ -88,6 +93,21 @@ var MiniMap = /** @class */ (function () {
|
|
|
88
93
|
this.__drop = function () {
|
|
89
94
|
document.removeEventListener('mousemove', _this.__drag);
|
|
90
95
|
document.removeEventListener('mouseup', _this.__drop);
|
|
96
|
+
var top = _this.__viewPortTop;
|
|
97
|
+
var left = _this.__viewPortLeft;
|
|
98
|
+
if (_this.__viewPortLeft > _this.__width) {
|
|
99
|
+
left = _this.__width - _this.__viewPortWidth;
|
|
100
|
+
}
|
|
101
|
+
if (_this.__viewPortTop > _this.__height) {
|
|
102
|
+
top = _this.__height - _this.__viewPortHeight;
|
|
103
|
+
}
|
|
104
|
+
if (_this.__viewPortLeft < -_this.__width) {
|
|
105
|
+
left = 0;
|
|
106
|
+
}
|
|
107
|
+
if (_this.__viewPortTop < -_this.__height) {
|
|
108
|
+
top = 0;
|
|
109
|
+
}
|
|
110
|
+
_this.moveViewport(top, left);
|
|
91
111
|
};
|
|
92
112
|
this.__lf = lf;
|
|
93
113
|
this.__miniMapWidth = lf.graphModel.width;
|
|
@@ -311,7 +331,7 @@ var MiniMap = /** @class */ (function () {
|
|
|
311
331
|
var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
|
|
312
332
|
var realViewPortHeight = realViewPortWidth / graphRatio;
|
|
313
333
|
this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
|
|
314
|
-
this.__viewPortLeft = -TRANSLATE_X * scale;
|
|
334
|
+
this.__viewPortLeft = TRANSLATE_X > 0 ? 0 : -TRANSLATE_X * scale;
|
|
315
335
|
this.__viewPortWidth = realViewPortWidth;
|
|
316
336
|
this.__viewPortHeight = realViewPortHeight;
|
|
317
337
|
viewStyle.top = this.__viewPortTop + "px";
|
|
@@ -34,6 +34,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
34
34
|
this.__drawOff = function () {
|
|
35
35
|
document.removeEventListener('mousemove', _this.__draw);
|
|
36
36
|
document.removeEventListener('mouseup', _this.__drawOff);
|
|
37
|
+
_this.wrapper.oncontextmenu = null;
|
|
37
38
|
_this.__domContainer.removeChild(_this.wrapper);
|
|
38
39
|
var _a = _this.startPoint, x = _a.x, y = _a.y;
|
|
39
40
|
var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
|
|
@@ -75,6 +76,9 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
75
76
|
_this.endPoint = { x: x, y: y };
|
|
76
77
|
var wrapper = document.createElement('div');
|
|
77
78
|
wrapper.className = 'lf-selection-select';
|
|
79
|
+
wrapper.oncontextmenu = function prevent(ev) {
|
|
80
|
+
ev.preventDefault();
|
|
81
|
+
};
|
|
78
82
|
wrapper.style.top = _this.startPoint.y + "px";
|
|
79
83
|
wrapper.style.left = _this.startPoint.x + "px";
|
|
80
84
|
domContainer.appendChild(wrapper);
|
package/cjs/index.js
CHANGED
|
@@ -29,3 +29,4 @@ __exportStar(require("./tools/flow-path"), exports);
|
|
|
29
29
|
__exportStar(require("./tools/auto-layout"), exports);
|
|
30
30
|
__exportStar(require("./bpmn-adapter/xml2json"), exports);
|
|
31
31
|
__exportStar(require("./bpmn-adapter/json2xml"), exports);
|
|
32
|
+
__exportStar(require("./components/highlight"), exports);
|
|
@@ -164,7 +164,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
164
164
|
真实dom存在缩放影响其宽高数值
|
|
165
165
|
在得到真实宽高后除以缩放比例即可得到正常宽高
|
|
166
166
|
*/
|
|
167
|
-
var base =
|
|
167
|
+
var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
|
|
168
168
|
var bbox = base.getBoundingClientRect();
|
|
169
169
|
var graphModel = this.lf.graphModel;
|
|
170
170
|
var transformModel = graphModel.transformModel;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import LogicFlow from '@logicflow/core';
|
|
2
|
+
declare type IMode = 'single' | 'path';
|
|
3
|
+
declare class Highlight {
|
|
4
|
+
lf: LogicFlow;
|
|
5
|
+
static pluginName: string;
|
|
6
|
+
mode: IMode;
|
|
7
|
+
manual: boolean;
|
|
8
|
+
tempStyles: {};
|
|
9
|
+
constructor({ lf }: {
|
|
10
|
+
lf: any;
|
|
11
|
+
});
|
|
12
|
+
setMode(mode: IMode): void;
|
|
13
|
+
setManual(manual: boolean): void;
|
|
14
|
+
private highlightSingle;
|
|
15
|
+
private highlightPath;
|
|
16
|
+
highlight(id: string, mode?: IMode): void;
|
|
17
|
+
restoreHighlight(): void;
|
|
18
|
+
render(lf: any, domContainer: any): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
export { Highlight };
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
// 后续并入FlowPath
|
|
33
|
+
var getPath = function (id, lf) {
|
|
34
|
+
var el = lf.getModelById(id);
|
|
35
|
+
return getNodePath(el.BaseType === 'node' ? el : el.targetNode, lf);
|
|
36
|
+
};
|
|
37
|
+
// dfs + 动态规划
|
|
38
|
+
// todo 算法优化
|
|
39
|
+
var getNodePath = function (node, lf) {
|
|
40
|
+
var incomingPaths = [];
|
|
41
|
+
var outgoingPaths = [];
|
|
42
|
+
var getIncomingPaths = function (curNode, path, prevNode) {
|
|
43
|
+
if (prevNode === void 0) { prevNode = null; }
|
|
44
|
+
if (prevNode) {
|
|
45
|
+
// * 上个节点和当前节点中间边
|
|
46
|
+
path.unshift.apply(path, __spread(lf
|
|
47
|
+
.getEdgeModels({
|
|
48
|
+
sourceNodeId: curNode.id,
|
|
49
|
+
targetNodeId: prevNode.id,
|
|
50
|
+
})
|
|
51
|
+
.map(function (item) { return item.id; })));
|
|
52
|
+
}
|
|
53
|
+
// * 路径中存在节点,则不再继续查找,说明出现环情况
|
|
54
|
+
if (path.includes(curNode.id)) {
|
|
55
|
+
incomingPaths.push(path);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// * 路径中当前加入节点
|
|
59
|
+
path.unshift(curNode.id);
|
|
60
|
+
if (!curNode.incoming.nodes.length) {
|
|
61
|
+
incomingPaths.push(path);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// * 往下找
|
|
65
|
+
curNode.incoming.nodes.forEach(function (nextNode) {
|
|
66
|
+
getIncomingPaths(nextNode, path.slice(), curNode);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
// * 同上逻辑
|
|
70
|
+
var getOutgoingPaths = function (curNode, path, prevNode) {
|
|
71
|
+
if (prevNode === void 0) { prevNode = null; }
|
|
72
|
+
if (prevNode) {
|
|
73
|
+
path.push.apply(path, __spread(lf
|
|
74
|
+
.getEdgeModels({
|
|
75
|
+
sourceNodeId: prevNode.id,
|
|
76
|
+
targetNodeId: curNode.id,
|
|
77
|
+
})
|
|
78
|
+
.map(function (item) { return item.id; })));
|
|
79
|
+
}
|
|
80
|
+
if (path.includes(curNode.id)) {
|
|
81
|
+
outgoingPaths.push(path);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
path.push(curNode.id);
|
|
85
|
+
if (!curNode.outgoing.nodes.length) {
|
|
86
|
+
outgoingPaths.push(path);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
curNode.outgoing.nodes.forEach(function (nextNode) {
|
|
90
|
+
getOutgoingPaths(nextNode, path.slice(), curNode);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
getIncomingPaths(node, []);
|
|
94
|
+
getOutgoingPaths(node, []);
|
|
95
|
+
return __spread(new Set(__spread(incomingPaths.flat(), outgoingPaths.flat())));
|
|
96
|
+
};
|
|
97
|
+
var Highlight = /** @class */ (function () {
|
|
98
|
+
function Highlight(_a) {
|
|
99
|
+
var lf = _a.lf;
|
|
100
|
+
this.mode = 'path';
|
|
101
|
+
this.manual = false;
|
|
102
|
+
this.tempStyles = {};
|
|
103
|
+
this.lf = lf;
|
|
104
|
+
}
|
|
105
|
+
Highlight.prototype.setMode = function (mode) {
|
|
106
|
+
this.mode = mode;
|
|
107
|
+
};
|
|
108
|
+
Highlight.prototype.setManual = function (manual) {
|
|
109
|
+
this.manual = manual;
|
|
110
|
+
};
|
|
111
|
+
Highlight.prototype.highlightSingle = function (id) {
|
|
112
|
+
var model = this.lf.getModelById(id);
|
|
113
|
+
if (model.BaseType === 'node') {
|
|
114
|
+
// 高亮节点
|
|
115
|
+
model.updateStyles(this.tempStyles[id]);
|
|
116
|
+
}
|
|
117
|
+
else if (model.BaseType === 'edge') {
|
|
118
|
+
// 高亮边及对应的节点
|
|
119
|
+
model.updateStyles(this.tempStyles[id]);
|
|
120
|
+
model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id]);
|
|
121
|
+
model.targetNode.updateStyles(this.tempStyles[model.targetNode.id]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
Highlight.prototype.highlightPath = function (id) {
|
|
125
|
+
var _this = this;
|
|
126
|
+
var path = getPath(id, this.lf);
|
|
127
|
+
path.forEach(function (_id) {
|
|
128
|
+
// 高亮路径上所有的边和节点
|
|
129
|
+
_this.lf.getModelById(_id).updateStyles(_this.tempStyles[_id]);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
Highlight.prototype.highlight = function (id, mode) {
|
|
133
|
+
var _this = this;
|
|
134
|
+
if (mode === void 0) { mode = this.mode; }
|
|
135
|
+
if (this.manual)
|
|
136
|
+
return;
|
|
137
|
+
if (Object.keys(this.tempStyles).length) {
|
|
138
|
+
this.restoreHighlight();
|
|
139
|
+
}
|
|
140
|
+
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
|
|
141
|
+
// 所有节点样式都进行备份
|
|
142
|
+
// eslint-disable-next-line operator-linebreak
|
|
143
|
+
var oStyle = item.BaseType === 'node' ? item.getNodeStyle() : item.getEdgeStyle();
|
|
144
|
+
_this.tempStyles[item.id] = __assign({}, oStyle);
|
|
145
|
+
// 所有节点都设置透明度为0.1
|
|
146
|
+
item.setStyles({ opacity: 0.1 });
|
|
147
|
+
});
|
|
148
|
+
var modeTrigger = {
|
|
149
|
+
single: this.highlightSingle.bind(this),
|
|
150
|
+
path: this.highlightPath.bind(this),
|
|
151
|
+
};
|
|
152
|
+
modeTrigger[mode](id);
|
|
153
|
+
};
|
|
154
|
+
Highlight.prototype.restoreHighlight = function () {
|
|
155
|
+
var _this = this;
|
|
156
|
+
// 恢复所有节点的样式
|
|
157
|
+
if (!Object.keys(this.tempStyles).length)
|
|
158
|
+
return;
|
|
159
|
+
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
|
|
160
|
+
var _a;
|
|
161
|
+
var oStyle = (_a = _this.tempStyles[item.id]) !== null && _a !== void 0 ? _a : {};
|
|
162
|
+
item.updateStyles(__assign({}, oStyle));
|
|
163
|
+
});
|
|
164
|
+
this.tempStyles = {};
|
|
165
|
+
};
|
|
166
|
+
Highlight.prototype.render = function (lf, domContainer) {
|
|
167
|
+
var _this = this;
|
|
168
|
+
this.lf.on('node:mouseenter', function (_a) {
|
|
169
|
+
var data = _a.data;
|
|
170
|
+
return _this.highlight(data.id);
|
|
171
|
+
});
|
|
172
|
+
this.lf.on('edge:mouseenter', function (_a) {
|
|
173
|
+
var data = _a.data;
|
|
174
|
+
return _this.highlight(data.id);
|
|
175
|
+
});
|
|
176
|
+
this.lf.on('node:mouseleave', this.restoreHighlight.bind(this));
|
|
177
|
+
this.lf.on('edge:mouseleave', this.restoreHighlight.bind(this));
|
|
178
|
+
this.lf.on('history:change', this.restoreHighlight.bind(this));
|
|
179
|
+
};
|
|
180
|
+
Highlight.prototype.destroy = function () { };
|
|
181
|
+
Highlight.pluginName = 'highlight';
|
|
182
|
+
return Highlight;
|
|
183
|
+
}());
|
|
184
|
+
export { Highlight };
|
|
@@ -61,12 +61,17 @@ var MiniMap = /** @class */ (function () {
|
|
|
61
61
|
y: e.y,
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
this.
|
|
64
|
+
this.moveViewport = function (top, left) {
|
|
65
65
|
var viewStyle = _this.__viewport.style;
|
|
66
|
-
_this.__viewPortTop
|
|
67
|
-
_this.__viewPortLeft
|
|
66
|
+
_this.__viewPortTop = top;
|
|
67
|
+
_this.__viewPortLeft = left;
|
|
68
68
|
viewStyle.top = _this.__viewPortTop + "px";
|
|
69
69
|
viewStyle.left = _this.__viewPortLeft + "px";
|
|
70
|
+
};
|
|
71
|
+
this.__drag = function (e) {
|
|
72
|
+
var top = _this.__viewPortTop + e.y - _this.__startPosition.y;
|
|
73
|
+
var left = _this.__viewPortLeft + e.x - _this.__startPosition.x;
|
|
74
|
+
_this.moveViewport(top, left);
|
|
70
75
|
_this.__startPosition = {
|
|
71
76
|
x: e.x,
|
|
72
77
|
y: e.y,
|
|
@@ -85,6 +90,21 @@ var MiniMap = /** @class */ (function () {
|
|
|
85
90
|
this.__drop = function () {
|
|
86
91
|
document.removeEventListener('mousemove', _this.__drag);
|
|
87
92
|
document.removeEventListener('mouseup', _this.__drop);
|
|
93
|
+
var top = _this.__viewPortTop;
|
|
94
|
+
var left = _this.__viewPortLeft;
|
|
95
|
+
if (_this.__viewPortLeft > _this.__width) {
|
|
96
|
+
left = _this.__width - _this.__viewPortWidth;
|
|
97
|
+
}
|
|
98
|
+
if (_this.__viewPortTop > _this.__height) {
|
|
99
|
+
top = _this.__height - _this.__viewPortHeight;
|
|
100
|
+
}
|
|
101
|
+
if (_this.__viewPortLeft < -_this.__width) {
|
|
102
|
+
left = 0;
|
|
103
|
+
}
|
|
104
|
+
if (_this.__viewPortTop < -_this.__height) {
|
|
105
|
+
top = 0;
|
|
106
|
+
}
|
|
107
|
+
_this.moveViewport(top, left);
|
|
88
108
|
};
|
|
89
109
|
this.__lf = lf;
|
|
90
110
|
this.__miniMapWidth = lf.graphModel.width;
|
|
@@ -308,7 +328,7 @@ var MiniMap = /** @class */ (function () {
|
|
|
308
328
|
var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
|
|
309
329
|
var realViewPortHeight = realViewPortWidth / graphRatio;
|
|
310
330
|
this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
|
|
311
|
-
this.__viewPortLeft = -TRANSLATE_X * scale;
|
|
331
|
+
this.__viewPortLeft = TRANSLATE_X > 0 ? 0 : -TRANSLATE_X * scale;
|
|
312
332
|
this.__viewPortWidth = realViewPortWidth;
|
|
313
333
|
this.__viewPortHeight = realViewPortHeight;
|
|
314
334
|
viewStyle.top = this.__viewPortTop + "px";
|
|
@@ -31,6 +31,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
31
31
|
this.__drawOff = function () {
|
|
32
32
|
document.removeEventListener('mousemove', _this.__draw);
|
|
33
33
|
document.removeEventListener('mouseup', _this.__drawOff);
|
|
34
|
+
_this.wrapper.oncontextmenu = null;
|
|
34
35
|
_this.__domContainer.removeChild(_this.wrapper);
|
|
35
36
|
var _a = _this.startPoint, x = _a.x, y = _a.y;
|
|
36
37
|
var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
|
|
@@ -72,6 +73,9 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
72
73
|
_this.endPoint = { x: x, y: y };
|
|
73
74
|
var wrapper = document.createElement('div');
|
|
74
75
|
wrapper.className = 'lf-selection-select';
|
|
76
|
+
wrapper.oncontextmenu = function prevent(ev) {
|
|
77
|
+
ev.preventDefault();
|
|
78
|
+
};
|
|
75
79
|
wrapper.style.top = _this.startPoint.y + "px";
|
|
76
80
|
wrapper.style.left = _this.startPoint.x + "px";
|
|
77
81
|
domContainer.appendChild(wrapper);
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -161,7 +161,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
161
161
|
真实dom存在缩放影响其宽高数值
|
|
162
162
|
在得到真实宽高后除以缩放比例即可得到正常宽高
|
|
163
163
|
*/
|
|
164
|
-
var base =
|
|
164
|
+
var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
|
|
165
165
|
var bbox = base.getBoundingClientRect();
|
|
166
166
|
var graphModel = this.lf.graphModel;
|
|
167
167
|
var transformModel = graphModel.transformModel;
|