@valbuild/react 0.150.22 → 0.151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/dist/declarations/src/internal/index.d.ts +1 -0
  3. package/dist/declarations/src/read/draft.d.ts +105 -0
  4. package/dist/declarations/src/read/index.d.ts +8 -0
  5. package/dist/declarations/src/read/jsonValues.d.ts +26 -0
  6. package/dist/declarations/src/read/layered.d.ts +45 -0
  7. package/dist/declarations/src/read/overlayStore.d.ts +113 -0
  8. package/dist/declarations/src/read/readers.d.ts +51 -0
  9. package/dist/declarations/src/read/refreshLoop.d.ts +61 -0
  10. package/dist/declarations/src/read/resolveVal.d.ts +93 -0
  11. package/dist/declarations/src/read/sources.d.ts +63 -0
  12. package/dist/{raw-be4b57fa.browser.esm.js → raw-15ce77ae.browser.esm.js} +1 -1
  13. package/dist/{raw-1b40484b.esm.js → raw-534fcde0.esm.js} +1 -1
  14. package/dist/{raw-43f9221a.worker.esm.js → raw-645a854a.worker.esm.js} +1 -1
  15. package/dist/{raw-ff060f24.cjs.dev.js → raw-67d24dd6.cjs.dev.js} +2 -0
  16. package/dist/{raw-b3745603.cjs.prod.js → raw-d504f4fd.cjs.prod.js} +2 -0
  17. package/internal/dist/valbuild-react-internal.browser.esm.js +1723 -6
  18. package/internal/dist/valbuild-react-internal.cjs.dev.js +1748 -4
  19. package/internal/dist/valbuild-react-internal.cjs.prod.js +1748 -4
  20. package/internal/dist/valbuild-react-internal.esm.js +1723 -6
  21. package/internal/dist/valbuild-react-internal.worker.esm.js +1723 -6
  22. package/package.json +4 -4
  23. package/stega/dist/valbuild-react-stega.browser.esm.js +2 -2
  24. package/stega/dist/valbuild-react-stega.cjs.dev.js +1 -1
  25. package/stega/dist/valbuild-react-stega.cjs.prod.js +1 -1
  26. package/stega/dist/valbuild-react-stega.esm.js +2 -2
  27. package/stega/dist/valbuild-react-stega.worker.esm.js +2 -2
@@ -3,12 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-522d616d.cjs.dev.js');
6
- var raw = require('../../dist/raw-ff060f24.cjs.dev.js');
6
+ var raw = require('../../dist/raw-67d24dd6.cjs.dev.js');
7
7
  var React = require('react');
8
8
  var ReactJSXRuntime = require('react/jsx-runtime');
9
- require('../../dist/slicedToArray-387314c6.cjs.dev.js');
10
- require('../../dist/typeof-b568f48f.cjs.dev.js');
11
- require('@valbuild/core');
9
+ var _typeof = require('../../dist/typeof-b568f48f.cjs.dev.js');
10
+ var core = require('@valbuild/core');
11
+ var patch = require('@valbuild/core/patch');
12
+ var slicedToArray = require('../../dist/slicedToArray-387314c6.cjs.dev.js');
12
13
  require('@vercel/stega');
13
14
 
14
15
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -155,4 +156,1747 @@ function classNameOfTag(tag, style, theme) {
155
156
  }))).join(" ");
156
157
  }
157
158
 
159
+ function _classCallCheck(a, n) {
160
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
161
+ }
162
+
163
+ function _defineProperties(e, r) {
164
+ for (var t = 0; t < r.length; t++) {
165
+ var o = r[t];
166
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, raw._toPropertyKey(o.key), o);
167
+ }
168
+ }
169
+ function _createClass(e, r, t) {
170
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
171
+ writable: !1
172
+ }), e;
173
+ }
174
+
175
+ // How long waitForLoad waits for draft data before giving up and resolving
176
+ // anyway (logging an error) so the Suspense boundary never hangs forever.
177
+ var LOAD_TIMEOUT_MS = 10000;
178
+
179
+ /** A read the overlay holds: always an answer. */
180
+
181
+ /**
182
+ * The page's store of what the Studio sent it: one read per module, as the
183
+ * relay sent it (`startOverlayRelay`). What `overlaySource` answers from.
184
+ *
185
+ * Moved here from `@valbuild/next` and `@valbuild/tanstack`, which each had a
186
+ * copy: the page's half of the relay is the same in both.
187
+ */
188
+ var ValExternalStore = /*#__PURE__*/function () {
189
+ function ValExternalStore() {
190
+ var _this = this;
191
+ _classCallCheck(this, ValExternalStore);
192
+ raw._defineProperty(this, "listeners", void 0);
193
+ raw._defineProperty(this, "loadPromises", void 0);
194
+ // Path-keyed reads, as the Studio sent them. The single source of truth:
195
+ // load state, snapshots and revisions are all derived from this, so data
196
+ // can be queried for any combination of paths even before a subscriber
197
+ // registers.
198
+ raw._defineProperty(this, "reads", void 0);
199
+ // Bumped per path whenever its read MOVES: what `revision` is made of.
200
+ raw._defineProperty(this, "revisions", void 0);
201
+ // Reference-stable per-subscriberId snapshot cache for `get`.
202
+ // Built lazily from `reads` in get() and invalidated in receive().
203
+ raw._defineProperty(this, "snapshots", void 0);
204
+ // One-shot listeners used solely by waitForLoad. Kept separate from the
205
+ // useSyncExternalStore listeners so waitForLoad never has to register (and
206
+ // leak) a subscriberId.
207
+ raw._defineProperty(this, "loadListeners", void 0);
208
+ raw._defineProperty(this, "subscribe", function (paths) {
209
+ return function (listener) {
210
+ var subscriberId = createSubscriberId(paths);
211
+ var existing = _this.listeners.get(subscriberId);
212
+ if (existing) {
213
+ existing.push(listener);
214
+ } else {
215
+ _this.listeners.set(subscriberId, [listener]);
216
+ }
217
+ return function () {
218
+ var current = _this.listeners.get(subscriberId);
219
+ if (!current) return;
220
+ var idx = current.indexOf(listener);
221
+ if (idx >= 0) current.splice(idx, 1);
222
+ if (current.length === 0) _this.listeners["delete"](subscriberId);
223
+ };
224
+ };
225
+ });
226
+ raw._defineProperty(this, "getSnapshot", function (paths) {
227
+ return function () {
228
+ return _this.get(paths);
229
+ };
230
+ });
231
+ raw._defineProperty(this, "getServerSnapshot", function (paths) {
232
+ return function () {
233
+ return _this.get(paths);
234
+ };
235
+ });
236
+ raw._defineProperty(this, "get", function (paths) {
237
+ var subscriberId = createSubscriberId(paths);
238
+ if (_this.snapshots.has(subscriberId)) {
239
+ return _this.snapshots.get(subscriberId);
240
+ }
241
+ // Build the snapshot from the path-keyed reads so data that arrived
242
+ // before this subscriber registered is still returned. Cache it for a
243
+ // reference-stable result.
244
+ var record;
245
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(paths),
246
+ _step;
247
+ try {
248
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
249
+ var p = _step.value;
250
+ var loaded = _this.reads.get(p);
251
+ if (loaded !== undefined) {
252
+ if (!record) {
253
+ record = {};
254
+ }
255
+ record[p] = loaded.source;
256
+ }
257
+ }
258
+ } catch (err) {
259
+ _iterator.e(err);
260
+ } finally {
261
+ _iterator.f();
262
+ }
263
+ _this.snapshots.set(subscriberId, record);
264
+ return record;
265
+ });
266
+ raw._defineProperty(this, "hasAllLoaded", function (paths) {
267
+ var _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(paths),
268
+ _step2;
269
+ try {
270
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
271
+ var p = _step2.value;
272
+ if (!_this.reads.has(p)) {
273
+ return false;
274
+ }
275
+ }
276
+ } catch (err) {
277
+ _iterator2.e(err);
278
+ } finally {
279
+ _iterator2.f();
280
+ }
281
+ return true;
282
+ });
283
+ /**
284
+ * Returns a cached promise that resolves once `update()` has populated
285
+ * every path in `paths`. The same promise instance is returned for the
286
+ * same paths until it resolves — required so `React.use` / classic
287
+ * Suspense doesn't re-suspend on every render.
288
+ *
289
+ * If the data never arrives (network failure, a path that is never
290
+ * `update()`'d, a typo in a module path) the promise would otherwise hang
291
+ * forever and keep the Suspense boundary in its fallback. To avoid a silent
292
+ * hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
293
+ * failure is diagnosable while the page still renders with partial data.
294
+ */
295
+ raw._defineProperty(this, "waitForLoad", function (paths) {
296
+ if (_this.hasAllLoaded(paths)) {
297
+ return Promise.resolve();
298
+ }
299
+ var subscriberId = createSubscriberId(paths);
300
+ var existing = _this.loadPromises.get(subscriberId);
301
+ if (existing) {
302
+ return existing;
303
+ }
304
+ var promise = new Promise(function (resolve) {
305
+ var cleanup = function cleanup() {
306
+ clearTimeout(timeout);
307
+ _this.loadListeners["delete"](listener);
308
+ _this.loadPromises["delete"](subscriberId);
309
+ };
310
+ var listener = function listener() {
311
+ if (_this.hasAllLoaded(paths)) {
312
+ cleanup();
313
+ resolve();
314
+ }
315
+ };
316
+ var timeout = setTimeout(function () {
317
+ var missing = paths.filter(function (p) {
318
+ return !_this.reads.has(p);
319
+ });
320
+ core.Internal.log.error("draft module(s) did not load within ".concat(LOAD_TIMEOUT_MS, "ms; rendering with partial data. Missing: ").concat(missing.join(", ")));
321
+ cleanup();
322
+ resolve();
323
+ }, LOAD_TIMEOUT_MS);
324
+ // Don't let the pending timer keep a Node process (e.g. the test runner
325
+ // or SSR) alive; setTimeout returns a number in the browser, where there
326
+ // is nothing to unref.
327
+ if (typeof timeout !== "number") {
328
+ timeout.unref();
329
+ }
330
+ _this.loadListeners.add(listener);
331
+ });
332
+ _this.loadPromises.set(subscriberId, promise);
333
+ return promise;
334
+ });
335
+ this.listeners = new Map();
336
+ this.loadPromises = new Map();
337
+ this.reads = new Map();
338
+ this.revisions = new Map();
339
+ this.snapshots = new Map();
340
+ this.loadListeners = new Set();
341
+ }
342
+ return _createClass(ValExternalStore, [{
343
+ key: "update",
344
+ value: /** {@link receive}, for a source with nothing more to say about it. */
345
+ function update(path, source) {
346
+ return this.receive(path, {
347
+ status: "ready",
348
+ source: source,
349
+ from: "overlay",
350
+ version: null
351
+ });
352
+ }
353
+
354
+ /**
355
+ * Take a module's read from the editor, as it sent it.
356
+ *
357
+ * Returns whether this actually MOVED the value, which the caller needs and
358
+ * cannot work out for itself: the same source arrives more than once by
359
+ * design. The editor sends a catch-up snapshot of everything it holds every
360
+ * time the page becomes a new document — a reload, or the one the dev server
361
+ * does when a publish rewrites the `.val.ts` files — and most of that
362
+ * snapshot is content this page already has.
363
+ *
364
+ * The answer tells the page's refresh loop whether the Studio's catch-up
365
+ * found the page behind (`startRefreshLoop`'s `changed`): a re-sent module
366
+ * the page already shows is no reason to re-read its server, and with
367
+ * auto-save on, counting arrivals was a whole-route request per pause in
368
+ * typing -- in development a re-render (and sometimes a recompile) of the
369
+ * page, and what left the canvas looking permanently busy.
370
+ */
371
+ }, {
372
+ key: "receive",
373
+ value: function receive(path, read) {
374
+ var _this$revisions$get;
375
+ // A miss means this page has never been given this module.
376
+ var before = this.reads.get(path);
377
+ var changed = before === undefined || !sameContent(before, read);
378
+ this.reads.set(path, read);
379
+ if (!changed) {
380
+ // Nothing downstream to do: every subscriber's snapshot still answers
381
+ // with the same value, so invalidating them would be a re-render that
382
+ // shows exactly what is already on screen.
383
+ return false;
384
+ }
385
+ this.revisions.set(path, ((_this$revisions$get = this.revisions.get(path)) !== null && _this$revisions$get !== void 0 ? _this$revisions$get : 0) + 1);
386
+ // Invalidate cached snapshots that include this path so the next get()
387
+ // rebuilds a fresh (new-reference) record, then notify their listeners.
388
+ for (var _i = 0, _Array$from = Array.from(this.snapshots.keys()); _i < _Array$from.length; _i++) {
389
+ var subscriberId = _Array$from[_i];
390
+ if (includesPath(subscriberId, path)) {
391
+ this.snapshots["delete"](subscriberId);
392
+ }
393
+ }
394
+ var _iterator3 = createForOfIteratorHelper._createForOfIteratorHelper(this.listeners.keys()),
395
+ _step3;
396
+ try {
397
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
398
+ var _subscriberId = _step3.value;
399
+ if (includesPath(_subscriberId, path)) {
400
+ this.emitChange(_subscriberId);
401
+ }
402
+ }
403
+ } catch (err) {
404
+ _iterator3.e(err);
405
+ } finally {
406
+ _iterator3.f();
407
+ }
408
+ for (var _i2 = 0, _Array$from2 = Array.from(this.loadListeners); _i2 < _Array$from2.length; _i2++) {
409
+ var listener = _Array$from2[_i2];
410
+ listener();
411
+ }
412
+ return true;
413
+ }
414
+
415
+ /** What the editor sent for `path`, or `undefined` for nothing yet. */
416
+ }, {
417
+ key: "read",
418
+ value: function read(path) {
419
+ return this.reads.get(path);
420
+ }
421
+
422
+ /**
423
+ * Changes exactly when what this store holds for any of `paths` moves: a
424
+ * `useSyncExternalStore` snapshot that is `===` while nothing moved.
425
+ */
426
+ }, {
427
+ key: "revision",
428
+ value: function revision(paths) {
429
+ var _this2 = this;
430
+ return paths.map(function (path) {
431
+ var _this2$revisions$get;
432
+ return (_this2$revisions$get = _this2.revisions.get(path)) !== null && _this2$revisions$get !== void 0 ? _this2$revisions$get : 0;
433
+ }).join(",");
434
+ }
435
+ }, {
436
+ key: "emitChange",
437
+ value: function emitChange(subscriberId) {
438
+ var _this$listeners$get;
439
+ var _iterator4 = createForOfIteratorHelper._createForOfIteratorHelper((_this$listeners$get = this.listeners.get(subscriberId)) !== null && _this$listeners$get !== void 0 ? _this$listeners$get : []),
440
+ _step4;
441
+ try {
442
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
443
+ var listener = _step4.value;
444
+ listener();
445
+ }
446
+ } catch (err) {
447
+ _iterator4.e(err);
448
+ } finally {
449
+ _iterator4.f();
450
+ }
451
+ }
452
+ }]);
453
+ }();
454
+
455
+ /**
456
+ * Whether two reads of a module hold the same content: the same object, or
457
+ * the same version, or -- where either has none -- the same JSON.
458
+ *
459
+ * The versions settle it without walking the module: the Studio relays each
460
+ * module with the version it computed (phase 5 of
461
+ * `docs/plans/one-content-model.md`), and the server's draft carries the
462
+ * version it read (`ValDraft.versions`, phase 6) -- the same version for the
463
+ * same content, so a page rendered from the server's draft takes the
464
+ * Studio's first relay of an unchanged module as the nothing it is (risk 8
465
+ * in the plan). A version names what a reader renders: the module's source,
466
+ * and the `.jsonValues()` entries its chain touched, which both the Studio
467
+ * (`entriesToRelay`) and the server's draft send in place of their markers;
468
+ * every other entry is the bundle's whether it travels as content or as a
469
+ * marker. A read without a version (a server or a Studio of the release
470
+ * before) is compared by content, as before.
471
+ */
472
+ function sameContent(a, b) {
473
+ if (a.source === b.source) return true;
474
+ if (a.version !== null && b.version !== null) {
475
+ return a.version.schema === b.version.schema && a.version.base === b.version.base && a.version.chain === b.version.chain;
476
+ }
477
+ return patch.deepEqual(a.source, b.source);
478
+ }
479
+ var SEPARATOR = "&";
480
+ function createSubscriberId(paths) {
481
+ return paths.slice().sort().join(SEPARATOR);
482
+ }
483
+
484
+ /** Whether `path` is one of the paths a subscriber id was made of. */
485
+ function includesPath(subscriberId, path) {
486
+ return subscriberId.split(SEPARATOR).includes(path);
487
+ }
488
+
489
+ /** What one `val-event` from the overlay did to the page's store. */
490
+
491
+ /**
492
+ * Apply one overlay event (`detail` of a `val-event`) to the page's store.
493
+ * `sources-synced` says the editor has sent everything it holds;
494
+ * `confirmed` how far the server holds the editor's changes; a
495
+ * `source-update` hands over one module's read, which the store keeps as it
496
+ * is (`read`). A Studio from the release before sent the bare `source`
497
+ * instead, and a page newer than the Studio it is open in -- a deploy rolling
498
+ * out -- still takes that.
499
+ *
500
+ * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
501
+ * provider had the same rule written inline.
502
+ */
503
+ function applyValEvent(store, detail) {
504
+ if (_typeof._typeof(detail) !== "object" || detail === null || !("type" in detail)) {
505
+ return {
506
+ type: "invalid",
507
+ detail: detail
508
+ };
509
+ }
510
+ if (detail.type === "sources-synced") {
511
+ return {
512
+ type: "synced"
513
+ };
514
+ }
515
+ if (detail.type === "confirmed") {
516
+ var seq = "seq" in detail ? detail.seq : undefined;
517
+ if (seq === null || typeof seq === "number") {
518
+ return {
519
+ type: "confirmed",
520
+ seq: seq
521
+ };
522
+ }
523
+ return {
524
+ type: "invalid",
525
+ detail: detail
526
+ };
527
+ }
528
+ if (detail.type === "source-update") {
529
+ var moduleFilePath = "moduleFilePath" in detail ? detail.moduleFilePath : undefined;
530
+ if (!isModuleFilePath$1(moduleFilePath)) {
531
+ return {
532
+ type: "invalid",
533
+ detail: detail
534
+ };
535
+ }
536
+ var read = "read" in detail ? heldRead(detail.read) : undefined;
537
+ if (read !== undefined) {
538
+ return {
539
+ type: "updated",
540
+ changed: store.receive(moduleFilePath, read)
541
+ };
542
+ }
543
+ // A Studio of the release before sent the bare `source`. This fallback
544
+ // goes with the relay's `source` field: see "Release-delayed deletions"
545
+ // in `docs/plans/one-content-model.md`.
546
+ var source = "source" in detail ? detail.source : undefined;
547
+ if (isJson(source)) {
548
+ return {
549
+ type: "updated",
550
+ changed: store.update(moduleFilePath, source),
551
+ fromPreviousStudio: true
552
+ };
553
+ }
554
+ }
555
+ return {
556
+ type: "invalid",
557
+ detail: detail
558
+ };
559
+ }
560
+
561
+ /** A relayed module path, checked: it crossed a window, as data. */
562
+ function isModuleFilePath$1(value) {
563
+ return typeof value === "string" && value.startsWith("/");
564
+ }
565
+
566
+ /** A relayed read, checked: it crossed a window, as data. */
567
+ function heldRead(value) {
568
+ if (_typeof._typeof(value) !== "object" || value === null || !("status" in value) || value.status !== "ready" || !("source" in value) || !isJson(value.source)) {
569
+ return undefined;
570
+ }
571
+ return {
572
+ status: "ready",
573
+ source: value.source,
574
+ from: "overlay",
575
+ version: "version" in value && isModuleVersion(value.version) ? value.version : null
576
+ };
577
+ }
578
+ function isModuleVersion(value) {
579
+ return _typeof._typeof(value) === "object" && value !== null && "schema" in value && typeof value.schema === "string" && "base" in value && typeof value.base === "string" && "chain" in value && typeof value.chain === "string";
580
+ }
581
+ function isJson(value) {
582
+ return value !== undefined;
583
+ }
584
+
585
+ /**
586
+ * What a draft page shows, read by the server for the request that renders it.
587
+ *
588
+ * The source of every module the editor's draft CHANGES -- the ones with
589
+ * patches applied, published-not-yet-built ones included -- and nothing
590
+ * else: a module without changes is the build's own source, which the page
591
+ * already has. Handed to `<ValProvider draft>` so the server's render and the
592
+ * browser's first render resolve the same text, and the page never shows the
593
+ * published version first and the draft a moment later.
594
+ *
595
+ * A `.jsonValues()` module is in the shape the Studio's own store gives it: the
596
+ * entries the draft edits hold their content, and every other entry is the
597
+ * thunkless marker the hooks resolve from the bundle.
598
+ *
599
+ * Plain JSON, because it travels from the server to the browser in the page's
600
+ * loader data (or a server component's props). `fetchValDraft` in
601
+ * `@valbuild/tanstack/server` reads it. Moved here from `@valbuild/tanstack`,
602
+ * which still exports it, when `@valbuild/next`'s `ValProvider` took a
603
+ * `draft` too: the page's half is the same in both.
604
+ */
605
+
606
+ /**
607
+ * Whether a server-read draft is a draft. At a proposal's address the server
608
+ * sends its snapshot whether or not draft mode is on, and one that is ONLY a
609
+ * snapshot (`draftMode: false`) is not a draft: it must not turn draft mode on
610
+ * or say the draft is synced.
611
+ */
612
+ function isDraft(draft) {
613
+ return draft !== null && draft !== undefined && draft.draftMode !== false;
614
+ }
615
+
616
+ /**
617
+ * The store a page starts from: seeded with the server-read draft, so the
618
+ * server render and the browser's first render show the same thing. What
619
+ * both frameworks' providers start from, and the scenario world's page.
620
+ *
621
+ * The seed (`seeded`, in a read's `from`) is held in the overlay's store
622
+ * rather than read as a source of its own, because what the Studio relays
623
+ * later is compared with what the page shows (`ValExternalStore.receive`):
624
+ * the first relay of a module the server already rendered moves nothing.
625
+ */
626
+ function createDraftStore(draft) {
627
+ var store = new ValExternalStore();
628
+ if (isDraft(draft)) {
629
+ for (var _i = 0, _draftHolds = draftHolds(draft); _i < _draftHolds.length; _i++) {
630
+ var _draft$versions$path, _draft$versions;
631
+ var path = _draftHolds[_i];
632
+ store.receive(path, {
633
+ status: "ready",
634
+ source: draft.sources[path],
635
+ from: "seeded",
636
+ version: (_draft$versions$path = (_draft$versions = draft.versions) === null || _draft$versions === void 0 ? void 0 : _draft$versions[path]) !== null && _draft$versions$path !== void 0 ? _draft$versions$path : null
637
+ });
638
+ }
639
+ }
640
+ return store;
641
+ }
642
+
643
+ /**
644
+ * What the page reports to the Studio when it connects: the modules it was
645
+ * rendered with a draft of. The Studio sends each of them in its catch-up,
646
+ * pending or not (`sendPendingSources` in `@valbuild/ui`), so a draft that
647
+ * stopped being the draft before the Studio was there -- discarded,
648
+ * published -- is replaced rather than kept. With the version of each
649
+ * where the draft carries one ({@link draftHoldsVersions}): the page compares
650
+ * what it is sent with what it holds by version (`ValExternalStore.receive`),
651
+ * and a module that did not move costs nothing.
652
+ */
653
+ function draftHolds(draft) {
654
+ if (!isDraft(draft)) return [];
655
+ return Object.keys(draft.sources).filter(isModuleFilePathOf(draft.sources));
656
+ }
657
+
658
+ /**
659
+ * The versions the page was rendered with, of the modules
660
+ * {@link draftHolds} names, where the draft says (phase 6 of
661
+ * `docs/plans/one-content-model.md`): what the page reports beside the paths
662
+ * when it connects, so the Studio can tell a module the page holds at the
663
+ * version it would send. A module without one is left out.
664
+ */
665
+ function draftHoldsVersions(draft) {
666
+ var versions = {};
667
+ if (!isDraft(draft) || draft.versions === undefined) return versions;
668
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(draftHolds(draft)),
669
+ _step;
670
+ try {
671
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
672
+ var path = _step.value;
673
+ var version = draft.versions[path];
674
+ if (version !== undefined) versions[path] = version;
675
+ }
676
+ } catch (err) {
677
+ _iterator.e(err);
678
+ } finally {
679
+ _iterator.f();
680
+ }
681
+ return versions;
682
+ }
683
+
684
+ /** Narrows a key of `sources` back to the path it was written under. */
685
+ function isModuleFilePathOf(sources) {
686
+ return function (key) {
687
+ return Object.prototype.hasOwnProperty.call(sources, key);
688
+ };
689
+ }
690
+
691
+ /**
692
+ * When a draft page re-reads what its server rendered: its loaders (TanStack
693
+ * Start's `router.invalidate()`) or its server components (Next's
694
+ * `router.refresh()`). The hooks need none of this -- they read what the
695
+ * Studio relays -- but server-read content only changes on a refresh, and only
696
+ * shows an edit once the server has it.
697
+ *
698
+ * So the page refreshes when the Studio says the server has CONFIRMED the
699
+ * edit (`confirmed`, with the server's `seq`), never when the edit arrives.
700
+ * Arrived, it raced the write: the page asked a server that did not have the
701
+ * patch yet, got the old content back, and nothing asked again until a safety
702
+ * refresh ten seconds later (S05 in `scenarios/`). That timer, and the 500 ms
703
+ * throttle that was there to keep the edit-driven refreshes from stacking,
704
+ * are gone: this has no timer at all. See `docs/plans/one-content-model.md`,
705
+ * "The page converges on the Studio".
706
+ *
707
+ * - **One refresh per confirmed version.** A version told twice (a save's
708
+ * answer, then the stat after it) or out of order refreshes once.
709
+ * - **At most one in flight**, where the refresh says when it is done (a
710
+ * promise): a version confirmed meanwhile waits for it and is then one more
711
+ * refresh, however many arrived. A refresh that cannot say (Next's
712
+ * `router.refresh()`) is simply sent each time.
713
+ * - **The first `confirmed` is the connection, not news.** The Studio says
714
+ * it once after its catch-up. The page refreshes then only if the catch-up
715
+ * moved what it holds (`changed`): its server render is older than what the
716
+ * Studio has. A page rendered from the draft the Studio holds -- the
717
+ * `draft` prop, read for this request -- is not refreshed for loading.
718
+ * - **A Studio of the release before never says `confirmed`** (a deploy
719
+ * rolling out: this page, that Studio). Its changes refresh the page as
720
+ * they arrive (`changedByPreviousStudio`), as that release's page did,
721
+ * until a `confirmed` says the Studio is this release's. They race the
722
+ * write, as they did then; it lasts as long as the rollout.
723
+ */
724
+
725
+ function startRefreshLoop(options) {
726
+ /** The version last told; `undefined` until the first. */
727
+ var told = undefined;
728
+ /** Whether the catch-up moved what the page holds: see above. */
729
+ var behind = false;
730
+ var running = false;
731
+ var again = false;
732
+ var stopped = false;
733
+ var refreshes = 0;
734
+ var _run = function run() {
735
+ if (stopped) return;
736
+ if (running) {
737
+ again = true;
738
+ return;
739
+ }
740
+ refreshes++;
741
+ var done = options.refresh();
742
+ if (done === undefined) return;
743
+ running = true;
744
+ var next = function next() {
745
+ running = false;
746
+ if (!again) return;
747
+ again = false;
748
+ _run();
749
+ };
750
+ done.then(next, next);
751
+ };
752
+ return {
753
+ changed: function changed() {
754
+ if (told === undefined) behind = true;
755
+ },
756
+ changedByPreviousStudio: function changedByPreviousStudio() {
757
+ if (told !== undefined) {
758
+ // A Studio that confirms: its `confirmed` is the refresh.
759
+ return;
760
+ }
761
+ _run();
762
+ },
763
+ confirmed: function confirmed(seq) {
764
+ if (told !== undefined && told !== null && seq !== null && seq <= told) {
765
+ return;
766
+ }
767
+ var first = told === undefined;
768
+ told = seq;
769
+ if (first && !behind) return;
770
+ _run();
771
+ },
772
+ refresh: function refresh() {
773
+ _run();
774
+ },
775
+ get refreshes() {
776
+ return refreshes;
777
+ },
778
+ stop: function stop() {
779
+ stopped = true;
780
+ }
781
+ };
782
+ }
783
+
784
+ /*
785
+ * `.jsonValues()` records, as the readers meet them. Moved here from the
786
+ * `routeFromVal.ts` of `@valbuild/next` and `@valbuild/tanstack`, which were
787
+ * the same lines twice.
788
+ */
789
+
790
+ /**
791
+ * True when the module's schema is a `.jsonValues()` record/router — i.e. each
792
+ * entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
793
+ * readers to load ONLY the entries they need instead of the whole record.
794
+ */
795
+ function isJsonValuesRecordSchema(schema) {
796
+ return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
797
+ }
798
+
799
+ /**
800
+ * The bundle's import of one `.jsonValues()` entry: `undefined` when the
801
+ * module's own source has no marker for `key` to import from.
802
+ */
803
+ function bundledJsonEntryImport(
804
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
805
+ module, key) {
806
+ var _Internal$getJsonImpo;
807
+ var source = module && core.Internal.getSource(module);
808
+ var marker = _typeof._typeof(source) === "object" && source !== null && !Array.isArray(source) ? Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined : undefined;
809
+ if (!core.Internal.isJson(marker)) {
810
+ return undefined;
811
+ }
812
+ return (_Internal$getJsonImpo = core.Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
813
+ }
814
+
815
+ /**
816
+ * Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
817
+ * strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
818
+ * identity transform (the content carries no selector path/schema).
819
+ *
820
+ * Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
821
+ * field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
822
+ * `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
823
+ */
824
+ function getJsonEntryStegaRoot(
825
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
826
+ selector, key
827
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
828
+ ) {
829
+ var modulePath = selector && core.Internal.getValPath(selector);
830
+ if (!modulePath) {
831
+ return undefined;
832
+ }
833
+ var schema = selector && core.Internal.getSchema(selector);
834
+ if (!(schema instanceof core.RecordSchema)) {
835
+ return undefined;
836
+ }
837
+ var path = core.Internal.createValPathOfItem(modulePath, key);
838
+ if (!path) {
839
+ return undefined;
840
+ }
841
+ return {
842
+ path: path,
843
+ schema: schema["executeSerialize"]().item
844
+ };
845
+ }
846
+
847
+ /*
848
+ * The sources a page reads from, in the browser and on the server alike
849
+ * (the server's own draft, `serverDraftSource`, is in `@valbuild/server`).
850
+ * See `docs/plans/one-content-model.md`, "One way to load".
851
+ */
852
+
853
+ var PASS$1 = {
854
+ status: "pass"
855
+ };
856
+
857
+ /**
858
+ * What a module's source says about one of its `.jsonValues()` entries: the
859
+ * same rule for every source that holds a whole module (the overlay, a
860
+ * snapshot). A module that is `null` (a nullable record) has no entries; a
861
+ * key it does not have is GONE -- an answer, not "ask the next one"; an entry
862
+ * that is still a marker is one this source has not loaded, so it passes.
863
+ */
864
+ function entryOfModuleSource(source, key, from) {
865
+ var _Object$entries$find;
866
+ if (source === null) {
867
+ return {
868
+ status: "gone",
869
+ from: from
870
+ };
871
+ }
872
+ if (_typeof._typeof(source) !== "object" || Array.isArray(source)) {
873
+ return PASS$1;
874
+ }
875
+ // Own keys only: an entry may be named `toString`.
876
+ if (!Object.prototype.hasOwnProperty.call(source, key)) {
877
+ return {
878
+ status: "gone",
879
+ from: from
880
+ };
881
+ }
882
+ var entry = (_Object$entries$find = Object.entries(source).find(function (_ref) {
883
+ var _ref2 = slicedToArray._slicedToArray(_ref, 1),
884
+ k = _ref2[0];
885
+ return k === key;
886
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1];
887
+ if (core.Internal.isJson(entry)) {
888
+ return PASS$1;
889
+ }
890
+ return {
891
+ status: "ready",
892
+ content: entry,
893
+ from: from
894
+ };
895
+ }
896
+
897
+ /**
898
+ * A content version's or a proposal's saved Source, for the modules it has
899
+ * (`ValDraft.snapshot`, `snapshotForReaders`): it stands in for the bundle's,
900
+ * draft mode or not. Its entries are content where the proposal saved them.
901
+ */
902
+ function snapshotSource(snapshot) {
903
+ var sourceOf = function sourceOf(path) {
904
+ return snapshot !== undefined && Object.prototype.hasOwnProperty.call(snapshot, path) ? snapshot[path] : undefined;
905
+ };
906
+ return {
907
+ name: "snapshot",
908
+ module: function module(path) {
909
+ var source = sourceOf(path);
910
+ return source === undefined ? PASS$1 : {
911
+ status: "ready",
912
+ source: source,
913
+ from: "snapshot",
914
+ version: null
915
+ };
916
+ },
917
+ entry: function entry(path, key) {
918
+ var source = sourceOf(path);
919
+ return source === undefined ? PASS$1 : entryOfModuleSource(source, key, "snapshot");
920
+ }
921
+ };
922
+ }
923
+
924
+ /** What the page knows about draft mode and the Studio, for {@link overlaySource}. */
925
+
926
+ /**
927
+ * What the Studio sent the page (`ValExternalStore`, fed by the relay), with
928
+ * the three waits `suspend` is made of (`architecture/quirks.md`, "`suspend`
929
+ * is three waits") as its states:
930
+ *
931
+ * 1. Draft mode unknown: wait for it to be known (`draftModeReady`), because
932
+ * a read that slips through then is a read of published content, and for
933
+ * a route that only exists in a patch that is a `notFound()` nothing later
934
+ * undoes.
935
+ * 2. Draft mode on, and the Studio has not yet said it sent everything: a
936
+ * module it has not sent may still be coming, so wait for it. After
937
+ * `sources-synced` a module it did not send has no draft: pass.
938
+ * 3. The render that decides is the provider's, which turns `suspend` on
939
+ * after hydrating; until then every wait is a pass.
940
+ *
941
+ * Draft mode off, or no store (a visitor): pass, always.
942
+ */
943
+ function overlaySource(store, state) {
944
+ var gate = function gate(path) {
945
+ if (store === undefined || state.draftMode === false) {
946
+ return PASS$1;
947
+ }
948
+ if (state.suspend && state.draftMode === null && state.draftModeReady !== undefined) {
949
+ return {
950
+ status: "pending",
951
+ ready: state.draftModeReady
952
+ };
953
+ }
954
+ var held = state.draftMode === true ? store.read(path) : undefined;
955
+ if (held !== undefined) {
956
+ return held;
957
+ }
958
+ if (state.suspend && !state.synced && store.read(path) === undefined) {
959
+ return {
960
+ status: "pending",
961
+ ready: store.waitForLoad([path])
962
+ };
963
+ }
964
+ return PASS$1;
965
+ };
966
+ return {
967
+ name: "overlay",
968
+ module: function module(path) {
969
+ return gate(path);
970
+ },
971
+ entry: function entry(path, key) {
972
+ var read = gate(path);
973
+ if (read.status === "pass") {
974
+ return PASS$1;
975
+ }
976
+ if (read.status === "pending") {
977
+ return read;
978
+ }
979
+ return entryOfModuleSource(read.source, key, "overlay");
980
+ },
981
+ subscribe: function subscribe(paths, onChange) {
982
+ return store === undefined ? function () {} : store.subscribe(paths)(onChange);
983
+ },
984
+ revision: function revision(paths) {
985
+ return store === undefined ? "" : store.revision(paths);
986
+ }
987
+ };
988
+ }
989
+
990
+ /** Where one bundled entry's import is. */
991
+
992
+ /**
993
+ * Every bundled entry's import, started once and kept, by the MODULE OBJECT
994
+ * it belongs to -- the build it came from -- so a new build (or a hot reload)
995
+ * is a new key rather than an old answer. Replaces the frameworks'
996
+ * `jsonEntryPromiseCache`, which was keyed by path and kept a previous
997
+ * build's entries for good.
998
+ *
999
+ * Kept for the process, as the imports themselves are: the module object
1000
+ * keeps them alive, and with it the entries the page has read. A failed
1001
+ * import is kept for {@link RETRY_FAILED_ENTRY_AFTER_MS}, then tried again.
1002
+ */
1003
+ var bundledEntries = new WeakMap();
1004
+
1005
+ /** How long a failed entry import answers "failed" before it is tried again. */
1006
+ var RETRY_FAILED_ENTRY_AFTER_MS = 5000;
1007
+ function bundledEntry(module, key) {
1008
+ var entries = bundledEntries.get(module);
1009
+ if (entries === undefined) {
1010
+ entries = new Map();
1011
+ bundledEntries.set(module, entries);
1012
+ }
1013
+ var entry = entries.get(key);
1014
+ if (entry === undefined) {
1015
+ var thunk = bundledJsonEntryImport(module, key);
1016
+ if (thunk === undefined) {
1017
+ return {
1018
+ status: "gone",
1019
+ from: "bundle"
1020
+ };
1021
+ }
1022
+ var kept = entries;
1023
+ var ready = thunk().then(function (imported) {
1024
+ kept.set(key, {
1025
+ status: "loaded",
1026
+ content: imported["default"]
1027
+ });
1028
+ }, function (error) {
1029
+ kept.set(key, {
1030
+ status: "failed",
1031
+ error: error,
1032
+ at: Date.now()
1033
+ });
1034
+ });
1035
+ entry = {
1036
+ status: "loading",
1037
+ ready: ready
1038
+ };
1039
+ entries.set(key, entry);
1040
+ }
1041
+ if (entry.status === "loading") {
1042
+ return {
1043
+ status: "pending",
1044
+ ready: entry.ready
1045
+ };
1046
+ }
1047
+ if (entry.status === "failed") {
1048
+ // A chunk that failed to load (a deploy, a dropped connection) is
1049
+ // imported again by a read after a while, rather than failing every
1050
+ // read until the page is reloaded -- and not by every read before
1051
+ // that, each of which would suspend a component again.
1052
+ if (Date.now() - entry.at >= RETRY_FAILED_ENTRY_AFTER_MS) {
1053
+ entries["delete"](key);
1054
+ return bundledEntry(module, key);
1055
+ }
1056
+ return {
1057
+ status: "failed",
1058
+ error: entry.error
1059
+ };
1060
+ }
1061
+ return {
1062
+ status: "ready",
1063
+ content: entry.content,
1064
+ from: "bundle"
1065
+ };
1066
+ }
1067
+
1068
+ /**
1069
+ * The build's own modules: what the code a reader runs was built with. Always
1070
+ * the last source, and the only one that never passes on an entry: its
1071
+ * entries are its own `import()`s, started when one is first read (never
1072
+ * before: a `.jsonValues()` record stays lazy) and kept by build.
1073
+ *
1074
+ * A module the bundle has passes here: the reader's own selector carries its
1075
+ * source, and `stegaEncode` reads it there (and a gallery's from the schema
1076
+ * that picks from it), so there is nothing to hand over.
1077
+ */
1078
+ function bundleSource(modules) {
1079
+ return {
1080
+ name: "bundle",
1081
+ module: function module() {
1082
+ return PASS$1;
1083
+ },
1084
+ entry: function entry(path, key) {
1085
+ var module = modules.get(path);
1086
+ if (_typeof._typeof(module) !== "object" || module === null) {
1087
+ return PASS$1;
1088
+ }
1089
+ return bundledEntry(module, key);
1090
+ }
1091
+ };
1092
+ }
1093
+
1094
+ /**
1095
+ * The rule that content is only read with the schema it was made for
1096
+ * (`docs/plans/one-content-model.md`, goal 3).
1097
+ *
1098
+ * `schemaOf(path)` is the version of the schema the READER's code has for a
1099
+ * module (`null`: not known, so no rule). A source whose answer names
1100
+ * another schema is not read: with `codeChanged` the read waits until the
1101
+ * code catches up; without it the next source answers, which ends at the
1102
+ * reader's own bundle -- content of the code that reads it.
1103
+ */
1104
+
1105
+ /** A module read, with the place in the list of the source that answered it. */
1106
+
1107
+ /** What `layered` gives back: one view over the sources, first answer wins. */
1108
+
1109
+ var PASS = {
1110
+ status: "pass"
1111
+ };
1112
+
1113
+ /**
1114
+ * The ONE place that decides which source wins: the first that does not
1115
+ * pass. Replaces the source-priority arrays each reader wrote inline
1116
+ * (`[draft, snapshot]`, then the bundle, in four places), and is the only
1117
+ * place the schema rule is applied.
1118
+ */
1119
+ function layered(sources, rule,
1120
+ /**
1121
+ * Waits that are already over. A source still answering one of them is
1122
+ * passed over: what it waited for came and did not give it an answer (draft
1123
+ * mode stayed unknown, a module the Studio never sent), and the read goes on
1124
+ * as it would have without waiting.
1125
+ */
1126
+ settled) {
1127
+ /**
1128
+ * THE schema rule: content made with another schema than this code has is
1129
+ * not read with it. `null`: read it. `next`: read the next source. A
1130
+ * promise: the code is changing (`codeChanged`), wait for it.
1131
+ */
1132
+ var schemaRule = function schemaRule(path, version, from) {
1133
+ if (version === null || version === undefined || !rule) return null;
1134
+ var own = rule.schemaOf(path);
1135
+ if (own === null || own === version.schema) return null;
1136
+ if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1137
+ core.Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1138
+ return "next";
1139
+ };
1140
+ return {
1141
+ sources: sources,
1142
+ module: function module(path) {
1143
+ for (var at = 0; at < sources.length; at++) {
1144
+ var source = sources[at];
1145
+ if (source === undefined) continue;
1146
+ var read = source.module(path);
1147
+ if (read.status === "pass") continue;
1148
+ if (read.status === "pending" && settled !== null && settled !== void 0 && settled.has(read.ready)) continue;
1149
+ if (read.status === "ready") {
1150
+ var ruled = schemaRule(path, read.version, read.from);
1151
+ if (ruled === "next") continue;
1152
+ if (ruled !== null) {
1153
+ return {
1154
+ read: {
1155
+ status: "pending",
1156
+ ready: ruled
1157
+ },
1158
+ at: at
1159
+ };
1160
+ }
1161
+ }
1162
+ return {
1163
+ read: read,
1164
+ at: at
1165
+ };
1166
+ }
1167
+ return {
1168
+ read: PASS,
1169
+ at: -1
1170
+ };
1171
+ },
1172
+ entry: function entry(path, key) {
1173
+ var after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
1174
+ for (var at = after + 1; at < sources.length; at++) {
1175
+ var _sources$at;
1176
+ var read = (_sources$at = sources[at]) === null || _sources$at === void 0 ? void 0 : _sources$at.entry(path, key);
1177
+ if (read === undefined || read.status === "pass") continue;
1178
+ if (read.status === "pending" && settled !== null && settled !== void 0 && settled.has(read.ready)) continue;
1179
+ if (read.status === "ready") {
1180
+ // The same rule as a module's: an entry carries its record's
1181
+ // schema version.
1182
+ var ruled = schemaRule(path, read.version, read.from);
1183
+ if (ruled === "next") continue;
1184
+ if (ruled !== null) return {
1185
+ status: "pending",
1186
+ ready: ruled
1187
+ };
1188
+ }
1189
+ return read;
1190
+ }
1191
+ return {
1192
+ status: "pass"
1193
+ };
1194
+ },
1195
+ subscribe: function subscribe(paths, onChange) {
1196
+ var offs = sources.map(function (source) {
1197
+ var _source$subscribe, _source$subscribe2;
1198
+ return (_source$subscribe = (_source$subscribe2 = source.subscribe) === null || _source$subscribe2 === void 0 ? void 0 : _source$subscribe2.call(source, paths, onChange)) !== null && _source$subscribe !== void 0 ? _source$subscribe : function () {};
1199
+ });
1200
+ return function () {
1201
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(offs),
1202
+ _step;
1203
+ try {
1204
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1205
+ var off = _step.value;
1206
+ off();
1207
+ }
1208
+ } catch (err) {
1209
+ _iterator.e(err);
1210
+ } finally {
1211
+ _iterator.f();
1212
+ }
1213
+ };
1214
+ },
1215
+ revision: function revision(paths) {
1216
+ return sources.map(function (source) {
1217
+ var _source$revision, _source$revision2;
1218
+ return (_source$revision = (_source$revision2 = source.revision) === null || _source$revision2 === void 0 ? void 0 : _source$revision2.call(source, paths)) !== null && _source$revision !== void 0 ? _source$revision : "";
1219
+ }).join("|");
1220
+ }
1221
+ };
1222
+ }
1223
+
1224
+ /**
1225
+ * Everything a read needs that is not the selector: where content comes from
1226
+ * and whether it carries edit tags. Built once per request on the server and
1227
+ * once per render in a component; the only thing the readers differ in.
1228
+ *
1229
+ * `encode` is decided ONCE, from draft mode (and, on TanStack, hydration and
1230
+ * analytics): there is no second encode on an error path to forget it.
1231
+ */
1232
+
1233
+ /** Which source a module was read from, and the version of what it read. */
1234
+
1235
+ /** What a read is: a value with the reads it was made of, or a wait. */
1236
+
1237
+ /**
1238
+ * What a read of `selector` reads: every module it names (`getModuleIds`),
1239
+ * the module objects it carries -- whose `.jsonValues()` entries the bundle
1240
+ * imports -- and the whole `.jsonValues()` record it is, if it is one.
1241
+ */
1242
+
1243
+ var plans = new WeakMap();
1244
+
1245
+ /**
1246
+ * The plan of a read: see {@link ReadPlan}. Kept per selector object, like
1247
+ * `getModuleIds`: a module is a module-level constant, so its plan is made
1248
+ * once for the life of the process.
1249
+ */
1250
+ /** A module id `getModuleIds` collected: a module's path. */
1251
+ function isModuleFilePath(id) {
1252
+ return id.startsWith("/");
1253
+ }
1254
+ function planOf(selector) {
1255
+ var _Internal$viewHandleM;
1256
+ var root = (_Internal$viewHandleM = core.Internal.viewHandleModule(selector)) !== null && _Internal$viewHandleM !== void 0 ? _Internal$viewHandleM : selector;
1257
+ var cacheable = _typeof._typeof(root) === "object" && root !== null;
1258
+ if (cacheable) {
1259
+ var cached = plans.get(root);
1260
+ if (cached !== undefined) return cached;
1261
+ }
1262
+ // The ids `getModuleIds` collects are module paths, as `useVal`
1263
+ // subscribed to them.
1264
+ var modules = raw.getModuleIds(root).filter(isModuleFilePath);
1265
+ var own = new Map();
1266
+ var record = null;
1267
+ var rootPath = core.Internal.isValModule(root) ? core.Internal.getValPath(root) : undefined;
1268
+ if (core.Internal.isValModule(root) && rootPath !== undefined) {
1269
+ var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(rootPath),
1270
+ _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1),
1271
+ path = _Internal$splitModule2[0];
1272
+ own.set(path, root);
1273
+ if (isJsonValuesRecordSchema(core.Internal.getSchema(root))) {
1274
+ record = path;
1275
+ }
1276
+ }
1277
+ var plan = {
1278
+ modules: modules,
1279
+ own: own,
1280
+ record: record
1281
+ };
1282
+ if (cacheable) plans.set(root, plan);
1283
+ return plan;
1284
+ }
1285
+ var resolves = 0;
1286
+ var encodes = 0;
1287
+
1288
+ /**
1289
+ * Counted work, for the scenarios' budgets (`read:resolve`, `read:encode`):
1290
+ * how many times a reader resolved, and how many of those encoded a value.
1291
+ * A render resolves once per selector unless something it waited on is in;
1292
+ * a server read resolves once per wait, plus the one that is ready.
1293
+ */
1294
+ function readWork() {
1295
+ return {
1296
+ resolve: resolves,
1297
+ encode: encodes
1298
+ };
1299
+ }
1300
+
1301
+ /** How a read is made, beyond its env. */
1302
+
1303
+ function viewOf(env, plan, settled) {
1304
+ var schemaVersionOf = env.schemaVersionOf;
1305
+ return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2({
1306
+ schemaOf: function schemaOf(path) {
1307
+ var module = plan.own.get(path);
1308
+ return module === undefined ? null : schemaVersionOf(module);
1309
+ }
1310
+ }, env.codeChanged ? {
1311
+ codeChanged: env.codeChanged
1312
+ } : {}) : undefined, settled);
1313
+ }
1314
+ function pending(waits) {
1315
+ var _waits = slicedToArray._slicedToArray(waits, 1),
1316
+ first = _waits[0];
1317
+ return first === undefined ? null : {
1318
+ status: "pending",
1319
+ ready: first,
1320
+ waits: waits
1321
+ };
1322
+ }
1323
+
1324
+ /**
1325
+ * Resolve `selector` against `env`: read the modules {@link planOf} names
1326
+ * from the sources (the first that does not pass wins: `layered`), fill a
1327
+ * whole `.jsonValues()` record's entries, and -- once nothing is pending --
1328
+ * encode the value. Every reader of a value goes through this: `fetchVal`,
1329
+ * `useVal`, and the route readers' modules.
1330
+ */
1331
+ function resolveVal(selector, env, opts) {
1332
+ resolves++;
1333
+ var plan = planOf(selector);
1334
+ var view = viewOf(env, plan, opts === null || opts === void 0 ? void 0 : opts.settled);
1335
+ var answers = new Map();
1336
+ var reads = [];
1337
+ var waits = [];
1338
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(plan.modules),
1339
+ _step;
1340
+ try {
1341
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1342
+ var path = _step.value;
1343
+ var _view$module = view.module(path),
1344
+ read = _view$module.read,
1345
+ at = _view$module.at;
1346
+ if (read.status === "pending") {
1347
+ waits.push(read.ready);
1348
+ continue;
1349
+ }
1350
+ if (read.status === "ready") {
1351
+ answers.set(path, read.source);
1352
+ reads.push({
1353
+ path: path,
1354
+ from: read.from,
1355
+ version: read.version
1356
+ });
1357
+ } else {
1358
+ reads.push({
1359
+ path: path,
1360
+ from: "bundle",
1361
+ version: null
1362
+ });
1363
+ }
1364
+ if (path === plan.record && (opts === null || opts === void 0 ? void 0 : opts.entries) !== false) {
1365
+ var _answers$get;
1366
+ var own = plan.own.get(path);
1367
+ var filled = fillRecord(view, path, (_answers$get = answers.get(path)) !== null && _answers$get !== void 0 ? _answers$get : own && core.Internal.getSource(own), at, waits);
1368
+ if (filled !== undefined) answers.set(path, filled);
1369
+ }
1370
+ }
1371
+ } catch (err) {
1372
+ _iterator.e(err);
1373
+ } finally {
1374
+ _iterator.f();
1375
+ }
1376
+ var wait = pending(waits);
1377
+ if (wait !== null) return wait;
1378
+ encodes++;
1379
+ return {
1380
+ status: "ready",
1381
+ value: raw.stegaEncode(selector, {
1382
+ disabled: !env.encode,
1383
+ getModule: function getModule(moduleId) {
1384
+ return answers.get(moduleId);
1385
+ }
1386
+ }),
1387
+ reads: reads
1388
+ };
1389
+ }
1390
+
1391
+ /**
1392
+ * A whole `.jsonValues()` record, with its entries' content: its own source
1393
+ * holds a lazy marker per entry, so a reader that encodes that source renders
1394
+ * every entry empty. An entry that is still a marker where the record was
1395
+ * read is taken from a later source that has its content, ending at the
1396
+ * bundle's import; one whose import failed keeps its marker, which is what a
1397
+ * failed read rendered before.
1398
+ *
1399
+ * `undefined` when there is nothing to fill: the record is not an object (a
1400
+ * nullable record that is null), or holds no marker.
1401
+ */
1402
+ function fillRecord(view, path, record, at, waits) {
1403
+ if (_typeof._typeof(record) !== "object" || record === null || Array.isArray(record)) {
1404
+ return undefined;
1405
+ }
1406
+ var filled = null;
1407
+ for (var _i = 0, _Object$entries = Object.entries(record); _i < _Object$entries.length; _i++) {
1408
+ var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
1409
+ key = _Object$entries$_i[0],
1410
+ entry = _Object$entries$_i[1];
1411
+ if (!core.Internal.isJson(entry)) continue;
1412
+ var content = undefined;
1413
+ // `gone` from a later source is not this entry gone: the source that
1414
+ // answered for the record has it. Ask the next one.
1415
+ for (var after = at; after < view.sources.length;) {
1416
+ var read = view.entry(path, key, after);
1417
+ if (read.status === "ready") {
1418
+ content = read.content;
1419
+ break;
1420
+ }
1421
+ if (read.status === "pending") {
1422
+ waits.push(read.ready);
1423
+ break;
1424
+ }
1425
+ if (read.status === "failed") {
1426
+ core.Internal.log.error("could not load the entry '".concat(key, "' of ").concat(path), read.error);
1427
+ break;
1428
+ }
1429
+ if (read.status === "gone") {
1430
+ after = sourceIndex(view, read.from, after);
1431
+ continue;
1432
+ }
1433
+ break;
1434
+ }
1435
+ if (content !== undefined) {
1436
+ filled !== null && filled !== void 0 ? filled : filled = raw._objectSpread2({}, record);
1437
+ filled[key] = content;
1438
+ }
1439
+ }
1440
+ return filled === null ? undefined : filled;
1441
+ }
1442
+
1443
+ /** The index of the source named `from`, after `after`. */
1444
+ function sourceIndex(view, from, after) {
1445
+ for (var at = after + 1; at < view.sources.length; at++) {
1446
+ var _view$sources$at;
1447
+ if (((_view$sources$at = view.sources[at]) === null || _view$sources$at === void 0 ? void 0 : _view$sources$at.name) === from) return at;
1448
+ }
1449
+ return view.sources.length;
1450
+ }
1451
+
1452
+ /**
1453
+ * Resolve ONE `.jsonValues()` entry of `selector` by key: the first source
1454
+ * that has an answer, where "the entry is gone" is an answer (a draft that
1455
+ * deleted it must not render the published one) and the bundle's import is
1456
+ * the last. Loads that entry and no other. `undefined` for an entry that is
1457
+ * not there. An entry whose import failed throws, as the import did.
1458
+ */
1459
+ function resolveValEntry(selector, key, env, opts) {
1460
+ return resolveModuleEntry(core.Internal.resolveViewedModule(selector), key, env, opts);
1461
+ }
1462
+
1463
+ /** {@link resolveValEntry}, for a module (a view resolved). */
1464
+ function resolveModuleEntry(module, key, env, opts) {
1465
+ resolves++;
1466
+ var plan = planOf(module);
1467
+ var path = plan.own.keys().next().value;
1468
+ if (path === undefined) {
1469
+ return {
1470
+ status: "ready",
1471
+ value: undefined,
1472
+ reads: []
1473
+ };
1474
+ }
1475
+ var read = viewOf(env, plan, opts === null || opts === void 0 ? void 0 : opts.settled).entry(path, key);
1476
+ if (read.status === "pending") {
1477
+ return {
1478
+ status: "pending",
1479
+ ready: read.ready,
1480
+ waits: [read.ready]
1481
+ };
1482
+ }
1483
+ if (read.status === "failed") {
1484
+ throw read.error;
1485
+ }
1486
+ var reads = [{
1487
+ path: path,
1488
+ from: read.status === "pass" ? "bundle" : read.from,
1489
+ version: null
1490
+ }];
1491
+ if (read.status !== "ready" || read.content === undefined) {
1492
+ return {
1493
+ status: "ready",
1494
+ value: undefined,
1495
+ reads: reads
1496
+ };
1497
+ }
1498
+ encodes++;
1499
+ return {
1500
+ status: "ready",
1501
+ value: raw.stegaEncode(read.content, {
1502
+ disabled: !env.encode,
1503
+ root: getJsonEntryStegaRoot(module, key)
1504
+ }),
1505
+ reads: reads
1506
+ };
1507
+ }
1508
+
1509
+ /** A resolution's value, mapped; a wait stays the same wait. */
1510
+ function mapResolution(r, f) {
1511
+ return r.status === "ready" ? {
1512
+ status: "ready",
1513
+ value: f(r.value),
1514
+ reads: r.reads
1515
+ } : r;
1516
+ }
1517
+
1518
+ function _regeneratorDefine(e, r, n, t) {
1519
+ var i = Object.defineProperty;
1520
+ try {
1521
+ i({}, "", {});
1522
+ } catch (e) {
1523
+ i = 0;
1524
+ }
1525
+ _regeneratorDefine = function (e, r, n, t) {
1526
+ function o(r, n) {
1527
+ _regeneratorDefine(e, r, function (e) {
1528
+ return this._invoke(r, n, e);
1529
+ });
1530
+ }
1531
+ r ? i ? i(e, r, {
1532
+ value: n,
1533
+ enumerable: !t,
1534
+ configurable: !t,
1535
+ writable: !t
1536
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
1537
+ }, _regeneratorDefine(e, r, n, t);
1538
+ }
1539
+
1540
+ function _regenerator() {
1541
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
1542
+ var e,
1543
+ t,
1544
+ r = "function" == typeof Symbol ? Symbol : {},
1545
+ n = r.iterator || "@@iterator",
1546
+ o = r.toStringTag || "@@toStringTag";
1547
+ function i(r, n, o, i) {
1548
+ var c = n && n.prototype instanceof Generator ? n : Generator,
1549
+ u = Object.create(c.prototype);
1550
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
1551
+ var i,
1552
+ c,
1553
+ u,
1554
+ f = 0,
1555
+ p = o || [],
1556
+ y = !1,
1557
+ G = {
1558
+ p: 0,
1559
+ n: 0,
1560
+ v: e,
1561
+ a: d,
1562
+ f: d.bind(e, 4),
1563
+ d: function (t, r) {
1564
+ return i = t, c = 0, u = e, G.n = r, a;
1565
+ }
1566
+ };
1567
+ function d(r, n) {
1568
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
1569
+ var o,
1570
+ i = p[t],
1571
+ d = G.p,
1572
+ l = i[2];
1573
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
1574
+ }
1575
+ if (o || r > 1) return a;
1576
+ throw y = !0, n;
1577
+ }
1578
+ return function (o, p, l) {
1579
+ if (f > 1) throw TypeError("Generator is already running");
1580
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
1581
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
1582
+ try {
1583
+ if (f = 2, i) {
1584
+ if (c || (o = "next"), t = i[o]) {
1585
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
1586
+ if (!t.done) return t;
1587
+ u = t.value, c < 2 && (c = 0);
1588
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
1589
+ i = e;
1590
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
1591
+ } catch (t) {
1592
+ i = e, c = 1, u = t;
1593
+ } finally {
1594
+ f = 1;
1595
+ }
1596
+ }
1597
+ return {
1598
+ value: t,
1599
+ done: y
1600
+ };
1601
+ };
1602
+ }(r, o, i), !0), u;
1603
+ }
1604
+ var a = {};
1605
+ function Generator() {}
1606
+ function GeneratorFunction() {}
1607
+ function GeneratorFunctionPrototype() {}
1608
+ t = Object.getPrototypeOf;
1609
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
1610
+ return this;
1611
+ }), t),
1612
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
1613
+ function f(e) {
1614
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
1615
+ }
1616
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
1617
+ return this;
1618
+ }), _regeneratorDefine(u, "toString", function () {
1619
+ return "[object Generator]";
1620
+ }), (_regenerator = function () {
1621
+ return {
1622
+ w: i,
1623
+ m: f
1624
+ };
1625
+ })();
1626
+ }
1627
+
1628
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
1629
+ try {
1630
+ var i = n[a](c),
1631
+ u = i.value;
1632
+ } catch (n) {
1633
+ return void e(n);
1634
+ }
1635
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
1636
+ }
1637
+ function _asyncToGenerator(n) {
1638
+ return function () {
1639
+ var t = this,
1640
+ e = arguments;
1641
+ return new Promise(function (r, o) {
1642
+ var a = n.apply(t, e);
1643
+ function _next(n) {
1644
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
1645
+ }
1646
+ function _throw(n) {
1647
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
1648
+ }
1649
+ _next(void 0);
1650
+ });
1651
+ };
1652
+ }
1653
+
1654
+ /*
1655
+ * How the readers wait: the one thing, besides where content comes from,
1656
+ * that differs between them. A server read awaits and resolves again; a
1657
+ * component suspends (`React.use`) and renders again. Everything before the
1658
+ * wait is `resolveVal`.
1659
+ */
1660
+
1661
+ /** A read that is ready: the value, and what it was read from. */
1662
+
1663
+ /**
1664
+ * How many times a server read may wait before it is a bug: each wait is a
1665
+ * source that will have an answer once it has loaded, and a read meets at
1666
+ * most a few (the draft, then the entries it names).
1667
+ */
1668
+ var MAX_WAITS = 50;
1669
+
1670
+ /**
1671
+ * Resolve on the server: wait for what is pending, then resolve again, with
1672
+ * the waits that are over handed back (`settled`, see `layered`).
1673
+ */
1674
+ function awaitResolved(_x) {
1675
+ return _awaitResolved.apply(this, arguments);
1676
+ }
1677
+
1678
+ /**
1679
+ * Resolve in a component: subscribe to the modules `selector` reads, and
1680
+ * suspend on what is pending (`React.use`, which the caller's `<Suspense>`
1681
+ * boundary waits on). The one hook every client reader of both frameworks is
1682
+ * built on; `env` is the framework's.
1683
+ *
1684
+ * Re-renders when a source says a read of those modules would answer
1685
+ * differently -- `revision` is a string, so `useSyncExternalStore` compares
1686
+ * it with `===` and a render that moves nothing re-renders nothing.
1687
+ */
1688
+ function _awaitResolved() {
1689
+ _awaitResolved = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(resolve) {
1690
+ var settled, waited, r, _iterator2, _step2, wait;
1691
+ return _regenerator().w(function (_context2) {
1692
+ while (1) switch (_context2.n) {
1693
+ case 0:
1694
+ settled = new Set();
1695
+ waited = 0;
1696
+ case 1:
1697
+ r = resolve(settled);
1698
+ if (!(r.status === "ready")) {
1699
+ _context2.n = 2;
1700
+ break;
1701
+ }
1702
+ return _context2.a(2, {
1703
+ value: r.value,
1704
+ reads: r.reads
1705
+ });
1706
+ case 2:
1707
+ if (!(waited >= MAX_WAITS)) {
1708
+ _context2.n = 3;
1709
+ break;
1710
+ }
1711
+ throw new Error("A content read was still waiting after ".concat(MAX_WAITS, " answers: a source answered \"pending\" without ever becoming ready."));
1712
+ case 3:
1713
+ _context2.n = 4;
1714
+ return Promise.all(r.waits);
1715
+ case 4:
1716
+ _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(r.waits);
1717
+ try {
1718
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1719
+ wait = _step2.value;
1720
+ settled.add(wait);
1721
+ }
1722
+ } catch (err) {
1723
+ _iterator2.e(err);
1724
+ } finally {
1725
+ _iterator2.f();
1726
+ }
1727
+ case 5:
1728
+ waited++;
1729
+ _context2.n = 1;
1730
+ break;
1731
+ case 6:
1732
+ return _context2.a(2);
1733
+ }
1734
+ }, _callee2);
1735
+ }));
1736
+ return _awaitResolved.apply(this, arguments);
1737
+ }
1738
+ function useResolved(selector, env, resolve) {
1739
+ var modules = planOf(selector).modules;
1740
+ var subscribe = React__default["default"].useCallback(function (onChange) {
1741
+ return layered(env.sources).subscribe(modules, onChange);
1742
+ }, [env, modules]);
1743
+ var revision = function revision() {
1744
+ return layered(env.sources).revision(modules);
1745
+ };
1746
+ React__default["default"].useSyncExternalStore(subscribe, revision, revision);
1747
+ var settled = new Set();
1748
+ for (;;) {
1749
+ var r = resolve(settled);
1750
+ if (r.status === "ready") {
1751
+ return r.value;
1752
+ }
1753
+ // Every wait the read met, together, as the server awaits them: one
1754
+ // suspension for a whole record's entries, not one per entry (each a
1755
+ // render that resolves the whole read again). Returns only once they
1756
+ // are all over (it throws to suspend until then), and then the read is
1757
+ // made again: what it waited for is in, or -- a source still waiting on
1758
+ // it -- did not come, and is passed over.
1759
+ React__default["default"].use(allOf(r.waits));
1760
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(r.waits),
1761
+ _step;
1762
+ try {
1763
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1764
+ var wait = _step.value;
1765
+ settled.add(wait);
1766
+ }
1767
+ } catch (err) {
1768
+ _iterator.e(err);
1769
+ } finally {
1770
+ _iterator.f();
1771
+ }
1772
+ }
1773
+ }
1774
+
1775
+ /**
1776
+ * The waits a read met, as one promise -- the SAME promise for the same
1777
+ * waits, render after render, which `React.use` needs (one made afresh each
1778
+ * render is never seen to settle). Kept beside the first wait.
1779
+ */
1780
+ var combined = new WeakMap();
1781
+ function allOf(waits) {
1782
+ var _combined$get;
1783
+ var _waits = slicedToArray._slicedToArray(waits, 1),
1784
+ first = _waits[0];
1785
+ if (first === undefined) return Promise.resolve();
1786
+ if (waits.length === 1) return first;
1787
+ var held = (_combined$get = combined.get(first)) !== null && _combined$get !== void 0 ? _combined$get : [];
1788
+ var found = held.find(function (entry) {
1789
+ return entry.waits.length === waits.length && entry.waits.every(function (wait, i) {
1790
+ return wait === waits[i];
1791
+ });
1792
+ });
1793
+ if (found !== undefined) return found.all;
1794
+ var all = Promise.all(waits).then(function () {
1795
+ return undefined;
1796
+ });
1797
+ held.push({
1798
+ waits: createForOfIteratorHelper._toConsumableArray(waits),
1799
+ all: all
1800
+ });
1801
+ combined.set(first, held);
1802
+ return all;
1803
+ }
1804
+
1805
+ /**
1806
+ * `useVal`, for both frameworks: the one hook that was `useValStega` in each,
1807
+ * with the framework's env (its overlay, its snapshot, its rule for edit
1808
+ * tags). `entries: false` for a reader that needs a `.jsonValues()` record's
1809
+ * keys and not its entries.
1810
+ */
1811
+ function useResolvedVal(selector, env, opts) {
1812
+ return useResolved(selector, env, function (settled) {
1813
+ return resolveVal(selector, env, raw._objectSpread2({
1814
+ settled: settled
1815
+ }, opts));
1816
+ });
1817
+ }
1818
+ var NOTHING = {
1819
+ status: "ready",
1820
+ value: undefined,
1821
+ reads: []
1822
+ };
1823
+
1824
+ /**
1825
+ * `useValKey`, for both frameworks: one `.jsonValues()` entry, loading that
1826
+ * entry and no other. `key: null` reads nothing (a route the params did not
1827
+ * match), and still subscribes, so the hooks of a component stay the same.
1828
+ */
1829
+ function useResolvedEntry(selector, key, env) {
1830
+ return useResolved(selector, env, function (settled) {
1831
+ return key === null ? NOTHING : resolveValEntry(selector, key, env, {
1832
+ settled: settled
1833
+ });
1834
+ });
1835
+ }
1836
+
1837
+ /** A `fetchVal` that also says what it read. */
1838
+
1839
+ var fetchValReads = new WeakMap();
1840
+
1841
+ /**
1842
+ * The public `fetchVal` of a framework: `withReads`, giving the value only.
1843
+ * The reads stay reachable, from the function, for the scenario world
1844
+ * (`scenarios/`), which records the version beside the value a loader shows
1845
+ * and must call the same function the product does to get it
1846
+ * ({@link readsOfFetchVal}). Nothing in the product asks.
1847
+ */
1848
+ function fetchValFrom(withReads) {
1849
+ var fetchVal = /*#__PURE__*/function () {
1850
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(selector) {
1851
+ return _regenerator().w(function (_context) {
1852
+ while (1) switch (_context.n) {
1853
+ case 0:
1854
+ _context.n = 1;
1855
+ return withReads(selector);
1856
+ case 1:
1857
+ return _context.a(2, _context.v.value);
1858
+ }
1859
+ }, _callee);
1860
+ }));
1861
+ return function fetchVal(_x2) {
1862
+ return _ref.apply(this, arguments);
1863
+ };
1864
+ }();
1865
+ fetchValReads.set(fetchVal, withReads);
1866
+ return fetchVal;
1867
+ }
1868
+
1869
+ /** The read behind a `fetchVal` made by {@link fetchValFrom}. */
1870
+ function readsOfFetchVal(fetchVal) {
1871
+ var _fetchValReads$get;
1872
+ return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1873
+ }
1874
+
1875
+ exports.ValExternalStore = ValExternalStore;
158
1876
  exports.ValRichText = ValRichText;
1877
+ exports.applyValEvent = applyValEvent;
1878
+ exports.awaitResolved = awaitResolved;
1879
+ exports.bundleSource = bundleSource;
1880
+ exports.bundledJsonEntryImport = bundledJsonEntryImport;
1881
+ exports.createDraftStore = createDraftStore;
1882
+ exports.draftHolds = draftHolds;
1883
+ exports.draftHoldsVersions = draftHoldsVersions;
1884
+ exports.entryOfModuleSource = entryOfModuleSource;
1885
+ exports.fetchValFrom = fetchValFrom;
1886
+ exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
1887
+ exports.isDraft = isDraft;
1888
+ exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
1889
+ exports.layered = layered;
1890
+ exports.mapResolution = mapResolution;
1891
+ exports.overlaySource = overlaySource;
1892
+ exports.planOf = planOf;
1893
+ exports.readWork = readWork;
1894
+ exports.readsOfFetchVal = readsOfFetchVal;
1895
+ exports.resolveModuleEntry = resolveModuleEntry;
1896
+ exports.resolveVal = resolveVal;
1897
+ exports.resolveValEntry = resolveValEntry;
1898
+ exports.snapshotSource = snapshotSource;
1899
+ exports.startRefreshLoop = startRefreshLoop;
1900
+ exports.useResolved = useResolved;
1901
+ exports.useResolvedEntry = useResolvedEntry;
1902
+ exports.useResolvedVal = useResolvedVal;