@neo4j-nvl/interaction-handlers 0.2.14 → 0.2.15

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.
@@ -1,5 +1,6 @@
1
1
  import { NODE_EDGE_WIDTH } from '../constants';
2
2
  import { BaseInteraction } from './base';
3
+ const DragThreshold = 10;
3
4
  /**
4
5
  * Interaction handler for dragging nodes.
5
6
  * Dragging is achieved by clicking and dragging on the node.
@@ -72,7 +73,7 @@ export class DragNodeInteraction extends BaseInteraction {
72
73
  this.mouseDownNode = null;
73
74
  }
74
75
  this.selectedNodes = this.nvlInstance.getSelectedNodes();
75
- if (this.mouseDownNode && this.selectedNodes.map((node) => node.id).includes(this.mouseDownNode.data.id)) {
76
+ if (this.mouseDownNode !== null && this.selectedNodes.map((node) => node.id).includes(this.mouseDownNode.data.id)) {
76
77
  this.moveSelectedNodes = true;
77
78
  }
78
79
  else {
@@ -86,8 +87,15 @@ export class DragNodeInteraction extends BaseInteraction {
86
87
  writable: true,
87
88
  value: (event) => {
88
89
  // Avoid conflicts on moving node position in drawing process.
89
- if (!this.mouseDownNode || event.buttons !== 1 || this.isDrawing)
90
+ if (this.mouseDownNode === null || event.buttons !== 1 || this.isDrawing) {
90
91
  return;
92
+ }
93
+ const diffX = Math.abs(event.clientX - this.mousePosition.x);
94
+ const diffY = Math.abs(event.clientY - this.mousePosition.y);
95
+ const distanceSquared = Math.pow(diffX, 2) + Math.pow(diffY, 2);
96
+ if (distanceSquared < DragThreshold) {
97
+ return;
98
+ }
91
99
  const zoom = this.nvlInstance.getScale();
92
100
  const dx = ((event.clientX - this.mousePosition.x) / zoom) * window.devicePixelRatio;
93
101
  const dy = ((event.clientY - this.mousePosition.y) / zoom) * window.devicePixelRatio;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/interaction-handlers",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "license": "SEE LICENSE IN 'Neo4j Early Access Agreement - Visualization Library.pdf'",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",