Skip to content

Events

Ezynota uses a typed event bus. Subscribe with editor.on(event, handler), which returns an unsubscribe function:

ts
const off = editor.on("change", (batch) => {
  console.log(batch.origin, batch.changes.length);
});

off(); // stop listening

There's also editor.off(event, handler) if you prefer handler references.

Event reference

EventPayloadDescription
readyEditor (and workspace) finished loading.
changeChangeBatchThe main event. Every committed transaction.
block:insertedblock infoA block was added.
block:updatedblock infoBlock data changed.
block:removedblock infoA block was deleted.
block:moved{ from, to }A block changed position.
selection:changedselection infoCaret/selection moved between editables.
focus / blurEditor surface gained/lost focus.
readOnly:changedbooleanRead-only toggled.
history:changed{ canUndo, canRedo }Undo stack state changed.
fullscreen:changedbooleanWorkspace fullscreen toggled.
workspace:changed{ kind, detail }See workspace events below.
errorEzynotaErrorA recoverable error occurred.
destroyedEditor was destroyed.

ChangeBatch

Every change event receives a batch describing exactly what happened:

ts
interface ChangeBatch {
  id: string;
  origin: "user" | "api" | "paste" | "history" | "remote" | "migration";
  timestamp: number;
  changes: EzynotaChange[];
}

Change types

Change typeMeaning
block:insertBlock added
block:updateBlock data changed
block:removeBlock deleted
block:moveBlock repositioned
block:convertBlock type converted
tune:updateA tune value changed (e.g. alignment)
title:updateDocument title changed
children:updateNested children changed (toggle sections)
document:replaceWhole document replaced (render())

Origin examples

ts
editor.on("change", (batch) => {
  switch (batch.origin) {
    case "user":     /* typed, clicked */ break;
    case "api":      /* your code called insertBlock etc. */ break;
    case "paste":    /* clipboard content applied */ break;
    case "history":  /* undo/redo replay */ break;
    case "remote":   /* cross-tab update */ break;
    case "migration": /* schema migration applied */ break;
  }
});

Workspace events

workspace:changed carries a kind discriminator:

kindMeaning
notesNotes created/renamed/moved/duplicated
foldersFolder tree changed
trashTrash contents changed
activeNoteA different note opened
activeFolderActive folder changed
saveStatusAutosave status changed (pending/saved/error)
remoteChangeAnother tab modified the workspace
loadedWorkspace finished loading
loadFailedWorkspace load failed (recovery UI shown)
noteRenamedA note's title changed

Declarative DOM events

Mount elements bubble ezn:ready, ezn:change, and ezn:error with { instance, payload } in event.detail. See Declarative usage.

Released under the MIT License. Zero runtime dependencies.