@valbuild/tanstack 0.144.10 → 0.144.12
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 +23 -0
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +59 -19
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +59 -19
- package/client/dist/valbuild-tanstack-client.esm.js +59 -19
- package/dist/{routeFromVal-97111bfd.cjs.dev.js → routeFromVal-385ee69c.cjs.dev.js} +113 -0
- package/dist/{routeFromVal-1221e70d.esm.js → routeFromVal-ae54a17e.esm.js} +112 -2
- package/dist/{routeFromVal-0b39e8e3.cjs.prod.js → routeFromVal-ffa948ef.cjs.prod.js} +113 -0
- package/dist/valbuild-tanstack.cjs.dev.js +1 -1
- package/dist/valbuild-tanstack.cjs.prod.js +1 -1
- package/dist/valbuild-tanstack.esm.js +1 -1
- package/dist/{version-6e0e4528.esm.js → version-3f098960.esm.js} +1 -1
- package/dist/{version-81a4c051.cjs.dev.js → version-656fbc67.cjs.prod.js} +1 -1
- package/dist/{version-447804c2.cjs.prod.js → version-70bf0fb4.cjs.dev.js} +1 -1
- package/package.json +7 -7
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +368 -265
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +368 -265
- package/server/dist/valbuild-tanstack-server.esm.js +368 -265
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @valbuild/tanstack
|
|
2
2
|
|
|
3
|
+
## 0.144.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#854](https://github.com/valbuild/val/pull/854) [`2193e3a`](https://github.com/valbuild/val/commit/2193e3ae133cd05dd73d0937dde7c15c88417f71) Thanks [@freekh](https://github.com/freekh)! - `useVal` and `fetchVal` on a whole `.jsonValues()` record now give every entry's content. They gave each entry back empty in production, on the server and in the browser, because the record holds only a lazy import for each entry; content showed up only where a draft or a hosted content version supplied it. They now load every entry the record names, together. `useValKey` and `fetchValKey` still load only the entry they are asked for, which is the reader to use when a page shows one entry of a large record.
|
|
8
|
+
- Updated dependencies [[`2193e3a`](https://github.com/valbuild/val/commit/2193e3ae133cd05dd73d0937dde7c15c88417f71)]:
|
|
9
|
+
- @valbuild/ui@0.144.12
|
|
10
|
+
- @valbuild/react@0.144.12
|
|
11
|
+
- @valbuild/server@0.144.12
|
|
12
|
+
- @valbuild/language-server@0.144.12
|
|
13
|
+
- @valbuild/mcp@0.144.12
|
|
14
|
+
|
|
15
|
+
## 0.144.11
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`c606395`](https://github.com/valbuild/val/commit/c60639571f9e836726dfef38e6bd0defc503d726)]:
|
|
20
|
+
- @valbuild/ui@0.144.11
|
|
21
|
+
- @valbuild/react@0.144.11
|
|
22
|
+
- @valbuild/server@0.144.11
|
|
23
|
+
- @valbuild/language-server@0.144.11
|
|
24
|
+
- @valbuild/mcp@0.144.11
|
|
25
|
+
|
|
3
26
|
## 0.144.10
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var routeFromVal = require('../../dist/routeFromVal-
|
|
5
|
+
var routeFromVal = require('../../dist/routeFromVal-385ee69c.cjs.dev.js');
|
|
6
6
|
var core = require('@valbuild/core');
|
|
7
7
|
var stega = require('@valbuild/react/stega');
|
|
8
8
|
var React = require('react');
|
|
@@ -116,18 +116,43 @@ function useValStega(selector) {
|
|
|
116
116
|
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && !valOverlayContext.draftSourcesSynced && store && !store.hasAllLoaded(moduleIds)) {
|
|
117
117
|
React__default["default"].use(store.waitForLoad(moduleIds));
|
|
118
118
|
}
|
|
119
|
+
var sourceOf = function sourceOf(moduleId) {
|
|
120
|
+
var _valOverlayContext$sn;
|
|
121
|
+
if (moduleMap && valOverlayContext.draftMode) {
|
|
122
|
+
var draft = moduleMap[moduleId];
|
|
123
|
+
if (draft !== undefined) {
|
|
124
|
+
return draft;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// At a proposal's address: its saved Source, not the bundle's.
|
|
128
|
+
return (_valOverlayContext$sn = valOverlayContext.snapshot) === null || _valOverlayContext$sn === void 0 ? void 0 : _valOverlayContext$sn[moduleId];
|
|
129
|
+
};
|
|
130
|
+
/*
|
|
131
|
+
* A whole `.jsonValues()` record is read with every entry's content: its own
|
|
132
|
+
* source holds only lazy markers. The entries no draft or snapshot has are
|
|
133
|
+
* imported from the bundle -- all of them started before waiting on any, so
|
|
134
|
+
* they load together. `useValKey` is the reader for one entry.
|
|
135
|
+
*/
|
|
136
|
+
var jsonValues = routeFromVal.jsonValuesRecordToFill(selector, function (modulePath) {
|
|
137
|
+
var _valOverlayContext$sn2;
|
|
138
|
+
return [moduleMap && valOverlayContext.draftMode ? moduleMap[modulePath] : undefined, (_valOverlayContext$sn2 = valOverlayContext.snapshot) === null || _valOverlayContext$sn2 === void 0 ? void 0 : _valOverlayContext$sn2[modulePath]];
|
|
139
|
+
});
|
|
140
|
+
var filledRecord = null;
|
|
141
|
+
if (jsonValues !== null) {
|
|
142
|
+
var pending = jsonValues.load.map(function (key) {
|
|
143
|
+
return committedJsonEntryPromise(jsonValues.module, jsonValues.modulePath, key);
|
|
144
|
+
});
|
|
145
|
+
var loaded = {};
|
|
146
|
+
jsonValues.load.forEach(function (key, index) {
|
|
147
|
+
var promise = pending[index];
|
|
148
|
+
loaded[key] = promise === undefined ? undefined : React__default["default"].use(promise);
|
|
149
|
+
});
|
|
150
|
+
filledRecord = routeFromVal.fillJsonValuesRecord(jsonValues.record, loaded);
|
|
151
|
+
}
|
|
119
152
|
return stega.stegaEncode(selector, {
|
|
120
153
|
disabled: !encodes,
|
|
121
154
|
getModule: function getModule(moduleId) {
|
|
122
|
-
|
|
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];
|
|
155
|
+
return jsonValues !== null && moduleId === jsonValues.modulePath ? filledRecord : sourceOf(moduleId);
|
|
131
156
|
}
|
|
132
157
|
});
|
|
133
158
|
}
|
|
@@ -142,7 +167,7 @@ function useValStega(selector) {
|
|
|
142
167
|
* correct in production, and stale the moment anyone edits in the Studio.
|
|
143
168
|
*/
|
|
144
169
|
function useDraftModuleSource(moduleFilePath) {
|
|
145
|
-
var _valOverlayContext$
|
|
170
|
+
var _valOverlayContext$sn3, _moduleMap$moduleFile;
|
|
146
171
|
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
147
172
|
var store = valOverlayContext.store;
|
|
148
173
|
var moduleIds = React__default["default"].useMemo(function () {
|
|
@@ -159,7 +184,7 @@ function useDraftModuleSource(moduleFilePath) {
|
|
|
159
184
|
return undefined;
|
|
160
185
|
}
|
|
161
186
|
// A proposal's saved Source stands in for the bundle's, draft or not.
|
|
162
|
-
var snapshot = (_valOverlayContext$
|
|
187
|
+
var snapshot = (_valOverlayContext$sn3 = valOverlayContext.snapshot) === null || _valOverlayContext$sn3 === void 0 ? void 0 : _valOverlayContext$sn3[moduleFilePath];
|
|
163
188
|
if (!valOverlayContext.draftMode) {
|
|
164
189
|
return snapshot;
|
|
165
190
|
}
|
|
@@ -234,7 +259,7 @@ var jsonEntryPromiseCache = new Map();
|
|
|
234
259
|
* entry's lazy import thunk from the local module.
|
|
235
260
|
*/
|
|
236
261
|
function useValKeyStega(selector, key) {
|
|
237
|
-
var _valOverlayContext$
|
|
262
|
+
var _valOverlayContext$sn4;
|
|
238
263
|
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
239
264
|
var encodes = useEncodesEditTags(valOverlayContext);
|
|
240
265
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
@@ -242,7 +267,7 @@ function useValKeyStega(selector, key) {
|
|
|
242
267
|
var valModule = core.Internal.resolveViewedModule(selector);
|
|
243
268
|
var moduleFilePath = valModule && core.Internal.getValPath(valModule);
|
|
244
269
|
var draftSource = useDraftModuleSource(moduleFilePath || undefined);
|
|
245
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
270
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn4 = valOverlayContext.snapshot) === null || _valOverlayContext$sn4 === void 0 ? void 0 : _valOverlayContext$sn4[moduleFilePath]), key);
|
|
246
271
|
if (draft.status === "absent") {
|
|
247
272
|
// Deleted in the draft state. Falling back to the bundled entry here would
|
|
248
273
|
// render content the editor has just removed.
|
|
@@ -266,7 +291,6 @@ function useValKeyStega(selector, key) {
|
|
|
266
291
|
* because `React.use` is not a hook, but a `use*` name would read like one.
|
|
267
292
|
*/
|
|
268
293
|
function readCommittedJsonEntry(selector, key) {
|
|
269
|
-
var _Internal$getValPath;
|
|
270
294
|
var source = selector && core.Internal.getSource(selector);
|
|
271
295
|
var marker = source && routeFromVal._typeof(source) === "object" ? source[key] : undefined;
|
|
272
296
|
if (!core.Internal.isJson(marker)) {
|
|
@@ -276,15 +300,31 @@ function readCommittedJsonEntry(selector, key) {
|
|
|
276
300
|
if (!thunk) {
|
|
277
301
|
return undefined;
|
|
278
302
|
}
|
|
279
|
-
var
|
|
303
|
+
var promise = committedJsonEntryPromise(selector, core.Internal.getValPath(selector), key);
|
|
304
|
+
return promise === undefined ? undefined : React__default["default"].use(promise);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The bundle's import of one entry, started once and kept, so every render
|
|
309
|
+
* that waits on it is handed the same promise (`React.use` needs that).
|
|
310
|
+
* `undefined` when the module has no import for `key`.
|
|
311
|
+
*/
|
|
312
|
+
function committedJsonEntryPromise(
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
314
|
+
module, modulePath, key) {
|
|
315
|
+
var cacheKey = "".concat(modulePath !== null && modulePath !== void 0 ? modulePath : "", " ").concat(key);
|
|
280
316
|
var promise = jsonEntryPromiseCache.get(cacheKey);
|
|
281
317
|
if (!promise) {
|
|
318
|
+
var thunk = routeFromVal.bundledJsonEntryImport(module, key);
|
|
319
|
+
if (!thunk) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
282
322
|
promise = thunk().then(function (mod) {
|
|
283
323
|
return mod["default"];
|
|
284
324
|
});
|
|
285
325
|
jsonEntryPromiseCache.set(cacheKey, promise);
|
|
286
326
|
}
|
|
287
|
-
return
|
|
327
|
+
return promise;
|
|
288
328
|
}
|
|
289
329
|
function resolveParams(params) {
|
|
290
330
|
if (!params) {
|
|
@@ -325,13 +365,13 @@ function useValRouteStega(selector, params) {
|
|
|
325
365
|
// `.jsonValues()` router: map params → the entry key and load ONLY that
|
|
326
366
|
// entry's backing `*.val.json` (one dynamic import), like `useValKey`.
|
|
327
367
|
if (routeFromVal.isJsonValuesRecordSchema(schema)) {
|
|
328
|
-
var _valOverlayContext$
|
|
368
|
+
var _valOverlayContext$sn5;
|
|
329
369
|
var source = valModule && core.Internal.getSource(valModule);
|
|
330
370
|
var url = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRoute", path, schema, source);
|
|
331
371
|
if (!url) {
|
|
332
372
|
return null;
|
|
333
373
|
}
|
|
334
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
374
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn5 = valOverlayContext.snapshot) === null || _valOverlayContext$sn5 === void 0 ? void 0 : _valOverlayContext$sn5[moduleFilePath]), url);
|
|
335
375
|
if (draft.status === "absent") {
|
|
336
376
|
// The draft state says this route is gone — see useValKeyStega.
|
|
337
377
|
return null;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var routeFromVal = require('../../dist/routeFromVal-
|
|
5
|
+
var routeFromVal = require('../../dist/routeFromVal-ffa948ef.cjs.prod.js');
|
|
6
6
|
var core = require('@valbuild/core');
|
|
7
7
|
var stega = require('@valbuild/react/stega');
|
|
8
8
|
var React = require('react');
|
|
@@ -116,18 +116,43 @@ function useValStega(selector) {
|
|
|
116
116
|
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && !valOverlayContext.draftSourcesSynced && store && !store.hasAllLoaded(moduleIds)) {
|
|
117
117
|
React__default["default"].use(store.waitForLoad(moduleIds));
|
|
118
118
|
}
|
|
119
|
+
var sourceOf = function sourceOf(moduleId) {
|
|
120
|
+
var _valOverlayContext$sn;
|
|
121
|
+
if (moduleMap && valOverlayContext.draftMode) {
|
|
122
|
+
var draft = moduleMap[moduleId];
|
|
123
|
+
if (draft !== undefined) {
|
|
124
|
+
return draft;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// At a proposal's address: its saved Source, not the bundle's.
|
|
128
|
+
return (_valOverlayContext$sn = valOverlayContext.snapshot) === null || _valOverlayContext$sn === void 0 ? void 0 : _valOverlayContext$sn[moduleId];
|
|
129
|
+
};
|
|
130
|
+
/*
|
|
131
|
+
* A whole `.jsonValues()` record is read with every entry's content: its own
|
|
132
|
+
* source holds only lazy markers. The entries no draft or snapshot has are
|
|
133
|
+
* imported from the bundle -- all of them started before waiting on any, so
|
|
134
|
+
* they load together. `useValKey` is the reader for one entry.
|
|
135
|
+
*/
|
|
136
|
+
var jsonValues = routeFromVal.jsonValuesRecordToFill(selector, function (modulePath) {
|
|
137
|
+
var _valOverlayContext$sn2;
|
|
138
|
+
return [moduleMap && valOverlayContext.draftMode ? moduleMap[modulePath] : undefined, (_valOverlayContext$sn2 = valOverlayContext.snapshot) === null || _valOverlayContext$sn2 === void 0 ? void 0 : _valOverlayContext$sn2[modulePath]];
|
|
139
|
+
});
|
|
140
|
+
var filledRecord = null;
|
|
141
|
+
if (jsonValues !== null) {
|
|
142
|
+
var pending = jsonValues.load.map(function (key) {
|
|
143
|
+
return committedJsonEntryPromise(jsonValues.module, jsonValues.modulePath, key);
|
|
144
|
+
});
|
|
145
|
+
var loaded = {};
|
|
146
|
+
jsonValues.load.forEach(function (key, index) {
|
|
147
|
+
var promise = pending[index];
|
|
148
|
+
loaded[key] = promise === undefined ? undefined : React__default["default"].use(promise);
|
|
149
|
+
});
|
|
150
|
+
filledRecord = routeFromVal.fillJsonValuesRecord(jsonValues.record, loaded);
|
|
151
|
+
}
|
|
119
152
|
return stega.stegaEncode(selector, {
|
|
120
153
|
disabled: !encodes,
|
|
121
154
|
getModule: function getModule(moduleId) {
|
|
122
|
-
|
|
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];
|
|
155
|
+
return jsonValues !== null && moduleId === jsonValues.modulePath ? filledRecord : sourceOf(moduleId);
|
|
131
156
|
}
|
|
132
157
|
});
|
|
133
158
|
}
|
|
@@ -142,7 +167,7 @@ function useValStega(selector) {
|
|
|
142
167
|
* correct in production, and stale the moment anyone edits in the Studio.
|
|
143
168
|
*/
|
|
144
169
|
function useDraftModuleSource(moduleFilePath) {
|
|
145
|
-
var _valOverlayContext$
|
|
170
|
+
var _valOverlayContext$sn3, _moduleMap$moduleFile;
|
|
146
171
|
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
147
172
|
var store = valOverlayContext.store;
|
|
148
173
|
var moduleIds = React__default["default"].useMemo(function () {
|
|
@@ -159,7 +184,7 @@ function useDraftModuleSource(moduleFilePath) {
|
|
|
159
184
|
return undefined;
|
|
160
185
|
}
|
|
161
186
|
// A proposal's saved Source stands in for the bundle's, draft or not.
|
|
162
|
-
var snapshot = (_valOverlayContext$
|
|
187
|
+
var snapshot = (_valOverlayContext$sn3 = valOverlayContext.snapshot) === null || _valOverlayContext$sn3 === void 0 ? void 0 : _valOverlayContext$sn3[moduleFilePath];
|
|
163
188
|
if (!valOverlayContext.draftMode) {
|
|
164
189
|
return snapshot;
|
|
165
190
|
}
|
|
@@ -234,7 +259,7 @@ var jsonEntryPromiseCache = new Map();
|
|
|
234
259
|
* entry's lazy import thunk from the local module.
|
|
235
260
|
*/
|
|
236
261
|
function useValKeyStega(selector, key) {
|
|
237
|
-
var _valOverlayContext$
|
|
262
|
+
var _valOverlayContext$sn4;
|
|
238
263
|
var valOverlayContext = ValOverlayContext.useValOverlayContext();
|
|
239
264
|
var encodes = useEncodesEditTags(valOverlayContext);
|
|
240
265
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
@@ -242,7 +267,7 @@ function useValKeyStega(selector, key) {
|
|
|
242
267
|
var valModule = core.Internal.resolveViewedModule(selector);
|
|
243
268
|
var moduleFilePath = valModule && core.Internal.getValPath(valModule);
|
|
244
269
|
var draftSource = useDraftModuleSource(moduleFilePath || undefined);
|
|
245
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
270
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn4 = valOverlayContext.snapshot) === null || _valOverlayContext$sn4 === void 0 ? void 0 : _valOverlayContext$sn4[moduleFilePath]), key);
|
|
246
271
|
if (draft.status === "absent") {
|
|
247
272
|
// Deleted in the draft state. Falling back to the bundled entry here would
|
|
248
273
|
// render content the editor has just removed.
|
|
@@ -266,7 +291,6 @@ function useValKeyStega(selector, key) {
|
|
|
266
291
|
* because `React.use` is not a hook, but a `use*` name would read like one.
|
|
267
292
|
*/
|
|
268
293
|
function readCommittedJsonEntry(selector, key) {
|
|
269
|
-
var _Internal$getValPath;
|
|
270
294
|
var source = selector && core.Internal.getSource(selector);
|
|
271
295
|
var marker = source && routeFromVal._typeof(source) === "object" ? source[key] : undefined;
|
|
272
296
|
if (!core.Internal.isJson(marker)) {
|
|
@@ -276,15 +300,31 @@ function readCommittedJsonEntry(selector, key) {
|
|
|
276
300
|
if (!thunk) {
|
|
277
301
|
return undefined;
|
|
278
302
|
}
|
|
279
|
-
var
|
|
303
|
+
var promise = committedJsonEntryPromise(selector, core.Internal.getValPath(selector), key);
|
|
304
|
+
return promise === undefined ? undefined : React__default["default"].use(promise);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The bundle's import of one entry, started once and kept, so every render
|
|
309
|
+
* that waits on it is handed the same promise (`React.use` needs that).
|
|
310
|
+
* `undefined` when the module has no import for `key`.
|
|
311
|
+
*/
|
|
312
|
+
function committedJsonEntryPromise(
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
314
|
+
module, modulePath, key) {
|
|
315
|
+
var cacheKey = "".concat(modulePath !== null && modulePath !== void 0 ? modulePath : "", " ").concat(key);
|
|
280
316
|
var promise = jsonEntryPromiseCache.get(cacheKey);
|
|
281
317
|
if (!promise) {
|
|
318
|
+
var thunk = routeFromVal.bundledJsonEntryImport(module, key);
|
|
319
|
+
if (!thunk) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
282
322
|
promise = thunk().then(function (mod) {
|
|
283
323
|
return mod["default"];
|
|
284
324
|
});
|
|
285
325
|
jsonEntryPromiseCache.set(cacheKey, promise);
|
|
286
326
|
}
|
|
287
|
-
return
|
|
327
|
+
return promise;
|
|
288
328
|
}
|
|
289
329
|
function resolveParams(params) {
|
|
290
330
|
if (!params) {
|
|
@@ -325,13 +365,13 @@ function useValRouteStega(selector, params) {
|
|
|
325
365
|
// `.jsonValues()` router: map params → the entry key and load ONLY that
|
|
326
366
|
// entry's backing `*.val.json` (one dynamic import), like `useValKey`.
|
|
327
367
|
if (routeFromVal.isJsonValuesRecordSchema(schema)) {
|
|
328
|
-
var _valOverlayContext$
|
|
368
|
+
var _valOverlayContext$sn5;
|
|
329
369
|
var source = valModule && core.Internal.getSource(valModule);
|
|
330
370
|
var url = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRoute", path, schema, source);
|
|
331
371
|
if (!url) {
|
|
332
372
|
return null;
|
|
333
373
|
}
|
|
334
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
374
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn5 = valOverlayContext.snapshot) === null || _valOverlayContext$sn5 === void 0 ? void 0 : _valOverlayContext$sn5[moduleFilePath]), url);
|
|
335
375
|
if (draft.status === "absent") {
|
|
336
376
|
// The draft state says this route is gone — see useValKeyStega.
|
|
337
377
|
return null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getJsonEntryStegaRoot, _ as _typeof, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal,
|
|
1
|
+
import { j as jsonValuesRecordToFill, f as fillJsonValuesRecord, g as getJsonEntryStegaRoot, _ as _typeof, b as bundledJsonEntryImport, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal, c as initValRouteFromVal } from '../../dist/routeFromVal-ae54a17e.esm.js';
|
|
2
2
|
import { Internal } from '@valbuild/core';
|
|
3
3
|
import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
|
|
4
4
|
import React from 'react';
|
|
@@ -108,18 +108,43 @@ function useValStega(selector) {
|
|
|
108
108
|
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && !valOverlayContext.draftSourcesSynced && store && !store.hasAllLoaded(moduleIds)) {
|
|
109
109
|
React.use(store.waitForLoad(moduleIds));
|
|
110
110
|
}
|
|
111
|
+
var sourceOf = function sourceOf(moduleId) {
|
|
112
|
+
var _valOverlayContext$sn;
|
|
113
|
+
if (moduleMap && valOverlayContext.draftMode) {
|
|
114
|
+
var draft = moduleMap[moduleId];
|
|
115
|
+
if (draft !== undefined) {
|
|
116
|
+
return draft;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// At a proposal's address: its saved Source, not the bundle's.
|
|
120
|
+
return (_valOverlayContext$sn = valOverlayContext.snapshot) === null || _valOverlayContext$sn === void 0 ? void 0 : _valOverlayContext$sn[moduleId];
|
|
121
|
+
};
|
|
122
|
+
/*
|
|
123
|
+
* A whole `.jsonValues()` record is read with every entry's content: its own
|
|
124
|
+
* source holds only lazy markers. The entries no draft or snapshot has are
|
|
125
|
+
* imported from the bundle -- all of them started before waiting on any, so
|
|
126
|
+
* they load together. `useValKey` is the reader for one entry.
|
|
127
|
+
*/
|
|
128
|
+
var jsonValues = jsonValuesRecordToFill(selector, function (modulePath) {
|
|
129
|
+
var _valOverlayContext$sn2;
|
|
130
|
+
return [moduleMap && valOverlayContext.draftMode ? moduleMap[modulePath] : undefined, (_valOverlayContext$sn2 = valOverlayContext.snapshot) === null || _valOverlayContext$sn2 === void 0 ? void 0 : _valOverlayContext$sn2[modulePath]];
|
|
131
|
+
});
|
|
132
|
+
var filledRecord = null;
|
|
133
|
+
if (jsonValues !== null) {
|
|
134
|
+
var pending = jsonValues.load.map(function (key) {
|
|
135
|
+
return committedJsonEntryPromise(jsonValues.module, jsonValues.modulePath, key);
|
|
136
|
+
});
|
|
137
|
+
var loaded = {};
|
|
138
|
+
jsonValues.load.forEach(function (key, index) {
|
|
139
|
+
var promise = pending[index];
|
|
140
|
+
loaded[key] = promise === undefined ? undefined : React.use(promise);
|
|
141
|
+
});
|
|
142
|
+
filledRecord = fillJsonValuesRecord(jsonValues.record, loaded);
|
|
143
|
+
}
|
|
111
144
|
return stegaEncode(selector, {
|
|
112
145
|
disabled: !encodes,
|
|
113
146
|
getModule: function getModule(moduleId) {
|
|
114
|
-
|
|
115
|
-
if (moduleMap && valOverlayContext.draftMode) {
|
|
116
|
-
var draft = moduleMap[moduleId];
|
|
117
|
-
if (draft !== undefined) {
|
|
118
|
-
return draft;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// At a proposal's address: its saved Source, not the bundle's.
|
|
122
|
-
return (_valOverlayContext$sn = valOverlayContext.snapshot) === null || _valOverlayContext$sn === void 0 ? void 0 : _valOverlayContext$sn[moduleId];
|
|
147
|
+
return jsonValues !== null && moduleId === jsonValues.modulePath ? filledRecord : sourceOf(moduleId);
|
|
123
148
|
}
|
|
124
149
|
});
|
|
125
150
|
}
|
|
@@ -134,7 +159,7 @@ function useValStega(selector) {
|
|
|
134
159
|
* correct in production, and stale the moment anyone edits in the Studio.
|
|
135
160
|
*/
|
|
136
161
|
function useDraftModuleSource(moduleFilePath) {
|
|
137
|
-
var _valOverlayContext$
|
|
162
|
+
var _valOverlayContext$sn3, _moduleMap$moduleFile;
|
|
138
163
|
var valOverlayContext = useValOverlayContext();
|
|
139
164
|
var store = valOverlayContext.store;
|
|
140
165
|
var moduleIds = React.useMemo(function () {
|
|
@@ -151,7 +176,7 @@ function useDraftModuleSource(moduleFilePath) {
|
|
|
151
176
|
return undefined;
|
|
152
177
|
}
|
|
153
178
|
// A proposal's saved Source stands in for the bundle's, draft or not.
|
|
154
|
-
var snapshot = (_valOverlayContext$
|
|
179
|
+
var snapshot = (_valOverlayContext$sn3 = valOverlayContext.snapshot) === null || _valOverlayContext$sn3 === void 0 ? void 0 : _valOverlayContext$sn3[moduleFilePath];
|
|
155
180
|
if (!valOverlayContext.draftMode) {
|
|
156
181
|
return snapshot;
|
|
157
182
|
}
|
|
@@ -226,7 +251,7 @@ var jsonEntryPromiseCache = new Map();
|
|
|
226
251
|
* entry's lazy import thunk from the local module.
|
|
227
252
|
*/
|
|
228
253
|
function useValKeyStega(selector, key) {
|
|
229
|
-
var _valOverlayContext$
|
|
254
|
+
var _valOverlayContext$sn4;
|
|
230
255
|
var valOverlayContext = useValOverlayContext();
|
|
231
256
|
var encodes = useEncodesEditTags(valOverlayContext);
|
|
232
257
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
@@ -234,7 +259,7 @@ function useValKeyStega(selector, key) {
|
|
|
234
259
|
var valModule = Internal.resolveViewedModule(selector);
|
|
235
260
|
var moduleFilePath = valModule && Internal.getValPath(valModule);
|
|
236
261
|
var draftSource = useDraftModuleSource(moduleFilePath || undefined);
|
|
237
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
262
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn4 = valOverlayContext.snapshot) === null || _valOverlayContext$sn4 === void 0 ? void 0 : _valOverlayContext$sn4[moduleFilePath]), key);
|
|
238
263
|
if (draft.status === "absent") {
|
|
239
264
|
// Deleted in the draft state. Falling back to the bundled entry here would
|
|
240
265
|
// render content the editor has just removed.
|
|
@@ -258,7 +283,6 @@ function useValKeyStega(selector, key) {
|
|
|
258
283
|
* because `React.use` is not a hook, but a `use*` name would read like one.
|
|
259
284
|
*/
|
|
260
285
|
function readCommittedJsonEntry(selector, key) {
|
|
261
|
-
var _Internal$getValPath;
|
|
262
286
|
var source = selector && Internal.getSource(selector);
|
|
263
287
|
var marker = source && _typeof(source) === "object" ? source[key] : undefined;
|
|
264
288
|
if (!Internal.isJson(marker)) {
|
|
@@ -268,15 +292,31 @@ function readCommittedJsonEntry(selector, key) {
|
|
|
268
292
|
if (!thunk) {
|
|
269
293
|
return undefined;
|
|
270
294
|
}
|
|
271
|
-
var
|
|
295
|
+
var promise = committedJsonEntryPromise(selector, Internal.getValPath(selector), key);
|
|
296
|
+
return promise === undefined ? undefined : React.use(promise);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The bundle's import of one entry, started once and kept, so every render
|
|
301
|
+
* that waits on it is handed the same promise (`React.use` needs that).
|
|
302
|
+
* `undefined` when the module has no import for `key`.
|
|
303
|
+
*/
|
|
304
|
+
function committedJsonEntryPromise(
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
306
|
+
module, modulePath, key) {
|
|
307
|
+
var cacheKey = "".concat(modulePath !== null && modulePath !== void 0 ? modulePath : "", " ").concat(key);
|
|
272
308
|
var promise = jsonEntryPromiseCache.get(cacheKey);
|
|
273
309
|
if (!promise) {
|
|
310
|
+
var thunk = bundledJsonEntryImport(module, key);
|
|
311
|
+
if (!thunk) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
274
314
|
promise = thunk().then(function (mod) {
|
|
275
315
|
return mod["default"];
|
|
276
316
|
});
|
|
277
317
|
jsonEntryPromiseCache.set(cacheKey, promise);
|
|
278
318
|
}
|
|
279
|
-
return
|
|
319
|
+
return promise;
|
|
280
320
|
}
|
|
281
321
|
function resolveParams(params) {
|
|
282
322
|
if (!params) {
|
|
@@ -317,13 +357,13 @@ function useValRouteStega(selector, params) {
|
|
|
317
357
|
// `.jsonValues()` router: map params → the entry key and load ONLY that
|
|
318
358
|
// entry's backing `*.val.json` (one dynamic import), like `useValKey`.
|
|
319
359
|
if (isJsonValuesRecordSchema(schema)) {
|
|
320
|
-
var _valOverlayContext$
|
|
360
|
+
var _valOverlayContext$sn5;
|
|
321
361
|
var source = valModule && Internal.getSource(valModule);
|
|
322
362
|
var url = getValRouteUrlFromVal(resolvedParams || {}, "useValRoute", path, schema, source);
|
|
323
363
|
if (!url) {
|
|
324
364
|
return null;
|
|
325
365
|
}
|
|
326
|
-
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$
|
|
366
|
+
var draft = draftOrSnapshotJsonEntry(draftSource, moduleFilePath && ((_valOverlayContext$sn5 = valOverlayContext.snapshot) === null || _valOverlayContext$sn5 === void 0 ? void 0 : _valOverlayContext$sn5[moduleFilePath]), url);
|
|
327
367
|
if (draft.status === "absent") {
|
|
328
368
|
// The draft state says this route is gone — see useValKeyStega.
|
|
329
369
|
return null;
|
|
@@ -23,6 +23,116 @@ function isJsonValuesRecordSchema(schema) {
|
|
|
23
23
|
return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
24
24
|
}
|
|
25
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 = core.Internal.resolveViewedModule(selector);
|
|
50
|
+
if (!module || !isJsonValuesRecordSchema(core.Internal.getSchema(module))) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
var modulePath = core.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 : core.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 = createForOfIteratorHelper._slicedToArray(_Object$entries[_i], 2),
|
|
72
|
+
key = _Object$entries$_i[0],
|
|
73
|
+
entry = _Object$entries$_i[1];
|
|
74
|
+
if (!core.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 && !core.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 = createForOfIteratorHelper._objectSpread2({}, record);
|
|
109
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
|
|
110
|
+
var _Object$entries2$_i = createForOfIteratorHelper._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 && core.Internal.getSource(module);
|
|
129
|
+
var marker = _typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
|
|
130
|
+
if (!core.Internal.isJson(marker)) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return (_Internal$getJsonImpo = core.Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
26
136
|
/**
|
|
27
137
|
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
28
138
|
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
@@ -212,7 +322,10 @@ val) {
|
|
|
212
322
|
}
|
|
213
323
|
|
|
214
324
|
exports._typeof = _typeof;
|
|
325
|
+
exports.bundledJsonEntryImport = bundledJsonEntryImport;
|
|
326
|
+
exports.fillJsonValuesRecord = fillJsonValuesRecord;
|
|
215
327
|
exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
|
|
216
328
|
exports.getValRouteUrlFromVal = getValRouteUrlFromVal;
|
|
217
329
|
exports.initValRouteFromVal = initValRouteFromVal;
|
|
218
330
|
exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
|
|
331
|
+
exports.jsonValuesRecordToFill = jsonValuesRecordToFill;
|