import { ColumnOrderState, Table, VisibilityState } from '@tanstack/react-table'; import { LeafColumnInfo } from '../helpers/columnIds'; export declare const getColumnOrderStorageKey: (uniqueKey?: string) => string | undefined; export declare const getColumnVisibilityStorageKey: (uniqueKey?: string) => string | undefined; /** * Whether a parsed `:column-order` value has the shape of an entry, **even one with nothing in it** (`{"v":1,"order":[]}`): the * right version and a list. That tells a well-formed entry (which confirms the user's own layout, empty or equal to the default * included) from a malformed one (which confirms nothing), where `sanitizeColumnOrder` answers `undefined` for both. */ export declare const isColumnOrderEntry: (raw: unknown) => raw is { v: number; order: unknown[]; }; /** The same for a parsed `:column-visibility` value: the right version and a map (`{"v":1,"visibility":{}}` is well formed). */ export declare const isColumnVisibilityEntry: (raw: unknown) => raw is { v: number; visibility: Record; }; /** * Checks a parsed `:column-order` value. Ids that no column has are kept: an order saved for columns that are not there at * the moment survives, and TanStack ignores them (ASMA-8597, DEC-W). `undefined` means nothing usable is saved. */ export declare const sanitizeColumnOrder: (raw: unknown) => string[] | undefined; /** * Checks a parsed `:column-visibility` value and returns the valid differences, or `undefined` when nothing usable is saved. * Values that are not booleans are dropped, and so are the ids of internal columns and of columns that cannot hide; **ids of * columns that are not there at the moment are kept** (DEC-W). */ export declare const sanitizeColumnVisibility: (raw: unknown, columns: readonly LeafColumnInfo[]) => Record | undefined; interface SavedColumnLayoutOptions { /** `persistColumnLayout`. */ enabled: boolean; uniqueKey: string | undefined; /** `persistColumnOrderKey`: where the order used to be saved, unscoped. */ legacyOrderKey: string | undefined; legacyVisibilityKey: string | undefined; /** The leaf columns of this render, in definition order. */ columns: readonly LeafColumnInfo[]; /** `initialState.columnOrder`, or `[]`. */ defaultOrder: ColumnOrderState; /** The whole visibility state the table opens with. */ defaultVisibility: VisibilityState; } export interface SavedColumnLayout { orderKey: string | undefined; visibilityKey: string | undefined; /** The saved order to open with, missing columns at their definition position (DEC-03), for the columns of this render. */ order: string[] | undefined; /** The whole visibility state to open with: this render's defaults with the saved differences on top. */ visibility: VisibilityState | undefined; } /** * Reads the saved layout of the table's current key, once per key, and migrates the old unscoped entries once (D-MIGRATE). * Reading is pure; the migration's writes and deletes happen in an effect, and are idempotent, so StrictMode's second run * changes nothing. **An old entry is deleted only after the entry that replaces it is written**: when storage refuses the * write (it is full or blocked) the old layout stays, and the next visit tries again. Needs to run before the table is * created, because the saved layout is part of its initial state. */ export declare const useSavedColumnLayout: (options: SavedColumnLayoutOptions) => SavedColumnLayout; export interface ColumnLayoutInputs { /** * What the table state was last brought in line with, as one string. `undefined` in a commit made while the layout was not * saved: nothing is reconciled then, so none is built (ASMA-8698); it is worked out from the inputs below if it is needed. */ signature: string | undefined; definitionIds: readonly string[]; defaultOrder: ColumnOrderState; defaultVisibility: VisibilityState; } /** * Whether the inputs the state was last brought in line with differ from this render's. A commit made while the layout was not * saved has no signature, so its is worked out from the inputs it recorded: a table that is opted in later, with other columns * or other defaults than it had, is reconciled exactly as one that was opted in all along. */ export declare const columnLayoutInputsChanged: (before: ColumnLayoutInputs | undefined, current: ColumnLayoutInputs) => boolean; /** * Keeps the table's state in step with the columns and the defaults of the current render (ASMA-8695, audit): the state was * created from what the first render knew, and TanStack never revisits it. * * - **A new column** goes to its definition position in an order the user changed (DEC-03), as it does when a saved order is * read; a user who has not moved anything stays on the definition order. * - **A changed default** reaches the user who had not changed that column: the order follows the new `initialState.columnOrder` * while the user is on the old default, and each column's visibility follows the new default unless the user changed it. * What the user changed stays. Without this the dot would show a difference the user never made. * * Returns `true` for the render in which the state is not yet in step: the writers wait (nothing is saved for a state that is * about to change), so a changed default is never saved as the user's choice. */ export declare const useColumnLayoutReconcile: (table: Table, options: { enabled: boolean; definitionIds: readonly string[]; defaultOrder: ColumnOrderState; defaultVisibility: VisibilityState; controlledVisibility: boolean; }) => boolean; interface ColumnLayoutWriterOptions { saved: SavedColumnLayout; /** `true` in the render that finds new columns or defaults, before the state is brought in line: nothing is written yet. */ reconciling: boolean; defaultOrder: ColumnOrderState; defaultVisibility: VisibilityState; /** The app owns `state.columnVisibility`: a key change blocks writes but does not set the state itself. */ controlledVisibility: boolean; } /** Saves the table's order and visibility under the keys of `saved`, by the storage rule of `usePersistedStateWriter`. */ export declare const useColumnLayoutWriter: (table: Table, options: ColumnLayoutWriterOptions) => void; export {};