Saver API: serialize the editor to JSON
Save and export editor content.
Reaching the editor instance
The methods below run on the editor you created with new Blok(). They are available once editor.isReady resolves.
// You already hold the instance returned by the constructor.
const editor = new Blok({ holder: 'editor' });
await editor.isReady;
// Call any API method on it.
editor.caret.setToLastBlock('end');Methods
saver.save()
Promise<OutputData>Alias for the main save() method. It rejects while read-only mode is enabled. It warns and throws Error("Blok's content can not be saved in read-only mode") before reaching the Saver. Guard the call with editor.readOnly.isEnabled, or call await editor.readOnly.set(false) first.
When to use
Identical to editor.save(). It is there for code that works through the saver module. Both await the full block tree.
Errors
Read-only mode is enabled (
editor.readOnly.isEnabled === true).Blok's content can not be saved in read-only mode
Disable read-only with
readOnly.set(false)before saving, or gate the call onreadOnly.isEnabled.Collecting the data failed (a tool's save() threw).
Blok's content can not be saved because collecting data failed
Inspect the rejected error: it is the tool's own error whenever the Saver recorded one.
if (!editor.readOnly.isEnabled) {
const data = await editor.saver.save();
// Returns: { version, time, blocks }
}