@tanstack/table-core 8.0.0-alpha.58 → 8.0.0-alpha.59
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 +3 -3
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +0 -15
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +8 -19
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Expanding.js +11 -19
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Grouping.js +6 -9
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +1 -67
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Pagination.js +3 -3
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +15 -47
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +0 -15
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +7 -10
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +8 -21
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +16 -0
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils.js +0 -16
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +90 -266
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +346 -346
- package/build/types/core.d.ts +8 -10
- package/build/types/createTable.d.ts +10 -11
- package/build/types/features/Cells.d.ts +1 -2
- package/build/types/features/ColumnSizing.d.ts +4 -18
- package/build/types/features/Expanding.d.ts +4 -8
- package/build/types/features/Grouping.d.ts +4 -8
- package/build/types/features/Headers.d.ts +1 -5
- package/build/types/features/Pagination.d.ts +5 -6
- package/build/types/features/RowSelection.d.ts +5 -12
- package/build/types/features/Rows.d.ts +2 -4
- package/build/types/features/Sorting.d.ts +3 -7
- package/build/types/features/Visibility.d.ts +3 -6
- package/build/types/filterFns.d.ts +5 -0
- package/build/types/types.d.ts +10 -60
- package/build/types/utils.d.ts +1 -4
- package/build/umd/index.development.js +89 -266
- 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.ts +28 -52
- package/src/createTable.ts +13 -17
- package/src/features/Cells.ts +1 -27
- package/src/features/ColumnSizing.ts +14 -44
- package/src/features/Columns.ts +0 -2
- package/src/features/Expanding.ts +14 -40
- package/src/features/Grouping.ts +10 -37
- package/src/features/Headers.ts +1 -95
- package/src/features/Pagination.ts +8 -2
- package/src/features/Pinning.ts +1 -1
- package/src/features/RowSelection.ts +25 -87
- package/src/features/Rows.ts +2 -30
- package/src/features/Sorting.ts +17 -41
- package/src/features/Visibility.ts +15 -43
- package/src/filterFns.ts +20 -0
- package/src/types.ts +36 -98
- package/src/utils/getColumnFilteredRowModelAsync.ts +1 -5
- package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -6
- package/src/utils/getSortedRowModelAsync.ts +0 -1
- package/src/utils.ts +1 -28
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.59",
|
|
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.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { functionalUpdate,
|
|
1
|
+
import { functionalUpdate, RequiredKeys } from './utils'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Updater,
|
|
5
|
-
|
|
5
|
+
TableOptions,
|
|
6
6
|
TableState,
|
|
7
|
-
ColumnDef,
|
|
8
|
-
TableProps,
|
|
9
|
-
TableBodyProps,
|
|
10
|
-
PropGetter,
|
|
11
7
|
TableInstance,
|
|
12
8
|
Renderable,
|
|
13
|
-
UseRenderer,
|
|
14
9
|
TableFeature,
|
|
15
10
|
TableGenerics,
|
|
11
|
+
InitialTableState,
|
|
16
12
|
} from './types'
|
|
17
13
|
|
|
18
14
|
import { Columns } from './features/Columns'
|
|
@@ -40,42 +36,38 @@ export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
40
36
|
data: TGenerics['Row'][]
|
|
41
37
|
state: Partial<TableState>
|
|
42
38
|
onStateChange: (updater: Updater<TableState>) => void
|
|
43
|
-
render: TGenerics['
|
|
39
|
+
render: TGenerics['Renderer']
|
|
44
40
|
debugAll?: boolean
|
|
45
41
|
debugTable?: boolean
|
|
46
42
|
debugHeaders?: boolean
|
|
47
43
|
debugColumns?: boolean
|
|
48
44
|
debugRows?: boolean
|
|
49
|
-
initialState?:
|
|
45
|
+
initialState?: InitialTableState
|
|
50
46
|
autoResetAll?: boolean
|
|
51
|
-
mergeOptions?: (
|
|
52
|
-
defaultOptions: TableFeature,
|
|
53
|
-
options: Partial<Options<TGenerics>>
|
|
54
|
-
) => Options<TGenerics>
|
|
47
|
+
mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
|
|
55
48
|
meta?: TGenerics['TableMeta']
|
|
56
49
|
}
|
|
57
50
|
|
|
58
51
|
export type TableCore<TGenerics extends TableGenerics> = {
|
|
52
|
+
// generics: TGenerics
|
|
59
53
|
initialState: TableState
|
|
60
54
|
reset: () => void
|
|
61
|
-
options: RequiredKeys<
|
|
62
|
-
setOptions: (newOptions: Updater<
|
|
55
|
+
options: RequiredKeys<TableOptions<TGenerics>, 'state'>
|
|
56
|
+
setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void
|
|
63
57
|
queue: (cb: () => void) => void
|
|
64
58
|
willUpdate: () => void
|
|
65
59
|
getState: () => TableState
|
|
66
60
|
setState: (updater: Updater<TableState>) => void
|
|
67
|
-
getTableProps: PropGetter<TableProps>
|
|
68
|
-
getTableBodyProps: PropGetter<TableBodyProps>
|
|
69
61
|
render: <TProps>(
|
|
70
62
|
template: Renderable<TGenerics, TProps>,
|
|
71
63
|
props: TProps
|
|
72
|
-
) => string | null |
|
|
64
|
+
) => string | null | TGenerics['Rendered']
|
|
73
65
|
getOverallProgress: () => number
|
|
74
66
|
_features: readonly TableFeature[]
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
export function createTableInstance<TGenerics extends TableGenerics>(
|
|
78
|
-
options:
|
|
70
|
+
options: TableOptions<TGenerics>
|
|
79
71
|
): TableInstance<TGenerics> {
|
|
80
72
|
if (options.debugAll || options.debugTable) {
|
|
81
73
|
console.info('Creating Table Instance...')
|
|
@@ -102,14 +94,23 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
102
94
|
|
|
103
95
|
const defaultOptions = instance._features.reduce((obj, feature) => {
|
|
104
96
|
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
105
|
-
}, {})
|
|
97
|
+
}, {}) as TableOptions<TGenerics>
|
|
106
98
|
|
|
107
|
-
const
|
|
99
|
+
const mergeOptions = (options: TableOptions<TGenerics>) => {
|
|
100
|
+
if (instance.options.mergeOptions) {
|
|
101
|
+
return instance.options.mergeOptions(defaultOptions, options)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
...defaultOptions,
|
|
106
|
+
...options,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
instance.options = {
|
|
108
111
|
...defaultOptions,
|
|
109
112
|
...options,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
instance.options = buildOptions(options)
|
|
113
|
+
}
|
|
113
114
|
|
|
114
115
|
const coreInitialState: CoreTableState = {
|
|
115
116
|
coreProgress: 1,
|
|
@@ -117,10 +118,10 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
117
118
|
|
|
118
119
|
const initialState = {
|
|
119
120
|
...coreInitialState,
|
|
121
|
+
...(options.initialState ?? {}),
|
|
120
122
|
...instance._features.reduce((obj, feature) => {
|
|
121
|
-
return Object.assign(obj, feature.getInitialState?.())
|
|
123
|
+
return Object.assign(obj, feature.getInitialState?.(options.initialState))
|
|
122
124
|
}, {}),
|
|
123
|
-
...(options.initialState ?? {}),
|
|
124
125
|
} as TableState
|
|
125
126
|
|
|
126
127
|
const queued: (() => void)[] = []
|
|
@@ -151,14 +152,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
151
152
|
},
|
|
152
153
|
setOptions: updater => {
|
|
153
154
|
const newOptions = functionalUpdate(updater, instance.options)
|
|
154
|
-
|
|
155
|
-
instance.options = instance.options.mergeOptions(
|
|
156
|
-
defaultOptions,
|
|
157
|
-
newOptions
|
|
158
|
-
)
|
|
159
|
-
} else {
|
|
160
|
-
instance.options = buildOptions(newOptions)
|
|
161
|
-
}
|
|
155
|
+
instance.options = mergeOptions(newOptions)
|
|
162
156
|
},
|
|
163
157
|
render: (template, props) => {
|
|
164
158
|
if (typeof instance.options.render === 'function') {
|
|
@@ -180,24 +174,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
180
174
|
instance.options.onStateChange?.(updater)
|
|
181
175
|
},
|
|
182
176
|
|
|
183
|
-
getTableProps: userProps => {
|
|
184
|
-
return propGetter(
|
|
185
|
-
{
|
|
186
|
-
role: 'table',
|
|
187
|
-
},
|
|
188
|
-
userProps
|
|
189
|
-
)
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
getTableBodyProps: userProps => {
|
|
193
|
-
return propGetter(
|
|
194
|
-
{
|
|
195
|
-
role: 'rowgroup',
|
|
196
|
-
},
|
|
197
|
-
userProps
|
|
198
|
-
)
|
|
199
|
-
},
|
|
200
|
-
|
|
201
177
|
getOverallProgress: () => {
|
|
202
178
|
const { coreProgress, columnFiltersProgress, globalFilterProgress } =
|
|
203
179
|
instance.getState()
|
package/src/createTable.ts
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
AccessorFn,
|
|
7
7
|
AnyRender,
|
|
8
8
|
TableGenerics,
|
|
9
|
-
|
|
9
|
+
TableOptions,
|
|
10
10
|
} from './types'
|
|
11
|
-
import { IfDefined, Overwrite
|
|
11
|
+
import { IfDefined, Overwrite } from './utils'
|
|
12
12
|
|
|
13
13
|
export type TableFactory<TGenerics extends TableGenerics> =
|
|
14
14
|
() => Table<TGenerics>
|
|
@@ -25,12 +25,16 @@ export type CreateTableOptions<
|
|
|
25
25
|
filterFns?: TFilterFns
|
|
26
26
|
sortingFns?: TSortingFns
|
|
27
27
|
aggregationFns?: TAggregationFns
|
|
28
|
-
} & Omit<
|
|
28
|
+
} & Omit<
|
|
29
|
+
TableOptions<TGenerics>,
|
|
30
|
+
'filterFns' | 'sortingFns' | 'aggregationFns'
|
|
31
|
+
>
|
|
29
32
|
>
|
|
30
33
|
|
|
31
34
|
export type Table<TGenerics extends TableGenerics> = {
|
|
32
35
|
generics: TGenerics
|
|
33
|
-
options: Partial<
|
|
36
|
+
options: Partial<TableOptions<TGenerics>>
|
|
37
|
+
setGenerics: <T extends TableGenerics>() => Table<T>
|
|
34
38
|
setRowType: <TRow>() => Table<Overwrite<TGenerics, { Row: TRow }>>
|
|
35
39
|
setTableMetaType: <TTableMeta>() => Table<
|
|
36
40
|
Overwrite<TGenerics, { TableMeta: TTableMeta }>
|
|
@@ -60,9 +64,6 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
60
64
|
}
|
|
61
65
|
>
|
|
62
66
|
>
|
|
63
|
-
createColumns: <TColumnDef extends ColumnDef<any>>(
|
|
64
|
-
columns: TColumnDef[]
|
|
65
|
-
) => TColumnDef[]
|
|
66
67
|
createGroup: (
|
|
67
68
|
column: Overwrite<
|
|
68
69
|
| Overwrite<
|
|
@@ -87,12 +88,7 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
87
88
|
>
|
|
88
89
|
) => ColumnDef<TGenerics>
|
|
89
90
|
createDisplayColumn: (
|
|
90
|
-
column:
|
|
91
|
-
PartialKeys<ColumnDef<TGenerics>, 'accessorFn' | 'accessorKey'>,
|
|
92
|
-
{
|
|
93
|
-
columns?: ColumnDef<any>[]
|
|
94
|
-
}
|
|
95
|
-
>
|
|
91
|
+
column: Omit<ColumnDef<TGenerics>, 'columns'>
|
|
96
92
|
) => ColumnDef<TGenerics>
|
|
97
93
|
createDataColumn: <
|
|
98
94
|
TAccessor extends AccessorFn<TGenerics['Row']> | keyof TGenerics['Row']
|
|
@@ -124,9 +120,9 @@ export type Table<TGenerics extends TableGenerics> = {
|
|
|
124
120
|
|
|
125
121
|
//
|
|
126
122
|
|
|
127
|
-
export function createTableFactory<
|
|
128
|
-
render:
|
|
129
|
-
}): () => Table<{
|
|
123
|
+
export function createTableFactory<TRenderer extends AnyRender>(opts: {
|
|
124
|
+
render: TRenderer
|
|
125
|
+
}): () => Table<{ Renderer: TRenderer; Rendered: ReturnType<TRenderer> }> {
|
|
130
126
|
return () => createTable(undefined, undefined, opts)
|
|
131
127
|
}
|
|
132
128
|
|
|
@@ -144,6 +140,7 @@ function createTable<TGenerics extends TableGenerics>(
|
|
|
144
140
|
throw new Error('')
|
|
145
141
|
})(),
|
|
146
142
|
},
|
|
143
|
+
setGenerics: () => table as any,
|
|
147
144
|
setRowType: () => table as any,
|
|
148
145
|
setTableMetaType: () => table as any,
|
|
149
146
|
setColumnMetaType: () => table as any,
|
|
@@ -152,7 +149,6 @@ function createTable<TGenerics extends TableGenerics>(
|
|
|
152
149
|
...options,
|
|
153
150
|
...newOptions,
|
|
154
151
|
} as any),
|
|
155
|
-
createColumns: columns => columns,
|
|
156
152
|
createDisplayColumn: column => ({ ...column, columnDefType: 'display' }),
|
|
157
153
|
createGroup: column => ({ ...column, columnDefType: 'group' } as any),
|
|
158
154
|
createDataColumn: (accessor, column): any => {
|
package/src/features/Cells.ts
CHANGED
|
@@ -5,11 +5,8 @@ import {
|
|
|
5
5
|
Row,
|
|
6
6
|
Column,
|
|
7
7
|
CoreCell,
|
|
8
|
-
Getter,
|
|
9
|
-
CellProps,
|
|
10
|
-
PropGetterValue,
|
|
11
8
|
} from '../types'
|
|
12
|
-
import { memo
|
|
9
|
+
import { memo } from '../utils'
|
|
13
10
|
|
|
14
11
|
export type CellsRow<TGenerics extends TableGenerics> = {
|
|
15
12
|
getAllCells: () => Cell<TGenerics>[]
|
|
@@ -23,11 +20,6 @@ export type CellsInstance<TGenerics extends TableGenerics> = {
|
|
|
23
20
|
value: any
|
|
24
21
|
) => Cell<TGenerics>
|
|
25
22
|
getCell: (rowId: string, columnId: string) => Cell<TGenerics>
|
|
26
|
-
getCellProps: <TGetter extends Getter<CellProps>>(
|
|
27
|
-
rowId: string,
|
|
28
|
-
columnId: string,
|
|
29
|
-
userProps?: TGetter
|
|
30
|
-
) => undefined | PropGetterValue<CellProps, TGetter>
|
|
31
23
|
}
|
|
32
24
|
|
|
33
25
|
//
|
|
@@ -83,8 +75,6 @@ export const Cells = {
|
|
|
83
75
|
row,
|
|
84
76
|
column,
|
|
85
77
|
value,
|
|
86
|
-
getCellProps: userProps =>
|
|
87
|
-
instance.getCellProps(row.id, column.id, userProps)!,
|
|
88
78
|
renderCell: () =>
|
|
89
79
|
column.cell
|
|
90
80
|
? instance.render(column.cell, {
|
|
@@ -135,22 +125,6 @@ export const Cells = {
|
|
|
135
125
|
|
|
136
126
|
return cell
|
|
137
127
|
},
|
|
138
|
-
|
|
139
|
-
getCellProps: (rowId, columnId, userProps) => {
|
|
140
|
-
const cell = instance.getCell(rowId, columnId)
|
|
141
|
-
|
|
142
|
-
if (!cell) {
|
|
143
|
-
return
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return propGetter(
|
|
147
|
-
{
|
|
148
|
-
key: cell.id,
|
|
149
|
-
role: 'gridcell',
|
|
150
|
-
},
|
|
151
|
-
userProps
|
|
152
|
-
)
|
|
153
|
-
},
|
|
154
128
|
}
|
|
155
129
|
},
|
|
156
130
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Column,
|
|
3
|
-
Getter,
|
|
4
3
|
Header,
|
|
5
4
|
OnChangeFn,
|
|
6
5
|
TableGenerics,
|
|
7
|
-
PropGetterValue,
|
|
8
6
|
TableInstance,
|
|
9
7
|
Updater,
|
|
8
|
+
TableFeature,
|
|
10
9
|
} from '../types'
|
|
11
|
-
import { makeStateUpdater
|
|
10
|
+
import { makeStateUpdater } from '../utils'
|
|
12
11
|
import { ColumnPinningPosition } from './Pinning'
|
|
13
12
|
|
|
14
13
|
//
|
|
@@ -44,14 +43,6 @@ export type ColumnSizingDefaultOptions = {
|
|
|
44
43
|
onColumnSizingInfoChange: OnChangeFn<ColumnSizingInfoState>
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
export type ColumnResizerProps = {
|
|
48
|
-
title?: string
|
|
49
|
-
onMouseDown?: (e: MouseEvent) => void
|
|
50
|
-
onTouchStart?: (e: TouchEvent) => void
|
|
51
|
-
draggable?: boolean
|
|
52
|
-
role?: string
|
|
53
|
-
}
|
|
54
|
-
|
|
55
46
|
export type ColumnSizingInstance<TGenerics extends TableGenerics> = {
|
|
56
47
|
getColumnSize: (columnId: string) => number
|
|
57
48
|
getColumnStart: (columnId: string, position?: ColumnPinningPosition) => number
|
|
@@ -63,10 +54,7 @@ export type ColumnSizingInstance<TGenerics extends TableGenerics> = {
|
|
|
63
54
|
resetHeaderSizeInfo: () => void
|
|
64
55
|
getColumnCanResize: (columnId: string) => boolean
|
|
65
56
|
getHeaderCanResize: (headerId: string) => boolean
|
|
66
|
-
|
|
67
|
-
headerId: string,
|
|
68
|
-
userProps?: TGetter
|
|
69
|
-
) => undefined | PropGetterValue<ColumnResizerProps, TGetter>
|
|
57
|
+
getResizeHandler: (headerId: string) => (event: unknown) => void
|
|
70
58
|
getColumnIsResizing: (columnId: string) => boolean
|
|
71
59
|
getHeaderIsResizing: (headerId: string) => boolean
|
|
72
60
|
getTotalSize: () => number
|
|
@@ -94,9 +82,7 @@ export type ColumnSizingColumn<TGenerics extends TableGenerics> = {
|
|
|
94
82
|
export type ColumnSizingHeader<TGenerics extends TableGenerics> = {
|
|
95
83
|
getCanResize: () => boolean
|
|
96
84
|
getIsResizing: () => boolean
|
|
97
|
-
|
|
98
|
-
userProps?: TGetter
|
|
99
|
-
) => undefined | PropGetterValue<ColumnResizerProps, TGetter>
|
|
85
|
+
getResizeHandler: () => (event: unknown) => void
|
|
100
86
|
resetSize: () => void
|
|
101
87
|
}
|
|
102
88
|
|
|
@@ -108,7 +94,7 @@ export const defaultColumnSizing = {
|
|
|
108
94
|
maxSize: Number.MAX_SAFE_INTEGER,
|
|
109
95
|
}
|
|
110
96
|
|
|
111
|
-
export const ColumnSizing = {
|
|
97
|
+
export const ColumnSizing: TableFeature = {
|
|
112
98
|
getDefaultColumn: (): ColumnSizingColumnDef => {
|
|
113
99
|
return defaultColumnSizing
|
|
114
100
|
},
|
|
@@ -157,8 +143,7 @@ export const ColumnSizing = {
|
|
|
157
143
|
getIsResizing: () => instance.getColumnIsResizing(header.column.id),
|
|
158
144
|
getCanResize: () => instance.getColumnCanResize(header.column.id),
|
|
159
145
|
resetSize: () => instance.resetColumnSize(header.column.id),
|
|
160
|
-
|
|
161
|
-
instance.getHeaderResizerProps(header.id, userProps),
|
|
146
|
+
getResizeHandler: () => instance.getResizeHandler(header.id),
|
|
162
147
|
}
|
|
163
148
|
},
|
|
164
149
|
|
|
@@ -274,14 +259,18 @@ export const ColumnSizing = {
|
|
|
274
259
|
|
|
275
260
|
return instance.getColumnIsResizing(header.column.id)
|
|
276
261
|
},
|
|
277
|
-
|
|
278
|
-
getHeaderResizerProps: (headerId, userProps) => {
|
|
262
|
+
getResizeHandler: (headerId: string) => {
|
|
279
263
|
const header = instance.getHeader(headerId)
|
|
280
264
|
const column = instance.getColumn(header.column.id)
|
|
281
|
-
|
|
282
265
|
const canResize = column.getCanResize()
|
|
283
266
|
|
|
284
|
-
|
|
267
|
+
return (e: unknown) => {
|
|
268
|
+
if (!canResize) {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
;(e as any).persist?.()
|
|
273
|
+
|
|
285
274
|
if (isTouchStartEvent(e)) {
|
|
286
275
|
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
287
276
|
if (e.touches && e.touches.length > 1) {
|
|
@@ -427,26 +416,7 @@ export const ColumnSizing = {
|
|
|
427
416
|
isResizingColumn: column.id,
|
|
428
417
|
}))
|
|
429
418
|
}
|
|
430
|
-
|
|
431
|
-
const initialProps: ColumnResizerProps = canResize
|
|
432
|
-
? {
|
|
433
|
-
title: 'Toggle Grouping',
|
|
434
|
-
draggable: false,
|
|
435
|
-
role: 'separator',
|
|
436
|
-
onMouseDown: (e: MouseEvent) => {
|
|
437
|
-
;(e as any).persist?.()
|
|
438
|
-
onResizeStart(e)
|
|
439
|
-
},
|
|
440
|
-
onTouchStart: (e: TouchEvent) => {
|
|
441
|
-
;(e as any).persist?.()
|
|
442
|
-
onResizeStart(e)
|
|
443
|
-
},
|
|
444
|
-
}
|
|
445
|
-
: {}
|
|
446
|
-
|
|
447
|
-
return propGetter(initialProps, userProps)
|
|
448
419
|
},
|
|
449
|
-
|
|
450
420
|
getTotalSize: () =>
|
|
451
421
|
instance.getHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
452
422
|
return sum + header.getSize()
|
package/src/features/Columns.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { features } from 'process'
|
|
2
1
|
import {
|
|
3
2
|
Cell,
|
|
4
3
|
Column,
|
|
@@ -12,7 +11,6 @@ import {
|
|
|
12
11
|
HeaderRenderProps,
|
|
13
12
|
} from '../types'
|
|
14
13
|
import { memo } from '../utils'
|
|
15
|
-
import { ColumnPinningPosition } from './Pinning'
|
|
16
14
|
|
|
17
15
|
export type CoreColumnDefType = 'data' | 'display' | 'group'
|
|
18
16
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
2
|
import {
|
|
3
|
-
Getter,
|
|
4
3
|
OnChangeFn,
|
|
5
4
|
TableGenerics,
|
|
6
|
-
PropGetterValue,
|
|
7
5
|
TableInstance,
|
|
8
6
|
Row,
|
|
9
7
|
Updater,
|
|
10
8
|
} from '../types'
|
|
11
|
-
import { makeStateUpdater
|
|
9
|
+
import { makeStateUpdater } from '../utils'
|
|
12
10
|
|
|
13
11
|
export type ExpandedStateList = Record<string, boolean>
|
|
14
12
|
export type ExpandedState = true | Record<string, boolean>
|
|
@@ -20,9 +18,7 @@ export type ExpandedRow = {
|
|
|
20
18
|
toggleExpanded: (expanded?: boolean) => void
|
|
21
19
|
getIsExpanded: () => boolean
|
|
22
20
|
getCanExpand: () => boolean
|
|
23
|
-
|
|
24
|
-
userProps?: TGetter
|
|
25
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
21
|
+
getToggleExpandedHandler: () => () => void
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
export type ExpandedOptions<TGenerics extends TableGenerics> = {
|
|
@@ -40,11 +36,6 @@ export type ExpandedOptions<TGenerics extends TableGenerics> = {
|
|
|
40
36
|
paginateExpandedRows?: boolean
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
export type ToggleExpandedProps = {
|
|
44
|
-
title?: string
|
|
45
|
-
onClick?: (event: unknown) => void
|
|
46
|
-
}
|
|
47
|
-
|
|
48
39
|
export type ExpandedInstance<TGenerics extends TableGenerics> = {
|
|
49
40
|
queueResetExpanded: () => void
|
|
50
41
|
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
@@ -54,13 +45,8 @@ export type ExpandedInstance<TGenerics extends TableGenerics> = {
|
|
|
54
45
|
getRowCanExpand: (rowId: string) => boolean
|
|
55
46
|
getCanSomeRowsExpand: () => boolean
|
|
56
47
|
getIsRowExpanded: (rowId: string) => boolean
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
userProps?: TGetter
|
|
60
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
61
|
-
getToggleAllRowsExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
|
|
62
|
-
userProps?: TGetter
|
|
63
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
48
|
+
getToggleExpandedHandler: (rowId: string) => undefined | (() => void)
|
|
49
|
+
getToggleAllRowsExpandedHandler: () => (event: unknown) => void
|
|
64
50
|
getIsSomeRowsExpanded: () => boolean
|
|
65
51
|
getIsAllRowsExpanded: () => boolean
|
|
66
52
|
getExpandedDepth: () => number
|
|
@@ -201,7 +187,7 @@ export const Expanding = {
|
|
|
201
187
|
instance.getRowCanExpand(id)
|
|
202
188
|
)
|
|
203
189
|
},
|
|
204
|
-
|
|
190
|
+
getToggleExpandedHandler: rowId => {
|
|
205
191
|
const row = instance.getRow(rowId)
|
|
206
192
|
|
|
207
193
|
if (!row) {
|
|
@@ -210,28 +196,16 @@ export const Expanding = {
|
|
|
210
196
|
|
|
211
197
|
const canExpand = instance.getRowCanExpand(rowId)
|
|
212
198
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
? (e: unknown) => {
|
|
217
|
-
;(e as any).persist?.()
|
|
218
|
-
instance.toggleRowExpanded(rowId)
|
|
219
|
-
}
|
|
220
|
-
: undefined,
|
|
199
|
+
return () => {
|
|
200
|
+
if (!canExpand) return
|
|
201
|
+
instance.toggleRowExpanded(rowId)
|
|
221
202
|
}
|
|
222
|
-
|
|
223
|
-
return propGetter(initialProps, userProps)
|
|
224
203
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
;(e as any).persist?.()
|
|
230
|
-
instance.toggleAllRowsExpanded()
|
|
231
|
-
},
|
|
204
|
+
getToggleAllRowsExpandedHandler: () => {
|
|
205
|
+
return (e: unknown) => {
|
|
206
|
+
;(e as any).persist?.()
|
|
207
|
+
instance.toggleAllRowsExpanded()
|
|
232
208
|
}
|
|
233
|
-
|
|
234
|
-
return propGetter(initialProps, userProps)
|
|
235
209
|
},
|
|
236
210
|
getIsSomeRowsExpanded: () => {
|
|
237
211
|
const expanded = instance.getState().expanded
|
|
@@ -303,8 +277,8 @@ export const Expanding = {
|
|
|
303
277
|
void instance.toggleRowExpanded(row.id, expanded),
|
|
304
278
|
getIsExpanded: () => instance.getIsRowExpanded(row.id),
|
|
305
279
|
getCanExpand: () => row.subRows && !!row.subRows.length,
|
|
306
|
-
|
|
307
|
-
instance.
|
|
280
|
+
getToggleExpandedHandler: () =>
|
|
281
|
+
instance.getToggleExpandedHandler(row.id)!,
|
|
308
282
|
}
|
|
309
283
|
},
|
|
310
284
|
}
|
package/src/features/Grouping.ts
CHANGED
|
@@ -3,24 +3,14 @@ import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
|
|
|
3
3
|
import {
|
|
4
4
|
Cell,
|
|
5
5
|
Column,
|
|
6
|
-
Getter,
|
|
7
6
|
OnChangeFn,
|
|
8
|
-
PropGetterValue,
|
|
9
7
|
TableInstance,
|
|
10
8
|
Row,
|
|
11
9
|
Updater,
|
|
12
10
|
Renderable,
|
|
13
|
-
UseRenderer,
|
|
14
11
|
TableGenerics,
|
|
15
12
|
} from '../types'
|
|
16
|
-
import {
|
|
17
|
-
functionalUpdate,
|
|
18
|
-
isFunction,
|
|
19
|
-
makeStateUpdater,
|
|
20
|
-
memo,
|
|
21
|
-
Overwrite,
|
|
22
|
-
propGetter,
|
|
23
|
-
} from '../utils'
|
|
13
|
+
import { isFunction, makeStateUpdater, Overwrite } from '../utils'
|
|
24
14
|
|
|
25
15
|
export type GroupingState = string[]
|
|
26
16
|
|
|
@@ -67,9 +57,7 @@ export type GroupingColumn<TGenerics extends TableGenerics> = {
|
|
|
67
57
|
getIsGrouped: () => boolean
|
|
68
58
|
getGroupedIndex: () => number
|
|
69
59
|
toggleGrouping: () => void
|
|
70
|
-
|
|
71
|
-
userProps?: TGetter
|
|
72
|
-
) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
|
|
60
|
+
getToggleGroupingHandler: () => () => void
|
|
73
61
|
}
|
|
74
62
|
|
|
75
63
|
export type GroupingRow = {
|
|
@@ -82,7 +70,7 @@ export type GroupingCell<TGenerics extends TableGenerics> = {
|
|
|
82
70
|
getIsGrouped: () => boolean
|
|
83
71
|
getIsPlaceholder: () => boolean
|
|
84
72
|
getIsAggregated: () => boolean
|
|
85
|
-
renderAggregatedCell: () => string | null |
|
|
73
|
+
renderAggregatedCell: () => string | null | TGenerics['Rendered']
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
export type ColumnDefaultOptions = {
|
|
@@ -108,11 +96,6 @@ export type GroupingOptions<TGenerics extends TableGenerics> = {
|
|
|
108
96
|
|
|
109
97
|
export type GroupingColumnMode = false | 'reorder' | 'remove'
|
|
110
98
|
|
|
111
|
-
export type ToggleGroupingProps = {
|
|
112
|
-
title?: string
|
|
113
|
-
onClick?: (event: unknown) => void
|
|
114
|
-
}
|
|
115
|
-
|
|
116
99
|
export type GroupingInstance<TGenerics extends TableGenerics> = {
|
|
117
100
|
queueResetGrouping: () => void
|
|
118
101
|
getColumnAutoAggregationFn: (
|
|
@@ -127,10 +110,7 @@ export type GroupingInstance<TGenerics extends TableGenerics> = {
|
|
|
127
110
|
getColumnCanGroup: (columnId: string) => boolean
|
|
128
111
|
getColumnIsGrouped: (columnId: string) => boolean
|
|
129
112
|
getColumnGroupedIndex: (columnId: string) => number
|
|
130
|
-
|
|
131
|
-
columnId: string,
|
|
132
|
-
userProps?: TGetter
|
|
133
|
-
) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
|
|
113
|
+
getToggleGroupingHandler: (columnId: string) => undefined | (() => void)
|
|
134
114
|
getRowIsGrouped: (rowId: string) => boolean
|
|
135
115
|
getPreGroupedRowModel: () => RowModel<TGenerics>
|
|
136
116
|
getGroupedRowModel: () => RowModel<TGenerics>
|
|
@@ -174,8 +154,8 @@ export const Grouping = {
|
|
|
174
154
|
getGroupedIndex: () => instance.getColumnGroupedIndex(column.id),
|
|
175
155
|
getIsGrouped: () => instance.getColumnIsGrouped(column.id),
|
|
176
156
|
toggleGrouping: () => instance.toggleColumnGrouping(column.id),
|
|
177
|
-
|
|
178
|
-
instance.
|
|
157
|
+
getToggleGroupingHandler: () =>
|
|
158
|
+
instance.getToggleGroupingHandler(column.id)!,
|
|
179
159
|
}
|
|
180
160
|
},
|
|
181
161
|
|
|
@@ -278,21 +258,14 @@ export const Grouping = {
|
|
|
278
258
|
instance.setGrouping(instance.initialState?.grouping ?? [])
|
|
279
259
|
},
|
|
280
260
|
|
|
281
|
-
|
|
261
|
+
getToggleGroupingHandler: columnId => {
|
|
282
262
|
const column = instance.getColumn(columnId)
|
|
283
|
-
|
|
284
263
|
const canGroup = column.getCanGroup()
|
|
285
264
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
? (e: unknown) => {
|
|
290
|
-
column.toggleGrouping?.()
|
|
291
|
-
}
|
|
292
|
-
: undefined,
|
|
265
|
+
return () => {
|
|
266
|
+
if (!canGroup) return
|
|
267
|
+
column.toggleGrouping?.()
|
|
293
268
|
}
|
|
294
|
-
|
|
295
|
-
return propGetter(initialProps, userProps)
|
|
296
269
|
},
|
|
297
270
|
|
|
298
271
|
getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
|