create-start-app 0.6.1 → 0.6.3

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.
@@ -1,11 +1,8 @@
1
1
  import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/solid-router'
2
-
3
2
  import { createForm } from '@tanstack/solid-form'
4
- import type { AnyFieldApi } from '@tanstack/solid-form'
5
3
 
6
- interface FieldInfoProps {
7
- field: AnyFieldApi
8
- }
4
+ import type { JSX } from 'solid-js/jsx-runtime'
5
+ import type { ValidationError } from '@tanstack/solid-form'
9
6
 
10
7
  <% if (codeRouter) { %>
11
8
  import type { RootRoute } from '@tanstack/react-router'
@@ -14,126 +11,333 @@ export const Route = createFileRoute('/demo/form')({
14
11
  component: FormExample,
15
12
  })
16
13
  <% } %>
17
- function FieldInfo(props: FieldInfoProps) {
14
+ function FieldWrapper(props: {
15
+ children: JSX.Element
16
+ errors: Array<ValidationError>
17
+ label: string
18
+ }) {
18
19
  return (
19
- <>
20
- {props.field.state.meta.isTouched &&
21
- props.field.state.meta.errors.length ? (
22
- <em>{props.field.state.meta.errors.join(',')}</em>
20
+ <div>
21
+ <label for={props.label} class="block font-bold mb-1 text-xl">
22
+ {props.label}
23
+ </label>
24
+ {props.children}
25
+ {props.errors.length ? (
26
+ <div class="text-red-500 mt-1 font-bold">{props.errors.join(', ')}</div>
23
27
  ) : null}
24
- {props.field.state.meta.isValidating ? 'Validating...' : null}
25
- </>
28
+ </div>
26
29
  )
27
30
  }
28
31
 
29
32
  function FormExample() {
30
33
  const form = createForm(() => ({
31
34
  defaultValues: {
32
- firstName: '',
33
- lastName: '',
35
+ fullName: '',
36
+ email: '',
37
+ address: {
38
+ street: '',
39
+ city: '',
40
+ state: '',
41
+ zipCode: '',
42
+ country: '',
43
+ },
44
+ phone: '',
34
45
  },
35
- onSubmit: async ({ value }) => {
36
- // Do something with form data
46
+ onSubmit: ({ value }) => {
37
47
  console.log(value)
48
+ // Show success message
49
+ alert('Form submitted successfully!')
38
50
  },
39
51
  }))
40
52
 
41
53
  return (
42
- <div class="max-w-md mx-auto mt-10 p-6 bg-white rounded-lg shadow-md">
43
- <h1 class="text-2xl font-bold mb-8 text-gray-800 leading-tight">
44
- Simple Form Example
45
- </h1>
46
- <form
47
- class="space-y-6"
48
- onSubmit={(e) => {
49
- e.preventDefault()
50
- e.stopPropagation()
51
- form.handleSubmit()
52
- }}
53
- >
54
- <div class="space-y-1">
55
- <form.Field
56
- name="firstName"
57
- validators={{
58
- onChange: ({ value }) =>
59
- !value
60
- ? 'A first name is required'
61
- : value.length < 3
62
- ? 'First name must be at least 3 characters'
63
- : undefined,
64
- onChangeAsyncDebounceMs: 500,
65
- onChangeAsync: async ({ value }) => {
66
- await new Promise((resolve) => setTimeout(resolve, 1000))
67
- return (
68
- value.includes('error') && 'No "error" allowed in first name'
69
- )
70
- },
71
- }}
72
- children={(field) => {
73
- return (
74
- <>
75
- <label
76
- for={field().name}
77
- class="block text-sm font-medium text-gray-700 mb-1 leading-tight"
78
- >
79
- First Name:
80
- </label>
54
+ <div
55
+ class="flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white"
56
+ style={{
57
+ 'background-image':
58
+ 'radial-gradient(50% 50% at 5% 40%, #f4a460 0%, #8b4513 70%, #1a0f0a 100%)',
59
+ }}
60
+ >
61
+ <div class="w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10">
62
+ <form
63
+ onSubmit={(e) => {
64
+ e.preventDefault()
65
+ e.stopPropagation()
66
+ form.handleSubmit()
67
+ }}
68
+ class="space-y-6"
69
+ >
70
+ {/* Full Name Field */}
71
+ <div>
72
+ <form.Field
73
+ name="fullName"
74
+ validators={{
75
+ onBlur: ({ value }) => {
76
+ if (value.trim().length === 0) {
77
+ return 'Full name is required'
78
+ }
79
+ if (value.length < 3) {
80
+ return 'Name must be at least 3 characters'
81
+ }
82
+ return undefined
83
+ },
84
+ }}
85
+ children={(field) => (
86
+ <FieldWrapper
87
+ label="Full Name"
88
+ errors={field().state.meta.errors}
89
+ >
81
90
  <input
82
- id={field().name}
83
- name={field().name}
91
+ id="fullName"
92
+ name="fullName"
84
93
  value={field().state.value}
85
94
  onBlur={field().handleBlur}
86
- onInput={(e) => field().handleChange(e.target.value)}
87
- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm leading-relaxed p-2"
95
+ onChange={(e) => field().handleChange(e.target.value)}
96
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
88
97
  />
89
- <FieldInfo field={field()} />
90
- </>
91
- )
92
- }}
93
- />
94
- </div>
95
- <div class="space-y-1">
96
- <form.Field
97
- name="lastName"
98
- children={(field) => (
99
- <>
100
- <label
101
- for={field().name}
102
- class="block text-sm font-medium text-gray-700 mb-1 leading-tight"
98
+ </FieldWrapper>
99
+ )}
100
+ />
101
+ </div>
102
+
103
+ {/* Email Field */}
104
+ <div>
105
+ <form.Field
106
+ name="email"
107
+ validators={{
108
+ onBlur: ({ value }) => {
109
+ if (!value || value.trim().length === 0) {
110
+ return 'Email is required'
111
+ }
112
+ if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)) {
113
+ return 'Invalid email address'
114
+ }
115
+ return undefined
116
+ },
117
+ }}
118
+ children={(field) => (
119
+ <FieldWrapper
120
+ label="Email Address"
121
+ errors={field().state.meta.errors}
103
122
  >
104
- Last Name:
105
- </label>
106
- <input
107
- id={field().name}
108
- name={field().name}
109
- value={field().state.value}
110
- onBlur={field().handleBlur}
111
- onInput={(e) => field().handleChange(e.target.value)}
112
- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm leading-relaxed p-2"
113
- />
114
- <FieldInfo field={field()} />
115
- </>
116
- )}
117
- />
118
- </div>
119
- <form.Subscribe
120
- selector={(state) => ({
121
- canSubmit: state.canSubmit,
122
- isSubmitting: state.isSubmitting,
123
- })}
124
- children={(state) => {
125
- return (
126
- <button
127
- type="submit"
128
- disabled={!state().canSubmit}
129
- class="w-full flex justify-center py-2.5 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed leading-tight"
130
- >
131
- {state().isSubmitting ? '...' : 'Submit'}
132
- </button>
133
- )
134
- }}
135
- />
136
- </form>
123
+ <input
124
+ id="email"
125
+ name="email"
126
+ type="email"
127
+ value={field().state.value}
128
+ onBlur={field().handleBlur}
129
+ onChange={(e) => field().handleChange(e.target.value)}
130
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
131
+ />
132
+ </FieldWrapper>
133
+ )}
134
+ />
135
+ </div>
136
+
137
+ {/* Street Address */}
138
+ <div>
139
+ <form.Field
140
+ name="address.street"
141
+ validators={{
142
+ onBlur: ({ value }) => {
143
+ if (!value || value.trim().length === 0) {
144
+ return 'Street address is required'
145
+ }
146
+ return undefined
147
+ },
148
+ }}
149
+ children={(field) => (
150
+ <FieldWrapper
151
+ label="Street Address"
152
+ errors={field().state.meta.errors}
153
+ >
154
+ <input
155
+ id="street"
156
+ name="street"
157
+ value={field().state.value}
158
+ onBlur={field().handleBlur}
159
+ onChange={(e) => field().handleChange(e.target.value)}
160
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
161
+ />
162
+ </FieldWrapper>
163
+ )}
164
+ />
165
+ </div>
166
+
167
+ {/* City, State, Zip in a row */}
168
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
169
+ {/* City */}
170
+ <form.Field
171
+ name="address.city"
172
+ validators={{
173
+ onBlur: ({ value }) => {
174
+ if (!value || value.trim().length === 0) {
175
+ return 'City is required'
176
+ }
177
+ return undefined
178
+ },
179
+ }}
180
+ children={(field) => (
181
+ <FieldWrapper label="City" errors={field().state.meta.errors}>
182
+ <input
183
+ id="city"
184
+ name="city"
185
+ value={field().state.value}
186
+ onBlur={field().handleBlur}
187
+ onChange={(e) => field().handleChange(e.target.value)}
188
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
189
+ />
190
+ </FieldWrapper>
191
+ )}
192
+ />
193
+
194
+ {/* State */}
195
+ <form.Field
196
+ name="address.state"
197
+ validators={{
198
+ onBlur: ({ value }) => {
199
+ if (!value || value.trim().length === 0) {
200
+ return 'State is required'
201
+ }
202
+ return undefined
203
+ },
204
+ }}
205
+ children={(field) => (
206
+ <FieldWrapper label="State" errors={field().state.meta.errors}>
207
+ <input
208
+ id="state"
209
+ name="state"
210
+ value={field().state.value}
211
+ onBlur={field().handleBlur}
212
+ onChange={(e) => field().handleChange(e.target.value)}
213
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
214
+ />
215
+ </FieldWrapper>
216
+ )}
217
+ />
218
+
219
+ {/* Zip Code */}
220
+ <form.Field
221
+ name="address.zipCode"
222
+ validators={{
223
+ onBlur: ({ value }) => {
224
+ if (!value || value.trim().length === 0) {
225
+ return 'Zip code is required'
226
+ }
227
+ if (!/^\d{5}(-\d{4})?$/.test(value)) {
228
+ return 'Invalid zip code format'
229
+ }
230
+ return undefined
231
+ },
232
+ }}
233
+ children={(field) => (
234
+ <FieldWrapper
235
+ label="Zip Code"
236
+ errors={field().state.meta.errors}
237
+ >
238
+ <input
239
+ id="zipCode"
240
+ name="zipCode"
241
+ value={field().state.value}
242
+ onBlur={field().handleBlur}
243
+ onChange={(e) => field().handleChange(e.target.value)}
244
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
245
+ />
246
+ </FieldWrapper>
247
+ )}
248
+ />
249
+ </div>
250
+
251
+ {/* Country */}
252
+ <div>
253
+ <form.Field
254
+ name="address.country"
255
+ validators={{
256
+ onBlur: ({ value }) => {
257
+ if (!value || value.trim().length === 0) {
258
+ return 'Country is required'
259
+ }
260
+ return undefined
261
+ },
262
+ }}
263
+ children={(field) => (
264
+ <FieldWrapper
265
+ label="Country"
266
+ errors={field().state.meta.errors}
267
+ >
268
+ <select
269
+ id="country"
270
+ name="country"
271
+ value={field().state.value}
272
+ onBlur={field().handleBlur}
273
+ onChange={(e) => field().handleChange(e.target.value)}
274
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
275
+ >
276
+ <option value="">Select a country</option>
277
+ <option value="US">United States</option>
278
+ <option value="CA">Canada</option>
279
+ <option value="UK">United Kingdom</option>
280
+ <option value="AU">Australia</option>
281
+ <option value="DE">Germany</option>
282
+ <option value="FR">France</option>
283
+ <option value="JP">Japan</option>
284
+ </select>
285
+ </FieldWrapper>
286
+ )}
287
+ />
288
+ </div>
289
+
290
+ {/* Phone Number */}
291
+ <div>
292
+ <form.Field
293
+ name="phone"
294
+ validators={{
295
+ onBlur: ({ value }) => {
296
+ if (!value || value.trim().length === 0) {
297
+ return 'Phone number is required'
298
+ }
299
+ if (
300
+ !/^(\+\d{1,3})?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/.test(
301
+ value,
302
+ )
303
+ ) {
304
+ return 'Invalid phone number format'
305
+ }
306
+ return undefined
307
+ },
308
+ }}
309
+ children={(field) => (
310
+ <FieldWrapper
311
+ label="Phone Number"
312
+ errors={field().state.meta.errors}
313
+ >
314
+ <input
315
+ id="phone"
316
+ name="phone"
317
+ type="tel"
318
+ value={field().state.value}
319
+ onBlur={field().handleBlur}
320
+ onChange={(e) => field().handleChange(e.target.value)}
321
+ class="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
322
+ placeholder="(123) 456-7890"
323
+ />
324
+ </FieldWrapper>
325
+ )}
326
+ />
327
+ </div>
328
+
329
+ {/* Submit Button */}
330
+ <div class="flex justify-end">
331
+ <button
332
+ type="submit"
333
+ disabled={form.state.isSubmitting}
334
+ class="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"
335
+ >
336
+ {form.state.isSubmitting ? 'Submitting...' : 'Submit'}
337
+ </button>
338
+ </div>
339
+ </form>
340
+ </div>
137
341
  </div>
138
342
  )
139
343
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@tanstack/solid-form": "^0.43.2"
3
+ "@tanstack/solid-form": "^1.0.0"
4
4
  }
5
5
  }
@@ -0,0 +1,112 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import { createApp } from '../src/create-app.js'
4
+ import { createTestEnvironment } from './test-utilities.js'
5
+
6
+ test('code router in javascript on npm', async () => {
7
+ const projectName = 'TEST'
8
+ const { environment, output } = createTestEnvironment(projectName)
9
+ await createApp(
10
+ {
11
+ addOns: false,
12
+ framework: 'react',
13
+ chosenAddOns: [],
14
+ git: true,
15
+ mode: 'code-router',
16
+ packageManager: 'npm',
17
+ projectName,
18
+ tailwind: false,
19
+ toolchain: 'none',
20
+ typescript: false,
21
+ variableValues: {},
22
+ },
23
+ {
24
+ silent: true,
25
+ environment,
26
+ },
27
+ )
28
+ await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
29
+ './snapshots/cra/cr-js-npm.json',
30
+ )
31
+ })
32
+
33
+ test('code router in typescript on npm', async () => {
34
+ const projectName = 'TEST'
35
+ const { environment, output } = createTestEnvironment(projectName)
36
+ await createApp(
37
+ {
38
+ addOns: false,
39
+ framework: 'react',
40
+ chosenAddOns: [],
41
+ git: true,
42
+ mode: 'code-router',
43
+ packageManager: 'npm',
44
+ projectName,
45
+ tailwind: false,
46
+ toolchain: 'none',
47
+ typescript: true,
48
+ variableValues: {},
49
+ },
50
+ {
51
+ silent: true,
52
+ environment,
53
+ },
54
+ )
55
+ await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
56
+ './snapshots/cra/cr-ts-npm.json',
57
+ )
58
+ })
59
+
60
+ test('file router on npm', async () => {
61
+ const projectName = 'TEST'
62
+ const { environment, output } = createTestEnvironment(projectName)
63
+ await createApp(
64
+ {
65
+ addOns: false,
66
+ framework: 'react',
67
+ chosenAddOns: [],
68
+ git: true,
69
+ mode: 'file-router',
70
+ packageManager: 'npm',
71
+ projectName,
72
+ tailwind: false,
73
+ toolchain: 'none',
74
+ typescript: true,
75
+ variableValues: {},
76
+ },
77
+ {
78
+ silent: true,
79
+ environment,
80
+ },
81
+ )
82
+ await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
83
+ './snapshots/cra/fr-ts-npm.json',
84
+ )
85
+ })
86
+
87
+ test('file router with tailwind on npm', async () => {
88
+ const projectName = 'TEST'
89
+ const { environment, output } = createTestEnvironment(projectName)
90
+ await createApp(
91
+ {
92
+ addOns: false,
93
+ framework: 'react',
94
+ chosenAddOns: [],
95
+ git: true,
96
+ mode: 'file-router',
97
+ packageManager: 'npm',
98
+ projectName,
99
+ tailwind: true,
100
+ toolchain: 'none',
101
+ typescript: true,
102
+ variableValues: {},
103
+ },
104
+ {
105
+ silent: true,
106
+ environment,
107
+ },
108
+ )
109
+ await expect(JSON.stringify(output, null, 2)).toMatchFileSnapshot(
110
+ './snapshots/cra/fr-ts-tw-npm.json',
111
+ )
112
+ })
@@ -0,0 +1,34 @@
1
+ {
2
+ "files": {
3
+ "/.vscode/settings.json": "{\n \"files.watcherExclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"search.exclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"files.readonlyInclude\": {\n \"**/routeTree.gen.ts\": true\n }\n}\n",
4
+ "/public/robots.txt": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n",
5
+ "/src/App.css": ".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
6
+ "/public/manifest.json": "{\n \"short_name\": \"TanStack App\",\n \"name\": \"Create TanStack App Sample\",\n \"icons\": [\n {\n \"src\": \"favicon.ico\",\n \"sizes\": \"64x64 32x32 24x24 16x16\",\n \"type\": \"image/x-icon\"\n },\n {\n \"src\": \"logo192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"logo512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ],\n \"start_url\": \".\",\n \"display\": \"standalone\",\n \"theme_color\": \"#000000\",\n \"background_color\": \"#ffffff\"\n}\n",
7
+ "/Users/jherr/projects/cta/create-tsrouter-app/vite.config.js": "import { defineConfig } from \"vite\";\nimport viteReact from \"@vitejs/plugin-react\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [viteReact()],\n test: {\n globals: true,\n environment: \"jsdom\",\n },\n\n});\n",
8
+ "/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",
9
+ "/src/reportWebVitals.js": " \nconst reportWebVitals = onPerfEntry => {\n if (onPerfEntry && onPerfEntry instanceof Function) {\n import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {\n onCLS(onPerfEntry);\n onINP(onPerfEntry);\n onFCP(onPerfEntry);\n onLCP(onPerfEntry);\n onTTFB(onPerfEntry);\n });\n }\n};\n\nexport default reportWebVitals;\n",
10
+ "/Users/jherr/projects/cta/create-tsrouter-app/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",
11
+ "/Users/jherr/projects/cta/create-tsrouter-app/package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"vite --port 3000\",\n \"build\": \"vite build && tsc\",\n \"serve\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tanstack/react-router\": \"^1.112.0\",\n \"@tanstack/router-devtools\": \"^1.112.0\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\"\n },\n \"devDependencies\": {\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.0.8\",\n \"@types/react-dom\": \"^19.0.3\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^26.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.1.0\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^4.2.4\"\n }\n}",
12
+ "/src/main.jsx": "import { StrictMode } from \"react\";\nimport ReactDOM from \"react-dom/client\";\nimport {\n Outlet,\n RouterProvider,\n createRootRoute,\n createRoute,\n createRouter,\n} from \"@tanstack/react-router\";\nimport { TanStackRouterDevtools } from \"@tanstack/router-devtools\";\n\n\nimport \"./styles.css\";\nimport reportWebVitals from \"./reportWebVitals.js\";\n\nimport App from \"./App.jsx\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n \n \n <Outlet />\n <TanStackRouterDevtools />\n \n \n </>\n ),\n});\n\nconst indexRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/\",\n component: App,\n});\n\nconst routeTree = rootRoute.addChildren([indexRoute]);\n\nconst router = createRouter({\n routeTree,\n defaultPreload: \"intent\",\n scrollRestoration: true,\n defaultStructuralSharing: true,\n});\n\nconst rootElement = document.getElementById(\"app\");\nif (rootElement && !rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n root.render(\n <StrictMode>\n <RouterProvider router={router} />\n </StrictMode>\n );\n}\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n",
13
+ "/src/App.jsx": "import logo from \"./logo.svg\";\nimport \"./App.css\";\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/App.jsx</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\n\nexport default App;\n\n",
14
+ "/src/App.test.jsx": "import { describe, expect, test } from \"vitest\";\nimport { render, screen } from \"@testing-library/react\";\nimport App from \"./App.jsx\";\n\ndescribe(\"App\", () => {\n test(\"renders\", () => {\n render(<App />);\n expect(screen.getByText(\"Learn React\")).toBeDefined();\n });\n});\n",
15
+ "/Users/jherr/projects/cta/create-tsrouter-app/.gitignore": "node_modules\n.DS_Store\ndist\ndist-ssr\n*.local\n",
16
+ "/Users/jherr/projects/cta/create-tsrouter-app/README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm start\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\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a code based router. Which means that the routes are defined in code (in the `./src/main.jsx` file). If you like you can also use a file based routing setup by following the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) guide.\n\n### Adding A Route\n\nTo add a new route to your application just add another `createRoute` call to the `./src/main.jsx` file. The example below adds a new `/about`route to the root route.\n\n```tsx\nconst aboutRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/about\",\n component: () => <h1>About</h1>,\n});\n```\n\nYou will also need to add the route to the `routeTree` in the `./src/main.jsx` file.\n\n```tsx\nconst routeTree = rootRoute.addChildren([indexRoute, aboutRoute]);\n```\n\nWith this set up you should be able to navigate to `/about` and see the about page.\n\nOf course you don't need to implement the About page in the `main.jsx` file. You can create that component in another file and import it into the `main.jsx` file, then use it in the `component` property of the `createRoute` call, like so:\n\n```tsx\nimport About from \"./components/About.jsx\";\n\nconst aboutRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/about\",\n component: About,\n});\n```\n\nThat is how we have the `App` component set up with the home page.\n\nFor more information on the options you have when you are creating code based routes check out the [Code Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing) documentation.\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\n\nLayouts can be used to wrap the contents of the routes in menus, headers, footers, etc.\n\nThere is already a layout in the `src/main.jsx` file:\n\n```tsx\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nYou can use the React component specified in the `component` property of the `rootRoute` to wrap the contents of the routes. The `<Outlet />` component is used to render the current route within the body of the layout. For example you could add a header to the layout like so:\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n\nconst rootRoute = 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](hthttps://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n### Migrating To File Base Routing\n\nFirst you need to add the Vite plugin for Tanstack Router:\n\n```bash\nnpm install -D @tanstack/router-plugin\n```\n\nFrom there you need to update your `vite.config.js` file to use the plugin:\n\n```ts\nimport { defineConfig } from \"vite\";\nimport viteReact from \"@vitejs/plugin-react\";\nimport { TanStackRouterVite } from \"@tanstack/router-plugin/vite\";\n \n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [\n TanStackRouterVite(),\n viteReact()\n ],\n});\n```\n\nNow you'll need to rearrange your files a little bit. That starts with creating a `routes` directory in the `src` directory:\n\n```bash\nmkdir src/routes\n```\n\nThen you'll need to create a `src/routes/__root.jsx` file with the contents of the root route that was in `main.jsx`.\n\n```tsx\nimport { createRootRoute, Outlet } from \"@tanstack/react-router\";\nimport { TanStackRouterDevtools } from \"@tanstack/router-devtools\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNext up you'll need to move your home route code into `src/routes/index.jsx`\n\n```tsx\nimport { createFileRoute } from \"@tanstack/react-router\";\n\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/App.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```\n\nAt this point you can delete `src/App.jsx`, you will no longer need it as the contents have moved into `src/routes/index.jsx`.\n\nThe only additional code is the `createFileRoute` function that tells TanStack Router where to render the route. Helpfully the Vite plugin will keep the path argument that goes to `createFileRoute` automatically in sync with the file system.\n\nFinally the `src/main.jsx` file can be simplified down to this:\n\n```tsx\nimport { StrictMode } from \"react\";\nimport ReactDOM from \"react-dom/client\";\nimport { RouterProvider, createRouter } from \"@tanstack/react-router\";\n\n// Import the generated route tree\nimport { routeTree } from \"./routeTree.gen\";\n\nimport \"./styles.css\";\nimport reportWebVitals from \"./reportWebVitals.js\";\n\n// Create a new router instance\nconst router = createRouter({ routeTree, defaultPreload: \"intent\", scrollRestoration: true, defaultStructuralSharing: true });\n\n// Render the app\nconst rootElement = document.getElementById(\"app\");\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n root.render(\n <StrictMode>\n <RouterProvider router={router} />\n </StrictMode>\n );\n}\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n```\n\nNow you've got a file based routing setup in your project! Let's have some fun with it! Just create a file in `about.jsx` in `src/routes` and it if the application is running TanStack will automatically add contents to the file and you'll have the start of your `/about` route ready to go with no additional work. You can see why folks find File Based Routing so easy to use.\n\nYou can find out everything you need to know on how to use file based routing in the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) documentation.\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 creata 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"
17
+ },
18
+ "commands": [
19
+ {
20
+ "command": "npm",
21
+ "args": [
22
+ "install"
23
+ ],
24
+ "cwd": "/Users/jherr/projects/cta/create-tsrouter-app/TEST"
25
+ },
26
+ {
27
+ "command": "git",
28
+ "args": [
29
+ "init"
30
+ ],
31
+ "cwd": "/Users/jherr/projects/cta/create-tsrouter-app/TEST"
32
+ }
33
+ ]
34
+ }