feat(rfInstance): add getElements function #274
This commit is contained in:
@@ -11,7 +11,7 @@ import useD3Zoom from '../../hooks/useD3Zoom';
|
||||
import useGlobalKeyHandler from '../../hooks/useGlobalKeyHandler';
|
||||
import useElementUpdater from '../../hooks/useElementUpdater';
|
||||
import { getDimensions } from '../../utils';
|
||||
import { fitView, zoomIn, zoomOut, project } from '../../utils/graph';
|
||||
import { fitView, zoomIn, zoomOut, project, getElements } from '../../utils/graph';
|
||||
import {
|
||||
Elements,
|
||||
NodeTypesType,
|
||||
@@ -133,6 +133,7 @@ const GraphView = memo(
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
project,
|
||||
getElements,
|
||||
});
|
||||
}
|
||||
}, [d3Initialised, onLoad]);
|
||||
|
||||
@@ -144,6 +144,7 @@ type OnLoadParams = {
|
||||
zoomOut: () => void;
|
||||
fitView: FitViewFunc;
|
||||
project: ProjectFunc;
|
||||
getElements: () => Elements;
|
||||
};
|
||||
|
||||
export type OnLoadFunc = (params: OnLoadParams) => void;
|
||||
|
||||
@@ -210,3 +210,17 @@ const zoom = (amount: number): void => {
|
||||
export const zoomIn = (): void => zoom(0.2);
|
||||
|
||||
export const zoomOut = (): void => zoom(-0.2);
|
||||
|
||||
export const getElements = (): Elements => {
|
||||
const { nodes, edges } = store.getState();
|
||||
|
||||
return [
|
||||
...nodes.map((node) => {
|
||||
const n = { ...node };
|
||||
|
||||
delete n.__rg;
|
||||
return n;
|
||||
}),
|
||||
...edges.map((e) => ({ ...e })),
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user