Skip to the content

The editor

Events and license states

What the editor tells your app: changes to the document, requests for dialogs, messages for the person, errors, and the state of its license and engine.

Events#

On the editorDOM event on <dorvyn-editor>ReactDetailWhen
editor.on("change")dorvyn-changeonChange{ document }The person changed the document, at most every 0.7 s while they type. Not when your code opens one with setDocument
editor.on("open")dorvyn-openonOpena requestThe editor wants a dialog, pane or view
editor.on("notice")dorvyn-noticeonNotice{ message }A message for the person
dorvyn-erroronErrorthe errorThe editor couldn't start, or a command failed
dorvyn-theme"light" or "dark"The person changed the theme (View, or Options)

In Angular, listen to the DOM events: (dorvyn-change)="…". DOM events bubble, so a listener on any ancestor hears them.

editor.on(…) returns a function that stops listening:

JavaScript
const stop = editor.on("change", ({ document }) => queueSave(document));
// later
stop();

Watching the state#

editor.state holds everything that's true now (the full list). Watch only the parts you show:

JavaScript
// Called each time the license state changes (not straight away: read it now with state.get()).
const show = (license) => banner.toggle(license !== "valid");
show(editor.state.get().license);
editor.state.select((s) => s.license, show);

// The whole state once, now.
const { words, pages, dirty } = editor.state.get();

In React, useEditorState((s) => s.license, "none"). In Angular, ed.select((s) => s.license, "none").

License states#

state.license says whether the editor can edit, and why not:

StateWhat it meansEditingSaving as WordThe full editor's status bar
"none"Starting: no license yetOffOff
"valid"Licensed for this pageOnOn
"grace"Dorvyn's license service can't be reached. Editing goes on with the last license for up to 24 hoursOnWaitsCan't reach the license service: editing continues, saving as Word waits
"lapsed"The license ran out before a new one came (the connection dropped, a laptop woke from sleep). The editor keeps tryingPausedOffReconnecting to your license… editing is paused
"unavailable"No license could be had: the person isn't signed in to your app, the key isn't for this site, or the network is down. The editor keeps tryingOffOffNot licensed here: editing is off
"refused"The editor didn't accept the license it got (it's for another site)OffOffThis license isn't for this site

In every state the document stays on screen and readable, drafts are kept, and nothing is lost. Editing comes back by itself as soon as a license does, without a reload.

state.readOnly is true whenever editing is off, for any of these reasons, or because the person chose Viewing.

Showing it in your own interface#

If you use your own layout instead of the full editor, tell people why they can't edit:

JavaScript
const MESSAGES = {
  unavailable: "Sign in again to keep editing.",
  lapsed: "Reconnecting…",
  refused: "The editor isn't licensed for this site.",
  grace: "Working offline. Saving as Word will be back soon.",
};
const update = (l) => showBanner(MESSAGES[l] ?? null);
update(editor.state.get().license);
editor.state.select((s) => s.license, update);

Engine states#

state.engine is the engine's own state:

StateWhat it means
"loading"Downloading and starting
"ready"Running. Lists that come from the engine (page sizes, shapes, equations) are filled now
"failed"It didn't load (network, CSP), or the file didn't match this SDK version. See Troubleshooting
"off"Turned off with the engine: false option

Errors#

dorvyn-error (onError in React) gets an Error. Its name tells you the kind:

nameWhat happened
GrantErrorThe editor couldn't be set up for licensing (no key or server-url, a key that isn't a publishable key)
EngineIntegrityErrorThe engine file didn't match this SDK version, so it wasn't started
ExportErrorSaving as Word failed. Its message says why
UnknownCommandErrorA command id that doesn't exist (a typo, or a command removed in a newer version)

Every message, with what to do about it, is in Messages and errors.

Dialogs, panes and views#

When the editor needs a dialog (Ctrl+K, clicking an equation, a ribbon button), it sends an open request. <dorvyn-dialogs> and <dorvyn-panes> answer with Dorvyn's own. Leave them out and answer with yours:

JavaScript
editor.on("open", (req) => {
  if (req.dialog === "link") myLinkDialog.show({ text: req.text, url: req.url });
  if (req.pane === "find") myFindBar.show(req.mode, req.query);
});

Every request and its fields are in Commands, state and lists. You can ask for one yourself with editor.open({ dialog: "link" }).

Notices#

Short messages for the person, like "Select a picture first (click it)." or "Replaced 3 items". <dorvyn-dialogs> shows them as toasts. With your own interface, show them your way:

JavaScript
editor.on("notice", ({ message }) => toast(message));