@tanstack/react-table 8.0.0-alpha.2 → 8.0.0-alpha.22

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 (99) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +96 -12
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +40 -3663
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -676
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +50 -3665
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +104 -7
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -519
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -103
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -331
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -234
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -396
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -228
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -486
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -83
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pinning.js +0 -163
  35. package/build/cjs/features/Pinning.js.map +0 -1
  36. package/build/cjs/features/Sorting.js +0 -269
  37. package/build/cjs/features/Sorting.js.map +0 -1
  38. package/build/cjs/features/Visibility.js +0 -160
  39. package/build/cjs/features/Visibility.js.map +0 -1
  40. package/build/cjs/filterTypes.js +0 -172
  41. package/build/cjs/filterTypes.js.map +0 -1
  42. package/build/cjs/sortTypes.js +0 -121
  43. package/build/cjs/sortTypes.js.map +0 -1
  44. package/build/cjs/utils/columnFilterRowsFn.js +0 -130
  45. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  46. package/build/cjs/utils/expandRowsFn.js +0 -38
  47. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  48. package/build/cjs/utils/globalFilterRowsFn.js +0 -100
  49. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/groupRowsFn.js +0 -154
  51. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  52. package/build/cjs/utils/sortRowsFn.js +0 -93
  53. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  54. package/build/cjs/utils.js +0 -143
  55. package/build/cjs/utils.js.map +0 -1
  56. package/build/types/aggregationTypes.d.ts +0 -22
  57. package/build/types/core.d.ts +0 -126
  58. package/build/types/createTable.d.ts +0 -35
  59. package/build/types/features/ColumnSizing.d.ts +0 -73
  60. package/build/types/features/Expanding.d.ts +0 -52
  61. package/build/types/features/Filters.d.ts +0 -93
  62. package/build/types/features/Grouping.d.ts +0 -82
  63. package/build/types/features/Headers.d.ts +0 -41
  64. package/build/types/features/Ordering.d.ts +0 -19
  65. package/build/types/features/Pinning.d.ts +0 -39
  66. package/build/types/features/Sorting.d.ts +0 -75
  67. package/build/types/features/Visibility.d.ts +0 -47
  68. package/build/types/filterTypes.d.ts +0 -50
  69. package/build/types/sortTypes.d.ts +0 -17
  70. package/build/types/types.d.ts +0 -124
  71. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  72. package/build/types/utils/expandRowsFn.d.ts +0 -2
  73. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  74. package/build/types/utils/groupRowsFn.d.ts +0 -2
  75. package/build/types/utils/sortRowsFn.d.ts +0 -2
  76. package/build/types/utils.d.ts +0 -24
  77. package/src/aggregationTypes.ts +0 -115
  78. package/src/core.tsx +0 -1232
  79. package/src/createTable.tsx +0 -181
  80. package/src/features/ColumnSizing.ts +0 -482
  81. package/src/features/Expanding.ts +0 -388
  82. package/src/features/Filters.ts +0 -707
  83. package/src/features/Grouping.ts +0 -451
  84. package/src/features/Headers.ts +0 -944
  85. package/src/features/Ordering.ts +0 -134
  86. package/src/features/Pinning.ts +0 -213
  87. package/src/features/Sorting.ts +0 -487
  88. package/src/features/Visibility.ts +0 -281
  89. package/src/features/withPagination.oldts +0 -208
  90. package/src/features/withRowSelection.oldts +0 -467
  91. package/src/filterTypes.ts +0 -251
  92. package/src/sortTypes.ts +0 -159
  93. package/src/types.ts +0 -314
  94. package/src/utils/columnFilterRowsFn.ts +0 -162
  95. package/src/utils/expandRowsFn.ts +0 -53
  96. package/src/utils/globalFilterRowsFn.ts +0 -129
  97. package/src/utils/groupRowsFn.ts +0 -196
  98. package/src/utils/sortRowsFn.ts +0 -115
  99. package/src/utils.tsx +0 -249
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.2",
4
+ "version": "8.0.0-alpha.22",
5
5
  "description": "Hooks for building lightweight, fast and extendable datagrids for React",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/react-table#readme",
@@ -33,6 +33,9 @@
33
33
  "build",
34
34
  "src"
35
35
  ],
36
+ "dependencies": {
37
+ "@tanstack/table-core": "8.0.0-alpha.22"
38
+ },
36
39
  "peerDependencies": {
37
40
  "react": ">=16",
38
41
  "react-dom": ">=16"
package/src/index.tsx CHANGED
@@ -1,7 +1,104 @@
1
- export * from './types'
2
- export * from './utils/columnFilterRowsFn'
3
- export * from './utils/globalFilterRowsFn'
4
- export * from './utils/sortRowsFn'
5
- export * from './utils/groupRowsFn'
6
- export * from './utils/expandRowsFn'
7
- export { createTable } from './createTable'
1
+ import * as React from 'react'
2
+ export * from '@tanstack/table-core'
3
+
4
+ import {
5
+ createTableInstance,
6
+ PartialKeys,
7
+ Options,
8
+ TableInstance,
9
+ PartialGenerics,
10
+ CreateTableFactoryOptions,
11
+ Table,
12
+ init,
13
+ AnyGenerics,
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 const render = <TProps extends {}>(
22
+ Comp: Renderable<TProps>,
23
+ props: TProps
24
+ ): React.ReactNode =>
25
+ !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
26
+
27
+ export type Render = typeof render
28
+
29
+ function isReactComponent(component: unknown): component is React.FC {
30
+ return (
31
+ isClassComponent(component) ||
32
+ typeof component === 'function' ||
33
+ isExoticComponent(component)
34
+ )
35
+ }
36
+
37
+ function isClassComponent(component: any) {
38
+ return (
39
+ typeof component === 'function' &&
40
+ (() => {
41
+ const proto = Object.getPrototypeOf(component)
42
+ return proto.prototype && proto.prototype.isReactComponent
43
+ })()
44
+ )
45
+ }
46
+
47
+ function isExoticComponent(component: any) {
48
+ return (
49
+ typeof component === 'object' &&
50
+ typeof component.$$typeof === 'symbol' &&
51
+ ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
52
+ )
53
+ }
54
+
55
+ const { createTable, createTableFactory } = init({ render })
56
+
57
+ export { createTable, createTableFactory }
58
+
59
+ export function useTable<TGenerics extends AnyGenerics>(
60
+ table: Table<TGenerics>,
61
+ options: PartialKeys<
62
+ Omit<
63
+ Options<TGenerics>,
64
+ keyof CreateTableFactoryOptions<any, any, any, any>
65
+ >,
66
+ 'state' | 'onStateChange'
67
+ >
68
+ ): TableInstance<TGenerics> {
69
+ // Compose in the generic options to the user options
70
+ const resolvedOptions: Options<TGenerics> = {
71
+ ...(table.__options ?? {}),
72
+ state: {}, // Dummy state
73
+ onStateChange: () => {}, // noop
74
+ render,
75
+ ...options,
76
+ }
77
+
78
+ // Create a new table instance and store it in state
79
+ const [instance] = React.useState(() =>
80
+ createTableInstance<TGenerics>(resolvedOptions)
81
+ )
82
+
83
+ // By default, manage table state here using the instance's initial state
84
+ const [state, setState] = React.useState(() => instance.initialState)
85
+
86
+ // Compose the default state above with any user state. This will allow the user
87
+ // to only control a subset of the state if desired.
88
+ instance.setOptions(prev => ({
89
+ ...prev,
90
+ ...options,
91
+ state: {
92
+ ...state,
93
+ ...options.state,
94
+ },
95
+ // Similarly, we'll maintain both our internal state and any user-provided
96
+ // state.
97
+ onStateChange: updater => {
98
+ setState(updater)
99
+ options.onStateChange?.(updater)
100
+ },
101
+ }))
102
+
103
+ return instance
104
+ }
@@ -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":";;;;;;;;;;;;;;;;IAAaA,gBAAgB,GAAG;AAC9BC,EAAAA,GAAG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