@rsc-kit/mcp 0.30.50 → 0.30.52
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 +71 -13
- package/dist/recipes.js.map +1 -1
- package/guides/admin.md +121 -2
- package/guides/{public-forms.md → blueprints.md} +126 -23
- package/guides/go.md +14 -5
- package/guides/index.json +5 -5
- package/guides/isr.md +1 -1
- package/guides/laravel.md +17 -4
- package/guides/pages.md +1 -1
- package/guides/your-own-backend.md +1 -1
- package/package.json +2 -2
package/guides/admin.md
CHANGED
|
@@ -12,7 +12,7 @@ The package has three entry points:
|
|
|
12
12
|
|
|
13
13
|
- `@rsc-kit/press` - resources, data sources, tenants, plugins and blocks. Nothing here draws.
|
|
14
14
|
- `@rsc-kit/press/admin` - `definePanel`, and the url schemas its routes export.
|
|
15
|
-
- `@rsc-kit/press/forms` - `
|
|
15
|
+
- `@rsc-kit/press/forms` - `defineBlueprint`, for [blueprints](/guides/blueprints/): a form defined once, drawn in any page and as a resource's form.
|
|
16
16
|
- `@rsc-kit/press/pages` - `definePages`, for [pages an editor builds from blocks](/guides/pages/).
|
|
17
17
|
- `@rsc-kit/press/shadcn` - the shadcn theme, which draws both.
|
|
18
18
|
|
|
@@ -132,6 +132,44 @@ const customersSource: DataSource<Customer, Values> = {
|
|
|
132
132
|
}
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
### Pages by count, or by cursor
|
|
136
|
+
|
|
137
|
+
A list answers its page one of two ways, and the table pages to match:
|
|
138
|
+
|
|
139
|
+
- `{ rows, total }` - counted. The table says how many, and numbers its pages.
|
|
140
|
+
- `{ rows, next, prev }` - by cursor. The table has Previous and Next, each a
|
|
141
|
+
link to the list with `?cursor=` set to the one the source handed out, and
|
|
142
|
+
says nothing of how many. `null` is no page that way.
|
|
143
|
+
|
|
144
|
+
A cursor suits a table too big to count, or a query that is cheap only by key -
|
|
145
|
+
Laravel's `cursorPaginate`, a keyset query, an API that hands back a cursor.
|
|
146
|
+
The source is told the one it gave as `query.cursor`, absent on the first page,
|
|
147
|
+
and reads that rather than `page`. A search, a filter or a sort starts again from
|
|
148
|
+
the first page; paging keeps them.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
list: async (query) => {
|
|
152
|
+
const page = await rpc('Orders.list', query)
|
|
153
|
+
|
|
154
|
+
return { rows: page.data as Order[], next: page.next_cursor, prev: page.prev_cursor }
|
|
155
|
+
},
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```php title="app/Rsc/Orders.php"
|
|
159
|
+
public function list(array $query): CursorPaginator
|
|
160
|
+
{
|
|
161
|
+
return Order::latest('id')->cursorPaginate($query['perPage'], cursor: $query['cursor'] ?? null);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
A method returning a paginator is typed as Laravel encodes it - `data`,
|
|
166
|
+
`next_cursor` and `prev_cursor` from `cursorPaginate`, `data` and `total` from
|
|
167
|
+
`paginate`, which is `{ rows: page.data as Order[], total: page.total }` - with
|
|
168
|
+
its rows unknown, which the cast names (`rsc-kit/laravel` 0.19).
|
|
169
|
+
|
|
170
|
+
Each resource chooses for itself, so one panel can have both. The dashboard
|
|
171
|
+
shows a dash for a resource it cannot count.
|
|
172
|
+
|
|
135
173
|
A save says "Product saved." on the list it lands on, and a delete says
|
|
136
174
|
"Product deleted." in place, as a toast. Both use
|
|
137
175
|
[`flash()`](/guides/server-actions#a-message-for-the-next-page).
|
|
@@ -168,6 +206,87 @@ and its messages show under the same fields as the schema's, with the form's
|
|
|
168
206
|
values kept. Nothing to catch: the panel treats the backend's refusal and its
|
|
169
207
|
own the same way.
|
|
170
208
|
|
|
209
|
+
### The backend's actions as the form
|
|
210
|
+
|
|
211
|
+
When the backend already says what a record takes - a FormRequest, a Go struct
|
|
212
|
+
with `validate` tags - the resource needs no schema of its own. Give it the
|
|
213
|
+
backend's generated actions instead of `form`, and the source keeps only
|
|
214
|
+
`list`, `find` and `delete`:
|
|
215
|
+
|
|
216
|
+
```ts title="src/admin/resources/products.ts"
|
|
217
|
+
import { productsStore, productsUpdate } from '@/actions/products'
|
|
218
|
+
|
|
219
|
+
export const products = defineResource<Product>()({
|
|
220
|
+
name: 'products',
|
|
221
|
+
key: 'id',
|
|
222
|
+
title: 'name',
|
|
223
|
+
source: { list: (q) => rpc('Products.list', q), find: (id) => rpc('Products.find', id), delete: (id) => rpc('Products.delete', id) },
|
|
224
|
+
actions: { create: productsStore, update: productsUpdate },
|
|
225
|
+
fields: { category_id: { relation: 'categories' } },
|
|
226
|
+
table: (col) => [col.text('name'), col.money('price')],
|
|
227
|
+
})
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
The create form is drawn from what `create` takes, and the edit form from what
|
|
231
|
+
`update` takes, so a password required on one can be optional on the other.
|
|
232
|
+
`fields` names the backend's fields - a misspelt one fails the typecheck - and
|
|
233
|
+
adds what the rules cannot say, such as a relation. `create` is called with the
|
|
234
|
+
values; `update` with the values, then the record's key:
|
|
235
|
+
|
|
236
|
+
```php title="app/Rsc/Actions/Products.php"
|
|
237
|
+
public function update(UpdateProductRequest $request, string $product): Product
|
|
238
|
+
{
|
|
239
|
+
return tap(Product::findOrFail($product))->update($request->validated());
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
```php title="app/Http/Requests/UpdateProductRequest.php"
|
|
244
|
+
'sku' => ['required', Rule::unique('products')->ignore($this->route('product'))],
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The key reaches the FormRequest as its route parameter, under the method's own
|
|
248
|
+
name for it, so a unique rule ignores the record being edited as it would on
|
|
249
|
+
`PUT /products/{product}` - and `Route::model()` binds it. In Go the update is
|
|
250
|
+
`func(ctx context.Context, in ProductInput, id string)`. An update that takes
|
|
251
|
+
only the values is refused at startup, since it could not be told which
|
|
252
|
+
record, and so is a `create` that takes a key.
|
|
253
|
+
|
|
254
|
+
The backend does every check. The panel still refuses a relation the visitor
|
|
255
|
+
cannot see before the backend is asked.
|
|
256
|
+
|
|
257
|
+
### A blueprint as the form
|
|
258
|
+
|
|
259
|
+
The same form is often wanted outside the panel too: a settings page where
|
|
260
|
+
people edit their own profile, a sign-up that creates what the panel lists.
|
|
261
|
+
Define it once as a [blueprint](/guides/blueprints/), and hand it to the
|
|
262
|
+
resource as its `form`:
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import { defineBlueprint } from '@rsc-kit/press/forms'
|
|
266
|
+
|
|
267
|
+
export const product = defineBlueprint({
|
|
268
|
+
name: 'product',
|
|
269
|
+
theme: shadcn,
|
|
270
|
+
actions: { create: productsStore, update: productsUpdate },
|
|
271
|
+
fields: { category_id: { relation: 'categories' } },
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
export const products = defineResource<Product>()({
|
|
275
|
+
name: 'products',
|
|
276
|
+
key: 'id',
|
|
277
|
+
title: 'name',
|
|
278
|
+
source: { list, find, delete: remove },
|
|
279
|
+
table: (col) => [col.text('name'), col.money('price')],
|
|
280
|
+
form: product,
|
|
281
|
+
})
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The panel's create and edit pages are then the blueprint's fields, saved with
|
|
285
|
+
the blueprint's actions - or a schema blueprint's `handle` and `update` - and a
|
|
286
|
+
page draws the same form with `<product.Form />`, or
|
|
287
|
+
`<product.Form id={p.id} values={p} />` to edit. A blueprint that does not
|
|
288
|
+
save leaves it to a whole source.
|
|
289
|
+
|
|
171
290
|
### Choices that read as words
|
|
172
291
|
|
|
173
292
|
An enum's options are shown humanized - `'in_stock'` reads "In stock" in the
|
|
@@ -236,7 +355,7 @@ and, when the schema allows `null`, a **Remove** button that saves `null`.
|
|
|
236
355
|
names, does that.
|
|
237
356
|
|
|
238
357
|
The field works the same in a [block](/guides/pages/) and in a
|
|
239
|
-
[
|
|
358
|
+
[blueprint's form](/guides/blueprints/).
|
|
240
359
|
|
|
241
360
|
## Relations
|
|
242
361
|
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Blueprints
|
|
2
2
|
|
|
3
|
-
> A
|
|
3
|
+
> A form defined once - fields, checks and saves - and drawn anywhere it is needed - a contact page, an edit page, an admin panel - from a Standard Schema or a backend's own actions.
|
|
4
4
|
|
|
5
|
-
`@rsc-kit/press/forms` turns a Standard Schema
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
`@rsc-kit/press/forms` turns a Standard Schema, or a backend's actions, into a
|
|
6
|
+
**blueprint**: a form's fields, its checks and what saving it does, defined
|
|
7
|
+
once. A page draws it with `<contact.Form />`, an edit page with
|
|
8
|
+
`<profile.Form id={user.id} values={user} />`, and an
|
|
9
|
+
[admin panel](/guides/admin/) draws its create and edit pages from it with
|
|
10
|
+
`defineResource({ form: profile })` - the same fields, the same browser
|
|
11
|
+
checks, the same refusals under the same fields. A
|
|
12
|
+
[theme](/guides/admin/#themes) draws it; the `shadcn` theme draws both.
|
|
9
13
|
|
|
10
|
-
On a Laravel or Go backend there is no schema to write:
|
|
11
|
-
|
|
14
|
+
On a Laravel or Go backend there is no schema to write: hand it the backend's
|
|
15
|
+
actions, and the form is drawn from what they take. See
|
|
12
16
|
[A Laravel or Go backend](#a-laravel-or-go-backend).
|
|
13
17
|
|
|
14
18
|
```ts title="src/forms/contact.ts"
|
|
15
19
|
import * as z from 'zod'
|
|
16
|
-
import {
|
|
20
|
+
import { defineBlueprint } from '@rsc-kit/press/forms'
|
|
17
21
|
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
18
22
|
|
|
19
|
-
export const contact =
|
|
23
|
+
export const contact = defineBlueprint({
|
|
20
24
|
name: 'contact',
|
|
21
25
|
form: z.object({
|
|
22
26
|
name: z.string().min(2),
|
|
@@ -55,6 +59,65 @@ Install is the panel's: `bun add @rsc-kit/press`, and the
|
|
|
55
59
|
`@import "@rsc-kit/press/shadcn.css"` line in the app's stylesheet, as in
|
|
56
60
|
[Admin panels](/guides/admin/#install).
|
|
57
61
|
|
|
62
|
+
## Editing a record
|
|
63
|
+
|
|
64
|
+
Give the blueprint an `update`, and `<profile.Form />` with an `id` edits that
|
|
65
|
+
record instead of creating one, starting from `values`:
|
|
66
|
+
|
|
67
|
+
```ts title="src/forms/profile.ts"
|
|
68
|
+
export const profile = defineBlueprint({
|
|
69
|
+
name: 'profile',
|
|
70
|
+
form: z.object({ name: z.string().min(2), email: z.email() }),
|
|
71
|
+
theme: shadcn,
|
|
72
|
+
honeypot: false,
|
|
73
|
+
done: 'Saved.',
|
|
74
|
+
update: async (values, key) => {
|
|
75
|
+
await db.update(users).set(values).where(eq(users.id, key))
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```tsx title="src/app/settings/page.tsx"
|
|
81
|
+
export default async function Settings() {
|
|
82
|
+
const user = await currentUser()
|
|
83
|
+
|
|
84
|
+
return <profile.Form id={user.id} values={user} />
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Only the blueprint's own fields of `values` reach the browser, so handing it
|
|
89
|
+
a whole row does not put its password hash in the page.
|
|
90
|
+
|
|
91
|
+
**The key comes back from the browser**, like every field, and anyone can post
|
|
92
|
+
another. `update` must check the visitor may change that record - here, by
|
|
93
|
+
comparing it with the session's user; in Laravel, the `FormRequest`'s
|
|
94
|
+
`authorize()`. A blueprint may have `handle`, `update` or both, and drawing it
|
|
95
|
+
for one it does not have says so.
|
|
96
|
+
|
|
97
|
+
`honeypot: false` drops the bot trap for a form only signed-in people reach.
|
|
98
|
+
|
|
99
|
+
## In an admin panel
|
|
100
|
+
|
|
101
|
+
A resource takes the blueprint as its `form`, and its create and edit pages are
|
|
102
|
+
that blueprint's form:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
export const people = defineResource<User>()({
|
|
106
|
+
name: 'people',
|
|
107
|
+
key: 'id',
|
|
108
|
+
title: 'name',
|
|
109
|
+
source: { list, find, delete: remove },
|
|
110
|
+
table: (col) => [col.text('name'), col.text('email')],
|
|
111
|
+
form: profile,
|
|
112
|
+
})
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
A blueprint that saves - a backend's `create` and `update`, or a schema's
|
|
116
|
+
`handle` and `update` - saves the panel's records too, so the source only
|
|
117
|
+
lists, finds and deletes. One that does not leaves saving to a whole
|
|
118
|
+
[source](/guides/admin/). `fields` and `actions` are said on the blueprint,
|
|
119
|
+
not again on the resource.
|
|
120
|
+
|
|
58
121
|
## What is checked, and where
|
|
59
122
|
|
|
60
123
|
The schema's constraints become the browser's - `required`, `minlength`,
|
|
@@ -76,21 +139,48 @@ handle: async ({ email }) => {
|
|
|
76
139
|
},
|
|
77
140
|
```
|
|
78
141
|
|
|
142
|
+
## Fields that depend on others
|
|
143
|
+
|
|
144
|
+
Two things a field can say about another, in `fields`, as plain data: the
|
|
145
|
+
browser applies them while the visitor types, and the server applies them again
|
|
146
|
+
to what was sent.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
fields: {
|
|
150
|
+
company: { visible: { when: 'topic', is: 'sales' } },
|
|
151
|
+
slug: { from: { field: 'title' } },
|
|
152
|
+
},
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**`visible`** shows a field only while another has one of the values in `is` -
|
|
156
|
+
one value or a list. `not` turns it round, and with neither the field shows
|
|
157
|
+
once the other is filled in, or a switch is on. A hidden field is not sent, and
|
|
158
|
+
the browser does not check it; if a post sends one anyway, the server drops it
|
|
159
|
+
before the schema sees it. So a field asked only sometimes is optional to the
|
|
160
|
+
schema - `z.string().min(2).optional()` - and checked whenever it is there.
|
|
161
|
+
|
|
162
|
+
**`from`** fills a field with the slug of another - "Café & Bar" is
|
|
163
|
+
`cafe-bar` - as the other is typed. Once someone edits it by hand it is left
|
|
164
|
+
alone, and one left empty is filled the same way on the server.
|
|
165
|
+
|
|
166
|
+
`when` and `field` name another of the form's fields, and one that does not
|
|
167
|
+
exist fails at startup.
|
|
168
|
+
|
|
79
169
|
## A Laravel or Go backend
|
|
80
170
|
|
|
81
|
-
Give it the backend's
|
|
82
|
-
backend already says what
|
|
83
|
-
|
|
84
|
-
|
|
171
|
+
Give it the backend's actions, and the form needs no schema of its own. The
|
|
172
|
+
backend already says what each takes, so the fields and the browser's checks
|
|
173
|
+
come from there, and every check that counts is the backend's. The actions are
|
|
174
|
+
the ones the build generated, imported like any other:
|
|
85
175
|
|
|
86
176
|
```ts title="resources/js/forms/contact.ts"
|
|
87
|
-
import {
|
|
177
|
+
import { defineBlueprint } from '@rsc-kit/press/forms'
|
|
88
178
|
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
89
179
|
import { contactSend } from '../server-actions.generated'
|
|
90
180
|
|
|
91
|
-
export const contact =
|
|
181
|
+
export const contact = defineBlueprint({
|
|
92
182
|
name: 'contact',
|
|
93
|
-
|
|
183
|
+
actions: { create: contactSend },
|
|
94
184
|
fields: { message: { type: 'textarea' } },
|
|
95
185
|
theme: shadcn,
|
|
96
186
|
submit: 'Send message',
|
|
@@ -98,6 +188,13 @@ export const contact = defineForm({
|
|
|
98
188
|
})
|
|
99
189
|
```
|
|
100
190
|
|
|
191
|
+
`actions` is `{ create, update }`, either or both. The create form is drawn
|
|
192
|
+
from what `create` takes and the edit form from what `update` takes, so a
|
|
193
|
+
password required to sign up can be optional to edit. `update` is called with
|
|
194
|
+
the record's key after the values: `update(UpdateProfile $request, string
|
|
195
|
+
$user)` in Laravel, where `$this->route('user')` reads it in `rules()` and
|
|
196
|
+
`authorize()`, and `func(ctx, in ProfileInput, id string)` in Go.
|
|
197
|
+
|
|
101
198
|
You need not write it: `bunx rsc-kit make:form contactSend` writes this file
|
|
102
199
|
from the action, and it is yours to edit from then on.
|
|
103
200
|
|
|
@@ -187,6 +284,9 @@ check alone, and its field a plain input: `regex` (PCRE is not the browser's
|
|
|
187
284
|
pattern), `Rule::enum()`, a closure. `rules()` runs with no request behind it,
|
|
188
285
|
so one that reads the request cannot be described: list the fields in `fields`.
|
|
189
286
|
|
|
287
|
+
`required_if:topic,support` is read as `visible`: the field shows while `topic`
|
|
288
|
+
is `support`, or any of the values listed after it, and is required then.
|
|
289
|
+
|
|
190
290
|
`rsc:install` does not set up Tailwind or shadcn, so the `shadcn` theme comes out
|
|
191
291
|
unstyled until the app has both.
|
|
192
292
|
|
|
@@ -227,7 +327,9 @@ The form's fields are the struct's, in its order, and a field is required unless
|
|
|
227
327
|
its `json` tag says `omitempty`. A `validate` tag, in go-playground/validator's
|
|
228
328
|
spelling, adds what the browser can check: `required`, `omitempty`, `email`,
|
|
229
329
|
`url`, `min`, `max`, `len`, `gte`, `lte`, `oneof` (a select) and
|
|
230
|
-
`datetime=2006-01-02`.
|
|
330
|
+
`datetime=2006-01-02`. `required_if=Topic support` is read as `visible`: the
|
|
331
|
+
field shows while `topic` is `support`, and is required then. Only one field and
|
|
332
|
+
one value - several pairs must all hold, which a form cannot show as one.
|
|
231
333
|
|
|
232
334
|
```go
|
|
233
335
|
type ContactInput struct {
|
|
@@ -244,7 +346,7 @@ need not come from a browser.
|
|
|
244
346
|
|
|
245
347
|
### On a kept page
|
|
246
348
|
|
|
247
|
-
A
|
|
349
|
+
A blueprint's form can sit in an [ISR](/guides/isr) page. The page is kept for
|
|
248
350
|
everyone, and the post is the visitor's own: it needs no token, because the
|
|
249
351
|
engine and Laravel 13 accept a same-origin post by its `Sec-Fetch-Site` header.
|
|
250
352
|
The call to the backend runs in that post, so it carries the visitor's cookie,
|
|
@@ -275,11 +377,12 @@ The trap is named `homepage`, so a form cannot have a field of that name.
|
|
|
275
377
|
|
|
276
378
|
## Drawing it yourself
|
|
277
379
|
|
|
278
|
-
The theme's part is one component, `
|
|
380
|
+
The theme's part is one component, `BlueprintForm`, typed `FormsTheme` from
|
|
279
381
|
`@rsc-kit/press/forms`. It is given the bound `action`, the `fields`, the
|
|
280
|
-
`submit` words, `done`, and the `honeypot` field's
|
|
281
|
-
|
|
382
|
+
starting `values`, the `submit` words, `done`, and the `honeypot` field's
|
|
383
|
+
name to render hidden - absent when the blueprint turned it off. Replace it
|
|
384
|
+
as you would a panel page:
|
|
282
385
|
|
|
283
386
|
```ts
|
|
284
|
-
theme: { ...shadcn,
|
|
387
|
+
theme: { ...shadcn, BlueprintForm: MyForm },
|
|
285
388
|
```
|
package/guides/go.md
CHANGED
|
@@ -331,6 +331,14 @@ arguments you bound. An action scoped to a team, `func(ctx, team string, in NewA
|
|
|
331
331
|
is `<Form action={appsCreate.bind(null, team)}>`. Numbers and booleans are
|
|
332
332
|
coerced by the struct's types and a repeated field is a slice.
|
|
333
333
|
|
|
334
|
+
An admin resource takes the generated actions in place of a schema, its create
|
|
335
|
+
`func(ctx, in ProductInput)` and its update the record's key after the struct,
|
|
336
|
+
`func(ctx, in ProductInput, id string)`. See
|
|
337
|
+
[the admin guide](/guides/admin#the-backends-actions-as-the-form). A list too
|
|
338
|
+
big to count pages by cursor: answer a struct tagged `json:"rows"`,
|
|
339
|
+
`json:"next"` and `json:"prev"`, and read the cursor from the query's `cursor`
|
|
340
|
+
([pages by count, or by cursor](/guides/admin#pages-by-count-or-by-cursor)).
|
|
341
|
+
|
|
334
342
|
`Revalidate` names a [section](/guides/sections) or `page`, and the answer to
|
|
335
343
|
the action carries it re-rendered rather than the browser being told to ask
|
|
336
344
|
again.
|
|
@@ -458,13 +466,13 @@ post need not come from a browser.
|
|
|
458
466
|
`bunx rsc-kit make:form contactSend` writes the form around it:
|
|
459
467
|
|
|
460
468
|
```ts title="src/forms/contact.ts"
|
|
461
|
-
import {
|
|
469
|
+
import { defineBlueprint } from '@rsc-kit/press/forms'
|
|
462
470
|
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
463
471
|
import { contactSend } from '../server-actions.generated'
|
|
464
472
|
|
|
465
|
-
export const contact =
|
|
473
|
+
export const contact = defineBlueprint({
|
|
466
474
|
name: 'contact',
|
|
467
|
-
|
|
475
|
+
actions: { create: contactSend },
|
|
468
476
|
fields: { message: { type: 'textarea' } },
|
|
469
477
|
theme: shadcn,
|
|
470
478
|
done: 'Thanks - we will be in touch.',
|
|
@@ -482,8 +490,9 @@ export default function ContactPage() {
|
|
|
482
490
|
```
|
|
483
491
|
|
|
484
492
|
`oneof` draws a select, and a field is required unless its `json` tag says
|
|
485
|
-
`omitempty`.
|
|
486
|
-
|
|
493
|
+
`omitempty`. `required_if=Topic support` shows the field only while `topic` is
|
|
494
|
+
`support`. [Blueprints](/guides/blueprints#go) has every tag that is read.
|
|
495
|
+
It needs `@rsc-kit/press` 0.30.52 and `github.com/rsc-kit/go` v0.16.0.
|
|
487
496
|
|
|
488
497
|
## Production
|
|
489
498
|
|
package/guides/index.json
CHANGED
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"title": "BAP vs Inertia",
|
|
30
30
|
"description": "Two ways to put React in front of Laravel, and when each is the right one."
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
"slug": "blueprints",
|
|
34
|
+
"title": "Blueprints",
|
|
35
|
+
"description": "A form defined once - fields, checks and saves - and drawn anywhere it is needed - a contact page, an edit page, an admin panel - from a Standard Schema or a backend's own actions."
|
|
36
|
+
},
|
|
32
37
|
{
|
|
33
38
|
"slug": "bun",
|
|
34
39
|
"title": "Running on Bun",
|
|
@@ -189,11 +194,6 @@
|
|
|
189
194
|
"title": "Partial prerendering",
|
|
190
195
|
"description": "Storing what every visitor sees the same, and rendering the rest per request."
|
|
191
196
|
},
|
|
192
|
-
{
|
|
193
|
-
"slug": "public-forms",
|
|
194
|
-
"title": "Public forms",
|
|
195
|
-
"description": "A contact form, a sign-up, a survey - drawn from a Standard Schema or a backend function, checked in the browser and on the server, sent to any backend."
|
|
196
|
-
},
|
|
197
197
|
{
|
|
198
198
|
"slug": "pwa",
|
|
199
199
|
"title": "Progressive web apps",
|
package/guides/isr.md
CHANGED
|
@@ -147,7 +147,7 @@ and no `Authorization`, and a cookie the backend sets is dropped. In Laravel,
|
|
|
147
147
|
goes to every visitor. A page that shows who is signed in is not one to keep.
|
|
148
148
|
|
|
149
149
|
A form in a kept page still works: a same-origin post needs no token. See
|
|
150
|
-
[
|
|
150
|
+
[blueprints](/guides/blueprints#on-a-kept-page).
|
|
151
151
|
|
|
152
152
|
## On several instances
|
|
153
153
|
|
package/guides/laravel.md
CHANGED
|
@@ -483,13 +483,13 @@ class Contact
|
|
|
483
483
|
`bunx rsc-kit make:form contactSend` writes the form around it:
|
|
484
484
|
|
|
485
485
|
```ts title="resources/js/forms/contact.ts"
|
|
486
|
-
import {
|
|
486
|
+
import { defineBlueprint } from '@rsc-kit/press/forms'
|
|
487
487
|
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
488
488
|
import { contactSend } from '../server-actions.generated'
|
|
489
489
|
|
|
490
|
-
export const contact =
|
|
490
|
+
export const contact = defineBlueprint({
|
|
491
491
|
name: 'contact',
|
|
492
|
-
|
|
492
|
+
actions: { create: contactSend },
|
|
493
493
|
fields: { message: { type: 'textarea' } },
|
|
494
494
|
theme: shadcn,
|
|
495
495
|
done: 'Thanks - we will be in touch.',
|
|
@@ -513,12 +513,25 @@ its 422 shows under the field, with what was typed kept. A field named in
|
|
|
513
513
|
`fields` that `rules()` does not have fails the typecheck.
|
|
514
514
|
|
|
515
515
|
A file field, or a check in TypeScript first, needs a schema and a `handle`
|
|
516
|
-
instead. [
|
|
516
|
+
instead. [Blueprints](/guides/blueprints#laravel) has the rest. `action`
|
|
517
517
|
taking the generated action, and `rsc-kit make:form`, need `@rsc-kit/press`
|
|
518
518
|
0.30.49, and the browser's checks from `rules()` need
|
|
519
519
|
`rsc-kit/laravel` 0.17; an older package draws the fields with `required` and
|
|
520
520
|
their types only.
|
|
521
521
|
|
|
522
|
+
An admin resource takes the same generated actions in place of a schema, and
|
|
523
|
+
its update takes the record's key after the request:
|
|
524
|
+
`update(UpdateProductRequest $request, string $product)`. The key is the
|
|
525
|
+
request's route parameter under that name, so
|
|
526
|
+
`Rule::unique('products')->ignore($this->route('product'))` keeps the record's
|
|
527
|
+
own value. [The admin guide](/guides/admin#the-backends-actions-as-the-form)
|
|
528
|
+
has it; it needs `@rsc-kit/press` 0.30.51 and `rsc-kit/laravel` 0.19.
|
|
529
|
+
|
|
530
|
+
A rule `required_if:topic,support` shows its field only while `topic` is
|
|
531
|
+
`support`, and requires it then; it needs `@rsc-kit/press` 0.30.52 and
|
|
532
|
+
`rsc-kit/laravel` 0.20. [Blueprints](/guides/blueprints#fields-that-depend-on-others)
|
|
533
|
+
has the rest.
|
|
534
|
+
|
|
522
535
|
## Route middleware
|
|
523
536
|
|
|
524
537
|
The renderer owns the route table, but Laravel still decides whether a route
|
package/guides/pages.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
`@rsc-kit/press/pages` lets an editor build pages in the [admin panel](/guides/admin/)
|
|
6
6
|
from blocks the app defines - a hero, a feature grid, a call to action, a
|
|
7
|
-
[
|
|
7
|
+
[blueprint's form](/guides/blueprints/) - and serves them from one catch-all
|
|
8
8
|
route. The blocks are the app's code and look like the rest of the site; what
|
|
9
9
|
is on a page, and in what order, is the editor's.
|
|
10
10
|
|
|
@@ -353,7 +353,7 @@ are `optional`, a variadic `rest`, and its `result`, each a JSON Schema;
|
|
|
353
353
|
```
|
|
354
354
|
|
|
355
355
|
A function taking one object with `properties` can be [a form with no
|
|
356
|
-
schema](/guides/
|
|
356
|
+
schema](/guides/blueprints#a-laravel-or-go-backend), read from these same
|
|
357
357
|
types: `required`, `format` (`email`, `date`), `minLength`, `maxLength`,
|
|
358
358
|
`minimum`, `maximum` and `enum` become its fields and browser checks. The
|
|
359
359
|
properties are drawn in the order written. If your language's JSON sorts a map,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/mcp",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.52",
|
|
4
4
|
"description": "An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
37
|
-
"create-rsc-kit": "^0.30.
|
|
37
|
+
"create-rsc-kit": "^0.30.52",
|
|
38
38
|
"zod": "^3.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|