feat(reactflowInstance): add toObject function closes #603

This commit is contained in:
moklick
2020-11-09 18:17:36 +01:00
parent 2db5a7bce2
commit 7cc2306975
4 changed files with 45 additions and 6 deletions
+24 -1
View File
@@ -1,6 +1,17 @@
import { Store } from 'easy-peasy';
import { StoreModel } from '../store';
import { ElementId, Node, Edge, Elements, Transform, XYPosition, Rect, Box, Connection } from '../types';
import {
ElementId,
Node,
Edge,
Elements,
Transform,
XYPosition,
Rect,
Box,
Connection,
FlowExportObject,
} from '../types';
export const isEdge = (element: Node | Connection | Edge): element is Edge =>
'id' in element && 'source' in element && 'target' in element;
@@ -236,3 +247,15 @@ export const onLoadGetElements = (currentStore: Store<StoreModel>) => {
return parseElements(nodes, edges);
};
};
export const onLoadToObject = (currentStore: Store<StoreModel>) => {
return (): FlowExportObject => {
const { nodes = [], edges = [], transform } = currentStore.getState();
return {
elements: parseElements(nodes, edges),
position: [transform[0], transform[1]],
zoom: transform[2],
};
};
};