View as Markdown

API reference: @salmonui/rich-text

RichTextExtensioninterface

import type { RichTextExtension } from '@salmonui/rich-text';
interface RichTextExtension {
    readonly name: string;
    readonly nodes?: Readonly<Record<string, NodeSpec>>;
    readonly marks?: Readonly<Record<string, MarkSpec>>;
    readonly plugins?: (context: RichTextExtensionContext) => readonly Plugin[] | Promise<readonly Plugin[]>;
    readonly keyBindings?: Readonly<Record<string, string | Command>>;
    readonly inputRules?: (schema: Schema) => readonly InputRule[];
    readonly commands?: Readonly<Record<string, (...args: never[]) => Command>>;
    readonly toolbarItems?: readonly RichTextExtensionToolbarItem[];
    readonly html?: {
        readonly tags?: readonly string[];
        readonly attributes?: Readonly<Record<string, readonly string[]>>;
    };
    readonly replacesHistory?: boolean;
    readonly history?: {
        readonly undo: Command;
        readonly redo: Command;
    };
}

An editor extension: schema nodes and marks, ProseMirror plugins (a factory may be async, for example the /collab Yjs binding), key bindings, input rules, commands and toolbar items. Keep the array stable.

RichTextExtension members (11)
NameSignatureDescription
namereadonly name: string;
nodesoptionalreadonly nodes?: Readonly<Record<string, NodeSpec>>;
marksoptionalreadonly marks?: Readonly<Record<string, MarkSpec>>;
pluginsoptionalreadonly plugins?: (context: RichTextExtensionContext) => readonly Plugin[] | Promise<readonly Plugin[]>;
keyBindingsoptionalreadonly keyBindings?: Readonly<Record<string, string | Command>>;

Key -> command id or ProseMirror command, before the built-in table (ProseMirror key names, Mod- for Ctrl/Cmd).

inputRulesoptionalreadonly inputRules?: (schema: Schema) => readonly InputRule[];
commandsoptionalreadonly commands?: Readonly<Record<string, (...args: never[]) => Command>>;

Command id -> factory of a ProseMirror command; run with actionsRef.current.run(id, ...args).

toolbarItemsoptionalreadonly toolbarItems?: readonly RichTextExtensionToolbarItem[];
htmloptionalreadonly html?: { readonly tags?: readonly string[]; readonly attributes?: Readonly<Record<string, readonly string[]>>; };

Elements and attributes the extension's nodes and marks write, added to the always-on sanitizer for value in, paste and HTML out. Active content (script, style, iframe, object, embed, forms), on* handlers, style and URL attributes other than href / cite / src / poster are never allowed; those four are checked by the URL rules.

replacesHistoryoptionalreadonly replacesHistory?: boolean;

Turns off history in the engine (the Yjs undo manager replaces it).

historyoptionalreadonly history?: { readonly undo: Command; readonly redo: Command; };

The undo and redo that replace the engine's (with replacesHistory): commands.undo / redo, the toolbar and its enabled state use them. Called without dispatch they answer whether a step is available.