export type SortDirection = 'asc' | 'desc' | null; export type SortState<_T = unknown> = { sortBy: string | null; sortDirection: SortDirection; }; export type SortEvent = Partial>; export type ColumnComparators = Partial) => number>>; export interface UseSortingProps { data?: readonly T[]; /** * Default/initial state. If you pass `state`, these are ignored. */ sortBy?: string | null; sortDirection?: SortDirection; /** * Controlled mode: if provided, hook will not keep its own state. */ state?: SortState; onStateChange?: (next: SortState) => void; /** * Optional per-column comparator. * If absent, falls back to default compare on the field value. */ columnComparators?: ColumnComparators; /** * How to handle null/undefined values when using the default comparator: * - "first": nulls come first * - "last": nulls come last */ nulls?: 'first' | 'last'; /** * If true, toggling a column cycles: asc -> desc -> null * If false, cycles: asc -> desc -> asc ... */ allowUnsort?: boolean; /** * When true, resets sorting when data reference changes. * (Most people want to keep sort; default false.) */ resetOnDataChange?: boolean; } export interface UseSortingResult { sortedData: T[]; sortState: SortState; onSortChange: (e: SortEvent) => void; setSort: (next: SortState) => void; clearSort: () => void; } export declare function defaultCompare(a: unknown, b: unknown, dir: 'asc' | 'desc', nulls: 'first' | 'last'): number; export declare function useSorting>({ data, sortBy, sortDirection, state, onStateChange, columnComparators, nulls, allowUnsort, resetOnDataChange, }: UseSortingProps): UseSortingResult;