@tanstack/vue-table 8.9.0 → 8.9.1

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.
@@ -49,6 +49,9 @@
49
49
  function isFunction(d) {
50
50
  return d instanceof Function;
51
51
  }
52
+ function isNumberArray(d) {
53
+ return Array.isArray(d) && d.every(val => typeof val === 'number');
54
+ }
52
55
  function flattenBy(arr, getChildren) {
53
56
  const flat = [];
54
57
  const recurse = subArr => {
@@ -1295,16 +1298,16 @@
1295
1298
  if (!leafRows.length) {
1296
1299
  return;
1297
1300
  }
1298
- let min = 0;
1299
- let max = 0;
1300
- leafRows.forEach(row => {
1301
- let value = row.getValue(columnId);
1302
- if (typeof value === 'number') {
1303
- min = Math.min(min, value);
1304
- max = Math.max(max, value);
1305
- }
1306
- });
1307
- return (min + max) / 2;
1301
+ const values = leafRows.map(row => row.getValue(columnId));
1302
+ if (!isNumberArray(values)) {
1303
+ return;
1304
+ }
1305
+ if (values.length === 1) {
1306
+ return values[0];
1307
+ }
1308
+ const mid = Math.floor(values.length / 2);
1309
+ const nums = values.sort((a, b) => a - b);
1310
+ return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
1308
1311
  };
1309
1312
  const unique = (columnId, leafRows) => {
1310
1313
  return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
@@ -3787,6 +3790,7 @@
3787
3790
  exports.getPaginationRowModel = getPaginationRowModel;
3788
3791
  exports.getSortedRowModel = getSortedRowModel;
3789
3792
  exports.isFunction = isFunction;
3793
+ exports.isNumberArray = isNumberArray;
3790
3794
  exports.isRowSelected = isRowSelected;
3791
3795
  exports.isSubRowSelected = isSubRowSelected;
3792
3796
  exports.makeStateUpdater = makeStateUpdater;