From b015b472bd4433d257d0548f0564f3d785d3a98e Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Wed, 23 Oct 2024 03:08:52 -0500 Subject: [PATCH] use core apis by builder pattern reference to fix some performance issues --- examples/lit/virtualized-rows/src/main.ts | 4 +- examples/react/pagination/src/main.tsx | 2 +- examples/react/sorting/src/main.tsx | 6 +- packages/table-core/src/core/cells/Cells.ts | 6 +- .../table-core/src/core/cells/Cells.utils.ts | 10 +--- .../table-core/src/core/columns/Columns.ts | 19 +++--- .../src/core/columns/Columns.utils.ts | 21 +++---- .../src/core/columns/constructColumn.ts | 3 +- .../table-core/src/core/headers/Headers.ts | 24 +++++--- .../src/core/headers/Headers.utils.ts | 12 ++-- .../src/core/row-models/createCoreRowModel.ts | 3 +- packages/table-core/src/core/rows/Rows.ts | 5 +- .../table-core/src/core/rows/Rows.utils.ts | 20 +++---- .../table-core/src/core/table/Tables.utils.ts | 2 +- .../createFacetedMinMaxValues.ts | 3 +- .../column-faceting/createFacetedRowModel.ts | 6 +- .../createFacetedUniqueValues.ts | 3 +- .../column-filtering/ColumnFiltering.utils.ts | 10 +--- .../createFilteredRowModel.ts | 7 +-- .../column-grouping/ColumnGrouping.ts | 1 - .../column-grouping/ColumnGrouping.utils.ts | 11 +--- .../column-grouping/createGroupedRowModel.ts | 7 +-- .../column-ordering/ColumnOrdering.ts | 7 +-- .../column-ordering/ColumnOrdering.utils.ts | 10 +--- .../features/column-pinning/ColumnPinning.ts | 60 ++++++++----------- .../column-pinning/ColumnPinning.utils.ts | 43 ++++++------- .../column-resizing/ColumnResizing.utils.ts | 8 +-- .../features/column-sizing/ColumnSizing.ts | 6 +- .../column-sizing/ColumnSizing.utils.ts | 11 +--- .../column-visibility/ColumnVisibility.ts | 11 +--- .../ColumnVisibility.utils.ts | 31 ++++------ .../global-filtering/GlobalFiltering.utils.ts | 3 +- .../row-expanding/RowExpanding.utils.ts | 19 +++--- .../row-expanding/createExpandedRowModel.ts | 5 +- .../row-pagination/RowPagination.utils.ts | 19 ++---- .../row-pagination/createPaginatedRowModel.ts | 8 +-- .../src/features/row-pinning/RowPinning.ts | 15 ++--- .../features/row-pinning/RowPinning.utils.ts | 26 +++----- .../features/row-selection/RowSelection.ts | 7 +-- .../row-selection/RowSelection.utils.ts | 31 ++++------ .../features/row-sorting/RowSorting.utils.ts | 19 ++---- .../row-sorting/createSortedRowModel.ts | 18 ++---- packages/table-core/src/utils.ts | 2 +- 43 files changed, 209 insertions(+), 335 deletions(-) diff --git a/examples/lit/virtualized-rows/src/main.ts b/examples/lit/virtualized-rows/src/main.ts index c878964212..081f325f36 100644 --- a/examples/lit/virtualized-rows/src/main.ts +++ b/examples/lit/virtualized-rows/src/main.ts @@ -11,7 +11,7 @@ import { styleMap } from 'lit/directives/style-map.js' import { Ref, createRef, ref } from 'lit/directives/ref.js' import { VirtualizerController } from '@tanstack/lit-virtual' import { Person, makeData } from './makeData.ts' -import type { ColumnDef, Row } from '@tanstack/lit-table' +import type { ColumnDef } from '@tanstack/lit-table' const columns: Array> = [ { @@ -149,7 +149,7 @@ class LitTableExample extends LitElement { .getVirtualItems(), (item) => item.key, (item) => { - const row = rows[item.index] as Row + const row = rows[item.index] return html` - , - // , + + + , ) diff --git a/packages/table-core/src/core/cells/Cells.ts b/packages/table-core/src/core/cells/Cells.ts index 23bdfa530e..06368f0c74 100644 --- a/packages/table-core/src/core/cells/Cells.ts +++ b/packages/table-core/src/core/cells/Cells.ts @@ -1,8 +1,8 @@ import { assignAPIs } from '../../utils' import { cell_getContext, cell_getValue, cell_renderValue } from './Cells.utils' +import type { Table_Internal } from '../../types/Table' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' import type { Cell } from '../../types/Cell' export const Cells: TableFeature = { @@ -12,11 +12,11 @@ export const Cells: TableFeature = { TValue extends CellData = CellData, >( cell: Cell, - table: Table, + table: Table_Internal, ) => { assignAPIs(cell, table, [ { - fn: () => cell_getValue(cell, table) as any, + fn: () => cell_getValue(cell), }, { fn: () => cell_renderValue(cell, table), diff --git a/packages/table-core/src/core/cells/Cells.utils.ts b/packages/table-core/src/core/cells/Cells.utils.ts index 1b4d3bfb3c..98a2137411 100644 --- a/packages/table-core/src/core/cells/Cells.utils.ts +++ b/packages/table-core/src/core/cells/Cells.utils.ts @@ -1,4 +1,3 @@ -import { row_getValue } from '../rows/Rows.utils' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -8,11 +7,8 @@ export function cell_getValue< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->( - cell: Cell, - table: Table, -): TValue { - return row_getValue(cell.row, table, cell.column.id) as TValue +>(cell: Cell): TValue { + return cell.row.getValue(cell.column.id) } export function cell_renderValue< @@ -20,7 +16,7 @@ export function cell_renderValue< TData extends RowData, TValue extends CellData = CellData, >(cell: Cell, table: Table) { - return cell_getValue(cell, table) ?? table.options.renderFallbackValue + return cell.getValue() ?? table.options.renderFallbackValue } export function cell_getContext< diff --git a/packages/table-core/src/core/columns/Columns.ts b/packages/table-core/src/core/columns/Columns.ts index 1daeae209f..acfa564743 100644 --- a/packages/table-core/src/core/columns/Columns.ts +++ b/packages/table-core/src/core/columns/Columns.ts @@ -1,18 +1,17 @@ import { assignAPIs } from '../../utils' -import { table_getState } from '../table/Tables.utils' import { column_getFlatColumns, column_getLeafColumns, - tableGetDefaultColumnDef, table_getAllColumns, table_getAllFlatColumns, table_getAllFlatColumnsById, table_getAllLeafColumns, table_getColumn, + table_getDefaultColumnDef, } from './Columns.utils' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' export const Columns: TableFeature = { @@ -22,7 +21,7 @@ export const Columns: TableFeature = { TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, ) => { assignAPIs(column, table, [ { @@ -32,8 +31,8 @@ export const Columns: TableFeature = { { fn: () => column_getLeafColumns(column, table), memoDeps: () => [ - table_getState(table).columnOrder, - table_getState(table).grouping, + table.getState().columnOrder, + table.getState().grouping, table.options.columns, table.options.groupedColumnMode, ], @@ -42,11 +41,11 @@ export const Columns: TableFeature = { }, constructTable: ( - table: Table, + table: Table_Internal, ) => { assignAPIs(table, table, [ { - fn: () => tableGetDefaultColumnDef(table), + fn: () => table_getDefaultColumnDef(table), memoDeps: () => [table.options.defaultColumn], }, { @@ -64,8 +63,8 @@ export const Columns: TableFeature = { { fn: () => table_getAllLeafColumns(table), memoDeps: () => [ - table_getState(table).columnOrder, - table_getState(table).grouping, + table.getState().columnOrder, + table.getState().grouping, table.options.columns, table.options.groupedColumnMode, ], diff --git a/packages/table-core/src/core/columns/Columns.utils.ts b/packages/table-core/src/core/columns/Columns.utils.ts index 28f7b16d48..12e81fdb82 100644 --- a/packages/table-core/src/core/columns/Columns.utils.ts +++ b/packages/table-core/src/core/columns/Columns.utils.ts @@ -17,10 +17,7 @@ export function column_getFlatColumns< >( column: Column, ): Array> { - return [ - column, - ...column.columns.flatMap((col) => column_getFlatColumns(col)), - ] + return [column, ...column.columns.flatMap((col) => col.getFlatColumns())] } export function column_getLeafColumns< @@ -33,7 +30,7 @@ export function column_getLeafColumns< ): Array> { if (column.columns.length) { const leafColumns = column.columns.flatMap( - (col) => column_getLeafColumns(col, table), // recursive + (col) => col.getLeafColumns(), // recursive ) return table_getOrderColumnsFn(table)(leafColumns) as any @@ -42,7 +39,7 @@ export function column_getLeafColumns< return [column] } -export function tableGetDefaultColumnDef< +export function table_getDefaultColumnDef< TFeatures extends TableFeatures, TData extends RowData, >( @@ -104,9 +101,7 @@ export function table_getAllFlatColumns< TFeatures extends TableFeatures, TData extends RowData, >(table: Table): Array> { - return table_getAllColumns(table).flatMap((column) => - column_getFlatColumns(column), - ) + return table.getAllColumns().flatMap((column) => column.getFlatColumns()) } export function table_getAllFlatColumnsById< @@ -115,7 +110,7 @@ export function table_getAllFlatColumnsById< >( table: Table, ): Record> { - return table_getAllFlatColumns(table).reduce( + return table.getAllFlatColumns().reduce( (acc, column) => { acc[column.id] = column return acc @@ -128,8 +123,8 @@ export function table_getAllLeafColumns< TFeatures extends TableFeatures, TData extends RowData, >(table: Table): Array> { - const leafColumns = table_getAllColumns(table).flatMap( - (c) => column_getLeafColumns(c, table), // recursive + const leafColumns = table.getAllColumns().flatMap( + (c) => c.getLeafColumns(), // recursive ) return table_getOrderColumnsFn(table)(leafColumns) } @@ -141,7 +136,7 @@ export function table_getColumn< table: Table, columnId: string, ): Column | undefined { - const column = table_getAllFlatColumnsById(table)[columnId] + const column = table.getAllFlatColumnsById()[columnId] if (process.env.NODE_ENV !== 'production' && !column) { console.warn(`[Table] Column with id '${columnId}' does not exist.`) diff --git a/packages/table-core/src/core/columns/constructColumn.ts b/packages/table-core/src/core/columns/constructColumn.ts index 104f578b35..ae42dbc221 100644 --- a/packages/table-core/src/core/columns/constructColumn.ts +++ b/packages/table-core/src/core/columns/constructColumn.ts @@ -1,4 +1,3 @@ -import { tableGetDefaultColumnDef } from './Columns.utils' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -20,7 +19,7 @@ export function constructColumn< depth: number, parent?: Column, ): Column { - const defaultColumn = tableGetDefaultColumnDef(table) + const defaultColumn = table.getDefaultColumnDef() const resolvedColumnDef = { ...defaultColumn, diff --git a/packages/table-core/src/core/headers/Headers.ts b/packages/table-core/src/core/headers/Headers.ts index 66fc87df5d..0537346a01 100644 --- a/packages/table-core/src/core/headers/Headers.ts +++ b/packages/table-core/src/core/headers/Headers.ts @@ -1,5 +1,4 @@ import { assignAPIs } from '../../utils' -import { table_getState } from '../table/Tables.utils' import { table_getCenterHeaderGroups, table_getLeftHeaderGroups, @@ -27,9 +26,16 @@ export const Headers: TableFeature = { header: Header, table: Table, ): void => { - header.getLeafHeaders = () => header_getLeafHeaders(header) - - header.getContext = () => header_getContext(header, table) + assignAPIs(header, table, [ + { + fn: () => header_getLeafHeaders(header), + memoDeps: () => [table.options.columns], + }, + { + fn: () => header_getContext(header, table), + memoDeps: () => [table.options.columns], + }, + ]) }, constructTable: ( @@ -40,19 +46,19 @@ export const Headers: TableFeature = { fn: () => table_getHeaderGroups(table), memoDeps: () => [ table.options.columns, - table_getState(table).columnOrder, - table_getState(table).grouping, - table_getState(table).columnPinning, + table.getState().columnOrder, + table.getState().grouping, + table.getState().columnPinning, table.options.groupedColumnMode, ], }, { fn: () => table_getFooterGroups(table), - memoDeps: () => [table_getHeaderGroups(table)], + memoDeps: () => [table.getHeaderGroups()], }, { fn: () => table_getFlatHeaders(table), - memoDeps: () => [table_getHeaderGroups(table)], + memoDeps: () => [table.getHeaderGroups()], }, { fn: () => table_getLeafHeaders(table), diff --git a/packages/table-core/src/core/headers/Headers.utils.ts b/packages/table-core/src/core/headers/Headers.utils.ts index 181a5cee67..e830c31ddd 100644 --- a/packages/table-core/src/core/headers/Headers.utils.ts +++ b/packages/table-core/src/core/headers/Headers.utils.ts @@ -1,12 +1,10 @@ -import { table_getAllColumns } from '../columns/Columns.utils' -import { table_getVisibleLeafColumns } from '../../features/column-visibility/ColumnVisibility.utils' -import { table_getState } from '../table/Tables.utils' import { getDefaultColumnPinningState, table_getCenterHeaderGroups, table_getLeftHeaderGroups, table_getRightHeaderGroups, } from '../../features/column-pinning/ColumnPinning.utils' +import { table_getVisibleLeafColumns } from '../../features/column-visibility/ColumnVisibility.utils' import { buildHeaderGroups } from './buildHeaderGroups' import type { Header } from '../../types/Header' import type { RowData } from '../../types/type-utils' @@ -50,8 +48,8 @@ export function table_getHeaderGroups< TData extends RowData, >(table: Table) { const { left, right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() - const allColumns = table_getAllColumns(table) + table.getState().columnPinning ?? getDefaultColumnPinningState() + const allColumns = table.getAllColumns() const leafColumns = table_getVisibleLeafColumns(table) const leftColumns = left @@ -79,7 +77,7 @@ export function table_getFooterGroups< TFeatures extends TableFeatures, TData extends RowData, >(table: Table) { - const headerGroups = table_getHeaderGroups(table) + const headerGroups = table.getHeaderGroups() return [...headerGroups].reverse() } @@ -87,7 +85,7 @@ export function table_getFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, >(table: Table) { - const headerGroups = table_getHeaderGroups(table) + const headerGroups = table.getHeaderGroups() return headerGroups .map((headerGroup) => { return headerGroup.headers diff --git a/packages/table-core/src/core/row-models/createCoreRowModel.ts b/packages/table-core/src/core/row-models/createCoreRowModel.ts index 1906a7894a..a11141b371 100644 --- a/packages/table-core/src/core/row-models/createCoreRowModel.ts +++ b/packages/table-core/src/core/row-models/createCoreRowModel.ts @@ -1,6 +1,5 @@ import { constructRow } from '../rows/constructRow' import { isDev, tableMemo } from '../../utils' -import { table_getRowId } from '../rows/Rows.utils' import { table_autoResetPageIndex } from '../../features/row-pagination/RowPagination.utils' import type { RowModel } from './RowModels.types' import type { RowData } from '../../types/type-utils' @@ -52,7 +51,7 @@ function _createCoreRowModel< // Make the row const row = constructRow( table, - table_getRowId(originalRow, table, i, parentRow), + table.getRowId(originalRow, i, parentRow), originalRow, i, depth, diff --git a/packages/table-core/src/core/rows/Rows.ts b/packages/table-core/src/core/rows/Rows.ts index 031d8f3e5b..7e4a96f672 100644 --- a/packages/table-core/src/core/rows/Rows.ts +++ b/packages/table-core/src/core/rows/Rows.ts @@ -1,5 +1,4 @@ import { assignAPIs } from '../../utils' -import { table_getAllLeafColumns } from '../columns/Columns.utils' import { row_getAllCells, row_getAllCellsByColumnId, @@ -25,11 +24,11 @@ export const Rows: TableFeature = { assignAPIs(row, table, [ { fn: () => row_getAllCellsByColumnId(row, table), - memoDeps: () => [row_getAllCells(row, table)], + memoDeps: () => [row.getAllCells()], }, { fn: () => row_getAllCells(row, table), - memoDeps: () => [table_getAllLeafColumns(table)], + memoDeps: () => [table.getAllLeafColumns()], }, { fn: () => row_getLeafRows(row), diff --git a/packages/table-core/src/core/rows/Rows.utils.ts b/packages/table-core/src/core/rows/Rows.utils.ts index 65e5818967..0b7fb557c4 100644 --- a/packages/table-core/src/core/rows/Rows.utils.ts +++ b/packages/table-core/src/core/rows/Rows.utils.ts @@ -1,9 +1,5 @@ import { flattenBy } from '../../utils' import { constructCell } from '../cells/constructCell' -import { - table_getAllLeafColumns, - table_getColumn, -} from '../columns/Columns.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -22,7 +18,7 @@ export function row_getValue< return row._valuesCache[columnId] } - const column = table_getColumn(table, columnId) + const column = table.getColumn(columnId) if (!column?.accessorFn) { return undefined @@ -45,14 +41,14 @@ export function row_getUniqueValues< return row._uniqueValuesCache[columnId] } - const column = table_getColumn(table, columnId) + const column = table.getColumn(columnId) if (!column?.accessorFn) { return undefined } if (!column.columnDef.getUniqueValues) { - row._uniqueValuesCache[columnId] = [row_getValue(row, table, columnId)] + row._uniqueValuesCache[columnId] = [row.getValue(columnId)] return row._uniqueValuesCache[columnId] } @@ -72,7 +68,7 @@ export function row_renderValue< table: Table, columnId: string, ) { - return row_getValue(row, table, columnId) ?? table.options.renderFallbackValue + return row.getValue(columnId) ?? table.options.renderFallbackValue } export function row_getLeafRows< @@ -86,7 +82,7 @@ export function row_getParentRow< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table) { - return row.parentId ? table_getRow(table, row.parentId, true) : undefined + return row.parentId ? table.getRow(row.parentId, true) : undefined } export function row_getParentRows< @@ -97,7 +93,7 @@ export function row_getParentRows< let currentRow = row // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition while (true) { - const parentRow = row_getParentRow(currentRow, table) + const parentRow = currentRow.getParentRow() if (!parentRow) break parentRows.push(parentRow) currentRow = parentRow @@ -112,7 +108,7 @@ export function row_getAllCells< row: Row, table: Table, ): Array> { - return table_getAllLeafColumns(table).map((column) => { + return table.getAllLeafColumns().map((column) => { return constructCell(column, row, table) }) } @@ -121,7 +117,7 @@ export function row_getAllCellsByColumnId< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table) { - return row_getAllCells(row, table).reduce( + return row.getAllCells().reduce( (acc, cell) => { acc[cell.column.id] = cell return acc diff --git a/packages/table-core/src/core/table/Tables.utils.ts b/packages/table-core/src/core/table/Tables.utils.ts index c0bf2d7941..4e4bae5351 100644 --- a/packages/table-core/src/core/table/Tables.utils.ts +++ b/packages/table-core/src/core/table/Tables.utils.ts @@ -9,7 +9,7 @@ export function table_reset< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal): void { - table_setState(table, table.initialState) + table.setState(table.initialState) } export function table_mergeOptions< diff --git a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts index 1b1bb43301..16e9201c4d 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedMinMaxValues.ts @@ -1,5 +1,4 @@ import { isDev, tableMemo } from '../../utils' -import { row_getUniqueValues } from '../../core/rows/Rows.utils' import { column_getFacetedRowModel } from './ColumnFaceting.utils' import type { RowModel } from '../../core/row-models/RowModels.types' import type { RowData } from '../../types/type-utils' @@ -36,7 +35,7 @@ function _createFacetedMinMaxValues< if (!facetedRowModel) return undefined const uniqueValues = facetedRowModel.flatRows - .flatMap((flatRow) => row_getUniqueValues(flatRow, table, columnId) ?? []) + .flatMap((flatRow) => flatRow.getUniqueValues(columnId) ?? []) .map(Number) .filter((value) => !Number.isNaN(value)) diff --git a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts index 401bd50029..b1a2c87b87 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts @@ -1,6 +1,6 @@ import { isDev, tableMemo } from '../../utils' import { filterRows } from '../column-filtering/filterRowsUtils' -import { table_getState } from '../../core/table/Tables.utils' + import type { ColumnFiltersState } from '../column-filtering/ColumnFiltering.types' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' @@ -21,8 +21,8 @@ export function createFacetedRowModel< fnName: 'createFacetedRowModel', memoDeps: () => [ table.getPreFilteredRowModel(), - table_getState(table).columnFilters, - table_getState(table).globalFilter, + table.getState().columnFilters, + table.getState().globalFilter, table.getFilteredRowModel(), ], fn: (preRowModel, columnFilters, globalFilter) => diff --git a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts index 440e318aa5..afc61984e1 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedUniqueValues.ts @@ -1,5 +1,4 @@ import { isDev, tableMemo } from '../../utils' -import { row_getUniqueValues } from '../../core/rows/Rows.utils' import { column_getFacetedRowModel } from './ColumnFaceting.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' @@ -37,7 +36,7 @@ function _createFacetedUniqueValues< const facetedUniqueValues = new Map() for (const row of facetedRowModel.flatRows) { - const values = row_getUniqueValues(row, table, columnId) + const values = row.getUniqueValues(columnId) for (const value of values) { if (facetedUniqueValues.has(value)) { diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts index 18956d6d7d..142fec7649 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts @@ -1,6 +1,4 @@ import { functionalUpdate, isFunction } from '../../utils' -import { row_getValue } from '../../core/rows/Rows.utils' -import { table_getState } from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -29,7 +27,7 @@ export function column_getAutoFilterFn< const firstRow = table.getCoreRowModel().flatRows[0] - const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined + const value = firstRow ? firstRow.getValue(column.id) : undefined if (typeof value === 'string') { return filterFns?.includesString @@ -115,8 +113,7 @@ export function column_getFilterValue< }, table: Table_Internal, ) { - return table_getState(table).columnFilters?.find((d) => d.id === column.id) - ?.value + return table.getState().columnFilters?.find((d) => d.id === column.id)?.value } export function column_getFilterIndex< @@ -130,8 +127,7 @@ export function column_getFilterIndex< table: Table_Internal, ): number { return ( - table_getState(table).columnFilters?.findIndex((d) => d.id === column.id) ?? - -1 + table.getState().columnFilters?.findIndex((d) => d.id === column.id) ?? -1 ) } diff --git a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts index 38e314eabc..78a6a9eb64 100644 --- a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts +++ b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts @@ -4,7 +4,6 @@ import { column_getCanGlobalFilter, table_getGlobalFilterFn, } from '../global-filtering/GlobalFiltering.utils' -import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' import { filterRows } from './filterRowsUtils' import { column_getFilterFn } from './ColumnFiltering.utils' @@ -28,8 +27,8 @@ export function createFilteredRowModel< fnName: 'table.getFilteredRowModel', memoDeps: () => [ table.getPreFilteredRowModel(), - table_getState(table).columnFilters, - table_getState(table).globalFilter, + table.getState().columnFilters, + table.getState().globalFilter, ], fn: () => _createFilteredRowModel(table), onAfterUpdate: () => table_autoResetPageIndex(table), @@ -41,7 +40,7 @@ function _createFilteredRowModel< TData extends RowData, >(table: Table): RowModel { const rowModel = table.getPreFilteredRowModel() - const { columnFilters, globalFilter } = table_getState(table) + const { columnFilters, globalFilter } = table.getState() if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) { for (const row of rowModel.flatRows) { diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts index fb22d2c613..801a4af009 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts @@ -27,7 +27,6 @@ import type { Cell_ColumnGrouping, ColumnDef_ColumnGrouping, Column_ColumnGrouping, - Row_ColumnGrouping, TableOptions_ColumnGrouping, TableState_ColumnGrouping, Table_ColumnGrouping, diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts index 5a577825e6..54c61d0847 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts @@ -1,12 +1,7 @@ import { isFunction } from '../../utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import { table_getColumn } from '../../core/columns/Columns.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { RowModel } from '../../core/row-models/RowModels.types' import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' @@ -67,7 +62,7 @@ export function column_getIsGrouped< }, table: Table_Internal, ): boolean { - return !!table_getState(table).grouping?.includes(column.id) + return !!table.getState().grouping?.includes(column.id) } export function column_getGroupedIndex< @@ -80,7 +75,7 @@ export function column_getGroupedIndex< }, table: Table_Internal, ): number { - return table_getState(table).grouping?.indexOf(column.id) ?? -1 + return table.getState().grouping?.indexOf(column.id) ?? -1 } export function column_getToggleGroupingHandler< @@ -162,7 +157,7 @@ export function table_resetGrouping< >(table: Table_Internal, defaultState?: boolean) { table_setGrouping( table, - defaultState ? [] : (table_getInitialState(table).grouping ?? []), + defaultState ? [] : (table.options.initialState.grouping ?? []), ) } diff --git a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts index a2e2d473b1..26a7874e5f 100644 --- a/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts +++ b/packages/table-core/src/features/column-grouping/createGroupedRowModel.ts @@ -1,7 +1,6 @@ import { flattenBy, isDev, tableMemo } from '../../utils' import { constructRow } from '../../core/rows/constructRow' import { table_getColumn } from '../../core/columns/Columns.utils' -import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetExpanded } from '../row-expanding/RowExpanding.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' import { row_getGroupingValue } from './ColumnGrouping.utils' @@ -20,7 +19,7 @@ export function createGroupedRowModel< debug: isDev && (table.options.debugAll ?? table.options.debugTable), fnName: 'table.getGroupedRowModel', memoDeps: () => [ - table_getState(table).grouping, + table.getState().grouping, table.getPreGroupedRowModel(), ], fn: () => _createGroupedRowModel(table), @@ -36,7 +35,7 @@ function _createGroupedRowModel< TData extends RowData, >(table: Table): RowModel { const rowModel = table.getPreGroupedRowModel() - const grouping = table_getState(table).grouping + const grouping = table.getState().grouping if (!rowModel.rows.length || !grouping?.length) { rowModel.rows.forEach((row) => { @@ -69,7 +68,7 @@ function _createGroupedRowModel< groupedFlatRows.push(row) groupedRowsById[row.id] = row - if (row.subRows) { + if (row.subRows.length) { row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id) } diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.ts index 0aa4b3f3ab..1b950630fa 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.ts @@ -1,5 +1,4 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' import { column_getIndex, column_getIsFirstColumn, @@ -61,9 +60,9 @@ export const ColumnOrdering: TableFeature = { fn: (position) => column_getIndex(column, table, position), memoDeps: (position) => [ position, - table_getState(table).columnOrder, - table_getState(table).columnPinning, - table_getState(table).grouping, + table.getState().columnOrder, + table.getState().columnPinning, + table.getState().grouping, ], }, { diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts index d5a7d8d29d..de1ccbe509 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts @@ -1,8 +1,4 @@ import { column_getVisibleLeafColumns } from '../column-visibility/ColumnVisibility.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -66,7 +62,7 @@ export function table_resetColumnOrder< >(table: Table_Internal, defaultState?: boolean) { table_setColumnOrder( table, - defaultState ? [] : (table_getInitialState(table).columnOrder ?? []), + defaultState ? [] : (table.options.initialState?.columnOrder ?? []), ) } @@ -74,7 +70,7 @@ export function table_getOrderColumnsFn< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const { columnOrder = [] } = table_getState(table) + const { columnOrder = [] } = table.getState() return (columns: Array>) => { // Sort grouped columns to the start of the column list @@ -116,7 +112,7 @@ export function orderColumns< table: Table_Internal, leafColumns: Array>, ) { - const { grouping = [] } = table_getState(table) + const { grouping = [] } = table.getState() const { groupedColumnMode } = table.options if (!grouping.length || !groupedColumnMode) { diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.ts index 24be2e1e2f..c48f94a9eb 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.ts @@ -1,8 +1,5 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' import { table_getVisibleLeafColumns } from '../column-visibility/ColumnVisibility.utils' -import { table_getAllColumns } from '../../core/columns/Columns.utils' -import { row_getAllCells } from '../../core/rows/Rows.utils' import { column_getCanPin, column_getIsPinned, @@ -109,25 +106,25 @@ export const ColumnPinning: TableFeature = { { fn: () => row_getCenterVisibleCells(row, table), memoDeps: () => [ - row_getAllCells(row, table), - table_getState(table).columnPinning, - table_getState(table).columnVisibility, + row.getAllCells(), + table.getState().columnPinning, + table.getState().columnVisibility, ], }, { fn: () => row_getLeftVisibleCells(row, table), memoDeps: () => [ - row_getAllCells(row, table), - table_getState(table).columnPinning?.left, - table_getState(table).columnVisibility, + row.getAllCells(), + table.getState().columnPinning?.left, + table.getState().columnVisibility, ], }, { fn: () => row_getRightVisibleCells(row, table), memoDeps: () => [ - row_getAllCells(row, table), - table_getState(table).columnPinning?.right, - table_getState(table).columnVisibility, + row.getAllCells(), + table.getState().columnPinning?.right, + table.getState().columnVisibility, ], }, ]) @@ -151,25 +148,25 @@ export const ColumnPinning: TableFeature = { { fn: () => table_getLeftHeaderGroups(table), memoDeps: () => [ - table_getAllColumns(table), + table.getAllColumns(), table_getVisibleLeafColumns(table), - table_getState(table).columnPinning?.left, + table.getState().columnPinning?.left, ], }, { fn: () => table_getCenterHeaderGroups(table), memoDeps: () => [ - table_getAllColumns(table), + table.getAllColumns(), table_getVisibleLeafColumns(table), - table_getState(table).columnPinning, + table.getState().columnPinning, ], }, { fn: () => table_getRightHeaderGroups(table), memoDeps: () => [ - table_getAllColumns(table), + table.getAllColumns(), table_getVisibleLeafColumns(table), - table_getState(table).columnPinning?.right, + table.getState().columnPinning?.right, ], }, // footer groups @@ -214,48 +211,39 @@ export const ColumnPinning: TableFeature = { // leaf columns { fn: () => table_getLeftLeafColumns(table), - memoDeps: () => [ - table.options.columns, - table_getState(table).columnPinning, - ], + memoDeps: () => [table.options.columns, table.getState().columnPinning], }, { fn: () => table_getRightLeafColumns(table), - memoDeps: () => [ - table.options.columns, - table_getState(table).columnPinning, - ], + memoDeps: () => [table.options.columns, table.getState().columnPinning], }, { fn: () => table_getCenterLeafColumns(table), - memoDeps: () => [ - table.options.columns, - table_getState(table).columnPinning, - ], + memoDeps: () => [table.options.columns, table.getState().columnPinning], }, // visible leaf columns { fn: () => table_getLeftVisibleLeafColumns(table), memoDeps: () => [ table.options.columns, - table_getState(table).columnPinning, - table_getState(table).columnVisibility, + table.getState().columnPinning, + table.getState().columnVisibility, ], }, { fn: () => table_getCenterVisibleLeafColumns(table), memoDeps: () => [ table.options.columns, - table_getState(table).columnPinning, - table_getState(table).columnVisibility, + table.getState().columnPinning, + table.getState().columnVisibility, ], }, { fn: () => table_getRightVisibleLeafColumns(table), memoDeps: () => [ table.options.columns, - table_getState(table).columnPinning, - table_getState(table).columnVisibility, + table.getState().columnPinning, + table.getState().columnVisibility, ], }, ]) diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts index 27c9f33faa..7bfb564bcf 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts @@ -3,11 +3,6 @@ import { row_getAllVisibleCells, table_getVisibleLeafColumns, } from '../column-visibility/ColumnVisibility.utils' -import { table_getAllColumns } from '../../core/columns/Columns.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import { buildHeaderGroups } from '../../core/headers/buildHeaderGroups' import type { Row } from '../../types/Row' import type { CellData, RowData, Updater } from '../../types/type-utils' @@ -102,7 +97,7 @@ export function column_getIsPinned< const leafColumnIds = column.getLeafColumns().map((d) => d.id) const { left, right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const isLeft = leafColumnIds.some((d) => left.includes(d)) const isRight = leafColumnIds.some((d) => right.includes(d)) @@ -121,7 +116,7 @@ export function column_getPinnedIndex< const position = column_getIsPinned(column, table) return position - ? (table_getState(table).columnPinning?.[position].indexOf(column.id) ?? -1) + ? (table.getState().columnPinning?.[position].indexOf(column.id) ?? -1) : 0 } @@ -131,7 +126,7 @@ export function row_getCenterVisibleCells< >(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { left, right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] return allCells.filter((d) => !leftAndRight.includes(d.column.id)) } @@ -142,7 +137,7 @@ export function row_getLeftVisibleCells< >(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { left } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const cells = left .map((columnId) => allCells.find((cell) => cell.column.id === columnId)!) .filter(Boolean) @@ -157,7 +152,7 @@ export function row_getRightVisibleCells< >(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const cells = right .map((columnId) => allCells.find((cell) => cell.column.id === columnId)!) .filter(Boolean) @@ -184,7 +179,7 @@ export function table_resetColumnPinning< table, defaultState ? getDefaultColumnPinningState() - : (table_getInitialState(table).columnPinning ?? + : (table.options.initialState?.columnPinning ?? getDefaultColumnPinningState()), ) } @@ -193,7 +188,7 @@ export function table_getIsSomeColumnsPinned< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal, position?: ColumnPinningPosition) { - const pinningState = table_getState(table).columnPinning + const pinningState = table.getState().columnPinning if (!position) { return Boolean(pinningState?.left.length || pinningState?.right.length) @@ -207,10 +202,10 @@ export function table_getLeftHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const allColumns = table_getAllColumns(table) + const allColumns = table.getAllColumns() const leafColumns = table_getVisibleLeafColumns(table) const { left } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const orderedLeafColumns = left .map((columnId) => leafColumns.find((d) => d.id === columnId)!) @@ -223,10 +218,10 @@ export function table_getRightHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const allColumns = table_getAllColumns(table) + const allColumns = table.getAllColumns() const leafColumns = table_getVisibleLeafColumns(table) const { right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const orderedLeafColumns = right .map((columnId) => leafColumns.find((d) => d.id === columnId)!) @@ -239,10 +234,10 @@ export function table_getCenterHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const allColumns = table_getAllColumns(table) + const allColumns = table.getAllColumns() let leafColumns = table_getVisibleLeafColumns(table) const { left, right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] leafColumns = leafColumns.filter( @@ -351,11 +346,11 @@ export function table_getLeftLeafColumns< TData extends RowData, >(table: Table_Internal) { const { left } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() return left .map( (columnId) => - table_getAllColumns(table).find((column) => column.id === columnId)!, + table.getAllColumns().find((column) => column.id === columnId)!, ) .filter(Boolean) } @@ -365,11 +360,11 @@ export function table_getRightLeafColumns< TData extends RowData, >(table: Table_Internal) { const { right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() return right .map( (columnId) => - table_getAllColumns(table).find((column) => column.id === columnId)!, + table.getAllColumns().find((column) => column.id === columnId)!, ) .filter(Boolean) } @@ -379,9 +374,9 @@ export function table_getCenterLeafColumns< TData extends RowData, >(table: Table_Internal) { const { left, right } = - table_getState(table).columnPinning ?? getDefaultColumnPinningState() + table.getState().columnPinning ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] - return table_getAllColumns(table).filter((d) => !leftAndRight.includes(d.id)) + return table.getAllColumns().filter((d) => !leftAndRight.includes(d.id)) } // visible leaf columns diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts index b052de6ff2..fe6653aef4 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts @@ -4,10 +4,6 @@ import { table_setColumnSizing, } from '../column-sizing/ColumnSizing.utils' import { table_getColumn } from '../../core/columns/Columns.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -56,7 +52,7 @@ export function column_getIsResizing< }, table: Table_Internal, ) { - return table_getState(table).columnResizing?.isResizingColumn === column.id + return table.getState().columnResizing?.isResizingColumn === column.id } export function header_getResizeHandler< @@ -252,7 +248,7 @@ export function table_resetHeaderSizeInfo< table, defaultState ? getDefaultColumnResizingState() - : (table_getInitialState(table).columnResizing ?? + : (table.options.initialState?.columnResizing ?? getDefaultColumnResizingState()), ) } diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.ts index b1d5aa7023..a52971efe0 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.ts @@ -1,6 +1,6 @@ import { assignAPIs, makeStateUpdater } from '../../utils' import { column_getVisibleLeafColumns } from '../column-visibility/ColumnVisibility.utils' -import { table_getState } from '../../core/table/Tables.utils' + import { column_getAfter, column_getSize, @@ -80,7 +80,7 @@ export const ColumnSizing: TableFeature = { memoDeps: (position) => [ position, column_getVisibleLeafColumns(table, position), - table_getState(table).columnSizing, + table.getState().columnSizing, ], }, { @@ -88,7 +88,7 @@ export const ColumnSizing: TableFeature = { memoDeps: (position) => [ position, column_getVisibleLeafColumns(table, position), - table_getState(table).columnSizing, + table.getState().columnSizing, ], }, { diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts index 88d4d04b3c..40819e42c5 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts @@ -1,13 +1,8 @@ -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import { table_getCenterHeaderGroups, table_getLeftHeaderGroups, table_getRightHeaderGroups, } from '../column-pinning/ColumnPinning.utils' -import { table_getHeaderGroups } from '../../core/headers/Headers.utils' import { column_getIndex } from '../column-ordering/ColumnOrdering.utils' import { column_getVisibleLeafColumns } from '../column-visibility/ColumnVisibility.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' @@ -43,7 +38,7 @@ export function column_getSize< table: Table_Internal, ): number { const defaultSizes = getDefaultColumnSizingColumnDef() - const columnSize = table_getState(table).columnSizing?.[column.id] + const columnSize = table.getState().columnSizing?.[column.id] return Math.min( Math.max( @@ -157,7 +152,7 @@ export function table_resetColumnSizing< >(table: Table_Internal, defaultState?: boolean) { table_setColumnSizing( table, - defaultState ? {} : (table_getInitialState(table).columnSizing ?? {}), + defaultState ? {} : (table.options.initialState?.columnSizing ?? {}), ) } @@ -166,7 +161,7 @@ export function table_getTotalSize< TData extends RowData, >(table: Table_Internal) { return ( - table_getHeaderGroups(table)[0]?.headers.reduce((sum, header) => { + table.getHeaderGroups()[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header, table) }, 0) ?? 0 ) diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.ts index 7f267c8c63..949d302aee 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.ts @@ -1,6 +1,4 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' -import { row_getAllCells } from '../../core/rows/Rows.utils' import { row_getCenterVisibleCells, row_getLeftVisibleCells, @@ -96,10 +94,7 @@ export const ColumnVisibility: TableFeature = { assignAPIs(row, table, [ { fn: () => row_getAllVisibleCells(row, table), - memoDeps: () => [ - row_getAllCells(row, table), - table_getState(table).columnVisibility, - ], + memoDeps: () => [row.getAllCells(), table.getState().columnVisibility], }, { fn: (left, center, right) => row_getVisibleCells(left, center, right), @@ -120,14 +115,14 @@ export const ColumnVisibility: TableFeature = { { fn: () => table_getVisibleFlatColumns(table), memoDeps: () => [ - table_getState(table).columnVisibility, + table.getState().columnVisibility, table.options.columns, ], }, { fn: () => table_getVisibleLeafColumns(table), memoDeps: () => [ - table_getState(table).columnVisibility, + table.getState().columnVisibility, table.options.columns, ], }, diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts index 7d2716cc9e..6c11dd4f77 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts @@ -1,12 +1,3 @@ -import { - table_getAllFlatColumns, - table_getAllLeafColumns, -} from '../../core/columns/Columns.utils' -import { row_getAllCells } from '../../core/rows/Rows.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import { table_getCenterVisibleLeafColumns, table_getLeftVisibleLeafColumns, @@ -61,7 +52,7 @@ export function column_getIsVisible< return ( (childColumns.length ? childColumns.some((c) => column_getIsVisible(c, table)) - : table_getState(table).columnVisibility?.[column.id]) ?? true + : table.getState().columnVisibility?.[column.id]) ?? true ) } @@ -120,9 +111,9 @@ export function row_getAllVisibleCells< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table_Internal) { - return row_getAllCells(row, table).filter((cell) => - column_getIsVisible(cell.column, table), - ) + return row + .getAllCells() + .filter((cell) => column_getIsVisible(cell.column, table)) } export function row_getVisibleCells< @@ -140,18 +131,18 @@ export function table_getVisibleFlatColumns< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - return table_getAllFlatColumns(table).filter((column) => - column_getIsVisible(column, table), - ) + return table + .getAllFlatColumns() + .filter((column) => column_getIsVisible(column, table)) } export function table_getVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - return table_getAllLeafColumns(table).filter((column) => - column_getIsVisible(column, table), - ) + return table + .getAllLeafColumns() + .filter((column) => column_getIsVisible(column, table)) } export function table_setColumnVisibility< @@ -170,7 +161,7 @@ export function table_resetColumnVisibility< >(table: Table_Internal, defaultState?: boolean) { table_setColumnVisibility( table, - defaultState ? {} : (table_getInitialState(table).columnVisibility ?? {}), + defaultState ? {} : (table.options.initialState?.columnVisibility ?? {}), ) } diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts index 735fc49d5a..8b1726331b 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts @@ -1,6 +1,5 @@ import { filterFns } from '../../fns/filterFns' import { isFunction } from '../../utils' -import { table_getInitialState } from '../../core/table/Tables.utils' import type { ColumnDefBase_All } from '../../types/ColumnDef' import type { FilterFn } from '../column-filtering/ColumnFiltering.types' import type { CellData, RowData } from '../../types/type-utils' @@ -82,6 +81,6 @@ export function table_resetGlobalFilter< >(table: Table_Internal, defaultState?: boolean) { table_setGlobalFilter( table, - defaultState ? undefined : table_getInitialState(table).globalFilter, + defaultState ? undefined : table.options.initialState?.globalFilter, ) } diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts index 52f05370cd..a2e4db46ec 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts @@ -1,8 +1,3 @@ -import { table_getRow } from '../../core/rows/Rows.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -72,7 +67,7 @@ export function table_resetExpanded< >(table: Table_Internal, defaultState?: boolean) { table_setExpanded( table, - defaultState ? {} : (table_getInitialState(table).expanded ?? {}), + defaultState ? {} : (table.options.initialState?.expanded ?? {}), ) } @@ -114,7 +109,7 @@ export function table_getIsSomeRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const expanded = table_getState(table).expanded ?? {} + const expanded = table.getState().expanded ?? {} return expanded === true || Object.values(expanded).some(Boolean) } @@ -127,7 +122,7 @@ export function table_getIsAllRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const expanded = table_getState(table).expanded ?? {} + const expanded = table.getState().expanded ?? {} // If expanded is true, save some cycles and return true if (expanded === true) { @@ -161,9 +156,9 @@ export function table_getExpandedDepth< let maxDepth = 0 const rowIds = - table_getState(table).expanded === true + table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) - : Object.keys(table_getState(table).expanded ?? {}) + : Object.keys(table.getState().expanded ?? {}) rowIds.forEach((id) => { const splitId = id.split('.') @@ -228,7 +223,7 @@ export function row_getIsExpanded< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table_Internal) { - const expanded = table_getState(table).expanded ?? {} + const expanded = table.getState().expanded ?? {} return !!( table.options.getIsRowExpanded?.(row) ?? @@ -266,7 +261,7 @@ export function row_getIsAllParentsExpanded< let currentRow = row while (isFullyExpanded && currentRow.parentId) { - currentRow = table_getRow(table, currentRow.parentId, true) + currentRow = table.getRow(currentRow.parentId, true) isFullyExpanded = row_getIsExpanded(row, table) } diff --git a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts index f1ba8093dc..2b10ba11e5 100644 --- a/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts +++ b/packages/table-core/src/features/row-expanding/createExpandedRowModel.ts @@ -1,5 +1,4 @@ import { isDev, tableMemo } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' import { row_getIsExpanded } from './RowExpanding.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' @@ -18,7 +17,7 @@ export function createExpandedRowModel< debug: isDev && (table.options.debugAll ?? table.options.debugTable), fnName: 'table.getExpandedRowModel', memoDeps: () => [ - table_getState(table).expanded, + table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows, ], @@ -31,7 +30,7 @@ export function _createExpandedRowModel< TData extends RowData, >(table: Table_Internal): RowModel { const rowModel = table.getPreExpandedRowModel() - const expanded = table_getState(table).expanded + const expanded = table.getState().expanded if ( !rowModel.rows.length || diff --git a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts index 153fbf00f6..070eb355dc 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts @@ -1,8 +1,4 @@ import { functionalUpdate } from '../../utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -74,8 +70,7 @@ export function table_resetPagination< table, defaultState ? getDefaultPaginationState() - : (table_getInitialState(table).pagination ?? - getDefaultPaginationState()), + : (table.options.initialState?.pagination ?? getDefaultPaginationState()), ) } @@ -119,8 +114,7 @@ export function table_resetPageIndex< table, defaultState ? defaultPageIndex - : (table_getInitialState(table).pagination?.pageIndex ?? - defaultPageIndex), + : (table.options.initialState?.pagination?.pageIndex ?? defaultPageIndex), ) } @@ -137,7 +131,7 @@ export function table_resetPageSize< table, defaultState ? defaultPageSize - : (table_getInitialState(table).pagination?.pageSize ?? defaultPageSize), + : (table.options.initialState?.pagination?.pageSize ?? defaultPageSize), ) } @@ -189,7 +183,7 @@ export function table_getCanPreviousPage< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - return (table_getState(table).pagination?.pageIndex ?? 0) > 0 + return (table.getState().pagination?.pageIndex ?? 0) > 0 } /** @@ -201,8 +195,7 @@ export function table_getCanNextPage< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const pageIndex = - table_getState(table).pagination?.pageIndex ?? defaultPageIndex + const pageIndex = table.getState().pagination?.pageIndex ?? defaultPageIndex const pageCount = table_getPageCount(table) @@ -280,7 +273,7 @@ export function table_getPageCount< table.options.pageCount ?? Math.ceil( table_getRowCount(table) / - (table_getState(table).pagination?.pageSize ?? defaultPageSize), + (table.getState().pagination?.pageSize ?? defaultPageSize), ) ) } diff --git a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts index da36508156..1af209352f 100644 --- a/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts +++ b/packages/table-core/src/features/row-pagination/createPaginatedRowModel.ts @@ -1,6 +1,6 @@ import { isDev, tableMemo } from '../../utils' import { expandRows } from '../row-expanding/createExpandedRowModel' -import { table_getState } from '../../core/table/Tables.utils' + import { getDefaultPaginationState } from './RowPagination.utils' import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' @@ -20,9 +20,9 @@ export function createPaginatedRowModel< fnName: 'table.getPaginatedRowModel', memoDeps: () => [ table.getPrePaginatedRowModel(), - table_getState(table).pagination, + table.getState().pagination, table.options.paginateExpandedRows - ? table_getState(table).expanded + ? table.getState().expanded : undefined, ], fn: () => _createPaginatedRowModel(table), @@ -34,7 +34,7 @@ function _createPaginatedRowModel< TData extends RowData, >(table: Table_Internal): RowModel { const prePaginatedRowModel = table.getPrePaginatedRowModel() - const pagination = table_getState(table).pagination + const pagination = table.getState().pagination if (!prePaginatedRowModel.rows.length) { return prePaginatedRowModel diff --git a/packages/table-core/src/features/row-pinning/RowPinning.ts b/packages/table-core/src/features/row-pinning/RowPinning.ts index d83ad1c855..51a58cf3da 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.ts @@ -1,5 +1,4 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' import { getDefaultRowPinningState, row_getCanPin, @@ -66,10 +65,7 @@ export const RowPinning: TableFeature = { }, { fn: () => row_getPinnedIndex(row, table), - memoDeps: () => [ - table.getRowModel().rows, - table_getState(table).rowPinning, - ], + memoDeps: () => [table.getRowModel().rows, table.getState().rowPinning], }, { fn: (position, includeLeafRows, includeParentRows) => @@ -96,22 +92,19 @@ export const RowPinning: TableFeature = { fn: () => table_getTopRows(table), memoDeps: () => [ table.getRowModel().rows, - table_getState(table).rowPinning?.top, + table.getState().rowPinning?.top, ], }, { fn: () => table_getBottomRows(table), memoDeps: () => [ table.getRowModel().rows, - table_getState(table).rowPinning?.bottom, + table.getState().rowPinning?.bottom, ], }, { fn: () => table_getCenterRows(table), - memoDeps: () => [ - table.getRowModel().rows, - table_getState(table).rowPinning, - ], + memoDeps: () => [table.getRowModel().rows, table.getState().rowPinning], }, ]) }, diff --git a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts index de6ca5196d..62b3f9d942 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts @@ -1,13 +1,4 @@ -import { - row_getLeafRows, - row_getParentRows, - table_getRow, -} from '../../core/rows/Rows.utils' import { row_getIsAllParentsExpanded } from '../row-expanding/RowExpanding.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -55,8 +46,7 @@ export function table_resetRowPinning< table, defaultState ? getDefaultRowPinningState() - : (table_getInitialState(table).rowPinning ?? - getDefaultRowPinningState()), + : (table.options.initialState?.rowPinning ?? getDefaultRowPinningState()), ) } @@ -75,7 +65,7 @@ export function table_getIsSomeRowsPinned< table: Table_Internal, position?: RowPinningPosition, ): boolean { - const rowPinning = table_getState(table).rowPinning + const rowPinning = table.getState().rowPinning if (!position) { return Boolean(rowPinning?.top.length || rowPinning?.bottom.length) @@ -97,14 +87,14 @@ function table_getPinnedRows< position: 'top' | 'bottom', ): Array> { const visibleRows = table.getRowModel().rows - const pinnedRowIds = table_getState(table).rowPinning?.[position] ?? [] + const pinnedRowIds = table.getState().rowPinning?.[position] ?? [] const rows = (table.options.keepPinnedRows ?? true) ? // get all rows that are pinned even if they would not be otherwise visible // account for expanded parent rows, but not pagination or filtering pinnedRowIds.map((rowId) => { - const row = table_getRow(table, rowId, true) + const row = table.getRow(rowId, true) return row_getIsAllParentsExpanded(row, table) ? row : null }) : // else get only visible rows that are pinned @@ -149,7 +139,7 @@ export function table_getCenterRows< TData extends RowData, >(table: Table_Internal): Array> { const { top, bottom } = - table_getState(table).rowPinning ?? getDefaultRowPinningState() + table.getState().rowPinning ?? getDefaultRowPinningState() const allRows = table.getRowModel().rows const topAndBottom = new Set([...top, ...bottom]) @@ -192,7 +182,7 @@ export function row_getIsPinned< table: Table_Internal, ): RowPinningPosition { const { top, bottom } = - table_getState(table).rowPinning ?? getDefaultRowPinningState() + table.getState().rowPinning ?? getDefaultRowPinningState() return top.includes(row.id) ? 'top' @@ -237,10 +227,10 @@ export function row_pin( includeParentRows?: boolean, ): void { const leafRowIds = includeLeafRows - ? row_getLeafRows(row).map(({ id }) => id) + ? row.getLeafRows().map(({ id }) => id) : [] const parentRowIds = includeParentRows - ? row_getParentRows(row, table).map(({ id }) => id) + ? row.getParentRows().map(({ id }) => id) : [] const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]) diff --git a/packages/table-core/src/features/row-selection/RowSelection.ts b/packages/table-core/src/features/row-selection/RowSelection.ts index f220cda613..8a5c4c9868 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.ts @@ -1,5 +1,4 @@ import { assignAPIs, makeStateUpdater } from '../../utils' -import { table_getState } from '../../core/table/Tables.utils' import { getDefaultRowSelectionState, row_getCanMultiSelect, @@ -127,21 +126,21 @@ export const RowSelection: TableFeature = { { fn: () => table_getSelectedRowModel(table), memoDeps: () => [ - table_getState(table).rowSelection, + table.getState().rowSelection, table.getCoreRowModel(), ], }, { fn: () => table_getFilteredSelectedRowModel(table), memoDeps: () => [ - table_getState(table).rowSelection, + table.getState().rowSelection, table.getFilteredRowModel(), ], }, { fn: () => table_getGroupedSelectedRowModel(table), memoDeps: () => [ - table_getState(table).rowSelection, + table.getState().rowSelection, table.getSortedRowModel(), ], }, diff --git a/packages/table-core/src/features/row-selection/RowSelection.utils.ts b/packages/table-core/src/features/row-selection/RowSelection.utils.ts index 514c605f68..558b458323 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.utils.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.utils.ts @@ -1,8 +1,3 @@ -import { table_getRow } from '../../core/rows/Rows.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../core/row-models/RowModels.types' @@ -42,7 +37,7 @@ export function table_resetRowSelection< >(table: Table_Internal, defaultState?: boolean) { table_setRowSelection( table, - defaultState ? {} : (table_getInitialState(table).rowSelection ?? {}), + defaultState ? {} : (table.options.initialState?.rowSelection ?? {}), ) } @@ -132,7 +127,7 @@ export function table_getSelectedRowModel< >(table: Table_Internal) { const rowModel = table.getCoreRowModel() - if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { + if (!Object.keys(table.getState().rowSelection ?? {}).length) { return { rows: [], flatRows: [], @@ -154,7 +149,7 @@ export function table_getFilteredSelectedRowModel< >(table: Table_Internal) { const rowModel = table.getCoreRowModel() - if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { + if (!Object.keys(table.getState().rowSelection ?? {}).length) { return { rows: [], flatRows: [], @@ -176,7 +171,7 @@ export function table_getGroupedSelectedRowModel< >(table: Table_Internal) { const rowModel = table.getCoreRowModel() - if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { + if (!Object.keys(table.getState().rowSelection ?? {}).length) { return { rows: [], flatRows: [], @@ -197,7 +192,7 @@ export function table_getIsAllRowsSelected< TData extends RowData, >(table: Table_Internal) { const preGroupedFlatRows = table.getFilteredRowModel().flatRows - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} let isAllRowsSelected = Boolean( preGroupedFlatRows.length && Object.keys(rowSelection).length, @@ -228,7 +223,7 @@ export function table_getIsAllPageRowsSelected< const paginationFlatRows = table .getPaginatedRowModel() .flatRows.filter((row) => row_getCanSelect(row, table)) - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} let isAllPageRowsSelected = !!paginationFlatRows.length @@ -251,9 +246,7 @@ export function table_getIsSomeRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(table: Table_Internal) { - const totalSelected = Object.keys( - table_getState(table).rowSelection ?? {}, - ).length + const totalSelected = Object.keys(table.getState().rowSelection ?? {}).length return ( totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length @@ -367,7 +360,7 @@ export function row_getIsSelected< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table_Internal) { - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} return isRowSelected(row, rowSelection) } @@ -381,7 +374,7 @@ export function row_getIsSomeSelected< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table_Internal) { - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} return isSubRowSelected(row, rowSelection, table) === 'some' } @@ -395,7 +388,7 @@ export function row_getIsAllSubRowsSelected< TFeatures extends TableFeatures, TData extends RowData, >(row: Row, table: Table_Internal) { - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} return isSubRowSelected(row, rowSelection, table) === 'all' } @@ -490,7 +483,7 @@ const mutateRowIsSelected = < includeChildren: boolean, table: Table_Internal, ) => { - const row = table_getRow(table, rowId, true) + const row = table.getRow(rowId, true) // const isGrouped = row.getIsGrouped() @@ -534,7 +527,7 @@ export function selectRowsFn< table: Table_Internal, rowModel: RowModel, ): RowModel { - const rowSelection = table_getState(table).rowSelection ?? {} + const rowSelection = table.getState().rowSelection ?? {} const newSelectedFlatRows: Array> = [] const newSelectedRowsById: Record> = {} diff --git a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts index c0ffdc527b..b7d1201c97 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts @@ -1,10 +1,5 @@ import { reSplitAlphaNumeric, sortingFn_basic } from '../../fns/sortingFns' import { isFunction } from '../../utils' -import { row_getValue } from '../../core/rows/Rows.utils' -import { - table_getInitialState, - table_getState, -} from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { Table_Internal } from '../../types/Table' @@ -36,7 +31,7 @@ export function table_resetSorting< >(table: Table_Internal, defaultState?: boolean) { table_setSorting( table, - defaultState ? [] : (table_getInitialState(table).sorting ?? []), + defaultState ? [] : (table.options.initialState?.sorting ?? []), ) } @@ -67,7 +62,7 @@ export function column_getAutoSortingFn< let isString = false for (const row of firstRows) { - const value = row_getValue(row, table, column.id) + const value = row.getValue(column.id) if (Object.prototype.toString.call(value) === '[object Date]') { sortingFn = sortingFns?.datetime @@ -105,7 +100,7 @@ export function column_getAutoSortDir< ) { const firstRow = table.getFilteredRowModel().flatRows[0] - const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined + const value = firstRow ? firstRow.getValue(column.id) : undefined if (typeof value === 'string') { return 'asc' @@ -359,9 +354,7 @@ export function column_getIsSorted< column: Column_Internal, table: Table_Internal, ): false | SortDirection { - const columnSort = table_getState(table).sorting?.find( - (d) => d.id === column.id, - ) + const columnSort = table.getState().sorting?.find((d) => d.id === column.id) return !columnSort ? false : columnSort.desc ? 'desc' : 'asc' } @@ -379,9 +372,7 @@ export function column_getSortIndex< column: Column_Internal, table: Table_Internal, ): number { - return ( - table_getState(table).sorting?.findIndex((d) => d.id === column.id) ?? -1 - ) + return table.getState().sorting?.findIndex((d) => d.id === column.id) ?? -1 } /** diff --git a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts index 05984aa936..e99d13ffa8 100644 --- a/packages/table-core/src/features/row-sorting/createSortedRowModel.ts +++ b/packages/table-core/src/features/row-sorting/createSortedRowModel.ts @@ -1,7 +1,4 @@ import { isDev, tableMemo } from '../../utils' -import { row_getValue } from '../../core/rows/Rows.utils' -import { table_getColumn } from '../../core/columns/Columns.utils' -import { table_getState } from '../../core/table/Tables.utils' import { table_autoResetPageIndex } from '../row-pagination/RowPagination.utils' import { column_getCanSort, column_getSortingFn } from './RowSorting.utils' import type { Column_Internal } from '../../types/Column' @@ -22,10 +19,7 @@ export function createSortedRowModel< tableMemo({ debug: isDev && (table.options.debugAll ?? table.options.debugTable), fnName: 'table.getSortedRowModel', - memoDeps: () => [ - table_getState(table).sorting, - table.getPreSortedRowModel(), - ], + memoDeps: () => [table.getState().sorting, table.getPreSortedRowModel()], fn: () => _createSortedRowModel(table), onAfterUpdate: () => table_autoResetPageIndex(table), }) @@ -36,7 +30,7 @@ function _createSortedRowModel< TData extends RowData, >(table: Table_Internal): RowModel { const preSortedRowModel = table.getPreSortedRowModel() - const sorting = table_getState(table).sorting + const sorting = table.getState().sorting if (!preSortedRowModel.rows.length || !sorting?.length) { return preSortedRowModel @@ -46,7 +40,7 @@ function _createSortedRowModel< // Filter out sortings that correspond to non existing columns const availableSorting = sorting.filter((sort) => - column_getCanSort(table_getColumn(table, sort.id)!, table), + column_getCanSort(table.getColumn(sort.id)!, table), ) const columnInfoById: Record< @@ -59,7 +53,7 @@ function _createSortedRowModel< > = {} availableSorting.forEach((sortEntry) => { - const column = table_getColumn(table, sortEntry.id) as + const column = table.getColumn(sortEntry.id) as | Column_Internal | undefined if (!column) return @@ -86,8 +80,8 @@ function _createSortedRowModel< // All sorting ints should always return in ascending order if (sortUndefined) { - const aValue = row_getValue(rowA, table, sortEntry.id) - const bValue = row_getValue(rowB, table, sortEntry.id) + const aValue = rowA.getValue(sortEntry.id) + const bValue = rowB.getValue(sortEntry.id) const aUndefined = aValue === undefined const bUndefined = bValue === undefined diff --git a/packages/table-core/src/utils.ts b/packages/table-core/src/utils.ts index 62afecf1bc..26f0da2317 100755 --- a/packages/table-core/src/utils.ts +++ b/packages/table-core/src/utils.ts @@ -152,7 +152,7 @@ export function tableMemo, TDepArgs, TResult>( console.info( `%c⏱ ${pad(`${compareTime.toFixed(1)} ms + ${executionTime.toFixed(1)} ms`, 17)}`, `font-size: .6rem; font-weight: bold; color: hsl( - ${Math.max(0, Math.min(120 - totalTime, 120))}deg 100% 31%);`, + ${Math.max(0, Math.min(120 - Math.log10(totalTime) * 60, 120))}deg 100% 31%);`, fnName, ) }