@tanstack/cta-engine 0.10.0-alpha.6
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 +21 -0
- package/dist/add-ons.js +109 -0
- package/dist/add.js +127 -0
- package/dist/cli.js +112 -0
- package/dist/config-file.js +23 -0
- package/dist/constants.js +5 -0
- package/dist/create-app.js +491 -0
- package/dist/custom-add-on.js +254 -0
- package/dist/environment.js +119 -0
- package/dist/index.js +1 -0
- package/dist/mcp.js +211 -0
- package/dist/options.js +309 -0
- package/dist/package-manager.js +30 -0
- package/dist/templates.js +6 -0
- package/dist/toolchain.js +6 -0
- package/dist/types/add-ons.d.ts +5 -0
- package/dist/types/add.d.ts +3 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config-file.d.ts +7 -0
- package/dist/types/constants.d.ts +6 -0
- package/dist/types/create-app.d.ts +6 -0
- package/dist/types/custom-add-on.d.ts +3 -0
- package/dist/types/environment.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp.d.ts +1 -0
- package/dist/types/options.d.ts +3 -0
- package/dist/types/package-manager.d.ts +6 -0
- package/dist/types/templates.d.ts +1 -0
- package/dist/types/toolchain.d.ts +3 -0
- package/dist/types/types.d.ts +107 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.js +8 -0
- package/package.json +49 -0
- package/src/add-ons.ts +145 -0
- package/src/add.ts +184 -0
- package/src/cli.ts +163 -0
- package/src/config-file.ts +45 -0
- package/src/constants.ts +9 -0
- package/src/create-app.ts +791 -0
- package/src/custom-add-on.ts +323 -0
- package/src/environment.ts +144 -0
- package/src/index.ts +1 -0
- package/src/mcp.ts +252 -0
- package/src/options.ts +359 -0
- package/src/package-manager.ts +46 -0
- package/src/templates.ts +7 -0
- package/src/toolchain.ts +7 -0
- package/src/types.ts +119 -0
- package/src/utils.ts +10 -0
- package/templates/react/add-on/clerk/README.md +3 -0
- package/templates/react/add-on/clerk/assets/_dot_env.local.append +2 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/header-user.tsx +19 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/provider.tsx +18 -0
- package/templates/react/add-on/clerk/assets/src/routes/demo.clerk.tsx +20 -0
- package/templates/react/add-on/clerk/info.json +13 -0
- package/templates/react/add-on/clerk/package.json +5 -0
- package/templates/react/add-on/convex/README.md +4 -0
- package/templates/react/add-on/convex/assets/_dot_cursorrules.append +93 -0
- package/templates/react/add-on/convex/assets/_dot_env.local.append +3 -0
- package/templates/react/add-on/convex/assets/convex/products.ts +8 -0
- package/templates/react/add-on/convex/assets/convex/schema.ts +10 -0
- package/templates/react/add-on/convex/assets/src/integrations/convex/provider.tsx +20 -0
- package/templates/react/add-on/convex/assets/src/routes/demo.convex.tsx +33 -0
- package/templates/react/add-on/convex/info.json +13 -0
- package/templates/react/add-on/convex/package.json +6 -0
- package/templates/react/add-on/form/assets/src/components/demo.FormComponents.tsx.ejs +300 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form-context.ts +4 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form.ts +22 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.address.tsx.ejs +213 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.simple.tsx.ejs +77 -0
- package/templates/react/add-on/form/info.json +26 -0
- package/templates/react/add-on/form/package.json +6 -0
- package/templates/react/add-on/module-federation/assets/module-federation.config.js.ejs +31 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +11 -0
- package/templates/react/add-on/module-federation/info.json +7 -0
- package/templates/react/add-on/module-federation/package.json +5 -0
- package/templates/react/add-on/netlify/README.md +11 -0
- package/templates/react/add-on/netlify/info.json +7 -0
- package/templates/react/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/react/add-on/sentry/assets/_dot_env.local.append +2 -0
- package/templates/react/add-on/sentry/assets/src/app/global-middleware.ts +25 -0
- package/templates/react/add-on/sentry/assets/src/routes/demo.sentry.testing.tsx +480 -0
- package/templates/react/add-on/sentry/info.json +14 -0
- package/templates/react/add-on/sentry/package.json +7 -0
- package/templates/react/add-on/shadcn/README.md +7 -0
- package/templates/react/add-on/shadcn/assets/_dot_cursorrules.append +7 -0
- package/templates/react/add-on/shadcn/assets/components.json +21 -0
- package/templates/react/add-on/shadcn/assets/src/lib/utils.ts +6 -0
- package/templates/react/add-on/shadcn/assets/src/styles.css +138 -0
- package/templates/react/add-on/shadcn/info.json +7 -0
- package/templates/react/add-on/shadcn/package.json +9 -0
- package/templates/react/add-on/start/assets/_dot_gitignore.append +2 -0
- package/templates/react/add-on/start/assets/app.config.ts.ejs +19 -0
- package/templates/react/add-on/start/assets/src/api.ts +6 -0
- package/templates/react/add-on/start/assets/src/client.tsx +8 -0
- package/templates/react/add-on/start/assets/src/router.tsx.ejs +77 -0
- package/templates/react/add-on/start/assets/src/routes/api.demo-names.ts +11 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.api-request.tsx.ejs +33 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +50 -0
- package/templates/react/add-on/start/assets/src/ssr.tsx +12 -0
- package/templates/react/add-on/start/info.json +18 -0
- package/templates/react/add-on/start/package.json +13 -0
- package/templates/react/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/react/add-on/store/assets/src/routes/demo.store.tsx.ejs +75 -0
- package/templates/react/add-on/store/info.json +13 -0
- package/templates/react/add-on/store/package.json +6 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/init.ts +9 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/react.ts +4 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/router.ts +18 -0
- package/templates/react/add-on/tRPC/assets/src/routes/api.trpc.$.tsx +16 -0
- package/templates/react/add-on/tRPC/info.json +9 -0
- package/templates/react/add-on/tRPC/package.json +9 -0
- package/templates/react/add-on/table/assets/src/data/demo-table-data.ts +50 -0
- package/templates/react/add-on/table/assets/src/routes/demo.table.tsx.ejs +373 -0
- package/templates/react/add-on/table/info.json +13 -0
- package/templates/react/add-on/table/package.json +7 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +5 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +70 -0
- package/templates/react/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx.ejs +53 -0
- package/templates/react/add-on/tanstack-query/info.json +13 -0
- package/templates/react/add-on/tanstack-query/package.json +6 -0
- package/templates/react/base/README.md.ejs +558 -0
- package/templates/react/base/_dot_gitignore +5 -0
- package/templates/react/base/_dot_vscode/settings.biome.json +38 -0
- package/templates/react/base/_dot_vscode/settings.json +11 -0
- package/templates/react/base/index.html.ejs +20 -0
- package/templates/react/base/package.biome.json +10 -0
- package/templates/react/base/package.eslintprettier.json +11 -0
- package/templates/react/base/package.json +29 -0
- package/templates/react/base/package.ts.json +7 -0
- package/templates/react/base/package.tw.json +6 -0
- package/templates/react/base/public/favicon.ico +0 -0
- package/templates/react/base/public/logo192.png +0 -0
- package/templates/react/base/public/logo512.png +0 -0
- package/templates/react/base/public/manifest.json +25 -0
- package/templates/react/base/public/robots.txt +3 -0
- package/templates/react/base/src/App.css +38 -0
- package/templates/react/base/src/App.test.tsx.ejs +10 -0
- package/templates/react/base/src/App.tsx.ejs +74 -0
- package/templates/react/base/src/components/Header.tsx.ejs +27 -0
- package/templates/react/base/src/logo.svg +44 -0
- package/templates/react/base/src/reportWebVitals.ts.ejs +28 -0
- package/templates/react/base/src/styles.css.ejs +15 -0
- package/templates/react/base/toolchain/.prettierignore +3 -0
- package/templates/react/base/toolchain/biome.json +31 -0
- package/templates/react/base/toolchain/eslint.config.js +5 -0
- package/templates/react/base/toolchain/prettier.config.js +10 -0
- package/templates/react/base/tsconfig.json.ejs +29 -0
- package/templates/react/base/vite.config.js.ejs +23 -0
- package/templates/react/code-router/src/main.tsx.ejs +92 -0
- package/templates/react/example/tanchat/README.md +37 -0
- package/templates/react/example/tanchat/assets/_dot_env.local.append +2 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-flowers.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-motherboard.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-racing.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-steamer-trunk.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-superhero.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-traveling.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-video-games.jpg +0 -0
- package/templates/react/example/tanchat/assets/src/components/example-AIAssistant.tsx +173 -0
- package/templates/react/example/tanchat/assets/src/components/example-GuitarRecommendation.tsx +47 -0
- package/templates/react/example/tanchat/assets/src/data/example-guitars.ts +83 -0
- package/templates/react/example/tanchat/assets/src/demo.index.css +220 -0
- package/templates/react/example/tanchat/assets/src/integrations/tanchat/header-user.tsx +5 -0
- package/templates/react/example/tanchat/assets/src/routes/example.chat.tsx +159 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/$guitarId.tsx +50 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/index.tsx +54 -0
- package/templates/react/example/tanchat/assets/src/store/example-assistant.ts +3 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.ai.ts +62 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.tools.ts +47 -0
- package/templates/react/example/tanchat/info.json +19 -0
- package/templates/react/example/tanchat/package.json +15 -0
- package/templates/react/file-router/package.fr.json +5 -0
- package/templates/react/file-router/src/main.tsx.ejs +55 -0
- package/templates/react/file-router/src/routes/__root.tsx.ejs +82 -0
- package/templates/solid/add-on/form/assets/src/routes/demo.form.tsx.ejs +352 -0
- package/templates/solid/add-on/form/info.json +13 -0
- package/templates/solid/add-on/form/package.json +5 -0
- package/templates/solid/add-on/module-federation/assets/module-federation.config.js.ejs +27 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +9 -0
- package/templates/solid/add-on/module-federation/info.json +7 -0
- package/templates/solid/add-on/module-federation/package.json +5 -0
- package/templates/solid/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/solid/add-on/sentry/assets/_dot_env.local.append +2 -0
- package/templates/solid/add-on/sentry/assets/src/routes/demo.sentry.bad-event-handler.tsx +20 -0
- package/templates/solid/add-on/sentry/info.json +13 -0
- package/templates/solid/add-on/sentry/package.json +5 -0
- package/templates/solid/add-on/solid-ui/README.md +9 -0
- package/templates/solid/add-on/solid-ui/assets/src/lib/utils.ts +6 -0
- package/templates/solid/add-on/solid-ui/assets/src/styles.css +138 -0
- package/templates/solid/add-on/solid-ui/assets/ui.config.json +13 -0
- package/templates/solid/add-on/solid-ui/info.json +11 -0
- package/templates/solid/add-on/solid-ui/package.json +9 -0
- package/templates/solid/add-on/start/assets/app.config.ts +16 -0
- package/templates/solid/add-on/start/assets/src/api.ts +6 -0
- package/templates/solid/add-on/start/assets/src/client.tsx +7 -0
- package/templates/solid/add-on/start/assets/src/router.tsx.ejs +24 -0
- package/templates/solid/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +49 -0
- package/templates/solid/add-on/start/assets/src/ssr.tsx +12 -0
- package/templates/solid/add-on/start/info.json +14 -0
- package/templates/solid/add-on/start/package.json +12 -0
- package/templates/solid/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/add-on/store/assets/src/routes/demo.store.tsx.ejs +77 -0
- package/templates/solid/add-on/store/info.json +13 -0
- package/templates/solid/add-on/store/package.json +6 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/header-user.tsx +5 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/provider.tsx +15 -0
- package/templates/solid/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx +30 -0
- package/templates/solid/add-on/tanstack-query/info.json +13 -0
- package/templates/solid/add-on/tanstack-query/package.json +6 -0
- package/templates/solid/base/README.md.ejs +215 -0
- package/templates/solid/base/_dot_cursorrules.append +35 -0
- package/templates/solid/base/_dot_gitignore +5 -0
- package/templates/solid/base/_dot_vscode/settings.biome.json +38 -0
- package/templates/solid/base/_dot_vscode/settings.json +11 -0
- package/templates/solid/base/index.html.ejs +20 -0
- package/templates/solid/base/package.biome.json +10 -0
- package/templates/solid/base/package.eslintprettier.json +11 -0
- package/templates/solid/base/package.json +22 -0
- package/templates/solid/base/package.ts.json +5 -0
- package/templates/solid/base/package.tw.json +6 -0
- package/templates/solid/base/public/favicon.ico +0 -0
- package/templates/solid/base/public/logo192.png +0 -0
- package/templates/solid/base/public/logo512.png +0 -0
- package/templates/solid/base/public/manifest.json +25 -0
- package/templates/solid/base/public/robots.txt +3 -0
- package/templates/solid/base/src/App.css +0 -0
- package/templates/solid/base/src/App.tsx.ejs +47 -0
- package/templates/solid/base/src/components/Header.tsx.ejs +26 -0
- package/templates/solid/base/src/logo.svg +120 -0
- package/templates/solid/base/src/styles.css.ejs +15 -0
- package/templates/solid/base/toolchain/.prettierignore +3 -0
- package/templates/solid/base/toolchain/biome.json +31 -0
- package/templates/solid/base/toolchain/eslint.config.js +5 -0
- package/templates/solid/base/toolchain/prettier.config.js +10 -0
- package/templates/solid/base/tsconfig.json.ejs +31 -0
- package/templates/solid/base/vite.config.js.ejs +22 -0
- package/templates/solid/code-router/src/main.tsx.ejs +71 -0
- package/templates/solid/example/tanchat/README.md +52 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/README.md +110 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/_dot_env.example +1 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/package.json +26 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/src/index.ts +102 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/tsconfig.json +15 -0
- package/templates/solid/example/tanchat/assets/src/components/demo.SettingsDialog.tsx +149 -0
- package/templates/solid/example/tanchat/assets/src/demo.index.css +227 -0
- package/templates/solid/example/tanchat/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/example/tanchat/assets/src/routes/example.chat.tsx +435 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.hooks.ts +17 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.store.ts +133 -0
- package/templates/solid/example/tanchat/info.json +14 -0
- package/templates/solid/example/tanchat/package.json +7 -0
- package/templates/solid/file-router/package.fr.json +5 -0
- package/templates/solid/file-router/src/main.tsx.ejs +47 -0
- package/templates/solid/file-router/src/routes/__root.tsx.ejs +41 -0
- package/templates/solid/file-router/src/routes/index.tsx +43 -0
- package/tests/cra.test.ts +293 -0
- package/tests/snapshots/cra/cr-js-npm.json +33 -0
- package/tests/snapshots/cra/cr-ts-npm.json +34 -0
- package/tests/snapshots/cra/cr-ts-start-npm.json +38 -0
- package/tests/snapshots/cra/fr-ts-npm.json +34 -0
- package/tests/snapshots/cra/fr-ts-tw-npm.json +33 -0
- package/tests/snapshots/cra/solid-cr-js-npm.json +31 -0
- package/tests/snapshots/cra/solid-cr-ts-npm.json +32 -0
- package/tests/snapshots/cra/solid-cr-ts-start-npm.json +36 -0
- package/tests/snapshots/cra/solid-fr-ts-npm.json +33 -0
- package/tests/snapshots/cra/solid-fr-ts-tw-npm.json +32 -0
- package/tests/test-utilities.ts +87 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
This document serves as some special instructions when working with Convex.
|
|
2
|
+
|
|
3
|
+
# Schemas
|
|
4
|
+
|
|
5
|
+
When designing the schema please see this page on built in System fields and data types available: https://docs.convex.dev/database/types
|
|
6
|
+
|
|
7
|
+
Here are some specifics that are often mishandled:
|
|
8
|
+
|
|
9
|
+
## v (https://docs.convex.dev/api/modules/values#v)
|
|
10
|
+
|
|
11
|
+
The validator builder.
|
|
12
|
+
|
|
13
|
+
This builder allows you to build validators for Convex values.
|
|
14
|
+
|
|
15
|
+
Validators can be used in schema definitions and as input validators for Convex functions.
|
|
16
|
+
|
|
17
|
+
Type declaration
|
|
18
|
+
Name Type
|
|
19
|
+
id <TableName>(tableName: TableName) => VId<GenericId<TableName>, "required">
|
|
20
|
+
null () => VNull<null, "required">
|
|
21
|
+
number () => VFloat64<number, "required">
|
|
22
|
+
float64 () => VFloat64<number, "required">
|
|
23
|
+
bigint () => VInt64<bigint, "required">
|
|
24
|
+
int64 () => VInt64<bigint, "required">
|
|
25
|
+
boolean () => VBoolean<boolean, "required">
|
|
26
|
+
string () => VString<string, "required">
|
|
27
|
+
bytes () => VBytes<ArrayBuffer, "required">
|
|
28
|
+
literal <T>(literal: T) => VLiteral<T, "required">
|
|
29
|
+
array <T>(element: T) => VArray<T["type"][], T, "required">
|
|
30
|
+
object <T>(fields: T) => VObject<Expand<{ [Property in string | number | symbol]?: Exclude<Infer<T[Property]>, undefined> } & { [Property in string | number | symbol]: Infer<T[Property]> }>, T, "required", { [Property in string | number | symbol]: Property | `${Property & string}.${T[Property]["fieldPaths"]}` }[keyof T] & string>
|
|
31
|
+
record <Key, Value>(keys: Key, values: Value) => VRecord<Record<Infer<Key>, Value["type"]>, Key, Value, "required", string>
|
|
32
|
+
union <T>(...members: T) => VUnion<T[number]["type"], T, "required", T[number]["fieldPaths"]>
|
|
33
|
+
any () => VAny<any, "required", string>
|
|
34
|
+
optional <T>(value: T) => VOptional<T>
|
|
35
|
+
|
|
36
|
+
## System fields (https://docs.convex.dev/database/types#system-fields)
|
|
37
|
+
|
|
38
|
+
Every document in Convex has two automatically-generated system fields:
|
|
39
|
+
|
|
40
|
+
_id: The document ID of the document.
|
|
41
|
+
_creationTime: The time this document was created, in milliseconds since the Unix epoch.
|
|
42
|
+
|
|
43
|
+
You do not need to add indices as these are added automatically.
|
|
44
|
+
|
|
45
|
+
## Example Schema
|
|
46
|
+
|
|
47
|
+
This is an example of a well crafted schema.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
51
|
+
import { v } from "convex/values";
|
|
52
|
+
|
|
53
|
+
export default defineSchema(
|
|
54
|
+
{
|
|
55
|
+
users: defineTable({
|
|
56
|
+
name: v.string(),
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
sessions: defineTable({
|
|
60
|
+
userId: v.id("users"),
|
|
61
|
+
sessionId: v.string(),
|
|
62
|
+
}).index("sessionId", ["sessionId"]),
|
|
63
|
+
|
|
64
|
+
threads: defineTable({
|
|
65
|
+
uuid: v.string(),
|
|
66
|
+
summary: v.optional(v.string()),
|
|
67
|
+
summarizer: v.optional(v.id("_scheduled_functions")),
|
|
68
|
+
}).index("uuid", ["uuid"]),
|
|
69
|
+
|
|
70
|
+
messages: defineTable({
|
|
71
|
+
message: v.string(),
|
|
72
|
+
threadId: v.id("threads"),
|
|
73
|
+
author: v.union(
|
|
74
|
+
v.object({
|
|
75
|
+
role: v.literal("system"),
|
|
76
|
+
}),
|
|
77
|
+
v.object({
|
|
78
|
+
role: v.literal("assistant"),
|
|
79
|
+
context: v.array(v.id("messages")),
|
|
80
|
+
model: v.optional(v.string()),
|
|
81
|
+
}),
|
|
82
|
+
v.object({
|
|
83
|
+
role: v.literal("user"),
|
|
84
|
+
userId: v.id("users"),
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
})
|
|
88
|
+
.index("threadId", ["threadId"]),
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Sourced from: https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/convex-cursorrules-prompt-file/.cursorrules
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConvexProvider } from 'convex/react'
|
|
2
|
+
import { ConvexQueryClient } from '@convex-dev/react-query'
|
|
3
|
+
|
|
4
|
+
const CONVEX_URL = (import.meta as any).env.VITE_CONVEX_URL
|
|
5
|
+
if (!CONVEX_URL) {
|
|
6
|
+
console.error('missing envar CONVEX_URL')
|
|
7
|
+
}
|
|
8
|
+
const convexQueryClient = new ConvexQueryClient(CONVEX_URL)
|
|
9
|
+
|
|
10
|
+
export default function AppConvexProvider({
|
|
11
|
+
children,
|
|
12
|
+
}: {
|
|
13
|
+
children: React.ReactNode
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<ConvexProvider client={convexQueryClient.convexClient}>
|
|
17
|
+
{children}
|
|
18
|
+
</ConvexProvider>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Suspense } from 'react'
|
|
2
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
3
|
+
import { useQuery } from 'convex/react'
|
|
4
|
+
|
|
5
|
+
import { api } from '../../convex/_generated/api'
|
|
6
|
+
|
|
7
|
+
export const Route = createFileRoute('/demo/convex')({
|
|
8
|
+
component: App,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function Products() {
|
|
12
|
+
const products = useQuery(api.products.get)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ul>
|
|
16
|
+
{(products || []).map((p) => (
|
|
17
|
+
<li key={p._id}>
|
|
18
|
+
{p.title} - {p.price}
|
|
19
|
+
</li>
|
|
20
|
+
))}
|
|
21
|
+
</ul>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<div className="p-4">
|
|
28
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
29
|
+
<Products />
|
|
30
|
+
</Suspense>
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { useStore } from '@tanstack/react-form'
|
|
2
|
+
|
|
3
|
+
import { useFieldContext, useFormContext } from '../hooks/demo.form-context'
|
|
4
|
+
<% if (addOnEnabled.shadcn) { %>
|
|
5
|
+
import { Button } from '@/components/ui/button'
|
|
6
|
+
import { Input } from '@/components/ui/input'
|
|
7
|
+
import { Textarea as ShadcnTextarea } from '@/components/ui/textarea'
|
|
8
|
+
import * as ShadcnSelect from '@/components/ui/select'
|
|
9
|
+
import { Slider as ShadcnSlider } from '@/components/ui/slider'
|
|
10
|
+
import { Switch as ShadcnSwitch } from '@/components/ui/switch'
|
|
11
|
+
import { Label } from '@/components/ui/label'
|
|
12
|
+
|
|
13
|
+
export function SubscribeButton({ label }: { label: string }) {
|
|
14
|
+
const form = useFormContext()
|
|
15
|
+
return (
|
|
16
|
+
<form.Subscribe selector={(state) => state.isSubmitting}>
|
|
17
|
+
{(isSubmitting) => (
|
|
18
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
19
|
+
{label}
|
|
20
|
+
</Button>
|
|
21
|
+
)}
|
|
22
|
+
</form.Subscribe>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ErrorMessages({
|
|
27
|
+
errors,
|
|
28
|
+
}: {
|
|
29
|
+
errors: Array<string | { message: string }>
|
|
30
|
+
}) {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
{errors.map((error) => (
|
|
34
|
+
<div
|
|
35
|
+
key={typeof error === 'string' ? error : error.message}
|
|
36
|
+
className="text-red-500 mt-1 font-bold"
|
|
37
|
+
>
|
|
38
|
+
{typeof error === 'string' ? error : error.message}
|
|
39
|
+
</div>
|
|
40
|
+
))}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function TextField({
|
|
46
|
+
label,
|
|
47
|
+
placeholder,
|
|
48
|
+
}: {
|
|
49
|
+
label: string
|
|
50
|
+
placeholder?: string
|
|
51
|
+
}) {
|
|
52
|
+
const field = useFieldContext<string>()
|
|
53
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div>
|
|
57
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
58
|
+
{label}
|
|
59
|
+
</Label>
|
|
60
|
+
<Input
|
|
61
|
+
value={field.state.value}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
onBlur={field.handleBlur}
|
|
64
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
65
|
+
/>
|
|
66
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function TextArea({
|
|
72
|
+
label,
|
|
73
|
+
rows = 3,
|
|
74
|
+
}: {
|
|
75
|
+
label: string
|
|
76
|
+
rows?: number
|
|
77
|
+
}) {
|
|
78
|
+
const field = useFieldContext<string>()
|
|
79
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
84
|
+
{label}
|
|
85
|
+
</Label>
|
|
86
|
+
<ShadcnTextarea
|
|
87
|
+
id={label}
|
|
88
|
+
value={field.state.value}
|
|
89
|
+
onBlur={field.handleBlur}
|
|
90
|
+
rows={rows}
|
|
91
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
92
|
+
/>
|
|
93
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function Select({
|
|
99
|
+
label,
|
|
100
|
+
values,
|
|
101
|
+
placeholder,
|
|
102
|
+
}: {
|
|
103
|
+
label: string
|
|
104
|
+
values: Array<{ label: string; value: string }>
|
|
105
|
+
placeholder?: string
|
|
106
|
+
}) {
|
|
107
|
+
const field = useFieldContext<string>()
|
|
108
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div>
|
|
112
|
+
<ShadcnSelect.Select
|
|
113
|
+
name={field.name}
|
|
114
|
+
value={field.state.value}
|
|
115
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
116
|
+
>
|
|
117
|
+
<ShadcnSelect.SelectTrigger className="w-full">
|
|
118
|
+
<ShadcnSelect.SelectValue placeholder={placeholder} />
|
|
119
|
+
</ShadcnSelect.SelectTrigger>
|
|
120
|
+
<ShadcnSelect.SelectContent>
|
|
121
|
+
<ShadcnSelect.SelectGroup>
|
|
122
|
+
<ShadcnSelect.SelectLabel>{label}</ShadcnSelect.SelectLabel>
|
|
123
|
+
{values.map((value) => (
|
|
124
|
+
<ShadcnSelect.SelectItem key={value.value} value={value.value}>
|
|
125
|
+
{value.label}
|
|
126
|
+
</ShadcnSelect.SelectItem>
|
|
127
|
+
))}
|
|
128
|
+
</ShadcnSelect.SelectGroup>
|
|
129
|
+
</ShadcnSelect.SelectContent>
|
|
130
|
+
</ShadcnSelect.Select>
|
|
131
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function Slider({ label }: { label: string }) {
|
|
137
|
+
const field = useFieldContext<number>()
|
|
138
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div>
|
|
142
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
143
|
+
{label}
|
|
144
|
+
</Label>
|
|
145
|
+
<ShadcnSlider
|
|
146
|
+
id={label}
|
|
147
|
+
onBlur={field.handleBlur}
|
|
148
|
+
value={[field.state.value]}
|
|
149
|
+
onValueChange={(value) => field.handleChange(value[0])}
|
|
150
|
+
/>
|
|
151
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function Switch({ label }: { label: string }) {
|
|
157
|
+
const field = useFieldContext<boolean>()
|
|
158
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div>
|
|
162
|
+
<div className="flex items-center gap-2">
|
|
163
|
+
<ShadcnSwitch
|
|
164
|
+
id={label}
|
|
165
|
+
onBlur={field.handleBlur}
|
|
166
|
+
checked={field.state.value}
|
|
167
|
+
onCheckedChange={(checked) => field.handleChange(checked)}
|
|
168
|
+
/>
|
|
169
|
+
<Label htmlFor={label}>{label}</Label>
|
|
170
|
+
</div>
|
|
171
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
172
|
+
</div>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
<% } else { %>
|
|
177
|
+
export function SubscribeButton({ label }: { label: string }) {
|
|
178
|
+
const form = useFormContext()
|
|
179
|
+
return (
|
|
180
|
+
<form.Subscribe selector={(state) => state.isSubmitting}>
|
|
181
|
+
{(isSubmitting) => (
|
|
182
|
+
<button
|
|
183
|
+
type="submit"
|
|
184
|
+
disabled={isSubmitting}
|
|
185
|
+
className="px-6 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-colors disabled:opacity-50"
|
|
186
|
+
>
|
|
187
|
+
{label}
|
|
188
|
+
</button>
|
|
189
|
+
)}
|
|
190
|
+
</form.Subscribe>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function ErrorMessages({
|
|
195
|
+
errors,
|
|
196
|
+
}: {
|
|
197
|
+
errors: Array<string | { message: string }>
|
|
198
|
+
}) {
|
|
199
|
+
return (
|
|
200
|
+
<>
|
|
201
|
+
{errors.map((error) => (
|
|
202
|
+
<div
|
|
203
|
+
key={typeof error === 'string' ? error : error.message}
|
|
204
|
+
className="text-red-500 mt-1 font-bold"
|
|
205
|
+
>
|
|
206
|
+
{typeof error === 'string' ? error : error.message}
|
|
207
|
+
</div>
|
|
208
|
+
))}
|
|
209
|
+
</>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function TextField({
|
|
214
|
+
label,
|
|
215
|
+
placeholder,
|
|
216
|
+
}: {
|
|
217
|
+
label: string
|
|
218
|
+
placeholder?: string
|
|
219
|
+
}) {
|
|
220
|
+
const field = useFieldContext<string>()
|
|
221
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<div>
|
|
225
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
226
|
+
{label}
|
|
227
|
+
<input
|
|
228
|
+
value={field.state.value}
|
|
229
|
+
placeholder={placeholder}
|
|
230
|
+
onBlur={field.handleBlur}
|
|
231
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
232
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
233
|
+
/>
|
|
234
|
+
</label>
|
|
235
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
236
|
+
</div>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function TextArea({
|
|
241
|
+
label,
|
|
242
|
+
rows = 3,
|
|
243
|
+
}: {
|
|
244
|
+
label: string
|
|
245
|
+
rows?: number
|
|
246
|
+
}) {
|
|
247
|
+
const field = useFieldContext<string>()
|
|
248
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div>
|
|
252
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
253
|
+
{label}
|
|
254
|
+
<textarea
|
|
255
|
+
value={field.state.value}
|
|
256
|
+
onBlur={field.handleBlur}
|
|
257
|
+
rows={rows}
|
|
258
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
259
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
260
|
+
/>
|
|
261
|
+
</label>
|
|
262
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
263
|
+
</div>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function Select({
|
|
268
|
+
label,
|
|
269
|
+
values,
|
|
270
|
+
}: {
|
|
271
|
+
label: string
|
|
272
|
+
values: Array<{ label: string; value: string }>
|
|
273
|
+
placeholder?: string
|
|
274
|
+
}) {
|
|
275
|
+
const field = useFieldContext<string>()
|
|
276
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<div>
|
|
280
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
281
|
+
{label}
|
|
282
|
+
</label>
|
|
283
|
+
<select
|
|
284
|
+
name={field.name}
|
|
285
|
+
value={field.state.value}
|
|
286
|
+
onBlur={field.handleBlur}
|
|
287
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
288
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
289
|
+
>
|
|
290
|
+
{values.map((value) => (
|
|
291
|
+
<option key={value.value} value={value.value}>
|
|
292
|
+
{value.label}
|
|
293
|
+
</option>
|
|
294
|
+
))}
|
|
295
|
+
</select>
|
|
296
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
297
|
+
</div>
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
<% } %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createFormHook } from '@tanstack/react-form'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Select,
|
|
5
|
+
SubscribeButton,
|
|
6
|
+
TextArea,
|
|
7
|
+
TextField,
|
|
8
|
+
} from '../components/demo.FormComponents'
|
|
9
|
+
import { fieldContext, formContext } from './demo.form-context'
|
|
10
|
+
|
|
11
|
+
export const { useAppForm } = createFormHook({
|
|
12
|
+
fieldComponents: {
|
|
13
|
+
TextField,
|
|
14
|
+
Select,
|
|
15
|
+
TextArea,
|
|
16
|
+
},
|
|
17
|
+
formComponents: {
|
|
18
|
+
SubscribeButton,
|
|
19
|
+
},
|
|
20
|
+
fieldContext,
|
|
21
|
+
formContext,
|
|
22
|
+
})
|