@valbuild/next 0.150.22 → 0.151.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 (77) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/README.md +82 -1
  3. package/client/dist/valbuild-next-client.cjs.dev.js +123 -256
  4. package/client/dist/valbuild-next-client.cjs.prod.js +123 -256
  5. package/client/dist/valbuild-next-client.esm.js +122 -255
  6. package/dist/{ValApp-a88a9ded.esm.js → ValApp-69cd599c.esm.js} +3 -3
  7. package/dist/{ValApp-c718d1a6.cjs.dev.js → ValApp-826dca6c.cjs.dev.js} +3 -3
  8. package/dist/ValApp-866089f6.cjs.js +7 -0
  9. package/dist/{ValApp-6c3da222.cjs.prod.js → ValApp-866089f6.cjs.prod.js} +3 -3
  10. package/dist/{ValCanvasBridge-9d221d32.cjs.dev.js → ValCanvasBridge-4b81f653.cjs.dev.js} +46 -13
  11. package/dist/ValCanvasBridge-6f568f1d.cjs.js +7 -0
  12. package/dist/{ValCanvasBridge-134c3ae1.cjs.prod.js → ValCanvasBridge-6f568f1d.cjs.prod.js} +46 -13
  13. package/dist/{ValCanvasBridge-4a5ef73c.esm.js → ValCanvasBridge-badc186b.esm.js} +46 -13
  14. package/dist/ValNextProvider-41d622a7.cjs.js +7 -0
  15. package/dist/{ValNextProvider-35d0b521.cjs.prod.js → ValNextProvider-41d622a7.cjs.prod.js} +124 -234
  16. package/dist/{ValNextProvider-a85a1d33.cjs.dev.js → ValNextProvider-4b9bcfc0.cjs.dev.js} +124 -234
  17. package/dist/{ValNextProvider-df6f351e.esm.js → ValNextProvider-745ed99e.esm.js} +124 -234
  18. package/dist/ValOverlayContext-0c29b6a7.cjs.dev.js +51 -0
  19. package/dist/ValOverlayContext-0f51d111.cjs.js +7 -0
  20. package/dist/ValOverlayContext-0f51d111.cjs.prod.js +51 -0
  21. package/dist/ValOverlayContext-178db68e.esm.js +37 -0
  22. package/dist/ValVideo-02f43a7c.cjs.js +7 -0
  23. package/dist/{ValVideo-dcd2b9f8.cjs.prod.js → ValVideo-02f43a7c.cjs.prod.js} +1 -2
  24. package/dist/{ValVideo-6e410ad8.cjs.dev.js → ValVideo-15e5c4fa.cjs.dev.js} +1 -2
  25. package/dist/{ValVideo-d377f06e.esm.js → ValVideo-8acf31b6.esm.js} +1 -2
  26. package/dist/{createForOfIteratorHelper-d4afcad8.cjs.prod.js → createForOfIteratorHelper-8459fbc7.cjs.prod.js} +1 -1
  27. package/dist/{createForOfIteratorHelper-5758a730.esm.js → createForOfIteratorHelper-9209e9dd.esm.js} +1 -1
  28. package/dist/{createForOfIteratorHelper-0445603c.cjs.dev.js → createForOfIteratorHelper-9c6aa3c7.cjs.dev.js} +1 -1
  29. package/dist/declarations/src/ValProvider.d.ts +1 -0
  30. package/dist/declarations/src/client/initValClient.d.ts +25 -3
  31. package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
  32. package/dist/declarations/src/rsc/index.d.ts +1 -0
  33. package/dist/declarations/src/rsc/initValRsc.d.ts +56 -118
  34. package/dist/declarations/src/server/initValServer.d.ts +2 -1
  35. package/dist/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
  36. package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
  37. package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
  38. package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
  39. package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
  40. package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
  41. package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
  42. package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
  43. package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
  44. package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
  45. package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
  46. package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
  47. package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
  48. package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
  49. package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
  50. package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
  51. package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
  52. package/dist/useHydrated-afcdbb66.esm.js +26 -0
  53. package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
  54. package/dist/valbuild-next.cjs.dev.js +7 -8
  55. package/dist/valbuild-next.cjs.prod.js +7 -8
  56. package/dist/valbuild-next.esm.js +7 -8
  57. package/dist/{version-18c11a6d.cjs.prod.js → version-114c45b6.cjs.prod.js} +1 -1
  58. package/dist/{version-70b7333d.cjs.dev.js → version-cc1bc4e5.cjs.dev.js} +1 -1
  59. package/dist/{version-a2218191.esm.js → version-d8f64e54.esm.js} +1 -1
  60. package/package.json +8 -8
  61. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
  62. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
  63. package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
  64. package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
  65. package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
  66. package/server/dist/valbuild-next-server.esm.js +4 -5
  67. package/dist/ValApp-6c3da222.cjs.js +0 -7
  68. package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
  69. package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
  70. package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
  71. package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
  72. package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
  73. package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
  74. package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
  75. package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
  76. package/dist/defineProperty-cca5affa.esm.js +0 -26
  77. package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
@@ -3,13 +3,12 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var objectSpread2 = require('./objectSpread2-58024783.cjs.dev.js');
6
+ var objectSpread2 = require('./objectSpread2-58726b14.cjs.dev.js');
7
7
  var objectWithoutProperties = require('./objectWithoutProperties-8f93848f.cjs.dev.js');
8
8
  var core = require('@valbuild/core');
9
9
  var React = require('react');
10
10
  var stega = require('@valbuild/react/stega');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
- require('./defineProperty-f90345d7.cjs.dev.js');
13
12
 
14
13
  var _excluded = ["src", "hls", "disableHotspot", "disableCaptions", "style", "width", "height"];
15
14
  /**
@@ -1,11 +1,10 @@
1
1
  'use client';
2
- import { _ as _objectSpread2 } from './objectSpread2-60d1bd93.esm.js';
2
+ import { _ as _objectSpread2 } from './objectSpread2-f1f0d77a.esm.js';
3
3
  import { _ as _objectWithoutProperties, d as decodeValPathsOfString } from './objectWithoutProperties-2daec22c.esm.js';
4
4
  import { Internal } from '@valbuild/core';
5
5
  import { useRef, useEffect } from 'react';
6
6
  import { raw } from '@valbuild/react/stega';
7
7
  import { jsx } from 'react/jsx-runtime';
8
- import './defineProperty-cca5affa.esm.js';
9
8
 
10
9
  var _excluded = ["src", "hls", "disableHotspot", "disableCaptions", "style", "width", "height"];
11
10
  /**
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var unsupportedIterableToArray = require('./unsupportedIterableToArray-0d2087a2.cjs.prod.js');
3
+ var unsupportedIterableToArray = require('./unsupportedIterableToArray-1aadf9fb.cjs.prod.js');
4
4
 
5
5
  function _createForOfIteratorHelper(r, e) {
6
6
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -1,4 +1,4 @@
1
- import { _ as _unsupportedIterableToArray } from './unsupportedIterableToArray-5baabfdc.esm.js';
1
+ import { _ as _unsupportedIterableToArray } from './unsupportedIterableToArray-f57eb659.esm.js';
2
2
 
3
3
  function _createForOfIteratorHelper(r, e) {
4
4
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var unsupportedIterableToArray = require('./unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
3
+ var unsupportedIterableToArray = require('./unsupportedIterableToArray-20a9209f.cjs.dev.js');
4
4
 
5
5
  function _createForOfIteratorHelper(r, e) {
6
6
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -3,4 +3,5 @@ export declare const ValProvider: (props: {
3
3
  config: import("@valbuild/core").ValConfig;
4
4
  disableRefresh?: boolean;
5
5
  suspend?: boolean;
6
+ draft?: import("@valbuild/react/internal").ValDraft | null;
6
7
  }) => import("react").JSX.Element;
@@ -1,6 +1,24 @@
1
- import { type ResolvableModule, SelectorSource } from "@valbuild/core";
1
+ import { type ResolvableModule, SelectorSource, type ValModule } from "@valbuild/core";
2
2
  import { type JsonEntryContentOf, type Resolvable, type ResolvedVal, type RouteValueOf } from "@valbuild/react/stega";
3
+ import { type ReadEnv, type Resolution, type ValExternalStore } from "@valbuild/react/internal";
3
4
  import { ValConfig } from "@valbuild/core";
5
+ /** What the provider tells the hooks: `ValOverlayContext`'s value. */
6
+ export type PageReadState = {
7
+ store?: ValExternalStore;
8
+ draftMode: boolean | null;
9
+ suspend: boolean;
10
+ draftModeReady?: Promise<void>;
11
+ draftSourcesSynced?: boolean;
12
+ };
13
+ /**
14
+ * Where this page's hooks read from, in order: what the Studio sent (the
15
+ * overlay, which starts from the server-read draft when the page has one),
16
+ * then -- added by every read -- the bundle. Edit tags in draft mode, unless
17
+ * `encode` says otherwise (see `useEncodesEditTags`). A plain function of the
18
+ * provider's state, as `@valbuild/tanstack`'s is (which the scenario world
19
+ * reads a page with).
20
+ */
21
+ export declare function pageReadEnv(state: PageReadState, encode?: boolean): ReadEnv;
4
22
  /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
5
23
  export type UseValType<T extends SelectorSource> = ResolvedVal<T>;
6
24
  declare function useValStega<T extends Resolvable>(selector: T): UseValType<T>;
@@ -11,10 +29,14 @@ declare function useValStega<T extends Resolvable>(selector: T): UseValType<T>;
11
29
  * inside a `<Suspense>` boundary.
12
30
  *
13
31
  * In draft mode it renders the editor's unpublished content, taken from the
14
- * overlay; in production — and whenever there is no draft view — it resolves the
15
- * entry's lazy import thunk from the local module.
32
+ * overlay; an entry the draft deleted is `undefined`, never the bundled one.
16
33
  */
17
34
  declare function useValKeyStega<T extends ResolvableModule>(selector: T, key: string): JsonEntryContentOf<T> | undefined;
35
+ /**
36
+ * {@link routeRead}, for a module (a view resolved). A plain function, so the
37
+ * scenario world (`scenarios/`) reads a route as the hook does.
38
+ */
39
+ export declare function moduleRouteRead<V>(valModule: ValModule<SelectorSource>, params: Record<string, string | string[]>, env: ReadEnv, settled?: ReadonlySet<Promise<void>>): Resolution<V | null>;
18
40
  declare function useValRouteStega<T extends ResolvableModule>(selector: T, params: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): RouteValueOf<T>;
19
41
  declare function useValRouteUrl<T extends ResolvableModule>(selector: T, params?: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): string | null;
20
42
  export declare function initValClient(config: ValConfig): {
@@ -15,6 +15,7 @@ export { type SelectorSource, type SelectorOf, GenericSelector, } from "@valbuil
15
15
  export { ValRichText } from "@valbuild/react/internal";
16
16
  export { type ValEncodedString, type File, type Image, type Video, type RichText, } from "@valbuild/react/stega";
17
17
  export { ValProvider } from "./ValProvider.js";
18
+ export type { ValDraft } from "@valbuild/react/internal";
18
19
  export { ValImage, type ValImageProps } from "./ValImage.js";
19
20
  export { ValVideo, type ValVideoProps } from "./ValVideo.js";
20
21
  export { ValApp } from "./ValApp.js";
@@ -1,2 +1,3 @@
1
1
  import "server-only";
2
2
  export { initValRsc } from "./initValRsc.js";
3
+ export type { ValDraft } from "@valbuild/react/internal";
@@ -1,134 +1,61 @@
1
1
  import { type JsonEntryContentOf, type Resolvable, type ResolvedVal, type RouteValueOf } from "@valbuild/react/stega";
2
+ import { type ValDraft } from "@valbuild/react/internal";
2
3
  import { ValConfig, ValModules, type ResolvableModule } from "@valbuild/core";
3
4
  import { cookies, draftMode, headers } from "next/headers";
4
- import { type RequestScopedMemo } from "@valbuild/shared/internal";
5
- import { ValServer } from "@valbuild/server";
5
+ import { type ValRuntime } from "@valbuild/server/internal";
6
6
  /**
7
- * The `modules` map every `fetchVal` in one render shares.
8
- *
9
- * Derived from the route's own response type rather than restated, so it cannot
10
- * drift from what `/sources/~` actually returns.
11
- */
12
- export type DraftSources = Extract<Awaited<ReturnType<ValServer["/sources/~"]["PUT"]>>, {
13
- status: 200;
14
- }>["json"]["modules"];
15
- /**
16
- * The slice of `ValServer` the draft-sources reader uses.
17
- *
18
- * Narrower than `ValServer` for the same reason `JsonEntryValServer` below is:
19
- * it says what the dependency IS, and it lets a test drive the reader with a
20
- * one-route fake instead of casting a partial object to the whole server type.
21
- */
22
- export type DraftSourcesValServer = Pick<ValServer, "/sources/~">;
23
- /** What the route readers need: the tree, plus the single-entry route. */
24
- export type RouteReaderValServer = Pick<ValServer, "/sources/~" | "/json">;
25
- /**
26
- * Where the reader gets its per-request memo box.
27
- *
28
- * Injected rather than reached for, so that "this reader needs a request to
29
- * scope its cache to" is part of its contract and a test can supply a scope it
30
- * controls — in jest, React's non-`react-server` build makes `cache` a
31
- * pass-through, so the real wiring memoises nothing there.
32
- */
33
- export type GetDraftSourcesScope = () => Promise<RequestScopedMemo<DraftSources | null> | null>;
34
- /**
35
- * A per-request memo box, from React's request memoisation.
36
- *
37
- * `cache()` is what makes this safe: in an RSC render React hands back the SAME
38
- * object for the length of one request and a fresh one for the next. Outside
39
- * that — a route handler, a test, the non-`react-server` build of React —
40
- * `cache` is a pass-through, so every call gets its own object, the memo misses,
41
- * and the reader does exactly what it did before. Ineffective, never shared.
42
- * See `memoizePerRequest`. `fetchVal` is an RSC API (`SET_RSC(true)` above, and
43
- * its own error messages say so), so the effective case is the normal one.
44
- *
45
- * Built PER `initValRsc` rather than once for the module, because the box is
46
- * only as specific as the `cache()` it came from: two Val servers in one
47
- * process sharing one would answer each other's reads within a request, and
48
- * they hold different content.
7
+ * What the readers read: this process's runtime for the app's `val.modules`
8
+ * (`createValRuntime`), the same one the API route's server is built on.
9
+ * Its head is the draft, read with the request's session.
49
10
  */
50
- export declare function createReactCacheScope(): GetDraftSourcesScope;
51
- export declare const initFetchValStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<DraftSourcesValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
52
- get(name: string): string | null;
53
- }>, getCookies: () => Promise<{
54
- get(name: string): {
55
- name: string;
56
- value: string;
57
- } | undefined;
58
- }>, getDraftSourcesScope: GetDraftSourcesScope) => <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
59
- declare const initFetchValRouteStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<RouteReaderValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
60
- get(name: string): string | null;
61
- }>, getCookies: () => Promise<{
62
- get(name: string): {
63
- name: string;
64
- value: string;
65
- } | undefined;
66
- }>, getDraftSourcesScope: GetDraftSourcesScope) => <T extends ResolvableModule>(selector: T, params: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<RouteValueOf<T>>;
67
- /**
68
- * Loads a single `.jsonValues()` entry's DRAFT content via the in-process
69
- * `/json` endpoint (which replays pending patches). Returns `undefined` when the
70
- * entry has no draft content to serve — the caller then falls back to the
71
- * locally-bundled committed content.
72
- */
73
- /**
74
- * What the draft state says about an entry.
75
- *
76
- * The three cases have to stay distinct: `absent` is an ANSWER — the entry is not
77
- * there in the draft state, e.g. a pending patch removed it — while `unavailable`
78
- * means we could not ask. Collapsing them into `undefined` is what made a
79
- * draft-deleted entry keep rendering its committed content: the caller could not
80
- * tell "it is gone" from "ask the committed source instead".
81
- */
82
- /**
83
- * The slice of `ValServer` the single-entry readers actually use. Narrower than
84
- * `ValServer` on purpose: it says what the dependency IS, and it lets a test
85
- * drive these readers with a one-route fake instead of casting a partial object
86
- * to the whole server type.
87
- */
88
- export type JsonEntryValServer = Pick<ValServer, "/json">;
89
- export type DraftJsonEntry = {
90
- status: "content";
91
- content: unknown;
92
- } | {
93
- status: "absent";
94
- } | {
95
- status: "unavailable";
11
+ export type ReaderRuntime = Promise<ValRuntime>;
12
+ /** What a reader needs from the app and the request. */
13
+ export type ReaderDeps = {
14
+ runtime: ReaderRuntime;
15
+ isEnabled: () => Promise<boolean>;
16
+ getHeaders: () => Promise<{
17
+ get(name: string): string | null;
18
+ }>;
19
+ getCookies: () => Promise<{
20
+ get(name: string): {
21
+ name: string;
22
+ value: string;
23
+ } | undefined;
24
+ }>;
96
25
  };
26
+ export declare const initFetchValStega: (deps: ReaderDeps) => <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
27
+ declare const initFetchValRouteStega: (deps: ReaderDeps) => <T extends ResolvableModule>(selector: T, params: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<RouteValueOf<T>>;
97
28
  /**
98
- * Picks the content a draft-aware single-entry read should render.
29
+ * Resolves ONE `.jsonValues()` entry by key, loading only that entry instead of
30
+ * the whole record — the runtime-scaling counterpart to the eager `fetchVal`.
31
+ *
32
+ * Production (Val disabled): the entry's lazy import from the bundle. One
33
+ * dynamic import, no server round-trip.
99
34
  *
100
- * The rule the two callers share: the draft state WINS when it has an answer —
101
- * including the answer "this entry is gone" — and the committed content is used
102
- * only when there is no draft answer to be had (Val disabled, or we could not
103
- * ask). Returning `undefined` means "render nothing"; both callers turn that into
104
- * a null/undefined result.
35
+ * Draft mode: the entry from the runtime's head, with the pending patches the
36
+ * draft holds for it, so uncommitted Studio edits show up; an entry the draft
37
+ * deleted is not there. An entry of a record no patch touched is the bundle's.
105
38
  */
106
- export declare function resolveDraftOrCommittedEntry(draft: DraftJsonEntry, loadCommitted: () => Promise<unknown | undefined>): Promise<unknown | undefined>;
39
+ export declare const initFetchValKeyStega: (deps: Omit<ReaderDeps, "getHeaders">) => <T extends ResolvableModule>(selector: T, key: string) => Promise<JsonEntryContentOf<T> | undefined>;
40
+ declare const initFetchValRouteUrl: (deps: ReaderDeps) => <T extends ResolvableModule>(selector: T, params?: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<string | null>;
107
41
  /**
108
- * Resolves ONE `.jsonValues()` entry by key, loading only that entry instead of
109
- * the whole record — the runtime-scaling counterpart to the eager `fetchVal`.
42
+ * The draft a page in this request should start from, or `null` for none:
43
+ * what `<ValProvider draft>` takes. See `ValDraft`.
110
44
  *
111
- * Production (Val disabled): resolves the entry's lazy import thunk from the
112
- * locally-bundled module. One dynamic import, no server round-trip.
45
+ * `null` -- and no read at all -- unless the request is in draft mode: a
46
+ * visitor pays one `draftMode()` lookup, which does not make a static route
47
+ * dynamic. In draft mode it is the source of every module the editor's draft
48
+ * changes, from the runtime's head -- the one every `fetchVal` reads -- so
49
+ * the server renders the draft and the browser hydrates the same thing, with
50
+ * the version of each, so the page compares versions with what the Studio
51
+ * relays rather than content. Also `null` when the session is not one Val
52
+ * accepts, or the draft could not be read (logged): the published page.
113
53
  *
114
- * Enabled (draft mode): reads the entry through `/json`, which replays pending
115
- * patches, so uncommitted Studio edits show up. Falls back to the local thunk if
116
- * the draft read yields nothing.
54
+ * The read is `readDraftChanges` in `@valbuild/server`, which
55
+ * `@valbuild/tanstack/server`'s `fetchValDraft` is too; only where draft mode
56
+ * and the cookies come from is Next's.
117
57
  */
118
- export declare const initFetchValKeyStega: (valServerPromise: Promise<JsonEntryValServer>, isEnabled: () => Promise<boolean>, getCookies: () => Promise<{
119
- get(name: string): {
120
- name: string;
121
- value: string;
122
- } | undefined;
123
- }>) => <T extends ResolvableModule>(selector: T, key: string) => Promise<JsonEntryContentOf<T> | undefined>;
124
- declare const initFetchValRouteUrl: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<RouteReaderValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
125
- get(name: string): string | null;
126
- }>, getCookies: () => Promise<{
127
- get(name: string): {
128
- name: string;
129
- value: string;
130
- } | undefined;
131
- }>, getDraftSourcesScope: GetDraftSourcesScope) => <T extends ResolvableModule>(selector: T, params?: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<string | null>;
58
+ export declare const initFetchValDraft: (deps: Omit<ReaderDeps, "getHeaders">) => () => Promise<ValDraft | null>;
132
59
  type ValNextRscConfig = {
133
60
  draftMode: typeof draftMode;
134
61
  headers: typeof headers;
@@ -139,5 +66,16 @@ export declare function initValRsc(config: ValConfig, valModules: ValModules, rs
139
66
  fetchValKeyStega: ReturnType<typeof initFetchValKeyStega>;
140
67
  fetchValRouteStega: ReturnType<typeof initFetchValRouteStega>;
141
68
  fetchValRouteUrl: ReturnType<typeof initFetchValRouteUrl>;
69
+ /**
70
+ * The draft for `<ValProvider draft>`, or `null` outside draft mode. Call
71
+ * it in the root layout (a Server Component) and pass what it returns:
72
+ *
73
+ * ```tsx
74
+ * <ValProvider config={config} draft={await fetchValDraft()}>
75
+ * ```
76
+ *
77
+ * See "The `draft` prop" in the README, and `ValDraft`.
78
+ */
79
+ fetchValDraft: ReturnType<typeof initFetchValDraft>;
142
80
  };
143
81
  export {};
@@ -1,8 +1,9 @@
1
1
  import { ValConfig, ValModules } from "@valbuild/core";
2
2
  import type { draftMode } from "next/headers";
3
+ import { NextResponse } from "next/server";
3
4
  declare const initValNextAppRouter: (valModules: ValModules, config: ValConfig, nextConfig: ValServerNextConfig & {
4
5
  formatter?: (code: string, filePath: string) => Promise<string> | string;
5
- }) => any;
6
+ }) => (req: Request) => Promise<NextResponse<unknown>>;
6
7
  type ValServerNextConfig = {
7
8
  draftMode: typeof draftMode;
8
9
  formatter?: (code: string, filePath: string) => Promise<string> | string;
@@ -1,6 +1,6 @@
1
1
  import { VAL_CONFIG_SESSION_STORAGE_KEY } from '@valbuild/shared/client';
2
2
  import React from 'react';
3
- import { _ as _slicedToArray } from './slicedToArray-aa291011.esm.js';
3
+ import { _ as _slicedToArray } from './slicedToArray-5ff32315.esm.js';
4
4
  import { Internal } from '@valbuild/core';
5
5
  import { VERSION } from '@valbuild/ui';
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  var client = require('@valbuild/shared/client');
4
4
  var React = require('react');
5
- var slicedToArray = require('./slicedToArray-44036a76.cjs.dev.js');
5
+ var slicedToArray = require('./slicedToArray-ed812733.cjs.dev.js');
6
6
  var core = require('@valbuild/core');
7
7
  var ui = require('@valbuild/ui');
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  var client = require('@valbuild/shared/client');
4
4
  var React = require('react');
5
- var slicedToArray = require('./slicedToArray-ce613de6.cjs.prod.js');
5
+ var slicedToArray = require('./slicedToArray-0fc63719.cjs.prod.js');
6
6
  var core = require('@valbuild/core');
7
7
  var ui = require('@valbuild/ui');
8
8
 
@@ -1,6 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var defineProperty = require('./defineProperty-8951f469.cjs.prod.js');
3
+ function _toPrimitive(t, r) {
4
+ if ("object" != typeof t || !t) return t;
5
+ var e = t[Symbol.toPrimitive];
6
+ if (void 0 !== e) {
7
+ var i = e.call(t, r || "default");
8
+ if ("object" != typeof i) return i;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return ("string" === r ? String : Number)(t);
12
+ }
13
+
14
+ function _toPropertyKey(t) {
15
+ var i = _toPrimitive(t, "string");
16
+ return "symbol" == typeof i ? i : i + "";
17
+ }
18
+
19
+ function _defineProperty(e, r, t) {
20
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
21
+ value: t,
22
+ enumerable: !0,
23
+ configurable: !0,
24
+ writable: !0
25
+ }) : e[r] = t, e;
26
+ }
4
27
 
5
28
  function ownKeys(e, r) {
6
29
  var t = Object.keys(e);
@@ -16,7 +39,7 @@ function _objectSpread2(e) {
16
39
  for (var r = 1; r < arguments.length; r++) {
17
40
  var t = null != arguments[r] ? arguments[r] : {};
18
41
  r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
19
- defineProperty._defineProperty(e, r, t[r]);
42
+ _defineProperty(e, r, t[r]);
20
43
  }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
21
44
  Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
22
45
  });
@@ -1,6 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var defineProperty = require('./defineProperty-f90345d7.cjs.dev.js');
3
+ function _toPrimitive(t, r) {
4
+ if ("object" != typeof t || !t) return t;
5
+ var e = t[Symbol.toPrimitive];
6
+ if (void 0 !== e) {
7
+ var i = e.call(t, r || "default");
8
+ if ("object" != typeof i) return i;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return ("string" === r ? String : Number)(t);
12
+ }
13
+
14
+ function _toPropertyKey(t) {
15
+ var i = _toPrimitive(t, "string");
16
+ return "symbol" == typeof i ? i : i + "";
17
+ }
18
+
19
+ function _defineProperty(e, r, t) {
20
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
21
+ value: t,
22
+ enumerable: !0,
23
+ configurable: !0,
24
+ writable: !0
25
+ }) : e[r] = t, e;
26
+ }
4
27
 
5
28
  function ownKeys(e, r) {
6
29
  var t = Object.keys(e);
@@ -16,7 +39,7 @@ function _objectSpread2(e) {
16
39
  for (var r = 1; r < arguments.length; r++) {
17
40
  var t = null != arguments[r] ? arguments[r] : {};
18
41
  r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
19
- defineProperty._defineProperty(e, r, t[r]);
42
+ _defineProperty(e, r, t[r]);
20
43
  }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
21
44
  Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
22
45
  });
@@ -1,4 +1,27 @@
1
- import { _ as _defineProperty } from './defineProperty-cca5affa.esm.js';
1
+ function _toPrimitive(t, r) {
2
+ if ("object" != typeof t || !t) return t;
3
+ var e = t[Symbol.toPrimitive];
4
+ if (void 0 !== e) {
5
+ var i = e.call(t, r || "default");
6
+ if ("object" != typeof i) return i;
7
+ throw new TypeError("@@toPrimitive must return a primitive value.");
8
+ }
9
+ return ("string" === r ? String : Number)(t);
10
+ }
11
+
12
+ function _toPropertyKey(t) {
13
+ var i = _toPrimitive(t, "string");
14
+ return "symbol" == typeof i ? i : i + "";
15
+ }
16
+
17
+ function _defineProperty(e, r, t) {
18
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
19
+ value: t,
20
+ enumerable: !0,
21
+ configurable: !0,
22
+ writable: !0
23
+ }) : e[r] = t, e;
24
+ }
2
25
 
3
26
  function ownKeys(e, r) {
4
27
  var t = Object.keys(e);
@@ -1,7 +1,7 @@
1
- import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-5758a730.esm.js';
2
- import { _ as _objectSpread2 } from './objectSpread2-60d1bd93.esm.js';
3
- import { _ as _slicedToArray } from './slicedToArray-aa291011.esm.js';
4
- import { RecordSchema, Internal } from '@valbuild/core';
1
+ import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-9209e9dd.esm.js';
2
+ import { _ as _objectSpread2 } from './objectSpread2-f1f0d77a.esm.js';
3
+ import { _ as _slicedToArray } from './slicedToArray-5ff32315.esm.js';
4
+ import { Internal, RecordSchema } from '@valbuild/core';
5
5
  import { getNextAppRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern } from '@valbuild/shared/client';
6
6
 
7
7
  function _typeof(o) {
@@ -14,156 +14,6 @@ function _typeof(o) {
14
14
  }, _typeof(o);
15
15
  }
16
16
 
17
- /**
18
- * True when the module's schema is a `.jsonValues()` record/router — i.e. each
19
- * entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
20
- * route helpers to load ONLY the matched entry instead of the whole record.
21
- */
22
- function isJsonValuesRecordSchema(schema) {
23
- return schema instanceof RecordSchema && schema["executeSerialize"]().jsonValues === true;
24
- }
25
-
26
- /**
27
- * A whole `.jsonValues()` record, as `useVal` and `fetchVal` read it: with
28
- * every entry's content. In the record's own source each entry is a lazy
29
- * `c.json(() => import(...))` marker, so a reader that encodes that source
30
- * renders every entry empty. (`useValKey` and `fetchValKey` read one entry,
31
- * and load only that one.)
32
- *
33
- * `sourcesOf(modulePath)` are what the reader has before the bundle, the first
34
- * that has the record winning: a draft view, then a snapshot (a proposal's saves, or the
35
- * content version the site serves). An entry that is still a marker there is
36
- * taken from a later source that has its content; the rest are named in
37
- * `load`, for the reader to load from the bundle by key and hand to
38
- * {@link fillJsonValuesRecord}.
39
- *
40
- * `null` when the selector is not a `.jsonValues()` module, or its record is
41
- * not an object (a nullable record that is null): there is nothing to fill.
42
- */
43
- function jsonValuesRecordToFill(
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- selector, sourcesOf) {
46
- // Untyped, as `getJsonEntryStegaRoot`'s selector is: a module or a view of
47
- // one, whichever source type it was defined with.
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- var module = Internal.resolveViewedModule(selector);
50
- if (!module || !isJsonValuesRecordSchema(Internal.getSchema(module))) {
51
- return null;
52
- }
53
- var modulePath = Internal.getValPath(module);
54
- if (!modulePath) {
55
- return null;
56
- }
57
- var sources = sourcesOf(modulePath);
58
- var isRecord = function isRecord(value) {
59
- return _typeof(value) === "object" && value !== null && !Array.isArray(value);
60
- };
61
- var chosen = sources.find(function (source) {
62
- return source !== undefined;
63
- });
64
- var base = chosen !== undefined ? chosen : Internal.getSource(module);
65
- if (!isRecord(base)) {
66
- return null;
67
- }
68
- var record = {};
69
- var load = [];
70
- var _loop = function _loop() {
71
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
72
- key = _Object$entries$_i[0],
73
- entry = _Object$entries$_i[1];
74
- if (!Internal.isJson(entry)) {
75
- record[key] = entry;
76
- return 1; // continue
77
- }
78
- var later = sources.slice(sources.indexOf(chosen) + 1).map(function (source) {
79
- return isRecord(source) && Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined;
80
- }).find(function (content) {
81
- return content !== undefined && !Internal.isJson(content);
82
- });
83
- if (later !== undefined) {
84
- record[key] = later;
85
- } else {
86
- // Left as the marker until it is loaded: see `fillJsonValuesRecord`.
87
- record[key] = entry;
88
- load.push(key);
89
- }
90
- };
91
- for (var _i = 0, _Object$entries = Object.entries(base); _i < _Object$entries.length; _i++) {
92
- if (_loop()) continue;
93
- }
94
- return {
95
- modulePath: modulePath,
96
- module: module,
97
- record: record,
98
- load: load
99
- };
100
- }
101
-
102
- /**
103
- * The record from {@link jsonValuesRecordToFill}, with the entries it named in
104
- * `load` put in: `loaded[key]`, as the bundle's import of that entry gave it.
105
- * An entry the bundle has no import for keeps its marker.
106
- */
107
- function fillJsonValuesRecord(record, loaded) {
108
- var filled = _objectSpread2({}, record);
109
- for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
110
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
111
- key = _Object$entries2$_i[0],
112
- content = _Object$entries2$_i[1];
113
- if (content !== undefined) {
114
- filled[key] = content;
115
- }
116
- }
117
- return filled;
118
- }
119
-
120
- /**
121
- * The bundle's import of one `.jsonValues()` entry, started: `undefined` when
122
- * the module's own source has no marker for `key` to import from.
123
- */
124
- function bundledJsonEntryImport(
125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
- module, key) {
127
- var _Internal$getJsonImpo;
128
- var source = module && Internal.getSource(module);
129
- var marker = _typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
130
- if (!Internal.isJson(marker)) {
131
- return undefined;
132
- }
133
- return (_Internal$getJsonImpo = Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
134
- }
135
-
136
- /**
137
- * Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
138
- * strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
139
- * identity transform (the content carries no selector path/schema).
140
- *
141
- * Yields e.g. `/app/support/[slug]/page.val.ts?p="/support/faq"`, so a `title`
142
- * field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
143
- * `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
144
- */
145
- function getJsonEntryStegaRoot(
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- selector, key
148
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
149
- ) {
150
- var modulePath = selector && Internal.getValPath(selector);
151
- if (!modulePath) {
152
- return undefined;
153
- }
154
- var schema = selector && Internal.getSchema(selector);
155
- if (!(schema instanceof RecordSchema)) {
156
- return undefined;
157
- }
158
- var path = Internal.createValPathOfItem(modulePath, key);
159
- if (!path) {
160
- return undefined;
161
- }
162
- return {
163
- path: path,
164
- schema: schema["executeSerialize"]().item
165
- };
166
- }
167
17
  function getValRouteUrlFromVal(resolvedParams, methodName,
168
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
19
  path,
@@ -307,4 +157,4 @@ val) {
307
157
  return actualRoute;
308
158
  }
309
159
 
310
- export { _typeof as _, isJsonValuesRecordSchema as a, getValRouteUrlFromVal as b, bundledJsonEntryImport as c, fillJsonValuesRecord as f, getJsonEntryStegaRoot as g, initValRouteFromVal as i, jsonValuesRecordToFill as j };
160
+ export { getValRouteUrlFromVal as g, initValRouteFromVal as i };