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