How to export doc JSON and apply in the next time?
Re-opening the issue #6911 , as I found it not to be straightforward to do JSON export-import with the Snapshot API.
In my case i applied the code like in the mentioned Snapshot API docs:
import { Job } from '@blocksuite/store';
const doc = createEmptyDoc().init();
const editor = new PageEditor();
editor.doc = doc;
const { collection } = doc;
const job = new Job({ collection });
const json = await job.docToSnapshot(doc);
const newDoc = await job.snapshotToDoc(json);
and it would throw me this:
text.js:19 Uncaught (in promise) TypeError: Cannot assign to read only property 'insert' of object '#<Object>' at new Text (text.js:19:34) at fromJSON (json.js:46:20) at eval (base.js:15:76) at Array.map (<anonymous>) at BaseBlockTransformer._propsFromSnapshot (base.js:14:61) at BaseBlockTransformer.fromSnapshot (base.js:26:28) at Job._snapshotToBlock (job.js:301:45) at Job._snapshotToBlock (job.js:308:24) at async Job._snapshotToBlock (job.js:308:13) at async Job.snapshotToBlock (job.js:60:27) at async Job.snapshotToDoc (job.js:95:13)
This error is caused by the job.snapshotToDoc(json) - method. If i feed this method with a "emptyDefaultSnapshot"-object it did not throw this error.
So how is the proper way to get exported JSON back in?