/** * What a key means to a widget, and what a listbox does with an arrow. * * The mapping from a key to an intent belongs to the kind — a combobox opens on ArrowDown, a dialog * overlay does not — and the catalogue is what says which is which. */ import type { MdyUiCommand } from "../commands.js"; import type { MdyWidgetKind } from "../catalog.js"; export type MdyWidgetKeyIntent = { readonly type: "open"; } | { readonly type: "close"; readonly restoreFocus: boolean; } | { readonly type: "move"; readonly target: "next" | "previous" | "first" | "last"; } | { readonly type: "commit"; } | { readonly type: "cancel"; readonly restoreFocus: boolean; } | { readonly type: "toggle"; } | { readonly type: "increment"; } | { readonly type: "decrement"; } /** Move whatever holds focus one place earlier or later in the value. */ | { readonly type: "reorder"; readonly by: -1 | 1; } /** Take off whatever holds focus. */ | { readonly type: "remove"; } /** * A printable character typed at a list: jump to the first option that begins with it. * * Carries the character rather than a target, because which option it lands on depends on the * labels — and the labels are the renderer's, not this layer's. */ | { readonly type: "typeahead"; readonly character: string; } /** * Pick up whatever holds focus, or put it down — one key, because it is one state seen from both * ends. What is held moves with the bare arrows and goes back where it was on `Escape`. */ | { readonly type: "grab"; } /** Put back the last destructive change, whichever act produced it. */ | { readonly type: "undo"; }; /** * How close to the viewport edge a popup may sit. Exported because it is part of the placement * arithmetic an adapter or a test has to be able to reproduce: room above an anchor is * `anchorTop - MDY_OVERLAY_VIEWPORT_MARGIN`, not `anchorTop`. */ export declare function widgetKeyIntent(kind: MdyWidgetKind, key: string, open: boolean): MdyWidgetKeyIntent | null; export declare function overlayCloseCommands(restoreFocus: boolean): readonly MdyUiCommand[]; export type MdyOptionNavigationTarget = "next" | "previous" | "first" | "last"; /** Resolves roving option navigation without any framework or DOM dependency. */ /** * Listbox navigation: clamps at the ends, and ArrowUp from "nothing active" lands on the last * option. Distinct from `optionNavigationIndex`, which wraps because a segmented control is a * closed ring. Adapters take both from here so a listbox never quietly behaves like a ring. */ export declare function optionNavigationIndex(key: string, currentIndex: number, optionCount: number): number | null;