@rsc-kit/mcp 0.41.0 → 0.42.1
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/dist/recipes.js +18 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +270 -216
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
package/guides/pages.md
CHANGED
|
@@ -3,15 +3,27 @@
|
|
|
3
3
|
> Landing pages, an about page, a pricing page - built in the admin panel from the app's own blocks, live on the next visit.
|
|
4
4
|
|
|
5
5
|
`@rsc-kit/press/pages` lets an editor build pages in the [admin panel](/guides/admin/)
|
|
6
|
-
from blocks the app defines
|
|
7
|
-
[blueprint's form](/guides/blueprints/) -
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
from blocks the app defines: a hero, a feature grid, a call to action, a
|
|
7
|
+
[blueprint's form](/guides/blueprints/). One catch-all route serves them. The
|
|
8
|
+
blocks are the app's code and look like the rest of the site; what is on a
|
|
9
|
+
page, and in what order, is the editor's.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```ts title="src/site/pages.ts"
|
|
12
|
+
import { definePages } from '@rsc-kit/press/pages'
|
|
13
|
+
import { features, hero, text } from './blocks'
|
|
14
|
+
|
|
15
|
+
export const site = definePages({
|
|
16
|
+
blocks: [hero, features, text],
|
|
17
|
+
source: pagesSource,
|
|
18
|
+
})
|
|
19
|
+
```
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
An editor adds a page in the panel, picks blocks and fills them in. It is live
|
|
22
|
+
at its address on the next visit, with nothing rebuilt.
|
|
23
|
+
|
|
24
|
+
## Defining a block
|
|
25
|
+
|
|
26
|
+
A block is a schema for what an editor fills in, and a component that draws it:
|
|
15
27
|
|
|
16
28
|
```tsx title="src/site/blocks.tsx"
|
|
17
29
|
import * as z from 'zod'
|
|
@@ -33,13 +45,54 @@ export const hero = defineBlock({
|
|
|
33
45
|
})
|
|
34
46
|
```
|
|
35
47
|
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
is
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
- `name` is what it is saved as: lowercase letters, digits and dashes.
|
|
49
|
+
- `label` is what an editor picks it by. It is made from the name unless said.
|
|
50
|
+
- `form` is any Standard Schema, and `fields` sets what it cannot say, as a
|
|
51
|
+
[resource's form](/guides/admin/forms/#the-form-is-any-standard-schema) does.
|
|
52
|
+
- `render` is a server component and may be async.
|
|
53
|
+
|
|
54
|
+
### A block that reads data
|
|
55
|
+
|
|
56
|
+
A block that lists the latest posts reads them itself:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
export const latestPosts = defineBlock({
|
|
60
|
+
name: 'latest-posts',
|
|
61
|
+
form: z.object({ heading: z.string(), count: z.number().int().min(1).max(12) }),
|
|
62
|
+
render: async ({ data }) => {
|
|
63
|
+
const posts = await latest(data.count)
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<section>
|
|
67
|
+
<h2>{data.heading}</h2>
|
|
68
|
+
<ul>{posts.map((post) => <li key={post.id}>{post.title}</li>)}</ul>
|
|
69
|
+
</section>
|
|
70
|
+
)
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### A block with a form
|
|
41
76
|
|
|
42
|
-
|
|
77
|
+
A block can place a public form, so the editor decides where it goes and the
|
|
78
|
+
code decides what it does:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { contact } from '@/forms/contact'
|
|
82
|
+
|
|
83
|
+
export const contactForm = defineBlock({
|
|
84
|
+
name: 'contact-form',
|
|
85
|
+
form: z.object({ heading: z.string() }),
|
|
86
|
+
render: ({ data }) => (
|
|
87
|
+
<section>
|
|
88
|
+
<h2>{data.heading}</h2>
|
|
89
|
+
<contact.Form />
|
|
90
|
+
</section>
|
|
91
|
+
),
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Serving the pages
|
|
43
96
|
|
|
44
97
|
```ts title="src/site/pages.ts"
|
|
45
98
|
import { FileText } from 'lucide-react'
|
|
@@ -80,51 +133,78 @@ export default site.middleware
|
|
|
80
133
|
resources: [site.resource, products, customers],
|
|
81
134
|
```
|
|
82
135
|
|
|
83
|
-
The catch-all is the weakest route there is, so every page and route the app
|
|
84
|
-
has wins over it
|
|
85
|
-
slug is its address
|
|
86
|
-
|
|
87
|
-
|
|
136
|
+
- The catch-all is the weakest route there is, so every page and route the app
|
|
137
|
+
has wins over it. It answers only the addresses nothing else does.
|
|
138
|
+
- A page's slug is its address: `about`, `pricing/teams`.
|
|
139
|
+
- A page's title and description become its `<title>` and meta description,
|
|
140
|
+
through `generateMetadata`.
|
|
141
|
+
- A draft is a page with Published off, reachable only in the panel.
|
|
142
|
+
- `blocks` lists the kinds of block an editor is offered, in that order.
|
|
143
|
+
|
|
144
|
+
### The home page
|
|
145
|
+
|
|
146
|
+
The page named `home` is served at `/` when the app has no `app/page.tsx` of
|
|
147
|
+
its own. `home` changes which:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
export const site = definePages({ blocks, source, home: 'welcome' })
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### A real 404
|
|
88
154
|
|
|
89
155
|
The middleware asks whether there is a published page at the address before
|
|
90
|
-
anything is sent, so a draft or a typo is a real **404**. Without it the
|
|
156
|
+
anything is sent, so a draft or a typo is a real **404**. Without it, the
|
|
91
157
|
route's shell has already gone out with a 200 by the time the page finds
|
|
92
|
-
nothing
|
|
158
|
+
nothing. See [Errors](/guides/errors/#when-the-page-has-to-decide).
|
|
159
|
+
|
|
160
|
+
### While a page is looked up
|
|
161
|
+
|
|
162
|
+
`fallback` is what shows while a page is looked up. Nothing shows by default:
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
export const site = definePages({ blocks, source, fallback: <Skeleton className="h-96" /> })
|
|
166
|
+
```
|
|
93
167
|
|
|
94
168
|
## Live on the next visit
|
|
95
169
|
|
|
96
170
|
A save in the panel is live on the next visit, and nothing is rebuilt. A page
|
|
97
|
-
is looked up once and then kept, so most visits
|
|
98
|
-
for 60 seconds, or until any page is saved.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
request:
|
|
171
|
+
is looked up once and then kept, so most visits don't ask the source at all:
|
|
172
|
+
for 60 seconds, or until any page is saved.
|
|
173
|
+
|
|
174
|
+
`revalidate` sets how long, in seconds, and `false` asks on every request:
|
|
102
175
|
|
|
103
176
|
```ts
|
|
104
177
|
export const site = definePages({ blocks, source, revalidate: 300 })
|
|
105
178
|
```
|
|
106
179
|
|
|
107
180
|
A change made around the panel, straight in the database, shows when the kept
|
|
108
|
-
copy expires, or at once after `changed('press:pages')
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
181
|
+
copy expires, or at once after `changed('press:pages')`:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { changed } from '@rsc-kit/core/changed'
|
|
185
|
+
|
|
186
|
+
await changed('press:pages')
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- The page is kept with [`cache()`](/guides/caching/#across-requests), in memory
|
|
190
|
+
unless the app installs a shared store.
|
|
191
|
+
- The build stores the route's frame as one shell for every address, and the
|
|
192
|
+
page streams into it.
|
|
113
193
|
|
|
114
194
|
## Where pages are kept
|
|
115
195
|
|
|
116
|
-
`source` is a [data source](/guides/admin
|
|
117
|
-
`{ id, title, slug, description?, published, blocks }
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
196
|
+
`source` is a [data source](/guides/admin/data-sources/) of rows shaped
|
|
197
|
+
`{ id, title, slug, description?, published, blocks }`. `blocks` is a list of
|
|
198
|
+
`{ type, data }`, a JSON column in a database.
|
|
199
|
+
|
|
200
|
+
Its `list()` is also how a page is found by its address:
|
|
201
|
+
it is asked for `filters: { slug }`, and must answer with the page at that slug.
|
|
122
202
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
203
|
+
### In a Laravel or Go backend
|
|
204
|
+
|
|
205
|
+
Pages an editor saves belong where the app keeps its other data. On a Laravel
|
|
206
|
+
or Go backend that is a `pages` table with a JSON `blocks` column, behind
|
|
207
|
+
`rpc()`:
|
|
128
208
|
|
|
129
209
|
```ts title="src/site/pages.ts"
|
|
130
210
|
const pagesSource: DataSource<PageRow, PageValues> = {
|
|
@@ -147,18 +227,47 @@ public function list(array $query): array
|
|
|
147
227
|
}
|
|
148
228
|
```
|
|
149
229
|
|
|
150
|
-
Cast `blocks` to an array on the model, and `published` to a boolean
|
|
151
|
-
|
|
230
|
+
Cast `blocks` to an array on the model, and `published` to a boolean:
|
|
231
|
+
|
|
232
|
+
```php title="app/Models/Page.php"
|
|
233
|
+
protected function casts(): array
|
|
234
|
+
{
|
|
235
|
+
return ['blocks' => 'array', 'published' => 'boolean'];
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
An app with no backend writes the same five functions over its own database:
|
|
152
240
|
Drizzle, Prisma, `bun:sqlite`.
|
|
153
241
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
242
|
+
### In memory, for a demo
|
|
243
|
+
|
|
244
|
+
`memorySource` keeps the pages in the process's memory, and filters on `slug`
|
|
245
|
+
as `list()` must:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { memorySource } from '@rsc-kit/press'
|
|
249
|
+
|
|
250
|
+
const pagesSource = memorySource<PageRow, PageValues>(
|
|
251
|
+
[{ id: 1, title: 'Home', slug: 'home', published: true, blocks: [] }],
|
|
252
|
+
'id',
|
|
253
|
+
(id, values) => ({ id, ...values }),
|
|
254
|
+
)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
An edit is gone when the server restarts, and two servers each have their own
|
|
258
|
+
copy. It is for a demo, or for pages that only ever come from rows in code.
|
|
259
|
+
|
|
260
|
+
### What a save checks
|
|
261
|
+
|
|
262
|
+
- Each block's data is checked by its own schema on every save, and a refusal
|
|
263
|
+
shows under that block's field.
|
|
264
|
+
- An address belongs to one page: saving a second page at `/about` is refused
|
|
265
|
+
under its slug.
|
|
157
266
|
|
|
158
267
|
## Blocks in any resource
|
|
159
268
|
|
|
160
|
-
The block editor is a field type, so any resource can have one
|
|
161
|
-
long description
|
|
269
|
+
The block editor is a field type, so any resource can have one, such as a
|
|
270
|
+
product's long description or a post's body:
|
|
162
271
|
|
|
163
272
|
```ts
|
|
164
273
|
form: z.object({ name: z.string(), body: z.array(z.any()) }),
|
|
@@ -173,5 +282,6 @@ import { Blocks } from '@rsc-kit/press'
|
|
|
173
282
|
<Blocks blocks={[text, gallery, quote]} value={post.body} />
|
|
174
283
|
```
|
|
175
284
|
|
|
176
|
-
A block whose kind the code no longer defines is left out of the page rather
|
|
177
|
-
than failing it, and the editor says that saving will remove it.
|
|
285
|
+
- A block whose kind the code no longer defines is left out of the page rather
|
|
286
|
+
than failing it, and the editor says that saving will remove it.
|
|
287
|
+
- Blocks don't nest: a block with a blocks field fails when it is defined.
|