@tanstack/react-table 8.0.0-alpha.1 → 8.0.0-alpha.16

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/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +96 -12
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +40 -3330
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -632
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +50 -3332
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +105 -7
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -493
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -103
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/Expanding.js +0 -234
  23. package/build/cjs/features/Expanding.js.map +0 -1
  24. package/build/cjs/features/Filters.js +0 -396
  25. package/build/cjs/features/Filters.js.map +0 -1
  26. package/build/cjs/features/Grouping.js +0 -228
  27. package/build/cjs/features/Grouping.js.map +0 -1
  28. package/build/cjs/features/Headers.js +0 -483
  29. package/build/cjs/features/Headers.js.map +0 -1
  30. package/build/cjs/features/Ordering.js +0 -83
  31. package/build/cjs/features/Ordering.js.map +0 -1
  32. package/build/cjs/features/Pinning.js +0 -163
  33. package/build/cjs/features/Pinning.js.map +0 -1
  34. package/build/cjs/features/Sorting.js +0 -269
  35. package/build/cjs/features/Sorting.js.map +0 -1
  36. package/build/cjs/features/Visibility.js +0 -160
  37. package/build/cjs/features/Visibility.js.map +0 -1
  38. package/build/cjs/filterTypes.js +0 -172
  39. package/build/cjs/filterTypes.js.map +0 -1
  40. package/build/cjs/sortTypes.js +0 -121
  41. package/build/cjs/sortTypes.js.map +0 -1
  42. package/build/cjs/utils/columnFilterRowsFn.js +0 -130
  43. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  44. package/build/cjs/utils/expandRowsFn.js +0 -38
  45. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  46. package/build/cjs/utils/globalFilterRowsFn.js +0 -100
  47. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  48. package/build/cjs/utils/groupRowsFn.js +0 -154
  49. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  50. package/build/cjs/utils/sortRowsFn.js +0 -93
  51. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  52. package/build/cjs/utils.js +0 -143
  53. package/build/cjs/utils.js.map +0 -1
  54. package/build/types/aggregationTypes.d.ts +0 -22
  55. package/build/types/core.d.ts +0 -122
  56. package/build/types/createTable.d.ts +0 -35
  57. package/build/types/features/Expanding.d.ts +0 -52
  58. package/build/types/features/Filters.d.ts +0 -93
  59. package/build/types/features/Grouping.d.ts +0 -82
  60. package/build/types/features/Headers.d.ts +0 -41
  61. package/build/types/features/Ordering.d.ts +0 -19
  62. package/build/types/features/Pinning.d.ts +0 -39
  63. package/build/types/features/Sorting.d.ts +0 -75
  64. package/build/types/features/Visibility.d.ts +0 -47
  65. package/build/types/filterTypes.d.ts +0 -50
  66. package/build/types/sortTypes.d.ts +0 -17
  67. package/build/types/types.d.ts +0 -122
  68. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  69. package/build/types/utils/expandRowsFn.d.ts +0 -2
  70. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  71. package/build/types/utils/groupRowsFn.d.ts +0 -2
  72. package/build/types/utils/sortRowsFn.d.ts +0 -2
  73. package/build/types/utils.d.ts +0 -24
  74. package/src/aggregationTypes.ts +0 -115
  75. package/src/core.tsx +0 -1194
  76. package/src/createTable.tsx +0 -181
  77. package/src/features/Expanding.ts +0 -388
  78. package/src/features/Filters.ts +0 -707
  79. package/src/features/Grouping.ts +0 -451
  80. package/src/features/Headers.ts +0 -907
  81. package/src/features/Ordering.ts +0 -134
  82. package/src/features/Pinning.ts +0 -213
  83. package/src/features/Sorting.ts +0 -487
  84. package/src/features/Visibility.ts +0 -281
  85. package/src/features/withColumnResizing.oldts +0 -281
  86. package/src/features/withPagination.oldts +0 -208
  87. package/src/features/withRowSelection.oldts +0 -467
  88. package/src/filterTypes.ts +0 -251
  89. package/src/sortTypes.ts +0 -159
  90. package/src/types.ts +0 -285
  91. package/src/utils/columnFilterRowsFn.ts +0 -162
  92. package/src/utils/expandRowsFn.ts +0 -53
  93. package/src/utils/globalFilterRowsFn.ts +0 -129
  94. package/src/utils/groupRowsFn.ts +0 -196
  95. package/src/utils/sortRowsFn.ts +0 -115
  96. package/src/utils.tsx +0 -243
package/src/utils.tsx DELETED
@@ -1,243 +0,0 @@
1
- import React from 'react'
2
- import { Getter, NoInfer, PropGetterValue, Renderable } from './types'
3
-
4
- export type IsAny<T> = 0 extends 1 & T ? true : false
5
- export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
6
- export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
7
- Required<Pick<T, K>>
8
- export type Overwrite<T, U> = Omit<T, keyof U> & U
9
-
10
- export type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput
11
-
12
- export type Updater<TInput, TOutput> =
13
- | TOutput
14
- | DataUpdateFunction<TInput, TOutput>
15
-
16
- export function functionalUpdate<TInput, TOutput = TInput>(
17
- updater: Updater<TInput, TOutput>,
18
- input: TInput
19
- ): TOutput {
20
- return typeof updater === 'function'
21
- ? (updater as DataUpdateFunction<TInput, TOutput>)(input)
22
- : updater
23
- }
24
-
25
- export function noop() {
26
- //
27
- }
28
-
29
- export function makeStateUpdater(key: string, instance: unknown) {
30
- return (updater: Updater<any, 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
- // SSR has issues with useLayoutEffect still, so use useEffect during SSR
41
- export const safeUseLayoutEffect =
42
- typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
43
-
44
- export function useMountedLayoutEffect(fn: any, deps: any[]) {
45
- const mountedRef = React.useRef(false)
46
-
47
- safeUseLayoutEffect(() => {
48
- if (mountedRef.current) {
49
- fn()
50
- }
51
- mountedRef.current = true
52
- // eslint-disable-next-line
53
- }, deps)
54
- }
55
-
56
- export function useGetLatest<T>(obj: T): () => T {
57
- const ref = React.useRef<T>()
58
- ref.current = obj
59
-
60
- return React.useCallback(() => ref.current!, [])
61
- }
62
-
63
- type AnyFunction = (...args: any) => any
64
-
65
- export function isFunction<T extends AnyFunction>(d: any): d is T {
66
- return d instanceof Function
67
- }
68
-
69
- export function flattenBy<TNode>(
70
- arr: TNode[],
71
- getChildren: (item: TNode) => TNode[]
72
- ) {
73
- const flat: TNode[] = []
74
-
75
- const recurse = (subArr: TNode[]) => {
76
- subArr.forEach(item => {
77
- flat.push(item)
78
- const children = getChildren(item)
79
- if (children?.length) {
80
- recurse(children)
81
- }
82
- })
83
- }
84
-
85
- recurse(arr)
86
-
87
- return flat
88
- }
89
-
90
- type PropGetterImpl = <TBaseProps, TGetter extends Getter<TBaseProps>>(
91
- initial: TBaseProps,
92
- userProps?: TGetter
93
- ) => PropGetterValue<TBaseProps, TGetter>
94
-
95
- // @ts-ignore // Just rely on the type, not the implementation
96
- export const propGetter: PropGetterImpl = (initial, getter) => {
97
- if (isFunction(getter)) {
98
- return getter(initial)
99
- }
100
-
101
- return {
102
- ...initial,
103
- ...(getter ?? {}),
104
- }
105
- }
106
-
107
- export function memo<TDeps extends readonly any[], TResult>(
108
- getDeps: () => [...TDeps],
109
- fn: (...args: NoInfer<[...TDeps]>) => TResult,
110
- key?: string,
111
- debug?: boolean
112
- ): () => TResult {
113
- let deps: any[] = []
114
- let result: TResult | undefined
115
-
116
- return () => {
117
- const newDeps = getDeps()
118
- const newSerializedDeps = newDeps
119
- const oldSerializedDeps = deps
120
-
121
- const depsChanged =
122
- newSerializedDeps.length !== oldSerializedDeps.length ||
123
- newSerializedDeps.some(
124
- (dep: any, index: number) => oldSerializedDeps[index] !== dep
125
- )
126
-
127
- if (depsChanged) {
128
- if (debug) {
129
- console.info(key, {
130
- length: `${oldSerializedDeps.length} -> ${newSerializedDeps.length}`,
131
- ...newSerializedDeps
132
- .map((_, index) => {
133
- if (oldSerializedDeps[index] !== newSerializedDeps[index]) {
134
- return [
135
- index,
136
- oldSerializedDeps[index],
137
- newSerializedDeps[index],
138
- ]
139
- }
140
-
141
- return false
142
- })
143
- .filter(Boolean)
144
- .reduce(
145
- (accu, curr: any) => ({
146
- ...accu,
147
- [curr[0]]: curr.slice(1),
148
- }),
149
- {}
150
- ),
151
- parent,
152
- })
153
- }
154
- result = fn(...newDeps)
155
- deps = newSerializedDeps
156
- }
157
-
158
- return result!
159
- }
160
- }
161
-
162
- // Copied from: https://github.com/jonschlinkert/is-plain-object
163
- export function isPlainObject(o: any): o is Object {
164
- if (!hasObjectPrototype(o)) {
165
- return false
166
- }
167
-
168
- // If has modified constructor
169
- const ctor = o.constructor
170
- if (typeof ctor === 'undefined') {
171
- return true
172
- }
173
-
174
- // If has modified prototype
175
- const prot = ctor.prototype
176
- if (!hasObjectPrototype(prot)) {
177
- return false
178
- }
179
-
180
- // If constructor does not have an Object-specific method
181
- if (!prot.hasOwnProperty('isPrototypeOf')) {
182
- return false
183
- }
184
-
185
- // Most likely a plain Object
186
- return true
187
- }
188
-
189
- function hasObjectPrototype(o: any): boolean {
190
- return Object.prototype.toString.call(o) === '[object Object]'
191
- }
192
-
193
- export type Render = typeof flexRender
194
-
195
- export function flexRender<TProps extends {}>(
196
- Comp: Renderable<TProps>,
197
- props: TProps
198
- ): React.ReactNode {
199
- return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
200
- }
201
-
202
- function isReactComponent(component: unknown): component is React.FC {
203
- return (
204
- isClassComponent(component) ||
205
- typeof component === 'function' ||
206
- isExoticComponent(component)
207
- )
208
- }
209
-
210
- function isClassComponent(component: any) {
211
- return (
212
- typeof component === 'function' &&
213
- (() => {
214
- const proto = Object.getPrototypeOf(component)
215
- return proto.prototype && proto.prototype.isReactComponent
216
- })()
217
- )
218
- }
219
-
220
- function isExoticComponent(component: any) {
221
- return (
222
- typeof component === 'object' &&
223
- typeof component.$$typeof === 'symbol' &&
224
- ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
225
- )
226
- }
227
-
228
- // export function hashString(str: string, seed = 0): string {
229
- // let h1 = 0xdeadbeef ^ seed,
230
- // h2 = 0x41c6ce57 ^ seed
231
- // for (let i = 0, ch; i < str.length; i++) {
232
- // ch = str.charCodeAt(i)
233
- // h1 = Math.imul(h1 ^ ch, 2654435761)
234
- // h2 = Math.imul(h2 ^ ch, 1597334677)
235
- // }
236
- // h1 =
237
- // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
238
- // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
239
- // h2 =
240
- // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
241
- // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
242
- // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
243
- // }