@knotx/plugins-connection-line 0.0.8 → 0.2.1
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 +17 -17
- package/dist/index.d.cts +6 -7
- package/dist/index.d.mts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.mjs +17 -17
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -76,17 +76,17 @@ 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, _createNodesAndEdges_dec, _createEdges_dec, _createEdge_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerNewNodeCreator_dec, _registerValidator_dec,
|
|
80
|
-
const
|
|
79
|
+
var _destroy_dec, _init_dec, _createNodesAndEdges_dec, _createEdges_dec, _createEdge_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerNewNodeCreator_dec, _registerValidator_dec, _config_dec, _getConnectHandleAttributes_dec, _selectedNodeIds_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
|
|
80
|
+
const DEFAULT_CONFIG = {
|
|
81
81
|
allowCreateNodeOnBlankArea: true,
|
|
82
82
|
newNodeType: "default",
|
|
83
83
|
edgeType: "bezier",
|
|
84
84
|
connectionLineClassName: "knotx-connection-line",
|
|
85
85
|
allowMultiDrag: true
|
|
86
86
|
};
|
|
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("selection", "selectedNodeIds")], _getConnectHandleAttributes_dec = [decorators.register("getConnectHandleAttributes")],
|
|
88
|
-
constructor(
|
|
89
|
-
super();
|
|
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("selection", "selectedNodeIds")], _getConnectHandleAttributes_dec = [decorators.register("getConnectHandleAttributes")], _config_dec = [decorators.register("config")], _registerValidator_dec = [decorators.register("registerValidator")], _registerNewNodeCreator_dec = [decorators.register("registerNewNodeCreator")], _containerRender_dec = [decorators.layer(core.Layer.Nodes, 10)], _createNodeAndEdge_dec = [decorators.edgeOperator()], _createEdge_dec = [decorators.edgeOperator()], _createEdges_dec = [decorators.edgeOperator()], _createNodesAndEdges_dec = [decorators.edgeOperator()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _a) {
|
|
88
|
+
constructor() {
|
|
89
|
+
super(...arguments);
|
|
90
90
|
__runInitializers(_init, 5, this);
|
|
91
91
|
__publicField(this, "name", "connectionLine");
|
|
92
92
|
__publicField(this, "getNode", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
@@ -126,7 +126,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
126
126
|
__publicField(this, "validators$", new rxjs.BehaviorSubject([]));
|
|
127
127
|
// 新节点创建器列表
|
|
128
128
|
__publicField(this, "creators$", new rxjs.BehaviorSubject([]));
|
|
129
|
-
__publicField(this, "
|
|
129
|
+
__publicField(this, "config", __runInitializers(_init, 40, this, DEFAULT_CONFIG)), __runInitializers(_init, 43, this);
|
|
130
130
|
__publicField(this, "registerValidator", __runInitializers(_init, 44, this, (validator) => {
|
|
131
131
|
const validators = this.validators$.value;
|
|
132
132
|
validators.push(validator);
|
|
@@ -153,7 +153,6 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
})), __runInitializers(_init, 51, this);
|
|
156
|
-
this.options = lodashEs.merge(DEFAULT_OPTIONS, options);
|
|
157
156
|
}
|
|
158
157
|
containerRender() {
|
|
159
158
|
const size = this.getContainerSize();
|
|
@@ -213,7 +212,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
213
212
|
* 根据当前拖拽的节点和选中的节点决定
|
|
214
213
|
*/
|
|
215
214
|
getSourceNodeIdsForDrag(currentNodeId) {
|
|
216
|
-
if (!this.
|
|
215
|
+
if (!this.config.allowMultiDrag || !this.selectedNodeIds.includes(currentNodeId)) {
|
|
217
216
|
return [currentNodeId];
|
|
218
217
|
}
|
|
219
218
|
return [...this.selectedNodeIds];
|
|
@@ -223,7 +222,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
223
222
|
*/
|
|
224
223
|
createConnectionLine(sourceNodeId, startPosition) {
|
|
225
224
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
226
|
-
svg.setAttribute("class", `${this.
|
|
225
|
+
svg.setAttribute("class", `${this.config.connectionLineClassName || "knotx-connection-line"} line-${sourceNodeId}`);
|
|
227
226
|
svg.style.position = "absolute";
|
|
228
227
|
svg.style.top = "0";
|
|
229
228
|
svg.style.left = "0";
|
|
@@ -296,7 +295,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
296
295
|
const newNodeId = core.generateId();
|
|
297
296
|
const newNode = {
|
|
298
297
|
id: newNodeId,
|
|
299
|
-
type: this.
|
|
298
|
+
type: this.config.newNodeType,
|
|
300
299
|
position,
|
|
301
300
|
data: {}
|
|
302
301
|
};
|
|
@@ -304,7 +303,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
304
303
|
id: core.generateId(),
|
|
305
304
|
source: sourceNodeId,
|
|
306
305
|
target: newNodeId,
|
|
307
|
-
type: this.
|
|
306
|
+
type: this.config.edgeType
|
|
308
307
|
}));
|
|
309
308
|
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
310
309
|
var _a2;
|
|
@@ -332,7 +331,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
332
331
|
id: core.generateId(),
|
|
333
332
|
source: sourceNodeId,
|
|
334
333
|
target: targetNodeId,
|
|
335
|
-
type: this.
|
|
334
|
+
type: this.config.edgeType
|
|
336
335
|
}
|
|
337
336
|
}];
|
|
338
337
|
}
|
|
@@ -348,7 +347,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
348
347
|
id: core.generateId(),
|
|
349
348
|
source: sourceNodeId,
|
|
350
349
|
target: targetNodeId,
|
|
351
|
-
type: this.
|
|
350
|
+
type: this.config.edgeType
|
|
352
351
|
}
|
|
353
352
|
}))
|
|
354
353
|
}];
|
|
@@ -359,7 +358,8 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
359
358
|
}
|
|
360
359
|
return this.createNodeAndEdge(sourceNodeIds, position);
|
|
361
360
|
}
|
|
362
|
-
init() {
|
|
361
|
+
init(config) {
|
|
362
|
+
this.config = lodashEs.merge(DEFAULT_CONFIG, config);
|
|
363
363
|
this.dragInteractable = interact__default(`.${this.classNames.source}[data-plugin-id="${this.pluginId}"]`).draggable({
|
|
364
364
|
inertia: false,
|
|
365
365
|
autoScroll: true,
|
|
@@ -446,12 +446,12 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
|
|
|
446
446
|
event.target.classList.remove(this.classNames.active);
|
|
447
447
|
}
|
|
448
448
|
});
|
|
449
|
-
if (this.
|
|
449
|
+
if (this.config.allowCreateNodeOnBlankArea) {
|
|
450
450
|
this.blankAreaDropInteractable = interact__default(`.${core.bem("canvas", "wrapper")}`).dropzone({
|
|
451
451
|
ondrop: (event) => {
|
|
452
452
|
const element = event.target;
|
|
453
453
|
const isNode = !!element.closest(`[data-node-id]`);
|
|
454
|
-
if (!isNode && this.connectionLines.size > 0 && this.
|
|
454
|
+
if (!isNode && this.connectionLines.size > 0 && this.config.allowCreateNodeOnBlankArea) {
|
|
455
455
|
const sourceNodeIds = Array.from(this.connectionLines.keys());
|
|
456
456
|
const firstLine = this.connectionLines.values().next().value;
|
|
457
457
|
if (firstLine) {
|
|
@@ -487,7 +487,7 @@ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, ConnectionLin
|
|
|
487
487
|
__decorateElement(_init, 5, "canInteract", _canInteract_dec, ConnectionLine);
|
|
488
488
|
__decorateElement(_init, 5, "selectedNodeIds", _selectedNodeIds_dec, ConnectionLine);
|
|
489
489
|
__decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
|
|
490
|
-
__decorateElement(_init, 5, "
|
|
490
|
+
__decorateElement(_init, 5, "config", _config_dec, ConnectionLine);
|
|
491
491
|
__decorateElement(_init, 5, "registerValidator", _registerValidator_dec, ConnectionLine);
|
|
492
492
|
__decorateElement(_init, 5, "registerNewNodeCreator", _registerNewNodeCreator_dec, ConnectionLine);
|
|
493
493
|
__decoratorMetadata(_init, ConnectionLine);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeData, EdgeData, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
5
5
|
* 是否允许连接到画布空白处并创建新节点
|
|
6
6
|
* @default false
|
|
@@ -38,7 +38,7 @@ type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
|
38
38
|
declare module '@knotx/core' {
|
|
39
39
|
interface PluginData {
|
|
40
40
|
connectionLine: {
|
|
41
|
-
|
|
41
|
+
config: ConnectionLineConfig;
|
|
42
42
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
43
43
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
44
44
|
node: NodeData;
|
|
@@ -59,7 +59,7 @@ declare module '@knotx/core' {
|
|
|
59
59
|
* 连接线插件
|
|
60
60
|
* 允许从指定DOM元素拖拽出连接线,连接到其他节点
|
|
61
61
|
*/
|
|
62
|
-
declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
62
|
+
declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLineConfig> {
|
|
63
63
|
name: "connectionLine";
|
|
64
64
|
getNode: (id: string) => NodeData | undefined;
|
|
65
65
|
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
@@ -85,8 +85,7 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
85
85
|
private blankAreaDropInteractable?;
|
|
86
86
|
private validators$;
|
|
87
87
|
private creators$;
|
|
88
|
-
|
|
89
|
-
options: ConnectionLineOptions;
|
|
88
|
+
private config;
|
|
90
89
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
91
90
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
92
91
|
node: NodeData;
|
|
@@ -145,8 +144,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
145
144
|
x: number;
|
|
146
145
|
y: number;
|
|
147
146
|
}): EdgeOperation[];
|
|
148
|
-
init(): void;
|
|
147
|
+
init(config: ConnectionLineConfig): void;
|
|
149
148
|
destroy(): void;
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
export { ConnectionLine, type
|
|
151
|
+
export { ConnectionLine, type ConnectionLineConfig, type ConnectionValidateContext, type ConnectionValidator };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeData, EdgeData, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
5
5
|
* 是否允许连接到画布空白处并创建新节点
|
|
6
6
|
* @default false
|
|
@@ -38,7 +38,7 @@ type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
|
38
38
|
declare module '@knotx/core' {
|
|
39
39
|
interface PluginData {
|
|
40
40
|
connectionLine: {
|
|
41
|
-
|
|
41
|
+
config: ConnectionLineConfig;
|
|
42
42
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
43
43
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
44
44
|
node: NodeData;
|
|
@@ -59,7 +59,7 @@ declare module '@knotx/core' {
|
|
|
59
59
|
* 连接线插件
|
|
60
60
|
* 允许从指定DOM元素拖拽出连接线,连接到其他节点
|
|
61
61
|
*/
|
|
62
|
-
declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
62
|
+
declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLineConfig> {
|
|
63
63
|
name: "connectionLine";
|
|
64
64
|
getNode: (id: string) => NodeData | undefined;
|
|
65
65
|
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
@@ -85,8 +85,7 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
85
85
|
private blankAreaDropInteractable?;
|
|
86
86
|
private validators$;
|
|
87
87
|
private creators$;
|
|
88
|
-
|
|
89
|
-
options: ConnectionLineOptions;
|
|
88
|
+
private config;
|
|
90
89
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
91
90
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
92
91
|
node: NodeData;
|
|
@@ -145,8 +144,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
145
144
|
x: number;
|
|
146
145
|
y: number;
|
|
147
146
|
}): EdgeOperation[];
|
|
148
|
-
init(): void;
|
|
147
|
+
init(config: ConnectionLineConfig): void;
|
|
149
148
|
destroy(): void;
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
export { ConnectionLine, type
|
|
151
|
+
export { ConnectionLine, type ConnectionLineConfig, type ConnectionValidateContext, type ConnectionValidator };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeData, EdgeData, BasePlugin, NodeOperation, EdgeOperation, InteractionPriority } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ConnectionLineConfig {
|
|
4
4
|
/**
|
|
5
5
|
* 是否允许连接到画布空白处并创建新节点
|
|
6
6
|
* @default false
|
|
@@ -38,7 +38,7 @@ type ConnectionValidator = (context: ConnectionValidateContext) => boolean;
|
|
|
38
38
|
declare module '@knotx/core' {
|
|
39
39
|
interface PluginData {
|
|
40
40
|
connectionLine: {
|
|
41
|
-
|
|
41
|
+
config: ConnectionLineConfig;
|
|
42
42
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
43
43
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
44
44
|
node: NodeData;
|
|
@@ -59,7 +59,7 @@ declare module '@knotx/core' {
|
|
|
59
59
|
* 连接线插件
|
|
60
60
|
* 允许从指定DOM元素拖拽出连接线,连接到其他节点
|
|
61
61
|
*/
|
|
62
|
-
declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
62
|
+
declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLineConfig> {
|
|
63
63
|
name: "connectionLine";
|
|
64
64
|
getNode: (id: string) => NodeData | undefined;
|
|
65
65
|
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
@@ -85,8 +85,7 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
85
85
|
private blankAreaDropInteractable?;
|
|
86
86
|
private validators$;
|
|
87
87
|
private creators$;
|
|
88
|
-
|
|
89
|
-
options: ConnectionLineOptions;
|
|
88
|
+
private config;
|
|
90
89
|
registerValidator: (validator: ConnectionValidator) => () => void;
|
|
91
90
|
registerNewNodeCreator: (creator: (sourceNodeIds: string[], node: NodeData, edges: EdgeData[]) => ({
|
|
92
91
|
node: NodeData;
|
|
@@ -145,8 +144,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine'> {
|
|
|
145
144
|
x: number;
|
|
146
145
|
y: number;
|
|
147
146
|
}): EdgeOperation[];
|
|
148
|
-
init(): void;
|
|
147
|
+
init(config: ConnectionLineConfig): void;
|
|
149
148
|
destroy(): void;
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
export { ConnectionLine, type
|
|
151
|
+
export { ConnectionLine, type ConnectionLineConfig, type ConnectionValidateContext, type ConnectionValidator };
|
package/dist/index.mjs
CHANGED
|
@@ -70,17 +70,17 @@ 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, _createNodesAndEdges_dec, _createEdges_dec, _createEdge_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerNewNodeCreator_dec, _registerValidator_dec,
|
|
74
|
-
const
|
|
73
|
+
var _destroy_dec, _init_dec, _createNodesAndEdges_dec, _createEdges_dec, _createEdge_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerNewNodeCreator_dec, _registerValidator_dec, _config_dec, _getConnectHandleAttributes_dec, _selectedNodeIds_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
|
|
74
|
+
const DEFAULT_CONFIG = {
|
|
75
75
|
allowCreateNodeOnBlankArea: true,
|
|
76
76
|
newNodeType: "default",
|
|
77
77
|
edgeType: "bezier",
|
|
78
78
|
connectionLineClassName: "knotx-connection-line",
|
|
79
79
|
allowMultiDrag: true
|
|
80
80
|
};
|
|
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("selection", "selectedNodeIds")], _getConnectHandleAttributes_dec = [register("getConnectHandleAttributes")],
|
|
82
|
-
constructor(
|
|
83
|
-
super();
|
|
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("selection", "selectedNodeIds")], _getConnectHandleAttributes_dec = [register("getConnectHandleAttributes")], _config_dec = [register("config")], _registerValidator_dec = [register("registerValidator")], _registerNewNodeCreator_dec = [register("registerNewNodeCreator")], _containerRender_dec = [layer(Layer.Nodes, 10)], _createNodeAndEdge_dec = [edgeOperator()], _createEdge_dec = [edgeOperator()], _createEdges_dec = [edgeOperator()], _createNodesAndEdges_dec = [edgeOperator()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _a) {
|
|
82
|
+
constructor() {
|
|
83
|
+
super(...arguments);
|
|
84
84
|
__runInitializers(_init, 5, this);
|
|
85
85
|
__publicField(this, "name", "connectionLine");
|
|
86
86
|
__publicField(this, "getNode", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
@@ -120,7 +120,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
120
120
|
__publicField(this, "validators$", new BehaviorSubject([]));
|
|
121
121
|
// 新节点创建器列表
|
|
122
122
|
__publicField(this, "creators$", new BehaviorSubject([]));
|
|
123
|
-
__publicField(this, "
|
|
123
|
+
__publicField(this, "config", __runInitializers(_init, 40, this, DEFAULT_CONFIG)), __runInitializers(_init, 43, this);
|
|
124
124
|
__publicField(this, "registerValidator", __runInitializers(_init, 44, this, (validator) => {
|
|
125
125
|
const validators = this.validators$.value;
|
|
126
126
|
validators.push(validator);
|
|
@@ -147,7 +147,6 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
})), __runInitializers(_init, 51, this);
|
|
150
|
-
this.options = merge(DEFAULT_OPTIONS, options);
|
|
151
150
|
}
|
|
152
151
|
containerRender() {
|
|
153
152
|
const size = this.getContainerSize();
|
|
@@ -207,7 +206,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
207
206
|
* 根据当前拖拽的节点和选中的节点决定
|
|
208
207
|
*/
|
|
209
208
|
getSourceNodeIdsForDrag(currentNodeId) {
|
|
210
|
-
if (!this.
|
|
209
|
+
if (!this.config.allowMultiDrag || !this.selectedNodeIds.includes(currentNodeId)) {
|
|
211
210
|
return [currentNodeId];
|
|
212
211
|
}
|
|
213
212
|
return [...this.selectedNodeIds];
|
|
@@ -217,7 +216,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
217
216
|
*/
|
|
218
217
|
createConnectionLine(sourceNodeId, startPosition) {
|
|
219
218
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
220
|
-
svg.setAttribute("class", `${this.
|
|
219
|
+
svg.setAttribute("class", `${this.config.connectionLineClassName || "knotx-connection-line"} line-${sourceNodeId}`);
|
|
221
220
|
svg.style.position = "absolute";
|
|
222
221
|
svg.style.top = "0";
|
|
223
222
|
svg.style.left = "0";
|
|
@@ -290,7 +289,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
290
289
|
const newNodeId = generateId();
|
|
291
290
|
const newNode = {
|
|
292
291
|
id: newNodeId,
|
|
293
|
-
type: this.
|
|
292
|
+
type: this.config.newNodeType,
|
|
294
293
|
position,
|
|
295
294
|
data: {}
|
|
296
295
|
};
|
|
@@ -298,7 +297,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
298
297
|
id: generateId(),
|
|
299
298
|
source: sourceNodeId,
|
|
300
299
|
target: newNodeId,
|
|
301
|
-
type: this.
|
|
300
|
+
type: this.config.edgeType
|
|
302
301
|
}));
|
|
303
302
|
const createResult = this.creators$.value.reduce((result, creator) => {
|
|
304
303
|
var _a2;
|
|
@@ -326,7 +325,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
326
325
|
id: generateId(),
|
|
327
326
|
source: sourceNodeId,
|
|
328
327
|
target: targetNodeId,
|
|
329
|
-
type: this.
|
|
328
|
+
type: this.config.edgeType
|
|
330
329
|
}
|
|
331
330
|
}];
|
|
332
331
|
}
|
|
@@ -342,7 +341,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
342
341
|
id: generateId(),
|
|
343
342
|
source: sourceNodeId,
|
|
344
343
|
target: targetNodeId,
|
|
345
|
-
type: this.
|
|
344
|
+
type: this.config.edgeType
|
|
346
345
|
}
|
|
347
346
|
}))
|
|
348
347
|
}];
|
|
@@ -353,7 +352,8 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
353
352
|
}
|
|
354
353
|
return this.createNodeAndEdge(sourceNodeIds, position);
|
|
355
354
|
}
|
|
356
|
-
init() {
|
|
355
|
+
init(config) {
|
|
356
|
+
this.config = merge(DEFAULT_CONFIG, config);
|
|
357
357
|
this.dragInteractable = interact(`.${this.classNames.source}[data-plugin-id="${this.pluginId}"]`).draggable({
|
|
358
358
|
inertia: false,
|
|
359
359
|
autoScroll: true,
|
|
@@ -440,12 +440,12 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
|
|
|
440
440
|
event.target.classList.remove(this.classNames.active);
|
|
441
441
|
}
|
|
442
442
|
});
|
|
443
|
-
if (this.
|
|
443
|
+
if (this.config.allowCreateNodeOnBlankArea) {
|
|
444
444
|
this.blankAreaDropInteractable = interact(`.${bem("canvas", "wrapper")}`).dropzone({
|
|
445
445
|
ondrop: (event) => {
|
|
446
446
|
const element = event.target;
|
|
447
447
|
const isNode = !!element.closest(`[data-node-id]`);
|
|
448
|
-
if (!isNode && this.connectionLines.size > 0 && this.
|
|
448
|
+
if (!isNode && this.connectionLines.size > 0 && this.config.allowCreateNodeOnBlankArea) {
|
|
449
449
|
const sourceNodeIds = Array.from(this.connectionLines.keys());
|
|
450
450
|
const firstLine = this.connectionLines.values().next().value;
|
|
451
451
|
if (firstLine) {
|
|
@@ -481,7 +481,7 @@ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, ConnectionLin
|
|
|
481
481
|
__decorateElement(_init, 5, "canInteract", _canInteract_dec, ConnectionLine);
|
|
482
482
|
__decorateElement(_init, 5, "selectedNodeIds", _selectedNodeIds_dec, ConnectionLine);
|
|
483
483
|
__decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
|
|
484
|
-
__decorateElement(_init, 5, "
|
|
484
|
+
__decorateElement(_init, 5, "config", _config_dec, ConnectionLine);
|
|
485
485
|
__decorateElement(_init, 5, "registerValidator", _registerValidator_dec, ConnectionLine);
|
|
486
486
|
__decorateElement(_init, 5, "registerNewNodeCreator", _registerNewNodeCreator_dec, ConnectionLine);
|
|
487
487
|
__decoratorMetadata(_init, ConnectionLine);
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-connection-line",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.8",
|
|
3
|
+
"version": "0.2.1",
|
|
5
4
|
"description": "Connectionline Plugin for Knotx",
|
|
6
5
|
"author": "boenfu",
|
|
7
6
|
"license": "MIT",
|
|
@@ -34,13 +33,14 @@
|
|
|
34
33
|
"@interactjs/modifiers": "^1.10.27",
|
|
35
34
|
"@interactjs/types": "^1.10.27",
|
|
36
35
|
"interactjs": "^1.10.27",
|
|
37
|
-
"@knotx/
|
|
36
|
+
"@knotx/jsx": "0.2.1",
|
|
37
|
+
"@knotx/plugins-selection": "0.2.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"lodash-es": "^4.17.21",
|
|
41
41
|
"rxjs": "^7.8.1",
|
|
42
|
-
"@knotx/core": "0.
|
|
43
|
-
"@knotx/decorators": "0.
|
|
42
|
+
"@knotx/core": "0.2.1",
|
|
43
|
+
"@knotx/decorators": "0.2.1"
|
|
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.
|
|
53
|
-
"@knotx/eslint-config": "0.
|
|
54
|
-
"@knotx/jsx": "0.
|
|
55
|
-
"@knotx/plugins-selection": "0.
|
|
56
|
-
"@knotx/typescript-config": "0.
|
|
52
|
+
"@knotx/build-config": "0.2.1",
|
|
53
|
+
"@knotx/eslint-config": "0.2.1",
|
|
54
|
+
"@knotx/jsx": "0.2.1",
|
|
55
|
+
"@knotx/plugins-selection": "0.2.1",
|
|
56
|
+
"@knotx/typescript-config": "0.2.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "unbuild --failOnWarn=false",
|