@logicflow/extension 2.0.15 → 2.0.16
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 +10 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/components/menu/index.js +12 -0
- package/es/components/selection-select/index.d.ts +4 -2
- package/es/components/selection-select/index.js +91 -55
- package/es/dynamic-group/index.d.ts +6 -2
- package/es/dynamic-group/index.js +29 -9
- package/lib/components/menu/index.js +12 -0
- package/lib/components/selection-select/index.d.ts +4 -2
- package/lib/components/selection-select/index.js +91 -55
- package/lib/dynamic-group/index.d.ts +6 -2
- package/lib/dynamic-group/index.js +29 -9
- package/package.json +3 -3
- package/src/components/menu/index.ts +4 -1
- package/src/components/selection-select/index.ts +100 -56
- package/src/dynamic-group/index.ts +32 -9
- package/stats.html +1 -1
|
@@ -1,3 +1,14 @@
|
|
|
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
|
+
};
|
|
1
12
|
var __read = (this && this.__read) || function (o, n) {
|
|
2
13
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
14
|
if (!m) return o;
|
|
@@ -205,6 +216,7 @@ var Menu = /** @class */ (function () {
|
|
|
205
216
|
var position = _a.position;
|
|
206
217
|
var menuList = (_c = (_b = _this.menuTypeMap) === null || _b === void 0 ? void 0 : _b.get(DefaultGraphMenuKey)) !== null && _c !== void 0 ? _c : [];
|
|
207
218
|
var _d = position.domOverlayPosition, x = _d.x, y = _d.y;
|
|
219
|
+
_this.__currentData = __assign({}, position.canvasOverlayPosition);
|
|
208
220
|
_this.showMenu(x, y, menuList);
|
|
209
221
|
});
|
|
210
222
|
this.lf.on('selection:contextmenu', function (_a) {
|
|
@@ -7,11 +7,13 @@ export declare class SelectionSelect {
|
|
|
7
7
|
private startPoint?;
|
|
8
8
|
private endPoint?;
|
|
9
9
|
private disabled;
|
|
10
|
-
private isDefaultStopMoveGraph;
|
|
11
10
|
private isWholeNode;
|
|
12
11
|
private isWholeEdge;
|
|
12
|
+
private mouseDownInfo;
|
|
13
13
|
constructor({ lf }: LogicFlow.IExtensionProps);
|
|
14
|
-
render(
|
|
14
|
+
render(_: LogicFlow, domContainer: HTMLElement): void;
|
|
15
|
+
onToolContainerMouseDown: (e: MouseEvent) => void;
|
|
16
|
+
onToolContainerMouseUp: (e: MouseEvent) => void;
|
|
15
17
|
/**
|
|
16
18
|
* 设置选中的灵敏度
|
|
17
19
|
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
|
|
@@ -3,9 +3,68 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
3
3
|
var lf = _a.lf;
|
|
4
4
|
var _this = this;
|
|
5
5
|
this.disabled = true;
|
|
6
|
-
this.isDefaultStopMoveGraph = false;
|
|
7
6
|
this.isWholeNode = true;
|
|
8
7
|
this.isWholeEdge = true;
|
|
8
|
+
// 用于区分选区和点击事件
|
|
9
|
+
this.mouseDownInfo = null;
|
|
10
|
+
this.onToolContainerMouseDown = function (e) {
|
|
11
|
+
// 避免在其他插件元素上点击时开启选区
|
|
12
|
+
if (e.target !== _this.container) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
_this.mouseDownInfo = {
|
|
16
|
+
x: e.clientX,
|
|
17
|
+
y: e.clientY,
|
|
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
|
+
}
|
|
67
|
+
};
|
|
9
68
|
this.draw = function (ev) {
|
|
10
69
|
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
|
11
70
|
_this.endPoint = {
|
|
@@ -56,16 +115,24 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
56
115
|
if (Math.abs(x1 - x) < 10 && Math.abs(y1 - y) < 10) {
|
|
57
116
|
return;
|
|
58
117
|
}
|
|
59
|
-
var
|
|
118
|
+
var elements_1 = _this.lf.graphModel.getAreaElement(lt, rb, _this.isWholeEdge, _this.isWholeNode, true);
|
|
60
119
|
var _d = _this.lf.graphModel, dynamicGroup_1 = _d.dynamicGroup, group_1 = _d.group;
|
|
61
120
|
var nonGroupedElements_1 = [];
|
|
62
|
-
|
|
121
|
+
elements_1.forEach(function (element) {
|
|
63
122
|
// 如果节点属于分组,则不选中节点,此处兼容旧版 Group 插件
|
|
64
|
-
if (group_1
|
|
65
|
-
|
|
123
|
+
if (group_1) {
|
|
124
|
+
var elementGroup = group_1.getNodeGroup(element.id);
|
|
125
|
+
if (elements_1.includes(elementGroup)) {
|
|
126
|
+
// 当被选中的元素的父分组被选中时,不选中该元素
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
66
129
|
}
|
|
67
|
-
if (dynamicGroup_1
|
|
68
|
-
|
|
130
|
+
if (dynamicGroup_1) {
|
|
131
|
+
var elementGroup = dynamicGroup_1.getGroupByNodeId(element.id);
|
|
132
|
+
if (elements_1.includes(elementGroup)) {
|
|
133
|
+
// 当被选中的元素的父分组被选中时,不选中该元素
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
69
136
|
}
|
|
70
137
|
_this.lf.selectElementById(element.id, true);
|
|
71
138
|
nonGroupedElements_1.push(element);
|
|
@@ -78,9 +145,6 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
78
145
|
}
|
|
79
146
|
};
|
|
80
147
|
this.lf = lf;
|
|
81
|
-
// 初始化isDefaultStopMoveGraph取值
|
|
82
|
-
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
|
|
83
|
-
this.isDefaultStopMoveGraph = stopMoveGraph;
|
|
84
148
|
// TODO: 有没有既能将方法挂载到lf上,又能提供类型提示的方法?
|
|
85
149
|
lf.openSelectionSelect = function () {
|
|
86
150
|
_this.openSelectionSelect();
|
|
@@ -89,42 +153,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
89
153
|
_this.closeSelectionSelect();
|
|
90
154
|
};
|
|
91
155
|
}
|
|
92
|
-
SelectionSelect.prototype.render = function (
|
|
93
|
-
var _this = this;
|
|
156
|
+
SelectionSelect.prototype.render = function (_, domContainer) {
|
|
94
157
|
this.container = domContainer;
|
|
95
|
-
lf.on('blank:mousedown', function (_a) {
|
|
96
|
-
var e = _a.e;
|
|
97
|
-
var config = lf.getEditConfig();
|
|
98
|
-
// 鼠标控制滚动移动画布的时候,不能选区。
|
|
99
|
-
if (!config.stopMoveGraph || _this.disabled) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// 禁用右键框选,修复可能导致画布出现多个框选框不消失的问题,见https://github.com/didi/LogicFlow/issues/985
|
|
103
|
-
var isRightClick = e.button === 2;
|
|
104
|
-
if (isRightClick) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
var _b = lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _b.x, y = _b.y;
|
|
108
|
-
_this.startPoint = {
|
|
109
|
-
x: x,
|
|
110
|
-
y: y,
|
|
111
|
-
};
|
|
112
|
-
_this.endPoint = {
|
|
113
|
-
x: x,
|
|
114
|
-
y: y,
|
|
115
|
-
};
|
|
116
|
-
var wrapper = document.createElement('div');
|
|
117
|
-
wrapper.className = 'lf-selection-select';
|
|
118
|
-
wrapper.oncontextmenu = function prevent(ev) {
|
|
119
|
-
ev.preventDefault();
|
|
120
|
-
};
|
|
121
|
-
wrapper.style.top = "".concat(_this.startPoint.y, "px");
|
|
122
|
-
wrapper.style.left = "".concat(_this.startPoint.x, "px");
|
|
123
|
-
domContainer.appendChild(wrapper);
|
|
124
|
-
_this.wrapper = wrapper;
|
|
125
|
-
document.addEventListener('mousemove', _this.draw);
|
|
126
|
-
document.addEventListener('mouseup', _this.drawOff);
|
|
127
|
-
});
|
|
128
158
|
};
|
|
129
159
|
/**
|
|
130
160
|
* 设置选中的灵敏度
|
|
@@ -141,24 +171,30 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
141
171
|
* 开启选区
|
|
142
172
|
*/
|
|
143
173
|
SelectionSelect.prototype.openSelectionSelect = function () {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
174
|
+
if (!this.disabled) {
|
|
175
|
+
this.closeSelectionSelect();
|
|
176
|
+
}
|
|
177
|
+
if (!this.container) {
|
|
178
|
+
return;
|
|
150
179
|
}
|
|
180
|
+
this.mouseDownInfo = null;
|
|
181
|
+
this.container.addEventListener('mousedown', this.onToolContainerMouseDown);
|
|
182
|
+
this.container.addEventListener('mouseup', this.onToolContainerMouseUp);
|
|
183
|
+
// 取消点击事件的穿透,只让 ToolOverlay 接收事件,避免与图形元素的事件冲突
|
|
184
|
+
this.container.style.pointerEvents = 'auto';
|
|
151
185
|
this.open();
|
|
152
186
|
};
|
|
153
187
|
/**
|
|
154
188
|
* 关闭选区
|
|
155
189
|
*/
|
|
156
190
|
SelectionSelect.prototype.closeSelectionSelect = function () {
|
|
157
|
-
if (!this.
|
|
158
|
-
|
|
159
|
-
stopMoveGraph: false,
|
|
160
|
-
});
|
|
191
|
+
if (!this.container) {
|
|
192
|
+
return;
|
|
161
193
|
}
|
|
194
|
+
this.container.style.pointerEvents = 'none';
|
|
195
|
+
this.mouseDownInfo = null;
|
|
196
|
+
this.container.removeEventListener('mousedown', this.onToolContainerMouseDown);
|
|
197
|
+
this.container.removeEventListener('mouseup', this.onToolContainerMouseUp);
|
|
162
198
|
this.close();
|
|
163
199
|
};
|
|
164
200
|
SelectionSelect.prototype.open = function () {
|
|
@@ -48,10 +48,14 @@ export declare class DynamicGroup {
|
|
|
48
48
|
* @param nodes
|
|
49
49
|
*/
|
|
50
50
|
calibrateTopGroupZIndex(nodes: NodeData[]): void;
|
|
51
|
-
|
|
51
|
+
onSelectionDrop: () => void;
|
|
52
|
+
onNodeAddOrDrop: ({ data: node }: CallbackArgs<'node:add'>) => void;
|
|
53
|
+
addNodeToGroup: (node: LogicFlow.NodeData) => void;
|
|
52
54
|
onGroupAddNode: ({ data: groupData, childId, }: CallbackArgs<'group:add-node'>) => void;
|
|
53
55
|
removeNodeFromGroup: ({ data: node, model, }: CallbackArgs<'node:delete'>) => void;
|
|
54
|
-
|
|
56
|
+
onSelectionDrag: () => void;
|
|
57
|
+
onNodeDrag: ({ data: node }: CallbackArgs<'node:drag'>) => void;
|
|
58
|
+
setActiveGroup: (node: LogicFlow.NodeData) => void;
|
|
55
59
|
/**
|
|
56
60
|
* 1. 分组节点默认在普通节点下面
|
|
57
61
|
* 2. 分组节点被选中后,会将分组节点以及其内部的其它分组节点放到其余分组节点的上面
|
|
@@ -55,9 +55,17 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
55
55
|
this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
|
|
56
56
|
// 存储节点与 group 的映射关系
|
|
57
57
|
this.nodeGroupMap = new Map();
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
this.onSelectionDrop = function () {
|
|
59
|
+
var selectedNodes = _this.lf.graphModel.getSelectElements().nodes;
|
|
60
|
+
selectedNodes.forEach(function (node) {
|
|
61
|
+
_this.addNodeToGroup(node);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
this.onNodeAddOrDrop = function (_a) {
|
|
60
65
|
var node = _a.data;
|
|
66
|
+
_this.addNodeToGroup(node);
|
|
67
|
+
};
|
|
68
|
+
this.addNodeToGroup = function (node) {
|
|
61
69
|
// 1. 如果该节点之前已经在 group 中了,则将其从之前的 group 移除
|
|
62
70
|
var preGroupId = _this.nodeGroupMap.get(node.id);
|
|
63
71
|
if (preGroupId) {
|
|
@@ -101,8 +109,7 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
101
109
|
if (isAllowAppendIn) {
|
|
102
110
|
group.addChild(node.id);
|
|
103
111
|
// 建立节点与 group 的映射关系放在了 group.addChild 触发的事件中,与直接调用 addChild 的行为保持一致
|
|
104
|
-
|
|
105
|
-
group.setAllowAppendChild(true);
|
|
112
|
+
group.setAllowAppendChild(false);
|
|
106
113
|
}
|
|
107
114
|
else {
|
|
108
115
|
// 抛出不允许插入的事件
|
|
@@ -134,8 +141,17 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
134
141
|
_this.nodeGroupMap.delete(node.id);
|
|
135
142
|
}
|
|
136
143
|
};
|
|
137
|
-
this.
|
|
144
|
+
this.onSelectionDrag = function () {
|
|
145
|
+
var selectedNodes = _this.lf.graphModel.getSelectElements().nodes;
|
|
146
|
+
selectedNodes.forEach(function (node) {
|
|
147
|
+
_this.setActiveGroup(node);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
this.onNodeDrag = function (_a) {
|
|
138
151
|
var node = _a.data;
|
|
152
|
+
_this.setActiveGroup(node);
|
|
153
|
+
};
|
|
154
|
+
this.setActiveGroup = function (node) {
|
|
139
155
|
var nodeModel = _this.lf.getNodeModelById(node.id);
|
|
140
156
|
var bounds = nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.getBounds();
|
|
141
157
|
if (nodeModel && bounds) {
|
|
@@ -567,9 +583,11 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
567
583
|
return true;
|
|
568
584
|
});
|
|
569
585
|
graphModel.dynamicGroup = this;
|
|
570
|
-
lf.on('node:add,node:drop,node:dnd-add', this.
|
|
586
|
+
lf.on('node:add,node:drop,node:dnd-add', this.onNodeAddOrDrop);
|
|
587
|
+
lf.on('selection:drop', this.onSelectionDrop);
|
|
571
588
|
lf.on('node:delete', this.removeNodeFromGroup);
|
|
572
|
-
lf.on('node:drag,node:dnd-drag', this.
|
|
589
|
+
lf.on('node:drag,node:dnd-drag', this.onNodeDrag);
|
|
590
|
+
lf.on('selection:drag', this.onSelectionDrag);
|
|
573
591
|
lf.on('node:click', this.onNodeSelect);
|
|
574
592
|
lf.on('node:mousemove', this.onNodeMove);
|
|
575
593
|
lf.on('graph:rendered', this.onGraphRendered);
|
|
@@ -623,9 +641,11 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
623
641
|
DynamicGroup.prototype.render = function () { };
|
|
624
642
|
DynamicGroup.prototype.destroy = function () {
|
|
625
643
|
// 销毁监听的事件,并移除渲染的 dom 内容
|
|
626
|
-
this.lf.off('node:add,node:drop,node:dnd-add', this.
|
|
644
|
+
this.lf.off('node:add,node:drop,node:dnd-add', this.onNodeAddOrDrop);
|
|
645
|
+
this.lf.off('selection:drop', this.onSelectionDrop);
|
|
627
646
|
this.lf.off('node:delete', this.removeNodeFromGroup);
|
|
628
|
-
this.lf.off('node:drag,node:dnd-drag', this.
|
|
647
|
+
this.lf.off('node:drag,node:dnd-drag', this.onNodeDrag);
|
|
648
|
+
this.lf.off('selection:drag', this.onSelectionDrag);
|
|
629
649
|
this.lf.off('node:click', this.onNodeSelect);
|
|
630
650
|
this.lf.off('node:mousemove', this.onNodeMove);
|
|
631
651
|
this.lf.off('graph:rendered', this.onGraphRendered);
|
|
@@ -1,4 +1,15 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
var __read = (this && this.__read) || function (o, n) {
|
|
3
14
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
15
|
if (!m) return o;
|
|
@@ -208,6 +219,7 @@ var Menu = /** @class */ (function () {
|
|
|
208
219
|
var position = _a.position;
|
|
209
220
|
var menuList = (_c = (_b = _this.menuTypeMap) === null || _b === void 0 ? void 0 : _b.get(DefaultGraphMenuKey)) !== null && _c !== void 0 ? _c : [];
|
|
210
221
|
var _d = position.domOverlayPosition, x = _d.x, y = _d.y;
|
|
222
|
+
_this.__currentData = __assign({}, position.canvasOverlayPosition);
|
|
211
223
|
_this.showMenu(x, y, menuList);
|
|
212
224
|
});
|
|
213
225
|
this.lf.on('selection:contextmenu', function (_a) {
|
|
@@ -7,11 +7,13 @@ export declare class SelectionSelect {
|
|
|
7
7
|
private startPoint?;
|
|
8
8
|
private endPoint?;
|
|
9
9
|
private disabled;
|
|
10
|
-
private isDefaultStopMoveGraph;
|
|
11
10
|
private isWholeNode;
|
|
12
11
|
private isWholeEdge;
|
|
12
|
+
private mouseDownInfo;
|
|
13
13
|
constructor({ lf }: LogicFlow.IExtensionProps);
|
|
14
|
-
render(
|
|
14
|
+
render(_: LogicFlow, domContainer: HTMLElement): void;
|
|
15
|
+
onToolContainerMouseDown: (e: MouseEvent) => void;
|
|
16
|
+
onToolContainerMouseUp: (e: MouseEvent) => void;
|
|
15
17
|
/**
|
|
16
18
|
* 设置选中的灵敏度
|
|
17
19
|
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
|
|
@@ -6,9 +6,68 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
6
6
|
var lf = _a.lf;
|
|
7
7
|
var _this = this;
|
|
8
8
|
this.disabled = true;
|
|
9
|
-
this.isDefaultStopMoveGraph = false;
|
|
10
9
|
this.isWholeNode = true;
|
|
11
10
|
this.isWholeEdge = true;
|
|
11
|
+
// 用于区分选区和点击事件
|
|
12
|
+
this.mouseDownInfo = null;
|
|
13
|
+
this.onToolContainerMouseDown = function (e) {
|
|
14
|
+
// 避免在其他插件元素上点击时开启选区
|
|
15
|
+
if (e.target !== _this.container) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
_this.mouseDownInfo = {
|
|
19
|
+
x: e.clientX,
|
|
20
|
+
y: e.clientY,
|
|
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
|
+
}
|
|
70
|
+
};
|
|
12
71
|
this.draw = function (ev) {
|
|
13
72
|
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
|
14
73
|
_this.endPoint = {
|
|
@@ -59,16 +118,24 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
59
118
|
if (Math.abs(x1 - x) < 10 && Math.abs(y1 - y) < 10) {
|
|
60
119
|
return;
|
|
61
120
|
}
|
|
62
|
-
var
|
|
121
|
+
var elements_1 = _this.lf.graphModel.getAreaElement(lt, rb, _this.isWholeEdge, _this.isWholeNode, true);
|
|
63
122
|
var _d = _this.lf.graphModel, dynamicGroup_1 = _d.dynamicGroup, group_1 = _d.group;
|
|
64
123
|
var nonGroupedElements_1 = [];
|
|
65
|
-
|
|
124
|
+
elements_1.forEach(function (element) {
|
|
66
125
|
// 如果节点属于分组,则不选中节点,此处兼容旧版 Group 插件
|
|
67
|
-
if (group_1
|
|
68
|
-
|
|
126
|
+
if (group_1) {
|
|
127
|
+
var elementGroup = group_1.getNodeGroup(element.id);
|
|
128
|
+
if (elements_1.includes(elementGroup)) {
|
|
129
|
+
// 当被选中的元素的父分组被选中时,不选中该元素
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
69
132
|
}
|
|
70
|
-
if (dynamicGroup_1
|
|
71
|
-
|
|
133
|
+
if (dynamicGroup_1) {
|
|
134
|
+
var elementGroup = dynamicGroup_1.getGroupByNodeId(element.id);
|
|
135
|
+
if (elements_1.includes(elementGroup)) {
|
|
136
|
+
// 当被选中的元素的父分组被选中时,不选中该元素
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
72
139
|
}
|
|
73
140
|
_this.lf.selectElementById(element.id, true);
|
|
74
141
|
nonGroupedElements_1.push(element);
|
|
@@ -81,9 +148,6 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
81
148
|
}
|
|
82
149
|
};
|
|
83
150
|
this.lf = lf;
|
|
84
|
-
// 初始化isDefaultStopMoveGraph取值
|
|
85
|
-
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
|
|
86
|
-
this.isDefaultStopMoveGraph = stopMoveGraph;
|
|
87
151
|
// TODO: 有没有既能将方法挂载到lf上,又能提供类型提示的方法?
|
|
88
152
|
lf.openSelectionSelect = function () {
|
|
89
153
|
_this.openSelectionSelect();
|
|
@@ -92,42 +156,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
92
156
|
_this.closeSelectionSelect();
|
|
93
157
|
};
|
|
94
158
|
}
|
|
95
|
-
SelectionSelect.prototype.render = function (
|
|
96
|
-
var _this = this;
|
|
159
|
+
SelectionSelect.prototype.render = function (_, domContainer) {
|
|
97
160
|
this.container = domContainer;
|
|
98
|
-
lf.on('blank:mousedown', function (_a) {
|
|
99
|
-
var e = _a.e;
|
|
100
|
-
var config = lf.getEditConfig();
|
|
101
|
-
// 鼠标控制滚动移动画布的时候,不能选区。
|
|
102
|
-
if (!config.stopMoveGraph || _this.disabled) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
// 禁用右键框选,修复可能导致画布出现多个框选框不消失的问题,见https://github.com/didi/LogicFlow/issues/985
|
|
106
|
-
var isRightClick = e.button === 2;
|
|
107
|
-
if (isRightClick) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
var _b = lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _b.x, y = _b.y;
|
|
111
|
-
_this.startPoint = {
|
|
112
|
-
x: x,
|
|
113
|
-
y: y,
|
|
114
|
-
};
|
|
115
|
-
_this.endPoint = {
|
|
116
|
-
x: x,
|
|
117
|
-
y: y,
|
|
118
|
-
};
|
|
119
|
-
var wrapper = document.createElement('div');
|
|
120
|
-
wrapper.className = 'lf-selection-select';
|
|
121
|
-
wrapper.oncontextmenu = function prevent(ev) {
|
|
122
|
-
ev.preventDefault();
|
|
123
|
-
};
|
|
124
|
-
wrapper.style.top = "".concat(_this.startPoint.y, "px");
|
|
125
|
-
wrapper.style.left = "".concat(_this.startPoint.x, "px");
|
|
126
|
-
domContainer.appendChild(wrapper);
|
|
127
|
-
_this.wrapper = wrapper;
|
|
128
|
-
document.addEventListener('mousemove', _this.draw);
|
|
129
|
-
document.addEventListener('mouseup', _this.drawOff);
|
|
130
|
-
});
|
|
131
161
|
};
|
|
132
162
|
/**
|
|
133
163
|
* 设置选中的灵敏度
|
|
@@ -144,24 +174,30 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
144
174
|
* 开启选区
|
|
145
175
|
*/
|
|
146
176
|
SelectionSelect.prototype.openSelectionSelect = function () {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
177
|
+
if (!this.disabled) {
|
|
178
|
+
this.closeSelectionSelect();
|
|
179
|
+
}
|
|
180
|
+
if (!this.container) {
|
|
181
|
+
return;
|
|
153
182
|
}
|
|
183
|
+
this.mouseDownInfo = null;
|
|
184
|
+
this.container.addEventListener('mousedown', this.onToolContainerMouseDown);
|
|
185
|
+
this.container.addEventListener('mouseup', this.onToolContainerMouseUp);
|
|
186
|
+
// 取消点击事件的穿透,只让 ToolOverlay 接收事件,避免与图形元素的事件冲突
|
|
187
|
+
this.container.style.pointerEvents = 'auto';
|
|
154
188
|
this.open();
|
|
155
189
|
};
|
|
156
190
|
/**
|
|
157
191
|
* 关闭选区
|
|
158
192
|
*/
|
|
159
193
|
SelectionSelect.prototype.closeSelectionSelect = function () {
|
|
160
|
-
if (!this.
|
|
161
|
-
|
|
162
|
-
stopMoveGraph: false,
|
|
163
|
-
});
|
|
194
|
+
if (!this.container) {
|
|
195
|
+
return;
|
|
164
196
|
}
|
|
197
|
+
this.container.style.pointerEvents = 'none';
|
|
198
|
+
this.mouseDownInfo = null;
|
|
199
|
+
this.container.removeEventListener('mousedown', this.onToolContainerMouseDown);
|
|
200
|
+
this.container.removeEventListener('mouseup', this.onToolContainerMouseUp);
|
|
165
201
|
this.close();
|
|
166
202
|
};
|
|
167
203
|
SelectionSelect.prototype.open = function () {
|
|
@@ -48,10 +48,14 @@ export declare class DynamicGroup {
|
|
|
48
48
|
* @param nodes
|
|
49
49
|
*/
|
|
50
50
|
calibrateTopGroupZIndex(nodes: NodeData[]): void;
|
|
51
|
-
|
|
51
|
+
onSelectionDrop: () => void;
|
|
52
|
+
onNodeAddOrDrop: ({ data: node }: CallbackArgs<'node:add'>) => void;
|
|
53
|
+
addNodeToGroup: (node: LogicFlow.NodeData) => void;
|
|
52
54
|
onGroupAddNode: ({ data: groupData, childId, }: CallbackArgs<'group:add-node'>) => void;
|
|
53
55
|
removeNodeFromGroup: ({ data: node, model, }: CallbackArgs<'node:delete'>) => void;
|
|
54
|
-
|
|
56
|
+
onSelectionDrag: () => void;
|
|
57
|
+
onNodeDrag: ({ data: node }: CallbackArgs<'node:drag'>) => void;
|
|
58
|
+
setActiveGroup: (node: LogicFlow.NodeData) => void;
|
|
55
59
|
/**
|
|
56
60
|
* 1. 分组节点默认在普通节点下面
|
|
57
61
|
* 2. 分组节点被选中后,会将分组节点以及其内部的其它分组节点放到其余分组节点的上面
|
|
@@ -72,9 +72,17 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
72
72
|
this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
|
|
73
73
|
// 存储节点与 group 的映射关系
|
|
74
74
|
this.nodeGroupMap = new Map();
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
this.onSelectionDrop = function () {
|
|
76
|
+
var selectedNodes = _this.lf.graphModel.getSelectElements().nodes;
|
|
77
|
+
selectedNodes.forEach(function (node) {
|
|
78
|
+
_this.addNodeToGroup(node);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
this.onNodeAddOrDrop = function (_a) {
|
|
77
82
|
var node = _a.data;
|
|
83
|
+
_this.addNodeToGroup(node);
|
|
84
|
+
};
|
|
85
|
+
this.addNodeToGroup = function (node) {
|
|
78
86
|
// 1. 如果该节点之前已经在 group 中了,则将其从之前的 group 移除
|
|
79
87
|
var preGroupId = _this.nodeGroupMap.get(node.id);
|
|
80
88
|
if (preGroupId) {
|
|
@@ -118,8 +126,7 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
118
126
|
if (isAllowAppendIn) {
|
|
119
127
|
group.addChild(node.id);
|
|
120
128
|
// 建立节点与 group 的映射关系放在了 group.addChild 触发的事件中,与直接调用 addChild 的行为保持一致
|
|
121
|
-
|
|
122
|
-
group.setAllowAppendChild(true);
|
|
129
|
+
group.setAllowAppendChild(false);
|
|
123
130
|
}
|
|
124
131
|
else {
|
|
125
132
|
// 抛出不允许插入的事件
|
|
@@ -151,8 +158,17 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
151
158
|
_this.nodeGroupMap.delete(node.id);
|
|
152
159
|
}
|
|
153
160
|
};
|
|
154
|
-
this.
|
|
161
|
+
this.onSelectionDrag = function () {
|
|
162
|
+
var selectedNodes = _this.lf.graphModel.getSelectElements().nodes;
|
|
163
|
+
selectedNodes.forEach(function (node) {
|
|
164
|
+
_this.setActiveGroup(node);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
this.onNodeDrag = function (_a) {
|
|
155
168
|
var node = _a.data;
|
|
169
|
+
_this.setActiveGroup(node);
|
|
170
|
+
};
|
|
171
|
+
this.setActiveGroup = function (node) {
|
|
156
172
|
var nodeModel = _this.lf.getNodeModelById(node.id);
|
|
157
173
|
var bounds = nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.getBounds();
|
|
158
174
|
if (nodeModel && bounds) {
|
|
@@ -584,9 +600,11 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
584
600
|
return true;
|
|
585
601
|
});
|
|
586
602
|
graphModel.dynamicGroup = this;
|
|
587
|
-
lf.on('node:add,node:drop,node:dnd-add', this.
|
|
603
|
+
lf.on('node:add,node:drop,node:dnd-add', this.onNodeAddOrDrop);
|
|
604
|
+
lf.on('selection:drop', this.onSelectionDrop);
|
|
588
605
|
lf.on('node:delete', this.removeNodeFromGroup);
|
|
589
|
-
lf.on('node:drag,node:dnd-drag', this.
|
|
606
|
+
lf.on('node:drag,node:dnd-drag', this.onNodeDrag);
|
|
607
|
+
lf.on('selection:drag', this.onSelectionDrag);
|
|
590
608
|
lf.on('node:click', this.onNodeSelect);
|
|
591
609
|
lf.on('node:mousemove', this.onNodeMove);
|
|
592
610
|
lf.on('graph:rendered', this.onGraphRendered);
|
|
@@ -640,9 +658,11 @@ var DynamicGroup = /** @class */ (function () {
|
|
|
640
658
|
DynamicGroup.prototype.render = function () { };
|
|
641
659
|
DynamicGroup.prototype.destroy = function () {
|
|
642
660
|
// 销毁监听的事件,并移除渲染的 dom 内容
|
|
643
|
-
this.lf.off('node:add,node:drop,node:dnd-add', this.
|
|
661
|
+
this.lf.off('node:add,node:drop,node:dnd-add', this.onNodeAddOrDrop);
|
|
662
|
+
this.lf.off('selection:drop', this.onSelectionDrop);
|
|
644
663
|
this.lf.off('node:delete', this.removeNodeFromGroup);
|
|
645
|
-
this.lf.off('node:drag,node:dnd-drag', this.
|
|
664
|
+
this.lf.off('node:drag,node:dnd-drag', this.onNodeDrag);
|
|
665
|
+
this.lf.off('selection:drag', this.onSelectionDrag);
|
|
646
666
|
this.lf.off('node:click', this.onNodeSelect);
|
|
647
667
|
this.lf.off('node:mousemove', this.onNodeMove);
|
|
648
668
|
this.lf.off('graph:rendered', this.onGraphRendered);
|