export type MenuWindowSize = "xs" | "sm" | "md" | "lg" | "xl"; export type MenuWindowUpdateOptions< Item extends Record = Record, > = { /** The collection the menu renders, filtered where there is a filter. */ items: ReadonlyArray; /** What identifies an option across a rebuild of `items`. */ getKey?: (item: Item, index: number) => unknown; /** The threshold gate, from `shouldVirtualizeMenu`. */ shouldVirtualize: boolean; virtualize: boolean | object | undefined; /** * Wrapping makes options unequal in height, so it is what turns measuring on. * Nothing else does: a `measured` key on `virtualize` is dropped. */ wrapOptions?: boolean; size?: MenuWindowSize; /** Whether menu items render at the fluid height. */ fluid?: boolean; scrollTop: number; }; export type MenuWindowState< Item extends Record = Record, > = { itemsToRender: Item[]; isVirtualized: boolean; startIndex: number; offsetY: number; totalHeight: number; /** A CSS length: the windowed viewport, or the size-based maximum. */ menuMaxHeight: string; /** * Whether a windowing configuration was resolved, which differs from the list * being windowed: one below the threshold resolves a config and still renders * whole. `menuMaxHeight` came from the viewport when this is `true`, so an * overflow rule gates on this. */ isWindowed: boolean; isMeasured: boolean; /** * Whether the windowed options are pinned to the viewport, as * `optimizeFastScroll` asks. */ isPinned: boolean; }; export type MenuWindow< Item extends Record = Record, > = { /** Resolve the window for the options the menu is about to render. */ update(options: MenuWindowUpdateOptions): MenuWindowState; /** * Bring the option at `index` into view, on whichever of the measured and * fixed-height paths the menu is on. */ scrollIntoView(index: number, align: "top" | "nearest"): void; /** * Reconcile height observation against what the menu now renders and * re-satisfy any outstanding scroll request. Call it after a render. */ sync(): void | Promise; /** Note a scroll event, so the reader supersedes an outstanding request. */ noteScroll(scrollTop: number): void; /** Forget the measurements on close; the estimate they averaged to survives. */ reset(): void; /** Stop observing for good. */ destroy(): void; }; export type CreateMenuWindowOptions< Item extends Record = Record, > = { /** The menu's scroll container, or nothing when the menu is not rendered. */ getContainer: () => HTMLElement | null | undefined; /** The scroll position the container actually took. */ onScrollTop: (scrollTop: number) => void; /** Called with a state resolved again because measurement moved it. */ onState?: (state: MenuWindowState) => void; }; /** * Which options a listbox menu renders and where they sit: the windowing * configuration, the visible slice, the measured heights and the estimate that * outlives them, scroll placement, and the menu's maximum height. * * Builds on the offset arithmetic in `src/utils/virtualize.js` and the DOM * height observation in `src/utils/height-measurer.js`. */ export declare function createMenuWindow< Item extends Record = Record, >(options: CreateMenuWindowOptions): MenuWindow; export type ScheduleHighlightScrollOptions = { open: boolean; shouldVirtualize: boolean; highlightedIndex: number; prevHighlightedIndex: number; listRef: HTMLElement | null | undefined; menuWindow: MenuWindow; }; /** * Call from `afterUpdate`. Schedules (via `tick`) a scroll of the newly * highlighted option into view. * * @returns The value to store as `prevHighlightedIndex`. */ export declare function scheduleHighlightScroll( options: ScheduleHighlightScrollOptions, ): number;