@neo4j-nvl/react 0.3.6-7b6d0ac4 → 0.3.6-800b1623

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.
@@ -23,6 +23,8 @@ export interface BasicReactWrapperProps {
23
23
  nvlCallbacks?: ExternalCallbacks;
24
24
  /** An object containing options for the Nvl instance */
25
25
  nvlOptions?: NvlOptions;
26
+ /** Sets the positions of the nodes in the graph using the {@link NVL.setNodePositions} method. */
27
+ positions?: Node[];
26
28
  /** A callback to handle any errors that happen during NVL initialization */
27
29
  onInitializationError?: (error: unknown) => void;
28
30
  }
@@ -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 = {}, onInitializationError, ...nvlEvents }, ref) => {
15
+ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, nvlCallbacks = {}, nvlOptions = {}, positions = [], onInitializationError, ...nvlEvents }, ref) => {
16
16
  const nvlRef = useRef(null);
17
17
  useImperativeHandle(ref, () => {
18
18
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -78,17 +78,19 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
78
78
  nvlRef.current.removeNodesWithIds(nodeChanges.removed.map((n) => n.id));
79
79
  }, [currentNodes, currentRels, nodes, rels]);
80
80
  useEffect(() => {
81
- if (nvlRef.current === null || layout === undefined) {
81
+ const updatedLayout = layout ?? nvlOptions.layout;
82
+ if (nvlRef.current === null || updatedLayout === undefined) {
82
83
  return;
83
84
  }
84
- nvlRef.current.setLayout(layout);
85
- }, [layout]);
85
+ nvlRef.current.setLayout(updatedLayout);
86
+ }, [layout, nvlOptions.layout]);
86
87
  useDeepCompareEffect(() => {
87
- if (nvlRef.current === null || layoutOptions === undefined) {
88
+ const updatedLayoutOptions = layoutOptions ?? nvlOptions?.layoutOptions;
89
+ if (nvlRef.current === null || updatedLayoutOptions === undefined) {
88
90
  return;
89
91
  }
90
- nvlRef.current.setLayoutOptions(layoutOptions);
91
- }, [layoutOptions]);
92
+ nvlRef.current.setLayoutOptions(updatedLayoutOptions);
93
+ }, [layoutOptions, nvlOptions.layoutOptions]);
92
94
  useEffect(() => {
93
95
  if (nvlRef.current === null || nvlOptions.useWebGL === undefined) {
94
96
  return;
@@ -107,5 +109,11 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
107
109
  }
108
110
  nvlRef.current.setDisableWebGL(nvlOptions.disableWebGL);
109
111
  }, [nvlOptions.disableWebGL]);
112
+ useEffect(() => {
113
+ if (nvlRef.current === null || positions.length === 0) {
114
+ return;
115
+ }
116
+ nvlRef.current.setNodePositions(positions);
117
+ }, [positions]);
110
118
  return _jsx("div", { id: BASIC_WRAPPER_ID, ref: containerRef, style: { height: '100%', outline: '0' }, ...nvlEvents });
111
119
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/react",
3
- "version": "0.3.6-7b6d0ac4",
3
+ "version": "0.3.6-800b1623",
4
4
  "main": "lib/index.js",
5
5
  "homepage": "https://neo4j.com/docs/nvl/current/",
6
6
  "license": "SEE LICENSE IN 'LICENSE.txt'",
@@ -34,8 +34,8 @@
34
34
  "babel-eslint": "^10.1.0"
35
35
  },
36
36
  "dependencies": {
37
- "@neo4j-nvl/base": "0.3.6-7b6d0ac4",
38
- "@neo4j-nvl/interaction-handlers": "0.3.6-7b6d0ac4",
37
+ "@neo4j-nvl/base": "0.3.6-800b1623",
38
+ "@neo4j-nvl/interaction-handlers": "0.3.6-800b1623",
39
39
  "lodash": "4.17.21",
40
40
  "react": "^18.2.0",
41
41
  "react-dom": "^18.2.0"