View as Markdown

API reference: @salmonui/rich-text

RichTextCommandsinterface

import type { RichTextCommands } from '@salmonui/rich-text';
interface RichTextCommands {
    bold(): boolean;
    italic(): boolean;
    underline(): boolean;
    strike(): boolean;
    subscript(): boolean;
    superscript(): boolean;
    code(): boolean;
    uppercase(): boolean;
    lowercase(): boolean;
    fontFamily(value: string | null): boolean;
    fontSize(value: string | null): boolean;
    color(value: string | null): boolean;
    backgroundColor(value: string | null): boolean;
    paragraph(): boolean;
    heading(level: 1 | 2 | 3 | 4 | 5 | 6): boolean;
    blockquote(): boolean;
    codeBlock(language?: string | null): boolean;
    setCodeLanguage(language: string | null): boolean;
    textAlign(align: RichTextTextAlign | null): boolean;
    lineHeight(value: string | null): boolean;
    indent(): boolean;
    outdent(): boolean;
    bulletList(style?: RichTextBulletStyle | null): boolean;
    orderedList(style?: RichTextOrderedStyle | null): boolean;
    taskList(): boolean;
    toggleTask(): boolean;
    horizontalRule(): boolean;
    clearFormat(): boolean;
    setLink(link: RichTextLinkInput): boolean;
    unsetLink(): boolean;
    insertImage(image: RichTextImageInput): boolean;
    updateImage(image: Partial<RichTextImageInput>): boolean;
    insertAudio(media: RichTextMediaInput): boolean;
    insertVideo(media: RichTextMediaInput): boolean;
    insertEmbed(media: RichTextMediaInput): boolean;
    deleteNode(): boolean;
    insertTable(size: {
        readonly rows: number;
        readonly cols: number;
        readonly headerRow?: boolean | undefined;
    }): boolean;
    addRowBefore(): boolean;
    addRowAfter(): boolean;
    deleteRow(): boolean;
    addColumnBefore(): boolean;
    addColumnAfter(): boolean;
    deleteColumn(): boolean;
    mergeCells(): boolean;
    splitCell(): boolean;
    toggleHeaderRow(): boolean;
    setTableStyle(style: RichTextTableStyle | null): boolean;
    deleteTable(): boolean;
    insertText(text: string): boolean;
    insertHtml(html: string, options?: {
        readonly blocks?: boolean;
    }): boolean;
    selectAll(): boolean;
    undo(): boolean;
    redo(): boolean;
    find(query: string, options?: RichTextFindOptions): number;
    findNext(): boolean;
    findPrevious(): boolean;
    replace(text: string): boolean;
    replaceAll(text: string): number;
    clearFind(): boolean;
    copyFormat(sticky?: boolean): boolean;
    applyFormat(): boolean;
    cancelFormatPainter(): boolean;
}

Typed commands (actionsRef.current.commands); each returns whether it applied.

RichTextCommands members (62)
NameSignatureDescription
boldbold(): boolean;
italicitalic(): boolean;
underlineunderline(): boolean;
strikestrike(): boolean;
subscriptsubscript(): boolean;
superscriptsuperscript(): boolean;
codecode(): boolean;
uppercaseuppercase(): boolean;
lowercaselowercase(): boolean;
fontFamilyfontFamily(value: string | null): boolean;
fontSizefontSize(value: string | null): boolean;
colorcolor(value: string | null): boolean;
backgroundColorbackgroundColor(value: string | null): boolean;
paragraphparagraph(): boolean;
headingheading(level: 1 | 2 | 3 | 4 | 5 | 6): boolean;
blockquoteblockquote(): boolean;
codeBlockcodeBlock(language?: string | null): boolean;
setCodeLanguagesetCodeLanguage(language: string | null): boolean;
textAligntextAlign(align: RichTextTextAlign | null): boolean;
lineHeightlineHeight(value: string | null): boolean;
indentindent(): boolean;
outdentoutdent(): boolean;
bulletListbulletList(style?: RichTextBulletStyle | null): boolean;
orderedListorderedList(style?: RichTextOrderedStyle | null): boolean;
taskListtaskList(): boolean;
toggleTasktoggleTask(): boolean;
horizontalRulehorizontalRule(): boolean;
clearFormatclearFormat(): boolean;
setLinksetLink(link: RichTextLinkInput): boolean;
unsetLinkunsetLink(): boolean;
insertImageinsertImage(image: RichTextImageInput): boolean;
updateImageupdateImage(image: Partial<RichTextImageInput>): boolean;
insertAudioinsertAudio(media: RichTextMediaInput): boolean;
insertVideoinsertVideo(media: RichTextMediaInput): boolean;
insertEmbedinsertEmbed(media: RichTextMediaInput): boolean;
deleteNodedeleteNode(): boolean;
insertTableinsertTable(size: { readonly rows: number; readonly cols: number; readonly headerRow?: boolean | undefined; }): boolean;
addRowBeforeaddRowBefore(): boolean;
addRowAfteraddRowAfter(): boolean;
deleteRowdeleteRow(): boolean;
addColumnBeforeaddColumnBefore(): boolean;
addColumnAfteraddColumnAfter(): boolean;
deleteColumndeleteColumn(): boolean;
mergeCellsmergeCells(): boolean;
splitCellsplitCell(): boolean;
toggleHeaderRowtoggleHeaderRow(): boolean;
setTableStylesetTableStyle(style: RichTextTableStyle | null): boolean;
deleteTabledeleteTable(): boolean;
insertTextinsertText(text: string): boolean;
insertHtmlinsertHtml(html: string, options?: { readonly blocks?: boolean; }): boolean;

Sanitized and parsed through the schema, replacing the selection like a paste; { blocks: true } inserts whole blocks after splitting the current one (imports).

selectAllselectAll(): boolean;
undoundo(): boolean;
redoredo(): boolean;
findfind(query: string, options?: RichTextFindOptions): number;

Highlights matches and selects the first; returns the match count.

findNextfindNext(): boolean;
findPreviousfindPrevious(): boolean;
replacereplace(text: string): boolean;

Replaces the current match and moves to the next.

replaceAllreplaceAll(text: string): number;

Returns the number of replaced matches.

clearFindclearFind(): boolean;
copyFormatcopyFormat(sticky?: boolean): boolean;

Format painter: copy the format at the selection (sticky keeps applying until cancelFormatPainter).

applyFormatapplyFormat(): boolean;
cancelFormatPaintercancelFormatPainter(): boolean;