@tanstack/react-table 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/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
|
@@ -0,0 +1,3867 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-table
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* table-core
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) TanStack
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
function functionalUpdate(updater, input) {
|
|
26
|
+
return typeof updater === 'function' ? updater(input) : updater;
|
|
27
|
+
}
|
|
28
|
+
function noop() {//
|
|
29
|
+
}
|
|
30
|
+
function makeStateUpdater(key, instance) {
|
|
31
|
+
return updater => {
|
|
32
|
+
instance.setState(old => {
|
|
33
|
+
return { ...old,
|
|
34
|
+
[key]: functionalUpdate(updater, old[key])
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function isFunction(d) {
|
|
40
|
+
return d instanceof Function;
|
|
41
|
+
}
|
|
42
|
+
function flattenBy(arr, getChildren) {
|
|
43
|
+
const flat = [];
|
|
44
|
+
|
|
45
|
+
const recurse = subArr => {
|
|
46
|
+
subArr.forEach(item => {
|
|
47
|
+
flat.push(item);
|
|
48
|
+
const children = getChildren(item);
|
|
49
|
+
|
|
50
|
+
if (children != null && children.length) {
|
|
51
|
+
recurse(children);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
recurse(arr);
|
|
57
|
+
return flat;
|
|
58
|
+
}
|
|
59
|
+
function memo(getDeps, fn, opts) {
|
|
60
|
+
let deps = [];
|
|
61
|
+
let result;
|
|
62
|
+
return () => {
|
|
63
|
+
let depTime;
|
|
64
|
+
if (opts.key && opts.debug) depTime = Date.now();
|
|
65
|
+
const newDeps = getDeps();
|
|
66
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
67
|
+
|
|
68
|
+
if (!depsChanged) {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
deps = newDeps;
|
|
73
|
+
let resultTime;
|
|
74
|
+
if (opts.key && opts.debug) resultTime = Date.now();
|
|
75
|
+
result = fn(...newDeps);
|
|
76
|
+
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
77
|
+
|
|
78
|
+
if (opts.key && opts.debug) {
|
|
79
|
+
if (opts != null && opts.debug()) {
|
|
80
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
81
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
82
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
83
|
+
|
|
84
|
+
const pad = (str, num) => {
|
|
85
|
+
str = String(str);
|
|
86
|
+
|
|
87
|
+
while (str.length < num) {
|
|
88
|
+
str = ' ' + str;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return str;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return result;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createColumn(instance, columnDef, depth, parent) {
|
|
103
|
+
var _ref, _columnDef$id;
|
|
104
|
+
|
|
105
|
+
const defaultColumn = instance._getDefaultColumnDef();
|
|
106
|
+
|
|
107
|
+
columnDef = { ...defaultColumn,
|
|
108
|
+
...columnDef
|
|
109
|
+
};
|
|
110
|
+
let id = (_ref = (_columnDef$id = columnDef.id) != null ? _columnDef$id : columnDef.accessorKey) != null ? _ref : typeof columnDef.header === 'string' ? columnDef.header : undefined;
|
|
111
|
+
let accessorFn;
|
|
112
|
+
|
|
113
|
+
if (columnDef.accessorFn) {
|
|
114
|
+
accessorFn = columnDef.accessorFn;
|
|
115
|
+
} else if (columnDef.accessorKey) {
|
|
116
|
+
accessorFn = originalRow => originalRow[columnDef.accessorKey];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!id) {
|
|
120
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
121
|
+
throw new Error(columnDef.accessorFn ? "Columns require an id when using an accessorFn" : "Columns require an id when using a non-string header");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new Error();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let column = {
|
|
128
|
+
id: "" + id,
|
|
129
|
+
accessorFn,
|
|
130
|
+
parent: parent,
|
|
131
|
+
depth,
|
|
132
|
+
columnDef,
|
|
133
|
+
columnDefType: columnDef.columnDefType,
|
|
134
|
+
columns: [],
|
|
135
|
+
getFlatColumns: memo(() => [true], () => {
|
|
136
|
+
var _column$columns;
|
|
137
|
+
|
|
138
|
+
return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
|
|
139
|
+
}, {
|
|
140
|
+
key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
|
|
141
|
+
debug: () => {
|
|
142
|
+
var _instance$options$deb;
|
|
143
|
+
|
|
144
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
getLeafColumns: memo(() => [instance._getOrderColumnsFn()], orderColumns => {
|
|
148
|
+
var _column$columns2;
|
|
149
|
+
|
|
150
|
+
if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
|
|
151
|
+
let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
|
|
152
|
+
return orderColumns(leafColumns);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return [column];
|
|
156
|
+
}, {
|
|
157
|
+
key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
|
|
158
|
+
debug: () => {
|
|
159
|
+
var _instance$options$deb2;
|
|
160
|
+
|
|
161
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
column = instance._features.reduce((obj, feature) => {
|
|
166
|
+
return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
|
|
167
|
+
}, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
168
|
+
|
|
169
|
+
return column;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//
|
|
173
|
+
function createHeader(instance, column, options) {
|
|
174
|
+
var _options$id;
|
|
175
|
+
|
|
176
|
+
const id = (_options$id = options.id) != null ? _options$id : column.id;
|
|
177
|
+
let header = {
|
|
178
|
+
id,
|
|
179
|
+
column,
|
|
180
|
+
index: options.index,
|
|
181
|
+
isPlaceholder: !!options.isPlaceholder,
|
|
182
|
+
placeholderId: options.placeholderId,
|
|
183
|
+
depth: options.depth,
|
|
184
|
+
subHeaders: [],
|
|
185
|
+
colSpan: 0,
|
|
186
|
+
rowSpan: 0,
|
|
187
|
+
headerGroup: null,
|
|
188
|
+
getLeafHeaders: () => {
|
|
189
|
+
const leafHeaders = [];
|
|
190
|
+
|
|
191
|
+
const recurseHeader = h => {
|
|
192
|
+
if (h.subHeaders && h.subHeaders.length) {
|
|
193
|
+
h.subHeaders.map(recurseHeader);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
leafHeaders.push(h);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
recurseHeader(header);
|
|
200
|
+
return leafHeaders;
|
|
201
|
+
},
|
|
202
|
+
renderHeader: () => column.columnDef.header ? instance._render(column.columnDef.header, {
|
|
203
|
+
instance,
|
|
204
|
+
header: header,
|
|
205
|
+
column
|
|
206
|
+
}) : null,
|
|
207
|
+
renderFooter: () => column.columnDef.footer ? instance._render(column.columnDef.footer, {
|
|
208
|
+
instance,
|
|
209
|
+
header: header,
|
|
210
|
+
column
|
|
211
|
+
}) : null
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
instance._features.forEach(feature => {
|
|
215
|
+
Object.assign(header, feature.createHeader == null ? void 0 : feature.createHeader(header, instance));
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return header;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const Headers = {
|
|
222
|
+
createInstance: instance => {
|
|
223
|
+
return {
|
|
224
|
+
// Header Groups
|
|
225
|
+
getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
226
|
+
var _left$map$filter, _right$map$filter;
|
|
227
|
+
|
|
228
|
+
const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
|
|
229
|
+
const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
|
|
230
|
+
const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
231
|
+
const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
|
|
232
|
+
return headerGroups;
|
|
233
|
+
}, {
|
|
234
|
+
key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
|
|
235
|
+
debug: () => {
|
|
236
|
+
var _instance$options$deb;
|
|
237
|
+
|
|
238
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugHeaders;
|
|
239
|
+
}
|
|
240
|
+
}),
|
|
241
|
+
getCenterHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
|
|
242
|
+
leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
|
|
243
|
+
return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
|
|
244
|
+
}, {
|
|
245
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
|
|
246
|
+
debug: () => {
|
|
247
|
+
var _instance$options$deb2;
|
|
248
|
+
|
|
249
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugHeaders;
|
|
250
|
+
}
|
|
251
|
+
}),
|
|
252
|
+
getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
|
|
253
|
+
var _left$map$filter2;
|
|
254
|
+
|
|
255
|
+
const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
|
|
256
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
|
|
257
|
+
}, {
|
|
258
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
|
|
259
|
+
debug: () => {
|
|
260
|
+
var _instance$options$deb3;
|
|
261
|
+
|
|
262
|
+
return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugHeaders;
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
|
|
266
|
+
var _right$map$filter2;
|
|
267
|
+
|
|
268
|
+
const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
|
|
269
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
|
|
270
|
+
}, {
|
|
271
|
+
key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
|
|
272
|
+
debug: () => {
|
|
273
|
+
var _instance$options$deb4;
|
|
274
|
+
|
|
275
|
+
return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugHeaders;
|
|
276
|
+
}
|
|
277
|
+
}),
|
|
278
|
+
// Footer Groups
|
|
279
|
+
getFooterGroups: memo(() => [instance.getHeaderGroups()], headerGroups => {
|
|
280
|
+
return [...headerGroups].reverse();
|
|
281
|
+
}, {
|
|
282
|
+
key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
|
|
283
|
+
debug: () => {
|
|
284
|
+
var _instance$options$deb5;
|
|
285
|
+
|
|
286
|
+
return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugHeaders;
|
|
287
|
+
}
|
|
288
|
+
}),
|
|
289
|
+
getLeftFooterGroups: memo(() => [instance.getLeftHeaderGroups()], headerGroups => {
|
|
290
|
+
return [...headerGroups].reverse();
|
|
291
|
+
}, {
|
|
292
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
|
|
293
|
+
debug: () => {
|
|
294
|
+
var _instance$options$deb6;
|
|
295
|
+
|
|
296
|
+
return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugHeaders;
|
|
297
|
+
}
|
|
298
|
+
}),
|
|
299
|
+
getCenterFooterGroups: memo(() => [instance.getCenterHeaderGroups()], headerGroups => {
|
|
300
|
+
return [...headerGroups].reverse();
|
|
301
|
+
}, {
|
|
302
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
|
|
303
|
+
debug: () => {
|
|
304
|
+
var _instance$options$deb7;
|
|
305
|
+
|
|
306
|
+
return (_instance$options$deb7 = instance.options.debugAll) != null ? _instance$options$deb7 : instance.options.debugHeaders;
|
|
307
|
+
}
|
|
308
|
+
}),
|
|
309
|
+
getRightFooterGroups: memo(() => [instance.getRightHeaderGroups()], headerGroups => {
|
|
310
|
+
return [...headerGroups].reverse();
|
|
311
|
+
}, {
|
|
312
|
+
key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
|
|
313
|
+
debug: () => {
|
|
314
|
+
var _instance$options$deb8;
|
|
315
|
+
|
|
316
|
+
return (_instance$options$deb8 = instance.options.debugAll) != null ? _instance$options$deb8 : instance.options.debugHeaders;
|
|
317
|
+
}
|
|
318
|
+
}),
|
|
319
|
+
// Flat Headers
|
|
320
|
+
getFlatHeaders: memo(() => [instance.getHeaderGroups()], headerGroups => {
|
|
321
|
+
return headerGroups.map(headerGroup => {
|
|
322
|
+
return headerGroup.headers;
|
|
323
|
+
}).flat();
|
|
324
|
+
}, {
|
|
325
|
+
key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
|
|
326
|
+
debug: () => {
|
|
327
|
+
var _instance$options$deb9;
|
|
328
|
+
|
|
329
|
+
return (_instance$options$deb9 = instance.options.debugAll) != null ? _instance$options$deb9 : instance.options.debugHeaders;
|
|
330
|
+
}
|
|
331
|
+
}),
|
|
332
|
+
getLeftFlatHeaders: memo(() => [instance.getLeftHeaderGroups()], left => {
|
|
333
|
+
return left.map(headerGroup => {
|
|
334
|
+
return headerGroup.headers;
|
|
335
|
+
}).flat();
|
|
336
|
+
}, {
|
|
337
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
|
|
338
|
+
debug: () => {
|
|
339
|
+
var _instance$options$deb10;
|
|
340
|
+
|
|
341
|
+
return (_instance$options$deb10 = instance.options.debugAll) != null ? _instance$options$deb10 : instance.options.debugHeaders;
|
|
342
|
+
}
|
|
343
|
+
}),
|
|
344
|
+
getCenterFlatHeaders: memo(() => [instance.getCenterHeaderGroups()], left => {
|
|
345
|
+
return left.map(headerGroup => {
|
|
346
|
+
return headerGroup.headers;
|
|
347
|
+
}).flat();
|
|
348
|
+
}, {
|
|
349
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
|
|
350
|
+
debug: () => {
|
|
351
|
+
var _instance$options$deb11;
|
|
352
|
+
|
|
353
|
+
return (_instance$options$deb11 = instance.options.debugAll) != null ? _instance$options$deb11 : instance.options.debugHeaders;
|
|
354
|
+
}
|
|
355
|
+
}),
|
|
356
|
+
getRightFlatHeaders: memo(() => [instance.getRightHeaderGroups()], left => {
|
|
357
|
+
return left.map(headerGroup => {
|
|
358
|
+
return headerGroup.headers;
|
|
359
|
+
}).flat();
|
|
360
|
+
}, {
|
|
361
|
+
key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
|
|
362
|
+
debug: () => {
|
|
363
|
+
var _instance$options$deb12;
|
|
364
|
+
|
|
365
|
+
return (_instance$options$deb12 = instance.options.debugAll) != null ? _instance$options$deb12 : instance.options.debugHeaders;
|
|
366
|
+
}
|
|
367
|
+
}),
|
|
368
|
+
// Leaf Headers
|
|
369
|
+
getCenterLeafHeaders: memo(() => [instance.getCenterFlatHeaders()], flatHeaders => {
|
|
370
|
+
return flatHeaders.filter(header => {
|
|
371
|
+
var _header$subHeaders;
|
|
372
|
+
|
|
373
|
+
return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
|
|
374
|
+
});
|
|
375
|
+
}, {
|
|
376
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
|
|
377
|
+
debug: () => {
|
|
378
|
+
var _instance$options$deb13;
|
|
379
|
+
|
|
380
|
+
return (_instance$options$deb13 = instance.options.debugAll) != null ? _instance$options$deb13 : instance.options.debugHeaders;
|
|
381
|
+
}
|
|
382
|
+
}),
|
|
383
|
+
getLeftLeafHeaders: memo(() => [instance.getLeftFlatHeaders()], flatHeaders => {
|
|
384
|
+
return flatHeaders.filter(header => {
|
|
385
|
+
var _header$subHeaders2;
|
|
386
|
+
|
|
387
|
+
return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
|
|
388
|
+
});
|
|
389
|
+
}, {
|
|
390
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
|
|
391
|
+
debug: () => {
|
|
392
|
+
var _instance$options$deb14;
|
|
393
|
+
|
|
394
|
+
return (_instance$options$deb14 = instance.options.debugAll) != null ? _instance$options$deb14 : instance.options.debugHeaders;
|
|
395
|
+
}
|
|
396
|
+
}),
|
|
397
|
+
getRightLeafHeaders: memo(() => [instance.getRightFlatHeaders()], flatHeaders => {
|
|
398
|
+
return flatHeaders.filter(header => {
|
|
399
|
+
var _header$subHeaders3;
|
|
400
|
+
|
|
401
|
+
return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
|
|
402
|
+
});
|
|
403
|
+
}, {
|
|
404
|
+
key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
|
|
405
|
+
debug: () => {
|
|
406
|
+
var _instance$options$deb15;
|
|
407
|
+
|
|
408
|
+
return (_instance$options$deb15 = instance.options.debugAll) != null ? _instance$options$deb15 : instance.options.debugHeaders;
|
|
409
|
+
}
|
|
410
|
+
}),
|
|
411
|
+
getLeafHeaders: memo(() => [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()], (left, center, right) => {
|
|
412
|
+
var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
|
|
413
|
+
|
|
414
|
+
return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
|
|
415
|
+
return header.getLeafHeaders();
|
|
416
|
+
}).flat();
|
|
417
|
+
}, {
|
|
418
|
+
key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
|
|
419
|
+
debug: () => {
|
|
420
|
+
var _instance$options$deb16;
|
|
421
|
+
|
|
422
|
+
return (_instance$options$deb16 = instance.options.debugAll) != null ? _instance$options$deb16 : instance.options.debugHeaders;
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
|
|
429
|
+
var _headerGroups$0$heade, _headerGroups$;
|
|
430
|
+
|
|
431
|
+
// Find the max depth of the columns:
|
|
432
|
+
// build the leaf column row
|
|
433
|
+
// build each buffer row going up
|
|
434
|
+
// placeholder for non-existent level
|
|
435
|
+
// real column for existing level
|
|
436
|
+
let maxDepth = 0;
|
|
437
|
+
|
|
438
|
+
const findMaxDepth = function (columns, depth) {
|
|
439
|
+
if (depth === void 0) {
|
|
440
|
+
depth = 1;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
444
|
+
columns.filter(column => column.getIsVisible()).forEach(column => {
|
|
445
|
+
var _column$columns;
|
|
446
|
+
|
|
447
|
+
if ((_column$columns = column.columns) != null && _column$columns.length) {
|
|
448
|
+
findMaxDepth(column.columns, depth + 1);
|
|
449
|
+
}
|
|
450
|
+
}, 0);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
findMaxDepth(allColumns);
|
|
454
|
+
let headerGroups = [];
|
|
455
|
+
|
|
456
|
+
const createHeaderGroup = (headersToGroup, depth) => {
|
|
457
|
+
// The header group we are creating
|
|
458
|
+
const headerGroup = {
|
|
459
|
+
depth,
|
|
460
|
+
id: [headerFamily, "" + depth].filter(Boolean).join('_'),
|
|
461
|
+
headers: []
|
|
462
|
+
}; // The parent columns we're going to scan next
|
|
463
|
+
|
|
464
|
+
const pendingParentHeaders = []; // Scan each column for parents
|
|
465
|
+
|
|
466
|
+
headersToGroup.forEach(headerToGroup => {
|
|
467
|
+
// What is the latest (last) parent column?
|
|
468
|
+
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
|
|
469
|
+
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
|
|
470
|
+
let column;
|
|
471
|
+
let isPlaceholder = false;
|
|
472
|
+
|
|
473
|
+
if (isLeafHeader && headerToGroup.column.parent) {
|
|
474
|
+
// The parent header is new
|
|
475
|
+
column = headerToGroup.column.parent;
|
|
476
|
+
} else {
|
|
477
|
+
// The parent header is repeated
|
|
478
|
+
column = headerToGroup.column;
|
|
479
|
+
isPlaceholder = true;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if ((latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
|
|
483
|
+
// This column is repeated. Add it as a sub header to the next batch
|
|
484
|
+
latestPendingParentHeader.subHeaders.push(headerToGroup);
|
|
485
|
+
} else {
|
|
486
|
+
// This is a new header. Let's create it
|
|
487
|
+
const header = createHeader(instance, column, {
|
|
488
|
+
id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
|
|
489
|
+
isPlaceholder,
|
|
490
|
+
placeholderId: isPlaceholder ? "" + pendingParentHeaders.filter(d => d.column === column).length : undefined,
|
|
491
|
+
depth,
|
|
492
|
+
index: pendingParentHeaders.length
|
|
493
|
+
}); // Add the headerToGroup as a subHeader of the new header
|
|
494
|
+
|
|
495
|
+
header.subHeaders.push(headerToGroup); // Add the new header to the pendingParentHeaders to get grouped
|
|
496
|
+
// in the next batch
|
|
497
|
+
|
|
498
|
+
pendingParentHeaders.push(header);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
headerGroup.headers.push(headerToGroup);
|
|
502
|
+
headerToGroup.headerGroup = headerGroup;
|
|
503
|
+
});
|
|
504
|
+
headerGroups.push(headerGroup);
|
|
505
|
+
|
|
506
|
+
if (depth > 0) {
|
|
507
|
+
createHeaderGroup(pendingParentHeaders, depth - 1);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
const bottomHeaders = columnsToGroup.map((column, index) => createHeader(instance, column, {
|
|
512
|
+
depth: maxDepth,
|
|
513
|
+
index
|
|
514
|
+
}));
|
|
515
|
+
createHeaderGroup(bottomHeaders, maxDepth - 1);
|
|
516
|
+
headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
|
|
517
|
+
// return !headerGroup.headers.every(header => header.isPlaceholder)
|
|
518
|
+
// })
|
|
519
|
+
|
|
520
|
+
const recurseHeadersForSpans = headers => {
|
|
521
|
+
const filteredHeaders = headers.filter(header => header.column.getIsVisible());
|
|
522
|
+
return filteredHeaders.map(header => {
|
|
523
|
+
let colSpan = 0;
|
|
524
|
+
let rowSpan = 0;
|
|
525
|
+
let childRowSpans = [0];
|
|
526
|
+
|
|
527
|
+
if (header.subHeaders && header.subHeaders.length) {
|
|
528
|
+
childRowSpans = [];
|
|
529
|
+
recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
|
|
530
|
+
let {
|
|
531
|
+
colSpan: childColSpan,
|
|
532
|
+
rowSpan: childRowSpan
|
|
533
|
+
} = _ref;
|
|
534
|
+
colSpan += childColSpan;
|
|
535
|
+
childRowSpans.push(childRowSpan);
|
|
536
|
+
});
|
|
537
|
+
} else {
|
|
538
|
+
colSpan = 1;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const minChildRowSpan = Math.min(...childRowSpans);
|
|
542
|
+
rowSpan = rowSpan + minChildRowSpan;
|
|
543
|
+
header.colSpan = colSpan;
|
|
544
|
+
header.rowSpan = rowSpan;
|
|
545
|
+
return {
|
|
546
|
+
colSpan,
|
|
547
|
+
rowSpan
|
|
548
|
+
};
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
|
|
553
|
+
return headerGroups;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
//
|
|
557
|
+
const defaultColumnSizing = {
|
|
558
|
+
size: 150,
|
|
559
|
+
minSize: 20,
|
|
560
|
+
maxSize: Number.MAX_SAFE_INTEGER
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
const getDefaultColumnSizingInfoState = () => ({
|
|
564
|
+
startOffset: null,
|
|
565
|
+
startSize: null,
|
|
566
|
+
deltaOffset: null,
|
|
567
|
+
deltaPercentage: null,
|
|
568
|
+
isResizingColumn: false,
|
|
569
|
+
columnSizingStart: []
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
const ColumnSizing = {
|
|
573
|
+
getDefaultColumnDef: () => {
|
|
574
|
+
return defaultColumnSizing;
|
|
575
|
+
},
|
|
576
|
+
getInitialState: state => {
|
|
577
|
+
return {
|
|
578
|
+
columnSizing: {},
|
|
579
|
+
columnSizingInfo: getDefaultColumnSizingInfoState(),
|
|
580
|
+
...state
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
getDefaultOptions: instance => {
|
|
584
|
+
return {
|
|
585
|
+
columnResizeMode: 'onEnd',
|
|
586
|
+
onColumnSizingChange: makeStateUpdater('columnSizing', instance),
|
|
587
|
+
onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
createColumn: (column, instance) => {
|
|
591
|
+
return {
|
|
592
|
+
getSize: () => {
|
|
593
|
+
var _column$columnDef$min, _ref, _column$columnDef$max;
|
|
594
|
+
|
|
595
|
+
const columnSize = instance.getState().columnSizing[column.id];
|
|
596
|
+
return Math.min(Math.max((_column$columnDef$min = column.columnDef.minSize) != null ? _column$columnDef$min : defaultColumnSizing.minSize, (_ref = columnSize != null ? columnSize : column.columnDef.size) != null ? _ref : defaultColumnSizing.size), (_column$columnDef$max = column.columnDef.maxSize) != null ? _column$columnDef$max : defaultColumnSizing.maxSize);
|
|
597
|
+
},
|
|
598
|
+
getStart: position => {
|
|
599
|
+
const columns = !position ? instance.getVisibleLeafColumns() : position === 'left' ? instance.getLeftVisibleLeafColumns() : instance.getRightVisibleLeafColumns();
|
|
600
|
+
const index = columns.findIndex(d => d.id === column.id);
|
|
601
|
+
|
|
602
|
+
if (index > 0) {
|
|
603
|
+
const prevSiblingColumn = columns[index - 1];
|
|
604
|
+
return prevSiblingColumn.getStart(position) + prevSiblingColumn.getSize();
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return 0;
|
|
608
|
+
},
|
|
609
|
+
resetSize: () => {
|
|
610
|
+
instance.setColumnSizing(_ref2 => {
|
|
611
|
+
let {
|
|
612
|
+
[column.id]: _,
|
|
613
|
+
...rest
|
|
614
|
+
} = _ref2;
|
|
615
|
+
return rest;
|
|
616
|
+
});
|
|
617
|
+
},
|
|
618
|
+
getCanResize: () => {
|
|
619
|
+
var _column$columnDef$ena, _instance$options$ena;
|
|
620
|
+
|
|
621
|
+
return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableColumnResizing) != null ? _instance$options$ena : true);
|
|
622
|
+
},
|
|
623
|
+
getIsResizing: () => {
|
|
624
|
+
return instance.getState().columnSizingInfo.isResizingColumn === column.id;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
},
|
|
628
|
+
createHeader: (header, instance) => {
|
|
629
|
+
return {
|
|
630
|
+
getSize: () => {
|
|
631
|
+
let sum = 0;
|
|
632
|
+
|
|
633
|
+
const recurse = header => {
|
|
634
|
+
if (header.subHeaders.length) {
|
|
635
|
+
header.subHeaders.forEach(recurse);
|
|
636
|
+
} else {
|
|
637
|
+
var _header$column$getSiz;
|
|
638
|
+
|
|
639
|
+
sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
recurse(header);
|
|
644
|
+
return sum;
|
|
645
|
+
},
|
|
646
|
+
getStart: () => {
|
|
647
|
+
if (header.index > 0) {
|
|
648
|
+
const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
|
|
649
|
+
return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return 0;
|
|
653
|
+
},
|
|
654
|
+
getResizeHandler: () => {
|
|
655
|
+
const column = instance.getColumn(header.column.id);
|
|
656
|
+
const canResize = column.getCanResize();
|
|
657
|
+
return e => {
|
|
658
|
+
if (!canResize) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
e.persist == null ? void 0 : e.persist();
|
|
662
|
+
|
|
663
|
+
if (isTouchStartEvent(e)) {
|
|
664
|
+
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
665
|
+
if (e.touches && e.touches.length > 1) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const startSize = header.getSize();
|
|
671
|
+
const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
|
|
672
|
+
const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
|
|
673
|
+
|
|
674
|
+
const updateOffset = (eventType, clientXPos) => {
|
|
675
|
+
if (typeof clientXPos !== 'number') {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
let newColumnSizing = {};
|
|
680
|
+
instance.setColumnSizingInfo(old => {
|
|
681
|
+
var _old$startOffset, _old$startSize;
|
|
682
|
+
|
|
683
|
+
const deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
|
|
684
|
+
const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
|
|
685
|
+
old.columnSizingStart.forEach(_ref3 => {
|
|
686
|
+
let [columnId, headerSize] = _ref3;
|
|
687
|
+
newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
|
|
688
|
+
});
|
|
689
|
+
return { ...old,
|
|
690
|
+
deltaOffset,
|
|
691
|
+
deltaPercentage
|
|
692
|
+
};
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
|
|
696
|
+
instance.setColumnSizing(old => ({ ...old,
|
|
697
|
+
...newColumnSizing
|
|
698
|
+
}));
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const onMove = clientXPos => updateOffset('move', clientXPos);
|
|
703
|
+
|
|
704
|
+
const onEnd = clientXPos => {
|
|
705
|
+
updateOffset('end', clientXPos);
|
|
706
|
+
instance.setColumnSizingInfo(old => ({ ...old,
|
|
707
|
+
isResizingColumn: false,
|
|
708
|
+
startOffset: null,
|
|
709
|
+
startSize: null,
|
|
710
|
+
deltaOffset: null,
|
|
711
|
+
deltaPercentage: null,
|
|
712
|
+
columnSizingStart: []
|
|
713
|
+
}));
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
const mouseEvents = {
|
|
717
|
+
moveHandler: e => onMove(e.clientX),
|
|
718
|
+
upHandler: e => {
|
|
719
|
+
document.removeEventListener('mousemove', mouseEvents.moveHandler);
|
|
720
|
+
document.removeEventListener('mouseup', mouseEvents.upHandler);
|
|
721
|
+
onEnd(e.clientX);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const passiveIfSupported = passiveEventSupported() ? {
|
|
725
|
+
passive: false
|
|
726
|
+
} : false;
|
|
727
|
+
|
|
728
|
+
if (isTouchStartEvent(e)) ; else {
|
|
729
|
+
document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
|
|
730
|
+
document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
instance.setColumnSizingInfo(old => ({ ...old,
|
|
734
|
+
startOffset: clientX,
|
|
735
|
+
startSize,
|
|
736
|
+
deltaOffset: 0,
|
|
737
|
+
deltaPercentage: 0,
|
|
738
|
+
columnSizingStart,
|
|
739
|
+
isResizingColumn: column.id
|
|
740
|
+
}));
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
},
|
|
745
|
+
createInstance: instance => {
|
|
746
|
+
return {
|
|
747
|
+
setColumnSizing: updater => instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater),
|
|
748
|
+
setColumnSizingInfo: updater => instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater),
|
|
749
|
+
resetColumnSizing: defaultState => {
|
|
750
|
+
var _instance$initialStat;
|
|
751
|
+
|
|
752
|
+
instance.setColumnSizing(defaultState ? {} : (_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
|
|
753
|
+
},
|
|
754
|
+
resetHeaderSizeInfo: defaultState => {
|
|
755
|
+
var _instance$initialStat2;
|
|
756
|
+
|
|
757
|
+
instance.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : getDefaultColumnSizingInfoState());
|
|
758
|
+
},
|
|
759
|
+
getTotalSize: () => {
|
|
760
|
+
var _instance$getHeaderGr, _instance$getHeaderGr2;
|
|
761
|
+
|
|
762
|
+
return (_instance$getHeaderGr = (_instance$getHeaderGr2 = instance.getHeaderGroups()[0]) == null ? void 0 : _instance$getHeaderGr2.headers.reduce((sum, header) => {
|
|
763
|
+
return sum + header.getSize();
|
|
764
|
+
}, 0)) != null ? _instance$getHeaderGr : 0;
|
|
765
|
+
},
|
|
766
|
+
getLeftTotalSize: () => {
|
|
767
|
+
var _instance$getLeftHead, _instance$getLeftHead2;
|
|
768
|
+
|
|
769
|
+
return (_instance$getLeftHead = (_instance$getLeftHead2 = instance.getLeftHeaderGroups()[0]) == null ? void 0 : _instance$getLeftHead2.headers.reduce((sum, header) => {
|
|
770
|
+
return sum + header.getSize();
|
|
771
|
+
}, 0)) != null ? _instance$getLeftHead : 0;
|
|
772
|
+
},
|
|
773
|
+
getCenterTotalSize: () => {
|
|
774
|
+
var _instance$getCenterHe, _instance$getCenterHe2;
|
|
775
|
+
|
|
776
|
+
return (_instance$getCenterHe = (_instance$getCenterHe2 = instance.getCenterHeaderGroups()[0]) == null ? void 0 : _instance$getCenterHe2.headers.reduce((sum, header) => {
|
|
777
|
+
return sum + header.getSize();
|
|
778
|
+
}, 0)) != null ? _instance$getCenterHe : 0;
|
|
779
|
+
},
|
|
780
|
+
getRightTotalSize: () => {
|
|
781
|
+
var _instance$getRightHea, _instance$getRightHea2;
|
|
782
|
+
|
|
783
|
+
return (_instance$getRightHea = (_instance$getRightHea2 = instance.getRightHeaderGroups()[0]) == null ? void 0 : _instance$getRightHea2.headers.reduce((sum, header) => {
|
|
784
|
+
return sum + header.getSize();
|
|
785
|
+
}, 0)) != null ? _instance$getRightHea : 0;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
let passiveSupported = null;
|
|
791
|
+
function passiveEventSupported() {
|
|
792
|
+
if (typeof passiveSupported === 'boolean') return passiveSupported;
|
|
793
|
+
let supported = false;
|
|
794
|
+
|
|
795
|
+
try {
|
|
796
|
+
const options = {
|
|
797
|
+
get passive() {
|
|
798
|
+
supported = true;
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
const noop = () => {};
|
|
805
|
+
|
|
806
|
+
window.addEventListener('test', noop, options);
|
|
807
|
+
window.removeEventListener('test', noop);
|
|
808
|
+
} catch (err) {
|
|
809
|
+
supported = false;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
passiveSupported = supported;
|
|
813
|
+
return passiveSupported;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
function isTouchStartEvent(e) {
|
|
817
|
+
return e.type === 'touchstart';
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
//
|
|
821
|
+
const Expanding = {
|
|
822
|
+
getInitialState: state => {
|
|
823
|
+
return {
|
|
824
|
+
expanded: {},
|
|
825
|
+
...state
|
|
826
|
+
};
|
|
827
|
+
},
|
|
828
|
+
getDefaultOptions: instance => {
|
|
829
|
+
return {
|
|
830
|
+
onExpandedChange: makeStateUpdater('expanded', instance),
|
|
831
|
+
autoResetExpanded: true,
|
|
832
|
+
paginateExpandedRows: true
|
|
833
|
+
};
|
|
834
|
+
},
|
|
835
|
+
createInstance: instance => {
|
|
836
|
+
let registered = false;
|
|
837
|
+
let queued = false;
|
|
838
|
+
return {
|
|
839
|
+
_autoResetExpanded: () => {
|
|
840
|
+
if (!registered) {
|
|
841
|
+
instance._queue(() => {
|
|
842
|
+
registered = true;
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
if (instance.options.autoResetAll === false) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
|
|
853
|
+
if (queued) return;
|
|
854
|
+
queued = true;
|
|
855
|
+
|
|
856
|
+
instance._queue(() => {
|
|
857
|
+
instance.resetExpanded();
|
|
858
|
+
queued = false;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
setExpanded: updater => instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater),
|
|
863
|
+
toggleAllRowsExpanded: expanded => {
|
|
864
|
+
if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
|
|
865
|
+
instance.setExpanded(true);
|
|
866
|
+
} else {
|
|
867
|
+
instance.setExpanded({});
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
resetExpanded: defaultState => {
|
|
871
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
872
|
+
|
|
873
|
+
instance.setExpanded(defaultState ? {} : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.expanded) != null ? _instance$initialStat : {});
|
|
874
|
+
},
|
|
875
|
+
getCanSomeRowsExpand: () => {
|
|
876
|
+
return instance.getRowModel().flatRows.some(row => row.getCanExpand());
|
|
877
|
+
},
|
|
878
|
+
getToggleAllRowsExpandedHandler: () => {
|
|
879
|
+
return e => {
|
|
880
|
+
e.persist == null ? void 0 : e.persist();
|
|
881
|
+
instance.toggleAllRowsExpanded();
|
|
882
|
+
};
|
|
883
|
+
},
|
|
884
|
+
getIsSomeRowsExpanded: () => {
|
|
885
|
+
const expanded = instance.getState().expanded;
|
|
886
|
+
return expanded === true || Object.values(expanded).some(Boolean);
|
|
887
|
+
},
|
|
888
|
+
getIsAllRowsExpanded: () => {
|
|
889
|
+
const expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
|
|
890
|
+
|
|
891
|
+
if (typeof expanded === 'boolean') {
|
|
892
|
+
return expanded === true;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
if (!Object.keys(expanded).length) {
|
|
896
|
+
return false;
|
|
897
|
+
} // If any row is not expanded, return false
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
if (instance.getRowModel().flatRows.some(row => row.getIsExpanded())) {
|
|
901
|
+
return false;
|
|
902
|
+
} // They must all be expanded :shrug:
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
return true;
|
|
906
|
+
},
|
|
907
|
+
getExpandedDepth: () => {
|
|
908
|
+
let maxDepth = 0;
|
|
909
|
+
const rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowModel().rowsById) : Object.keys(instance.getState().expanded);
|
|
910
|
+
rowIds.forEach(id => {
|
|
911
|
+
const splitId = id.split('.');
|
|
912
|
+
maxDepth = Math.max(maxDepth, splitId.length);
|
|
913
|
+
});
|
|
914
|
+
return maxDepth;
|
|
915
|
+
},
|
|
916
|
+
getPreExpandedRowModel: () => instance.getGroupedRowModel(),
|
|
917
|
+
getExpandedRowModel: () => {
|
|
918
|
+
if (!instance._getExpandedRowModel && instance.options.getExpandedRowModel) {
|
|
919
|
+
instance._getExpandedRowModel = instance.options.getExpandedRowModel(instance);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
if (instance.options.manualExpanding || !instance._getExpandedRowModel) {
|
|
923
|
+
return instance.getPreExpandedRowModel();
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
return instance._getExpandedRowModel();
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
},
|
|
930
|
+
createRow: (row, instance) => {
|
|
931
|
+
return {
|
|
932
|
+
toggleExpanded: expanded => {
|
|
933
|
+
instance.setExpanded(old => {
|
|
934
|
+
var _expanded;
|
|
935
|
+
|
|
936
|
+
const exists = old === true ? true : !!(old != null && old[row.id]);
|
|
937
|
+
let oldExpanded = {};
|
|
938
|
+
|
|
939
|
+
if (old === true) {
|
|
940
|
+
Object.keys(instance.getRowModel().rowsById).forEach(rowId => {
|
|
941
|
+
oldExpanded[rowId] = true;
|
|
942
|
+
});
|
|
943
|
+
} else {
|
|
944
|
+
oldExpanded = old;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
expanded = (_expanded = expanded) != null ? _expanded : !exists;
|
|
948
|
+
|
|
949
|
+
if (!exists && expanded) {
|
|
950
|
+
return { ...oldExpanded,
|
|
951
|
+
[row.id]: true
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
if (exists && !expanded) {
|
|
956
|
+
const {
|
|
957
|
+
[row.id]: _,
|
|
958
|
+
...rest
|
|
959
|
+
} = oldExpanded;
|
|
960
|
+
return rest;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
return old;
|
|
964
|
+
});
|
|
965
|
+
},
|
|
966
|
+
getIsExpanded: () => {
|
|
967
|
+
var _instance$options$get;
|
|
968
|
+
|
|
969
|
+
const expanded = instance.getState().expanded;
|
|
970
|
+
return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded === true || (expanded == null ? void 0 : expanded[row.id]));
|
|
971
|
+
},
|
|
972
|
+
getCanExpand: () => {
|
|
973
|
+
var _instance$options$get2, _instance$options$ena, _row$subRows;
|
|
974
|
+
|
|
975
|
+
return ((_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : true) && ((_instance$options$ena = instance.options.enableExpanding) != null ? _instance$options$ena : true) && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
|
|
976
|
+
},
|
|
977
|
+
getToggleExpandedHandler: () => {
|
|
978
|
+
const canExpand = row.getCanExpand();
|
|
979
|
+
return () => {
|
|
980
|
+
if (!canExpand) return;
|
|
981
|
+
row.toggleExpanded();
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
const includesString = (row, columnId, filterValue) => {
|
|
989
|
+
const search = filterValue.toLowerCase();
|
|
990
|
+
return row.getValue(columnId).toLowerCase().includes(search);
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
includesString.autoRemove = val => testFalsey(val);
|
|
994
|
+
|
|
995
|
+
const includesStringSensitive = (row, columnId, filterValue) => {
|
|
996
|
+
return row.getValue(columnId).includes(filterValue);
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
includesStringSensitive.autoRemove = val => testFalsey(val);
|
|
1000
|
+
|
|
1001
|
+
const equalsString = (row, columnId, filterValue) => {
|
|
1002
|
+
return row.getValue(columnId).toLowerCase() === filterValue.toLowerCase();
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
equalsString.autoRemove = val => testFalsey(val);
|
|
1006
|
+
|
|
1007
|
+
const arrIncludes = (row, columnId, filterValue) => {
|
|
1008
|
+
return row.getValue(columnId).includes(filterValue);
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
1012
|
+
|
|
1013
|
+
const arrIncludesAll = (row, columnId, filterValue) => {
|
|
1014
|
+
return !filterValue.some(val => !row.getValue(columnId).includes(val));
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
1018
|
+
|
|
1019
|
+
const arrIncludesSome = (row, columnId, filterValue) => {
|
|
1020
|
+
return filterValue.some(val => row.getValue(columnId).includes(val));
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
|
|
1024
|
+
|
|
1025
|
+
const equals = (row, columnId, filterValue) => {
|
|
1026
|
+
return row.getValue(columnId) === filterValue;
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
equals.autoRemove = val => testFalsey(val);
|
|
1030
|
+
|
|
1031
|
+
const weakEquals = (row, columnId, filterValue) => {
|
|
1032
|
+
return row.getValue(columnId) == filterValue;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
weakEquals.autoRemove = val => testFalsey(val);
|
|
1036
|
+
|
|
1037
|
+
const inNumberRange = (row, columnId, filterValue) => {
|
|
1038
|
+
let [min, max] = filterValue;
|
|
1039
|
+
const rowValue = row.getValue(columnId);
|
|
1040
|
+
return rowValue >= min && rowValue <= max;
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
inNumberRange.resolveFilterValue = val => {
|
|
1044
|
+
let [unsafeMin, unsafeMax] = val;
|
|
1045
|
+
let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
|
|
1046
|
+
let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
|
|
1047
|
+
let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
|
|
1048
|
+
let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
|
|
1049
|
+
|
|
1050
|
+
if (min > max) {
|
|
1051
|
+
const temp = min;
|
|
1052
|
+
min = max;
|
|
1053
|
+
max = temp;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
return [min, max];
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]); // Export
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
const filterFns = {
|
|
1063
|
+
includesString,
|
|
1064
|
+
includesStringSensitive,
|
|
1065
|
+
equalsString,
|
|
1066
|
+
arrIncludes,
|
|
1067
|
+
arrIncludesAll,
|
|
1068
|
+
arrIncludesSome,
|
|
1069
|
+
equals,
|
|
1070
|
+
weakEquals,
|
|
1071
|
+
inNumberRange
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
// Utils
|
|
1075
|
+
function testFalsey(val) {
|
|
1076
|
+
return val === undefined || val === null || val === '';
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
//
|
|
1080
|
+
const Filters = {
|
|
1081
|
+
getDefaultColumnDef: () => {
|
|
1082
|
+
return {
|
|
1083
|
+
filterFn: 'auto'
|
|
1084
|
+
};
|
|
1085
|
+
},
|
|
1086
|
+
getInitialState: state => {
|
|
1087
|
+
return {
|
|
1088
|
+
columnFilters: [],
|
|
1089
|
+
globalFilter: undefined,
|
|
1090
|
+
// filtersProgress: 1,
|
|
1091
|
+
// facetProgress: {},
|
|
1092
|
+
...state
|
|
1093
|
+
};
|
|
1094
|
+
},
|
|
1095
|
+
getDefaultOptions: instance => {
|
|
1096
|
+
return {
|
|
1097
|
+
onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
|
|
1098
|
+
onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
|
|
1099
|
+
filterFromLeafRows: false,
|
|
1100
|
+
globalFilterFn: 'auto',
|
|
1101
|
+
getColumnCanGlobalFilter: column => {
|
|
1102
|
+
var _instance$getCoreRowM, _instance$getCoreRowM2;
|
|
1103
|
+
|
|
1104
|
+
const value = (_instance$getCoreRowM = instance.getCoreRowModel().flatRows[0]) == null ? void 0 : (_instance$getCoreRowM2 = _instance$getCoreRowM._getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreRowM2.getValue();
|
|
1105
|
+
return typeof value === 'string';
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
},
|
|
1109
|
+
createColumn: (column, instance) => {
|
|
1110
|
+
return {
|
|
1111
|
+
filterFn: column.filterFn,
|
|
1112
|
+
getAutoFilterFn: () => {
|
|
1113
|
+
const firstRow = instance.getCoreRowModel().flatRows[0];
|
|
1114
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
1115
|
+
|
|
1116
|
+
if (typeof value === 'string') {
|
|
1117
|
+
return filterFns.includesString;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
if (typeof value === 'number') {
|
|
1121
|
+
return filterFns.inNumberRange;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
if (typeof value === 'boolean') {
|
|
1125
|
+
return filterFns.equals;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
if (value !== null && typeof value === 'object') {
|
|
1129
|
+
return filterFns.equals;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
if (Array.isArray(value)) {
|
|
1133
|
+
return filterFns.arrIncludes;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return filterFns.weakEquals;
|
|
1137
|
+
},
|
|
1138
|
+
getFilterFn: () => {
|
|
1139
|
+
var _ref;
|
|
1140
|
+
|
|
1141
|
+
const userFilterFns = instance.options.filterFns;
|
|
1142
|
+
return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
|
|
1143
|
+
},
|
|
1144
|
+
getCanFilter: () => {
|
|
1145
|
+
var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
|
|
1146
|
+
|
|
1147
|
+
return ((_column$columnDef$ena = column.columnDef.enableColumnFilter) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableColumnFilters) != null ? _instance$options$ena : true) && ((_instance$options$ena2 = instance.options.enableFilters) != null ? _instance$options$ena2 : true) && !!column.accessorFn;
|
|
1148
|
+
},
|
|
1149
|
+
getCanGlobalFilter: () => {
|
|
1150
|
+
var _column$columnDef$ena2, _instance$options$ena3, _instance$options$ena4, _instance$options$get;
|
|
1151
|
+
|
|
1152
|
+
return ((_column$columnDef$ena2 = column.columnDef.enableGlobalFilter) != null ? _column$columnDef$ena2 : true) && ((_instance$options$ena3 = instance.options.enableGlobalFilter) != null ? _instance$options$ena3 : true) && ((_instance$options$ena4 = instance.options.enableFilters) != null ? _instance$options$ena4 : true) && ((_instance$options$get = instance.options.getColumnCanGlobalFilter == null ? void 0 : instance.options.getColumnCanGlobalFilter(column)) != null ? _instance$options$get : true) && !!column.accessorFn;
|
|
1153
|
+
},
|
|
1154
|
+
getIsFiltered: () => column.getFilterIndex() > -1,
|
|
1155
|
+
getFilterValue: () => {
|
|
1156
|
+
var _instance$getState$co, _instance$getState$co2;
|
|
1157
|
+
|
|
1158
|
+
return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(d => d.id === column.id)) == null ? void 0 : _instance$getState$co2.value;
|
|
1159
|
+
},
|
|
1160
|
+
getFilterIndex: () => {
|
|
1161
|
+
var _instance$getState$co3, _instance$getState$co4;
|
|
1162
|
+
|
|
1163
|
+
return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(d => d.id === column.id)) != null ? _instance$getState$co3 : -1;
|
|
1164
|
+
},
|
|
1165
|
+
setFilterValue: value => {
|
|
1166
|
+
instance.setColumnFilters(old => {
|
|
1167
|
+
const filterFn = column.getFilterFn();
|
|
1168
|
+
const previousfilter = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
1169
|
+
const newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
|
|
1170
|
+
|
|
1171
|
+
if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
|
|
1172
|
+
var _old$filter;
|
|
1173
|
+
|
|
1174
|
+
return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
const newFilterObj = {
|
|
1178
|
+
id: column.id,
|
|
1179
|
+
value: newFilter
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
if (previousfilter) {
|
|
1183
|
+
var _old$map;
|
|
1184
|
+
|
|
1185
|
+
return (_old$map = old == null ? void 0 : old.map(d => {
|
|
1186
|
+
if (d.id === column.id) {
|
|
1187
|
+
return newFilterObj;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
return d;
|
|
1191
|
+
})) != null ? _old$map : [];
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
if (old != null && old.length) {
|
|
1195
|
+
return [...old, newFilterObj];
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
return [newFilterObj];
|
|
1199
|
+
});
|
|
1200
|
+
},
|
|
1201
|
+
_getFacetedRowModel: instance.options.getFacetedRowModel && instance.options.getFacetedRowModel(instance, column.id),
|
|
1202
|
+
getFacetedRowModel: () => {
|
|
1203
|
+
if (!column._getFacetedRowModel) {
|
|
1204
|
+
return instance.getPreFilteredRowModel();
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
return column._getFacetedRowModel();
|
|
1208
|
+
},
|
|
1209
|
+
_getFacetedUniqueValues: instance.options.getFacetedUniqueValues && instance.options.getFacetedUniqueValues(instance, column.id),
|
|
1210
|
+
getFacetedUniqueValues: () => {
|
|
1211
|
+
if (!column._getFacetedUniqueValues) {
|
|
1212
|
+
return new Map();
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
return column._getFacetedUniqueValues();
|
|
1216
|
+
},
|
|
1217
|
+
_getFacetedMinMaxValues: instance.options.getFacetedMinMaxValues && instance.options.getFacetedMinMaxValues(instance, column.id),
|
|
1218
|
+
getFacetedMinMaxValues: () => {
|
|
1219
|
+
if (!column._getFacetedMinMaxValues) {
|
|
1220
|
+
return undefined;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
return column._getFacetedMinMaxValues();
|
|
1224
|
+
} // () => [column.getFacetedRowModel()],
|
|
1225
|
+
// facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
|
|
1226
|
+
|
|
1227
|
+
};
|
|
1228
|
+
},
|
|
1229
|
+
createRow: (row, instance) => {
|
|
1230
|
+
return {
|
|
1231
|
+
columnFilters: {},
|
|
1232
|
+
columnFiltersMeta: {}
|
|
1233
|
+
};
|
|
1234
|
+
},
|
|
1235
|
+
createInstance: instance => {
|
|
1236
|
+
return {
|
|
1237
|
+
getGlobalAutoFilterFn: () => {
|
|
1238
|
+
return filterFns.includesString;
|
|
1239
|
+
},
|
|
1240
|
+
getGlobalFilterFn: () => {
|
|
1241
|
+
var _ref2;
|
|
1242
|
+
|
|
1243
|
+
const {
|
|
1244
|
+
filterFns: userFilterFns,
|
|
1245
|
+
globalFilterFn: globalFilterFn
|
|
1246
|
+
} = instance.options;
|
|
1247
|
+
return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterFns == null ? void 0 : userFilterFns[globalFilterFn]) != null ? _ref2 : filterFns[globalFilterFn];
|
|
1248
|
+
},
|
|
1249
|
+
setColumnFilters: updater => {
|
|
1250
|
+
const leafColumns = instance.getAllLeafColumns();
|
|
1251
|
+
|
|
1252
|
+
const updateFn = old => {
|
|
1253
|
+
var _functionalUpdate;
|
|
1254
|
+
|
|
1255
|
+
return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
|
|
1256
|
+
const column = leafColumns.find(d => d.id === filter.id);
|
|
1257
|
+
|
|
1258
|
+
if (column) {
|
|
1259
|
+
const filterFn = column.getFilterFn();
|
|
1260
|
+
|
|
1261
|
+
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
|
|
1262
|
+
return false;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
return true;
|
|
1267
|
+
});
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn);
|
|
1271
|
+
},
|
|
1272
|
+
setGlobalFilter: updater => {
|
|
1273
|
+
instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater);
|
|
1274
|
+
},
|
|
1275
|
+
resetGlobalFilter: defaultState => {
|
|
1276
|
+
instance.setGlobalFilter(defaultState ? undefined : instance.initialState.globalFilter);
|
|
1277
|
+
},
|
|
1278
|
+
resetColumnFilters: defaultState => {
|
|
1279
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
1280
|
+
|
|
1281
|
+
instance.setColumnFilters(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnFilters) != null ? _instance$initialStat : []);
|
|
1282
|
+
},
|
|
1283
|
+
getPreFilteredRowModel: () => instance.getCoreRowModel(),
|
|
1284
|
+
_getFilteredRowModel: instance.options.getFilteredRowModel && instance.options.getFilteredRowModel(instance),
|
|
1285
|
+
getFilteredRowModel: () => {
|
|
1286
|
+
if (instance.options.manualFiltering || !instance._getFilteredRowModel) {
|
|
1287
|
+
return instance.getPreFilteredRowModel();
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
return instance._getFilteredRowModel();
|
|
1291
|
+
},
|
|
1292
|
+
_getGlobalFacetedRowModel: instance.options.getFacetedRowModel && instance.options.getFacetedRowModel(instance, '__global__'),
|
|
1293
|
+
getGlobalFacetedRowModel: () => {
|
|
1294
|
+
if (instance.options.manualFiltering || !instance._getGlobalFacetedRowModel) {
|
|
1295
|
+
return instance.getPreFilteredRowModel();
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
return instance._getGlobalFacetedRowModel();
|
|
1299
|
+
},
|
|
1300
|
+
_getGlobalFacetedUniqueValues: instance.options.getFacetedUniqueValues && instance.options.getFacetedUniqueValues(instance, '__global__'),
|
|
1301
|
+
getGlobalFacetedUniqueValues: () => {
|
|
1302
|
+
if (!instance._getGlobalFacetedUniqueValues) {
|
|
1303
|
+
return new Map();
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
return instance._getGlobalFacetedUniqueValues();
|
|
1307
|
+
},
|
|
1308
|
+
_getGlobalFacetedMinMaxValues: instance.options.getFacetedMinMaxValues && instance.options.getFacetedMinMaxValues(instance, '__global__'),
|
|
1309
|
+
getGlobalFacetedMinMaxValues: () => {
|
|
1310
|
+
if (!instance._getGlobalFacetedMinMaxValues) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
return instance._getGlobalFacetedMinMaxValues();
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
function shouldAutoRemoveFilter(filterFn, value, column) {
|
|
1320
|
+
return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
const sum = (columnId, _leafRows, childRows) => {
|
|
1324
|
+
// It's faster to just add the aggregations together instead of
|
|
1325
|
+
// process leaf nodes individually
|
|
1326
|
+
return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
const min = (columnId, _leafRows, childRows) => {
|
|
1330
|
+
let min;
|
|
1331
|
+
childRows.forEach(row => {
|
|
1332
|
+
const value = row.getValue(columnId);
|
|
1333
|
+
|
|
1334
|
+
if (value != null && (min > value || min === undefined && value >= value)) {
|
|
1335
|
+
min = value;
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
return min;
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
const max = (columnId, _leafRows, childRows) => {
|
|
1342
|
+
let max;
|
|
1343
|
+
childRows.forEach(row => {
|
|
1344
|
+
const value = row.getValue(columnId);
|
|
1345
|
+
|
|
1346
|
+
if (value != null && (max < value || max === undefined && value >= value)) {
|
|
1347
|
+
max = value;
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
return max;
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
const extent = (columnId, _leafRows, childRows) => {
|
|
1354
|
+
let min;
|
|
1355
|
+
let max;
|
|
1356
|
+
childRows.forEach(row => {
|
|
1357
|
+
const value = row.getValue(columnId);
|
|
1358
|
+
|
|
1359
|
+
if (value != null) {
|
|
1360
|
+
if (min === undefined) {
|
|
1361
|
+
if (value >= value) min = max = value;
|
|
1362
|
+
} else {
|
|
1363
|
+
if (min > value) min = value;
|
|
1364
|
+
if (max < value) max = value;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
return [min, max];
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
const mean = (columnId, leafRows) => {
|
|
1372
|
+
let count = 0;
|
|
1373
|
+
let sum = 0;
|
|
1374
|
+
leafRows.forEach(row => {
|
|
1375
|
+
let value = row.getValue(columnId);
|
|
1376
|
+
|
|
1377
|
+
if (value != null && (value = +value) >= value) {
|
|
1378
|
+
++count, sum += value;
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
if (count) return sum / count;
|
|
1382
|
+
return;
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
const median = (columnId, leafRows) => {
|
|
1386
|
+
if (!leafRows.length) {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
let min = 0;
|
|
1391
|
+
let max = 0;
|
|
1392
|
+
leafRows.forEach(row => {
|
|
1393
|
+
let value = row.getValue(columnId);
|
|
1394
|
+
|
|
1395
|
+
if (typeof value === 'number') {
|
|
1396
|
+
min = Math.min(min, value);
|
|
1397
|
+
max = Math.max(max, value);
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
return (min + max) / 2;
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
const unique = (columnId, leafRows) => {
|
|
1404
|
+
return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
const uniqueCount = (columnId, leafRows) => {
|
|
1408
|
+
return new Set(leafRows.map(d => d.getValue(columnId))).size;
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
const count = (_columnId, leafRows) => {
|
|
1412
|
+
return leafRows.length;
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
const aggregationFns = {
|
|
1416
|
+
sum,
|
|
1417
|
+
min,
|
|
1418
|
+
max,
|
|
1419
|
+
extent,
|
|
1420
|
+
mean,
|
|
1421
|
+
median,
|
|
1422
|
+
unique,
|
|
1423
|
+
uniqueCount,
|
|
1424
|
+
count
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
//
|
|
1428
|
+
const Grouping = {
|
|
1429
|
+
getDefaultColumnDef: () => {
|
|
1430
|
+
return {
|
|
1431
|
+
aggregationFn: 'auto'
|
|
1432
|
+
};
|
|
1433
|
+
},
|
|
1434
|
+
getInitialState: state => {
|
|
1435
|
+
return {
|
|
1436
|
+
grouping: [],
|
|
1437
|
+
...state
|
|
1438
|
+
};
|
|
1439
|
+
},
|
|
1440
|
+
getDefaultOptions: instance => {
|
|
1441
|
+
return {
|
|
1442
|
+
onGroupingChange: makeStateUpdater('grouping', instance),
|
|
1443
|
+
groupedColumnMode: 'reorder'
|
|
1444
|
+
};
|
|
1445
|
+
},
|
|
1446
|
+
createColumn: (column, instance) => {
|
|
1447
|
+
return {
|
|
1448
|
+
toggleGrouping: () => {
|
|
1449
|
+
instance.setGrouping(old => {
|
|
1450
|
+
// Find any existing grouping for this column
|
|
1451
|
+
if (old != null && old.includes(column.id)) {
|
|
1452
|
+
return old.filter(d => d !== column.id);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
return [...(old != null ? old : []), column.id];
|
|
1456
|
+
});
|
|
1457
|
+
},
|
|
1458
|
+
getCanGroup: () => {
|
|
1459
|
+
var _ref, _ref2, _ref3, _column$columnDef$ena;
|
|
1460
|
+
|
|
1461
|
+
return (_ref = (_ref2 = (_ref3 = (_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) != null ? _ref3 : instance.options.enableGrouping) != null ? _ref2 : true) != null ? _ref : !!column.accessorFn;
|
|
1462
|
+
},
|
|
1463
|
+
getIsGrouped: () => {
|
|
1464
|
+
var _instance$getState$gr;
|
|
1465
|
+
|
|
1466
|
+
return (_instance$getState$gr = instance.getState().grouping) == null ? void 0 : _instance$getState$gr.includes(column.id);
|
|
1467
|
+
},
|
|
1468
|
+
getGroupedIndex: () => {
|
|
1469
|
+
var _instance$getState$gr2;
|
|
1470
|
+
|
|
1471
|
+
return (_instance$getState$gr2 = instance.getState().grouping) == null ? void 0 : _instance$getState$gr2.indexOf(column.id);
|
|
1472
|
+
},
|
|
1473
|
+
getToggleGroupingHandler: () => {
|
|
1474
|
+
const canGroup = column.getCanGroup();
|
|
1475
|
+
return () => {
|
|
1476
|
+
if (!canGroup) return;
|
|
1477
|
+
column.toggleGrouping();
|
|
1478
|
+
};
|
|
1479
|
+
},
|
|
1480
|
+
getAutoAggregationFn: () => {
|
|
1481
|
+
const firstRow = instance.getCoreRowModel().flatRows[0];
|
|
1482
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
1483
|
+
|
|
1484
|
+
if (typeof value === 'number') {
|
|
1485
|
+
return aggregationFns.sum;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
1489
|
+
return aggregationFns.extent;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
return aggregationFns.count;
|
|
1493
|
+
},
|
|
1494
|
+
getAggregationFn: () => {
|
|
1495
|
+
var _ref4;
|
|
1496
|
+
|
|
1497
|
+
const userAggregationFns = instance.options.aggregationFns;
|
|
1498
|
+
|
|
1499
|
+
if (!column) {
|
|
1500
|
+
throw new Error();
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
},
|
|
1507
|
+
createInstance: instance => {
|
|
1508
|
+
return {
|
|
1509
|
+
setGrouping: updater => instance.options.onGroupingChange == null ? void 0 : instance.options.onGroupingChange(updater),
|
|
1510
|
+
resetGrouping: defaultState => {
|
|
1511
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
1512
|
+
|
|
1513
|
+
instance.setGrouping(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
|
|
1514
|
+
},
|
|
1515
|
+
getPreGroupedRowModel: () => instance.getSortedRowModel(),
|
|
1516
|
+
getGroupedRowModel: () => {
|
|
1517
|
+
if (!instance._getGroupedRowModel && instance.options.getGroupedRowModel) {
|
|
1518
|
+
instance._getGroupedRowModel = instance.options.getGroupedRowModel(instance);
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
if (instance.options.manualGrouping || !instance._getGroupedRowModel) {
|
|
1522
|
+
return instance.getPreGroupedRowModel();
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
return instance._getGroupedRowModel();
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
},
|
|
1529
|
+
createRow: row => {
|
|
1530
|
+
return {
|
|
1531
|
+
getIsGrouped: () => !!row.groupingColumnId,
|
|
1532
|
+
_groupingValuesCache: {}
|
|
1533
|
+
};
|
|
1534
|
+
},
|
|
1535
|
+
createCell: (cell, column, row, instance) => {
|
|
1536
|
+
return {
|
|
1537
|
+
getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
1538
|
+
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
1539
|
+
getIsAggregated: () => {
|
|
1540
|
+
var _row$subRows;
|
|
1541
|
+
|
|
1542
|
+
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
|
|
1543
|
+
},
|
|
1544
|
+
renderAggregatedCell: () => {
|
|
1545
|
+
var _column$columnDef$agg;
|
|
1546
|
+
|
|
1547
|
+
const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
|
|
1548
|
+
return template ? instance._render(template, {
|
|
1549
|
+
instance,
|
|
1550
|
+
column,
|
|
1551
|
+
row,
|
|
1552
|
+
cell,
|
|
1553
|
+
getValue: cell.getValue
|
|
1554
|
+
}) : null;
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
function orderColumns(leafColumns, grouping, groupedColumnMode) {
|
|
1560
|
+
if (!(grouping != null && grouping.length) || !groupedColumnMode) {
|
|
1561
|
+
return leafColumns;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
|
|
1565
|
+
|
|
1566
|
+
if (groupedColumnMode === 'remove') {
|
|
1567
|
+
return nonGroupingColumns;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
|
|
1571
|
+
return [...groupingColumns, ...nonGroupingColumns];
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
//
|
|
1575
|
+
const Ordering = {
|
|
1576
|
+
getInitialState: state => {
|
|
1577
|
+
return {
|
|
1578
|
+
columnOrder: [],
|
|
1579
|
+
...state
|
|
1580
|
+
};
|
|
1581
|
+
},
|
|
1582
|
+
getDefaultOptions: instance => {
|
|
1583
|
+
return {
|
|
1584
|
+
onColumnOrderChange: makeStateUpdater('columnOrder', instance)
|
|
1585
|
+
};
|
|
1586
|
+
},
|
|
1587
|
+
createInstance: instance => {
|
|
1588
|
+
return {
|
|
1589
|
+
setColumnOrder: updater => instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater),
|
|
1590
|
+
resetColumnOrder: defaultState => {
|
|
1591
|
+
var _instance$initialStat;
|
|
1592
|
+
|
|
1593
|
+
instance.setColumnOrder(defaultState ? [] : (_instance$initialStat = instance.initialState.columnOrder) != null ? _instance$initialStat : []);
|
|
1594
|
+
},
|
|
1595
|
+
_getOrderColumnsFn: memo(() => [instance.getState().columnOrder, instance.getState().grouping, instance.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
|
|
1596
|
+
// Sort grouped columns to the start of the column list
|
|
1597
|
+
// before the headers are built
|
|
1598
|
+
let orderedColumns = []; // If there is no order, return the normal columns
|
|
1599
|
+
|
|
1600
|
+
if (!(columnOrder != null && columnOrder.length)) {
|
|
1601
|
+
orderedColumns = columns;
|
|
1602
|
+
} else {
|
|
1603
|
+
const columnOrderCopy = [...columnOrder]; // If there is an order, make a copy of the columns
|
|
1604
|
+
|
|
1605
|
+
const columnsCopy = [...columns]; // And make a new ordered array of the columns
|
|
1606
|
+
// Loop over the columns and place them in order into the new array
|
|
1607
|
+
|
|
1608
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
1609
|
+
const targetColumnId = columnOrderCopy.shift();
|
|
1610
|
+
const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
|
|
1611
|
+
|
|
1612
|
+
if (foundIndex > -1) {
|
|
1613
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
|
|
1614
|
+
}
|
|
1615
|
+
} // If there are any columns left, add them to the end
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
orderedColumns = [...orderedColumns, ...columnsCopy];
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
return orderColumns(orderedColumns, grouping, groupedColumnMode);
|
|
1622
|
+
}, {
|
|
1623
|
+
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn' // debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
1624
|
+
|
|
1625
|
+
})
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
//
|
|
1631
|
+
const defaultPageIndex = 0;
|
|
1632
|
+
const defaultPageSize = 10;
|
|
1633
|
+
|
|
1634
|
+
const getDefaultPaginationState = () => ({
|
|
1635
|
+
pageIndex: defaultPageIndex,
|
|
1636
|
+
pageSize: defaultPageSize
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
const Pagination = {
|
|
1640
|
+
getInitialState: state => {
|
|
1641
|
+
return { ...state,
|
|
1642
|
+
pagination: { ...getDefaultPaginationState(),
|
|
1643
|
+
...(state == null ? void 0 : state.pagination)
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
},
|
|
1647
|
+
getDefaultOptions: instance => {
|
|
1648
|
+
return {
|
|
1649
|
+
onPaginationChange: makeStateUpdater('pagination', instance)
|
|
1650
|
+
};
|
|
1651
|
+
},
|
|
1652
|
+
createInstance: instance => {
|
|
1653
|
+
let registered = false;
|
|
1654
|
+
let queued = false;
|
|
1655
|
+
return {
|
|
1656
|
+
_autoResetPageIndex: () => {
|
|
1657
|
+
var _ref, _instance$options$aut;
|
|
1658
|
+
|
|
1659
|
+
if (!registered) {
|
|
1660
|
+
instance._queue(() => {
|
|
1661
|
+
registered = true;
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
|
|
1668
|
+
if (queued) return;
|
|
1669
|
+
queued = true;
|
|
1670
|
+
|
|
1671
|
+
instance._queue(() => {
|
|
1672
|
+
instance.resetPageIndex();
|
|
1673
|
+
queued = false;
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
},
|
|
1677
|
+
setPagination: updater => {
|
|
1678
|
+
const safeUpdater = old => {
|
|
1679
|
+
let newState = functionalUpdate(updater, old);
|
|
1680
|
+
return newState;
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater);
|
|
1684
|
+
},
|
|
1685
|
+
resetPagination: defaultState => {
|
|
1686
|
+
var _instance$initialStat;
|
|
1687
|
+
|
|
1688
|
+
instance.setPagination(defaultState ? getDefaultPaginationState() : (_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : getDefaultPaginationState());
|
|
1689
|
+
},
|
|
1690
|
+
setPageIndex: updater => {
|
|
1691
|
+
instance.setPagination(old => {
|
|
1692
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
1693
|
+
const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
|
|
1694
|
+
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
|
|
1695
|
+
return { ...old,
|
|
1696
|
+
pageIndex
|
|
1697
|
+
};
|
|
1698
|
+
});
|
|
1699
|
+
},
|
|
1700
|
+
resetPageIndex: defaultState => {
|
|
1701
|
+
var _instance$initialStat2, _instance$initialStat3, _instance$initialStat4;
|
|
1702
|
+
|
|
1703
|
+
instance.setPageIndex(defaultState ? defaultPageIndex : (_instance$initialStat2 = (_instance$initialStat3 = instance.initialState) == null ? void 0 : (_instance$initialStat4 = _instance$initialStat3.pagination) == null ? void 0 : _instance$initialStat4.pageIndex) != null ? _instance$initialStat2 : defaultPageIndex);
|
|
1704
|
+
},
|
|
1705
|
+
resetPageSize: defaultState => {
|
|
1706
|
+
var _instance$initialStat5, _instance$initialStat6, _instance$initialStat7;
|
|
1707
|
+
|
|
1708
|
+
instance.setPageSize(defaultState ? defaultPageSize : (_instance$initialStat5 = (_instance$initialStat6 = instance.initialState) == null ? void 0 : (_instance$initialStat7 = _instance$initialStat6.pagination) == null ? void 0 : _instance$initialStat7.pageSize) != null ? _instance$initialStat5 : defaultPageSize);
|
|
1709
|
+
},
|
|
1710
|
+
setPageSize: updater => {
|
|
1711
|
+
instance.setPagination(old => {
|
|
1712
|
+
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
|
|
1713
|
+
const topRowIndex = old.pageSize * old.pageIndex;
|
|
1714
|
+
const pageIndex = Math.floor(topRowIndex / pageSize);
|
|
1715
|
+
return { ...old,
|
|
1716
|
+
pageIndex,
|
|
1717
|
+
pageSize
|
|
1718
|
+
};
|
|
1719
|
+
});
|
|
1720
|
+
},
|
|
1721
|
+
setPageCount: updater => instance.setPagination(old => {
|
|
1722
|
+
var _old$pageCount;
|
|
1723
|
+
|
|
1724
|
+
let newPageCount = functionalUpdate(updater, (_old$pageCount = old.pageCount) != null ? _old$pageCount : -1);
|
|
1725
|
+
|
|
1726
|
+
if (typeof newPageCount === 'number') {
|
|
1727
|
+
newPageCount = Math.max(-1, newPageCount);
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
return { ...old,
|
|
1731
|
+
pageCount: newPageCount
|
|
1732
|
+
};
|
|
1733
|
+
}),
|
|
1734
|
+
getPageOptions: memo(() => [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount], (pageSize, pageCount) => {
|
|
1735
|
+
let pageOptions = [];
|
|
1736
|
+
|
|
1737
|
+
if (pageCount && pageCount > 0) {
|
|
1738
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
return pageOptions;
|
|
1742
|
+
}, {
|
|
1743
|
+
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
1744
|
+
debug: () => {
|
|
1745
|
+
var _instance$options$deb;
|
|
1746
|
+
|
|
1747
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
1748
|
+
}
|
|
1749
|
+
}),
|
|
1750
|
+
getCanPreviousPage: () => instance.getState().pagination.pageIndex > 0,
|
|
1751
|
+
getCanNextPage: () => {
|
|
1752
|
+
const {
|
|
1753
|
+
pageIndex
|
|
1754
|
+
} = instance.getState().pagination;
|
|
1755
|
+
const pageCount = instance.getPageCount();
|
|
1756
|
+
|
|
1757
|
+
if (pageCount === -1) {
|
|
1758
|
+
return true;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
if (pageCount === 0) {
|
|
1762
|
+
return false;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
return pageIndex < pageCount - 1;
|
|
1766
|
+
},
|
|
1767
|
+
previousPage: () => {
|
|
1768
|
+
return instance.setPageIndex(old => old - 1);
|
|
1769
|
+
},
|
|
1770
|
+
nextPage: () => {
|
|
1771
|
+
return instance.setPageIndex(old => {
|
|
1772
|
+
return old + 1;
|
|
1773
|
+
});
|
|
1774
|
+
},
|
|
1775
|
+
getPrePaginationRowModel: () => instance.getExpandedRowModel(),
|
|
1776
|
+
getPaginationRowModel: () => {
|
|
1777
|
+
if (!instance._getPaginationRowModel && instance.options.getPaginationRowModel) {
|
|
1778
|
+
instance._getPaginationRowModel = instance.options.getPaginationRowModel(instance);
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
if (instance.options.manualPagination || !instance._getPaginationRowModel) {
|
|
1782
|
+
return instance.getPrePaginationRowModel();
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
return instance._getPaginationRowModel();
|
|
1786
|
+
},
|
|
1787
|
+
getPageCount: () => {
|
|
1788
|
+
const {
|
|
1789
|
+
pageCount
|
|
1790
|
+
} = instance.getState().pagination;
|
|
1791
|
+
|
|
1792
|
+
if (typeof pageCount !== 'undefined') {
|
|
1793
|
+
return pageCount;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
return Math.ceil(instance.getPrePaginationRowModel().rows.length / instance.getState().pagination.pageSize);
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
//
|
|
1803
|
+
const getDefaultPinningState = () => ({
|
|
1804
|
+
left: [],
|
|
1805
|
+
right: []
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
const Pinning = {
|
|
1809
|
+
getInitialState: state => {
|
|
1810
|
+
return {
|
|
1811
|
+
columnPinning: getDefaultPinningState(),
|
|
1812
|
+
...state
|
|
1813
|
+
};
|
|
1814
|
+
},
|
|
1815
|
+
getDefaultOptions: instance => {
|
|
1816
|
+
return {
|
|
1817
|
+
onColumnPinningChange: makeStateUpdater('columnPinning', instance)
|
|
1818
|
+
};
|
|
1819
|
+
},
|
|
1820
|
+
createColumn: (column, instance) => {
|
|
1821
|
+
return {
|
|
1822
|
+
pin: position => {
|
|
1823
|
+
const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
|
|
1824
|
+
instance.setColumnPinning(old => {
|
|
1825
|
+
var _old$left3, _old$right3;
|
|
1826
|
+
|
|
1827
|
+
if (position === 'right') {
|
|
1828
|
+
var _old$left, _old$right;
|
|
1829
|
+
|
|
1830
|
+
return {
|
|
1831
|
+
left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
1832
|
+
right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
if (position === 'left') {
|
|
1837
|
+
var _old$left2, _old$right2;
|
|
1838
|
+
|
|
1839
|
+
return {
|
|
1840
|
+
left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
|
|
1841
|
+
right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
return {
|
|
1846
|
+
left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
|
|
1847
|
+
right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
|
|
1848
|
+
};
|
|
1849
|
+
});
|
|
1850
|
+
},
|
|
1851
|
+
getCanPin: () => {
|
|
1852
|
+
const leafColumns = column.getLeafColumns();
|
|
1853
|
+
return leafColumns.some(d => {
|
|
1854
|
+
var _d$columnDef$enablePi, _instance$options$ena;
|
|
1855
|
+
|
|
1856
|
+
return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_instance$options$ena = instance.options.enablePinning) != null ? _instance$options$ena : true);
|
|
1857
|
+
});
|
|
1858
|
+
},
|
|
1859
|
+
getIsPinned: () => {
|
|
1860
|
+
const leafColumnIds = column.getLeafColumns().map(d => d.id);
|
|
1861
|
+
const {
|
|
1862
|
+
left,
|
|
1863
|
+
right
|
|
1864
|
+
} = instance.getState().columnPinning;
|
|
1865
|
+
const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
|
|
1866
|
+
const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
|
|
1867
|
+
return isLeft ? 'left' : isRight ? 'right' : false;
|
|
1868
|
+
},
|
|
1869
|
+
getPinnedIndex: () => {
|
|
1870
|
+
var _instance$getState$co, _instance$getState$co2, _instance$getState$co3;
|
|
1871
|
+
|
|
1872
|
+
const position = column.getIsPinned();
|
|
1873
|
+
return position ? (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnPinning) == null ? void 0 : (_instance$getState$co3 = _instance$getState$co2[position]) == null ? void 0 : _instance$getState$co3.indexOf(column.id)) != null ? _instance$getState$co : -1 : 0;
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
},
|
|
1877
|
+
createRow: (row, instance) => {
|
|
1878
|
+
return {
|
|
1879
|
+
getCenterVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allCells, left, right) => {
|
|
1880
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
1881
|
+
return allCells.filter(d => !leftAndRight.includes(d.column.id));
|
|
1882
|
+
}, {
|
|
1883
|
+
key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
|
|
1884
|
+
debug: () => {
|
|
1885
|
+
var _instance$options$deb;
|
|
1886
|
+
|
|
1887
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
|
|
1888
|
+
}
|
|
1889
|
+
}),
|
|
1890
|
+
getLeftVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.left,,], (allCells, left) => {
|
|
1891
|
+
const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
|
|
1892
|
+
position: 'left'
|
|
1893
|
+
}));
|
|
1894
|
+
return cells;
|
|
1895
|
+
}, {
|
|
1896
|
+
key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
|
|
1897
|
+
debug: () => {
|
|
1898
|
+
var _instance$options$deb2;
|
|
1899
|
+
|
|
1900
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
|
|
1901
|
+
}
|
|
1902
|
+
}),
|
|
1903
|
+
getRightVisibleCells: memo(() => [row._getAllVisibleCells(), instance.getState().columnPinning.right], (allCells, right) => {
|
|
1904
|
+
const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({ ...d,
|
|
1905
|
+
position: 'left'
|
|
1906
|
+
}));
|
|
1907
|
+
return cells;
|
|
1908
|
+
}, {
|
|
1909
|
+
key: process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
|
|
1910
|
+
debug: () => {
|
|
1911
|
+
var _instance$options$deb3;
|
|
1912
|
+
|
|
1913
|
+
return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugRows;
|
|
1914
|
+
}
|
|
1915
|
+
})
|
|
1916
|
+
};
|
|
1917
|
+
},
|
|
1918
|
+
createInstance: instance => {
|
|
1919
|
+
return {
|
|
1920
|
+
setColumnPinning: updater => instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater),
|
|
1921
|
+
resetColumnPinning: defaultState => {
|
|
1922
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
1923
|
+
|
|
1924
|
+
return instance.setColumnPinning(defaultState ? getDefaultPinningState() : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.columnPinning) != null ? _instance$initialStat : getDefaultPinningState());
|
|
1925
|
+
},
|
|
1926
|
+
getIsSomeColumnsPinned: position => {
|
|
1927
|
+
var _pinningState$positio;
|
|
1928
|
+
|
|
1929
|
+
const pinningState = instance.getState().columnPinning;
|
|
1930
|
+
|
|
1931
|
+
if (!position) {
|
|
1932
|
+
var _pinningState$left, _pinningState$right;
|
|
1933
|
+
|
|
1934
|
+
return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
|
|
1938
|
+
},
|
|
1939
|
+
getLeftLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.left], (allColumns, left) => {
|
|
1940
|
+
return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
1941
|
+
}, {
|
|
1942
|
+
key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
|
|
1943
|
+
debug: () => {
|
|
1944
|
+
var _instance$options$deb4;
|
|
1945
|
+
|
|
1946
|
+
return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
|
|
1947
|
+
}
|
|
1948
|
+
}),
|
|
1949
|
+
getRightLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.right], (allColumns, right) => {
|
|
1950
|
+
return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
|
|
1951
|
+
}, {
|
|
1952
|
+
key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
|
|
1953
|
+
debug: () => {
|
|
1954
|
+
var _instance$options$deb5;
|
|
1955
|
+
|
|
1956
|
+
return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
|
|
1957
|
+
}
|
|
1958
|
+
}),
|
|
1959
|
+
getCenterLeafColumns: memo(() => [instance.getAllLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, left, right) => {
|
|
1960
|
+
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
1961
|
+
return allColumns.filter(d => !leftAndRight.includes(d.id));
|
|
1962
|
+
}, {
|
|
1963
|
+
key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
|
|
1964
|
+
debug: () => {
|
|
1965
|
+
var _instance$options$deb6;
|
|
1966
|
+
|
|
1967
|
+
return (_instance$options$deb6 = instance.options.debugAll) != null ? _instance$options$deb6 : instance.options.debugColumns;
|
|
1968
|
+
}
|
|
1969
|
+
})
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
//
|
|
1975
|
+
const RowSelection = {
|
|
1976
|
+
getInitialState: state => {
|
|
1977
|
+
return {
|
|
1978
|
+
rowSelection: {},
|
|
1979
|
+
...state
|
|
1980
|
+
};
|
|
1981
|
+
},
|
|
1982
|
+
getDefaultOptions: instance => {
|
|
1983
|
+
return {
|
|
1984
|
+
onRowSelectionChange: makeStateUpdater('rowSelection', instance),
|
|
1985
|
+
enableRowSelection: true,
|
|
1986
|
+
enableMultiRowSelection: true,
|
|
1987
|
+
enableSubRowSelection: true // enableGroupingRowSelection: false,
|
|
1988
|
+
// isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
|
|
1989
|
+
// isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
|
|
1990
|
+
|
|
1991
|
+
};
|
|
1992
|
+
},
|
|
1993
|
+
createInstance: instance => {
|
|
1994
|
+
return {
|
|
1995
|
+
setRowSelection: updater => instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater),
|
|
1996
|
+
resetRowSelection: defaultState => {
|
|
1997
|
+
var _instance$initialStat;
|
|
1998
|
+
|
|
1999
|
+
return instance.setRowSelection(defaultState ? {} : (_instance$initialStat = instance.initialState.rowSelection) != null ? _instance$initialStat : {});
|
|
2000
|
+
},
|
|
2001
|
+
toggleAllRowsSelected: value => {
|
|
2002
|
+
instance.setRowSelection(old => {
|
|
2003
|
+
value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected();
|
|
2004
|
+
const rowSelection = { ...old
|
|
2005
|
+
};
|
|
2006
|
+
const preGroupedFlatRows = instance.getPreGroupedRowModel().flatRows; // We don't use `mutateRowIsSelected` here for performance reasons.
|
|
2007
|
+
// All of the rows are flat already, so it wouldn't be worth it
|
|
2008
|
+
|
|
2009
|
+
if (value) {
|
|
2010
|
+
preGroupedFlatRows.forEach(row => {
|
|
2011
|
+
rowSelection[row.id] = true;
|
|
2012
|
+
});
|
|
2013
|
+
} else {
|
|
2014
|
+
preGroupedFlatRows.forEach(row => {
|
|
2015
|
+
delete rowSelection[row.id];
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
return rowSelection;
|
|
2020
|
+
});
|
|
2021
|
+
},
|
|
2022
|
+
toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
|
|
2023
|
+
typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
|
|
2024
|
+
const rowSelection = { ...old
|
|
2025
|
+
};
|
|
2026
|
+
instance.getRowModel().rows.forEach(row => {
|
|
2027
|
+
mutateRowIsSelected(rowSelection, row.id, value, instance);
|
|
2028
|
+
});
|
|
2029
|
+
return rowSelection;
|
|
2030
|
+
}),
|
|
2031
|
+
// addRowSelectionRange: rowId => {
|
|
2032
|
+
// const {
|
|
2033
|
+
// rows,
|
|
2034
|
+
// rowsById,
|
|
2035
|
+
// options: { selectGroupingRows, selectSubRows },
|
|
2036
|
+
// } = instance
|
|
2037
|
+
// const findSelectedRow = (rows: Row[]) => {
|
|
2038
|
+
// let found
|
|
2039
|
+
// rows.find(d => {
|
|
2040
|
+
// if (d.getIsSelected()) {
|
|
2041
|
+
// found = d
|
|
2042
|
+
// return true
|
|
2043
|
+
// }
|
|
2044
|
+
// const subFound = findSelectedRow(d.subRows || [])
|
|
2045
|
+
// if (subFound) {
|
|
2046
|
+
// found = subFound
|
|
2047
|
+
// return true
|
|
2048
|
+
// }
|
|
2049
|
+
// return false
|
|
2050
|
+
// })
|
|
2051
|
+
// return found
|
|
2052
|
+
// }
|
|
2053
|
+
// const firstRow = findSelectedRow(rows) || rows[0]
|
|
2054
|
+
// const lastRow = rowsById[rowId]
|
|
2055
|
+
// let include = false
|
|
2056
|
+
// const selectedRowIds = {}
|
|
2057
|
+
// const addRow = (row: Row) => {
|
|
2058
|
+
// mutateRowIsSelected(selectedRowIds, row.id, true, {
|
|
2059
|
+
// rowsById,
|
|
2060
|
+
// selectGroupingRows: selectGroupingRows!,
|
|
2061
|
+
// selectSubRows: selectSubRows!,
|
|
2062
|
+
// })
|
|
2063
|
+
// }
|
|
2064
|
+
// instance.rows.forEach(row => {
|
|
2065
|
+
// const isFirstRow = row.id === firstRow.id
|
|
2066
|
+
// const isLastRow = row.id === lastRow.id
|
|
2067
|
+
// if (isFirstRow || isLastRow) {
|
|
2068
|
+
// if (!include) {
|
|
2069
|
+
// include = true
|
|
2070
|
+
// } else if (include) {
|
|
2071
|
+
// addRow(row)
|
|
2072
|
+
// include = false
|
|
2073
|
+
// }
|
|
2074
|
+
// }
|
|
2075
|
+
// if (include) {
|
|
2076
|
+
// addRow(row)
|
|
2077
|
+
// }
|
|
2078
|
+
// })
|
|
2079
|
+
// instance.setRowSelection(selectedRowIds)
|
|
2080
|
+
// },
|
|
2081
|
+
getPreSelectedRowModel: () => instance.getCoreRowModel(),
|
|
2082
|
+
getSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getCoreRowModel()], (rowSelection, rowModel) => {
|
|
2083
|
+
if (!Object.keys(rowSelection).length) {
|
|
2084
|
+
return {
|
|
2085
|
+
rows: [],
|
|
2086
|
+
flatRows: [],
|
|
2087
|
+
rowsById: {}
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
return selectRowsFn(instance, rowModel);
|
|
2092
|
+
}, {
|
|
2093
|
+
key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
|
|
2094
|
+
debug: () => {
|
|
2095
|
+
var _instance$options$deb;
|
|
2096
|
+
|
|
2097
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
2098
|
+
}
|
|
2099
|
+
}),
|
|
2100
|
+
getFilteredSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getFilteredRowModel()], (rowSelection, rowModel) => {
|
|
2101
|
+
if (!Object.keys(rowSelection).length) {
|
|
2102
|
+
return {
|
|
2103
|
+
rows: [],
|
|
2104
|
+
flatRows: [],
|
|
2105
|
+
rowsById: {}
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
return selectRowsFn(instance, rowModel);
|
|
2110
|
+
}, {
|
|
2111
|
+
key: process.env.NODE_ENV === 'production' && 'getFilteredSelectedRowModel',
|
|
2112
|
+
debug: () => {
|
|
2113
|
+
var _instance$options$deb2;
|
|
2114
|
+
|
|
2115
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
|
|
2116
|
+
}
|
|
2117
|
+
}),
|
|
2118
|
+
getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getGroupedRowModel()], (rowSelection, rowModel) => {
|
|
2119
|
+
if (!Object.keys(rowSelection).length) {
|
|
2120
|
+
return {
|
|
2121
|
+
rows: [],
|
|
2122
|
+
flatRows: [],
|
|
2123
|
+
rowsById: {}
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
return selectRowsFn(instance, rowModel);
|
|
2128
|
+
}, {
|
|
2129
|
+
key: process.env.NODE_ENV === 'production' && 'getGroupedSelectedRowModel',
|
|
2130
|
+
debug: () => {
|
|
2131
|
+
var _instance$options$deb3;
|
|
2132
|
+
|
|
2133
|
+
return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugTable;
|
|
2134
|
+
}
|
|
2135
|
+
}),
|
|
2136
|
+
///
|
|
2137
|
+
// getGroupingRowCanSelect: rowId => {
|
|
2138
|
+
// const row = instance.getRow(rowId)
|
|
2139
|
+
// if (!row) {
|
|
2140
|
+
// throw new Error()
|
|
2141
|
+
// }
|
|
2142
|
+
// if (typeof instance.options.enableGroupingRowSelection === 'function') {
|
|
2143
|
+
// return instance.options.enableGroupingRowSelection(row)
|
|
2144
|
+
// }
|
|
2145
|
+
// return instance.options.enableGroupingRowSelection ?? false
|
|
2146
|
+
// },
|
|
2147
|
+
getIsAllRowsSelected: () => {
|
|
2148
|
+
const preFilteredFlatRows = instance.getPreFilteredRowModel().flatRows;
|
|
2149
|
+
const {
|
|
2150
|
+
rowSelection
|
|
2151
|
+
} = instance.getState();
|
|
2152
|
+
let isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
|
|
2153
|
+
|
|
2154
|
+
if (isAllRowsSelected) {
|
|
2155
|
+
if (preFilteredFlatRows.some(row => !rowSelection[row.id])) {
|
|
2156
|
+
isAllRowsSelected = false;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
return isAllRowsSelected;
|
|
2161
|
+
},
|
|
2162
|
+
getIsAllPageRowsSelected: () => {
|
|
2163
|
+
const paginationFlatRows = instance.getPaginationRowModel().flatRows;
|
|
2164
|
+
const {
|
|
2165
|
+
rowSelection
|
|
2166
|
+
} = instance.getState();
|
|
2167
|
+
let isAllPageRowsSelected = !!paginationFlatRows.length;
|
|
2168
|
+
|
|
2169
|
+
if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
|
|
2170
|
+
isAllPageRowsSelected = false;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
return isAllPageRowsSelected;
|
|
2174
|
+
},
|
|
2175
|
+
getIsSomeRowsSelected: () => {
|
|
2176
|
+
var _instance$getState$ro;
|
|
2177
|
+
|
|
2178
|
+
return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
|
|
2179
|
+
},
|
|
2180
|
+
getIsSomePageRowsSelected: () => {
|
|
2181
|
+
const paginationFlatRows = instance.getPaginationRowModel().flatRows;
|
|
2182
|
+
return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
|
|
2183
|
+
},
|
|
2184
|
+
getToggleAllRowsSelectedHandler: () => {
|
|
2185
|
+
return e => {
|
|
2186
|
+
instance.toggleAllRowsSelected(e.target.checked);
|
|
2187
|
+
};
|
|
2188
|
+
},
|
|
2189
|
+
getToggleAllPageRowsSelectedHandler: () => {
|
|
2190
|
+
return e => {
|
|
2191
|
+
instance.toggleAllPageRowsSelected(e.target.checked);
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
};
|
|
2195
|
+
},
|
|
2196
|
+
createRow: (row, instance) => {
|
|
2197
|
+
return {
|
|
2198
|
+
toggleSelected: value => {
|
|
2199
|
+
const isSelected = row.getIsSelected();
|
|
2200
|
+
instance.setRowSelection(old => {
|
|
2201
|
+
value = typeof value !== 'undefined' ? value : !isSelected;
|
|
2202
|
+
|
|
2203
|
+
if (isSelected === value) {
|
|
2204
|
+
return old;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
const selectedRowIds = { ...old
|
|
2208
|
+
};
|
|
2209
|
+
mutateRowIsSelected(selectedRowIds, row.id, value, instance);
|
|
2210
|
+
return selectedRowIds;
|
|
2211
|
+
});
|
|
2212
|
+
},
|
|
2213
|
+
getIsSelected: () => {
|
|
2214
|
+
const {
|
|
2215
|
+
rowSelection
|
|
2216
|
+
} = instance.getState();
|
|
2217
|
+
return isRowSelected(row, rowSelection) === true;
|
|
2218
|
+
},
|
|
2219
|
+
getIsSomeSelected: () => {
|
|
2220
|
+
const {
|
|
2221
|
+
rowSelection
|
|
2222
|
+
} = instance.getState();
|
|
2223
|
+
return isRowSelected(row, rowSelection) === 'some';
|
|
2224
|
+
},
|
|
2225
|
+
getCanSelect: () => {
|
|
2226
|
+
var _instance$options$ena;
|
|
2227
|
+
|
|
2228
|
+
if (typeof instance.options.enableRowSelection === 'function') {
|
|
2229
|
+
return instance.options.enableRowSelection(row);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
|
|
2233
|
+
},
|
|
2234
|
+
getCanSelectSubRows: () => {
|
|
2235
|
+
var _instance$options$ena2;
|
|
2236
|
+
|
|
2237
|
+
if (typeof instance.options.enableSubRowSelection === 'function') {
|
|
2238
|
+
return instance.options.enableSubRowSelection(row);
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
|
|
2242
|
+
},
|
|
2243
|
+
getCanMultiSelect: () => {
|
|
2244
|
+
var _instance$options$ena3;
|
|
2245
|
+
|
|
2246
|
+
if (typeof instance.options.enableMultiRowSelection === 'function') {
|
|
2247
|
+
return instance.options.enableMultiRowSelection(row);
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
|
|
2251
|
+
},
|
|
2252
|
+
getToggleSelectedHandler: () => {
|
|
2253
|
+
const canSelect = row.getCanSelect();
|
|
2254
|
+
return e => {
|
|
2255
|
+
var _target;
|
|
2256
|
+
|
|
2257
|
+
if (!canSelect) return;
|
|
2258
|
+
row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
|
|
2265
|
+
const mutateRowIsSelected = (selectedRowIds, id, value, instance) => {
|
|
2266
|
+
var _row$subRows;
|
|
2267
|
+
|
|
2268
|
+
const row = instance.getRow(id);
|
|
2269
|
+
row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
|
|
2270
|
+
// !isGrouped ||
|
|
2271
|
+
// (isGrouped && instance.options.enableGroupingRowSelection)
|
|
2272
|
+
// ) {
|
|
2273
|
+
|
|
2274
|
+
if (value) {
|
|
2275
|
+
selectedRowIds[id] = true;
|
|
2276
|
+
} else {
|
|
2277
|
+
delete selectedRowIds[id];
|
|
2278
|
+
} // }
|
|
2279
|
+
|
|
2280
|
+
|
|
2281
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
|
|
2282
|
+
row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, instance));
|
|
2283
|
+
}
|
|
2284
|
+
};
|
|
2285
|
+
|
|
2286
|
+
function selectRowsFn(instance, rowModel) {
|
|
2287
|
+
const rowSelection = instance.getState().rowSelection;
|
|
2288
|
+
const newSelectedFlatRows = [];
|
|
2289
|
+
const newSelectedRowsById = {}; // Filters top level and nested rows
|
|
2290
|
+
|
|
2291
|
+
const recurseRows = function (rows, depth) {
|
|
2292
|
+
if (depth === void 0) {
|
|
2293
|
+
depth = 0;
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
return rows.map(row => {
|
|
2297
|
+
var _row$subRows2;
|
|
2298
|
+
|
|
2299
|
+
const isSelected = isRowSelected(row, rowSelection) === true;
|
|
2300
|
+
|
|
2301
|
+
if (isSelected) {
|
|
2302
|
+
newSelectedFlatRows.push(row);
|
|
2303
|
+
newSelectedRowsById[row.id] = row;
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
|
|
2307
|
+
row = { ...row,
|
|
2308
|
+
subRows: recurseRows(row.subRows, depth + 1)
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
if (isSelected) {
|
|
2313
|
+
return row;
|
|
2314
|
+
}
|
|
2315
|
+
}).filter(Boolean);
|
|
2316
|
+
};
|
|
2317
|
+
|
|
2318
|
+
return {
|
|
2319
|
+
rows: recurseRows(rowModel.rows),
|
|
2320
|
+
flatRows: newSelectedFlatRows,
|
|
2321
|
+
rowsById: newSelectedRowsById
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
function isRowSelected(row, selection, instance) {
|
|
2325
|
+
if (selection[row.id]) {
|
|
2326
|
+
return true;
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
if (row.subRows && row.subRows.length) {
|
|
2330
|
+
let allChildrenSelected = true;
|
|
2331
|
+
let someSelected = false;
|
|
2332
|
+
row.subRows.forEach(subRow => {
|
|
2333
|
+
// Bail out early if we know both of these
|
|
2334
|
+
if (someSelected && !allChildrenSelected) {
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
if (isRowSelected(subRow, selection)) {
|
|
2339
|
+
someSelected = true;
|
|
2340
|
+
} else {
|
|
2341
|
+
allChildrenSelected = false;
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
return allChildrenSelected ? true : someSelected ? 'some' : false;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
return false;
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
const reSplitAlphaNumeric = /([0-9]+)/gm;
|
|
2351
|
+
|
|
2352
|
+
const alphanumeric = (rowA, rowB, columnId) => {
|
|
2353
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
|
|
2357
|
+
return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
2358
|
+
}; // The text filter is more basic (less numeric support)
|
|
2359
|
+
// but is much faster
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
const text = (rowA, rowB, columnId) => {
|
|
2363
|
+
return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
|
|
2364
|
+
}; // The text filter is more basic (less numeric support)
|
|
2365
|
+
// but is much faster
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
const textCaseSensitive = (rowA, rowB, columnId) => {
|
|
2369
|
+
return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
const datetime = (rowA, rowB, columnId) => {
|
|
2373
|
+
return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
|
|
2374
|
+
};
|
|
2375
|
+
|
|
2376
|
+
const basic = (rowA, rowB, columnId) => {
|
|
2377
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
|
|
2378
|
+
}; // Utils
|
|
2379
|
+
|
|
2380
|
+
|
|
2381
|
+
function compareBasic(a, b) {
|
|
2382
|
+
return a === b ? 0 : a > b ? 1 : -1;
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
function toString(a) {
|
|
2386
|
+
if (typeof a === 'number') {
|
|
2387
|
+
if (isNaN(a) || a === Infinity || a === -Infinity) {
|
|
2388
|
+
return '';
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
return String(a);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
if (typeof a === 'string') {
|
|
2395
|
+
return a;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
return '';
|
|
2399
|
+
} // Mixed sorting is slow, but very inclusive of many edge cases.
|
|
2400
|
+
// It handles numbers, mixed alphanumeric combinations, and even
|
|
2401
|
+
// null, undefined, and Infinity
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
function compareAlphanumeric(aStr, bStr) {
|
|
2405
|
+
// Split on number groups, but keep the delimiter
|
|
2406
|
+
// Then remove falsey split values
|
|
2407
|
+
const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
|
|
2408
|
+
const b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
|
|
2409
|
+
|
|
2410
|
+
while (a.length && b.length) {
|
|
2411
|
+
const aa = a.shift();
|
|
2412
|
+
const bb = b.shift();
|
|
2413
|
+
const an = parseInt(aa, 10);
|
|
2414
|
+
const bn = parseInt(bb, 10);
|
|
2415
|
+
const combo = [an, bn].sort(); // Both are string
|
|
2416
|
+
|
|
2417
|
+
if (isNaN(combo[0])) {
|
|
2418
|
+
if (aa > bb) {
|
|
2419
|
+
return 1;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
if (bb > aa) {
|
|
2423
|
+
return -1;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
continue;
|
|
2427
|
+
} // One is a string, one is a number
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
if (isNaN(combo[1])) {
|
|
2431
|
+
return isNaN(an) ? -1 : 1;
|
|
2432
|
+
} // Both are numbers
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
if (an > bn) {
|
|
2436
|
+
return 1;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
if (bn > an) {
|
|
2440
|
+
return -1;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
return a.length - b.length;
|
|
2445
|
+
} // Exports
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
const sortingFns = {
|
|
2449
|
+
alphanumeric,
|
|
2450
|
+
alphanumericCaseSensitive,
|
|
2451
|
+
text,
|
|
2452
|
+
textCaseSensitive,
|
|
2453
|
+
datetime,
|
|
2454
|
+
basic
|
|
2455
|
+
};
|
|
2456
|
+
|
|
2457
|
+
//
|
|
2458
|
+
const Sorting = {
|
|
2459
|
+
getInitialState: state => {
|
|
2460
|
+
return {
|
|
2461
|
+
sorting: [],
|
|
2462
|
+
...state
|
|
2463
|
+
};
|
|
2464
|
+
},
|
|
2465
|
+
getDefaultColumnDef: () => {
|
|
2466
|
+
return {
|
|
2467
|
+
sortingFn: 'auto'
|
|
2468
|
+
};
|
|
2469
|
+
},
|
|
2470
|
+
getDefaultOptions: instance => {
|
|
2471
|
+
return {
|
|
2472
|
+
onSortingChange: makeStateUpdater('sorting', instance),
|
|
2473
|
+
isMultiSortEvent: e => {
|
|
2474
|
+
return e.shiftKey;
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
},
|
|
2478
|
+
createColumn: (column, instance) => {
|
|
2479
|
+
return {
|
|
2480
|
+
getAutoSortingFn: () => {
|
|
2481
|
+
const firstRows = instance.getFilteredRowModel().flatRows.slice(10);
|
|
2482
|
+
let isString = false;
|
|
2483
|
+
|
|
2484
|
+
for (const row of firstRows) {
|
|
2485
|
+
const value = row == null ? void 0 : row.getValue(column.id);
|
|
2486
|
+
|
|
2487
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
2488
|
+
return sortingFns.datetime;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
if (typeof value === 'string') {
|
|
2492
|
+
isString = true;
|
|
2493
|
+
|
|
2494
|
+
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
2495
|
+
return sortingFns.alphanumeric;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
if (isString) {
|
|
2501
|
+
return sortingFns.text;
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
return sortingFns.basic;
|
|
2505
|
+
},
|
|
2506
|
+
getAutoSortDir: () => {
|
|
2507
|
+
const firstRow = instance.getFilteredRowModel().flatRows[0];
|
|
2508
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
2509
|
+
|
|
2510
|
+
if (typeof value === 'string') {
|
|
2511
|
+
return 'asc';
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
return 'desc';
|
|
2515
|
+
},
|
|
2516
|
+
getSortingFn: () => {
|
|
2517
|
+
var _ref;
|
|
2518
|
+
|
|
2519
|
+
const userSortingFn = instance.options.sortingFns;
|
|
2520
|
+
|
|
2521
|
+
if (!column) {
|
|
2522
|
+
throw new Error();
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
return isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn : column.columnDef.sortingFn === 'auto' ? column.getAutoSortingFn() : (_ref = userSortingFn == null ? void 0 : userSortingFn[column.columnDef.sortingFn]) != null ? _ref : sortingFns[column.columnDef.sortingFn];
|
|
2526
|
+
},
|
|
2527
|
+
toggleSorting: (desc, multi) => {
|
|
2528
|
+
// if (column.columns.length) {
|
|
2529
|
+
// column.columns.forEach((c, i) => {
|
|
2530
|
+
// if (c.id) {
|
|
2531
|
+
// instance.toggleColumnSorting(c.id, undefined, multi || !!i)
|
|
2532
|
+
// }
|
|
2533
|
+
// })
|
|
2534
|
+
// return
|
|
2535
|
+
// }
|
|
2536
|
+
instance.setSorting(old => {
|
|
2537
|
+
var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
|
|
2538
|
+
|
|
2539
|
+
// Find any existing sorting for this column
|
|
2540
|
+
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
2541
|
+
const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
|
|
2542
|
+
const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
|
|
2543
|
+
let newSorting = []; // What should we do with this sort action?
|
|
2544
|
+
|
|
2545
|
+
let sortAction;
|
|
2546
|
+
|
|
2547
|
+
if (column.getCanMultiSort() && multi) {
|
|
2548
|
+
if (existingSorting) {
|
|
2549
|
+
sortAction = 'toggle';
|
|
2550
|
+
} else {
|
|
2551
|
+
sortAction = 'add';
|
|
2552
|
+
}
|
|
2553
|
+
} else {
|
|
2554
|
+
// Normal mode
|
|
2555
|
+
if (old != null && old.length && existingIndex !== old.length - 1) {
|
|
2556
|
+
sortAction = 'replace';
|
|
2557
|
+
} else if (existingSorting) {
|
|
2558
|
+
sortAction = 'toggle';
|
|
2559
|
+
} else {
|
|
2560
|
+
sortAction = 'replace';
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
|
|
2565
|
+
|
|
2566
|
+
if (sortAction === 'toggle' && ( // Must be toggling
|
|
2567
|
+
(_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
|
|
2568
|
+
!hasDescDefined && ( // Must not be setting desc
|
|
2569
|
+
multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
|
|
2570
|
+
existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
|
|
2571
|
+
? !sortDescFirst : sortDescFirst)) {
|
|
2572
|
+
sortAction = 'remove';
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
if (sortAction === 'replace') {
|
|
2576
|
+
newSorting = [{
|
|
2577
|
+
id: column.id,
|
|
2578
|
+
desc: hasDescDefined ? desc : !!sortDescFirst
|
|
2579
|
+
}];
|
|
2580
|
+
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2581
|
+
var _instance$options$max;
|
|
2582
|
+
|
|
2583
|
+
newSorting = [...old, {
|
|
2584
|
+
id: column.id,
|
|
2585
|
+
desc: hasDescDefined ? desc : !!sortDescFirst
|
|
2586
|
+
}]; // Take latest n columns
|
|
2587
|
+
|
|
2588
|
+
newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
|
|
2589
|
+
} else if (sortAction === 'toggle' && old != null && old.length) {
|
|
2590
|
+
// This flips (or sets) the
|
|
2591
|
+
newSorting = old.map(d => {
|
|
2592
|
+
if (d.id === column.id) {
|
|
2593
|
+
return { ...d,
|
|
2594
|
+
desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
return d;
|
|
2599
|
+
});
|
|
2600
|
+
} else if (sortAction === 'remove' && old != null && old.length) {
|
|
2601
|
+
newSorting = old.filter(d => d.id !== column.id);
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
return newSorting;
|
|
2605
|
+
});
|
|
2606
|
+
},
|
|
2607
|
+
getCanSort: () => {
|
|
2608
|
+
var _column$columnDef$ena, _instance$options$ena3;
|
|
2609
|
+
|
|
2610
|
+
return ((_column$columnDef$ena = column.columnDef.enableSorting) != null ? _column$columnDef$ena : true) && ((_instance$options$ena3 = instance.options.enableSorting) != null ? _instance$options$ena3 : true) && !!column.accessorFn;
|
|
2611
|
+
},
|
|
2612
|
+
getCanMultiSort: () => {
|
|
2613
|
+
var _ref3, _column$columnDef$ena2;
|
|
2614
|
+
|
|
2615
|
+
return (_ref3 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : instance.options.enableMultiSort) != null ? _ref3 : !!column.accessorFn;
|
|
2616
|
+
},
|
|
2617
|
+
getIsSorted: () => {
|
|
2618
|
+
var _instance$getState$so;
|
|
2619
|
+
|
|
2620
|
+
const columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(d => d.id === column.id);
|
|
2621
|
+
return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
|
|
2622
|
+
},
|
|
2623
|
+
getSortIndex: () => {
|
|
2624
|
+
var _instance$getState$so2, _instance$getState$so3;
|
|
2625
|
+
|
|
2626
|
+
return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(d => d.id === column.id)) != null ? _instance$getState$so2 : -1;
|
|
2627
|
+
},
|
|
2628
|
+
clearSorting: () => {
|
|
2629
|
+
//clear sorting for just 1 column
|
|
2630
|
+
instance.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
|
|
2631
|
+
},
|
|
2632
|
+
getToggleSortingHandler: () => {
|
|
2633
|
+
const canSort = column.getCanSort();
|
|
2634
|
+
return e => {
|
|
2635
|
+
if (!canSort) return;
|
|
2636
|
+
e.persist == null ? void 0 : e.persist();
|
|
2637
|
+
column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
},
|
|
2642
|
+
createInstance: instance => {
|
|
2643
|
+
return {
|
|
2644
|
+
setSorting: updater => instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater),
|
|
2645
|
+
resetSorting: defaultState => {
|
|
2646
|
+
var _instance$initialStat, _instance$initialStat2;
|
|
2647
|
+
|
|
2648
|
+
instance.setSorting(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
|
|
2649
|
+
},
|
|
2650
|
+
getPreSortedRowModel: () => instance.getFilteredRowModel(),
|
|
2651
|
+
getSortedRowModel: () => {
|
|
2652
|
+
if (!instance._getSortedRowModel && instance.options.getSortedRowModel) {
|
|
2653
|
+
instance._getSortedRowModel = instance.options.getSortedRowModel(instance);
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
if (instance.options.manualSorting || !instance._getSortedRowModel) {
|
|
2657
|
+
return instance.getPreSortedRowModel();
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
return instance._getSortedRowModel();
|
|
2661
|
+
}
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
};
|
|
2665
|
+
|
|
2666
|
+
//
|
|
2667
|
+
const Visibility = {
|
|
2668
|
+
getInitialState: state => {
|
|
2669
|
+
return {
|
|
2670
|
+
columnVisibility: {},
|
|
2671
|
+
...state
|
|
2672
|
+
};
|
|
2673
|
+
},
|
|
2674
|
+
getDefaultOptions: instance => {
|
|
2675
|
+
return {
|
|
2676
|
+
onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
|
|
2677
|
+
};
|
|
2678
|
+
},
|
|
2679
|
+
createColumn: (column, instance) => {
|
|
2680
|
+
return {
|
|
2681
|
+
toggleVisibility: value => {
|
|
2682
|
+
if (column.getCanHide()) {
|
|
2683
|
+
instance.setColumnVisibility(old => ({ ...old,
|
|
2684
|
+
[column.id]: value != null ? value : !column.getIsVisible()
|
|
2685
|
+
}));
|
|
2686
|
+
}
|
|
2687
|
+
},
|
|
2688
|
+
getIsVisible: () => {
|
|
2689
|
+
var _instance$getState$co, _instance$getState$co2;
|
|
2690
|
+
|
|
2691
|
+
return (_instance$getState$co = (_instance$getState$co2 = instance.getState().columnVisibility) == null ? void 0 : _instance$getState$co2[column.id]) != null ? _instance$getState$co : true;
|
|
2692
|
+
},
|
|
2693
|
+
getCanHide: () => {
|
|
2694
|
+
var _column$columnDef$ena, _instance$options$ena;
|
|
2695
|
+
|
|
2696
|
+
return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_instance$options$ena = instance.options.enableHiding) != null ? _instance$options$ena : true);
|
|
2697
|
+
},
|
|
2698
|
+
getToggleVisibilityHandler: () => {
|
|
2699
|
+
return e => {
|
|
2700
|
+
column.toggleVisibility == null ? void 0 : column.toggleVisibility(e.target.checked);
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
},
|
|
2705
|
+
createRow: (row, instance) => {
|
|
2706
|
+
return {
|
|
2707
|
+
_getAllVisibleCells: memo(() => [row.getAllCells(), instance.getState().columnVisibility], cells => {
|
|
2708
|
+
return cells.filter(cell => cell.column.getIsVisible());
|
|
2709
|
+
}, {
|
|
2710
|
+
key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
|
|
2711
|
+
debug: () => {
|
|
2712
|
+
var _instance$options$deb;
|
|
2713
|
+
|
|
2714
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
|
|
2715
|
+
}
|
|
2716
|
+
}),
|
|
2717
|
+
getVisibleCells: memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], {
|
|
2718
|
+
key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
|
|
2719
|
+
debug: () => {
|
|
2720
|
+
var _instance$options$deb2;
|
|
2721
|
+
|
|
2722
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
|
|
2723
|
+
}
|
|
2724
|
+
})
|
|
2725
|
+
};
|
|
2726
|
+
},
|
|
2727
|
+
createInstance: instance => {
|
|
2728
|
+
const makeVisibleColumnsMethod = (key, getColumns) => {
|
|
2729
|
+
return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
|
|
2730
|
+
return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
|
|
2731
|
+
}, {
|
|
2732
|
+
key,
|
|
2733
|
+
debug: () => {
|
|
2734
|
+
var _instance$options$deb3;
|
|
2735
|
+
|
|
2736
|
+
return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
|
|
2737
|
+
}
|
|
2738
|
+
});
|
|
2739
|
+
};
|
|
2740
|
+
|
|
2741
|
+
return {
|
|
2742
|
+
getVisibleFlatColumns: makeVisibleColumnsMethod('getVisibleFlatColumns', () => instance.getAllFlatColumns()),
|
|
2743
|
+
getVisibleLeafColumns: makeVisibleColumnsMethod('getVisibleLeafColumns', () => instance.getAllLeafColumns()),
|
|
2744
|
+
getLeftVisibleLeafColumns: makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => instance.getLeftLeafColumns()),
|
|
2745
|
+
getRightVisibleLeafColumns: makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => instance.getRightLeafColumns()),
|
|
2746
|
+
getCenterVisibleLeafColumns: makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => instance.getCenterLeafColumns()),
|
|
2747
|
+
setColumnVisibility: updater => instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater),
|
|
2748
|
+
resetColumnVisibility: defaultState => {
|
|
2749
|
+
var _instance$initialStat;
|
|
2750
|
+
|
|
2751
|
+
instance.setColumnVisibility(defaultState ? {} : (_instance$initialStat = instance.initialState.columnVisibility) != null ? _instance$initialStat : {});
|
|
2752
|
+
},
|
|
2753
|
+
toggleAllColumnsVisible: value => {
|
|
2754
|
+
var _value;
|
|
2755
|
+
|
|
2756
|
+
value = (_value = value) != null ? _value : !instance.getIsAllColumnsVisible();
|
|
2757
|
+
instance.setColumnVisibility(instance.getAllLeafColumns().reduce((obj, column) => ({ ...obj,
|
|
2758
|
+
[column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
|
|
2759
|
+
}), {}));
|
|
2760
|
+
},
|
|
2761
|
+
getIsAllColumnsVisible: () => !instance.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible())),
|
|
2762
|
+
getIsSomeColumnsVisible: () => instance.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible()),
|
|
2763
|
+
getToggleAllColumnsVisibilityHandler: () => {
|
|
2764
|
+
return e => {
|
|
2765
|
+
var _target;
|
|
2766
|
+
|
|
2767
|
+
instance.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
};
|
|
2773
|
+
|
|
2774
|
+
const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing]; //
|
|
2775
|
+
|
|
2776
|
+
function createTableInstance(options) {
|
|
2777
|
+
var _options$initialState;
|
|
2778
|
+
|
|
2779
|
+
if (options.debugAll || options.debugTable) {
|
|
2780
|
+
console.info('Creating Table Instance...');
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
let instance = {
|
|
2784
|
+
_features: features
|
|
2785
|
+
};
|
|
2786
|
+
|
|
2787
|
+
const defaultOptions = instance._features.reduce((obj, feature) => {
|
|
2788
|
+
return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
|
|
2789
|
+
}, {});
|
|
2790
|
+
|
|
2791
|
+
const mergeOptions = options => {
|
|
2792
|
+
if (instance.options.mergeOptions) {
|
|
2793
|
+
return instance.options.mergeOptions(defaultOptions, options);
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
return { ...defaultOptions,
|
|
2797
|
+
...options
|
|
2798
|
+
};
|
|
2799
|
+
};
|
|
2800
|
+
|
|
2801
|
+
const coreInitialState = {};
|
|
2802
|
+
let initialState = { ...coreInitialState,
|
|
2803
|
+
...((_options$initialState = options.initialState) != null ? _options$initialState : {})
|
|
2804
|
+
};
|
|
2805
|
+
|
|
2806
|
+
instance._features.forEach(feature => {
|
|
2807
|
+
var _feature$getInitialSt;
|
|
2808
|
+
|
|
2809
|
+
initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
|
|
2810
|
+
});
|
|
2811
|
+
|
|
2812
|
+
const queued = [];
|
|
2813
|
+
let queuedTimeout = false;
|
|
2814
|
+
const coreInstance = {
|
|
2815
|
+
_features: features,
|
|
2816
|
+
options: { ...defaultOptions,
|
|
2817
|
+
...options
|
|
2818
|
+
},
|
|
2819
|
+
initialState,
|
|
2820
|
+
_queue: cb => {
|
|
2821
|
+
queued.push(cb);
|
|
2822
|
+
|
|
2823
|
+
if (!queuedTimeout) {
|
|
2824
|
+
queuedTimeout = true; // Schedule a microtask to run the queued callbacks after
|
|
2825
|
+
// the current call stack (render, etc) has finished.
|
|
2826
|
+
|
|
2827
|
+
Promise.resolve().then(() => {
|
|
2828
|
+
while (queued.length) {
|
|
2829
|
+
queued.shift()();
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
queuedTimeout = false;
|
|
2833
|
+
}).catch(error => setTimeout(() => {
|
|
2834
|
+
throw error;
|
|
2835
|
+
}));
|
|
2836
|
+
}
|
|
2837
|
+
},
|
|
2838
|
+
reset: () => {
|
|
2839
|
+
instance.setState(instance.initialState);
|
|
2840
|
+
},
|
|
2841
|
+
setOptions: updater => {
|
|
2842
|
+
const newOptions = functionalUpdate(updater, instance.options);
|
|
2843
|
+
instance.options = mergeOptions(newOptions);
|
|
2844
|
+
},
|
|
2845
|
+
_render: (template, props) => {
|
|
2846
|
+
if (typeof instance.options.render === 'function') {
|
|
2847
|
+
return instance.options.render(template, props);
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
if (typeof template === 'function') {
|
|
2851
|
+
return template(props);
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
return template;
|
|
2855
|
+
},
|
|
2856
|
+
getState: () => {
|
|
2857
|
+
return instance.options.state;
|
|
2858
|
+
},
|
|
2859
|
+
setState: updater => {
|
|
2860
|
+
instance.options.onStateChange == null ? void 0 : instance.options.onStateChange(updater);
|
|
2861
|
+
},
|
|
2862
|
+
_getRowId: (row, index, parent) => {
|
|
2863
|
+
var _instance$options$get;
|
|
2864
|
+
|
|
2865
|
+
return (_instance$options$get = instance.options.getRowId == null ? void 0 : instance.options.getRowId(row, index, parent)) != null ? _instance$options$get : "" + (parent ? [parent.id, index].join('.') : index);
|
|
2866
|
+
},
|
|
2867
|
+
getCoreRowModel: () => {
|
|
2868
|
+
if (!instance._getCoreRowModel) {
|
|
2869
|
+
instance._getCoreRowModel = instance.options.getCoreRowModel(instance);
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
return instance._getCoreRowModel();
|
|
2873
|
+
},
|
|
2874
|
+
// The final calls start at the bottom of the model,
|
|
2875
|
+
// expanded rows, which then work their way up
|
|
2876
|
+
getRowModel: () => {
|
|
2877
|
+
return instance.getPaginationRowModel();
|
|
2878
|
+
},
|
|
2879
|
+
getRow: id => {
|
|
2880
|
+
const row = instance.getRowModel().rowsById[id];
|
|
2881
|
+
|
|
2882
|
+
if (!row) {
|
|
2883
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2884
|
+
throw new Error("getRow expected an ID, but got " + id);
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
throw new Error();
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
return row;
|
|
2891
|
+
},
|
|
2892
|
+
_getDefaultColumnDef: memo(() => [instance.options.defaultColumn], defaultColumn => {
|
|
2893
|
+
var _defaultColumn;
|
|
2894
|
+
|
|
2895
|
+
defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
|
|
2896
|
+
return {
|
|
2897
|
+
header: props => props.header.column.id,
|
|
2898
|
+
footer: props => props.header.column.id,
|
|
2899
|
+
cell: props => {
|
|
2900
|
+
var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
|
|
2901
|
+
|
|
2902
|
+
return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
|
|
2903
|
+
},
|
|
2904
|
+
...instance._features.reduce((obj, feature) => {
|
|
2905
|
+
return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
|
|
2906
|
+
}, {}),
|
|
2907
|
+
...defaultColumn
|
|
2908
|
+
};
|
|
2909
|
+
}, {
|
|
2910
|
+
debug: () => {
|
|
2911
|
+
var _instance$options$deb;
|
|
2912
|
+
|
|
2913
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugColumns;
|
|
2914
|
+
},
|
|
2915
|
+
key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef'
|
|
2916
|
+
}),
|
|
2917
|
+
_getColumnDefs: () => instance.options.columns,
|
|
2918
|
+
getAllColumns: memo(() => [instance._getColumnDefs()], columnDefs => {
|
|
2919
|
+
const recurseColumns = function (columnDefs, parent, depth) {
|
|
2920
|
+
if (depth === void 0) {
|
|
2921
|
+
depth = 0;
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
return columnDefs.map(columnDef => {
|
|
2925
|
+
const column = createColumn(instance, columnDef, depth, parent);
|
|
2926
|
+
column.columns = columnDef.columns ? recurseColumns(columnDef.columns, column, depth + 1) : [];
|
|
2927
|
+
return column;
|
|
2928
|
+
});
|
|
2929
|
+
};
|
|
2930
|
+
|
|
2931
|
+
return recurseColumns(columnDefs);
|
|
2932
|
+
}, {
|
|
2933
|
+
key: process.env.NODE_ENV === 'development' && 'getAllColumns',
|
|
2934
|
+
debug: () => {
|
|
2935
|
+
var _instance$options$deb2;
|
|
2936
|
+
|
|
2937
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugColumns;
|
|
2938
|
+
}
|
|
2939
|
+
}),
|
|
2940
|
+
getAllFlatColumns: memo(() => [instance.getAllColumns()], allColumns => {
|
|
2941
|
+
return allColumns.flatMap(column => {
|
|
2942
|
+
return column.getFlatColumns();
|
|
2943
|
+
});
|
|
2944
|
+
}, {
|
|
2945
|
+
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
|
|
2946
|
+
debug: () => {
|
|
2947
|
+
var _instance$options$deb3;
|
|
2948
|
+
|
|
2949
|
+
return (_instance$options$deb3 = instance.options.debugAll) != null ? _instance$options$deb3 : instance.options.debugColumns;
|
|
2950
|
+
}
|
|
2951
|
+
}),
|
|
2952
|
+
_getAllFlatColumnsById: memo(() => [instance.getAllFlatColumns()], flatColumns => {
|
|
2953
|
+
return flatColumns.reduce((acc, column) => {
|
|
2954
|
+
acc[column.id] = column;
|
|
2955
|
+
return acc;
|
|
2956
|
+
}, {});
|
|
2957
|
+
}, {
|
|
2958
|
+
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
|
|
2959
|
+
debug: () => {
|
|
2960
|
+
var _instance$options$deb4;
|
|
2961
|
+
|
|
2962
|
+
return (_instance$options$deb4 = instance.options.debugAll) != null ? _instance$options$deb4 : instance.options.debugColumns;
|
|
2963
|
+
}
|
|
2964
|
+
}),
|
|
2965
|
+
getAllLeafColumns: memo(() => [instance.getAllColumns(), instance._getOrderColumnsFn()], (allColumns, orderColumns) => {
|
|
2966
|
+
let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
|
|
2967
|
+
return orderColumns(leafColumns);
|
|
2968
|
+
}, {
|
|
2969
|
+
key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
|
|
2970
|
+
debug: () => {
|
|
2971
|
+
var _instance$options$deb5;
|
|
2972
|
+
|
|
2973
|
+
return (_instance$options$deb5 = instance.options.debugAll) != null ? _instance$options$deb5 : instance.options.debugColumns;
|
|
2974
|
+
}
|
|
2975
|
+
}),
|
|
2976
|
+
getColumn: columnId => {
|
|
2977
|
+
const column = instance._getAllFlatColumnsById()[columnId];
|
|
2978
|
+
|
|
2979
|
+
if (!column) {
|
|
2980
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2981
|
+
console.warn("[Table] Column with id " + columnId + " does not exist.");
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
throw new Error();
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
return column;
|
|
2988
|
+
}
|
|
2989
|
+
};
|
|
2990
|
+
Object.assign(instance, coreInstance);
|
|
2991
|
+
|
|
2992
|
+
instance._features.forEach(feature => {
|
|
2993
|
+
return Object.assign(instance, feature.createInstance == null ? void 0 : feature.createInstance(instance));
|
|
2994
|
+
});
|
|
2995
|
+
|
|
2996
|
+
return instance;
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
//
|
|
3000
|
+
function createTableFactory(opts) {
|
|
3001
|
+
return () => createTable(undefined, undefined, opts);
|
|
3002
|
+
} // A lot of returns in here are `as any` for a reason. Unless you
|
|
3003
|
+
// can find a better way to do this, then don't worry about them
|
|
3004
|
+
|
|
3005
|
+
function createTable(_, __, options) {
|
|
3006
|
+
const table = {
|
|
3007
|
+
generics: undefined,
|
|
3008
|
+
options: options != null ? options : {
|
|
3009
|
+
render: (() => {
|
|
3010
|
+
throw new Error('');
|
|
3011
|
+
})()
|
|
3012
|
+
},
|
|
3013
|
+
// setGenerics: () => table as any,
|
|
3014
|
+
setRowType: () => table,
|
|
3015
|
+
setTableMetaType: () => table,
|
|
3016
|
+
setColumnMetaType: () => table,
|
|
3017
|
+
setFilterMetaType: () => table,
|
|
3018
|
+
setOptions: newOptions => createTable(_, __, { ...options,
|
|
3019
|
+
...newOptions
|
|
3020
|
+
}),
|
|
3021
|
+
createDisplayColumn: column => ({ ...column,
|
|
3022
|
+
columnDefType: 'display'
|
|
3023
|
+
}),
|
|
3024
|
+
createGroup: column => ({ ...column,
|
|
3025
|
+
columnDefType: 'group'
|
|
3026
|
+
}),
|
|
3027
|
+
createDataColumn: (accessor, column) => {
|
|
3028
|
+
column = { ...column,
|
|
3029
|
+
columnDefType: 'data',
|
|
3030
|
+
id: column.id
|
|
3031
|
+
};
|
|
3032
|
+
|
|
3033
|
+
if (typeof accessor === 'string') {
|
|
3034
|
+
var _column$id;
|
|
3035
|
+
|
|
3036
|
+
return { ...column,
|
|
3037
|
+
id: (_column$id = column.id) != null ? _column$id : accessor,
|
|
3038
|
+
accessorKey: accessor
|
|
3039
|
+
};
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
if (typeof accessor === 'function') {
|
|
3043
|
+
return { ...column,
|
|
3044
|
+
accessorFn: accessor
|
|
3045
|
+
};
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3048
|
+
throw new Error('Invalid accessor');
|
|
3049
|
+
},
|
|
3050
|
+
createOptions: options => options
|
|
3051
|
+
};
|
|
3052
|
+
return table;
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
function createCell(instance, row, column, columnId) {
|
|
3056
|
+
const cell = {
|
|
3057
|
+
id: row.id + "_" + column.id,
|
|
3058
|
+
row,
|
|
3059
|
+
column,
|
|
3060
|
+
getValue: () => row.getValue(columnId),
|
|
3061
|
+
renderCell: () => {
|
|
3062
|
+
return column.columnDef.cell ? instance._render(column.columnDef.cell, {
|
|
3063
|
+
instance,
|
|
3064
|
+
column,
|
|
3065
|
+
row,
|
|
3066
|
+
cell: cell,
|
|
3067
|
+
getValue: cell.getValue
|
|
3068
|
+
}) : null;
|
|
3069
|
+
}
|
|
3070
|
+
};
|
|
3071
|
+
|
|
3072
|
+
instance._features.forEach(feature => {
|
|
3073
|
+
Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
|
|
3074
|
+
}, {});
|
|
3075
|
+
|
|
3076
|
+
return cell;
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
const createRow = (instance, id, original, rowIndex, depth, subRows) => {
|
|
3080
|
+
let row = {
|
|
3081
|
+
id,
|
|
3082
|
+
index: rowIndex,
|
|
3083
|
+
original,
|
|
3084
|
+
depth,
|
|
3085
|
+
_valuesCache: {},
|
|
3086
|
+
getValue: columnId => {
|
|
3087
|
+
if (row._valuesCache.hasOwnProperty(columnId)) {
|
|
3088
|
+
return row._valuesCache[columnId];
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
const column = instance.getColumn(columnId);
|
|
3092
|
+
|
|
3093
|
+
if (!column.accessorFn) {
|
|
3094
|
+
return undefined;
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
|
|
3098
|
+
return row._valuesCache[columnId];
|
|
3099
|
+
},
|
|
3100
|
+
subRows: subRows != null ? subRows : [],
|
|
3101
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
3102
|
+
getAllCells: memo(() => [instance.getAllLeafColumns()], leafColumns => {
|
|
3103
|
+
return leafColumns.map(column => {
|
|
3104
|
+
return createCell(instance, row, column, column.id);
|
|
3105
|
+
});
|
|
3106
|
+
}, {
|
|
3107
|
+
key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
|
|
3108
|
+
debug: () => {
|
|
3109
|
+
var _instance$options$deb;
|
|
3110
|
+
|
|
3111
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugRows;
|
|
3112
|
+
}
|
|
3113
|
+
}),
|
|
3114
|
+
_getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
|
|
3115
|
+
return allCells.reduce((acc, cell) => {
|
|
3116
|
+
acc[cell.column.id] = cell;
|
|
3117
|
+
return acc;
|
|
3118
|
+
}, {});
|
|
3119
|
+
}, {
|
|
3120
|
+
key: process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
|
|
3121
|
+
debug: () => {
|
|
3122
|
+
var _instance$options$deb2;
|
|
3123
|
+
|
|
3124
|
+
return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugRows;
|
|
3125
|
+
}
|
|
3126
|
+
})
|
|
3127
|
+
};
|
|
3128
|
+
|
|
3129
|
+
for (let i = 0; i < instance._features.length; i++) {
|
|
3130
|
+
const feature = instance._features[i];
|
|
3131
|
+
Object.assign(row, feature == null ? void 0 : feature.createRow == null ? void 0 : feature.createRow(row, instance));
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
return row;
|
|
3135
|
+
};
|
|
3136
|
+
|
|
3137
|
+
function getCoreRowModel() {
|
|
3138
|
+
return instance => memo(() => [instance.options.data], data => {
|
|
3139
|
+
const rowModel = {
|
|
3140
|
+
rows: [],
|
|
3141
|
+
flatRows: [],
|
|
3142
|
+
rowsById: {}
|
|
3143
|
+
};
|
|
3144
|
+
|
|
3145
|
+
const accessRows = function (originalRows, depth, parent) {
|
|
3146
|
+
if (depth === void 0) {
|
|
3147
|
+
depth = 0;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
const rows = [];
|
|
3151
|
+
|
|
3152
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
3153
|
+
// This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
3154
|
+
// if (!id) {
|
|
3155
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
3156
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
3157
|
+
// }
|
|
3158
|
+
// }
|
|
3159
|
+
// Make the row
|
|
3160
|
+
const row = createRow(instance, instance._getRowId(originalRows[i], i, parent), originalRows[i], i, depth); // Keep track of every row in a flat array
|
|
3161
|
+
|
|
3162
|
+
rowModel.flatRows.push(row); // Also keep track of every row by its ID
|
|
3163
|
+
|
|
3164
|
+
rowModel.rowsById[row.id] = row; // Push instance row into parent
|
|
3165
|
+
|
|
3166
|
+
rows.push(row); // Get the original subrows
|
|
3167
|
+
|
|
3168
|
+
if (instance.options.getSubRows) {
|
|
3169
|
+
var _row$originalSubRows;
|
|
3170
|
+
|
|
3171
|
+
row.originalSubRows = instance.options.getSubRows(originalRows[i], i); // Then recursively access them
|
|
3172
|
+
|
|
3173
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
3174
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
return rows;
|
|
3180
|
+
};
|
|
3181
|
+
|
|
3182
|
+
rowModel.rows = accessRows(data);
|
|
3183
|
+
return rowModel;
|
|
3184
|
+
}, {
|
|
3185
|
+
key: process.env.NODE_ENV === 'development' && 'getRowModel',
|
|
3186
|
+
debug: () => {
|
|
3187
|
+
var _instance$options$deb;
|
|
3188
|
+
|
|
3189
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3190
|
+
},
|
|
3191
|
+
onChange: () => {
|
|
3192
|
+
instance._autoResetPageIndex();
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
function filterRows(rows, filterRowImpl, instance) {
|
|
3198
|
+
if (instance.options.filterFromLeafRows) {
|
|
3199
|
+
return filterRowModelFromLeafs(rows, filterRowImpl, instance);
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
return filterRowModelFromRoot(rows, filterRowImpl, instance);
|
|
3203
|
+
}
|
|
3204
|
+
function filterRowModelFromLeafs(rowsToFilter, filterRow, instance) {
|
|
3205
|
+
const newFilteredFlatRows = [];
|
|
3206
|
+
const newFilteredRowsById = {};
|
|
3207
|
+
let row;
|
|
3208
|
+
let newRow;
|
|
3209
|
+
|
|
3210
|
+
const recurseFilterRows = function (rowsToFilter, depth) {
|
|
3211
|
+
if (depth === void 0) {
|
|
3212
|
+
depth = 0;
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3215
|
+
const rows = []; // Filter from children up first
|
|
3216
|
+
|
|
3217
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
3218
|
+
var _row$subRows;
|
|
3219
|
+
|
|
3220
|
+
row = rowsToFilter[i];
|
|
3221
|
+
|
|
3222
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
|
|
3223
|
+
newRow = createRow(instance, row.id, row.original, row.index, row.depth);
|
|
3224
|
+
newRow.columnFilters = row.columnFilters;
|
|
3225
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
|
|
3226
|
+
|
|
3227
|
+
if (!newRow.subRows.length) {
|
|
3228
|
+
continue;
|
|
3229
|
+
}
|
|
3230
|
+
|
|
3231
|
+
row = newRow;
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
if (filterRow(row)) {
|
|
3235
|
+
rows.push(row);
|
|
3236
|
+
newFilteredRowsById[row.id] = row;
|
|
3237
|
+
newFilteredRowsById[i] = row;
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
|
|
3241
|
+
return rows;
|
|
3242
|
+
};
|
|
3243
|
+
|
|
3244
|
+
return {
|
|
3245
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
3246
|
+
flatRows: newFilteredFlatRows,
|
|
3247
|
+
rowsById: newFilteredRowsById
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
function filterRowModelFromRoot(rowsToFilter, filterRow, instance) {
|
|
3251
|
+
const newFilteredFlatRows = [];
|
|
3252
|
+
const newFilteredRowsById = {};
|
|
3253
|
+
let rows;
|
|
3254
|
+
let row;
|
|
3255
|
+
let newRow; // Filters top level and nested rows
|
|
3256
|
+
|
|
3257
|
+
const recurseFilterRows = function (rowsToFilter, depth) {
|
|
3258
|
+
if (depth === void 0) {
|
|
3259
|
+
depth = 0;
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
// Filter from parents downward first
|
|
3263
|
+
rows = []; // Apply the filter to any subRows
|
|
3264
|
+
|
|
3265
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
3266
|
+
row = rowsToFilter[i];
|
|
3267
|
+
const pass = filterRow(row);
|
|
3268
|
+
|
|
3269
|
+
if (pass) {
|
|
3270
|
+
var _row$subRows2;
|
|
3271
|
+
|
|
3272
|
+
if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
|
|
3273
|
+
newRow = createRow(instance, row.id, row.original, row.index, row.depth);
|
|
3274
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
|
|
3275
|
+
row = newRow;
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
rows.push(row);
|
|
3279
|
+
newFilteredFlatRows.push(row);
|
|
3280
|
+
newFilteredRowsById[row.id] = row;
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
return rows;
|
|
3285
|
+
};
|
|
3286
|
+
|
|
3287
|
+
return {
|
|
3288
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
3289
|
+
flatRows: newFilteredFlatRows,
|
|
3290
|
+
rowsById: newFilteredRowsById
|
|
3291
|
+
};
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
function getFilteredRowModel() {
|
|
3295
|
+
return instance => memo(() => [instance.getPreFilteredRowModel(), instance.getState().columnFilters, instance.getState().globalFilter], (rowModel, columnFilters, globalFilter) => {
|
|
3296
|
+
if (!rowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
|
|
3297
|
+
for (let i = 0; i < rowModel.flatRows.length; i++) {
|
|
3298
|
+
rowModel.flatRows[i].columnFilters = {};
|
|
3299
|
+
rowModel.flatRows[i].columnFiltersMeta = {};
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
return rowModel;
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3305
|
+
const resolvedColumnFilters = [];
|
|
3306
|
+
const resolvedGlobalFilters = [];
|
|
3307
|
+
(columnFilters != null ? columnFilters : []).forEach(d => {
|
|
3308
|
+
var _filterFn$resolveFilt;
|
|
3309
|
+
|
|
3310
|
+
const column = instance.getColumn(d.id);
|
|
3311
|
+
|
|
3312
|
+
if (!column) {
|
|
3313
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3314
|
+
console.warn("Table: Could not find a column to filter with columnId: " + d.id);
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
const filterFn = column.getFilterFn();
|
|
3319
|
+
|
|
3320
|
+
if (!filterFn) {
|
|
3321
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3322
|
+
console.warn("Could not find a valid 'column.filterFn' for column with the ID: " + column.id + ".");
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
return;
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
resolvedColumnFilters.push({
|
|
3329
|
+
id: d.id,
|
|
3330
|
+
filterFn,
|
|
3331
|
+
resolvedValue: (_filterFn$resolveFilt = filterFn.resolveFilterValue == null ? void 0 : filterFn.resolveFilterValue(d.value)) != null ? _filterFn$resolveFilt : d.value
|
|
3332
|
+
});
|
|
3333
|
+
});
|
|
3334
|
+
const filterableIds = columnFilters.map(d => d.id);
|
|
3335
|
+
const globalFilterFn = instance.getGlobalFilterFn();
|
|
3336
|
+
const globallyFilterableColumns = instance.getAllLeafColumns().filter(column => column.getCanGlobalFilter());
|
|
3337
|
+
|
|
3338
|
+
if (globalFilter && globalFilterFn && globallyFilterableColumns.length) {
|
|
3339
|
+
filterableIds.push('__global__');
|
|
3340
|
+
globallyFilterableColumns.forEach(column => {
|
|
3341
|
+
var _globalFilterFn$resol;
|
|
3342
|
+
|
|
3343
|
+
resolvedGlobalFilters.push({
|
|
3344
|
+
id: column.id,
|
|
3345
|
+
filterFn: globalFilterFn,
|
|
3346
|
+
resolvedValue: (_globalFilterFn$resol = globalFilterFn.resolveFilterValue == null ? void 0 : globalFilterFn.resolveFilterValue(globalFilter)) != null ? _globalFilterFn$resol : globalFilter
|
|
3347
|
+
});
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
let currentColumnFilter;
|
|
3352
|
+
let currentGlobalFilter; // Flag the prefiltered row model with each filter state
|
|
3353
|
+
|
|
3354
|
+
for (let j = 0; j < rowModel.flatRows.length; j++) {
|
|
3355
|
+
const row = rowModel.flatRows[j];
|
|
3356
|
+
row.columnFilters = {};
|
|
3357
|
+
|
|
3358
|
+
if (resolvedColumnFilters.length) {
|
|
3359
|
+
for (let i = 0; i < resolvedColumnFilters.length; i++) {
|
|
3360
|
+
currentColumnFilter = resolvedColumnFilters[i];
|
|
3361
|
+
const id = currentColumnFilter.id; // Tag the row with the column filter state
|
|
3362
|
+
|
|
3363
|
+
row.columnFilters[id] = currentColumnFilter.filterFn(row, id, currentColumnFilter.resolvedValue, filterMeta => {
|
|
3364
|
+
row.columnFiltersMeta[id] = filterMeta;
|
|
3365
|
+
});
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
if (resolvedGlobalFilters.length) {
|
|
3370
|
+
for (let i = 0; i < resolvedGlobalFilters.length; i++) {
|
|
3371
|
+
currentGlobalFilter = resolvedGlobalFilters[i];
|
|
3372
|
+
const id = currentGlobalFilter.id; // Tag the row with the first truthy global filter state
|
|
3373
|
+
|
|
3374
|
+
if (currentGlobalFilter.filterFn(row, id, currentGlobalFilter.resolvedValue, filterMeta => {
|
|
3375
|
+
row.columnFiltersMeta[id] = filterMeta;
|
|
3376
|
+
})) {
|
|
3377
|
+
row.columnFilters.__global__ = true;
|
|
3378
|
+
break;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
if (row.columnFilters.__global__ !== true) {
|
|
3383
|
+
row.columnFilters.__global__ = false;
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
const filterRowsImpl = row => {
|
|
3389
|
+
// Horizontally filter rows through each column
|
|
3390
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
3391
|
+
if (row.columnFilters[filterableIds[i]] === false) {
|
|
3392
|
+
return false;
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
return true;
|
|
3397
|
+
}; // Filter final rows using all of the active filters
|
|
3398
|
+
|
|
3399
|
+
|
|
3400
|
+
return filterRows(rowModel.rows, filterRowsImpl, instance);
|
|
3401
|
+
}, {
|
|
3402
|
+
key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
|
|
3403
|
+
debug: () => {
|
|
3404
|
+
var _instance$options$deb;
|
|
3405
|
+
|
|
3406
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3407
|
+
},
|
|
3408
|
+
onChange: () => {
|
|
3409
|
+
instance._autoResetPageIndex();
|
|
3410
|
+
}
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
function getFacetedRowModel() {
|
|
3415
|
+
return (instance, columnId) => memo(() => [instance.getPreFilteredRowModel(), instance.getState().columnFilters, instance.getState().globalFilter, instance.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
|
|
3416
|
+
if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
|
|
3417
|
+
return preRowModel;
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3420
|
+
const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
|
|
3421
|
+
|
|
3422
|
+
const filterRowsImpl = row => {
|
|
3423
|
+
// Horizontally filter rows through each column
|
|
3424
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
3425
|
+
if (row.columnFilters[filterableIds[i]] === false) {
|
|
3426
|
+
return false;
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
return true;
|
|
3431
|
+
};
|
|
3432
|
+
|
|
3433
|
+
return filterRows(preRowModel.rows, filterRowsImpl, instance);
|
|
3434
|
+
}, {
|
|
3435
|
+
key: process.env.NODE_ENV === 'development' && 'getFacetedRowModel_' + columnId,
|
|
3436
|
+
debug: () => {
|
|
3437
|
+
var _instance$options$deb;
|
|
3438
|
+
|
|
3439
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3440
|
+
},
|
|
3441
|
+
onChange: () => {}
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
function getFacetedUniqueValues() {
|
|
3446
|
+
return (instance, columnId) => memo(() => [instance.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
|
|
3447
|
+
let facetedUniqueValues = new Map();
|
|
3448
|
+
|
|
3449
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
3450
|
+
var _facetedRowModel$flat;
|
|
3451
|
+
|
|
3452
|
+
const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
|
|
3453
|
+
|
|
3454
|
+
if (facetedUniqueValues.has(value)) {
|
|
3455
|
+
var _facetedUniqueValues$;
|
|
3456
|
+
|
|
3457
|
+
facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
|
|
3458
|
+
} else {
|
|
3459
|
+
facetedUniqueValues.set(value, 1);
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
return facetedUniqueValues;
|
|
3464
|
+
}, {
|
|
3465
|
+
key: process.env.NODE_ENV === 'development' && 'getFacetedUniqueValues_' + columnId,
|
|
3466
|
+
debug: () => {
|
|
3467
|
+
var _instance$options$deb;
|
|
3468
|
+
|
|
3469
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3470
|
+
},
|
|
3471
|
+
onChange: () => {}
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
function getFacetedMinMaxValues() {
|
|
3476
|
+
return (instance, columnId) => memo(() => [instance.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
|
|
3477
|
+
var _facetedRowModel$flat;
|
|
3478
|
+
|
|
3479
|
+
const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
|
|
3480
|
+
|
|
3481
|
+
if (typeof firstValue === 'undefined') {
|
|
3482
|
+
return undefined;
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
let facetedMinMaxValues = [firstValue, firstValue];
|
|
3486
|
+
|
|
3487
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
3488
|
+
var _facetedRowModel$flat2;
|
|
3489
|
+
|
|
3490
|
+
const value = (_facetedRowModel$flat2 = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat2.getValue(columnId);
|
|
3491
|
+
|
|
3492
|
+
if (value < facetedMinMaxValues[0]) {
|
|
3493
|
+
facetedMinMaxValues[0] = value;
|
|
3494
|
+
} else if (value > facetedMinMaxValues[1]) {
|
|
3495
|
+
facetedMinMaxValues[1] = value;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
return facetedMinMaxValues;
|
|
3500
|
+
}, {
|
|
3501
|
+
key: process.env.NODE_ENV === 'development' && 'getFacetedMinMaxValues_' + columnId,
|
|
3502
|
+
debug: () => {
|
|
3503
|
+
var _instance$options$deb;
|
|
3504
|
+
|
|
3505
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3506
|
+
},
|
|
3507
|
+
onChange: () => {}
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
function getSortedRowModel() {
|
|
3512
|
+
return instance => memo(() => [instance.getState().sorting, instance.getPreSortedRowModel()], (sorting, rowModel) => {
|
|
3513
|
+
if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
|
|
3514
|
+
return rowModel;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
const sortingState = instance.getState().sorting;
|
|
3518
|
+
const sortedFlatRows = []; // Filter out sortings that correspond to non existing columns
|
|
3519
|
+
|
|
3520
|
+
const availableSorting = sortingState.filter(sort => instance.getColumn(sort.id).getCanSort());
|
|
3521
|
+
const columnInfoById = {};
|
|
3522
|
+
availableSorting.forEach(sortEntry => {
|
|
3523
|
+
const column = instance.getColumn(sortEntry.id);
|
|
3524
|
+
columnInfoById[sortEntry.id] = {
|
|
3525
|
+
sortUndefined: column.columnDef.sortUndefined,
|
|
3526
|
+
invertSorting: column.columnDef.invertSorting,
|
|
3527
|
+
sortingFn: column.getSortingFn()
|
|
3528
|
+
};
|
|
3529
|
+
});
|
|
3530
|
+
|
|
3531
|
+
const sortData = rows => {
|
|
3532
|
+
// This will also perform a stable sorting using the row index
|
|
3533
|
+
// if needed.
|
|
3534
|
+
const sortedData = rows.slice();
|
|
3535
|
+
sortedData.sort((rowA, rowB) => {
|
|
3536
|
+
for (let i = 0; i < availableSorting.length; i += 1) {
|
|
3537
|
+
var _sortEntry$desc;
|
|
3538
|
+
|
|
3539
|
+
const sortEntry = availableSorting[i];
|
|
3540
|
+
const columnInfo = columnInfoById[sortEntry.id];
|
|
3541
|
+
const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
|
|
3542
|
+
|
|
3543
|
+
if (columnInfo.sortUndefined) {
|
|
3544
|
+
const aValue = rowA.getValue(sortEntry.id);
|
|
3545
|
+
const bValue = rowB.getValue(sortEntry.id);
|
|
3546
|
+
const aUndefined = typeof aValue === 'undefined';
|
|
3547
|
+
const bUndefined = typeof bValue === 'undefined';
|
|
3548
|
+
|
|
3549
|
+
if (aUndefined || bUndefined) {
|
|
3550
|
+
return aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
|
|
3551
|
+
}
|
|
3552
|
+
} // This function should always return in ascending order
|
|
3553
|
+
|
|
3554
|
+
|
|
3555
|
+
let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
|
|
3556
|
+
|
|
3557
|
+
if (sortInt !== 0) {
|
|
3558
|
+
if (isDesc) {
|
|
3559
|
+
sortInt *= -1;
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
if (columnInfo.invertSorting) {
|
|
3563
|
+
sortInt *= -1;
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
return sortInt;
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
return rowA.index - rowB.index;
|
|
3571
|
+
}); // If there are sub-rows, sort them
|
|
3572
|
+
|
|
3573
|
+
sortedData.forEach(row => {
|
|
3574
|
+
sortedFlatRows.push(row);
|
|
3575
|
+
|
|
3576
|
+
if (!row.subRows || row.subRows.length <= 1) {
|
|
3577
|
+
return;
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
row.subRows = sortData(row.subRows);
|
|
3581
|
+
});
|
|
3582
|
+
return sortedData;
|
|
3583
|
+
};
|
|
3584
|
+
|
|
3585
|
+
return {
|
|
3586
|
+
rows: sortData(rowModel.rows),
|
|
3587
|
+
flatRows: sortedFlatRows,
|
|
3588
|
+
rowsById: rowModel.rowsById
|
|
3589
|
+
};
|
|
3590
|
+
}, {
|
|
3591
|
+
key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
|
|
3592
|
+
debug: () => {
|
|
3593
|
+
var _instance$options$deb;
|
|
3594
|
+
|
|
3595
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3596
|
+
},
|
|
3597
|
+
onChange: () => {
|
|
3598
|
+
instance._autoResetPageIndex();
|
|
3599
|
+
}
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
function getGroupedRowModel() {
|
|
3604
|
+
return instance => memo(() => [instance.getState().grouping, instance.getPreGroupedRowModel()], (grouping, rowModel) => {
|
|
3605
|
+
if (!rowModel.rows.length || !grouping.length) {
|
|
3606
|
+
return rowModel;
|
|
3607
|
+
} // Filter the grouping list down to columns that exist
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
const existingGrouping = grouping.filter(columnId => instance.getColumn(columnId));
|
|
3611
|
+
const groupedFlatRows = [];
|
|
3612
|
+
const groupedRowsById = {}; // const onlyGroupedFlatRows: Row[] = [];
|
|
3613
|
+
// const onlyGroupedRowsById: Record<RowId, Row> = {};
|
|
3614
|
+
// const nonGroupedFlatRows: Row[] = [];
|
|
3615
|
+
// const nonGroupedRowsById: Record<RowId, Row> = {};
|
|
3616
|
+
// Recursively group the data
|
|
3617
|
+
|
|
3618
|
+
const groupUpRecursively = function (rows, depth, parentId) {
|
|
3619
|
+
if (depth === void 0) {
|
|
3620
|
+
depth = 0;
|
|
3621
|
+
}
|
|
3622
|
+
|
|
3623
|
+
// This is the last level, just return the rows
|
|
3624
|
+
if (depth === existingGrouping.length) {
|
|
3625
|
+
return rows;
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
const columnId = existingGrouping[depth]; // Group the rows together for this level
|
|
3629
|
+
|
|
3630
|
+
const rowGroupsMap = groupBy(rows, columnId); // Peform aggregations for each group
|
|
3631
|
+
|
|
3632
|
+
const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map((_ref, index) => {
|
|
3633
|
+
let [groupingValue, groupedRows] = _ref;
|
|
3634
|
+
let id = columnId + ":" + groupingValue;
|
|
3635
|
+
id = parentId ? parentId + ">" + id : id; // First, Recurse to group sub rows before aggregation
|
|
3636
|
+
|
|
3637
|
+
const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
|
|
3638
|
+
|
|
3639
|
+
const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
|
|
3640
|
+
const row = createRow(instance, id, undefined, index, depth);
|
|
3641
|
+
Object.assign(row, {
|
|
3642
|
+
groupingColumnId: columnId,
|
|
3643
|
+
groupingValue,
|
|
3644
|
+
subRows,
|
|
3645
|
+
leafRows,
|
|
3646
|
+
getValue: columnId => {
|
|
3647
|
+
// Don't aggregate columns that are in the grouping
|
|
3648
|
+
if (existingGrouping.includes(columnId)) {
|
|
3649
|
+
if (row._valuesCache.hasOwnProperty(columnId)) {
|
|
3650
|
+
return row._valuesCache[columnId];
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
if (groupedRows[0]) {
|
|
3654
|
+
var _groupedRows$0$getVal;
|
|
3655
|
+
|
|
3656
|
+
row._valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
|
|
3657
|
+
}
|
|
3658
|
+
|
|
3659
|
+
return row._valuesCache[columnId];
|
|
3660
|
+
}
|
|
3661
|
+
|
|
3662
|
+
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
|
|
3663
|
+
return row._groupingValuesCache[columnId];
|
|
3664
|
+
} // Aggregate the values
|
|
3665
|
+
|
|
3666
|
+
|
|
3667
|
+
const column = instance.getColumn(columnId);
|
|
3668
|
+
const aggregateFn = column.getAggregationFn();
|
|
3669
|
+
|
|
3670
|
+
if (aggregateFn) {
|
|
3671
|
+
row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
|
|
3672
|
+
return row._groupingValuesCache[columnId];
|
|
3673
|
+
} else if (column.aggregationFn) {
|
|
3674
|
+
console.info({
|
|
3675
|
+
column
|
|
3676
|
+
});
|
|
3677
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
});
|
|
3681
|
+
subRows.forEach(subRow => {
|
|
3682
|
+
groupedFlatRows.push(subRow);
|
|
3683
|
+
groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
|
|
3684
|
+
// onlyGroupedFlatRows.push(subRow);
|
|
3685
|
+
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
3686
|
+
// } else {
|
|
3687
|
+
// nonGroupedFlatRows.push(subRow);
|
|
3688
|
+
// nonGroupedRowsById[subRow.id] = subRow;
|
|
3689
|
+
// }
|
|
3690
|
+
});
|
|
3691
|
+
return row;
|
|
3692
|
+
});
|
|
3693
|
+
return aggregatedGroupedRows;
|
|
3694
|
+
};
|
|
3695
|
+
|
|
3696
|
+
const groupedRows = groupUpRecursively(rowModel.rows, 0, '');
|
|
3697
|
+
groupedRows.forEach(subRow => {
|
|
3698
|
+
groupedFlatRows.push(subRow);
|
|
3699
|
+
groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
|
|
3700
|
+
// onlyGroupedFlatRows.push(subRow);
|
|
3701
|
+
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
3702
|
+
// } else {
|
|
3703
|
+
// nonGroupedFlatRows.push(subRow);
|
|
3704
|
+
// nonGroupedRowsById[subRow.id] = subRow;
|
|
3705
|
+
// }
|
|
3706
|
+
});
|
|
3707
|
+
return {
|
|
3708
|
+
rows: groupedRows,
|
|
3709
|
+
flatRows: groupedFlatRows,
|
|
3710
|
+
rowsById: groupedRowsById
|
|
3711
|
+
};
|
|
3712
|
+
}, {
|
|
3713
|
+
key: process.env.NODE_ENV === 'development' && 'getGroupedRowModel',
|
|
3714
|
+
debug: () => {
|
|
3715
|
+
var _instance$options$deb;
|
|
3716
|
+
|
|
3717
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3718
|
+
},
|
|
3719
|
+
onChange: () => {
|
|
3720
|
+
instance._queue(() => {
|
|
3721
|
+
instance._autoResetExpanded();
|
|
3722
|
+
|
|
3723
|
+
instance._autoResetPageIndex();
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
});
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
function groupBy(rows, columnId) {
|
|
3730
|
+
const groupMap = new Map();
|
|
3731
|
+
return rows.reduce((map, row) => {
|
|
3732
|
+
const resKey = "" + row.getValue(columnId);
|
|
3733
|
+
const previous = map.get(resKey);
|
|
3734
|
+
|
|
3735
|
+
if (!previous) {
|
|
3736
|
+
map.set(resKey, [row]);
|
|
3737
|
+
} else {
|
|
3738
|
+
map.set(resKey, [...previous, row]);
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3741
|
+
return map;
|
|
3742
|
+
}, groupMap);
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
function getExpandedRowModel() {
|
|
3746
|
+
return instance => memo(() => [instance.getState().expanded, instance.getPreExpandedRowModel(), instance.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
|
|
3747
|
+
if (!rowModel.rows.length || // Do not expand if rows are not included in pagination
|
|
3748
|
+
!paginateExpandedRows || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
|
|
3749
|
+
return rowModel;
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3752
|
+
return expandRows(rowModel);
|
|
3753
|
+
}, {
|
|
3754
|
+
key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
|
|
3755
|
+
debug: () => {
|
|
3756
|
+
var _instance$options$deb;
|
|
3757
|
+
|
|
3758
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3759
|
+
}
|
|
3760
|
+
});
|
|
3761
|
+
}
|
|
3762
|
+
function expandRows(rowModel, instance) {
|
|
3763
|
+
const expandedRows = [];
|
|
3764
|
+
|
|
3765
|
+
const handleRow = row => {
|
|
3766
|
+
var _row$subRows;
|
|
3767
|
+
|
|
3768
|
+
expandedRows.push(row);
|
|
3769
|
+
|
|
3770
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
|
|
3771
|
+
row.subRows.forEach(handleRow);
|
|
3772
|
+
}
|
|
3773
|
+
};
|
|
3774
|
+
|
|
3775
|
+
rowModel.rows.forEach(handleRow);
|
|
3776
|
+
return {
|
|
3777
|
+
rows: expandedRows,
|
|
3778
|
+
flatRows: rowModel.flatRows,
|
|
3779
|
+
rowsById: rowModel.rowsById
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
|
|
3783
|
+
function getPaginationRowModel(opts) {
|
|
3784
|
+
return instance => memo(() => [instance.getState().pagination, instance.getPrePaginationRowModel()], (pagination, rowModel) => {
|
|
3785
|
+
if (!rowModel.rows.length) {
|
|
3786
|
+
return rowModel;
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
const {
|
|
3790
|
+
pageSize,
|
|
3791
|
+
pageIndex
|
|
3792
|
+
} = pagination;
|
|
3793
|
+
let {
|
|
3794
|
+
rows,
|
|
3795
|
+
flatRows,
|
|
3796
|
+
rowsById
|
|
3797
|
+
} = rowModel;
|
|
3798
|
+
const pageStart = pageSize * pageIndex;
|
|
3799
|
+
const pageEnd = pageStart + pageSize;
|
|
3800
|
+
rows = rows.slice(pageStart, pageEnd);
|
|
3801
|
+
|
|
3802
|
+
if (!instance.options.paginateExpandedRows) {
|
|
3803
|
+
return expandRows({
|
|
3804
|
+
rows,
|
|
3805
|
+
flatRows,
|
|
3806
|
+
rowsById
|
|
3807
|
+
});
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
return {
|
|
3811
|
+
rows,
|
|
3812
|
+
flatRows,
|
|
3813
|
+
rowsById
|
|
3814
|
+
};
|
|
3815
|
+
}, {
|
|
3816
|
+
key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
|
|
3817
|
+
debug: () => {
|
|
3818
|
+
var _instance$options$deb;
|
|
3819
|
+
|
|
3820
|
+
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3821
|
+
}
|
|
3822
|
+
});
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
exports.ColumnSizing = ColumnSizing;
|
|
3826
|
+
exports.Expanding = Expanding;
|
|
3827
|
+
exports.Filters = Filters;
|
|
3828
|
+
exports.Grouping = Grouping;
|
|
3829
|
+
exports.Headers = Headers;
|
|
3830
|
+
exports.Ordering = Ordering;
|
|
3831
|
+
exports.Pagination = Pagination;
|
|
3832
|
+
exports.Pinning = Pinning;
|
|
3833
|
+
exports.RowSelection = RowSelection;
|
|
3834
|
+
exports.Sorting = Sorting;
|
|
3835
|
+
exports.Visibility = Visibility;
|
|
3836
|
+
exports.aggregationFns = aggregationFns;
|
|
3837
|
+
exports.buildHeaderGroups = buildHeaderGroups;
|
|
3838
|
+
exports.createColumn = createColumn;
|
|
3839
|
+
exports.createRow = createRow;
|
|
3840
|
+
exports.createTableFactory = createTableFactory;
|
|
3841
|
+
exports.createTableInstance = createTableInstance;
|
|
3842
|
+
exports.defaultColumnSizing = defaultColumnSizing;
|
|
3843
|
+
exports.expandRows = expandRows;
|
|
3844
|
+
exports.filterFns = filterFns;
|
|
3845
|
+
exports.flattenBy = flattenBy;
|
|
3846
|
+
exports.functionalUpdate = functionalUpdate;
|
|
3847
|
+
exports.getCoreRowModel = getCoreRowModel;
|
|
3848
|
+
exports.getExpandedRowModel = getExpandedRowModel;
|
|
3849
|
+
exports.getFacetedMinMaxValues = getFacetedMinMaxValues;
|
|
3850
|
+
exports.getFacetedRowModel = getFacetedRowModel;
|
|
3851
|
+
exports.getFacetedUniqueValues = getFacetedUniqueValues;
|
|
3852
|
+
exports.getFilteredRowModel = getFilteredRowModel;
|
|
3853
|
+
exports.getGroupedRowModel = getGroupedRowModel;
|
|
3854
|
+
exports.getPaginationRowModel = getPaginationRowModel;
|
|
3855
|
+
exports.getSortedRowModel = getSortedRowModel;
|
|
3856
|
+
exports.isFunction = isFunction;
|
|
3857
|
+
exports.isRowSelected = isRowSelected;
|
|
3858
|
+
exports.makeStateUpdater = makeStateUpdater;
|
|
3859
|
+
exports.memo = memo;
|
|
3860
|
+
exports.noop = noop;
|
|
3861
|
+
exports.orderColumns = orderColumns;
|
|
3862
|
+
exports.passiveEventSupported = passiveEventSupported;
|
|
3863
|
+
exports.reSplitAlphaNumeric = reSplitAlphaNumeric;
|
|
3864
|
+
exports.selectRowsFn = selectRowsFn;
|
|
3865
|
+
exports.shouldAutoRemoveFilter = shouldAutoRemoveFilter;
|
|
3866
|
+
exports.sortingFns = sortingFns;
|
|
3867
|
+
//# sourceMappingURL=index.js.map
|