@logicflow/extension 1.2.0-alpha.5 → 1.2.0-alpha.6
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 +5 -0
- package/cjs/components/selection-select/index.js +22 -2
- package/cjs/index.js +1 -0
- package/cjs/materials/group/GroupNode.js +22 -12
- package/es/components/highlight/index.d.ts +21 -0
- package/es/components/highlight/index.js +184 -0
- package/es/components/mini-map/index.js +5 -0
- package/es/components/selection-select/index.d.ts +1 -0
- package/es/components/selection-select/index.js +22 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/materials/group/GroupNode.js +22 -12
- 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/EnLocale.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 +2 -2
- package/types/components/highlight/index.d.ts +21 -0
- package/types/components/selection-select/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;
|
|
@@ -103,6 +103,11 @@ var MiniMap = /** @class */ (function () {
|
|
|
103
103
|
_this.__setView();
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
+
this.__lf.on('blank:drop', function () {
|
|
107
|
+
if (_this.__isShow) {
|
|
108
|
+
_this.__setView();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
106
111
|
};
|
|
107
112
|
MiniMap.prototype.init = function (option) {
|
|
108
113
|
this.__disabledPlugins = this.__disabledPlugins.concat(option.disabledPlugins || []);
|
|
@@ -43,9 +43,11 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
43
43
|
}
|
|
44
44
|
var lt = [Math.min(x, x1), Math.min(y, y1)];
|
|
45
45
|
var rt = [Math.max(x, x1), Math.max(y, y1)];
|
|
46
|
-
var elements = _this.lf.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
|
|
46
|
+
var elements = _this.lf.graphModel.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
|
|
47
47
|
elements.forEach(function (element) {
|
|
48
|
-
_this.
|
|
48
|
+
if (_this.isSelectElement(element)) {
|
|
49
|
+
_this.lf.selectElementById(element.id, true);
|
|
50
|
+
}
|
|
49
51
|
});
|
|
50
52
|
_this.lf.emit('selection:selected', elements);
|
|
51
53
|
};
|
|
@@ -118,6 +120,24 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
118
120
|
}
|
|
119
121
|
this.close();
|
|
120
122
|
};
|
|
123
|
+
SelectionSelect.prototype.isSelectElement = function (elementModel) {
|
|
124
|
+
// 如果不可见,则不被选中
|
|
125
|
+
if (!elementModel.visible)
|
|
126
|
+
return false;
|
|
127
|
+
var group = this.lf.extension.group;
|
|
128
|
+
// 节点在group中,则不被选中
|
|
129
|
+
if (group) {
|
|
130
|
+
if (elementModel.BaseType === 'node' && group.getNodeGroup(elementModel.id))
|
|
131
|
+
return false;
|
|
132
|
+
if (elementModel.BaseType === 'edge') {
|
|
133
|
+
if (group.getNodeGroup(elementModel.sourceNodeId)
|
|
134
|
+
|| group.getNodeGroup(elementModel.targetNodeId)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
121
141
|
SelectionSelect.prototype.open = function () {
|
|
122
142
|
this.__disabled = false;
|
|
123
143
|
};
|
package/cjs/index.js
CHANGED
|
@@ -30,3 +30,4 @@ __exportStar(require("./tools/auto-layout"), exports);
|
|
|
30
30
|
__exportStar(require("./bpmn-adapter/xml2json"), exports);
|
|
31
31
|
__exportStar(require("./bpmn-adapter/json2xml"), exports);
|
|
32
32
|
__exportStar(require("./locale/en-locale"), exports);
|
|
33
|
+
__exportStar(require("./components/highlight"), exports);
|
|
@@ -107,24 +107,30 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
107
107
|
this.isFolded = isFolded;
|
|
108
108
|
// step 1
|
|
109
109
|
if (isFolded) {
|
|
110
|
-
this.x = this.x - this.width / 2 + this.foldedWidth / 2;
|
|
111
|
-
this.y = this.y - this.height / 2 + this.foldedHeight / 2;
|
|
112
110
|
this.unfoldedWidth = this.width;
|
|
113
111
|
this.unfoldedHight = this.height;
|
|
114
|
-
this.
|
|
115
|
-
|
|
112
|
+
this.updateAttributes({
|
|
113
|
+
x: this.x - this.width / 2 + this.foldedWidth / 2,
|
|
114
|
+
y: this.y - this.height / 2 + this.foldedHeight / 2,
|
|
115
|
+
width: this.foldedWidth,
|
|
116
|
+
height: this.foldedHeight,
|
|
117
|
+
});
|
|
116
118
|
}
|
|
117
119
|
else {
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
this.updateAttributes({
|
|
121
|
+
width: this.unfoldedWidth,
|
|
122
|
+
height: this.unfoldedHight,
|
|
123
|
+
x: this.x + this.unfoldedWidth / 2 - this.foldedWidth / 2,
|
|
124
|
+
y: this.y + this.unfoldedHight / 2 - this.foldedHeight / 2,
|
|
125
|
+
});
|
|
122
126
|
}
|
|
123
127
|
// step 2
|
|
124
128
|
var allEdges = this.incoming.edges.concat(this.outgoing.edges);
|
|
125
129
|
this.children.forEach(function (elementId) {
|
|
126
130
|
var nodeModel = _this.graphModel.getElement(elementId);
|
|
127
|
-
nodeModel.
|
|
131
|
+
nodeModel.updateAttributes({
|
|
132
|
+
visible: !isFolded,
|
|
133
|
+
});
|
|
128
134
|
allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
|
|
129
135
|
});
|
|
130
136
|
// step 3
|
|
@@ -196,7 +202,9 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
196
202
|
if (targetNodeIdGroup.id !== _this.id || sourceNodeIdGroup.id !== _this.id) {
|
|
197
203
|
_this.createVirtualEdge(data);
|
|
198
204
|
}
|
|
199
|
-
edgeModel.
|
|
205
|
+
edgeModel.updateAttributes({
|
|
206
|
+
visible: false,
|
|
207
|
+
});
|
|
200
208
|
}
|
|
201
209
|
// 展开时,处理被隐藏的边的逻辑
|
|
202
210
|
if (!isFolded && edgeModel.visible === false) {
|
|
@@ -212,7 +220,9 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
212
220
|
_this.createVirtualEdge(data);
|
|
213
221
|
}
|
|
214
222
|
else {
|
|
215
|
-
edgeModel.
|
|
223
|
+
edgeModel.updateAttributes({
|
|
224
|
+
visible: true,
|
|
225
|
+
});
|
|
216
226
|
}
|
|
217
227
|
}
|
|
218
228
|
});
|
|
@@ -222,7 +232,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
222
232
|
var model = this.graphModel.addEdge(edgeData);
|
|
223
233
|
model.virtual = true;
|
|
224
234
|
// 强制不保存group连线数据
|
|
225
|
-
model.getData =
|
|
235
|
+
// model.getData = () => null;
|
|
226
236
|
model.text.editable = false;
|
|
227
237
|
model.isFoldedEdge = true;
|
|
228
238
|
};
|
|
@@ -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 };
|
|
@@ -100,6 +100,11 @@ var MiniMap = /** @class */ (function () {
|
|
|
100
100
|
_this.__setView();
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
+
this.__lf.on('blank:drop', function () {
|
|
104
|
+
if (_this.__isShow) {
|
|
105
|
+
_this.__setView();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
103
108
|
};
|
|
104
109
|
MiniMap.prototype.init = function (option) {
|
|
105
110
|
this.__disabledPlugins = this.__disabledPlugins.concat(option.disabledPlugins || []);
|
|
@@ -40,9 +40,11 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
40
40
|
}
|
|
41
41
|
var lt = [Math.min(x, x1), Math.min(y, y1)];
|
|
42
42
|
var rt = [Math.max(x, x1), Math.max(y, y1)];
|
|
43
|
-
var elements = _this.lf.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
|
|
43
|
+
var elements = _this.lf.graphModel.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
|
|
44
44
|
elements.forEach(function (element) {
|
|
45
|
-
_this.
|
|
45
|
+
if (_this.isSelectElement(element)) {
|
|
46
|
+
_this.lf.selectElementById(element.id, true);
|
|
47
|
+
}
|
|
46
48
|
});
|
|
47
49
|
_this.lf.emit('selection:selected', elements);
|
|
48
50
|
};
|
|
@@ -115,6 +117,24 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
115
117
|
}
|
|
116
118
|
this.close();
|
|
117
119
|
};
|
|
120
|
+
SelectionSelect.prototype.isSelectElement = function (elementModel) {
|
|
121
|
+
// 如果不可见,则不被选中
|
|
122
|
+
if (!elementModel.visible)
|
|
123
|
+
return false;
|
|
124
|
+
var group = this.lf.extension.group;
|
|
125
|
+
// 节点在group中,则不被选中
|
|
126
|
+
if (group) {
|
|
127
|
+
if (elementModel.BaseType === 'node' && group.getNodeGroup(elementModel.id))
|
|
128
|
+
return false;
|
|
129
|
+
if (elementModel.BaseType === 'edge') {
|
|
130
|
+
if (group.getNodeGroup(elementModel.sourceNodeId)
|
|
131
|
+
|| group.getNodeGroup(elementModel.targetNodeId)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
};
|
|
118
138
|
SelectionSelect.prototype.open = function () {
|
|
119
139
|
this.__disabled = false;
|
|
120
140
|
};
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -105,24 +105,30 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
105
105
|
this.isFolded = isFolded;
|
|
106
106
|
// step 1
|
|
107
107
|
if (isFolded) {
|
|
108
|
-
this.x = this.x - this.width / 2 + this.foldedWidth / 2;
|
|
109
|
-
this.y = this.y - this.height / 2 + this.foldedHeight / 2;
|
|
110
108
|
this.unfoldedWidth = this.width;
|
|
111
109
|
this.unfoldedHight = this.height;
|
|
112
|
-
this.
|
|
113
|
-
|
|
110
|
+
this.updateAttributes({
|
|
111
|
+
x: this.x - this.width / 2 + this.foldedWidth / 2,
|
|
112
|
+
y: this.y - this.height / 2 + this.foldedHeight / 2,
|
|
113
|
+
width: this.foldedWidth,
|
|
114
|
+
height: this.foldedHeight,
|
|
115
|
+
});
|
|
114
116
|
}
|
|
115
117
|
else {
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
this.updateAttributes({
|
|
119
|
+
width: this.unfoldedWidth,
|
|
120
|
+
height: this.unfoldedHight,
|
|
121
|
+
x: this.x + this.unfoldedWidth / 2 - this.foldedWidth / 2,
|
|
122
|
+
y: this.y + this.unfoldedHight / 2 - this.foldedHeight / 2,
|
|
123
|
+
});
|
|
120
124
|
}
|
|
121
125
|
// step 2
|
|
122
126
|
var allEdges = this.incoming.edges.concat(this.outgoing.edges);
|
|
123
127
|
this.children.forEach(function (elementId) {
|
|
124
128
|
var nodeModel = _this.graphModel.getElement(elementId);
|
|
125
|
-
nodeModel.
|
|
129
|
+
nodeModel.updateAttributes({
|
|
130
|
+
visible: !isFolded,
|
|
131
|
+
});
|
|
126
132
|
allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
|
|
127
133
|
});
|
|
128
134
|
// step 3
|
|
@@ -194,7 +200,9 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
194
200
|
if (targetNodeIdGroup.id !== _this.id || sourceNodeIdGroup.id !== _this.id) {
|
|
195
201
|
_this.createVirtualEdge(data);
|
|
196
202
|
}
|
|
197
|
-
edgeModel.
|
|
203
|
+
edgeModel.updateAttributes({
|
|
204
|
+
visible: false,
|
|
205
|
+
});
|
|
198
206
|
}
|
|
199
207
|
// 展开时,处理被隐藏的边的逻辑
|
|
200
208
|
if (!isFolded && edgeModel.visible === false) {
|
|
@@ -210,7 +218,9 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
210
218
|
_this.createVirtualEdge(data);
|
|
211
219
|
}
|
|
212
220
|
else {
|
|
213
|
-
edgeModel.
|
|
221
|
+
edgeModel.updateAttributes({
|
|
222
|
+
visible: true,
|
|
223
|
+
});
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
});
|
|
@@ -220,7 +230,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
220
230
|
var model = this.graphModel.addEdge(edgeData);
|
|
221
231
|
model.virtual = true;
|
|
222
232
|
// 强制不保存group连线数据
|
|
223
|
-
model.getData =
|
|
233
|
+
// model.getData = () => null;
|
|
224
234
|
model.text.editable = false;
|
|
225
235
|
model.isFoldedEdge = true;
|
|
226
236
|
};
|