@valbuild/next 0.84.3 → 0.85.1

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 (35) hide show
  1. package/client/dist/valbuild-next-client.cjs.dev.js +28 -6
  2. package/client/dist/valbuild-next-client.cjs.prod.js +28 -6
  3. package/client/dist/valbuild-next-client.esm.js +27 -5
  4. package/dist/ValApp-0ded607c.cjs.dev.js +133 -0
  5. package/dist/ValApp-489d97dc.esm.js +125 -0
  6. package/dist/ValApp-b10c2084.cjs.js +7 -0
  7. package/dist/ValApp-b10c2084.cjs.prod.js +133 -0
  8. package/dist/{ValNextProvider-25f1f5c9.esm.js → ValNextProvider-10c232b6.esm.js} +80 -44
  9. package/dist/ValNextProvider-7042b86d.cjs.js +7 -0
  10. package/dist/{ValNextProvider-a618d775.cjs.prod.js → ValNextProvider-7042b86d.cjs.prod.js} +80 -44
  11. package/dist/{ValNextProvider-c7952bdc.cjs.dev.js → ValNextProvider-726026f9.cjs.dev.js} +80 -44
  12. package/dist/cssUtils-9c11102f.cjs.dev.js +41 -0
  13. package/dist/cssUtils-b5651c03.esm.js +32 -0
  14. package/dist/cssUtils-d97a757c.cjs.prod.js +41 -0
  15. package/dist/declarations/src/ValApp.d.ts +1 -1
  16. package/dist/declarations/src/client/initValClient.d.ts +2 -0
  17. package/dist/declarations/src/rsc/initValRsc.d.ts +9 -0
  18. package/dist/{initValRouteFromVal-4e6253bf.esm.js → routeFromVal-248c62f1.esm.js} +17 -4
  19. package/dist/{initValRouteFromVal-0f4f2d39.cjs.prod.js → routeFromVal-a317debc.cjs.prod.js} +17 -3
  20. package/dist/{initValRouteFromVal-65dd1262.cjs.dev.js → routeFromVal-a3987ae3.cjs.dev.js} +17 -3
  21. package/dist/valbuild-next.cjs.dev.js +2 -2
  22. package/dist/valbuild-next.cjs.prod.js +2 -2
  23. package/dist/valbuild-next.esm.js +2 -2
  24. package/package.json +6 -6
  25. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +134 -46
  26. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +134 -46
  27. package/rsc/dist/valbuild-next-rsc.esm.js +133 -45
  28. package/dist/ValApp-0efa0e5d.cjs.dev.js +0 -63
  29. package/dist/ValApp-3ab62a2b.esm.js +0 -55
  30. package/dist/ValApp-a808cf89.cjs.js +0 -7
  31. package/dist/ValApp-a808cf89.cjs.prod.js +0 -63
  32. package/dist/ValNextProvider-a618d775.cjs.js +0 -7
  33. package/dist/useRemoteConfigSender-02451801.esm.js +0 -70
  34. package/dist/useRemoteConfigSender-3ea2fe91.cjs.prod.js +0 -76
  35. package/dist/useRemoteConfigSender-c78b81c5.cjs.dev.js +0 -76
@@ -7,7 +7,7 @@ var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
9
  var ValOverlayContext = require('../../dist/ValOverlayContext-c82a4507.cjs.dev.js');
10
- var initValRouteFromVal = require('../../dist/initValRouteFromVal-65dd1262.cjs.dev.js');
10
+ var routeFromVal = require('../../dist/routeFromVal-a3987ae3.cjs.dev.js');
11
11
  require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
12
12
  require('../../dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
13
13
  require('../../dist/objectSpread2-792eb2c2.cjs.dev.js');
@@ -41,19 +41,40 @@ function useValStega(selector) {
41
41
  }
42
42
  });
43
43
  }
44
- function useValRouteStega(selector, params) {
45
- var val = useValStega(selector);
44
+ function resolveParams(params) {
45
+ if (!params) {
46
+ return null;
47
+ }
46
48
  var resolvedParams = "then" in params ? undefined : params;
47
49
  if ("then" in params) {
48
50
  if ("use" in React__default["default"]) {
49
51
  // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
50
52
  resolvedParams = React__default["default"].use(params);
51
53
  } else {
52
- console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
54
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is unavailable. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
53
55
  return null;
54
56
  }
55
57
  }
56
- var route = initValRouteFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
58
+ return resolvedParams;
59
+ }
60
+ function useValRouteStega(selector, params) {
61
+ var val = useValStega(selector);
62
+ var resolvedParams = resolveParams(params);
63
+ // Careful: null means there was an error - undefined means no params
64
+ if (resolvedParams === null) {
65
+ return null;
66
+ }
67
+ var route = routeFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
68
+ return route;
69
+ }
70
+ function useValRouteUrl(selector, params) {
71
+ var val = useValStega(selector);
72
+ var resolvedParams = params === undefined ? undefined : resolveParams(params);
73
+ // Careful: null means there was an error - undefined means no params
74
+ if (resolvedParams === null) {
75
+ return null;
76
+ }
77
+ var route = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
57
78
  return route;
58
79
  }
59
80
 
@@ -61,7 +82,8 @@ function useValRouteStega(selector, params) {
61
82
  function initValClient(config) {
62
83
  return {
63
84
  useValStega: useValStega,
64
- useValRouteStega: useValRouteStega
85
+ useValRouteStega: useValRouteStega,
86
+ useValRouteUrl: useValRouteUrl
65
87
  };
66
88
  }
67
89
 
@@ -7,7 +7,7 @@ var core = require('@valbuild/core');
7
7
  var stega = require('@valbuild/react/stega');
8
8
  var React = require('react');
9
9
  var ValOverlayContext = require('../../dist/ValOverlayContext-942f1294.cjs.prod.js');
10
- var initValRouteFromVal = require('../../dist/initValRouteFromVal-0f4f2d39.cjs.prod.js');
10
+ var routeFromVal = require('../../dist/routeFromVal-a317debc.cjs.prod.js');
11
11
  require('../../dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js');
12
12
  require('../../dist/unsupportedIterableToArray-0d2087a2.cjs.prod.js');
13
13
  require('../../dist/objectSpread2-3c87fb4f.cjs.prod.js');
@@ -41,19 +41,40 @@ function useValStega(selector) {
41
41
  }
42
42
  });
43
43
  }
44
- function useValRouteStega(selector, params) {
45
- var val = useValStega(selector);
44
+ function resolveParams(params) {
45
+ if (!params) {
46
+ return null;
47
+ }
46
48
  var resolvedParams = "then" in params ? undefined : params;
47
49
  if ("then" in params) {
48
50
  if ("use" in React__default["default"]) {
49
51
  // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
50
52
  resolvedParams = React__default["default"].use(params);
51
53
  } else {
52
- console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
54
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is unavailable. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
53
55
  return null;
54
56
  }
55
57
  }
56
- var route = initValRouteFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
58
+ return resolvedParams;
59
+ }
60
+ function useValRouteStega(selector, params) {
61
+ var val = useValStega(selector);
62
+ var resolvedParams = resolveParams(params);
63
+ // Careful: null means there was an error - undefined means no params
64
+ if (resolvedParams === null) {
65
+ return null;
66
+ }
67
+ var route = routeFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
68
+ return route;
69
+ }
70
+ function useValRouteUrl(selector, params) {
71
+ var val = useValStega(selector);
72
+ var resolvedParams = params === undefined ? undefined : resolveParams(params);
73
+ // Careful: null means there was an error - undefined means no params
74
+ if (resolvedParams === null) {
75
+ return null;
76
+ }
77
+ var route = routeFromVal.getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
57
78
  return route;
58
79
  }
59
80
 
@@ -61,7 +82,8 @@ function useValRouteStega(selector, params) {
61
82
  function initValClient(config) {
62
83
  return {
63
84
  useValStega: useValStega,
64
- useValRouteStega: useValRouteStega
85
+ useValRouteStega: useValRouteStega,
86
+ useValRouteUrl: useValRouteUrl
65
87
  };
66
88
  }
67
89
 
@@ -3,7 +3,7 @@ import { Internal } from '@valbuild/core';
3
3
  import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
4
4
  import React from 'react';
5
5
  import { useValOverlayContext } from '../../dist/ValOverlayContext-6635a4d7.esm.js';
6
- import { i as initValRouteFromVal } from '../../dist/initValRouteFromVal-4e6253bf.esm.js';
6
+ import { i as initValRouteFromVal, g as getValRouteUrlFromVal } from '../../dist/routeFromVal-248c62f1.esm.js';
7
7
  import '../../dist/createForOfIteratorHelper-5758a730.esm.js';
8
8
  import '../../dist/unsupportedIterableToArray-5baabfdc.esm.js';
9
9
  import '../../dist/objectSpread2-c1340c1c.esm.js';
@@ -33,27 +33,49 @@ function useValStega(selector) {
33
33
  }
34
34
  });
35
35
  }
36
- function useValRouteStega(selector, params) {
37
- var val = useValStega(selector);
36
+ function resolveParams(params) {
37
+ if (!params) {
38
+ return null;
39
+ }
38
40
  var resolvedParams = "then" in params ? undefined : params;
39
41
  if ("then" in params) {
40
42
  if ("use" in React) {
41
43
  // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
42
44
  resolvedParams = React.use(params);
43
45
  } else {
44
- console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
46
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is unavailable. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
45
47
  return null;
46
48
  }
47
49
  }
50
+ return resolvedParams;
51
+ }
52
+ function useValRouteStega(selector, params) {
53
+ var val = useValStega(selector);
54
+ var resolvedParams = resolveParams(params);
55
+ // Careful: null means there was an error - undefined means no params
56
+ if (resolvedParams === null) {
57
+ return null;
58
+ }
48
59
  var route = initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && Internal.getValPath(selector), selector && Internal.getSchema(selector), val);
49
60
  return route;
50
61
  }
62
+ function useValRouteUrl(selector, params) {
63
+ var val = useValStega(selector);
64
+ var resolvedParams = params === undefined ? undefined : resolveParams(params);
65
+ // Careful: null means there was an error - undefined means no params
66
+ if (resolvedParams === null) {
67
+ return null;
68
+ }
69
+ var route = getValRouteUrlFromVal(resolvedParams || {}, "useValRouteUrl", selector && Internal.getValPath(selector), selector && Internal.getSchema(selector), val);
70
+ return route;
71
+ }
51
72
 
52
73
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
74
  function initValClient(config) {
54
75
  return {
55
76
  useValStega: useValStega,
56
- useValRouteStega: useValRouteStega
77
+ useValRouteStega: useValRouteStega,
78
+ useValRouteUrl: useValRouteUrl
57
79
  };
58
80
  }
59
81
 
@@ -0,0 +1,133 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var slicedToArray = require('./slicedToArray-44036a76.cjs.dev.js');
7
+ var ui = require('@valbuild/ui');
8
+ var Script = require('next/script');
9
+ var React = require('react');
10
+ var cssUtils = require('./cssUtils-9c11102f.cjs.dev.js');
11
+ var jsxRuntime = require('react/jsx-runtime');
12
+ require('./unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
13
+ require('@valbuild/shared/internal');
14
+ require('@valbuild/core');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
17
+
18
+ var Script__default = /*#__PURE__*/_interopDefault(Script);
19
+
20
+ var ValApp = function ValApp(_ref) {
21
+ var config = _ref.config;
22
+ var route = "/api/val"; // TODO: make configurable
23
+ var _useState = React.useState(),
24
+ _useState2 = slicedToArray._slicedToArray(_useState, 2),
25
+ inMessageMode = _useState2[0],
26
+ setInMessageMode = _useState2[1];
27
+ var isClientSIde = inMessageMode === undefined;
28
+ cssUtils.useConfigStorageSave(config);
29
+ React.useEffect(function () {
30
+ if (location.search === "?message_onready=true") {
31
+ setInMessageMode(true);
32
+ var interval = setInterval(function () {
33
+ window.parent.postMessage({
34
+ type: "val-ready"
35
+ }, "*");
36
+ });
37
+ return function () {
38
+ clearInterval(interval);
39
+ };
40
+ } else {
41
+ setInMessageMode(false);
42
+ }
43
+ }, []);
44
+
45
+ // this theme is used to avoid flickering
46
+ var _useState3 = React.useState(config.defaultTheme || null),
47
+ _useState4 = slicedToArray._slicedToArray(_useState3, 2),
48
+ loadingTheme = _useState4[0],
49
+ setLoadingTheme = _useState4[1];
50
+ React.useEffect(function () {
51
+ var theme = localStorage.getItem("val-theme-" + ((config === null || config === void 0 ? void 0 : config.project) || "unknown"));
52
+ if (theme === "dark") {
53
+ setLoadingTheme("dark");
54
+ } else if (theme === "light") {
55
+ setLoadingTheme("light");
56
+ } else if (config.defaultTheme) {
57
+ setLoadingTheme(config.defaultTheme);
58
+ }
59
+ }, [config]);
60
+ var darkBg = "#0c111d";
61
+ var lightBg = "white";
62
+ React.useEffect(function () {
63
+ if (inMessageMode || loadingTheme === null) {
64
+ return;
65
+ }
66
+ var body = document.body;
67
+ var prevBodyBg = body.style.backgroundColor;
68
+ var prevBodyMinHeight = body.style.minHeight;
69
+ var prevBodyMinWidth = body.style.minWidth;
70
+ body.style.backgroundColor = loadingTheme === "dark" ? darkBg : lightBg;
71
+ body.style.minHeight = "100vh";
72
+ body.style.minWidth = "100%";
73
+ window.addEventListener("val-css-loaded", function () {
74
+ // css was loaded, has been loaded, so let app decide what to do
75
+ setLoadingTheme(null);
76
+ });
77
+ return function () {
78
+ body.style.backgroundColor = prevBodyBg;
79
+ body.style.minHeight = prevBodyMinHeight;
80
+ body.style.minWidth = prevBodyMinWidth;
81
+ window.removeEventListener("val-css-loaded", function () {
82
+ setLoadingTheme(null);
83
+ });
84
+ };
85
+ }, [inMessageMode, loadingTheme]);
86
+ if (loadingTheme !== null && isClientSIde) {
87
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
88
+ style: {
89
+ color: loadingTheme === "dark" ? "white" : "black",
90
+ display: "flex",
91
+ justifyContent: "center",
92
+ alignItems: "center",
93
+ padding: "1rem",
94
+ backgroundColor: loadingTheme === "dark" ? darkBg : lightBg,
95
+ minHeight: "100vh",
96
+ minWidth: "100%"
97
+ },
98
+ children: [/*#__PURE__*/jsxRuntime.jsx("style", {
99
+ children: ".".concat(cssUtils.valPrefixedClass, "animate-spin {\n animation: ").concat(cssUtils.valPrefixedClass, "spin 2s linear infinite;\n}\n@keyframes ").concat(cssUtils.valPrefixedClass, "spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}")
100
+ }), /*#__PURE__*/jsxRuntime.jsx("svg", {
101
+ xmlns: "http://www.w3.org/2000/svg",
102
+ width: "24",
103
+ height: "24",
104
+ viewBox: "0 0 24 24",
105
+ fill: "none",
106
+ stroke: "currentColor",
107
+ strokeWidth: "2",
108
+ strokeLinecap: "round",
109
+ strokeLinejoin: "round",
110
+ className: cssUtils.cn(["animate-spin"]),
111
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
112
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
113
+ })
114
+ })]
115
+ });
116
+ }
117
+ if (inMessageMode) {
118
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
119
+ children: "Val Studio is disabled: in message mode"
120
+ });
121
+ }
122
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
123
+ children: [/*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
124
+ type: "module",
125
+ src: "".concat(route, "/static").concat(ui.VERSION ? "/".concat(ui.VERSION) : "").concat(ui.VAL_APP_PATH),
126
+ crossOrigin: "anonymous"
127
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
128
+ id: ui.VAL_APP_ID
129
+ })]
130
+ });
131
+ };
132
+
133
+ exports.ValApp = ValApp;
@@ -0,0 +1,125 @@
1
+ 'use client';
2
+ import { _ as _slicedToArray } from './slicedToArray-aa291011.esm.js';
3
+ import { VERSION, VAL_APP_PATH, VAL_APP_ID } from '@valbuild/ui';
4
+ import Script from 'next/script';
5
+ import { useState, useEffect } from 'react';
6
+ import { u as useConfigStorageSave, v as valPrefixedClass, c as cn } from './cssUtils-b5651c03.esm.js';
7
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
+ import './unsupportedIterableToArray-5baabfdc.esm.js';
9
+ import '@valbuild/shared/internal';
10
+ import '@valbuild/core';
11
+
12
+ var ValApp = function ValApp(_ref) {
13
+ var config = _ref.config;
14
+ var route = "/api/val"; // TODO: make configurable
15
+ var _useState = useState(),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ inMessageMode = _useState2[0],
18
+ setInMessageMode = _useState2[1];
19
+ var isClientSIde = inMessageMode === undefined;
20
+ useConfigStorageSave(config);
21
+ useEffect(function () {
22
+ if (location.search === "?message_onready=true") {
23
+ setInMessageMode(true);
24
+ var interval = setInterval(function () {
25
+ window.parent.postMessage({
26
+ type: "val-ready"
27
+ }, "*");
28
+ });
29
+ return function () {
30
+ clearInterval(interval);
31
+ };
32
+ } else {
33
+ setInMessageMode(false);
34
+ }
35
+ }, []);
36
+
37
+ // this theme is used to avoid flickering
38
+ var _useState3 = useState(config.defaultTheme || null),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ loadingTheme = _useState4[0],
41
+ setLoadingTheme = _useState4[1];
42
+ useEffect(function () {
43
+ var theme = localStorage.getItem("val-theme-" + ((config === null || config === void 0 ? void 0 : config.project) || "unknown"));
44
+ if (theme === "dark") {
45
+ setLoadingTheme("dark");
46
+ } else if (theme === "light") {
47
+ setLoadingTheme("light");
48
+ } else if (config.defaultTheme) {
49
+ setLoadingTheme(config.defaultTheme);
50
+ }
51
+ }, [config]);
52
+ var darkBg = "#0c111d";
53
+ var lightBg = "white";
54
+ useEffect(function () {
55
+ if (inMessageMode || loadingTheme === null) {
56
+ return;
57
+ }
58
+ var body = document.body;
59
+ var prevBodyBg = body.style.backgroundColor;
60
+ var prevBodyMinHeight = body.style.minHeight;
61
+ var prevBodyMinWidth = body.style.minWidth;
62
+ body.style.backgroundColor = loadingTheme === "dark" ? darkBg : lightBg;
63
+ body.style.minHeight = "100vh";
64
+ body.style.minWidth = "100%";
65
+ window.addEventListener("val-css-loaded", function () {
66
+ // css was loaded, has been loaded, so let app decide what to do
67
+ setLoadingTheme(null);
68
+ });
69
+ return function () {
70
+ body.style.backgroundColor = prevBodyBg;
71
+ body.style.minHeight = prevBodyMinHeight;
72
+ body.style.minWidth = prevBodyMinWidth;
73
+ window.removeEventListener("val-css-loaded", function () {
74
+ setLoadingTheme(null);
75
+ });
76
+ };
77
+ }, [inMessageMode, loadingTheme]);
78
+ if (loadingTheme !== null && isClientSIde) {
79
+ return /*#__PURE__*/jsxs("div", {
80
+ style: {
81
+ color: loadingTheme === "dark" ? "white" : "black",
82
+ display: "flex",
83
+ justifyContent: "center",
84
+ alignItems: "center",
85
+ padding: "1rem",
86
+ backgroundColor: loadingTheme === "dark" ? darkBg : lightBg,
87
+ minHeight: "100vh",
88
+ minWidth: "100%"
89
+ },
90
+ children: [/*#__PURE__*/jsx("style", {
91
+ children: ".".concat(valPrefixedClass, "animate-spin {\n animation: ").concat(valPrefixedClass, "spin 2s linear infinite;\n}\n@keyframes ").concat(valPrefixedClass, "spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}")
92
+ }), /*#__PURE__*/jsx("svg", {
93
+ xmlns: "http://www.w3.org/2000/svg",
94
+ width: "24",
95
+ height: "24",
96
+ viewBox: "0 0 24 24",
97
+ fill: "none",
98
+ stroke: "currentColor",
99
+ strokeWidth: "2",
100
+ strokeLinecap: "round",
101
+ strokeLinejoin: "round",
102
+ className: cn(["animate-spin"]),
103
+ children: /*#__PURE__*/jsx("path", {
104
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
105
+ })
106
+ })]
107
+ });
108
+ }
109
+ if (inMessageMode) {
110
+ return /*#__PURE__*/jsx("div", {
111
+ children: "Val Studio is disabled: in message mode"
112
+ });
113
+ }
114
+ return /*#__PURE__*/jsxs(Fragment, {
115
+ children: [/*#__PURE__*/jsx(Script, {
116
+ type: "module",
117
+ src: "".concat(route, "/static").concat(VERSION ? "/".concat(VERSION) : "").concat(VAL_APP_PATH),
118
+ crossOrigin: "anonymous"
119
+ }), /*#__PURE__*/jsx("div", {
120
+ id: VAL_APP_ID
121
+ })]
122
+ });
123
+ };
124
+
125
+ export { ValApp };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./ValApp-b10c2084.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./ValApp-b10c2084.cjs.dev.js");
7
+ }
@@ -0,0 +1,133 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var slicedToArray = require('./slicedToArray-ce613de6.cjs.prod.js');
7
+ var ui = require('@valbuild/ui');
8
+ var Script = require('next/script');
9
+ var React = require('react');
10
+ var cssUtils = require('./cssUtils-d97a757c.cjs.prod.js');
11
+ var jsxRuntime = require('react/jsx-runtime');
12
+ require('./unsupportedIterableToArray-0d2087a2.cjs.prod.js');
13
+ require('@valbuild/shared/internal');
14
+ require('@valbuild/core');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
17
+
18
+ var Script__default = /*#__PURE__*/_interopDefault(Script);
19
+
20
+ var ValApp = function ValApp(_ref) {
21
+ var config = _ref.config;
22
+ var route = "/api/val"; // TODO: make configurable
23
+ var _useState = React.useState(),
24
+ _useState2 = slicedToArray._slicedToArray(_useState, 2),
25
+ inMessageMode = _useState2[0],
26
+ setInMessageMode = _useState2[1];
27
+ var isClientSIde = inMessageMode === undefined;
28
+ cssUtils.useConfigStorageSave(config);
29
+ React.useEffect(function () {
30
+ if (location.search === "?message_onready=true") {
31
+ setInMessageMode(true);
32
+ var interval = setInterval(function () {
33
+ window.parent.postMessage({
34
+ type: "val-ready"
35
+ }, "*");
36
+ });
37
+ return function () {
38
+ clearInterval(interval);
39
+ };
40
+ } else {
41
+ setInMessageMode(false);
42
+ }
43
+ }, []);
44
+
45
+ // this theme is used to avoid flickering
46
+ var _useState3 = React.useState(config.defaultTheme || null),
47
+ _useState4 = slicedToArray._slicedToArray(_useState3, 2),
48
+ loadingTheme = _useState4[0],
49
+ setLoadingTheme = _useState4[1];
50
+ React.useEffect(function () {
51
+ var theme = localStorage.getItem("val-theme-" + ((config === null || config === void 0 ? void 0 : config.project) || "unknown"));
52
+ if (theme === "dark") {
53
+ setLoadingTheme("dark");
54
+ } else if (theme === "light") {
55
+ setLoadingTheme("light");
56
+ } else if (config.defaultTheme) {
57
+ setLoadingTheme(config.defaultTheme);
58
+ }
59
+ }, [config]);
60
+ var darkBg = "#0c111d";
61
+ var lightBg = "white";
62
+ React.useEffect(function () {
63
+ if (inMessageMode || loadingTheme === null) {
64
+ return;
65
+ }
66
+ var body = document.body;
67
+ var prevBodyBg = body.style.backgroundColor;
68
+ var prevBodyMinHeight = body.style.minHeight;
69
+ var prevBodyMinWidth = body.style.minWidth;
70
+ body.style.backgroundColor = loadingTheme === "dark" ? darkBg : lightBg;
71
+ body.style.minHeight = "100vh";
72
+ body.style.minWidth = "100%";
73
+ window.addEventListener("val-css-loaded", function () {
74
+ // css was loaded, has been loaded, so let app decide what to do
75
+ setLoadingTheme(null);
76
+ });
77
+ return function () {
78
+ body.style.backgroundColor = prevBodyBg;
79
+ body.style.minHeight = prevBodyMinHeight;
80
+ body.style.minWidth = prevBodyMinWidth;
81
+ window.removeEventListener("val-css-loaded", function () {
82
+ setLoadingTheme(null);
83
+ });
84
+ };
85
+ }, [inMessageMode, loadingTheme]);
86
+ if (loadingTheme !== null && isClientSIde) {
87
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
88
+ style: {
89
+ color: loadingTheme === "dark" ? "white" : "black",
90
+ display: "flex",
91
+ justifyContent: "center",
92
+ alignItems: "center",
93
+ padding: "1rem",
94
+ backgroundColor: loadingTheme === "dark" ? darkBg : lightBg,
95
+ minHeight: "100vh",
96
+ minWidth: "100%"
97
+ },
98
+ children: [/*#__PURE__*/jsxRuntime.jsx("style", {
99
+ children: ".".concat(cssUtils.valPrefixedClass, "animate-spin {\n animation: ").concat(cssUtils.valPrefixedClass, "spin 2s linear infinite;\n}\n@keyframes ").concat(cssUtils.valPrefixedClass, "spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}")
100
+ }), /*#__PURE__*/jsxRuntime.jsx("svg", {
101
+ xmlns: "http://www.w3.org/2000/svg",
102
+ width: "24",
103
+ height: "24",
104
+ viewBox: "0 0 24 24",
105
+ fill: "none",
106
+ stroke: "currentColor",
107
+ strokeWidth: "2",
108
+ strokeLinecap: "round",
109
+ strokeLinejoin: "round",
110
+ className: cssUtils.cn(["animate-spin"]),
111
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
112
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
113
+ })
114
+ })]
115
+ });
116
+ }
117
+ if (inMessageMode) {
118
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
119
+ children: "Val Studio is disabled: in message mode"
120
+ });
121
+ }
122
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
123
+ children: [/*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
124
+ type: "module",
125
+ src: "".concat(route, "/static").concat(ui.VERSION ? "/".concat(ui.VERSION) : "").concat(ui.VAL_APP_PATH),
126
+ crossOrigin: "anonymous"
127
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
128
+ id: ui.VAL_APP_ID
129
+ })]
130
+ });
131
+ };
132
+
133
+ exports.ValApp = ValApp;