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