@obelism/content 0.28.2 → 0.28.4
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/README.md +7 -4
- package/dist/bridge.d.mts +3 -2
- package/dist/bridge.d.mts.map +1 -1
- package/dist/bridge.d.ts +3 -2
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.global.js +4 -4
- package/dist/bridge.js +448 -373
- package/dist/bridge.mjs +449 -374
- package/dist/index.mjs +1 -1
- package/dist/{preview-el7sfk3h.mjs → preview-9qff497d.mjs} +1 -1
- package/dist/site-j5kqgtj3.js +368 -0
- package/dist/site-m85jdjid.mjs +360 -0
- package/dist/site.js +10 -340
- package/dist/site.mjs +2 -336
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -381,10 +381,13 @@ how often each block is clicked on the page itself: a label on a block
|
|
|
381
381
|
("24% clicked"), and a little tag on the corner of each tagged link or
|
|
382
382
|
button — a cross before its first click, an hourglass while fewer than 20
|
|
383
383
|
visitors saw its page, then its rate ("24%"). In the visual editor the
|
|
384
|
-
**Show click rates on the page** switch turns them on and off.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
384
|
+
**Show click rates on the page** switch turns them on and off. The on-site
|
|
385
|
+
editor shows a rate once its block is selected (or, outside the blocks, its
|
|
386
|
+
element clicked) and keeps it while the page is open, so a few can be
|
|
387
|
+
compared. Clicking one selects its block. The rates come from Obelism
|
|
388
|
+
Numbers over the last 30 days, so tag a block's clickable element with its
|
|
389
|
+
uid and load Numbers' script on the site (see the CMS's visual editor
|
|
390
|
+
guide, "Click rates"):
|
|
388
391
|
|
|
389
392
|
```tsx
|
|
390
393
|
<a href={block.link} data-numbers-id={block._uid}>
|
package/dist/bridge.d.mts
CHANGED
|
@@ -19,10 +19,11 @@ type StatsOverlay = {
|
|
|
19
19
|
refresh(): void;
|
|
20
20
|
destroy(): void;
|
|
21
21
|
};
|
|
22
|
-
declare const mountStatsOverlay: (win: Window, { selector, onSelect, checked, labels: labelOverrides, }: {
|
|
22
|
+
declare const mountStatsOverlay: (win: Window, { selector, onSelect, checked, shows, labels: labelOverrides, }: {
|
|
23
23
|
selector: (uid: string) => string;
|
|
24
24
|
onSelect: (uid: string) => void;
|
|
25
25
|
checked?: ((id: string) => boolean) | undefined;
|
|
26
|
+
shows?: ((id: string, element: Element) => boolean) | undefined;
|
|
26
27
|
labels?: Partial<StatsLabels> | undefined;
|
|
27
28
|
}) => StatsOverlay;
|
|
28
29
|
|
|
@@ -50,6 +51,7 @@ type BridgeState = {
|
|
|
50
51
|
stats: Readonly<Record<string, BlockStats>>;
|
|
51
52
|
statsVisible: boolean;
|
|
52
53
|
};
|
|
54
|
+
declare const INITIAL_STATE: BridgeState;
|
|
53
55
|
type PromptResult = {
|
|
54
56
|
summary: string;
|
|
55
57
|
};
|
|
@@ -120,7 +122,6 @@ type ContentBridge = {
|
|
|
120
122
|
select(uid: string | null): void;
|
|
121
123
|
destroy(): void;
|
|
122
124
|
};
|
|
123
|
-
declare const INITIAL_STATE: BridgeState;
|
|
124
125
|
|
|
125
126
|
type SharedLabels = {
|
|
126
127
|
open: string;
|
package/dist/bridge.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.mts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/contract.ts","../src/bridge/labels.ts","../src/bridge/promptBox.ts","../src/bridge/siteEditor.ts","../src/bridge.ts"],"mappings":"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","names":[]}
|
package/dist/bridge.d.ts
CHANGED
|
@@ -19,10 +19,11 @@ type StatsOverlay = {
|
|
|
19
19
|
refresh(): void;
|
|
20
20
|
destroy(): void;
|
|
21
21
|
};
|
|
22
|
-
declare const mountStatsOverlay: (win: Window, { selector, onSelect, checked, labels: labelOverrides, }: {
|
|
22
|
+
declare const mountStatsOverlay: (win: Window, { selector, onSelect, checked, shows, labels: labelOverrides, }: {
|
|
23
23
|
selector: (uid: string) => string;
|
|
24
24
|
onSelect: (uid: string) => void;
|
|
25
25
|
checked?: ((id: string) => boolean) | undefined;
|
|
26
|
+
shows?: ((id: string, element: Element) => boolean) | undefined;
|
|
26
27
|
labels?: Partial<StatsLabels> | undefined;
|
|
27
28
|
}) => StatsOverlay;
|
|
28
29
|
|
|
@@ -50,6 +51,7 @@ type BridgeState = {
|
|
|
50
51
|
stats: Readonly<Record<string, BlockStats>>;
|
|
51
52
|
statsVisible: boolean;
|
|
52
53
|
};
|
|
54
|
+
declare const INITIAL_STATE: BridgeState;
|
|
53
55
|
type PromptResult = {
|
|
54
56
|
summary: string;
|
|
55
57
|
};
|
|
@@ -120,7 +122,6 @@ type ContentBridge = {
|
|
|
120
122
|
select(uid: string | null): void;
|
|
121
123
|
destroy(): void;
|
|
122
124
|
};
|
|
123
|
-
declare const INITIAL_STATE: BridgeState;
|
|
124
125
|
|
|
125
126
|
type SharedLabels = {
|
|
126
127
|
open: string;
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/contract.ts","../src/bridge/labels.ts","../src/bridge/promptBox.ts","../src/bridge/siteEditor.ts","../src/bridge.ts"],"mappings":"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","names":[]}
|
package/dist/bridge.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!/*! Obelism Content bridge (@obelism/content), MIT. https://content.obelism.studio/docs/guides/canvas */function(){"use strict";var e;let t="data-cms-uid",r="data-cms-entry",n="data-cms-
|
|
1
|
+
!/*! Obelism Content bridge (@obelism/content), MIT. https://content.obelism.studio/docs/guides/canvas */function(){"use strict";var e;let t="data-cms-uid",r="data-cms-entry",n="obelism-content-bridge",a={features:[],selectedUid:null,prompting:!1,canUndo:!1,unsaved:!1,saving:!1,publishing:!1,selecting:!1,stats:{},statsVisible:!1},i="#d58a1f",o=(e="")=>`${e}[${t}]{cursor:pointer;transition:outline-color .15s}${e}[${t}]:hover{outline:2px dashed ${i};outline-offset:2px}${e}[${t}][data-cms-selected]{outline:2px solid ${i};outline-offset:2px}`,s=e=>`[${t}="${e.replace(/["\\]/g,"\\$&")}"]`,l=()=>{let e={update:new Set,saved:new Set,published:new Set,change:new Set};return{listeners:e,on:(t,r)=>(e[t].add(r),()=>{e[t].delete(r)}),emit(t,r){for(let n of e[t])try{n(r)}catch(e){console.error("[@obelism/content bridge]",e)}}}},d=(e=a)=>{let t=l(),r=e;return{...t,getState:()=>r,setState(e){r={...r,...e},t.emit("change",r)}}},p=(e,t,r=!1)=>{for(let t of e.querySelectorAll("[data-cms-selected]"))t.removeAttribute("data-cms-selected");let n=t?e.querySelector(s(t)):null;n&&(n.setAttribute("data-cms-selected",""),r&&n.scrollIntoView({behavior:"smooth",block:"center"}))},c=e=>{let t=null;return{update(r,n){(t||0!==Object.keys(r).length)&&(t??(t=e()),t.update(r,n))},refresh:()=>t?.refresh(),destroy:()=>t?.destroy()}},u=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0,g=e=>{if(!e||"object"!=typeof e||Array.isArray(e))return{};let t={};for(let[r,n]of Object.entries(e)){let{clicks:e,clickers:a,viewers:i,rate:o}=n??{};u(e)&&u(a)&&u(i)&&u(o)&&(t[r]={clicks:e,clickers:a,viewers:i,rate:o})}return t},h=()=>Promise.reject(Error("Save and publish in the visual editor itself")),b=()=>Promise.reject(Error("Only while signed in to edit on the site")),m={prompt:()=>Promise.reject(Error("Prompts only work inside the visual editor")),createPage:()=>Promise.reject(Error("New pages are made on the site itself")),createProductPage:()=>Promise.reject(Error("Product pages are made on the site itself")),createCollectionPage:()=>Promise.reject(Error("Collection pages are made on the site itself")),view:b,applyJson:b,openForm:(e,t={})=>(queueMicrotask(()=>t.onError?.("Only while signed in to edit on the site")),{close:()=>{}}),pages:b,openPage:()=>{},undo:()=>{},save:h,publish:h,signOut:()=>{},select:()=>{},setSelecting:()=>{}},f=()=>({isEditing:!1,mode:null,entryId:null,environment:null,product:null,collection:null,on:l().on,getState:()=>a,...m,destroy:()=>{}}),v="cms_environment",x={clicked:"{rate}% clicked",clickedShort:"{rate}%",title:"{clickers} of {viewers} visitors of its page clicked it in the last 30 days ({clicks} clicks)",noClicks:"No clicks yet in the last 30 days",counting:"{clicks} clicks so far: a click rate once {needed} visitors saw its page ({viewers} yet)"},y="data-numbers-id",w={none:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',counting:'<path d="M5 22h14"/><path d="M5 2h14"/><path d="M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22"/><path d="M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2"/>'},k=(e,t)=>e.replace(/\{(\w+)\}/g,(e,r)=>r in t?String(t[r]):e),E=`
|
|
2
2
|
:host { all: initial; }
|
|
3
3
|
.layer {
|
|
4
4
|
position: fixed; inset: 0; pointer-events: none;
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
width: 12px; height: 12px; fill: none; stroke: currentColor;
|
|
38
38
|
stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
|
|
39
39
|
}
|
|
40
|
-
`,c=(e,{selector:r,onSelect:n,checked:a,labels:i})=>{let c=e.document,u={...o,...i},g=c.createElement("div");g.setAttribute("data-obelism-stats","");let h=g.attachShadow({mode:"open"}),b=c.createElement("style");b.textContent=p;let m=c.createElement("div");m.className="layer",h.append(b,m),c.body.appendChild(g);let f={},v=!1,x=null,y=(r,a,i)=>{let o,s=a.getBoundingClientRect();if(!s.width&&!s.height||s.bottom<0||s.top>e.innerHeight)return;let p=f[r],g=p&&0!==p.clicks?p.viewers<20?"counting":"rate":"none",h=c.createElement("button");h.type="button",h.dataset.uid=r,h.dataset.status=g;let b=p?Math.round(100*p.rate):0;h.title="rate"===g?d(u.title,{clickers:p.clickers,viewers:p.viewers,clicks:p.clicks}):"none"===g?u.noClicks:d(u.counting,{clicks:p.clicks,viewers:p.viewers,needed:20});let{top:v,left:x}="rate"===g&&s.height>=64?{top:Math.max(s.top,0)+8,left:s.right-8}:(o={width:e.innerWidth,height:e.innerHeight},{top:Math.min(Math.max(s.top,10),o.height-10),left:Math.min(s.right,o.width-10)});"rate"===g&&s.height>=64?(h.className="badge",h.textContent=d(u.clicked,{rate:b})):(h.className="tag","rate"===g?h.textContent=d(u.clickedShort,{rate:b}):h.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true">${l[g]}</svg>`,h.setAttribute("aria-label",h.title)),h.style.top=`${v}px`,h.style.left=`${x}px`;let y=i.has(r)?r:a.closest(`[${t}]`)?.getAttribute(t);y&&h.addEventListener("click",()=>n(y)),m.appendChild(h)},w=()=>{if(x=null,m.replaceChildren(),m.hidden=!v,!v)return;let e=new Set;for(let r of c.querySelectorAll(`[${t}]`))e.add(r.getAttribute(t)??"");let n=a??(t=>e.has(t)),i=new Set;for(let t of c.querySelectorAll(`[${s}]`)){let r=t.getAttribute(s);r&&(f[r]||n(r))&&(i.add(r),y(r,t,e))}for(let t of Object.keys(f)){if(i.has(t)||!e.has(t))continue;let n=c.querySelector(r(t));n&&y(t,n,e)}},k=()=>{null===x&&v&&(x=e.requestAnimationFrame(w))};e.addEventListener("scroll",k,{capture:!0,passive:!0}),e.addEventListener("resize",k);let E=e.MutationObserver,C="function"==typeof E?new E(k):null;return C?.observe(c.body,{childList:!0,subtree:!0}),{update(t,r){f=t,v=r,null!==x&&(e.cancelAnimationFrame?.(x),x=null),w()},refresh:k,destroy(){null!==x&&e.cancelAnimationFrame?.(x),e.removeEventListener("scroll",k,{capture:!0}),e.removeEventListener("resize",k),C?.disconnect(),g.remove()}}},u=/(-?\d*\.?\d+)(?:s|l|d)?vh\b/g,g=(e,t)=>(u.lastIndex=0,u.test(e))?e.replace(u,(e,r)=>`${Math.round(Number(r)*t/100*100)/100}px`):null,h=(e,t)=>{for(let r=0;r<e.length;r++){let n=e.item(r),a=g(e.getPropertyValue(n),t);null!==a&&e.setProperty(n,a,e.getPropertyPriority(n))}},b=(e,t)=>{for(let r of Array.from(e)){let{style:e,cssRules:n}=r;e&&h(e,t),n&&b(n,t)}},m="obelism-content-bridge",f="#d58a1f",v=(e="")=>`${e}[${t}]{cursor:pointer;transition:outline-color .15s}${e}[${t}]:hover{outline:2px dashed ${f};outline-offset:2px}${e}[${t}][data-cms-selected]{outline:2px solid ${f};outline-offset:2px}`,x={features:[],selectedUid:null,prompting:!1,canUndo:!1,unsaved:!1,saving:!1,publishing:!1,selecting:!1,stats:{},statsVisible:!1},y=()=>{let e={update:new Set,saved:new Set,published:new Set,change:new Set};return{listeners:e,on:(t,r)=>(e[t].add(r),()=>{e[t].delete(r)}),emit(t,r){for(let n of e[t])try{n(r)}catch(e){console.error("[@obelism/content bridge]",e)}}}},w=()=>Promise.reject(Error("Save and publish in the visual editor itself")),k=()=>Promise.reject(Error("Only while signed in to edit on the site")),E={prompt:()=>Promise.reject(Error("Prompts only work inside the visual editor")),createPage:()=>Promise.reject(Error("New pages are made on the site itself")),createProductPage:()=>Promise.reject(Error("Product pages are made on the site itself")),createCollectionPage:()=>Promise.reject(Error("Collection pages are made on the site itself")),view:k,applyJson:k,openForm:(e,t={})=>(queueMicrotask(()=>t.onError?.("Only while signed in to edit on the site")),{close:()=>{}}),pages:k,openPage:()=>{},undo:()=>{},save:w,publish:w,signOut:()=>{},select:()=>{},setSelecting:()=>{}},C=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0,A=e=>{if(!e||"object"!=typeof e||Array.isArray(e))return{};let t={};for(let[r,n]of Object.entries(e)){let{clicks:e,clickers:a,viewers:i,rate:o}=n??{};C(e)&&C(a)&&C(i)&&C(o)&&(t[r]={clicks:e,clickers:a,viewers:i,rate:o})}return t},N=e=>`[${t}="${e.replace(/["\\]/g,"\\$&")}"]`,S=(e,t)=>{let r=y();e.on("saved",()=>r.emit("saved",{})),e.on("published",()=>r.emit("published",{}));let n=!1;return{isEditing:e.isEditing,mode:e.isEditing?"editor":null,entryId:e.entryId,environment:t.get(i),product:null,collection:null,on:(t,a)=>("update"!==t||n||(n=!0,e.on("update",e=>{let t=e?.entry;t&&r.emit("update",{entry:t,selectedUid:null})})),r.on(t,a)),getState:()=>x,...E,destroy:()=>{}}},L=(e,t,r={},...n)=>{let a=e.createElement(t);for(let t of(Object.assign(a,r),n))a.appendChild("string"==typeof t?e.createTextNode(t):t);return a},P='<rect x="10" y="2" width="4" height="20"/><rect x="2" y="10" width="20" height="4"/><circle cx="6" cy="6" r="2.6"/><circle cx="18" cy="6" r="2.6"/><circle cx="6" cy="18" r="2.6"/><circle cx="18" cy="18" r="2.6"/>',$='<circle cx="6" cy="6" r="2.2"/><circle cx="18" cy="6" r="2.2"/><circle cx="12" cy="12" r="2.2" class="accent"/><circle cx="6" cy="18" r="2.2"/><circle cx="18" cy="18" r="2.2"/>',M=(e,t,r)=>{let n=L(e,"span",{className:t});return n.setAttribute("aria-hidden","true"),n.innerHTML=`<svg viewBox="0 0 24 24">${r}</svg>`,n},U=(e,t)=>e.replace(/\{(\w+)\}/g,(e,r)=>r in t?String(t[r]):e),z={page:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/>',newPage:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M9 15h6"/><path d="M12 18v-6"/>',block:'<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 8h10"/><path d="M7 12h6"/>',undo:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>',close:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',minimize:'<path d="m6 9 6 6 6-6"/>',expand:'<path d="m18 15-6-6-6 6"/>',chevrons:'<path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',check:'<path d="M20 6 9 17l-5-5"/>',mark:`<g fill="currentColor" stroke="none">${P}</g>`,send:'<path d="M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"/><path d="M6 12h16"/>',arrowUp:'<path d="M12 19V5"/><path d="m5 12 7-7 7 7"/>',dash:'<path d="M5 12h14"/>',eye:'<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/>',eyeOff:'<path d="M10.7 5.1A10 10 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-2.2 3.2"/><path d="M6.6 6.6A17 17 0 0 0 2 12s3.5 7 10 7a9.7 9.7 0 0 0 5.4-1.6"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/><path d="m2 2 20 20"/>',plus:'<path d="M5 12h14"/><path d="M12 5v14"/>',scope:'<rect x="3" y="3" width="18" height="18" rx="3" stroke-dasharray="3 3"/>',alert:'<circle cx="12" cy="12" r="10"/><path d="M12 8v4"/><path d="M12 16h.01"/>'},O=(e,t)=>M(e,"icon",z[t]),I=(e,t,r,{onReady:n,onError:a,onEscape:i})=>{let o=null,s=!1,l=null;return{get mounted(){return null!==o},get loading(){return s},get error(){return l},mount(){s=!0,l=null;let d=e.openForm(t,{title:r,onReady:()=>{o===d&&(s=!1,n())},onError:e=>{o===d&&(s=!1,l=e,a(e))},onEscape:()=>{o===d&&i?.()}});o=d},unmount(){o?.close(),o=null,s=!1,l=null}}},j={open:"Edit with a prompt",placeholder:"Describe a change, like “make it warmer”",send:"Apply",undo:"Undo",minimize:"Minimize, to see the page",scopeEntry:"Whole page",working:"Working on it…",publish:"Publish",saving:"Saving…",publishing:"Publishing…",saved:"Saved as a draft",published:"Published",unsaved:"Unsaved changes",signOut:"Exit",viewingDrafts:"Viewing drafts",newPage:"New page",newPageCancel:"Edit this page instead",newPagePlaceholder:"Describe the new page, e.g. “a pricing page for agencies”",path:"Path",pathPlaceholder:"/pricing",creating:"Writing the page…",created:"Opening the new page…",modes:"Edit with",modePrompt:"Ask",form:"Edit fields",formTitle:"The content form",formLoading:"Opening the form…",pages:"Pages",pagesSearch:"Find a page",pagesLoading:"Loading pages…",pagesEmpty:"No pages match",pageCurrent:"This page",pageDraft:"Draft",pageChanged:"Changed",addProductPage:"Add a product page",addingProductPage:"Making the product page…",addedProductPage:"Opening the product page…",productPageHint:"This product has no page yet. Add one for what the store doesn’t say.",addCollectionPage:"Add a collection page",addingCollectionPage:"Making the collection page…",addedCollectionPage:"Opening the collection page…",collectionPageHint:"This collection has no page yet. Add one for what goes around its products."},T={...j,close:"Close",expand:"Expand",scopeNoPage:"Whole page",scopeBlock:"Selected block",clearBlock:"Edit the whole page instead",save:"Save",selectHint:"Click a block to change only that block"},R={...j,editor:"Obelism editor",editing:"Editing",hideOutlines:"Show the page without outlines",environment:"Environment",envProduction:"live",scopeNoteBlock:"Working on {name}. Click another block to switch.",scopeNotePage:"Working on the whole page. Click a block to change only that block.",scopeUp:"Up to {name}",block:"Block",previewChip:"{name} \xb7 preview",askIntro:"Describe a change and Obelism shows it on the page. Nothing is stored until you keep it and save.",you:"You",obelism:"Obelism",suggested:"Suggested by Obelism",keep:"Keep it",retry:"Try another",retryPrompt:"{prompt}\n\nWrite a different version than the last one.",kept:"Kept",undone:"Undone",before:"Before",after:"After",emptyValue:"Empty",moreChanges:"{count} more changed",keepFirst:"Keep or undo the suggestion to save",keepBeforeFields:"Keep or undo the suggestion before editing fields.",saveDraft:"Save draft",upToDate:"No unsaved changes",saveFailed:"Couldn’t save",publishFailed:"Couldn’t publish",tryAgain:"Try again"},D=(e,t,r,{onLoad:n,onClose:a})=>{let i=L(e,"input",{type:"text",placeholder:r.pagesSearch,autocomplete:"off",spellcheck:!1});i.setAttribute("role","combobox"),i.setAttribute("aria-label",r.pagesSearch),i.setAttribute("aria-autocomplete","list"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-controls","obelism-pages");let o=L(e,"label",{className:"search"},O(e,"search"),i),s=L(e,"ul",{className:"options",id:"obelism-pages"});s.setAttribute("role","listbox"),s.setAttribute("aria-label",r.pages);let l=L(e,"p",{className:"empty"}),d=null,p=null,c=null,u=0,g=()=>{let e=i.value.trim().toLowerCase();return(d??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},h=e=>{if(e.entryId===t.entryId)return a();t.openPage(e)},b=()=>{let n=g();u=Math.max(0,Math.min(u,n.length-1)),s.textContent="",n.forEach((n,a)=>{let i=L(e,"li",{className:`option${a===u?" active":""}`,id:`obelism-page-${a}`},L(e,"span",{className:"option-text"},L(e,"span",{textContent:n.name}),L(e,"span",{className:"option-path",textContent:n.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(a===u)),"published"!==n.status&&i.appendChild(L(e,"span",{className:"badge",textContent:"draft"===n.status?r.pageDraft:r.pageChanged})),n.entryId===t.entryId){i.setAttribute("aria-current","page");let t=O(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",r.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>h(n)),s.appendChild(i)});let a=s.children[u];a?(i.setAttribute("aria-activedescendant",a.id),a.scrollIntoView?.({block:"nearest"})):i.removeAttribute("aria-activedescendant"),l.textContent=(c??(d?"":r.pagesLoading))||(0===n.length?r.pagesEmpty:""),l.hidden=!l.textContent,l.className=`empty${c?" error":""}`},m=()=>(p??(p=t.pages().then(e=>{d=e,c=null,b(),n()},e=>{p=null,c=e instanceof Error?e.message:String(e),b(),n()})),p);return i.addEventListener("input",()=>{u=0,b()}),i.addEventListener("keydown",e=>{let t=s.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;u=(u+("ArrowDown"===e.key?1:-1)+t)%t,b()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),a());else{e.preventDefault();let t=g()[u];t&&h(t)}}),{searchRow:o,search:i,list:s,note:l,get pages(){return d},get error(){return c},current:()=>d?.find(({entryId:e})=>e===t.entryId)??null,fetch:m,forget(){d=null,p=null},reset(){i.value="",u=Math.max(0,(d??[]).findIndex(({entryId:e})=>e===t.entryId)),m(),b()},render:b}},q=e=>e instanceof Error?e.message:String(e),F=(e,t,r)=>{let n="site"===e.mode,a=n&&t.features.includes("create"),i=n&&null===e.entryId,o=i&&a?e.product?"product":e.collection?"collection":null:null;return{site:n,canCreate:a,pageless:i,shopHere:o,onlyNew:i&&a&&!o&&!r}},B=(e,t)=>"collection"===t?{add:e.addCollectionPage,adding:e.addingCollectionPage,hint:e.collectionPageHint}:{add:e.addProductPage,adding:e.addingProductPage,hint:e.productPageHint},V=async(e,t)=>{try{if(e.product)return await e.createProductPage(),{text:t.addedProductPage,error:!1};return await e.createCollectionPage(),{text:t.addedCollectionPage,error:!1}}catch(e){return{text:q(e),error:!0}}},H=async(e,t)=>{try{return await e[t](),null}catch(e){return q(e)}},_="obelism-content-prompt-side",W=`
|
|
40
|
+
`,C=(e,{selector:r,onSelect:n,checked:a,shows:i,labels:o})=>{let s=e.document,l={...x,...o},d=s.createElement("div");d.setAttribute("data-obelism-stats","");let p=d.attachShadow({mode:"open"}),c=s.createElement("style");c.textContent=E;let u=s.createElement("div");u.className="layer",p.append(c,u),s.body.appendChild(d);let g={},h=!1,b=null,m=(r,a,i)=>{let o,d=a.getBoundingClientRect();if(!d.width&&!d.height||d.bottom<0||d.top>e.innerHeight)return;let p=g[r],c=p&&0!==p.clicks?p.viewers<20?"counting":"rate":"none",h=s.createElement("button");h.type="button",h.dataset.uid=r,h.dataset.status=c;let b=p?Math.round(100*p.rate):0;h.title="rate"===c?k(l.title,{clickers:p.clickers,viewers:p.viewers,clicks:p.clicks}):"none"===c?l.noClicks:k(l.counting,{clicks:p.clicks,viewers:p.viewers,needed:20});let{top:m,left:f}="rate"===c&&d.height>=64?{top:Math.max(d.top,0)+8,left:d.right-8}:(o={width:e.innerWidth,height:e.innerHeight},{top:Math.min(Math.max(d.top,10),o.height-10),left:Math.min(d.right,o.width-10)});"rate"===c&&d.height>=64?(h.className="badge",h.textContent=k(l.clicked,{rate:b})):(h.className="tag","rate"===c?h.textContent=k(l.clickedShort,{rate:b}):h.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true">${w[c]}</svg>`,h.setAttribute("aria-label",h.title)),h.style.top=`${m}px`,h.style.left=`${f}px`;let v=i.has(r)?r:a.closest(`[${t}]`)?.getAttribute(t);v&&h.addEventListener("click",()=>n(v)),u.appendChild(h)},f=()=>{if(b=null,u.replaceChildren(),u.hidden=!h,!h)return;let e=new Set;for(let r of s.querySelectorAll(`[${t}]`))e.add(r.getAttribute(t)??"");let n=a??(t=>e.has(t)),o=new Set;for(let t of s.querySelectorAll(`[${y}]`)){let r=t.getAttribute(y);r&&(g[r]||n(r))&&(o.add(r),(!i||i(r,t))&&m(r,t,e))}for(let t of Object.keys(g)){if(o.has(t)||!e.has(t))continue;let n=s.querySelector(r(t));n&&(!i||i(t,n))&&m(t,n,e)}},v=()=>{null===b&&h&&(b=e.requestAnimationFrame(f))};e.addEventListener("scroll",v,{capture:!0,passive:!0}),e.addEventListener("resize",v);let C=e.MutationObserver,A="function"==typeof C?new C(v):null;return A?.observe(s.body,{childList:!0,subtree:!0}),{update(t,r){g=t,h=r,null!==b&&(e.cancelAnimationFrame?.(b),b=null),f()},refresh:v,destroy(){null!==b&&e.cancelAnimationFrame?.(b),e.removeEventListener("scroll",v,{capture:!0}),e.removeEventListener("resize",v),A?.disconnect(),d.remove()}}},A=/(-?\d*\.?\d+)(?:s|l|d)?vh\b/g,N=(e,t)=>(A.lastIndex=0,A.test(e))?e.replace(A,(e,r)=>`${Math.round(Number(r)*t/100*100)/100}px`):null,S=(e,t)=>{for(let r=0;r<e.length;r++){let n=e.item(r),a=N(e.getPropertyValue(n),t);null!==a&&e.setProperty(n,a,e.getPropertyPriority(n))}},L=(e,t)=>{for(let r of Array.from(e)){let{style:e,cssRules:n}=r;e&&S(e,t),n&&L(n,t)}},P=(e,t,r={},...n)=>{let a=e.createElement(t);for(let t of(Object.assign(a,r),n))a.appendChild("string"==typeof t?e.createTextNode(t):t);return a},$='<rect x="10" y="2" width="4" height="20"/><rect x="2" y="10" width="20" height="4"/><circle cx="6" cy="6" r="2.6"/><circle cx="18" cy="6" r="2.6"/><circle cx="6" cy="18" r="2.6"/><circle cx="18" cy="18" r="2.6"/>',M='<circle cx="6" cy="6" r="2.2"/><circle cx="18" cy="6" r="2.2"/><circle cx="12" cy="12" r="2.2" class="accent"/><circle cx="6" cy="18" r="2.2"/><circle cx="18" cy="18" r="2.2"/>',z=(e,t,r)=>{let n=P(e,"span",{className:t});return n.setAttribute("aria-hidden","true"),n.innerHTML=`<svg viewBox="0 0 24 24">${r}</svg>`,n},U=(e,t)=>e.replace(/\{(\w+)\}/g,(e,r)=>r in t?String(t[r]):e),O=e=>{e.style.height="auto",e.style.height=`${e.scrollHeight}px`},I={page:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/>',newPage:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M9 15h6"/><path d="M12 18v-6"/>',block:'<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 8h10"/><path d="M7 12h6"/>',undo:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>',close:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',minimize:'<path d="m6 9 6 6 6-6"/>',expand:'<path d="m18 15-6-6-6 6"/>',chevrons:'<path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',check:'<path d="M20 6 9 17l-5-5"/>',mark:`<g fill="currentColor" stroke="none">${$}</g>`,send:'<path d="M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"/><path d="M6 12h16"/>',arrowUp:'<path d="M12 19V5"/><path d="m5 12 7-7 7 7"/>',dash:'<path d="M5 12h14"/>',eye:'<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/>',eyeOff:'<path d="M10.7 5.1A10 10 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-2.2 3.2"/><path d="M6.6 6.6A17 17 0 0 0 2 12s3.5 7 10 7a9.7 9.7 0 0 0 5.4-1.6"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/><path d="m2 2 20 20"/>',plus:'<path d="M5 12h14"/><path d="M12 5v14"/>',scope:'<rect x="3" y="3" width="18" height="18" rx="3" stroke-dasharray="3 3"/>',alert:'<circle cx="12" cy="12" r="10"/><path d="M12 8v4"/><path d="M12 16h.01"/>'},j=(e,t)=>z(e,"icon",I[t]),T=(e,t,r,{onReady:n,onError:a,onEscape:i})=>{let o=null,s=!1,l=null;return{get mounted(){return null!==o},get loading(){return s},get error(){return l},mount(){s=!0,l=null;let d=e.openForm(t,{title:r,onReady:()=>{o===d&&(s=!1,n())},onError:e=>{o===d&&(s=!1,l=e,a(e))},onEscape:()=>{o===d&&i?.()}});o=d},unmount(){o?.close(),o=null,s=!1,l=null}}},D={open:"Edit with a prompt",placeholder:"Describe a change, like “make it warmer”",send:"Apply",undo:"Undo",minimize:"Minimize, to see the page",scopeEntry:"Whole page",working:"Working on it…",publish:"Publish",saving:"Saving…",publishing:"Publishing…",saved:"Saved as a draft",published:"Published",unsaved:"Unsaved changes",signOut:"Exit",viewingDrafts:"Viewing drafts",newPage:"New page",newPageCancel:"Edit this page instead",newPagePlaceholder:"Describe the new page, e.g. “a pricing page for agencies”",path:"Path",pathPlaceholder:"/pricing",creating:"Writing the page…",created:"Opening the new page…",modes:"Edit with",modePrompt:"Ask",form:"Edit fields",formTitle:"The content form",formLoading:"Opening the form…",pages:"Pages",pagesSearch:"Find a page",pagesLoading:"Loading pages…",pagesEmpty:"No pages match",pageCurrent:"This page",pageDraft:"Draft",pageChanged:"Changed",addProductPage:"Add a product page",addingProductPage:"Making the product page…",addedProductPage:"Opening the product page…",productPageHint:"This product has no page yet. Add one for what the store doesn’t say.",addCollectionPage:"Add a collection page",addingCollectionPage:"Making the collection page…",addedCollectionPage:"Opening the collection page…",collectionPageHint:"This collection has no page yet. Add one for what goes around its products."},q={...D,close:"Close",expand:"Expand",scopeNoPage:"Whole page",scopeBlock:"Selected block",clearBlock:"Edit the whole page instead",save:"Save",selectHint:"Click a block to change only that block"},R={...D,editor:"Obelism editor",editing:"Editing",hideOutlines:"Show the page without outlines",environment:"Environment",envProduction:"live",scopeNoteBlock:"Working on {name}. Click another block to switch.",scopeNotePage:"Working on the whole page. Click a block to change only that block.",scopeUp:"Up to {name}",block:"Block",previewChip:"{name} \xb7 preview",askIntro:"Describe a change and Obelism shows it on the page. Nothing is stored until you keep it and save.",you:"You",obelism:"Obelism",suggested:"Suggested by Obelism",keep:"Keep it",retry:"Try another",retryPrompt:"{prompt}\n\nWrite a different version than the last one.",kept:"Kept",undone:"Undone",before:"Before",after:"After",emptyValue:"Empty",moreChanges:"{count} more changed",keepFirst:"Keep or undo the suggestion to save",keepBeforeFields:"Keep or undo the suggestion before editing fields.",saveDraft:"Save draft",upToDate:"No unsaved changes",saveFailed:"Couldn’t save",publishFailed:"Couldn’t publish",tryAgain:"Try again"},F=(e,t,r,{onLoad:n,onClose:a})=>{let i=P(e,"input",{type:"text",placeholder:r.pagesSearch,autocomplete:"off",spellcheck:!1});i.setAttribute("role","combobox"),i.setAttribute("aria-label",r.pagesSearch),i.setAttribute("aria-autocomplete","list"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-controls","obelism-pages");let o=P(e,"label",{className:"search"},j(e,"search"),i),s=P(e,"ul",{className:"options",id:"obelism-pages"});s.setAttribute("role","listbox"),s.setAttribute("aria-label",r.pages);let l=P(e,"p",{className:"empty"}),d=null,p=null,c=null,u=0,g=()=>{let e=i.value.trim().toLowerCase();return(d??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},h=e=>{if(e.entryId===t.entryId)return a();t.openPage(e)},b=()=>{let n=g();u=Math.max(0,Math.min(u,n.length-1)),s.textContent="",n.forEach((n,a)=>{let i=P(e,"li",{className:`option${a===u?" active":""}`,id:`obelism-page-${a}`},P(e,"span",{className:"option-text"},P(e,"span",{textContent:n.name}),P(e,"span",{className:"option-path",textContent:n.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(a===u)),"published"!==n.status&&i.appendChild(P(e,"span",{className:"badge",textContent:"draft"===n.status?r.pageDraft:r.pageChanged})),n.entryId===t.entryId){i.setAttribute("aria-current","page");let t=j(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",r.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>h(n)),s.appendChild(i)});let a=s.children[u];a?(i.setAttribute("aria-activedescendant",a.id),a.scrollIntoView?.({block:"nearest"})):i.removeAttribute("aria-activedescendant"),l.textContent=(c??(d?"":r.pagesLoading))||(0===n.length?r.pagesEmpty:""),l.hidden=!l.textContent,l.className=`empty${c?" error":""}`},m=()=>(p??(p=t.pages().then(e=>{d=e,c=null,b(),n()},e=>{p=null,c=e instanceof Error?e.message:String(e),b(),n()})),p);return i.addEventListener("input",()=>{u=0,b()}),i.addEventListener("keydown",e=>{let t=s.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;u=(u+("ArrowDown"===e.key?1:-1)+t)%t,b()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),a());else{e.preventDefault();let t=g()[u];t&&h(t)}}),{searchRow:o,search:i,list:s,note:l,get pages(){return d},get error(){return c},current:()=>d?.find(({entryId:e})=>e===t.entryId)??null,fetch:m,forget(){d=null,p=null},reset(){i.value="",u=Math.max(0,(d??[]).findIndex(({entryId:e})=>e===t.entryId)),m(),b()},render:b}},B={product:{item:"data-cms-product",handle:"data-cms-product-handle",setting:"productPath",route:"/products/{handle}",marker:"editableProduct(product)",add:"addProductPage",adding:"addingProductPage",hint:"productPageHint",added:"addedProductPage"},collection:{item:"data-cms-collection",handle:"data-cms-collection-handle",setting:"collectionPath",route:"/collections/{handle}",marker:"editableCollection(collection)",add:"addCollectionPage",adding:"addingCollectionPage",hint:"collectionPageHint",added:"addedCollectionPage"}},V=(e,t)=>{let{item:r,handle:n}=B[t],a=e.querySelector(`[${r}]`),i=a?.getAttribute(r),o=a?.getAttribute(n);return i&&o?{id:i,handle:o}:null},W=e=>e.product?"product":e.collection?"collection":null,_=(e,t)=>{let r=B[t];return{add:e[r.add],adding:e[r.adding],hint:e[r.hint],added:e[r.added]}},H=e=>e instanceof Error?e.message:String(e),Y=async(e,t)=>{let r=W(e);if(!r)return null;try{return"product"===r?await e.createProductPage():await e.createCollectionPage(),{text:t[B[r].added],error:!1}}catch(e){return{text:H(e),error:!0}}},X=async(e,t)=>{try{return await e[t](),null}catch(e){return H(e)}},K=(e,t,r,{promptWithoutPage:n,signOut:a,labels:i})=>{let o,s,l,d,p=(s=(o="site"===e.mode)&&t.features.includes("create"),d=(l=o&&null===e.entryId)&&s?W(e):null,{site:o,canCreate:s,pageless:l,shop:d,onlyNew:l&&s&&!d&&!n}),c=p.canCreate&&(r.creating||p.onlyNew),u=t.features.includes("prompt"),g=t.saving||t.publishing,h=t.prompting||g;return{...p,creating:c,available:u,storing:g,busy:h,offerShop:null!==p.shop&&!c,canForm:p.site&&!c&&!p.pageless,placeholder:c?i.newPagePlaceholder:i.placeholder,canSave:t.features.includes("save")&&!p.pageless,canPublish:t.features.includes("publish")&&!p.pageless,showSignOut:p.site&&!1!==a,canSend:(e,t)=>!h&&""!==e.trim()&&(!c||""!==t.trim())}},J="obelism-content-prompt-side",Z=`
|
|
41
41
|
:host { all: initial; }
|
|
42
42
|
* { box-sizing: border-box; font: inherit; color: inherit; margin: 0; }
|
|
43
43
|
.root {
|
|
@@ -268,7 +268,7 @@ button.chip:disabled { opacity: .5; }
|
|
|
268
268
|
.empty { padding: 8px 12px; color: rgb(var(--theme-foreground-muted-rgb)); }
|
|
269
269
|
.empty.error { color: var(--theme-error); }
|
|
270
270
|
[hidden] { display: none !important; }
|
|
271
|
-
`,
|
|
271
|
+
`,G=(e,t,r={})=>{let n,a={...q,...r.labels},i=P(e,"div");i.setAttribute("data-obelism-content-prompt","");let o=i.attachShadow({mode:"open"}),s="site"===t.mode,l=P(e,"span",{textContent:a.open}),d=P(e,"button",{className:"pill",type:"button"},l,((n=j(e,"mark")).classList.add("mark"),n)),p=P(e,"span",{className:"pill compact"},`${a.viewingDrafts} \xb7 `),c=P(e,"button",{className:"link",type:"button",textContent:a.signOut});p.appendChild(c);let u=P(e,"p",{className:"status"});u.setAttribute("role","status");let g=P(e,"textarea",{placeholder:a.placeholder,rows:1});g.setAttribute("aria-label",a.open);let h=P(e,"div",{className:"form-loader",textContent:a.formLoading});h.setAttribute("role","status");let b=P(e,"div",{className:"form"},h),m=j(e,"page"),f=j(e,"block"),v=P(e,"span"),x=P(e,"button",{type:"button",title:a.clearBlock});x.setAttribute("aria-label",a.clearBlock),x.appendChild(j(e,"close"));let y=P(e,"span",{className:"chip scope"},m,f,v,x),w=P(e,"button",{className:"action chip",type:"button"},j(e,"undo"),a.undo),k=t=>{let r=P(e,"button",{type:"button",textContent:t});return r.setAttribute("aria-pressed","false"),r},E=k(a.modePrompt),C=k(a.form),A=P(e,"span",{className:"modes"},E,C);A.setAttribute("role","group"),A.setAttribute("aria-label",a.modes);let N=P(e,"button",{className:"action chip",type:"button"},j(e,"newPage"),a.newPage),S=P(e,"button",{className:"action chip product",type:"button"},j(e,"newPage"),a.addProductPage),L=P(e,"button",{type:"button",title:a.newPageCancel});L.setAttribute("aria-label",a.newPageCancel),L.appendChild(j(e,"close"));let $=P(e,"span",{className:"chip scope"},j(e,"newPage"),P(e,"span",{textContent:a.newPage}),L),M=P(e,"input",{type:"text",placeholder:a.pathPlaceholder,autocomplete:"off",spellcheck:!1}),z=P(e,"label",{className:"path"},P(e,"span",{textContent:a.path}),M),U=P(e,"button",{className:"close icon-button",type:"button",title:a.close},j(e,"close"));U.setAttribute("aria-label",a.close);let I=j(e,"minimize"),D=j(e,"expand"),R=P(e,"button",{className:"icon-button",type:"button"},I,D),B=P(e,"button",{className:"action primary icon-button",type:"submit"},P(e,"span",{className:"visually-hidden",textContent:a.send}),j(e,"send"));B.title=a.send;let V=P(e,"span",{className:"divider"}),W=P(e,"div",{className:"toolbar"},y,$,A,w,S,N,P(e,"span",{className:"spacer"}),R,U,V,B),G=P(e,"span",{textContent:a.pages}),Q=P(e,"button",{className:"chip page-chip",type:"button",title:a.pages},j(e,"page"),G,j(e,"chevrons"));Q.setAttribute("aria-haspopup","listbox"),Q.setAttribute("aria-expanded","false"),Q.setAttribute("aria-controls","obelism-pages");let ee=F(e,t,a,{onLoad:()=>eC(),onClose:()=>eS(!1)}),et=P(e,"div",{className:"pages"},ee.searchRow,ee.list,ee.note),er=P(e,"slot");er.name="actions-footer";let en=P(e,"slot");en.name="actions-bar",r.actions&&(r.actions.slot="actions-bar",i.appendChild(r.actions));let ea=P(e,"span",{className:"unsaved"});ea.appendChild(P(e,"span",{className:"dot"})),ea.appendChild(e.createTextNode(a.unsaved));let ei=P(e,"button",{className:"link",type:"button",textContent:a.signOut}),eo=P(e,"button",{className:"action chip",type:"button",textContent:a.save}),es=P(e,"button",{className:"action chip",type:"button",textContent:a.publish}),el=P(e,"div",{className:"footer"},Q,ea,P(e,"span",{className:"spacer"}),er,ei,eo,es),ed=P(e,"form",{className:"panel"},u,z,g,b,W,et,el),ep=P(e,"div",{className:"root"},P(e,"div",{className:"bar"},d,p,en),ed);o.append(P(e,"style",{textContent:Z}),ep);let ec=e.defaultView,eu=e=>{"center"===e?delete ep.dataset.side:ep.dataset.side=e};eu((()=>{try{let e=ec?.localStorage.getItem(J);return"left"===e||"right"===e?e:"center"}catch{return"center"}})());let eg=null,eh=!1;ep.addEventListener("pointerdown",e=>{if(eh=!1,0!==e.button||!e.isPrimary)return;let t=e.target.closest("button, input, textarea, select, iframe, a, label, .pages, .form");if(t&&t!==d)return;let{left:r,right:n}=ep.getBoundingClientRect();eg={id:e.pointerId,startX:e.clientX,x:e.clientX,velocity:0,time:e.timeStamp,moved:!1,min:Math.min(0,16-r),max:Math.max(0,(ec?.innerWidth??0)-16-n)}}),ep.addEventListener("pointermove",e=>{if(!eg||e.pointerId!==eg.id)return;let t=e.clientX-eg.startX;if(!eg.moved){if(6>Math.abs(t))return;eg.moved=!0,ep.classList.add("dragging");try{ep.setPointerCapture(e.pointerId)}catch{}}let r=e.timeStamp-eg.time;r>0&&(eg.velocity=(e.clientX-eg.x)/r),eg.x=e.clientX,eg.time=e.timeStamp;let n=Math.min(Math.max(t,eg.min),eg.max);ep.style.translate=`${n+(t-n)/3}px 0`});let eb=e=>{if(!eg||e.pointerId!==eg.id)return;let{moved:t,x:r,velocity:n,time:a}=eg;if(eg=null,!t)return;eh=!0;let i=ep.getBoundingClientRect().left,o=ec?.innerWidth??0,s=r+(e.timeStamp-a>80?0:Math.min(Math.max(150*n,-120),120)),l=s<o/3?"left":s>2*o/3?"right":"center";eu(l),ep.style.translate="";let d=ep.getBoundingClientRect().left;ep.style.translate=`${i-d}px 0`,ep.offsetWidth,ep.classList.remove("dragging"),ep.style.translate="";try{ec?.localStorage.setItem(J,l)}catch{}};ep.addEventListener("pointerup",eb),ep.addEventListener("pointercancel",eb),ep.addEventListener("click",e=>{eh&&(eh=!1,e.preventDefault(),e.stopPropagation())},!0);let em=!1,ef=!1,ev=!1,ex=null,ey=!1,ew=T(t,b,a.formTitle,{onReady:()=>{ex=null,eC()},onError:e=>{ex={text:e,error:!0},eC()}}),ek=!1,eE=e=>{let n=K(t,e,{creating:ev},{promptWithoutPage:r.promptWithoutPage,signOut:r.signOut,labels:a}),{available:i,busy:o,canCreate:s,site:k,pageless:P,onlyNew:U}=n,{offerShop:O,canForm:j}=n;ev=n.creating,j||(ey=!1),ep.hidden=!i&&!k,d.hidden=em||!i,p.hidden=i||!k,ed.hidden=!em||!i;let T=n.shop?_(a,n.shop):null;S.lastChild.textContent=T?.add??a.addProductPage;let q=em&&i&&ey;q&&!ew.mounted?ew.mount():!q&&ew.mounted&&ew.unmount(),l.textContent=O?T.add:U?a.newPage:a.open,L.hidden=U,y.hidden=ev||O,$.hidden=!ev,S.hidden=!O,S.disabled=o,N.hidden=ev||ey||!s,N.disabled=o,ef&&(ek=!1),z.hidden=!ev||ek||ef,M.disabled=o,g.hidden=ey||ek||ef||O,b.hidden=!ey||ek||ef,b.classList.toggle("loading",ew.loading),h.hidden=!ew.loading,W.hidden=ek,et.hidden=!ek,g.placeholder=n.placeholder,v.textContent=e.selectedUid?a.scopeBlock:P?a.scopeNoPage:a.scopeEntry,x.hidden=!e.selectedUid,m.hidden=!!e.selectedUid,f.hidden=!e.selectedUid,A.hidden=!k||ev||P||!e.features.includes("form"),E.setAttribute("aria-pressed",String(!ey)),C.setAttribute("aria-pressed",String(ey)),A.querySelectorAll("button").forEach(e=>{e.disabled=o}),w.hidden=ev||!e.canUndo,w.disabled=o,B.hidden=ey||ef||O,V.hidden=ey||ef||O;let F=ef?a.expand:a.minimize;R.title=F,R.setAttribute("aria-label",F),R.setAttribute("aria-expanded",String(!ef)),I.hidden=ef,D.hidden=!ef,B.disabled=!n.canSend(g.value,M.value),g.disabled=o,eo.hidden=!n.canSave,eo.disabled=o||!e.unsaved,eo.textContent=e.saving?a.saving:a.save,es.hidden=!n.canPublish,es.disabled=o,es.textContent=e.publishing?a.publishing:a.publish,ei.hidden=!n.showSignOut,c.hidden=!n.showSignOut,r.actions&&(r.actions.slot=em&&i?"actions-footer":"actions-bar"),el.hidden=!k,ea.hidden=!e.unsaved,Q.hidden=!k,Q.setAttribute("aria-expanded",String(ek)),G.textContent=ee.current()?.name??a.pages;let H=ey&&ew.loading&&!ek,Y=e.prompting,X=e.prompting?ev?a.creating:O?T.adding:a.working:H?"":ex?.text??(O?T.hint:!k||ev||ek||e.selectedUid?"":a.selectHint);u.textContent=X,u.hidden=!X||ef,u.className=`status${Y?" working":""}${!o&&!H&&ex?.error?" error":""}`},eC=()=>eE(t.getState()),eA=e=>{ey!==e&&(ey=e,ex=null,eC(),ey||g.focus())},eN=async()=>{if(ey)return;let e=g.value.trim();if(e&&!t.getState().prompting){ex=null;try{if(ev){let r=M.value.trim();if(!r)return M.focus();await t.createPage(r,e),ee.forget(),ex={text:a.created,error:!1}}else{let{summary:r}=await t.prompt(e);ex={text:r,error:!1}}g.value="",O(g)}catch(e){ex={text:H(e),error:!0}}eC(),g.focus()}},eS=e=>{ex=null,(ek=e)&&ee.reset(),eC(),(ek?ee.search:Q).focus()},eL=e=>{(em=e)||(ek=!1,ef=!1),eC(),s&&t.setSelecting(em&&!ev),em&&s&&ee.fetch()},eP=e=>{ev=e,ex=null,t.setSelecting(em&&!ev),ev&&t.select(null),eC(),(ev?M:g).focus()},e$=async e=>{ex=null;let r=await X(t,e);ex=r?{text:r,error:!0}:{text:"save"===e?a.saved:a.published,error:!1},eC()};d.addEventListener("click",()=>{eL(!0),ey||(ev?M:g).focus()}),U.addEventListener("click",()=>eL(!1)),R.addEventListener("click",()=>{ef=!ef,eC(),ef||(ey?R:g).focus()}),ed.addEventListener("click",e=>{if(!ef)return;let t=e.target.closest("button");t&&t!==R&&t!==U&&(ef=!1,eC())},!0),eo.addEventListener("click",()=>void e$("save")),es.addEventListener("click",()=>void e$("publish")),ei.addEventListener("click",()=>t.signOut()),c.addEventListener("click",()=>t.signOut()),x.addEventListener("click",()=>t.select(null)),N.addEventListener("click",()=>eP(!0)),S.addEventListener("click",async()=>{ex=null,ex=await Y(t,a),eC()}),L.addEventListener("click",()=>eP(!1)),E.addEventListener("click",()=>eA(!1)),C.addEventListener("click",()=>eA(!0)),Q.addEventListener("click",()=>eS(!ek)),M.addEventListener("input",eC),M.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing?"Escape"===e.key&&eL(!1):(e.preventDefault(),g.focus())}),w.addEventListener("click",()=>{ex=null,t.undo()}),ed.addEventListener("submit",e=>{e.preventDefault(),eN()}),g.addEventListener("input",()=>{O(g),eC()}),g.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing?"Escape"===e.key&&eL(!1):(e.preventDefault(),eN())});let eM=t.on("change",eE);return eC(),e.body.appendChild(i),()=>{eM(),ew.unmount(),i.remove()}},Q="https://content.obelism.studio",ee=(e,t="")=>`entries/${encodeURIComponent(e)}${t}`,et=e=>ee(e,"/save"),er=e=>ee(e,"/publish"),en=/^(?:\/[\w.~-]+)+$/,ea=e=>{let{protocol:t}=new URL(e,"https://site.invalid");if("https:"!==t&&"http:"!==t)throw Error(`Not a page address: ${e}`);return e},ei=(e,t)=>JSON.stringify(e)===JSON.stringify(t),eo="obelism-content-editor",es=`
|
|
272
272
|
:host { all: initial; }
|
|
273
273
|
* { box-sizing: border-box; font: inherit; color: inherit; margin: 0; }
|
|
274
274
|
.root {
|
|
@@ -591,4 +591,4 @@ textarea:disabled, .path input:disabled { opacity: .6; }
|
|
|
591
591
|
.chips .accent-chip .mark { color: rgb(23 22 20); }
|
|
592
592
|
.chips .accent-chip .mark svg { width: 11px; height: 11px; }
|
|
593
593
|
.chips .ink-chip { background: rgb(23 22 20); color: rgb(255 255 255); font-weight: 500; }
|
|
594
|
-
`,ee=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},et=e=>!!e&&"object"==typeof e&&!Array.isArray(e),er=(e,t,r,n)=>{if(null!=e&&""!==e){if("object"!=typeof e)return void n.set(r,{label:t,text:String(e)});if(Array.isArray(e)){if(e.every(e=>null===e||"object"!=typeof e)){e.length&&n.set(r,{label:t,text:e.join(", ")});return}e.forEach((e,a)=>{let i=et(e)&&"string"==typeof e._uid?e._uid:a,o=et(e)&&"string"==typeof e._type?e._type:null;er(e,o?ee(o):t,`${r}/${i}`,n)});return}for(let[a,i]of Object.entries(e))"_uid"!==a&&"_type"!==a&&er(i,t?`${t} \xb7 ${ee(a)}`:ee(a),`${r}/${a}`,n)}},en=(e,n,a={})=>{let i,o={...R,...a.labels},s=e.defaultView,l=e.documentElement,d=(t,...r)=>L(e,"button",{className:t,type:"button"},...r),p=L(e,"div");p.setAttribute("data-obelism-content-editor","");let c=p.attachShadow({mode:"open"}),u=L(e,"style",{textContent:(i=`[${t}]`,`html[data-obelism-editor]{transition:margin-right .3s cubic-bezier(.2,.8,.2,1)}html[data-obelism-docked]{margin-right:436px!important}html[data-obelism-docked] [data-obelism-dock]{right:436px!important;max-width:calc(100vw - 436px)!important}html[data-obelism-editor][data-cms-selecting] ${i}:hover:not([data-cms-selected]){outline:none}html[data-obelism-editor][data-cms-selecting] ${i}[data-cms-selected]{outline:2px solid rgb(212 130 30);outline-offset:2px}@media (prefers-reduced-motion:reduce){html[data-obelism-editor]{transition:none}}`)}),g=L(e,"span",{className:"tile"},M(e,"mark",P)),h=L(e,"span"),b=d("page-button hit",h,L(e,"span",{className:"visually-hidden",textContent:`, ${o.pages}`}),O(e,"chevrons"));b.setAttribute("aria-haspopup","listbox"),b.setAttribute("aria-expanded","false"),b.setAttribute("aria-controls","obelism-pages");let m=L(e,"span",{className:"page-name"}),f=L(e,"span"),v=L(e,"span",{className:"env"},L(e,"span",{className:"visually-hidden",textContent:`${o.environment}: `}),f),x=d("icon-button hit",O(e,"dash"));x.setAttribute("aria-label",o.minimize),x.title=o.minimize;let y=d("mode hit",M(e,"mark",P),o.modePrompt);y.setAttribute("aria-pressed","false");let w=L(e,"div",{className:"head"},g,b,m,v,L(e,"span",{className:"spacer"}),y,x),k=D(e,n,o,{onLoad:()=>td(),onClose:()=>tb(!1)}),E=d("button quiet new-page",O(e,"plus"),o.newPage),C=L(e,"div",{className:"pages"},k.searchRow,k.list,k.note,E),A=d("button primary",o.keep),S=d("button quiet",o.undo),z=L(e,"div",{className:"gate"},L(e,"p",{textContent:o.keepBeforeFields}),L(e,"div",{className:"actions"},A,S));z.setAttribute("role","alert");let j=L(e,"span"),T=d("",o.scopeEntry),_=d("",o.newPageCancel),W=L(e,"div",{className:"note"},O(e,"scope"),j,T,_),Y=L(e,"p",{className:"intro",textContent:o.askIntro}),X=L(e,"p",{className:"summary"}),K=L(e,"span"),J=d("button primary",O(e,"plus"),K),Z=L(e,"div",{className:"shop"},X,J),en=L(e,"div",{className:"log"});en.setAttribute("role","log");let ea=L(e,"div",{className:"scroll"},W,Y,Z,en),ei=L(e,"input",{type:"text",placeholder:o.pathPlaceholder,autocomplete:"off",spellcheck:!1}),eo=L(e,"label",{className:"path"},L(e,"span",{textContent:o.path}),ei),es=L(e,"textarea",{rows:1});es.setAttribute("aria-label",o.open);let el=O(e,"arrowUp"),ed=M(e,"working",$),ep=L(e,"button",{className:"send",type:"submit",title:o.send},L(e,"span",{className:"visually-hidden",textContent:o.send}),el,ed),ec=L(e,"div",{className:"bar"},M(e,"mark",P),es,ep),eu=L(e,"form",{className:"composer"},eo,ec),eg=L(e,"div",{className:"ask",id:"obelism-ask"},ea,eu);eg.setAttribute("role","tabpanel"),eg.setAttribute("aria-label",o.modePrompt);let eh=L(e,"p",{className:"form-note"});eh.setAttribute("role","status");let eb=L(e,"div",{className:"form"},eh),em=L(e,"span"),ef=d("",o.scopeEntry),ev=L(e,"div",{className:"note"},O(e,"scope"),em,ef),ex=L(e,"div",{className:"fields",id:"obelism-fields"},ev,eb);ex.setAttribute("role","tabpanel"),ex.setAttribute("aria-label",o.form);let ey=L(e,"p",{className:"save-state"});ey.setAttribute("aria-live","polite");let ew=L(e,"slot");ew.name="actions-footer";let ek=d("button quiet",O(e,"undo"),o.undo),eE=d("button secondary",o.saveDraft),eC=d("button primary",o.publish),eA=L(e,"div",{className:"foot"},ey,ew,ek,eE,eC),eN=L(e,"p",{className:"visually-hidden"});eN.setAttribute("role","status");let eS=L(e,"aside",{className:"panel",id:"obelism-editor"},w,C,z,eg,ex,eA,eN);eS.setAttribute("aria-label",o.editor);let eL=d("launch",L(e,"span",{className:"launch-tile"},M(e,"mark",P)),o.editing);eL.setAttribute("aria-controls",eS.id);let eP=L(e,"span",{className:"reading"},L(e,"span",{className:"launch-tile"},M(e,"mark",P)),o.viewingDrafts),e$=O(e,"eye"),eM=O(e,"eyeOff"),eU=d("eye",e$,eM);eU.setAttribute("aria-label",o.hideOutlines),eU.title=o.hideOutlines;let ez=L(e,"slot");ez.name="actions-bar";let eO=d("exit",o.signOut),eI=L(e,"div",{className:"launcher"},eL,eP,eU,ez,eO);a.actions&&p.appendChild(a.actions);let ej=L(e,"div",{className:"layer"});ej.setAttribute("aria-hidden","true");let eT=L(e,"div",{className:"wash"});eT.setAttribute("aria-hidden","true");let eR=L(e,"div",{className:"root"},eT,ej,eS,eI);c.append(L(e,"style",{textContent:Q}),eR);let eD=(e=>{try{return e?.localStorage.getItem(G)!=="minimised"}catch{return!0}})(s),eq="fields",eF="fields",eB=!1,eV=!1,eH=!0,e_=!1,eW=null,eY=!1,eX=null,eK=[],eJ=!0,eZ=null,eG=new Map,eQ=new Map,e0="idle",e1=!1,e2=I(n,eb,o.formTitle,{onReady:()=>{td(),eD&&"fields"===eF&&e4()},onError:()=>td(),onEscape:()=>tf()}),e4=()=>eb.querySelector("iframe")?.focus(),e5=()=>eK.filter(({status:e})=>"pending"===e),e6=()=>e5().slice(-1)[0]??null,e3=()=>eK.some(({status:e})=>"working"===e)?null:e6(),e8=e=>(eG.has(e)||"loading"===e0||(eG.set(e,null),n.view({uid:e}).then(t=>{"string"==typeof t._type&&eG.set(e,ee(t._type)),td()},()=>{})),eG.get(e)??o.block),e7=(e,t=null)=>{if(Array.isArray(e))e.forEach(e=>e7(e,t));else if(et(e)){let r=t;"string"==typeof e._uid&&"string"==typeof e._type&&(r=e._uid,eQ.set(r,t),eG.set(r,ee(e._type))),Object.values(e).forEach(e=>e7(e,r))}},e9=r=>e.querySelector(N(r))?.parentElement?.closest(`[${t}]`)?.getAttribute(t)??eQ.get(r)??null,te=()=>k.current()?.name||e.title.trim(),tt=null,tr=()=>{null===tt&&s&&(tt=s.requestAnimationFrame(()=>{tt=null,(t=>{if(ej.replaceChildren(),eT.replaceChildren(),!ta(t))return;let n=t=>{let r=e.querySelector(t),n=r?.getBoundingClientRect();return n&&(n.width||n.height)?n:null},a=(t,r,n=ej)=>{let a=L(e,"div",{className:`box ${r}`});Object.assign(a.style,{top:`${t.top-3}px`,left:`${t.left-3}px`,width:`${t.width+6}px`,height:`${t.height+6}px`}),n.appendChild(a)},i=(t,...r)=>{let n=L(e,"div",{className:"chips"},...r),a=t.top-34<0?t.top+6:t.top-34;Object.assign(n.style,{top:`${a}px`,left:`${t.left-3}px`}),ej.appendChild(n)},s=(t,r)=>{let n=L(e,"span",{className:"accent-chip"});return r&&n.appendChild(M(e,"mark",P)),n.appendChild(e.createTextNode(t)),n},l=e6(),d=l?l.uid?N(l.uid):`[${r}]`:null,p=d?n(d):null;if(p&&a(p,"fill",eT),eZ&&eZ!==t.selectedUid){let t=n(N(eZ));if(t){a(t,"hover");let r=t.top-23<0,n=L(e,"span",{className:`name-tab${r?" inside":""}`,textContent:e8(eZ)});Object.assign(n.style,{top:`${r?t.top-1.5:t.top-23}px`,left:`${t.left-3}px`}),ej.appendChild(n)}}let c=!!l&&l.uid===t.selectedUid;if(t.selectedUid){let r=n(N(t.selectedUid));if(r){let n=e8(t.selectedUid),a=te();i(r,s(c?U(o.previewChip,{name:n}):n,c),...a?[L(e,"span",{className:"ink-chip",textContent:a})]:[])}}if(p&&!c){a(p,"preview");let e=l.uid?e8(l.uid):te()||o.pages;i(p,s(U(o.previewChip,{name:e}),!0))}})(n.getState())}))},tn=e=>e.features.includes("prompt")&&eD,ta=e=>tn(e)&&eH&&!eV,ti=t=>L(e,"span",{className:`value${t?"":" none"}`,textContent:t||o.emptyValue}),to=t=>{let r=t.node.querySelector(".card");if(r.querySelector(".status-line")?.remove(),"failed"===t.status)return void r.appendChild(L(e,"p",{className:"failure"},O(e,"alert"),t.summary));for(let n of(r.appendChild(t.eyebrow),t.summary&&r.appendChild(L(e,"p",{className:"summary",textContent:t.summary})),t.diffs.slice(0,3))){let a=L(e,"div",{className:"diff-field"},L(e,"span",{className:"diff-label",textContent:n.label}),L(e,"div",{className:"diff"},L(e,"div",{className:"before"},L(e,"span",{className:"tag",textContent:o.before}),ti(n.before)),L(e,"div",{className:"after"},L(e,"span",{className:"tag",textContent:o.after}),ti(n.after))));t.details.push(a),r.appendChild(a)}if(t.diffs.length>3){let n=L(e,"p",{className:"more",textContent:U(o.moreChanges,{count:t.diffs.length-3})});t.details.push(n),r.appendChild(n)}if("pending"===t.status){let n=d("button primary",o.keep),a=d("button secondary",o.retry),i=d("button quiet",o.undo);n.addEventListener("click",()=>tv()),a.addEventListener("click",()=>void tw(t)),i.addEventListener("click",()=>tx(t)),t.actions=L(e,"div",{className:"actions"},n,a,i),r.appendChild(t.actions)}},ts=(t,r)=>{let n=L(e,"div",{className:"card"},L(e,"span",{className:"visually-hidden",textContent:`${o.obelism}: `}),L(e,"p",{className:"status-line"},M(e,"working",$),eV?o.creating:o.working)),a=L(e,"div",{className:"answer"},L(e,"span",{className:"chip"},M(e,"mark",P)),n);a.dataset.status="working";let i={prompt:t,uid:r,status:"working",summary:"",diffs:[],step:null,node:a,eyebrow:L(e,"p",{className:"eyebrow"}),actions:null,details:[]};return eK.push(i),en.appendChild(a),i},tl=t=>{if(e1)return;let r=t.features.includes("prompt"),i=t.saving||t.publishing,s=t.prompting||i,p=r&&eD,{site:c,canCreate:u,pageless:g,shopHere:x,onlyNew:w}=F(n,t,a.promptWithoutPage);u||(eV=!1),w&&(eV=!0);let N=c&&!eV&&!g&&t.features.includes("form");eF=N?eq:"ask";let P=e5().length>0;for(let e of(P&&"fields"!==eF||(eB=!1),eK))null!==e.step&&e.step>(t.undoSteps??0)&&(e.step=null);eR.hidden=!r&&!c,eS.toggleAttribute("data-closed",!p),eS.inert=!p,eL.hidden=!r,eL.setAttribute("aria-expanded",String(p)),eP.hidden=r,eU.hidden=!p,eU.setAttribute("aria-pressed",String(!eH)),e$.hidden=!eH,eM.hidden=eH,eO.hidden=!1===a.signOut;let I=p&&eJ;l.toggleAttribute("data-obelism-docked",I),l.style.setProperty("--obelism-dock",`${436*!!I}px`);let R=p&&eH&&!eV;t.selecting!==R&&n.setSelecting(R);let D=p&&"fields"===eF;D&&!e2.mounted?e2.mount():!D&&e2.mounted&&e2.unmount(),e_&&!p&&(e_=!1),h.textContent=te()||o.pages,b.hidden=null===k.pages&&null!==k.error,m.hidden=!b.hidden,m.textContent=te()||o.pages,b.setAttribute("aria-expanded",String(e_)),C.hidden=!e_,E.hidden=!u||eV,E.disabled=s;let q=n.environment;v.hidden=!q,v.dataset.env=q??"",f.textContent="production"===q?o.envProduction:q??"",y.hidden=!N,y.setAttribute("aria-pressed",String("ask"===eF)),y.disabled=s,z.hidden=!eB,A.disabled=S.disabled=s,eg.hidden="ask"!==eF,ex.hidden="fields"!==eF;let V=null!==x&&!eV;if(eV)j.textContent=o.newPage;else if(t.selectedUid){let[r,n=""]=o.scopeNoteBlock.split("{name}");for(let a of[j,em])a.replaceChildren(r??"",L(e,"strong",{textContent:e8(t.selectedUid)}),n)}else j.textContent=o.scopeNotePage;let H=t.selectedUid?e9(t.selectedUid):null,G=H?U(o.scopeUp,{name:e8(H)}):o.scopeEntry;for(let e of[T,ef])e.textContent!==G&&(e.textContent=G);ev.hidden=eV||!t.selectedUid,W.hidden=V||g&&!eV&&!a.promptWithoutPage,T.hidden=eV||!t.selectedUid,_.hidden=!eV||w,Y.hidden=eK.length>0||V||eV,Z.hidden=!V;let Q=B(o,x);K.textContent=t.prompting&&V?Q.adding:Q.add,J.disabled=s,X.textContent=eX?.text??Q.hint,X.className=eX?.error?"failure":"summary",eu.hidden=V,eo.hidden=!eV,ei.disabled=s,es.placeholder=eV?o.newPagePlaceholder:o.placeholder,es.disabled=s,ep.disabled=s||""===es.value.trim()||eV&&""===ei.value.trim(),ep.setAttribute("aria-busy",String(t.prompting)),el.hidden=t.prompting,ed.hidden=!t.prompting,ek.hidden=P||!t.canUndo||eV,ek.disabled=s,eE.hidden=!t.features.includes("save")||g,eE.disabled=s||P||!t.unsaved,eC.hidden=!t.features.includes("publish")||g,eC.disabled=s||P,a.actions&&(a.actions.slot=p?"actions-footer":"actions-bar"),eA.hidden=!c,t.unsaved&&!eY&&(eW=null),eY=t.unsaved;let ee=i?M(e,"working",$):eW?.kind==="error"?O(e,"alert"):P||t.unsaved?L(e,"span",{className:"dot"}):O(e,"check"),et=t.saving?o.saving:t.publishing?o.publishing:eW?.kind==="error"?`${"save"===eW.action?o.saveFailed:o.publishFailed}: ${eW.text}`:P?o.keepFirst:t.unsaved?o.unsaved:eW?.kind==="saved"?o.saved:eW?.kind==="published"?o.published:o.upToDate,er=i?"saving":eW?.kind==="error"?"error":P||t.unsaved?"unsaved":"saved";if((ey.dataset.state!==er||ey.dataset.text!==et)&&(ey.dataset.state=er,ey.dataset.text=et,ey.replaceChildren(ee,L(e,"span",{textContent:et})),eW?.kind==="error"&&!i)){let e=eW.action,t=d("link",o.tryAgain);t.addEventListener("click",()=>void tE(e)),ey.appendChild(t)}eb.classList.toggle("loading",e2.loading||null!==e2.error),eh.hidden=!e2.loading&&null===e2.error,eh.className=`form-note${null!==e2.error?" error":""}`,eh.textContent=e2.error??o.formLoading;let en=e3();for(let e of eK){if("working"===e.status||"failed"===e.status)continue;e.node.dataset.status=e.status;let t="pending"===e.status?o.suggested:"kept"===e.status?o.kept:o.undone;for(let r of(e.eyebrow.textContent!==t&&(e.eyebrow.textContent=t),e.actions&&(e.actions.hidden=e!==en),e.details))r.hidden="undone"===e.status}p&&((()=>{if("idle"!==e0||null===n.entryId)return;e0="loading";let e=()=>{e0="done",td()};n.view({uid:null}).then(t=>{e7(t),e()},e)})(),null===k.pages&&null===k.error&&k.fetch()),tr()},td=()=>tl(n.getState()),tp=()=>{es.style.height="auto",es.style.height=`${es.scrollHeight}px`},tc=()=>{ea.scrollTop=ea.scrollHeight},tu=e=>{eD=e;try{s?.localStorage.setItem(G,eD?"open":"minimised")}catch{}eD||(e_=!1),td(),eD?eV?ei.focus():"fields"===eF?e4():es.focus():eL.focus()},tg=e=>{if("fields"===e&&e5().length>0){eB=!0,td(),A.focus();return}if(eB=!1,eq===e)return td();eq=e,td()},th=e=>{e_=!1,(eV=e)&&n.select(null),td(),(eV?ei:es).focus()},tb=e=>{(e_=e)&&k.reset(),td(),(e_?k.search:b).focus()},tm=()=>{let{selectedUid:e}=n.getState();return e&&n.select(e9(e)),!n.getState().selectedUid},tf=()=>{let e=n.getState();if(!tn(e))return!1;if(e_)tb(!1);else{if(!e.selectedUid)return!1;tm()}return!0},tv=(e=!0)=>{let t=e5();t.length&&e3()&&(t.forEach(e=>{e.status="kept"}),td(),e&&es.focus())},tx=(e,t=!0)=>{e===e3()&&(n.undo(),e.status="undone",td(),t&&es.focus())},ty=async(e,t)=>{let r={uid:e.uid},a=await n.view(r).catch(()=>null);try{let{summary:i}=await n.prompt(t,r);e.step=n.getState().undoSteps??null;let o=a?await n.view(r).catch(()=>null):null;e.summary=i,e.diffs=a&&o?((e,t)=>{let r=new Map,n=new Map;er(e,"","",r),er(t,"","",n);let a=[];for(let e of new Set([...r.keys(),...n.keys()])){let t=r.get(e),i=n.get(e);t?.text!==i?.text&&a.push({label:(i??t).label,before:t?.text??"",after:i?.text??""})}return a})(a,o):[],e.status="pending"}catch(t){e.summary=q(t),e.status="failed"}to(e),td(),tc()},tw=async e=>{if(e!==e3())return;n.undo(),e.status="undone";let t=ts(e.prompt,e.uid);td(),tc(),es.focus(),await ty(t,U(o.retryPrompt,{prompt:e.prompt}))},tk=async()=>{let t=es.value.trim(),r=n.getState();if(!t||r.prompting)return;let a=ei.value.trim();if(eV&&!a)return ei.focus();let i=eV?null:r.selectedUid,s=eV?`${o.newPage} \xb7 ${a}`:i?e8(i):o.scopeEntry;en.appendChild(L(e,"p",{className:"bubble"},L(e,"span",{className:"visually-hidden",textContent:`${o.you} (${s}): `}),t)),es.value="",tp();let l=ts(t,i);if(td(),tc(),eV){try{await n.createPage(a,t),k.forget(),l.summary=o.created,l.status="kept"}catch(e){l.summary=q(e),l.status="failed"}to(l),td()}else await ty(l,t);es.focus()},tE=async e=>{eW=null;let t=await H(n,e);eW=t?{kind:"error",action:e,text:t}:{kind:"save"===e?"saved":"published"},td()};eL.addEventListener("click",()=>tu(!eD)),x.addEventListener("click",()=>tu(!1)),eU.addEventListener("click",()=>{eH=!eH,td()}),eO.addEventListener("click",()=>n.signOut()),b.addEventListener("click",()=>tb(!e_)),E.addEventListener("click",()=>th(!0)),_.addEventListener("click",()=>th(!1)),T.addEventListener("click",()=>{tm()&&es.focus()}),ef.addEventListener("click",()=>{tm()&&e4()}),J.addEventListener("click",async()=>{eX=null,eX=await V(n,o),td()}),y.addEventListener("click",()=>tg("ask"===eq?"fields":"ask")),A.addEventListener("click",()=>{tv(!1),tg("fields"),e4()}),S.addEventListener("click",()=>{for(let e=e3();e;e=e3())tx(e,!1);tg("fields"),e4()}),ek.addEventListener("click",()=>{let e=n.getState().undoSteps,t=void 0===e?void 0:eK.find(t=>"kept"===t.status&&t.step===e);if(n.undo(),t){var r;t.status="undone",td(),r=`${o.undone}: ${t.summary}`,eN.textContent="",eN.textContent=r}ek.hidden&&es.focus()}),eE.addEventListener("click",()=>void tE("save")),eC.addEventListener("click",()=>void tE("publish")),eu.addEventListener("submit",e=>{e.preventDefault(),tk()}),es.addEventListener("input",()=>{tp(),td()}),es.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing||(e.preventDefault(),tk())}),ei.addEventListener("input",td),ei.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing||(e.preventDefault(),es.focus())});let tC=e=>{"Escape"===e.key&&!e.defaultPrevented&&tf()&&e.preventDefault()};e.addEventListener("keydown",tC);let tA=e=>{let r=e.target,n=r?.closest?.(`[${t}]`),a=n?.getAttribute(t)??null;a!==eZ&&(eZ=a,tr())},tN=()=>{eZ=null,tr()};e.addEventListener("pointerover",tA),l.addEventListener("pointerleave",tN),s?.addEventListener("scroll",tr,{capture:!0,passive:!0}),s?.addEventListener("resize",tr);let tS=s?.MutationObserver,tL="function"==typeof tS?new tS(tr):null;tL?.observe(e.body,{childList:!0,subtree:!0});let tP=s?.ResizeObserver,t$="function"==typeof tP?new tP(tr):null;t$?.observe(l);let tM=s?.matchMedia?.("(min-width: 768px)")??null;eJ=tM?.matches??!0;let tU=()=>{eJ=tM?.matches??!0,td()};tM?.addEventListener?.("change",tU);let tz=n.on("change",tl);return l.setAttribute("data-obelism-editor",""),e.head.appendChild(u),e.body.appendChild(p),td(),()=>{e1=!0,tz(),e2.unmount(),null!==tt&&s?.cancelAnimationFrame?.(tt),e.removeEventListener("keydown",tC),e.removeEventListener("pointerover",tA),l.removeEventListener("pointerleave",tN),s?.removeEventListener("scroll",tr,{capture:!0}),s?.removeEventListener("resize",tr),tM?.removeEventListener?.("change",tU),tL?.disconnect(),t$?.disconnect(),n.setSelecting(!1),l.removeAttribute("data-obelism-editor"),l.removeAttribute("data-obelism-docked"),l.style.removeProperty("--obelism-dock"),u.remove(),p.remove()}},ea=Symbol.for("@obelism/content/bridge"),ei=S({isEditing:!1,entryId:null,on:()=>{}},new URLSearchParams),eo=({url:e,prompt:o=!0,pagePath:l,productPath:d,collectionPath:p}={})=>{let u;if("u"<typeof window)return ei;let g=window;if(g[ea])return g[ea];if(g.ObelismBridge)u=S(g.ObelismBridge,new URLSearchParams(g.location.search));else{let f=(u=((e,r)=>{let n,a,o,s,l,d=new URLSearchParams(e.location.search),p=e.parent!==e&&d.has("cms_preview"),u=y(),g=[],f={...x,selecting:!0},w=e=>{f={...f,...e},u.emit("change",f)},k={isEditing:p,mode:p?"editor":null,entryId:d.get("cms_entry"),environment:d.get(i),product:null,collection:null,on:u.on,getState:()=>f,...E,destroy:()=>{g.splice(0).forEach(e=>e())}};if(!p)return k;let C=e.document,S=(t,n={})=>{e.parent.postMessage({source:m,type:t,...n},r)},L=C.createElement("style");L.textContent=v(),C.head.appendChild(L),g.push(()=>L.remove());let P=(e,t)=>{if(C.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),f.selectedUid!==(e??null)&&w({selectedUid:e??null}),!e)return;let r=C.querySelector(N(e));r&&(r.setAttribute("data-cms-selected",""),t&&r.scrollIntoView({behavior:"smooth",block:"center"}))},$=e=>{let r=e.target,n=r?.closest?.(`[${t}]`);if(!n)return;e.preventDefault(),e.stopPropagation();let a=n.getAttribute(t);P(a,!1),S("select",{uid:a})};C.addEventListener("click",$,!0),g.push(()=>C.removeEventListener("click",$,!0));let M=()=>Math.ceil(Math.max(C.documentElement.scrollHeight,C.body?.scrollHeight??0)),U=0,z=()=>{U=M(),S("ready",{url:e.location.href,height:U})},O=e.ResizeObserver;if("function"==typeof O){let e=new O(()=>{let e=M();e!==U&&(U=e,S("size",{height:e}))});e.observe(C.documentElement),C.body&&e.observe(C.body),g.push(()=>e.disconnect())}let I=new Map,j=0,T=e=>{let t=I.get(e);return t?(clearTimeout(t.timer),I.delete(e),0===I.size&&w({prompting:!1}),t):null};k.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!f.features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let n=`prompt_${++j}`,a=void 0===t.uid?f.selectedUid:t.uid;return new Promise((e,t)=>{let i=setTimeout(()=>{T(n)?.reject(Error("The editor did not answer in time"))},12e4);I.set(n,{resolve:e,reject:t,timer:i}),w({prompting:!0}),S("prompt",{id:n,prompt:r,uid:a})})},k.undo=()=>S("undo"),k.select=e=>{P(e,!1),S("select",{uid:e})};let R=null;g.push(()=>R?.destroy()),g.push(()=>{for(let e of I.keys())T(e)?.reject(Error("The bridge was destroyed"))});let D=(n=new WeakSet,a=null,o=null,s=!1,l=()=>{if(null!==a){for(let e of Array.from(C.styleSheets)){let t;if(!n.has(e)){try{t=e.cssRules}catch{continue}n.add(e),b(t,a)}}C.querySelectorAll('[style*="vh"]').forEach(e=>{h(e.style,a)})}},{freeze(e){if(null!==a||!(e>0))return;a=e,l();let t=C.defaultView?.MutationObserver;t&&(o=new t(()=>{if(s)return;s=!0;let e=()=>{s=!1,l()};C.defaultView?.requestAnimationFrame?C.defaultView.requestAnimationFrame(e):e()})).observe(C.documentElement,{childList:!0,subtree:!0})},destroy(){o?.disconnect()}});g.push(()=>D.destroy());let q=t=>{if(t.origin!==r||t.source!==e.parent)return;let n=t.data;if(n&&"obelism-content-editor"===n.source){if("connect"===n.type)z();else if("update"===n.type&&n.entry)u.emit("update",{entry:n.entry,selectedUid:n.selectedUid??null}),e.requestAnimationFrame(()=>P(n.selectedUid,!1)),R?.refresh();else if("select"===n.type)P(n.uid,!0);else if("saved"===n.type||"published"===n.type)u.emit(n.type,{}),0===u.listeners.update.size&&e.location.reload();else if("features"===n.type&&Array.isArray(n.features))w({features:n.features.filter(e=>"string"==typeof e)});else if("stats"===n.type)w({stats:A(n.stats),statsVisible:!1!==n.visible}),(R||Object.keys(f.stats).length)&&(R??(R=c(e,{selector:N,onSelect:e=>k.select(e)})),R.update(f.stats,f.statsVisible));else if("viewport"===n.type&&"number"==typeof n.height)D.freeze(n.height);else if("promptState"===n.type)w({canUndo:!0===n.canUndo});else if("promptResult"===n.type&&"string"==typeof n.id){let e=T(n.id);if(!e)return;!0===n.ok?e.resolve({summary:"string"==typeof n.summary?n.summary:""}):e.reject(Error("string"==typeof n.error?n.error:"The prompt failed"))}}};return e.addEventListener("message",q),g.push(()=>e.removeEventListener("message",q)),"loading"===C.readyState?(C.addEventListener("DOMContentLoaded",z,{once:!0}),g.push(()=>C.removeEventListener("DOMContentLoaded",z))):z(),k})(g,new URL(e||X).origin)).isEditing||g.parent!==g?null:(e=>{for(let t of e.cookie.split(";")){let[e,...r]=t.trim().split("=");if("obelism_content_editing"===e)try{let e=decodeURIComponent(r.join("="));return K.test(e)?e:null}catch{break}}return null})(g.document);if(f&&(u=((e,i,{pagePath:o=e=>`/${e.replace(/^\/+/,"")}`,productPath:l,collectionPath:d}={})=>{let p=e.document,u=y(),g=[],h=new Map,b=[],f=new Set,w=null,k=null,E=-1/0,C=new Map,S=x,L=e=>{S={...S,...e},u.emit("change",S)},P=()=>L({unsaved:[...h.values()].some(({content:e,saved:t})=>!Z(e,t)),canUndo:b.length>0,undoSteps:b.length}),$=async(t,r)=>{let n=await e.fetch(`${i}/api/${t}`,void 0===r?{credentials:"same-origin"}:{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-obelism-content":"1"},body:JSON.stringify(r)}),a=await n.json().catch(()=>({}));if(401===n.status)throw L({features:[]}),Error("You were signed out. Sign in again to edit.");if(!n.ok)throw Error("string"==typeof a.error?a.error:`Obelism Content answered ${n.status}`);return a},M=()=>p.querySelector(`[${r}]`)?.getAttribute(r)??null,U=()=>{let e=p.querySelector(`[${n}]`),t=e?.getAttribute(n),r=e?.getAttribute("data-cms-product-handle");return t&&r?{id:t,handle:r}:null},z=()=>{let e=p.querySelector(`[${a}]`),t=e?.getAttribute(a),r=e?.getAttribute("data-cms-collection-handle");return t&&r?{id:t,handle:r}:null},O=e=>{let t=e?p.querySelector(N(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??M()},I=()=>{if(!w)return;let e=w.space.locales.map(({code:e})=>e),t=p.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:w.space.defaultLocale},j=new Map,T=async e=>{let t=h.get(e);if(t)return t;let r=j.get(e);return r||(r=$(`entries/${encodeURIComponent(e)}`).then(t=>{let r=h.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return h.set(e,r),r}).finally(()=>j.delete(e)),j.set(e,r)),r},R=e=>{let t=void 0===e?S.selectedUid:e,r=O(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},D=e=>{p.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),S.selectedUid!==e&&L({selectedUid:e}),e&&p.querySelector(N(e))?.setAttribute("data-cms-selected","")},q=async t=>{if(0===u.listeners.update.size)return;let r=h.get(t)?.content,{entry:n}=await $(`entries/${encodeURIComponent(t)}/preview`,{content:r,locale:I()});u.emit("update",{entry:n,selectedUid:S.selectedUid}),e.requestAnimationFrame(()=>D(S.selectedUid))},F=e=>console.error("[@obelism/content bridge]",e),B=t=>{u.emit(t,{}),0===u.listeners.update.size&&e.location.reload()},V=async()=>{for(let[e,t]of h){if(Z(t.content,t.saved))continue;let{draftRevision:r}=await $(`entries/${encodeURIComponent(e)}/save`,{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,f.add(e)}b.length=0,E=-1/0,P()},H={isEditing:!0,mode:"site",get entryId(){return M()},get product(){return U()},get collection(){return z()},get environment(){return w?.environment??null},on:u.on,getState:()=>S,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!S.features.includes("prompt"))throw Error("You may not edit content here");let{uid:n,entryId:a}=R(t.uid);L({prompting:!0});try{let e=await T(a),t=await $(`entries/${encodeURIComponent(a)}/prompt`,{prompt:r,content:e.content,locale:I(),uid:n});return b.push({entryId:a,content:e.content}),E=-1/0,e.content=t.content,P(),await q(a),{summary:t.summary}}finally{L({prompting:!1})}},async createPage(t,r){let n=r.trim();if(!n)throw Error("Say what the page is for");if(!t.trim())throw Error("Say where the page goes, like /pricing");if(!S.features.includes("create"))throw Error("You may not add pages here");if(S.unsaved)throw Error("Save or undo your changes before adding a page");L({prompting:!0});try{let r=await $("entries",{path:t,prompt:n,locale:I(),from:M()}),a=o(r.path,I()??"");return e.location.assign(J(a)),{summary:r.summary,entryId:r.entryId,path:r.path,url:a}}finally{L({prompting:!1})}},async createProductPage(t=U()??void 0){if(!t)throw Error("Nothing on this page is marked as a product: add editableProduct(product)");if(!S.features.includes("create"))throw Error("You may not add pages here");if(S.unsaved)throw Error("Save or undo your changes before adding a page");L({prompting:!0});try{let r=await $("product-pages",{product:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{L({prompting:!1})}},async createCollectionPage(t=z()??void 0){if(!t)throw Error("Nothing on this page is marked as a collection: add editableCollection(collection)");if(!S.features.includes("create"))throw Error("You may not add pages here");if(S.unsaved)throw Error("Save or undo your changes before adding a page");L({prompting:!0});try{let r=await $("collection-pages",{collection:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{L({prompting:!1})}},async view(e={}){let{uid:t,entryId:r}=R(e.uid),n=await T(r),{view:a}=await $(`entries/${encodeURIComponent(r)}/view`,{content:n.content,locale:I(),uid:t});return a},async applyJson(e,t={}){if(!S.features.includes("prompt"))throw Error("You may not edit content here");if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Send the fields to change as an object");let{uid:r,entryId:n}=R(t.uid);L({prompting:!0});try{let t=await T(n),a=await $(`entries/${encodeURIComponent(n)}/apply`,{changes:e,content:t.content,locale:I(),uid:r});return Z(a.content,t.content)||(b.push({entryId:n,content:t.content}),E=-1/0,t.content=a.content,P(),await q(n)),{changed:a.changed??[],...a.view&&{view:a.view}}}finally{L({prompting:!1})}},openForm(t,r={}){let{title:n="Content form",onReady:a,onError:i,onEscape:o}=r;k?.();let s=!1,l=null,d=null,p=()=>{},c=e=>{s||i?.(e instanceof Error?e.message:String(e))},g=()=>{s||(s=!0,p(),l?.destroy(),k===g&&(k=null))};k=g;let f=()=>{if(s||!l)return;let e=O(S.selectedUid);if(!e)return;let t=h.get(e);if(!t)return void T(e).then(f,c);let r={entryId:e,content:t.content,locale:I(),selectedUid:S.selectedUid};d&&d.entryId===r.entryId&&d.content===r.content&&d.locale===r.locale&&d.selectedUid===r.selectedUid||(d=r,l.show(r))},v=(e,t)=>{let r=t??d?.entryId,n=void 0===r?void 0:h.get(r);if(s||void 0===r||!n||Z(e,n.content))return;let a=Date.now();a-E>=1e3&&b.push({entryId:r,content:n.content}),E=a,n.content=e,d?.entryId===r&&(d={...d,content:e}),P(),clearTimeout(C.get(r)),C.set(r,setTimeout(()=>{C.delete(r),q(r).catch(F)},300))};return(async()=>{if(!S.features.includes("form"))throw Error("You may not edit content here");await T(R(void 0).entryId);let{url:r}=await $("form",{});s||(l=((e,t,r,n,a)=>{let i=null;try{i=new URL(r)}catch{}if(!i||!/^https?:$/.test(i.protocol))throw Error("Obelism Content sent no form to open");let o=i.origin,s=t.ownerDocument.createElement("iframe");s.title=n,s.src=r;let l=!1,d=!1,p=null,c=()=>{l&&p&&s.contentWindow?.postMessage({source:m,type:"content",...p},o)},u=setTimeout(()=>{d||a.onError("The form did not open")},3e4),g=()=>{d=!0,clearTimeout(u),a.onReady()},h=e=>{if(e.origin!==o||!s.contentWindow||e.source!==s.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)l=!0,c(),!0!==t.loading&&g();else if("loaded"===t.type)l&&g();else{let e;if("change"!==t.type||!(e=t.content)||"object"!=typeof e||Array.isArray(e))if("height"===t.type){let e=t.height;if("number"==typeof e&&Number.isFinite(e)){let t=Math.round(Math.min(Math.max(e,80),4e3));s.style.height=`min(${t}px, 60vh)`}}else"escape"===t.type?a.onEscape?.():"error"===t.type&&a.onError("string"==typeof t.message&&t.message?t.message:"The form failed");else a.onChange(t.content,"string"==typeof t.entryId?t.entryId:void 0)}};return e.addEventListener("message",h),t.appendChild(s),{show(e){p=e,c()},destroy(){clearTimeout(u),e.removeEventListener("message",h),s.remove()}}})(e,t,"string"==typeof r?r:"",n,{onReady:()=>a?.(),onChange:v,onError:e=>i?.(e),onEscape:()=>o?.()}),p=u.on("change",f),f())})().catch(c),{close:g}},async pages(){let{pages:e}=await $("pages"),t=[I(),w?.space.defaultLocale];return e.flatMap(e=>{let r,n,a=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],i=void 0===a?void 0:e.paths[a];return void 0===a||void 0===i?[]:[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:i,url:e.product?(r=e.product.handle,l?l(r,a):(w?.productPath??"/products/{handle}").replaceAll("{handle}",encodeURIComponent(r))):e.collection?(n=e.collection.handle,d?d(n,a):(w?.collectionPath??"/collections/{handle}").replaceAll("{handle}",encodeURIComponent(n))):o(i,a),product:e.product??null,collection:e.collection??null}]})},openPage(t){(!S.unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(h.clear(),b.length=0,P(),e.location.assign(J(t.url)))},undo(){let e=b.pop(),t=e&&h.get(e.entryId);e&&t&&(E=-1/0,t.content=e.content,P(),q(e.entryId).catch(F))},async save(){if(!S.features.includes("save"))throw Error("You may not edit content here");L({saving:!0});try{await V()}finally{L({saving:!1})}B("saved")},async publish(){if(!S.features.includes("publish"))throw Error("You may not publish here");L({publishing:!0});try{await V();let e=M(),t=f.size>0?[...f]:e?[e]:[];if(0===t.length)throw Error("Nothing on this page is marked as an entry: add editable(entry)");for(let e of t)await $(`entries/${encodeURIComponent(e)}/publish`,{}),f.delete(e)}finally{L({publishing:!1})}B("published")},signOut(){if(S.unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;h.clear(),P();let t=e.location.pathname+e.location.search;e.location.href=`${i}/logout?return_to=${encodeURIComponent(t)}`},select(e){D(e)},setSelecting(e){e?p.documentElement.setAttribute("data-cms-selecting",""):p.documentElement.removeAttribute("data-cms-selecting"),L({selecting:e,statsVisible:e}),et()},destroy(){k?.(),C.forEach(e=>clearTimeout(e)),C.clear(),g.splice(0).forEach(e=>e())}},_=p.createElement("style");_.textContent=v("html[data-cms-selecting] "),p.head.appendChild(_),g.push(()=>_.remove()),g.push(()=>p.documentElement.removeAttribute("data-cms-selecting"));let W=e=>{if(!S.selecting)return;let r=e.target,n=r?.closest?.(`[${t}]`);n&&(e.preventDefault(),e.stopPropagation(),D(n.getAttribute(t)))};p.addEventListener("click",W,!0),g.push(()=>p.removeEventListener("click",W,!0));let Y=e=>{S.unsaved&&(e.preventDefault(),e.returnValue="")};e.addEventListener("beforeunload",Y),g.push(()=>e.removeEventListener("beforeunload",Y));let X=new Set,K=new Set,G=!1,Q=null,ee=null,et=()=>Q?.update(S.stats,S.statsVisible),er=async()=>{if(G)return;let t=[...new Set([...p.querySelectorAll(`[${s}]`)].map(e=>e.getAttribute(s)??""))].filter(e=>e&&!X.has(e)),n=t.slice(0,500);if(!n.length)return;n.forEach(e=>X.add(e));let a=[...new Set([...p.querySelectorAll(`[${r}]`)].map(e=>e.getAttribute(r)??""))].filter(Boolean).slice(0,20);try{let{stats:e}=await $("stats",{uids:n,...a.length>0&&{entries:a}});n.forEach(e=>K.add(e)),L({stats:{...S.stats,...A(e)}})}catch{G=!0;return}Q??(Q=c(e,{selector:N,onSelect:e=>D(e),checked:e=>K.has(e)})),et(),t.length>n.length&&en()},en=()=>{null!==ee||G||(ee=setTimeout(()=>{ee=null,er()},1e3))},ea=e.MutationObserver,ei="function"==typeof ea?new ea(en):null;return g.push(()=>{ei?.disconnect(),null!==ee&&clearTimeout(ee),Q?.destroy()}),$("session").then(e=>{w=e,L({features:e.features}),er(),ei?.observe(p.body,{childList:!0,subtree:!0})}).catch(e=>console.error("[@obelism/content bridge]",e)),H})(g,f,{pagePath:l,productPath:d,collectionPath:p})),u.isEditing&&o){let e=g.document,t=()=>{},r=!1,n=f?en:Y,a=()=>{r||(t=n(e,u,!0===o?{}:o))};e.body?a():e.addEventListener("DOMContentLoaded",a,{once:!0});let i=u.destroy;u.destroy=()=>{r=!0,e.removeEventListener("DOMContentLoaded",a),t(),i()}}}return g[ea]=u,u};(e=window).ObelismBridge=eo((e=>{let t=e?.dataset.url,r=t||X;if(!t&&e?.src){let t=new URL(e.src);"/bridge.js"===t.pathname&&(r=t.origin)}return{url:r,prompt:e?.dataset.prompt!=="false"}})(document.currentScript)),e.ObelismContent={getContentBridge:eo,mountPromptBox:Y,mountSiteEditor:en}}();
|
|
594
|
+
`,el=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},ed=e=>!!e&&"object"==typeof e&&!Array.isArray(e),ep=(e,t,r,n)=>{if(null!=e&&""!==e){if("object"!=typeof e)return void n.set(r,{label:t,text:String(e)});if(Array.isArray(e)){if(e.every(e=>null===e||"object"!=typeof e)){e.length&&n.set(r,{label:t,text:e.join(", ")});return}e.forEach((e,a)=>{let i=ed(e)&&"string"==typeof e._uid?e._uid:a,o=ed(e)&&"string"==typeof e._type?e._type:null;ep(e,o?el(o):t,`${r}/${i}`,n)});return}for(let[a,i]of Object.entries(e))"_uid"!==a&&"_type"!==a&&ep(i,t?`${t} \xb7 ${el(a)}`:el(a),`${r}/${a}`,n)}},ec=(e,n,a={})=>{let i,o={...R,...a.labels},l=e.defaultView,d=e.documentElement,p=(t,...r)=>P(e,"button",{className:t,type:"button"},...r),c=P(e,"div");c.setAttribute("data-obelism-content-editor","");let u=c.attachShadow({mode:"open"}),g=P(e,"style",{textContent:(i=`[${t}]`,`html[data-obelism-editor]{transition:margin-right .3s cubic-bezier(.2,.8,.2,1)}html[data-obelism-docked]{margin-right:436px!important}html[data-obelism-docked] [data-obelism-dock]{right:436px!important;max-width:calc(100vw - 436px)!important}html[data-obelism-editor][data-cms-selecting] ${i}:hover:not([data-cms-selected]){outline:none}html[data-obelism-editor][data-cms-selecting] ${i}[data-cms-selected]{outline:2px solid rgb(212 130 30);outline-offset:2px}@media (prefers-reduced-motion:reduce){html[data-obelism-editor]{transition:none}}`)}),h=P(e,"span",{className:"tile"},z(e,"mark",$)),b=P(e,"span"),m=p("page-button hit",b,P(e,"span",{className:"visually-hidden",textContent:`, ${o.pages}`}),j(e,"chevrons"));m.setAttribute("aria-haspopup","listbox"),m.setAttribute("aria-expanded","false"),m.setAttribute("aria-controls","obelism-pages");let f=P(e,"span",{className:"page-name"}),v=P(e,"span"),x=P(e,"span",{className:"env"},P(e,"span",{className:"visually-hidden",textContent:`${o.environment}: `}),v),y=p("icon-button hit",j(e,"dash"));y.setAttribute("aria-label",o.minimize),y.title=o.minimize;let w=p("mode hit",z(e,"mark",$),o.modePrompt);w.setAttribute("aria-pressed","false");let k=P(e,"div",{className:"head"},h,m,f,x,P(e,"span",{className:"spacer"}),w,y),E=F(e,n,o,{onLoad:()=>tp(),onClose:()=>tb(!1)}),C=p("button quiet new-page",j(e,"plus"),o.newPage),A=P(e,"div",{className:"pages"},E.searchRow,E.list,E.note,C),N=p("button primary",o.keep),S=p("button quiet",o.undo),L=P(e,"div",{className:"gate"},P(e,"p",{textContent:o.keepBeforeFields}),P(e,"div",{className:"actions"},N,S));L.setAttribute("role","alert");let I=P(e,"span"),D=p("",o.scopeEntry),q=p("",o.newPageCancel),B=P(e,"div",{className:"note"},j(e,"scope"),I,D,q),V=P(e,"p",{className:"intro",textContent:o.askIntro}),W=P(e,"p",{className:"summary"}),J=P(e,"span"),Z=p("button primary",j(e,"plus"),J),G=P(e,"div",{className:"shop"},W,Z),Q=P(e,"div",{className:"log"});Q.setAttribute("role","log");let ee=P(e,"div",{className:"scroll"},B,V,G,Q),et=P(e,"input",{type:"text",placeholder:o.pathPlaceholder,autocomplete:"off",spellcheck:!1}),er=P(e,"label",{className:"path"},P(e,"span",{textContent:o.path}),et),en=P(e,"textarea",{rows:1});en.setAttribute("aria-label",o.open);let ea=j(e,"arrowUp"),ei=z(e,"working",M),ec=P(e,"button",{className:"send",type:"submit",title:o.send},P(e,"span",{className:"visually-hidden",textContent:o.send}),ea,ei),eu=P(e,"div",{className:"bar"},z(e,"mark",$),en,ec),eg=P(e,"form",{className:"composer"},er,eu),eh=P(e,"div",{className:"ask",id:"obelism-ask"},ee,eg);eh.setAttribute("role","tabpanel"),eh.setAttribute("aria-label",o.modePrompt);let eb=P(e,"p",{className:"form-note"});eb.setAttribute("role","status");let em=P(e,"div",{className:"form"},eb),ef=P(e,"span"),ev=p("",o.scopeEntry),ex=P(e,"div",{className:"note"},j(e,"scope"),ef,ev),ey=P(e,"div",{className:"fields",id:"obelism-fields"},ex,em);ey.setAttribute("role","tabpanel"),ey.setAttribute("aria-label",o.form);let ew=P(e,"p",{className:"save-state"});ew.setAttribute("aria-live","polite");let ek=P(e,"slot");ek.name="actions-footer";let eE=p("button quiet",j(e,"undo"),o.undo),eC=p("button secondary",o.saveDraft),eA=p("button primary",o.publish),eN=P(e,"div",{className:"foot"},ew,ek,eE,eC,eA),eS=P(e,"p",{className:"visually-hidden"});eS.setAttribute("role","status");let eL=P(e,"aside",{className:"panel",id:"obelism-editor"},k,A,L,eh,ey,eN,eS);eL.setAttribute("aria-label",o.editor);let eP=p("launch",P(e,"span",{className:"launch-tile"},z(e,"mark",$)),o.editing);eP.setAttribute("aria-controls",eL.id);let e$=P(e,"span",{className:"reading"},P(e,"span",{className:"launch-tile"},z(e,"mark",$)),o.viewingDrafts),eM=j(e,"eye"),ez=j(e,"eyeOff"),eU=p("eye",eM,ez);eU.setAttribute("aria-label",o.hideOutlines),eU.title=o.hideOutlines;let eO=P(e,"slot");eO.name="actions-bar";let eI=p("exit",o.signOut),ej=P(e,"div",{className:"launcher"},eP,e$,eU,eO,eI);a.actions&&c.appendChild(a.actions);let eT=P(e,"div",{className:"layer"});eT.setAttribute("aria-hidden","true");let eD=P(e,"div",{className:"wash"});eD.setAttribute("aria-hidden","true");let eq=P(e,"div",{className:"root"},eD,eT,eL,ej);u.append(P(e,"style",{textContent:es}),eq);let eR=(e=>{try{return e?.localStorage.getItem(eo)!=="minimised"}catch{return!0}})(l),eF="fields",eB="fields",eV=!1,eW=!1,e_=!0,eH=!1,eY=null,eX=!1,eK=null,eJ=[],eZ=!0,eG=null,eQ=new Map,e0=new Map,e1="idle",e2=!1,e4=T(n,em,o.formTitle,{onReady:()=>{tp(),eR&&"fields"===eB&&e5()},onError:()=>tp(),onEscape:()=>tf()}),e5=()=>em.querySelector("iframe")?.focus(),e6=()=>eJ.filter(({status:e})=>"pending"===e),e3=()=>e6().slice(-1)[0]??null,e8=()=>eJ.some(({status:e})=>"working"===e)?null:e3(),e7=e=>(eQ.has(e)||"loading"===e1||(eQ.set(e,null),n.view({uid:e}).then(t=>{"string"==typeof t._type&&eQ.set(e,el(t._type)),tp()},()=>{})),eQ.get(e)??o.block),e9=(e,t=null)=>{if(Array.isArray(e))e.forEach(e=>e9(e,t));else if(ed(e)){let r=t;"string"==typeof e._uid&&"string"==typeof e._type&&(r=e._uid,e0.set(r,t),eQ.set(r,el(e._type))),Object.values(e).forEach(e=>e9(e,r))}},te=r=>e.querySelector(s(r))?.parentElement?.closest(`[${t}]`)?.getAttribute(t)??e0.get(r)??null,tt=()=>E.current()?.name||e.title.trim(),tr=null,tn=()=>{null===tr&&l&&(tr=l.requestAnimationFrame(()=>{tr=null,(t=>{if(eT.replaceChildren(),eD.replaceChildren(),!ti(t))return;let n=t=>{let r=e.querySelector(t),n=r?.getBoundingClientRect();return n&&(n.width||n.height)?n:null},a=(t,r,n=eT)=>{let a=P(e,"div",{className:`box ${r}`});Object.assign(a.style,{top:`${t.top-3}px`,left:`${t.left-3}px`,width:`${t.width+6}px`,height:`${t.height+6}px`}),n.appendChild(a)},i=(t,...r)=>{let n=P(e,"div",{className:"chips"},...r),a=t.top-34<0?t.top+6:t.top-34;Object.assign(n.style,{top:`${a}px`,left:`${t.left-3}px`}),eT.appendChild(n)},l=(t,r)=>{let n=P(e,"span",{className:"accent-chip"});return r&&n.appendChild(z(e,"mark",$)),n.appendChild(e.createTextNode(t)),n},d=e3(),p=d?d.uid?s(d.uid):`[${r}]`:null,c=p?n(p):null;if(c&&a(c,"fill",eD),eG&&eG!==t.selectedUid){let t=n(s(eG));if(t){a(t,"hover");let r=t.top-23<0,n=P(e,"span",{className:`name-tab${r?" inside":""}`,textContent:e7(eG)});Object.assign(n.style,{top:`${r?t.top-1.5:t.top-23}px`,left:`${t.left-3}px`}),eT.appendChild(n)}}let u=!!d&&d.uid===t.selectedUid;if(t.selectedUid){let r=n(s(t.selectedUid));if(r){let n=e7(t.selectedUid),a=tt();i(r,l(u?U(o.previewChip,{name:n}):n,u),...a?[P(e,"span",{className:"ink-chip",textContent:a})]:[])}}if(c&&!u){a(c,"preview");let e=d.uid?e7(d.uid):tt()||o.pages;i(c,l(U(o.previewChip,{name:e}),!0))}})(n.getState())}))},ta=e=>e.features.includes("prompt")&&eR,ti=e=>ta(e)&&e_&&!eW,to=t=>P(e,"span",{className:`value${t?"":" none"}`,textContent:t||o.emptyValue}),ts=t=>{let r=t.node.querySelector(".card");if(r.querySelector(".status-line")?.remove(),"failed"===t.status)return void r.appendChild(P(e,"p",{className:"failure"},j(e,"alert"),t.summary));for(let n of(r.appendChild(t.eyebrow),t.summary&&r.appendChild(P(e,"p",{className:"summary",textContent:t.summary})),t.diffs.slice(0,3))){let a=P(e,"div",{className:"diff-field"},P(e,"span",{className:"diff-label",textContent:n.label}),P(e,"div",{className:"diff"},P(e,"div",{className:"before"},P(e,"span",{className:"tag",textContent:o.before}),to(n.before)),P(e,"div",{className:"after"},P(e,"span",{className:"tag",textContent:o.after}),to(n.after))));t.details.push(a),r.appendChild(a)}if(t.diffs.length>3){let n=P(e,"p",{className:"more",textContent:U(o.moreChanges,{count:t.diffs.length-3})});t.details.push(n),r.appendChild(n)}if("pending"===t.status){let n=p("button primary",o.keep),a=p("button secondary",o.retry),i=p("button quiet",o.undo);n.addEventListener("click",()=>tv()),a.addEventListener("click",()=>void tw(t)),i.addEventListener("click",()=>tx(t)),t.actions=P(e,"div",{className:"actions"},n,a,i),r.appendChild(t.actions)}},tl=(t,r)=>{let n=P(e,"div",{className:"card"},P(e,"span",{className:"visually-hidden",textContent:`${o.obelism}: `}),P(e,"p",{className:"status-line"},z(e,"working",M),eW?o.creating:o.working)),a=P(e,"div",{className:"answer"},P(e,"span",{className:"chip"},z(e,"mark",$)),n);a.dataset.status="working";let i={prompt:t,uid:r,status:"working",summary:"",diffs:[],step:null,node:a,eyebrow:P(e,"p",{className:"eyebrow"}),actions:null,details:[]};return eJ.push(i),Q.appendChild(a),i},td=t=>{if(e2)return;let r=K(n,t,{creating:eW},{promptWithoutPage:a.promptWithoutPage,signOut:a.signOut,labels:o}),{available:i,busy:s,canCreate:l,pageless:c,site:u,shop:g,onlyNew:h}=r,{storing:y}=r,k=r.canForm&&t.features.includes("form"),$=i&&eR;eW=r.creating,eB=k?eF:"ask";let O=e6().length>0;for(let e of(O&&"fields"!==eB||(eV=!1),eJ))null!==e.step&&e.step>(t.undoSteps??0)&&(e.step=null);eq.hidden=!i&&!u,eL.toggleAttribute("data-closed",!$),eL.inert=!$,eP.hidden=!i,eP.setAttribute("aria-expanded",String($)),e$.hidden=i,eU.hidden=!$,eU.setAttribute("aria-pressed",String(!e_)),eM.hidden=!e_,ez.hidden=e_,eI.hidden=!r.showSignOut;let T=$&&eZ;d.toggleAttribute("data-obelism-docked",T),d.style.setProperty("--obelism-dock",`${436*!!T}px`);let R=$&&e_&&!eW;t.selecting!==R&&n.setSelecting(R);let F=$&&"fields"===eB;F&&!e4.mounted?e4.mount():!F&&e4.mounted&&e4.unmount(),eH&&!$&&(eH=!1),b.textContent=tt()||o.pages,m.hidden=null===E.pages&&null!==E.error,f.hidden=!m.hidden,f.textContent=tt()||o.pages,m.setAttribute("aria-expanded",String(eH)),A.hidden=!eH,C.hidden=!l||eW,C.disabled=s;let H=n.environment;x.hidden=!H,x.dataset.env=H??"",v.textContent="production"===H?o.envProduction:H??"",w.hidden=!k,w.setAttribute("aria-pressed",String("ask"===eB)),w.disabled=s,L.hidden=!eV,N.disabled=S.disabled=s,eh.hidden="ask"!==eB,ey.hidden="fields"!==eB;let Y=r.offerShop;if(eW)I.textContent=o.newPage;else if(t.selectedUid){let[r,n=""]=o.scopeNoteBlock.split("{name}");for(let a of[I,ef])a.replaceChildren(r??"",P(e,"strong",{textContent:e7(t.selectedUid)}),n)}else I.textContent=o.scopeNotePage;let X=t.selectedUid?te(t.selectedUid):null,Q=X?U(o.scopeUp,{name:e7(X)}):o.scopeEntry;for(let e of[D,ev])e.textContent!==Q&&(e.textContent=Q);ex.hidden=eW||!t.selectedUid,B.hidden=Y||c&&!eW&&!a.promptWithoutPage,D.hidden=eW||!t.selectedUid,q.hidden=!eW||h,V.hidden=eJ.length>0||Y||eW,G.hidden=!Y;let ee=g?_(o,g):null;J.textContent=ee?t.prompting&&Y?ee.adding:ee.add:"",Z.disabled=s,W.textContent=eK?.text??ee?.hint??"",W.className=eK?.error?"failure":"summary",eg.hidden=Y,er.hidden=!eW,et.disabled=s,en.placeholder=r.placeholder,en.disabled=s,ec.disabled=!r.canSend(en.value,et.value),ec.setAttribute("aria-busy",String(t.prompting)),ea.hidden=t.prompting,ei.hidden=!t.prompting,eE.hidden=O||!t.canUndo||eW,eE.disabled=s,eC.hidden=!r.canSave,eC.disabled=s||O||!t.unsaved,eA.hidden=!r.canPublish,eA.disabled=s||O,a.actions&&(a.actions.slot=$?"actions-footer":"actions-bar"),eN.hidden=!u,t.unsaved&&!eX&&(eY=null),eX=t.unsaved;let eo=y?z(e,"working",M):eY?.kind==="error"?j(e,"alert"):O||t.unsaved?P(e,"span",{className:"dot"}):j(e,"check"),es=t.saving?o.saving:t.publishing?o.publishing:eY?.kind==="error"?`${"save"===eY.action?o.saveFailed:o.publishFailed}: ${eY.text}`:O?o.keepFirst:t.unsaved?o.unsaved:eY?.kind==="saved"?o.saved:eY?.kind==="published"?o.published:o.upToDate,el=y?"saving":eY?.kind==="error"?"error":O||t.unsaved?"unsaved":"saved";if((ew.dataset.state!==el||ew.dataset.text!==es)&&(ew.dataset.state=el,ew.dataset.text=es,ew.replaceChildren(eo,P(e,"span",{textContent:es})),eY?.kind==="error"&&!y)){let e=eY.action,t=p("link",o.tryAgain);t.addEventListener("click",()=>void tE(e)),ew.appendChild(t)}em.classList.toggle("loading",e4.loading||null!==e4.error),eb.hidden=!e4.loading&&null===e4.error,eb.className=`form-note${null!==e4.error?" error":""}`,eb.textContent=e4.error??o.formLoading;let ed=e8();for(let e of eJ){if("working"===e.status||"failed"===e.status)continue;e.node.dataset.status=e.status;let t="pending"===e.status?o.suggested:"kept"===e.status?o.kept:o.undone;for(let r of(e.eyebrow.textContent!==t&&(e.eyebrow.textContent=t),e.actions&&(e.actions.hidden=e!==ed),e.details))r.hidden="undone"===e.status}$&&((()=>{if("idle"!==e1||null===n.entryId)return;e1="loading";let e=()=>{e1="done",tp()};n.view({uid:null}).then(t=>{e9(t),e()},e)})(),null===E.pages&&null===E.error&&E.fetch()),tn()},tp=()=>td(n.getState()),tc=()=>{ee.scrollTop=ee.scrollHeight},tu=e=>{eR=e;try{l?.localStorage.setItem(eo,eR?"open":"minimised")}catch{}eR||(eH=!1),tp(),eR?eW?et.focus():"fields"===eB?e5():en.focus():eP.focus()},tg=e=>{if("fields"===e&&e6().length>0){eV=!0,tp(),N.focus();return}if(eV=!1,eF===e)return tp();eF=e,tp()},th=e=>{eH=!1,(eW=e)&&n.select(null),tp(),(eW?et:en).focus()},tb=e=>{(eH=e)&&E.reset(),tp(),(eH?E.search:m).focus()},tm=()=>{let{selectedUid:e}=n.getState();return e&&n.select(te(e)),!n.getState().selectedUid},tf=()=>{let e=n.getState();if(!ta(e))return!1;if(eH)tb(!1);else{if(!e.selectedUid)return!1;tm()}return!0},tv=(e=!0)=>{let t=e6();t.length&&e8()&&(t.forEach(e=>{e.status="kept"}),tp(),e&&en.focus())},tx=(e,t=!0)=>{e===e8()&&(n.undo(),e.status="undone",tp(),t&&en.focus())},ty=async(e,t)=>{let r={uid:e.uid},a=await n.view(r).catch(()=>null);try{let{summary:i}=await n.prompt(t,r);e.step=n.getState().undoSteps??null;let o=a?await n.view(r).catch(()=>null):null;e.summary=i,e.diffs=a&&o?((e,t)=>{let r=new Map,n=new Map;ep(e,"","",r),ep(t,"","",n);let a=[];for(let e of new Set([...r.keys(),...n.keys()])){let t=r.get(e),i=n.get(e);t?.text!==i?.text&&a.push({label:(i??t).label,before:t?.text??"",after:i?.text??""})}return a})(a,o):[],e.status="pending"}catch(t){e.summary=H(t),e.status="failed"}ts(e),tp(),tc()},tw=async e=>{if(e!==e8())return;n.undo(),e.status="undone";let t=tl(e.prompt,e.uid);tp(),tc(),en.focus(),await ty(t,U(o.retryPrompt,{prompt:e.prompt}))},tk=async()=>{let t=en.value.trim(),r=n.getState();if(!t||r.prompting)return;let a=et.value.trim();if(eW&&!a)return et.focus();let i=eW?null:r.selectedUid,s=eW?`${o.newPage} \xb7 ${a}`:i?e7(i):o.scopeEntry;Q.appendChild(P(e,"p",{className:"bubble"},P(e,"span",{className:"visually-hidden",textContent:`${o.you} (${s}): `}),t)),en.value="",O(en);let l=tl(t,i);if(tp(),tc(),eW){try{await n.createPage(a,t),E.forget(),l.summary=o.created,l.status="kept"}catch(e){l.summary=H(e),l.status="failed"}ts(l),tp()}else await ty(l,t);en.focus()},tE=async e=>{eY=null;let t=await X(n,e);eY=t?{kind:"error",action:e,text:t}:{kind:"save"===e?"saved":"published"},tp()};eP.addEventListener("click",()=>tu(!eR)),y.addEventListener("click",()=>tu(!1)),eU.addEventListener("click",()=>{e_=!e_,tp()}),eI.addEventListener("click",()=>n.signOut()),m.addEventListener("click",()=>tb(!eH)),C.addEventListener("click",()=>th(!0)),q.addEventListener("click",()=>th(!1)),D.addEventListener("click",()=>{tm()&&en.focus()}),ev.addEventListener("click",()=>{tm()&&e5()}),Z.addEventListener("click",async()=>{eK=null,eK=await Y(n,o),tp()}),w.addEventListener("click",()=>tg("ask"===eF?"fields":"ask")),N.addEventListener("click",()=>{tv(!1),tg("fields"),e5()}),S.addEventListener("click",()=>{for(let e=e8();e;e=e8())tx(e,!1);tg("fields"),e5()}),eE.addEventListener("click",()=>{let e=n.getState().undoSteps,t=void 0===e?void 0:eJ.find(t=>"kept"===t.status&&t.step===e);if(n.undo(),t){var r;t.status="undone",tp(),r=`${o.undone}: ${t.summary}`,eS.textContent="",eS.textContent=r}eE.hidden&&en.focus()}),eC.addEventListener("click",()=>void tE("save")),eA.addEventListener("click",()=>void tE("publish")),eg.addEventListener("submit",e=>{e.preventDefault(),tk()}),en.addEventListener("input",()=>{O(en),tp()}),en.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing||(e.preventDefault(),tk())}),et.addEventListener("input",tp),et.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing||(e.preventDefault(),en.focus())});let tC=e=>{"Escape"===e.key&&!e.defaultPrevented&&tf()&&e.preventDefault()};e.addEventListener("keydown",tC);let tA=e=>{let r=e.target,n=r?.closest?.(`[${t}]`),a=n?.getAttribute(t)??null;a!==eG&&(eG=a,tn())},tN=()=>{eG=null,tn()};e.addEventListener("pointerover",tA),d.addEventListener("pointerleave",tN),l?.addEventListener("scroll",tn,{capture:!0,passive:!0}),l?.addEventListener("resize",tn);let tS=l?.MutationObserver,tL="function"==typeof tS?new tS(tn):null;tL?.observe(e.body,{childList:!0,subtree:!0});let tP=l?.ResizeObserver,t$="function"==typeof tP?new tP(tn):null;t$?.observe(d);let tM=l?.matchMedia?.("(min-width: 768px)")??null;eZ=tM?.matches??!0;let tz=()=>{eZ=tM?.matches??!0,tp()};tM?.addEventListener?.("change",tz);let tU=n.on("change",td);return d.setAttribute("data-obelism-editor",""),e.head.appendChild(g),e.body.appendChild(c),tp(),()=>{e2=!0,tU(),e4.unmount(),null!==tr&&l?.cancelAnimationFrame?.(tr),e.removeEventListener("keydown",tC),e.removeEventListener("pointerover",tA),d.removeEventListener("pointerleave",tN),l?.removeEventListener("scroll",tn,{capture:!0}),l?.removeEventListener("resize",tn),tM?.removeEventListener?.("change",tz),tL?.disconnect(),t$?.disconnect(),n.setSelecting(!1),d.removeAttribute("data-obelism-editor"),d.removeAttribute("data-obelism-docked"),d.style.removeProperty("--obelism-dock"),g.remove(),c.remove()}},eu=Symbol.for("@obelism/content/bridge"),eg=f(),eh=({url:e,prompt:i=!0,pagePath:u,productPath:h,collectionPath:b}={})=>{let x;if("u"<typeof window)return eg;let w=window;if(w[eu])return w[eu];if(w.ObelismBridge){var k,E;let e,t;k=w.ObelismBridge,E=new URLSearchParams(w.location.search),e=l(),k.on("saved",()=>e.emit("saved",{})),k.on("published",()=>e.emit("published",{})),t=!1,x={...f(),isEditing:k.isEditing,mode:k.isEditing?"editor":null,entryId:k.entryId,environment:E.get(v),on:(r,n)=>("update"!==r||t||(t=!0,k.on("update",t=>{let r=t?.entry;r&&e.emit("update",{entry:r,selectedUid:null})})),e.on(r,n))}}else{let l,f=(x=((e,r)=>{let i,l,u,h,b,f=new URLSearchParams(e.location.search),x=e.parent!==e&&f.has("cms_preview"),{on:y,getState:w,setState:k,emit:E,listeners:A}=d({...a,selecting:!0}),N=[],P={isEditing:x,mode:x?"editor":null,entryId:f.get("cms_entry"),environment:f.get(v),product:null,collection:null,on:y,getState:w,...m,destroy:()=>{N.splice(0).forEach(e=>e())}};if(!x)return P;let $=e.document,M=(t,a={})=>{e.parent.postMessage({source:n,type:t,...a},r)},z=$.createElement("style");z.textContent=o(),$.head.appendChild(z),N.push(()=>z.remove());let U=(e,t)=>{w().selectedUid!==(e??null)&&k({selectedUid:e??null}),p($,e,t)},O=e=>{let r=e.target,n=r?.closest?.(`[${t}]`);if(!n)return;e.preventDefault(),e.stopPropagation();let a=n.getAttribute(t);U(a,!1),M("select",{uid:a})};$.addEventListener("click",O,!0),N.push(()=>$.removeEventListener("click",O,!0));let I=()=>Math.ceil(Math.max($.documentElement.scrollHeight,$.body?.scrollHeight??0)),j=0,T=()=>{j=I(),M("ready",{url:e.location.href,height:j})},D=e.ResizeObserver;if("function"==typeof D){let e=new D(()=>{let e=I();e!==j&&(j=e,M("size",{height:e}))});e.observe($.documentElement),$.body&&e.observe($.body),N.push(()=>e.disconnect())}let q=new Map,R=0,F=e=>{let t=q.get(e);return t?(clearTimeout(t.timer),q.delete(e),0===q.size&&k({prompting:!1}),t):null};P.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!w().features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let n=`prompt_${++R}`,a=void 0===t.uid?w().selectedUid:t.uid;return new Promise((e,t)=>{let i=setTimeout(()=>{F(n)?.reject(Error("The editor did not answer in time"))},12e4);q.set(n,{resolve:e,reject:t,timer:i}),k({prompting:!0}),M("prompt",{id:n,prompt:r,uid:a})})},P.undo=()=>M("undo"),P.select=e=>{U(e,!1),M("select",{uid:e})};let B=c(()=>C(e,{selector:s,onSelect:e=>P.select(e)}));N.push(()=>B.destroy()),N.push(()=>{for(let e of q.keys())F(e)?.reject(Error("The bridge was destroyed"))});let V=(i=new WeakSet,l=null,u=null,h=!1,b=()=>{if(null!==l){for(let e of Array.from($.styleSheets)){let t;if(!i.has(e)){try{t=e.cssRules}catch{continue}i.add(e),L(t,l)}}$.querySelectorAll('[style*="vh"]').forEach(e=>{S(e.style,l)})}},{freeze(e){if(null!==l||!(e>0))return;l=e,b();let t=$.defaultView?.MutationObserver;t&&(u=new t(()=>{if(h)return;h=!0;let e=()=>{h=!1,b()};$.defaultView?.requestAnimationFrame?$.defaultView.requestAnimationFrame(e):e()})).observe($.documentElement,{childList:!0,subtree:!0})},destroy(){u?.disconnect()}});N.push(()=>V.destroy());let W=t=>{if(t.origin!==r||t.source!==e.parent)return;let n=t.data;if(n&&"obelism-content-editor"===n.source){if("connect"===n.type)T();else if("update"===n.type&&n.entry)E("update",{entry:n.entry,selectedUid:n.selectedUid??null}),e.requestAnimationFrame(()=>U(n.selectedUid,!1)),B.refresh();else if("select"===n.type)U(n.uid,!0);else if("saved"===n.type||"published"===n.type)E(n.type,{}),0===A.update.size&&e.location.reload();else if("features"===n.type&&Array.isArray(n.features))k({features:n.features.filter(e=>"string"==typeof e)});else if("stats"===n.type){k({stats:g(n.stats),statsVisible:!1!==n.visible});let{stats:e,statsVisible:t}=w();B.update(e,t)}else if("viewport"===n.type&&"number"==typeof n.height)V.freeze(n.height);else if("promptState"===n.type)k({canUndo:!0===n.canUndo});else if("promptResult"===n.type&&"string"==typeof n.id){let e=F(n.id);if(!e)return;!0===n.ok?e.resolve({summary:"string"==typeof n.summary?n.summary:""}):e.reject(Error("string"==typeof n.error?n.error:"The prompt failed"))}}};return e.addEventListener("message",W),N.push(()=>e.removeEventListener("message",W)),"loading"===$.readyState?($.addEventListener("DOMContentLoaded",T,{once:!0}),N.push(()=>$.removeEventListener("DOMContentLoaded",T))):T(),P})(w,new URL(e||Q).origin)).isEditing||w.parent!==w?null:(l=(e=>{let t=new Map;for(let r of e.split(";")){let e=r.indexOf("=");if(e<0)continue;let n=r.slice(0,e).trim();if(!(!n||t.has(n)))try{t.set(n,decodeURIComponent(r.slice(e+1).trim()))}catch{t.set(n,r.slice(e+1).trim())}}return t})(w.document.cookie).get("obelism_content_editing"))&&en.test(l)?l:null;if(f&&(x=((e,a,{pagePath:i=e=>`/${e.replace(/^\/+/,"")}`,productPath:l,collectionPath:u}={})=>{let h=e.document,{on:b,getState:m,setState:f,emit:v,listeners:x}=d(),w=[],k=new Map,E=[],A=new Set,N=null,S=null,L=-1/0,P=new Map,$=()=>f({unsaved:[...k.values()].some(({content:e,saved:t})=>!ei(e,t)),canUndo:E.length>0,undoSteps:E.length}),M=async(t,r)=>{let n=await e.fetch(`${a}/api/${t}`,void 0===r?{credentials:"same-origin"}:{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-obelism-content":"1"},body:JSON.stringify(r)}),i=await n.json().catch(()=>({}));if(401===n.status)throw f({features:[]}),Error("You were signed out. Sign in again to edit.");if(!n.ok)throw Error("string"==typeof i.error?i.error:`Obelism Content answered ${n.status}`);return i},z=()=>h.querySelector(`[${r}]`)?.getAttribute(r)??null,U=e=>{let t=e?h.querySelector(s(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??z()},O=()=>{if(!N)return;let e=N.space.locales.map(({code:e})=>e),t=h.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:N.space.defaultLocale},I=new Map,j=async e=>{let t=k.get(e);if(t)return t;let r=I.get(e);return r||(r=M(ee(e)).then(t=>{let r=k.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return k.set(e,r),r}).finally(()=>I.delete(e)),I.set(e,r)),r},T=e=>{let t=void 0===e?m().selectedUid:e,r=U(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},D=new Set,q=new Set,R=new Set,F=c(()=>C(e,{selector:s,onSelect:e=>_(e),checked:e=>R.has(e),shows:(e,r)=>D.has(r.closest(`[${t}]`)?.getAttribute(t)??e)})),_=e=>{m().selectedUid!==e&&f({selectedUid:e}),p(h,e),e&&!D.has(e)&&(D.add(e),F.refresh())},H=async t=>{if(0===x.update.size)return;let r=k.get(t)?.content,{entry:n}=await M(ee(t,"/preview"),{content:r,locale:O()});v("update",{entry:n,selectedUid:m().selectedUid}),e.requestAnimationFrame(()=>_(m().selectedUid))},Y=e=>console.error("[@obelism/content bridge]",e),X=t=>{v(t,{}),0===x.update.size&&e.location.reload()},K=async()=>{for(let[e,t]of k){if(ei(t.content,t.saved))continue;let{draftRevision:r}=await M(et(e),{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,A.add(e)}E.length=0,L=-1/0,$()},J=e=>m().features.includes(e),Z=async(t,r)=>{let n=B[t];if(!r)throw Error(`Nothing on this page is marked as a ${t}: add ${n.marker}`);if(!J("create"))throw Error("You may not add pages here");if(m().unsaved)throw Error("Save or undo your changes before adding a page");f({prompting:!0});try{let n,a=await M((n=t,`${n}-pages`),{[t]:{id:r.id,handle:r.handle}});return e.location.reload(),a}finally{f({prompting:!1})}},G=h.createElement("style");G.textContent=o("html[data-cms-selecting] "),h.head.appendChild(G),w.push(()=>G.remove()),w.push(()=>h.documentElement.removeAttribute("data-cms-selecting"));let Q=e=>{if(!m().selecting)return;let r=e.target,n=r?.closest?.(`[${t}]`),a=n?null:r?.closest?.(`[${y}]`),i=a?.getAttribute(y);if(i&&R.has(i)){e.preventDefault(),e.stopPropagation(),D.has(i)||(D.add(i),F.refresh());return}n&&(e.preventDefault(),e.stopPropagation(),_(n.getAttribute(t)))};h.addEventListener("click",Q,!0),w.push(()=>h.removeEventListener("click",Q,!0));let en=e=>{m().unsaved&&(e.preventDefault(),e.returnValue="")};e.addEventListener("beforeunload",en),w.push(()=>e.removeEventListener("beforeunload",en));let eo=!1,es=null,el=()=>F.update(m().stats,m().statsVisible),ed=async()=>{if(eo)return;let e=[...new Set([...h.querySelectorAll(`[${y}]`)].map(e=>e.getAttribute(y)??""))].filter(e=>e&&!q.has(e)),t=e.slice(0,500);if(!t.length)return;t.forEach(e=>q.add(e));let n=[...new Set([...h.querySelectorAll(`[${r}]`)].map(e=>e.getAttribute(r)??""))].filter(Boolean).slice(0,20);try{let{stats:e}=await M("stats",{uids:t,...n.length>0&&{entries:n}});t.forEach(e=>R.add(e)),f({stats:{...m().stats,...g(e)}})}catch{eo=!0;return}el(),e.length>t.length&&ep()},ep=()=>{null!==es||eo||(es=setTimeout(()=>{es=null,ed()},1e3))},ec=e.MutationObserver,eu="function"==typeof ec?new ec(ep):null;return w.push(()=>{eu?.disconnect(),null!==es&&clearTimeout(es),F.destroy()}),M("session").then(e=>{N=e,f({features:e.features}),ed(),eu?.observe(h.body,{childList:!0,subtree:!0})}).catch(e=>console.error("[@obelism/content bridge]",e)),{isEditing:!0,mode:"site",get entryId(){return z()},get product(){return V(h,"product")},get collection(){return V(h,"collection")},get environment(){return N?.environment??null},on:b,getState:m,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!J("prompt"))throw Error("You may not edit content here");let{uid:n,entryId:a}=T(t.uid);f({prompting:!0});try{let e,t=await j(a),i=await M((e=a,ee(e,"/prompt")),{prompt:r,content:t.content,locale:O(),uid:n});return E.push({entryId:a,content:t.content}),L=-1/0,t.content=i.content,$(),await H(a),{summary:i.summary}}finally{f({prompting:!1})}},async createPage(t,r){let n=r.trim();if(!n)throw Error("Say what the page is for");if(!t.trim())throw Error("Say where the page goes, like /pricing");if(!J("create"))throw Error("You may not add pages here");if(m().unsaved)throw Error("Save or undo your changes before adding a page");f({prompting:!0});try{let r=await M("entries",{path:t,prompt:n,locale:O(),from:z()}),a=i(r.path,O()??"");return e.location.assign(ea(a)),{summary:r.summary,entryId:r.entryId,path:r.path,url:a}}finally{f({prompting:!1})}},createProductPage:(e=V(h,"product")??void 0)=>Z("product",e),createCollectionPage:(e=V(h,"collection")??void 0)=>Z("collection",e),async view(e={}){let{uid:t,entryId:r}=T(e.uid),n=await j(r),{view:a}=await M(ee(r,"/view"),{content:n.content,locale:O(),uid:t});return a},async applyJson(e,t={}){if(!J("prompt"))throw Error("You may not edit content here");if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Send the fields to change as an object");let{uid:r,entryId:n}=T(t.uid);f({prompting:!0});try{let t,a=await j(n),i=await M((t=n,ee(t,"/apply")),{changes:e,content:a.content,locale:O(),uid:r});return ei(i.content,a.content)||(E.push({entryId:n,content:a.content}),L=-1/0,a.content=i.content,$(),await H(n)),{changed:i.changed??[],...i.view&&{view:i.view}}}finally{f({prompting:!1})}},openForm(t,r={}){let{title:a="Content form",onReady:i,onError:o,onEscape:s}=r;S?.();let l=!1,d=null,p=null,c=()=>{},u=e=>{l||o?.(e instanceof Error?e.message:String(e))},g=()=>{l||(l=!0,c(),d?.destroy(),S===g&&(S=null))};S=g;let h=()=>{if(l||!d)return;let e=U(m().selectedUid);if(!e)return;let t=k.get(e);if(!t)return void j(e).then(h,u);let r={entryId:e,content:t.content,locale:O(),selectedUid:m().selectedUid};p&&p.entryId===r.entryId&&p.content===r.content&&p.locale===r.locale&&p.selectedUid===r.selectedUid||(p=r,d.show(r))},f=(e,t)=>{let r=t??p?.entryId,n=void 0===r?void 0:k.get(r);if(l||void 0===r||!n||ei(e,n.content))return;let a=Date.now();a-L>=1e3&&E.push({entryId:r,content:n.content}),L=a,n.content=e,p?.entryId===r&&(p={...p,content:e}),$(),clearTimeout(P.get(r)),P.set(r,setTimeout(()=>{P.delete(r),H(r).catch(Y)},300))};return(async()=>{if(!J("form"))throw Error("You may not edit content here");await j(T(void 0).entryId);let{url:r}=await M("form",{});l||(d=((e,t,r,a,i)=>{let o=null;try{o=new URL(r)}catch{}if(!o||!/^https?:$/.test(o.protocol))throw Error("Obelism Content sent no form to open");let s=o.origin,l=t.ownerDocument.createElement("iframe");l.title=a,l.src=r;let d=!1,p=!1,c=null,u=()=>{d&&c&&l.contentWindow?.postMessage({source:n,type:"content",...c},s)},g=setTimeout(()=>{p||i.onError("The form did not open")},3e4),h=()=>{p=!0,clearTimeout(g),i.onReady()},b=e=>{if(e.origin!==s||!l.contentWindow||e.source!==l.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)d=!0,u(),!0!==t.loading&&h();else if("loaded"===t.type)d&&h();else{let e;if("change"!==t.type||!(e=t.content)||"object"!=typeof e||Array.isArray(e))if("height"===t.type){let e=t.height;if("number"==typeof e&&Number.isFinite(e)){let t=Math.round(Math.min(Math.max(e,80),4e3));l.style.height=`min(${t}px, 60vh)`}}else"escape"===t.type?i.onEscape?.():"error"===t.type&&i.onError("string"==typeof t.message&&t.message?t.message:"The form failed");else i.onChange(t.content,"string"==typeof t.entryId?t.entryId:void 0)}};return e.addEventListener("message",b),t.appendChild(l),{show(e){c=e,u()},destroy(){clearTimeout(g),e.removeEventListener("message",b),l.remove()}}})(e,t,"string"==typeof r?r:"",a,{onReady:()=>i?.(),onChange:f,onError:e=>o?.(e),onEscape:()=>s?.()}),c=b("change",h),h())})().catch(u),{close:g}},async pages(){let{pages:e}=await M("pages"),t=[O(),N?.space.defaultLocale];return e.flatMap(e=>{let r=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],n=void 0===r?void 0:e.paths[r];if(void 0===r||void 0===n)return[];let a=W(e),o=e.product??e.collection??null;return[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:n,url:a&&o?((e,t,r)=>{let n="product"===e?l:u;if(n)return n(t,r);let{setting:a,route:i}=B[e];return(N?.[a]??i).replaceAll("{handle}",encodeURIComponent(t))})(a,o.handle,r):i(n,r),product:e.product??null,collection:e.collection??null}]})},openPage(t){(!m().unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(k.clear(),E.length=0,$(),e.location.assign(ea(t.url)))},undo(){let e=E.pop(),t=e&&k.get(e.entryId);e&&t&&(L=-1/0,t.content=e.content,$(),H(e.entryId).catch(Y))},async save(){if(!J("save"))throw Error("You may not edit content here");f({saving:!0});try{await K()}finally{f({saving:!1})}X("saved")},async publish(){if(!J("publish"))throw Error("You may not publish here");f({publishing:!0});try{await K();let e=z(),t=A.size>0?[...A]:e?[e]:[];if(0===t.length)throw Error("Nothing on this page is marked as an entry: add editable(entry)");for(let e of t)await M(er(e),{}),A.delete(e)}finally{f({publishing:!1})}X("published")},signOut(){if(m().unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;k.clear(),$();let t=e.location.pathname+e.location.search;e.location.href=`${a}/logout?return_to=${encodeURIComponent(t)}`},select(e){_(e)},setSelecting(e){e?h.documentElement.setAttribute("data-cms-selecting",""):h.documentElement.removeAttribute("data-cms-selecting"),f({selecting:e,statsVisible:e}),el()},destroy(){S?.(),P.forEach(e=>clearTimeout(e)),P.clear(),w.splice(0).forEach(e=>e())}}})(w,f,{pagePath:u,productPath:h,collectionPath:b})),x.isEditing&&i){let e=w.document,t=()=>{},r=!1,n=f?ec:G,a=()=>{r||(t=n(e,x,!0===i?{}:i))};e.body?a():e.addEventListener("DOMContentLoaded",a,{once:!0});let o=x.destroy;x.destroy=()=>{r=!0,e.removeEventListener("DOMContentLoaded",a),t(),o()}}}return w[eu]=x,x};(e=window).ObelismBridge=eh((e=>{let t=e?.dataset.url,r=t||Q;if(!t&&e?.src){let t=new URL(e.src);"/bridge.js"===t.pathname&&(r=t.origin)}return{url:r,prompt:e?.dataset.prompt!=="false"}})(document.currentScript)),e.ObelismContent={getContentBridge:eh,mountPromptBox:G,mountSiteEditor:ec}}();
|