editor.on() and unsubscribed through editor.off().
Subscribing to Events
Useeditor.on() to register a handler and editor.off() to remove it. Always hold a named reference to the callback function if you intend to unsubscribe later.
change
Fires on every content change in the editor — keystrokes, pastes, formatting commands, setHTML() calls, and undo/redo operations all trigger this event.
The full editor content as a sanitized HTML string at the moment of the change.
selectionchange
Fires whenever the cursor position or text selection changes inside the editor. No payload is delivered — query editor.getHTML() or inspect window.getSelection() inside the handler if you need context about the current selection.
history:change
Fires when the undo/redo stack changes — both when a new snapshot is pushed and when the user navigates the history. Use this to enable or disable custom undo/redo UI controls.
view:toggle
Fires after the editor transitions between WYSIWYG mode and raw HTML editing mode, either programmatically via toggleHtmlView() or through the built-in toolbar button.
true when the editor has just entered raw HTML mode; false when it has returned to WYSIWYG mode.autosave
Fires after the editor successfully writes content to localStorage. This event only fires when the autoSave option is configured. No payload is delivered.
The
autosave event fires after a successful write. It does not fire if localStorage is unavailable or throws (e.g. in private browsing with storage blocked). Subscribe to error to catch storage failures.error
Fires when a recoverable error occurs inside the editor. The editor does not throw exceptions for these conditions — it emits them as events so you can decide how to surface them to the user.
A machine-readable error code string. See the Error codes table below.
A human-readable description of what went wrong.
Error Codes
The following codes appear in theerror event’s code field:
| Code | Trigger |
|---|---|
UPLOAD_TOO_LARGE | The selected image file exceeds the maxImageSize limit (default 5 MB). |
UPLOAD_INVALID_TYPE | The file’s MIME type is not in the allowedImageTypes list. |
UPLOAD_INVALID_MAGIC | The file’s magic bytes do not match its declared MIME type — likely a spoofed file extension. |
UPLOAD_FAILED | The uploadImage callback threw an exception or returned a falsy value. |