@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.
- package/build/cjs/aggregationFns.js +50 -51
- package/build/cjs/aggregationFns.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -2
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +5 -5
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +5 -13
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/esm/index.js +62 -71
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +314 -314
- package/build/types/aggregationFns.d.ts +10 -19
- package/build/types/features/Filters.d.ts +0 -2
- package/build/types/features/Grouping.d.ts +6 -8
- package/build/umd/index.development.js +61 -71
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/aggregationFns.ts +44 -40
- package/src/features/Filters.ts +0 -5
- package/src/features/Grouping.ts +15 -18
- package/src/utils/getGroupedRowModel.ts +8 -17
|
@@ -1,22 +1,13 @@
|
|
|
1
|
+
import { AggregationFn } from './features/Grouping';
|
|
1
2
|
export declare const aggregationFns: {
|
|
2
|
-
sum:
|
|
3
|
-
min:
|
|
4
|
-
max:
|
|
5
|
-
extent:
|
|
6
|
-
mean:
|
|
7
|
-
median:
|
|
8
|
-
unique:
|
|
9
|
-
uniqueCount:
|
|
10
|
-
count:
|
|
3
|
+
sum: AggregationFn<any>;
|
|
4
|
+
min: AggregationFn<any>;
|
|
5
|
+
max: AggregationFn<any>;
|
|
6
|
+
extent: AggregationFn<any>;
|
|
7
|
+
mean: AggregationFn<any>;
|
|
8
|
+
median: AggregationFn<any>;
|
|
9
|
+
unique: AggregationFn<any>;
|
|
10
|
+
uniqueCount: AggregationFn<any>;
|
|
11
|
+
count: AggregationFn<any>;
|
|
11
12
|
};
|
|
12
13
|
export declare type BuiltInAggregationFn = keyof typeof aggregationFns;
|
|
13
|
-
declare function sum(_getLeafValues: () => unknown[], getChildValues: () => unknown[]): number;
|
|
14
|
-
declare function min(_getLeafValues: () => unknown[], getChildValues: () => unknown[]): number | undefined;
|
|
15
|
-
declare function max(_getLeafValues: () => unknown[], getChildValues: () => unknown[]): number | undefined;
|
|
16
|
-
declare function extent(_getLeafValues: () => unknown[], getChildValues: () => unknown[]): (number | undefined)[];
|
|
17
|
-
export declare function mean(getLeafValues: () => unknown[]): number | undefined;
|
|
18
|
-
declare function median(getLeafValues: () => unknown[]): number | undefined;
|
|
19
|
-
declare function unique<T>(getLeafValues: () => T[]): T[];
|
|
20
|
-
declare function uniqueCount(getLeafValues: () => unknown[]): number;
|
|
21
|
-
declare function count(getLeafValues: () => unknown[]): number;
|
|
22
|
-
export {};
|
|
@@ -32,7 +32,6 @@ export declare type FiltersColumnDef<TGenerics extends TableGenerics> = {
|
|
|
32
32
|
}>>;
|
|
33
33
|
enableColumnFilter?: boolean;
|
|
34
34
|
enableGlobalFilter?: boolean;
|
|
35
|
-
enableFaceting?: boolean;
|
|
36
35
|
};
|
|
37
36
|
export declare type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
38
37
|
filterFn: FilterFnOption<Overwrite<TGenerics, {
|
|
@@ -56,7 +55,6 @@ export declare type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
|
56
55
|
export declare type FiltersRow<TGenerics extends TableGenerics> = {
|
|
57
56
|
columnFilters: Record<string, boolean>;
|
|
58
57
|
columnFiltersMeta: Record<string, TGenerics['FilterMeta']>;
|
|
59
|
-
subRowsByFacetId: Record<string, Row<TGenerics>[]>;
|
|
60
58
|
};
|
|
61
59
|
export declare type FiltersOptions<TGenerics extends TableGenerics> = {
|
|
62
60
|
enableFilters?: boolean;
|
|
@@ -4,17 +4,16 @@ import { TableFeature } from '../core/instance';
|
|
|
4
4
|
import { Cell, Column, OnChangeFn, TableInstance, Row, Updater, Renderable, TableGenerics } from '../types';
|
|
5
5
|
import { Overwrite } from '../utils';
|
|
6
6
|
export declare type GroupingState = string[];
|
|
7
|
-
export declare type AggregationFn<TGenerics extends TableGenerics> = (getLeafValues: () => TGenerics['Value'][], getChildValues: () => TGenerics['Value'][]) => any;
|
|
8
|
-
export declare type CustomAggregationFns<TGenerics extends TableGenerics> = Record<string, AggregationFn<TGenerics>>;
|
|
9
|
-
export declare type AggregationFnOption<TGenerics extends TableGenerics> = 'auto' | BuiltInAggregationFn | keyof TGenerics['AggregationFns'] | AggregationFn<TGenerics>;
|
|
10
7
|
export declare type GroupingTableState = {
|
|
11
8
|
grouping: GroupingState;
|
|
12
9
|
};
|
|
10
|
+
export declare type AggregationFn<TGenerics extends TableGenerics> = (columnId: string, leafRows: Row<TGenerics>[], childRows: Row<TGenerics>[]) => any;
|
|
11
|
+
export declare type CustomAggregationFns<TGenerics extends TableGenerics> = Record<string, AggregationFn<TGenerics>>;
|
|
12
|
+
export declare type AggregationFnOption<TGenerics extends TableGenerics> = 'auto' | BuiltInAggregationFn | keyof TGenerics['AggregationFns'] | AggregationFn<TGenerics>;
|
|
13
13
|
export declare type GroupingColumnDef<TGenerics extends TableGenerics> = {
|
|
14
14
|
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, {
|
|
15
15
|
Value: any;
|
|
16
16
|
}>>;
|
|
17
|
-
aggregateValue?: (columnValue: unknown) => any;
|
|
18
17
|
aggregatedCell?: Renderable<TGenerics, {
|
|
19
18
|
instance: TableInstance<TGenerics>;
|
|
20
19
|
row: Row<TGenerics>;
|
|
@@ -33,14 +32,14 @@ export declare type GroupingColumn<TGenerics extends TableGenerics> = {
|
|
|
33
32
|
getGroupedIndex: () => number;
|
|
34
33
|
toggleGrouping: () => void;
|
|
35
34
|
getToggleGroupingHandler: () => () => void;
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
getAutoAggregationFn: () => AggregationFn<TGenerics> | undefined;
|
|
36
|
+
getAggregationFn: () => AggregationFn<TGenerics> | undefined;
|
|
38
37
|
};
|
|
39
38
|
export declare type GroupingRow = {
|
|
40
39
|
groupingColumnId?: string;
|
|
41
40
|
groupingValue?: any;
|
|
42
41
|
getIsGrouped: () => boolean;
|
|
43
|
-
|
|
42
|
+
_groupingValuesCache: Record<string, any>;
|
|
44
43
|
};
|
|
45
44
|
export declare type GroupingCell<TGenerics extends TableGenerics> = {
|
|
46
45
|
getIsGrouped: () => boolean;
|
|
@@ -57,7 +56,6 @@ export declare type GroupingOptions<TGenerics extends TableGenerics> = {
|
|
|
57
56
|
aggregationFns?: TGenerics['AggregationFns'];
|
|
58
57
|
onGroupingChange?: OnChangeFn<GroupingState>;
|
|
59
58
|
enableGrouping?: boolean;
|
|
60
|
-
enableGroupingRemoval?: boolean;
|
|
61
59
|
getGroupedRowModel?: (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics>;
|
|
62
60
|
groupedColumnMode?: false | 'reorder' | 'remove';
|
|
63
61
|
};
|
|
@@ -1216,8 +1216,7 @@
|
|
|
1216
1216
|
createRow: (row, instance) => {
|
|
1217
1217
|
return {
|
|
1218
1218
|
columnFilters: {},
|
|
1219
|
-
columnFiltersMeta: {}
|
|
1220
|
-
subRowsByFacetId: {}
|
|
1219
|
+
columnFiltersMeta: {}
|
|
1221
1220
|
};
|
|
1222
1221
|
},
|
|
1223
1222
|
createInstance: instance => {
|
|
@@ -1308,53 +1307,42 @@
|
|
|
1308
1307
|
return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
|
|
1309
1308
|
}
|
|
1310
1309
|
|
|
1311
|
-
const
|
|
1312
|
-
sum,
|
|
1313
|
-
min,
|
|
1314
|
-
max,
|
|
1315
|
-
extent,
|
|
1316
|
-
mean,
|
|
1317
|
-
median,
|
|
1318
|
-
unique,
|
|
1319
|
-
uniqueCount,
|
|
1320
|
-
count
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
function sum(_getLeafValues, getChildValues) {
|
|
1310
|
+
const sum = (columnId, _leafRows, childRows) => {
|
|
1324
1311
|
// It's faster to just add the aggregations together instead of
|
|
1325
1312
|
// process leaf nodes individually
|
|
1326
|
-
return
|
|
1327
|
-
}
|
|
1313
|
+
return childRows.reduce((sum, next) => sum + (typeof next === 'number' ? next : 0), 0);
|
|
1314
|
+
};
|
|
1328
1315
|
|
|
1329
|
-
|
|
1316
|
+
const min = (columnId, _leafRows, childRows) => {
|
|
1330
1317
|
let min;
|
|
1318
|
+
childRows.forEach(row => {
|
|
1319
|
+
const value = row.getValue(columnId);
|
|
1331
1320
|
|
|
1332
|
-
for (const value of getChildValues()) {
|
|
1333
1321
|
if (value != null && (min > value || min === undefined && value >= value)) {
|
|
1334
1322
|
min = value;
|
|
1335
1323
|
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1324
|
+
});
|
|
1338
1325
|
return min;
|
|
1339
|
-
}
|
|
1326
|
+
};
|
|
1340
1327
|
|
|
1341
|
-
|
|
1328
|
+
const max = (columnId, _leafRows, childRows) => {
|
|
1342
1329
|
let max;
|
|
1330
|
+
childRows.forEach(row => {
|
|
1331
|
+
const value = row.getValue(columnId);
|
|
1343
1332
|
|
|
1344
|
-
for (const value of getChildValues()) {
|
|
1345
1333
|
if (value != null && (max < value || max === undefined && value >= value)) {
|
|
1346
1334
|
max = value;
|
|
1347
1335
|
}
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1336
|
+
});
|
|
1350
1337
|
return max;
|
|
1351
|
-
}
|
|
1338
|
+
};
|
|
1352
1339
|
|
|
1353
|
-
|
|
1340
|
+
const extent = (columnId, _leafRows, childRows) => {
|
|
1354
1341
|
let min;
|
|
1355
1342
|
let max;
|
|
1343
|
+
childRows.forEach(row => {
|
|
1344
|
+
const value = row.getValue(columnId);
|
|
1356
1345
|
|
|
1357
|
-
for (const value of getChildValues()) {
|
|
1358
1346
|
if (value != null) {
|
|
1359
1347
|
if (min === undefined) {
|
|
1360
1348
|
if (value >= value) min = max = value;
|
|
@@ -1363,54 +1351,65 @@
|
|
|
1363
1351
|
if (max < value) max = value;
|
|
1364
1352
|
}
|
|
1365
1353
|
}
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1354
|
+
});
|
|
1368
1355
|
return [min, max];
|
|
1369
|
-
}
|
|
1356
|
+
};
|
|
1370
1357
|
|
|
1371
|
-
|
|
1358
|
+
const mean = (columnId, leafRows) => {
|
|
1372
1359
|
let count = 0;
|
|
1373
1360
|
let sum = 0;
|
|
1361
|
+
leafRows.forEach(row => {
|
|
1362
|
+
let value = row.getValue(columnId);
|
|
1374
1363
|
|
|
1375
|
-
for (let value of getLeafValues()) {
|
|
1376
1364
|
if (value != null && (value = +value) >= value) {
|
|
1377
1365
|
++count, sum += value;
|
|
1378
1366
|
}
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1367
|
+
});
|
|
1381
1368
|
if (count) return sum / count;
|
|
1382
1369
|
return;
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
function median(getLeafValues) {
|
|
1386
|
-
const leafValues = getLeafValues();
|
|
1370
|
+
};
|
|
1387
1371
|
|
|
1388
|
-
|
|
1372
|
+
const median = (columnId, leafRows) => {
|
|
1373
|
+
if (!leafRows.length) {
|
|
1389
1374
|
return;
|
|
1390
1375
|
}
|
|
1391
1376
|
|
|
1392
1377
|
let min = 0;
|
|
1393
1378
|
let max = 0;
|
|
1394
|
-
|
|
1379
|
+
leafRows.forEach(row => {
|
|
1380
|
+
let value = row.getValue(columnId);
|
|
1381
|
+
|
|
1395
1382
|
if (typeof value === 'number') {
|
|
1396
1383
|
min = Math.min(min, value);
|
|
1397
1384
|
max = Math.max(max, value);
|
|
1398
1385
|
}
|
|
1399
1386
|
});
|
|
1400
1387
|
return (min + max) / 2;
|
|
1401
|
-
}
|
|
1388
|
+
};
|
|
1402
1389
|
|
|
1403
|
-
|
|
1404
|
-
return Array.from(new Set(
|
|
1405
|
-
}
|
|
1390
|
+
const unique = (columnId, leafRows) => {
|
|
1391
|
+
return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
|
|
1392
|
+
};
|
|
1406
1393
|
|
|
1407
|
-
|
|
1408
|
-
return new Set(
|
|
1409
|
-
}
|
|
1394
|
+
const uniqueCount = (columnId, leafRows) => {
|
|
1395
|
+
return new Set(leafRows.map(d => d.getValue(columnId))).size;
|
|
1396
|
+
};
|
|
1410
1397
|
|
|
1411
|
-
|
|
1412
|
-
return
|
|
1413
|
-
}
|
|
1398
|
+
const count = (_columnId, leafRows) => {
|
|
1399
|
+
return leafRows.length;
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
const aggregationFns = {
|
|
1403
|
+
sum,
|
|
1404
|
+
min,
|
|
1405
|
+
max,
|
|
1406
|
+
extent,
|
|
1407
|
+
mean,
|
|
1408
|
+
median,
|
|
1409
|
+
unique,
|
|
1410
|
+
uniqueCount,
|
|
1411
|
+
count
|
|
1412
|
+
};
|
|
1414
1413
|
|
|
1415
1414
|
//
|
|
1416
1415
|
const Grouping = {
|
|
@@ -1465,7 +1464,7 @@
|
|
|
1465
1464
|
column.toggleGrouping();
|
|
1466
1465
|
};
|
|
1467
1466
|
},
|
|
1468
|
-
|
|
1467
|
+
getAutoAggregationFn: () => {
|
|
1469
1468
|
const firstRow = instance.getCoreRowModel().flatRows[0];
|
|
1470
1469
|
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
1471
1470
|
|
|
@@ -1479,7 +1478,7 @@
|
|
|
1479
1478
|
|
|
1480
1479
|
return aggregationFns.count;
|
|
1481
1480
|
},
|
|
1482
|
-
|
|
1481
|
+
getAggregationFn: () => {
|
|
1483
1482
|
var _ref4;
|
|
1484
1483
|
|
|
1485
1484
|
const userAggregationFns = instance.options.aggregationFns;
|
|
@@ -1488,7 +1487,7 @@
|
|
|
1488
1487
|
throw new Error();
|
|
1489
1488
|
}
|
|
1490
1489
|
|
|
1491
|
-
return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.
|
|
1490
|
+
return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
|
|
1492
1491
|
}
|
|
1493
1492
|
};
|
|
1494
1493
|
},
|
|
@@ -1514,10 +1513,10 @@
|
|
|
1514
1513
|
}
|
|
1515
1514
|
};
|
|
1516
1515
|
},
|
|
1517
|
-
createRow:
|
|
1516
|
+
createRow: row => {
|
|
1518
1517
|
return {
|
|
1519
1518
|
getIsGrouped: () => !!row.groupingColumnId,
|
|
1520
|
-
|
|
1519
|
+
_groupingValuesCache: {}
|
|
1521
1520
|
};
|
|
1522
1521
|
},
|
|
1523
1522
|
createCell: (cell, column, row, instance) => {
|
|
@@ -3650,25 +3649,17 @@
|
|
|
3650
3649
|
return row._valuesCache[columnId];
|
|
3651
3650
|
}
|
|
3652
3651
|
|
|
3653
|
-
if (row.
|
|
3654
|
-
return row.
|
|
3652
|
+
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
|
|
3653
|
+
return row._groupingValuesCache[columnId];
|
|
3655
3654
|
} // Aggregate the values
|
|
3656
3655
|
|
|
3657
3656
|
|
|
3658
3657
|
const column = instance.getColumn(columnId);
|
|
3659
|
-
const aggregateFn = column.
|
|
3658
|
+
const aggregateFn = column.getAggregationFn();
|
|
3660
3659
|
|
|
3661
3660
|
if (aggregateFn) {
|
|
3662
|
-
row.
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
if (!depth && column.columnDef.aggregateValue) {
|
|
3666
|
-
columnValue = column.columnDef.aggregateValue(columnValue);
|
|
3667
|
-
}
|
|
3668
|
-
|
|
3669
|
-
return columnValue;
|
|
3670
|
-
}), () => groupedRows.map(row => row.getValue(columnId)));
|
|
3671
|
-
return row.groupingValuesCache[columnId];
|
|
3661
|
+
row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
|
|
3662
|
+
return row._groupingValuesCache[columnId];
|
|
3672
3663
|
} else if (column.aggregationFn) {
|
|
3673
3664
|
console.info({
|
|
3674
3665
|
column
|
|
@@ -3855,7 +3846,6 @@
|
|
|
3855
3846
|
exports.isFunction = isFunction;
|
|
3856
3847
|
exports.isRowSelected = isRowSelected;
|
|
3857
3848
|
exports.makeStateUpdater = makeStateUpdater;
|
|
3858
|
-
exports.mean = mean;
|
|
3859
3849
|
exports.memo = memo;
|
|
3860
3850
|
exports.noop = noop;
|
|
3861
3851
|
exports.orderColumns = orderColumns;
|