@tanstack/table-core 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.
@@ -1979,6 +1979,10 @@ const RowSelection = {
1979
1979
 
1980
1980
  if (value) {
1981
1981
  preGroupedFlatRows.forEach(row => {
1982
+ if (!row.getCanSelect()) {
1983
+ return;
1984
+ }
1985
+
1982
1986
  rowSelection[row.id] = true;
1983
1987
  });
1984
1988
  } else {
@@ -2242,8 +2246,8 @@ const RowSelection = {
2242
2246
  const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
2243
2247
  var _row$subRows;
2244
2248
 
2245
- const row = table.getRow(id);
2246
- row.getIsGrouped(); // if ( // TODO: enforce grouping row selection rules
2249
+ const row = table.getRow(id); // const isGrouped = row.getIsGrouped()
2250
+ // if ( // TODO: enforce grouping row selection rules
2247
2251
  // !isGrouped ||
2248
2252
  // (isGrouped && table.options.enableGroupingRowSelection)
2249
2253
  // ) {
@@ -2253,7 +2257,9 @@ const mutateRowIsSelected = (selectedRowIds, id, value, table) => {
2253
2257
  Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
2254
2258
  }
2255
2259
 
2256
- selectedRowIds[id] = true;
2260
+ if (row.getCanSelect()) {
2261
+ selectedRowIds[id] = true;
2262
+ }
2257
2263
  } else {
2258
2264
  delete selectedRowIds[id];
2259
2265
  } // }
@@ -2349,7 +2355,12 @@ const textCaseSensitive = (rowA, rowB, columnId) => {
2349
2355
  };
2350
2356
 
2351
2357
  const datetime = (rowA, rowB, columnId) => {
2352
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2358
+ const a = rowA.getValue(columnId);
2359
+ const b = rowB.getValue(columnId); // Can handle nullish values
2360
+ // Use > and < because == (and ===) doesn't work with
2361
+ // Date objects (would require calling getTime()).
2362
+
2363
+ return a > b ? 1 : a < b ? -1 : 0;
2353
2364
  };
2354
2365
 
2355
2366
  const basic = (rowA, rowB, columnId) => {
@@ -2510,18 +2521,17 @@ const Sorting = {
2510
2521
  // }
2511
2522
  // this needs to be outside of table.setSorting to be in sync with rerender
2512
2523
  const nextSortingOrder = column.getNextSortingOrder();
2524
+ const hasManualValue = typeof desc !== 'undefined' && desc !== null;
2513
2525
  table.setSorting(old => {
2514
- var _table$options$enable, _table$options$enable2;
2515
-
2516
2526
  // Find any existing sorting for this column
2517
2527
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2518
2528
  const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2519
- const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
2520
2529
  let newSorting = []; // What should we do with this sort action?
2521
2530
 
2522
2531
  let sortAction;
2532
+ let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'; // Multi-mode
2523
2533
 
2524
- if (column.getCanMultiSort() && multi) {
2534
+ if (old != null && old.length && column.getCanMultiSort() && multi) {
2525
2535
  if (existingSorting) {
2526
2536
  sortAction = 'toggle';
2527
2537
  } else {
@@ -2539,63 +2549,71 @@ const Sorting = {
2539
2549
  } // Handle toggle states that will remove the sorting
2540
2550
 
2541
2551
 
2542
- if (sortAction === 'toggle' && ( // Must be toggling
2543
- (_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && // If enableSortRemove, enable in general
2544
- !hasDescDefined && ( // Must not be setting desc
2545
- multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) && // If multi, don't allow if enableMultiRemove
2546
- !nextSortingOrder // Finally, detect if it should indeed be removed
2547
- ) {
2548
- sortAction = 'remove';
2552
+ if (sortAction === 'toggle') {
2553
+ // If we are "actually" toggling (not a manual set value), should we remove the sorting?
2554
+ if (!hasManualValue) {
2555
+ // Is our intention to remove?
2556
+ if (!nextSortingOrder) {
2557
+ sortAction = 'remove';
2558
+ }
2559
+ }
2549
2560
  }
2550
2561
 
2551
- if (sortAction === 'replace') {
2552
- newSorting = [{
2553
- id: column.id,
2554
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2555
- }];
2556
- } else if (sortAction === 'add' && old != null && old.length) {
2562
+ if (sortAction === 'add') {
2557
2563
  var _table$options$maxMul;
2558
2564
 
2559
2565
  newSorting = [...old, {
2560
2566
  id: column.id,
2561
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2567
+ desc: nextDesc
2562
2568
  }]; // Take latest n columns
2563
2569
 
2564
2570
  newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
2565
- } else if (sortAction === 'toggle' && old != null && old.length) {
2571
+ } else if (sortAction === 'toggle') {
2566
2572
  // This flips (or sets) the
2567
2573
  newSorting = old.map(d => {
2568
2574
  if (d.id === column.id) {
2569
2575
  return { ...d,
2570
- desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2576
+ desc: nextDesc
2571
2577
  };
2572
2578
  }
2573
2579
 
2574
2580
  return d;
2575
2581
  });
2576
- } else if (sortAction === 'remove' && old != null && old.length) {
2582
+ } else if (sortAction === 'remove') {
2577
2583
  newSorting = old.filter(d => d.id !== column.id);
2584
+ } else {
2585
+ newSorting = [{
2586
+ id: column.id,
2587
+ desc: nextDesc
2588
+ }];
2578
2589
  }
2579
2590
 
2580
2591
  return newSorting;
2581
2592
  });
2582
2593
  },
2583
- getNextSortingOrder: () => {
2594
+ getFirstSortDir: () => {
2584
2595
  var _ref, _column$columnDef$sor;
2585
2596
 
2586
2597
  const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
2587
- const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2598
+ return sortDescFirst ? 'desc' : 'asc';
2599
+ },
2600
+ getNextSortingOrder: multi => {
2601
+ var _table$options$enable, _table$options$enable2;
2602
+
2603
+ const firstSortDirection = column.getFirstSortDir();
2588
2604
  const isSorted = column.getIsSorted();
2589
2605
 
2590
2606
  if (!isSorted) {
2591
2607
  return firstSortDirection;
2592
2608
  }
2593
2609
 
2594
- if (isSorted === firstSortDirection) {
2595
- return isSorted === 'desc' ? 'asc' : 'desc';
2596
- } else {
2610
+ if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && ( // If enableSortRemove, enable in general
2611
+ multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
2612
+ ) {
2597
2613
  return false;
2598
2614
  }
2615
+
2616
+ return isSorted === 'desc' ? 'asc' : 'desc';
2599
2617
  },
2600
2618
  getCanSort: () => {
2601
2619
  var _column$columnDef$ena, _table$options$enable3;
@@ -3544,9 +3562,20 @@ function getGroupedRowModel() {
3544
3562
  depth = 0;
3545
3563
  }
3546
3564
 
3547
- // This is the last level, just return the rows
3548
- if (depth === existingGrouping.length) {
3549
- return rows;
3565
+ // Grouping depth has been been met
3566
+ // Stop grouping and simply rewrite thd depth and row relationships
3567
+ if (depth >= existingGrouping.length) {
3568
+ return rows.map(row => {
3569
+ row.depth = depth;
3570
+ groupedFlatRows.push(row);
3571
+ groupedRowsById[row.id] = row;
3572
+
3573
+ if (row.subRows) {
3574
+ row.subRows = groupUpRecursively(row.subRows, depth + 1);
3575
+ }
3576
+
3577
+ return row;
3578
+ });
3550
3579
  }
3551
3580
 
3552
3581
  const columnId = existingGrouping[depth]; // Group the rows together for this level