@knotx/plugins-connection-line 0.2.13 → 0.2.14
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/dist/index.cjs +37 -88
- package/dist/index.d.cts +25 -44
- package/dist/index.d.mts +25 -44
- package/dist/index.d.ts +25 -44
- package/dist/index.js +38 -89
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -76,15 +76,14 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
|
|
|
76
76
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
77
77
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
78
78
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
79
|
-
var _destroy_dec, _init_dec, _createEdges_dec,
|
|
79
|
+
var _destroy_dec, _init_dec, _createEdges_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _selectedNodeIds_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
|
|
80
80
|
const DEFAULT_CONFIG = {
|
|
81
81
|
allowCreateNodeOnBlankArea: true,
|
|
82
|
-
newNodeType: "default",
|
|
83
82
|
edgeType: "bezier",
|
|
84
|
-
connectionLineClassName: "
|
|
83
|
+
connectionLineClassName: core.bem("connection-line", "line"),
|
|
85
84
|
allowMultiDrag: true
|
|
86
85
|
};
|
|
87
|
-
class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.inject.getNode()], _dispatchNodeOperation_dec = [decorators.inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [decorators.inject.dispatchEdgeOperation()], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _selectedNodeIds_dec = [decorators.inject
|
|
86
|
+
class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.inject.getNode()], _dispatchNodeOperation_dec = [decorators.inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [decorators.inject.dispatchEdgeOperation()], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _selectedNodeIds_dec = [decorators.inject.selection.selectedNodeIds()], _getConnectHandleAttributes_dec = [decorators.register("getConnectHandleAttributes")], _registerCreator_dec = [decorators.register("registerCreator")], _containerRender_dec = [decorators.layer(core.Layer.Nodes, 10)], _createNodeAndEdge_dec = [decorators.edgeOperator()], _createEdges_dec = [decorators.edgeOperator()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _a) {
|
|
88
87
|
constructor() {
|
|
89
88
|
super(...arguments);
|
|
90
89
|
__runInitializers(_init, 5, this);
|
|
@@ -96,12 +95,12 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
96
95
|
__publicField(this, "endInteraction", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
97
96
|
__publicField(this, "canInteract", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
|
|
98
97
|
__publicField(this, "selectedNodeIds", __runInitializers(_init, 32, this, [])), __runInitializers(_init, 35, this);
|
|
99
|
-
__publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 36, this, (nodeId, type,
|
|
98
|
+
__publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 36, this, ({ nodeId, type, index = 0, className = "" }) => {
|
|
100
99
|
return {
|
|
101
|
-
"className": `${this.classNames.connector} ${this.classNames[type]}`,
|
|
100
|
+
"className": `${className} ${this.classNames.connector} ${this.classNames[type]}`,
|
|
102
101
|
"data-plugin-id": this.pluginId,
|
|
103
102
|
"data-node-id": nodeId,
|
|
104
|
-
"data-connector-id": String(
|
|
103
|
+
"data-connector-id": String(index),
|
|
105
104
|
"data-connector-type": type
|
|
106
105
|
};
|
|
107
106
|
})), __runInitializers(_init, 39, this);
|
|
@@ -117,30 +116,13 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
117
116
|
__publicField(this, "startScale", 1);
|
|
118
117
|
// 用于存储当前触发拖拽事件的DOM元素对应的节点ID
|
|
119
118
|
__publicField(this, "currentDragNodeId", null);
|
|
120
|
-
// 各种订阅和交互对象
|
|
121
|
-
__publicField(this, "subscription");
|
|
122
119
|
__publicField(this, "dragInteractable");
|
|
123
120
|
__publicField(this, "dropInteractable");
|
|
124
121
|
__publicField(this, "blankAreaDropInteractable");
|
|
125
|
-
// 验证器列表
|
|
126
|
-
__publicField(this, "validators$", new rxjs.BehaviorSubject([]));
|
|
127
122
|
// 新节点创建器列表
|
|
128
123
|
__publicField(this, "creators$", new rxjs.BehaviorSubject([]));
|
|
129
|
-
__publicField(this, "config",
|
|
130
|
-
__publicField(this, "
|
|
131
|
-
const validators = this.validators$.value;
|
|
132
|
-
validators.push(validator);
|
|
133
|
-
this.validators$.next(validators);
|
|
134
|
-
return () => {
|
|
135
|
-
const currentValidators = this.validators$.value;
|
|
136
|
-
const index = currentValidators.indexOf(validator);
|
|
137
|
-
if (index > -1) {
|
|
138
|
-
currentValidators.splice(index, 1);
|
|
139
|
-
this.validators$.next(currentValidators);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
})), __runInitializers(_init, 47, this);
|
|
143
|
-
__publicField(this, "registerNewNodeCreator", __runInitializers(_init, 48, this, (creator) => {
|
|
124
|
+
__publicField(this, "config", DEFAULT_CONFIG);
|
|
125
|
+
__publicField(this, "registerCreator", __runInitializers(_init, 40, this, (creator) => {
|
|
144
126
|
const creators = this.creators$.value;
|
|
145
127
|
creators.push(creator);
|
|
146
128
|
this.creators$.next(creators);
|
|
@@ -152,7 +134,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
152
134
|
this.creators$.next(currentCreators);
|
|
153
135
|
}
|
|
154
136
|
};
|
|
155
|
-
})), __runInitializers(_init,
|
|
137
|
+
})), __runInitializers(_init, 43, this);
|
|
156
138
|
}
|
|
157
139
|
containerRender() {
|
|
158
140
|
const size = this.getContainerSize();
|
|
@@ -179,31 +161,6 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
179
161
|
getContainerSize() {
|
|
180
162
|
return 1;
|
|
181
163
|
}
|
|
182
|
-
/**
|
|
183
|
-
* 应用所有验证器,检查连接是否有效
|
|
184
|
-
*/
|
|
185
|
-
validateConnection(sourceNodeId, targetNodeId) {
|
|
186
|
-
const sourceNode = this.getNode(sourceNodeId);
|
|
187
|
-
if (!sourceNode)
|
|
188
|
-
return false;
|
|
189
|
-
let targetNode;
|
|
190
|
-
if (targetNodeId) {
|
|
191
|
-
targetNode = this.getNode(targetNodeId);
|
|
192
|
-
if (!targetNode)
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
const context = {
|
|
196
|
-
sourceNodeId,
|
|
197
|
-
sourceNode,
|
|
198
|
-
targetNodeId,
|
|
199
|
-
targetNode,
|
|
200
|
-
isValid: true
|
|
201
|
-
};
|
|
202
|
-
return this.validators$.value.reduce(
|
|
203
|
-
(isValid, validator) => isValid && validator(context),
|
|
204
|
-
true
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
164
|
getContainerElement() {
|
|
208
165
|
return document.querySelector(`.${core.bem("connection-line", "container")}[data-plugin-id="${this.pluginId}"]`);
|
|
209
166
|
}
|
|
@@ -222,7 +179,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
222
179
|
*/
|
|
223
180
|
createConnectionLine(sourceNodeId, startPosition) {
|
|
224
181
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
225
|
-
svg.setAttribute("class", `${this.config.connectionLineClassName
|
|
182
|
+
svg.setAttribute("class", `${this.config.connectionLineClassName} line-${sourceNodeId}`);
|
|
226
183
|
svg.style.position = "absolute";
|
|
227
184
|
svg.style.top = "0";
|
|
228
185
|
svg.style.left = "0";
|
|
@@ -298,7 +255,6 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
298
255
|
const newNodeId = core.generateId();
|
|
299
256
|
const newNode = {
|
|
300
257
|
id: newNodeId,
|
|
301
|
-
type: this.config.newNodeType,
|
|
302
258
|
position,
|
|
303
259
|
data: {}
|
|
304
260
|
};
|
|
@@ -310,14 +266,21 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
310
266
|
}));
|
|
311
267
|
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
312
268
|
var _a2;
|
|
313
|
-
return (_a2 = creator(
|
|
314
|
-
|
|
269
|
+
return (_a2 = creator({
|
|
270
|
+
sourceNodeIds,
|
|
271
|
+
targetNodeId: void 0,
|
|
272
|
+
targetPosition: position
|
|
273
|
+
})) != null ? _a2 : result;
|
|
274
|
+
}, {
|
|
275
|
+
nodes: [newNode],
|
|
276
|
+
edges: newEdges
|
|
277
|
+
});
|
|
315
278
|
if (createResult === false) {
|
|
316
279
|
return [];
|
|
317
280
|
}
|
|
318
281
|
this.dispatchNodeOperation({
|
|
319
|
-
type: "
|
|
320
|
-
|
|
282
|
+
type: "batch",
|
|
283
|
+
operations: createResult.nodes.map((node) => ({ type: "add", data: node }))
|
|
321
284
|
});
|
|
322
285
|
return [{
|
|
323
286
|
type: "batch",
|
|
@@ -327,31 +290,26 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
327
290
|
}))
|
|
328
291
|
}];
|
|
329
292
|
}
|
|
330
|
-
createEdge(sourceNodeId, targetNodeId) {
|
|
331
|
-
return [{
|
|
332
|
-
type: "add",
|
|
333
|
-
data: {
|
|
334
|
-
id: core.generateId(),
|
|
335
|
-
source: sourceNodeId,
|
|
336
|
-
target: targetNodeId,
|
|
337
|
-
type: this.config.edgeType
|
|
338
|
-
}
|
|
339
|
-
}];
|
|
340
|
-
}
|
|
341
293
|
createEdges(sourceNodeIds, targetNodeId) {
|
|
342
294
|
if (sourceNodeIds.length === 0 || !targetNodeId) {
|
|
343
295
|
return [];
|
|
344
296
|
}
|
|
297
|
+
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
298
|
+
var _a2;
|
|
299
|
+
return (_a2 = creator({
|
|
300
|
+
sourceNodeIds,
|
|
301
|
+
targetNodeId,
|
|
302
|
+
targetPosition: void 0
|
|
303
|
+
})) != null ? _a2 : result;
|
|
304
|
+
}, { edges: [] });
|
|
305
|
+
if (createResult === false || createResult.edges.length === 0) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
345
308
|
return [{
|
|
346
309
|
type: "batch",
|
|
347
|
-
operations:
|
|
310
|
+
operations: createResult.edges.map((edge) => ({
|
|
348
311
|
type: "add",
|
|
349
|
-
data:
|
|
350
|
-
id: core.generateId(),
|
|
351
|
-
source: sourceNodeId,
|
|
352
|
-
target: targetNodeId,
|
|
353
|
-
type: this.config.edgeType
|
|
354
|
-
}
|
|
312
|
+
data: edge
|
|
355
313
|
}))
|
|
356
314
|
}];
|
|
357
315
|
}
|
|
@@ -434,12 +392,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
434
392
|
const sourceNodeIds = Array.from(this.connectionLines.keys()).filter((id) => id !== targetNodeId);
|
|
435
393
|
if (sourceNodeIds.length === 0)
|
|
436
394
|
return;
|
|
437
|
-
|
|
438
|
-
(sourceNodeId) => this.validateConnection(sourceNodeId, targetNodeId)
|
|
439
|
-
);
|
|
440
|
-
if (validSourceNodeIds.length > 0) {
|
|
441
|
-
this.createEdges(validSourceNodeIds, targetNodeId);
|
|
442
|
-
}
|
|
395
|
+
this.createEdges(sourceNodeIds, targetNodeId);
|
|
443
396
|
event.target.classList.remove(this.classNames.active);
|
|
444
397
|
}
|
|
445
398
|
});
|
|
@@ -460,18 +413,16 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
460
413
|
}
|
|
461
414
|
}
|
|
462
415
|
destroy() {
|
|
463
|
-
var _a2, _b, _c
|
|
416
|
+
var _a2, _b, _c;
|
|
464
417
|
(_a2 = this.dragInteractable) == null ? void 0 : _a2.unset();
|
|
465
418
|
(_b = this.dropInteractable) == null ? void 0 : _b.unset();
|
|
466
419
|
(_c = this.blankAreaDropInteractable) == null ? void 0 : _c.unset();
|
|
467
420
|
this.clearAllConnectionLines();
|
|
468
|
-
(_d = this.subscription) == null ? void 0 : _d.unsubscribe();
|
|
469
421
|
}
|
|
470
422
|
}
|
|
471
423
|
_init = __decoratorStart(_a);
|
|
472
424
|
__decorateElement(_init, 1, "containerRender", _containerRender_dec, ConnectionLine);
|
|
473
425
|
__decorateElement(_init, 1, "createNodeAndEdge", _createNodeAndEdge_dec, ConnectionLine);
|
|
474
|
-
__decorateElement(_init, 1, "createEdge", _createEdge_dec, ConnectionLine);
|
|
475
426
|
__decorateElement(_init, 1, "createEdges", _createEdges_dec, ConnectionLine);
|
|
476
427
|
__decorateElement(_init, 1, "init", _init_dec, ConnectionLine);
|
|
477
428
|
__decorateElement(_init, 1, "destroy", _destroy_dec, ConnectionLine);
|
|
@@ -483,9 +434,7 @@ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, ConnectionLin
|
|
|
483
434
|
__decorateElement(_init, 5, "canInteract", _canInteract_dec, ConnectionLine);
|
|
484
435
|
__decorateElement(_init, 5, "selectedNodeIds", _selectedNodeIds_dec, ConnectionLine);
|
|
485
436
|
__decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
|
|
486
|
-
__decorateElement(_init, 5, "
|
|
487
|
-
__decorateElement(_init, 5, "registerValidator", _registerValidator_dec, ConnectionLine);
|
|
488
|
-
__decorateElement(_init, 5, "registerNewNodeCreator", _registerNewNodeCreator_dec, ConnectionLine);
|
|
437
|
+
__decorateElement(_init, 5, "registerCreator", _registerCreator_dec, ConnectionLine);
|
|
489
438
|
__decoratorMetadata(_init, ConnectionLine);
|
|
490
439
|
|
|
491
440
|
exports.ConnectionLine = ConnectionLine;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
1
|
+
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority, PluginData } from '@knotx/core';
|
|
2
2
|
|
|
3
3
|
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
@@ -6,11 +6,6 @@ interface ConnectionLineConfig {
|
|
|
6
6
|
* @default false
|
|
7
7
|
*/
|
|
8
8
|
allowCreateNodeOnBlankArea?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* 当连接到画布空白处时创建的节点类型
|
|
11
|
-
* @default 'default'
|
|
12
|
-
*/
|
|
13
|
-
newNodeType?: string;
|
|
14
9
|
/**
|
|
15
10
|
* 新创建的边的类型
|
|
16
11
|
* @default 'bezier'
|
|
@@ -18,7 +13,6 @@ interface ConnectionLineConfig {
|
|
|
18
13
|
edgeType?: string;
|
|
19
14
|
/**
|
|
20
15
|
* 临时连接线的类名
|
|
21
|
-
* @default 'knotx-connection-line'
|
|
22
16
|
*/
|
|
23
17
|
connectionLineClassName?: string;
|
|
24
18
|
/**
|
|
@@ -27,23 +21,25 @@ interface ConnectionLineConfig {
|
|
|
27
21
|
*/
|
|
28
22
|
allowMultiDrag?: boolean;
|
|
29
23
|
}
|
|
30
|
-
interface ConnectionValidateContext {
|
|
31
|
-
sourceNodeId: string;
|
|
32
|
-
sourceNode: Node;
|
|
33
|
-
targetNodeId?: string;
|
|
34
|
-
targetNode?: Node;
|
|
35
|
-
isValid: boolean;
|
|
36
|
-
}
|
|
37
|
-
type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
38
24
|
declare module '@knotx/core' {
|
|
39
25
|
interface PluginData {
|
|
40
26
|
connectionLine: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 注册新节点创建器
|
|
29
|
+
* @param creator 新节点创建器
|
|
30
|
+
* @returns 取消注册的函数, 如果创建器返回 false, 则不会创建节点和边, 如果返回 undefined, 则使用默认的创建逻辑
|
|
31
|
+
*/
|
|
32
|
+
registerCreator: (creator: (params: {
|
|
33
|
+
sourceNodeIds: string[];
|
|
34
|
+
targetNodeId: string | undefined;
|
|
35
|
+
targetPosition: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}) => ({
|
|
40
|
+
nodes: Node[];
|
|
45
41
|
edges: Edge[];
|
|
46
|
-
}) | false) => () => void;
|
|
42
|
+
}) | undefined | false) => () => void;
|
|
47
43
|
/**
|
|
48
44
|
* 获取连接点的属性
|
|
49
45
|
* @param nodeId 节点ID
|
|
@@ -51,7 +47,12 @@ declare module '@knotx/core' {
|
|
|
51
47
|
* @param index 连接点索引,多个连接点时使用
|
|
52
48
|
* @returns 连接点属性对象
|
|
53
49
|
*/
|
|
54
|
-
getConnectHandleAttributes: (
|
|
50
|
+
getConnectHandleAttributes: (params: {
|
|
51
|
+
nodeId: string;
|
|
52
|
+
type: 'source' | 'target';
|
|
53
|
+
index?: number;
|
|
54
|
+
className?: string;
|
|
55
|
+
}) => Record<string, string>;
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -68,38 +69,22 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
68
69
|
endInteraction: (pluginId: string, type: string) => void;
|
|
69
70
|
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
70
71
|
selectedNodeIds: string[];
|
|
71
|
-
getConnectHandleAttributes:
|
|
72
|
-
className: string;
|
|
73
|
-
'data-plugin-id': string;
|
|
74
|
-
'data-node-id': string;
|
|
75
|
-
'data-connector-id': string;
|
|
76
|
-
'data-connector-type': "source" | "target";
|
|
77
|
-
};
|
|
72
|
+
getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
|
|
78
73
|
private classNames;
|
|
79
74
|
private connectionLines;
|
|
80
75
|
private startScale;
|
|
81
76
|
private currentDragNodeId;
|
|
82
|
-
private subscription?;
|
|
83
77
|
private dragInteractable?;
|
|
84
78
|
private dropInteractable?;
|
|
85
79
|
private blankAreaDropInteractable?;
|
|
86
|
-
private validators$;
|
|
87
80
|
private creators$;
|
|
88
81
|
config: ConnectionLineConfig;
|
|
89
|
-
|
|
90
|
-
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: Node, edges: Edge[]) => ({
|
|
91
|
-
node: Node;
|
|
92
|
-
edges: Edge[];
|
|
93
|
-
}) | false) => () => void;
|
|
82
|
+
registerCreator: PluginData['connectionLine']['registerCreator'];
|
|
94
83
|
containerRender(): JSX.Element;
|
|
95
84
|
/**
|
|
96
85
|
* 获取容器大小
|
|
97
86
|
*/
|
|
98
87
|
private getContainerSize;
|
|
99
|
-
/**
|
|
100
|
-
* 应用所有验证器,检查连接是否有效
|
|
101
|
-
*/
|
|
102
|
-
private validateConnection;
|
|
103
88
|
private getContainerElement;
|
|
104
89
|
/**
|
|
105
90
|
* 获取需要为其创建连接线的源节点ID列表
|
|
@@ -129,10 +114,6 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
129
114
|
x: number;
|
|
130
115
|
y: number;
|
|
131
116
|
}): EdgeOperation[];
|
|
132
|
-
/**
|
|
133
|
-
* 创建新的边
|
|
134
|
-
*/
|
|
135
|
-
createEdge(sourceNodeId: string, targetNodeId: string): EdgeOperation[];
|
|
136
117
|
/**
|
|
137
118
|
* 批量创建新的边
|
|
138
119
|
*/
|
|
@@ -141,4 +122,4 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
141
122
|
destroy(): void;
|
|
142
123
|
}
|
|
143
124
|
|
|
144
|
-
export { ConnectionLine, type ConnectionLineConfig
|
|
125
|
+
export { ConnectionLine, type ConnectionLineConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
1
|
+
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority, PluginData } from '@knotx/core';
|
|
2
2
|
|
|
3
3
|
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
@@ -6,11 +6,6 @@ interface ConnectionLineConfig {
|
|
|
6
6
|
* @default false
|
|
7
7
|
*/
|
|
8
8
|
allowCreateNodeOnBlankArea?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* 当连接到画布空白处时创建的节点类型
|
|
11
|
-
* @default 'default'
|
|
12
|
-
*/
|
|
13
|
-
newNodeType?: string;
|
|
14
9
|
/**
|
|
15
10
|
* 新创建的边的类型
|
|
16
11
|
* @default 'bezier'
|
|
@@ -18,7 +13,6 @@ interface ConnectionLineConfig {
|
|
|
18
13
|
edgeType?: string;
|
|
19
14
|
/**
|
|
20
15
|
* 临时连接线的类名
|
|
21
|
-
* @default 'knotx-connection-line'
|
|
22
16
|
*/
|
|
23
17
|
connectionLineClassName?: string;
|
|
24
18
|
/**
|
|
@@ -27,23 +21,25 @@ interface ConnectionLineConfig {
|
|
|
27
21
|
*/
|
|
28
22
|
allowMultiDrag?: boolean;
|
|
29
23
|
}
|
|
30
|
-
interface ConnectionValidateContext {
|
|
31
|
-
sourceNodeId: string;
|
|
32
|
-
sourceNode: Node;
|
|
33
|
-
targetNodeId?: string;
|
|
34
|
-
targetNode?: Node;
|
|
35
|
-
isValid: boolean;
|
|
36
|
-
}
|
|
37
|
-
type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
38
24
|
declare module '@knotx/core' {
|
|
39
25
|
interface PluginData {
|
|
40
26
|
connectionLine: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 注册新节点创建器
|
|
29
|
+
* @param creator 新节点创建器
|
|
30
|
+
* @returns 取消注册的函数, 如果创建器返回 false, 则不会创建节点和边, 如果返回 undefined, 则使用默认的创建逻辑
|
|
31
|
+
*/
|
|
32
|
+
registerCreator: (creator: (params: {
|
|
33
|
+
sourceNodeIds: string[];
|
|
34
|
+
targetNodeId: string | undefined;
|
|
35
|
+
targetPosition: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}) => ({
|
|
40
|
+
nodes: Node[];
|
|
45
41
|
edges: Edge[];
|
|
46
|
-
}) | false) => () => void;
|
|
42
|
+
}) | undefined | false) => () => void;
|
|
47
43
|
/**
|
|
48
44
|
* 获取连接点的属性
|
|
49
45
|
* @param nodeId 节点ID
|
|
@@ -51,7 +47,12 @@ declare module '@knotx/core' {
|
|
|
51
47
|
* @param index 连接点索引,多个连接点时使用
|
|
52
48
|
* @returns 连接点属性对象
|
|
53
49
|
*/
|
|
54
|
-
getConnectHandleAttributes: (
|
|
50
|
+
getConnectHandleAttributes: (params: {
|
|
51
|
+
nodeId: string;
|
|
52
|
+
type: 'source' | 'target';
|
|
53
|
+
index?: number;
|
|
54
|
+
className?: string;
|
|
55
|
+
}) => Record<string, string>;
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -68,38 +69,22 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
68
69
|
endInteraction: (pluginId: string, type: string) => void;
|
|
69
70
|
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
70
71
|
selectedNodeIds: string[];
|
|
71
|
-
getConnectHandleAttributes:
|
|
72
|
-
className: string;
|
|
73
|
-
'data-plugin-id': string;
|
|
74
|
-
'data-node-id': string;
|
|
75
|
-
'data-connector-id': string;
|
|
76
|
-
'data-connector-type': "source" | "target";
|
|
77
|
-
};
|
|
72
|
+
getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
|
|
78
73
|
private classNames;
|
|
79
74
|
private connectionLines;
|
|
80
75
|
private startScale;
|
|
81
76
|
private currentDragNodeId;
|
|
82
|
-
private subscription?;
|
|
83
77
|
private dragInteractable?;
|
|
84
78
|
private dropInteractable?;
|
|
85
79
|
private blankAreaDropInteractable?;
|
|
86
|
-
private validators$;
|
|
87
80
|
private creators$;
|
|
88
81
|
config: ConnectionLineConfig;
|
|
89
|
-
|
|
90
|
-
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: Node, edges: Edge[]) => ({
|
|
91
|
-
node: Node;
|
|
92
|
-
edges: Edge[];
|
|
93
|
-
}) | false) => () => void;
|
|
82
|
+
registerCreator: PluginData['connectionLine']['registerCreator'];
|
|
94
83
|
containerRender(): JSX.Element;
|
|
95
84
|
/**
|
|
96
85
|
* 获取容器大小
|
|
97
86
|
*/
|
|
98
87
|
private getContainerSize;
|
|
99
|
-
/**
|
|
100
|
-
* 应用所有验证器,检查连接是否有效
|
|
101
|
-
*/
|
|
102
|
-
private validateConnection;
|
|
103
88
|
private getContainerElement;
|
|
104
89
|
/**
|
|
105
90
|
* 获取需要为其创建连接线的源节点ID列表
|
|
@@ -129,10 +114,6 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
129
114
|
x: number;
|
|
130
115
|
y: number;
|
|
131
116
|
}): EdgeOperation[];
|
|
132
|
-
/**
|
|
133
|
-
* 创建新的边
|
|
134
|
-
*/
|
|
135
|
-
createEdge(sourceNodeId: string, targetNodeId: string): EdgeOperation[];
|
|
136
117
|
/**
|
|
137
118
|
* 批量创建新的边
|
|
138
119
|
*/
|
|
@@ -141,4 +122,4 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
141
122
|
destroy(): void;
|
|
142
123
|
}
|
|
143
124
|
|
|
144
|
-
export { ConnectionLine, type ConnectionLineConfig
|
|
125
|
+
export { ConnectionLine, type ConnectionLineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
1
|
+
import { Node, Edge, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority, PluginData } from '@knotx/core';
|
|
2
2
|
|
|
3
3
|
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
@@ -6,11 +6,6 @@ interface ConnectionLineConfig {
|
|
|
6
6
|
* @default false
|
|
7
7
|
*/
|
|
8
8
|
allowCreateNodeOnBlankArea?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* 当连接到画布空白处时创建的节点类型
|
|
11
|
-
* @default 'default'
|
|
12
|
-
*/
|
|
13
|
-
newNodeType?: string;
|
|
14
9
|
/**
|
|
15
10
|
* 新创建的边的类型
|
|
16
11
|
* @default 'bezier'
|
|
@@ -18,7 +13,6 @@ interface ConnectionLineConfig {
|
|
|
18
13
|
edgeType?: string;
|
|
19
14
|
/**
|
|
20
15
|
* 临时连接线的类名
|
|
21
|
-
* @default 'knotx-connection-line'
|
|
22
16
|
*/
|
|
23
17
|
connectionLineClassName?: string;
|
|
24
18
|
/**
|
|
@@ -27,23 +21,25 @@ interface ConnectionLineConfig {
|
|
|
27
21
|
*/
|
|
28
22
|
allowMultiDrag?: boolean;
|
|
29
23
|
}
|
|
30
|
-
interface ConnectionValidateContext {
|
|
31
|
-
sourceNodeId: string;
|
|
32
|
-
sourceNode: Node;
|
|
33
|
-
targetNodeId?: string;
|
|
34
|
-
targetNode?: Node;
|
|
35
|
-
isValid: boolean;
|
|
36
|
-
}
|
|
37
|
-
type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
38
24
|
declare module '@knotx/core' {
|
|
39
25
|
interface PluginData {
|
|
40
26
|
connectionLine: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 注册新节点创建器
|
|
29
|
+
* @param creator 新节点创建器
|
|
30
|
+
* @returns 取消注册的函数, 如果创建器返回 false, 则不会创建节点和边, 如果返回 undefined, 则使用默认的创建逻辑
|
|
31
|
+
*/
|
|
32
|
+
registerCreator: (creator: (params: {
|
|
33
|
+
sourceNodeIds: string[];
|
|
34
|
+
targetNodeId: string | undefined;
|
|
35
|
+
targetPosition: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}) => ({
|
|
40
|
+
nodes: Node[];
|
|
45
41
|
edges: Edge[];
|
|
46
|
-
}) | false) => () => void;
|
|
42
|
+
}) | undefined | false) => () => void;
|
|
47
43
|
/**
|
|
48
44
|
* 获取连接点的属性
|
|
49
45
|
* @param nodeId 节点ID
|
|
@@ -51,7 +47,12 @@ declare module '@knotx/core' {
|
|
|
51
47
|
* @param index 连接点索引,多个连接点时使用
|
|
52
48
|
* @returns 连接点属性对象
|
|
53
49
|
*/
|
|
54
|
-
getConnectHandleAttributes: (
|
|
50
|
+
getConnectHandleAttributes: (params: {
|
|
51
|
+
nodeId: string;
|
|
52
|
+
type: 'source' | 'target';
|
|
53
|
+
index?: number;
|
|
54
|
+
className?: string;
|
|
55
|
+
}) => Record<string, string>;
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -68,38 +69,22 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
68
69
|
endInteraction: (pluginId: string, type: string) => void;
|
|
69
70
|
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
70
71
|
selectedNodeIds: string[];
|
|
71
|
-
getConnectHandleAttributes:
|
|
72
|
-
className: string;
|
|
73
|
-
'data-plugin-id': string;
|
|
74
|
-
'data-node-id': string;
|
|
75
|
-
'data-connector-id': string;
|
|
76
|
-
'data-connector-type': "source" | "target";
|
|
77
|
-
};
|
|
72
|
+
getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
|
|
78
73
|
private classNames;
|
|
79
74
|
private connectionLines;
|
|
80
75
|
private startScale;
|
|
81
76
|
private currentDragNodeId;
|
|
82
|
-
private subscription?;
|
|
83
77
|
private dragInteractable?;
|
|
84
78
|
private dropInteractable?;
|
|
85
79
|
private blankAreaDropInteractable?;
|
|
86
|
-
private validators$;
|
|
87
80
|
private creators$;
|
|
88
81
|
config: ConnectionLineConfig;
|
|
89
|
-
|
|
90
|
-
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: Node, edges: Edge[]) => ({
|
|
91
|
-
node: Node;
|
|
92
|
-
edges: Edge[];
|
|
93
|
-
}) | false) => () => void;
|
|
82
|
+
registerCreator: PluginData['connectionLine']['registerCreator'];
|
|
94
83
|
containerRender(): JSX.Element;
|
|
95
84
|
/**
|
|
96
85
|
* 获取容器大小
|
|
97
86
|
*/
|
|
98
87
|
private getContainerSize;
|
|
99
|
-
/**
|
|
100
|
-
* 应用所有验证器,检查连接是否有效
|
|
101
|
-
*/
|
|
102
|
-
private validateConnection;
|
|
103
88
|
private getContainerElement;
|
|
104
89
|
/**
|
|
105
90
|
* 获取需要为其创建连接线的源节点ID列表
|
|
@@ -129,10 +114,6 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
129
114
|
x: number;
|
|
130
115
|
y: number;
|
|
131
116
|
}): EdgeOperation[];
|
|
132
|
-
/**
|
|
133
|
-
* 创建新的边
|
|
134
|
-
*/
|
|
135
|
-
createEdge(sourceNodeId: string, targetNodeId: string): EdgeOperation[];
|
|
136
117
|
/**
|
|
137
118
|
* 批量创建新的边
|
|
138
119
|
*/
|
|
@@ -141,4 +122,4 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
|
|
|
141
122
|
destroy(): void;
|
|
142
123
|
}
|
|
143
124
|
|
|
144
|
-
export { ConnectionLine, type ConnectionLineConfig
|
|
125
|
+
export { ConnectionLine, type ConnectionLineConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from '@knotx/jsx/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { bem, Layer, generateId, InteractionPriority, BasePlugin } from '@knotx/core';
|
|
3
3
|
import { inject, register, layer, edgeOperator, OnInit, OnDestroy } from '@knotx/decorators';
|
|
4
4
|
import interact from 'interactjs';
|
|
5
5
|
import { merge } from 'lodash-es';
|
|
@@ -70,15 +70,14 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
|
|
|
70
70
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
71
71
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
72
72
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
73
|
-
var _destroy_dec, _init_dec, _createEdges_dec,
|
|
73
|
+
var _destroy_dec, _init_dec, _createEdges_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _selectedNodeIds_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
|
|
74
74
|
const DEFAULT_CONFIG = {
|
|
75
75
|
allowCreateNodeOnBlankArea: true,
|
|
76
|
-
newNodeType: "default",
|
|
77
76
|
edgeType: "bezier",
|
|
78
|
-
connectionLineClassName: "
|
|
77
|
+
connectionLineClassName: bem("connection-line", "line"),
|
|
79
78
|
allowMultiDrag: true
|
|
80
79
|
};
|
|
81
|
-
class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [inject.dispatchEdgeOperation()], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _selectedNodeIds_dec = [inject
|
|
80
|
+
class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [inject.dispatchEdgeOperation()], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _selectedNodeIds_dec = [inject.selection.selectedNodeIds()], _getConnectHandleAttributes_dec = [register("getConnectHandleAttributes")], _registerCreator_dec = [register("registerCreator")], _containerRender_dec = [layer(Layer.Nodes, 10)], _createNodeAndEdge_dec = [edgeOperator()], _createEdges_dec = [edgeOperator()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _a) {
|
|
82
81
|
constructor() {
|
|
83
82
|
super(...arguments);
|
|
84
83
|
__runInitializers(_init, 5, this);
|
|
@@ -90,12 +89,12 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
90
89
|
__publicField(this, "endInteraction", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
91
90
|
__publicField(this, "canInteract", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
|
|
92
91
|
__publicField(this, "selectedNodeIds", __runInitializers(_init, 32, this, [])), __runInitializers(_init, 35, this);
|
|
93
|
-
__publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 36, this, (nodeId, type,
|
|
92
|
+
__publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 36, this, ({ nodeId, type, index = 0, className = "" }) => {
|
|
94
93
|
return {
|
|
95
|
-
"className": `${this.classNames.connector} ${this.classNames[type]}`,
|
|
94
|
+
"className": `${className} ${this.classNames.connector} ${this.classNames[type]}`,
|
|
96
95
|
"data-plugin-id": this.pluginId,
|
|
97
96
|
"data-node-id": nodeId,
|
|
98
|
-
"data-connector-id": String(
|
|
97
|
+
"data-connector-id": String(index),
|
|
99
98
|
"data-connector-type": type
|
|
100
99
|
};
|
|
101
100
|
})), __runInitializers(_init, 39, this);
|
|
@@ -111,30 +110,13 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
111
110
|
__publicField(this, "startScale", 1);
|
|
112
111
|
// 用于存储当前触发拖拽事件的DOM元素对应的节点ID
|
|
113
112
|
__publicField(this, "currentDragNodeId", null);
|
|
114
|
-
// 各种订阅和交互对象
|
|
115
|
-
__publicField(this, "subscription");
|
|
116
113
|
__publicField(this, "dragInteractable");
|
|
117
114
|
__publicField(this, "dropInteractable");
|
|
118
115
|
__publicField(this, "blankAreaDropInteractable");
|
|
119
|
-
// 验证器列表
|
|
120
|
-
__publicField(this, "validators$", new BehaviorSubject([]));
|
|
121
116
|
// 新节点创建器列表
|
|
122
117
|
__publicField(this, "creators$", new BehaviorSubject([]));
|
|
123
|
-
__publicField(this, "config",
|
|
124
|
-
__publicField(this, "
|
|
125
|
-
const validators = this.validators$.value;
|
|
126
|
-
validators.push(validator);
|
|
127
|
-
this.validators$.next(validators);
|
|
128
|
-
return () => {
|
|
129
|
-
const currentValidators = this.validators$.value;
|
|
130
|
-
const index = currentValidators.indexOf(validator);
|
|
131
|
-
if (index > -1) {
|
|
132
|
-
currentValidators.splice(index, 1);
|
|
133
|
-
this.validators$.next(currentValidators);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
})), __runInitializers(_init, 47, this);
|
|
137
|
-
__publicField(this, "registerNewNodeCreator", __runInitializers(_init, 48, this, (creator) => {
|
|
118
|
+
__publicField(this, "config", DEFAULT_CONFIG);
|
|
119
|
+
__publicField(this, "registerCreator", __runInitializers(_init, 40, this, (creator) => {
|
|
138
120
|
const creators = this.creators$.value;
|
|
139
121
|
creators.push(creator);
|
|
140
122
|
this.creators$.next(creators);
|
|
@@ -146,7 +128,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
146
128
|
this.creators$.next(currentCreators);
|
|
147
129
|
}
|
|
148
130
|
};
|
|
149
|
-
})), __runInitializers(_init,
|
|
131
|
+
})), __runInitializers(_init, 43, this);
|
|
150
132
|
}
|
|
151
133
|
containerRender() {
|
|
152
134
|
const size = this.getContainerSize();
|
|
@@ -173,31 +155,6 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
173
155
|
getContainerSize() {
|
|
174
156
|
return 1;
|
|
175
157
|
}
|
|
176
|
-
/**
|
|
177
|
-
* 应用所有验证器,检查连接是否有效
|
|
178
|
-
*/
|
|
179
|
-
validateConnection(sourceNodeId, targetNodeId) {
|
|
180
|
-
const sourceNode = this.getNode(sourceNodeId);
|
|
181
|
-
if (!sourceNode)
|
|
182
|
-
return false;
|
|
183
|
-
let targetNode;
|
|
184
|
-
if (targetNodeId) {
|
|
185
|
-
targetNode = this.getNode(targetNodeId);
|
|
186
|
-
if (!targetNode)
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
const context = {
|
|
190
|
-
sourceNodeId,
|
|
191
|
-
sourceNode,
|
|
192
|
-
targetNodeId,
|
|
193
|
-
targetNode,
|
|
194
|
-
isValid: true
|
|
195
|
-
};
|
|
196
|
-
return this.validators$.value.reduce(
|
|
197
|
-
(isValid, validator) => isValid && validator(context),
|
|
198
|
-
true
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
158
|
getContainerElement() {
|
|
202
159
|
return document.querySelector(`.${bem("connection-line", "container")}[data-plugin-id="${this.pluginId}"]`);
|
|
203
160
|
}
|
|
@@ -216,7 +173,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
216
173
|
*/
|
|
217
174
|
createConnectionLine(sourceNodeId, startPosition) {
|
|
218
175
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
219
|
-
svg.setAttribute("class", `${this.config.connectionLineClassName
|
|
176
|
+
svg.setAttribute("class", `${this.config.connectionLineClassName} line-${sourceNodeId}`);
|
|
220
177
|
svg.style.position = "absolute";
|
|
221
178
|
svg.style.top = "0";
|
|
222
179
|
svg.style.left = "0";
|
|
@@ -292,7 +249,6 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
292
249
|
const newNodeId = generateId();
|
|
293
250
|
const newNode = {
|
|
294
251
|
id: newNodeId,
|
|
295
|
-
type: this.config.newNodeType,
|
|
296
252
|
position,
|
|
297
253
|
data: {}
|
|
298
254
|
};
|
|
@@ -304,14 +260,21 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
304
260
|
}));
|
|
305
261
|
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
306
262
|
var _a2;
|
|
307
|
-
return (_a2 = creator(
|
|
308
|
-
|
|
263
|
+
return (_a2 = creator({
|
|
264
|
+
sourceNodeIds,
|
|
265
|
+
targetNodeId: void 0,
|
|
266
|
+
targetPosition: position
|
|
267
|
+
})) != null ? _a2 : result;
|
|
268
|
+
}, {
|
|
269
|
+
nodes: [newNode],
|
|
270
|
+
edges: newEdges
|
|
271
|
+
});
|
|
309
272
|
if (createResult === false) {
|
|
310
273
|
return [];
|
|
311
274
|
}
|
|
312
275
|
this.dispatchNodeOperation({
|
|
313
|
-
type: "
|
|
314
|
-
|
|
276
|
+
type: "batch",
|
|
277
|
+
operations: createResult.nodes.map((node) => ({ type: "add", data: node }))
|
|
315
278
|
});
|
|
316
279
|
return [{
|
|
317
280
|
type: "batch",
|
|
@@ -321,31 +284,26 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
321
284
|
}))
|
|
322
285
|
}];
|
|
323
286
|
}
|
|
324
|
-
createEdge(sourceNodeId, targetNodeId) {
|
|
325
|
-
return [{
|
|
326
|
-
type: "add",
|
|
327
|
-
data: {
|
|
328
|
-
id: generateId(),
|
|
329
|
-
source: sourceNodeId,
|
|
330
|
-
target: targetNodeId,
|
|
331
|
-
type: this.config.edgeType
|
|
332
|
-
}
|
|
333
|
-
}];
|
|
334
|
-
}
|
|
335
287
|
createEdges(sourceNodeIds, targetNodeId) {
|
|
336
288
|
if (sourceNodeIds.length === 0 || !targetNodeId) {
|
|
337
289
|
return [];
|
|
338
290
|
}
|
|
291
|
+
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
292
|
+
var _a2;
|
|
293
|
+
return (_a2 = creator({
|
|
294
|
+
sourceNodeIds,
|
|
295
|
+
targetNodeId,
|
|
296
|
+
targetPosition: void 0
|
|
297
|
+
})) != null ? _a2 : result;
|
|
298
|
+
}, { edges: [] });
|
|
299
|
+
if (createResult === false || createResult.edges.length === 0) {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
339
302
|
return [{
|
|
340
303
|
type: "batch",
|
|
341
|
-
operations:
|
|
304
|
+
operations: createResult.edges.map((edge) => ({
|
|
342
305
|
type: "add",
|
|
343
|
-
data:
|
|
344
|
-
id: generateId(),
|
|
345
|
-
source: sourceNodeId,
|
|
346
|
-
target: targetNodeId,
|
|
347
|
-
type: this.config.edgeType
|
|
348
|
-
}
|
|
306
|
+
data: edge
|
|
349
307
|
}))
|
|
350
308
|
}];
|
|
351
309
|
}
|
|
@@ -428,12 +386,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
428
386
|
const sourceNodeIds = Array.from(this.connectionLines.keys()).filter((id) => id !== targetNodeId);
|
|
429
387
|
if (sourceNodeIds.length === 0)
|
|
430
388
|
return;
|
|
431
|
-
|
|
432
|
-
(sourceNodeId) => this.validateConnection(sourceNodeId, targetNodeId)
|
|
433
|
-
);
|
|
434
|
-
if (validSourceNodeIds.length > 0) {
|
|
435
|
-
this.createEdges(validSourceNodeIds, targetNodeId);
|
|
436
|
-
}
|
|
389
|
+
this.createEdges(sourceNodeIds, targetNodeId);
|
|
437
390
|
event.target.classList.remove(this.classNames.active);
|
|
438
391
|
}
|
|
439
392
|
});
|
|
@@ -454,18 +407,16 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
454
407
|
}
|
|
455
408
|
}
|
|
456
409
|
destroy() {
|
|
457
|
-
var _a2, _b, _c
|
|
410
|
+
var _a2, _b, _c;
|
|
458
411
|
(_a2 = this.dragInteractable) == null ? void 0 : _a2.unset();
|
|
459
412
|
(_b = this.dropInteractable) == null ? void 0 : _b.unset();
|
|
460
413
|
(_c = this.blankAreaDropInteractable) == null ? void 0 : _c.unset();
|
|
461
414
|
this.clearAllConnectionLines();
|
|
462
|
-
(_d = this.subscription) == null ? void 0 : _d.unsubscribe();
|
|
463
415
|
}
|
|
464
416
|
}
|
|
465
417
|
_init = __decoratorStart(_a);
|
|
466
418
|
__decorateElement(_init, 1, "containerRender", _containerRender_dec, ConnectionLine);
|
|
467
419
|
__decorateElement(_init, 1, "createNodeAndEdge", _createNodeAndEdge_dec, ConnectionLine);
|
|
468
|
-
__decorateElement(_init, 1, "createEdge", _createEdge_dec, ConnectionLine);
|
|
469
420
|
__decorateElement(_init, 1, "createEdges", _createEdges_dec, ConnectionLine);
|
|
470
421
|
__decorateElement(_init, 1, "init", _init_dec, ConnectionLine);
|
|
471
422
|
__decorateElement(_init, 1, "destroy", _destroy_dec, ConnectionLine);
|
|
@@ -477,9 +428,7 @@ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, ConnectionLin
|
|
|
477
428
|
__decorateElement(_init, 5, "canInteract", _canInteract_dec, ConnectionLine);
|
|
478
429
|
__decorateElement(_init, 5, "selectedNodeIds", _selectedNodeIds_dec, ConnectionLine);
|
|
479
430
|
__decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
|
|
480
|
-
__decorateElement(_init, 5, "
|
|
481
|
-
__decorateElement(_init, 5, "registerValidator", _registerValidator_dec, ConnectionLine);
|
|
482
|
-
__decorateElement(_init, 5, "registerNewNodeCreator", _registerNewNodeCreator_dec, ConnectionLine);
|
|
431
|
+
__decorateElement(_init, 5, "registerCreator", _registerCreator_dec, ConnectionLine);
|
|
483
432
|
__decoratorMetadata(_init, ConnectionLine);
|
|
484
433
|
|
|
485
434
|
export { ConnectionLine };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-connection-line",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Connectionline Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"@interactjs/modifiers": "^1.10.27",
|
|
34
34
|
"@interactjs/types": "^1.10.27",
|
|
35
35
|
"interactjs": "^1.10.27",
|
|
36
|
-
"@knotx/jsx": "0.2.
|
|
37
|
-
"@knotx/plugins-selection": "0.2.
|
|
36
|
+
"@knotx/jsx": "0.2.12",
|
|
37
|
+
"@knotx/plugins-selection": "0.2.14"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"lodash-es": "^4.17.21",
|
|
41
41
|
"rxjs": "^7.8.1",
|
|
42
|
-
"@knotx/core": "0.2.
|
|
43
|
-
"@knotx/decorators": "0.2.
|
|
42
|
+
"@knotx/core": "0.2.13",
|
|
43
|
+
"@knotx/decorators": "0.2.14"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@interactjs/actions": "^1.10.27",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"@interactjs/types": "^1.10.27",
|
|
50
50
|
"@types/lodash-es": "^4.17.12",
|
|
51
51
|
"interactjs": "^1.10.27",
|
|
52
|
-
"@knotx/build-config": "0.2.
|
|
53
|
-
"@knotx/eslint-config": "0.2.
|
|
54
|
-
"@knotx/jsx": "0.2.
|
|
55
|
-
"@knotx/plugins-selection": "0.2.
|
|
56
|
-
"@knotx/typescript-config": "0.2.
|
|
52
|
+
"@knotx/build-config": "0.2.12",
|
|
53
|
+
"@knotx/eslint-config": "0.2.12",
|
|
54
|
+
"@knotx/jsx": "0.2.12",
|
|
55
|
+
"@knotx/plugins-selection": "0.2.14",
|
|
56
|
+
"@knotx/typescript-config": "0.2.12"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "unbuild",
|