@valbuild/tanstack 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.
- package/CHANGELOG.md +198 -0
- package/README.md +11 -11
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +100 -293
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +100 -293
- package/client/dist/valbuild-tanstack-client.esm.js +99 -292
- package/dist/ValOverlayContext-1e50a557.cjs.prod.js +47 -0
- package/dist/ValOverlayContext-6826b4d9.esm.js +40 -0
- package/dist/ValOverlayContext-b18c2f18.cjs.dev.js +47 -0
- package/dist/declarations/src/ValDraft.d.ts +6 -50
- package/dist/declarations/src/ValModulesClient.d.ts +1 -3
- package/dist/declarations/src/ValProvider.d.ts +1 -1
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/server/initValContent.d.ts +55 -169
- package/dist/{routeFromVal-06590f50.esm.js → routeFromVal-124235a5.esm.js} +3 -153
- package/dist/{routeFromVal-3c3915e2.cjs.dev.js → routeFromVal-2e834397.cjs.prod.js} +1 -156
- package/dist/{routeFromVal-b31a9e00.cjs.prod.js → routeFromVal-3d4d7c30.cjs.dev.js} +1 -156
- package/dist/{typeof-66e2d869.esm.js → typeof-3e1a1d11.esm.js} +1 -1
- package/dist/{typeof-8998e126.cjs.prod.js → typeof-56656438.cjs.prod.js} +0 -2
- package/dist/{typeof-dd0246a1.cjs.dev.js → typeof-bd6ec82c.cjs.dev.js} +0 -2
- package/dist/valbuild-tanstack.cjs.dev.js +162 -282
- package/dist/valbuild-tanstack.cjs.prod.js +162 -282
- package/dist/valbuild-tanstack.esm.js +162 -281
- package/dist/{version-dafb6d0d.esm.js → version-2b3824bf.esm.js} +2 -19
- package/dist/{version-cae4af97.cjs.dev.js → version-8e19c405.cjs.dev.js} +1 -19
- package/dist/{version-51de2c0e.cjs.prod.js → version-d46bc4bb.cjs.prod.js} +1 -19
- package/package.json +8 -8
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +278 -1140
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +278 -1140
- package/server/dist/valbuild-tanstack-server.esm.js +279 -1141
- package/dist/ValOverlayContext-198b4bd1.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-6411bbe3.esm.js +0 -293
- package/dist/ValOverlayContext-d9b22d1a.cjs.prod.js +0 -301
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
|
|
6
5
|
var core = require('@valbuild/core');
|
|
7
|
-
var
|
|
6
|
+
var internal = require('@valbuild/react/internal');
|
|
8
7
|
var React = require('react');
|
|
9
|
-
var ValOverlayContext = require('../../dist/ValOverlayContext-
|
|
10
|
-
var routeFromVal = require('../../dist/routeFromVal-
|
|
11
|
-
require('@valbuild/core/patch');
|
|
8
|
+
var ValOverlayContext = require('../../dist/ValOverlayContext-1e50a557.cjs.prod.js');
|
|
9
|
+
var routeFromVal = require('../../dist/routeFromVal-2e834397.cjs.prod.js');
|
|
12
10
|
require('react/jsx-runtime');
|
|
11
|
+
require('../../dist/typeof-56656438.cjs.prod.js');
|
|
13
12
|
require('@valbuild/shared/client');
|
|
14
13
|
|
|
15
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -70,193 +69,58 @@ function useEncodesEditTags(context) {
|
|
|
70
69
|
return !!context.analytics && hydrated;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
/** What
|
|
74
|
-
|
|
75
|
-
function useValStega(selector) {
|
|
76
|
-
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
77
|
-
var encodes = useEncodesEditTags(valOverlayContext);
|
|
78
|
-
var moduleIds = React__default["default"].useMemo(function () {
|
|
79
|
-
return stega.getModuleIds(selector);
|
|
80
|
-
}, [selector]);
|
|
81
|
-
var store = valOverlayContext.store;
|
|
82
|
-
var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
|
|
83
|
-
return function () {};
|
|
84
|
-
}, store ? store.getSnapshot(moduleIds) : function () {
|
|
85
|
-
return;
|
|
86
|
-
}, store ? store.getServerSnapshot(moduleIds) : function () {
|
|
87
|
-
return;
|
|
88
|
-
});
|
|
89
|
-
// Suspense gate. `suspend` is false during SSR and hydration (so the static
|
|
90
|
-
// committed source is rendered, matching the server HTML exactly) and is
|
|
91
|
-
// activated by ValProvider after hydration — inside a transition — when the
|
|
92
|
-
// `suspend` prop is set AND the Val Enable cookie is present (checked
|
|
93
|
-
// client-side; the server store is never populated). It never deactivates.
|
|
94
|
-
// The production path (no cookie) skips the call entirely. The
|
|
95
|
-
// `draftMode !== false` check is a release valve: with draft mode off the
|
|
96
|
-
// store never receives source updates, so waitForLoad could only ever
|
|
97
|
-
// resolve via its timeout — and would then re-suspend on every subsequent
|
|
98
|
-
// render since the resolved promise is evicted from the cache. draftMode is
|
|
99
|
-
// null until the first /draft/stat poll resolves; null -> true keeps
|
|
100
|
-
// suspending, -> false only unblocks, and false -> true happens only on an
|
|
101
|
-
// explicit draft-mode enable which already refreshes the route.
|
|
102
|
-
// React.use is allowed inside conditionals — it is not a hook.
|
|
103
|
-
/**
|
|
104
|
-
* Wait until draft mode is KNOWN, before anything else.
|
|
105
|
-
*
|
|
106
|
-
* `draftMode === null` means `/draft/stat` has not answered yet, and the
|
|
107
|
-
* `getModule` below treats it as off — so a render that slips through here
|
|
108
|
-
* while it is unknown resolves against committed source. For an ordinary field
|
|
109
|
-
* that is a flash of published content; for `useValRoute` on a route that
|
|
110
|
-
* exists only in an uncommitted patch it is `notFound()`, which no later
|
|
111
|
-
* answer can undo. That was the 404 on a page you had just created.
|
|
112
|
-
*/
|
|
113
|
-
if (valOverlayContext.suspend && valOverlayContext.draftMode === null && valOverlayContext.draftModeReady) {
|
|
114
|
-
React__default["default"].use(valOverlayContext.draftModeReady);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Then wait for the draft sources — but only while more might be coming.
|
|
118
|
-
*
|
|
119
|
-
* `draftSourcesSynced` is the editor saying it has sent everything it holds,
|
|
120
|
-
* and it only holds modules with patches: an unedited module has no draft, so
|
|
121
|
-
* nothing is ever sent for it. Without that signal this could not tell "not
|
|
122
|
-
* sent yet" from "nothing to send", and waited out `waitForLoad`'s ten second
|
|
123
|
-
* timeout once per unedited module the page reads — which is what left a newly
|
|
124
|
-
* created page sitting on its loading fallback.
|
|
125
|
-
*/
|
|
126
|
-
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && !valOverlayContext.draftSourcesSynced && store && !store.hasAllLoaded(moduleIds)) {
|
|
127
|
-
React__default["default"].use(store.waitForLoad(moduleIds));
|
|
128
|
-
}
|
|
129
|
-
var sourceOf = function sourceOf(moduleId) {
|
|
130
|
-
var _valOverlayContext$sn;
|
|
131
|
-
if (moduleMap && valOverlayContext.draftMode) {
|
|
132
|
-
var draft = moduleMap[moduleId];
|
|
133
|
-
if (draft !== undefined) {
|
|
134
|
-
return draft;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// At a proposal's address: its saved Source, not the bundle's.
|
|
138
|
-
return (_valOverlayContext$sn = valOverlayContext.snapshot) === null || _valOverlayContext$sn === void 0 ? void 0 : _valOverlayContext$sn[moduleId];
|
|
139
|
-
};
|
|
140
|
-
/*
|
|
141
|
-
* A whole `.jsonValues()` record is read with every entry's content: its own
|
|
142
|
-
* source holds only lazy markers. The entries no draft or snapshot has are
|
|
143
|
-
* imported from the bundle -- all of them started before waiting on any, so
|
|
144
|
-
* they load together. `useValKey` is the reader for one entry.
|
|
145
|
-
*/
|
|
146
|
-
var jsonValues = routeFromVal.jsonValuesRecordToFill(selector, function (modulePath) {
|
|
147
|
-
var _valOverlayContext$sn2;
|
|
148
|
-
return [moduleMap && valOverlayContext.draftMode ? moduleMap[modulePath] : undefined, (_valOverlayContext$sn2 = valOverlayContext.snapshot) === null || _valOverlayContext$sn2 === void 0 ? void 0 : _valOverlayContext$sn2[modulePath]];
|
|
149
|
-
});
|
|
150
|
-
var filledRecord = null;
|
|
151
|
-
if (jsonValues !== null) {
|
|
152
|
-
var pending = jsonValues.load.map(function (key) {
|
|
153
|
-
return committedJsonEntryPromise(jsonValues.module, jsonValues.modulePath, key);
|
|
154
|
-
});
|
|
155
|
-
var loaded = {};
|
|
156
|
-
jsonValues.load.forEach(function (key, index) {
|
|
157
|
-
var promise = pending[index];
|
|
158
|
-
loaded[key] = promise === undefined ? undefined : React__default["default"].use(promise);
|
|
159
|
-
});
|
|
160
|
-
filledRecord = routeFromVal.fillJsonValuesRecord(jsonValues.record, loaded);
|
|
161
|
-
}
|
|
162
|
-
return stega.stegaEncode(selector, {
|
|
163
|
-
disabled: !encodes,
|
|
164
|
-
getModule: function getModule(moduleId) {
|
|
165
|
-
return jsonValues !== null && moduleId === jsonValues.modulePath ? filledRecord : sourceOf(moduleId);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* The module's source as the overlay currently sees it — i.e. WITH the editor's
|
|
172
|
-
* unpublished changes — or undefined when there is no draft view to be had
|
|
173
|
-
* (production, draft mode off, or the overlay has not pushed this module yet).
|
|
174
|
-
*
|
|
175
|
-
* This is what lets the single-entry readers show drafts. They otherwise resolve
|
|
176
|
-
* an entry through its local import thunk, which is the content that was bundled:
|
|
177
|
-
* correct in production, and stale the moment anyone edits in the Studio.
|
|
178
|
-
*/
|
|
179
|
-
function useDraftModuleSource(moduleFilePath) {
|
|
180
|
-
var _valOverlayContext$sn3, _moduleMap$moduleFile;
|
|
181
|
-
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
182
|
-
var store = valOverlayContext.store;
|
|
183
|
-
var moduleIds = React__default["default"].useMemo(function () {
|
|
184
|
-
return moduleFilePath ? [moduleFilePath] : [];
|
|
185
|
-
}, [moduleFilePath]);
|
|
186
|
-
var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
|
|
187
|
-
return function () {};
|
|
188
|
-
}, store ? store.getSnapshot(moduleIds) : function () {
|
|
189
|
-
return undefined;
|
|
190
|
-
}, store ? store.getServerSnapshot(moduleIds) : function () {
|
|
191
|
-
return undefined;
|
|
192
|
-
});
|
|
193
|
-
if (!moduleFilePath) {
|
|
194
|
-
return undefined;
|
|
195
|
-
}
|
|
196
|
-
// A proposal's saved Source stands in for the bundle's, draft or not.
|
|
197
|
-
var snapshot = (_valOverlayContext$sn3 = valOverlayContext.snapshot) === null || _valOverlayContext$sn3 === void 0 ? void 0 : _valOverlayContext$sn3[moduleFilePath];
|
|
198
|
-
if (!valOverlayContext.draftMode) {
|
|
199
|
-
return snapshot;
|
|
200
|
-
}
|
|
201
|
-
return (_moduleMap$moduleFile = moduleMap === null || moduleMap === void 0 ? void 0 : moduleMap[moduleFilePath]) !== null && _moduleMap$moduleFile !== void 0 ? _moduleMap$moduleFile : snapshot;
|
|
202
|
-
}
|
|
72
|
+
/** What the provider tells the hooks: `ValOverlayContext`'s value. */
|
|
203
73
|
|
|
204
74
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
75
|
+
* Where this page's hooks read from, in order: what the Studio sent (the
|
|
76
|
+
* overlay, which starts from the server-read draft when the page has one),
|
|
77
|
+
* then a proposal's or a content version's snapshot, then -- added by every
|
|
78
|
+
* read -- the bundle. A plain function of the provider's state, so the
|
|
79
|
+
* scenario world (`scenarios/`) reads a page with what the hooks read.
|
|
210
80
|
*/
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
// A nullable record that is null in the draft view: it has no entries.
|
|
214
|
-
return {
|
|
215
|
-
status: "absent"
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
if (draftSource === undefined || _typeof._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
|
|
219
|
-
return {
|
|
220
|
-
status: "unavailable"
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
// Own keys only: an entry may be named `toString`.
|
|
224
|
-
if (!Object.prototype.hasOwnProperty.call(draftSource, key)) {
|
|
225
|
-
// The module IS in the draft view and this key is not: it was deleted.
|
|
226
|
-
return {
|
|
227
|
-
status: "absent"
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
var entry = draftSource[key];
|
|
231
|
-
if (core.Internal.isJson(entry)) {
|
|
232
|
-
// An un-loaded marker: the Studio has not fetched this entry's content, so
|
|
233
|
-
// the draft view cannot answer. (The engine asks for entries that pending
|
|
234
|
-
// patches touch, so this resolves itself for anything actually edited.)
|
|
235
|
-
return {
|
|
236
|
-
status: "unavailable"
|
|
237
|
-
};
|
|
238
|
-
}
|
|
81
|
+
function pageReadEnv(state, encode) {
|
|
82
|
+
var _state$draftSourcesSy;
|
|
239
83
|
return {
|
|
240
|
-
|
|
241
|
-
|
|
84
|
+
sources: [internal.overlaySource(state.store, {
|
|
85
|
+
draftMode: state.draftMode,
|
|
86
|
+
suspend: state.suspend,
|
|
87
|
+
draftModeReady: state.draftModeReady,
|
|
88
|
+
synced: (_state$draftSourcesSy = state.draftSourcesSynced) !== null && _state$draftSourcesSy !== void 0 ? _state$draftSourcesSy : false
|
|
89
|
+
}), internal.snapshotSource(state.snapshot)],
|
|
90
|
+
encode: encode
|
|
242
91
|
};
|
|
243
92
|
}
|
|
244
93
|
|
|
245
94
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* the content version the site serves, with entries filled in. The order the
|
|
249
|
-
* server renders in (`snapshotJsonEntry` in initValContent), so a draft page
|
|
250
|
-
* hydrates to what it was served rather than to the build's older entry.
|
|
95
|
+
* {@link pageReadEnv} for this component, kept while nothing it is made of
|
|
96
|
+
* moves, so a component's subscription is not made again on every render.
|
|
251
97
|
*/
|
|
252
|
-
function
|
|
253
|
-
var
|
|
254
|
-
|
|
98
|
+
function useReadEnv() {
|
|
99
|
+
var context = ValOverlayContext.useValOverlayContext();
|
|
100
|
+
var encode = useEncodesEditTags(context);
|
|
101
|
+
var store = context.store,
|
|
102
|
+
draftMode = context.draftMode,
|
|
103
|
+
suspend = context.suspend,
|
|
104
|
+
draftModeReady = context.draftModeReady,
|
|
105
|
+
draftSourcesSynced = context.draftSourcesSynced;
|
|
106
|
+
var snapshot = context.snapshot;
|
|
107
|
+
return React__default["default"].useMemo(function () {
|
|
108
|
+
return pageReadEnv({
|
|
109
|
+
store: store,
|
|
110
|
+
draftMode: draftMode,
|
|
111
|
+
suspend: suspend,
|
|
112
|
+
draftModeReady: draftModeReady,
|
|
113
|
+
draftSourcesSynced: draftSourcesSynced,
|
|
114
|
+
snapshot: snapshot
|
|
115
|
+
}, encode);
|
|
116
|
+
}, [store, draftMode, suspend, draftModeReady, draftSourcesSynced, snapshot, encode]);
|
|
255
117
|
}
|
|
256
118
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
119
|
+
/** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
|
|
120
|
+
|
|
121
|
+
function useValStega(selector) {
|
|
122
|
+
return internal.useResolvedVal(selector, useReadEnv());
|
|
123
|
+
}
|
|
260
124
|
|
|
261
125
|
/**
|
|
262
126
|
* Client counterpart to `fetchValKey`: resolves a SINGLE `.jsonValues()` entry
|
|
@@ -265,76 +129,10 @@ var jsonEntryPromiseCache = new Map();
|
|
|
265
129
|
* inside a `<Suspense>` boundary.
|
|
266
130
|
*
|
|
267
131
|
* In draft mode it renders the editor's unpublished content, taken from the
|
|
268
|
-
* overlay;
|
|
269
|
-
* entry's lazy import thunk from the local module.
|
|
132
|
+
* overlay; an entry the draft deleted is `undefined`, never the bundled one.
|
|
270
133
|
*/
|
|
271
134
|
function useValKeyStega(selector, key) {
|
|
272
|
-
|
|
273
|
-
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
274
|
-
var encodes = useEncodesEditTags(valOverlayContext);
|
|
275
|
-
// A view is a pointer: everything below reads a path, a schema and a source
|
|
276
|
-
// off this, and a pointer has none of them. See `resolveViewedModule`.
|
|
277
|
-
var valModule = core.Internal.resolveViewedModule(selector);
|
|
278
|
-
var moduleFilePath = valModule && core.Internal.getValPath(valModule);
|
|
279
|
-
var draftSource = useDraftModuleSource(moduleFilePath || undefined);
|
|
280
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn4 = valOverlayContext.snapshot) === null || _valOverlayContext$sn4 === void 0 ? void 0 : _valOverlayContext$sn4[moduleFilePath]), key);
|
|
281
|
-
if (draft.status === "absent") {
|
|
282
|
-
// Deleted in the draft state. Falling back to the bundled entry here would
|
|
283
|
-
// render content the editor has just removed.
|
|
284
|
-
return undefined;
|
|
285
|
-
}
|
|
286
|
-
var content = draft.status === "content" ? draft.content : undefined;
|
|
287
|
-
if (content === undefined) {
|
|
288
|
-
content = readCommittedJsonEntry(valModule, key);
|
|
289
|
-
}
|
|
290
|
-
return stega.stegaEncode(content, {
|
|
291
|
-
disabled: !encodes,
|
|
292
|
-
root: routeFromVal.getJsonEntryStegaRoot(valModule, key)
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* The entry's content as bundled: its lazy import thunk, resolved through
|
|
298
|
-
* `React.use` so the caller suspends until it lands.
|
|
299
|
-
*
|
|
300
|
-
* Deliberately not named `use*`: it is called conditionally, which is fine
|
|
301
|
-
* because `React.use` is not a hook, but a `use*` name would read like one.
|
|
302
|
-
*/
|
|
303
|
-
function readCommittedJsonEntry(selector, key) {
|
|
304
|
-
var source = selector && core.Internal.getSource(selector);
|
|
305
|
-
var marker = source && _typeof._typeof(source) === "object" ? source[key] : undefined;
|
|
306
|
-
if (!core.Internal.isJson(marker)) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
var thunk = core.Internal.getJsonImport(marker);
|
|
310
|
-
if (!thunk) {
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
var promise = committedJsonEntryPromise(selector, core.Internal.getValPath(selector), key);
|
|
314
|
-
return promise === undefined ? undefined : React__default["default"].use(promise);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* The bundle's import of one entry, started once and kept, so every render
|
|
319
|
-
* that waits on it is handed the same promise (`React.use` needs that).
|
|
320
|
-
* `undefined` when the module has no import for `key`.
|
|
321
|
-
*/
|
|
322
|
-
function committedJsonEntryPromise(
|
|
323
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
324
|
-
module, modulePath, key) {
|
|
325
|
-
var cacheKey = "".concat(modulePath !== null && modulePath !== void 0 ? modulePath : "", " ").concat(key);
|
|
326
|
-
var promise = jsonEntryPromiseCache.get(cacheKey);
|
|
327
|
-
if (!promise) {
|
|
328
|
-
var thunk = routeFromVal.bundledJsonEntryImport(module, key);
|
|
329
|
-
if (!thunk) {
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
promise = thunk().then(function (mod) {
|
|
333
|
-
return mod["default"];
|
|
334
|
-
});
|
|
335
|
-
jsonEntryPromiseCache.set(cacheKey, promise);
|
|
336
|
-
}
|
|
337
|
-
return promise;
|
|
135
|
+
return internal.useResolvedEntry(selector, key, useReadEnv());
|
|
338
136
|
}
|
|
339
137
|
function resolveParams(params) {
|
|
340
138
|
if (!params) {
|
|
@@ -353,66 +151,75 @@ function resolveParams(params) {
|
|
|
353
151
|
}
|
|
354
152
|
return params;
|
|
355
153
|
}
|
|
356
|
-
|
|
357
|
-
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* `useValRoute`'s read, once its params are known: a `.jsonValues()`
|
|
157
|
+
* router's one entry for the params (one dynamic import, like `useValKey`),
|
|
158
|
+
* or the router's entry for them. `null` for no such route.
|
|
159
|
+
*/
|
|
160
|
+
function routeRead(selector, params, env, settled) {
|
|
358
161
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
359
162
|
// off this, and a pointer has none of them. See `resolveViewedModule`.
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
var
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
var path = valModule && core.Internal.getValPath(valModule);
|
|
374
|
-
var schema = valModule && core.Internal.getSchema(valModule);
|
|
375
|
-
// `.jsonValues()` router: map params → the entry key and load ONLY that
|
|
376
|
-
// entry's backing `*.val.json` (one dynamic import), like `useValKey`.
|
|
377
|
-
if (routeFromVal.isJsonValuesRecordSchema(schema)) {
|
|
378
|
-
var _valOverlayContext$sn5;
|
|
379
|
-
var source = valModule && core.Internal.getSource(valModule);
|
|
380
|
-
var url = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRoute", path, schema, source);
|
|
163
|
+
return moduleRouteRead(core.Internal.resolveViewedModule(selector), params, env, settled);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* {@link routeRead}, for a module (a view resolved). A plain function, so the
|
|
168
|
+
* scenario world (`scenarios/`) reads a route as the hook does.
|
|
169
|
+
*/
|
|
170
|
+
function moduleRouteRead(valModule, params, env, settled) {
|
|
171
|
+
var path = core.Internal.getValPath(valModule);
|
|
172
|
+
var schema = core.Internal.getSchema(valModule);
|
|
173
|
+
if (internal.isJsonValuesRecordSchema(schema)) {
|
|
174
|
+
var url = routeFromVal.getValRouteUrlFromVal(params, "useValRoute", path, schema, core.Internal.getSource(valModule));
|
|
381
175
|
if (!url) {
|
|
382
|
-
return
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
var content = draft.status === "content" ? draft.content : undefined;
|
|
390
|
-
if (content === undefined) {
|
|
391
|
-
content = readCommittedJsonEntry(valModule, url);
|
|
176
|
+
return {
|
|
177
|
+
status: "ready",
|
|
178
|
+
value: null,
|
|
179
|
+
reads: []
|
|
180
|
+
};
|
|
392
181
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
disabled: !encodes,
|
|
398
|
-
root: routeFromVal.getJsonEntryStegaRoot(valModule, url)
|
|
182
|
+
return internal.mapResolution(internal.resolveModuleEntry(valModule, url, env, {
|
|
183
|
+
settled: settled
|
|
184
|
+
}), function (entry) {
|
|
185
|
+
return entry === undefined ? null : entry;
|
|
399
186
|
});
|
|
400
187
|
}
|
|
401
|
-
|
|
402
|
-
|
|
188
|
+
return internal.mapResolution(internal.resolveVal(valModule, env, {
|
|
189
|
+
settled: settled
|
|
190
|
+
}), function (val) {
|
|
191
|
+
return routeFromVal.initValRouteFromVal(params, "useValRoute", path, schema, val);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function useValRouteStega(selector, params) {
|
|
195
|
+
var env = useReadEnv();
|
|
196
|
+
var resolvedParams = resolveParams(params);
|
|
197
|
+
var value = internal.useResolved(selector, env, function (settled) {
|
|
198
|
+
return resolvedParams === null ? NO_ROUTE : routeRead(selector, resolvedParams || {}, env, settled);
|
|
199
|
+
});
|
|
200
|
+
// Careful: null means there was an error - undefined means no params
|
|
201
|
+
return resolvedParams === null ? null : value;
|
|
403
202
|
}
|
|
203
|
+
var NO_ROUTE = {
|
|
204
|
+
status: "ready",
|
|
205
|
+
value: null,
|
|
206
|
+
reads: []
|
|
207
|
+
};
|
|
404
208
|
function useValRouteUrl(selector, params) {
|
|
405
209
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
406
210
|
// off this, and a pointer has none of them. See `resolveViewedModule`.
|
|
407
211
|
var valModule = core.Internal.resolveViewedModule(selector);
|
|
408
|
-
|
|
212
|
+
// The url is made of the params and the module's path: a `.jsonValues()`
|
|
213
|
+
// router's entries are not imported for it.
|
|
214
|
+
var val = internal.useResolvedVal(valModule, useReadEnv(), {
|
|
215
|
+
entries: false
|
|
216
|
+
});
|
|
409
217
|
var resolvedParams = params === undefined ? undefined : resolveParams(params);
|
|
410
218
|
// Careful: null means there was an error - undefined means no params
|
|
411
219
|
if (resolvedParams === null) {
|
|
412
220
|
return null;
|
|
413
221
|
}
|
|
414
|
-
|
|
415
|
-
return route;
|
|
222
|
+
return routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", valModule && core.Internal.getValPath(valModule), valModule && core.Internal.getSchema(valModule), val);
|
|
416
223
|
}
|
|
417
224
|
|
|
418
225
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|