@tanstack/table-core 8.0.0-alpha.53 → 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.
Files changed (117) hide show
  1. package/build/cjs/core.js +9 -384
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js.map +1 -1
  4. package/build/cjs/features/Cells.js +122 -0
  5. package/build/cjs/features/Cells.js.map +1 -0
  6. package/build/cjs/features/ColumnSizing.js +90 -37
  7. package/build/cjs/features/ColumnSizing.js.map +1 -1
  8. package/build/cjs/features/Columns.js +216 -0
  9. package/build/cjs/features/Columns.js.map +1 -0
  10. package/build/cjs/features/Expanding.js +1 -1
  11. package/build/cjs/features/Expanding.js.map +1 -1
  12. package/build/cjs/features/Filters.js +1 -1
  13. package/build/cjs/features/Filters.js.map +1 -1
  14. package/build/cjs/features/Grouping.js +1 -1
  15. package/build/cjs/features/Grouping.js.map +1 -1
  16. package/build/cjs/features/Headers.js +78 -153
  17. package/build/cjs/features/Headers.js.map +1 -1
  18. package/build/cjs/features/Ordering.js +2 -2
  19. package/build/cjs/features/Ordering.js.map +1 -1
  20. package/build/cjs/features/Pagination.js +1 -1
  21. package/build/cjs/features/Pagination.js.map +1 -1
  22. package/build/cjs/features/Pinning.js +172 -2
  23. package/build/cjs/features/Pinning.js.map +1 -1
  24. package/build/cjs/features/RowSelection.js +1 -1
  25. package/build/cjs/features/RowSelection.js.map +1 -1
  26. package/build/cjs/features/Rows.js +99 -0
  27. package/build/cjs/features/Rows.js.map +1 -0
  28. package/build/cjs/features/Sorting.js +1 -1
  29. package/build/cjs/features/Sorting.js.map +1 -1
  30. package/build/cjs/features/Visibility.js +51 -17
  31. package/build/cjs/features/Visibility.js.map +1 -1
  32. package/build/cjs/filterFns.js.map +1 -1
  33. package/build/cjs/sortingFns.js.map +1 -1
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
  36. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
  37. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
  38. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  39. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -1
  40. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  41. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  42. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
  43. package/build/cjs/utils.js +2 -2
  44. package/build/cjs/utils.js.map +1 -1
  45. package/build/esm/index.js +879 -693
  46. package/build/esm/index.js.map +1 -1
  47. package/build/stats-html.html +1 -1
  48. package/build/stats-react.json +420 -318
  49. package/build/types/core.d.ts +5 -82
  50. package/build/types/createTable.d.ts +4 -4
  51. package/build/types/features/Cells.d.ts +14 -0
  52. package/build/types/features/ColumnSizing.d.ts +31 -23
  53. package/build/types/features/Columns.d.ts +54 -0
  54. package/build/types/features/Expanding.d.ts +6 -6
  55. package/build/types/features/Filters.d.ts +14 -14
  56. package/build/types/features/Grouping.d.ts +16 -16
  57. package/build/types/features/Headers.d.ts +5 -13
  58. package/build/types/features/Ordering.d.ts +5 -5
  59. package/build/types/features/Pagination.d.ts +5 -5
  60. package/build/types/features/Pinning.d.ts +21 -7
  61. package/build/types/features/RowSelection.d.ts +8 -8
  62. package/build/types/features/Rows.d.ts +29 -0
  63. package/build/types/features/Sorting.d.ts +12 -12
  64. package/build/types/features/Visibility.d.ts +11 -6
  65. package/build/types/filterFns.d.ts +10 -10
  66. package/build/types/sortingFns.d.ts +7 -7
  67. package/build/types/types.d.ts +37 -33
  68. package/build/types/utils/filterRowsUtils.d.ts +3 -3
  69. package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +2 -2
  70. package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -2
  71. package/build/types/utils/getCoreRowModelAsync.d.ts +2 -2
  72. package/build/types/utils/getCoreRowModelSync.d.ts +2 -2
  73. package/build/types/utils/getExpandedRowModel.d.ts +3 -3
  74. package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +2 -2
  75. package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -2
  76. package/build/types/utils/getGroupedRowModel.d.ts +2 -2
  77. package/build/types/utils/getPaginationRowModel.d.ts +2 -2
  78. package/build/types/utils/getSortedRowModelAsync.d.ts +4 -4
  79. package/build/types/utils/getSortedRowModelSync.d.ts +2 -2
  80. package/build/types/utils.d.ts +0 -1
  81. package/build/umd/index.development.js +857 -671
  82. package/build/umd/index.development.js.map +1 -1
  83. package/build/umd/index.production.js +1 -1
  84. package/build/umd/index.production.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/core.ts +32 -554
  87. package/src/createTable.ts +12 -5
  88. package/src/features/Cells.ts +156 -0
  89. package/src/features/ColumnSizing.ts +109 -58
  90. package/src/features/Columns.ts +290 -0
  91. package/src/features/Expanding.ts +6 -7
  92. package/src/features/Filters.ts +14 -15
  93. package/src/features/Grouping.ts +16 -17
  94. package/src/features/Headers.ts +51 -142
  95. package/src/features/Ordering.ts +8 -7
  96. package/src/features/Pagination.ts +5 -6
  97. package/src/features/Pinning.ts +198 -8
  98. package/src/features/RowSelection.ts +9 -10
  99. package/src/features/Rows.ts +151 -0
  100. package/src/features/Sorting.ts +12 -13
  101. package/src/features/Visibility.ts +73 -27
  102. package/src/filterFns.ts +10 -10
  103. package/src/sortingFns.ts +7 -7
  104. package/src/types.ts +47 -65
  105. package/src/utils/filterRowsUtils.ts +3 -3
  106. package/src/utils/getColumnFilteredRowModelAsync.ts +2 -2
  107. package/src/utils/getColumnFilteredRowModelSync.ts +2 -2
  108. package/src/utils/getCoreRowModelAsync.ts +2 -2
  109. package/src/utils/getCoreRowModelSync.ts +2 -2
  110. package/src/utils/getExpandedRowModel.ts +3 -3
  111. package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -2
  112. package/src/utils/getGlobalFilteredRowModelSync.ts +2 -2
  113. package/src/utils/getGroupedRowModel.ts +3 -3
  114. package/src/utils/getPaginationRowModel.ts +2 -2
  115. package/src/utils/getSortedRowModelAsync.ts +4 -4
  116. package/src/utils/getSortedRowModelSync.ts +2 -2
  117. package/src/utils.ts +3 -5
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.53",
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
- AnyGenerics,
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
- export type CoreOptions<TGenerics extends AnyGenerics> = {
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,
@@ -98,137 +55,26 @@ export type CoreOptions<TGenerics extends AnyGenerics> = {
98
55
  meta?: TGenerics['TableMeta']
99
56
  }
100
57
 
101
- export type TableCore<TGenerics extends AnyGenerics> = {
58
+ export type TableCore<TGenerics extends TableGenerics> = {
102
59
  initialState: TableState
103
60
  reset: () => void
104
61
  options: RequiredKeys<Options<TGenerics>, 'state'>
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
74
+ _features: readonly TableFeature[]
165
75
  }
166
76
 
167
- export type CoreRow<TGenerics extends AnyGenerics> = {
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 AnyGenerics> = {
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 AnyGenerics> = {
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>[]
229
- }
230
-
231
- export function createTableInstance<TGenerics extends AnyGenerics>(
77
+ export function createTableInstance<TGenerics extends TableGenerics>(
232
78
  options: Options<TGenerics>
233
79
  ): TableInstance<TGenerics> {
234
80
  if (options.debugAll || options.debugTable) {
@@ -237,7 +83,24 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
237
83
 
238
84
  let instance = {} as TableInstance<TGenerics>
239
85
 
240
- const defaultOptions = features.reduce((obj, feature) => {
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 AnyGenerics>(
254
117
 
255
118
  const initialState = {
256
119
  ...coreInitialState,
257
- ...features.reduce((obj, feature) => {
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 AnyGenerics>(
265
128
 
266
129
  const finalInstance: TableInstance<TGenerics> = {
267
130
  ...instance,
268
- ...features.reduce((obj, feature) => {
269
- return Object.assign(obj, feature.getInstance?.(instance))
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 AnyGenerics>(
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 AnyGenerics>(
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 AnyGenerics>(
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()