Saving and restoring

Consistent JSON/CSS snapshots, events and application-owned storage.

1.0.0-beta.6 · Local build · desktop

What to store

getJSON returns an independent structural snapshot. getCSS returns the separate stylesheet; JSON alone does not contain CSS. Store both from the same applied revision. You can also retain getHTML for publishing. Change events provide html/json/css/revision of the applied document.

Application persistence

ViText itself does not write to a server. Your application implements debounce, authentication, request ordering, retries and conflict handling. Never treat selection changes as document writes. Source errors preserve the last valid document, not the unvalidated draft.

Restore a snapshot

Read your saved JSON/CSS and await setContent(json, { css }). Validate external data before publishing. A new editor also accepts initial structured content and stylesheet, with whenReady for asynchronous CSS initialization.

Browser example

The storage example has separate Save snapshot and Restore snapshot buttons. Save explicitly writes JSON+CSS to this browser's localStorage. Edit the text afterward, then restore to see the saved version return. Reloading the example does not erase that snapshot. It is not shared with another browser/device or a server; Delete snapshot clears it.

const unsubscribe = editor.on('change', event => {
  const snapshot = { json: event.json, css: event.css, revision: event.revision };
  console.log(snapshot);
});
const snapshot = { json: editor.getJSON(), css: editor.getCSS() };
await editor.setContent(snapshot.json, { css: snapshot.css });
unsubscribe();

Search documentation

No results. Try different words.

All documentation