@tanstack/table-core 8.0.0-alpha.84 → 8.0.0-alpha.85

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.
@@ -1212,8 +1212,7 @@ const Filters = {
1212
1212
  createRow: (row, instance) => {
1213
1213
  return {
1214
1214
  columnFilters: {},
1215
- columnFiltersMeta: {},
1216
- subRowsByFacetId: {}
1215
+ columnFiltersMeta: {}
1217
1216
  };
1218
1217
  },
1219
1218
  createInstance: instance => {
@@ -1304,53 +1303,42 @@ function shouldAutoRemoveFilter(filterFn, value, column) {
1304
1303
  return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1305
1304
  }
1306
1305
 
1307
- const aggregationFns = {
1308
- sum,
1309
- min,
1310
- max,
1311
- extent,
1312
- mean,
1313
- median,
1314
- unique,
1315
- uniqueCount,
1316
- count
1317
- };
1318
-
1319
- function sum(_getLeafValues, getChildValues) {
1306
+ const sum = (columnId, _leafRows, childRows) => {
1320
1307
  // It's faster to just add the aggregations together instead of
1321
1308
  // process leaf nodes individually
1322
- return getChildValues().reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1323
- }
1309
+ return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1310
+ };
1324
1311
 
1325
- function min(_getLeafValues, getChildValues) {
1312
+ const min = (columnId, _leafRows, childRows) => {
1326
1313
  let min;
1314
+ childRows.forEach(row => {
1315
+ const value = row.getValue(columnId);
1327
1316
 
1328
- for (const value of getChildValues()) {
1329
1317
  if (value != null && (min > value || min === undefined && value >= value)) {
1330
1318
  min = value;
1331
1319
  }
1332
- }
1333
-
1320
+ });
1334
1321
  return min;
1335
- }
1322
+ };
1336
1323
 
1337
- function max(_getLeafValues, getChildValues) {
1324
+ const max = (columnId, _leafRows, childRows) => {
1338
1325
  let max;
1326
+ childRows.forEach(row => {
1327
+ const value = row.getValue(columnId);
1339
1328
 
1340
- for (const value of getChildValues()) {
1341
1329
  if (value != null && (max < value || max === undefined && value >= value)) {
1342
1330
  max = value;
1343
1331
  }
1344
- }
1345
-
1332
+ });
1346
1333
  return max;
1347
- }
1334
+ };
1348
1335
 
1349
- function extent(_getLeafValues, getChildValues) {
1336
+ const extent = (columnId, _leafRows, childRows) => {
1350
1337
  let min;
1351
1338
  let max;
1339
+ childRows.forEach(row => {
1340
+ const value = row.getValue(columnId);
1352
1341
 
1353
- for (const value of getChildValues()) {
1354
1342
  if (value != null) {
1355
1343
  if (min === undefined) {
1356
1344
  if (value >= value) min = max = value;
@@ -1359,54 +1347,65 @@ function extent(_getLeafValues, getChildValues) {
1359
1347
  if (max < value) max = value;
1360
1348
  }
1361
1349
  }
1362
- }
1363
-
1350
+ });
1364
1351
  return [min, max];
1365
- }
1352
+ };
1366
1353
 
1367
- function mean(getLeafValues) {
1354
+ const mean = (columnId, leafRows) => {
1368
1355
  let count = 0;
1369
1356
  let sum = 0;
1357
+ leafRows.forEach(row => {
1358
+ let value = row.getValue(columnId);
1370
1359
 
1371
- for (let value of getLeafValues()) {
1372
1360
  if (value != null && (value = +value) >= value) {
1373
1361
  ++count, sum += value;
1374
1362
  }
1375
- }
1376
-
1363
+ });
1377
1364
  if (count) return sum / count;
1378
1365
  return;
1379
- }
1380
-
1381
- function median(getLeafValues) {
1382
- const leafValues = getLeafValues();
1366
+ };
1383
1367
 
1384
- if (!leafValues.length) {
1368
+ const median = (columnId, leafRows) => {
1369
+ if (!leafRows.length) {
1385
1370
  return;
1386
1371
  }
1387
1372
 
1388
1373
  let min = 0;
1389
1374
  let max = 0;
1390
- leafValues.forEach(value => {
1375
+ leafRows.forEach(row => {
1376
+ let value = row.getValue(columnId);
1377
+
1391
1378
  if (typeof value === 'number') {
1392
1379
  min = Math.min(min, value);
1393
1380
  max = Math.max(max, value);
1394
1381
  }
1395
1382
  });
1396
1383
  return (min + max) / 2;
1397
- }
1384
+ };
1398
1385
 
1399
- function unique(getLeafValues) {
1400
- return Array.from(new Set(getLeafValues()).values());
1401
- }
1386
+ const unique = (columnId, leafRows) => {
1387
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1388
+ };
1402
1389
 
1403
- function uniqueCount(getLeafValues) {
1404
- return new Set(getLeafValues()).size;
1405
- }
1390
+ const uniqueCount = (columnId, leafRows) => {
1391
+ return new Set(leafRows.map(d => d.getValue(columnId))).size;
1392
+ };
1406
1393
 
1407
- function count(getLeafValues) {
1408
- return getLeafValues().length;
1409
- }
1394
+ const count = (_columnId, leafRows) => {
1395
+ return leafRows.length;
1396
+ };
1397
+
1398
+ const aggregationFns = {
1399
+ sum,
1400
+ min,
1401
+ max,
1402
+ extent,
1403
+ mean,
1404
+ median,
1405
+ unique,
1406
+ uniqueCount,
1407
+ count
1408
+ };
1410
1409
 
1411
1410
  //
1412
1411
  const Grouping = {
@@ -1461,7 +1460,7 @@ const Grouping = {
1461
1460
  column.toggleGrouping();
1462
1461
  };
1463
1462
  },
1464
- getColumnAutoAggregationFn: () => {
1463
+ getAutoAggregationFn: () => {
1465
1464
  const firstRow = instance.getCoreRowModel().flatRows[0];
1466
1465
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1467
1466
 
@@ -1475,7 +1474,7 @@ const Grouping = {
1475
1474
 
1476
1475
  return aggregationFns.count;
1477
1476
  },
1478
- getColumnAggregationFn: () => {
1477
+ getAggregationFn: () => {
1479
1478
  var _ref4;
1480
1479
 
1481
1480
  const userAggregationFns = instance.options.aggregationFns;
@@ -1484,7 +1483,7 @@ const Grouping = {
1484
1483
  throw new Error();
1485
1484
  }
1486
1485
 
1487
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getColumnAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1486
+ return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1488
1487
  }
1489
1488
  };
1490
1489
  },
@@ -1510,10 +1509,10 @@ const Grouping = {
1510
1509
  }
1511
1510
  };
1512
1511
  },
1513
- createRow: (row, instance) => {
1512
+ createRow: row => {
1514
1513
  return {
1515
1514
  getIsGrouped: () => !!row.groupingColumnId,
1516
- groupingValuesCache: {}
1515
+ _groupingValuesCache: {}
1517
1516
  };
1518
1517
  },
1519
1518
  createCell: (cell, column, row, instance) => {
@@ -3648,25 +3647,17 @@ function getGroupedRowModel() {
3648
3647
  return row._valuesCache[columnId];
3649
3648
  }
3650
3649
 
3651
- if (row.groupingValuesCache.hasOwnProperty(columnId)) {
3652
- return row.groupingValuesCache[columnId];
3650
+ if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3651
+ return row._groupingValuesCache[columnId];
3653
3652
  } // Aggregate the values
3654
3653
 
3655
3654
 
3656
3655
  const column = instance.getColumn(columnId);
3657
- const aggregateFn = column.getColumnAggregationFn();
3656
+ const aggregateFn = column.getAggregationFn();
3658
3657
 
3659
3658
  if (aggregateFn) {
3660
- row.groupingValuesCache[columnId] = aggregateFn(() => leafRows.map(row => {
3661
- let columnValue = row.getValue(columnId);
3662
-
3663
- if (!depth && column.columnDef.aggregateValue) {
3664
- columnValue = column.columnDef.aggregateValue(columnValue);
3665
- }
3666
-
3667
- return columnValue;
3668
- }), () => groupedRows.map(row => row.getValue(columnId)));
3669
- return row.groupingValuesCache[columnId];
3659
+ row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3660
+ return row._groupingValuesCache[columnId];
3670
3661
  } else if (column.aggregationFn) {
3671
3662
  console.info({
3672
3663
  column
@@ -3819,5 +3810,5 @@ function getPaginationRowModel(opts) {
3819
3810
  });
3820
3811
  }
3821
3812
 
3822
- export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTableFactory, createTableInstance, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, makeStateUpdater, mean, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
3813
+ export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTableFactory, createTableInstance, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
3823
3814
  //# sourceMappingURL=index.js.map