@soroush.design/cli 0.2.0-alpha.4 → 0.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/bin.mjs +2 -15
  2. package/dist/index.mjs +1 -1
  3. package/dist/{io-C_8_JerZ.mjs → io-CqI2BTaP.mjs} +81 -12
  4. package/package.json +3 -2
  5. package/templates/react-router/js/base/README.md +67 -0
  6. package/templates/react-router/js/base/_gitignore +4 -0
  7. package/templates/{vike/js/spa/src/pages/+onRenderHtml.jsx → react-router/js/base/index.html} +3 -7
  8. package/templates/react-router/js/base/src/components/RouterLink.jsx +12 -0
  9. package/templates/react-router/js/base/src/data/api.js +76 -0
  10. package/templates/react-router/js/base/src/main.jsx +38 -0
  11. package/templates/react-router/js/base/src/pages/ErrorPage.jsx +14 -0
  12. package/templates/react-router/js/base/src/pages/Layout.jsx +141 -0
  13. package/templates/react-router/js/base/src/pages/index/Counter.jsx +18 -0
  14. package/templates/react-router/js/base/src/pages/index/Greeting.jsx +48 -0
  15. package/templates/react-router/js/base/src/pages/index/Page.jsx +29 -0
  16. package/templates/react-router/js/base/src/pages/index/Page.test.jsx +61 -0
  17. package/templates/react-router/js/base/src/routes.jsx +46 -0
  18. package/templates/react-router/js/base/vite.config.js +13 -0
  19. package/templates/react-router/js/base/vitest.config.js +13 -0
  20. package/templates/react-router/js/sample-data/src/data/items.js +55 -0
  21. package/templates/react-router/js/sample-data/src/pages/item/Page.jsx +49 -0
  22. package/templates/react-router/js/sample-data/src/pages/item/loader.js +14 -0
  23. package/templates/react-router/js/sample-data/src/pages/items/Page.jsx +48 -0
  24. package/templates/react-router/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  25. package/templates/react-router/js/sample-data/src/pages/items/loader.js +11 -0
  26. package/templates/react-router/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  27. package/templates/react-router/js/with/jotai/src/state/counter.js +4 -0
  28. package/templates/react-router/js/with/jotai/src/state/scheme.js +4 -0
  29. package/templates/react-router/js/with/msw/_env +3 -0
  30. package/templates/react-router/js/with/msw/src/mocks/browser.js +5 -0
  31. package/templates/react-router/js/with/msw/src/mocks/handlers.js +24 -0
  32. package/templates/react-router/js/with/msw/src/mocks/server.js +5 -0
  33. package/templates/react-router/js/with/msw/src/mocks/setupTests.js +7 -0
  34. package/templates/react-router/js/with/msw/src/mocks/start.js +10 -0
  35. package/templates/react-router/js/with/react-hook-form/src/pages/form/Page.jsx +294 -0
  36. package/templates/react-router/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  37. package/templates/react-router/js/with/redux-toolkit/src/state/store.js +27 -0
  38. package/templates/react-router/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  39. package/templates/react-router/js/with/zustand/src/state/counter.js +14 -0
  40. package/templates/react-router/js/with/zustand/src/state/scheme.js +14 -0
  41. package/templates/react-router/ts/base/README.md +67 -0
  42. package/templates/react-router/ts/base/_gitignore +4 -0
  43. package/templates/react-router/ts/base/index.html +12 -0
  44. package/templates/react-router/ts/base/src/components/RouterLink.tsx +12 -0
  45. package/templates/react-router/ts/base/src/data/api.ts +84 -0
  46. package/templates/react-router/ts/base/src/main.tsx +38 -0
  47. package/templates/react-router/ts/base/src/pages/ErrorPage.tsx +14 -0
  48. package/templates/react-router/ts/base/src/pages/Layout.tsx +141 -0
  49. package/templates/react-router/ts/base/src/pages/index/Counter.tsx +18 -0
  50. package/templates/react-router/ts/base/src/pages/index/Greeting.tsx +49 -0
  51. package/templates/react-router/ts/base/src/pages/index/Page.test.tsx +61 -0
  52. package/templates/react-router/ts/base/src/pages/index/Page.tsx +29 -0
  53. package/templates/react-router/ts/base/src/routes.tsx +47 -0
  54. package/templates/react-router/ts/base/tsconfig.json +18 -0
  55. package/templates/react-router/ts/base/vite.config.ts +13 -0
  56. package/templates/react-router/ts/base/vitest.config.ts +13 -0
  57. package/templates/react-router/ts/sample-data/src/data/items.ts +61 -0
  58. package/templates/react-router/ts/sample-data/src/pages/item/Page.tsx +50 -0
  59. package/templates/react-router/ts/sample-data/src/pages/item/loader.ts +14 -0
  60. package/templates/react-router/ts/sample-data/src/pages/items/Page.tsx +49 -0
  61. package/templates/react-router/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  62. package/templates/react-router/ts/sample-data/src/pages/items/loader.ts +11 -0
  63. package/templates/react-router/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  64. package/templates/react-router/ts/with/jotai/src/state/counter.ts +4 -0
  65. package/templates/react-router/ts/with/jotai/src/state/scheme.ts +4 -0
  66. package/templates/react-router/ts/with/msw/_env +3 -0
  67. package/templates/react-router/ts/with/msw/src/mocks/browser.ts +5 -0
  68. package/templates/react-router/ts/with/msw/src/mocks/handlers.ts +24 -0
  69. package/templates/react-router/ts/with/msw/src/mocks/server.ts +5 -0
  70. package/templates/react-router/ts/with/msw/src/mocks/setupTests.ts +7 -0
  71. package/templates/react-router/ts/with/msw/src/mocks/start.ts +10 -0
  72. package/templates/react-router/ts/with/react-hook-form/src/pages/form/Page.tsx +298 -0
  73. package/templates/react-router/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  74. package/templates/react-router/ts/with/redux-toolkit/src/state/store.ts +29 -0
  75. package/templates/react-router/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  76. package/templates/react-router/ts/with/zustand/src/state/counter.ts +19 -0
  77. package/templates/react-router/ts/with/zustand/src/state/scheme.ts +19 -0
  78. package/templates/templates.md +2 -1
  79. package/templates/vike/js/base/README.md +0 -4
  80. package/templates/vike/ts/base/README.md +0 -4
  81. package/templates/vike/js/spa/src/pages/+config.js +0 -12
  82. package/templates/vike/js/spa/src/pages/+onRenderClient.jsx +0 -25
  83. package/templates/vike/ts/spa/src/pages/+config.ts +0 -14
  84. package/templates/vike/ts/spa/src/pages/+onRenderClient.tsx +0 -27
  85. package/templates/vike/ts/spa/src/pages/+onRenderHtml.tsx +0 -17
  86. /package/templates/{vike/js/spa/src/pages/about/+Page.jsx → react-router/js/base/src/pages/about/Page.jsx} +0 -0
  87. /package/templates/{vike/ts/spa/src/pages/about/+Page.tsx → react-router/ts/base/src/pages/about/Page.tsx} +0 -0
@@ -0,0 +1,5 @@
1
+ import { setupServer } from 'msw/node'
2
+ import { handlers } from './handlers'
3
+
4
+ /** The mock API in Node, for the tests: it answers the requests the handlers match. */
5
+ export const server = setupServer(...handlers)
@@ -0,0 +1,7 @@
1
+ import { afterAll, afterEach, beforeAll } from 'vitest'
2
+ import { server } from './server'
3
+
4
+ // The mock API answers every request a test makes; one it has no handler for fails the test.
5
+ beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
6
+ afterEach(() => server.resetHandlers())
7
+ afterAll(() => server.close())
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Starts the mock API in the browser while VITE_MSW, in .env, is true. Set it to false once the
3
+ * app's own API answers.
4
+ */
5
+ export async function startMocks() {
6
+ if (import.meta.env.VITE_MSW !== 'true') return
7
+ const { worker } = await import('./browser')
8
+ // A request the mock API has no handler for - a module, an image - goes to the network.
9
+ await worker.start({ onUnhandledFrame: 'bypass' })
10
+ }
@@ -0,0 +1,298 @@
1
+ // @if !tanstack-query && !swr
2
+ import { useState } from 'react'
3
+ // @endif
4
+ import { zodResolver } from '@hookform/resolvers/zod'
5
+ // @if tanstack-query
6
+ import { useMutation } from '@tanstack/react-query'
7
+ // @endif
8
+ import { Controller, useForm } from 'react-hook-form'
9
+ // @if swr
10
+ import useSWRMutation from 'swr/mutation'
11
+ // @endif
12
+ import { z } from 'zod'
13
+ import { Button } from '@soroush.tech/design-system/Button'
14
+ import { Flex } from '@soroush.tech/design-system/Flex'
15
+ import { TextInput } from '@soroush.tech/design-system/TextInput'
16
+ import { Typography } from '@soroush.tech/design-system/Typography'
17
+ // @if tanstack-query || swr || msw
18
+ import { sendMessage } from '../../data/api'
19
+ // @endif
20
+
21
+ /** What the form takes, and what it says when a value will not do. */
22
+ const schema = z.object({
23
+ name: z.string().trim().min(1, 'Your name, please.'),
24
+ email: z.email('An email address, please.'),
25
+ })
26
+
27
+ type Values = z.infer<typeof schema>
28
+
29
+ // @if tanstack-query
30
+ /** A form whose values a Zod schema checks; once they pass, it sends them with a mutation of TanStack Query. */
31
+ export default function Page() {
32
+ const mutation = useMutation({ mutationFn: sendMessage })
33
+ const { control, handleSubmit } = useForm<Values>({
34
+ resolver: zodResolver(schema),
35
+ defaultValues: { name: '', email: '' },
36
+ })
37
+ return (
38
+ <Flex gap={2} alignItems="flex-start">
39
+ <Typography variant="h2">Form</Typography>
40
+ <Typography color="secondary">
41
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
42
+ </Typography>
43
+ <form noValidate onSubmit={handleSubmit((values) => mutation.mutate(values))}>
44
+ <Flex gap={2} alignItems="flex-start">
45
+ <Controller
46
+ name="name"
47
+ control={control}
48
+ render={({ field, fieldState }) => (
49
+ <Flex gap={1}>
50
+ <TextInput
51
+ name={field.name}
52
+ value={field.value}
53
+ onChange={field.onChange}
54
+ placeholder="Name"
55
+ error={fieldState.invalid}
56
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
57
+ />
58
+ <Typography variant="caption" color="error">
59
+ {fieldState.error?.message}
60
+ </Typography>
61
+ </Flex>
62
+ )}
63
+ />
64
+ <Controller
65
+ name="email"
66
+ control={control}
67
+ render={({ field, fieldState }) => (
68
+ <Flex gap={1}>
69
+ <TextInput
70
+ name={field.name}
71
+ value={field.value}
72
+ onChange={field.onChange}
73
+ type="email"
74
+ placeholder="Email"
75
+ error={fieldState.invalid}
76
+ inputProps={{
77
+ 'aria-label': 'Email',
78
+ autoComplete: 'email',
79
+ onBlur: field.onBlur,
80
+ }}
81
+ />
82
+ <Typography variant="caption" color="error">
83
+ {fieldState.error?.message}
84
+ </Typography>
85
+ </Flex>
86
+ )}
87
+ />
88
+ <Button type="submit">Send</Button>
89
+ </Flex>
90
+ </form>
91
+ {mutation.data ? <Typography>{mutation.data.message}</Typography> : null}
92
+ </Flex>
93
+ )
94
+ }
95
+ // @elif swr
96
+ /** A form whose values a Zod schema checks; once they pass, it sends them with SWR's mutation. */
97
+ export default function Page() {
98
+ const { trigger, data } = useSWRMutation('messages', (_key: string, { arg }: { arg: Values }) =>
99
+ sendMessage(arg)
100
+ )
101
+ const { control, handleSubmit } = useForm<Values>({
102
+ resolver: zodResolver(schema),
103
+ defaultValues: { name: '', email: '' },
104
+ })
105
+ return (
106
+ <Flex gap={2} alignItems="flex-start">
107
+ <Typography variant="h2">Form</Typography>
108
+ <Typography color="secondary">
109
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
110
+ </Typography>
111
+ <form noValidate onSubmit={handleSubmit((values) => trigger(values))}>
112
+ <Flex gap={2} alignItems="flex-start">
113
+ <Controller
114
+ name="name"
115
+ control={control}
116
+ render={({ field, fieldState }) => (
117
+ <Flex gap={1}>
118
+ <TextInput
119
+ name={field.name}
120
+ value={field.value}
121
+ onChange={field.onChange}
122
+ placeholder="Name"
123
+ error={fieldState.invalid}
124
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
125
+ />
126
+ <Typography variant="caption" color="error">
127
+ {fieldState.error?.message}
128
+ </Typography>
129
+ </Flex>
130
+ )}
131
+ />
132
+ <Controller
133
+ name="email"
134
+ control={control}
135
+ render={({ field, fieldState }) => (
136
+ <Flex gap={1}>
137
+ <TextInput
138
+ name={field.name}
139
+ value={field.value}
140
+ onChange={field.onChange}
141
+ type="email"
142
+ placeholder="Email"
143
+ error={fieldState.invalid}
144
+ inputProps={{
145
+ 'aria-label': 'Email',
146
+ autoComplete: 'email',
147
+ onBlur: field.onBlur,
148
+ }}
149
+ />
150
+ <Typography variant="caption" color="error">
151
+ {fieldState.error?.message}
152
+ </Typography>
153
+ </Flex>
154
+ )}
155
+ />
156
+ <Button type="submit">Send</Button>
157
+ </Flex>
158
+ </form>
159
+ {data ? <Typography>{data.message}</Typography> : null}
160
+ </Flex>
161
+ )
162
+ }
163
+ // @elif msw
164
+ /** A form whose values a Zod schema checks; once they pass, it sends them to the API. */
165
+ export default function Page() {
166
+ const [answer, setAnswer] = useState<string | null>(null)
167
+ const { control, handleSubmit } = useForm<Values>({
168
+ resolver: zodResolver(schema),
169
+ defaultValues: { name: '', email: '' },
170
+ })
171
+ return (
172
+ <Flex gap={2} alignItems="flex-start">
173
+ <Typography variant="h2">Form</Typography>
174
+ <Typography color="secondary">
175
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
176
+ </Typography>
177
+ <form
178
+ noValidate
179
+ onSubmit={handleSubmit(async (values) => setAnswer((await sendMessage(values)).message))}
180
+ >
181
+ <Flex gap={2} alignItems="flex-start">
182
+ <Controller
183
+ name="name"
184
+ control={control}
185
+ render={({ field, fieldState }) => (
186
+ <Flex gap={1}>
187
+ <TextInput
188
+ name={field.name}
189
+ value={field.value}
190
+ onChange={field.onChange}
191
+ placeholder="Name"
192
+ error={fieldState.invalid}
193
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
194
+ />
195
+ <Typography variant="caption" color="error">
196
+ {fieldState.error?.message}
197
+ </Typography>
198
+ </Flex>
199
+ )}
200
+ />
201
+ <Controller
202
+ name="email"
203
+ control={control}
204
+ render={({ field, fieldState }) => (
205
+ <Flex gap={1}>
206
+ <TextInput
207
+ name={field.name}
208
+ value={field.value}
209
+ onChange={field.onChange}
210
+ type="email"
211
+ placeholder="Email"
212
+ error={fieldState.invalid}
213
+ inputProps={{
214
+ 'aria-label': 'Email',
215
+ autoComplete: 'email',
216
+ onBlur: field.onBlur,
217
+ }}
218
+ />
219
+ <Typography variant="caption" color="error">
220
+ {fieldState.error?.message}
221
+ </Typography>
222
+ </Flex>
223
+ )}
224
+ />
225
+ <Button type="submit">Send</Button>
226
+ </Flex>
227
+ </form>
228
+ {answer ? <Typography>{answer}</Typography> : null}
229
+ </Flex>
230
+ )
231
+ }
232
+ // @else
233
+ /** A form whose values a Zod schema checks; once they pass, it shows them. */
234
+ export default function Page() {
235
+ const [sent, setSent] = useState<Values | null>(null)
236
+ const { control, handleSubmit } = useForm<Values>({
237
+ resolver: zodResolver(schema),
238
+ defaultValues: { name: '', email: '' },
239
+ })
240
+ return (
241
+ <Flex gap={2} alignItems="flex-start">
242
+ <Typography variant="h2">Form</Typography>
243
+ <Typography color="secondary">
244
+ React Hook Form holds the values, and a Zod schema checks them when the form is sent.
245
+ </Typography>
246
+ <form noValidate onSubmit={handleSubmit(setSent)}>
247
+ <Flex gap={2} alignItems="flex-start">
248
+ <Controller
249
+ name="name"
250
+ control={control}
251
+ render={({ field, fieldState }) => (
252
+ <Flex gap={1}>
253
+ <TextInput
254
+ name={field.name}
255
+ value={field.value}
256
+ onChange={field.onChange}
257
+ placeholder="Name"
258
+ error={fieldState.invalid}
259
+ inputProps={{ 'aria-label': 'Name', autoComplete: 'name', onBlur: field.onBlur }}
260
+ />
261
+ <Typography variant="caption" color="error">
262
+ {fieldState.error?.message}
263
+ </Typography>
264
+ </Flex>
265
+ )}
266
+ />
267
+ <Controller
268
+ name="email"
269
+ control={control}
270
+ render={({ field, fieldState }) => (
271
+ <Flex gap={1}>
272
+ <TextInput
273
+ name={field.name}
274
+ value={field.value}
275
+ onChange={field.onChange}
276
+ type="email"
277
+ placeholder="Email"
278
+ error={fieldState.invalid}
279
+ inputProps={{
280
+ 'aria-label': 'Email',
281
+ autoComplete: 'email',
282
+ onBlur: field.onBlur,
283
+ }}
284
+ />
285
+ <Typography variant="caption" color="error">
286
+ {fieldState.error?.message}
287
+ </Typography>
288
+ </Flex>
289
+ )}
290
+ />
291
+ <Button type="submit">Send</Button>
292
+ </Flex>
293
+ </form>
294
+ {sent ? <Typography>Thanks, {sent.name}: the form was valid.</Typography> : null}
295
+ </Flex>
296
+ )
297
+ }
298
+ // @endif
@@ -0,0 +1,20 @@
1
+ import { Button } from '@soroush.tech/design-system/Button'
2
+ import { Flex } from '@soroush.tech/design-system/Flex'
3
+ import { Typography } from '@soroush.tech/design-system/Typography'
4
+ import { useDispatch, useSelector } from 'react-redux'
5
+ import { incremented, type RootState } from '../../state/store'
6
+
7
+ /** A count, held in the Redux store, src/state/store, and the button that adds to it. */
8
+ export function Counter() {
9
+ const count = useSelector((state: RootState) => state.count)
10
+ const dispatch = useDispatch()
11
+ const increment = () => dispatch(incremented())
12
+ return (
13
+ <Flex flexDirection="row" alignItems="center" gap={2}>
14
+ <Button size="sm" variant="outlined" onClick={increment}>
15
+ Count
16
+ </Button>
17
+ <Typography>Count: {count}</Typography>
18
+ </Flex>
19
+ )
20
+ }
@@ -0,0 +1,29 @@
1
+ import { configureStore, createSlice, type PayloadAction } from '@reduxjs/toolkit'
2
+
3
+ /** The color scheme the app is drawn in: a slice of the store. */
4
+ const schemeSlice = createSlice({
5
+ name: 'scheme',
6
+ initialState: '__SCHEME__' as 'light' | 'dark',
7
+ reducers: {
8
+ schemeChanged: (_scheme, action: PayloadAction<'light' | 'dark'>) => action.payload,
9
+ },
10
+ })
11
+
12
+ /** The home page's count: another slice. */
13
+ const countSlice = createSlice({
14
+ name: 'count',
15
+ initialState: 0,
16
+ reducers: {
17
+ incremented: (count) => count + 1,
18
+ },
19
+ })
20
+
21
+ export const { schemeChanged } = schemeSlice.actions
22
+ export const { incremented } = countSlice.actions
23
+
24
+ /** The app's Redux store, which src/main.tsx provides to every page. */
25
+ export const store = configureStore({
26
+ reducer: { scheme: schemeSlice.reducer, count: countSlice.reducer },
27
+ })
28
+
29
+ export type RootState = ReturnType<typeof store.getState>
@@ -0,0 +1,17 @@
1
+ import { Button } from '@soroush.tech/design-system/Button'
2
+ import { Flex } from '@soroush.tech/design-system/Flex'
3
+ import { Typography } from '@soroush.tech/design-system/Typography'
4
+ import { useCounter } from '../../state/counter'
5
+
6
+ /** A count, held in a zustand store, src/state/counter, and the button that adds to it. */
7
+ export function Counter() {
8
+ const { count, increment } = useCounter()
9
+ return (
10
+ <Flex flexDirection="row" alignItems="center" gap={2}>
11
+ <Button size="sm" variant="outlined" onClick={increment}>
12
+ Count
13
+ </Button>
14
+ <Typography>Count: {count}</Typography>
15
+ </Flex>
16
+ )
17
+ }
@@ -0,0 +1,19 @@
1
+ import { create } from 'zustand'
2
+
3
+ interface CounterState {
4
+ count: number
5
+ increment: () => void
6
+ }
7
+
8
+ /** The home page's count: a zustand store, which any component can read. */
9
+ // @if ts
10
+ export const useCounter = create<CounterState>()((set) => ({
11
+ count: 0,
12
+ increment: () => set((state) => ({ count: state.count + 1 })),
13
+ }))
14
+ // @else
15
+ export const useCounter = create((set) => ({
16
+ count: 0,
17
+ increment: () => set((state) => ({ count: state.count + 1 })),
18
+ }))
19
+ // @endif
@@ -0,0 +1,19 @@
1
+ import { create } from 'zustand'
2
+
3
+ interface SchemeState {
4
+ scheme: 'light' | 'dark'
5
+ setScheme: (scheme: 'light' | 'dark') => void
6
+ }
7
+
8
+ /** The color scheme the app is drawn in: a zustand store, which any component can read. */
9
+ // @if ts
10
+ export const useScheme = create<SchemeState>()((set) => ({
11
+ scheme: '__SCHEME__',
12
+ setScheme: (scheme) => set({ scheme }),
13
+ }))
14
+ // @else
15
+ export const useScheme = create((set) => ({
16
+ scheme: '__SCHEME__',
17
+ setScheme: (scheme) => set({ scheme }),
18
+ }))
19
+ // @endif
@@ -55,7 +55,8 @@ quotes) and `__SCHEME__` (`light` or `dark`). A path a text names is written as
55
55
 
56
56
  ## The JavaScript templates
57
57
 
58
- `pnpm gen:templates` makes `<framework>/js/` from `<framework>/ts/`: it takes the types out of each
58
+ The package's build, and its tests' setup, make `<framework>/js/` from `<framework>/ts/`
59
+ (`scripts/gen-templates.mjs`): it takes the types out of each
59
60
  `.ts` and `.tsx` file and of an `.astro` file's frontmatter (`ts-blank-space`), drops a line that
60
61
  held only types, turns the paths a text names and the file names to `.js` and `.jsx`, leaves out
61
62
  `tsconfig.json` and `.d.ts` files, and formats the result. `pnpm build` runs it before the code is
@@ -5,8 +5,6 @@ A [Vike](https://vike.dev) app on the [@soroush.tech design system](https://docs
5
5
  prerendered at build time with its styles in the HTML, then moving between pages with no reload.
6
6
  <!-- @elif ssr -->
7
7
  every page rendered on the server, on each request, with its styles in the HTML, then moving between pages with no reload.
8
- <!-- @elif spa -->
9
- a single-page app: each page is an HTML shell from the build, rendered in the browser, which moves between pages with no reload.
10
8
  <!-- @else -->
11
9
  every page prerendered to HTML at build time, with its styles, and no JavaScript in the browser.
12
10
  <!-- @endif -->
@@ -22,8 +20,6 @@ every page prerendered to HTML at build time, with its styles, and no JavaScript
22
20
  - In `src/pages/`, `+onRenderHtml` and `+onRenderClient` render the pages, with the styles each page uses in its HTML.
23
21
  <!-- @elif ssr -->
24
22
  - In `src/pages/`, `+onRenderHtml` renders each page on the server and `+onRenderClient` takes it over in the browser, with the styles each page uses in its HTML.
25
- <!-- @elif spa -->
26
- - In `src/pages/`, `+onRenderHtml` writes the HTML shell of each page, and `+onRenderClient` renders the page in it.
27
23
  <!-- @else -->
28
24
  - In `src/pages/`, `+onRenderHtml` renders the pages to HTML, with the styles each page uses.
29
25
  <!-- @endif -->
@@ -5,8 +5,6 @@ A [Vike](https://vike.dev) app on the [@soroush.tech design system](https://docs
5
5
  prerendered at build time with its styles in the HTML, then moving between pages with no reload.
6
6
  <!-- @elif ssr -->
7
7
  every page rendered on the server, on each request, with its styles in the HTML, then moving between pages with no reload.
8
- <!-- @elif spa -->
9
- a single-page app: each page is an HTML shell from the build, rendered in the browser, which moves between pages with no reload.
10
8
  <!-- @else -->
11
9
  every page prerendered to HTML at build time, with its styles, and no JavaScript in the browser.
12
10
  <!-- @endif -->
@@ -22,8 +20,6 @@ every page prerendered to HTML at build time, with its styles, and no JavaScript
22
20
  - In `src/pages/`, `+onRenderHtml` and `+onRenderClient` render the pages, with the styles each page uses in its HTML.
23
21
  <!-- @elif ssr -->
24
22
  - In `src/pages/`, `+onRenderHtml` renders each page on the server and `+onRenderClient` takes it over in the browser, with the styles each page uses in its HTML.
25
- <!-- @elif spa -->
26
- - In `src/pages/`, `+onRenderHtml` writes the HTML shell of each page, and `+onRenderClient` renders the page in it.
27
23
  <!-- @else -->
28
24
  - In `src/pages/`, `+onRenderHtml` renders the pages to HTML, with the styles each page uses.
29
25
  <!-- @endif -->
@@ -1,12 +0,0 @@
1
- // The settings of every page: https://vike.dev/config
2
- export default {
3
- // SPA: every page is an empty HTML shell from the build, which the browser renders; the app
4
- // moves between pages with no reload.
5
- prerender: true,
6
- clientRouting: true,
7
- // The page and +Layout, a setting of this app's own, load in the browser only.
8
- meta: {
9
- Page: { env: { server: false, client: true } },
10
- Layout: { env: { server: false, client: true } },
11
- },
12
- }
@@ -1,25 +0,0 @@
1
- import { createRoot } from 'react-dom/client'
2
- // @if msw
3
- import { startMocks } from '../mocks/start'
4
- // @else
5
- // @endif
6
- import { PageShell } from './PageShell'
7
-
8
- let root
9
- // @if msw
10
- const mocks = startMocks()
11
- // @endif
12
-
13
- /** Draws the page in the browser, and each page the app moves to. */
14
- // @if msw
15
- export const onRenderClient = async (pageContext) => {
16
- await mocks
17
- root ??= createRoot(document.getElementById('root'))
18
- root.render(<PageShell pageContext={pageContext} />)
19
- }
20
- // @else
21
- export const onRenderClient = (pageContext) => {
22
- root ??= createRoot(document.getElementById('root'))
23
- root.render(<PageShell pageContext={pageContext} />)
24
- }
25
- // @endif
@@ -1,14 +0,0 @@
1
- import type { Config } from 'vike/types'
2
-
3
- // The settings of every page: https://vike.dev/config
4
- export default {
5
- // SPA: every page is an empty HTML shell from the build, which the browser renders; the app
6
- // moves between pages with no reload.
7
- prerender: true,
8
- clientRouting: true,
9
- // The page and +Layout, a setting of this app's own, load in the browser only.
10
- meta: {
11
- Page: { env: { server: false, client: true } },
12
- Layout: { env: { server: false, client: true } },
13
- },
14
- } satisfies Config
@@ -1,27 +0,0 @@
1
- import { createRoot, type Root } from 'react-dom/client'
2
- // @if msw
3
- import type { OnRenderClientAsync } from 'vike/types'
4
- import { startMocks } from '../mocks/start'
5
- // @else
6
- import type { OnRenderClientSync } from 'vike/types'
7
- // @endif
8
- import { PageShell } from './PageShell'
9
-
10
- let root: Root | undefined
11
- // @if msw
12
- const mocks = startMocks()
13
- // @endif
14
-
15
- /** Draws the page in the browser, and each page the app moves to. */
16
- // @if msw
17
- export const onRenderClient: OnRenderClientAsync = async (pageContext) => {
18
- await mocks
19
- root ??= createRoot(document.getElementById('root')!)
20
- root.render(<PageShell pageContext={pageContext} />)
21
- }
22
- // @else
23
- export const onRenderClient: OnRenderClientSync = (pageContext) => {
24
- root ??= createRoot(document.getElementById('root')!)
25
- root.render(<PageShell pageContext={pageContext} />)
26
- }
27
- // @endif
@@ -1,17 +0,0 @@
1
- import { escapeInject } from 'vike/server'
2
- import type { OnRenderHtmlSync } from 'vike/types'
3
-
4
- /** The page's HTML shell, from the build: the browser renders the page in #root. */
5
- export const onRenderHtml: OnRenderHtmlSync = () => {
6
- return escapeInject`<!doctype html>
7
- <html lang="en">
8
- <head>
9
- <meta charset="UTF-8" />
10
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
11
- <title>__TITLE__</title>
12
- </head>
13
- <body>
14
- <div id="root"></div>
15
- </body>
16
- </html>`
17
- }