@neo4j-nvl/react 0.3.5-f46f9cc3 → 0.3.6-02e96ab6
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.
|
@@ -26,10 +26,14 @@ describe('BasicNvlWrapper', () => {
|
|
|
26
26
|
jest.spyOn(NVL.prototype, 'destroy').mockImplementation(destroy);
|
|
27
27
|
const { unmount } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [] }) }));
|
|
28
28
|
unmount();
|
|
29
|
-
expect(
|
|
29
|
+
expect(NVL).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(destroy).toHaveBeenCalledTimes(1);
|
|
30
31
|
});
|
|
31
32
|
test('successfully re-initialises NVL when using React StrictMode', () => {
|
|
33
|
+
const destroy = jest.fn();
|
|
34
|
+
jest.spyOn(NVL.prototype, 'destroy').mockImplementation(destroy);
|
|
32
35
|
render(_jsx(React.StrictMode, { children: _jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [] }) }) }));
|
|
33
36
|
expect(NVL).toHaveBeenCalledTimes(2);
|
|
37
|
+
expect(destroy).toHaveBeenCalledTimes(1);
|
|
34
38
|
});
|
|
35
39
|
});
|
|
@@ -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
|
|
@@ -63,7 +63,7 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
|
|
|
63
63
|
nvlRef.current = null;
|
|
64
64
|
};
|
|
65
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, [
|
|
66
|
+
}, []);
|
|
67
67
|
useEffect(() => {
|
|
68
68
|
if (nvlRef.current === null) {
|
|
69
69
|
return;
|
|
@@ -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
|
-
|
|
81
|
+
const updatedLayout = layout ?? nvlOptions.layout;
|
|
82
|
+
if (nvlRef.current === null || updatedLayout === undefined) {
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
|
-
nvlRef.current.setLayout(
|
|
85
|
-
}, [layout]);
|
|
85
|
+
nvlRef.current.setLayout(updatedLayout);
|
|
86
|
+
}, [layout, nvlOptions.layout]);
|
|
86
87
|
useDeepCompareEffect(() => {
|
|
87
|
-
|
|
88
|
+
const updatedLayoutOptions = layoutOptions ?? nvlOptions?.layoutOptions;
|
|
89
|
+
if (nvlRef.current === null || updatedLayoutOptions === undefined) {
|
|
88
90
|
return;
|
|
89
91
|
}
|
|
90
|
-
nvlRef.current.setLayoutOptions(
|
|
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.
|
|
3
|
+
"version": "0.3.6-02e96ab6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"homepage": "https://neo4j.com/docs/nvl/current/",
|
|
6
6
|
"license": "SEE LICENSE IN 'LICENSE.txt'",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"babel-eslint": "^10.1.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@neo4j-nvl/base": "0.3.
|
|
38
|
-
"@neo4j-nvl/interaction-handlers": "0.3.
|
|
37
|
+
"@neo4j-nvl/base": "0.3.6-02e96ab6",
|
|
38
|
+
"@neo4j-nvl/interaction-handlers": "0.3.6-02e96ab6",
|
|
39
39
|
"lodash": "4.17.21",
|
|
40
40
|
"react": "^18.2.0",
|
|
41
41
|
"react-dom": "^18.2.0"
|
|
42
42
|
},
|
|
43
|
-
"stableVersion": "0.3.
|
|
43
|
+
"stableVersion": "0.3.6"
|
|
44
44
|
}
|