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