@valbuild/tanstack 0.146.4 → 0.147.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.
- package/CHANGELOG.md +48 -0
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +6 -6
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +6 -6
- package/client/dist/valbuild-tanstack-client.esm.js +4 -4
- package/demo/dist/valbuild-tanstack-demo.cjs.d.ts +2 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.dev.js +105 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.js +7 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.prod.js +105 -0
- package/demo/dist/valbuild-tanstack-demo.esm.js +101 -0
- package/demo/package.json +4 -0
- package/dist/{ValOverlayContext-3f080cce.cjs.dev.js → ValOverlayContext-510328ec.cjs.dev.js} +17 -17
- package/dist/{ValOverlayContext-59a0b19f.esm.js → ValOverlayContext-6278320b.esm.js} +1 -1
- package/dist/{ValOverlayContext-3e2c48a6.cjs.prod.js → ValOverlayContext-d3acd157.cjs.prod.js} +17 -17
- package/dist/{version-4da65f4f.esm.js → asyncToGenerator-500f022f.esm.js} +1 -149
- package/dist/{version-2cbea560.cjs.prod.js → asyncToGenerator-8e5c36c8.cjs.prod.js} +0 -151
- package/dist/{version-1f65da50.cjs.dev.js → asyncToGenerator-c3823d62.cjs.dev.js} +0 -151
- package/dist/declarations/src/ValApp.d.ts +15 -1
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/demo/index.d.ts +7 -0
- package/dist/declarations/src/demo/initValDemoServer.d.ts +27 -0
- package/dist/demoServiceWorker-382e1b63.cjs.dev.js +60 -0
- package/dist/demoServiceWorker-56fd96cf.esm.js +55 -0
- package/dist/demoServiceWorker-994710f7.cjs.prod.js +60 -0
- package/dist/{routeFromVal-385ee69c.cjs.dev.js → routeFromVal-0ea4586f.cjs.dev.js} +17 -24
- package/dist/{routeFromVal-ffa948ef.cjs.prod.js → routeFromVal-97a52f43.cjs.prod.js} +17 -24
- package/dist/{routeFromVal-ae54a17e.esm.js → routeFromVal-9f1f8725.esm.js} +7 -13
- package/dist/{createForOfIteratorHelper-93a62170.esm.js → typeof-66e2d869.esm.js} +11 -1
- package/dist/{createForOfIteratorHelper-9afd7d2d.cjs.prod.js → typeof-8998e126.cjs.prod.js} +11 -0
- package/dist/{createForOfIteratorHelper-4497beef.cjs.dev.js → typeof-dd0246a1.cjs.dev.js} +11 -0
- package/dist/valbuild-tanstack.cjs.dev.js +371 -42
- package/dist/valbuild-tanstack.cjs.prod.js +371 -42
- package/dist/valbuild-tanstack.esm.js +337 -8
- package/dist/version-1ae7092b.esm.js +174 -0
- package/dist/version-83d7f4b7.cjs.prod.js +179 -0
- package/dist/version-a820698f.cjs.dev.js +179 -0
- package/package.json +16 -10
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +60 -75
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +60 -75
- package/server/dist/valbuild-tanstack-server.esm.js +4 -19
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
|
|
6
|
+
var _typeof = require('./typeof-dd0246a1.cjs.dev.js');
|
|
7
7
|
var core = require('@valbuild/core');
|
|
8
8
|
var stega = require('@valbuild/react/stega');
|
|
9
|
+
var version = require('./version-a820698f.cjs.dev.js');
|
|
9
10
|
var internal = require('@valbuild/react/internal');
|
|
10
11
|
var ui = require('@valbuild/ui');
|
|
11
12
|
var reactRouter = require('@tanstack/react-router');
|
|
12
13
|
var React = require('react');
|
|
13
|
-
var ValOverlayContext = require('./ValOverlayContext-
|
|
14
|
+
var ValOverlayContext = require('./ValOverlayContext-510328ec.cjs.dev.js');
|
|
14
15
|
var client = require('@valbuild/shared/client');
|
|
15
16
|
var jsxRuntime = require('react/jsx-runtime');
|
|
17
|
+
var demoServiceWorker = require('./demoServiceWorker-382e1b63.cjs.dev.js');
|
|
16
18
|
require('@valbuild/core/patch');
|
|
17
19
|
|
|
18
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -65,8 +67,8 @@ function isValEnabled() {
|
|
|
65
67
|
return _isValEnabled.apply(this, arguments);
|
|
66
68
|
}
|
|
67
69
|
function _isValEnabled() {
|
|
68
|
-
_isValEnabled =
|
|
69
|
-
return
|
|
70
|
+
_isValEnabled = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
|
|
71
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
70
72
|
while (1) switch (_context.n) {
|
|
71
73
|
case 0:
|
|
72
74
|
return _context.a(2, version.readValEnableCookie());
|
|
@@ -81,14 +83,14 @@ var initVal = function initVal(config) {
|
|
|
81
83
|
c = _createValSystem.c,
|
|
82
84
|
val = _createValSystem.val,
|
|
83
85
|
systemConfig = _createValSystem.config;
|
|
84
|
-
var currentConfig =
|
|
86
|
+
var currentConfig = _typeof._objectSpread2(_typeof._objectSpread2({}, systemConfig), config);
|
|
85
87
|
return {
|
|
86
88
|
s: s,
|
|
87
89
|
c: c,
|
|
88
90
|
isValEnabled: isValEnabled,
|
|
89
91
|
tanstackRouter: tanstackRouter,
|
|
90
92
|
externalPageRouter: externalPageRouter,
|
|
91
|
-
val:
|
|
93
|
+
val: _typeof._objectSpread2(_typeof._objectSpread2({}, val), {}, {
|
|
92
94
|
attrs: stega.attrs,
|
|
93
95
|
unstable_decodeValPathsOfString: decodeValPathsOfString,
|
|
94
96
|
raw: stega.raw,
|
|
@@ -161,7 +163,7 @@ function initSessionTheme(config) {
|
|
|
161
163
|
var valPrefixedClass = "val-prefix-" + core.Internal.getSHA256Hash(new TextEncoder().encode(ui.VERSION || "")).slice(0, 8) + "-";
|
|
162
164
|
var prefixStyles = function prefixStyles(styles) {
|
|
163
165
|
return Object.entries(styles).map(function (_ref) {
|
|
164
|
-
var _ref2 =
|
|
166
|
+
var _ref2 = _typeof._slicedToArray(_ref, 2),
|
|
165
167
|
key = _ref2[0],
|
|
166
168
|
value = _ref2[1];
|
|
167
169
|
return ".".concat(valPrefixedClass).concat(key.replace(/\//g, "\\/"), " { ").concat(value, " }");
|
|
@@ -183,7 +185,7 @@ var cn = function cn(className) {
|
|
|
183
185
|
* too.
|
|
184
186
|
*/
|
|
185
187
|
function hasValEnableCookie(cookieString) {
|
|
186
|
-
var _iterator =
|
|
188
|
+
var _iterator = _typeof._createForOfIteratorHelper(cookieString.split(";")),
|
|
187
189
|
_step;
|
|
188
190
|
try {
|
|
189
191
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -261,7 +263,7 @@ function ValCanvasBridge(_ref) {
|
|
|
261
263
|
var draftMode = _ref.draftMode,
|
|
262
264
|
isRefreshing = _ref.isRefreshing;
|
|
263
265
|
var _React$useState = React__default["default"].useState(false),
|
|
264
|
-
_React$useState2 =
|
|
266
|
+
_React$useState2 = _typeof._slicedToArray(_React$useState, 2),
|
|
265
267
|
picking = _React$useState2[0],
|
|
266
268
|
setPicking = _React$useState2[1];
|
|
267
269
|
/**
|
|
@@ -274,11 +276,11 @@ function ValCanvasBridge(_ref) {
|
|
|
274
276
|
* its content.
|
|
275
277
|
*/
|
|
276
278
|
var _React$useState3 = React__default["default"].useState(DEFAULT_SELECTION),
|
|
277
|
-
_React$useState4 =
|
|
279
|
+
_React$useState4 = _typeof._slicedToArray(_React$useState3, 2),
|
|
278
280
|
selectionColors = _React$useState4[0],
|
|
279
281
|
setSelectionColors = _React$useState4[1];
|
|
280
282
|
var _React$useState5 = React__default["default"].useState(null),
|
|
281
|
-
_React$useState6 =
|
|
283
|
+
_React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
|
|
282
284
|
highlighted = _React$useState6[0],
|
|
283
285
|
setHighlighted = _React$useState6[1];
|
|
284
286
|
// Kept in a ref as well, because the capture-phase click listener below is
|
|
@@ -966,9 +968,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
966
968
|
var clientRef = React__default["default"].useRef(null);
|
|
967
969
|
var configRef = React__default["default"].useRef(props.config);
|
|
968
970
|
configRef.current = props.config;
|
|
969
|
-
var getClient = React__default["default"].useCallback(/*#__PURE__*/
|
|
971
|
+
var getClient = React__default["default"].useCallback(/*#__PURE__*/asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
|
|
970
972
|
var _yield$import, createValClient;
|
|
971
|
-
return
|
|
973
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
972
974
|
while (1) switch (_context.n) {
|
|
973
975
|
case 0:
|
|
974
976
|
if (clientRef.current) {
|
|
@@ -980,7 +982,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
980
982
|
case 1:
|
|
981
983
|
_yield$import = _context.v;
|
|
982
984
|
createValClient = _yield$import.createValClient;
|
|
983
|
-
clientRef.current = createValClient(route,
|
|
985
|
+
clientRef.current = createValClient(route, _typeof._objectSpread2(_typeof._objectSpread2({}, configRef.current), {}, {
|
|
984
986
|
contentHostUrl: core.DEFAULT_CONTENT_HOST
|
|
985
987
|
}));
|
|
986
988
|
case 2:
|
|
@@ -1020,7 +1022,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1020
1022
|
var store = new ValOverlayContext.ValExternalStore();
|
|
1021
1023
|
if (hasDraft) {
|
|
1022
1024
|
for (var _i = 0, _Object$entries = Object.entries(initialDraft.sources); _i < _Object$entries.length; _i++) {
|
|
1023
|
-
var _Object$entries$_i =
|
|
1025
|
+
var _Object$entries$_i = _typeof._slicedToArray(_Object$entries[_i], 2),
|
|
1024
1026
|
path = _Object$entries$_i[0],
|
|
1025
1027
|
source = _Object$entries$_i[1];
|
|
1026
1028
|
store.update(path, source);
|
|
@@ -1040,7 +1042,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1040
1042
|
// and then swaps to draft data as a normal update — no Suspense fallback
|
|
1041
1043
|
// flash and no hydration mismatch.
|
|
1042
1044
|
var _React$useState = React__default["default"].useState(false),
|
|
1043
|
-
_React$useState2 =
|
|
1045
|
+
_React$useState2 = _typeof._slicedToArray(_React$useState, 2),
|
|
1044
1046
|
suspendActive = _React$useState2[0],
|
|
1045
1047
|
setSuspendActive = _React$useState2[1];
|
|
1046
1048
|
/**
|
|
@@ -1054,11 +1056,11 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1054
1056
|
// A server-read draft is everything there is: a module missing from it has
|
|
1055
1057
|
// no changes, so there is nothing more to wait for.
|
|
1056
1058
|
var _React$useState3 = React__default["default"].useState(hasDraft),
|
|
1057
|
-
_React$useState4 =
|
|
1059
|
+
_React$useState4 = _typeof._slicedToArray(_React$useState3, 2),
|
|
1058
1060
|
draftSourcesSynced = _React$useState4[0],
|
|
1059
1061
|
setDraftSourcesSynced = _React$useState4[1];
|
|
1060
1062
|
var _React$useState5 = React__default["default"].useState(),
|
|
1061
|
-
_React$useState6 =
|
|
1063
|
+
_React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
|
|
1062
1064
|
mountOverlay = _React$useState6[0],
|
|
1063
1065
|
setMountOverlay = _React$useState6[1];
|
|
1064
1066
|
/**
|
|
@@ -1075,13 +1077,13 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1075
1077
|
* the document was loaded, and it cannot change without a navigation.
|
|
1076
1078
|
*/
|
|
1077
1079
|
var _React$useState7 = React__default["default"].useState(false),
|
|
1078
|
-
_React$useState8 =
|
|
1080
|
+
_React$useState8 = _typeof._slicedToArray(_React$useState7, 2),
|
|
1079
1081
|
isCanvas = _React$useState8[0],
|
|
1080
1082
|
setIsCanvas = _React$useState8[1];
|
|
1081
1083
|
// Known on the server when it read a draft: `fetchValDraft` only reads one
|
|
1082
1084
|
// in draft mode. Otherwise unknown until `/draft/stat` answers.
|
|
1083
1085
|
var _React$useState9 = React__default["default"].useState(hasDraft ? true : null),
|
|
1084
|
-
_React$useState0 =
|
|
1086
|
+
_React$useState0 = _typeof._slicedToArray(_React$useState9, 2),
|
|
1085
1087
|
draftMode = _React$useState0[0],
|
|
1086
1088
|
setDraftMode = _React$useState0[1];
|
|
1087
1089
|
/**
|
|
@@ -1119,12 +1121,12 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1119
1121
|
}
|
|
1120
1122
|
}, [draftMode]);
|
|
1121
1123
|
var _React$useState1 = React__default["default"].useState(false),
|
|
1122
|
-
_React$useState10 =
|
|
1124
|
+
_React$useState10 = _typeof._slicedToArray(_React$useState1, 2),
|
|
1123
1125
|
spaReady = _React$useState10[0],
|
|
1124
1126
|
setSpaReady = _React$useState10[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
|
|
1125
1127
|
var router = reactRouter.useRouter();
|
|
1126
1128
|
var _React$useTransition = React__default["default"].useTransition(),
|
|
1127
|
-
_React$useTransition2 =
|
|
1129
|
+
_React$useTransition2 = _typeof._slicedToArray(_React$useTransition, 2),
|
|
1128
1130
|
isRefreshing = _React$useTransition2[0],
|
|
1129
1131
|
startTransition = _React$useTransition2[1];
|
|
1130
1132
|
/**
|
|
@@ -1138,7 +1140,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1138
1140
|
var isRefreshingRef = React__default["default"].useRef(false);
|
|
1139
1141
|
var rerenderCounterRef = React__default["default"].useRef(0);
|
|
1140
1142
|
var _React$useState11 = React__default["default"].useState(null),
|
|
1141
|
-
_React$useState12 =
|
|
1143
|
+
_React$useState12 = _typeof._slicedToArray(_React$useState11, 2),
|
|
1142
1144
|
iframeSrc = _React$useState12[0],
|
|
1143
1145
|
setIframeSrc = _React$useState12[1];
|
|
1144
1146
|
var pathname = reactRouter.useRouterState({
|
|
@@ -1162,6 +1164,16 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1162
1164
|
setMountOverlay(false);
|
|
1163
1165
|
return;
|
|
1164
1166
|
}
|
|
1167
|
+
if (props.demo) {
|
|
1168
|
+
// Only the canvas, and always as the draft: see `demo`.
|
|
1169
|
+
var canvas = client.isValCanvasFrame(location.search, readParentPathname());
|
|
1170
|
+
setIsCanvas(canvas);
|
|
1171
|
+
setMountOverlay(canvas);
|
|
1172
|
+
if (canvas) {
|
|
1173
|
+
setDraftMode(true);
|
|
1174
|
+
}
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1165
1177
|
setIsCanvas(client.isValCanvasFrame(location.search, readParentPathname()));
|
|
1166
1178
|
setMountOverlay(hasValEnableCookie(document.cookie));
|
|
1167
1179
|
}, []);
|
|
@@ -1209,7 +1221,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1209
1221
|
* there are any.
|
|
1210
1222
|
*/
|
|
1211
1223
|
React__default["default"].useEffect(function () {
|
|
1212
|
-
|
|
1224
|
+
// A demo's loaders read a server that never sees the tab's edits, so
|
|
1225
|
+
// re-running them would only fetch the published content again.
|
|
1226
|
+
if (!mountOverlay || props.disableRefresh || props.demo) {
|
|
1213
1227
|
return;
|
|
1214
1228
|
}
|
|
1215
1229
|
var timer = null;
|
|
@@ -1299,7 +1313,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1299
1313
|
clearInterval(safety);
|
|
1300
1314
|
if (timer !== null) clearTimeout(timer);
|
|
1301
1315
|
};
|
|
1302
|
-
}, [mountOverlay, props.disableRefresh]);
|
|
1316
|
+
}, [mountOverlay, props.disableRefresh, props.demo]);
|
|
1303
1317
|
React__default["default"].useEffect(function () {
|
|
1304
1318
|
if (!mountOverlay) {
|
|
1305
1319
|
return;
|
|
@@ -1349,7 +1363,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1349
1363
|
|
|
1350
1364
|
var timeout;
|
|
1351
1365
|
function pollCurrentDraftMode() {
|
|
1352
|
-
|
|
1366
|
+
// A demo has no server to ask: draft mode is on in its canvas, and
|
|
1367
|
+
// nothing is mounted anywhere else.
|
|
1368
|
+
if (!mountOverlay || props.demo) {
|
|
1353
1369
|
return;
|
|
1354
1370
|
}
|
|
1355
1371
|
window.dispatchEvent(new CustomEvent("val-overlay-spa", {
|
|
@@ -1426,7 +1442,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1426
1442
|
return function () {
|
|
1427
1443
|
clearTimeout(timeout);
|
|
1428
1444
|
};
|
|
1429
|
-
}, [mountOverlay, iframeSrc]);
|
|
1445
|
+
}, [mountOverlay, iframeSrc, props.demo]);
|
|
1430
1446
|
React__default["default"].useEffect(function () {
|
|
1431
1447
|
if (!mountOverlay) {
|
|
1432
1448
|
return;
|
|
@@ -1518,7 +1534,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1518
1534
|
}
|
|
1519
1535
|
});
|
|
1520
1536
|
var _React$useState13 = React__default["default"].useState(null),
|
|
1521
|
-
_React$useState14 =
|
|
1537
|
+
_React$useState14 = _typeof._slicedToArray(_React$useState13, 2),
|
|
1522
1538
|
dropZone = _React$useState14[0],
|
|
1523
1539
|
setDropZone = _React$useState14[1];
|
|
1524
1540
|
React__default["default"].useEffect(function () {
|
|
@@ -1534,7 +1550,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1534
1550
|
return initSessionTheme(props.config);
|
|
1535
1551
|
}, [props.config]);
|
|
1536
1552
|
var _React$useState15 = React__default["default"].useState(false),
|
|
1537
|
-
_React$useState16 =
|
|
1553
|
+
_React$useState16 = _typeof._slicedToArray(_React$useState15, 2),
|
|
1538
1554
|
spaLoaded = _React$useState16[0],
|
|
1539
1555
|
setSpaLoaded = _React$useState16[1];
|
|
1540
1556
|
React__default["default"].useEffect(function () {
|
|
@@ -1554,7 +1570,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1554
1570
|
}
|
|
1555
1571
|
return [floatLightBg, "black"];
|
|
1556
1572
|
}, [initTheme]),
|
|
1557
|
-
_React$useMemo2 =
|
|
1573
|
+
_React$useMemo2 = _typeof._slicedToArray(_React$useMemo, 2),
|
|
1558
1574
|
backgroundColor = _React$useMemo2[0],
|
|
1559
1575
|
textColor = _React$useMemo2[1];
|
|
1560
1576
|
var commonStyles = React__default["default"].useMemo(function () {
|
|
@@ -1847,7 +1863,7 @@ function ValImage(props) {
|
|
|
1847
1863
|
var valPaths = valPathsOfUrl ? valPathsOfUrl : [];
|
|
1848
1864
|
var maybeValPathOfAlt = alt ? decodeValPathsOfString(alt) : undefined;
|
|
1849
1865
|
if (maybeValPathOfAlt) {
|
|
1850
|
-
var _iterator =
|
|
1866
|
+
var _iterator = _typeof._createForOfIteratorHelper(maybeValPathOfAlt),
|
|
1851
1867
|
_step;
|
|
1852
1868
|
try {
|
|
1853
1869
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -1861,14 +1877,14 @@ function ValImage(props) {
|
|
|
1861
1877
|
}
|
|
1862
1878
|
}
|
|
1863
1879
|
var hotspot = src === null || src === void 0 ? void 0 : src.hotspot;
|
|
1864
|
-
var imageStyle = hotspot && !disableHotspot ?
|
|
1880
|
+
var imageStyle = hotspot && !disableHotspot ? _typeof._objectSpread2(_typeof._objectSpread2({}, style), {}, {
|
|
1865
1881
|
objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
|
|
1866
1882
|
}) : style;
|
|
1867
1883
|
// The authored dimensions are only used when the caller has not said
|
|
1868
1884
|
// otherwise: an explicit width/height is the caller sizing the element, and
|
|
1869
1885
|
// overriding it with the file's own size would fight them.
|
|
1870
1886
|
var preferMetadataDims = ((src === null || src === void 0 ? void 0 : src.width) !== undefined || (src === null || src === void 0 ? void 0 : src.height) !== undefined) && !width && !height;
|
|
1871
|
-
return /*#__PURE__*/jsxRuntime.jsx("img",
|
|
1887
|
+
return /*#__PURE__*/jsxRuntime.jsx("img", _typeof._objectSpread2(_typeof._objectSpread2({}, rest), {}, {
|
|
1872
1888
|
src: valPathsOfUrl && valPathsOfUrl.length > 0 ? stega.raw(src === null || src === void 0 ? void 0 : src.url) : src === null || src === void 0 ? void 0 : src.url,
|
|
1873
1889
|
"data-val-path": valPaths.join(","),
|
|
1874
1890
|
"data-val-attr-alt": maybeValPathOfAlt,
|
|
@@ -1990,13 +2006,13 @@ function ValVideo(props) {
|
|
|
1990
2006
|
};
|
|
1991
2007
|
}, [startTime, endTime]);
|
|
1992
2008
|
var hotspot = src === null || src === void 0 ? void 0 : src.hotspot;
|
|
1993
|
-
var videoStyle = hotspot && !disableHotspot ?
|
|
2009
|
+
var videoStyle = hotspot && !disableHotspot ? _typeof._objectSpread2(_typeof._objectSpread2({}, style), {}, {
|
|
1994
2010
|
objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
|
|
1995
2011
|
}) : style;
|
|
1996
2012
|
// As for `ValImage`: the file's own size reserves the space, unless the
|
|
1997
2013
|
// caller is sizing the element.
|
|
1998
2014
|
var preferMetadataDims = ((src === null || src === void 0 ? void 0 : src.width) !== undefined || (src === null || src === void 0 ? void 0 : src.height) !== undefined) && !width && !height;
|
|
1999
|
-
return /*#__PURE__*/jsxRuntime.jsx("video",
|
|
2015
|
+
return /*#__PURE__*/jsxRuntime.jsx("video", _typeof._objectSpread2(_typeof._objectSpread2({
|
|
2000
2016
|
playsInline: true,
|
|
2001
2017
|
preload: "metadata"
|
|
2002
2018
|
}, rest), {}, {
|
|
@@ -2021,6 +2037,154 @@ function ValVideo(props) {
|
|
|
2021
2037
|
}));
|
|
2022
2038
|
}
|
|
2023
2039
|
|
|
2040
|
+
/** A request the demo's service worker hands this tab. */
|
|
2041
|
+
|
|
2042
|
+
function isHeaderList(value) {
|
|
2043
|
+
return Array.isArray(value) && value.every(function (entry) {
|
|
2044
|
+
return Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "string";
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
function isRelayRequest(value) {
|
|
2048
|
+
return _typeof._typeof(value) === "object" && value !== null && "type" in value && value.type === demoServiceWorker.DEMO_RELAY_MESSAGE && "url" in value && typeof value.url === "string" && "method" in value && typeof value.method === "string" && "headers" in value && isHeaderList(value.headers) && "body" in value && (value.body === null || value.body instanceof ArrayBuffer);
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
/** Statuses a `Response` may not be given a body with. */
|
|
2052
|
+
var NO_BODY = new Set([101, 204, 205, 304]);
|
|
2053
|
+
function answer(_x, _x2) {
|
|
2054
|
+
return _answer.apply(this, arguments);
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Make this tab the server for the demo's uploads and unpublished files.
|
|
2058
|
+
*
|
|
2059
|
+
* Registers the demo's service worker (see `DEMO_SERVICE_WORKER_SOURCE`) and
|
|
2060
|
+
* answers what it relays with the same in-tab server the Studio's client
|
|
2061
|
+
* uses. Resolves once the worker controls this page -- the Studio must not
|
|
2062
|
+
* start before, or the first images it asks for go past it to a server that
|
|
2063
|
+
* has none of them.
|
|
2064
|
+
*
|
|
2065
|
+
* Resolves `false` where a service worker cannot run: an insecure context
|
|
2066
|
+
* (plain http on anything but localhost), or a browser without them. Uploads
|
|
2067
|
+
* are then off, and the Studio says why.
|
|
2068
|
+
*/
|
|
2069
|
+
function _answer() {
|
|
2070
|
+
_answer = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee(fetch, request) {
|
|
2071
|
+
var res, body, _t;
|
|
2072
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
2073
|
+
while (1) switch (_context.n) {
|
|
2074
|
+
case 0:
|
|
2075
|
+
_context.n = 1;
|
|
2076
|
+
return fetch(request.url, {
|
|
2077
|
+
method: request.method,
|
|
2078
|
+
headers: request.headers,
|
|
2079
|
+
body: request.body
|
|
2080
|
+
});
|
|
2081
|
+
case 1:
|
|
2082
|
+
res = _context.v;
|
|
2083
|
+
if (!NO_BODY.has(res.status)) {
|
|
2084
|
+
_context.n = 2;
|
|
2085
|
+
break;
|
|
2086
|
+
}
|
|
2087
|
+
_t = null;
|
|
2088
|
+
_context.n = 4;
|
|
2089
|
+
break;
|
|
2090
|
+
case 2:
|
|
2091
|
+
_context.n = 3;
|
|
2092
|
+
return res.arrayBuffer();
|
|
2093
|
+
case 3:
|
|
2094
|
+
_t = _context.v;
|
|
2095
|
+
case 4:
|
|
2096
|
+
body = _t;
|
|
2097
|
+
return _context.a(2, {
|
|
2098
|
+
status: res.status,
|
|
2099
|
+
headers: version._toConsumableArray(res.headers),
|
|
2100
|
+
body: body
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
}, _callee);
|
|
2104
|
+
}));
|
|
2105
|
+
return _answer.apply(this, arguments);
|
|
2106
|
+
}
|
|
2107
|
+
function startDemoRelay(_x3) {
|
|
2108
|
+
return _startDemoRelay.apply(this, arguments);
|
|
2109
|
+
}
|
|
2110
|
+
function _startDemoRelay() {
|
|
2111
|
+
_startDemoRelay = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee2(fetch) {
|
|
2112
|
+
var container, registration, _registration$active, controlled, _t2;
|
|
2113
|
+
return asyncToGenerator._regenerator().w(function (_context2) {
|
|
2114
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
2115
|
+
case 0:
|
|
2116
|
+
if (!(typeof navigator === "undefined" || !("serviceWorker" in navigator) || !window.isSecureContext)) {
|
|
2117
|
+
_context2.n = 1;
|
|
2118
|
+
break;
|
|
2119
|
+
}
|
|
2120
|
+
return _context2.a(2, false);
|
|
2121
|
+
case 1:
|
|
2122
|
+
container = navigator.serviceWorker;
|
|
2123
|
+
container.addEventListener("message", function (event) {
|
|
2124
|
+
var port = event.ports[0];
|
|
2125
|
+
if (!isRelayRequest(event.data) || !port) return;
|
|
2126
|
+
answer(fetch, event.data).then(function (res) {
|
|
2127
|
+
return port.postMessage(res, res.body ? [res.body] : []);
|
|
2128
|
+
})["catch"](function (err) {
|
|
2129
|
+
console.error("Val: the demo could not answer a relayed request", err);
|
|
2130
|
+
port.postMessage({
|
|
2131
|
+
status: 500,
|
|
2132
|
+
headers: [["Content-Type", "application/json"]],
|
|
2133
|
+
body: new TextEncoder().encode(JSON.stringify({
|
|
2134
|
+
message: "The demo's server failed to answer."
|
|
2135
|
+
})).buffer
|
|
2136
|
+
});
|
|
2137
|
+
});
|
|
2138
|
+
});
|
|
2139
|
+
// Messages are queued until this is called, when the listener is added with
|
|
2140
|
+
// `addEventListener` rather than assigned to `onmessage`.
|
|
2141
|
+
container.startMessages();
|
|
2142
|
+
_context2.p = 2;
|
|
2143
|
+
_context2.n = 3;
|
|
2144
|
+
return container.register("/api/val".concat(demoServiceWorker.DEMO_SERVICE_WORKER_PATH), {
|
|
2145
|
+
scope: "/"
|
|
2146
|
+
});
|
|
2147
|
+
case 3:
|
|
2148
|
+
_context2.n = 4;
|
|
2149
|
+
return container.ready;
|
|
2150
|
+
case 4:
|
|
2151
|
+
registration = _context2.v;
|
|
2152
|
+
if (container.controller) {
|
|
2153
|
+
_context2.n = 5;
|
|
2154
|
+
break;
|
|
2155
|
+
}
|
|
2156
|
+
// Not controlled yet. On a first visit the worker claims this page when
|
|
2157
|
+
// it activates. After a hard reload (Shift+Reload) it has activated
|
|
2158
|
+
// already and a browser deliberately leaves the page uncontrolled, so
|
|
2159
|
+
// the page asks it to claim -- or this would wait out the timeout and
|
|
2160
|
+
// start with uploads off.
|
|
2161
|
+
controlled = new Promise(function (resolve) {
|
|
2162
|
+
var timer = setTimeout(resolve, 10000);
|
|
2163
|
+
container.addEventListener("controllerchange", function () {
|
|
2164
|
+
clearTimeout(timer);
|
|
2165
|
+
resolve();
|
|
2166
|
+
}, {
|
|
2167
|
+
once: true
|
|
2168
|
+
});
|
|
2169
|
+
});
|
|
2170
|
+
(_registration$active = registration.active) === null || _registration$active === void 0 || _registration$active.postMessage({
|
|
2171
|
+
type: demoServiceWorker.DEMO_CLAIM_MESSAGE
|
|
2172
|
+
});
|
|
2173
|
+
_context2.n = 5;
|
|
2174
|
+
return controlled;
|
|
2175
|
+
case 5:
|
|
2176
|
+
return _context2.a(2, container.controller !== null);
|
|
2177
|
+
case 6:
|
|
2178
|
+
_context2.p = 6;
|
|
2179
|
+
_t2 = _context2.v;
|
|
2180
|
+
console.error("Val: the demo's service worker did not start", _t2);
|
|
2181
|
+
return _context2.a(2, false);
|
|
2182
|
+
}
|
|
2183
|
+
}, _callee2, null, [[2, 6]]);
|
|
2184
|
+
}));
|
|
2185
|
+
return _startDemoRelay.apply(this, arguments);
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2024
2188
|
var VAL_READY_PING_MS = 100;
|
|
2025
2189
|
|
|
2026
2190
|
/**
|
|
@@ -2038,10 +2202,12 @@ var studioStylesLoaded = false;
|
|
|
2038
2202
|
var LOADING_SCREEN_MAX_MS = 15000;
|
|
2039
2203
|
var ValApp = function ValApp(_ref) {
|
|
2040
2204
|
var config = _ref.config,
|
|
2041
|
-
children = _ref.children
|
|
2205
|
+
children = _ref.children,
|
|
2206
|
+
demo = _ref.demo;
|
|
2042
2207
|
var route = "/api/val"; // TODO: make configurable
|
|
2208
|
+
var demoStart = useDemoServer(demo === true, config);
|
|
2043
2209
|
var _useState = React.useState(),
|
|
2044
|
-
_useState2 =
|
|
2210
|
+
_useState2 = _typeof._slicedToArray(_useState, 2),
|
|
2045
2211
|
inMessageMode = _useState2[0],
|
|
2046
2212
|
setInMessageMode = _useState2[1];
|
|
2047
2213
|
var isClientSIde = inMessageMode === undefined;
|
|
@@ -2077,7 +2243,7 @@ var ValApp = function ValApp(_ref) {
|
|
|
2077
2243
|
var _useState3 = React.useState(function () {
|
|
2078
2244
|
return !studioStylesLoaded;
|
|
2079
2245
|
}),
|
|
2080
|
-
_useState4 =
|
|
2246
|
+
_useState4 = _typeof._slicedToArray(_useState3, 2),
|
|
2081
2247
|
covering = _useState4[0],
|
|
2082
2248
|
setCovering = _useState4[1];
|
|
2083
2249
|
React.useEffect(function () {
|
|
@@ -2100,7 +2266,7 @@ var ValApp = function ValApp(_ref) {
|
|
|
2100
2266
|
|
|
2101
2267
|
// this theme is used to avoid flickering
|
|
2102
2268
|
var _useState5 = React.useState(config.defaultTheme || null),
|
|
2103
|
-
_useState6 =
|
|
2269
|
+
_useState6 = _typeof._slicedToArray(_useState5, 2),
|
|
2104
2270
|
loadingTheme = _useState6[0],
|
|
2105
2271
|
setLoadingTheme = _useState6[1];
|
|
2106
2272
|
React.useEffect(function () {
|
|
@@ -2192,6 +2358,21 @@ var ValApp = function ValApp(_ref) {
|
|
|
2192
2358
|
children: "Val Studio is disabled: in message mode"
|
|
2193
2359
|
});
|
|
2194
2360
|
}
|
|
2361
|
+
if (demo && demoStart.status === "failed") {
|
|
2362
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2363
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(DemoStartFailed, {
|
|
2364
|
+
failure: demoStart
|
|
2365
|
+
}), children]
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
if (demo && demoStart.status !== "ready") {
|
|
2369
|
+
// The Studio reads `window.__VAL_DEMO__` when its script starts, so the
|
|
2370
|
+
// server it talks to has to be there first. The modules are registered
|
|
2371
|
+
// by a child (`ValModulesClient`), whose effect has run by then.
|
|
2372
|
+
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
2373
|
+
children: children
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2195
2376
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2196
2377
|
children: [loadingScreen, /*#__PURE__*/jsxRuntime.jsx(ValScript, {
|
|
2197
2378
|
src: "".concat(route, "/static").concat(ui.VERSION ? "/".concat(ui.VERSION) : "").concat(ui.VAL_APP_PATH)
|
|
@@ -2202,6 +2383,154 @@ var ValApp = function ValApp(_ref) {
|
|
|
2202
2383
|
});
|
|
2203
2384
|
};
|
|
2204
2385
|
|
|
2386
|
+
/**
|
|
2387
|
+
* Starts Val's server in this tab, and hands it to the Studio.
|
|
2388
|
+
*
|
|
2389
|
+
* Loaded on demand: `@valbuild/server/browser` is the whole request-handling
|
|
2390
|
+
* half of the server, and only a demo should download it.
|
|
2391
|
+
*/
|
|
2392
|
+
|
|
2393
|
+
function useDemoServer(demo, config) {
|
|
2394
|
+
var _useState7 = React.useState({
|
|
2395
|
+
status: "starting"
|
|
2396
|
+
}),
|
|
2397
|
+
_useState8 = _typeof._slicedToArray(_useState7, 2),
|
|
2398
|
+
start = _useState8[0],
|
|
2399
|
+
setStart = _useState8[1];
|
|
2400
|
+
React.useEffect(function () {
|
|
2401
|
+
if (!demo) return;
|
|
2402
|
+
var cancelled = false;
|
|
2403
|
+
var run = /*#__PURE__*/function () {
|
|
2404
|
+
var _ref2 = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
|
|
2405
|
+
var _yield$import, createInTabValFetch, modules, fetch, uploads, runtime;
|
|
2406
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
2407
|
+
while (1) switch (_context.n) {
|
|
2408
|
+
case 0:
|
|
2409
|
+
_context.n = 1;
|
|
2410
|
+
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@valbuild/server/browser')); });
|
|
2411
|
+
case 1:
|
|
2412
|
+
_yield$import = _context.v;
|
|
2413
|
+
createInTabValFetch = _yield$import.createInTabValFetch;
|
|
2414
|
+
modules = window.__VAL_MODULES__;
|
|
2415
|
+
if (modules) {
|
|
2416
|
+
_context.n = 2;
|
|
2417
|
+
break;
|
|
2418
|
+
}
|
|
2419
|
+
return _context.a(2, {
|
|
2420
|
+
status: "failed",
|
|
2421
|
+
message: "This demo was built without its content. Render <ValModulesClient modules={valModules} /> inside <ValApp demo>.",
|
|
2422
|
+
details: null,
|
|
2423
|
+
retryable: false
|
|
2424
|
+
});
|
|
2425
|
+
case 2:
|
|
2426
|
+
fetch = createInTabValFetch(modules, {
|
|
2427
|
+
config: config
|
|
2428
|
+
});
|
|
2429
|
+
_context.n = 3;
|
|
2430
|
+
return startDemoRelay(fetch);
|
|
2431
|
+
case 3:
|
|
2432
|
+
uploads = _context.v;
|
|
2433
|
+
runtime = {
|
|
2434
|
+
fetch: fetch,
|
|
2435
|
+
uploads: uploads
|
|
2436
|
+
};
|
|
2437
|
+
window.__VAL_DEMO__ = runtime;
|
|
2438
|
+
return _context.a(2, {
|
|
2439
|
+
status: "ready"
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
}, _callee);
|
|
2443
|
+
}));
|
|
2444
|
+
return function run() {
|
|
2445
|
+
return _ref2.apply(this, arguments);
|
|
2446
|
+
};
|
|
2447
|
+
}();
|
|
2448
|
+
run()["catch"](function (err) {
|
|
2449
|
+
console.error("Val: the demo could not start", err);
|
|
2450
|
+
return {
|
|
2451
|
+
status: "failed",
|
|
2452
|
+
// Most often the server's code did not download: the page is fine,
|
|
2453
|
+
// and loading it again fetches it again.
|
|
2454
|
+
message: "The demo could not start: part of it did not load.",
|
|
2455
|
+
details: err instanceof Error ? err.message : String(err),
|
|
2456
|
+
retryable: true
|
|
2457
|
+
};
|
|
2458
|
+
}).then(function (result) {
|
|
2459
|
+
if (!cancelled) setStart(result);
|
|
2460
|
+
});
|
|
2461
|
+
return function () {
|
|
2462
|
+
cancelled = true;
|
|
2463
|
+
};
|
|
2464
|
+
}, [demo, config]);
|
|
2465
|
+
return start;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
/**
|
|
2469
|
+
* Said on the page, not only in the console: without it a demo that failed
|
|
2470
|
+
* to start is a site with no Studio and no reason given. Plain styles, since
|
|
2471
|
+
* the Studio's stylesheet is exactly what has not loaded.
|
|
2472
|
+
*/
|
|
2473
|
+
function DemoStartFailed(_ref3) {
|
|
2474
|
+
var failure = _ref3.failure;
|
|
2475
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
2476
|
+
role: "alert",
|
|
2477
|
+
style: {
|
|
2478
|
+
position: "fixed",
|
|
2479
|
+
left: "1rem",
|
|
2480
|
+
right: "1rem",
|
|
2481
|
+
bottom: "1rem",
|
|
2482
|
+
maxWidth: "28rem",
|
|
2483
|
+
margin: "0 auto",
|
|
2484
|
+
padding: "1rem",
|
|
2485
|
+
borderRadius: "0.75rem",
|
|
2486
|
+
background: "white",
|
|
2487
|
+
color: "black",
|
|
2488
|
+
boxShadow: "0 8px 30px rgba(0, 0, 0, 0.2)",
|
|
2489
|
+
fontFamily: "system-ui, sans-serif",
|
|
2490
|
+
fontSize: "0.875rem",
|
|
2491
|
+
lineHeight: 1.4,
|
|
2492
|
+
zIndex: 2147483647
|
|
2493
|
+
},
|
|
2494
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("p", {
|
|
2495
|
+
style: {
|
|
2496
|
+
margin: 0
|
|
2497
|
+
},
|
|
2498
|
+
children: failure.message
|
|
2499
|
+
}), failure.retryable && /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
2500
|
+
type: "button",
|
|
2501
|
+
onClick: function onClick() {
|
|
2502
|
+
return window.location.reload();
|
|
2503
|
+
},
|
|
2504
|
+
style: {
|
|
2505
|
+
marginTop: "0.75rem",
|
|
2506
|
+
padding: "0.375rem 0.75rem",
|
|
2507
|
+
borderRadius: "0.375rem",
|
|
2508
|
+
border: "1px solid #ccc",
|
|
2509
|
+
background: "#f4f4f4",
|
|
2510
|
+
font: "inherit",
|
|
2511
|
+
cursor: "pointer"
|
|
2512
|
+
},
|
|
2513
|
+
children: "Try again"
|
|
2514
|
+
}), failure.details !== null && /*#__PURE__*/jsxRuntime.jsxs("details", {
|
|
2515
|
+
style: {
|
|
2516
|
+
marginTop: "0.75rem",
|
|
2517
|
+
color: "#555"
|
|
2518
|
+
},
|
|
2519
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("summary", {
|
|
2520
|
+
style: {
|
|
2521
|
+
cursor: "pointer"
|
|
2522
|
+
},
|
|
2523
|
+
children: "Details"
|
|
2524
|
+
}), /*#__PURE__*/jsxRuntime.jsx("code", {
|
|
2525
|
+
style: {
|
|
2526
|
+
wordBreak: "break-word"
|
|
2527
|
+
},
|
|
2528
|
+
children: failure.details
|
|
2529
|
+
})]
|
|
2530
|
+
})]
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2205
2534
|
// Keep in sync with VAL_MODULES_UPDATED_EVENT in @valbuild/ui (useValModules.ts).
|
|
2206
2535
|
var VAL_MODULES_UPDATED_EVENT = "val-modules-updated";
|
|
2207
2536
|
|
|
@@ -2259,8 +2588,8 @@ stega.autoTagJSX();
|
|
|
2259
2588
|
* keeps everything the emitter needs reachable through the package entry point.
|
|
2260
2589
|
*/
|
|
2261
2590
|
|
|
2262
|
-
var Internal =
|
|
2263
|
-
VERSION:
|
|
2591
|
+
var Internal = _typeof._objectSpread2(_typeof._objectSpread2({}, core.Internal), {}, {
|
|
2592
|
+
VERSION: _typeof._objectSpread2(_typeof._objectSpread2({}, core.Internal.VERSION), {}, {
|
|
2264
2593
|
tanstack: version.VERSION
|
|
2265
2594
|
})
|
|
2266
2595
|
});
|