@tanstack/react-table 8.2.1 → 8.2.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.
@@ -1993,6 +1993,10 @@ const RowSelection = {
1993
1993
 
1994
1994
  if (value) {
1995
1995
  preGroupedFlatRows.forEach(row => {
1996
+ if (!row.getCanSelect()) {
1997
+ return;
1998
+ }
1999
+
1996
2000
  rowSelection[row.id] = true;
1997
2001
  });
1998
2002
  } else {
@@ -2256,8 +2260,8 @@ const RowSelection = {
2256
2260
  const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
2257
2261
  var _row$subRows;
2258
2262
 
2259
- const row = table.getRow(id);
2260
- row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
2263
+ const row = table.getRow(id); // const isGrouped = row.getIsGrouped()
2264
+ // if ( // TODO: enforce grouping row selection rules
2261
2265
  // !isGrouped ||
2262
2266
  // (isGrouped && table.options.enableGroupingRowSelection)
2263
2267
  // ) {
@@ -2267,7 +2271,9 @@ const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
2267
2271
  Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
2268
2272
  }
2269
2273
 
2270
- selectedRowIds[id] = true;
2274
+ if (row.getCanSelect()) {
2275
+ selectedRowIds[id] = true;
2276
+ }
2271
2277
  } else {
2272
2278
  delete selectedRowIds[id];
2273
2279
  } // }
@@ -2363,7 +2369,12 @@ const textCaseSensitive = (rowA, rowB, columnId) => {
2363
2369
  };
2364
2370
 
2365
2371
  const datetime = (rowA, rowB, columnId) => {
2366
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2372
+ const a = rowA.getValue(columnId);
2373
+ const b = rowB.getValue(columnId); // Can handle nullish values
2374
+ // Use > and < because == (and ===) doesn't work with
2375
+ // Date objects (would require calling getTime()).
2376
+
2377
+ return a > b ? 1 : a < b ? -1 : 0;
2367
2378
  };
2368
2379
 
2369
2380
  const basic = (rowA, rowB, columnId) => {
@@ -2524,18 +2535,17 @@ const Sorting = {
2524
2535
  // }
2525
2536
  // this needs to be outside of table.setSorting to be in sync with rerender
2526
2537
  const nextSortingOrder = column.getNextSortingOrder();
2538
+ const hasManualValue = typeof desc !== 'undefined' && desc !== null;
2527
2539
  table.setSorting(old => {
2528
- var _table$options$enable, _table$options$enable2;
2529
-
2530
2540
  // Find any existing sorting for this column
2531
2541
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2532
2542
  const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2533
- const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2534
2543
  let newSorting = []; // What should we do with this sort action?
2535
2544
 
2536
2545
  let sortAction;
2546
+ let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'; // Multi-mode
2537
2547
 
2538
- if (column.getCanMultiSort() && multi) {
2548
+ if (old != null && old.length && column.getCanMultiSort() && multi) {
2539
2549
  if (existingSorting) {
2540
2550
  sortAction = 'toggle';
2541
2551
  } else {
@@ -2553,63 +2563,71 @@ const Sorting = {
2553
2563
  } // Handle toggle states that will remove the sorting
2554
2564
 
2555
2565
 
2556
- if (sortAction === 'toggle' && ( // Must be toggling
2557
- (_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && // If enableSortRemove, enable in general
2558
- !hasDescDefined && ( // Must not be setting desc
2559
- multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) && // If multi, don't allow if enableMultiRemove
2560
- !nextSortingOrder // Finally, detect if it should indeed be removed
2561
- ) {
2562
- sortAction = 'remove';
2566
+ if (sortAction === 'toggle') {
2567
+ // If we are "actually" toggling (not a manual set value), should we remove the sorting?
2568
+ if (!hasManualValue) {
2569
+ // Is our intention to remove?
2570
+ if (!nextSortingOrder) {
2571
+ sortAction = 'remove';
2572
+ }
2573
+ }
2563
2574
  }
2564
2575
 
2565
- if (sortAction === 'replace') {
2566
- newSorting = [{
2567
- id: column.id,
2568
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2569
- }];
2570
- } else if (sortAction === 'add' && old != null && old.length) {
2576
+ if (sortAction === 'add') {
2571
2577
  var _table$options$maxMul;
2572
2578
 
2573
2579
  newSorting = [...old, {
2574
2580
  id: column.id,
2575
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2581
+ desc: nextDesc
2576
2582
  }]; // Take latest n columns
2577
2583
 
2578
2584
  newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
2579
- } else if (sortAction === 'toggle' && old != null && old.length) {
2585
+ } else if (sortAction === 'toggle') {
2580
2586
  // This flips (or sets) the
2581
2587
  newSorting = old.map(d => {
2582
2588
  if (d.id === column.id) {
2583
2589
  return { ...d,
2584
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2590
+ desc: nextDesc
2585
2591
  };
2586
2592
  }
2587
2593
 
2588
2594
  return d;
2589
2595
  });
2590
- } else if (sortAction === 'remove' && old != null && old.length) {
2596
+ } else if (sortAction === 'remove') {
2591
2597
  newSorting = old.filter(d => d.id !== column.id);
2598
+ } else {
2599
+ newSorting = [{
2600
+ id: column.id,
2601
+ desc: nextDesc
2602
+ }];
2592
2603
  }
2593
2604
 
2594
2605
  return newSorting;
2595
2606
  });
2596
2607
  },
2597
- getNextSortingOrder: () => {
2608
+ getFirstSortDir: () => {
2598
2609
  var _ref, _column$columnDef$sor;
2599
2610
 
2600
2611
  const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
2601
- const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2612
+ return sortDescFirst ? 'desc' : 'asc';
2613
+ },
2614
+ getNextSortingOrder: multi => {
2615
+ var _table$options$enable, _table$options$enable2;
2616
+
2617
+ const firstSortDirection = column.getFirstSortDir();
2602
2618
  const isSorted = column.getIsSorted();
2603
2619
 
2604
2620
  if (!isSorted) {
2605
2621
  return firstSortDirection;
2606
2622
  }
2607
2623
 
2608
- if (isSorted === firstSortDirection) {
2609
- return isSorted === 'desc' ? 'asc' : 'desc';
2610
- } else {
2624
+ if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && ( // If enableSortRemove, enable in general
2625
+ multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
2626
+ ) {
2611
2627
  return false;
2612
2628
  }
2629
+
2630
+ return isSorted === 'desc' ? 'asc' : 'desc';
2613
2631
  },
2614
2632
  getCanSort: () => {
2615
2633
  var _column$columnDef$ena, _table$options$enable3;
@@ -3558,9 +3576,20 @@ function getGroupedRowModel() {
3558
3576
  depth = 0;
3559
3577
  }
3560
3578
 
3561
- // This is the last level, just return the rows
3562
- if (depth === existingGrouping.length) {
3563
- return rows;
3579
+ // Grouping depth has been been met
3580
+ // Stop grouping and simply rewrite thd depth and row relationships
3581
+ if (depth >= existingGrouping.length) {
3582
+ return rows.map(row => {
3583
+ row.depth = depth;
3584
+ groupedFlatRows.push(row);
3585
+ groupedRowsById[row.id] = row;
3586
+
3587
+ if (row.subRows) {
3588
+ row.subRows = groupUpRecursively(row.subRows, depth + 1);
3589
+ }
3590
+
3591
+ return row;
3592
+ });
3564
3593
  }
3565
3594
 
3566
3595
  const columnId = existingGrouping[depth]; // Group the rows together for this level