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