@tanstack/alpine-table 9.0.0-beta.0
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 +128 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/createTable.cjs +65 -0
- package/dist/createTable.cjs.map +1 -0
- package/dist/createTable.d.cts +18 -0
- package/dist/createTable.d.ts +18 -0
- package/dist/createTable.js +63 -0
- package/dist/createTable.js.map +1 -0
- package/dist/createTableHook.cjs +24 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +17 -0
- package/dist/createTableHook.d.ts +17 -0
- package/dist/createTableHook.js +24 -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/flexRender.cjs +40 -0
- package/dist/flexRender.cjs.map +1 -0
- package/dist/flexRender.d.cts +61 -0
- package/dist/flexRender.d.ts +61 -0
- package/dist/flexRender.js +38 -0
- package/dist/flexRender.js.map +1 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -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/package.json +68 -0
- package/src/createTable.ts +148 -0
- package/src/createTableHook.ts +48 -0
- package/src/flex-render.ts +1 -0
- package/src/flexRender.ts +100 -0
- package/src/index.ts +5 -0
- package/src/reactivity.ts +41 -0
- package/src/static-functions.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
> - [Alpine Table](https://tanstack.com/table/alpha/docs/framework/alpine/alpine-table)
|
|
43
|
+
|
|
44
|
+
A headless table library for building powerful datagrids with full control over markup, styles, and behavior.
|
|
45
|
+
|
|
46
|
+
- Framework‑agnostic core with bindings for React, Vue & Solid
|
|
47
|
+
- 100% customizable — bring your own UI, components, and styles
|
|
48
|
+
- Sorting, filtering, grouping, aggregation & row selection
|
|
49
|
+
- Lightweight, virtualizable & server‑side friendly
|
|
50
|
+
|
|
51
|
+
### <a href="https://tanstack.com/table">Read the Docs →</a>
|
|
52
|
+
|
|
53
|
+
## Using an AI Coding Agent?
|
|
54
|
+
|
|
55
|
+
TanStack Table ships [TanStack Intent](https://github.com/TanStack/intent) skills inside each adapter package. After installing the library, run:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npx @tanstack/intent@latest install
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
to add skill-loading guidance for your agent (Claude Code, Cursor, Copilot, etc.). The same CLI also exposes `intent list` to browse available skills and `intent load <skill>` to print one for inspection. Skills version with the library — your agent gets guidance that matches the version of `@tanstack/<framework>-table` you installed. Only available for v9 and above.
|
|
62
|
+
|
|
63
|
+
## Get Involved
|
|
64
|
+
|
|
65
|
+
- We welcome issues and pull requests!
|
|
66
|
+
- Participate in [GitHub discussions](https://github.com/TanStack/table/discussions)
|
|
67
|
+
- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
|
|
68
|
+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
|
|
69
|
+
|
|
70
|
+
## Partners
|
|
71
|
+
|
|
72
|
+
<table align="center">
|
|
73
|
+
<tr>
|
|
74
|
+
<td>
|
|
75
|
+
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
|
|
76
|
+
<picture>
|
|
77
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" />
|
|
78
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" />
|
|
79
|
+
<img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
|
|
80
|
+
</picture>
|
|
81
|
+
</a>
|
|
82
|
+
</td>
|
|
83
|
+
<td padding="20">
|
|
84
|
+
<a href="https://www.cloudflare.com?utm_source=tanstack">
|
|
85
|
+
<picture>
|
|
86
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" />
|
|
87
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" />
|
|
88
|
+
<img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
|
|
89
|
+
</picture>
|
|
90
|
+
</a>
|
|
91
|
+
</td>
|
|
92
|
+
<td>
|
|
93
|
+
<a href="https://ag-grid.com/react-data-grid/?utm_source=reacttable&utm_campaign=githubreacttable" style="display: flex; align-items: center; border: none;">
|
|
94
|
+
<picture>
|
|
95
|
+
<source media="(prefers-color-scheme: dark)" srcset="./media/ag-grid-dark.svg" height="40" />
|
|
96
|
+
<source media="(prefers-color-scheme: light)" srcset="./media/ag-grid-light.svg" height="40" />
|
|
97
|
+
<img src="https://raw.githubusercontent.com/tannerlinsley/files/master/partners/ag-grid.svg" height="60" alt="AG Grid" />
|
|
98
|
+
</picture>
|
|
99
|
+
</a>
|
|
100
|
+
</td>
|
|
101
|
+
</tr>
|
|
102
|
+
</table>
|
|
103
|
+
|
|
104
|
+
<div align="center">
|
|
105
|
+
<img src="./media/partner_logo.svg" alt="Table & you?" height="65">
|
|
106
|
+
<p>
|
|
107
|
+
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.
|
|
108
|
+
</p>
|
|
109
|
+
<a href="mailto:partners@tanstack.com?subject=TanStack Table Partnership"><b>LET'S CHAT</b></a>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
## Explore the TanStack Ecosystem
|
|
113
|
+
|
|
114
|
+
- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
|
|
115
|
+
- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
|
|
116
|
+
- <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
|
|
117
|
+
- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
|
|
118
|
+
- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching <br/>
|
|
119
|
+
- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
|
|
120
|
+
- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
|
|
121
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
|
|
122
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
|
|
123
|
+
- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
|
|
124
|
+
- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
|
|
125
|
+
|
|
126
|
+
… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
|
|
127
|
+
|
|
128
|
+
<!-- USE THE FORCE LUKE -->
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_flexRender = require('./flexRender.cjs');
|
|
3
|
+
const require_reactivity = require('./reactivity.cjs');
|
|
4
|
+
let _tanstack_table_core = require("@tanstack/table-core");
|
|
5
|
+
let alpinejs = require("alpinejs");
|
|
6
|
+
alpinejs = require_runtime.__toESM(alpinejs, 1);
|
|
7
|
+
|
|
8
|
+
//#region src/createTable.ts
|
|
9
|
+
function createTable(tableOptions) {
|
|
10
|
+
const table = (0, _tanstack_table_core.constructTable)({
|
|
11
|
+
...tableOptions,
|
|
12
|
+
features: {
|
|
13
|
+
coreReactivityFeature: require_reactivity.alpineReactivity(),
|
|
14
|
+
...tableOptions.features
|
|
15
|
+
},
|
|
16
|
+
mergeOptions: (defaultOptions, newOptions) => {
|
|
17
|
+
return {
|
|
18
|
+
...defaultOptions,
|
|
19
|
+
...newOptions
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
table.flexRender = require_flexRender.flexRender;
|
|
24
|
+
table.FlexRender = require_flexRender.FlexRender;
|
|
25
|
+
const reactivity = alpinejs.default.reactive({ _ver: 0 });
|
|
26
|
+
table.store.subscribe(() => {
|
|
27
|
+
reactivity._ver++;
|
|
28
|
+
});
|
|
29
|
+
let initialized = false;
|
|
30
|
+
alpinejs.default.effect(() => {
|
|
31
|
+
const state = tableOptions.state;
|
|
32
|
+
if (state) for (const key in state) state[key];
|
|
33
|
+
tableOptions.data;
|
|
34
|
+
table.setOptions((prev) => ({
|
|
35
|
+
...prev,
|
|
36
|
+
...tableOptions
|
|
37
|
+
}));
|
|
38
|
+
if (initialized) reactivity._ver++;
|
|
39
|
+
initialized = true;
|
|
40
|
+
});
|
|
41
|
+
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
const toReactiveProxy = (value) => {
|
|
43
|
+
if (typeof value !== "object" || value === null) return value;
|
|
44
|
+
if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet || value instanceof Date || value instanceof RegExp || value instanceof Promise) return value;
|
|
45
|
+
const cachedProxy = proxyCache.get(value);
|
|
46
|
+
if (cachedProxy) return cachedProxy;
|
|
47
|
+
const proxy = new Proxy(value, { get(target, prop, receiver) {
|
|
48
|
+
if (prop === "__v_skip") return true;
|
|
49
|
+
const resolvedValue = Reflect.get(target, prop, receiver);
|
|
50
|
+
if (typeof resolvedValue === "function") return (...args) => {
|
|
51
|
+
reactivity._ver;
|
|
52
|
+
return toReactiveProxy(resolvedValue.apply(target, args));
|
|
53
|
+
};
|
|
54
|
+
reactivity._ver;
|
|
55
|
+
return toReactiveProxy(resolvedValue);
|
|
56
|
+
} });
|
|
57
|
+
proxyCache.set(value, proxy);
|
|
58
|
+
return proxy;
|
|
59
|
+
};
|
|
60
|
+
return toReactiveProxy(table);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.createTable = createTable;
|
|
65
|
+
//# sourceMappingURL=createTable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTable.cjs","names":["alpineReactivity","flexRender","FlexRender","Alpine"],"sources":["../src/createTable.ts"],"sourcesContent":["import Alpine from 'alpinejs'\nimport { constructTable } from '@tanstack/table-core'\nimport { FlexRender, flexRender } from './flexRender'\nimport { alpineReactivity } from './reactivity'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n} from '@tanstack/table-core'\n\nexport type AlpineTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Table<TFeatures, TData> & {\n /**\n * A lower-level helper to render the content of a cell, header, or footer from a render function and its context.\n */\n flexRender: typeof flexRender\n\n /**\n * A convenience helper to render a cell, header, or footer object. Call from `x-html`, e.g. `FlexRender({ header })`.\n */\n FlexRender: typeof FlexRender\n}\n\nexport function createTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): AlpineTable<TFeatures, TData> {\n const mergedOptions: TableOptions<TFeatures, TData> = {\n ...tableOptions,\n features: {\n coreReactivityFeature: alpineReactivity(),\n ...tableOptions.features,\n },\n mergeOptions: (\n defaultOptions: TableOptions<TFeatures, TData>,\n newOptions: Partial<TableOptions<TFeatures, TData>>,\n ) => {\n return {\n ...defaultOptions,\n ...newOptions,\n }\n },\n }\n\n const table = constructTable(mergedOptions) as unknown as AlpineTable<\n TFeatures,\n TData\n >\n\n table.flexRender = flexRender\n table.FlexRender = FlexRender\n\n const reactivity = Alpine.reactive({ _ver: 0 })\n\n table.store.subscribe(() => {\n reactivity._ver++\n })\n\n // Reactively sync options when external Alpine-reactive getters change (e.g.\n // a `get data()` backed by `Alpine.reactive`). Reading the option getters\n // inside the effect registers the dependencies, so the effect re-runs when\n // they change and re-applies the live values via `setOptions`.\n //\n // `setOptions` writes to the options store, not the state store, so a `data`\n // (or other option) change does not emit on `table.store` and would not bump\n // `_ver` on its own. We bump `_ver` here so the template re-pulls derived\n // APIs like `getRowModel()`, which recompute from the new options. The effect\n // never reads `_ver`, so writing it does not re-trigger this effect.\n let initialized = false\n Alpine.effect(() => {\n const state = tableOptions.state as Record<string, unknown> | undefined\n if (state) {\n for (const key in state) {\n void state[key]\n }\n }\n void tableOptions.data\n\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n if (initialized) {\n reactivity._ver++\n }\n initialized = true\n })\n\n const proxyCache = new WeakMap<object, object>()\n\n const toReactiveProxy = <TValue>(value: TValue): TValue => {\n if (typeof value !== 'object' || value === null) {\n return value\n }\n\n // Built-in exotic objects (Map, Set, Date, etc.) rely on internal slots and\n // throw \"incompatible receiver\" when their getters/methods run with a Proxy\n // as the receiver (e.g. `getFacetedUniqueValues().size`). Return them as-is;\n // the read that produced them already tracked `_ver` at the call site.\n if (\n value instanceof Map ||\n value instanceof Set ||\n value instanceof WeakMap ||\n value instanceof WeakSet ||\n value instanceof Date ||\n value instanceof RegExp ||\n value instanceof Promise\n ) {\n return value\n }\n\n const cachedProxy = proxyCache.get(value)\n if (cachedProxy) {\n return cachedProxy as TValue\n }\n\n const proxy = new Proxy(value, {\n get(target, prop, receiver) {\n if (prop === '__v_skip') {\n return true\n }\n\n const resolvedValue = Reflect.get(target, prop, receiver)\n\n if (typeof resolvedValue === 'function') {\n return (...args: Array<unknown>) => {\n void reactivity._ver\n return toReactiveProxy(\n (resolvedValue as Function).apply(target, args),\n )\n }\n }\n\n void reactivity._ver\n return toReactiveProxy(resolvedValue)\n },\n })\n\n proxyCache.set(value, proxy)\n return proxy\n }\n\n return toReactiveProxy(table)\n}\n"],"mappings":";;;;;;;;AA0BA,SAAgB,YAGd,cAA6E;CAkB7E,MAAM,iDAAuB;EAhB3B,GAAG;EACH,UAAU;GACR,uBAAuBA,oCAAiB;GACxC,GAAG,aAAa;EAClB;EACA,eACE,gBACA,eACG;GACH,OAAO;IACL,GAAG;IACH,GAAG;GACL;EACF;CAGuC,CAAC;CAK1C,MAAM,aAAaC;CACnB,MAAM,aAAaC;CAEnB,MAAM,aAAaC,iBAAO,SAAS,EAAE,MAAM,EAAE,CAAC;CAE9C,MAAM,MAAM,gBAAgB;EAC1B,WAAW;CACb,CAAC;CAYD,IAAI,cAAc;CAClB,iBAAO,aAAa;EAClB,MAAM,QAAQ,aAAa;EAC3B,IAAI,OACF,KAAK,MAAM,OAAO,OAChB,AAAK,MAAM;EAGf,AAAK,aAAa;EAElB,MAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;EACL,EAAE;EAEF,IAAI,aACF,WAAW;EAEb,cAAc;CAChB,CAAC;CAED,MAAM,6BAAa,IAAI,QAAwB;CAE/C,MAAM,mBAA2B,UAA0B;EACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;EAOT,IACE,iBAAiB,OACjB,iBAAiB,OACjB,iBAAiB,WACjB,iBAAiB,WACjB,iBAAiB,QACjB,iBAAiB,UACjB,iBAAiB,SAEjB,OAAO;EAGT,MAAM,cAAc,WAAW,IAAI,KAAK;EACxC,IAAI,aACF,OAAO;EAGT,MAAM,QAAQ,IAAI,MAAM,OAAO,EAC7B,IAAI,QAAQ,MAAM,UAAU;GAC1B,IAAI,SAAS,YACX,OAAO;GAGT,MAAM,gBAAgB,QAAQ,IAAI,QAAQ,MAAM,QAAQ;GAExD,IAAI,OAAO,kBAAkB,YAC3B,QAAQ,GAAG,SAAyB;IAClC,AAAK,WAAW;IAChB,OAAO,gBACJ,cAA2B,MAAM,QAAQ,IAAI,CAChD;GACF;GAGF,AAAK,WAAW;GAChB,OAAO,gBAAgB,aAAa;EACtC,EACF,CAAC;EAED,WAAW,IAAI,OAAO,KAAK;EAC3B,OAAO;CACT;CAEA,OAAO,gBAAgB,KAAK;AAC9B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FlexRender, flexRender } from "./flexRender.cjs";
|
|
2
|
+
import { RowData, Table, TableFeatures, TableOptions } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/createTable.d.ts
|
|
5
|
+
type AlpineTable<TFeatures extends TableFeatures, TData extends RowData> = Table<TFeatures, TData> & {
|
|
6
|
+
/**
|
|
7
|
+
* A lower-level helper to render the content of a cell, header, or footer from a render function and its context.
|
|
8
|
+
*/
|
|
9
|
+
flexRender: typeof flexRender;
|
|
10
|
+
/**
|
|
11
|
+
* A convenience helper to render a cell, header, or footer object. Call from `x-html`, e.g. `FlexRender({ header })`.
|
|
12
|
+
*/
|
|
13
|
+
FlexRender: typeof FlexRender;
|
|
14
|
+
};
|
|
15
|
+
declare function createTable<TFeatures extends TableFeatures, TData extends RowData>(tableOptions: TableOptions<TFeatures, TData>): AlpineTable<TFeatures, TData>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AlpineTable, createTable };
|
|
18
|
+
//# sourceMappingURL=createTable.d.cts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FlexRender, flexRender } from "./flexRender.js";
|
|
2
|
+
import { RowData, Table, TableFeatures, TableOptions } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/createTable.d.ts
|
|
5
|
+
type AlpineTable<TFeatures extends TableFeatures, TData extends RowData> = Table<TFeatures, TData> & {
|
|
6
|
+
/**
|
|
7
|
+
* A lower-level helper to render the content of a cell, header, or footer from a render function and its context.
|
|
8
|
+
*/
|
|
9
|
+
flexRender: typeof flexRender;
|
|
10
|
+
/**
|
|
11
|
+
* A convenience helper to render a cell, header, or footer object. Call from `x-html`, e.g. `FlexRender({ header })`.
|
|
12
|
+
*/
|
|
13
|
+
FlexRender: typeof FlexRender;
|
|
14
|
+
};
|
|
15
|
+
declare function createTable<TFeatures extends TableFeatures, TData extends RowData>(tableOptions: TableOptions<TFeatures, TData>): AlpineTable<TFeatures, TData>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AlpineTable, createTable };
|
|
18
|
+
//# sourceMappingURL=createTable.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { FlexRender, flexRender } from "./flexRender.js";
|
|
2
|
+
import { alpineReactivity } from "./reactivity.js";
|
|
3
|
+
import { constructTable } from "@tanstack/table-core";
|
|
4
|
+
import Alpine from "alpinejs";
|
|
5
|
+
|
|
6
|
+
//#region src/createTable.ts
|
|
7
|
+
function createTable(tableOptions) {
|
|
8
|
+
const table = constructTable({
|
|
9
|
+
...tableOptions,
|
|
10
|
+
features: {
|
|
11
|
+
coreReactivityFeature: alpineReactivity(),
|
|
12
|
+
...tableOptions.features
|
|
13
|
+
},
|
|
14
|
+
mergeOptions: (defaultOptions, newOptions) => {
|
|
15
|
+
return {
|
|
16
|
+
...defaultOptions,
|
|
17
|
+
...newOptions
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
table.flexRender = flexRender;
|
|
22
|
+
table.FlexRender = FlexRender;
|
|
23
|
+
const reactivity = Alpine.reactive({ _ver: 0 });
|
|
24
|
+
table.store.subscribe(() => {
|
|
25
|
+
reactivity._ver++;
|
|
26
|
+
});
|
|
27
|
+
let initialized = false;
|
|
28
|
+
Alpine.effect(() => {
|
|
29
|
+
const state = tableOptions.state;
|
|
30
|
+
if (state) for (const key in state) state[key];
|
|
31
|
+
tableOptions.data;
|
|
32
|
+
table.setOptions((prev) => ({
|
|
33
|
+
...prev,
|
|
34
|
+
...tableOptions
|
|
35
|
+
}));
|
|
36
|
+
if (initialized) reactivity._ver++;
|
|
37
|
+
initialized = true;
|
|
38
|
+
});
|
|
39
|
+
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
40
|
+
const toReactiveProxy = (value) => {
|
|
41
|
+
if (typeof value !== "object" || value === null) return value;
|
|
42
|
+
if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet || value instanceof Date || value instanceof RegExp || value instanceof Promise) return value;
|
|
43
|
+
const cachedProxy = proxyCache.get(value);
|
|
44
|
+
if (cachedProxy) return cachedProxy;
|
|
45
|
+
const proxy = new Proxy(value, { get(target, prop, receiver) {
|
|
46
|
+
if (prop === "__v_skip") return true;
|
|
47
|
+
const resolvedValue = Reflect.get(target, prop, receiver);
|
|
48
|
+
if (typeof resolvedValue === "function") return (...args) => {
|
|
49
|
+
reactivity._ver;
|
|
50
|
+
return toReactiveProxy(resolvedValue.apply(target, args));
|
|
51
|
+
};
|
|
52
|
+
reactivity._ver;
|
|
53
|
+
return toReactiveProxy(resolvedValue);
|
|
54
|
+
} });
|
|
55
|
+
proxyCache.set(value, proxy);
|
|
56
|
+
return proxy;
|
|
57
|
+
};
|
|
58
|
+
return toReactiveProxy(table);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createTable };
|
|
63
|
+
//# sourceMappingURL=createTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTable.js","names":[],"sources":["../src/createTable.ts"],"sourcesContent":["import Alpine from 'alpinejs'\nimport { constructTable } from '@tanstack/table-core'\nimport { FlexRender, flexRender } from './flexRender'\nimport { alpineReactivity } from './reactivity'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n} from '@tanstack/table-core'\n\nexport type AlpineTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Table<TFeatures, TData> & {\n /**\n * A lower-level helper to render the content of a cell, header, or footer from a render function and its context.\n */\n flexRender: typeof flexRender\n\n /**\n * A convenience helper to render a cell, header, or footer object. Call from `x-html`, e.g. `FlexRender({ header })`.\n */\n FlexRender: typeof FlexRender\n}\n\nexport function createTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): AlpineTable<TFeatures, TData> {\n const mergedOptions: TableOptions<TFeatures, TData> = {\n ...tableOptions,\n features: {\n coreReactivityFeature: alpineReactivity(),\n ...tableOptions.features,\n },\n mergeOptions: (\n defaultOptions: TableOptions<TFeatures, TData>,\n newOptions: Partial<TableOptions<TFeatures, TData>>,\n ) => {\n return {\n ...defaultOptions,\n ...newOptions,\n }\n },\n }\n\n const table = constructTable(mergedOptions) as unknown as AlpineTable<\n TFeatures,\n TData\n >\n\n table.flexRender = flexRender\n table.FlexRender = FlexRender\n\n const reactivity = Alpine.reactive({ _ver: 0 })\n\n table.store.subscribe(() => {\n reactivity._ver++\n })\n\n // Reactively sync options when external Alpine-reactive getters change (e.g.\n // a `get data()` backed by `Alpine.reactive`). Reading the option getters\n // inside the effect registers the dependencies, so the effect re-runs when\n // they change and re-applies the live values via `setOptions`.\n //\n // `setOptions` writes to the options store, not the state store, so a `data`\n // (or other option) change does not emit on `table.store` and would not bump\n // `_ver` on its own. We bump `_ver` here so the template re-pulls derived\n // APIs like `getRowModel()`, which recompute from the new options. The effect\n // never reads `_ver`, so writing it does not re-trigger this effect.\n let initialized = false\n Alpine.effect(() => {\n const state = tableOptions.state as Record<string, unknown> | undefined\n if (state) {\n for (const key in state) {\n void state[key]\n }\n }\n void tableOptions.data\n\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n if (initialized) {\n reactivity._ver++\n }\n initialized = true\n })\n\n const proxyCache = new WeakMap<object, object>()\n\n const toReactiveProxy = <TValue>(value: TValue): TValue => {\n if (typeof value !== 'object' || value === null) {\n return value\n }\n\n // Built-in exotic objects (Map, Set, Date, etc.) rely on internal slots and\n // throw \"incompatible receiver\" when their getters/methods run with a Proxy\n // as the receiver (e.g. `getFacetedUniqueValues().size`). Return them as-is;\n // the read that produced them already tracked `_ver` at the call site.\n if (\n value instanceof Map ||\n value instanceof Set ||\n value instanceof WeakMap ||\n value instanceof WeakSet ||\n value instanceof Date ||\n value instanceof RegExp ||\n value instanceof Promise\n ) {\n return value\n }\n\n const cachedProxy = proxyCache.get(value)\n if (cachedProxy) {\n return cachedProxy as TValue\n }\n\n const proxy = new Proxy(value, {\n get(target, prop, receiver) {\n if (prop === '__v_skip') {\n return true\n }\n\n const resolvedValue = Reflect.get(target, prop, receiver)\n\n if (typeof resolvedValue === 'function') {\n return (...args: Array<unknown>) => {\n void reactivity._ver\n return toReactiveProxy(\n (resolvedValue as Function).apply(target, args),\n )\n }\n }\n\n void reactivity._ver\n return toReactiveProxy(resolvedValue)\n },\n })\n\n proxyCache.set(value, proxy)\n return proxy\n }\n\n return toReactiveProxy(table)\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,YAGd,cAA6E;CAkB7E,MAAM,QAAQ,eAAe;EAhB3B,GAAG;EACH,UAAU;GACR,uBAAuB,iBAAiB;GACxC,GAAG,aAAa;EAClB;EACA,eACE,gBACA,eACG;GACH,OAAO;IACL,GAAG;IACH,GAAG;GACL;EACF;CAGuC,CAAC;CAK1C,MAAM,aAAa;CACnB,MAAM,aAAa;CAEnB,MAAM,aAAa,OAAO,SAAS,EAAE,MAAM,EAAE,CAAC;CAE9C,MAAM,MAAM,gBAAgB;EAC1B,WAAW;CACb,CAAC;CAYD,IAAI,cAAc;CAClB,OAAO,aAAa;EAClB,MAAM,QAAQ,aAAa;EAC3B,IAAI,OACF,KAAK,MAAM,OAAO,OAChB,AAAK,MAAM;EAGf,AAAK,aAAa;EAElB,MAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;EACL,EAAE;EAEF,IAAI,aACF,WAAW;EAEb,cAAc;CAChB,CAAC;CAED,MAAM,6BAAa,IAAI,QAAwB;CAE/C,MAAM,mBAA2B,UAA0B;EACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;EAOT,IACE,iBAAiB,OACjB,iBAAiB,OACjB,iBAAiB,WACjB,iBAAiB,WACjB,iBAAiB,QACjB,iBAAiB,UACjB,iBAAiB,SAEjB,OAAO;EAGT,MAAM,cAAc,WAAW,IAAI,KAAK;EACxC,IAAI,aACF,OAAO;EAGT,MAAM,QAAQ,IAAI,MAAM,OAAO,EAC7B,IAAI,QAAQ,MAAM,UAAU;GAC1B,IAAI,SAAS,YACX,OAAO;GAGT,MAAM,gBAAgB,QAAQ,IAAI,QAAQ,MAAM,QAAQ;GAExD,IAAI,OAAO,kBAAkB,YAC3B,QAAQ,GAAG,SAAyB;IAClC,AAAK,WAAW;IAChB,OAAO,gBACJ,cAA2B,MAAM,QAAQ,IAAI,CAChD;GACF;GAGF,AAAK,WAAW;GAChB,OAAO,gBAAgB,aAAa;EACtC,EACF,CAAC;EAED,WAAW,IAAI,OAAO,KAAK;EAC3B,OAAO;CACT;CAEA,OAAO,gBAAgB,KAAK;AAC9B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const require_createTable = require('./createTable.cjs');
|
|
2
|
+
let _tanstack_table_core = require("@tanstack/table-core");
|
|
3
|
+
|
|
4
|
+
//#region src/createTableHook.ts
|
|
5
|
+
function createTableHook({ ...defaultTableOptions }) {
|
|
6
|
+
function createAppColumnHelper() {
|
|
7
|
+
return (0, _tanstack_table_core.createColumnHelper)();
|
|
8
|
+
}
|
|
9
|
+
function createAppTable(tableOptions) {
|
|
10
|
+
return require_createTable.createTable({
|
|
11
|
+
...defaultTableOptions,
|
|
12
|
+
...tableOptions
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
appFeatures: defaultTableOptions.features,
|
|
17
|
+
createAppColumnHelper,
|
|
18
|
+
createAppTable
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.createTableHook = createTableHook;
|
|
24
|
+
//# sourceMappingURL=createTableHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTableHook.cjs","names":["createTable"],"sources":["../src/createTableHook.ts"],"sourcesContent":["import { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { createTable } from './createTable'\nimport type { AlpineTable } from './createTable'\nimport type { RowData, TableFeatures, TableOptions } from '@tanstack/table-core'\n\nexport type CreateTableHookOptions<TFeatures extends TableFeatures> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'state'\n>\n\nexport type AppAlpineTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = AlpineTable<TFeatures, TData>\n\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = ReturnType<typeof coreCreateColumnHelper<TFeatures, TData>>\n\nexport function createTableHook<TFeatures extends TableFeatures>({\n ...defaultTableOptions\n}: CreateTableHookOptions<TFeatures>) {\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData\n > {\n return coreCreateColumnHelper<TFeatures, TData>()\n }\n\n function createAppTable<TData extends RowData>(\n tableOptions: Omit<TableOptions<TFeatures, TData>, 'features'>,\n ): AppAlpineTable<TFeatures, TData> {\n // Merge default options with provided options (provided takes precedence)\n const mergedOptions = {\n ...defaultTableOptions,\n ...tableOptions,\n } as TableOptions<TFeatures, TData>\n\n return createTable<TFeatures, TData>(mergedOptions)\n }\n\n return {\n appFeatures: defaultTableOptions.features as TFeatures,\n createAppColumnHelper,\n createAppTable,\n }\n}\n"],"mappings":";;;;AAoBA,SAAgB,gBAAiD,EAC/D,GAAG,uBACiC;CACpC,SAAS,wBAGP;EACA,oDAAgD;CAClD;CAEA,SAAS,eACP,cACkC;EAOlC,OAAOA,gCAA8B;GAJnC,GAAG;GACH,GAAG;EAG4C,CAAC;CACpD;CAEA,OAAO;EACL,aAAa,oBAAoB;EACjC;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AlpineTable } from "./createTable.cjs";
|
|
2
|
+
import { RowData, TableFeatures, TableOptions, createColumnHelper } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/createTableHook.d.ts
|
|
5
|
+
type CreateTableHookOptions<TFeatures extends TableFeatures> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'state'>;
|
|
6
|
+
type AppAlpineTable<TFeatures extends TableFeatures, TData extends RowData> = AlpineTable<TFeatures, TData>;
|
|
7
|
+
type AppColumnHelper<TFeatures extends TableFeatures, TData extends RowData> = ReturnType<typeof createColumnHelper<TFeatures, TData>>;
|
|
8
|
+
declare function createTableHook<TFeatures extends TableFeatures>({
|
|
9
|
+
...defaultTableOptions
|
|
10
|
+
}: CreateTableHookOptions<TFeatures>): {
|
|
11
|
+
appFeatures: TFeatures;
|
|
12
|
+
createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData>;
|
|
13
|
+
createAppTable: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, "features">) => AppAlpineTable<TFeatures, TData>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { AppAlpineTable, AppColumnHelper, CreateTableHookOptions, createTableHook };
|
|
17
|
+
//# sourceMappingURL=createTableHook.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AlpineTable } from "./createTable.js";
|
|
2
|
+
import { RowData, TableFeatures, TableOptions, createColumnHelper } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/createTableHook.d.ts
|
|
5
|
+
type CreateTableHookOptions<TFeatures extends TableFeatures> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'state'>;
|
|
6
|
+
type AppAlpineTable<TFeatures extends TableFeatures, TData extends RowData> = AlpineTable<TFeatures, TData>;
|
|
7
|
+
type AppColumnHelper<TFeatures extends TableFeatures, TData extends RowData> = ReturnType<typeof createColumnHelper<TFeatures, TData>>;
|
|
8
|
+
declare function createTableHook<TFeatures extends TableFeatures>({
|
|
9
|
+
...defaultTableOptions
|
|
10
|
+
}: CreateTableHookOptions<TFeatures>): {
|
|
11
|
+
appFeatures: TFeatures;
|
|
12
|
+
createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData>;
|
|
13
|
+
createAppTable: <TData extends RowData>(tableOptions: Omit<TableOptions<TFeatures, TData>, "features">) => AppAlpineTable<TFeatures, TData>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { AppAlpineTable, AppColumnHelper, CreateTableHookOptions, createTableHook };
|
|
17
|
+
//# sourceMappingURL=createTableHook.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createTable } from "./createTable.js";
|
|
2
|
+
import { createColumnHelper } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/createTableHook.ts
|
|
5
|
+
function createTableHook({ ...defaultTableOptions }) {
|
|
6
|
+
function createAppColumnHelper() {
|
|
7
|
+
return createColumnHelper();
|
|
8
|
+
}
|
|
9
|
+
function createAppTable(tableOptions) {
|
|
10
|
+
return createTable({
|
|
11
|
+
...defaultTableOptions,
|
|
12
|
+
...tableOptions
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
appFeatures: defaultTableOptions.features,
|
|
17
|
+
createAppColumnHelper,
|
|
18
|
+
createAppTable
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createTableHook };
|
|
24
|
+
//# sourceMappingURL=createTableHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTableHook.js","names":["coreCreateColumnHelper"],"sources":["../src/createTableHook.ts"],"sourcesContent":["import { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { createTable } from './createTable'\nimport type { AlpineTable } from './createTable'\nimport type { RowData, TableFeatures, TableOptions } from '@tanstack/table-core'\n\nexport type CreateTableHookOptions<TFeatures extends TableFeatures> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'state'\n>\n\nexport type AppAlpineTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = AlpineTable<TFeatures, TData>\n\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = ReturnType<typeof coreCreateColumnHelper<TFeatures, TData>>\n\nexport function createTableHook<TFeatures extends TableFeatures>({\n ...defaultTableOptions\n}: CreateTableHookOptions<TFeatures>) {\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData\n > {\n return coreCreateColumnHelper<TFeatures, TData>()\n }\n\n function createAppTable<TData extends RowData>(\n tableOptions: Omit<TableOptions<TFeatures, TData>, 'features'>,\n ): AppAlpineTable<TFeatures, TData> {\n // Merge default options with provided options (provided takes precedence)\n const mergedOptions = {\n ...defaultTableOptions,\n ...tableOptions,\n } as TableOptions<TFeatures, TData>\n\n return createTable<TFeatures, TData>(mergedOptions)\n }\n\n return {\n appFeatures: defaultTableOptions.features as TFeatures,\n createAppColumnHelper,\n createAppTable,\n }\n}\n"],"mappings":";;;;AAoBA,SAAgB,gBAAiD,EAC/D,GAAG,uBACiC;CACpC,SAAS,wBAGP;EACA,OAAOA,mBAAyC;CAClD;CAEA,SAAS,eACP,cACkC;EAOlC,OAAO,YAA8B;GAJnC,GAAG;GACH,GAAG;EAG4C,CAAC;CACpD;CAEA,OAAO;EACL,aAAa,oBAAoB;EACjC;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/flexRender.ts
|
|
3
|
+
/**
|
|
4
|
+
* Renders an Alpine table value with the provided context props.
|
|
5
|
+
*
|
|
6
|
+
* Use this lower-level helper for custom header, cell, or footer renderers when
|
|
7
|
+
* you already have the render function and context. `FlexRender` is the
|
|
8
|
+
* convenience wrapper for table cell/header/footer objects. Renderers typically
|
|
9
|
+
* return a string of markup that you render into the DOM with `x-html`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function flexRender(render, props) {
|
|
17
|
+
if (typeof render === "function") return render(props);
|
|
18
|
+
return render;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Simplified wrapper of `flexRender`. Use this utility function to render headers, cells, or footers with custom markup.
|
|
22
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
23
|
+
* @example
|
|
24
|
+
* ```html
|
|
25
|
+
* <th x-html="FlexRender({ header })"></th>
|
|
26
|
+
* <td x-html="FlexRender({ cell })"></td>
|
|
27
|
+
* <th x-html="FlexRender({ footer: header })"></th>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function FlexRender(props) {
|
|
31
|
+
if ("cell" in props && props.cell) return flexRender(props.cell.column.columnDef.cell, props.cell.getContext());
|
|
32
|
+
if ("header" in props && props.header) return flexRender(props.header.column.columnDef.header, props.header.getContext());
|
|
33
|
+
if ("footer" in props && props.footer) return flexRender(props.footer.column.columnDef.footer, props.footer.getContext());
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.FlexRender = FlexRender;
|
|
39
|
+
exports.flexRender = flexRender;
|
|
40
|
+
//# sourceMappingURL=flexRender.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flexRender.cjs","names":[],"sources":["../src/flexRender.ts"],"sourcesContent":["import type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\n\n/**\n * Renders an Alpine table value with the provided context props.\n *\n * Use this lower-level helper for custom header, cell, or footer renderers when\n * you already have the render function and context. `FlexRender` is the\n * convenience wrapper for table cell/header/footer objects. Renderers typically\n * return a string of markup that you render into the DOM with `x-html`.\n *\n * @example\n * ```ts\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * ```\n */\nexport function flexRender<TProps extends object>(\n render: any,\n props: TProps,\n): any {\n if (typeof render === 'function') {\n return render(props)\n }\n return render\n}\n\n/**\n * Simplified wrapper of `flexRender`. Use this utility function to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```html\n * <th x-html=\"FlexRender({ header })\"></th>\n * <td x-html=\"FlexRender({ cell })\"></td>\n * <th x-html=\"FlexRender({ footer: header })\"></th>\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```ts\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 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 wrapper of `flexRender`. Use this utility function to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```html\n * <th x-html=\"FlexRender({ header })\"></th>\n * <td x-html=\"FlexRender({ cell })\"></td>\n * <th x-html=\"FlexRender({ footer: header })\"></th>\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>): any {\n if ('cell' in props && props.cell) {\n return flexRender(props.cell.column.columnDef.cell, props.cell.getContext())\n }\n\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\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\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,SAAgB,WACd,QACA,OACK;CACL,IAAI,OAAO,WAAW,YACpB,OAAO,OAAO,KAAK;CAErB,OAAO;AACT;;;;;;;;;;;AA8CA,SAAgB,WAId,OAAuD;CACvD,IAAI,UAAU,SAAS,MAAM,MAC3B,OAAO,WAAW,MAAM,KAAK,OAAO,UAAU,MAAM,MAAM,KAAK,WAAW,CAAC;CAG7E,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,WAAW,CAC1B;CAGF,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,WAAW,CAC1B;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Cell, CellData, Header, RowData, TableFeatures } from "@tanstack/table-core";
|
|
2
|
+
|
|
3
|
+
//#region src/flexRender.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Renders an Alpine table value with the provided context props.
|
|
6
|
+
*
|
|
7
|
+
* Use this lower-level helper for custom header, cell, or footer renderers when
|
|
8
|
+
* you already have the render function and context. `FlexRender` is the
|
|
9
|
+
* convenience wrapper for table cell/header/footer objects. Renderers typically
|
|
10
|
+
* return a string of markup that you render into the DOM with `x-html`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function flexRender<TProps extends object>(render: any, props: TProps): any;
|
|
18
|
+
/**
|
|
19
|
+
* Simplified wrapper of `flexRender`. Use this utility function to render headers, cells, or footers with custom markup.
|
|
20
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
21
|
+
* @example
|
|
22
|
+
* ```html
|
|
23
|
+
* <th x-html="FlexRender({ header })"></th>
|
|
24
|
+
* <td x-html="FlexRender({ cell })"></td>
|
|
25
|
+
* <th x-html="FlexRender({ footer: header })"></th>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* This replaces calling `flexRender` directly like this:
|
|
29
|
+
* ```ts
|
|
30
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
31
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
32
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
type FlexRenderProps<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> = {
|
|
36
|
+
cell: Cell<TFeatures, TData, TValue>;
|
|
37
|
+
header?: never;
|
|
38
|
+
footer?: never;
|
|
39
|
+
} | {
|
|
40
|
+
header: Header<TFeatures, TData, TValue>;
|
|
41
|
+
cell?: never;
|
|
42
|
+
footer?: never;
|
|
43
|
+
} | {
|
|
44
|
+
footer: Header<TFeatures, TData, TValue>;
|
|
45
|
+
cell?: never;
|
|
46
|
+
header?: never;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Simplified wrapper of `flexRender`. Use this utility function to render headers, cells, or footers with custom markup.
|
|
50
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed.
|
|
51
|
+
* @example
|
|
52
|
+
* ```html
|
|
53
|
+
* <th x-html="FlexRender({ header })"></th>
|
|
54
|
+
* <td x-html="FlexRender({ cell })"></td>
|
|
55
|
+
* <th x-html="FlexRender({ footer: header })"></th>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function FlexRender<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(props: FlexRenderProps<TFeatures, TData, TValue>): any;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { FlexRender, FlexRenderProps, flexRender };
|
|
61
|
+
//# sourceMappingURL=flexRender.d.cts.map
|