@tanstack/table-core 8.0.0-alpha.46 → 8.0.0-alpha.49

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/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.46",
4
+ "version": "8.0.0-alpha.49",
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",
@@ -10,7 +10,7 @@ export const aggregationFns = {
10
10
  count,
11
11
  }
12
12
 
13
- export type BuiltInAggregationType = keyof typeof aggregationFns
13
+ export type BuiltInAggregationFn = keyof typeof aggregationFns
14
14
 
15
15
  function sum(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
16
16
  // It's faster to just add the aggregations together instead of
@@ -1,6 +1,6 @@
1
- import { CustomFilterTypes, FilterFn } from './features/Filters'
2
- import { AggregationFn, CustomAggregationTypes } from './features/Grouping'
3
- import { CustomSortingTypes, SortingFn } from './features/Sorting'
1
+ import { CustomFilterFns, FilterFn } from './features/Filters'
2
+ import { AggregationFn, CustomAggregationFns } from './features/Grouping'
3
+ import { CustomSortingFns, SortingFn } from './features/Sorting'
4
4
  import { ColumnDef, AccessorFn, AnyRender, AnyGenerics, Options } from './types'
5
5
  import { IfDefined, Overwrite, PartialKeys } from './utils'
6
6
 
@@ -8,9 +8,9 @@ export type TableFactory<TGenerics extends AnyGenerics> = () => Table<TGenerics>
8
8
 
9
9
  export type CreateTableOptions<
10
10
  TRender extends AnyRender,
11
- TFilterFns extends CustomFilterTypes<any>,
12
- TSortingFns extends CustomSortingTypes<any>,
13
- TAggregationFns extends CustomAggregationTypes<any>,
11
+ TFilterFns extends CustomFilterFns<any>,
12
+ TSortingFns extends CustomSortingFns<any>,
13
+ TAggregationFns extends CustomAggregationFns<any>,
14
14
  TGenerics extends AnyGenerics
15
15
  > = Partial<
16
16
  {
@@ -24,13 +24,11 @@ export type CreateTableOptions<
24
24
  export type Table<TGenerics extends AnyGenerics> = {
25
25
  generics: TGenerics
26
26
  options: Partial<Options<TGenerics>>
27
- setRowType: <TRow extends object>() => Table<
28
- Overwrite<TGenerics, { Row: TRow }>
29
- >
30
- setTableMetaType: <TTableMeta extends object>() => Table<
27
+ setRowType: <TRow>() => Table<Overwrite<TGenerics, { Row: TRow }>>
28
+ setTableMetaType: <TTableMeta>() => Table<
31
29
  Overwrite<TGenerics, { TableMeta: TTableMeta }>
32
30
  >
33
- setColumnMetaType: <TColumnMeta extends object>() => Table<
31
+ setColumnMetaType: <TColumnMeta>() => Table<
34
32
  Overwrite<TGenerics, { ColumnMeta: TColumnMeta }>
35
33
  >
36
34
  setOptions: <
@@ -1,5 +1,5 @@
1
1
  import { RowModel } from '..'
2
- import { BuiltInFilterType, filterFns } from '../filterFns'
2
+ import { BuiltInFilterFn, filterFns } from '../filterFns'
3
3
  import {
4
4
  Column,
5
5
  OnChangeFn,
@@ -17,12 +17,23 @@ import {
17
17
  Overwrite,
18
18
  } from '../utils'
19
19
 
20
+ export type FiltersTableState = {
21
+ columnFilters: ColumnFiltersState
22
+ globalFilter: any
23
+ columnFiltersProgress: number
24
+ globalFilterProgress: number
25
+ }
26
+
27
+ export type ColumnFiltersState = ColumnFilter[]
28
+
20
29
  export type ColumnFilter = {
21
30
  id: string
22
31
  value: unknown
23
32
  }
24
33
 
25
- export type ColumnFiltersState = ColumnFilter[]
34
+ /*
35
+ A filter function is any function that takes an array of rows and returns an array of rows. Because filter functions can be used for both column and global filters, they are passed an array of columnIds to filter on.
36
+ */
26
37
 
27
38
  export type FilterFn<TGenerics extends AnyGenerics> = {
28
39
  (rows: Row<TGenerics>[], columnIds: string[], filterValue: any): any
@@ -34,26 +45,19 @@ export type ColumnFilterAutoRemoveTestFn<TGenerics extends AnyGenerics> = (
34
45
  column?: Column<TGenerics>
35
46
  ) => boolean
36
47
 
37
- export type CustomFilterTypes<TGenerics extends AnyGenerics> = Record<
48
+ export type CustomFilterFns<TGenerics extends AnyGenerics> = Record<
38
49
  string,
39
50
  FilterFn<TGenerics>
40
51
  >
41
52
 
42
- export type FiltersTableState = {
43
- columnFilters: ColumnFiltersState
44
- globalFilter: any
45
- columnFiltersProgress: number
46
- globalFilterProgress: number
47
- }
48
-
49
- export type FilterType<TGenerics extends AnyGenerics> =
53
+ export type FilterFnOption<TGenerics extends AnyGenerics> =
50
54
  | 'auto'
51
- | BuiltInFilterType
55
+ | BuiltInFilterFn
52
56
  | keyof TGenerics['FilterFns']
53
57
  | FilterFn<TGenerics>
54
58
 
55
59
  export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
56
- filterFn?: FilterType<Overwrite<TGenerics, { Value: any }>>
60
+ filterFn?: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
57
61
  enableAllFilters?: boolean
58
62
  enableColumnFilter?: boolean
59
63
  enableGlobalFilter?: boolean
@@ -63,7 +67,7 @@ export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
63
67
  }
64
68
 
65
69
  export type FiltersColumn<TGenerics extends AnyGenerics> = {
66
- filterFn: FilterType<Overwrite<TGenerics, { Value: any }>>
70
+ filterFn: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
67
71
  getCanColumnFilter: () => boolean
68
72
  getCanGlobalFilter: () => boolean
69
73
  getColumnFilterIndex: () => number
@@ -87,7 +91,7 @@ export type FiltersOptions<TGenerics extends AnyGenerics> = {
87
91
  instance: TableInstance<TGenerics>
88
92
  ) => () => RowModel<TGenerics>
89
93
  // Global
90
- globalFilterType?: FilterType<TGenerics>
94
+ globalFilterFn?: FilterFnOption<TGenerics>
91
95
  onGlobalFilterChange?: OnChangeFn<any>
92
96
  autoResetGlobalFilter?: boolean
93
97
  enableGlobalFilter?: boolean
@@ -161,7 +165,7 @@ export const Filters = {
161
165
  autoResetColumnFilters: true,
162
166
  filterFromLeafRows: true,
163
167
  autoResetGlobalFilter: true,
164
- globalFilterType: 'auto',
168
+ globalFilterFn: 'auto',
165
169
  getColumnCanGlobalFilterFn: column => {
166
170
  const value = instance
167
171
  .getCoreRowModel()
@@ -291,7 +295,7 @@ export const Filters = {
291
295
  },
292
296
  getColumnFilterFn: columnId => {
293
297
  const column = instance.getColumn(columnId)
294
- const userFilterTypes = instance.options.filterFns
298
+ const userFilterFns = instance.options.filterFns
295
299
 
296
300
  if (!column) {
297
301
  throw new Error()
@@ -301,27 +305,27 @@ export const Filters = {
301
305
  ? column.filterFn
302
306
  : column.filterFn === 'auto'
303
307
  ? instance.getColumnAutoFilterFn(columnId)
304
- : (userFilterTypes as Record<string, any>)?.[
308
+ : (userFilterFns as Record<string, any>)?.[
305
309
  column.filterFn as string
306
310
  ] ??
307
311
  (filterFns[
308
- column.filterFn as BuiltInFilterType
312
+ column.filterFn as BuiltInFilterFn
309
313
  ] as FilterFn<TGenerics>)
310
314
  },
311
315
 
312
316
  getGlobalFilterFn: () => {
313
- const { filterFns: userFilterTypes, globalFilterType } =
317
+ const { filterFns: userFilterFns, globalFilterFn: globalFilterFn } =
314
318
  instance.options
315
319
 
316
- return isFunction(globalFilterType)
317
- ? globalFilterType
318
- : globalFilterType === 'auto'
320
+ return isFunction(globalFilterFn)
321
+ ? globalFilterFn
322
+ : globalFilterFn === 'auto'
319
323
  ? instance.getGlobalAutoFilterFn()
320
- : (userFilterTypes as Record<string, any>)?.[
321
- globalFilterType as string
324
+ : (userFilterFns as Record<string, any>)?.[
325
+ globalFilterFn as string
322
326
  ] ??
323
327
  (filterFns[
324
- globalFilterType as BuiltInFilterType
328
+ globalFilterFn as BuiltInFilterFn
325
329
  ] as FilterFn<TGenerics>)
326
330
  },
327
331
 
@@ -373,8 +377,8 @@ export const Filters = {
373
377
  column.enableColumnFilter ??
374
378
  instance.options.enableFilters ??
375
379
  instance.options.enableColumnFilters ??
376
- column.defaultCanFilter ??
377
380
  column.defaultCanColumnFilter ??
381
+ column.defaultCanFilter ??
378
382
  !!column.accessorFn
379
383
  )
380
384
  },
@@ -391,8 +395,8 @@ export const Filters = {
391
395
  instance.options.enableGlobalFilter ??
392
396
  column.enableAllFilters ??
393
397
  column.enableGlobalFilter ??
394
- column.defaultCanFilter ??
395
398
  column.defaultCanGlobalFilter ??
399
+ column.defaultCanFilter ??
396
400
  !!column.accessorFn) &&
397
401
  instance.options.getColumnCanGlobalFilterFn?.(column)) ??
398
402
  true
@@ -1,5 +1,5 @@
1
1
  import { RowModel } from '..'
2
- import { BuiltInAggregationType, aggregationFns } from '../aggregationFns'
2
+ import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
3
3
  import {
4
4
  Cell,
5
5
  Column,
@@ -30,14 +30,14 @@ export type AggregationFn<TGenerics extends AnyGenerics> = (
30
30
  getChildValues: () => TGenerics['Row'][]
31
31
  ) => any
32
32
 
33
- export type CustomAggregationTypes<TGenerics extends AnyGenerics> = Record<
33
+ export type CustomAggregationFns<TGenerics extends AnyGenerics> = Record<
34
34
  string,
35
35
  AggregationFn<TGenerics>
36
36
  >
37
37
 
38
- export type AggregationType<TGenerics extends AnyGenerics> =
38
+ export type AggregationFnOption<TGenerics extends AnyGenerics> =
39
39
  | 'auto'
40
- | BuiltInAggregationType
40
+ | BuiltInAggregationFn
41
41
  | keyof TGenerics['AggregationFns']
42
42
  | AggregationFn<TGenerics>
43
43
 
@@ -46,7 +46,7 @@ export type GroupingTableState = {
46
46
  }
47
47
 
48
48
  export type GroupingColumnDef<TGenerics extends AnyGenerics> = {
49
- aggregationFn?: AggregationType<Overwrite<TGenerics, { Value: any }>>
49
+ aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
50
50
  aggregateValue?: (columnValue: unknown) => any
51
51
  aggregatedCell?: Renderable<
52
52
  TGenerics,
@@ -63,7 +63,7 @@ export type GroupingColumnDef<TGenerics extends AnyGenerics> = {
63
63
  }
64
64
 
65
65
  export type GroupingColumn<TGenerics extends AnyGenerics> = {
66
- aggregationFn?: AggregationType<Overwrite<TGenerics, { Value: any }>>
66
+ aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
67
67
  getCanGroup: () => boolean
68
68
  getIsGrouped: () => boolean
69
69
  getGroupedIndex: () => number
@@ -221,7 +221,7 @@ export const Grouping = {
221
221
  },
222
222
  getColumnAggregationFn: columnId => {
223
223
  const column = instance.getColumn(columnId)
224
- const userAggregationTypes = instance.options.aggregationFns
224
+ const userAggregationFns = instance.options.aggregationFns
225
225
 
226
226
  if (!column) {
227
227
  throw new Error()
@@ -231,11 +231,11 @@ export const Grouping = {
231
231
  ? column.aggregationFn
232
232
  : column.aggregationFn === 'auto'
233
233
  ? instance.getColumnAutoAggregationFn(columnId)
234
- : (userAggregationTypes as Record<string, any>)?.[
234
+ : (userAggregationFns as Record<string, any>)?.[
235
235
  column.aggregationFn as string
236
236
  ] ??
237
237
  (aggregationFns[
238
- column.aggregationFn as BuiltInAggregationType
238
+ column.aggregationFn as BuiltInAggregationFn
239
239
  ] as AggregationFn<TGenerics>)
240
240
  },
241
241
 
@@ -1,5 +1,9 @@
1
1
  import { RowModel } from '..'
2
- import { BuiltInSortType, reSplitAlphaNumeric, sortingFns } from '../sortingFns'
2
+ import {
3
+ BuiltInSortingFn,
4
+ reSplitAlphaNumeric,
5
+ sortingFns,
6
+ } from '../sortingFns'
3
7
 
4
8
  import {
5
9
  Column,
@@ -36,7 +40,7 @@ export type SortingFn<TGenerics extends AnyGenerics> = {
36
40
  (rowA: Row<TGenerics>, rowB: Row<TGenerics>, columnId: string): number
37
41
  }
38
42
 
39
- export type CustomSortingTypes<TGenerics extends AnyGenerics> = Record<
43
+ export type CustomSortingFns<TGenerics extends AnyGenerics> = Record<
40
44
  string,
41
45
  SortingFn<TGenerics>
42
46
  >
@@ -45,14 +49,14 @@ export type SortingTableState = {
45
49
  sorting: SortingState
46
50
  }
47
51
 
48
- export type SortType<TGenerics extends AnyGenerics> =
52
+ export type SortingFnOption<TGenerics extends AnyGenerics> =
49
53
  | 'auto'
50
- | BuiltInSortType
54
+ | BuiltInSortingFn
51
55
  | keyof TGenerics['SortingFns']
52
56
  | SortingFn<TGenerics>
53
57
 
54
58
  export type SortingColumnDef<TGenerics extends AnyGenerics> = {
55
- sortingFn?: SortType<Overwrite<TGenerics, { Value: any }>>
59
+ sortingFn?: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
56
60
  sortDescFirst?: boolean
57
61
  enableSorting?: boolean
58
62
  enableMultiSort?: boolean
@@ -62,7 +66,7 @@ export type SortingColumnDef<TGenerics extends AnyGenerics> = {
62
66
  }
63
67
 
64
68
  export type SortingColumn<TGenerics extends AnyGenerics> = {
65
- sortingFn: SortType<Overwrite<TGenerics, { Value: any }>>
69
+ sortingFn: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
66
70
  getCanSort: () => boolean
67
71
  getCanMultiSort: () => boolean
68
72
  getSortIndex: () => number
@@ -236,7 +240,7 @@ export const Sorting = {
236
240
  },
237
241
  getColumnSortingFn: columnId => {
238
242
  const column = instance.getColumn(columnId)
239
- const userSortTypes = instance.options.sortingFns
243
+ const userSortingFn = instance.options.sortingFns
240
244
 
241
245
  if (!column) {
242
246
  throw new Error()
@@ -246,11 +250,11 @@ export const Sorting = {
246
250
  ? column.sortingFn
247
251
  : column.sortingFn === 'auto'
248
252
  ? instance.getColumnAutoSortingFn(columnId)
249
- : (userSortTypes as Record<string, any>)?.[
253
+ : (userSortingFn as Record<string, any>)?.[
250
254
  column.sortingFn as string
251
255
  ] ??
252
256
  (sortingFns[
253
- column.sortingFn as BuiltInSortType
257
+ column.sortingFn as BuiltInSortingFn
254
258
  ] as SortingFn<TGenerics>)
255
259
  },
256
260
 
package/src/filterFns.ts CHANGED
@@ -12,7 +12,7 @@ export const filterFns = {
12
12
  betweenNumberRange,
13
13
  }
14
14
 
15
- export type BuiltInFilterType = keyof typeof filterFns
15
+ export type BuiltInFilterFn = keyof typeof filterFns
16
16
 
17
17
  function includesString<TGenerics extends AnyGenerics>(
18
18
  rows: Row<TGenerics>[],
package/src/sortingFns.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PartialGenerics, AnyGenerics, Row } from './types'
1
+ import { AnyGenerics, Row } from './types'
2
2
 
3
3
  export const reSplitAlphaNumeric = /([0-9]+)/gm
4
4
 
@@ -11,7 +11,7 @@ export const sortingFns = {
11
11
  basic,
12
12
  }
13
13
 
14
- export type BuiltInSortType = keyof typeof sortingFns
14
+ export type BuiltInSortingFn = keyof typeof sortingFns
15
15
 
16
16
  function alphanumeric<TGenerics extends AnyGenerics>(
17
17
  rowA: Row<TGenerics>,