@logicflow/extension 1.0.0-alhpa.0 → 1.0.0-alpha.3
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/index.js +1 -0
- package/cjs/materials/node-selection/index.js +267 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/materials/node-selection/index.d.ts +29 -0
- package/es/materials/node-selection/index.js +264 -0
- package/lib/AutoLayout.js +1 -1
- package/lib/BpmnAdapter.js +1 -1
- package/lib/BpmnElement.js +1 -1
- package/lib/ContextMenu.js +1 -1
- package/lib/Control.js +1 -1
- package/lib/CurvedEdge.js +1 -1
- package/lib/DndPanel.js +1 -1
- package/lib/FlowPath.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/InsertNodeInPolyline.js +1 -1
- package/lib/Menu.js +1 -1
- package/lib/MiniMap.js +1 -1
- package/lib/NodeResize.js +1 -1
- package/lib/NodeSelection.js +10 -0
- 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/package.json +2 -2
- package/types/index.d.ts +1 -0
package/cjs/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./materials/group"), exports);
|
|
|
27
27
|
__exportStar(require("./NodeResize"), exports);
|
|
28
28
|
__exportStar(require("./tools/flow-path"), exports);
|
|
29
29
|
__exportStar(require("./tools/auto-layout"), exports);
|
|
30
|
+
__exportStar(require("./materials/node-selection"), exports);
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NodeSelection = void 0;
|
|
17
|
+
var lodash_es_1 = require("lodash-es");
|
|
18
|
+
var core_1 = require("@logicflow/core");
|
|
19
|
+
var NodeSelectionView = /** @class */ (function (_super) {
|
|
20
|
+
__extends(NodeSelectionView, _super);
|
|
21
|
+
function NodeSelectionView() {
|
|
22
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
_this.d = 10;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
NodeSelectionView.prototype.getShapeStyle = function () {
|
|
27
|
+
// 设置边框为虚线
|
|
28
|
+
var style = _super.prototype.getShapeStyle.call(this);
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
style.strokeDashArray = '10 5';
|
|
31
|
+
return style;
|
|
32
|
+
};
|
|
33
|
+
NodeSelectionView.prototype.getLabelShape = function () {
|
|
34
|
+
var attributes = _super.prototype.getAttributes.call(this);
|
|
35
|
+
var x = attributes.x, // 元素中心点
|
|
36
|
+
y = attributes.y, // 元素中心点
|
|
37
|
+
width = attributes.width, height = attributes.height, stroke = attributes.stroke, id = attributes.id, _a = attributes.properties, labelText = _a.label_text, disabledDelete = _a.disabled_delete;
|
|
38
|
+
return core_1.h('svg', {
|
|
39
|
+
x: x - width / 2,
|
|
40
|
+
y: y - height / 2,
|
|
41
|
+
style: 'z-index: 0; background: none; overflow: auto;',
|
|
42
|
+
}, labelText ? core_1.h('text', {
|
|
43
|
+
x: 0,
|
|
44
|
+
y: -5,
|
|
45
|
+
width: 50,
|
|
46
|
+
height: 24,
|
|
47
|
+
fontSize: '16px',
|
|
48
|
+
fill: stroke,
|
|
49
|
+
}, '方案') : '', disabledDelete ? '' : core_1.h('text', {
|
|
50
|
+
x: labelText ? 50 : 0,
|
|
51
|
+
y: -5,
|
|
52
|
+
width: 50,
|
|
53
|
+
height: 24,
|
|
54
|
+
fontSize: '24px',
|
|
55
|
+
cursor: 'pointer',
|
|
56
|
+
fill: stroke,
|
|
57
|
+
onclick: this.handleCustomDeleteIconClick.bind(this, id),
|
|
58
|
+
}, 'x'));
|
|
59
|
+
};
|
|
60
|
+
NodeSelectionView.prototype.getShape = function () {
|
|
61
|
+
var attributes = _super.prototype.getAttributes.call(this);
|
|
62
|
+
var x = attributes.x, // 元素中心点
|
|
63
|
+
y = attributes.y, // 元素中心点
|
|
64
|
+
width = attributes.width, height = attributes.height, fill = attributes.fill, stroke = attributes.stroke, strokeWidth = attributes.strokeWidth, strokeDashArray = attributes.strokeDashArray, id = attributes.id;
|
|
65
|
+
return core_1.h('g', {}, [
|
|
66
|
+
core_1.h('rect', {
|
|
67
|
+
x: x - width / 2,
|
|
68
|
+
y: y - height / 2,
|
|
69
|
+
fill: fill,
|
|
70
|
+
stroke: stroke,
|
|
71
|
+
strokeWidth: strokeWidth,
|
|
72
|
+
width: width,
|
|
73
|
+
height: height,
|
|
74
|
+
strokeDashArray: strokeDashArray,
|
|
75
|
+
id: id,
|
|
76
|
+
}),
|
|
77
|
+
this.getLabelShape(),
|
|
78
|
+
]);
|
|
79
|
+
};
|
|
80
|
+
NodeSelectionView.prototype.toFront = function () { };
|
|
81
|
+
/**
|
|
82
|
+
* 点击删除
|
|
83
|
+
* @param id
|
|
84
|
+
*/
|
|
85
|
+
NodeSelectionView.prototype.handleCustomDeleteIconClick = function (id) {
|
|
86
|
+
var graphModel = this.props.graphModel;
|
|
87
|
+
graphModel.deleteNode(id);
|
|
88
|
+
};
|
|
89
|
+
return NodeSelectionView;
|
|
90
|
+
}(core_1.PolygonNode));
|
|
91
|
+
var NodeSelectionModel = /** @class */ (function (_super) {
|
|
92
|
+
__extends(NodeSelectionModel, _super);
|
|
93
|
+
function NodeSelectionModel() {
|
|
94
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
95
|
+
_this.d = 10;
|
|
96
|
+
return _this;
|
|
97
|
+
}
|
|
98
|
+
NodeSelectionModel.prototype.setAttributes = function () {
|
|
99
|
+
var _this = this;
|
|
100
|
+
// 默认不显示
|
|
101
|
+
this.points = [];
|
|
102
|
+
this.text = {
|
|
103
|
+
value: '',
|
|
104
|
+
x: 0,
|
|
105
|
+
y: 0,
|
|
106
|
+
draggable: false,
|
|
107
|
+
editable: false,
|
|
108
|
+
};
|
|
109
|
+
this.stroke = this.properties.active_color || '#008000';
|
|
110
|
+
this.zIndex = 0;
|
|
111
|
+
this.draggable = false;
|
|
112
|
+
this.anchorsOffset = [[0, 0]];
|
|
113
|
+
if (this.properties.node_selection_ids.length > 1) {
|
|
114
|
+
setTimeout(function () {
|
|
115
|
+
_this.updatePointsByNodes(_this.properties.node_selection_ids);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
NodeSelectionModel.prototype.getAnchorsByOffset = function () {
|
|
120
|
+
return [];
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* 更新points
|
|
124
|
+
* @param points
|
|
125
|
+
*/
|
|
126
|
+
NodeSelectionModel.prototype.updatePoints = function (points) {
|
|
127
|
+
this.points = points;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* 更新x y
|
|
131
|
+
*/
|
|
132
|
+
NodeSelectionModel.prototype.updateCoordinate = function (_a) {
|
|
133
|
+
var x = _a.x, y = _a.y;
|
|
134
|
+
this.x = x;
|
|
135
|
+
this.y = y;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 更新points
|
|
139
|
+
*/
|
|
140
|
+
NodeSelectionModel.prototype.updatePointsByNodes = function (nodesIds) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
// TODO: 临时方案矩形
|
|
143
|
+
var points = [];
|
|
144
|
+
var minX = Infinity;
|
|
145
|
+
var minY = Infinity;
|
|
146
|
+
var maxX = -Infinity;
|
|
147
|
+
var maxY = -Infinity;
|
|
148
|
+
nodesIds.forEach(function (id) {
|
|
149
|
+
var model = _this.graphModel.getNodeModel(id);
|
|
150
|
+
if (!model)
|
|
151
|
+
return;
|
|
152
|
+
var width = model.width, height = model.height, x = model.x, y = model.y;
|
|
153
|
+
minX = Math.min(minX, x - width / 2 - _this.d);
|
|
154
|
+
minY = Math.min(minY, y - height / 2 - _this.d);
|
|
155
|
+
maxX = Math.max(maxX, x + width / 2 + _this.d);
|
|
156
|
+
maxY = Math.max(maxY, y + height / 2 + _this.d);
|
|
157
|
+
});
|
|
158
|
+
points.push([minX, minY], [maxX, minY], [maxX, maxY], [minX, maxY]);
|
|
159
|
+
if ([minX, minY, maxX, maxY].some(function (n) { return Math.abs(n) === Infinity; }))
|
|
160
|
+
return;
|
|
161
|
+
this.updatePoints(points);
|
|
162
|
+
this.updateCoordinate({ x: ((maxX + minX) / 2), y: (maxY + minY) / 2 });
|
|
163
|
+
};
|
|
164
|
+
return NodeSelectionModel;
|
|
165
|
+
}(core_1.PolygonNodeModel));
|
|
166
|
+
var NodeSelection = /** @class */ (function () {
|
|
167
|
+
function NodeSelection(_a) {
|
|
168
|
+
var lf = _a.lf;
|
|
169
|
+
this.lf = null; // lf 实例
|
|
170
|
+
this.selectNodes = []; // 选择的nodes
|
|
171
|
+
this.currentClickNode = null; // 当前点击的节点,选中的节点是无序的
|
|
172
|
+
this.d = 10;
|
|
173
|
+
lf.register({
|
|
174
|
+
type: 'node-selection',
|
|
175
|
+
view: NodeSelectionView,
|
|
176
|
+
model: NodeSelectionModel,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
Object.defineProperty(NodeSelection.prototype, "selectNodesIds", {
|
|
180
|
+
/**
|
|
181
|
+
* 获取所选node的id数组
|
|
182
|
+
*/
|
|
183
|
+
get: function () {
|
|
184
|
+
return this.selectNodes.map(function (node) { return node.id; });
|
|
185
|
+
},
|
|
186
|
+
enumerable: false,
|
|
187
|
+
configurable: true
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* 新建node-selection节点
|
|
191
|
+
*/
|
|
192
|
+
NodeSelection.prototype.addNodeSelection = function () {
|
|
193
|
+
var node = this.lf.addNode({
|
|
194
|
+
type: 'node-selection',
|
|
195
|
+
text: '',
|
|
196
|
+
properties: {
|
|
197
|
+
node_selection_ids: this.selectNodesIds,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
node.updatePointsByNodes(this.selectNodesIds);
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* 更新node-selection节点
|
|
204
|
+
*/
|
|
205
|
+
NodeSelection.prototype.updateNodeSelection = function () {
|
|
206
|
+
var nodeSelection = this.getNodeSelection();
|
|
207
|
+
if (!nodeSelection)
|
|
208
|
+
return;
|
|
209
|
+
this.lf.setProperties(nodeSelection.id, {
|
|
210
|
+
node_selection_ids: this.selectNodesIds,
|
|
211
|
+
});
|
|
212
|
+
this.lf.getNodeModel(nodeSelection.id).updatePointsByNodes(this.selectNodesIds);
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* 获取所属的node-selection
|
|
216
|
+
*/
|
|
217
|
+
NodeSelection.prototype.getNodeSelection = function () {
|
|
218
|
+
var _this = this;
|
|
219
|
+
var ids = this.selectNodesIds;
|
|
220
|
+
var rawData = this.lf.getGraphRawData();
|
|
221
|
+
var oldIds = ids.filter(function (id) { return id !== _this.currentClickNode.id; });
|
|
222
|
+
return rawData.nodes.find(function (node) {
|
|
223
|
+
if (node.type === 'node-selection') {
|
|
224
|
+
var nodeSelectionIds_1 = lodash_es_1.default.get(node, 'properties.node_selection_ids', []);
|
|
225
|
+
return oldIds.every(function (id) { return nodeSelectionIds_1.includes(id); });
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
NodeSelection.prototype.render = function (lf) {
|
|
231
|
+
var _this = this;
|
|
232
|
+
this.lf = lf;
|
|
233
|
+
lf.on('node:click', function (val) {
|
|
234
|
+
if (!val.e.shiftKey || val.data.type === 'node-selection')
|
|
235
|
+
return;
|
|
236
|
+
_this.currentClickNode = val.data;
|
|
237
|
+
// 如果selectNodesIds中已存在此节点,则取消选中此节点
|
|
238
|
+
var isUnSelected = false;
|
|
239
|
+
if (_this.selectNodesIds.includes(val.data.id)) {
|
|
240
|
+
_this.lf.getNodeModel(val.data.id).setSelected(false);
|
|
241
|
+
isUnSelected = true;
|
|
242
|
+
}
|
|
243
|
+
// 获取所有被选中的节点,获取到的数组是无序的
|
|
244
|
+
var nodes = lf.getSelectElements(true).nodes;
|
|
245
|
+
// 使用插件时判断是否允许使用node-selection
|
|
246
|
+
if (lf.disableNodeSelection && lf.disableNodeSelection(nodes)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
_this.selectNodes = nodes;
|
|
250
|
+
if (_this.selectNodes.length === 1) {
|
|
251
|
+
if (!isUnSelected) {
|
|
252
|
+
_this.addNodeSelection();
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
_this.updateNodeSelection();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
else if (_this.selectNodes.length > 1) {
|
|
259
|
+
_this.updateNodeSelection();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
NodeSelection.pluginName = 'node-selection';
|
|
264
|
+
return NodeSelection;
|
|
265
|
+
}());
|
|
266
|
+
exports.NodeSelection = NodeSelection;
|
|
267
|
+
exports.default = NodeSelection;
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare class NodeSelection {
|
|
2
|
+
static pluginName: string;
|
|
3
|
+
lf: any;
|
|
4
|
+
selectNodes: any[];
|
|
5
|
+
currentClickNode: any;
|
|
6
|
+
d: number;
|
|
7
|
+
constructor({ lf }: {
|
|
8
|
+
lf: any;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* 获取所选node的id数组
|
|
12
|
+
*/
|
|
13
|
+
get selectNodesIds(): any[];
|
|
14
|
+
/**
|
|
15
|
+
* 新建node-selection节点
|
|
16
|
+
*/
|
|
17
|
+
addNodeSelection(): void;
|
|
18
|
+
/**
|
|
19
|
+
* 更新node-selection节点
|
|
20
|
+
*/
|
|
21
|
+
updateNodeSelection(): void;
|
|
22
|
+
/**
|
|
23
|
+
* 获取所属的node-selection
|
|
24
|
+
*/
|
|
25
|
+
getNodeSelection(): any;
|
|
26
|
+
render(lf: any): void;
|
|
27
|
+
}
|
|
28
|
+
export default NodeSelection;
|
|
29
|
+
export { NodeSelection, };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import _ from 'lodash-es';
|
|
15
|
+
import { h, PolygonNode, PolygonNodeModel } from '@logicflow/core';
|
|
16
|
+
var NodeSelectionView = /** @class */ (function (_super) {
|
|
17
|
+
__extends(NodeSelectionView, _super);
|
|
18
|
+
function NodeSelectionView() {
|
|
19
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
20
|
+
_this.d = 10;
|
|
21
|
+
return _this;
|
|
22
|
+
}
|
|
23
|
+
NodeSelectionView.prototype.getShapeStyle = function () {
|
|
24
|
+
// 设置边框为虚线
|
|
25
|
+
var style = _super.prototype.getShapeStyle.call(this);
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
style.strokeDashArray = '10 5';
|
|
28
|
+
return style;
|
|
29
|
+
};
|
|
30
|
+
NodeSelectionView.prototype.getLabelShape = function () {
|
|
31
|
+
var attributes = _super.prototype.getAttributes.call(this);
|
|
32
|
+
var x = attributes.x, // 元素中心点
|
|
33
|
+
y = attributes.y, // 元素中心点
|
|
34
|
+
width = attributes.width, height = attributes.height, stroke = attributes.stroke, id = attributes.id, _a = attributes.properties, labelText = _a.label_text, disabledDelete = _a.disabled_delete;
|
|
35
|
+
return h('svg', {
|
|
36
|
+
x: x - width / 2,
|
|
37
|
+
y: y - height / 2,
|
|
38
|
+
style: 'z-index: 0; background: none; overflow: auto;',
|
|
39
|
+
}, labelText ? h('text', {
|
|
40
|
+
x: 0,
|
|
41
|
+
y: -5,
|
|
42
|
+
width: 50,
|
|
43
|
+
height: 24,
|
|
44
|
+
fontSize: '16px',
|
|
45
|
+
fill: stroke,
|
|
46
|
+
}, '方案') : '', disabledDelete ? '' : h('text', {
|
|
47
|
+
x: labelText ? 50 : 0,
|
|
48
|
+
y: -5,
|
|
49
|
+
width: 50,
|
|
50
|
+
height: 24,
|
|
51
|
+
fontSize: '24px',
|
|
52
|
+
cursor: 'pointer',
|
|
53
|
+
fill: stroke,
|
|
54
|
+
onclick: this.handleCustomDeleteIconClick.bind(this, id),
|
|
55
|
+
}, 'x'));
|
|
56
|
+
};
|
|
57
|
+
NodeSelectionView.prototype.getShape = function () {
|
|
58
|
+
var attributes = _super.prototype.getAttributes.call(this);
|
|
59
|
+
var x = attributes.x, // 元素中心点
|
|
60
|
+
y = attributes.y, // 元素中心点
|
|
61
|
+
width = attributes.width, height = attributes.height, fill = attributes.fill, stroke = attributes.stroke, strokeWidth = attributes.strokeWidth, strokeDashArray = attributes.strokeDashArray, id = attributes.id;
|
|
62
|
+
return h('g', {}, [
|
|
63
|
+
h('rect', {
|
|
64
|
+
x: x - width / 2,
|
|
65
|
+
y: y - height / 2,
|
|
66
|
+
fill: fill,
|
|
67
|
+
stroke: stroke,
|
|
68
|
+
strokeWidth: strokeWidth,
|
|
69
|
+
width: width,
|
|
70
|
+
height: height,
|
|
71
|
+
strokeDashArray: strokeDashArray,
|
|
72
|
+
id: id,
|
|
73
|
+
}),
|
|
74
|
+
this.getLabelShape(),
|
|
75
|
+
]);
|
|
76
|
+
};
|
|
77
|
+
NodeSelectionView.prototype.toFront = function () { };
|
|
78
|
+
/**
|
|
79
|
+
* 点击删除
|
|
80
|
+
* @param id
|
|
81
|
+
*/
|
|
82
|
+
NodeSelectionView.prototype.handleCustomDeleteIconClick = function (id) {
|
|
83
|
+
var graphModel = this.props.graphModel;
|
|
84
|
+
graphModel.deleteNode(id);
|
|
85
|
+
};
|
|
86
|
+
return NodeSelectionView;
|
|
87
|
+
}(PolygonNode));
|
|
88
|
+
var NodeSelectionModel = /** @class */ (function (_super) {
|
|
89
|
+
__extends(NodeSelectionModel, _super);
|
|
90
|
+
function NodeSelectionModel() {
|
|
91
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
92
|
+
_this.d = 10;
|
|
93
|
+
return _this;
|
|
94
|
+
}
|
|
95
|
+
NodeSelectionModel.prototype.setAttributes = function () {
|
|
96
|
+
var _this = this;
|
|
97
|
+
// 默认不显示
|
|
98
|
+
this.points = [];
|
|
99
|
+
this.text = {
|
|
100
|
+
value: '',
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0,
|
|
103
|
+
draggable: false,
|
|
104
|
+
editable: false,
|
|
105
|
+
};
|
|
106
|
+
this.stroke = this.properties.active_color || '#008000';
|
|
107
|
+
this.zIndex = 0;
|
|
108
|
+
this.draggable = false;
|
|
109
|
+
this.anchorsOffset = [[0, 0]];
|
|
110
|
+
if (this.properties.node_selection_ids.length > 1) {
|
|
111
|
+
setTimeout(function () {
|
|
112
|
+
_this.updatePointsByNodes(_this.properties.node_selection_ids);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
NodeSelectionModel.prototype.getAnchorsByOffset = function () {
|
|
117
|
+
return [];
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* 更新points
|
|
121
|
+
* @param points
|
|
122
|
+
*/
|
|
123
|
+
NodeSelectionModel.prototype.updatePoints = function (points) {
|
|
124
|
+
this.points = points;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* 更新x y
|
|
128
|
+
*/
|
|
129
|
+
NodeSelectionModel.prototype.updateCoordinate = function (_a) {
|
|
130
|
+
var x = _a.x, y = _a.y;
|
|
131
|
+
this.x = x;
|
|
132
|
+
this.y = y;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 更新points
|
|
136
|
+
*/
|
|
137
|
+
NodeSelectionModel.prototype.updatePointsByNodes = function (nodesIds) {
|
|
138
|
+
var _this = this;
|
|
139
|
+
// TODO: 临时方案矩形
|
|
140
|
+
var points = [];
|
|
141
|
+
var minX = Infinity;
|
|
142
|
+
var minY = Infinity;
|
|
143
|
+
var maxX = -Infinity;
|
|
144
|
+
var maxY = -Infinity;
|
|
145
|
+
nodesIds.forEach(function (id) {
|
|
146
|
+
var model = _this.graphModel.getNodeModel(id);
|
|
147
|
+
if (!model)
|
|
148
|
+
return;
|
|
149
|
+
var width = model.width, height = model.height, x = model.x, y = model.y;
|
|
150
|
+
minX = Math.min(minX, x - width / 2 - _this.d);
|
|
151
|
+
minY = Math.min(minY, y - height / 2 - _this.d);
|
|
152
|
+
maxX = Math.max(maxX, x + width / 2 + _this.d);
|
|
153
|
+
maxY = Math.max(maxY, y + height / 2 + _this.d);
|
|
154
|
+
});
|
|
155
|
+
points.push([minX, minY], [maxX, minY], [maxX, maxY], [minX, maxY]);
|
|
156
|
+
if ([minX, minY, maxX, maxY].some(function (n) { return Math.abs(n) === Infinity; }))
|
|
157
|
+
return;
|
|
158
|
+
this.updatePoints(points);
|
|
159
|
+
this.updateCoordinate({ x: ((maxX + minX) / 2), y: (maxY + minY) / 2 });
|
|
160
|
+
};
|
|
161
|
+
return NodeSelectionModel;
|
|
162
|
+
}(PolygonNodeModel));
|
|
163
|
+
var NodeSelection = /** @class */ (function () {
|
|
164
|
+
function NodeSelection(_a) {
|
|
165
|
+
var lf = _a.lf;
|
|
166
|
+
this.lf = null; // lf 实例
|
|
167
|
+
this.selectNodes = []; // 选择的nodes
|
|
168
|
+
this.currentClickNode = null; // 当前点击的节点,选中的节点是无序的
|
|
169
|
+
this.d = 10;
|
|
170
|
+
lf.register({
|
|
171
|
+
type: 'node-selection',
|
|
172
|
+
view: NodeSelectionView,
|
|
173
|
+
model: NodeSelectionModel,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
Object.defineProperty(NodeSelection.prototype, "selectNodesIds", {
|
|
177
|
+
/**
|
|
178
|
+
* 获取所选node的id数组
|
|
179
|
+
*/
|
|
180
|
+
get: function () {
|
|
181
|
+
return this.selectNodes.map(function (node) { return node.id; });
|
|
182
|
+
},
|
|
183
|
+
enumerable: false,
|
|
184
|
+
configurable: true
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* 新建node-selection节点
|
|
188
|
+
*/
|
|
189
|
+
NodeSelection.prototype.addNodeSelection = function () {
|
|
190
|
+
var node = this.lf.addNode({
|
|
191
|
+
type: 'node-selection',
|
|
192
|
+
text: '',
|
|
193
|
+
properties: {
|
|
194
|
+
node_selection_ids: this.selectNodesIds,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
node.updatePointsByNodes(this.selectNodesIds);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* 更新node-selection节点
|
|
201
|
+
*/
|
|
202
|
+
NodeSelection.prototype.updateNodeSelection = function () {
|
|
203
|
+
var nodeSelection = this.getNodeSelection();
|
|
204
|
+
if (!nodeSelection)
|
|
205
|
+
return;
|
|
206
|
+
this.lf.setProperties(nodeSelection.id, {
|
|
207
|
+
node_selection_ids: this.selectNodesIds,
|
|
208
|
+
});
|
|
209
|
+
this.lf.getNodeModel(nodeSelection.id).updatePointsByNodes(this.selectNodesIds);
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* 获取所属的node-selection
|
|
213
|
+
*/
|
|
214
|
+
NodeSelection.prototype.getNodeSelection = function () {
|
|
215
|
+
var _this = this;
|
|
216
|
+
var ids = this.selectNodesIds;
|
|
217
|
+
var rawData = this.lf.getGraphRawData();
|
|
218
|
+
var oldIds = ids.filter(function (id) { return id !== _this.currentClickNode.id; });
|
|
219
|
+
return rawData.nodes.find(function (node) {
|
|
220
|
+
if (node.type === 'node-selection') {
|
|
221
|
+
var nodeSelectionIds_1 = _.get(node, 'properties.node_selection_ids', []);
|
|
222
|
+
return oldIds.every(function (id) { return nodeSelectionIds_1.includes(id); });
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
NodeSelection.prototype.render = function (lf) {
|
|
228
|
+
var _this = this;
|
|
229
|
+
this.lf = lf;
|
|
230
|
+
lf.on('node:click', function (val) {
|
|
231
|
+
if (!val.e.shiftKey || val.data.type === 'node-selection')
|
|
232
|
+
return;
|
|
233
|
+
_this.currentClickNode = val.data;
|
|
234
|
+
// 如果selectNodesIds中已存在此节点,则取消选中此节点
|
|
235
|
+
var isUnSelected = false;
|
|
236
|
+
if (_this.selectNodesIds.includes(val.data.id)) {
|
|
237
|
+
_this.lf.getNodeModel(val.data.id).setSelected(false);
|
|
238
|
+
isUnSelected = true;
|
|
239
|
+
}
|
|
240
|
+
// 获取所有被选中的节点,获取到的数组是无序的
|
|
241
|
+
var nodes = lf.getSelectElements(true).nodes;
|
|
242
|
+
// 使用插件时判断是否允许使用node-selection
|
|
243
|
+
if (lf.disableNodeSelection && lf.disableNodeSelection(nodes)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
_this.selectNodes = nodes;
|
|
247
|
+
if (_this.selectNodes.length === 1) {
|
|
248
|
+
if (!isUnSelected) {
|
|
249
|
+
_this.addNodeSelection();
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
_this.updateNodeSelection();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (_this.selectNodes.length > 1) {
|
|
256
|
+
_this.updateNodeSelection();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
NodeSelection.pluginName = 'node-selection';
|
|
261
|
+
return NodeSelection;
|
|
262
|
+
}());
|
|
263
|
+
export default NodeSelection;
|
|
264
|
+
export { NodeSelection, };
|