excalidraw / excalidraw

Virtual whiteboard for sketching hand-drawn like diagrams
https://excalidraw.com
MIT License
76.28k stars 6.95k forks source link

Add new elements such as images programmatically #8118

Open MarcDuQuesne opened 2 weeks ago

MarcDuQuesne commented 2 weeks ago

As an extension of what was done previously and described here: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/excalidraw-element-skeleton

It would be great to be able to programmatically add icons and images (and text around them), and connect these entities.

I would like to use this feature to create AWS architectures diagrams programmatically from (AWS CDK) code.

dwelle commented 2 weeks ago

While it's not possible to do so using the Skeleton API right now, you can still add images using addFiles in combination with updateScene.

Example here: https://codesandbox.io/p/sandbox/excalidraw-files-example-r7ophm?file=%2Fsrc%2FApp.js%3A20%2C43, check the onClick handler inside the <Excalidraw/> child button (ignore that codesandbox errors out).

MarcDuQuesne commented 2 weeks ago

Thanks, I'll take a look.