/** * Trigger sessions — the state machine behind the suggestion popup. * * The element exposes no keystrokes, so the session is a pure function of the * editor's two event streams: document text (`bindchange`) and the collapsed * caret offset (`bindselection`). On every sync we look at the **run** — the * non-whitespace text between the last boundary and the caret. A run starting * with a trigger (`@` / a pattern match) means an active session whose query * is the rest of the run; anything else means no session. Whitespace, caret * exits, blur and selection all close it for free, because they all change * the run. * * `onQuery` may be async: results are tagged with an epoch and discarded when * a newer query (or a close) supersedes them. An optional per-trigger * `debounce` batches fast typing. */ import type { TriggerItem, TriggerSpec } from '../plugin.js'; export interface TriggerSession { /** Owning plugin's name. */ plugin: string; /** Offset of the trigger char (run start) in the document text. */ anchor: number; /** Text typed after the trigger prefix. */ query: string; /** Caret offset (exclusive end of the run). */ caret: number; /** Latest resolved suggestions ([] while loading or empty). */ items: TriggerItem[]; /** True while an async `onQuery` for the current query is in flight. */ loading: boolean; } export interface TriggerSessionManager { /** Feed the latest document text (from `bindchange`). */ syncText(text: string): void; /** Feed the collapsed caret offset (from `bindselection`); `-1` = no collapsed caret. */ syncCaret(caret: number): void; /** Close the active session (blur, selection made, escape). */ close(): void; readonly session: TriggerSession | null; } export interface TriggerSessionManagerOptions { triggers: ReadonlyArray<{ plugin: string; spec: TriggerSpec; }>; /** Fired whenever the session opens, updates (query/items), or closes. */ onUpdate(session: TriggerSession | null): void; } export declare function createTriggerSessionManager(opts: TriggerSessionManagerOptions): TriggerSessionManager;