@tanstack/react-table 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.
- package/build/cjs/react-table/src/index.js +139 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3867 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3196 -4117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -813
- package/build/types/index.d.ts +16 -9
- package/build/umd/index.development.js +3234 -4125
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -6
- package/src/index.tsx +111 -9
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -122
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -318
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -239
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -414
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -232
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -629
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -193
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -526
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -315
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -174
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -44
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/cjs/utils.js +0 -167
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/createTable.d.ts +0 -42
- package/build/types/features/ColumnSizing.d.ts +0 -73
- package/build/types/features/Expanding.d.ts +0 -48
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -83
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -39
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -58
- package/build/types/features/Sorting.d.ts +0 -79
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -138
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/build/types/utils.d.ts +0 -23
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -186
- package/src/features/ColumnSizing.ts +0 -424
- package/src/features/Expanding.ts +0 -318
- package/src/features/Filters.ts +0 -560
- package/src/features/Grouping.ts +0 -361
- package/src/features/Headers.ts +0 -729
- package/src/features/Ordering.ts +0 -110
- package/src/features/Pagination.ts +0 -250
- package/src/features/Pinning.ts +0 -174
- package/src/features/RowSelection.ts +0 -651
- package/src/features/Sorting.ts +0 -453
- package/src/features/Visibility.ts +0 -238
- package/src/filterTypes.ts +0 -188
- package/src/sortTypes.ts +0 -147
- package/src/types.ts +0 -311
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
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
|
-
// }
|