@tanstack/table-core 8.0.0-alpha.24 → 8.0.0-alpha.27
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 +10 -21
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +9 -4
- 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.map +1 -1
- package/build/cjs/features/Filters.js.map +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.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/groupRowsFn.js.map +1 -1
- package/build/cjs/utils.js +5 -4
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2613 -2602
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +350 -336
- package/build/types/core.d.ts +9 -12
- 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 +14 -14
- 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/umd/index.development.js +2620 -2611
- 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 +35 -51
- package/src/createTable.tsx +20 -13
- package/src/features/ColumnSizing.ts +31 -7
- package/src/features/Expanding.ts +5 -5
- package/src/features/Filters.ts +13 -13
- package/src/features/Grouping.ts +16 -15
- 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 +8 -8
- 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/groupRowsFn.ts +1 -1
- package/src/utils.tsx +1 -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.27",
|
|
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
|
@@ -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,7 +148,7 @@ 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']
|
|
@@ -161,13 +162,10 @@ export type CoreRow<TGenerics extends PartialGenerics> = {
|
|
|
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,11 +197,14 @@ export type CoreColumnDef<TGenerics extends PartialGenerics> = {
|
|
|
199
197
|
}
|
|
200
198
|
// & GeneratedProperties<true>
|
|
201
199
|
|
|
202
|
-
export type
|
|
200
|
+
export type CoreColumnDefType = 'data' | 'display' | 'group'
|
|
201
|
+
|
|
202
|
+
export type CoreColumn<TGenerics extends AnyGenerics> = {
|
|
203
203
|
id: string
|
|
204
204
|
depth: number
|
|
205
205
|
accessorFn?: AccessorFn<TGenerics['Row']>
|
|
206
206
|
columnDef: ColumnDef<TGenerics>
|
|
207
|
+
columnDefType: CoreColumnDefType
|
|
207
208
|
getWidth: () => number
|
|
208
209
|
columns: Column<TGenerics>[]
|
|
209
210
|
parent?: Column<TGenerics>
|
|
@@ -211,7 +212,7 @@ export type CoreColumn<TGenerics extends PartialGenerics> = {
|
|
|
211
212
|
getLeafColumns: () => Column<TGenerics>[]
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
export function createTableInstance<TGenerics extends
|
|
215
|
+
export function createTableInstance<TGenerics extends AnyGenerics>(
|
|
215
216
|
options: Options<TGenerics>
|
|
216
217
|
): TableInstance<TGenerics> {
|
|
217
218
|
if (options.debugAll || options.debugTable) {
|
|
@@ -221,7 +222,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
221
222
|
let instance = {} as TableInstance<TGenerics>
|
|
222
223
|
|
|
223
224
|
const defaultOptions = features.reduce((obj, feature) => {
|
|
224
|
-
return Object.assign(obj,
|
|
225
|
+
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
225
226
|
}, {})
|
|
226
227
|
|
|
227
228
|
const buildOptions = (options: Options<TGenerics>) => ({
|
|
@@ -233,7 +234,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
233
234
|
|
|
234
235
|
const initialState = {
|
|
235
236
|
...features.reduce((obj, feature) => {
|
|
236
|
-
return Object.assign(obj,
|
|
237
|
+
return Object.assign(obj, feature.getInitialState?.())
|
|
237
238
|
}, {}),
|
|
238
239
|
...(options.initialState ?? {}),
|
|
239
240
|
} as TableState
|
|
@@ -241,7 +242,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
241
242
|
const finalInstance: TableInstance<TGenerics> = {
|
|
242
243
|
...instance,
|
|
243
244
|
...features.reduce((obj, feature) => {
|
|
244
|
-
return Object.assign(obj,
|
|
245
|
+
return Object.assign(obj, feature.getInstance?.(instance))
|
|
245
246
|
}, {}),
|
|
246
247
|
initialState,
|
|
247
248
|
reset: () => {
|
|
@@ -288,7 +289,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
288
289
|
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
289
290
|
typeof value === 'boolean' ? value.toString() : value,
|
|
290
291
|
...features.reduce((obj, feature) => {
|
|
291
|
-
return Object.assign(obj,
|
|
292
|
+
return Object.assign(obj, feature.getDefaultColumn?.())
|
|
292
293
|
}, {}),
|
|
293
294
|
...defaultColumn,
|
|
294
295
|
} as Partial<ColumnDef<TGenerics>>
|
|
@@ -301,7 +302,11 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
301
302
|
|
|
302
303
|
getColumnDefs: () => instance.options.columns,
|
|
303
304
|
|
|
304
|
-
createColumn: (
|
|
305
|
+
createColumn: (
|
|
306
|
+
columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
|
|
307
|
+
depth: number,
|
|
308
|
+
parent
|
|
309
|
+
) => {
|
|
305
310
|
const defaultColumn = instance.getDefaultColumn()
|
|
306
311
|
|
|
307
312
|
let id =
|
|
@@ -330,7 +335,6 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
330
335
|
}
|
|
331
336
|
|
|
332
337
|
let column: CoreColumn<TGenerics> = {
|
|
333
|
-
...defaultColumnSizing,
|
|
334
338
|
...defaultColumn,
|
|
335
339
|
...columnDef,
|
|
336
340
|
id: `${id}`,
|
|
@@ -338,6 +342,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
338
342
|
parent: parent as any,
|
|
339
343
|
depth,
|
|
340
344
|
columnDef,
|
|
345
|
+
columnDefType: columnDef.columnDefType as CoreColumnDefType,
|
|
341
346
|
columns: [],
|
|
342
347
|
getWidth: () => instance.getColumnWidth(column.id),
|
|
343
348
|
getFlatColumns: memo(
|
|
@@ -376,10 +381,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
376
381
|
}
|
|
377
382
|
|
|
378
383
|
column = features.reduce((obj, feature) => {
|
|
379
|
-
return Object.assign(
|
|
380
|
-
obj,
|
|
381
|
-
(feature as any).createColumn?.(column, instance)
|
|
382
|
-
)
|
|
384
|
+
return Object.assign(obj, feature.createColumn?.(column, instance))
|
|
383
385
|
}, column)
|
|
384
386
|
|
|
385
387
|
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
@@ -465,24 +467,6 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
465
467
|
return column
|
|
466
468
|
},
|
|
467
469
|
|
|
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
470
|
createCell: (row, column, value) => {
|
|
487
471
|
const cell: CoreCell<TGenerics> = {
|
|
488
472
|
id: `${row.id}_${column.id}`,
|
|
@@ -508,7 +492,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
508
492
|
features.forEach(feature => {
|
|
509
493
|
Object.assign(
|
|
510
494
|
cell,
|
|
511
|
-
|
|
495
|
+
feature.createCell?.(
|
|
512
496
|
cell as Cell<TGenerics>,
|
|
513
497
|
column,
|
|
514
498
|
row as Row<TGenerics>,
|
|
@@ -567,7 +551,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
567
551
|
|
|
568
552
|
for (let i = 0; i < features.length; i++) {
|
|
569
553
|
const feature = features[i]
|
|
570
|
-
Object.assign(row,
|
|
554
|
+
Object.assign(row, feature.createRow?.(row, instance))
|
|
571
555
|
}
|
|
572
556
|
|
|
573
557
|
return row as Row<TGenerics>
|
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!,
|
|
@@ -127,11 +133,12 @@ function _createTable<TGenerics extends PartialGenerics>(
|
|
|
127
133
|
},
|
|
128
134
|
},
|
|
129
135
|
createColumns: columns => columns,
|
|
130
|
-
createDisplayColumn: column => column
|
|
131
|
-
createGroup: column => column as any,
|
|
136
|
+
createDisplayColumn: column => ({ ...column, columnDefType: 'display' }),
|
|
137
|
+
createGroup: column => ({ ...column, columnDefType: 'group' } as any),
|
|
132
138
|
createDataColumn: (accessor, column): any => {
|
|
133
139
|
column = {
|
|
134
140
|
...column,
|
|
141
|
+
columnDefType: 'data',
|
|
135
142
|
id: column.id,
|
|
136
143
|
}
|
|
137
144
|
|
|
@@ -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 => {
|
package/src/features/Filters.ts
CHANGED
|
@@ -24,17 +24,17 @@ export type ColumnFilter = {
|
|
|
24
24
|
|
|
25
25
|
export type ColumnFiltersState = ColumnFilter[]
|
|
26
26
|
|
|
27
|
-
export type FilterFn<TGenerics extends
|
|
27
|
+
export type FilterFn<TGenerics extends AnyGenerics> = {
|
|
28
28
|
(rows: Row<TGenerics>[], columnIds: string[], filterValue: any): any
|
|
29
29
|
autoRemove?: ColumnFilterAutoRemoveTestFn<TGenerics>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export type ColumnFilterAutoRemoveTestFn<TGenerics extends
|
|
32
|
+
export type ColumnFilterAutoRemoveTestFn<TGenerics extends AnyGenerics> = (
|
|
33
33
|
value: unknown,
|
|
34
34
|
column?: Column<TGenerics>
|
|
35
35
|
) => boolean
|
|
36
36
|
|
|
37
|
-
export type CustomFilterTypes<TGenerics extends
|
|
37
|
+
export type CustomFilterTypes<TGenerics extends AnyGenerics> = Record<
|
|
38
38
|
string,
|
|
39
39
|
FilterFn<TGenerics>
|
|
40
40
|
>
|
|
@@ -44,13 +44,13 @@ export type FiltersTableState = {
|
|
|
44
44
|
globalFilter: any
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export type FilterType<TGenerics extends
|
|
47
|
+
export type FilterType<TGenerics extends AnyGenerics> =
|
|
48
48
|
| 'auto'
|
|
49
49
|
| BuiltInFilterType
|
|
50
50
|
| TGenerics['FilterFns']
|
|
51
51
|
| FilterFn<TGenerics>
|
|
52
52
|
|
|
53
|
-
export type FiltersColumnDef<TGenerics extends
|
|
53
|
+
export type FiltersColumnDef<TGenerics extends AnyGenerics> = {
|
|
54
54
|
filterType?: FilterType<Overwrite<TGenerics, { Value: any }>>
|
|
55
55
|
enableAllFilters?: boolean
|
|
56
56
|
enableColumnFilter?: boolean
|
|
@@ -60,7 +60,7 @@ export type FiltersColumnDef<TGenerics extends PartialGenerics> = {
|
|
|
60
60
|
defaultCanGlobalFilter?: boolean
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export type FiltersColumn<TGenerics extends
|
|
63
|
+
export type FiltersColumn<TGenerics extends AnyGenerics> = {
|
|
64
64
|
filterType: FilterType<Overwrite<TGenerics, { Value: any }>>
|
|
65
65
|
getCanColumnFilter: () => boolean
|
|
66
66
|
getCanGlobalFilter: () => boolean
|
|
@@ -73,7 +73,7 @@ export type FiltersColumn<TGenerics extends PartialGenerics> = {
|
|
|
73
73
|
getPreFilteredMinMaxValues: () => [any, any]
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export type FiltersOptions<TGenerics extends
|
|
76
|
+
export type FiltersOptions<TGenerics extends AnyGenerics> = {
|
|
77
77
|
filterFromLeafRows?: boolean
|
|
78
78
|
filterTypes?: TGenerics['FilterFns']
|
|
79
79
|
enableFilters?: boolean
|
|
@@ -98,7 +98,7 @@ export type FiltersOptions<TGenerics extends PartialGenerics> = {
|
|
|
98
98
|
getColumnCanGlobalFilterFn?: (column: Column<TGenerics>) => boolean
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export type FiltersInstance<TGenerics extends
|
|
101
|
+
export type FiltersInstance<TGenerics extends AnyGenerics> = {
|
|
102
102
|
_notifyFiltersReset: () => void
|
|
103
103
|
getColumnAutoFilterFn: (columnId: string) => FilterFn<TGenerics> | undefined
|
|
104
104
|
|
|
@@ -135,7 +135,7 @@ export type FiltersInstance<TGenerics extends PartialGenerics> = {
|
|
|
135
135
|
|
|
136
136
|
export const Filters = {
|
|
137
137
|
getDefaultColumn: <
|
|
138
|
-
TGenerics extends
|
|
138
|
+
TGenerics extends AnyGenerics
|
|
139
139
|
>(): FiltersColumnDef<TGenerics> => {
|
|
140
140
|
return {
|
|
141
141
|
filterType: 'auto',
|
|
@@ -149,7 +149,7 @@ export const Filters = {
|
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
151
|
|
|
152
|
-
getDefaultOptions: <TGenerics extends
|
|
152
|
+
getDefaultOptions: <TGenerics extends AnyGenerics>(
|
|
153
153
|
instance: TableInstance<TGenerics>
|
|
154
154
|
): FiltersOptions<TGenerics> => {
|
|
155
155
|
return {
|
|
@@ -169,7 +169,7 @@ export const Filters = {
|
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
171
|
|
|
172
|
-
createColumn: <TGenerics extends
|
|
172
|
+
createColumn: <TGenerics extends AnyGenerics>(
|
|
173
173
|
column: Column<TGenerics>,
|
|
174
174
|
instance: TableInstance<TGenerics>
|
|
175
175
|
): FiltersColumn<TGenerics> => {
|
|
@@ -228,7 +228,7 @@ export const Filters = {
|
|
|
228
228
|
}
|
|
229
229
|
},
|
|
230
230
|
|
|
231
|
-
getInstance: <TGenerics extends
|
|
231
|
+
getInstance: <TGenerics extends AnyGenerics>(
|
|
232
232
|
instance: TableInstance<TGenerics>
|
|
233
233
|
): FiltersInstance<TGenerics> => {
|
|
234
234
|
let registered = false
|
|
@@ -553,7 +553,7 @@ export const Filters = {
|
|
|
553
553
|
},
|
|
554
554
|
}
|
|
555
555
|
|
|
556
|
-
export function shouldAutoRemoveFilter<TGenerics extends
|
|
556
|
+
export function shouldAutoRemoveFilter<TGenerics extends AnyGenerics>(
|
|
557
557
|
filterFn?: FilterFn<TGenerics>,
|
|
558
558
|
value?: any,
|
|
559
559
|
column?: Column<TGenerics>
|