Skip to content

Commit

Permalink
remove state unavailable types again
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Oct 28, 2024
1 parent 4f502ca commit 5b2fad4
Show file tree
Hide file tree
Showing 59 changed files with 260 additions and 469 deletions.
4 changes: 2 additions & 2 deletions packages/table-core/src/core/cells/constructCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table } from '../../types/Table'
import type { Row } from '../../types/Row'
import type { Cell } from '../../types/Cell'
Expand All @@ -22,7 +22,7 @@ export function constructCell<
table,
}

for (const feature of Object.values(table._features) as Array<TableFeature>) {
for (const feature of Object.values(table._features)) {
feature.constructCellAPIs?.(cell as Cell<TFeatures, TData, TValue>)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/table-core/src/core/columns/Columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const Columns: TableFeature = {
{
fn: () => column_getLeafColumns(column),
memoDeps: () => [
table.getState().columnOrder,
table.getState().grouping,
table.options.state?.columnOrder,
table.options.state?.grouping,
table.options.columns,
table.options.groupedColumnMode,
],
Expand Down Expand Up @@ -63,8 +63,8 @@ export const Columns: TableFeature = {
{
fn: () => table_getAllLeafColumns(table),
memoDeps: () => [
table.getState().columnOrder,
table.getState().grouping,
table.options.state?.columnOrder,
table.options.state?.grouping,
table.options.columns,
table.options.groupedColumnMode,
],
Expand Down
2 changes: 1 addition & 1 deletion packages/table-core/src/core/columns/Columns.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function table_getDefaultColumnDef<
},
cell: (props) => props.renderValue<any>()?.toString?.() ?? null,
...Object.values(table._features).reduce((obj, feature) => {
return Object.assign(obj ?? {}, feature?.getDefaultColumnDef?.())
return Object.assign(obj, feature.getDefaultColumnDef?.())
}, {}),
...table.options.defaultColumn,
} as Partial<ColumnDef<TFeatures, TData, unknown>>
Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/columns/constructColumn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table } from '../../types/Table'
import type {
AccessorFn,
Expand Down Expand Up @@ -83,7 +83,7 @@ export function constructColumn<
table,
}

for (const feature of Object.values(table._features) as Array<TableFeature>) {
for (const feature of Object.values(table._features)) {
feature.constructColumnAPIs?.(column as Column<TFeatures, TData, TValue>)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/table-core/src/core/headers/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const Headers: TableFeature = {
fn: () => table_getHeaderGroups(table),
memoDeps: () => [
table.options.columns,
table.getState().columnOrder,
table.getState().grouping,
table.getState().columnPinning,
table.options.state?.columnOrder,
table.options.state?.grouping,
table.options.state?.columnPinning,
table.options.groupedColumnMode,
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/table-core/src/core/headers/Headers.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function table_getHeaderGroups<
TData extends RowData,
>(table: Table<TFeatures, TData>) {
const { left, right } =
table.getState().columnPinning ?? getDefaultColumnPinningState()
table.options.state?.columnPinning ?? getDefaultColumnPinningState()
const allColumns = table.getAllColumns()
const leafColumns = table_getVisibleLeafColumns(table)

Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/headers/constructHeader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CellData, RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table } from '../../types/Table'
import type { Header } from '../../types/Header'
import type { Column } from '../../types/Column'
Expand Down Expand Up @@ -34,7 +34,7 @@ export function constructHeader<
table,
}

for (const feature of Object.values(table._features) as Array<TableFeature>) {
for (const feature of Object.values(table._features)) {
feature.constructHeaderAPIs?.(header as Header<TFeatures, TData, TValue>)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/rows/constructRow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RowData } from '../../types/type-utils'
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table } from '../../types/Table'
import type { Row } from '../../types/Row'
import type { Row_CoreProperties } from './Rows.types'
Expand Down Expand Up @@ -28,7 +28,7 @@ export const constructRow = <
table,
}

for (const feature of Object.values(table._features) as Array<TableFeature>) {
for (const feature of Object.values(table._features)) {
feature.constructRowAPIs?.(row as Row<TFeatures, TData>)
}

Expand Down
4 changes: 3 additions & 1 deletion packages/table-core/src/core/table/constructTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function getInitialTableState<TFeatures extends TableFeatures>(
initialState: Partial<TableState<TFeatures>> | undefined = {},
): TableState<TFeatures> {
Object.values(features).forEach((feature) => {
initialState = feature.getInitialState?.(initialState) ?? initialState
initialState =
feature.getInitialState?.(initialState as TableState<TFeatures>) ??
initialState
})
return structuredClone(initialState) as TableState<TFeatures>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ export function createFacetedMinMaxValues<
column_getFacetedRowModel(table.getColumn(columnId), table)(),
],
fn: (facetedRowModel) =>
_createFacetedMinMaxValues(table, columnId, facetedRowModel),
_createFacetedMinMaxValues(columnId, facetedRowModel),
})
}

function _createFacetedMinMaxValues<
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table<TFeatures, TData>,
columnId: string,
facetedRowModel?: RowModel<TFeatures, TData>,
): undefined | [number, number] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function createFacetedRowModel<
fnName: 'createFacetedRowModel',
memoDeps: () => [
table.getPreFilteredRowModel(),
table.getState().columnFilters,
table.getState().globalFilter,
table.options.state?.columnFilters,
table.options.state?.globalFilter,
table.getFilteredRowModel(),
],
fn: (preRowModel, columnFilters, globalFilter) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
Column_ColumnFiltering,
Row_ColumnFiltering,
TableOptions_ColumnFiltering,
TableState_ColumnFiltering,
Table_ColumnFiltering,
} from './ColumnFiltering.types'

Expand All @@ -36,8 +35,8 @@ import type {
*/
export const ColumnFiltering: TableFeature = {
getInitialState: <TFeatures extends TableFeatures>(
state: TableState<TFeatures>,
): TableState<TFeatures> & TableState_ColumnFiltering => {
state: Partial<TableState<TFeatures>>,
): Partial<TableState<TFeatures>> => {
return {
columnFilters: getDefaultColumnFiltersState(),
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export interface TableState_ColumnFiltering {
columnFilters: ColumnFiltersState
}

export interface TableState_ColumnFiltering_Unavailable {
/**
* @deprecated Import the `ColumnFiltering` feature to use the column filtering APIs.
*/
columnFilters?: ColumnFiltersState
}

export type ColumnFiltersState = Array<ColumnFilter>

export interface ColumnFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ export function column_getFilterValue<
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
},
) {
return column.table.getState().columnFilters?.find((d) => d.id === column.id)
?.value
return column.table.options.state?.columnFilters?.find(
(d) => d.id === column.id,
)?.value
}

export function column_getFilterIndex<
Expand All @@ -120,9 +121,9 @@ export function column_getFilterIndex<
},
): number {
return (
column.table
.getState()
.columnFilters?.findIndex((d) => d.id === column.id) ?? -1
column.table.options.state?.columnFilters?.findIndex(
(d) => d.id === column.id,
) ?? -1
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function createFilteredRowModel<
fnName: 'table.getFilteredRowModel',
memoDeps: () => [
table.getPreFilteredRowModel(),
table.getState().columnFilters,
table.getState().globalFilter,
table.options.state?.columnFilters,
table.options.state?.globalFilter,
],
fn: () => _createFilteredRowModel(table),
onAfterUpdate: () => table_autoResetPageIndex(table),
Expand All @@ -40,7 +40,7 @@ function _createFilteredRowModel<
TData extends RowData,
>(table: Table<TFeatures, TData>): RowModel<TFeatures, TData> {
const rowModel = table.getPreFilteredRowModel()
const { columnFilters, globalFilter } = table.getState()
const { columnFilters, globalFilter } = table.options.state ?? {}

if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) {
for (const row of rowModel.flatRows as Array<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import type {
Column_ColumnGrouping,
Row_ColumnGrouping,
TableOptions_ColumnGrouping,
TableState_ColumnGrouping,
Table_ColumnGrouping,
} from './ColumnGrouping.types'

Expand All @@ -40,8 +39,8 @@ import type {
*/
export const ColumnGrouping: TableFeature = {
getInitialState: <TFeatures extends TableFeatures>(
state: TableState<TFeatures>,
): TableState<TFeatures> & TableState_ColumnGrouping => {
state: Partial<TableState<TFeatures>>,
): Partial<TableState<TFeatures>> => {
return {
grouping: getDefaultGroupingState(),
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ export interface TableState_ColumnGrouping {
grouping: GroupingState
}

export interface TableState_ColumnGrouping_Unavailable {
/**
* @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs.
*/
grouping?: GroupingState
}

export interface TableFns_ColumnGrouping<
TFeatures extends TableFeatures,
TData extends RowData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function column_getIsGrouped<
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
): boolean {
return !!column.table.getState().grouping?.includes(column.id)
return !!column.table.options.state?.grouping?.includes(column.id)
}

export function column_getGroupedIndex<
Expand All @@ -69,7 +69,7 @@ export function column_getGroupedIndex<
columnDef: Partial<ColumnDef_ColumnGrouping<TFeatures, TData>>
},
): number {
return column.table.getState().grouping?.indexOf(column.id) ?? -1
return column.table.options.state?.grouping?.indexOf(column.id) ?? -1
}

export function column_getToggleGroupingHandler<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function createGroupedRowModel<
debug: isDev && (table.options.debugAll ?? table.options.debugTable),
fnName: 'table.getGroupedRowModel',
memoDeps: () => [
table.getState().grouping,
table.options.state?.grouping,
table.getPreGroupedRowModel(),
],
fn: () => _createGroupedRowModel(table),
Expand All @@ -40,7 +40,7 @@ function _createGroupedRowModel<
TData extends RowData,
>(table: Table<TFeatures, TData>): RowModel<TFeatures, TData> {
const rowModel = table.getPreGroupedRowModel()
const grouping = table.getState().grouping
const grouping = table.options.state?.grouping

if (!rowModel.rows.length || !grouping?.length) {
rowModel.rows.forEach((row) => {
Expand Down
26 changes: 17 additions & 9 deletions packages/table-core/src/features/column-ordering/ColumnOrdering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import {
column_getIsFirstColumn,
column_getIsLastColumn,
getDefaultColumnOrderState,
table_getOrderColumnsFn,
table_resetColumnOrder,
table_setColumnOrder,
} from './ColumnOrdering.utils'
import type { TableState } from '../../types/TableState'
import type {
ColumnOrderDefaultOptions,
Column_ColumnOrdering,
TableState_ColumnOrdering,
Table_ColumnOrdering,
} from './ColumnOrdering.types'
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'

/**
Expand All @@ -26,8 +26,8 @@ import type { Column } from '../../types/Column'
*/
export const ColumnOrdering: TableFeature = {
getInitialState: <TFeatures extends TableFeatures>(
state: TableState<TFeatures>,
): TableState<TFeatures> & TableState_ColumnOrdering => {
state: Partial<TableState<TFeatures>>,
): Partial<TableState<TFeatures>> => {
return {
columnOrder: getDefaultColumnOrderState(),
...state,
Expand All @@ -38,7 +38,7 @@ export const ColumnOrdering: TableFeature = {
TFeatures extends TableFeatures,
TData extends RowData,
>(
table: Table<TFeatures, TData> &
table: Table_Internal<TFeatures, TData> &
Partial<Table_ColumnOrdering<TFeatures, TData>>,
): ColumnOrderDefaultOptions => {
return {
Expand All @@ -58,9 +58,9 @@ export const ColumnOrdering: TableFeature = {
fn: (position) => column_getIndex(column, position),
memoDeps: (position) => [
position,
column.table.getState().columnOrder,
column.table.getState().columnPinning,
column.table.getState().grouping,
column.table.options.state?.columnOrder,
column.table.options.state?.columnPinning,
column.table.options.state?.grouping,
],
},
{
Expand All @@ -73,7 +73,7 @@ export const ColumnOrdering: TableFeature = {
},

constructTableAPIs: <TFeatures extends TableFeatures, TData extends RowData>(
table: Table<TFeatures, TData> &
table: Table_Internal<TFeatures, TData> &
Partial<Table_ColumnOrdering<TFeatures, TData>>,
): void => {
assignAPIs(table, [
Expand All @@ -83,6 +83,14 @@ export const ColumnOrdering: TableFeature = {
{
fn: (defaultState) => table_resetColumnOrder(table, defaultState),
},
{
fn: () => table_getOrderColumnsFn(table),
memoDeps: () => [
table.options.state?.columnOrder,
table.options.state?.grouping,
table.options.groupedColumnMode,
],
},
])
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ export interface TableState_ColumnOrdering {
columnOrder: ColumnOrderState
}

export interface TableState_ColumnOrdering_Unavailable {
/**
* @deprecated Import the `ColumnOrdering` feature to use the column ordering APIs.
*/
columnOrder?: ColumnOrderState
}

export interface TableOptions_ColumnOrdering {
/**
* If provided, this function will be called with an `updaterFn` when `state.columnOrder` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
Expand Down
Loading

0 comments on commit 5b2fad4

Please sign in to comment.