/** * @zendir/ui - useLiveSelection Hook * * Manages "live follow" vs "pinned" selection for any streaming list. * * Behaviour: * - **Live mode** (default): the selection automatically tracks the newest * item in the list (index 0 after sorting newest-first). * - **Pinned mode**: the user has manually selected an item. The list can * continue to receive new items but the highlighted row stays fixed on the * chosen packet until the user explicitly resumes live follow. * - **Paused mode**: live updates to the list are frozen externally (handled * by the caller). Pinned selection is preserved across pause/resume. * * Usage: * ```ts * const { selectedId, isLive, isPinned, pin, resume } = useLiveSelection({ * items: filteredPackets, * getId: getPacketId, * isPaused, * }); * ``` */ export interface UseLiveSelectionOptions { /** The current (possibly filtered) ordered list, newest first. */ items: T[]; /** Derive a stable string identity from an item. */ getId: (item: T) => string | null; /** * When true, the caller is freezing new items from being added. * useLiveSelection will not try to auto-follow while paused. */ isPaused: boolean; } export interface UseLiveSelectionResult { /** The stable id of the currently selected item (null = nothing selected). */ selectedId: string | null; /** The currently selected item, or null. */ selectedItem: T | null; /** Index of the selected item within `items` (−1 if not found). */ selectedIndex: number; /** True when auto-following the newest item. False when user has pinned a selection. */ isLive: boolean; /** True when the user has manually pinned a specific item. */ isPinned: boolean; /** * Call this when the user manually clicks a row. * Switches to pinned mode and locks the given item as the selection. */ pin: (item: T) => void; /** * Call this to return to live-follow mode. * Clears the pinned selection and immediately selects the newest item. */ resume: () => void; } export declare function useLiveSelection({ items, getId, isPaused, }: UseLiveSelectionOptions): UseLiveSelectionResult;