From 199fffc26877742e81438a105ffe30fd1b2b7597 Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Sun, 29 Sep 2024 14:03:31 -0500 Subject: [PATCH] trying out internal types --- .../column-filtering/ColumnFiltering.types.ts | 2 +- .../column-grouping/ColumnGrouping.types.ts | 2 +- .../column-ordering/ColumnOrdering.types.ts | 2 +- .../column-pinning/ColumnPinning.types.ts | 2 +- .../column-resizing/ColumnResizing.types.ts | 2 +- .../column-sizing/ColumnSizing.types.ts | 2 +- .../ColumnVisibility.types.ts | 2 +- .../global-filtering/GlobalFiltering.types.ts | 2 +- .../global-filtering/GlobalFiltering.utils.ts | 38 ++---- .../row-expanding/RowExpanding.types.ts | 2 +- .../row-pagination/RowPagination.types.ts | 2 +- .../features/row-pinning/RowPinning.types.ts | 2 +- .../row-selection/RowSelection.types.ts | 2 +- .../features/row-sorting/RowSorting.types.ts | 2 +- packages/table-core/src/types/ColumnDef.ts | 63 ++++++++-- .../table-core/src/types/TableFeatures.ts | 8 +- packages/table-core/src/types/TableState.ts | 108 +++++++++++++++--- 17 files changed, 175 insertions(+), 68 deletions(-) diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts index f1ea51772c..28ead4ac25 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts @@ -22,7 +22,7 @@ export interface TableState_ColumnFiltering_Unavailable { /** * @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs. */ - columnFilters: ColumnFiltersState + columnFilters?: ColumnFiltersState } export type ColumnFiltersState = Array diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts index b0ffff93b2..1809c87df8 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts @@ -21,7 +21,7 @@ export interface TableState_ColumnGrouping_Unavailable { /** * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. */ - grouping: GroupingState + grouping?: GroupingState } export interface AggregationFns {} diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts index d4846f071e..08fce14559 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts @@ -12,7 +12,7 @@ export interface TableState_ColumnOrdering_Unavailable { /** * @deprecated Import the `ColumnOrdering` feature to use the column ordering APIs. */ - columnOrder: ColumnOrderState + columnOrder?: ColumnOrderState } export interface TableOptions_ColumnOrdering { diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts index 2d5bc0509e..68cfa35b81 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts @@ -20,7 +20,7 @@ export interface TableState_ColumnPinning_Unavailable { /** * @deprecated Import the `ColumnPinning` feature to use the column pinning APIs. */ - columnPinning: ColumnPinningState + columnPinning?: ColumnPinningState } export interface TableOptions_ColumnPinning { diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts index ee64040dca..f8787ae2fd 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts @@ -8,7 +8,7 @@ export interface TableState_ColumnResizing_Unavailable { /** * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. */ - columnResizing: columnResizingState + columnResizing?: columnResizingState } export interface columnResizingState { diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts index e771f608b7..0fd21425a6 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts @@ -9,7 +9,7 @@ export interface TableState_ColumnSizing_Unavailable { /** * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. */ - columnSizing: ColumnSizingState + columnSizing?: ColumnSizingState } export type ColumnSizingState = Record diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts index 26ab2594ed..7528492354 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts @@ -13,7 +13,7 @@ export interface TableState_ColumnVisibility_Unavailable { /** * @deprecated Import the `ColumnVisibility` feature to use the column visibility APIs. */ - columnVisibility: ColumnVisibilityState + columnVisibility?: ColumnVisibilityState } export interface TableOptions_ColumnVisibility { diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts index d904292dc9..0f0d19edcf 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts @@ -19,7 +19,7 @@ export interface TableState_GlobalFiltering_Unavailable { /** * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. */ - globalFilter: any + globalFilter?: any } export interface ColumnDef_GlobalFiltering { diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts index 0e5c8a75fd..b03b3afe71 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts @@ -1,18 +1,15 @@ import { filterFns } from '../../fns/filterFns' import { isFunction } from '../../utils' import { table_getInitialState } from '../../core/table/Tables.utils' +import type { ColumnDefBase_All } from '../../types/ColumnDef' +import type { TableOptions_GlobalFiltering } from './GlobalFiltering.types' import type { - ColumnDef_GlobalFiltering, - TableOptions_GlobalFiltering, -} from './GlobalFiltering.types' -import type { - ColumnDef_ColumnFiltering, FilterFn, TableOptions_ColumnFiltering, } from '../column-filtering/ColumnFiltering.types' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table, Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { BuiltInFilterFn } from '../../fns/filterFns' @@ -28,16 +25,9 @@ export function column_getCanGlobalFilter< TValue extends CellData = CellData, >( column: Column & { - columnDef: Partial< - ColumnDef_GlobalFiltering & ColumnDef_ColumnFiltering - > - }, - table: Table & { - options: Partial< - TableOptions_GlobalFiltering & - TableOptions_ColumnFiltering - > + columnDef: ColumnDefBase_All }, + table: Table_Internal, ): boolean { return ( (column.columnDef.enableGlobalFilter ?? true) && @@ -61,12 +51,7 @@ export function table_getGlobalFilterFn< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial< - TableOptions_GlobalFiltering & - TableOptions_ColumnFiltering - > - }, + table: Table_Internal ): FilterFn | FilterFn | undefined { const { globalFilterFn: globalFilterFn } = table.options @@ -87,9 +72,7 @@ export function table_setGlobalFilter< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, updater: any, ) { table.options.onGlobalFilterChange?.(updater) @@ -104,12 +87,7 @@ export function table_resetGlobalFilter< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial< - TableOptions_GlobalFiltering & - TableOptions_ColumnFiltering - > - }, + table: Table_Internal, defaultState?: boolean, ) { table_setGlobalFilter( diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts index dd48ffa134..89cbbe83e1 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts @@ -14,7 +14,7 @@ export interface TableState_RowExpanding_Unavailable { /** * @deprecated Import the `RowExpanding` feature to use the row expansion APIs. */ - expanded: ExpandedState + expanded?: ExpandedState } export interface Row_RowExpanding { diff --git a/packages/table-core/src/features/row-pagination/RowPagination.types.ts b/packages/table-core/src/features/row-pagination/RowPagination.types.ts index 9cb02cb78b..d17ee8e5be 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.types.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.types.ts @@ -14,7 +14,7 @@ export interface TableState_RowPagination_Unavailable { /** * @deprecated Import the `RowPagination` feature to use the row pagination APIs. */ - pagination: PaginationState + pagination?: PaginationState } export interface TableOptions_RowPagination { diff --git a/packages/table-core/src/features/row-pinning/RowPinning.types.ts b/packages/table-core/src/features/row-pinning/RowPinning.types.ts index 698dc940ed..d9f567d1d0 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.types.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.types.ts @@ -17,7 +17,7 @@ export interface TableState_RowPinning_Unavailable { /** * @deprecated Import the `RowPinning` feature to use the row pinning APIs. */ - rowPinning: RowPinningState + rowPinning?: RowPinningState } export interface TableOptions_RowPinning< diff --git a/packages/table-core/src/features/row-selection/RowSelection.types.ts b/packages/table-core/src/features/row-selection/RowSelection.types.ts index 2102b802f8..45a63d70fb 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.types.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.types.ts @@ -13,7 +13,7 @@ export interface TableState_RowSelection_Unavailable { /** * @deprecated Import the `RowSelection` feature to use the row selection APIs. */ - rowSelection: RowSelectionState + rowSelection?: RowSelectionState } export interface TableOptions_RowSelection< diff --git a/packages/table-core/src/features/row-sorting/RowSorting.types.ts b/packages/table-core/src/features/row-sorting/RowSorting.types.ts index 58b62e1dc5..067842a482 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.types.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.types.ts @@ -21,7 +21,7 @@ export interface TableState_RowSorting_Unavailable { /** * @deprecated Import the `RowSorting` feature to use the row sorting APIs. */ - sorting: SortingState + sorting?: SortingState } export interface SortingFns {} diff --git a/packages/table-core/src/types/ColumnDef.ts b/packages/table-core/src/types/ColumnDef.ts index b72e72732e..839faa2beb 100644 --- a/packages/table-core/src/types/ColumnDef.ts +++ b/packages/table-core/src/types/ColumnDef.ts @@ -2,14 +2,35 @@ import type { CellData, RowData, UnionToIntersection } from './type-utils' import type { TableFeatures } from './TableFeatures' import type { CellContext } from '../core/cells/Cells.types' import type { HeaderContext } from '../core/headers/Headers.types' -import type { ColumnDef_ColumnFiltering } from '../features/column-filtering/ColumnFiltering.types' -import type { ColumnDef_ColumnGrouping } from '../features/column-grouping/ColumnGrouping.types' -import type { ColumnDef_ColumnPinning } from '../features/column-pinning/ColumnPinning.types' -import type { ColumnDef_ColumnResizing } from '../features/column-resizing/ColumnResizing.types' +import type { + ColumnDef_ColumnFiltering, + ColumnDef_ColumnFiltering_Unavailable, +} from '../features/column-filtering/ColumnFiltering.types' +import type { + ColumnDef_ColumnGrouping, + ColumnDef_ColumnGrouping_Unavailable, +} from '../features/column-grouping/ColumnGrouping.types' +import type { + ColumnDef_ColumnPinning, + ColumnDef_ColumnPinning_Unavailable, +} from '../features/column-pinning/ColumnPinning.types' +import type { + ColumnDef_ColumnResizing, + ColumnDef_ColumnResizing_Unavailable, +} from '../features/column-resizing/ColumnResizing.types' import type { ColumnDef_ColumnSizing } from '../features/column-sizing/ColumnSizing.types' -import type { ColumnDef_ColumnVisibility } from '../features/column-visibility/ColumnVisibility.types' -import type { ColumnDef_GlobalFiltering } from '../features/global-filtering/GlobalFiltering.types' -import type { ColumnDef_RowSorting } from '../features/row-sorting/RowSorting.types' +import type { + ColumnDef_ColumnVisibility, + ColumnDef_ColumnVisibility_Unavailable, +} from '../features/column-visibility/ColumnVisibility.types' +import type { + ColumnDef_GlobalFiltering, + ColumnDef_GlobalFiltering_Unavailable, +} from '../features/global-filtering/GlobalFiltering.types' +import type { + ColumnDef_RowSorting, + ColumnDef_RowSorting_Unavailable, +} from '../features/row-sorting/RowSorting.types' export interface ColumnMeta< TFeatures extends TableFeatures, @@ -92,6 +113,34 @@ export type ColumnDefBase< : never) > +// export type ColumnDefBase< +// TFeatures extends TableFeatures, +// TData extends RowData, +// TValue extends CellData = CellData, +// > = ColumnDefBase_Core & +// ('ColumnVisibility' extends keyof TFeatures +// ? ColumnDef_ColumnVisibility +// : ColumnDef_ColumnVisibility_Unavailable) & +// ('ColumnPinning' extends keyof TFeatures +// ? ColumnDef_ColumnPinning +// : ColumnDef_ColumnPinning_Unavailable) & +// ('ColumnFiltering' extends keyof TFeatures +// ? ColumnDef_ColumnFiltering +// : ColumnDef_ColumnFiltering_Unavailable) & +// ('GlobalFiltering' extends keyof TFeatures +// ? ColumnDef_GlobalFiltering +// : ColumnDef_GlobalFiltering_Unavailable) & +// ('RowSorting' extends keyof TFeatures +// ? ColumnDef_RowSorting +// : ColumnDef_RowSorting_Unavailable) & +// ('ColumnGrouping' extends keyof TFeatures +// ? ColumnDef_ColumnGrouping +// : ColumnDef_ColumnGrouping_Unavailable) & +// ('ColumnSizing' extends keyof TFeatures ? ColumnDef_ColumnSizing : {}) & +// ('ColumnResizing' extends keyof TFeatures +// ? ColumnDef_ColumnResizing +// : ColumnDef_ColumnResizing_Unavailable) + export type ColumnDefBase_All< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/TableFeatures.ts b/packages/table-core/src/types/TableFeatures.ts index 504584e9af..655a5e4aae 100644 --- a/packages/table-core/src/types/TableFeatures.ts +++ b/packages/table-core/src/types/TableFeatures.ts @@ -54,11 +54,11 @@ export interface TableFeature { } export interface CoreTableFeatures { - Tables?: TableFeature - Rows?: TableFeature - Headers?: TableFeature - Columns?: TableFeature Cells?: TableFeature + Columns?: TableFeature + Headers?: TableFeature + Rows?: TableFeature + Tables?: TableFeature } export interface TableFeatures extends CoreTableFeatures { diff --git a/packages/table-core/src/types/TableState.ts b/packages/table-core/src/types/TableState.ts index bc4e28e2d4..faae28231e 100644 --- a/packages/table-core/src/types/TableState.ts +++ b/packages/table-core/src/types/TableState.ts @@ -1,20 +1,59 @@ import type { UnionToIntersection } from './type-utils' -import type { TableState_ColumnFiltering } from '../features/column-filtering/ColumnFiltering.types' -import type { TableState_ColumnGrouping } from '../features/column-grouping/ColumnGrouping.types' -import type { TableState_ColumnOrdering } from '../features/column-ordering/ColumnOrdering.types' -import type { TableState_ColumnPinning } from '../features/column-pinning/ColumnPinning.types' -import type { TableState_ColumnResizing } from '../features/column-resizing/ColumnResizing.types' -import type { TableState_ColumnSizing } from '../features/column-sizing/ColumnSizing.types' -import type { TableState_ColumnVisibility } from '../features/column-visibility/ColumnVisibility.types' -import type { TableState_GlobalFiltering } from '../features/global-filtering/GlobalFiltering.types' -import type { TableState_RowExpanding } from '../features/row-expanding/RowExpanding.types' -import type { TableState_RowPagination } from '../features/row-pagination/RowPagination.types' -import type { TableState_RowPinning } from '../features/row-pinning/RowPinning.types' -import type { TableState_RowSelection } from '../features/row-selection/RowSelection.types' -import type { TableState_RowSorting } from '../features/row-sorting/RowSorting.types' +import type { + TableState_ColumnFiltering, + TableState_ColumnFiltering_Unavailable, +} from '../features/column-filtering/ColumnFiltering.types' +import type { + TableState_ColumnGrouping, + TableState_ColumnGrouping_Unavailable, +} from '../features/column-grouping/ColumnGrouping.types' +import type { + TableState_ColumnOrdering, + TableState_ColumnOrdering_Unavailable, +} from '../features/column-ordering/ColumnOrdering.types' +import type { + TableState_ColumnPinning, + TableState_ColumnPinning_Unavailable, +} from '../features/column-pinning/ColumnPinning.types' +import type { + TableState_ColumnResizing, + TableState_ColumnResizing_Unavailable, +} from '../features/column-resizing/ColumnResizing.types' +import type { + TableState_ColumnSizing, + TableState_ColumnSizing_Unavailable, +} from '../features/column-sizing/ColumnSizing.types' +import type { + TableState_ColumnVisibility, + TableState_ColumnVisibility_Unavailable, +} from '../features/column-visibility/ColumnVisibility.types' +import type { + TableState_GlobalFiltering, + TableState_GlobalFiltering_Unavailable, +} from '../features/global-filtering/GlobalFiltering.types' +import type { + TableState_RowExpanding, + TableState_RowExpanding_Unavailable, +} from '../features/row-expanding/RowExpanding.types' +import type { + TableState_RowPagination, + TableState_RowPagination_Unavailable, +} from '../features/row-pagination/RowPagination.types' +import type { + TableState_RowPinning, + TableState_RowPinning_Unavailable, +} from '../features/row-pinning/RowPinning.types' +import type { + TableState_RowSelection, + TableState_RowSelection_Unavailable, +} from '../features/row-selection/RowSelection.types' +import type { + TableState_RowSorting, + TableState_RowSorting_Unavailable, +} from '../features/row-sorting/RowSorting.types' import type { TableFeatures } from './TableFeatures' -export type TableState = { +export type _TableState = { /** * @deprecated */ @@ -62,3 +101,44 @@ export type TableState_All = Partial< TableState_RowSelection & TableState_RowSorting > + +export type TableState = + ('ColumnFiltering' extends keyof TFeatures + ? TableState_ColumnFiltering + : TableState_ColumnFiltering_Unavailable) & + ('ColumnGrouping' extends keyof TFeatures + ? TableState_ColumnGrouping + : TableState_ColumnGrouping_Unavailable) & + ('ColumnOrdering' extends keyof TFeatures + ? TableState_ColumnOrdering + : TableState_ColumnOrdering_Unavailable) & + ('ColumnPinning' extends keyof TFeatures + ? TableState_ColumnPinning + : TableState_ColumnPinning_Unavailable) & + ('ColumnResizing' extends keyof TFeatures + ? TableState_ColumnResizing + : TableState_ColumnResizing_Unavailable) & + ('ColumnSizing' extends keyof TFeatures + ? TableState_ColumnSizing + : TableState_ColumnSizing_Unavailable) & + ('ColumnVisibility' extends keyof TFeatures + ? TableState_ColumnVisibility + : TableState_ColumnVisibility_Unavailable) & + ('GlobalFiltering' extends keyof TFeatures + ? TableState_GlobalFiltering + : TableState_GlobalFiltering_Unavailable) & + ('RowExpanding' extends keyof TFeatures + ? TableState_RowExpanding + : TableState_RowExpanding_Unavailable) & + ('RowPagination' extends keyof TFeatures + ? TableState_RowPagination + : TableState_RowPagination_Unavailable) & + ('RowPinning' extends keyof TFeatures + ? TableState_RowPinning + : TableState_RowPinning_Unavailable) & + ('RowSelection' extends keyof TFeatures + ? TableState_RowSelection + : TableState_RowSelection_Unavailable) & + ('RowSorting' extends keyof TFeatures + ? TableState_RowSorting + : TableState_RowSorting_Unavailable)