@neo4j-nvl/interaction-handlers 0.2.22 → 0.2.24
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/lib/constants.d.ts +1 -0
- package/lib/constants.js +1 -0
- package/lib/interaction-handlers/click-interaction.d.ts +2 -2
- package/lib/interaction-handlers/click-interaction.js +12 -14
- package/lib/interaction-handlers/drag-node-interaction.js +2 -5
- package/lib/interaction-handlers/hover-interaction.js +1 -0
- package/lib/interaction-handlers/utils.d.ts +4 -0
- package/lib/interaction-handlers/utils.js +10 -0
- package/package.json +1 -1
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -91,6 +91,7 @@ export type ClickInteractionCallbacks = {
|
|
|
91
91
|
export declare class ClickInteraction extends BaseInteraction<ClickInteractionCallbacks> {
|
|
92
92
|
private moved;
|
|
93
93
|
private readonly options;
|
|
94
|
+
private mousePosition;
|
|
94
95
|
/**
|
|
95
96
|
* Creates a new click interaction handler.
|
|
96
97
|
* @param nvl - The NVL instance to attach the interaction handler to
|
|
@@ -98,10 +99,9 @@ export declare class ClickInteraction extends BaseInteraction<ClickInteractionCa
|
|
|
98
99
|
*/
|
|
99
100
|
constructor(nvl: NVL, options?: ClickInteractionOptions);
|
|
100
101
|
private handleMouseDown;
|
|
101
|
-
private handleMouseMove;
|
|
102
102
|
private handleRightClick;
|
|
103
103
|
private handleDoubleClick;
|
|
104
|
-
private
|
|
104
|
+
private handleClick;
|
|
105
105
|
/**
|
|
106
106
|
* Removes all related event listeners from the container.
|
|
107
107
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseInteraction } from './base';
|
|
2
|
+
import { isDraggingMovement } from './utils';
|
|
2
3
|
/**
|
|
3
4
|
* Click interaction handler that handles click, double click and right click events on
|
|
4
5
|
* nodes, relationships and canvas.
|
|
@@ -35,20 +36,18 @@ export class ClickInteraction extends BaseInteraction {
|
|
|
35
36
|
writable: true,
|
|
36
37
|
value: void 0
|
|
37
38
|
});
|
|
38
|
-
Object.defineProperty(this, "
|
|
39
|
+
Object.defineProperty(this, "mousePosition", {
|
|
39
40
|
enumerable: true,
|
|
40
41
|
configurable: true,
|
|
41
42
|
writable: true,
|
|
42
|
-
value:
|
|
43
|
-
this.moved = false;
|
|
44
|
-
}
|
|
43
|
+
value: void 0
|
|
45
44
|
});
|
|
46
|
-
Object.defineProperty(this, "
|
|
45
|
+
Object.defineProperty(this, "handleMouseDown", {
|
|
47
46
|
enumerable: true,
|
|
48
47
|
configurable: true,
|
|
49
48
|
writable: true,
|
|
50
|
-
value: () => {
|
|
51
|
-
this.
|
|
49
|
+
value: (event) => {
|
|
50
|
+
this.mousePosition = { x: event.clientX, y: event.clientY };
|
|
52
51
|
}
|
|
53
52
|
});
|
|
54
53
|
Object.defineProperty(this, "handleRightClick", {
|
|
@@ -90,12 +89,12 @@ export class ClickInteraction extends BaseInteraction {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
});
|
|
93
|
-
Object.defineProperty(this, "
|
|
92
|
+
Object.defineProperty(this, "handleClick", {
|
|
94
93
|
enumerable: true,
|
|
95
94
|
configurable: true,
|
|
96
95
|
writable: true,
|
|
97
96
|
value: (event) => {
|
|
98
|
-
if (this.
|
|
97
|
+
if (isDraggingMovement(event, this.mousePosition) || event.button !== 0) {
|
|
99
98
|
return;
|
|
100
99
|
}
|
|
101
100
|
const { nvlTargets } = this.nvlInstance.getHits(event);
|
|
@@ -146,16 +145,15 @@ export class ClickInteraction extends BaseInteraction {
|
|
|
146
145
|
writable: true,
|
|
147
146
|
value: () => {
|
|
148
147
|
this.removeEventListener('mousedown', this.handleMouseDown, true);
|
|
149
|
-
this.removeEventListener('
|
|
150
|
-
this.removeEventListener('
|
|
151
|
-
this.removeEventListener('dblclick', this.handleMouseUp, true);
|
|
148
|
+
this.removeEventListener('click', this.handleClick, true);
|
|
149
|
+
this.removeEventListener('dblclick', this.handleClick, true);
|
|
152
150
|
this.removeEventListener('contextmenu', this.handleRightClick, true);
|
|
153
151
|
}
|
|
154
152
|
});
|
|
155
153
|
this.options = options;
|
|
154
|
+
this.mousePosition = { x: 0, y: 0 };
|
|
156
155
|
this.addEventListener('mousedown', this.handleMouseDown, true);
|
|
157
|
-
this.addEventListener('
|
|
158
|
-
this.addEventListener('mouseup', this.handleMouseUp, true);
|
|
156
|
+
this.addEventListener('click', this.handleClick, true);
|
|
159
157
|
this.addEventListener('dblclick', this.handleDoubleClick, true);
|
|
160
158
|
this.addEventListener('contextmenu', this.handleRightClick, true);
|
|
161
159
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NODE_EDGE_WIDTH } from '../constants';
|
|
2
2
|
import { BaseInteraction } from './base';
|
|
3
|
-
|
|
3
|
+
import { isDraggingMovement } from './utils';
|
|
4
4
|
/**
|
|
5
5
|
* Interaction handler for dragging nodes.
|
|
6
6
|
* Dragging is achieved by clicking and dragging on the node.
|
|
@@ -96,10 +96,7 @@ export class DragNodeInteraction extends BaseInteraction {
|
|
|
96
96
|
if (this.mouseDownNode === null || evt.buttons !== 1 || this.isDrawing) {
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
const diffY = Math.abs(evt.clientY - this.mousePosition.y);
|
|
101
|
-
const distanceSquared = Math.pow(diffX, 2) + Math.pow(diffY, 2);
|
|
102
|
-
if (distanceSquared < DragThreshold) {
|
|
99
|
+
if (!isDraggingMovement(evt, this.mousePosition)) {
|
|
103
100
|
return;
|
|
104
101
|
}
|
|
105
102
|
if (!this.isDragging) {
|
|
@@ -76,6 +76,7 @@ export class HoverInteraction extends BaseInteraction {
|
|
|
76
76
|
this.callCallbackIfRegistered('onHover', this.currentHoveredElement, nvlTargets, event);
|
|
77
77
|
// Use pure update API to avoid the previous removed node to be re-added to the scene.
|
|
78
78
|
this.options.drawShadowOnHover &&
|
|
79
|
+
this.nvlInstance.nodes.length > 0 &&
|
|
79
80
|
this.nvlInstance.updateElementsInGraph(this.updates.nodes, this.updates.relationships);
|
|
80
81
|
this.clearUpdates();
|
|
81
82
|
}
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
import { DRAG_THRESHOLD } from '../constants';
|
|
1
2
|
export const generateUniqueId = (digit) => Math.floor(Math.random() * Math.pow(10, digit)).toString();
|
|
3
|
+
export const isDraggingMovement = (event, originalPosition) => {
|
|
4
|
+
const diffX = Math.abs(event.clientX - originalPosition.x);
|
|
5
|
+
const diffY = Math.abs(event.clientY - originalPosition.y);
|
|
6
|
+
if (diffX > DRAG_THRESHOLD || diffY > DRAG_THRESHOLD) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const distanceSquared = Math.pow(diffX, 2) + Math.pow(diffY, 2);
|
|
10
|
+
return distanceSquared > DRAG_THRESHOLD;
|
|
11
|
+
};
|