API / @aionbuilders/nabu/extend

NabuInternals

Type Stability: unstable

The engine machinery behind Nabu#internals. Unstable: may change in any version (see docs/guides/extensions.md, "Stability"). Methods are bound to the editor; their signatures are those of the Nabu methods of the same name.

Unstable This shape may change in any minor version. See nabu.internals.

Related guide: Extensions: Stability →

Definition

TypeScript
import type { NabuInternals } from '@aionbuilders/nabu/extend';
TypeScript
interface NabuInternals {
  beforeinput: (e: InputEvent) => any;
  captureUndoSelection: (source?: 'user' | 'settle') => void;
  clearStoredMarks: () => void;
  commandConfirm: CommandConfirmation;
  content: LoroMap<Record<string, unknown>>;
  deleteNode: (nodeId: string) => void;
  dispatchEventToSelection: (handlerName: string, e: Event, hookName?: string) => void;
  dropAt: (dt: DataTransfer, position: DropPosition, opts?: { source?: { range: DeletionRange } | null }) => void;
  dropTarget: DropTarget | null;
  fileConfig: FilesConfig;
  handleBeforeinput: (e: InputEvent) => void;
  handleCompositionEnd: (e: CompositionEvent) => void;
  handleCompositionStart: (e: CompositionEvent) => void;
  handleCompositionUpdate: (e: CompositionEvent) => void;
  handleCopy: (e: ClipboardEvent) => void;
  handleCut: (e: ClipboardEvent) => void;
  handleDragEnd: (e?: DragEvent) => void;
  handleDragLeave: (e: DragEvent) => void;
  handleDragOver: (e: DragEvent) => void;
  handleDragStart: (e: DragEvent) => void;
  handleDrop: (e: DragEvent) => void;
  handleKeydown: (e: KeyboardEvent) => void;
  handleMousedown: (e: MouseEvent) => void;
  handlePaste: (e: ClipboardEvent) => void;
  hookOwners: WeakMap<Function, string>;
  hooks: Map<string, ((nabu: Nabu, ...args: any[]) => any)[]>;
  inputRules: InputRule[];
  insertFragment: (fragment: PasteFragment, opts?: { at?: DropPosition }) => void;
  noteTextChange: (block: Block) => void;
  pasteFileHandlers: PasteFileHandler[];
  pasteInterpreters: PasteInterpreter[];
  pulse: Pulse<typeof PulseEvent>;
  rearmTab: () => void;
  sealUndoEnd: () => void;
  selection: {
    attachRoot: (el: HTMLElement) => () => void;
    normalize: () => boolean;
    owns: (node: Node | null | undefined) => boolean;
    placements: number;
    repairAfterRemoval: () => boolean;
    root: HTMLElement | null;
    scheduleRepair: () => void;
    scope: (live?: Selection | null) => 'mine' | 'foreign' | 'outside';
  };
  selection.attachRoot: (el: HTMLElement) => () => void;
  selection.normalize: () => boolean;
  selection.owns: (node: Node | null | undefined) => boolean;
  selection.placements: number;
  selection.repairAfterRemoval: () => boolean;
  selection.root: HTMLElement | null;
  selection.scheduleRepair: () => void;
  selection.scope: (live?: Selection | null) => 'mine' | 'foreign' | 'outside';
  storedMarks: Record<string, boolean> | null;
  tabDescription: string | undefined;
  toggleStoredMark: (name: string) => void;
  undoManager: UndoManager;
  updateRoots: (retyped?: Set<string>) => void;
}

Properties

Properties of NabuInternals
PropertyTypeDescription
beforeinput(e: InputEvent) => anyn/a
captureUndoSelection(source?: 'user' | 'settle') => void

Remember the selection for the undo step now being recorded.

clearStoredMarks() => voidn/a
commandConfirmCommandConfirmation

The confirmation controller of commands (hold / invite / choose): start, stop, offer, choose, cancel, pending.

contentLoroMap<Record<string, unknown>>

The free-form content map of the document.

deleteNode(nodeId: string) => void

Delete a block by node id (no commit).

dispatchEventToSelection(handlerName: string, e: Event, hookName?: string) => void

Route a native event to the block that holds the selection.

dropAt(dt: DataTransfer, position: DropPosition, opts?: { source?: { range: DeletionRange } | null }) => void

Drop a DataTransfer at a position, as the drag and drop does.

dropTargetDropTarget | null

The drop indicator being shown (reactive).

fileConfigFilesConfig

The resolved files option.

handleBeforeinput(e: InputEvent) => voidn/a
handleCompositionEnd(e: CompositionEvent) => voidn/a
handleCompositionStart(e: CompositionEvent) => voidn/a
handleCompositionUpdate(e: CompositionEvent) => voidn/a
handleCopy(e: ClipboardEvent) => void

Write the selection to a clipboard (every format).

handleCut(e: ClipboardEvent) => voidn/a
handleDragEnd(e?: DragEvent) => voidn/a
handleDragLeave(e: DragEvent) => voidn/a
handleDragOver(e: DragEvent) => voidn/a
handleDragStart(e: DragEvent) => voidn/a
handleDrop(e: DragEvent) => voidn/a
handleKeydown(e: KeyboardEvent) => void

The keydown pipeline (commands first, then hooks, then the block).

handleMousedown(e: MouseEvent) => voidn/a
handlePaste(e: ClipboardEvent) => void

The paste pipeline (interpreters, files, acceptPaste).

hookOwnersWeakMap<Function, string>

Hook function to the name of the extension that registered it.

hooksMap<string, ((nabu: Nabu, ...args: any[]) => any)[]>

Extension hooks by name, in registration order (the normalizers of onBeforeTransaction, the onBeforeInput handlers...).

inputRulesInputRule[]

The input rules collected from the extensions.

insertFragment(fragment: PasteFragment, opts?: { at?: DropPosition }) => void

Insert a PasteFragment at the selection (what a paste does after interpreting).

noteTextChange(block: Block) => voidn/a
pasteFileHandlersPasteFileHandler[]

The paste file handlers, by priority.

pasteInterpretersPasteInterpreter[]

The paste interpreters collected from the extensions.

pulsePulse<typeof PulseEvent>

The action bus behind exec(): pulse.on(topic, handler) observes or adds a topic at runtime.

rearmTab() => voidn/a
sealUndoEnd() => void

Close the "where did the last action end" mark of the undo history.

selection{ attachRoot: (el: HTMLElement) => () => void; normalize: () => boolean; owns: (node: Node | null | undefined) => boolean; placements: number; repairAfterRemoval: () => boolean; root: HTMLElement | null; scheduleRepair: () => void; scope: (live?: Selection | null) => 'mine' | 'foreign' | 'outside'; }

The selection's own repair machinery, and the engine's root element: attachRoot(el) (what Nabu.svelte calls on mount, it returns the detach function), root, owns(node) (inside MY root, not in a nested editor) and scope() ('mine' | 'outside' | 'foreign': whose business the live DOM selection is).

selection.attachRoot(el: HTMLElement) => () => voidn/a
selection.normalize() => booleann/a
selection.owns(node: Node | null | undefined) => booleann/a
selection.placementsnumbern/a
selection.repairAfterRemoval() => booleann/a
selection.rootHTMLElement | nulln/a
selection.scheduleRepair() => voidn/a
selection.scope(live?: Selection | null) => 'mine' | 'foreign' | 'outside'n/a
storedMarksRecord<string, boolean> | null

Pending inline marks for the next typed character (reactive; assignable).

tabDescriptionstring | undefined

The aria-description the root carries while tab traps the focus.

toggleStoredMark(name: string) => voidn/a
undoManagerUndoManager

The Loro undo manager (undo steps, merge window).

updateRoots(retyped?: Set<string>) => void

Re-read the root blocks from the tree.

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