/** * Lightweight deep equality check optimized for DataTable rows. * Compares arrays of row objects by first checking IDs (fast path), * then falling back to deep object comparison to handle nested structures. */ export function rowsEqual( a: ReadonlyArray | null, b: ReadonlyArray | null, ): boolean; /** * Returns true if the element's class list indicates the click target * is an overflow menu, checkbox, or radio button (row click should be ignored). */ export function shouldIgnoreRowClick(target: EventTarget | null): boolean; /** * Resolves a nested property path in an object. * Supports both direct property access and nested paths like "contact.company". */ export function resolvePath>( object: T, path: string, ): unknown; /** * Paginates an array of rows based on page number and page size. */ export function getDisplayedRows>( rows: ReadonlyArray, page: number, pageSize: number, ): ReadonlyArray; /** * Formats header width styles for table headers. * Combines width and minWidth into a CSS style string. */ export function formatHeaderWidth< Header extends { width?: string | null | number; minWidth?: string | null | number; [key: string]: unknown; } = { width?: string | null | number; minWidth?: string | null | number; [key: string]: unknown; }, >(header: Header): string | undefined; /** * Compares two values for sorting in a data table. * Handles numbers, strings, null/undefined values, and custom sort functions. * @returns {number} Negative if a < b (ascending) or a > b (descending), positive if a > b (ascending) or a < b (descending), 0 if equal */ export function compareValues( itemA: T, itemB: T, ascending: boolean, customSort?: ((a: T, b: T) => number) | false | undefined, ): number; export type ToCsvHeader = { /** Column key. Supports nested paths like `"contact.company"`. */ key: string; /** Column label written to the header row. Falls back to `key`. */ value?: unknown; /** Whether the column renders no data. Empty columns are skipped. */ empty?: boolean; /** Whether the column is hidden. Hidden columns are skipped. */ columnHidden?: boolean; /** Formats the cell value, matching the rendered table. */ display?: (item: unknown, row: Row) => unknown; }; export type ToCsvOptions = { /** * Field delimiter. Set to `"\t"` for TSV or `";"` for locales where * Excel expects it. * @default "," */ delimiter?: string; /** * Emit the header row. * @default true */ includeHeaders?: boolean; /** * Prefix a field starting with `=`, `+`, `-`, `@`, tab, or carriage return * with a single quote so spreadsheets do not evaluate it as a formula. * @default true */ escapeFormulas?: boolean; /** * Line ending. RFC 4180 specifies `"\r\n"`, which is what Excel expects. * @default "\r\n" */ newline?: string; }; /** * Serializes data table headers and rows to a CSV string. * Skips empty and hidden columns, resolves nested keys, and applies `display` * formatting so the export matches the rendered table. */ export function toCsv>( headers: ReadonlyArray>, rows: ReadonlyArray, options?: ToCsvOptions, ): string; type PathDepth = [never, 0, 1, 2, ...0[]]; type Join = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}` : never : never; /** * Drops string/number index signatures so `keyof` is only declared keys. * Used for paths on `DataTableRow` and subtypes, whose index signature would * otherwise widen `PropertyPath` to plain `string`. */ export type KeysWithoutIndexSignature = { [ K in keyof T as string extends K ? never : number extends K ? never : K ]: T[K]; }; // For performance, the maximum traversal depth is 3. export type PropertyPath = [D] extends [never] ? never : T extends object ? { [K in keyof T]-?: K extends string | number ? `${K}` | Join> : never; }[keyof T] : ""; /** * Like {@link PropertyPath}, but ignores string/number index signatures at * each object level so declared keys stay as literal unions (for `DataTableRow` subtypes). */ export type PropertyPathIgnoringIndexSignatures = [ D, ] extends [never] ? never : T extends object ? { [K in keyof KeysWithoutIndexSignature]-?: K extends string | number ? | `${K}` | Join< K, PropertyPathIgnoringIndexSignatures< KeysWithoutIndexSignature[K], PathDepth[D] > > : never; }[keyof KeysWithoutIndexSignature] : ""; /** * Cell value type at a column path (e.g. `"port"` or `"contact.company"`). */ export type DataTableValueAtPath = Row extends object ? Path extends keyof Row & string ? Row[Path] : Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Row ? DataTableValueAtPath, Rest> : unknown : unknown : unknown; /** * Union of cell value types for all column paths on `Row`. * Used for default and per-column `sort` comparators. * * `Row` is unconstrained so generated `DataTableSortValue` aliases stay valid; * non-object `Row` resolves to `never`. */ export type DataTableSortValue = Row extends object ? PropertyPath extends infer K ? K extends string ? DataTableValueAtPath : never : never : never;