@neo4j-nvl/interaction-handlers 0.2.8 → 0.2.9

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/index.d.ts CHANGED
@@ -3,13 +3,14 @@ import { ClickInteraction } from './interaction-handlers/click-interaction';
3
3
  import { DragNodeInteraction } from './interaction-handlers/drag-node-interaction';
4
4
  import type { DragNodeInteractionCallbacks } from './interaction-handlers/drag-node-interaction';
5
5
  import { DrawInteraction } from './interaction-handlers/draw-interaction';
6
+ import type { DrawInteractionCallbacks } from './interaction-handlers/draw-interaction';
6
7
  import type { HoverInteractionOptions, HoverInteractionCallbacks } from './interaction-handlers/hover-interaction';
7
8
  import { HoverInteraction } from './interaction-handlers/hover-interaction';
8
- import type { MultiSelectInteractionOptions } from './interaction-handlers/multi-select-interaction';
9
+ import type { MultiSelectInteractionOptions, MultiSelectInteractionCallbacks } from './interaction-handlers/multi-select-interaction';
9
10
  import { MultiSelectInteraction } from './interaction-handlers/multi-select-interaction';
10
11
  import type { PanInteractionCallbacks } from './interaction-handlers/pan-interaction';
11
12
  import { PanInteraction } from './interaction-handlers/pan-interaction';
12
13
  import type { ZoomInteractionCallbacks } from './interaction-handlers/zoom-interaction';
13
14
  import { ZoomInteraction } from './interaction-handlers/zoom-interaction';
14
- export type { MultiSelectInteractionOptions, ClickInteractionOptions, HoverInteractionOptions, HoverInteractionCallbacks, DragNodeInteractionCallbacks, ClickInteractionCallbacks, PanInteractionCallbacks, ZoomInteractionCallbacks };
15
+ export type { MultiSelectInteractionOptions, MultiSelectInteractionCallbacks, ClickInteractionOptions, HoverInteractionOptions, HoverInteractionCallbacks, DragNodeInteractionCallbacks, ClickInteractionCallbacks, PanInteractionCallbacks, ZoomInteractionCallbacks, DrawInteractionCallbacks };
15
16
  export { ZoomInteraction, PanInteraction, MultiSelectInteraction, ClickInteraction, HoverInteraction, DragNodeInteraction, DrawInteraction };
@@ -4,7 +4,7 @@ import { NVL } from '@neo4j-nvl/core';
4
4
  * @abstract
5
5
  * @internal
6
6
  */
7
- declare abstract class BaseInteraction<T extends Record<string, (...args: unknown[]) => void>> {
7
+ declare abstract class BaseInteraction<T extends Record<string, ((...args: unknown[]) => void) | boolean>> {
8
8
  private readonly nvl;
9
9
  private readonly container;
10
10
  /**
@@ -34,7 +34,7 @@ declare abstract class BaseInteraction<T extends Record<string, (...args: unknow
34
34
  /**
35
35
  * @internal
36
36
  */
37
- callCallbackIfRegistered: (name: keyof T, ...args: Parameters<T[keyof T]>) => void;
37
+ callCallbackIfRegistered: (name: keyof T, ...args: any) => void;
38
38
  /**
39
39
  * Add or update a callback for a given event of type.
40
40
  * @param name - The name of the event
@@ -60,7 +60,7 @@ class BaseInteraction {
60
60
  writable: true,
61
61
  value: (name, ...args) => {
62
62
  const callback = this.callbackMap.get(name);
63
- if (callback) {
63
+ if (typeof callback === 'function') {
64
64
  callback(...args);
65
65
  }
66
66
  }
@@ -20,57 +20,57 @@ export type ClickInteractionCallbacks = {
20
20
  * @param hitElements - All elements that were hit by the click
21
21
  * @param event - The original mouse event
22
22
  */
23
- onNodeClick: (nodes: Node, hitElements: HitTargets, event: MouseEvent) => void;
23
+ onNodeClick?: ((nodes: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
24
24
  /**
25
25
  * Called when a relationship is clicked
26
26
  * @param relationship - The relationship that was clicked
27
27
  * @param hitElements - All elements that were hit by the click
28
28
  * @param event - The original mouse event
29
29
  */
30
- onRelationshipClick: (relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void;
30
+ onRelationshipClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
31
31
  /**
32
32
  * Called when the canvas is clicked
33
33
  * @param event - The original mouse event
34
34
  */
35
- onCanvasClick: (event: MouseEvent) => void;
35
+ onCanvasClick?: ((event: MouseEvent) => void) | boolean;
36
36
  /**
37
37
  * Called when a node is double clicked
38
38
  * @param event - The original mouse event
39
39
  */
40
- onCanvasDoubleClick: (event: MouseEvent) => void;
40
+ onCanvasDoubleClick?: ((event: MouseEvent) => void) | boolean;
41
41
  /**
42
42
  * Called when a relationship is right-clicked
43
43
  * @param event - The original mouse event
44
44
  */
45
- onCanvasRightClick: (event: MouseEvent) => void;
45
+ onCanvasRightClick?: ((event: MouseEvent) => void) | boolean;
46
46
  /**
47
47
  * Called when a node is double-clicked
48
48
  * @param nodes - The node that was double-clicked
49
49
  * @param hitElements - All elements that were hit by the double-click
50
50
  * @param event - The original mouse event
51
51
  */
52
- onNodeDoubleClick: (node: Node, hitElements: HitTargets, event: MouseEvent) => void;
52
+ onNodeDoubleClick?: ((node: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
53
53
  /**
54
54
  * Called when a node is right-clicked
55
55
  * @param nodes - The node that was right-clicked
56
56
  * @param hitElements - All elements that were hit by the right-click
57
57
  * @param event - The original mouse event
58
58
  */
59
- onNodeRightClick: (node: Node, hitElements: HitTargets, event: MouseEvent) => void;
59
+ onNodeRightClick?: ((node: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
60
60
  /**
61
61
  * Called when a relationship is double-clicked
62
62
  * @param relationship - The relationship that was double-clicked
63
63
  * @param hitElements - All elements that were hit by the double-click
64
64
  * @param event - The original mouse event
65
65
  */
66
- onRelationshipDoubleClick: (relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void;
66
+ onRelationshipDoubleClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
67
67
  /**
68
68
  * Called when a relationship is right-clicked
69
69
  * @param relationship - The relationship that was right-clicked
70
70
  * @param hitElements - All elements that were hit by the right-click
71
71
  * @param event - The original mouse event
72
72
  */
73
- onRelationshipRightClick: (relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void;
73
+ onRelationshipRightClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
74
74
  };
75
75
  /**
76
76
  * Click interaction handler that handles click, double click and right click events on
@@ -8,7 +8,7 @@ export type DragNodeInteractionCallbacks = {
8
8
  * Called when node(s) are dragged
9
9
  * @param nodes - The node(s) being dragged
10
10
  */
11
- onDrag: (nodes: Node[]) => void;
11
+ onDrag?: ((nodes: Node[]) => void) | boolean;
12
12
  };
13
13
  /**
14
14
  * Interaction handler for dragging nodes.
@@ -2,10 +2,16 @@ import { NVL, Node, Relationship } from '@neo4j-nvl/core';
2
2
  import { BaseInteraction } from './base';
3
3
  /**
4
4
  * @internal
5
+ * @experimental
5
6
  */
6
- export declare class DrawInteraction extends BaseInteraction<{
7
- onDrawEnd: (newRelationshipToAdd: Relationship | null, newTargetNodeToAdd: Node | null) => void;
8
- }> {
7
+ export type DrawInteractionCallbacks = {
8
+ onDrawEnd?: ((newRelationshipToAdd: Relationship | null, newTargetNodeToAdd: Node | null) => void) | boolean;
9
+ };
10
+ /**
11
+ * @internal
12
+ * @experimental
13
+ */
14
+ export declare class DrawInteraction extends BaseInteraction<DrawInteractionCallbacks> {
9
15
  private overlayRenderer;
10
16
  private isMoved;
11
17
  private isDrawing;
@@ -4,6 +4,7 @@ import { NODE_EDGE_WIDTH } from '../constants';
4
4
  import { BaseInteraction } from './base';
5
5
  /**
6
6
  * @internal
7
+ * @experimental
7
8
  */
8
9
  export class DrawInteraction extends BaseInteraction {
9
10
  constructor(nvl) {
@@ -22,7 +22,7 @@ export type HoverInteractionCallbacks = {
22
22
  * @note This callback is called every time the mouse moves,
23
23
  * even when no element is hovered or the current element is already hovered.
24
24
  */
25
- onHover: (element: Node | Relationship, hitElements: HitTargets, event: MouseEvent) => void;
25
+ onHover?: ((element: Node | Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
26
26
  };
27
27
  /**
28
28
  * Interaction handler for hovering nodes and relationships.
@@ -16,10 +16,10 @@ export type MultiSelectInteractionCallbacks = {
16
16
  * @param nodes - The nodes that were selected
17
17
  * @param rels - The relationships that were selected
18
18
  */
19
- onMultiSelect: ({ nodes, rels }: {
19
+ onMultiSelect?: (({ nodes, rels }: {
20
20
  nodes: Node[];
21
21
  rels: Relationship[];
22
- }) => void;
22
+ }) => void) | boolean;
23
23
  };
24
24
  /**
25
25
  * Interaction handler for multi-selecting nodes and relationships.
@@ -8,10 +8,10 @@ export type PanInteractionCallbacks = {
8
8
  * Called when the canvas is panned.
9
9
  * @param panning - The panning coordinates
10
10
  */
11
- onPan: (panning: {
11
+ onPan?: ((panning: {
12
12
  x: number;
13
13
  y: number;
14
- }) => void;
14
+ }) => void) | boolean;
15
15
  };
16
16
  /**
17
17
  * Interaction handler for panning the canvas.
@@ -8,7 +8,7 @@ export type ZoomInteractionCallbacks = {
8
8
  * Called when the canvas is zoomed.
9
9
  * @param zoomLevel - The zoom level
10
10
  */
11
- onZoom: (zoomLevel: number) => void;
11
+ onZoom?: (zoomLevel: number) => void | boolean;
12
12
  };
13
13
  /**
14
14
  * Interaction handler for zooming the canvas.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/interaction-handlers",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",