@tanstack/react-table 9.0.0-alpha.4 → 9.0.0-alpha.40
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 +117 -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 +14 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +103 -0
- package/dist/Subscribe.d.ts +103 -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/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 +193 -0
- package/dist/useLegacyTable.cjs.map +1 -0
- package/dist/useLegacyTable.d.cts +234 -0
- package/dist/useLegacyTable.d.ts +234 -0
- package/dist/useLegacyTable.js +182 -0
- package/dist/useLegacyTable.js.map +1 -0
- package/dist/useTable.cjs +41 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +92 -0
- package/dist/useTable.d.ts +92 -0
- package/dist/useTable.js +40 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +37 -20
- package/src/FlexRender.tsx +147 -0
- package/src/Subscribe.ts +199 -0
- package/src/createTableHook.tsx +1118 -0
- package/src/flex-render.ts +1 -0
- package/src/index.ts +6 -0
- package/src/legacy.ts +3 -0
- package/src/static-functions.ts +1 -0
- package/src/useLegacyTable.ts +489 -0
- package/src/useTable.ts +160 -0
- package/dist/cjs/index.cjs +0 -78
- 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 -94
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./media/header_table.png" alt="TanStack Table">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://npmjs.com/package/@tanstack/react-table" target="\_parent">
|
|
9
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@tanstack/react-table.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/tanstack/table" target="\_parent">
|
|
12
|
+
<img alt="github stars" src="https://img.shields.io/github/stars/tanstack/react-table.svg?style=social&label=Star" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://bundlephobia.com/result?p=@tanstack/react-table@latest" target="\_parent">
|
|
15
|
+
<img alt="bundle size" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-table@latest" />
|
|
16
|
+
</a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<a href="#badge">
|
|
21
|
+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://bestofjs.org/projects/tanstack-table"><img alt="Best of JS" src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=TanStack%2Ftable%26since=daily" /></a>
|
|
24
|
+
<a href="https://twitter.com/tan_stack"><img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/></a>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
# TanStack Table
|
|
32
|
+
|
|
33
|
+
> [!NOTE]
|
|
34
|
+
> You may know TanStack Table by the adapter names:
|
|
35
|
+
>
|
|
36
|
+
> - [Angular Table](https://tanstack.com/table/alpha/docs/framework/angular/angular-table)
|
|
37
|
+
> - [Lit Table](https://tanstack.com/table/alpha/docs/framework/lit/lit-table)
|
|
38
|
+
> - [React Table](https://tanstack.com/table/alpha/docs/framework/react/react-table)
|
|
39
|
+
> - [Solid Table](https://tanstack.com/table/alpha/docs/framework/solid/solid-table)
|
|
40
|
+
> - [Svelte Table](https://tanstack.com/table/alpha/docs/framework/svelte/svelte-table)
|
|
41
|
+
> - [Vue Table](https://tanstack.com/table/alpha/docs/framework/vue/vue-table)
|
|
42
|
+
|
|
43
|
+
A headless table library for building powerful datagrids with full control over markup, styles, and behavior.
|
|
44
|
+
|
|
45
|
+
- Framework‑agnostic core with bindings for React, Vue & Solid
|
|
46
|
+
- 100% customizable — bring your own UI, components, and styles
|
|
47
|
+
- Sorting, filtering, grouping, aggregation & row selection
|
|
48
|
+
- Lightweight, virtualizable & server‑side friendly
|
|
49
|
+
|
|
50
|
+
### <a href="https://tanstack.com/table">Read the Docs →</a>
|
|
51
|
+
|
|
52
|
+
## Get Involved
|
|
53
|
+
|
|
54
|
+
- We welcome issues and pull requests!
|
|
55
|
+
- Participate in [GitHub discussions](https://github.com/TanStack/table/discussions)
|
|
56
|
+
- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
|
|
57
|
+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
|
|
58
|
+
|
|
59
|
+
## Partners
|
|
60
|
+
|
|
61
|
+
<table align="center">
|
|
62
|
+
<tr>
|
|
63
|
+
<td>
|
|
64
|
+
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
|
|
65
|
+
<picture>
|
|
66
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" />
|
|
67
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" />
|
|
68
|
+
<img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
|
|
69
|
+
</picture>
|
|
70
|
+
</a>
|
|
71
|
+
</td>
|
|
72
|
+
<td padding="20">
|
|
73
|
+
<a href="https://www.cloudflare.com?utm_source=tanstack">
|
|
74
|
+
<picture>
|
|
75
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" />
|
|
76
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" />
|
|
77
|
+
<img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
|
|
78
|
+
</picture>
|
|
79
|
+
</a>
|
|
80
|
+
</td>
|
|
81
|
+
<td>
|
|
82
|
+
<a href="https://ag-grid.com/react-data-grid/?utm_source=reacttable&utm_campaign=githubreacttable" style="display: flex; align-items: center; border: none;">
|
|
83
|
+
<picture>
|
|
84
|
+
<source media="(prefers-color-scheme: dark)" srcset="./media/ag-grid-dark.svg" height="40" />
|
|
85
|
+
<source media="(prefers-color-scheme: light)" srcset="./media/ag-grid-light.svg" height="40" />
|
|
86
|
+
<img src="https://raw.githubusercontent.com/tannerlinsley/files/master/partners/ag-grid.svg" height="60" alt="AG Grid" />
|
|
87
|
+
</picture>
|
|
88
|
+
</a>
|
|
89
|
+
</td>
|
|
90
|
+
</tr>
|
|
91
|
+
</table>
|
|
92
|
+
|
|
93
|
+
<div align="center">
|
|
94
|
+
<img src="./media/partner_logo.svg" alt="Table & you?" height="65">
|
|
95
|
+
<p>
|
|
96
|
+
We're looking for TanStack Table Partners to join our mission! Partner with us to push the boundaries of TanStack Table and build amazing things together.
|
|
97
|
+
</p>
|
|
98
|
+
<a href="mailto:partners@tanstack.com?subject=TanStack Table Partnership"><b>LET'S CHAT</b></a>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
## Explore the TanStack Ecosystem
|
|
102
|
+
|
|
103
|
+
- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
|
|
104
|
+
- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
|
|
105
|
+
- <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
|
|
106
|
+
- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
|
|
107
|
+
- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching <br/>
|
|
108
|
+
- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
|
|
109
|
+
- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
|
|
110
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
|
|
111
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
|
|
112
|
+
- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
|
|
113
|
+
- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
|
|
114
|
+
|
|
115
|
+
… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
|
|
116
|
+
|
|
117
|
+
<!-- USE THE FORCE LUKE -->
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let react = require("react");
|
|
3
|
+
react = require_runtime.__toESM(react);
|
|
4
|
+
|
|
5
|
+
//#region src/FlexRender.tsx
|
|
6
|
+
function isReactComponent(component) {
|
|
7
|
+
return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
|
|
8
|
+
}
|
|
9
|
+
function isClassComponent(component) {
|
|
10
|
+
return typeof component === "function" && (() => {
|
|
11
|
+
const proto = Object.getPrototypeOf(component);
|
|
12
|
+
return proto.prototype && proto.prototype.isReactComponent;
|
|
13
|
+
})();
|
|
14
|
+
}
|
|
15
|
+
function isExoticComponent(component) {
|
|
16
|
+
return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
20
|
+
* @example flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
21
|
+
*/
|
|
22
|
+
function flexRender(Comp, props) {
|
|
23
|
+
return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ react.default.createElement(Comp, props) : Comp;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
27
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <FlexRender cell={cell} />
|
|
31
|
+
* <FlexRender header={header} />
|
|
32
|
+
* <FlexRender footer={footer} />
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* This replaces calling `flexRender` directly like this:
|
|
36
|
+
* ```tsx
|
|
37
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
38
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
39
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function FlexRender(props) {
|
|
43
|
+
if ("cell" in props && props.cell) {
|
|
44
|
+
var _groupingCell$getIsAg, _groupingCell$getIsPl;
|
|
45
|
+
const cell = props.cell;
|
|
46
|
+
const def = cell.column.columnDef;
|
|
47
|
+
const groupingCell = cell;
|
|
48
|
+
const groupingDef = def;
|
|
49
|
+
if ((_groupingCell$getIsAg = groupingCell.getIsAggregated) === null || _groupingCell$getIsAg === void 0 ? void 0 : _groupingCell$getIsAg.call(groupingCell)) return flexRender(groupingDef.aggregatedCell ?? def.cell, cell.getContext());
|
|
50
|
+
if ((_groupingCell$getIsPl = groupingCell.getIsPlaceholder) === null || _groupingCell$getIsPl === void 0 ? void 0 : _groupingCell$getIsPl.call(groupingCell)) return null;
|
|
51
|
+
return flexRender(def.cell, cell.getContext());
|
|
52
|
+
}
|
|
53
|
+
if ("header" in props && props.header) return flexRender(props.header.column.columnDef.header, props.header.getContext());
|
|
54
|
+
if ("footer" in props && props.footer) return flexRender(props.footer.column.columnDef.footer, props.footer.getContext());
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.FlexRender = FlexRender;
|
|
60
|
+
exports.flexRender = flexRender;
|
|
61
|
+
//# sourceMappingURL=FlexRender.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlexRender.cjs","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import React from 'react'\nimport type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentType, JSX, ReactNode } from 'react'\n\nexport type Renderable<TProps> = ReactNode | ComponentType<TProps>\n\nfunction isReactComponent<TProps>(\n component: unknown,\n): component is 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\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps,\n): ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;;;AAYA,SAAS,iBACP,WACoC;AACpC,QACE,iBAAiB,UAAU,IAC3B,OAAO,cAAc,cACrB,kBAAkB,UAAU;;AAIhC,SAAS,iBAAiB,WAAgB;AACxC,QACE,OAAO,cAAc,qBACd;EACL,MAAM,QAAQ,OAAO,eAAe,UAAU;AAC9C,SAAO,MAAM,aAAa,MAAM,UAAU;KACxC;;AAIR,SAAS,kBAAkB,WAAgB;AACzC,QACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,cAAc,oBAAoB,CAAC,SAAS,UAAU,SAAS,YAAY;;;;;;AAQhF,SAAgB,WACd,MACA,OACyB;AACzB,QAAO,CAAC,OAAO,OAAO,iBAAyB,KAAK,GAClD,4CAAC,MAAS,MAAS,GAEnB;;;;;;;;;;;;;;;;;;;AA6CJ,SAAgB,WAId,OAAkD;AAClD,KAAI,UAAU,SAAS,MAAM,MAAM;;EACjC,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,KAAK,OAAO;EAYxB,MAAM,eAAe;EAIrB,MAAM,cAAc;AAGpB,+BAAI,aAAa,iHAAmB,CAClC,QAAO,WACL,YAAY,kBAAkB,IAAI,MAClC,KAAK,YAAY,CAClB;AAEH,+BAAI,aAAa,kHAAoB,CACnC,QAAO;AAET,SAAO,WAAW,IAAI,MAAM,KAAK,YAAY,CAAC;;AAEhD,KAAI,YAAY,SAAS,MAAM,OAC7B,QAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;AAEH,KAAI,YAAY,SAAS,MAAM,OAC7B,QAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;AAEH,QAAO"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { ComponentType, JSX, ReactNode } from "react";
|
|
2
|
+
import { Cell, CellData, Header, RowData, TableFeatures } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/FlexRender.d.ts
|
|
5
|
+
type Renderable<TProps> = ReactNode | ComponentType<TProps>;
|
|
6
|
+
/**
|
|
7
|
+
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
8
|
+
* @example flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
9
|
+
*/
|
|
10
|
+
declare function flexRender<TProps extends object>(Comp: Renderable<TProps>, props: TProps): ReactNode | JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
13
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
14
|
+
* @example <FlexRender cell={cell} />
|
|
15
|
+
* @example <FlexRender header={header} />
|
|
16
|
+
* @example <FlexRender footer={footer} />
|
|
17
|
+
*/
|
|
18
|
+
type FlexRenderProps<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = {
|
|
19
|
+
cell: Cell<TFeatures, TData, TValue>;
|
|
20
|
+
header?: never;
|
|
21
|
+
footer?: never;
|
|
22
|
+
} | {
|
|
23
|
+
header: Header<TFeatures, TData, TValue>;
|
|
24
|
+
cell?: never;
|
|
25
|
+
footer?: never;
|
|
26
|
+
} | {
|
|
27
|
+
footer: Header<TFeatures, TData, TValue>;
|
|
28
|
+
cell?: never;
|
|
29
|
+
header?: never;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
33
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <FlexRender cell={cell} />
|
|
37
|
+
* <FlexRender header={header} />
|
|
38
|
+
* <FlexRender footer={footer} />
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* This replaces calling `flexRender` directly like this:
|
|
42
|
+
* ```tsx
|
|
43
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
44
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
45
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function FlexRender<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | JSX.Element | null | undefined;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FlexRender, FlexRenderProps, Renderable, flexRender };
|
|
51
|
+
//# sourceMappingURL=FlexRender.d.cts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Cell, CellData, Header, RowData, TableFeatures } from "@tanstack/table-core";
|
|
2
|
+
import React, { ComponentType, JSX, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/FlexRender.d.ts
|
|
5
|
+
type Renderable<TProps> = ReactNode | ComponentType<TProps>;
|
|
6
|
+
/**
|
|
7
|
+
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
8
|
+
* @example flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
9
|
+
*/
|
|
10
|
+
declare function flexRender<TProps extends object>(Comp: Renderable<TProps>, props: TProps): ReactNode | JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
13
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
14
|
+
* @example <FlexRender cell={cell} />
|
|
15
|
+
* @example <FlexRender header={header} />
|
|
16
|
+
* @example <FlexRender footer={footer} />
|
|
17
|
+
*/
|
|
18
|
+
type FlexRenderProps<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = {
|
|
19
|
+
cell: Cell<TFeatures, TData, TValue>;
|
|
20
|
+
header?: never;
|
|
21
|
+
footer?: never;
|
|
22
|
+
} | {
|
|
23
|
+
header: Header<TFeatures, TData, TValue>;
|
|
24
|
+
cell?: never;
|
|
25
|
+
footer?: never;
|
|
26
|
+
} | {
|
|
27
|
+
footer: Header<TFeatures, TData, TValue>;
|
|
28
|
+
cell?: never;
|
|
29
|
+
header?: never;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
33
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <FlexRender cell={cell} />
|
|
37
|
+
* <FlexRender header={header} />
|
|
38
|
+
* <FlexRender footer={footer} />
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* This replaces calling `flexRender` directly like this:
|
|
42
|
+
* ```tsx
|
|
43
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
44
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
45
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function FlexRender<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | JSX.Element | null | undefined;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FlexRender, FlexRenderProps, Renderable, flexRender };
|
|
51
|
+
//# sourceMappingURL=FlexRender.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/FlexRender.tsx
|
|
4
|
+
function isReactComponent(component) {
|
|
5
|
+
return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
|
|
6
|
+
}
|
|
7
|
+
function isClassComponent(component) {
|
|
8
|
+
return typeof component === "function" && (() => {
|
|
9
|
+
const proto = Object.getPrototypeOf(component);
|
|
10
|
+
return proto.prototype && proto.prototype.isReactComponent;
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
13
|
+
function isExoticComponent(component) {
|
|
14
|
+
return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
|
|
18
|
+
* @example flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
19
|
+
*/
|
|
20
|
+
function flexRender(Comp, props) {
|
|
21
|
+
return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ React.createElement(Comp, props) : Comp;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.
|
|
25
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <FlexRender cell={cell} />
|
|
29
|
+
* <FlexRender header={header} />
|
|
30
|
+
* <FlexRender footer={footer} />
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* This replaces calling `flexRender` directly like this:
|
|
34
|
+
* ```tsx
|
|
35
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
36
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
37
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function FlexRender(props) {
|
|
41
|
+
if ("cell" in props && props.cell) {
|
|
42
|
+
var _groupingCell$getIsAg, _groupingCell$getIsPl;
|
|
43
|
+
const cell = props.cell;
|
|
44
|
+
const def = cell.column.columnDef;
|
|
45
|
+
const groupingCell = cell;
|
|
46
|
+
const groupingDef = def;
|
|
47
|
+
if ((_groupingCell$getIsAg = groupingCell.getIsAggregated) === null || _groupingCell$getIsAg === void 0 ? void 0 : _groupingCell$getIsAg.call(groupingCell)) return flexRender(groupingDef.aggregatedCell ?? def.cell, cell.getContext());
|
|
48
|
+
if ((_groupingCell$getIsPl = groupingCell.getIsPlaceholder) === null || _groupingCell$getIsPl === void 0 ? void 0 : _groupingCell$getIsPl.call(groupingCell)) return null;
|
|
49
|
+
return flexRender(def.cell, cell.getContext());
|
|
50
|
+
}
|
|
51
|
+
if ("header" in props && props.header) return flexRender(props.header.column.columnDef.header, props.header.getContext());
|
|
52
|
+
if ("footer" in props && props.footer) return flexRender(props.footer.column.columnDef.footer, props.footer.getContext());
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { FlexRender, flexRender };
|
|
58
|
+
//# sourceMappingURL=FlexRender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlexRender.js","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import React from 'react'\nimport type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentType, JSX, ReactNode } from 'react'\n\nexport type Renderable<TProps> = ReactNode | ComponentType<TProps>\n\nfunction isReactComponent<TProps>(\n component: unknown,\n): component is 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\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps>,\n props: TProps,\n): ReactNode | JSX.Element {\n return !Comp ? null : isReactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;AAYA,SAAS,iBACP,WACoC;AACpC,QACE,iBAAiB,UAAU,IAC3B,OAAO,cAAc,cACrB,kBAAkB,UAAU;;AAIhC,SAAS,iBAAiB,WAAgB;AACxC,QACE,OAAO,cAAc,qBACd;EACL,MAAM,QAAQ,OAAO,eAAe,UAAU;AAC9C,SAAO,MAAM,aAAa,MAAM,UAAU;KACxC;;AAIR,SAAS,kBAAkB,WAAgB;AACzC,QACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,cAAc,oBAAoB,CAAC,SAAS,UAAU,SAAS,YAAY;;;;;;AAQhF,SAAgB,WACd,MACA,OACyB;AACzB,QAAO,CAAC,OAAO,OAAO,iBAAyB,KAAK,GAClD,oCAAC,MAAS,MAAS,GAEnB;;;;;;;;;;;;;;;;;;;AA6CJ,SAAgB,WAId,OAAkD;AAClD,KAAI,UAAU,SAAS,MAAM,MAAM;;EACjC,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,KAAK,OAAO;EAYxB,MAAM,eAAe;EAIrB,MAAM,cAAc;AAGpB,+BAAI,aAAa,iHAAmB,CAClC,QAAO,WACL,YAAY,kBAAkB,IAAI,MAClC,KAAK,YAAY,CAClB;AAEH,+BAAI,aAAa,kHAAoB,CACnC,QAAO;AAET,SAAO,WAAW,IAAI,MAAM,KAAK,YAAY,CAAC;;AAEhD,KAAI,YAAY,SAAS,MAAM,OAC7B,QAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;AAEH,KAAI,YAAY,SAAS,MAAM,OAC7B,QAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;AAEH,QAAO"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
let _tanstack_react_store = require("@tanstack/react-store");
|
|
5
|
+
|
|
6
|
+
//#region src/Subscribe.ts
|
|
7
|
+
function Subscribe(props) {
|
|
8
|
+
const selected = (0, _tanstack_react_store.useSelector)("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_react_store.shallow });
|
|
9
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.Subscribe = Subscribe;
|
|
14
|
+
//# sourceMappingURL=Subscribe.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscribe.cjs","names":["shallow"],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store). The selector\n * receives the source value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected). Prefer\n * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\n/**\n * A React component that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX\n * contextual typing works. This standalone component uses a union `props` type.\n *\n * @example\n * ```tsx\n * // As a standalone component — full store\n * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Entire source (atom or store) — no selector\n * <Subscribe table={table} source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project source value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * source={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection?.[row.id]}\n * >\n * {(selected) => <tr data-selected={!!selected}>...</tr>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // As table.Subscribe (table instance method)\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </table.Subscribe>\n * ```\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n source,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ReactNode)(selected)\n : props.children\n}\n"],"mappings":";;;;;;AA8KA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,kDAJS,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMpE,EACE,SAASA,+BACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FunctionComponent, ReactNode } from "react";
|
|
2
|
+
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
4
|
+
|
|
5
|
+
//#region src/Subscribe.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to `table.store` (full table state). The selector receives the full
|
|
8
|
+
* {@link TableState}.
|
|
9
|
+
*/
|
|
10
|
+
type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
|
|
11
|
+
table: Table<TFeatures, TData>;
|
|
12
|
+
/**
|
|
13
|
+
* Select from full table state. Re-renders when the selected value changes
|
|
14
|
+
* (shallow compare).
|
|
15
|
+
*
|
|
16
|
+
* Required in store mode so you never accidentally subscribe to the whole
|
|
17
|
+
* store without an explicit projection.
|
|
18
|
+
*/
|
|
19
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
20
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
24
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
25
|
+
* selector — children receive `TSourceValue`.
|
|
26
|
+
*/
|
|
27
|
+
type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
|
|
28
|
+
table: Table<TFeatures, TData>;
|
|
29
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
30
|
+
selector?: undefined;
|
|
31
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
35
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
36
|
+
*/
|
|
37
|
+
type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
|
|
38
|
+
table: Table<TFeatures, TData>;
|
|
39
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
40
|
+
selector: (state: TSourceValue) => TSelected;
|
|
41
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
46
|
+
* for clearer inference when `selector` is omitted.
|
|
47
|
+
*/
|
|
48
|
+
type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
50
|
+
/**
|
|
51
|
+
* A React component that allows you to subscribe to the table state.
|
|
52
|
+
*
|
|
53
|
+
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
54
|
+
*
|
|
55
|
+
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
|
|
56
|
+
* contextual typing works. This standalone component uses a union `props` type.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* // As a standalone component — full store
|
|
61
|
+
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
62
|
+
* {({ rowSelection }) => (
|
|
63
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
64
|
+
* )}
|
|
65
|
+
* </Subscribe>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* // Entire source (atom or store) — no selector
|
|
71
|
+
* <Subscribe table={table} source={table.atoms.rowSelection}>
|
|
72
|
+
* {(rowSelection) => <div>...</div>}
|
|
73
|
+
* </Subscribe>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // Project source value (e.g. one row’s selection)
|
|
79
|
+
* <Subscribe
|
|
80
|
+
* table={table}
|
|
81
|
+
* source={table.atoms.rowSelection}
|
|
82
|
+
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
|
+
* >
|
|
84
|
+
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
85
|
+
* </Subscribe>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* // As table.Subscribe (table instance method)
|
|
91
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
92
|
+
* {({ rowSelection }) => (
|
|
93
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
94
|
+
* )}
|
|
95
|
+
* </table.Subscribe>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
101
|
+
//#endregion
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
|
|
103
|
+
//# sourceMappingURL=Subscribe.d.cts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
2
|
+
import { FunctionComponent, ReactNode } from "react";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
4
|
+
|
|
5
|
+
//#region src/Subscribe.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to `table.store` (full table state). The selector receives the full
|
|
8
|
+
* {@link TableState}.
|
|
9
|
+
*/
|
|
10
|
+
type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
|
|
11
|
+
table: Table<TFeatures, TData>;
|
|
12
|
+
/**
|
|
13
|
+
* Select from full table state. Re-renders when the selected value changes
|
|
14
|
+
* (shallow compare).
|
|
15
|
+
*
|
|
16
|
+
* Required in store mode so you never accidentally subscribe to the whole
|
|
17
|
+
* store without an explicit projection.
|
|
18
|
+
*/
|
|
19
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
20
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
24
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
25
|
+
* selector — children receive `TSourceValue`.
|
|
26
|
+
*/
|
|
27
|
+
type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
|
|
28
|
+
table: Table<TFeatures, TData>;
|
|
29
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
30
|
+
selector?: undefined;
|
|
31
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
35
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
36
|
+
*/
|
|
37
|
+
type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
|
|
38
|
+
table: Table<TFeatures, TData>;
|
|
39
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
40
|
+
selector: (state: TSourceValue) => TSelected;
|
|
41
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
46
|
+
* for clearer inference when `selector` is omitted.
|
|
47
|
+
*/
|
|
48
|
+
type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
50
|
+
/**
|
|
51
|
+
* A React component that allows you to subscribe to the table state.
|
|
52
|
+
*
|
|
53
|
+
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
54
|
+
*
|
|
55
|
+
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
|
|
56
|
+
* contextual typing works. This standalone component uses a union `props` type.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* // As a standalone component — full store
|
|
61
|
+
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
62
|
+
* {({ rowSelection }) => (
|
|
63
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
64
|
+
* )}
|
|
65
|
+
* </Subscribe>
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* // Entire source (atom or store) — no selector
|
|
71
|
+
* <Subscribe table={table} source={table.atoms.rowSelection}>
|
|
72
|
+
* {(rowSelection) => <div>...</div>}
|
|
73
|
+
* </Subscribe>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // Project source value (e.g. one row’s selection)
|
|
79
|
+
* <Subscribe
|
|
80
|
+
* table={table}
|
|
81
|
+
* source={table.atoms.rowSelection}
|
|
82
|
+
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
|
+
* >
|
|
84
|
+
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
85
|
+
* </Subscribe>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* // As table.Subscribe (table instance method)
|
|
91
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
92
|
+
* {({ rowSelection }) => (
|
|
93
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
94
|
+
* )}
|
|
95
|
+
* </table.Subscribe>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
101
|
+
//#endregion
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
|
|
103
|
+
//# sourceMappingURL=Subscribe.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { shallow, useSelector } from "@tanstack/react-store";
|
|
4
|
+
|
|
5
|
+
//#region src/Subscribe.ts
|
|
6
|
+
function Subscribe(props) {
|
|
7
|
+
const selected = useSelector("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
|
|
8
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Subscribe };
|
|
13
|
+
//# sourceMappingURL=Subscribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store). The selector\n * receives the source value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected). Prefer\n * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\n/**\n * A React component that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX\n * contextual typing works. This standalone component uses a union `props` type.\n *\n * @example\n * ```tsx\n * // As a standalone component — full store\n * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Entire source (atom or store) — no selector\n * <Subscribe table={table} source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project source value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * source={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection?.[row.id]}\n * >\n * {(selected) => <tr data-selected={!!selected}>...</tr>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // As table.Subscribe (table instance method)\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </table.Subscribe>\n * ```\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n source,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ReactNode)(selected)\n : props.children\n}\n"],"mappings":";;;;;AA8KA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,WAAW,YAJF,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMpE,EACE,SAAS,SACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|