@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.
- package/CHANGELOG.md +36 -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
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _slicedToArray } from './slicedToArray-70ecb9da.esm.js';
|
|
3
|
+
import { VAL_PREVIEW_MESSAGES, Internal } from '@valbuild/core';
|
|
4
|
+
import { DEFAULT_CANVAS_SELECTION } from '@valbuild/shared/client';
|
|
5
|
+
import { useRef, useState, useEffect } from 'react';
|
|
6
|
+
import { ValComponentControlsOff } from './ValComponentEditorChrome-93321513.esm.js';
|
|
7
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
var HOVER_ATTRIBUTE = "data-val-preview-hover";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* EXPERIMENTAL: the preview route's side of its conversation with the Studio,
|
|
13
|
+
* without the framework. `@valbuild/next` and `@valbuild/tanstack` each wrap it
|
|
14
|
+
* with what a refresh means in their router.
|
|
15
|
+
*
|
|
16
|
+
* - **Refresh.** The Studio runs in the parent frame, so an edit is applied
|
|
17
|
+
* there and the preview has no way of knowing about it. The Studio posts a
|
|
18
|
+
* message, and this calls `onRefresh`, which reads the content again.
|
|
19
|
+
* - **Size.** The Studio cannot see into the frame to measure it, so this
|
|
20
|
+
* reports how tall the component is whenever that changes, and the Studio
|
|
21
|
+
* sizes the frame to fit.
|
|
22
|
+
* - **Pick.** Content read with stega carries its source path (Val tags the
|
|
23
|
+
* element with `data-val-path`), so a click on it says which field it came
|
|
24
|
+
* from. While the Studio has picking on - it is by default - a click on
|
|
25
|
+
* tagged content is sent to the Studio, which opens that field, instead of
|
|
26
|
+
* doing what it does on the site.
|
|
27
|
+
*/
|
|
28
|
+
function ValPreviewBridgeCore(_ref) {
|
|
29
|
+
var onRefresh = _ref.onRefresh,
|
|
30
|
+
children = _ref.children;
|
|
31
|
+
var ref = useRef(null);
|
|
32
|
+
// A ref, so a new `onRefresh` - a router can hand out a new one after every
|
|
33
|
+
// refresh - does not re-subscribe and announce `ready` all over again.
|
|
34
|
+
var onRefreshRef = useRef(onRefresh);
|
|
35
|
+
onRefreshRef.current = onRefresh;
|
|
36
|
+
// On until the Studio says otherwise: it says so as soon as it hears `ready`.
|
|
37
|
+
var _useState = useState(true),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
picking = _useState2[0],
|
|
40
|
+
setPicking = _useState2[1];
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
if (window.parent === window) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var listener = function listener(event) {
|
|
46
|
+
var _event$data, _event$data2;
|
|
47
|
+
if (event.origin !== window.location.origin) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === VAL_PREVIEW_MESSAGES.refresh) {
|
|
51
|
+
onRefreshRef.current();
|
|
52
|
+
} else if (((_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.type) === VAL_PREVIEW_MESSAGES.picking && typeof event.data.enabled === "boolean") {
|
|
53
|
+
setPicking(event.data.enabled);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("message", listener);
|
|
57
|
+
window.parent.postMessage({
|
|
58
|
+
type: VAL_PREVIEW_MESSAGES.ready
|
|
59
|
+
}, window.location.origin);
|
|
60
|
+
return function () {
|
|
61
|
+
window.removeEventListener("message", listener);
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
var element = ref.current;
|
|
66
|
+
if (!element || window.parent === window) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var post = function post() {
|
|
70
|
+
// The wrapper rather than the document: a layout that gives the body a
|
|
71
|
+
// `min-height: 100vh` makes the document exactly as tall as the frame,
|
|
72
|
+
// so measuring it could only ever confirm the frame's height and never
|
|
73
|
+
// shrink it. Down to the wrapper's bottom edge, plus the body's own
|
|
74
|
+
// margin below it, is everything the component takes up.
|
|
75
|
+
var height = element.getBoundingClientRect().bottom + window.scrollY + (parseFloat(getComputedStyle(document.body).marginBottom) || 0);
|
|
76
|
+
window.parent.postMessage({
|
|
77
|
+
type: VAL_PREVIEW_MESSAGES.size,
|
|
78
|
+
height: Math.ceil(height)
|
|
79
|
+
}, window.location.origin);
|
|
80
|
+
};
|
|
81
|
+
var observer = new ResizeObserver(post);
|
|
82
|
+
observer.observe(element);
|
|
83
|
+
post();
|
|
84
|
+
return function () {
|
|
85
|
+
observer.disconnect();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
useEffect(function () {
|
|
89
|
+
if (!picking || window.parent === window) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var hovered = null;
|
|
93
|
+
var setHovered = function setHovered(next) {
|
|
94
|
+
var _hovered, _hovered2;
|
|
95
|
+
(_hovered = hovered) === null || _hovered === void 0 || _hovered.removeAttribute(HOVER_ATTRIBUTE);
|
|
96
|
+
hovered = next;
|
|
97
|
+
(_hovered2 = hovered) === null || _hovered2 === void 0 || _hovered2.setAttribute(HOVER_ATTRIBUTE, "");
|
|
98
|
+
};
|
|
99
|
+
var taggedAt = function taggedAt(target) {
|
|
100
|
+
return target instanceof Element ? target.closest("[data-val-path]") : null;
|
|
101
|
+
};
|
|
102
|
+
var onOver = function onOver(event) {
|
|
103
|
+
return setHovered(taggedAt(event.target));
|
|
104
|
+
};
|
|
105
|
+
var onLeave = function onLeave() {
|
|
106
|
+
return setHovered(null);
|
|
107
|
+
};
|
|
108
|
+
// Capture, so the component's own handlers - a link, a button - never
|
|
109
|
+
// see a click that was a pick.
|
|
110
|
+
var onClick = function onClick(event) {
|
|
111
|
+
var _taggedAt;
|
|
112
|
+
var attribute = (_taggedAt = taggedAt(event.target)) === null || _taggedAt === void 0 ? void 0 : _taggedAt.getAttribute("data-val-path");
|
|
113
|
+
if (!attribute) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
window.parent.postMessage({
|
|
119
|
+
type: VAL_PREVIEW_MESSAGES.pick,
|
|
120
|
+
paths: Internal.splitJoinedSourcePaths(attribute)
|
|
121
|
+
}, window.location.origin);
|
|
122
|
+
};
|
|
123
|
+
document.addEventListener("mouseover", onOver);
|
|
124
|
+
document.documentElement.addEventListener("mouseleave", onLeave);
|
|
125
|
+
document.addEventListener("click", onClick, {
|
|
126
|
+
capture: true
|
|
127
|
+
});
|
|
128
|
+
return function () {
|
|
129
|
+
setHovered(null);
|
|
130
|
+
document.removeEventListener("mouseover", onOver);
|
|
131
|
+
document.documentElement.removeEventListener("mouseleave", onLeave);
|
|
132
|
+
document.removeEventListener("click", onClick, {
|
|
133
|
+
capture: true
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
}, [picking]);
|
|
137
|
+
|
|
138
|
+
// `flow-root` so the first and last child's margins stay inside the box
|
|
139
|
+
// being measured, rather than collapsing through it.
|
|
140
|
+
return /*#__PURE__*/jsxs("div", {
|
|
141
|
+
ref: ref,
|
|
142
|
+
style: {
|
|
143
|
+
display: "flow-root"
|
|
144
|
+
},
|
|
145
|
+
children: [picking &&
|
|
146
|
+
/*#__PURE__*/
|
|
147
|
+
// The canvas's outline colour, so a pick looks the same in both
|
|
148
|
+
jsx("style", {
|
|
149
|
+
children: "[".concat(HOVER_ATTRIBUTE, "] { outline: 2px solid ").concat(DEFAULT_CANVAS_SELECTION, "; outline-offset: 2px; cursor: pointer; }")
|
|
150
|
+
}), /*#__PURE__*/jsx(ValComponentControlsOff.Provider, {
|
|
151
|
+
value: true,
|
|
152
|
+
children: children
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { ValPreviewBridgeCore };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _slicedToArray } from './slicedToArray-b66ff800.browser.esm.js';
|
|
3
|
+
import { VAL_PREVIEW_MESSAGES, Internal } from '@valbuild/core';
|
|
4
|
+
import { DEFAULT_CANVAS_SELECTION } from '@valbuild/shared/client';
|
|
5
|
+
import { useRef, useState, useEffect } from 'react';
|
|
6
|
+
import { ValComponentControlsOff } from './ValComponentEditorChrome-bf2fefc6.browser.esm.js';
|
|
7
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
var HOVER_ATTRIBUTE = "data-val-preview-hover";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* EXPERIMENTAL: the preview route's side of its conversation with the Studio,
|
|
13
|
+
* without the framework. `@valbuild/next` and `@valbuild/tanstack` each wrap it
|
|
14
|
+
* with what a refresh means in their router.
|
|
15
|
+
*
|
|
16
|
+
* - **Refresh.** The Studio runs in the parent frame, so an edit is applied
|
|
17
|
+
* there and the preview has no way of knowing about it. The Studio posts a
|
|
18
|
+
* message, and this calls `onRefresh`, which reads the content again.
|
|
19
|
+
* - **Size.** The Studio cannot see into the frame to measure it, so this
|
|
20
|
+
* reports how tall the component is whenever that changes, and the Studio
|
|
21
|
+
* sizes the frame to fit.
|
|
22
|
+
* - **Pick.** Content read with stega carries its source path (Val tags the
|
|
23
|
+
* element with `data-val-path`), so a click on it says which field it came
|
|
24
|
+
* from. While the Studio has picking on - it is by default - a click on
|
|
25
|
+
* tagged content is sent to the Studio, which opens that field, instead of
|
|
26
|
+
* doing what it does on the site.
|
|
27
|
+
*/
|
|
28
|
+
function ValPreviewBridgeCore(_ref) {
|
|
29
|
+
var onRefresh = _ref.onRefresh,
|
|
30
|
+
children = _ref.children;
|
|
31
|
+
var ref = useRef(null);
|
|
32
|
+
// A ref, so a new `onRefresh` - a router can hand out a new one after every
|
|
33
|
+
// refresh - does not re-subscribe and announce `ready` all over again.
|
|
34
|
+
var onRefreshRef = useRef(onRefresh);
|
|
35
|
+
onRefreshRef.current = onRefresh;
|
|
36
|
+
// On until the Studio says otherwise: it says so as soon as it hears `ready`.
|
|
37
|
+
var _useState = useState(true),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
picking = _useState2[0],
|
|
40
|
+
setPicking = _useState2[1];
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
if (window.parent === window) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var listener = function listener(event) {
|
|
46
|
+
var _event$data, _event$data2;
|
|
47
|
+
if (event.origin !== window.location.origin) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === VAL_PREVIEW_MESSAGES.refresh) {
|
|
51
|
+
onRefreshRef.current();
|
|
52
|
+
} else if (((_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.type) === VAL_PREVIEW_MESSAGES.picking && typeof event.data.enabled === "boolean") {
|
|
53
|
+
setPicking(event.data.enabled);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("message", listener);
|
|
57
|
+
window.parent.postMessage({
|
|
58
|
+
type: VAL_PREVIEW_MESSAGES.ready
|
|
59
|
+
}, window.location.origin);
|
|
60
|
+
return function () {
|
|
61
|
+
window.removeEventListener("message", listener);
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
var element = ref.current;
|
|
66
|
+
if (!element || window.parent === window) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var post = function post() {
|
|
70
|
+
// The wrapper rather than the document: a layout that gives the body a
|
|
71
|
+
// `min-height: 100vh` makes the document exactly as tall as the frame,
|
|
72
|
+
// so measuring it could only ever confirm the frame's height and never
|
|
73
|
+
// shrink it. Down to the wrapper's bottom edge, plus the body's own
|
|
74
|
+
// margin below it, is everything the component takes up.
|
|
75
|
+
var height = element.getBoundingClientRect().bottom + window.scrollY + (parseFloat(getComputedStyle(document.body).marginBottom) || 0);
|
|
76
|
+
window.parent.postMessage({
|
|
77
|
+
type: VAL_PREVIEW_MESSAGES.size,
|
|
78
|
+
height: Math.ceil(height)
|
|
79
|
+
}, window.location.origin);
|
|
80
|
+
};
|
|
81
|
+
var observer = new ResizeObserver(post);
|
|
82
|
+
observer.observe(element);
|
|
83
|
+
post();
|
|
84
|
+
return function () {
|
|
85
|
+
observer.disconnect();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
useEffect(function () {
|
|
89
|
+
if (!picking || window.parent === window) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var hovered = null;
|
|
93
|
+
var setHovered = function setHovered(next) {
|
|
94
|
+
var _hovered, _hovered2;
|
|
95
|
+
(_hovered = hovered) === null || _hovered === void 0 || _hovered.removeAttribute(HOVER_ATTRIBUTE);
|
|
96
|
+
hovered = next;
|
|
97
|
+
(_hovered2 = hovered) === null || _hovered2 === void 0 || _hovered2.setAttribute(HOVER_ATTRIBUTE, "");
|
|
98
|
+
};
|
|
99
|
+
var taggedAt = function taggedAt(target) {
|
|
100
|
+
return target instanceof Element ? target.closest("[data-val-path]") : null;
|
|
101
|
+
};
|
|
102
|
+
var onOver = function onOver(event) {
|
|
103
|
+
return setHovered(taggedAt(event.target));
|
|
104
|
+
};
|
|
105
|
+
var onLeave = function onLeave() {
|
|
106
|
+
return setHovered(null);
|
|
107
|
+
};
|
|
108
|
+
// Capture, so the component's own handlers - a link, a button - never
|
|
109
|
+
// see a click that was a pick.
|
|
110
|
+
var onClick = function onClick(event) {
|
|
111
|
+
var _taggedAt;
|
|
112
|
+
var attribute = (_taggedAt = taggedAt(event.target)) === null || _taggedAt === void 0 ? void 0 : _taggedAt.getAttribute("data-val-path");
|
|
113
|
+
if (!attribute) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
window.parent.postMessage({
|
|
119
|
+
type: VAL_PREVIEW_MESSAGES.pick,
|
|
120
|
+
paths: Internal.splitJoinedSourcePaths(attribute)
|
|
121
|
+
}, window.location.origin);
|
|
122
|
+
};
|
|
123
|
+
document.addEventListener("mouseover", onOver);
|
|
124
|
+
document.documentElement.addEventListener("mouseleave", onLeave);
|
|
125
|
+
document.addEventListener("click", onClick, {
|
|
126
|
+
capture: true
|
|
127
|
+
});
|
|
128
|
+
return function () {
|
|
129
|
+
setHovered(null);
|
|
130
|
+
document.removeEventListener("mouseover", onOver);
|
|
131
|
+
document.documentElement.removeEventListener("mouseleave", onLeave);
|
|
132
|
+
document.removeEventListener("click", onClick, {
|
|
133
|
+
capture: true
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
}, [picking]);
|
|
137
|
+
|
|
138
|
+
// `flow-root` so the first and last child's margins stay inside the box
|
|
139
|
+
// being measured, rather than collapsing through it.
|
|
140
|
+
return /*#__PURE__*/jsxs("div", {
|
|
141
|
+
ref: ref,
|
|
142
|
+
style: {
|
|
143
|
+
display: "flow-root"
|
|
144
|
+
},
|
|
145
|
+
children: [picking &&
|
|
146
|
+
/*#__PURE__*/
|
|
147
|
+
// The canvas's outline colour, so a pick looks the same in both
|
|
148
|
+
jsx("style", {
|
|
149
|
+
children: "[".concat(HOVER_ATTRIBUTE, "] { outline: 2px solid ").concat(DEFAULT_CANVAS_SELECTION, "; outline-offset: 2px; cursor: pointer; }")
|
|
150
|
+
}), /*#__PURE__*/jsx(ValComponentControlsOff.Provider, {
|
|
151
|
+
value: true,
|
|
152
|
+
children: children
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { ValPreviewBridgeCore };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var slicedToArray = require('./slicedToArray-64c83d56.cjs.prod.js');
|
|
7
|
+
var core = require('@valbuild/core');
|
|
8
|
+
var client = require('@valbuild/shared/client');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var ValComponentEditorChrome = require('./ValComponentEditorChrome-c0b30556.cjs.prod.js');
|
|
11
|
+
var ReactJSXRuntime = require('react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
var HOVER_ATTRIBUTE = "data-val-preview-hover";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* EXPERIMENTAL: the preview route's side of its conversation with the Studio,
|
|
17
|
+
* without the framework. `@valbuild/next` and `@valbuild/tanstack` each wrap it
|
|
18
|
+
* with what a refresh means in their router.
|
|
19
|
+
*
|
|
20
|
+
* - **Refresh.** The Studio runs in the parent frame, so an edit is applied
|
|
21
|
+
* there and the preview has no way of knowing about it. The Studio posts a
|
|
22
|
+
* message, and this calls `onRefresh`, which reads the content again.
|
|
23
|
+
* - **Size.** The Studio cannot see into the frame to measure it, so this
|
|
24
|
+
* reports how tall the component is whenever that changes, and the Studio
|
|
25
|
+
* sizes the frame to fit.
|
|
26
|
+
* - **Pick.** Content read with stega carries its source path (Val tags the
|
|
27
|
+
* element with `data-val-path`), so a click on it says which field it came
|
|
28
|
+
* from. While the Studio has picking on - it is by default - a click on
|
|
29
|
+
* tagged content is sent to the Studio, which opens that field, instead of
|
|
30
|
+
* doing what it does on the site.
|
|
31
|
+
*/
|
|
32
|
+
function ValPreviewBridgeCore(_ref) {
|
|
33
|
+
var onRefresh = _ref.onRefresh,
|
|
34
|
+
children = _ref.children;
|
|
35
|
+
var ref = React.useRef(null);
|
|
36
|
+
// A ref, so a new `onRefresh` - a router can hand out a new one after every
|
|
37
|
+
// refresh - does not re-subscribe and announce `ready` all over again.
|
|
38
|
+
var onRefreshRef = React.useRef(onRefresh);
|
|
39
|
+
onRefreshRef.current = onRefresh;
|
|
40
|
+
// On until the Studio says otherwise: it says so as soon as it hears `ready`.
|
|
41
|
+
var _useState = React.useState(true),
|
|
42
|
+
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
|
43
|
+
picking = _useState2[0],
|
|
44
|
+
setPicking = _useState2[1];
|
|
45
|
+
React.useEffect(function () {
|
|
46
|
+
if (window.parent === window) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var listener = function listener(event) {
|
|
50
|
+
var _event$data, _event$data2;
|
|
51
|
+
if (event.origin !== window.location.origin) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === core.VAL_PREVIEW_MESSAGES.refresh) {
|
|
55
|
+
onRefreshRef.current();
|
|
56
|
+
} else if (((_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.type) === core.VAL_PREVIEW_MESSAGES.picking && typeof event.data.enabled === "boolean") {
|
|
57
|
+
setPicking(event.data.enabled);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener("message", listener);
|
|
61
|
+
window.parent.postMessage({
|
|
62
|
+
type: core.VAL_PREVIEW_MESSAGES.ready
|
|
63
|
+
}, window.location.origin);
|
|
64
|
+
return function () {
|
|
65
|
+
window.removeEventListener("message", listener);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
React.useEffect(function () {
|
|
69
|
+
var element = ref.current;
|
|
70
|
+
if (!element || window.parent === window) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var post = function post() {
|
|
74
|
+
// The wrapper rather than the document: a layout that gives the body a
|
|
75
|
+
// `min-height: 100vh` makes the document exactly as tall as the frame,
|
|
76
|
+
// so measuring it could only ever confirm the frame's height and never
|
|
77
|
+
// shrink it. Down to the wrapper's bottom edge, plus the body's own
|
|
78
|
+
// margin below it, is everything the component takes up.
|
|
79
|
+
var height = element.getBoundingClientRect().bottom + window.scrollY + (parseFloat(getComputedStyle(document.body).marginBottom) || 0);
|
|
80
|
+
window.parent.postMessage({
|
|
81
|
+
type: core.VAL_PREVIEW_MESSAGES.size,
|
|
82
|
+
height: Math.ceil(height)
|
|
83
|
+
}, window.location.origin);
|
|
84
|
+
};
|
|
85
|
+
var observer = new ResizeObserver(post);
|
|
86
|
+
observer.observe(element);
|
|
87
|
+
post();
|
|
88
|
+
return function () {
|
|
89
|
+
observer.disconnect();
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
React.useEffect(function () {
|
|
93
|
+
if (!picking || window.parent === window) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
var hovered = null;
|
|
97
|
+
var setHovered = function setHovered(next) {
|
|
98
|
+
var _hovered, _hovered2;
|
|
99
|
+
(_hovered = hovered) === null || _hovered === void 0 || _hovered.removeAttribute(HOVER_ATTRIBUTE);
|
|
100
|
+
hovered = next;
|
|
101
|
+
(_hovered2 = hovered) === null || _hovered2 === void 0 || _hovered2.setAttribute(HOVER_ATTRIBUTE, "");
|
|
102
|
+
};
|
|
103
|
+
var taggedAt = function taggedAt(target) {
|
|
104
|
+
return target instanceof Element ? target.closest("[data-val-path]") : null;
|
|
105
|
+
};
|
|
106
|
+
var onOver = function onOver(event) {
|
|
107
|
+
return setHovered(taggedAt(event.target));
|
|
108
|
+
};
|
|
109
|
+
var onLeave = function onLeave() {
|
|
110
|
+
return setHovered(null);
|
|
111
|
+
};
|
|
112
|
+
// Capture, so the component's own handlers - a link, a button - never
|
|
113
|
+
// see a click that was a pick.
|
|
114
|
+
var onClick = function onClick(event) {
|
|
115
|
+
var _taggedAt;
|
|
116
|
+
var attribute = (_taggedAt = taggedAt(event.target)) === null || _taggedAt === void 0 ? void 0 : _taggedAt.getAttribute("data-val-path");
|
|
117
|
+
if (!attribute) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
event.stopPropagation();
|
|
122
|
+
window.parent.postMessage({
|
|
123
|
+
type: core.VAL_PREVIEW_MESSAGES.pick,
|
|
124
|
+
paths: core.Internal.splitJoinedSourcePaths(attribute)
|
|
125
|
+
}, window.location.origin);
|
|
126
|
+
};
|
|
127
|
+
document.addEventListener("mouseover", onOver);
|
|
128
|
+
document.documentElement.addEventListener("mouseleave", onLeave);
|
|
129
|
+
document.addEventListener("click", onClick, {
|
|
130
|
+
capture: true
|
|
131
|
+
});
|
|
132
|
+
return function () {
|
|
133
|
+
setHovered(null);
|
|
134
|
+
document.removeEventListener("mouseover", onOver);
|
|
135
|
+
document.documentElement.removeEventListener("mouseleave", onLeave);
|
|
136
|
+
document.removeEventListener("click", onClick, {
|
|
137
|
+
capture: true
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}, [picking]);
|
|
141
|
+
|
|
142
|
+
// `flow-root` so the first and last child's margins stay inside the box
|
|
143
|
+
// being measured, rather than collapsing through it.
|
|
144
|
+
return /*#__PURE__*/ReactJSXRuntime.jsxs("div", {
|
|
145
|
+
ref: ref,
|
|
146
|
+
style: {
|
|
147
|
+
display: "flow-root"
|
|
148
|
+
},
|
|
149
|
+
children: [picking &&
|
|
150
|
+
/*#__PURE__*/
|
|
151
|
+
// The canvas's outline colour, so a pick looks the same in both
|
|
152
|
+
ReactJSXRuntime.jsx("style", {
|
|
153
|
+
children: "[".concat(HOVER_ATTRIBUTE, "] { outline: 2px solid ").concat(client.DEFAULT_CANVAS_SELECTION, "; outline-offset: 2px; cursor: pointer; }")
|
|
154
|
+
}), /*#__PURE__*/ReactJSXRuntime.jsx(ValComponentEditorChrome.ValComponentControlsOff.Provider, {
|
|
155
|
+
value: true,
|
|
156
|
+
children: children
|
|
157
|
+
})]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
exports.ValPreviewBridgeCore = ValPreviewBridgeCore;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var slicedToArray = require('./slicedToArray-387314c6.cjs.dev.js');
|
|
7
|
+
var core = require('@valbuild/core');
|
|
8
|
+
var client = require('@valbuild/shared/client');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var ValComponentEditorChrome = require('./ValComponentEditorChrome-440d086a.cjs.dev.js');
|
|
11
|
+
var ReactJSXRuntime = require('react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
var HOVER_ATTRIBUTE = "data-val-preview-hover";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* EXPERIMENTAL: the preview route's side of its conversation with the Studio,
|
|
17
|
+
* without the framework. `@valbuild/next` and `@valbuild/tanstack` each wrap it
|
|
18
|
+
* with what a refresh means in their router.
|
|
19
|
+
*
|
|
20
|
+
* - **Refresh.** The Studio runs in the parent frame, so an edit is applied
|
|
21
|
+
* there and the preview has no way of knowing about it. The Studio posts a
|
|
22
|
+
* message, and this calls `onRefresh`, which reads the content again.
|
|
23
|
+
* - **Size.** The Studio cannot see into the frame to measure it, so this
|
|
24
|
+
* reports how tall the component is whenever that changes, and the Studio
|
|
25
|
+
* sizes the frame to fit.
|
|
26
|
+
* - **Pick.** Content read with stega carries its source path (Val tags the
|
|
27
|
+
* element with `data-val-path`), so a click on it says which field it came
|
|
28
|
+
* from. While the Studio has picking on - it is by default - a click on
|
|
29
|
+
* tagged content is sent to the Studio, which opens that field, instead of
|
|
30
|
+
* doing what it does on the site.
|
|
31
|
+
*/
|
|
32
|
+
function ValPreviewBridgeCore(_ref) {
|
|
33
|
+
var onRefresh = _ref.onRefresh,
|
|
34
|
+
children = _ref.children;
|
|
35
|
+
var ref = React.useRef(null);
|
|
36
|
+
// A ref, so a new `onRefresh` - a router can hand out a new one after every
|
|
37
|
+
// refresh - does not re-subscribe and announce `ready` all over again.
|
|
38
|
+
var onRefreshRef = React.useRef(onRefresh);
|
|
39
|
+
onRefreshRef.current = onRefresh;
|
|
40
|
+
// On until the Studio says otherwise: it says so as soon as it hears `ready`.
|
|
41
|
+
var _useState = React.useState(true),
|
|
42
|
+
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
|
43
|
+
picking = _useState2[0],
|
|
44
|
+
setPicking = _useState2[1];
|
|
45
|
+
React.useEffect(function () {
|
|
46
|
+
if (window.parent === window) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var listener = function listener(event) {
|
|
50
|
+
var _event$data, _event$data2;
|
|
51
|
+
if (event.origin !== window.location.origin) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === core.VAL_PREVIEW_MESSAGES.refresh) {
|
|
55
|
+
onRefreshRef.current();
|
|
56
|
+
} else if (((_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.type) === core.VAL_PREVIEW_MESSAGES.picking && typeof event.data.enabled === "boolean") {
|
|
57
|
+
setPicking(event.data.enabled);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener("message", listener);
|
|
61
|
+
window.parent.postMessage({
|
|
62
|
+
type: core.VAL_PREVIEW_MESSAGES.ready
|
|
63
|
+
}, window.location.origin);
|
|
64
|
+
return function () {
|
|
65
|
+
window.removeEventListener("message", listener);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
React.useEffect(function () {
|
|
69
|
+
var element = ref.current;
|
|
70
|
+
if (!element || window.parent === window) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var post = function post() {
|
|
74
|
+
// The wrapper rather than the document: a layout that gives the body a
|
|
75
|
+
// `min-height: 100vh` makes the document exactly as tall as the frame,
|
|
76
|
+
// so measuring it could only ever confirm the frame's height and never
|
|
77
|
+
// shrink it. Down to the wrapper's bottom edge, plus the body's own
|
|
78
|
+
// margin below it, is everything the component takes up.
|
|
79
|
+
var height = element.getBoundingClientRect().bottom + window.scrollY + (parseFloat(getComputedStyle(document.body).marginBottom) || 0);
|
|
80
|
+
window.parent.postMessage({
|
|
81
|
+
type: core.VAL_PREVIEW_MESSAGES.size,
|
|
82
|
+
height: Math.ceil(height)
|
|
83
|
+
}, window.location.origin);
|
|
84
|
+
};
|
|
85
|
+
var observer = new ResizeObserver(post);
|
|
86
|
+
observer.observe(element);
|
|
87
|
+
post();
|
|
88
|
+
return function () {
|
|
89
|
+
observer.disconnect();
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
React.useEffect(function () {
|
|
93
|
+
if (!picking || window.parent === window) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
var hovered = null;
|
|
97
|
+
var setHovered = function setHovered(next) {
|
|
98
|
+
var _hovered, _hovered2;
|
|
99
|
+
(_hovered = hovered) === null || _hovered === void 0 || _hovered.removeAttribute(HOVER_ATTRIBUTE);
|
|
100
|
+
hovered = next;
|
|
101
|
+
(_hovered2 = hovered) === null || _hovered2 === void 0 || _hovered2.setAttribute(HOVER_ATTRIBUTE, "");
|
|
102
|
+
};
|
|
103
|
+
var taggedAt = function taggedAt(target) {
|
|
104
|
+
return target instanceof Element ? target.closest("[data-val-path]") : null;
|
|
105
|
+
};
|
|
106
|
+
var onOver = function onOver(event) {
|
|
107
|
+
return setHovered(taggedAt(event.target));
|
|
108
|
+
};
|
|
109
|
+
var onLeave = function onLeave() {
|
|
110
|
+
return setHovered(null);
|
|
111
|
+
};
|
|
112
|
+
// Capture, so the component's own handlers - a link, a button - never
|
|
113
|
+
// see a click that was a pick.
|
|
114
|
+
var onClick = function onClick(event) {
|
|
115
|
+
var _taggedAt;
|
|
116
|
+
var attribute = (_taggedAt = taggedAt(event.target)) === null || _taggedAt === void 0 ? void 0 : _taggedAt.getAttribute("data-val-path");
|
|
117
|
+
if (!attribute) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
event.stopPropagation();
|
|
122
|
+
window.parent.postMessage({
|
|
123
|
+
type: core.VAL_PREVIEW_MESSAGES.pick,
|
|
124
|
+
paths: core.Internal.splitJoinedSourcePaths(attribute)
|
|
125
|
+
}, window.location.origin);
|
|
126
|
+
};
|
|
127
|
+
document.addEventListener("mouseover", onOver);
|
|
128
|
+
document.documentElement.addEventListener("mouseleave", onLeave);
|
|
129
|
+
document.addEventListener("click", onClick, {
|
|
130
|
+
capture: true
|
|
131
|
+
});
|
|
132
|
+
return function () {
|
|
133
|
+
setHovered(null);
|
|
134
|
+
document.removeEventListener("mouseover", onOver);
|
|
135
|
+
document.documentElement.removeEventListener("mouseleave", onLeave);
|
|
136
|
+
document.removeEventListener("click", onClick, {
|
|
137
|
+
capture: true
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}, [picking]);
|
|
141
|
+
|
|
142
|
+
// `flow-root` so the first and last child's margins stay inside the box
|
|
143
|
+
// being measured, rather than collapsing through it.
|
|
144
|
+
return /*#__PURE__*/ReactJSXRuntime.jsxs("div", {
|
|
145
|
+
ref: ref,
|
|
146
|
+
style: {
|
|
147
|
+
display: "flow-root"
|
|
148
|
+
},
|
|
149
|
+
children: [picking &&
|
|
150
|
+
/*#__PURE__*/
|
|
151
|
+
// The canvas's outline colour, so a pick looks the same in both
|
|
152
|
+
ReactJSXRuntime.jsx("style", {
|
|
153
|
+
children: "[".concat(HOVER_ATTRIBUTE, "] { outline: 2px solid ").concat(client.DEFAULT_CANVAS_SELECTION, "; outline-offset: 2px; cursor: pointer; }")
|
|
154
|
+
}), /*#__PURE__*/ReactJSXRuntime.jsx(ValComponentEditorChrome.ValComponentControlsOff.Provider, {
|
|
155
|
+
value: true,
|
|
156
|
+
children: children
|
|
157
|
+
})]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
exports.ValPreviewBridgeCore = ValPreviewBridgeCore;
|