create-croissant 0.1.49 → 0.1.50

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.
Files changed (25) hide show
  1. package/package.json +1 -1
  2. package/template/apps/desktop/electron.vite.config.ts +11 -1
  3. package/template/apps/desktop/package.json +19 -1
  4. package/template/apps/desktop/src/renderer/index.html +1 -1
  5. package/template/apps/desktop/src/renderer/src/components/app-sidebar.tsx +186 -0
  6. package/template/apps/desktop/src/renderer/src/components/login-form.tsx +154 -0
  7. package/template/apps/desktop/src/renderer/src/components/signup-form.tsx +201 -0
  8. package/template/apps/desktop/src/renderer/src/lib/auth-client.ts +3 -0
  9. package/template/apps/desktop/src/renderer/src/lib/orpc.ts +12 -0
  10. package/template/apps/desktop/src/renderer/src/main.tsx +15 -4
  11. package/template/apps/desktop/src/renderer/src/routeTree.gen.ts +240 -0
  12. package/template/apps/desktop/src/renderer/src/routes/__root.tsx +29 -0
  13. package/template/apps/desktop/src/renderer/src/routes/_auth/account.tsx +267 -0
  14. package/template/apps/desktop/src/renderer/src/routes/_auth/dashboard.tsx +46 -0
  15. package/template/apps/desktop/src/renderer/src/routes/_auth/examples/client-orpc-auth.tsx +35 -0
  16. package/template/apps/desktop/src/renderer/src/routes/_auth.tsx +35 -0
  17. package/template/apps/desktop/src/renderer/src/routes/_public/examples/client-orpc.tsx +306 -0
  18. package/template/apps/desktop/src/renderer/src/routes/_public/index.tsx +54 -0
  19. package/template/apps/desktop/src/renderer/src/routes/_public/login.tsx +16 -0
  20. package/template/apps/desktop/src/renderer/src/routes/_public/signup.tsx +16 -0
  21. package/template/apps/desktop/src/renderer/src/routes/_public.tsx +23 -0
  22. package/template/apps/desktop/tsconfig.web.json +1 -0
  23. package/template/package.json +3 -0
  24. package/template/packages/ui/package.json +4 -2
  25. package/template/apps/desktop/src/renderer/src/App.tsx +0 -35
@@ -0,0 +1,306 @@
1
+ import * as React from "react";
2
+ import { createFileRoute } from "@tanstack/react-router";
3
+ import { Check, Pencil, Plus, Trash2 } from "lucide-react";
4
+ import { toast } from "sonner";
5
+ import { useForm } from "@tanstack/react-form";
6
+ import { z } from "zod";
7
+
8
+ import { Button } from "@workspace/ui/components/button";
9
+ import { Input } from "@workspace/ui/components/input";
10
+ import { Field, FieldError, FieldLabel } from "@workspace/ui/components/field";
11
+
12
+ import type { router } from "@workspace/orpc/router";
13
+ import type { InferRouterOutputs } from "@orpc/server";
14
+ import { usePlanets, useCreatePlanet, useUpdatePlanet, useDeletePlanet } from "@workspace/orpc/react";
15
+
16
+ type Outputs = InferRouterOutputs<typeof router>;
17
+ type Planet = Outputs["planets"]["getPlanets"][number];
18
+
19
+ const planetSchema = z.object({
20
+ name: z.string().min(1),
21
+ description: z.string(),
22
+ distance: z.string().refine((val) => !isNaN(parseFloat(val)), {
23
+ message: "Must be a number",
24
+ }),
25
+ diameter: z.string().refine((val) => !isNaN(parseFloat(val)), {
26
+ message: "Must be a number",
27
+ }),
28
+ });
29
+
30
+ export const Route = createFileRoute("/_public/examples/client-orpc")({
31
+ component: ClientORPC,
32
+ });
33
+
34
+ function ClientORPC() {
35
+ const [editingId, setEditingId] = React.useState<number | null>(null);
36
+
37
+ const { data: planets = [], isLoading } = usePlanets();
38
+
39
+ const form = useForm({
40
+ defaultValues: {
41
+ name: "",
42
+ description: "",
43
+ distance: "0",
44
+ diameter: "0",
45
+ },
46
+ validators: {
47
+ onChange: planetSchema,
48
+ },
49
+ onSubmit: async ({ value }) => {
50
+ if (editingId) {
51
+ await updateMutation.mutateAsync({
52
+ id: editingId,
53
+ name: value.name,
54
+ description: value.description,
55
+ distanceFromSun: parseFloat(value.distance),
56
+ diameter: parseFloat(value.diameter),
57
+ hasRings: false,
58
+ });
59
+ } else {
60
+ await createMutation.mutateAsync({
61
+ name: value.name,
62
+ description: value.description,
63
+ distanceFromSun: parseFloat(value.distance),
64
+ diameter: parseFloat(value.diameter),
65
+ hasRings: false,
66
+ });
67
+ }
68
+ },
69
+ });
70
+
71
+ const resetForm = () => {
72
+ form.reset();
73
+ setEditingId(null);
74
+ };
75
+
76
+ const createMutation = useCreatePlanet({
77
+ onSuccess: () => {
78
+ resetForm();
79
+ toast.success("Planet added successfully");
80
+ },
81
+ onError: (err) => {
82
+ toast.error(err.message || "Failed to add planet");
83
+ },
84
+ });
85
+
86
+ const updateMutation = useUpdatePlanet({
87
+ onSuccess: () => {
88
+ resetForm();
89
+ toast.success("Planet updated successfully");
90
+ },
91
+ onError: (err) => {
92
+ toast.error(err.message || "Failed to update planet");
93
+ },
94
+ });
95
+
96
+ const deleteMutation = useDeletePlanet({
97
+ onSuccess: () => {
98
+ toast.success("Planet deleted successfully");
99
+ },
100
+ onError: (err) => {
101
+ toast.error(err.message || "Failed to delete planet");
102
+ },
103
+ });
104
+
105
+ const handleDelete = async (id: number) => {
106
+ if (!confirm("Are you sure you want to delete this planet?")) return;
107
+ await deleteMutation.mutateAsync({ id });
108
+ };
109
+
110
+ const startEdit = (planet: Planet) => {
111
+ setEditingId(planet.id);
112
+ form.setFieldValue("name", planet.name);
113
+ form.setFieldValue("description", planet.description || "");
114
+ form.setFieldValue("distance", planet.distanceFromSun.toString());
115
+ form.setFieldValue("diameter", planet.diameter.toString());
116
+ };
117
+
118
+ return (
119
+ <div className="flex flex-col gap-8">
120
+ <div>
121
+ <h1 className="text-2xl font-bold mb-2">Client + oRPC CRUD</h1>
122
+ <p className="text-muted-foreground">
123
+ Manage planets directly from the client using TanStack Query, TanStack Form and oRPC.
124
+ </p>
125
+ </div>
126
+
127
+ <div className="rounded-lg border p-6 bg-muted/30 dark:bg-zinc-900/30">
128
+ <h2 className="font-semibold mb-4 flex items-center gap-2">
129
+ {editingId ? <Pencil className="h-4 w-4" /> : <Plus className="h-4 w-4" />}
130
+ {editingId ? "Edit Planet" : "Add New Planet"}
131
+ </h2>
132
+ <form
133
+ onSubmit={(e) => {
134
+ e.preventDefault();
135
+ e.stopPropagation();
136
+ form.handleSubmit();
137
+ }}
138
+ >
139
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
140
+ <form.Field
141
+ name="name"
142
+ children={(field) => (
143
+ <Field
144
+ data-invalid={field.state.meta.isTouched && field.state.meta.errors.length > 0}
145
+ >
146
+ <FieldLabel htmlFor={field.name}>Name</FieldLabel>
147
+ <Input
148
+ id={field.name}
149
+ name={field.name}
150
+ value={field.state.value}
151
+ onBlur={field.handleBlur}
152
+ onChange={(e) => field.handleChange(e.target.value)}
153
+ placeholder="Mars"
154
+ />
155
+ {field.state.meta.isTouched && <FieldError errors={field.state.meta.errors} />}
156
+ </Field>
157
+ )}
158
+ />
159
+ <form.Field
160
+ name="description"
161
+ children={(field) => (
162
+ <Field
163
+ data-invalid={field.state.meta.isTouched && field.state.meta.errors.length > 0}
164
+ >
165
+ <FieldLabel htmlFor={field.name}>Description</FieldLabel>
166
+ <Input
167
+ id={field.name}
168
+ name={field.name}
169
+ value={field.state.value}
170
+ onBlur={field.handleBlur}
171
+ onChange={(e) => field.handleChange(e.target.value)}
172
+ placeholder="The red planet"
173
+ />
174
+ {field.state.meta.isTouched && <FieldError errors={field.state.meta.errors} />}
175
+ </Field>
176
+ )}
177
+ />
178
+ <form.Field
179
+ name="distance"
180
+ children={(field) => (
181
+ <Field
182
+ data-invalid={field.state.meta.isTouched && field.state.meta.errors.length > 0}
183
+ >
184
+ <FieldLabel htmlFor={field.name}>Distance (M km)</FieldLabel>
185
+ <Input
186
+ id={field.name}
187
+ name={field.name}
188
+ type="number"
189
+ value={field.state.value}
190
+ onBlur={field.handleBlur}
191
+ onChange={(e) => field.handleChange(e.target.value)}
192
+ />
193
+ {field.state.meta.isTouched && <FieldError errors={field.state.meta.errors} />}
194
+ </Field>
195
+ )}
196
+ />
197
+ <form.Field
198
+ name="diameter"
199
+ children={(field) => (
200
+ <Field
201
+ data-invalid={field.state.meta.isTouched && field.state.meta.errors.length > 0}
202
+ >
203
+ <FieldLabel htmlFor={field.name}>Diameter (km)</FieldLabel>
204
+ <Input
205
+ id={field.name}
206
+ name={field.name}
207
+ type="number"
208
+ value={field.state.value}
209
+ onBlur={field.handleBlur}
210
+ onChange={(e) => field.handleChange(e.target.value)}
211
+ />
212
+ {field.state.meta.isTouched && <FieldError errors={field.state.meta.errors} />}
213
+ </Field>
214
+ )}
215
+ />
216
+ </div>
217
+ <div className="mt-6 flex gap-2">
218
+ <form.Subscribe
219
+ selector={(state) => [state.canSubmit, state.isSubmitting]}
220
+ children={([canSubmit, isSubmitting]) => (
221
+ <>
222
+ {editingId ? (
223
+ <>
224
+ <Button
225
+ type="submit"
226
+ className="flex items-center gap-2"
227
+ disabled={!canSubmit || isSubmitting || updateMutation.isPending}
228
+ >
229
+ <Check className="h-4 w-4" />{" "}
230
+ {isSubmitting || updateMutation.isPending ? "Saving..." : "Save Changes"}
231
+ </Button>
232
+ <Button
233
+ variant="outline"
234
+ type="button"
235
+ onClick={resetForm}
236
+ disabled={isSubmitting || updateMutation.isPending}
237
+ >
238
+ Cancel
239
+ </Button>
240
+ </>
241
+ ) : (
242
+ <Button
243
+ type="submit"
244
+ className="flex items-center gap-2"
245
+ disabled={!canSubmit || isSubmitting || createMutation.isPending}
246
+ >
247
+ <Plus className="h-4 w-4" />{" "}
248
+ {isSubmitting || createMutation.isPending ? "Adding..." : "Add Planet"}
249
+ </Button>
250
+ )}
251
+ </>
252
+ )}
253
+ />
254
+ </div>
255
+ </form>
256
+ </div>
257
+
258
+ <div className="space-y-4">
259
+ <h2 className="font-semibold text-lg">Current Planets</h2>
260
+ {isLoading ? (
261
+ <p>Loading planets...</p>
262
+ ) : planets.length === 0 ? (
263
+ <p className="text-gray-500 italic">No planets found.</p>
264
+ ) : (
265
+ <div className="grid grid-cols-1 gap-3">
266
+ {planets.map((planet) => (
267
+ <div
268
+ key={planet.id}
269
+ className="flex items-center justify-between rounded-lg border p-4 bg-background shadow-sm hover:shadow-md transition-shadow dark:bg-zinc-900"
270
+ >
271
+ <div className="flex-1">
272
+ <div className="flex items-center gap-2">
273
+ <span className="font-bold text-lg">{planet.name}</span>
274
+ <span className="text-xs bg-muted px-2 py-0.5 rounded-full text-muted-foreground">
275
+ ID: {planet.id}
276
+ </span>
277
+ </div>
278
+ <p className="text-sm text-muted-foreground">
279
+ {planet.description || "No description provided."}
280
+ </p>
281
+ <div className="mt-2 flex gap-4 text-xs text-muted-foreground font-mono">
282
+ <span>Distance: {planet.distanceFromSun} M km</span>
283
+ <span>Diameter: {planet.diameter} km</span>
284
+ </div>
285
+ </div>
286
+ <div className="flex gap-2 ml-4">
287
+ <Button variant="outline" size="icon" onClick={() => startEdit(planet)}>
288
+ <Pencil className="h-4 w-4" />
289
+ </Button>
290
+ <Button
291
+ variant="destructive"
292
+ size="icon"
293
+ onClick={() => handleDelete(planet.id)}
294
+ disabled={deleteMutation.isPending}
295
+ >
296
+ <Trash2 className="h-4 w-4" />
297
+ </Button>
298
+ </div>
299
+ </div>
300
+ ))}
301
+ </div>
302
+ )}
303
+ </div>
304
+ </div>
305
+ );
306
+ }
@@ -0,0 +1,54 @@
1
+ import { Link, createFileRoute } from "@tanstack/react-router";
2
+ import { Button } from "@workspace/ui/components/button";
3
+ import { useHello, usePlanets } from "@workspace/orpc/react";
4
+
5
+ export const Route = createFileRoute("/_public/")({
6
+ component: App,
7
+ });
8
+
9
+ function App() {
10
+ const { data: helloData, isLoading: helloLoading } = useHello("Croissant Desktop");
11
+ const { data: planets, isLoading: planetsLoading } = usePlanets();
12
+
13
+ return (
14
+ <div className="flex min-h-svh p-6">
15
+ <div className="flex max-w-lg min-w-0 flex-col gap-4 text-sm leading-loose">
16
+ <div>
17
+ <h1 className="font-medium text-2xl mb-4">Desktop Project ready!</h1>
18
+ <p>
19
+ oRPC integration: <span className="font-bold">{helloLoading ? "Loading..." : helloData?.message}</span>
20
+ </p>
21
+
22
+ <div className="mt-8">
23
+ <h2 className="text-xl font-semibold mb-2">Planets from Database:</h2>
24
+ {planetsLoading ? (
25
+ <p className="text-gray-500 italic">Loading planets...</p>
26
+ ) : !planets || planets.length === 0 ? (
27
+ <p className="text-gray-500 italic">
28
+ No planets found in the database.
29
+ </p>
30
+ ) : (
31
+ <ul className="grid grid-cols-1 gap-2">
32
+ {planets.map((planet) => (
33
+ <li key={planet.id} className="rounded-md border p-3 shadow-sm">
34
+ <span className="font-bold">{planet.name}</span> - {planet.description}
35
+ </li>
36
+ ))}
37
+ </ul>
38
+ )}
39
+ </div>
40
+
41
+ <div className="mt-8 flex gap-2">
42
+ <Link to="/login">
43
+ <Button>Go to Login</Button>
44
+ </Link>
45
+ <Link to="/dashboard">
46
+ <Button variant="outline">Go to Dashboard</Button>
47
+ </Link>
48
+ </div>
49
+ <p className="mt-4 text-gray-500">You may now add components and start building.</p>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1,16 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { LoginForm } from "@/components/login-form";
3
+
4
+ export const Route = createFileRoute("/_public/login")({
5
+ component: Login,
6
+ });
7
+
8
+ function Login() {
9
+ return (
10
+ <div className="flex min-h-svh items-center justify-center p-6">
11
+ <div className="w-full max-w-sm">
12
+ <LoginForm />
13
+ </div>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,16 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { SignupForm } from "@/components/signup-form";
3
+
4
+ export const Route = createFileRoute("/_public/signup")({
5
+ component: Signup,
6
+ });
7
+
8
+ function Signup() {
9
+ return (
10
+ <div className="flex min-h-svh items-center justify-center p-6">
11
+ <div className="w-full max-w-sm">
12
+ <SignupForm />
13
+ </div>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,23 @@
1
+ import { Outlet, createFileRoute } from "@tanstack/react-router";
2
+ import { SidebarProvider, SidebarTrigger } from "@workspace/ui/components/sidebar";
3
+ import { PublicSidebar } from "@/components/app-sidebar";
4
+
5
+ export const Route = createFileRoute("/_public")({
6
+ component: PublicLayout,
7
+ });
8
+
9
+ function PublicLayout() {
10
+ return (
11
+ <SidebarProvider>
12
+ <PublicSidebar />
13
+ <main className="flex flex-1 flex-col overflow-hidden">
14
+ <header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
15
+ <SidebarTrigger />
16
+ </header>
17
+ <div className="flex-1 overflow-auto p-4">
18
+ <Outlet />
19
+ </div>
20
+ </main>
21
+ </SidebarProvider>
22
+ );
23
+ }
@@ -10,6 +10,7 @@
10
10
  "compilerOptions": {
11
11
  "composite": true,
12
12
  "paths": {
13
+ "@/*": ["./src/renderer/src/*"],
13
14
  "@renderer/*": ["./src/renderer/src/*"],
14
15
  "@main/*": ["./src/main/src/*"],
15
16
  "@preload/*": ["./src/preload/src/*"]
@@ -21,6 +21,9 @@
21
21
  "prepare": "husky"
22
22
  },
23
23
  "dependencies": {
24
+ "@orpc/client": "^1.14.2",
25
+ "@orpc/server": "^1.14.2",
26
+ "@tanstack/react-start": "^1.167.65",
24
27
  "react": "19.2.5",
25
28
  "react-dom": "19.2.5"
26
29
  },
@@ -7,6 +7,7 @@
7
7
  "./globals.css": "./src/styles/globals.css",
8
8
  "./lib/*": "./src/lib/*.ts",
9
9
  "./components/*": "./src/components/*.tsx",
10
+ "./commons/*": "./src/commons/*.tsx",
10
11
  "./hooks/*": "./src/hooks/*.ts"
11
12
  },
12
13
  "scripts": {
@@ -15,6 +16,8 @@
15
16
  "dependencies": {
16
17
  "@base-ui/react": "^1.4.1",
17
18
  "@fontsource-variable/geist": "^5.2.8",
19
+ "@tanstack/react-router": "^1.168.24",
20
+ "better-auth": "^1.6.10",
18
21
  "class-variance-authority": "^0.7.1",
19
22
  "clsx": "^2.1.1",
20
23
  "cmdk": "^1.1.1",
@@ -32,8 +35,7 @@
32
35
  "sonner": "^2.0.7",
33
36
  "tailwind-merge": "^3.5.0",
34
37
  "tw-animate-css": "^1.4.0",
35
- "vaul": "^1.1.2",
36
- "@tanstack/react-router": "^1.168.24"
38
+ "vaul": "^1.1.2"
37
39
  },
38
40
  "devDependencies": {
39
41
  "@tailwindcss/vite": "^4.2.4",
@@ -1,35 +0,0 @@
1
- import Versions from "./components/Versions";
2
- import electronLogo from "./assets/electron.svg";
3
-
4
- function App(): React.JSX.Element {
5
- const ipcHandle = (): void => window.electron.ipcRenderer.send("ping");
6
-
7
- return (
8
- <>
9
- <img alt="logo" className="logo" src={electronLogo} />
10
- <div className="creator">Powered by electron-vite</div>
11
- <div className="text">
12
- Build an Electron app with <span className="react">React</span>
13
- &nbsp;and <span className="ts">TypeScript</span>
14
- </div>
15
- <p className="tip">
16
- Please try pressing <code>F12</code> to open the devTool
17
- </p>
18
- <div className="actions">
19
- <div className="action">
20
- <a href="https://electron-vite.org/" target="_blank" rel="noreferrer">
21
- Documentation
22
- </a>
23
- </div>
24
- <div className="action">
25
- <a target="_blank" rel="noreferrer" onClick={ipcHandle}>
26
- Send IPC
27
- </a>
28
- </div>
29
- </div>
30
- <Versions></Versions>
31
- </>
32
- );
33
- }
34
-
35
- export default App;