import { type Debounced } from '../../internal/debounce'; import type { ComboboxOption } from './combobox'; /** Matches maker-ds's `DEFAULT_DEBOUNCE_MS`. */ export declare const DEFAULT_DEBOUNCE_MS = 250; /** * An async option loader. Receives the current search term and an `AbortSignal` that * is aborted as soon as a newer search supersedes this one. * * The signal is the one addition to maker-ds's shape. Upstream discards a stale result * by comparing a request id after the await, which is correct as far as rendering goes * but leaves the superseded request running to completion — every keystroke past the * debounce holds a connection open until the server answers nobody. Passing the signal * lets a `fetch`-based loader actually cancel. Ignoring it still works. */ export type AsyncOptionsLoader = (searchTerm: string, signal: AbortSignal) => Promise | TOption[]; /** `options` is either a static array or a loader. The function form is what selects async mode. */ export type ComboboxOptionsProp = TOption[] | AsyncOptionsLoader; export interface UseAsyncOptionsParams { /** Identifies the combobox in the error it logs when a load fails. */ id: string; /** Whether async mode is active. `false` makes every member of the result inert. */ enabled: boolean; options: ComboboxOptionsProp; /** Called once with the first result, so a caller can resolve a preselected label. */ onInitialize?: (options: TOption[]) => void; /** @default 250 */ debounceMs?: number; } export interface UseAsyncOptionsResult { options: TOption[]; /** True while any request is in flight. */ isLoading: boolean; /** True only while the very first request is in flight. */ isInitializing: boolean; error: unknown; load: (searchTerm: string) => Promise; debouncedLoad: Debounced<[string]>; } /** * Drives an async `options` loader for `Combobox`. * * Stale-safe two ways. A monotonic request id means a late result cannot overwrite a * newer one — the same guard maker-ds uses, repeated in the success, failure, and * settle paths so a late rejection cannot clear a newer request's loading flag. And * each superseded request has its `AbortSignal` aborted, which upstream does not do. * * Deliberately not ported from upstream: * * - **`enableRefetchOnChange`.** Implemented there and passed by neither combobox, so * it is untested dead capability. A caller who wants a refetch can change the loader * identity, which already refetches. * - **Result caching.** Upstream has none, and adding it here would be inventing * invalidation semantics nobody has asked for. Each settled keystroke is one request. */ export declare function useAsyncOptions({ id, enabled, options, onInitialize, debounceMs, }: UseAsyncOptionsParams): UseAsyncOptionsResult; //# sourceMappingURL=use-async-options.d.ts.map