marcveens / react-drawio

React component for integrating the Diagrams (draw.io) embed iframe
MIT License
43 stars 8 forks source link

Load drawio with files of different formats #6

Closed AngusParsonson closed 6 months ago

AngusParsonson commented 6 months ago

Hi there,

Is there a way to load DrawIoEmbed with different file types, not just XML?

I want to load PNG, Visio files, etc., when the component is mounted. Currently, I can only load XML files by using the xml prop.

If I spin up DrawIoEmbed, I can drop these files into the editor, and it works nicely, so there might be a way to do this programmatically.

Thanks

marcveens commented 6 months ago

Hi Angus,

According to the draw.io docs it should be possible, I just have to find some time to check whether it's easily implemented within this plugin. I'll get back to you later!

marcveens commented 6 months ago

I just added an example of how to load a .png file, and transform it to the correct format:

https://github.com/marcveens/react-drawio/blob/f154102ec850d1ad1ea7a07479ebf7a483fcda7f/stories/DiagramsEmbed.stories.tsx#L53C1-L66C3

In case of .vsdx files, I don't know how draw.io handles them. There's not much to find online on how to parse those files. In the end, it should be an xml/base64 format one way or the other. I can't seem to parse that file type correctly, so unfortunately I'm not able to help with that.