Skip to content

Commands

Every built-in behavior in Ezynota routes through a command bus. This gives custom toolbars, keyboard layers, and plugins a stable dispatch surface that doesn't depend on internal methods.

ts
editor.dispatch("EZ_UNDO");
editor.dispatch("EZ_INSERT_BLOCK", { type: "callout", data: { variant: "info", content: [] } });

Command reference

Commands are addressed by the EZ constants (all values are "EZ_*" strings):

ConstantValuePayloadAction
EZ.INSERT_BLOCKEZ_INSERT_BLOCK{ type, data? }Insert a block.
EZ.DELETE_BLOCKEZ_DELETE_BLOCK{ id }Delete a block.
EZ.MOVE_BLOCKEZ_MOVE_BLOCK{ id, target }Move a block.
EZ.DUPLICATE_BLOCKEZ_DUPLICATE_BLOCK{ id }Duplicate a block.
EZ.CONVERT_BLOCKEZ_CONVERT_BLOCK{ id, targetType }Convert block type.
EZ.UPDATE_BLOCKEZ_UPDATE_BLOCK{ id, data }Replace block data.
EZ.FOCUS_BLOCKEZ_FOCUS_BLOCK{ id }Focus a block.
EZ.UNDO / EZ.REDOEZ_UNDO / EZ_REDOHistory step.
EZ.OPEN_SLASH_MENUEZ_OPEN_SLASH_MENU{ blockId?, insert? }Open the block picker.
EZ.SET_READ_ONLYEZ_SET_READ_ONLY{ value }Toggle read-only.
EZ.SELECT_BLOCKEZ_SELECT_BLOCK{ id }Select a block.

The raw string values work too — constants are just a typo-safety layer:

ts
import { EZ } from "ezynota";

editor.dispatch(EZ.INSERT_BLOCK, { type: "paragraph", data: { content: [] } });

CommandDescriptor

Commands are described by a small interface:

ts
interface CommandDescriptor<TPayload = unknown> {
  name: string;
  run(payload: TPayload, api: EzynotaEditorAPI): void;
}

api is the editor's public API surface, so command handlers have the same capabilities as your integration code.

When to use commands vs. methods

  • Methods (editor.insertBlock(...)) — when you have a direct reference and want type checking.
  • Commands (editor.dispatch(...)) — when the call site is generic or dynamic: custom toolbar buttons, saved macros, keyboard layers, plugin integrations.

Both paths end in the same transaction pipeline, emit the same events, and participate in undo.

Released under the MIT License. Zero runtime dependencies.