From d3e480db1f128138b3be51e8b247fb94c0b9d922 Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Wed, 20 Nov 2024 21:23:55 -0600 Subject: [PATCH] add plugin system! --- examples/react/custom-features/src/main.tsx | 88 +++++++++++------- .../createFacetedMinMaxValues.ts | 15 +++- .../column-faceting/createFacetedRowModel.ts | 21 +++-- .../createFacetedUniqueValues.ts | 15 +++- .../createFilteredRowModel.ts | 29 +++--- .../column-grouping/createGroupedRowModel.ts | 35 ++++---- .../row-expanding/createExpandedRowModel.ts | 28 +++--- .../row-pagination/createPaginatedRowModel.ts | 21 +++-- .../row-sorting/createSortedRowModel.ts | 27 +++--- packages/table-core/src/types/Cell.ts | 9 ++ packages/table-core/src/types/Column.ts | 11 ++- packages/table-core/src/types/ColumnDef.ts | 4 +- packages/table-core/src/types/Header.ts | 11 ++- packages/table-core/src/types/HeaderGroup.ts | 5 +- .../table-core/src/types/ProcessingFns.ts | 32 ++++--- packages/table-core/src/types/Row.ts | 11 ++- packages/table-core/src/types/RowModel.ts | 13 ++- packages/table-core/src/types/Table.ts | 5 +- .../table-core/src/types/TableFeatures.ts | 7 +- packages/table-core/src/types/TableOptions.ts | 5 +- packages/table-core/src/types/TableState.ts | 90 +++++++++---------- 21 files changed, 303 insertions(+), 179 deletions(-) diff --git a/examples/react/custom-features/src/main.tsx b/examples/react/custom-features/src/main.tsx index f58f7752c9..61104b131e 100644 --- a/examples/react/custom-features/src/main.tsx +++ b/examples/react/custom-features/src/main.tsx @@ -2,12 +2,18 @@ import React from 'react' import ReactDOM from 'react-dom/client' import './index.css' import { + columnFilteringFeature, createFilteredRowModel, createPaginatedRowModel, createSortedRowModel, + filterFns, flexRender, functionalUpdate, makeStateUpdater, + rowPaginationFeature, + rowSortingFeature, + sortFns, + tableFeatures, useTable, } from '@tanstack/react-table' import { makeData } from './makeData' @@ -19,6 +25,7 @@ import type { Table, TableFeature, TableFeatures, + TableState, Updater, } from '@tanstack/react-table' import type { Person } from './makeData' @@ -27,40 +34,42 @@ import type { Person } from './makeData' // define types for our new feature's custom state export type DensityState = 'sm' | 'md' | 'lg' -export interface DensityTableState { +export interface TableState_Density { density: DensityState } // define types for our new feature's table options -export interface DensityOptions { +export interface TableOptions_Density { enableDensity?: boolean onDensityChange?: OnChangeFn } // Define types for our new feature's table APIs -export interface DensityInstance { +export interface Table_Density { setDensity: (updater: Updater) => void toggleDensity: (value?: DensityState) => void } // Use declaration merging to add our new feature APIs and state types to TanStack Table's existing types. declare module '@tanstack/react-table' { + // declare our new feature as a plugin + interface Plugins { + densityPlugin: TableFeature + } // merge our new feature's state with the existing table state - interface TableState extends DensityTableState {} + interface TableState_Plugins extends TableState_Density {} // merge our new feature's options with the existing table options - interface TableOptions - extends DensityOptions {} + interface TableOptions_Plugins extends TableOptions_Density {} // merge our new feature's instance APIs with the existing table instance APIs - interface Table - extends DensityInstance {} + interface Table_Plugins extends Table_Density {} // if you need to add cell instance APIs... - // interface Cell extends DensityCell + // interface Cell_Plugins extends Cell_Density {} // if you need to add row instance APIs... - // interface Row extends DensityRow + // interface Row_Plugins extends Row_Density {} // if you need to add column instance APIs... - // interface Column extends DensityColumn + // interface Column_Plugins extends Column_Density {} // if you need to add header instance APIs... - // interface Header extends DensityHeader + // interface Header_Plugins extends Header_Density {} // Note: declaration merging on `ColumnDef` is not possible because it is a type, not an interface. // But you can still use declaration merging on `ColumnDef.meta` @@ -69,12 +78,14 @@ declare module '@tanstack/react-table' { // end of TS setup! // Here is all of the actual javascript code for our new feature -export const DensityFeature: TableFeature = { +export const densityPlugin: TableFeature = { // define the new feature's initial state - getInitialState: (state): DensityTableState => { + getInitialState: ( + initialState: Partial>, + ): Partial> => { return { density: 'md', - ...state, + ...initialState, // must come last } }, @@ -83,12 +94,12 @@ export const DensityFeature: TableFeature = { TFeatures extends TableFeatures, TData extends RowData, >( - table: Partial>, - ): DensityOptions => { + table: Table, + ): TableOptions_Density => { return { enableDensity: true, onDensityChange: makeStateUpdater('density', table), - } as DensityOptions + } as TableOptions_Density }, // if you need to add a default column definition... // getDefaultColumnDef: (): Partial> => { @@ -96,7 +107,7 @@ export const DensityFeature: TableFeature = { // }, // define the new feature's table instance methods - constructTable: ( + constructTableAPIs: ( table: Table, ): void => { table.setDensity = (updater) => { @@ -114,20 +125,27 @@ export const DensityFeature: TableFeature = { } }, - // if you need to add row instance APIs... - // constructRow: (row, table): void => {}, - // if you need to add cell instance APIs... - // constructCell: (cell, column, row, table): void => {}, - // if you need to add column instance APIs... - // constructColumn: (column, table): void => {}, - // if you need to add header instance APIs... - // constructHeader: (header, table): void => {}, + // // if you need to add row instance APIs... + // constructRowAPIs: (row: Row, table: Table): void => {}, + // // if you need to add cell instance APIs... + // constructCellAPIs: (cell: Cell): void => {}, + // // if you need to add column instance APIs... + // constructColumnAPIs: (column: Column): void => {}, + // // if you need to add header instance APIs... + // constructHeaderAPIs: (header: Header): void => {}, } // end of custom feature code // app code +const _features = tableFeatures({ + columnFilteringFeature, + rowSortingFeature, + rowPaginationFeature, + densityPlugin, // pass in our plugin just like any other stock feature +}) + function App() { - const columns = React.useMemo>>( + const columns = React.useMemo>>( () => [ { accessorKey: 'firstName', @@ -169,12 +187,16 @@ function App() { const [density, setDensity] = React.useState('md') const table = useTable({ - _features: { DensityFeature }, // pass our custom feature to the table to be instantiated upon creation + _features, _rowModels: { filteredRowModel: createFilteredRowModel(), paginatedRowModel: createPaginatedRowModel(), sortedRowModel: createSortedRowModel(), }, + _processingFns: { + filterFns, + sortFns, + }, columns, data, debugTable: true, @@ -245,7 +267,7 @@ function App() { {table.getRowModel().rows.map((row) => { return ( - {row.getVisibleCells().map((cell) => { + {row.getAllCells().map((cell) => { return ( - table: Table + column: Column + table: Table }) { const firstValue = table .getPreFilteredRowModel() @@ -356,8 +378,6 @@ function Filter({ const columnFilterValue = column.getFilterValue() - console.log('columnFilterValue', { columnFilterValue, table, column }) - return typeof firstValue === 'number' ? (
(): ( - table: Table_Internal, +export function createFacetedMinMaxValues< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, columnId: string, ) => () => undefined | [number, number] { return (table, columnId) => @@ -20,9 +24,12 @@ export function createFacetedMinMaxValues(): ( }) } -function _createFacetedMinMaxValues( +function _createFacetedMinMaxValues< + TFeatures extends TableFeatures, + TData extends RowData = any, +>( columnId: string, - facetedRowModel?: RowModel, + facetedRowModel?: RowModel, ): undefined | [number, number] { if (!facetedRowModel) return undefined diff --git a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts index 27ce6ffd85..f4bf6820ad 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts @@ -8,11 +8,15 @@ import type { import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Row } from '../../types/Row' +import type { RowData } from '../../types/type-utils' -export function createFacetedRowModel(): ( - table: Table_Internal, +export function createFacetedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, columnId: string, -) => () => RowModel { +) => () => RowModel { return (table, columnId) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -34,10 +38,13 @@ export function createFacetedRowModel(): ( }) } -function _createFacetedRowModel( - table: Table_Internal, +function _createFacetedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>( + table: Table_Internal, columnId: string, - preRowModel: RowModel, + preRowModel: RowModel, columnFilters?: ColumnFiltersState, globalFilter?: string, ) { @@ -51,7 +58,7 @@ function _createFacetedRowModel( ].filter(Boolean) as Array const filterRowsImpl = ( - row: Row & Partial>, + row: Row & Partial>, ) => { // Horizontally filter rows through each column for (const colId of filterableIds) { diff --git a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts index a2752ae233..4aa30b1f11 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts @@ -3,9 +3,13 @@ import { column_getFacetedRowModel } from './columnFacetingFeature.utils' import type { Table_Internal } from '../../types/Table' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { TableFeatures } from '../../types/TableFeatures' +import type { RowData } from '../../types/type-utils' -export function createFacetedUniqueValues(): ( - table: Table_Internal, +export function createFacetedUniqueValues< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, columnId: string, ) => () => Map { return (table, columnId) => @@ -20,9 +24,12 @@ export function createFacetedUniqueValues(): ( }) } -function _createFacetedUniqueValues( +function _createFacetedUniqueValues< + TFeatures extends TableFeatures, + TData extends RowData = any, +>( columnId: string, - facetedRowModel: RowModel | undefined, + facetedRowModel: RowModel | undefined, ): Map { if (!facetedRowModel) return new Map() diff --git a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts index 27e083a409..cf8b9145cd 100644 --- a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts +++ b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts @@ -7,6 +7,7 @@ import { import { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils' import { filterRows } from './filterRowsUtils' import { column_getFilterFn } from './columnFilteringFeature.utils' +import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Table_Internal } from '../../types/Table' @@ -16,9 +17,12 @@ import type { Row_ColumnFiltering, } from './columnFilteringFeature.types' -export function createFilteredRowModel(): ( - table: Table_Internal, -) => () => RowModel { +export function createFilteredRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, +) => () => RowModel { return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -33,15 +37,16 @@ export function createFilteredRowModel(): ( }) } -function _createFilteredRowModel( - table: Table_Internal, -): RowModel { +function _createFilteredRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(table: Table_Internal): RowModel { const rowModel = table.getPreFilteredRowModel() const { columnFilters, globalFilter } = table.options.state ?? {} if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) { for (const row of rowModel.flatRows as Array< - Row & Partial> + Row & Partial> >) { row.columnFilters = {} row.columnFiltersMeta = {} @@ -49,8 +54,10 @@ function _createFilteredRowModel( return rowModel } - const resolvedColumnFilters: Array> = [] - const resolvedGlobalFilters: Array> = [] + const resolvedColumnFilters: Array> = + [] + const resolvedGlobalFilters: Array> = + [] columnFilters?.forEach((columnFilter) => { const column = table_getColumn(table, columnFilter.id) @@ -92,7 +99,7 @@ function _createFilteredRowModel( // Flag the pre-filtered row model with each filter state for (const row of rowModel.flatRows as Array< - Row & Partial> + Row & Partial> >) { row.columnFilters = {} @@ -142,7 +149,7 @@ function _createFilteredRowModel( } const filterRowsImpl = ( - row: Row & Row_ColumnFiltering, + row: Row & Row_ColumnFiltering, ) => { // Horizontally filter rows through each column for (const columnId of filterableIds) { diff --git a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts index af7dbce58a..5dc2f65e97 100644 --- a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts +++ b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts @@ -13,10 +13,14 @@ import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' - -export function createGroupedRowModel(): ( - table: Table_Internal, -) => () => RowModel { +import type { RowData } from '../../types/type-utils' + +export function createGroupedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, +) => () => RowModel { return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -33,9 +37,10 @@ export function createGroupedRowModel(): ( }) } -function _createGroupedRowModel( - table: Table_Internal, -): RowModel { +function _createGroupedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(table: Table_Internal): RowModel { const rowModel = table.getPreGroupedRowModel() const grouping = table.options.state?.grouping @@ -52,13 +57,13 @@ function _createGroupedRowModel( table_getColumn(table, columnId), ) - const groupedFlatRows: Array> & + const groupedFlatRows: Array> & Partial = [] - const groupedRowsById: Record> = {} + const groupedRowsById: Record> = {} // Recursively group the data const groupUpRecursively = ( - rows: Array>, + rows: Array>, depth = 0, parentId?: string, ) => { @@ -110,7 +115,7 @@ function _createGroupedRowModel( depth, undefined, parentId, - ) as Row & Partial + ) as Row & Partial Object.assign(row, { groupingColumnId: columnId, @@ -139,7 +144,7 @@ function _createGroupedRowModel( // Aggregate the values const column = table.getColumn(colId) const aggregateFn = column_getAggregationFn( - column as Column, + column as Column, ) if (!row._groupingValuesCache) row._groupingValuesCache = {} @@ -182,11 +187,11 @@ function _createGroupedRowModel( } } -function groupBy( - rows: Array>, +function groupBy( + rows: Array>, columnId: string, ) { - const groupMap = new Map>>() + const groupMap = new Map>>() return rows.reduce((map, row) => { const resKey = `${row_getGroupingValue(row, columnId)}` diff --git a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts index dc3d637359..1a1d742d34 100644 --- a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts +++ b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts @@ -4,10 +4,14 @@ import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' +import type { RowData } from '../../types/type-utils' -export function createExpandedRowModel(): ( - table: Table_Internal, -) => () => RowModel { +export function createExpandedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, +) => () => RowModel { return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -21,9 +25,10 @@ export function createExpandedRowModel(): ( }) } -export function _createExpandedRowModel( - table: Table_Internal, -): RowModel { +function _createExpandedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(table: Table_Internal): RowModel { const rowModel = table.getPreExpandedRowModel() const expanded = table.options.state?.expanded @@ -42,12 +47,13 @@ export function _createExpandedRowModel( return expandRows(rowModel) } -export function expandRows( - rowModel: RowModel, -) { - const expandedRows: Array> = [] +export function expandRows< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(rowModel: RowModel): RowModel { + const expandedRows: Array> = [] - const handleRow = (row: Row) => { + const handleRow = (row: Row) => { expandedRows.push(row) if (row.subRows.length && row_getIsExpanded(row)) { diff --git a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts index 7ce6be86f4..1a2c735412 100644 --- a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts +++ b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts @@ -5,10 +5,14 @@ import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' +import type { RowData } from '../../types/type-utils' -export function createPaginatedRowModel(): ( - table: Table_Internal, -) => () => RowModel { +export function createPaginatedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, +) => () => RowModel { return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -24,9 +28,10 @@ export function createPaginatedRowModel(): ( }) } -function _createPaginatedRowModel( - table: Table_Internal, -): RowModel { +function _createPaginatedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(table: Table_Internal): RowModel { const prePaginatedRowModel = table.getPrePaginatedRowModel() const pagination = table.options.state?.pagination @@ -41,7 +46,7 @@ function _createPaginatedRowModel( const paginatedRows = rows.slice(pageStart, pageEnd) - let paginatedRowModel: RowModel + let paginatedRowModel: RowModel if (!table.options.paginateExpandedRows) { paginatedRowModel = expandRows({ @@ -59,7 +64,7 @@ function _createPaginatedRowModel( paginatedRowModel.flatRows = [] - const handleRow = (row: Row) => { + const handleRow = (row: Row) => { paginatedRowModel.flatRows.push(row) if (row.subRows.length) { row.subRows.forEach(handleRow) diff --git a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts index 15ea2f81eb..25bebb5db9 100644 --- a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts +++ b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts @@ -10,10 +10,14 @@ import type { RowModel } from '../../core/row-models/rowModelsFeature.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { SortingFn } from './rowSortingFeature.types' - -export function createSortedRowModel(): ( - table: Table_Internal, -) => () => RowModel { +import type { RowData } from '../../types/type-utils' + +export function createSortedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(): ( + table: Table_Internal, +) => () => RowModel { return (table) => tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), @@ -27,9 +31,10 @@ export function createSortedRowModel(): ( }) } -function _createSortedRowModel( - table: Table_Internal, -): RowModel { +function _createSortedRowModel< + TFeatures extends TableFeatures, + TData extends RowData = any, +>(table: Table_Internal): RowModel { const preSortedRowModel = table.getPreSortedRowModel() const sorting = table.options.state?.sorting @@ -37,7 +42,7 @@ function _createSortedRowModel( return preSortedRowModel } - const sortedFlatRows: Array> = [] + const sortedFlatRows: Array> = [] // Filter out sortings that correspond to non existing columns const availableSorting = sorting.filter((sort) => @@ -49,13 +54,13 @@ function _createSortedRowModel( { sortUndefined?: false | -1 | 1 | 'first' | 'last' invertSorting?: boolean - sortingFn: SortingFn + sortingFn: SortingFn } > = {} availableSorting.forEach((sortEntry) => { const column = table.getColumn(sortEntry.id) as - | Column_Internal + | Column_Internal | undefined if (!column) return @@ -66,7 +71,7 @@ function _createSortedRowModel( } }) - const sortData = (rows: Array>) => { + const sortData = (rows: Array>) => { // This will also perform a stable sorting using the row index // if needed. const sortedData = rows.map((row) => ({ ...row })) diff --git a/packages/table-core/src/types/Cell.ts b/packages/table-core/src/types/Cell.ts index 6aa60e220b..fd35c18a98 100644 --- a/packages/table-core/src/types/Cell.ts +++ b/packages/table-core/src/types/Cell.ts @@ -3,6 +3,15 @@ import type { TableFeatures } from './TableFeatures' import type { Cell_Cell } from '../core/cells/cellsFeature.types' import type { Cell_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types' +export interface Cell_Plugins {} + +export interface Cell_Core< + TFeatures extends TableFeatures, + TData extends RowData, + TValue extends CellData = CellData, +> extends Cell_Cell, + Cell_Plugins {} + export type Cell< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/Column.ts b/packages/table-core/src/types/Column.ts index f2a063a1a3..0edd472f24 100644 --- a/packages/table-core/src/types/Column.ts +++ b/packages/table-core/src/types/Column.ts @@ -13,11 +13,20 @@ import type { Column_ColumnVisibility } from '../features/column-visibility/colu import type { Column_GlobalFiltering } from '../features/global-filtering/globalFilteringFeature.types' import type { Column_RowSorting } from '../features/row-sorting/rowSortingFeature.types' +export interface Column_Plugins {} + +export interface Column_Core< + TFeatures extends TableFeatures, + TData extends RowData, + TValue = unknown, +> extends Column_Column, + Column_Plugins {} + export type Column< TFeatures extends TableFeatures, TData extends RowData, TValue = unknown, -> = Column_Column & +> = Column_Core & UnionToIntersection< | ('columnFacetingFeature' extends keyof TFeatures ? Column_ColumnFaceting diff --git a/packages/table-core/src/types/ColumnDef.ts b/packages/table-core/src/types/ColumnDef.ts index 103da441b2..47c773f545 100644 --- a/packages/table-core/src/types/ColumnDef.ts +++ b/packages/table-core/src/types/ColumnDef.ts @@ -11,6 +11,8 @@ import type { ColumnDef_ColumnVisibility } from '../features/column-visibility/c import type { ColumnDef_GlobalFiltering } from '../features/global-filtering/globalFilteringFeature.types' import type { ColumnDef_RowSorting } from '../features/row-sorting/rowSortingFeature.types' +export interface ColumnDef_Plugins {} + export interface ColumnMeta< TFeatures extends TableFeatures, TData extends RowData, @@ -55,7 +57,7 @@ interface ColumnDefBase_Core< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, -> { +> extends ColumnDef_Plugins { getUniqueValues?: AccessorFn> footer?: ColumnDefTemplate> cell?: ColumnDefTemplate> diff --git a/packages/table-core/src/types/Header.ts b/packages/table-core/src/types/Header.ts index 78f99215be..b23bec88f9 100644 --- a/packages/table-core/src/types/Header.ts +++ b/packages/table-core/src/types/Header.ts @@ -4,11 +4,20 @@ import type { Header_Header } from '../core/headers/headersFeature.types' import type { Header_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types' import type { Header_ColumnSizing } from '../features/column-sizing/columnSizingFeature.types' +export interface Header_Plugins {} + +export interface Header_Core< + TFeatures extends TableFeatures, + TData extends RowData, + TValue extends CellData = CellData, +> extends Header_Header, + Header_Plugins {} + export type Header< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, -> = Header_Header & +> = Header_Core & UnionToIntersection< | ('columnSizingFeature' extends keyof TFeatures ? Header_ColumnSizing diff --git a/packages/table-core/src/types/HeaderGroup.ts b/packages/table-core/src/types/HeaderGroup.ts index ff98b3a1a6..199b4645b8 100644 --- a/packages/table-core/src/types/HeaderGroup.ts +++ b/packages/table-core/src/types/HeaderGroup.ts @@ -2,10 +2,13 @@ import type { HeaderGroup_Header } from '../core/headers/headersFeature.types' import type { TableFeatures } from './TableFeatures' import type { RowData } from './type-utils' +export interface HeaderGroup_Plugins {} + export interface HeaderGroup_Core< TFeatures extends TableFeatures, TData extends RowData, -> extends HeaderGroup_Header {} +> extends HeaderGroup_Header, + HeaderGroup_Plugins {} export interface HeaderGroup< TFeatures extends TableFeatures, diff --git a/packages/table-core/src/types/ProcessingFns.ts b/packages/table-core/src/types/ProcessingFns.ts index d911208b22..c4e3885c83 100644 --- a/packages/table-core/src/types/ProcessingFns.ts +++ b/packages/table-core/src/types/ProcessingFns.ts @@ -4,27 +4,25 @@ import type { RowData, UnionToIntersection } from './type-utils' import type { TableFns_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types' import type { TableFeatures } from './TableFeatures' +export interface ProcessingFns_Plugins {} + export type ProcessingFns< TFeatures extends TableFeatures, TData extends RowData, -> = { - /** - * @deprecated - */ - _?: never -} & Partial< - UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? TableFns_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? TableFns_ColumnGrouping - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? TableFns_RowSorting - : never) +> = ProcessingFns_Plugins & + Partial< + UnionToIntersection< + | ('columnFilteringFeature' extends keyof TFeatures + ? TableFns_ColumnFiltering + : never) + | ('columnGroupingFeature' extends keyof TFeatures + ? TableFns_ColumnGrouping + : never) + | ('rowSortingFeature' extends keyof TFeatures + ? TableFns_RowSorting + : never) + > > -> export type ProcessingFns_All< TFeatures extends TableFeatures, diff --git a/packages/table-core/src/types/Row.ts b/packages/table-core/src/types/Row.ts index 8490a6cc07..2a7a09e9ae 100644 --- a/packages/table-core/src/types/Row.ts +++ b/packages/table-core/src/types/Row.ts @@ -9,10 +9,19 @@ import type { Row_RowExpanding } from '../features/row-expanding/rowExpandingFea import type { Row_RowPinning } from '../features/row-pinning/rowPinningFeature.types' import type { Row_RowSelection } from '../features/row-selection/rowSelectionFeature.types' +export interface Row_Plugins {} + +export interface Row_Core< + TFeatures extends TableFeatures, + TData extends RowData, +> extends Row_Row, + Row_Plugins {} + export type Row< TFeatures extends TableFeatures, TData extends RowData, -> = Row_Row & +> = Row_Core & + Row_Plugins & UnionToIntersection< | ('columnFilteringFeature' extends keyof TFeatures ? Row_ColumnFiltering diff --git a/packages/table-core/src/types/RowModel.ts b/packages/table-core/src/types/RowModel.ts index 35f11c0b33..d6ffcaeae3 100644 --- a/packages/table-core/src/types/RowModel.ts +++ b/packages/table-core/src/types/RowModel.ts @@ -30,10 +30,14 @@ import type { import type { RowData, UnionToIntersection } from './type-utils' import type { TableFeatures } from './TableFeatures' +export interface CreateRowModel_Plugins {} +export interface CachedRowModel_Plugins {} + export type CreateRowModels< TFeatures extends TableFeatures, TData extends RowData, > = CreateRowModel_Core & + CreateRowModel_Plugins & UnionToIntersection< | ('columnFacetingFeature' extends keyof TFeatures ? CreateRowModel_Faceted @@ -64,7 +68,8 @@ export type CreateRowModels_All< CreateRowModel_Filtered & CreateRowModel_Grouped & CreateRowModel_Paginated & - CreateRowModel_Sorted + CreateRowModel_Sorted & + CreateRowModel_Plugins export type CachedRowModels< TFeatures extends TableFeatures, @@ -90,7 +95,8 @@ export type CachedRowModels< | ('rowSortingFeature' extends keyof TFeatures ? CachedRowModel_Sorted : never) -> +> & + CachedRowModel_Plugins export type CachedRowModel_All< TFeatures extends TableFeatures, @@ -102,5 +108,6 @@ export type CachedRowModel_All< CachedRowModel_Filtered & CachedRowModel_Grouped & CachedRowModel_Paginated & - CachedRowModel_Sorted + CachedRowModel_Sorted & + CachedRowModel_Plugins > diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index 41c5210cc3..68d4548022 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -24,6 +24,8 @@ import type { Table_RowSelection } from '../features/row-selection/rowSelectionF import type { Table_RowSorting } from '../features/row-sorting/rowSortingFeature.types' import type { TableOptions_All } from './TableOptions' +export interface Table_Plugins {} + /** * The core table object that only includes the core table functionality such as column, header, row, and table APIS. * No features are included. @@ -35,7 +37,8 @@ export type Table_Core< Table_Columns & Table_Rows & Table_RowModels & - Table_Headers + Table_Headers & + Table_Plugins /** * The table object that includes both the core table functionality and the features that are enabled via the `_features` table option. diff --git a/packages/table-core/src/types/TableFeatures.ts b/packages/table-core/src/types/TableFeatures.ts index c8daff2cc2..dd5eb9c858 100644 --- a/packages/table-core/src/types/TableFeatures.ts +++ b/packages/table-core/src/types/TableFeatures.ts @@ -34,7 +34,12 @@ export interface StockTableFeatures { rowSortingFeature?: TableFeature } -export interface TableFeatures extends CoreTableFeatures, StockTableFeatures {} +export interface Plugins {} + +export interface TableFeatures + extends CoreTableFeatures, + StockTableFeatures, + Plugins {} export interface TableFeature { constructCellAPIs?: < diff --git a/packages/table-core/src/types/TableOptions.ts b/packages/table-core/src/types/TableOptions.ts index 9cef2320cc..6b952eb779 100644 --- a/packages/table-core/src/types/TableOptions.ts +++ b/packages/table-core/src/types/TableOptions.ts @@ -19,6 +19,8 @@ import type { TableOptions_RowSorting } from '../features/row-sorting/rowSorting import type { RowData, UnionToIntersection } from './type-utils' import type { TableFeatures } from './TableFeatures' +export interface TableOptions_Plugins {} + export interface TableOptions_Core< TFeatures extends TableFeatures, TData extends RowData, @@ -26,7 +28,8 @@ export interface TableOptions_Core< TableOptions_Cell, TableOptions_Columns, TableOptions_Rows, - TableOptions_Headers {} + TableOptions_Headers, + TableOptions_Plugins {} export type TableOptions< TFeatures extends TableFeatures, diff --git a/packages/table-core/src/types/TableState.ts b/packages/table-core/src/types/TableState.ts index 91aff81b7d..bcf9c5b6be 100644 --- a/packages/table-core/src/types/TableState.ts +++ b/packages/table-core/src/types/TableState.ts @@ -14,52 +14,50 @@ import type { TableState_RowSelection } from '../features/row-selection/rowSelec import type { TableState_RowSorting } from '../features/row-sorting/rowSortingFeature.types' import type { TableFeatures } from './TableFeatures' -export type TableState = { - /** - * @deprecated - */ - _?: never -} & UnionToIntersection< - | ('columnFilteringFeature' extends keyof TFeatures - ? TableState_ColumnFiltering - : never) - | ('columnGroupingFeature' extends keyof TFeatures - ? TableState_ColumnGrouping - : never) - | ('columnOrderingFeature' extends keyof TFeatures - ? TableState_ColumnOrdering - : never) - | ('columnPinningFeature' extends keyof TFeatures - ? TableState_ColumnPinning - : never) - | ('columnResizingFeature' extends keyof TFeatures - ? TableState_ColumnResizing - : never) - | ('columnSizingFeature' extends keyof TFeatures - ? TableState_ColumnSizing - : never) - | ('columnVisibilityFeature' extends keyof TFeatures - ? TableState_ColumnVisibility - : never) - | ('globalFilteringFeature' extends keyof TFeatures - ? TableState_GlobalFiltering - : never) - | ('rowExpandingFeature' extends keyof TFeatures - ? TableState_RowExpanding - : never) - | ('rowPaginationFeature' extends keyof TFeatures - ? TableState_RowPagination - : never) - | ('rowPinningFeature' extends keyof TFeatures - ? TableState_RowPinning - : never) - | ('rowSelectionFeature' extends keyof TFeatures - ? TableState_RowSelection - : never) - | ('rowSortingFeature' extends keyof TFeatures - ? TableState_RowSorting - : never) -> +export interface TableState_Plugins {} + +export type TableState = TableState_Plugins & + UnionToIntersection< + | ('columnFilteringFeature' extends keyof TFeatures + ? TableState_ColumnFiltering + : never) + | ('columnGroupingFeature' extends keyof TFeatures + ? TableState_ColumnGrouping + : never) + | ('columnOrderingFeature' extends keyof TFeatures + ? TableState_ColumnOrdering + : never) + | ('columnPinningFeature' extends keyof TFeatures + ? TableState_ColumnPinning + : never) + | ('columnResizingFeature' extends keyof TFeatures + ? TableState_ColumnResizing + : never) + | ('columnSizingFeature' extends keyof TFeatures + ? TableState_ColumnSizing + : never) + | ('columnVisibilityFeature' extends keyof TFeatures + ? TableState_ColumnVisibility + : never) + | ('globalFilteringFeature' extends keyof TFeatures + ? TableState_GlobalFiltering + : never) + | ('rowExpandingFeature' extends keyof TFeatures + ? TableState_RowExpanding + : never) + | ('rowPaginationFeature' extends keyof TFeatures + ? TableState_RowPagination + : never) + | ('rowPinningFeature' extends keyof TFeatures + ? TableState_RowPinning + : never) + | ('rowSelectionFeature' extends keyof TFeatures + ? TableState_RowSelection + : never) + | ('rowSortingFeature' extends keyof TFeatures + ? TableState_RowSorting + : never) + > export type TableState_All = Partial< TableState_ColumnFiltering &