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