History

history:build#

Hook emitted while building an undo/redo snapshot. Handlers may return { html, data } to extend the snapshot.

Type: hook (handler may return a value).

Payload:

  • html — snapshot HTML
  • offset — caret offset object for history restore (optional)
  • focusPath — node path for restoring focus on non-editable blocks (optional)
  • data — object — extend with plugin state; merged on return
  • scope — string — snapshot scope (e.g. schemaSection) (optional)
  • sectionId — string — schema section id when scoped (optional)
  • sectionPath — node path to the schema section (optional)

Example:

app.on('history:build', (snapshot) => {
  return {
    data: {
      ...(snapshot.data || {}),
      sidebar: getSidebarState()
    }
  };
});

history:record#

Emitted after a new history entry is recorded. Payload: { reason, undo, redo }.

Type: signal.

Payload:

  • reason — string — why a history entry was recorded
  • undo — number — undo stack depth after the record
  • redo — number — redo stack depth after the record

Example:

app.on('history:record', ({ reason, undo, redo }) => {
  app.statusbar.update('history', `undo ${undo} / redo ${redo}`);
});

history:restore#

Hook emitted before a snapshot is restored. Use it to restore plugin/product state from snapshot.data.

Type: hook (handler may return a value).

Payload:

  • html — snapshot HTML to restore
  • offset — caret offset object for history restore (optional)
  • focusPath — node path for restoring focus on non-editable blocks (optional)
  • data — plugin state saved in history:build
  • scope — string — snapshot scope (e.g. schemaSection) (optional)

Example:

app.on('history:restore', (snapshot) => {
  restoreSidebarState(snapshot.data?.sidebar);
});