@logicflow/extension 2.0.16 → 2.0.18
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +14 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/components/highlight/index.js +19 -3
- package/es/components/selection-select/index.d.ts +25 -3
- package/es/components/selection-select/index.js +215 -77
- package/es/dynamic-group/index.js +0 -11
- package/es/materials/group/GroupNode.js +0 -1
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/tools/proximity-connect/index.js +25 -4
- package/es/tools/snapshot/index.d.ts +47 -20
- package/es/tools/snapshot/index.js +459 -246
- package/lib/components/highlight/index.js +18 -2
- package/lib/components/selection-select/index.d.ts +25 -3
- package/lib/components/selection-select/index.js +215 -77
- package/lib/dynamic-group/index.js +0 -11
- package/lib/materials/group/GroupNode.js +0 -1
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/tools/proximity-connect/index.js +24 -3
- package/lib/tools/snapshot/index.d.ts +47 -20
- package/lib/tools/snapshot/index.js +459 -246
- package/package.json +3 -3
- package/src/components/highlight/index.ts +30 -5
- package/src/components/selection-select/index.ts +198 -64
- package/src/dynamic-group/index.ts +0 -12
- package/src/materials/group/GroupNode.ts +0 -1
- package/src/style/raw.ts +4 -0
- package/src/tools/proximity-connect/index.ts +30 -3
- package/src/tools/snapshot/index.ts +325 -152
- package/stats.html +1 -1
|
@@ -134,10 +134,14 @@ var Highlight = /** @class */ (function () {
|
|
|
134
134
|
model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id]);
|
|
135
135
|
model.targetNode.updateStyles(this.tempStyles[model.targetNode.id]);
|
|
136
136
|
}
|
|
137
|
+
this.lf.emit('highlight:single', {
|
|
138
|
+
data: model,
|
|
139
|
+
});
|
|
137
140
|
};
|
|
138
141
|
Highlight.prototype.highlightNeighbours = function (id) {
|
|
139
142
|
var _this = this;
|
|
140
143
|
var model = this.lf.getModelById(id);
|
|
144
|
+
var relateElements = [];
|
|
141
145
|
if ((model === null || model === void 0 ? void 0 : model.BaseType) === 'node') {
|
|
142
146
|
// 高亮节点
|
|
143
147
|
model.updateStyles(this.tempStyles[id]);
|
|
@@ -149,21 +153,33 @@ var Highlight = /** @class */ (function () {
|
|
|
149
153
|
(0, lodash_es_1.concat)(incomingEdges, outgoingEdges).forEach(function (edge) {
|
|
150
154
|
edge.updateStyles(_this.tempStyles[edge.id]);
|
|
151
155
|
});
|
|
156
|
+
relateElements = (0, lodash_es_1.uniqBy)((0, lodash_es_1.concat)(relateElements, incomingNodes, outgoingNodes, incomingEdges, outgoingEdges), 'id');
|
|
152
157
|
}
|
|
153
158
|
else if ((model === null || model === void 0 ? void 0 : model.BaseType) === 'edge') {
|
|
154
159
|
// 高亮边及对应的节点
|
|
155
160
|
model.updateStyles(this.tempStyles[id]);
|
|
156
161
|
model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id]);
|
|
157
162
|
model.targetNode.updateStyles(this.tempStyles[model.targetNode.id]);
|
|
163
|
+
relateElements = [model.sourceNode, model.targetNode];
|
|
158
164
|
}
|
|
165
|
+
this.lf.emit('highlight:neighbours', {
|
|
166
|
+
data: model,
|
|
167
|
+
relateElements: relateElements,
|
|
168
|
+
});
|
|
159
169
|
};
|
|
160
170
|
Highlight.prototype.highlightPath = function (id) {
|
|
161
171
|
var _this = this;
|
|
162
172
|
var path = getPath(id, this.lf);
|
|
173
|
+
var relateElements = [];
|
|
163
174
|
path.forEach(function (_id) {
|
|
164
|
-
var
|
|
175
|
+
var elementModel = _this.lf.getModelById(_id);
|
|
165
176
|
// 高亮路径上所有的边和节点
|
|
166
|
-
|
|
177
|
+
elementModel === null || elementModel === void 0 ? void 0 : elementModel.updateStyles(_this.tempStyles[_id]);
|
|
178
|
+
relateElements.push(elementModel);
|
|
179
|
+
});
|
|
180
|
+
this.lf.emit('highlight:path', {
|
|
181
|
+
data: this.lf.getModelById(id),
|
|
182
|
+
relateElements: relateElements,
|
|
167
183
|
});
|
|
168
184
|
};
|
|
169
185
|
Highlight.prototype.highlight = function (id, mode) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import LogicFlow from '@logicflow/core';
|
|
2
|
+
export interface SelectionConfig {
|
|
3
|
+
exclusiveMode?: boolean;
|
|
4
|
+
}
|
|
2
5
|
export declare class SelectionSelect {
|
|
3
6
|
static pluginName: string;
|
|
4
7
|
private container?;
|
|
@@ -9,11 +12,30 @@ export declare class SelectionSelect {
|
|
|
9
12
|
private disabled;
|
|
10
13
|
private isWholeNode;
|
|
11
14
|
private isWholeEdge;
|
|
15
|
+
exclusiveMode: boolean;
|
|
12
16
|
private mouseDownInfo;
|
|
13
|
-
|
|
17
|
+
private originalStopMoveGraph;
|
|
18
|
+
constructor({ lf, options }: LogicFlow.IExtensionProps);
|
|
14
19
|
render(_: LogicFlow, domContainer: HTMLElement): void;
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 清理选区状态
|
|
22
|
+
*/
|
|
23
|
+
private cleanupSelectionState;
|
|
24
|
+
/**
|
|
25
|
+
* 切换框选模式
|
|
26
|
+
* @param exclusive 是否为独占模式。true 表示只能进行框选操作,false 表示可以同时进行其他画布操作
|
|
27
|
+
*/
|
|
28
|
+
setExclusiveMode(exclusive?: boolean): void;
|
|
29
|
+
private addEventListeners;
|
|
30
|
+
private removeEventListeners;
|
|
31
|
+
/**
|
|
32
|
+
* 处理画布空白处鼠标按下事件(非独占模式)
|
|
33
|
+
*/
|
|
34
|
+
private handleBlankMouseDown;
|
|
35
|
+
/**
|
|
36
|
+
* 处理鼠标按下事件
|
|
37
|
+
*/
|
|
38
|
+
private handleMouseDown;
|
|
17
39
|
/**
|
|
18
40
|
* 设置选中的灵敏度
|
|
19
41
|
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
|
|
@@ -1,72 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
28
|
exports.SelectionSelect = void 0;
|
|
29
|
+
var lodash_es_1 = require("lodash-es");
|
|
4
30
|
var SelectionSelect = /** @class */ (function () {
|
|
5
31
|
function SelectionSelect(_a) {
|
|
6
|
-
var lf = _a.lf;
|
|
32
|
+
var lf = _a.lf, options = _a.options;
|
|
7
33
|
var _this = this;
|
|
34
|
+
var _b;
|
|
8
35
|
this.disabled = true;
|
|
9
36
|
this.isWholeNode = true;
|
|
10
37
|
this.isWholeEdge = true;
|
|
38
|
+
this.exclusiveMode = false; // 框选独占模式:true 表示只能进行框选操作,false 表示可以同时进行其他画布操作
|
|
11
39
|
// 用于区分选区和点击事件
|
|
12
40
|
this.mouseDownInfo = null;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
time: Date.now(),
|
|
22
|
-
};
|
|
23
|
-
var lf = _this.lf;
|
|
24
|
-
var domContainer = _this.container;
|
|
25
|
-
if (!domContainer) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (_this.disabled) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// 禁用右键框选,修复可能导致画布出现多个框选框不消失的问题,见https://github.com/didi/LogicFlow/issues/985
|
|
32
|
-
var isRightClick = e.button === 2;
|
|
33
|
-
if (isRightClick) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
var _a = lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _a.x, y = _a.y;
|
|
37
|
-
_this.startPoint = {
|
|
38
|
-
x: x,
|
|
39
|
-
y: y,
|
|
40
|
-
};
|
|
41
|
-
_this.endPoint = {
|
|
42
|
-
x: x,
|
|
43
|
-
y: y,
|
|
44
|
-
};
|
|
45
|
-
var wrapper = document.createElement('div');
|
|
46
|
-
wrapper.className = 'lf-selection-select';
|
|
47
|
-
wrapper.oncontextmenu = function prevent(ev) {
|
|
48
|
-
ev.preventDefault();
|
|
49
|
-
};
|
|
50
|
-
wrapper.style.top = "".concat(_this.startPoint.y, "px");
|
|
51
|
-
wrapper.style.left = "".concat(_this.startPoint.x, "px");
|
|
52
|
-
domContainer.appendChild(wrapper);
|
|
53
|
-
_this.wrapper = wrapper;
|
|
54
|
-
document.addEventListener('mousemove', _this.draw);
|
|
55
|
-
document.addEventListener('mouseup', _this.drawOff);
|
|
56
|
-
};
|
|
57
|
-
this.onToolContainerMouseUp = function (e) {
|
|
58
|
-
if (_this.mouseDownInfo) {
|
|
59
|
-
var _a = _this.mouseDownInfo, x = _a.x, y = _a.y, time = _a.time;
|
|
60
|
-
var now = Date.now();
|
|
61
|
-
// 用 mouseDown 和 mouseUp 的位置偏移及时间间隔来判断是否是点击事件
|
|
62
|
-
var isClickEvent = Math.abs(e.clientX - x) < 10 &&
|
|
63
|
-
Math.abs(e.clientY - y) < 10 &&
|
|
64
|
-
now - time < 100;
|
|
65
|
-
if (isClickEvent) {
|
|
66
|
-
_this.lf.clearSelectElements();
|
|
67
|
-
}
|
|
68
|
-
_this.mouseDownInfo = null;
|
|
69
|
-
}
|
|
41
|
+
// 记录原始的 stopMoveGraph 设置
|
|
42
|
+
this.originalStopMoveGraph = false;
|
|
43
|
+
/**
|
|
44
|
+
* 处理画布空白处鼠标按下事件(非独占模式)
|
|
45
|
+
*/
|
|
46
|
+
this.handleBlankMouseDown = function (_a) {
|
|
47
|
+
var e = _a.e;
|
|
48
|
+
_this.handleMouseDown(e);
|
|
70
49
|
};
|
|
71
50
|
this.draw = function (ev) {
|
|
72
51
|
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
|
@@ -96,17 +75,33 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
96
75
|
}
|
|
97
76
|
}
|
|
98
77
|
};
|
|
99
|
-
this.drawOff = function () {
|
|
100
|
-
|
|
78
|
+
this.drawOff = function (e) {
|
|
79
|
+
// 处理鼠标抬起事件
|
|
80
|
+
// 首先判断是否是点击,如果是,则清空框选
|
|
81
|
+
if (_this.mouseDownInfo) {
|
|
82
|
+
var _a = _this.mouseDownInfo, x = _a.x, y = _a.y, time = _a.time;
|
|
83
|
+
var isClick = Math.abs(e.clientX - x) < 5 &&
|
|
84
|
+
Math.abs(e.clientY - y) < 5 &&
|
|
85
|
+
Date.now() - time < 200;
|
|
86
|
+
if (isClick) {
|
|
87
|
+
_this.lf.clearSelectElements();
|
|
88
|
+
_this.cleanupSelectionState();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var curStartPoint = (0, lodash_es_1.cloneDeep)(_this.startPoint);
|
|
93
|
+
var curEndPoint = (0, lodash_es_1.cloneDeep)(_this.endPoint);
|
|
101
94
|
document.removeEventListener('mousemove', _this.draw);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
_this.wrapper.oncontextmenu = null;
|
|
105
|
-
(_a = _this.container) === null || _a === void 0 ? void 0 : _a.removeChild(_this.wrapper);
|
|
95
|
+
if (!_this.exclusiveMode) {
|
|
96
|
+
document.removeEventListener('mouseup', _this.drawOff);
|
|
106
97
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
// 恢复原始的 stopMoveGraph 设置
|
|
99
|
+
_this.lf.updateEditConfig({
|
|
100
|
+
stopMoveGraph: _this.originalStopMoveGraph,
|
|
101
|
+
});
|
|
102
|
+
if (curStartPoint && curEndPoint) {
|
|
103
|
+
var x = curStartPoint.x, y = curStartPoint.y;
|
|
104
|
+
var x1 = curEndPoint.x, y1 = curEndPoint.y;
|
|
110
105
|
// 返回框选范围,左上角和右下角的坐标
|
|
111
106
|
var lt = [Math.min(x, x1), Math.min(y, y1)];
|
|
112
107
|
var rb = [Math.max(x, x1), Math.max(y, y1)];
|
|
@@ -116,11 +111,21 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
116
111
|
});
|
|
117
112
|
// 选区太小的情况就忽略
|
|
118
113
|
if (Math.abs(x1 - x) < 10 && Math.abs(y1 - y) < 10) {
|
|
114
|
+
if (_this.wrapper) {
|
|
115
|
+
_this.wrapper.oncontextmenu = null;
|
|
116
|
+
if (_this.container && _this.wrapper.parentNode === _this.container) {
|
|
117
|
+
_this.container.removeChild(_this.wrapper);
|
|
118
|
+
}
|
|
119
|
+
_this.wrapper = undefined;
|
|
120
|
+
}
|
|
119
121
|
return;
|
|
120
122
|
}
|
|
121
123
|
var elements_1 = _this.lf.graphModel.getAreaElement(lt, rb, _this.isWholeEdge, _this.isWholeNode, true);
|
|
122
|
-
var
|
|
124
|
+
var _b = _this.lf.graphModel, dynamicGroup_1 = _b.dynamicGroup, group_1 = _b.group;
|
|
123
125
|
var nonGroupedElements_1 = [];
|
|
126
|
+
var selectedElements = _this.lf.getSelectElements();
|
|
127
|
+
// 同时记录节点和边的ID
|
|
128
|
+
var selectedIds_1 = new Set(__spreadArray(__spreadArray([], __read(selectedElements.nodes.map(function (node) { return node.id; })), false), __read(selectedElements.edges.map(function (edge) { return edge.id; })), false));
|
|
124
129
|
elements_1.forEach(function (element) {
|
|
125
130
|
// 如果节点属于分组,则不选中节点,此处兼容旧版 Group 插件
|
|
126
131
|
if (group_1) {
|
|
@@ -137,17 +142,40 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
137
142
|
return;
|
|
138
143
|
}
|
|
139
144
|
}
|
|
145
|
+
// 在独占模式下,如果元素已经被选中,则取消选中
|
|
146
|
+
if (_this.exclusiveMode && selectedIds_1.has(element.id)) {
|
|
147
|
+
_this.lf.deselectElementById(element.id);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// 非独占模式下,或者元素未被选中时,选中元素
|
|
140
151
|
_this.lf.selectElementById(element.id, true);
|
|
141
152
|
nonGroupedElements_1.push(element);
|
|
142
153
|
});
|
|
154
|
+
// 重置起始点和终点
|
|
155
|
+
// 注意:这两个值必须在触发closeSelectionSelect方法前充值,否则会导致独占模式下元素无法选中的问题
|
|
156
|
+
_this.startPoint = undefined;
|
|
157
|
+
_this.endPoint = undefined;
|
|
158
|
+
// 如果有选中的元素,触发 selection:drop 事件
|
|
159
|
+
if (nonGroupedElements_1.length > 0) {
|
|
160
|
+
_this.lf.emit('selection:drop', { e: e });
|
|
161
|
+
}
|
|
162
|
+
// 触发 selection:selected 事件
|
|
143
163
|
_this.lf.emit('selection:selected', {
|
|
144
164
|
elements: nonGroupedElements_1,
|
|
145
165
|
leftTopPoint: lt,
|
|
146
166
|
rightBottomPoint: rb,
|
|
147
167
|
});
|
|
148
168
|
}
|
|
169
|
+
if (_this.wrapper) {
|
|
170
|
+
_this.wrapper.oncontextmenu = null;
|
|
171
|
+
if (_this.container && _this.wrapper.parentNode === _this.container) {
|
|
172
|
+
_this.container.removeChild(_this.wrapper);
|
|
173
|
+
}
|
|
174
|
+
_this.wrapper = undefined;
|
|
175
|
+
}
|
|
149
176
|
};
|
|
150
177
|
this.lf = lf;
|
|
178
|
+
this.exclusiveMode = (_b = options === null || options === void 0 ? void 0 : options.exclusiveMode) !== null && _b !== void 0 ? _b : false;
|
|
151
179
|
// TODO: 有没有既能将方法挂载到lf上,又能提供类型提示的方法?
|
|
152
180
|
lf.openSelectionSelect = function () {
|
|
153
181
|
_this.openSelectionSelect();
|
|
@@ -155,10 +183,115 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
155
183
|
lf.closeSelectionSelect = function () {
|
|
156
184
|
_this.closeSelectionSelect();
|
|
157
185
|
};
|
|
186
|
+
// 新增切换独占模式的方法
|
|
187
|
+
lf.setSelectionSelectMode = function (exclusive) {
|
|
188
|
+
_this.setExclusiveMode(exclusive);
|
|
189
|
+
};
|
|
190
|
+
// 绑定方法的 this 上下文
|
|
191
|
+
this.handleMouseDown = this.handleMouseDown.bind(this);
|
|
192
|
+
this.draw = this.draw.bind(this);
|
|
193
|
+
this.drawOff = this.drawOff.bind(this);
|
|
158
194
|
}
|
|
159
195
|
SelectionSelect.prototype.render = function (_, domContainer) {
|
|
160
196
|
this.container = domContainer;
|
|
161
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* 清理选区状态
|
|
200
|
+
*/
|
|
201
|
+
SelectionSelect.prototype.cleanupSelectionState = function () {
|
|
202
|
+
// 清理当前的选区状态
|
|
203
|
+
if (this.wrapper) {
|
|
204
|
+
this.wrapper.oncontextmenu = null;
|
|
205
|
+
if (this.container && this.wrapper.parentNode === this.container) {
|
|
206
|
+
this.container.removeChild(this.wrapper);
|
|
207
|
+
}
|
|
208
|
+
this.wrapper = undefined;
|
|
209
|
+
}
|
|
210
|
+
this.startPoint = undefined;
|
|
211
|
+
this.endPoint = undefined;
|
|
212
|
+
this.mouseDownInfo = null;
|
|
213
|
+
// 移除事件监听
|
|
214
|
+
document.removeEventListener('mousemove', this.draw);
|
|
215
|
+
document.removeEventListener('mouseup', this.drawOff);
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* 切换框选模式
|
|
219
|
+
* @param exclusive 是否为独占模式。true 表示只能进行框选操作,false 表示可以同时进行其他画布操作
|
|
220
|
+
*/
|
|
221
|
+
SelectionSelect.prototype.setExclusiveMode = function (exclusive) {
|
|
222
|
+
if (exclusive === void 0) { exclusive = false; }
|
|
223
|
+
if (this.exclusiveMode === exclusive)
|
|
224
|
+
return;
|
|
225
|
+
this.cleanupSelectionState();
|
|
226
|
+
this.exclusiveMode = exclusive;
|
|
227
|
+
if (this.container && !this.disabled) {
|
|
228
|
+
// 切换事件监听方式
|
|
229
|
+
this.removeEventListeners();
|
|
230
|
+
this.addEventListeners();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
SelectionSelect.prototype.addEventListeners = function () {
|
|
234
|
+
if (!this.container)
|
|
235
|
+
return;
|
|
236
|
+
if (this.exclusiveMode) {
|
|
237
|
+
// 独占模式:监听 container 的 mousedown 事件
|
|
238
|
+
this.container.style.pointerEvents = 'auto';
|
|
239
|
+
this.container.addEventListener('mousedown', this.handleMouseDown);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// 非独占模式:监听画布的 blank:mousedown 事件
|
|
243
|
+
this.container.style.pointerEvents = 'none';
|
|
244
|
+
// 使用实例方法而不是箭头函数,这样可以正确移除事件监听
|
|
245
|
+
this.lf.on('blank:mousedown', this.handleBlankMouseDown);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
SelectionSelect.prototype.removeEventListeners = function () {
|
|
249
|
+
if (this.container) {
|
|
250
|
+
this.container.style.pointerEvents = 'none';
|
|
251
|
+
this.container.removeEventListener('mousedown', this.handleMouseDown);
|
|
252
|
+
}
|
|
253
|
+
// 移除 blank:mousedown 事件监听
|
|
254
|
+
this.lf.off('blank:mousedown', this.handleBlankMouseDown);
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* 处理鼠标按下事件
|
|
258
|
+
*/
|
|
259
|
+
SelectionSelect.prototype.handleMouseDown = function (e) {
|
|
260
|
+
var _a;
|
|
261
|
+
if (!this.container || this.disabled)
|
|
262
|
+
return;
|
|
263
|
+
// 禁用右键框选
|
|
264
|
+
var isRightClick = e.button === 2;
|
|
265
|
+
if (isRightClick)
|
|
266
|
+
return;
|
|
267
|
+
// 清理之前可能存在的选区状态
|
|
268
|
+
this.cleanupSelectionState();
|
|
269
|
+
// 记录鼠标按下时的位置和时间
|
|
270
|
+
this.mouseDownInfo = {
|
|
271
|
+
x: e.clientX,
|
|
272
|
+
y: e.clientY,
|
|
273
|
+
time: Date.now(),
|
|
274
|
+
};
|
|
275
|
+
// 记录原始设置并临时禁止画布移动
|
|
276
|
+
this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
|
|
277
|
+
this.lf.updateEditConfig({
|
|
278
|
+
stopMoveGraph: true,
|
|
279
|
+
});
|
|
280
|
+
var _b = this.lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _b.x, y = _b.y;
|
|
281
|
+
this.startPoint = { x: x, y: y };
|
|
282
|
+
this.endPoint = { x: x, y: y };
|
|
283
|
+
var wrapper = document.createElement('div');
|
|
284
|
+
wrapper.className = 'lf-selection-select';
|
|
285
|
+
wrapper.oncontextmenu = function prevent(ev) {
|
|
286
|
+
ev.preventDefault();
|
|
287
|
+
};
|
|
288
|
+
wrapper.style.top = "".concat(this.startPoint.y, "px");
|
|
289
|
+
wrapper.style.left = "".concat(this.startPoint.x, "px");
|
|
290
|
+
(_a = this.container) === null || _a === void 0 ? void 0 : _a.appendChild(wrapper);
|
|
291
|
+
this.wrapper = wrapper;
|
|
292
|
+
document.addEventListener('mousemove', this.draw);
|
|
293
|
+
document.addEventListener('mouseup', this.drawOff);
|
|
294
|
+
};
|
|
162
295
|
/**
|
|
163
296
|
* 设置选中的灵敏度
|
|
164
297
|
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
|
|
@@ -180,11 +313,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
180
313
|
if (!this.container) {
|
|
181
314
|
return;
|
|
182
315
|
}
|
|
183
|
-
this.
|
|
184
|
-
this.
|
|
185
|
-
this.container.addEventListener('mouseup', this.onToolContainerMouseUp);
|
|
186
|
-
// 取消点击事件的穿透,只让 ToolOverlay 接收事件,避免与图形元素的事件冲突
|
|
187
|
-
this.container.style.pointerEvents = 'auto';
|
|
316
|
+
this.cleanupSelectionState();
|
|
317
|
+
this.addEventListeners();
|
|
188
318
|
this.open();
|
|
189
319
|
};
|
|
190
320
|
/**
|
|
@@ -194,10 +324,18 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
194
324
|
if (!this.container) {
|
|
195
325
|
return;
|
|
196
326
|
}
|
|
197
|
-
|
|
198
|
-
this.
|
|
199
|
-
|
|
200
|
-
|
|
327
|
+
// 如果还有未完成的框选,先触发 drawOff 完成框选
|
|
328
|
+
if (this.wrapper && this.startPoint && this.endPoint) {
|
|
329
|
+
// 记录上一次的结束点,用于触发 mouseup 事件
|
|
330
|
+
var lastEndPoint = (0, lodash_es_1.cloneDeep)(this.endPoint);
|
|
331
|
+
var lastEvent = new MouseEvent('mouseup', {
|
|
332
|
+
clientX: lastEndPoint.x,
|
|
333
|
+
clientY: lastEndPoint.y,
|
|
334
|
+
});
|
|
335
|
+
this.drawOff(lastEvent);
|
|
336
|
+
}
|
|
337
|
+
this.cleanupSelectionState();
|
|
338
|
+
this.removeEventListeners();
|
|
201
339
|
this.close();
|
|
202
340
|
};
|
|
203
341
|
SelectionSelect.prototype.open = function () {
|
|
@@ -122,7 +122,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
122
122
|
var group = _this.getGroupByBounds(bounds, node);
|
|
123
123
|
if (group) {
|
|
124
124
|
var isAllowAppendIn = group.isAllowAppendIn(node);
|
|
125
|
-
console.log('isAllowAppendIn', isAllowAppendIn);
|
|
126
125
|
if (isAllowAppendIn) {
|
|
127
126
|
group.addChild(node.id);
|
|
128
127
|
// 建立节点与 group 的映射关系放在了 group.addChild 触发的事件中,与直接调用 addChild 的行为保持一致
|
|
@@ -140,7 +139,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
140
139
|
};
|
|
141
140
|
this.onGroupAddNode = function (_a) {
|
|
142
141
|
var groupData = _a.data, childId = _a.childId;
|
|
143
|
-
console.log('group:add-node', groupData);
|
|
144
142
|
_this.nodeGroupMap.set(childId, groupData.id);
|
|
145
143
|
};
|
|
146
144
|
this.removeNodeFromGroup = function (_a) {
|
|
@@ -183,7 +181,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
183
181
|
if (!isAllowAppendIn)
|
|
184
182
|
return;
|
|
185
183
|
_this.activeGroup = targetGroup;
|
|
186
|
-
console.log('this.activeGroup', _this.activeGroup);
|
|
187
184
|
_this.activeGroup.setAllowAppendChild(true);
|
|
188
185
|
}
|
|
189
186
|
};
|
|
@@ -293,7 +290,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
293
290
|
};
|
|
294
291
|
this.onGraphRendered = function (_a) {
|
|
295
292
|
var data = _a.data;
|
|
296
|
-
console.log('data', data);
|
|
297
293
|
(0, lodash_es_1.forEach)(data.nodes, function (node) {
|
|
298
294
|
if (node.children) {
|
|
299
295
|
(0, lodash_es_1.forEach)(node.children, function (childId) {
|
|
@@ -470,8 +466,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
470
466
|
}
|
|
471
467
|
}
|
|
472
468
|
});
|
|
473
|
-
// TODO: 确认,递归的方式,是否将所有嵌套的边数据都有返回
|
|
474
|
-
console.log('allRelatedEdges -->>', allRelatedEdges);
|
|
475
469
|
// 1. 判断每一条边的开始节点、目标节点是否在 Group 中
|
|
476
470
|
var edgesInnerGroup = (0, lodash_es_1.filter)(allRelatedEdges, function (edge) {
|
|
477
471
|
return ((0, lodash_es_1.has)(nodeIdMap, edge.sourceNodeId) && (0, lodash_es_1.has)(nodeIdMap, edge.targetNodeId));
|
|
@@ -608,10 +602,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
608
602
|
lf.on('node:click', this.onNodeSelect);
|
|
609
603
|
lf.on('node:mousemove', this.onNodeMove);
|
|
610
604
|
lf.on('graph:rendered', this.onGraphRendered);
|
|
611
|
-
lf.on('graph:updated', function (_a) {
|
|
612
|
-
var data = _a.data;
|
|
613
|
-
return console.log('data', data);
|
|
614
|
-
});
|
|
615
605
|
lf.on('group:add-node', this.onGroupAddNode);
|
|
616
606
|
// https://github.com/didi/LogicFlow/issues/1346
|
|
617
607
|
// 重写 addElements() 方法,在 addElements() 原有基础上增加对 group 内部所有 nodes 和 edges 的复制功能
|
|
@@ -645,7 +635,6 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
645
635
|
(0, lodash_es_1.forEach)(edgesInnerGroup, function (edge) {
|
|
646
636
|
_this.createEdge(edge, nodeIdMap, distance);
|
|
647
637
|
});
|
|
648
|
-
console.log('selectedEdges --->>>', selectedEdges);
|
|
649
638
|
(0, lodash_es_1.forEach)(selectedEdges, function (edge) {
|
|
650
639
|
elements.edges.push(_this.createEdge(edge, nodeIdMap, distance));
|
|
651
640
|
});
|
|
@@ -329,7 +329,6 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
329
329
|
var _this = this;
|
|
330
330
|
var data = _super.prototype.getData.call(this);
|
|
331
331
|
data.children = [];
|
|
332
|
-
console.log('this.children', this.children);
|
|
333
332
|
this.children.forEach(function (childId) {
|
|
334
333
|
var model = _this.graphModel.getNodeModelById(childId);
|
|
335
334
|
if (model && !model.virtual) {
|