Merge pull request #3537 from wbkd/use-svelte-flow-to-object

feat(svelte) added toObject() on useSvelteFlow
This commit is contained in:
Moritz Klack
2023-10-30 11:53:19 +01:00
committed by GitHub
2 changed files with 24 additions and 2 deletions
@@ -51,6 +51,7 @@ export function useSvelteFlow(): {
getConnectedEdges: (id: string | (Partial<Node> & { id: Node['id'] })[]) => Edge[];
getIncomers: (node: string | (Partial<Node> & { id: Node['id'] })) => Node[];
getOutgoers: (node: string | (Partial<Node> & { id: Node['id'] })) => Node[];
toObject: () => { nodes: Node[]; edges: Edge[]; viewport: Viewport };
} {
const {
zoomIn,
@@ -263,6 +264,19 @@ export function useSvelteFlow(): {
return getOutgoersBase(_node, get(nodes), get(edges));
},
toObject: () => {
return {
nodes: get(nodes).map((node) => ({
...node,
// we want to make sure that changes to the nodes object that gets returned by toObject
// do not affect the nodes object
position: { ...node.position },
data: { ...node.data }
})),
edges: get(edges).map((edge) => ({ ...edge })),
viewport: { ...get(viewport) }
};
},
viewport
};
}