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