@tanstack/react-table 8.0.0-alpha.1 → 8.0.0-alpha.4

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 (100) hide show
  1. package/build/cjs/core.js +118 -59
  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 +317 -0
  6. package/build/cjs/features/ColumnSizing.js.map +1 -0
  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 +88 -22
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/Ordering.js +4 -1
  16. package/build/cjs/features/Ordering.js.map +1 -1
  17. package/build/cjs/features/Pagination.js +198 -0
  18. package/build/cjs/features/Pagination.js.map +1 -0
  19. package/build/cjs/features/Pinning.js +0 -14
  20. package/build/cjs/features/Pinning.js.map +1 -1
  21. package/build/cjs/features/RowSelection.js +541 -0
  22. package/build/cjs/features/RowSelection.js.map +1 -0
  23. package/build/cjs/features/Sorting.js +76 -18
  24. package/build/cjs/features/Sorting.js.map +1 -1
  25. package/build/cjs/features/Visibility.js +8 -2
  26. package/build/cjs/features/Visibility.js.map +1 -1
  27. package/build/cjs/index.js +2 -0
  28. package/build/cjs/index.js.map +1 -1
  29. package/build/cjs/sortTypes.js +1 -0
  30. package/build/cjs/sortTypes.js.map +1 -1
  31. package/build/cjs/utils/columnFilterRowsFn.js +3 -2
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  33. package/build/cjs/utils/expandRowsFn.js +2 -2
  34. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  35. package/build/cjs/utils/globalFilterRowsFn.js +3 -2
  36. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  37. package/build/cjs/utils/groupRowsFn.js +4 -3
  38. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  39. package/build/cjs/utils/paginateRowsFn.js +44 -0
  40. package/build/cjs/utils/paginateRowsFn.js.map +1 -0
  41. package/build/cjs/utils/sortRowsFn.js +3 -2
  42. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  43. package/build/cjs/utils.js +6 -3
  44. package/build/cjs/utils.js.map +1 -1
  45. package/build/esm/index.js +1613 -225
  46. package/build/esm/index.js.map +1 -1
  47. package/build/stats-html.html +1 -1
  48. package/build/stats-react.json +363 -217
  49. package/build/types/core.d.ts +14 -25
  50. package/build/types/createTable.d.ts +21 -3
  51. package/build/types/features/ColumnSizing.d.ts +67 -0
  52. package/build/types/features/Expanding.d.ts +2 -1
  53. package/build/types/features/Filters.d.ts +7 -2
  54. package/build/types/features/Grouping.d.ts +2 -2
  55. package/build/types/features/Ordering.d.ts +1 -1
  56. package/build/types/features/Pagination.d.ts +44 -0
  57. package/build/types/features/Pinning.d.ts +3 -3
  58. package/build/types/features/RowSelection.d.ts +66 -0
  59. package/build/types/features/Sorting.d.ts +5 -2
  60. package/build/types/index.d.ts +1 -0
  61. package/build/types/sortTypes.d.ts +5 -4
  62. package/build/types/types.d.ts +13 -8
  63. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  64. package/build/types/utils/expandRowsFn.d.ts +2 -2
  65. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  66. package/build/types/utils/groupRowsFn.d.ts +2 -2
  67. package/build/types/utils/paginateRowsFn.d.ts +2 -0
  68. package/build/types/utils/sortRowsFn.d.ts +2 -2
  69. package/build/types/utils.d.ts +7 -3
  70. package/build/umd/index.development.js +1613 -224
  71. package/build/umd/index.development.js.map +1 -1
  72. package/build/umd/index.production.js +1 -1
  73. package/build/umd/index.production.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/core.tsx +252 -265
  76. package/src/createTable.tsx +69 -9
  77. package/src/features/ColumnSizing.ts +453 -0
  78. package/src/features/Expanding.ts +27 -11
  79. package/src/features/Filters.ts +75 -20
  80. package/src/features/Grouping.ts +27 -12
  81. package/src/features/Headers.ts +55 -50
  82. package/src/features/Ordering.ts +2 -3
  83. package/src/features/Pagination.ts +327 -0
  84. package/src/features/Pinning.ts +3 -16
  85. package/src/features/RowSelection.ts +831 -0
  86. package/src/features/Sorting.ts +82 -22
  87. package/src/features/Visibility.ts +2 -4
  88. package/src/index.tsx +1 -0
  89. package/src/sortTypes.ts +1 -1
  90. package/src/types.ts +55 -9
  91. package/src/utils/columnFilterRowsFn.ts +5 -12
  92. package/src/utils/expandRowsFn.ts +2 -5
  93. package/src/utils/globalFilterRowsFn.ts +3 -10
  94. package/src/utils/groupRowsFn.ts +3 -5
  95. package/src/utils/paginateRowsFn.ts +34 -0
  96. package/src/utils/sortRowsFn.ts +5 -5
  97. package/src/utils.tsx +20 -6
  98. package/src/features/withColumnResizing.oldts +0 -281
  99. package/src/features/withPagination.oldts +0 -208
  100. 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,41 @@ var expandRowsFn = function expandRowsFn(instance, _expandedState, sortedRowMode
646
653
  flatRows: sortedRowModel.flatRows,
647
654
  rowsById: sortedRowModel.rowsById
648
655
  };
649
- };
656
+ }
657
+
658
+ function paginateRowsFn(instance, rowModel) {
659
+ var _instance$getState$pa = instance.getState().pagination,
660
+ pageSize = _instance$getState$pa.pageSize,
661
+ pageIndex = _instance$getState$pa.pageIndex;
662
+ var rows = rowModel.rows,
663
+ flatRows = rowModel.flatRows,
664
+ rowsById = rowModel.rowsById;
665
+ var pageStart = pageSize * pageIndex;
666
+ var pageEnd = pageStart + pageSize;
667
+ rows = rows.slice(pageStart, pageEnd);
668
+
669
+ if (!instance.options.paginateExpandedRows) {
670
+ return expandRowsFn(instance, {
671
+ rows: rows,
672
+ flatRows: flatRows,
673
+ rowsById: rowsById
674
+ });
675
+ }
676
+
677
+ return {
678
+ rows: rows,
679
+ flatRows: flatRows,
680
+ rowsById: rowsById
681
+ };
682
+ }
650
683
 
651
684
  //
652
- function getInitialState$6() {
685
+ function getInitialState$9() {
653
686
  return {
654
687
  columnVisibility: {}
655
688
  };
656
689
  }
657
- function getDefaultOptions$6(instance) {
690
+ function getDefaultOptions$9(instance) {
658
691
  return {
659
692
  onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
660
693
  };
@@ -664,7 +697,7 @@ function getDefaultColumn$3() {
664
697
  defaultIsVisible: true
665
698
  };
666
699
  }
667
- function createColumn$4(column, instance) {
700
+ function createColumn$5(column, instance) {
668
701
  return {
669
702
  getCanHide: function getCanHide() {
670
703
  return instance.getColumnCanHide(column.id);
@@ -688,7 +721,7 @@ function createColumn$4(column, instance) {
688
721
  }
689
722
  };
690
723
  }
691
- function getInstance$7(instance) {
724
+ function getInstance$a(instance) {
692
725
  return {
693
726
  getVisibleFlatColumns: memo(function () {
694
727
  return [instance.getAllFlatColumns(), instance.getAllFlatColumns().filter(function (d) {
@@ -700,7 +733,10 @@ function getInstance$7(instance) {
700
733
  return allFlatColumns.filter(function (d) {
701
734
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
702
735
  });
703
- }, 'getVisibleFlatColumns', instance.options.debug),
736
+ }, {
737
+ key: 'getVisibleFlatColumns',
738
+ debug: instance.options.debug
739
+ }),
704
740
  getVisibleLeafColumns: memo(function () {
705
741
  return [instance.getAllLeafColumns(), instance.getAllLeafColumns().filter(function (d) {
706
742
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
@@ -711,7 +747,10 @@ function getInstance$7(instance) {
711
747
  return allFlatColumns.filter(function (d) {
712
748
  return d.getIsVisible == null ? void 0 : d.getIsVisible();
713
749
  });
714
- }, 'getVisibleLeafColumns', instance.options.debug),
750
+ }, {
751
+ key: 'getVisibleLeafColumns',
752
+ debug: instance.options.debug
753
+ }),
715
754
  setColumnVisibility: function setColumnVisibility(updater) {
716
755
  return instance.options.onColumnVisibilityChange == null ? void 0 : instance.options.onColumnVisibilityChange(updater, functionalUpdate(updater, instance.getState().columnVisibility));
717
756
  },
@@ -785,6 +824,15 @@ function getInstance$7(instance) {
785
824
  };
786
825
  }
787
826
 
827
+ var Visibility = /*#__PURE__*/Object.freeze({
828
+ __proto__: null,
829
+ getInitialState: getInitialState$9,
830
+ getDefaultOptions: getDefaultOptions$9,
831
+ getDefaultColumn: getDefaultColumn$3,
832
+ createColumn: createColumn$5,
833
+ getInstance: getInstance$a
834
+ });
835
+
788
836
  var aggregationTypes = {
789
837
  sum: sum,
790
838
  min: min,
@@ -903,19 +951,19 @@ function getDefaultColumn$2() {
903
951
  aggregationType: 'auto'
904
952
  };
905
953
  }
906
- function getInitialState$5() {
954
+ function getInitialState$8() {
907
955
  return {
908
956
  grouping: []
909
957
  };
910
958
  }
911
- function getDefaultOptions$5(instance) {
959
+ function getDefaultOptions$8(instance) {
912
960
  return {
913
961
  onGroupingChange: makeStateUpdater('grouping', instance),
914
962
  autoResetGrouping: true,
915
963
  groupedColumnMode: 'reorder'
916
964
  };
917
965
  }
918
- function createColumn$3(column, instance) {
966
+ function createColumn$4(column, instance) {
919
967
  return {
920
968
  aggregationType: column.aggregationType,
921
969
  getCanGroup: function getCanGroup() {
@@ -935,8 +983,23 @@ function createColumn$3(column, instance) {
935
983
  }
936
984
  };
937
985
  }
938
- function getInstance$6(instance) {
986
+ function getInstance$9(instance) {
987
+ var registered = false;
939
988
  return {
989
+ _notifyGroupingReset: function _notifyGroupingReset() {
990
+ if (!registered) {
991
+ registered = true;
992
+ return;
993
+ }
994
+
995
+ if (instance.options.autoResetAll === false) {
996
+ return;
997
+ }
998
+
999
+ if (instance.options.autoResetAll === true || instance.options.autoResetGrouping) {
1000
+ instance.resetGrouping();
1001
+ }
1002
+ },
940
1003
  getColumnAutoAggregationFn: function getColumnAutoAggregationFn(columnId) {
941
1004
  var firstRow = instance.getCoreFlatRows()[0];
942
1005
  var value = firstRow == null ? void 0 : firstRow.values[columnId];
@@ -1034,8 +1097,14 @@ function getInstance$6(instance) {
1034
1097
  }
1035
1098
 
1036
1099
  if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Grouping...');
1037
- return groupRowsFn(instance, grouping, rowModel);
1038
- }, 'getGroupedRowModel', instance.options.debug),
1100
+ return groupRowsFn(instance, rowModel);
1101
+ }, {
1102
+ key: 'getGroupedRowModel',
1103
+ debug: instance.options.debug,
1104
+ onChange: function onChange() {
1105
+ return instance._notifyExpandedReset();
1106
+ }
1107
+ }),
1039
1108
  getPreGroupedRows: function getPreGroupedRows() {
1040
1109
  return instance.getSortedRowModel().rows;
1041
1110
  },
@@ -1056,7 +1125,7 @@ function getInstance$6(instance) {
1056
1125
  }
1057
1126
  };
1058
1127
  }
1059
- function createRow$2(row, instance) {
1128
+ function createRow$3(row, instance) {
1060
1129
  return {
1061
1130
  getIsGrouped: function getIsGrouped() {
1062
1131
  return instance.getRowIsGrouped(row.id);
@@ -1099,18 +1168,30 @@ function orderColumns(leafColumns, grouping, groupedColumnMode) {
1099
1168
  return [].concat(groupingColumns, nonGroupingColumns);
1100
1169
  }
1101
1170
 
1171
+ var Grouping = /*#__PURE__*/Object.freeze({
1172
+ __proto__: null,
1173
+ getDefaultColumn: getDefaultColumn$2,
1174
+ getInitialState: getInitialState$8,
1175
+ getDefaultOptions: getDefaultOptions$8,
1176
+ createColumn: createColumn$4,
1177
+ getInstance: getInstance$9,
1178
+ createRow: createRow$3,
1179
+ createCell: createCell,
1180
+ orderColumns: orderColumns
1181
+ });
1182
+
1102
1183
  //
1103
- function getInitialState$4() {
1184
+ function getInitialState$7() {
1104
1185
  return {
1105
1186
  columnOrder: []
1106
1187
  };
1107
1188
  }
1108
- function getDefaultOptions$4(instance) {
1189
+ function getDefaultOptions$7(instance) {
1109
1190
  return {
1110
1191
  onColumnOrderChange: makeStateUpdater('columnOrder', instance)
1111
1192
  };
1112
1193
  }
1113
- function getInstance$5(instance) {
1194
+ function getInstance$8(instance) {
1114
1195
  return {
1115
1196
  setColumnOrder: function setColumnOrder(updater) {
1116
1197
  return instance.options.onColumnOrderChange == null ? void 0 : instance.options.onColumnOrderChange(updater, functionalUpdate(updater, instance.getState().columnOrder));
@@ -1157,12 +1238,22 @@ function getInstance$5(instance) {
1157
1238
 
1158
1239
  return orderColumns(orderedColumns, grouping, groupedColumnMode);
1159
1240
  };
1160
- }, 'getOrderColumnsFn', instance.options.debug)
1241
+ }, {
1242
+ key: 'getOrderColumnsFn',
1243
+ debug: instance.options.debug
1244
+ })
1161
1245
  };
1162
1246
  }
1163
1247
 
1248
+ var Ordering = /*#__PURE__*/Object.freeze({
1249
+ __proto__: null,
1250
+ getInitialState: getInitialState$7,
1251
+ getDefaultOptions: getDefaultOptions$7,
1252
+ getInstance: getInstance$8
1253
+ });
1254
+
1164
1255
  //
1165
- function getInitialState$3() {
1256
+ function getInitialState$6() {
1166
1257
  return {
1167
1258
  columnPinning: {
1168
1259
  left: [],
@@ -1170,12 +1261,12 @@ function getInitialState$3() {
1170
1261
  }
1171
1262
  };
1172
1263
  }
1173
- function getDefaultOptions$3(instance) {
1264
+ function getDefaultOptions$6(instance) {
1174
1265
  return {
1175
1266
  onColumnPinningChange: makeStateUpdater('columnPinning', instance)
1176
1267
  };
1177
1268
  }
1178
- function createColumn$2(column, instance) {
1269
+ function createColumn$3(column, instance) {
1179
1270
  return {
1180
1271
  getCanPin: function getCanPin() {
1181
1272
  return instance.getColumnCanPin(column.id);
@@ -1191,7 +1282,7 @@ function createColumn$2(column, instance) {
1191
1282
  }
1192
1283
  };
1193
1284
  }
1194
- function getInstance$4(instance) {
1285
+ function getInstance$7(instance) {
1195
1286
  return {
1196
1287
  setColumnPinning: function setColumnPinning(updater) {
1197
1288
  return instance.options.onColumnPinningChange == null ? void 0 : instance.options.onColumnPinningChange(updater, functionalUpdate(updater, instance.getState().columnPinning));
@@ -1278,33 +1369,27 @@ function getInstance$4(instance) {
1278
1369
  var isRight = leafColumnIds.some(function (d) {
1279
1370
  return right == null ? void 0 : right.includes(d);
1280
1371
  });
1281
-
1282
- if (isLeft && isRight) {
1283
- return 'both';
1284
- }
1285
-
1286
1372
  return isLeft ? 'left' : isRight ? 'right' : false;
1287
1373
  },
1288
1374
  getColumnPinnedIndex: function getColumnPinnedIndex(columnId) {
1289
1375
  var _instance$getState$co2, _instance$getState$co3, _instance$getState$co4;
1290
1376
 
1291
1377
  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
1378
  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
1379
  }
1303
1380
  };
1304
1381
  }
1305
1382
 
1383
+ var Pinning = /*#__PURE__*/Object.freeze({
1384
+ __proto__: null,
1385
+ getInitialState: getInitialState$6,
1386
+ getDefaultOptions: getDefaultOptions$6,
1387
+ createColumn: createColumn$3,
1388
+ getInstance: getInstance$7
1389
+ });
1390
+
1306
1391
  //
1307
- function createRow$1(row, instance) {
1392
+ function createRow$2(row, instance) {
1308
1393
  return {
1309
1394
  _getAllVisibleCells: memo(function () {
1310
1395
  return [row.getAllCells().filter(function (cell) {
@@ -1316,12 +1401,18 @@ function createRow$1(row, instance) {
1316
1401
  return row.getAllCells().filter(function (cell) {
1317
1402
  return cell.column.getIsVisible();
1318
1403
  });
1319
- }, 'row._getAllVisibleCells', instance.options.debug),
1404
+ }, {
1405
+ key: 'row._getAllVisibleCells',
1406
+ debug: instance.options.debug
1407
+ }),
1320
1408
  getVisibleCells: memo(function () {
1321
1409
  return [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()];
1322
1410
  }, function (left, center, right) {
1323
1411
  return [].concat(left, center, right);
1324
- }, 'row.getVisibleCells', instance.options.debug),
1412
+ }, {
1413
+ key: 'row.getVisibleCells',
1414
+ debug: instance.options.debug
1415
+ }),
1325
1416
  getCenterVisibleCells: memo(function () {
1326
1417
  return [row._getAllVisibleCells(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1327
1418
  }, function (allCells, left, right) {
@@ -1329,7 +1420,10 @@ function createRow$1(row, instance) {
1329
1420
  return allCells.filter(function (d) {
1330
1421
  return !leftAndRight.includes(d.columnId);
1331
1422
  });
1332
- }, 'row.getCenterVisibleCells', instance.options.debug),
1423
+ }, {
1424
+ key: 'row.getCenterVisibleCells',
1425
+ debug: instance.options.debug
1426
+ }),
1333
1427
  getLeftVisibleCells: memo(function () {
1334
1428
  return [row._getAllVisibleCells(), instance.getState().columnPinning.left,,];
1335
1429
  }, function (allCells, left) {
@@ -1339,7 +1433,10 @@ function createRow$1(row, instance) {
1339
1433
  });
1340
1434
  }).filter(Boolean);
1341
1435
  return cells;
1342
- }, 'row.getLeftVisibleCells', instance.options.debug),
1436
+ }, {
1437
+ key: 'row.getLeftVisibleCells',
1438
+ debug: instance.options.debug
1439
+ }),
1343
1440
  getRightVisibleCells: memo(function () {
1344
1441
  return [row._getAllVisibleCells(), instance.getState().columnPinning.right];
1345
1442
  }, function (allCells, right) {
@@ -1349,10 +1446,13 @@ function createRow$1(row, instance) {
1349
1446
  });
1350
1447
  }).filter(Boolean);
1351
1448
  return cells;
1352
- }, 'row.getRightVisibleCells', instance.options.debug)
1449
+ }, {
1450
+ key: 'row.getRightVisibleCells',
1451
+ debug: instance.options.debug
1452
+ })
1353
1453
  };
1354
1454
  }
1355
- function getInstance$3(instance) {
1455
+ function getInstance$6(instance) {
1356
1456
  return {
1357
1457
  createHeader: function createHeader(column, options) {
1358
1458
  var _options$id;
@@ -1405,17 +1505,20 @@ function getInstance$3(instance) {
1405
1505
  },
1406
1506
  renderHeader: function renderHeader() {
1407
1507
  return flexRender(column.header, {
1508
+ instance: instance,
1408
1509
  header: header,
1409
1510
  column: column
1410
1511
  });
1411
1512
  },
1412
1513
  renderFooter: function renderFooter() {
1413
1514
  return flexRender(column.footer, {
1515
+ instance: instance,
1414
1516
  header: header,
1415
1517
  column: column
1416
1518
  });
1417
1519
  }
1418
- };
1520
+ }; // Yes, we have to convert instance to uknown, because we know more than the compiler here.
1521
+
1419
1522
  return header;
1420
1523
  },
1421
1524
  // Header Groups
@@ -1433,7 +1536,10 @@ function getInstance$3(instance) {
1433
1536
  });
1434
1537
  var headerGroups = buildHeaderGroups(allColumns, [].concat(leftColumns, centerColumns, rightColumns), instance);
1435
1538
  return headerGroups;
1436
- }, 'getHeaderGroups', instance.options.debug),
1539
+ }, {
1540
+ key: 'getHeaderGroups',
1541
+ debug: instance.options.debug
1542
+ }),
1437
1543
  getCenterHeaderGroups: memo(function () {
1438
1544
  return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right];
1439
1545
  }, function (allColumns, leafColumns, left, right) {
@@ -1441,7 +1547,10 @@ function getInstance$3(instance) {
1441
1547
  return !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id));
1442
1548
  });
1443
1549
  return buildHeaderGroups(allColumns, leafColumns, instance, 'center');
1444
- }, 'getCenterHeaderGroups', instance.options.debug),
1550
+ }, {
1551
+ key: 'getCenterHeaderGroups',
1552
+ debug: instance.options.debug
1553
+ }),
1445
1554
  getLeftHeaderGroups: memo(function () {
1446
1555
  return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left];
1447
1556
  }, function (allColumns, leafColumns, left) {
@@ -1449,7 +1558,10 @@ function getInstance$3(instance) {
1449
1558
  return left == null ? void 0 : left.includes(column.id);
1450
1559
  });
1451
1560
  return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
1452
- }, 'getLeftHeaderGroups', instance.options.debug),
1561
+ }, {
1562
+ key: 'getLeftHeaderGroups',
1563
+ debug: instance.options.debug
1564
+ }),
1453
1565
  getRightHeaderGroups: memo(function () {
1454
1566
  return [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right];
1455
1567
  }, function (allColumns, leafColumns, right) {
@@ -1457,28 +1569,43 @@ function getInstance$3(instance) {
1457
1569
  return right == null ? void 0 : right.includes(column.id);
1458
1570
  });
1459
1571
  return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
1460
- }, 'getRightHeaderGroups', instance.options.debug),
1572
+ }, {
1573
+ key: 'getRightHeaderGroups',
1574
+ debug: instance.options.debug
1575
+ }),
1461
1576
  // Footer Groups
1462
1577
  getFooterGroups: memo(function () {
1463
1578
  return [instance.getHeaderGroups()];
1464
1579
  }, function (headerGroups) {
1465
1580
  return [].concat(headerGroups).reverse();
1466
- }, 'getFooterGroups', instance.options.debug),
1581
+ }, {
1582
+ key: 'getFooterGroups',
1583
+ debug: instance.options.debug
1584
+ }),
1467
1585
  getLeftFooterGroups: memo(function () {
1468
1586
  return [instance.getLeftHeaderGroups()];
1469
1587
  }, function (headerGroups) {
1470
1588
  return [].concat(headerGroups).reverse();
1471
- }, 'getLeftFooterGroups', instance.options.debug),
1589
+ }, {
1590
+ key: 'getLeftFooterGroups',
1591
+ debug: instance.options.debug
1592
+ }),
1472
1593
  getCenterFooterGroups: memo(function () {
1473
1594
  return [instance.getCenterHeaderGroups()];
1474
1595
  }, function (headerGroups) {
1475
1596
  return [].concat(headerGroups).reverse();
1476
- }, 'getCenterFooterGroups', instance.options.debug),
1597
+ }, {
1598
+ key: 'getCenterFooterGroups',
1599
+ debug: instance.options.debug
1600
+ }),
1477
1601
  getRightFooterGroups: memo(function () {
1478
1602
  return [instance.getRightHeaderGroups()];
1479
1603
  }, function (headerGroups) {
1480
1604
  return [].concat(headerGroups).reverse();
1481
- }, 'getRightFooterGroups', instance.options.debug),
1605
+ }, {
1606
+ key: 'getRightFooterGroups',
1607
+ debug: instance.options.debug
1608
+ }),
1482
1609
  // Flat Headers
1483
1610
  getFlatHeaders: memo(function () {
1484
1611
  return [instance.getHeaderGroups()];
@@ -1486,28 +1613,40 @@ function getInstance$3(instance) {
1486
1613
  return headerGroups.map(function (headerGroup) {
1487
1614
  return headerGroup.headers;
1488
1615
  }).flat();
1489
- }, 'getFlatHeaders', instance.options.debug),
1616
+ }, {
1617
+ key: 'getFlatHeaders',
1618
+ debug: instance.options.debug
1619
+ }),
1490
1620
  getLeftFlatHeaders: memo(function () {
1491
1621
  return [instance.getLeftHeaderGroups()];
1492
1622
  }, function (left) {
1493
1623
  return left.map(function (headerGroup) {
1494
1624
  return headerGroup.headers;
1495
1625
  }).flat();
1496
- }, 'getLeftFlatHeaders', instance.options.debug),
1626
+ }, {
1627
+ key: 'getLeftFlatHeaders',
1628
+ debug: instance.options.debug
1629
+ }),
1497
1630
  getCenterFlatHeaders: memo(function () {
1498
1631
  return [instance.getCenterHeaderGroups()];
1499
1632
  }, function (left) {
1500
1633
  return left.map(function (headerGroup) {
1501
1634
  return headerGroup.headers;
1502
1635
  }).flat();
1503
- }, 'getCenterFlatHeaders', instance.options.debug),
1636
+ }, {
1637
+ key: 'getCenterFlatHeaders',
1638
+ debug: instance.options.debug
1639
+ }),
1504
1640
  getRightFlatHeaders: memo(function () {
1505
1641
  return [instance.getRightHeaderGroups()];
1506
1642
  }, function (left) {
1507
1643
  return left.map(function (headerGroup) {
1508
1644
  return headerGroup.headers;
1509
1645
  }).flat();
1510
- }, 'getRightFlatHeaders', instance.options.debug),
1646
+ }, {
1647
+ key: 'getRightFlatHeaders',
1648
+ debug: instance.options.debug
1649
+ }),
1511
1650
  // Leaf Headers
1512
1651
  getCenterLeafHeaders: memo(function () {
1513
1652
  return [instance.getCenterFlatHeaders()];
@@ -1517,7 +1656,10 @@ function getInstance$3(instance) {
1517
1656
 
1518
1657
  return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
1519
1658
  });
1520
- }, 'getCenterLeafHeaders', instance.options.debug),
1659
+ }, {
1660
+ key: 'getCenterLeafHeaders',
1661
+ debug: instance.options.debug
1662
+ }),
1521
1663
  getLeftLeafHeaders: memo(function () {
1522
1664
  return [instance.getLeftFlatHeaders()];
1523
1665
  }, function (flatHeaders) {
@@ -1526,7 +1668,10 @@ function getInstance$3(instance) {
1526
1668
 
1527
1669
  return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
1528
1670
  });
1529
- }, 'getLeftLeafHeaders', instance.options.debug),
1671
+ }, {
1672
+ key: 'getLeftLeafHeaders',
1673
+ debug: instance.options.debug
1674
+ }),
1530
1675
  getRightLeafHeaders: memo(function () {
1531
1676
  return [instance.getRightFlatHeaders()];
1532
1677
  }, function (flatHeaders) {
@@ -1535,7 +1680,10 @@ function getInstance$3(instance) {
1535
1680
 
1536
1681
  return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
1537
1682
  });
1538
- }, 'getRightLeafHeaders', instance.options.debug),
1683
+ }, {
1684
+ key: 'getRightLeafHeaders',
1685
+ debug: instance.options.debug
1686
+ }),
1539
1687
  getLeafHeaders: memo(function () {
1540
1688
  return [instance.getLeftHeaderGroups(), instance.getCenterHeaderGroups(), instance.getRightHeaderGroups()];
1541
1689
  }, function (left, center, right) {
@@ -1544,7 +1692,10 @@ function getInstance$3(instance) {
1544
1692
  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) {
1545
1693
  return header.getLeafHeaders();
1546
1694
  }).flat();
1547
- }, 'getLeafHeaders', instance.options.debug),
1695
+ }, {
1696
+ key: 'getLeafHeaders',
1697
+ debug: instance.options.debug
1698
+ }),
1548
1699
  getHeader: function getHeader(id) {
1549
1700
  var header = [].concat(instance.getFlatHeaders(), instance.getCenterFlatHeaders(), instance.getLeftFlatHeaders(), instance.getRightFlatHeaders()).find(function (d) {
1550
1701
  return d.id === id;
@@ -1766,6 +1917,13 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
1766
1917
  return headerGroups;
1767
1918
  }
1768
1919
 
1920
+ var Headers = /*#__PURE__*/Object.freeze({
1921
+ __proto__: null,
1922
+ createRow: createRow$2,
1923
+ getInstance: getInstance$6,
1924
+ buildHeaderGroups: buildHeaderGroups
1925
+ });
1926
+
1769
1927
  var filterTypes = {
1770
1928
  includesString: includesString,
1771
1929
  includesStringSensitive: includesStringSensitive,
@@ -1928,13 +2086,13 @@ function getDefaultColumn$1() {
1928
2086
  filterType: 'auto'
1929
2087
  };
1930
2088
  }
1931
- function getInitialState$2() {
2089
+ function getInitialState$5() {
1932
2090
  return {
1933
2091
  columnFilters: [],
1934
2092
  globalFilter: undefined
1935
2093
  };
1936
2094
  }
1937
- function getDefaultOptions$2(instance) {
2095
+ function getDefaultOptions$5(instance) {
1938
2096
  return {
1939
2097
  onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
1940
2098
  onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
@@ -1950,7 +2108,7 @@ function getDefaultOptions$2(instance) {
1950
2108
  }
1951
2109
  };
1952
2110
  }
1953
- function createColumn$1(column, instance) {
2111
+ function createColumn$2(column, instance) {
1954
2112
  var getFacetInfo = memo(function () {
1955
2113
  return [column.getPreFilteredRows()];
1956
2114
  }, function (rows) {
@@ -1987,7 +2145,10 @@ function createColumn$1(column, instance) {
1987
2145
  preFilteredUniqueValues: preFilteredUniqueValues,
1988
2146
  preFilteredMinMaxValues: preFilteredMinMaxValues
1989
2147
  };
1990
- }, 'column.getFacetInfo', instance.options.debug);
2148
+ }, {
2149
+ key: 'column.getFacetInfo',
2150
+ debug: instance.options.debug
2151
+ });
1991
2152
  return {
1992
2153
  filterType: column.filterType,
1993
2154
  getCanColumnFilter: function getCanColumnFilter() {
@@ -2019,8 +2180,31 @@ function createColumn$1(column, instance) {
2019
2180
  }
2020
2181
  };
2021
2182
  }
2022
- function getInstance$2(instance) {
2183
+ function getInstance$5(instance) {
2184
+ var registered = false;
2023
2185
  return {
2186
+ _notifyFiltersReset: function _notifyFiltersReset() {
2187
+ if (!registered) {
2188
+ registered = true;
2189
+ return;
2190
+ }
2191
+
2192
+ if (instance.options.autoResetAll === false) {
2193
+ return;
2194
+ }
2195
+
2196
+ if (instance.options.autoResetAll === true) {
2197
+ instance.resetSorting();
2198
+ } else {
2199
+ if (instance.options.autoResetColumnFilters) {
2200
+ instance.resetColumnFilters();
2201
+ }
2202
+
2203
+ if (instance.options.autoResetGlobalFilter) {
2204
+ instance.resetGlobalFilter();
2205
+ }
2206
+ }
2207
+ },
2024
2208
  getColumnAutoFilterFn: function getColumnAutoFilterFn(columnId) {
2025
2209
  var firstRow = instance.getCoreFlatRows()[0];
2026
2210
  var value = firstRow == null ? void 0 : firstRow.values[columnId];
@@ -2201,7 +2385,7 @@ function getInstance$2(instance) {
2201
2385
  }
2202
2386
 
2203
2387
  if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Column Filtering...');
2204
- return columnFiltersFn(instance, columnFilters, rowModel);
2388
+ return columnFiltersFn(instance, rowModel);
2205
2389
  }(); // Now that each filtered column has it's partially filtered rows,
2206
2390
  // lets assign the final filtered rows to all of the other columns
2207
2391
 
@@ -2221,7 +2405,24 @@ function getInstance$2(instance) {
2221
2405
  };
2222
2406
  });
2223
2407
  return columnFilteredRowModel;
2224
- }, 'getColumnFilteredRowModel', instance.options.debug),
2408
+ }, {
2409
+ key: 'getColumnFilteredRowModel',
2410
+ debug: instance.options.debug
2411
+ }),
2412
+ // These might be easier to remember than "column" filtered rows
2413
+ getPreFilteredRowModel: function getPreFilteredRowModel() {
2414
+ return instance.getCoreRowModel();
2415
+ },
2416
+ getPreFilteredRows: function getPreFilteredRows() {
2417
+ return instance.getCoreRowModel().rows;
2418
+ },
2419
+ getPreFilteredFlatRows: function getPreFilteredFlatRows() {
2420
+ return instance.getCoreRowModel().flatRows;
2421
+ },
2422
+ getPreFilteredRowsById: function getPreFilteredRowsById() {
2423
+ return instance.getCoreRowModel().rowsById;
2424
+ },
2425
+ // Pre Column Filter
2225
2426
  getPreColumnFilteredRows: function getPreColumnFilteredRows() {
2226
2427
  return instance.getCoreRowModel().rows;
2227
2428
  },
@@ -2249,7 +2450,7 @@ function getInstance$2(instance) {
2249
2450
  }
2250
2451
 
2251
2452
  if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Global Filtering...');
2252
- return globalFiltersFn(instance, globalFilterValue, columnFilteredRowModel);
2453
+ return globalFiltersFn(instance, columnFilteredRowModel);
2253
2454
  }(); // Now that each filtered column has it's partially filtered rows,
2254
2455
  // lets assign the final filtered rows to all of the other columns
2255
2456
 
@@ -2269,7 +2470,13 @@ function getInstance$2(instance) {
2269
2470
  };
2270
2471
  });
2271
2472
  return globalFilteredRowModel;
2272
- }, 'getGlobalFilteredRowModel', instance.options.debug),
2473
+ }, {
2474
+ key: 'getGlobalFilteredRowModel',
2475
+ debug: instance.options.debug,
2476
+ onChange: function onChange() {
2477
+ return instance._notifySortingReset();
2478
+ }
2479
+ }),
2273
2480
  getPreGlobalFilteredRows: function getPreGlobalFilteredRows() {
2274
2481
  return instance.getColumnFilteredRowModel().rows;
2275
2482
  },
@@ -2294,6 +2501,16 @@ function shouldAutoRemoveFilter(filterFn, value, column) {
2294
2501
  return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
2295
2502
  }
2296
2503
 
2504
+ var Filters = /*#__PURE__*/Object.freeze({
2505
+ __proto__: null,
2506
+ getDefaultColumn: getDefaultColumn$1,
2507
+ getInitialState: getInitialState$5,
2508
+ getDefaultOptions: getDefaultOptions$5,
2509
+ createColumn: createColumn$2,
2510
+ getInstance: getInstance$5,
2511
+ shouldAutoRemoveFilter: shouldAutoRemoveFilter
2512
+ });
2513
+
2297
2514
  var reSplitAlphaNumeric = /([0-9]+)/gm;
2298
2515
  var sortTypes = {
2299
2516
  alphanumeric: alphanumeric,
@@ -2405,18 +2622,21 @@ function getDefaultColumn() {
2405
2622
  sortType: 'auto'
2406
2623
  };
2407
2624
  }
2408
- function getInitialState$1() {
2625
+ function getInitialState$4() {
2409
2626
  return {
2410
2627
  sorting: []
2411
2628
  };
2412
2629
  }
2413
- function getDefaultOptions$1(instance) {
2630
+ function getDefaultOptions$4(instance) {
2414
2631
  return {
2415
2632
  onSortingChange: makeStateUpdater('sorting', instance),
2416
- autoResetSorting: true
2633
+ autoResetSorting: true,
2634
+ isMultiSortEvent: function isMultiSortEvent(e) {
2635
+ return e.shiftKey;
2636
+ }
2417
2637
  };
2418
2638
  }
2419
- function createColumn(column, instance) {
2639
+ function createColumn$1(column, instance) {
2420
2640
  return {
2421
2641
  sortType: column.sortType,
2422
2642
  getCanSort: function getCanSort() {
@@ -2439,22 +2659,60 @@ function createColumn(column, instance) {
2439
2659
  }
2440
2660
  };
2441
2661
  }
2442
- function getInstance$1(instance) {
2662
+ function getInstance$4(instance) {
2663
+ var registered = false;
2443
2664
  return {
2665
+ _notifySortingReset: function _notifySortingReset() {
2666
+ if (!registered) {
2667
+ registered = true;
2668
+ return;
2669
+ }
2670
+
2671
+ if (instance.options.autoResetAll === false) {
2672
+ return;
2673
+ }
2674
+
2675
+ if (instance.options.autoResetAll === true || instance.options.autoResetSorting) {
2676
+ instance.resetSorting();
2677
+ }
2678
+ },
2444
2679
  getColumnAutoSortingFn: function getColumnAutoSortingFn(columnId) {
2445
- var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2446
- var value = firstRow == null ? void 0 : firstRow.values[columnId];
2680
+ var firstRows = instance.getGlobalFilteredRowModel().flatRows.slice(100);
2681
+ var isString = false;
2447
2682
 
2448
- if (typeof value === 'string') {
2449
- return sortTypes.alphanumeric;
2683
+ for (var _iterator = _createForOfIteratorHelperLoose(firstRows), _step; !(_step = _iterator()).done;) {
2684
+ var row = _step.value;
2685
+ var value = row == null ? void 0 : row.values[columnId];
2686
+
2687
+ if (Object.prototype.toString.call(value) === '[object Date]') {
2688
+ return sortTypes.datetime;
2689
+ }
2690
+
2691
+ if (typeof value === 'string') {
2692
+ isString = true;
2693
+
2694
+ if (value.split(reSplitAlphaNumeric).length > 1) {
2695
+ return sortTypes.alphanumeric;
2696
+ }
2697
+ }
2450
2698
  }
2451
2699
 
2452
- if (Object.prototype.toString.call(value) === '[object Date]') {
2453
- return sortTypes.datetime;
2700
+ if (isString) {
2701
+ return sortTypes.text;
2454
2702
  }
2455
2703
 
2456
2704
  return sortTypes.basic;
2457
2705
  },
2706
+ getColumnAutoSortDir: function getColumnAutoSortDir(columnId) {
2707
+ var firstRow = instance.getGlobalFilteredRowModel().flatRows[0];
2708
+ var value = firstRow == null ? void 0 : firstRow.values[columnId];
2709
+
2710
+ if (typeof value === 'string') {
2711
+ return 'asc';
2712
+ }
2713
+
2714
+ return 'desc';
2715
+ },
2458
2716
  getColumnSortingFn: function getColumnSortingFn(columnId) {
2459
2717
  var _ref;
2460
2718
 
@@ -2465,7 +2723,7 @@ function getInstance$1(instance) {
2465
2723
  throw new Error();
2466
2724
  }
2467
2725
 
2468
- 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];
2726
+ 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];
2469
2727
  },
2470
2728
  setSorting: function setSorting(updater) {
2471
2729
  return instance.options.onSortingChange == null ? void 0 : instance.options.onSortingChange(updater, functionalUpdate(updater, instance.getState().sorting));
@@ -2475,10 +2733,18 @@ function getInstance$1(instance) {
2475
2733
 
2476
2734
  if (!column) {
2477
2735
  throw new Error();
2478
- }
2736
+ } // if (column.columns.length) {
2737
+ // column.columns.forEach((c, i) => {
2738
+ // if (c.id) {
2739
+ // instance.toggleColumnSorting(c.id, undefined, multi || !!i)
2740
+ // }
2741
+ // })
2742
+ // return
2743
+ // }
2744
+
2479
2745
 
2480
2746
  instance.setSorting(function (old) {
2481
- var _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2747
+ var _ref2, _column$sortDescFirst, _instance$options$ena, _instance$options$ena2;
2482
2748
 
2483
2749
  // Find any existing sorting for this column
2484
2750
  var existingSorting = old == null ? void 0 : old.find(function (d) {
@@ -2492,7 +2758,7 @@ function getInstance$1(instance) {
2492
2758
 
2493
2759
  var sortAction;
2494
2760
 
2495
- if (!column.getCanMultiSort() && multi) {
2761
+ if (column.getCanMultiSort() && multi) {
2496
2762
  if (existingSorting) {
2497
2763
  sortAction = 'toggle';
2498
2764
  } else {
@@ -2509,7 +2775,7 @@ function getInstance$1(instance) {
2509
2775
  }
2510
2776
  }
2511
2777
 
2512
- var sortDescFirst = (_column$sortDescFirst = column.sortDescFirst) != null ? _column$sortDescFirst : instance.options.sortDescFirst; // Handle toggle states that will remove the sorting
2778
+ 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
2513
2779
 
2514
2780
  if (sortAction === 'toggle' && ( // Must be toggling
2515
2781
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
@@ -2555,7 +2821,7 @@ function getInstance$1(instance) {
2555
2821
  });
2556
2822
  },
2557
2823
  getColumnCanSort: function getColumnCanSort(columnId) {
2558
- var _ref2, _ref3, _column$enableSorting;
2824
+ var _ref3, _ref4, _column$enableSorting;
2559
2825
 
2560
2826
  var column = instance.getColumn(columnId);
2561
2827
 
@@ -2563,10 +2829,13 @@ function getInstance$1(instance) {
2563
2829
  throw new Error();
2564
2830
  }
2565
2831
 
2566
- return (_ref2 = (_ref3 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref3 : column.defaultCanSort) != null ? _ref2 : !!column.accessorFn;
2832
+ return (_ref3 = (_ref4 = (_column$enableSorting = column.enableSorting) != null ? _column$enableSorting : instance.options.enableSorting) != null ? _ref4 : column.defaultCanSort) != null ? _ref3 : !!column.accessorFn // (!!column.accessorFn ||
2833
+ // column.columns?.some(c => c.id && instance.getColumnCanSort(c.id))) ??
2834
+ // false
2835
+ ;
2567
2836
  },
2568
2837
  getColumnCanMultiSort: function getColumnCanMultiSort(columnId) {
2569
- var _ref4, _column$enableMultiSo;
2838
+ var _ref5, _column$enableMultiSo;
2570
2839
 
2571
2840
  var column = instance.getColumn(columnId);
2572
2841
 
@@ -2574,7 +2843,7 @@ function getInstance$1(instance) {
2574
2843
  throw new Error();
2575
2844
  }
2576
2845
 
2577
- return (_ref4 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref4 : !!column.accessorFn;
2846
+ return (_ref5 = (_column$enableMultiSo = column.enableMultiSort) != null ? _column$enableMultiSo : instance.options.enableMultiSort) != null ? _ref5 : !!column.accessorFn;
2578
2847
  },
2579
2848
  getColumnIsSorted: function getColumnIsSorted(columnId) {
2580
2849
  var _instance$getState$so;
@@ -2621,8 +2890,14 @@ function getInstance$1(instance) {
2621
2890
  }
2622
2891
 
2623
2892
  if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Sorting...');
2624
- return sortingFn(instance, sorting, rowModel);
2625
- }, 'getSortedRowModel', instance.options.debug),
2893
+ return sortingFn(instance, rowModel);
2894
+ }, {
2895
+ key: 'getSortedRowModel',
2896
+ debug: instance.options.debug,
2897
+ onChange: function onChange() {
2898
+ return instance._notifyGroupingReset();
2899
+ }
2900
+ }),
2626
2901
  getPreSortedRows: function getPreSortedRows() {
2627
2902
  return instance.getGlobalFilteredRowModel().rows;
2628
2903
  },
@@ -2644,13 +2919,22 @@ function getInstance$1(instance) {
2644
2919
  };
2645
2920
  }
2646
2921
 
2922
+ var Sorting = /*#__PURE__*/Object.freeze({
2923
+ __proto__: null,
2924
+ getDefaultColumn: getDefaultColumn,
2925
+ getInitialState: getInitialState$4,
2926
+ getDefaultOptions: getDefaultOptions$4,
2927
+ createColumn: createColumn$1,
2928
+ getInstance: getInstance$4
2929
+ });
2930
+
2647
2931
  //
2648
- function getInitialState() {
2932
+ function getInitialState$3() {
2649
2933
  return {
2650
2934
  expanded: {}
2651
2935
  };
2652
2936
  }
2653
- function getDefaultOptions(instance) {
2937
+ function getDefaultOptions$3(instance) {
2654
2938
  return {
2655
2939
  onExpandedChange: makeStateUpdater('expanded', instance),
2656
2940
  autoResetExpanded: true,
@@ -2661,8 +2945,23 @@ function getDefaultOptions(instance) {
2661
2945
  paginateExpandedRows: true
2662
2946
  };
2663
2947
  }
2664
- function getInstance(instance) {
2948
+ function getInstance$3(instance) {
2949
+ var registered = false;
2665
2950
  return {
2951
+ _notifyExpandedReset: function _notifyExpandedReset() {
2952
+ if (!registered) {
2953
+ registered = true;
2954
+ return;
2955
+ }
2956
+
2957
+ if (instance.options.autoResetAll === false) {
2958
+ return;
2959
+ }
2960
+
2961
+ if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
2962
+ instance.resetExpanded();
2963
+ }
2964
+ },
2666
2965
  setExpanded: function setExpanded(updater) {
2667
2966
  return instance.options.onExpandedChange == null ? void 0 : instance.options.onExpandedChange(updater, functionalUpdate(updater, instance.getState().expanded));
2668
2967
  },
@@ -2810,8 +3109,14 @@ function getInstance(instance) {
2810
3109
  }
2811
3110
 
2812
3111
  if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Expanding...');
2813
- return expandRowsFn(instance, expanded, rowModel);
2814
- }, 'getExpandedRowModel', instance.options.debug),
3112
+ return expandRowsFn(instance, rowModel);
3113
+ }, {
3114
+ key: 'getExpandedRowModel',
3115
+ debug: instance.options.debug,
3116
+ onChange: function onChange() {
3117
+ return instance._notifyPageIndexReset();
3118
+ }
3119
+ }),
2815
3120
  getPreExpandedRows: function getPreExpandedRows() {
2816
3121
  return instance.getGroupedRowModel().rows;
2817
3122
  },
@@ -2832,7 +3137,7 @@ function getInstance(instance) {
2832
3137
  }
2833
3138
  };
2834
3139
  }
2835
- function createRow(row, instance) {
3140
+ function createRow$1(row, instance) {
2836
3141
  return {
2837
3142
  toggleExpanded: function toggleExpanded(expanded) {
2838
3143
  return void instance.toggleRowExpanded(row.id, expanded);
@@ -2856,87 +3161,1122 @@ function createRow(row, instance) {
2856
3161
  };
2857
3162
  }
2858
3163
 
2859
- function createTableInstance(options, rerender) {
2860
- var _options$initialState;
3164
+ var Expanding = /*#__PURE__*/Object.freeze({
3165
+ __proto__: null,
3166
+ getInitialState: getInitialState$3,
3167
+ getDefaultOptions: getDefaultOptions$3,
3168
+ getInstance: getInstance$3,
3169
+ createRow: createRow$1
3170
+ });
2861
3171
 
2862
- if (process.env.NODE_ENV !== 'production' && options.debug) {
2863
- console.info('Creating React Table Instance...');
2864
- }
3172
+ //
3173
+ var defaultColumnSizing = {
3174
+ width: 150,
3175
+ minWidth: 20,
3176
+ maxWidth: Number.MAX_SAFE_INTEGER
3177
+ };
3178
+ function getInitialState$2() {
3179
+ return {
3180
+ columnSizing: {},
3181
+ columnSizingInfo: {
3182
+ startOffset: null,
3183
+ startSize: null,
3184
+ deltaOffset: null,
3185
+ deltaPercentage: null,
3186
+ isResizingColumn: false,
3187
+ columnSizingStart: []
3188
+ }
3189
+ };
3190
+ }
3191
+ function getDefaultOptions$2(instance) {
3192
+ return {
3193
+ columnResizeMode: 'onEnd',
3194
+ onColumnSizingChange: makeStateUpdater('columnSizing', instance),
3195
+ onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', instance)
3196
+ };
3197
+ }
3198
+ function getInstance$2(instance) {
3199
+ return {
3200
+ setColumnSizing: function setColumnSizing(updater) {
3201
+ return instance.options.onColumnSizingChange == null ? void 0 : instance.options.onColumnSizingChange(updater, functionalUpdate(updater, instance.getState().columnSizing));
3202
+ },
3203
+ setColumnSizingInfo: function setColumnSizingInfo(updater) {
3204
+ return instance.options.onColumnSizingInfoChange == null ? void 0 : instance.options.onColumnSizingInfoChange(updater, functionalUpdate(updater, instance.getState().columnSizingInfo));
3205
+ },
3206
+ resetColumnSizing: function resetColumnSizing() {
3207
+ var _instance$initialStat;
2865
3208
 
2866
- var instance = {};
3209
+ instance.setColumnSizing((_instance$initialStat = instance.initialState.columnSizing) != null ? _instance$initialStat : {});
3210
+ },
3211
+ resetHeaderSizeInfo: function resetHeaderSizeInfo() {
3212
+ var _instance$initialStat2;
2867
3213
 
2868
- var defaultOptions = _extends({}, getDefaultOptions$6(instance), getDefaultOptions$4(instance), getDefaultOptions$3(instance), getDefaultOptions$2(instance), getDefaultOptions$1(instance), getDefaultOptions$5(instance), getDefaultOptions(instance));
3214
+ instance.setColumnSizingInfo((_instance$initialStat2 = instance.initialState.columnSizingInfo) != null ? _instance$initialStat2 : {});
3215
+ },
3216
+ resetColumnSize: function resetColumnSize(columnId) {
3217
+ instance.setColumnSizing(function (_ref) {
3218
+ _ref[columnId];
3219
+ var rest = _objectWithoutPropertiesLoose(_ref, [columnId].map(_toPropertyKey));
2869
3220
 
2870
- var defaultState = {};
3221
+ return rest;
3222
+ });
3223
+ },
3224
+ resetHeaderSize: function resetHeaderSize(headerId) {
3225
+ var header = instance.getHeader(headerId);
2871
3226
 
2872
- var buildOptions = function buildOptions(options) {
2873
- return _extends({
2874
- state: defaultState
2875
- }, defaultOptions, options);
2876
- };
3227
+ if (!header) {
3228
+ return;
3229
+ }
2877
3230
 
2878
- instance.options = buildOptions(options);
3231
+ return instance.resetColumnSize(header.column.id);
3232
+ },
3233
+ getHeaderCanResize: function getHeaderCanResize(headerId) {
3234
+ var header = instance.getHeader(headerId);
2879
3235
 
2880
- var initialState = _extends({}, getInitialState$6(), getInitialState$4(), getInitialState$3(), getInitialState$2(), getInitialState$1(), getInitialState$5(), getInitialState(), (_options$initialState = options.initialState) != null ? _options$initialState : {});
3236
+ if (!header) {
3237
+ throw new Error();
3238
+ }
2881
3239
 
2882
- var finalInstance = _extends({}, instance, getInstance$7(instance), getInstance$5(instance), getInstance$4(instance), getInstance$3(instance), getInstance$2(instance), getInstance$1(instance), getInstance$6(instance), getInstance(instance), {
2883
- rerender: rerender,
2884
- initialState: initialState,
2885
- internalState: initialState,
2886
- reset: function reset() {
2887
- instance.setState(instance.initialState);
2888
- },
2889
- updateOptions: function updateOptions(newOptions) {
2890
- instance.options = buildOptions(newOptions);
3240
+ return instance.getColumnCanResize(header.column.id);
2891
3241
  },
2892
- getRowId: function getRowId(_, index, parent) {
2893
- return "" + (parent ? [parent.id, index].join('.') : index);
3242
+ getColumnCanResize: function getColumnCanResize(columnId) {
3243
+ var _ref2, _ref3, _column$enableResizin;
3244
+
3245
+ var column = instance.getColumn(columnId);
3246
+
3247
+ if (!column) {
3248
+ throw new Error();
3249
+ }
3250
+
3251
+ return (_ref2 = (_ref3 = (_column$enableResizin = column.enableResizing) != null ? _column$enableResizin : instance.options.enableColumnResizing) != null ? _ref3 : column.defaultCanResize) != null ? _ref2 : true;
2894
3252
  },
2895
- getState: function getState() {
2896
- return _extends({}, instance.internalState, instance.options.state);
3253
+ getColumnIsResizing: function getColumnIsResizing(columnId) {
3254
+ var column = instance.getColumn(columnId);
3255
+
3256
+ if (!column) {
3257
+ throw new Error();
3258
+ }
3259
+
3260
+ return instance.getState().columnSizingInfo.isResizingColumn === columnId;
2897
3261
  },
2898
- setState: function setState(updater, shouldRerender) {
2899
- if (shouldRerender === void 0) {
2900
- shouldRerender = true;
3262
+ getHeaderIsResizing: function getHeaderIsResizing(headerId) {
3263
+ var header = instance.getHeader(headerId);
3264
+
3265
+ if (!header) {
3266
+ throw new Error();
2901
3267
  }
2902
3268
 
2903
- var newState = functionalUpdate(updater, instance.internalState);
2904
- var onStateChange = instance.options.onStateChange;
2905
- instance.internalState = newState;
3269
+ return instance.getColumnIsResizing(header.column.id);
3270
+ },
3271
+ getColumnResizerProps: function getColumnResizerProps(headerId, userProps) {
3272
+ var header = instance.getHeader(headerId);
2906
3273
 
2907
- if (onStateChange) {
2908
- onStateChange(newState);
3274
+ if (!header) {
2909
3275
  return;
2910
3276
  }
2911
3277
 
2912
- if (shouldRerender) {
2913
- instance.rerender();
3278
+ var column = instance.getColumn(header.column.id);
3279
+
3280
+ if (!column) {
3281
+ return;
2914
3282
  }
2915
- },
2916
- getDefaultColumn: memo(function () {
2917
- return [instance.options.defaultColumn];
2918
- }, function (defaultColumn) {
2919
- var _defaultColumn;
2920
3283
 
2921
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2922
- return _extends({
2923
- header: function header(props) {
2924
- return props.header.column.id;
2925
- },
2926
- footer: function footer(props) {
2927
- return props.header.column.id;
2928
- },
2929
- cell: function cell(_ref) {
2930
- var _ref$value = _ref.value,
3284
+ var canResize = column.getCanResize();
3285
+
3286
+ var onResizeStart = function onResizeStart(e) {
3287
+ if (isTouchStartEvent(e)) {
3288
+ // lets not respond to multiple touches (e.g. 2 or 3 fingers)
3289
+ if (e.touches && e.touches.length > 1) {
3290
+ return;
3291
+ }
3292
+ }
3293
+
3294
+ var columnSizingStart = header.getLeafHeaders().map(function (d) {
3295
+ return [d.column.id, d.getWidth()];
3296
+ });
3297
+ var clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
3298
+
3299
+ var updateOffset = function updateOffset(eventType, clientXPos) {
3300
+ if (typeof clientXPos !== 'number') {
3301
+ return;
3302
+ }
3303
+
3304
+ var newColumnSizing = {};
3305
+ instance.setColumnSizingInfo(function (old) {
3306
+ var _old$startOffset, _old$startSize;
3307
+
3308
+ var deltaOffset = clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0);
3309
+ var deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
3310
+ old.columnSizingStart.forEach(function (_ref4) {
3311
+ var columnId = _ref4[0],
3312
+ headerWidth = _ref4[1];
3313
+ newColumnSizing[columnId] = Math.max(headerWidth + headerWidth * deltaPercentage, 0);
3314
+ });
3315
+ return _extends({}, old, {
3316
+ deltaOffset: deltaOffset,
3317
+ deltaPercentage: deltaPercentage
3318
+ });
3319
+ });
3320
+
3321
+ if (instance.options.columnResizeMode === 'onChange' || eventType === 'end') {
3322
+ instance.setColumnSizing(function (old) {
3323
+ return _extends({}, old, newColumnSizing);
3324
+ });
3325
+ }
3326
+ };
3327
+
3328
+ var onMove = function onMove(clientXPos) {
3329
+ return updateOffset('move', clientXPos);
3330
+ };
3331
+
3332
+ var onEnd = function onEnd(clientXPos) {
3333
+ updateOffset('end', clientXPos);
3334
+ instance.setColumnSizingInfo(function (old) {
3335
+ return _extends({}, old, {
3336
+ isResizingColumn: false,
3337
+ startOffset: null,
3338
+ startSize: null,
3339
+ deltaOffset: null,
3340
+ deltaPercentage: null,
3341
+ columnSizingStart: []
3342
+ });
3343
+ });
3344
+ };
3345
+
3346
+ var mouseEvents = {
3347
+ moveHandler: function moveHandler(e) {
3348
+ return onMove(e.clientX);
3349
+ },
3350
+ upHandler: function upHandler(e) {
3351
+ document.removeEventListener('mousemove', mouseEvents.moveHandler);
3352
+ document.removeEventListener('mouseup', mouseEvents.upHandler);
3353
+ onEnd(e.clientX);
3354
+ }
3355
+ };
3356
+ var touchEvents = {
3357
+ moveHandler: function moveHandler(e) {
3358
+ if (e.cancelable) {
3359
+ e.preventDefault();
3360
+ e.stopPropagation();
3361
+ }
3362
+
3363
+ onMove(e.touches[0].clientX);
3364
+ return false;
3365
+ },
3366
+ upHandler: function upHandler(e) {
3367
+ document.removeEventListener('touchmove', touchEvents.moveHandler);
3368
+ document.removeEventListener('touchend', touchEvents.upHandler);
3369
+
3370
+ if (e.cancelable) {
3371
+ e.preventDefault();
3372
+ e.stopPropagation();
3373
+ }
3374
+
3375
+ onEnd(e.touches[0].clientX);
3376
+ }
3377
+ };
3378
+ var passiveIfSupported = passiveEventSupported() ? {
3379
+ passive: false
3380
+ } : false;
3381
+
3382
+ if (isTouchStartEvent(e)) {
3383
+ document.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
3384
+ document.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
3385
+ } else {
3386
+ document.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
3387
+ document.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
3388
+ }
3389
+
3390
+ instance.setColumnSizingInfo(function (old) {
3391
+ return _extends({}, old, {
3392
+ startOffset: clientX,
3393
+ startSize: header.getWidth(),
3394
+ deltaOffset: 0,
3395
+ deltaPercentage: 0,
3396
+ columnSizingStart: columnSizingStart,
3397
+ isResizingColumn: header.column.id
3398
+ });
3399
+ });
3400
+ };
3401
+
3402
+ var initialProps = canResize ? {
3403
+ title: 'Toggle Grouping',
3404
+ draggable: false,
3405
+ role: 'separator',
3406
+ onMouseDown: function onMouseDown(e) {
3407
+ e.persist();
3408
+ onResizeStart(e);
3409
+ },
3410
+ onTouchStart: function onTouchStart(e) {
3411
+ e.persist();
3412
+ onResizeStart(e);
3413
+ }
3414
+ } : {};
3415
+ return propGetter(initialProps, userProps);
3416
+ }
3417
+ };
3418
+ }
3419
+ function createColumn(column, instance) {
3420
+ return {
3421
+ getIsResizing: function getIsResizing() {
3422
+ return instance.getColumnIsResizing(column.id);
3423
+ },
3424
+ getCanResize: function getCanResize() {
3425
+ return instance.getColumnCanResize(column.id);
3426
+ },
3427
+ resetSize: function resetSize() {
3428
+ return instance.resetColumnSize(column.id);
3429
+ },
3430
+ getResizerProps: function getResizerProps(userProps) {
3431
+ return instance.getColumnResizerProps(column.id, userProps);
3432
+ }
3433
+ };
3434
+ }
3435
+ var passiveSupported = null;
3436
+ function passiveEventSupported() {
3437
+ if (typeof passiveSupported === 'boolean') return passiveSupported;
3438
+ var supported = false;
3439
+
3440
+ try {
3441
+ var options = {
3442
+ get passive() {
3443
+ supported = true;
3444
+ return false;
3445
+ }
3446
+
3447
+ };
3448
+
3449
+ var noop = function noop() {};
3450
+
3451
+ window.addEventListener('test', noop, options);
3452
+ window.removeEventListener('test', noop);
3453
+ } catch (err) {
3454
+ supported = false;
3455
+ }
3456
+
3457
+ passiveSupported = supported;
3458
+ return passiveSupported;
3459
+ }
3460
+
3461
+ function isTouchStartEvent(e) {
3462
+ return e.type === 'touchstart';
3463
+ }
3464
+
3465
+ var ColumnSizing = /*#__PURE__*/Object.freeze({
3466
+ __proto__: null,
3467
+ defaultColumnSizing: defaultColumnSizing,
3468
+ getInitialState: getInitialState$2,
3469
+ getDefaultOptions: getDefaultOptions$2,
3470
+ getInstance: getInstance$2,
3471
+ createColumn: createColumn,
3472
+ passiveEventSupported: passiveEventSupported
3473
+ });
3474
+
3475
+ //
3476
+ function getInitialState$1() {
3477
+ return {
3478
+ pagination: {
3479
+ pageIndex: 0,
3480
+ pageSize: 10
3481
+ }
3482
+ };
3483
+ }
3484
+ function getDefaultOptions$1(instance) {
3485
+ return {
3486
+ onPaginationChange: makeStateUpdater('pagination', instance),
3487
+ autoResetPageIndex: true
3488
+ };
3489
+ }
3490
+ function getInstance$1(instance) {
3491
+ var registered = false;
3492
+ return {
3493
+ _notifyPageIndexReset: function _notifyPageIndexReset() {
3494
+ if (!registered) {
3495
+ registered = true;
3496
+ return;
3497
+ }
3498
+
3499
+ if (instance.options.autoResetAll === false) {
3500
+ return;
3501
+ }
3502
+
3503
+ if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
3504
+ instance.resetPageSize();
3505
+ }
3506
+ },
3507
+ setPagination: function setPagination(updater) {
3508
+ var safeUpdater = function safeUpdater(old) {
3509
+ var newState = functionalUpdate(updater, old);
3510
+
3511
+ if (instance.options.paginateRowsFn) {
3512
+ var _instance$getPrePagin;
3513
+
3514
+ newState.pageCount = (_instance$getPrePagin = instance.getPrePaginationRows()) != null && _instance$getPrePagin.length ? Math.ceil(instance.getPrePaginationRows().length / instance.getState().pagination.pageSize) : 0;
3515
+ }
3516
+
3517
+ return newState;
3518
+ };
3519
+
3520
+ return instance.options.onPaginationChange == null ? void 0 : instance.options.onPaginationChange(safeUpdater, functionalUpdate(safeUpdater, instance.getState().pagination));
3521
+ },
3522
+ resetPagination: function resetPagination() {
3523
+ var _instance$initialStat;
3524
+
3525
+ instance.setPagination((_instance$initialStat = instance.initialState.pagination) != null ? _instance$initialStat : {
3526
+ pageIndex: 0,
3527
+ pageSize: 10,
3528
+ pageCount: -1
3529
+ });
3530
+ },
3531
+ setPageIndex: function setPageIndex(updater) {
3532
+ instance.setPagination(function (old) {
3533
+ var pageIndex = functionalUpdate(updater, old.pageIndex);
3534
+ var maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
3535
+ pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
3536
+ return _extends({}, old, {
3537
+ pageIndex: pageIndex
3538
+ });
3539
+ });
3540
+ },
3541
+ resetPageIndex: function resetPageIndex() {
3542
+ instance.setPageIndex(0);
3543
+ },
3544
+ resetPageSize: function resetPageSize() {
3545
+ var _instance$options$ini, _instance$options$ini2, _instance$options$ini3;
3546
+
3547
+ 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);
3548
+ },
3549
+ setPageSize: function setPageSize(updater) {
3550
+ instance.setPagination(function (old) {
3551
+ var pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
3552
+ var topRowIndex = old.pageSize * old.pageIndex;
3553
+ var pageIndex = Math.floor(topRowIndex / pageSize);
3554
+ return _extends({}, old, {
3555
+ pageIndex: pageIndex,
3556
+ pageSize: pageSize
3557
+ });
3558
+ });
3559
+ },
3560
+ setPageCount: function setPageCount(updater) {
3561
+ return instance.setPagination(function (old) {
3562
+ var newPageCount = functionalUpdate(updater, old.pageCount);
3563
+
3564
+ if (typeof newPageCount === 'number') {
3565
+ newPageCount = Math.max(-1, newPageCount);
3566
+ }
3567
+
3568
+ return _extends({}, old, {
3569
+ pageCount: newPageCount
3570
+ });
3571
+ });
3572
+ },
3573
+ getPageOptions: memo(function () {
3574
+ return [instance.getState().pagination.pageSize, instance.getState().pagination.pageCount];
3575
+ }, function (pageSize, pageCount) {
3576
+ var pageOptions = [];
3577
+
3578
+ if (pageCount && pageCount > 0) {
3579
+ pageOptions = [].concat(new Array(pageCount)).fill(null).map(function (_, i) {
3580
+ return i;
3581
+ });
3582
+ }
3583
+
3584
+ return pageOptions;
3585
+ }, {
3586
+ key: 'getPageOptions',
3587
+ debug: instance.options.debug
3588
+ }),
3589
+ getCanPreviousPage: function getCanPreviousPage() {
3590
+ return instance.getState().pagination.pageIndex > 0;
3591
+ },
3592
+ getCanNextPage: function getCanNextPage() {
3593
+ var _instance$getState$pa = instance.getState().pagination,
3594
+ pageIndex = _instance$getState$pa.pageIndex,
3595
+ pageCount = _instance$getState$pa.pageCount,
3596
+ pageSize = _instance$getState$pa.pageSize;
3597
+
3598
+ if (pageCount === -1) {
3599
+ return true;
3600
+ }
3601
+
3602
+ if (pageCount === 0) {
3603
+ return false;
3604
+ }
3605
+
3606
+ return pageIndex < Math.ceil(instance.getPrePaginationRows().length / pageSize) - 1;
3607
+ },
3608
+ previousPage: function previousPage() {
3609
+ return instance.setPageIndex(function (old) {
3610
+ return old - 1;
3611
+ });
3612
+ },
3613
+ nextPage: function nextPage() {
3614
+ return instance.setPageIndex(function (old) {
3615
+ return old + 1;
3616
+ });
3617
+ },
3618
+ getPaginationRowModel: memo(function () {
3619
+ return [instance.getState().pagination, instance.getExpandedRowModel(), instance.options.paginateRowsFn];
3620
+ }, function (_pagination, rowModel, paginateRowsFn) {
3621
+ if (!paginateRowsFn || !rowModel.rows.length) {
3622
+ return rowModel;
3623
+ }
3624
+
3625
+ if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Paginating...');
3626
+ return paginateRowsFn(instance, rowModel);
3627
+ }, {
3628
+ key: 'getPaginationRowModel',
3629
+ debug: instance.options.debug
3630
+ }),
3631
+ getPrePaginationRows: function getPrePaginationRows() {
3632
+ return instance.getExpandedRowModel().rows;
3633
+ },
3634
+ getPrePaginationFlatRows: function getPrePaginationFlatRows() {
3635
+ return instance.getExpandedRowModel().flatRows;
3636
+ },
3637
+ getPrePaginationRowsById: function getPrePaginationRowsById() {
3638
+ return instance.getExpandedRowModel().rowsById;
3639
+ },
3640
+ getPaginationRows: function getPaginationRows() {
3641
+ return instance.getPaginationRowModel().rows;
3642
+ },
3643
+ getPaginationFlatRows: function getPaginationFlatRows() {
3644
+ return instance.getPaginationRowModel().flatRows;
3645
+ },
3646
+ getPaginationRowsById: function getPaginationRowsById() {
3647
+ return instance.getPaginationRowModel().rowsById;
3648
+ }
3649
+ };
3650
+ }
3651
+
3652
+ var Pagination = /*#__PURE__*/Object.freeze({
3653
+ __proto__: null,
3654
+ getInitialState: getInitialState$1,
3655
+ getDefaultOptions: getDefaultOptions$1,
3656
+ getInstance: getInstance$1
3657
+ });
3658
+
3659
+ //
3660
+ function getInitialState() {
3661
+ return {
3662
+ rowSelection: {}
3663
+ };
3664
+ }
3665
+ function getDefaultOptions(instance) {
3666
+ return {
3667
+ onRowSelectionChange: makeStateUpdater('rowSelection', instance),
3668
+ autoResetRowSelection: true,
3669
+ enableRowSelection: true,
3670
+ enableMultiRowSelection: true,
3671
+ enableSubRowSelection: true // enableGroupingRowSelection: false,
3672
+ // isAdditiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.metaKey,
3673
+ // isInclusiveSelectEvent: (e: MouseEvent | TouchEvent) => !!e.shiftKey,
3674
+
3675
+ };
3676
+ }
3677
+ function getInstance(instance) {
3678
+ var registered = false; // const pageRows = instance.getPageRows()
3679
+
3680
+ return {
3681
+ _notifyRowSelectionReset: function _notifyRowSelectionReset() {
3682
+ if (!registered) {
3683
+ registered = true;
3684
+ return;
3685
+ }
3686
+
3687
+ if (instance.options.autoResetAll === false) {
3688
+ return;
3689
+ }
3690
+
3691
+ if (instance.options.autoResetAll === true || instance.options.autoResetRowSelection) {
3692
+ instance.resetRowSelection();
3693
+ }
3694
+ },
3695
+ setRowSelection: function setRowSelection(updater) {
3696
+ return instance.options.onRowSelectionChange == null ? void 0 : instance.options.onRowSelectionChange(updater, functionalUpdate(updater, instance.getState().rowSelection));
3697
+ },
3698
+ resetRowSelection: function resetRowSelection() {
3699
+ var _getInitialState$rowS;
3700
+
3701
+ return instance.setRowSelection((_getInitialState$rowS = getInitialState().rowSelection) != null ? _getInitialState$rowS : {});
3702
+ },
3703
+ toggleAllRowsSelected: function toggleAllRowsSelected(value) {
3704
+ instance.setRowSelection(function (old) {
3705
+ value = typeof value !== 'undefined' ? value : !instance.getIsAllRowsSelected(); // Only remove/add the rows that are visible on the screen
3706
+ // Leave all the other rows that are selected alone.
3707
+
3708
+ var rowSelection = Object.assign({}, old);
3709
+ var preGroupedFlatRows = instance.getPreGroupedFlatRows(); // We don't use `mutateRowIsSelected` here for performance reasons.
3710
+ // All of the rows are flat already, so it wouldn't be worth it
3711
+
3712
+ if (value) {
3713
+ preGroupedFlatRows.forEach(function (row) {
3714
+ rowSelection[row.id] = true;
3715
+ });
3716
+ } else {
3717
+ preGroupedFlatRows.forEach(function (row) {
3718
+ delete rowSelection[row.id];
3719
+ });
3720
+ }
3721
+
3722
+ return rowSelection;
3723
+ });
3724
+ },
3725
+ toggleAllPageRowsSelected: function toggleAllPageRowsSelected(value) {
3726
+ return instance.setRowSelection(function (old) {
3727
+ typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
3728
+
3729
+ var rowSelection = _extends({}, old);
3730
+
3731
+ instance.getRows().forEach(function (row) {
3732
+ mutateRowIsSelected(rowSelection, row.id, value, instance);
3733
+ });
3734
+ return rowSelection;
3735
+ });
3736
+ },
3737
+ toggleRowSelected: function toggleRowSelected(rowId, value) {
3738
+ var row = instance.getRow(rowId);
3739
+ var isSelected = row.getIsSelected();
3740
+ instance.setRowSelection(function (old) {
3741
+ value = typeof value !== 'undefined' ? value : !isSelected;
3742
+
3743
+ if (isSelected === value) {
3744
+ return old;
3745
+ }
3746
+
3747
+ var selectedRowIds = _extends({}, old);
3748
+
3749
+ mutateRowIsSelected(selectedRowIds, rowId, value, instance);
3750
+ return selectedRowIds;
3751
+ });
3752
+ },
3753
+ // addRowSelectionRange: rowId => {
3754
+ // const {
3755
+ // rows,
3756
+ // rowsById,
3757
+ // options: { selectGroupingRows, selectSubRows },
3758
+ // } = instance
3759
+ // const findSelectedRow = (rows: Row[]) => {
3760
+ // let found
3761
+ // rows.find(d => {
3762
+ // if (d.getIsSelected()) {
3763
+ // found = d
3764
+ // return true
3765
+ // }
3766
+ // const subFound = findSelectedRow(d.subRows || [])
3767
+ // if (subFound) {
3768
+ // found = subFound
3769
+ // return true
3770
+ // }
3771
+ // return false
3772
+ // })
3773
+ // return found
3774
+ // }
3775
+ // const firstRow = findSelectedRow(rows) || rows[0]
3776
+ // const lastRow = rowsById[rowId]
3777
+ // let include = false
3778
+ // const selectedRowIds = {}
3779
+ // const addRow = (row: Row) => {
3780
+ // mutateRowIsSelected(selectedRowIds, row.id, true, {
3781
+ // rowsById,
3782
+ // selectGroupingRows: selectGroupingRows!,
3783
+ // selectSubRows: selectSubRows!,
3784
+ // })
3785
+ // }
3786
+ // instance.rows.forEach(row => {
3787
+ // const isFirstRow = row.id === firstRow.id
3788
+ // const isLastRow = row.id === lastRow.id
3789
+ // if (isFirstRow || isLastRow) {
3790
+ // if (!include) {
3791
+ // include = true
3792
+ // } else if (include) {
3793
+ // addRow(row)
3794
+ // include = false
3795
+ // }
3796
+ // }
3797
+ // if (include) {
3798
+ // addRow(row)
3799
+ // }
3800
+ // })
3801
+ // instance.setRowSelection(selectedRowIds)
3802
+ // },
3803
+ getSelectedRowModel: memo(function () {
3804
+ return [instance.getState().rowSelection, instance.getCoreRowModel()];
3805
+ }, function (rowSelection, rowModel) {
3806
+ if (!Object.keys(rowSelection).length) {
3807
+ return {
3808
+ rows: [],
3809
+ flatRows: [],
3810
+ rowsById: {}
3811
+ };
3812
+ }
3813
+
3814
+ if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Selecting...');
3815
+ return selectRowsFn(instance, rowModel);
3816
+ }, {
3817
+ key: 'getSelectedRowModel',
3818
+ debug: instance.options.debug,
3819
+ onChange: function onChange() {
3820
+ return instance._notifyExpandedReset();
3821
+ }
3822
+ }),
3823
+ getSelectedRows: function getSelectedRows() {
3824
+ return instance.getSelectedRowModel().rows;
3825
+ },
3826
+ getSelectedFlatRows: function getSelectedFlatRows() {
3827
+ return instance.getSelectedRowModel().flatRows;
3828
+ },
3829
+ getSelectedRowsById: function getSelectedRowsById() {
3830
+ return instance.getSelectedRowModel().rowsById;
3831
+ },
3832
+ getFilteredSelectedRowModel: memo(function () {
3833
+ return [instance.getState().rowSelection, instance.getGlobalFilteredRowModel()];
3834
+ }, function (rowSelection, rowModel) {
3835
+ if (!Object.keys(rowSelection).length) {
3836
+ return {
3837
+ rows: [],
3838
+ flatRows: [],
3839
+ rowsById: {}
3840
+ };
3841
+ }
3842
+
3843
+ if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Selecting...');
3844
+ return selectRowsFn(instance, rowModel);
3845
+ }, {
3846
+ key: 'getFilteredSelectedRowModel',
3847
+ debug: instance.options.debug,
3848
+ onChange: function onChange() {
3849
+ return instance._notifyExpandedReset();
3850
+ }
3851
+ }),
3852
+ getFilteredSelectedRows: function getFilteredSelectedRows() {
3853
+ return instance.getFilteredSelectedRowModel().rows;
3854
+ },
3855
+ getFilteredSelectedFlatRows: function getFilteredSelectedFlatRows() {
3856
+ return instance.getFilteredSelectedRowModel().flatRows;
3857
+ },
3858
+ getFilteredSelectedRowsById: function getFilteredSelectedRowsById() {
3859
+ return instance.getFilteredSelectedRowModel().rowsById;
3860
+ },
3861
+ getGroupedSelectedRowModel: memo(function () {
3862
+ return [instance.getState().rowSelection, instance.getGroupedRowModel()];
3863
+ }, function (rowSelection, rowModel) {
3864
+ if (!Object.keys(rowSelection).length) {
3865
+ return {
3866
+ rows: [],
3867
+ flatRows: [],
3868
+ rowsById: {}
3869
+ };
3870
+ }
3871
+
3872
+ if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Selecting...');
3873
+ return selectRowsFn(instance, rowModel);
3874
+ }, {
3875
+ key: 'getGroupedSelectedRowModel',
3876
+ debug: instance.options.debug,
3877
+ onChange: function onChange() {
3878
+ return instance._notifyExpandedReset();
3879
+ }
3880
+ }),
3881
+ getGroupedSelectedRows: function getGroupedSelectedRows() {
3882
+ return instance.getGroupedSelectedRowModel().rows;
3883
+ },
3884
+ getGroupedSelectedFlatRows: function getGroupedSelectedFlatRows() {
3885
+ return instance.getGroupedSelectedRowModel().flatRows;
3886
+ },
3887
+ getGroupedSelectedRowsById: function getGroupedSelectedRowsById() {
3888
+ return instance.getGroupedSelectedRowModel().rowsById;
3889
+ },
3890
+ ///
3891
+ getRowIsSelected: function getRowIsSelected(rowId) {
3892
+ var _instance$getState = instance.getState(),
3893
+ rowSelection = _instance$getState.rowSelection;
3894
+
3895
+ var row = instance.getRow(rowId);
3896
+
3897
+ if (!row) {
3898
+ throw new Error();
3899
+ }
3900
+
3901
+ return isRowSelected(row, rowSelection) === true;
3902
+ },
3903
+ getRowIsSomeSelected: function getRowIsSomeSelected(rowId) {
3904
+ var _instance$getState2 = instance.getState(),
3905
+ rowSelection = _instance$getState2.rowSelection;
3906
+
3907
+ var row = instance.getRow(rowId);
3908
+
3909
+ if (!row) {
3910
+ throw new Error();
3911
+ }
3912
+
3913
+ return isRowSelected(row, rowSelection) === 'some';
3914
+ },
3915
+ getRowCanSelect: function getRowCanSelect(rowId) {
3916
+ var _instance$options$ena;
3917
+
3918
+ var row = instance.getRow(rowId);
3919
+
3920
+ if (!row) {
3921
+ throw new Error();
3922
+ }
3923
+
3924
+ if (typeof instance.options.enableRowSelection === 'function') {
3925
+ return instance.options.enableRowSelection(row);
3926
+ }
3927
+
3928
+ return (_instance$options$ena = instance.options.enableRowSelection) != null ? _instance$options$ena : true;
3929
+ },
3930
+ getRowCanSelectSubRows: function getRowCanSelectSubRows(rowId) {
3931
+ var _instance$options$ena2;
3932
+
3933
+ var row = instance.getRow(rowId);
3934
+
3935
+ if (!row) {
3936
+ throw new Error();
3937
+ }
3938
+
3939
+ if (typeof instance.options.enableSubRowSelection === 'function') {
3940
+ return instance.options.enableSubRowSelection(row);
3941
+ }
3942
+
3943
+ return (_instance$options$ena2 = instance.options.enableSubRowSelection) != null ? _instance$options$ena2 : true;
3944
+ },
3945
+ getRowCanMultiSelect: function getRowCanMultiSelect(rowId) {
3946
+ var _instance$options$ena3;
3947
+
3948
+ var row = instance.getRow(rowId);
3949
+
3950
+ if (!row) {
3951
+ throw new Error();
3952
+ }
3953
+
3954
+ if (typeof instance.options.enableMultiRowSelection === 'function') {
3955
+ return instance.options.enableMultiRowSelection(row);
3956
+ }
3957
+
3958
+ return (_instance$options$ena3 = instance.options.enableMultiRowSelection) != null ? _instance$options$ena3 : true;
3959
+ },
3960
+ // getGroupingRowCanSelect: rowId => {
3961
+ // const row = instance.getRow(rowId)
3962
+ // if (!row) {
3963
+ // throw new Error()
3964
+ // }
3965
+ // if (typeof instance.options.enableGroupingRowSelection === 'function') {
3966
+ // return instance.options.enableGroupingRowSelection(row)
3967
+ // }
3968
+ // return instance.options.enableGroupingRowSelection ?? false
3969
+ // },
3970
+ getIsAllRowsSelected: function getIsAllRowsSelected() {
3971
+ var preFilteredFlatRows = instance.getPreGlobalFilteredFlatRows();
3972
+
3973
+ var _instance$getState3 = instance.getState(),
3974
+ rowSelection = _instance$getState3.rowSelection;
3975
+
3976
+ var isAllRowsSelected = Boolean(preFilteredFlatRows.length && Object.keys(rowSelection).length);
3977
+
3978
+ if (isAllRowsSelected) {
3979
+ if (preFilteredFlatRows.some(function (row) {
3980
+ return !rowSelection[row.id];
3981
+ })) {
3982
+ isAllRowsSelected = false;
3983
+ }
3984
+ }
3985
+
3986
+ return isAllRowsSelected;
3987
+ },
3988
+ getIsAllPageRowsSelected: function getIsAllPageRowsSelected() {
3989
+ var paginationFlatRows = instance.getPaginationFlatRows();
3990
+
3991
+ var _instance$getState4 = instance.getState(),
3992
+ rowSelection = _instance$getState4.rowSelection;
3993
+
3994
+ var isAllPageRowsSelected = !!paginationFlatRows.length;
3995
+
3996
+ if (isAllPageRowsSelected && paginationFlatRows.some(function (row) {
3997
+ return !rowSelection[row.id];
3998
+ })) {
3999
+ isAllPageRowsSelected = false;
4000
+ }
4001
+
4002
+ return isAllPageRowsSelected;
4003
+ },
4004
+ getIsSomeRowsSelected: function getIsSomeRowsSelected() {
4005
+ var _instance$getState$ro;
4006
+
4007
+ return !instance.getIsAllRowsSelected() && !!Object.keys((_instance$getState$ro = instance.getState().rowSelection) != null ? _instance$getState$ro : {}).length;
4008
+ },
4009
+ getIsSomePageRowsSelected: function getIsSomePageRowsSelected() {
4010
+ var paginationFlatRows = instance.getPaginationFlatRows();
4011
+ return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
4012
+ },
4013
+ getToggleRowSelectedProps: function getToggleRowSelectedProps(rowId, userProps) {
4014
+ var row = instance.getRow(rowId);
4015
+ var isSelected = row.getIsSelected();
4016
+ var isSomeSelected = row.getIsSomeSelected();
4017
+ var canSelect = row.getCanSelect();
4018
+ var initialProps = {
4019
+ onChange: canSelect ? function (e) {
4020
+ row.toggleSelected(e.target.checked);
4021
+ } : undefined,
4022
+ checked: isSelected,
4023
+ title: 'Toggle Row Selected',
4024
+ indeterminate: isSomeSelected // onChange: forInput
4025
+ // ? (e: Event) => e.stopPropagation()
4026
+ // : (e: Event) => {
4027
+ // if (instance.options.isAdditiveSelectEvent(e)) {
4028
+ // row.toggleSelected()
4029
+ // } else if (instance.options.isInclusiveSelectEvent(e)) {
4030
+ // instance.addRowSelectionRange(row.id)
4031
+ // } else {
4032
+ // instance.setRowSelection({})
4033
+ // row.toggleSelected()
4034
+ // }
4035
+ // if (props.onClick) props.onClick(e)
4036
+ // },
4037
+
4038
+ };
4039
+ return propGetter(initialProps, userProps);
4040
+ },
4041
+ getToggleAllRowsSelectedProps: function getToggleAllRowsSelectedProps(userProps) {
4042
+ var isSomeRowsSelected = instance.getIsSomeRowsSelected();
4043
+ var isAllRowsSelected = instance.getIsAllRowsSelected();
4044
+ var initialProps = {
4045
+ onChange: function onChange(e) {
4046
+ instance.toggleAllRowsSelected(e.target.checked);
4047
+ },
4048
+ checked: isAllRowsSelected,
4049
+ title: 'Toggle All Rows Selected',
4050
+ indeterminate: isSomeRowsSelected
4051
+ };
4052
+ return propGetter(initialProps, userProps);
4053
+ },
4054
+ getToggleAllPageRowsSelectedProps: function getToggleAllPageRowsSelectedProps(userProps) {
4055
+ var isSomePageRowsSelected = instance.getIsSomePageRowsSelected();
4056
+ var isAllPageRowsSelected = instance.getIsAllPageRowsSelected();
4057
+ var initialProps = {
4058
+ onChange: function onChange(e) {
4059
+ instance.toggleAllPageRowsSelected(e.target.checked);
4060
+ },
4061
+ checked: isAllPageRowsSelected,
4062
+ title: 'Toggle All Current Page Rows Selected',
4063
+ indeterminate: isSomePageRowsSelected
4064
+ };
4065
+ return propGetter(initialProps, userProps);
4066
+ }
4067
+ };
4068
+ }
4069
+ function createRow(row, instance) {
4070
+ return {
4071
+ getIsSelected: function getIsSelected() {
4072
+ return instance.getRowIsSelected(row.id);
4073
+ },
4074
+ getIsSomeSelected: function getIsSomeSelected() {
4075
+ return instance.getRowIsSomeSelected(row.id);
4076
+ },
4077
+ toggleSelected: function toggleSelected(value) {
4078
+ return instance.toggleRowSelected(row.id, value);
4079
+ },
4080
+ getToggleSelectedProps: function getToggleSelectedProps(userProps) {
4081
+ return instance.getToggleRowSelectedProps(row.id, userProps);
4082
+ },
4083
+ getCanMultiSelect: function getCanMultiSelect() {
4084
+ return instance.getRowCanMultiSelect(row.id);
4085
+ },
4086
+ getCanSelect: function getCanSelect() {
4087
+ return instance.getRowCanSelect(row.id);
4088
+ }
4089
+ };
4090
+ }
4091
+
4092
+ var mutateRowIsSelected = function mutateRowIsSelected(selectedRowIds, id, value, instance) {
4093
+ var _row$subRows;
4094
+
4095
+ var row = instance.getRow(id);
4096
+ row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
4097
+ // !isGrouped ||
4098
+ // (isGrouped && instance.options.enableGroupingRowSelection)
4099
+ // ) {
4100
+
4101
+ if (value) {
4102
+ selectedRowIds[id] = true;
4103
+ } else {
4104
+ delete selectedRowIds[id];
4105
+ } // }
4106
+
4107
+
4108
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && instance.getRowCanSelectSubRows(row.id)) {
4109
+ row.subRows.forEach(function (row) {
4110
+ return mutateRowIsSelected(selectedRowIds, row.id, value, instance);
4111
+ });
4112
+ }
4113
+ };
4114
+
4115
+ function selectRowsFn(instance, rowModel) {
4116
+ var rowSelection = instance.getState().rowSelection;
4117
+ var newSelectedFlatRows = [];
4118
+ var newSelectedRowsById = {}; // Filters top level and nested rows
4119
+
4120
+ var recurseRows = function recurseRows(rows, depth) {
4121
+
4122
+ return rows.map(function (row) {
4123
+ var _row$subRows2;
4124
+
4125
+ var isSelected = isRowSelected(row, rowSelection) === true;
4126
+
4127
+ if (isSelected) {
4128
+ newSelectedFlatRows.push(row);
4129
+ newSelectedRowsById[row.id] = row;
4130
+ }
4131
+
4132
+ if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
4133
+ row = _extends({}, row, {
4134
+ subRows: recurseRows(row.subRows)
4135
+ });
4136
+ }
4137
+
4138
+ if (isSelected) {
4139
+ return row;
4140
+ }
4141
+ }).filter(Boolean);
4142
+ };
4143
+
4144
+ return {
4145
+ rows: recurseRows(rowModel.rows),
4146
+ flatRows: newSelectedFlatRows,
4147
+ rowsById: newSelectedRowsById
4148
+ };
4149
+ }
4150
+ function isRowSelected(row, selection, instance) {
4151
+ if (selection[row.id]) {
4152
+ return true;
4153
+ }
4154
+
4155
+ if (row.subRows && row.subRows.length) {
4156
+ var allChildrenSelected = true;
4157
+ var someSelected = false;
4158
+ row.subRows.forEach(function (subRow) {
4159
+ // Bail out early if we know both of these
4160
+ if (someSelected && !allChildrenSelected) {
4161
+ return;
4162
+ }
4163
+
4164
+ if (isRowSelected(subRow, selection)) {
4165
+ someSelected = true;
4166
+ } else {
4167
+ allChildrenSelected = false;
4168
+ }
4169
+ });
4170
+ return allChildrenSelected ? true : someSelected ? 'some' : false;
4171
+ }
4172
+
4173
+ return false;
4174
+ }
4175
+
4176
+ var RowSelection = /*#__PURE__*/Object.freeze({
4177
+ __proto__: null,
4178
+ getInitialState: getInitialState,
4179
+ getDefaultOptions: getDefaultOptions,
4180
+ getInstance: getInstance,
4181
+ createRow: createRow,
4182
+ selectRowsFn: selectRowsFn,
4183
+ isRowSelected: isRowSelected
4184
+ });
4185
+
4186
+ var features = [Visibility, Ordering, Pinning, Headers, Filters, Sorting, Grouping, Expanding, ColumnSizing, Pagination, RowSelection];
4187
+ function createTableInstance(options, rerender) {
4188
+ var _options$initialState;
4189
+
4190
+ if (process.env.NODE_ENV !== 'production' && options.debug) {
4191
+ console.info('Creating React Table Instance...');
4192
+ }
4193
+
4194
+ var instance = {};
4195
+ var defaultOptions = features.reduce(function (obj, feature) {
4196
+ return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(instance));
4197
+ }, {});
4198
+ var defaultState = {};
4199
+
4200
+ var buildOptions = function buildOptions(options) {
4201
+ return _extends({
4202
+ state: defaultState
4203
+ }, defaultOptions, options);
4204
+ };
4205
+
4206
+ instance.options = buildOptions(options);
4207
+
4208
+ var initialState = _extends({}, features.reduce(function (obj, feature) {
4209
+ return Object.assign(obj, feature.getInitialState == null ? void 0 : feature.getInitialState());
4210
+ }, {}), (_options$initialState = options.initialState) != null ? _options$initialState : {});
4211
+
4212
+ var finalInstance = _extends({}, instance, features.reduce(function (obj, feature) {
4213
+ return Object.assign(obj, feature.getInstance == null ? void 0 : feature.getInstance(instance));
4214
+ }, {}), {
4215
+ rerender: rerender,
4216
+ initialState: initialState,
4217
+ internalState: initialState,
4218
+ reset: function reset() {
4219
+ instance.setState(instance.initialState);
4220
+ },
4221
+ updateOptions: function updateOptions(newOptions) {
4222
+ instance.options = buildOptions(newOptions);
4223
+ },
4224
+ getRowId: function getRowId(_, index, parent) {
4225
+ return "" + (parent ? [parent.id, index].join('.') : index);
4226
+ },
4227
+ getState: function getState() {
4228
+ var state = _extends({}, instance.internalState, instance.options.state);
4229
+
4230
+ return state;
4231
+ },
4232
+ setState: function setState(updater, shouldRerender) {
4233
+ if (shouldRerender === void 0) {
4234
+ shouldRerender = true;
4235
+ }
4236
+
4237
+ var onStateChange = instance.options.onStateChange;
4238
+ var internalState = instance.internalState;
4239
+ var newState = functionalUpdate(updater, internalState);
4240
+ instance.internalState = newState;
4241
+
4242
+ if (onStateChange) {
4243
+ onStateChange(newState);
4244
+ return;
4245
+ }
4246
+
4247
+ if (shouldRerender) {
4248
+ instance.rerender();
4249
+ }
4250
+ },
4251
+ getDefaultColumn: memo(function () {
4252
+ return [instance.options.defaultColumn];
4253
+ }, function (defaultColumn) {
4254
+ var _defaultColumn;
4255
+
4256
+ defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
4257
+ return _extends({
4258
+ header: function header(props) {
4259
+ return props.header.column.id;
4260
+ },
4261
+ footer: function footer(props) {
4262
+ return props.header.column.id;
4263
+ },
4264
+ cell: function cell(_ref) {
4265
+ var _ref$value = _ref.value,
2931
4266
  value = _ref$value === void 0 ? '' : _ref$value;
2932
4267
  return typeof value === 'boolean' ? value.toString() : value;
2933
4268
  }
2934
- }, getDefaultColumn$3(), getDefaultColumn$1(), getDefaultColumn(), getDefaultColumn$2(), defaultColumn);
2935
- }, 'getDefaultColumn', instance.options.debug),
4269
+ }, features.reduce(function (obj, feature) {
4270
+ return Object.assign(obj, feature.getDefaultColumn == null ? void 0 : feature.getDefaultColumn());
4271
+ }, {}), defaultColumn);
4272
+ }, {
4273
+ debug: instance.options.debug,
4274
+ key: 'getDefaultColumn'
4275
+ }),
2936
4276
  getColumnDefs: function getColumnDefs() {
2937
4277
  return instance.options.columns;
2938
4278
  },
2939
- createColumn: function createColumn$5(columnDef, depth, parent) {
4279
+ createColumn: function createColumn(columnDef, depth, parent) {
2940
4280
  var _ref2, _columnDef$id;
2941
4281
 
2942
4282
  var defaultColumn = instance.getDefaultColumn();
@@ -2959,11 +4299,7 @@ function createTableInstance(options, rerender) {
2959
4299
  throw new Error();
2960
4300
  }
2961
4301
 
2962
- var column = _extends({
2963
- width: 150,
2964
- minWidth: 20,
2965
- maxWidth: Number.MAX_SAFE_INTEGER
2966
- }, defaultColumn, columnDef, {
4302
+ var column = _extends({}, defaultColumnSizing, defaultColumn, columnDef, {
2967
4303
  id: "" + id,
2968
4304
  accessorFn: accessorFn,
2969
4305
  parent: parent,
@@ -2981,7 +4317,10 @@ function createTableInstance(options, rerender) {
2981
4317
  return [column].concat((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(function (d) {
2982
4318
  return d.getFlatColumns();
2983
4319
  }));
2984
- }, 'column.getFlatColumns', instance.options.debug),
4320
+ }, {
4321
+ key: 'column.getFlatColumns',
4322
+ debug: instance.options.debug
4323
+ }),
2985
4324
  getLeafColumns: memo(function () {
2986
4325
  return [instance.getOrderColumnsFn()];
2987
4326
  }, function (orderColumns) {
@@ -2995,10 +4334,15 @@ function createTableInstance(options, rerender) {
2995
4334
  }
2996
4335
 
2997
4336
  return [column];
2998
- }, 'column.getLeafColumns', instance.options.debug)
4337
+ }, {
4338
+ key: 'column.getLeafColumns',
4339
+ debug: instance.options.debug
4340
+ })
2999
4341
  });
3000
4342
 
3001
- column = Object.assign(column, createColumn$4(column, instance), createColumn$2(column, instance), createColumn$1(column, instance), createColumn(column, instance), createColumn$3(column, instance)); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
4343
+ column = features.reduce(function (obj, feature) {
4344
+ return Object.assign(obj, feature.createColumn == null ? void 0 : feature.createColumn(column, instance));
4345
+ }, column); // Yes, we have to convert instance to uknown, because we know more than the compiler here.
3002
4346
 
3003
4347
  return column;
3004
4348
  },
@@ -3020,14 +4364,20 @@ function createTableInstance(options, rerender) {
3020
4364
  };
3021
4365
 
3022
4366
  return recurseColumns(columnDefs);
3023
- }, 'getAllColumns', instance.options.debug),
4367
+ }, {
4368
+ key: 'getAllColumns',
4369
+ debug: instance.options.debug
4370
+ }),
3024
4371
  getAllFlatColumns: memo(function () {
3025
4372
  return [instance.getAllColumns()];
3026
4373
  }, function (allColumns) {
3027
4374
  return allColumns.flatMap(function (column) {
3028
4375
  return column.getFlatColumns();
3029
4376
  });
3030
- }, 'getAllFlatColumns', instance.options.debug),
4377
+ }, {
4378
+ key: 'getAllFlatColumns',
4379
+ debug: instance.options.debug
4380
+ }),
3031
4381
  getAllFlatColumnsById: memo(function () {
3032
4382
  return [instance.getAllFlatColumns()];
3033
4383
  }, function (flatColumns) {
@@ -3035,7 +4385,10 @@ function createTableInstance(options, rerender) {
3035
4385
  acc[column.id] = column;
3036
4386
  return acc;
3037
4387
  }, {});
3038
- }, 'getAllFlatColumnsById', instance.options.debug),
4388
+ }, {
4389
+ key: 'getAllFlatColumnsById',
4390
+ debug: instance.options.debug
4391
+ }),
3039
4392
  getAllLeafColumns: memo(function () {
3040
4393
  return [instance.getAllColumns(), instance.getOrderColumnsFn()];
3041
4394
  }, function (allColumns, orderColumns) {
@@ -3043,7 +4396,10 @@ function createTableInstance(options, rerender) {
3043
4396
  return column.getLeafColumns();
3044
4397
  });
3045
4398
  return orderColumns(leafColumns);
3046
- }, 'getAllLeafColumns', instance.options.debug),
4399
+ }, {
4400
+ key: 'getAllLeafColumns',
4401
+ debug: instance.options.debug
4402
+ }),
3047
4403
  getColumn: function getColumn(columnId) {
3048
4404
  var column = instance.getAllFlatColumnsById()[columnId];
3049
4405
 
@@ -3058,7 +4414,7 @@ function createTableInstance(options, rerender) {
3058
4414
  return column;
3059
4415
  },
3060
4416
  getColumnWidth: function getColumnWidth(columnId) {
3061
- var _column$minWidth, _column$width, _column$maxWidth;
4417
+ var _column$minWidth, _ref3, _column$maxWidth;
3062
4418
 
3063
4419
  var column = instance.getColumn(columnId);
3064
4420
 
@@ -3066,9 +4422,10 @@ function createTableInstance(options, rerender) {
3066
4422
  throw new Error();
3067
4423
  }
3068
4424
 
3069
- return Math.min(Math.max((_column$minWidth = column.minWidth) != null ? _column$minWidth : 0, (_column$width = column.width) != null ? _column$width : 0), (_column$maxWidth = column.maxWidth) != null ? _column$maxWidth : 0);
4425
+ var columnSize = instance.getState().columnSizing[column.id];
4426
+ 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);
3070
4427
  },
3071
- createCell: function createCell$1(row, column, value) {
4428
+ createCell: function createCell(row, column, value) {
3072
4429
  var cell = {
3073
4430
  id: row.id + "_" + column.id,
3074
4431
  rowId: row.id,
@@ -3081,16 +4438,20 @@ function createTableInstance(options, rerender) {
3081
4438
  },
3082
4439
  renderCell: function renderCell() {
3083
4440
  return flexRender(column.cell, {
4441
+ instance: instance,
3084
4442
  column: column,
4443
+ row: row,
3085
4444
  cell: cell,
3086
4445
  value: value
3087
4446
  });
3088
4447
  }
3089
4448
  };
3090
- Object.assign(cell, _extends({}, createCell(cell, column, row)));
4449
+ features.forEach(function (feature) {
4450
+ Object.assign(cell, feature.createCell == null ? void 0 : feature.createCell(cell, column, row, instance));
4451
+ }, {});
3091
4452
  return cell;
3092
4453
  },
3093
- createRow: function createRow$3(id, original, rowIndex, depth, values) {
4454
+ createRow: function createRow(id, original, rowIndex, depth, values) {
3094
4455
  var row = {
3095
4456
  id: id,
3096
4457
  index: rowIndex,
@@ -3111,7 +4472,10 @@ function createTableInstance(options, rerender) {
3111
4472
  return leafColumns.map(function (column) {
3112
4473
  return instance.createCell(row, column, row.values[column.id]);
3113
4474
  });
3114
- }, process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '', instance.options.debug);
4475
+ }, {
4476
+ key: process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '',
4477
+ debug: instance.options.debug
4478
+ });
3115
4479
  row.getAllCellsByColumnId = memo(function () {
3116
4480
  return [row.getAllCells()];
3117
4481
  }, function (allCells) {
@@ -3119,42 +4483,19 @@ function createTableInstance(options, rerender) {
3119
4483
  acc[cell.columnId] = cell;
3120
4484
  return acc;
3121
4485
  }, {});
3122
- }, 'row.getAllCellsByColumnId', instance.options.debug);
3123
- row = Object.assign(row, createRow$1(row, instance), createRow$2(row, instance), createRow(row, instance));
4486
+ }, {
4487
+ key: 'row.getAllCellsByColumnId',
4488
+ debug: instance.options.debug
4489
+ });
4490
+ features.forEach(function (feature) {
4491
+ Object.assign(row, feature.createRow == null ? void 0 : feature.createRow(row, instance));
4492
+ });
3124
4493
  return row;
3125
4494
  },
3126
4495
  getCoreRowModel: memo(function () {
3127
4496
  return [instance.options.data];
3128
4497
  }, function (data) {
3129
- if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Accessing...'); // Auto-reset data-dependent states if configured
3130
-
3131
- if (instance.options.autoResetColumnFilters && // @ts-ignore
3132
- instance.getRowModelNonFirst) {
3133
- instance.resetColumnFilters();
3134
- }
3135
-
3136
- if (instance.options.autoResetGlobalFilter && // @ts-ignore
3137
- instance.getRowModelNonFirst) {
3138
- instance.resetGlobalFilter();
3139
- }
3140
-
3141
- if (instance.options.autoResetSorting && // @ts-ignore
3142
- instance.getRowModelNonFirst) {
3143
- instance.resetSorting();
3144
- }
3145
-
3146
- if (instance.options.autoResetGrouping && // @ts-ignore
3147
- instance.getRowModelNonFirst) {
3148
- instance.resetGrouping();
3149
- }
3150
-
3151
- if (instance.options.autoResetExpanded && // @ts-ignore
3152
- instance.getRowModelNonFirst) {
3153
- instance.resetExpanded();
3154
- } // @ts-ignore
3155
-
3156
-
3157
- instance.getRowModelNonFirst = true; // Access the row model using initial columns
4498
+ if (process.env.NODE_ENV !== 'production' && instance.options.debug) console.info('Accessing...'); // Access the row model using initial columns
3158
4499
 
3159
4500
  var rows = [];
3160
4501
  var flatRows = [];
@@ -3222,7 +4563,15 @@ function createTableInstance(options, rerender) {
3222
4563
  flatRows: flatRows,
3223
4564
  rowsById: rowsById
3224
4565
  };
3225
- }, 'getRowModel', instance.options.debug),
4566
+ }, {
4567
+ key: 'getRowModel',
4568
+ debug: instance.options.debug,
4569
+ onChange: function onChange() {
4570
+ instance._notifyRowSelectionReset();
4571
+
4572
+ instance._notifyFiltersReset();
4573
+ }
4574
+ }),
3226
4575
  // The standard
3227
4576
  getCoreRows: function getCoreRows() {
3228
4577
  return instance.getCoreRowModel().rows;
@@ -3236,7 +4585,7 @@ function createTableInstance(options, rerender) {
3236
4585
  // The final calls start at the bottom of the model,
3237
4586
  // expanded rows, which then work their way up
3238
4587
  getRowModel: function getRowModel() {
3239
- return instance.getExpandedRowModel();
4588
+ return instance.getPaginationRowModel();
3240
4589
  },
3241
4590
  getRows: function getRows() {
3242
4591
  return instance.getRowModel().rows;
@@ -3316,10 +4665,44 @@ function createTableInstance(options, rerender) {
3316
4665
  key: cell.id,
3317
4666
  role: 'gridcell'
3318
4667
  }, userProps);
4668
+ },
4669
+ getTableWidth: function getTableWidth() {
4670
+ var _instance$getHeaderGr, _instance$getHeaderGr2;
4671
+
4672
+ return (_instance$getHeaderGr = (_instance$getHeaderGr2 = instance.getHeaderGroups()[0]) == null ? void 0 : _instance$getHeaderGr2.headers.reduce(function (sum, header) {
4673
+ return sum + header.getWidth();
4674
+ }, 0)) != null ? _instance$getHeaderGr : 0;
4675
+ },
4676
+ getLeftTableWidth: function getLeftTableWidth() {
4677
+ var _instance$getLeftHead, _instance$getLeftHead2;
4678
+
4679
+ return (_instance$getLeftHead = (_instance$getLeftHead2 = instance.getLeftHeaderGroups()[0]) == null ? void 0 : _instance$getLeftHead2.headers.reduce(function (sum, header) {
4680
+ return sum + header.getWidth();
4681
+ }, 0)) != null ? _instance$getLeftHead : 0;
4682
+ },
4683
+ getCenterTableWidth: function getCenterTableWidth() {
4684
+ var _instance$getCenterHe, _instance$getCenterHe2;
4685
+
4686
+ return (_instance$getCenterHe = (_instance$getCenterHe2 = instance.getCenterHeaderGroups()[0]) == null ? void 0 : _instance$getCenterHe2.headers.reduce(function (sum, header) {
4687
+ return sum + header.getWidth();
4688
+ }, 0)) != null ? _instance$getCenterHe : 0;
4689
+ },
4690
+ getRightTableWidth: function getRightTableWidth() {
4691
+ var _instance$getRightHea, _instance$getRightHea2;
4692
+
4693
+ return (_instance$getRightHea = (_instance$getRightHea2 = instance.getRightHeaderGroups()[0]) == null ? void 0 : _instance$getRightHea2.headers.reduce(function (sum, header) {
4694
+ return sum + header.getWidth();
4695
+ }, 0)) != null ? _instance$getRightHea : 0;
3319
4696
  }
3320
4697
  });
3321
4698
 
3322
- return Object.assign(instance, finalInstance);
4699
+ instance = Object.assign(instance, finalInstance); // This won't trigger a rerender yet, but it will force
4700
+ // pagination derivation to run (particularly pageSize detection)
4701
+
4702
+ instance.setPagination(function (d) {
4703
+ return d;
4704
+ });
4705
+ return instance;
3323
4706
  }
3324
4707
 
3325
4708
  function createTable() {
@@ -3339,7 +4722,17 @@ function createTable() {
3339
4722
  createColumns: function createColumns(columns) {
3340
4723
  return columns;
3341
4724
  },
3342
- createColumn: function createColumn(accessor, column) {
4725
+ createDisplayColumn: function createDisplayColumn(column) {
4726
+ return _extends({}, column, {
4727
+ __generated: true
4728
+ });
4729
+ },
4730
+ createGroup: function createGroup(column) {
4731
+ return _extends({}, column, {
4732
+ __generated: true
4733
+ });
4734
+ },
4735
+ createDataColumn: function createDataColumn(accessor, column) {
3343
4736
  column = _extends({}, column, {
3344
4737
  id: column.id
3345
4738
  });
@@ -3363,11 +4756,6 @@ function createTable() {
3363
4756
 
3364
4757
  throw new Error('Invalid accessor');
3365
4758
  },
3366
- createGroup: function createGroup(column) {
3367
- return _extends({}, column, {
3368
- __generated: true
3369
- });
3370
- },
3371
4759
  useTable: function useTable(options) {
3372
4760
  var instanceRef = React.useRef(undefined);
3373
4761
  var rerender = React.useReducer(function () {
@@ -3385,5 +4773,5 @@ function createTable() {
3385
4773
  };
3386
4774
  }
3387
4775
 
3388
- export { columnFilterRowsFn, createTable, expandRowsFn, globalFilterRowsFn, groupRowsFn, sortRowsFn };
4776
+ export { columnFilterRowsFn, createTable, expandRowsFn, globalFilterRowsFn, groupRowsFn, paginateRowsFn, sortRowsFn };
3389
4777
  //# sourceMappingURL=index.js.map