@tanstack/react-table 8.17.0 → 9.0.0-alpha.0

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