View as Markdown

API reference: @salmonui/dropdowns/mention

MentionEditorTargetinterface

import type { MentionEditorTarget } from '@salmonui/dropdowns/mention';
interface MentionEditorTarget {
    readonly element: HTMLElement;
    getTextBeforeCaret(): string | null;
    getCaretRect(offset: number): {
        readonly left: number;
        readonly top: number;
        readonly bottom: number;
    } | null;
    insertMention(insertion: MentionEditorInsertion): void;
    subscribe(listener: () => void): () => void;
}

A rich text surface Mention attaches to instead of a <textarea> or <input>: a plain contenteditable element through createContentEditableMentionTarget, or the @salmonui/rich-text engine. Offsets count the characters of the current text block, an inline atom (an inserted mention) as one U+FFFC character.

MentionEditorTarget members (5)
NameSignatureDescription
elementreadonly element: HTMLElement;

The editable element (the host gives it role="textbox"). Mention adds the combobox ARIA attributes to it while the list is open, listens for keydown in the capture phase (keys it handles while open call preventDefault() and stopImmediatePropagation()), for composition and for focusout.

getTextBeforeCaretgetTextBeforeCaret(): string | null;

Text of the current text block from its start to the caret; null when the selection is not collapsed or not editable.

getCaretRectgetCaretRect(offset: number): { readonly left: number; readonly top: number; readonly bottom: number; } | null;

Viewport rectangle of the character at offset of that text, null when unknown.

insertMentioninsertMention(insertion: MentionEditorInsertion): void;

Replaces [start, end) of the text block with the mention (and its suffix) and puts the caret after it.

subscribesubscribe(listener: () => void): () => void;

Calls listener after the editor applied a text or selection change; returns the unsubscribe function.