@tanstack/table-core 8.0.0-alpha.55 → 8.0.0-alpha.59

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.
Files changed (88) hide show
  1. package/build/cjs/core.js +18 -404
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +3 -3
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/Cells.js +107 -0
  6. package/build/cjs/features/Cells.js.map +1 -0
  7. package/build/cjs/features/ColumnSizing.js +96 -54
  8. package/build/cjs/features/ColumnSizing.js.map +1 -1
  9. package/build/cjs/features/Columns.js +216 -0
  10. package/build/cjs/features/Columns.js.map +1 -0
  11. package/build/cjs/features/Expanding.js +13 -21
  12. package/build/cjs/features/Expanding.js.map +1 -1
  13. package/build/cjs/features/Filters.js +3 -3
  14. package/build/cjs/features/Filters.js.map +1 -1
  15. package/build/cjs/features/Grouping.js +8 -11
  16. package/build/cjs/features/Grouping.js.map +1 -1
  17. package/build/cjs/features/Headers.js +79 -220
  18. package/build/cjs/features/Headers.js.map +1 -1
  19. package/build/cjs/features/Ordering.js +1 -1
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js +5 -5
  22. package/build/cjs/features/Pagination.js.map +1 -1
  23. package/build/cjs/features/Pinning.js +172 -2
  24. package/build/cjs/features/Pinning.js.map +1 -1
  25. package/build/cjs/features/RowSelection.js +16 -48
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Rows.js +84 -0
  28. package/build/cjs/features/Rows.js.map +1 -0
  29. package/build/cjs/features/Sorting.js +9 -12
  30. package/build/cjs/features/Sorting.js.map +1 -1
  31. package/build/cjs/features/Visibility.js +59 -38
  32. package/build/cjs/features/Visibility.js.map +1 -1
  33. package/build/cjs/filterFns.js +16 -0
  34. package/build/cjs/filterFns.js.map +1 -1
  35. package/build/cjs/index.js +0 -1
  36. package/build/cjs/index.js.map +1 -1
  37. package/build/cjs/utils.js +0 -16
  38. package/build/cjs/utils.js.map +1 -1
  39. package/build/esm/index.js +866 -856
  40. package/build/esm/index.js.map +1 -1
  41. package/build/stats-html.html +1 -1
  42. package/build/stats-react.json +424 -322
  43. package/build/types/core.d.ts +9 -88
  44. package/build/types/createTable.d.ts +10 -11
  45. package/build/types/features/Cells.d.ts +13 -0
  46. package/build/types/features/ColumnSizing.d.ts +24 -30
  47. package/build/types/features/Columns.d.ts +54 -0
  48. package/build/types/features/Expanding.d.ts +6 -9
  49. package/build/types/features/Filters.d.ts +3 -1
  50. package/build/types/features/Grouping.d.ts +6 -9
  51. package/build/types/features/Headers.d.ts +3 -15
  52. package/build/types/features/Ordering.d.ts +1 -1
  53. package/build/types/features/Pagination.d.ts +6 -6
  54. package/build/types/features/Pinning.d.ts +18 -4
  55. package/build/types/features/RowSelection.d.ts +6 -13
  56. package/build/types/features/Rows.d.ts +27 -0
  57. package/build/types/features/Sorting.d.ts +5 -8
  58. package/build/types/features/Visibility.d.ts +9 -7
  59. package/build/types/filterFns.d.ts +5 -0
  60. package/build/types/types.d.ts +27 -69
  61. package/build/types/utils.d.ts +1 -5
  62. package/build/umd/index.development.js +844 -835
  63. package/build/umd/index.development.js.map +1 -1
  64. package/build/umd/index.production.js +1 -1
  65. package/build/umd/index.production.js.map +1 -1
  66. package/package.json +1 -1
  67. package/src/core.ts +55 -601
  68. package/src/createTable.ts +13 -17
  69. package/src/features/Cells.ts +130 -0
  70. package/src/features/ColumnSizing.ts +111 -89
  71. package/src/features/Columns.ts +288 -0
  72. package/src/features/Expanding.ts +20 -42
  73. package/src/features/Filters.ts +11 -3
  74. package/src/features/Grouping.ts +13 -39
  75. package/src/features/Headers.ts +49 -233
  76. package/src/features/Ordering.ts +1 -1
  77. package/src/features/Pagination.ts +14 -4
  78. package/src/features/Pinning.ts +194 -3
  79. package/src/features/RowSelection.ts +26 -88
  80. package/src/features/Rows.ts +123 -0
  81. package/src/features/Sorting.ts +20 -43
  82. package/src/features/Visibility.ts +82 -63
  83. package/src/filterFns.ts +20 -0
  84. package/src/types.ts +59 -133
  85. package/src/utils/getColumnFilteredRowModelAsync.ts +1 -5
  86. package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -6
  87. package/src/utils/getSortedRowModelAsync.ts +0 -1
  88. package/src/utils.ts +2 -31
package/src/core.ts CHANGED
@@ -1,39 +1,19 @@
1
- import {
2
- flattenBy,
3
- functionalUpdate,
4
- propGetter,
5
- memo,
6
- RequiredKeys,
7
- } from './utils'
1
+ import { functionalUpdate, RequiredKeys } from './utils'
8
2
 
9
3
  import {
10
4
  Updater,
11
- PropGetterValue,
12
- Options,
5
+ TableOptions,
13
6
  TableState,
14
- ColumnDef,
15
- Row,
16
- Column,
17
- Cell,
18
- Header,
19
- AccessorFn,
20
- HeaderRenderProps,
21
- TableProps,
22
- TableBodyProps,
23
- PropGetter,
24
- Getter,
25
- RowProps,
26
- CellProps,
27
7
  TableInstance,
28
- RowValues,
29
- CoreCell,
30
8
  Renderable,
31
- UseRenderer,
32
- RowModel,
33
9
  TableFeature,
34
10
  TableGenerics,
11
+ InitialTableState,
35
12
  } from './types'
36
13
 
14
+ import { Columns } from './features/Columns'
15
+ import { Rows } from './features/Rows'
16
+ import { Cells } from './features/Cells'
37
17
  import { ColumnSizing } from './features/ColumnSizing'
38
18
  import { Expanding } from './features/Expanding'
39
19
  import { Filters } from './features/Filters'
@@ -45,191 +25,49 @@ import { RowSelection } from './features/RowSelection'
45
25
  import { Sorting } from './features/Sorting'
46
26
  import { Visibility } from './features/Visibility'
47
27
  import { Headers } from './features/Headers'
28
+ //
48
29
  import { mean } from './aggregationFns'
49
30
 
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
31
  export type CoreTableState = {
65
32
  coreProgress: number
66
33
  }
67
34
 
68
35
  export type CoreOptions<TGenerics extends TableGenerics> = {
69
36
  data: TGenerics['Row'][]
70
- columns: ColumnDef<TGenerics>[]
71
37
  state: Partial<TableState>
72
38
  onStateChange: (updater: Updater<TableState>) => void
73
- render: TGenerics['Render']
74
- getCoreRowModel: (
75
- instance: TableInstance<TGenerics>
76
- ) => () => RowModel<TGenerics>
39
+ render: TGenerics['Renderer']
77
40
  debugAll?: boolean
78
41
  debugTable?: boolean
79
42
  debugHeaders?: boolean
80
43
  debugColumns?: boolean
81
44
  debugRows?: boolean
82
- defaultColumn?: Partial<ColumnDef<TGenerics>>
83
- 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
45
+ initialState?: InitialTableState
93
46
  autoResetAll?: boolean
94
- mergeOptions?: (
95
- defaultOptions: TableFeature,
96
- options: Partial<Options<TGenerics>>
97
- ) => Options<TGenerics>
47
+ mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
98
48
  meta?: TGenerics['TableMeta']
99
49
  }
100
50
 
101
51
  export type TableCore<TGenerics extends TableGenerics> = {
52
+ // generics: TGenerics
102
53
  initialState: TableState
103
54
  reset: () => void
104
- options: RequiredKeys<Options<TGenerics>, 'state'>
105
- setOptions: (newOptions: Updater<Options<TGenerics>>) => void
55
+ options: RequiredKeys<TableOptions<TGenerics>, 'state'>
56
+ setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void
106
57
  queue: (cb: () => void) => void
107
58
  willUpdate: () => void
108
- getRowId: (
109
- _: TGenerics['Row'],
110
- index: number,
111
- parent?: Row<TGenerics>
112
- ) => string
113
59
  getState: () => TableState
114
60
  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
- getTableProps: PropGetter<TableProps>
146
- 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
61
  render: <TProps>(
161
62
  template: Renderable<TGenerics, TProps>,
162
63
  props: TProps
163
- ) => string | null | ReturnType<UseRenderer<TGenerics>>
64
+ ) => string | null | TGenerics['Rendered']
164
65
  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>[]
66
+ _features: readonly TableFeature[]
229
67
  }
230
68
 
231
69
  export function createTableInstance<TGenerics extends TableGenerics>(
232
- options: Options<TGenerics>
70
+ options: TableOptions<TGenerics>
233
71
  ): TableInstance<TGenerics> {
234
72
  if (options.debugAll || options.debugTable) {
235
73
  console.info('Creating Table Instance...')
@@ -237,16 +75,42 @@ export function createTableInstance<TGenerics extends TableGenerics>(
237
75
 
238
76
  let instance = {} as TableInstance<TGenerics>
239
77
 
240
- const defaultOptions = features.reduce((obj, feature) => {
78
+ instance._features = [
79
+ Columns,
80
+ Rows,
81
+ Cells,
82
+ Headers,
83
+ Visibility,
84
+ Ordering,
85
+ Pinning,
86
+ Filters,
87
+ Sorting,
88
+ Grouping,
89
+ Expanding,
90
+ Pagination,
91
+ RowSelection,
92
+ ColumnSizing,
93
+ ] as const
94
+
95
+ const defaultOptions = instance._features.reduce((obj, feature) => {
241
96
  return Object.assign(obj, feature.getDefaultOptions?.(instance))
242
- }, {})
97
+ }, {}) as TableOptions<TGenerics>
98
+
99
+ const mergeOptions = (options: TableOptions<TGenerics>) => {
100
+ if (instance.options.mergeOptions) {
101
+ return instance.options.mergeOptions(defaultOptions, options)
102
+ }
243
103
 
244
- const buildOptions = (options: Options<TGenerics>) => ({
104
+ return {
105
+ ...defaultOptions,
106
+ ...options,
107
+ }
108
+ }
109
+
110
+ instance.options = {
245
111
  ...defaultOptions,
246
112
  ...options,
247
- })
248
-
249
- instance.options = buildOptions(options)
113
+ }
250
114
 
251
115
  const coreInitialState: CoreTableState = {
252
116
  coreProgress: 1,
@@ -254,10 +118,10 @@ export function createTableInstance<TGenerics extends TableGenerics>(
254
118
 
255
119
  const initialState = {
256
120
  ...coreInitialState,
257
- ...features.reduce((obj, feature) => {
258
- return Object.assign(obj, feature.getInitialState?.())
259
- }, {}),
260
121
  ...(options.initialState ?? {}),
122
+ ...instance._features.reduce((obj, feature) => {
123
+ return Object.assign(obj, feature.getInitialState?.(options.initialState))
124
+ }, {}),
261
125
  } as TableState
262
126
 
263
127
  const queued: (() => void)[] = []
@@ -265,9 +129,9 @@ export function createTableInstance<TGenerics extends TableGenerics>(
265
129
 
266
130
  const finalInstance: TableInstance<TGenerics> = {
267
131
  ...instance,
268
- ...features.reduce((obj, feature) => {
269
- return Object.assign(obj, feature.getInstance?.(instance))
270
- }, {}),
132
+ ...(instance._features.reduce((obj, feature) => {
133
+ return Object.assign(obj, feature.createInstance?.(instance))
134
+ }, {}) as unknown as TableInstance<TGenerics>),
271
135
  queue: cb => {
272
136
  queued.push(cb)
273
137
  if (!queuedTimeout) {
@@ -288,14 +152,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
288
152
  },
289
153
  setOptions: updater => {
290
154
  const newOptions = functionalUpdate(updater, instance.options)
291
- if (instance.options.mergeOptions) {
292
- instance.options = instance.options.mergeOptions(
293
- defaultOptions,
294
- newOptions
295
- )
296
- } else {
297
- instance.options = buildOptions(newOptions)
298
- }
155
+ instance.options = mergeOptions(newOptions)
299
156
  },
300
157
  render: (template, props) => {
301
158
  if (typeof instance.options.render === 'function') {
@@ -309,10 +166,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
309
166
  return template
310
167
  },
311
168
 
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
169
  getState: () => {
317
170
  return instance.options.state as TableState
318
171
  },
@@ -321,405 +174,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
321
174
  instance.options.onStateChange?.(updater)
322
175
  },
323
176
 
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
- getTableProps: userProps => {
658
- return propGetter(
659
- {
660
- role: 'table',
661
- },
662
- userProps
663
- )
664
- },
665
-
666
- getTableBodyProps: userProps => {
667
- return propGetter(
668
- {
669
- role: 'rowgroup',
670
- },
671
- userProps
672
- )
673
- },
674
-
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
177
  getOverallProgress: () => {
724
178
  const { coreProgress, columnFiltersProgress, globalFilterProgress } =
725
179
  instance.getState()