import type { EditorState } from "prosemirror-state"; import type { EditorView } from "prosemirror-view"; import { type MentionSource } from "./mentionAutocomplete"; /** * Re-open BlockNote's suggestion menu for an `@`-token that already exists in * the document. * * BlockNote's `SuggestionMenuPlugin` only ever *activates* from `handleTextInput` * — i.e. the moment the trigger character is literally typed — and its state is * destroyed by any transaction carrying a `focus`, `blur` or `pointer` meta. So * once the editor loses focus mid-mention (`@yan`), clicking back in leaves the * menu permanently closed: neither re-focus nor typing more of the token can * bring it back, and the user has to delete and retype the `@`. * * This module re-arms the plugin from the outside whenever the caret comes to * rest inside a valid mention token and the menu is closed. Detection reuses * {@link parseActiveMention}, so all the trigger rules (the `@` must start a * word, whitespace ends the token, longest-prefix source routing) stay in one * place and behave identically to the textarea frontend. */ /** The subset of the BlockNote editor API this module needs. */ export type MentionReopenEditor = { readonly prosemirrorView?: EditorView; readonly domElement?: HTMLElement; readonly suggestionMenus: { readonly shown: boolean; }; readonly isEditable: boolean; }; export type MentionReopenOptions = { /** Sources to use. Falls back to the global registry (`setMentionSources`). */ sources?: MentionSource[]; /** Must match the menu's trigger. Only `@` is supported; anything else is a no-op. */ triggerCharacter?: string; }; type MentionHit = { /** Document position of the `@`. */ atPos: number; /** Document position of the caret (end of the token). */ caret: number; }; /** * Attach the re-open behavior to a BlockNote editor. Returns a cleanup function. * * Listeners live on `document` (not on the editor element) so that attaching * does not depend on the ProseMirror view already being mounted; each handler * checks that the event happened inside this editor. */ export declare function attachMentionReopen(editor: MentionReopenEditor, options?: MentionReopenOptions): () => void; /** * The mention token the caret sits in, as document positions. Returns `null` * for non-collapsed selections, code blocks, and any caret that is not inside a * token an available source claims. */ export declare function findMentionAtCaret(state: EditorState, sources: MentionSource[]): MentionHit | null; export {};