@valbuild/next 0.103.1 → 0.105.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 +43 -15
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -520,11 +520,12 @@ export default async function MyPage({ params }: { params:
|
|
|
520
520
|
}
|
|
521
521
|
```
|
|
522
522
|
|
|
523
|
-
###
|
|
523
|
+
### Previews
|
|
524
524
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
525
|
+
A **preview** is what the Val editor shows for each ITEM of a container — the row
|
|
526
|
+
you see in a list of records, or of array items. Declare one with `.preview()` on
|
|
527
|
+
a `record` or an `array`, and return a `title`, and optionally a `subtitle` and an
|
|
528
|
+
`image`.
|
|
528
529
|
|
|
529
530
|
#### Example
|
|
530
531
|
|
|
@@ -532,19 +533,46 @@ The only currently supported layout is `list`, which provides a customizable lis
|
|
|
532
533
|
const pagesSchema = s
|
|
533
534
|
.record(s.object({ title: s.string(), image: s.image() }))
|
|
534
535
|
.router(nextAppRouter)
|
|
535
|
-
.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
536
|
+
.preview(({ key, val }) => ({
|
|
537
|
+
// Capitalize the first letter of the key for display
|
|
538
|
+
title: key?.[0]?.toUpperCase() + key?.slice(1),
|
|
539
|
+
// Show the image from the record
|
|
540
|
+
image: val.image,
|
|
541
|
+
}));
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
An array's preview gets the item alone, since there is no key:
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
const sectionsSchema = s
|
|
548
|
+
.array(s.object({ heading: s.string(), body: s.string() }))
|
|
549
|
+
.preview(({ val }) => ({ title: val.heading, subtitle: val.body }));
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
Your function is run on demand, for the rows actually on screen, so it is fine
|
|
553
|
+
for it to read into the item's content.
|
|
554
|
+
|
|
555
|
+
### Field rendering
|
|
556
|
+
|
|
557
|
+
A **render** is how ONE field is laid out in the editor. It is static
|
|
558
|
+
configuration rather than a function, and it is a different thing from a
|
|
559
|
+
preview: a preview describes a container's items, a render describes a single
|
|
560
|
+
field.
|
|
561
|
+
|
|
562
|
+
```ts
|
|
563
|
+
const articleSchema = s.object({
|
|
564
|
+
title: s.string(),
|
|
565
|
+
// A multi-line box instead of a single-line input
|
|
566
|
+
summary: s.string().render({ as: "textarea" }),
|
|
567
|
+
// A syntax-highlighted code editor
|
|
568
|
+
snippet: s.string().render({ as: "code", language: "typescript" }),
|
|
569
|
+
});
|
|
546
570
|
```
|
|
547
571
|
|
|
572
|
+
`as: "code"` takes a `language` — `typescript`, `javascript`, `json`, `html`,
|
|
573
|
+
`css`, `markdown`, `python`, `sql` and others; see `CodeLanguage` in
|
|
574
|
+
`@valbuild/core` for the full list.
|
|
575
|
+
|
|
548
576
|
## RichText
|
|
549
577
|
|
|
550
578
|
<details>
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"next",
|
|
13
13
|
"react"
|
|
14
14
|
],
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.105.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/core": "0.
|
|
51
|
-
"@valbuild/language-server": "0.
|
|
52
|
-
"@valbuild/react": "0.
|
|
53
|
-
"@valbuild/server": "0.
|
|
54
|
-
"@valbuild/shared": "0.
|
|
55
|
-
"@valbuild/ui": "0.
|
|
50
|
+
"@valbuild/core": "0.105.0",
|
|
51
|
+
"@valbuild/language-server": "0.105.0",
|
|
52
|
+
"@valbuild/react": "0.105.0",
|
|
53
|
+
"@valbuild/server": "0.105.0",
|
|
54
|
+
"@valbuild/shared": "0.105.0",
|
|
55
|
+
"@valbuild/ui": "0.105.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@testing-library/react": "^16.3.2",
|