@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/aggregationFns.js +120 -0
- package/build/cjs/aggregationFns.js.map +1 -0
- package/build/cjs/core/cell.js +40 -0
- package/build/cjs/core/cell.js.map +1 -0
- package/build/cjs/core/column.js +88 -0
- package/build/cjs/core/column.js.map +1 -0
- package/build/cjs/core/headers.js +403 -0
- package/build/cjs/core/headers.js.map +1 -0
- package/build/cjs/core/instance.js +255 -0
- package/build/cjs/core/instance.js.map +1 -0
- package/build/cjs/core/row.js +77 -0
- package/build/cjs/core/row.js.map +1 -0
- package/build/cjs/createTable.js +36 -29
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +157 -189
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +103 -155
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +155 -304
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +97 -157
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +30 -41
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +102 -105
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +131 -89
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +138 -267
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +82 -167
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +69 -115
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +107 -0
- package/build/cjs/filterFns.js.map +1 -0
- package/build/cjs/index.js +36 -23
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/sortingFns.js +124 -0
- package/build/cjs/sortingFns.js.map +1 -0
- package/build/cjs/utils/filterRowsUtils.js +117 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/getCoreRowModel.js +79 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +57 -0
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js +54 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +139 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +161 -0
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
- package/build/cjs/utils/getPaginationRowModel.js +61 -0
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
- package/build/cjs/utils/getSortedRowModel.js +110 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +38 -107
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2976 -3853
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +586 -408
- package/build/types/aggregationFns.d.ts +13 -0
- package/build/types/core/cell.d.ts +9 -0
- package/build/types/core/column.d.ts +40 -0
- package/build/types/core/headers.d.ts +46 -0
- package/build/types/core/instance.d.ts +57 -0
- package/build/types/core/row.d.ts +15 -0
- package/build/types/createTable.d.ts +47 -26
- package/build/types/features/ColumnSizing.d.ts +32 -44
- package/build/types/features/Expanding.d.ts +15 -26
- package/build/types/features/Filters.d.ts +64 -63
- package/build/types/features/Grouping.d.ts +32 -46
- package/build/types/features/Ordering.d.ts +7 -10
- package/build/types/features/Pagination.d.ts +16 -15
- package/build/types/features/Pinning.d.ts +16 -17
- package/build/types/features/RowSelection.d.ts +13 -33
- package/build/types/features/Sorting.d.ts +25 -44
- package/build/types/features/Visibility.d.ts +16 -25
- package/build/types/filterFns.d.ts +13 -0
- package/build/types/index.d.ts +16 -10
- package/build/types/sortingFns.d.ts +11 -0
- package/build/types/types.d.ts +37 -122
- package/build/types/utils/filterRowsUtils.d.ts +4 -0
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getExpandedRowModel.d.ts +7 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/getFilteredRowModel.d.ts +2 -0
- package/build/types/utils/getGroupedRowModel.d.ts +2 -0
- package/build/types/utils/getPaginationRowModel.d.ts +4 -0
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +7 -11
- package/build/umd/index.development.js +3024 -3893
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +9 -10
- package/src/aggregationFns.ts +123 -0
- package/src/core/cell.ts +48 -0
- package/src/core/column.ts +147 -0
- package/src/core/headers.ts +575 -0
- package/src/core/instance.ts +359 -0
- package/src/core/row.ts +85 -0
- package/src/createTable.ts +188 -0
- package/src/features/ColumnSizing.ts +170 -185
- package/src/features/Expanding.ts +120 -194
- package/src/features/Filters.ts +299 -381
- package/src/features/Grouping.ts +158 -220
- package/src/features/Ordering.ts +24 -25
- package/src/features/Pagination.ts +88 -73
- package/src/features/Pinning.ts +186 -63
- package/src/features/RowSelection.ts +107 -245
- package/src/features/Sorting.ts +125 -225
- package/src/features/Visibility.ts +116 -132
- package/src/filterFns.ts +135 -0
- package/src/index.ts +29 -0
- package/src/{sortTypes.ts → sortingFns.ts} +63 -85
- package/src/types.ts +62 -168
- package/src/utils/filterRowsUtils.ts +112 -0
- package/src/utils/getCoreRowModel.ts +84 -0
- package/src/utils/getExpandedRowModel.ts +54 -0
- package/src/utils/getFacetedMinMaxValues.ts +40 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/getFilteredRowModel.ts +159 -0
- package/src/utils/getGroupedRowModel.ts +175 -0
- package/src/utils/getPaginationRowModel.ts +48 -0
- package/src/utils/getSortedRowModel.ts +116 -0
- package/src/utils.ts +126 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -630
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/features/Headers.d.ts +0 -43
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/src/.DS_Store +0 -0
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -137
- package/src/features/Headers.ts +0 -747
- package/src/filterTypes.ts +0 -188
- package/src/index.tsx +0 -23
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
package/src/core.tsx
DELETED
|
@@ -1,763 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flattenBy,
|
|
3
|
-
functionalUpdate,
|
|
4
|
-
propGetter,
|
|
5
|
-
memo,
|
|
6
|
-
flexRender,
|
|
7
|
-
RequiredKeys,
|
|
8
|
-
} from './utils'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
Updater,
|
|
12
|
-
PropGetterValue,
|
|
13
|
-
Options,
|
|
14
|
-
TableState,
|
|
15
|
-
ColumnDef,
|
|
16
|
-
Row,
|
|
17
|
-
Column,
|
|
18
|
-
Cell,
|
|
19
|
-
Header,
|
|
20
|
-
AccessorFn,
|
|
21
|
-
HeaderRenderProps,
|
|
22
|
-
TableProps,
|
|
23
|
-
TableBodyProps,
|
|
24
|
-
PropGetter,
|
|
25
|
-
Getter,
|
|
26
|
-
RowProps,
|
|
27
|
-
CellProps,
|
|
28
|
-
TableInstance,
|
|
29
|
-
RowValues,
|
|
30
|
-
Renderable,
|
|
31
|
-
Please_use_the_create_table_column_utilities_to_define_columns,
|
|
32
|
-
PartialGenerics,
|
|
33
|
-
} from './types'
|
|
34
|
-
|
|
35
|
-
import { Visibility } from './features/Visibility'
|
|
36
|
-
import { Ordering } from './features/Ordering'
|
|
37
|
-
import { Pinning } from './features/Pinning'
|
|
38
|
-
import { Headers } from './features/Headers'
|
|
39
|
-
import { Filters } from './features/Filters'
|
|
40
|
-
import { Sorting } from './features/Sorting'
|
|
41
|
-
import { Grouping, GroupingCell } from './features/Grouping'
|
|
42
|
-
import { Expanding } from './features/Expanding'
|
|
43
|
-
import { ColumnSizing, defaultColumnSizing } from './features/ColumnSizing'
|
|
44
|
-
import { Pagination } from './features/Pagination'
|
|
45
|
-
import { RowSelection } from './features/RowSelection'
|
|
46
|
-
import { RowModel } from '.'
|
|
47
|
-
|
|
48
|
-
const features = [
|
|
49
|
-
Visibility,
|
|
50
|
-
Ordering,
|
|
51
|
-
Pinning,
|
|
52
|
-
Headers,
|
|
53
|
-
Filters,
|
|
54
|
-
Sorting,
|
|
55
|
-
Grouping,
|
|
56
|
-
Expanding,
|
|
57
|
-
ColumnSizing,
|
|
58
|
-
Pagination,
|
|
59
|
-
RowSelection,
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
export type CoreOptions<TGenerics extends PartialGenerics> = {
|
|
63
|
-
data: TGenerics['Row'][]
|
|
64
|
-
columns: ColumnDef<TGenerics>[]
|
|
65
|
-
state: Partial<TableState>
|
|
66
|
-
onStateChange: (updater: Updater<TableState>) => void
|
|
67
|
-
debugAll?: boolean
|
|
68
|
-
debugTable?: boolean
|
|
69
|
-
debugHeaders?: boolean
|
|
70
|
-
debugColumns?: boolean
|
|
71
|
-
debugRows?: boolean
|
|
72
|
-
defaultColumn?: Partial<ColumnDef<TGenerics>>
|
|
73
|
-
initialState?: Partial<TableState>
|
|
74
|
-
getSubRows?: (
|
|
75
|
-
originalRow: TGenerics['Row'],
|
|
76
|
-
index: number
|
|
77
|
-
) => TGenerics['Row'][]
|
|
78
|
-
getRowId?: (
|
|
79
|
-
originalRow: TGenerics['Row'],
|
|
80
|
-
index: number,
|
|
81
|
-
parent?: Row<TGenerics>
|
|
82
|
-
) => string
|
|
83
|
-
autoResetAll?: boolean
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type TableCore<TGenerics extends PartialGenerics> = {
|
|
87
|
-
initialState: TableState
|
|
88
|
-
reset: () => void
|
|
89
|
-
options: RequiredKeys<Options<TGenerics>, 'state'>
|
|
90
|
-
setOptions: (newOptions: Updater<Options<TGenerics>>) => void
|
|
91
|
-
getRowId: (
|
|
92
|
-
_: TGenerics['Row'],
|
|
93
|
-
index: number,
|
|
94
|
-
parent?: Row<TGenerics>
|
|
95
|
-
) => string
|
|
96
|
-
getState: () => TableState
|
|
97
|
-
setState: (updater: Updater<TableState>) => void
|
|
98
|
-
getDefaultColumn: () => Partial<ColumnDef<TGenerics>>
|
|
99
|
-
getColumnDefs: () => ColumnDef<TGenerics>[]
|
|
100
|
-
createColumn: (
|
|
101
|
-
columnDef: ColumnDef<TGenerics>,
|
|
102
|
-
depth: number,
|
|
103
|
-
parent?: Column<TGenerics>
|
|
104
|
-
) => Column<TGenerics>
|
|
105
|
-
getAllColumns: () => Column<TGenerics>[]
|
|
106
|
-
getAllFlatColumns: () => Column<TGenerics>[]
|
|
107
|
-
getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
|
|
108
|
-
getAllLeafColumns: () => Column<TGenerics>[]
|
|
109
|
-
getColumn: (columnId: string) => Column<TGenerics>
|
|
110
|
-
getColumnWidth: (columnId: string) => number
|
|
111
|
-
getTotalWidth: () => number
|
|
112
|
-
createCell: (
|
|
113
|
-
row: Row<TGenerics>,
|
|
114
|
-
column: Column<TGenerics>,
|
|
115
|
-
value: any
|
|
116
|
-
) => Cell<TGenerics>
|
|
117
|
-
createRow: (
|
|
118
|
-
id: string,
|
|
119
|
-
original: TGenerics['Row'] | undefined,
|
|
120
|
-
rowIndex: number,
|
|
121
|
-
depth: number,
|
|
122
|
-
values: Record<string, any>
|
|
123
|
-
) => Row<TGenerics>
|
|
124
|
-
getCoreRowModel: () => RowModel<TGenerics>
|
|
125
|
-
getRowModel: () => RowModel<TGenerics>
|
|
126
|
-
getRow: (id: string) => Row<TGenerics>
|
|
127
|
-
getCell: (rowId: string, columnId: string) => Cell<TGenerics>
|
|
128
|
-
getTableProps: PropGetter<TableProps>
|
|
129
|
-
getTableBodyProps: PropGetter<TableBodyProps>
|
|
130
|
-
getRowProps: <TGetter extends Getter<RowProps>>(
|
|
131
|
-
rowId: string,
|
|
132
|
-
userProps?: TGetter
|
|
133
|
-
) => undefined | PropGetterValue<RowProps, TGetter>
|
|
134
|
-
getCellProps: <TGetter extends Getter<CellProps>>(
|
|
135
|
-
rowId: string,
|
|
136
|
-
columnId: string,
|
|
137
|
-
userProps?: TGetter
|
|
138
|
-
) => undefined | PropGetterValue<CellProps, TGetter>
|
|
139
|
-
getTableWidth: () => number
|
|
140
|
-
getLeftTableWidth: () => number
|
|
141
|
-
getCenterTableWidth: () => number
|
|
142
|
-
getRightTableWidth: () => number
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export type CoreRow<TGenerics extends PartialGenerics> = {
|
|
146
|
-
id: string
|
|
147
|
-
index: number
|
|
148
|
-
original?: TGenerics['Row']
|
|
149
|
-
depth: number
|
|
150
|
-
values: RowValues
|
|
151
|
-
leafRows: Row<TGenerics>[]
|
|
152
|
-
subRows: Row<TGenerics>[]
|
|
153
|
-
getRowProps: PropGetter<RowProps>
|
|
154
|
-
originalSubRows?: TGenerics['Row'][]
|
|
155
|
-
getAllCells: () => Cell<TGenerics>[]
|
|
156
|
-
getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export type CoreColumnDef<TGenerics extends PartialGenerics> = {
|
|
160
|
-
id: string
|
|
161
|
-
accessorKey?: string & keyof TGenerics['Row']
|
|
162
|
-
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
163
|
-
header?:
|
|
164
|
-
| string
|
|
165
|
-
| Renderable<{
|
|
166
|
-
instance: TableInstance<TGenerics>
|
|
167
|
-
header: Header<TGenerics>
|
|
168
|
-
column: Column<TGenerics>
|
|
169
|
-
}>
|
|
170
|
-
width?: number
|
|
171
|
-
minWidth?: number
|
|
172
|
-
maxWidth?: number
|
|
173
|
-
columns?: ColumnDef<TGenerics>[]
|
|
174
|
-
footer?: Renderable<{
|
|
175
|
-
instance: TableInstance<TGenerics>
|
|
176
|
-
header: Header<TGenerics>
|
|
177
|
-
column: Column<TGenerics>
|
|
178
|
-
}>
|
|
179
|
-
cell?: Renderable<{
|
|
180
|
-
instance: TableInstance<TGenerics>
|
|
181
|
-
row: Row<TGenerics>
|
|
182
|
-
column: Column<TGenerics>
|
|
183
|
-
cell: Cell<TGenerics>
|
|
184
|
-
value: TGenerics['Value']
|
|
185
|
-
}>
|
|
186
|
-
defaultIsVisible?: boolean
|
|
187
|
-
[Please_use_the_create_table_column_utilities_to_define_columns]: true
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export type CoreColumn<TGenerics extends PartialGenerics> = {
|
|
191
|
-
id: string
|
|
192
|
-
depth: number
|
|
193
|
-
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
194
|
-
columnDef: ColumnDef<TGenerics>
|
|
195
|
-
getWidth: () => number
|
|
196
|
-
columns: Column<TGenerics>[]
|
|
197
|
-
parent?: Column<TGenerics>
|
|
198
|
-
getFlatColumns: () => Column<TGenerics>[]
|
|
199
|
-
getLeafColumns: () => Column<TGenerics>[]
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
203
|
-
options: Options<TGenerics>
|
|
204
|
-
): TableInstance<TGenerics> {
|
|
205
|
-
if (options.debugAll || options.debugTable) {
|
|
206
|
-
console.info('Creating React Table Instance...')
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let instance = {} as TableInstance<TGenerics>
|
|
210
|
-
|
|
211
|
-
let listeners: (() => void)[] = []
|
|
212
|
-
|
|
213
|
-
const defaultOptions = features.reduce((obj, feature) => {
|
|
214
|
-
return Object.assign(obj, (feature as any).getDefaultOptions?.(instance))
|
|
215
|
-
}, {})
|
|
216
|
-
|
|
217
|
-
const buildOptions = (options: Options<TGenerics>) => ({
|
|
218
|
-
...defaultOptions,
|
|
219
|
-
...options,
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
instance.options = buildOptions(options)
|
|
223
|
-
|
|
224
|
-
const initialState = {
|
|
225
|
-
...features.reduce((obj, feature) => {
|
|
226
|
-
return Object.assign(obj, (feature as any).getInitialState?.())
|
|
227
|
-
}, {}),
|
|
228
|
-
...(options.initialState ?? {}),
|
|
229
|
-
} as TableState
|
|
230
|
-
|
|
231
|
-
const finalInstance: TableInstance<TGenerics> = {
|
|
232
|
-
...instance,
|
|
233
|
-
...features.reduce((obj, feature) => {
|
|
234
|
-
return Object.assign(obj, (feature as any).getInstance?.(instance))
|
|
235
|
-
}, {}),
|
|
236
|
-
initialState,
|
|
237
|
-
reset: () => {
|
|
238
|
-
instance.setState(instance.initialState)
|
|
239
|
-
},
|
|
240
|
-
setOptions: updater => {
|
|
241
|
-
instance.options = buildOptions(
|
|
242
|
-
functionalUpdate(updater, instance.options)
|
|
243
|
-
)
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
getRowId: (_: TGenerics['Row'], index: number, parent?: Row<TGenerics>) =>
|
|
247
|
-
`${parent ? [parent.id, index].join('.') : index}`,
|
|
248
|
-
|
|
249
|
-
getState: () => {
|
|
250
|
-
return instance.options.state as TableState
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
setState: (updater: Updater<TableState>) => {
|
|
254
|
-
instance.options.onStateChange?.(updater)
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
getDefaultColumn: memo(
|
|
258
|
-
() => [instance.options.defaultColumn],
|
|
259
|
-
defaultColumn => {
|
|
260
|
-
defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
header: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
264
|
-
props.header.column.id,
|
|
265
|
-
footer: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
266
|
-
props.header.column.id,
|
|
267
|
-
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
268
|
-
typeof value === 'boolean' ? value.toString() : value,
|
|
269
|
-
...features.reduce((obj, feature) => {
|
|
270
|
-
return Object.assign(obj, (feature as any).getDefaultColumn?.())
|
|
271
|
-
}, {}),
|
|
272
|
-
...defaultColumn,
|
|
273
|
-
} as Partial<ColumnDef<TGenerics>>
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
277
|
-
key: 'getDefaultColumn',
|
|
278
|
-
}
|
|
279
|
-
),
|
|
280
|
-
|
|
281
|
-
getColumnDefs: () => instance.options.columns,
|
|
282
|
-
|
|
283
|
-
createColumn: (columnDef, depth: number, parent) => {
|
|
284
|
-
const defaultColumn = instance.getDefaultColumn()
|
|
285
|
-
|
|
286
|
-
let id =
|
|
287
|
-
columnDef.id ??
|
|
288
|
-
columnDef.accessorKey ??
|
|
289
|
-
(typeof columnDef.header === 'string' ? columnDef.header : undefined)
|
|
290
|
-
|
|
291
|
-
let accessorFn: AccessorFn<TGenerics['Row']> | undefined
|
|
292
|
-
|
|
293
|
-
if (columnDef.accessorFn) {
|
|
294
|
-
accessorFn = columnDef.accessorFn
|
|
295
|
-
} else if (columnDef.accessorKey) {
|
|
296
|
-
accessorFn = (originalRow?: TGenerics['Row']) =>
|
|
297
|
-
(originalRow as any)[columnDef.accessorKey]
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!id) {
|
|
301
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
302
|
-
throw new Error(
|
|
303
|
-
columnDef.accessorFn
|
|
304
|
-
? `Columns require an id when using an accessorFn`
|
|
305
|
-
: `Columns require an id when using a non-string header`
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
throw new Error()
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
let column: CoreColumn<TGenerics> = {
|
|
312
|
-
...defaultColumnSizing,
|
|
313
|
-
...defaultColumn,
|
|
314
|
-
...columnDef,
|
|
315
|
-
id: `${id}`,
|
|
316
|
-
accessorFn,
|
|
317
|
-
parent: parent as any,
|
|
318
|
-
depth,
|
|
319
|
-
columnDef,
|
|
320
|
-
columns: [],
|
|
321
|
-
getWidth: () => instance.getColumnWidth(column.id),
|
|
322
|
-
getFlatColumns: memo(
|
|
323
|
-
() => [true],
|
|
324
|
-
() => {
|
|
325
|
-
return [
|
|
326
|
-
column as Column<TGenerics>,
|
|
327
|
-
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
328
|
-
]
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
key: 'column.getFlatColumns',
|
|
332
|
-
debug: () =>
|
|
333
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
334
|
-
}
|
|
335
|
-
),
|
|
336
|
-
getLeafColumns: memo(
|
|
337
|
-
() => [instance.getOrderColumnsFn()],
|
|
338
|
-
orderColumns => {
|
|
339
|
-
if (column.columns?.length) {
|
|
340
|
-
let leafColumns = column.columns.flatMap(column =>
|
|
341
|
-
column.getLeafColumns()
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
return orderColumns(leafColumns)
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return [column as Column<TGenerics>]
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
key: 'column.getLeafColumns',
|
|
351
|
-
debug: () =>
|
|
352
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
353
|
-
}
|
|
354
|
-
),
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
column = features.reduce((obj, feature) => {
|
|
358
|
-
return Object.assign(
|
|
359
|
-
obj,
|
|
360
|
-
(feature as any).createColumn?.(column, instance)
|
|
361
|
-
)
|
|
362
|
-
}, column)
|
|
363
|
-
|
|
364
|
-
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
365
|
-
return column as Column<TGenerics>
|
|
366
|
-
},
|
|
367
|
-
|
|
368
|
-
getAllColumns: memo(
|
|
369
|
-
() => [instance.getColumnDefs()],
|
|
370
|
-
columnDefs => {
|
|
371
|
-
const recurseColumns = (
|
|
372
|
-
columnDefs: ColumnDef<TGenerics>[],
|
|
373
|
-
parent?: Column<TGenerics>,
|
|
374
|
-
depth = 0
|
|
375
|
-
): Column<TGenerics>[] => {
|
|
376
|
-
return columnDefs.map(columnDef => {
|
|
377
|
-
const column = instance.createColumn(columnDef, depth, parent)
|
|
378
|
-
|
|
379
|
-
column.columns = columnDef.columns
|
|
380
|
-
? recurseColumns(columnDef.columns, column, depth + 1)
|
|
381
|
-
: []
|
|
382
|
-
|
|
383
|
-
return column
|
|
384
|
-
})
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return recurseColumns(columnDefs)
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
key: 'getAllColumns',
|
|
391
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
392
|
-
}
|
|
393
|
-
),
|
|
394
|
-
|
|
395
|
-
getAllFlatColumns: memo(
|
|
396
|
-
() => [instance.getAllColumns()],
|
|
397
|
-
allColumns => {
|
|
398
|
-
return allColumns.flatMap(column => {
|
|
399
|
-
return column.getFlatColumns()
|
|
400
|
-
})
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
key: 'getAllFlatColumns',
|
|
404
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
405
|
-
}
|
|
406
|
-
),
|
|
407
|
-
|
|
408
|
-
getAllFlatColumnsById: memo(
|
|
409
|
-
() => [instance.getAllFlatColumns()],
|
|
410
|
-
flatColumns => {
|
|
411
|
-
return flatColumns.reduce((acc, column) => {
|
|
412
|
-
acc[column.id] = column
|
|
413
|
-
return acc
|
|
414
|
-
}, {} as Record<string, Column<TGenerics>>)
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
key: 'getAllFlatColumnsById',
|
|
418
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
419
|
-
}
|
|
420
|
-
),
|
|
421
|
-
|
|
422
|
-
getAllLeafColumns: memo(
|
|
423
|
-
() => [instance.getAllColumns(), instance.getOrderColumnsFn()],
|
|
424
|
-
(allColumns, orderColumns) => {
|
|
425
|
-
let leafColumns = allColumns.flatMap(column => column.getLeafColumns())
|
|
426
|
-
return orderColumns(leafColumns)
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
key: 'getAllLeafColumns',
|
|
430
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
431
|
-
}
|
|
432
|
-
),
|
|
433
|
-
|
|
434
|
-
getColumn: columnId => {
|
|
435
|
-
const column = instance.getAllFlatColumnsById()[columnId]
|
|
436
|
-
|
|
437
|
-
if (!column) {
|
|
438
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
439
|
-
console.warn(
|
|
440
|
-
`[React Table] Column with id ${columnId} does not exist.`
|
|
441
|
-
)
|
|
442
|
-
}
|
|
443
|
-
throw new Error()
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return column
|
|
447
|
-
},
|
|
448
|
-
|
|
449
|
-
getColumnWidth: (columnId: string) => {
|
|
450
|
-
const column = instance.getColumn(columnId)
|
|
451
|
-
|
|
452
|
-
if (!column) {
|
|
453
|
-
throw new Error()
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
const columnSize = instance.getState().columnSizing[column.id]
|
|
457
|
-
|
|
458
|
-
return Math.min(
|
|
459
|
-
Math.max(
|
|
460
|
-
column.minWidth ?? defaultColumnSizing.minWidth,
|
|
461
|
-
columnSize ?? column.width ?? defaultColumnSizing.width
|
|
462
|
-
),
|
|
463
|
-
column.maxWidth ?? defaultColumnSizing.maxWidth
|
|
464
|
-
)
|
|
465
|
-
},
|
|
466
|
-
|
|
467
|
-
createCell: (row, column, value) => {
|
|
468
|
-
const cell: Cell<TGenerics> = {
|
|
469
|
-
id: `${row.id}_${column.id}`,
|
|
470
|
-
rowId: row.id,
|
|
471
|
-
columnId: column.id,
|
|
472
|
-
row,
|
|
473
|
-
column,
|
|
474
|
-
value,
|
|
475
|
-
getCellProps: userProps =>
|
|
476
|
-
instance.getCellProps(row.id, column.id, userProps)!,
|
|
477
|
-
renderCell: () =>
|
|
478
|
-
flexRender(column.cell, { instance, column, row, cell, value }),
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
features.forEach(feature => {
|
|
482
|
-
Object.assign(
|
|
483
|
-
cell,
|
|
484
|
-
(feature as any).createCell?.(
|
|
485
|
-
cell as Cell<TGenerics> & GroupingCell,
|
|
486
|
-
column,
|
|
487
|
-
row as Row<TGenerics>,
|
|
488
|
-
instance
|
|
489
|
-
)
|
|
490
|
-
)
|
|
491
|
-
}, {})
|
|
492
|
-
|
|
493
|
-
return cell
|
|
494
|
-
},
|
|
495
|
-
|
|
496
|
-
createRow: (id, original, rowIndex, depth, values) => {
|
|
497
|
-
let row: CoreRow<TGenerics> = {
|
|
498
|
-
id,
|
|
499
|
-
index: rowIndex,
|
|
500
|
-
original,
|
|
501
|
-
depth,
|
|
502
|
-
values,
|
|
503
|
-
subRows: [],
|
|
504
|
-
leafRows: [],
|
|
505
|
-
getRowProps: userProps => instance.getRowProps(row.id, userProps)!,
|
|
506
|
-
getAllCells: undefined!,
|
|
507
|
-
getAllCellsByColumnId: undefined!,
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
row.getAllCells = memo(
|
|
511
|
-
() => [instance.getAllLeafColumns()],
|
|
512
|
-
leafColumns => {
|
|
513
|
-
return leafColumns.map(column => {
|
|
514
|
-
return instance.createCell(
|
|
515
|
-
row as Row<TGenerics>,
|
|
516
|
-
column,
|
|
517
|
-
row.values[column.id]
|
|
518
|
-
)
|
|
519
|
-
})
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
key: process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '',
|
|
523
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
524
|
-
}
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
row.getAllCellsByColumnId = memo(
|
|
528
|
-
() => [row.getAllCells()],
|
|
529
|
-
allCells => {
|
|
530
|
-
return allCells.reduce((acc, cell) => {
|
|
531
|
-
acc[cell.columnId] = cell
|
|
532
|
-
return acc
|
|
533
|
-
}, {} as Record<string, Cell<TGenerics>>)
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
key: 'row.getAllCellsByColumnId',
|
|
537
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
538
|
-
}
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
for (let i = 0; i < features.length; i++) {
|
|
542
|
-
const feature = features[i]
|
|
543
|
-
Object.assign(row, (feature as any).createRow?.(row, instance))
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return row as Row<TGenerics>
|
|
547
|
-
},
|
|
548
|
-
|
|
549
|
-
getCoreRowModel: memo(
|
|
550
|
-
() => [instance.options.data],
|
|
551
|
-
(
|
|
552
|
-
data
|
|
553
|
-
): {
|
|
554
|
-
rows: Row<TGenerics>[]
|
|
555
|
-
flatRows: Row<TGenerics>[]
|
|
556
|
-
rowsById: Record<string, Row<TGenerics>>
|
|
557
|
-
} => {
|
|
558
|
-
// Access the row model using initial columns
|
|
559
|
-
const rows: Row<TGenerics>[] = []
|
|
560
|
-
const flatRows: Row<TGenerics>[] = []
|
|
561
|
-
const rowsById: Record<string, Row<TGenerics>> = {}
|
|
562
|
-
|
|
563
|
-
const leafColumns = instance.getAllLeafColumns()
|
|
564
|
-
|
|
565
|
-
const accessRow = (
|
|
566
|
-
originalRow: TGenerics['Row'],
|
|
567
|
-
rowIndex: number,
|
|
568
|
-
depth = 0,
|
|
569
|
-
parentRows: Row<TGenerics>[],
|
|
570
|
-
parent?: Row<TGenerics>
|
|
571
|
-
) => {
|
|
572
|
-
const id = instance.getRowId(originalRow, rowIndex, parent)
|
|
573
|
-
|
|
574
|
-
if (!id) {
|
|
575
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
576
|
-
throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
const values: Record<string, any> = {}
|
|
581
|
-
|
|
582
|
-
for (let i = 0; i < leafColumns.length; i++) {
|
|
583
|
-
const column = leafColumns[i]
|
|
584
|
-
if (column && column.accessorFn) {
|
|
585
|
-
values[column.id] = column.accessorFn(originalRow, rowIndex)
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// Make the row
|
|
590
|
-
const row = instance.createRow(
|
|
591
|
-
id,
|
|
592
|
-
originalRow,
|
|
593
|
-
rowIndex,
|
|
594
|
-
depth,
|
|
595
|
-
values
|
|
596
|
-
)
|
|
597
|
-
|
|
598
|
-
// Push instance row into the parentRows array
|
|
599
|
-
parentRows.push(row)
|
|
600
|
-
// Keep track of every row in a flat array
|
|
601
|
-
flatRows.push(row)
|
|
602
|
-
// Also keep track of every row by its ID
|
|
603
|
-
rowsById[id] = row
|
|
604
|
-
|
|
605
|
-
// Get the original subrows
|
|
606
|
-
if (instance.options.getSubRows) {
|
|
607
|
-
const originalSubRows = instance.options.getSubRows(
|
|
608
|
-
originalRow,
|
|
609
|
-
rowIndex
|
|
610
|
-
)
|
|
611
|
-
|
|
612
|
-
// Then recursively access them
|
|
613
|
-
if (originalSubRows?.length) {
|
|
614
|
-
row.originalSubRows = originalSubRows
|
|
615
|
-
const subRows: Row<TGenerics>[] = []
|
|
616
|
-
|
|
617
|
-
for (let i = 0; i < row.originalSubRows.length; i++) {
|
|
618
|
-
accessRow(
|
|
619
|
-
row.originalSubRows[i] as TGenerics['Row'],
|
|
620
|
-
i,
|
|
621
|
-
depth + 1,
|
|
622
|
-
subRows,
|
|
623
|
-
row
|
|
624
|
-
)
|
|
625
|
-
}
|
|
626
|
-
// Keep the new subRows array on the row
|
|
627
|
-
row.subRows = subRows
|
|
628
|
-
row.leafRows = flattenBy(subRows, d => d.leafRows)
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
for (let i = 0; i < data.length; i++) {
|
|
634
|
-
accessRow(data[i] as TGenerics['Row'], i, 0, rows)
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
return { rows, flatRows, rowsById }
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
key: 'getRowModel',
|
|
641
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
642
|
-
onChange: () => {
|
|
643
|
-
instance._notifyRowSelectionReset()
|
|
644
|
-
instance._notifyFiltersReset()
|
|
645
|
-
},
|
|
646
|
-
}
|
|
647
|
-
),
|
|
648
|
-
|
|
649
|
-
// The final calls start at the bottom of the model,
|
|
650
|
-
// expanded rows, which then work their way up
|
|
651
|
-
|
|
652
|
-
getRowModel: () => {
|
|
653
|
-
return instance.getPaginationRowModel()
|
|
654
|
-
},
|
|
655
|
-
|
|
656
|
-
getRow: (id: string) => {
|
|
657
|
-
const row = instance.getRowModel().rowsById[id]
|
|
658
|
-
|
|
659
|
-
if (!row) {
|
|
660
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
661
|
-
throw new Error(`getRow expected an ID, but got ${id}`)
|
|
662
|
-
}
|
|
663
|
-
throw new Error()
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
return row
|
|
667
|
-
},
|
|
668
|
-
|
|
669
|
-
getCell: (rowId: string, columnId: string) => {
|
|
670
|
-
const row = instance.getRow(rowId)
|
|
671
|
-
|
|
672
|
-
if (!row) {
|
|
673
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
674
|
-
throw new Error(`[React Table] could not find row with id ${rowId}`)
|
|
675
|
-
}
|
|
676
|
-
throw new Error()
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
const cell = row.getAllCellsByColumnId()[columnId]
|
|
680
|
-
|
|
681
|
-
if (!cell) {
|
|
682
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
683
|
-
throw new Error(
|
|
684
|
-
`[React Table] could not find cell ${columnId} in row ${rowId}`
|
|
685
|
-
)
|
|
686
|
-
}
|
|
687
|
-
throw new Error()
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
return cell
|
|
691
|
-
},
|
|
692
|
-
|
|
693
|
-
getTableProps: userProps => {
|
|
694
|
-
return propGetter(
|
|
695
|
-
{
|
|
696
|
-
role: 'table',
|
|
697
|
-
},
|
|
698
|
-
userProps
|
|
699
|
-
)
|
|
700
|
-
},
|
|
701
|
-
|
|
702
|
-
getTableBodyProps: userProps => {
|
|
703
|
-
return propGetter(
|
|
704
|
-
{
|
|
705
|
-
role: 'rowgroup',
|
|
706
|
-
},
|
|
707
|
-
userProps
|
|
708
|
-
)
|
|
709
|
-
},
|
|
710
|
-
|
|
711
|
-
getRowProps: (rowId, userProps) => {
|
|
712
|
-
const row = instance.getRow(rowId)
|
|
713
|
-
if (!row) {
|
|
714
|
-
return
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
return propGetter(
|
|
718
|
-
{
|
|
719
|
-
key: row.id,
|
|
720
|
-
role: 'row',
|
|
721
|
-
},
|
|
722
|
-
userProps
|
|
723
|
-
)
|
|
724
|
-
},
|
|
725
|
-
|
|
726
|
-
getCellProps: (rowId, columnId, userProps) => {
|
|
727
|
-
const cell = instance.getCell(rowId, columnId)
|
|
728
|
-
|
|
729
|
-
if (!cell) {
|
|
730
|
-
return
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
return propGetter(
|
|
734
|
-
{
|
|
735
|
-
key: cell.id,
|
|
736
|
-
role: 'gridcell',
|
|
737
|
-
},
|
|
738
|
-
userProps
|
|
739
|
-
)
|
|
740
|
-
},
|
|
741
|
-
|
|
742
|
-
getTableWidth: () =>
|
|
743
|
-
instance.getHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
744
|
-
return sum + header.getWidth()
|
|
745
|
-
}, 0) ?? 0,
|
|
746
|
-
getLeftTableWidth: () =>
|
|
747
|
-
instance.getLeftHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
748
|
-
return sum + header.getWidth()
|
|
749
|
-
}, 0) ?? 0,
|
|
750
|
-
getCenterTableWidth: () =>
|
|
751
|
-
instance.getCenterHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
752
|
-
return sum + header.getWidth()
|
|
753
|
-
}, 0) ?? 0,
|
|
754
|
-
getRightTableWidth: () =>
|
|
755
|
-
instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
756
|
-
return sum + header.getWidth()
|
|
757
|
-
}, 0) ?? 0,
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
instance = Object.assign(instance, finalInstance)
|
|
761
|
-
|
|
762
|
-
return instance
|
|
763
|
-
}
|