@tanstack/react-table 0.0.1-alpha.0

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.
Files changed (49) hide show
  1. package/dist/react-table.development.js +3406 -0
  2. package/dist/react-table.development.js.map +1 -0
  3. package/dist/react-table.production.min.js +2 -0
  4. package/dist/react-table.production.min.js.map +1 -0
  5. package/lib/index.js +65 -0
  6. package/package.json +122 -0
  7. package/src/.DS_Store +0 -0
  8. package/src/aggregationTypes.ts +115 -0
  9. package/src/core.tsx +1194 -0
  10. package/src/createTable.tsx +181 -0
  11. package/src/features/Expanding.ts +388 -0
  12. package/src/features/Filters.ts +707 -0
  13. package/src/features/Grouping.ts +451 -0
  14. package/src/features/Headers.ts +907 -0
  15. package/src/features/Ordering.ts +134 -0
  16. package/src/features/Pinning.ts +213 -0
  17. package/src/features/Sorting.ts +487 -0
  18. package/src/features/Visibility.ts +281 -0
  19. package/src/features/notest/useAbsoluteLayout.test.js +152 -0
  20. package/src/features/notest/useBlockLayout.test.js +158 -0
  21. package/src/features/notest/useColumnOrder.test.js +186 -0
  22. package/src/features/notest/useExpanded.test.js +125 -0
  23. package/src/features/notest/useFilters.test.js +393 -0
  24. package/src/features/notest/useFiltersAndRowSelect.test.js +256 -0
  25. package/src/features/notest/useFlexLayout.test.js +152 -0
  26. package/src/features/notest/useGroupBy.test.js +259 -0
  27. package/src/features/notest/usePagination.test.js +231 -0
  28. package/src/features/notest/useResizeColumns.test.js +229 -0
  29. package/src/features/notest/useRowSelect.test.js +250 -0
  30. package/src/features/notest/useRowState.test.js +178 -0
  31. package/src/features/tests/Visibility.test.tsx +225 -0
  32. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +390 -0
  33. package/src/features/tests/withSorting.notest.tsx +341 -0
  34. package/src/features/withColumnResizing.ts +281 -0
  35. package/src/features/withPagination.ts +208 -0
  36. package/src/features/withRowSelection.ts +467 -0
  37. package/src/filterTypes.ts +251 -0
  38. package/src/index.tsx +7 -0
  39. package/src/sortTypes.ts +159 -0
  40. package/src/test-utils/makeTestData.ts +41 -0
  41. package/src/tests/__snapshots__/core.test.tsx.snap +148 -0
  42. package/src/tests/core.test.tsx +241 -0
  43. package/src/types.ts +285 -0
  44. package/src/utils/columnFilterRowsFn.ts +162 -0
  45. package/src/utils/expandRowsFn.ts +53 -0
  46. package/src/utils/globalFilterRowsFn.ts +129 -0
  47. package/src/utils/groupRowsFn.ts +196 -0
  48. package/src/utils/sortRowsFn.ts +115 -0
  49. package/src/utils.tsx +243 -0
package/lib/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _exportNames = {
5
+ createTable: true
6
+ };
7
+ exports.createTable = void 0;
8
+
9
+ var _types = require("./types");
10
+
11
+ Object.keys(_types).forEach(function (key) {
12
+ if (key === "default" || key === "__esModule") return;
13
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
+ if (key in exports && exports[key] === _types[key]) return;
15
+ exports[key] = _types[key];
16
+ });
17
+
18
+ var _columnFilterRowsFn = require("./utils/columnFilterRowsFn");
19
+
20
+ Object.keys(_columnFilterRowsFn).forEach(function (key) {
21
+ if (key === "default" || key === "__esModule") return;
22
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
23
+ if (key in exports && exports[key] === _columnFilterRowsFn[key]) return;
24
+ exports[key] = _columnFilterRowsFn[key];
25
+ });
26
+
27
+ var _globalFilterRowsFn = require("./utils/globalFilterRowsFn");
28
+
29
+ Object.keys(_globalFilterRowsFn).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
32
+ if (key in exports && exports[key] === _globalFilterRowsFn[key]) return;
33
+ exports[key] = _globalFilterRowsFn[key];
34
+ });
35
+
36
+ var _sortRowsFn = require("./utils/sortRowsFn");
37
+
38
+ Object.keys(_sortRowsFn).forEach(function (key) {
39
+ if (key === "default" || key === "__esModule") return;
40
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
41
+ if (key in exports && exports[key] === _sortRowsFn[key]) return;
42
+ exports[key] = _sortRowsFn[key];
43
+ });
44
+
45
+ var _groupRowsFn = require("./utils/groupRowsFn");
46
+
47
+ Object.keys(_groupRowsFn).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ if (key in exports && exports[key] === _groupRowsFn[key]) return;
51
+ exports[key] = _groupRowsFn[key];
52
+ });
53
+
54
+ var _expandRowsFn = require("./utils/expandRowsFn");
55
+
56
+ Object.keys(_expandRowsFn).forEach(function (key) {
57
+ if (key === "default" || key === "__esModule") return;
58
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
59
+ if (key in exports && exports[key] === _expandRowsFn[key]) return;
60
+ exports[key] = _expandRowsFn[key];
61
+ });
62
+
63
+ var _createTable = require("./createTable");
64
+
65
+ exports.createTable = _createTable.createTable;
package/package.json ADDED
@@ -0,0 +1,122 @@
1
+ {
2
+ "name": "@tanstack/react-table",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Hooks for building lightweight, fast and extendable datagrids for React",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/tannerlinsley/react-table#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/tannerlinsley/react-table.git"
10
+ },
11
+ "keywords": [
12
+ "react",
13
+ "table",
14
+ "react-table",
15
+ "datagrid"
16
+ ],
17
+ "funding": {
18
+ "type": "github",
19
+ "url": "https://github.com/sponsors/tannerlinsley"
20
+ },
21
+ "main": "lib/index.js",
22
+ "module": "es/index.js",
23
+ "typings": "types/index.d.ts",
24
+ "scripts": {
25
+ "test": "(is-ci && yarn test:ci) || yarn test:dev",
26
+ "test:dev": "jest --watch",
27
+ "test:ci": "jest",
28
+ "test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
29
+ "build": "yarn format && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:types",
30
+ "build:commonjs": "rimraf ./lib && cross-env BABEL_ENV=commonjs babel --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir lib",
31
+ "build:es": "rimraf ./es && babel --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir es",
32
+ "build:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json",
33
+ "build:types": "rimraf ./types && tsc --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r --silent && replace 'export type' 'export' ./types -r --silent",
34
+ "watch": "yarn watch:commonjs & yarn watch:es & yarn watch:umd & yarn watch:types",
35
+ "watch:commonjs": "rimraf ./lib && cross-env BABEL_ENV=commonjs babel --watch --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir lib",
36
+ "watch:es": "rimraf ./es && babel --watch --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir es",
37
+ "watch:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -w -c && rollup-plugin-visualizer stats-react.json",
38
+ "watch:types": "rimraf ./types && tsc --watch --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r --silent && replace 'export type' 'export' ./types -r --silent",
39
+ "now-build": "yarn && cd www && yarn && yarn build",
40
+ "prettier": "prettier \"{.,src,src/**,example/src,example/src/**}/*.{md,js,jsx,ts,tsx,json}\"",
41
+ "start": "yarn watch",
42
+ "format": "yarn prettier --write",
43
+ "stats": "open ./stats.html",
44
+ "doctoc": "doctoc README.md"
45
+ },
46
+ "engines": {
47
+ "node": ">=12"
48
+ },
49
+ "release": {
50
+ "branches": [
51
+ "master",
52
+ {
53
+ "name": "beta",
54
+ "prerelease": true
55
+ }
56
+ ]
57
+ },
58
+ "files": [
59
+ "dist",
60
+ "src"
61
+ ],
62
+ "browserslist": [
63
+ "last 2 versions",
64
+ "> 0.2%"
65
+ ],
66
+ "peerDependencies": {
67
+ "react": ">=16",
68
+ "react-dom": ">=16"
69
+ },
70
+ "dependencies": {
71
+ "ts-toolbelt": "^9.6.0"
72
+ },
73
+ "devDependencies": {
74
+ "@babel/cli": "^7.15.7",
75
+ "@babel/core": "^7.15.8",
76
+ "@babel/plugin-transform-runtime": "^7.15.8",
77
+ "@babel/preset-env": "^7.15.8",
78
+ "@babel/preset-react": "^7.14.5",
79
+ "@babel/preset-typescript": "^7.15.0",
80
+ "@rollup/plugin-replace": "^3.0.0",
81
+ "@testing-library/jest-dom": "^5.14.1",
82
+ "@testing-library/react": "^12.1.2",
83
+ "@testing-library/react-hooks": "^7.0.2",
84
+ "@types/react": "^17.0.27",
85
+ "@types/react-dom": "^17.0.9",
86
+ "@types/semver": "^7.3.9",
87
+ "babel-plugin-const-enum": "^1.1.0",
88
+ "babel-plugin-dev-expression": "^0.2.2",
89
+ "babel-plugin-transform-async-to-promises": "^0.8.15",
90
+ "conventional-changelog-angular": "^5.0.13",
91
+ "cross-env": "^7.0.3",
92
+ "current-git-branch": "^1.1.0",
93
+ "doctoc": "^2.1.0",
94
+ "fast-async": "^6.3.8",
95
+ "git-log-parser": "^1.2.0",
96
+ "is-ci": "^3.0.0",
97
+ "jest": "^27.4.5",
98
+ "jsonfile": "^6.1.0",
99
+ "lerna": "^4.0.0",
100
+ "prettier": "^2.4.1",
101
+ "prompt-confirm": "^2.0.4",
102
+ "react": "^17.0.2",
103
+ "react-dom": "^17.0.2",
104
+ "react-test-renderer": "^17.0.2",
105
+ "replace": "^1.2.1",
106
+ "rimraf": "^3.0.2",
107
+ "rollup": "^2.16.1",
108
+ "rollup-plugin-babel": "^4.4.0",
109
+ "rollup-plugin-commonjs": "^10.1.0",
110
+ "rollup-plugin-jscc": "^1.0.0",
111
+ "rollup-plugin-node-resolve": "^5.2.0",
112
+ "rollup-plugin-peer-deps-external": "^2.2.2",
113
+ "rollup-plugin-prettier": "^2.1.0",
114
+ "rollup-plugin-size": "^0.2.2",
115
+ "rollup-plugin-terser": "^7.0.2",
116
+ "rollup-plugin-visualizer": "^5.5.2",
117
+ "stream-to-array": "^2.3.0",
118
+ "ts-node": "^10.3.0",
119
+ "tslib": "^2.3.1",
120
+ "typescript": "^4.4.3"
121
+ }
122
+ }
package/src/.DS_Store ADDED
Binary file
@@ -0,0 +1,115 @@
1
+ export const aggregationTypes = {
2
+ sum,
3
+ min,
4
+ max,
5
+ extent,
6
+ mean,
7
+ median,
8
+ unique,
9
+ uniqueCount,
10
+ count,
11
+ }
12
+
13
+ export type BuiltInAggregationType = keyof typeof aggregationTypes
14
+
15
+ function sum(_leafValues: unknown[], childValues: unknown[]) {
16
+ // It's faster to just add the aggregations together instead of
17
+ // process leaf nodes individually
18
+ return childValues.reduce(
19
+ (sum: number, next: unknown) => sum + (typeof next === 'number' ? next : 0),
20
+ 0
21
+ )
22
+ }
23
+
24
+ function min(_leafValues: unknown[], childValues: unknown[]) {
25
+ let min: number | undefined
26
+
27
+ for (const value of childValues as number[]) {
28
+ if (
29
+ value != null &&
30
+ (min! > value || (min === undefined && value >= value))
31
+ ) {
32
+ min = value
33
+ }
34
+ }
35
+
36
+ return min
37
+ }
38
+
39
+ function max(_leafValues: unknown[], childValues: unknown[]) {
40
+ let max: number | undefined
41
+
42
+ for (const value of childValues as number[]) {
43
+ if (
44
+ value != null &&
45
+ (max! < value || (max === undefined && value >= value))
46
+ ) {
47
+ max = value
48
+ }
49
+ }
50
+
51
+ return max
52
+ }
53
+
54
+ function extent(_leafValues: unknown[], childValues: unknown[]) {
55
+ let min: number | undefined
56
+ let max: number | undefined
57
+
58
+ for (const value of childValues as number[]) {
59
+ if (value != null) {
60
+ if (min === undefined) {
61
+ if (value >= value) min = max = value
62
+ } else {
63
+ if (min > value) min = value
64
+ if (max! < value) max = value
65
+ }
66
+ }
67
+ }
68
+
69
+ return [min, max]
70
+ }
71
+
72
+ function mean(leafValues: unknown[]) {
73
+ let count = 0
74
+ let sum = 0
75
+
76
+ for (let value of leafValues as number[]) {
77
+ if (value != null && (value = +value) >= value) {
78
+ ++count, (sum += value)
79
+ }
80
+ }
81
+
82
+ if (count) return sum / count
83
+
84
+ return
85
+ }
86
+
87
+ function median(values: unknown[]) {
88
+ if (!values.length) {
89
+ return
90
+ }
91
+
92
+ let min = 0
93
+ let max = 0
94
+
95
+ values.forEach(value => {
96
+ if (typeof value === 'number') {
97
+ min = Math.min(min, value)
98
+ max = Math.max(max, value)
99
+ }
100
+ })
101
+
102
+ return (min + max) / 2
103
+ }
104
+
105
+ function unique<T>(values: T[]) {
106
+ return Array.from(new Set(values).values())
107
+ }
108
+
109
+ function uniqueCount(values: unknown[]) {
110
+ return new Set(values).size
111
+ }
112
+
113
+ function count(values: unknown[]) {
114
+ return values.length
115
+ }