honotan 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +70 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5685,7 +5685,9 @@ function generateWebPackageJson(data) {
|
|
|
5685
5685
|
"@hookform/resolvers": "^5.1.1",
|
|
5686
5686
|
"@tailwindcss/vite": "^4.0.15",
|
|
5687
5687
|
"@tanstack/react-form": "^1.28.0",
|
|
5688
|
+
"@tanstack/react-query": "^5.0.0",
|
|
5688
5689
|
"@tanstack/react-router": "^1.141.1",
|
|
5690
|
+
"@tanstack/react-store": "^0.7.0",
|
|
5689
5691
|
"class-variance-authority": "^0.7.1",
|
|
5690
5692
|
clsx: "^2.1.1",
|
|
5691
5693
|
"lucide-react": "^0.473.0",
|
|
@@ -5821,16 +5823,19 @@ function generateIndexHtml(data) {
|
|
|
5821
5823
|
//#region src/templates/monorepo/apps/web/src-main.template.ts
|
|
5822
5824
|
function generateMainTsx(_data) {
|
|
5823
5825
|
return `import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
5826
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5824
5827
|
import ReactDOM from "react-dom/client";
|
|
5825
5828
|
|
|
5826
5829
|
import Loader from "./components/loader";
|
|
5827
5830
|
import { routeTree } from "./routeTree.gen";
|
|
5828
5831
|
|
|
5832
|
+
const queryClient = new QueryClient();
|
|
5833
|
+
|
|
5829
5834
|
const router = createRouter({
|
|
5830
5835
|
routeTree,
|
|
5831
5836
|
defaultPreload: "intent",
|
|
5832
5837
|
defaultPendingComponent: () => <Loader />,
|
|
5833
|
-
context: {},
|
|
5838
|
+
context: { queryClient },
|
|
5834
5839
|
});
|
|
5835
5840
|
|
|
5836
5841
|
declare module "@tanstack/react-router" {
|
|
@@ -5847,7 +5852,11 @@ if (!rootElement) {
|
|
|
5847
5852
|
|
|
5848
5853
|
if (!rootElement.innerHTML) {
|
|
5849
5854
|
const root = ReactDOM.createRoot(rootElement);
|
|
5850
|
-
root.render(
|
|
5855
|
+
root.render(
|
|
5856
|
+
<QueryClientProvider client={queryClient}>
|
|
5857
|
+
<RouterProvider router={router} />
|
|
5858
|
+
</QueryClientProvider>
|
|
5859
|
+
);
|
|
5851
5860
|
}
|
|
5852
5861
|
`;
|
|
5853
5862
|
}
|
|
@@ -5857,6 +5866,7 @@ if (!rootElement.innerHTML) {
|
|
|
5857
5866
|
function generateRoutesRootTsx(data) {
|
|
5858
5867
|
return `import { HeadContent, Outlet, createRootRouteWithContext } from "@tanstack/react-router";
|
|
5859
5868
|
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
|
5869
|
+
import { type QueryClient } from "@tanstack/react-query";
|
|
5860
5870
|
|
|
5861
5871
|
import Header from "@/components/header";
|
|
5862
5872
|
import { ThemeProvider } from "@/components/theme-provider";
|
|
@@ -5864,7 +5874,9 @@ import { Toaster } from "@/components/ui/sonner";
|
|
|
5864
5874
|
|
|
5865
5875
|
import "../index.css";
|
|
5866
5876
|
|
|
5867
|
-
export interface RouterAppContext {
|
|
5877
|
+
export interface RouterAppContext {
|
|
5878
|
+
queryClient: QueryClient;
|
|
5879
|
+
}
|
|
5868
5880
|
|
|
5869
5881
|
export const Route = createRootRouteWithContext<RouterAppContext>()({
|
|
5870
5882
|
component: RootComponent,
|
|
@@ -5912,8 +5924,13 @@ function RootComponent() {
|
|
|
5912
5924
|
|
|
5913
5925
|
//#endregion
|
|
5914
5926
|
//#region src/templates/monorepo/apps/web/src-routes-index.template.ts
|
|
5915
|
-
function generateRoutesIndexTsx(
|
|
5927
|
+
function generateRoutesIndexTsx(data) {
|
|
5916
5928
|
return `import { createFileRoute } from "@tanstack/react-router";
|
|
5929
|
+
import { useQuery } from "@tanstack/react-query";
|
|
5930
|
+
import { Button } from "@/components/ui/button";
|
|
5931
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
5932
|
+
import { useCounter, increment, decrement, reset } from "@/lib/counter-store";
|
|
5933
|
+
import { env } from "${data.scope}/env/client";
|
|
5917
5934
|
|
|
5918
5935
|
export const Route = createFileRoute("/")({
|
|
5919
5936
|
component: HomeComponent,
|
|
@@ -5936,13 +5953,37 @@ const TITLE_TEXT = \`
|
|
|
5936
5953
|
\`;
|
|
5937
5954
|
|
|
5938
5955
|
function HomeComponent() {
|
|
5956
|
+
const count = useCounter();
|
|
5957
|
+
|
|
5958
|
+
const { data: helloData, isLoading: helloLoading } = useQuery({
|
|
5959
|
+
queryKey: ["hello"],
|
|
5960
|
+
queryFn: async () => {
|
|
5961
|
+
const res = await fetch(env.VITE_API_URL + "/hello");
|
|
5962
|
+
if (!res.ok) throw new Error("Failed to fetch /hello");
|
|
5963
|
+
return res.json() as Promise<{ message: string }>;
|
|
5964
|
+
},
|
|
5965
|
+
});
|
|
5966
|
+
|
|
5939
5967
|
return (
|
|
5940
5968
|
<div className="container mx-auto max-w-3xl px-4 py-2">
|
|
5941
5969
|
<pre className="overflow-x-auto font-mono text-sm">{TITLE_TEXT}</pre>
|
|
5942
5970
|
<div className="grid gap-6">
|
|
5943
5971
|
<section className="rounded-lg border p-4">
|
|
5944
|
-
<h2 className="mb-2 font-medium">API
|
|
5945
|
-
|
|
5972
|
+
<h2 className="mb-2 font-medium">Hello API (TanStack Query)</h2>
|
|
5973
|
+
{helloLoading ? (
|
|
5974
|
+
<Skeleton className="h-5 w-48" />
|
|
5975
|
+
) : (
|
|
5976
|
+
<p className="text-sm text-muted-foreground">{helloData?.message}</p>
|
|
5977
|
+
)}
|
|
5978
|
+
</section>
|
|
5979
|
+
<section className="rounded-lg border p-4">
|
|
5980
|
+
<h2 className="mb-2 font-medium">Counter (TanStack Store)</h2>
|
|
5981
|
+
<div className="flex items-center gap-4">
|
|
5982
|
+
<Button variant="outline" size="sm" onClick={decrement}>−</Button>
|
|
5983
|
+
<span className="w-12 text-center text-lg font-semibold tabular-nums">{count}</span>
|
|
5984
|
+
<Button variant="outline" size="sm" onClick={increment}>+</Button>
|
|
5985
|
+
<Button variant="ghost" size="sm" onClick={reset}>Reset</Button>
|
|
5986
|
+
</div>
|
|
5946
5987
|
</section>
|
|
5947
5988
|
</div>
|
|
5948
5989
|
</div>
|
|
@@ -6685,6 +6726,28 @@ function generateWebEnvExample(data) {
|
|
|
6685
6726
|
return lines.join("\n") + "\n";
|
|
6686
6727
|
}
|
|
6687
6728
|
|
|
6729
|
+
//#endregion
|
|
6730
|
+
//#region src/templates/monorepo/apps/web/src-lib-counter-store.template.ts
|
|
6731
|
+
function generateLibCounterStoreTs(_data) {
|
|
6732
|
+
return `import { Store } from "@tanstack/react-store";
|
|
6733
|
+
import { useStore } from "@tanstack/react-store";
|
|
6734
|
+
|
|
6735
|
+
export const counterStore = new Store({ count: 0 });
|
|
6736
|
+
|
|
6737
|
+
export const increment = () =>
|
|
6738
|
+
counterStore.setState((s) => ({ count: s.count + 1 }));
|
|
6739
|
+
|
|
6740
|
+
export const decrement = () =>
|
|
6741
|
+
counterStore.setState((s) => ({ count: s.count - 1 }));
|
|
6742
|
+
|
|
6743
|
+
export const reset = () => counterStore.setState(() => ({ count: 0 }));
|
|
6744
|
+
|
|
6745
|
+
export function useCounter() {
|
|
6746
|
+
return useStore(counterStore, (s) => s.count);
|
|
6747
|
+
}
|
|
6748
|
+
`;
|
|
6749
|
+
}
|
|
6750
|
+
|
|
6688
6751
|
//#endregion
|
|
6689
6752
|
//#region src/templates/monorepo/root/package-json.template.ts
|
|
6690
6753
|
function generateRootPackageJson(data) {
|
|
@@ -9216,6 +9279,7 @@ function collectWebFiles(data) {
|
|
|
9216
9279
|
w("src/routes/__root.tsx", generateRoutesRootTsx(data)),
|
|
9217
9280
|
w("src/routes/index.tsx", generateRoutesIndexTsx(data)),
|
|
9218
9281
|
w("src/lib/utils.ts", generateLibUtilsTs(data)),
|
|
9282
|
+
w("src/lib/counter-store.ts", generateLibCounterStoreTs(data)),
|
|
9219
9283
|
w("src/components/header.tsx", generateHeaderTsx(data)),
|
|
9220
9284
|
w("src/components/theme-provider.tsx", generateThemeProviderTsx(data)),
|
|
9221
9285
|
w("src/components/loader.tsx", generateLoaderTsx(data)),
|