Quick start
Core concepts
Snapshot
Every time the editor state changes, the toolbar produces aToolbarSnapshot. Read it to know what your UI should look like.
Execute
Run a command by ID. The editor gets focus back automatically — no need foronMouseDown={e => e.preventDefault()} or manual focus management.
Subscribe
subscribe() fires immediately with the current snapshot, then again on every change. It returns an unsubscribe function.
API reference
createHeadlessToolbar(options)
Creates a headless toolbar controller bound to a SuperDoc instance.
The SuperDoc instance to bind to.
Command IDs to track. When omitted, all available commands are tracked.
HeadlessToolbarController.
HeadlessToolbarController
getSnapshot()
Returns the current ToolbarSnapshot without subscribing.
subscribe(listener)
Registers a listener that receives { snapshot } on every state change. Fires immediately with the current snapshot. Returns an unsubscribe function.
execute(id, payload?)
Runs the command identified by id. Returns true if the command executed, false otherwise. Automatically restores focus to the editor.
destroy()
Tears down event listeners and clears all subscriptions. Call this when unmounting your toolbar.
ToolbarSnapshot
The current editing context.
null when no editor is active.Map of command IDs to their current state.
ToolbarCommandState
Whether the command is currently active (e.g., bold is on at the cursor position).
Whether the command can run right now. Disabled when the editor isn’t editable or the command doesn’t apply to the current selection.
The current value for commands that have one (font size, text color, zoom, etc.). Not present for toggle commands like bold.
ToolbarContext
The primary execution surface. Use
target.commands for direct command access when execute() doesn’t cover your use case.Which document surface is currently active.
Whether the editor is in an editable state.
Whether the current selection is collapsed (cursor with no range).
Command reference
Text formatting
| Command | Payload | value in snapshot |
|---|---|---|
bold | — | — |
italic | — | — |
underline | — | — |
strikethrough | — | — |
clear-formatting | — | — |
copy-format | — | — |
Font controls
| Command | Payload | value in snapshot |
|---|---|---|
font-size | '12pt' | '12pt' |
font-family | 'Arial, sans-serif' | 'Arial, sans-serif' |
text-color | '#ff0000' or 'none' | '#ff0000' |
highlight-color | '#ffff00' or 'none' | '#ffff00' |
Paragraph
| Command | Payload | value in snapshot |
|---|---|---|
text-align | 'left' | 'center' | 'right' | 'justify' | alignment string |
line-height | number (e.g. 1.5) | number |
linked-style | style object from helpers | style ID string |
bullet-list | — | — |
numbered-list | — | — |
indent-increase | — | — |
indent-decrease | — | — |
Insert
| Command | Payload | value in snapshot |
|---|---|---|
link | { href: string | null } | href string or null |
image | — (opens file picker) | — |
table-insert | { rows: number, cols: number } | — |
Table actions
| Command | Payload | value in snapshot |
|---|---|---|
table-add-row-before | — | — |
table-add-row-after | — | — |
table-delete-row | — | — |
table-add-column-before | — | — |
table-add-column-after | — | — |
table-delete-column | — | — |
table-delete | — | — |
table-merge-cells | — | — |
table-split-cell | — | — |
table-remove-borders | — | — |
table-fix | — | — |
Document
| Command | Payload | value in snapshot |
|---|---|---|
undo | — | — |
redo | — | — |
ruler | — | — |
zoom | number (e.g. 125) | number |
document-mode | 'editing' | 'suggesting' | 'viewing' | mode string |
Track changes
| Command | Payload | value in snapshot |
|---|---|---|
track-changes-accept-selection | — | — |
track-changes-reject-selection | — | — |
Constants
headlessToolbarConstants provides preset option arrays for dropdown-style controls. Each option has { label, value } — use value when calling execute().
| Constant | Contents |
|---|---|
DEFAULT_FONT_FAMILY_OPTIONS | Aptos, Georgia, Arial, Courier New, Times New Roman |
DEFAULT_FONT_SIZE_OPTIONS | 8pt through 96pt (14 sizes) |
DEFAULT_TEXT_ALIGN_OPTIONS | left, center, right, justify |
DEFAULT_LINE_HEIGHT_OPTIONS | 1.00, 1.15, 1.50, 2.00, 2.50, 3.00 |
DEFAULT_ZOOM_OPTIONS | 50% through 200% (7 levels) |
DEFAULT_DOCUMENT_MODE_OPTIONS | editing, suggesting, viewing (with descriptions) |
DEFAULT_TEXT_COLOR_OPTIONS | 13 colors including none |
DEFAULT_HIGHLIGHT_COLOR_OPTIONS | 8 colors including none |
Helpers
headlessToolbarHelpers provides utilities for advanced workflows.
| Helper | What it does |
|---|---|
getQuickFormatList(editor) | Returns available paragraph styles (Normal, Heading 1, etc.) for a style dropdown. |
generateLinkedStyleString(style, ...) | Returns inline CSS for previewing a paragraph style in your UI. |
getFileOpener() | Returns a function that opens a file picker. Most consumers should use execute('image') instead. |
processAndInsertImageFile(...) | Processes and inserts an image file into the editor. Most consumers should use execute('image') instead. |
React example
A minimal hook that wires the headless toolbar to React state:Examples
Framework examples
Full examples with React + shadcn, React + MUI, Vue + Vuetify, Svelte, and vanilla JS

