import { OnChangeFn, SortingState } from '@tanstack/react-table';
export declare const getSortingStorageKey: (uniqueKey?: string) => string | undefined;
/** What decides whether `StyledTable` saves a table's sorting: the props that matter, read from the table's own. */
export interface SortingPersistenceInput {
uniqueKey?: string;
/** The `persistSorting` prop as the app wrote it; `undefined` when it did not. */
persistSorting?: boolean;
/**
* The app owns the sorting state: it passes `state.sorting`, or `onSortingChange`. TanStack hands every change to that
* handler instead of updating the table's own state, so a handler alone is as much the app's state as `state.sorting`.
*/
controlled: boolean;
}
/**
* Whether `StyledTable` reads and writes the sorting under `${uniqueKey}:sorting` (ASMA-8698, DEC-8698-OPTOUT).
*
* - No `uniqueKey`: never.
* - `persistSorting={false}`: never, the opt-out for tables whose order is the user's own (drag and drop).
* - `persistSorting={true}`: yes, even when the app owns the sorting state. That is how such an app lets `StyledTable` be the
* only writer of the sort it reads back with `usePersistedSorting`.
* - Not written: yes, unless the app owns the sorting state. A saved sort could not be applied to a state the table does not
* own, and an app that persists its own sort would have two writers fighting over it.
*/
export declare const savesSorting: ({ uniqueKey, persistSorting, controlled }: SortingPersistenceInput) => boolean;
/** What a saved sort is checked against: the columns that can sort, and the multi-sort rules. */
export interface SortingRules {
sortableColumns: readonly {
id: string;
canMultiSort: boolean;
}[];
/** `false` keeps only the first saved entry. */
enableMultiSort?: boolean;
maxMultiSortColCount?: number;
}
/**
* Checks a parsed `:sorting` value (`{"v":1,"sorting":[{"id","desc"}]}`) and returns the valid rest, or
* `undefined` when it holds nothing usable and the app's default sorting should apply. A saved empty list
* is a real answer (sorting turned off) and returns `[]`.
*/
export declare const sanitizeSorting: (raw: unknown, rules: SortingRules) => SortingState | undefined;
export declare const serializeSorting: (sorting: SortingState) => string;
export declare const sortingSignature: (sorting: SortingState) => string;
export declare const readSortingFromStorage: (uniqueKey: string | undefined, rules: SortingRules) => SortingState | undefined;
export interface PersistedSortingOptions {
/** Ids of the columns the table can sort by; saved entries for any other column are dropped. */
sortableColumnIds: readonly string[];
/** Multi-sort rules of the table; both default to TanStack's (allowed, no cap). */
enableMultiSort?: boolean;
maxMultiSortColCount?: number;
}
/**
* Reads the sorting `StyledTable` saved for `uniqueKey`, checked against the columns
* the caller can sort by. Synchronous and pure, so a table that owns its sorting state (for example because
* the server sorts) can use the saved sort for its first request. Returns `undefined` when nothing valid is
* saved, and `[]` when the user turned sorting off.
*/
export declare const readPersistedSorting: (uniqueKey: string | undefined, options: PersistedSortingOptions) => SortingState | undefined;
/**
* Sorting state for a table that owns `state.sorting`: the saved sort on the first render (before the first
* request), `defaultSorting` when nothing valid is saved, and the new key's sort after `uniqueKey` changes.
* It never writes: `StyledTable` is the only writer, and it saves a sort the app owns only with `persistSorting` written
* on the table (see `savesSorting`). It takes the same default from `initialState.sorting`, which Reset columns restores.
*
* ```tsx
* const { sorting, onSortingChange } = usePersistedSorting({ uniqueKey, defaultSorting, sortableColumnIds })
*
* ```
*/
export declare const usePersistedSorting: ({ uniqueKey, defaultSorting, ...options }: PersistedSortingOptions & {
uniqueKey?: string;
defaultSorting?: SortingState;
}) => {
sorting: SortingState;
onSortingChange: OnChangeFn;
};