@tanstack/svelte-table 8.0.0-alpha.84 → 8.0.0-alpha.87

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.
@@ -828,7 +828,6 @@ const Expanding = {
828
828
  return {
829
829
  onExpandedChange: makeStateUpdater('expanded', instance),
830
830
  autoResetExpanded: true,
831
- expandSubRows: true,
832
831
  paginateExpandedRows: true
833
832
  };
834
833
  },
@@ -1225,8 +1224,7 @@ const Filters = {
1225
1224
  createRow: (row, instance) => {
1226
1225
  return {
1227
1226
  columnFilters: {},
1228
- columnFiltersMeta: {},
1229
- subRowsByFacetId: {}
1227
+ columnFiltersMeta: {}
1230
1228
  };
1231
1229
  },
1232
1230
  createInstance: instance => {
@@ -1317,53 +1315,42 @@ function shouldAutoRemoveFilter(filterFn, value, column) {
1317
1315
  return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
1318
1316
  }
1319
1317
 
1320
- const aggregationFns = {
1321
- sum,
1322
- min,
1323
- max,
1324
- extent,
1325
- mean,
1326
- median,
1327
- unique,
1328
- uniqueCount,
1329
- count
1330
- };
1331
-
1332
- function sum(_getLeafValues, getChildValues) {
1318
+ const sum = (columnId, _leafRows, childRows) => {
1333
1319
  // It's faster to just add the aggregations together instead of
1334
1320
  // process leaf nodes individually
1335
- return getChildValues().reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1336
- }
1321
+ return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
1322
+ };
1337
1323
 
1338
- function min(_getLeafValues, getChildValues) {
1324
+ const min = (columnId, _leafRows, childRows) => {
1339
1325
  let min;
1326
+ childRows.forEach(row => {
1327
+ const value = row.getValue(columnId);
1340
1328
 
1341
- for (const value of getChildValues()) {
1342
1329
  if (value != null && (min > value || min === undefined && value >= value)) {
1343
1330
  min = value;
1344
1331
  }
1345
- }
1346
-
1332
+ });
1347
1333
  return min;
1348
- }
1334
+ };
1349
1335
 
1350
- function max(_getLeafValues, getChildValues) {
1336
+ const max = (columnId, _leafRows, childRows) => {
1351
1337
  let max;
1338
+ childRows.forEach(row => {
1339
+ const value = row.getValue(columnId);
1352
1340
 
1353
- for (const value of getChildValues()) {
1354
1341
  if (value != null && (max < value || max === undefined && value >= value)) {
1355
1342
  max = value;
1356
1343
  }
1357
- }
1358
-
1344
+ });
1359
1345
  return max;
1360
- }
1346
+ };
1361
1347
 
1362
- function extent(_getLeafValues, getChildValues) {
1348
+ const extent = (columnId, _leafRows, childRows) => {
1363
1349
  let min;
1364
1350
  let max;
1351
+ childRows.forEach(row => {
1352
+ const value = row.getValue(columnId);
1365
1353
 
1366
- for (const value of getChildValues()) {
1367
1354
  if (value != null) {
1368
1355
  if (min === undefined) {
1369
1356
  if (value >= value) min = max = value;
@@ -1372,54 +1359,65 @@ function extent(_getLeafValues, getChildValues) {
1372
1359
  if (max < value) max = value;
1373
1360
  }
1374
1361
  }
1375
- }
1376
-
1362
+ });
1377
1363
  return [min, max];
1378
- }
1364
+ };
1379
1365
 
1380
- function mean(getLeafValues) {
1366
+ const mean = (columnId, leafRows) => {
1381
1367
  let count = 0;
1382
1368
  let sum = 0;
1369
+ leafRows.forEach(row => {
1370
+ let value = row.getValue(columnId);
1383
1371
 
1384
- for (let value of getLeafValues()) {
1385
1372
  if (value != null && (value = +value) >= value) {
1386
1373
  ++count, sum += value;
1387
1374
  }
1388
- }
1389
-
1375
+ });
1390
1376
  if (count) return sum / count;
1391
1377
  return;
1392
- }
1393
-
1394
- function median(getLeafValues) {
1395
- const leafValues = getLeafValues();
1378
+ };
1396
1379
 
1397
- if (!leafValues.length) {
1380
+ const median = (columnId, leafRows) => {
1381
+ if (!leafRows.length) {
1398
1382
  return;
1399
1383
  }
1400
1384
 
1401
1385
  let min = 0;
1402
1386
  let max = 0;
1403
- leafValues.forEach(value => {
1387
+ leafRows.forEach(row => {
1388
+ let value = row.getValue(columnId);
1389
+
1404
1390
  if (typeof value === 'number') {
1405
1391
  min = Math.min(min, value);
1406
1392
  max = Math.max(max, value);
1407
1393
  }
1408
1394
  });
1409
1395
  return (min + max) / 2;
1410
- }
1396
+ };
1411
1397
 
1412
- function unique(getLeafValues) {
1413
- return Array.from(new Set(getLeafValues()).values());
1414
- }
1398
+ const unique = (columnId, leafRows) => {
1399
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
1400
+ };
1415
1401
 
1416
- function uniqueCount(getLeafValues) {
1417
- return new Set(getLeafValues()).size;
1418
- }
1402
+ const uniqueCount = (columnId, leafRows) => {
1403
+ return new Set(leafRows.map(d => d.getValue(columnId))).size;
1404
+ };
1419
1405
 
1420
- function count(getLeafValues) {
1421
- return getLeafValues().length;
1422
- }
1406
+ const count = (_columnId, leafRows) => {
1407
+ return leafRows.length;
1408
+ };
1409
+
1410
+ const aggregationFns = {
1411
+ sum,
1412
+ min,
1413
+ max,
1414
+ extent,
1415
+ mean,
1416
+ median,
1417
+ unique,
1418
+ uniqueCount,
1419
+ count
1420
+ };
1423
1421
 
1424
1422
  //
1425
1423
  const Grouping = {
@@ -1474,7 +1472,7 @@ const Grouping = {
1474
1472
  column.toggleGrouping();
1475
1473
  };
1476
1474
  },
1477
- getColumnAutoAggregationFn: () => {
1475
+ getAutoAggregationFn: () => {
1478
1476
  const firstRow = instance.getCoreRowModel().flatRows[0];
1479
1477
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
1480
1478
 
@@ -1488,7 +1486,7 @@ const Grouping = {
1488
1486
 
1489
1487
  return aggregationFns.count;
1490
1488
  },
1491
- getColumnAggregationFn: () => {
1489
+ getAggregationFn: () => {
1492
1490
  var _ref4;
1493
1491
 
1494
1492
  const userAggregationFns = instance.options.aggregationFns;
@@ -1497,7 +1495,7 @@ const Grouping = {
1497
1495
  throw new Error();
1498
1496
  }
1499
1497
 
1500
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getColumnAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1498
+ return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1501
1499
  }
1502
1500
  };
1503
1501
  },
@@ -1523,10 +1521,10 @@ const Grouping = {
1523
1521
  }
1524
1522
  };
1525
1523
  },
1526
- createRow: (row, instance) => {
1524
+ createRow: row => {
1527
1525
  return {
1528
1526
  getIsGrouped: () => !!row.groupingColumnId,
1529
- groupingValuesCache: {}
1527
+ _groupingValuesCache: {}
1530
1528
  };
1531
1529
  },
1532
1530
  createCell: (cell, column, row, instance) => {
@@ -2345,21 +2343,54 @@ function isRowSelected(row, selection, instance) {
2345
2343
  }
2346
2344
 
2347
2345
  const reSplitAlphaNumeric = /([0-9]+)/gm;
2348
- const sortingFns = {
2349
- alphanumeric,
2350
- alphanumericCaseSensitive,
2351
- text,
2352
- textCaseSensitive,
2353
- datetime,
2354
- basic
2355
- };
2356
2346
 
2357
- function alphanumeric(rowA, rowB, columnId) {
2347
+ const alphanumeric = (rowA, rowB, columnId) => {
2358
2348
  return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2359
- }
2349
+ };
2360
2350
 
2361
- function alphanumericCaseSensitive(rowA, rowB, columnId) {
2351
+ const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2362
2352
  return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2353
+ }; // The text filter is more basic (less numeric support)
2354
+ // but is much faster
2355
+
2356
+
2357
+ const text = (rowA, rowB, columnId) => {
2358
+ return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2359
+ }; // The text filter is more basic (less numeric support)
2360
+ // but is much faster
2361
+
2362
+
2363
+ const textCaseSensitive = (rowA, rowB, columnId) => {
2364
+ return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2365
+ };
2366
+
2367
+ const datetime = (rowA, rowB, columnId) => {
2368
+ return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2369
+ };
2370
+
2371
+ const basic = (rowA, rowB, columnId) => {
2372
+ return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2373
+ }; // Utils
2374
+
2375
+
2376
+ function compareBasic(a, b) {
2377
+ return a === b ? 0 : a > b ? 1 : -1;
2378
+ }
2379
+
2380
+ function toString(a) {
2381
+ if (typeof a === 'number') {
2382
+ if (isNaN(a) || a === Infinity || a === -Infinity) {
2383
+ return '';
2384
+ }
2385
+
2386
+ return String(a);
2387
+ }
2388
+
2389
+ if (typeof a === 'string') {
2390
+ return a;
2391
+ }
2392
+
2393
+ return '';
2363
2394
  } // Mixed sorting is slow, but very inclusive of many edge cases.
2364
2395
  // It handles numbers, mixed alphanumeric combinations, and even
2365
2396
  // null, undefined, and Infinity
@@ -2406,48 +2437,17 @@ function compareAlphanumeric(aStr, bStr) {
2406
2437
  }
2407
2438
 
2408
2439
  return a.length - b.length;
2409
- } // The text filter is more basic (less numeric support)
2410
- // but is much faster
2411
-
2412
-
2413
- function text(rowA, rowB, columnId) {
2414
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2415
- } // The text filter is more basic (less numeric support)
2416
- // but is much faster
2417
-
2418
-
2419
- function textCaseSensitive(rowA, rowB, columnId) {
2420
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2421
- }
2422
-
2423
- function datetime(rowA, rowB, columnId) {
2424
- return compareBasic(rowA.getValue(columnId).getTime(), rowB.getValue(columnId).getTime());
2425
- }
2426
-
2427
- function basic(rowA, rowB, columnId) {
2428
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2429
- } // Utils
2440
+ } // Exports
2430
2441
 
2431
2442
 
2432
- function compareBasic(a, b) {
2433
- return a === b ? 0 : a > b ? 1 : -1;
2434
- }
2435
-
2436
- function toString(a) {
2437
- if (typeof a === 'number') {
2438
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2439
- return '';
2440
- }
2441
-
2442
- return String(a);
2443
- }
2444
-
2445
- if (typeof a === 'string') {
2446
- return a;
2447
- }
2448
-
2449
- return '';
2450
- }
2443
+ const sortingFns = {
2444
+ alphanumeric,
2445
+ alphanumericCaseSensitive,
2446
+ text,
2447
+ textCaseSensitive,
2448
+ datetime,
2449
+ basic
2450
+ };
2451
2451
 
2452
2452
  //
2453
2453
  const Sorting = {
@@ -2671,11 +2671,6 @@ const Visibility = {
2671
2671
  onColumnVisibilityChange: makeStateUpdater('columnVisibility', instance)
2672
2672
  };
2673
2673
  },
2674
- getDefaultColumnDef: () => {
2675
- return {
2676
- defaultIsVisible: true
2677
- };
2678
- },
2679
2674
  createColumn: (column, instance) => {
2680
2675
  return {
2681
2676
  toggleVisibility: value => {
@@ -3661,25 +3656,17 @@ function getGroupedRowModel() {
3661
3656
  return row._valuesCache[columnId];
3662
3657
  }
3663
3658
 
3664
- if (row.groupingValuesCache.hasOwnProperty(columnId)) {
3665
- return row.groupingValuesCache[columnId];
3659
+ if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3660
+ return row._groupingValuesCache[columnId];
3666
3661
  } // Aggregate the values
3667
3662
 
3668
3663
 
3669
3664
  const column = instance.getColumn(columnId);
3670
- const aggregateFn = column.getColumnAggregationFn();
3665
+ const aggregateFn = column.getAggregationFn();
3671
3666
 
3672
3667
  if (aggregateFn) {
3673
- row.groupingValuesCache[columnId] = aggregateFn(() => leafRows.map(row => {
3674
- let columnValue = row.getValue(columnId);
3675
-
3676
- if (!depth && column.columnDef.aggregateValue) {
3677
- columnValue = column.columnDef.aggregateValue(columnValue);
3678
- }
3679
-
3680
- return columnValue;
3681
- }), () => groupedRows.map(row => row.getValue(columnId)));
3682
- return row.groupingValuesCache[columnId];
3668
+ row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3669
+ return row._groupingValuesCache[columnId];
3683
3670
  } else if (column.aggregationFn) {
3684
3671
  console.info({
3685
3672
  column
@@ -3759,7 +3746,7 @@ function getExpandedRowModel() {
3759
3746
  return rowModel;
3760
3747
  }
3761
3748
 
3762
- return expandRows(rowModel, instance);
3749
+ return expandRows(rowModel);
3763
3750
  }, {
3764
3751
  key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
3765
3752
  debug: () => {
@@ -3777,7 +3764,7 @@ function expandRows(rowModel, instance) {
3777
3764
 
3778
3765
  expandedRows.push(row);
3779
3766
 
3780
- if (instance.options.expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3767
+ if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
3781
3768
  row.subRows.forEach(handleRow);
3782
3769
  }
3783
3770
  };
@@ -3814,7 +3801,7 @@ function getPaginationRowModel(opts) {
3814
3801
  rows,
3815
3802
  flatRows,
3816
3803
  rowsById
3817
- }, instance);
3804
+ });
3818
3805
  }
3819
3806
 
3820
3807
  return {
@@ -4028,5 +4015,5 @@ function createTableInstance(table, options) {
4028
4015
  return instanceReadable;
4029
4016
  }
4030
4017
 
4031
- export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTable, 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, render, renderComponent, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
4018
+ export { ColumnSizing, Expanding, Filters, Grouping, Headers, Ordering, Pagination, Pinning, RowSelection, Sorting, Visibility, aggregationFns, buildHeaderGroups, createColumn, createRow, createTable, createTableFactory, createTableInstance, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, isFunction, isRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, render, renderComponent, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
4032
4019
  //# sourceMappingURL=index.js.map