@tanstack/react-table 8.0.0-alpha.2 → 8.0.0-alpha.5

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 (99) hide show
  1. package/build/cjs/core.js +85 -52
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +11 -6
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +2 -16
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +23 -2
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +54 -5
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +23 -2
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +87 -24
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/Ordering.js +4 -1
  16. package/build/cjs/features/Ordering.js.map +1 -1
  17. package/build/cjs/features/Pagination.js +198 -0
  18. package/build/cjs/features/Pagination.js.map +1 -0
  19. package/build/cjs/features/Pinning.js +0 -14
  20. package/build/cjs/features/Pinning.js.map +1 -1
  21. package/build/cjs/features/RowSelection.js +541 -0
  22. package/build/cjs/features/RowSelection.js.map +1 -0
  23. package/build/cjs/features/Sorting.js +76 -18
  24. package/build/cjs/features/Sorting.js.map +1 -1
  25. package/build/cjs/features/Visibility.js +8 -2
  26. package/build/cjs/features/Visibility.js.map +1 -1
  27. package/build/cjs/index.js +2 -0
  28. package/build/cjs/index.js.map +1 -1
  29. package/build/cjs/sortTypes.js +1 -0
  30. package/build/cjs/sortTypes.js.map +1 -1
  31. package/build/cjs/utils/columnFilterRowsFn.js +3 -2
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  33. package/build/cjs/utils/expandRowsFn.js +2 -2
  34. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  35. package/build/cjs/utils/globalFilterRowsFn.js +3 -2
  36. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  37. package/build/cjs/utils/groupRowsFn.js +4 -3
  38. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  39. package/build/cjs/utils/paginateRowsFn.js +44 -0
  40. package/build/cjs/utils/paginateRowsFn.js.map +1 -0
  41. package/build/cjs/utils/sortRowsFn.js +3 -2
  42. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  43. package/build/cjs/utils.js +6 -3
  44. package/build/cjs/utils.js.map +1 -1
  45. package/build/esm/index.js +2626 -1571
  46. package/build/esm/index.js.map +1 -1
  47. package/build/stats-html.html +1 -1
  48. package/build/stats-react.json +350 -248
  49. package/build/types/core.d.ts +10 -25
  50. package/build/types/createTable.d.ts +21 -4
  51. package/build/types/features/ColumnSizing.d.ts +4 -10
  52. package/build/types/features/Expanding.d.ts +2 -1
  53. package/build/types/features/Filters.d.ts +7 -2
  54. package/build/types/features/Grouping.d.ts +2 -2
  55. package/build/types/features/Ordering.d.ts +1 -1
  56. package/build/types/features/Pagination.d.ts +44 -0
  57. package/build/types/features/Pinning.d.ts +3 -3
  58. package/build/types/features/RowSelection.d.ts +66 -0
  59. package/build/types/features/Sorting.d.ts +5 -2
  60. package/build/types/index.d.ts +2 -1
  61. package/build/types/sortTypes.d.ts +1 -0
  62. package/build/types/types.d.ts +9 -6
  63. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  64. package/build/types/utils/expandRowsFn.d.ts +2 -2
  65. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  66. package/build/types/utils/groupRowsFn.d.ts +2 -2
  67. package/build/types/utils/paginateRowsFn.d.ts +2 -0
  68. package/build/types/utils/sortRowsFn.d.ts +2 -2
  69. package/build/types/utils.d.ts +5 -1
  70. package/build/umd/index.development.js +2626 -1570
  71. package/build/umd/index.development.js.map +1 -1
  72. package/build/umd/index.production.js +1 -1
  73. package/build/umd/index.production.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/core.tsx +222 -273
  76. package/src/createTable.tsx +69 -9
  77. package/src/features/ColumnSizing.ts +8 -37
  78. package/src/features/Expanding.ts +27 -11
  79. package/src/features/Filters.ts +74 -19
  80. package/src/features/Grouping.ts +27 -12
  81. package/src/features/Headers.ts +26 -58
  82. package/src/features/Ordering.ts +2 -3
  83. package/src/features/Pagination.ts +327 -0
  84. package/src/features/Pinning.ts +3 -16
  85. package/src/features/RowSelection.ts +831 -0
  86. package/src/features/Sorting.ts +82 -22
  87. package/src/features/Visibility.ts +2 -4
  88. package/src/index.tsx +2 -1
  89. package/src/sortTypes.ts +1 -1
  90. package/src/types.ts +25 -8
  91. package/src/utils/columnFilterRowsFn.ts +5 -12
  92. package/src/utils/expandRowsFn.ts +2 -5
  93. package/src/utils/globalFilterRowsFn.ts +3 -10
  94. package/src/utils/groupRowsFn.ts +3 -5
  95. package/src/utils/paginateRowsFn.ts +34 -0
  96. package/src/utils/sortRowsFn.ts +5 -5
  97. package/src/utils.tsx +12 -4
  98. package/src/features/withPagination.oldts +0 -208
  99. package/src/features/withRowSelection.oldts +0 -467
@@ -37,7 +37,8 @@
37
37
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
38
38
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
39
 
40
- var columnFilterRowsFn = function columnFilterRowsFn(instance, columnFilters, rowModel) {
40
+ function columnFilterRowsFn(instance, rowModel) {
41
+ var columnFilters = instance.getState().columnFilters;
41
42
  var newFilteredFlatRows = [];
42
43
  var newFilteredRowsById = {};
43
44
  var filterFromChildrenUp = instance.options.filterFromChildrenUp;
@@ -149,9 +150,10 @@
149
150
  flatRows: newFilteredFlatRows,
150
151
  rowsById: newFilteredRowsById
151
152
  };
152
- };
153
+ }
153
154
 
154
- var globalFilterRowsFn = function globalFilterRowsFn(instance, globalFilter, rowModel) {
155
+ function globalFilterRowsFn(instance, rowModel) {
156
+ var globalFilter = instance.getState().globalFilter;
155
157
  var newFilteredFlatRows = [];
156
158
  var newFilteredRowsById = {};
157
159
  var filterFromChildrenUp = instance.options.filterFromChildrenUp;
@@ -233,9 +235,10 @@
233
235
  flatRows: newFilteredFlatRows,
234
236
  rowsById: newFilteredRowsById
235
237
  };
236
- };
238
+ }
237
239
 
238
- var sortRowsFn = function sortRowsFn(instance, sortingState, rowModel) {
240
+ function sortRowsFn(instance, rowModel) {
241
+ var sortingState = instance.getState().sorting;
239
242
  var sortedFlatRows = []; // Filter out sortings that correspond to non existing columns
240
243
 
241
244
  var availableSorting = sortingState.filter(function (sort) {
@@ -310,7 +313,7 @@
310
313
  flatRows: sortedFlatRows,
311
314
  rowsById: rowModel.rowsById
312
315
  };
313
- };
316
+ }
314
317
 
315
318
  function _extends() {
316
319
  _extends = Object.assign || function (target) {
@@ -444,7 +447,7 @@
444
447
 
445
448
  return _extends({}, initial, getter != null ? getter : {});
446
449
  };
447
- function memo(getDeps, fn, key, debug) {
450
+ function memo(getDeps, fn, opts) {
448
451
  var deps = [];
449
452
  var result;
450
453
  return function () {
@@ -456,8 +459,8 @@
456
459
  });
457
460
 
458
461
  if (depsChanged) {
459
- if (debug) {
460
- console.info(key, _extends({
462
+ if (opts != null && opts.debug) {
463
+ console.info(opts == null ? void 0 : opts.key, _extends({
461
464
  length: oldSerializedDeps.length + " -> " + newSerializedDeps.length
462
465
  }, newSerializedDeps.map(function (_, index) {
463
466
  if (oldSerializedDeps[index] !== newSerializedDeps[index]) {
@@ -474,8 +477,11 @@
474
477
  }));
475
478
  }
476
479
 
480
+ var oldResult = result;
477
481
  result = fn.apply(void 0, newDeps);
478
482
  deps = newSerializedDeps;
483
+ opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result, oldResult);
484
+ oldResult = undefined;
479
485
  }
480
486
 
481
487
  return result;
@@ -516,8 +522,9 @@
516
522
  // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
517
523
  // }
518
524
 
519
- var groupRowsFn = function groupRowsFn(instance, groupingState, sortedRowModel) {
520
- // Filter the grouping list down to columns that exist
525
+ function groupRowsFn(instance, sortedRowModel) {
526
+ var groupingState = instance.getState().grouping; // Filter the grouping list down to columns that exist
527
+
521
528
  var existingGrouping = groupingState.filter(function (columnId) {
522
529
  return instance.getColumn(columnId);
523
530
  }); // Find the columns that can or are aggregating
@@ -634,7 +641,7 @@
634
641
  flatRows: groupedFlatRows,
635
642
  rowsById: groupedRowsById
636
643
  };
637
- };
644
+ }
638
645
 
639
646
  function groupBy(rows, columnId) {
640
647
  var groupMap = new Map();
@@ -652,7 +659,7 @@
652
659
  }, groupMap);
653
660
  }
654
661
 
655
- var expandRowsFn = function expandRowsFn(instance, _expandedState, sortedRowModel) {
662
+ function expandRowsFn(instance, sortedRowModel) {
656
663
  var expandedRows = [];
657
664
  var expandSubRows = instance.options.expandSubRows;
658
665
 
@@ -672,15 +679,41 @@
672
679
  flatRows: sortedRowModel.flatRows,
673
680
  rowsById: sortedRowModel.rowsById
674
681
  };
675
- };
682
+ }
683
+
684
+ function paginateRowsFn(instance, rowModel) {
685
+ var _instance$getState$pa = instance.getState().pagination,
686
+ pageSize = _instance$getState$pa.pageSize,
687
+ pageIndex = _instance$getState$pa.pageIndex;
688
+ var rows = rowModel.rows,
689
+ flatRows = rowModel.flatRows,
690
+ rowsById = rowModel.rowsById;
691
+ var pageStart = pageSize * pageIndex;
692
+ var pageEnd = pageStart + pageSize;
693
+ rows = rows.slice(pageStart, pageEnd);
694
+
695
+ if (!instance.options.paginateExpandedRows) {
696
+ return expandRowsFn(instance, {
697
+ rows: rows,
698
+ flatRows: flatRows,
699
+ rowsById: rowsById
700
+ });
701
+ }
702
+
703
+ return {
704
+ rows: rows,
705
+ flatRows: flatRows,
706
+ rowsById: rowsById
707
+ };
708
+ }
676
709
 
677
710
  //
678
- function getInitialState$7() {
711
+ function getInitialState$9() {
679
712
  return {
680
713
  columnVisibility: {}
681
714
  };
682
715
  }
683
- function getDefaultOptions$7(instance) {
716
+ function getDefaultOptions$9(instance) {
684
717
  return {
685
718
  onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
686
719
  };
@@ -714,7 +747,7 @@
714
747
  }
715
748
  };
716
749
  }
717
- function getInstance$8(instance) {
750
+ function getInstance$a(instance) {
718
751
  return {
719
752
  getVisibleFlatColumns: memo(function () {
720
753
  return [instance.getAllFlatColumns(), instance.getAllFlatColumns().filter(function (d) {
@@ -726,7 +759,10 @@
726
759
  return allFlatColumns.filter(function (d) {
727
760
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
728
761
  });
729
- }, 'getVisibleFlatColumns', instance.options.debug),
762
+ }, {
763
+ key: 'getVisibleFlatColumns',
764
+ debug: instance.options.debug
765
+ }),
730
766
  getVisibleLeafColumns: memo(function () {
731
767
  return [instance.getAllLeafColumns(), instance.getAllLeafColumns().filter(function (d) {
732
768
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
@@ -737,7 +773,10 @@
737
773
  return allFlatColumns.filter(function (d) {
738
774
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
739
775
  });
740
- }, 'getVisibleLeafColumns', instance.options.debug),
776
+ }, {
777
+ key: 'getVisibleLeafColumns',
778
+ debug: instance.options.debug
779
+ }),
741
780
  setColumnVisibility: function setColumnVisibility(updater) {
742
781
  return instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater, functionalUpdate(updater, instance.getState().columnVisibility));
743
782
  },
@@ -811,6 +850,15 @@
811
850
  };
812
851
  }
813
852
 
853
+ var Visibility = /*#__PURE__*/Object.freeze({
854
+ __proto__: null,
855
+ getInitialState: getInitialState$9,
856
+ getDefaultOptions: getDefaultOptions$9,
857
+ getDefaultColumn: getDefaultColumn$3,
858
+ createColumn: createColumn$5,
859
+ getInstance: getInstance$a
860
+ });
861
+
814
862
  var aggregationTypes = {
815
863
  sum: sum,
816
864
  min: min,
@@ -929,12 +977,12 @@
929
977
  aggregationType: 'auto'
930
978
  };
931
979
  }
932
- function getInitialState$6() {
980
+ function getInitialState$8() {
933
981
  return {
934
982
  grouping: []
935
983
  };
936
984
  }
937
- function getDefaultOptions$6(instance) {
985
+ function getDefaultOptions$8(instance) {
938
986
  return {
939
987
  onGroupingChange: makeStateUpdater('grouping', instance),
940
988
  autoResetGrouping: true,
@@ -961,8 +1009,23 @@
961
1009
  }
962
1010
  };
963
1011
  }
964
- function getInstance$7(instance) {
1012
+ function getInstance$9(instance) {
1013
+ var registered = false;
965
1014
  return {
1015
+ _notifyGroupingReset: function _notifyGroupingReset() {
1016
+ if (!registered) {
1017
+ registered = true;
1018
+ return;
1019
+ }
1020
+
1021
+ if (instance.options.autoResetAll === false) {
1022
+ return;
1023
+ }
1024
+
1025
+ if (instance.options.autoResetAll === true || instance.options.autoResetGrouping) {
1026
+ instance.resetGrouping();
1027
+ }
1028
+ },
966
1029
  getColumnAutoAggregationFn: function getColumnAutoAggregationFn(columnId) {
967
1030
  var firstRow = instance.getCoreFlatRows()[0];
968
1031
  var value = firstRow == null ? void 0 : firstRow.values[columnId];
@@ -1060,8 +1123,14 @@
1060
1123
  }
1061
1124
 
1062
1125
  if (instance.options.debug) console.info('Grouping...');
1063
- return groupRowsFn(instance, grouping, rowModel);
1064
- }, 'getGroupedRowModel', instance.options.debug),
1126
+ return groupRowsFn(instance, rowModel);
1127
+ }, {
1128
+ key: 'getGroupedRowModel',
1129
+ debug: instance.options.debug,
1130
+ onChange: function onChange() {
1131
+ return instance._notifyExpandedReset();
1132
+ }
1133
+ }),
1065
1134
  getPreGroupedRows: function getPreGroupedRows() {
1066
1135
  return instance.getSortedRowModel().rows;
1067
1136
  },
@@ -1082,7 +1151,7 @@
1082
1151
  }
1083
1152
  };
1084
1153
  }
1085
- function createRow$2(row, instance) {
1154
+ function createRow$3(row, instance) {
1086
1155
  return {
1087
1156
  getIsGrouped: function getIsGrouped() {
1088
1157
  return instance.getRowIsGrouped(row.id);
@@ -1125,18 +1194,30 @@
1125
1194
  return [].concat(groupingColumns, nonGroupingColumns);
1126
1195
  }
1127
1196
 
1197
+ var Grouping = /*#__PURE__*/Object.freeze({
1198
+ __proto__: null,
1199
+ getDefaultColumn: getDefaultColumn$2,
1200
+ getInitialState: getInitialState$8,
1201
+ getDefaultOptions: getDefaultOptions$8,
1202
+ createColumn: createColumn$4,
1203
+ getInstance: getInstance$9,
1204
+ createRow: createRow$3,
1205
+ createCell: createCell,
1206
+ orderColumns: orderColumns
1207
+ });
1208
+
1128
1209
  //
1129
- function getInitialState$5() {
1210
+ function getInitialState$7() {
1130
1211
  return {
1131
1212
  columnOrder: []
1132
1213
  };
1133
1214
  }
1134
- function getDefaultOptions$5(instance) {
1215
+ function getDefaultOptions$7(instance) {
1135
1216
  return {
1136
1217
  onColumnOrderChange: makeStateUpdater('columnOrder', instance)
1137
1218
  };
1138
1219
  }
1139
- function getInstance$6(instance) {
1220
+ function getInstance$8(instance) {
1140
1221
  return {
1141
1222
  setColumnOrder: function setColumnOrder(updater) {
1142
1223
  return instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater, functionalUpdate(updater, instance.getState().columnOrder));
@@ -1183,12 +1264,22 @@
1183
1264
 
1184
1265
  return orderColumns(orderedColumns, grouping, groupedColumnMode);
1185
1266
  };
1186
- }, 'getOrderColumnsFn', instance.options.debug)
1267
+ }, {
1268
+ key: 'getOrderColumnsFn',
1269
+ debug: instance.options.debug
1270
+ })
1187
1271
  };
1188
1272
  }
1189
1273
 
1274
+ var Ordering = /*#__PURE__*/Object.freeze({
1275
+ __proto__: null,
1276
+ getInitialState: getInitialState$7,
1277
+ getDefaultOptions: getDefaultOptions$7,
1278
+ getInstance: getInstance$8
1279
+ });
1280
+
1190
1281
  //
1191
- function getInitialState$4() {
1282
+ function getInitialState$6() {
1192
1283
  return {
1193
1284
  columnPinning: {
1194
1285
  left: [],
@@ -1196,7 +1287,7 @@
1196
1287
  }
1197
1288
  };
1198
1289
  }
1199
- function getDefaultOptions$4(instance) {
1290
+ function getDefaultOptions$6(instance) {
1200
1291
  return {
1201
1292
  onColumnPinningChange: makeStateUpdater('columnPinning', instance)
1202
1293
  };
@@ -1217,7 +1308,7 @@
1217
1308
  }
1218
1309
  };
1219
1310
  }
1220
- function getInstance$5(instance) {
1311
+ function getInstance$7(instance) {
1221
1312
  return {
1222
1313
  setColumnPinning: function setColumnPinning(updater) {
1223
1314
  return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
@@ -1304,1892 +1395,2821 @@
1304
1395
  var isRight = leafColumnIds.some(function (d) {
1305
1396
  return right == null ? void 0 : right.includes(d);
1306
1397
  });
1307
-
1308
- if (isLeft && isRight) {
1309
- return 'both';
1310
- }
1311
-
1312
1398
  return isLeft ? 'left' : isRight ? 'right' : false;
1313
1399
  },
1314
1400
  getColumnPinnedIndex: function getColumnPinnedIndex(columnId) {
1315
1401
  var _instance$getState$co2, _instance$getState$co3, _instance$getState$co4;
1316
1402
 
1317
1403
  var position = instance.getColumnIsPinned(columnId);
1318
-
1319
- if (position === 'both') {
1320
- {
1321
- console.warn("Column " + columnId + " has leaf columns that are pinned on both sides");
1322
- }
1323
-
1324
- throw new Error();
1325
- }
1326
-
1327
1404
  return position ? (_instance$getState$co2 = (_instance$getState$co3 = instance.getState().columnPinning) == null ? void 0 : (_instance$getState$co4 = _instance$getState$co3[position]) == null ? void 0 : _instance$getState$co4.indexOf(columnId)) != null ? _instance$getState$co2 : -1 : 0;
1328
1405
  }
1329
1406
  };
1330
1407
  }
1331
1408
 
1409
+ var Pinning = /*#__PURE__*/Object.freeze({
1410
+ __proto__: null,
1411
+ getInitialState: getInitialState$6,
1412
+ getDefaultOptions: getDefaultOptions$6,
1413
+ createColumn: createColumn$3,
1414
+ getInstance: getInstance$7
1415
+ });
1416
+
1332
1417
  //
1333
- var defaultColumnSizing = {
1334
- width: 150,
1335
- minWidth: 20,
1336
- maxWidth: Number.MAX_SAFE_INTEGER
1337
- };
1338
- function getInitialState$3() {
1339
- return {
1340
- columnSizing: {},
1341
- columnSizingInfo: {
1342
- startOffset: null,
1343
- startSize: null,
1344
- deltaOffset: null,
1345
- deltaPercentage: null,
1346
- isResizingColumn: false,
1347
- columnSizingStart: []
1348
- }
1349
- };
1350
- }
1351
- function getDefaultOptions$3(instance) {
1418
+ function createRow$2(row, instance) {
1352
1419
  return {
1353
- columnResizeMode: 'onEnd',
1354
- onColumnSizingChange: makeStateUpdater('columnSizing', instance),
1355
- onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
1420
+ _getAllVisibleCells: memo(function () {
1421
+ return [row.getAllCells().filter(function (cell) {
1422
+ return cell.column.getIsVisible();
1423
+ }).map(function (d) {
1424
+ return d.id;
1425
+ }).join('_')];
1426
+ }, function (_) {
1427
+ return row.getAllCells().filter(function (cell) {
1428
+ return cell.column.getIsVisible();
1429
+ });
1430
+ }, {
1431
+ key: 'row._getAllVisibleCells',
1432
+ debug: instance.options.debug
1433
+ }),
1434
+ getVisibleCells: memo(function () {
1435
+ return [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()];
1436
+ }, function (left, center, right) {
1437
+ return [].concat(left, center, right);
1438
+ }, {
1439
+ key: 'row.getVisibleCells',
1440
+ debug: instance.options.debug
1441
+ }),
1442
+ getCenterVisibleCells: memo(function () {
1443
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1444
+ }, function (allCells, left, right) {
1445
+ var leftAndRight = [].concat(left != null ? left : [], right != null ? right : []);
1446
+ return allCells.filter(function (d) {
1447
+ return !leftAndRight.includes(d.columnId);
1448
+ });
1449
+ }, {
1450
+ key: 'row.getCenterVisibleCells',
1451
+ debug: instance.options.debug
1452
+ }),
1453
+ getLeftVisibleCells: memo(function () {
1454
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.left,,];
1455
+ }, function (allCells, left) {
1456
+ var cells = (left != null ? left : []).map(function (columnId) {
1457
+ return allCells.find(function (cell) {
1458
+ return cell.columnId === columnId;
1459
+ });
1460
+ }).filter(Boolean);
1461
+ return cells;
1462
+ }, {
1463
+ key: 'row.getLeftVisibleCells',
1464
+ debug: instance.options.debug
1465
+ }),
1466
+ getRightVisibleCells: memo(function () {
1467
+ return [row._getAllVisibleCells(), instance.getState().columnPinning.right];
1468
+ }, function (allCells, right) {
1469
+ var cells = (right != null ? right : []).map(function (columnId) {
1470
+ return allCells.find(function (cell) {
1471
+ return cell.columnId === columnId;
1472
+ });
1473
+ }).filter(Boolean);
1474
+ return cells;
1475
+ }, {
1476
+ key: 'row.getRightVisibleCells',
1477
+ debug: instance.options.debug
1478
+ })
1356
1479
  };
1357
1480
  }
1358
- function getInstance$4(instance) {
1481
+ function getInstance$6(instance) {
1359
1482
  return {
1360
- setColumnSizing: function setColumnSizing(updater) {
1361
- return instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater, functionalUpdate(updater, instance.getState().columnSizing));
1362
- },
1363
- setColumnSizingInfo: function setColumnSizingInfo(updater) {
1364
- return instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater, functionalUpdate(updater, instance.getState().columnSizingInfo));
1365
- },
1366
- resetColumnSizing: function resetColumnSizing() {
1367
- var _instance$initialStat;
1368
-
1369
- instance.setColumnSizing((_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
1370
- },
1371
- resetHeaderSizeInfo: function resetHeaderSizeInfo() {
1372
- var _instance$initialStat2;
1373
-
1374
- instance.setColumnSizingInfo((_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : {});
1375
- },
1376
- resetColumnSize: function resetColumnSize(columnId) {
1377
- instance.setColumnSizing(function (_ref) {
1378
- _ref[columnId];
1379
- var rest = _objectWithoutPropertiesLoose(_ref, [columnId].map(_toPropertyKey));
1380
-
1381
- return rest;
1382
- });
1383
- },
1384
- resetHeaderSize: function resetHeaderSize(headerId) {
1385
- var header = instance.getHeader(headerId);
1386
-
1387
- if (!header) {
1388
- return;
1389
- }
1390
-
1391
- return instance.resetColumnSize(header.column.id);
1392
- },
1393
- getHeaderCanResize: function getHeaderCanResize(headerId) {
1394
- var header = instance.getHeader(headerId);
1395
-
1396
- if (!header) {
1397
- throw new Error();
1398
- }
1483
+ createHeader: function createHeader(column, options) {
1484
+ var _options$id;
1399
1485
 
1400
- return instance.getColumnCanResize(header.column.id);
1401
- },
1402
- getColumnCanResize: function getColumnCanResize(columnId) {
1403
- var _ref2, _ref3, _column$enableResizin;
1486
+ var id = (_options$id = options.id) != null ? _options$id : column.id;
1487
+ var header = {
1488
+ id: id,
1489
+ column: column,
1490
+ isPlaceholder: options.isPlaceholder,
1491
+ placeholderId: options.placeholderId,
1492
+ depth: options.depth,
1493
+ subHeaders: [],
1494
+ colSpan: 0,
1495
+ rowSpan: 0,
1496
+ getWidth: function getWidth() {
1497
+ var sum = 0;
1404
1498
 
1405
- var column = instance.getColumn(columnId);
1499
+ var recurse = function recurse(header) {
1500
+ if (header.subHeaders.length) {
1501
+ header.subHeaders.forEach(recurse);
1502
+ } else {
1503
+ var _header$column$getWid;
1406
1504
 
1407
- if (!column) {
1408
- throw new Error();
1409
- }
1505
+ sum += (_header$column$getWid = header.column.getWidth()) != null ? _header$column$getWid : 0;
1506
+ }
1507
+ };
1410
1508
 
1411
- return (_ref2 = (_ref3 = (_column$enableResizin = column.enableResizing) != null ? _column$enableResizin : instance.options.enableColumnResizing) != null ? _ref3 : column.defaultCanResize) != null ? _ref2 : true;
1412
- },
1413
- getColumnIsResizing: function getColumnIsResizing(columnId) {
1414
- var column = instance.getColumn(columnId);
1509
+ recurse(header);
1510
+ return sum;
1511
+ },
1512
+ getLeafHeaders: function getLeafHeaders() {
1513
+ var leafHeaders = [];
1415
1514
 
1416
- if (!column) {
1417
- throw new Error();
1418
- }
1515
+ var recurseHeader = function recurseHeader(h) {
1516
+ if (h.subHeaders && h.subHeaders.length) {
1517
+ h.subHeaders.map(recurseHeader);
1518
+ }
1419
1519
 
1420
- return instance.getState().columnSizingInfo.isResizingColumn === columnId;
1421
- },
1422
- getHeaderIsResizing: function getHeaderIsResizing(headerId) {
1423
- var header = instance.getHeader(headerId);
1520
+ leafHeaders.push(h);
1521
+ };
1424
1522
 
1425
- if (!header) {
1426
- throw new Error();
1427
- }
1523
+ recurseHeader(header);
1524
+ return leafHeaders;
1525
+ },
1526
+ getHeaderProps: function getHeaderProps(userProps) {
1527
+ return instance.getHeaderProps(header.id, userProps);
1528
+ },
1529
+ getFooterProps: function getFooterProps(userProps) {
1530
+ return instance.getFooterProps(header.id, userProps);
1531
+ },
1532
+ renderHeader: function renderHeader() {
1533
+ return flexRender(column.header, {
1534
+ instance: instance,
1535
+ header: header,
1536
+ column: column
1537
+ });
1538
+ },
1539
+ renderFooter: function renderFooter() {
1540
+ return flexRender(column.footer, {
1541
+ instance: instance,
1542
+ header: header,
1543
+ column: column
1544
+ });
1545
+ }
1546
+ }; // Yes, we have to convert instance to uknown, because we know more than the compiler here.
1428
1547
 
1429
- return instance.getColumnIsResizing(header.column.id);
1548
+ return header;
1430
1549
  },
1431
- getHeaderResizerProps: function getHeaderResizerProps(headerId, userProps) {
1432
- var header = instance.getHeader(headerId);
1433
-
1434
- if (!header) {
1435
- return;
1436
- }
1437
-
1438
- var column = instance.getColumn(header.column.id);
1439
-
1440
- if (!column) {
1441
- return;
1442
- }
1443
-
1444
- var canResize = column.getCanResize();
1445
-
1446
- var onResizeStart = function onResizeStart(e) {
1447
- if (isTouchStartEvent(e)) {
1448
- // lets not respond to multiple touches (e.g. 2 or 3 fingers)
1449
- if (e.touches && e.touches.length > 1) {
1450
- return;
1451
- }
1550
+ // Header Groups
1551
+ getHeaderGroups: memo(function () {
1552
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1553
+ }, function (allColumns, leafColumns, left, right) {
1554
+ var leftColumns = leafColumns.filter(function (column) {
1555
+ return left == null ? void 0 : left.includes(column.id);
1556
+ });
1557
+ var rightColumns = leafColumns.filter(function (column) {
1558
+ return right == null ? void 0 : right.includes(column.id);
1559
+ });
1560
+ var centerColumns = leafColumns.filter(function (column) {
1561
+ return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1562
+ });
1563
+ var headerGroups = buildHeaderGroups(allColumns, [].concat(leftColumns, centerColumns, rightColumns), instance);
1564
+ return headerGroups;
1565
+ }, {
1566
+ key: 'getHeaderGroups',
1567
+ debug: instance.options.debug
1568
+ }),
1569
+ getCenterHeaderGroups: memo(function () {
1570
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1571
+ }, function (allColumns, leafColumns, left, right) {
1572
+ leafColumns = leafColumns.filter(function (column) {
1573
+ return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1574
+ });
1575
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
1576
+ }, {
1577
+ key: 'getCenterHeaderGroups',
1578
+ debug: instance.options.debug
1579
+ }),
1580
+ getLeftHeaderGroups: memo(function () {
1581
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left];
1582
+ }, function (allColumns, leafColumns, left) {
1583
+ leafColumns = leafColumns.filter(function (column) {
1584
+ return left == null ? void 0 : left.includes(column.id);
1585
+ });
1586
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
1587
+ }, {
1588
+ key: 'getLeftHeaderGroups',
1589
+ debug: instance.options.debug
1590
+ }),
1591
+ getRightHeaderGroups: memo(function () {
1592
+ return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right];
1593
+ }, function (allColumns, leafColumns, right) {
1594
+ leafColumns = leafColumns.filter(function (column) {
1595
+ return right == null ? void 0 : right.includes(column.id);
1596
+ });
1597
+ return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
1598
+ }, {
1599
+ key: 'getRightHeaderGroups',
1600
+ debug: instance.options.debug
1601
+ }),
1602
+ // Footer Groups
1603
+ getFooterGroups: memo(function () {
1604
+ return [instance.getHeaderGroups()];
1605
+ }, function (headerGroups) {
1606
+ return [].concat(headerGroups).reverse();
1607
+ }, {
1608
+ key: 'getFooterGroups',
1609
+ debug: instance.options.debug
1610
+ }),
1611
+ getLeftFooterGroups: memo(function () {
1612
+ return [instance.getLeftHeaderGroups()];
1613
+ }, function (headerGroups) {
1614
+ return [].concat(headerGroups).reverse();
1615
+ }, {
1616
+ key: 'getLeftFooterGroups',
1617
+ debug: instance.options.debug
1618
+ }),
1619
+ getCenterFooterGroups: memo(function () {
1620
+ return [instance.getCenterHeaderGroups()];
1621
+ }, function (headerGroups) {
1622
+ return [].concat(headerGroups).reverse();
1623
+ }, {
1624
+ key: 'getCenterFooterGroups',
1625
+ debug: instance.options.debug
1626
+ }),
1627
+ getRightFooterGroups: memo(function () {
1628
+ return [instance.getRightHeaderGroups()];
1629
+ }, function (headerGroups) {
1630
+ return [].concat(headerGroups).reverse();
1631
+ }, {
1632
+ key: 'getRightFooterGroups',
1633
+ debug: instance.options.debug
1634
+ }),
1635
+ // Flat Headers
1636
+ getFlatHeaders: memo(function () {
1637
+ return [instance.getHeaderGroups()];
1638
+ }, function (headerGroups) {
1639
+ return headerGroups.map(function (headerGroup) {
1640
+ return headerGroup.headers;
1641
+ }).flat();
1642
+ }, {
1643
+ key: 'getFlatHeaders',
1644
+ debug: instance.options.debug
1645
+ }),
1646
+ getLeftFlatHeaders: memo(function () {
1647
+ return [instance.getLeftHeaderGroups()];
1648
+ }, function (left) {
1649
+ return left.map(function (headerGroup) {
1650
+ return headerGroup.headers;
1651
+ }).flat();
1652
+ }, {
1653
+ key: 'getLeftFlatHeaders',
1654
+ debug: instance.options.debug
1655
+ }),
1656
+ getCenterFlatHeaders: memo(function () {
1657
+ return [instance.getCenterHeaderGroups()];
1658
+ }, function (left) {
1659
+ return left.map(function (headerGroup) {
1660
+ return headerGroup.headers;
1661
+ }).flat();
1662
+ }, {
1663
+ key: 'getCenterFlatHeaders',
1664
+ debug: instance.options.debug
1665
+ }),
1666
+ getRightFlatHeaders: memo(function () {
1667
+ return [instance.getRightHeaderGroups()];
1668
+ }, function (left) {
1669
+ return left.map(function (headerGroup) {
1670
+ return headerGroup.headers;
1671
+ }).flat();
1672
+ }, {
1673
+ key: 'getRightFlatHeaders',
1674
+ debug: instance.options.debug
1675
+ }),
1676
+ // Leaf Headers
1677
+ getCenterLeafHeaders: memo(function () {
1678
+ return [instance.getCenterFlatHeaders()];
1679
+ }, function (flatHeaders) {
1680
+ return flatHeaders.filter(function (header) {
1681
+ var _header$subHeaders;
1682
+
1683
+ return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
1684
+ });
1685
+ }, {
1686
+ key: 'getCenterLeafHeaders',
1687
+ debug: instance.options.debug
1688
+ }),
1689
+ getLeftLeafHeaders: memo(function () {
1690
+ return [instance.getLeftFlatHeaders()];
1691
+ }, function (flatHeaders) {
1692
+ return flatHeaders.filter(function (header) {
1693
+ var _header$subHeaders2;
1694
+
1695
+ return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
1696
+ });
1697
+ }, {
1698
+ key: 'getLeftLeafHeaders',
1699
+ debug: instance.options.debug
1700
+ }),
1701
+ getRightLeafHeaders: memo(function () {
1702
+ return [instance.getRightFlatHeaders()];
1703
+ }, function (flatHeaders) {
1704
+ return flatHeaders.filter(function (header) {
1705
+ var _header$subHeaders3;
1706
+
1707
+ return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
1708
+ });
1709
+ }, {
1710
+ key: 'getRightLeafHeaders',
1711
+ debug: instance.options.debug
1712
+ }),
1713
+ getLeafHeaders: memo(function () {
1714
+ return [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()];
1715
+ }, function (left, center, right) {
1716
+ var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
1717
+
1718
+ return [].concat((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : [], (_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : [], (_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : []).map(function (header) {
1719
+ return header.getLeafHeaders();
1720
+ }).flat();
1721
+ }, {
1722
+ key: 'getLeafHeaders',
1723
+ debug: instance.options.debug
1724
+ }),
1725
+ getHeader: function getHeader(id) {
1726
+ var header = [].concat(instance.getFlatHeaders(), instance.getCenterFlatHeaders(), instance.getLeftFlatHeaders(), instance.getRightFlatHeaders()).find(function (d) {
1727
+ return d.id === id;
1728
+ });
1729
+
1730
+ if (!header) {
1731
+ {
1732
+ console.warn("Could not find header with id: " + id);
1452
1733
  }
1453
1734
 
1454
- var columnSizingStart = header.getLeafHeaders().map(function (d) {
1455
- return [d.column.id, d.getWidth()];
1735
+ throw new Error();
1736
+ }
1737
+
1738
+ return header;
1739
+ },
1740
+ getHeaderGroupProps: function getHeaderGroupProps(id, userProps) {
1741
+ var headerGroup = instance.getHeaderGroups().find(function (d) {
1742
+ return d.id === id;
1743
+ });
1744
+
1745
+ if (!headerGroup) {
1746
+ return;
1747
+ }
1748
+
1749
+ return propGetter({
1750
+ key: headerGroup.id,
1751
+ role: 'row'
1752
+ }, userProps);
1753
+ },
1754
+ getFooterGroupProps: function getFooterGroupProps(id, userProps) {
1755
+ var headerGroup = instance.getFooterGroups().find(function (d) {
1756
+ return d.id === id;
1757
+ });
1758
+
1759
+ if (!headerGroup) {
1760
+ return;
1761
+ }
1762
+
1763
+ var initialProps = {
1764
+ key: headerGroup.id,
1765
+ role: 'row'
1766
+ };
1767
+ return propGetter(initialProps, userProps);
1768
+ },
1769
+ getHeaderProps: function getHeaderProps(id, userProps) {
1770
+ var header = instance.getHeader(id);
1771
+
1772
+ if (!header) {
1773
+ throw new Error();
1774
+ }
1775
+
1776
+ var initialProps = {
1777
+ key: header.id,
1778
+ role: 'columnheader',
1779
+ colSpan: header.colSpan,
1780
+ rowSpan: header.rowSpan
1781
+ };
1782
+ return propGetter(initialProps, userProps);
1783
+ },
1784
+ getFooterProps: function getFooterProps(id, userProps) {
1785
+ var header = instance.getHeader(id);
1786
+
1787
+ if (!header) {
1788
+ return;
1789
+ }
1790
+
1791
+ var initialProps = {
1792
+ key: header.id,
1793
+ role: 'columnfooter',
1794
+ colSpan: header.colSpan,
1795
+ rowSpan: header.rowSpan
1796
+ };
1797
+ return propGetter(initialProps, userProps);
1798
+ },
1799
+ getTotalWidth: function getTotalWidth() {
1800
+ var width = 0;
1801
+ instance.getVisibleLeafColumns().forEach(function (column) {
1802
+ var _column$getWidth;
1803
+
1804
+ width += (_column$getWidth = column.getWidth()) != null ? _column$getWidth : 0;
1805
+ });
1806
+ return width;
1807
+ }
1808
+ };
1809
+ }
1810
+ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
1811
+ var _headerGroups$0$heade, _headerGroups$;
1812
+
1813
+ // Find the max depth of the columns:
1814
+ // build the leaf column row
1815
+ // build each buffer row going up
1816
+ // placeholder for non-existent level
1817
+ // real column for existing level
1818
+ var maxDepth = 0;
1819
+
1820
+ var findMaxDepth = function findMaxDepth(columns, depth) {
1821
+ if (depth === void 0) {
1822
+ depth = 1;
1823
+ }
1824
+
1825
+ maxDepth = Math.max(maxDepth, depth);
1826
+ columns.filter(function (column) {
1827
+ return column.getIsVisible();
1828
+ }).forEach(function (column) {
1829
+ var _column$columns;
1830
+
1831
+ if ((_column$columns = column.columns) != null && _column$columns.length) {
1832
+ findMaxDepth(column.columns, depth + 1);
1833
+ }
1834
+ }, 0);
1835
+ };
1836
+
1837
+ findMaxDepth(allColumns);
1838
+ var headerGroups = [];
1839
+
1840
+ var createHeaderGroup = function createHeaderGroup(headersToGroup, depth) {
1841
+ // The header group we are creating
1842
+ var headerGroup = {
1843
+ depth: depth,
1844
+ id: [headerFamily, "" + depth].filter(Boolean).join('_'),
1845
+ headers: [],
1846
+ getHeaderGroupProps: function getHeaderGroupProps(getterValue) {
1847
+ return instance.getHeaderGroupProps("" + depth, getterValue);
1848
+ },
1849
+ getFooterGroupProps: function getFooterGroupProps(getterValue) {
1850
+ return instance.getFooterGroupProps("" + depth, getterValue);
1851
+ }
1852
+ }; // The parent columns we're going to scan next
1853
+
1854
+ var parentHeaders = []; // Scan each column for parents
1855
+
1856
+ headersToGroup.forEach(function (headerToGroup) {
1857
+ // What is the latest (last) parent column?
1858
+ var latestParentHeader = [].concat(parentHeaders).reverse()[0];
1859
+ var isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
1860
+ var column;
1861
+ var isPlaceholder = false;
1862
+
1863
+ if (isLeafHeader && headerToGroup.column.parent) {
1864
+ // The parent header is new
1865
+ column = headerToGroup.column.parent;
1866
+ } else {
1867
+ // The parent header is repeated
1868
+ column = headerToGroup.column;
1869
+ isPlaceholder = true;
1870
+ }
1871
+
1872
+ var header = instance.createHeader(column, {
1873
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
1874
+ isPlaceholder: isPlaceholder,
1875
+ placeholderId: isPlaceholder ? "" + parentHeaders.filter(function (d) {
1876
+ return d.column === column;
1877
+ }).length : undefined,
1878
+ depth: depth
1879
+ });
1880
+
1881
+ if (!latestParentHeader || latestParentHeader.column !== header.column) {
1882
+ header.subHeaders.push(headerToGroup);
1883
+ parentHeaders.push(header);
1884
+ } else {
1885
+ latestParentHeader.subHeaders.push(headerToGroup);
1886
+ } // if (!headerToGroup.isPlaceholder) {
1887
+ // headerToGroup.column.header = headerToGroup;
1888
+ // }
1889
+
1890
+
1891
+ headerGroup.headers.push(headerToGroup);
1892
+ });
1893
+ headerGroups.push(headerGroup);
1894
+
1895
+ if (depth > 0) {
1896
+ createHeaderGroup(parentHeaders, depth - 1);
1897
+ }
1898
+ };
1899
+
1900
+ var bottomHeaders = columnsToGroup.map(function (column) {
1901
+ return instance.createHeader(column, {
1902
+ depth: maxDepth
1903
+ });
1904
+ });
1905
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
1906
+ headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
1907
+ // return !headerGroup.headers.every(header => header.isPlaceholder)
1908
+ // })
1909
+
1910
+ var recurseHeadersForSpans = function recurseHeadersForSpans(headers) {
1911
+ var filteredHeaders = headers.filter(function (header) {
1912
+ return header.column.getIsVisible();
1913
+ });
1914
+ return filteredHeaders.map(function (header) {
1915
+ var colSpan = 0;
1916
+ var rowSpan = 0;
1917
+ var childRowSpans = [0];
1918
+
1919
+ if (header.subHeaders && header.subHeaders.length) {
1920
+ childRowSpans = [];
1921
+ recurseHeadersForSpans(header.subHeaders).forEach(function (_ref) {
1922
+ var childColSpan = _ref.colSpan,
1923
+ childRowSpan = _ref.rowSpan;
1924
+ colSpan += childColSpan;
1925
+ childRowSpans.push(childRowSpan);
1456
1926
  });
1457
- var clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
1927
+ } else {
1928
+ colSpan = 1;
1929
+ }
1458
1930
 
1459
- var updateOffset = function updateOffset(eventType, clientXPos) {
1460
- if (typeof clientXPos !== 'number') {
1461
- return;
1462
- }
1931
+ var minChildRowSpan = Math.min.apply(Math, childRowSpans);
1932
+ rowSpan = rowSpan + minChildRowSpan;
1933
+ header.colSpan = colSpan > 0 ? colSpan : undefined;
1934
+ header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
1935
+ return {
1936
+ colSpan: colSpan,
1937
+ rowSpan: rowSpan
1938
+ };
1939
+ });
1940
+ };
1463
1941
 
1464
- var newColumnSizing = {};
1465
- instance.setColumnSizingInfo(function (old) {
1466
- var _old$startOffset, _old$startSize;
1942
+ recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
1943
+ return headerGroups;
1944
+ }
1467
1945
 
1468
- var deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
1469
- var deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
1470
- old.columnSizingStart.forEach(function (_ref4) {
1471
- var columnId = _ref4[0],
1472
- headerWidth = _ref4[1];
1473
- newColumnSizing[columnId] = Math.max(headerWidth + headerWidth * deltaPercentage, 0);
1474
- });
1475
- return _extends({}, old, {
1476
- deltaOffset: deltaOffset,
1477
- deltaPercentage: deltaPercentage
1478
- });
1479
- });
1946
+ var Headers = /*#__PURE__*/Object.freeze({
1947
+ __proto__: null,
1948
+ createRow: createRow$2,
1949
+ getInstance: getInstance$6,
1950
+ buildHeaderGroups: buildHeaderGroups
1951
+ });
1480
1952
 
1481
- if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
1482
- instance.setColumnSizing(function (old) {
1483
- return _extends({}, old, newColumnSizing);
1484
- });
1485
- }
1486
- };
1953
+ var filterTypes = {
1954
+ includesString: includesString,
1955
+ includesStringSensitive: includesStringSensitive,
1956
+ equalsString: equalsString,
1957
+ equalsStringSensitive: equalsStringSensitive,
1958
+ arrIncludes: arrIncludes,
1959
+ arrIncludesAll: arrIncludesAll,
1960
+ equals: equals,
1961
+ weakEquals: weakEquals,
1962
+ betweenNumberRange: betweenNumberRange
1963
+ };
1487
1964
 
1488
- var onMove = function onMove(clientXPos) {
1489
- return updateOffset('move', clientXPos);
1490
- };
1965
+ function includesString(rows, columnIds, filterValue) {
1966
+ var search = String(filterValue).toLowerCase();
1967
+ rows = rows.filter(function (row) {
1968
+ return columnIds.some(function (id) {
1969
+ return String(row.values[id]).toLowerCase().includes(search);
1970
+ });
1971
+ });
1972
+ return rows;
1973
+ }
1491
1974
 
1492
- var onEnd = function onEnd(clientXPos) {
1493
- updateOffset('end', clientXPos);
1494
- instance.setColumnSizingInfo(function (old) {
1495
- return _extends({}, old, {
1496
- isResizingColumn: false,
1497
- startOffset: null,
1498
- startSize: null,
1499
- deltaOffset: null,
1500
- deltaPercentage: null,
1501
- columnSizingStart: []
1502
- });
1503
- });
1504
- };
1975
+ includesString.autoRemove = function (val) {
1976
+ return testFalsey(val);
1977
+ };
1505
1978
 
1506
- var mouseEvents = {
1507
- moveHandler: function moveHandler(e) {
1508
- return onMove(e.clientX);
1509
- },
1510
- upHandler: function upHandler(e) {
1511
- document.removeEventListener('mousemove', mouseEvents.moveHandler);
1512
- document.removeEventListener('mouseup', mouseEvents.upHandler);
1513
- onEnd(e.clientX);
1514
- }
1515
- };
1516
- var touchEvents = {
1517
- moveHandler: function moveHandler(e) {
1518
- if (e.cancelable) {
1519
- e.preventDefault();
1520
- e.stopPropagation();
1521
- }
1979
+ function includesStringSensitive(rows, columnIds, filterValue) {
1980
+ var search = String(filterValue);
1981
+ rows = rows.filter(function (row) {
1982
+ return columnIds.some(function (id) {
1983
+ return String(row.values[id]).includes(search);
1984
+ });
1985
+ });
1986
+ return rows;
1987
+ }
1988
+
1989
+ includesStringSensitive.autoRemove = function (val) {
1990
+ return testFalsey(val);
1991
+ };
1992
+
1993
+ function equalsString(rows, columnIds, filterValue) {
1994
+ var search = String(filterValue).toLowerCase();
1995
+ return rows.filter(function (row) {
1996
+ return columnIds.some(function (id) {
1997
+ var rowValue = row.values[id];
1998
+ return rowValue !== undefined ? String(rowValue).toLowerCase() === search : true;
1999
+ });
2000
+ });
2001
+ }
1522
2002
 
1523
- onMove(e.touches[0].clientX);
1524
- return false;
1525
- },
1526
- upHandler: function upHandler(e) {
1527
- document.removeEventListener('touchmove', touchEvents.moveHandler);
1528
- document.removeEventListener('touchend', touchEvents.upHandler);
2003
+ equalsString.autoRemove = function (val) {
2004
+ return testFalsey(val);
2005
+ };
1529
2006
 
1530
- if (e.cancelable) {
1531
- e.preventDefault();
1532
- e.stopPropagation();
1533
- }
2007
+ function equalsStringSensitive(rows, columnIds, filterValue) {
2008
+ var search = String(filterValue);
2009
+ return rows.filter(function (row) {
2010
+ return columnIds.some(function (id) {
2011
+ var rowValue = row.values[id];
2012
+ return rowValue !== undefined ? String(rowValue) === search : true;
2013
+ });
2014
+ });
2015
+ }
1534
2016
 
1535
- onEnd(e.touches[0].clientX);
1536
- }
1537
- };
1538
- var passiveIfSupported = passiveEventSupported() ? {
1539
- passive: false
1540
- } : false;
2017
+ equalsStringSensitive.autoRemove = function (val) {
2018
+ return testFalsey(val);
2019
+ };
1541
2020
 
1542
- if (isTouchStartEvent(e)) {
1543
- document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
1544
- document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
1545
- } else {
1546
- document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
1547
- document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
1548
- }
2021
+ function arrIncludes(rows, columnIds, filterValue) {
2022
+ return rows.filter(function (row) {
2023
+ return columnIds.some(function (id) {
2024
+ var rowValue = row.values[id];
2025
+ return rowValue.includes(filterValue);
2026
+ });
2027
+ });
2028
+ }
1549
2029
 
1550
- instance.setColumnSizingInfo(function (old) {
1551
- return _extends({}, old, {
1552
- startOffset: clientX,
1553
- startSize: header.getWidth(),
1554
- deltaOffset: 0,
1555
- deltaPercentage: 0,
1556
- columnSizingStart: columnSizingStart,
1557
- isResizingColumn: header.column.id
1558
- });
1559
- });
1560
- };
2030
+ arrIncludes.autoRemove = function (val) {
2031
+ return testFalsey(val) || !(val != null && val.length);
2032
+ };
1561
2033
 
1562
- var initialProps = canResize ? {
1563
- title: 'Toggle Grouping',
1564
- draggable: false,
1565
- role: 'separator',
1566
- onMouseDown: function onMouseDown(e) {
1567
- e.persist();
1568
- onResizeStart(e);
1569
- },
1570
- onTouchStart: function onTouchStart(e) {
1571
- e.persist();
1572
- onResizeStart(e);
1573
- }
1574
- } : {};
1575
- return propGetter(initialProps, userProps);
1576
- }
1577
- };
2034
+ function arrIncludesAll(rows, columnIds, filterValue) {
2035
+ return rows.filter(function (row) {
2036
+ return columnIds.some(function (id) {
2037
+ var rowValue = row.values[id];
2038
+ return rowValue && rowValue.length && filterValue.every(function (val) {
2039
+ return rowValue.includes(val);
2040
+ });
2041
+ });
2042
+ });
1578
2043
  }
1579
- function createColumn$2(column, instance) {
1580
- return {
1581
- getIsResizing: function getIsResizing() {
1582
- return instance.getColumnIsResizing(column.id);
1583
- },
1584
- getCanResize: function getCanResize() {
1585
- return instance.getColumnCanResize(column.id);
1586
- },
1587
- resetSize: function resetSize() {
1588
- return instance.resetColumnSize(column.id);
1589
- }
1590
- };
2044
+
2045
+ arrIncludesAll.autoRemove = function (val) {
2046
+ return testFalsey(val) || !(val != null && val.length);
2047
+ };
2048
+
2049
+ function equals(rows, columnIds, filterValue) {
2050
+ return rows.filter(function (row) {
2051
+ return columnIds.some(function (id) {
2052
+ var rowValue = row.values[id];
2053
+ return rowValue === filterValue;
2054
+ });
2055
+ });
1591
2056
  }
1592
- function createHeader(header, instance) {
1593
- return {
1594
- getIsResizing: function getIsResizing() {
1595
- return instance.getHeaderIsResizing(header.id);
1596
- },
1597
- getCanResize: function getCanResize() {
1598
- return instance.getHeaderCanResize(header.id);
1599
- },
1600
- getResizerProps: function getResizerProps(userProps) {
1601
- return instance.getHeaderResizerProps(header.id, userProps);
1602
- },
1603
- resetSize: function resetSize() {
1604
- return instance.resetHeaderSize(header.id);
1605
- }
1606
- };
2057
+
2058
+ equals.autoRemove = function (val) {
2059
+ return testFalsey(val);
2060
+ };
2061
+
2062
+ function weakEquals(rows, columnIds, filterValue) {
2063
+ return rows.filter(function (row) {
2064
+ return columnIds.some(function (id) {
2065
+ var rowValue = row.values[id]; // eslint-disable-next-line eqeqeq
2066
+
2067
+ return rowValue == filterValue;
2068
+ });
2069
+ });
1607
2070
  }
1608
- var passiveSupported = null;
1609
- function passiveEventSupported() {
1610
- if (typeof passiveSupported === 'boolean') return passiveSupported;
1611
- var supported = false;
1612
2071
 
1613
- try {
1614
- var options = {
1615
- get passive() {
1616
- supported = true;
1617
- return false;
1618
- }
2072
+ weakEquals.autoRemove = function (val) {
2073
+ return testFalsey(val);
2074
+ };
1619
2075
 
1620
- };
2076
+ function betweenNumberRange(rows, columnIds, filterValue) {
2077
+ var _ref = filterValue || [],
2078
+ unsafeMin = _ref[0],
2079
+ unsafeMax = _ref[1];
1621
2080
 
1622
- var noop = function noop() {};
2081
+ var parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
2082
+ var parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
2083
+ var min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
2084
+ var max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
1623
2085
 
1624
- window.addEventListener('test', noop, options);
1625
- window.removeEventListener('test', noop);
1626
- } catch (err) {
1627
- supported = false;
2086
+ if (min > max) {
2087
+ var temp = min;
2088
+ min = max;
2089
+ max = temp;
1628
2090
  }
1629
2091
 
1630
- passiveSupported = supported;
1631
- return passiveSupported;
2092
+ return rows.filter(function (row) {
2093
+ return columnIds.some(function (id) {
2094
+ var rowValue = row.values[id];
2095
+ return rowValue >= min && rowValue <= max;
2096
+ });
2097
+ });
1632
2098
  }
1633
2099
 
1634
- function isTouchStartEvent(e) {
1635
- return e.type === 'touchstart';
2100
+ betweenNumberRange.autoRemove = function (val) {
2101
+ return testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
2102
+ }; // Utils
2103
+
2104
+
2105
+ function testFalsey(val) {
2106
+ return val === undefined || val === null || val === '';
1636
2107
  }
1637
2108
 
1638
2109
  //
1639
- function createRow$1(row, instance) {
2110
+ function getDefaultColumn$1() {
1640
2111
  return {
1641
- _getAllVisibleCells: memo(function () {
1642
- return [row.getAllCells().filter(function (cell) {
1643
- return cell.column.getIsVisible();
1644
- }).map(function (d) {
1645
- return d.id;
1646
- }).join('_')];
1647
- }, function (_) {
1648
- return row.getAllCells().filter(function (cell) {
1649
- return cell.column.getIsVisible();
1650
- });
1651
- }, 'row._getAllVisibleCells', instance.options.debug),
1652
- getVisibleCells: memo(function () {
1653
- return [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()];
1654
- }, function (left, center, right) {
1655
- return [].concat(left, center, right);
1656
- }, 'row.getVisibleCells', instance.options.debug),
1657
- getCenterVisibleCells: memo(function () {
1658
- return [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1659
- }, function (allCells, left, right) {
1660
- var leftAndRight = [].concat(left != null ? left : [], right != null ? right : []);
1661
- return allCells.filter(function (d) {
1662
- return !leftAndRight.includes(d.columnId);
1663
- });
1664
- }, 'row.getCenterVisibleCells', instance.options.debug),
1665
- getLeftVisibleCells: memo(function () {
1666
- return [row._getAllVisibleCells(), instance.getState().columnPinning.left,,];
1667
- }, function (allCells, left) {
1668
- var cells = (left != null ? left : []).map(function (columnId) {
1669
- return allCells.find(function (cell) {
1670
- return cell.columnId === columnId;
1671
- });
1672
- }).filter(Boolean);
1673
- return cells;
1674
- }, 'row.getLeftVisibleCells', instance.options.debug),
1675
- getRightVisibleCells: memo(function () {
1676
- return [row._getAllVisibleCells(), instance.getState().columnPinning.right];
1677
- }, function (allCells, right) {
1678
- var cells = (right != null ? right : []).map(function (columnId) {
1679
- return allCells.find(function (cell) {
1680
- return cell.columnId === columnId;
1681
- });
1682
- }).filter(Boolean);
1683
- return cells;
1684
- }, 'row.getRightVisibleCells', instance.options.debug)
2112
+ filterType: 'auto'
1685
2113
  };
1686
2114
  }
1687
- function getInstance$3(instance) {
2115
+ function getInitialState$5() {
1688
2116
  return {
1689
- createHeader: function createHeader$1(column, options) {
1690
- var _options$id;
2117
+ columnFilters: [],
2118
+ globalFilter: undefined
2119
+ };
2120
+ }
2121
+ function getDefaultOptions$5(instance) {
2122
+ return {
2123
+ onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
2124
+ onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
2125
+ autoResetColumnFilters: true,
2126
+ filterFromChildrenUp: true,
2127
+ autoResetGlobalFilter: true,
2128
+ globalFilterType: 'auto',
2129
+ getColumnCanGlobalFilterFn: function getColumnCanGlobalFilterFn(column) {
2130
+ var _instance$getCoreFlat, _instance$getCoreFlat2;
2131
+
2132
+ var value = (_instance$getCoreFlat = instance.getCoreFlatRows()[0]) == null ? void 0 : (_instance$getCoreFlat2 = _instance$getCoreFlat.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreFlat2.value;
2133
+ return typeof value === 'string';
2134
+ }
2135
+ };
2136
+ }
2137
+ function createColumn$2(column, instance) {
2138
+ var getFacetInfo = memo(function () {
2139
+ return [column.getPreFilteredRows()];
2140
+ }, function (rows) {
2141
+ var _rows$0$values$column, _rows$, _rows$0$values$column2, _rows$2;
2142
+
2143
+ if (rows === void 0) {
2144
+ rows = [];
2145
+ }
1691
2146
 
1692
- var id = (_options$id = options.id) != null ? _options$id : column.id;
1693
- var header = {
1694
- id: id,
1695
- column: column,
1696
- isPlaceholder: options.isPlaceholder,
1697
- placeholderId: options.placeholderId,
1698
- depth: options.depth,
1699
- subHeaders: [],
1700
- colSpan: 0,
1701
- rowSpan: 0,
1702
- getWidth: function getWidth() {
1703
- var sum = 0;
2147
+ var preFilteredUniqueValues = new Map();
2148
+ var preFilteredMinMaxValues = [(_rows$0$values$column = (_rows$ = rows[0]) == null ? void 0 : _rows$.values[column.id]) != null ? _rows$0$values$column : null, (_rows$0$values$column2 = (_rows$2 = rows[0]) == null ? void 0 : _rows$2.values[column.id]) != null ? _rows$0$values$column2 : null];
1704
2149
 
1705
- var recurse = function recurse(header) {
1706
- if (header.subHeaders.length) {
1707
- header.subHeaders.forEach(recurse);
1708
- } else {
1709
- var _header$column$getWid;
2150
+ for (var i = 0; i < rows.length; i++) {
2151
+ var _rows$i;
1710
2152
 
1711
- sum += (_header$column$getWid = header.column.getWidth()) != null ? _header$column$getWid : 0;
1712
- }
1713
- };
2153
+ var _value = (_rows$i = rows[i]) == null ? void 0 : _rows$i.values[column.id];
1714
2154
 
1715
- recurse(header);
1716
- return sum;
1717
- },
1718
- getLeafHeaders: function getLeafHeaders() {
1719
- var leafHeaders = [];
2155
+ if (preFilteredUniqueValues.has(_value)) {
2156
+ var _preFilteredUniqueVal;
1720
2157
 
1721
- var recurseHeader = function recurseHeader(h) {
1722
- if (h.subHeaders && h.subHeaders.length) {
1723
- h.subHeaders.map(recurseHeader);
1724
- }
2158
+ preFilteredUniqueValues.set(_value, ((_preFilteredUniqueVal = preFilteredUniqueValues.get(_value)) != null ? _preFilteredUniqueVal : 0) + 1);
2159
+ } else {
2160
+ preFilteredUniqueValues.set(_value, 1);
2161
+ }
1725
2162
 
1726
- leafHeaders.push(h);
1727
- };
2163
+ if (_value < preFilteredMinMaxValues[0]) {
2164
+ preFilteredMinMaxValues[0] = _value;
2165
+ } else if (_value > preFilteredMinMaxValues[1]) {
2166
+ preFilteredMinMaxValues[1] = _value;
2167
+ }
2168
+ }
1728
2169
 
1729
- recurseHeader(header);
1730
- return leafHeaders;
1731
- },
1732
- getHeaderProps: function getHeaderProps(userProps) {
1733
- return instance.getHeaderProps(header.id, userProps);
1734
- },
1735
- getFooterProps: function getFooterProps(userProps) {
1736
- return instance.getFooterProps(header.id, userProps);
1737
- },
1738
- renderHeader: function renderHeader() {
1739
- return flexRender(column.header, {
1740
- header: header,
1741
- column: column
1742
- });
1743
- },
1744
- renderFooter: function renderFooter() {
1745
- return flexRender(column.footer, {
1746
- header: header,
1747
- column: column
1748
- });
2170
+ return {
2171
+ preFilteredUniqueValues: preFilteredUniqueValues,
2172
+ preFilteredMinMaxValues: preFilteredMinMaxValues
2173
+ };
2174
+ }, {
2175
+ key: 'column.getFacetInfo',
2176
+ debug: instance.options.debug
2177
+ });
2178
+ return {
2179
+ filterType: column.filterType,
2180
+ getCanColumnFilter: function getCanColumnFilter() {
2181
+ return instance.getColumnCanColumnFilter(column.id);
2182
+ },
2183
+ getCanGlobalFilter: function getCanGlobalFilter() {
2184
+ return instance.getColumnCanGlobalFilter(column.id);
2185
+ },
2186
+ getColumnFilterIndex: function getColumnFilterIndex() {
2187
+ return instance.getColumnFilterIndex(column.id);
2188
+ },
2189
+ getIsColumnFiltered: function getIsColumnFiltered() {
2190
+ return instance.getColumnIsFiltered(column.id);
2191
+ },
2192
+ getColumnFilterValue: function getColumnFilterValue() {
2193
+ return instance.getColumnFilterValue(column.id);
2194
+ },
2195
+ setColumnFilterValue: function setColumnFilterValue(val) {
2196
+ return instance.setColumnFilterValue(column.id, val);
2197
+ },
2198
+ getPreFilteredUniqueValues: function getPreFilteredUniqueValues() {
2199
+ return getFacetInfo().preFilteredUniqueValues;
2200
+ },
2201
+ getPreFilteredMinMaxValues: function getPreFilteredMinMaxValues() {
2202
+ return getFacetInfo().preFilteredMinMaxValues;
2203
+ },
2204
+ getPreFilteredRows: function getPreFilteredRows() {
2205
+ return undefined;
2206
+ }
2207
+ };
2208
+ }
2209
+ function getInstance$5(instance) {
2210
+ var registered = false;
2211
+ return {
2212
+ _notifyFiltersReset: function _notifyFiltersReset() {
2213
+ if (!registered) {
2214
+ registered = true;
2215
+ return;
2216
+ }
2217
+
2218
+ if (instance.options.autoResetAll === false) {
2219
+ return;
2220
+ }
2221
+
2222
+ if (instance.options.autoResetAll === true) {
2223
+ instance.resetSorting();
2224
+ } else {
2225
+ if (instance.options.autoResetColumnFilters) {
2226
+ instance.resetColumnFilters();
1749
2227
  }
1750
- };
1751
- header = Object.assign(header, createHeader(header, instance)); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
1752
2228
 
1753
- return header;
2229
+ if (instance.options.autoResetGlobalFilter) {
2230
+ instance.resetGlobalFilter();
2231
+ }
2232
+ }
1754
2233
  },
1755
- // Header Groups
1756
- getHeaderGroups: memo(function () {
1757
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1758
- }, function (allColumns, leafColumns, left, right) {
1759
- var leftColumns = leafColumns.filter(function (column) {
1760
- return left == null ? void 0 : left.includes(column.id);
1761
- });
1762
- var rightColumns = leafColumns.filter(function (column) {
1763
- return right == null ? void 0 : right.includes(column.id);
1764
- });
1765
- var centerColumns = leafColumns.filter(function (column) {
1766
- return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1767
- });
1768
- var headerGroups = buildHeaderGroups(allColumns, [].concat(leftColumns, centerColumns, rightColumns), instance);
1769
- return headerGroups;
1770
- }, 'getHeaderGroups', instance.options.debug),
1771
- getCenterHeaderGroups: memo(function () {
1772
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1773
- }, function (allColumns, leafColumns, left, right) {
1774
- leafColumns = leafColumns.filter(function (column) {
1775
- return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1776
- });
1777
- return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
1778
- }, 'getCenterHeaderGroups', instance.options.debug),
1779
- getLeftHeaderGroups: memo(function () {
1780
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left];
1781
- }, function (allColumns, leafColumns, left) {
1782
- leafColumns = leafColumns.filter(function (column) {
1783
- return left == null ? void 0 : left.includes(column.id);
1784
- });
1785
- return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
1786
- }, 'getLeftHeaderGroups', instance.options.debug),
1787
- getRightHeaderGroups: memo(function () {
1788
- return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right];
1789
- }, function (allColumns, leafColumns, right) {
1790
- leafColumns = leafColumns.filter(function (column) {
1791
- return right == null ? void 0 : right.includes(column.id);
1792
- });
1793
- return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
1794
- }, 'getRightHeaderGroups', instance.options.debug),
1795
- // Footer Groups
1796
- getFooterGroups: memo(function () {
1797
- return [instance.getHeaderGroups()];
1798
- }, function (headerGroups) {
1799
- return [].concat(headerGroups).reverse();
1800
- }, 'getFooterGroups', instance.options.debug),
1801
- getLeftFooterGroups: memo(function () {
1802
- return [instance.getLeftHeaderGroups()];
1803
- }, function (headerGroups) {
1804
- return [].concat(headerGroups).reverse();
1805
- }, 'getLeftFooterGroups', instance.options.debug),
1806
- getCenterFooterGroups: memo(function () {
1807
- return [instance.getCenterHeaderGroups()];
1808
- }, function (headerGroups) {
1809
- return [].concat(headerGroups).reverse();
1810
- }, 'getCenterFooterGroups', instance.options.debug),
1811
- getRightFooterGroups: memo(function () {
1812
- return [instance.getRightHeaderGroups()];
1813
- }, function (headerGroups) {
1814
- return [].concat(headerGroups).reverse();
1815
- }, 'getRightFooterGroups', instance.options.debug),
1816
- // Flat Headers
1817
- getFlatHeaders: memo(function () {
1818
- return [instance.getHeaderGroups()];
1819
- }, function (headerGroups) {
1820
- return headerGroups.map(function (headerGroup) {
1821
- return headerGroup.headers;
1822
- }).flat();
1823
- }, 'getFlatHeaders', instance.options.debug),
1824
- getLeftFlatHeaders: memo(function () {
1825
- return [instance.getLeftHeaderGroups()];
1826
- }, function (left) {
1827
- return left.map(function (headerGroup) {
1828
- return headerGroup.headers;
1829
- }).flat();
1830
- }, 'getLeftFlatHeaders', instance.options.debug),
1831
- getCenterFlatHeaders: memo(function () {
1832
- return [instance.getCenterHeaderGroups()];
1833
- }, function (left) {
1834
- return left.map(function (headerGroup) {
1835
- return headerGroup.headers;
1836
- }).flat();
1837
- }, 'getCenterFlatHeaders', instance.options.debug),
1838
- getRightFlatHeaders: memo(function () {
1839
- return [instance.getRightHeaderGroups()];
1840
- }, function (left) {
1841
- return left.map(function (headerGroup) {
1842
- return headerGroup.headers;
1843
- }).flat();
1844
- }, 'getRightFlatHeaders', instance.options.debug),
1845
- // Leaf Headers
1846
- getCenterLeafHeaders: memo(function () {
1847
- return [instance.getCenterFlatHeaders()];
1848
- }, function (flatHeaders) {
1849
- return flatHeaders.filter(function (header) {
1850
- var _header$subHeaders;
2234
+ getColumnAutoFilterFn: function getColumnAutoFilterFn(columnId) {
2235
+ var firstRow = instance.getCoreFlatRows()[0];
2236
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
1851
2237
 
1852
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
1853
- });
1854
- }, 'getCenterLeafHeaders', instance.options.debug),
1855
- getLeftLeafHeaders: memo(function () {
1856
- return [instance.getLeftFlatHeaders()];
1857
- }, function (flatHeaders) {
1858
- return flatHeaders.filter(function (header) {
1859
- var _header$subHeaders2;
2238
+ if (typeof value === 'string') {
2239
+ return filterTypes.includesString;
2240
+ }
1860
2241
 
1861
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
1862
- });
1863
- }, 'getLeftLeafHeaders', instance.options.debug),
1864
- getRightLeafHeaders: memo(function () {
1865
- return [instance.getRightFlatHeaders()];
1866
- }, function (flatHeaders) {
1867
- return flatHeaders.filter(function (header) {
1868
- var _header$subHeaders3;
2242
+ if (typeof value === 'number') {
2243
+ return filterTypes.betweenNumberRange;
2244
+ }
1869
2245
 
1870
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
1871
- });
1872
- }, 'getRightLeafHeaders', instance.options.debug),
1873
- getLeafHeaders: memo(function () {
1874
- return [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()];
1875
- }, function (left, center, right) {
1876
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
2246
+ if (value !== null && typeof value === 'object') {
2247
+ return filterTypes.equals;
2248
+ }
1877
2249
 
1878
- return [].concat((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : [], (_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : [], (_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : []).map(function (header) {
1879
- return header.getLeafHeaders();
1880
- }).flat();
1881
- }, 'getLeafHeaders', instance.options.debug),
1882
- getHeader: function getHeader(id) {
1883
- var header = [].concat(instance.getFlatHeaders(), instance.getCenterFlatHeaders(), instance.getLeftFlatHeaders(), instance.getRightFlatHeaders()).find(function (d) {
1884
- return d.id === id;
1885
- });
2250
+ if (Array.isArray(value)) {
2251
+ return filterTypes.arrIncludes;
2252
+ }
1886
2253
 
1887
- if (!header) {
1888
- {
1889
- console.warn("Could not find header with id: " + id);
1890
- }
2254
+ return filterTypes.weakEquals;
2255
+ },
2256
+ getGlobalAutoFilterFn: function getGlobalAutoFilterFn() {
2257
+ return filterTypes.includesString;
2258
+ },
2259
+ getColumnFilterFn: function getColumnFilterFn(columnId) {
2260
+ var _ref;
2261
+
2262
+ var column = instance.getColumn(columnId);
2263
+ var userFilterTypes = instance.options.filterTypes;
1891
2264
 
2265
+ if (!column) {
1892
2266
  throw new Error();
1893
2267
  }
1894
2268
 
1895
- return header;
2269
+ return isFunction(column.filterType) ? column.filterType : column.filterType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userFilterTypes == null ? void 0 : userFilterTypes[column.filterType]) != null ? _ref : filterTypes[column.filterType];
1896
2270
  },
1897
- getHeaderGroupProps: function getHeaderGroupProps(id, userProps) {
1898
- var headerGroup = instance.getHeaderGroups().find(function (d) {
1899
- return d.id === id;
1900
- });
1901
-
1902
- if (!headerGroup) {
1903
- return;
1904
- }
2271
+ getGlobalFilterFn: function getGlobalFilterFn() {
2272
+ var _ref2;
1905
2273
 
1906
- return propGetter({
1907
- key: headerGroup.id,
1908
- role: 'row'
1909
- }, userProps);
2274
+ var _instance$options = instance.options,
2275
+ userFilterTypes = _instance$options.filterTypes,
2276
+ globalFilterType = _instance$options.globalFilterType;
2277
+ return isFunction(globalFilterType) ? globalFilterType : globalFilterType === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterTypes == null ? void 0 : userFilterTypes[globalFilterType]) != null ? _ref2 : filterTypes[globalFilterType];
1910
2278
  },
1911
- getFooterGroupProps: function getFooterGroupProps(id, userProps) {
1912
- var headerGroup = instance.getFooterGroups().find(function (d) {
1913
- return d.id === id;
1914
- });
2279
+ setColumnFilters: function setColumnFilters(updater) {
2280
+ var leafColumns = instance.getAllLeafColumns();
1915
2281
 
1916
- if (!headerGroup) {
1917
- return;
1918
- }
2282
+ var updateFn = function updateFn(old) {
2283
+ var _functionalUpdate;
1919
2284
 
1920
- var initialProps = {
1921
- key: headerGroup.id,
1922
- role: 'row'
2285
+ return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(function (filter) {
2286
+ var column = leafColumns.find(function (d) {
2287
+ return d.id === filter.id;
2288
+ });
2289
+
2290
+ if (column) {
2291
+ var filterFn = instance.getColumnFilterFn(column.id);
2292
+
2293
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
2294
+ return false;
2295
+ }
2296
+ }
2297
+
2298
+ return true;
2299
+ });
1923
2300
  };
1924
- return propGetter(initialProps, userProps);
2301
+
2302
+ instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn, updateFn(instance.getState().columnFilters));
1925
2303
  },
1926
- getHeaderProps: function getHeaderProps(id, userProps) {
1927
- var header = instance.getHeader(id);
2304
+ setGlobalFilter: function setGlobalFilter(updater) {
2305
+ instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater, functionalUpdate(updater, instance.getState().globalFilter));
2306
+ },
2307
+ resetGlobalFilter: function resetGlobalFilter() {
2308
+ instance.setGlobalFilter(undefined);
2309
+ },
2310
+ getColumnCanColumnFilter: function getColumnCanColumnFilter(columnId) {
2311
+ var _ref3, _ref4, _ref5, _ref6, _ref7, _column$enableAllFilt;
1928
2312
 
1929
- if (!header) {
2313
+ var column = instance.getColumn(columnId);
2314
+
2315
+ if (!column) {
1930
2316
  throw new Error();
1931
2317
  }
1932
2318
 
1933
- var initialProps = {
1934
- key: header.id,
1935
- role: 'columnheader',
1936
- colSpan: header.colSpan,
1937
- rowSpan: header.rowSpan
1938
- };
1939
- return propGetter(initialProps, userProps);
2319
+ return (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_ref7 = (_column$enableAllFilt = column.enableAllFilters) != null ? _column$enableAllFilt : column.enableColumnFilter) != null ? _ref7 : instance.options.enableFilters) != null ? _ref6 : instance.options.enableColumnFilters) != null ? _ref5 : column.defaultCanFilter) != null ? _ref4 : column.defaultCanColumnFilter) != null ? _ref3 : !!column.accessorFn;
1940
2320
  },
1941
- getFooterProps: function getFooterProps(id, userProps) {
1942
- var header = instance.getHeader(id);
2321
+ getColumnCanGlobalFilter: function getColumnCanGlobalFilter(columnId) {
2322
+ var _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _instance$options$ena;
1943
2323
 
1944
- if (!header) {
1945
- return;
2324
+ var column = instance.getColumn(columnId);
2325
+
2326
+ if (!column) {
2327
+ throw new Error();
1946
2328
  }
1947
2329
 
1948
- var initialProps = {
1949
- key: header.id,
1950
- role: 'columnfooter',
1951
- colSpan: header.colSpan,
1952
- rowSpan: header.rowSpan
1953
- };
1954
- return propGetter(initialProps, userProps);
2330
+ return (_ref8 = ((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_instance$options$ena = instance.options.enableFilters) != null ? _instance$options$ena : instance.options.enableGlobalFilter) != null ? _ref13 : column.enableAllFilters) != null ? _ref12 : column.enableGlobalFilter) != null ? _ref11 : column.defaultCanFilter) != null ? _ref10 : column.defaultCanGlobalFilter) != null ? _ref9 : !!column.accessorFn) && (instance.options.getColumnCanGlobalFilterFn == null ? void 0 : instance.options.getColumnCanGlobalFilterFn(column))) != null ? _ref8 : true;
1955
2331
  },
1956
- getTotalWidth: function getTotalWidth() {
1957
- var width = 0;
1958
- instance.getVisibleLeafColumns().forEach(function (column) {
1959
- var _column$getWidth;
2332
+ getColumnIsFiltered: function getColumnIsFiltered(columnId) {
2333
+ return instance.getColumnFilterIndex(columnId) > -1;
2334
+ },
2335
+ getColumnFilterValue: function getColumnFilterValue(columnId) {
2336
+ var _instance$getState$co, _instance$getState$co2;
1960
2337
 
1961
- width += (_column$getWidth = column.getWidth()) != null ? _column$getWidth : 0;
1962
- });
1963
- return width;
1964
- }
1965
- };
1966
- }
1967
- function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
1968
- var _headerGroups$0$heade, _headerGroups$;
2338
+ return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(function (d) {
2339
+ return d.id === columnId;
2340
+ })) == null ? void 0 : _instance$getState$co2.value;
2341
+ },
2342
+ getColumnFilterIndex: function getColumnFilterIndex(columnId) {
2343
+ var _instance$getState$co3, _instance$getState$co4;
1969
2344
 
1970
- // Find the max depth of the columns:
1971
- // build the leaf column row
1972
- // build each buffer row going up
1973
- // placeholder for non-existent level
1974
- // real column for existing level
1975
- var maxDepth = 0;
2345
+ return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(function (d) {
2346
+ return d.id === columnId;
2347
+ })) != null ? _instance$getState$co3 : -1;
2348
+ },
2349
+ setColumnFilterValue: function setColumnFilterValue(columnId, value) {
2350
+ if (!columnId) return;
2351
+ instance.setColumnFilters(function (old) {
2352
+ var column = instance.getColumn(columnId);
1976
2353
 
1977
- var findMaxDepth = function findMaxDepth(columns, depth) {
1978
- if (depth === void 0) {
1979
- depth = 1;
1980
- }
2354
+ if (!column) {
2355
+ {
2356
+ console.warn("React-Table: Could not find a column with id: " + columnId);
2357
+ }
1981
2358
 
1982
- maxDepth = Math.max(maxDepth, depth);
1983
- columns.filter(function (column) {
1984
- return column.getIsVisible();
1985
- }).forEach(function (column) {
1986
- var _column$columns;
2359
+ throw new Error();
2360
+ }
1987
2361
 
1988
- if ((_column$columns = column.columns) != null && _column$columns.length) {
1989
- findMaxDepth(column.columns, depth + 1);
1990
- }
1991
- }, 0);
1992
- };
2362
+ var filterFn = instance.getColumnFilterFn(column.id);
2363
+ var previousfilter = old == null ? void 0 : old.find(function (d) {
2364
+ return d.id === columnId;
2365
+ });
2366
+ var newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
1993
2367
 
1994
- findMaxDepth(allColumns);
1995
- var headerGroups = [];
2368
+ if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
2369
+ var _old$filter;
1996
2370
 
1997
- var createHeaderGroup = function createHeaderGroup(headersToGroup, depth) {
1998
- // The header group we are creating
1999
- var headerGroup = {
2000
- depth: depth,
2001
- id: [headerFamily, "" + depth].filter(Boolean).join('_'),
2002
- headers: [],
2003
- getHeaderGroupProps: function getHeaderGroupProps(getterValue) {
2004
- return instance.getHeaderGroupProps("" + depth, getterValue);
2005
- },
2006
- getFooterGroupProps: function getFooterGroupProps(getterValue) {
2007
- return instance.getFooterGroupProps("" + depth, getterValue);
2008
- }
2009
- }; // The parent columns we're going to scan next
2371
+ return (_old$filter = old == null ? void 0 : old.filter(function (d) {
2372
+ return d.id !== columnId;
2373
+ })) != null ? _old$filter : [];
2374
+ }
2010
2375
 
2011
- var parentHeaders = []; // Scan each column for parents
2376
+ var newFilterObj = {
2377
+ id: columnId,
2378
+ value: newFilter
2379
+ };
2012
2380
 
2013
- headersToGroup.forEach(function (headerToGroup) {
2014
- // What is the latest (last) parent column?
2015
- var latestParentHeader = [].concat(parentHeaders).reverse()[0];
2016
- var isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
2017
- var column;
2018
- var isPlaceholder = false;
2381
+ if (previousfilter) {
2382
+ var _old$map;
2019
2383
 
2020
- if (isLeafHeader && headerToGroup.column.parent) {
2021
- // The parent header is new
2022
- column = headerToGroup.column.parent;
2023
- } else {
2024
- // The parent header is repeated
2025
- column = headerToGroup.column;
2026
- isPlaceholder = true;
2027
- }
2384
+ return (_old$map = old == null ? void 0 : old.map(function (d) {
2385
+ if (d.id === columnId) {
2386
+ return newFilterObj;
2387
+ }
2028
2388
 
2029
- var header = instance.createHeader(column, {
2030
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
2031
- isPlaceholder: isPlaceholder,
2032
- placeholderId: isPlaceholder ? "" + parentHeaders.filter(function (d) {
2033
- return d.column === column;
2034
- }).length : undefined,
2035
- depth: depth
2389
+ return d;
2390
+ })) != null ? _old$map : [];
2391
+ }
2392
+
2393
+ if (old != null && old.length) {
2394
+ return [].concat(old, [newFilterObj]);
2395
+ }
2396
+
2397
+ return [newFilterObj];
2036
2398
  });
2399
+ },
2400
+ resetColumnFilters: function resetColumnFilters() {
2401
+ var _instance$options$ini, _instance$options2, _instance$options2$in;
2037
2402
 
2038
- if (!latestParentHeader || latestParentHeader.column !== header.column) {
2039
- header.subHeaders.push(headerToGroup);
2040
- parentHeaders.push(header);
2041
- } else {
2042
- latestParentHeader.subHeaders.push(headerToGroup);
2043
- } // if (!headerToGroup.isPlaceholder) {
2044
- // headerToGroup.column.header = headerToGroup;
2045
- // }
2403
+ instance.setColumnFilters((_instance$options$ini = (_instance$options2 = instance.options) == null ? void 0 : (_instance$options2$in = _instance$options2.initialState) == null ? void 0 : _instance$options2$in.columnFilters) != null ? _instance$options$ini : []);
2404
+ },
2405
+ getColumnFilteredRowModel: memo(function () {
2406
+ return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
2407
+ }, function (columnFilters, rowModel, columnFiltersFn) {
2408
+ var columnFilteredRowModel = function () {
2409
+ if (!(columnFilters != null && columnFilters.length) || !columnFiltersFn) {
2410
+ return rowModel;
2411
+ }
2412
+
2413
+ if (instance.options.debug) console.info('Column Filtering...');
2414
+ return columnFiltersFn(instance, rowModel);
2415
+ }(); // Now that each filtered column has it's partially filtered rows,
2416
+ // lets assign the final filtered rows to all of the other columns
2417
+
2418
+
2419
+ var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2420
+ var _instance$getState$co5;
2421
+
2422
+ return !((_instance$getState$co5 = instance.getState().columnFilters) != null && _instance$getState$co5.find(function (d) {
2423
+ return d.id === column.id;
2424
+ }));
2425
+ }); // This essentially enables faceted filter options to be built easily
2426
+ // using every column's preFilteredRows value
2046
2427
 
2428
+ nonFilteredColumns.forEach(function (column) {
2429
+ column.getPreFilteredRows = function () {
2430
+ return columnFilteredRowModel.rows;
2431
+ };
2432
+ });
2433
+ return columnFilteredRowModel;
2434
+ }, {
2435
+ key: 'getColumnFilteredRowModel',
2436
+ debug: instance.options.debug
2437
+ }),
2438
+ // These might be easier to remember than "column" filtered rows
2439
+ getPreFilteredRowModel: function getPreFilteredRowModel() {
2440
+ return instance.getCoreRowModel();
2441
+ },
2442
+ getPreFilteredRows: function getPreFilteredRows() {
2443
+ return instance.getCoreRowModel().rows;
2444
+ },
2445
+ getPreFilteredFlatRows: function getPreFilteredFlatRows() {
2446
+ return instance.getCoreRowModel().flatRows;
2447
+ },
2448
+ getPreFilteredRowsById: function getPreFilteredRowsById() {
2449
+ return instance.getCoreRowModel().rowsById;
2450
+ },
2451
+ // Pre Column Filter
2452
+ getPreColumnFilteredRows: function getPreColumnFilteredRows() {
2453
+ return instance.getCoreRowModel().rows;
2454
+ },
2455
+ getPreColumnFilteredFlatRows: function getPreColumnFilteredFlatRows() {
2456
+ return instance.getCoreRowModel().flatRows;
2457
+ },
2458
+ getPreColumnFilteredRowsById: function getPreColumnFilteredRowsById() {
2459
+ return instance.getCoreRowModel().rowsById;
2460
+ },
2461
+ getColumnFilteredRows: function getColumnFilteredRows() {
2462
+ return instance.getColumnFilteredRowModel().rows;
2463
+ },
2464
+ getColumnFilteredFlatRows: function getColumnFilteredFlatRows() {
2465
+ return instance.getColumnFilteredRowModel().flatRows;
2466
+ },
2467
+ getColumnFilteredRowsById: function getColumnFilteredRowsById() {
2468
+ return instance.getColumnFilteredRowModel().rowsById;
2469
+ },
2470
+ getGlobalFilteredRowModel: memo(function () {
2471
+ return [instance.getState().globalFilter, instance.getColumnFilteredRowModel(), instance.options.globalFilterRowsFn];
2472
+ }, function (globalFilterValue, columnFilteredRowModel, globalFiltersFn) {
2473
+ var globalFilteredRowModel = function () {
2474
+ if (!globalFiltersFn || !globalFilterValue) {
2475
+ return columnFilteredRowModel;
2476
+ }
2047
2477
 
2048
- headerGroup.headers.push(headerToGroup);
2049
- });
2050
- headerGroups.push(headerGroup);
2478
+ if (instance.options.debug) console.info('Global Filtering...');
2479
+ return globalFiltersFn(instance, columnFilteredRowModel);
2480
+ }(); // Now that each filtered column has it's partially filtered rows,
2481
+ // lets assign the final filtered rows to all of the other columns
2051
2482
 
2052
- if (depth > 0) {
2053
- createHeaderGroup(parentHeaders, depth - 1);
2054
- }
2055
- };
2056
2483
 
2057
- var bottomHeaders = columnsToGroup.map(function (column) {
2058
- return instance.createHeader(column, {
2059
- depth: maxDepth
2060
- });
2061
- });
2062
- createHeaderGroup(bottomHeaders, maxDepth - 1);
2063
- headerGroups.reverse(); // headerGroups = headerGroups.filter(headerGroup => {
2064
- // return !headerGroup.headers.every(header => header.isPlaceholder)
2065
- // })
2484
+ var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2485
+ var _instance$getState$co6;
2066
2486
 
2067
- var recurseHeadersForSpans = function recurseHeadersForSpans(headers) {
2068
- var filteredHeaders = headers.filter(function (header) {
2069
- return header.column.getIsVisible();
2070
- });
2071
- return filteredHeaders.map(function (header) {
2072
- var colSpan = 0;
2073
- var rowSpan = 0;
2074
- var childRowSpans = [0];
2487
+ return !((_instance$getState$co6 = instance.getState().columnFilters) != null && _instance$getState$co6.find(function (d) {
2488
+ return d.id === column.id;
2489
+ }));
2490
+ }); // This essentially enables faceted filter options to be built easily
2491
+ // using every column's preFilteredRows value
2075
2492
 
2076
- if (header.subHeaders && header.subHeaders.length) {
2077
- childRowSpans = [];
2078
- recurseHeadersForSpans(header.subHeaders).forEach(function (_ref) {
2079
- var childColSpan = _ref.colSpan,
2080
- childRowSpan = _ref.rowSpan;
2081
- colSpan += childColSpan;
2082
- childRowSpans.push(childRowSpan);
2083
- });
2084
- } else {
2085
- colSpan = 1;
2493
+ nonFilteredColumns.forEach(function (column) {
2494
+ column.getPreFilteredRows = function () {
2495
+ return globalFilteredRowModel.rows;
2496
+ };
2497
+ });
2498
+ return globalFilteredRowModel;
2499
+ }, {
2500
+ key: 'getGlobalFilteredRowModel',
2501
+ debug: instance.options.debug,
2502
+ onChange: function onChange() {
2503
+ return instance._notifySortingReset();
2086
2504
  }
2087
-
2088
- var minChildRowSpan = Math.min.apply(Math, childRowSpans);
2089
- rowSpan = rowSpan + minChildRowSpan;
2090
- header.colSpan = colSpan > 0 ? colSpan : undefined;
2091
- header.rowSpan = rowSpan > 0 ? rowSpan : undefined;
2092
- return {
2093
- colSpan: colSpan,
2094
- rowSpan: rowSpan
2095
- };
2096
- });
2505
+ }),
2506
+ getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
2507
+ return instance.getColumnFilteredRowModel().rows;
2508
+ },
2509
+ getPreGlobalFilteredFlatRows: function getPreGlobalFilteredFlatRows() {
2510
+ return instance.getColumnFilteredRowModel().flatRows;
2511
+ },
2512
+ getPreGlobalFilteredRowsById: function getPreGlobalFilteredRowsById() {
2513
+ return instance.getColumnFilteredRowModel().rowsById;
2514
+ },
2515
+ getGlobalFilteredRows: function getGlobalFilteredRows() {
2516
+ return instance.getGlobalFilteredRowModel().rows;
2517
+ },
2518
+ getGlobalFilteredFlatRows: function getGlobalFilteredFlatRows() {
2519
+ return instance.getGlobalFilteredRowModel().flatRows;
2520
+ },
2521
+ getGlobalFilteredRowsById: function getGlobalFilteredRowsById() {
2522
+ return instance.getGlobalFilteredRowModel().rowsById;
2523
+ }
2097
2524
  };
2098
-
2099
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
2100
- return headerGroups;
2525
+ }
2526
+ function shouldAutoRemoveFilter(filterFn, value, column) {
2527
+ return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
2101
2528
  }
2102
2529
 
2103
- var filterTypes = {
2104
- includesString: includesString,
2105
- includesStringSensitive: includesStringSensitive,
2106
- equalsString: equalsString,
2107
- equalsStringSensitive: equalsStringSensitive,
2108
- arrIncludes: arrIncludes,
2109
- arrIncludesAll: arrIncludesAll,
2110
- equals: equals,
2111
- weakEquals: weakEquals,
2112
- betweenNumberRange: betweenNumberRange
2530
+ var Filters = /*#__PURE__*/Object.freeze({
2531
+ __proto__: null,
2532
+ getDefaultColumn: getDefaultColumn$1,
2533
+ getInitialState: getInitialState$5,
2534
+ getDefaultOptions: getDefaultOptions$5,
2535
+ createColumn: createColumn$2,
2536
+ getInstance: getInstance$5,
2537
+ shouldAutoRemoveFilter: shouldAutoRemoveFilter
2538
+ });
2539
+
2540
+ var reSplitAlphaNumeric = /([0-9]+)/gm;
2541
+ var sortTypes = {
2542
+ alphanumeric: alphanumeric,
2543
+ alphanumericCaseSensitive: alphanumericCaseSensitive,
2544
+ text: text,
2545
+ textCaseSensitive: textCaseSensitive,
2546
+ datetime: datetime,
2547
+ basic: basic
2113
2548
  };
2114
2549
 
2115
- function includesString(rows, columnIds, filterValue) {
2116
- var search = String(filterValue).toLowerCase();
2117
- rows = rows.filter(function (row) {
2118
- return columnIds.some(function (id) {
2119
- return String(row.values[id]).toLowerCase().includes(search);
2120
- });
2121
- });
2122
- return rows;
2550
+ function alphanumeric(rowA, rowB, columnId) {
2551
+ return compareAlphanumeric(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2123
2552
  }
2124
2553
 
2125
- includesString.autoRemove = function (val) {
2126
- return testFalsey(val);
2127
- };
2554
+ function alphanumericCaseSensitive(rowA, rowB, columnId) {
2555
+ return compareAlphanumeric(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2556
+ } // Mixed sorting is slow, but very inclusive of many edge cases.
2557
+ // It handles numbers, mixed alphanumeric combinations, and even
2558
+ // null, undefined, and Infinity
2128
2559
 
2129
- function includesStringSensitive(rows, columnIds, filterValue) {
2130
- var search = String(filterValue);
2131
- rows = rows.filter(function (row) {
2132
- return columnIds.some(function (id) {
2133
- return String(row.values[id]).includes(search);
2134
- });
2135
- });
2136
- return rows;
2137
- }
2138
2560
 
2139
- includesStringSensitive.autoRemove = function (val) {
2140
- return testFalsey(val);
2141
- };
2561
+ function compareAlphanumeric(aStr, bStr) {
2562
+ // Split on number groups, but keep the delimiter
2563
+ // Then remove falsey split values
2564
+ var a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2565
+ var b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
2142
2566
 
2143
- function equalsString(rows, columnIds, filterValue) {
2144
- var search = String(filterValue).toLowerCase();
2145
- return rows.filter(function (row) {
2146
- return columnIds.some(function (id) {
2147
- var rowValue = row.values[id];
2148
- return rowValue !== undefined ? String(rowValue).toLowerCase() === search : true;
2149
- });
2150
- });
2151
- }
2567
+ while (a.length && b.length) {
2568
+ var aa = a.shift();
2569
+ var bb = b.shift();
2570
+ var an = parseInt(aa, 10);
2571
+ var bn = parseInt(bb, 10);
2572
+ var combo = [an, bn].sort(); // Both are string
2152
2573
 
2153
- equalsString.autoRemove = function (val) {
2154
- return testFalsey(val);
2155
- };
2574
+ if (isNaN(combo[0])) {
2575
+ if (aa > bb) {
2576
+ return 1;
2577
+ }
2156
2578
 
2157
- function equalsStringSensitive(rows, columnIds, filterValue) {
2158
- var search = String(filterValue);
2159
- return rows.filter(function (row) {
2160
- return columnIds.some(function (id) {
2161
- var rowValue = row.values[id];
2162
- return rowValue !== undefined ? String(rowValue) === search : true;
2163
- });
2164
- });
2165
- }
2579
+ if (bb > aa) {
2580
+ return -1;
2581
+ }
2166
2582
 
2167
- equalsStringSensitive.autoRemove = function (val) {
2168
- return testFalsey(val);
2169
- };
2583
+ continue;
2584
+ } // One is a string, one is a number
2170
2585
 
2171
- function arrIncludes(rows, columnIds, filterValue) {
2172
- return rows.filter(function (row) {
2173
- return columnIds.some(function (id) {
2174
- var rowValue = row.values[id];
2175
- return rowValue.includes(filterValue);
2176
- });
2177
- });
2178
- }
2179
2586
 
2180
- arrIncludes.autoRemove = function (val) {
2181
- return testFalsey(val) || !(val != null && val.length);
2182
- };
2587
+ if (isNaN(combo[1])) {
2588
+ return isNaN(an) ? -1 : 1;
2589
+ } // Both are numbers
2183
2590
 
2184
- function arrIncludesAll(rows, columnIds, filterValue) {
2185
- return rows.filter(function (row) {
2186
- return columnIds.some(function (id) {
2187
- var rowValue = row.values[id];
2188
- return rowValue && rowValue.length && filterValue.every(function (val) {
2189
- return rowValue.includes(val);
2190
- });
2191
- });
2192
- });
2193
- }
2194
2591
 
2195
- arrIncludesAll.autoRemove = function (val) {
2196
- return testFalsey(val) || !(val != null && val.length);
2197
- };
2592
+ if (an > bn) {
2593
+ return 1;
2594
+ }
2198
2595
 
2199
- function equals(rows, columnIds, filterValue) {
2200
- return rows.filter(function (row) {
2201
- return columnIds.some(function (id) {
2202
- var rowValue = row.values[id];
2203
- return rowValue === filterValue;
2204
- });
2205
- });
2206
- }
2596
+ if (bn > an) {
2597
+ return -1;
2598
+ }
2599
+ }
2207
2600
 
2208
- equals.autoRemove = function (val) {
2209
- return testFalsey(val);
2210
- };
2601
+ return a.length - b.length;
2602
+ } // The text filter is more basic (less numeric support)
2603
+ // but is much faster
2211
2604
 
2212
- function weakEquals(rows, columnIds, filterValue) {
2213
- return rows.filter(function (row) {
2214
- return columnIds.some(function (id) {
2215
- var rowValue = row.values[id]; // eslint-disable-next-line eqeqeq
2216
2605
 
2217
- return rowValue == filterValue;
2218
- });
2219
- });
2220
- }
2606
+ function text(rowA, rowB, columnId) {
2607
+ return compareBasic(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2608
+ } // The text filter is more basic (less numeric support)
2609
+ // but is much faster
2221
2610
 
2222
- weakEquals.autoRemove = function (val) {
2223
- return testFalsey(val);
2224
- };
2225
2611
 
2226
- function betweenNumberRange(rows, columnIds, filterValue) {
2227
- var _ref = filterValue || [],
2228
- unsafeMin = _ref[0],
2229
- unsafeMax = _ref[1];
2612
+ function textCaseSensitive(rowA, rowB, columnId) {
2613
+ return compareBasic(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2614
+ }
2230
2615
 
2231
- var parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
2232
- var parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
2233
- var min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
2234
- var max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
2616
+ function datetime(rowA, rowB, columnId) {
2617
+ return compareBasic(rowA.values[columnId].getTime(), rowB.values[columnId].getTime());
2618
+ }
2235
2619
 
2236
- if (min > max) {
2237
- var temp = min;
2238
- min = max;
2239
- max = temp;
2240
- }
2620
+ function basic(rowA, rowB, columnId) {
2621
+ return compareBasic(rowA.values[columnId], rowB.values[columnId]);
2622
+ } // Utils
2241
2623
 
2242
- return rows.filter(function (row) {
2243
- return columnIds.some(function (id) {
2244
- var rowValue = row.values[id];
2245
- return rowValue >= min && rowValue <= max;
2246
- });
2247
- });
2624
+
2625
+ function compareBasic(a, b) {
2626
+ return a === b ? 0 : a > b ? 1 : -1;
2248
2627
  }
2249
2628
 
2250
- betweenNumberRange.autoRemove = function (val) {
2251
- return testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
2252
- }; // Utils
2629
+ function toString(a) {
2630
+ if (typeof a === 'number') {
2631
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2632
+ return '';
2633
+ }
2634
+
2635
+ return String(a);
2636
+ }
2253
2637
 
2638
+ if (typeof a === 'string') {
2639
+ return a;
2640
+ }
2254
2641
 
2255
- function testFalsey(val) {
2256
- return val === undefined || val === null || val === '';
2642
+ return '';
2257
2643
  }
2258
2644
 
2259
2645
  //
2260
- function getDefaultColumn$1() {
2646
+ function getDefaultColumn() {
2261
2647
  return {
2262
- filterType: 'auto'
2648
+ sortType: 'auto'
2263
2649
  };
2264
2650
  }
2265
- function getInitialState$2() {
2651
+ function getInitialState$4() {
2266
2652
  return {
2267
- columnFilters: [],
2268
- globalFilter: undefined
2653
+ sorting: []
2269
2654
  };
2270
2655
  }
2271
- function getDefaultOptions$2(instance) {
2656
+ function getDefaultOptions$4(instance) {
2272
2657
  return {
2273
- onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
2274
- onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
2275
- autoResetColumnFilters: true,
2276
- filterFromChildrenUp: true,
2277
- autoResetGlobalFilter: true,
2278
- globalFilterType: 'auto',
2279
- getColumnCanGlobalFilterFn: function getColumnCanGlobalFilterFn(column) {
2280
- var _instance$getCoreFlat, _instance$getCoreFlat2;
2281
-
2282
- var value = (_instance$getCoreFlat = instance.getCoreFlatRows()[0]) == null ? void 0 : (_instance$getCoreFlat2 = _instance$getCoreFlat.getAllCellsByColumnId()[column.id]) == null ? void 0 : _instance$getCoreFlat2.value;
2283
- return typeof value === 'string';
2658
+ onSortingChange: makeStateUpdater('sorting', instance),
2659
+ autoResetSorting: true,
2660
+ isMultiSortEvent: function isMultiSortEvent(e) {
2661
+ return e.shiftKey;
2284
2662
  }
2285
2663
  };
2286
2664
  }
2287
2665
  function createColumn$1(column, instance) {
2288
- var getFacetInfo = memo(function () {
2289
- return [column.getPreFilteredRows()];
2290
- }, function (rows) {
2291
- var _rows$0$values$column, _rows$, _rows$0$values$column2, _rows$2;
2292
-
2293
- if (rows === void 0) {
2294
- rows = [];
2666
+ return {
2667
+ sortType: column.sortType,
2668
+ getCanSort: function getCanSort() {
2669
+ return instance.getColumnCanSort(column.id);
2670
+ },
2671
+ getCanMultiSort: function getCanMultiSort() {
2672
+ return instance.getColumnCanMultiSort(column.id);
2673
+ },
2674
+ getSortIndex: function getSortIndex() {
2675
+ return instance.getColumnSortIndex(column.id);
2676
+ },
2677
+ getIsSorted: function getIsSorted() {
2678
+ return instance.getColumnIsSorted(column.id);
2679
+ },
2680
+ toggleSorting: function toggleSorting(desc, isMulti) {
2681
+ return instance.toggleColumnSorting(column.id, desc, isMulti);
2682
+ },
2683
+ getToggleSortingProps: function getToggleSortingProps(userProps) {
2684
+ return instance.getToggleSortingProps(column.id, userProps);
2295
2685
  }
2686
+ };
2687
+ }
2688
+ function getInstance$4(instance) {
2689
+ var registered = false;
2690
+ return {
2691
+ _notifySortingReset: function _notifySortingReset() {
2692
+ if (!registered) {
2693
+ registered = true;
2694
+ return;
2695
+ }
2296
2696
 
2297
- var preFilteredUniqueValues = new Map();
2298
- var preFilteredMinMaxValues = [(_rows$0$values$column = (_rows$ = rows[0]) == null ? void 0 : _rows$.values[column.id]) != null ? _rows$0$values$column : null, (_rows$0$values$column2 = (_rows$2 = rows[0]) == null ? void 0 : _rows$2.values[column.id]) != null ? _rows$0$values$column2 : null];
2697
+ if (instance.options.autoResetAll === false) {
2698
+ return;
2699
+ }
2299
2700
 
2300
- for (var i = 0; i < rows.length; i++) {
2301
- var _rows$i;
2701
+ if (instance.options.autoResetAll === true || instance.options.autoResetSorting) {
2702
+ instance.resetSorting();
2703
+ }
2704
+ },
2705
+ getColumnAutoSortingFn: function getColumnAutoSortingFn(columnId) {
2706
+ var firstRows = instance.getGlobalFilteredRowModel().flatRows.slice(100);
2707
+ var isString = false;
2302
2708
 
2303
- var _value = (_rows$i = rows[i]) == null ? void 0 : _rows$i.values[column.id];
2709
+ for (var _iterator = _createForOfIteratorHelperLoose(firstRows), _step; !(_step = _iterator()).done;) {
2710
+ var row = _step.value;
2711
+ var value = row == null ? void 0 : row.values[columnId];
2304
2712
 
2305
- if (preFilteredUniqueValues.has(_value)) {
2306
- var _preFilteredUniqueVal;
2713
+ if (Object.prototype.toString.call(value) === '[object Date]') {
2714
+ return sortTypes.datetime;
2715
+ }
2307
2716
 
2308
- preFilteredUniqueValues.set(_value, ((_preFilteredUniqueVal = preFilteredUniqueValues.get(_value)) != null ? _preFilteredUniqueVal : 0) + 1);
2309
- } else {
2310
- preFilteredUniqueValues.set(_value, 1);
2717
+ if (typeof value === 'string') {
2718
+ isString = true;
2719
+
2720
+ if (value.split(reSplitAlphaNumeric).length > 1) {
2721
+ return sortTypes.alphanumeric;
2722
+ }
2723
+ }
2311
2724
  }
2312
2725
 
2313
- if (_value < preFilteredMinMaxValues[0]) {
2314
- preFilteredMinMaxValues[0] = _value;
2315
- } else if (_value > preFilteredMinMaxValues[1]) {
2316
- preFilteredMinMaxValues[1] = _value;
2726
+ if (isString) {
2727
+ return sortTypes.text;
2317
2728
  }
2318
- }
2319
2729
 
2320
- return {
2321
- preFilteredUniqueValues: preFilteredUniqueValues,
2322
- preFilteredMinMaxValues: preFilteredMinMaxValues
2323
- };
2324
- }, 'column.getFacetInfo', instance.options.debug);
2325
- return {
2326
- filterType: column.filterType,
2327
- getCanColumnFilter: function getCanColumnFilter() {
2328
- return instance.getColumnCanColumnFilter(column.id);
2329
- },
2330
- getCanGlobalFilter: function getCanGlobalFilter() {
2331
- return instance.getColumnCanGlobalFilter(column.id);
2332
- },
2333
- getColumnFilterIndex: function getColumnFilterIndex() {
2334
- return instance.getColumnFilterIndex(column.id);
2335
- },
2336
- getIsColumnFiltered: function getIsColumnFiltered() {
2337
- return instance.getColumnIsFiltered(column.id);
2338
- },
2339
- getColumnFilterValue: function getColumnFilterValue() {
2340
- return instance.getColumnFilterValue(column.id);
2730
+ return sortTypes.basic;
2341
2731
  },
2342
- setColumnFilterValue: function setColumnFilterValue(val) {
2343
- return instance.setColumnFilterValue(column.id, val);
2732
+ getColumnAutoSortDir: function getColumnAutoSortDir(columnId) {
2733
+ var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2734
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
2735
+
2736
+ if (typeof value === 'string') {
2737
+ return 'asc';
2738
+ }
2739
+
2740
+ return 'desc';
2344
2741
  },
2345
- getPreFilteredUniqueValues: function getPreFilteredUniqueValues() {
2346
- return getFacetInfo().preFilteredUniqueValues;
2742
+ getColumnSortingFn: function getColumnSortingFn(columnId) {
2743
+ var _ref;
2744
+
2745
+ var column = instance.getColumn(columnId);
2746
+ var userSortTypes = instance.options.sortTypes;
2747
+
2748
+ if (!column) {
2749
+ throw new Error();
2750
+ }
2751
+
2752
+ return isFunction(column.sortType) ? column.sortType : column.sortType === 'auto' ? instance.getColumnAutoSortingFn(columnId) : (_ref = userSortTypes == null ? void 0 : userSortTypes[column.sortType]) != null ? _ref : sortTypes[column.sortType];
2347
2753
  },
2348
- getPreFilteredMinMaxValues: function getPreFilteredMinMaxValues() {
2349
- return getFacetInfo().preFilteredMinMaxValues;
2754
+ setSorting: function setSorting(updater) {
2755
+ return instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater, functionalUpdate(updater, instance.getState().sorting));
2350
2756
  },
2351
- getPreFilteredRows: function getPreFilteredRows() {
2352
- return undefined;
2353
- }
2354
- };
2355
- }
2356
- function getInstance$2(instance) {
2357
- return {
2358
- getColumnAutoFilterFn: function getColumnAutoFilterFn(columnId) {
2359
- var firstRow = instance.getCoreFlatRows()[0];
2360
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
2757
+ toggleColumnSorting: function toggleColumnSorting(columnId, desc, multi) {
2758
+ var column = instance.getColumn(columnId);
2759
+
2760
+ if (!column) {
2761
+ throw new Error();
2762
+ } // if (column.columns.length) {
2763
+ // column.columns.forEach((c, i) => {
2764
+ // if (c.id) {
2765
+ // instance.toggleColumnSorting(c.id, undefined, multi || !!i)
2766
+ // }
2767
+ // })
2768
+ // return
2769
+ // }
2770
+
2771
+
2772
+ instance.setSorting(function (old) {
2773
+ var _ref2, _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2774
+
2775
+ // Find any existing sorting for this column
2776
+ var existingSorting = old == null ? void 0 : old.find(function (d) {
2777
+ return d.id === columnId;
2778
+ });
2779
+ var existingIndex = old == null ? void 0 : old.findIndex(function (d) {
2780
+ return d.id === columnId;
2781
+ });
2782
+ var hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2783
+ var newSorting = []; // What should we do with this sort action?
2784
+
2785
+ var sortAction;
2786
+
2787
+ if (column.getCanMultiSort() && multi) {
2788
+ if (existingSorting) {
2789
+ sortAction = 'toggle';
2790
+ } else {
2791
+ sortAction = 'add';
2792
+ }
2793
+ } else {
2794
+ // Normal mode
2795
+ if (old != null && old.length && existingIndex !== old.length - 1) {
2796
+ sortAction = 'replace';
2797
+ } else if (existingSorting) {
2798
+ sortAction = 'toggle';
2799
+ } else {
2800
+ sortAction = 'replace';
2801
+ }
2802
+ }
2803
+
2804
+ var sortDescFirst = (_ref2 = (_column$sortDescFirst = column.sortDescFirst) != null ? _column$sortDescFirst : instance.options.sortDescFirst) != null ? _ref2 : instance.getColumnAutoSortDir(columnId) === 'desc'; // Handle toggle states that will remove the sorting
2805
+
2806
+ if (sortAction === 'toggle' && ( // Must be toggling
2807
+ (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2808
+ !hasDescDefined && ( // Must not be setting desc
2809
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2810
+ existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2811
+ ? !sortDescFirst : sortDescFirst)) {
2812
+ sortAction = 'remove';
2813
+ }
2814
+
2815
+ if (sortAction === 'replace') {
2816
+ newSorting = [{
2817
+ id: columnId,
2818
+ desc: hasDescDefined ? desc : !!sortDescFirst
2819
+ }];
2820
+ } else if (sortAction === 'add' && old != null && old.length) {
2821
+ var _instance$options$max;
2361
2822
 
2362
- if (typeof value === 'string') {
2363
- return filterTypes.includesString;
2364
- }
2823
+ newSorting = [].concat(old, [{
2824
+ id: columnId,
2825
+ desc: hasDescDefined ? desc : !!sortDescFirst
2826
+ }]); // Take latest n columns
2365
2827
 
2366
- if (typeof value === 'number') {
2367
- return filterTypes.betweenNumberRange;
2368
- }
2828
+ newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
2829
+ } else if (sortAction === 'toggle' && old != null && old.length) {
2830
+ // This flips (or sets) the
2831
+ newSorting = old.map(function (d) {
2832
+ if (d.id === columnId) {
2833
+ return _extends({}, d, {
2834
+ desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2835
+ });
2836
+ }
2369
2837
 
2370
- if (value !== null && typeof value === 'object') {
2371
- return filterTypes.equals;
2372
- }
2838
+ return d;
2839
+ });
2840
+ } else if (sortAction === 'remove' && old != null && old.length) {
2841
+ newSorting = old.filter(function (d) {
2842
+ return d.id !== columnId;
2843
+ });
2844
+ }
2373
2845
 
2374
- if (Array.isArray(value)) {
2375
- return filterTypes.arrIncludes;
2846
+ return newSorting;
2847
+ });
2848
+ },
2849
+ getColumnCanSort: function getColumnCanSort(columnId) {
2850
+ var _ref3, _ref4, _column$enableSorting;
2851
+
2852
+ var column = instance.getColumn(columnId);
2853
+
2854
+ if (!column) {
2855
+ throw new Error();
2376
2856
  }
2377
2857
 
2378
- return filterTypes.weakEquals;
2379
- },
2380
- getGlobalAutoFilterFn: function getGlobalAutoFilterFn() {
2381
- return filterTypes.includesString;
2858
+ return (_ref3 = (_ref4 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref4 : column.defaultCanSort) != null ? _ref3 : !!column.accessorFn // (!!column.accessorFn ||
2859
+ // column.columns?.some(c => c.id && instance.getColumnCanSort(c.id))) ??
2860
+ // false
2861
+ ;
2382
2862
  },
2383
- getColumnFilterFn: function getColumnFilterFn(columnId) {
2384
- var _ref;
2863
+ getColumnCanMultiSort: function getColumnCanMultiSort(columnId) {
2864
+ var _ref5, _column$enableMultiSo;
2385
2865
 
2386
2866
  var column = instance.getColumn(columnId);
2387
- var userFilterTypes = instance.options.filterTypes;
2388
2867
 
2389
2868
  if (!column) {
2390
2869
  throw new Error();
2391
2870
  }
2392
2871
 
2393
- return isFunction(column.filterType) ? column.filterType : column.filterType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userFilterTypes == null ? void 0 : userFilterTypes[column.filterType]) != null ? _ref : filterTypes[column.filterType];
2872
+ return (_ref5 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref5 : !!column.accessorFn;
2394
2873
  },
2395
- getGlobalFilterFn: function getGlobalFilterFn() {
2396
- var _ref2;
2874
+ getColumnIsSorted: function getColumnIsSorted(columnId) {
2875
+ var _instance$getState$so;
2397
2876
 
2398
- var _instance$options = instance.options,
2399
- userFilterTypes = _instance$options.filterTypes,
2400
- globalFilterType = _instance$options.globalFilterType;
2401
- return isFunction(globalFilterType) ? globalFilterType : globalFilterType === 'auto' ? instance.getGlobalAutoFilterFn() : (_ref2 = userFilterTypes == null ? void 0 : userFilterTypes[globalFilterType]) != null ? _ref2 : filterTypes[globalFilterType];
2877
+ var columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(function (d) {
2878
+ return d.id === columnId;
2879
+ });
2880
+ return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2402
2881
  },
2403
- setColumnFilters: function setColumnFilters(updater) {
2404
- var leafColumns = instance.getAllLeafColumns();
2405
-
2406
- var updateFn = function updateFn(old) {
2407
- var _functionalUpdate;
2882
+ getColumnSortIndex: function getColumnSortIndex(columnId) {
2883
+ var _instance$getState$so2, _instance$getState$so3;
2408
2884
 
2409
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(function (filter) {
2410
- var column = leafColumns.find(function (d) {
2411
- return d.id === filter.id;
2412
- });
2885
+ return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(function (d) {
2886
+ return d.id === columnId;
2887
+ })) != null ? _instance$getState$so2 : -1;
2888
+ },
2889
+ resetSorting: function resetSorting() {
2890
+ var _instance$options$ini, _instance$options, _instance$options$ini2;
2413
2891
 
2414
- if (column) {
2415
- var filterFn = instance.getColumnFilterFn(column.id);
2892
+ instance.setSorting((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.sorting) != null ? _instance$options$ini : []);
2893
+ },
2894
+ getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2895
+ var column = instance.getColumn(columnId);
2416
2896
 
2417
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
2418
- return false;
2419
- }
2420
- }
2897
+ if (!column) {
2898
+ throw new Error();
2899
+ }
2421
2900
 
2422
- return true;
2423
- });
2901
+ var canSort = column.getCanSort();
2902
+ var initialProps = {
2903
+ title: canSort ? 'Toggle Sorting' : undefined,
2904
+ onClick: canSort ? function (e) {
2905
+ e.persist();
2906
+ column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
2907
+ } : undefined
2424
2908
  };
2909
+ return propGetter(initialProps, userProps);
2910
+ },
2911
+ getSortedRowModel: memo(function () {
2912
+ return [instance.getState().sorting, instance.getGlobalFilteredRowModel(), instance.options.sortRowsFn];
2913
+ }, function (sorting, rowModel, sortingFn) {
2914
+ if (!sortingFn || !(sorting != null && sorting.length)) {
2915
+ return rowModel;
2916
+ }
2425
2917
 
2426
- instance.options.onColumnFiltersChange == null ? void 0 : instance.options.onColumnFiltersChange(updateFn, updateFn(instance.getState().columnFilters));
2918
+ if (instance.options.debug) console.info('Sorting...');
2919
+ return sortingFn(instance, rowModel);
2920
+ }, {
2921
+ key: 'getSortedRowModel',
2922
+ debug: instance.options.debug,
2923
+ onChange: function onChange() {
2924
+ return instance._notifyGroupingReset();
2925
+ }
2926
+ }),
2927
+ getPreSortedRows: function getPreSortedRows() {
2928
+ return instance.getGlobalFilteredRowModel().rows;
2427
2929
  },
2428
- setGlobalFilter: function setGlobalFilter(updater) {
2429
- instance.options.onGlobalFilterChange == null ? void 0 : instance.options.onGlobalFilterChange(updater, functionalUpdate(updater, instance.getState().globalFilter));
2930
+ getPreSortedFlatRows: function getPreSortedFlatRows() {
2931
+ return instance.getGlobalFilteredRowModel().flatRows;
2430
2932
  },
2431
- resetGlobalFilter: function resetGlobalFilter() {
2432
- instance.setGlobalFilter(undefined);
2933
+ getPreSortedRowsById: function getPreSortedRowsById() {
2934
+ return instance.getGlobalFilteredRowModel().rowsById;
2433
2935
  },
2434
- getColumnCanColumnFilter: function getColumnCanColumnFilter(columnId) {
2435
- var _ref3, _ref4, _ref5, _ref6, _ref7, _column$enableAllFilt;
2436
-
2437
- var column = instance.getColumn(columnId);
2936
+ getSortedRows: function getSortedRows() {
2937
+ return instance.getSortedRowModel().rows;
2938
+ },
2939
+ getSortedFlatRows: function getSortedFlatRows() {
2940
+ return instance.getSortedRowModel().flatRows;
2941
+ },
2942
+ getSortedRowsById: function getSortedRowsById() {
2943
+ return instance.getSortedRowModel().rowsById;
2944
+ }
2945
+ };
2946
+ }
2438
2947
 
2439
- if (!column) {
2440
- throw new Error();
2441
- }
2948
+ var Sorting = /*#__PURE__*/Object.freeze({
2949
+ __proto__: null,
2950
+ getDefaultColumn: getDefaultColumn,
2951
+ getInitialState: getInitialState$4,
2952
+ getDefaultOptions: getDefaultOptions$4,
2953
+ createColumn: createColumn$1,
2954
+ getInstance: getInstance$4
2955
+ });
2442
2956
 
2443
- return (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_ref7 = (_column$enableAllFilt = column.enableAllFilters) != null ? _column$enableAllFilt : column.enableColumnFilter) != null ? _ref7 : instance.options.enableFilters) != null ? _ref6 : instance.options.enableColumnFilters) != null ? _ref5 : column.defaultCanFilter) != null ? _ref4 : column.defaultCanColumnFilter) != null ? _ref3 : !!column.accessorFn;
2957
+ //
2958
+ function getInitialState$3() {
2959
+ return {
2960
+ expanded: {}
2961
+ };
2962
+ }
2963
+ function getDefaultOptions$3(instance) {
2964
+ return {
2965
+ onExpandedChange: makeStateUpdater('expanded', instance),
2966
+ autoResetExpanded: true,
2967
+ getIsRowExpanded: function getIsRowExpanded(row) {
2968
+ return !!(row == null ? void 0 : row.original).expanded;
2444
2969
  },
2445
- getColumnCanGlobalFilter: function getColumnCanGlobalFilter(columnId) {
2446
- var _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _instance$options$ena;
2447
-
2448
- var column = instance.getColumn(columnId);
2970
+ expandSubRows: true,
2971
+ paginateExpandedRows: true
2972
+ };
2973
+ }
2974
+ function getInstance$3(instance) {
2975
+ var registered = false;
2976
+ return {
2977
+ _notifyExpandedReset: function _notifyExpandedReset() {
2978
+ if (!registered) {
2979
+ registered = true;
2980
+ return;
2981
+ }
2449
2982
 
2450
- if (!column) {
2451
- throw new Error();
2983
+ if (instance.options.autoResetAll === false) {
2984
+ return;
2452
2985
  }
2453
2986
 
2454
- return (_ref8 = ((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_instance$options$ena = instance.options.enableFilters) != null ? _instance$options$ena : instance.options.enableGlobalFilter) != null ? _ref13 : column.enableAllFilters) != null ? _ref12 : column.enableGlobalFilter) != null ? _ref11 : column.defaultCanFilter) != null ? _ref10 : column.defaultCanGlobalFilter) != null ? _ref9 : !!column.accessorFn) && (instance.options.getColumnCanGlobalFilterFn == null ? void 0 : instance.options.getColumnCanGlobalFilterFn(column))) != null ? _ref8 : true;
2987
+ if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
2988
+ instance.resetExpanded();
2989
+ }
2455
2990
  },
2456
- getColumnIsFiltered: function getColumnIsFiltered(columnId) {
2457
- return instance.getColumnFilterIndex(columnId) > -1;
2991
+ setExpanded: function setExpanded(updater) {
2992
+ return instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater, functionalUpdate(updater, instance.getState().expanded));
2458
2993
  },
2459
- getColumnFilterValue: function getColumnFilterValue(columnId) {
2460
- var _instance$getState$co, _instance$getState$co2;
2994
+ toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
2995
+ if (!rowId) return;
2996
+ instance.setExpanded(function (old) {
2997
+ var _old, _expanded;
2461
2998
 
2462
- return (_instance$getState$co = instance.getState().columnFilters) == null ? void 0 : (_instance$getState$co2 = _instance$getState$co.find(function (d) {
2463
- return d.id === columnId;
2464
- })) == null ? void 0 : _instance$getState$co2.value;
2465
- },
2466
- getColumnFilterIndex: function getColumnFilterIndex(columnId) {
2467
- var _instance$getState$co3, _instance$getState$co4;
2999
+ if (old === void 0) {
3000
+ old = {};
3001
+ }
2468
3002
 
2469
- return (_instance$getState$co3 = (_instance$getState$co4 = instance.getState().columnFilters) == null ? void 0 : _instance$getState$co4.findIndex(function (d) {
2470
- return d.id === columnId;
2471
- })) != null ? _instance$getState$co3 : -1;
2472
- },
2473
- setColumnFilterValue: function setColumnFilterValue(columnId, value) {
2474
- if (!columnId) return;
2475
- instance.setColumnFilters(function (old) {
2476
- var column = instance.getColumn(columnId);
3003
+ var exists = old === true ? true : !!((_old = old) != null && _old[rowId]);
3004
+ var oldExpanded = {};
2477
3005
 
2478
- if (!column) {
2479
- {
2480
- console.warn("React-Table: Could not find a column with id: " + columnId);
2481
- }
3006
+ if (old === true) {
3007
+ Object.keys(instance.getRowsById()).forEach(function (rowId) {
3008
+ oldExpanded[rowId] = true;
3009
+ });
3010
+ } else {
3011
+ oldExpanded = old;
3012
+ }
2482
3013
 
2483
- throw new Error();
3014
+ expanded = (_expanded = expanded) != null ? _expanded : !exists;
3015
+
3016
+ if (!exists && expanded) {
3017
+ var _extends2;
3018
+
3019
+ return _extends({}, oldExpanded, (_extends2 = {}, _extends2[rowId] = true, _extends2));
2484
3020
  }
2485
3021
 
2486
- var filterFn = instance.getColumnFilterFn(column.id);
2487
- var previousfilter = old == null ? void 0 : old.find(function (d) {
2488
- return d.id === columnId;
2489
- });
2490
- var newFilter = functionalUpdate(value, previousfilter ? previousfilter.value : undefined); //
3022
+ if (exists && !expanded) {
3023
+ var _oldExpanded = oldExpanded;
3024
+ _oldExpanded[rowId];
3025
+ var rest = _objectWithoutPropertiesLoose(_oldExpanded, [rowId].map(_toPropertyKey));
2491
3026
 
2492
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
2493
- var _old$filter;
3027
+ return rest;
3028
+ }
2494
3029
 
2495
- return (_old$filter = old == null ? void 0 : old.filter(function (d) {
2496
- return d.id !== columnId;
2497
- })) != null ? _old$filter : [];
3030
+ return old;
3031
+ });
3032
+ },
3033
+ toggleAllRowsExpanded: function toggleAllRowsExpanded(expanded) {
3034
+ if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
3035
+ instance.setExpanded(true);
3036
+ } else {
3037
+ instance.setExpanded({});
3038
+ }
3039
+ },
3040
+ resetExpanded: function resetExpanded() {
3041
+ var _instance$options$ini, _instance$options, _instance$options$ini2;
3042
+
3043
+ instance.setExpanded((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.expanded) != null ? _instance$options$ini : {});
3044
+ },
3045
+ getIsRowExpanded: function getIsRowExpanded(rowId) {
3046
+ var _instance$options$get;
3047
+
3048
+ var row = instance.getRow(rowId);
3049
+
3050
+ if (!row) {
3051
+ {
3052
+ console.warn("[ReactTable] getIsRowExpanded: no row found with id " + rowId);
2498
3053
  }
2499
3054
 
2500
- var newFilterObj = {
2501
- id: columnId,
2502
- value: newFilter
2503
- };
3055
+ throw new Error();
3056
+ }
2504
3057
 
2505
- if (previousfilter) {
2506
- var _old$map;
3058
+ var expanded = instance.getState().expanded;
3059
+ return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded || (expanded == null ? void 0 : expanded[rowId]));
3060
+ },
3061
+ getRowCanExpand: function getRowCanExpand(rowId) {
3062
+ var _ref, _ref2, _instance$options$get2, _row$subRows;
2507
3063
 
2508
- return (_old$map = old == null ? void 0 : old.map(function (d) {
2509
- if (d.id === columnId) {
2510
- return newFilterObj;
2511
- }
3064
+ var row = instance.getRow(rowId);
2512
3065
 
2513
- return d;
2514
- })) != null ? _old$map : [];
3066
+ if (!row) {
3067
+ {
3068
+ console.warn("[ReactTable] getRowCanExpand: no row found with id " + rowId);
2515
3069
  }
2516
3070
 
2517
- if (old != null && old.length) {
2518
- return [].concat(old, [newFilterObj]);
2519
- }
3071
+ throw new Error();
3072
+ }
2520
3073
 
2521
- return [newFilterObj];
2522
- });
3074
+ return (_ref = (_ref2 = (_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : instance.options.enableExpanded) != null ? _ref2 : instance.options.defaultCanExpand) != null ? _ref : !!((_row$subRows = row.subRows) != null && _row$subRows.length);
2523
3075
  },
2524
- resetColumnFilters: function resetColumnFilters() {
2525
- var _instance$options$ini, _instance$options2, _instance$options2$in;
3076
+ getToggleExpandedProps: function getToggleExpandedProps(rowId, userProps) {
3077
+ var row = instance.getRow(rowId);
2526
3078
 
2527
- instance.setColumnFilters((_instance$options$ini = (_instance$options2 = instance.options) == null ? void 0 : (_instance$options2$in = _instance$options2.initialState) == null ? void 0 : _instance$options2$in.columnFilters) != null ? _instance$options$ini : []);
3079
+ if (!row) {
3080
+ return;
3081
+ }
3082
+
3083
+ var canExpand = instance.getRowCanExpand(rowId);
3084
+ var initialProps = {
3085
+ title: canExpand ? 'Toggle Expanded' : undefined,
3086
+ onClick: canExpand ? function (e) {
3087
+ e.persist();
3088
+ instance.toggleRowExpanded(rowId);
3089
+ } : undefined
3090
+ };
3091
+ return propGetter(initialProps, userProps);
2528
3092
  },
2529
- getColumnFilteredRowModel: memo(function () {
2530
- return [instance.getState().columnFilters, instance.getCoreRowModel(), instance.options.columnFilterRowsFn];
2531
- }, function (columnFilters, rowModel, columnFiltersFn) {
2532
- var columnFilteredRowModel = function () {
2533
- if (!(columnFilters != null && columnFilters.length) || !columnFiltersFn) {
2534
- return rowModel;
3093
+ getToggleAllRowsExpandedProps: function getToggleAllRowsExpandedProps(userProps) {
3094
+ var initialProps = {
3095
+ title: 'Toggle All Expanded',
3096
+ onClick: function onClick(e) {
3097
+ e.persist();
3098
+ instance.toggleAllRowsExpanded();
2535
3099
  }
3100
+ };
3101
+ return propGetter(initialProps, userProps);
3102
+ },
3103
+ getIsAllRowsExpanded: function getIsAllRowsExpanded() {
3104
+ var expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
2536
3105
 
2537
- if (instance.options.debug) console.info('Column Filtering...');
2538
- return columnFiltersFn(instance, columnFilters, rowModel);
2539
- }(); // Now that each filtered column has it's partially filtered rows,
2540
- // lets assign the final filtered rows to all of the other columns
3106
+ if (expanded === true) {
3107
+ return true;
3108
+ } // If any row is not expanded, return false
2541
3109
 
2542
3110
 
2543
- var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2544
- var _instance$getState$co5;
3111
+ if (Object.keys(instance.getRowsById()).some(function (id) {
3112
+ return !instance.getIsRowExpanded(id);
3113
+ })) {
3114
+ return false;
3115
+ } // They must all be expanded :shrug:
2545
3116
 
2546
- return !((_instance$getState$co5 = instance.getState().columnFilters) != null && _instance$getState$co5.find(function (d) {
2547
- return d.id === column.id;
2548
- }));
2549
- }); // This essentially enables faceted filter options to be built easily
2550
- // using every column's preFilteredRows value
2551
3117
 
2552
- nonFilteredColumns.forEach(function (column) {
2553
- column.getPreFilteredRows = function () {
2554
- return columnFilteredRowModel.rows;
2555
- };
3118
+ return true;
3119
+ },
3120
+ getExpandedDepth: function getExpandedDepth() {
3121
+ var maxDepth = 0;
3122
+ var rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowsById()) : Object.keys(instance.getState().expanded);
3123
+ rowIds.forEach(function (id) {
3124
+ var splitId = id.split('.');
3125
+ maxDepth = Math.max(maxDepth, splitId.length);
2556
3126
  });
2557
- return columnFilteredRowModel;
2558
- }, 'getColumnFilteredRowModel', instance.options.debug),
2559
- getPreColumnFilteredRows: function getPreColumnFilteredRows() {
2560
- return instance.getCoreRowModel().rows;
3127
+ return maxDepth;
2561
3128
  },
2562
- getPreColumnFilteredFlatRows: function getPreColumnFilteredFlatRows() {
2563
- return instance.getCoreRowModel().flatRows;
3129
+ getExpandedRowModel: memo(function () {
3130
+ return [instance.getState().expanded, instance.getGroupedRowModel(), instance.options.expandRowsFn, instance.options.paginateExpandedRows];
3131
+ }, function (expanded, rowModel, expandRowsFn, paginateExpandedRows) {
3132
+ if (!expandRowsFn || // Do not expand if rows are not included in pagination
3133
+ !paginateExpandedRows || !Object.keys(expanded != null ? expanded : {}).length) {
3134
+ return rowModel;
3135
+ }
3136
+
3137
+ if (instance.options.debug) console.info('Expanding...');
3138
+ return expandRowsFn(instance, rowModel);
3139
+ }, {
3140
+ key: 'getExpandedRowModel',
3141
+ debug: instance.options.debug,
3142
+ onChange: function onChange() {
3143
+ return instance._notifyPageIndexReset();
3144
+ }
3145
+ }),
3146
+ getPreExpandedRows: function getPreExpandedRows() {
3147
+ return instance.getGroupedRowModel().rows;
2564
3148
  },
2565
- getPreColumnFilteredRowsById: function getPreColumnFilteredRowsById() {
2566
- return instance.getCoreRowModel().rowsById;
3149
+ getPreExpandedFlatRows: function getPreExpandedFlatRows() {
3150
+ return instance.getGroupedRowModel().flatRows;
2567
3151
  },
2568
- getColumnFilteredRows: function getColumnFilteredRows() {
2569
- return instance.getColumnFilteredRowModel().rows;
3152
+ getPreExpandedRowsById: function getPreExpandedRowsById() {
3153
+ return instance.getGroupedRowModel().rowsById;
2570
3154
  },
2571
- getColumnFilteredFlatRows: function getColumnFilteredFlatRows() {
2572
- return instance.getColumnFilteredRowModel().flatRows;
3155
+ getExpandedRows: function getExpandedRows() {
3156
+ return instance.getExpandedRowModel().rows;
2573
3157
  },
2574
- getColumnFilteredRowsById: function getColumnFilteredRowsById() {
2575
- return instance.getColumnFilteredRowModel().rowsById;
3158
+ getExpandedFlatRows: function getExpandedFlatRows() {
3159
+ return instance.getExpandedRowModel().flatRows;
2576
3160
  },
2577
- getGlobalFilteredRowModel: memo(function () {
2578
- return [instance.getState().globalFilter, instance.getColumnFilteredRowModel(), instance.options.globalFilterRowsFn];
2579
- }, function (globalFilterValue, columnFilteredRowModel, globalFiltersFn) {
2580
- var globalFilteredRowModel = function () {
2581
- if (!globalFiltersFn || !globalFilterValue) {
2582
- return columnFilteredRowModel;
3161
+ getExpandedRowsById: function getExpandedRowsById() {
3162
+ return instance.getExpandedRowModel().rowsById;
3163
+ }
3164
+ };
3165
+ }
3166
+ function createRow$1(row, instance) {
3167
+ return {
3168
+ toggleExpanded: function toggleExpanded(expanded) {
3169
+ return void instance.toggleRowExpanded(row.id, expanded);
3170
+ },
3171
+ getIsExpanded: function getIsExpanded() {
3172
+ return instance.getIsRowExpanded(row.id);
3173
+ },
3174
+ getCanExpand: function getCanExpand() {
3175
+ return row.subRows && !!row.subRows.length;
3176
+ },
3177
+ getToggleExpandedProps: function getToggleExpandedProps(userProps) {
3178
+ var initialProps = {
3179
+ title: 'Toggle Row Expanded',
3180
+ onClick: function onClick(e) {
3181
+ e.stopPropagation();
3182
+ instance.toggleRowExpanded(row.id);
2583
3183
  }
3184
+ };
3185
+ return propGetter(initialProps, userProps);
3186
+ }
3187
+ };
3188
+ }
2584
3189
 
2585
- if (instance.options.debug) console.info('Global Filtering...');
2586
- return globalFiltersFn(instance, globalFilterValue, columnFilteredRowModel);
2587
- }(); // Now that each filtered column has it's partially filtered rows,
2588
- // lets assign the final filtered rows to all of the other columns
3190
+ var Expanding = /*#__PURE__*/Object.freeze({
3191
+ __proto__: null,
3192
+ getInitialState: getInitialState$3,
3193
+ getDefaultOptions: getDefaultOptions$3,
3194
+ getInstance: getInstance$3,
3195
+ createRow: createRow$1
3196
+ });
2589
3197
 
3198
+ //
3199
+ var defaultColumnSizing = {
3200
+ width: 150,
3201
+ minWidth: 20,
3202
+ maxWidth: Number.MAX_SAFE_INTEGER
3203
+ };
3204
+ function getInitialState$2() {
3205
+ return {
3206
+ columnSizing: {},
3207
+ columnSizingInfo: {
3208
+ startOffset: null,
3209
+ startSize: null,
3210
+ deltaOffset: null,
3211
+ deltaPercentage: null,
3212
+ isResizingColumn: false,
3213
+ columnSizingStart: []
3214
+ }
3215
+ };
3216
+ }
3217
+ function getDefaultOptions$2(instance) {
3218
+ return {
3219
+ columnResizeMode: 'onEnd',
3220
+ onColumnSizingChange: makeStateUpdater('columnSizing', instance),
3221
+ onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
3222
+ };
3223
+ }
3224
+ function getInstance$2(instance) {
3225
+ return {
3226
+ setColumnSizing: function setColumnSizing(updater) {
3227
+ return instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater, functionalUpdate(updater, instance.getState().columnSizing));
3228
+ },
3229
+ setColumnSizingInfo: function setColumnSizingInfo(updater) {
3230
+ return instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater, functionalUpdate(updater, instance.getState().columnSizingInfo));
3231
+ },
3232
+ resetColumnSizing: function resetColumnSizing() {
3233
+ var _instance$initialStat;
2590
3234
 
2591
- var nonFilteredColumns = instance.getAllLeafColumns().filter(function (column) {
2592
- var _instance$getState$co6;
3235
+ instance.setColumnSizing((_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
3236
+ },
3237
+ resetHeaderSizeInfo: function resetHeaderSizeInfo() {
3238
+ var _instance$initialStat2;
2593
3239
 
2594
- return !((_instance$getState$co6 = instance.getState().columnFilters) != null && _instance$getState$co6.find(function (d) {
2595
- return d.id === column.id;
2596
- }));
2597
- }); // This essentially enables faceted filter options to be built easily
2598
- // using every column's preFilteredRows value
3240
+ instance.setColumnSizingInfo((_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : {});
3241
+ },
3242
+ resetColumnSize: function resetColumnSize(columnId) {
3243
+ instance.setColumnSizing(function (_ref) {
3244
+ _ref[columnId];
3245
+ var rest = _objectWithoutPropertiesLoose(_ref, [columnId].map(_toPropertyKey));
2599
3246
 
2600
- nonFilteredColumns.forEach(function (column) {
2601
- column.getPreFilteredRows = function () {
2602
- return globalFilteredRowModel.rows;
2603
- };
3247
+ return rest;
2604
3248
  });
2605
- return globalFilteredRowModel;
2606
- }, 'getGlobalFilteredRowModel', instance.options.debug),
2607
- getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
2608
- return instance.getColumnFilteredRowModel().rows;
2609
3249
  },
2610
- getPreGlobalFilteredFlatRows: function getPreGlobalFilteredFlatRows() {
2611
- return instance.getColumnFilteredRowModel().flatRows;
2612
- },
2613
- getPreGlobalFilteredRowsById: function getPreGlobalFilteredRowsById() {
2614
- return instance.getColumnFilteredRowModel().rowsById;
2615
- },
2616
- getGlobalFilteredRows: function getGlobalFilteredRows() {
2617
- return instance.getGlobalFilteredRowModel().rows;
3250
+ resetHeaderSize: function resetHeaderSize(headerId) {
3251
+ var header = instance.getHeader(headerId);
3252
+
3253
+ if (!header) {
3254
+ return;
3255
+ }
3256
+
3257
+ return instance.resetColumnSize(header.column.id);
2618
3258
  },
2619
- getGlobalFilteredFlatRows: function getGlobalFilteredFlatRows() {
2620
- return instance.getGlobalFilteredRowModel().flatRows;
3259
+ getHeaderCanResize: function getHeaderCanResize(headerId) {
3260
+ var header = instance.getHeader(headerId);
3261
+
3262
+ if (!header) {
3263
+ throw new Error();
3264
+ }
3265
+
3266
+ return instance.getColumnCanResize(header.column.id);
2621
3267
  },
2622
- getGlobalFilteredRowsById: function getGlobalFilteredRowsById() {
2623
- return instance.getGlobalFilteredRowModel().rowsById;
2624
- }
2625
- };
2626
- }
2627
- function shouldAutoRemoveFilter(filterFn, value, column) {
2628
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
2629
- }
3268
+ getColumnCanResize: function getColumnCanResize(columnId) {
3269
+ var _ref2, _ref3, _column$enableResizin;
2630
3270
 
2631
- var reSplitAlphaNumeric = /([0-9]+)/gm;
2632
- var sortTypes = {
2633
- alphanumeric: alphanumeric,
2634
- alphanumericCaseSensitive: alphanumericCaseSensitive,
2635
- text: text,
2636
- textCaseSensitive: textCaseSensitive,
2637
- datetime: datetime,
2638
- basic: basic
2639
- };
3271
+ var column = instance.getColumn(columnId);
2640
3272
 
2641
- function alphanumeric(rowA, rowB, columnId) {
2642
- return compareAlphanumeric(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2643
- }
3273
+ if (!column) {
3274
+ throw new Error();
3275
+ }
2644
3276
 
2645
- function alphanumericCaseSensitive(rowA, rowB, columnId) {
2646
- return compareAlphanumeric(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2647
- } // Mixed sorting is slow, but very inclusive of many edge cases.
2648
- // It handles numbers, mixed alphanumeric combinations, and even
2649
- // null, undefined, and Infinity
3277
+ return (_ref2 = (_ref3 = (_column$enableResizin = column.enableResizing) != null ? _column$enableResizin : instance.options.enableColumnResizing) != null ? _ref3 : column.defaultCanResize) != null ? _ref2 : true;
3278
+ },
3279
+ getColumnIsResizing: function getColumnIsResizing(columnId) {
3280
+ var column = instance.getColumn(columnId);
2650
3281
 
3282
+ if (!column) {
3283
+ throw new Error();
3284
+ }
2651
3285
 
2652
- function compareAlphanumeric(aStr, bStr) {
2653
- // Split on number groups, but keep the delimiter
2654
- // Then remove falsey split values
2655
- var a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2656
- var b = bStr.split(reSplitAlphaNumeric).filter(Boolean); // While
3286
+ return instance.getState().columnSizingInfo.isResizingColumn === columnId;
3287
+ },
3288
+ getHeaderIsResizing: function getHeaderIsResizing(headerId) {
3289
+ var header = instance.getHeader(headerId);
2657
3290
 
2658
- while (a.length && b.length) {
2659
- var aa = a.shift();
2660
- var bb = b.shift();
2661
- var an = parseInt(aa, 10);
2662
- var bn = parseInt(bb, 10);
2663
- var combo = [an, bn].sort(); // Both are string
3291
+ if (!header) {
3292
+ throw new Error();
3293
+ }
2664
3294
 
2665
- if (isNaN(combo[0])) {
2666
- if (aa > bb) {
2667
- return 1;
3295
+ return instance.getColumnIsResizing(header.column.id);
3296
+ },
3297
+ getColumnResizerProps: function getColumnResizerProps(headerId, userProps) {
3298
+ var header = instance.getHeader(headerId);
3299
+
3300
+ if (!header) {
3301
+ return;
2668
3302
  }
2669
3303
 
2670
- if (bb > aa) {
2671
- return -1;
3304
+ var column = instance.getColumn(header.column.id);
3305
+
3306
+ if (!column) {
3307
+ return;
2672
3308
  }
2673
3309
 
2674
- continue;
2675
- } // One is a string, one is a number
3310
+ var canResize = column.getCanResize();
2676
3311
 
3312
+ var onResizeStart = function onResizeStart(e) {
3313
+ if (isTouchStartEvent(e)) {
3314
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
3315
+ if (e.touches && e.touches.length > 1) {
3316
+ return;
3317
+ }
3318
+ }
2677
3319
 
2678
- if (isNaN(combo[1])) {
2679
- return isNaN(an) ? -1 : 1;
2680
- } // Both are numbers
3320
+ var columnSizingStart = header.getLeafHeaders().map(function (d) {
3321
+ return [d.column.id, d.getWidth()];
3322
+ });
3323
+ var clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
2681
3324
 
3325
+ var updateOffset = function updateOffset(eventType, clientXPos) {
3326
+ if (typeof clientXPos !== 'number') {
3327
+ return;
3328
+ }
2682
3329
 
2683
- if (an > bn) {
2684
- return 1;
2685
- }
3330
+ var newColumnSizing = {};
3331
+ instance.setColumnSizingInfo(function (old) {
3332
+ var _old$startOffset, _old$startSize;
2686
3333
 
2687
- if (bn > an) {
2688
- return -1;
2689
- }
2690
- }
3334
+ var deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
3335
+ var deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
3336
+ old.columnSizingStart.forEach(function (_ref4) {
3337
+ var columnId = _ref4[0],
3338
+ headerWidth = _ref4[1];
3339
+ newColumnSizing[columnId] = Math.max(headerWidth + headerWidth * deltaPercentage, 0);
3340
+ });
3341
+ return _extends({}, old, {
3342
+ deltaOffset: deltaOffset,
3343
+ deltaPercentage: deltaPercentage
3344
+ });
3345
+ });
2691
3346
 
2692
- return a.length - b.length;
2693
- } // The text filter is more basic (less numeric support)
2694
- // but is much faster
3347
+ if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
3348
+ instance.setColumnSizing(function (old) {
3349
+ return _extends({}, old, newColumnSizing);
3350
+ });
3351
+ }
3352
+ };
3353
+
3354
+ var onMove = function onMove(clientXPos) {
3355
+ return updateOffset('move', clientXPos);
3356
+ };
2695
3357
 
3358
+ var onEnd = function onEnd(clientXPos) {
3359
+ updateOffset('end', clientXPos);
3360
+ instance.setColumnSizingInfo(function (old) {
3361
+ return _extends({}, old, {
3362
+ isResizingColumn: false,
3363
+ startOffset: null,
3364
+ startSize: null,
3365
+ deltaOffset: null,
3366
+ deltaPercentage: null,
3367
+ columnSizingStart: []
3368
+ });
3369
+ });
3370
+ };
2696
3371
 
2697
- function text(rowA, rowB, columnId) {
2698
- return compareBasic(toString(rowA.values[columnId]).toLowerCase(), toString(rowB.values[columnId]).toLowerCase());
2699
- } // The text filter is more basic (less numeric support)
2700
- // but is much faster
3372
+ var mouseEvents = {
3373
+ moveHandler: function moveHandler(e) {
3374
+ return onMove(e.clientX);
3375
+ },
3376
+ upHandler: function upHandler(e) {
3377
+ document.removeEventListener('mousemove', mouseEvents.moveHandler);
3378
+ document.removeEventListener('mouseup', mouseEvents.upHandler);
3379
+ onEnd(e.clientX);
3380
+ }
3381
+ };
3382
+ var touchEvents = {
3383
+ moveHandler: function moveHandler(e) {
3384
+ if (e.cancelable) {
3385
+ e.preventDefault();
3386
+ e.stopPropagation();
3387
+ }
2701
3388
 
3389
+ onMove(e.touches[0].clientX);
3390
+ return false;
3391
+ },
3392
+ upHandler: function upHandler(e) {
3393
+ document.removeEventListener('touchmove', touchEvents.moveHandler);
3394
+ document.removeEventListener('touchend', touchEvents.upHandler);
2702
3395
 
2703
- function textCaseSensitive(rowA, rowB, columnId) {
2704
- return compareBasic(toString(rowA.values[columnId]), toString(rowB.values[columnId]));
2705
- }
3396
+ if (e.cancelable) {
3397
+ e.preventDefault();
3398
+ e.stopPropagation();
3399
+ }
2706
3400
 
2707
- function datetime(rowA, rowB, columnId) {
2708
- return compareBasic(rowA.values[columnId].getTime(), rowB.values[columnId].getTime());
2709
- }
3401
+ onEnd(e.touches[0].clientX);
3402
+ }
3403
+ };
3404
+ var passiveIfSupported = passiveEventSupported() ? {
3405
+ passive: false
3406
+ } : false;
2710
3407
 
2711
- function basic(rowA, rowB, columnId) {
2712
- return compareBasic(rowA.values[columnId], rowB.values[columnId]);
2713
- } // Utils
3408
+ if (isTouchStartEvent(e)) {
3409
+ document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
3410
+ document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
3411
+ } else {
3412
+ document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
3413
+ document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
3414
+ }
2714
3415
 
3416
+ instance.setColumnSizingInfo(function (old) {
3417
+ return _extends({}, old, {
3418
+ startOffset: clientX,
3419
+ startSize: header.getWidth(),
3420
+ deltaOffset: 0,
3421
+ deltaPercentage: 0,
3422
+ columnSizingStart: columnSizingStart,
3423
+ isResizingColumn: header.column.id
3424
+ });
3425
+ });
3426
+ };
2715
3427
 
2716
- function compareBasic(a, b) {
2717
- return a === b ? 0 : a > b ? 1 : -1;
3428
+ var initialProps = canResize ? {
3429
+ title: 'Toggle Grouping',
3430
+ draggable: false,
3431
+ role: 'separator',
3432
+ onMouseDown: function onMouseDown(e) {
3433
+ e.persist();
3434
+ onResizeStart(e);
3435
+ },
3436
+ onTouchStart: function onTouchStart(e) {
3437
+ e.persist();
3438
+ onResizeStart(e);
3439
+ }
3440
+ } : {};
3441
+ return propGetter(initialProps, userProps);
3442
+ }
3443
+ };
2718
3444
  }
2719
-
2720
- function toString(a) {
2721
- if (typeof a === 'number') {
2722
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2723
- return '';
3445
+ function createColumn(column, instance) {
3446
+ return {
3447
+ getIsResizing: function getIsResizing() {
3448
+ return instance.getColumnIsResizing(column.id);
3449
+ },
3450
+ getCanResize: function getCanResize() {
3451
+ return instance.getColumnCanResize(column.id);
3452
+ },
3453
+ resetSize: function resetSize() {
3454
+ return instance.resetColumnSize(column.id);
3455
+ },
3456
+ getResizerProps: function getResizerProps(userProps) {
3457
+ return instance.getColumnResizerProps(column.id, userProps);
2724
3458
  }
3459
+ };
3460
+ }
3461
+ var passiveSupported = null;
3462
+ function passiveEventSupported() {
3463
+ if (typeof passiveSupported === 'boolean') return passiveSupported;
3464
+ var supported = false;
3465
+
3466
+ try {
3467
+ var options = {
3468
+ get passive() {
3469
+ supported = true;
3470
+ return false;
3471
+ }
3472
+
3473
+ };
3474
+
3475
+ var noop = function noop() {};
2725
3476
 
2726
- return String(a);
3477
+ window.addEventListener('test', noop, options);
3478
+ window.removeEventListener('test', noop);
3479
+ } catch (err) {
3480
+ supported = false;
2727
3481
  }
2728
3482
 
2729
- if (typeof a === 'string') {
2730
- return a;
2731
- }
3483
+ passiveSupported = supported;
3484
+ return passiveSupported;
3485
+ }
2732
3486
 
2733
- return '';
3487
+ function isTouchStartEvent(e) {
3488
+ return e.type === 'touchstart';
2734
3489
  }
2735
3490
 
3491
+ var ColumnSizing = /*#__PURE__*/Object.freeze({
3492
+ __proto__: null,
3493
+ defaultColumnSizing: defaultColumnSizing,
3494
+ getInitialState: getInitialState$2,
3495
+ getDefaultOptions: getDefaultOptions$2,
3496
+ getInstance: getInstance$2,
3497
+ createColumn: createColumn,
3498
+ passiveEventSupported: passiveEventSupported
3499
+ });
3500
+
2736
3501
  //
2737
- function getDefaultColumn() {
2738
- return {
2739
- sortType: 'auto'
2740
- };
2741
- }
2742
3502
  function getInitialState$1() {
2743
3503
  return {
2744
- sorting: []
3504
+ pagination: {
3505
+ pageIndex: 0,
3506
+ pageSize: 10
3507
+ }
2745
3508
  };
2746
3509
  }
2747
3510
  function getDefaultOptions$1(instance) {
2748
3511
  return {
2749
- onSortingChange: makeStateUpdater('sorting', instance),
2750
- autoResetSorting: true
2751
- };
2752
- }
2753
- function createColumn(column, instance) {
2754
- return {
2755
- sortType: column.sortType,
2756
- getCanSort: function getCanSort() {
2757
- return instance.getColumnCanSort(column.id);
2758
- },
2759
- getCanMultiSort: function getCanMultiSort() {
2760
- return instance.getColumnCanMultiSort(column.id);
2761
- },
2762
- getSortIndex: function getSortIndex() {
2763
- return instance.getColumnSortIndex(column.id);
2764
- },
2765
- getIsSorted: function getIsSorted() {
2766
- return instance.getColumnIsSorted(column.id);
2767
- },
2768
- toggleSorting: function toggleSorting(desc, isMulti) {
2769
- return instance.toggleColumnSorting(column.id, desc, isMulti);
2770
- },
2771
- getToggleSortingProps: function getToggleSortingProps(userProps) {
2772
- return instance.getToggleSortingProps(column.id, userProps);
2773
- }
3512
+ onPaginationChange: makeStateUpdater('pagination', instance),
3513
+ autoResetPageIndex: true
2774
3514
  };
2775
3515
  }
2776
3516
  function getInstance$1(instance) {
3517
+ var registered = false;
2777
3518
  return {
2778
- getColumnAutoSortingFn: function getColumnAutoSortingFn(columnId) {
2779
- var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2780
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
2781
-
2782
- if (typeof value === 'string') {
2783
- return sortTypes.alphanumeric;
3519
+ _notifyPageIndexReset: function _notifyPageIndexReset() {
3520
+ if (!registered) {
3521
+ registered = true;
3522
+ return;
2784
3523
  }
2785
3524
 
2786
- if (Object.prototype.toString.call(value) === '[object Date]') {
2787
- return sortTypes.datetime;
3525
+ if (instance.options.autoResetAll === false) {
3526
+ return;
2788
3527
  }
2789
3528
 
2790
- return sortTypes.basic;
2791
- },
2792
- getColumnSortingFn: function getColumnSortingFn(columnId) {
2793
- var _ref;
2794
-
2795
- var column = instance.getColumn(columnId);
2796
- var userSortTypes = instance.options.sortTypes;
2797
-
2798
- if (!column) {
2799
- throw new Error();
3529
+ if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
3530
+ instance.resetPageSize();
2800
3531
  }
2801
-
2802
- return isFunction(column.sortType) ? column.sortType : column.sortType === 'auto' ? instance.getColumnAutoFilterFn(columnId) : (_ref = userSortTypes == null ? void 0 : userSortTypes[column.sortType]) != null ? _ref : sortTypes[column.sortType];
2803
- },
2804
- setSorting: function setSorting(updater) {
2805
- return instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater, functionalUpdate(updater, instance.getState().sorting));
2806
3532
  },
2807
- toggleColumnSorting: function toggleColumnSorting(columnId, desc, multi) {
2808
- var column = instance.getColumn(columnId);
2809
-
2810
- if (!column) {
2811
- throw new Error();
2812
- }
2813
-
2814
- instance.setSorting(function (old) {
2815
- var _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2816
-
2817
- // Find any existing sorting for this column
2818
- var existingSorting = old == null ? void 0 : old.find(function (d) {
2819
- return d.id === columnId;
2820
- });
2821
- var existingIndex = old == null ? void 0 : old.findIndex(function (d) {
2822
- return d.id === columnId;
2823
- });
2824
- var hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2825
- var newSorting = []; // What should we do with this sort action?
3533
+ setPagination: function setPagination(updater) {
3534
+ var safeUpdater = function safeUpdater(old) {
3535
+ var newState = functionalUpdate(updater, old);
2826
3536
 
2827
- var sortAction;
3537
+ if (instance.options.paginateRowsFn) {
3538
+ var _instance$getPrePagin;
2828
3539
 
2829
- if (!column.getCanMultiSort() && multi) {
2830
- if (existingSorting) {
2831
- sortAction = 'toggle';
2832
- } else {
2833
- sortAction = 'add';
2834
- }
2835
- } else {
2836
- // Normal mode
2837
- if (old != null && old.length && existingIndex !== old.length - 1) {
2838
- sortAction = 'replace';
2839
- } else if (existingSorting) {
2840
- sortAction = 'toggle';
2841
- } else {
2842
- sortAction = 'replace';
2843
- }
3540
+ newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
2844
3541
  }
2845
3542
 
2846
- var sortDescFirst = (_column$sortDescFirst = column.sortDescFirst) != null ? _column$sortDescFirst : instance.options.sortDescFirst; // Handle toggle states that will remove the sorting
2847
-
2848
- if (sortAction === 'toggle' && ( // Must be toggling
2849
- (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2850
- !hasDescDefined && ( // Must not be setting desc
2851
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2852
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2853
- ? !sortDescFirst : sortDescFirst)) {
2854
- sortAction = 'remove';
2855
- }
3543
+ return newState;
3544
+ };
2856
3545
 
2857
- if (sortAction === 'replace') {
2858
- newSorting = [{
2859
- id: columnId,
2860
- desc: hasDescDefined ? desc : !!sortDescFirst
2861
- }];
2862
- } else if (sortAction === 'add' && old != null && old.length) {
2863
- var _instance$options$max;
3546
+ return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
3547
+ },
3548
+ resetPagination: function resetPagination() {
3549
+ var _instance$initialStat;
2864
3550
 
2865
- newSorting = [].concat(old, [{
2866
- id: columnId,
2867
- desc: hasDescDefined ? desc : !!sortDescFirst
2868
- }]); // Take latest n columns
3551
+ instance.setPagination((_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : {
3552
+ pageIndex: 0,
3553
+ pageSize: 10,
3554
+ pageCount: -1
3555
+ });
3556
+ },
3557
+ setPageIndex: function setPageIndex(updater) {
3558
+ instance.setPagination(function (old) {
3559
+ var pageIndex = functionalUpdate(updater, old.pageIndex);
3560
+ var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3561
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
3562
+ return _extends({}, old, {
3563
+ pageIndex: pageIndex
3564
+ });
3565
+ });
3566
+ },
3567
+ resetPageIndex: function resetPageIndex() {
3568
+ instance.setPageIndex(0);
3569
+ },
3570
+ resetPageSize: function resetPageSize() {
3571
+ var _instance$options$ini, _instance$options$ini2, _instance$options$ini3;
2869
3572
 
2870
- newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
2871
- } else if (sortAction === 'toggle' && old != null && old.length) {
2872
- // This flips (or sets) the
2873
- newSorting = old.map(function (d) {
2874
- if (d.id === columnId) {
2875
- return _extends({}, d, {
2876
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2877
- });
2878
- }
3573
+ instance.setPageSize((_instance$options$ini = (_instance$options$ini2 = instance.options.initialState) == null ? void 0 : (_instance$options$ini3 = _instance$options$ini2.pagination) == null ? void 0 : _instance$options$ini3.pageSize) != null ? _instance$options$ini : 10);
3574
+ },
3575
+ setPageSize: function setPageSize(updater) {
3576
+ instance.setPagination(function (old) {
3577
+ var pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
3578
+ var topRowIndex = old.pageSize * old.pageIndex;
3579
+ var pageIndex = Math.floor(topRowIndex / pageSize);
3580
+ return _extends({}, old, {
3581
+ pageIndex: pageIndex,
3582
+ pageSize: pageSize
3583
+ });
3584
+ });
3585
+ },
3586
+ setPageCount: function setPageCount(updater) {
3587
+ return instance.setPagination(function (old) {
3588
+ var newPageCount = functionalUpdate(updater, old.pageCount);
2879
3589
 
2880
- return d;
2881
- });
2882
- } else if (sortAction === 'remove' && old != null && old.length) {
2883
- newSorting = old.filter(function (d) {
2884
- return d.id !== columnId;
2885
- });
3590
+ if (typeof newPageCount === 'number') {
3591
+ newPageCount = Math.max(-1, newPageCount);
2886
3592
  }
2887
3593
 
2888
- return newSorting;
3594
+ return _extends({}, old, {
3595
+ pageCount: newPageCount
3596
+ });
2889
3597
  });
2890
3598
  },
2891
- getColumnCanSort: function getColumnCanSort(columnId) {
2892
- var _ref2, _ref3, _column$enableSorting;
2893
-
2894
- var column = instance.getColumn(columnId);
3599
+ getPageOptions: memo(function () {
3600
+ return [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount];
3601
+ }, function (pageSize, pageCount) {
3602
+ var pageOptions = [];
2895
3603
 
2896
- if (!column) {
2897
- throw new Error();
3604
+ if (pageCount && pageCount > 0) {
3605
+ pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3606
+ return i;
3607
+ });
2898
3608
  }
2899
3609
 
2900
- return (_ref2 = (_ref3 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref3 : column.defaultCanSort) != null ? _ref2 : !!column.accessorFn;
2901
- },
2902
- getColumnCanMultiSort: function getColumnCanMultiSort(columnId) {
2903
- var _ref4, _column$enableMultiSo;
2904
-
2905
- var column = instance.getColumn(columnId);
3610
+ return pageOptions;
3611
+ }, {
3612
+ key: 'getPageOptions',
3613
+ debug: instance.options.debug
3614
+ }),
3615
+ getCanPreviousPage: function getCanPreviousPage() {
3616
+ return instance.getState().pagination.pageIndex > 0;
3617
+ },
3618
+ getCanNextPage: function getCanNextPage() {
3619
+ var _instance$getState$pa = instance.getState().pagination,
3620
+ pageIndex = _instance$getState$pa.pageIndex,
3621
+ pageCount = _instance$getState$pa.pageCount,
3622
+ pageSize = _instance$getState$pa.pageSize;
3623
+
3624
+ if (pageCount === -1) {
3625
+ return true;
3626
+ }
2906
3627
 
2907
- if (!column) {
2908
- throw new Error();
3628
+ if (pageCount === 0) {
3629
+ return false;
2909
3630
  }
2910
3631
 
2911
- return (_ref4 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref4 : !!column.accessorFn;
3632
+ return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
2912
3633
  },
2913
- getColumnIsSorted: function getColumnIsSorted(columnId) {
2914
- var _instance$getState$so;
2915
-
2916
- var columnSort = (_instance$getState$so = instance.getState().sorting) == null ? void 0 : _instance$getState$so.find(function (d) {
2917
- return d.id === columnId;
3634
+ previousPage: function previousPage() {
3635
+ return instance.setPageIndex(function (old) {
3636
+ return old - 1;
2918
3637
  });
2919
- return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2920
- },
2921
- getColumnSortIndex: function getColumnSortIndex(columnId) {
2922
- var _instance$getState$so2, _instance$getState$so3;
2923
-
2924
- return (_instance$getState$so2 = (_instance$getState$so3 = instance.getState().sorting) == null ? void 0 : _instance$getState$so3.findIndex(function (d) {
2925
- return d.id === columnId;
2926
- })) != null ? _instance$getState$so2 : -1;
2927
- },
2928
- resetSorting: function resetSorting() {
2929
- var _instance$options$ini, _instance$options, _instance$options$ini2;
2930
-
2931
- instance.setSorting((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.sorting) != null ? _instance$options$ini : []);
2932
3638
  },
2933
- getToggleSortingProps: function getToggleSortingProps(columnId, userProps) {
2934
- var column = instance.getColumn(columnId);
2935
-
2936
- if (!column) {
2937
- throw new Error();
2938
- }
2939
-
2940
- var canSort = column.getCanSort();
2941
- var initialProps = {
2942
- title: canSort ? 'Toggle Sorting' : undefined,
2943
- onClick: canSort ? function (e) {
2944
- e.persist();
2945
- column.toggleSorting == null ? void 0 : column.toggleSorting(undefined, column.getCanMultiSort() ? instance.options.isMultiSortEvent == null ? void 0 : instance.options.isMultiSortEvent(e) : false);
2946
- } : undefined
2947
- };
2948
- return propGetter(initialProps, userProps);
3639
+ nextPage: function nextPage() {
3640
+ return instance.setPageIndex(function (old) {
3641
+ return old + 1;
3642
+ });
2949
3643
  },
2950
- getSortedRowModel: memo(function () {
2951
- return [instance.getState().sorting, instance.getGlobalFilteredRowModel(), instance.options.sortRowsFn];
2952
- }, function (sorting, rowModel, sortingFn) {
2953
- if (!sortingFn || !(sorting != null && sorting.length)) {
3644
+ getPaginationRowModel: memo(function () {
3645
+ return [instance.getState().pagination, instance.getExpandedRowModel(), instance.options.paginateRowsFn];
3646
+ }, function (_pagination, rowModel, paginateRowsFn) {
3647
+ if (!paginateRowsFn || !rowModel.rows.length) {
2954
3648
  return rowModel;
2955
3649
  }
2956
3650
 
2957
- if (instance.options.debug) console.info('Sorting...');
2958
- return sortingFn(instance, sorting, rowModel);
2959
- }, 'getSortedRowModel', instance.options.debug),
2960
- getPreSortedRows: function getPreSortedRows() {
2961
- return instance.getGlobalFilteredRowModel().rows;
3651
+ if (instance.options.debug) console.info('Paginating...');
3652
+ return paginateRowsFn(instance, rowModel);
3653
+ }, {
3654
+ key: 'getPaginationRowModel',
3655
+ debug: instance.options.debug
3656
+ }),
3657
+ getPrePaginationRows: function getPrePaginationRows() {
3658
+ return instance.getExpandedRowModel().rows;
2962
3659
  },
2963
- getPreSortedFlatRows: function getPreSortedFlatRows() {
2964
- return instance.getGlobalFilteredRowModel().flatRows;
3660
+ getPrePaginationFlatRows: function getPrePaginationFlatRows() {
3661
+ return instance.getExpandedRowModel().flatRows;
2965
3662
  },
2966
- getPreSortedRowsById: function getPreSortedRowsById() {
2967
- return instance.getGlobalFilteredRowModel().rowsById;
3663
+ getPrePaginationRowsById: function getPrePaginationRowsById() {
3664
+ return instance.getExpandedRowModel().rowsById;
2968
3665
  },
2969
- getSortedRows: function getSortedRows() {
2970
- return instance.getSortedRowModel().rows;
3666
+ getPaginationRows: function getPaginationRows() {
3667
+ return instance.getPaginationRowModel().rows;
2971
3668
  },
2972
- getSortedFlatRows: function getSortedFlatRows() {
2973
- return instance.getSortedRowModel().flatRows;
3669
+ getPaginationFlatRows: function getPaginationFlatRows() {
3670
+ return instance.getPaginationRowModel().flatRows;
2974
3671
  },
2975
- getSortedRowsById: function getSortedRowsById() {
2976
- return instance.getSortedRowModel().rowsById;
3672
+ getPaginationRowsById: function getPaginationRowsById() {
3673
+ return instance.getPaginationRowModel().rowsById;
2977
3674
  }
2978
3675
  };
2979
3676
  }
2980
3677
 
3678
+ var Pagination = /*#__PURE__*/Object.freeze({
3679
+ __proto__: null,
3680
+ getInitialState: getInitialState$1,
3681
+ getDefaultOptions: getDefaultOptions$1,
3682
+ getInstance: getInstance$1
3683
+ });
3684
+
2981
3685
  //
2982
3686
  function getInitialState() {
2983
3687
  return {
2984
- expanded: {}
3688
+ rowSelection: {}
2985
3689
  };
2986
3690
  }
2987
3691
  function getDefaultOptions(instance) {
2988
3692
  return {
2989
- onExpandedChange: makeStateUpdater('expanded', instance),
2990
- autoResetExpanded: true,
2991
- getIsRowExpanded: function getIsRowExpanded(row) {
2992
- return !!(row == null ? void 0 : row.original).expanded;
2993
- },
2994
- expandSubRows: true,
2995
- paginateExpandedRows: true
3693
+ onRowSelectionChange: makeStateUpdater('rowSelection', instance),
3694
+ autoResetRowSelection: true,
3695
+ enableRowSelection: true,
3696
+ enableMultiRowSelection: true,
3697
+ enableSubRowSelection: true // enableGroupingRowSelection: false,
3698
+ // isAdditiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.metaKey,
3699
+ // isInclusiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.shiftKey,
3700
+
2996
3701
  };
2997
3702
  }
2998
3703
  function getInstance(instance) {
3704
+ var registered = false; // const pageRows = instance.getPageRows()
3705
+
2999
3706
  return {
3000
- setExpanded: function setExpanded(updater) {
3001
- return instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater, functionalUpdate(updater, instance.getState().expanded));
3002
- },
3003
- toggleRowExpanded: function toggleRowExpanded(rowId, expanded) {
3004
- if (!rowId) return;
3005
- instance.setExpanded(function (old) {
3006
- var _old, _expanded;
3707
+ _notifyRowSelectionReset: function _notifyRowSelectionReset() {
3708
+ if (!registered) {
3709
+ registered = true;
3710
+ return;
3711
+ }
3007
3712
 
3008
- if (old === void 0) {
3009
- old = {};
3010
- }
3713
+ if (instance.options.autoResetAll === false) {
3714
+ return;
3715
+ }
3011
3716
 
3012
- var exists = old === true ? true : !!((_old = old) != null && _old[rowId]);
3013
- var oldExpanded = {};
3717
+ if (instance.options.autoResetAll === true || instance.options.autoResetRowSelection) {
3718
+ instance.resetRowSelection();
3719
+ }
3720
+ },
3721
+ setRowSelection: function setRowSelection(updater) {
3722
+ return instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater, functionalUpdate(updater, instance.getState().rowSelection));
3723
+ },
3724
+ resetRowSelection: function resetRowSelection() {
3725
+ var _getInitialState$rowS;
3014
3726
 
3015
- if (old === true) {
3016
- Object.keys(instance.getRowsById()).forEach(function (rowId) {
3017
- oldExpanded[rowId] = true;
3727
+ return instance.setRowSelection((_getInitialState$rowS = getInitialState().rowSelection) != null ? _getInitialState$rowS : {});
3728
+ },
3729
+ toggleAllRowsSelected: function toggleAllRowsSelected(value) {
3730
+ instance.setRowSelection(function (old) {
3731
+ value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected(); // Only remove/add the rows that are visible on the screen
3732
+ // Leave all the other rows that are selected alone.
3733
+
3734
+ var rowSelection = Object.assign({}, old);
3735
+ var preGroupedFlatRows = instance.getPreGroupedFlatRows(); // We don't use `mutateRowIsSelected` here for performance reasons.
3736
+ // All of the rows are flat already, so it wouldn't be worth it
3737
+
3738
+ if (value) {
3739
+ preGroupedFlatRows.forEach(function (row) {
3740
+ rowSelection[row.id] = true;
3018
3741
  });
3019
3742
  } else {
3020
- oldExpanded = old;
3743
+ preGroupedFlatRows.forEach(function (row) {
3744
+ delete rowSelection[row.id];
3745
+ });
3021
3746
  }
3022
3747
 
3023
- expanded = (_expanded = expanded) != null ? _expanded : !exists;
3024
-
3025
- if (!exists && expanded) {
3026
- var _extends2;
3748
+ return rowSelection;
3749
+ });
3750
+ },
3751
+ toggleAllPageRowsSelected: function toggleAllPageRowsSelected(value) {
3752
+ return instance.setRowSelection(function (old) {
3753
+ typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
3027
3754
 
3028
- return _extends({}, oldExpanded, (_extends2 = {}, _extends2[rowId] = true, _extends2));
3029
- }
3755
+ var rowSelection = _extends({}, old);
3030
3756
 
3031
- if (exists && !expanded) {
3032
- var _oldExpanded = oldExpanded;
3033
- _oldExpanded[rowId];
3034
- var rest = _objectWithoutPropertiesLoose(_oldExpanded, [rowId].map(_toPropertyKey));
3757
+ instance.getRows().forEach(function (row) {
3758
+ mutateRowIsSelected(rowSelection, row.id, value, instance);
3759
+ });
3760
+ return rowSelection;
3761
+ });
3762
+ },
3763
+ toggleRowSelected: function toggleRowSelected(rowId, value) {
3764
+ var row = instance.getRow(rowId);
3765
+ var isSelected = row.getIsSelected();
3766
+ instance.setRowSelection(function (old) {
3767
+ value = typeof value !== 'undefined' ? value : !isSelected;
3035
3768
 
3036
- return rest;
3769
+ if (isSelected === value) {
3770
+ return old;
3037
3771
  }
3038
3772
 
3039
- return old;
3773
+ var selectedRowIds = _extends({}, old);
3774
+
3775
+ mutateRowIsSelected(selectedRowIds, rowId, value, instance);
3776
+ return selectedRowIds;
3040
3777
  });
3041
3778
  },
3042
- toggleAllRowsExpanded: function toggleAllRowsExpanded(expanded) {
3043
- if (expanded != null ? expanded : !instance.getIsAllRowsExpanded()) {
3044
- instance.setExpanded(true);
3045
- } else {
3046
- instance.setExpanded({});
3779
+ // addRowSelectionRange: rowId => {
3780
+ // const {
3781
+ // rows,
3782
+ // rowsById,
3783
+ // options: { selectGroupingRows, selectSubRows },
3784
+ // } = instance
3785
+ // const findSelectedRow = (rows: Row[]) => {
3786
+ // let found
3787
+ // rows.find(d => {
3788
+ // if (d.getIsSelected()) {
3789
+ // found = d
3790
+ // return true
3791
+ // }
3792
+ // const subFound = findSelectedRow(d.subRows || [])
3793
+ // if (subFound) {
3794
+ // found = subFound
3795
+ // return true
3796
+ // }
3797
+ // return false
3798
+ // })
3799
+ // return found
3800
+ // }
3801
+ // const firstRow = findSelectedRow(rows) || rows[0]
3802
+ // const lastRow = rowsById[rowId]
3803
+ // let include = false
3804
+ // const selectedRowIds = {}
3805
+ // const addRow = (row: Row) => {
3806
+ // mutateRowIsSelected(selectedRowIds, row.id, true, {
3807
+ // rowsById,
3808
+ // selectGroupingRows: selectGroupingRows!,
3809
+ // selectSubRows: selectSubRows!,
3810
+ // })
3811
+ // }
3812
+ // instance.rows.forEach(row => {
3813
+ // const isFirstRow = row.id === firstRow.id
3814
+ // const isLastRow = row.id === lastRow.id
3815
+ // if (isFirstRow || isLastRow) {
3816
+ // if (!include) {
3817
+ // include = true
3818
+ // } else if (include) {
3819
+ // addRow(row)
3820
+ // include = false
3821
+ // }
3822
+ // }
3823
+ // if (include) {
3824
+ // addRow(row)
3825
+ // }
3826
+ // })
3827
+ // instance.setRowSelection(selectedRowIds)
3828
+ // },
3829
+ getSelectedRowModel: memo(function () {
3830
+ return [instance.getState().rowSelection, instance.getCoreRowModel()];
3831
+ }, function (rowSelection, rowModel) {
3832
+ if (!Object.keys(rowSelection).length) {
3833
+ return {
3834
+ rows: [],
3835
+ flatRows: [],
3836
+ rowsById: {}
3837
+ };
3838
+ }
3839
+
3840
+ if (instance.options.debug) console.info('Selecting...');
3841
+ return selectRowsFn(instance, rowModel);
3842
+ }, {
3843
+ key: 'getSelectedRowModel',
3844
+ debug: instance.options.debug,
3845
+ onChange: function onChange() {
3846
+ return instance._notifyExpandedReset();
3047
3847
  }
3848
+ }),
3849
+ getSelectedRows: function getSelectedRows() {
3850
+ return instance.getSelectedRowModel().rows;
3048
3851
  },
3049
- resetExpanded: function resetExpanded() {
3050
- var _instance$options$ini, _instance$options, _instance$options$ini2;
3852
+ getSelectedFlatRows: function getSelectedFlatRows() {
3853
+ return instance.getSelectedRowModel().flatRows;
3854
+ },
3855
+ getSelectedRowsById: function getSelectedRowsById() {
3856
+ return instance.getSelectedRowModel().rowsById;
3857
+ },
3858
+ getFilteredSelectedRowModel: memo(function () {
3859
+ return [instance.getState().rowSelection, instance.getGlobalFilteredRowModel()];
3860
+ }, function (rowSelection, rowModel) {
3861
+ if (!Object.keys(rowSelection).length) {
3862
+ return {
3863
+ rows: [],
3864
+ flatRows: [],
3865
+ rowsById: {}
3866
+ };
3867
+ }
3051
3868
 
3052
- instance.setExpanded((_instance$options$ini = (_instance$options = instance.options) == null ? void 0 : (_instance$options$ini2 = _instance$options.initialState) == null ? void 0 : _instance$options$ini2.expanded) != null ? _instance$options$ini : {});
3869
+ if (instance.options.debug) console.info('Selecting...');
3870
+ return selectRowsFn(instance, rowModel);
3871
+ }, {
3872
+ key: 'getFilteredSelectedRowModel',
3873
+ debug: instance.options.debug,
3874
+ onChange: function onChange() {
3875
+ return instance._notifyExpandedReset();
3876
+ }
3877
+ }),
3878
+ getFilteredSelectedRows: function getFilteredSelectedRows() {
3879
+ return instance.getFilteredSelectedRowModel().rows;
3053
3880
  },
3054
- getIsRowExpanded: function getIsRowExpanded(rowId) {
3055
- var _instance$options$get;
3881
+ getFilteredSelectedFlatRows: function getFilteredSelectedFlatRows() {
3882
+ return instance.getFilteredSelectedRowModel().flatRows;
3883
+ },
3884
+ getFilteredSelectedRowsById: function getFilteredSelectedRowsById() {
3885
+ return instance.getFilteredSelectedRowModel().rowsById;
3886
+ },
3887
+ getGroupedSelectedRowModel: memo(function () {
3888
+ return [instance.getState().rowSelection, instance.getGroupedRowModel()];
3889
+ }, function (rowSelection, rowModel) {
3890
+ if (!Object.keys(rowSelection).length) {
3891
+ return {
3892
+ rows: [],
3893
+ flatRows: [],
3894
+ rowsById: {}
3895
+ };
3896
+ }
3897
+
3898
+ if (instance.options.debug) console.info('Selecting...');
3899
+ return selectRowsFn(instance, rowModel);
3900
+ }, {
3901
+ key: 'getGroupedSelectedRowModel',
3902
+ debug: instance.options.debug,
3903
+ onChange: function onChange() {
3904
+ return instance._notifyExpandedReset();
3905
+ }
3906
+ }),
3907
+ getGroupedSelectedRows: function getGroupedSelectedRows() {
3908
+ return instance.getGroupedSelectedRowModel().rows;
3909
+ },
3910
+ getGroupedSelectedFlatRows: function getGroupedSelectedFlatRows() {
3911
+ return instance.getGroupedSelectedRowModel().flatRows;
3912
+ },
3913
+ getGroupedSelectedRowsById: function getGroupedSelectedRowsById() {
3914
+ return instance.getGroupedSelectedRowModel().rowsById;
3915
+ },
3916
+ ///
3917
+ getRowIsSelected: function getRowIsSelected(rowId) {
3918
+ var _instance$getState = instance.getState(),
3919
+ rowSelection = _instance$getState.rowSelection;
3056
3920
 
3057
3921
  var row = instance.getRow(rowId);
3058
3922
 
3059
3923
  if (!row) {
3060
- {
3061
- console.warn("[ReactTable] getIsRowExpanded: no row found with id " + rowId);
3062
- }
3063
-
3064
3924
  throw new Error();
3065
3925
  }
3066
3926
 
3067
- var expanded = instance.getState().expanded;
3068
- return !!((_instance$options$get = instance.options.getIsRowExpanded == null ? void 0 : instance.options.getIsRowExpanded(row)) != null ? _instance$options$get : expanded || (expanded == null ? void 0 : expanded[rowId]));
3927
+ return isRowSelected(row, rowSelection) === true;
3069
3928
  },
3070
- getRowCanExpand: function getRowCanExpand(rowId) {
3071
- var _ref, _ref2, _instance$options$get2, _row$subRows;
3929
+ getRowIsSomeSelected: function getRowIsSomeSelected(rowId) {
3930
+ var _instance$getState2 = instance.getState(),
3931
+ rowSelection = _instance$getState2.rowSelection;
3072
3932
 
3073
3933
  var row = instance.getRow(rowId);
3074
3934
 
3075
3935
  if (!row) {
3076
- {
3077
- console.warn("[ReactTable] getRowCanExpand: no row found with id " + rowId);
3078
- }
3079
-
3080
3936
  throw new Error();
3081
3937
  }
3082
3938
 
3083
- return (_ref = (_ref2 = (_instance$options$get2 = instance.options.getRowCanExpand == null ? void 0 : instance.options.getRowCanExpand(row)) != null ? _instance$options$get2 : instance.options.enableExpanded) != null ? _ref2 : instance.options.defaultCanExpand) != null ? _ref : !!((_row$subRows = row.subRows) != null && _row$subRows.length);
3939
+ return isRowSelected(row, rowSelection) === 'some';
3084
3940
  },
3085
- getToggleExpandedProps: function getToggleExpandedProps(rowId, userProps) {
3941
+ getRowCanSelect: function getRowCanSelect(rowId) {
3942
+ var _instance$options$ena;
3943
+
3086
3944
  var row = instance.getRow(rowId);
3087
3945
 
3088
3946
  if (!row) {
3089
- return;
3947
+ throw new Error();
3090
3948
  }
3091
3949
 
3092
- var canExpand = instance.getRowCanExpand(rowId);
3093
- var initialProps = {
3094
- title: canExpand ? 'Toggle Expanded' : undefined,
3095
- onClick: canExpand ? function (e) {
3096
- e.persist();
3097
- instance.toggleRowExpanded(rowId);
3098
- } : undefined
3099
- };
3100
- return propGetter(initialProps, userProps);
3950
+ if (typeof instance.options.enableRowSelection === 'function') {
3951
+ return instance.options.enableRowSelection(row);
3952
+ }
3953
+
3954
+ return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
3101
3955
  },
3102
- getToggleAllRowsExpandedProps: function getToggleAllRowsExpandedProps(userProps) {
3103
- var initialProps = {
3104
- title: 'Toggle All Expanded',
3105
- onClick: function onClick(e) {
3106
- e.persist();
3107
- instance.toggleAllRowsExpanded();
3108
- }
3109
- };
3110
- return propGetter(initialProps, userProps);
3956
+ getRowCanSelectSubRows: function getRowCanSelectSubRows(rowId) {
3957
+ var _instance$options$ena2;
3958
+
3959
+ var row = instance.getRow(rowId);
3960
+
3961
+ if (!row) {
3962
+ throw new Error();
3963
+ }
3964
+
3965
+ if (typeof instance.options.enableSubRowSelection === 'function') {
3966
+ return instance.options.enableSubRowSelection(row);
3967
+ }
3968
+
3969
+ return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
3111
3970
  },
3112
- getIsAllRowsExpanded: function getIsAllRowsExpanded() {
3113
- var expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
3971
+ getRowCanMultiSelect: function getRowCanMultiSelect(rowId) {
3972
+ var _instance$options$ena3;
3114
3973
 
3115
- if (expanded === true) {
3116
- return true;
3117
- } // If any row is not expanded, return false
3974
+ var row = instance.getRow(rowId);
3118
3975
 
3976
+ if (!row) {
3977
+ throw new Error();
3978
+ }
3119
3979
 
3120
- if (Object.keys(instance.getRowsById()).some(function (id) {
3121
- return !instance.getIsRowExpanded(id);
3122
- })) {
3123
- return false;
3124
- } // They must all be expanded :shrug:
3980
+ if (typeof instance.options.enableMultiRowSelection === 'function') {
3981
+ return instance.options.enableMultiRowSelection(row);
3982
+ }
3125
3983
 
3984
+ return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
3985
+ },
3986
+ // getGroupingRowCanSelect: rowId => {
3987
+ // const row = instance.getRow(rowId)
3988
+ // if (!row) {
3989
+ // throw new Error()
3990
+ // }
3991
+ // if (typeof instance.options.enableGroupingRowSelection === 'function') {
3992
+ // return instance.options.enableGroupingRowSelection(row)
3993
+ // }
3994
+ // return instance.options.enableGroupingRowSelection ?? false
3995
+ // },
3996
+ getIsAllRowsSelected: function getIsAllRowsSelected() {
3997
+ var preFilteredFlatRows = instance.getPreGlobalFilteredFlatRows();
3998
+
3999
+ var _instance$getState3 = instance.getState(),
4000
+ rowSelection = _instance$getState3.rowSelection;
4001
+
4002
+ var isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
4003
+
4004
+ if (isAllRowsSelected) {
4005
+ if (preFilteredFlatRows.some(function (row) {
4006
+ return !rowSelection[row.id];
4007
+ })) {
4008
+ isAllRowsSelected = false;
4009
+ }
4010
+ }
3126
4011
 
3127
- return true;
3128
- },
3129
- getExpandedDepth: function getExpandedDepth() {
3130
- var maxDepth = 0;
3131
- var rowIds = instance.getState().expanded === true ? Object.keys(instance.getRowsById()) : Object.keys(instance.getState().expanded);
3132
- rowIds.forEach(function (id) {
3133
- var splitId = id.split('.');
3134
- maxDepth = Math.max(maxDepth, splitId.length);
3135
- });
3136
- return maxDepth;
4012
+ return isAllRowsSelected;
3137
4013
  },
3138
- getExpandedRowModel: memo(function () {
3139
- return [instance.getState().expanded, instance.getGroupedRowModel(), instance.options.expandRowsFn, instance.options.paginateExpandedRows];
3140
- }, function (expanded, rowModel, expandRowsFn, paginateExpandedRows) {
3141
- if (!expandRowsFn || // Do not expand if rows are not included in pagination
3142
- !paginateExpandedRows || !Object.keys(expanded != null ? expanded : {}).length) {
3143
- return rowModel;
4014
+ getIsAllPageRowsSelected: function getIsAllPageRowsSelected() {
4015
+ var paginationFlatRows = instance.getPaginationFlatRows();
4016
+
4017
+ var _instance$getState4 = instance.getState(),
4018
+ rowSelection = _instance$getState4.rowSelection;
4019
+
4020
+ var isAllPageRowsSelected = !!paginationFlatRows.length;
4021
+
4022
+ if (isAllPageRowsSelected && paginationFlatRows.some(function (row) {
4023
+ return !rowSelection[row.id];
4024
+ })) {
4025
+ isAllPageRowsSelected = false;
3144
4026
  }
3145
4027
 
3146
- if (instance.options.debug) console.info('Expanding...');
3147
- return expandRowsFn(instance, expanded, rowModel);
3148
- }, 'getExpandedRowModel', instance.options.debug),
3149
- getPreExpandedRows: function getPreExpandedRows() {
3150
- return instance.getGroupedRowModel().rows;
4028
+ return isAllPageRowsSelected;
3151
4029
  },
3152
- getPreExpandedFlatRows: function getPreExpandedFlatRows() {
3153
- return instance.getGroupedRowModel().flatRows;
4030
+ getIsSomeRowsSelected: function getIsSomeRowsSelected() {
4031
+ var _instance$getState$ro;
4032
+
4033
+ return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
3154
4034
  },
3155
- getPreExpandedRowsById: function getPreExpandedRowsById() {
3156
- return instance.getGroupedRowModel().rowsById;
4035
+ getIsSomePageRowsSelected: function getIsSomePageRowsSelected() {
4036
+ var paginationFlatRows = instance.getPaginationFlatRows();
4037
+ return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
3157
4038
  },
3158
- getExpandedRows: function getExpandedRows() {
3159
- return instance.getExpandedRowModel().rows;
4039
+ getToggleRowSelectedProps: function getToggleRowSelectedProps(rowId, userProps) {
4040
+ var row = instance.getRow(rowId);
4041
+ var isSelected = row.getIsSelected();
4042
+ var isSomeSelected = row.getIsSomeSelected();
4043
+ var canSelect = row.getCanSelect();
4044
+ var initialProps = {
4045
+ onChange: canSelect ? function (e) {
4046
+ row.toggleSelected(e.target.checked);
4047
+ } : undefined,
4048
+ checked: isSelected,
4049
+ title: 'Toggle Row Selected',
4050
+ indeterminate: isSomeSelected // onChange: forInput
4051
+ // ? (e: Event) => e.stopPropagation()
4052
+ // : (e: Event) => {
4053
+ // if (instance.options.isAdditiveSelectEvent(e)) {
4054
+ // row.toggleSelected()
4055
+ // } else if (instance.options.isInclusiveSelectEvent(e)) {
4056
+ // instance.addRowSelectionRange(row.id)
4057
+ // } else {
4058
+ // instance.setRowSelection({})
4059
+ // row.toggleSelected()
4060
+ // }
4061
+ // if (props.onClick) props.onClick(e)
4062
+ // },
4063
+
4064
+ };
4065
+ return propGetter(initialProps, userProps);
3160
4066
  },
3161
- getExpandedFlatRows: function getExpandedFlatRows() {
3162
- return instance.getExpandedRowModel().flatRows;
4067
+ getToggleAllRowsSelectedProps: function getToggleAllRowsSelectedProps(userProps) {
4068
+ var isSomeRowsSelected = instance.getIsSomeRowsSelected();
4069
+ var isAllRowsSelected = instance.getIsAllRowsSelected();
4070
+ var initialProps = {
4071
+ onChange: function onChange(e) {
4072
+ instance.toggleAllRowsSelected(e.target.checked);
4073
+ },
4074
+ checked: isAllRowsSelected,
4075
+ title: 'Toggle All Rows Selected',
4076
+ indeterminate: isSomeRowsSelected
4077
+ };
4078
+ return propGetter(initialProps, userProps);
3163
4079
  },
3164
- getExpandedRowsById: function getExpandedRowsById() {
3165
- return instance.getExpandedRowModel().rowsById;
4080
+ getToggleAllPageRowsSelectedProps: function getToggleAllPageRowsSelectedProps(userProps) {
4081
+ var isSomePageRowsSelected = instance.getIsSomePageRowsSelected();
4082
+ var isAllPageRowsSelected = instance.getIsAllPageRowsSelected();
4083
+ var initialProps = {
4084
+ onChange: function onChange(e) {
4085
+ instance.toggleAllPageRowsSelected(e.target.checked);
4086
+ },
4087
+ checked: isAllPageRowsSelected,
4088
+ title: 'Toggle All Current Page Rows Selected',
4089
+ indeterminate: isSomePageRowsSelected
4090
+ };
4091
+ return propGetter(initialProps, userProps);
3166
4092
  }
3167
4093
  };
3168
4094
  }
3169
4095
  function createRow(row, instance) {
3170
4096
  return {
3171
- toggleExpanded: function toggleExpanded(expanded) {
3172
- return void instance.toggleRowExpanded(row.id, expanded);
4097
+ getIsSelected: function getIsSelected() {
4098
+ return instance.getRowIsSelected(row.id);
3173
4099
  },
3174
- getIsExpanded: function getIsExpanded() {
3175
- return instance.getIsRowExpanded(row.id);
4100
+ getIsSomeSelected: function getIsSomeSelected() {
4101
+ return instance.getRowIsSomeSelected(row.id);
3176
4102
  },
3177
- getCanExpand: function getCanExpand() {
3178
- return row.subRows && !!row.subRows.length;
4103
+ toggleSelected: function toggleSelected(value) {
4104
+ return instance.toggleRowSelected(row.id, value);
3179
4105
  },
3180
- getToggleExpandedProps: function getToggleExpandedProps(userProps) {
3181
- var initialProps = {
3182
- title: 'Toggle Row Expanded',
3183
- onClick: function onClick(e) {
3184
- e.stopPropagation();
3185
- instance.toggleRowExpanded(row.id);
3186
- }
3187
- };
3188
- return propGetter(initialProps, userProps);
4106
+ getToggleSelectedProps: function getToggleSelectedProps(userProps) {
4107
+ return instance.getToggleRowSelectedProps(row.id, userProps);
4108
+ },
4109
+ getCanMultiSelect: function getCanMultiSelect() {
4110
+ return instance.getRowCanMultiSelect(row.id);
4111
+ },
4112
+ getCanSelect: function getCanSelect() {
4113
+ return instance.getRowCanSelect(row.id);
3189
4114
  }
3190
4115
  };
3191
4116
  }
3192
4117
 
4118
+ var mutateRowIsSelected = function mutateRowIsSelected(selectedRowIds, id, value, instance) {
4119
+ var _row$subRows;
4120
+
4121
+ var row = instance.getRow(id);
4122
+ row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
4123
+ // !isGrouped ||
4124
+ // (isGrouped && instance.options.enableGroupingRowSelection)
4125
+ // ) {
4126
+
4127
+ if (value) {
4128
+ selectedRowIds[id] = true;
4129
+ } else {
4130
+ delete selectedRowIds[id];
4131
+ } // }
4132
+
4133
+
4134
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && instance.getRowCanSelectSubRows(row.id)) {
4135
+ row.subRows.forEach(function (row) {
4136
+ return mutateRowIsSelected(selectedRowIds, row.id, value, instance);
4137
+ });
4138
+ }
4139
+ };
4140
+
4141
+ function selectRowsFn(instance, rowModel) {
4142
+ var rowSelection = instance.getState().rowSelection;
4143
+ var newSelectedFlatRows = [];
4144
+ var newSelectedRowsById = {}; // Filters top level and nested rows
4145
+
4146
+ var recurseRows = function recurseRows(rows, depth) {
4147
+
4148
+ return rows.map(function (row) {
4149
+ var _row$subRows2;
4150
+
4151
+ var isSelected = isRowSelected(row, rowSelection) === true;
4152
+
4153
+ if (isSelected) {
4154
+ newSelectedFlatRows.push(row);
4155
+ newSelectedRowsById[row.id] = row;
4156
+ }
4157
+
4158
+ if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
4159
+ row = _extends({}, row, {
4160
+ subRows: recurseRows(row.subRows)
4161
+ });
4162
+ }
4163
+
4164
+ if (isSelected) {
4165
+ return row;
4166
+ }
4167
+ }).filter(Boolean);
4168
+ };
4169
+
4170
+ return {
4171
+ rows: recurseRows(rowModel.rows),
4172
+ flatRows: newSelectedFlatRows,
4173
+ rowsById: newSelectedRowsById
4174
+ };
4175
+ }
4176
+ function isRowSelected(row, selection, instance) {
4177
+ if (selection[row.id]) {
4178
+ return true;
4179
+ }
4180
+
4181
+ if (row.subRows && row.subRows.length) {
4182
+ var allChildrenSelected = true;
4183
+ var someSelected = false;
4184
+ row.subRows.forEach(function (subRow) {
4185
+ // Bail out early if we know both of these
4186
+ if (someSelected && !allChildrenSelected) {
4187
+ return;
4188
+ }
4189
+
4190
+ if (isRowSelected(subRow, selection)) {
4191
+ someSelected = true;
4192
+ } else {
4193
+ allChildrenSelected = false;
4194
+ }
4195
+ });
4196
+ return allChildrenSelected ? true : someSelected ? 'some' : false;
4197
+ }
4198
+
4199
+ return false;
4200
+ }
4201
+
4202
+ var RowSelection = /*#__PURE__*/Object.freeze({
4203
+ __proto__: null,
4204
+ getInitialState: getInitialState,
4205
+ getDefaultOptions: getDefaultOptions,
4206
+ getInstance: getInstance,
4207
+ createRow: createRow,
4208
+ selectRowsFn: selectRowsFn,
4209
+ isRowSelected: isRowSelected
4210
+ });
4211
+
4212
+ var features = [Visibility, Ordering, Pinning, Headers, Filters, Sorting, Grouping, Expanding, ColumnSizing, Pagination, RowSelection];
3193
4213
  function createTableInstance(options, rerender) {
3194
4214
  var _options$initialState;
3195
4215
 
@@ -3198,9 +4218,9 @@
3198
4218
  }
3199
4219
 
3200
4220
  var instance = {};
3201
-
3202
- var defaultOptions = _extends({}, getDefaultOptions$7(instance), getDefaultOptions$5(instance), getDefaultOptions$4(instance), getDefaultOptions$2(instance), getDefaultOptions$1(instance), getDefaultOptions$6(instance), getDefaultOptions(instance), getDefaultOptions$3(instance));
3203
-
4221
+ var defaultOptions = features.reduce(function (obj, feature) {
4222
+ return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
4223
+ }, {});
3204
4224
  var defaultState = {};
3205
4225
 
3206
4226
  var buildOptions = function buildOptions(options) {
@@ -3211,9 +4231,13 @@
3211
4231
 
3212
4232
  instance.options = buildOptions(options);
3213
4233
 
3214
- var initialState = _extends({}, getInitialState$7(), getInitialState$5(), getInitialState$4(), getInitialState$2(), getInitialState$1(), getInitialState$6(), getInitialState(), getInitialState$3(), (_options$initialState = options.initialState) != null ? _options$initialState : {});
4234
+ var initialState = _extends({}, features.reduce(function (obj, feature) {
4235
+ return Object.assign(obj, feature.getInitialState == null ? void 0 : feature.getInitialState());
4236
+ }, {}), (_options$initialState = options.initialState) != null ? _options$initialState : {});
3215
4237
 
3216
- var finalInstance = _extends({}, instance, getInstance$8(instance), getInstance$6(instance), getInstance$5(instance), getInstance$3(instance), getInstance$2(instance), getInstance$1(instance), getInstance$7(instance), getInstance(instance), getInstance$4(instance), {
4238
+ var finalInstance = _extends({}, instance, features.reduce(function (obj, feature) {
4239
+ return Object.assign(obj, feature.getInstance == null ? void 0 : feature.getInstance(instance));
4240
+ }, {}), {
3217
4241
  rerender: rerender,
3218
4242
  initialState: initialState,
3219
4243
  internalState: initialState,
@@ -3227,15 +4251,18 @@
3227
4251
  return "" + (parent ? [parent.id, index].join('.') : index);
3228
4252
  },
3229
4253
  getState: function getState() {
3230
- return _extends({}, instance.internalState, instance.options.state);
4254
+ var state = _extends({}, instance.internalState, instance.options.state);
4255
+
4256
+ return state;
3231
4257
  },
3232
4258
  setState: function setState(updater, shouldRerender) {
3233
4259
  if (shouldRerender === void 0) {
3234
4260
  shouldRerender = true;
3235
4261
  }
3236
4262
 
3237
- var newState = functionalUpdate(updater, instance.internalState);
3238
4263
  var onStateChange = instance.options.onStateChange;
4264
+ var internalState = instance.internalState;
4265
+ var newState = functionalUpdate(updater, internalState);
3239
4266
  instance.internalState = newState;
3240
4267
 
3241
4268
  if (onStateChange) {
@@ -3265,12 +4292,17 @@
3265
4292
  value = _ref$value === void 0 ? '' : _ref$value;
3266
4293
  return typeof value === 'boolean' ? value.toString() : value;
3267
4294
  }
3268
- }, getDefaultColumn$3(), getDefaultColumn$1(), getDefaultColumn(), getDefaultColumn$2(), defaultColumn);
3269
- }, 'getDefaultColumn', instance.options.debug),
4295
+ }, features.reduce(function (obj, feature) {
4296
+ return Object.assign(obj, feature.getDefaultColumn == null ? void 0 : feature.getDefaultColumn());
4297
+ }, {}), defaultColumn);
4298
+ }, {
4299
+ debug: instance.options.debug,
4300
+ key: 'getDefaultColumn'
4301
+ }),
3270
4302
  getColumnDefs: function getColumnDefs() {
3271
4303
  return instance.options.columns;
3272
4304
  },
3273
- createColumn: function createColumn$6(columnDef, depth, parent) {
4305
+ createColumn: function createColumn(columnDef, depth, parent) {
3274
4306
  var _ref2, _columnDef$id;
3275
4307
 
3276
4308
  var defaultColumn = instance.getDefaultColumn();
@@ -3309,7 +4341,10 @@
3309
4341
  return [column].concat((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(function (d) {
3310
4342
  return d.getFlatColumns();
3311
4343
  }));
3312
- }, 'column.getFlatColumns', instance.options.debug),
4344
+ }, {
4345
+ key: 'column.getFlatColumns',
4346
+ debug: instance.options.debug
4347
+ }),
3313
4348
  getLeafColumns: memo(function () {
3314
4349
  return [instance.getOrderColumnsFn()];
3315
4350
  }, function (orderColumns) {
@@ -3323,10 +4358,15 @@
3323
4358
  }
3324
4359
 
3325
4360
  return [column];
3326
- }, 'column.getLeafColumns', instance.options.debug)
4361
+ }, {
4362
+ key: 'column.getLeafColumns',
4363
+ debug: instance.options.debug
4364
+ })
3327
4365
  });
3328
4366
 
3329
- column = Object.assign(column, createColumn$5(column, instance), createColumn$3(column, instance), createColumn$1(column, instance), createColumn(column, instance), createColumn$4(column, instance), createColumn$2(column, instance)); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
4367
+ column = features.reduce(function (obj, feature) {
4368
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
4369
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
3330
4370
 
3331
4371
  return column;
3332
4372
  },
@@ -3348,14 +4388,20 @@
3348
4388
  };
3349
4389
 
3350
4390
  return recurseColumns(columnDefs);
3351
- }, 'getAllColumns', instance.options.debug),
4391
+ }, {
4392
+ key: 'getAllColumns',
4393
+ debug: instance.options.debug
4394
+ }),
3352
4395
  getAllFlatColumns: memo(function () {
3353
4396
  return [instance.getAllColumns()];
3354
4397
  }, function (allColumns) {
3355
4398
  return allColumns.flatMap(function (column) {
3356
4399
  return column.getFlatColumns();
3357
4400
  });
3358
- }, 'getAllFlatColumns', instance.options.debug),
4401
+ }, {
4402
+ key: 'getAllFlatColumns',
4403
+ debug: instance.options.debug
4404
+ }),
3359
4405
  getAllFlatColumnsById: memo(function () {
3360
4406
  return [instance.getAllFlatColumns()];
3361
4407
  }, function (flatColumns) {
@@ -3363,7 +4409,10 @@
3363
4409
  acc[column.id] = column;
3364
4410
  return acc;
3365
4411
  }, {});
3366
- }, 'getAllFlatColumnsById', instance.options.debug),
4412
+ }, {
4413
+ key: 'getAllFlatColumnsById',
4414
+ debug: instance.options.debug
4415
+ }),
3367
4416
  getAllLeafColumns: memo(function () {
3368
4417
  return [instance.getAllColumns(), instance.getOrderColumnsFn()];
3369
4418
  }, function (allColumns, orderColumns) {
@@ -3371,7 +4420,10 @@
3371
4420
  return column.getLeafColumns();
3372
4421
  });
3373
4422
  return orderColumns(leafColumns);
3374
- }, 'getAllLeafColumns', instance.options.debug),
4423
+ }, {
4424
+ key: 'getAllLeafColumns',
4425
+ debug: instance.options.debug
4426
+ }),
3375
4427
  getColumn: function getColumn(columnId) {
3376
4428
  var column = instance.getAllFlatColumnsById()[columnId];
3377
4429
 
@@ -3397,7 +4449,7 @@
3397
4449
  var columnSize = instance.getState().columnSizing[column.id];
3398
4450
  return Math.min(Math.max((_column$minWidth = column.minWidth) != null ? _column$minWidth : defaultColumnSizing.minWidth, (_ref3 = columnSize != null ? columnSize : column.width) != null ? _ref3 : defaultColumnSizing.width), (_column$maxWidth = column.maxWidth) != null ? _column$maxWidth : defaultColumnSizing.maxWidth);
3399
4451
  },
3400
- createCell: function createCell$1(row, column, value) {
4452
+ createCell: function createCell(row, column, value) {
3401
4453
  var cell = {
3402
4454
  id: row.id + "_" + column.id,
3403
4455
  rowId: row.id,
@@ -3410,16 +4462,20 @@
3410
4462
  },
3411
4463
  renderCell: function renderCell() {
3412
4464
  return flexRender(column.cell, {
4465
+ instance: instance,
3413
4466
  column: column,
4467
+ row: row,
3414
4468
  cell: cell,
3415
4469
  value: value
3416
4470
  });
3417
4471
  }
3418
4472
  };
3419
- Object.assign(cell, _extends({}, createCell(cell, column, row)));
4473
+ features.forEach(function (feature) {
4474
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
4475
+ }, {});
3420
4476
  return cell;
3421
4477
  },
3422
- createRow: function createRow$3(id, original, rowIndex, depth, values) {
4478
+ createRow: function createRow(id, original, rowIndex, depth, values) {
3423
4479
  var row = {
3424
4480
  id: id,
3425
4481
  index: rowIndex,
@@ -3440,7 +4496,10 @@
3440
4496
  return leafColumns.map(function (column) {
3441
4497
  return instance.createCell(row, column, row.values[column.id]);
3442
4498
  });
3443
- }, 'row.getAllCells' , instance.options.debug);
4499
+ }, {
4500
+ key: 'row.getAllCells' ,
4501
+ debug: instance.options.debug
4502
+ });
3444
4503
  row.getAllCellsByColumnId = memo(function () {
3445
4504
  return [row.getAllCells()];
3446
4505
  }, function (allCells) {
@@ -3448,42 +4507,19 @@
3448
4507
  acc[cell.columnId] = cell;
3449
4508
  return acc;
3450
4509
  }, {});
3451
- }, 'row.getAllCellsByColumnId', instance.options.debug);
3452
- row = Object.assign(row, createRow$1(row, instance), createRow$2(row, instance), createRow(row, instance));
4510
+ }, {
4511
+ key: 'row.getAllCellsByColumnId',
4512
+ debug: instance.options.debug
4513
+ });
4514
+ features.forEach(function (feature) {
4515
+ Object.assign(row, feature.createRow == null ? void 0 : feature.createRow(row, instance));
4516
+ });
3453
4517
  return row;
3454
4518
  },
3455
4519
  getCoreRowModel: memo(function () {
3456
4520
  return [instance.options.data];
3457
4521
  }, function (data) {
3458
- if (instance.options.debug) console.info('Accessing...'); // Auto-reset data-dependent states if configured
3459
-
3460
- if (instance.options.autoResetColumnFilters && // @ts-ignore
3461
- instance.getRowModelNonFirst) {
3462
- instance.resetColumnFilters();
3463
- }
3464
-
3465
- if (instance.options.autoResetGlobalFilter && // @ts-ignore
3466
- instance.getRowModelNonFirst) {
3467
- instance.resetGlobalFilter();
3468
- }
3469
-
3470
- if (instance.options.autoResetSorting && // @ts-ignore
3471
- instance.getRowModelNonFirst) {
3472
- instance.resetSorting();
3473
- }
3474
-
3475
- if (instance.options.autoResetGrouping && // @ts-ignore
3476
- instance.getRowModelNonFirst) {
3477
- instance.resetGrouping();
3478
- }
3479
-
3480
- if (instance.options.autoResetExpanded && // @ts-ignore
3481
- instance.getRowModelNonFirst) {
3482
- instance.resetExpanded();
3483
- } // @ts-ignore
3484
-
3485
-
3486
- instance.getRowModelNonFirst = true; // Access the row model using initial columns
4522
+ if (instance.options.debug) console.info('Accessing...'); // Access the row model using initial columns
3487
4523
 
3488
4524
  var rows = [];
3489
4525
  var flatRows = [];
@@ -3551,7 +4587,15 @@
3551
4587
  flatRows: flatRows,
3552
4588
  rowsById: rowsById
3553
4589
  };
3554
- }, 'getRowModel', instance.options.debug),
4590
+ }, {
4591
+ key: 'getRowModel',
4592
+ debug: instance.options.debug,
4593
+ onChange: function onChange() {
4594
+ instance._notifyRowSelectionReset();
4595
+
4596
+ instance._notifyFiltersReset();
4597
+ }
4598
+ }),
3555
4599
  // The standard
3556
4600
  getCoreRows: function getCoreRows() {
3557
4601
  return instance.getCoreRowModel().rows;
@@ -3565,7 +4609,7 @@
3565
4609
  // The final calls start at the bottom of the model,
3566
4610
  // expanded rows, which then work their way up
3567
4611
  getRowModel: function getRowModel() {
3568
- return instance.getExpandedRowModel();
4612
+ return instance.getPaginationRowModel();
3569
4613
  },
3570
4614
  getRows: function getRows() {
3571
4615
  return instance.getRowModel().rows;
@@ -3670,7 +4714,13 @@
3670
4714
  }
3671
4715
  });
3672
4716
 
3673
- return Object.assign(instance, finalInstance);
4717
+ instance = Object.assign(instance, finalInstance); // This won't trigger a rerender yet, but it will force
4718
+ // pagination derivation to run (particularly pageSize detection)
4719
+
4720
+ instance.setPagination(function (d) {
4721
+ return d;
4722
+ });
4723
+ return instance;
3674
4724
  }
3675
4725
 
3676
4726
  function createTable() {
@@ -3690,7 +4740,17 @@
3690
4740
  createColumns: function createColumns(columns) {
3691
4741
  return columns;
3692
4742
  },
3693
- createColumn: function createColumn(accessor, column) {
4743
+ createDisplayColumn: function createDisplayColumn(column) {
4744
+ return _extends({}, column, {
4745
+ __generated: true
4746
+ });
4747
+ },
4748
+ createGroup: function createGroup(column) {
4749
+ return _extends({}, column, {
4750
+ __generated: true
4751
+ });
4752
+ },
4753
+ createDataColumn: function createDataColumn(accessor, column) {
3694
4754
  column = _extends({}, column, {
3695
4755
  id: column.id
3696
4756
  });
@@ -3714,11 +4774,6 @@
3714
4774
 
3715
4775
  throw new Error('Invalid accessor');
3716
4776
  },
3717
- createGroup: function createGroup(column) {
3718
- return _extends({}, column, {
3719
- __generated: true
3720
- });
3721
- },
3722
4777
  useTable: function useTable(options) {
3723
4778
  var instanceRef = React__namespace.useRef(undefined);
3724
4779
  var rerender = React__namespace.useReducer(function () {
@@ -3741,6 +4796,7 @@
3741
4796
  exports.expandRowsFn = expandRowsFn;
3742
4797
  exports.globalFilterRowsFn = globalFilterRowsFn;
3743
4798
  exports.groupRowsFn = groupRowsFn;
4799
+ exports.paginateRowsFn = paginateRowsFn;
3744
4800
  exports.sortRowsFn = sortRowsFn;
3745
4801
 
3746
4802
  Object.defineProperty(exports, '__esModule', { value: true });