@tanstack/react-table 8.0.0-alpha.1 → 8.0.0-alpha.16

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 (96) 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 -3330
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -632
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +50 -3332
  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 +105 -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 -493
  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/Expanding.js +0 -234
  23. package/build/cjs/features/Expanding.js.map +0 -1
  24. package/build/cjs/features/Filters.js +0 -396
  25. package/build/cjs/features/Filters.js.map +0 -1
  26. package/build/cjs/features/Grouping.js +0 -228
  27. package/build/cjs/features/Grouping.js.map +0 -1
  28. package/build/cjs/features/Headers.js +0 -483
  29. package/build/cjs/features/Headers.js.map +0 -1
  30. package/build/cjs/features/Ordering.js +0 -83
  31. package/build/cjs/features/Ordering.js.map +0 -1
  32. package/build/cjs/features/Pinning.js +0 -163
  33. package/build/cjs/features/Pinning.js.map +0 -1
  34. package/build/cjs/features/Sorting.js +0 -269
  35. package/build/cjs/features/Sorting.js.map +0 -1
  36. package/build/cjs/features/Visibility.js +0 -160
  37. package/build/cjs/features/Visibility.js.map +0 -1
  38. package/build/cjs/filterTypes.js +0 -172
  39. package/build/cjs/filterTypes.js.map +0 -1
  40. package/build/cjs/sortTypes.js +0 -121
  41. package/build/cjs/sortTypes.js.map +0 -1
  42. package/build/cjs/utils/columnFilterRowsFn.js +0 -130
  43. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  44. package/build/cjs/utils/expandRowsFn.js +0 -38
  45. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  46. package/build/cjs/utils/globalFilterRowsFn.js +0 -100
  47. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  48. package/build/cjs/utils/groupRowsFn.js +0 -154
  49. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  50. package/build/cjs/utils/sortRowsFn.js +0 -93
  51. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  52. package/build/cjs/utils.js +0 -143
  53. package/build/cjs/utils.js.map +0 -1
  54. package/build/types/aggregationTypes.d.ts +0 -22
  55. package/build/types/core.d.ts +0 -122
  56. package/build/types/createTable.d.ts +0 -35
  57. package/build/types/features/Expanding.d.ts +0 -52
  58. package/build/types/features/Filters.d.ts +0 -93
  59. package/build/types/features/Grouping.d.ts +0 -82
  60. package/build/types/features/Headers.d.ts +0 -41
  61. package/build/types/features/Ordering.d.ts +0 -19
  62. package/build/types/features/Pinning.d.ts +0 -39
  63. package/build/types/features/Sorting.d.ts +0 -75
  64. package/build/types/features/Visibility.d.ts +0 -47
  65. package/build/types/filterTypes.d.ts +0 -50
  66. package/build/types/sortTypes.d.ts +0 -17
  67. package/build/types/types.d.ts +0 -122
  68. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  69. package/build/types/utils/expandRowsFn.d.ts +0 -2
  70. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  71. package/build/types/utils/groupRowsFn.d.ts +0 -2
  72. package/build/types/utils/sortRowsFn.d.ts +0 -2
  73. package/build/types/utils.d.ts +0 -24
  74. package/src/aggregationTypes.ts +0 -115
  75. package/src/core.tsx +0 -1194
  76. package/src/createTable.tsx +0 -181
  77. package/src/features/Expanding.ts +0 -388
  78. package/src/features/Filters.ts +0 -707
  79. package/src/features/Grouping.ts +0 -451
  80. package/src/features/Headers.ts +0 -907
  81. package/src/features/Ordering.ts +0 -134
  82. package/src/features/Pinning.ts +0 -213
  83. package/src/features/Sorting.ts +0 -487
  84. package/src/features/Visibility.ts +0 -281
  85. package/src/features/withColumnResizing.oldts +0 -281
  86. package/src/features/withPagination.oldts +0 -208
  87. package/src/features/withRowSelection.oldts +0 -467
  88. package/src/filterTypes.ts +0 -251
  89. package/src/sortTypes.ts +0 -159
  90. package/src/types.ts +0 -285
  91. package/src/utils/columnFilterRowsFn.ts +0 -162
  92. package/src/utils/expandRowsFn.ts +0 -53
  93. package/src/utils/globalFilterRowsFn.ts +0 -129
  94. package/src/utils/groupRowsFn.ts +0 -196
  95. package/src/utils/sortRowsFn.ts +0 -115
  96. package/src/utils.tsx +0 -243
package/src/index.tsx CHANGED
@@ -1,7 +1,105 @@
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
+ _NonGenerated,
7
+ PartialKeys,
8
+ Options,
9
+ TableInstance,
10
+ PartialGenerics,
11
+ CreateTableFactoryOptions,
12
+ Table,
13
+ init,
14
+ AnyGenerics,
15
+ } from '@tanstack/table-core'
16
+
17
+ export type Renderable<TProps> =
18
+ | React.ReactNode
19
+ | React.FunctionComponent<TProps>
20
+ | React.Component<TProps>
21
+
22
+ export const render = <TProps extends {}>(
23
+ Comp: Renderable<TProps>,
24
+ props: TProps
25
+ ): React.ReactNode =>
26
+ !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
27
+
28
+ export type Render = typeof render
29
+
30
+ function isReactComponent(component: unknown): component is React.FC {
31
+ return (
32
+ isClassComponent(component) ||
33
+ typeof component === 'function' ||
34
+ isExoticComponent(component)
35
+ )
36
+ }
37
+
38
+ function isClassComponent(component: any) {
39
+ return (
40
+ typeof component === 'function' &&
41
+ (() => {
42
+ const proto = Object.getPrototypeOf(component)
43
+ return proto.prototype && proto.prototype.isReactComponent
44
+ })()
45
+ )
46
+ }
47
+
48
+ function isExoticComponent(component: any) {
49
+ return (
50
+ typeof component === 'object' &&
51
+ typeof component.$$typeof === 'symbol' &&
52
+ ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
53
+ )
54
+ }
55
+
56
+ const { createTable, createTableFactory } = init({ render })
57
+
58
+ export { createTable, createTableFactory }
59
+
60
+ export function useTable<TGenerics extends AnyGenerics>(
61
+ table: Table<TGenerics>,
62
+ options: PartialKeys<
63
+ Omit<
64
+ Options<TGenerics>,
65
+ keyof CreateTableFactoryOptions<any, any, any, any>
66
+ >,
67
+ 'state' | 'onStateChange'
68
+ >
69
+ ): TableInstance<TGenerics> {
70
+ // Compose in the generic options to the user options
71
+ const resolvedOptions: Options<TGenerics> = {
72
+ ...(table.__options ?? {}),
73
+ state: {}, // Dummy state
74
+ onStateChange: () => {}, // noop
75
+ render,
76
+ ...options,
77
+ }
78
+
79
+ // Create a new table instance and store it in state
80
+ const [instance] = React.useState(() =>
81
+ createTableInstance<TGenerics>(resolvedOptions)
82
+ )
83
+
84
+ // By default, manage table state here using the instance's initial state
85
+ const [state, setState] = React.useState(() => instance.initialState)
86
+
87
+ // Compose the default state above with any user state. This will allow the user
88
+ // to only control a subset of the state if desired.
89
+ instance.setOptions(prev => ({
90
+ ...prev,
91
+ ...options,
92
+ state: {
93
+ ...state,
94
+ ...options.state,
95
+ },
96
+ // Similarly, we'll maintain both our internal state and any user-provided
97
+ // state.
98
+ onStateChange: updater => {
99
+ setState(updater)
100
+ options.onStateChange?.(updater)
101
+ },
102
+ }))
103
+
104
+ return instance
105
+ }
@@ -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,EAAHA,GAD8B;AAE9BC,EAAAA,GAAG,EAAHA,GAF8B;AAG9BC,EAAAA,GAAG,EAAHA,GAH8B;AAI9BC,EAAAA,MAAM,EAANA,MAJ8B;AAK9BC,EAAAA,IAAI,EAAJA,IAL8B;AAM9BC,EAAAA,MAAM,EAANA,MAN8B;AAO9BC,EAAAA,MAAM,EAANA,MAP8B;AAQ9BC,EAAAA,WAAW,EAAXA,WAR8B;AAS9BC,EAAAA,KAAK,EAALA;AAT8B;;AAchC,SAASR,GAAT,CAAaS,WAAb,EAAqCC,WAArC,EAA6D;AAC3D;AACA;AACA,SAAOA,WAAW,CAACC,MAAZ,CACL,UAACX,GAAD,EAAcY,IAAd;AAAA,WAAgCZ,GAAG,IAAI,OAAOY,IAAP,KAAgB,QAA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