@tanstack/react-table 8.0.0-alpha.9 → 8.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/react-table/src/index.js +139 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3867 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3196 -4117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -813
- package/build/types/index.d.ts +16 -9
- package/build/umd/index.development.js +3234 -4125
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -6
- package/src/index.tsx +111 -9
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -122
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -318
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -239
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -414
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -232
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -629
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -193
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -526
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -315
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -174
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -44
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/cjs/utils.js +0 -167
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/createTable.d.ts +0 -42
- package/build/types/features/ColumnSizing.d.ts +0 -73
- package/build/types/features/Expanding.d.ts +0 -48
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -83
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -39
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -58
- package/build/types/features/Sorting.d.ts +0 -79
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -138
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/build/types/utils.d.ts +0 -23
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -186
- package/src/features/ColumnSizing.ts +0 -424
- package/src/features/Expanding.ts +0 -318
- package/src/features/Filters.ts +0 -560
- package/src/features/Grouping.ts +0 -361
- package/src/features/Headers.ts +0 -729
- package/src/features/Ordering.ts +0 -110
- package/src/features/Pagination.ts +0 -250
- package/src/features/Pinning.ts +0 -174
- package/src/features/RowSelection.ts +0 -651
- package/src/features/Sorting.ts +0 -453
- package/src/features/Visibility.ts +0 -238
- package/src/filterTypes.ts +0 -188
- package/src/sortTypes.ts +0 -147
- package/src/types.ts +0 -311
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
package/src/features/Ordering.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
TableInstance,
|
|
5
|
-
OnChangeFn,
|
|
6
|
-
Updater,
|
|
7
|
-
Column,
|
|
8
|
-
PartialGenerics,
|
|
9
|
-
} from '../types'
|
|
10
|
-
|
|
11
|
-
import * as Grouping from './Grouping'
|
|
12
|
-
|
|
13
|
-
export type ColumnOrderState = string[]
|
|
14
|
-
|
|
15
|
-
export type ColumnOrderTableState = {
|
|
16
|
-
columnOrder: ColumnOrderState
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type ColumnOrderOptions = {
|
|
20
|
-
onColumnOrderChange?: OnChangeFn<ColumnOrderState>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type ColumnOrderDefaultOptions = {
|
|
24
|
-
onColumnOrderChange: OnChangeFn<ColumnOrderState>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type ColumnOrderInstance<TGenerics extends PartialGenerics> = {
|
|
28
|
-
setColumnOrder: (updater: Updater<ColumnOrderState>) => void
|
|
29
|
-
resetColumnOrder: () => void
|
|
30
|
-
getOrderColumnsFn: () => (columns: Column<TGenerics>[]) => Column<TGenerics>[]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
export function getInitialState(): ColumnOrderTableState {
|
|
36
|
-
return {
|
|
37
|
-
columnOrder: [],
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getDefaultOptions<TGenerics extends PartialGenerics>(
|
|
42
|
-
instance: TableInstance<TGenerics>
|
|
43
|
-
): ColumnOrderDefaultOptions {
|
|
44
|
-
return {
|
|
45
|
-
onColumnOrderChange: makeStateUpdater('columnOrder', instance),
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getInstance<TGenerics extends PartialGenerics>(
|
|
50
|
-
instance: TableInstance<TGenerics>
|
|
51
|
-
): ColumnOrderInstance<TGenerics> {
|
|
52
|
-
return {
|
|
53
|
-
setColumnOrder: updater =>
|
|
54
|
-
instance.options.onColumnOrderChange?.(
|
|
55
|
-
updater,
|
|
56
|
-
functionalUpdate(updater, instance.getState().columnOrder)
|
|
57
|
-
),
|
|
58
|
-
resetColumnOrder: () => {
|
|
59
|
-
instance.setColumnOrder(instance.initialState.columnOrder ?? [])
|
|
60
|
-
},
|
|
61
|
-
getOrderColumnsFn: memo(
|
|
62
|
-
() => [
|
|
63
|
-
instance.getState().columnOrder,
|
|
64
|
-
instance.getState().grouping,
|
|
65
|
-
instance.options.groupedColumnMode,
|
|
66
|
-
],
|
|
67
|
-
(columnOrder, grouping, groupedColumnMode) => columns => {
|
|
68
|
-
// Sort grouped columns to the start of the column list
|
|
69
|
-
// before the headers are built
|
|
70
|
-
let orderedColumns: Column<TGenerics>[] = []
|
|
71
|
-
|
|
72
|
-
// If there is no order, return the normal columns
|
|
73
|
-
if (!columnOrder?.length) {
|
|
74
|
-
orderedColumns = columns
|
|
75
|
-
} else {
|
|
76
|
-
const columnOrderCopy = [...columnOrder]
|
|
77
|
-
|
|
78
|
-
// If there is an order, make a copy of the columns
|
|
79
|
-
const columnsCopy = [...columns]
|
|
80
|
-
|
|
81
|
-
// And make a new ordered array of the columns
|
|
82
|
-
|
|
83
|
-
// Loop over the columns and place them in order into the new array
|
|
84
|
-
while (columnsCopy.length && columnOrderCopy.length) {
|
|
85
|
-
const targetColumnId = columnOrderCopy.shift()
|
|
86
|
-
const foundIndex = columnsCopy.findIndex(
|
|
87
|
-
d => d.id === targetColumnId
|
|
88
|
-
)
|
|
89
|
-
if (foundIndex > -1) {
|
|
90
|
-
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]!)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If there are any columns left, add them to the end
|
|
95
|
-
orderedColumns = [...orderedColumns, ...columnsCopy]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return Grouping.orderColumns(
|
|
99
|
-
orderedColumns,
|
|
100
|
-
grouping,
|
|
101
|
-
groupedColumnMode
|
|
102
|
-
)
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
key: 'getOrderColumnsFn',
|
|
106
|
-
// debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
107
|
-
}
|
|
108
|
-
),
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Column,
|
|
3
|
-
OnChangeFn,
|
|
4
|
-
PartialGenerics,
|
|
5
|
-
TableInstance,
|
|
6
|
-
Row,
|
|
7
|
-
RowModel,
|
|
8
|
-
TableState,
|
|
9
|
-
Updater,
|
|
10
|
-
} from '../types'
|
|
11
|
-
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
12
|
-
|
|
13
|
-
export type PaginationState = {
|
|
14
|
-
pageIndex: number
|
|
15
|
-
pageSize: number
|
|
16
|
-
pageCount: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type PaginationTableState = {
|
|
20
|
-
pagination: PaginationState
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type PaginationOptions<TGenerics extends PartialGenerics> = {
|
|
24
|
-
onPaginationChange?: OnChangeFn<PaginationState>
|
|
25
|
-
autoResetPageIndex?: boolean
|
|
26
|
-
paginateRowsFn?: (
|
|
27
|
-
instance: TableInstance<TGenerics>,
|
|
28
|
-
rowModel: RowModel<TGenerics>
|
|
29
|
-
) => RowModel<TGenerics>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type PaginationDefaultOptions = {
|
|
33
|
-
onPaginationChange: OnChangeFn<PaginationState>
|
|
34
|
-
autoResetPageIndex: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type PaginationInstance<TGenerics extends PartialGenerics> = {
|
|
38
|
-
_notifyPageIndexReset: () => void
|
|
39
|
-
setPagination: (updater: Updater<PaginationState>) => void
|
|
40
|
-
resetPagination: () => void
|
|
41
|
-
setPageIndex: (updater: Updater<number>) => void
|
|
42
|
-
resetPageIndex: () => void
|
|
43
|
-
setPageSize: (updater: Updater<number>) => void
|
|
44
|
-
resetPageSize: () => void
|
|
45
|
-
setPageCount: (updater: Updater<number>) => void
|
|
46
|
-
getPageOptions: () => number[]
|
|
47
|
-
getCanPreviousPage: () => boolean
|
|
48
|
-
getCanNextPage: () => boolean
|
|
49
|
-
previousPage: () => void
|
|
50
|
-
nextPage: () => void
|
|
51
|
-
getPrePaginationRowModel: () => RowModel<TGenerics>
|
|
52
|
-
getPaginationRowModel: () => RowModel<TGenerics>
|
|
53
|
-
getPageCount: () => number
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
export function getInitialState(): PaginationTableState {
|
|
59
|
-
return {
|
|
60
|
-
pagination: {
|
|
61
|
-
pageCount: -1,
|
|
62
|
-
pageIndex: 0,
|
|
63
|
-
pageSize: 10,
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function getDefaultOptions<TGenerics extends PartialGenerics>(
|
|
69
|
-
instance: TableInstance<TGenerics>
|
|
70
|
-
): PaginationDefaultOptions {
|
|
71
|
-
return {
|
|
72
|
-
onPaginationChange: makeStateUpdater('pagination', instance),
|
|
73
|
-
autoResetPageIndex: true,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function getInstance<TGenerics extends PartialGenerics>(
|
|
78
|
-
instance: TableInstance<TGenerics>
|
|
79
|
-
): PaginationInstance<TGenerics> {
|
|
80
|
-
let registered = false
|
|
81
|
-
return {
|
|
82
|
-
_notifyPageIndexReset: () => {
|
|
83
|
-
if (!registered) {
|
|
84
|
-
registered = true
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (instance.options.autoResetAll === false) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
instance.options.autoResetAll === true ||
|
|
94
|
-
instance.options.autoResetPageIndex
|
|
95
|
-
) {
|
|
96
|
-
instance.resetPageIndex()
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
setPagination: updater => {
|
|
100
|
-
const safeUpdater: Updater<PaginationState> = old => {
|
|
101
|
-
let newState = functionalUpdate(updater, old)
|
|
102
|
-
|
|
103
|
-
return newState
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return instance.options.onPaginationChange?.(
|
|
107
|
-
safeUpdater,
|
|
108
|
-
functionalUpdate(safeUpdater, instance.getState().pagination)
|
|
109
|
-
)
|
|
110
|
-
},
|
|
111
|
-
resetPagination: () => {
|
|
112
|
-
instance.setPagination(
|
|
113
|
-
instance.initialState.pagination ?? {
|
|
114
|
-
pageIndex: 0,
|
|
115
|
-
pageSize: 10,
|
|
116
|
-
pageCount: -1,
|
|
117
|
-
}
|
|
118
|
-
)
|
|
119
|
-
},
|
|
120
|
-
setPageIndex: updater => {
|
|
121
|
-
instance.setPagination(old => {
|
|
122
|
-
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
123
|
-
|
|
124
|
-
const maxPageIndex =
|
|
125
|
-
old.pageCount && old.pageCount > 0
|
|
126
|
-
? old.pageCount - 1
|
|
127
|
-
: Number.MAX_SAFE_INTEGER
|
|
128
|
-
|
|
129
|
-
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
...old,
|
|
133
|
-
pageIndex,
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
},
|
|
137
|
-
resetPageIndex: () => {
|
|
138
|
-
instance.setPageIndex(0)
|
|
139
|
-
},
|
|
140
|
-
resetPageSize: () => {
|
|
141
|
-
instance.setPageSize(instance.initialState?.pagination?.pageSize ?? 10)
|
|
142
|
-
},
|
|
143
|
-
setPageSize: updater => {
|
|
144
|
-
instance.setPagination(old => {
|
|
145
|
-
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))
|
|
146
|
-
const topRowIndex = old.pageSize * old.pageIndex!
|
|
147
|
-
const pageIndex = Math.floor(topRowIndex / pageSize)
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
...old,
|
|
151
|
-
pageIndex,
|
|
152
|
-
pageSize,
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
},
|
|
156
|
-
setPageCount: updater =>
|
|
157
|
-
instance.setPagination(old => {
|
|
158
|
-
let newPageCount = functionalUpdate(updater, old.pageCount)
|
|
159
|
-
|
|
160
|
-
if (typeof newPageCount === 'number') {
|
|
161
|
-
newPageCount = Math.max(-1, newPageCount)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
...old,
|
|
166
|
-
pageCount: newPageCount,
|
|
167
|
-
}
|
|
168
|
-
}),
|
|
169
|
-
|
|
170
|
-
getPageOptions: memo(
|
|
171
|
-
() => [
|
|
172
|
-
instance.getState().pagination.pageSize,
|
|
173
|
-
instance.getState().pagination.pageCount,
|
|
174
|
-
],
|
|
175
|
-
(pageSize, pageCount) => {
|
|
176
|
-
let pageOptions: number[] = []
|
|
177
|
-
if (pageCount && pageCount > 0) {
|
|
178
|
-
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
179
|
-
}
|
|
180
|
-
return pageOptions
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
key: 'getPageOptions',
|
|
184
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
185
|
-
}
|
|
186
|
-
),
|
|
187
|
-
|
|
188
|
-
getCanPreviousPage: () => instance.getState().pagination.pageIndex > 0,
|
|
189
|
-
|
|
190
|
-
getCanNextPage: () => {
|
|
191
|
-
const { pageIndex, pageCount, pageSize } = instance.getState().pagination
|
|
192
|
-
|
|
193
|
-
if (pageCount === -1) {
|
|
194
|
-
return true
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (pageCount === 0) {
|
|
198
|
-
return false
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return (
|
|
202
|
-
pageIndex <
|
|
203
|
-
Math.ceil(instance.getPrePaginationRowModel().rows.length / pageSize) -
|
|
204
|
-
1
|
|
205
|
-
)
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
previousPage: () => {
|
|
209
|
-
return instance.setPageIndex(old => old - 1)
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
nextPage: () => {
|
|
213
|
-
return instance.setPageIndex(old => {
|
|
214
|
-
return old + 1
|
|
215
|
-
})
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
getPrePaginationRowModel: () => instance.getExpandedRowModel(),
|
|
219
|
-
getPaginationRowModel: memo(
|
|
220
|
-
() => [
|
|
221
|
-
instance.getState().pagination,
|
|
222
|
-
instance.getExpandedRowModel(),
|
|
223
|
-
instance.options.paginateRowsFn,
|
|
224
|
-
],
|
|
225
|
-
(_pagination, rowModel, paginateRowsFn) => {
|
|
226
|
-
if (!paginateRowsFn || !rowModel.rows.length) {
|
|
227
|
-
return rowModel
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return paginateRowsFn(instance, rowModel)
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
key: 'getPaginationRowModel',
|
|
234
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
235
|
-
}
|
|
236
|
-
),
|
|
237
|
-
|
|
238
|
-
getPageCount: () => {
|
|
239
|
-
const { pageCount } = instance.getState().pagination
|
|
240
|
-
if (pageCount > 0) {
|
|
241
|
-
return pageCount
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return Math.ceil(
|
|
245
|
-
instance.getPrePaginationRowModel().rows.length /
|
|
246
|
-
instance.getState().pagination.pageSize
|
|
247
|
-
)
|
|
248
|
-
},
|
|
249
|
-
}
|
|
250
|
-
}
|
package/src/features/Pinning.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OnChangeFn,
|
|
3
|
-
Updater,
|
|
4
|
-
TableInstance,
|
|
5
|
-
Column,
|
|
6
|
-
PartialGenerics,
|
|
7
|
-
} from '../types'
|
|
8
|
-
import { functionalUpdate, makeStateUpdater } from '../utils'
|
|
9
|
-
|
|
10
|
-
type ColumnPinningPosition = false | 'left' | 'right'
|
|
11
|
-
|
|
12
|
-
export type ColumnPinningState = {
|
|
13
|
-
left?: string[]
|
|
14
|
-
right?: string[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type ColumnPinningTableState = {
|
|
18
|
-
columnPinning: ColumnPinningState
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ColumnPinningOptions = {
|
|
22
|
-
onColumnPinningChange?: OnChangeFn<ColumnPinningState>
|
|
23
|
-
enablePinning?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ColumnPinningDefaultOptions = {
|
|
27
|
-
onColumnPinningChange: OnChangeFn<ColumnPinningState>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type ColumnPinningColumnDef = {
|
|
31
|
-
enablePinning?: boolean
|
|
32
|
-
defaultCanPin?: boolean
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type ColumnPinningColumn = {
|
|
36
|
-
getCanPin: () => boolean
|
|
37
|
-
getPinnedIndex: () => number
|
|
38
|
-
getIsPinned: () => ColumnPinningPosition
|
|
39
|
-
pin: (position: ColumnPinningPosition) => void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type ColumnPinningInstance<TGenerics extends PartialGenerics> = {
|
|
43
|
-
setColumnPinning: (updater: Updater<ColumnPinningState>) => void
|
|
44
|
-
resetColumnPinning: () => void
|
|
45
|
-
pinColumn: (columnId: string, position: ColumnPinningPosition) => void
|
|
46
|
-
getColumnCanPin: (columnId: string) => boolean
|
|
47
|
-
getColumnIsPinned: (columnId: string) => ColumnPinningPosition
|
|
48
|
-
getColumnPinnedIndex: (columnId: string) => number
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
export function getInitialState(): ColumnPinningTableState {
|
|
54
|
-
return {
|
|
55
|
-
columnPinning: {
|
|
56
|
-
left: [],
|
|
57
|
-
right: [],
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function getDefaultOptions<TGenerics extends PartialGenerics>(
|
|
63
|
-
instance: TableInstance<TGenerics>
|
|
64
|
-
): ColumnPinningDefaultOptions {
|
|
65
|
-
return {
|
|
66
|
-
onColumnPinningChange: makeStateUpdater('columnPinning', instance),
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function createColumn<TGenerics extends PartialGenerics>(
|
|
71
|
-
column: Column<TGenerics>,
|
|
72
|
-
instance: TableInstance<TGenerics>
|
|
73
|
-
): ColumnPinningColumn {
|
|
74
|
-
return {
|
|
75
|
-
getCanPin: () => instance.getColumnCanPin(column.id),
|
|
76
|
-
getPinnedIndex: () => instance.getColumnPinnedIndex(column.id),
|
|
77
|
-
getIsPinned: () => instance.getColumnIsPinned(column.id),
|
|
78
|
-
pin: position => instance.pinColumn(column.id, position),
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getInstance<TGenerics extends PartialGenerics>(
|
|
83
|
-
instance: TableInstance<TGenerics>
|
|
84
|
-
): ColumnPinningInstance<TGenerics> {
|
|
85
|
-
return {
|
|
86
|
-
setColumnPinning: updater =>
|
|
87
|
-
instance.options.onColumnPinningChange?.(
|
|
88
|
-
updater,
|
|
89
|
-
functionalUpdate(updater, instance.getState().columnPinning)
|
|
90
|
-
),
|
|
91
|
-
|
|
92
|
-
resetColumnPinning: () =>
|
|
93
|
-
instance.setColumnPinning(instance.initialState?.columnPinning ?? {}),
|
|
94
|
-
|
|
95
|
-
pinColumn: (columnId, position) => {
|
|
96
|
-
const column = instance.getColumn(columnId)
|
|
97
|
-
|
|
98
|
-
const columnIds = column
|
|
99
|
-
?.getLeafColumns()
|
|
100
|
-
.map(d => d.id)
|
|
101
|
-
.filter(Boolean) as string[]
|
|
102
|
-
|
|
103
|
-
instance.setColumnPinning(old => {
|
|
104
|
-
if (position === 'right') {
|
|
105
|
-
return {
|
|
106
|
-
left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
|
|
107
|
-
right: [
|
|
108
|
-
...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
|
|
109
|
-
...columnIds,
|
|
110
|
-
],
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (position === 'left') {
|
|
115
|
-
return {
|
|
116
|
-
left: [
|
|
117
|
-
...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
|
|
118
|
-
...columnIds,
|
|
119
|
-
],
|
|
120
|
-
right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
|
|
126
|
-
right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
getColumnCanPin: columnId => {
|
|
132
|
-
const column = instance.getColumn(columnId)
|
|
133
|
-
|
|
134
|
-
if (!column) {
|
|
135
|
-
throw new Error()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const leafColumns = column.getLeafColumns()
|
|
139
|
-
|
|
140
|
-
return leafColumns.some(
|
|
141
|
-
d =>
|
|
142
|
-
d.enablePinning ??
|
|
143
|
-
instance.options.enablePinning ??
|
|
144
|
-
d.defaultCanPin ??
|
|
145
|
-
!!d.accessorFn
|
|
146
|
-
)
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
getColumnIsPinned: columnId => {
|
|
150
|
-
const column = instance.getColumn(columnId)
|
|
151
|
-
|
|
152
|
-
if (!column) {
|
|
153
|
-
throw new Error()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const leafColumnIds = column.getLeafColumns().map(d => d.id)
|
|
157
|
-
|
|
158
|
-
const { left, right } = instance.getState().columnPinning
|
|
159
|
-
|
|
160
|
-
const isLeft = leafColumnIds.some(d => left?.includes(d))
|
|
161
|
-
const isRight = leafColumnIds.some(d => right?.includes(d))
|
|
162
|
-
|
|
163
|
-
return isLeft ? 'left' : isRight ? 'right' : false
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
getColumnPinnedIndex: columnId => {
|
|
167
|
-
const position = instance.getColumnIsPinned(columnId)
|
|
168
|
-
|
|
169
|
-
return position
|
|
170
|
-
? instance.getState().columnPinning?.[position]?.indexOf(columnId) ?? -1
|
|
171
|
-
: 0
|
|
172
|
-
},
|
|
173
|
-
}
|
|
174
|
-
}
|