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 editor | DOM event on <dorvyn-editor> | React | Detail | When |
|---|---|---|---|---|
editor.on("change") | dorvyn-change | onChange | { 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-open | onOpen | a request | The editor wants a dialog, pane or view |
editor.on("notice") | dorvyn-notice | onNotice | { message } | A message for the person |
dorvyn-error | onError | the error | The 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:
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:
// 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:
| State | What it means | Editing | Saving as Word | The full editor's status bar |
|---|---|---|---|---|
"none" | Starting: no license yet | Off | Off | |
"valid" | Licensed for this page | On | On | |
"grace" | Dorvyn's license service can't be reached. Editing goes on with the last license for up to 24 hours | On | Waits | Can'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 trying | Paused | Off | Reconnecting 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 trying | Off | Off | Not licensed here: editing is off |
"refused" | The editor didn't accept the license it got (it's for another site) | Off | Off | This 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:
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:
| State | What 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:
name | What happened |
|---|---|
GrantError | The editor couldn't be set up for licensing (no key or server-url, a key that isn't a publishable key) |
EngineIntegrityError | The engine file didn't match this SDK version, so it wasn't started |
ExportError | Saving as Word failed. Its message says why |
UnknownCommandError | A 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:
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:
editor.on("notice", ({ message }) => toast(message));