@tanstack/table-core 8.0.0-alpha.83 → 8.0.0-alpha.86

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 (105) hide show
  1. package/build/cjs/aggregationFns.js +50 -51
  2. package/build/cjs/aggregationFns.js.map +1 -1
  3. package/build/cjs/core/cell.js +38 -0
  4. package/build/cjs/core/cell.js.map +1 -0
  5. package/build/cjs/core/column.js +88 -0
  6. package/build/cjs/core/column.js.map +1 -0
  7. package/build/cjs/{features/Headers.js → core/headers.js} +54 -66
  8. package/build/cjs/core/headers.js.map +1 -0
  9. package/build/cjs/core/instance.js +255 -0
  10. package/build/cjs/core/instance.js.map +1 -0
  11. package/build/cjs/core/row.js +77 -0
  12. package/build/cjs/core/row.js.map +1 -0
  13. package/build/cjs/features/ColumnSizing.js.map +1 -1
  14. package/build/cjs/features/Expanding.js +0 -1
  15. package/build/cjs/features/Expanding.js.map +1 -1
  16. package/build/cjs/features/Filters.js +2 -3
  17. package/build/cjs/features/Filters.js.map +1 -1
  18. package/build/cjs/features/Grouping.js +5 -5
  19. package/build/cjs/features/Grouping.js.map +1 -1
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js.map +1 -1
  22. package/build/cjs/features/Pinning.js +3 -3
  23. package/build/cjs/features/Pinning.js.map +1 -1
  24. package/build/cjs/features/RowSelection.js.map +1 -1
  25. package/build/cjs/features/Sorting.js.map +1 -1
  26. package/build/cjs/features/Visibility.js +0 -5
  27. package/build/cjs/features/Visibility.js.map +1 -1
  28. package/build/cjs/index.js +9 -6
  29. package/build/cjs/index.js.map +1 -1
  30. package/build/cjs/utils/filterRowsUtils.js +23 -21
  31. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  32. package/build/cjs/utils/getCoreRowModel.js +9 -8
  33. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  34. package/build/cjs/utils/getExpandedRowModel.js +2 -2
  35. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  36. package/build/cjs/utils/getGroupedRowModel.js +13 -20
  37. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  38. package/build/cjs/utils/getPaginationRowModel.js +1 -1
  39. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  40. package/build/esm/index.js +718 -838
  41. package/build/esm/index.js.map +1 -1
  42. package/build/stats-html.html +1 -1
  43. package/build/stats-react.json +403 -380
  44. package/build/types/aggregationFns.d.ts +10 -19
  45. package/build/types/core/cell.d.ts +9 -0
  46. package/build/types/{features/Columns.d.ts → core/column.d.ts} +3 -17
  47. package/build/types/{features/Headers.d.ts → core/headers.d.ts} +26 -11
  48. package/build/types/core/instance.d.ts +57 -0
  49. package/build/types/core/row.d.ts +15 -0
  50. package/build/types/features/ColumnSizing.d.ts +2 -1
  51. package/build/types/features/Expanding.d.ts +2 -2
  52. package/build/types/features/Filters.d.ts +2 -3
  53. package/build/types/features/Grouping.d.ts +8 -9
  54. package/build/types/features/Ordering.d.ts +2 -1
  55. package/build/types/features/Pagination.d.ts +2 -1
  56. package/build/types/features/Pinning.d.ts +2 -1
  57. package/build/types/features/RowSelection.d.ts +2 -1
  58. package/build/types/features/Sorting.d.ts +2 -1
  59. package/build/types/features/Visibility.d.ts +7 -7
  60. package/build/types/index.d.ts +4 -2
  61. package/build/types/sortingFns.d.ts +4 -4
  62. package/build/types/types.d.ts +10 -53
  63. package/build/umd/index.development.js +721 -836
  64. package/build/umd/index.development.js.map +1 -1
  65. package/build/umd/index.production.js +1 -1
  66. package/build/umd/index.production.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/aggregationFns.ts +44 -40
  69. package/src/core/cell.ts +47 -0
  70. package/src/core/column.ts +148 -0
  71. package/src/{features/Headers.ts → core/headers.ts} +98 -99
  72. package/src/core/instance.ts +361 -0
  73. package/src/core/row.ts +85 -0
  74. package/src/features/ColumnSizing.ts +1 -1
  75. package/src/features/Expanding.ts +1 -4
  76. package/src/features/Filters.ts +2 -7
  77. package/src/features/Grouping.ts +16 -19
  78. package/src/features/Ordering.ts +1 -1
  79. package/src/features/Pagination.ts +1 -1
  80. package/src/features/Pinning.ts +8 -4
  81. package/src/features/RowSelection.ts +1 -1
  82. package/src/features/Sorting.ts +1 -1
  83. package/src/features/Visibility.ts +8 -17
  84. package/src/index.ts +4 -8
  85. package/src/types.ts +9 -61
  86. package/src/utils/filterRowsUtils.ts +4 -2
  87. package/src/utils/getCoreRowModel.ts +4 -2
  88. package/src/utils/getExpandedRowModel.ts +1 -5
  89. package/src/utils/getGroupedRowModel.ts +14 -23
  90. package/build/cjs/core.js +0 -168
  91. package/build/cjs/core.js.map +0 -1
  92. package/build/cjs/features/Cells.js +0 -101
  93. package/build/cjs/features/Cells.js.map +0 -1
  94. package/build/cjs/features/Columns.js +0 -191
  95. package/build/cjs/features/Columns.js.map +0 -1
  96. package/build/cjs/features/Headers.js.map +0 -1
  97. package/build/cjs/features/Rows.js +0 -94
  98. package/build/cjs/features/Rows.js.map +0 -1
  99. package/build/types/core.d.ts +0 -30
  100. package/build/types/features/Cells.d.ts +0 -13
  101. package/build/types/features/Rows.d.ts +0 -28
  102. package/src/core.ts +0 -246
  103. package/src/features/Cells.ts +0 -128
  104. package/src/features/Columns.ts +0 -293
  105. package/src/features/Rows.ts +0 -142
@@ -0,0 +1,361 @@
1
+ import { flattenBy, functionalUpdate, memo, RequiredKeys } from '../utils'
2
+
3
+ import {
4
+ Updater,
5
+ TableOptionsResolved,
6
+ TableState,
7
+ TableInstance,
8
+ Renderable,
9
+ TableGenerics,
10
+ InitialTableState,
11
+ Row,
12
+ Column,
13
+ RowModel,
14
+ ColumnDef,
15
+ } from '../types'
16
+
17
+ //
18
+ import { createColumn } from './column'
19
+ import { Headers } from './headers'
20
+ //
21
+
22
+ import { ColumnSizing } from '../features/ColumnSizing'
23
+ import { Expanding } from '../features/Expanding'
24
+ import { Filters } from '../features/Filters'
25
+ import { Grouping } from '../features/Grouping'
26
+ import { Ordering } from '../features/Ordering'
27
+ import { Pagination } from '../features/Pagination'
28
+ import { Pinning } from '../features/Pinning'
29
+ import { RowSelection } from '../features/RowSelection'
30
+ import { Sorting } from '../features/Sorting'
31
+ import { Visibility } from '../features/Visibility'
32
+
33
+ export type TableFeature = {
34
+ getDefaultOptions?: (instance: any) => any
35
+ getInitialState?: (initialState?: InitialTableState) => any
36
+ createInstance?: (instance: any) => any
37
+ getDefaultColumnDef?: () => any
38
+ createColumn?: (column: any, instance: any) => any
39
+ createHeader?: (column: any, instance: any) => any
40
+ createCell?: (cell: any, column: any, row: any, instance: any) => any
41
+ createRow?: (row: any, instance: any) => any
42
+ }
43
+
44
+ const features = [
45
+ Headers,
46
+ Visibility,
47
+ Ordering,
48
+ Pinning,
49
+ Filters,
50
+ Sorting,
51
+ Grouping,
52
+ Expanding,
53
+ Pagination,
54
+ RowSelection,
55
+ ColumnSizing,
56
+ ] as const
57
+
58
+ //
59
+
60
+ export type CoreTableState = {}
61
+
62
+ export type CoreOptions<TGenerics extends TableGenerics> = {
63
+ data: TGenerics['Row'][]
64
+ state: Partial<TableState>
65
+ onStateChange: (updater: Updater<TableState>) => void
66
+ render: TGenerics['Renderer']
67
+ debugAll?: boolean
68
+ debugTable?: boolean
69
+ debugHeaders?: boolean
70
+ debugColumns?: boolean
71
+ debugRows?: boolean
72
+ initialState?: InitialTableState
73
+ autoResetAll?: boolean
74
+ mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
75
+ meta?: TGenerics['TableMeta']
76
+ getCoreRowModel: (
77
+ instance: TableInstance<TGenerics>
78
+ ) => () => RowModel<TGenerics>
79
+ getSubRows?: (
80
+ originalRow: TGenerics['Row'],
81
+ index: number
82
+ ) => undefined | TGenerics['Row'][]
83
+ getRowId?: (
84
+ originalRow: TGenerics['Row'],
85
+ index: number,
86
+ parent?: Row<TGenerics>
87
+ ) => string
88
+ columns: ColumnDef<TGenerics>[]
89
+ defaultColumn?: Partial<ColumnDef<TGenerics>>
90
+ }
91
+
92
+ export type CoreInstance<TGenerics extends TableGenerics> = {
93
+ initialState: TableState
94
+ reset: () => void
95
+ options: RequiredKeys<TableOptionsResolved<TGenerics>, 'state'>
96
+ setOptions: (newOptions: Updater<TableOptionsResolved<TGenerics>>) => void
97
+ getState: () => TableState
98
+ setState: (updater: Updater<TableState>) => void
99
+ _features: readonly TableFeature[]
100
+ _queue: (cb: () => void) => void
101
+ _render: <TProps>(
102
+ template: Renderable<TGenerics, TProps>,
103
+ props: TProps
104
+ ) => string | null | TGenerics['Rendered']
105
+ _getRowId: (
106
+ _: TGenerics['Row'],
107
+ index: number,
108
+ parent?: Row<TGenerics>
109
+ ) => string
110
+ getCoreRowModel: () => RowModel<TGenerics>
111
+ _getCoreRowModel?: () => RowModel<TGenerics>
112
+ getRowModel: () => RowModel<TGenerics>
113
+ getRow: (id: string) => Row<TGenerics>
114
+ _getDefaultColumnDef: () => Partial<ColumnDef<TGenerics>>
115
+ _getColumnDefs: () => ColumnDef<TGenerics>[]
116
+ _getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
117
+ getAllColumns: () => Column<TGenerics>[]
118
+ getAllFlatColumns: () => Column<TGenerics>[]
119
+ getAllLeafColumns: () => Column<TGenerics>[]
120
+ getColumn: (columnId: string) => Column<TGenerics>
121
+ }
122
+
123
+ export function createTableInstance<TGenerics extends TableGenerics>(
124
+ options: TableOptionsResolved<TGenerics>
125
+ ): TableInstance<TGenerics> {
126
+ if (options.debugAll || options.debugTable) {
127
+ console.info('Creating Table Instance...')
128
+ }
129
+
130
+ let instance = { _features: features } as unknown as TableInstance<TGenerics>
131
+
132
+ const defaultOptions = instance._features.reduce((obj, feature) => {
133
+ return Object.assign(obj, feature.getDefaultOptions?.(instance))
134
+ }, {}) as TableOptionsResolved<TGenerics>
135
+
136
+ const mergeOptions = (options: TableOptionsResolved<TGenerics>) => {
137
+ if (instance.options.mergeOptions) {
138
+ return instance.options.mergeOptions(defaultOptions, options)
139
+ }
140
+
141
+ return {
142
+ ...defaultOptions,
143
+ ...options,
144
+ }
145
+ }
146
+
147
+ const coreInitialState: CoreTableState = {}
148
+
149
+ let initialState = {
150
+ ...coreInitialState,
151
+ ...(options.initialState ?? {}),
152
+ } as TableState
153
+
154
+ instance._features.forEach(feature => {
155
+ initialState = feature.getInitialState?.(initialState) ?? initialState
156
+ })
157
+
158
+ const queued: (() => void)[] = []
159
+ let queuedTimeout = false
160
+
161
+ const coreInstance: CoreInstance<TGenerics> = {
162
+ _features: features,
163
+ options: {
164
+ ...defaultOptions,
165
+ ...options,
166
+ },
167
+ initialState,
168
+ _queue: cb => {
169
+ queued.push(cb)
170
+
171
+ if (!queuedTimeout) {
172
+ queuedTimeout = true
173
+
174
+ // Schedule a microtask to run the queued callbacks after
175
+ // the current call stack (render, etc) has finished.
176
+ Promise.resolve()
177
+ .then(() => {
178
+ while (queued.length) {
179
+ queued.shift()!()
180
+ }
181
+ queuedTimeout = false
182
+ })
183
+ .catch(error =>
184
+ setTimeout(() => {
185
+ throw error
186
+ })
187
+ )
188
+ }
189
+ },
190
+ reset: () => {
191
+ instance.setState(instance.initialState)
192
+ },
193
+ setOptions: updater => {
194
+ const newOptions = functionalUpdate(updater, instance.options)
195
+ instance.options = mergeOptions(newOptions)
196
+ },
197
+ _render: (template, props) => {
198
+ if (typeof instance.options.render === 'function') {
199
+ return instance.options.render(template, props)
200
+ }
201
+
202
+ if (typeof template === 'function') {
203
+ return (template as Function)(props)
204
+ }
205
+
206
+ return template
207
+ },
208
+
209
+ getState: () => {
210
+ return instance.options.state as TableState
211
+ },
212
+
213
+ setState: (updater: Updater<TableState>) => {
214
+ instance.options.onStateChange?.(updater)
215
+ },
216
+
217
+ _getRowId: (
218
+ row: TGenerics['Row'],
219
+ index: number,
220
+ parent?: Row<TGenerics>
221
+ ) =>
222
+ instance.options.getRowId?.(row, index, parent) ??
223
+ `${parent ? [parent.id, index].join('.') : index}`,
224
+
225
+ getCoreRowModel: () => {
226
+ if (!instance._getCoreRowModel) {
227
+ instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
228
+ }
229
+
230
+ return instance._getCoreRowModel()
231
+ },
232
+
233
+ // The final calls start at the bottom of the model,
234
+ // expanded rows, which then work their way up
235
+
236
+ getRowModel: () => {
237
+ return instance.getPaginationRowModel()
238
+ },
239
+ getRow: (id: string) => {
240
+ const row = instance.getRowModel().rowsById[id]
241
+
242
+ if (!row) {
243
+ if (process.env.NODE_ENV !== 'production') {
244
+ throw new Error(`getRow expected an ID, but got ${id}`)
245
+ }
246
+ throw new Error()
247
+ }
248
+
249
+ return row
250
+ },
251
+ _getDefaultColumnDef: memo(
252
+ () => [instance.options.defaultColumn],
253
+ defaultColumn => {
254
+ defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
255
+
256
+ return {
257
+ header: props => props.header.column.id,
258
+ footer: props => props.header.column.id,
259
+ cell: props => props.getValue().toString?.() ?? null,
260
+ ...instance._features.reduce((obj, feature) => {
261
+ return Object.assign(obj, feature.getDefaultColumnDef?.())
262
+ }, {}),
263
+ ...defaultColumn,
264
+ } as Partial<ColumnDef<TGenerics>>
265
+ },
266
+ {
267
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
268
+ key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef',
269
+ }
270
+ ),
271
+
272
+ _getColumnDefs: () => instance.options.columns,
273
+
274
+ getAllColumns: memo(
275
+ () => [instance._getColumnDefs()],
276
+ columnDefs => {
277
+ const recurseColumns = (
278
+ columnDefs: ColumnDef<TGenerics>[],
279
+ parent?: Column<TGenerics>,
280
+ depth = 0
281
+ ): Column<TGenerics>[] => {
282
+ return columnDefs.map(columnDef => {
283
+ const column = createColumn(instance, columnDef, depth, parent)
284
+
285
+ column.columns = columnDef.columns
286
+ ? recurseColumns(columnDef.columns, column, depth + 1)
287
+ : []
288
+
289
+ return column
290
+ })
291
+ }
292
+
293
+ return recurseColumns(columnDefs)
294
+ },
295
+ {
296
+ key: process.env.NODE_ENV === 'development' && 'getAllColumns',
297
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
298
+ }
299
+ ),
300
+
301
+ getAllFlatColumns: memo(
302
+ () => [instance.getAllColumns()],
303
+ allColumns => {
304
+ return allColumns.flatMap(column => {
305
+ return column.getFlatColumns()
306
+ })
307
+ },
308
+ {
309
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
310
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
311
+ }
312
+ ),
313
+
314
+ _getAllFlatColumnsById: memo(
315
+ () => [instance.getAllFlatColumns()],
316
+ flatColumns => {
317
+ return flatColumns.reduce((acc, column) => {
318
+ acc[column.id] = column
319
+ return acc
320
+ }, {} as Record<string, Column<TGenerics>>)
321
+ },
322
+ {
323
+ key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
324
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
325
+ }
326
+ ),
327
+
328
+ getAllLeafColumns: memo(
329
+ () => [instance.getAllColumns(), instance._getOrderColumnsFn()],
330
+ (allColumns, orderColumns) => {
331
+ let leafColumns = allColumns.flatMap(column => column.getLeafColumns())
332
+ return orderColumns(leafColumns)
333
+ },
334
+ {
335
+ key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
336
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
337
+ }
338
+ ),
339
+
340
+ getColumn: columnId => {
341
+ const column = instance._getAllFlatColumnsById()[columnId]
342
+
343
+ if (!column) {
344
+ if (process.env.NODE_ENV !== 'production') {
345
+ console.warn(`[Table] Column with id ${columnId} does not exist.`)
346
+ }
347
+ throw new Error()
348
+ }
349
+
350
+ return column
351
+ },
352
+ }
353
+
354
+ Object.assign(instance, coreInstance)
355
+
356
+ instance._features.forEach(feature => {
357
+ return Object.assign(instance, feature.createInstance?.(instance))
358
+ })
359
+
360
+ return instance
361
+ }
@@ -0,0 +1,85 @@
1
+ import { Cell, Row, TableGenerics, TableInstance } from '../types'
2
+ import { flattenBy, memo } from '../utils'
3
+ import { createCell } from './cell'
4
+
5
+ export type CoreRow<TGenerics extends TableGenerics> = {
6
+ id: string
7
+ index: number
8
+ original?: TGenerics['Row']
9
+ depth: number
10
+ _valuesCache: Record<string, any>
11
+ getValue: (columnId: string) => any
12
+ subRows: Row<TGenerics>[]
13
+ getLeafRows: () => Row<TGenerics>[]
14
+ originalSubRows?: TGenerics['Row'][]
15
+ getAllCells: () => Cell<TGenerics>[]
16
+ _getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
17
+ }
18
+
19
+ export const createRow = <TGenerics extends TableGenerics>(
20
+ instance: TableInstance<TGenerics>,
21
+ id: string,
22
+ original: TGenerics['Row'] | undefined,
23
+ rowIndex: number,
24
+ depth: number,
25
+ subRows?: Row<TGenerics>[]
26
+ ): Row<TGenerics> => {
27
+ let row: CoreRow<TGenerics> = {
28
+ id,
29
+ index: rowIndex,
30
+ original,
31
+ depth,
32
+ _valuesCache: {},
33
+ getValue: columnId => {
34
+ if (row._valuesCache.hasOwnProperty(columnId)) {
35
+ return row._valuesCache[columnId]
36
+ }
37
+
38
+ const column = instance.getColumn(columnId)
39
+
40
+ if (!column.accessorFn) {
41
+ return undefined
42
+ }
43
+
44
+ row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex)
45
+
46
+ return row._valuesCache[columnId]
47
+ },
48
+ subRows: subRows ?? [],
49
+ getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
50
+ getAllCells: memo(
51
+ () => [instance.getAllLeafColumns()],
52
+ leafColumns => {
53
+ return leafColumns.map(column => {
54
+ return createCell(instance, row as Row<TGenerics>, column, column.id)
55
+ })
56
+ },
57
+ {
58
+ key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
59
+ debug: () => instance.options.debugAll ?? instance.options.debugRows,
60
+ }
61
+ ),
62
+
63
+ _getAllCellsByColumnId: memo(
64
+ () => [row.getAllCells()],
65
+ allCells => {
66
+ return allCells.reduce((acc, cell) => {
67
+ acc[cell.column.id] = cell
68
+ return acc
69
+ }, {} as Record<string, Cell<TGenerics>>)
70
+ },
71
+ {
72
+ key:
73
+ process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
74
+ debug: () => instance.options.debugAll ?? instance.options.debugRows,
75
+ }
76
+ ),
77
+ }
78
+
79
+ for (let i = 0; i < instance._features.length; i++) {
80
+ const feature = instance._features[i]
81
+ Object.assign(row, feature?.createRow?.(row, instance))
82
+ }
83
+
84
+ return row as Row<TGenerics>
85
+ }
@@ -1,3 +1,4 @@
1
+ import { TableFeature } from '../core/instance'
1
2
  import {
2
3
  Column,
3
4
  Header,
@@ -5,7 +6,6 @@ import {
5
6
  TableGenerics,
6
7
  TableInstance,
7
8
  Updater,
8
- TableFeature,
9
9
  } from '../types'
10
10
  import { makeStateUpdater } from '../utils'
11
11
  import { ColumnPinningPosition } from './Pinning'
@@ -1,14 +1,13 @@
1
1
  import { RowModel } from '..'
2
+ import { TableFeature } from '../core/instance'
2
3
  import {
3
4
  OnChangeFn,
4
5
  TableGenerics,
5
6
  TableInstance,
6
7
  Row,
7
8
  Updater,
8
- TableFeature,
9
9
  } from '../types'
10
10
  import { makeStateUpdater } from '../utils'
11
- import { Rows } from './Rows'
12
11
 
13
12
  export type ExpandedStateList = Record<string, boolean>
14
13
  export type ExpandedState = true | Record<string, boolean>
@@ -31,7 +30,6 @@ export type ExpandedOptions<TGenerics extends TableGenerics> = {
31
30
  getExpandedRowModel?: (
32
31
  instance: TableInstance<TGenerics>
33
32
  ) => () => RowModel<TGenerics>
34
- expandSubRows?: boolean
35
33
  getIsRowExpanded?: (row: Row<TGenerics>) => boolean
36
34
  getRowCanExpand?: (row: Row<TGenerics>) => boolean
37
35
  paginateExpandedRows?: boolean
@@ -68,7 +66,6 @@ export const Expanding: TableFeature = {
68
66
  return {
69
67
  onExpandedChange: makeStateUpdater('expanded', instance),
70
68
  autoResetExpanded: true,
71
- expandSubRows: true,
72
69
  paginateExpandedRows: true,
73
70
  }
74
71
  },
@@ -1,4 +1,5 @@
1
1
  import { RowModel } from '..'
2
+ import { TableFeature } from '../core/instance'
2
3
  import { BuiltInFilterFn, filterFns } from '../filterFns'
3
4
  import {
4
5
  Column,
@@ -7,7 +8,6 @@ import {
7
8
  TableInstance,
8
9
  Row,
9
10
  Updater,
10
- TableFeature,
11
11
  } from '../types'
12
12
  import {
13
13
  functionalUpdate,
@@ -20,8 +20,6 @@ import {
20
20
  export type FiltersTableState = {
21
21
  columnFilters: ColumnFiltersState
22
22
  globalFilter: any
23
- // filtersProgress: number
24
- // facetProgress: Record<string, number>
25
23
  }
26
24
 
27
25
  export type ColumnFiltersState = ColumnFilter[]
@@ -74,7 +72,6 @@ export type FiltersColumnDef<TGenerics extends TableGenerics> = {
74
72
  filterFn?: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
75
73
  enableColumnFilter?: boolean
76
74
  enableGlobalFilter?: boolean
77
- enableFaceting?: boolean
78
75
  }
79
76
 
80
77
  export type FiltersColumn<TGenerics extends TableGenerics> = {
@@ -98,7 +95,6 @@ export type FiltersColumn<TGenerics extends TableGenerics> = {
98
95
  export type FiltersRow<TGenerics extends TableGenerics> = {
99
96
  columnFilters: Record<string, boolean>
100
97
  columnFiltersMeta: Record<string, TGenerics['FilterMeta']>
101
- subRowsByFacetId: Record<string, Row<TGenerics>[]>
102
98
  }
103
99
 
104
100
  export type FiltersOptions<TGenerics extends TableGenerics> = {
@@ -190,7 +186,7 @@ export const Filters: TableFeature = {
190
186
  getColumnCanGlobalFilter: column => {
191
187
  const value = instance
192
188
  .getCoreRowModel()
193
- .flatRows[0]?.getAllCellsByColumnId()
189
+ .flatRows[0]?._getAllCellsByColumnId()
194
190
  [column.id]?.getValue()
195
191
 
196
192
  return typeof value === 'string'
@@ -356,7 +352,6 @@ export const Filters: TableFeature = {
356
352
  return {
357
353
  columnFilters: {},
358
354
  columnFiltersMeta: {},
359
- subRowsByFacetId: {},
360
355
  }
361
356
  },
362
357
 
@@ -1,5 +1,6 @@
1
1
  import { RowModel } from '..'
2
2
  import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
3
+ import { TableFeature } from '../core/instance'
3
4
  import {
4
5
  Cell,
5
6
  Column,
@@ -9,15 +10,19 @@ import {
9
10
  Updater,
10
11
  Renderable,
11
12
  TableGenerics,
12
- TableFeature,
13
13
  } from '../types'
14
14
  import { isFunction, makeStateUpdater, Overwrite } from '../utils'
15
15
 
16
16
  export type GroupingState = string[]
17
17
 
18
+ export type GroupingTableState = {
19
+ grouping: GroupingState
20
+ }
21
+
18
22
  export type AggregationFn<TGenerics extends TableGenerics> = (
19
- getLeafValues: () => TGenerics['Value'][],
20
- getChildValues: () => TGenerics['Value'][]
23
+ columnId: string,
24
+ leafRows: Row<TGenerics>[],
25
+ childRows: Row<TGenerics>[]
21
26
  ) => any
22
27
 
23
28
  export type CustomAggregationFns<TGenerics extends TableGenerics> = Record<
@@ -31,13 +36,8 @@ export type AggregationFnOption<TGenerics extends TableGenerics> =
31
36
  | keyof TGenerics['AggregationFns']
32
37
  | AggregationFn<TGenerics>
33
38
 
34
- export type GroupingTableState = {
35
- grouping: GroupingState
36
- }
37
-
38
39
  export type GroupingColumnDef<TGenerics extends TableGenerics> = {
39
40
  aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
40
- aggregateValue?: (columnValue: unknown) => any
41
41
  aggregatedCell?: Renderable<
42
42
  TGenerics,
43
43
  {
@@ -58,15 +58,15 @@ export type GroupingColumn<TGenerics extends TableGenerics> = {
58
58
  getGroupedIndex: () => number
59
59
  toggleGrouping: () => void
60
60
  getToggleGroupingHandler: () => () => void
61
- getColumnAutoAggregationFn: () => AggregationFn<TGenerics> | undefined
62
- getColumnAggregationFn: () => AggregationFn<TGenerics> | undefined
61
+ getAutoAggregationFn: () => AggregationFn<TGenerics> | undefined
62
+ getAggregationFn: () => AggregationFn<TGenerics> | undefined
63
63
  }
64
64
 
65
65
  export type GroupingRow = {
66
66
  groupingColumnId?: string
67
67
  groupingValue?: any
68
68
  getIsGrouped: () => boolean
69
- groupingValuesCache: Record<string, any>
69
+ _groupingValuesCache: Record<string, any>
70
70
  }
71
71
 
72
72
  export type GroupingCell<TGenerics extends TableGenerics> = {
@@ -87,11 +87,9 @@ export type GroupingOptions<TGenerics extends TableGenerics> = {
87
87
  aggregationFns?: TGenerics['AggregationFns']
88
88
  onGroupingChange?: OnChangeFn<GroupingState>
89
89
  enableGrouping?: boolean
90
- enableGroupingRemoval?: boolean
91
90
  getGroupedRowModel?: (
92
91
  instance: TableInstance<TGenerics>
93
92
  ) => () => RowModel<TGenerics>
94
-
95
93
  groupedColumnMode?: false | 'reorder' | 'remove'
96
94
  }
97
95
 
@@ -172,7 +170,7 @@ export const Grouping: TableFeature = {
172
170
  column.toggleGrouping()
173
171
  }
174
172
  },
175
- getColumnAutoAggregationFn: () => {
173
+ getAutoAggregationFn: () => {
176
174
  const firstRow = instance.getCoreRowModel().flatRows[0]
177
175
 
178
176
  const value = firstRow?.getValue(column.id)
@@ -187,7 +185,7 @@ export const Grouping: TableFeature = {
187
185
 
188
186
  return aggregationFns.count
189
187
  },
190
- getColumnAggregationFn: () => {
188
+ getAggregationFn: () => {
191
189
  const userAggregationFns = instance.options.aggregationFns
192
190
 
193
191
  if (!column) {
@@ -197,7 +195,7 @@ export const Grouping: TableFeature = {
197
195
  return isFunction(column.aggregationFn)
198
196
  ? column.aggregationFn
199
197
  : column.aggregationFn === 'auto'
200
- ? column.getColumnAutoAggregationFn()
198
+ ? column.getAutoAggregationFn()
201
199
  : (userAggregationFns as Record<string, any>)?.[
202
200
  column.aggregationFn as string
203
201
  ] ??
@@ -240,12 +238,11 @@ export const Grouping: TableFeature = {
240
238
  },
241
239
 
242
240
  createRow: <TGenerics extends TableGenerics>(
243
- row: Row<TGenerics>,
244
- instance: TableInstance<TGenerics>
241
+ row: Row<TGenerics>
245
242
  ): GroupingRow => {
246
243
  return {
247
244
  getIsGrouped: () => !!row.groupingColumnId,
248
- groupingValuesCache: {},
245
+ _groupingValuesCache: {},
249
246
  }
250
247
  },
251
248
 
@@ -6,10 +6,10 @@ import {
6
6
  Updater,
7
7
  Column,
8
8
  TableGenerics,
9
- TableFeature,
10
9
  } from '../types'
11
10
 
12
11
  import { Grouping, orderColumns } from './Grouping'
12
+ import { TableFeature } from '../core/instance'
13
13
 
14
14
  export type ColumnOrderTableState = {
15
15
  columnOrder: ColumnOrderState
@@ -1,10 +1,10 @@
1
+ import { TableFeature } from '../core/instance'
1
2
  import {
2
3
  OnChangeFn,
3
4
  TableGenerics,
4
5
  TableInstance,
5
6
  RowModel,
6
7
  Updater,
7
- TableFeature,
8
8
  } from '../types'
9
9
  import { functionalUpdate, makeStateUpdater, memo } from '../utils'
10
10