@tanstack/react-table 8.0.0-alpha.6 → 8.0.0-alpha.9

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.js +66 -73
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +47 -33
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +23 -22
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +10 -22
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +27 -58
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +10 -27
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +108 -28
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/Ordering.js +2 -2
  16. package/build/cjs/features/Ordering.js.map +1 -1
  17. package/build/cjs/features/Pagination.js +24 -29
  18. package/build/cjs/features/Pagination.js.map +1 -1
  19. package/build/cjs/features/Pinning.js.map +1 -1
  20. package/build/cjs/features/RowSelection.js +23 -38
  21. package/build/cjs/features/RowSelection.js.map +1 -1
  22. package/build/cjs/features/Sorting.js +10 -22
  23. package/build/cjs/features/Sorting.js.map +1 -1
  24. package/build/cjs/features/Visibility.js +10 -2
  25. package/build/cjs/features/Visibility.js.map +1 -1
  26. package/build/cjs/filterTypes.js.map +1 -1
  27. package/build/cjs/index.js +12 -0
  28. package/build/cjs/index.js.map +1 -1
  29. package/build/cjs/sortTypes.js.map +1 -1
  30. package/build/cjs/types.js +22 -0
  31. package/build/cjs/types.js.map +1 -0
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  33. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  34. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  35. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  36. package/build/cjs/utils/paginateRowsFn.js.map +1 -1
  37. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  38. package/build/cjs/utils.js +44 -18
  39. package/build/cjs/utils.js.map +1 -1
  40. package/build/esm/index.js +1388 -1355
  41. package/build/esm/index.js.map +1 -1
  42. package/build/stats-html.html +1 -1
  43. package/build/stats-react.json +337 -307
  44. package/build/types/core.d.ts +63 -67
  45. package/build/types/createTable.d.ts +34 -44
  46. package/build/types/features/ColumnSizing.d.ts +13 -7
  47. package/build/types/features/Expanding.d.ts +11 -16
  48. package/build/types/features/Filters.d.ts +39 -47
  49. package/build/types/features/Grouping.d.ts +28 -27
  50. package/build/types/features/Headers.d.ts +30 -30
  51. package/build/types/features/Ordering.d.ts +5 -5
  52. package/build/types/features/Pagination.d.ts +11 -16
  53. package/build/types/features/Pinning.d.ts +5 -5
  54. package/build/types/features/RowSelection.d.ts +15 -23
  55. package/build/types/features/Sorting.d.ts +26 -25
  56. package/build/types/features/Visibility.d.ts +9 -9
  57. package/build/types/filterTypes.d.ts +10 -10
  58. package/build/types/index.d.ts +1 -0
  59. package/build/types/sortTypes.d.ts +7 -7
  60. package/build/types/types.d.ts +34 -23
  61. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  62. package/build/types/utils/expandRowsFn.d.ts +2 -2
  63. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  64. package/build/types/utils/groupRowsFn.d.ts +2 -2
  65. package/build/types/utils/paginateRowsFn.d.ts +2 -2
  66. package/build/types/utils/sortRowsFn.d.ts +2 -2
  67. package/build/types/utils.d.ts +5 -6
  68. package/build/umd/index.development.js +1397 -1354
  69. package/build/umd/index.development.js.map +1 -1
  70. package/build/umd/index.production.js +1 -1
  71. package/build/umd/index.production.js.map +1 -1
  72. package/package.json +1 -1
  73. package/src/core.tsx +192 -520
  74. package/src/createTable.tsx +137 -192
  75. package/src/features/ColumnSizing.ts +48 -77
  76. package/src/features/Expanding.ts +25 -113
  77. package/src/features/Filters.ts +91 -293
  78. package/src/features/Grouping.ts +60 -165
  79. package/src/features/Headers.ts +148 -331
  80. package/src/features/Ordering.ts +19 -42
  81. package/src/features/Pagination.ts +35 -110
  82. package/src/features/Pinning.ts +16 -40
  83. package/src/features/RowSelection.ts +47 -227
  84. package/src/features/Sorting.ts +49 -143
  85. package/src/features/Visibility.ts +23 -64
  86. package/src/filterTypes.ts +19 -82
  87. package/src/index.tsx +1 -0
  88. package/src/sortTypes.ts +19 -31
  89. package/src/types.ts +80 -100
  90. package/src/utils/columnFilterRowsFn.ts +11 -53
  91. package/src/utils/expandRowsFn.ts +7 -27
  92. package/src/utils/globalFilterRowsFn.ts +10 -43
  93. package/src/utils/groupRowsFn.ts +13 -37
  94. package/src/utils/paginateRowsFn.ts +5 -11
  95. package/src/utils/sortRowsFn.ts +8 -28
  96. package/src/utils.tsx +61 -35
@@ -1,25 +1,13 @@
1
- import { ReactTable, Row, RowModel } from '../types'
1
+ import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
2
2
  import { SortingFn } from '../features/Sorting'
3
3
 
4
- export function sortRowsFn<
5
- TData,
6
- TValue,
7
- TFilterFns,
8
- TSortingFns,
9
- TAggregationFns
10
- >(
11
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
12
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
13
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
4
+ export function sortRowsFn<TGenerics extends PartialGenerics>(
5
+ instance: TableInstance<TGenerics>,
6
+ rowModel: RowModel<TGenerics>
7
+ ): RowModel<TGenerics> {
14
8
  const sortingState = instance.getState().sorting
15
9
 
16
- const sortedFlatRows: Row<
17
- TData,
18
- TValue,
19
- TFilterFns,
20
- TSortingFns,
21
- TAggregationFns
22
- >[] = []
10
+ const sortedFlatRows: Row<TGenerics>[] = []
23
11
 
24
12
  // Filter out sortings that correspond to non existing columns
25
13
  const availableSorting = sortingState.filter(sort =>
@@ -31,13 +19,7 @@ export function sortRowsFn<
31
19
  {
32
20
  sortUndefined?: false | -1 | 1
33
21
  invertSorting?: boolean
34
- sortingFn: SortingFn<
35
- TData,
36
- TValue,
37
- TFilterFns,
38
- TSortingFns,
39
- TAggregationFns
40
- >
22
+ sortingFn: SortingFn<TGenerics>
41
23
  }
42
24
  > = {}
43
25
 
@@ -51,9 +33,7 @@ export function sortRowsFn<
51
33
  }
52
34
  })
53
35
 
54
- const sortData = (
55
- rows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
56
- ) => {
36
+ const sortData = (rows: Row<TGenerics>[]) => {
57
37
  // This will also perform a stable sorting using the row index
58
38
  // if needed.
59
39
  const sortedData = rows.slice()
package/src/utils.tsx CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  PropGetterValue,
6
6
  Renderable,
7
7
  TableState,
8
+ Updater,
8
9
  } from './types'
9
10
 
10
11
  export type IsAny<T> = 0 extends 1 & T ? true : false
@@ -13,18 +14,11 @@ export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
13
14
  Required<Pick<T, K>>
14
15
  export type Overwrite<T, U> = Omit<T, keyof U> & U
15
16
 
16
- export type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput
17
+ export type DataUpdateFunction<T> = (input: T) => T
17
18
 
18
- export type Updater<TInput, TOutput> =
19
- | TOutput
20
- | DataUpdateFunction<TInput, TOutput>
21
-
22
- export function functionalUpdate<TInput, TOutput = TInput>(
23
- updater: Updater<TInput, TOutput>,
24
- input: TInput
25
- ): TOutput {
19
+ export function functionalUpdate<T>(updater: Updater<T>, input: T): T {
26
20
  return typeof updater === 'function'
27
- ? (updater as DataUpdateFunction<TInput, TOutput>)(input)
21
+ ? (updater as DataUpdateFunction<T>)(input)
28
22
  : updater
29
23
  }
30
24
 
@@ -33,7 +27,7 @@ export function noop() {
33
27
  }
34
28
 
35
29
  export function makeStateUpdater(key: keyof TableState, instance: unknown) {
36
- return (updater: Updater<any, any>) => {
30
+ return (updater: Updater<any>) => {
37
31
  ;(instance as any).setState(<TTableState,>(old: TTableState) => {
38
32
  return {
39
33
  ...old,
@@ -92,7 +86,7 @@ export function memo<TDeps extends readonly any[], TResult>(
92
86
  fn: (...args: NoInfer<[...TDeps]>) => TResult,
93
87
  opts: {
94
88
  key: string
95
- debug?: boolean
89
+ debug?: () => any
96
90
  onChange?: (result: TResult, previousResult?: TResult) => void
97
91
  }
98
92
  ): () => TResult {
@@ -100,6 +94,9 @@ export function memo<TDeps extends readonly any[], TResult>(
100
94
  let result: TResult | undefined
101
95
 
102
96
  return () => {
97
+ let depTime: number
98
+ if (opts.key && opts.debug) depTime = performance.now()
99
+
103
100
  const newDeps = getDeps()
104
101
 
105
102
  const depsChanged =
@@ -107,34 +104,63 @@ export function memo<TDeps extends readonly any[], TResult>(
107
104
  newDeps.some((dep: any, index: number) => deps[index] !== dep)
108
105
 
109
106
  if (depsChanged) {
110
- if (opts?.debug) {
111
- console.info(opts?.key, {
112
- length: `${deps.length} -> ${newDeps.length}`,
113
- ...newDeps
114
- .map((_, index) => {
115
- if (deps[index] !== newDeps[index]) {
116
- return [index, deps[index], newDeps[index]]
117
- }
118
-
119
- return false
120
- })
121
- .filter(Boolean)
122
- .reduce(
123
- (accu, curr: any) => ({
124
- ...accu,
125
- [curr[0]]: curr.slice(1),
126
- }),
127
- {}
128
- ),
129
- parent,
130
- })
131
- }
132
-
133
107
  let oldResult = result
108
+ let resultTime: number
109
+ if (opts.key && opts.debug) resultTime = performance.now()
134
110
  result = fn(...newDeps)
135
111
  deps = newDeps
136
112
  opts?.onChange?.(result, oldResult)
137
113
 
114
+ if (opts.key && opts.debug) {
115
+ if (opts?.debug()) {
116
+ const depEndTime =
117
+ Math.round((performance.now() - depTime!) * 100) / 100
118
+ const resultEndTime =
119
+ Math.round((performance.now() - resultTime!) * 100) / 100
120
+ const resultFpsPercentage = resultEndTime / 16
121
+
122
+ const pad = (str: number | string, num: number) => {
123
+ str = String(str)
124
+ while (str.length < num) {
125
+ str = ' ' + str
126
+ }
127
+ return str
128
+ }
129
+
130
+ console.info(
131
+ `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,
132
+ `
133
+ font-size: .6rem;
134
+ font-weight: bold;
135
+ color: hsl(${Math.max(
136
+ 0,
137
+ Math.min(120 - 120 * resultFpsPercentage, 120)
138
+ )}deg 100% 31%);`,
139
+ opts?.key,
140
+ {
141
+ length: `${deps.length} -> ${newDeps.length}`,
142
+ ...newDeps
143
+ .map((_, index) => {
144
+ if (deps[index] !== newDeps[index]) {
145
+ return [index, deps[index], newDeps[index]]
146
+ }
147
+
148
+ return false
149
+ })
150
+ .filter(Boolean)
151
+ .reduce(
152
+ (accu, [a, b]: any) => ({
153
+ ...accu,
154
+ [a]: b,
155
+ }),
156
+ {}
157
+ ),
158
+ parent,
159
+ }
160
+ )
161
+ }
162
+ }
163
+
138
164
  oldResult = undefined
139
165
  }
140
166