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