@tanstack/react-table 0.0.1-alpha.8 → 8.0.0-alpha.11

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 (61) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +34 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/index.js +85 -0
  4. package/build/cjs/index.js.map +1 -0
  5. package/build/esm/index.js +73 -0
  6. package/build/esm/index.js.map +1 -0
  7. package/build/stats-html.html +2689 -0
  8. package/build/stats-react.json +99 -0
  9. package/build/types/index.d.ts +3 -0
  10. package/build/umd/index.development.js +105 -0
  11. package/build/umd/index.development.js.map +1 -0
  12. package/build/umd/index.production.js +12 -0
  13. package/build/umd/index.production.js.map +1 -0
  14. package/package.json +12 -94
  15. package/src/index.tsx +56 -7
  16. package/dist/react-table.development.js +0 -3406
  17. package/dist/react-table.development.js.map +0 -1
  18. package/dist/react-table.production.min.js +0 -2
  19. package/dist/react-table.production.min.js.map +0 -1
  20. package/lib/index.js +0 -65
  21. package/src/aggregationTypes.ts +0 -115
  22. package/src/core.tsx +0 -1194
  23. package/src/createTable.tsx +0 -181
  24. package/src/features/Expanding.ts +0 -388
  25. package/src/features/Filters.ts +0 -707
  26. package/src/features/Grouping.ts +0 -451
  27. package/src/features/Headers.ts +0 -907
  28. package/src/features/Ordering.ts +0 -134
  29. package/src/features/Pinning.ts +0 -213
  30. package/src/features/Sorting.ts +0 -487
  31. package/src/features/Visibility.ts +0 -281
  32. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  33. package/src/features/notest/useBlockLayout.test.js +0 -158
  34. package/src/features/notest/useColumnOrder.test.js +0 -186
  35. package/src/features/notest/useExpanded.test.js +0 -125
  36. package/src/features/notest/useFilters.test.js +0 -393
  37. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  38. package/src/features/notest/useFlexLayout.test.js +0 -152
  39. package/src/features/notest/useGroupBy.test.js +0 -259
  40. package/src/features/notest/usePagination.test.js +0 -231
  41. package/src/features/notest/useResizeColumns.test.js +0 -229
  42. package/src/features/notest/useRowSelect.test.js +0 -250
  43. package/src/features/notest/useRowState.test.js +0 -178
  44. package/src/features/tests/Visibility.test.tsx +0 -225
  45. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  46. package/src/features/tests/withSorting.notest.tsx +0 -341
  47. package/src/features/withColumnResizing.ts +0 -281
  48. package/src/features/withPagination.ts +0 -208
  49. package/src/features/withRowSelection.ts +0 -467
  50. package/src/filterTypes.ts +0 -251
  51. package/src/sortTypes.ts +0 -159
  52. package/src/test-utils/makeTestData.ts +0 -41
  53. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  54. package/src/tests/core.test.tsx +0 -241
  55. package/src/types.ts +0 -285
  56. package/src/utils/columnFilterRowsFn.ts +0 -162
  57. package/src/utils/expandRowsFn.ts +0 -53
  58. package/src/utils/globalFilterRowsFn.ts +0 -129
  59. package/src/utils/groupRowsFn.ts +0 -196
  60. package/src/utils/sortRowsFn.ts +0 -115
  61. package/src/utils.tsx +0 -243
@@ -0,0 +1,99 @@
1
+ {
2
+ "version": 2,
3
+ "tree": {
4
+ "name": "root",
5
+ "children": [
6
+ {
7
+ "name": "index.production.js",
8
+ "children": [
9
+ {
10
+ "uid": "ff18-113",
11
+ "name": "\u0000rollupPluginBabelHelpers.js"
12
+ },
13
+ {
14
+ "name": "packages/react-table/src/index.tsx",
15
+ "uid": "ff18-115"
16
+ }
17
+ ]
18
+ }
19
+ ],
20
+ "isRoot": true
21
+ },
22
+ "nodeParts": {
23
+ "ff18-113": {
24
+ "renderedLength": 410,
25
+ "gzipLength": 231,
26
+ "brotliLength": 0,
27
+ "mainUid": "ff18-112"
28
+ },
29
+ "ff18-115": {
30
+ "renderedLength": 1429,
31
+ "gzipLength": 565,
32
+ "brotliLength": 0,
33
+ "mainUid": "ff18-114"
34
+ }
35
+ },
36
+ "nodeMetas": {
37
+ "ff18-112": {
38
+ "id": "\u0000rollupPluginBabelHelpers.js",
39
+ "moduleParts": {
40
+ "index.production.js": "ff18-113"
41
+ },
42
+ "imported": [],
43
+ "importedBy": [
44
+ {
45
+ "uid": "ff18-114"
46
+ }
47
+ ]
48
+ },
49
+ "ff18-114": {
50
+ "id": "/packages/react-table/src/index.tsx",
51
+ "moduleParts": {
52
+ "index.production.js": "ff18-115"
53
+ },
54
+ "imported": [
55
+ {
56
+ "uid": "ff18-112"
57
+ },
58
+ {
59
+ "uid": "ff18-116"
60
+ },
61
+ {
62
+ "uid": "ff18-117"
63
+ }
64
+ ],
65
+ "importedBy": [],
66
+ "isEntry": true
67
+ },
68
+ "ff18-116": {
69
+ "id": "react",
70
+ "moduleParts": {},
71
+ "imported": [],
72
+ "importedBy": [
73
+ {
74
+ "uid": "ff18-114"
75
+ }
76
+ ],
77
+ "isExternal": true
78
+ },
79
+ "ff18-117": {
80
+ "id": "@tanstack/table-core",
81
+ "moduleParts": {},
82
+ "imported": [],
83
+ "importedBy": [
84
+ {
85
+ "uid": "ff18-114"
86
+ }
87
+ ],
88
+ "isExternal": true
89
+ }
90
+ },
91
+ "env": {
92
+ "rollup": "2.66.0"
93
+ },
94
+ "options": {
95
+ "gzip": true,
96
+ "brotli": false,
97
+ "sourcemap": false
98
+ }
99
+ }
@@ -0,0 +1,3 @@
1
+ export * from '@tanstack/table-core';
2
+ import { PartialKeys, Options, TableInstance, PartialGenerics, CreateTableFactoryOptions, TableFactory } from '@tanstack/table-core';
3
+ export declare function useTable<TGenerics extends PartialGenerics>(table: TableFactory<TGenerics>, options: PartialKeys<Omit<Options<TGenerics>, keyof CreateTableFactoryOptions<any, any, any>>, 'state' | 'onStateChange'>): TableInstance<TGenerics>;
@@ -0,0 +1,105 @@
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
+ (function (global, factory) {
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/table-core')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/table-core'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTable = {}, global.React, global.TableCore));
15
+ })(this, (function (exports, React, tableCore) { 'use strict';
16
+
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n["default"] = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
+
37
+ function _extends() {
38
+ _extends = Object.assign || function (target) {
39
+ for (var i = 1; i < arguments.length; i++) {
40
+ var source = arguments[i];
41
+
42
+ for (var key in source) {
43
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
44
+ target[key] = source[key];
45
+ }
46
+ }
47
+ }
48
+
49
+ return target;
50
+ };
51
+
52
+ return _extends.apply(this, arguments);
53
+ }
54
+
55
+ function useTable(table, options) {
56
+ var _table$__options;
57
+
58
+ // Compose in the generic options to the user options
59
+ var resolvedOptions = _extends({}, (_table$__options = table.__options) != null ? _table$__options : {}, {
60
+ state: {},
61
+ // Dummy state
62
+ onStateChange: function onStateChange() {}
63
+ }, options); // Create a new table instance and store it in state
64
+
65
+
66
+ var _React$useState = React__namespace.useState(function () {
67
+ return tableCore.createTableInstance(resolvedOptions);
68
+ }),
69
+ instance = _React$useState[0]; // By default, manage table state here using the instance's initial state
70
+
71
+
72
+ var _React$useState2 = React__namespace.useState(function () {
73
+ return instance.initialState;
74
+ }),
75
+ state = _React$useState2[0],
76
+ setState = _React$useState2[1]; // Compose the default state above with any user state. This will allow the user
77
+ // to only control a subset of the state if desired.
78
+
79
+
80
+ instance.setOptions(function (prev) {
81
+ return _extends({}, prev, options, {
82
+ state: _extends({}, state, options.state),
83
+ // Similarly, we'll maintain both our internal state and any user-provided
84
+ // state.
85
+ onStateChange: function onStateChange(updater) {
86
+ setState(updater);
87
+ options.onStateChange == null ? void 0 : options.onStateChange(updater);
88
+ }
89
+ });
90
+ });
91
+ return instance;
92
+ }
93
+
94
+ exports.useTable = useTable;
95
+ Object.keys(tableCore).forEach(function (k) {
96
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
97
+ enumerable: true,
98
+ get: function () { return tableCore[k]; }
99
+ });
100
+ });
101
+
102
+ Object.defineProperty(exports, '__esModule', { value: true });
103
+
104
+ }));
105
+ //# sourceMappingURL=index.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.development.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n createTableInstance,\n _NonGenerated,\n PartialKeys,\n Options,\n TableInstance,\n PartialGenerics,\n CreateTableFactoryOptions,\n TableFactory,\n} from '@tanstack/table-core'\n\nexport function useTable<TGenerics extends PartialGenerics>(\n table: TableFactory<TGenerics>,\n options: PartialKeys<\n Omit<Options<TGenerics>, keyof CreateTableFactoryOptions<any, any, any>>,\n 'state' | 'onStateChange'\n >\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions = {\n ...(table.__options ?? {}),\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n ...options,\n }\n\n // Create a new table instance and store it in state\n const [instance] = React.useState(() =>\n createTableInstance<TGenerics>(resolvedOptions)\n )\n\n // By default, manage table state here using the instance's initial state\n const [state, setState] = React.useState(() => instance.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n instance.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return instance\n}\n"],"names":["useTable","table","options","resolvedOptions","__options","state","onStateChange","React","useState","createTableInstance","instance","initialState","setState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcO,SAASA,QAAT,CACLC,KADK,EAELC,OAFK,EAMqB;EAAA;;EAC1B;EACA,MAAMC,eAAe,oCACfF,KAAK,CAACG,SADS,+BACI,EADJ;EAEnBC,IAAAA,KAAK,EAAE,EAFY;EAER;EACXC,IAAAA,aAAa,EAAE,yBAAM;EAHF,KAIhBJ,OAJgB,CAArB,CAF0B;;;EAU1B,wBAAmBK,gBAAK,CAACC,QAAN,CAAe;EAAA,WAChCC,6BAAmB,CAAYN,eAAZ,CADa;EAAA,GAAf,CAAnB;EAAA,MAAOO,QAAP,sBAV0B;;;EAe1B,yBAA0BH,gBAAK,CAACC,QAAN,CAAe;EAAA,WAAME,QAAQ,CAACC,YAAf;EAAA,GAAf,CAA1B;EAAA,MAAON,KAAP;EAAA,MAAcO,QAAd,uBAf0B;EAkB1B;;;EACAF,EAAAA,QAAQ,CAACG,UAAT,CAAoB,UAAAC,IAAI;EAAA,wBACnBA,IADmB,EAEnBZ,OAFmB;EAGtBG,MAAAA,KAAK,eACAA,KADA,EAEAH,OAAO,CAACG,KAFR,CAHiB;EAOtB;EACA;EACAC,MAAAA,aAAa,EAAE,uBAAAS,OAAO,EAAI;EACxBH,QAAAA,QAAQ,CAACG,OAAD,CAAR;EACAb,QAAAA,OAAO,CAACI,aAAR,oBAAAJ,OAAO,CAACI,aAAR,CAAwBS,OAAxB;EACD;EAZqB;EAAA,GAAxB;EAeA,SAAOL,QAAP;EACD;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
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
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/table-core")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/table-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactTable={},e.React,e.TableCore)}(this,(function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=r(t);function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o.apply(this,arguments)}e.useTable=function(e,t){var r,u=o({},null!=(r=e.__options)?r:{},{state:{},onStateChange:function(){}},t),c=a.useState((function(){return n.createTableInstance(u)}))[0],i=a.useState((function(){return c.initialState})),f=i[0],l=i[1];return c.setOptions((function(e){return o({},e,t,{state:o({},f,t.state),onStateChange:function(e){l(e),null==t.onStateChange||t.onStateChange(e)}})})),c},Object.keys(n).forEach((function(t){"default"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),Object.defineProperty(e,"__esModule",{value:!0})}));
12
+ //# sourceMappingURL=index.production.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.production.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n createTableInstance,\n _NonGenerated,\n PartialKeys,\n Options,\n TableInstance,\n PartialGenerics,\n CreateTableFactoryOptions,\n TableFactory,\n} from '@tanstack/table-core'\n\nexport function useTable<TGenerics extends PartialGenerics>(\n table: TableFactory<TGenerics>,\n options: PartialKeys<\n Omit<Options<TGenerics>, keyof CreateTableFactoryOptions<any, any, any>>,\n 'state' | 'onStateChange'\n >\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions = {\n ...(table.__options ?? {}),\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n ...options,\n }\n\n // Create a new table instance and store it in state\n const [instance] = React.useState(() =>\n createTableInstance<TGenerics>(resolvedOptions)\n )\n\n // By default, manage table state here using the instance's initial state\n const [state, setState] = React.useState(() => instance.initialState)\n\n // Compose the default state above with any user state. This will allow the user\n // to only control a subset of the state if desired.\n instance.setOptions(prev => ({\n ...prev,\n ...options,\n state: {\n ...state,\n ...options.state,\n },\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: updater => {\n setState(updater)\n options.onStateChange?.(updater)\n },\n }))\n\n return instance\n}\n"],"names":["table","options","resolvedOptions","__options","state","onStateChange","instance","React","useState","createTableInstance","initialState","setState","setOptions","prev","updater"],"mappings":";;;;;;;;;;+1BAcO,SACLA,EACAC,SAMMC,gBACAF,EAAMG,aAAa,IACvBC,MAAO,GACPC,cAAe,cACZJ,GAIEK,EAAYC,EAAMC,UAAS,kBAChCC,sBAA+BP,WAIPK,EAAMC,UAAS,kBAAMF,EAASI,gBAAjDN,OAAOO,cAIdL,EAASM,YAAW,SAAAC,eACfA,EACAZ,GACHG,WACKA,EACAH,EAAQG,OAIbC,cAAe,SAAAS,GACbH,EAASG,SACTb,EAAQI,eAARJ,EAAQI,cAAgBS,SAIrBR"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
- "version": "0.0.1-alpha.8",
3
+ "author": "Tanner Linsley",
4
+ "version": "8.0.0-alpha.11",
4
5
  "description": "Hooks for building lightweight, fast and extendable datagrids for React",
5
6
  "license": "MIT",
6
- "homepage": "https://github.com/tannerlinsley/react-table#readme",
7
+ "homepage": "https://github.com/tanstack/react-table#readme",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "git+https://github.com/tannerlinsley/react-table.git"
10
+ "url": "git+https://github.com/tanstack/react-table.git"
10
11
  },
11
12
  "publishConfig": {
12
13
  "registry": "https://registry.npmjs.org/"
@@ -21,105 +22,22 @@
21
22
  "type": "github",
22
23
  "url": "https://github.com/sponsors/tannerlinsley"
23
24
  },
24
- "main": "lib/index.js",
25
- "module": "es/index.js",
26
- "typings": "types/index.d.ts",
27
- "scripts": {
28
- "test": "(is-ci && yarn test:ci) || yarn test:dev",
29
- "test:dev": "jest --watch",
30
- "test:ci": "jest",
31
- "test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
32
- "build": "yarn format && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:types",
33
- "build:commonjs": "rimraf ./lib && cross-env BABEL_ENV=commonjs babel --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir lib",
34
- "build:es": "rimraf ./es && babel --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir es",
35
- "build:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json",
36
- "build:types": "rimraf ./types && tsc --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r --silent && replace 'export type' 'export' ./types -r --silent",
37
- "watch": "yarn watch:commonjs & yarn watch:es & yarn watch:umd & yarn watch:types",
38
- "watch:commonjs": "rimraf ./lib && cross-env BABEL_ENV=commonjs babel --watch --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir lib",
39
- "watch:es": "rimraf ./es && babel --watch --extensions .ts,.tsx --ignore ./src/**/tests/**/* ./src --out-dir es",
40
- "watch:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -w -c && rollup-plugin-visualizer stats-react.json",
41
- "watch:types": "rimraf ./types && tsc --watch --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r --silent && replace 'export type' 'export' ./types -r --silent",
42
- "now-build": "yarn && cd www && yarn && yarn build",
43
- "prettier": "prettier \"{.,src,src/**,example/src,example/src/**}/*.{md,js,jsx,ts,tsx,json}\"",
44
- "start": "yarn watch",
45
- "format": "yarn prettier --write",
46
- "stats": "open ./stats.html",
47
- "doctoc": "doctoc README.md"
48
- },
25
+ "module": "build/esm/index.js",
26
+ "main": "build/cjs/index.js",
27
+ "browser": "build/umd/index.production.min.js",
28
+ "types": "build/types/index.d.ts",
49
29
  "engines": {
50
30
  "node": ">=12"
51
31
  },
52
- "release": {
53
- "branches": [
54
- "master",
55
- {
56
- "name": "beta",
57
- "prerelease": true
58
- }
59
- ]
60
- },
61
32
  "files": [
62
- "dist",
33
+ "build",
63
34
  "src"
64
35
  ],
65
- "browserslist": [
66
- "last 2 versions",
67
- "> 0.2%"
68
- ],
36
+ "dependencies": {
37
+ "@tanstack/table-core": "^8.0.0-alpha.9"
38
+ },
69
39
  "peerDependencies": {
70
40
  "react": ">=16",
71
41
  "react-dom": ">=16"
72
- },
73
- "dependencies": {
74
- "ts-toolbelt": "^9.6.0"
75
- },
76
- "devDependencies": {
77
- "@babel/cli": "^7.15.7",
78
- "@babel/core": "^7.15.8",
79
- "@babel/plugin-transform-runtime": "^7.15.8",
80
- "@babel/preset-env": "^7.15.8",
81
- "@babel/preset-react": "^7.14.5",
82
- "@babel/preset-typescript": "^7.15.0",
83
- "@rollup/plugin-replace": "^3.0.0",
84
- "@testing-library/jest-dom": "^5.14.1",
85
- "@testing-library/react": "^12.1.2",
86
- "@testing-library/react-hooks": "^7.0.2",
87
- "@types/react": "^17.0.27",
88
- "@types/react-dom": "^17.0.9",
89
- "@types/semver": "^7.3.9",
90
- "babel-plugin-const-enum": "^1.1.0",
91
- "babel-plugin-dev-expression": "^0.2.2",
92
- "babel-plugin-transform-async-to-promises": "^0.8.15",
93
- "conventional-changelog-angular": "^5.0.13",
94
- "cross-env": "^7.0.3",
95
- "current-git-branch": "^1.1.0",
96
- "doctoc": "^2.1.0",
97
- "fast-async": "^6.3.8",
98
- "git-log-parser": "^1.2.0",
99
- "is-ci": "^3.0.0",
100
- "jest": "^27.4.5",
101
- "jsonfile": "^6.1.0",
102
- "lerna": "^4.0.0",
103
- "prettier": "^2.4.1",
104
- "prompt-confirm": "^2.0.4",
105
- "react": "^17.0.2",
106
- "react-dom": "^17.0.2",
107
- "react-test-renderer": "^17.0.2",
108
- "replace": "^1.2.1",
109
- "rimraf": "^3.0.2",
110
- "rollup": "^2.16.1",
111
- "rollup-plugin-babel": "^4.4.0",
112
- "rollup-plugin-commonjs": "^10.1.0",
113
- "rollup-plugin-jscc": "^1.0.0",
114
- "rollup-plugin-node-resolve": "^5.2.0",
115
- "rollup-plugin-peer-deps-external": "^2.2.2",
116
- "rollup-plugin-prettier": "^2.1.0",
117
- "rollup-plugin-size": "^0.2.2",
118
- "rollup-plugin-terser": "^7.0.2",
119
- "rollup-plugin-visualizer": "^5.5.2",
120
- "stream-to-array": "^2.3.0",
121
- "ts-node": "^10.3.0",
122
- "tslib": "^2.3.1",
123
- "typescript": "^4.4.3"
124
42
  }
125
43
  }
package/src/index.tsx CHANGED
@@ -1,7 +1,56 @@
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
+ TableFactory,
13
+ } from '@tanstack/table-core'
14
+
15
+ export function useTable<TGenerics extends PartialGenerics>(
16
+ table: TableFactory<TGenerics>,
17
+ options: PartialKeys<
18
+ Omit<Options<TGenerics>, keyof CreateTableFactoryOptions<any, any, any>>,
19
+ 'state' | 'onStateChange'
20
+ >
21
+ ): TableInstance<TGenerics> {
22
+ // Compose in the generic options to the user options
23
+ const resolvedOptions = {
24
+ ...(table.__options ?? {}),
25
+ state: {}, // Dummy state
26
+ onStateChange: () => {}, // noop
27
+ ...options,
28
+ }
29
+
30
+ // Create a new table instance and store it in state
31
+ const [instance] = React.useState(() =>
32
+ createTableInstance<TGenerics>(resolvedOptions)
33
+ )
34
+
35
+ // By default, manage table state here using the instance's initial state
36
+ const [state, setState] = React.useState(() => instance.initialState)
37
+
38
+ // Compose the default state above with any user state. This will allow the user
39
+ // to only control a subset of the state if desired.
40
+ instance.setOptions(prev => ({
41
+ ...prev,
42
+ ...options,
43
+ state: {
44
+ ...state,
45
+ ...options.state,
46
+ },
47
+ // Similarly, we'll maintain both our internal state and any user-provided
48
+ // state.
49
+ onStateChange: updater => {
50
+ setState(updater)
51
+ options.onStateChange?.(updater)
52
+ },
53
+ }))
54
+
55
+ return instance
56
+ }