@tanstack/react-table 8.0.0-alpha.9 → 8.0.0-beta.2
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/react-table/src/index.js +139 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3867 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3196 -4117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -813
- package/build/types/index.d.ts +16 -9
- package/build/umd/index.development.js +3234 -4125
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -6
- package/src/index.tsx +111 -9
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -122
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -318
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -239
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -414
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -232
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -629
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -193
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -526
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -315
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -174
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -44
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/cjs/utils.js +0 -167
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/createTable.d.ts +0 -42
- package/build/types/features/ColumnSizing.d.ts +0 -73
- package/build/types/features/Expanding.d.ts +0 -48
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -83
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -39
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -58
- package/build/types/features/Sorting.d.ts +0 -79
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -138
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/build/types/utils.d.ts +0 -23
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -186
- package/src/features/ColumnSizing.ts +0 -424
- package/src/features/Expanding.ts +0 -318
- package/src/features/Filters.ts +0 -560
- package/src/features/Grouping.ts +0 -361
- package/src/features/Headers.ts +0 -729
- package/src/features/Ordering.ts +0 -110
- package/src/features/Pagination.ts +0 -250
- package/src/features/Pinning.ts +0 -174
- package/src/features/RowSelection.ts +0 -651
- package/src/features/Sorting.ts +0 -453
- package/src/features/Visibility.ts +0 -238
- package/src/filterTypes.ts +0 -188
- package/src/sortTypes.ts +0 -147
- package/src/types.ts +0 -311
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "8.0.0-beta.2",
|
|
5
|
+
"description": "Headless UI for building powerful tables & datagrids for React.",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/tanstack/
|
|
7
|
+
"homepage": "https://github.com/tanstack/table#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/tanstack/
|
|
10
|
+
"url": "git+https://github.com/tanstack/table.git"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
24
24
|
},
|
|
25
25
|
"module": "build/esm/index.js",
|
|
26
|
-
"main": "build/cjs/index.js",
|
|
27
|
-
"browser": "build/umd/index.production.
|
|
26
|
+
"main": "build/cjs/react-table/src/index.js",
|
|
27
|
+
"browser": "build/umd/index.production.js",
|
|
28
28
|
"types": "build/types/index.d.ts",
|
|
29
|
+
"sideEffects": false,
|
|
29
30
|
"engines": {
|
|
30
31
|
"node": ">=12"
|
|
31
32
|
},
|
|
@@ -33,6 +34,9 @@
|
|
|
33
34
|
"build",
|
|
34
35
|
"src"
|
|
35
36
|
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@tanstack/table-core": "8.0.0-beta.2"
|
|
39
|
+
},
|
|
36
40
|
"peerDependencies": {
|
|
37
41
|
"react": ">=16",
|
|
38
42
|
"react-dom": ">=16"
|
package/src/index.tsx
CHANGED
|
@@ -1,9 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
export * from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
export * from '@tanstack/table-core'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
createTableInstance,
|
|
6
|
+
TableOptions,
|
|
7
|
+
TableInstance,
|
|
8
|
+
Table,
|
|
9
|
+
TableGenerics,
|
|
10
|
+
createTableFactory,
|
|
11
|
+
Overwrite,
|
|
12
|
+
PartialKeys,
|
|
13
|
+
TableOptionsResolved,
|
|
14
|
+
} from '@tanstack/table-core'
|
|
15
|
+
|
|
16
|
+
export type Renderable<TProps> =
|
|
17
|
+
| React.ReactNode
|
|
18
|
+
| React.FunctionComponent<TProps>
|
|
19
|
+
| React.Component<TProps>
|
|
20
|
+
|
|
21
|
+
export type Render = <TProps extends {}>(
|
|
22
|
+
Comp: Renderable<TProps>,
|
|
23
|
+
props: TProps
|
|
24
|
+
) => React.ReactNode | JSX.Element
|
|
25
|
+
|
|
26
|
+
export type ReactTableGenerics = Overwrite<
|
|
27
|
+
TableGenerics,
|
|
28
|
+
{ Renderer: Render; Rendered: ReturnType<Render> }
|
|
29
|
+
>
|
|
30
|
+
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
export const render: Render = (Comp, props) =>
|
|
34
|
+
!Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
|
|
35
|
+
|
|
36
|
+
function isReactComponent(component: unknown): component is React.FC {
|
|
37
|
+
return (
|
|
38
|
+
isClassComponent(component) ||
|
|
39
|
+
typeof component === 'function' ||
|
|
40
|
+
isExoticComponent(component)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isClassComponent(component: any) {
|
|
45
|
+
return (
|
|
46
|
+
typeof component === 'function' &&
|
|
47
|
+
(() => {
|
|
48
|
+
const proto = Object.getPrototypeOf(component)
|
|
49
|
+
return proto.prototype && proto.prototype.isReactComponent
|
|
50
|
+
})()
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isExoticComponent(component: any) {
|
|
55
|
+
return (
|
|
56
|
+
typeof component === 'object' &&
|
|
57
|
+
typeof component.$$typeof === 'symbol' &&
|
|
58
|
+
['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const createTable = createTableFactory({ render })
|
|
63
|
+
|
|
64
|
+
// const useIsomorphicLayoutEffect =
|
|
65
|
+
// typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
66
|
+
|
|
67
|
+
export type UseTableInstanceOptions<TGenerics extends ReactTableGenerics> =
|
|
68
|
+
TableOptions<TGenerics>
|
|
69
|
+
|
|
70
|
+
export function useTableInstance<TGenerics extends ReactTableGenerics>(
|
|
71
|
+
table: Table<TGenerics>,
|
|
72
|
+
options: UseTableInstanceOptions<TGenerics>
|
|
73
|
+
): TableInstance<TGenerics> {
|
|
74
|
+
// Compose in the generic options to the user options
|
|
75
|
+
const resolvedOptions: TableOptionsResolved<TGenerics> = {
|
|
76
|
+
...table.options,
|
|
77
|
+
state: {}, // Dummy state
|
|
78
|
+
onStateChange: () => {}, // noop
|
|
79
|
+
render,
|
|
80
|
+
...options,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Create a new table instance and store it in state
|
|
84
|
+
const [instanceRef] = React.useState(() => ({
|
|
85
|
+
current: createTableInstance<TGenerics>(resolvedOptions),
|
|
86
|
+
}))
|
|
87
|
+
|
|
88
|
+
// By default, manage table state here using the instance's initial state
|
|
89
|
+
const [state, setState] = React.useState(
|
|
90
|
+
() => instanceRef.current.initialState
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
// Compose the default state above with any user state. This will allow the user
|
|
94
|
+
// to only control a subset of the state if desired.
|
|
95
|
+
instanceRef.current.setOptions(prev => ({
|
|
96
|
+
...prev,
|
|
97
|
+
...options,
|
|
98
|
+
state: {
|
|
99
|
+
...state,
|
|
100
|
+
...options.state,
|
|
101
|
+
},
|
|
102
|
+
// Similarly, we'll maintain both our internal state and any user-provided
|
|
103
|
+
// state.
|
|
104
|
+
onStateChange: updater => {
|
|
105
|
+
setState(updater)
|
|
106
|
+
options.onStateChange?.(updater)
|
|
107
|
+
},
|
|
108
|
+
}))
|
|
109
|
+
|
|
110
|
+
return instanceRef.current
|
|
111
|
+
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-table
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
function _extends() {
|
|
16
|
-
_extends = Object.assign || function (target) {
|
|
17
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
-
var source = arguments[i];
|
|
19
|
-
|
|
20
|
-
for (var key in source) {
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
|
-
target[key] = source[key];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return _extends.apply(this, arguments);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
34
|
-
if (source == null) return {};
|
|
35
|
-
var target = {};
|
|
36
|
-
var sourceKeys = Object.keys(source);
|
|
37
|
-
var key, i;
|
|
38
|
-
|
|
39
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
40
|
-
key = sourceKeys[i];
|
|
41
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
42
|
-
target[key] = source[key];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return target;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
49
|
-
if (!o) return;
|
|
50
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
51
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
52
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
53
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
54
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function _arrayLikeToArray(arr, len) {
|
|
58
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
59
|
-
|
|
60
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
61
|
-
|
|
62
|
-
return arr2;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
66
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
67
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
68
|
-
|
|
69
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
70
|
-
if (it) o = it;
|
|
71
|
-
var i = 0;
|
|
72
|
-
return function () {
|
|
73
|
-
if (i >= o.length) return {
|
|
74
|
-
done: true
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
done: false,
|
|
78
|
-
value: o[i++]
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function _toPrimitive(input, hint) {
|
|
87
|
-
if (typeof input !== "object" || input === null) return input;
|
|
88
|
-
var prim = input[Symbol.toPrimitive];
|
|
89
|
-
|
|
90
|
-
if (prim !== undefined) {
|
|
91
|
-
var res = prim.call(input, hint || "default");
|
|
92
|
-
if (typeof res !== "object") return res;
|
|
93
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (hint === "string" ? String : Number)(input);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function _toPropertyKey(arg) {
|
|
100
|
-
var key = _toPrimitive(arg, "string");
|
|
101
|
-
|
|
102
|
-
return typeof key === "symbol" ? key : String(key);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.arrayLikeToArray = _arrayLikeToArray;
|
|
106
|
-
exports.createForOfIteratorHelperLoose = _createForOfIteratorHelperLoose;
|
|
107
|
-
exports["extends"] = _extends;
|
|
108
|
-
exports.objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose;
|
|
109
|
-
exports.toPrimitive = _toPrimitive;
|
|
110
|
-
exports.toPropertyKey = _toPropertyKey;
|
|
111
|
-
exports.unsupportedIterableToArray = _unsupportedIterableToArray;
|
|
112
|
-
//# sourceMappingURL=_rollupPluginBabelHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-table
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
16
|
-
|
|
17
|
-
var aggregationTypes = {
|
|
18
|
-
sum: sum,
|
|
19
|
-
min: min,
|
|
20
|
-
max: max,
|
|
21
|
-
extent: extent,
|
|
22
|
-
mean: mean,
|
|
23
|
-
median: median,
|
|
24
|
-
unique: unique,
|
|
25
|
-
uniqueCount: uniqueCount,
|
|
26
|
-
count: count
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function sum(_leafValues, childValues) {
|
|
30
|
-
// It's faster to just add the aggregations together instead of
|
|
31
|
-
// process leaf nodes individually
|
|
32
|
-
return childValues.reduce(function (sum, next) {
|
|
33
|
-
return sum + (typeof next === 'number' ? next : 0);
|
|
34
|
-
}, 0);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function min(_leafValues, childValues) {
|
|
38
|
-
var min;
|
|
39
|
-
|
|
40
|
-
for (var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelperLoose(childValues), _step; !(_step = _iterator()).done;) {
|
|
41
|
-
var value = _step.value;
|
|
42
|
-
|
|
43
|
-
if (value != null && (min > value || min === undefined && value >= value)) {
|
|
44
|
-
min = value;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return min;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function max(_leafValues, childValues) {
|
|
52
|
-
var max;
|
|
53
|
-
|
|
54
|
-
for (var _iterator2 = _rollupPluginBabelHelpers.createForOfIteratorHelperLoose(childValues), _step2; !(_step2 = _iterator2()).done;) {
|
|
55
|
-
var value = _step2.value;
|
|
56
|
-
|
|
57
|
-
if (value != null && (max < value || max === undefined && value >= value)) {
|
|
58
|
-
max = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return max;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function extent(_leafValues, childValues) {
|
|
66
|
-
var min;
|
|
67
|
-
var max;
|
|
68
|
-
|
|
69
|
-
for (var _iterator3 = _rollupPluginBabelHelpers.createForOfIteratorHelperLoose(childValues), _step3; !(_step3 = _iterator3()).done;) {
|
|
70
|
-
var value = _step3.value;
|
|
71
|
-
|
|
72
|
-
if (value != null) {
|
|
73
|
-
if (min === undefined) {
|
|
74
|
-
if (value >= value) min = max = value;
|
|
75
|
-
} else {
|
|
76
|
-
if (min > value) min = value;
|
|
77
|
-
if (max < value) max = value;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return [min, max];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function mean(leafValues) {
|
|
86
|
-
var count = 0;
|
|
87
|
-
var sum = 0;
|
|
88
|
-
|
|
89
|
-
for (var _iterator4 = _rollupPluginBabelHelpers.createForOfIteratorHelperLoose(leafValues), _step4; !(_step4 = _iterator4()).done;) {
|
|
90
|
-
var value = _step4.value;
|
|
91
|
-
|
|
92
|
-
if (value != null && (value = +value) >= value) {
|
|
93
|
-
++count, sum += value;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (count) return sum / count;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function median(values) {
|
|
102
|
-
if (!values.length) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
var min = 0;
|
|
107
|
-
var max = 0;
|
|
108
|
-
values.forEach(function (value) {
|
|
109
|
-
if (typeof value === 'number') {
|
|
110
|
-
min = Math.min(min, value);
|
|
111
|
-
max = Math.max(max, value);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return (min + max) / 2;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function unique(values) {
|
|
118
|
-
return Array.from(new Set(values).values());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function uniqueCount(values) {
|
|
122
|
-
return new Set(values).size;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function count(values) {
|
|
126
|
-
return values.length;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
exports.aggregationTypes = aggregationTypes;
|
|
130
|
-
//# sourceMappingURL=aggregationTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregationTypes.js","sources":["../../src/aggregationTypes.ts"],"sourcesContent":["export const aggregationTypes = {\n sum,\n min,\n max,\n extent,\n mean,\n median,\n unique,\n uniqueCount,\n count,\n}\n\nexport type BuiltInAggregationType = keyof typeof aggregationTypes\n\nfunction sum(_leafValues: unknown[], childValues: unknown[]) {\n // It's faster to just add the aggregations together instead of\n // process leaf nodes individually\n return childValues.reduce(\n (sum: number, next: unknown) => sum + (typeof next === 'number' ? next : 0),\n 0\n )\n}\n\nfunction min(_leafValues: unknown[], childValues: unknown[]) {\n let min: number | undefined\n\n for (const value of childValues as number[]) {\n if (\n value != null &&\n (min! > value || (min === undefined && value >= value))\n ) {\n min = value\n }\n }\n\n return min\n}\n\nfunction max(_leafValues: unknown[], childValues: unknown[]) {\n let max: number | undefined\n\n for (const value of childValues as number[]) {\n if (\n value != null &&\n (max! < value || (max === undefined && value >= value))\n ) {\n max = value\n }\n }\n\n return max\n}\n\nfunction extent(_leafValues: unknown[], childValues: unknown[]) {\n let min: number | undefined\n let max: number | undefined\n\n for (const value of childValues as number[]) {\n if (value != null) {\n if (min === undefined) {\n if (value >= value) min = max = value\n } else {\n if (min > value) min = value\n if (max! < value) max = value\n }\n }\n }\n\n return [min, max]\n}\n\nfunction mean(leafValues: unknown[]) {\n let count = 0\n let sum = 0\n\n for (let value of leafValues as number[]) {\n if (value != null && (value = +value) >= value) {\n ++count, (sum += value)\n }\n }\n\n if (count) return sum / count\n\n return\n}\n\nfunction median(values: unknown[]) {\n if (!values.length) {\n return\n }\n\n let min = 0\n let max = 0\n\n values.forEach(value => {\n if (typeof value === 'number') {\n min = Math.min(min, value)\n max = Math.max(max, value)\n }\n })\n\n return (min + max) / 2\n}\n\nfunction unique<T>(values: T[]) {\n return Array.from(new Set(values).values())\n}\n\nfunction uniqueCount(values: unknown[]) {\n return new Set(values).size\n}\n\nfunction count(values: unknown[]) {\n return values.length\n}\n"],"names":["aggregationTypes","sum","min","max","extent","mean","median","unique","uniqueCount","count","_leafValues","childValues","reduce","next","value","undefined","leafValues","values","length","forEach","Math","Array","from","Set","size"],"mappings":";;;;;;;;;;;;;;;;IAA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