API reference
Everything the package exports, generated from the source's JSDoc at build time. Three entry points, each with its own
import path. This is version 0.1.2.
@aionbuilders/nabu
Create an editor, mount it, pick the built-in extensions and reach its subsystems.
Functions 15
- createDialogueExtension Dialogue extension factory.
- createDocumentEditor Paragraph + headings + rich text. Good for articles, notes.
- createEditor Create a Nabu editor instance from a preset and optional extra extensions.
- createFullEditor All built-in blocks + rich text. The full Nabu experience.
- createMinimalEditor Paragraph-only editor. Ideal as a simple textarea replacement.
- createPersistedEditor Create a Nabu editor instance with automatic IndexedDB persistence.
- createTextEditor Paragraph + rich text marks. Good for comment boxes, descriptions.
- deltaToHtml Converts a Loro text delta to inline HTML. Marks are rendered as semantic HTML tags.
- deltaToMarkdown Converts a Loro text delta to inline Markdown.
A line break (
\nin the text) is exported as a markdown hard break (backslash + newline), unlessrawBreaks(a block that re-reads its own lines, like a callout body, keeps the plain newline). - formatChord Format a chord for display, per platform. macOS:
⌃⌥⇧⌘+ key, no separator (⌘⇧Z,⌘↩). Elsewhere:Ctrl+Alt+Shift+Meta+Key(Ctrl+Shift+Z,Ctrl+Enter). - insertImageFromFile Insert an image block from a local File: optimistic preview → persist → ref. Re-exported for back-compat.
- insertMediaFromFile Insert a media block of
typefrom a local File. The block appears at once (pending, with a local preview), the bytes are hashed and written to the local store (ADR 014), then the block gets itsnabu-asset:sha256-…ref:ready, or — with a host (files.onBeforePersist) — stillpendingwhile the background upload runs (block.progress,block.retry(),block.cancel()); the ref never changes afterwards. A file overfiles.maxFileSizeis refused: the block is createdrejected, with no ref and a readablereason. - isSupportedJsonVersion Whether
importJSONcan read a document export of thisversion(seeJSON_FORMAT_VERSION). A missing version is read as the current one; the number1and the string'1'are the same version. - RegionsExtension Regions extension factory (ADR 016, data model of ADR 018): structure a text in divisions. Installs the
regioncontainer block (its header is its title, its body is its children), the placement / nesting normalizer, and the reactive registry (nabu.regions, alsoRegions.get(nabu)). - sanitizeUrl Return
urlwhen it is safe to put in anhref/src, otherwisenull.
Classes 7
- FileRejectedError Thrown by
Files#ingest/Files#persistfor a file the options refuse (maxFileSize). - Files Document-level file/asset manager (ADR 014). The bytes of a file live in an
AssetStore, the document only holdsnabu-asset:sha256-<hex>references and a smallassetIndexLoro map (hash → { mime, name, size, url? }). Lazy: Files.get(nabu). - MemoryOutbox In-memory
Outbox(lost with the page, like a non-persisted document). - Nabu The editor engine. It owns the document (a Loro CRDT), the block tree and its registry, the selection, the commands and the
extensions, and runs the event, clipboard and drag and drop pipelines;
NabuEditorrenders it. Create one withcreateEditor(or a preset factory such ascreateDocumentEditor) rather thannew Nabu(...), then read and write the content throughserialize,importMarkdown,importJSON,execandtransact. The members documented as public are the stable contract of@aionbuilders/nabu/extend;internalsis the unstable door to the rest. - Region One division of the document, as computed by the registry (ADR 018 §3.4). A read-only VIEW over a region BLOCK, a container
of the tree: the structure (
level,parent,children,index,path) is derived from the tree;title/fields/label/blocks/wordCountread reactive state when you read them. - Regions Document-level reactive registry of the regions (ADR 018 §3.4): a pure, derived view over the TREE (stores nothing in
Loro). Lazy and cheap: ONE pass over the root blocks and the bodies of the regions builds everything, and it only re-runs
when the STRUCTURE changes (a region inserted / moved / deleted / retyped, a child added to a region body), not when
text is typed. Obtain it with
Regions.get(nabu);RegionsExtensionalso installs it asnabu.regions. - Todos Document-level reactive registry of all to-do items (checklist list-items). Pure derived view over the block tree — stores nothing in Loro. Lazy: obtain via Todos.get(nabu).
Components 1
- NabuEditor The contenteditable root: renders the document of an editor and wires every event to the engine.
Constants 31
- BlockExtension The
block:transformaction: turn a block into another type (exec('block:transform', { type, props })). The block extensions' own actions (heading:1,callout...) and the slash menu go through it. - BlockquoteExtension The quote block: the
>shortcut, Backspace and Enter de-transformations, markdown and HTML paste rules, and the "Quote" slash entry. - CalloutExtension The callout block (
note,tip,important,warning,cautionvariants): the!shortcut, thecalloutaction and the "Callout" slash entry. - CLIPBOARD_FORMAT_VERSION Current version of the
application/x-nabu+jsonclipboard format (see docs/design/clipboard-format.md). Written on copy asversion; the Nabu paste interpreter accepts it (and fragments without a version). - CodeExtension The code block: plain monospace text with a language, the ``` shortcut, the
code:blockaction and the "Code" slash entry. - createRegionsExtension Alias following the
createXxxExtensionnaming of the other factories. - DEFAULT_REGION_MESSAGES The default texts of the regions: command labels, the seam and end marker wording, the chooser and the hold prompt (English).
Override any key with
RegionsExtension({ messages }). - DEFAULT_REGION_TYPES Default types: ONE generic
sectiondivision over three levels, as three types (the level IS the type: changing the level of a region = changing its type, ADR 016 §3.4). Labels "1.", "1.1", "1.1.1". - DialogueExtension Default instance (dash
–). - DividerExtension The divider block (a horizontal rule): the
---shortcut, markdown and HTML paste rules, and the "Divider" slash entry. - DocumentPreset Paragraph + headings + rich text. Document-like, no lists.
- FileExtension The file block: an attachment (name, size, download link) stored through the
filesoption; thefile:*actions, file paste for any file type and the "File" slash entry. - FullPreset All built-in block types + rich text.
- HeadingExtension The heading block (levels 1 to 6): the
#shortcuts, theheading:1toheading:6actions and the "Heading" slash entries. - HtmlPasteExtension Paste of
text/html(web pages, Google Docs, Word, spreadsheets): turns the markup into blocks through the rules the registered block classes declare (htmlRules). - ImageExtension The image block: stored through the
filesoption, with theimage:insertandimage:pickactions, image file paste and the "Image" slash entry. - JSON_FORMAT_VERSION Version written by
serialize('json')(document export).importJSONreads this one (a missing version is read as it). - ListExtension The list container (bulleted, numbered or to-do): the
list:*actions, Tab and Shift+Tab indentation over a selection, and the list slash entries. Always loaded together withListItemExtension. - ListItemExtension The list item block: Enter, Backspace and Tab behaviour inside lists, the to-do checkbox and
todo:toggle(Mod-Enter). Always loaded together withListExtension. - MarkdownPasteExtension Paste of markdown typed as
text/plain: parses it into blocks and inline marks through the rules the registered block classes declare (markdownRules). It also powersimportMarkdown(). - MarkdownShortcutsExtension Inline markdown shortcuts while typing:
**bold**,_italic_,`code`,~~strike~~turn into marks as the closing delimiter is typed. - MinimalPreset Paragraph only. The simplest possible editor.
- NabuPasteExtension Paste of
application/x-nabu+json, the format Nabu writes on copy and cut: copying between Nabu editors keeps the block structure, marks and files. - ParagraphExtension The paragraph block, the default text block: the
paragraphaction (turn a block back into text) and the "Text" slash entry. - PlainTextPasteExtension Interprète text/plain comme du texte pur. - Chaque ligne non vide → un bloc (une ligne = un bloc) - Les lignes vides ne sont que des séparateurs (aucun paragraphe vide) Priorité 0 (fallback de dernier recours).
- REASON_CODES The stable codes of
FileReason. - RichTextExtension The inline marks (bold, italic, underline, code, strikethrough) and links: the
mark:*andlink:*actions and their keyboard shortcuts. - TextPreset Paragraph + rich text marks (bold, italic, underline, code, strikethrough).
- ToggleExtension The toggle block: a collapsible container with its own header text and a body of child blocks; the
toggleaction and the "Toggle" slash entry. - TypographyExtension Smart typography input rules.
Currently:
--→—(em-dash substitution while typing). A longer run of dashes (---, a divider-like-----) is left alone: the--must not be preceded by another-. - VideoExtension The video block: stored through the
filesoption, with thevideo:insertandvideo:pickactions, video file paste and the "Video" slash entry.
Types 29
- Chord A parsed key chord: a key and its four modifiers (
Modis resolved toctrlormetafor the platform). - CommandConfirm
- CommandConfirmOptions
- CommandContext What the engine builds at each key press (and for
nabu.execof a command, withevent: null). Extensions add FACTS (any other property) throughExtension#commandContext; facts never replace the fields below. - CommandDef A command: a label, optional default keys, a
whencondition, ascopeand arunfunction. Declared by extensions (ExtensionInit.commands); every command is also an action of the bus (nabu.exec(id, data)). - CommandInfo What
nabu.commands.list()/get()return: a plain snapshot (the registry is fixed once the editor is built, so it needs no reactivity; read it again after akeymapchange, i.e. a new editor). - CompactOptions
- CompactResult
- ConfirmMessages
- EditorOptions Options of the editor factories: every
NabuInitoption (files,placeholders,snapshot,keymap,tab,lang…, forwarded toNabu) plus thepresetthe factory starts from.extensionsare appended to the preset's. -preset: base extensions (default:FullPreset, or the preset of the named factory). -tab: default by preset: Minimal / Text'focus', Document / Full'stay', a custom preset array'focus'. - EmbeddedAsset
- FieldKind
- FieldSpec
- FilesConfig
- HistoryConfig
- NabuInit 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), bycreateEditorand the preset factories, and bycreatePersistedEditor. - Numbering
- PlaceholdersConfig
- PlaceholdersOption
- PlaceholderText A string,
false(no placeholder) or a function of the block returning one of those. - Platform The platform whose conventions
Modand the displayed shortcuts follow:'mac'(Cmd) or'other'(Ctrl). - Recovery What happened when a stored document could not be read (ADR 010, theme 8). Exposed as
nabu.persistence.recoveryand given to theonRecoveroption, so the host can tell the user. - RegionMessageParams
- RegionMessages
- RegionNameParams
- RegionsConfig
- RegionTypeDef
- RegionTypeInit
- RegionTypeParams
@aionbuilders/nabu/ui
The optional UI: formatting toolbar, slash menu, drag handle and command-confirmation surfaces.
Classes 1
- SlashMenuController The state of the "/" menu for one editor: whether it is open, the query typed after the slash, the filtered and sorted entries
and the selected one.
SlashMenuis its default rendering; use it directly to build your own menu.
Components 5
- CommandChooser Default NEUTRAL rendering of the
choosestrategy (ADR 017 §3.4c): a list at the caret. The keyboard (arrows, Enter, digits 1-9, Escape) is handled by the engine while the chooser is pending; this component renders the state and takes the mouse. The editor keeps the focus, so options are not tabbable: the highlighted one is announced by the live region. - CommandInvite
truealways shows it;falsenever (the target draws everything). - DragHandle The handle shown next to a block to drag it elsewhere in the document.
- FloatingToolbar Floating mark toolbar. Appears above the current (non-collapsed) selection.
Positioned with
position: fixedin viewport coordinates, so it works inside any layout (scrollable containers, overflow: hidden ancestors…) without a positioning wrapper. - SlashMenu The "/" menu: a filterable list of blocks to insert, anchored at the caret.
Types 1
- SlashCommand An entry of the slash menu: a title, optional subtitle, icon and aliases to filter on, a group and order for sorting, an optional
whento limit where it is offered, and the action to run. Extensions contribute theirs withslashCommands.
@aionbuilders/nabu/extend
The extension() factory, the block base classes, the text behavior and the stable contract of a third-party block.
Functions 11
- canonicalChord Parse then canonicalize a chord string.
- chordId The canonical string of a chord:
Ctrl-Alt-Shift-Meta-<key>. - detectPlatform Detect the platform whose conventions
Modand the displayed shortcuts follow: Cmd on macOS and iOS, Ctrl everywhere else. - escapeAttr Escape a value for a quoted HTML attribute. Same table as
escapeHtml; kept as a distinct name so the call sites say what they mean. - escapeHtml Escape text for use as HTML text content OR inside a quoted attribute value (& < > " ').
- eventChord Normalize a keyboard event to a chord, with the rules of the module doc.
- eventChordId The canonical string of a keyboard event (see
eventChord), ornull. - extension Create an extension: the unit that bundles a block type, its component, hooks, commands, actions, paste handlers and slash entries.
Shorthand for
new Extension(name, init). - hasCommandModifier Whether the chord carries a modifier that makes it a shortcut rather than typing: Ctrl, Alt or Meta.
Shiftalone does not (Shift+letter is a capital letter). - isReservedChord Whether a chord is reserved by the browser or the OS (close tab, reload, quit...) and so refused when a command declares it.
- parseChord Parse a chord string. Returns
nullfor anything invalid: empty, unknown key name, unknown/duplicated modifier, orShifton a digit/symbol (see the module doc).
Classes 8
- Block The base class of every block. A block wraps a node of the document tree (Loro) and holds the behaviour of one block type: the capability flags, the tree accessors, and the handlers for typing, keys, splitting, merging, pasting and serialization that a subclass overrides.
- CommandRegistry Holds the commands of an editor (
nabu.commandsis its public face): registers them from the extensions, resolves the keymap and the key chords at keydown, and answerslist,get,hasandrun. - Extension A named bundle of editor behaviour (see
ExtensionInit); the built-in blocks and behaviours are extensions. Build one withextension(name, init)and pass it tocreateEditor({ extensions }). - MegaBlock A block that holds child blocks (a container): list, list item, toggle, region. It keeps its
childrenin sync with the tree and delegates positions, word count and event handling to them. - NabuSelection Utilitaire réactif pour gérer la sélection de texte avec Svelte 5 runes
- SvelteSelection Utilitaire réactif pour gérer la sélection de texte avec Svelte 5 runes
- TextBehavior The editing of a block's rich text: wraps a Loro text and offers the reactive
textanddelta, the selection in that text, and insertion, deletion, splitting, marks and links. Text blocks use it throughTextBlock; a container with a header (list item, toggle) owns one. - TextBlock Base class for purely textual blocks (paragraph, heading, dialogue…). Owns a single TextBehavior and proxies the standard Block text API to it, removing the proxy boilerplate previously duplicated in every text block.
Components 2
- BlockComponent Renders one block with the component its extension registered. Used by container blocks to render their children.
- RichText Renders the delta of a text block: marks, links and the trailing-line filler.
Constants 1
- RESERVED_CHORDS Chords the browser or the OS keeps for itself (tabs, windows, quit, reload, address bar, devtools, zoom, tab switching):
a page often cannot intercept them, and stealing them would be hostile anyway. Commands cannot bind them (refused at
registration with a warning). Written with
Mod, resolved per platform byreservedChords.
Types 20
- Chord A parsed key chord: a key and its four modifiers (
Modis resolved toctrlormetafor the platform). - CommandContext What the engine builds at each key press (and for
nabu.execof a command, withevent: null). Extensions add FACTS (any other property) throughExtension#commandContext; facts never replace the fields below. - CommandDef A command: a label, optional default keys, a
whencondition, ascopeand arunfunction. Declared by extensions (ExtensionInit.commands); every command is also an action of the bus (nabu.exec(id, data)). - ExtensionHooks The hooks an extension can register (
ExtensionInit.hooks). A hook returnsnabu.BREAK(or, foronSplit, an object) to stop the engine from going on; the others return nothing. Any other name is a custom hook, run withnabu.trigger(name, ...args). Declared as methods, so a handler may narrow the block parameter ((nabu, block: Paragraph) => ...). - ExtensionInit What an extension is made of: a block class and its component, hooks, serializers, actions, commands, paste interpreters and
file handlers, input rules, slash menu entries and Loro text styles. Every field is optional; pass it to
extension(name, init). - HtmlHelpers
- HtmlRule
selectoris a CSS selector tested withel.matches().priority: higher is tried first (a specific block beats a generic fallback).filter: an extra test once the selector matches.embed: the element may sit inside the inline content of another block and is then lifted out as a block of its own.props: props the rule asksfromHTMLto set. - InputRule A declarative text-replacement rule applied while typing: when the text before the caret matches
pattern,handlerruns (the markdown shortcuts and the typography substitutions are input rules). - MarkdownHelpers
- MarkdownRule
detect: does the block start at this line.consume: how many lines it takes fromindex(at least 1).priority: higher is tried first.interruptsParagraph: the block may start in the middle of a paragraph (a fence, a heading, a quote...);truemeans "wheneverdetectmatches". - NabuInternals The engine machinery behind
Nabu#internals. Unstable: may change in any version (seedocs/guides/extensions.md, "Stability"). Methods are bound to the editor; their signatures are those of theNabumethods of the same name. - NabuNode
- PasteBlock
- PasteFileHandler What an extension does with a FILE pasted from the clipboard (a screenshot, a file copied from the OS): it makes a block
of it. The engine reads the bytes, stores them through
Files(in the document, or sent tofiles.onBeforePersistwith the optimisticpendingblock) and inserts the blocks at the caret, in the order of the files, as ONE undo step. The engine names no block type: whatever an extension accepts is its own business. - PasteFragment
- PasteInterpreter
- PasteInterpretOptions
- Platform The platform whose conventions
Modand the displayed shortcuts follow:'mac'(Cmd) or'other'(Ctrl). - SerializeContext
recurse: serialize one child block.recurseAll(markdown only): serialize siblings in order, telling each its neighbours.before/after(markdown only): the siblings around this block. - SplitData What
onSplitreceives besides the block: where the text is cut, and the tail that moves to the new block.
nabu.internals
The door to the engine machinery behind the stable contract. Unstable: may change in any minor version. Read the warning and the keys →