@tanstack/table-core 8.0.0-alpha.22 → 8.0.0-alpha.25
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/aggregationTypes.js +21 -19
- package/build/cjs/aggregationTypes.js.map +1 -1
- package/build/cjs/core.js +17 -29
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +2 -2
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +23 -8
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +1 -8
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +3 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterTypes.js.map +1 -1
- package/build/cjs/sortTypes.js.map +1 -1
- package/build/cjs/utils/columnFilterRowsFn.js +20 -78
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +100 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/globalFilterRowsFn.js +10 -62
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/groupRowsFn.js +15 -15
- package/build/cjs/utils/groupRowsFn.js.map +1 -1
- package/build/cjs/utils/sortRowsFn.js +1 -1
- package/build/cjs/utils/sortRowsFn.js.map +1 -1
- package/build/esm/index.js +2587 -2620
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +368 -335
- package/build/types/aggregationTypes.d.ts +9 -9
- package/build/types/core.d.ts +8 -13
- package/build/types/createTable.d.ts +4 -4
- package/build/types/features/ColumnSizing.d.ts +13 -8
- package/build/types/features/Expanding.d.ts +6 -6
- package/build/types/features/Filters.d.ts +15 -15
- package/build/types/features/Grouping.d.ts +16 -16
- package/build/types/features/Headers.d.ts +6 -6
- package/build/types/features/Ordering.d.ts +4 -4
- package/build/types/features/Pagination.d.ts +5 -5
- package/build/types/features/Pinning.d.ts +5 -5
- package/build/types/features/RowSelection.d.ts +8 -8
- package/build/types/features/Sorting.d.ts +12 -12
- package/build/types/features/Visibility.d.ts +6 -6
- package/build/types/filterTypes.d.ts +10 -10
- package/build/types/sortTypes.d.ts +7 -7
- package/build/types/types.d.ts +22 -13
- package/build/types/utils/filterRowsUtils.d.ts +3 -0
- package/build/types/utils/sortRowsQuicksortFn.d.ts +11 -0
- package/build/umd/index.development.js +2587 -2620
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/aggregationTypes.ts +23 -19
- package/src/core.tsx +29 -55
- package/src/createTable.tsx +17 -11
- package/src/features/ColumnSizing.ts +31 -7
- package/src/features/Expanding.ts +7 -15
- package/src/features/Filters.ts +15 -15
- package/src/features/Grouping.ts +19 -19
- package/src/features/Headers.ts +5 -5
- package/src/features/Ordering.ts +3 -3
- package/src/features/Pagination.ts +4 -4
- package/src/features/Pinning.ts +4 -4
- package/src/features/RowSelection.ts +9 -11
- package/src/features/Sorting.ts +11 -11
- package/src/features/Visibility.ts +5 -5
- package/src/filterTypes.ts +9 -9
- package/src/sortTypes.ts +6 -6
- package/src/types.ts +34 -25
- package/src/utils/columnFilterRowsFn.ts +12 -73
- package/src/utils/filterRowsUtils.ts +107 -0
- package/src/utils/globalFilterRowsFn.ts +10 -66
- package/src/utils/groupRowsFn.ts +15 -17
- package/src/utils/sortRowsFn.ts +6 -8
- package/src/utils/sortRowsQuicksortFn.ts +174 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.25",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/aggregationTypes.ts
CHANGED
|
@@ -12,19 +12,19 @@ export const aggregationTypes = {
|
|
|
12
12
|
|
|
13
13
|
export type BuiltInAggregationType = keyof typeof aggregationTypes
|
|
14
14
|
|
|
15
|
-
function sum(
|
|
15
|
+
function sum(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
16
16
|
// It's faster to just add the aggregations together instead of
|
|
17
17
|
// process leaf nodes individually
|
|
18
|
-
return
|
|
18
|
+
return getChildValues().reduce(
|
|
19
19
|
(sum: number, next: unknown) => sum + (typeof next === 'number' ? next : 0),
|
|
20
20
|
0
|
|
21
21
|
)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function min(
|
|
24
|
+
function min(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
25
25
|
let min: number | undefined
|
|
26
26
|
|
|
27
|
-
for (const value of
|
|
27
|
+
for (const value of getChildValues() as number[]) {
|
|
28
28
|
if (
|
|
29
29
|
value != null &&
|
|
30
30
|
(min! > value || (min === undefined && value >= value))
|
|
@@ -36,10 +36,10 @@ function min(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
36
36
|
return min
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function max(
|
|
39
|
+
function max(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
40
40
|
let max: number | undefined
|
|
41
41
|
|
|
42
|
-
for (const value of
|
|
42
|
+
for (const value of getChildValues() as number[]) {
|
|
43
43
|
if (
|
|
44
44
|
value != null &&
|
|
45
45
|
(max! < value || (max === undefined && value >= value))
|
|
@@ -51,11 +51,14 @@ function max(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
51
51
|
return max
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function extent(
|
|
54
|
+
function extent(
|
|
55
|
+
_getLeafValues: () => unknown[],
|
|
56
|
+
getChildValues: () => unknown[]
|
|
57
|
+
) {
|
|
55
58
|
let min: number | undefined
|
|
56
59
|
let max: number | undefined
|
|
57
60
|
|
|
58
|
-
for (const value of
|
|
61
|
+
for (const value of getChildValues() as number[]) {
|
|
59
62
|
if (value != null) {
|
|
60
63
|
if (min === undefined) {
|
|
61
64
|
if (value >= value) min = max = value
|
|
@@ -69,11 +72,11 @@ function extent(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
69
72
|
return [min, max]
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
function mean(
|
|
75
|
+
function mean(getLeafValues: () => unknown[]) {
|
|
73
76
|
let count = 0
|
|
74
77
|
let sum = 0
|
|
75
78
|
|
|
76
|
-
for (let value of
|
|
79
|
+
for (let value of getLeafValues() as number[]) {
|
|
77
80
|
if (value != null && (value = +value) >= value) {
|
|
78
81
|
++count, (sum += value)
|
|
79
82
|
}
|
|
@@ -84,15 +87,16 @@ function mean(leafValues: unknown[]) {
|
|
|
84
87
|
return
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
function median(
|
|
88
|
-
|
|
90
|
+
function median(getLeafValues: () => unknown[]) {
|
|
91
|
+
const leafValues = getLeafValues()
|
|
92
|
+
if (!leafValues.length) {
|
|
89
93
|
return
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
let min = 0
|
|
93
97
|
let max = 0
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
leafValues.forEach(value => {
|
|
96
100
|
if (typeof value === 'number') {
|
|
97
101
|
min = Math.min(min, value)
|
|
98
102
|
max = Math.max(max, value)
|
|
@@ -102,14 +106,14 @@ function median(values: unknown[]) {
|
|
|
102
106
|
return (min + max) / 2
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
function unique<T>(
|
|
106
|
-
return Array.from(new Set(
|
|
109
|
+
function unique<T>(getLeafValues: () => T[]) {
|
|
110
|
+
return Array.from(new Set(getLeafValues()).values())
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
function uniqueCount(
|
|
110
|
-
return new Set(
|
|
113
|
+
function uniqueCount(getLeafValues: () => unknown[]) {
|
|
114
|
+
return new Set(getLeafValues()).size
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
function count(
|
|
114
|
-
return
|
|
117
|
+
function count(getLeafValues: () => unknown[]) {
|
|
118
|
+
return getLeafValues().length
|
|
115
119
|
}
|
package/src/core.tsx
CHANGED
|
@@ -30,36 +30,38 @@ import {
|
|
|
30
30
|
CoreCell,
|
|
31
31
|
Renderable,
|
|
32
32
|
UseRenderer,
|
|
33
|
+
RowModel,
|
|
34
|
+
TableFeature,
|
|
35
|
+
AnyGenerics,
|
|
33
36
|
} from './types'
|
|
34
37
|
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import { Pinning } from './features/Pinning'
|
|
38
|
-
import { Headers } from './features/Headers'
|
|
38
|
+
import { ColumnSizing } from './features/ColumnSizing'
|
|
39
|
+
import { Expanding } from './features/Expanding'
|
|
39
40
|
import { Filters } from './features/Filters'
|
|
40
|
-
import { Sorting } from './features/Sorting'
|
|
41
41
|
import { Grouping } from './features/Grouping'
|
|
42
|
-
import {
|
|
43
|
-
import { ColumnSizing, defaultColumnSizing } from './features/ColumnSizing'
|
|
42
|
+
import { Ordering } from './features/Ordering'
|
|
44
43
|
import { Pagination } from './features/Pagination'
|
|
44
|
+
import { Pinning } from './features/Pinning'
|
|
45
45
|
import { RowSelection } from './features/RowSelection'
|
|
46
|
-
import {
|
|
46
|
+
import { Sorting } from './features/Sorting'
|
|
47
|
+
import { Visibility } from './features/Visibility'
|
|
48
|
+
import { Headers } from './features/Headers'
|
|
47
49
|
|
|
48
|
-
const features = [
|
|
50
|
+
const features: TableFeature[] = [
|
|
51
|
+
Headers,
|
|
49
52
|
Visibility,
|
|
50
53
|
Ordering,
|
|
51
54
|
Pinning,
|
|
52
|
-
Headers,
|
|
53
55
|
Filters,
|
|
54
56
|
Sorting,
|
|
55
57
|
Grouping,
|
|
56
58
|
Expanding,
|
|
57
|
-
ColumnSizing,
|
|
58
59
|
Pagination,
|
|
59
60
|
RowSelection,
|
|
61
|
+
ColumnSizing,
|
|
60
62
|
]
|
|
61
63
|
|
|
62
|
-
export type CoreOptions<TGenerics extends
|
|
64
|
+
export type CoreOptions<TGenerics extends AnyGenerics> = {
|
|
63
65
|
data: TGenerics['Row'][]
|
|
64
66
|
columns: ColumnDef<TGenerics>[]
|
|
65
67
|
state: Partial<TableState>
|
|
@@ -84,7 +86,7 @@ export type CoreOptions<TGenerics extends PartialGenerics> = {
|
|
|
84
86
|
autoResetAll?: boolean
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
export type TableCore<TGenerics extends
|
|
89
|
+
export type TableCore<TGenerics extends AnyGenerics> = {
|
|
88
90
|
initialState: TableState
|
|
89
91
|
reset: () => void
|
|
90
92
|
options: RequiredKeys<Options<TGenerics>, 'state'>
|
|
@@ -108,7 +110,6 @@ export type TableCore<TGenerics extends PartialGenerics> = {
|
|
|
108
110
|
getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
|
|
109
111
|
getAllLeafColumns: () => Column<TGenerics>[]
|
|
110
112
|
getColumn: (columnId: string) => Column<TGenerics>
|
|
111
|
-
getColumnWidth: (columnId: string) => number
|
|
112
113
|
getTotalWidth: () => number
|
|
113
114
|
createCell: (
|
|
114
115
|
row: Row<TGenerics>,
|
|
@@ -147,27 +148,24 @@ export type TableCore<TGenerics extends PartialGenerics> = {
|
|
|
147
148
|
) => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
export type CoreRow<TGenerics extends
|
|
151
|
+
export type CoreRow<TGenerics extends AnyGenerics> = {
|
|
151
152
|
id: string
|
|
152
153
|
index: number
|
|
153
154
|
original?: TGenerics['Row']
|
|
154
155
|
depth: number
|
|
155
156
|
values: RowValues
|
|
156
|
-
leafRows: Row<TGenerics>[]
|
|
157
157
|
subRows: Row<TGenerics>[]
|
|
158
|
+
getLeafRows: () => Row<TGenerics>[]
|
|
158
159
|
getRowProps: PropGetter<RowProps>
|
|
159
160
|
originalSubRows?: TGenerics['Row'][]
|
|
160
161
|
getAllCells: () => Cell<TGenerics>[]
|
|
161
162
|
getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
export type CoreColumnDef<TGenerics extends
|
|
165
|
+
export type CoreColumnDef<TGenerics extends AnyGenerics> = {
|
|
165
166
|
id: string
|
|
166
167
|
accessorKey?: string & keyof TGenerics['Row']
|
|
167
168
|
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
168
|
-
width?: number
|
|
169
|
-
minWidth?: number
|
|
170
|
-
maxWidth?: number
|
|
171
169
|
columns?: ColumnDef<TGenerics>[]
|
|
172
170
|
header?: Renderable<
|
|
173
171
|
TGenerics,
|
|
@@ -199,7 +197,7 @@ export type CoreColumnDef<TGenerics extends PartialGenerics> = {
|
|
|
199
197
|
}
|
|
200
198
|
// & GeneratedProperties<true>
|
|
201
199
|
|
|
202
|
-
export type CoreColumn<TGenerics extends
|
|
200
|
+
export type CoreColumn<TGenerics extends AnyGenerics> = {
|
|
203
201
|
id: string
|
|
204
202
|
depth: number
|
|
205
203
|
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
@@ -211,7 +209,7 @@ export type CoreColumn<TGenerics extends PartialGenerics> = {
|
|
|
211
209
|
getLeafColumns: () => Column<TGenerics>[]
|
|
212
210
|
}
|
|
213
211
|
|
|
214
|
-
export function createTableInstance<TGenerics extends
|
|
212
|
+
export function createTableInstance<TGenerics extends AnyGenerics>(
|
|
215
213
|
options: Options<TGenerics>
|
|
216
214
|
): TableInstance<TGenerics> {
|
|
217
215
|
if (options.debugAll || options.debugTable) {
|
|
@@ -221,7 +219,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
221
219
|
let instance = {} as TableInstance<TGenerics>
|
|
222
220
|
|
|
223
221
|
const defaultOptions = features.reduce((obj, feature) => {
|
|
224
|
-
return Object.assign(obj,
|
|
222
|
+
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
225
223
|
}, {})
|
|
226
224
|
|
|
227
225
|
const buildOptions = (options: Options<TGenerics>) => ({
|
|
@@ -233,7 +231,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
233
231
|
|
|
234
232
|
const initialState = {
|
|
235
233
|
...features.reduce((obj, feature) => {
|
|
236
|
-
return Object.assign(obj,
|
|
234
|
+
return Object.assign(obj, feature.getInitialState?.())
|
|
237
235
|
}, {}),
|
|
238
236
|
...(options.initialState ?? {}),
|
|
239
237
|
} as TableState
|
|
@@ -241,7 +239,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
241
239
|
const finalInstance: TableInstance<TGenerics> = {
|
|
242
240
|
...instance,
|
|
243
241
|
...features.reduce((obj, feature) => {
|
|
244
|
-
return Object.assign(obj,
|
|
242
|
+
return Object.assign(obj, feature.getInstance?.(instance))
|
|
245
243
|
}, {}),
|
|
246
244
|
initialState,
|
|
247
245
|
reset: () => {
|
|
@@ -288,7 +286,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
288
286
|
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
289
287
|
typeof value === 'boolean' ? value.toString() : value,
|
|
290
288
|
...features.reduce((obj, feature) => {
|
|
291
|
-
return Object.assign(obj,
|
|
289
|
+
return Object.assign(obj, feature.getDefaultColumn?.())
|
|
292
290
|
}, {}),
|
|
293
291
|
...defaultColumn,
|
|
294
292
|
} as Partial<ColumnDef<TGenerics>>
|
|
@@ -330,7 +328,6 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
330
328
|
}
|
|
331
329
|
|
|
332
330
|
let column: CoreColumn<TGenerics> = {
|
|
333
|
-
...defaultColumnSizing,
|
|
334
331
|
...defaultColumn,
|
|
335
332
|
...columnDef,
|
|
336
333
|
id: `${id}`,
|
|
@@ -376,10 +373,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
376
373
|
}
|
|
377
374
|
|
|
378
375
|
column = features.reduce((obj, feature) => {
|
|
379
|
-
return Object.assign(
|
|
380
|
-
obj,
|
|
381
|
-
(feature as any).createColumn?.(column, instance)
|
|
382
|
-
)
|
|
376
|
+
return Object.assign(obj, feature.createColumn?.(column, instance))
|
|
383
377
|
}, column)
|
|
384
378
|
|
|
385
379
|
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
@@ -465,24 +459,6 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
465
459
|
return column
|
|
466
460
|
},
|
|
467
461
|
|
|
468
|
-
getColumnWidth: (columnId: string) => {
|
|
469
|
-
const column = instance.getColumn(columnId)
|
|
470
|
-
|
|
471
|
-
if (!column) {
|
|
472
|
-
throw new Error()
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
const columnSize = instance.getState().columnSizing[column.id]
|
|
476
|
-
|
|
477
|
-
return Math.min(
|
|
478
|
-
Math.max(
|
|
479
|
-
column.minWidth ?? defaultColumnSizing.minWidth,
|
|
480
|
-
columnSize ?? column.width ?? defaultColumnSizing.width
|
|
481
|
-
),
|
|
482
|
-
column.maxWidth ?? defaultColumnSizing.maxWidth
|
|
483
|
-
)
|
|
484
|
-
},
|
|
485
|
-
|
|
486
462
|
createCell: (row, column, value) => {
|
|
487
463
|
const cell: CoreCell<TGenerics> = {
|
|
488
464
|
id: `${row.id}_${column.id}`,
|
|
@@ -508,7 +484,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
508
484
|
features.forEach(feature => {
|
|
509
485
|
Object.assign(
|
|
510
486
|
cell,
|
|
511
|
-
|
|
487
|
+
feature.createCell?.(
|
|
512
488
|
cell as Cell<TGenerics>,
|
|
513
489
|
column,
|
|
514
490
|
row as Row<TGenerics>,
|
|
@@ -528,7 +504,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
528
504
|
depth,
|
|
529
505
|
values,
|
|
530
506
|
subRows: [],
|
|
531
|
-
|
|
507
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
532
508
|
getRowProps: userProps => instance.getRowProps(row.id, userProps)!,
|
|
533
509
|
getAllCells: undefined!,
|
|
534
510
|
getAllCellsByColumnId: undefined!,
|
|
@@ -567,7 +543,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
567
543
|
|
|
568
544
|
for (let i = 0; i < features.length; i++) {
|
|
569
545
|
const feature = features[i]
|
|
570
|
-
Object.assign(row,
|
|
546
|
+
Object.assign(row, feature.createRow?.(row, instance))
|
|
571
547
|
}
|
|
572
548
|
|
|
573
549
|
return row as Row<TGenerics>
|
|
@@ -650,9 +626,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
650
626
|
row
|
|
651
627
|
)
|
|
652
628
|
}
|
|
653
|
-
// Keep the new subRows array on the row
|
|
654
629
|
row.subRows = subRows
|
|
655
|
-
row.leafRows = flattenBy(subRows, d => d.leafRows)
|
|
656
630
|
}
|
|
657
631
|
}
|
|
658
632
|
}
|
|
@@ -667,8 +641,8 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
667
641
|
key: 'getRowModel',
|
|
668
642
|
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
669
643
|
onChange: () => {
|
|
670
|
-
instance._notifyRowSelectionReset()
|
|
671
644
|
instance._notifyFiltersReset()
|
|
645
|
+
instance._notifyRowSelectionReset()
|
|
672
646
|
},
|
|
673
647
|
}
|
|
674
648
|
),
|
package/src/createTable.tsx
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { CustomFilterTypes } from './features/Filters'
|
|
2
2
|
import { CustomAggregationTypes } from './features/Grouping'
|
|
3
3
|
import { CustomSortingTypes } from './features/Sorting'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ColumnDef,
|
|
6
|
+
AccessorFn,
|
|
7
|
+
PartialGenerics,
|
|
8
|
+
AnyRender,
|
|
9
|
+
AnyGenerics,
|
|
10
|
+
} from './types'
|
|
5
11
|
import { Overwrite, PartialKeys } from './utils'
|
|
6
12
|
|
|
7
|
-
export type CreateTableFactory<TGenerics extends
|
|
13
|
+
export type CreateTableFactory<TGenerics extends AnyGenerics> = <
|
|
8
14
|
TSubGenerics extends {
|
|
9
15
|
Row: any
|
|
10
16
|
ColumnMeta?: object
|
|
@@ -28,7 +34,7 @@ export type CreateTableFactoryOptions<
|
|
|
28
34
|
aggregationFns?: TAggregationFns
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
export type Table<TGenerics extends
|
|
37
|
+
export type Table<TGenerics extends AnyGenerics> = {
|
|
32
38
|
generics: TGenerics
|
|
33
39
|
__options: CreateTableFactoryOptions<any, any, any, any>
|
|
34
40
|
createColumns: <TColumnDef extends ColumnDef<any>>(
|
|
@@ -94,8 +100,8 @@ export type Table<TGenerics extends PartialGenerics> = {
|
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
type InitTable<TRender extends AnyRender> = {
|
|
97
|
-
createTableFactory: <TGenerics extends
|
|
98
|
-
options
|
|
103
|
+
createTableFactory: <TGenerics extends AnyGenerics>(
|
|
104
|
+
options: CreateTableFactoryOptions<TRender, any, any, any>
|
|
99
105
|
) => CreateTableFactory<Overwrite<TGenerics, { Render: TRender }>>
|
|
100
106
|
createTable: CreateTableFactory<
|
|
101
107
|
Overwrite<PartialGenerics, { Render: TRender }>
|
|
@@ -108,16 +114,16 @@ export function init<TRender extends AnyRender>(opts: {
|
|
|
108
114
|
render: TRender
|
|
109
115
|
}): InitTable<TRender> {
|
|
110
116
|
return {
|
|
111
|
-
createTableFactory:
|
|
112
|
-
_createTable(undefined, undefined, { ...
|
|
117
|
+
createTableFactory: factoryOptions => () =>
|
|
118
|
+
_createTable(undefined, undefined, { ...factoryOptions, ...opts }),
|
|
113
119
|
createTable: () => _createTable(undefined, undefined, opts),
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
function _createTable<TGenerics extends
|
|
118
|
-
_
|
|
119
|
-
__
|
|
120
|
-
__options
|
|
123
|
+
function _createTable<TGenerics extends AnyGenerics>(
|
|
124
|
+
_: undefined,
|
|
125
|
+
__: undefined,
|
|
126
|
+
__options: CreateTableFactoryOptions<any, any, any, any>
|
|
121
127
|
): Table<TGenerics> {
|
|
122
128
|
return {
|
|
123
129
|
generics: undefined!,
|
|
@@ -52,7 +52,8 @@ export type ColumnResizerProps = {
|
|
|
52
52
|
role?: string
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export type ColumnSizingInstance<TGenerics extends
|
|
55
|
+
export type ColumnSizingInstance<TGenerics extends AnyGenerics> = {
|
|
56
|
+
getColumnWidth: (columnId: string) => number
|
|
56
57
|
setColumnSizing: (updater: Updater<ColumnSizing>) => void
|
|
57
58
|
setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => void
|
|
58
59
|
resetColumnSizing: () => void
|
|
@@ -72,15 +73,18 @@ export type ColumnSizingInstance<TGenerics extends PartialGenerics> = {
|
|
|
72
73
|
export type ColumnSizingColumnDef = {
|
|
73
74
|
enableResizing?: boolean
|
|
74
75
|
defaultCanResize?: boolean
|
|
76
|
+
width?: number
|
|
77
|
+
minWidth?: number
|
|
78
|
+
maxWidth?: number
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
export type ColumnSizingColumn<TGenerics extends
|
|
81
|
+
export type ColumnSizingColumn<TGenerics extends AnyGenerics> = {
|
|
78
82
|
getCanResize: () => boolean
|
|
79
83
|
getIsResizing: () => boolean
|
|
80
84
|
resetSize: () => void
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
export type ColumnSizingHeader<TGenerics extends
|
|
87
|
+
export type ColumnSizingHeader<TGenerics extends AnyGenerics> = {
|
|
84
88
|
getCanResize: () => boolean
|
|
85
89
|
getIsResizing: () => boolean
|
|
86
90
|
getResizerProps: <TGetter extends Getter<ColumnResizerProps>>(
|
|
@@ -98,6 +102,9 @@ export const defaultColumnSizing = {
|
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
export const ColumnSizing = {
|
|
105
|
+
getDefaultColumn: (): ColumnSizingColumnDef => {
|
|
106
|
+
return defaultColumnSizing
|
|
107
|
+
},
|
|
101
108
|
getInitialState: (): ColumnSizingTableState => {
|
|
102
109
|
return {
|
|
103
110
|
columnSizing: {},
|
|
@@ -112,7 +119,7 @@ export const ColumnSizing = {
|
|
|
112
119
|
}
|
|
113
120
|
},
|
|
114
121
|
|
|
115
|
-
getDefaultOptions: <TGenerics extends
|
|
122
|
+
getDefaultOptions: <TGenerics extends AnyGenerics>(
|
|
116
123
|
instance: TableInstance<TGenerics>
|
|
117
124
|
): ColumnSizingDefaultOptions => {
|
|
118
125
|
return {
|
|
@@ -122,10 +129,27 @@ export const ColumnSizing = {
|
|
|
122
129
|
}
|
|
123
130
|
},
|
|
124
131
|
|
|
125
|
-
getInstance: <TGenerics extends
|
|
132
|
+
getInstance: <TGenerics extends AnyGenerics>(
|
|
126
133
|
instance: TableInstance<TGenerics>
|
|
127
134
|
): ColumnSizingInstance<TGenerics> => {
|
|
128
135
|
return {
|
|
136
|
+
getColumnWidth: (columnId: string) => {
|
|
137
|
+
const column = instance.getColumn(columnId)
|
|
138
|
+
|
|
139
|
+
if (!column) {
|
|
140
|
+
throw new Error()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const columnSize = instance.getState().columnSizing[column.id]
|
|
144
|
+
|
|
145
|
+
return Math.min(
|
|
146
|
+
Math.max(
|
|
147
|
+
column.minWidth ?? defaultColumnSizing.minWidth,
|
|
148
|
+
columnSize ?? column.width ?? defaultColumnSizing.width
|
|
149
|
+
),
|
|
150
|
+
column.maxWidth ?? defaultColumnSizing.maxWidth
|
|
151
|
+
)
|
|
152
|
+
},
|
|
129
153
|
setColumnSizing: updater =>
|
|
130
154
|
instance.options.onColumnSizingChange?.(
|
|
131
155
|
updater,
|
|
@@ -373,7 +397,7 @@ export const ColumnSizing = {
|
|
|
373
397
|
}
|
|
374
398
|
},
|
|
375
399
|
|
|
376
|
-
createColumn: <TGenerics extends
|
|
400
|
+
createColumn: <TGenerics extends AnyGenerics>(
|
|
377
401
|
column: Column<TGenerics>,
|
|
378
402
|
instance: TableInstance<TGenerics>
|
|
379
403
|
): ColumnSizingColumn<TGenerics> => {
|
|
@@ -384,7 +408,7 @@ export const ColumnSizing = {
|
|
|
384
408
|
}
|
|
385
409
|
},
|
|
386
410
|
|
|
387
|
-
createHeader: <TGenerics extends
|
|
411
|
+
createHeader: <TGenerics extends AnyGenerics>(
|
|
388
412
|
header: Header<TGenerics>,
|
|
389
413
|
instance: TableInstance<TGenerics>
|
|
390
414
|
): ColumnSizingHeader<TGenerics> => {
|
|
@@ -27,7 +27,7 @@ export type ExpandedRow = {
|
|
|
27
27
|
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export type ExpandedOptions<TGenerics extends
|
|
30
|
+
export type ExpandedOptions<TGenerics extends AnyGenerics> = {
|
|
31
31
|
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
32
32
|
autoResetExpanded?: boolean
|
|
33
33
|
enableExpanded?: boolean
|
|
@@ -47,7 +47,7 @@ export type ToggleExpandedProps = {
|
|
|
47
47
|
onClick?: (event: MouseEvent | TouchEvent) => void
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export type ExpandedInstance<TGenerics extends
|
|
50
|
+
export type ExpandedInstance<TGenerics extends AnyGenerics> = {
|
|
51
51
|
_notifyExpandedReset: () => void
|
|
52
52
|
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
53
53
|
toggleRowExpanded: (rowId: string, expanded?: boolean) => void
|
|
@@ -78,7 +78,7 @@ export const Expanding = {
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
|
|
81
|
-
getDefaultOptions: <TGenerics extends
|
|
81
|
+
getDefaultOptions: <TGenerics extends AnyGenerics>(
|
|
82
82
|
instance: TableInstance<TGenerics>
|
|
83
83
|
): ExpandedOptions<TGenerics> => {
|
|
84
84
|
return {
|
|
@@ -89,7 +89,7 @@ export const Expanding = {
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
|
|
92
|
-
getInstance: <TGenerics extends
|
|
92
|
+
getInstance: <TGenerics extends AnyGenerics>(
|
|
93
93
|
instance: TableInstance<TGenerics>
|
|
94
94
|
): ExpandedInstance<TGenerics> => {
|
|
95
95
|
let registered = false
|
|
@@ -298,7 +298,7 @@ export const Expanding = {
|
|
|
298
298
|
}
|
|
299
299
|
},
|
|
300
300
|
|
|
301
|
-
createRow: <TGenerics extends
|
|
301
|
+
createRow: <TGenerics extends AnyGenerics>(
|
|
302
302
|
row: Row<TGenerics>,
|
|
303
303
|
instance: TableInstance<TGenerics>
|
|
304
304
|
): ExpandedRow => {
|
|
@@ -307,16 +307,8 @@ export const Expanding = {
|
|
|
307
307
|
void instance.toggleRowExpanded(row.id, expanded),
|
|
308
308
|
getIsExpanded: () => instance.getIsRowExpanded(row.id),
|
|
309
309
|
getCanExpand: () => row.subRows && !!row.subRows.length,
|
|
310
|
-
getToggleExpandedProps: userProps =>
|
|
311
|
-
|
|
312
|
-
title: 'Toggle Row Expanded',
|
|
313
|
-
onClick: (e: MouseEvent | TouchEvent) => {
|
|
314
|
-
e.stopPropagation()
|
|
315
|
-
instance.toggleRowExpanded(row.id)
|
|
316
|
-
},
|
|
317
|
-
}
|
|
318
|
-
return propGetter(initialProps, userProps)
|
|
319
|
-
},
|
|
310
|
+
getToggleExpandedProps: userProps =>
|
|
311
|
+
instance.getToggleExpandedProps(row.id, userProps),
|
|
320
312
|
}
|
|
321
313
|
},
|
|
322
314
|
}
|