@valbuild/next 0.108.5 → 0.109.0
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/README.md +55 -22
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -522,42 +522,53 @@ export default async function MyPage({ params }: { params:
|
|
|
522
522
|
|
|
523
523
|
### Previews
|
|
524
524
|
|
|
525
|
-
A **preview** is
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
`image`.
|
|
525
|
+
A **preview** is how a VALUE is shown wherever the Val editor shows a preview of
|
|
526
|
+
it rather than opening it: a row in a list, an entry in a `keyOf` dropdown, a
|
|
527
|
+
search hit, a reference. Declare one with `.preview()` on the schema of the value
|
|
528
|
+
being previewed, and return a `title`, and optionally a `subtitle` and an `image`.
|
|
529
529
|
|
|
530
530
|
#### Example
|
|
531
531
|
|
|
532
532
|
```ts
|
|
533
|
-
const
|
|
534
|
-
.
|
|
535
|
-
.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
// Show the image from the record
|
|
540
|
-
image: val.image,
|
|
541
|
-
}));
|
|
533
|
+
const pageSchema = s
|
|
534
|
+
.object({ title: s.string(), image: s.image() })
|
|
535
|
+
.preview(({ val }) => ({ title: val.title, image: val.image }));
|
|
536
|
+
|
|
537
|
+
// Every row of this record previews with the closure above
|
|
538
|
+
const pagesSchema = s.record(pageSchema).router(nextAppRouter);
|
|
542
539
|
```
|
|
543
540
|
|
|
544
|
-
|
|
541
|
+
The container reifies its rows by running each ITEM's closure, so an array works
|
|
542
|
+
the same way:
|
|
545
543
|
|
|
546
544
|
```ts
|
|
547
|
-
const sectionsSchema = s
|
|
548
|
-
|
|
549
|
-
|
|
545
|
+
const sectionsSchema = s.array(
|
|
546
|
+
s
|
|
547
|
+
.object({ heading: s.string(), body: s.string() })
|
|
548
|
+
.preview(({ val }) => ({ title: val.heading, subtitle: val.body })),
|
|
549
|
+
);
|
|
550
550
|
```
|
|
551
551
|
|
|
552
|
+
A tagged union with no preview of its own previews as the VARIANT the value
|
|
553
|
+
takes, so a page-builder list previews each block by its own block type.
|
|
554
|
+
|
|
552
555
|
Your function is run on demand, for the rows actually on screen, so it is fine
|
|
553
|
-
for it to read into the
|
|
556
|
+
for it to read into the value's content.
|
|
557
|
+
|
|
558
|
+
> **Changed in the release that added `.render({ as: "inline" })`.** A
|
|
559
|
+
> `.preview()` on `s.array(...)` / `s.record(...)` used to describe the
|
|
560
|
+
> container's ROWS; it now describes the container ITSELF as a value, for when
|
|
561
|
+
> it is someone else's item. Move the closure onto the item schema. The record
|
|
562
|
+
> closure no longer receives `key` — derive the title from `val`. And
|
|
563
|
+
> `.jsonValues()` must come before `.preview(...)`, like `.validate(...)`.
|
|
554
564
|
|
|
555
565
|
### Field rendering
|
|
556
566
|
|
|
557
|
-
A **render** is how ONE field is laid out in the editor
|
|
558
|
-
configuration rather than a function, and it is a
|
|
559
|
-
preview: a
|
|
560
|
-
|
|
567
|
+
A **render** is how ONE field is laid out in the editor when you are LOOKING at
|
|
568
|
+
that field. It is static configuration rather than a function, and it is a
|
|
569
|
+
different thing from a preview: a render is the field's own layout, a preview is
|
|
570
|
+
how the value shows where it is navigable to. A schema can carry both, and a
|
|
571
|
+
second `.render(...)` replaces the first rather than merging with it.
|
|
561
572
|
|
|
562
573
|
```ts
|
|
563
574
|
const articleSchema = s.object({
|
|
@@ -573,6 +584,28 @@ const articleSchema = s.object({
|
|
|
573
584
|
`css`, `markdown`, `python`, `sql` and others; see `CodeLanguage` in
|
|
574
585
|
`@valbuild/core` for the full list.
|
|
575
586
|
|
|
587
|
+
#### Editing list items in place
|
|
588
|
+
|
|
589
|
+
Every field takes `.render({ as: "inline" })`. On the ITEM of an array or record
|
|
590
|
+
it means: edit the item right there in the (sortable) list row, instead of
|
|
591
|
+
showing a preview row that navigates into it. This is what a page-builder list is
|
|
592
|
+
made of.
|
|
593
|
+
|
|
594
|
+
```ts
|
|
595
|
+
const sectionsSchema = s.array(
|
|
596
|
+
s.object({ title: s.string(), body: s.richtext() }).render({ as: "inline" }),
|
|
597
|
+
);
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
> **Breaking.** Strings in arrays are no longer inlined implicitly.
|
|
601
|
+
> `s.array(s.string())` now renders preview rows and its items are navigation
|
|
602
|
+
> stops, like every other item type. Add `.render({ as: "inline" })` to the
|
|
603
|
+
> string schema for the old behavior:
|
|
604
|
+
>
|
|
605
|
+
> ```ts
|
|
606
|
+
> s.array(s.string().render({ as: "inline" }));
|
|
607
|
+
> ```
|
|
608
|
+
|
|
576
609
|
## RichText
|
|
577
610
|
|
|
578
611
|
<details>
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"next",
|
|
13
13
|
"react"
|
|
14
14
|
],
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.109.0",
|
|
16
16
|
"main": "dist/valbuild-next.cjs.js",
|
|
17
17
|
"module": "dist/valbuild-next.esm.js",
|
|
18
18
|
"exports": {
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"client-only": "^0.0.1",
|
|
49
49
|
"server-only": "^0.0.1",
|
|
50
|
-
"@valbuild/
|
|
51
|
-
"@valbuild/
|
|
52
|
-
"@valbuild/
|
|
53
|
-
"@valbuild/
|
|
54
|
-
"@valbuild/
|
|
55
|
-
"@valbuild/
|
|
50
|
+
"@valbuild/core": "0.109.0",
|
|
51
|
+
"@valbuild/react": "0.109.0",
|
|
52
|
+
"@valbuild/language-server": "0.109.0",
|
|
53
|
+
"@valbuild/server": "0.109.0",
|
|
54
|
+
"@valbuild/shared": "0.109.0",
|
|
55
|
+
"@valbuild/ui": "0.109.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@testing-library/react": "^16.3.3",
|