@tanstack/react-table 8.0.0-beta.3 → 8.0.0-beta.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.
@@ -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":"6d83-127"},{"name":"react-table/src/index.tsx","uid":"6d83-129"}]}]}],"isRoot":true},"nodeParts":{"6d83-127":{"renderedLength":137570,"gzipLength":23393,"brotliLength":0,"mainUid":"6d83-126"},"6d83-129":{"renderedLength":2102,"gzipLength":836,"brotliLength":0,"mainUid":"6d83-128"}},"nodeMetas":{"6d83-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"6d83-127"},"imported":[],"importedBy":[{"uid":"6d83-128"}]},"6d83-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"6d83-129"},"imported":[{"uid":"6d83-130"},{"uid":"6d83-126"}],"importedBy":[],"isEntry":true},"6d83-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"6d83-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":"50f7-127"},{"name":"react-table/src/index.tsx","uid":"50f7-129"}]}]}],"isRoot":true},"nodeParts":{"50f7-127":{"renderedLength":138364,"gzipLength":23596,"brotliLength":0,"mainUid":"50f7-126"},"50f7-129":{"renderedLength":2135,"gzipLength":854,"brotliLength":0,"mainUid":"50f7-128"}},"nodeMetas":{"50f7-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"50f7-127"},"imported":[],"importedBy":[{"uid":"50f7-128"}]},"50f7-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"50f7-129"},"imported":[{"uid":"50f7-130"},{"uid":"50f7-126"}],"importedBy":[],"isEntry":true},"50f7-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"50f7-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": "6d83-132"
14
+ "uid": "50f7-132"
15
15
  },
16
16
  {
17
17
  "name": "react-table/src/index.tsx",
18
- "uid": "6d83-134"
18
+ "uid": "50f7-134"
19
19
  }
20
20
  ]
21
21
  }
@@ -25,55 +25,55 @@
25
25
  "isRoot": true
26
26
  },
27
27
  "nodeParts": {
28
- "6d83-132": {
29
- "renderedLength": 137570,
30
- "gzipLength": 23393,
28
+ "50f7-132": {
29
+ "renderedLength": 138364,
30
+ "gzipLength": 23596,
31
31
  "brotliLength": 0,
32
- "mainUid": "6d83-131"
32
+ "mainUid": "50f7-131"
33
33
  },
34
- "6d83-134": {
35
- "renderedLength": 2102,
36
- "gzipLength": 836,
34
+ "50f7-134": {
35
+ "renderedLength": 2135,
36
+ "gzipLength": 854,
37
37
  "brotliLength": 0,
38
- "mainUid": "6d83-133"
38
+ "mainUid": "50f7-133"
39
39
  }
40
40
  },
41
41
  "nodeMetas": {
42
- "6d83-131": {
42
+ "50f7-131": {
43
43
  "id": "/packages/table-core/build/esm/index.js",
44
44
  "moduleParts": {
45
- "index.production.js": "6d83-132"
45
+ "index.production.js": "50f7-132"
46
46
  },
47
47
  "imported": [],
48
48
  "importedBy": [
49
49
  {
50
- "uid": "6d83-133"
50
+ "uid": "50f7-133"
51
51
  }
52
52
  ]
53
53
  },
54
- "6d83-133": {
54
+ "50f7-133": {
55
55
  "id": "/packages/react-table/src/index.tsx",
56
56
  "moduleParts": {
57
- "index.production.js": "6d83-134"
57
+ "index.production.js": "50f7-134"
58
58
  },
59
59
  "imported": [
60
60
  {
61
- "uid": "6d83-135"
61
+ "uid": "50f7-135"
62
62
  },
63
63
  {
64
- "uid": "6d83-131"
64
+ "uid": "50f7-131"
65
65
  }
66
66
  ],
67
67
  "importedBy": [],
68
68
  "isEntry": true
69
69
  },
70
- "6d83-135": {
70
+ "50f7-135": {
71
71
  "id": "react",
72
72
  "moduleParts": {},
73
73
  "imported": [],
74
74
  "importedBy": [
75
75
  {
76
- "uid": "6d83-133"
76
+ "uid": "50f7-133"
77
77
  }
78
78
  ],
79
79
  "isExternal": true
@@ -1555,6 +1555,12 @@
1555
1555
  };
1556
1556
  },
1557
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
+
1558
1564
  return {
1559
1565
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1560
1566
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1564,15 +1570,19 @@
1564
1570
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1565
1571
  },
1566
1572
  renderAggregatedCell: () => {
1567
- 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
+ }
1568
1578
 
1569
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1579
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1570
1580
  return template ? instance._render(template, {
1571
1581
  instance,
1572
1582
  column,
1573
1583
  row,
1574
1584
  cell,
1575
- getValue: cell.getValue
1585
+ getValue: getRenderValue
1576
1586
  }) : null;
1577
1587
  }
1578
1588
  };
@@ -2555,8 +2565,10 @@
2555
2565
  // })
2556
2566
  // return
2557
2567
  // }
2568
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2569
+ const nextSortingOrder = column.getNextSortingOrder();
2558
2570
  instance.setSorting(old => {
2559
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2571
+ var _instance$options$ena, _instance$options$ena2;
2560
2572
 
2561
2573
  // Find any existing sorting for this column
2562
2574
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2581,30 +2593,29 @@
2581
2593
  } else {
2582
2594
  sortAction = 'replace';
2583
2595
  }
2584
- }
2596
+ } // Handle toggle states that will remove the sorting
2585
2597
 
2586
- 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
2587
2598
 
2588
2599
  if (sortAction === 'toggle' && ( // Must be toggling
2589
2600
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2590
2601
  !hasDescDefined && ( // Must not be setting desc
2591
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2592
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2593
- ? !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
+ ) {
2594
2605
  sortAction = 'remove';
2595
2606
  }
2596
2607
 
2597
2608
  if (sortAction === 'replace') {
2598
2609
  newSorting = [{
2599
2610
  id: column.id,
2600
- desc: hasDescDefined ? desc : !!sortDescFirst
2611
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2601
2612
  }];
2602
2613
  } else if (sortAction === 'add' && old != null && old.length) {
2603
2614
  var _instance$options$max;
2604
2615
 
2605
2616
  newSorting = [...old, {
2606
2617
  id: column.id,
2607
- desc: hasDescDefined ? desc : !!sortDescFirst
2618
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2608
2619
  }]; // Take latest n columns
2609
2620
 
2610
2621
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2613,7 +2624,7 @@
2613
2624
  newSorting = old.map(d => {
2614
2625
  if (d.id === column.id) {
2615
2626
  return { ...d,
2616
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2627
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2617
2628
  };
2618
2629
  }
2619
2630
 
@@ -2626,6 +2637,23 @@
2626
2637
  return newSorting;
2627
2638
  });
2628
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
+ },
2629
2657
  getCanSort: () => {
2630
2658
  var _column$columnDef$ena, _instance$options$ena3;
2631
2659
 
@@ -3073,6 +3101,12 @@
3073
3101
  }
3074
3102
 
3075
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
+
3076
3110
  const cell = {
3077
3111
  id: row.id + "_" + column.id,
3078
3112
  row,
@@ -3084,7 +3118,7 @@
3084
3118
  column,
3085
3119
  row,
3086
3120
  cell: cell,
3087
- getValue: cell.getValue
3121
+ getValue: getRenderValue
3088
3122
  }) : null;
3089
3123
  }
3090
3124
  };
@@ -3868,6 +3902,7 @@
3868
3902
  onStateChange: () => {},
3869
3903
  // noop
3870
3904
  render,
3905
+ renderFallbackValue: null,
3871
3906
  ...options
3872
3907
  }; // Create a new table instance and store it in state
3873
3908