@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.0

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 (186) hide show
  1. package/build/cjs/aggregationFns.js +120 -0
  2. package/build/cjs/aggregationFns.js.map +1 -0
  3. package/build/cjs/core/cell.js +40 -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/core/headers.js +403 -0
  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/createTable.js +36 -29
  14. package/build/cjs/createTable.js.map +1 -1
  15. package/build/cjs/features/ColumnSizing.js +157 -189
  16. package/build/cjs/features/ColumnSizing.js.map +1 -1
  17. package/build/cjs/features/Expanding.js +103 -155
  18. package/build/cjs/features/Expanding.js.map +1 -1
  19. package/build/cjs/features/Filters.js +155 -304
  20. package/build/cjs/features/Filters.js.map +1 -1
  21. package/build/cjs/features/Grouping.js +97 -157
  22. package/build/cjs/features/Grouping.js.map +1 -1
  23. package/build/cjs/features/Ordering.js +30 -41
  24. package/build/cjs/features/Ordering.js.map +1 -1
  25. package/build/cjs/features/Pagination.js +102 -105
  26. package/build/cjs/features/Pagination.js.map +1 -1
  27. package/build/cjs/features/Pinning.js +131 -89
  28. package/build/cjs/features/Pinning.js.map +1 -1
  29. package/build/cjs/features/RowSelection.js +138 -267
  30. package/build/cjs/features/RowSelection.js.map +1 -1
  31. package/build/cjs/features/Sorting.js +82 -167
  32. package/build/cjs/features/Sorting.js.map +1 -1
  33. package/build/cjs/features/Visibility.js +69 -115
  34. package/build/cjs/features/Visibility.js.map +1 -1
  35. package/build/cjs/filterFns.js +107 -0
  36. package/build/cjs/filterFns.js.map +1 -0
  37. package/build/cjs/index.js +36 -23
  38. package/build/cjs/index.js.map +1 -1
  39. package/build/cjs/sortingFns.js +124 -0
  40. package/build/cjs/sortingFns.js.map +1 -0
  41. package/build/cjs/utils/filterRowsUtils.js +117 -0
  42. package/build/cjs/utils/filterRowsUtils.js.map +1 -0
  43. package/build/cjs/utils/getCoreRowModel.js +79 -0
  44. package/build/cjs/utils/getCoreRowModel.js.map +1 -0
  45. package/build/cjs/utils/getExpandedRowModel.js +57 -0
  46. package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
  47. package/build/cjs/utils/getFacetedMinMaxValues.js +54 -0
  48. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
  49. package/build/cjs/utils/getFacetedRowModel.js +50 -0
  50. package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
  51. package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
  52. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
  53. package/build/cjs/utils/getFilteredRowModel.js +139 -0
  54. package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
  55. package/build/cjs/utils/getGroupedRowModel.js +161 -0
  56. package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
  57. package/build/cjs/utils/getPaginationRowModel.js +61 -0
  58. package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
  59. package/build/cjs/utils/getSortedRowModel.js +110 -0
  60. package/build/cjs/utils/getSortedRowModel.js.map +1 -0
  61. package/build/cjs/utils.js +38 -107
  62. package/build/cjs/utils.js.map +1 -1
  63. package/build/esm/index.js +2976 -3853
  64. package/build/esm/index.js.map +1 -1
  65. package/build/stats-html.html +1 -1
  66. package/build/stats-react.json +586 -408
  67. package/build/types/aggregationFns.d.ts +13 -0
  68. package/build/types/core/cell.d.ts +9 -0
  69. package/build/types/core/column.d.ts +40 -0
  70. package/build/types/core/headers.d.ts +46 -0
  71. package/build/types/core/instance.d.ts +57 -0
  72. package/build/types/core/row.d.ts +15 -0
  73. package/build/types/createTable.d.ts +47 -26
  74. package/build/types/features/ColumnSizing.d.ts +32 -44
  75. package/build/types/features/Expanding.d.ts +15 -26
  76. package/build/types/features/Filters.d.ts +64 -63
  77. package/build/types/features/Grouping.d.ts +32 -46
  78. package/build/types/features/Ordering.d.ts +7 -10
  79. package/build/types/features/Pagination.d.ts +16 -15
  80. package/build/types/features/Pinning.d.ts +16 -17
  81. package/build/types/features/RowSelection.d.ts +13 -33
  82. package/build/types/features/Sorting.d.ts +25 -44
  83. package/build/types/features/Visibility.d.ts +16 -25
  84. package/build/types/filterFns.d.ts +13 -0
  85. package/build/types/index.d.ts +16 -10
  86. package/build/types/sortingFns.d.ts +11 -0
  87. package/build/types/types.d.ts +37 -122
  88. package/build/types/utils/filterRowsUtils.d.ts +4 -0
  89. package/build/types/utils/getCoreRowModel.d.ts +2 -0
  90. package/build/types/utils/getExpandedRowModel.d.ts +7 -0
  91. package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
  92. package/build/types/utils/getFacetedRowModel.d.ts +2 -0
  93. package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
  94. package/build/types/utils/getFilteredRowModel.d.ts +2 -0
  95. package/build/types/utils/getGroupedRowModel.d.ts +2 -0
  96. package/build/types/utils/getPaginationRowModel.d.ts +4 -0
  97. package/build/types/utils/getSortedRowModel.d.ts +2 -0
  98. package/build/types/utils.d.ts +7 -11
  99. package/build/umd/index.development.js +3024 -3893
  100. package/build/umd/index.development.js.map +1 -1
  101. package/build/umd/index.production.js +1 -1
  102. package/build/umd/index.production.js.map +1 -1
  103. package/package.json +9 -10
  104. package/src/.DS_Store +0 -0
  105. package/src/aggregationFns.ts +123 -0
  106. package/src/core/cell.ts +48 -0
  107. package/src/core/column.ts +147 -0
  108. package/src/core/headers.ts +575 -0
  109. package/src/core/instance.ts +361 -0
  110. package/src/core/row.ts +85 -0
  111. package/src/createTable.ts +188 -0
  112. package/src/features/ColumnSizing.ts +170 -185
  113. package/src/features/Expanding.ts +122 -194
  114. package/src/features/Filters.ts +301 -381
  115. package/src/features/Grouping.ts +160 -220
  116. package/src/features/Ordering.ts +24 -25
  117. package/src/features/Pagination.ts +90 -73
  118. package/src/features/Pinning.ts +186 -63
  119. package/src/features/RowSelection.ts +107 -245
  120. package/src/features/Sorting.ts +127 -225
  121. package/src/features/Visibility.ts +116 -132
  122. package/src/filterFns.ts +135 -0
  123. package/src/index.ts +29 -0
  124. package/src/{sortTypes.ts → sortingFns.ts} +63 -85
  125. package/src/types.ts +62 -168
  126. package/src/utils/filterRowsUtils.ts +112 -0
  127. package/src/utils/getCoreRowModel.ts +84 -0
  128. package/src/utils/getExpandedRowModel.ts +54 -0
  129. package/src/utils/getFacetedMinMaxValues.ts +40 -0
  130. package/src/utils/getFacetedRowModel.ts +50 -0
  131. package/src/utils/getFacetedUniqueValues.ts +37 -0
  132. package/src/utils/getFilteredRowModel.ts +159 -0
  133. package/src/utils/getGroupedRowModel.ts +175 -0
  134. package/src/utils/getPaginationRowModel.ts +48 -0
  135. package/src/utils/getSortedRowModel.ts +116 -0
  136. package/src/utils.ts +126 -0
  137. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
  138. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  139. package/build/cjs/aggregationTypes.js +0 -130
  140. package/build/cjs/aggregationTypes.js.map +0 -1
  141. package/build/cjs/core.js +0 -545
  142. package/build/cjs/core.js.map +0 -1
  143. package/build/cjs/features/Headers.js +0 -630
  144. package/build/cjs/features/Headers.js.map +0 -1
  145. package/build/cjs/filterTypes.js +0 -172
  146. package/build/cjs/filterTypes.js.map +0 -1
  147. package/build/cjs/sortTypes.js +0 -122
  148. package/build/cjs/sortTypes.js.map +0 -1
  149. package/build/cjs/types.js +0 -22
  150. package/build/cjs/types.js.map +0 -1
  151. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  152. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  153. package/build/cjs/utils/expandRowsFn.js +0 -38
  154. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  155. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  156. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  157. package/build/cjs/utils/groupRowsFn.js +0 -155
  158. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  159. package/build/cjs/utils/paginateRowsFn.js +0 -44
  160. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  161. package/build/cjs/utils/sortRowsFn.js +0 -94
  162. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  163. package/build/types/aggregationTypes.d.ts +0 -22
  164. package/build/types/core.d.ts +0 -105
  165. package/build/types/features/Headers.d.ts +0 -43
  166. package/build/types/filterTypes.d.ts +0 -50
  167. package/build/types/sortTypes.d.ts +0 -18
  168. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  169. package/build/types/utils/expandRowsFn.d.ts +0 -2
  170. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  171. package/build/types/utils/groupRowsFn.d.ts +0 -2
  172. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  173. package/build/types/utils/sortRowsFn.d.ts +0 -2
  174. package/src/aggregationTypes.ts +0 -115
  175. package/src/core.tsx +0 -763
  176. package/src/createTable.tsx +0 -137
  177. package/src/features/Headers.ts +0 -747
  178. package/src/filterTypes.ts +0 -188
  179. package/src/index.tsx +0 -23
  180. package/src/utils/columnFilterRowsFn.ts +0 -113
  181. package/src/utils/expandRowsFn.ts +0 -30
  182. package/src/utils/globalFilterRowsFn.ts +0 -89
  183. package/src/utils/groupRowsFn.ts +0 -170
  184. package/src/utils/paginateRowsFn.ts +0 -28
  185. package/src/utils/sortRowsFn.ts +0 -95
  186. package/src/utils.tsx +0 -221
@@ -1,95 +0,0 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
2
- import { SortingFn } from '../features/Sorting'
3
-
4
- export function sortRowsFn<TGenerics extends PartialGenerics>(
5
- instance: TableInstance<TGenerics>,
6
- rowModel: RowModel<TGenerics>
7
- ): RowModel<TGenerics> {
8
- const sortingState = instance.getState().sorting
9
-
10
- const sortedFlatRows: Row<TGenerics>[] = []
11
-
12
- // Filter out sortings that correspond to non existing columns
13
- const availableSorting = sortingState.filter(sort =>
14
- instance.getColumnCanSort(sort.id)
15
- )
16
-
17
- const columnInfoById: Record<
18
- string,
19
- {
20
- sortUndefined?: false | -1 | 1
21
- invertSorting?: boolean
22
- sortingFn: SortingFn<TGenerics>
23
- }
24
- > = {}
25
-
26
- availableSorting.forEach(sortEntry => {
27
- const column = instance.getColumn(sortEntry.id)!
28
-
29
- columnInfoById[sortEntry.id] = {
30
- sortUndefined: column.sortUndefined,
31
- invertSorting: column.invertSorting,
32
- sortingFn: instance.getColumnSortingFn(sortEntry.id)!,
33
- }
34
- })
35
-
36
- const sortData = (rows: Row<TGenerics>[]) => {
37
- // This will also perform a stable sorting using the row index
38
- // if needed.
39
- const sortedData = rows.slice()
40
-
41
- sortedData.sort((rowA, rowB) => {
42
- for (let i = 0; i < availableSorting.length; i += 1) {
43
- const sortEntry = availableSorting[i]!
44
- const columnInfo = columnInfoById[sortEntry.id]!
45
- const isDesc = sortEntry?.desc ?? false
46
-
47
- if (columnInfo.sortUndefined) {
48
- const aValue = rowA.values[sortEntry.id]
49
- const bValue = rowB.values[sortEntry.id]
50
-
51
- const aUndefined = typeof aValue === 'undefined'
52
- const bUndefined = typeof bValue === 'undefined'
53
-
54
- if (aUndefined || bUndefined) {
55
- return aUndefined && bUndefined ? 0 : aUndefined ? 1 : -1
56
- }
57
- }
58
-
59
- // This function should always return in ascending order
60
- let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
61
-
62
- if (sortInt !== 0) {
63
- if (isDesc) {
64
- sortInt *= -1
65
- }
66
-
67
- if (columnInfo.invertSorting) {
68
- sortInt *= -1
69
- }
70
-
71
- return sortInt
72
- }
73
- }
74
-
75
- return rowA.index - rowB.index
76
- })
77
-
78
- // If there are sub-rows, sort them
79
- sortedData.forEach(row => {
80
- sortedFlatRows.push(row)
81
- if (!row.subRows || row.subRows.length <= 1) {
82
- return
83
- }
84
- row.subRows = sortData(row.subRows)
85
- })
86
-
87
- return sortedData
88
- }
89
-
90
- return {
91
- rows: sortData(rowModel.rows),
92
- flatRows: sortedFlatRows,
93
- rowsById: rowModel.rowsById,
94
- }
95
- }
package/src/utils.tsx DELETED
@@ -1,221 +0,0 @@
1
- import React from 'react'
2
- import {
3
- Getter,
4
- NoInfer,
5
- PropGetterValue,
6
- Renderable,
7
- TableState,
8
- Updater,
9
- } from './types'
10
-
11
- export type IsAny<T> = 0 extends 1 & T ? true : false
12
- export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
13
- export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
14
- Required<Pick<T, K>>
15
- export type Overwrite<T, U> = Omit<T, keyof U> & U
16
-
17
- export type DataUpdateFunction<T> = (input: T) => T
18
-
19
- export function functionalUpdate<T>(updater: Updater<T>, input: T): T {
20
- return typeof updater === 'function'
21
- ? (updater as DataUpdateFunction<T>)(input)
22
- : updater
23
- }
24
-
25
- export function noop() {
26
- //
27
- }
28
-
29
- export function makeStateUpdater(key: keyof TableState, instance: unknown) {
30
- return (updater: Updater<any>) => {
31
- ;(instance as any).setState(<TTableState,>(old: TTableState) => {
32
- return {
33
- ...old,
34
- [key]: functionalUpdate(updater, (old as any)[key]),
35
- }
36
- })
37
- }
38
- }
39
-
40
- type AnyFunction = (...args: any) => any
41
-
42
- export function isFunction<T extends AnyFunction>(d: any): d is T {
43
- return d instanceof Function
44
- }
45
-
46
- export function flattenBy<TNode>(
47
- arr: TNode[],
48
- getChildren: (item: TNode) => TNode[]
49
- ) {
50
- const flat: TNode[] = []
51
-
52
- const recurse = (subArr: TNode[]) => {
53
- subArr.forEach(item => {
54
- flat.push(item)
55
- const children = getChildren(item)
56
- if (children?.length) {
57
- recurse(children)
58
- }
59
- })
60
- }
61
-
62
- recurse(arr)
63
-
64
- return flat
65
- }
66
-
67
- type PropGetterImpl = <TBaseProps, TGetter extends Getter<TBaseProps>>(
68
- initial: TBaseProps,
69
- userProps?: TGetter
70
- ) => PropGetterValue<TBaseProps, TGetter>
71
-
72
- // @ts-ignore // Just rely on the type, not the implementation
73
- export const propGetter: PropGetterImpl = (initial, getter) => {
74
- if (isFunction(getter)) {
75
- return getter(initial)
76
- }
77
-
78
- return {
79
- ...initial,
80
- ...(getter ?? {}),
81
- }
82
- }
83
-
84
- export function memo<TDeps extends readonly any[], TResult>(
85
- getDeps: () => [...TDeps],
86
- fn: (...args: NoInfer<[...TDeps]>) => TResult,
87
- opts: {
88
- key: string
89
- debug?: () => any
90
- onChange?: (result: TResult, previousResult?: TResult) => void
91
- }
92
- ): () => TResult {
93
- let deps: any[] = []
94
- let result: TResult | undefined
95
-
96
- return () => {
97
- let depTime: number
98
- if (opts.key && opts.debug) depTime = performance.now()
99
-
100
- const newDeps = getDeps()
101
-
102
- const depsChanged =
103
- newDeps.length !== deps.length ||
104
- newDeps.some((dep: any, index: number) => deps[index] !== dep)
105
-
106
- if (depsChanged) {
107
- let oldResult = result
108
- let resultTime: number
109
- if (opts.key && opts.debug) resultTime = performance.now()
110
- result = fn(...newDeps)
111
- deps = newDeps
112
- opts?.onChange?.(result, oldResult)
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
-
164
- oldResult = undefined
165
- }
166
-
167
- return result!
168
- }
169
- }
170
-
171
- export type Render = typeof flexRender
172
-
173
- export function flexRender<TProps extends {}>(
174
- Comp: Renderable<TProps>,
175
- props: TProps
176
- ): React.ReactNode {
177
- return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
178
- }
179
-
180
- function isReactComponent(component: unknown): component is React.FC {
181
- return (
182
- isClassComponent(component) ||
183
- typeof component === 'function' ||
184
- isExoticComponent(component)
185
- )
186
- }
187
-
188
- function isClassComponent(component: any) {
189
- return (
190
- typeof component === 'function' &&
191
- (() => {
192
- const proto = Object.getPrototypeOf(component)
193
- return proto.prototype && proto.prototype.isReactComponent
194
- })()
195
- )
196
- }
197
-
198
- function isExoticComponent(component: any) {
199
- return (
200
- typeof component === 'object' &&
201
- typeof component.$$typeof === 'symbol' &&
202
- ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
203
- )
204
- }
205
-
206
- // export function hashString(str: string, seed = 0): string {
207
- // let h1 = 0xdeadbeef ^ seed,
208
- // h2 = 0x41c6ce57 ^ seed
209
- // for (let i = 0, ch; i < str.length; i++) {
210
- // ch = str.charCodeAt(i)
211
- // h1 = Math.imul(h1 ^ ch, 2654435761)
212
- // h2 = Math.imul(h2 ^ ch, 1597334677)
213
- // }
214
- // h1 =
215
- // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
216
- // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
217
- // h2 =
218
- // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
219
- // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
220
- // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
221
- // }