@valbuild/react 0.154.1 → 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 +36 -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
@@ -2,14 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-522d616d.cjs.dev.js');
6
- var raw = require('../../dist/raw-67d24dd6.cjs.dev.js');
5
+ var toConsumableArray = require('../../dist/toConsumableArray-d7cf1601.cjs.dev.js');
6
+ var objectSpread2 = require('../../dist/objectSpread2-792eb2c2.cjs.dev.js');
7
7
  var React = require('react');
8
8
  var ReactJSXRuntime = require('react/jsx-runtime');
9
+ var raw = require('../../dist/raw-de032c12.cjs.dev.js');
10
+ var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-8a871dc3.cjs.dev.js');
11
+ var slicedToArray = require('../../dist/slicedToArray-387314c6.cjs.dev.js');
9
12
  var _typeof = require('../../dist/typeof-b568f48f.cjs.dev.js');
10
13
  var core = require('@valbuild/core');
14
+ var ValPreviewBridgeCore = require('../../dist/ValPreviewBridgeCore-bbedf957.cjs.dev.js');
15
+ var ValComponentEditorChrome = require('../../dist/ValComponentEditorChrome-440d086a.cjs.dev.js');
11
16
  var patch = require('@valbuild/core/patch');
12
- var slicedToArray = require('../../dist/slicedToArray-387314c6.cjs.dev.js');
13
17
  var internal = require('@valbuild/shared/internal');
14
18
  require('@vercel/stega');
15
19
 
@@ -127,7 +131,7 @@ function ValRichText(_ref) {
127
131
  href: child.tag === "a" ? child.href : undefined
128
132
  });
129
133
  }
130
- return /*#__PURE__*/ReactJSXRuntime.jsx("div", raw._objectSpread2(raw._objectSpread2({
134
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", objectSpread2._objectSpread2(objectSpread2._objectSpread2({
131
135
  className: className,
132
136
  style: style
133
137
  }, raw.attrs(root)), {}, {
@@ -140,7 +144,7 @@ function classNameOfTag(tag, style, theme) {
140
144
  var _tag;
141
145
  thisTagClassName = (_tag = theme[tag]) !== null && _tag !== void 0 ? _tag : null;
142
146
  }
143
- return [].concat(createForOfIteratorHelper._toConsumableArray(thisTagClassName ? [thisTagClassName] : []), createForOfIteratorHelper._toConsumableArray(style.map(function (style) {
147
+ return [].concat(toConsumableArray._toConsumableArray(thisTagClassName ? [thisTagClassName] : []), toConsumableArray._toConsumableArray(style.map(function (style) {
144
148
  if (theme &&
145
149
  // not need on type-level, but defensive on runtime:
146
150
  typeof style === "string") {
@@ -164,7 +168,7 @@ function _classCallCheck(a, n) {
164
168
  function _defineProperties(e, r) {
165
169
  for (var t = 0; t < r.length; t++) {
166
170
  var o = r[t];
167
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, raw._toPropertyKey(o.key), o);
171
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, objectSpread2._toPropertyKey(o.key), o);
168
172
  }
169
173
  }
170
174
  function _createClass(e, r, t) {
@@ -190,23 +194,23 @@ var ValExternalStore = /*#__PURE__*/function () {
190
194
  function ValExternalStore() {
191
195
  var _this = this;
192
196
  _classCallCheck(this, ValExternalStore);
193
- raw._defineProperty(this, "listeners", void 0);
194
- raw._defineProperty(this, "loadPromises", void 0);
197
+ objectSpread2._defineProperty(this, "listeners", void 0);
198
+ objectSpread2._defineProperty(this, "loadPromises", void 0);
195
199
  // Path-keyed reads, as the Studio sent them. The single source of truth:
196
200
  // load state, snapshots and revisions are all derived from this, so data
197
201
  // can be queried for any combination of paths even before a subscriber
198
202
  // registers.
199
- raw._defineProperty(this, "reads", void 0);
203
+ objectSpread2._defineProperty(this, "reads", void 0);
200
204
  // Bumped per path whenever its read MOVES: what `revision` is made of.
201
- raw._defineProperty(this, "revisions", void 0);
205
+ objectSpread2._defineProperty(this, "revisions", void 0);
202
206
  // Reference-stable per-subscriberId snapshot cache for `get`.
203
207
  // Built lazily from `reads` in get() and invalidated in receive().
204
- raw._defineProperty(this, "snapshots", void 0);
208
+ objectSpread2._defineProperty(this, "snapshots", void 0);
205
209
  // One-shot listeners used solely by waitForLoad. Kept separate from the
206
210
  // useSyncExternalStore listeners so waitForLoad never has to register (and
207
211
  // leak) a subscriberId.
208
- raw._defineProperty(this, "loadListeners", void 0);
209
- raw._defineProperty(this, "subscribe", function (paths) {
212
+ objectSpread2._defineProperty(this, "loadListeners", void 0);
213
+ objectSpread2._defineProperty(this, "subscribe", function (paths) {
210
214
  return function (listener) {
211
215
  var subscriberId = createSubscriberId(paths);
212
216
  var existing = _this.listeners.get(subscriberId);
@@ -224,17 +228,17 @@ var ValExternalStore = /*#__PURE__*/function () {
224
228
  };
225
229
  };
226
230
  });
227
- raw._defineProperty(this, "getSnapshot", function (paths) {
231
+ objectSpread2._defineProperty(this, "getSnapshot", function (paths) {
228
232
  return function () {
229
233
  return _this.get(paths);
230
234
  };
231
235
  });
232
- raw._defineProperty(this, "getServerSnapshot", function (paths) {
236
+ objectSpread2._defineProperty(this, "getServerSnapshot", function (paths) {
233
237
  return function () {
234
238
  return _this.get(paths);
235
239
  };
236
240
  });
237
- raw._defineProperty(this, "get", function (paths) {
241
+ objectSpread2._defineProperty(this, "get", function (paths) {
238
242
  var subscriberId = createSubscriberId(paths);
239
243
  if (_this.snapshots.has(subscriberId)) {
240
244
  return _this.snapshots.get(subscriberId);
@@ -264,7 +268,7 @@ var ValExternalStore = /*#__PURE__*/function () {
264
268
  _this.snapshots.set(subscriberId, record);
265
269
  return record;
266
270
  });
267
- raw._defineProperty(this, "hasAllLoaded", function (paths) {
271
+ objectSpread2._defineProperty(this, "hasAllLoaded", function (paths) {
268
272
  var _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(paths),
269
273
  _step2;
270
274
  try {
@@ -293,7 +297,7 @@ var ValExternalStore = /*#__PURE__*/function () {
293
297
  * hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
294
298
  * failure is diagnosable while the page still renders with partial data.
295
299
  */
296
- raw._defineProperty(this, "waitForLoad", function (paths) {
300
+ objectSpread2._defineProperty(this, "waitForLoad", function (paths) {
297
301
  if (_this.hasAllLoaded(paths)) {
298
302
  return Promise.resolve();
299
303
  }
@@ -818,7 +822,9 @@ selector, key
818
822
  }
819
823
  return {
820
824
  path: path,
821
- schema: schema["executeSerialize"]().item
825
+ schema: schema["executeSerialize"]().item,
826
+ // Where a `.component()` of the entry's objects lives: see `stegaEncode`.
827
+ instance: schema["item"]
822
828
  };
823
829
  }
824
830
 
@@ -1088,7 +1094,7 @@ function codeChangedReporter(announce) {
1088
1094
  var scheduled = false;
1089
1095
  var flush = function flush() {
1090
1096
  scheduled = false;
1091
- var modules = createForOfIteratorHelper._toConsumableArray(refused.keys()).sort();
1097
+ var modules = toConsumableArray._toConsumableArray(refused.keys()).sort();
1092
1098
  if (modules.join("\n") === announced.join("\n")) return;
1093
1099
  announced = modules;
1094
1100
  announce(modules);
@@ -1351,7 +1357,7 @@ function readWork() {
1351
1357
 
1352
1358
  function viewOf(env, plan, settled) {
1353
1359
  var schemaVersionOf = env.schemaVersionOf;
1354
- return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2(raw._objectSpread2({
1360
+ return layered([].concat(toConsumableArray._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? objectSpread2._objectSpread2(objectSpread2._objectSpread2({
1355
1361
  schemaOf: function schemaOf(path) {
1356
1362
  var module = plan.own.get(path);
1357
1363
  return module === undefined ? null : schemaVersionOf(module);
@@ -1484,7 +1490,7 @@ function fillRecord(view, path, record, at, waits) {
1484
1490
  break;
1485
1491
  }
1486
1492
  if (content !== undefined) {
1487
- filled !== null && filled !== void 0 ? filled : filled = raw._objectSpread2({}, record);
1493
+ filled !== null && filled !== void 0 ? filled : filled = objectSpread2._objectSpread2({}, record);
1488
1494
  filled[key] = content;
1489
1495
  }
1490
1496
  }
@@ -1846,7 +1852,7 @@ function allOf(waits) {
1846
1852
  return undefined;
1847
1853
  });
1848
1854
  held.push({
1849
- waits: createForOfIteratorHelper._toConsumableArray(waits),
1855
+ waits: toConsumableArray._toConsumableArray(waits),
1850
1856
  all: all
1851
1857
  });
1852
1858
  combined.set(first, held);
@@ -1861,7 +1867,7 @@ function allOf(waits) {
1861
1867
  */
1862
1868
  function useResolvedVal(selector, env, opts) {
1863
1869
  return useResolved(selector, env, function (settled) {
1864
- return resolveVal(selector, env, raw._objectSpread2({
1870
+ return resolveVal(selector, env, objectSpread2._objectSpread2({
1865
1871
  settled: settled
1866
1872
  }, opts));
1867
1873
  });
@@ -1923,7 +1929,405 @@ function readsOfFetchVal(fetchVal) {
1923
1929
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1924
1930
  }
1925
1931
 
1932
+ function findValModule(_x, _x2) {
1933
+ return _findValModule.apply(this, arguments);
1934
+ }
1935
+ function _findValModule() {
1936
+ _findValModule = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules, sourcePath) {
1937
+ var _Internal$splitModule, _Internal$splitModule2, moduleFilePath, _iterator, _step, _yield$def, def, valModule, _t, _t2, _t3, _t4;
1938
+ return _regenerator().w(function (_context) {
1939
+ while (1) switch (_context.p = _context.n) {
1940
+ case 0:
1941
+ _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(sourcePath), _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1), moduleFilePath = _Internal$splitModule2[0];
1942
+ _iterator = createForOfIteratorHelper._createForOfIteratorHelper(valModules.modules);
1943
+ _context.p = 1;
1944
+ _iterator.s();
1945
+ case 2:
1946
+ if ((_step = _iterator.n()).done) {
1947
+ _context.n = 8;
1948
+ break;
1949
+ }
1950
+ def = _step.value.def;
1951
+ _context.n = 3;
1952
+ return def();
1953
+ case 3:
1954
+ _t2 = _yield$def = _context.v;
1955
+ _t = _t2 === null;
1956
+ if (_t) {
1957
+ _context.n = 4;
1958
+ break;
1959
+ }
1960
+ _t = _yield$def === void 0;
1961
+ case 4:
1962
+ if (!_t) {
1963
+ _context.n = 5;
1964
+ break;
1965
+ }
1966
+ _t3 = void 0;
1967
+ _context.n = 6;
1968
+ break;
1969
+ case 5:
1970
+ _t3 = _yield$def["default"];
1971
+ case 6:
1972
+ valModule = _t3;
1973
+ if (!(valModule && String(core.Internal.getValPath(valModule)) === moduleFilePath)) {
1974
+ _context.n = 7;
1975
+ break;
1976
+ }
1977
+ return _context.a(2, valModule);
1978
+ case 7:
1979
+ _context.n = 2;
1980
+ break;
1981
+ case 8:
1982
+ _context.n = 10;
1983
+ break;
1984
+ case 9:
1985
+ _context.p = 9;
1986
+ _t4 = _context.v;
1987
+ _iterator.e(_t4);
1988
+ case 10:
1989
+ _context.p = 10;
1990
+ _iterator.f();
1991
+ return _context.f(10);
1992
+ case 11:
1993
+ return _context.a(2, null);
1994
+ }
1995
+ }, _callee, null, [[1, 9, 10, 11]]);
1996
+ }));
1997
+ return _findValModule.apply(this, arguments);
1998
+ }
1999
+ /**
2000
+ * EXPERIMENTAL: the component that renders the value at `sourcePath`, and the
2001
+ * props to render it with - the framework-free half of a component preview,
2002
+ * shared by `@valbuild/next` and `@valbuild/tanstack`.
2003
+ *
2004
+ * `moduleValue` is the module's content as the app reads it (`fetchVal`), not
2005
+ * its own source: a section added in the Studio is in the former and not the
2006
+ * latter, and only the content says which variant of a union a section is.
2007
+ *
2008
+ * With `example`, the props are the render's `example`; with `props`, those.
2009
+ * Neither is content, so neither carries edit tags: a click in the preview must
2010
+ * not lead to a field the value is not in.
2011
+ */
2012
+ function resolveValComponentPreview(_x3) {
2013
+ return _resolveValComponentPreview.apply(this, arguments);
2014
+ }
2015
+
2016
+ /**
2017
+ * Give every object inside `value` the component its schema links it to,
2018
+ * as a reader does (`stegaEncode`), for a value that lost them on the way.
2019
+ *
2020
+ * A preview's content often has: on TanStack the route's loader reads it in a
2021
+ * server function, and what comes back is JSON, which a component cannot
2022
+ * ride on. The component being previewed is found by path either way, but
2023
+ * one that renders a list of components of its own (`ValComponentEditor`)
2024
+ * would be handed items with nothing to render them with.
2025
+ *
2026
+ * Looked up from the root by each object's path - through whichever variant
2027
+ * of a union the value there takes - which is the reader's own way of
2028
+ * finding one. A path that cannot be resolved has no component, as before.
2029
+ */
2030
+ function _resolveValComponentPreview() {
2031
+ _resolveValComponentPreview = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
2032
+ var valModule, sourcePath, moduleValue, example, props, _Internal$splitModule3, _Internal$splitModule4, moduleFilePath, modulePath, moduleSchema, schema, value, resolved, render, source, componentProps, _t5, _t6, _t7;
2033
+ return _regenerator().w(function (_context2) {
2034
+ while (1) switch (_context2.p = _context2.n) {
2035
+ case 0:
2036
+ valModule = _ref.valModule, sourcePath = _ref.sourcePath, moduleValue = _ref.moduleValue, example = _ref.example, props = _ref.props;
2037
+ _Internal$splitModule3 = core.Internal.splitModuleFilePathAndModulePath(sourcePath), _Internal$splitModule4 = slicedToArray._slicedToArray(_Internal$splitModule3, 2), moduleFilePath = _Internal$splitModule4[0], modulePath = _Internal$splitModule4[1];
2038
+ moduleSchema = core.Internal.getSchema(valModule);
2039
+ if (moduleSchema) {
2040
+ _context2.n = 1;
2041
+ break;
2042
+ }
2043
+ return _context2.a(2, {
2044
+ status: "error",
2045
+ message: "'".concat(moduleFilePath, "' has no schema.")
2046
+ });
2047
+ case 1:
2048
+ schema = moduleSchema;
2049
+ value = moduleValue;
2050
+ if (!modulePath) {
2051
+ _context2.n = 4;
2052
+ break;
2053
+ }
2054
+ _context2.p = 2;
2055
+ resolved = core.Internal.resolvePath(modulePath,
2056
+ // What the app read is the module's source with media resolved,
2057
+ // which is what this walks.
2058
+ moduleValue, moduleSchema);
2059
+ schema = resolved.schema;
2060
+ value = resolved.source;
2061
+ _context2.n = 4;
2062
+ break;
2063
+ case 3:
2064
+ _context2.p = 3;
2065
+ _t5 = _context2.v;
2066
+ return _context2.a(2, {
2067
+ status: "error",
2068
+ message: "".concat(sourcePath, ": ").concat(_t5 instanceof Error ? _t5.message : String(_t5))
2069
+ });
2070
+ case 4:
2071
+ render = core.getComponentRender(schema, value);
2072
+ if (render) {
2073
+ _context2.n = 5;
2074
+ break;
2075
+ }
2076
+ return _context2.a(2, {
2077
+ status: "error",
2078
+ message: "".concat(sourcePath, " has no component: give its schema .component(() => import(...)) to preview it.")
2079
+ });
2080
+ case 5:
2081
+ if (!(props !== undefined || example)) {
2082
+ _context2.n = 7;
2083
+ break;
2084
+ }
2085
+ source = props !== undefined ? props : render.example;
2086
+ if (!(source === undefined)) {
2087
+ _context2.n = 6;
2088
+ break;
2089
+ }
2090
+ return _context2.a(2, {
2091
+ status: "error",
2092
+ message: "".concat(sourcePath, " has no example.")
2093
+ });
2094
+ case 6:
2095
+ value = raw.stegaEncode(source, {
2096
+ disabled: true,
2097
+ root: {
2098
+ path: sourcePath,
2099
+ schema: schema["executeSerialize"](),
2100
+ // So a list of components inside the example has its components
2101
+ instance: schema
2102
+ }
2103
+ });
2104
+ _context2.n = 8;
2105
+ break;
2106
+ case 7:
2107
+ linkComponents(value, schema);
2108
+ case 8:
2109
+ // What the site hands the component (`ValComponentEditor`): the value, or
2110
+ // what the schema's `props` function makes of it. One function for both, so
2111
+ // the preview cannot show a component the site renders differently.
2112
+ componentProps = core.componentPropsOf(render, value);
2113
+ if (!(_typeof._typeof(componentProps) !== "object" || componentProps === null)) {
2114
+ _context2.n = 9;
2115
+ break;
2116
+ }
2117
+ return _context2.a(2, {
2118
+ status: "error",
2119
+ message: "Expected an object to spread as props, got ".concat(componentProps === null ? "null" : _typeof._typeof(componentProps), ".")
2120
+ });
2121
+ case 9:
2122
+ _context2.n = 10;
2123
+ return core.loadComponent(render);
2124
+ case 10:
2125
+ _t6 = _context2.v;
2126
+ _t7 = componentProps;
2127
+ return _context2.a(2, {
2128
+ status: "ok",
2129
+ Component: _t6,
2130
+ props: _t7
2131
+ });
2132
+ }
2133
+ }, _callee2, null, [[2, 3]]);
2134
+ }));
2135
+ return _resolveValComponentPreview.apply(this, arguments);
2136
+ }
2137
+ function linkComponents(value, schema) {
2138
+ var _visit = function visit(node, path) {
2139
+ if (Array.isArray(node)) {
2140
+ node.forEach(function (child, index) {
2141
+ return _visit(child, [].concat(toConsumableArray._toConsumableArray(path), [String(index)]));
2142
+ });
2143
+ return;
2144
+ }
2145
+ if (_typeof._typeof(node) !== "object" || node === null) {
2146
+ return;
2147
+ }
2148
+ // The root is the previewed component itself, which the caller renders
2149
+ if (path.length > 0) {
2150
+ try {
2151
+ var at = core.Internal.resolvePath(core.Internal.patchPathToModulePath(path),
2152
+ // What the app read is the source with media resolved, which is
2153
+ // what `resolvePath` walks: see `resolveValComponentPreview`.
2154
+ value, schema);
2155
+ var render = core.getComponentRender(at.schema, at.source);
2156
+ if (render) {
2157
+ core.setComponentOfValue(node, render);
2158
+ }
2159
+ } catch (_unused) {
2160
+ // Not a path the schema knows: nothing to link
2161
+ }
2162
+ }
2163
+ for (var _i = 0, _Object$entries = Object.entries(node); _i < _Object$entries.length; _i++) {
2164
+ var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
2165
+ key = _Object$entries$_i[0],
2166
+ child = _Object$entries$_i[1];
2167
+ _visit(child, [].concat(toConsumableArray._toConsumableArray(path), [key]));
2168
+ }
2169
+ };
2170
+ _visit(value, []);
2171
+ }
2172
+
2173
+ /** A message in place of the component, for when there is none to render. */
2174
+ function ValPreviewMessage(_ref2) {
2175
+ var children = _ref2.children;
2176
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
2177
+ style: {
2178
+ fontFamily: "ui-monospace, monospace",
2179
+ fontSize: "13px",
2180
+ padding: "1rem"
2181
+ },
2182
+ children: children
2183
+ });
2184
+ }
2185
+
2186
+ /**
2187
+ * EXPERIMENTAL: renders content with the components its schema links it to.
2188
+ *
2189
+ * Each object is rendered by the component its own schema names
2190
+ * (`.component(() => import("./Hero"))`), with the props that schema's `props`
2191
+ * function makes of it - so there is no map from a `type` to a component to
2192
+ * keep, and none to forget a case in. A list renders every item in order; a
2193
+ * single object renders the one.
2194
+ *
2195
+ * In the Studio, on the page itself, a list can be arranged: a section is
2196
+ * dragged to another place, one is added between two others, one is taken
2197
+ * away. Outside the Studio none of that exists, and this is the components
2198
+ * and an element around each.
2199
+ *
2200
+ * It is optional. The same content can be read and rendered by hand, with a
2201
+ * `map` and a `switch`, and a page is free to use this for one list and not
2202
+ * for the rest of what it shows.
2203
+ *
2204
+ * The component is found on the VALUE, which the reader attached it to. So
2205
+ * render the value where it was read: one passed from a server component to
2206
+ * a client component arrives without it, like the module behind a `s.view()`.
2207
+ *
2208
+ * @example
2209
+ * const page = useValRoute(pageVal, {});
2210
+ * return <ValComponentEditor value={page.sections} />;
2211
+ */
2212
+ function ValComponentEditor(_ref) {
2213
+ var value = _ref.value,
2214
+ className = _ref.className,
2215
+ itemClassName = _ref.itemClassName,
2216
+ _ref$fallback = _ref.fallback,
2217
+ fallback = _ref$fallback === void 0 ? null : _ref$fallback;
2218
+ if (value === null || value === undefined) {
2219
+ return null;
2220
+ }
2221
+ if (isList(value)) {
2222
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ValComponentEditorChrome.ValComponentList, {
2223
+ path: core.Internal.valPathOf(value),
2224
+ className: className,
2225
+ count: value.length,
2226
+ children: value.map(function (item, index) {
2227
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ValComponentItem
2228
+ // A list item has no identity but its place
2229
+ , {
2230
+ value: item,
2231
+ className: itemClassName,
2232
+ fallback: fallback
2233
+ }, index);
2234
+ })
2235
+ });
2236
+ }
2237
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ValComponentItem, {
2238
+ value: value,
2239
+ className: itemClassName,
2240
+ fallback: fallback
2241
+ });
2242
+ }
2243
+ function isList(value) {
2244
+ return Array.isArray(value);
2245
+ }
2246
+ function ValComponentItem(_ref2) {
2247
+ var value = _ref2.value,
2248
+ className = _ref2.className,
2249
+ fallback = _ref2.fallback;
2250
+ var path = core.Internal.valPathOf(value);
2251
+ var render = core.componentOfValue(value);
2252
+ // The element is there whether or not there is something in it: it is the
2253
+ // item's place in the list, which the editing on the page counts by.
2254
+ var attributes = objectSpread2._defineProperty(objectSpread2._defineProperty({
2255
+ className: className
2256
+ }, ValComponentEditorChrome.VAL_COMPONENT_ATTRIBUTE, ""), "data-val-path", path);
2257
+ if (render === null) {
2258
+ warnNoComponent(value, path);
2259
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", objectSpread2._objectSpread2({}, attributes));
2260
+ }
2261
+ var props = core.componentPropsOf(render, value);
2262
+ if (_typeof._typeof(props) !== "object" || props === null) {
2263
+ core.Internal.log.error("ValComponentEditor: the props of the component".concat(path ? " at ".concat(path) : "", " must be an object, got ").concat(props === null ? "null" : _typeof._typeof(props), ". Check what its `props` function returns."));
2264
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", objectSpread2._objectSpread2({}, attributes));
2265
+ }
2266
+ var Component = lazyComponentOf(render);
2267
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, attributes), {}, {
2268
+ children: /*#__PURE__*/ReactJSXRuntime.jsx(React.Suspense, {
2269
+ fallback: fallback,
2270
+ children: /*#__PURE__*/ReactJSXRuntime.jsx(Component, objectSpread2._objectSpread2({}, props))
2271
+ })
2272
+ }));
2273
+ }
2274
+ var lazyComponents = new WeakMap();
2275
+
2276
+ /**
2277
+ * One lazy component per thunk, kept: a new `lazy()` on every render is a new
2278
+ * component type every time, which React unmounts and mounts again - a
2279
+ * section that loses its state, and suspends, at every keystroke.
2280
+ */
2281
+ function lazyComponentOf(render) {
2282
+ var existing = lazyComponents.get(render.component);
2283
+ if (existing) {
2284
+ return existing;
2285
+ }
2286
+ var created = /*#__PURE__*/React.lazy(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2287
+ var _t;
2288
+ return _regenerator().w(function (_context) {
2289
+ while (1) switch (_context.n) {
2290
+ case 0:
2291
+ _context.n = 1;
2292
+ return core.loadComponent(render);
2293
+ case 1:
2294
+ _t = _context.v;
2295
+ return _context.a(2, {
2296
+ "default": _t
2297
+ });
2298
+ }
2299
+ }, _callee);
2300
+ })));
2301
+ lazyComponents.set(render.component, created);
2302
+ return created;
2303
+ }
2304
+ var warned = new Set();
2305
+
2306
+ /**
2307
+ * Said once per place, and only where there is someone to read it: in
2308
+ * production the types have already refused this, so what is left is a value
2309
+ * that lost its component on the way here.
2310
+ */
2311
+ function warnNoComponent(value, path) {
2312
+ if (value === null || value === undefined) {
2313
+ // An item nobody has filled in yet: an editor just added it.
2314
+ return;
2315
+ }
2316
+ var key = path !== null && path !== void 0 ? path : "";
2317
+ if (warned.has(key)) {
2318
+ return;
2319
+ }
2320
+ warned.add(key);
2321
+ core.Internal.log.warn("ValComponentEditor: nothing to render".concat(path ? " ".concat(path) : " a value", " with. ") + "Either its schema has no .component(), or the value was passed from a server component to a client component, which drops the component it carried. " + "Render it in the component that read it.");
2322
+ }
2323
+
2324
+ Object.defineProperty(exports, 'ValPreviewBridgeCore', {
2325
+ enumerable: true,
2326
+ get: function () { return ValPreviewBridgeCore.ValPreviewBridgeCore; }
2327
+ });
2328
+ exports.ValComponentEditor = ValComponentEditor;
1926
2329
  exports.ValExternalStore = ValExternalStore;
2330
+ exports.ValPreviewMessage = ValPreviewMessage;
1927
2331
  exports.ValRichText = ValRichText;
1928
2332
  exports.applyValEvent = applyValEvent;
1929
2333
  exports.awaitResolved = awaitResolved;
@@ -1936,6 +2340,7 @@ exports.draftHolds = draftHolds;
1936
2340
  exports.draftHoldsVersions = draftHoldsVersions;
1937
2341
  exports.entryOfModuleSource = entryOfModuleSource;
1938
2342
  exports.fetchValFrom = fetchValFrom;
2343
+ exports.findValModule = findValModule;
1939
2344
  exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
1940
2345
  exports.isDraft = isDraft;
1941
2346
  exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
@@ -1947,6 +2352,7 @@ exports.readWork = readWork;
1947
2352
  exports.readsOfFetchVal = readsOfFetchVal;
1948
2353
  exports.resolveModuleEntry = resolveModuleEntry;
1949
2354
  exports.resolveVal = resolveVal;
2355
+ exports.resolveValComponentPreview = resolveValComponentPreview;
1950
2356
  exports.resolveValEntry = resolveValEntry;
1951
2357
  exports.snapshotSource = snapshotSource;
1952
2358
  exports.startRefreshLoop = startRefreshLoop;