@valbuild/next 0.150.23 → 0.152.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 (76) hide show
  1. package/CHANGELOG.md +175 -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/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
  35. package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
  36. package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
  37. package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
  38. package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
  39. package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
  40. package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
  41. package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
  42. package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
  43. package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
  44. package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
  45. package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
  46. package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
  47. package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
  48. package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
  49. package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
  50. package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
  51. package/dist/useHydrated-afcdbb66.esm.js +26 -0
  52. package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
  53. package/dist/valbuild-next.cjs.dev.js +7 -8
  54. package/dist/valbuild-next.cjs.prod.js +7 -8
  55. package/dist/valbuild-next.esm.js +7 -8
  56. package/dist/{version-b292025f.cjs.dev.js → version-284ab1bc.cjs.prod.js} +1 -1
  57. package/dist/{version-8bac9fbe.esm.js → version-41472ee7.esm.js} +1 -1
  58. package/dist/{version-bfb6bbc0.cjs.prod.js → version-bab8ec07.cjs.dev.js} +1 -1
  59. package/package.json +8 -8
  60. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
  61. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
  62. package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
  63. package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
  64. package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
  65. package/server/dist/valbuild-next-server.esm.js +4 -5
  66. package/dist/ValApp-6c3da222.cjs.js +0 -7
  67. package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
  68. package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
  69. package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
  70. package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
  71. package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
  72. package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
  73. package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
  74. package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
  75. package/dist/defineProperty-cca5affa.esm.js +0 -26
  76. package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
@@ -3,174 +3,93 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('client-only');
6
- var routeFromVal = require('../../dist/routeFromVal-4df1157a.cjs.dev.js');
7
6
  var core = require('@valbuild/core');
8
- var stega = require('@valbuild/react/stega');
7
+ var internal = require('@valbuild/react/internal');
9
8
  var React = require('react');
10
- var ValOverlayContext = require('../../dist/ValOverlayContext-262899b3.cjs.dev.js');
11
- require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
12
- require('../../dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
13
- require('../../dist/objectSpread2-58024783.cjs.dev.js');
14
- require('../../dist/defineProperty-f90345d7.cjs.dev.js');
15
- require('../../dist/slicedToArray-44036a76.cjs.dev.js');
9
+ var ValOverlayContext = require('../../dist/ValOverlayContext-0c29b6a7.cjs.dev.js');
10
+ var useHydrated = require('../../dist/useHydrated-ff733777.cjs.dev.js');
11
+ var routeFromVal = require('../../dist/routeFromVal-a1e0a8be.cjs.dev.js');
12
+ require('../../dist/createForOfIteratorHelper-9c6aa3c7.cjs.dev.js');
13
+ require('../../dist/unsupportedIterableToArray-20a9209f.cjs.dev.js');
14
+ require('../../dist/objectSpread2-58726b14.cjs.dev.js');
15
+ require('../../dist/slicedToArray-ed812733.cjs.dev.js');
16
16
  require('@valbuild/shared/client');
17
17
 
18
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
19
19
 
20
20
  var React__default = /*#__PURE__*/_interopDefault(React);
21
21
 
22
- /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
23
-
24
- function useValStega(selector) {
25
- var valOverlayContext = ValOverlayContext.useValOverlayContext();
26
- var moduleIds = React__default["default"].useMemo(function () {
27
- return stega.getModuleIds(selector);
28
- }, [selector]);
29
- var store = valOverlayContext.store;
30
- var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
31
- return function () {};
32
- }, store ? store.getSnapshot(moduleIds) : function () {
33
- return;
34
- }, store ? store.getServerSnapshot(moduleIds) : function () {
35
- return;
36
- });
37
- // Suspense gate. `suspend` is false during SSR and hydration (so the static
38
- // committed source is rendered, matching the server HTML exactly) and is
39
- // activated by ValProvider after hydration — inside a transition — when the
40
- // `suspend` prop is set AND the Val Enable cookie is present (checked
41
- // client-side; the server store is never populated). It never deactivates.
42
- // The production path (no cookie) skips the call entirely. The
43
- // `draftMode !== false` check is a release valve: with draft mode off the
44
- // store never receives source updates, so waitForLoad could only ever
45
- // resolve via its timeout — and would then re-suspend on every subsequent
46
- // render since the resolved promise is evicted from the cache. draftMode is
47
- // null until the first /draft/stat poll resolves; null -> true keeps
48
- // suspending, -> false only unblocks, and false -> true happens only on an
49
- // explicit draft-mode enable which already refreshes the route.
50
- // React.use is allowed inside conditionals — it is not a hook.
51
- /**
52
- * Wait until draft mode is KNOWN, before anything else.
53
- *
54
- * `draftMode === null` means `/draft/stat` has not answered yet, and the
55
- * `getModule` below treats it as off — so a render that slips through here
56
- * while it is unknown resolves against committed source. For an ordinary field
57
- * that is a flash of published content; for `useValRoute` on a route that
58
- * exists only in an uncommitted patch it is `notFound()`, which no later
59
- * answer can undo. That was the 404 on a page you had just created.
60
- */
61
- if (valOverlayContext.suspend && valOverlayContext.draftMode === null && valOverlayContext.draftModeReady) {
62
- React__default["default"].use(valOverlayContext.draftModeReady);
63
- }
64
- /**
65
- * Then wait for the draft sources — but only while more might be coming.
66
- *
67
- * `draftSourcesSynced` is the editor saying it has sent everything it holds,
68
- * and it only holds modules with patches: an unedited module has no draft, so
69
- * nothing is ever sent for it. Without that signal this could not tell "not
70
- * sent yet" from "nothing to send", and waited out `waitForLoad`'s ten second
71
- * timeout once per unedited module the page reads — which is what left a newly
72
- * created page sitting on its loading fallback.
73
- */
74
- if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && !valOverlayContext.draftSourcesSynced && store && !store.hasAllLoaded(moduleIds)) {
75
- React__default["default"].use(store.waitForLoad(moduleIds));
76
- }
77
- var sourceOf = function sourceOf(moduleId) {
78
- return moduleMap && valOverlayContext.draftMode ? moduleMap[moduleId] : undefined;
79
- };
80
- /*
81
- * A whole `.jsonValues()` record is read with every entry's content: its own
82
- * source holds only lazy markers. The entries the draft view does not have
83
- * are imported from the bundle -- all of them started before waiting on any,
84
- * so they load together. `useValKey` is the reader for one entry.
85
- */
86
- var jsonValues = routeFromVal.jsonValuesRecordToFill(selector, function (modulePath) {
87
- return [sourceOf(modulePath)];
88
- });
89
- var filledRecord = null;
90
- if (jsonValues !== null) {
91
- var pending = jsonValues.load.map(function (key) {
92
- return committedJsonEntryPromise(jsonValues.module, jsonValues.modulePath, key);
93
- });
94
- var loaded = {};
95
- jsonValues.load.forEach(function (key, index) {
96
- var promise = pending[index];
97
- loaded[key] = promise === undefined ? undefined : React__default["default"].use(promise);
98
- });
99
- filledRecord = routeFromVal.fillJsonValuesRecord(jsonValues.record, loaded);
100
- }
101
- return stega.stegaEncode(selector, {
102
- disabled: !valOverlayContext.draftMode,
103
- getModule: function getModule(moduleId) {
104
- return jsonValues !== null && moduleId === jsonValues.modulePath ? filledRecord : sourceOf(moduleId);
105
- }
106
- });
107
- }
108
-
109
22
  /**
110
- * The module's source as the overlay currently sees it — i.e. WITH the editor's
111
- * unpublished changes — or undefined when there is no draft view to be had
112
- * (production, draft mode off, or the overlay has not pushed this module yet).
23
+ * Whether the content this component renders carries its edit tags.
113
24
  *
114
- * This is what lets the single-entry readers show drafts. They otherwise resolve
115
- * an entry through its local import thunk, which is the content that was bundled:
116
- * correct in production, and stale the moment anyone edits in the Studio.
25
+ * In draft mode -- except, on a page rendered from a server-read draft
26
+ * (`<ValProvider draft>`), for the server's render and for this component's
27
+ * own hydration render: then the draft text goes out without them, and the
28
+ * render React does right after hydrating the component puts them in. JSX
29
+ * auto-tagging turns a tagged string into a `data-val-path` attribute as the
30
+ * element is created, and whether the server renders with the patched JSX
31
+ * runtime depends on how it was bundled; a string with no tags in it has
32
+ * nothing to tag, so the server's HTML and every hydration render agree.
33
+ * The same rule as `@valbuild/tanstack`'s.
117
34
  */
118
- function useDraftModuleSource(moduleFilePath) {
119
- var valOverlayContext = ValOverlayContext.useValOverlayContext();
120
- var store = valOverlayContext.store;
121
- var moduleIds = React__default["default"].useMemo(function () {
122
- return moduleFilePath ? [moduleFilePath] : [];
123
- }, [moduleFilePath]);
124
- var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
125
- return function () {};
126
- }, store ? store.getSnapshot(moduleIds) : function () {
127
- return undefined;
128
- }, store ? store.getServerSnapshot(moduleIds) : function () {
129
- return undefined;
130
- });
131
- if (!valOverlayContext.draftMode || !moduleFilePath) {
132
- return undefined;
133
- }
134
- return moduleMap === null || moduleMap === void 0 ? void 0 : moduleMap[moduleFilePath];
35
+ function useEncodesEditTags(context) {
36
+ var hydrated = useHydrated.useHydrated();
37
+ if (!context.draftMode) return false;
38
+ return !context.serverDraft || hydrated;
135
39
  }
136
40
 
41
+ /** What the provider tells the hooks: `ValOverlayContext`'s value. */
42
+
137
43
  /**
138
- * What the draft view says about one `.jsonValues()` entry.
139
- *
140
- * Mirrors the server-side rule in `fetchValKey`/`fetchValRoute`: a draft view
141
- * that HAS an answer wins, including the answer "this entry is gone", and the
142
- * bundled content is used only when there is no draft view.
44
+ * Where this page's hooks read from, in order: what the Studio sent (the
45
+ * overlay, which starts from the server-read draft when the page has one),
46
+ * then -- added by every read -- the bundle. Edit tags in draft mode, unless
47
+ * `encode` says otherwise (see `useEncodesEditTags`). A plain function of the
48
+ * provider's state, as `@valbuild/tanstack`'s is (which the scenario world
49
+ * reads a page with).
143
50
  */
144
- function draftJsonEntry(draftSource, key) {
145
- if (draftSource === undefined || draftSource === null || routeFromVal._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
146
- return {
147
- status: "unavailable"
148
- };
149
- }
150
- var entry = draftSource[key];
151
- if (entry === undefined) {
152
- // The module IS in the draft view and this key is not: it was deleted.
153
- return {
154
- status: "absent"
155
- };
156
- }
157
- if (core.Internal.isJson(entry)) {
158
- // An un-loaded marker: the Studio has not fetched this entry's content, so
159
- // the draft view cannot answer. (The engine asks for entries that pending
160
- // patches touch, so this resolves itself for anything actually edited.)
161
- return {
162
- status: "unavailable"
163
- };
164
- }
51
+ function pageReadEnv(state) {
52
+ var _state$draftSourcesSy;
53
+ var encode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !!state.draftMode;
165
54
  return {
166
- status: "content",
167
- content: entry
55
+ sources: [internal.overlaySource(state.store, {
56
+ draftMode: state.draftMode,
57
+ suspend: state.suspend,
58
+ draftModeReady: state.draftModeReady,
59
+ synced: (_state$draftSourcesSy = state.draftSourcesSynced) !== null && _state$draftSourcesSy !== void 0 ? _state$draftSourcesSy : false
60
+ })],
61
+ encode: encode
168
62
  };
169
63
  }
170
64
 
171
- // Module-level cache of in-flight/resolved entry loads, so `React.use` gets a
172
- // stable promise across renders (keyed by module path + entry key).
173
- var jsonEntryPromiseCache = new Map();
65
+ /**
66
+ * {@link pageReadEnv} for this component, kept while nothing it is made of
67
+ * moves, so a component's subscription is not made again on every render.
68
+ */
69
+ function useReadEnv() {
70
+ var context = ValOverlayContext.useValOverlayContext();
71
+ var encode = useEncodesEditTags(context);
72
+ var store = context.store,
73
+ draftMode = context.draftMode,
74
+ suspend = context.suspend,
75
+ draftModeReady = context.draftModeReady,
76
+ draftSourcesSynced = context.draftSourcesSynced;
77
+ return React__default["default"].useMemo(function () {
78
+ return pageReadEnv({
79
+ store: store,
80
+ draftMode: draftMode,
81
+ suspend: suspend,
82
+ draftModeReady: draftModeReady,
83
+ draftSourcesSynced: draftSourcesSynced
84
+ }, encode);
85
+ }, [store, draftMode, suspend, draftModeReady, draftSourcesSynced, encode]);
86
+ }
87
+
88
+ /** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
89
+
90
+ function useValStega(selector) {
91
+ return internal.useResolvedVal(selector, useReadEnv());
92
+ }
174
93
 
175
94
  /**
176
95
  * Client counterpart to `fetchValKey`: resolves a SINGLE `.jsonValues()` entry
@@ -179,74 +98,10 @@ var jsonEntryPromiseCache = new Map();
179
98
  * inside a `<Suspense>` boundary.
180
99
  *
181
100
  * In draft mode it renders the editor's unpublished content, taken from the
182
- * overlay; in production — and whenever there is no draft view — it resolves the
183
- * entry's lazy import thunk from the local module.
101
+ * overlay; an entry the draft deleted is `undefined`, never the bundled one.
184
102
  */
185
103
  function useValKeyStega(selector, key) {
186
- var valOverlayContext = ValOverlayContext.useValOverlayContext();
187
- // A view is a pointer: everything below reads a path, a schema and a source
188
- // off this, and a pointer has none of them. See `resolveViewedModule`.
189
- var valModule = core.Internal.resolveViewedModule(selector);
190
- var moduleFilePath = valModule && core.Internal.getValPath(valModule);
191
- var draftSource = useDraftModuleSource(moduleFilePath || undefined);
192
- var draft = draftJsonEntry(draftSource, key);
193
- if (draft.status === "absent") {
194
- // Deleted in the draft state. Falling back to the bundled entry here would
195
- // render content the editor has just removed.
196
- return undefined;
197
- }
198
- var content = draft.status === "content" ? draft.content : undefined;
199
- if (content === undefined) {
200
- content = readCommittedJsonEntry(valModule, key);
201
- }
202
- return stega.stegaEncode(content, {
203
- disabled: !valOverlayContext.draftMode,
204
- root: routeFromVal.getJsonEntryStegaRoot(valModule, key)
205
- });
206
- }
207
-
208
- /**
209
- * The entry's content as bundled: its lazy import thunk, resolved through
210
- * `React.use` so the caller suspends until it lands.
211
- *
212
- * Deliberately not named `use*`: it is called conditionally, which is fine
213
- * because `React.use` is not a hook, but a `use*` name would read like one.
214
- */
215
- function readCommittedJsonEntry(selector, key) {
216
- var source = selector && core.Internal.getSource(selector);
217
- var marker = source && routeFromVal._typeof(source) === "object" ? source[key] : undefined;
218
- if (!core.Internal.isJson(marker)) {
219
- return undefined;
220
- }
221
- var thunk = core.Internal.getJsonImport(marker);
222
- if (!thunk) {
223
- return undefined;
224
- }
225
- var promise = committedJsonEntryPromise(selector, core.Internal.getValPath(selector), key);
226
- return promise === undefined ? undefined : React__default["default"].use(promise);
227
- }
228
-
229
- /**
230
- * The bundle's import of one entry, started once and kept, so every render
231
- * that waits on it is handed the same promise (`React.use` needs that).
232
- * `undefined` when the module has no import for `key`.
233
- */
234
- function committedJsonEntryPromise(
235
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
- module, modulePath, key) {
237
- var cacheKey = "".concat(modulePath !== null && modulePath !== void 0 ? modulePath : "", " ").concat(key);
238
- var promise = jsonEntryPromiseCache.get(cacheKey);
239
- if (!promise) {
240
- var thunk = routeFromVal.bundledJsonEntryImport(module, key);
241
- if (!thunk) {
242
- return undefined;
243
- }
244
- promise = thunk().then(function (mod) {
245
- return mod["default"];
246
- });
247
- jsonEntryPromiseCache.set(cacheKey, promise);
248
- }
249
- return promise;
104
+ return internal.useResolvedEntry(selector, key, useReadEnv());
250
105
  }
251
106
  function resolveParams(params) {
252
107
  if (!params) {
@@ -265,63 +120,75 @@ function resolveParams(params) {
265
120
  }
266
121
  return params;
267
122
  }
268
- function useValRouteStega(selector, params) {
269
- var valOverlayContext = ValOverlayContext.useValOverlayContext();
123
+
124
+ /**
125
+ * `useValRoute`'s read, once its params are known: a `.jsonValues()`
126
+ * router's one entry for the params (one dynamic import, like `useValKey`),
127
+ * or the router's entry for them. `null` for no such route.
128
+ */
129
+ function routeRead(selector, params, env, settled) {
270
130
  // A view is a pointer: everything below reads a path, a schema and a source
271
131
  // off this, and a pointer has none of them. See `resolveViewedModule`.
272
- var valModule = core.Internal.resolveViewedModule(selector);
273
- // Both called unconditionally to keep hook order stable. For a `.jsonValues()`
274
- // router `val` is unused (we resolve a single entry below instead); for any
275
- // other router `draftSource` is.
276
- var val = useValStega(valModule);
277
- var draftSource = useDraftModuleSource(valModule && core.Internal.getValPath(valModule) || undefined);
278
- var resolvedParams = resolveParams(params);
279
- // Careful: null means there was an error - undefined means no params
280
- if (resolvedParams === null) {
281
- return null;
282
- }
283
- var path = valModule && core.Internal.getValPath(valModule);
284
- var schema = valModule && core.Internal.getSchema(valModule);
285
- // `.jsonValues()` router: map params → the entry key and load ONLY that
286
- // entry's backing `*.val.json` (one dynamic import), like `useValKey`.
287
- if (routeFromVal.isJsonValuesRecordSchema(schema)) {
288
- var source = valModule && core.Internal.getSource(valModule);
289
- var url = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRoute", path, schema, source);
132
+ return moduleRouteRead(core.Internal.resolveViewedModule(selector), params, env, settled);
133
+ }
134
+
135
+ /**
136
+ * {@link routeRead}, for a module (a view resolved). A plain function, so the
137
+ * scenario world (`scenarios/`) reads a route as the hook does.
138
+ */
139
+ function moduleRouteRead(valModule, params, env, settled) {
140
+ var path = core.Internal.getValPath(valModule);
141
+ var schema = core.Internal.getSchema(valModule);
142
+ if (internal.isJsonValuesRecordSchema(schema)) {
143
+ var url = routeFromVal.getValRouteUrlFromVal(params, "useValRoute", path, schema, core.Internal.getSource(valModule));
290
144
  if (!url) {
291
- return null;
292
- }
293
- var draft = draftJsonEntry(draftSource, url);
294
- if (draft.status === "absent") {
295
- // The draft state says this route is gone — see useValKeyStega.
296
- return null;
297
- }
298
- var content = draft.status === "content" ? draft.content : undefined;
299
- if (content === undefined) {
300
- content = readCommittedJsonEntry(valModule, url);
145
+ return {
146
+ status: "ready",
147
+ value: null,
148
+ reads: []
149
+ };
301
150
  }
302
- if (content === undefined) {
303
- return null;
304
- }
305
- return stega.stegaEncode(content, {
306
- disabled: !valOverlayContext.draftMode,
307
- root: routeFromVal.getJsonEntryStegaRoot(valModule, url)
151
+ return internal.mapResolution(internal.resolveModuleEntry(valModule, url, env, {
152
+ settled: settled
153
+ }), function (entry) {
154
+ return entry === undefined ? null : entry;
308
155
  });
309
156
  }
310
- var route = routeFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", path, schema, val);
311
- return route;
157
+ return internal.mapResolution(internal.resolveVal(valModule, env, {
158
+ settled: settled
159
+ }), function (val) {
160
+ return routeFromVal.initValRouteFromVal(params, "useValRoute", path, schema, val);
161
+ });
312
162
  }
163
+ function useValRouteStega(selector, params) {
164
+ var env = useReadEnv();
165
+ var resolvedParams = resolveParams(params);
166
+ var value = internal.useResolved(selector, env, function (settled) {
167
+ return resolvedParams === null ? NO_ROUTE : routeRead(selector, resolvedParams || {}, env, settled);
168
+ });
169
+ // Careful: null means there was an error - undefined means no params
170
+ return resolvedParams === null ? null : value;
171
+ }
172
+ var NO_ROUTE = {
173
+ status: "ready",
174
+ value: null,
175
+ reads: []
176
+ };
313
177
  function useValRouteUrl(selector, params) {
314
178
  // A view is a pointer: everything below reads a path, a schema and a source
315
179
  // off this, and a pointer has none of them. See `resolveViewedModule`.
316
180
  var valModule = core.Internal.resolveViewedModule(selector);
317
- var val = useValStega(valModule);
181
+ // The url is made of the params and the module's path: a `.jsonValues()`
182
+ // router's entries are not imported for it.
183
+ var val = internal.useResolvedVal(valModule, useReadEnv(), {
184
+ entries: false
185
+ });
318
186
  var resolvedParams = params === undefined ? undefined : resolveParams(params);
319
187
  // Careful: null means there was an error - undefined means no params
320
188
  if (resolvedParams === null) {
321
189
  return null;
322
190
  }
323
- var route = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", valModule && core.Internal.getValPath(valModule), valModule && core.Internal.getSchema(valModule), val);
324
- return route;
191
+ return routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", valModule && core.Internal.getValPath(valModule), valModule && core.Internal.getSchema(valModule), val);
325
192
  }
326
193
 
327
194
  // eslint-disable-next-line @typescript-eslint/no-unused-vars