@metaobjectsdev/tanstack 0.5.0-rc.1

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/LICENSE ADDED
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording and
55
+ discussing modifications to the Work, but excluding communication that
56
+ is conspicuously marked or designated in writing by the copyright owner
57
+ as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, reproduce, modify,
120
+ prepare derivative works of, distribute, and sublicense such modifications,
121
+ as an additional requirement of this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any conditions of TITLE,
141
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
142
+ PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer
163
+ only obligations consistent to this License provided that the
164
+ obligations are consistent with this License.
165
+
166
+ END OF TERMS AND CONDITIONS
167
+
168
+ APPENDIX: How to apply the Apache License to your work.
169
+
170
+ To apply the Apache License to your work, attach the following
171
+ boilerplate notice, with the fields enclosed by brackets "[]"
172
+ replaced with your own identifying information. (Don't include
173
+ the brackets!) The text should be enclosed in the appropriate
174
+ comment syntax for the file format in question. Also add information
175
+ on how to contact you electronically and/or by mail.
176
+
177
+ Copyright 2026 MetaObjects Contributors
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @metaobjectsdev/tanstack
2
+
3
+ TanStack runtime for metaobjects: `EntityFetcherProvider`, `<EntityGrid>`, `CellRendererProvider`, and `defaultCellRenderers`. Pairs with `@metaobjectsdev/codegen-ts-tanstack`, which generates `<Entity>.hooks.ts` and `<Entity>.columns.tsx` files that import from this package.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @metaobjectsdev/tanstack
9
+ ```
10
+
11
+ ## License
12
+
13
+ Apache-2.0.
@@ -0,0 +1,10 @@
1
+ import { type ReactNode } from "react";
2
+ import { type CellRenderer } from "./cell-renderers.js";
3
+ export interface CellRendererProviderProps {
4
+ /** Overrides merged on top of the inherited renderers. */
5
+ value: Partial<Record<string, CellRenderer>>;
6
+ children: ReactNode;
7
+ }
8
+ export declare function CellRendererProvider({ value, children }: CellRendererProviderProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function useCellRenderers(): Record<string, CellRenderer>;
10
+ //# sourceMappingURL=cell-renderer-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-renderer-provider.d.ts","sourceRoot":"","sources":["../src/cell-renderer-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAI9E,MAAM,WAAW,yBAAyB;IACxC,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,yBAAyB,2CAIlF;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAE/D"}
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from "react";
3
+ import { defaultCellRenderers } from "./cell-renderers.js";
4
+ const CellRendererContext = createContext(defaultCellRenderers);
5
+ export function CellRendererProvider({ value, children }) {
6
+ const inherited = useContext(CellRendererContext);
7
+ const merged = useMemo(() => ({ ...inherited, ...value }), [inherited, value]);
8
+ return _jsx(CellRendererContext.Provider, { value: merged, children: children });
9
+ }
10
+ export function useCellRenderers() {
11
+ return useContext(CellRendererContext);
12
+ }
13
+ //# sourceMappingURL=cell-renderer-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-renderer-provider.js","sourceRoot":"","sources":["../src/cell-renderer-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAqB,MAAM,qBAAqB,CAAC;AAE9E,MAAM,mBAAmB,GAAG,aAAa,CAA+B,oBAAoB,CAAC,CAAC;AAQ9F,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA6B;IACjF,MAAM,SAAS,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAiC,CAAC;IAC/G,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YAAG,QAAQ,GAAgC,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CellContext } from "@tanstack/react-table";
2
+ import type { ReactNode } from "react";
3
+ export type CellRenderer = (ctx: CellContext<any, any>) => ReactNode;
4
+ /**
5
+ * Default cell renderers keyed by field `view` subtype.
6
+ * Apps override per-key via <CellRendererProvider>.
7
+ */
8
+ export declare const defaultCellRenderers: Record<string, CellRenderer>;
9
+ //# sourceMappingURL=cell-renderers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-renderers.d.ts","sourceRoot":"","sources":["../src/cell-renderers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,SAAS,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CA0B7D,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { formatCurrency } from "@metaobjectsdev/runtime-web";
2
+ /**
3
+ * Default cell renderers keyed by field `view` subtype.
4
+ * Apps override per-key via <CellRendererProvider>.
5
+ */
6
+ export const defaultCellRenderers = {
7
+ text: (ctx) => String(ctx.getValue() ?? ""),
8
+ textarea: (ctx) => String(ctx.getValue() ?? ""),
9
+ number: (ctx) => String(ctx.getValue() ?? ""),
10
+ date: (ctx) => {
11
+ const v = ctx.getValue();
12
+ return v ? new Date(v).toLocaleDateString() : "";
13
+ },
14
+ datetime: (ctx) => {
15
+ const v = ctx.getValue();
16
+ return v ? new Date(v).toLocaleString() : "";
17
+ },
18
+ boolean: (ctx) => (ctx.getValue() ? "Yes" : "No"),
19
+ currency: (ctx) => {
20
+ const value = ctx.getValue();
21
+ if (value == null || !Number.isFinite(Number(value)))
22
+ return "";
23
+ const meta = (ctx.column.columnDef.meta ?? {});
24
+ try {
25
+ return formatCurrency(value, meta.currency, meta.locale);
26
+ }
27
+ catch {
28
+ // Invalid currency code or unsupported locale — fall back to raw value
29
+ return String(value);
30
+ }
31
+ },
32
+ dropdown: (ctx) => String(ctx.getValue() ?? ""),
33
+ password: () => "•••••",
34
+ };
35
+ //# sourceMappingURL=cell-renderers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-renderers.js","sourceRoot":"","sources":["../src/cell-renderers.tsx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E,CAAC;QAChE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAA2C,CAAC;QACzF,IAAI,CAAC;YACH,OAAO,cAAc,CAAC,KAAe,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,uEAAuE;YACvE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC/C,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO;CACxB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ import type { EntityFetcher } from "@metaobjectsdev/runtime-web";
3
+ export interface EntityFetcherProviderProps {
4
+ value: EntityFetcher;
5
+ children: ReactNode;
6
+ }
7
+ /** Wrap your app (or admin subtree) to supply a fetcher to generated hooks. */
8
+ export declare function EntityFetcherProvider({ value, children }: EntityFetcherProviderProps): import("react/jsx-runtime").JSX.Element;
9
+ /** Reads the fetcher from context. Throws if not provided. */
10
+ export declare function useEntityFetcher(): EntityFetcher;
11
+ //# sourceMappingURL=entity-fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-fetcher.d.ts","sourceRoot":"","sources":["../src/entity-fetcher.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAIjE,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,0BAA0B,2CAEpF;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,IAAI,aAAa,CAShD"}
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ const EntityFetcherContext = createContext(null);
4
+ /** Wrap your app (or admin subtree) to supply a fetcher to generated hooks. */
5
+ export function EntityFetcherProvider({ value, children }) {
6
+ return _jsx(EntityFetcherContext.Provider, { value: value, children: children });
7
+ }
8
+ /** Reads the fetcher from context. Throws if not provided. */
9
+ export function useEntityFetcher() {
10
+ const fetcher = useContext(EntityFetcherContext);
11
+ if (!fetcher) {
12
+ throw new Error("useEntityFetcher() called outside <EntityFetcherProvider>. " +
13
+ "Wrap your app (or the relevant subtree) with EntityFetcherProvider value={...}.");
14
+ }
15
+ return fetcher;
16
+ }
17
+ //# sourceMappingURL=entity-fetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-fetcher.js","sourceRoot":"","sources":["../src/entity-fetcher.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAGlE,MAAM,oBAAoB,GAAG,aAAa,CAAuB,IAAI,CAAC,CAAC;AAOvE,+EAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA8B;IACnF,OAAO,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiC,CAAC;AACjG,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB;IAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,iFAAiF,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ColumnDef, type SortingState, type PaginationState, type ColumnFiltersState, type OnChangeFn } from "@tanstack/react-table";
3
+ import type { GridConfig } from "@metaobjectsdev/runtime-web";
4
+ export interface EntityGridState {
5
+ sorting: SortingState;
6
+ pagination: PaginationState;
7
+ columnFilters: ColumnFiltersState;
8
+ }
9
+ export interface EntityGridProps<T> {
10
+ columns: ColumnDef<T>[];
11
+ grid: GridConfig;
12
+ /** The single server page of rows. */
13
+ data: T[];
14
+ /** Total rows matching the filter (server-supplied; drives page count). */
15
+ rowCount: number;
16
+ /** Controlled state — owned by the parent / generated grid hook. */
17
+ state: EntityGridState;
18
+ onSortingChange: OnChangeFn<SortingState>;
19
+ onPaginationChange: OnChangeFn<PaginationState>;
20
+ onColumnFiltersChange: OnChangeFn<ColumnFiltersState>;
21
+ /** Optional free-text search — input renders iff onSearchChange is supplied. */
22
+ search?: string;
23
+ onSearchChange?: (value: string) => void;
24
+ isLoading?: boolean;
25
+ error?: Error | null;
26
+ emptyState?: ReactNode;
27
+ onRowClick?: (row: T) => void;
28
+ actions?: (row: T) => ReactNode;
29
+ className?: string;
30
+ headerClassName?: string;
31
+ rowClassName?: string;
32
+ cellClassName?: string;
33
+ paginationClassName?: string;
34
+ searchClassName?: string;
35
+ }
36
+ /**
37
+ * Controlled, server-driven data grid. All filter/sort/pagination state lives
38
+ * outside; on-change callbacks fire so the parent re-queries. The component
39
+ * renders `data` as-is — no client-side sort/paginate/filter row models.
40
+ *
41
+ * Cell rendering routes through the CellRendererProvider registry, keyed by
42
+ * `column.meta.view`. Per-column `cell` always wins if set.
43
+ */
44
+ export declare function EntityGrid<T extends {
45
+ id?: number | string;
46
+ }>(props: EntityGridProps<T>): ReactNode;
47
+ //# sourceMappingURL=entity-grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-grid.d.ts","sourceRoot":"","sources":["../src/entity-grid.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,SAAS,EAAE,MAA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aAAa,CAAC,EAAQ,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAM,MAAM,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAC3D,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACxB,SAAS,CAoGX"}
@@ -0,0 +1,57 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { useReactTable, getCoreRowModel, flexRender, } from "@tanstack/react-table";
4
+ import { useCellRenderers } from "./cell-renderer-provider.js";
5
+ /**
6
+ * Controlled, server-driven data grid. All filter/sort/pagination state lives
7
+ * outside; on-change callbacks fire so the parent re-queries. The component
8
+ * renders `data` as-is — no client-side sort/paginate/filter row models.
9
+ *
10
+ * Cell rendering routes through the CellRendererProvider registry, keyed by
11
+ * `column.meta.view`. Per-column `cell` always wins if set.
12
+ */
13
+ export function EntityGrid(props) {
14
+ const renderers = useCellRenderers();
15
+ const columns = useMemo(() => {
16
+ const base = props.columns.map((col) => {
17
+ if (col.cell)
18
+ return col;
19
+ const viewKey = col.meta?.view;
20
+ const renderer = viewKey ? renderers[viewKey] : undefined;
21
+ if (!renderer)
22
+ return col;
23
+ return { ...col, cell: renderer };
24
+ });
25
+ if (props.actions) {
26
+ base.push({
27
+ id: "__actions",
28
+ header: "",
29
+ cell: ({ row }) => props.actions(row.original),
30
+ });
31
+ }
32
+ return base;
33
+ }, [props.columns, props.actions, renderers]);
34
+ const table = useReactTable({
35
+ data: props.data,
36
+ columns,
37
+ rowCount: props.rowCount,
38
+ state: props.state,
39
+ onSortingChange: props.onSortingChange,
40
+ onPaginationChange: props.onPaginationChange,
41
+ onColumnFiltersChange: props.onColumnFiltersChange,
42
+ manualSorting: true,
43
+ manualPagination: true,
44
+ manualFiltering: true,
45
+ getCoreRowModel: getCoreRowModel(),
46
+ });
47
+ if (!props.isLoading && props.data.length === 0 && props.emptyState) {
48
+ return _jsx(_Fragment, { children: props.emptyState });
49
+ }
50
+ return (_jsxs("div", { children: [props.onSearchChange !== undefined && (_jsx("div", { className: props.searchClassName, children: _jsx("input", { type: "search", placeholder: "Search", value: props.search ?? "", onChange: (e) => props.onSearchChange(e.target.value) }) })), _jsxs("table", { className: props.className, children: [_jsx("thead", { className: props.headerClassName, children: table.getHeaderGroups().map((hg) => (_jsx("tr", { children: hg.headers.map((h) => {
51
+ const meta = h.column.columnDef.meta;
52
+ const sortable = meta?.sortable !== false && h.column.getCanSort();
53
+ const sortDir = h.column.getIsSorted();
54
+ return (_jsxs("th", { style: meta?.width ? { width: meta.width } : undefined, onClick: sortable ? h.column.getToggleSortingHandler() : undefined, "aria-sort": sortDir === "asc" ? "ascending" : sortDir === "desc" ? "descending" : "none", children: [flexRender(h.column.columnDef.header, h.getContext()), sortDir === "asc" ? " ↑" : sortDir === "desc" ? " ↓" : ""] }, h.id));
55
+ }) }, hg.id))) }), _jsx("tbody", { children: table.getRowModel().rows.map((row) => (_jsx("tr", { className: props.rowClassName, onClick: props.onRowClick ? () => props.onRowClick(row.original) : undefined, style: props.onRowClick ? { cursor: "pointer" } : undefined, children: row.getVisibleCells().map((cell) => (_jsx("td", { className: props.cellClassName, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))) }, row.id))) })] }), table.getPageCount() > 1 && (_jsxs("div", { className: props.paginationClassName, children: [_jsx("button", { onClick: () => table.previousPage(), disabled: !table.getCanPreviousPage(), children: "Prev" }), _jsxs("span", { children: ["Page ", table.getState().pagination.pageIndex + 1, " of ", table.getPageCount()] }), _jsx("button", { onClick: () => table.nextPage(), disabled: !table.getCanNextPage(), children: "Next" })] }))] }));
56
+ }
57
+ //# sourceMappingURL=entity-grid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-grid.js","sourceRoot":"","sources":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YAE1D,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnC,aAAkB,SAAS,EAAE,KAAK,CAAC,aAAa,YAC7C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,IADnD,IAAI,CAAC,EAAE,CAEX,CACN,CAAC,IATG,GAAG,CAAC,EAAE,CAUR,CACN,CAAC,GACI,IACF,EACP,KAAK,CAAC,YAAY,EAAE,GAAG,CAAC,IAAI,CAC3B,eAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,aACvC,iBAAQ,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,kBAAkB,EAAE,qBAAe,EACjG,oCAAY,KAAK,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC,UAAM,KAAK,CAAC,YAAY,EAAE,IAAQ,EACvF,iBAAQ,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,qBAAe,IACrF,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { EntityFetcherProvider, useEntityFetcher } from "./entity-fetcher.js";
2
+ export type { EntityFetcherProviderProps } from "./entity-fetcher.js";
3
+ export type { EntityFetcher, GridConfig } from "@metaobjectsdev/runtime-web";
4
+ export { defaultCellRenderers, type CellRenderer } from "./cell-renderers.js";
5
+ export { CellRendererProvider, useCellRenderers, type CellRendererProviderProps, } from "./cell-renderer-provider.js";
6
+ export { EntityGrid, type EntityGridProps, type EntityGridState } from "./entity-grid.js";
7
+ export { buildFilterQs } from "@metaobjectsdev/runtime-web";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,yBAAyB,GAC/B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Public API surface for @metaobjectsdev/tanstack.
2
+ export { EntityFetcherProvider, useEntityFetcher } from "./entity-fetcher.js";
3
+ export { defaultCellRenderers } from "./cell-renderers.js";
4
+ export { CellRendererProvider, useCellRenderers, } from "./cell-renderer-provider.js";
5
+ export { EntityGrid } from "./entity-grid.js";
6
+ export { buildFilterQs } from "@metaobjectsdev/runtime-web";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EAAE,oBAAoB,EAAqB,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,gBAAgB,GAEjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAA8C,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@metaobjectsdev/tanstack",
3
+ "version": "0.5.0-rc.1",
4
+ "description": "TanStack runtime for metaobjects: EntityFetcherProvider, EntityGrid, default cell renderers.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "bun": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": ["dist", "src", "README.md", "LICENSE"],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "typecheck": "tsc -p tsconfig.typecheck.json",
19
+ "test": "bun test"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "author": "Doug Mealing <doug@dougmealing.com>",
23
+ "homepage": "https://metaobjects.dev",
24
+ "bugs": {
25
+ "url": "https://github.com/metaobjectsdev/metaobjects/issues"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/metaobjectsdev/metaobjects.git",
30
+ "directory": "client/web/packages/tanstack"
31
+ },
32
+ "keywords": ["metaobjects", "tanstack", "react-query", "react-table", "entity-grid"],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "dependencies": {
37
+ "@metaobjectsdev/runtime-web": "0.5.0",
38
+ "@metaobjectsdev/react": "0.5.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@tanstack/react-query": ">=5.90.0",
42
+ "@tanstack/react-table": ">=8.20.0",
43
+ "react": ">=18.0.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@tanstack/react-query": {
47
+ "optional": true
48
+ },
49
+ "@tanstack/react-table": {
50
+ "optional": true
51
+ },
52
+ "react": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "devDependencies": {
57
+ "@tanstack/react-query": "^5.90.0",
58
+ "@tanstack/react-table": "^8.20.0",
59
+ "@testing-library/react": "^16.0.0",
60
+ "@testing-library/dom": "^10.0.0",
61
+ "@types/react": "^19.0.0",
62
+ "bun-types": "latest",
63
+ "jsdom": "^29.1.1",
64
+ "react": "^19.0.0",
65
+ "react-dom": "^19.0.0",
66
+ "typescript": "^5.6.0"
67
+ }
68
+ }
@@ -0,0 +1,20 @@
1
+ import { createContext, useContext, useMemo, type ReactNode } from "react";
2
+ import { defaultCellRenderers, type CellRenderer } from "./cell-renderers.js";
3
+
4
+ const CellRendererContext = createContext<Record<string, CellRenderer>>(defaultCellRenderers);
5
+
6
+ export interface CellRendererProviderProps {
7
+ /** Overrides merged on top of the inherited renderers. */
8
+ value: Partial<Record<string, CellRenderer>>;
9
+ children: ReactNode;
10
+ }
11
+
12
+ export function CellRendererProvider({ value, children }: CellRendererProviderProps) {
13
+ const inherited = useContext(CellRendererContext);
14
+ const merged = useMemo(() => ({ ...inherited, ...value }), [inherited, value]) as Record<string, CellRenderer>;
15
+ return <CellRendererContext.Provider value={merged}>{children}</CellRendererContext.Provider>;
16
+ }
17
+
18
+ export function useCellRenderers(): Record<string, CellRenderer> {
19
+ return useContext(CellRendererContext);
20
+ }
@@ -0,0 +1,37 @@
1
+ import type { CellContext } from "@tanstack/react-table";
2
+ import type { ReactNode } from "react";
3
+ import { formatCurrency } from "@metaobjectsdev/runtime-web";
4
+
5
+ export type CellRenderer = (ctx: CellContext<any, any>) => ReactNode;
6
+
7
+ /**
8
+ * Default cell renderers keyed by field `view` subtype.
9
+ * Apps override per-key via <CellRendererProvider>.
10
+ */
11
+ export const defaultCellRenderers: Record<string, CellRenderer> = {
12
+ text: (ctx) => String(ctx.getValue() ?? ""),
13
+ textarea: (ctx) => String(ctx.getValue() ?? ""),
14
+ number: (ctx) => String(ctx.getValue() ?? ""),
15
+ date: (ctx) => {
16
+ const v = ctx.getValue();
17
+ return v ? new Date(v as string).toLocaleDateString() : "";
18
+ },
19
+ datetime: (ctx) => {
20
+ const v = ctx.getValue();
21
+ return v ? new Date(v as string).toLocaleString() : "";
22
+ },
23
+ boolean: (ctx) => (ctx.getValue() ? "Yes" : "No"),
24
+ currency: (ctx) => {
25
+ const value = ctx.getValue();
26
+ if (value == null || !Number.isFinite(Number(value))) return "";
27
+ const meta = (ctx.column.columnDef.meta ?? {}) as { currency?: string; locale?: string };
28
+ try {
29
+ return formatCurrency(value as number, meta.currency, meta.locale);
30
+ } catch {
31
+ // Invalid currency code or unsupported locale — fall back to raw value
32
+ return String(value);
33
+ }
34
+ },
35
+ dropdown: (ctx) => String(ctx.getValue() ?? ""),
36
+ password: () => "•••••",
37
+ };
@@ -0,0 +1,26 @@
1
+ import { createContext, useContext, type ReactNode } from "react";
2
+ import type { EntityFetcher } from "@metaobjectsdev/runtime-web";
3
+
4
+ const EntityFetcherContext = createContext<EntityFetcher | null>(null);
5
+
6
+ export interface EntityFetcherProviderProps {
7
+ value: EntityFetcher;
8
+ children: ReactNode;
9
+ }
10
+
11
+ /** Wrap your app (or admin subtree) to supply a fetcher to generated hooks. */
12
+ export function EntityFetcherProvider({ value, children }: EntityFetcherProviderProps) {
13
+ return <EntityFetcherContext.Provider value={value}>{children}</EntityFetcherContext.Provider>;
14
+ }
15
+
16
+ /** Reads the fetcher from context. Throws if not provided. */
17
+ export function useEntityFetcher(): EntityFetcher {
18
+ const fetcher = useContext(EntityFetcherContext);
19
+ if (!fetcher) {
20
+ throw new Error(
21
+ "useEntityFetcher() called outside <EntityFetcherProvider>. " +
22
+ "Wrap your app (or the relevant subtree) with EntityFetcherProvider value={...}.",
23
+ );
24
+ }
25
+ return fetcher;
26
+ }
@@ -0,0 +1,159 @@
1
+ import { useMemo, type ReactNode } from "react";
2
+ import {
3
+ useReactTable,
4
+ getCoreRowModel,
5
+ flexRender,
6
+ type ColumnDef,
7
+ type SortingState,
8
+ type PaginationState,
9
+ type ColumnFiltersState,
10
+ type OnChangeFn,
11
+ } from "@tanstack/react-table";
12
+ import type { GridConfig } from "@metaobjectsdev/runtime-web";
13
+ import { useCellRenderers } from "./cell-renderer-provider.js";
14
+
15
+ export interface EntityGridState {
16
+ sorting: SortingState;
17
+ pagination: PaginationState;
18
+ columnFilters: ColumnFiltersState;
19
+ }
20
+
21
+ export interface EntityGridProps<T> {
22
+ columns: ColumnDef<T>[];
23
+ grid: GridConfig;
24
+ /** The single server page of rows. */
25
+ data: T[];
26
+ /** Total rows matching the filter (server-supplied; drives page count). */
27
+ rowCount: number;
28
+ /** Controlled state — owned by the parent / generated grid hook. */
29
+ state: EntityGridState;
30
+ onSortingChange: OnChangeFn<SortingState>;
31
+ onPaginationChange: OnChangeFn<PaginationState>;
32
+ onColumnFiltersChange: OnChangeFn<ColumnFiltersState>;
33
+ /** Optional free-text search — input renders iff onSearchChange is supplied. */
34
+ search?: string;
35
+ onSearchChange?: (value: string) => void;
36
+ isLoading?: boolean;
37
+ error?: Error | null;
38
+ emptyState?: ReactNode;
39
+ onRowClick?: (row: T) => void;
40
+ actions?: (row: T) => ReactNode;
41
+ className?: string;
42
+ headerClassName?: string;
43
+ rowClassName?: string;
44
+ cellClassName?: string;
45
+ paginationClassName?: string;
46
+ searchClassName?: string;
47
+ }
48
+
49
+ /**
50
+ * Controlled, server-driven data grid. All filter/sort/pagination state lives
51
+ * outside; on-change callbacks fire so the parent re-queries. The component
52
+ * renders `data` as-is — no client-side sort/paginate/filter row models.
53
+ *
54
+ * Cell rendering routes through the CellRendererProvider registry, keyed by
55
+ * `column.meta.view`. Per-column `cell` always wins if set.
56
+ */
57
+ export function EntityGrid<T extends { id?: number | string }>(
58
+ props: EntityGridProps<T>,
59
+ ): ReactNode {
60
+ const renderers = useCellRenderers();
61
+
62
+ const columns = useMemo<ColumnDef<T>[]>(() => {
63
+ const base: ColumnDef<T>[] = props.columns.map((col): ColumnDef<T> => {
64
+ if (col.cell) return col;
65
+ const viewKey = (col.meta as { view?: string } | undefined)?.view;
66
+ const renderer = viewKey ? renderers[viewKey] : undefined;
67
+ if (!renderer) return col;
68
+ return { ...col, cell: renderer } as ColumnDef<T>;
69
+ });
70
+ if (props.actions) {
71
+ base.push({
72
+ id: "__actions",
73
+ header: "",
74
+ cell: ({ row }) => props.actions!(row.original),
75
+ });
76
+ }
77
+ return base;
78
+ }, [props.columns, props.actions, renderers]);
79
+
80
+ const table = useReactTable<T>({
81
+ data: props.data,
82
+ columns,
83
+ rowCount: props.rowCount,
84
+ state: props.state,
85
+ onSortingChange: props.onSortingChange,
86
+ onPaginationChange: props.onPaginationChange,
87
+ onColumnFiltersChange: props.onColumnFiltersChange,
88
+ manualSorting: true,
89
+ manualPagination: true,
90
+ manualFiltering: true,
91
+ getCoreRowModel: getCoreRowModel(),
92
+ });
93
+
94
+ if (!props.isLoading && props.data.length === 0 && props.emptyState) {
95
+ return <>{props.emptyState}</>;
96
+ }
97
+
98
+ return (
99
+ <div>
100
+ {props.onSearchChange !== undefined && (
101
+ <div className={props.searchClassName}>
102
+ <input
103
+ type="search"
104
+ placeholder="Search"
105
+ value={props.search ?? ""}
106
+ onChange={(e) => props.onSearchChange!(e.target.value)}
107
+ />
108
+ </div>
109
+ )}
110
+ <table className={props.className}>
111
+ <thead className={props.headerClassName}>
112
+ {table.getHeaderGroups().map((hg) => (
113
+ <tr key={hg.id}>
114
+ {hg.headers.map((h) => {
115
+ const meta = h.column.columnDef.meta as { sortable?: boolean; width?: number } | undefined;
116
+ const sortable = meta?.sortable !== false && h.column.getCanSort();
117
+ const sortDir = h.column.getIsSorted();
118
+ return (
119
+ <th
120
+ key={h.id}
121
+ style={meta?.width ? { width: meta.width } : undefined}
122
+ onClick={sortable ? h.column.getToggleSortingHandler() : undefined}
123
+ aria-sort={sortDir === "asc" ? "ascending" : sortDir === "desc" ? "descending" : "none"}
124
+ >
125
+ {flexRender(h.column.columnDef.header, h.getContext())}
126
+ {sortDir === "asc" ? " ↑" : sortDir === "desc" ? " ↓" : ""}
127
+ </th>
128
+ );
129
+ })}
130
+ </tr>
131
+ ))}
132
+ </thead>
133
+ <tbody>
134
+ {table.getRowModel().rows.map((row) => (
135
+ <tr
136
+ key={row.id}
137
+ className={props.rowClassName}
138
+ onClick={props.onRowClick ? () => props.onRowClick!(row.original) : undefined}
139
+ style={props.onRowClick ? { cursor: "pointer" } : undefined}
140
+ >
141
+ {row.getVisibleCells().map((cell) => (
142
+ <td key={cell.id} className={props.cellClassName}>
143
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
144
+ </td>
145
+ ))}
146
+ </tr>
147
+ ))}
148
+ </tbody>
149
+ </table>
150
+ {table.getPageCount() > 1 && (
151
+ <div className={props.paginationClassName}>
152
+ <button onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>Prev</button>
153
+ <span>Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()}</span>
154
+ <button onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>Next</button>
155
+ </div>
156
+ )}
157
+ </div>
158
+ );
159
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Public API surface for @metaobjectsdev/tanstack.
2
+ export { EntityFetcherProvider, useEntityFetcher } from "./entity-fetcher.js";
3
+ export type { EntityFetcherProviderProps } from "./entity-fetcher.js";
4
+ export type { EntityFetcher, GridConfig } from "@metaobjectsdev/runtime-web";
5
+ export { defaultCellRenderers, type CellRenderer } from "./cell-renderers.js";
6
+ export {
7
+ CellRendererProvider,
8
+ useCellRenderers,
9
+ type CellRendererProviderProps,
10
+ } from "./cell-renderer-provider.js";
11
+ export { EntityGrid, type EntityGridProps, type EntityGridState } from "./entity-grid.js";
12
+ export { buildFilterQs } from "@metaobjectsdev/runtime-web";