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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2669,7 +2669,7 @@ var drawChart = (function (exports) {
2669
2669
  </script>
2670
2670
  <script>
2671
2671
  /*<!--*/
2672
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"table-core/build/esm/index.js","uid":"5790-127"},{"name":"react-table/src/index.tsx","uid":"5790-129"}]}]}],"isRoot":true},"nodeParts":{"5790-127":{"renderedLength":137430,"gzipLength":23365,"brotliLength":0,"mainUid":"5790-126"},"5790-129":{"renderedLength":2102,"gzipLength":836,"brotliLength":0,"mainUid":"5790-128"}},"nodeMetas":{"5790-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"5790-127"},"imported":[],"importedBy":[{"uid":"5790-128"}]},"5790-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"5790-129"},"imported":[{"uid":"5790-130"},{"uid":"5790-126"}],"importedBy":[],"isEntry":true},"5790-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"5790-128"}],"isExternal":true}},"env":{"rollup":"2.70.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
2672
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"table-core/build/esm/index.js","uid":"8d24-127"},{"name":"react-table/src/index.tsx","uid":"8d24-129"}]}]}],"isRoot":true},"nodeParts":{"8d24-127":{"renderedLength":138784,"gzipLength":23663,"brotliLength":0,"mainUid":"8d24-126"},"8d24-129":{"renderedLength":2135,"gzipLength":854,"brotliLength":0,"mainUid":"8d24-128"}},"nodeMetas":{"8d24-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"8d24-127"},"imported":[],"importedBy":[{"uid":"8d24-128"}]},"8d24-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"8d24-129"},"imported":[{"uid":"8d24-130"},{"uid":"8d24-126"}],"importedBy":[],"isEntry":true},"8d24-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"8d24-128"}],"isExternal":true}},"env":{"rollup":"2.70.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
2673
2673
 
2674
2674
  const run = () => {
2675
2675
  const width = window.innerWidth;
@@ -11,11 +11,11 @@
11
11
  "children": [
12
12
  {
13
13
  "name": "table-core/build/esm/index.js",
14
- "uid": "5790-132"
14
+ "uid": "8d24-132"
15
15
  },
16
16
  {
17
17
  "name": "react-table/src/index.tsx",
18
- "uid": "5790-134"
18
+ "uid": "8d24-134"
19
19
  }
20
20
  ]
21
21
  }
@@ -25,55 +25,55 @@
25
25
  "isRoot": true
26
26
  },
27
27
  "nodeParts": {
28
- "5790-132": {
29
- "renderedLength": 137430,
30
- "gzipLength": 23365,
28
+ "8d24-132": {
29
+ "renderedLength": 138784,
30
+ "gzipLength": 23663,
31
31
  "brotliLength": 0,
32
- "mainUid": "5790-131"
32
+ "mainUid": "8d24-131"
33
33
  },
34
- "5790-134": {
35
- "renderedLength": 2102,
36
- "gzipLength": 836,
34
+ "8d24-134": {
35
+ "renderedLength": 2135,
36
+ "gzipLength": 854,
37
37
  "brotliLength": 0,
38
- "mainUid": "5790-133"
38
+ "mainUid": "8d24-133"
39
39
  }
40
40
  },
41
41
  "nodeMetas": {
42
- "5790-131": {
42
+ "8d24-131": {
43
43
  "id": "/packages/table-core/build/esm/index.js",
44
44
  "moduleParts": {
45
- "index.production.js": "5790-132"
45
+ "index.production.js": "8d24-132"
46
46
  },
47
47
  "imported": [],
48
48
  "importedBy": [
49
49
  {
50
- "uid": "5790-133"
50
+ "uid": "8d24-133"
51
51
  }
52
52
  ]
53
53
  },
54
- "5790-133": {
54
+ "8d24-133": {
55
55
  "id": "/packages/react-table/src/index.tsx",
56
56
  "moduleParts": {
57
- "index.production.js": "5790-134"
57
+ "index.production.js": "8d24-134"
58
58
  },
59
59
  "imported": [
60
60
  {
61
- "uid": "5790-135"
61
+ "uid": "8d24-135"
62
62
  },
63
63
  {
64
- "uid": "5790-131"
64
+ "uid": "8d24-131"
65
65
  }
66
66
  ],
67
67
  "importedBy": [],
68
68
  "isEntry": true
69
69
  },
70
- "5790-135": {
70
+ "8d24-135": {
71
71
  "id": "react",
72
72
  "moduleParts": {},
73
73
  "imported": [],
74
74
  "importedBy": [
75
75
  {
76
- "uid": "5790-133"
76
+ "uid": "8d24-133"
77
77
  }
78
78
  ],
79
79
  "isExternal": true
@@ -1128,7 +1128,6 @@
1128
1128
  },
1129
1129
  createColumn: (column, instance) => {
1130
1130
  return {
1131
- filterFn: column.filterFn,
1132
1131
  getAutoFilterFn: () => {
1133
1132
  const firstRow = instance.getCoreRowModel().flatRows[0];
1134
1133
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
@@ -1159,7 +1158,7 @@
1159
1158
  var _ref;
1160
1159
 
1161
1160
  const userFilterFns = instance.options.filterFns;
1162
- return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
1161
+ return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.columnDef.filterFn]) != null ? _ref : filterFns[column.columnDef.filterFn];
1163
1162
  },
1164
1163
  getCanFilter: () => {
1165
1164
  var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
@@ -1448,6 +1447,11 @@
1448
1447
  const Grouping = {
1449
1448
  getDefaultColumnDef: () => {
1450
1449
  return {
1450
+ aggregatedCell: props => {
1451
+ var _props$getValue$toStr, _props$getValue;
1452
+
1453
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
1454
+ },
1451
1455
  aggregationFn: 'auto'
1452
1456
  };
1453
1457
  },
@@ -1508,8 +1512,6 @@
1508
1512
  if (Object.prototype.toString.call(value) === '[object Date]') {
1509
1513
  return aggregationFns.extent;
1510
1514
  }
1511
-
1512
- return aggregationFns.count;
1513
1515
  },
1514
1516
  getAggregationFn: () => {
1515
1517
  var _ref4;
@@ -1520,7 +1522,7 @@
1520
1522
  throw new Error();
1521
1523
  }
1522
1524
 
1523
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1525
+ return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.columnDef.aggregationFn]) != null ? _ref4 : aggregationFns[column.columnDef.aggregationFn];
1524
1526
  }
1525
1527
  };
1526
1528
  },
@@ -1553,6 +1555,12 @@
1553
1555
  };
1554
1556
  },
1555
1557
  createCell: (cell, column, row, instance) => {
1558
+ const getRenderValue = () => {
1559
+ var _cell$getValue;
1560
+
1561
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
1562
+ };
1563
+
1556
1564
  return {
1557
1565
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1558
1566
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1562,15 +1570,19 @@
1562
1570
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1563
1571
  },
1564
1572
  renderAggregatedCell: () => {
1565
- var _column$columnDef$agg;
1573
+ {
1574
+ if (!column.columnDef.aggregatedCell) {
1575
+ console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
1576
+ }
1577
+ }
1566
1578
 
1567
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1579
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1568
1580
  return template ? instance._render(template, {
1569
1581
  instance,
1570
1582
  column,
1571
1583
  row,
1572
1584
  cell,
1573
- getValue: cell.getValue
1585
+ getValue: getRenderValue
1574
1586
  }) : null;
1575
1587
  }
1576
1588
  };
@@ -2040,11 +2052,11 @@
2040
2052
  });
2041
2053
  },
2042
2054
  toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
2043
- typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
2055
+ const resolvedValue = typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
2044
2056
  const rowSelection = { ...old
2045
2057
  };
2046
2058
  instance.getRowModel().rows.forEach(row => {
2047
- mutateRowIsSelected(rowSelection, row.id, value, instance);
2059
+ mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance);
2048
2060
  });
2049
2061
  return rowSelection;
2050
2062
  }),
@@ -2199,7 +2211,7 @@
2199
2211
  },
2200
2212
  getIsSomePageRowsSelected: () => {
2201
2213
  const paginationFlatRows = instance.getPaginationRowModel().flatRows;
2202
- return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
2214
+ return instance.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
2203
2215
  },
2204
2216
  getToggleAllRowsSelectedHandler: () => {
2205
2217
  return e => {
@@ -2553,8 +2565,10 @@
2553
2565
  // })
2554
2566
  // return
2555
2567
  // }
2568
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2569
+ const nextSortingOrder = column.getNextSortingOrder();
2556
2570
  instance.setSorting(old => {
2557
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2571
+ var _instance$options$ena, _instance$options$ena2;
2558
2572
 
2559
2573
  // Find any existing sorting for this column
2560
2574
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2579,30 +2593,29 @@
2579
2593
  } else {
2580
2594
  sortAction = 'replace';
2581
2595
  }
2582
- }
2596
+ } // Handle toggle states that will remove the sorting
2583
2597
 
2584
- const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
2585
2598
 
2586
2599
  if (sortAction === 'toggle' && ( // Must be toggling
2587
2600
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2588
2601
  !hasDescDefined && ( // Must not be setting desc
2589
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2590
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2591
- ? !sortDescFirst : sortDescFirst)) {
2602
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2603
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2604
+ ) {
2592
2605
  sortAction = 'remove';
2593
2606
  }
2594
2607
 
2595
2608
  if (sortAction === 'replace') {
2596
2609
  newSorting = [{
2597
2610
  id: column.id,
2598
- desc: hasDescDefined ? desc : !!sortDescFirst
2611
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2599
2612
  }];
2600
2613
  } else if (sortAction === 'add' && old != null && old.length) {
2601
2614
  var _instance$options$max;
2602
2615
 
2603
2616
  newSorting = [...old, {
2604
2617
  id: column.id,
2605
- desc: hasDescDefined ? desc : !!sortDescFirst
2618
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2606
2619
  }]; // Take latest n columns
2607
2620
 
2608
2621
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2611,7 +2624,7 @@
2611
2624
  newSorting = old.map(d => {
2612
2625
  if (d.id === column.id) {
2613
2626
  return { ...d,
2614
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2627
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2615
2628
  };
2616
2629
  }
2617
2630
 
@@ -2624,6 +2637,23 @@
2624
2637
  return newSorting;
2625
2638
  });
2626
2639
  },
2640
+ getNextSortingOrder: () => {
2641
+ var _ref2, _column$columnDef$sor;
2642
+
2643
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2644
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2645
+ const isSorted = column.getIsSorted();
2646
+
2647
+ if (!isSorted) {
2648
+ return firstSortDirection;
2649
+ }
2650
+
2651
+ if (isSorted === firstSortDirection) {
2652
+ return isSorted === 'desc' ? 'asc' : 'desc';
2653
+ } else {
2654
+ return false;
2655
+ }
2656
+ },
2627
2657
  getCanSort: () => {
2628
2658
  var _column$columnDef$ena, _instance$options$ena3;
2629
2659
 
@@ -2915,9 +2945,9 @@
2915
2945
  header: props => props.header.column.id,
2916
2946
  footer: props => props.header.column.id,
2917
2947
  cell: props => {
2918
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2948
+ var _props$getValue$toStr, _props$getValue;
2919
2949
 
2920
- return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
2950
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
2921
2951
  },
2922
2952
  ...instance._features.reduce((obj, feature) => {
2923
2953
  return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
@@ -3071,6 +3101,12 @@
3071
3101
  }
3072
3102
 
3073
3103
  function createCell(instance, row, column, columnId) {
3104
+ const getRenderValue = () => {
3105
+ var _cell$getValue;
3106
+
3107
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
3108
+ };
3109
+
3074
3110
  const cell = {
3075
3111
  id: row.id + "_" + column.id,
3076
3112
  row,
@@ -3082,7 +3118,7 @@
3082
3118
  column,
3083
3119
  row,
3084
3120
  cell: cell,
3085
- getValue: cell.getValue
3121
+ getValue: getRenderValue
3086
3122
  }) : null;
3087
3123
  }
3088
3124
  };
@@ -3688,11 +3724,6 @@
3688
3724
  if (aggregateFn) {
3689
3725
  row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3690
3726
  return row._groupingValuesCache[columnId];
3691
- } else if (column.aggregationFn) {
3692
- console.info({
3693
- column
3694
- });
3695
- throw new Error("Table: Invalid column.aggregateType option for column listed above" );
3696
3727
  }
3697
3728
  }
3698
3729
  });
@@ -3816,20 +3847,34 @@
3816
3847
  const pageStart = pageSize * pageIndex;
3817
3848
  const pageEnd = pageStart + pageSize;
3818
3849
  rows = rows.slice(pageStart, pageEnd);
3850
+ let paginatedRowModel;
3819
3851
 
3820
3852
  if (!instance.options.paginateExpandedRows) {
3821
- return expandRows({
3853
+ paginatedRowModel = expandRows({
3822
3854
  rows,
3823
3855
  flatRows,
3824
3856
  rowsById
3825
3857
  });
3858
+ } else {
3859
+ paginatedRowModel = {
3860
+ rows,
3861
+ flatRows,
3862
+ rowsById
3863
+ };
3826
3864
  }
3827
3865
 
3828
- return {
3829
- rows,
3830
- flatRows,
3831
- rowsById
3866
+ paginatedRowModel.flatRows = [];
3867
+
3868
+ const handleRow = row => {
3869
+ paginatedRowModel.flatRows.push(row);
3870
+
3871
+ if (row.subRows.length) {
3872
+ row.subRows.forEach(handleRow);
3873
+ }
3832
3874
  };
3875
+
3876
+ paginatedRowModel.rows.forEach(handleRow);
3877
+ return paginatedRowModel;
3833
3878
  }, {
3834
3879
  key: 'getPaginationRowModel',
3835
3880
  debug: () => {
@@ -3871,6 +3916,7 @@
3871
3916
  onStateChange: () => {},
3872
3917
  // noop
3873
3918
  render,
3919
+ renderFallbackValue: null,
3874
3920
  ...options
3875
3921
  }; // Create a new table instance and store it in state
3876
3922