/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import type { SlotItem } from "./model/slots.js"; /** A box as the viewport measures it — what `getBoundingClientRect` gives. */ export interface PlacementBox { /** Its left edge. */ readonly left: number; /** Its top edge. */ readonly top: number; /** Its width. */ readonly width: number; /** Its height. */ readonly height: number; } /** What {@link placeAutocomplete} places the popover by. */ export interface AutocompletePlacementInput { /** The slot's box, as the viewport measures it. */ readonly anchor: PlacementBox; /** The builder's box, as the viewport measures it. */ readonly bounds: PlacementBox; /** The popover's width, in the builder's own pixels (its `offsetWidth`). */ readonly width: number; /** How much the builder is CSS-scaled: its measured width over its own (`offsetWidth`); 1 when it is not. */ readonly scale: number; } /** The popover below its slot, in the builder's own pixels. */ export interface AutocompleteBelow { /** The side of its slot it opens on. */ readonly side: "below"; /** Its left edge, from the builder's. */ readonly left: number; /** Its top edge, from the builder's. */ readonly top: number; /** Its greatest height, to end inside the builder. */ readonly maxHeight: number; } /** The popover above its slot, in the builder's own pixels: its bottom edge is held, so it grows upward. */ export interface AutocompleteAbove { /** The side of its slot it opens on. */ readonly side: "above"; /** Its left edge, from the builder's. */ readonly left: number; /** Its bottom edge, from the builder's bottom edge. */ readonly bottom: number; /** Its greatest height, to start inside the builder. */ readonly maxHeight: number; } /** Where the popover goes, in the builder's own pixels. */ export type AutocompletePlacement = AutocompleteBelow | AutocompleteAbove; /** * Where the slot autocomplete goes (`Query Editor Spec.md` §4.5): left-aligned * with its slot and clamped 8px inside the builder; 4px below the slot, or 4px * above it when under 280px remain below and more is above. A CSS-scaled * builder measures scaled, so every measure is divided by its scale into the * builder's own pixels, the ones its absolutely positioned popover is laid * out in. * * @param input - the slot's and the builder's boxes as measured, the popover's width and the builder's scale * @returns the side it opens on, its left edge and its top edge (below) or bottom edge (above), and its greatest height */ export declare function placeAutocomplete({ anchor, bounds, width, scale }: AutocompletePlacementInput): AutocompletePlacement; /** Props of {@link SlotAutocomplete}. */ export interface SlotAutocompleteProps { /** The slot's element: the popover hangs from it, and a press on it is the host's (it toggles the slot), not a press outside. */ anchor: HTMLElement; /** * The builder's element: the popover is portaled into it and stays inside * it, absolutely positioned in its coordinates — so it is the popover's * containing block (positioned, or transformed). */ bounds: HTMLElement; /** Its label — `FIELD` (#934's `slotLabel`). */ label: string; /** The filter's placeholder (#934's `slotPlaceholder`). */ placeholder: string; /** The footer's hint: where the offers come from (#934's `slotHint`). */ hint: string; /** What it says with nothing to offer (#934's `slotEmpty`). */ empty: string; /** The keys' hint, `↑↓ ⏎ esc` (#934's `slotKeys`). */ keys: string; /** * The offers for the text typed — #934's `slotItems`, which the host * recomputes on each change of text. A new list for the same text (a * summary arrived) keeps the active offer, found by its group and label, * while it is still offered. */ items: readonly SlotItem[]; /** The text typed; a text the host sets, other than the one typed, replaces it. */ text: string; /** Told each change of the text. */ onText: (text: string) => void; /** * The offer active when it opens — #934's `activeItem`; `-1` when none can * be picked. Typing makes the first offer that can be picked active. */ initialActive: number; /** Told the offer picked: ⏎, Tab or a click. */ onPick: (item: SlotItem) => void; /** Told it closes: Esc, or a press outside it and its anchor. */ onClose: () => void; /** * A phone's frame's overlay slot: drawn there, a view over the whole builder (`Query Builder Phone Spec.md` QP33) — * ← back and its label at its head, the filter in a 56 band, its rows at least 44, where the offers come from at its * foot — placed nowhere and floating over nothing. Esc goes back, wherever the focus is. */ view?: HTMLElement | null | undefined; /** The name of the view's ←. */ backLabel?: string | undefined; /** What it is for, beside the view's title: `Step 1 · condition 2`. */ context?: string | undefined; /** A view with no filter: a short list of steps (QP34). */ noFilter?: boolean | undefined; } /** * The slot autocomplete — see the module docs. It opens with `initialActive` * active and its filter focused (without scrolling); the active offer stays in * view. While it is open it follows its slot as the page scrolls or resizes, * and when it closes with the focus in it, the focus returns to its slot. * Callbacks reach the host through `queueMicrotask`. * * @param props - its slot and builder, its words, the offers, the text typed, and the callbacks ({@link SlotAutocompleteProps}) * @returns the popover, portaled into the builder */ export declare const SlotAutocomplete: import("react").MemoExoticComponent<({ anchor, bounds, label, placeholder, hint, empty, keys, items, text, onText, initialActive, onPick, onClose, view, backLabel, context, noFilter, }: SlotAutocompleteProps) => import("react").ReactPortal>; //# sourceMappingURL=autocomplete.d.ts.map