jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.61k stars 721 forks source link

Is it possible to store nodes and connections in LocalStorage? #173

Closed adamburczy closed 3 years ago

adamburczy commented 3 years ago

Hello, when I create nodes non-programmatically, for example using drag and drop on demo: https://jerosoler.github.io/Drawflow/, after I refresh page, everything I added disappear. Is there way to keep it after page refresh for example, storing it to LocalStorage, and then adding to HTML code of page?

jerosoler commented 3 years ago

Hello @adamburczy

Yes is possible.

View to save object in localstorage: https://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage

Use editor.export() and editor.import() to save and load.

Jero

adamburczy commented 3 years ago

Thanks for your reply @jerosoler ! It's working, I can get the JSON object, with nodes using editor.export() and editor.import(), but I have one more question, and I will be happy, if you could help me. Im not sure if I understand those methods. I have JSON object, and I can save it to the localStorage with storage.setItem(keyName, keyVale), but how can I add those created nodes from JSON into DOM?

jerosoler commented 3 years ago

Hello, @adamburczy

With the function editor.import("YOUR JSON");

It should load its nodes into the DOM.

Jero