@tanstack/react-table 8.0.0-alpha.86 → 8.0.0-alpha.89

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":"74a1-127"},{"name":"react-table/src/index.tsx","uid":"74a1-129"}]}]}],"isRoot":true},"nodeParts":{"74a1-127":{"renderedLength":137358,"gzipLength":23347,"brotliLength":0,"mainUid":"74a1-126"},"74a1-129":{"renderedLength":2102,"gzipLength":836,"brotliLength":0,"mainUid":"74a1-128"}},"nodeMetas":{"74a1-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"74a1-127"},"imported":[],"importedBy":[{"uid":"74a1-128"}]},"74a1-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"74a1-129"},"imported":[{"uid":"74a1-130"},{"uid":"74a1-126"}],"importedBy":[],"isEntry":true},"74a1-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"74a1-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":"756b-127"},{"name":"react-table/src/index.tsx","uid":"756b-129"}]}]}],"isRoot":true},"nodeParts":{"756b-127":{"renderedLength":137942,"gzipLength":23472,"brotliLength":0,"mainUid":"756b-126"},"756b-129":{"renderedLength":2102,"gzipLength":836,"brotliLength":0,"mainUid":"756b-128"}},"nodeMetas":{"756b-126":{"id":"/packages/table-core/build/esm/index.js","moduleParts":{"index.production.js":"756b-127"},"imported":[],"importedBy":[{"uid":"756b-128"}]},"756b-128":{"id":"/packages/react-table/src/index.tsx","moduleParts":{"index.production.js":"756b-129"},"imported":[{"uid":"756b-130"},{"uid":"756b-126"}],"importedBy":[],"isEntry":true},"756b-130":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"756b-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": "74a1-132"
14
+ "uid": "756b-132"
15
15
  },
16
16
  {
17
17
  "name": "react-table/src/index.tsx",
18
- "uid": "74a1-134"
18
+ "uid": "756b-134"
19
19
  }
20
20
  ]
21
21
  }
@@ -25,55 +25,55 @@
25
25
  "isRoot": true
26
26
  },
27
27
  "nodeParts": {
28
- "74a1-132": {
29
- "renderedLength": 137358,
30
- "gzipLength": 23347,
28
+ "756b-132": {
29
+ "renderedLength": 137942,
30
+ "gzipLength": 23472,
31
31
  "brotliLength": 0,
32
- "mainUid": "74a1-131"
32
+ "mainUid": "756b-131"
33
33
  },
34
- "74a1-134": {
34
+ "756b-134": {
35
35
  "renderedLength": 2102,
36
36
  "gzipLength": 836,
37
37
  "brotliLength": 0,
38
- "mainUid": "74a1-133"
38
+ "mainUid": "756b-133"
39
39
  }
40
40
  },
41
41
  "nodeMetas": {
42
- "74a1-131": {
42
+ "756b-131": {
43
43
  "id": "/packages/table-core/build/esm/index.js",
44
44
  "moduleParts": {
45
- "index.production.js": "74a1-132"
45
+ "index.production.js": "756b-132"
46
46
  },
47
47
  "imported": [],
48
48
  "importedBy": [
49
49
  {
50
- "uid": "74a1-133"
50
+ "uid": "756b-133"
51
51
  }
52
52
  ]
53
53
  },
54
- "74a1-133": {
54
+ "756b-133": {
55
55
  "id": "/packages/react-table/src/index.tsx",
56
56
  "moduleParts": {
57
- "index.production.js": "74a1-134"
57
+ "index.production.js": "756b-134"
58
58
  },
59
59
  "imported": [
60
60
  {
61
- "uid": "74a1-135"
61
+ "uid": "756b-135"
62
62
  },
63
63
  {
64
- "uid": "74a1-131"
64
+ "uid": "756b-131"
65
65
  }
66
66
  ],
67
67
  "importedBy": [],
68
68
  "isEntry": true
69
69
  },
70
- "74a1-135": {
70
+ "756b-135": {
71
71
  "id": "react",
72
72
  "moduleParts": {},
73
73
  "imported": [],
74
74
  "importedBy": [
75
75
  {
76
- "uid": "74a1-133"
76
+ "uid": "756b-133"
77
77
  }
78
78
  ],
79
79
  "isExternal": true
@@ -144,7 +144,7 @@
144
144
  }
145
145
  }
146
146
 
147
- let column = { ...columnDef,
147
+ let column = {
148
148
  id: "" + id,
149
149
  accessorFn,
150
150
  parent: parent,
@@ -908,8 +908,12 @@
908
908
  getIsAllRowsExpanded: () => {
909
909
  const expanded = instance.getState().expanded; // If expanded is true, save some cycles and return true
910
910
 
911
- if (expanded === true) {
912
- return true;
911
+ if (typeof expanded === 'boolean') {
912
+ return expanded === true;
913
+ }
914
+
915
+ if (!Object.keys(expanded).length) {
916
+ return false;
913
917
  } // If any row is not expanded, return false
914
918
 
915
919
 
@@ -2364,21 +2368,54 @@
2364
2368
  }
2365
2369
 
2366
2370
  const reSplitAlphaNumeric = /([0-9]+)/gm;
2367
- const sortingFns = {
2368
- alphanumeric,
2369
- alphanumericCaseSensitive,
2370
- text,
2371
- textCaseSensitive,
2372
- datetime,
2373
- basic
2374
- };
2375
2371
 
2376
- function alphanumeric(rowA, rowB, columnId) {
2372
+ const alphanumeric = (rowA, rowB, columnId) => {
2377
2373
  return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2378
- }
2374
+ };
2379
2375
 
2380
- function alphanumericCaseSensitive(rowA, rowB, columnId) {
2376
+ const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2381
2377
  return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2378
+ }; // The text filter is more basic (less numeric support)
2379
+ // but is much faster
2380
+
2381
+
2382
+ const text = (rowA, rowB, columnId) => {
2383
+ return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2384
+ }; // The text filter is more basic (less numeric support)
2385
+ // but is much faster
2386
+
2387
+
2388
+ const textCaseSensitive = (rowA, rowB, columnId) => {
2389
+ return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2390
+ };
2391
+
2392
+ const datetime = (rowA, rowB, columnId) => {
2393
+ return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2394
+ };
2395
+
2396
+ const basic = (rowA, rowB, columnId) => {
2397
+ return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2398
+ }; // Utils
2399
+
2400
+
2401
+ function compareBasic(a, b) {
2402
+ return a === b ? 0 : a > b ? 1 : -1;
2403
+ }
2404
+
2405
+ function toString(a) {
2406
+ if (typeof a === 'number') {
2407
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2408
+ return '';
2409
+ }
2410
+
2411
+ return String(a);
2412
+ }
2413
+
2414
+ if (typeof a === 'string') {
2415
+ return a;
2416
+ }
2417
+
2418
+ return '';
2382
2419
  } // Mixed sorting is slow, but very inclusive of many edge cases.
2383
2420
  // It handles numbers, mixed alphanumeric combinations, and even
2384
2421
  // null, undefined, and Infinity
@@ -2425,48 +2462,17 @@
2425
2462
  }
2426
2463
 
2427
2464
  return a.length - b.length;
2428
- } // The text filter is more basic (less numeric support)
2429
- // but is much faster
2430
-
2431
-
2432
- function text(rowA, rowB, columnId) {
2433
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2434
- } // The text filter is more basic (less numeric support)
2435
- // but is much faster
2436
-
2437
-
2438
- function textCaseSensitive(rowA, rowB, columnId) {
2439
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2440
- }
2441
-
2442
- function datetime(rowA, rowB, columnId) {
2443
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2444
- }
2445
-
2446
- function basic(rowA, rowB, columnId) {
2447
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2448
- } // Utils
2449
-
2450
-
2451
- function compareBasic(a, b) {
2452
- return a === b ? 0 : a > b ? 1 : -1;
2453
- }
2465
+ } // Exports
2454
2466
 
2455
- function toString(a) {
2456
- if (typeof a === 'number') {
2457
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2458
- return '';
2459
- }
2460
-
2461
- return String(a);
2462
- }
2463
2467
 
2464
- if (typeof a === 'string') {
2465
- return a;
2466
- }
2467
-
2468
- return '';
2469
- }
2468
+ const sortingFns = {
2469
+ alphanumeric,
2470
+ alphanumericCaseSensitive,
2471
+ text,
2472
+ textCaseSensitive,
2473
+ datetime,
2474
+ basic
2475
+ };
2470
2476
 
2471
2477
  //
2472
2478
  const Sorting = {
@@ -2547,8 +2553,10 @@
2547
2553
  // })
2548
2554
  // return
2549
2555
  // }
2556
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2557
+ const nextSortingOrder = column.getNextSortingOrder();
2550
2558
  instance.setSorting(old => {
2551
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2559
+ var _instance$options$ena, _instance$options$ena2;
2552
2560
 
2553
2561
  // Find any existing sorting for this column
2554
2562
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2573,30 +2581,29 @@
2573
2581
  } else {
2574
2582
  sortAction = 'replace';
2575
2583
  }
2576
- }
2584
+ } // Handle toggle states that will remove the sorting
2577
2585
 
2578
- 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
2579
2586
 
2580
2587
  if (sortAction === 'toggle' && ( // Must be toggling
2581
2588
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2582
2589
  !hasDescDefined && ( // Must not be setting desc
2583
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2584
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2585
- ? !sortDescFirst : sortDescFirst)) {
2590
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2591
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2592
+ ) {
2586
2593
  sortAction = 'remove';
2587
2594
  }
2588
2595
 
2589
2596
  if (sortAction === 'replace') {
2590
2597
  newSorting = [{
2591
2598
  id: column.id,
2592
- desc: hasDescDefined ? desc : !!sortDescFirst
2599
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2593
2600
  }];
2594
2601
  } else if (sortAction === 'add' && old != null && old.length) {
2595
2602
  var _instance$options$max;
2596
2603
 
2597
2604
  newSorting = [...old, {
2598
2605
  id: column.id,
2599
- desc: hasDescDefined ? desc : !!sortDescFirst
2606
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2600
2607
  }]; // Take latest n columns
2601
2608
 
2602
2609
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2605,7 +2612,7 @@
2605
2612
  newSorting = old.map(d => {
2606
2613
  if (d.id === column.id) {
2607
2614
  return { ...d,
2608
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2615
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2609
2616
  };
2610
2617
  }
2611
2618
 
@@ -2618,6 +2625,23 @@
2618
2625
  return newSorting;
2619
2626
  });
2620
2627
  },
2628
+ getNextSortingOrder: () => {
2629
+ var _ref2, _column$columnDef$sor;
2630
+
2631
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2632
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2633
+ const isSorted = column.getIsSorted();
2634
+
2635
+ if (!isSorted) {
2636
+ return firstSortDirection;
2637
+ }
2638
+
2639
+ if (isSorted === firstSortDirection) {
2640
+ return isSorted === 'desc' ? 'asc' : 'desc';
2641
+ } else {
2642
+ return false;
2643
+ }
2644
+ },
2621
2645
  getCanSort: () => {
2622
2646
  var _column$columnDef$ena, _instance$options$ena3;
2623
2647
 
@@ -2718,8 +2742,8 @@
2718
2742
  },
2719
2743
  createRow: (row, instance) => {
2720
2744
  return {
2721
- _getAllVisibleCells: memo(() => [row.getAllCells().filter(cell => cell.column.getIsVisible()).map(d => d.id).join('_')], _ => {
2722
- return row.getAllCells().filter(cell => cell.column.getIsVisible());
2745
+ _getAllVisibleCells: memo(() => [row.getAllCells(), instance.getState().columnVisibility], cells => {
2746
+ return cells.filter(cell => cell.column.getIsVisible());
2723
2747
  }, {
2724
2748
  key: "development" === 'production' ,
2725
2749
  debug: () => {
@@ -3070,13 +3094,15 @@
3070
3094
  row,
3071
3095
  column,
3072
3096
  getValue: () => row.getValue(columnId),
3073
- renderCell: () => column.columnDef.cell ? instance._render(column.columnDef.cell, {
3074
- instance,
3075
- column,
3076
- row,
3077
- cell: cell,
3078
- getValue: cell.getValue
3079
- }) : null
3097
+ renderCell: () => {
3098
+ return column.columnDef.cell ? instance._render(column.columnDef.cell, {
3099
+ instance,
3100
+ column,
3101
+ row,
3102
+ cell: cell,
3103
+ getValue: cell.getValue
3104
+ }) : null;
3105
+ }
3080
3106
  };
3081
3107
 
3082
3108
  instance._features.forEach(feature => {
@@ -3151,27 +3177,23 @@
3151
3177
  flatRows: [],
3152
3178
  rowsById: {}
3153
3179
  };
3154
- let rows;
3155
- let row;
3156
- let originalRow;
3157
3180
 
3158
3181
  const accessRows = function (originalRows, depth, parent) {
3159
3182
  if (depth === void 0) {
3160
3183
  depth = 0;
3161
3184
  }
3162
3185
 
3163
- rows = [];
3186
+ const rows = [];
3164
3187
 
3165
3188
  for (let i = 0; i < originalRows.length; i++) {
3166
- originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3189
+ // This could be an expensive check at scale, so we should move it somewhere else, but where?
3167
3190
  // if (!id) {
3168
3191
  // if ("development" !== 'production') {
3169
3192
  // throw new Error(`getRowId expected an ID, but got ${id}`)
3170
3193
  // }
3171
3194
  // }
3172
3195
  // Make the row
3173
-
3174
- row = createRow(instance, instance._getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3196
+ const row = createRow(instance, instance._getRowId(originalRows[i], i, parent), originalRows[i], i, depth); // Keep track of every row in a flat array
3175
3197
 
3176
3198
  rowModel.flatRows.push(row); // Also keep track of every row by its ID
3177
3199
 
@@ -3182,7 +3204,7 @@
3182
3204
  if (instance.options.getSubRows) {
3183
3205
  var _row$originalSubRows;
3184
3206
 
3185
- row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3207
+ row.originalSubRows = instance.options.getSubRows(originalRows[i], i); // Then recursively access them
3186
3208
 
3187
3209
  if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3188
3210
  row.subRows = accessRows(row.originalSubRows, depth + 1, row);