@tanstack/react-table 8.0.0-alpha.3 → 8.0.0-alpha.30

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 (107) 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 +39 -4687
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -746
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +49 -4689
  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 +103 -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 -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 -255
  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 -194
  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/sortRowsFn.js +0 -94
  57. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  58. package/build/cjs/utils.js +0 -146
  59. package/build/cjs/utils.js.map +0 -1
  60. package/build/types/aggregationTypes.d.ts +0 -22
  61. package/build/types/core.d.ts +0 -111
  62. package/build/types/createTable.d.ts +0 -53
  63. package/build/types/features/ColumnSizing.d.ts +0 -67
  64. package/build/types/features/Expanding.d.ts +0 -53
  65. package/build/types/features/Filters.d.ts +0 -98
  66. package/build/types/features/Grouping.d.ts +0 -82
  67. package/build/types/features/Headers.d.ts +0 -41
  68. package/build/types/features/Ordering.d.ts +0 -19
  69. package/build/types/features/Pagination.d.ts +0 -43
  70. package/build/types/features/Pinning.d.ts +0 -39
  71. package/build/types/features/RowSelection.d.ts +0 -66
  72. package/build/types/features/Sorting.d.ts +0 -78
  73. package/build/types/features/Visibility.d.ts +0 -47
  74. package/build/types/filterTypes.d.ts +0 -50
  75. package/build/types/sortTypes.d.ts +0 -18
  76. package/build/types/types.d.ts +0 -127
  77. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  78. package/build/types/utils/expandRowsFn.d.ts +0 -2
  79. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  80. package/build/types/utils/groupRowsFn.d.ts +0 -2
  81. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  82. package/build/types/utils/sortRowsFn.d.ts +0 -2
  83. package/build/types/utils.d.ts +0 -28
  84. package/src/aggregationTypes.ts +0 -115
  85. package/src/core.tsx +0 -1182
  86. package/src/createTable.tsx +0 -241
  87. package/src/features/ColumnSizing.ts +0 -453
  88. package/src/features/Expanding.ts +0 -404
  89. package/src/features/Filters.ts +0 -762
  90. package/src/features/Grouping.ts +0 -466
  91. package/src/features/Headers.ts +0 -912
  92. package/src/features/Ordering.ts +0 -133
  93. package/src/features/Pagination.ts +0 -314
  94. package/src/features/Pinning.ts +0 -200
  95. package/src/features/RowSelection.ts +0 -831
  96. package/src/features/Sorting.ts +0 -547
  97. package/src/features/Visibility.ts +0 -279
  98. package/src/filterTypes.ts +0 -251
  99. package/src/sortTypes.ts +0 -159
  100. package/src/types.ts +0 -331
  101. package/src/utils/columnFilterRowsFn.ts +0 -155
  102. package/src/utils/expandRowsFn.ts +0 -50
  103. package/src/utils/globalFilterRowsFn.ts +0 -122
  104. package/src/utils/groupRowsFn.ts +0 -194
  105. package/src/utils/paginateRowsFn.ts +0 -34
  106. package/src/utils/sortRowsFn.ts +0 -115
  107. package/src/utils.tsx +0 -257
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.3",
4
+ "version": "8.0.0-alpha.30",
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.30"
38
+ },
36
39
  "peerDependencies": {
37
40
  "react": ">=16",
38
41
  "react-dom": ">=16"
package/src/index.tsx CHANGED
@@ -1,7 +1,103 @@
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
+ CreateTableFactoryOptions,
10
+ Table,
11
+ init,
12
+ AnyGenerics,
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 const render = <TProps extends {}>(
21
+ Comp: Renderable<TProps>,
22
+ props: TProps
23
+ ): React.ReactNode =>
24
+ !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
25
+
26
+ export type Render = typeof render
27
+
28
+ function isReactComponent(component: unknown): component is React.FC {
29
+ return (
30
+ isClassComponent(component) ||
31
+ typeof component === 'function' ||
32
+ isExoticComponent(component)
33
+ )
34
+ }
35
+
36
+ function isClassComponent(component: any) {
37
+ return (
38
+ typeof component === 'function' &&
39
+ (() => {
40
+ const proto = Object.getPrototypeOf(component)
41
+ return proto.prototype && proto.prototype.isReactComponent
42
+ })()
43
+ )
44
+ }
45
+
46
+ function isExoticComponent(component: any) {
47
+ return (
48
+ typeof component === 'object' &&
49
+ typeof component.$$typeof === 'symbol' &&
50
+ ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
51
+ )
52
+ }
53
+
54
+ const { createTable, createTableFactory } = init({ render })
55
+
56
+ export { createTable, createTableFactory }
57
+
58
+ export function useTable<TGenerics extends AnyGenerics>(
59
+ table: Table<TGenerics>,
60
+ options: PartialKeys<
61
+ Omit<
62
+ Options<TGenerics>,
63
+ keyof CreateTableFactoryOptions<any, any, any, any>
64
+ >,
65
+ 'state' | 'onStateChange'
66
+ >
67
+ ): TableInstance<TGenerics> {
68
+ // Compose in the generic options to the user options
69
+ const resolvedOptions: Options<TGenerics> = {
70
+ ...(table.__options ?? {}),
71
+ state: {}, // Dummy state
72
+ onStateChange: () => {}, // noop
73
+ render,
74
+ ...options,
75
+ }
76
+
77
+ // Create a new table instance and store it in state
78
+ const [instance] = React.useState(() =>
79
+ createTableInstance<TGenerics>(resolvedOptions)
80
+ )
81
+
82
+ // By default, manage table state here using the instance's initial state
83
+ const [state, setState] = React.useState(() => instance.initialState)
84
+
85
+ // Compose the default state above with any user state. This will allow the user
86
+ // to only control a subset of the state if desired.
87
+ instance.setOptions(prev => ({
88
+ ...prev,
89
+ ...options,
90
+ state: {
91
+ ...state,
92
+ ...options.state,
93
+ },
94
+ // Similarly, we'll maintain both our internal state and any user-provided
95
+ // state.
96
+ onStateChange: updater => {
97
+ setState(updater)
98
+ options.onStateChange?.(updater)
99
+ },
100
+ }))
101
+
102
+ return instance
103
+ }
@@ -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,gFAAoBS,WAApB,wCAA6C;AAAA,QAAlCG,KAAkC;;AAC3C,QACEA,KAAK,IAAI,IAAT,KACCZ,GAAG,GAAIY,KAAP,IAAiBZ,GAAG,KAAKa,SAAR,IAAqBD,KAAK,IAAIA,KADhD,CADF,EAGE;AACAZ,MAAAA,GAAG,GAAGY,KAAN;AACD;AACF;;AAED,SAAOZ,GAAP;AACD;;AAED,SAASC,GAAT,CAAaO,WAAb,EAAqCC,WAArC,EAA6D;AAC3D,MAAIR,GAAJ;;AAEA,iFAAoBQ,WAApB,2CAA6C;AAA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