@tanstack/react-table 9.0.0-alpha.9 → 9.0.0-beta.2
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.
- package/README.md +127 -0
- package/dist/FlexRender.cjs +61 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +51 -0
- package/dist/FlexRender.d.ts +51 -0
- package/dist/FlexRender.js +58 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/Subscribe.cjs +13 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +101 -0
- package/dist/Subscribe.d.ts +101 -0
- package/dist/Subscribe.js +13 -0
- package/dist/Subscribe.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/createTableHook.cjs +313 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +358 -0
- package/dist/createTableHook.d.ts +358 -0
- package/dist/createTableHook.js +311 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/flex-render.cjs +5 -0
- package/dist/flex-render.d.cts +2 -0
- package/dist/flex-render.d.ts +2 -0
- package/dist/flex-render.js +3 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/legacy.cjs +14 -0
- package/dist/legacy.d.cts +2 -0
- package/dist/legacy.d.ts +2 -0
- package/dist/legacy.js +3 -0
- package/dist/reactivity.cjs +34 -0
- package/dist/reactivity.cjs.map +1 -0
- package/dist/reactivity.js +34 -0
- package/dist/reactivity.js.map +1 -0
- package/dist/static-functions.cjs +9 -0
- package/dist/static-functions.d.cts +1 -0
- package/dist/static-functions.d.ts +1 -0
- package/dist/static-functions.js +3 -0
- package/dist/useLegacyTable.cjs +191 -0
- package/dist/useLegacyTable.cjs.map +1 -0
- package/dist/useLegacyTable.d.cts +233 -0
- package/dist/useLegacyTable.d.ts +233 -0
- package/dist/useLegacyTable.js +181 -0
- package/dist/useLegacyTable.js.map +1 -0
- package/dist/useTable.cjs +72 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +122 -0
- package/dist/useTable.d.ts +122 -0
- package/dist/useTable.js +72 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +41 -22
- package/skills/react/client-to-server/SKILL.md +377 -0
- package/skills/react/compose-with-tanstack-form/SKILL.md +363 -0
- package/skills/react/compose-with-tanstack-pacer/SKILL.md +287 -0
- package/skills/react/compose-with-tanstack-query/SKILL.md +467 -0
- package/skills/react/compose-with-tanstack-store/SKILL.md +347 -0
- package/skills/react/compose-with-tanstack-virtual/SKILL.md +388 -0
- package/skills/react/compose-with-tanstack-virtual/references/column-virtualization-and-infinite-scroll.md +136 -0
- package/skills/react/getting-started/SKILL.md +388 -0
- package/skills/react/migrate-v8-to-v9/SKILL.md +488 -0
- package/skills/react/production-readiness/SKILL.md +341 -0
- package/skills/react/react-subscribe-compiler-compat/SKILL.md +269 -0
- package/skills/react/table-state/SKILL.md +432 -0
- package/src/FlexRender.tsx +136 -0
- package/src/Subscribe.ts +153 -0
- package/src/createTableHook.tsx +1121 -0
- package/src/flex-render.ts +1 -0
- package/src/index.ts +6 -0
- package/src/legacy.ts +3 -0
- package/src/reactivity.ts +41 -0
- package/src/static-functions.ts +1 -0
- package/src/useLegacyTable.ts +487 -0
- package/src/useTable.ts +191 -0
- package/dist/cjs/index.cjs +0 -77
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -9
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.js +0 -55
- package/dist/esm/index.js.map +0 -1
- package/src/index.tsx +0 -92
package/src/useTable.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from 'react'
|
|
4
|
+
import { constructTable } from '@tanstack/table-core'
|
|
5
|
+
import { shallow, useSelector } from '@tanstack/react-store'
|
|
6
|
+
import { reactReactivity } from './reactivity'
|
|
7
|
+
import { FlexRender } from './FlexRender'
|
|
8
|
+
import { Subscribe } from './Subscribe'
|
|
9
|
+
import type { FlexRenderProps } from './FlexRender'
|
|
10
|
+
import type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'
|
|
11
|
+
import type {
|
|
12
|
+
CellData,
|
|
13
|
+
RowData,
|
|
14
|
+
Table,
|
|
15
|
+
TableFeatures,
|
|
16
|
+
TableOptions,
|
|
17
|
+
TableState,
|
|
18
|
+
} from '@tanstack/table-core'
|
|
19
|
+
import type { FunctionComponent, ReactNode } from 'react'
|
|
20
|
+
|
|
21
|
+
export type ReactTable<
|
|
22
|
+
TFeatures extends TableFeatures,
|
|
23
|
+
TData extends RowData,
|
|
24
|
+
TSelected = TableState<TFeatures>,
|
|
25
|
+
> = Omit<Table<TFeatures, TData>, 'store'> & {
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Prefer `table.state` for render reads,
|
|
28
|
+
* `table.atoms.<slice>.get()` for slice snapshots, or
|
|
29
|
+
* `table.Subscribe` / `useSelector(table.store, selector)` for explicit
|
|
30
|
+
* subscriptions. `table.store.state` is a current-value snapshot and is easy
|
|
31
|
+
* to misuse in render code.
|
|
32
|
+
*/
|
|
33
|
+
readonly store: Table<TFeatures, TData>['store']
|
|
34
|
+
/**
|
|
35
|
+
* A React HOC (Higher Order Component) that allows you to subscribe to the table state.
|
|
36
|
+
*
|
|
37
|
+
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
38
|
+
*
|
|
39
|
+
* Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
|
|
40
|
+
* or `table.optionsStore`) instead of the full `table.store`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
44
|
+
* {({ rowSelection }) => (
|
|
45
|
+
* <tr key={row.id}>...</tr>
|
|
46
|
+
* )}
|
|
47
|
+
* </table.Subscribe>
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* <table.Subscribe source={table.atoms.rowSelection}>
|
|
51
|
+
* {(rowSelection) => <div>...</div>}
|
|
52
|
+
* </table.Subscribe>
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
|
|
56
|
+
* {() => <tr key={row.id}>...</tr>}
|
|
57
|
+
* </table.Subscribe>
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Overloads (not a single union) so `selector` callbacks get correct contextual
|
|
61
|
+
* types in JSX; a union of two `selector` signatures degrades to implicit `any`.
|
|
62
|
+
*
|
|
63
|
+
* Source **without** `selector` is a separate overload so children receive `TSourceValue`
|
|
64
|
+
* (identity projection). If `selector` were optional on one overload, `TSubSelected`
|
|
65
|
+
* would default to `unknown` instead of inferring from the source.
|
|
66
|
+
*
|
|
67
|
+
* The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
|
|
68
|
+
*/
|
|
69
|
+
Subscribe: {
|
|
70
|
+
<TSourceValue>(props: {
|
|
71
|
+
source: SubscribeSource<TSourceValue>
|
|
72
|
+
selector?: undefined
|
|
73
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode
|
|
74
|
+
}): ReturnType<FunctionComponent>
|
|
75
|
+
<TSourceValue, TSubSelected>(props: {
|
|
76
|
+
source: SubscribeSource<TSourceValue>
|
|
77
|
+
selector: (state: TSourceValue) => TSubSelected
|
|
78
|
+
children: ((state: TSubSelected) => ReactNode) | ReactNode
|
|
79
|
+
}): ReturnType<FunctionComponent>
|
|
80
|
+
<TSubSelected>(
|
|
81
|
+
props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,
|
|
82
|
+
): ReturnType<FunctionComponent>
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A React component that renders headers, cells, or footers with custom markup.
|
|
86
|
+
* Use this utility component instead of manually calling flexRender.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* <table.FlexRender cell={cell} />
|
|
91
|
+
* <table.FlexRender header={header} />
|
|
92
|
+
* <table.FlexRender footer={footer} />
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* This replaces calling `flexRender` directly like this:
|
|
96
|
+
* ```tsx
|
|
97
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
98
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
99
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
FlexRender: <TValue extends CellData = CellData>(
|
|
103
|
+
props: FlexRenderProps<TFeatures, TData, TValue>,
|
|
104
|
+
) => ReactNode
|
|
105
|
+
/**
|
|
106
|
+
* The selected state of the table. This state may not match the structure of
|
|
107
|
+
* the full table state because it is selected by the selector function that
|
|
108
|
+
* you pass as the 2nd argument to `useTable`.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
112
|
+
*
|
|
113
|
+
* console.log(table.state.globalFilter)
|
|
114
|
+
*/
|
|
115
|
+
readonly state: Readonly<TSelected>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a React table instance backed by TanStack Store atoms.
|
|
120
|
+
*
|
|
121
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
122
|
+
* exposed on `table.state` and compared shallowly for React re-renders. Omit
|
|
123
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
124
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
125
|
+
* subscriptions.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const table = useTable(
|
|
130
|
+
* {
|
|
131
|
+
* features,
|
|
132
|
+
* rowModels: {},
|
|
133
|
+
* columns,
|
|
134
|
+
* data,
|
|
135
|
+
* },
|
|
136
|
+
* (state) => ({ pagination: state.pagination }),
|
|
137
|
+
* )
|
|
138
|
+
*
|
|
139
|
+
* table.state.pagination
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function useTable<
|
|
143
|
+
TFeatures extends TableFeatures,
|
|
144
|
+
TData extends RowData,
|
|
145
|
+
TSelected = TableState<TFeatures>,
|
|
146
|
+
>(
|
|
147
|
+
tableOptions: TableOptions<TFeatures, TData>,
|
|
148
|
+
selector?: (state: TableState<TFeatures>) => TSelected,
|
|
149
|
+
): ReactTable<TFeatures, TData, TSelected> {
|
|
150
|
+
const [table] = useState(() => {
|
|
151
|
+
const tableInstance = constructTable({
|
|
152
|
+
...tableOptions,
|
|
153
|
+
features: {
|
|
154
|
+
coreReativityFeature: reactReactivity(),
|
|
155
|
+
...tableOptions.features,
|
|
156
|
+
},
|
|
157
|
+
}) as unknown as ReactTable<TFeatures, TData, TSelected>
|
|
158
|
+
|
|
159
|
+
tableInstance.Subscribe = ((props: any) => {
|
|
160
|
+
const source = props.source ?? tableInstance.store
|
|
161
|
+
|
|
162
|
+
return Subscribe({
|
|
163
|
+
...props,
|
|
164
|
+
source,
|
|
165
|
+
})
|
|
166
|
+
}) as ReactTable<TFeatures, TData, TSelected>['Subscribe']
|
|
167
|
+
|
|
168
|
+
tableInstance.FlexRender = FlexRender
|
|
169
|
+
|
|
170
|
+
return tableInstance
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
// sync options on every render
|
|
174
|
+
table.setOptions((prev) => ({
|
|
175
|
+
...prev,
|
|
176
|
+
...tableOptions,
|
|
177
|
+
}))
|
|
178
|
+
|
|
179
|
+
const state = useSelector(table.store, selector, { compare: shallow })
|
|
180
|
+
|
|
181
|
+
// we know this is not the most efficient way to return the table,
|
|
182
|
+
// but it is required for the react compiler to work
|
|
183
|
+
return useMemo(
|
|
184
|
+
() => ({
|
|
185
|
+
...table,
|
|
186
|
+
options: tableOptions,
|
|
187
|
+
state,
|
|
188
|
+
}),
|
|
189
|
+
[table, tableOptions, state],
|
|
190
|
+
)
|
|
191
|
+
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const React = require("react");
|
|
5
|
-
const tableCore = require("@tanstack/table-core");
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e) {
|
|
9
|
-
for (const k in e) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
|
-
function flexRender(Comp, props) {
|
|
24
|
-
return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...props }) : Comp;
|
|
25
|
-
}
|
|
26
|
-
function isReactComponent(component) {
|
|
27
|
-
return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
|
|
28
|
-
}
|
|
29
|
-
function isClassComponent(component) {
|
|
30
|
-
return typeof component === "function" && (() => {
|
|
31
|
-
const proto = Object.getPrototypeOf(component);
|
|
32
|
-
return proto.prototype && proto.prototype.isReactComponent;
|
|
33
|
-
})();
|
|
34
|
-
}
|
|
35
|
-
function isExoticComponent(component) {
|
|
36
|
-
return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
|
|
37
|
-
}
|
|
38
|
-
function useTable(options) {
|
|
39
|
-
const resolvedOptions = {
|
|
40
|
-
state: {},
|
|
41
|
-
// Dummy state
|
|
42
|
-
onStateChange: () => {
|
|
43
|
-
},
|
|
44
|
-
// noop
|
|
45
|
-
renderFallbackValue: null,
|
|
46
|
-
...options
|
|
47
|
-
};
|
|
48
|
-
const [tableRef] = React__namespace.useState(() => ({
|
|
49
|
-
current: tableCore._createTable(resolvedOptions)
|
|
50
|
-
}));
|
|
51
|
-
const [state, setState] = React__namespace.useState(() => tableRef.current.initialState);
|
|
52
|
-
tableRef.current.setOptions((prev) => ({
|
|
53
|
-
...prev,
|
|
54
|
-
...options,
|
|
55
|
-
state: {
|
|
56
|
-
...state,
|
|
57
|
-
...options.state
|
|
58
|
-
},
|
|
59
|
-
// Similarly, we'll maintain both our internal state and any user-provided
|
|
60
|
-
// state.
|
|
61
|
-
onStateChange: (updater) => {
|
|
62
|
-
var _a;
|
|
63
|
-
setState(updater);
|
|
64
|
-
(_a = options.onStateChange) == null ? void 0 : _a.call(options, updater);
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
return tableRef.current;
|
|
68
|
-
}
|
|
69
|
-
exports.flexRender = flexRender;
|
|
70
|
-
exports.useTable = useTable;
|
|
71
|
-
Object.keys(tableCore).forEach((k) => {
|
|
72
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: () => tableCore[k]
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n _createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\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\nexport function useTable<TData extends RowData>(options: TableOptions<TData>) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: _createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.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 tableRef.current.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 tableRef.current\n}\n"],"names":["jsx","React","_createTable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBgB,SAAA,WACd,MACA,OAC+B;AACxB,SAAA,CAAC,OAAO,OAAO,iBAAyB,IAAI,IAChDA,+BAAA,MAAA,EAAM,GAAG,MAAO,CAAA,IAEjB;AAEJ;AAEA,SAAS,iBACP,WAC0C;AAC1C,SACE,iBAAiB,SAAS,KAC1B,OAAO,cAAc,cACrB,kBAAkB,SAAS;AAE/B;AAEA,SAAS,iBAAiB,WAAgB;AAEtC,SAAA,OAAO,cAAc,eACpB,MAAM;AACC,UAAA,QAAQ,OAAO,eAAe,SAAS;AACtC,WAAA,MAAM,aAAa,MAAM,UAAU;AAAA,EAAA;AAGhD;AAEA,SAAS,kBAAkB,WAAgB;AACzC,SACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,cAAc,mBAAmB,EAAE,SAAS,UAAU,SAAS,WAAW;AAE/E;AAEO,SAAS,SAAgC,SAA8B;AAE5E,QAAM,kBAA+C;AAAA,IACnD,OAAO,CAAC;AAAA;AAAA,IACR,eAAe,MAAM;AAAA,IAAC;AAAA;AAAA,IACtB,qBAAqB;AAAA,IACrB,GAAG;AAAA,EAAA;AAIL,QAAM,CAAC,QAAQ,IAAIC,iBAAM,SAAS,OAAO;AAAA,IACvC,SAASC,uBAAoB,eAAe;AAAA,EAC5C,EAAA;AAGI,QAAA,CAAC,OAAO,QAAQ,IAAID,iBAAM,SAAS,MAAM,SAAS,QAAQ,YAAY;AAInE,WAAA,QAAQ,WAAW,CAAS,UAAA;AAAA,IACnC,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG,QAAQ;AAAA,IACb;AAAA;AAAA;AAAA,IAGA,eAAe,CAAW,YAAA;;AACxB,eAAS,OAAO;AAChB,oBAAQ,kBAAR,iCAAwB;AAAA,IAC1B;AAAA,EACA,EAAA;AAEF,SAAO,SAAS;AAClB;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TableOptions, RowData } from '@tanstack/table-core';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
export * from '@tanstack/table-core';
|
|
4
|
-
export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>;
|
|
5
|
-
/**
|
|
6
|
-
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
7
|
-
*/
|
|
8
|
-
export declare function flexRender<TProps extends object>(Comp: Renderable<TProps>, props: TProps): React.ReactNode | JSX.Element;
|
|
9
|
-
export declare function useTable<TData extends RowData>(options: TableOptions<TData>): import('@tanstack/table-core').Table<TData>;
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TableOptions, RowData } from '@tanstack/table-core';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
export * from '@tanstack/table-core';
|
|
4
|
-
export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>;
|
|
5
|
-
/**
|
|
6
|
-
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
7
|
-
*/
|
|
8
|
-
export declare function flexRender<TProps extends object>(Comp: Renderable<TProps>, props: TProps): React.ReactNode | JSX.Element;
|
|
9
|
-
export declare function useTable<TData extends RowData>(options: TableOptions<TData>): import('@tanstack/table-core').Table<TData>;
|
package/dist/esm/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { _createTable } from "@tanstack/table-core";
|
|
4
|
-
export * from "@tanstack/table-core";
|
|
5
|
-
function flexRender(Comp, props) {
|
|
6
|
-
return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ jsx(Comp, { ...props }) : Comp;
|
|
7
|
-
}
|
|
8
|
-
function isReactComponent(component) {
|
|
9
|
-
return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
|
|
10
|
-
}
|
|
11
|
-
function isClassComponent(component) {
|
|
12
|
-
return typeof component === "function" && (() => {
|
|
13
|
-
const proto = Object.getPrototypeOf(component);
|
|
14
|
-
return proto.prototype && proto.prototype.isReactComponent;
|
|
15
|
-
})();
|
|
16
|
-
}
|
|
17
|
-
function isExoticComponent(component) {
|
|
18
|
-
return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
|
|
19
|
-
}
|
|
20
|
-
function useTable(options) {
|
|
21
|
-
const resolvedOptions = {
|
|
22
|
-
state: {},
|
|
23
|
-
// Dummy state
|
|
24
|
-
onStateChange: () => {
|
|
25
|
-
},
|
|
26
|
-
// noop
|
|
27
|
-
renderFallbackValue: null,
|
|
28
|
-
...options
|
|
29
|
-
};
|
|
30
|
-
const [tableRef] = React.useState(() => ({
|
|
31
|
-
current: _createTable(resolvedOptions)
|
|
32
|
-
}));
|
|
33
|
-
const [state, setState] = React.useState(() => tableRef.current.initialState);
|
|
34
|
-
tableRef.current.setOptions((prev) => ({
|
|
35
|
-
...prev,
|
|
36
|
-
...options,
|
|
37
|
-
state: {
|
|
38
|
-
...state,
|
|
39
|
-
...options.state
|
|
40
|
-
},
|
|
41
|
-
// Similarly, we'll maintain both our internal state and any user-provided
|
|
42
|
-
// state.
|
|
43
|
-
onStateChange: (updater) => {
|
|
44
|
-
var _a;
|
|
45
|
-
setState(updater);
|
|
46
|
-
(_a = options.onStateChange) == null ? void 0 : _a.call(options, updater);
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
49
|
-
return tableRef.current;
|
|
50
|
-
}
|
|
51
|
-
export {
|
|
52
|
-
flexRender,
|
|
53
|
-
useTable
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nexport * from '@tanstack/table-core'\n\nimport {\n TableOptions,\n TableOptionsResolved,\n RowData,\n _createTable,\n} from '@tanstack/table-core'\n\nexport type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>\n\n//\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps\n): React.ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\nfunction isReactComponent<TProps>(\n component: unknown\n): component is React.ComponentType<TProps> {\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\nexport function useTable<TData extends RowData>(options: TableOptions<TData>) {\n // Compose in the generic options to the user options\n const resolvedOptions: TableOptionsResolved<TData> = {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n ...options,\n }\n\n // Create a new table and store it in state\n const [tableRef] = React.useState(() => ({\n current: _createTable<TData>(resolvedOptions),\n }))\n\n // By default, manage table state here using the table's initial state\n const [state, setState] = React.useState(() => tableRef.current.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 tableRef.current.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 tableRef.current\n}\n"],"names":[],"mappings":";;;;AAiBgB,SAAA,WACd,MACA,OAC+B;AACxB,SAAA,CAAC,OAAO,OAAO,iBAAyB,IAAI,IAChD,oBAAA,MAAA,EAAM,GAAG,MAAO,CAAA,IAEjB;AAEJ;AAEA,SAAS,iBACP,WAC0C;AAC1C,SACE,iBAAiB,SAAS,KAC1B,OAAO,cAAc,cACrB,kBAAkB,SAAS;AAE/B;AAEA,SAAS,iBAAiB,WAAgB;AAEtC,SAAA,OAAO,cAAc,eACpB,MAAM;AACC,UAAA,QAAQ,OAAO,eAAe,SAAS;AACtC,WAAA,MAAM,aAAa,MAAM,UAAU;AAAA,EAAA;AAGhD;AAEA,SAAS,kBAAkB,WAAgB;AACzC,SACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,cAAc,mBAAmB,EAAE,SAAS,UAAU,SAAS,WAAW;AAE/E;AAEO,SAAS,SAAgC,SAA8B;AAE5E,QAAM,kBAA+C;AAAA,IACnD,OAAO,CAAC;AAAA;AAAA,IACR,eAAe,MAAM;AAAA,IAAC;AAAA;AAAA,IACtB,qBAAqB;AAAA,IACrB,GAAG;AAAA,EAAA;AAIL,QAAM,CAAC,QAAQ,IAAI,MAAM,SAAS,OAAO;AAAA,IACvC,SAAS,aAAoB,eAAe;AAAA,EAC5C,EAAA;AAGI,QAAA,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,YAAY;AAInE,WAAA,QAAQ,WAAW,CAAS,UAAA;AAAA,IACnC,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG,QAAQ;AAAA,IACb;AAAA;AAAA;AAAA,IAGA,eAAe,CAAW,YAAA;;AACxB,eAAS,OAAO;AAChB,oBAAQ,kBAAR,iCAAwB;AAAA,IAC1B;AAAA,EACA,EAAA;AAEF,SAAO,SAAS;AAClB;"}
|
package/src/index.tsx
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
export * from '@tanstack/table-core'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
TableOptions,
|
|
6
|
-
TableOptionsResolved,
|
|
7
|
-
RowData,
|
|
8
|
-
_createTable,
|
|
9
|
-
} from '@tanstack/table-core'
|
|
10
|
-
|
|
11
|
-
export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
17
|
-
*/
|
|
18
|
-
export function flexRender<TProps extends object>(
|
|
19
|
-
Comp: Renderable<TProps>,
|
|
20
|
-
props: TProps
|
|
21
|
-
): React.ReactNode | JSX.Element {
|
|
22
|
-
return !Comp ? null : isReactComponent<TProps>(Comp) ? (
|
|
23
|
-
<Comp {...props} />
|
|
24
|
-
) : (
|
|
25
|
-
Comp
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isReactComponent<TProps>(
|
|
30
|
-
component: unknown
|
|
31
|
-
): component is React.ComponentType<TProps> {
|
|
32
|
-
return (
|
|
33
|
-
isClassComponent(component) ||
|
|
34
|
-
typeof component === 'function' ||
|
|
35
|
-
isExoticComponent(component)
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isClassComponent(component: any) {
|
|
40
|
-
return (
|
|
41
|
-
typeof component === 'function' &&
|
|
42
|
-
(() => {
|
|
43
|
-
const proto = Object.getPrototypeOf(component)
|
|
44
|
-
return proto.prototype && proto.prototype.isReactComponent
|
|
45
|
-
})()
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isExoticComponent(component: any) {
|
|
50
|
-
return (
|
|
51
|
-
typeof component === 'object' &&
|
|
52
|
-
typeof component.$$typeof === 'symbol' &&
|
|
53
|
-
['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function useTable<TData extends RowData>(options: TableOptions<TData>) {
|
|
58
|
-
// Compose in the generic options to the user options
|
|
59
|
-
const resolvedOptions: TableOptionsResolved<TData> = {
|
|
60
|
-
state: {}, // Dummy state
|
|
61
|
-
onStateChange: () => {}, // noop
|
|
62
|
-
renderFallbackValue: null,
|
|
63
|
-
...options,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Create a new table and store it in state
|
|
67
|
-
const [tableRef] = React.useState(() => ({
|
|
68
|
-
current: _createTable<TData>(resolvedOptions),
|
|
69
|
-
}))
|
|
70
|
-
|
|
71
|
-
// By default, manage table state here using the table's initial state
|
|
72
|
-
const [state, setState] = React.useState(() => tableRef.current.initialState)
|
|
73
|
-
|
|
74
|
-
// Compose the default state above with any user state. This will allow the user
|
|
75
|
-
// to only control a subset of the state if desired.
|
|
76
|
-
tableRef.current.setOptions(prev => ({
|
|
77
|
-
...prev,
|
|
78
|
-
...options,
|
|
79
|
-
state: {
|
|
80
|
-
...state,
|
|
81
|
-
...options.state,
|
|
82
|
-
},
|
|
83
|
-
// Similarly, we'll maintain both our internal state and any user-provided
|
|
84
|
-
// state.
|
|
85
|
-
onStateChange: updater => {
|
|
86
|
-
setState(updater)
|
|
87
|
-
options.onStateChange?.(updater)
|
|
88
|
-
},
|
|
89
|
-
}))
|
|
90
|
-
|
|
91
|
-
return tableRef.current
|
|
92
|
-
}
|