@tanstack/table-core 8.0.0-alpha.65 → 8.0.0-alpha.69

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 (144) hide show
  1. package/build/cjs/aggregationFns.js +25 -37
  2. package/build/cjs/aggregationFns.js.map +1 -1
  3. package/build/cjs/core.js +167 -48
  4. package/build/cjs/core.js.map +1 -1
  5. package/build/cjs/createTable.js +24 -40
  6. package/build/cjs/createTable.js.map +1 -1
  7. package/build/cjs/features/Cells.js +28 -34
  8. package/build/cjs/features/Cells.js.map +1 -1
  9. package/build/cjs/features/ColumnSizing.js +136 -225
  10. package/build/cjs/features/ColumnSizing.js.map +1 -1
  11. package/build/cjs/features/Columns.js +57 -84
  12. package/build/cjs/features/Columns.js.map +1 -1
  13. package/build/cjs/features/Expanding.js +79 -126
  14. package/build/cjs/features/Expanding.js.map +1 -1
  15. package/build/cjs/features/Filters.js +137 -288
  16. package/build/cjs/features/Filters.js.map +1 -1
  17. package/build/cjs/features/Grouping.js +71 -117
  18. package/build/cjs/features/Grouping.js.map +1 -1
  19. package/build/cjs/features/Headers.js +125 -205
  20. package/build/cjs/features/Headers.js.map +1 -1
  21. package/build/cjs/features/Ordering.js +32 -44
  22. package/build/cjs/features/Ordering.js.map +1 -1
  23. package/build/cjs/features/Pagination.js +79 -82
  24. package/build/cjs/features/Pagination.js.map +1 -1
  25. package/build/cjs/features/Pinning.js +99 -178
  26. package/build/cjs/features/Pinning.js.map +1 -1
  27. package/build/cjs/features/RowSelection.js +133 -204
  28. package/build/cjs/features/RowSelection.js.map +1 -1
  29. package/build/cjs/features/Rows.js +32 -22
  30. package/build/cjs/features/Rows.js.map +1 -1
  31. package/build/cjs/features/Sorting.js +67 -136
  32. package/build/cjs/features/Sorting.js.map +1 -1
  33. package/build/cjs/features/Visibility.js +56 -118
  34. package/build/cjs/features/Visibility.js.map +1 -1
  35. package/build/cjs/filterFns.js +48 -72
  36. package/build/cjs/filterFns.js.map +1 -1
  37. package/build/cjs/index.js +13 -13
  38. package/build/cjs/sortingFns.js +21 -21
  39. package/build/cjs/sortingFns.js.map +1 -1
  40. package/build/cjs/utils/filterRowsUtils.js +49 -55
  41. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  42. package/build/cjs/utils/getCoreRowModel.js +98 -0
  43. package/build/cjs/utils/getCoreRowModel.js.map +1 -0
  44. package/build/cjs/utils/getExpandedRowModel.js +18 -22
  45. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  46. package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
  47. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
  48. package/build/cjs/utils/getFacetedRowModel.js +50 -0
  49. package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
  50. package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
  51. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
  52. package/build/cjs/utils/getFilteredRowModel.js +130 -0
  53. package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
  54. package/build/cjs/utils/getGroupedRowModel.js +126 -136
  55. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  56. package/build/cjs/utils/getPaginationRowModel.js +39 -39
  57. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  58. package/build/cjs/utils/getSortedRowModel.js +112 -0
  59. package/build/cjs/utils/getSortedRowModel.js.map +1 -0
  60. package/build/cjs/utils.js +36 -207
  61. package/build/cjs/utils.js.map +1 -1
  62. package/build/esm/index.js +2024 -2971
  63. package/build/esm/index.js.map +1 -1
  64. package/build/stats-html.html +1 -1
  65. package/build/stats-react.json +421 -481
  66. package/build/types/core.d.ts +3 -5
  67. package/build/types/features/Cells.d.ts +1 -1
  68. package/build/types/features/ColumnSizing.d.ts +4 -15
  69. package/build/types/features/Columns.d.ts +1 -1
  70. package/build/types/features/Expanding.d.ts +2 -7
  71. package/build/types/features/Filters.d.ts +24 -21
  72. package/build/types/features/Grouping.d.ts +5 -11
  73. package/build/types/features/Ordering.d.ts +1 -1
  74. package/build/types/features/Pagination.d.ts +3 -3
  75. package/build/types/features/Pinning.d.ts +1 -5
  76. package/build/types/features/RowSelection.d.ts +2 -8
  77. package/build/types/features/Rows.d.ts +4 -3
  78. package/build/types/features/Sorting.d.ts +5 -15
  79. package/build/types/features/Visibility.d.ts +1 -4
  80. package/build/types/index.d.ts +6 -4
  81. package/build/types/types.d.ts +3 -15
  82. package/build/types/utils/filterRowsUtils.d.ts +3 -3
  83. package/build/types/utils/getCoreRowModel.d.ts +2 -0
  84. package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
  85. package/build/types/utils/getFacetedRowModel.d.ts +2 -0
  86. package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
  87. package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
  88. package/build/types/utils/getGroupedRowModel.d.ts +1 -1
  89. package/build/types/utils/getSortedRowModel.d.ts +2 -0
  90. package/build/types/utils.d.ts +1 -17
  91. package/build/umd/index.development.js +2053 -3002
  92. package/build/umd/index.development.js.map +1 -1
  93. package/build/umd/index.production.js +1 -1
  94. package/build/umd/index.production.js.map +1 -1
  95. package/package.json +1 -1
  96. package/src/core.ts +197 -47
  97. package/src/features/Cells.ts +7 -11
  98. package/src/features/ColumnSizing.ts +89 -139
  99. package/src/features/Columns.ts +10 -13
  100. package/src/features/Expanding.ts +62 -107
  101. package/src/features/Filters.ts +201 -308
  102. package/src/features/Grouping.ts +55 -81
  103. package/src/features/Headers.ts +18 -40
  104. package/src/features/Ordering.ts +6 -4
  105. package/src/features/Pagination.ts +31 -17
  106. package/src/features/Pinning.ts +79 -96
  107. package/src/features/RowSelection.ts +68 -118
  108. package/src/features/Rows.ts +21 -6
  109. package/src/features/Sorting.ts +47 -103
  110. package/src/features/Visibility.ts +24 -47
  111. package/src/filterFns.ts +9 -9
  112. package/src/index.ts +12 -4
  113. package/src/sortingFns.ts +11 -11
  114. package/src/types.ts +3 -18
  115. package/src/utils/filterRowsUtils.ts +47 -68
  116. package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +3 -9
  117. package/src/utils/getExpandedRowModel.ts +2 -2
  118. package/src/utils/getFacetedMinMaxValues.ts +37 -0
  119. package/src/utils/getFacetedRowModel.ts +50 -0
  120. package/src/utils/getFacetedUniqueValues.ts +37 -0
  121. package/src/utils/getFilteredRowModel.ts +150 -0
  122. package/src/utils/getGroupedRowModel.ts +53 -62
  123. package/src/utils/getPaginationRowModel.ts +1 -1
  124. package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +7 -7
  125. package/src/utils.ts +28 -236
  126. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
  127. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  128. package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
  129. package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
  130. package/build/cjs/utils/getCoreRowModelSync.js +0 -102
  131. package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
  132. package/build/cjs/utils/getFilteredRowModelSync.js +0 -130
  133. package/build/cjs/utils/getFilteredRowModelSync.js.map +0 -1
  134. package/build/cjs/utils/getSortedRowModelSync.js +0 -118
  135. package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
  136. package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
  137. package/build/types/utils/getFilteredRowModelAsync.d.ts +0 -4
  138. package/build/types/utils/getFilteredRowModelSync.d.ts +0 -2
  139. package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
  140. package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
  141. package/src/utils/getCoreRowModelAsync.ts +0 -104
  142. package/src/utils/getFilteredRowModelAsync.ts +0 -49
  143. package/src/utils/getFilteredRowModelSync.ts +0 -150
  144. package/src/utils/getSortedRowModelAsync.ts +0 -200
@@ -1,150 +0,0 @@
1
- import { ColumnFilter, FilterFn } from '../features/Filters'
2
- import { TableInstance, RowModel, TableGenerics, Row } from '../types'
3
- import { memo } from '../utils'
4
- import { filterRows } from './filterRowsUtils'
5
-
6
- type ResolvedColumnFilter<TGenerics extends TableGenerics> = {
7
- id: string
8
- filterFn: FilterFn<TGenerics>
9
- resolvedFilterValue: unknown
10
- }
11
-
12
- export function getFilteredRowModelSync<TGenerics extends TableGenerics>(): (
13
- instance: TableInstance<TGenerics>
14
- ) => () => RowModel<TGenerics> {
15
- return instance =>
16
- memo(
17
- () => [
18
- instance.getPreFilteredRowModel(),
19
- instance.getState().columnFilters,
20
- instance.getState().globalFilter,
21
- ],
22
- (rowModel, columnFilters, globalFilter) => {
23
- const columnFilteredRowModel: RowModel<TGenerics> = (() => {
24
- if (
25
- !rowModel.rows.length ||
26
- (!columnFilters?.length && !globalFilter)
27
- ) {
28
- return rowModel
29
- }
30
-
31
- const resolvedColumnFilters: ResolvedColumnFilter<TGenerics>[] = []
32
- const resolvedGlobalFilters: ResolvedColumnFilter<TGenerics>[] = []
33
-
34
- ;(columnFilters ?? []).forEach(d => {
35
- const column = instance.getColumn(d.id)
36
-
37
- if (!column) {
38
- if (process.env.NODE_ENV !== 'production') {
39
- console.warn(
40
- `Table: Could not find a column to filter with columnId: ${d.id}`
41
- )
42
- }
43
- }
44
-
45
- const filterFn = instance.getColumnFilterFn(column.id)!
46
-
47
- if (!filterFn) {
48
- if (process.env.NODE_ENV !== 'production') {
49
- console.warn(
50
- `Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`
51
- )
52
- }
53
- return
54
- }
55
-
56
- resolvedColumnFilters.push({
57
- id: d.id,
58
- filterFn,
59
- resolvedFilterValue:
60
- filterFn.resolveFilterValue?.(d.value) ?? d.value,
61
- })
62
- })
63
-
64
- const filterableIds = columnFilters.map(d => d.id)
65
-
66
- const globalFilterFn = instance.getGlobalFilterFn()
67
-
68
- const globallyFilterableColumns = instance
69
- .getAllLeafColumns()
70
- .filter(column => column.getCanGlobalFilter())
71
-
72
- if (
73
- globalFilter &&
74
- globalFilterFn &&
75
- globallyFilterableColumns.length
76
- ) {
77
- filterableIds.push('__global__')
78
-
79
- globallyFilterableColumns.forEach(column => {
80
- resolvedGlobalFilters.push({
81
- id: column.id,
82
- filterFn: globalFilterFn,
83
- resolvedFilterValue:
84
- globalFilterFn.resolveFilterValue?.(globalFilter) ??
85
- globalFilter,
86
- })
87
- })
88
- }
89
-
90
- // Flag the prefiltered row model with each filter state
91
- for (let j = 0; j < rowModel.flatRows.length; j++) {
92
- const row = rowModel.flatRows[j]
93
-
94
- row.columnFilterMap = {}
95
-
96
- if (resolvedColumnFilters.length) {
97
- for (let i = 0; i < resolvedColumnFilters.length; i++) {
98
- const columnFilter = resolvedColumnFilters[i]
99
-
100
- // Tag the row with the column filter state
101
- row.columnFilterMap[columnFilter.id] = columnFilter.filterFn(
102
- row,
103
- columnFilter.id,
104
- columnFilter.resolvedFilterValue
105
- )
106
- }
107
- }
108
-
109
- if (resolvedGlobalFilters.length) {
110
- let hit = false
111
-
112
- for (let i = 0; i < resolvedGlobalFilters.length; i++) {
113
- const globalFilter = resolvedGlobalFilters[i]
114
- // Tag the row with the first truthy global filter state
115
- if (
116
- globalFilter.filterFn(
117
- row,
118
- globalFilter.id,
119
- globalFilter.resolvedFilterValue
120
- )
121
- ) {
122
- hit = true
123
- row.columnFilterMap.__global__ = true
124
- break
125
- }
126
- }
127
-
128
- if (row.columnFilterMap.__global__ !== true) {
129
- row.columnFilterMap.__global__ = false
130
- }
131
- }
132
- }
133
-
134
- // Filter final rows using all of the active filters
135
- return filterRows(rowModel.rows, filterableIds, instance)
136
- })()
137
-
138
- return columnFilteredRowModel
139
- },
140
- {
141
- key: process.env.NODE_ENV === 'production' && 'getFilteredRowModelSync',
142
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
143
- onChange: () => {
144
- instance.queue(() => {
145
- instance._autoResetPageIndex()
146
- })
147
- },
148
- }
149
- )
150
- }
@@ -1,200 +0,0 @@
1
- import { TableInstance, Row, RowModel, TableGenerics } from '../types'
2
- import { incrementalMemo, memo } from '../utils'
3
-
4
- export function getSortedRowModelSync<TGenerics extends TableGenerics>(opts?: {
5
- initialSync?: boolean
6
- }): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
7
- return instance =>
8
- incrementalMemo(
9
- () => [instance.getState().sorting, instance.getPreSortedRowModel()],
10
- (_sorting, rowModel): RowModel<TGenerics> => {
11
- return {
12
- rows: rowModel.rows.slice(),
13
- flatRows: [],
14
- rowsById: rowModel.rowsById,
15
- }
16
- },
17
- (sorting, rowModel) => rowModelRef => scheduleTask => {
18
- // TODO: Figure out how to do async sorting
19
- // We probably need to use a sorting algo that is "divide and
20
- // conquer", since that will probably distribute the easiest into
21
- // separate tasks. The trick will be batching those tasks in a way
22
- // that makes them fast. JS work loops don't tend to do well with
23
- // a high number of tasks that do one thing. Instead, shoot for each
24
- // task to have a few thousand opts (or whatever amount is generally
25
- // fast for most devices).
26
-
27
- throw new Error()
28
-
29
- // if (!rowModel.rows.length || !sorting?.length) {
30
- // rowModelRef.current = rowModel
31
- // return
32
- // }
33
-
34
- // const sortingState = instance.getState().sorting
35
-
36
- // const sortedFlatRows: Row<TGenerics>[] = []
37
-
38
- // // Filter out sortings that correspond to non existing columns
39
- // const availableSorting = sortingState.filter(sort =>
40
- // instance.getColumnCanSort(sort.id)
41
- // )
42
-
43
- // const sorters = availableSorting.map(columnSorting => {
44
- // const column = instance.getColumn(columnSorting.id)!
45
- // const sortingFn = instance.getColumnSortingFn(columnSorting.id)!
46
-
47
- // return {
48
- // id: columnSorting.id,
49
- // compare: (rowA: Row<TGenerics>, rowB: Row<TGenerics>) =>
50
- // sortingFn(rowA, rowB, columnSorting.id),
51
- // desc: columnSorting.desc,
52
- // invertSorting: column.invertSorting,
53
- // sortUndefined: column.sortUndefined,
54
- // }
55
- // })
56
-
57
- // const sortData = (rows: Row<TGenerics>[]) => {
58
- // // This will also perform a stable sorting using the row index
59
- // // if needed.
60
-
61
- // const sortedData = quicksort(rows, sorters)
62
-
63
- // // If there are sub-rows, sort them
64
- // sortedData.forEach(row => {
65
- // rowModelRef.current.flatRows.push(row)
66
- // if (!row.subRows || row.subRows.length <= 1) {
67
- // return
68
- // }
69
- // row.subRows = sortData(row.subRows)
70
- // })
71
-
72
- // return sortedData
73
- // }
74
-
75
- // sortData(rowModelRef.current.rows)
76
- },
77
- {
78
- key: process.env.NODE_ENV === 'production' && 'getSortedRowModel',
79
- initialSync: opts?.initialSync,
80
- onProgress: progress => {
81
- instance.setState(old => ({ ...old, sortingProgress: progress }))
82
- },
83
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
84
- onChange: () => {
85
- instance.queue(() => {
86
- instance._autoResetPageIndex()
87
- })
88
- },
89
- }
90
- )
91
- }
92
-
93
- type Sorter<TGenerics extends TableGenerics> = {
94
- id: string
95
- compare: (a: Row<TGenerics>, b: Row<TGenerics>) => number
96
- desc?: boolean
97
- sortUndefined?: false | -1 | 1
98
- invertSorting?: boolean
99
- }
100
-
101
- export function quicksort<TGenerics extends TableGenerics>(
102
- rows: Row<TGenerics>[],
103
- sorters: Sorter<TGenerics>[]
104
- ): Row<TGenerics>[] {
105
- if (!rows.length) {
106
- return rows
107
- }
108
-
109
- // Copy the rows so we can mutate the order
110
- rows = rows.slice()
111
-
112
- // Start the quicksort recursion
113
- recurse(0, rows.length - 1)
114
-
115
- // Return the rows
116
- return rows
117
-
118
- function recurse(start: number, end: number) {
119
- const pivotIndex = pivot(start, end)
120
-
121
- if (start < pivotIndex - 1) {
122
- recurse(start, pivotIndex - 1)
123
- }
124
-
125
- if (pivotIndex < end) {
126
- recurse(pivotIndex + 1, end)
127
- }
128
- }
129
-
130
- function pivot(start: number, end: number) {
131
- const pivotIndex = Math.floor((start + end) / 2)
132
- let i = start
133
- let j = end
134
-
135
- const compare = (a: number, b: number) => {
136
- const rowA = rows[a]
137
- const rowB = rows[b]
138
-
139
- for (let i = 0; i < sorters.length; i += 1) {
140
- const sorter = sorters[i]!
141
- const isDesc = sorter?.desc ?? false
142
-
143
- if (sorter.sortUndefined) {
144
- const aValue = rowA.values[sorter.id]
145
- const bValue = rowB.values[sorter.id]
146
-
147
- const aUndefined = typeof aValue === 'undefined'
148
- const bUndefined = typeof bValue === 'undefined'
149
-
150
- if (aUndefined || bUndefined) {
151
- if (aUndefined !== bUndefined) {
152
- return aUndefined ? sorter.sortUndefined : -sorter.sortUndefined
153
- }
154
- }
155
- }
156
-
157
- // This function should always return in ascending order
158
- let sortInt = sorter.compare(rowA, rowB)
159
-
160
- if (sortInt !== 0) {
161
- if (isDesc) {
162
- sortInt *= -1
163
- }
164
-
165
- if (sorter.invertSorting) {
166
- sortInt *= -1
167
- }
168
-
169
- return sortInt
170
- }
171
- }
172
-
173
- return rowA.index < rowB.index ? -1 : 1
174
- }
175
-
176
- while (i <= j) {
177
- while (compare(i, pivotIndex) < 0) {
178
- i++
179
- }
180
-
181
- while (compare(pivotIndex, j) < 0) {
182
- j--
183
- }
184
-
185
- if (i <= j) {
186
- swap(rows, i, j)
187
- i++
188
- j--
189
- }
190
- }
191
-
192
- return i
193
- }
194
-
195
- function swap<T>(arr: T[], a: number, b: number) {
196
- const t = arr[a]
197
- arr[a] = arr[b]
198
- arr[b] = t
199
- }
200
- }