@decocms/start 0.27.0 → 0.27.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.
- package/package.json +1 -1
- package/src/hooks/LiveControls.tsx +16 -2
package/package.json
CHANGED
|
@@ -39,10 +39,19 @@ function LiveControlsScript() {
|
|
|
39
39
|
if (window.__DECO_LIVE_CONTROLS__) return;
|
|
40
40
|
window.__DECO_LIVE_CONTROLS__ = true;
|
|
41
41
|
|
|
42
|
+
var TRUSTED_ORIGINS = ["https://deco.cx", "https://admin.deco.cx", "https://play.deco.cx"];
|
|
43
|
+
function isTrustedOrigin(origin) {
|
|
44
|
+
return TRUSTED_ORIGINS.indexOf(origin) !== -1 ||
|
|
45
|
+
(origin.startsWith("https://") && origin.endsWith(".deco.cx")) ||
|
|
46
|
+
origin === window.location.origin;
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
var LIVE = JSON.parse(document.getElementById("__DECO_STATE")?.textContent || "{}");
|
|
43
50
|
window.LIVE = { ...window.LIVE, ...LIVE };
|
|
44
51
|
|
|
45
52
|
window.addEventListener("message", function(event) {
|
|
53
|
+
if (!isTrustedOrigin(event.origin)) return;
|
|
54
|
+
|
|
46
55
|
var data = event.data;
|
|
47
56
|
if (!data || typeof data !== "object") return;
|
|
48
57
|
|
|
@@ -54,7 +63,7 @@ function LiveControlsScript() {
|
|
|
54
63
|
break;
|
|
55
64
|
|
|
56
65
|
case "scrollToComponent":
|
|
57
|
-
var el = document.querySelector('[data-manifest-key="' + data.args?.id + '"]');
|
|
66
|
+
var el = document.querySelector('[data-manifest-key="' + CSS.escape(data.args?.id || "") + '"]');
|
|
58
67
|
if (!el) el = document.getElementById(data.args?.id);
|
|
59
68
|
if (el) el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
60
69
|
break;
|
|
@@ -64,7 +73,12 @@ function LiveControlsScript() {
|
|
|
64
73
|
|
|
65
74
|
case "editor::rerender":
|
|
66
75
|
if (data.args?.url) {
|
|
67
|
-
|
|
76
|
+
try {
|
|
77
|
+
var targetUrl = new URL(data.args.url, window.location.origin);
|
|
78
|
+
if (targetUrl.origin === window.location.origin) {
|
|
79
|
+
window.location.href = targetUrl.href;
|
|
80
|
+
}
|
|
81
|
+
} catch(e) {}
|
|
68
82
|
}
|
|
69
83
|
break;
|
|
70
84
|
}
|