Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.superdoc.dev/llms.txt

Use this file to discover all available pages before exploring further.

SuperDoc uses an event system for lifecycle hooks and change notifications.
Driving live React UI state? Prefer superdoc/ui subscriptions. useSuperDocSelection, useSuperDocComments, useSuperDocTrackChanges, useSuperDocDocument, and useSuperDocCommand give you typed, memoized, per-slice state with one re-render per change instead of a manual superdoc.on('editor-update', ...) loop. See Custom UI.The events on this page are for lifecycle (ready, editor-create), integration (error, comment-changed), analytics, and compatibility with code that doesn’t use the React surface.

Subscribing to events

superdoc.on('ready', handler);     // Subscribe
superdoc.once('ready', handler);   // One-time listener
superdoc.off('ready', handler);    // Unsubscribe

Lifecycle events

ready

Fired when SuperDoc is fully initialized.
superdoc.on('ready', ({ superdoc }) => {
  // Safe to use all features
});

editorBeforeCreate

Fired before an editor is created. Use this to configure extensions or set up services.
superdoc.on('editorBeforeCreate', ({ editor }) => {
  // Configure before editor mounts
});

editorCreate

When an editor is created.
superdoc.on('editorCreate', ({ editor }) => {
  editor.focus();
});

editorDestroy

When an editor is destroyed.
superdoc.on('editorDestroy', () => {
  cleanup();
});

Content events

editor-update

When editor content changes. Use this to refresh live UI state like word counts or auto-save.
superdoc.on('editor-update', ({ editor }) => {
  if (!editor) return;
  autoSave(editor.getJSON());
});
Live counter example: Read editor.doc.info() inside the handler to build a live document-stats panel without polling.
superdoc.on('editor-update', ({ editor }) => {
  const { counts } = editor.doc.info();
  document.getElementById('stats').textContent =
    `${counts.words} words, ${counts.characters} characters, ` +
    `${counts.trackedChanges} tracked changes, ${counts.lists} lists`;
});

content-error

When content processing fails.
superdoc.on('content-error', ({ error, editor }) => {
  console.error('Content error:', error);
});

fonts-resolved

When document fonts are resolved.
superdoc.on('fonts-resolved', ({ documentFonts, unsupportedFonts }) => {
  if (unsupportedFonts.length > 0) {
    console.warn('Unsupported fonts:', unsupportedFonts.join(', '));
  }
});

Content controls (SDT fields)

content-control:active-change

Fires when selection enters a content control, switches between controls, or leaves all controls.
superdoc.on('content-control:active-change', ({ active, previous, activePath, source }) => {
  // source: 'keyboard' | 'pointer'
  // active / previous: SdtRef | null
  // activePath: SdtRef[] - full active stack, innermost first ([] when none)
});
SdtRef shape:
type SdtRef = {
  id: string;
  tag?: string;
  alias?: string;
  controlType: string;
  scope: 'inline' | 'block';
};
active is the deepest control (activePath[0]); activePath holds the full stack, innermost first. Controls without an id do not emit these events. How to interpret:
  1. Focus (null -> A): previous === null && active !== null
  2. Switch (A -> B): previous !== null && active !== null && previous.id !== active.id
  3. Blur (A -> null): previous !== null && active === null

content-control:click

Fires on pointer click inside a content control.
superdoc.on('content-control:click', ({ target, source }) => {
  // source is always 'pointer'
  // target: SdtRef
});
Both are also available as config callbacks: onContentControlActiveChange and onContentControlClick. To build your own content-control UI on these events, see Custom UI > Content controls.

Comments events

comments-update

When comments are modified.
superdoc.on('comments-update', ({ type, comment, changes }) => {
  // type: 'add', 'update', 'deleted', 'resolved'
  // comment: the comment object (when applicable)
  // changes: per-field change set (when the update is a mutation)
});

Collaboration events

collaboration-ready

When collaboration is initialized.
superdoc.on('collaboration-ready', ({ editor }) => {
  showOnlineUsers();
});

awareness-update

When user presence changes.
superdoc.on('awareness-update', ({ states, added, removed }) => {
  updateUserCursors(states);
});

locked

When document lock state changes.
superdoc.on('locked', ({ isLocked, lockedBy }) => {
  if (isLocked && lockedBy) {
    showLockBanner(`Locked by ${lockedBy.name}`);
  }
});

Pagination events

pagination-update

Fired after each layout pass with the current page count. Use this to know when page data is available: activeEditor.currentTotalPages is only populated after the first layout completes, which happens after the ready event.
superdoc.on('pagination-update', ({ totalPages, superdoc }) => {
  console.log(`Document has ${totalPages} pages`);
});

UI events

zoomChange

When the zoom level changes via setZoom().
superdoc.on('zoomChange', ({ zoom }) => {
  console.log(`Zoom: ${zoom}%`);
});
When the comments sidebar is toggled.
superdoc.on('sidebar-toggle', (isOpened) => {
  adjustLayout(isOpened);
});

Error events

exception

When an error occurs during document processing or runtime.
superdoc.on('exception', (payload) => {
  // `payload` is a discriminated union; narrow before reading variant-specific fields.
  // `code` is only on the editor-lifecycle variant; `stage` is only on document-init.
  console.error('SuperDoc error:', payload.error);
});

Configuration-based events

Events can also be set during initialization:
new SuperDoc({
  selector: '#editor',
  document: 'document.docx',
  onReady: ({ superdoc }) => { },
  onEditorBeforeCreate: ({ editor }) => { },
  onEditorCreate: ({ editor }) => { },
  onEditorUpdate: ({ editor }) => { },
  onFontsResolved: ({ documentFonts, unsupportedFonts }) => { },
  onPaginationUpdate: ({ totalPages, superdoc }) => { },
  onSidebarToggle: (isOpened) => { },
  onException: ({ error }) => { },
});

Event order

  1. editorBeforeCreate: Before editor mounts
  2. editorCreate: Editor ready
  3. ready: All editors ready
  4. collaboration-ready: If collaboration enabled
  5. pagination-update: After each layout pass (page count available)
  6. Runtime events (editor-update, comments-update, sidebar-toggle, etc.)
  7. editorDestroy: Cleanup