@tanstack/react-table 0.0.1-alpha.9 → 8.0.0-alpha.14

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 +114 -0
  4. package/build/cjs/index.js.map +1 -0
  5. package/build/esm/index.js +99 -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 +13 -0
  10. package/build/umd/index.development.js +134 -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 +105 -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": "6958-111",
11
+ "name": "\u0000rollupPluginBabelHelpers.js"
12
+ },
13
+ {
14
+ "name": "packages/react-table/src/index.tsx",
15
+ "uid": "6958-113"
16
+ }
17
+ ]
18
+ }
19
+ ],
20
+ "isRoot": true
21
+ },
22
+ "nodeParts": {
23
+ "6958-111": {
24
+ "renderedLength": 410,
25
+ "gzipLength": 231,
26
+ "brotliLength": 0,
27
+ "mainUid": "6958-110"
28
+ },
29
+ "6958-113": {
30
+ "renderedLength": 2378,
31
+ "gzipLength": 855,
32
+ "brotliLength": 0,
33
+ "mainUid": "6958-112"
34
+ }
35
+ },
36
+ "nodeMetas": {
37
+ "6958-110": {
38
+ "id": "\u0000rollupPluginBabelHelpers.js",
39
+ "moduleParts": {
40
+ "index.production.js": "6958-111"
41
+ },
42
+ "imported": [],
43
+ "importedBy": [
44
+ {
45
+ "uid": "6958-112"
46
+ }
47
+ ]
48
+ },
49
+ "6958-112": {
50
+ "id": "/packages/react-table/src/index.tsx",
51
+ "moduleParts": {
52
+ "index.production.js": "6958-113"
53
+ },
54
+ "imported": [
55
+ {
56
+ "uid": "6958-110"
57
+ },
58
+ {
59
+ "uid": "6958-114"
60
+ },
61
+ {
62
+ "uid": "6958-115"
63
+ }
64
+ ],
65
+ "importedBy": [],
66
+ "isEntry": true
67
+ },
68
+ "6958-114": {
69
+ "id": "react",
70
+ "moduleParts": {},
71
+ "imported": [],
72
+ "importedBy": [
73
+ {
74
+ "uid": "6958-112"
75
+ }
76
+ ],
77
+ "isExternal": true
78
+ },
79
+ "6958-115": {
80
+ "id": "@tanstack/table-core",
81
+ "moduleParts": {},
82
+ "imported": [],
83
+ "importedBy": [
84
+ {
85
+ "uid": "6958-112"
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,13 @@
1
+ import * as React from 'react';
2
+ export * from '@tanstack/table-core';
3
+ import { PartialKeys, Options, TableInstance, CreateTableFactoryOptions, Table, AnyGenerics } from '@tanstack/table-core';
4
+ export declare type Renderable<TProps> = React.ReactNode | React.FunctionComponent<TProps> | React.Component<TProps>;
5
+ export declare const render: <TProps extends {}>(Comp: Renderable<TProps>, props: TProps) => React.ReactNode;
6
+ export declare type Render = typeof render;
7
+ declare const createTable: import("@tanstack/table-core").CreateTableFactory<import("@tanstack/table-core").Overwrite<Partial<import("@tanstack/table-core").DefaultGenerics>, {
8
+ Render: <TProps extends {}>(Comp: Renderable<TProps>, props: TProps) => React.ReactNode;
9
+ }>>, createTableFactory: <TGenerics extends Partial<import("@tanstack/table-core").DefaultGenerics>>(options?: CreateTableFactoryOptions<(<TProps extends {}>(Comp: Renderable<TProps>, props: TProps) => React.ReactNode), any, any, any> | undefined) => import("@tanstack/table-core").CreateTableFactory<import("@tanstack/table-core").Overwrite<TGenerics, {
10
+ Render: <TProps extends {}>(Comp: Renderable<TProps>, props: TProps) => React.ReactNode;
11
+ }>>;
12
+ export { createTable, createTableFactory };
13
+ export declare function useTable<TGenerics extends AnyGenerics>(table: Table<TGenerics>, options: PartialKeys<Omit<Options<TGenerics>, keyof CreateTableFactoryOptions<any, any, any, any>>, 'state' | 'onStateChange'>): TableInstance<TGenerics>;
@@ -0,0 +1,134 @@
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
+ var render = function render(Comp, props) {
56
+ return !Comp ? null : isReactComponent(Comp) ? /*#__PURE__*/React__namespace.createElement(Comp, props) : Comp;
57
+ };
58
+
59
+ function isReactComponent(component) {
60
+ return isClassComponent(component) || typeof component === 'function' || isExoticComponent(component);
61
+ }
62
+
63
+ function isClassComponent(component) {
64
+ return typeof component === 'function' && function () {
65
+ var proto = Object.getPrototypeOf(component);
66
+ return proto.prototype && proto.prototype.isReactComponent;
67
+ }();
68
+ }
69
+
70
+ function isExoticComponent(component) {
71
+ return typeof component === 'object' && typeof component.$$typeof === 'symbol' && ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description);
72
+ }
73
+
74
+ var _init = tableCore.init({
75
+ render: render
76
+ }),
77
+ createTable = _init.createTable,
78
+ createTableFactory = _init.createTableFactory;
79
+ function useTable(table, options) {
80
+ var _table$__options;
81
+
82
+ // Compose in the generic options to the user options
83
+ var resolvedOptions = _extends({}, (_table$__options = table.__options) != null ? _table$__options : {}, {
84
+ state: {},
85
+ // Dummy state
86
+ onStateChange: function onStateChange() {},
87
+ // noop
88
+ render: render
89
+ }, options); // Create a new table instance and store it in state
90
+
91
+
92
+ var _React$useState = React__namespace.useState(function () {
93
+ return tableCore.createTableInstance(resolvedOptions);
94
+ }),
95
+ instance = _React$useState[0]; // By default, manage table state here using the instance's initial state
96
+
97
+
98
+ var _React$useState2 = React__namespace.useState(function () {
99
+ return instance.initialState;
100
+ }),
101
+ state = _React$useState2[0],
102
+ setState = _React$useState2[1]; // Compose the default state above with any user state. This will allow the user
103
+ // to only control a subset of the state if desired.
104
+
105
+
106
+ instance.setOptions(function (prev) {
107
+ return _extends({}, prev, options, {
108
+ state: _extends({}, state, options.state),
109
+ // Similarly, we'll maintain both our internal state and any user-provided
110
+ // state.
111
+ onStateChange: function onStateChange(updater) {
112
+ setState(updater);
113
+ options.onStateChange == null ? void 0 : options.onStateChange(updater);
114
+ }
115
+ });
116
+ });
117
+ return instance;
118
+ }
119
+
120
+ exports.createTable = createTable;
121
+ exports.createTableFactory = createTableFactory;
122
+ exports.render = render;
123
+ exports.useTable = useTable;
124
+ Object.keys(tableCore).forEach(function (k) {
125
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
126
+ enumerable: true,
127
+ get: function () { return tableCore[k]; }
128
+ });
129
+ });
130
+
131
+ Object.defineProperty(exports, '__esModule', { value: true });
132
+
133
+ }));
134
+ //# 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 Table,\n init,\n AnyGenerics,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> =\n | React.ReactNode\n | React.FunctionComponent<TProps>\n | React.Component<TProps>\n\nexport const render = <TProps extends {}>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode =>\n !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp\n\nexport type Render = typeof render\n\nfunction isReactComponent(component: unknown): component is React.FC {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\nconst { createTable, createTableFactory } = init({ render })\n\nexport { createTable, createTableFactory }\n\nexport function useTable<TGenerics extends AnyGenerics>(\n table: Table<TGenerics>,\n options: PartialKeys<\n Omit<\n Options<TGenerics>,\n keyof CreateTableFactoryOptions<any, any, any, any>\n >,\n 'state' | 'onStateChange'\n >\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions: Options<TGenerics> = {\n ...(table.__options ?? {}),\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n render,\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":["render","Comp","props","isReactComponent","React","component","isClassComponent","isExoticComponent","proto","Object","getPrototypeOf","prototype","$$typeof","includes","description","init","createTable","createTableFactory","useTable","table","options","resolvedOptions","__options","state","onStateChange","useState","createTableInstance","instance","initialState","setState","setOptions","prev","updater"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAqBaA,MAAM,GAAG,SAATA,MAAS,CACpBC,IADoB,EAEpBC,KAFoB;EAAA,SAIpB,CAACD,IAAD,GAAQ,IAAR,GAAeE,gBAAgB,CAACF,IAAD,CAAhB,gBAAyBG,+BAAC,IAAD,EAAUF,KAAV,CAAzB,GAA+CD,IAJ1C;EAAA;;EAQtB,SAASE,gBAAT,CAA0BE,SAA1B,EAAqE;EACnE,SACEC,gBAAgB,CAACD,SAAD,CAAhB,IACA,OAAOA,SAAP,KAAqB,UADrB,IAEAE,iBAAiB,CAACF,SAAD,CAHnB;EAKD;;EAED,SAASC,gBAAT,CAA0BD,SAA1B,EAA0C;EACxC,SACE,OAAOA,SAAP,KAAqB,UAArB,IACC,YAAM;EACL,QAAMG,KAAK,GAAGC,MAAM,CAACC,cAAP,CAAsBL,SAAtB,CAAd;EACA,WAAOG,KAAK,CAACG,SAAN,IAAmBH,KAAK,CAACG,SAAN,CAAgBR,gBAA1C;EACD,GAHD,EAFF;EAOD;;EAED,SAASI,iBAAT,CAA2BF,SAA3B,EAA2C;EACzC,SACE,OAAOA,SAAP,KAAqB,QAArB,IACA,OAAOA,SAAS,CAACO,QAAjB,KAA8B,QAD9B,IAEA,CAAC,YAAD,EAAe,mBAAf,EAAoCC,QAApC,CAA6CR,SAAS,CAACO,QAAV,CAAmBE,WAAhE,CAHF;EAKD;;cAE2CC,cAAI,CAAC;EAAEf,EAAAA,MAAM,EAANA;EAAF,CAAD,CAAhD;EAAA,IAAQgB,WAAR,SAAQA,WAAR;EAAA,IAAqBC,kBAArB,SAAqBA;EAId,SAASC,QAAT,CACLC,KADK,EAELC,OAFK,EASqB;EAAA;;EAC1B;EACA,MAAMC,eAAmC,oCACnCF,KAAK,CAACG,SAD6B,+BAChB,EADgB;EAEvCC,IAAAA,KAAK,EAAE,EAFgC;EAE5B;EACXC,IAAAA,aAAa,EAAE,yBAAM,EAHkB;EAGd;EACzBxB,IAAAA,MAAM,EAANA;EAJuC,KAKpCoB,OALoC,CAAzC,CAF0B;;;EAW1B,wBAAmBhB,gBAAK,CAACqB,QAAN,CAAe;EAAA,WAChCC,6BAAmB,CAAYL,eAAZ,CADa;EAAA,GAAf,CAAnB;EAAA,MAAOM,QAAP,sBAX0B;;;EAgB1B,yBAA0BvB,gBAAK,CAACqB,QAAN,CAAe;EAAA,WAAME,QAAQ,CAACC,YAAf;EAAA,GAAf,CAA1B;EAAA,MAAOL,KAAP;EAAA,MAAcM,QAAd,uBAhB0B;EAmB1B;;;EACAF,EAAAA,QAAQ,CAACG,UAAT,CAAoB,UAAAC,IAAI;EAAA,wBACnBA,IADmB,EAEnBX,OAFmB;EAGtBG,MAAAA,KAAK,eACAA,KADA,EAEAH,OAAO,CAACG,KAFR,CAHiB;EAOtB;EACA;EACAC,MAAAA,aAAa,EAAE,uBAAAQ,OAAO,EAAI;EACxBH,QAAAA,QAAQ,CAACG,OAAD,CAAR;EACAZ,QAAAA,OAAO,CAACI,aAAR,oBAAAJ,OAAO,CAACI,aAAR,CAAwBQ,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 o=r(t);function a(){return a=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},a.apply(this,arguments)}var c=function(e,t){return e?function(e){return"function"==typeof e&&((t=Object.getPrototypeOf(e)).prototype&&t.prototype.isReactComponent);var t}(n=e)||"function"==typeof n||function(e){return"object"==typeof e&&"symbol"==typeof e.$$typeof&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}(n)?o.createElement(e,t):e:null;var n};var u=n.init({render:c}),f=u.createTable,i=u.createTableFactory;e.createTable=f,e.createTableFactory=i,e.render=c,e.useTable=function(e,t){var r,u=a({},null!=(r=e.__options)?r:{},{state:{},onStateChange:function(){},render:c},t),f=o.useState((function(){return n.createTableInstance(u)}))[0],i=o.useState((function(){return f.initialState})),l=i[0],s=i[1];return f.setOptions((function(e){return a({},e,t,{state:a({},l,t.state),onStateChange:function(e){s(e),null==t.onStateChange||t.onStateChange(e)}})})),f},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 Table,\n init,\n AnyGenerics,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> =\n | React.ReactNode\n | React.FunctionComponent<TProps>\n | React.Component<TProps>\n\nexport const render = <TProps extends {}>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode =>\n !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp\n\nexport type Render = typeof render\n\nfunction isReactComponent(component: unknown): component is React.FC {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isReactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)\n )\n}\n\nconst { createTable, createTableFactory } = init({ render })\n\nexport { createTable, createTableFactory }\n\nexport function useTable<TGenerics extends AnyGenerics>(\n table: Table<TGenerics>,\n options: PartialKeys<\n Omit<\n Options<TGenerics>,\n keyof CreateTableFactoryOptions<any, any, any, any>\n >,\n 'state' | 'onStateChange'\n >\n): TableInstance<TGenerics> {\n // Compose in the generic options to the user options\n const resolvedOptions: Options<TGenerics> = {\n ...(table.__options ?? {}),\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n render,\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":["render","Comp","props","component","proto","Object","getPrototypeOf","prototype","isReactComponent","isClassComponent","$$typeof","includes","description","isExoticComponent","React","init","createTable","createTableFactory","table","options","resolvedOptions","__options","state","onStateChange","instance","useState","createTableInstance","initialState","setState","setOptions","prev","updater"],"mappings":";;;;;;;;;;w1BAqBaA,EAAS,SACpBC,EACAC,UAECD,EAYH,SAA0BE,SAED,mBAAdA,KAECC,EAAQC,OAAOC,eAAeH,IACvBI,WAAaH,EAAMG,UAAUC,kBAF3C,IACOJ,EAVRK,CAFsBN,EAJQF,IAOT,mBAAdE,GAeX,SAA2BA,SAEF,iBAAdA,GACuB,iBAAvBA,EAAUO,UACjB,CAAC,aAAc,qBAAqBC,SAASR,EAAUO,SAASE,aAlBhEC,CAAkBV,GARoBW,gBAACb,EAASC,GAAYD,EAAtD,KAIV,IAA0BE,SA0BkBY,OAAK,CAAEf,OAAAA,IAA3CgB,IAAAA,YAAaC,IAAAA,gFAId,SACLC,EACAC,SASMC,gBACAF,EAAMG,aAAa,IACvBC,MAAO,GACPC,cAAe,aACfvB,OAAAA,GACGmB,GAIEK,EAAYV,EAAMW,UAAS,kBAChCC,sBAA+BN,WAIPN,EAAMW,UAAS,kBAAMD,EAASG,gBAAjDL,OAAOM,cAIdJ,EAASK,YAAW,SAAAC,eACfA,EACAX,GACHG,WACKA,EACAH,EAAQG,OAIbC,cAAe,SAAAQ,GACbH,EAASG,SACTZ,EAAQI,eAARJ,EAAQI,cAAgBQ,SAIrBP"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
- "version": "0.0.1-alpha.9",
3
+ "author": "Tanner Linsley",
4
+ "version": "8.0.0-alpha.14",
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,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
+ }