View as Markdown

API reference: @salmonui/rich-text

RichTextEngineclass

import { RichTextEngine } from '@salmonui/rich-text';
class RichTextEngine {
    #private;
    readonly schema: Schema;
    readonly commands: RichTextCommands;
    readonly extensionCommands: Record<string, (...args: never[]) => Command>;
    readonly historyCommands: {
        readonly undo: Command;
        readonly redo: Command;
    } | null;
    state: EditorState;
    view: EditorView | null;
    constructor(options: EngineOptions, extensionPlugins: readonly Plugin[], schema?: Schema);
    parseHtml(html: string): PMNode;
    parseSlice(html: string): Slice;
    getHtml(options?: {
        readonly xhtml?: boolean | undefined;
    }): string;
    getText(): string;
    get characterCount(): number;
    get isEmpty(): boolean;
    setHtml(html: string, options?: {
        readonly addToHistory?: boolean;
    }): void;
    dispatch(tr: Transaction): void;
    exec(command: Command): boolean;
    run(id: string, ...args: unknown[]): unknown;
    subscribe(listener: Listener): () => void;
    getSelection(): RichTextSelection;
    setSelection(anchor: number, head?: number): void;
    clearHistory(): void;
    get suggest(): SuggestState | null;
    dismissSuggest(): void;
    completeSuggest(content: string | null): void;
    get findState(): import("./plugins.js").FindState | undefined;
    get painterActive(): boolean;
    insertFiles(files: readonly File[], at?: number): Promise<void>;
    mount(element: HTMLElement): EditorView;
    get mentionTarget(): MentionEditorTarget | null;
    focus(): void;
    refresh(): void;
    destroy(): void;
    selectedNode(): PMNode | null;
    sliceHtml(): string;
}
RichTextEngine members (34)
NameSignatureDescription
__#4@#private#private;
schemareadonly schema: Schema;
commandsreadonly commands: RichTextCommands;
extensionCommandsreadonly extensionCommands: Record<string, (...args: never[]) => Command>;
historyCommandsreadonly historyCommands: { readonly undo: Command; readonly redo: Command; } | null;

Undo and redo of an extension that replaces the history, else null.

statestate: EditorState;
viewview: EditorView | null;
parseHtmlparseHtml(html: string): PMNode;
parseSliceparseSlice(html: string): Slice;
getHtmlgetHtml(options?: { readonly xhtml?: boolean | undefined; }): string;
getTextgetText(): string;
characterCountget characterCount(): number;
isEmptyget isEmpty(): boolean;
setHtmlsetHtml(html: string, options?: { readonly addToHistory?: boolean; }): void;

Replaces the document (controlled value, form reset, source view).

dispatchdispatch(tr: Transaction): void;
execexec(command: Command): boolean;
runrun(id: string, ...args: unknown[]): unknown;

Runs a command, an alias, an extension command or a UI action by id; false when cancelled or not applied.

subscribesubscribe(listener: Listener): () => void;
getSelectiongetSelection(): RichTextSelection;
setSelectionsetSelection(anchor: number, head?: number): void;
clearHistoryclearHistory(): void;
suggestget suggest(): SuggestState | null;
dismissSuggestdismissSuggest(): void;
completeSuggestcompleteSuggest(content: string | null): void;

Replaces the active trigger and query (/head, :smi) with content.

findStateget findState(): import("./plugins.js").FindState | undefined;
painterActiveget painterActive(): boolean;
insertFilesinsertFiles(files: readonly File[], at?: number): Promise<void>;
mountmount(element: HTMLElement): EditorView;
mentionTargetget mentionTarget(): MentionEditorTarget | null;

The @salmonui/dropdowns/mention editor target over this view; one per view.

focusfocus(): void;
refreshrefresh(): void;

Refreshes decorations and editable state after option changes.

destroydestroy(): void;
selectedNodeselectedNode(): PMNode | null;

Selection as a NodeSelection of an image, figure, audio, video or embed, if any.

sliceHtmlsliceHtml(): string;