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