@tanstack/table-core 8.0.13 → 8.1.1

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 (96) hide show
  1. package/build/cjs/core/cell.js +13 -13
  2. package/build/cjs/core/cell.js.map +1 -1
  3. package/build/cjs/core/column.js +20 -21
  4. package/build/cjs/core/column.js.map +1 -1
  5. package/build/cjs/core/headers.js +63 -68
  6. package/build/cjs/core/headers.js.map +1 -1
  7. package/build/cjs/core/row.js +16 -11
  8. package/build/cjs/core/row.js.map +1 -1
  9. package/build/cjs/core/{instance.js → table.js} +46 -57
  10. package/build/cjs/core/table.js.map +1 -0
  11. package/build/cjs/features/ColumnSizing.js +36 -36
  12. package/build/cjs/features/ColumnSizing.js.map +1 -1
  13. package/build/cjs/features/Expanding.js +34 -34
  14. package/build/cjs/features/Expanding.js.map +1 -1
  15. package/build/cjs/features/Filters.js +46 -52
  16. package/build/cjs/features/Filters.js.map +1 -1
  17. package/build/cjs/features/Grouping.js +24 -49
  18. package/build/cjs/features/Grouping.js.map +1 -1
  19. package/build/cjs/features/Ordering.js +8 -8
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js +37 -37
  22. package/build/cjs/features/Pagination.js.map +1 -1
  23. package/build/cjs/features/Pinning.js +33 -33
  24. package/build/cjs/features/Pinning.js.map +1 -1
  25. package/build/cjs/features/RowSelection.js +86 -74
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Sorting.js +36 -40
  28. package/build/cjs/features/Sorting.js.map +1 -1
  29. package/build/cjs/features/Visibility.js +30 -30
  30. package/build/cjs/features/Visibility.js.map +1 -1
  31. package/build/cjs/index.js +3 -4
  32. package/build/cjs/index.js.map +1 -1
  33. package/build/cjs/utils/filterRowsUtils.js +8 -8
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getCoreRowModel.js +8 -8
  36. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  37. package/build/cjs/utils/getExpandedRowModel.js +4 -4
  38. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  39. package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
  40. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
  41. package/build/cjs/utils/getFacetedRowModel.js +4 -4
  42. package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
  43. package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
  44. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
  45. package/build/cjs/utils/getFilteredRowModel.js +8 -8
  46. package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
  47. package/build/cjs/utils/getGroupedRowModel.js +9 -9
  48. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  49. package/build/cjs/utils/getPaginationRowModel.js +4 -4
  50. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  51. package/build/cjs/utils/getSortedRowModel.js +7 -7
  52. package/build/cjs/utils/getSortedRowModel.js.map +1 -1
  53. package/build/cjs/utils.js +2 -2
  54. package/build/cjs/utils.js.map +1 -1
  55. package/build/esm/index.js +585 -677
  56. package/build/esm/index.js.map +1 -1
  57. package/build/stats-html.html +1 -1
  58. package/build/stats-react.json +352 -377
  59. package/build/types/index.d.ts +286 -360
  60. package/build/umd/index.development.js +586 -678
  61. package/build/umd/index.development.js.map +1 -1
  62. package/build/umd/index.production.js +1 -1
  63. package/build/umd/index.production.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/core/cell.ts +34 -28
  66. package/src/core/column.ts +83 -72
  67. package/src/core/headers.ts +118 -149
  68. package/src/core/row.ts +31 -25
  69. package/src/core/{instance.ts → table.ts} +85 -116
  70. package/src/features/ColumnSizing.ts +45 -47
  71. package/src/features/Expanding.ts +53 -59
  72. package/src/features/Filters.ts +112 -132
  73. package/src/features/Grouping.ts +63 -112
  74. package/src/features/Ordering.ts +19 -21
  75. package/src/features/Pagination.ts +54 -55
  76. package/src/features/Pinning.ts +49 -61
  77. package/src/features/RowSelection.ts +115 -114
  78. package/src/features/Sorting.ts +57 -72
  79. package/src/features/Visibility.ts +48 -48
  80. package/src/index.ts +1 -2
  81. package/src/types.ts +64 -69
  82. package/src/utils/filterRowsUtils.ts +33 -28
  83. package/src/utils/getCoreRowModel.ts +22 -22
  84. package/src/utils/getExpandedRowModel.ts +15 -15
  85. package/src/utils/getFacetedMinMaxValues.ts +6 -6
  86. package/src/utils/getFacetedRowModel.ts +12 -12
  87. package/src/utils/getFacetedUniqueValues.ts +6 -6
  88. package/src/utils/getFilteredRowModel.ts +17 -17
  89. package/src/utils/getGroupedRowModel.ts +18 -21
  90. package/src/utils/getPaginationRowModel.ts +10 -13
  91. package/src/utils/getSortedRowModel.ts +14 -14
  92. package/src/utils.ts +8 -2
  93. package/build/cjs/core/instance.js.map +0 -1
  94. package/build/cjs/createTable.js +0 -72
  95. package/build/cjs/createTable.js.map +0 -1
  96. package/src/createTable.ts +0 -188
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CoreOptions, CoreTableState, CoreInstance } from './core/instance'
1
+ import { CoreOptions, CoreTableState, CoreInstance } from './core/table'
2
2
  import { CoreColumn, CoreColumnDef } from './core/column'
3
3
  import {
4
4
  VisibilityInstance,
@@ -38,6 +38,7 @@ import {
38
38
  SortingTableState,
39
39
  } from './features/Sorting'
40
40
  import {
41
+ CustomAggregationFns,
41
42
  GroupingCell,
42
43
  GroupingColumn,
43
44
  GroupingColumnDef,
@@ -79,51 +80,45 @@ import { CoreCell } from './core/cell'
79
80
  export type Updater<T> = T | ((old: T) => T)
80
81
  export type OnChangeFn<T> = (updaterOrValue: Updater<T>) => void
81
82
 
83
+ export type RowData = object | any[]
84
+
82
85
  export type TableGenerics = {
83
86
  Row?: any
84
87
  Value?: any
85
- FilterFns?: any
86
- SortingFns?: any
87
- AggregationFns?: any
88
- Renderer?: any
89
- Rendered?: any
90
88
  ColumnMeta?: any
91
89
  TableMeta?: any
92
- FilterMeta?: any
93
90
  }
94
91
 
95
92
  export type AnyRender = (Comp: any, props: any) => any
96
93
 
97
- export type TableInstance<TGenerics extends TableGenerics> =
98
- CoreInstance<TGenerics> &
99
- HeadersInstance<TGenerics> &
100
- VisibilityInstance<TGenerics> &
101
- ColumnOrderInstance<TGenerics> &
102
- ColumnPinningInstance<TGenerics> &
103
- FiltersInstance<TGenerics> &
104
- SortingInstance<TGenerics> &
105
- GroupingInstance<TGenerics> &
106
- ColumnSizingInstance<TGenerics> &
107
- ExpandedInstance<TGenerics> &
108
- PaginationInstance<TGenerics> &
109
- RowSelectionInstance<TGenerics>
110
-
111
- export type TableOptionsResolved<TGenerics extends TableGenerics> =
112
- CoreOptions<TGenerics> &
113
- VisibilityOptions &
114
- ColumnOrderOptions &
115
- ColumnPinningOptions &
116
- FiltersOptions<TGenerics> &
117
- SortingOptions<TGenerics> &
118
- GroupingOptions<TGenerics> &
119
- ExpandedOptions<TGenerics> &
120
- ColumnSizingOptions &
121
- PaginationOptions<TGenerics> &
122
- RowSelectionOptions<TGenerics>
123
-
124
- export type TableOptions<TGenerics extends TableGenerics> = Omit<
125
- PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>,
126
- 'render' | 'renderFallbackValue'
94
+ export type Table<TData extends RowData> = CoreInstance<TData> &
95
+ HeadersInstance<TData> &
96
+ VisibilityInstance<TData> &
97
+ ColumnOrderInstance<TData> &
98
+ ColumnPinningInstance<TData> &
99
+ FiltersInstance<TData> &
100
+ SortingInstance<TData> &
101
+ GroupingInstance<TData> &
102
+ ColumnSizingInstance &
103
+ ExpandedInstance<TData> &
104
+ PaginationInstance<TData> &
105
+ RowSelectionInstance<TData>
106
+
107
+ export type TableOptionsResolved<TData extends RowData> = CoreOptions<TData> &
108
+ VisibilityOptions &
109
+ ColumnOrderOptions &
110
+ ColumnPinningOptions &
111
+ FiltersOptions<TData> &
112
+ SortingOptions<TData> &
113
+ GroupingOptions &
114
+ ExpandedOptions<TData> &
115
+ ColumnSizingOptions &
116
+ PaginationOptions &
117
+ RowSelectionOptions<TData>
118
+
119
+ export type TableOptions<TData extends RowData> = PartialKeys<
120
+ TableOptionsResolved<TData>,
121
+ 'state' | 'onStateChange' | 'renderFallbackValue'
127
122
  >
128
123
 
129
124
  export type TableState = CoreTableState &
@@ -152,10 +147,10 @@ export type InitialTableState = Partial<
152
147
  RowSelectionTableState
153
148
  >
154
149
 
155
- export type Row<TGenerics extends TableGenerics> = CoreRow<TGenerics> &
156
- VisibilityRow<TGenerics> &
157
- ColumnPinningRow<TGenerics> &
158
- FiltersRow<TGenerics> &
150
+ export type Row<TData extends RowData> = CoreRow<TData> &
151
+ VisibilityRow<TData> &
152
+ ColumnPinningRow<TData> &
153
+ FiltersRow<TData> &
159
154
  GroupingRow &
160
155
  RowSelectionRow &
161
156
  ExpandedRow
@@ -164,42 +159,42 @@ export type RowValues = {
164
159
  [key: string]: any
165
160
  }
166
161
 
167
- export type RowModel<TGenerics extends TableGenerics> = {
168
- rows: Row<TGenerics>[]
169
- flatRows: Row<TGenerics>[]
170
- rowsById: Record<string, Row<TGenerics>>
162
+ export type RowModel<TData extends RowData> = {
163
+ rows: Row<TData>[]
164
+ flatRows: Row<TData>[]
165
+ rowsById: Record<string, Row<TData>>
171
166
  }
172
167
 
173
- export type AccessorFn<TData> = (originalRow: TData, index: number) => any
168
+ export type AccessorFn<TData extends RowData> = (
169
+ originalRow: TData,
170
+ index: number
171
+ ) => any
174
172
 
175
- export type Renderable<TGenerics extends TableGenerics, TProps> =
173
+ export type ColumnDefTemplate<TProps extends object> =
176
174
  | string
177
- | ((props: TProps) => TGenerics['Rendered'])
178
-
179
- export type ColumnDef<TGenerics extends TableGenerics> =
180
- CoreColumnDef<TGenerics> &
181
- VisibilityColumnDef &
182
- ColumnPinningColumnDef &
183
- FiltersColumnDef<TGenerics> &
184
- SortingColumnDef<TGenerics> &
185
- GroupingColumnDef<TGenerics> &
186
- ColumnSizingColumnDef
187
-
188
- export type Column<TGenerics extends TableGenerics> = CoreColumn<TGenerics> &
175
+ | ((props: TProps) => unknown)
176
+
177
+ export type ColumnDef<TData extends RowData> = CoreColumnDef<TData> &
178
+ VisibilityColumnDef &
179
+ ColumnPinningColumnDef &
180
+ FiltersColumnDef<TData> &
181
+ SortingColumnDef<TData> &
182
+ GroupingColumnDef<TData> &
183
+ ColumnSizingColumnDef
184
+
185
+ export type Column<TData extends RowData> = CoreColumn<TData> &
189
186
  ColumnVisibilityColumn &
190
187
  ColumnPinningColumn &
191
- FiltersColumn<TGenerics> &
192
- SortingColumn<TGenerics> &
193
- GroupingColumn<TGenerics> &
194
- ColumnSizingColumn<TGenerics>
188
+ FiltersColumn<TData> &
189
+ SortingColumn<TData> &
190
+ GroupingColumn<TData> &
191
+ ColumnSizingColumn
195
192
 
196
- export type Cell<TGenerics extends TableGenerics> = CoreCell<TGenerics> &
197
- GroupingCell<TGenerics>
193
+ export type Cell<TData extends RowData> = CoreCell<TData> & GroupingCell
198
194
 
199
- export type Header<TGenerics extends TableGenerics> = CoreHeader<TGenerics> &
200
- ColumnSizingHeader<TGenerics>
195
+ export type Header<TData extends RowData> = CoreHeader<TData> &
196
+ ColumnSizingHeader
201
197
 
202
- export type HeaderGroup<TGenerics extends TableGenerics> =
203
- CoreHeaderGroup<TGenerics>
198
+ export type HeaderGroup<TData extends RowData> = CoreHeaderGroup<TData>
204
199
 
205
200
  export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
@@ -1,36 +1,41 @@
1
1
  import { createRow } from '../core/row'
2
- import { TableGenerics, Row, RowModel, TableInstance } from '../types'
2
+ import { TableGenerics, Row, RowModel, Table, RowData } from '../types'
3
3
 
4
- export function filterRows<TGenerics extends TableGenerics>(
5
- rows: Row<TGenerics>[],
6
- filterRowImpl: (row: Row<TGenerics>) => any,
7
- instance: TableInstance<TGenerics>
4
+ export function filterRows<TData extends RowData>(
5
+ rows: Row<TData>[],
6
+ filterRowImpl: (row: Row<TData>) => any,
7
+ table: Table<TData>
8
8
  ) {
9
- if (instance.options.filterFromLeafRows) {
10
- return filterRowModelFromLeafs(rows, filterRowImpl, instance)
9
+ if (table.options.filterFromLeafRows) {
10
+ return filterRowModelFromLeafs(rows, filterRowImpl, table)
11
11
  }
12
12
 
13
- return filterRowModelFromRoot(rows, filterRowImpl, instance)
13
+ return filterRowModelFromRoot(rows, filterRowImpl, table)
14
14
  }
15
15
 
16
- export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
17
- rowsToFilter: Row<TGenerics>[],
18
- filterRow: (row: Row<TGenerics>) => Row<TGenerics>[],
19
- instance: TableInstance<TGenerics>
20
- ): RowModel<TGenerics> {
21
- const newFilteredFlatRows: Row<TGenerics>[] = []
22
- const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
16
+ export function filterRowModelFromLeafs<TData extends RowData>(
17
+ rowsToFilter: Row<TData>[],
18
+ filterRow: (row: Row<TData>) => Row<TData>[],
19
+ table: Table<TData>
20
+ ): RowModel<TData> {
21
+ const newFilteredFlatRows: Row<TData>[] = []
22
+ const newFilteredRowsById: Record<string, Row<TData>> = {}
23
23
 
24
-
25
- const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
26
- const rows: Row<TGenerics>[] = []
24
+ const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {
25
+ const rows: Row<TData>[] = []
27
26
 
28
27
  // Filter from children up first
29
28
  for (let i = 0; i < rowsToFilter.length; i++) {
30
29
  let row = rowsToFilter[i]!
31
30
 
32
31
  if (row.subRows?.length) {
33
- const newRow = createRow(instance, row.id, row.original, row.index, row.depth)
32
+ const newRow = createRow(
33
+ table,
34
+ row.id,
35
+ row.original,
36
+ row.index,
37
+ row.depth
38
+ )
34
39
  newRow.columnFilters = row.columnFilters
35
40
  newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
36
41
  if (!newRow.subRows.length) {
@@ -56,16 +61,16 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
56
61
  }
57
62
  }
58
63
 
59
- export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
60
- rowsToFilter: Row<TGenerics>[],
61
- filterRow: (row: Row<TGenerics>) => any,
62
- instance: TableInstance<TGenerics>
63
- ): RowModel<TGenerics> {
64
- const newFilteredFlatRows: Row<TGenerics>[] = []
65
- const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
64
+ export function filterRowModelFromRoot<TData extends RowData>(
65
+ rowsToFilter: Row<TData>[],
66
+ filterRow: (row: Row<TData>) => any,
67
+ table: Table<TData>
68
+ ): RowModel<TData> {
69
+ const newFilteredFlatRows: Row<TData>[] = []
70
+ const newFilteredRowsById: Record<string, Row<TData>> = {}
66
71
 
67
72
  // Filters top level and nested rows
68
- const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
73
+ const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {
69
74
  // Filter from parents downward first
70
75
 
71
76
  const rows = []
@@ -79,7 +84,7 @@ export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
79
84
  if (pass) {
80
85
  if (row.subRows?.length) {
81
86
  const newRow = createRow(
82
- instance,
87
+ table,
83
88
  row.id,
84
89
  row.original,
85
90
  row.index,
@@ -1,32 +1,32 @@
1
1
  import { createRow } from '../core/row'
2
- import { TableInstance, Row, RowModel, TableGenerics } from '../types'
2
+ import { Table, Row, RowModel, TableGenerics, RowData } from '../types'
3
3
  import { memo } from '../utils'
4
4
 
5
- export function getCoreRowModel<TGenerics extends TableGenerics>(): (
6
- instance: TableInstance<TGenerics>
7
- ) => () => RowModel<TGenerics> {
8
- return instance =>
5
+ export function getCoreRowModel<TData extends RowData>(): (
6
+ table: Table<TData>
7
+ ) => () => RowModel<TData> {
8
+ return table =>
9
9
  memo(
10
- () => [instance.options.data],
10
+ () => [table.options.data],
11
11
  (
12
12
  data
13
13
  ): {
14
- rows: Row<TGenerics>[]
15
- flatRows: Row<TGenerics>[]
16
- rowsById: Record<string, Row<TGenerics>>
14
+ rows: Row<TData>[]
15
+ flatRows: Row<TData>[]
16
+ rowsById: Record<string, Row<TData>>
17
17
  } => {
18
- const rowModel: RowModel<TGenerics> = {
18
+ const rowModel: RowModel<TData> = {
19
19
  rows: [],
20
20
  flatRows: [],
21
21
  rowsById: {},
22
22
  }
23
23
 
24
24
  const accessRows = (
25
- originalRows: TGenerics['Row'][],
25
+ originalRows: TData[],
26
26
  depth = 0,
27
- parent?: Row<TGenerics>
28
- ): Row<TGenerics>[] => {
29
- const rows = [] as Row<TGenerics>[]
27
+ parent?: Row<TData>
28
+ ): Row<TData>[] => {
29
+ const rows = [] as Row<TData>[]
30
30
 
31
31
  for (let i = 0; i < originalRows.length; i++) {
32
32
  // This could be an expensive check at scale, so we should move it somewhere else, but where?
@@ -38,8 +38,8 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
38
38
 
39
39
  // Make the row
40
40
  const row = createRow(
41
- instance,
42
- instance._getRowId(originalRows[i], i, parent),
41
+ table,
42
+ table._getRowId(originalRows[i]!, i, parent),
43
43
  originalRows[i],
44
44
  i,
45
45
  depth
@@ -49,13 +49,13 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
49
49
  rowModel.flatRows.push(row)
50
50
  // Also keep track of every row by its ID
51
51
  rowModel.rowsById[row.id] = row
52
- // Push instance row into parent
52
+ // Push table row into parent
53
53
  rows.push(row)
54
54
 
55
55
  // Get the original subrows
56
- if (instance.options.getSubRows) {
57
- row.originalSubRows = instance.options.getSubRows(
58
- originalRows[i],
56
+ if (table.options.getSubRows) {
57
+ row.originalSubRows = table.options.getSubRows(
58
+ originalRows[i]!,
59
59
  i
60
60
  )
61
61
 
@@ -75,9 +75,9 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
75
75
  },
76
76
  {
77
77
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
78
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
78
+ debug: () => table.options.debugAll ?? table.options.debugTable,
79
79
  onChange: () => {
80
- instance._autoResetPageIndex()
80
+ table._autoResetPageIndex()
81
81
  },
82
82
  }
83
83
  )
@@ -1,15 +1,15 @@
1
- import { TableInstance, Row, RowModel, TableGenerics } from '../types'
1
+ import { Table, Row, RowModel, TableGenerics, RowData } from '../types'
2
2
  import { memo } from '../utils'
3
3
 
4
- export function getExpandedRowModel<TGenerics extends TableGenerics>(): (
5
- instance: TableInstance<TGenerics>
6
- ) => () => RowModel<TGenerics> {
7
- return instance =>
4
+ export function getExpandedRowModel<TData extends RowData>(): (
5
+ table: Table<TData>
6
+ ) => () => RowModel<TData> {
7
+ return table =>
8
8
  memo(
9
9
  () => [
10
- instance.getState().expanded,
11
- instance.getPreExpandedRowModel(),
12
- instance.options.paginateExpandedRows,
10
+ table.getState().expanded,
11
+ table.getPreExpandedRowModel(),
12
+ table.options.paginateExpandedRows,
13
13
  ],
14
14
  (expanded, rowModel, paginateExpandedRows) => {
15
15
  if (
@@ -21,22 +21,22 @@ export function getExpandedRowModel<TGenerics extends TableGenerics>(): (
21
21
  return rowModel
22
22
  }
23
23
 
24
- return expandRows(rowModel, instance)
24
+ return expandRows(rowModel, table)
25
25
  },
26
26
  {
27
27
  key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
28
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
28
+ debug: () => table.options.debugAll ?? table.options.debugTable,
29
29
  }
30
30
  )
31
31
  }
32
32
 
33
- export function expandRows<TGenerics extends TableGenerics>(
34
- rowModel: RowModel<TGenerics>,
35
- instance: TableInstance<TGenerics>
33
+ export function expandRows<TData extends RowData>(
34
+ rowModel: RowModel<TData>,
35
+ table: Table<TData>
36
36
  ) {
37
- const expandedRows: Row<TGenerics>[] = []
37
+ const expandedRows: Row<TData>[] = []
38
38
 
39
- const handleRow = (row: Row<TGenerics>) => {
39
+ const handleRow = (row: Row<TData>) => {
40
40
  expandedRows.push(row)
41
41
 
42
42
  if (row.subRows?.length && row.getIsExpanded()) {
@@ -1,13 +1,13 @@
1
- import { TableInstance, TableGenerics } from '../types'
1
+ import { Table, TableGenerics, RowData } from '../types'
2
2
  import { memo } from '../utils'
3
3
 
4
- export function getFacetedMinMaxValues<TGenerics extends TableGenerics>(): (
5
- instance: TableInstance<TGenerics>,
4
+ export function getFacetedMinMaxValues<TData extends RowData>(): (
5
+ table: Table<TData>,
6
6
  columnId: string
7
7
  ) => () => undefined | [number, number] {
8
- return (instance, columnId) =>
8
+ return (table, columnId) =>
9
9
  memo(
10
- () => [instance.getColumn(columnId).getFacetedRowModel()],
10
+ () => [table.getColumn(columnId).getFacetedRowModel()],
11
11
  facetedRowModel => {
12
12
  const firstValue = facetedRowModel.flatRows[0]?.getValue(columnId)
13
13
 
@@ -33,7 +33,7 @@ export function getFacetedMinMaxValues<TGenerics extends TableGenerics>(): (
33
33
  key:
34
34
  process.env.NODE_ENV === 'development' &&
35
35
  'getFacetedMinMaxValues_' + columnId,
36
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
36
+ debug: () => table.options.debugAll ?? table.options.debugTable,
37
37
  onChange: () => {},
38
38
  }
39
39
  )
@@ -1,18 +1,18 @@
1
- import { TableInstance, RowModel, TableGenerics, Row } from '../types'
1
+ import { Table, RowModel, TableGenerics, Row, RowData } from '../types'
2
2
  import { memo } from '../utils'
3
3
  import { filterRows } from './filterRowsUtils'
4
4
 
5
- export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
6
- instance: TableInstance<TGenerics>,
5
+ export function getFacetedRowModel<TData extends RowData>(): (
6
+ table: Table<TData>,
7
7
  columnId: string
8
- ) => () => RowModel<TGenerics> {
9
- return (instance, columnId) =>
8
+ ) => () => RowModel<TData> {
9
+ return (table, columnId) =>
10
10
  memo(
11
11
  () => [
12
- instance.getPreFilteredRowModel(),
13
- instance.getState().columnFilters,
14
- instance.getState().globalFilter,
15
- instance.getFilteredRowModel(),
12
+ table.getPreFilteredRowModel(),
13
+ table.getState().columnFilters,
14
+ table.getState().globalFilter,
15
+ table.getFilteredRowModel(),
16
16
  ],
17
17
  (preRowModel, columnFilters, globalFilter) => {
18
18
  if (
@@ -27,7 +27,7 @@ export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
27
27
  globalFilter ? '__global__' : undefined,
28
28
  ].filter(Boolean) as string[]
29
29
 
30
- const filterRowsImpl = (row: Row<TGenerics>) => {
30
+ const filterRowsImpl = (row: Row<TData>) => {
31
31
  // Horizontally filter rows through each column
32
32
  for (let i = 0; i < filterableIds.length; i++) {
33
33
  if (row.columnFilters[filterableIds[i]!] === false) {
@@ -37,13 +37,13 @@ export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
37
37
  return true
38
38
  }
39
39
 
40
- return filterRows(preRowModel.rows, filterRowsImpl, instance)
40
+ return filterRows(preRowModel.rows, filterRowsImpl, table)
41
41
  },
42
42
  {
43
43
  key:
44
44
  process.env.NODE_ENV === 'development' &&
45
45
  'getFacetedRowModel_' + columnId,
46
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
46
+ debug: () => table.options.debugAll ?? table.options.debugTable,
47
47
  onChange: () => {},
48
48
  }
49
49
  )
@@ -1,13 +1,13 @@
1
- import { TableInstance, TableGenerics } from '../types'
1
+ import { Table, TableGenerics, RowData } from '../types'
2
2
  import { memo } from '../utils'
3
3
 
4
- export function getFacetedUniqueValues<TGenerics extends TableGenerics>(): (
5
- instance: TableInstance<TGenerics>,
4
+ export function getFacetedUniqueValues<TData extends RowData>(): (
5
+ table: Table<TData>,
6
6
  columnId: string
7
7
  ) => () => Map<any, number> {
8
- return (instance, columnId) =>
8
+ return (table, columnId) =>
9
9
  memo(
10
- () => [instance.getColumn(columnId).getFacetedRowModel()],
10
+ () => [table.getColumn(columnId).getFacetedRowModel()],
11
11
  facetedRowModel => {
12
12
  let facetedUniqueValues = new Map<any, number>()
13
13
 
@@ -30,7 +30,7 @@ export function getFacetedUniqueValues<TGenerics extends TableGenerics>(): (
30
30
  key:
31
31
  process.env.NODE_ENV === 'development' &&
32
32
  'getFacetedUniqueValues_' + columnId,
33
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
33
+ debug: () => table.options.debugAll ?? table.options.debugTable,
34
34
  onChange: () => {},
35
35
  }
36
36
  )
@@ -1,17 +1,17 @@
1
1
  import { ResolvedColumnFilter } from '../features/Filters'
2
- import { TableInstance, RowModel, TableGenerics, Row } from '../types'
2
+ import { Table, RowModel, TableGenerics, Row, RowData } from '../types'
3
3
  import { memo } from '../utils'
4
4
  import { filterRows } from './filterRowsUtils'
5
5
 
6
- export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
7
- instance: TableInstance<TGenerics>
8
- ) => () => RowModel<TGenerics> {
9
- return instance =>
6
+ export function getFilteredRowModel<TData extends RowData>(): (
7
+ table: Table<TData>
8
+ ) => () => RowModel<TData> {
9
+ return table =>
10
10
  memo(
11
11
  () => [
12
- instance.getPreFilteredRowModel(),
13
- instance.getState().columnFilters,
14
- instance.getState().globalFilter,
12
+ table.getPreFilteredRowModel(),
13
+ table.getState().columnFilters,
14
+ table.getState().globalFilter,
15
15
  ],
16
16
  (rowModel, columnFilters, globalFilter) => {
17
17
  if (
@@ -25,11 +25,11 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
25
25
  return rowModel
26
26
  }
27
27
 
28
- const resolvedColumnFilters: ResolvedColumnFilter<TGenerics>[] = []
29
- const resolvedGlobalFilters: ResolvedColumnFilter<TGenerics>[] = []
28
+ const resolvedColumnFilters: ResolvedColumnFilter<TData>[] = []
29
+ const resolvedGlobalFilters: ResolvedColumnFilter<TData>[] = []
30
30
 
31
31
  ;(columnFilters ?? []).forEach(d => {
32
- const column = instance.getColumn(d.id)
32
+ const column = table.getColumn(d.id)
33
33
 
34
34
  if (!column) {
35
35
  if (process.env.NODE_ENV !== 'production') {
@@ -59,9 +59,9 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
59
59
 
60
60
  const filterableIds = columnFilters.map(d => d.id)
61
61
 
62
- const globalFilterFn = instance.getGlobalFilterFn()
62
+ const globalFilterFn = table.getGlobalFilterFn()
63
63
 
64
- const globallyFilterableColumns = instance
64
+ const globallyFilterableColumns = table
65
65
  .getAllLeafColumns()
66
66
  .filter(column => column.getCanGlobalFilter())
67
67
 
@@ -135,7 +135,7 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
135
135
  }
136
136
  }
137
137
 
138
- const filterRowsImpl = (row: Row<TGenerics>) => {
138
+ const filterRowsImpl = (row: Row<TData>) => {
139
139
  // Horizontally filter rows through each column
140
140
  for (let i = 0; i < filterableIds.length; i++) {
141
141
  if (row.columnFilters[filterableIds[i]!] === false) {
@@ -146,13 +146,13 @@ export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
146
146
  }
147
147
 
148
148
  // Filter final rows using all of the active filters
149
- return filterRows(rowModel.rows, filterRowsImpl, instance)
149
+ return filterRows(rowModel.rows, filterRowsImpl, table)
150
150
  },
151
151
  {
152
152
  key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
153
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
153
+ debug: () => table.options.debugAll ?? table.options.debugTable,
154
154
  onChange: () => {
155
- instance._autoResetPageIndex()
155
+ table._autoResetPageIndex()
156
156
  },
157
157
  }
158
158
  )