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

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