@neo4j-nvl/react 0.3.6-e7f05fb1 → 0.3.6-f1ebcb95
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;
|
|
@@ -107,5 +107,11 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
|
|
|
107
107
|
}
|
|
108
108
|
nvlRef.current.setDisableWebGL(nvlOptions.disableWebGL);
|
|
109
109
|
}, [nvlOptions.disableWebGL]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (nvlRef.current === null || positions.length === 0) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
nvlRef.current.setNodePositions(positions);
|
|
115
|
+
}, [positions]);
|
|
110
116
|
return _jsx("div", { id: BASIC_WRAPPER_ID, ref: containerRef, style: { height: '100%', outline: '0' }, ...nvlEvents });
|
|
111
117
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-nvl/react",
|
|
3
|
-
"version": "0.3.6-
|
|
3
|
+
"version": "0.3.6-f1ebcb95",
|
|
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-
|
|
38
|
-
"@neo4j-nvl/interaction-handlers": "0.3.6-
|
|
37
|
+
"@neo4j-nvl/base": "0.3.6-f1ebcb95",
|
|
38
|
+
"@neo4j-nvl/interaction-handlers": "0.3.6-f1ebcb95",
|
|
39
39
|
"lodash": "4.17.21",
|
|
40
40
|
"react": "^18.2.0",
|
|
41
41
|
"react-dom": "^18.2.0"
|