@neo4j-nvl/interaction-handlers
Advanced tools
Comparing version 0.2.22 to 0.2.23
export declare const NODE_EDGE_WIDTH = 10; | ||
export declare const DRAG_THRESHOLD = 10; |
export const NODE_EDGE_WIDTH = 10; | ||
export const DRAG_THRESHOLD = 10; |
@@ -94,2 +94,3 @@ import type { HitTargets, NVL, Node, Relationship } from '@neo4j-nvl/core'; | ||
private readonly options; | ||
private mousePosition; | ||
/** | ||
@@ -102,6 +103,5 @@ * Creates a new click interaction handler. | ||
private handleMouseDown; | ||
private handleMouseMove; | ||
private handleRightClick; | ||
private handleDoubleClick; | ||
private handleMouseUp; | ||
private handleClick; | ||
/** | ||
@@ -108,0 +108,0 @@ * Removes all related event listeners from the container. |
import { BaseInteraction } from './base'; | ||
import { isDraggingMovement } from './utils'; | ||
/** | ||
@@ -38,16 +39,14 @@ * Click interaction handler that handles click, double click and right click events on | ||
}); | ||
Object.defineProperty(this, "handleMouseDown", { | ||
Object.defineProperty(this, "mousePosition", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => { | ||
this.moved = false; | ||
} | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "handleMouseMove", { | ||
Object.defineProperty(this, "handleMouseDown", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: () => { | ||
this.moved = true; | ||
value: (event) => { | ||
this.mousePosition = { x: event.clientX, y: event.clientY }; | ||
} | ||
@@ -94,3 +93,3 @@ }); | ||
}); | ||
Object.defineProperty(this, "handleMouseUp", { | ||
Object.defineProperty(this, "handleClick", { | ||
enumerable: true, | ||
@@ -100,3 +99,3 @@ configurable: true, | ||
value: (event) => { | ||
if (this.moved || event.button !== 0) { | ||
if (isDraggingMovement(event, this.mousePosition) || event.button !== 0) { | ||
return; | ||
@@ -152,5 +151,4 @@ } | ||
this.removeEventListener('mousedown', this.handleMouseDown, true); | ||
this.removeEventListener('mousemove', this.handleMouseMove, true); | ||
this.removeEventListener('mouseup', this.handleMouseUp, true); | ||
this.removeEventListener('dblclick', this.handleMouseUp, true); | ||
this.removeEventListener('click', this.handleClick, true); | ||
this.removeEventListener('dblclick', this.handleClick, true); | ||
this.removeEventListener('contextmenu', this.handleRightClick, true); | ||
@@ -160,5 +158,5 @@ } | ||
this.options = options; | ||
this.mousePosition = { x: 0, y: 0 }; | ||
this.addEventListener('mousedown', this.handleMouseDown, true); | ||
this.addEventListener('mousemove', this.handleMouseMove, true); | ||
this.addEventListener('mouseup', this.handleMouseUp, true); | ||
this.addEventListener('click', this.handleClick, true); | ||
this.addEventListener('dblclick', this.handleDoubleClick, true); | ||
@@ -165,0 +163,0 @@ this.addEventListener('contextmenu', this.handleRightClick, true); |
import { NODE_EDGE_WIDTH } from '../constants'; | ||
import { BaseInteraction } from './base'; | ||
const DragThreshold = 10; | ||
import { isDraggingMovement } from './utils'; | ||
/** | ||
@@ -99,6 +99,3 @@ * Interaction handler for dragging nodes. | ||
} | ||
const diffX = Math.abs(evt.clientX - this.mousePosition.x); | ||
const diffY = Math.abs(evt.clientY - this.mousePosition.y); | ||
const distanceSquared = Math.pow(diffX, 2) + Math.pow(diffY, 2); | ||
if (distanceSquared < DragThreshold) { | ||
if (!isDraggingMovement(evt, this.mousePosition)) { | ||
return; | ||
@@ -105,0 +102,0 @@ } |
export declare const generateUniqueId: (digit: number) => string; | ||
export declare const isDraggingMovement: (event: MouseEvent, originalPosition: { | ||
x: number; | ||
y: number; | ||
}) => boolean; |
@@ -0,1 +1,11 @@ | ||
import { DRAG_THRESHOLD } from '../constants'; | ||
export const generateUniqueId = (digit) => Math.floor(Math.random() * Math.pow(10, digit)).toString(); | ||
export const isDraggingMovement = (event, originalPosition) => { | ||
const diffX = Math.abs(event.clientX - originalPosition.x); | ||
const diffY = Math.abs(event.clientY - originalPosition.y); | ||
if (diffX > DRAG_THRESHOLD || diffY > DRAG_THRESHOLD) { | ||
return true; | ||
} | ||
const distanceSquared = Math.pow(diffX, 2) + Math.pow(diffY, 2); | ||
return distanceSquared > DRAG_THRESHOLD; | ||
}; |
{ | ||
"name": "@neo4j-nvl/interaction-handlers", | ||
"version": "0.2.22", | ||
"version": "0.2.23", | ||
"license": "SEE LICENSE IN 'Neo4j Early Access Agreement - Visualization Library.pdf'", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
270617
1844