update(examples): Add Save & Restore example

* add localforage to dev deps
This commit is contained in:
Braks
2021-10-22 10:00:21 +02:00
parent eb9714b898
commit 3f863ef71c
8 changed files with 135 additions and 7 deletions
+10 -6
View File
@@ -273,7 +273,6 @@ const parseElements = (nodes: Node[], edges: Edge[]): Elements => [
n.position = n.__rf.position
n.__rf = {} as any
return n
}),
...edges.map((e) => ({ ...e })),
@@ -282,11 +281,16 @@ const parseElements = (nodes: Node[], edges: Edge[]): Elements => [
export const onLoadGetElements = (currentStore: FlowStore) => (): Elements =>
parseElements(currentStore.nodes || [], currentStore.edges || [])
export const onLoadToObject = (currentStore: FlowStore) => (): FlowExportObject => ({
elements: parseElements(currentStore.nodes || [], currentStore.edges || []),
position: [currentStore.transform[0], currentStore.transform[1]],
zoom: currentStore.transform[2],
})
export const onLoadToObject = (currentStore: FlowStore) => (): FlowExportObject => {
// we have to stringify/parse so objects containing refs (like nodes and edges) can potentially be saved in a storage
return JSON.parse(
JSON.stringify({
elements: parseElements(currentStore.nodes || [], currentStore.edges || []),
position: [currentStore.transform[0], currentStore.transform[1]],
zoom: currentStore.transform[2],
}),
)
}
export const getTransformForBounds = (
bounds: Rect,