@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.
- package/CHANGELOG.md +44 -0
- package/analytics/dist/valbuild-react-analytics.browser.esm.js +2 -1
- package/analytics/dist/valbuild-react-analytics.cjs.dev.js +6 -5
- package/analytics/dist/valbuild-react-analytics.cjs.prod.js +6 -5
- package/analytics/dist/valbuild-react-analytics.esm.js +2 -1
- package/analytics/dist/valbuild-react-analytics.worker.esm.js +2 -1
- package/dist/ValComponentEditorChrome-440d086a.cjs.dev.js +966 -0
- package/dist/ValComponentEditorChrome-4ac9dc79.worker.esm.js +952 -0
- package/dist/ValComponentEditorChrome-93321513.esm.js +952 -0
- package/dist/ValComponentEditorChrome-bf2fefc6.browser.esm.js +952 -0
- package/dist/ValComponentEditorChrome-c0b30556.cjs.js +7 -0
- package/dist/ValComponentEditorChrome-c0b30556.cjs.prod.js +966 -0
- package/dist/ValPreviewBridgeCore-00015d00.esm.js +157 -0
- package/dist/ValPreviewBridgeCore-023ffffb.browser.esm.js +157 -0
- package/dist/ValPreviewBridgeCore-9b984cb0.cjs.js +7 -0
- package/dist/ValPreviewBridgeCore-9b984cb0.cjs.prod.js +161 -0
- package/dist/ValPreviewBridgeCore-bbedf957.cjs.dev.js +161 -0
- package/dist/ValPreviewBridgeCore-e0d5a840.worker.esm.js +157 -0
- package/dist/{createForOfIteratorHelper-598a2f85.cjs.prod.js → createForOfIteratorHelper-6f9dc6fa.cjs.prod.js} +0 -17
- package/dist/{createForOfIteratorHelper-522d616d.cjs.dev.js → createForOfIteratorHelper-8a871dc3.cjs.dev.js} +0 -17
- package/dist/{createForOfIteratorHelper-595d57b7.esm.js → createForOfIteratorHelper-8bd0009a.browser.esm.js} +2 -18
- package/dist/{createForOfIteratorHelper-548f1578.worker.esm.js → createForOfIteratorHelper-93215c75.worker.esm.js} +2 -18
- package/dist/{createForOfIteratorHelper-3316a633.browser.esm.js → createForOfIteratorHelper-9b22d0cd.esm.js} +2 -18
- package/dist/declarations/src/internal/ValComponentEditor.d.ts +54 -0
- package/dist/declarations/src/internal/ValPreviewBridgeCore.d.ts +22 -0
- package/dist/declarations/src/internal/componentPreview.d.ts +39 -0
- package/dist/declarations/src/internal/index.d.ts +3 -0
- package/dist/declarations/src/read/jsonValues.d.ts +2 -0
- package/dist/declarations/src/stega/stegaEncode.d.ts +9 -218
- package/dist/objectSpread2-3c87fb4f.cjs.prod.js +52 -0
- package/dist/objectSpread2-69569a13.worker.esm.js +48 -0
- package/dist/objectSpread2-792eb2c2.cjs.dev.js +52 -0
- package/dist/objectSpread2-af6b2a44.browser.esm.js +48 -0
- package/dist/objectSpread2-be6bfc61.esm.js +48 -0
- package/dist/{raw-15ce77ae.browser.esm.js → raw-0561be8e.browser.esm.js} +81 -90
- package/dist/{raw-d504f4fd.cjs.prod.js → raw-a69a8d13.cjs.prod.js} +80 -92
- package/dist/{raw-534fcde0.esm.js → raw-aa7a3ac4.esm.js} +81 -90
- package/dist/{raw-67d24dd6.cjs.dev.js → raw-de032c12.cjs.dev.js} +80 -92
- package/dist/{raw-645a854a.worker.esm.js → raw-f32dca84.worker.esm.js} +81 -90
- package/dist/toConsumableArray-203e636a.cjs.prod.js +21 -0
- package/dist/toConsumableArray-257d6741.esm.js +19 -0
- package/dist/toConsumableArray-2fc46f85.browser.esm.js +19 -0
- package/dist/toConsumableArray-d7cf1601.cjs.dev.js +21 -0
- package/dist/toConsumableArray-e4f48095.worker.esm.js +19 -0
- package/internal/dist/valbuild-react-internal.browser.esm.js +405 -7
- package/internal/dist/valbuild-react-internal.cjs.dev.js +430 -24
- package/internal/dist/valbuild-react-internal.cjs.prod.js +430 -24
- package/internal/dist/valbuild-react-internal.esm.js +405 -7
- package/internal/dist/valbuild-react-internal.worker.esm.js +405 -7
- package/package.json +4 -4
- package/stega/dist/valbuild-react-stega.browser.esm.js +5 -3
- package/stega/dist/valbuild-react-stega.cjs.dev.js +11 -9
- package/stega/dist/valbuild-react-stega.cjs.prod.js +11 -9
- package/stega/dist/valbuild-react-stega.esm.js +5 -3
- package/stega/dist/valbuild-react-stega.worker.esm.js +5 -3
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { _ as _toConsumableArray
|
|
2
|
-
import { _ as _objectSpread2,
|
|
3
|
-
import React from 'react';
|
|
1
|
+
import { _ as _toConsumableArray } from '../../dist/toConsumableArray-257d6741.esm.js';
|
|
2
|
+
import { _ as _objectSpread2, a as _toPropertyKey, b as _defineProperty } from '../../dist/objectSpread2-be6bfc61.esm.js';
|
|
3
|
+
import React, { Suspense, lazy } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { r as raw, c as attrs, g as getModuleIds, a as stegaEncode } from '../../dist/raw-aa7a3ac4.esm.js';
|
|
6
|
+
import { _ as _createForOfIteratorHelper } from '../../dist/createForOfIteratorHelper-9b22d0cd.esm.js';
|
|
7
|
+
import { _ as _slicedToArray } from '../../dist/slicedToArray-70ecb9da.esm.js';
|
|
5
8
|
import { _ as _typeof } from '../../dist/typeof-a1531d8f.esm.js';
|
|
6
|
-
import { Internal, RecordSchema } from '@valbuild/core';
|
|
9
|
+
import { Internal, RecordSchema, loadComponent, componentPropsOf, getComponentRender, setComponentOfValue, componentOfValue } from '@valbuild/core';
|
|
10
|
+
export { ValPreviewBridgeCore } from '../../dist/ValPreviewBridgeCore-00015d00.esm.js';
|
|
11
|
+
import { ValComponentList, VAL_COMPONENT_ATTRIBUTE } from '../../dist/ValComponentEditorChrome-93321513.esm.js';
|
|
7
12
|
import { deepEqual } from '@valbuild/core/patch';
|
|
8
|
-
import { _ as _slicedToArray } from '../../dist/slicedToArray-70ecb9da.esm.js';
|
|
9
13
|
import { CODE_CHANGED_EVENT } from '@valbuild/shared/internal';
|
|
10
14
|
import '@vercel/stega';
|
|
11
15
|
|
|
@@ -810,7 +814,9 @@ selector, key
|
|
|
810
814
|
}
|
|
811
815
|
return {
|
|
812
816
|
path: path,
|
|
813
|
-
schema: schema["executeSerialize"]().item
|
|
817
|
+
schema: schema["executeSerialize"]().item,
|
|
818
|
+
// Where a `.component()` of the entry's objects lives: see `stegaEncode`.
|
|
819
|
+
instance: schema["item"]
|
|
814
820
|
};
|
|
815
821
|
}
|
|
816
822
|
|
|
@@ -1915,4 +1921,396 @@ function readsOfFetchVal(fetchVal) {
|
|
|
1915
1921
|
return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
|
|
1916
1922
|
}
|
|
1917
1923
|
|
|
1918
|
-
|
|
1924
|
+
function findValModule(_x, _x2) {
|
|
1925
|
+
return _findValModule.apply(this, arguments);
|
|
1926
|
+
}
|
|
1927
|
+
function _findValModule() {
|
|
1928
|
+
_findValModule = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules, sourcePath) {
|
|
1929
|
+
var _Internal$splitModule, _Internal$splitModule2, moduleFilePath, _iterator, _step, _yield$def, def, valModule, _t, _t2, _t3, _t4;
|
|
1930
|
+
return _regenerator().w(function (_context) {
|
|
1931
|
+
while (1) switch (_context.p = _context.n) {
|
|
1932
|
+
case 0:
|
|
1933
|
+
_Internal$splitModule = Internal.splitModuleFilePathAndModulePath(sourcePath), _Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 1), moduleFilePath = _Internal$splitModule2[0];
|
|
1934
|
+
_iterator = _createForOfIteratorHelper(valModules.modules);
|
|
1935
|
+
_context.p = 1;
|
|
1936
|
+
_iterator.s();
|
|
1937
|
+
case 2:
|
|
1938
|
+
if ((_step = _iterator.n()).done) {
|
|
1939
|
+
_context.n = 8;
|
|
1940
|
+
break;
|
|
1941
|
+
}
|
|
1942
|
+
def = _step.value.def;
|
|
1943
|
+
_context.n = 3;
|
|
1944
|
+
return def();
|
|
1945
|
+
case 3:
|
|
1946
|
+
_t2 = _yield$def = _context.v;
|
|
1947
|
+
_t = _t2 === null;
|
|
1948
|
+
if (_t) {
|
|
1949
|
+
_context.n = 4;
|
|
1950
|
+
break;
|
|
1951
|
+
}
|
|
1952
|
+
_t = _yield$def === void 0;
|
|
1953
|
+
case 4:
|
|
1954
|
+
if (!_t) {
|
|
1955
|
+
_context.n = 5;
|
|
1956
|
+
break;
|
|
1957
|
+
}
|
|
1958
|
+
_t3 = void 0;
|
|
1959
|
+
_context.n = 6;
|
|
1960
|
+
break;
|
|
1961
|
+
case 5:
|
|
1962
|
+
_t3 = _yield$def["default"];
|
|
1963
|
+
case 6:
|
|
1964
|
+
valModule = _t3;
|
|
1965
|
+
if (!(valModule && String(Internal.getValPath(valModule)) === moduleFilePath)) {
|
|
1966
|
+
_context.n = 7;
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1969
|
+
return _context.a(2, valModule);
|
|
1970
|
+
case 7:
|
|
1971
|
+
_context.n = 2;
|
|
1972
|
+
break;
|
|
1973
|
+
case 8:
|
|
1974
|
+
_context.n = 10;
|
|
1975
|
+
break;
|
|
1976
|
+
case 9:
|
|
1977
|
+
_context.p = 9;
|
|
1978
|
+
_t4 = _context.v;
|
|
1979
|
+
_iterator.e(_t4);
|
|
1980
|
+
case 10:
|
|
1981
|
+
_context.p = 10;
|
|
1982
|
+
_iterator.f();
|
|
1983
|
+
return _context.f(10);
|
|
1984
|
+
case 11:
|
|
1985
|
+
return _context.a(2, null);
|
|
1986
|
+
}
|
|
1987
|
+
}, _callee, null, [[1, 9, 10, 11]]);
|
|
1988
|
+
}));
|
|
1989
|
+
return _findValModule.apply(this, arguments);
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* EXPERIMENTAL: the component that renders the value at `sourcePath`, and the
|
|
1993
|
+
* props to render it with - the framework-free half of a component preview,
|
|
1994
|
+
* shared by `@valbuild/next` and `@valbuild/tanstack`.
|
|
1995
|
+
*
|
|
1996
|
+
* `moduleValue` is the module's content as the app reads it (`fetchVal`), not
|
|
1997
|
+
* its own source: a section added in the Studio is in the former and not the
|
|
1998
|
+
* latter, and only the content says which variant of a union a section is.
|
|
1999
|
+
*
|
|
2000
|
+
* With `example`, the props are the render's `example`; with `props`, those.
|
|
2001
|
+
* Neither is content, so neither carries edit tags: a click in the preview must
|
|
2002
|
+
* not lead to a field the value is not in.
|
|
2003
|
+
*/
|
|
2004
|
+
function resolveValComponentPreview(_x3) {
|
|
2005
|
+
return _resolveValComponentPreview.apply(this, arguments);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* Give every object inside `value` the component its schema links it to,
|
|
2010
|
+
* as a reader does (`stegaEncode`), for a value that lost them on the way.
|
|
2011
|
+
*
|
|
2012
|
+
* A preview's content often has: on TanStack the route's loader reads it in a
|
|
2013
|
+
* server function, and what comes back is JSON, which a component cannot
|
|
2014
|
+
* ride on. The component being previewed is found by path either way, but
|
|
2015
|
+
* one that renders a list of components of its own (`ValComponentEditor`)
|
|
2016
|
+
* would be handed items with nothing to render them with.
|
|
2017
|
+
*
|
|
2018
|
+
* Looked up from the root by each object's path - through whichever variant
|
|
2019
|
+
* of a union the value there takes - which is the reader's own way of
|
|
2020
|
+
* finding one. A path that cannot be resolved has no component, as before.
|
|
2021
|
+
*/
|
|
2022
|
+
function _resolveValComponentPreview() {
|
|
2023
|
+
_resolveValComponentPreview = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
2024
|
+
var valModule, sourcePath, moduleValue, example, props, _Internal$splitModule3, _Internal$splitModule4, moduleFilePath, modulePath, moduleSchema, schema, value, resolved, render, source, componentProps, _t5, _t6, _t7;
|
|
2025
|
+
return _regenerator().w(function (_context2) {
|
|
2026
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
2027
|
+
case 0:
|
|
2028
|
+
valModule = _ref.valModule, sourcePath = _ref.sourcePath, moduleValue = _ref.moduleValue, example = _ref.example, props = _ref.props;
|
|
2029
|
+
_Internal$splitModule3 = Internal.splitModuleFilePathAndModulePath(sourcePath), _Internal$splitModule4 = _slicedToArray(_Internal$splitModule3, 2), moduleFilePath = _Internal$splitModule4[0], modulePath = _Internal$splitModule4[1];
|
|
2030
|
+
moduleSchema = Internal.getSchema(valModule);
|
|
2031
|
+
if (moduleSchema) {
|
|
2032
|
+
_context2.n = 1;
|
|
2033
|
+
break;
|
|
2034
|
+
}
|
|
2035
|
+
return _context2.a(2, {
|
|
2036
|
+
status: "error",
|
|
2037
|
+
message: "'".concat(moduleFilePath, "' has no schema.")
|
|
2038
|
+
});
|
|
2039
|
+
case 1:
|
|
2040
|
+
schema = moduleSchema;
|
|
2041
|
+
value = moduleValue;
|
|
2042
|
+
if (!modulePath) {
|
|
2043
|
+
_context2.n = 4;
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
_context2.p = 2;
|
|
2047
|
+
resolved = Internal.resolvePath(modulePath,
|
|
2048
|
+
// What the app read is the module's source with media resolved,
|
|
2049
|
+
// which is what this walks.
|
|
2050
|
+
moduleValue, moduleSchema);
|
|
2051
|
+
schema = resolved.schema;
|
|
2052
|
+
value = resolved.source;
|
|
2053
|
+
_context2.n = 4;
|
|
2054
|
+
break;
|
|
2055
|
+
case 3:
|
|
2056
|
+
_context2.p = 3;
|
|
2057
|
+
_t5 = _context2.v;
|
|
2058
|
+
return _context2.a(2, {
|
|
2059
|
+
status: "error",
|
|
2060
|
+
message: "".concat(sourcePath, ": ").concat(_t5 instanceof Error ? _t5.message : String(_t5))
|
|
2061
|
+
});
|
|
2062
|
+
case 4:
|
|
2063
|
+
render = getComponentRender(schema, value);
|
|
2064
|
+
if (render) {
|
|
2065
|
+
_context2.n = 5;
|
|
2066
|
+
break;
|
|
2067
|
+
}
|
|
2068
|
+
return _context2.a(2, {
|
|
2069
|
+
status: "error",
|
|
2070
|
+
message: "".concat(sourcePath, " has no component: give its schema .component(() => import(...)) to preview it.")
|
|
2071
|
+
});
|
|
2072
|
+
case 5:
|
|
2073
|
+
if (!(props !== undefined || example)) {
|
|
2074
|
+
_context2.n = 7;
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
source = props !== undefined ? props : render.example;
|
|
2078
|
+
if (!(source === undefined)) {
|
|
2079
|
+
_context2.n = 6;
|
|
2080
|
+
break;
|
|
2081
|
+
}
|
|
2082
|
+
return _context2.a(2, {
|
|
2083
|
+
status: "error",
|
|
2084
|
+
message: "".concat(sourcePath, " has no example.")
|
|
2085
|
+
});
|
|
2086
|
+
case 6:
|
|
2087
|
+
value = stegaEncode(source, {
|
|
2088
|
+
disabled: true,
|
|
2089
|
+
root: {
|
|
2090
|
+
path: sourcePath,
|
|
2091
|
+
schema: schema["executeSerialize"](),
|
|
2092
|
+
// So a list of components inside the example has its components
|
|
2093
|
+
instance: schema
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
2096
|
+
_context2.n = 8;
|
|
2097
|
+
break;
|
|
2098
|
+
case 7:
|
|
2099
|
+
linkComponents(value, schema);
|
|
2100
|
+
case 8:
|
|
2101
|
+
// What the site hands the component (`ValComponentEditor`): the value, or
|
|
2102
|
+
// what the schema's `props` function makes of it. One function for both, so
|
|
2103
|
+
// the preview cannot show a component the site renders differently.
|
|
2104
|
+
componentProps = componentPropsOf(render, value);
|
|
2105
|
+
if (!(_typeof(componentProps) !== "object" || componentProps === null)) {
|
|
2106
|
+
_context2.n = 9;
|
|
2107
|
+
break;
|
|
2108
|
+
}
|
|
2109
|
+
return _context2.a(2, {
|
|
2110
|
+
status: "error",
|
|
2111
|
+
message: "Expected an object to spread as props, got ".concat(componentProps === null ? "null" : _typeof(componentProps), ".")
|
|
2112
|
+
});
|
|
2113
|
+
case 9:
|
|
2114
|
+
_context2.n = 10;
|
|
2115
|
+
return loadComponent(render);
|
|
2116
|
+
case 10:
|
|
2117
|
+
_t6 = _context2.v;
|
|
2118
|
+
_t7 = componentProps;
|
|
2119
|
+
return _context2.a(2, {
|
|
2120
|
+
status: "ok",
|
|
2121
|
+
Component: _t6,
|
|
2122
|
+
props: _t7
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
}, _callee2, null, [[2, 3]]);
|
|
2126
|
+
}));
|
|
2127
|
+
return _resolveValComponentPreview.apply(this, arguments);
|
|
2128
|
+
}
|
|
2129
|
+
function linkComponents(value, schema) {
|
|
2130
|
+
var _visit = function visit(node, path) {
|
|
2131
|
+
if (Array.isArray(node)) {
|
|
2132
|
+
node.forEach(function (child, index) {
|
|
2133
|
+
return _visit(child, [].concat(_toConsumableArray(path), [String(index)]));
|
|
2134
|
+
});
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
if (_typeof(node) !== "object" || node === null) {
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
// The root is the previewed component itself, which the caller renders
|
|
2141
|
+
if (path.length > 0) {
|
|
2142
|
+
try {
|
|
2143
|
+
var at = Internal.resolvePath(Internal.patchPathToModulePath(path),
|
|
2144
|
+
// What the app read is the source with media resolved, which is
|
|
2145
|
+
// what `resolvePath` walks: see `resolveValComponentPreview`.
|
|
2146
|
+
value, schema);
|
|
2147
|
+
var render = getComponentRender(at.schema, at.source);
|
|
2148
|
+
if (render) {
|
|
2149
|
+
setComponentOfValue(node, render);
|
|
2150
|
+
}
|
|
2151
|
+
} catch (_unused) {
|
|
2152
|
+
// Not a path the schema knows: nothing to link
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
for (var _i = 0, _Object$entries = Object.entries(node); _i < _Object$entries.length; _i++) {
|
|
2156
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2157
|
+
key = _Object$entries$_i[0],
|
|
2158
|
+
child = _Object$entries$_i[1];
|
|
2159
|
+
_visit(child, [].concat(_toConsumableArray(path), [key]));
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
_visit(value, []);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
/** A message in place of the component, for when there is none to render. */
|
|
2166
|
+
function ValPreviewMessage(_ref2) {
|
|
2167
|
+
var children = _ref2.children;
|
|
2168
|
+
return /*#__PURE__*/jsx("div", {
|
|
2169
|
+
style: {
|
|
2170
|
+
fontFamily: "ui-monospace, monospace",
|
|
2171
|
+
fontSize: "13px",
|
|
2172
|
+
padding: "1rem"
|
|
2173
|
+
},
|
|
2174
|
+
children: children
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* EXPERIMENTAL: renders content with the components its schema links it to.
|
|
2180
|
+
*
|
|
2181
|
+
* Each object is rendered by the component its own schema names
|
|
2182
|
+
* (`.component(() => import("./Hero"))`), with the props that schema's `props`
|
|
2183
|
+
* function makes of it - so there is no map from a `type` to a component to
|
|
2184
|
+
* keep, and none to forget a case in. A list renders every item in order; a
|
|
2185
|
+
* single object renders the one.
|
|
2186
|
+
*
|
|
2187
|
+
* In the Studio, on the page itself, a list can be arranged: a section is
|
|
2188
|
+
* dragged to another place, one is added between two others, one is taken
|
|
2189
|
+
* away. Outside the Studio none of that exists, and this is the components
|
|
2190
|
+
* and an element around each.
|
|
2191
|
+
*
|
|
2192
|
+
* It is optional. The same content can be read and rendered by hand, with a
|
|
2193
|
+
* `map` and a `switch`, and a page is free to use this for one list and not
|
|
2194
|
+
* for the rest of what it shows.
|
|
2195
|
+
*
|
|
2196
|
+
* The component is found on the VALUE, which the reader attached it to. So
|
|
2197
|
+
* render the value where it was read: one passed from a server component to
|
|
2198
|
+
* a client component arrives without it, like the module behind a `s.view()`.
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* const page = useValRoute(pageVal, {});
|
|
2202
|
+
* return <ValComponentEditor value={page.sections} />;
|
|
2203
|
+
*/
|
|
2204
|
+
function ValComponentEditor(_ref) {
|
|
2205
|
+
var value = _ref.value,
|
|
2206
|
+
className = _ref.className,
|
|
2207
|
+
itemClassName = _ref.itemClassName,
|
|
2208
|
+
_ref$fallback = _ref.fallback,
|
|
2209
|
+
fallback = _ref$fallback === void 0 ? null : _ref$fallback;
|
|
2210
|
+
if (value === null || value === undefined) {
|
|
2211
|
+
return null;
|
|
2212
|
+
}
|
|
2213
|
+
if (isList(value)) {
|
|
2214
|
+
return /*#__PURE__*/jsx(ValComponentList, {
|
|
2215
|
+
path: Internal.valPathOf(value),
|
|
2216
|
+
className: className,
|
|
2217
|
+
count: value.length,
|
|
2218
|
+
children: value.map(function (item, index) {
|
|
2219
|
+
return /*#__PURE__*/jsx(ValComponentItem
|
|
2220
|
+
// A list item has no identity but its place
|
|
2221
|
+
, {
|
|
2222
|
+
value: item,
|
|
2223
|
+
className: itemClassName,
|
|
2224
|
+
fallback: fallback
|
|
2225
|
+
}, index);
|
|
2226
|
+
})
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
return /*#__PURE__*/jsx(ValComponentItem, {
|
|
2230
|
+
value: value,
|
|
2231
|
+
className: itemClassName,
|
|
2232
|
+
fallback: fallback
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
function isList(value) {
|
|
2236
|
+
return Array.isArray(value);
|
|
2237
|
+
}
|
|
2238
|
+
function ValComponentItem(_ref2) {
|
|
2239
|
+
var value = _ref2.value,
|
|
2240
|
+
className = _ref2.className,
|
|
2241
|
+
fallback = _ref2.fallback;
|
|
2242
|
+
var path = Internal.valPathOf(value);
|
|
2243
|
+
var render = componentOfValue(value);
|
|
2244
|
+
// The element is there whether or not there is something in it: it is the
|
|
2245
|
+
// item's place in the list, which the editing on the page counts by.
|
|
2246
|
+
var attributes = _defineProperty(_defineProperty({
|
|
2247
|
+
className: className
|
|
2248
|
+
}, VAL_COMPONENT_ATTRIBUTE, ""), "data-val-path", path);
|
|
2249
|
+
if (render === null) {
|
|
2250
|
+
warnNoComponent(value, path);
|
|
2251
|
+
return /*#__PURE__*/jsx("div", _objectSpread2({}, attributes));
|
|
2252
|
+
}
|
|
2253
|
+
var props = componentPropsOf(render, value);
|
|
2254
|
+
if (_typeof(props) !== "object" || props === null) {
|
|
2255
|
+
Internal.log.error("ValComponentEditor: the props of the component".concat(path ? " at ".concat(path) : "", " must be an object, got ").concat(props === null ? "null" : _typeof(props), ". Check what its `props` function returns."));
|
|
2256
|
+
return /*#__PURE__*/jsx("div", _objectSpread2({}, attributes));
|
|
2257
|
+
}
|
|
2258
|
+
var Component = lazyComponentOf(render);
|
|
2259
|
+
return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({}, attributes), {}, {
|
|
2260
|
+
children: /*#__PURE__*/jsx(Suspense, {
|
|
2261
|
+
fallback: fallback,
|
|
2262
|
+
children: /*#__PURE__*/jsx(Component, _objectSpread2({}, props))
|
|
2263
|
+
})
|
|
2264
|
+
}));
|
|
2265
|
+
}
|
|
2266
|
+
var lazyComponents = new WeakMap();
|
|
2267
|
+
|
|
2268
|
+
/**
|
|
2269
|
+
* One lazy component per thunk, kept: a new `lazy()` on every render is a new
|
|
2270
|
+
* component type every time, which React unmounts and mounts again - a
|
|
2271
|
+
* section that loses its state, and suspends, at every keystroke.
|
|
2272
|
+
*/
|
|
2273
|
+
function lazyComponentOf(render) {
|
|
2274
|
+
var existing = lazyComponents.get(render.component);
|
|
2275
|
+
if (existing) {
|
|
2276
|
+
return existing;
|
|
2277
|
+
}
|
|
2278
|
+
var created = /*#__PURE__*/lazy(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
2279
|
+
var _t;
|
|
2280
|
+
return _regenerator().w(function (_context) {
|
|
2281
|
+
while (1) switch (_context.n) {
|
|
2282
|
+
case 0:
|
|
2283
|
+
_context.n = 1;
|
|
2284
|
+
return loadComponent(render);
|
|
2285
|
+
case 1:
|
|
2286
|
+
_t = _context.v;
|
|
2287
|
+
return _context.a(2, {
|
|
2288
|
+
"default": _t
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
}, _callee);
|
|
2292
|
+
})));
|
|
2293
|
+
lazyComponents.set(render.component, created);
|
|
2294
|
+
return created;
|
|
2295
|
+
}
|
|
2296
|
+
var warned = new Set();
|
|
2297
|
+
|
|
2298
|
+
/**
|
|
2299
|
+
* Said once per place, and only where there is someone to read it: in
|
|
2300
|
+
* production the types have already refused this, so what is left is a value
|
|
2301
|
+
* that lost its component on the way here.
|
|
2302
|
+
*/
|
|
2303
|
+
function warnNoComponent(value, path) {
|
|
2304
|
+
if (value === null || value === undefined) {
|
|
2305
|
+
// An item nobody has filled in yet: an editor just added it.
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
var key = path !== null && path !== void 0 ? path : "";
|
|
2309
|
+
if (warned.has(key)) {
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
warned.add(key);
|
|
2313
|
+
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.");
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
export { ValComponentEditor, ValExternalStore, ValPreviewMessage, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, codeChangedReporter, createDraftStore, dispatchCodeChanged, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, findValModule, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValComponentPreview, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal, windowCodeChangedReporter };
|