@tanstack/table-core 8.0.0-alpha.67 → 8.0.0-alpha.70
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/aggregationFns.js +25 -37
- package/build/cjs/aggregationFns.js.map +1 -1
- package/build/cjs/core.js +167 -46
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +24 -40
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +28 -34
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +102 -116
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +52 -79
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Expanding.js +49 -58
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +98 -193
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +53 -71
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +109 -165
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +31 -43
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +79 -82
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +71 -125
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +93 -112
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +32 -22
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +54 -73
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +47 -86
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +48 -72
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +13 -13
- package/build/cjs/sortingFns.js +21 -21
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +49 -55
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +98 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +17 -21
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +130 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +126 -136
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +39 -39
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +112 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +36 -207
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +1778 -2347
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +421 -481
- package/build/types/core.d.ts +3 -5
- package/build/types/features/Cells.d.ts +1 -1
- package/build/types/features/ColumnSizing.d.ts +2 -2
- package/build/types/features/Columns.d.ts +1 -1
- package/build/types/features/Expanding.d.ts +1 -1
- package/build/types/features/Filters.d.ts +12 -7
- package/build/types/features/Grouping.d.ts +5 -4
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +4 -4
- package/build/types/features/Pinning.d.ts +1 -1
- package/build/types/features/RowSelection.d.ts +1 -1
- package/build/types/features/Rows.d.ts +4 -3
- package/build/types/features/Sorting.d.ts +2 -1
- package/build/types/features/Visibility.d.ts +1 -0
- package/build/types/index.d.ts +6 -4
- package/build/types/types.d.ts +3 -13
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
- package/build/types/utils/getGroupedRowModel.d.ts +1 -1
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +1 -17
- package/build/umd/index.development.js +1779 -2350
- 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 +197 -45
- package/src/features/Cells.ts +7 -11
- package/src/features/ColumnSizing.ts +27 -19
- package/src/features/Columns.ts +4 -8
- package/src/features/Expanding.ts +5 -3
- package/src/features/Filters.ts +105 -162
- package/src/features/Grouping.ts +21 -23
- package/src/features/Ordering.ts +5 -3
- package/src/features/Pagination.ts +32 -19
- package/src/features/Pinning.ts +13 -7
- package/src/features/RowSelection.ts +5 -3
- package/src/features/Rows.ts +21 -6
- package/src/features/Sorting.ts +14 -12
- package/src/features/Visibility.ts +7 -0
- package/src/filterFns.ts +9 -9
- package/src/index.ts +12 -4
- package/src/sortingFns.ts +11 -11
- package/src/types.ts +3 -16
- package/src/utils/filterRowsUtils.ts +47 -68
- package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +2 -8
- package/src/utils/getFacetedMinMaxValues.ts +37 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/{getFilteredRowModelSync.ts → getFilteredRowModel.ts} +29 -20
- package/src/utils/getGroupedRowModel.ts +52 -61
- package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +3 -3
- package/src/utils.ts +28 -236
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
- package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelSync.js +0 -102
- package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
- package/build/cjs/utils/getFilteredRowModelSync.js +0 -125
- package/build/cjs/utils/getFilteredRowModelSync.js.map +0 -1
- package/build/cjs/utils/getSortedRowModelSync.js +0 -118
- package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
- package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelSync.d.ts +0 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
- package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
- package/src/utils/getCoreRowModelAsync.ts +0 -104
- package/src/utils/getFilteredRowModelAsync.ts +0 -157
- package/src/utils/getSortedRowModelAsync.ts +0 -200
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.70",
|
|
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
|
@@ -26,10 +26,9 @@ import { Sorting } from './features/Sorting'
|
|
|
26
26
|
import { Visibility } from './features/Visibility'
|
|
27
27
|
import { Headers } from './features/Headers'
|
|
28
28
|
//
|
|
29
|
-
import { mean } from './aggregationFns'
|
|
30
29
|
|
|
31
30
|
export type CoreTableState = {
|
|
32
|
-
coreProgress: number
|
|
31
|
+
// coreProgress: number
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
@@ -45,27 +44,52 @@ export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
45
44
|
initialState?: InitialTableState
|
|
46
45
|
autoResetAll?: boolean
|
|
47
46
|
mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
|
|
47
|
+
keepPreviousData?: boolean
|
|
48
48
|
meta?: TGenerics['TableMeta']
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export type
|
|
51
|
+
export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
52
52
|
// generics: TGenerics
|
|
53
53
|
initialState: TableState
|
|
54
54
|
reset: () => void
|
|
55
55
|
options: RequiredKeys<TableOptions<TGenerics>, 'state'>
|
|
56
56
|
setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void
|
|
57
57
|
queue: (cb: () => void) => void
|
|
58
|
-
// willUpdate: () => void
|
|
59
58
|
getState: () => TableState
|
|
60
59
|
setState: (updater: Updater<TableState>) => void
|
|
61
60
|
render: <TProps>(
|
|
62
61
|
template: Renderable<TGenerics, TProps>,
|
|
63
62
|
props: TProps
|
|
64
63
|
) => string | null | TGenerics['Rendered']
|
|
65
|
-
getOverallProgress: () => number
|
|
64
|
+
// getOverallProgress: () => number
|
|
65
|
+
// getProgressStage: () =>
|
|
66
|
+
// | undefined
|
|
67
|
+
// | 'coreRowModel'
|
|
68
|
+
// | 'filteredRowModel'
|
|
69
|
+
// | 'facetedRowModel'
|
|
66
70
|
_features: readonly TableFeature[]
|
|
71
|
+
// createBatch: (priority: keyof CoreBatches) => Batch
|
|
72
|
+
// init: () => void
|
|
73
|
+
// willUpdate: () => void
|
|
74
|
+
// destroy: () => void
|
|
75
|
+
// batches: CoreBatches
|
|
67
76
|
}
|
|
68
77
|
|
|
78
|
+
// export type Batch = {
|
|
79
|
+
// id: number
|
|
80
|
+
// priority: keyof CoreBatches
|
|
81
|
+
// tasks: (() => void)[]
|
|
82
|
+
// schedule: (cb: () => void) => void
|
|
83
|
+
// cancel: () => void
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
// type CoreBatches = {
|
|
87
|
+
// data: Batch[]
|
|
88
|
+
// facets: Batch[]
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// export type TaskPriority = keyof CoreBatches
|
|
92
|
+
|
|
69
93
|
export function createTableInstance<TGenerics extends TableGenerics>(
|
|
70
94
|
options: TableOptions<TGenerics>
|
|
71
95
|
): TableInstance<TGenerics> {
|
|
@@ -73,24 +97,24 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
73
97
|
console.info('Creating Table Instance...')
|
|
74
98
|
}
|
|
75
99
|
|
|
76
|
-
let instance = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
let instance = {
|
|
101
|
+
_features: [
|
|
102
|
+
Columns,
|
|
103
|
+
Rows,
|
|
104
|
+
Cells,
|
|
105
|
+
Headers,
|
|
106
|
+
Visibility,
|
|
107
|
+
Ordering,
|
|
108
|
+
Pinning,
|
|
109
|
+
Filters,
|
|
110
|
+
Sorting,
|
|
111
|
+
Grouping,
|
|
112
|
+
Expanding,
|
|
113
|
+
Pagination,
|
|
114
|
+
RowSelection,
|
|
115
|
+
ColumnSizing,
|
|
116
|
+
] as const,
|
|
117
|
+
} as unknown as CoreInstance<TGenerics>
|
|
94
118
|
|
|
95
119
|
const defaultOptions = instance._features.reduce((obj, feature) => {
|
|
96
120
|
return Object.assign(obj, feature.getDefaultOptions?.(instance))
|
|
@@ -107,13 +131,8 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
107
131
|
}
|
|
108
132
|
}
|
|
109
133
|
|
|
110
|
-
instance.options = {
|
|
111
|
-
...defaultOptions,
|
|
112
|
-
...options,
|
|
113
|
-
}
|
|
114
|
-
|
|
115
134
|
const coreInitialState: CoreTableState = {
|
|
116
|
-
coreProgress: 1,
|
|
135
|
+
// coreProgress: 1,
|
|
117
136
|
}
|
|
118
137
|
|
|
119
138
|
let initialState = {
|
|
@@ -128,11 +147,90 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
128
147
|
const queued: (() => void)[] = []
|
|
129
148
|
let queuedTimeout = false
|
|
130
149
|
|
|
131
|
-
|
|
150
|
+
// let workScheduled = false
|
|
151
|
+
// let working = false
|
|
152
|
+
// let latestCallback: ReturnType<typeof requestIdleCallback>
|
|
153
|
+
// let batchUid = 0
|
|
154
|
+
// const onProgress = () => {}
|
|
155
|
+
// const getBatch = () => {
|
|
156
|
+
// instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
|
|
157
|
+
// instance.batches.facets = instance.batches.facets.filter(
|
|
158
|
+
// d => d.tasks.length
|
|
159
|
+
// )
|
|
160
|
+
|
|
161
|
+
// return (
|
|
162
|
+
// instance.batches.data.find(d => d.tasks.length) ??
|
|
163
|
+
// instance.batches.facets.find(d => d.tasks.length)
|
|
164
|
+
// )
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
// const startWorkLoop = () => {
|
|
168
|
+
// working = true
|
|
169
|
+
|
|
170
|
+
// const workLoop = (deadline: IdleDeadline) => {
|
|
171
|
+
// const batch = getBatch()
|
|
172
|
+
|
|
173
|
+
// if (!batch) {
|
|
174
|
+
// working = false
|
|
175
|
+
// return
|
|
176
|
+
// }
|
|
177
|
+
// // Prioritize tasks
|
|
178
|
+
// while (deadline.timeRemaining() > 0 && batch.tasks.length) {
|
|
179
|
+
// batch.tasks.shift()!()
|
|
180
|
+
// }
|
|
181
|
+
|
|
182
|
+
// onProgress()
|
|
183
|
+
|
|
184
|
+
// if (working) {
|
|
185
|
+
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
186
|
+
// }
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
190
|
+
// }
|
|
191
|
+
|
|
192
|
+
// const startWork = () => {
|
|
193
|
+
// if (getBatch() && !working) {
|
|
194
|
+
// if (
|
|
195
|
+
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
196
|
+
// instance.options.debugTable
|
|
197
|
+
// ) {
|
|
198
|
+
// console.info('Starting work...')
|
|
199
|
+
// }
|
|
200
|
+
// startWorkLoop()
|
|
201
|
+
// }
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// const stopWork = () => {
|
|
205
|
+
// if (working) {
|
|
206
|
+
// if (
|
|
207
|
+
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
208
|
+
// instance.options.debugTable
|
|
209
|
+
// ) {
|
|
210
|
+
// console.info('Stopping work...')
|
|
211
|
+
// }
|
|
212
|
+
|
|
213
|
+
// working = false
|
|
214
|
+
// cancelIdleCallback(latestCallback)
|
|
215
|
+
// }
|
|
216
|
+
// }
|
|
217
|
+
|
|
218
|
+
const midInstance: CoreInstance<TGenerics> = {
|
|
132
219
|
...instance,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
220
|
+
// init: () => {
|
|
221
|
+
// startWork()
|
|
222
|
+
// },
|
|
223
|
+
// willUpdate: () => {
|
|
224
|
+
// startWork()
|
|
225
|
+
// },
|
|
226
|
+
// destroy: () => {
|
|
227
|
+
// stopWork()
|
|
228
|
+
// },
|
|
229
|
+
options: {
|
|
230
|
+
...defaultOptions,
|
|
231
|
+
...options,
|
|
232
|
+
},
|
|
233
|
+
initialState,
|
|
136
234
|
queue: cb => {
|
|
137
235
|
queued.push(cb)
|
|
138
236
|
|
|
@@ -155,7 +253,43 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
155
253
|
)
|
|
156
254
|
}
|
|
157
255
|
},
|
|
158
|
-
|
|
256
|
+
// batches: {
|
|
257
|
+
// data: [],
|
|
258
|
+
// facets: [],
|
|
259
|
+
// },
|
|
260
|
+
// createBatch: priority => {
|
|
261
|
+
// const batchId = batchUid++
|
|
262
|
+
// let canceled: boolean
|
|
263
|
+
|
|
264
|
+
// const batch: Batch = {
|
|
265
|
+
// id: batchId,
|
|
266
|
+
// priority,
|
|
267
|
+
// tasks: [],
|
|
268
|
+
// schedule: cb => {
|
|
269
|
+
// if (canceled) return
|
|
270
|
+
// batch.tasks.push(cb)
|
|
271
|
+
|
|
272
|
+
// if (!working && !workScheduled) {
|
|
273
|
+
// workScheduled = true
|
|
274
|
+
// instance.queue(() => {
|
|
275
|
+
// workScheduled = false
|
|
276
|
+
// instance.setState(old => ({ ...old }))
|
|
277
|
+
// })
|
|
278
|
+
// }
|
|
279
|
+
// },
|
|
280
|
+
// cancel: () => {
|
|
281
|
+
// canceled = true
|
|
282
|
+
// batch.tasks = []
|
|
283
|
+
// instance.batches[priority] = instance.batches[priority].filter(
|
|
284
|
+
// b => b.id !== batchId
|
|
285
|
+
// )
|
|
286
|
+
// },
|
|
287
|
+
// }
|
|
288
|
+
|
|
289
|
+
// instance.batches[priority].push(batch)
|
|
290
|
+
|
|
291
|
+
// return batch
|
|
292
|
+
// },
|
|
159
293
|
reset: () => {
|
|
160
294
|
instance.setState(instance.initialState)
|
|
161
295
|
},
|
|
@@ -183,19 +317,37 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
183
317
|
instance.options.onStateChange?.(updater)
|
|
184
318
|
},
|
|
185
319
|
|
|
186
|
-
getOverallProgress: () => {
|
|
187
|
-
|
|
188
|
-
|
|
320
|
+
// getOverallProgress: () => {
|
|
321
|
+
// const { coreProgress, filtersProgress, facetProgress } =
|
|
322
|
+
// instance.getState()
|
|
189
323
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
324
|
+
// return mean(() =>
|
|
325
|
+
// [coreProgress, filtersProgress].filter(d => d < 1)
|
|
326
|
+
// ) as number
|
|
327
|
+
// },
|
|
328
|
+
// getProgressStage: () => {
|
|
329
|
+
// const { coreProgress, filtersProgress, facetProgress } =
|
|
330
|
+
// instance.getState()
|
|
331
|
+
|
|
332
|
+
// if (coreProgress < 1) {
|
|
333
|
+
// return 'coreRowModel'
|
|
334
|
+
// }
|
|
335
|
+
|
|
336
|
+
// if (filtersProgress < 1) {
|
|
337
|
+
// return 'filteredRowModel'
|
|
338
|
+
// }
|
|
339
|
+
|
|
340
|
+
// if (Object.values(facetProgress).some(d => d < 1)) {
|
|
341
|
+
// return 'facetedRowModel'
|
|
342
|
+
// }
|
|
343
|
+
// },
|
|
196
344
|
}
|
|
197
345
|
|
|
198
|
-
instance = Object.assign(instance,
|
|
346
|
+
instance = Object.assign(instance, midInstance)
|
|
347
|
+
|
|
348
|
+
instance._features.forEach(feature => {
|
|
349
|
+
return Object.assign(instance, feature.createInstance?.(instance))
|
|
350
|
+
})
|
|
199
351
|
|
|
200
|
-
return instance
|
|
352
|
+
return instance as TableInstance<TGenerics>
|
|
201
353
|
}
|
package/src/features/Cells.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type CellsInstance<TGenerics extends TableGenerics> = {
|
|
|
17
17
|
createCell: (
|
|
18
18
|
row: Row<TGenerics>,
|
|
19
19
|
column: Column<TGenerics>,
|
|
20
|
-
|
|
20
|
+
columnId: string
|
|
21
21
|
) => Cell<TGenerics>
|
|
22
22
|
getCell: (rowId: string, columnId: string) => Cell<TGenerics>
|
|
23
23
|
}
|
|
@@ -34,15 +34,11 @@ export const Cells = {
|
|
|
34
34
|
() => [instance.getAllLeafColumns()],
|
|
35
35
|
leafColumns => {
|
|
36
36
|
return leafColumns.map(column => {
|
|
37
|
-
return instance.createCell(
|
|
38
|
-
row as Row<TGenerics>,
|
|
39
|
-
column,
|
|
40
|
-
row.values[column.id]
|
|
41
|
-
)
|
|
37
|
+
return instance.createCell(row as Row<TGenerics>, column, column.id)
|
|
42
38
|
})
|
|
43
39
|
},
|
|
44
40
|
{
|
|
45
|
-
key: process.env.NODE_ENV === 'development'
|
|
41
|
+
key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
|
|
46
42
|
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
47
43
|
}
|
|
48
44
|
),
|
|
@@ -69,14 +65,14 @@ export const Cells = {
|
|
|
69
65
|
instance: TableInstance<TGenerics>
|
|
70
66
|
): CellsInstance<TGenerics> => {
|
|
71
67
|
return {
|
|
72
|
-
createCell: (row, column,
|
|
68
|
+
createCell: (row, column, columnId) => {
|
|
73
69
|
const cell: CoreCell<TGenerics> = {
|
|
74
70
|
id: `${row.id}_${column.id}`,
|
|
75
71
|
rowId: row.id,
|
|
76
|
-
columnId
|
|
72
|
+
columnId,
|
|
77
73
|
row,
|
|
78
74
|
column,
|
|
79
|
-
|
|
75
|
+
getValue: () => row.getValue(columnId),
|
|
80
76
|
renderCell: () =>
|
|
81
77
|
column.cell
|
|
82
78
|
? instance.render(column.cell, {
|
|
@@ -84,7 +80,7 @@ export const Cells = {
|
|
|
84
80
|
column,
|
|
85
81
|
row,
|
|
86
82
|
cell: cell as Cell<TGenerics>,
|
|
87
|
-
|
|
83
|
+
getValue: cell.getValue,
|
|
88
84
|
})
|
|
89
85
|
: null,
|
|
90
86
|
}
|
|
@@ -46,8 +46,8 @@ export type ColumnSizingDefaultOptions = {
|
|
|
46
46
|
export type ColumnSizingInstance<TGenerics extends TableGenerics> = {
|
|
47
47
|
setColumnSizing: (updater: Updater<ColumnSizingState>) => void
|
|
48
48
|
setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => void
|
|
49
|
-
resetColumnSizing: () => void
|
|
50
|
-
resetHeaderSizeInfo: () => void
|
|
49
|
+
resetColumnSizing: (defaultState?: boolean) => void
|
|
50
|
+
resetHeaderSizeInfo: (defaultState?: boolean) => void
|
|
51
51
|
getTotalSize: () => number
|
|
52
52
|
getLeftTotalSize: () => number
|
|
53
53
|
getCenterTotalSize: () => number
|
|
@@ -83,6 +83,15 @@ export const defaultColumnSizing = {
|
|
|
83
83
|
maxSize: Number.MAX_SAFE_INTEGER,
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
const getDefaultColumnSizingInfoState = (): ColumnSizingInfoState => ({
|
|
87
|
+
startOffset: null,
|
|
88
|
+
startSize: null,
|
|
89
|
+
deltaOffset: null,
|
|
90
|
+
deltaPercentage: null,
|
|
91
|
+
isResizingColumn: false,
|
|
92
|
+
columnSizingStart: [],
|
|
93
|
+
})
|
|
94
|
+
|
|
86
95
|
export const ColumnSizing: TableFeature = {
|
|
87
96
|
getDefaultColumn: (): ColumnSizingColumnDef => {
|
|
88
97
|
return defaultColumnSizing
|
|
@@ -90,14 +99,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
90
99
|
getInitialState: (state): ColumnSizingTableState => {
|
|
91
100
|
return {
|
|
92
101
|
columnSizing: {},
|
|
93
|
-
columnSizingInfo:
|
|
94
|
-
startOffset: null,
|
|
95
|
-
startSize: null,
|
|
96
|
-
deltaOffset: null,
|
|
97
|
-
deltaPercentage: null,
|
|
98
|
-
isResizingColumn: false,
|
|
99
|
-
columnSizingStart: [],
|
|
100
|
-
},
|
|
102
|
+
columnSizingInfo: getDefaultColumnSizingInfoState(),
|
|
101
103
|
...state,
|
|
102
104
|
}
|
|
103
105
|
},
|
|
@@ -138,7 +140,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
138
140
|
const index = columns.findIndex(d => d.id === column.id)
|
|
139
141
|
|
|
140
142
|
if (index > 0) {
|
|
141
|
-
const prevSiblingColumn = columns[index - 1]
|
|
143
|
+
const prevSiblingColumn = columns[index - 1]!
|
|
142
144
|
|
|
143
145
|
return (
|
|
144
146
|
prevSiblingColumn.getStart(position) + prevSiblingColumn.getSize()
|
|
@@ -188,7 +190,8 @@ export const ColumnSizing: TableFeature = {
|
|
|
188
190
|
},
|
|
189
191
|
getStart: () => {
|
|
190
192
|
if (header.index > 0) {
|
|
191
|
-
const prevSiblingHeader =
|
|
193
|
+
const prevSiblingHeader =
|
|
194
|
+
header.headerGroup.headers[header.index - 1]!
|
|
192
195
|
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize()
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -221,7 +224,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
221
224
|
: [[column.id, column.getSize()]]
|
|
222
225
|
|
|
223
226
|
const clientX = isTouchStartEvent(e)
|
|
224
|
-
? Math.round(e.touches[0]
|
|
227
|
+
? Math.round(e.touches[0]!.clientX)
|
|
225
228
|
: (e as MouseEvent).clientX
|
|
226
229
|
|
|
227
230
|
const updateOffset = (
|
|
@@ -298,7 +301,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
298
301
|
e.preventDefault()
|
|
299
302
|
e.stopPropagation()
|
|
300
303
|
}
|
|
301
|
-
onMove(e.touches[0]
|
|
304
|
+
onMove(e.touches[0]!.clientX)
|
|
302
305
|
return false
|
|
303
306
|
},
|
|
304
307
|
upHandler: (e: TouchEvent) => {
|
|
@@ -308,7 +311,7 @@ export const ColumnSizing: TableFeature = {
|
|
|
308
311
|
e.preventDefault()
|
|
309
312
|
e.stopPropagation()
|
|
310
313
|
}
|
|
311
|
-
onEnd(e.touches[0]
|
|
314
|
+
onEnd(e.touches[0]!.clientX)
|
|
312
315
|
},
|
|
313
316
|
}
|
|
314
317
|
|
|
@@ -352,12 +355,17 @@ export const ColumnSizing: TableFeature = {
|
|
|
352
355
|
instance.options.onColumnSizingChange?.(updater),
|
|
353
356
|
setColumnSizingInfo: updater =>
|
|
354
357
|
instance.options.onColumnSizingInfoChange?.(updater),
|
|
355
|
-
resetColumnSizing:
|
|
356
|
-
instance.setColumnSizing(
|
|
358
|
+
resetColumnSizing: defaultState => {
|
|
359
|
+
instance.setColumnSizing(
|
|
360
|
+
defaultState ? {} : instance.initialState.columnSizing ?? {}
|
|
361
|
+
)
|
|
357
362
|
},
|
|
358
|
-
resetHeaderSizeInfo:
|
|
363
|
+
resetHeaderSizeInfo: defaultState => {
|
|
359
364
|
instance.setColumnSizingInfo(
|
|
360
|
-
|
|
365
|
+
defaultState
|
|
366
|
+
? getDefaultColumnSizingInfoState()
|
|
367
|
+
: instance.initialState.columnSizingInfo ??
|
|
368
|
+
getDefaultColumnSizingInfoState()
|
|
361
369
|
)
|
|
362
370
|
},
|
|
363
371
|
getTotalSize: () =>
|
package/src/features/Columns.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
AccessorFn,
|
|
9
9
|
ColumnDef,
|
|
10
10
|
Renderable,
|
|
11
|
-
HeaderRenderProps,
|
|
12
11
|
} from '../types'
|
|
13
12
|
import { memo } from '../utils'
|
|
14
13
|
|
|
@@ -42,7 +41,7 @@ export type CoreColumnDef<TGenerics extends TableGenerics> = {
|
|
|
42
41
|
row: Row<TGenerics>
|
|
43
42
|
column: Column<TGenerics>
|
|
44
43
|
cell: Cell<TGenerics>
|
|
45
|
-
|
|
44
|
+
getValue: () => TGenerics['Value']
|
|
46
45
|
}
|
|
47
46
|
>
|
|
48
47
|
meta?: TGenerics['ColumnMeta']
|
|
@@ -93,12 +92,9 @@ export const Columns = {
|
|
|
93
92
|
defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
|
|
94
93
|
|
|
95
94
|
return {
|
|
96
|
-
header:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
props.header.column.id,
|
|
100
|
-
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
101
|
-
typeof value === 'boolean' ? value.toString() : value,
|
|
95
|
+
header: props => props.header.column.id,
|
|
96
|
+
footer: props => props.header.column.id,
|
|
97
|
+
cell: props => props.getValue().toString?.() ?? null,
|
|
102
98
|
...instance._features.reduce((obj, feature) => {
|
|
103
99
|
return Object.assign(obj, feature.getDefaultColumn?.())
|
|
104
100
|
}, {}),
|
|
@@ -41,7 +41,7 @@ export type ExpandedInstance<TGenerics extends TableGenerics> = {
|
|
|
41
41
|
_autoResetExpanded: () => void
|
|
42
42
|
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
43
43
|
toggleAllRowsExpanded: (expanded?: boolean) => void
|
|
44
|
-
resetExpanded: () => void
|
|
44
|
+
resetExpanded: (defaultState?: boolean) => void
|
|
45
45
|
getCanSomeRowsExpand: () => boolean
|
|
46
46
|
getToggleAllRowsExpandedHandler: () => (event: unknown) => void
|
|
47
47
|
getIsSomeRowsExpanded: () => boolean
|
|
@@ -104,8 +104,10 @@ export const Expanding: TableFeature = {
|
|
|
104
104
|
instance.setExpanded({})
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
|
-
resetExpanded:
|
|
108
|
-
instance.setExpanded(
|
|
107
|
+
resetExpanded: defaultState => {
|
|
108
|
+
instance.setExpanded(
|
|
109
|
+
defaultState ? {} : instance.initialState?.expanded ?? {}
|
|
110
|
+
)
|
|
109
111
|
},
|
|
110
112
|
getCanSomeRowsExpand: () => {
|
|
111
113
|
return instance.getRowModel().flatRows.some(row => row.getCanExpand())
|