API / @aionbuilders/nabu

NabuInit

Type Stability: stable

The options of an editor: the extensions to load, an initial snapshot, files, placeholders, readonly, language, Tab behaviour, keymap and command confirmation. Accepted by new Nabu(init), by createEditor and the preset factories, and by createPersistedEditor.

Related guide: Your first editor →

Definition

TypeScript
import type { NabuInit } from '@aionbuilders/nabu';
TypeScript
interface NabuInit {
  commandConfirm?: CommandConfirmOptions;
  extensions?: Extension[];
  files?: FilesConfig;
  keymap?: Record<string, string[]>;
  lang?: string;
  placeholders?: PlaceholdersOption;
  platform?: 'mac' | 'other';
  readonly?: boolean;
  snapshot?: Uint8Array<ArrayBufferLike>;
  spellcheck?: boolean;
  tab?: 'focus' | 'stay' | 'indent';
  tabDefault?: 'focus' | 'stay' | 'indent';
  tabHint?: string | false;
}

Properties

Properties of NabuInit
PropertyTypeDescription
commandConfirmoptionalCommandConfirmOptions

Confirmation of commands asked by a key press (ADR 017 lot 2): { holdMs?: number (700), inviteMs?: number (5000), messages?: ConfirmMessages }. messages are the texts of the prompts and outcomes announced to screen readers (English by default; each is a string or a function of the parameters, see ConfirmMessages); a command can override them with confirm.messages.

extensionsoptionalExtension[]n/a
filesoptionalFilesConfign/a
keymapoptionalRecord<string, string[]>

Replaces the keyboard shortcuts of commands (ADR 017): { 'mark:bold': ['Mod-Alt-b'] }; [] disables a command's keys. Chords: see utils/keys.js; the same checks as for a declared key apply (reserved chords, a key without modifier needs the command's when).

langoptionalstring

Language of the content, a BCP 47 tag ('fr', 'en-GB'). Set on the root as lang, so the browser's spellchecker, hyphenation and screen readers use it. Unset: inherits the page language. An invalid tag is ignored (warning). Reactive: nabu.lang.

placeholdersoptionalPlaceholdersOption

Hint text of empty blocks. false: none. true / omitted: defaults (shown on the empty block holding the cursor). Object: { show?: 'focus' | 'empty', text?: Record<blockType, string | false | ((block) => string | false)> }.

platformoptional'mac' | 'other'

Which platform's conventions Mod and the displayed shortcuts follow. Detected from the browser by default; set it for tests or server-side rendering.

readonlyoptionalboolean

Show the document without letting the user change it (default false). Reactive: nabu.readonly, assign to toggle live (<NabuEditor readonly> sets it). The editor root becomes contenteditable="false"; the engine ignores typing, paste, cut, drop, drag moves and every command / shortcut (undo and redo included). Copy, text selection and links keep working, and the floating UI (toolbar, slash menu, drag handle) hides itself. Code of the host is NOT restricted: insert, importJSON, importMarkdown, importRemote, transact still work, which is how a viewer loads its document.

snapshotoptionalUint8Array<ArrayBufferLike>n/a
spellcheckoptionalboolean

Browser spellcheck on the editor (default true). false turns it off and adds the opt-out hints of the Grammarly extension (data-gramm="false", ...). Code blocks are never spellchecked. Reactive: nabu.spellcheck.

taboptional'focus' | 'stay' | 'indent'

What Tab / Shift+Tab do in a plain text block, where no block handles them structurally (list indent, code indentation and region titles keep their own meaning, whatever this says; P-41). 'focus': the browser default, Tab leaves the editor. 'stay': both keys are swallowed and the caret stays; Escape then Tab leaves (announced to screen readers, see tabHint). 'indent': Tab inserts a tab character at the caret (replacing a selection inside one block), Shift+Tab removes one right before it; several blocks selected: like 'stay'. 'nest' is planned, not implemented. Default: tabDefault (the factories of presets.js set it from the preset: Minimal / Text 'focus', Document / Full 'stay'), else 'focus'. An unknown value warns and uses the default. Reactive: nabu.tab.

tabDefaultoptional'focus' | 'stay' | 'indent'

The mode used when tab is unset or invalid. Meant for the preset factories.

tabHintoptionalstring | false

Text announced on the editor root (aria-description) while tab traps the focus ('stay', 'indent'): default "Press Escape then Tab to leave the editor"; translate it here, false for none. Reactive: nabu.tabHint.

Source: src/lib/blocks/nabu.svelte.js:45