@websline/cms-view-utils 1.0.0-alpha.5 → 1.0.0

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
- (()=>{(function(){var c;if(typeof window>"u")return;let u=150,a=60,t=document.currentScript||[...document.querySelectorAll("script[data-slug]")].pop(),n=(c=t==null?void 0:t.dataset)==null?void 0:c.slug;if(!n){console.warn("[editScroll] Missing data-slug");return}let s=`preview-scroll:${n}`,r=null,l=0,i=()=>{let e=window.scrollY;e!==l&&(l=e,sessionStorage.setItem(s,String(e)))},d=()=>{clearTimeout(r),r=setTimeout(i,u)},w=()=>{let e=sessionStorage.getItem(s);if(!e)return;let o=Number(e);Number.isNaN(o)||requestAnimationFrame(()=>{window.scrollTo(0,o),setTimeout(()=>{window.scrollTo(0,o)},a)})};window.addEventListener("scroll",d,{passive:!0}),window.addEventListener("beforeunload",i),window.addEventListener("load",w)})();})();
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 e={BLOCK_ADD:"BLOCK_ADD",BLOCK_DELETE:"BLOCK_DELETE",BLOCK_EDIT:"BLOCK_EDIT",BLOCK_POSITION:"BLOCK_POSITION",BLOCK_SHOW:"BLOCK_SHOW",BLOCK_HIDE:"BLOCK_HIDE",SLUG_CHANGED:"SLUG_CHANGED",SLUG_ON_LOAD:"SLUG_ON_LOAD",IFRAME_DOM_LOADED:"IFRAME_DOM_LOADED",CURRENT_BLOCK_EDIT:"CURRENT_BLOCK_EDIT",SCROLL_TO_BLOCK:"SCROLL_TO_BLOCK"},_=(r,L={})=>{r&&window.parent!==window&&window.parent.postMessage({type:r,payload:L},"*")};(function(){if(window.parent===window||window.__PREVIEW_BRIDGE_INITIALIZED__)return;window.__PREVIEW_BRIDGE_INITIALIZED__=!0;let r=t=>t.metaKey||t.ctrlKey||t.shiftKey,L=t=>{let n=t.target.closest("a[href]");if(!n||n.target==="_blank"||r(t))return;let o=new URL(n.href,window.location.origin);o.origin===window.location.origin&&(t.preventDefault(),t.stopPropagation(),_(e.SLUG_CHANGED,{slug:o.pathname}))};document.addEventListener("click",L,!0),_(e.SLUG_ON_LOAD,{slug:window.location.pathname}),window.addEventListener("load",()=>{_(e.IFRAME_DOM_LOADED)});let E=t=>{let n=`[data-cms-block-id="${t}"]`,o=0,i=10,O=setInterval(()=>{let a=document.querySelector(n);a&&(a.scrollIntoView({behavior:"smooth",block:"center"}),clearInterval(O)),++o>=i&&clearInterval(O)},100)};window.addEventListener("message",t=>{let{type:n,payload:o}=t.data||{};if(n&&n===e.SCROLL_TO_BLOCK){let{draftBlockUuid:i}=o||{};if(!i)return;E(i)}})})();})();
1
+ (()=>{var e={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"},_=(r,a={})=>{r&&window.parent!==window&&window.parent.postMessage({type:r,payload:a},"*")};(function(){if(window.parent===window||window.__PREVIEW_BRIDGE_INITIALIZED__)return;window.__PREVIEW_BRIDGE_INITIALIZED__=!0;let r=t=>t.metaKey||t.ctrlKey||t.shiftKey,a=t=>{let n=t.target.closest("a[href]");if(!n||n.target==="_blank"||r(t))return;let o=new URL(n.href,window.location.origin);o.origin===window.location.origin&&(t.preventDefault(),t.stopPropagation(),_(e.PATH_CHANGED,{path:o.pathname}))};document.addEventListener("click",a,!0),_(e.PATH_ON_LOAD,{path:window.location.pathname}),window.addEventListener("load",()=>{_(e.IFRAME_DOM_LOADED)});let L=t=>{let n=`[data-cms-block-id="${t}"]`,o=0,i=10,O=setInterval(()=>{let E=document.querySelector(n);E&&(E.scrollIntoView({behavior:"smooth",block:"center"}),clearInterval(O)),++o>=i&&clearInterval(O)},100)};window.addEventListener("message",t=>{let{type:n,payload:o}=t.data||{};if(n&&n===e.SCROLL_TO_BLOCK){let{draftBlockUuid:i}=o||{};if(!i)return;L(i)}})})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/cms-view-utils",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -6,16 +6,16 @@
6
6
 
7
7
  const script =
8
8
  document.currentScript ||
9
- [...document.querySelectorAll("script[data-slug]")].pop();
9
+ [...document.querySelectorAll("script[data-path]")].pop();
10
10
 
11
- const slug = script?.dataset?.slug;
11
+ const path = script?.dataset?.path;
12
12
 
13
- if (!slug) {
14
- console.warn("[editScroll] Missing data-slug");
13
+ if (!path) {
14
+ console.warn("[editScroll] Missing data-path");
15
15
  return;
16
16
  }
17
17
 
18
- const storageKey = `preview-scroll:${slug}`;
18
+ const storageKey = `preview-scroll:${path}`;
19
19
 
20
20
  let timeout = null;
21
21
  let lastY = 0;
@@ -4,20 +4,21 @@ import { buildCmsHeaders } from "./headers.js";
4
4
  import { HttpError } from "./errors.js";
5
5
 
6
6
  const fetchPage = async (context) => {
7
- let { slug = "" } = context.params;
7
+ let { path = "" } = context.params;
8
+
8
9
  const request = context.request;
9
10
  const url = new URL(request.url);
10
11
  const isCMSPreviewRoute = url.pathname.startsWith("/preview_");
11
12
 
12
13
  if (isCMSPreviewRoute) {
13
- slug = slug.replace(/^preview_/, "");
14
+ path = path.replace(/^preview_/, "");
14
15
  }
15
16
 
16
17
  const editorToken = url.searchParams.get("editorToken");
17
18
  const draftUuid = resolveDraftUuidFromToken(editorToken);
18
19
  const isCMSEditRoute = editorToken && draftUuid;
19
20
 
20
- const cmsUrl = buildCmsPageUrl({ slug, draftUuid });
21
+ const cmsUrl = buildCmsPageUrl({ draftUuid, path });
21
22
 
22
23
  const response = await fetch(cmsUrl, {
23
24
  method: "GET",
@@ -5,8 +5,8 @@ const EVENTS = {
5
5
  BLOCK_POSITION: "BLOCK_POSITION",
6
6
  BLOCK_SHOW: "BLOCK_SHOW",
7
7
  BLOCK_HIDE: "BLOCK_HIDE",
8
- SLUG_CHANGED: "SLUG_CHANGED",
9
- SLUG_ON_LOAD: "SLUG_ON_LOAD",
8
+ PATH_CHANGED: "PATH_CHANGED",
9
+ PATH_ON_LOAD: "PATH_ON_LOAD",
10
10
  IFRAME_DOM_LOADED: "IFRAME_DOM_LOADED",
11
11
  CURRENT_BLOCK_EDIT: "CURRENT_BLOCK_EDIT",
12
12
  SCROLL_TO_BLOCK: "SCROLL_TO_BLOCK",
@@ -21,15 +21,15 @@ import { EVENTS, notifyCMS } from "./notify.js";
21
21
  event.preventDefault();
22
22
  event.stopPropagation();
23
23
 
24
- notifyCMS(EVENTS.SLUG_CHANGED, {
25
- slug: url.pathname,
24
+ notifyCMS(EVENTS.PATH_CHANGED, {
25
+ path: url.pathname,
26
26
  });
27
27
  };
28
28
 
29
29
  document.addEventListener("click", handleClick, true);
30
30
 
31
- notifyCMS(EVENTS.SLUG_ON_LOAD, {
32
- slug: window.location.pathname,
31
+ notifyCMS(EVENTS.PATH_ON_LOAD, {
32
+ path: window.location.pathname,
33
33
  });
34
34
 
35
35
  window.addEventListener("load", () => {
@@ -1,13 +1,13 @@
1
- const buildCmsPageUrl = ({ slug, draftUuid }) => {
1
+ const buildCmsPageUrl = ({ draftUuid, path }) => {
2
2
  const base = import.meta.env.CMS_URL;
3
3
 
4
4
  if (draftUuid) {
5
5
  return `${base}/api/public/pages/preview/${draftUuid}`;
6
6
  }
7
7
 
8
- const normalizedSlug = slug.startsWith("/") ? slug : `/${slug}`;
8
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
9
9
 
10
- return `${base}/api/public/pages${normalizedSlug}`;
10
+ return `${base}/api/public/pages${normalizedPath}`;
11
11
  };
12
12
 
13
13
  export { buildCmsPageUrl };