@neo4j-nvl/react 1.2.0-ec100981 → 1.2.0-eea71f07

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.
@@ -27,7 +27,11 @@ describe('BasicNvlWrapper', () => {
27
27
  });
28
28
  test('initialises NVL expectedly with a graph object and properties', () => {
29
29
  const mockLayoutDoneFunction = jest.fn();
30
- render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [{ id: '1' }, { id: '2' }], rels: [{ id: '12', from: '1', to: '2' }], layout: HierarchicalLayoutType, layoutOptions: { direction: 'down' }, nvlOptions: { renderer: 'canvas' }, nvlCallbacks: { onLayoutDone: mockLayoutDoneFunction } }) }));
30
+ render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [{ id: '1' }, { id: '2' }], rels: [{ id: '12', from: '1', to: '2' }], nvlOptions: {
31
+ renderer: 'canvas',
32
+ layout: HierarchicalLayoutType,
33
+ layoutOptions: { direction: 'down' }
34
+ }, nvlCallbacks: { onLayoutDone: mockLayoutDoneFunction } }) }));
31
35
  expect(NVL).toHaveBeenCalledWith(expect.any(HTMLDivElement), [{ id: '1' }, { id: '2' }], [{ id: '12', from: '1', to: '2' }], { renderer: 'canvas', layout: HierarchicalLayoutType, layoutOptions: { direction: 'down' } }, {
32
36
  onLayoutDone: mockLayoutDoneFunction
33
37
  });
@@ -132,4 +136,24 @@ describe('BasicNvlWrapper', () => {
132
136
  expect(setZoomAndPan).toHaveBeenCalledTimes(1);
133
137
  expect(setZoom).not.toHaveBeenCalled();
134
138
  });
139
+ test('calls setLayout when nvlOptions.layout changes', () => {
140
+ const setLayout = jest.fn();
141
+ jest.spyOn(NVL.prototype, 'setLayout').mockImplementation(setLayout);
142
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], nvlOptions: { layout: HierarchicalLayoutType } }) }));
143
+ expect(setLayout).toHaveBeenCalledWith(HierarchicalLayoutType);
144
+ expect(setLayout).toHaveBeenCalledTimes(1);
145
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], nvlOptions: { layout: 'forceDirected' } }) }));
146
+ expect(setLayout).toHaveBeenCalledWith('forceDirected');
147
+ expect(setLayout).toHaveBeenCalledTimes(2);
148
+ });
149
+ test('calls setLayoutOptions when nvlOptions.layoutOptions changes', () => {
150
+ const setLayoutOptions = jest.fn();
151
+ jest.spyOn(NVL.prototype, 'setLayoutOptions').mockImplementation(setLayoutOptions);
152
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], nvlOptions: { layoutOptions: { direction: 'down' } } }) }));
153
+ expect(setLayoutOptions).toHaveBeenCalledWith({ direction: 'down' });
154
+ expect(setLayoutOptions).toHaveBeenCalledTimes(1);
155
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], nvlOptions: { layoutOptions: { direction: 'up' } } }) }));
156
+ expect(setLayoutOptions).toHaveBeenCalledWith({ direction: 'up' });
157
+ expect(setLayoutOptions).toHaveBeenCalledTimes(2);
158
+ });
135
159
  });
@@ -85,7 +85,11 @@ describe('InteractiveNvlWrapper', () => {
85
85
  });
86
86
  test('initialises NVL expectedly with a graph object and properties', () => {
87
87
  const mockLayoutDoneFunction = jest.fn();
88
- render(_jsx(InteractiveNvlWrapper, { nodes: [{ id: '1' }, { id: '2' }], rels: [{ id: '12', from: '1', to: '2' }], layout: HierarchicalLayoutType, layoutOptions: { direction: 'down' }, nvlOptions: { renderer: 'canvas' }, nvlCallbacks: { onLayoutDone: mockLayoutDoneFunction } }));
88
+ render(_jsx(InteractiveNvlWrapper, { nodes: [{ id: '1' }, { id: '2' }], rels: [{ id: '12', from: '1', to: '2' }], nvlOptions: {
89
+ renderer: 'canvas',
90
+ layout: HierarchicalLayoutType,
91
+ layoutOptions: { direction: 'down' }
92
+ }, nvlCallbacks: { onLayoutDone: mockLayoutDoneFunction } }));
89
93
  act(() => {
90
94
  mockOnInitialization?.();
91
95
  });
@@ -187,7 +191,7 @@ describe('InteractiveNvlWrapper', () => {
187
191
  {
188
192
  name: 'ZoomInteraction',
189
193
  InteractionClass: ZoomInteraction,
190
- callback: { onZoom: jest.fn() },
194
+ callback: { onZoomAndPan: jest.fn() },
191
195
  options: {}
192
196
  },
193
197
  {
@@ -1,4 +1,4 @@
1
- import type { ExternalCallbacks, Layout, LayoutOptions, Node, NvlOptions, Relationship } from '@neo4j-nvl/base';
1
+ import type { ExternalCallbacks, Node, NvlOptions, Relationship } from '@neo4j-nvl/base';
2
2
  import NVL from '@neo4j-nvl/base';
3
3
  import { type HTMLProps } from 'react';
4
4
  /**
@@ -9,17 +9,6 @@ export interface BasicReactWrapperProps {
9
9
  nodes: Node[];
10
10
  /** The rels of the graph of type Relationship[] */
11
11
  rels: Relationship[];
12
- /**
13
- * The layout, can be 'forceDirected' or 'hierarchical'
14
- * @deprecated Use the layout property in nvlOptions instead. This property will be removed in a future version.
15
- */
16
- layout?: Layout;
17
- /**
18
- * Options for the current layout
19
- * @deprecated Use `layoutOptions` property in {@link nvlOptions} instead.
20
- * This property will be removed in a future version.
21
- */
22
- layoutOptions?: LayoutOptions;
23
12
  /** an Object containing functions for callbacks on certain actions */
24
13
  nvlCallbacks?: ExternalCallbacks;
25
14
  /** An object containing options for the Nvl instance */
@@ -12,7 +12,7 @@ import { useDeepCompareEffect } from '../utils/hooks';
12
12
  *
13
13
  * For examples, head to the {@link https://neo4j.com/docs/nvl/current/react-wrappers/#_basic_react_wrapper Basic React wrapper documentation page}.
14
14
  */
15
- export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, nvlCallbacks = {}, nvlOptions = {}, positions = [], zoom, pan, onInitializationError, ...nvlEvents }, ref) => {
15
+ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, nvlCallbacks = {}, nvlOptions = {}, positions = [], zoom, pan, onInitializationError, ...nvlEvents }, ref) => {
16
16
  const nvlRef = useRef(null);
17
17
  const prevZoomRef = useRef(undefined);
18
18
  const prevPanRef = useRef(undefined);
@@ -47,12 +47,8 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
47
47
  const mainContainerIsReady = containerRef.current !== null;
48
48
  if (mainContainerIsReady && minimapContainerIsReady) {
49
49
  if (nvlRef.current === null) {
50
- const combinedOptions = { ...nvlOptions, layoutOptions };
51
- if (layout !== undefined) {
52
- combinedOptions.layout = layout;
53
- }
54
50
  try {
55
- newNvl = new NVL(containerRef.current, currentNodes, currentRels, combinedOptions, nvlCallbacks);
51
+ newNvl = new NVL(containerRef.current, currentNodes, currentRels, nvlOptions, nvlCallbacks);
56
52
  nvlRef.current = newNvl;
57
53
  setCurrentRels(rels);
58
54
  setCurrentNodes(nodes);
@@ -96,19 +92,17 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
96
92
  nvlRef.current.removeNodesWithIds(nodesToRemove);
97
93
  }, [currentNodes, currentRels, nodes, rels]);
98
94
  useEffect(() => {
99
- const updatedLayout = layout ?? nvlOptions.layout;
100
- if (nvlRef.current === null || updatedLayout === undefined) {
95
+ if (nvlRef.current === null || nvlOptions.layout === undefined) {
101
96
  return;
102
97
  }
103
- nvlRef.current.setLayout(updatedLayout);
104
- }, [layout, nvlOptions.layout]);
98
+ nvlRef.current.setLayout(nvlOptions.layout);
99
+ }, [nvlOptions.layout]);
105
100
  useDeepCompareEffect(() => {
106
- const updatedLayoutOptions = layoutOptions ?? nvlOptions?.layoutOptions;
107
- if (nvlRef.current === null || updatedLayoutOptions === undefined) {
101
+ if (nvlRef.current === null || nvlOptions.layoutOptions === undefined) {
108
102
  return;
109
103
  }
110
- nvlRef.current.setLayoutOptions(updatedLayoutOptions);
111
- }, [layoutOptions, nvlOptions.layoutOptions]);
104
+ nvlRef.current.setLayoutOptions(nvlOptions.layoutOptions);
105
+ }, [nvlOptions.layoutOptions]);
112
106
  useEffect(() => {
113
107
  if (nvlRef.current === null || nvlOptions.renderer === undefined) {
114
108
  return;
@@ -22,7 +22,6 @@ export const InteractionHandlers = ({ nvlRef, mouseEventCallbacks, keyboardEvent
22
22
  useInteraction(ClickInteraction, clickInteraction, mouseEventCallbacks.onCanvasDoubleClick, 'onCanvasDoubleClick', nvlRef, interactionOptions);
23
23
  useInteraction(ClickInteraction, clickInteraction, mouseEventCallbacks.onCanvasRightClick, 'onCanvasRightClick', nvlRef, interactionOptions);
24
24
  useInteraction(PanInteraction, panInteraction, mouseEventCallbacks.onPan, 'onPan', nvlRef, interactionOptions);
25
- useInteraction(ZoomInteraction, zoomInteraction, mouseEventCallbacks.onZoom, 'onZoom', nvlRef, interactionOptions);
26
25
  useInteraction(ZoomInteraction, zoomInteraction, mouseEventCallbacks.onZoomAndPan, 'onZoomAndPan', nvlRef, interactionOptions);
27
26
  useInteraction(DragNodeInteraction, dragNodeInteraction, mouseEventCallbacks.onDrag, 'onDrag', nvlRef, interactionOptions);
28
27
  useInteraction(DragNodeInteraction, dragNodeInteraction, mouseEventCallbacks.onDragStart, 'onDragStart', nvlRef, interactionOptions);
@@ -20,7 +20,7 @@ const options = {
20
20
  *
21
21
  * For examples, head to the {@link https://neo4j.com/docs/nvl/current/react-wrappers/#_interactive_reactive_wrapperr Interactive React wrapper documentation page}.
22
22
  */
23
- export const InteractiveNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, onInitializationError, mouseEventCallbacks = {}, keyboardEventCallbacks = {}, nvlCallbacks = {}, nvlOptions = {}, interactionOptions = options, ...nvlEvents }, nvlRef) => {
23
+ export const InteractiveNvlWrapper = memo(forwardRef(({ nodes, rels, onInitializationError, mouseEventCallbacks = {}, keyboardEventCallbacks = {}, nvlCallbacks = {}, nvlOptions = {}, interactionOptions = options, ...nvlEvents }, nvlRef) => {
24
24
  const newNvlRef = useRef(null);
25
25
  const myNvlRef = nvlRef ?? newNvlRef;
26
26
  const [isNvlInitialized, setIsNvlInitialized] = useState(false);
@@ -42,5 +42,5 @@ export const InteractiveNvlWrapper = memo(forwardRef(({ nodes, rels, layout, lay
42
42
  }
43
43
  handleInitialization();
44
44
  }
45
- }, layout: layout, layoutOptions: layoutOptions, onInitializationError: handleInitializationError, ...nvlEvents }), setupInteractions && (_jsx(InteractionHandlers, { nvlRef: myNvlRef, mouseEventCallbacks: mouseEventCallbacks, keyboardEventCallbacks: keyboardEventCallbacks, interactionOptions: interactionOptions }))] }));
45
+ }, onInitializationError: handleInitializationError, ...nvlEvents }), setupInteractions && (_jsx(InteractionHandlers, { nvlRef: myNvlRef, mouseEventCallbacks: mouseEventCallbacks, keyboardEventCallbacks: keyboardEventCallbacks, interactionOptions: interactionOptions }))] }));
46
46
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/react",
3
- "version": "1.2.0-ec100981",
3
+ "version": "1.2.0-eea71f07",
4
4
  "main": "lib/index.js",
5
5
  "homepage": "https://neo4j.com/docs/nvl/current/",
6
6
  "license": "SEE LICENSE IN 'LICENSE.txt'",
@@ -36,8 +36,8 @@
36
36
  "react-dom": "19.2.1"
37
37
  },
38
38
  "dependencies": {
39
- "@neo4j-nvl/base": "1.2.0-ec100981",
40
- "@neo4j-nvl/interaction-handlers": "1.2.0-ec100981",
39
+ "@neo4j-nvl/base": "1.2.0-eea71f07",
40
+ "@neo4j-nvl/interaction-handlers": "1.2.0-eea71f07",
41
41
  "lodash": "4.18.1"
42
42
  },
43
43
  "peerDependencies": {