@tanstack/svelte-table 8.13.1 → 8.14.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.
@@ -24,6 +24,63 @@
24
24
  *
25
25
  * @license MIT
26
26
  */
27
+ // type Person = {
28
+ // firstName: string
29
+ // lastName: string
30
+ // age: number
31
+ // visits: number
32
+ // status: string
33
+ // progress: number
34
+ // createdAt: Date
35
+ // nested: {
36
+ // foo: [
37
+ // {
38
+ // bar: 'bar'
39
+ // }
40
+ // ]
41
+ // bar: { subBar: boolean }[]
42
+ // baz: {
43
+ // foo: 'foo'
44
+ // bar: {
45
+ // baz: 'baz'
46
+ // }
47
+ // }
48
+ // }
49
+ // }
50
+
51
+ // const test: DeepKeys<Person> = 'nested.foo.0.bar'
52
+ // const test2: DeepKeys<Person> = 'nested.bar'
53
+
54
+ // const helper = createColumnHelper<Person>()
55
+
56
+ // helper.accessor('nested.foo', {
57
+ // cell: info => info.getValue(),
58
+ // })
59
+
60
+ // helper.accessor('nested.foo.0.bar', {
61
+ // cell: info => info.getValue(),
62
+ // })
63
+
64
+ // helper.accessor('nested.bar', {
65
+ // cell: info => info.getValue(),
66
+ // })
67
+
68
+ function createColumnHelper() {
69
+ return {
70
+ accessor: (accessor, column) => {
71
+ return typeof accessor === 'function' ? {
72
+ ...column,
73
+ accessorFn: accessor
74
+ } : {
75
+ ...column,
76
+ accessorKey: accessor
77
+ };
78
+ },
79
+ display: column => column,
80
+ group: column => column
81
+ };
82
+ }
83
+
27
84
  // Is this type a tuple?
28
85
 
29
86
  // If this type is a tuple, what indices are allowed?
@@ -114,6 +171,32 @@
114
171
  };
115
172
  }
116
173
 
174
+ function createCell(table, row, column, columnId) {
175
+ const getRenderValue = () => {
176
+ var _cell$getValue;
177
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
178
+ };
179
+ const cell = {
180
+ id: `${row.id}_${column.id}`,
181
+ row,
182
+ column,
183
+ getValue: () => row.getValue(columnId),
184
+ renderValue: getRenderValue,
185
+ getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
186
+ table,
187
+ column,
188
+ row,
189
+ cell: cell,
190
+ getValue: cell.getValue,
191
+ renderValue: cell.renderValue
192
+ }), getMemoOptions(table.options, 'debugCells', 'cell.getContext'))
193
+ };
194
+ table._features.forEach(feature => {
195
+ feature.createCell == null || feature.createCell(cell, column, row, table);
196
+ }, {});
197
+ return cell;
198
+ }
199
+
117
200
  function createColumn(table, columnDef, depth, parent) {
118
201
  var _ref, _resolvedColumnDef$id;
119
202
  const defaultColumn = table._getDefaultColumnDef();
@@ -173,7 +256,7 @@
173
256
  feature.createColumn == null || feature.createColumn(column, table);
174
257
  }
175
258
 
176
- // Yes, we have to convert table to uknown, because we know more than the compiler here.
259
+ // Yes, we have to convert table to unknown, because we know more than the compiler here.
177
260
  return column;
178
261
  }
179
262
 
@@ -430,656 +513,1087 @@
430
513
  return headerGroups;
431
514
  }
432
515
 
433
- //
516
+ const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
517
+ let row = {
518
+ id,
519
+ index: rowIndex,
520
+ original,
521
+ depth,
522
+ parentId,
523
+ _valuesCache: {},
524
+ _uniqueValuesCache: {},
525
+ getValue: columnId => {
526
+ if (row._valuesCache.hasOwnProperty(columnId)) {
527
+ return row._valuesCache[columnId];
528
+ }
529
+ const column = table.getColumn(columnId);
530
+ if (!(column != null && column.accessorFn)) {
531
+ return undefined;
532
+ }
533
+ row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
534
+ return row._valuesCache[columnId];
535
+ },
536
+ getUniqueValues: columnId => {
537
+ if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
538
+ return row._uniqueValuesCache[columnId];
539
+ }
540
+ const column = table.getColumn(columnId);
541
+ if (!(column != null && column.accessorFn)) {
542
+ return undefined;
543
+ }
544
+ if (!column.columnDef.getUniqueValues) {
545
+ row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
546
+ return row._uniqueValuesCache[columnId];
547
+ }
548
+ row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
549
+ return row._uniqueValuesCache[columnId];
550
+ },
551
+ renderValue: columnId => {
552
+ var _row$getValue;
553
+ return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
554
+ },
555
+ subRows: subRows != null ? subRows : [],
556
+ getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
557
+ getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : undefined,
558
+ getParentRows: () => {
559
+ let parentRows = [];
560
+ let currentRow = row;
561
+ while (true) {
562
+ const parentRow = currentRow.getParentRow();
563
+ if (!parentRow) break;
564
+ parentRows.push(parentRow);
565
+ currentRow = parentRow;
566
+ }
567
+ return parentRows.reverse();
568
+ },
569
+ getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
570
+ return leafColumns.map(column => {
571
+ return createCell(table, row, column, column.id);
572
+ });
573
+ }, getMemoOptions(table.options, 'debugRows', 'getAllCells')),
574
+ _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
575
+ return allCells.reduce((acc, cell) => {
576
+ acc[cell.column.id] = cell;
577
+ return acc;
578
+ }, {});
579
+ }, getMemoOptions(table.options, 'debugRows', 'getAllCellsByColumnId'))
580
+ };
581
+ for (let i = 0; i < table._features.length; i++) {
582
+ const feature = table._features[i];
583
+ feature == null || feature.createRow == null || feature.createRow(row, table);
584
+ }
585
+ return row;
586
+ };
434
587
 
435
588
  //
436
589
 
437
- const defaultColumnSizing = {
438
- size: 150,
439
- minSize: 20,
440
- maxSize: Number.MAX_SAFE_INTEGER
441
- };
442
- const getDefaultColumnSizingInfoState = () => ({
443
- startOffset: null,
444
- startSize: null,
445
- deltaOffset: null,
446
- deltaPercentage: null,
447
- isResizingColumn: false,
448
- columnSizingStart: []
449
- });
450
- const ColumnSizing = {
451
- getDefaultColumnDef: () => {
452
- return defaultColumnSizing;
453
- },
454
- getInitialState: state => {
455
- return {
456
- columnSizing: {},
457
- columnSizingInfo: getDefaultColumnSizingInfoState(),
458
- ...state
459
- };
460
- },
461
- getDefaultOptions: table => {
462
- return {
463
- columnResizeMode: 'onEnd',
464
- columnResizeDirection: 'ltr',
465
- onColumnSizingChange: makeStateUpdater('columnSizing', table),
466
- onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table)
467
- };
468
- },
590
+ const ColumnFaceting = {
469
591
  createColumn: (column, table) => {
470
- column.getSize = () => {
471
- var _column$columnDef$min, _ref, _column$columnDef$max;
472
- const columnSize = table.getState().columnSizing[column.id];
473
- 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);
474
- };
475
- 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'));
476
- 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'));
477
- column.resetSize = () => {
478
- table.setColumnSizing(_ref2 => {
479
- let {
480
- [column.id]: _,
481
- ...rest
482
- } = _ref2;
483
- return rest;
484
- });
485
- };
486
- column.getCanResize = () => {
487
- var _column$columnDef$ena, _table$options$enable;
488
- return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
489
- };
490
- column.getIsResizing = () => {
491
- return table.getState().columnSizingInfo.isResizingColumn === column.id;
592
+ column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
593
+ column.getFacetedRowModel = () => {
594
+ if (!column._getFacetedRowModel) {
595
+ return table.getPreFilteredRowModel();
596
+ }
597
+ return column._getFacetedRowModel();
492
598
  };
493
- },
494
- createHeader: (header, table) => {
495
- header.getSize = () => {
496
- let sum = 0;
497
- const recurse = header => {
498
- if (header.subHeaders.length) {
499
- header.subHeaders.forEach(recurse);
500
- } else {
501
- var _header$column$getSiz;
502
- sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
503
- }
504
- };
505
- recurse(header);
506
- return sum;
599
+ column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
600
+ column.getFacetedUniqueValues = () => {
601
+ if (!column._getFacetedUniqueValues) {
602
+ return new Map();
603
+ }
604
+ return column._getFacetedUniqueValues();
507
605
  };
508
- header.getStart = () => {
509
- if (header.index > 0) {
510
- const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
511
- return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
606
+ column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
607
+ column.getFacetedMinMaxValues = () => {
608
+ if (!column._getFacetedMinMaxValues) {
609
+ return undefined;
512
610
  }
513
- return 0;
514
- };
515
- header.getResizeHandler = _contextDocument => {
516
- const column = table.getColumn(header.column.id);
517
- const canResize = column == null ? void 0 : column.getCanResize();
518
- return e => {
519
- if (!column || !canResize) {
520
- return;
521
- }
522
- e.persist == null || e.persist();
523
- if (isTouchStartEvent(e)) {
524
- // lets not respond to multiple touches (e.g. 2 or 3 fingers)
525
- if (e.touches && e.touches.length > 1) {
526
- return;
527
- }
528
- }
529
- const startSize = header.getSize();
530
- const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
531
- const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
532
- const newColumnSizing = {};
533
- const updateOffset = (eventType, clientXPos) => {
534
- if (typeof clientXPos !== 'number') {
535
- return;
536
- }
537
- table.setColumnSizingInfo(old => {
538
- var _old$startOffset, _old$startSize;
539
- const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1;
540
- const deltaOffset = (clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0)) * deltaDirection;
541
- const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
542
- old.columnSizingStart.forEach(_ref3 => {
543
- let [columnId, headerSize] = _ref3;
544
- newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
545
- });
546
- return {
547
- ...old,
548
- deltaOffset,
549
- deltaPercentage
550
- };
551
- });
552
- if (table.options.columnResizeMode === 'onChange' || eventType === 'end') {
553
- table.setColumnSizing(old => ({
554
- ...old,
555
- ...newColumnSizing
556
- }));
557
- }
558
- };
559
- const onMove = clientXPos => updateOffset('move', clientXPos);
560
- const onEnd = clientXPos => {
561
- updateOffset('end', clientXPos);
562
- table.setColumnSizingInfo(old => ({
563
- ...old,
564
- isResizingColumn: false,
565
- startOffset: null,
566
- startSize: null,
567
- deltaOffset: null,
568
- deltaPercentage: null,
569
- columnSizingStart: []
570
- }));
571
- };
572
- const contextDocument = _contextDocument || typeof document !== 'undefined' ? document : null;
573
- const mouseEvents = {
574
- moveHandler: e => onMove(e.clientX),
575
- upHandler: e => {
576
- contextDocument == null || contextDocument.removeEventListener('mousemove', mouseEvents.moveHandler);
577
- contextDocument == null || contextDocument.removeEventListener('mouseup', mouseEvents.upHandler);
578
- onEnd(e.clientX);
579
- }
580
- };
581
- const touchEvents = {
582
- moveHandler: e => {
583
- if (e.cancelable) {
584
- e.preventDefault();
585
- e.stopPropagation();
586
- }
587
- onMove(e.touches[0].clientX);
588
- return false;
589
- },
590
- upHandler: e => {
591
- var _e$touches$;
592
- contextDocument == null || contextDocument.removeEventListener('touchmove', touchEvents.moveHandler);
593
- contextDocument == null || contextDocument.removeEventListener('touchend', touchEvents.upHandler);
594
- if (e.cancelable) {
595
- e.preventDefault();
596
- e.stopPropagation();
597
- }
598
- onEnd((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.clientX);
599
- }
600
- };
601
- const passiveIfSupported = passiveEventSupported() ? {
602
- passive: false
603
- } : false;
604
- if (isTouchStartEvent(e)) {
605
- contextDocument == null || contextDocument.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
606
- contextDocument == null || contextDocument.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
607
- } else {
608
- contextDocument == null || contextDocument.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
609
- contextDocument == null || contextDocument.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
610
- }
611
- table.setColumnSizingInfo(old => ({
612
- ...old,
613
- startOffset: clientX,
614
- startSize,
615
- deltaOffset: 0,
616
- deltaPercentage: 0,
617
- columnSizingStart,
618
- isResizingColumn: column.id
619
- }));
620
- };
621
- };
622
- },
623
- createTable: table => {
624
- table.setColumnSizing = updater => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater);
625
- table.setColumnSizingInfo = updater => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater);
626
- table.resetColumnSizing = defaultState => {
627
- var _table$initialState$c;
628
- table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
629
- };
630
- table.resetHeaderSizeInfo = defaultState => {
631
- var _table$initialState$c2;
632
- table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
633
- };
634
- table.getTotalSize = () => {
635
- var _table$getHeaderGroup, _table$getHeaderGroup2;
636
- return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum, header) => {
637
- return sum + header.getSize();
638
- }, 0)) != null ? _table$getHeaderGroup : 0;
639
- };
640
- table.getLeftTotalSize = () => {
641
- var _table$getLeftHeaderG, _table$getLeftHeaderG2;
642
- return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum, header) => {
643
- return sum + header.getSize();
644
- }, 0)) != null ? _table$getLeftHeaderG : 0;
645
- };
646
- table.getCenterTotalSize = () => {
647
- var _table$getCenterHeade, _table$getCenterHeade2;
648
- return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum, header) => {
649
- return sum + header.getSize();
650
- }, 0)) != null ? _table$getCenterHeade : 0;
651
- };
652
- table.getRightTotalSize = () => {
653
- var _table$getRightHeader, _table$getRightHeader2;
654
- return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum, header) => {
655
- return sum + header.getSize();
656
- }, 0)) != null ? _table$getRightHeader : 0;
611
+ return column._getFacetedMinMaxValues();
657
612
  };
658
613
  }
659
614
  };
660
- let passiveSupported = null;
661
- function passiveEventSupported() {
662
- if (typeof passiveSupported === 'boolean') return passiveSupported;
663
- let supported = false;
664
- try {
665
- const options = {
666
- get passive() {
667
- supported = true;
668
- return false;
669
- }
670
- };
671
- const noop = () => {};
672
- window.addEventListener('test', noop, options);
673
- window.removeEventListener('test', noop);
674
- } catch (err) {
675
- supported = false;
615
+
616
+ const includesString = (row, columnId, filterValue) => {
617
+ var _row$getValue;
618
+ const search = filterValue.toLowerCase();
619
+ 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));
620
+ };
621
+ includesString.autoRemove = val => testFalsey(val);
622
+ const includesStringSensitive = (row, columnId, filterValue) => {
623
+ var _row$getValue2;
624
+ return Boolean((_row$getValue2 = row.getValue(columnId)) == null || (_row$getValue2 = _row$getValue2.toString()) == null ? void 0 : _row$getValue2.includes(filterValue));
625
+ };
626
+ includesStringSensitive.autoRemove = val => testFalsey(val);
627
+ const equalsString = (row, columnId, filterValue) => {
628
+ var _row$getValue3;
629
+ return ((_row$getValue3 = row.getValue(columnId)) == null || (_row$getValue3 = _row$getValue3.toString()) == null ? void 0 : _row$getValue3.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
630
+ };
631
+ equalsString.autoRemove = val => testFalsey(val);
632
+ const arrIncludes = (row, columnId, filterValue) => {
633
+ var _row$getValue4;
634
+ return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
635
+ };
636
+ arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
637
+ const arrIncludesAll = (row, columnId, filterValue) => {
638
+ return !filterValue.some(val => {
639
+ var _row$getValue5;
640
+ return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
641
+ });
642
+ };
643
+ arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
644
+ const arrIncludesSome = (row, columnId, filterValue) => {
645
+ return filterValue.some(val => {
646
+ var _row$getValue6;
647
+ return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
648
+ });
649
+ };
650
+ arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
651
+ const equals = (row, columnId, filterValue) => {
652
+ return row.getValue(columnId) === filterValue;
653
+ };
654
+ equals.autoRemove = val => testFalsey(val);
655
+ const weakEquals = (row, columnId, filterValue) => {
656
+ return row.getValue(columnId) == filterValue;
657
+ };
658
+ weakEquals.autoRemove = val => testFalsey(val);
659
+ const inNumberRange = (row, columnId, filterValue) => {
660
+ let [min, max] = filterValue;
661
+ const rowValue = row.getValue(columnId);
662
+ return rowValue >= min && rowValue <= max;
663
+ };
664
+ inNumberRange.resolveFilterValue = val => {
665
+ let [unsafeMin, unsafeMax] = val;
666
+ let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
667
+ let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
668
+ let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
669
+ let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
670
+ if (min > max) {
671
+ const temp = min;
672
+ min = max;
673
+ max = temp;
676
674
  }
677
- passiveSupported = supported;
678
- return passiveSupported;
679
- }
680
- function isTouchStartEvent(e) {
681
- return e.type === 'touchstart';
675
+ return [min, max];
676
+ };
677
+ inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
678
+
679
+ // Export
680
+
681
+ const filterFns = {
682
+ includesString,
683
+ includesStringSensitive,
684
+ equalsString,
685
+ arrIncludes,
686
+ arrIncludesAll,
687
+ arrIncludesSome,
688
+ equals,
689
+ weakEquals,
690
+ inNumberRange
691
+ };
692
+ // Utils
693
+
694
+ function testFalsey(val) {
695
+ return val === undefined || val === null || val === '';
682
696
  }
683
697
 
684
698
  //
685
699
 
686
- const Expanding = {
700
+ const ColumnFiltering = {
701
+ getDefaultColumnDef: () => {
702
+ return {
703
+ filterFn: 'auto'
704
+ };
705
+ },
687
706
  getInitialState: state => {
688
707
  return {
689
- expanded: {},
708
+ columnFilters: [],
690
709
  ...state
691
710
  };
692
711
  },
693
712
  getDefaultOptions: table => {
694
713
  return {
695
- onExpandedChange: makeStateUpdater('expanded', table),
696
- paginateExpandedRows: true
714
+ onColumnFiltersChange: makeStateUpdater('columnFilters', table),
715
+ filterFromLeafRows: false,
716
+ maxLeafRowFilterDepth: 100
697
717
  };
698
718
  },
699
- createTable: table => {
700
- let registered = false;
701
- let queued = false;
702
- table._autoResetExpanded = () => {
703
- var _ref, _table$options$autoRe;
704
- if (!registered) {
705
- table._queue(() => {
706
- registered = true;
707
- });
708
- return;
709
- }
710
- if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
711
- if (queued) return;
712
- queued = true;
713
- table._queue(() => {
714
- table.resetExpanded();
715
- queued = false;
716
- });
719
+ createColumn: (column, table) => {
720
+ column.getAutoFilterFn = () => {
721
+ const firstRow = table.getCoreRowModel().flatRows[0];
722
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
723
+ if (typeof value === 'string') {
724
+ return filterFns.includesString;
717
725
  }
718
- };
719
- table.setExpanded = updater => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater);
720
- table.toggleAllRowsExpanded = expanded => {
721
- if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
722
- table.setExpanded(true);
723
- } else {
724
- table.setExpanded({});
726
+ if (typeof value === 'number') {
727
+ return filterFns.inNumberRange;
725
728
  }
726
- };
727
- table.resetExpanded = defaultState => {
728
- var _table$initialState$e, _table$initialState;
729
- table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
730
- };
731
- table.getCanSomeRowsExpand = () => {
732
- return table.getPrePaginationRowModel().flatRows.some(row => row.getCanExpand());
733
- };
734
- table.getToggleAllRowsExpandedHandler = () => {
735
- return e => {
736
- e.persist == null || e.persist();
737
- table.toggleAllRowsExpanded();
738
- };
739
- };
740
- table.getIsSomeRowsExpanded = () => {
741
- const expanded = table.getState().expanded;
742
- return expanded === true || Object.values(expanded).some(Boolean);
743
- };
744
- table.getIsAllRowsExpanded = () => {
745
- const expanded = table.getState().expanded;
746
-
747
- // If expanded is true, save some cycles and return true
748
- if (typeof expanded === 'boolean') {
749
- return expanded === true;
729
+ if (typeof value === 'boolean') {
730
+ return filterFns.equals;
750
731
  }
751
- if (!Object.keys(expanded).length) {
752
- return false;
732
+ if (value !== null && typeof value === 'object') {
733
+ return filterFns.equals;
753
734
  }
754
-
755
- // If any row is not expanded, return false
756
- if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
757
- return false;
735
+ if (Array.isArray(value)) {
736
+ return filterFns.arrIncludes;
758
737
  }
759
-
760
- // They must all be expanded :shrug:
761
- return true;
738
+ return filterFns.weakEquals;
762
739
  };
763
- table.getExpandedDepth = () => {
764
- let maxDepth = 0;
765
- const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
766
- rowIds.forEach(id => {
767
- const splitId = id.split('.');
768
- maxDepth = Math.max(maxDepth, splitId.length);
769
- });
770
- return maxDepth;
740
+ column.getFilterFn = () => {
741
+ var _table$options$filter, _table$options$filter2;
742
+ return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : // @ts-ignore
743
+ (_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];
771
744
  };
772
- table.getPreExpandedRowModel = () => table.getSortedRowModel();
773
- table.getExpandedRowModel = () => {
774
- if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
775
- table._getExpandedRowModel = table.options.getExpandedRowModel(table);
776
- }
777
- if (table.options.manualExpanding || !table._getExpandedRowModel) {
778
- return table.getPreExpandedRowModel();
779
- }
780
- return table._getExpandedRowModel();
745
+ column.getCanFilter = () => {
746
+ var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
747
+ 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;
781
748
  };
782
- },
783
- createRow: (row, table) => {
784
- row.toggleExpanded = expanded => {
785
- table.setExpanded(old => {
786
- var _expanded;
787
- const exists = old === true ? true : !!(old != null && old[row.id]);
788
- let oldExpanded = {};
789
- if (old === true) {
790
- Object.keys(table.getRowModel().rowsById).forEach(rowId => {
791
- oldExpanded[rowId] = true;
792
- });
793
- } else {
794
- oldExpanded = old;
749
+ column.getIsFiltered = () => column.getFilterIndex() > -1;
750
+ column.getFilterValue = () => {
751
+ var _table$getState$colum;
752
+ 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;
753
+ };
754
+ column.getFilterIndex = () => {
755
+ var _table$getState$colum2, _table$getState$colum3;
756
+ 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;
757
+ };
758
+ column.setFilterValue = value => {
759
+ table.setColumnFilters(old => {
760
+ const filterFn = column.getFilterFn();
761
+ const previousFilter = old == null ? void 0 : old.find(d => d.id === column.id);
762
+ const newFilter = functionalUpdate(value, previousFilter ? previousFilter.value : undefined);
763
+
764
+ //
765
+ if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
766
+ var _old$filter;
767
+ return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
795
768
  }
796
- expanded = (_expanded = expanded) != null ? _expanded : !exists;
797
- if (!exists && expanded) {
798
- return {
799
- ...oldExpanded,
800
- [row.id]: true
801
- };
769
+ const newFilterObj = {
770
+ id: column.id,
771
+ value: newFilter
772
+ };
773
+ if (previousFilter) {
774
+ var _old$map;
775
+ return (_old$map = old == null ? void 0 : old.map(d => {
776
+ if (d.id === column.id) {
777
+ return newFilterObj;
778
+ }
779
+ return d;
780
+ })) != null ? _old$map : [];
802
781
  }
803
- if (exists && !expanded) {
804
- const {
805
- [row.id]: _,
806
- ...rest
807
- } = oldExpanded;
808
- return rest;
782
+ if (old != null && old.length) {
783
+ return [...old, newFilterObj];
809
784
  }
810
- return old;
785
+ return [newFilterObj];
811
786
  });
812
787
  };
813
- row.getIsExpanded = () => {
814
- var _table$options$getIsR;
815
- const expanded = table.getState().expanded;
816
- 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]));
788
+ },
789
+ createRow: (row, _table) => {
790
+ row.columnFilters = {};
791
+ row.columnFiltersMeta = {};
792
+ },
793
+ createTable: table => {
794
+ table.setColumnFilters = updater => {
795
+ const leafColumns = table.getAllLeafColumns();
796
+ const updateFn = old => {
797
+ var _functionalUpdate;
798
+ return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
799
+ const column = leafColumns.find(d => d.id === filter.id);
800
+ if (column) {
801
+ const filterFn = column.getFilterFn();
802
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
803
+ return false;
804
+ }
805
+ }
806
+ return true;
807
+ });
808
+ };
809
+ table.options.onColumnFiltersChange == null || table.options.onColumnFiltersChange(updateFn);
817
810
  };
818
- row.getCanExpand = () => {
819
- var _table$options$getRow, _table$options$enable, _row$subRows;
820
- 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);
811
+ table.resetColumnFilters = defaultState => {
812
+ var _table$initialState$c, _table$initialState;
813
+ table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
821
814
  };
822
- row.getIsAllParentsExpanded = () => {
823
- let isFullyExpanded = true;
824
- let currentRow = row;
825
- while (isFullyExpanded && currentRow.parentId) {
826
- currentRow = table.getRow(currentRow.parentId, true);
827
- isFullyExpanded = currentRow.getIsExpanded();
815
+ table.getPreFilteredRowModel = () => table.getCoreRowModel();
816
+ table.getFilteredRowModel = () => {
817
+ if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
818
+ table._getFilteredRowModel = table.options.getFilteredRowModel(table);
828
819
  }
829
- return isFullyExpanded;
830
- };
831
- row.getToggleExpandedHandler = () => {
832
- const canExpand = row.getCanExpand();
833
- return () => {
834
- if (!canExpand) return;
835
- row.toggleExpanded();
836
- };
820
+ if (table.options.manualFiltering || !table._getFilteredRowModel) {
821
+ return table.getPreFilteredRowModel();
822
+ }
823
+ return table._getFilteredRowModel();
837
824
  };
838
825
  }
839
826
  };
827
+ function shouldAutoRemoveFilter(filterFn, value, column) {
828
+ return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
829
+ }
840
830
 
841
- const includesString = (row, columnId, filterValue) => {
842
- var _row$getValue;
843
- const search = filterValue.toLowerCase();
844
- 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));
845
- };
846
- includesString.autoRemove = val => testFalsey(val);
847
- const includesStringSensitive = (row, columnId, filterValue) => {
848
- var _row$getValue2;
849
- return Boolean((_row$getValue2 = row.getValue(columnId)) == null || (_row$getValue2 = _row$getValue2.toString()) == null ? void 0 : _row$getValue2.includes(filterValue));
850
- };
851
- includesStringSensitive.autoRemove = val => testFalsey(val);
852
- const equalsString = (row, columnId, filterValue) => {
853
- var _row$getValue3;
854
- return ((_row$getValue3 = row.getValue(columnId)) == null || (_row$getValue3 = _row$getValue3.toString()) == null ? void 0 : _row$getValue3.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
855
- };
856
- equalsString.autoRemove = val => testFalsey(val);
857
- const arrIncludes = (row, columnId, filterValue) => {
858
- var _row$getValue4;
859
- return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
831
+ const sum = (columnId, _leafRows, childRows) => {
832
+ // It's faster to just add the aggregations together instead of
833
+ // process leaf nodes individually
834
+ return childRows.reduce((sum, next) => {
835
+ const nextValue = next.getValue(columnId);
836
+ return sum + (typeof nextValue === 'number' ? nextValue : 0);
837
+ }, 0);
860
838
  };
861
- arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
862
- const arrIncludesAll = (row, columnId, filterValue) => {
863
- return !filterValue.some(val => {
864
- var _row$getValue5;
865
- return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
839
+ const min = (columnId, _leafRows, childRows) => {
840
+ let min;
841
+ childRows.forEach(row => {
842
+ const value = row.getValue(columnId);
843
+ if (value != null && (min > value || min === undefined && value >= value)) {
844
+ min = value;
845
+ }
866
846
  });
847
+ return min;
867
848
  };
868
- arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
869
- const arrIncludesSome = (row, columnId, filterValue) => {
870
- return filterValue.some(val => {
871
- var _row$getValue6;
872
- return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
849
+ const max = (columnId, _leafRows, childRows) => {
850
+ let max;
851
+ childRows.forEach(row => {
852
+ const value = row.getValue(columnId);
853
+ if (value != null && (max < value || max === undefined && value >= value)) {
854
+ max = value;
855
+ }
873
856
  });
857
+ return max;
874
858
  };
875
- arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
876
- const equals = (row, columnId, filterValue) => {
877
- return row.getValue(columnId) === filterValue;
878
- };
879
- equals.autoRemove = val => testFalsey(val);
880
- const weakEquals = (row, columnId, filterValue) => {
881
- return row.getValue(columnId) == filterValue;
859
+ const extent = (columnId, _leafRows, childRows) => {
860
+ let min;
861
+ let max;
862
+ childRows.forEach(row => {
863
+ const value = row.getValue(columnId);
864
+ if (value != null) {
865
+ if (min === undefined) {
866
+ if (value >= value) min = max = value;
867
+ } else {
868
+ if (min > value) min = value;
869
+ if (max < value) max = value;
870
+ }
871
+ }
872
+ });
873
+ return [min, max];
874
+ };
875
+ const mean = (columnId, leafRows) => {
876
+ let count = 0;
877
+ let sum = 0;
878
+ leafRows.forEach(row => {
879
+ let value = row.getValue(columnId);
880
+ if (value != null && (value = +value) >= value) {
881
+ ++count, sum += value;
882
+ }
883
+ });
884
+ if (count) return sum / count;
885
+ return;
886
+ };
887
+ const median = (columnId, leafRows) => {
888
+ if (!leafRows.length) {
889
+ return;
890
+ }
891
+ const values = leafRows.map(row => row.getValue(columnId));
892
+ if (!isNumberArray(values)) {
893
+ return;
894
+ }
895
+ if (values.length === 1) {
896
+ return values[0];
897
+ }
898
+ const mid = Math.floor(values.length / 2);
899
+ const nums = values.sort((a, b) => a - b);
900
+ return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
901
+ };
902
+ const unique = (columnId, leafRows) => {
903
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
904
+ };
905
+ const uniqueCount = (columnId, leafRows) => {
906
+ return new Set(leafRows.map(d => d.getValue(columnId))).size;
907
+ };
908
+ const count = (_columnId, leafRows) => {
909
+ return leafRows.length;
910
+ };
911
+ const aggregationFns = {
912
+ sum,
913
+ min,
914
+ max,
915
+ extent,
916
+ mean,
917
+ median,
918
+ unique,
919
+ uniqueCount,
920
+ count
921
+ };
922
+
923
+ //
924
+
925
+ const ColumnGrouping = {
926
+ getDefaultColumnDef: () => {
927
+ return {
928
+ aggregatedCell: props => {
929
+ var _toString, _props$getValue;
930
+ return (_toString = (_props$getValue = props.getValue()) == null || _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
931
+ },
932
+ aggregationFn: 'auto'
933
+ };
934
+ },
935
+ getInitialState: state => {
936
+ return {
937
+ grouping: [],
938
+ ...state
939
+ };
940
+ },
941
+ getDefaultOptions: table => {
942
+ return {
943
+ onGroupingChange: makeStateUpdater('grouping', table),
944
+ groupedColumnMode: 'reorder'
945
+ };
946
+ },
947
+ createColumn: (column, table) => {
948
+ column.toggleGrouping = () => {
949
+ table.setGrouping(old => {
950
+ // Find any existing grouping for this column
951
+ if (old != null && old.includes(column.id)) {
952
+ return old.filter(d => d !== column.id);
953
+ }
954
+ return [...(old != null ? old : []), column.id];
955
+ });
956
+ };
957
+ column.getCanGroup = () => {
958
+ var _ref, _ref2, _ref3, _column$columnDef$ena;
959
+ return (_ref = (_ref2 = (_ref3 = (_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) != null ? _ref3 : table.options.enableGrouping) != null ? _ref2 : true) != null ? _ref : !!column.accessorFn;
960
+ };
961
+ column.getIsGrouped = () => {
962
+ var _table$getState$group;
963
+ return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
964
+ };
965
+ column.getGroupedIndex = () => {
966
+ var _table$getState$group2;
967
+ return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
968
+ };
969
+ column.getToggleGroupingHandler = () => {
970
+ const canGroup = column.getCanGroup();
971
+ return () => {
972
+ if (!canGroup) return;
973
+ column.toggleGrouping();
974
+ };
975
+ };
976
+ column.getAutoAggregationFn = () => {
977
+ const firstRow = table.getCoreRowModel().flatRows[0];
978
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
979
+ if (typeof value === 'number') {
980
+ return aggregationFns.sum;
981
+ }
982
+ if (Object.prototype.toString.call(value) === '[object Date]') {
983
+ return aggregationFns.extent;
984
+ }
985
+ };
986
+ column.getAggregationFn = () => {
987
+ var _table$options$aggreg, _table$options$aggreg2;
988
+ if (!column) {
989
+ throw new Error();
990
+ }
991
+ 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];
992
+ };
993
+ },
994
+ createTable: table => {
995
+ table.setGrouping = updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater);
996
+ table.resetGrouping = defaultState => {
997
+ var _table$initialState$g, _table$initialState;
998
+ table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
999
+ };
1000
+ table.getPreGroupedRowModel = () => table.getFilteredRowModel();
1001
+ table.getGroupedRowModel = () => {
1002
+ if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
1003
+ table._getGroupedRowModel = table.options.getGroupedRowModel(table);
1004
+ }
1005
+ if (table.options.manualGrouping || !table._getGroupedRowModel) {
1006
+ return table.getPreGroupedRowModel();
1007
+ }
1008
+ return table._getGroupedRowModel();
1009
+ };
1010
+ },
1011
+ createRow: (row, table) => {
1012
+ row.getIsGrouped = () => !!row.groupingColumnId;
1013
+ row.getGroupingValue = columnId => {
1014
+ if (row._groupingValuesCache.hasOwnProperty(columnId)) {
1015
+ return row._groupingValuesCache[columnId];
1016
+ }
1017
+ const column = table.getColumn(columnId);
1018
+ if (!(column != null && column.columnDef.getGroupingValue)) {
1019
+ return row.getValue(columnId);
1020
+ }
1021
+ row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(row.original);
1022
+ return row._groupingValuesCache[columnId];
1023
+ };
1024
+ row._groupingValuesCache = {};
1025
+ },
1026
+ createCell: (cell, column, row, table) => {
1027
+ cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
1028
+ cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
1029
+ cell.getIsAggregated = () => {
1030
+ var _row$subRows;
1031
+ return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
1032
+ };
1033
+ }
1034
+ };
1035
+ function orderColumns(leafColumns, grouping, groupedColumnMode) {
1036
+ if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1037
+ return leafColumns;
1038
+ }
1039
+ const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
1040
+ if (groupedColumnMode === 'remove') {
1041
+ return nonGroupingColumns;
1042
+ }
1043
+ const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
1044
+ return [...groupingColumns, ...nonGroupingColumns];
1045
+ }
1046
+
1047
+ //
1048
+
1049
+ const ColumnOrdering = {
1050
+ getInitialState: state => {
1051
+ return {
1052
+ columnOrder: [],
1053
+ ...state
1054
+ };
1055
+ },
1056
+ getDefaultOptions: table => {
1057
+ return {
1058
+ onColumnOrderChange: makeStateUpdater('columnOrder', table)
1059
+ };
1060
+ },
1061
+ createColumn: (column, table) => {
1062
+ column.getIndex = memo(position => [_getVisibleLeafColumns(table, position)], columns => columns.findIndex(d => d.id === column.id), getMemoOptions(table.options, 'debugColumns', 'getIndex'));
1063
+ column.getIsFirstColumn = position => {
1064
+ var _columns$;
1065
+ const columns = _getVisibleLeafColumns(table, position);
1066
+ return ((_columns$ = columns[0]) == null ? void 0 : _columns$.id) === column.id;
1067
+ };
1068
+ column.getIsLastColumn = position => {
1069
+ var _columns;
1070
+ const columns = _getVisibleLeafColumns(table, position);
1071
+ return ((_columns = columns[columns.length - 1]) == null ? void 0 : _columns.id) === column.id;
1072
+ };
1073
+ },
1074
+ createTable: table => {
1075
+ table.setColumnOrder = updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater);
1076
+ table.resetColumnOrder = defaultState => {
1077
+ var _table$initialState$c;
1078
+ table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
1079
+ };
1080
+ table._getOrderColumnsFn = memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1081
+ // Sort grouped columns to the start of the column list
1082
+ // before the headers are built
1083
+ let orderedColumns = [];
1084
+
1085
+ // If there is no order, return the normal columns
1086
+ if (!(columnOrder != null && columnOrder.length)) {
1087
+ orderedColumns = columns;
1088
+ } else {
1089
+ const columnOrderCopy = [...columnOrder];
1090
+
1091
+ // If there is an order, make a copy of the columns
1092
+ const columnsCopy = [...columns];
1093
+
1094
+ // And make a new ordered array of the columns
1095
+
1096
+ // Loop over the columns and place them in order into the new array
1097
+ while (columnsCopy.length && columnOrderCopy.length) {
1098
+ const targetColumnId = columnOrderCopy.shift();
1099
+ const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
1100
+ if (foundIndex > -1) {
1101
+ orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1102
+ }
1103
+ }
1104
+
1105
+ // If there are any columns left, add them to the end
1106
+ orderedColumns = [...orderedColumns, ...columnsCopy];
1107
+ }
1108
+ return orderColumns(orderedColumns, grouping, groupedColumnMode);
1109
+ }, getMemoOptions(table.options, 'debugTable', '_getOrderColumnsFn'));
1110
+ }
1111
+ };
1112
+
1113
+ //
1114
+
1115
+ const getDefaultColumnPinningState = () => ({
1116
+ left: [],
1117
+ right: []
1118
+ });
1119
+ const ColumnPinning = {
1120
+ getInitialState: state => {
1121
+ return {
1122
+ columnPinning: getDefaultColumnPinningState(),
1123
+ ...state
1124
+ };
1125
+ },
1126
+ getDefaultOptions: table => {
1127
+ return {
1128
+ onColumnPinningChange: makeStateUpdater('columnPinning', table)
1129
+ };
1130
+ },
1131
+ createColumn: (column, table) => {
1132
+ column.pin = position => {
1133
+ const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
1134
+ table.setColumnPinning(old => {
1135
+ var _old$left3, _old$right3;
1136
+ if (position === 'right') {
1137
+ var _old$left, _old$right;
1138
+ return {
1139
+ left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1140
+ right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
1141
+ };
1142
+ }
1143
+ if (position === 'left') {
1144
+ var _old$left2, _old$right2;
1145
+ return {
1146
+ left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1147
+ right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1148
+ };
1149
+ }
1150
+ return {
1151
+ left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1152
+ right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1153
+ };
1154
+ });
1155
+ };
1156
+ column.getCanPin = () => {
1157
+ const leafColumns = column.getLeafColumns();
1158
+ return leafColumns.some(d => {
1159
+ var _d$columnDef$enablePi, _ref, _table$options$enable;
1160
+ 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);
1161
+ });
1162
+ };
1163
+ column.getIsPinned = () => {
1164
+ const leafColumnIds = column.getLeafColumns().map(d => d.id);
1165
+ const {
1166
+ left,
1167
+ right
1168
+ } = table.getState().columnPinning;
1169
+ const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
1170
+ const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
1171
+ return isLeft ? 'left' : isRight ? 'right' : false;
1172
+ };
1173
+ column.getPinnedIndex = () => {
1174
+ var _table$getState$colum, _table$getState$colum2;
1175
+ const position = column.getIsPinned();
1176
+ 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;
1177
+ };
1178
+ },
1179
+ createRow: (row, table) => {
1180
+ row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1181
+ const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1182
+ return allCells.filter(d => !leftAndRight.includes(d.column.id));
1183
+ }, getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells'));
1184
+ row.getLeftVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left], (allCells, left) => {
1185
+ const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1186
+ ...d,
1187
+ position: 'left'
1188
+ }));
1189
+ return cells;
1190
+ }, getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells'));
1191
+ row.getRightVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1192
+ const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1193
+ ...d,
1194
+ position: 'right'
1195
+ }));
1196
+ return cells;
1197
+ }, getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells'));
1198
+ },
1199
+ createTable: table => {
1200
+ table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1201
+ table.resetColumnPinning = defaultState => {
1202
+ var _table$initialState$c, _table$initialState;
1203
+ return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1204
+ };
1205
+ table.getIsSomeColumnsPinned = position => {
1206
+ var _pinningState$positio;
1207
+ const pinningState = table.getState().columnPinning;
1208
+ if (!position) {
1209
+ var _pinningState$left, _pinningState$right;
1210
+ return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1211
+ }
1212
+ return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1213
+ };
1214
+ table.getLeftLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1215
+ return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1216
+ }, getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns'));
1217
+ table.getRightLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1218
+ return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1219
+ }, getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns'));
1220
+ table.getCenterLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1221
+ const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1222
+ return allColumns.filter(d => !leftAndRight.includes(d.id));
1223
+ }, getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns'));
1224
+ }
882
1225
  };
883
- weakEquals.autoRemove = val => testFalsey(val);
884
- const inNumberRange = (row, columnId, filterValue) => {
885
- let [min, max] = filterValue;
886
- const rowValue = row.getValue(columnId);
887
- return rowValue >= min && rowValue <= max;
1226
+
1227
+ //
1228
+
1229
+ //
1230
+
1231
+ const defaultColumnSizing = {
1232
+ size: 150,
1233
+ minSize: 20,
1234
+ maxSize: Number.MAX_SAFE_INTEGER
888
1235
  };
889
- inNumberRange.resolveFilterValue = val => {
890
- let [unsafeMin, unsafeMax] = val;
891
- let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
892
- let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
893
- let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
894
- let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
895
- if (min > max) {
896
- const temp = min;
897
- min = max;
898
- max = temp;
1236
+ const getDefaultColumnSizingInfoState = () => ({
1237
+ startOffset: null,
1238
+ startSize: null,
1239
+ deltaOffset: null,
1240
+ deltaPercentage: null,
1241
+ isResizingColumn: false,
1242
+ columnSizingStart: []
1243
+ });
1244
+ const ColumnSizing = {
1245
+ getDefaultColumnDef: () => {
1246
+ return defaultColumnSizing;
1247
+ },
1248
+ getInitialState: state => {
1249
+ return {
1250
+ columnSizing: {},
1251
+ columnSizingInfo: getDefaultColumnSizingInfoState(),
1252
+ ...state
1253
+ };
1254
+ },
1255
+ getDefaultOptions: table => {
1256
+ return {
1257
+ columnResizeMode: 'onEnd',
1258
+ columnResizeDirection: 'ltr',
1259
+ onColumnSizingChange: makeStateUpdater('columnSizing', table),
1260
+ onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table)
1261
+ };
1262
+ },
1263
+ createColumn: (column, table) => {
1264
+ column.getSize = () => {
1265
+ var _column$columnDef$min, _ref, _column$columnDef$max;
1266
+ const columnSize = table.getState().columnSizing[column.id];
1267
+ 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);
1268
+ };
1269
+ 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'));
1270
+ 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'));
1271
+ column.resetSize = () => {
1272
+ table.setColumnSizing(_ref2 => {
1273
+ let {
1274
+ [column.id]: _,
1275
+ ...rest
1276
+ } = _ref2;
1277
+ return rest;
1278
+ });
1279
+ };
1280
+ column.getCanResize = () => {
1281
+ var _column$columnDef$ena, _table$options$enable;
1282
+ return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
1283
+ };
1284
+ column.getIsResizing = () => {
1285
+ return table.getState().columnSizingInfo.isResizingColumn === column.id;
1286
+ };
1287
+ },
1288
+ createHeader: (header, table) => {
1289
+ header.getSize = () => {
1290
+ let sum = 0;
1291
+ const recurse = header => {
1292
+ if (header.subHeaders.length) {
1293
+ header.subHeaders.forEach(recurse);
1294
+ } else {
1295
+ var _header$column$getSiz;
1296
+ sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
1297
+ }
1298
+ };
1299
+ recurse(header);
1300
+ return sum;
1301
+ };
1302
+ header.getStart = () => {
1303
+ if (header.index > 0) {
1304
+ const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
1305
+ return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
1306
+ }
1307
+ return 0;
1308
+ };
1309
+ header.getResizeHandler = _contextDocument => {
1310
+ const column = table.getColumn(header.column.id);
1311
+ const canResize = column == null ? void 0 : column.getCanResize();
1312
+ return e => {
1313
+ if (!column || !canResize) {
1314
+ return;
1315
+ }
1316
+ e.persist == null || e.persist();
1317
+ if (isTouchStartEvent(e)) {
1318
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
1319
+ if (e.touches && e.touches.length > 1) {
1320
+ return;
1321
+ }
1322
+ }
1323
+ const startSize = header.getSize();
1324
+ const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
1325
+ const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
1326
+ const newColumnSizing = {};
1327
+ const updateOffset = (eventType, clientXPos) => {
1328
+ if (typeof clientXPos !== 'number') {
1329
+ return;
1330
+ }
1331
+ table.setColumnSizingInfo(old => {
1332
+ var _old$startOffset, _old$startSize;
1333
+ const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1;
1334
+ const deltaOffset = (clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0)) * deltaDirection;
1335
+ const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
1336
+ old.columnSizingStart.forEach(_ref3 => {
1337
+ let [columnId, headerSize] = _ref3;
1338
+ newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
1339
+ });
1340
+ return {
1341
+ ...old,
1342
+ deltaOffset,
1343
+ deltaPercentage
1344
+ };
1345
+ });
1346
+ if (table.options.columnResizeMode === 'onChange' || eventType === 'end') {
1347
+ table.setColumnSizing(old => ({
1348
+ ...old,
1349
+ ...newColumnSizing
1350
+ }));
1351
+ }
1352
+ };
1353
+ const onMove = clientXPos => updateOffset('move', clientXPos);
1354
+ const onEnd = clientXPos => {
1355
+ updateOffset('end', clientXPos);
1356
+ table.setColumnSizingInfo(old => ({
1357
+ ...old,
1358
+ isResizingColumn: false,
1359
+ startOffset: null,
1360
+ startSize: null,
1361
+ deltaOffset: null,
1362
+ deltaPercentage: null,
1363
+ columnSizingStart: []
1364
+ }));
1365
+ };
1366
+ const contextDocument = _contextDocument || typeof document !== 'undefined' ? document : null;
1367
+ const mouseEvents = {
1368
+ moveHandler: e => onMove(e.clientX),
1369
+ upHandler: e => {
1370
+ contextDocument == null || contextDocument.removeEventListener('mousemove', mouseEvents.moveHandler);
1371
+ contextDocument == null || contextDocument.removeEventListener('mouseup', mouseEvents.upHandler);
1372
+ onEnd(e.clientX);
1373
+ }
1374
+ };
1375
+ const touchEvents = {
1376
+ moveHandler: e => {
1377
+ if (e.cancelable) {
1378
+ e.preventDefault();
1379
+ e.stopPropagation();
1380
+ }
1381
+ onMove(e.touches[0].clientX);
1382
+ return false;
1383
+ },
1384
+ upHandler: e => {
1385
+ var _e$touches$;
1386
+ contextDocument == null || contextDocument.removeEventListener('touchmove', touchEvents.moveHandler);
1387
+ contextDocument == null || contextDocument.removeEventListener('touchend', touchEvents.upHandler);
1388
+ if (e.cancelable) {
1389
+ e.preventDefault();
1390
+ e.stopPropagation();
1391
+ }
1392
+ onEnd((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.clientX);
1393
+ }
1394
+ };
1395
+ const passiveIfSupported = passiveEventSupported() ? {
1396
+ passive: false
1397
+ } : false;
1398
+ if (isTouchStartEvent(e)) {
1399
+ contextDocument == null || contextDocument.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
1400
+ contextDocument == null || contextDocument.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
1401
+ } else {
1402
+ contextDocument == null || contextDocument.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
1403
+ contextDocument == null || contextDocument.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
1404
+ }
1405
+ table.setColumnSizingInfo(old => ({
1406
+ ...old,
1407
+ startOffset: clientX,
1408
+ startSize,
1409
+ deltaOffset: 0,
1410
+ deltaPercentage: 0,
1411
+ columnSizingStart,
1412
+ isResizingColumn: column.id
1413
+ }));
1414
+ };
1415
+ };
1416
+ },
1417
+ createTable: table => {
1418
+ table.setColumnSizing = updater => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater);
1419
+ table.setColumnSizingInfo = updater => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater);
1420
+ table.resetColumnSizing = defaultState => {
1421
+ var _table$initialState$c;
1422
+ table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
1423
+ };
1424
+ table.resetHeaderSizeInfo = defaultState => {
1425
+ var _table$initialState$c2;
1426
+ table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
1427
+ };
1428
+ table.getTotalSize = () => {
1429
+ var _table$getHeaderGroup, _table$getHeaderGroup2;
1430
+ return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum, header) => {
1431
+ return sum + header.getSize();
1432
+ }, 0)) != null ? _table$getHeaderGroup : 0;
1433
+ };
1434
+ table.getLeftTotalSize = () => {
1435
+ var _table$getLeftHeaderG, _table$getLeftHeaderG2;
1436
+ return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum, header) => {
1437
+ return sum + header.getSize();
1438
+ }, 0)) != null ? _table$getLeftHeaderG : 0;
1439
+ };
1440
+ table.getCenterTotalSize = () => {
1441
+ var _table$getCenterHeade, _table$getCenterHeade2;
1442
+ return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum, header) => {
1443
+ return sum + header.getSize();
1444
+ }, 0)) != null ? _table$getCenterHeade : 0;
1445
+ };
1446
+ table.getRightTotalSize = () => {
1447
+ var _table$getRightHeader, _table$getRightHeader2;
1448
+ return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum, header) => {
1449
+ return sum + header.getSize();
1450
+ }, 0)) != null ? _table$getRightHeader : 0;
1451
+ };
899
1452
  }
900
- return [min, max];
901
- };
902
- inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
903
-
904
- // Export
905
-
906
- const filterFns = {
907
- includesString,
908
- includesStringSensitive,
909
- equalsString,
910
- arrIncludes,
911
- arrIncludesAll,
912
- arrIncludesSome,
913
- equals,
914
- weakEquals,
915
- inNumberRange
916
1453
  };
917
- // Utils
918
-
919
- function testFalsey(val) {
920
- return val === undefined || val === null || val === '';
1454
+ let passiveSupported = null;
1455
+ function passiveEventSupported() {
1456
+ if (typeof passiveSupported === 'boolean') return passiveSupported;
1457
+ let supported = false;
1458
+ try {
1459
+ const options = {
1460
+ get passive() {
1461
+ supported = true;
1462
+ return false;
1463
+ }
1464
+ };
1465
+ const noop = () => {};
1466
+ window.addEventListener('test', noop, options);
1467
+ window.removeEventListener('test', noop);
1468
+ } catch (err) {
1469
+ supported = false;
1470
+ }
1471
+ passiveSupported = supported;
1472
+ return passiveSupported;
1473
+ }
1474
+ function isTouchStartEvent(e) {
1475
+ return e.type === 'touchstart';
921
1476
  }
922
1477
 
923
1478
  //
924
1479
 
925
- const Filters = {
926
- getDefaultColumnDef: () => {
927
- return {
928
- filterFn: 'auto'
929
- };
930
- },
1480
+ const ColumnVisibility = {
931
1481
  getInitialState: state => {
932
1482
  return {
933
- columnFilters: [],
934
- globalFilter: undefined,
935
- // filtersProgress: 1,
936
- // facetProgress: {},
1483
+ columnVisibility: {},
937
1484
  ...state
938
1485
  };
939
1486
  },
940
1487
  getDefaultOptions: table => {
941
1488
  return {
942
- onColumnFiltersChange: makeStateUpdater('columnFilters', table),
943
- onGlobalFilterChange: makeStateUpdater('globalFilter', table),
944
- filterFromLeafRows: false,
945
- maxLeafRowFilterDepth: 100,
946
- globalFilterFn: 'auto',
947
- getColumnCanGlobalFilter: column => {
948
- var _table$getCoreRowMode;
949
- const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null || (_table$getCoreRowMode = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode.getValue();
950
- return typeof value === 'string' || typeof value === 'number';
951
- }
1489
+ onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
952
1490
  };
953
1491
  },
954
1492
  createColumn: (column, table) => {
955
- column.getAutoFilterFn = () => {
956
- const firstRow = table.getCoreRowModel().flatRows[0];
957
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
958
- if (typeof value === 'string') {
959
- return filterFns.includesString;
960
- }
961
- if (typeof value === 'number') {
962
- return filterFns.inNumberRange;
963
- }
964
- if (typeof value === 'boolean') {
965
- return filterFns.equals;
966
- }
967
- if (value !== null && typeof value === 'object') {
968
- return filterFns.equals;
969
- }
970
- if (Array.isArray(value)) {
971
- return filterFns.arrIncludes;
1493
+ column.toggleVisibility = value => {
1494
+ if (column.getCanHide()) {
1495
+ table.setColumnVisibility(old => ({
1496
+ ...old,
1497
+ [column.id]: value != null ? value : !column.getIsVisible()
1498
+ }));
972
1499
  }
973
- return filterFns.weakEquals;
974
1500
  };
975
- column.getFilterFn = () => {
976
- var _table$options$filter, _table$options$filter2;
977
- return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : // @ts-ignore
978
- (_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];
1501
+ column.getIsVisible = () => {
1502
+ var _ref, _table$getState$colum;
1503
+ const childColumns = column.columns;
1504
+ 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;
979
1505
  };
980
- column.getCanFilter = () => {
981
- var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
982
- 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;
1506
+ column.getCanHide = () => {
1507
+ var _column$columnDef$ena, _table$options$enable;
1508
+ return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
983
1509
  };
984
- column.getCanGlobalFilter = () => {
985
- var _column$columnDef$ena2, _table$options$enable3, _table$options$enable4, _table$options$getCol;
986
- return ((_column$columnDef$ena2 = column.columnDef.enableGlobalFilter) != null ? _column$columnDef$ena2 : true) && ((_table$options$enable3 = table.options.enableGlobalFilter) != null ? _table$options$enable3 : true) && ((_table$options$enable4 = table.options.enableFilters) != null ? _table$options$enable4 : true) && ((_table$options$getCol = table.options.getColumnCanGlobalFilter == null ? void 0 : table.options.getColumnCanGlobalFilter(column)) != null ? _table$options$getCol : true) && !!column.accessorFn;
1510
+ column.getToggleVisibilityHandler = () => {
1511
+ return e => {
1512
+ column.toggleVisibility == null || column.toggleVisibility(e.target.checked);
1513
+ };
987
1514
  };
988
- column.getIsFiltered = () => column.getFilterIndex() > -1;
989
- column.getFilterValue = () => {
990
- var _table$getState$colum;
991
- 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;
1515
+ },
1516
+ createRow: (row, table) => {
1517
+ row._getAllVisibleCells = memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
1518
+ return cells.filter(cell => cell.column.getIsVisible());
1519
+ }, getMemoOptions(table.options, 'debugRows', '_getAllVisibleCells'));
1520
+ row.getVisibleCells = memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], getMemoOptions(table.options, 'debugRows', 'getVisibleCells'));
1521
+ },
1522
+ createTable: table => {
1523
+ const makeVisibleColumnsMethod = (key, getColumns) => {
1524
+ return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
1525
+ return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
1526
+ }, getMemoOptions(table.options, 'debugColumns', key));
992
1527
  };
993
- column.getFilterIndex = () => {
994
- var _table$getState$colum2, _table$getState$colum3;
995
- 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;
1528
+ table.getVisibleFlatColumns = makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns());
1529
+ table.getVisibleLeafColumns = makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns());
1530
+ table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns());
1531
+ table.getRightVisibleLeafColumns = makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns());
1532
+ table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns());
1533
+ table.setColumnVisibility = updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater);
1534
+ table.resetColumnVisibility = defaultState => {
1535
+ var _table$initialState$c;
1536
+ table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
996
1537
  };
997
- column.setFilterValue = value => {
998
- table.setColumnFilters(old => {
999
- const filterFn = column.getFilterFn();
1000
- const previousfilter = old == null ? void 0 : old.find(d => d.id === column.id);
1001
- const newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined);
1002
-
1003
- //
1004
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
1005
- var _old$filter;
1006
- return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
1007
- }
1008
- const newFilterObj = {
1009
- id: column.id,
1010
- value: newFilter
1011
- };
1012
- if (previousfilter) {
1013
- var _old$map;
1014
- return (_old$map = old == null ? void 0 : old.map(d => {
1015
- if (d.id === column.id) {
1016
- return newFilterObj;
1017
- }
1018
- return d;
1019
- })) != null ? _old$map : [];
1020
- }
1021
- if (old != null && old.length) {
1022
- return [...old, newFilterObj];
1023
- }
1024
- return [newFilterObj];
1025
- });
1538
+ table.toggleAllColumnsVisible = value => {
1539
+ var _value;
1540
+ value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
1541
+ table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
1542
+ ...obj,
1543
+ [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
1544
+ }), {}));
1026
1545
  };
1027
- column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
1028
- column.getFacetedRowModel = () => {
1029
- if (!column._getFacetedRowModel) {
1030
- return table.getPreFilteredRowModel();
1031
- }
1032
- return column._getFacetedRowModel();
1546
+ table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible()));
1547
+ table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible());
1548
+ table.getToggleAllColumnsVisibilityHandler = () => {
1549
+ return e => {
1550
+ var _target;
1551
+ table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
1552
+ };
1033
1553
  };
1034
- column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
1035
- column.getFacetedUniqueValues = () => {
1036
- if (!column._getFacetedUniqueValues) {
1037
- return new Map();
1038
- }
1039
- return column._getFacetedUniqueValues();
1554
+ }
1555
+ };
1556
+ function _getVisibleLeafColumns(table, position) {
1557
+ return !position ? table.getVisibleLeafColumns() : position === 'center' ? table.getCenterVisibleLeafColumns() : position === 'left' ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
1558
+ }
1559
+
1560
+ //
1561
+
1562
+ const GlobalFiltering = {
1563
+ getInitialState: state => {
1564
+ return {
1565
+ globalFilter: undefined,
1566
+ ...state
1040
1567
  };
1041
- column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
1042
- column.getFacetedMinMaxValues = () => {
1043
- if (!column._getFacetedMinMaxValues) {
1044
- return undefined;
1568
+ },
1569
+ getDefaultOptions: table => {
1570
+ return {
1571
+ onGlobalFilterChange: makeStateUpdater('globalFilter', table),
1572
+ globalFilterFn: 'auto',
1573
+ getColumnCanGlobalFilter: column => {
1574
+ var _table$getCoreRowMode;
1575
+ const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null || (_table$getCoreRowMode = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode.getValue();
1576
+ return typeof value === 'string' || typeof value === 'number';
1045
1577
  }
1046
- return column._getFacetedMinMaxValues();
1047
1578
  };
1048
- // () => [column.getFacetedRowModel()],
1049
- // facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
1050
1579
  },
1051
- createRow: (row, table) => {
1052
- row.columnFilters = {};
1053
- row.columnFiltersMeta = {};
1580
+ createColumn: (column, table) => {
1581
+ column.getCanGlobalFilter = () => {
1582
+ var _column$columnDef$ena, _table$options$enable, _table$options$enable2, _table$options$getCol;
1583
+ 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;
1584
+ };
1054
1585
  },
1055
1586
  createTable: table => {
1056
1587
  table.getGlobalAutoFilterFn = () => {
1057
1588
  return filterFns.includesString;
1058
1589
  };
1059
1590
  table.getGlobalFilterFn = () => {
1060
- var _table$options$filter3, _table$options$filter4;
1591
+ var _table$options$filter, _table$options$filter2;
1061
1592
  const {
1062
1593
  globalFilterFn: globalFilterFn
1063
1594
  } = table.options;
1064
1595
  return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? table.getGlobalAutoFilterFn() : // @ts-ignore
1065
- (_table$options$filter3 = (_table$options$filter4 = table.options.filterFns) == null ? void 0 : _table$options$filter4[globalFilterFn]) != null ? _table$options$filter3 : filterFns[globalFilterFn];
1066
- };
1067
- table.setColumnFilters = updater => {
1068
- const leafColumns = table.getAllLeafColumns();
1069
- const updateFn = old => {
1070
- var _functionalUpdate;
1071
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
1072
- const column = leafColumns.find(d => d.id === filter.id);
1073
- if (column) {
1074
- const filterFn = column.getFilterFn();
1075
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
1076
- return false;
1077
- }
1078
- }
1079
- return true;
1080
- });
1081
- };
1082
- table.options.onColumnFiltersChange == null || table.options.onColumnFiltersChange(updateFn);
1596
+ (_table$options$filter = (_table$options$filter2 = table.options.filterFns) == null ? void 0 : _table$options$filter2[globalFilterFn]) != null ? _table$options$filter : filterFns[globalFilterFn];
1083
1597
  };
1084
1598
  table.setGlobalFilter = updater => {
1085
1599
  table.options.onGlobalFilterChange == null || table.options.onGlobalFilterChange(updater);
@@ -1087,20 +1601,6 @@
1087
1601
  table.resetGlobalFilter = defaultState => {
1088
1602
  table.setGlobalFilter(defaultState ? undefined : table.initialState.globalFilter);
1089
1603
  };
1090
- table.resetColumnFilters = defaultState => {
1091
- var _table$initialState$c, _table$initialState;
1092
- table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
1093
- };
1094
- table.getPreFilteredRowModel = () => table.getCoreRowModel();
1095
- table.getFilteredRowModel = () => {
1096
- if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
1097
- table._getFilteredRowModel = table.options.getFilteredRowModel(table);
1098
- }
1099
- if (table.options.manualFiltering || !table._getFilteredRowModel) {
1100
- return table.getPreFilteredRowModel();
1101
- }
1102
- return table._getFilteredRowModel();
1103
- };
1104
1604
  table._getGlobalFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, '__global__');
1105
1605
  table.getGlobalFacetedRowModel = () => {
1106
1606
  if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
@@ -1124,289 +1624,161 @@
1124
1624
  };
1125
1625
  }
1126
1626
  };
1127
- function shouldAutoRemoveFilter(filterFn, value, column) {
1128
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1129
- }
1130
-
1131
- const sum = (columnId, _leafRows, childRows) => {
1132
- // It's faster to just add the aggregations together instead of
1133
- // process leaf nodes individually
1134
- return childRows.reduce((sum, next) => {
1135
- const nextValue = next.getValue(columnId);
1136
- return sum + (typeof nextValue === 'number' ? nextValue : 0);
1137
- }, 0);
1138
- };
1139
- const min = (columnId, _leafRows, childRows) => {
1140
- let min;
1141
- childRows.forEach(row => {
1142
- const value = row.getValue(columnId);
1143
- if (value != null && (min > value || min === undefined && value >= value)) {
1144
- min = value;
1145
- }
1146
- });
1147
- return min;
1148
- };
1149
- const max = (columnId, _leafRows, childRows) => {
1150
- let max;
1151
- childRows.forEach(row => {
1152
- const value = row.getValue(columnId);
1153
- if (value != null && (max < value || max === undefined && value >= value)) {
1154
- max = value;
1155
- }
1156
- });
1157
- return max;
1158
- };
1159
- const extent = (columnId, _leafRows, childRows) => {
1160
- let min;
1161
- let max;
1162
- childRows.forEach(row => {
1163
- const value = row.getValue(columnId);
1164
- if (value != null) {
1165
- if (min === undefined) {
1166
- if (value >= value) min = max = value;
1167
- } else {
1168
- if (min > value) min = value;
1169
- if (max < value) max = value;
1170
- }
1171
- }
1172
- });
1173
- return [min, max];
1174
- };
1175
- const mean = (columnId, leafRows) => {
1176
- let count = 0;
1177
- let sum = 0;
1178
- leafRows.forEach(row => {
1179
- let value = row.getValue(columnId);
1180
- if (value != null && (value = +value) >= value) {
1181
- ++count, sum += value;
1182
- }
1183
- });
1184
- if (count) return sum / count;
1185
- return;
1186
- };
1187
- const median = (columnId, leafRows) => {
1188
- if (!leafRows.length) {
1189
- return;
1190
- }
1191
- const values = leafRows.map(row => row.getValue(columnId));
1192
- if (!isNumberArray(values)) {
1193
- return;
1194
- }
1195
- if (values.length === 1) {
1196
- return values[0];
1197
- }
1198
- const mid = Math.floor(values.length / 2);
1199
- const nums = values.sort((a, b) => a - b);
1200
- return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
1201
- };
1202
- const unique = (columnId, leafRows) => {
1203
- return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1204
- };
1205
- const uniqueCount = (columnId, leafRows) => {
1206
- return new Set(leafRows.map(d => d.getValue(columnId))).size;
1207
- };
1208
- const count = (_columnId, leafRows) => {
1209
- return leafRows.length;
1210
- };
1211
- const aggregationFns = {
1212
- sum,
1213
- min,
1214
- max,
1215
- extent,
1216
- mean,
1217
- median,
1218
- unique,
1219
- uniqueCount,
1220
- count
1221
- };
1222
1627
 
1223
1628
  //
1224
1629
 
1225
- const Grouping = {
1226
- getDefaultColumnDef: () => {
1227
- return {
1228
- aggregatedCell: props => {
1229
- var _toString, _props$getValue;
1230
- return (_toString = (_props$getValue = props.getValue()) == null || _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
1231
- },
1232
- aggregationFn: 'auto'
1233
- };
1234
- },
1630
+ const RowExpanding = {
1235
1631
  getInitialState: state => {
1236
1632
  return {
1237
- grouping: [],
1633
+ expanded: {},
1238
1634
  ...state
1239
1635
  };
1240
1636
  },
1241
1637
  getDefaultOptions: table => {
1242
1638
  return {
1243
- onGroupingChange: makeStateUpdater('grouping', table),
1244
- groupedColumnMode: 'reorder'
1639
+ onExpandedChange: makeStateUpdater('expanded', table),
1640
+ paginateExpandedRows: true
1245
1641
  };
1246
1642
  },
1247
- createColumn: (column, table) => {
1248
- column.toggleGrouping = () => {
1249
- table.setGrouping(old => {
1250
- // Find any existing grouping for this column
1251
- if (old != null && old.includes(column.id)) {
1252
- return old.filter(d => d !== column.id);
1253
- }
1254
- return [...(old != null ? old : []), column.id];
1255
- });
1256
- };
1257
- column.getCanGroup = () => {
1258
- var _ref, _ref2, _ref3, _column$columnDef$ena;
1259
- return (_ref = (_ref2 = (_ref3 = (_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) != null ? _ref3 : table.options.enableGrouping) != null ? _ref2 : true) != null ? _ref : !!column.accessorFn;
1260
- };
1261
- column.getIsGrouped = () => {
1262
- var _table$getState$group;
1263
- return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
1264
- };
1265
- column.getGroupedIndex = () => {
1266
- var _table$getState$group2;
1267
- return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
1268
- };
1269
- column.getToggleGroupingHandler = () => {
1270
- const canGroup = column.getCanGroup();
1271
- return () => {
1272
- if (!canGroup) return;
1273
- column.toggleGrouping();
1274
- };
1275
- };
1276
- column.getAutoAggregationFn = () => {
1277
- const firstRow = table.getCoreRowModel().flatRows[0];
1278
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1279
- if (typeof value === 'number') {
1280
- return aggregationFns.sum;
1643
+ createTable: table => {
1644
+ let registered = false;
1645
+ let queued = false;
1646
+ table._autoResetExpanded = () => {
1647
+ var _ref, _table$options$autoRe;
1648
+ if (!registered) {
1649
+ table._queue(() => {
1650
+ registered = true;
1651
+ });
1652
+ return;
1281
1653
  }
1282
- if (Object.prototype.toString.call(value) === '[object Date]') {
1283
- return aggregationFns.extent;
1654
+ if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
1655
+ if (queued) return;
1656
+ queued = true;
1657
+ table._queue(() => {
1658
+ table.resetExpanded();
1659
+ queued = false;
1660
+ });
1284
1661
  }
1285
1662
  };
1286
- column.getAggregationFn = () => {
1287
- var _table$options$aggreg, _table$options$aggreg2;
1288
- if (!column) {
1289
- throw new Error();
1663
+ table.setExpanded = updater => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater);
1664
+ table.toggleAllRowsExpanded = expanded => {
1665
+ if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
1666
+ table.setExpanded(true);
1667
+ } else {
1668
+ table.setExpanded({});
1290
1669
  }
1291
- 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];
1292
1670
  };
1293
- },
1294
- createTable: table => {
1295
- table.setGrouping = updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater);
1296
- table.resetGrouping = defaultState => {
1297
- var _table$initialState$g, _table$initialState;
1298
- table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
1671
+ table.resetExpanded = defaultState => {
1672
+ var _table$initialState$e, _table$initialState;
1673
+ table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
1299
1674
  };
1300
- table.getPreGroupedRowModel = () => table.getFilteredRowModel();
1301
- table.getGroupedRowModel = () => {
1302
- if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
1303
- table._getGroupedRowModel = table.options.getGroupedRowModel(table);
1304
- }
1305
- if (table.options.manualGrouping || !table._getGroupedRowModel) {
1306
- return table.getPreGroupedRowModel();
1307
- }
1308
- return table._getGroupedRowModel();
1675
+ table.getCanSomeRowsExpand = () => {
1676
+ return table.getPrePaginationRowModel().flatRows.some(row => row.getCanExpand());
1309
1677
  };
1310
- },
1311
- createRow: (row, table) => {
1312
- row.getIsGrouped = () => !!row.groupingColumnId;
1313
- row.getGroupingValue = columnId => {
1314
- if (row._groupingValuesCache.hasOwnProperty(columnId)) {
1315
- return row._groupingValuesCache[columnId];
1678
+ table.getToggleAllRowsExpandedHandler = () => {
1679
+ return e => {
1680
+ e.persist == null || e.persist();
1681
+ table.toggleAllRowsExpanded();
1682
+ };
1683
+ };
1684
+ table.getIsSomeRowsExpanded = () => {
1685
+ const expanded = table.getState().expanded;
1686
+ return expanded === true || Object.values(expanded).some(Boolean);
1687
+ };
1688
+ table.getIsAllRowsExpanded = () => {
1689
+ const expanded = table.getState().expanded;
1690
+
1691
+ // If expanded is true, save some cycles and return true
1692
+ if (typeof expanded === 'boolean') {
1693
+ return expanded === true;
1316
1694
  }
1317
- const column = table.getColumn(columnId);
1318
- if (!(column != null && column.columnDef.getGroupingValue)) {
1319
- return row.getValue(columnId);
1695
+ if (!Object.keys(expanded).length) {
1696
+ return false;
1320
1697
  }
1321
- row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(row.original);
1322
- return row._groupingValuesCache[columnId];
1323
- };
1324
- row._groupingValuesCache = {};
1325
- },
1326
- createCell: (cell, column, row, table) => {
1327
- cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
1328
- cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
1329
- cell.getIsAggregated = () => {
1330
- var _row$subRows;
1331
- return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
1332
- };
1333
- }
1334
- };
1335
- function orderColumns(leafColumns, grouping, groupedColumnMode) {
1336
- if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1337
- return leafColumns;
1338
- }
1339
- const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
1340
- if (groupedColumnMode === 'remove') {
1341
- return nonGroupingColumns;
1342
- }
1343
- const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
1344
- return [...groupingColumns, ...nonGroupingColumns];
1345
- }
1346
1698
 
1347
- //
1699
+ // If any row is not expanded, return false
1700
+ if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
1701
+ return false;
1702
+ }
1348
1703
 
1349
- const Ordering = {
1350
- getInitialState: state => {
1351
- return {
1352
- columnOrder: [],
1353
- ...state
1704
+ // They must all be expanded :shrug:
1705
+ return true;
1354
1706
  };
1355
- },
1356
- getDefaultOptions: table => {
1357
- return {
1358
- onColumnOrderChange: makeStateUpdater('columnOrder', table)
1707
+ table.getExpandedDepth = () => {
1708
+ let maxDepth = 0;
1709
+ const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
1710
+ rowIds.forEach(id => {
1711
+ const splitId = id.split('.');
1712
+ maxDepth = Math.max(maxDepth, splitId.length);
1713
+ });
1714
+ return maxDepth;
1715
+ };
1716
+ table.getPreExpandedRowModel = () => table.getSortedRowModel();
1717
+ table.getExpandedRowModel = () => {
1718
+ if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
1719
+ table._getExpandedRowModel = table.options.getExpandedRowModel(table);
1720
+ }
1721
+ if (table.options.manualExpanding || !table._getExpandedRowModel) {
1722
+ return table.getPreExpandedRowModel();
1723
+ }
1724
+ return table._getExpandedRowModel();
1359
1725
  };
1360
1726
  },
1361
- createColumn: (column, table) => {
1362
- column.getIndex = memo(position => [_getVisibleLeafColumns(table, position)], columns => columns.findIndex(d => d.id === column.id), getMemoOptions(table.options, 'debugColumns', 'getIndex'));
1363
- column.getIsFirstColumn = position => {
1364
- var _columns$;
1365
- const columns = _getVisibleLeafColumns(table, position);
1366
- return ((_columns$ = columns[0]) == null ? void 0 : _columns$.id) === column.id;
1727
+ createRow: (row, table) => {
1728
+ row.toggleExpanded = expanded => {
1729
+ table.setExpanded(old => {
1730
+ var _expanded;
1731
+ const exists = old === true ? true : !!(old != null && old[row.id]);
1732
+ let oldExpanded = {};
1733
+ if (old === true) {
1734
+ Object.keys(table.getRowModel().rowsById).forEach(rowId => {
1735
+ oldExpanded[rowId] = true;
1736
+ });
1737
+ } else {
1738
+ oldExpanded = old;
1739
+ }
1740
+ expanded = (_expanded = expanded) != null ? _expanded : !exists;
1741
+ if (!exists && expanded) {
1742
+ return {
1743
+ ...oldExpanded,
1744
+ [row.id]: true
1745
+ };
1746
+ }
1747
+ if (exists && !expanded) {
1748
+ const {
1749
+ [row.id]: _,
1750
+ ...rest
1751
+ } = oldExpanded;
1752
+ return rest;
1753
+ }
1754
+ return old;
1755
+ });
1367
1756
  };
1368
- column.getIsLastColumn = position => {
1369
- var _columns;
1370
- const columns = _getVisibleLeafColumns(table, position);
1371
- return ((_columns = columns[columns.length - 1]) == null ? void 0 : _columns.id) === column.id;
1757
+ row.getIsExpanded = () => {
1758
+ var _table$options$getIsR;
1759
+ const expanded = table.getState().expanded;
1760
+ 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]));
1372
1761
  };
1373
- },
1374
- createTable: table => {
1375
- table.setColumnOrder = updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater);
1376
- table.resetColumnOrder = defaultState => {
1377
- var _table$initialState$c;
1378
- table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
1762
+ row.getCanExpand = () => {
1763
+ var _table$options$getRow, _table$options$enable, _row$subRows;
1764
+ 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);
1379
1765
  };
1380
- table._getOrderColumnsFn = memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1381
- // Sort grouped columns to the start of the column list
1382
- // before the headers are built
1383
- let orderedColumns = [];
1384
-
1385
- // If there is no order, return the normal columns
1386
- if (!(columnOrder != null && columnOrder.length)) {
1387
- orderedColumns = columns;
1388
- } else {
1389
- const columnOrderCopy = [...columnOrder];
1390
-
1391
- // If there is an order, make a copy of the columns
1392
- const columnsCopy = [...columns];
1393
-
1394
- // And make a new ordered array of the columns
1395
-
1396
- // Loop over the columns and place them in order into the new array
1397
- while (columnsCopy.length && columnOrderCopy.length) {
1398
- const targetColumnId = columnOrderCopy.shift();
1399
- const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
1400
- if (foundIndex > -1) {
1401
- orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1402
- }
1403
- }
1404
-
1405
- // If there are any columns left, add them to the end
1406
- orderedColumns = [...orderedColumns, ...columnsCopy];
1766
+ row.getIsAllParentsExpanded = () => {
1767
+ let isFullyExpanded = true;
1768
+ let currentRow = row;
1769
+ while (isFullyExpanded && currentRow.parentId) {
1770
+ currentRow = table.getRow(currentRow.parentId, true);
1771
+ isFullyExpanded = currentRow.getIsExpanded();
1407
1772
  }
1408
- return orderColumns(orderedColumns, grouping, groupedColumnMode);
1409
- }, getMemoOptions(table.options, 'debugTable', '_getOrderColumnsFn'));
1773
+ return isFullyExpanded;
1774
+ };
1775
+ row.getToggleExpandedHandler = () => {
1776
+ const canExpand = row.getCanExpand();
1777
+ return () => {
1778
+ if (!canExpand) return;
1779
+ row.toggleExpanded();
1780
+ };
1781
+ };
1410
1782
  }
1411
1783
  };
1412
1784
 
@@ -1418,7 +1790,7 @@
1418
1790
  pageIndex: defaultPageIndex,
1419
1791
  pageSize: defaultPageSize
1420
1792
  });
1421
- const Pagination = {
1793
+ const RowPagination = {
1422
1794
  getInitialState: state => {
1423
1795
  return {
1424
1796
  ...state,
@@ -1565,88 +1937,34 @@
1565
1937
 
1566
1938
  //
1567
1939
 
1568
- const getDefaultColumnPinningState = () => ({
1569
- left: [],
1570
- right: []
1571
- });
1572
1940
  const getDefaultRowPinningState = () => ({
1573
1941
  top: [],
1574
1942
  bottom: []
1575
1943
  });
1576
- const Pinning = {
1944
+ const RowPinning = {
1577
1945
  getInitialState: state => {
1578
1946
  return {
1579
- columnPinning: getDefaultColumnPinningState(),
1580
1947
  rowPinning: getDefaultRowPinningState(),
1581
1948
  ...state
1582
1949
  };
1583
1950
  },
1584
1951
  getDefaultOptions: table => {
1585
1952
  return {
1586
- onColumnPinningChange: makeStateUpdater('columnPinning', table),
1587
1953
  onRowPinningChange: makeStateUpdater('rowPinning', table)
1588
1954
  };
1589
1955
  },
1590
- createColumn: (column, table) => {
1591
- column.pin = position => {
1592
- const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
1593
- table.setColumnPinning(old => {
1594
- var _old$left3, _old$right3;
1595
- if (position === 'right') {
1596
- var _old$left, _old$right;
1597
- return {
1598
- left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1599
- right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
1600
- };
1601
- }
1602
- if (position === 'left') {
1603
- var _old$left2, _old$right2;
1604
- return {
1605
- left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1606
- right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1607
- };
1608
- }
1609
- return {
1610
- left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1611
- right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1612
- };
1613
- });
1614
- };
1615
- column.getCanPin = () => {
1616
- const leafColumns = column.getLeafColumns();
1617
- return leafColumns.some(d => {
1618
- var _d$columnDef$enablePi, _ref, _table$options$enable;
1619
- 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);
1620
- });
1621
- };
1622
- column.getIsPinned = () => {
1623
- const leafColumnIds = column.getLeafColumns().map(d => d.id);
1624
- const {
1625
- left,
1626
- right
1627
- } = table.getState().columnPinning;
1628
- const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
1629
- const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
1630
- return isLeft ? 'left' : isRight ? 'right' : false;
1631
- };
1632
- column.getPinnedIndex = () => {
1633
- var _table$getState$colum, _table$getState$colum2;
1634
- const position = column.getIsPinned();
1635
- 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;
1636
- };
1637
- },
1638
1956
  createRow: (row, table) => {
1639
1957
  row.pin = (position, includeLeafRows, includeParentRows) => {
1640
- const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref2 => {
1958
+ const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref => {
1641
1959
  let {
1642
1960
  id
1643
- } = _ref2;
1961
+ } = _ref;
1644
1962
  return id;
1645
1963
  }) : [];
1646
- const parentRowIds = includeParentRows ? row.getParentRows().map(_ref3 => {
1964
+ const parentRowIds = includeParentRows ? row.getParentRows().map(_ref2 => {
1647
1965
  let {
1648
1966
  id
1649
- } = _ref3;
1967
+ } = _ref2;
1650
1968
  return id;
1651
1969
  }) : [];
1652
1970
  const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
@@ -1673,7 +1991,7 @@
1673
1991
  });
1674
1992
  };
1675
1993
  row.getCanPin = () => {
1676
- var _ref4;
1994
+ var _ref3;
1677
1995
  const {
1678
1996
  enableRowPinning,
1679
1997
  enablePinning
@@ -1681,7 +1999,7 @@
1681
1999
  if (typeof enableRowPinning === 'function') {
1682
2000
  return enableRowPinning(row);
1683
2001
  }
1684
- return (_ref4 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref4 : true;
2002
+ return (_ref3 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref3 : true;
1685
2003
  };
1686
2004
  row.getIsPinned = () => {
1687
2005
  const rowIds = [row.id];
@@ -1696,72 +2014,30 @@
1696
2014
  row.getPinnedIndex = () => {
1697
2015
  var _table$_getPinnedRows, _visiblePinnedRowIds$;
1698
2016
  const position = row.getIsPinned();
1699
- if (!position) return -1;
1700
- const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref5 => {
1701
- let {
1702
- id
1703
- } = _ref5;
1704
- return id;
1705
- });
1706
- return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1707
- };
1708
- row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1709
- const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1710
- return allCells.filter(d => !leftAndRight.includes(d.column.id));
1711
- }, getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells'));
1712
- row.getLeftVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left], (allCells, left) => {
1713
- const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1714
- ...d,
1715
- position: 'left'
1716
- }));
1717
- return cells;
1718
- }, getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells'));
1719
- row.getRightVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1720
- const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1721
- ...d,
1722
- position: 'right'
1723
- }));
1724
- return cells;
1725
- }, getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells'));
1726
- },
1727
- createTable: table => {
1728
- table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1729
- table.resetColumnPinning = defaultState => {
1730
- var _table$initialState$c, _table$initialState;
1731
- return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1732
- };
1733
- table.getIsSomeColumnsPinned = position => {
1734
- var _pinningState$positio;
1735
- const pinningState = table.getState().columnPinning;
1736
- if (!position) {
1737
- var _pinningState$left, _pinningState$right;
1738
- return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1739
- }
1740
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
2017
+ if (!position) return -1;
2018
+ const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref4 => {
2019
+ let {
2020
+ id
2021
+ } = _ref4;
2022
+ return id;
2023
+ });
2024
+ return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1741
2025
  };
1742
- table.getLeftLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1743
- return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1744
- }, getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns'));
1745
- table.getRightLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1746
- return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1747
- }, getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns'));
1748
- table.getCenterLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1749
- const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1750
- return allColumns.filter(d => !leftAndRight.includes(d.id));
1751
- }, getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns'));
2026
+ },
2027
+ createTable: table => {
1752
2028
  table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
1753
2029
  table.resetRowPinning = defaultState => {
1754
- var _table$initialState$r, _table$initialState2;
1755
- return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState2 = table.initialState) == null ? void 0 : _table$initialState2.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
2030
+ var _table$initialState$r, _table$initialState;
2031
+ return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
1756
2032
  };
1757
2033
  table.getIsSomeRowsPinned = position => {
1758
- var _pinningState$positio2;
2034
+ var _pinningState$positio;
1759
2035
  const pinningState = table.getState().rowPinning;
1760
2036
  if (!position) {
1761
2037
  var _pinningState$top, _pinningState$bottom;
1762
2038
  return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
1763
2039
  }
1764
- return Boolean((_pinningState$positio2 = pinningState[position]) == null ? void 0 : _pinningState$positio2.length);
2040
+ return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1765
2041
  };
1766
2042
  table._getPinnedRows = memo(position => [table.getRowModel().rows, table.getState().rowPinning[position], position], (visibleRows, pinnedRowIds, position) => {
1767
2043
  var _table$options$keepPi;
@@ -2267,7 +2543,7 @@
2267
2543
 
2268
2544
  //
2269
2545
 
2270
- const Sorting = {
2546
+ const RowSorting = {
2271
2547
  getInitialState: state => {
2272
2548
  return {
2273
2549
  sorting: [],
@@ -2474,99 +2750,22 @@
2474
2750
  }
2475
2751
  };
2476
2752
 
2477
- //
2478
-
2479
- const Visibility = {
2480
- getInitialState: state => {
2481
- return {
2482
- columnVisibility: {},
2483
- ...state
2484
- };
2485
- },
2486
- getDefaultOptions: table => {
2487
- return {
2488
- onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
2489
- };
2490
- },
2491
- createColumn: (column, table) => {
2492
- column.toggleVisibility = value => {
2493
- if (column.getCanHide()) {
2494
- table.setColumnVisibility(old => ({
2495
- ...old,
2496
- [column.id]: value != null ? value : !column.getIsVisible()
2497
- }));
2498
- }
2499
- };
2500
- column.getIsVisible = () => {
2501
- var _ref, _table$getState$colum;
2502
- const childColumns = column.columns;
2503
- 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;
2504
- };
2505
- column.getCanHide = () => {
2506
- var _column$columnDef$ena, _table$options$enable;
2507
- return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
2508
- };
2509
- column.getToggleVisibilityHandler = () => {
2510
- return e => {
2511
- column.toggleVisibility == null || column.toggleVisibility(e.target.checked);
2512
- };
2513
- };
2514
- },
2515
- createRow: (row, table) => {
2516
- row._getAllVisibleCells = memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
2517
- return cells.filter(cell => cell.column.getIsVisible());
2518
- }, getMemoOptions(table.options, 'debugRows', '_getAllVisibleCells'));
2519
- row.getVisibleCells = memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], getMemoOptions(table.options, 'debugRows', 'getVisibleCells'));
2520
- },
2521
- createTable: table => {
2522
- const makeVisibleColumnsMethod = (key, getColumns) => {
2523
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
2524
- return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
2525
- }, getMemoOptions(table.options, 'debugColumns', key));
2526
- };
2527
- table.getVisibleFlatColumns = makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns());
2528
- table.getVisibleLeafColumns = makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns());
2529
- table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns());
2530
- table.getRightVisibleLeafColumns = makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns());
2531
- table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns());
2532
- table.setColumnVisibility = updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater);
2533
- table.resetColumnVisibility = defaultState => {
2534
- var _table$initialState$c;
2535
- table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
2536
- };
2537
- table.toggleAllColumnsVisible = value => {
2538
- var _value;
2539
- value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
2540
- table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
2541
- ...obj,
2542
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
2543
- }), {}));
2544
- };
2545
- table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible()));
2546
- table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible());
2547
- table.getToggleAllColumnsVisibilityHandler = () => {
2548
- return e => {
2549
- var _target;
2550
- table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
2551
- };
2552
- };
2553
- }
2554
- };
2555
- function _getVisibleLeafColumns(table, position) {
2556
- return !position ? table.getVisibleLeafColumns() : position === 'center' ? table.getCenterVisibleLeafColumns() : position === 'left' ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
2557
- }
2558
-
2559
- const features = [Headers, Visibility, Ordering, Pinning, Filters, Sorting, Grouping, Expanding, Pagination, RowSelection, ColumnSizing];
2753
+ const builtInFeatures = [Headers, ColumnVisibility, ColumnOrdering, ColumnPinning, ColumnFaceting, ColumnFiltering, GlobalFiltering,
2754
+ //depends on ColumnFiltering and ColumnFaceting
2755
+ RowSorting, ColumnGrouping,
2756
+ //depends on RowSorting
2757
+ RowExpanding, RowPagination, RowPinning, RowSelection, ColumnSizing];
2560
2758
 
2561
2759
  //
2562
2760
 
2563
2761
  function createTable(options) {
2564
- var _options$initialState;
2565
- if (options.debugAll || options.debugTable) {
2762
+ var _options$_features, _options$initialState;
2763
+ if ((options.debugAll || options.debugTable)) {
2566
2764
  console.info('Creating Table Instance...');
2567
2765
  }
2766
+ const _features = [...builtInFeatures, ...((_options$_features = options._features) != null ? _options$_features : [])];
2568
2767
  let table = {
2569
- _features: features
2768
+ _features
2570
2769
  };
2571
2770
  const defaultOptions = table._features.reduce((obj, feature) => {
2572
2771
  return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
@@ -2592,7 +2791,7 @@
2592
2791
  const queued = [];
2593
2792
  let queuedTimeout = false;
2594
2793
  const coreInstance = {
2595
- _features: features,
2794
+ _features,
2596
2795
  options: {
2597
2796
  ...defaultOptions,
2598
2797
  ...options
@@ -2655,232 +2854,77 @@
2655
2854
  }
2656
2855
  }
2657
2856
  }
2658
- return row;
2659
- },
2660
- _getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
2661
- var _defaultColumn;
2662
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2663
- return {
2664
- header: props => {
2665
- const resolvedColumnDef = props.header.column.columnDef;
2666
- if (resolvedColumnDef.accessorKey) {
2667
- return resolvedColumnDef.accessorKey;
2668
- }
2669
- if (resolvedColumnDef.accessorFn) {
2670
- return resolvedColumnDef.id;
2671
- }
2672
- return null;
2673
- },
2674
- // footer: props => props.header.column.id,
2675
- cell: props => {
2676
- var _props$renderValue$to, _props$renderValue;
2677
- return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null || _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
2678
- },
2679
- ...table._features.reduce((obj, feature) => {
2680
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2681
- }, {}),
2682
- ...defaultColumn
2683
- };
2684
- }, getMemoOptions(options, 'debugColumns', '_getDefaultColumnDef')),
2685
- _getColumnDefs: () => table.options.columns,
2686
- getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
2687
- const recurseColumns = function (columnDefs, parent, depth) {
2688
- if (depth === void 0) {
2689
- depth = 0;
2690
- }
2691
- return columnDefs.map(columnDef => {
2692
- const column = createColumn(table, columnDef, depth, parent);
2693
- const groupingColumnDef = columnDef;
2694
- column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
2695
- return column;
2696
- });
2697
- };
2698
- return recurseColumns(columnDefs);
2699
- }, getMemoOptions(options, 'debugColumns', 'getAllColumns')),
2700
- getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
2701
- return allColumns.flatMap(column => {
2702
- return column.getFlatColumns();
2703
- });
2704
- }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumns')),
2705
- _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
2706
- return flatColumns.reduce((acc, column) => {
2707
- acc[column.id] = column;
2708
- return acc;
2709
- }, {});
2710
- }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumnsById')),
2711
- getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2712
- let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2713
- return orderColumns(leafColumns);
2714
- }, getMemoOptions(options, 'debugColumns', 'getAllLeafColumns')),
2715
- getColumn: columnId => {
2716
- const column = table._getAllFlatColumnsById()[columnId];
2717
- if (!column) {
2718
- console.error(`[Table] Column with id '${columnId}' does not exist.`);
2719
- }
2720
- return column;
2721
- }
2722
- };
2723
- Object.assign(table, coreInstance);
2724
- for (let index = 0; index < table._features.length; index++) {
2725
- const feature = table._features[index];
2726
- feature == null || feature.createTable == null || feature.createTable(table);
2727
- }
2728
- return table;
2729
- }
2730
-
2731
- function createCell(table, row, column, columnId) {
2732
- const getRenderValue = () => {
2733
- var _cell$getValue;
2734
- return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
2735
- };
2736
- const cell = {
2737
- id: `${row.id}_${column.id}`,
2738
- row,
2739
- column,
2740
- getValue: () => row.getValue(columnId),
2741
- renderValue: getRenderValue,
2742
- getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
2743
- table,
2744
- column,
2745
- row,
2746
- cell: cell,
2747
- getValue: cell.getValue,
2748
- renderValue: cell.renderValue
2749
- }), getMemoOptions(table.options, 'debugCells', 'cell.getContext'))
2750
- };
2751
- table._features.forEach(feature => {
2752
- feature.createCell == null || feature.createCell(cell, column, row, table);
2753
- }, {});
2754
- return cell;
2755
- }
2756
-
2757
- const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
2758
- let row = {
2759
- id,
2760
- index: rowIndex,
2761
- original,
2762
- depth,
2763
- parentId,
2764
- _valuesCache: {},
2765
- _uniqueValuesCache: {},
2766
- getValue: columnId => {
2767
- if (row._valuesCache.hasOwnProperty(columnId)) {
2768
- return row._valuesCache[columnId];
2769
- }
2770
- const column = table.getColumn(columnId);
2771
- if (!(column != null && column.accessorFn)) {
2772
- return undefined;
2773
- }
2774
- row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
2775
- return row._valuesCache[columnId];
2776
- },
2777
- getUniqueValues: columnId => {
2778
- if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
2779
- return row._uniqueValuesCache[columnId];
2780
- }
2781
- const column = table.getColumn(columnId);
2782
- if (!(column != null && column.accessorFn)) {
2783
- return undefined;
2784
- }
2785
- if (!column.columnDef.getUniqueValues) {
2786
- row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
2787
- return row._uniqueValuesCache[columnId];
2788
- }
2789
- row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
2790
- return row._uniqueValuesCache[columnId];
2791
- },
2792
- renderValue: columnId => {
2793
- var _row$getValue;
2794
- return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
2795
- },
2796
- subRows: subRows != null ? subRows : [],
2797
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
2798
- getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : undefined,
2799
- getParentRows: () => {
2800
- let parentRows = [];
2801
- let currentRow = row;
2802
- while (true) {
2803
- const parentRow = currentRow.getParentRow();
2804
- if (!parentRow) break;
2805
- parentRows.push(parentRow);
2806
- currentRow = parentRow;
2807
- }
2808
- return parentRows.reverse();
2809
- },
2810
- getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
2811
- return leafColumns.map(column => {
2812
- return createCell(table, row, column, column.id);
2857
+ return row;
2858
+ },
2859
+ _getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
2860
+ var _defaultColumn;
2861
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2862
+ return {
2863
+ header: props => {
2864
+ const resolvedColumnDef = props.header.column.columnDef;
2865
+ if (resolvedColumnDef.accessorKey) {
2866
+ return resolvedColumnDef.accessorKey;
2867
+ }
2868
+ if (resolvedColumnDef.accessorFn) {
2869
+ return resolvedColumnDef.id;
2870
+ }
2871
+ return null;
2872
+ },
2873
+ // footer: props => props.header.column.id,
2874
+ cell: props => {
2875
+ var _props$renderValue$to, _props$renderValue;
2876
+ return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null || _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
2877
+ },
2878
+ ...table._features.reduce((obj, feature) => {
2879
+ return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2880
+ }, {}),
2881
+ ...defaultColumn
2882
+ };
2883
+ }, getMemoOptions(options, 'debugColumns', '_getDefaultColumnDef')),
2884
+ _getColumnDefs: () => table.options.columns,
2885
+ getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
2886
+ const recurseColumns = function (columnDefs, parent, depth) {
2887
+ if (depth === void 0) {
2888
+ depth = 0;
2889
+ }
2890
+ return columnDefs.map(columnDef => {
2891
+ const column = createColumn(table, columnDef, depth, parent);
2892
+ const groupingColumnDef = columnDef;
2893
+ column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
2894
+ return column;
2895
+ });
2896
+ };
2897
+ return recurseColumns(columnDefs);
2898
+ }, getMemoOptions(options, 'debugColumns', 'getAllColumns')),
2899
+ getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
2900
+ return allColumns.flatMap(column => {
2901
+ return column.getFlatColumns();
2813
2902
  });
2814
- }, getMemoOptions(table.options, 'debugRows', 'getAllCells')),
2815
- _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
2816
- return allCells.reduce((acc, cell) => {
2817
- acc[cell.column.id] = cell;
2903
+ }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumns')),
2904
+ _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
2905
+ return flatColumns.reduce((acc, column) => {
2906
+ acc[column.id] = column;
2818
2907
  return acc;
2819
2908
  }, {});
2820
- }, getMemoOptions(table.options, 'debugRows', 'getAllCellsByColumnId'))
2909
+ }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumnsById')),
2910
+ getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2911
+ let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2912
+ return orderColumns(leafColumns);
2913
+ }, getMemoOptions(options, 'debugColumns', 'getAllLeafColumns')),
2914
+ getColumn: columnId => {
2915
+ const column = table._getAllFlatColumnsById()[columnId];
2916
+ if (!column) {
2917
+ console.error(`[Table] Column with id '${columnId}' does not exist.`);
2918
+ }
2919
+ return column;
2920
+ }
2821
2921
  };
2822
- for (let i = 0; i < table._features.length; i++) {
2823
- const feature = table._features[i];
2824
- feature == null || feature.createRow == null || feature.createRow(row, table);
2922
+ Object.assign(table, coreInstance);
2923
+ for (let index = 0; index < table._features.length; index++) {
2924
+ const feature = table._features[index];
2925
+ feature == null || feature.createTable == null || feature.createTable(table);
2825
2926
  }
2826
- return row;
2827
- };
2828
-
2829
- // type Person = {
2830
- // firstName: string
2831
- // lastName: string
2832
- // age: number
2833
- // visits: number
2834
- // status: string
2835
- // progress: number
2836
- // createdAt: Date
2837
- // nested: {
2838
- // foo: [
2839
- // {
2840
- // bar: 'bar'
2841
- // }
2842
- // ]
2843
- // bar: { subBar: boolean }[]
2844
- // baz: {
2845
- // foo: 'foo'
2846
- // bar: {
2847
- // baz: 'baz'
2848
- // }
2849
- // }
2850
- // }
2851
- // }
2852
-
2853
- // const test: DeepKeys<Person> = 'nested.foo.0.bar'
2854
- // const test2: DeepKeys<Person> = 'nested.bar'
2855
-
2856
- // const helper = createColumnHelper<Person>()
2857
-
2858
- // helper.accessor('nested.foo', {
2859
- // cell: info => info.getValue(),
2860
- // })
2861
-
2862
- // helper.accessor('nested.foo.0.bar', {
2863
- // cell: info => info.getValue(),
2864
- // })
2865
-
2866
- // helper.accessor('nested.bar', {
2867
- // cell: info => info.getValue(),
2868
- // })
2869
-
2870
- function createColumnHelper() {
2871
- return {
2872
- accessor: (accessor, column) => {
2873
- return typeof accessor === 'function' ? {
2874
- ...column,
2875
- accessorFn: accessor
2876
- } : {
2877
- ...column,
2878
- accessorKey: accessor
2879
- };
2880
- },
2881
- display: column => column,
2882
- group: column => column
2883
- };
2927
+ return table;
2884
2928
  }
2885
2929
 
2886
2930
  function getCoreRowModel() {
@@ -2931,6 +2975,62 @@
2931
2975
  }, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
2932
2976
  }
2933
2977
 
2978
+ function getExpandedRowModel() {
2979
+ return table => memo(() => [table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
2980
+ if (!rowModel.rows.length || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
2981
+ return rowModel;
2982
+ }
2983
+ if (!paginateExpandedRows) {
2984
+ // Only expand rows at this point if they are being paginated
2985
+ return rowModel;
2986
+ }
2987
+ return expandRows(rowModel);
2988
+ }, getMemoOptions(table.options, 'debugTable', 'getExpandedRowModel'));
2989
+ }
2990
+ function expandRows(rowModel) {
2991
+ const expandedRows = [];
2992
+ const handleRow = row => {
2993
+ var _row$subRows;
2994
+ expandedRows.push(row);
2995
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
2996
+ row.subRows.forEach(handleRow);
2997
+ }
2998
+ };
2999
+ rowModel.rows.forEach(handleRow);
3000
+ return {
3001
+ rows: expandedRows,
3002
+ flatRows: rowModel.flatRows,
3003
+ rowsById: rowModel.rowsById
3004
+ };
3005
+ }
3006
+
3007
+ function getFacetedMinMaxValues() {
3008
+ return (table, columnId) => memo(() => {
3009
+ var _table$getColumn;
3010
+ return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3011
+ }, facetedRowModel => {
3012
+ var _facetedRowModel$flat;
3013
+ if (!facetedRowModel) return undefined;
3014
+ const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3015
+ if (typeof firstValue === 'undefined') {
3016
+ return undefined;
3017
+ }
3018
+ let facetedMinMaxValues = [firstValue, firstValue];
3019
+ for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3020
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3021
+ for (let j = 0; j < values.length; j++) {
3022
+ const value = values[j];
3023
+ if (value < facetedMinMaxValues[0]) {
3024
+ facetedMinMaxValues[0] = value;
3025
+ } else if (value > facetedMinMaxValues[1]) {
3026
+ facetedMinMaxValues[1] = value;
3027
+ }
3028
+ }
3029
+ }
3030
+ return facetedMinMaxValues;
3031
+ }, getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues'));
3032
+ }
3033
+
2934
3034
  function filterRows(rows, filterRowImpl, table) {
2935
3035
  if (table.options.filterFromLeafRows) {
2936
3036
  return filterRowModelFromLeafs(rows, filterRowImpl, table);
@@ -3026,6 +3126,48 @@
3026
3126
  };
3027
3127
  }
3028
3128
 
3129
+ function getFacetedRowModel() {
3130
+ return (table, columnId) => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter, table.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
3131
+ if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3132
+ return preRowModel;
3133
+ }
3134
+ const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
3135
+ const filterRowsImpl = row => {
3136
+ // Horizontally filter rows through each column
3137
+ for (let i = 0; i < filterableIds.length; i++) {
3138
+ if (row.columnFilters[filterableIds[i]] === false) {
3139
+ return false;
3140
+ }
3141
+ }
3142
+ return true;
3143
+ };
3144
+ return filterRows(preRowModel.rows, filterRowsImpl, table);
3145
+ }, getMemoOptions(table.options, 'debugTable', 'getFacetedRowModel'));
3146
+ }
3147
+
3148
+ function getFacetedUniqueValues() {
3149
+ return (table, columnId) => memo(() => {
3150
+ var _table$getColumn;
3151
+ return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3152
+ }, facetedRowModel => {
3153
+ if (!facetedRowModel) return new Map();
3154
+ let facetedUniqueValues = new Map();
3155
+ for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3156
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3157
+ for (let j = 0; j < values.length; j++) {
3158
+ const value = values[j];
3159
+ if (facetedUniqueValues.has(value)) {
3160
+ var _facetedUniqueValues$;
3161
+ facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
3162
+ } else {
3163
+ facetedUniqueValues.set(value, 1);
3164
+ }
3165
+ }
3166
+ }
3167
+ return facetedUniqueValues;
3168
+ }, getMemoOptions(table.options, 'debugTable', `getFacetedUniqueValues_${columnId}`));
3169
+ }
3170
+
3029
3171
  function getFilteredRowModel() {
3030
3172
  return table => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter], (rowModel, columnFilters, globalFilter) => {
3031
3173
  if (!rowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
@@ -3098,34 +3240,13 @@
3098
3240
  })) {
3099
3241
  row.columnFilters.__global__ = true;
3100
3242
  break;
3101
- }
3102
- }
3103
- if (row.columnFilters.__global__ !== true) {
3104
- row.columnFilters.__global__ = false;
3105
- }
3106
- }
3107
- }
3108
- const filterRowsImpl = row => {
3109
- // Horizontally filter rows through each column
3110
- for (let i = 0; i < filterableIds.length; i++) {
3111
- if (row.columnFilters[filterableIds[i]] === false) {
3112
- return false;
3113
- }
3114
- }
3115
- return true;
3116
- };
3117
-
3118
- // Filter final rows using all of the active filters
3119
- return filterRows(rowModel.rows, filterRowsImpl, table);
3120
- }, getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () => table._autoResetPageIndex()));
3121
- }
3122
-
3123
- function getFacetedRowModel() {
3124
- return (table, columnId) => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter, table.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
3125
- if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3126
- return preRowModel;
3243
+ }
3244
+ }
3245
+ if (row.columnFilters.__global__ !== true) {
3246
+ row.columnFilters.__global__ = false;
3247
+ }
3248
+ }
3127
3249
  }
3128
- const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
3129
3250
  const filterRowsImpl = row => {
3130
3251
  // Horizontally filter rows through each column
3131
3252
  for (let i = 0; i < filterableIds.length; i++) {
@@ -3135,141 +3256,10 @@
3135
3256
  }
3136
3257
  return true;
3137
3258
  };
3138
- return filterRows(preRowModel.rows, filterRowsImpl, table);
3139
- }, getMemoOptions(table.options, 'debugTable', 'getFacetedRowModel'));
3140
- }
3141
-
3142
- function getFacetedUniqueValues() {
3143
- return (table, columnId) => memo(() => {
3144
- var _table$getColumn;
3145
- return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3146
- }, facetedRowModel => {
3147
- if (!facetedRowModel) return new Map();
3148
- let facetedUniqueValues = new Map();
3149
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3150
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3151
- for (let j = 0; j < values.length; j++) {
3152
- const value = values[j];
3153
- if (facetedUniqueValues.has(value)) {
3154
- var _facetedUniqueValues$;
3155
- facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
3156
- } else {
3157
- facetedUniqueValues.set(value, 1);
3158
- }
3159
- }
3160
- }
3161
- return facetedUniqueValues;
3162
- }, getMemoOptions(table.options, 'debugTable', `getFacetedUniqueValues_${columnId}`));
3163
- }
3164
-
3165
- function getFacetedMinMaxValues() {
3166
- return (table, columnId) => memo(() => {
3167
- var _table$getColumn;
3168
- return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3169
- }, facetedRowModel => {
3170
- var _facetedRowModel$flat;
3171
- if (!facetedRowModel) return undefined;
3172
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3173
- if (typeof firstValue === 'undefined') {
3174
- return undefined;
3175
- }
3176
- let facetedMinMaxValues = [firstValue, firstValue];
3177
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3178
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3179
- for (let j = 0; j < values.length; j++) {
3180
- const value = values[j];
3181
- if (value < facetedMinMaxValues[0]) {
3182
- facetedMinMaxValues[0] = value;
3183
- } else if (value > facetedMinMaxValues[1]) {
3184
- facetedMinMaxValues[1] = value;
3185
- }
3186
- }
3187
- }
3188
- return facetedMinMaxValues;
3189
- }, getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues'));
3190
- }
3191
-
3192
- function getSortedRowModel() {
3193
- return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3194
- if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3195
- return rowModel;
3196
- }
3197
- const sortingState = table.getState().sorting;
3198
- const sortedFlatRows = [];
3199
-
3200
- // Filter out sortings that correspond to non existing columns
3201
- const availableSorting = sortingState.filter(sort => {
3202
- var _table$getColumn;
3203
- return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
3204
- });
3205
- const columnInfoById = {};
3206
- availableSorting.forEach(sortEntry => {
3207
- const column = table.getColumn(sortEntry.id);
3208
- if (!column) return;
3209
- columnInfoById[sortEntry.id] = {
3210
- sortUndefined: column.columnDef.sortUndefined,
3211
- invertSorting: column.columnDef.invertSorting,
3212
- sortingFn: column.getSortingFn()
3213
- };
3214
- });
3215
- const sortData = rows => {
3216
- // This will also perform a stable sorting using the row index
3217
- // if needed.
3218
- const sortedData = rows.map(row => ({
3219
- ...row
3220
- }));
3221
- sortedData.sort((rowA, rowB) => {
3222
- for (let i = 0; i < availableSorting.length; i += 1) {
3223
- var _sortEntry$desc;
3224
- const sortEntry = availableSorting[i];
3225
- const columnInfo = columnInfoById[sortEntry.id];
3226
- const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
3227
- let sortInt = 0;
3228
-
3229
- // All sorting ints should always return in ascending order
3230
- if (columnInfo.sortUndefined) {
3231
- const aValue = rowA.getValue(sortEntry.id);
3232
- const bValue = rowB.getValue(sortEntry.id);
3233
- const aUndefined = aValue === undefined;
3234
- const bUndefined = bValue === undefined;
3235
- if (aUndefined || bUndefined) {
3236
- sortInt = aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
3237
- }
3238
- }
3239
- if (sortInt === 0) {
3240
- sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3241
- }
3242
-
3243
- // If sorting is non-zero, take care of desc and inversion
3244
- if (sortInt !== 0) {
3245
- if (isDesc) {
3246
- sortInt *= -1;
3247
- }
3248
- if (columnInfo.invertSorting) {
3249
- sortInt *= -1;
3250
- }
3251
- return sortInt;
3252
- }
3253
- }
3254
- return rowA.index - rowB.index;
3255
- });
3256
3259
 
3257
- // If there are sub-rows, sort them
3258
- sortedData.forEach(row => {
3259
- var _row$subRows;
3260
- sortedFlatRows.push(row);
3261
- if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3262
- row.subRows = sortData(row.subRows);
3263
- }
3264
- });
3265
- return sortedData;
3266
- };
3267
- return {
3268
- rows: sortData(rowModel.rows),
3269
- flatRows: sortedFlatRows,
3270
- rowsById: rowModel.rowsById
3271
- };
3272
- }, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
3260
+ // Filter final rows using all of the active filters
3261
+ return filterRows(rowModel.rows, filterRowsImpl, table);
3262
+ }, getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () => table._autoResetPageIndex()));
3273
3263
  }
3274
3264
 
3275
3265
  function getGroupedRowModel() {
@@ -3405,35 +3395,6 @@
3405
3395
  }, groupMap);
3406
3396
  }
3407
3397
 
3408
- function getExpandedRowModel() {
3409
- return table => memo(() => [table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
3410
- if (!rowModel.rows.length || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
3411
- return rowModel;
3412
- }
3413
- if (!paginateExpandedRows) {
3414
- // Only expand rows at this point if they are being paginated
3415
- return rowModel;
3416
- }
3417
- return expandRows(rowModel);
3418
- }, getMemoOptions(table.options, 'debugTable', 'getExpandedRowModel'));
3419
- }
3420
- function expandRows(rowModel) {
3421
- const expandedRows = [];
3422
- const handleRow = row => {
3423
- var _row$subRows;
3424
- expandedRows.push(row);
3425
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3426
- row.subRows.forEach(handleRow);
3427
- }
3428
- };
3429
- rowModel.rows.forEach(handleRow);
3430
- return {
3431
- rows: expandedRows,
3432
- flatRows: rowModel.flatRows,
3433
- rowsById: rowModel.rowsById
3434
- };
3435
- }
3436
-
3437
3398
  function getPaginationRowModel(opts) {
3438
3399
  return table => memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
3439
3400
  if (!rowModel.rows.length) {
@@ -3477,6 +3438,89 @@
3477
3438
  }, getMemoOptions(table.options, 'debugTable', 'getPaginationRowModel'));
3478
3439
  }
3479
3440
 
3441
+ function getSortedRowModel() {
3442
+ return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3443
+ if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3444
+ return rowModel;
3445
+ }
3446
+ const sortingState = table.getState().sorting;
3447
+ const sortedFlatRows = [];
3448
+
3449
+ // Filter out sortings that correspond to non existing columns
3450
+ const availableSorting = sortingState.filter(sort => {
3451
+ var _table$getColumn;
3452
+ return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
3453
+ });
3454
+ const columnInfoById = {};
3455
+ availableSorting.forEach(sortEntry => {
3456
+ const column = table.getColumn(sortEntry.id);
3457
+ if (!column) return;
3458
+ columnInfoById[sortEntry.id] = {
3459
+ sortUndefined: column.columnDef.sortUndefined,
3460
+ invertSorting: column.columnDef.invertSorting,
3461
+ sortingFn: column.getSortingFn()
3462
+ };
3463
+ });
3464
+ const sortData = rows => {
3465
+ // This will also perform a stable sorting using the row index
3466
+ // if needed.
3467
+ const sortedData = rows.map(row => ({
3468
+ ...row
3469
+ }));
3470
+ sortedData.sort((rowA, rowB) => {
3471
+ for (let i = 0; i < availableSorting.length; i += 1) {
3472
+ var _sortEntry$desc;
3473
+ const sortEntry = availableSorting[i];
3474
+ const columnInfo = columnInfoById[sortEntry.id];
3475
+ const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
3476
+ let sortInt = 0;
3477
+
3478
+ // All sorting ints should always return in ascending order
3479
+ if (columnInfo.sortUndefined) {
3480
+ const aValue = rowA.getValue(sortEntry.id);
3481
+ const bValue = rowB.getValue(sortEntry.id);
3482
+ const aUndefined = aValue === undefined;
3483
+ const bUndefined = bValue === undefined;
3484
+ if (aUndefined || bUndefined) {
3485
+ sortInt = aUndefined && bUndefined ? 0 : aUndefined ? columnInfo.sortUndefined : -columnInfo.sortUndefined;
3486
+ }
3487
+ }
3488
+ if (sortInt === 0) {
3489
+ sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3490
+ }
3491
+
3492
+ // If sorting is non-zero, take care of desc and inversion
3493
+ if (sortInt !== 0) {
3494
+ if (isDesc) {
3495
+ sortInt *= -1;
3496
+ }
3497
+ if (columnInfo.invertSorting) {
3498
+ sortInt *= -1;
3499
+ }
3500
+ return sortInt;
3501
+ }
3502
+ }
3503
+ return rowA.index - rowB.index;
3504
+ });
3505
+
3506
+ // If there are sub-rows, sort them
3507
+ sortedData.forEach(row => {
3508
+ var _row$subRows;
3509
+ sortedFlatRows.push(row);
3510
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3511
+ row.subRows = sortData(row.subRows);
3512
+ }
3513
+ });
3514
+ return sortedData;
3515
+ };
3516
+ return {
3517
+ rows: sortData(rowModel.rows),
3518
+ flatRows: sortedFlatRows,
3519
+ rowsById: rowModel.rowsById
3520
+ };
3521
+ }, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
3522
+ }
3523
+
3480
3524
  /* src/placeholder.svelte generated by Svelte v4.2.8 */
3481
3525
 
3482
3526
  function create_fragment$1(ctx) {
@@ -3662,17 +3706,20 @@
3662
3706
  return tableReadable;
3663
3707
  }
3664
3708
 
3709
+ exports.ColumnFaceting = ColumnFaceting;
3710
+ exports.ColumnFiltering = ColumnFiltering;
3711
+ exports.ColumnGrouping = ColumnGrouping;
3712
+ exports.ColumnOrdering = ColumnOrdering;
3713
+ exports.ColumnPinning = ColumnPinning;
3665
3714
  exports.ColumnSizing = ColumnSizing;
3666
- exports.Expanding = Expanding;
3667
- exports.Filters = Filters;
3668
- exports.Grouping = Grouping;
3715
+ exports.ColumnVisibility = ColumnVisibility;
3716
+ exports.GlobalFiltering = GlobalFiltering;
3669
3717
  exports.Headers = Headers;
3670
- exports.Ordering = Ordering;
3671
- exports.Pagination = Pagination;
3672
- exports.Pinning = Pinning;
3718
+ exports.RowExpanding = RowExpanding;
3719
+ exports.RowPagination = RowPagination;
3720
+ exports.RowPinning = RowPinning;
3673
3721
  exports.RowSelection = RowSelection;
3674
- exports.Sorting = Sorting;
3675
- exports.Visibility = Visibility;
3722
+ exports.RowSorting = RowSorting;
3676
3723
  exports._getVisibleLeafColumns = _getVisibleLeafColumns;
3677
3724
  exports.aggregationFns = aggregationFns;
3678
3725
  exports.buildHeaderGroups = buildHeaderGroups;