@valbuild/react 0.154.0 → 0.154.2

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 (55) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/analytics/dist/valbuild-react-analytics.browser.esm.js +2 -1
  3. package/analytics/dist/valbuild-react-analytics.cjs.dev.js +6 -5
  4. package/analytics/dist/valbuild-react-analytics.cjs.prod.js +6 -5
  5. package/analytics/dist/valbuild-react-analytics.esm.js +2 -1
  6. package/analytics/dist/valbuild-react-analytics.worker.esm.js +2 -1
  7. package/dist/ValComponentEditorChrome-440d086a.cjs.dev.js +966 -0
  8. package/dist/ValComponentEditorChrome-4ac9dc79.worker.esm.js +952 -0
  9. package/dist/ValComponentEditorChrome-93321513.esm.js +952 -0
  10. package/dist/ValComponentEditorChrome-bf2fefc6.browser.esm.js +952 -0
  11. package/dist/ValComponentEditorChrome-c0b30556.cjs.js +7 -0
  12. package/dist/ValComponentEditorChrome-c0b30556.cjs.prod.js +966 -0
  13. package/dist/ValPreviewBridgeCore-00015d00.esm.js +157 -0
  14. package/dist/ValPreviewBridgeCore-023ffffb.browser.esm.js +157 -0
  15. package/dist/ValPreviewBridgeCore-9b984cb0.cjs.js +7 -0
  16. package/dist/ValPreviewBridgeCore-9b984cb0.cjs.prod.js +161 -0
  17. package/dist/ValPreviewBridgeCore-bbedf957.cjs.dev.js +161 -0
  18. package/dist/ValPreviewBridgeCore-e0d5a840.worker.esm.js +157 -0
  19. package/dist/{createForOfIteratorHelper-598a2f85.cjs.prod.js → createForOfIteratorHelper-6f9dc6fa.cjs.prod.js} +0 -17
  20. package/dist/{createForOfIteratorHelper-522d616d.cjs.dev.js → createForOfIteratorHelper-8a871dc3.cjs.dev.js} +0 -17
  21. package/dist/{createForOfIteratorHelper-595d57b7.esm.js → createForOfIteratorHelper-8bd0009a.browser.esm.js} +2 -18
  22. package/dist/{createForOfIteratorHelper-548f1578.worker.esm.js → createForOfIteratorHelper-93215c75.worker.esm.js} +2 -18
  23. package/dist/{createForOfIteratorHelper-3316a633.browser.esm.js → createForOfIteratorHelper-9b22d0cd.esm.js} +2 -18
  24. package/dist/declarations/src/internal/ValComponentEditor.d.ts +54 -0
  25. package/dist/declarations/src/internal/ValPreviewBridgeCore.d.ts +22 -0
  26. package/dist/declarations/src/internal/componentPreview.d.ts +39 -0
  27. package/dist/declarations/src/internal/index.d.ts +3 -0
  28. package/dist/declarations/src/read/jsonValues.d.ts +2 -0
  29. package/dist/declarations/src/stega/stegaEncode.d.ts +9 -218
  30. package/dist/objectSpread2-3c87fb4f.cjs.prod.js +52 -0
  31. package/dist/objectSpread2-69569a13.worker.esm.js +48 -0
  32. package/dist/objectSpread2-792eb2c2.cjs.dev.js +52 -0
  33. package/dist/objectSpread2-af6b2a44.browser.esm.js +48 -0
  34. package/dist/objectSpread2-be6bfc61.esm.js +48 -0
  35. package/dist/{raw-15ce77ae.browser.esm.js → raw-0561be8e.browser.esm.js} +81 -90
  36. package/dist/{raw-d504f4fd.cjs.prod.js → raw-a69a8d13.cjs.prod.js} +80 -92
  37. package/dist/{raw-534fcde0.esm.js → raw-aa7a3ac4.esm.js} +81 -90
  38. package/dist/{raw-67d24dd6.cjs.dev.js → raw-de032c12.cjs.dev.js} +80 -92
  39. package/dist/{raw-645a854a.worker.esm.js → raw-f32dca84.worker.esm.js} +81 -90
  40. package/dist/toConsumableArray-203e636a.cjs.prod.js +21 -0
  41. package/dist/toConsumableArray-257d6741.esm.js +19 -0
  42. package/dist/toConsumableArray-2fc46f85.browser.esm.js +19 -0
  43. package/dist/toConsumableArray-d7cf1601.cjs.dev.js +21 -0
  44. package/dist/toConsumableArray-e4f48095.worker.esm.js +19 -0
  45. package/internal/dist/valbuild-react-internal.browser.esm.js +405 -7
  46. package/internal/dist/valbuild-react-internal.cjs.dev.js +430 -24
  47. package/internal/dist/valbuild-react-internal.cjs.prod.js +430 -24
  48. package/internal/dist/valbuild-react-internal.esm.js +405 -7
  49. package/internal/dist/valbuild-react-internal.worker.esm.js +405 -7
  50. package/package.json +4 -4
  51. package/stega/dist/valbuild-react-stega.browser.esm.js +5 -3
  52. package/stega/dist/valbuild-react-stega.cjs.dev.js +11 -9
  53. package/stega/dist/valbuild-react-stega.cjs.prod.js +11 -9
  54. package/stega/dist/valbuild-react-stega.esm.js +5 -3
  55. package/stega/dist/valbuild-react-stega.worker.esm.js +5 -3
@@ -1,58 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var createForOfIteratorHelper = require('./createForOfIteratorHelper-598a2f85.cjs.prod.js');
3
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-6f9dc6fa.cjs.prod.js');
4
4
  var _typeof = require('./typeof-16428c61.cjs.prod.js');
5
5
  var core = require('@valbuild/core');
6
6
  var stega = require('@vercel/stega');
7
+ var objectSpread2 = require('./objectSpread2-3c87fb4f.cjs.prod.js');
7
8
  var slicedToArray = require('./slicedToArray-64c83d56.cjs.prod.js');
8
9
 
9
- function _toPrimitive(t, r) {
10
- if ("object" != typeof t || !t) return t;
11
- var e = t[Symbol.toPrimitive];
12
- if (void 0 !== e) {
13
- var i = e.call(t, r || "default");
14
- if ("object" != typeof i) return i;
15
- throw new TypeError("@@toPrimitive must return a primitive value.");
16
- }
17
- return ("string" === r ? String : Number)(t);
18
- }
19
-
20
- function _toPropertyKey(t) {
21
- var i = _toPrimitive(t, "string");
22
- return "symbol" == typeof i ? i : i + "";
23
- }
24
-
25
- function _defineProperty(e, r, t) {
26
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
27
- value: t,
28
- enumerable: !0,
29
- configurable: !0,
30
- writable: !0
31
- }) : e[r] = t, e;
32
- }
33
-
34
- function ownKeys(e, r) {
35
- var t = Object.keys(e);
36
- if (Object.getOwnPropertySymbols) {
37
- var o = Object.getOwnPropertySymbols(e);
38
- r && (o = o.filter(function (r) {
39
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
40
- })), t.push.apply(t, o);
41
- }
42
- return t;
43
- }
44
- function _objectSpread2(e) {
45
- for (var r = 1; r < arguments.length; r++) {
46
- var t = null != arguments[r] ? arguments[r] : {};
47
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
48
- _defineProperty(e, r, t[r]);
49
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
50
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
51
- });
52
- }
53
- return e;
54
- }
55
-
56
10
  function stegaDecodeStrings(encodedString) {
57
11
  if (!encodedString || typeof encodedString !== "string") return;
58
12
  var encodedBits = stega.vercelStegaDecodeAll(encodedString);
@@ -77,38 +31,8 @@ function stegaDecodeStrings(encodedString) {
77
31
  return paths.length > 0 ? paths : undefined;
78
32
  }
79
33
 
80
- /**
81
- * ValEncodedString is a string that is encoded using steganography.
82
- *
83
- * This means that there is a hidden / non-visible object embedded in the string.
84
- * This object includes a path, which is used to automatically tag
85
- * where the content comes from for contextual editing.
86
- *
87
- */
88
-
89
- /**
90
- * An image as a consumer sees it: what was authored, plus the generated `url`.
91
- *
92
- * `path` stays a plain string — it is what `url` is derived from, so encoding it
93
- * would corrupt every URL built from it.
94
- */
95
-
96
- /**
97
- * A video as a consumer sees it: what was authored, plus a generated `url` on
98
- * the video, on its poster and on each caption track.
99
- *
100
- * Only the video's own `url` carries the edit tag — a click on the player
101
- * reaches the field. The poster and the captions are parts of the same field,
102
- * not fields of their own, so their URLs are plain.
103
- *
104
- * An HLS stream (`mimeType` `application/vnd.apple.mpegurl`) plays natively in
105
- * Safari and needs a library such as hls.js everywhere else; `url` is then the
106
- * master playlist.
107
- */
108
-
109
- /**
110
- * RichText is accessible by users (after conversion via useVal / fetchVal)
111
- **/
34
+ // The read types are defined in core (`read.ts`), which has to be able to say
35
+ // them: `.component()` checks a component against what a reader gives back.
112
36
 
113
37
  /**
114
38
  * What resolving `T` gives back — the one definition the framework readers
@@ -152,6 +76,33 @@ function stegaDecodeStrings(encodedString) {
152
76
 
153
77
  /** What a route reader gives back for the entry the params matched. */
154
78
 
79
+ /**
80
+ * The component of the object at `path`, looked up on the schema INSTANCE of
81
+ * what is being walked: from the root down, by the path, through whichever
82
+ * variant of a union the value there takes. `null` when it cannot be found,
83
+ * which leaves the object without a component, as one whose schema has none.
84
+ */
85
+ function componentRenderAt(root, path) {
86
+ try {
87
+ // Only the part below the root: a `.jsonValues()` entry's root is the
88
+ // entry, whose own path already has a key in it.
89
+ var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(root.path),
90
+ _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 2),
91
+ rootModulePath = _Internal$splitModule2[1];
92
+ var _Internal$splitModule3 = core.Internal.splitModuleFilePathAndModulePath(path),
93
+ _Internal$splitModule4 = slicedToArray._slicedToArray(_Internal$splitModule3, 2),
94
+ modulePath = _Internal$splitModule4[1];
95
+ var below = core.Internal.splitModulePath(modulePath).slice(core.Internal.splitModulePath(rootModulePath).length);
96
+ if (below.length === 0) {
97
+ return core.getComponentRender(root.schema, root.source);
98
+ }
99
+ var at = core.Internal.resolvePath(core.Internal.patchPathToModulePath(below), root.source, root.schema);
100
+ return core.getComponentRender(at.schema, at.source);
101
+ } catch (_unused) {
102
+ return null;
103
+ }
104
+ }
105
+
155
106
  /**
156
107
  * Resolves the matching variant of a discriminated union from the value's tag.
157
108
  * Returns the matching schema or null if no match is found.
@@ -251,6 +202,7 @@ function handleRichTextSchema(sourceOrSelector, recOpts, rec) {
251
202
  return sourceOrSelector;
252
203
  }
253
204
  function stegaEncode(input, opts) {
205
+ var _opts$root;
254
206
  var viewModules = new Map();
255
207
  /**
256
208
  * The published entries of the galleries the module's fields pick from, for
@@ -262,6 +214,17 @@ function stegaEncode(input, opts) {
262
214
  var _opts$getModule, _opts$getModule2;
263
215
  return (_opts$getModule = (_opts$getModule2 = opts.getModule) === null || _opts$getModule2 === void 0 ? void 0 : _opts$getModule2.call(opts, modulePath)) !== null && _opts$getModule !== void 0 ? _opts$getModule : galleries.get(modulePath);
264
216
  };
217
+ /**
218
+ * What is being walked, with its schema INSTANCE: the one thing that holds a
219
+ * `.component()`'s closures. Everything below walks the serialized schema,
220
+ * which carries a marker and not the component, so an object with the
221
+ * marker looks its component up from here, by its own path.
222
+ */
223
+ var componentRoot = ((_opts$root = opts.root) === null || _opts$root === void 0 ? void 0 : _opts$root.instance) !== undefined ? {
224
+ path: opts.root.path,
225
+ schema: opts.root.instance,
226
+ source: input
227
+ } : undefined;
265
228
  // Handed a view handle rather than a module: resolve it and encode what it
266
229
  // points at. This is what makes `useVal(page.header)` read the header.
267
230
  var resolved = core.Internal.viewHandleModule(input);
@@ -371,7 +334,7 @@ function stegaEncode(input, opts) {
371
334
  var _src = core.Internal.media.fillFromGallery(sourceOrSelector, recOpts.schema, getGallery);
372
335
  // `url` carries the edit tag, so a click on an image reaches its field.
373
336
  // `path` must stay raw: it is what the URL was derived from.
374
- return _objectSpread2(_objectSpread2({}, _src), {}, {
337
+ return objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, _src), {}, {
375
338
  url: rec(core.Internal.mediaUrl(_src), recOpts)
376
339
  });
377
340
  }
@@ -415,29 +378,48 @@ function stegaEncode(input, opts) {
415
378
  } finally {
416
379
  _iterator2.f();
417
380
  }
418
- return rec(opts.getModule && opts.getModule(selectorPath) !== undefined ? opts.getModule(selectorPath) : core.Internal.getSource(sourceOrSelector), {
381
+ var moduleSource = opts.getModule && opts.getModule(selectorPath) !== undefined ? opts.getModule(selectorPath) : core.Internal.getSource(sourceOrSelector);
382
+ var outerComponentRoot = componentRoot;
383
+ componentRoot = newSchema && {
419
384
  path: selectorPath,
420
- schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema["executeSerialize"]()
421
- });
385
+ schema: newSchema,
386
+ source: moduleSource
387
+ };
388
+ try {
389
+ return rec(moduleSource, {
390
+ path: selectorPath,
391
+ schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema["executeSerialize"]()
392
+ });
393
+ } finally {
394
+ componentRoot = outerComponentRoot;
395
+ }
422
396
  }
423
397
  if (Array.isArray(sourceOrSelector)) {
424
- return sourceOrSelector.map(function (el, i) {
398
+ var items = sourceOrSelector.map(function (el, i) {
425
399
  return rec(el, recOpts && {
426
400
  path: core.Internal.createValPathOfItem(recOpts.path, i),
427
401
  schema: recOpts.schema.item
428
402
  });
429
403
  });
404
+ // Where the list was read from, as for an object below: an EMPTY list
405
+ // has no item to learn it from, and that is the list an editor most
406
+ // needs to be able to add to (`ValComponentEditor`).
407
+ if (recOpts !== null && recOpts !== void 0 && recOpts.path && !opts.disabled) {
408
+ core.Internal.setValPath(items, recOpts.path);
409
+ }
410
+ return items;
430
411
  }
431
412
  if (!Array.isArray(sourceOrSelector)) {
413
+ var _recOpts$schema$rende;
432
414
  var res = {};
433
415
  var _entries = Object.entries(sourceOrSelector);
434
416
  for (var _i = 0, _entries2 = _entries; _i < _entries2.length; _i++) {
435
417
  var _entries2$_i = slicedToArray._slicedToArray(_entries2[_i], 2),
436
- _key = _entries2$_i[0],
418
+ key = _entries2$_i[0],
437
419
  value = _entries2$_i[1];
438
- res[_key] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
439
- path: core.Internal.createValPathOfItem(recOpts.path, _key),
440
- schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key] : unknownSchema(recOpts.schema)
420
+ res[key] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
421
+ path: core.Internal.createValPathOfItem(recOpts.path, key),
422
+ schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[key] : unknownSchema(recOpts.schema)
441
423
  });
442
424
  }
443
425
  // Where an object was read from, for `attrs`: an object has no text
@@ -447,6 +429,15 @@ function stegaEncode(input, opts) {
447
429
  if (recOpts !== null && recOpts !== void 0 && recOpts.path && !opts.disabled) {
448
430
  core.Internal.setValPath(res, recOpts.path);
449
431
  }
432
+ // The component this object is linked to (`.component()`), so the app
433
+ // can render the object without a registry. In production too: this
434
+ // is how the site renders, not only how the Studio edits.
435
+ if (componentRoot && recOpts !== null && recOpts !== void 0 && recOpts.path && isObjectSchema(recOpts.schema) && ((_recOpts$schema$rende = recOpts.schema.render) === null || _recOpts$schema$rende === void 0 ? void 0 : _recOpts$schema$rende.as) === "component") {
436
+ var render = componentRenderAt(componentRoot, recOpts.path);
437
+ if (render) {
438
+ core.setComponentOfValue(res, render);
439
+ }
440
+ }
450
441
  return res;
451
442
  }
452
443
  core.Internal.log.error("Could not transform source selector: ".concat(_typeof._typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
@@ -729,9 +720,6 @@ function raw(val) {
729
720
  return val;
730
721
  }
731
722
 
732
- exports._defineProperty = _defineProperty;
733
- exports._objectSpread2 = _objectSpread2;
734
- exports._toPropertyKey = _toPropertyKey;
735
723
  exports.attrs = attrs;
736
724
  exports.getModuleIds = getModuleIds;
737
725
  exports.raw = raw;
@@ -1,56 +1,10 @@
1
- import { a as _createForOfIteratorHelper } from './createForOfIteratorHelper-595d57b7.esm.js';
1
+ import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-9b22d0cd.esm.js';
2
2
  import { _ as _typeof } from './typeof-a1531d8f.esm.js';
3
- import { Internal, isValViewSource } from '@valbuild/core';
3
+ import { Internal, isValViewSource, setComponentOfValue, getComponentRender } from '@valbuild/core';
4
4
  import { vercelStegaDecodeAll, vercelStegaSplit, vercelStegaCombine } from '@vercel/stega';
5
+ import { _ as _objectSpread2 } from './objectSpread2-be6bfc61.esm.js';
5
6
  import { _ as _slicedToArray } from './slicedToArray-70ecb9da.esm.js';
6
7
 
7
- function _toPrimitive(t, r) {
8
- if ("object" != typeof t || !t) return t;
9
- var e = t[Symbol.toPrimitive];
10
- if (void 0 !== e) {
11
- var i = e.call(t, r || "default");
12
- if ("object" != typeof i) return i;
13
- throw new TypeError("@@toPrimitive must return a primitive value.");
14
- }
15
- return ("string" === r ? String : Number)(t);
16
- }
17
-
18
- function _toPropertyKey(t) {
19
- var i = _toPrimitive(t, "string");
20
- return "symbol" == typeof i ? i : i + "";
21
- }
22
-
23
- function _defineProperty(e, r, t) {
24
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
25
- value: t,
26
- enumerable: !0,
27
- configurable: !0,
28
- writable: !0
29
- }) : e[r] = t, e;
30
- }
31
-
32
- function ownKeys(e, r) {
33
- var t = Object.keys(e);
34
- if (Object.getOwnPropertySymbols) {
35
- var o = Object.getOwnPropertySymbols(e);
36
- r && (o = o.filter(function (r) {
37
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
38
- })), t.push.apply(t, o);
39
- }
40
- return t;
41
- }
42
- function _objectSpread2(e) {
43
- for (var r = 1; r < arguments.length; r++) {
44
- var t = null != arguments[r] ? arguments[r] : {};
45
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
46
- _defineProperty(e, r, t[r]);
47
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
48
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
49
- });
50
- }
51
- return e;
52
- }
53
-
54
8
  function stegaDecodeStrings(encodedString) {
55
9
  if (!encodedString || typeof encodedString !== "string") return;
56
10
  var encodedBits = vercelStegaDecodeAll(encodedString);
@@ -75,38 +29,8 @@ function stegaDecodeStrings(encodedString) {
75
29
  return paths.length > 0 ? paths : undefined;
76
30
  }
77
31
 
78
- /**
79
- * ValEncodedString is a string that is encoded using steganography.
80
- *
81
- * This means that there is a hidden / non-visible object embedded in the string.
82
- * This object includes a path, which is used to automatically tag
83
- * where the content comes from for contextual editing.
84
- *
85
- */
86
-
87
- /**
88
- * An image as a consumer sees it: what was authored, plus the generated `url`.
89
- *
90
- * `path` stays a plain string — it is what `url` is derived from, so encoding it
91
- * would corrupt every URL built from it.
92
- */
93
-
94
- /**
95
- * A video as a consumer sees it: what was authored, plus a generated `url` on
96
- * the video, on its poster and on each caption track.
97
- *
98
- * Only the video's own `url` carries the edit tag — a click on the player
99
- * reaches the field. The poster and the captions are parts of the same field,
100
- * not fields of their own, so their URLs are plain.
101
- *
102
- * An HLS stream (`mimeType` `application/vnd.apple.mpegurl`) plays natively in
103
- * Safari and needs a library such as hls.js everywhere else; `url` is then the
104
- * master playlist.
105
- */
106
-
107
- /**
108
- * RichText is accessible by users (after conversion via useVal / fetchVal)
109
- **/
32
+ // The read types are defined in core (`read.ts`), which has to be able to say
33
+ // them: `.component()` checks a component against what a reader gives back.
110
34
 
111
35
  /**
112
36
  * What resolving `T` gives back — the one definition the framework readers
@@ -150,6 +74,33 @@ function stegaDecodeStrings(encodedString) {
150
74
 
151
75
  /** What a route reader gives back for the entry the params matched. */
152
76
 
77
+ /**
78
+ * The component of the object at `path`, looked up on the schema INSTANCE of
79
+ * what is being walked: from the root down, by the path, through whichever
80
+ * variant of a union the value there takes. `null` when it cannot be found,
81
+ * which leaves the object without a component, as one whose schema has none.
82
+ */
83
+ function componentRenderAt(root, path) {
84
+ try {
85
+ // Only the part below the root: a `.jsonValues()` entry's root is the
86
+ // entry, whose own path already has a key in it.
87
+ var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(root.path),
88
+ _Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 2),
89
+ rootModulePath = _Internal$splitModule2[1];
90
+ var _Internal$splitModule3 = Internal.splitModuleFilePathAndModulePath(path),
91
+ _Internal$splitModule4 = _slicedToArray(_Internal$splitModule3, 2),
92
+ modulePath = _Internal$splitModule4[1];
93
+ var below = Internal.splitModulePath(modulePath).slice(Internal.splitModulePath(rootModulePath).length);
94
+ if (below.length === 0) {
95
+ return getComponentRender(root.schema, root.source);
96
+ }
97
+ var at = Internal.resolvePath(Internal.patchPathToModulePath(below), root.source, root.schema);
98
+ return getComponentRender(at.schema, at.source);
99
+ } catch (_unused) {
100
+ return null;
101
+ }
102
+ }
103
+
153
104
  /**
154
105
  * Resolves the matching variant of a discriminated union from the value's tag.
155
106
  * Returns the matching schema or null if no match is found.
@@ -249,6 +200,7 @@ function handleRichTextSchema(sourceOrSelector, recOpts, rec) {
249
200
  return sourceOrSelector;
250
201
  }
251
202
  function stegaEncode(input, opts) {
203
+ var _opts$root;
252
204
  var viewModules = new Map();
253
205
  /**
254
206
  * The published entries of the galleries the module's fields pick from, for
@@ -260,6 +212,17 @@ function stegaEncode(input, opts) {
260
212
  var _opts$getModule, _opts$getModule2;
261
213
  return (_opts$getModule = (_opts$getModule2 = opts.getModule) === null || _opts$getModule2 === void 0 ? void 0 : _opts$getModule2.call(opts, modulePath)) !== null && _opts$getModule !== void 0 ? _opts$getModule : galleries.get(modulePath);
262
214
  };
215
+ /**
216
+ * What is being walked, with its schema INSTANCE: the one thing that holds a
217
+ * `.component()`'s closures. Everything below walks the serialized schema,
218
+ * which carries a marker and not the component, so an object with the
219
+ * marker looks its component up from here, by its own path.
220
+ */
221
+ var componentRoot = ((_opts$root = opts.root) === null || _opts$root === void 0 ? void 0 : _opts$root.instance) !== undefined ? {
222
+ path: opts.root.path,
223
+ schema: opts.root.instance,
224
+ source: input
225
+ } : undefined;
263
226
  // Handed a view handle rather than a module: resolve it and encode what it
264
227
  // points at. This is what makes `useVal(page.header)` read the header.
265
228
  var resolved = Internal.viewHandleModule(input);
@@ -413,29 +376,48 @@ function stegaEncode(input, opts) {
413
376
  } finally {
414
377
  _iterator2.f();
415
378
  }
416
- return rec(opts.getModule && opts.getModule(selectorPath) !== undefined ? opts.getModule(selectorPath) : Internal.getSource(sourceOrSelector), {
379
+ var moduleSource = opts.getModule && opts.getModule(selectorPath) !== undefined ? opts.getModule(selectorPath) : Internal.getSource(sourceOrSelector);
380
+ var outerComponentRoot = componentRoot;
381
+ componentRoot = newSchema && {
417
382
  path: selectorPath,
418
- schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema["executeSerialize"]()
419
- });
383
+ schema: newSchema,
384
+ source: moduleSource
385
+ };
386
+ try {
387
+ return rec(moduleSource, {
388
+ path: selectorPath,
389
+ schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema["executeSerialize"]()
390
+ });
391
+ } finally {
392
+ componentRoot = outerComponentRoot;
393
+ }
420
394
  }
421
395
  if (Array.isArray(sourceOrSelector)) {
422
- return sourceOrSelector.map(function (el, i) {
396
+ var items = sourceOrSelector.map(function (el, i) {
423
397
  return rec(el, recOpts && {
424
398
  path: Internal.createValPathOfItem(recOpts.path, i),
425
399
  schema: recOpts.schema.item
426
400
  });
427
401
  });
402
+ // Where the list was read from, as for an object below: an EMPTY list
403
+ // has no item to learn it from, and that is the list an editor most
404
+ // needs to be able to add to (`ValComponentEditor`).
405
+ if (recOpts !== null && recOpts !== void 0 && recOpts.path && !opts.disabled) {
406
+ Internal.setValPath(items, recOpts.path);
407
+ }
408
+ return items;
428
409
  }
429
410
  if (!Array.isArray(sourceOrSelector)) {
411
+ var _recOpts$schema$rende;
430
412
  var res = {};
431
413
  var _entries = Object.entries(sourceOrSelector);
432
414
  for (var _i = 0, _entries2 = _entries; _i < _entries2.length; _i++) {
433
415
  var _entries2$_i = _slicedToArray(_entries2[_i], 2),
434
- _key = _entries2$_i[0],
416
+ key = _entries2$_i[0],
435
417
  value = _entries2$_i[1];
436
- res[_key] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
437
- path: Internal.createValPathOfItem(recOpts.path, _key),
438
- schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key] : unknownSchema(recOpts.schema)
418
+ res[key] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
419
+ path: Internal.createValPathOfItem(recOpts.path, key),
420
+ schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[key] : unknownSchema(recOpts.schema)
439
421
  });
440
422
  }
441
423
  // Where an object was read from, for `attrs`: an object has no text
@@ -445,6 +427,15 @@ function stegaEncode(input, opts) {
445
427
  if (recOpts !== null && recOpts !== void 0 && recOpts.path && !opts.disabled) {
446
428
  Internal.setValPath(res, recOpts.path);
447
429
  }
430
+ // The component this object is linked to (`.component()`), so the app
431
+ // can render the object without a registry. In production too: this
432
+ // is how the site renders, not only how the Studio edits.
433
+ if (componentRoot && recOpts !== null && recOpts !== void 0 && recOpts.path && isObjectSchema(recOpts.schema) && ((_recOpts$schema$rende = recOpts.schema.render) === null || _recOpts$schema$rende === void 0 ? void 0 : _recOpts$schema$rende.as) === "component") {
434
+ var render = componentRenderAt(componentRoot, recOpts.path);
435
+ if (render) {
436
+ setComponentOfValue(res, render);
437
+ }
438
+ }
448
439
  return res;
449
440
  }
450
441
  Internal.log.error("Could not transform source selector: ".concat(_typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
@@ -727,4 +718,4 @@ function raw(val) {
727
718
  return val;
728
719
  }
729
720
 
730
- export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, _toPropertyKey as d, _defineProperty as e, getModuleIds as g, raw as r, stegaDecodeStrings as s };
721
+ export { stegaEncode as a, stegaClean as b, attrs as c, getModuleIds as g, raw as r, stegaDecodeStrings as s };