import type { GridSortDirection, GridSortModel } from '@mui/x-data-grid'; import { type ListPageSort } from '@aglyn/shared-util-tools/list-query/list-column-sort'; import type { ListQuerySort } from '@aglyn/shared-util-tools/list-query/list-query-plan'; /** * How a column's header sorts, as `ListTable` reads it: by the query, over * the loaded page (and says so), or over a list loaded WHOLE (`complete`), * where a value sort orders every row and is exact. */ export interface ListColumnSortColumn { mode: 'query' | 'page' | 'loaded'; sortingOrder: GridSortDirection[]; } export interface ListColumnSort { /** The order to ask the query for, or null for the list's own order. */ sort: ListQuerySort | null; sortModel: GridSortModel; onSortModelChange: (model: GridSortModel) => void; sortingMode: 'server'; /** The rows to draw: the page, sorted while a page header is active. */ rows: readonly Row[]; /** What the reader is told about the order on screen. */ notices: string[]; /** Every column that sorts, by field. A column not here does not. */ columns: Readonly>; /** * A page sort by a comparator a column hands over itself — a plugin column * that draws its own header. `null` clears it if it is still that column's. */ sortPage: (id: string, compare: ((a: Row, b: Row) => number) | null) => void; /** The comparator column sorting the page, or null. */ pageSortedBy: string | null; } export interface ListColumnSortOptions { /** * The orders the list's query serves. Each one with a `column` is a header * sort; the rest (the default id order) are ignored here. Usually the * declaration's `sorts`. */ sorts: readonly ListQuerySort[]; /** The order asked while no header is: one of `sorts`, or null. */ defaultSort?: ListQuerySort | null; /** * The asked order, CONTROLLED — for a list whose query is read before the * rows this hook sorts exist (the order feeds the read; the read feeds the * rows). Omitted, the hook holds it. */ sort?: ListQuerySort | null; onSortChange?: (sort: ListQuerySort | null) => void; /** * The order the query WILL read in — the plan's `orderBy` — when that can * differ from the one asked (an `alone` fallback, a range filter). The * header shows that order, not the one clicked. */ orderBy?: ListQuerySort | null; rows: readonly Row[]; /** Columns sorted over the loaded page (strategy 3): field → value. */ pageSorts?: Readonly>>; /** Headers, for the page-sort notice: field → label. */ headers?: Readonly>; /** * The rows are the WHOLE list, not a page of it (strategy 4) — a roster * read in full and paged by the grid's own footer. A `pageSorts` column * then orders every row, so its header is exact: mode `loaded`, no "this * page" description and no notice. Lets a fully loaded list sort its own * columns and a plugin column's comparator through ONE order. */ complete?: boolean; } export declare function useListColumnSort(options: ListColumnSortOptions): ListColumnSort;