jerosoler / Drawflow

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

Reload default diagrams when adding a new module #625

Open angelostiffy opened 1 year ago

angelostiffy commented 1 year ago

Hi Jero

I'm trying to implement to reload the default loaded diagrams that I setup whenever a user wants to add a new module. Below is the picture showing the default diagrams loaded. image

Here is when a user adds a new module. image

And this what it looks after adding a new module. image

I'm looking for implementations (if you have any) that can reload the default diagrams whenever a user adds a new module.

Thank you!

jerosoler commented 1 year ago

I could listen to the moduleCreated event and add the content to the module.

And add content to module:

editor.drawflow.drawflow[ModuleName] =  { "data": { YOUR NODES } }
CelticRugger commented 1 year ago

As jero has pointed out but have implemented exactly this

update the JSON with the additional module data so its ready for parsing but you have to do some house keeping first. So

  1. editor.clear()
  2. remove module links (UI) - remove UI tabs (important because of later reloading with fresh data) then i have something like this with the new modified json json = JSON.parse(json); for (var module in json.drawflow) { editor.addModule(module); addModuleLink(module); / wrapper function to create the UI tab and its properties - study the main flow tab and how that is set up in jero's code example and mimic it but with new tab module names with the same property/ }

then editor.import which will then map all the draw data to the UI module tabs