@websline/cms-view-utils 1.5.0 → 1.5.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/dist/editScroll.global.js +1 -1
- package/dist/previewBridge.global.js +1 -1
- package/package.json +1 -1
- package/src/cms/fetchPage.js +1 -0
- package/src/components/EditableBlock.svelte +17 -2
- package/src/editor/editScroll.js +3 -20
- package/src/editor/previewBridge.js +12 -0
- package/src/editor/scrollStore.js +7 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{(function(){var
|
|
1
|
+
(()=>{var l=t=>`preview-scroll:${t}`;(function(){var s;if(typeof window>"u")return;let t=150,e=document.currentScript||[...document.querySelectorAll("script[data-path]")].pop(),r=(s=e==null?void 0:e.dataset)==null?void 0:s.path;if(!r){console.warn("[editScroll] Missing data-path");return}let c=l(r),n=null,a=0,i=()=>{let o=window.scrollY;o!==a&&(a=o,sessionStorage.setItem(c,String(o)))},p=()=>{clearTimeout(n),n=setTimeout(i,t)};window.addEventListener("scroll",p,{passive:!0})})();})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var i={BLOCK_ADD:"BLOCK_ADD",BLOCK_DELETE:"BLOCK_DELETE",BLOCK_EDIT:"BLOCK_EDIT",BLOCK_POSITION:"BLOCK_POSITION",BLOCK_SHOW:"BLOCK_SHOW",BLOCK_HIDE:"BLOCK_HIDE",PATH_CHANGED:"PATH_CHANGED",PATH_ON_LOAD:"PATH_ON_LOAD",IFRAME_DOM_LOADED:"IFRAME_DOM_LOADED",CURRENT_BLOCK_EDIT:"CURRENT_BLOCK_EDIT",SCROLL_TO_BLOCK:"SCROLL_TO_BLOCK"},s=(r,e={})=>{r&&window.parent!==window&&window.parent.postMessage({type:r,payload:e},"*")};var l=r=>`preview-scroll:${r}`,O=()=>{var r,e;return((e=(r=[...document.querySelectorAll("script[data-path]")].pop())==null?void 0:r.dataset)==null?void 0:e.path)||window.location.pathname};(function(){if(window.parent===window||window.__PREVIEW_BRIDGE_INITIALIZED__)return;window.__PREVIEW_BRIDGE_INITIALIZED__=!0;let r=t=>t.metaKey||t.ctrlKey||t.shiftKey,e=t=>{let o=t.target.closest("a[href]");if(!o||o.target==="_blank"||r(t))return;let n=new URL(o.href,window.location.origin);n.origin===window.location.origin&&(t.preventDefault(),t.stopPropagation(),s(i.PATH_CHANGED,{path:n.pathname}))};document.addEventListener("click",e,!0),s(i.PATH_ON_LOAD,{path:window.location.pathname});let E=()=>{let t=sessionStorage.getItem(l(O()));if(!t)return;let o=Number(t);Number.isNaN(o)||window.scrollTo({top:o,left:0,behavior:"instant"})};window.addEventListener("load",()=>{E(),s(i.IFRAME_DOM_LOADED)});let L=t=>{let o=`[data-cms-block-id="${t}"]`,n=0,a=10,_=setInterval(()=>{let c=document.querySelector(o);c&&(c.scrollIntoView({behavior:"smooth",block:"start"}),clearInterval(_)),++n>=a&&clearInterval(_)},100)};window.addEventListener("message",t=>{let{type:o,payload:n}=t.data||{};if(o&&o===i.SCROLL_TO_BLOCK){let{draftBlockUuid:a}=n||{};if(!a)return;L(a)}})})();})();
|
package/package.json
CHANGED
package/src/cms/fetchPage.js
CHANGED
|
@@ -40,6 +40,7 @@ const fetchPage = async (context) => {
|
|
|
40
40
|
context.locals.page = data?.page ?? {};
|
|
41
41
|
context.locals.seo = data?.seo ?? {};
|
|
42
42
|
context.locals.languageSwitcher = data?.languageSwitcher ?? [];
|
|
43
|
+
context.locals.tenant = data?.tenant ?? null;
|
|
43
44
|
context.locals._cmsRaw = data;
|
|
44
45
|
|
|
45
46
|
if (isCMSPreviewRoute) {
|
|
@@ -126,13 +126,28 @@
|
|
|
126
126
|
isHovered = true;
|
|
127
127
|
}, 50);
|
|
128
128
|
|
|
129
|
+
const isRefInViewport = () => {
|
|
130
|
+
if (!ref) return true;
|
|
131
|
+
|
|
132
|
+
const { top, bottom } = ref.getBoundingClientRect();
|
|
133
|
+
const viewportHeight =
|
|
134
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
135
|
+
|
|
136
|
+
return bottom > 0 && top < viewportHeight;
|
|
137
|
+
};
|
|
138
|
+
|
|
129
139
|
const handler = (event) => {
|
|
130
140
|
const { type, payload } = event.data || {};
|
|
131
141
|
if (type !== EVENTS.CURRENT_BLOCK_EDIT) return;
|
|
132
142
|
|
|
133
|
-
const { draftBlockUuid } = payload || {};
|
|
143
|
+
const { draftBlockUuid, scroll } = payload || {};
|
|
144
|
+
const becameActive = draftBlockUuid === block.uuid;
|
|
145
|
+
|
|
146
|
+
isActive = becameActive;
|
|
134
147
|
|
|
135
|
-
|
|
148
|
+
if (becameActive && scroll && !isRefInViewport()) {
|
|
149
|
+
ref.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
150
|
+
}
|
|
136
151
|
};
|
|
137
152
|
|
|
138
153
|
let isOutside = $derived(calcBarPosition === "outside");
|
package/src/editor/editScroll.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { storageKeyForPath } from "./scrollStore.js";
|
|
2
|
+
|
|
1
3
|
(function () {
|
|
2
4
|
if (typeof window === "undefined") return;
|
|
3
5
|
|
|
4
6
|
const DEBOUNCE_MS = 150;
|
|
5
|
-
const RESTORE_DELAY = 60;
|
|
6
7
|
|
|
7
8
|
const script =
|
|
8
9
|
document.currentScript ||
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const storageKey =
|
|
19
|
+
const storageKey = storageKeyForPath(path);
|
|
19
20
|
|
|
20
21
|
let timeout = null;
|
|
21
22
|
let lastY = 0;
|
|
@@ -33,23 +34,5 @@
|
|
|
33
34
|
timeout = setTimeout(saveScroll, DEBOUNCE_MS);
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
const restoreScroll = () => {
|
|
37
|
-
const raw = sessionStorage.getItem(storageKey);
|
|
38
|
-
if (!raw) return;
|
|
39
|
-
|
|
40
|
-
const y = Number(raw);
|
|
41
|
-
if (Number.isNaN(y)) return;
|
|
42
|
-
|
|
43
|
-
requestAnimationFrame(() => {
|
|
44
|
-
window.scrollTo(0, y);
|
|
45
|
-
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
window.scrollTo(0, y);
|
|
48
|
-
}, RESTORE_DELAY);
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
37
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
53
|
-
window.addEventListener("beforeunload", saveScroll);
|
|
54
|
-
window.addEventListener("load", restoreScroll);
|
|
55
38
|
})();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EVENTS, notifyCMS } from "./notify.js";
|
|
2
|
+
import { resolveScrollPath, storageKeyForPath } from "./scrollStore.js";
|
|
2
3
|
|
|
3
4
|
(function () {
|
|
4
5
|
if (window.parent === window) return;
|
|
@@ -32,7 +33,18 @@ import { EVENTS, notifyCMS } from "./notify.js";
|
|
|
32
33
|
path: window.location.pathname,
|
|
33
34
|
});
|
|
34
35
|
|
|
36
|
+
const restoreScroll = () => {
|
|
37
|
+
const raw = sessionStorage.getItem(storageKeyForPath(resolveScrollPath()));
|
|
38
|
+
if (!raw) return;
|
|
39
|
+
|
|
40
|
+
const y = Number(raw);
|
|
41
|
+
if (Number.isNaN(y)) return;
|
|
42
|
+
|
|
43
|
+
window.scrollTo({ top: y, left: 0, behavior: "instant" });
|
|
44
|
+
};
|
|
45
|
+
|
|
35
46
|
window.addEventListener("load", () => {
|
|
47
|
+
restoreScroll();
|
|
36
48
|
notifyCMS(EVENTS.IFRAME_DOM_LOADED);
|
|
37
49
|
});
|
|
38
50
|
|