@valbuild/next 0.85.1 → 0.86.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.
Files changed (2) hide show
  1. package/README.md +86 -4
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <p align="center">
3
- <a href="https://app.val.build">
3
+ <a href="https://admin.val.build">
4
4
  <svg width="100" height="100" viewBox="0 0 944 944" fill="none" xmlns="http://www.w3.org/2000/svg">
5
5
  <circle cx="472" cy="472" r="472" fill="#1D1C28"/>
6
6
  <g filter="url(#filter0_d_14_601)">
@@ -196,7 +196,7 @@ export default async function Home() {
196
196
 
197
197
  # Remote Mode
198
198
 
199
- Enable remote mode to allow editors to update content online (outside of local development) by creating a project at [app.val.build](https://app.val.build).
199
+ Enable remote mode to allow editors to update content online (outside of local development) by creating a project at [admin.val.build](https://admin.val.build).
200
200
 
201
201
  **NOTE**: Your content remains yours. Hosting content from your repository does not require a subscription. However, to edit content online, a subscription is needed — unless your project is a public repository or qualifies for the free tier. Visit the [pricing page](https://val.build/pricing) for details.
202
202
 
@@ -204,11 +204,11 @@ Enable remote mode to allow editors to update content online (outside of local d
204
204
 
205
205
  ## Remote Mode Configuration
206
206
 
207
- Once your project is set up in [app.val.build](https://app.val.build), configure your application to use it by setting the following:
207
+ Once your project is set up in [admin.val.build](https://admin.val.build), configure your application to use it by setting the following:
208
208
 
209
209
  ### Environment Variables
210
210
 
211
- - **`VAL_API_KEY`**: This is the API key used to authenticate server side API requests. You can find it under Settings in your project on [app.val.build](https://app.val.build).
211
+ - **`VAL_API_KEY`**: This is the API key used to authenticate server side API requests. You can find it under Settings in your project on [admin.val.build](https://admin.val.build).
212
212
  - **`VAL_SECRET`**: In addition to the VAL_API_KEY, you need to generate a random secret to secure communication between the UX client and your Next.js application. You can use any random string for this, but if you have openssl installed you can run the following command: `openssl rand -hex 16`
213
213
 
214
214
  ### `val.config` Properties
@@ -363,6 +363,73 @@ s.object({
363
363
  });
364
364
  ```
365
365
 
366
+ #### Page router
367
+
368
+ You can configure Val to track your page structure and display content as navigable web pages in the editor interface.
369
+
370
+ For editors, this creates an intuitive page-based editing experience where they can navigate through your site structure and edit content directly within the context of each page.
371
+
372
+ You can use the `.router` method on `record` to achieve this.
373
+
374
+ When using the `.router` with the `nextAppRouter`, it will automatically generate routes based on your record keys and integrate seamlessly with Next.js App Router conventions.
375
+
376
+ #### Example:
377
+
378
+ ```ts
379
+ import { s, c, nextAppRouter } from "../val.config";
380
+
381
+ const pageSchema = s.object({ title: s.string() });
382
+ const pagesSchema = s.record(pageSchema).router(nextAppRouter);
383
+
384
+ // NOTE: to use router(nextAppRouter) - the module must be a sibling of the page.tsx. In other words it must with page.val.ts or page.val.js
385
+ export default c.define("/app/[slug]/page.val.ts", pageSchema, {
386
+ "/test-page": {
387
+ // This is the full pathname of the page - it must match the pattern of the Next JS route of the page.tsx you are consuming this from
388
+ title: "Test page",
389
+ },
390
+ });
391
+ ```
392
+
393
+ To consume a page route from a NextJS "page component", it is recommended you use `fetchValRoute` or `useValRoute`.
394
+
395
+ NOTE: to be refactor proof (i.e. not break when changing the route), you should always provide the params of the NextJS page component.
396
+
397
+ #### Example fetchValRoute
398
+
399
+ ```ts
400
+ export default async function MyPage({ params }: { params:
401
+ Promise<{ slug: string }> // use params: Promise<unknown> if this page route has no params
402
+ }) {
403
+ const page = await fetchValRoute(pageVal, params)
404
+ return <MyPageComponent {...page}>
405
+ }
406
+ ```
407
+
408
+ ### Custom render
409
+
410
+ You can customize how records are displayed in the Val editor interface by using the `.render` method on `record`. This allows you to control how individual record items appear in the editor's preview.
411
+
412
+ The only currently supported layout is `list`, which provides a customizable list view for record previews.
413
+
414
+ #### Example
415
+
416
+ ```ts
417
+ const pagesSchema = s
418
+ .record(s.object({ title: s.string(), image: s.image() }))
419
+ .router(nextAppRouter)
420
+ .render({
421
+ layout: "list", // Use list layout for record preview
422
+ select({ key, val }) {
423
+ return {
424
+ // Capitalize the first letter of the key for display
425
+ title: key?.[0]?.toUpperCase() + key?.slice(1),
426
+ // Show the image from the record
427
+ image: val.image,
428
+ };
429
+ },
430
+ });
431
+ ```
432
+
366
433
  ## RichText
367
434
 
368
435
  <details>
@@ -706,3 +773,18 @@ const authors = useVal(otherVal); // s.record(s.object({ name: s.string() }))
706
773
 
707
774
  const nameOfAuthor = authors[articleVal.author].name;
708
775
  ```
776
+
777
+ # Custom validation
778
+
779
+ All schema can use the `validate` method to show custom validation errors to editors.
780
+
781
+ ## Example
782
+
783
+ ```ts
784
+ s.string().validate((val) => {
785
+ if (val.startsWith("something")) {
786
+ return "Cannot have something in this string";
787
+ }
788
+ return false; // no validation error
789
+ });
790
+ ```
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "next",
9
9
  "react"
10
10
  ],
11
- "version": "0.85.1",
11
+ "version": "0.86.0",
12
12
  "scripts": {
13
13
  "typecheck": "tsc --noEmit",
14
14
  "test": "jest"
@@ -45,11 +45,11 @@
45
45
  "exports": true
46
46
  },
47
47
  "dependencies": {
48
- "@valbuild/core": "~0.85.1",
49
- "@valbuild/react": "~0.85.1",
50
- "@valbuild/server": "~0.85.1",
51
- "@valbuild/shared": "~0.85.1",
52
- "@valbuild/ui": "~0.85.1",
48
+ "@valbuild/core": "~0.86.0",
49
+ "@valbuild/react": "~0.86.0",
50
+ "@valbuild/server": "~0.86.0",
51
+ "@valbuild/shared": "~0.86.0",
52
+ "@valbuild/ui": "~0.86.0",
53
53
  "client-only": "^0.0.1",
54
54
  "server-only": "^0.0.1"
55
55
  },