@tanstack/table-core 8.0.0-alpha.12 → 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.
- package/build/cjs/core.js +17 -6
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +17 -9
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +2 -2
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +2 -2
- 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 +13 -2
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +4 -4
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +1 -3
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/types.js +0 -3
- package/build/cjs/types.js.map +1 -1
- package/build/cjs/utils/columnFilterRowsFn.js +1 -1
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/expandRowsFn.js.map +1 -1
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/groupRowsFn.js +1 -1
- package/build/cjs/utils/groupRowsFn.js.map +1 -1
- package/build/cjs/utils/paginateRowsFn.js.map +1 -1
- package/build/cjs/utils/sortRowsFn.js.map +1 -1
- package/build/cjs/utils.js +0 -24
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +58 -50
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +268 -282
- package/build/types/core.d.ts +11 -9
- package/build/types/createTable.d.ts +32 -16
- package/build/types/features/ColumnSizing.d.ts +2 -3
- package/build/types/features/Grouping.d.ts +11 -5
- package/build/types/features/RowSelection.d.ts +2 -3
- package/build/types/features/Visibility.d.ts +1 -0
- package/build/types/types.d.ts +14 -7
- package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
- package/build/types/utils/expandRowsFn.d.ts +2 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
- package/build/types/utils/groupRowsFn.d.ts +2 -2
- package/build/types/utils/paginateRowsFn.d.ts +2 -2
- package/build/types/utils/sortRowsFn.d.ts +2 -2
- package/build/types/utils.d.ts +4 -5
- package/build/umd/index.development.js +62 -58
- 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/core.tsx +63 -35
- package/src/createTable.tsx +69 -34
- package/src/features/ColumnSizing.ts +8 -14
- package/src/features/Expanding.ts +2 -2
- package/src/features/Filters.ts +1 -1
- package/src/features/Grouping.ts +30 -7
- package/src/features/Headers.ts +15 -3
- package/src/features/RowSelection.ts +2 -2
- package/src/features/Visibility.ts +1 -0
- package/src/types.ts +28 -15
- package/src/utils/columnFilterRowsFn.ts +3 -5
- package/src/utils/expandRowsFn.ts +2 -2
- package/src/utils/globalFilterRowsFn.ts +2 -2
- package/src/utils/groupRowsFn.ts +4 -4
- package/src/utils/paginateRowsFn.ts +2 -2
- package/src/utils/sortRowsFn.ts +2 -2
- package/src/utils.tsx +6 -45
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.16",
|
|
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/core.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
functionalUpdate,
|
|
4
4
|
propGetter,
|
|
5
5
|
memo,
|
|
6
|
-
flexRender,
|
|
7
6
|
RequiredKeys,
|
|
8
7
|
} from './utils'
|
|
9
8
|
|
|
@@ -27,9 +26,11 @@ import {
|
|
|
27
26
|
CellProps,
|
|
28
27
|
TableInstance,
|
|
29
28
|
RowValues,
|
|
30
|
-
Renderable,
|
|
31
29
|
Please_use_the_create_table_column_utilities_to_define_columns,
|
|
32
30
|
PartialGenerics,
|
|
31
|
+
CoreCell,
|
|
32
|
+
Renderable,
|
|
33
|
+
UseRenderer,
|
|
33
34
|
} from './types'
|
|
34
35
|
|
|
35
36
|
import { Visibility } from './features/Visibility'
|
|
@@ -38,7 +39,7 @@ import { Pinning } from './features/Pinning'
|
|
|
38
39
|
import { Headers } from './features/Headers'
|
|
39
40
|
import { Filters } from './features/Filters'
|
|
40
41
|
import { Sorting } from './features/Sorting'
|
|
41
|
-
import { Grouping
|
|
42
|
+
import { Grouping } from './features/Grouping'
|
|
42
43
|
import { Expanding } from './features/Expanding'
|
|
43
44
|
import { ColumnSizing, defaultColumnSizing } from './features/ColumnSizing'
|
|
44
45
|
import { Pagination } from './features/Pagination'
|
|
@@ -64,6 +65,7 @@ export type CoreOptions<TGenerics extends PartialGenerics> = {
|
|
|
64
65
|
columns: ColumnDef<TGenerics>[]
|
|
65
66
|
state: Partial<TableState>
|
|
66
67
|
onStateChange: (updater: Updater<TableState>) => void
|
|
68
|
+
render: TGenerics['Render']
|
|
67
69
|
debugAll?: boolean
|
|
68
70
|
debugTable?: boolean
|
|
69
71
|
debugHeaders?: boolean
|
|
@@ -140,6 +142,10 @@ export type TableCore<TGenerics extends PartialGenerics> = {
|
|
|
140
142
|
getLeftTableWidth: () => number
|
|
141
143
|
getCenterTableWidth: () => number
|
|
142
144
|
getRightTableWidth: () => number
|
|
145
|
+
render: <TProps>(
|
|
146
|
+
template: Renderable<TGenerics, TProps>,
|
|
147
|
+
props: TProps
|
|
148
|
+
) => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
export type CoreRow<TGenerics extends PartialGenerics> = {
|
|
@@ -160,30 +166,37 @@ export type CoreColumnDef<TGenerics extends PartialGenerics> = {
|
|
|
160
166
|
id: string
|
|
161
167
|
accessorKey?: string & keyof TGenerics['Row']
|
|
162
168
|
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
163
|
-
header?:
|
|
164
|
-
| string
|
|
165
|
-
| Renderable<{
|
|
166
|
-
instance: TableInstance<TGenerics>
|
|
167
|
-
header: Header<TGenerics>
|
|
168
|
-
column: Column<TGenerics>
|
|
169
|
-
}>
|
|
170
169
|
width?: number
|
|
171
170
|
minWidth?: number
|
|
172
171
|
maxWidth?: number
|
|
173
172
|
columns?: ColumnDef<TGenerics>[]
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
header?: Renderable<
|
|
174
|
+
TGenerics,
|
|
175
|
+
{
|
|
176
|
+
instance: TableInstance<TGenerics>
|
|
177
|
+
header: Header<TGenerics>
|
|
178
|
+
column: Column<TGenerics>
|
|
179
|
+
}
|
|
180
|
+
>
|
|
181
|
+
footer?: Renderable<
|
|
182
|
+
TGenerics,
|
|
183
|
+
{
|
|
184
|
+
instance: TableInstance<TGenerics>
|
|
185
|
+
header: Header<TGenerics>
|
|
186
|
+
column: Column<TGenerics>
|
|
187
|
+
}
|
|
188
|
+
>
|
|
189
|
+
cell?: Renderable<
|
|
190
|
+
TGenerics,
|
|
191
|
+
{
|
|
192
|
+
instance: TableInstance<TGenerics>
|
|
193
|
+
row: Row<TGenerics>
|
|
194
|
+
column: Column<TGenerics>
|
|
195
|
+
cell: Cell<TGenerics>
|
|
196
|
+
value: TGenerics['Value']
|
|
197
|
+
}
|
|
198
|
+
>
|
|
199
|
+
meta?: TGenerics['ColumnMeta']
|
|
187
200
|
[Please_use_the_create_table_column_utilities_to_define_columns]: true
|
|
188
201
|
}
|
|
189
202
|
|
|
@@ -203,13 +216,11 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
203
216
|
options: Options<TGenerics>
|
|
204
217
|
): TableInstance<TGenerics> {
|
|
205
218
|
if (options.debugAll || options.debugTable) {
|
|
206
|
-
console.info('Creating
|
|
219
|
+
console.info('Creating Table Instance...')
|
|
207
220
|
}
|
|
208
221
|
|
|
209
222
|
let instance = {} as TableInstance<TGenerics>
|
|
210
223
|
|
|
211
|
-
let listeners: (() => void)[] = []
|
|
212
|
-
|
|
213
224
|
const defaultOptions = features.reduce((obj, feature) => {
|
|
214
225
|
return Object.assign(obj, (feature as any).getDefaultOptions?.(instance))
|
|
215
226
|
}, {})
|
|
@@ -242,6 +253,17 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
242
253
|
functionalUpdate(updater, instance.options)
|
|
243
254
|
)
|
|
244
255
|
},
|
|
256
|
+
render: (template, props) => {
|
|
257
|
+
if (typeof instance.options.render === 'function') {
|
|
258
|
+
return instance.options.render(template, props)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (typeof template === 'function') {
|
|
262
|
+
return (template as Function)(props)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return template
|
|
266
|
+
},
|
|
245
267
|
|
|
246
268
|
getRowId: (_: TGenerics['Row'], index: number, parent?: Row<TGenerics>) =>
|
|
247
269
|
`${parent ? [parent.id, index].join('.') : index}`,
|
|
@@ -436,9 +458,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
436
458
|
|
|
437
459
|
if (!column) {
|
|
438
460
|
if (process.env.NODE_ENV !== 'production') {
|
|
439
|
-
console.warn(
|
|
440
|
-
`[React Table] Column with id ${columnId} does not exist.`
|
|
441
|
-
)
|
|
461
|
+
console.warn(`[Table] Column with id ${columnId} does not exist.`)
|
|
442
462
|
}
|
|
443
463
|
throw new Error()
|
|
444
464
|
}
|
|
@@ -465,7 +485,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
465
485
|
},
|
|
466
486
|
|
|
467
487
|
createCell: (row, column, value) => {
|
|
468
|
-
const cell:
|
|
488
|
+
const cell: CoreCell<TGenerics> = {
|
|
469
489
|
id: `${row.id}_${column.id}`,
|
|
470
490
|
rowId: row.id,
|
|
471
491
|
columnId: column.id,
|
|
@@ -475,14 +495,22 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
475
495
|
getCellProps: userProps =>
|
|
476
496
|
instance.getCellProps(row.id, column.id, userProps)!,
|
|
477
497
|
renderCell: () =>
|
|
478
|
-
|
|
498
|
+
column.cell
|
|
499
|
+
? instance.render(column.cell, {
|
|
500
|
+
instance,
|
|
501
|
+
column,
|
|
502
|
+
row,
|
|
503
|
+
cell: cell as Cell<TGenerics>,
|
|
504
|
+
value,
|
|
505
|
+
})
|
|
506
|
+
: null,
|
|
479
507
|
}
|
|
480
508
|
|
|
481
509
|
features.forEach(feature => {
|
|
482
510
|
Object.assign(
|
|
483
511
|
cell,
|
|
484
512
|
(feature as any).createCell?.(
|
|
485
|
-
cell as Cell<TGenerics
|
|
513
|
+
cell as Cell<TGenerics>,
|
|
486
514
|
column,
|
|
487
515
|
row as Row<TGenerics>,
|
|
488
516
|
instance
|
|
@@ -490,7 +518,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
490
518
|
)
|
|
491
519
|
}, {})
|
|
492
520
|
|
|
493
|
-
return cell
|
|
521
|
+
return cell as Cell<TGenerics>
|
|
494
522
|
},
|
|
495
523
|
|
|
496
524
|
createRow: (id, original, rowIndex, depth, values) => {
|
|
@@ -671,7 +699,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
671
699
|
|
|
672
700
|
if (!row) {
|
|
673
701
|
if (process.env.NODE_ENV !== 'production') {
|
|
674
|
-
throw new Error(`[
|
|
702
|
+
throw new Error(`[Table] could not find row with id ${rowId}`)
|
|
675
703
|
}
|
|
676
704
|
throw new Error()
|
|
677
705
|
}
|
|
@@ -681,7 +709,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
681
709
|
if (!cell) {
|
|
682
710
|
if (process.env.NODE_ENV !== 'production') {
|
|
683
711
|
throw new Error(
|
|
684
|
-
`[
|
|
712
|
+
`[Table] could not find cell ${columnId} in row ${rowId}`
|
|
685
713
|
)
|
|
686
714
|
}
|
|
687
715
|
throw new Error()
|
package/src/createTable.tsx
CHANGED
|
@@ -4,47 +4,38 @@ import { CustomSortingTypes } from './features/Sorting'
|
|
|
4
4
|
import {
|
|
5
5
|
ColumnDef,
|
|
6
6
|
AccessorFn,
|
|
7
|
-
DefaultGenerics,
|
|
8
7
|
PartialGenerics,
|
|
9
8
|
_NonGenerated,
|
|
9
|
+
AnyRender,
|
|
10
10
|
} from './types'
|
|
11
11
|
import { Overwrite, PartialKeys } from './utils'
|
|
12
12
|
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export type CreateTableFactory<TGenerics extends PartialGenerics> = <
|
|
14
|
+
TSubGenerics extends {
|
|
15
|
+
Row: any
|
|
16
|
+
ColumnMeta?: object
|
|
17
|
+
}
|
|
18
|
+
>() => Table<
|
|
19
|
+
Overwrite<
|
|
20
|
+
TGenerics,
|
|
21
|
+
{ Row: TSubGenerics['Row']; ColumnMeta: TSubGenerics['ColumnMeta'] }
|
|
22
|
+
>
|
|
23
|
+
>
|
|
16
24
|
|
|
17
25
|
export type CreateTableFactoryOptions<
|
|
26
|
+
TRender extends AnyRender,
|
|
18
27
|
TFilterFns extends CustomFilterTypes<any>,
|
|
19
28
|
TSortingFns extends CustomSortingTypes<any>,
|
|
20
29
|
TAggregationFns extends CustomAggregationTypes<any>
|
|
21
30
|
> = {
|
|
31
|
+
render: TRender
|
|
22
32
|
filterFns?: TFilterFns
|
|
23
33
|
sortingFns?: TSortingFns
|
|
24
34
|
aggregationFns?: TAggregationFns
|
|
25
35
|
}
|
|
26
36
|
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
TSortingFns extends CustomSortingTypes<any>,
|
|
30
|
-
TAggregationFns extends CustomAggregationTypes<any>
|
|
31
|
-
>(
|
|
32
|
-
opts: CreateTableFactoryOptions<TFilterFns, TSortingFns, TAggregationFns>
|
|
33
|
-
): CreatTableFactory<
|
|
34
|
-
Overwrite<
|
|
35
|
-
PartialGenerics,
|
|
36
|
-
{
|
|
37
|
-
FilterFns: TFilterFns
|
|
38
|
-
SortingFns: TSortingFns
|
|
39
|
-
AggregationFns: TAggregationFns
|
|
40
|
-
}
|
|
41
|
-
>
|
|
42
|
-
> {
|
|
43
|
-
return () => _createTable(undefined, undefined, opts)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
|
|
47
|
-
__options: CreateTableFactoryOptions<any, any, any>
|
|
37
|
+
export type Table<TGenerics extends PartialGenerics> = {
|
|
38
|
+
__options: CreateTableFactoryOptions<any, any, any, any>
|
|
48
39
|
createColumns: (columns: ColumnDef<TGenerics>[]) => ColumnDef<TGenerics>[]
|
|
49
40
|
createGroup: (
|
|
50
41
|
column: Overwrite<
|
|
@@ -62,7 +53,13 @@ export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
|
|
|
62
53
|
header?: string | ColumnDef<TGenerics>['header']
|
|
63
54
|
}
|
|
64
55
|
>,
|
|
65
|
-
{
|
|
56
|
+
{
|
|
57
|
+
accessorFn?: never
|
|
58
|
+
accessorKey?: never
|
|
59
|
+
// This is sketchy, but allows the column helper pattern we want.
|
|
60
|
+
// Someone smarter than me could probably do this better.
|
|
61
|
+
columns?: ColumnDef<any>[]
|
|
62
|
+
}
|
|
66
63
|
>
|
|
67
64
|
) => ColumnDef<TGenerics>
|
|
68
65
|
createDisplayColumn: (
|
|
@@ -78,11 +75,17 @@ export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
|
|
|
78
75
|
column: Overwrite<
|
|
79
76
|
TAccessor extends (...args: any[]) => any
|
|
80
77
|
? // Accessor Fn
|
|
81
|
-
_NonGenerated<
|
|
78
|
+
_NonGenerated<
|
|
79
|
+
ColumnDef<Overwrite<TGenerics, { Value: ReturnType<TAccessor> }>>
|
|
80
|
+
>
|
|
82
81
|
: TAccessor extends keyof TGenerics['Row']
|
|
83
82
|
? // Accessor Key
|
|
84
83
|
Overwrite<
|
|
85
|
-
_NonGenerated<
|
|
84
|
+
_NonGenerated<
|
|
85
|
+
ColumnDef<
|
|
86
|
+
Overwrite<TGenerics, { Value: TGenerics['Row'][TAccessor] }>
|
|
87
|
+
>
|
|
88
|
+
>,
|
|
86
89
|
{
|
|
87
90
|
id?: string
|
|
88
91
|
}
|
|
@@ -93,20 +96,52 @@ export type TableFactory<TGenerics extends Partial<DefaultGenerics>> = {
|
|
|
93
96
|
accessorKey?: never
|
|
94
97
|
}
|
|
95
98
|
>
|
|
96
|
-
) => ColumnDef<
|
|
99
|
+
) => ColumnDef<
|
|
100
|
+
Overwrite<
|
|
101
|
+
TGenerics,
|
|
102
|
+
{
|
|
103
|
+
Value: TAccessor extends (...args: any[]) => any
|
|
104
|
+
? ReturnType<TAccessor>
|
|
105
|
+
: TAccessor extends keyof TGenerics['Row']
|
|
106
|
+
? TGenerics['Row'][TAccessor]
|
|
107
|
+
: never
|
|
108
|
+
}
|
|
109
|
+
>
|
|
110
|
+
>
|
|
97
111
|
}
|
|
98
112
|
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
type InitTable<TRender extends AnyRender> = {
|
|
114
|
+
createTableFactory: <TGenerics extends PartialGenerics>(
|
|
115
|
+
options?: CreateTableFactoryOptions<TRender, any, any, any>
|
|
116
|
+
) => CreateTableFactory<Overwrite<TGenerics, { Render: TRender }>>
|
|
117
|
+
createTable: CreateTableFactory<
|
|
118
|
+
Overwrite<PartialGenerics, { Render: TRender }>
|
|
119
|
+
>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//
|
|
123
|
+
|
|
124
|
+
export function init<TRender extends AnyRender>(opts: {
|
|
125
|
+
render: TRender
|
|
126
|
+
}): InitTable<TRender> {
|
|
127
|
+
return {
|
|
128
|
+
createTableFactory: options => () =>
|
|
129
|
+
_createTable(undefined, undefined, { ...options, ...opts }),
|
|
130
|
+
createTable: () => _createTable(undefined, undefined, opts),
|
|
131
|
+
}
|
|
101
132
|
}
|
|
102
133
|
|
|
103
134
|
function _createTable<TGenerics extends PartialGenerics>(
|
|
104
135
|
_?: undefined,
|
|
105
136
|
__?: undefined,
|
|
106
|
-
__options?: CreateTableFactoryOptions<any, any, any>
|
|
107
|
-
):
|
|
137
|
+
__options?: CreateTableFactoryOptions<any, any, any, any>
|
|
138
|
+
): Table<TGenerics> {
|
|
108
139
|
return {
|
|
109
|
-
__options: __options
|
|
140
|
+
__options: __options ?? {
|
|
141
|
+
render: () => {
|
|
142
|
+
throw new Error()
|
|
143
|
+
},
|
|
144
|
+
},
|
|
110
145
|
createColumns: columns => columns,
|
|
111
146
|
createDisplayColumn: column => column as any,
|
|
112
147
|
createGroup: column => column as any,
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MouseEvent as ReactMouseEvent,
|
|
3
|
-
TouchEvent as ReactTouchEvent,
|
|
4
|
-
} from 'react'
|
|
5
1
|
import {
|
|
6
2
|
Column,
|
|
7
3
|
Getter,
|
|
@@ -49,8 +45,8 @@ export type ColumnSizingDefaultOptions = {
|
|
|
49
45
|
|
|
50
46
|
export type ColumnResizerProps = {
|
|
51
47
|
title?: string
|
|
52
|
-
onMouseDown?: (e:
|
|
53
|
-
onTouchStart?: (e:
|
|
48
|
+
onMouseDown?: (e: MouseEvent) => void
|
|
49
|
+
onTouchStart?: (e: TouchEvent) => void
|
|
54
50
|
draggable?: boolean
|
|
55
51
|
role?: string
|
|
56
52
|
}
|
|
@@ -207,7 +203,7 @@ export const ColumnSizing = {
|
|
|
207
203
|
|
|
208
204
|
const canResize = column.getCanResize()
|
|
209
205
|
|
|
210
|
-
const onResizeStart = (e:
|
|
206
|
+
const onResizeStart = (e: MouseEvent | TouchEvent) => {
|
|
211
207
|
if (isTouchStartEvent(e)) {
|
|
212
208
|
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
213
209
|
if (e.touches && e.touches.length > 1) {
|
|
@@ -360,12 +356,12 @@ export const ColumnSizing = {
|
|
|
360
356
|
title: 'Toggle Grouping',
|
|
361
357
|
draggable: false,
|
|
362
358
|
role: 'separator',
|
|
363
|
-
onMouseDown: (e:
|
|
364
|
-
e.persist()
|
|
359
|
+
onMouseDown: (e: MouseEvent & { persist?: () => void }) => {
|
|
360
|
+
e.persist?.()
|
|
365
361
|
onResizeStart(e)
|
|
366
362
|
},
|
|
367
|
-
onTouchStart: (e:
|
|
368
|
-
e.persist()
|
|
363
|
+
onTouchStart: (e: TouchEvent & { persist?: () => void }) => {
|
|
364
|
+
e.persist?.()
|
|
369
365
|
onResizeStart(e)
|
|
370
366
|
},
|
|
371
367
|
}
|
|
@@ -425,8 +421,6 @@ export function passiveEventSupported() {
|
|
|
425
421
|
return passiveSupported
|
|
426
422
|
}
|
|
427
423
|
|
|
428
|
-
function isTouchStartEvent(
|
|
429
|
-
e: ReactTouchEvent | ReactMouseEvent
|
|
430
|
-
): e is ReactTouchEvent {
|
|
424
|
+
function isTouchStartEvent(e: TouchEvent | MouseEvent): e is TouchEvent {
|
|
431
425
|
return e.type === 'touchstart'
|
|
432
426
|
}
|
|
@@ -165,7 +165,7 @@ export const Expanding = {
|
|
|
165
165
|
if (!row) {
|
|
166
166
|
if (process.env.NODE_ENV !== 'production') {
|
|
167
167
|
console.warn(
|
|
168
|
-
`[
|
|
168
|
+
`[Table] getIsRowExpanded: no row found with id ${rowId}`
|
|
169
169
|
)
|
|
170
170
|
}
|
|
171
171
|
throw new Error()
|
|
@@ -184,7 +184,7 @@ export const Expanding = {
|
|
|
184
184
|
if (!row) {
|
|
185
185
|
if (process.env.NODE_ENV !== 'production') {
|
|
186
186
|
console.warn(
|
|
187
|
-
`[
|
|
187
|
+
`[Table] getRowCanExpand: no row found with id ${rowId}`
|
|
188
188
|
)
|
|
189
189
|
}
|
|
190
190
|
throw new Error()
|
package/src/features/Filters.ts
CHANGED
|
@@ -409,7 +409,7 @@ export const Filters = {
|
|
|
409
409
|
if (!column) {
|
|
410
410
|
if (process.env.NODE_ENV !== 'production') {
|
|
411
411
|
console.warn(
|
|
412
|
-
`
|
|
412
|
+
`Table: Could not find a column with id: ${columnId}`
|
|
413
413
|
)
|
|
414
414
|
}
|
|
415
415
|
throw new Error()
|
package/src/features/Grouping.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React, { MouseEvent, TouchEvent } from 'react'
|
|
2
1
|
import { RowModel } from '..'
|
|
3
2
|
import { BuiltInAggregationType, aggregationTypes } from '../aggregationTypes'
|
|
4
3
|
import {
|
|
@@ -11,6 +10,8 @@ import {
|
|
|
11
10
|
Row,
|
|
12
11
|
Updater,
|
|
13
12
|
PartialGenerics,
|
|
13
|
+
Renderable,
|
|
14
|
+
UseRenderer,
|
|
14
15
|
} from '../types'
|
|
15
16
|
import {
|
|
16
17
|
functionalUpdate,
|
|
@@ -46,7 +47,16 @@ export type GroupingTableState = {
|
|
|
46
47
|
export type GroupingColumnDef<TGenerics extends PartialGenerics> = {
|
|
47
48
|
aggregationType?: AggregationType<Overwrite<TGenerics, { Value: any }>>
|
|
48
49
|
aggregateValue?: (columnValue: unknown) => any
|
|
49
|
-
|
|
50
|
+
aggregatedCell?: Renderable<
|
|
51
|
+
TGenerics,
|
|
52
|
+
{
|
|
53
|
+
instance: TableInstance<TGenerics>
|
|
54
|
+
row: Row<TGenerics>
|
|
55
|
+
column: Column<TGenerics>
|
|
56
|
+
cell: Cell<TGenerics>
|
|
57
|
+
value: TGenerics['Value']
|
|
58
|
+
}
|
|
59
|
+
>
|
|
50
60
|
enableGrouping?: boolean
|
|
51
61
|
defaultCanGroup?: boolean
|
|
52
62
|
}
|
|
@@ -68,10 +78,11 @@ export type GroupingRow = {
|
|
|
68
78
|
getIsGrouped: () => boolean
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
export type GroupingCell = {
|
|
81
|
+
export type GroupingCell<TGenerics extends PartialGenerics> = {
|
|
72
82
|
getIsGrouped: () => boolean
|
|
73
83
|
getIsPlaceholder: () => boolean
|
|
74
84
|
getIsAggregated: () => boolean
|
|
85
|
+
renderAggregatedCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
export type ColumnDefaultOptions = {
|
|
@@ -277,7 +288,6 @@ export const Grouping = {
|
|
|
277
288
|
title: canGroup ? 'Toggle Grouping' : undefined,
|
|
278
289
|
onClick: canGroup
|
|
279
290
|
? (e: MouseEvent | TouchEvent) => {
|
|
280
|
-
e.persist()
|
|
281
291
|
column.toggleGrouping?.()
|
|
282
292
|
}
|
|
283
293
|
: undefined,
|
|
@@ -321,11 +331,11 @@ export const Grouping = {
|
|
|
321
331
|
},
|
|
322
332
|
|
|
323
333
|
createCell: <TGenerics extends PartialGenerics>(
|
|
324
|
-
cell: Cell<TGenerics
|
|
334
|
+
cell: Cell<TGenerics>,
|
|
325
335
|
column: Column<TGenerics>,
|
|
326
336
|
row: Row<TGenerics>,
|
|
327
|
-
|
|
328
|
-
): GroupingCell => {
|
|
337
|
+
instance: TableInstance<TGenerics>
|
|
338
|
+
): GroupingCell<TGenerics> => {
|
|
329
339
|
return {
|
|
330
340
|
getIsGrouped: () =>
|
|
331
341
|
column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
@@ -334,6 +344,19 @@ export const Grouping = {
|
|
|
334
344
|
!cell.getIsGrouped() &&
|
|
335
345
|
!cell.getIsPlaceholder() &&
|
|
336
346
|
row.subRows?.length > 1,
|
|
347
|
+
renderAggregatedCell: () => {
|
|
348
|
+
const template = column.aggregatedCell ?? column.cell
|
|
349
|
+
|
|
350
|
+
return template
|
|
351
|
+
? instance.render(template, {
|
|
352
|
+
instance,
|
|
353
|
+
column,
|
|
354
|
+
row,
|
|
355
|
+
cell,
|
|
356
|
+
value: cell.value,
|
|
357
|
+
})
|
|
358
|
+
: null
|
|
359
|
+
},
|
|
337
360
|
}
|
|
338
361
|
},
|
|
339
362
|
|
package/src/features/Headers.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
TableInstance,
|
|
15
15
|
Row,
|
|
16
16
|
} from '../types'
|
|
17
|
-
import { propGetter, memo
|
|
17
|
+
import { propGetter, memo } from '../utils'
|
|
18
18
|
import { ColumnSizing } from './ColumnSizing'
|
|
19
19
|
|
|
20
20
|
export type HeadersRow<TGenerics extends PartialGenerics> = {
|
|
@@ -224,9 +224,21 @@ export const Headers = {
|
|
|
224
224
|
getFooterProps: userProps =>
|
|
225
225
|
instance.getFooterProps(header.id, userProps)!,
|
|
226
226
|
renderHeader: () =>
|
|
227
|
-
|
|
227
|
+
column.header
|
|
228
|
+
? instance.render(column.header, {
|
|
229
|
+
instance,
|
|
230
|
+
header: header as Header<TGenerics>,
|
|
231
|
+
column,
|
|
232
|
+
})
|
|
233
|
+
: null,
|
|
228
234
|
renderFooter: () =>
|
|
229
|
-
|
|
235
|
+
column.footer
|
|
236
|
+
? instance.render(column.footer, {
|
|
237
|
+
instance,
|
|
238
|
+
header: header as Header<TGenerics>,
|
|
239
|
+
column,
|
|
240
|
+
})
|
|
241
|
+
: null,
|
|
230
242
|
}
|
|
231
243
|
|
|
232
244
|
// Yes, we have to convert instance to unknown, because we know more than the compiler here.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React, { MouseEvent, TouchEvent } from 'react'
|
|
2
1
|
import {
|
|
3
2
|
Getter,
|
|
4
3
|
OnChangeFn,
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
Row,
|
|
9
8
|
RowModel,
|
|
10
9
|
Updater,
|
|
10
|
+
AnyGenerics,
|
|
11
11
|
} from '../types'
|
|
12
12
|
import { functionalUpdate, makeStateUpdater, memo, propGetter } from '../utils'
|
|
13
13
|
|
|
@@ -581,7 +581,7 @@ const mutateRowIsSelected = <TGenerics extends PartialGenerics>(
|
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
-
export function selectRowsFn<TGenerics extends
|
|
584
|
+
export function selectRowsFn<TGenerics extends AnyGenerics>(
|
|
585
585
|
instance: TableInstance<TGenerics>,
|
|
586
586
|
rowModel: RowModel<TGenerics>
|
|
587
587
|
): RowModel<TGenerics> {
|