@knotx/plugins-connection-line 0.4.0 → 0.4.2

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 CHANGED
@@ -76,14 +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, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _selected_dec, _interaction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
79
+ var _destroy_dec, _init_dec, _onTransform_dec, _onIsDragging_dec, _createEdges_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _isDragging_dec, _selected_dec, _edgeScroll_dec, _transform_dec, _interaction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
80
80
  const DEFAULT_CONFIG = {
81
81
  allowCreateNodeOnBlankArea: true,
82
82
  edgeType: "bezier",
83
83
  connectionLineClassName: core.bem("connection-line", "line"),
84
84
  allowMultiDrag: true
85
85
  };
86
- class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.inject.getNode()], _dispatchNodeOperation_dec = [decorators.inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [decorators.inject.dispatchEdgeOperation()], _interaction_dec = [decorators.inject.interaction()], _selected_dec = [decorators.inject.selection.selected()], _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) {
86
+ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.inject.getNode()], _dispatchNodeOperation_dec = [decorators.inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [decorators.inject.dispatchEdgeOperation()], _interaction_dec = [decorators.inject.interaction()], _transform_dec = [decorators.inject.canvas.transform()], _edgeScroll_dec = [decorators.inject.canvas.edgeScroll()], _selected_dec = [decorators.inject.selection.selected()], _isDragging_dec = [decorators.register("isDragging")], _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()], _onIsDragging_dec = [decorators.subscribe.connectionLine.isDragging()], _onTransform_dec = [decorators.subscribe.canvas.transform()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _a) {
87
87
  constructor() {
88
88
  super(...arguments);
89
89
  __runInitializers(_init, 5, this);
@@ -92,16 +92,19 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
92
92
  __publicField(this, "dispatchNodeOperation", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
93
93
  __publicField(this, "dispatchEdgeOperation", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
94
94
  __publicField(this, "interaction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
95
- __publicField(this, "selected", __runInitializers(_init, 24, this, [])), __runInitializers(_init, 27, this);
96
- __publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 28, this, ({ nodeId, type, index = 0, className = "" }) => {
95
+ __publicField(this, "transform", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
96
+ __publicField(this, "edgeScroll", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
97
+ __publicField(this, "selected", __runInitializers(_init, 32, this, [])), __runInitializers(_init, 35, this);
98
+ __publicField(this, "isDragging", __runInitializers(_init, 36, this, false)), __runInitializers(_init, 39, this);
99
+ __publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 40, this, ({ nodeId, type, index = 0, className = "" }) => {
97
100
  return {
98
101
  "className": `${className} ${this.classNames.connector} ${this.classNames[type]}`,
99
- "data-plugin-id": this.pluginId,
102
+ [`data-${this.pluginId}`]: "",
100
103
  "data-node-id": nodeId,
101
104
  "data-connector-id": String(index),
102
105
  "data-connector-type": type
103
106
  };
104
- })), __runInitializers(_init, 31, this);
107
+ })), __runInitializers(_init, 43, this);
105
108
  __publicField(this, "classNames", {
106
109
  connector: core.bem("connection-line", "connector"),
107
110
  source: core.bem("connection-line", "connector", "source"),
@@ -112,6 +115,8 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
112
115
  __publicField(this, "connectionLines", /* @__PURE__ */ new Map());
113
116
  // 拖拽起始缩放比例
114
117
  __publicField(this, "startScale", 1);
118
+ // 记录拖拽开始时画布的位置
119
+ __publicField(this, "startTransformPosition", { x: 0, y: 0 });
115
120
  // 用于存储当前触发拖拽事件的DOM元素对应的节点ID
116
121
  __publicField(this, "currentDragNodeId", null);
117
122
  __publicField(this, "dragInteractable");
@@ -120,7 +125,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
120
125
  // 新节点创建器列表
121
126
  __publicField(this, "creators$", new rxjs.BehaviorSubject([]));
122
127
  __publicField(this, "config", DEFAULT_CONFIG);
123
- __publicField(this, "registerCreator", __runInitializers(_init, 32, this, (creator) => {
128
+ __publicField(this, "registerCreator", __runInitializers(_init, 44, this, (creator) => {
124
129
  const creators = this.creators$.value;
125
130
  creators.push(creator);
126
131
  this.creators$.next(creators);
@@ -132,15 +137,14 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
132
137
  this.creators$.next(currentCreators);
133
138
  }
134
139
  };
135
- })), __runInitializers(_init, 35, this);
140
+ })), __runInitializers(_init, 47, this);
136
141
  }
137
142
  containerRender() {
138
143
  const size = this.getContainerSize();
139
144
  return /* @__PURE__ */ jsxRuntime.jsx(
140
145
  "div",
141
- {
146
+ __spreadValues({
142
147
  className: core.bem("connection-line", "container"),
143
- "data-plugin-id": this.pluginId,
144
148
  style: {
145
149
  position: "absolute",
146
150
  left: 0,
@@ -150,7 +154,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
150
154
  overflow: "visible",
151
155
  pointerEvents: "none"
152
156
  }
153
- }
157
+ }, { [`data-${this.pluginId}`]: "" })
154
158
  );
155
159
  }
156
160
  /**
@@ -160,7 +164,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
160
164
  return 1;
161
165
  }
162
166
  getContainerElement() {
163
- return document.querySelector(`.${core.bem("connection-line", "container")}[data-plugin-id="${this.pluginId}"]`);
167
+ return document.querySelector(`.${core.bem("connection-line", "container")}[data-${this.pluginId}]`);
164
168
  }
165
169
  /**
166
170
  * 获取需要为其创建连接线的源节点ID列表
@@ -233,13 +237,21 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
233
237
  if (!currentDragConnectionLine) {
234
238
  return;
235
239
  }
236
- currentDragConnectionLine.currentPosition.x += dx / this.startScale;
237
- currentDragConnectionLine.currentPosition.y += dy / this.startScale;
240
+ const transformDeltaX = this.transform.positionX - this.startTransformPosition.x;
241
+ const transformDeltaY = this.transform.positionY - this.startTransformPosition.y;
242
+ const scaledDx = dx / this.transform.scale;
243
+ const scaledDy = dy / this.transform.scale;
244
+ currentDragConnectionLine.currentPosition.x += scaledDx - transformDeltaX / this.transform.scale;
245
+ currentDragConnectionLine.currentPosition.y += scaledDy - transformDeltaY / this.transform.scale;
238
246
  this.connectionLines.forEach((state) => {
239
247
  state.currentPosition.x = currentDragConnectionLine.currentPosition.x;
240
248
  state.currentPosition.y = currentDragConnectionLine.currentPosition.y;
241
249
  this.updateConnectionLine(state);
242
250
  });
251
+ this.startTransformPosition = {
252
+ x: this.transform.positionX,
253
+ y: this.transform.positionY
254
+ };
243
255
  }
244
256
  /**
245
257
  * 清除所有临时连接线
@@ -315,11 +327,18 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
315
327
  }))
316
328
  }];
317
329
  }
330
+ onIsDragging(isDragging) {
331
+ var _a2;
332
+ (_a2 = this.edgeScroll) == null ? void 0 : _a2.setConfig({ enabled: isDragging });
333
+ }
334
+ onTransform() {
335
+ this.updateAllConnectionLines(0, 0);
336
+ }
318
337
  init(config) {
319
338
  this.config = lodashEs.merge(DEFAULT_CONFIG, config);
320
- this.dragInteractable = interact__default(`.${this.classNames.source}[data-plugin-id="${this.pluginId}"]`).draggable({
339
+ this.dragInteractable = interact__default(`.${this.classNames.source}[data-${this.pluginId}]`).draggable({
321
340
  inertia: false,
322
- autoScroll: true,
341
+ autoScroll: false,
323
342
  listeners: {
324
343
  start: (event) => {
325
344
  var _a2;
@@ -333,7 +352,11 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
333
352
  const x = (rect.left + rect.right) / 2;
334
353
  const y = (rect.top + rect.bottom) / 2;
335
354
  const { left: containerLeft, top: containerTop, width: containerWidth } = ((_a2 = this.getContainerElement()) == null ? void 0 : _a2.getBoundingClientRect()) || { left: 0, top: 0, width: 1 };
336
- this.startScale = containerWidth / this.getContainerSize();
355
+ this.startScale = this.transform.scale || containerWidth / this.getContainerSize();
356
+ this.startTransformPosition = {
357
+ x: this.transform.positionX,
358
+ y: this.transform.positionY
359
+ };
337
360
  const startPosition = {
338
361
  x: (x - containerLeft) / this.startScale,
339
362
  y: (y - containerTop) / this.startScale
@@ -346,7 +369,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
346
369
  if (sourceNodeId !== currentNodeId) {
347
370
  const connectHandleType = element.getAttribute("data-connector-type");
348
371
  const connectHandleId = element.getAttribute("data-connector-id");
349
- const connector = document.querySelector(`[data-plugin-id="${this.pluginId}"][data-node-id="${sourceNodeId}"][data-connector-type="${connectHandleType}"][data-connector-id="${connectHandleId}"]`);
372
+ const connector = document.querySelector(`[data-${this.pluginId}][data-node-id="${sourceNodeId}"][data-connector-type="${connectHandleType}"][data-connector-id="${connectHandleId}"]`);
350
373
  if (connector) {
351
374
  const connectorRect = connector.getBoundingClientRect();
352
375
  const connectorX = (connectorRect.left + connectorRect.right) / 2;
@@ -360,6 +383,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
360
383
  const state = this.createConnectionLine(sourceNodeId, nodeStartPosition);
361
384
  this.connectionLines.set(sourceNodeId, state);
362
385
  this.interaction.start(this.pluginId, "connect", core.InteractionPriority.EntityConnectDrag);
386
+ this.isDragging = true;
363
387
  });
364
388
  },
365
389
  move: (event) => {
@@ -371,10 +395,13 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
371
395
  this.clearAllConnectionLines();
372
396
  this.currentDragNodeId = null;
373
397
  this.interaction.end(this.pluginId, "connect");
398
+ this.isDragging = false;
374
399
  }
375
400
  }
376
401
  });
377
- this.dropInteractable = interact__default(`.${this.classNames.target}[data-plugin-id="${this.pluginId}"]`).dropzone({
402
+ interact__default.dynamicDrop(true);
403
+ this.dropInteractable = interact__default(`.${this.classNames.target}[data-${this.pluginId}]`).dropzone({
404
+ autoScroll: { enabled: false },
378
405
  ondragenter: (event) => {
379
406
  event.target.classList.add(this.classNames.active);
380
407
  },
@@ -400,6 +427,7 @@ class ConnectionLine extends (_a = core.BasePlugin, _getNode_dec = [decorators.i
400
427
  });
401
428
  if (this.config.allowCreateNodeOnBlankArea) {
402
429
  this.blankAreaDropInteractable = interact__default(`.${core.bem("canvas", "wrapper")}`).dropzone({
430
+ autoScroll: { enabled: false },
403
431
  ondrop: (event) => {
404
432
  const element = event.target;
405
433
  const isNode = !!element.closest(`[data-node-id]`);
@@ -426,13 +454,18 @@ _init = __decoratorStart(_a);
426
454
  __decorateElement(_init, 1, "containerRender", _containerRender_dec, ConnectionLine);
427
455
  __decorateElement(_init, 1, "createNodeAndEdge", _createNodeAndEdge_dec, ConnectionLine);
428
456
  __decorateElement(_init, 1, "createEdges", _createEdges_dec, ConnectionLine);
457
+ __decorateElement(_init, 1, "onIsDragging", _onIsDragging_dec, ConnectionLine);
458
+ __decorateElement(_init, 1, "onTransform", _onTransform_dec, ConnectionLine);
429
459
  __decorateElement(_init, 1, "init", _init_dec, ConnectionLine);
430
460
  __decorateElement(_init, 1, "destroy", _destroy_dec, ConnectionLine);
431
461
  __decorateElement(_init, 5, "getNode", _getNode_dec, ConnectionLine);
432
462
  __decorateElement(_init, 5, "dispatchNodeOperation", _dispatchNodeOperation_dec, ConnectionLine);
433
463
  __decorateElement(_init, 5, "dispatchEdgeOperation", _dispatchEdgeOperation_dec, ConnectionLine);
434
464
  __decorateElement(_init, 5, "interaction", _interaction_dec, ConnectionLine);
465
+ __decorateElement(_init, 5, "transform", _transform_dec, ConnectionLine);
466
+ __decorateElement(_init, 5, "edgeScroll", _edgeScroll_dec, ConnectionLine);
435
467
  __decorateElement(_init, 5, "selected", _selected_dec, ConnectionLine);
468
+ __decorateElement(_init, 5, "isDragging", _isDragging_dec, ConnectionLine);
436
469
  __decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
437
470
  __decorateElement(_init, 5, "registerCreator", _registerCreator_dec, ConnectionLine);
438
471
  __decoratorMetadata(_init, ConnectionLine);
package/dist/index.d.cts CHANGED
@@ -28,6 +28,7 @@ interface ConnectionLineConfig {
28
28
  declare module '@knotx/core' {
29
29
  interface PluginData {
30
30
  connectionLine: {
31
+ isDragging: boolean;
31
32
  /**
32
33
  * 注册新节点创建器
33
34
  * @param creator 新节点创建器
@@ -70,11 +71,15 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
70
71
  dispatchNodeOperation: Engine['dispatchNodeOperation'];
71
72
  dispatchEdgeOperation: Engine['dispatchEdgeOperation'];
72
73
  interaction: Engine['interaction'];
74
+ transform: PluginData['canvas']['transform'];
75
+ edgeScroll: PluginData['canvas']['edgeScroll'];
73
76
  selected: PluginData['selection']['selected'];
77
+ isDragging: boolean;
74
78
  getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
75
79
  private classNames;
76
80
  private connectionLines;
77
81
  private startScale;
82
+ private startTransformPosition;
78
83
  private currentDragNodeId;
79
84
  private dragInteractable?;
80
85
  private dropInteractable?;
@@ -120,6 +125,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
120
125
  * 批量创建新的边
121
126
  */
122
127
  createEdges(sourceNodeIds: string[], targetNodeId: string): EdgeOperation[];
128
+ onIsDragging(isDragging: boolean): void;
129
+ onTransform(): void;
123
130
  init(config: ConnectionLineConfig): void;
124
131
  destroy(): void;
125
132
  }
package/dist/index.d.mts CHANGED
@@ -28,6 +28,7 @@ interface ConnectionLineConfig {
28
28
  declare module '@knotx/core' {
29
29
  interface PluginData {
30
30
  connectionLine: {
31
+ isDragging: boolean;
31
32
  /**
32
33
  * 注册新节点创建器
33
34
  * @param creator 新节点创建器
@@ -70,11 +71,15 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
70
71
  dispatchNodeOperation: Engine['dispatchNodeOperation'];
71
72
  dispatchEdgeOperation: Engine['dispatchEdgeOperation'];
72
73
  interaction: Engine['interaction'];
74
+ transform: PluginData['canvas']['transform'];
75
+ edgeScroll: PluginData['canvas']['edgeScroll'];
73
76
  selected: PluginData['selection']['selected'];
77
+ isDragging: boolean;
74
78
  getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
75
79
  private classNames;
76
80
  private connectionLines;
77
81
  private startScale;
82
+ private startTransformPosition;
78
83
  private currentDragNodeId;
79
84
  private dragInteractable?;
80
85
  private dropInteractable?;
@@ -120,6 +125,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
120
125
  * 批量创建新的边
121
126
  */
122
127
  createEdges(sourceNodeIds: string[], targetNodeId: string): EdgeOperation[];
128
+ onIsDragging(isDragging: boolean): void;
129
+ onTransform(): void;
123
130
  init(config: ConnectionLineConfig): void;
124
131
  destroy(): void;
125
132
  }
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ interface ConnectionLineConfig {
28
28
  declare module '@knotx/core' {
29
29
  interface PluginData {
30
30
  connectionLine: {
31
+ isDragging: boolean;
31
32
  /**
32
33
  * 注册新节点创建器
33
34
  * @param creator 新节点创建器
@@ -70,11 +71,15 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
70
71
  dispatchNodeOperation: Engine['dispatchNodeOperation'];
71
72
  dispatchEdgeOperation: Engine['dispatchEdgeOperation'];
72
73
  interaction: Engine['interaction'];
74
+ transform: PluginData['canvas']['transform'];
75
+ edgeScroll: PluginData['canvas']['edgeScroll'];
73
76
  selected: PluginData['selection']['selected'];
77
+ isDragging: boolean;
74
78
  getConnectHandleAttributes: PluginData['connectionLine']['getConnectHandleAttributes'];
75
79
  private classNames;
76
80
  private connectionLines;
77
81
  private startScale;
82
+ private startTransformPosition;
78
83
  private currentDragNodeId;
79
84
  private dragInteractable?;
80
85
  private dropInteractable?;
@@ -120,6 +125,8 @@ declare class ConnectionLine extends BasePlugin<'connectionLine', ConnectionLine
120
125
  * 批量创建新的边
121
126
  */
122
127
  createEdges(sourceNodeIds: string[], targetNodeId: string): EdgeOperation[];
128
+ onIsDragging(isDragging: boolean): void;
129
+ onTransform(): void;
123
130
  init(config: ConnectionLineConfig): void;
124
131
  destroy(): void;
125
132
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx } from '@knotx/jsx/jsx-runtime';
2
2
  import { bem, Layer, generateId, InteractionPriority, BasePlugin } from '@knotx/core';
3
- import { inject, register, layer, edgeOperator, OnInit, OnDestroy } from '@knotx/decorators';
3
+ import { inject, register, layer, edgeOperator, subscribe, OnInit, OnDestroy } from '@knotx/decorators';
4
4
  import interact from 'interactjs';
5
5
  import { merge } from 'lodash-es';
6
6
  import { BehaviorSubject } from 'rxjs';
@@ -70,14 +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, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _selected_dec, _interaction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
73
+ var _destroy_dec, _init_dec, _onTransform_dec, _onIsDragging_dec, _createEdges_dec, _createNodeAndEdge_dec, _containerRender_dec, _registerCreator_dec, _getConnectHandleAttributes_dec, _isDragging_dec, _selected_dec, _edgeScroll_dec, _transform_dec, _interaction_dec, _dispatchEdgeOperation_dec, _dispatchNodeOperation_dec, _getNode_dec, _a, _init;
74
74
  const DEFAULT_CONFIG = {
75
75
  allowCreateNodeOnBlankArea: true,
76
76
  edgeType: "bezier",
77
77
  connectionLineClassName: bem("connection-line", "line"),
78
78
  allowMultiDrag: true
79
79
  };
80
- class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [inject.dispatchEdgeOperation()], _interaction_dec = [inject.interaction()], _selected_dec = [inject.selection.selected()], _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) {
80
+ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _dispatchEdgeOperation_dec = [inject.dispatchEdgeOperation()], _interaction_dec = [inject.interaction()], _transform_dec = [inject.canvas.transform()], _edgeScroll_dec = [inject.canvas.edgeScroll()], _selected_dec = [inject.selection.selected()], _isDragging_dec = [register("isDragging")], _getConnectHandleAttributes_dec = [register("getConnectHandleAttributes")], _registerCreator_dec = [register("registerCreator")], _containerRender_dec = [layer(Layer.Nodes, 10)], _createNodeAndEdge_dec = [edgeOperator()], _createEdges_dec = [edgeOperator()], _onIsDragging_dec = [subscribe.connectionLine.isDragging()], _onTransform_dec = [subscribe.canvas.transform()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _a) {
81
81
  constructor() {
82
82
  super(...arguments);
83
83
  __runInitializers(_init, 5, this);
@@ -86,16 +86,19 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
86
86
  __publicField(this, "dispatchNodeOperation", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
87
87
  __publicField(this, "dispatchEdgeOperation", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
88
88
  __publicField(this, "interaction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
89
- __publicField(this, "selected", __runInitializers(_init, 24, this, [])), __runInitializers(_init, 27, this);
90
- __publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 28, this, ({ nodeId, type, index = 0, className = "" }) => {
89
+ __publicField(this, "transform", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
90
+ __publicField(this, "edgeScroll", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
91
+ __publicField(this, "selected", __runInitializers(_init, 32, this, [])), __runInitializers(_init, 35, this);
92
+ __publicField(this, "isDragging", __runInitializers(_init, 36, this, false)), __runInitializers(_init, 39, this);
93
+ __publicField(this, "getConnectHandleAttributes", __runInitializers(_init, 40, this, ({ nodeId, type, index = 0, className = "" }) => {
91
94
  return {
92
95
  "className": `${className} ${this.classNames.connector} ${this.classNames[type]}`,
93
- "data-plugin-id": this.pluginId,
96
+ [`data-${this.pluginId}`]: "",
94
97
  "data-node-id": nodeId,
95
98
  "data-connector-id": String(index),
96
99
  "data-connector-type": type
97
100
  };
98
- })), __runInitializers(_init, 31, this);
101
+ })), __runInitializers(_init, 43, this);
99
102
  __publicField(this, "classNames", {
100
103
  connector: bem("connection-line", "connector"),
101
104
  source: bem("connection-line", "connector", "source"),
@@ -106,6 +109,8 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
106
109
  __publicField(this, "connectionLines", /* @__PURE__ */ new Map());
107
110
  // 拖拽起始缩放比例
108
111
  __publicField(this, "startScale", 1);
112
+ // 记录拖拽开始时画布的位置
113
+ __publicField(this, "startTransformPosition", { x: 0, y: 0 });
109
114
  // 用于存储当前触发拖拽事件的DOM元素对应的节点ID
110
115
  __publicField(this, "currentDragNodeId", null);
111
116
  __publicField(this, "dragInteractable");
@@ -114,7 +119,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
114
119
  // 新节点创建器列表
115
120
  __publicField(this, "creators$", new BehaviorSubject([]));
116
121
  __publicField(this, "config", DEFAULT_CONFIG);
117
- __publicField(this, "registerCreator", __runInitializers(_init, 32, this, (creator) => {
122
+ __publicField(this, "registerCreator", __runInitializers(_init, 44, this, (creator) => {
118
123
  const creators = this.creators$.value;
119
124
  creators.push(creator);
120
125
  this.creators$.next(creators);
@@ -126,15 +131,14 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
126
131
  this.creators$.next(currentCreators);
127
132
  }
128
133
  };
129
- })), __runInitializers(_init, 35, this);
134
+ })), __runInitializers(_init, 47, this);
130
135
  }
131
136
  containerRender() {
132
137
  const size = this.getContainerSize();
133
138
  return /* @__PURE__ */ jsx(
134
139
  "div",
135
- {
140
+ __spreadValues({
136
141
  className: bem("connection-line", "container"),
137
- "data-plugin-id": this.pluginId,
138
142
  style: {
139
143
  position: "absolute",
140
144
  left: 0,
@@ -144,7 +148,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
144
148
  overflow: "visible",
145
149
  pointerEvents: "none"
146
150
  }
147
- }
151
+ }, { [`data-${this.pluginId}`]: "" })
148
152
  );
149
153
  }
150
154
  /**
@@ -154,7 +158,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
154
158
  return 1;
155
159
  }
156
160
  getContainerElement() {
157
- return document.querySelector(`.${bem("connection-line", "container")}[data-plugin-id="${this.pluginId}"]`);
161
+ return document.querySelector(`.${bem("connection-line", "container")}[data-${this.pluginId}]`);
158
162
  }
159
163
  /**
160
164
  * 获取需要为其创建连接线的源节点ID列表
@@ -227,13 +231,21 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
227
231
  if (!currentDragConnectionLine) {
228
232
  return;
229
233
  }
230
- currentDragConnectionLine.currentPosition.x += dx / this.startScale;
231
- currentDragConnectionLine.currentPosition.y += dy / this.startScale;
234
+ const transformDeltaX = this.transform.positionX - this.startTransformPosition.x;
235
+ const transformDeltaY = this.transform.positionY - this.startTransformPosition.y;
236
+ const scaledDx = dx / this.transform.scale;
237
+ const scaledDy = dy / this.transform.scale;
238
+ currentDragConnectionLine.currentPosition.x += scaledDx - transformDeltaX / this.transform.scale;
239
+ currentDragConnectionLine.currentPosition.y += scaledDy - transformDeltaY / this.transform.scale;
232
240
  this.connectionLines.forEach((state) => {
233
241
  state.currentPosition.x = currentDragConnectionLine.currentPosition.x;
234
242
  state.currentPosition.y = currentDragConnectionLine.currentPosition.y;
235
243
  this.updateConnectionLine(state);
236
244
  });
245
+ this.startTransformPosition = {
246
+ x: this.transform.positionX,
247
+ y: this.transform.positionY
248
+ };
237
249
  }
238
250
  /**
239
251
  * 清除所有临时连接线
@@ -309,11 +321,18 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
309
321
  }))
310
322
  }];
311
323
  }
324
+ onIsDragging(isDragging) {
325
+ var _a2;
326
+ (_a2 = this.edgeScroll) == null ? void 0 : _a2.setConfig({ enabled: isDragging });
327
+ }
328
+ onTransform() {
329
+ this.updateAllConnectionLines(0, 0);
330
+ }
312
331
  init(config) {
313
332
  this.config = merge(DEFAULT_CONFIG, config);
314
- this.dragInteractable = interact(`.${this.classNames.source}[data-plugin-id="${this.pluginId}"]`).draggable({
333
+ this.dragInteractable = interact(`.${this.classNames.source}[data-${this.pluginId}]`).draggable({
315
334
  inertia: false,
316
- autoScroll: true,
335
+ autoScroll: false,
317
336
  listeners: {
318
337
  start: (event) => {
319
338
  var _a2;
@@ -327,7 +346,11 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
327
346
  const x = (rect.left + rect.right) / 2;
328
347
  const y = (rect.top + rect.bottom) / 2;
329
348
  const { left: containerLeft, top: containerTop, width: containerWidth } = ((_a2 = this.getContainerElement()) == null ? void 0 : _a2.getBoundingClientRect()) || { left: 0, top: 0, width: 1 };
330
- this.startScale = containerWidth / this.getContainerSize();
349
+ this.startScale = this.transform.scale || containerWidth / this.getContainerSize();
350
+ this.startTransformPosition = {
351
+ x: this.transform.positionX,
352
+ y: this.transform.positionY
353
+ };
331
354
  const startPosition = {
332
355
  x: (x - containerLeft) / this.startScale,
333
356
  y: (y - containerTop) / this.startScale
@@ -340,7 +363,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
340
363
  if (sourceNodeId !== currentNodeId) {
341
364
  const connectHandleType = element.getAttribute("data-connector-type");
342
365
  const connectHandleId = element.getAttribute("data-connector-id");
343
- const connector = document.querySelector(`[data-plugin-id="${this.pluginId}"][data-node-id="${sourceNodeId}"][data-connector-type="${connectHandleType}"][data-connector-id="${connectHandleId}"]`);
366
+ const connector = document.querySelector(`[data-${this.pluginId}][data-node-id="${sourceNodeId}"][data-connector-type="${connectHandleType}"][data-connector-id="${connectHandleId}"]`);
344
367
  if (connector) {
345
368
  const connectorRect = connector.getBoundingClientRect();
346
369
  const connectorX = (connectorRect.left + connectorRect.right) / 2;
@@ -354,6 +377,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
354
377
  const state = this.createConnectionLine(sourceNodeId, nodeStartPosition);
355
378
  this.connectionLines.set(sourceNodeId, state);
356
379
  this.interaction.start(this.pluginId, "connect", InteractionPriority.EntityConnectDrag);
380
+ this.isDragging = true;
357
381
  });
358
382
  },
359
383
  move: (event) => {
@@ -365,10 +389,13 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
365
389
  this.clearAllConnectionLines();
366
390
  this.currentDragNodeId = null;
367
391
  this.interaction.end(this.pluginId, "connect");
392
+ this.isDragging = false;
368
393
  }
369
394
  }
370
395
  });
371
- this.dropInteractable = interact(`.${this.classNames.target}[data-plugin-id="${this.pluginId}"]`).dropzone({
396
+ interact.dynamicDrop(true);
397
+ this.dropInteractable = interact(`.${this.classNames.target}[data-${this.pluginId}]`).dropzone({
398
+ autoScroll: { enabled: false },
372
399
  ondragenter: (event) => {
373
400
  event.target.classList.add(this.classNames.active);
374
401
  },
@@ -394,6 +421,7 @@ class ConnectionLine extends (_a = BasePlugin, _getNode_dec = [inject.getNode()]
394
421
  });
395
422
  if (this.config.allowCreateNodeOnBlankArea) {
396
423
  this.blankAreaDropInteractable = interact(`.${bem("canvas", "wrapper")}`).dropzone({
424
+ autoScroll: { enabled: false },
397
425
  ondrop: (event) => {
398
426
  const element = event.target;
399
427
  const isNode = !!element.closest(`[data-node-id]`);
@@ -420,13 +448,18 @@ _init = __decoratorStart(_a);
420
448
  __decorateElement(_init, 1, "containerRender", _containerRender_dec, ConnectionLine);
421
449
  __decorateElement(_init, 1, "createNodeAndEdge", _createNodeAndEdge_dec, ConnectionLine);
422
450
  __decorateElement(_init, 1, "createEdges", _createEdges_dec, ConnectionLine);
451
+ __decorateElement(_init, 1, "onIsDragging", _onIsDragging_dec, ConnectionLine);
452
+ __decorateElement(_init, 1, "onTransform", _onTransform_dec, ConnectionLine);
423
453
  __decorateElement(_init, 1, "init", _init_dec, ConnectionLine);
424
454
  __decorateElement(_init, 1, "destroy", _destroy_dec, ConnectionLine);
425
455
  __decorateElement(_init, 5, "getNode", _getNode_dec, ConnectionLine);
426
456
  __decorateElement(_init, 5, "dispatchNodeOperation", _dispatchNodeOperation_dec, ConnectionLine);
427
457
  __decorateElement(_init, 5, "dispatchEdgeOperation", _dispatchEdgeOperation_dec, ConnectionLine);
428
458
  __decorateElement(_init, 5, "interaction", _interaction_dec, ConnectionLine);
459
+ __decorateElement(_init, 5, "transform", _transform_dec, ConnectionLine);
460
+ __decorateElement(_init, 5, "edgeScroll", _edgeScroll_dec, ConnectionLine);
429
461
  __decorateElement(_init, 5, "selected", _selected_dec, ConnectionLine);
462
+ __decorateElement(_init, 5, "isDragging", _isDragging_dec, ConnectionLine);
430
463
  __decorateElement(_init, 5, "getConnectHandleAttributes", _getConnectHandleAttributes_dec, ConnectionLine);
431
464
  __decorateElement(_init, 5, "registerCreator", _registerCreator_dec, ConnectionLine);
432
465
  __decoratorMetadata(_init, ConnectionLine);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/plugins-connection-line",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Connectionline Plugin for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -33,14 +33,15 @@
33
33
  "@interactjs/modifiers": "^1.10.27",
34
34
  "@interactjs/types": "^1.10.27",
35
35
  "interactjs": "^1.10.27",
36
- "@knotx/jsx": "0.4.0",
37
- "@knotx/plugins-selection": "0.4.0"
36
+ "@knotx/jsx": "0.4.2",
37
+ "@knotx/plugins-canvas": "0.4.2",
38
+ "@knotx/plugins-selection": "0.4.2"
38
39
  },
39
40
  "dependencies": {
40
41
  "lodash-es": "^4.17.21",
41
42
  "rxjs": "^7.8.1",
42
- "@knotx/core": "0.4.0",
43
- "@knotx/decorators": "0.4.0"
43
+ "@knotx/core": "0.4.2",
44
+ "@knotx/decorators": "0.4.2"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@interactjs/actions": "^1.10.27",
@@ -49,11 +50,12 @@
49
50
  "@interactjs/types": "^1.10.27",
50
51
  "@types/lodash-es": "^4.17.12",
51
52
  "interactjs": "^1.10.27",
52
- "@knotx/build-config": "0.4.0",
53
- "@knotx/eslint-config": "0.4.0",
54
- "@knotx/jsx": "0.4.0",
55
- "@knotx/plugins-selection": "0.4.0",
56
- "@knotx/typescript-config": "0.4.0"
53
+ "@knotx/build-config": "0.4.2",
54
+ "@knotx/eslint-config": "0.4.2",
55
+ "@knotx/jsx": "0.4.2",
56
+ "@knotx/plugins-canvas": "0.4.2",
57
+ "@knotx/plugins-selection": "0.4.2",
58
+ "@knotx/typescript-config": "0.4.2"
57
59
  },
58
60
  "scripts": {
59
61
  "build": "unbuild",