@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.0
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 +120 -0
- package/build/cjs/aggregationFns.js.map +1 -0
- package/build/cjs/core/cell.js +40 -0
- package/build/cjs/core/cell.js.map +1 -0
- package/build/cjs/core/column.js +88 -0
- package/build/cjs/core/column.js.map +1 -0
- package/build/cjs/core/headers.js +403 -0
- package/build/cjs/core/headers.js.map +1 -0
- package/build/cjs/core/instance.js +255 -0
- package/build/cjs/core/instance.js.map +1 -0
- package/build/cjs/core/row.js +77 -0
- package/build/cjs/core/row.js.map +1 -0
- package/build/cjs/createTable.js +36 -29
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +157 -189
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +103 -155
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +155 -304
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +97 -157
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +30 -41
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +102 -105
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +131 -89
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +138 -267
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +82 -167
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +69 -115
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +107 -0
- package/build/cjs/filterFns.js.map +1 -0
- package/build/cjs/index.js +36 -23
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/sortingFns.js +124 -0
- package/build/cjs/sortingFns.js.map +1 -0
- package/build/cjs/utils/filterRowsUtils.js +117 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/getCoreRowModel.js +79 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +57 -0
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js +54 -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 +139 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +161 -0
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
- package/build/cjs/utils/getPaginationRowModel.js +61 -0
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
- package/build/cjs/utils/getSortedRowModel.js +110 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +38 -107
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2976 -3853
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +586 -408
- package/build/types/aggregationFns.d.ts +13 -0
- package/build/types/core/cell.d.ts +9 -0
- package/build/types/core/column.d.ts +40 -0
- package/build/types/core/headers.d.ts +46 -0
- package/build/types/core/instance.d.ts +57 -0
- package/build/types/core/row.d.ts +15 -0
- package/build/types/createTable.d.ts +47 -26
- package/build/types/features/ColumnSizing.d.ts +32 -44
- package/build/types/features/Expanding.d.ts +15 -26
- package/build/types/features/Filters.d.ts +64 -63
- package/build/types/features/Grouping.d.ts +32 -46
- package/build/types/features/Ordering.d.ts +7 -10
- package/build/types/features/Pagination.d.ts +16 -15
- package/build/types/features/Pinning.d.ts +16 -17
- package/build/types/features/RowSelection.d.ts +13 -33
- package/build/types/features/Sorting.d.ts +25 -44
- package/build/types/features/Visibility.d.ts +16 -25
- package/build/types/filterFns.d.ts +13 -0
- package/build/types/index.d.ts +16 -10
- package/build/types/sortingFns.d.ts +11 -0
- package/build/types/types.d.ts +37 -122
- package/build/types/utils/filterRowsUtils.d.ts +4 -0
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getExpandedRowModel.d.ts +7 -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/getFilteredRowModel.d.ts +2 -0
- package/build/types/utils/getGroupedRowModel.d.ts +2 -0
- package/build/types/utils/getPaginationRowModel.d.ts +4 -0
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +7 -11
- package/build/umd/index.development.js +3024 -3893
- 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 +9 -10
- package/src/.DS_Store +0 -0
- package/src/aggregationFns.ts +123 -0
- package/src/core/cell.ts +48 -0
- package/src/core/column.ts +147 -0
- package/src/core/headers.ts +575 -0
- package/src/core/instance.ts +361 -0
- package/src/core/row.ts +85 -0
- package/src/createTable.ts +188 -0
- package/src/features/ColumnSizing.ts +170 -185
- package/src/features/Expanding.ts +122 -194
- package/src/features/Filters.ts +301 -381
- package/src/features/Grouping.ts +160 -220
- package/src/features/Ordering.ts +24 -25
- package/src/features/Pagination.ts +90 -73
- package/src/features/Pinning.ts +186 -63
- package/src/features/RowSelection.ts +107 -245
- package/src/features/Sorting.ts +127 -225
- package/src/features/Visibility.ts +116 -132
- package/src/filterFns.ts +135 -0
- package/src/index.ts +29 -0
- package/src/{sortTypes.ts → sortingFns.ts} +63 -85
- package/src/types.ts +62 -168
- package/src/utils/filterRowsUtils.ts +112 -0
- package/src/utils/getCoreRowModel.ts +84 -0
- package/src/utils/getExpandedRowModel.ts +54 -0
- package/src/utils/getFacetedMinMaxValues.ts +40 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/getFilteredRowModel.ts +159 -0
- package/src/utils/getGroupedRowModel.ts +175 -0
- package/src/utils/getPaginationRowModel.ts +48 -0
- package/src/utils/getSortedRowModel.ts +116 -0
- package/src/utils.ts +126 -0
- 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/features/Headers.js +0 -630
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.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/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/features/Headers.d.ts +0 -43
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- 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/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -137
- package/src/features/Headers.ts +0 -747
- package/src/filterTypes.ts +0 -188
- package/src/index.tsx +0 -23
- 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/types.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
CoreColumn,
|
|
4
|
-
CoreColumnDef,
|
|
5
|
-
CoreOptions,
|
|
6
|
-
CoreRow,
|
|
7
|
-
TableCore,
|
|
8
|
-
} from './core'
|
|
1
|
+
import { CoreOptions, CoreTableState, CoreInstance } from './core/instance'
|
|
2
|
+
import { CoreColumn, CoreColumnDef } from './core/column'
|
|
9
3
|
import {
|
|
10
4
|
VisibilityInstance,
|
|
11
5
|
VisibilityTableState,
|
|
@@ -24,14 +18,16 @@ import {
|
|
|
24
18
|
ColumnPinningColumnDef,
|
|
25
19
|
ColumnPinningInstance,
|
|
26
20
|
ColumnPinningOptions,
|
|
21
|
+
ColumnPinningRow,
|
|
27
22
|
ColumnPinningTableState,
|
|
28
23
|
} from './features/Pinning'
|
|
29
|
-
import {
|
|
24
|
+
import { CoreHeader, CoreHeaderGroup, HeadersInstance } from './core/headers'
|
|
30
25
|
import {
|
|
31
26
|
FiltersColumn,
|
|
32
27
|
FiltersColumnDef,
|
|
33
28
|
FiltersInstance,
|
|
34
29
|
FiltersOptions,
|
|
30
|
+
FiltersRow,
|
|
35
31
|
FiltersTableState,
|
|
36
32
|
} from './features/Filters'
|
|
37
33
|
import {
|
|
@@ -42,6 +38,7 @@ import {
|
|
|
42
38
|
SortingTableState,
|
|
43
39
|
} from './features/Sorting'
|
|
44
40
|
import {
|
|
41
|
+
GroupingCell,
|
|
45
42
|
GroupingColumn,
|
|
46
43
|
GroupingColumnDef,
|
|
47
44
|
GroupingInstance,
|
|
@@ -55,7 +52,6 @@ import {
|
|
|
55
52
|
ExpandedTableState,
|
|
56
53
|
ExpandedRow,
|
|
57
54
|
} from './features/Expanding'
|
|
58
|
-
import { Overwrite } from './utils'
|
|
59
55
|
import {
|
|
60
56
|
ColumnSizingColumn,
|
|
61
57
|
ColumnSizingColumnDef,
|
|
@@ -65,6 +61,7 @@ import {
|
|
|
65
61
|
ColumnSizingTableState,
|
|
66
62
|
} from './features/ColumnSizing'
|
|
67
63
|
import {
|
|
64
|
+
PaginationInitialTableState,
|
|
68
65
|
PaginationInstance,
|
|
69
66
|
PaginationOptions,
|
|
70
67
|
PaginationTableState,
|
|
@@ -75,27 +72,34 @@ import {
|
|
|
75
72
|
RowSelectionRow,
|
|
76
73
|
RowSelectionTableState,
|
|
77
74
|
} from './features/RowSelection'
|
|
75
|
+
import { CoreRow } from './core/row'
|
|
76
|
+
import { PartialKeys } from './utils'
|
|
77
|
+
import { CoreCell } from './core/cell'
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// }
|
|
79
|
+
export type Updater<T> = T | ((old: T) => T)
|
|
80
|
+
export type OnChangeFn<T> = (updaterOrValue: Updater<T>) => void
|
|
82
81
|
|
|
83
|
-
export type
|
|
84
|
-
Row
|
|
85
|
-
Value
|
|
86
|
-
FilterFns
|
|
87
|
-
SortingFns
|
|
88
|
-
AggregationFns
|
|
82
|
+
export type TableGenerics = {
|
|
83
|
+
Row?: any
|
|
84
|
+
Value?: any
|
|
85
|
+
FilterFns?: any
|
|
86
|
+
SortingFns?: any
|
|
87
|
+
AggregationFns?: any
|
|
88
|
+
Renderer?: any
|
|
89
|
+
Rendered?: any
|
|
90
|
+
ColumnMeta?: any
|
|
91
|
+
TableMeta?: any
|
|
92
|
+
FilterMeta?: any
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
export type
|
|
95
|
+
export type AnyRender = (Comp: any, props: any) => any
|
|
92
96
|
|
|
93
|
-
export type TableInstance<TGenerics extends
|
|
94
|
-
|
|
97
|
+
export type TableInstance<TGenerics extends TableGenerics> =
|
|
98
|
+
CoreInstance<TGenerics> &
|
|
99
|
+
HeadersInstance<TGenerics> &
|
|
95
100
|
VisibilityInstance<TGenerics> &
|
|
96
101
|
ColumnOrderInstance<TGenerics> &
|
|
97
102
|
ColumnPinningInstance<TGenerics> &
|
|
98
|
-
HeadersInstance<TGenerics> &
|
|
99
103
|
FiltersInstance<TGenerics> &
|
|
100
104
|
SortingInstance<TGenerics> &
|
|
101
105
|
GroupingInstance<TGenerics> &
|
|
@@ -104,14 +108,7 @@ export type TableInstance<TGenerics extends PartialGenerics> =
|
|
|
104
108
|
PaginationInstance<TGenerics> &
|
|
105
109
|
RowSelectionInstance<TGenerics>
|
|
106
110
|
|
|
107
|
-
export type
|
|
108
|
-
| React.ReactNode
|
|
109
|
-
| React.FunctionComponent<TProps>
|
|
110
|
-
| React.Component<TProps>
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
export type Options<TGenerics extends PartialGenerics> =
|
|
111
|
+
export type TableOptionsResolved<TGenerics extends TableGenerics> =
|
|
115
112
|
CoreOptions<TGenerics> &
|
|
116
113
|
VisibilityOptions &
|
|
117
114
|
ColumnOrderOptions &
|
|
@@ -124,10 +121,13 @@ export type Options<TGenerics extends PartialGenerics> =
|
|
|
124
121
|
PaginationOptions<TGenerics> &
|
|
125
122
|
RowSelectionOptions<TGenerics>
|
|
126
123
|
|
|
127
|
-
export type
|
|
128
|
-
|
|
124
|
+
export type TableOptions<TGenerics extends TableGenerics> = Omit<
|
|
125
|
+
PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>,
|
|
126
|
+
'render'
|
|
127
|
+
>
|
|
129
128
|
|
|
130
|
-
export type TableState =
|
|
129
|
+
export type TableState = CoreTableState &
|
|
130
|
+
VisibilityTableState &
|
|
131
131
|
ColumnOrderTableState &
|
|
132
132
|
ColumnPinningTableState &
|
|
133
133
|
FiltersTableState &
|
|
@@ -138,9 +138,24 @@ export type TableState = VisibilityTableState &
|
|
|
138
138
|
PaginationTableState &
|
|
139
139
|
RowSelectionTableState
|
|
140
140
|
|
|
141
|
-
export type
|
|
141
|
+
export type InitialTableState = Partial<
|
|
142
|
+
CoreTableState &
|
|
143
|
+
VisibilityTableState &
|
|
144
|
+
ColumnOrderTableState &
|
|
145
|
+
ColumnPinningTableState &
|
|
146
|
+
FiltersTableState &
|
|
147
|
+
SortingTableState &
|
|
148
|
+
ExpandedTableState &
|
|
149
|
+
GroupingTableState &
|
|
150
|
+
ColumnSizingTableState &
|
|
151
|
+
PaginationInitialTableState &
|
|
152
|
+
RowSelectionTableState
|
|
153
|
+
>
|
|
154
|
+
|
|
155
|
+
export type Row<TGenerics extends TableGenerics> = CoreRow<TGenerics> &
|
|
142
156
|
VisibilityRow<TGenerics> &
|
|
143
|
-
|
|
157
|
+
ColumnPinningRow<TGenerics> &
|
|
158
|
+
FiltersRow<TGenerics> &
|
|
144
159
|
GroupingRow &
|
|
145
160
|
RowSelectionRow &
|
|
146
161
|
ExpandedRow
|
|
@@ -149,7 +164,7 @@ export type RowValues = {
|
|
|
149
164
|
[key: string]: any
|
|
150
165
|
}
|
|
151
166
|
|
|
152
|
-
export type RowModel<TGenerics extends
|
|
167
|
+
export type RowModel<TGenerics extends TableGenerics> = {
|
|
153
168
|
rows: Row<TGenerics>[]
|
|
154
169
|
flatRows: Row<TGenerics>[]
|
|
155
170
|
rowsById: Record<string, Row<TGenerics>>
|
|
@@ -157,17 +172,11 @@ export type RowModel<TGenerics extends PartialGenerics> = {
|
|
|
157
172
|
|
|
158
173
|
export type AccessorFn<TData> = (originalRow: TData, index: number) => any
|
|
159
174
|
|
|
160
|
-
export
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
export type _NonGenerated<T> = Overwrite<
|
|
164
|
-
T,
|
|
165
|
-
{
|
|
166
|
-
[Please_use_the_create_table_column_utilities_to_define_columns]?: never
|
|
167
|
-
}
|
|
168
|
-
>
|
|
175
|
+
export type Renderable<TGenerics extends TableGenerics, TProps> =
|
|
176
|
+
| string
|
|
177
|
+
| ((props: TProps) => TGenerics['Rendered'])
|
|
169
178
|
|
|
170
|
-
export type ColumnDef<TGenerics extends
|
|
179
|
+
export type ColumnDef<TGenerics extends TableGenerics> =
|
|
171
180
|
CoreColumnDef<TGenerics> &
|
|
172
181
|
VisibilityColumnDef &
|
|
173
182
|
ColumnPinningColumnDef &
|
|
@@ -176,8 +185,7 @@ export type ColumnDef<TGenerics extends PartialGenerics> =
|
|
|
176
185
|
GroupingColumnDef<TGenerics> &
|
|
177
186
|
ColumnSizingColumnDef
|
|
178
187
|
|
|
179
|
-
export type Column<TGenerics extends
|
|
180
|
-
CoreColumn<TGenerics> &
|
|
188
|
+
export type Column<TGenerics extends TableGenerics> = CoreColumn<TGenerics> &
|
|
181
189
|
ColumnVisibilityColumn &
|
|
182
190
|
ColumnPinningColumn &
|
|
183
191
|
FiltersColumn<TGenerics> &
|
|
@@ -185,127 +193,13 @@ export type Column<TGenerics extends PartialGenerics> = ColumnDef<TGenerics> &
|
|
|
185
193
|
GroupingColumn<TGenerics> &
|
|
186
194
|
ColumnSizingColumn<TGenerics>
|
|
187
195
|
|
|
188
|
-
export type Cell<TGenerics extends
|
|
189
|
-
|
|
190
|
-
rowId: string
|
|
191
|
-
columnId: string
|
|
192
|
-
value: TGenerics['Value']
|
|
193
|
-
row: Row<TGenerics>
|
|
194
|
-
column: Column<TGenerics>
|
|
195
|
-
getCellProps: PropGetter<CellProps>
|
|
196
|
-
renderCell: () => React.ReactNode
|
|
197
|
-
}
|
|
196
|
+
export type Cell<TGenerics extends TableGenerics> = CoreCell<TGenerics> &
|
|
197
|
+
GroupingCell<TGenerics>
|
|
198
198
|
|
|
199
|
-
export type Header<TGenerics extends
|
|
199
|
+
export type Header<TGenerics extends TableGenerics> = CoreHeader<TGenerics> &
|
|
200
200
|
ColumnSizingHeader<TGenerics>
|
|
201
201
|
|
|
202
|
-
export type
|
|
203
|
-
|
|
204
|
-
depth: number
|
|
205
|
-
column: Column<TGenerics>
|
|
206
|
-
getWidth: () => number
|
|
207
|
-
subHeaders: Header<TGenerics>[]
|
|
208
|
-
colSpan?: number
|
|
209
|
-
rowSpan?: number
|
|
210
|
-
getHeaderProps: PropGetter<HeaderProps>
|
|
211
|
-
getFooterProps: PropGetter<HeaderProps>
|
|
212
|
-
getLeafHeaders: () => Header<TGenerics>[]
|
|
213
|
-
isPlaceholder?: boolean
|
|
214
|
-
placeholderId?: string
|
|
215
|
-
renderHeader: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
|
|
216
|
-
renderFooter: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export type HeaderGroup<TGenerics extends PartialGenerics> = {
|
|
220
|
-
id: string
|
|
221
|
-
depth: number
|
|
222
|
-
headers: Header<TGenerics>[]
|
|
223
|
-
getHeaderGroupProps: PropGetter<HeaderGroupProps>
|
|
224
|
-
getFooterGroupProps: PropGetter<FooterGroupProps>
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export type HeaderRenderProps<THeader> = {
|
|
228
|
-
header: THeader
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export type FooterRenderProps<THeader> = {
|
|
232
|
-
header: THeader
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export type CellRenderProps<TCell, TRow> = {
|
|
236
|
-
cell: TCell
|
|
237
|
-
row: TRow
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export type TableProps = {
|
|
241
|
-
role: string
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export type TableBodyProps = {
|
|
245
|
-
role: string
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export type TableHeadProps = {
|
|
249
|
-
key: string
|
|
250
|
-
role: string
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export type TableFooterProps = {
|
|
254
|
-
key: string
|
|
255
|
-
role: string
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export type HeaderGroupProps = {
|
|
259
|
-
key: string
|
|
260
|
-
role: string
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export type FooterGroupProps = {
|
|
264
|
-
key: string
|
|
265
|
-
role: string
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export type HeaderProps = {
|
|
269
|
-
key: string
|
|
270
|
-
role: string
|
|
271
|
-
colSpan?: number
|
|
272
|
-
rowSpan?: number
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export type FooterProps = {
|
|
276
|
-
key: string
|
|
277
|
-
role: string
|
|
278
|
-
colSpan?: number
|
|
279
|
-
rowSpan?: number
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export type RowProps = {
|
|
283
|
-
key: string
|
|
284
|
-
role: string
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export type CellProps = {
|
|
288
|
-
key: string
|
|
289
|
-
role: string
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
export type PropGetter<TBase> = <TGetter extends Getter<TBase>>(
|
|
295
|
-
userProps?: TGetter
|
|
296
|
-
) => PropGetterValue<TBase, TGetter>
|
|
297
|
-
|
|
298
|
-
export type Getter<TInitial> =
|
|
299
|
-
| ((initial: TInitial) => object)
|
|
300
|
-
| object
|
|
301
|
-
| undefined
|
|
302
|
-
|
|
303
|
-
export type PropGetterValue<TBase, TGetter> = TGetter extends undefined
|
|
304
|
-
? TBase
|
|
305
|
-
: TGetter extends (...args: any[]) => infer TReturn
|
|
306
|
-
? Overwrite<TBase, TReturn>
|
|
307
|
-
: TGetter extends object
|
|
308
|
-
? Overwrite<TBase, TGetter>
|
|
309
|
-
: never
|
|
202
|
+
export type HeaderGroup<TGenerics extends TableGenerics> =
|
|
203
|
+
CoreHeaderGroup<TGenerics>
|
|
310
204
|
|
|
311
205
|
export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createRow } from '../core/row'
|
|
2
|
+
import { TableGenerics, Row, RowModel, TableInstance } from '../types'
|
|
3
|
+
|
|
4
|
+
export function filterRows<TGenerics extends TableGenerics>(
|
|
5
|
+
rows: Row<TGenerics>[],
|
|
6
|
+
filterRowImpl: (row: Row<TGenerics>) => any,
|
|
7
|
+
instance: TableInstance<TGenerics>
|
|
8
|
+
) {
|
|
9
|
+
if (instance.options.filterFromLeafRows) {
|
|
10
|
+
return filterRowModelFromLeafs(rows, filterRowImpl, instance)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return filterRowModelFromRoot(rows, filterRowImpl, instance)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
17
|
+
rowsToFilter: Row<TGenerics>[],
|
|
18
|
+
filterRow: (row: Row<TGenerics>) => Row<TGenerics>[],
|
|
19
|
+
instance: TableInstance<TGenerics>
|
|
20
|
+
): RowModel<TGenerics> {
|
|
21
|
+
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
22
|
+
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
23
|
+
|
|
24
|
+
let row
|
|
25
|
+
let newRow
|
|
26
|
+
|
|
27
|
+
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
28
|
+
const rows: Row<TGenerics>[] = []
|
|
29
|
+
|
|
30
|
+
// Filter from children up first
|
|
31
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
32
|
+
row = rowsToFilter[i]!
|
|
33
|
+
|
|
34
|
+
if (row.subRows?.length) {
|
|
35
|
+
newRow = createRow(instance, row.id, row.original, row.index, row.depth)
|
|
36
|
+
newRow.columnFilters = row.columnFilters
|
|
37
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
38
|
+
if (!newRow.subRows.length) {
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
row = newRow
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (filterRow(row)) {
|
|
45
|
+
rows.push(row)
|
|
46
|
+
newFilteredRowsById[row.id] = row
|
|
47
|
+
newFilteredRowsById[i] = row
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return rows
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
56
|
+
flatRows: newFilteredFlatRows,
|
|
57
|
+
rowsById: newFilteredRowsById,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
|
|
62
|
+
rowsToFilter: Row<TGenerics>[],
|
|
63
|
+
filterRow: (row: Row<TGenerics>) => any,
|
|
64
|
+
instance: TableInstance<TGenerics>
|
|
65
|
+
): RowModel<TGenerics> {
|
|
66
|
+
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
67
|
+
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
68
|
+
|
|
69
|
+
let rows
|
|
70
|
+
let row
|
|
71
|
+
let newRow
|
|
72
|
+
|
|
73
|
+
// Filters top level and nested rows
|
|
74
|
+
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
75
|
+
// Filter from parents downward first
|
|
76
|
+
|
|
77
|
+
rows = []
|
|
78
|
+
|
|
79
|
+
// Apply the filter to any subRows
|
|
80
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
81
|
+
row = rowsToFilter[i]!
|
|
82
|
+
|
|
83
|
+
const pass = filterRow(row)
|
|
84
|
+
|
|
85
|
+
if (pass) {
|
|
86
|
+
if (row.subRows?.length) {
|
|
87
|
+
newRow = createRow(
|
|
88
|
+
instance,
|
|
89
|
+
row.id,
|
|
90
|
+
row.original,
|
|
91
|
+
row.index,
|
|
92
|
+
row.depth
|
|
93
|
+
)
|
|
94
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
95
|
+
row = newRow
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
rows.push(row)
|
|
99
|
+
newFilteredFlatRows.push(row)
|
|
100
|
+
newFilteredRowsById[row.id] = row
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return rows
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
109
|
+
flatRows: newFilteredFlatRows,
|
|
110
|
+
rowsById: newFilteredRowsById,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createRow } from '../core/row'
|
|
2
|
+
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
3
|
+
import { memo } from '../utils'
|
|
4
|
+
|
|
5
|
+
export function getCoreRowModel<TGenerics extends TableGenerics>(): (
|
|
6
|
+
instance: TableInstance<TGenerics>
|
|
7
|
+
) => () => RowModel<TGenerics> {
|
|
8
|
+
return instance =>
|
|
9
|
+
memo(
|
|
10
|
+
() => [instance.options.data],
|
|
11
|
+
(
|
|
12
|
+
data
|
|
13
|
+
): {
|
|
14
|
+
rows: Row<TGenerics>[]
|
|
15
|
+
flatRows: Row<TGenerics>[]
|
|
16
|
+
rowsById: Record<string, Row<TGenerics>>
|
|
17
|
+
} => {
|
|
18
|
+
const rowModel: RowModel<TGenerics> = {
|
|
19
|
+
rows: [],
|
|
20
|
+
flatRows: [],
|
|
21
|
+
rowsById: {},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const accessRows = (
|
|
25
|
+
originalRows: TGenerics['Row'][],
|
|
26
|
+
depth = 0,
|
|
27
|
+
parent?: Row<TGenerics>
|
|
28
|
+
): Row<TGenerics>[] => {
|
|
29
|
+
const rows = [] as Row<TGenerics>[]
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
32
|
+
// This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
33
|
+
// if (!id) {
|
|
34
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
// Make the row
|
|
40
|
+
const row = createRow(
|
|
41
|
+
instance,
|
|
42
|
+
instance._getRowId(originalRows[i], i, parent),
|
|
43
|
+
originalRows[i],
|
|
44
|
+
i,
|
|
45
|
+
depth
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
// Keep track of every row in a flat array
|
|
49
|
+
rowModel.flatRows.push(row)
|
|
50
|
+
// Also keep track of every row by its ID
|
|
51
|
+
rowModel.rowsById[row.id] = row
|
|
52
|
+
// Push instance row into parent
|
|
53
|
+
rows.push(row)
|
|
54
|
+
|
|
55
|
+
// Get the original subrows
|
|
56
|
+
if (instance.options.getSubRows) {
|
|
57
|
+
row.originalSubRows = instance.options.getSubRows(
|
|
58
|
+
originalRows[i],
|
|
59
|
+
i
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
// Then recursively access them
|
|
63
|
+
if (row.originalSubRows?.length) {
|
|
64
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return rows
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
rowModel.rows = accessRows(data)
|
|
73
|
+
|
|
74
|
+
return rowModel
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: process.env.NODE_ENV === 'development' && 'getRowModel',
|
|
78
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
79
|
+
onChange: () => {
|
|
80
|
+
instance._autoResetPageIndex()
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
|
|
4
|
+
export function getExpandedRowModel<TGenerics extends TableGenerics>(): (
|
|
5
|
+
instance: TableInstance<TGenerics>
|
|
6
|
+
) => () => RowModel<TGenerics> {
|
|
7
|
+
return instance =>
|
|
8
|
+
memo(
|
|
9
|
+
() => [
|
|
10
|
+
instance.getState().expanded,
|
|
11
|
+
instance.getPreExpandedRowModel(),
|
|
12
|
+
instance.options.paginateExpandedRows,
|
|
13
|
+
],
|
|
14
|
+
(expanded, rowModel, paginateExpandedRows) => {
|
|
15
|
+
if (
|
|
16
|
+
!rowModel.rows.length ||
|
|
17
|
+
// Do not expand if rows are not included in pagination
|
|
18
|
+
!paginateExpandedRows ||
|
|
19
|
+
(expanded !== true && !Object.keys(expanded ?? {}).length)
|
|
20
|
+
) {
|
|
21
|
+
return rowModel
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return expandRows(rowModel, instance)
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
|
|
28
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function expandRows<TGenerics extends TableGenerics>(
|
|
34
|
+
rowModel: RowModel<TGenerics>,
|
|
35
|
+
instance: TableInstance<TGenerics>
|
|
36
|
+
) {
|
|
37
|
+
const expandedRows: Row<TGenerics>[] = []
|
|
38
|
+
|
|
39
|
+
const handleRow = (row: Row<TGenerics>) => {
|
|
40
|
+
expandedRows.push(row)
|
|
41
|
+
|
|
42
|
+
if (row.subRows?.length && row.getIsExpanded()) {
|
|
43
|
+
row.subRows.forEach(handleRow)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
rowModel.rows.forEach(handleRow)
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
rows: expandedRows,
|
|
51
|
+
flatRows: rowModel.flatRows,
|
|
52
|
+
rowsById: rowModel.rowsById,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TableInstance, TableGenerics } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
|
|
4
|
+
export function getFacetedMinMaxValues<TGenerics extends TableGenerics>(): (
|
|
5
|
+
instance: TableInstance<TGenerics>,
|
|
6
|
+
columnId: string
|
|
7
|
+
) => () => undefined | [number, number] {
|
|
8
|
+
return (instance, columnId) =>
|
|
9
|
+
memo(
|
|
10
|
+
() => [instance.getColumn(columnId).getFacetedRowModel()],
|
|
11
|
+
facetedRowModel => {
|
|
12
|
+
const firstValue = facetedRowModel.flatRows[0]?.getValue(columnId)
|
|
13
|
+
|
|
14
|
+
if (typeof firstValue === 'undefined') {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let facetedMinMaxValues: [any, any] = [firstValue, firstValue]
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
21
|
+
const value = facetedRowModel.flatRows[i]?.getValue(columnId)
|
|
22
|
+
|
|
23
|
+
if (value < facetedMinMaxValues[0]) {
|
|
24
|
+
facetedMinMaxValues[0] = value
|
|
25
|
+
} else if (value > facetedMinMaxValues[1]) {
|
|
26
|
+
facetedMinMaxValues[1] = value
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return facetedMinMaxValues
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key:
|
|
34
|
+
process.env.NODE_ENV === 'development' &&
|
|
35
|
+
'getFacetedMinMaxValues_' + columnId,
|
|
36
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
37
|
+
onChange: () => {},
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
import { filterRows } from './filterRowsUtils'
|
|
4
|
+
|
|
5
|
+
export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
|
|
6
|
+
instance: TableInstance<TGenerics>,
|
|
7
|
+
columnId: string
|
|
8
|
+
) => () => RowModel<TGenerics> {
|
|
9
|
+
return (instance, columnId) =>
|
|
10
|
+
memo(
|
|
11
|
+
() => [
|
|
12
|
+
instance.getPreFilteredRowModel(),
|
|
13
|
+
instance.getState().columnFilters,
|
|
14
|
+
instance.getState().globalFilter,
|
|
15
|
+
instance.getFilteredRowModel(),
|
|
16
|
+
],
|
|
17
|
+
(preRowModel, columnFilters, globalFilter) => {
|
|
18
|
+
if (
|
|
19
|
+
!preRowModel.rows.length ||
|
|
20
|
+
(!columnFilters?.length && !globalFilter)
|
|
21
|
+
) {
|
|
22
|
+
return preRowModel
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const filterableIds = [
|
|
26
|
+
...columnFilters.map(d => d.id).filter(d => d !== columnId),
|
|
27
|
+
globalFilter ? '__global__' : undefined,
|
|
28
|
+
].filter(Boolean) as string[]
|
|
29
|
+
|
|
30
|
+
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
31
|
+
// Horizontally filter rows through each column
|
|
32
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
33
|
+
if (row.columnFilters[filterableIds[i]!] === false) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return filterRows(preRowModel.rows, filterRowsImpl, instance)
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key:
|
|
44
|
+
process.env.NODE_ENV === 'development' &&
|
|
45
|
+
'getFacetedRowModel_' + columnId,
|
|
46
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
47
|
+
onChange: () => {},
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
}
|