@tanstack/react-table 8.0.0-alpha.6 → 8.0.0-alpha.60

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 (109) 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 +99 -17
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +39 -4707
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +29 -779
  9. package/build/types/index.d.ts +16 -8
  10. package/build/umd/index.development.js +51 -4713
  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 +115 -8
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -552
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -108
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -317
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -251
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -445
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -249
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -549
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -86
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pagination.js +0 -198
  35. package/build/cjs/features/Pagination.js.map +0 -1
  36. package/build/cjs/features/Pinning.js +0 -149
  37. package/build/cjs/features/Pinning.js.map +0 -1
  38. package/build/cjs/features/RowSelection.js +0 -541
  39. package/build/cjs/features/RowSelection.js.map +0 -1
  40. package/build/cjs/features/Sorting.js +0 -327
  41. package/build/cjs/features/Sorting.js.map +0 -1
  42. package/build/cjs/features/Visibility.js +0 -166
  43. package/build/cjs/features/Visibility.js.map +0 -1
  44. package/build/cjs/filterTypes.js +0 -172
  45. package/build/cjs/filterTypes.js.map +0 -1
  46. package/build/cjs/sortTypes.js +0 -122
  47. package/build/cjs/sortTypes.js.map +0 -1
  48. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  49. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/expandRowsFn.js +0 -38
  51. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  52. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  53. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  54. package/build/cjs/utils/groupRowsFn.js +0 -155
  55. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  56. package/build/cjs/utils/paginateRowsFn.js +0 -44
  57. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  58. package/build/cjs/utils/sortRowsFn.js +0 -94
  59. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  60. package/build/cjs/utils.js +0 -141
  61. package/build/cjs/utils.js.map +0 -1
  62. package/build/types/aggregationTypes.d.ts +0 -22
  63. package/build/types/core.d.ts +0 -109
  64. package/build/types/createTable.d.ts +0 -52
  65. package/build/types/features/ColumnSizing.d.ts +0 -67
  66. package/build/types/features/Expanding.d.ts +0 -53
  67. package/build/types/features/Filters.d.ts +0 -98
  68. package/build/types/features/Grouping.d.ts +0 -82
  69. package/build/types/features/Headers.d.ts +0 -41
  70. package/build/types/features/Ordering.d.ts +0 -19
  71. package/build/types/features/Pagination.d.ts +0 -44
  72. package/build/types/features/Pinning.d.ts +0 -39
  73. package/build/types/features/RowSelection.d.ts +0 -66
  74. package/build/types/features/Sorting.d.ts +0 -78
  75. package/build/types/features/Visibility.d.ts +0 -47
  76. package/build/types/filterTypes.d.ts +0 -50
  77. package/build/types/sortTypes.d.ts +0 -18
  78. package/build/types/types.d.ts +0 -127
  79. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  80. package/build/types/utils/expandRowsFn.d.ts +0 -2
  81. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  82. package/build/types/utils/groupRowsFn.d.ts +0 -2
  83. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  84. package/build/types/utils/sortRowsFn.d.ts +0 -2
  85. package/build/types/utils.d.ts +0 -24
  86. package/src/aggregationTypes.ts +0 -115
  87. package/src/core.tsx +0 -1091
  88. package/src/createTable.tsx +0 -241
  89. package/src/features/ColumnSizing.ts +0 -453
  90. package/src/features/Expanding.ts +0 -406
  91. package/src/features/Filters.ts +0 -762
  92. package/src/features/Grouping.ts +0 -466
  93. package/src/features/Headers.ts +0 -912
  94. package/src/features/Ordering.ts +0 -133
  95. package/src/features/Pagination.ts +0 -325
  96. package/src/features/Pinning.ts +0 -198
  97. package/src/features/RowSelection.ts +0 -831
  98. package/src/features/Sorting.ts +0 -547
  99. package/src/features/Visibility.ts +0 -279
  100. package/src/filterTypes.ts +0 -251
  101. package/src/sortTypes.ts +0 -159
  102. package/src/types.ts +0 -331
  103. package/src/utils/columnFilterRowsFn.ts +0 -155
  104. package/src/utils/expandRowsFn.ts +0 -50
  105. package/src/utils/globalFilterRowsFn.ts +0 -122
  106. package/src/utils/groupRowsFn.ts +0 -194
  107. package/src/utils/paginateRowsFn.ts +0 -34
  108. package/src/utils/sortRowsFn.ts +0 -115
  109. package/src/utils.tsx +0 -195
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.6",
4
+ "version": "8.0.0-alpha.60",
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.60"
38
+ },
36
39
  "peerDependencies": {
37
40
  "react": ">=16",
38
41
  "react-dom": ">=16"
package/src/index.tsx CHANGED
@@ -1,8 +1,115 @@
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 * from './utils/paginateRowsFn'
8
- export * from './createTable'
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
+ } from '@tanstack/table-core'
14
+
15
+ export type Renderable<TProps> =
16
+ | React.ReactNode
17
+ | React.FunctionComponent<TProps>
18
+ | React.Component<TProps>
19
+
20
+ export type Render = <TProps extends {}>(
21
+ Comp: Renderable<TProps>,
22
+ props: TProps
23
+ ) => React.ReactNode | JSX.Element
24
+
25
+ export type ReactTableGenerics = Overwrite<
26
+ TableGenerics,
27
+ { Renderer: Render; Rendered: ReturnType<Render> }
28
+ >
29
+
30
+ //
31
+
32
+ export const render: Render = (Comp, props) =>
33
+ !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
34
+
35
+ function isReactComponent(component: unknown): component is React.FC {
36
+ return (
37
+ isClassComponent(component) ||
38
+ typeof component === 'function' ||
39
+ isExoticComponent(component)
40
+ )
41
+ }
42
+
43
+ function isClassComponent(component: any) {
44
+ return (
45
+ typeof component === 'function' &&
46
+ (() => {
47
+ const proto = Object.getPrototypeOf(component)
48
+ return proto.prototype && proto.prototype.isReactComponent
49
+ })()
50
+ )
51
+ }
52
+
53
+ function isExoticComponent(component: any) {
54
+ return (
55
+ typeof component === 'object' &&
56
+ typeof component.$$typeof === 'symbol' &&
57
+ ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
58
+ )
59
+ }
60
+
61
+ export const createTable = createTableFactory({ render })
62
+
63
+ const useIsomorphicLayoutEffect =
64
+ typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
65
+
66
+ export type UseTableInstanceOptions<TGenerics extends ReactTableGenerics> =
67
+ PartialKeys<
68
+ Omit<TableOptions<TGenerics>, 'render'>,
69
+ 'state' | 'onStateChange'
70
+ >
71
+
72
+ export function useTableInstance<TGenerics extends ReactTableGenerics>(
73
+ table: Table<TGenerics>,
74
+ options: UseTableInstanceOptions<TGenerics>
75
+ ): TableInstance<TGenerics> {
76
+ // Compose in the generic options to the user options
77
+ const resolvedOptions: TableOptions<TGenerics> = {
78
+ ...table.options,
79
+ state: {}, // Dummy state
80
+ onStateChange: () => {}, // noop
81
+ render,
82
+ ...options,
83
+ }
84
+
85
+ // Create a new table instance and store it in state
86
+ const [instance] = React.useState(() =>
87
+ createTableInstance<TGenerics>(resolvedOptions)
88
+ )
89
+
90
+ // By default, manage table state here using the instance's initial state
91
+ const [state, setState] = React.useState(() => instance.initialState)
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
+ instance.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
+ useIsomorphicLayoutEffect(() => {
111
+ instance.willUpdate()
112
+ })
113
+
114
+ return instance
115
+ }
@@ -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,QAAhB,GAA2BA,IAA3B,GAAkC,CAAtC,CAAnC;AAAA,GADK,EAEL,CAFK,CAAP;AAID;;AAED,SAASX,GAAT,CAAaQ,WAAb,EAAqCC,WAArC,EAA6D;AAC3D,MAAIT,GAAJ;;AAEA,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