@tanstack/table-core 8.0.0-alpha.53 → 8.0.0-alpha.57
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 +9 -384
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +122 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +90 -37
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +216 -0
- package/build/cjs/features/Columns.js.map +1 -0
- package/build/cjs/features/Expanding.js +1 -1
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +78 -153
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +2 -2
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +172 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +99 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +51 -17
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +879 -693
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +420 -318
- package/build/types/core.d.ts +5 -82
- package/build/types/createTable.d.ts +4 -4
- package/build/types/features/Cells.d.ts +14 -0
- package/build/types/features/ColumnSizing.d.ts +31 -23
- package/build/types/features/Columns.d.ts +54 -0
- 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 +5 -13
- package/build/types/features/Ordering.d.ts +5 -5
- package/build/types/features/Pagination.d.ts +5 -5
- package/build/types/features/Pinning.d.ts +21 -7
- package/build/types/features/RowSelection.d.ts +8 -8
- package/build/types/features/Rows.d.ts +29 -0
- package/build/types/features/Sorting.d.ts +12 -12
- package/build/types/features/Visibility.d.ts +11 -6
- package/build/types/filterFns.d.ts +10 -10
- package/build/types/sortingFns.d.ts +7 -7
- package/build/types/types.d.ts +37 -33
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelAsync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelSync.d.ts +2 -2
- package/build/types/utils/getExpandedRowModel.d.ts +3 -3
- package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getGroupedRowModel.d.ts +2 -2
- package/build/types/utils/getPaginationRowModel.d.ts +2 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +4 -4
- package/build/types/utils/getSortedRowModelSync.d.ts +2 -2
- package/build/types/utils.d.ts +0 -1
- package/build/umd/index.development.js +857 -671
- 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 +32 -554
- package/src/createTable.ts +12 -5
- package/src/features/Cells.ts +156 -0
- package/src/features/ColumnSizing.ts +109 -58
- package/src/features/Columns.ts +290 -0
- package/src/features/Expanding.ts +6 -7
- package/src/features/Filters.ts +14 -15
- package/src/features/Grouping.ts +16 -17
- package/src/features/Headers.ts +51 -142
- package/src/features/Ordering.ts +8 -7
- package/src/features/Pagination.ts +5 -6
- package/src/features/Pinning.ts +198 -8
- package/src/features/RowSelection.ts +9 -10
- package/src/features/Rows.ts +151 -0
- package/src/features/Sorting.ts +12 -13
- package/src/features/Visibility.ts +73 -27
- package/src/filterFns.ts +10 -10
- package/src/sortingFns.ts +7 -7
- package/src/types.ts +47 -65
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getColumnFilteredRowModelAsync.ts +2 -2
- package/src/utils/getColumnFilteredRowModelSync.ts +2 -2
- package/src/utils/getCoreRowModelAsync.ts +2 -2
- package/src/utils/getCoreRowModelSync.ts +2 -2
- package/src/utils/getExpandedRowModel.ts +3 -3
- package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -2
- package/src/utils/getGlobalFilteredRowModelSync.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +3 -3
- package/src/utils/getPaginationRowModel.ts +2 -2
- package/src/utils/getSortedRowModelAsync.ts +4 -4
- package/src/utils/getSortedRowModelSync.ts +2 -2
- package/src/utils.ts +3 -5
package/src/features/Headers.ts
CHANGED
|
@@ -9,30 +9,21 @@ import {
|
|
|
9
9
|
HeaderGroup,
|
|
10
10
|
HeaderGroupProps,
|
|
11
11
|
HeaderProps,
|
|
12
|
-
|
|
13
|
-
PartialGenerics,
|
|
12
|
+
TableGenerics,
|
|
14
13
|
PropGetterValue,
|
|
15
14
|
TableInstance,
|
|
16
15
|
Row,
|
|
17
16
|
} from '../types'
|
|
18
17
|
import { propGetter, memo } from '../utils'
|
|
19
|
-
import { ColumnSizing } from './ColumnSizing'
|
|
20
|
-
|
|
21
|
-
export type HeadersRow<TGenerics extends AnyGenerics> = {
|
|
22
|
-
_getAllVisibleCells: () => Cell<TGenerics>[]
|
|
23
|
-
getVisibleCells: () => Cell<TGenerics>[]
|
|
24
|
-
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
25
|
-
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
26
|
-
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
27
|
-
}
|
|
28
18
|
|
|
29
|
-
export type HeadersInstance<TGenerics extends
|
|
19
|
+
export type HeadersInstance<TGenerics extends TableGenerics> = {
|
|
30
20
|
createHeader: (
|
|
31
21
|
column: Column<TGenerics>,
|
|
32
22
|
options: {
|
|
33
23
|
id?: string
|
|
34
24
|
isPlaceholder?: boolean
|
|
35
25
|
placeholderId?: string
|
|
26
|
+
index: number
|
|
36
27
|
depth: number
|
|
37
28
|
}
|
|
38
29
|
) => Header<TGenerics>
|
|
@@ -74,100 +65,12 @@ export type HeadersInstance<TGenerics extends AnyGenerics> = {
|
|
|
74
65
|
headerId: string,
|
|
75
66
|
userProps?: TGetter
|
|
76
67
|
) => undefined | PropGetterValue<FooterProps, TGetter>
|
|
77
|
-
getTotalWidth: () => number
|
|
78
68
|
}
|
|
79
69
|
|
|
80
70
|
//
|
|
81
71
|
|
|
82
72
|
export const Headers = {
|
|
83
|
-
|
|
84
|
-
row: Row<TGenerics>,
|
|
85
|
-
instance: TableInstance<TGenerics>
|
|
86
|
-
): HeadersRow<TGenerics> => {
|
|
87
|
-
return {
|
|
88
|
-
_getAllVisibleCells: memo(
|
|
89
|
-
() => [
|
|
90
|
-
row
|
|
91
|
-
.getAllCells()
|
|
92
|
-
.filter(cell => cell.column.getIsVisible())
|
|
93
|
-
.map(d => d.id)
|
|
94
|
-
.join('_'),
|
|
95
|
-
],
|
|
96
|
-
_ => {
|
|
97
|
-
return row.getAllCells().filter(cell => cell.column.getIsVisible())
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
key: 'row._getAllVisibleCells',
|
|
101
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
102
|
-
}
|
|
103
|
-
),
|
|
104
|
-
getVisibleCells: memo(
|
|
105
|
-
() => [
|
|
106
|
-
row.getLeftVisibleCells(),
|
|
107
|
-
row.getCenterVisibleCells(),
|
|
108
|
-
row.getRightVisibleCells(),
|
|
109
|
-
],
|
|
110
|
-
(left, center, right) => [...left, ...center, ...right],
|
|
111
|
-
{
|
|
112
|
-
key: 'row.getVisibleCells',
|
|
113
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
114
|
-
}
|
|
115
|
-
),
|
|
116
|
-
getCenterVisibleCells: memo(
|
|
117
|
-
() => [
|
|
118
|
-
row._getAllVisibleCells(),
|
|
119
|
-
instance.getState().columnPinning.left,
|
|
120
|
-
instance.getState().columnPinning.right,
|
|
121
|
-
],
|
|
122
|
-
(allCells, left, right) => {
|
|
123
|
-
const leftAndRight = [...(left ?? []), ...(right ?? [])]
|
|
124
|
-
|
|
125
|
-
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
key: 'row.getCenterVisibleCells',
|
|
129
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
130
|
-
}
|
|
131
|
-
),
|
|
132
|
-
getLeftVisibleCells: memo(
|
|
133
|
-
() => [
|
|
134
|
-
row._getAllVisibleCells(),
|
|
135
|
-
instance.getState().columnPinning.left,
|
|
136
|
-
,
|
|
137
|
-
],
|
|
138
|
-
(allCells, left) => {
|
|
139
|
-
const cells = (left ?? [])
|
|
140
|
-
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
141
|
-
.filter(Boolean)
|
|
142
|
-
|
|
143
|
-
return cells
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
key: 'row.getLeftVisibleCells',
|
|
147
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
148
|
-
}
|
|
149
|
-
),
|
|
150
|
-
getRightVisibleCells: memo(
|
|
151
|
-
() => [
|
|
152
|
-
row._getAllVisibleCells(),
|
|
153
|
-
instance.getState().columnPinning.right,
|
|
154
|
-
],
|
|
155
|
-
(allCells, right) => {
|
|
156
|
-
const cells = (right ?? [])
|
|
157
|
-
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
158
|
-
.filter(Boolean)
|
|
159
|
-
|
|
160
|
-
return cells
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
key: 'row.getRightVisibleCells',
|
|
164
|
-
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
165
|
-
}
|
|
166
|
-
),
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
getInstance: <TGenerics extends AnyGenerics>(
|
|
73
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
171
74
|
instance: TableInstance<TGenerics>
|
|
172
75
|
): HeadersInstance<TGenerics> => {
|
|
173
76
|
return {
|
|
@@ -177,6 +80,7 @@ export const Headers = {
|
|
|
177
80
|
id?: string
|
|
178
81
|
isPlaceholder?: boolean
|
|
179
82
|
placeholderId?: string
|
|
83
|
+
index: number
|
|
180
84
|
depth: number
|
|
181
85
|
}
|
|
182
86
|
) => {
|
|
@@ -185,20 +89,22 @@ export const Headers = {
|
|
|
185
89
|
let header: CoreHeader<TGenerics> = {
|
|
186
90
|
id,
|
|
187
91
|
column,
|
|
92
|
+
index: options.index,
|
|
188
93
|
isPlaceholder: options.isPlaceholder,
|
|
189
94
|
placeholderId: options.placeholderId,
|
|
190
95
|
depth: options.depth,
|
|
191
96
|
subHeaders: [],
|
|
192
97
|
colSpan: 0,
|
|
193
98
|
rowSpan: 0,
|
|
194
|
-
|
|
99
|
+
headerGroup: null!,
|
|
100
|
+
getSize: () => {
|
|
195
101
|
let sum = 0
|
|
196
102
|
|
|
197
103
|
const recurse = (header: CoreHeader<TGenerics>) => {
|
|
198
104
|
if (header.subHeaders.length) {
|
|
199
105
|
header.subHeaders.forEach(recurse)
|
|
200
106
|
} else {
|
|
201
|
-
sum += header.column.
|
|
107
|
+
sum += header.column.getSize() ?? 0
|
|
202
108
|
}
|
|
203
109
|
}
|
|
204
110
|
|
|
@@ -206,6 +112,15 @@ export const Headers = {
|
|
|
206
112
|
|
|
207
113
|
return sum
|
|
208
114
|
},
|
|
115
|
+
getStart: () => {
|
|
116
|
+
if (header.index > 0) {
|
|
117
|
+
const prevSiblingHeader =
|
|
118
|
+
header.headerGroup.headers[header.index - 1]
|
|
119
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return 0
|
|
123
|
+
},
|
|
209
124
|
getLeafHeaders: (): Header<TGenerics>[] => {
|
|
210
125
|
const leafHeaders: CoreHeader<TGenerics>[] = []
|
|
211
126
|
|
|
@@ -242,11 +157,11 @@ export const Headers = {
|
|
|
242
157
|
: null,
|
|
243
158
|
}
|
|
244
159
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
160
|
+
instance._features.forEach(feature => {
|
|
161
|
+
Object.assign(header, feature.createHeader?.(header, instance))
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return header as Header<TGenerics>
|
|
250
165
|
},
|
|
251
166
|
|
|
252
167
|
// Header Groups
|
|
@@ -593,21 +508,11 @@ export const Headers = {
|
|
|
593
508
|
|
|
594
509
|
return propGetter(initialProps, userProps)
|
|
595
510
|
},
|
|
596
|
-
|
|
597
|
-
getTotalWidth: () => {
|
|
598
|
-
let width = 0
|
|
599
|
-
|
|
600
|
-
instance.getVisibleLeafColumns().forEach(column => {
|
|
601
|
-
width += column.getWidth() ?? 0
|
|
602
|
-
})
|
|
603
|
-
|
|
604
|
-
return width
|
|
605
|
-
},
|
|
606
511
|
}
|
|
607
512
|
},
|
|
608
513
|
}
|
|
609
514
|
|
|
610
|
-
export function buildHeaderGroups<TGenerics extends
|
|
515
|
+
export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
611
516
|
allColumns: Column<TGenerics>[],
|
|
612
517
|
columnsToGroup: Column<TGenerics>[],
|
|
613
518
|
instance: TableInstance<TGenerics>,
|
|
@@ -653,13 +558,13 @@ export function buildHeaderGroups<TGenerics extends AnyGenerics>(
|
|
|
653
558
|
}
|
|
654
559
|
|
|
655
560
|
// The parent columns we're going to scan next
|
|
656
|
-
const
|
|
561
|
+
const pendingParentHeaders: Header<TGenerics>[] = []
|
|
657
562
|
|
|
658
563
|
// Scan each column for parents
|
|
659
564
|
headersToGroup.forEach(headerToGroup => {
|
|
660
565
|
// What is the latest (last) parent column?
|
|
661
566
|
|
|
662
|
-
const
|
|
567
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0]
|
|
663
568
|
|
|
664
569
|
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth
|
|
665
570
|
|
|
@@ -675,41 +580,45 @@ export function buildHeaderGroups<TGenerics extends AnyGenerics>(
|
|
|
675
580
|
isPlaceholder = true
|
|
676
581
|
}
|
|
677
582
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
.join('_'),
|
|
682
|
-
isPlaceholder,
|
|
683
|
-
placeholderId: isPlaceholder
|
|
684
|
-
? `${parentHeaders.filter(d => d.column === column).length}`
|
|
685
|
-
: undefined,
|
|
686
|
-
depth,
|
|
687
|
-
})
|
|
688
|
-
|
|
689
|
-
if (!latestParentHeader || latestParentHeader.column !== header.column) {
|
|
690
|
-
header.subHeaders.push(headerToGroup)
|
|
691
|
-
parentHeaders.push(header)
|
|
583
|
+
if (latestPendingParentHeader?.column === column) {
|
|
584
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
585
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup)
|
|
692
586
|
} else {
|
|
693
|
-
|
|
694
|
-
|
|
587
|
+
// This is a new header. Let's create it
|
|
588
|
+
const header = instance.createHeader(column, {
|
|
589
|
+
id: [headerFamily, depth, column.id, headerToGroup?.id]
|
|
590
|
+
.filter(Boolean)
|
|
591
|
+
.join('_'),
|
|
592
|
+
isPlaceholder,
|
|
593
|
+
placeholderId: isPlaceholder
|
|
594
|
+
? `${pendingParentHeaders.filter(d => d.column === column).length}`
|
|
595
|
+
: undefined,
|
|
596
|
+
depth,
|
|
597
|
+
index: pendingParentHeaders.length,
|
|
598
|
+
})
|
|
695
599
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
600
|
+
// Add the headerToGroup as a subHeader of the new header
|
|
601
|
+
header.subHeaders.push(headerToGroup)
|
|
602
|
+
// Add the new header to the pendingParentHeaders to get grouped
|
|
603
|
+
// in the next batch
|
|
604
|
+
pendingParentHeaders.push(header)
|
|
605
|
+
}
|
|
699
606
|
|
|
700
607
|
headerGroup.headers.push(headerToGroup)
|
|
608
|
+
headerToGroup.headerGroup = headerGroup
|
|
701
609
|
})
|
|
702
610
|
|
|
703
611
|
headerGroups.push(headerGroup)
|
|
704
612
|
|
|
705
613
|
if (depth > 0) {
|
|
706
|
-
createHeaderGroup(
|
|
614
|
+
createHeaderGroup(pendingParentHeaders, depth - 1)
|
|
707
615
|
}
|
|
708
616
|
}
|
|
709
617
|
|
|
710
|
-
const bottomHeaders = columnsToGroup.map(column =>
|
|
618
|
+
const bottomHeaders = columnsToGroup.map((column, index) =>
|
|
711
619
|
instance.createHeader(column, {
|
|
712
620
|
depth: maxDepth,
|
|
621
|
+
index,
|
|
713
622
|
})
|
|
714
623
|
)
|
|
715
624
|
|
package/src/features/Ordering.ts
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
OnChangeFn,
|
|
6
6
|
Updater,
|
|
7
7
|
Column,
|
|
8
|
-
|
|
9
|
-
PartialGenerics,
|
|
8
|
+
TableGenerics,
|
|
10
9
|
} from '../types'
|
|
11
10
|
|
|
12
11
|
import { Grouping } from './Grouping'
|
|
@@ -25,10 +24,12 @@ export type ColumnOrderDefaultOptions = {
|
|
|
25
24
|
onColumnOrderChange: OnChangeFn<ColumnOrderState>
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export type ColumnOrderInstance<TGenerics extends
|
|
27
|
+
export type ColumnOrderInstance<TGenerics extends TableGenerics> = {
|
|
29
28
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void
|
|
30
29
|
resetColumnOrder: () => void
|
|
31
|
-
|
|
30
|
+
_getOrderColumnsFn: () => (
|
|
31
|
+
columns: Column<TGenerics>[]
|
|
32
|
+
) => Column<TGenerics>[]
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
//
|
|
@@ -40,7 +41,7 @@ export const Ordering = {
|
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
|
|
43
|
-
getDefaultOptions: <TGenerics extends
|
|
44
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
44
45
|
instance: TableInstance<TGenerics>
|
|
45
46
|
): ColumnOrderDefaultOptions => {
|
|
46
47
|
return {
|
|
@@ -48,7 +49,7 @@ export const Ordering = {
|
|
|
48
49
|
}
|
|
49
50
|
},
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
52
53
|
instance: TableInstance<TGenerics>
|
|
53
54
|
): ColumnOrderInstance<TGenerics> => {
|
|
54
55
|
return {
|
|
@@ -57,7 +58,7 @@ export const Ordering = {
|
|
|
57
58
|
resetColumnOrder: () => {
|
|
58
59
|
instance.setColumnOrder(instance.initialState.columnOrder ?? [])
|
|
59
60
|
},
|
|
60
|
-
|
|
61
|
+
_getOrderColumnsFn: memo(
|
|
61
62
|
() => [
|
|
62
63
|
instance.getState().columnOrder,
|
|
63
64
|
instance.getState().grouping,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OnChangeFn,
|
|
3
|
-
|
|
4
|
-
PartialGenerics,
|
|
3
|
+
TableGenerics,
|
|
5
4
|
TableInstance,
|
|
6
5
|
RowModel,
|
|
7
6
|
Updater,
|
|
@@ -18,7 +17,7 @@ export type PaginationTableState = {
|
|
|
18
17
|
pagination: PaginationState
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
export type PaginationOptions<TGenerics extends
|
|
20
|
+
export type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
22
21
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
23
22
|
autoResetPageIndex?: boolean
|
|
24
23
|
getPaginationRowModel?: (
|
|
@@ -31,7 +30,7 @@ export type PaginationDefaultOptions = {
|
|
|
31
30
|
autoResetPageIndex: boolean
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
export type PaginationInstance<TGenerics extends
|
|
33
|
+
export type PaginationInstance<TGenerics extends TableGenerics> = {
|
|
35
34
|
queueResetPageIndex: () => void
|
|
36
35
|
setPagination: (updater: Updater<PaginationState>) => void
|
|
37
36
|
resetPagination: () => void
|
|
@@ -64,7 +63,7 @@ export const Pagination = {
|
|
|
64
63
|
}
|
|
65
64
|
},
|
|
66
65
|
|
|
67
|
-
getDefaultOptions: <TGenerics extends
|
|
66
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
68
67
|
instance: TableInstance<TGenerics>
|
|
69
68
|
): PaginationDefaultOptions => {
|
|
70
69
|
return {
|
|
@@ -73,7 +72,7 @@ export const Pagination = {
|
|
|
73
72
|
}
|
|
74
73
|
},
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
77
76
|
instance: TableInstance<TGenerics>
|
|
78
77
|
): PaginationInstance<TGenerics> => {
|
|
79
78
|
let registered = false
|
package/src/features/Pinning.ts
CHANGED
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
Updater,
|
|
4
4
|
TableInstance,
|
|
5
5
|
Column,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
TableGenerics,
|
|
7
|
+
Row,
|
|
8
|
+
Cell,
|
|
8
9
|
} from '../types'
|
|
9
|
-
import { functionalUpdate, makeStateUpdater } from '../utils'
|
|
10
|
+
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
10
11
|
|
|
11
|
-
type ColumnPinningPosition = false | 'left' | 'right'
|
|
12
|
+
export type ColumnPinningPosition = false | 'left' | 'right'
|
|
12
13
|
|
|
13
14
|
export type ColumnPinningState = {
|
|
14
15
|
left?: string[]
|
|
@@ -40,7 +41,19 @@ export type ColumnPinningColumn = {
|
|
|
40
41
|
pin: (position: ColumnPinningPosition) => void
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export type
|
|
44
|
+
export type ColumnPinningRow<TGenerics extends TableGenerics> = {
|
|
45
|
+
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
46
|
+
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
47
|
+
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ColumnPinningCell<TGenerics extends TableGenerics> = {
|
|
51
|
+
getLeftVisibleCells: () => Cell<TGenerics>[]
|
|
52
|
+
getCenterVisibleCells: () => Cell<TGenerics>[]
|
|
53
|
+
getRightVisibleCells: () => Cell<TGenerics>[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
|
|
44
57
|
setColumnPinning: (updater: Updater<ColumnPinningState>) => void
|
|
45
58
|
resetColumnPinning: () => void
|
|
46
59
|
pinColumn: (columnId: string, position: ColumnPinningPosition) => void
|
|
@@ -48,6 +61,9 @@ export type ColumnPinningInstance<TGenerics extends AnyGenerics> = {
|
|
|
48
61
|
getColumnIsPinned: (columnId: string) => ColumnPinningPosition
|
|
49
62
|
getColumnPinnedIndex: (columnId: string) => number
|
|
50
63
|
getIsSomeColumnsPinned: () => boolean
|
|
64
|
+
getLeftLeafColumns: () => Column<TGenerics>[]
|
|
65
|
+
getRightLeafColumns: () => Column<TGenerics>[]
|
|
66
|
+
getCenterLeafColumns: () => Column<TGenerics>[]
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
//
|
|
@@ -62,7 +78,7 @@ export const Pinning = {
|
|
|
62
78
|
}
|
|
63
79
|
},
|
|
64
80
|
|
|
65
|
-
getDefaultOptions: <TGenerics extends
|
|
81
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
66
82
|
instance: TableInstance<TGenerics>
|
|
67
83
|
): ColumnPinningDefaultOptions => {
|
|
68
84
|
return {
|
|
@@ -70,7 +86,7 @@ export const Pinning = {
|
|
|
70
86
|
}
|
|
71
87
|
},
|
|
72
88
|
|
|
73
|
-
createColumn: <TGenerics extends
|
|
89
|
+
createColumn: <TGenerics extends TableGenerics>(
|
|
74
90
|
column: Column<TGenerics>,
|
|
75
91
|
instance: TableInstance<TGenerics>
|
|
76
92
|
): ColumnPinningColumn => {
|
|
@@ -82,7 +98,129 @@ export const Pinning = {
|
|
|
82
98
|
}
|
|
83
99
|
},
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
102
|
+
row: Row<TGenerics>,
|
|
103
|
+
instance: TableInstance<TGenerics>
|
|
104
|
+
): ColumnPinningRow<TGenerics> => {
|
|
105
|
+
return {
|
|
106
|
+
getCenterVisibleCells: memo(
|
|
107
|
+
() => [
|
|
108
|
+
row._getAllVisibleCells(),
|
|
109
|
+
instance.getState().columnPinning.left,
|
|
110
|
+
instance.getState().columnPinning.right,
|
|
111
|
+
],
|
|
112
|
+
(allCells, left, right) => {
|
|
113
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
114
|
+
|
|
115
|
+
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: 'row.getCenterVisibleCells',
|
|
119
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
getLeftVisibleCells: memo(
|
|
123
|
+
() => [
|
|
124
|
+
row._getAllVisibleCells(),
|
|
125
|
+
instance.getState().columnPinning.left,
|
|
126
|
+
,
|
|
127
|
+
],
|
|
128
|
+
(allCells, left) => {
|
|
129
|
+
const cells = (left ?? [])
|
|
130
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
131
|
+
.filter(Boolean)
|
|
132
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
133
|
+
|
|
134
|
+
return cells
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
key: 'row.getLeftVisibleCells',
|
|
138
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
139
|
+
}
|
|
140
|
+
),
|
|
141
|
+
getRightVisibleCells: memo(
|
|
142
|
+
() => [
|
|
143
|
+
row._getAllVisibleCells(),
|
|
144
|
+
instance.getState().columnPinning.right,
|
|
145
|
+
],
|
|
146
|
+
(allCells, right) => {
|
|
147
|
+
const cells = (right ?? [])
|
|
148
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
151
|
+
|
|
152
|
+
return cells
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
key: 'row.getRightVisibleCells',
|
|
156
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
createCell: <TGenerics extends TableGenerics>(
|
|
163
|
+
cell: Cell<TGenerics>,
|
|
164
|
+
instance: TableInstance<TGenerics>
|
|
165
|
+
): ColumnPinningCell<TGenerics> => {
|
|
166
|
+
return {
|
|
167
|
+
getCenterVisibleCells: memo(
|
|
168
|
+
() => [
|
|
169
|
+
cell.row._getAllVisibleCells(),
|
|
170
|
+
instance.getState().columnPinning.left,
|
|
171
|
+
instance.getState().columnPinning.right,
|
|
172
|
+
],
|
|
173
|
+
(allCells, left, right) => {
|
|
174
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
175
|
+
|
|
176
|
+
return allCells.filter(d => !leftAndRight.includes(d.columnId))
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: 'row.getCenterVisibleCells',
|
|
180
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
getLeftVisibleCells: memo(
|
|
184
|
+
() => [
|
|
185
|
+
cell.row._getAllVisibleCells(),
|
|
186
|
+
instance.getState().columnPinning.left,
|
|
187
|
+
,
|
|
188
|
+
],
|
|
189
|
+
(allCells, left) => {
|
|
190
|
+
const cells = (left ?? [])
|
|
191
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
192
|
+
.filter(Boolean)
|
|
193
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
194
|
+
|
|
195
|
+
return cells
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: 'row.getLeftVisibleCells',
|
|
199
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
getRightVisibleCells: memo(
|
|
203
|
+
() => [
|
|
204
|
+
cell.row._getAllVisibleCells(),
|
|
205
|
+
instance.getState().columnPinning.right,
|
|
206
|
+
],
|
|
207
|
+
(allCells, right) => {
|
|
208
|
+
const cells = (right ?? [])
|
|
209
|
+
.map(columnId => allCells.find(cell => cell.columnId === columnId)!)
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
|
|
212
|
+
|
|
213
|
+
return cells
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'row.getRightVisibleCells',
|
|
217
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
86
224
|
instance: TableInstance<TGenerics>
|
|
87
225
|
): ColumnPinningInstance<TGenerics> => {
|
|
88
226
|
return {
|
|
@@ -177,6 +315,58 @@ export const Pinning = {
|
|
|
177
315
|
|
|
178
316
|
return Boolean(left?.length || right?.length)
|
|
179
317
|
},
|
|
318
|
+
|
|
319
|
+
getLeftLeafColumns: memo(
|
|
320
|
+
() => [
|
|
321
|
+
instance.getAllLeafColumns(),
|
|
322
|
+
instance.getState().columnPinning.left,
|
|
323
|
+
],
|
|
324
|
+
(allColumns, left) => {
|
|
325
|
+
return (left ?? [])
|
|
326
|
+
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
327
|
+
.filter(Boolean)
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
key: 'getLeftLeafColumns',
|
|
331
|
+
debug: () =>
|
|
332
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
333
|
+
}
|
|
334
|
+
),
|
|
335
|
+
|
|
336
|
+
getRightLeafColumns: memo(
|
|
337
|
+
() => [
|
|
338
|
+
instance.getAllLeafColumns(),
|
|
339
|
+
instance.getState().columnPinning.right,
|
|
340
|
+
],
|
|
341
|
+
(allColumns, right) => {
|
|
342
|
+
return (right ?? [])
|
|
343
|
+
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
344
|
+
.filter(Boolean)
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
key: 'getRightLeafColumns',
|
|
348
|
+
debug: () =>
|
|
349
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
350
|
+
}
|
|
351
|
+
),
|
|
352
|
+
|
|
353
|
+
getCenterLeafColumns: memo(
|
|
354
|
+
() => [
|
|
355
|
+
instance.getAllLeafColumns(),
|
|
356
|
+
instance.getState().columnPinning.left,
|
|
357
|
+
instance.getState().columnPinning.right,
|
|
358
|
+
],
|
|
359
|
+
(allColumns, left, right) => {
|
|
360
|
+
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
361
|
+
|
|
362
|
+
return allColumns.filter(d => !leftAndRight.includes(d.id))
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
key: 'getCenterLeafColumns',
|
|
366
|
+
debug: () =>
|
|
367
|
+
instance.options.debugAll ?? instance.options.debugColumns,
|
|
368
|
+
}
|
|
369
|
+
),
|
|
180
370
|
}
|
|
181
371
|
},
|
|
182
372
|
}
|