@tanstack/react-table 8.2.0 → 8.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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":"06ee-123"},{"name":"react-table/src/index.tsx","uid":"06ee-125"}]}]}],"isRoot":true},"nodeParts":{"06ee-123":{"renderedLength":134386,"gzipLength":23082,"brotliLength":0,"mainUid":"06ee-122"},"06ee-125":{"renderedLength":1900,"gzipLength":752,"brotliLength":0,"mainUid":"06ee-124"}},"nodeMetas":{"06ee-122":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"06ee-123"},"imported":[],"importedBy":[{"uid":"06ee-124"}]},"06ee-124":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"06ee-125"},"imported":[{"uid":"06ee-126"},{"uid":"06ee-122"}],"importedBy":[],"isEntry":true},"06ee-126":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"06ee-124"}],"isExternal":true}},"env":{"rollup":"2.76.0"},"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":"6aaf-123"},{"name":"react-table/src/index.tsx","uid":"6aaf-125"}]}]}],"isRoot":true},"nodeParts":{"6aaf-123":{"renderedLength":134724,"gzipLength":23206,"brotliLength":0,"mainUid":"6aaf-122"},"6aaf-125":{"renderedLength":1900,"gzipLength":752,"brotliLength":0,"mainUid":"6aaf-124"}},"nodeMetas":{"6aaf-122":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"6aaf-123"},"imported":[],"importedBy":[{"uid":"6aaf-124"}]},"6aaf-124":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"6aaf-125"},"imported":[{"uid":"6aaf-126"},{"uid":"6aaf-122"}],"importedBy":[],"isEntry":true},"6aaf-126":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"6aaf-124"}],"isExternal":true}},"env":{"rollup":"2.76.0"},"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": "06ee-128"
14
+ "uid": "6aaf-128"
15
15
  },
16
16
  {
17
17
  "name": "react-table/src/index.tsx",
18
- "uid": "06ee-130"
18
+ "uid": "6aaf-130"
19
19
  }
20
20
  ]
21
21
  }
@@ -25,55 +25,55 @@
25
25
  "isRoot": true
26
26
  },
27
27
  "nodeParts": {
28
- "06ee-128": {
29
- "renderedLength": 134386,
30
- "gzipLength": 23082,
28
+ "6aaf-128": {
29
+ "renderedLength": 134724,
30
+ "gzipLength": 23206,
31
31
  "brotliLength": 0,
32
- "mainUid": "06ee-127"
32
+ "mainUid": "6aaf-127"
33
33
  },
34
- "06ee-130": {
34
+ "6aaf-130": {
35
35
  "renderedLength": 1900,
36
36
  "gzipLength": 752,
37
37
  "brotliLength": 0,
38
- "mainUid": "06ee-129"
38
+ "mainUid": "6aaf-129"
39
39
  }
40
40
  },
41
41
  "nodeMetas": {
42
- "06ee-127": {
42
+ "6aaf-127": {
43
43
  "id": "/packages/table-core/build/esm/index.js",
44
44
  "moduleParts": {
45
- "index.production.js": "06ee-128"
45
+ "index.production.js": "6aaf-128"
46
46
  },
47
47
  "imported": [],
48
48
  "importedBy": [
49
49
  {
50
- "uid": "06ee-129"
50
+ "uid": "6aaf-129"
51
51
  }
52
52
  ]
53
53
  },
54
- "06ee-129": {
54
+ "6aaf-129": {
55
55
  "id": "/packages/react-table/src/index.tsx",
56
56
  "moduleParts": {
57
- "index.production.js": "06ee-130"
57
+ "index.production.js": "6aaf-130"
58
58
  },
59
59
  "imported": [
60
60
  {
61
- "uid": "06ee-131"
61
+ "uid": "6aaf-131"
62
62
  },
63
63
  {
64
- "uid": "06ee-127"
64
+ "uid": "6aaf-127"
65
65
  }
66
66
  ],
67
67
  "importedBy": [],
68
68
  "isEntry": true
69
69
  },
70
- "06ee-131": {
70
+ "6aaf-131": {
71
71
  "id": "react",
72
72
  "moduleParts": {},
73
73
  "imported": [],
74
74
  "importedBy": [
75
75
  {
76
- "uid": "06ee-129"
76
+ "uid": "6aaf-129"
77
77
  }
78
78
  ],
79
79
  "isExternal": true
@@ -2013,6 +2013,10 @@
2013
2013
 
2014
2014
  if (value) {
2015
2015
  preGroupedFlatRows.forEach(row => {
2016
+ if (!row.getCanSelect()) {
2017
+ return;
2018
+ }
2019
+
2016
2020
  rowSelection[row.id] = true;
2017
2021
  });
2018
2022
  } else {
@@ -2287,7 +2291,9 @@
2287
2291
  Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
2288
2292
  }
2289
2293
 
2290
- selectedRowIds[id] = true;
2294
+ if (row.getCanSelect()) {
2295
+ selectedRowIds[id] = true;
2296
+ }
2291
2297
  } else {
2292
2298
  delete selectedRowIds[id];
2293
2299
  } // }
@@ -2383,7 +2389,12 @@
2383
2389
  };
2384
2390
 
2385
2391
  const datetime = (rowA, rowB, columnId) => {
2386
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2392
+ const a = rowA.getValue(columnId);
2393
+ const b = rowB.getValue(columnId); // Can handle nullish values
2394
+ // Use > and < because == (and ===) doesn't work with
2395
+ // Date objects (would require calling getTime()).
2396
+
2397
+ return a > b ? 1 : a < b ? -1 : 0;
2387
2398
  };
2388
2399
 
2389
2400
  const basic = (rowA, rowB, columnId) => {
@@ -2544,18 +2555,17 @@
2544
2555
  // }
2545
2556
  // this needs to be outside of table.setSorting to be in sync with rerender
2546
2557
  const nextSortingOrder = column.getNextSortingOrder();
2558
+ const hasManualValue = typeof desc !== 'undefined' && desc !== null;
2547
2559
  table.setSorting(old => {
2548
- var _table$options$enable, _table$options$enable2;
2549
-
2550
2560
  // Find any existing sorting for this column
2551
2561
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2552
2562
  const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2553
- const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2554
2563
  let newSorting = []; // What should we do with this sort action?
2555
2564
 
2556
2565
  let sortAction;
2566
+ let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'; // Multi-mode
2557
2567
 
2558
- if (column.getCanMultiSort() && multi) {
2568
+ if (old != null && old.length && column.getCanMultiSort() && multi) {
2559
2569
  if (existingSorting) {
2560
2570
  sortAction = 'toggle';
2561
2571
  } else {
@@ -2573,63 +2583,71 @@
2573
2583
  } // Handle toggle states that will remove the sorting
2574
2584
 
2575
2585
 
2576
- if (sortAction === 'toggle' && ( // Must be toggling
2577
- (_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && // If enableSortRemove, enable in general
2578
- !hasDescDefined && ( // Must not be setting desc
2579
- multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) && // If multi, don't allow if enableMultiRemove
2580
- !nextSortingOrder // Finally, detect if it should indeed be removed
2581
- ) {
2582
- sortAction = 'remove';
2586
+ if (sortAction === 'toggle') {
2587
+ // If we are "actually" toggling (not a manual set value), should we remove the sorting?
2588
+ if (!hasManualValue) {
2589
+ // Is our intention to remove?
2590
+ if (!nextSortingOrder) {
2591
+ sortAction = 'remove';
2592
+ }
2593
+ }
2583
2594
  }
2584
2595
 
2585
- if (sortAction === 'replace') {
2586
- newSorting = [{
2587
- id: column.id,
2588
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2589
- }];
2590
- } else if (sortAction === 'add' && old != null && old.length) {
2596
+ if (sortAction === 'add') {
2591
2597
  var _table$options$maxMul;
2592
2598
 
2593
2599
  newSorting = [...old, {
2594
2600
  id: column.id,
2595
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2601
+ desc: nextDesc
2596
2602
  }]; // Take latest n columns
2597
2603
 
2598
2604
  newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
2599
- } else if (sortAction === 'toggle' && old != null && old.length) {
2605
+ } else if (sortAction === 'toggle') {
2600
2606
  // This flips (or sets) the
2601
2607
  newSorting = old.map(d => {
2602
2608
  if (d.id === column.id) {
2603
2609
  return { ...d,
2604
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2610
+ desc: nextDesc
2605
2611
  };
2606
2612
  }
2607
2613
 
2608
2614
  return d;
2609
2615
  });
2610
- } else if (sortAction === 'remove' && old != null && old.length) {
2616
+ } else if (sortAction === 'remove') {
2611
2617
  newSorting = old.filter(d => d.id !== column.id);
2618
+ } else {
2619
+ newSorting = [{
2620
+ id: column.id,
2621
+ desc: nextDesc
2622
+ }];
2612
2623
  }
2613
2624
 
2614
2625
  return newSorting;
2615
2626
  });
2616
2627
  },
2617
- getNextSortingOrder: () => {
2628
+ getFirstSortDir: () => {
2618
2629
  var _ref, _column$columnDef$sor;
2619
2630
 
2620
2631
  const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
2621
- const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2632
+ return sortDescFirst ? 'desc' : 'asc';
2633
+ },
2634
+ getNextSortingOrder: multi => {
2635
+ var _table$options$enable, _table$options$enable2;
2636
+
2637
+ const firstSortDirection = column.getFirstSortDir();
2622
2638
  const isSorted = column.getIsSorted();
2623
2639
 
2624
2640
  if (!isSorted) {
2625
2641
  return firstSortDirection;
2626
2642
  }
2627
2643
 
2628
- if (isSorted === firstSortDirection) {
2629
- return isSorted === 'desc' ? 'asc' : 'desc';
2630
- } else {
2644
+ if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && ( // If enableSortRemove, enable in general
2645
+ multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
2646
+ ) {
2631
2647
  return false;
2632
2648
  }
2649
+
2650
+ return isSorted === 'desc' ? 'asc' : 'desc';
2633
2651
  },
2634
2652
  getCanSort: () => {
2635
2653
  var _column$columnDef$ena, _table$options$enable3;
@@ -3593,7 +3611,7 @@
3593
3611
  const subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
3594
3612
 
3595
3613
  const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3596
- const row = createRow(table, id, undefined, index, depth);
3614
+ const row = createRow(table, id, leafRows[0].original, index, depth);
3597
3615
  Object.assign(row, {
3598
3616
  groupingColumnId: columnId,
3599
3617
  groupingValue,