tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
34.31k stars 2.06k forks source link

[Example Request]: Load JSON/tldr in component #4076

Open Vanshbordia opened 3 days ago

Vanshbordia commented 3 days ago

What's the example?

Using store & persistent is useful to span the data across browser tabs, but I want to have a Component on the page with custom data passed to it, the store prop would make it persistent with other pages and cause issues. Is there a simpler way to just save / export from tldraw and host the file and pass the json / tldr file to render on my page.

Code of Conduct

linear[bot] commented 3 days ago

TLD-2603 [Example Request]: Load JSON/tldr in component

Kesavaraja commented 3 days ago

editor.store.loadSnapshot may help you

Vanshbordia commented 3 days ago

Is there an example for this, kind of trying to implement this for hours, could not seem to figure it out. If not that is what I was kind of asking for in the first place. https://tldraw.dev/examples/editor-api/snapshots Even this the snapshot Json is different from the json that we get when exporting /saving the file

Kesavaraja commented 3 days ago

If you see that there is a variation with your JSON, kindly check the version of TLdraw you are using. Because I am able to use getSnapshot and loadSnapshot from editor.store without any issues. Refer if needed

Vanshbordia commented 2 days ago

I am on version 2.3.0. Exporting from the website tldraw.com as well as the local version the json does not contain the same data that store or snapshot contains, the structure itself is different

Kesavaraja commented 2 days ago

Export is different from Snapshot. Snapshot contains Schema and store in json but export as json contains schema and shapes. Just use getSnapshot and loadSnapshot from editor.store for easier work.