import type { KeyboardEvent as ReactKeyboardEvent, RefObject } from 'react'; import type { EditorState, MentionItem, MentionQuery, MentionQueryOptions } from '@rtif-sdk/web'; import type { EditorHandle } from './use-editor.js'; /** * Async entity search the app implements (architecture §9.1). `search` MUST * forward `signal` to the underlying request (`fetch(url, { signal })`) so a * superseded search actually cancels; the hook never commits aborted results. */ export interface MentionSource { search(query: MentionQuery, signal: AbortSignal): Promise; /** Quiet period before `search` fires while the user types (default 120ms). */ readonly debounceMs?: number; } /** Options for {@link useMentions}. Read live — the latest render's values win. */ export interface UseMentionsOptions { /** Sigil → detection options; pass the same object given to `createMentionsFeature`. */ readonly triggers: Readonly>; readonly source: MentionSource; /** Insert command run by {@link MentionsApi.pick} (default `'mentions.insert'`). */ readonly command?: string; /** Map a picked item for insertion when `TItem` is not `MentionItem`-shaped. */ readonly toItem?: (item: TItem) => MentionItem; /** Replace insertion wholesale; when set, `pick` calls this instead of the command. */ readonly onPick?: (item: TItem, query: MentionQuery) => void; /** Replace trigger detection wholesale (default `findMentionQuery(state, triggers)`). */ readonly detect?: (state: EditorState) => MentionQuery | null; } /** Caret rect relative to the container element. */ export interface MentionPopupPosition { readonly left: number; readonly top: number; } /** Everything a dropdown UI needs; rendered by `MentionsPopup` or any custom component. */ export interface MentionsApi { /** An active query exists and a search is loading or has returned. */ readonly open: boolean; /** A search is in flight (previous results stay visible to avoid flicker). */ readonly loading: boolean; /** * The last (non-aborted) search failure for this query; null when none. * Cleared when the next search starts or the query ends. */ readonly error: unknown; readonly query: MentionQuery | null; readonly items: readonly TItem[]; readonly activeIndex: number; readonly position: MentionPopupPosition | null; /** Attach on the editor container so ↑/↓/Enter/Tab/Escape never reach the editor while open. */ readonly onKeyDownCapture: (event: ReactKeyboardEvent) => void; pick(item: TItem): void; highlight(index: number): void; /** Suppress the popup until the caret leaves the current query. */ dismiss(): void; } /** * The mention-autocomplete state machine (architecture §9.1): trigger * detection is a `useEditorState` selector; searching is delegated to the * app's async {@link MentionSource}. The hook owns debounce, AbortController * cancellation of superseded searches, and stale-response dropping. Headless — * render the returned {@link MentionsApi} with `MentionsPopup` or your own UI. * * @param editor - The handle from `useEditor`. * @param containerRef - Positioning origin for the popup (style it `position: relative`). * @param options - Triggers, source, and the customization hooks. * @returns The dropdown state and actions. */ export declare function useMentions(editor: EditorHandle, containerRef: RefObject, options: UseMentionsOptions): MentionsApi; //# sourceMappingURL=use-mentions.d.ts.map