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