@tanstack/cta-framework-react-cra 0.44.0 → 0.44.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/add-ons/drizzle/assets/src/routes/demo/drizzle.tsx +1 -1
- package/add-ons/oRPC/assets/src/routes/api.$.ts +1 -1
- package/add-ons/oRPC/package.json +7 -7
- package/add-ons/paraglide/README.md +7 -0
- package/add-ons/paraglide/assets/messages/de.json +9 -0
- package/add-ons/paraglide/assets/messages/en.json +9 -0
- package/add-ons/paraglide/assets/project.inlang/settings.json +12 -0
- package/add-ons/paraglide/assets/src/components/LocaleSwitcher.tsx.ejs +44 -0
- package/add-ons/paraglide/assets/src/routes/demo.i18n.tsx.ejs +34 -0
- package/add-ons/paraglide/info.json +25 -0
- package/add-ons/paraglide/package.json +5 -0
- package/add-ons/paraglide/small-logo.svg +4 -0
- package/add-ons/sentry/package.json +1 -1
- package/add-ons/start/assets/src/router.tsx.ejs +9 -0
- package/add-ons/start/assets/src/server.ts.ejs +9 -0
- package/add-ons/start/assets/vite.config.ts.ejs +8 -1
- package/add-ons/tanstack-query/info.json +1 -1
- package/examples/tanchat/assets/src/routes/demo/api.tanchat.ts +33 -33
- package/hosts/nitro/package.json +1 -1
- package/package.json +2 -2
- package/project/base/README.md.ejs +1 -1
- package/project/base/src/main.tsx.ejs +9 -2
- package/project/base/src/routes/__root.tsx.ejs +23 -2
- package/project/base/tsconfig.json.ejs +2 -1
- package/project/base/vite.config.ts.ejs +7 -2
- package/tests/snapshots/react-cra/cr-js-form-npm.json +1 -1
- package/tests/snapshots/react-cra/cr-js-npm.json +1 -1
- package/tests/snapshots/react-cra/cr-ts-npm.json +1 -1
- package/tests/snapshots/react-cra/cr-ts-start-apollo-client-npm.json +1 -1
- package/tests/snapshots/react-cra/cr-ts-start-npm.json +1 -1
- package/tests/snapshots/react-cra/cr-ts-start-tanstack-query-npm.json +1 -1
- package/tests/snapshots/react-cra/fr-ts-biome-npm.json +2 -2
- package/tests/snapshots/react-cra/fr-ts-npm.json +1 -1
- package/tests/snapshots/react-cra/fr-ts-tw-npm.json +1 -1
- package/toolchains/biome/assets/biome.json +2 -1
|
@@ -2,7 +2,7 @@ import '@/polyfill'
|
|
|
2
2
|
|
|
3
3
|
import { OpenAPIHandler } from '@orpc/openapi/fetch'
|
|
4
4
|
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
|
5
|
-
import {
|
|
5
|
+
import { SmartCoercionPlugin } from '@orpc/json-schema'
|
|
6
6
|
import { createFileRoute } from '@tanstack/react-router'
|
|
7
7
|
import { onError } from '@orpc/server'
|
|
8
8
|
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@orpc/client": "^1.
|
|
4
|
-
"@orpc/json-schema": "^1.
|
|
5
|
-
"@orpc/openapi": "^1.
|
|
6
|
-
"@orpc/server": "^1.
|
|
7
|
-
"@orpc/tanstack-query": "^1.
|
|
8
|
-
"@orpc/zod": "^1.
|
|
9
|
-
"zod": "^4.
|
|
3
|
+
"@orpc/client": "^1.13.0",
|
|
4
|
+
"@orpc/json-schema": "^1.13.0",
|
|
5
|
+
"@orpc/openapi": "^1.13.0",
|
|
6
|
+
"@orpc/server": "^1.13.0",
|
|
7
|
+
"@orpc/tanstack-query": "^1.13.0",
|
|
8
|
+
"@orpc/zod": "^1.13.0",
|
|
9
|
+
"zod": "^4.2.1"
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Paraglide i18n
|
|
2
|
+
|
|
3
|
+
This add-on wires up ParaglideJS for localized routing and message formatting.
|
|
4
|
+
|
|
5
|
+
- Messages live in `project.inlang/messages`.
|
|
6
|
+
- URLs are localized through the Paraglide Vite plugin and router `rewrite` hooks.
|
|
7
|
+
- Run the dev server or build to regenerate the `src/paraglide` outputs.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://inlang.com/schema/inlang-message-format",
|
|
3
|
+
"home_page": "Startseite",
|
|
4
|
+
"about_page": "Über uns",
|
|
5
|
+
"example_message": "Willkommen in deiner i18n-App.",
|
|
6
|
+
"language_label": "Sprache",
|
|
7
|
+
"current_locale": "Aktuelle Sprache: {locale}",
|
|
8
|
+
"learn_router": "Paraglide JS lernen"
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://inlang.com/schema/inlang-message-format",
|
|
3
|
+
"home_page": "Home page",
|
|
4
|
+
"about_page": "About page",
|
|
5
|
+
"example_message": "Welcome to your i18n app.",
|
|
6
|
+
"language_label": "Language",
|
|
7
|
+
"current_locale": "Current locale: {locale}",
|
|
8
|
+
"learn_router": "Learn Paraglide JS"
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://inlang.com/schema/project-settings",
|
|
3
|
+
"baseLocale": "en",
|
|
4
|
+
"locales": ["en", "de"],
|
|
5
|
+
"modules": [
|
|
6
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js",
|
|
7
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js"
|
|
8
|
+
],
|
|
9
|
+
"plugin.inlang.messageFormat": {
|
|
10
|
+
"pathPattern": "./messages/{locale}.json"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Locale switcher refs:
|
|
2
|
+
// - Paraglide docs: https://inlang.com/m/gerre34r/library-inlang-paraglideJs
|
|
3
|
+
// - Router example: https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#switching-locale
|
|
4
|
+
import { getLocale, locales, setLocale } from '@/paraglide/runtime'
|
|
5
|
+
import { m } from '@/paraglide/messages'
|
|
6
|
+
|
|
7
|
+
export default function ParaglideLocaleSwitcher() {
|
|
8
|
+
const currentLocale = getLocale()
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div
|
|
12
|
+
style={{
|
|
13
|
+
display: 'flex',
|
|
14
|
+
gap: '0.5rem',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
color: 'inherit',
|
|
17
|
+
}}
|
|
18
|
+
aria-label={m.language_label()}
|
|
19
|
+
>
|
|
20
|
+
<span style={{ opacity: 0.85 }}>{m.current_locale({ locale: currentLocale })}</span>
|
|
21
|
+
<div style={{ display: 'flex', gap: '0.25rem' }}>
|
|
22
|
+
{locales.map((locale) => (
|
|
23
|
+
<button
|
|
24
|
+
key={locale}
|
|
25
|
+
onClick={() => setLocale(locale)}
|
|
26
|
+
aria-pressed={locale === currentLocale}
|
|
27
|
+
style={{
|
|
28
|
+
cursor: 'pointer',
|
|
29
|
+
padding: '0.35rem 0.75rem',
|
|
30
|
+
borderRadius: '999px',
|
|
31
|
+
border: '1px solid #d1d5db',
|
|
32
|
+
background: locale === currentLocale ? '#0f172a' : 'transparent',
|
|
33
|
+
color: locale === currentLocale ? '#f8fafc' : 'inherit',
|
|
34
|
+
fontWeight: locale === currentLocale ? 700 : 500,
|
|
35
|
+
letterSpacing: '0.01em',
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
{locale.toUpperCase()}
|
|
39
|
+
</button>
|
|
40
|
+
))}
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import logo from "../logo.svg";
|
|
3
|
+
import { m } from "@/paraglide/messages";
|
|
4
|
+
import LocaleSwitcher from "../components/LocaleSwitcher";
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/demo/i18n")({
|
|
7
|
+
component: App,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function App() {
|
|
11
|
+
return (
|
|
12
|
+
<div className="text-center">
|
|
13
|
+
<header className="min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)] gap-4">
|
|
14
|
+
<img
|
|
15
|
+
src={logo}
|
|
16
|
+
className="h-[40vmin] pointer-events-none animate-[spin_20s_linear_infinite]"
|
|
17
|
+
alt="logo"
|
|
18
|
+
/>
|
|
19
|
+
<p>{m.example_message({ username: "TanStack Router" })}</p>
|
|
20
|
+
<a
|
|
21
|
+
className="text-[#61dafb] hover:underline"
|
|
22
|
+
href="https://inlang.com/m/gerre34r/library-inlang-paraglideJs"
|
|
23
|
+
target="_blank"
|
|
24
|
+
rel="noopener noreferrer"
|
|
25
|
+
>
|
|
26
|
+
{m.learn_router()}
|
|
27
|
+
</a>
|
|
28
|
+
<div className="mt-3">
|
|
29
|
+
<LocaleSwitcher />
|
|
30
|
+
</div>
|
|
31
|
+
</header>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Paraglide (i18n)",
|
|
3
|
+
"description": "i18n with localized routing",
|
|
4
|
+
"phase": "add-on",
|
|
5
|
+
"modes": ["file-router"],
|
|
6
|
+
"type": "add-on",
|
|
7
|
+
"priority": 30,
|
|
8
|
+
"link": "https://github.com/paraglidejs/paraglide-js",
|
|
9
|
+
"routes": [
|
|
10
|
+
{
|
|
11
|
+
"icon": "Languages",
|
|
12
|
+
"url": "/demo/i18n",
|
|
13
|
+
"name": "I18n example",
|
|
14
|
+
"path": "src/routes/demo.i18n.tsx",
|
|
15
|
+
"jsName": "I18nDemo"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"integrations": [
|
|
19
|
+
{
|
|
20
|
+
"type": "header-user",
|
|
21
|
+
"path": "src/components/LocaleSwitcher.tsx",
|
|
22
|
+
"jsName": "ParaglideLocaleSwitcher"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"scripts": {
|
|
3
3
|
"build": "vite build && cp instrument.server.mjs .output/server",
|
|
4
|
-
"dev": "NODE_OPTIONS='--import ./instrument.server.mjs' vite dev --port 3000",
|
|
4
|
+
"dev": "dotenv -e .env.local -- sh -c \"NODE_OPTIONS='--import ./instrument.server.mjs' vite dev --port 3000\"",
|
|
5
5
|
"start": "node --import ./.output/server/instrument.server.mjs .output/server/index.mjs"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
@@ -11,6 +11,8 @@ import { HttpLink } from "@apollo/client";
|
|
|
11
11
|
<% } %>
|
|
12
12
|
<% if (addOnEnabled.sentry) { %>
|
|
13
13
|
import * as Sentry from "@sentry/tanstackstart-react";
|
|
14
|
+
<% } %><% if (addOnEnabled.paraglide) { %>
|
|
15
|
+
import { deLocalizeUrl, localizeUrl } from "./paraglide/runtime";
|
|
14
16
|
<% } %>
|
|
15
17
|
|
|
16
18
|
// Import the generated route tree
|
|
@@ -41,6 +43,13 @@ export const getRouter = () => {
|
|
|
41
43
|
...rqContext,
|
|
42
44
|
<% } %>
|
|
43
45
|
},
|
|
46
|
+
<% if (addOnEnabled.paraglide) { %>
|
|
47
|
+
// Paraglide URL rewrite docs: https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#rewrite-url
|
|
48
|
+
rewrite: {
|
|
49
|
+
input: ({ url }) => deLocalizeUrl(url),
|
|
50
|
+
output: ({ url }) => localizeUrl(url),
|
|
51
|
+
},
|
|
52
|
+
<% } %>
|
|
44
53
|
<% if (addOnEnabled['tanstack-query'] || addOnEnabled['apollo-client']) { %>
|
|
45
54
|
defaultPreload: "intent",
|
|
46
55
|
<% } else { %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<% if (!addOnEnabled.paraglide) { ignoreFile() } %>import { paraglideMiddleware } from './paraglide/server'
|
|
2
|
+
import handler from '@tanstack/react-start/server-entry'
|
|
3
|
+
|
|
4
|
+
// Server-side URL localization/redirects for Paraglide
|
|
5
|
+
export default {
|
|
6
|
+
fetch(req: Request): Promise<Response> {
|
|
7
|
+
return paraglideMiddleware(req, () => handler.fetch(req))
|
|
8
|
+
},
|
|
9
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
2
|
import { devtools } from '@tanstack/devtools-vite'
|
|
3
|
+
<% if (addOnEnabled.paraglide) { -%>
|
|
4
|
+
import { paraglideVitePlugin } from "@inlang/paraglide-js"
|
|
5
|
+
<% } -%>
|
|
3
6
|
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
4
7
|
import viteReact from '@vitejs/plugin-react'
|
|
5
8
|
import viteTsConfigPaths from 'vite-tsconfig-paths'<% if (tailwind) { %>
|
|
@@ -8,7 +11,11 @@ import tailwindcss from "@tailwindcss/vite"
|
|
|
8
11
|
<% } %>
|
|
9
12
|
|
|
10
13
|
const config = defineConfig({
|
|
11
|
-
plugins: [devtools(), <%
|
|
14
|
+
plugins: [devtools(), <% if (addOnEnabled.paraglide) { %>paraglideVitePlugin({
|
|
15
|
+
project: './project.inlang',
|
|
16
|
+
outdir: './src/paraglide',
|
|
17
|
+
strategy: ['url'],
|
|
18
|
+
}), <% } %><% for(const integration of integrations.filter(i => i.type === 'vite-plugin')) { %><%- integrationImportCode(integration) %>,<% } %>
|
|
12
19
|
// this is the plugin that enables path aliases
|
|
13
20
|
viteTsConfigPaths({
|
|
14
21
|
projects: ['./tsconfig.json'],
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { createFileRoute } from
|
|
2
|
-
import { chat, maxIterations,
|
|
3
|
-
import { anthropicText } from
|
|
4
|
-
import { openaiText } from
|
|
5
|
-
import { geminiText } from
|
|
6
|
-
import { ollamaText } from
|
|
1
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
2
|
+
import { chat, maxIterations, toServerSentEventsResponse } from '@tanstack/ai'
|
|
3
|
+
import { anthropicText } from '@tanstack/ai-anthropic'
|
|
4
|
+
import { openaiText } from '@tanstack/ai-openai'
|
|
5
|
+
import { geminiText } from '@tanstack/ai-gemini'
|
|
6
|
+
import { ollamaText } from '@tanstack/ai-ollama'
|
|
7
7
|
|
|
8
|
-
import { getGuitars, recommendGuitarToolDef } from
|
|
9
|
-
import type { Provider } from
|
|
8
|
+
import { getGuitars, recommendGuitarToolDef } from '@/lib/example.guitar-tools'
|
|
9
|
+
import type { Provider } from '@/lib/model-selection'
|
|
10
10
|
|
|
11
11
|
const SYSTEM_PROMPT = `You are a helpful assistant for a store that sells guitars.
|
|
12
12
|
|
|
@@ -23,39 +23,39 @@ IMPORTANT:
|
|
|
23
23
|
- ONLY recommend guitars from our inventory (use getGuitars first)
|
|
24
24
|
- The recommendGuitar tool has a buy button - this is how customers purchase
|
|
25
25
|
- Do NOT describe the guitar yourself - let the recommendGuitar tool do it
|
|
26
|
-
|
|
26
|
+
`
|
|
27
27
|
|
|
28
|
-
export const Route = createFileRoute(
|
|
28
|
+
export const Route = createFileRoute('/demo/api/tanchat')({
|
|
29
29
|
server: {
|
|
30
30
|
handlers: {
|
|
31
31
|
POST: async ({ request }) => {
|
|
32
32
|
// Capture request signal before reading body (it may be aborted after body is consumed)
|
|
33
|
-
const requestSignal = request.signal
|
|
33
|
+
const requestSignal = request.signal
|
|
34
34
|
|
|
35
35
|
// If request is already aborted, return early
|
|
36
36
|
if (requestSignal.aborted) {
|
|
37
|
-
return new Response(null, { status: 499 })
|
|
37
|
+
return new Response(null, { status: 499 }) // 499 = Client Closed Request
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const abortController = new AbortController()
|
|
40
|
+
const abortController = new AbortController()
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
|
-
const body = await request.json()
|
|
44
|
-
const { messages } = body
|
|
45
|
-
const data = body.data || {}
|
|
46
|
-
const provider: Provider = data.provider ||
|
|
47
|
-
const model: string = data.model ||
|
|
43
|
+
const body = await request.json()
|
|
44
|
+
const { messages } = body
|
|
45
|
+
const data = body.data || {}
|
|
46
|
+
const provider: Provider = data.provider || 'anthropic'
|
|
47
|
+
const model: string = data.model || 'claude-haiku-4-5'
|
|
48
48
|
|
|
49
49
|
// Adapter factory pattern for multi-vendor support
|
|
50
50
|
const adapterConfig = {
|
|
51
51
|
anthropic: () =>
|
|
52
|
-
anthropicText((model ||
|
|
53
|
-
openai: () => openaiText((model ||
|
|
54
|
-
gemini: () => geminiText((model ||
|
|
55
|
-
ollama: () => ollamaText((model ||
|
|
56
|
-
}
|
|
52
|
+
anthropicText((model || 'claude-haiku-4-5') as any),
|
|
53
|
+
openai: () => openaiText((model || 'gpt-4o') as any),
|
|
54
|
+
gemini: () => geminiText((model || 'gemini-2.0-flash-exp') as any),
|
|
55
|
+
ollama: () => ollamaText((model || 'mistral:7b') as any),
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
const adapter = adapterConfig[provider]()
|
|
58
|
+
const adapter = adapterConfig[provider]()
|
|
59
59
|
|
|
60
60
|
const stream = chat({
|
|
61
61
|
adapter,
|
|
@@ -67,23 +67,23 @@ export const Route = createFileRoute("/demo/api/tanchat")({
|
|
|
67
67
|
agentLoopStrategy: maxIterations(5),
|
|
68
68
|
messages,
|
|
69
69
|
abortController,
|
|
70
|
-
})
|
|
70
|
+
})
|
|
71
71
|
|
|
72
|
-
return
|
|
72
|
+
return toServerSentEventsResponse(stream, { abortController })
|
|
73
73
|
} catch (error: any) {
|
|
74
74
|
// If request was aborted, return early (don't send error response)
|
|
75
|
-
if (error.name ===
|
|
76
|
-
return new Response(null, { status: 499 })
|
|
75
|
+
if (error.name === 'AbortError' || abortController.signal.aborted) {
|
|
76
|
+
return new Response(null, { status: 499 }) // 499 = Client Closed Request
|
|
77
77
|
}
|
|
78
78
|
return new Response(
|
|
79
|
-
JSON.stringify({ error:
|
|
79
|
+
JSON.stringify({ error: 'Failed to process chat request' }),
|
|
80
80
|
{
|
|
81
81
|
status: 500,
|
|
82
|
-
headers: {
|
|
83
|
-
}
|
|
84
|
-
)
|
|
82
|
+
headers: { 'Content-Type': 'application/json' },
|
|
83
|
+
},
|
|
84
|
+
)
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
},
|
|
89
|
-
})
|
|
89
|
+
})
|
package/hosts/nitro/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/cta-framework-react-cra",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.2",
|
|
4
4
|
"description": "CTA Framework for React (Create React App)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"author": "Jack Herrington <jherr@pobox.com>",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tanstack/cta-engine": "0.44.
|
|
26
|
+
"@tanstack/cta-engine": "0.44.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.6.0",
|
|
@@ -105,6 +105,8 @@ import ReactDOM from "react-dom/client";
|
|
|
105
105
|
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
106
106
|
<% for(const integration of integrations.filter(i => i.type === 'root-provider')) { %>
|
|
107
107
|
import * as <%= integration.jsName %> from "<%= relativePath(integration.path) %>";
|
|
108
|
+
<% } %><% if (addOnEnabled.paraglide) { %>
|
|
109
|
+
import { deLocalizeUrl, localizeUrl } from "./paraglide/runtime";
|
|
108
110
|
<% } %>
|
|
109
111
|
|
|
110
112
|
// Import the generated route tree
|
|
@@ -122,7 +124,12 @@ const <%= integration.jsName %>Context = <%= integration.jsName %>.getContext();
|
|
|
122
124
|
<% for(const integration of integrations.filter(i => i.type === 'root-provider')) { %>
|
|
123
125
|
...<%= integration.jsName %>Context,
|
|
124
126
|
<% } %>
|
|
125
|
-
}
|
|
127
|
+
},<% if (addOnEnabled.paraglide) { %>
|
|
128
|
+
// Paraglide URL rewrite docs: https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#rewrite-url
|
|
129
|
+
rewrite: {
|
|
130
|
+
input: ({ url }) => deLocalizeUrl(url),
|
|
131
|
+
output: ({ url }) => localizeUrl(url),
|
|
132
|
+
},<% } %>
|
|
126
133
|
defaultPreload: "intent",
|
|
127
134
|
scrollRestoration: true,
|
|
128
135
|
defaultStructuralSharing: true,
|
|
@@ -156,4 +163,4 @@ if (rootElement && !rootElement.innerHTML) {
|
|
|
156
163
|
// If you want to start measuring performance in your app, pass a function
|
|
157
164
|
// to log results (for example: reportWebVitals(console.log))
|
|
158
165
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
159
|
-
reportWebVitals();<% } %>
|
|
166
|
+
reportWebVitals();<% } %>
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<% let hasContext = addOnEnabled["apollo-client"] || addOnEnabled["tanstack-query"]; %>
|
|
2
2
|
<% if (!fileRouter) { ignoreFile() } %>import { <% if (addOnEnabled.start) { %>
|
|
3
|
-
HeadContent<% } else { %>Outlet<% } %><% if (addOnEnabled.start) { %>, Scripts<% } %>, <% if (hasContext) { %>createRootRouteWithContext<% } else { %>createRootRoute<% } %> } from '@tanstack/react-router'
|
|
3
|
+
HeadContent<% } else { %>Outlet<% } %><% if (addOnEnabled.start) { %>, Scripts<% } %>, <% if (hasContext) { %>createRootRouteWithContext<% } else { %>createRootRoute<% } %><% if (addOnEnabled.paraglide) { %>, redirect<% } %> } from '@tanstack/react-router'
|
|
4
4
|
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools';
|
|
5
5
|
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
6
6
|
<% if (addOns.length) { %>
|
|
7
7
|
import Header from '../components/Header'
|
|
8
8
|
<% } %><% for(const integration of integrations.filter(i => i.type === 'layout' || i.type === 'provider' || i.type === 'devtools')) { %>
|
|
9
9
|
import <%= integration.jsName %> from '<%= relativePath(integration.path, true) %>'
|
|
10
|
+
<% } %><% if (addOnEnabled.paraglide) { %>
|
|
11
|
+
import { getLocale, shouldRedirect } from '@/paraglide/runtime'
|
|
10
12
|
<% } %>
|
|
11
13
|
<% if (addOnEnabled.start) { %>
|
|
12
14
|
import appCss from '../styles.css?url'
|
|
@@ -32,6 +34,25 @@ interface MyRouterContext <% if (addOnEnabled["apollo-client"]) {%> extends Apol
|
|
|
32
34
|
}<% } %>
|
|
33
35
|
|
|
34
36
|
export const Route = <% if (hasContext) { %>createRootRouteWithContext<MyRouterContext>()<% } else { %>createRootRoute<% } %>({
|
|
37
|
+
<% if (addOnEnabled.paraglide) { %>
|
|
38
|
+
beforeLoad: async () => {
|
|
39
|
+
// Other redirect strategies are possible; see
|
|
40
|
+
// https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#offline-redirect
|
|
41
|
+
if (typeof document !== 'undefined') {
|
|
42
|
+
document.documentElement.setAttribute('lang', getLocale())
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
<% if (!addOnEnabled.start) { %>// Client-side fallback redirect for SPA/file-router builds. Start apps should
|
|
46
|
+
// prefer server-side paraglideMiddleware (see start template server.ts).
|
|
47
|
+
if (typeof window !== 'undefined') {
|
|
48
|
+
const decision = await shouldRedirect({ url: window.location.href })
|
|
49
|
+
|
|
50
|
+
if (decision.redirectUrl) {
|
|
51
|
+
throw redirect({ href: decision.redirectUrl.href })
|
|
52
|
+
}
|
|
53
|
+
}<% } %>
|
|
54
|
+
},
|
|
55
|
+
<% } %>
|
|
35
56
|
<% if (addOnEnabled.start) { %>
|
|
36
57
|
head: () => ({
|
|
37
58
|
meta: [
|
|
@@ -84,7 +105,7 @@ export const Route = <% if (hasContext) { %>createRootRouteWithContext<MyRouterC
|
|
|
84
105
|
<% if (addOnEnabled.start) { %>
|
|
85
106
|
function RootDocument({ children }: { children: React.ReactNode }) {
|
|
86
107
|
return (
|
|
87
|
-
|
|
108
|
+
<% if (addOnEnabled.paraglide) { %><html lang={getLocale()}><% } else { %><html lang="en"><% } %>
|
|
88
109
|
<head>
|
|
89
110
|
<HeadContent />
|
|
90
111
|
</head>
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
/* Bundler mode */
|
|
12
12
|
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true
|
|
13
|
+
"allowImportingTsExtensions": true,<% if (addOnEnabled.paraglide) { %>
|
|
14
|
+
"allowJs": true,<% } %>
|
|
14
15
|
"verbatimModuleSyntax": <%= addOnEnabled['start'] ? 'false' : 'true' %>,
|
|
15
16
|
"noEmit": true,
|
|
16
17
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<% if (addOnEnabled.start) { ignoreFile() } %>import { defineConfig } from "vite";
|
|
2
|
-
import { devtools } from '@tanstack/devtools-vite'
|
|
2
|
+
import { devtools } from '@tanstack/devtools-vite'<% if (addOnEnabled.paraglide) { %>
|
|
3
|
+
import { paraglideVitePlugin } from "@inlang/paraglide-js"<% } %>
|
|
3
4
|
import viteReact from "@vitejs/plugin-react";<% if (tailwind) { %>
|
|
4
5
|
import tailwindcss from "@tailwindcss/vite";
|
|
5
6
|
<% } %><%if (fileRouter) { %>
|
|
@@ -11,7 +12,11 @@ import federationConfig from "./module-federation.config.js";<% } %><% for(const
|
|
|
11
12
|
|
|
12
13
|
// https://vitejs.dev/config/
|
|
13
14
|
export default defineConfig({
|
|
14
|
-
plugins: [devtools(), <%
|
|
15
|
+
plugins: [devtools(), <% if (addOnEnabled.paraglide) { %>paraglideVitePlugin({
|
|
16
|
+
project: './project.inlang',
|
|
17
|
+
outdir: './src/paraglide',
|
|
18
|
+
strategy: ['url'],
|
|
19
|
+
}), <% } %><% for(const integration of integrations.filter(i => i.type === 'vite-plugin')) { %><%- integrationImportCode(integration) %>,<% } %> <% if(fileRouter) { %>tanstackRouter({
|
|
15
20
|
target: "react",
|
|
16
21
|
autoCodeSplitting: true,
|
|
17
22
|
}), <% } %>viteReact(<% if (addOnEnabled.compiler) { %>{
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"/src/routes/demo/form.simple.jsx": "import { createFileRoute } from '@tanstack/react-router'\nimport { z } from 'zod'\n\nimport { useAppForm } from '@/hooks/demo.form'\n\nexport const Route = createFileRoute('/demo/form')({\n component: SimpleForm,\n})\n\nconst schema = z.object({\n title: z.string().min(1, 'Title is required'),\n description: z.string().min(1, 'Description is required'),\n})\n\nfunction SimpleForm() {\n const form = useAppForm({\n defaultValues: {\n title: '',\n description: '',\n },\n validators: {\n onBlur: schema,\n },\n onSubmit: ({ value }) => {\n console.log(value)\n // Show success message\n alert('Form submitted successfully!')\n },\n })\n\n return (\n <div\n className=\"flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white\"\n style={{\n backgroundImage:\n 'radial-gradient(50% 50% at 5% 40%, #add8e6 0%, #0000ff 70%, #00008b 100%)',\n }}\n >\n <div className=\"w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10\">\n <form\n onSubmit={(e) => {\n e.preventDefault()\n e.stopPropagation()\n form.handleSubmit()\n }}\n className=\"space-y-6\"\n >\n <form.AppField name=\"title\">\n {(field) => <field.TextField label=\"Title\" />}\n </form.AppField>\n\n <form.AppField name=\"description\">\n {(field) => <field.TextArea label=\"Description\" />}\n </form.AppField>\n\n <div className=\"flex justify-end\">\n <form.AppForm>\n <form.SubscribeButton label=\"Submit\" />\n </form.AppForm>\n </div>\n </form>\n </div>\n </div>\n )\n}\n",
|
|
18
18
|
"/src/routes/index.jsx": "import { createFileRoute } from '@tanstack/react-router'\nimport logo from '../logo.svg'\nimport '../App.css'\n\nexport const Route = createFileRoute('/')({\n component: App,\n})\n\nfunction App() {\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit <code>src/routes/index.tsx</code> and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n <a\n className=\"App-link\"\n href=\"https://tanstack.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn TanStack\n </a>\n </header>\n </div>\n )\n}\n",
|
|
19
19
|
"/src/styles.css": "\nbody {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n",
|
|
20
|
-
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run
|
|
20
|
+
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run dev\n```\n\n# Building For Production\n\nTo build this application for production:\n\n```bash\nnpm run build\n```\n\n## Testing\n\nThis project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:\n\n```bash\nnpm run test\n```\n\n## Styling\n\nThis project uses CSS for styling.\n\n\n\n\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.\n\n### Adding A Route\n\nTo add a new route to your application just add another a new file in the `./src/routes` directory.\n\nTanStack will automatically generate the content of the route file for you.\n\nNow that you have two routes you can use a `Link` component to navigate between them.\n\n### Adding Links\n\nTo use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n```\n\nThen anywhere in your JSX you can use it like so:\n\n```tsx\n<Link to=\"/about\">About</Link>\n```\n\nThis will create a link that will navigate to the `/about` route.\n\nMore information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).\n\n### Using A Layout\n\nIn the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.\n\nHere is an example layout that includes a header:\n\n```tsx\nimport { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport { Link } from \"@tanstack/react-router\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <header>\n <nav>\n <Link to=\"/\">Home</Link>\n <Link to=\"/about\">About</Link>\n </nav>\n </header>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n```\n\nThe `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.\n\nMore information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n## Data Fetching\n\nThere are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.\n\nFor example:\n\n```tsx\nconst peopleRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/people\",\n loader: async () => {\n const response = await fetch(\"https://swapi.dev/api/people\");\n return response.json();\n },\n component: () => {\n const data = peopleRoute.useLoaderData();\n return (\n <ul>\n {data.results.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n );\n },\n});\n```\n\nLoaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).\n\n### React-Query\n\nReact-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.\n\nFirst add your dependencies:\n\n```bash\nnpm install @tanstack/react-query @tanstack/react-query-devtools\n```\n\nNext we'll need to create a query client and provider. We recommend putting those in `main.jsx`.\n\n```tsx\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\n\n// ...\n\nconst queryClient = new QueryClient();\n\n// ...\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n\n root.render(\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n </QueryClientProvider>\n );\n}\n```\n\nYou can also add TanStack Query Devtools to the root route (optional).\n\n```tsx\nimport { ReactQueryDevtools } from \"@tanstack/react-query-devtools\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <ReactQueryDevtools buttonPosition=\"top-right\" />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNow you can use `useQuery` to fetch your data.\n\n```tsx\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport \"./App.css\";\n\nfunction App() {\n const { data } = useQuery({\n queryKey: [\"people\"],\n queryFn: () =>\n fetch(\"https://swapi.dev/api/people\")\n .then((res) => res.json())\n .then((data) => data.results),\n initialData: [],\n });\n\n return (\n <div>\n <ul>\n {data.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nexport default App;\n```\n\nYou can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).\n\n## State Management\n\nAnother common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.\n\nFirst you need to add TanStack Store as a dependency:\n\n```bash\nnpm install @tanstack/store\n```\n\nNow let's create a simple counter in the `src/App.jsx` file as a demonstration.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nfunction App() {\n const count = useStore(countStore);\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n </div>\n );\n}\n\nexport default App;\n```\n\nOne of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.\n\nLet's check this out by doubling the count using derived state.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store, Derived } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nconst doubledStore = new Derived({\n fn: () => countStore.state * 2,\n deps: [countStore],\n});\ndoubledStore.mount();\n\nfunction App() {\n const count = useStore(countStore);\n const doubledCount = useStore(doubledStore);\n\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n <div>Doubled - {doubledCount}</div>\n </div>\n );\n}\n\nexport default App;\n```\n\nWe use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.\n\nOnce we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.\n\nYou can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).\n\n# Demo files\n\nFiles prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.\n\n# Learn More\n\nYou can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).\n",
|
|
21
21
|
"index.html": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n <meta name=\"theme-color\" content=\"#000000\" />\n <meta\n name=\"description\"\n content=\"Web site created using create-tsrouter-app\"\n />\n <link rel=\"apple-touch-icon\" href=\"/logo192.png\" />\n <link rel=\"manifest\" href=\"/manifest.json\" />\n <title>Create TanStack App - TEST</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.jsx\"></script>\n </body>\n</html>\n",
|
|
22
22
|
"package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vite --port 3000\",\n \"build\": \"vite build && tsc\",\n \"preview\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tanstack/react-devtools\": \"^0.7.0\",\n \"@tanstack/react-form\": \"^1.0.0\",\n \"@tanstack/react-router\": \"^1.132.0\",\n \"@tanstack/react-router-devtools\": \"^1.132.0\",\n \"@tanstack/router-plugin\": \"^1.132.0\",\n \"react\": \"^19.2.0\",\n \"react-dom\": \"^19.2.0\",\n \"zod\": \"^4.1.11\"\n },\n \"devDependencies\": {\n \"@tanstack/devtools-vite\": \"^0.3.11\",\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.2.0\",\n \"@types/react-dom\": \"^19.2.0\",\n \"@vitejs/plugin-react\": \"^5.0.4\",\n \"jsdom\": \"^27.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^7.1.7\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^5.1.0\"\n }\n}",
|
|
23
23
|
"vite.config.js": "import { defineConfig } from 'vite'\nimport { devtools } from '@tanstack/devtools-vite'\nimport viteReact from '@vitejs/plugin-react'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { fileURLToPath, URL } from 'node:url'\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [\n devtools(),\n tanstackRouter({\n target: 'react',\n autoCodeSplitting: true,\n }),\n viteReact(),\n ],\n resolve: {\n alias: {\n '@': fileURLToPath(new URL('./src', import.meta.url)),\n },\n },\n})\n"
|