diff --git a/packages/table-core/src/core/cells/constructCell.ts b/packages/table-core/src/core/cells/constructCell.ts index 2d23506026..da59c24536 100644 --- a/packages/table-core/src/core/cells/constructCell.ts +++ b/packages/table-core/src/core/cells/constructCell.ts @@ -1,4 +1,4 @@ -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Row } from '../../types/Row' @@ -13,7 +13,7 @@ import type { Cell_CoreProperties } from './coreCellsFeature.types' function getCellPrototype< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): object { +>(table: Table): object { if (!table._cellPrototype) { table._cellPrototype = { table } const features = Object.values(table._features) @@ -36,7 +36,7 @@ export function constructCell< >( column: Column, row: Row, - table: Table_Internal, + table: Table, ): Cell { // Create cell with shared prototype for memory efficiency const cellPrototype = getCellPrototype(table) diff --git a/packages/table-core/src/core/cells/coreCellsFeature.types.ts b/packages/table-core/src/core/cells/coreCellsFeature.types.ts index a2a1832620..a48c8aab26 100644 --- a/packages/table-core/src/core/cells/coreCellsFeature.types.ts +++ b/packages/table-core/src/core/cells/coreCellsFeature.types.ts @@ -1,6 +1,6 @@ import type { CellData, Getter, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' import type { Column } from '../../types/Column' @@ -38,7 +38,7 @@ export interface Cell_CoreProperties< /** * Reference to the parent table instance. */ - table: Table_Internal + table: Table } export interface Cell_Cell< diff --git a/packages/table-core/src/core/columns/constructColumn.ts b/packages/table-core/src/core/columns/constructColumn.ts index b6ca11debf..fe9f16e7f1 100644 --- a/packages/table-core/src/core/columns/constructColumn.ts +++ b/packages/table-core/src/core/columns/constructColumn.ts @@ -1,5 +1,5 @@ import {} from '../../utils' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { @@ -17,7 +17,7 @@ import type { Column_CoreProperties } from './coreColumnsFeature.types' function getColumnPrototype< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): object { +>(table: Table): object { if (!table._columnPrototype) { table._columnPrototype = { table } const features = Object.values(table._features) @@ -38,7 +38,7 @@ export function constructColumn< TData extends RowData, TValue extends CellData = CellData, >( - table: Table_Internal, + table: Table, columnDef: ColumnDef, depth: number, parent?: Column, diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.ts b/packages/table-core/src/core/columns/coreColumnsFeature.ts index f21a2b3bfc..71f050842a 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.ts @@ -12,10 +12,16 @@ import { } from './coreColumnsFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +type CoreColumnsFeature = Partial<{ + coreColumnsFeature: TableFeature + columnOrderingFeature: TableFeature + columnGroupingFeature: TableFeature +}> + /** * Core feature that builds the column tree and exposes table/column column APIs. */ -export const coreColumnsFeature: TableFeature = { +export const coreColumnsFeature: TableFeature = { assignColumnPrototype: (prototype, table) => { assignPrototypeAPIs('coreColumnsFeature', prototype, table, { column_getFlatColumns: { diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.types.ts b/packages/table-core/src/core/columns/coreColumnsFeature.types.ts index 2cd8780410..bcc6e9ee60 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.types.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.types.ts @@ -1,4 +1,4 @@ -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { AccessorFn, ColumnDef } from '../../types/ColumnDef' @@ -39,7 +39,7 @@ export interface Column_CoreProperties< /** * Reference to the parent table instance. */ - table: Table_Internal + table: Table } export interface Column_Column< diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts b/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts index 5901595f1c..48423337c9 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts @@ -1,7 +1,7 @@ import { callMemoOrStaticFn } from '../../utils' import { table_getOrderColumnsFn } from '../../features/column-ordering/columnOrderingFeature.utils' import { constructColumn } from './constructColumn' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { @@ -81,7 +81,7 @@ export function table_getDefaultColumnDef< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, ): Partial> { return { header: (props) => { @@ -120,9 +120,7 @@ export function table_getDefaultColumnDef< export function table_getAllColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, -): Array> { +>(table: Table): Array> { const recurseColumns = ( colDefs: ReadonlyArray>, parent?: Column, @@ -162,9 +160,7 @@ export function table_getAllColumns< export function table_getAllFlatColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, -): Array> { +>(table: Table): Array> { return table.getAllColumns().flatMap((column) => column.getFlatColumns()) } @@ -183,7 +179,7 @@ export function table_getAllFlatColumnsById< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, ): Record> { const result: Record> = {} const flatColumns = table.getAllFlatColumns() @@ -208,9 +204,7 @@ export function table_getAllFlatColumnsById< export function table_getAllLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, -): Array> { +>(table: Table): Array> { const leafColumns = table.getAllColumns().flatMap( (c) => c.getLeafColumns(), // recursive ) @@ -236,7 +230,7 @@ export function table_getAllLeafColumnsById< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, ): Record> { const result: Record> = {} const leafColumns = table.getAllLeafColumns() @@ -262,7 +256,7 @@ export function table_getColumn< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, columnId: string, ): Column | undefined { const column = table.getAllFlatColumnsById()[columnId] diff --git a/packages/table-core/src/core/headers/buildHeaderGroups.ts b/packages/table-core/src/core/headers/buildHeaderGroups.ts index f0c913a117..2bcca52fa8 100644 --- a/packages/table-core/src/core/headers/buildHeaderGroups.ts +++ b/packages/table-core/src/core/headers/buildHeaderGroups.ts @@ -1,7 +1,7 @@ import { callMemoOrStaticFn } from '../../utils' import { column_getIsVisible } from '../../features/column-visibility/columnVisibilityFeature.utils' import { constructHeader } from './constructHeader' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Header } from '../../types/Header' @@ -20,7 +20,7 @@ export function buildHeaderGroups< >( allColumns: Array>, columnsToGroup: Array>, - table: Table_Internal, + table: Table, headerFamily?: 'center' | 'left' | 'right', ) { // Find the max depth of the columns: @@ -113,9 +113,7 @@ export function buildHeaderGroups< pendingParentHeaders.push(header) } - headerGroup.headers.push( - headerToGroup as Header, - ) + headerGroup.headers.push(headerToGroup) headerToGroup.headerGroup = headerGroup }) @@ -138,7 +136,7 @@ export function buildHeaderGroups< headerGroups.reverse() const recurseHeadersForSpans = ( - headers: Array>, + headers: Array>, ): Array<{ colSpan: number; rowSpan: number }> => { const results: Array<{ colSpan: number; rowSpan: number }> = [] @@ -176,9 +174,7 @@ export function buildHeaderGroups< return results } - recurseHeadersForSpans( - (headerGroups[0]?.headers ?? []) as Array>, - ) + recurseHeadersForSpans(headerGroups[0]?.headers ?? []) return headerGroups } diff --git a/packages/table-core/src/core/headers/constructHeader.ts b/packages/table-core/src/core/headers/constructHeader.ts index 7e52343dfd..bd02c53d16 100644 --- a/packages/table-core/src/core/headers/constructHeader.ts +++ b/packages/table-core/src/core/headers/constructHeader.ts @@ -1,4 +1,4 @@ -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Header } from '../../types/Header' @@ -12,7 +12,7 @@ import type { Header_CoreProperties } from './coreHeadersFeature.types' function getHeaderPrototype< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): object { +>(table: Table): object { if (!table._headerPrototype) { table._headerPrototype = { table } const features = Object.values(table._features) @@ -33,7 +33,7 @@ export function constructHeader< TData extends RowData, TValue extends CellData = CellData, >( - table: Table_Internal, + table: Table, column: Column, options: { id?: string diff --git a/packages/table-core/src/core/headers/coreHeadersFeature.ts b/packages/table-core/src/core/headers/coreHeadersFeature.ts index b8c7a214e4..d85c91eb42 100644 --- a/packages/table-core/src/core/headers/coreHeadersFeature.ts +++ b/packages/table-core/src/core/headers/coreHeadersFeature.ts @@ -8,11 +8,19 @@ import { table_getLeafHeaders, } from './coreHeadersFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +import type { CoreFeatures } from '../coreFeatures' + +type CoreHeadersFeature = CoreFeatures & { + columnGroupingFeature: TableFeature + columnOrderingFeature: TableFeature + columnPinningFeature: TableFeature + columnVisibilityFeature: TableFeature +} /** * Core feature that builds header groups and exposes header context APIs. */ -export const coreHeadersFeature: TableFeature = { +export const coreHeadersFeature: TableFeature = { assignHeaderPrototype: (prototype, table) => { assignPrototypeAPIs('coreHeadersFeature', prototype, table, { header_getLeafHeaders: { diff --git a/packages/table-core/src/core/headers/coreHeadersFeature.utils.ts b/packages/table-core/src/core/headers/coreHeadersFeature.utils.ts index a6152c03ef..b40e280b0e 100644 --- a/packages/table-core/src/core/headers/coreHeadersFeature.utils.ts +++ b/packages/table-core/src/core/headers/coreHeadersFeature.utils.ts @@ -5,12 +5,15 @@ import { } from '../../features/column-visibility/columnVisibilityFeature.utils' import { callMemoOrStaticFn } from '../../utils' import { buildHeaderGroups } from './buildHeaderGroups' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Header } from '../../types/Header' import type { RowData } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Header_Header } from './coreHeadersFeature.types' -import type { Column } from '../../types/Column' + +type HeaderFeatures = Partial<{ + columnPinningFeature: TableFeature +}> /** * Walks a header tree and collects all descendant leaf headers. @@ -78,9 +81,10 @@ export function header_getContext< export function table_getHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const { left, right } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const allColumns = table.getAllColumns() const leafColumns = callMemoOrStaticFn( table, @@ -142,7 +146,7 @@ export function table_getHeaderGroups< export function table_getFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const headerGroups = table.getHeaderGroups() return [...headerGroups].reverse() } @@ -161,7 +165,7 @@ export function table_getFooterGroups< export function table_getFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const headerGroups = table.getHeaderGroups() const result: Array> = [] for (let i = 0; i < headerGroups.length; i++) { @@ -187,7 +191,7 @@ export function table_getFlatHeaders< export function table_getLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const topHeaders = table.getHeaderGroups()[0]?.headers ?? [] const result: Array> = [] for (let i = 0; i < topHeaders.length; i++) { diff --git a/packages/table-core/src/core/row-models/coreRowModelsFeature.ts b/packages/table-core/src/core/row-models/coreRowModelsFeature.ts index 8b1b32b729..790d91b307 100644 --- a/packages/table-core/src/core/row-models/coreRowModelsFeature.ts +++ b/packages/table-core/src/core/row-models/coreRowModelsFeature.ts @@ -14,11 +14,12 @@ import { table_getSortedRowModel, } from './coreRowModelsFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +import type { CoreFeatures } from '../coreFeatures' /** * Core feature that wires table row-model accessors and row-model caches. */ -export const coreRowModelsFeature: TableFeature = { +export const coreRowModelsFeature: TableFeature = { constructTableAPIs: (table) => { assignTableAPIs('coreRowModelsFeature', table, { table_getCoreRowModel: { diff --git a/packages/table-core/src/core/row-models/coreRowModelsFeature.utils.ts b/packages/table-core/src/core/row-models/coreRowModelsFeature.utils.ts index f132dfb376..e38a18b067 100644 --- a/packages/table-core/src/core/row-models/coreRowModelsFeature.utils.ts +++ b/packages/table-core/src/core/row-models/coreRowModelsFeature.utils.ts @@ -1,9 +1,18 @@ import { createCoreRowModel } from './createCoreRowModel' -import type { Table_Internal } from '../../types/Table' -import type { TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowData } from '../../types/type-utils' import type { RowModel } from './coreRowModelsFeature.types' +type RowModelFeatures = Partial<{ + coreRowModelsFeature: TableFeature + columnFilteringFeature: TableFeature + columnGroupingFeature: TableFeature + rowSortingFeature: TableFeature + rowExpandingFeature: TableFeature + rowPaginationFeature: TableFeature +}> + /** * Resolves the table's unmodified core row model. * @@ -18,14 +27,20 @@ import type { RowModel } from './coreRowModelsFeature.types' export function table_getCoreRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.coreRowModel) { - table._rowModels.coreRowModel = +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if (!featureTable._rowModels.coreRowModel) { + featureTable._rowModels.coreRowModel = table.options.features.coreRowModel?.(table) ?? - createCoreRowModel()(table) + (createCoreRowModel()( + table, + ) as unknown as () => RowModel) } - return table._rowModels.coreRowModel() + return featureTable._rowModels.coreRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -42,7 +57,7 @@ export function table_getCoreRowModel< export function table_getPreFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getCoreRowModel() } @@ -59,19 +74,29 @@ export function table_getPreFilteredRowModel< * ``` */ export function table_getFilteredRowModel< - TFeatures extends TableFeatures, - TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.filteredRowModel) { - table._rowModels.filteredRowModel = - table.options.features.filteredRowModel?.(table) + TFeatures extends TableFeatures = any, + TData extends RowData = any, +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if ( + !featureTable._rowModels.filteredRowModel && + table.options.features.filteredRowModel + ) { + featureTable._rowModels.filteredRowModel = + table.options.features.filteredRowModel(table) } - if (table.options.manualFiltering || !table._rowModels.filteredRowModel) { + if ( + featureTable.options.manualFiltering || + !featureTable._rowModels.filteredRowModel + ) { return table.getPreFilteredRowModel() } - return table._rowModels.filteredRowModel() + return featureTable._rowModels.filteredRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -87,7 +112,7 @@ export function table_getFilteredRowModel< export function table_getPreGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getFilteredRowModel() } @@ -105,17 +130,27 @@ export function table_getPreGroupedRowModel< export function table_getGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.groupedRowModel) { - table._rowModels.groupedRowModel = - table.options.features.groupedRowModel?.(table) +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if ( + !featureTable._rowModels.groupedRowModel && + table.options.features.groupedRowModel + ) { + featureTable._rowModels.groupedRowModel = + table.options.features.groupedRowModel(table) } - if (table.options.manualGrouping || !table._rowModels.groupedRowModel) { + if ( + featureTable.options.manualGrouping || + !featureTable._rowModels.groupedRowModel + ) { return table.getPreGroupedRowModel() } - return table._rowModels.groupedRowModel() + return featureTable._rowModels.groupedRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -131,7 +166,7 @@ export function table_getGroupedRowModel< export function table_getPreSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getGroupedRowModel() } @@ -150,17 +185,27 @@ export function table_getPreSortedRowModel< export function table_getSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.sortedRowModel) { - table._rowModels.sortedRowModel = - table.options.features.sortedRowModel?.(table) +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if ( + !featureTable._rowModels.sortedRowModel && + table.options.features.sortedRowModel + ) { + featureTable._rowModels.sortedRowModel = + table.options.features.sortedRowModel(table) } - if (table.options.manualSorting || !table._rowModels.sortedRowModel) { + if ( + featureTable.options.manualSorting || + !featureTable._rowModels.sortedRowModel + ) { return table.getPreSortedRowModel() } - return table._rowModels.sortedRowModel() + return featureTable._rowModels.sortedRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -176,7 +221,7 @@ export function table_getSortedRowModel< export function table_getPreExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getSortedRowModel() } @@ -194,17 +239,27 @@ export function table_getPreExpandedRowModel< export function table_getExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.expandedRowModel) { - table._rowModels.expandedRowModel = - table.options.features.expandedRowModel?.(table) +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if ( + !featureTable._rowModels.expandedRowModel && + table.options.features.expandedRowModel + ) { + featureTable._rowModels.expandedRowModel = + table.options.features.expandedRowModel(table) } - if (table.options.manualExpanding || !table._rowModels.expandedRowModel) { + if ( + featureTable.options.manualExpanding || + !featureTable._rowModels.expandedRowModel + ) { return table.getPreExpandedRowModel() } - return table._rowModels.expandedRowModel() + return featureTable._rowModels.expandedRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -221,7 +276,7 @@ export function table_getExpandedRowModel< export function table_getPrePaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getExpandedRowModel() } @@ -240,17 +295,27 @@ export function table_getPrePaginatedRowModel< export function table_getPaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { - if (!table._rowModels.paginatedRowModel) { - table._rowModels.paginatedRowModel = - table.options.features.paginatedRowModel?.(table) +>(table: Table): RowModel { + const featureTable = table as unknown as Table + if ( + !featureTable._rowModels.paginatedRowModel && + table.options.features.paginatedRowModel + ) { + featureTable._rowModels.paginatedRowModel = + table.options.features.paginatedRowModel(table) } - if (table.options.manualPagination || !table._rowModels.paginatedRowModel) { + if ( + featureTable.options.manualPagination || + !featureTable._rowModels.paginatedRowModel + ) { return table.getPrePaginatedRowModel() } - return table._rowModels.paginatedRowModel() + return featureTable._rowModels.paginatedRowModel() as unknown as RowModel< + TFeatures, + TData + > } /** @@ -267,6 +332,6 @@ export function table_getPaginatedRowModel< export function table_getRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getPaginatedRowModel() } diff --git a/packages/table-core/src/core/row-models/createCoreRowModel.ts b/packages/table-core/src/core/row-models/createCoreRowModel.ts index 417893961a..8d174ac853 100644 --- a/packages/table-core/src/core/row-models/createCoreRowModel.ts +++ b/packages/table-core/src/core/row-models/createCoreRowModel.ts @@ -1,7 +1,7 @@ import { constructRow } from '../rows/constructRow' import { tableMemo } from '../../utils' import { table_autoResetPageIndex } from '../../features/row-pagination/rowPaginationFeature.utils' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { RowModel } from './coreRowModelsFeature.types' import type { TableFeatures } from '../../types/TableFeatures' import type { Row } from '../../types/Row' @@ -15,9 +15,7 @@ import type { RowData } from '../../types/type-utils' export function createCoreRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(): ( - table: Table_Internal, -) => () => RowModel { +>(): (table: Table) => () => RowModel { return (table) => { return tableMemo({ feature: 'coreRowModelsFeature', @@ -34,7 +32,7 @@ function _createCoreRowModel< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, data: ReadonlyArray, ): { rows: Array> diff --git a/packages/table-core/src/core/rows/constructRow.ts b/packages/table-core/src/core/rows/constructRow.ts index 5c9e707e18..aac9928278 100644 --- a/packages/table-core/src/core/rows/constructRow.ts +++ b/packages/table-core/src/core/rows/constructRow.ts @@ -1,4 +1,4 @@ -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Row } from '../../types/Row' @@ -11,7 +11,7 @@ import type { Row_CoreProperties } from './coreRowsFeature.types' function getRowPrototype< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): object { +>(table: Table): object { if (!table._rowPrototype) { table._rowPrototype = { table } const features = Object.values(table._features) @@ -31,7 +31,7 @@ export const constructRow = < TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, id: string, original: TData, rowIndex: number, diff --git a/packages/table-core/src/core/rows/coreRowsFeature.ts b/packages/table-core/src/core/rows/coreRowsFeature.ts index 94ded78286..f81195c47b 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.ts @@ -12,11 +12,12 @@ import { table_getRowId, } from './coreRowsFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +import type { CoreFeatures } from '../coreFeatures' /** * Core feature that creates row APIs for values, cells, and tree traversal. */ -export const coreRowsFeature: TableFeature = { +export const coreRowsFeature: TableFeature = { assignRowPrototype: (prototype, table) => { assignPrototypeAPIs('coreRowsFeature', prototype, table, { row_getAllCellsByColumnId: { diff --git a/packages/table-core/src/core/rows/coreRowsFeature.types.ts b/packages/table-core/src/core/rows/coreRowsFeature.types.ts index 4345405577..4bd6282ac1 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.types.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.types.ts @@ -1,4 +1,4 @@ -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Row } from '../../types/Row' @@ -41,7 +41,7 @@ export interface Row_CoreProperties< /** * Reference to the parent table instance. */ - table: Table_Internal + table: Table } export interface Row_Row< diff --git a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts index ce568a28a1..9707ca80d8 100644 --- a/packages/table-core/src/core/rows/coreRowsFeature.utils.ts +++ b/packages/table-core/src/core/rows/coreRowsFeature.utils.ts @@ -1,6 +1,6 @@ import { flattenBy } from '../../utils' import { constructCell } from '../cells/constructCell' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Row } from '../../types/Row' @@ -217,7 +217,7 @@ export function table_getRowId< TData extends RowData, >( originalRow: TData, - table: Table_Internal, + table: Table, index: number, parent?: Row, ) { @@ -242,7 +242,7 @@ export function table_getRow< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, rowId: string, searchAll?: boolean, ): Row { diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index c4f10f0ed5..6b2215dc26 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -2,13 +2,18 @@ import { coreFeatures } from '../coreFeatures' import { cloneState } from '../../utils' import { atomToStore } from '../reactivity/coreReactivityFeature.utils' import { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils' -import type { Atom } from '@tanstack/store' +import type { Atom, ReadonlyStore } from '@tanstack/store' import type { RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { TableOptions } from '../../types/TableOptions' -import type { TableState, TableState_All } from '../../types/TableState' +import type { TableState } from '../../types/TableState' +type Writeable = { -readonly [P in keyof T]: T[P] } +type MutableTable< + TFeatures extends TableFeatures, + TRowData extends RowData, +> = Writeable> /** * Builds the initial table state from registered features and user initial state. * @@ -64,15 +69,21 @@ export function constructTable< _rowModelFns: { aggregationFns, filterFns, sortFns }, baseAtoms: {}, atoms: {}, - } as unknown as Table_Internal + } as unknown as MutableTable const featuresList: Array = Object.values(table._features) const defaultOptions = featuresList.reduce((obj, feature) => { - return Object.assign(obj, feature.getDefaultTableOptions?.(table)) + return Object.assign( + obj, + feature.getDefaultTableOptions?.(table as unknown as Table), + ) }, {}) as TableOptions - const mergedOptions = { ...defaultOptions, ...tableOptions } + const mergedOptions = { ...defaultOptions, ...tableOptions } as TableOptions< + TFeatures, + TData + > if (_reactivity.wrapExternalAtoms && mergedOptions.atoms) { for (const [atomKey, _atom] of Object.entries(mergedOptions.atoms)) { @@ -113,7 +124,7 @@ export function constructTable< }, }) } else { - table.options = mergedOptions + table.options = mergedOptions as any } table.initialState = getInitialTableState( @@ -121,50 +132,53 @@ export function constructTable< table.options.initialState, ) - const stateKeys = Object.keys(table.initialState) as Array< - string & keyof TableState_All - > + const stateKeys = Object.keys(table.initialState) for (let i = 0; i < stateKeys.length; i++) { const key = stateKeys[i]! - table.baseAtoms[key] = _reactivity.createWritableAtom( - table.initialState[key], - { - debugName: `table/baseAtoms/${key}`, - }, - ) as any + table.baseAtoms[key as keyof typeof table.baseAtoms] = + _reactivity.createWritableAtom( + table.initialState[key as keyof typeof table.initialState], + { + debugName: `table/baseAtoms/${key}`, + }, + ) as any // create readonly derived atom: on each get(), read either external atom or base atom - ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom( - () => { - const externalAtoms = table.options.atoms as - | Partial>> - | undefined - const externalAtom = externalAtoms?.[key] - if (externalAtom) { - return externalAtom.get() - } - return table.baseAtoms[key]!.get() - }, - { debugName: `table/atoms/${key}` }, - ) + table.atoms[key as keyof typeof table.atoms] = + _reactivity.createReadonlyAtom( + () => { + const externalAtoms = table.options.atoms + const externalAtom = ( + externalAtoms as Record> | undefined + )?.[key] + if (externalAtom) { + return externalAtom.get() + } + return table.baseAtoms[key as keyof typeof table.baseAtoms].get() + }, + { debugName: `table/atoms/${key}` }, + ) } - table_syncExternalStateToBaseAtoms(table) + table_syncExternalStateToBaseAtoms( + table as unknown as Table, + ) table.store = atomToStore( _reactivity.createReadonlyAtom( () => { - const snapshot = {} as TableState & TableState_All + const snapshot = {} as TableState for (let i = 0; i < stateKeys.length; i++) { const key = stateKeys[i]! - ;(snapshot as Record)[key] = table.atoms[key]!.get() + ;(snapshot as Record)[key] = + table.atoms[key as keyof typeof table.atoms].get() } return snapshot }, { debugName: 'table/store' }, ), - ) + ) as unknown as ReadonlyStore> if ( process.env.NODE_ENV === 'development' && @@ -199,7 +213,7 @@ export function constructTable< } for (let i = 0; i < featuresList.length; i++) { - featuresList[i]!.constructTableAPIs?.(table) + featuresList[i]!.constructTableAPIs?.(table as unknown as Table) } return table as unknown as Table diff --git a/packages/table-core/src/core/table/coreTablesFeature.types.ts b/packages/table-core/src/core/table/coreTablesFeature.types.ts index 014e37be5c..69567467c5 100644 --- a/packages/table-core/src/core/table/coreTablesFeature.types.ts +++ b/packages/table-core/src/core/table/coreTablesFeature.types.ts @@ -10,7 +10,7 @@ import type { } from '../../types/TableFeatures' import type { CachedRowModels } from '../../types/RowModel' import type { TableOptions } from '../../types/TableOptions' -import type { TableState, TableState_All } from '../../types/TableState' +import type { TableState } from '../../types/TableState' export interface TableMeta< in out TFeatures extends TableFeatures, @@ -63,26 +63,6 @@ export type ExternalAtoms = Partial<{ [K in keyof TableState]: Atom[K]> }> -/** - * Internal "all features" flat variants of the atom types. `Table_Internal` - * uses these so feature code (written generically over `TFeatures`) can access - * any slice atom (e.g. `table.atoms.columnPinning`) without TypeScript - * narrowing away slices that aren't in the current `TFeatures` union. - * - * Keys are optional: feature code can read atoms from slices it doesn't own, - * but those slices may not be registered on the current table. Consumers must - * use optional chaining (`table.atoms.columnPinning?.get() ?? default`). - */ -export type BaseAtoms_All = { - [K in keyof TableState_All]?: Atom -} -export type Atoms_All = { - [K in keyof TableState_All]?: ReadonlyAtom -} -export type ExternalAtoms_All = Partial<{ - [K in keyof TableState_All]: Atom -}> - export interface TableOptions_Table< in out TFeatures extends TableFeatures, in out TData extends RowData, diff --git a/packages/table-core/src/core/table/coreTablesFeature.utils.ts b/packages/table-core/src/core/table/coreTablesFeature.utils.ts index 236710a32b..d56b718030 100644 --- a/packages/table-core/src/core/table/coreTablesFeature.utils.ts +++ b/packages/table-core/src/core/table/coreTablesFeature.utils.ts @@ -1,7 +1,7 @@ import { cloneState, functionalUpdate } from '../../utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { TableOptions } from '../../types/TableOptions' /** @@ -18,7 +18,7 @@ import type { TableOptions } from '../../types/TableOptions' export function table_syncExternalStateToBaseAtoms< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): void { +>(table: Table): void { const state = table.options.state if (!state) { return @@ -53,7 +53,7 @@ export function table_syncExternalStateToBaseAtoms< export function table_reset< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): void { +>(table: Table): void { const snap = cloneState(table.initialState) table._reactivity.batch(() => { const keys = Object.keys(snap) as Array @@ -78,15 +78,9 @@ export function table_reset< export function table_mergeOptions< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - newOptions: TableOptions, -) { +>(table: Table, newOptions: TableOptions) { if (table.options.mergeOptions) { - return table.options.mergeOptions( - table.options as TableOptions, - newOptions, - ) + return table.options.mergeOptions(table.options, newOptions) } return { @@ -110,13 +104,10 @@ export function table_setOptions< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, updater: Updater>, ): void { - const newOptions = functionalUpdate( - updater, - table.options as TableOptions, - ) + const newOptions = functionalUpdate(updater, table.options) // table static options that should never change after initialization const { features, atoms, initialState } = table.options const mergedOptions = Object.assign(table_mergeOptions(table, newOptions), { @@ -130,7 +121,7 @@ export function table_setOptions< if (table.optionsStore) { table.optionsStore.set(() => mergedOptions) } else { - table.options = mergedOptions + ;(table as any).options = mergedOptions } table_syncExternalStateToBaseAtoms(table) } diff --git a/packages/table-core/src/features/column-faceting/columnFacetingFeature.ts b/packages/table-core/src/features/column-faceting/columnFacetingFeature.ts index 193d1066dc..2d658d6b07 100644 --- a/packages/table-core/src/features/column-faceting/columnFacetingFeature.ts +++ b/packages/table-core/src/features/column-faceting/columnFacetingFeature.ts @@ -13,10 +13,16 @@ import { } from './columnFacetingFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +type ColumnFacetingFeature = { + columnFacetingFeature: TableFeature + columnFilteringFeature: TableFeature + globalFilteringFeature: TableFeature +} + /** * Feature that derives faceted row models, unique values, and min/max values for filters. */ -export const columnFacetingFeature: TableFeature = { +export const columnFacetingFeature: TableFeature = { assignColumnPrototype: (prototype, table) => { assignPrototypeAPIs('columnFacetingFeature', prototype, table, { column_getFacetedRowModel: { diff --git a/packages/table-core/src/features/column-faceting/columnFacetingFeature.utils.ts b/packages/table-core/src/features/column-faceting/columnFacetingFeature.utils.ts index 8c76af0f48..0f172c0863 100644 --- a/packages/table-core/src/features/column-faceting/columnFacetingFeature.utils.ts +++ b/packages/table-core/src/features/column-faceting/columnFacetingFeature.utils.ts @@ -1,8 +1,8 @@ import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table_Internal } from '../../types/Table' -import type { Column_Internal } from '../../types/Column' +import type { Table } from '../../types/Table' +import type { Column } from '../../types/Column' /** * Computes min and max numeric facet values for one column. @@ -20,8 +20,8 @@ export function column_getFacetedMinMaxValues< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, - table: Table_Internal, + column: Column, + table: Table, ): [number, number] | undefined { const facetedMinMaxValuesFn = table.options.features.facetedMinMaxValues?.(table, column.id) ?? @@ -46,8 +46,8 @@ export function column_getFacetedRowModel< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal | undefined, - table: Table_Internal, + column: Column | undefined, + table: Table, ): RowModel { const facetedRowModelFn = table.options.features.facetedRowModel?.(table, column?.id ?? '') ?? @@ -71,8 +71,8 @@ export function column_getFacetedUniqueValues< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, - table: Table_Internal, + column: Column, + table: Table, ): Map { const facetedUniqueValuesFn = table.options.features.facetedUniqueValues?.(table, column.id) ?? @@ -94,7 +94,7 @@ export function column_getFacetedUniqueValues< export function table_getGlobalFacetedMinMaxValues< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): undefined | [number, number] { +>(table: Table): undefined | [number, number] { const facetedMinMaxValuesFn = table.options.features.facetedMinMaxValues?.(table, '__global__') ?? (() => undefined) @@ -116,7 +116,7 @@ export function table_getGlobalFacetedMinMaxValues< export function table_getGlobalFacetedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { const facetedRowModelFn = table.options.features.facetedRowModel?.(table, '__global__') ?? (() => table.getPreFilteredRowModel()) @@ -137,7 +137,7 @@ export function table_getGlobalFacetedRowModel< export function table_getGlobalFacetedUniqueValues< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): Map { +>(table: Table): Map { const facetedUniqueValuesFn = table.options.features.facetedUniqueValues?.(table, '__global__') ?? (() => new Map()) diff --git a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts index 8db098c064..a85a8bedf4 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts @@ -1,7 +1,7 @@ import { callMemoOrStaticFn, tableMemo } from '../../utils' import { column_getFacetedRowModel } from './columnFacetingFeature.utils' import type { Row } from '../../types/Row' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { TableFeatures } from '../../types/TableFeatures' import type { RowData } from '../../types/type-utils' @@ -17,8 +17,7 @@ export function createFacetedMinMaxValues< table: Table, columnId: string, ) => () => undefined | [number, number] { - return (_table, columnId) => { - const table = _table as unknown as Table_Internal + return (table, columnId) => { return tableMemo({ feature: 'columnFacetingFeature', fn: (flatRows) => _createFacetedMinMaxValues(columnId, flatRows), diff --git a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts index 9c944aa2ab..0a231757ba 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts @@ -1,15 +1,21 @@ import { tableMemo } from '../../utils' import { filterRows } from '../column-filtering/filterRowsUtils' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { ColumnFiltersState, Row_ColumnFiltering, } from '../column-filtering/columnFilteringFeature.types' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' import type { Row } from '../../types/Row' import type { RowData } from '../../types/type-utils' +type FacetedRowModelFeatures = Partial<{ + columnFacetingFeature: TableFeature + columnFilteringFeature: TableFeature + globalFilteringFeature: TableFeature +}> + /** * Creates a memoized faceted row model factory. * @@ -22,16 +28,19 @@ export function createFacetedRowModel< table: Table, columnId: string, ) => () => RowModel { - return (_table, columnId) => { - const table = _table as unknown as Table_Internal + return (table, columnId) => { + const featureTable = table as unknown as Table< + FacetedRowModelFeatures, + TData + > return tableMemo({ feature: 'columnFacetingFeature', table, fnName: 'createFacetedRowModel', memoDeps: () => [ table.getPreFilteredRowModel(), - table.atoms.columnFilters?.get(), - table.atoms.globalFilter?.get(), + featureTable.atoms.columnFilters?.get(), + featureTable.atoms.globalFilter?.get(), table.getFilteredRowModel(), ], fn: (preRowModel, columnFilters, globalFilter) => @@ -50,7 +59,7 @@ function _createFacetedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, >( - table: Table_Internal, + table: Table, columnId: string, preRowModel: RowModel, columnFilters?: ColumnFiltersState, diff --git a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts index 8c6ce5c86e..71454294a5 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts @@ -1,7 +1,7 @@ import { callMemoOrStaticFn, tableMemo } from '../../utils' import { column_getFacetedRowModel } from './columnFacetingFeature.utils' import type { Row } from '../../types/Row' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { TableFeatures } from '../../types/TableFeatures' import type { RowData } from '../../types/type-utils' @@ -17,8 +17,7 @@ export function createFacetedUniqueValues< table: Table, columnId: string, ) => () => Map { - return (_table, columnId) => { - const table = _table as unknown as Table_Internal + return (table, columnId) => { return tableMemo({ feature: 'columnFacetingFeature', table, diff --git a/packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts b/packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts index fb09fe8f4a..0642265108 100644 --- a/packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts +++ b/packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts @@ -1,13 +1,17 @@ import { cloneState, functionalUpdate, isFunction } from '../../utils' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' -import type { Column_Internal } from '../../types/Column' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { Column } from '../../types/Column' import type { ColumnFiltersState, FilterFn, } from './columnFilteringFeature.types' +type ColumnFilteringFeatures = Partial<{ + columnFilteringFeature: TableFeature +}> + /** * Creates the default column filter state. * @@ -39,9 +43,14 @@ export function column_getAutoFilterFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { - const filterFns: Record> | undefined = - column.table._rowModelFns.filterFns +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnFilteringFeatures, + TData + > + const filterFns = featureTable._rowModelFns.filterFns as + | Record> + | undefined const firstRow = column.table.getCoreRowModel().flatRows[0] @@ -87,16 +96,31 @@ export function column_getFilterFn< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, ): FilterFn | undefined { let filterFn = null - const filterFns: Record> | undefined = - column.table._rowModelFns.filterFns - filterFn = isFunction(column.columnDef.filterFn) - ? column.columnDef.filterFn - : column.columnDef.filterFn === 'auto' + const featureTable = column.table as unknown as Table< + ColumnFilteringFeatures, + TData + > + const filterFns = featureTable._rowModelFns.filterFns as + | Record> + | undefined + const featureColumn = column as unknown as Column< + ColumnFilteringFeatures, + TData, + TValue + > + const columnFilterFn = featureColumn.columnDef.filterFn as unknown as + | FilterFn + | 'auto' + | string + | undefined + filterFn = isFunction(columnFilterFn) + ? columnFilterFn + : columnFilterFn === 'auto' ? column_getAutoFilterFn(column) - : filterFns?.[column.columnDef.filterFn as string] + : filterFns?.[columnFilterFn as unknown as string] if (process.env.NODE_ENV === 'development' && !filterFn) { console.warn( @@ -122,11 +146,20 @@ export function column_getCanFilter< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnFilteringFeatures, + TData + > + const featureColumn = column as unknown as Column< + ColumnFilteringFeatures, + TData, + TValue + > return ( - (column.columnDef.enableColumnFilter ?? true) && - (column.table.options.enableColumnFilters ?? true) && - (column.table.options.enableFilters ?? true) && + (featureColumn.columnDef.enableColumnFilter ?? true) && + (featureTable.options.enableColumnFilters ?? true) && + (featureTable.options.enableFilters ?? true) && !!column.accessorFn ) } @@ -146,7 +179,7 @@ export function column_getIsFiltered< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { return column_getFilterIndex(column) > -1 } @@ -164,8 +197,12 @@ export function column_getFilterValue< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { - return column.table.atoms.columnFilters +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnFilteringFeatures, + TData + > + return featureTable.atoms.columnFilters ?.get() ?.find((d) => d.id === column.id)?.value } @@ -184,9 +221,13 @@ export function column_getFilterIndex< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): number { +>(column: Column): number { + const featureTable = column.table as unknown as Table< + ColumnFilteringFeatures, + TData + > return ( - column.table.atoms.columnFilters + featureTable.atoms.columnFilters ?.get() ?.findIndex((d) => d.id === column.id) ?? -1 ) @@ -207,7 +248,7 @@ export function column_setFilterValue< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal, value: any) { +>(column: Column, value: any) { table_setColumnFilters(column.table, (old) => { const filterFn = column_getFilterFn(column) const previousFilter = old.find((d) => d.id === column.id) @@ -255,10 +296,7 @@ export function column_setFilterValue< export function table_setColumnFilters< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { +>(table: Table, updater: Updater) { const leafColumnsById = table.getAllLeafColumnsById() const updateFn = (old: ColumnFiltersState) => { @@ -277,7 +315,8 @@ export function table_setColumnFilters< }) } - table.options.onColumnFiltersChange?.(updateFn) + const featureTable = table as unknown as Table + featureTable.options.onColumnFiltersChange?.(updateFn) } /** @@ -295,10 +334,13 @@ export function table_setColumnFilters< export function table_resetColumnFilters< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setColumnFilters( table, - defaultState ? [] : cloneState(table.initialState.columnFilters ?? []), + defaultState + ? [] + : cloneState(featureTable.initialState.columnFilters ?? []), ) } @@ -319,7 +361,7 @@ export function shouldAutoRemoveFilter< >( filterFn?: FilterFn, value?: any, - column?: Column_Internal, + column?: Column, ) { return ( (filterFn && filterFn.autoRemove diff --git a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts index 29cec6fb47..186a46bf3f 100644 --- a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts +++ b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts @@ -8,9 +8,9 @@ import { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature 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 { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { ResolvedColumnFilter, @@ -29,16 +29,22 @@ export function createFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData = any, >(): (table: Table) => () => RowModel { - return (_table) => { - const table = _table as unknown as Table_Internal + return (table) => { + const typedTable = table as unknown as Table< + { + columnFilteringFeature: TableFeature + globalFilteringFeature: TableFeature + }, + TData + > return tableMemo({ feature: 'columnFilteringFeature', table, fnName: 'table.getFilteredRowModel', memoDeps: () => [ - table.getPreFilteredRowModel(), - table.atoms.columnFilters?.get(), - table.atoms.globalFilter?.get(), + typedTable.getPreFilteredRowModel(), + typedTable.atoms.columnFilters?.get(), + typedTable.atoms.globalFilter?.get(), ], fn: () => _createFilteredRowModel(table), onAfterUpdate: () => table_autoResetPageIndex(table), @@ -49,10 +55,17 @@ export function createFilteredRowModel< function _createFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData = any, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { + const typedTable = table as unknown as Table< + { + columnFilteringFeature: TableFeature + globalFilteringFeature: TableFeature + }, + TData + > const rowModel = table.getPreFilteredRowModel() - const columnFilters = table.atoms.columnFilters?.get() - const globalFilter = table.atoms.globalFilter?.get() + const columnFilters = typedTable.atoms.columnFilters?.get() + const globalFilter = typedTable.atoms.globalFilter?.get() if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) { const flatRows = rowModel.flatRows as Array< diff --git a/packages/table-core/src/features/column-filtering/filterRowsUtils.ts b/packages/table-core/src/features/column-filtering/filterRowsUtils.ts index 1a995b4ed2..871cfd9c4c 100644 --- a/packages/table-core/src/features/column-filtering/filterRowsUtils.ts +++ b/packages/table-core/src/features/column-filtering/filterRowsUtils.ts @@ -2,10 +2,14 @@ import { constructRow } from '../../core/rows/constructRow' import type { Row_ColumnFiltering } from './columnFilteringFeature.types' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' import type { Row } from '../../types/Row' -import type { Table_Internal } from '../../types/Table' -import type { TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowData } from '../../types/type-utils' +type ColumnFilteringFeatures = Partial<{ + columnFilteringFeature: TableFeature +}> + /** * Filters a row model with the supplied row predicate. * @@ -17,9 +21,10 @@ export function filterRows< >( rows: Array>, filterRowImpl: (row: Row) => any, - table: Table_Internal, + table: Table, ) { - if (table.options.filterFromLeafRows) { + const featureTable = table as unknown as Table + if (featureTable.options.filterFromLeafRows) { return filterRowModelFromLeafs(rows, filterRowImpl, table) } @@ -34,11 +39,12 @@ function filterRowModelFromLeafs< filterRow: ( row: Row, ) => Array> | undefined, - table: Table_Internal, + table: Table, ): RowModel { const newFilteredFlatRows: Array> = [] const newFilteredRowsById: Record> = {} - const maxDepth = table.options.maxLeafRowFilterDepth ?? 100 + const featureTable = table as unknown as Table + const maxDepth = featureTable.options.maxLeafRowFilterDepth ?? 100 const recurseFilterRows = ( rowsToFilter: Array< @@ -106,11 +112,12 @@ function filterRowModelFromRoot< >( rowsToFilter: Array>, filterRow: (row: Row) => any, - table: Table_Internal, + table: Table, ): RowModel { const newFilteredFlatRows: Array> = [] const newFilteredRowsById: Record> = {} - const maxDepth = table.options.maxLeafRowFilterDepth ?? 100 + const featureTable = table as unknown as Table + const maxDepth = featureTable.options.maxLeafRowFilterDepth ?? 100 // Filters top level and nested rows const recurseFilterRows = ( diff --git a/packages/table-core/src/features/column-grouping/columnGroupingFeature.utils.ts b/packages/table-core/src/features/column-grouping/columnGroupingFeature.utils.ts index 7b96c2ceac..b017497730 100644 --- a/packages/table-core/src/features/column-grouping/columnGroupingFeature.utils.ts +++ b/packages/table-core/src/features/column-grouping/columnGroupingFeature.utils.ts @@ -1,8 +1,8 @@ import { cloneState, isFunction } from '../../utils' -import type { Column_Internal } from '../../types/Column' +import type { Column } from '../../types/Column' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' import type { @@ -11,6 +11,8 @@ import type { Row_ColumnGrouping, } from './columnGroupingFeature.types' +type ColumnGroupingFeatures = Partial<{ columnGroupingFeature: TableFeature }> + /** * Creates the default grouping state. * @@ -41,7 +43,7 @@ export function column_toggleGrouping< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { table_setGrouping(column.table, (old) => { // Find any existing grouping for this column if (old.includes(column.id)) { @@ -67,11 +69,16 @@ export function column_getCanGroup< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureColumn = column as unknown as Column< + ColumnGroupingFeatures, + TData, + TValue + > return ( - (column.columnDef.enableGrouping ?? true) && - (column.table.options.enableGrouping ?? true) && - (!!column.accessorFn || !!column.columnDef.getGroupingValue) + (featureColumn.columnDef.enableGrouping ?? true) && + (featureColumn.table.options.enableGrouping ?? true) && + (!!column.accessorFn || !!featureColumn.columnDef.getGroupingValue) ) } @@ -90,8 +97,12 @@ export function column_getIsGrouped< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): boolean { - return !!column.table.atoms.grouping?.get()?.includes(column.id) +>(column: Column): boolean { + const featureTable = column.table as unknown as Table< + ColumnGroupingFeatures, + TData + > + return !!featureTable.atoms.grouping?.get()?.includes(column.id) } /** @@ -108,8 +119,12 @@ export function column_getGroupedIndex< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): number { - return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1 +>(column: Column): number { + const featureTable = column.table as unknown as Table< + ColumnGroupingFeatures, + TData + > + return featureTable.atoms.grouping?.get()?.indexOf(column.id) ?? -1 } /** @@ -126,7 +141,7 @@ export function column_getToggleGroupingHandler< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { const canGroup = column_getCanGroup(column) return () => { @@ -150,10 +165,18 @@ export function column_getAutoAggregationFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>( + column: Column, +): AggregationFn | undefined { + const featureTable = column.table as unknown as Table< + ColumnGroupingFeatures, + TData + > const aggregationFns: | Record> - | undefined = column.table._rowModelFns.aggregationFns + | undefined = featureTable._rowModelFns.aggregationFns as + | Record> + | undefined const firstRow = column.table.getCoreRowModel().flatRows[0] @@ -184,16 +207,33 @@ export function column_getAggregationFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>( + column: Column, +): AggregationFn | undefined { + const featureColumn = column as unknown as Column< + ColumnGroupingFeatures, + TData, + TValue + > + const featureTable = column.table as unknown as Table< + ColumnGroupingFeatures, + TData + > const aggregationFns: | Record> - | undefined = column.table._rowModelFns.aggregationFns + | undefined = featureTable._rowModelFns.aggregationFns as + | Record> + | undefined - return isFunction(column.columnDef.aggregationFn) - ? column.columnDef.aggregationFn - : column.columnDef.aggregationFn === 'auto' + const aggregationFn = isFunction(featureColumn.columnDef.aggregationFn) + ? featureColumn.columnDef.aggregationFn + : featureColumn.columnDef.aggregationFn === 'auto' ? column_getAutoAggregationFn(column) - : aggregationFns?.[column.columnDef.aggregationFn as string] + : featureColumn.columnDef.aggregationFn + ? aggregationFns?.[featureColumn.columnDef.aggregationFn] + : undefined + + return aggregationFn as AggregationFn | undefined } /** @@ -210,8 +250,9 @@ export function column_getAggregationFn< export function table_setGrouping< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { - table.options.onGroupingChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onGroupingChange?.(updater) } /** @@ -229,10 +270,11 @@ export function table_setGrouping< export function table_resetGrouping< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setGrouping( table, - defaultState ? [] : cloneState(table.initialState.grouping ?? []), + defaultState ? [] : cloneState(featureTable.initialState.grouping ?? []), ) } @@ -272,19 +314,19 @@ export function row_getGroupingValue< return row._groupingValuesCache[columnId] } - const column = row.table.getColumn(columnId) as Column_Internal< - TFeatures, + const column = row.table.getColumn(columnId) as Column + const featureColumn = column as unknown as Column< + ColumnGroupingFeatures, TData > - if (!column.columnDef.getGroupingValue) { + if (!featureColumn.columnDef.getGroupingValue) { return row.getValue(columnId) } if (row._groupingValuesCache) { - row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue( - row.original, - ) + row._groupingValuesCache[columnId] = + featureColumn.columnDef.getGroupingValue(row.original) } return row._groupingValuesCache?.[columnId] @@ -305,9 +347,11 @@ export function cell_getIsGrouped< TData extends RowData, TValue extends CellData = CellData, >(cell: Cell) { - const row = cell.row as Row & Partial + const row = cell.row return ( - column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId + column_getIsGrouped(cell.column) && + cell.column.id === + (row as Row & Row_ColumnGrouping).groupingColumnId ) } diff --git a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts index 35d74464fc..7c4e561700 100644 --- a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts +++ b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts @@ -9,12 +9,14 @@ import { } from './columnGroupingFeature.utils' import type { Column } from '../../types/Column' import type { Row_ColumnGrouping } from './columnGroupingFeature.types' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowData } from '../../types/type-utils' +type GroupedRowModelFeatures = Partial<{ columnGroupingFeature: TableFeature }> + /** * Creates a memoized grouped row model factory. * @@ -28,14 +30,17 @@ export function createGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, >(): (table: Table) => () => RowModel { - return (_table) => { - const table = _table as unknown as Table_Internal + return (table) => { + const featureTable = table as unknown as Table< + GroupedRowModelFeatures, + TData + > return tableMemo({ feature: 'columnGroupingFeature', table, fnName: 'table.getGroupedRowModel', memoDeps: () => [ - table.atoms.grouping?.get(), + featureTable.atoms.grouping?.get(), table.getPreGroupedRowModel(), ], fn: () => _createGroupedRowModel(table), @@ -50,9 +55,10 @@ export function createGroupedRowModel< function _createGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { + const featureTable = table as unknown as Table const rowModel = table.getPreGroupedRowModel() - const grouping = table.atoms.grouping?.get() + const grouping = featureTable.atoms.grouping?.get() if (!rowModel.rows.length || !grouping?.length) { rowModel.rows.forEach((row) => { @@ -153,9 +159,11 @@ function _createGroupedRowModel< // Aggregate the values const column = table.getColumn(colId) - const aggregateFn = column_getAggregationFn( - column as Column, - ) + const aggregateFn = column + ? column_getAggregationFn( + column as Column, + ) + : undefined if (!row._groupingValuesCache) row._groupingValuesCache = {} diff --git a/packages/table-core/src/features/column-ordering/columnOrderingFeature.utils.ts b/packages/table-core/src/features/column-ordering/columnOrderingFeature.utils.ts index 49a2654aef..57386d4135 100644 --- a/packages/table-core/src/features/column-ordering/columnOrderingFeature.utils.ts +++ b/packages/table-core/src/features/column-ordering/columnOrderingFeature.utils.ts @@ -2,12 +2,17 @@ import { table_getPinnedVisibleLeafColumns } from '../column-pinning/columnPinni import { cloneState } from '../../utils' import type { GroupingState } from '../column-grouping/columnGroupingFeature.types' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' -import type { Column_Internal } from '../../types/Column' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { Column } from '../../types/Column' import type { ColumnPinningPosition } from '../column-pinning/columnPinningFeature.types' import type { ColumnOrderState } from './columnOrderingFeature.types' +type ColumnOrderingFeatures = Partial<{ + columnOrderingFeature: TableFeature + columnGroupingFeature: TableFeature +}> + /** * Creates the default column order state. * @@ -39,7 +44,7 @@ export function column_getIndex< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, position?: ColumnPinningPosition | 'center', ) { const columns = table_getPinnedVisibleLeafColumns(column.table, position) @@ -61,7 +66,7 @@ export function column_getIsFirstColumn< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, position?: ColumnPinningPosition | 'center', ) { const columns = table_getPinnedVisibleLeafColumns(column.table, position) @@ -83,7 +88,7 @@ export function column_getIsLastColumn< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, position?: ColumnPinningPosition | 'center', ) { const columns = table_getPinnedVisibleLeafColumns(column.table, position) @@ -104,8 +109,9 @@ export function column_getIsLastColumn< export function table_setColumnOrder< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { - table.options.onColumnOrderChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onColumnOrderChange?.(updater) } /** @@ -123,10 +129,11 @@ export function table_setColumnOrder< export function table_resetColumnOrder< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setColumnOrder( table, - defaultState ? [] : cloneState(table.initialState.columnOrder ?? []), + defaultState ? [] : cloneState(featureTable.initialState.columnOrder ?? []), ) } @@ -144,23 +151,21 @@ export function table_resetColumnOrder< export function table_getOrderColumnsFn< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - const columnOrder = table.atoms.columnOrder?.get() +>(table: Table) { + const featureTable = table as unknown as Table + const columnOrder = featureTable.atoms.columnOrder?.get() - return (columns: Array>) => { + return (columns: Array>) => { // Sort grouped columns to the start of the column list // before the headers are built - let orderedColumns: Array> = [] + let orderedColumns: Array> = [] // If there is no order, return the normal columns if (!columnOrder?.length) { orderedColumns = columns } else { // Index columns by id for O(1) lookup - const remaining = new Map< - string, - Column_Internal - >() + const remaining = new Map>() for (let i = 0; i < columns.length; i++) { const column = columns[i]! remaining.set(column.id, column) @@ -204,11 +209,12 @@ export function orderColumns< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, - leafColumns: Array>, + table: Table, + leafColumns: Array>, ) { - const grouping = table.atoms.grouping?.get() ?? ([] as GroupingState) - const { groupedColumnMode } = table.options + const featureTable = table as unknown as Table + const grouping = featureTable.atoms.grouping?.get() ?? ([] as GroupingState) + const { groupedColumnMode } = featureTable.options if (!grouping.length || !groupedColumnMode) { return leafColumns @@ -222,16 +228,13 @@ export function orderColumns< return nonGroupingColumns } - const leafColumnsById = new Map< - string, - Column_Internal - >() + const leafColumnsById = new Map>() for (let i = 0; i < leafColumns.length; i++) { const col = leafColumns[i]! leafColumnsById.set(col.id, col) } - const groupingColumns: Array> = [] + const groupingColumns: Array> = [] for (let i = 0; i < grouping.length; i++) { const col = leafColumnsById.get(grouping[i]!) if (col) groupingColumns.push(col) diff --git a/packages/table-core/src/features/column-pinning/columnPinningFeature.utils.ts b/packages/table-core/src/features/column-pinning/columnPinningFeature.utils.ts index 4bb3f4305f..5b7ee4f182 100644 --- a/packages/table-core/src/features/column-pinning/columnPinningFeature.utils.ts +++ b/packages/table-core/src/features/column-pinning/columnPinningFeature.utils.ts @@ -11,14 +11,18 @@ import type { HeaderGroup } from '../../types/HeaderGroup' import type { Cell } from '../../types/Cell' import type { Row } from '../../types/Row' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' -import type { Column, Column_Internal } from '../../types/Column' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { Column } from '../../types/Column' import type { ColumnPinningPosition, ColumnPinningState, } from './columnPinningFeature.types' +type ColumnPinningFeatures = Partial<{ + columnPinningFeature: TableFeature +}> + // State /** @@ -57,10 +61,7 @@ export function column_pin< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->( - column: Column_Internal, - position: ColumnPinningPosition, -) { +>(column: Column, position: ColumnPinningPosition) { // Single pass: collect non-empty leaf-column ids. const leafColumns = column.getLeafColumns() const columnIds: Array = [] @@ -109,16 +110,24 @@ export function column_getCanPin< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { - const leafColumns = column.getLeafColumns() as Array< - Column_Internal +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnPinningFeatures, + TData > + const leafColumns = column.getLeafColumns() - return leafColumns.some( - (leafColumn) => - (leafColumn.columnDef.enablePinning ?? true) && - (column.table.options.enableColumnPinning ?? true), - ) + return leafColumns.some((leafColumn) => { + const featureColumn = leafColumn as unknown as Column< + ColumnPinningFeatures, + TData, + TValue + > + return ( + (featureColumn.columnDef.enablePinning ?? true) && + (featureTable.options.enableColumnPinning ?? true) + ) + }) } /** @@ -136,13 +145,15 @@ export function column_getIsPinned< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->( - column: Column_Internal, -): ColumnPinningPosition | false { +>(column: Column): ColumnPinningPosition | false { + const featureTable = column.table as unknown as Table< + ColumnPinningFeatures, + TData + > const leafColumnIds = column.getLeafColumns().map((d) => d.id) const { left, right } = - column.table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const isLeft = leafColumnIds.some((d) => left.includes(d)) const isRight = leafColumnIds.some((d) => right.includes(d)) @@ -165,11 +176,15 @@ export function column_getPinnedIndex< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnPinningFeatures, + TData + > const position = column_getIsPinned(column) return position - ? (column.table.atoms.columnPinning?.get()?.[position].indexOf(column.id) ?? + ? (featureTable.atoms.columnPinning?.get()?.[position].indexOf(column.id) ?? -1) : 0 } @@ -190,13 +205,17 @@ export function row_getCenterVisibleCells< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { + const featureTable = row.table as unknown as Table< + ColumnPinningFeatures, + TData + > const allCells = callMemoOrStaticFn( row, 'getVisibleCells', row_getVisibleCells, ) const { left, right } = - row.table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] return allCells.filter((d) => !leftAndRight.includes(d.column.id)) } @@ -216,8 +235,12 @@ export function row_getLeftVisibleCells< TFeatures extends TableFeatures, TData extends RowData, >(row: Row): Array> { + const featureTable = row.table as unknown as Table< + ColumnPinningFeatures, + TData + > const { left } = - row.table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() if (!left.length) return [] const allVisibleCells = callMemoOrStaticFn( row, @@ -252,8 +275,12 @@ export function row_getRightVisibleCells< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { + const featureTable = row.table as unknown as Table< + ColumnPinningFeatures, + TData + > const { right } = - row.table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() if (!right.length) return [] as Array> const allVisibleCells = callMemoOrStaticFn( row, @@ -289,11 +316,9 @@ export function row_getRightVisibleCells< export function table_setColumnPinning< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { - table.options.onColumnPinningChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onColumnPinningChange?.(updater) } /** @@ -312,13 +337,15 @@ export function table_setColumnPinning< export function table_resetColumnPinning< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setColumnPinning( table, defaultState ? getDefaultColumnPinningState() : cloneState( - table.initialState.columnPinning ?? getDefaultColumnPinningState(), + featureTable.initialState.columnPinning ?? + getDefaultColumnPinningState(), ), ) } @@ -337,8 +364,9 @@ export function table_resetColumnPinning< export function table_getIsSomeColumnsPinned< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, position?: ColumnPinningPosition) { - const pinningState = table.atoms.columnPinning?.get() +>(table: Table, position?: ColumnPinningPosition) { + const featureTable = table as unknown as Table + const pinningState = featureTable.atoms.columnPinning?.get() if (!position) { return Boolean(pinningState?.left.length || pinningState?.right.length) @@ -362,11 +390,12 @@ export function table_getIsSomeColumnsPinned< export function table_getLeftHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const allColumns = table.getAllColumns() const leafColumnsById = table.getAllLeafColumnsById() const { left } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const orderedLeafColumns: Array> = [] for (let i = 0; i < left.length; i++) { @@ -396,11 +425,12 @@ export function table_getLeftHeaderGroups< export function table_getRightHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const allColumns = table.getAllColumns() const leafColumnsById = table.getAllLeafColumnsById() const { right } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const orderedLeafColumns: Array> = [] for (let i = 0; i < right.length; i++) { @@ -430,9 +460,8 @@ export function table_getRightHeaderGroups< export function table_getCenterHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, -): Array> { +>(table: Table): Array> { + const featureTable = table as unknown as Table const allColumns = table.getAllColumns() let leafColumns = callMemoOrStaticFn( table, @@ -440,7 +469,7 @@ export function table_getCenterHeaderGroups< table_getVisibleLeafColumns, ) const { left, right } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] leafColumns = leafColumns.filter( @@ -464,7 +493,7 @@ export function table_getCenterHeaderGroups< export function table_getLeftFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const headerGroups = callMemoOrStaticFn( table, 'getLeftHeaderGroups', @@ -486,7 +515,7 @@ export function table_getLeftFooterGroups< export function table_getRightFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const headerGroups = callMemoOrStaticFn( table, 'getRightHeaderGroups', @@ -508,7 +537,7 @@ export function table_getRightFooterGroups< export function table_getCenterFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const headerGroups = callMemoOrStaticFn( table, 'getCenterHeaderGroups', @@ -532,7 +561,7 @@ export function table_getCenterFooterGroups< export function table_getLeftFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const leftHeaderGroups = callMemoOrStaticFn( table, 'getLeftHeaderGroups', @@ -542,7 +571,7 @@ export function table_getLeftFlatHeaders< for (let i = 0; i < leftHeaderGroups.length; i++) { const headers = leftHeaderGroups[i]!.headers for (let j = 0; j < headers.length; j++) { - result.push(headers[j]!) + result.push(headers[j] as Header) } } return result @@ -561,7 +590,7 @@ export function table_getLeftFlatHeaders< export function table_getRightFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const rightHeaderGroups = callMemoOrStaticFn( table, 'getRightHeaderGroups', @@ -571,7 +600,7 @@ export function table_getRightFlatHeaders< for (let i = 0; i < rightHeaderGroups.length; i++) { const headers = rightHeaderGroups[i]!.headers for (let j = 0; j < headers.length; j++) { - result.push(headers[j]!) + result.push(headers[j] as Header) } } return result @@ -590,7 +619,7 @@ export function table_getRightFlatHeaders< export function table_getCenterFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const centerHeaderGroups = callMemoOrStaticFn( table, 'getCenterHeaderGroups', @@ -600,7 +629,7 @@ export function table_getCenterFlatHeaders< for (let i = 0; i < centerHeaderGroups.length; i++) { const headers = centerHeaderGroups[i]!.headers for (let j = 0; j < headers.length; j++) { - result.push(headers[j]!) + result.push(headers[j] as Header) } } return result @@ -621,7 +650,7 @@ export function table_getCenterFlatHeaders< export function table_getLeftLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getLeftFlatHeaders', @@ -642,7 +671,7 @@ export function table_getLeftLeafHeaders< export function table_getRightLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getRightFlatHeaders', @@ -663,7 +692,7 @@ export function table_getRightLeafHeaders< export function table_getCenterLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getCenterFlatHeaders', @@ -687,11 +716,12 @@ export function table_getCenterLeafHeaders< export function table_getLeftLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const { left } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const leafColumnsById = table.getAllLeafColumnsById() - const result: Array> = [] + const result: Array> = [] for (let i = 0; i < left.length; i++) { const column = leafColumnsById[left[i]!] if (column) result.push(column) @@ -713,11 +743,12 @@ export function table_getLeftLeafColumns< export function table_getRightLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const { right } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const leafColumnsById = table.getAllLeafColumnsById() - const result: Array> = [] + const result: Array> = [] for (let i = 0; i < right.length; i++) { const column = leafColumnsById[right[i]!] if (column) result.push(column) @@ -738,9 +769,10 @@ export function table_getRightLeafColumns< export function table_getCenterLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const { left, right } = - table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] return table.getAllLeafColumns().filter((d) => !leftAndRight.includes(d.id)) } @@ -759,10 +791,7 @@ export function table_getCenterLeafColumns< export function table_getPinnedLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - position: ColumnPinningPosition | 'center', -) { +>(table: Table, position: ColumnPinningPosition | 'center') { return !position ? table.getAllLeafColumns() : position === 'left' @@ -799,7 +828,7 @@ export function table_getPinnedLeafColumns< export function table_getLeftVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getLeftLeafColumns', @@ -822,7 +851,7 @@ export function table_getLeftVisibleLeafColumns< export function table_getRightVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getRightLeafColumns', @@ -846,7 +875,7 @@ export function table_getRightVisibleLeafColumns< export function table_getCenterVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return callMemoOrStaticFn( table, 'getCenterLeafColumns', @@ -870,10 +899,7 @@ export function table_getCenterVisibleLeafColumns< export function table_getPinnedVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - position?: ColumnPinningPosition | 'center', -) { +>(table: Table, position?: ColumnPinningPosition | 'center') { return !position ? callMemoOrStaticFn( table, diff --git a/packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts b/packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts index 75c278c23c..e64b782e4f 100644 --- a/packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts +++ b/packages/table-core/src/features/column-resizing/columnResizingFeature.utils.ts @@ -5,13 +5,15 @@ import { } from '../column-sizing/columnSizingFeature.utils' import { cloneState } from '../../utils' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Header } from '../../types/Header' -import type { Column_Internal } from '../../types/Column' +import type { Column } from '../../types/Column' import type { ColumnSizingState } from '../column-sizing/columnSizingFeature.types' import type { columnResizingState } from './columnResizingFeature.types' +type ColumnResizingFeatures = Partial<{ columnResizingFeature: TableFeature }> + /** * Creates the default transient column resizing state. * @@ -49,10 +51,15 @@ export function column_getCanResize< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureColumn = column as unknown as Column< + ColumnResizingFeatures, + TData, + TValue + > return ( - (column.columnDef.enableResizing ?? true) && - (column.table.options.enableColumnResizing ?? true) + (featureColumn.columnDef.enableResizing ?? true) && + (featureColumn.table.options.enableColumnResizing ?? true) ) } @@ -70,9 +77,13 @@ export function column_getIsResizing< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureTable = column.table as unknown as Table< + ColumnResizingFeatures, + TData + > return ( - column.table.atoms.columnResizing?.get()?.isResizingColumn === column.id + featureTable.atoms.columnResizing?.get()?.isResizingColumn === column.id ) } @@ -94,6 +105,10 @@ export function header_getResizeHandler< TValue extends CellData = CellData, >(header: Header, _contextDocument?: Document) { const column = header.table.getColumn(header.column.id)! + const featureTable = column.table as unknown as Table< + ColumnResizingFeatures, + TData + > const canResize = column_getCanResize(column) return (event: unknown) => { @@ -132,7 +147,7 @@ export function header_getResizeHandler< table_setColumnResizing(column.table, (old) => { const deltaDirection = - column.table.options.columnResizeDirection === 'rtl' ? -1 : 1 + featureTable.options.columnResizeDirection === 'rtl' ? -1 : 1 const deltaOffset = (clientXPos - (old.startOffset ?? 0)) * deltaDirection const startSize = old.startSize ?? 0 @@ -161,7 +176,7 @@ export function header_getResizeHandler< }) if ( - column.table.options.columnResizeMode === 'onChange' || + featureTable.options.columnResizeMode === 'onChange' || eventType === 'end' ) { table_setColumnSizing(column.table, (old) => ({ @@ -279,11 +294,9 @@ export function header_getResizeHandler< export function table_setColumnResizing< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { - table.options.onColumnResizingChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onColumnResizingChange?.(updater) } /** @@ -302,13 +315,15 @@ export function table_setColumnResizing< export function table_resetHeaderSizeInfo< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setColumnResizing( table, defaultState ? getDefaultColumnResizingState() : cloneState( - table.initialState.columnResizing ?? getDefaultColumnResizingState(), + featureTable.initialState.columnResizing ?? + getDefaultColumnResizingState(), ), ) } diff --git a/packages/table-core/src/features/column-sizing/columnSizingFeature.utils.ts b/packages/table-core/src/features/column-sizing/columnSizingFeature.utils.ts index 89ce6ce02c..05b8bcacd4 100644 --- a/packages/table-core/src/features/column-sizing/columnSizingFeature.utils.ts +++ b/packages/table-core/src/features/column-sizing/columnSizingFeature.utils.ts @@ -8,12 +8,14 @@ import { column_getIndex } from '../column-ordering/columnOrderingFeature.utils' import { callMemoOrStaticFn, cloneState } from '../../utils' import type { ColumnPinningPosition } from '../column-pinning/columnPinningFeature.types' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Header } from '../../types/Header' -import type { Column_Internal } from '../../types/Column' +import type { Column } from '../../types/Column' import type { ColumnSizingState } from './columnSizingFeature.types' +type ColumnSizingFeatures = Partial<{ columnSizingFeature: TableFeature }> + /** * Creates the default committed column sizing state. * @@ -64,16 +66,21 @@ export function column_getSize< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): number { +>(column: Column): number { const defaultSizes = getDefaultColumnSizingColumnDef() - const columnSize = column.table.atoms.columnSizing?.get()?.[column.id] + const featureColumn = column as unknown as Column< + ColumnSizingFeatures, + TData, + TValue + > + const columnSize = featureColumn.table.atoms.columnSizing?.get()?.[column.id] return Math.min( Math.max( - column.columnDef.minSize ?? defaultSizes.minSize, - columnSize ?? column.columnDef.size ?? defaultSizes.size, + featureColumn.columnDef.minSize ?? defaultSizes.minSize, + columnSize ?? featureColumn.columnDef.size ?? defaultSizes.size, ), - column.columnDef.maxSize ?? defaultSizes.maxSize, + featureColumn.columnDef.maxSize ?? defaultSizes.maxSize, ) } @@ -93,7 +100,7 @@ export function column_getStart< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, position: ColumnPinningPosition | 'center', ): number { const index = callMemoOrStaticFn( @@ -134,7 +141,7 @@ export function column_getAfter< TData extends RowData, TValue extends CellData = CellData, >( - column: Column_Internal, + column: Column, position: ColumnPinningPosition | 'center', ): number { const visibleLeafColumns = callMemoOrStaticFn( @@ -173,7 +180,7 @@ export function column_resetSize< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { table_setColumnSizing(column.table, ({ [column.id]: _, ...rest }) => { return rest }) @@ -255,11 +262,9 @@ export function header_getStart< export function table_setColumnSizing< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { - table.options.onColumnSizingChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onColumnSizingChange?.(updater) } /** @@ -277,10 +282,13 @@ export function table_setColumnSizing< export function table_resetColumnSizing< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setColumnSizing( table, - defaultState ? {} : cloneState(table.initialState.columnSizing ?? {}), + defaultState + ? {} + : cloneState(featureTable.initialState.columnSizing ?? {}), ) } @@ -297,7 +305,7 @@ export function table_resetColumnSizing< export function table_getTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return ( table.getHeaderGroups()[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header) @@ -318,7 +326,7 @@ export function table_getTotalSize< export function table_getLeftTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return ( callMemoOrStaticFn( table, @@ -343,7 +351,7 @@ export function table_getLeftTotalSize< export function table_getCenterTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return ( callMemoOrStaticFn( table, @@ -368,7 +376,7 @@ export function table_getCenterTotalSize< export function table_getRightTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return ( callMemoOrStaticFn( table, diff --git a/packages/table-core/src/features/column-visibility/columnVisibilityFeature.utils.ts b/packages/table-core/src/features/column-visibility/columnVisibilityFeature.utils.ts index 7c669d871b..73d161be4d 100644 --- a/packages/table-core/src/features/column-visibility/columnVisibilityFeature.utils.ts +++ b/packages/table-core/src/features/column-visibility/columnVisibilityFeature.utils.ts @@ -1,13 +1,18 @@ import { callMemoOrStaticFn, cloneState } from '../../utils' import { getDefaultColumnPinningState } from '../column-pinning/columnPinningFeature.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Cell } from '../../types/Cell' -import type { Column_Internal } from '../../types/Column' +import type { Column } from '../../types/Column' import type { ColumnVisibilityState } from './columnVisibilityFeature.types' import type { Row } from '../../types/Row' +type ColumnVisibilityFeatures = Partial<{ + columnVisibilityFeature: TableFeature + columnPinningFeature: TableFeature +}> + /** * Creates the default column visibility state. * @@ -38,7 +43,7 @@ export function column_toggleVisibility< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal, visible?: boolean): void { +>(column: Column, visible?: boolean): void { if (column_getCanHide(column)) { table_setColumnVisibility(column.table, (old) => ({ ...old, @@ -65,14 +70,19 @@ export function column_getIsVisible< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): boolean { +>(column: Column): boolean { + const featureColumn = column as unknown as Column< + ColumnVisibilityFeatures, + TData, + TValue + > const childColumns = column.columns return ( (childColumns.length ? childColumns.some((childColumn) => callMemoOrStaticFn(childColumn, 'getIsVisible', column_getIsVisible), ) - : column.table.atoms.columnVisibility?.get()?.[column.id]) ?? true + : featureColumn.table.atoms.columnVisibility?.get()?.[column.id]) ?? true ) } @@ -90,10 +100,15 @@ export function column_getCanHide< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureColumn = column as unknown as Column< + ColumnVisibilityFeatures, + TData, + TValue + > return ( - (column.columnDef.enableHiding ?? true) && - (column.table.options.enableHiding ?? true) + (featureColumn.columnDef.enableHiding ?? true) && + (featureColumn.table.options.enableHiding ?? true) ) } @@ -112,7 +127,7 @@ export function column_getToggleVisibilityHandler< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { return (e: unknown) => { column_toggleVisibility( column, @@ -136,6 +151,10 @@ export function row_getVisibleCells< TFeatures extends TableFeatures, TData extends RowData, >(row: Row): Array> { + const featureTable = row.table as unknown as Table< + ColumnVisibilityFeatures, + TData + > const allCells = row.getAllCells() const visibleCells: Array> = [] for (let i = 0; i < allCells.length; i++) { @@ -146,7 +165,7 @@ export function row_getVisibleCells< } const { left, right } = - row.table.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() + featureTable.atoms.columnPinning?.get() ?? getDefaultColumnPinningState() if (!left.length && !right.length) return visibleCells // no pinning, return early const visibleCellsByColumnId = callMemoOrStaticFn( @@ -217,7 +236,7 @@ export function row_getVisibleCellsByColumnId< export function table_getVisibleFlatColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table .getAllFlatColumns() .filter((column) => @@ -239,7 +258,7 @@ export function table_getVisibleFlatColumns< export function table_getVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table .getAllLeafColumns() .filter((column) => @@ -261,11 +280,12 @@ export function table_getVisibleLeafColumns< export function table_setColumnVisibility< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { - table.options.onColumnVisibilityChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table< + ColumnVisibilityFeatures, + TData + > + featureTable.options.onColumnVisibilityChange?.(updater) } /** @@ -283,10 +303,16 @@ export function table_setColumnVisibility< export function table_resetColumnVisibility< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table< + ColumnVisibilityFeatures, + TData + > table_setColumnVisibility( table, - defaultState ? {} : cloneState(table.initialState.columnVisibility ?? {}), + defaultState + ? {} + : cloneState(featureTable.initialState.columnVisibility ?? {}), ) } @@ -303,7 +329,7 @@ export function table_resetColumnVisibility< export function table_toggleAllColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, value?: boolean) { +>(table: Table, value?: boolean) { value = value ?? !table_getIsAllColumnsVisible(table) const visibility: Record = {} @@ -330,7 +356,7 @@ export function table_toggleAllColumnsVisible< export function table_getIsAllColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return !table .getAllLeafColumns() .some( @@ -352,7 +378,7 @@ export function table_getIsAllColumnsVisible< export function table_getIsSomeColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table .getAllLeafColumns() .some((column) => @@ -374,7 +400,7 @@ export function table_getIsSomeColumnsVisible< export function table_getToggleAllColumnsVisibilityHandler< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return (e: unknown) => { table_toggleAllColumnsVisible( table, diff --git a/packages/table-core/src/features/global-filtering/globalFilteringFeature.ts b/packages/table-core/src/features/global-filtering/globalFilteringFeature.ts index ef4f630c02..2d8f3eb7e9 100644 --- a/packages/table-core/src/features/global-filtering/globalFilteringFeature.ts +++ b/packages/table-core/src/features/global-filtering/globalFilteringFeature.ts @@ -27,7 +27,7 @@ export const globalFilteringFeature: TableFeature = { return { onGlobalFilterChange: makeStateUpdater('globalFilter', table), globalFilterFn: 'auto', - getColumnCanGlobalFilter: (column) => { + getColumnCanGlobalFilter: (column: any) => { const value = table .getCoreRowModel() .flatRows[0]?.getAllCellsByColumnId() diff --git a/packages/table-core/src/features/global-filtering/globalFilteringFeature.utils.ts b/packages/table-core/src/features/global-filtering/globalFilteringFeature.utils.ts index 588475f7f7..bb3b62cf9b 100644 --- a/packages/table-core/src/features/global-filtering/globalFilteringFeature.utils.ts +++ b/packages/table-core/src/features/global-filtering/globalFilteringFeature.utils.ts @@ -1,10 +1,15 @@ import { filterFn_includesString } from '../../fns/filterFns' import { cloneState, isFunction } from '../../utils' -import type { Column_Internal } from '../../types/Column' +import type { Column } from '../../types/Column' import type { FilterFn } from '../column-filtering/columnFilteringFeature.types' import type { CellData, RowData } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' + +type GlobalFilteringFeatures = Partial<{ + globalFilteringFeature: TableFeature + columnFilteringFeature: TableFeature +}> /** * Checks whether this accessor column participates in global filtering. @@ -21,12 +26,18 @@ export function column_getCanGlobalFilter< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): boolean { +>(column: Column): boolean { + const featureColumn = column as unknown as Column< + GlobalFilteringFeatures, + TData, + TValue + > return ( - (column.columnDef.enableGlobalFilter ?? true) && - (column.table.options.enableGlobalFilter ?? true) && - (column.table.options.enableFilters ?? true) && - (column.table.options.getColumnCanGlobalFilter?.(column as any) ?? true) && + (featureColumn.columnDef.enableGlobalFilter ?? true) && + (featureColumn.table.options.enableGlobalFilter ?? true) && + (featureColumn.table.options.enableFilters ?? true) && + (featureColumn.table.options.getColumnCanGlobalFilter?.(column as any) ?? + true) && !!column.accessorFn ) } @@ -61,20 +72,23 @@ export function table_getGlobalAutoFilterFn() { export function table_getGlobalFilterFn< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, -): FilterFn | undefined { - const { globalFilterFn: globalFilterFn } = table.options +>(table: Table): FilterFn | undefined { + const featureTable = table as unknown as Table + const { globalFilterFn: globalFilterFn } = featureTable.options const filterFns: Record> | undefined = - table._rowModelFns.filterFns + featureTable._rowModelFns.filterFns as + | Record> + | undefined const filterFn = isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? table_getGlobalAutoFilterFn() - : filterFns?.[globalFilterFn as string] + : globalFilterFn + ? filterFns?.[globalFilterFn] + : undefined - return filterFn + return filterFn as FilterFn | undefined } /** @@ -91,8 +105,9 @@ export function table_getGlobalFilterFn< export function table_setGlobalFilter< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: any) { - table.options.onGlobalFilterChange?.(updater) +>(table: Table, updater: any) { + const featureTable = table as unknown as Table + featureTable.options.onGlobalFilterChange?.(updater) } /** @@ -110,9 +125,12 @@ export function table_setGlobalFilter< export function table_resetGlobalFilter< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setGlobalFilter( table, - defaultState ? undefined : cloneState(table.initialState.globalFilter), + defaultState + ? undefined + : cloneState(featureTable.initialState.globalFilter), ) } diff --git a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts index 093b8fbed9..eb6ea9ecfb 100644 --- a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts +++ b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts @@ -1,10 +1,11 @@ import { tableMemo } from '../../utils' import { row_getIsExpanded } from './rowExpandingFeature.utils' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowData } from '../../types/type-utils' +type ExpandedRowModelFeatures = Partial<{ rowExpandingFeature: TableFeature }> /** * Creates a memoized expanded row model factory. @@ -15,16 +16,19 @@ export function createExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, >(): (table: Table) => () => RowModel { - return (_table) => { - const table = _table as unknown as Table_Internal + return (table) => { + const featureTable = table as unknown as Table< + ExpandedRowModelFeatures, + TData + > return tableMemo({ feature: 'rowExpandingFeature', table, fnName: 'table.getExpandedRowModel', memoDeps: () => [ - table.atoms.expanded?.get(), + featureTable.atoms.expanded?.get(), table.getPreExpandedRowModel(), - table.options.paginateExpandedRows, + featureTable.options.paginateExpandedRows, ], fn: () => _createExpandedRowModel(table), }) @@ -34,9 +38,13 @@ export function createExpandedRowModel< function _createExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { + const featureTable = table as unknown as Table< + ExpandedRowModelFeatures, + TData + > const rowModel = table.getPreExpandedRowModel() - const expanded = table.atoms.expanded?.get() + const expanded = featureTable.atoms.expanded?.get() if ( !rowModel.rows.length || @@ -45,7 +53,7 @@ function _createExpandedRowModel< return rowModel } - if (!table.options.paginateExpandedRows) { + if (!featureTable.options.paginateExpandedRows) { // Only expand rows at this point if they are being paginated return rowModel } diff --git a/packages/table-core/src/features/row-expanding/rowExpandingFeature.utils.ts b/packages/table-core/src/features/row-expanding/rowExpandingFeature.utils.ts index cb99ad56f2..1b100768ae 100644 --- a/packages/table-core/src/features/row-expanding/rowExpandingFeature.utils.ts +++ b/packages/table-core/src/features/row-expanding/rowExpandingFeature.utils.ts @@ -1,13 +1,15 @@ import { cloneState } from '../../utils' import type { RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { ExpandedState, ExpandedStateList, } from './rowExpandingFeature.types' +type RowExpandingFeatures = Partial<{ rowExpandingFeature: TableFeature }> + /** * Creates the default expanded state. * @@ -38,11 +40,12 @@ export function getDefaultExpandedState(): ExpandedState { export function table_autoResetExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table if ( table.options.autoResetAll ?? - table.options.autoResetExpanded ?? - !table.options.manualExpanding + featureTable.options.autoResetExpanded ?? + !featureTable.options.manualExpanding ) { table._reactivity.schedule(() => table_resetExpanded(table)) } @@ -62,8 +65,9 @@ export function table_autoResetExpanded< export function table_setExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { - table.options.onExpandedChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onExpandedChange?.(updater) } /** @@ -81,7 +85,7 @@ export function table_setExpanded< export function table_toggleAllRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, expanded?: boolean) { +>(table: Table, expanded?: boolean) { if (expanded ?? !table_getIsAllRowsExpanded(table)) { table_setExpanded(table, true) } else { @@ -104,10 +108,11 @@ export function table_toggleAllRowsExpanded< export function table_resetExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setExpanded( table, - defaultState ? {} : cloneState(table.initialState.expanded ?? {}), + defaultState ? {} : cloneState(featureTable.initialState.expanded ?? {}), ) } @@ -125,7 +130,7 @@ export function table_resetExpanded< export function table_getCanSomeRowsExpand< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table .getPrePaginatedRowModel() .flatRows.some((row) => row_getCanExpand(row)) @@ -145,7 +150,7 @@ export function table_getCanSomeRowsExpand< export function table_getToggleAllRowsExpandedHandler< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return (e: unknown) => { ;(e as any).persist?.() table_toggleAllRowsExpanded(table) @@ -165,8 +170,9 @@ export function table_getToggleAllRowsExpandedHandler< export function table_getIsSomeRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - const expanded = table.atoms.expanded?.get() ?? {} +>(table: Table) { + const featureTable = table as unknown as Table + const expanded = featureTable.atoms.expanded?.get() ?? {} return expanded === true || Object.values(expanded).some(Boolean) } @@ -184,8 +190,9 @@ export function table_getIsSomeRowsExpanded< export function table_getIsAllRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - const expanded = table.atoms.expanded?.get() ?? {} +>(table: Table) { + const featureTable = table as unknown as Table + const expanded = featureTable.atoms.expanded?.get() ?? {} // If expanded is true, save some cycles and return true if (expanded === true) { @@ -219,13 +226,14 @@ export function table_getIsAllRowsExpanded< export function table_getExpandedDepth< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table let maxDepth = 0 const rowIds = - table.atoms.expanded?.get() === true + featureTable.atoms.expanded?.get() === true ? Object.keys(table.getRowModel().rowsById) - : Object.keys(table.atoms.expanded?.get() ?? {}) + : Object.keys(featureTable.atoms.expanded?.get() ?? {}) rowIds.forEach((id) => { const splitId = id.split('.') @@ -297,10 +305,16 @@ export function row_getIsExpanded< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { - const expanded: ExpandedState = row.table.atoms.expanded?.get() ?? {} + const featureTable = row.table as unknown as Table< + RowExpandingFeatures, + TData + > + const expanded: ExpandedState = featureTable.atoms.expanded?.get() ?? {} return !!( - row.table.options.getIsRowExpanded?.(row) ?? + featureTable.options.getIsRowExpanded?.( + row as unknown as Row, + ) ?? (expanded === true || expanded[row.id]) ) } @@ -320,9 +334,15 @@ export function row_getCanExpand< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { + const featureTable = row.table as unknown as Table< + RowExpandingFeatures, + TData + > return ( - row.table.options.getRowCanExpand?.(row) ?? - ((row.table.options.enableExpanding ?? true) && !!row.subRows.length) + featureTable.options.getRowCanExpand?.( + row as unknown as Row, + ) ?? + ((featureTable.options.enableExpanding ?? true) && !!row.subRows.length) ) } diff --git a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts index f6fd43c0a3..f6b0caa5e9 100644 --- a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts +++ b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts @@ -1,12 +1,17 @@ import { tableMemo } from '../../utils' import { expandRows } from '../row-expanding/createExpandedRowModel' import { getDefaultPaginationState } from './rowPaginationFeature.utils' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowData } from '../../types/type-utils' +type PaginatedRowModelFeatures = Partial<{ + rowPaginationFeature: TableFeature + rowExpandingFeature: TableFeature +}> + /** * Creates a memoized paginated row model factory. * @@ -16,17 +21,20 @@ export function createPaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, >(): (table: Table) => () => RowModel { - return (_table) => { - const table = _table as unknown as Table_Internal + return (table) => { + const featureTable = table as unknown as Table< + PaginatedRowModelFeatures, + TData + > return tableMemo({ feature: 'rowPaginationFeature', table, fnName: 'table.getPaginatedRowModel', memoDeps: () => [ table.getPrePaginatedRowModel(), - table.atoms.pagination?.get(), - table.options.paginateExpandedRows - ? table.atoms.expanded?.get() + featureTable.atoms.pagination?.get(), + featureTable.options.paginateExpandedRows + ? featureTable.atoms.expanded?.get() : undefined, ], fn: () => _createPaginatedRowModel(table), @@ -37,9 +45,13 @@ export function createPaginatedRowModel< function _createPaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { + const featureTable = table as unknown as Table< + PaginatedRowModelFeatures, + TData + > const prePaginatedRowModel = table.getPrePaginatedRowModel() - const pagination = table.atoms.pagination?.get() + const pagination = featureTable.atoms.pagination?.get() if (!prePaginatedRowModel.rows.length) { return prePaginatedRowModel @@ -54,7 +66,7 @@ function _createPaginatedRowModel< let paginatedRowModel: RowModel - if (!table.options.paginateExpandedRows) { + if (!featureTable.options.paginateExpandedRows) { paginatedRowModel = expandRows({ rows: paginatedRows, flatRows, diff --git a/packages/table-core/src/features/row-pagination/rowPaginationFeature.utils.ts b/packages/table-core/src/features/row-pagination/rowPaginationFeature.utils.ts index 359a944620..39a0417102 100644 --- a/packages/table-core/src/features/row-pagination/rowPaginationFeature.utils.ts +++ b/packages/table-core/src/features/row-pagination/rowPaginationFeature.utils.ts @@ -1,9 +1,11 @@ import { cloneState, functionalUpdate } from '../../utils' import type { RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { PaginationState } from './rowPaginationFeature.types' +type RowPaginationFeatures = Partial<{ rowPaginationFeature: TableFeature }> + const defaultPageIndex = 0 const defaultPageSize = 10 @@ -40,11 +42,12 @@ export function getDefaultPaginationState(): PaginationState { export function table_autoResetPageIndex< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table if ( table.options.autoResetAll ?? - table.options.autoResetPageIndex ?? - !table.options.manualPagination + featureTable.options.autoResetPageIndex ?? + !featureTable.options.manualPagination ) { table_resetPageIndex(table) } @@ -65,14 +68,15 @@ export function table_autoResetPageIndex< export function table_setPagination< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table const safeUpdater: Updater = (old) => { const newState = functionalUpdate(updater, old) return newState } - return table.options.onPaginationChange?.(safeUpdater) + return featureTable.options.onPaginationChange?.(safeUpdater) } /** @@ -91,13 +95,14 @@ export function table_setPagination< export function table_resetPagination< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setPagination( table, defaultState ? getDefaultPaginationState() : cloneState( - table.initialState.pagination ?? getDefaultPaginationState(), + featureTable.initialState.pagination ?? getDefaultPaginationState(), ), ) } @@ -116,15 +121,16 @@ export function table_resetPagination< export function table_setPageIndex< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table table_setPagination(table, (old) => { let pageIndex = functionalUpdate(updater, old.pageIndex) const maxPageIndex = - typeof table.options.pageCount === 'undefined' || - table.options.pageCount === -1 + typeof featureTable.options.pageCount === 'undefined' || + featureTable.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER - : table.options.pageCount - 1 + : featureTable.options.pageCount - 1 pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex)) @@ -150,12 +156,13 @@ export function table_setPageIndex< export function table_resetPageIndex< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table const currentPageIndex = - table.atoms.pagination?.get()?.pageIndex ?? defaultPageIndex + featureTable.atoms.pagination?.get()?.pageIndex ?? defaultPageIndex const newPageIndex = defaultState ? defaultPageIndex - : (table.initialState.pagination?.pageIndex ?? defaultPageIndex) + : (featureTable.initialState.pagination?.pageIndex ?? defaultPageIndex) if (newPageIndex === currentPageIndex) return table_setPageIndex(table, newPageIndex) } @@ -175,12 +182,13 @@ export function table_resetPageIndex< export function table_resetPageSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table const currentPageSize = - table.atoms.pagination?.get()?.pageSize ?? defaultPageSize + featureTable.atoms.pagination?.get()?.pageSize ?? defaultPageSize const newPageSize = defaultState ? defaultPageSize - : (table.initialState.pagination?.pageSize ?? defaultPageSize) + : (featureTable.initialState.pagination?.pageSize ?? defaultPageSize) if (newPageSize === currentPageSize) return table_setPageSize(table, newPageSize) } @@ -199,7 +207,7 @@ export function table_resetPageSize< export function table_setPageSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { +>(table: Table, updater: Updater) { table_setPagination(table, (old) => { const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize)) const topRowIndex = old.pageSize * old.pageIndex @@ -227,7 +235,7 @@ export function table_setPageSize< export function table_getPageOptions< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const pageCount = table_getPageCount(table) let pageOptions: Array = [] if (pageCount && pageCount > 0) { @@ -250,8 +258,9 @@ export function table_getPageOptions< export function table_getCanPreviousPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - return (table.atoms.pagination?.get()?.pageIndex ?? 0) > 0 +>(table: Table) { + const featureTable = table as unknown as Table + return (featureTable.atoms.pagination?.get()?.pageIndex ?? 0) > 0 } /** @@ -268,8 +277,10 @@ export function table_getCanPreviousPage< export function table_getCanNextPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - const pageIndex = table.atoms.pagination?.get()?.pageIndex ?? defaultPageIndex +>(table: Table) { + const featureTable = table as unknown as Table + const pageIndex = + featureTable.atoms.pagination?.get()?.pageIndex ?? defaultPageIndex const pageCount = table_getPageCount(table) @@ -298,7 +309,7 @@ export function table_getCanNextPage< export function table_previousPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table_setPageIndex(table, (old) => old - 1) } @@ -316,7 +327,7 @@ export function table_previousPage< export function table_nextPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table_setPageIndex(table, (old) => { return old + 1 }) @@ -335,7 +346,7 @@ export function table_nextPage< export function table_firstPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table_setPageIndex(table, 0) } @@ -352,7 +363,7 @@ export function table_firstPage< export function table_lastPage< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return table_setPageIndex(table, table_getPageCount(table) - 1) } @@ -370,12 +381,13 @@ export function table_lastPage< export function table_getPageCount< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table return ( - table.options.pageCount ?? + featureTable.options.pageCount ?? Math.ceil( table_getRowCount(table) / - (table.atoms.pagination?.get()?.pageSize ?? defaultPageSize), + (featureTable.atoms.pagination?.get()?.pageSize ?? defaultPageSize), ) ) } @@ -395,6 +407,9 @@ export function table_getPageCount< export function table_getRowCount< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { - return table.options.rowCount ?? table.getPrePaginatedRowModel().rows.length +>(table: Table) { + const featureTable = table as unknown as Table + return ( + featureTable.options.rowCount ?? table.getPrePaginatedRowModel().rows.length + ) } diff --git a/packages/table-core/src/features/row-pinning/rowPinningFeature.utils.ts b/packages/table-core/src/features/row-pinning/rowPinningFeature.utils.ts index 085d1d06c9..069b51bdd5 100644 --- a/packages/table-core/src/features/row-pinning/rowPinningFeature.utils.ts +++ b/packages/table-core/src/features/row-pinning/rowPinningFeature.utils.ts @@ -1,14 +1,16 @@ import { row_getIsAllParentsExpanded } from '../row-expanding/rowExpandingFeature.utils' import { callMemoOrStaticFn, cloneState } from '../../utils' import type { RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowPinningPosition, RowPinningState, } from './rowPinningFeature.types' +type RowPinningFeatures = Partial<{ rowPinningFeature: TableFeature }> + // State Utils /** @@ -43,11 +45,9 @@ export function getDefaultRowPinningState(): RowPinningState { export function table_setRowPinning< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -): void { - table.options.onRowPinningChange?.(updater) +>(table: Table, updater: Updater): void { + const featureTable = table as unknown as Table + featureTable.options.onRowPinningChange?.(updater) } /** @@ -66,13 +66,14 @@ export function table_setRowPinning< export function table_resetRowPinning< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean): void { +>(table: Table, defaultState?: boolean): void { + const featureTable = table as unknown as Table table_setRowPinning( table, defaultState ? getDefaultRowPinningState() : cloneState( - table.initialState.rowPinning ?? getDefaultRowPinningState(), + featureTable.initialState.rowPinning ?? getDefaultRowPinningState(), ), ) } @@ -93,11 +94,9 @@ export function table_resetRowPinning< export function table_getIsSomeRowsPinned< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - position?: RowPinningPosition, -): boolean { - const rowPinning = table.atoms.rowPinning?.get() +>(table: Table, position?: RowPinningPosition): boolean { + const featureTable = table as unknown as Table + const rowPinning = featureTable.atoms.rowPinning?.get() if (!position) { return Boolean(rowPinning?.top.length || rowPinning?.bottom.length) @@ -109,12 +108,13 @@ function table_getPinnedRows< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table_Internal, + table: Table, position: 'top' | 'bottom', ): Array> { + const featureTable = table as unknown as Table const visibleRows = table.getRowModel().rows - const pinnedRowIds = table.atoms.rowPinning?.get()?.[position] ?? [] - const keepPinnedRows = table.options.keepPinnedRows ?? true + const pinnedRowIds = featureTable.atoms.rowPinning?.get()?.[position] ?? [] + const keepPinnedRows = featureTable.options.keepPinnedRows ?? true const result: Array> = [] for (let i = 0; i < pinnedRowIds.length; i++) { @@ -152,7 +152,7 @@ function table_getPinnedRows< export function table_getTopRows< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): Array> { +>(table: Table): Array> { return table_getPinnedRows(table, 'top') } @@ -170,7 +170,7 @@ export function table_getTopRows< export function table_getBottomRows< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): Array> { +>(table: Table): Array> { return table_getPinnedRows(table, 'bottom') } @@ -188,9 +188,10 @@ export function table_getBottomRows< export function table_getCenterRows< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): Array> { +>(table: Table): Array> { + const featureTable = table as unknown as Table const { top, bottom } = - table.atoms.rowPinning?.get() ?? getDefaultRowPinningState() + featureTable.atoms.rowPinning?.get() ?? getDefaultRowPinningState() const allRows = table.getRowModel().rows const topAndBottom = new Set([...top, ...bottom]) @@ -214,9 +215,10 @@ export function row_getCanPin< TFeatures extends TableFeatures, TData extends RowData, >(row: Row): boolean { - const { enableRowPinning } = row.table.options + const featureTable = row.table as unknown as Table + const { enableRowPinning } = featureTable.options if (typeof enableRowPinning === 'function') { - return enableRowPinning(row) + return enableRowPinning(row as unknown as Row) } return enableRowPinning ?? true } @@ -236,8 +238,9 @@ export function row_getIsPinned< TFeatures extends TableFeatures, TData extends RowData, >(row: Row): RowPinningPosition { + const featureTable = row.table as unknown as Table const { top, bottom } = - row.table.atoms.rowPinning?.get() ?? getDefaultRowPinningState() + featureTable.atoms.rowPinning?.get() ?? getDefaultRowPinningState() return top.includes(row.id) ? 'top' diff --git a/packages/table-core/src/features/row-selection/rowSelectionFeature.ts b/packages/table-core/src/features/row-selection/rowSelectionFeature.ts index 691e9dadc3..13bb2ebbcf 100644 --- a/packages/table-core/src/features/row-selection/rowSelectionFeature.ts +++ b/packages/table-core/src/features/row-selection/rowSelectionFeature.ts @@ -29,11 +29,14 @@ import { table_toggleAllRowsSelected, } from './rowSelectionFeature.utils' import type { TableFeature } from '../../types/TableFeatures' +import './rowSelectionFeature.types' /** * Feature that adds row selection state and APIs for row and page selection. */ -export const rowSelectionFeature: TableFeature = { +export const rowSelectionFeature: TableFeature<{ + rowSelectionFeature: TableFeature +}> = { getInitialState: (initialState) => { return { rowSelection: getDefaultRowSelectionState(), diff --git a/packages/table-core/src/features/row-selection/rowSelectionFeature.types.ts b/packages/table-core/src/features/row-selection/rowSelectionFeature.types.ts index 8af6d8f280..0ae2d6ea53 100644 --- a/packages/table-core/src/features/row-selection/rowSelectionFeature.types.ts +++ b/packages/table-core/src/features/row-selection/rowSelectionFeature.types.ts @@ -1,5 +1,5 @@ import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' import type { Row } from '../../types/Row' diff --git a/packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts b/packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts index a04e84510e..98e4e96b51 100644 --- a/packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts +++ b/packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts @@ -1,11 +1,13 @@ import { cloneState } from '../../utils' import type { RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' import type { RowSelectionState } from './rowSelectionFeature.types' +type RowSelectionFeatures = Partial<{ rowSelectionFeature: TableFeature }> + // State APIs /** @@ -37,11 +39,9 @@ export function getDefaultRowSelectionState(): RowSelectionState { export function table_setRowSelection< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table_Internal, - updater: Updater, -) { - table.options.onRowSelectionChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onRowSelectionChange?.(updater) } /** @@ -59,10 +59,13 @@ export function table_setRowSelection< export function table_resetRowSelection< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setRowSelection( table, - defaultState ? {} : cloneState(table.initialState.rowSelection ?? {}), + defaultState + ? {} + : cloneState(featureTable.initialState.rowSelection ?? {}), ) } @@ -82,7 +85,7 @@ export function table_resetRowSelection< export function table_toggleAllRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, value?: boolean) { +>(table: Table, value?: boolean) { table_setRowSelection(table, (old) => { value = typeof value !== 'undefined' ? value : !table_getIsAllRowsSelected(table) @@ -124,7 +127,7 @@ export function table_toggleAllRowsSelected< export function table_toggleAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, value?: boolean) { +>(table: Table, value?: boolean) { table_setRowSelection(table, (old) => { const resolvedValue = typeof value !== 'undefined' @@ -155,7 +158,7 @@ export function table_toggleAllPageRowsSelected< export function table_getPreSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { return table.getCoreRowModel() } @@ -173,10 +176,11 @@ export function table_getPreSelectedRowModel< export function table_getSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const rowModel = table.getCoreRowModel() - if (!Object.keys(table.atoms.rowSelection?.get() ?? {}).length) { + if (!Object.keys(featureTable.atoms.rowSelection?.get() ?? {}).length) { return { rows: [], flatRows: [], @@ -201,10 +205,11 @@ export function table_getSelectedRowModel< export function table_getFilteredSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const rowModel = table.getCoreRowModel() - if (!Object.keys(table.atoms.rowSelection?.get() ?? {}).length) { + if (!Object.keys(featureTable.atoms.rowSelection?.get() ?? {}).length) { return { rows: [], flatRows: [], @@ -229,10 +234,11 @@ export function table_getFilteredSelectedRowModel< export function table_getGroupedSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const rowModel = table.getCoreRowModel() - if (!Object.keys(table.atoms.rowSelection?.get() ?? {}).length) { + if (!Object.keys(featureTable.atoms.rowSelection?.get() ?? {}).length) { return { rows: [], flatRows: [], @@ -257,9 +263,11 @@ export function table_getGroupedSelectedRowModel< export function table_getIsAllRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const preGroupedFlatRows = table.getFilteredRowModel().flatRows - const rowSelection: RowSelectionState = table.atoms.rowSelection?.get() ?? {} + const rowSelection: RowSelectionState = + featureTable.atoms.rowSelection?.get() ?? {} let isAllRowsSelected = Boolean( preGroupedFlatRows.length && Object.keys(rowSelection).length, @@ -291,11 +299,13 @@ export function table_getIsAllRowsSelected< export function table_getIsAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const paginationFlatRows = table .getPaginatedRowModel() .flatRows.filter((row) => row_getCanSelect(row)) - const rowSelection: RowSelectionState = table.atoms.rowSelection?.get() ?? {} + const rowSelection: RowSelectionState = + featureTable.atoms.rowSelection?.get() ?? {} let isAllPageRowsSelected = !!paginationFlatRows.length @@ -323,9 +333,10 @@ export function table_getIsAllPageRowsSelected< export function table_getIsSomeRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { + const featureTable = table as unknown as Table const totalSelected = Object.keys( - table.atoms.rowSelection?.get() ?? {}, + featureTable.atoms.rowSelection?.get() ?? {}, ).length return ( totalSelected > 0 && @@ -347,7 +358,7 @@ export function table_getIsSomeRowsSelected< export function table_getIsSomePageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { const paginationFlatRows = table.getPaginatedRowModel().flatRows return table_getIsAllPageRowsSelected(table) ? false @@ -370,7 +381,7 @@ export function table_getIsSomePageRowsSelected< export function table_getToggleAllRowsSelectedHandler< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return (e: unknown) => { table_toggleAllRowsSelected( table, @@ -393,7 +404,7 @@ export function table_getToggleAllRowsSelectedHandler< export function table_getToggleAllPageRowsSelectedHandler< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal) { +>(table: Table) { return (e: unknown) => { table_toggleAllPageRowsSelected( table, @@ -514,9 +525,15 @@ export function row_getCanSelect< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { - const options = row.table.options + const featureTable = row.table as unknown as Table< + RowSelectionFeatures, + TData + > + const options = featureTable.options if (typeof options.enableRowSelection === 'function') { - return options.enableRowSelection(row) + return options.enableRowSelection( + row as unknown as Row, + ) } return options.enableRowSelection ?? true @@ -537,9 +554,15 @@ export function row_getCanSelectSubRows< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { - const options = row.table.options + const featureTable = row.table as unknown as Table< + RowSelectionFeatures, + TData + > + const options = featureTable.options if (typeof options.enableSubRowSelection === 'function') { - return options.enableSubRowSelection(row) + return options.enableSubRowSelection( + row as unknown as Row, + ) } return options.enableSubRowSelection ?? true @@ -560,9 +583,15 @@ export function row_getCanMultiSelect< TFeatures extends TableFeatures, TData extends RowData, >(row: Row) { - const options = row.table.options + const featureTable = row.table as unknown as Table< + RowSelectionFeatures, + TData + > + const options = featureTable.options if (typeof options.enableMultiRowSelection === 'function') { - return options.enableMultiRowSelection(row) + return options.enableMultiRowSelection( + row as unknown as Row, + ) } return options.enableMultiRowSelection ?? true @@ -602,7 +631,7 @@ const mutateRowIsSelected = < rowId: string, value: boolean, includeChildren: boolean, - table: Table_Internal, + table: Table, ) => { const row = table.getRow(rowId, true) @@ -695,7 +724,11 @@ export function isRowSelected< TFeatures extends TableFeatures, TData extends RowData, >(row: Row): boolean { - return (row.table.atoms.rowSelection?.get() ?? {})[row.id] ?? false + const featureTable = row.table as unknown as Table< + RowSelectionFeatures, + TData + > + return (featureTable.atoms.rowSelection?.get() ?? {})[row.id] ?? false } /** diff --git a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts index 42e8578233..ef9bfa710e 100644 --- a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts +++ b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts @@ -1,14 +1,16 @@ import { tableMemo } from '../../utils' import { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils' import { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils' -import type { Column_Internal } from '../../types/Column' -import type { TableFeatures } from '../../types/TableFeatures' +import type { Column } from '../../types/Column' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table } from '../../types/Table' import type { Row } from '../../types/Row' -import type { SortFn } from './rowSortingFeature.types' +import type { ColumnDef_RowSorting, SortFn } from './rowSortingFeature.types' import type { RowData } from '../../types/type-utils' +type SortedRowModelFeatures = Partial<{ rowSortingFeature: TableFeature }> + /** * Creates a memoized sorted row model factory. * @@ -21,14 +23,17 @@ export function createSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, >(): (table: Table) => () => RowModel { - return (_table) => { - const table = _table as unknown as Table_Internal + return (table) => { + const featureTable = table as unknown as Table< + SortedRowModelFeatures, + TData + > return tableMemo({ feature: 'rowSortingFeature', - table, + table: table, fnName: 'table.getSortedRowModel', memoDeps: () => [ - table.atoms.sorting?.get(), + featureTable.atoms.sorting?.get(), table.getPreSortedRowModel(), ], fn: () => _createSortedRowModel(table), @@ -40,9 +45,10 @@ export function createSortedRowModel< function _createSortedRowModel< TFeatures extends TableFeatures, TData extends RowData = any, ->(table: Table_Internal): RowModel { +>(table: Table): RowModel { + const featureTable = table as unknown as Table const preSortedRowModel = table.getPreSortedRowModel() - const sorting = table.atoms.sorting?.get() + const sorting = featureTable.atoms.sorting?.get() if (!preSortedRowModel.rows.length || !sorting?.length) { return preSortedRowModel @@ -52,9 +58,7 @@ function _createSortedRowModel< // Filter out sortings that correspond to non existing columns const availableSorting = sorting.filter((sort) => - column_getCanSort( - table.getColumn(sort.id) as Column_Internal, - ), + column_getCanSort(table.getColumn(sort.id) as Column), ) const columnInfoById: Record< @@ -67,13 +71,15 @@ function _createSortedRowModel< > = {} availableSorting.forEach((sortEntry) => { - const column: Column_Internal | undefined = - table.getColumn(sortEntry.id) + const column: Column | undefined = table.getColumn( + sortEntry.id, + ) if (!column) return + const columnDef = column.columnDef as ColumnDef_RowSorting columnInfoById[sortEntry.id] = { - sortUndefined: column.columnDef.sortUndefined, - invertSorting: column.columnDef.invertSorting, + sortUndefined: columnDef.sortUndefined, + invertSorting: columnDef.invertSorting, sortFn: column_getSortFn(column), } }) diff --git a/packages/table-core/src/features/row-sorting/rowSortingFeature.utils.ts b/packages/table-core/src/features/row-sorting/rowSortingFeature.utils.ts index b8a4c94afb..6ffe9b2bbf 100644 --- a/packages/table-core/src/features/row-sorting/rowSortingFeature.utils.ts +++ b/packages/table-core/src/features/row-sorting/rowSortingFeature.utils.ts @@ -1,15 +1,18 @@ import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns' import { cloneState, isFunction } from '../../utils' import type { CellData, RowData, Updater } from '../../types/type-utils' -import type { TableFeatures } from '../../types/TableFeatures' -import type { Table_Internal } from '../../types/Table' -import type { Column_Internal } from '../../types/Column' +import type { TableFeature, TableFeatures } from '../../types/TableFeatures' +import type { Table } from '../../types/Table' +import type { Column } from '../../types/Column' import type { + ColumnDef_RowSorting, SortDirection, SortFn, SortingState, } from './rowSortingFeature.types' +type RowSortingFeatures = Partial<{ rowSortingFeature: TableFeature }> + // State Utils /** @@ -41,8 +44,9 @@ export function getDefaultSortingState(): SortingState { export function table_setSorting< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, updater: Updater) { - table.options.onSortingChange?.(updater) +>(table: Table, updater: Updater) { + const featureTable = table as unknown as Table + featureTable.options.onSortingChange?.(updater) } /** @@ -60,10 +64,11 @@ export function table_setSorting< export function table_resetSorting< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table_Internal, defaultState?: boolean) { +>(table: Table, defaultState?: boolean) { + const featureTable = table as unknown as Table table_setSorting( table, - defaultState ? [] : cloneState(table.initialState.sorting ?? []), + defaultState ? [] : cloneState(featureTable.initialState.sorting ?? []), ) } @@ -85,9 +90,16 @@ export function column_getAutoSortFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): SortFn { +>(column: Column): SortFn { + const columnDef = column.columnDef as ColumnDef_RowSorting + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > const sortFns: Record> | undefined = - column.table._rowModelFns.sortFns + featureTable._rowModelFns.sortFns as + | Record> + | undefined const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10) @@ -135,7 +147,7 @@ export function column_getAutoSortDir< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { const firstRow = column.table.getFilteredRowModel().flatRows[0] const value = firstRow ? firstRow.getValue(column.id) : undefined @@ -163,15 +175,22 @@ export function column_getSortFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): SortFn { +>(column: Column): SortFn { + const columnDef = column.columnDef as ColumnDef_RowSorting + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > const sortFns: Record> | undefined = - column.table._rowModelFns.sortFns + featureTable._rowModelFns.sortFns as + | Record> + | undefined - return isFunction(column.columnDef.sortFn) - ? column.columnDef.sortFn - : column.columnDef.sortFn === 'auto' + return isFunction(columnDef.sortFn) + ? columnDef.sortFn + : columnDef.sortFn === 'auto' ? column_getAutoSortFn(column) - : (sortFns?.[column.columnDef.sortFn as string] ?? sortFn_basic) + : (sortFns?.[columnDef.sortFn as string] ?? sortFn_basic) } /** @@ -190,11 +209,11 @@ export function column_toggleSorting< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->( - column: Column_Internal, - desc?: boolean, - multi?: boolean, -) { +>(column: Column, desc?: boolean, multi?: boolean) { + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > // if (column.columns.length) { // column.columns.forEach((c, i) => { // if (c.id) { @@ -260,7 +279,7 @@ export function column_toggleSorting< newSorting.splice( 0, newSorting.length - - (column.table.options.maxMultiSortColCount ?? + (featureTable.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER), ) } else if (sortAction === 'toggle') { @@ -304,10 +323,15 @@ export function column_getFirstSortDir< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const columnDef = column.columnDef as ColumnDef_RowSorting + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > const sortDescFirst = - column.columnDef.sortDescFirst ?? - column.table.options.sortDescFirst ?? + columnDef.sortDescFirst ?? + featureTable.options.sortDescFirst ?? column_getAutoSortDir(column) === 'desc' return sortDescFirst ? 'desc' : 'asc' } @@ -327,7 +351,11 @@ export function column_getNextSortingOrder< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal, multi?: boolean) { +>(column: Column, multi?: boolean) { + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > const firstSortDirection = column_getFirstSortDir(column) const isSorted = column_getIsSorted(column) @@ -337,8 +365,8 @@ export function column_getNextSortingOrder< if ( isSorted !== firstSortDirection && - (column.table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general - (multi ? (column.table.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove)) + (featureTable.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general + (multi ? (featureTable.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove)) ) { return false } @@ -360,10 +388,15 @@ export function column_getCanSort< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const columnDef = column.columnDef as ColumnDef_RowSorting + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > return ( - (column.columnDef.enableSorting ?? true) && - (column.table.options.enableSorting ?? true) && + (columnDef.enableSorting ?? true) && + (featureTable.options.enableSorting ?? true) && !!column.accessorFn ) } @@ -383,10 +416,15 @@ export function column_getCanMultiSort< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): boolean { +>(column: Column): boolean { + const columnDef = column.columnDef as ColumnDef_RowSorting + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > return ( - column.columnDef.enableMultiSort ?? - column.table.options.enableMultiSort ?? + columnDef.enableMultiSort ?? + featureTable.options.enableMultiSort ?? !!column.accessorFn ) } @@ -406,8 +444,12 @@ export function column_getIsSorted< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): false | SortDirection { - const columnSort = column.table.atoms.sorting +>(column: Column): false | SortDirection { + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > + const columnSort = featureTable.atoms.sorting ?.get() ?.find((d) => d.id === column.id) return !columnSort ? false : columnSort.desc ? 'desc' : 'asc' @@ -427,9 +469,13 @@ export function column_getSortIndex< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal): number { +>(column: Column): number { + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > return ( - column.table.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ?? + featureTable.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ?? -1 ) } @@ -448,7 +494,7 @@ export function column_clearSorting< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { // clear sorting for just 1 column table_setSorting(column.table, (old) => old.length ? old.filter((d) => d.id !== column.id) : [], @@ -471,7 +517,11 @@ export function column_getToggleSortingHandler< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column_Internal) { +>(column: Column) { + const featureTable = column.table as unknown as Table< + RowSortingFeatures, + TData + > const canSort = column_getCanSort(column) return (e: unknown) => { @@ -482,7 +532,7 @@ export function column_getToggleSortingHandler< undefined, column_getCanMultiSort(column) - ? column.table.options.isMultiSortEvent?.(e) + ? featureTable.options.isMultiSortEvent?.(e) : false, ) } diff --git a/packages/table-core/src/features/stockFeatures.ts b/packages/table-core/src/features/stockFeatures.ts index 3c9f5f4702..ae3961466e 100644 --- a/packages/table-core/src/features/stockFeatures.ts +++ b/packages/table-core/src/features/stockFeatures.ts @@ -12,6 +12,7 @@ import { rowPaginationFeature } from './row-pagination/rowPaginationFeature' import { rowPinningFeature } from './row-pinning/rowPinningFeature' import { rowSelectionFeature } from './row-selection/rowSelectionFeature' import { rowSortingFeature } from './row-sorting/rowSortingFeature' +import type { TableFeature } from '../types/TableFeatures' export interface StockFeatures { columnFacetingFeature: typeof columnFacetingFeature @@ -26,7 +27,7 @@ export interface StockFeatures { rowExpandingFeature: typeof rowExpandingFeature rowPaginationFeature: typeof rowPaginationFeature rowPinningFeature: typeof rowPinningFeature - rowSelectionFeature: typeof rowSelectionFeature + rowSelectionFeature: TableFeature rowSortingFeature: typeof rowSortingFeature } diff --git a/packages/table-core/src/types/Column.ts b/packages/table-core/src/types/Column.ts index 59d12ad91d..aa0a401e9c 100644 --- a/packages/table-core/src/types/Column.ts +++ b/packages/table-core/src/types/Column.ts @@ -8,7 +8,6 @@ import type { Column_ColumnPinning } from '../features/column-pinning/columnPinn import type { Column_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types' import type { Column_ColumnSizing } from '../features/column-sizing/columnSizingFeature.types' import type { Column_ColumnVisibility } from '../features/column-visibility/columnVisibilityFeature.types' -import type { ColumnDefBase_All } from './ColumnDef' import type { RowData } from './type-utils' import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures' import type { Column_Column } from '../core/columns/coreColumnsFeature.types' @@ -41,11 +40,3 @@ export type Column< TValue = unknown, > = Column_Core & ExtractFeatureMapTypes> - -export interface Column_Internal< - in out TFeatures extends TableFeatures, - in out TData extends RowData, - TValue = unknown, -> extends Omit, 'columnDef'> { - columnDef: ColumnDefBase_All -} diff --git a/packages/table-core/src/types/ColumnDef.ts b/packages/table-core/src/types/ColumnDef.ts index ad4c35814b..ba9e969dfc 100644 --- a/packages/table-core/src/types/ColumnDef.ts +++ b/packages/table-core/src/types/ColumnDef.ts @@ -151,22 +151,6 @@ export type ColumnDefBase< ColumnDef_FeatureMap > -export type ColumnDefBase_All< - TFeatures extends TableFeatures, - TData extends RowData, - TValue extends CellData = CellData, -> = ColumnDefBase_Core & - Partial< - ColumnDef_ColumnVisibility & - ColumnDef_ColumnPinning & - ColumnDef_ColumnFiltering & - ColumnDef_GlobalFiltering & - ColumnDef_RowSorting & - ColumnDef_ColumnGrouping & - ColumnDef_ColumnSizing & - ColumnDef_ColumnResizing - > - export type IdentifiedColumnDef< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/types/RowModel.ts b/packages/table-core/src/types/RowModel.ts index 04a413a3dc..2514728612 100644 --- a/packages/table-core/src/types/RowModel.ts +++ b/packages/table-core/src/types/RowModel.ts @@ -1,10 +1,7 @@ import type { CachedRowModel_Faceted } from '../features/column-faceting/columnFacetingFeature.types' import type { CachedRowModel_Grouped } from '../features/column-grouping/columnGroupingFeature.types' import type { CachedRowModel_Filtered } from '../features/column-filtering/columnFilteringFeature.types' -import type { - CachedRowModel_Core, - RowModel, -} from '../core/row-models/coreRowModelsFeature.types' +import type { RowModel } from '../core/row-models/coreRowModelsFeature.types' import type { CachedRowModel_Expanded } from '../features/row-expanding/rowExpandingFeature.types' import type { CachedRowModel_Paginated } from '../features/row-pagination/rowPaginationFeature.types' import type { CachedRowModel_Sorted } from '../features/row-sorting/rowSortingFeature.types' @@ -27,21 +24,8 @@ export type CachedRowModels< TFeatures extends TableFeatures, TData extends RowData, > = { - CachedRowModel_Core: () => RowModel + coreRowModel: () => RowModel } & ExtractFeatureMapTypes< TFeatures, CachedRowModels_FeatureMap > - -export interface CachedRowModel_All< - in out TFeatures extends TableFeatures, - in out TData extends RowData = any, -> extends Partial< - CachedRowModel_Core & - CachedRowModel_Expanded & - CachedRowModel_Faceted & - CachedRowModel_Filtered & - CachedRowModel_Grouped & - CachedRowModel_Paginated & - CachedRowModel_Sorted -> {} diff --git a/packages/table-core/src/types/RowModelFns.ts b/packages/table-core/src/types/RowModelFns.ts index 09faeac541..824effa0cd 100644 --- a/packages/table-core/src/types/RowModelFns.ts +++ b/packages/table-core/src/types/RowModelFns.ts @@ -21,12 +21,3 @@ export type RowModelFns< > = Partial< ExtractFeatureMapTypes> > - -export interface RowModelFns_All< - in out TFeatures extends TableFeatures, - in out TData extends RowData, -> extends Partial< - RowModelFns_ColumnFiltering & - RowModelFns_ColumnGrouping & - RowModelFns_RowSorting -> {} diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index 829b657344..37eb0c9e21 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -14,23 +14,12 @@ import type { Table_RowPagination } from '../features/row-pagination/rowPaginati import type { Table_RowSelection } from '../features/row-selection/rowSelectionFeature.types' import type { Table_RowSorting } from '../features/row-sorting/rowSortingFeature.types' import type { Table_RowModels } from '../core/row-models/coreRowModelsFeature.types' -import type { CachedRowModel_All } from './RowModel' -import type { RowModelFns_All } from './RowModelFns' -import type { TableState, TableState_All } from './TableState' import type { RowData } from './type-utils' import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures' import type { Table_Columns } from '../core/columns/coreColumnsFeature.types' import type { Table_Headers } from '../core/headers/coreHeadersFeature.types' import type { Table_Rows } from '../core/rows/coreRowsFeature.types' -import type { - Atoms, - Atoms_All, - BaseAtoms, - BaseAtoms_All, - ExternalAtoms_All, - Table_Table, -} from '../core/table/coreTablesFeature.types' -import type { DebugOptions, TableOptions_All } from './TableOptions' +import type { Table_Table } from '../core/table/coreTablesFeature.types' /** * The core table object that only includes the core table functionality such as column, header, row, and table APIS. @@ -75,42 +64,3 @@ export type Table< TData extends RowData, > = Table_Core & ExtractFeatureMapTypes> - -/** - * `Table_Table` members that `Table_Internal` re-declares with broadened - * (all-features) types so internal code can read any feature's slots and - * construction code can assign them. - */ -type Table_InternalBroadenedKeys = - | '_rowModels' - | '_rowModelFns' - | 'options' - | 'initialState' - | 'store' - -/** - * Internal broad table shape used by feature implementations. - */ -export interface Table_Internal< - in out TFeatures extends TableFeatures, - in out TData extends RowData = any, -> - extends - Omit, Table_InternalBroadenedKeys>, - Table_Columns, - Table_Rows, - Table_RowModels, - Table_Headers { - _rowModels: CachedRowModel_All - _rowModelFns: RowModelFns_All - options: DebugOptions & - TableOptions_All & { - state?: TableState_All - initialState?: TableState_All - atoms?: ExternalAtoms_All - } - initialState: TableState & TableState_All - baseAtoms: BaseAtoms & BaseAtoms_All - atoms: Atoms & Atoms_All - store: ReadonlyStore> & ReadonlyStore -} diff --git a/packages/table-core/src/types/TableFeatures.ts b/packages/table-core/src/types/TableFeatures.ts index 74d4d2fbe2..d288cf507c 100644 --- a/packages/table-core/src/types/TableFeatures.ts +++ b/packages/table-core/src/types/TableFeatures.ts @@ -1,15 +1,15 @@ import type { CoreFeatures } from '../core/coreFeatures' import type { CellData, RowData, UnionToIntersection } from './type-utils' -import type { ColumnDefBase_All } from './ColumnDef' import type { Row } from './Row' -import type { Table_Internal } from './Table' -import type { TableOptions_All } from './TableOptions' -import type { TableState_All } from './TableState' +import type { Table } from './Table' +import type { TableOptions } from './TableOptions' +import type { TableState } from './TableState' import type { StockFeatures } from '../features/stockFeatures' import type { RowModel } from '../core/row-models/coreRowModelsFeature.types' import type { FilterFn } from '../features/column-filtering/columnFilteringFeature.types' import type { SortFn } from '../features/row-sorting/rowSortingFeature.types' import type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types' +import type { ColumnDefBase } from './ColumnDef' export type IsAny = 0 extends 1 & T ? true : false type UnionToIntersectionOrEmpty = [T] extends [never] @@ -221,75 +221,61 @@ export interface TableFeatures tableMeta?: object } -export interface TableFeature { +export interface TableFeature { /** * Assigns Cell APIs to the cell prototype for memory-efficient method sharing. * This is called once per table to build a shared prototype for all cells. */ - assignCellPrototype?: < - TFeatures extends TableFeatures, - TData extends RowData, - >( + assignCellPrototype?: ( prototype: Record, - table: Table_Internal, + table: Table, ) => void /** * Assigns Column APIs to the column prototype for memory-efficient method sharing. * This is called once per table to build a shared prototype for all columns. */ - assignColumnPrototype?: < - TFeatures extends TableFeatures, - TData extends RowData, - >( + assignColumnPrototype?: ( prototype: Record, - table: Table_Internal, + table: Table, ) => void /** * Assigns Header APIs to the header prototype for memory-efficient method sharing. * This is called once per table to build a shared prototype for all headers. */ - assignHeaderPrototype?: < - TFeatures extends TableFeatures, - TData extends RowData, - >( + assignHeaderPrototype?: ( prototype: Record, - table: Table_Internal, + table: Table, ) => void /** * Assigns Row APIs to the row prototype for memory-efficient method sharing. * This is called once per table to build a shared prototype for all rows. */ - assignRowPrototype?: ( + assignRowPrototype?: ( prototype: Record, - table: Table_Internal, + table: Table, ) => void /** * Assigns Table APIs to the table instance. * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly. */ - constructTableAPIs?: ( - table: Table_Internal, + constructTableAPIs?: ( + table: Table, ) => void getDefaultColumnDef?: < - TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, - >() => ColumnDefBase_All - getDefaultTableOptions?: < - TFeatures extends TableFeatures, - TData extends RowData, - >( - table: Table_Internal, - ) => Partial> - getInitialState?: (initialState: Partial) => TableState_All + >() => ColumnDefBase + getDefaultTableOptions?: ( + table: Table, + ) => Partial> + getInitialState?: ( + initialState: Partial>, + ) => Partial> /** * Initializes instance-specific data on each row (e.g., caches). * Methods should be assigned via assignRowPrototype instead. */ - initRowInstanceData?: < - TFeatures extends TableFeatures, - TData extends RowData, - >( - row: Row, + initRowInstanceData?: ( + row: Row, ) => void } diff --git a/packages/table-core/src/types/TableOptions.ts b/packages/table-core/src/types/TableOptions.ts index 7e8aaba3b7..d15952dd1a 100644 --- a/packages/table-core/src/types/TableOptions.ts +++ b/packages/table-core/src/types/TableOptions.ts @@ -16,7 +16,7 @@ import type { TableOptions_RowPagination } from '../features/row-pagination/rowP import type { TableOptions_RowPinning } from '../features/row-pinning/rowPinningFeature.types' import type { TableOptions_RowSelection } from '../features/row-selection/rowSelectionFeature.types' import type { TableOptions_RowSorting } from '../features/row-sorting/rowSortingFeature.types' -import type { RowData, UnionToIntersection } from './type-utils' +import type { RowData } from './type-utils' import type { ExtractFeatureMapTypes, NonFeatureKeys, @@ -73,43 +73,6 @@ export interface TableOptions_FeatureMap< rowSortingFeature: TableOptions_RowSorting } -type TableOptions_StockFeatureKeys = - | 'columnFilteringFeature' - | 'columnGroupingFeature' - | 'columnOrderingFeature' - | 'columnPinningFeature' - | 'columnResizingFeature' - | 'columnSizingFeature' - | 'columnVisibilityFeature' - | 'globalFilteringFeature' - | 'rowExpandingFeature' - | 'rowPaginationFeature' - | 'rowPinningFeature' - | 'rowSelectionFeature' - | 'rowSortingFeature' - -/** - * Plugin entries declaration-merged into `TableOptions_FeatureMap`, i.e. keys - * beyond the stock set. Resolves to `unknown` (an intersection no-op) when no - * plugins are merged so the common case skips the union-to-intersection work. - */ -type TableOptions_PluginFeatureMapTypes< - TFeatures extends TableFeatures, - TData extends RowData, -> = [ - Exclude< - keyof TableOptions_FeatureMap, - TableOptions_StockFeatureKeys - >, -] extends [never] - ? unknown - : UnionToIntersection< - TableOptions_FeatureMap[Exclude< - keyof TableOptions_FeatureMap, - TableOptions_StockFeatureKeys - >] - > - /** * Complete table options for a specific feature set. * @@ -123,28 +86,3 @@ export type TableOptions< > = TableOptions_Core & ExtractFeatureMapTypes> & DebugOptions - -/** - * Internal broad option shape used where feature code may need to read options - * from features that are not present in the current generic feature set. - */ -export type TableOptions_All< - TFeatures extends TableFeatures, - TData extends RowData, -> = TableOptions_Core & - Partial< - TableOptions_ColumnFiltering & - TableOptions_ColumnGrouping & - TableOptions_ColumnOrdering & - TableOptions_ColumnPinning & - TableOptions_ColumnResizing & - TableOptions_ColumnSizing & - TableOptions_ColumnVisibility & - TableOptions_GlobalFiltering & - TableOptions_RowExpanding & - TableOptions_RowPagination & - TableOptions_RowPinning & - TableOptions_RowSelection & - TableOptions_RowSorting & - TableOptions_PluginFeatureMapTypes - > diff --git a/packages/table-core/src/types/TableState.ts b/packages/table-core/src/types/TableState.ts index e3f0b1eaf0..99c3ffb645 100644 --- a/packages/table-core/src/types/TableState.ts +++ b/packages/table-core/src/types/TableState.ts @@ -37,25 +37,3 @@ export interface TableState_FeatureMap { */ export type TableState = ExtractFeatureMapTypes - -/** - * Internal broad state shape containing every registered feature state slice. - * - * Feature internals use this when they may need to inspect optional slices owned - * by other features. - */ -export interface TableState_All extends Partial< - TableState_ColumnFiltering & - TableState_ColumnGrouping & - TableState_ColumnOrdering & - TableState_ColumnPinning & - TableState_ColumnResizing & - TableState_ColumnSizing & - TableState_ColumnVisibility & - TableState_GlobalFiltering & - TableState_RowExpanding & - TableState_RowPagination & - TableState_RowPinning & - TableState_RowSelection & - TableState_RowSorting -> {} diff --git a/packages/table-core/src/utils.ts b/packages/table-core/src/utils.ts index 4d0e1b4b0e..ed6902cb3e 100755 --- a/packages/table-core/src/utils.ts +++ b/packages/table-core/src/utils.ts @@ -1,7 +1,7 @@ -import type { Table_Internal } from './types/Table' +import type { Table } from './types/Table' import type { NoInfer, RowData, Updater } from './types/type-utils' import type { TableFeatures } from './types/TableFeatures' -import type { TableState, TableState_All } from './types/TableState' +import type { TableState } from './types/TableState' /** * Applies a TanStack updater to a value. @@ -52,12 +52,11 @@ export function cloneState(value: T): T { */ export function makeStateUpdater< TFeatures extends TableFeatures, - K extends (string & {}) | keyof TableState_All | keyof TableState, + K extends (string & {}) | keyof TableState, >( key: K, - // Minimal structural shape so any table view (public `Table`, - // `Table_Internal`, or a custom plugin table) can be passed without forcing - // the compiler to relate the full table types. + // Minimal structural shape so public tables and custom plugin tables can be + // passed without forcing the compiler to relate the full table types. instance: { readonly options: { readonly atoms?: object | undefined } readonly baseAtoms: object @@ -172,7 +171,7 @@ interface TableMemoOptions< fnName: string objectId?: string onAfterUpdate?: () => void - table: Table_Internal + table: Table } const pad = (str: number | string, num: number) => { @@ -353,7 +352,7 @@ export function assignTableAPIs< TDepArgs, >( feature: keyof TFeatures & string, - table: Table_Internal, + table: Table, apis: APIObject>, ): void { for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) { @@ -396,7 +395,7 @@ export function assignPrototypeAPIs< >( feature: keyof TFeatures & string, prototype: Record, - table: Table_Internal, + table: Table, apis: PrototypeAPIObject>, ): void { for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) { diff --git a/packages/table-core/tests/declaration-emit/tableOptions.ts b/packages/table-core/tests/declaration-emit/tableOptions.ts index 9f040fd3e7..ea2faa8f34 100644 --- a/packages/table-core/tests/declaration-emit/tableOptions.ts +++ b/packages/table-core/tests/declaration-emit/tableOptions.ts @@ -12,21 +12,21 @@ const features = tableFeatures({ }) export const optionsWithFeaturesOnly = tableOptions({ - features, + features: features, }) export const optionsWithFeaturesAndData = tableOptions({ - features, + features: features, data: [] as Array, }) export const optionsWithFeaturesAndColumns = tableOptions({ - features, + features: features, columns: [], }) export const optionsWithFeaturesDataAndColumns = tableOptions({ - features, + features: features, data: [] as Array, columns: [], }) diff --git a/packages/table-core/tests/helpers/generateTestTable.ts b/packages/table-core/tests/helpers/generateTestTable.ts index 6bc721ac6e..41e6a665fa 100644 --- a/packages/table-core/tests/helpers/generateTestTable.ts +++ b/packages/table-core/tests/helpers/generateTestTable.ts @@ -4,10 +4,10 @@ import { generateTestData } from '../fixtures/data/generateTestData' import { storeReactivityBindings } from '../../src/store-reactivity-bindings' import type { Row, + Table, TableFeatures, TableOptions, TableState, - Table_Internal, } from '../../src' import type { Person } from '../fixtures/data/types' @@ -19,7 +19,7 @@ export function generateTestTableWithData( > & { features?: TFeatures }, -): Table_Internal { +): Table { const lengthsArray = Array.isArray(lengths) ? lengths : [lengths] const data = generateTestData(...lengthsArray) const columns = generateTestColumnDefs(data) @@ -34,13 +34,13 @@ export function generateTestTableWithData( ...options?.features, coreReactivityFeature: storeReactivityBindings(), }, - } as any) as unknown as Table_Internal + } as any) } export function generateTestTableFromData( data: Array, options?: Omit, 'data' | 'columns'>, -): Table_Internal { +): Table { const columns = generateTestColumnDefs(data) return constructTable({ data, @@ -51,7 +51,7 @@ export function generateTestTableFromData( ...options?.features, coreReactivityFeature: storeReactivityBindings(), }, - } as any) as unknown as Table_Internal + } as any) } export function generateTestTableWithDataAndState< @@ -62,7 +62,7 @@ export function generateTestTableWithDataAndState< TableOptions, 'data' | 'columns' | 'onStateChange' >, -): Table_Internal { +): Table { const lengthsArray = Array.isArray(lengths) ? lengths : [lengths] const data = generateTestData(...lengthsArray) const columns = generateTestColumnDefs(data) @@ -98,7 +98,7 @@ export function generateTestTableWithStateFromData< TableOptions, 'data' | 'columns' | 'onStateChange' >, -): Table_Internal { +): Table { const columns = generateTestColumnDefs(data) let state = { ...options?.initialState } as TableState diff --git a/packages/table-core/tests/helpers/rowPinningHelpers.ts b/packages/table-core/tests/helpers/rowPinningHelpers.ts index 401c57beab..df3664dcf0 100644 --- a/packages/table-core/tests/helpers/rowPinningHelpers.ts +++ b/packages/table-core/tests/helpers/rowPinningHelpers.ts @@ -17,8 +17,8 @@ import type { ColumnDef, RowPinningState, StockFeatures, + Table, TableOptions, - Table_Internal, Table_RowPinning, } from '../../src' import type { Person } from '../fixtures/data/types' @@ -63,8 +63,7 @@ export function createTableWithPinningState( } export function createTableWithMockOnPinningChange(rowCount = 10): { - table: Table_Internal & - Table_RowPinning + table: Table & Table_RowPinning onRowPinningChangeMock: ReturnType } { const onRowPinningChangeMock = vi.fn() @@ -72,7 +71,7 @@ export function createTableWithMockOnPinningChange(rowCount = 10): { features: { rowPinning: rowPinningFeature, }, - } as any) as Table_Internal & + } as any) as Table & Table_RowPinning table.options.onRowPinningChange = onRowPinningChangeMock return { table, onRowPinningChangeMock } diff --git a/packages/table-core/tests/unit/core/cells/constructCell.test.ts b/packages/table-core/tests/unit/core/cells/constructCell.test.ts index e075e0966e..50a8af64ab 100644 --- a/packages/table-core/tests/unit/core/cells/constructCell.test.ts +++ b/packages/table-core/tests/unit/core/cells/constructCell.test.ts @@ -3,7 +3,7 @@ import { constructCell } from '../../../../src/core/cells/constructCell' import { coreCellsFeature } from '../../../../src/core/cells/coreCellsFeature' import type { Row } from '../../../../src/types/Row' import type { Column } from '../../../../src/types/Column' -import type { Table_Internal } from '../../../../src/types/Table' +import type { Table } from '../../../../src/types/Table' type TestData = Record type TestFeatures = { @@ -20,7 +20,7 @@ describe('constructCell', () => { const table = { _features: { coreCellsFeature }, options: {}, - } as unknown as Table_Internal + } as unknown as Table const coreCell = constructCell(column, row, table) expect(coreCell).toBeDefined() diff --git a/packages/table-core/tests/unit/core/columns/constructColumn.test.ts b/packages/table-core/tests/unit/core/columns/constructColumn.test.ts index bd671531f8..bdf8c92d21 100644 --- a/packages/table-core/tests/unit/core/columns/constructColumn.test.ts +++ b/packages/table-core/tests/unit/core/columns/constructColumn.test.ts @@ -4,7 +4,7 @@ import { constructColumn } from '../../../../src/core/columns/constructColumn' import { constructTable } from '../../../../src' import { storeReactivityBindings } from '../../../../src/store-reactivity-bindings' import type { ColumnDef } from '../../../../src/types/ColumnDef' -import type { Table_Internal } from '../../../../src/types/Table' +import type { Table } from '../../../../src/types/Table' const features = { coreColumnsFeature, @@ -21,7 +21,7 @@ describe('constructColumn', () => { features, columns: [], data: [], - }) as unknown as Table_Internal + }) const columnDef = { id: 'test-column', diff --git a/packages/table-core/tests/unit/core/headers/constructHeader.test.ts b/packages/table-core/tests/unit/core/headers/constructHeader.test.ts index 47774b8cdd..ae9114a74e 100644 --- a/packages/table-core/tests/unit/core/headers/constructHeader.test.ts +++ b/packages/table-core/tests/unit/core/headers/constructHeader.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import { coreHeadersFeature } from '../../../../src/core/headers/coreHeadersFeature' import { constructHeader } from '../../../../src/core/headers/constructHeader' import type { Column } from '../../../../src/types/Column' -import type { Table_Internal } from '../../../../src/types/Table' +import type { Table } from '../../../../src/types/Table' type TestData = Record type TestFeatures = { @@ -14,7 +14,7 @@ describe('constructHeader', () => { const table = { _features: { coreHeadersFeature }, options: {}, - } as unknown as Table_Internal + } as unknown as Table const column = { id: 'test-column', columnDef: { id: 'test-column-def' }, diff --git a/packages/table-core/tests/unit/core/rows/constructRow.test.ts b/packages/table-core/tests/unit/core/rows/constructRow.test.ts index d83c60bf9d..21007baf3e 100644 --- a/packages/table-core/tests/unit/core/rows/constructRow.test.ts +++ b/packages/table-core/tests/unit/core/rows/constructRow.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { coreRowsFeature } from '../../../../src/core/rows/coreRowsFeature' import { constructRow } from '../../../../src/core/rows/constructRow' -import type { Table_Internal } from '../../../../src/types/Table' +import type { Table } from '../../../../src/types/Table' import type { Row } from '../../../../src/types/Row' type TestFeatures = { @@ -17,7 +17,7 @@ describe('constructRow', () => { const table = { _features: { coreRowsFeature }, options: {}, - } as unknown as Table_Internal + } as unknown as Table const id = 'test-row' const original = { firstName: 'Tanner' } const rowIndex = 0 diff --git a/packages/table-core/tests/unit/core/tableAtoms.test.ts b/packages/table-core/tests/unit/core/tableAtoms.test.ts index d0f2eb4d23..ce683de0e5 100644 --- a/packages/table-core/tests/unit/core/tableAtoms.test.ts +++ b/packages/table-core/tests/unit/core/tableAtoms.test.ts @@ -11,8 +11,8 @@ import { storeReactivityBindings } from '../../../src/store-reactivity-bindings' import type { PaginationState, SortingState, + Table, TableFeatures, - Table_Internal, Table_RowPagination, Table_RowSorting, } from '../../../src' @@ -25,7 +25,7 @@ const features = { function makeTable( options: any = {}, -): Table_Internal & +): Table & Table_RowSorting & Table_RowPagination { return constructTable({ @@ -37,7 +37,7 @@ function makeTable( columns: [], data: [], ...options, - }) as unknown as Table_Internal & + }) as unknown as Table & Table_RowSorting & Table_RowPagination } diff --git a/packages/table-core/tests/unit/features/column-pinning/columnPinningFeature.utils.test.ts b/packages/table-core/tests/unit/features/column-pinning/columnPinningFeature.utils.test.ts index e50fd05ebd..efb7f703c4 100644 --- a/packages/table-core/tests/unit/features/column-pinning/columnPinningFeature.utils.test.ts +++ b/packages/table-core/tests/unit/features/column-pinning/columnPinningFeature.utils.test.ts @@ -37,9 +37,9 @@ import type { Person } from '../../../fixtures/data/types' import type { Header, StockFeatures, + Table, Table_ColumnOrdering, Table_ColumnPinning, - Table_Internal, } from '../../../../src' describe('getDefaultColumnPinningState', () => { @@ -557,7 +557,7 @@ describe('table_getPinnedLeafColumns', () => { right: [], }, }, - }) as Table_Internal & + }) as Table & Table_ColumnPinning const leafColumns = table_getPinnedLeafColumns(table, 'left') @@ -652,7 +652,7 @@ describe('column pinning table instance APIs', () => { age: false, }, }, - }) as Table_Internal & + }) as Table & Table_ColumnPinning expect( @@ -682,7 +682,7 @@ describe('column pinning table instance APIs', () => { it('should update center visible columns when column order changes', () => { const table = generateTestTableWithDataAndState(1, { features: stockFeatures, - }) as Table_Internal & + }) as Table & Table_ColumnPinning & Table_ColumnOrdering diff --git a/packages/table-core/tsconfig.json b/packages/table-core/tsconfig.json index 44533f71cd..f7c0cd8806 100644 --- a/packages/table-core/tsconfig.json +++ b/packages/table-core/tsconfig.json @@ -1,4 +1,9 @@ { "extends": "../../tsconfig.json", + "compilerOptions": { + "paths": { + "@tanstack/table-core": ["./src/index.ts"] + } + }, "include": ["src", "eslint.config.js", "vite.config.ts", "tests"] }