import type React from 'react'; import type { ColumnDef, ColumnFiltersState, ColumnPinningState, GlobalFilter, HeaderGroup, PaginationState, Row, RowData, SortingState, Table, TableMeta } from '@tanstack/table-core'; import type { Promisable, Simplify } from 'type-fest'; import type { MEMOIZED_HANDLE_ID, ROW_ACTIONS_METADATA_KEY, TABLE_NAME_METADATA_KEY } from './constants.ts'; import type { DataTableEmptyStateProps } from './DataTableEmptyState.tsx'; declare module '@tanstack/table-core' { interface ColumnMeta { [key: string]: unknown; } type GlobalFilter = string | undefined; interface TableMeta { [key: string]: unknown; [ROW_ACTIONS_METADATA_KEY]?: DataTableRowAction[]; [TABLE_NAME_METADATA_KEY]?: string; } interface TableState { globalFilter: GlobalFilter; } } /********************************************************************* * BASE *********************************************************************/ export type BaseDataTableStoreParams = { columnBreakpoints?: DataTableColumnBreakpoints; columns: ColumnDef>[]; data: T[]; meta?: TableMeta>; rowActions?: DataTableRowAction>[]; tableName?: string; }; export type DataTableColumnBreakpoints = { 0: number; 512: number; 768: number; 1024: number; 1280: number; }; export type DataTableContentProps = { disableSearch?: boolean; emptyStateProps?: Partial; onRowClick?: (row: T) => Promisable; onRowDoubleClick?: (row: T) => Promisable; onSearchChange?: DataTableSearchChangeHandler>; togglesComponent?: React.FC<{ table: Table; }>; }; export type DataTableHandles = { [K in keyof T]: MemoizedHandle<() => T[K]>; }; export type DataTableRowAction = { destructive?: boolean; disabled?: ((row: T) => boolean) | boolean; label: string; onSelect: (row: T, table: Table) => Promisable; }; export type DataTableSearchChangeHandler = (value: string, table: Table) => void; export type MemoizedHandle any> = T & { invalidate(): void; [MEMOIZED_HANDLE_ID]: symbol; }; /********************************************************************* * CLIENT *********************************************************************/ export type ClientDataTableInitialState = { columnFilters?: ColumnFiltersState; columnPinning?: ColumnPinningState; sorting?: SortingState; }; export type ClientDataTableStoreParams = Simplify & { initialState?: ClientDataTableInitialState; mode?: 'client'; }>; export type ClientDataTableProps = Simplify & DataTableContentProps>; /********************************************************************* * SERVER *********************************************************************/ export type ServerDataTableStoreParams = Simplify & { initialState?: never; mode: 'server'; onPaginationChange: (state: PaginationState) => void; onSortingChange?: (state: SortingState) => void; pageCount: number; }>; export type ServerDataTableProps = DataTableContentProps & ServerDataTableStoreParams; /********************************************************************* * COMMON *********************************************************************/ export type DataTableStoreParams = ClientDataTableStoreParams | ServerDataTableStoreParams; export type DataTableProps = ClientDataTableProps | ServerDataTableProps; export type DataTableStore = { $handles: DataTableHandles<{ headerGroups: HeaderGroup[]; paginationInfo: { pageCount: number; pageIndex: number; }; rowCount: number; rows: Row[]; table: Table; tableMeta: TableMeta; }>; _containerWidth: null | number; _key: symbol; reset: (params: DataTableStoreParams) => void; setContainerWidth: (containerWidth: number) => void; setGlobalFilter: (globalFilter: GlobalFilter) => void; setPageIndex: (index: number) => void; style: React.CSSProperties; }; //# sourceMappingURL=types.d.ts.map