@tanstack/table-core 8.0.0-alpha.55 → 8.0.0-alpha.57
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/core.js +9 -384
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Cells.js +122 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +90 -37
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +216 -0
- package/build/cjs/features/Columns.js.map +1 -0
- package/build/cjs/features/Expanding.js +1 -1
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +78 -153
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +1 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +172 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +99 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +51 -17
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +876 -690
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +418 -316
- package/build/types/core.d.ts +2 -79
- package/build/types/features/Cells.d.ts +14 -0
- package/build/types/features/ColumnSizing.d.ts +23 -15
- package/build/types/features/Columns.d.ts +54 -0
- package/build/types/features/Expanding.d.ts +1 -1
- package/build/types/features/Filters.d.ts +1 -1
- package/build/types/features/Grouping.d.ts +1 -1
- package/build/types/features/Headers.d.ts +3 -11
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +1 -1
- package/build/types/features/Pinning.d.ts +18 -4
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Rows.d.ts +29 -0
- package/build/types/features/Sorting.d.ts +1 -1
- package/build/types/features/Visibility.d.ts +7 -2
- package/build/types/types.d.ts +18 -10
- package/build/types/utils.d.ts +0 -1
- package/build/umd/index.development.js +854 -668
- 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 +1 -1
- package/src/core.ts +28 -550
- package/src/features/Cells.ts +156 -0
- package/src/features/ColumnSizing.ts +99 -47
- package/src/features/Columns.ts +290 -0
- package/src/features/Expanding.ts +1 -1
- package/src/features/Filters.ts +1 -1
- package/src/features/Grouping.ts +1 -1
- package/src/features/Headers.ts +48 -138
- package/src/features/Ordering.ts +1 -1
- package/src/features/Pagination.ts +1 -1
- package/src/features/Pinning.ts +194 -3
- package/src/features/RowSelection.ts +1 -1
- package/src/features/Rows.ts +151 -0
- package/src/features/Sorting.ts +1 -1
- package/src/features/Visibility.ts +67 -20
- package/src/types.ts +25 -37
- package/src/utils.ts +1 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.57",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/core.ts
CHANGED
|
@@ -1,39 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flattenBy,
|
|
3
|
-
functionalUpdate,
|
|
4
|
-
propGetter,
|
|
5
|
-
memo,
|
|
6
|
-
RequiredKeys,
|
|
7
|
-
} from './utils'
|
|
1
|
+
import { functionalUpdate, propGetter, RequiredKeys } from './utils'
|
|
8
2
|
|
|
9
3
|
import {
|
|
10
4
|
Updater,
|
|
11
|
-
PropGetterValue,
|
|
12
5
|
Options,
|
|
13
6
|
TableState,
|
|
14
7
|
ColumnDef,
|
|
15
|
-
Row,
|
|
16
|
-
Column,
|
|
17
|
-
Cell,
|
|
18
|
-
Header,
|
|
19
|
-
AccessorFn,
|
|
20
|
-
HeaderRenderProps,
|
|
21
8
|
TableProps,
|
|
22
9
|
TableBodyProps,
|
|
23
10
|
PropGetter,
|
|
24
|
-
Getter,
|
|
25
|
-
RowProps,
|
|
26
|
-
CellProps,
|
|
27
11
|
TableInstance,
|
|
28
|
-
RowValues,
|
|
29
|
-
CoreCell,
|
|
30
12
|
Renderable,
|
|
31
13
|
UseRenderer,
|
|
32
|
-
RowModel,
|
|
33
14
|
TableFeature,
|
|
34
15
|
TableGenerics,
|
|
35
16
|
} from './types'
|
|
36
17
|
|
|
18
|
+
import { Columns } from './features/Columns'
|
|
19
|
+
import { Rows } from './features/Rows'
|
|
20
|
+
import { Cells } from './features/Cells'
|
|
37
21
|
import { ColumnSizing } from './features/ColumnSizing'
|
|
38
22
|
import { Expanding } from './features/Expanding'
|
|
39
23
|
import { Filters } from './features/Filters'
|
|
@@ -45,51 +29,24 @@ import { RowSelection } from './features/RowSelection'
|
|
|
45
29
|
import { Sorting } from './features/Sorting'
|
|
46
30
|
import { Visibility } from './features/Visibility'
|
|
47
31
|
import { Headers } from './features/Headers'
|
|
32
|
+
//
|
|
48
33
|
import { mean } from './aggregationFns'
|
|
49
34
|
|
|
50
|
-
const features: TableFeature[] = [
|
|
51
|
-
Headers,
|
|
52
|
-
Visibility,
|
|
53
|
-
Ordering,
|
|
54
|
-
Pinning,
|
|
55
|
-
Filters,
|
|
56
|
-
Sorting,
|
|
57
|
-
Grouping,
|
|
58
|
-
Expanding,
|
|
59
|
-
Pagination,
|
|
60
|
-
RowSelection,
|
|
61
|
-
ColumnSizing,
|
|
62
|
-
]
|
|
63
|
-
|
|
64
35
|
export type CoreTableState = {
|
|
65
36
|
coreProgress: number
|
|
66
37
|
}
|
|
67
38
|
|
|
68
39
|
export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
69
40
|
data: TGenerics['Row'][]
|
|
70
|
-
columns: ColumnDef<TGenerics>[]
|
|
71
41
|
state: Partial<TableState>
|
|
72
42
|
onStateChange: (updater: Updater<TableState>) => void
|
|
73
43
|
render: TGenerics['Render']
|
|
74
|
-
getCoreRowModel: (
|
|
75
|
-
instance: TableInstance<TGenerics>
|
|
76
|
-
) => () => RowModel<TGenerics>
|
|
77
44
|
debugAll?: boolean
|
|
78
45
|
debugTable?: boolean
|
|
79
46
|
debugHeaders?: boolean
|
|
80
47
|
debugColumns?: boolean
|
|
81
48
|
debugRows?: boolean
|
|
82
|
-
defaultColumn?: Partial<ColumnDef<TGenerics>>
|
|
83
49
|
initialState?: Partial<TableState>
|
|
84
|
-
getSubRows?: (
|
|
85
|
-
originalRow: TGenerics['Row'],
|
|
86
|
-
index: number
|
|
87
|
-
) => TGenerics['Row'][]
|
|
88
|
-
getRowId?: (
|
|
89
|
-
originalRow: TGenerics['Row'],
|
|
90
|
-
index: number,
|
|
91
|
-
parent?: Row<TGenerics>
|
|
92
|
-
) => string
|
|
93
50
|
autoResetAll?: boolean
|
|
94
51
|
mergeOptions?: (
|
|
95
52
|
defaultOptions: TableFeature,
|
|
@@ -105,127 +62,16 @@ export type TableCore<TGenerics extends TableGenerics> = {
|
|
|
105
62
|
setOptions: (newOptions: Updater<Options<TGenerics>>) => void
|
|
106
63
|
queue: (cb: () => void) => void
|
|
107
64
|
willUpdate: () => void
|
|
108
|
-
getRowId: (
|
|
109
|
-
_: TGenerics['Row'],
|
|
110
|
-
index: number,
|
|
111
|
-
parent?: Row<TGenerics>
|
|
112
|
-
) => string
|
|
113
65
|
getState: () => TableState
|
|
114
66
|
setState: (updater: Updater<TableState>) => void
|
|
115
|
-
getDefaultColumn: () => Partial<ColumnDef<TGenerics>>
|
|
116
|
-
getColumnDefs: () => ColumnDef<TGenerics>[]
|
|
117
|
-
createColumn: (
|
|
118
|
-
columnDef: ColumnDef<TGenerics>,
|
|
119
|
-
depth: number,
|
|
120
|
-
parent?: Column<TGenerics>
|
|
121
|
-
) => Column<TGenerics>
|
|
122
|
-
getAllColumns: () => Column<TGenerics>[]
|
|
123
|
-
getAllFlatColumns: () => Column<TGenerics>[]
|
|
124
|
-
getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
|
|
125
|
-
getAllLeafColumns: () => Column<TGenerics>[]
|
|
126
|
-
getColumn: (columnId: string) => Column<TGenerics>
|
|
127
|
-
getTotalWidth: () => number
|
|
128
|
-
createCell: (
|
|
129
|
-
row: Row<TGenerics>,
|
|
130
|
-
column: Column<TGenerics>,
|
|
131
|
-
value: any
|
|
132
|
-
) => Cell<TGenerics>
|
|
133
|
-
createRow: (
|
|
134
|
-
id: string,
|
|
135
|
-
original: TGenerics['Row'] | undefined,
|
|
136
|
-
rowIndex: number,
|
|
137
|
-
depth: number,
|
|
138
|
-
values: Record<string, any>
|
|
139
|
-
) => Row<TGenerics>
|
|
140
|
-
getCoreRowModel: () => RowModel<TGenerics>
|
|
141
|
-
_getCoreRowModel?: () => RowModel<TGenerics>
|
|
142
|
-
getRowModel: () => RowModel<TGenerics>
|
|
143
|
-
getRow: (id: string) => Row<TGenerics>
|
|
144
|
-
getCell: (rowId: string, columnId: string) => Cell<TGenerics>
|
|
145
67
|
getTableProps: PropGetter<TableProps>
|
|
146
68
|
getTableBodyProps: PropGetter<TableBodyProps>
|
|
147
|
-
getRowProps: <TGetter extends Getter<RowProps>>(
|
|
148
|
-
rowId: string,
|
|
149
|
-
userProps?: TGetter
|
|
150
|
-
) => undefined | PropGetterValue<RowProps, TGetter>
|
|
151
|
-
getCellProps: <TGetter extends Getter<CellProps>>(
|
|
152
|
-
rowId: string,
|
|
153
|
-
columnId: string,
|
|
154
|
-
userProps?: TGetter
|
|
155
|
-
) => undefined | PropGetterValue<CellProps, TGetter>
|
|
156
|
-
getTableWidth: () => number
|
|
157
|
-
getLeftTableWidth: () => number
|
|
158
|
-
getCenterTableWidth: () => number
|
|
159
|
-
getRightTableWidth: () => number
|
|
160
69
|
render: <TProps>(
|
|
161
70
|
template: Renderable<TGenerics, TProps>,
|
|
162
71
|
props: TProps
|
|
163
72
|
) => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
164
73
|
getOverallProgress: () => number
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
export type CoreRow<TGenerics extends TableGenerics> = {
|
|
168
|
-
id: string
|
|
169
|
-
index: number
|
|
170
|
-
original?: TGenerics['Row']
|
|
171
|
-
depth: number
|
|
172
|
-
values: RowValues
|
|
173
|
-
subRows: Row<TGenerics>[]
|
|
174
|
-
getLeafRows: () => Row<TGenerics>[]
|
|
175
|
-
getRowProps: PropGetter<RowProps>
|
|
176
|
-
originalSubRows?: TGenerics['Row'][]
|
|
177
|
-
getAllCells: () => Cell<TGenerics>[]
|
|
178
|
-
getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export type CoreColumnDef<TGenerics extends TableGenerics> = {
|
|
182
|
-
id: string
|
|
183
|
-
accessorKey?: string & keyof TGenerics['Row']
|
|
184
|
-
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
185
|
-
columns?: ColumnDef<TGenerics>[]
|
|
186
|
-
header?: Renderable<
|
|
187
|
-
TGenerics,
|
|
188
|
-
{
|
|
189
|
-
instance: TableInstance<TGenerics>
|
|
190
|
-
header: Header<TGenerics>
|
|
191
|
-
column: Column<TGenerics>
|
|
192
|
-
}
|
|
193
|
-
>
|
|
194
|
-
footer?: Renderable<
|
|
195
|
-
TGenerics,
|
|
196
|
-
{
|
|
197
|
-
instance: TableInstance<TGenerics>
|
|
198
|
-
header: Header<TGenerics>
|
|
199
|
-
column: Column<TGenerics>
|
|
200
|
-
}
|
|
201
|
-
>
|
|
202
|
-
cell?: Renderable<
|
|
203
|
-
TGenerics,
|
|
204
|
-
{
|
|
205
|
-
instance: TableInstance<TGenerics>
|
|
206
|
-
row: Row<TGenerics>
|
|
207
|
-
column: Column<TGenerics>
|
|
208
|
-
cell: Cell<TGenerics>
|
|
209
|
-
value: TGenerics['Value']
|
|
210
|
-
}
|
|
211
|
-
>
|
|
212
|
-
meta?: TGenerics['ColumnMeta']
|
|
213
|
-
}
|
|
214
|
-
// & GeneratedProperties<true>
|
|
215
|
-
|
|
216
|
-
export type CoreColumnDefType = 'data' | 'display' | 'group'
|
|
217
|
-
|
|
218
|
-
export type CoreColumn<TGenerics extends TableGenerics> = {
|
|
219
|
-
id: string
|
|
220
|
-
depth: number
|
|
221
|
-
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
222
|
-
columnDef: ColumnDef<TGenerics>
|
|
223
|
-
columnDefType: CoreColumnDefType
|
|
224
|
-
getWidth: () => number
|
|
225
|
-
columns: Column<TGenerics>[]
|
|
226
|
-
parent?: Column<TGenerics>
|
|
227
|
-
getFlatColumns: () => Column<TGenerics>[]
|
|
228
|
-
getLeafColumns: () => Column<TGenerics>[]
|
|
74
|
+
_features: readonly TableFeature[]
|
|
229
75
|
}
|
|
230
76
|
|
|
231
77
|
export function createTableInstance<TGenerics extends TableGenerics>(
|
|
@@ -237,7 +83,24 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
237
83
|
|
|
238
84
|
let instance = {} as TableInstance<TGenerics>
|
|
239
85
|
|
|
240
|
-
|
|
86
|
+
instance._features = [
|
|
87
|
+
Columns,
|
|
88
|
+
Rows,
|
|
89
|
+
Cells,
|
|
90
|
+
Headers,
|
|
91
|
+
Visibility,
|
|
92
|
+
Ordering,
|
|
93
|
+
Pinning,
|
|
94
|
+
Filters,
|
|
95
|
+
Sorting,
|
|
96
|
+
Grouping,
|
|
97
|
+
Expanding,
|
|
98
|
+
Pagination,
|
|
99
|
+
RowSelection,
|
|
100
|
+
ColumnSizing,
|
|
101
|
+
] as const
|
|
102
|
+
|
|
103
|
+
const defaultOptions = instance._features.reduce((obj, feature) => {
|
|
241
104
|
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
242
105
|
}, {})
|
|
243
106
|
|
|
@@ -254,7 +117,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
254
117
|
|
|
255
118
|
const initialState = {
|
|
256
119
|
...coreInitialState,
|
|
257
|
-
...
|
|
120
|
+
...instance._features.reduce((obj, feature) => {
|
|
258
121
|
return Object.assign(obj, feature.getInitialState?.())
|
|
259
122
|
}, {}),
|
|
260
123
|
...(options.initialState ?? {}),
|
|
@@ -265,9 +128,9 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
265
128
|
|
|
266
129
|
const finalInstance: TableInstance<TGenerics> = {
|
|
267
130
|
...instance,
|
|
268
|
-
...
|
|
269
|
-
return Object.assign(obj, feature.
|
|
270
|
-
}, {}),
|
|
131
|
+
...(instance._features.reduce((obj, feature) => {
|
|
132
|
+
return Object.assign(obj, feature.createInstance?.(instance))
|
|
133
|
+
}, {}) as unknown as TableInstance<TGenerics>),
|
|
271
134
|
queue: cb => {
|
|
272
135
|
queued.push(cb)
|
|
273
136
|
if (!queuedTimeout) {
|
|
@@ -309,10 +172,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
309
172
|
return template
|
|
310
173
|
},
|
|
311
174
|
|
|
312
|
-
getRowId: (row: TGenerics['Row'], index: number, parent?: Row<TGenerics>) =>
|
|
313
|
-
instance.options.getRowId?.(row, index, parent) ??
|
|
314
|
-
`${parent ? [parent.id, index].join('.') : index}`,
|
|
315
|
-
|
|
316
175
|
getState: () => {
|
|
317
176
|
return instance.options.state as TableState
|
|
318
177
|
},
|
|
@@ -321,339 +180,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
321
180
|
instance.options.onStateChange?.(updater)
|
|
322
181
|
},
|
|
323
182
|
|
|
324
|
-
getDefaultColumn: memo(
|
|
325
|
-
() => [instance.options.defaultColumn],
|
|
326
|
-
defaultColumn => {
|
|
327
|
-
defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
|
|
328
|
-
|
|
329
|
-
return {
|
|
330
|
-
header: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
331
|
-
props.header.column.id,
|
|
332
|
-
footer: (props: HeaderRenderProps<Header<TGenerics>>) =>
|
|
333
|
-
props.header.column.id,
|
|
334
|
-
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
335
|
-
typeof value === 'boolean' ? value.toString() : value,
|
|
336
|
-
...features.reduce((obj, feature) => {
|
|
337
|
-
return Object.assign(obj, feature.getDefaultColumn?.())
|
|
338
|
-
}, {}),
|
|
339
|
-
...defaultColumn,
|
|
340
|
-
} as Partial<ColumnDef<TGenerics>>
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
344
|
-
key: 'getDefaultColumn',
|
|
345
|
-
}
|
|
346
|
-
),
|
|
347
|
-
|
|
348
|
-
getColumnDefs: () => instance.options.columns,
|
|
349
|
-
|
|
350
|
-
createColumn: (
|
|
351
|
-
columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
|
|
352
|
-
depth: number,
|
|
353
|
-
parent
|
|
354
|
-
) => {
|
|
355
|
-
const defaultColumn = instance.getDefaultColumn()
|
|
356
|
-
|
|
357
|
-
let id =
|
|
358
|
-
columnDef.id ??
|
|
359
|
-
columnDef.accessorKey ??
|
|
360
|
-
(typeof columnDef.header === 'string' ? columnDef.header : undefined)
|
|
361
|
-
|
|
362
|
-
let accessorFn: AccessorFn<TGenerics['Row']> | undefined
|
|
363
|
-
|
|
364
|
-
if (columnDef.accessorFn) {
|
|
365
|
-
accessorFn = columnDef.accessorFn
|
|
366
|
-
} else if (columnDef.accessorKey) {
|
|
367
|
-
accessorFn = (originalRow?: TGenerics['Row']) =>
|
|
368
|
-
(originalRow as any)[columnDef.accessorKey]
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (!id) {
|
|
372
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
373
|
-
throw new Error(
|
|
374
|
-
columnDef.accessorFn
|
|
375
|
-
? `Columns require an id when using an accessorFn`
|
|
376
|
-
: `Columns require an id when using a non-string header`
|
|
377
|
-
)
|
|
378
|
-
}
|
|
379
|
-
throw new Error()
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
let column: CoreColumn<TGenerics> = {
|
|
383
|
-
...defaultColumn,
|
|
384
|
-
...columnDef,
|
|
385
|
-
id: `${id}`,
|
|
386
|
-
accessorFn,
|
|
387
|
-
parent: parent as any,
|
|
388
|
-
depth,
|
|
389
|
-
columnDef,
|
|
390
|
-
columnDefType: columnDef.columnDefType as CoreColumnDefType,
|
|
391
|
-
columns: [],
|
|
392
|
-
getWidth: () => instance.getColumnWidth(column.id),
|
|
393
|
-
getFlatColumns: memo(
|
|
394
|
-
() => [true],
|
|
395
|
-
() => {
|
|
396
|
-
return [
|
|
397
|
-
column as Column<TGenerics>,
|
|
398
|
-
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
399
|
-
]
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
key: 'column.getFlatColumns',
|
|
403
|
-
debug: () =>
|
|
404
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
405
|
-
}
|
|
406
|
-
),
|
|
407
|
-
getLeafColumns: memo(
|
|
408
|
-
() => [instance._getOrderColumnsFn()],
|
|
409
|
-
orderColumns => {
|
|
410
|
-
if (column.columns?.length) {
|
|
411
|
-
let leafColumns = column.columns.flatMap(column =>
|
|
412
|
-
column.getLeafColumns()
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
return orderColumns(leafColumns)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return [column as Column<TGenerics>]
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
key: 'column.getLeafColumns',
|
|
422
|
-
debug: () =>
|
|
423
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
424
|
-
}
|
|
425
|
-
),
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
column = features.reduce((obj, feature) => {
|
|
429
|
-
return Object.assign(obj, feature.createColumn?.(column, instance))
|
|
430
|
-
}, column)
|
|
431
|
-
|
|
432
|
-
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
433
|
-
return column as Column<TGenerics>
|
|
434
|
-
},
|
|
435
|
-
|
|
436
|
-
getAllColumns: memo(
|
|
437
|
-
() => [instance.getColumnDefs()],
|
|
438
|
-
columnDefs => {
|
|
439
|
-
const recurseColumns = (
|
|
440
|
-
columnDefs: ColumnDef<TGenerics>[],
|
|
441
|
-
parent?: Column<TGenerics>,
|
|
442
|
-
depth = 0
|
|
443
|
-
): Column<TGenerics>[] => {
|
|
444
|
-
return columnDefs.map(columnDef => {
|
|
445
|
-
const column = instance.createColumn(columnDef, depth, parent)
|
|
446
|
-
|
|
447
|
-
column.columns = columnDef.columns
|
|
448
|
-
? recurseColumns(columnDef.columns, column, depth + 1)
|
|
449
|
-
: []
|
|
450
|
-
|
|
451
|
-
return column
|
|
452
|
-
})
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return recurseColumns(columnDefs)
|
|
456
|
-
},
|
|
457
|
-
{
|
|
458
|
-
key: 'getAllColumns',
|
|
459
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
460
|
-
}
|
|
461
|
-
),
|
|
462
|
-
|
|
463
|
-
getAllFlatColumns: memo(
|
|
464
|
-
() => [instance.getAllColumns()],
|
|
465
|
-
allColumns => {
|
|
466
|
-
return allColumns.flatMap(column => {
|
|
467
|
-
return column.getFlatColumns()
|
|
468
|
-
})
|
|
469
|
-
},
|
|
470
|
-
{
|
|
471
|
-
key: 'getAllFlatColumns',
|
|
472
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
473
|
-
}
|
|
474
|
-
),
|
|
475
|
-
|
|
476
|
-
getAllFlatColumnsById: memo(
|
|
477
|
-
() => [instance.getAllFlatColumns()],
|
|
478
|
-
flatColumns => {
|
|
479
|
-
return flatColumns.reduce((acc, column) => {
|
|
480
|
-
acc[column.id] = column
|
|
481
|
-
return acc
|
|
482
|
-
}, {} as Record<string, Column<TGenerics>>)
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
key: 'getAllFlatColumnsById',
|
|
486
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
487
|
-
}
|
|
488
|
-
),
|
|
489
|
-
|
|
490
|
-
getAllLeafColumns: memo(
|
|
491
|
-
() => [instance.getAllColumns(), instance._getOrderColumnsFn()],
|
|
492
|
-
(allColumns, orderColumns) => {
|
|
493
|
-
let leafColumns = allColumns.flatMap(column => column.getLeafColumns())
|
|
494
|
-
return orderColumns(leafColumns)
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
key: 'getAllLeafColumns',
|
|
498
|
-
debug: () => instance.options.debugAll ?? instance.options.debugColumns,
|
|
499
|
-
}
|
|
500
|
-
),
|
|
501
|
-
|
|
502
|
-
getColumn: columnId => {
|
|
503
|
-
const column = instance.getAllFlatColumnsById()[columnId]
|
|
504
|
-
|
|
505
|
-
if (!column) {
|
|
506
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
507
|
-
console.warn(`[Table] Column with id ${columnId} does not exist.`)
|
|
508
|
-
}
|
|
509
|
-
throw new Error()
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
return column
|
|
513
|
-
},
|
|
514
|
-
|
|
515
|
-
createCell: (row, column, value) => {
|
|
516
|
-
const cell: CoreCell<TGenerics> = {
|
|
517
|
-
id: `${row.id}_${column.id}`,
|
|
518
|
-
rowId: row.id,
|
|
519
|
-
columnId: column.id,
|
|
520
|
-
row,
|
|
521
|
-
column,
|
|
522
|
-
value,
|
|
523
|
-
getCellProps: userProps =>
|
|
524
|
-
instance.getCellProps(row.id, column.id, userProps)!,
|
|
525
|
-
renderCell: () =>
|
|
526
|
-
column.cell
|
|
527
|
-
? instance.render(column.cell, {
|
|
528
|
-
instance,
|
|
529
|
-
column,
|
|
530
|
-
row,
|
|
531
|
-
cell: cell as Cell<TGenerics>,
|
|
532
|
-
value,
|
|
533
|
-
})
|
|
534
|
-
: null,
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
features.forEach(feature => {
|
|
538
|
-
Object.assign(
|
|
539
|
-
cell,
|
|
540
|
-
feature.createCell?.(
|
|
541
|
-
cell as Cell<TGenerics>,
|
|
542
|
-
column,
|
|
543
|
-
row as Row<TGenerics>,
|
|
544
|
-
instance
|
|
545
|
-
)
|
|
546
|
-
)
|
|
547
|
-
}, {})
|
|
548
|
-
|
|
549
|
-
return cell as Cell<TGenerics>
|
|
550
|
-
},
|
|
551
|
-
|
|
552
|
-
createRow: (id, original, rowIndex, depth, values) => {
|
|
553
|
-
let row: CoreRow<TGenerics> = {
|
|
554
|
-
id,
|
|
555
|
-
index: rowIndex,
|
|
556
|
-
original,
|
|
557
|
-
depth,
|
|
558
|
-
values,
|
|
559
|
-
subRows: [],
|
|
560
|
-
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
561
|
-
getRowProps: userProps => instance.getRowProps(row.id, userProps)!,
|
|
562
|
-
getAllCells: undefined!,
|
|
563
|
-
getAllCellsByColumnId: undefined!,
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
row.getAllCells = memo(
|
|
567
|
-
() => [instance.getAllLeafColumns()],
|
|
568
|
-
leafColumns => {
|
|
569
|
-
return leafColumns.map(column => {
|
|
570
|
-
return instance.createCell(
|
|
571
|
-
row as Row<TGenerics>,
|
|
572
|
-
column,
|
|
573
|
-
row.values[column.id]
|
|
574
|
-
)
|
|
575
|
-
})
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
key: process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '',
|
|
579
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
580
|
-
}
|
|
581
|
-
)
|
|
582
|
-
|
|
583
|
-
row.getAllCellsByColumnId = memo(
|
|
584
|
-
() => [row.getAllCells()],
|
|
585
|
-
allCells => {
|
|
586
|
-
return allCells.reduce((acc, cell) => {
|
|
587
|
-
acc[cell.columnId] = cell
|
|
588
|
-
return acc
|
|
589
|
-
}, {} as Record<string, Cell<TGenerics>>)
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
key: 'row.getAllCellsByColumnId',
|
|
593
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
594
|
-
}
|
|
595
|
-
)
|
|
596
|
-
|
|
597
|
-
for (let i = 0; i < features.length; i++) {
|
|
598
|
-
const feature = features[i]
|
|
599
|
-
Object.assign(row, feature.createRow?.(row, instance))
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
return row as Row<TGenerics>
|
|
603
|
-
},
|
|
604
|
-
|
|
605
|
-
getCoreRowModel: () => {
|
|
606
|
-
if (!instance._getCoreRowModel) {
|
|
607
|
-
instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
return instance._getCoreRowModel()
|
|
611
|
-
},
|
|
612
|
-
|
|
613
|
-
// The final calls start at the bottom of the model,
|
|
614
|
-
// expanded rows, which then work their way up
|
|
615
|
-
|
|
616
|
-
getRowModel: () => {
|
|
617
|
-
return instance.getPaginationRowModel()
|
|
618
|
-
},
|
|
619
|
-
|
|
620
|
-
getRow: (id: string) => {
|
|
621
|
-
const row = instance.getRowModel().rowsById[id]
|
|
622
|
-
|
|
623
|
-
if (!row) {
|
|
624
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
625
|
-
throw new Error(`getRow expected an ID, but got ${id}`)
|
|
626
|
-
}
|
|
627
|
-
throw new Error()
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
return row
|
|
631
|
-
},
|
|
632
|
-
|
|
633
|
-
getCell: (rowId: string, columnId: string) => {
|
|
634
|
-
const row = instance.getRow(rowId)
|
|
635
|
-
|
|
636
|
-
if (!row) {
|
|
637
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
638
|
-
throw new Error(`[Table] could not find row with id ${rowId}`)
|
|
639
|
-
}
|
|
640
|
-
throw new Error()
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const cell = row.getAllCellsByColumnId()[columnId]
|
|
644
|
-
|
|
645
|
-
if (!cell) {
|
|
646
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
647
|
-
throw new Error(
|
|
648
|
-
`[Table] could not find cell ${columnId} in row ${rowId}`
|
|
649
|
-
)
|
|
650
|
-
}
|
|
651
|
-
throw new Error()
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return cell
|
|
655
|
-
},
|
|
656
|
-
|
|
657
183
|
getTableProps: userProps => {
|
|
658
184
|
return propGetter(
|
|
659
185
|
{
|
|
@@ -672,54 +198,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
672
198
|
)
|
|
673
199
|
},
|
|
674
200
|
|
|
675
|
-
getRowProps: (rowId, userProps) => {
|
|
676
|
-
const row = instance.getRow(rowId)
|
|
677
|
-
if (!row) {
|
|
678
|
-
return
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
return propGetter(
|
|
682
|
-
{
|
|
683
|
-
key: row.id,
|
|
684
|
-
role: 'row',
|
|
685
|
-
},
|
|
686
|
-
userProps
|
|
687
|
-
)
|
|
688
|
-
},
|
|
689
|
-
|
|
690
|
-
getCellProps: (rowId, columnId, userProps) => {
|
|
691
|
-
const cell = instance.getCell(rowId, columnId)
|
|
692
|
-
|
|
693
|
-
if (!cell) {
|
|
694
|
-
return
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
return propGetter(
|
|
698
|
-
{
|
|
699
|
-
key: cell.id,
|
|
700
|
-
role: 'gridcell',
|
|
701
|
-
},
|
|
702
|
-
userProps
|
|
703
|
-
)
|
|
704
|
-
},
|
|
705
|
-
|
|
706
|
-
getTableWidth: () =>
|
|
707
|
-
instance.getHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
708
|
-
return sum + header.getWidth()
|
|
709
|
-
}, 0) ?? 0,
|
|
710
|
-
getLeftTableWidth: () =>
|
|
711
|
-
instance.getLeftHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
712
|
-
return sum + header.getWidth()
|
|
713
|
-
}, 0) ?? 0,
|
|
714
|
-
getCenterTableWidth: () =>
|
|
715
|
-
instance.getCenterHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
716
|
-
return sum + header.getWidth()
|
|
717
|
-
}, 0) ?? 0,
|
|
718
|
-
getRightTableWidth: () =>
|
|
719
|
-
instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
720
|
-
return sum + header.getWidth()
|
|
721
|
-
}, 0) ?? 0,
|
|
722
|
-
|
|
723
201
|
getOverallProgress: () => {
|
|
724
202
|
const { coreProgress, columnFiltersProgress, globalFilterProgress } =
|
|
725
203
|
instance.getState()
|