@krantho/studio 1.1.2 → 1.1.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.
Files changed (26) hide show
  1. package/dist/assets/{AssistantPanel-ECkcslXS.js → AssistantPanel-DpYeurU-.js} +1 -1
  2. package/dist/assets/{GraphBrowser-BBKTzzRV.js → GraphBrowser-Cm5q82MJ.js} +2 -2
  3. package/dist/assets/{GraphCanvas-Cct1E2As.js → GraphCanvas-CZJNUa_J.js} +1 -1
  4. package/dist/assets/{api-seo-CwGP6Bi2.js → api-seo-DeG5gsh6.js} +1 -1
  5. package/dist/assets/{collection-view--erTGbRH.js → collection-view-Bbr6ff-2.js} +1 -1
  6. package/dist/assets/{editor-page-XOJrwlcZ.js → editor-page-ydSt1TIL.js} +3 -3
  7. package/dist/assets/{fill-job-YPZFETW1.js → fill-job-CKtHKXwV.js} +1 -1
  8. package/dist/assets/{fill-run-view-B6rnYhKS.js → fill-run-view-ChrOLoV4.js} +1 -1
  9. package/dist/assets/{graph-config-DKVGDPTG.js → graph-config-CgXhm7XP.js} +1 -1
  10. package/dist/assets/{image-editor-BX-DHJDa.js → image-editor-CAZbOhRZ.js} +1 -1
  11. package/dist/assets/{index-CEQ7ZdKC.js → index-d5j-az5g.js} +2 -2
  12. package/dist/assets/{live-markdown-editor-DM8hYG3n.js → live-markdown-editor-DSsCNBWR.js} +1 -1
  13. package/dist/assets/{media-page-CeBC5FQS.js → media-page-DuSUjFO1.js} +1 -1
  14. package/dist/assets/{pulse-page-C00oCF2o.js → pulse-page-zRYAQJh6.js} +1 -1
  15. package/dist/assets/{setup-page-BHJcTaTH.js → setup-page-CshRkFJ-.js} +1 -1
  16. package/dist/assets/{site-BYsfQB_3.js → site-CGs9-oiw.js} +1 -1
  17. package/dist/assets/{site-model-C5bJvTbk.js → site-model-BXHOxNij.js} +1 -1
  18. package/dist/assets/{site-overview-5EhmXIR0.js → site-overview-B0Dnsj2N.js} +1 -1
  19. package/dist/assets/{structure-page-9d9MG7vU.js → structure-page-DpM1G-M9.js} +2 -2
  20. package/dist/assets/{use-drawer-actions-CR6Q0qdd.js → use-drawer-actions-BeAi2hJS.js} +1 -1
  21. package/dist/assets/{use-loaded-BBFak2E1.js → use-loaded-BNCu0C-c.js} +1 -1
  22. package/dist/assets/{use-locale-versions-BycCbBLd.js → use-locale-versions-CcJ_us1I.js} +1 -1
  23. package/dist/assets/vendor-markdown-BeOOOWTF.js +74 -0
  24. package/dist/index.html +1 -1
  25. package/package.json +5 -5
  26. package/dist/assets/vendor-markdown-pd8vs9n-.js +0 -74
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-diff-DGCTJYJ4.js","assets/rolldown-runtime-COiEfhsA.js","assets/GraphBrowser-BBKTzzRV.js","assets/save-ClSXW9cb.js","assets/createLucideIcon-BklFHeMd.js","assets/createLucideIcon-DO6kYgVn.css","assets/upload-CaqQJaUr.js","assets/graph-config-DKVGDPTG.js","assets/use-loaded-BBFak2E1.js","assets/index-CEQ7ZdKC.js","assets/vendor-react-CXaWJ_ii.js","assets/vendor-react-DLioOiRN.css","assets/vendor-router-B4czwg8X.js","assets/auth-CIpilSKF.js","assets/format-C3ZX9yGM.js","assets/api-client-BRi_ki2Y.js","assets/index-Buq8auz3.css","assets/copy-V85khWct.js","assets/corner-down-right-BpwOGRFR.js","assets/findability-BrhtZ2yD.js","assets/layers-0VWe0rKm.js","assets/guards-BFEDbduR.js","assets/graph-config-mZyX0Lqo.css","assets/catalog-offer-CeRRk2Zo.js","assets/circle-check-big-DQjpuxcC.js","assets/circle-x-peGpq98w.js","assets/trash-DzRCm500.js","assets/export-helpers-C_HVpJN9.js","assets/triangle-exclamation-point-ttN5lZI0.js","assets/external-link-Dh7p8Ii6.js","assets/GraphBrowser-U_-D112C.css","assets/live-markdown-editor-DM8hYG3n.js","assets/arrow-down-B5kfR2lG.js","assets/arrow-left-7opbl8fu.js","assets/use-drawer-actions-CR6Q0qdd.js","assets/media-model-D4F1Farw.js","assets/action-button-DIrhqMRc.js","assets/use-drawer-actions-DeFJMhBn.css"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{a as t,o as n,s as r}from"./vendor-diff-DGCTJYJ4.js";import{f as i,r as a,s as o,t as s,u as c}from"./vendor-router-B4czwg8X.js";import{a as l,d as u,i as d,o as f,r as p,t as m,u as h}from"./format-C3ZX9yGM.js";import{$ as g,B as _,C as v,D as y,Et as b,F as ee,G as x,H as S,M as te,Q as ne,S as re,Tt as ie,U as ae,V as oe,Y as se,Z as ce,_t as le,at as ue,c as C,ct as de,d as w,et as fe,f as T,ft as pe,g as me,gt as he,j as ge,lt as _e,m as ve,mt as ye,n as be,o as xe,ot as Se,p as Ce,pt as E,r as D,s as O,st as we,t as Te,tt as Ee,u as De,vt as Oe,x as ke,xt as Ae}from"./index-CEQ7ZdKC.js";import{a as je,f as Me}from"./site-model-C5bJvTbk.js";import{i as Ne,r as Pe,t as Fe}from"./api-client-BRi_ki2Y.js";import{n as Ie,t as Le}from"./use-loaded-BBFak2E1.js";import{i as Re,n as k,r as A,t as j}from"./createLucideIcon-BklFHeMd.js";import{a as ze,c as Be,d as Ve,f as He,i as Ue,l as We,p as Ge,s as Ke,u as qe}from"./use-drawer-actions-CR6Q0qdd.js";import{t as Je}from"./clock-DoBIVjZO.js";import{n as Ye,r as Xe}from"./vendor-markdown-pd8vs9n-.js";import{t as Ze}from"./rotate-ccw-BgARBEK3.js";import{E as Qe,k as $e,r as et,y as tt}from"./media-model-D4F1Farw.js";import{m as nt}from"./vendor-react-CXaWJ_ii.js";import{i as rt}from"./auth-CIpilSKF.js";import{i as it,t as at}from"./meter-ZOLJ0WhG.js";import{t as ot}from"./empty-state-CeUZocHx.js";import{D as st,a as ct,d as lt,i as ut,l as dt,n as ft,o as pt,r as mt,t as ht,u as gt,x as _t}from"./graph-config-DKVGDPTG.js";import{t as vt}from"./circle-x-peGpq98w.js";import{c as yt,l as bt,s as xt,u as St}from"./fill-job-YPZFETW1.js";import{t as Ct}from"./action-button-DIrhqMRc.js";import{t as wt}from"./external-link-Dh7p8Ii6.js";import{t as Tt}from"./info-Cxkabti5.js";import{t as Et}from"./triangle-exclamation-point-ttN5lZI0.js";import{t as Dt}from"./pen-line-B524Nue8.js";import{d as Ot,f as kt,l as At,o as jt,s as Mt,t as Nt,u as Pt,y as Ft}from"./api-seo-CwGP6Bi2.js";import{t as It}from"./arrow-left-7opbl8fu.js";import{t as Lt}from"./findability-BrhtZ2yD.js";import{n as Rt}from"./use-locale-versions-BycCbBLd.js";var zt={name:`chevron-up`,size:24,node:[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]};zt.node;var Bt=j(zt),Vt={name:`eye`,size:24,node:[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};Vt.node;var Ht=j(Vt),Ut={name:`file-question-mark`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 9.5a3 2.5 0 016 0c0 2-2 2-3 3.5`,key:`1awbb0`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`file-question`]};Ut.node;var Wt=j(Ut),Gt={name:`lock-open`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]],aliases:[`unlock`]};Gt.node;var Kt=j(Gt),qt={name:`monitor-x`,size:24,node:[[`path`,{d:`m14.5 12.5-5-5`,key:`1jahn5`}],[`path`,{d:`m9.5 12.5 5-5`,key:`1k2t7b`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};qt.node;var Jt=j(qt),Yt={name:`panel-right-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]};Yt.node;var Xt=j(Yt),Zt={name:`panel-right-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]};Zt.node;var Qt=j(Zt),$t={name:`scan-search`,size:24,node:[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`path`,{d:`m16 16-1.9-1.9`,key:`1dq9hf`}]]};$t.node;var en=j($t);async function tn(e,t,n){return Ne(`/content/${e}/${t}/versions${Pe(n)}`)}async function nn(e,t,n,r){let i=await Ne(`/content/${e}/${t}/versions/${n}${Pe(r)}`);return{version:i.meta.version,metadata:i.metadata,contract:i.contract,defaults:i.defaults,repositoryBasis:i.repositoryBasis,fields:i.fields,body:i.body,changedBy:i.meta.changedBy,createdAt:i.meta.createdAt}}async function rn(e,t,n,r){return Ne(`/content/${e}/${t}/restore/${n}${Pe(r)}`,{method:`POST`})}var M=e(r(),1),N=n();function P({title:e,lead:t,aside:n,children:r}){let i=(0,M.useId)();return(0,N.jsxs)(`section`,{className:`data-card`,"aria-labelledby":i,children:[(0,N.jsxs)(`div`,{className:`data-card-head`,children:[(0,N.jsx)(`h2`,{id:i,className:`data-card-title`,children:e}),n&&(0,N.jsx)(`div`,{className:`data-card-aside`,children:n})]}),t&&(0,N.jsx)(`p`,{className:`data-card-lead`,children:t}),r]})}function F({children:e,tone:t}){return(0,N.jsx)(`p`,{className:t===`error`?`data-note data-note--error`:`data-note`,children:e})}function an({children:e}){return(0,N.jsx)(`p`,{role:`alert`,className:`data-note data-note--error`,children:e})}function on(e,t){return{live:e===t.liveVersion,current:e===t.version}}function sn(e,t){return{version:(e[0]?.version??0)+1,metadata:t.metadata,contract:null,defaults:[],repositoryBasis:null,fields:t.fields,body:t.body,changedBy:null,createdAt:new Date().toISOString()}}function cn(e,t){let n=`v${e} is saved again as the newest version; the versions in between stay, and the live page is unchanged until you publish.`;return t?`${n} Your unsaved changes in the form will be lost.`:n}function ln(e,t){return`v${e} could not be restored: ${t}`}function un(e,t){return`v${e} was restored as v${t}, but the page could not be refreshed. Reload it to see the restored version.`}function dn(e){let t=(0,M.useRef)(null);return(0,N.jsx)(w,{title:`Restore v${e.version}?`,onClose:e.onClose,initialFocus:t,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:t,onClick:e.onClose,children:`Cancel`}),(0,N.jsx)(k,{variant:`danger`,onClick:e.onConfirm,children:`Restore`})]}),children:(0,N.jsx)(`p`,{children:cn(e.version,e.unsaved)})})}function fn({n:e,actions:t,restoring:n}){return(0,N.jsxs)(`span`,{className:`data-version-actions`,children:[t.diff&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,"aria-label":`Diff v${e} with the version before`,onClick:t.diff,children:`Diff`}),t.compare&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,"aria-label":`Compare v${e} with your form`,onClick:t.compare,children:`Compare`}),t.restore&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Restore v${e}`,"aria-disabled":n,title:n?`A restore is under way.`:void 0,onClick:n?void 0:t.restore,children:`Restore`})]})}function pn({version:e,props:t,actions:n,restoring:r}){let i=on(e.version,t.saved);return(0,N.jsxs)(`li`,{className:`data-version`,children:[(0,N.jsxs)(`span`,{className:`data-version-number`,children:[`v`,e.version]}),(0,N.jsxs)(`span`,{className:`data-version-meta`,children:[(0,N.jsx)(`time`,{dateTime:e.createdAt,children:p(e.createdAt)}),(0,N.jsx)(`span`,{children:e.changedBy?D(e.changedBy):`Unknown author`})]}),(0,N.jsxs)(`span`,{className:`data-version-chips`,children:[i.live&&(0,N.jsx)(O,{tone:`success`,children:`live`}),i.current&&(0,N.jsx)(O,{tone:`accent`,children:`current`})]}),(0,N.jsx)(fn,{n:e.version,actions:n,restoring:r})]})}var mn=(0,M.lazy)(()=>t(()=>import(`./vendor-diff-DGCTJYJ4.js`).then(e=>e.t),__vite__mapDeps([0,1])));function hn(){let e=document.documentElement.getAttribute(`data-theme`);return e===`dark`?!0:e===`light`?!1:window.matchMedia?.(`(prefers-color-scheme: dark)`).matches??!1}function gn(){let[e,t]=(0,M.useState)(hn);return(0,M.useEffect)(()=>{let e=()=>t(hn()),n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]});let r=window.matchMedia?.(`(prefers-color-scheme: dark)`);return r?.addEventListener(`change`,e),()=>{n.disconnect(),r?.removeEventListener(`change`,e)}},[]),e}function _n(e,t){return t?`Your form`:`v${e.version}`}function vn({pressed:e,onPress:t,children:n}){return(0,N.jsx)(k,{size:`sm`,variant:e?`secondary`:`ghost`,"aria-pressed":e,onClick:t,children:n})}function yn({view:e,onView:t,onClose:n}){return(0,N.jsxs)(`div`,{className:`data-diff-controls`,children:[(0,N.jsx)(vn,{pressed:e.part===`fields`,onPress:()=>t({...e,part:`fields`}),children:`Fields`}),(0,N.jsx)(vn,{pressed:e.part===`metadata`,onPress:()=>t({...e,part:`metadata`}),children:`Details`}),(0,N.jsx)(vn,{pressed:e.part===`body`,onPress:()=>t({...e,part:`body`}),children:`Body`}),(0,N.jsx)(vn,{pressed:e.split,onPress:()=>t({...e,split:!e.split}),children:`Split`}),(0,N.jsx)(A,{icon:Ee,label:`Close the diff`,size:`sm`,onClick:n})]})}function bn({comparison:e,onClose:t}){let[n,r]=(0,M.useState)({part:`fields`,split:!1}),i=gn(),a=(0,M.useId)(),o=(0,M.useRef)(null),{base:s,compare:c,form:l}=e;(0,M.useEffect)(()=>o.current?.focus(),[e]);let u=e=>n.part===`body`?e.body:JSON.stringify(n.part===`fields`?e.fields:e.metadata,null,2);return(0,N.jsxs)(`section`,{className:`data-diff`,"aria-labelledby":a,children:[(0,N.jsxs)(`div`,{className:`data-diff-head`,children:[(0,N.jsxs)(`h3`,{id:a,ref:o,tabIndex:-1,className:`data-diff-title`,children:[`v`,s.version,` → `,_n(c,l)]}),(0,N.jsx)(yn,{view:n,onView:r,onClose:t})]}),(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(F,{children:`Loading the diff…`}),children:(0,N.jsx)(`div`,{className:`data-diff-body`,children:(0,N.jsx)(mn,{oldValue:u(s),newValue:u(c),splitView:n.split,useDarkTheme:i,leftTitle:`v${s.version}`,rightTitle:_n(c,l)})})})]})}function xn(e){let t=e.seo;return!t||!Array.isArray(t.entities)?null:t}function Sn(e){let t=xn(e)?.entities[0]?.properties??{},n=e.sharing??{},r=e.editorial??{},i=e.publication??{};return{...t,...n.title===void 0?{}:{headline:n.title},...n.description===void 0?{}:{description:n.description},...n.image===void 0?{}:{image:n.image},...n.canonicalUrl===void 0?{}:{url:n.canonicalUrl},...r.byline===void 0?{}:{author:r.byline},...i.date===void 0?{}:{datePublished:i.date}}}var I={title:[`title`,`name`],description:[`meta-description`,`description`,`ingress`,`excerpt`],author:[`author`],datePublished:[`published-date`,`date`],image:[`og-image`,`image`,`hero-image`],canonicalUrl:[`canonical-url`],robotsIndex:[`robots-index`],robotsFollow:[`robots-follow`],ogTitle:[`og-title`],ogDescription:[`og-description`],ogImage:[`og-image`,`image`],ogType:[`og-type`]};function L(e){let t=new Set(e);function n(e){return e.find(e=>t.has(e))??null}return{title:n(I.title),description:n(I.description),author:n(I.author),datePublished:n(I.datePublished),image:n(I.image),canonicalUrl:n(I.canonicalUrl),robotsIndex:n(I.robotsIndex),robotsFollow:n(I.robotsFollow),ogTitle:n(I.ogTitle),ogDescription:n(I.ogDescription),ogImage:n(I.ogImage),ogType:n(I.ogType)}}function Cn(e,t,n){let r=e[t];if(!r)return``;let i=n[r];return typeof i==`string`&&i.length>0?i:``}var wn=new Set([`status`]);function Tn(e){return e.description?.match(/^ref:(\w+)/)?.[1]??null}function En(e,t){return e.format===`date`||e.format===`date-time`?`date`:t.includes(`color`)||t.includes(`colour`)?`color`:e.maxLength!==void 0&&e.maxLength>200||t.includes(`description`)||t.includes(`ingress`)||t.includes(`intro`)?`textarea`:`text`}function R(e,t){return e.description===`media`?`media`:Tn(e)?`reference`:e.enum?`enum`:e.type===`boolean`?`boolean`:e.type===`number`||e.type===`integer`?`number`:e.type===`array`&&e.items?.type===`string`?`tags`:e.type===`string`?En(e,t):`text`}function Dn(e,t){return e.type===`string`?e.format===`uri`||e.format===`url`?`url`:e.format===`email`?`email`:e.format===`date`?`date`:e.format===`date-time`?`datetime-local`:t.includes(`url`)||t.includes(`link`)||t.includes(`href`)?`url`:t.includes(`email`)||t.includes(`e-mail`)?`email`:`text`:`text`}function On(e,t){return e.format===`date-time`?`date and time`:e.format===`date`?`date`:e.format===`uri`||e.format===`url`?`web address`:e.format===`email`?`email`:t.endsWith(`-slug`)||t===`slug`?`URL name`:`text`}var kn={media:`image or file`,reference:`link to a page`,enum:`choice`,color:`color`};function An(e,t){return kn[R(e,t)]||(e.type===`array`?e.items?.type===`string`?`list of text`:`list`:e.type===`string`?On(e,t):e.type===`integer`?`number`:e.type===`boolean`?`yes/no`:e.type===`object`?`group`:e.type??`text`)}function jn(e){return e.description===`media`||Tn(e)!==null?null:e.description?.trim()||null}var Mn={title:`title`,description:`meta description`,author:`author`,datePublished:`date published`,image:`image`,canonicalUrl:`canonical address`,robotsIndex:`search indexing`,robotsFollow:`link following`,ogTitle:`sharing title`,ogDescription:`sharing description`,ogImage:`sharing image`,ogType:`sharing type`},Nn=Object.keys(I);function Pn(e,t,n){let r=e.get(t)??[];r.includes(n)||r.push(n),e.set(t,r)}function Fn(e){let t=new Set(e),n=L(e),r=new Map,i=new Map;for(let e of Nn)for(let a of I[e])t.has(a)&&Pn(n[e]===a?r:i,a,Mn[e]);let a=new Map;for(let t of e){let e=r.get(t),n=i.get(t)?.filter(t=>!e?.includes(t)),o=[...e??[],...n?.length?[`backup for ${n.join(`, `)}`]:[]];o.length>0&&a.set(t,o.join(` · `))}return a}var In=nt(),Ln=20;function Rn(e){let[t,n]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let t=!0;return n({state:`loading`}),Qe({limit:Ln,offset:e*Ln}).then(e=>t&&n({state:`ready`,...e})).catch(e=>t&&n({state:`failed`,message:T(e,`Media could not be read`)})),()=>{t=!1}},[e]),t}function zn({library:e,onSelect:t}){return e.state===`loading`?(0,N.jsx)(`p`,{role:`status`,children:`Loading media…`}):e.state===`failed`?(0,N.jsx)(`p`,{role:`alert`,children:e.message}):e.items.length===0?(0,N.jsx)(`p`,{children:`No media yet. Upload an image above.`}):(0,N.jsx)(`ul`,{className:`media-picker-grid`,"aria-label":`Library`,children:e.items.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`media-picker-file`,onClick:()=>t(e),children:[(0,N.jsx)(`img`,{src:tt(e,`sm`),alt:``}),(0,N.jsx)(`span`,{className:`media-picker-name`,children:e.filename})]})},e.id))})}function Bn({onSelect:e,onUpload:t,onClose:n}){let[r,i]=(0,M.useState)(0),a=Rn(r),{hasRole:o}=rt(),s=a.state===`ready`?Math.ceil(a.total/Ln):0;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Be,{multiple:!1,blocked:o(`editor`)?null:et,onUploaded:([e])=>e&&t(e)}),(0,N.jsx)(zn,{library:a,onSelect:e}),(0,N.jsx)(Ke,{page:r,count:s,onPage:i}),(0,N.jsx)(`div`,{className:`media-picker-actions`,children:(0,N.jsx)(k,{onClick:n,children:`Cancel`})})]})}function Vn(e){let t=(0,M.useRef)(null),n=(0,M.useId)();g(t,!0);function r(t){t.key===`Escape`&&(t.stopPropagation(),e.onClose())}return(0,In.createPortal)((0,N.jsxs)(`div`,{className:`media-picker-layer`,children:[(0,N.jsx)(`div`,{className:`media-picker-scrim`,"aria-hidden":`true`,onClick:e.onClose}),(0,N.jsxs)(`div`,{ref:t,className:`media-picker`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":n,tabIndex:-1,onKeyDown:r,children:[(0,N.jsx)(`h2`,{id:n,className:`media-picker-title`,children:`Choose an image`}),(0,N.jsx)(Bn,{...e})]})]}),document.body)}function Hn(e){let[t,n]=(0,M.useState)({state:e?`loading`:`none`});return(0,M.useEffect)(()=>{if(!e){n({state:`none`});return}let t=!0;return n(t=>t.state===`ready`&&t.item.id===e?t:{state:`loading`}),$e(e).then(e=>t&&n({state:`ready`,item:e})).catch(()=>t&&n({state:`missing`,id:e})),()=>{t=!1}},[e]),[t,e=>n({state:`ready`,item:e})]}function Un({item:e}){let t=e.altText.trim()!==``;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`img`,{className:`editor-media-thumb`,src:tt(e,`sm`),alt:``}),(0,N.jsxs)(`div`,{className:`editor-media-text`,children:[(0,N.jsx)(`span`,{className:`editor-media-name`,children:e.filename}),(0,N.jsxs)(`span`,{className:`editor-media-meta`,children:[e.width!==null&&e.height!==null&&`${e.width} × ${e.height} · `,d(e.size)]}),(0,N.jsxs)(`span`,{className:t?`editor-media-alt`:`editor-media-alt editor-media-alt--missing`,children:[t?(0,N.jsx)(E,{"aria-hidden":`true`}):(0,N.jsx)(pe,{"aria-hidden":`true`}),t?`Alt text set`:`No alt text`]})]})]})}function Wn({selected:e}){if(e.state===`ready`)return(0,N.jsx)(Un,{item:e.item});let t=e.state===`loading`?`Loading…`:e.state===`missing`?`Media ${e.id} was not found`:`No image chosen`;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`editor-media-thumb editor-media-thumb--empty`,"aria-hidden":`true`,children:(0,N.jsx)(qe,{})}),(0,N.jsx)(`span`,{className:`editor-media-text editor-media-meta`,children:t})]})}function Gn({id:e,current:t,describedBy:n,changeRef:r,onPick:i,onClear:a}){return(0,N.jsxs)(`div`,{className:`editor-media-actions`,children:[(0,N.jsx)(k,{id:e,ref:r,size:`sm`,"aria-describedby":n,onClick:i,children:t?`Change`:`Choose image`}),t&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>{a(),r.current?.focus()},children:`Clear`})]})}function Kn(e,t){let n=[e?`Required`:null,t?`not valid`:null].filter(Boolean);return n.length>0?n.join(`, `):null}function qn(e){let{id:t,labelId:n,name:r,value:i,onChange:a}=e,o=typeof i==`string`?i:``,[s,c]=Hn(o),[l,u]=(0,M.useState)(!1),d=(0,M.useRef)(null),f=Kn(e.required,e.invalid),p=[f?`${t}-state`:null,e.describedBy].filter(Boolean).join(` `)||void 0;function m(e){c(e),a(r,e.id),u(!1)}return(0,N.jsxs)(`fieldset`,{className:`editor-media`,"aria-labelledby":n,"aria-describedby":p,children:[f&&(0,N.jsx)(`span`,{id:`${t}-state`,className:`visually-hidden`,children:f}),(0,N.jsx)(Wn,{selected:s}),(0,N.jsx)(Gn,{id:t,current:o,describedBy:p,changeRef:d,onPick:()=>u(!0),onClear:()=>a(r,``)}),l&&(0,N.jsx)(Vn,{onSelect:m,onUpload:m,onClose:()=>u(!1)})]})}function Jn(e){let[t,n]=(0,M.useState)(null);return(0,M.useEffect)(()=>{let t=!0;return _(e).then(({items:e})=>{t&&n(e.map(({meta:e,fields:t})=>({slug:e.slug,label:typeof t.title==`string`?t.title:e.slug})))}).catch(()=>{t&&n([])}),()=>{t=!1}},[e]),t}function Yn(e){let{id:t,name:n,property:r,value:i,describedBy:a,invalid:o,required:s,onChange:c}=e,l=Tn(r)??``,u=Jn(l),d=typeof i==`string`?i:``,f=d!==``&&u!==null&&!u.some(e=>e.slug===d);return(0,N.jsxs)(`select`,{id:t,name:n,className:`editor-control editor-control--short`,value:d,"aria-describedby":a,"aria-invalid":o||void 0,"aria-required":s||void 0,"aria-busy":u===null||void 0,onChange:e=>c(n,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:u===null?`Loading…`:`Choose from ${l}…`}),f&&(0,N.jsx)(`option`,{value:d,children:d}),u?.map(e=>(0,N.jsx)(`option`,{value:e.slug,children:e.label},e.slug))]})}function Xn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Zn({tags:e,onRemove:t}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`editor-tags-list`,children:e.map((e,n)=>(0,N.jsxs)(`li`,{className:`editor-tag`,children:[e,(0,N.jsx)(`button`,{type:`button`,className:`editor-tag-remove`,"aria-label":`Remove ${e}`,onClick:()=>t(n),children:(0,N.jsx)(Ee,{"aria-hidden":`true`})})]},`${e}-${n}`))})}function Qn(e){let{id:t,name:n,value:r,describedBy:i,invalid:a,required:o,onChange:s}=e,[c,l]=(0,M.useState)(``),u=(0,M.useRef)(null),d=Xn(r);function f(e){e.key===`Enter`&&c.trim()&&(e.preventDefault(),s(n,[...d,c.trim()]),l(``))}function p(e){s(n,d.filter((t,n)=>n!==e)),u.current?.focus()}return(0,N.jsxs)(`div`,{className:`editor-tags`,children:[(0,N.jsx)(Zn,{tags:d,onRemove:p}),(0,N.jsx)(`input`,{ref:u,id:t,name:n,type:`text`,className:`editor-control`,placeholder:`Type and press Enter`,value:c,"aria-describedby":i,"aria-invalid":a||void 0,"aria-required":o||void 0,onChange:e=>l(e.target.value),onKeyDown:f})]})}function $n(e){if(typeof e!=`string`||e===``)return``;let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=e=>String(e).padStart(2,`0`);return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`}T${n(t.getHours())}:${n(t.getMinutes())}`}function er(e){if(e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toISOString().slice(0,19)}Z`}function z(e){return typeof e==`string`?e:``}function B(e){return{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}}function tr(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsx)(`input`,{...B(e),type:Dn(n,t),className:`editor-control`,value:z(r),maxLength:n.maxLength,pattern:n.pattern,onChange:e=>i(t,e.target.value)})}function nr(e){let{id:t,name:n,property:r,value:i,onChange:a}=e,o=z(i).length,s=r.maxLength!==void 0,c=`${t}-count`,l=[e.describedBy,s?c:null].filter(Boolean).join(` `);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`textarea`,{...B(e),"aria-describedby":l||void 0,className:`editor-control editor-control--area`,value:z(i),rows:3,maxLength:r.maxLength,onChange:e=>a(n,e.target.value)}),s&&(0,N.jsxs)(`span`,{id:c,className:`editor-field-counter`,children:[o,` of `,r.maxLength,` characters`]})]})}function rr(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsx)(`input`,{...B(e),type:`number`,className:`editor-control editor-control--short`,value:typeof r==`number`&&!Number.isNaN(r)?r:``,min:n.minimum,max:n.maximum,onChange:e=>i(t,e.target.value===``?void 0:e.target.valueAsNumber)})}function ir(e){let{name:t,value:n,onChange:r}=e;return(0,N.jsx)(`input`,{...B(e),type:`checkbox`,className:`editor-checkbox`,checked:n===!0,onChange:e=>r(t,e.target.checked)})}function ar(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsxs)(`select`,{...B(e),className:`editor-control editor-control--short`,value:z(r),onChange:e=>i(t,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Choose…`}),n.enum?.map(e=>(0,N.jsx)(`option`,{value:e,children:e},e))]})}function or(e){let{name:t,value:n,onChange:r}=e;return(0,N.jsxs)(`span`,{className:`editor-color`,children:[(0,N.jsx)(`input`,{type:`color`,className:`editor-color-swatch`,"aria-label":`${t}, colour picker`,value:z(n),onChange:e=>r(t,e.target.value)}),(0,N.jsx)(`input`,{...B(e),type:`text`,className:`editor-control editor-control--short`,value:z(n),placeholder:`#rrggbb`,onChange:e=>r(t,e.target.value)})]})}function sr(e){let{name:t,property:n,value:r,onChange:i}=e,a=Dn(n,t),o=a===`datetime-local`,s=(0,N.jsx)(`input`,{...B(e),type:a,className:`editor-control editor-control--short`,value:o?$n(r):z(r).slice(0,10),onChange:e=>{let n=e.target.value;i(t,o?er(n):n)}});return o?(0,N.jsxs)(`span`,{className:`editor-timestamp`,children:[s,(0,N.jsx)(`small`,{className:`editor-timestamp-shown`,children:l(r)})]}):s}var cr={media:qn,reference:Yn,enum:ar,boolean:ir,number:rr,tags:Qn,textarea:nr,color:or,date:sr,text:tr};function V(e,t){let n=e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/[-_]/g,` `);return t.title??n.charAt(0).toUpperCase()+n.slice(1)}function lr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function H(e){let{property:t,value:n,onValue:r}=e,i=V(e.name,t),a=t.anyOf??t.oneOf;if(a?.some(e=>e.type===`null`)){let o=a.find(e=>e.type!==`null`)??{};return(0,N.jsxs)(`div`,{className:`metadata-property`,children:[n===null?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`p`,{children:[i,`: No value`]}),(0,N.jsxs)(k,{size:`sm`,onClick:()=>r(o.default??(o.type===`object`?{}:o.type===`array`?[]:o.type===`boolean`?!1:o.type===`number`?0:``)),children:[`Set `,i.toLowerCase()]})]}):(0,N.jsx)(H,{...e,property:{...t,...o,anyOf:void 0,oneOf:void 0}}),n!==null&&(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>r(null),children:`Use no value`})]})}if(t.type===`object`)return(0,N.jsxs)(`fieldset`,{className:`metadata-object`,children:[(0,N.jsx)(`legend`,{children:i}),(0,N.jsx)(dr,{property:t,values:lr(n),path:e.path,errors:e.errors,sources:e.sources,onValues:r})]});if(t.type===`array`&&t.items?.type!==`string`){let a=Array.isArray(n)?n:[];return(0,N.jsxs)(`fieldset`,{className:`metadata-array`,children:[(0,N.jsx)(`legend`,{children:i}),a.map((n,o)=>(0,N.jsxs)(`div`,{className:`metadata-array-item`,children:[(0,N.jsx)(H,{...e,name:`${i} ${o+1}`,path:`${e.path}.${o}`,property:t.items??{},value:n,onValue:e=>r(a.map((t,n)=>n===o?e:t))}),(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>r(a.filter((e,t)=>t!==o)),children:`Remove`})]},`${e.path}.${o}`)),(0,N.jsx)(k,{variant:`secondary`,size:`sm`,onClick:()=>r([...a,t.items?.type===`object`?{}:``]),children:`Add item`})]})}return(0,N.jsx)(ur,{...e})}function ur(e){let t=(0,M.useId)(),n=V(e.name,e.property),r=jn(e.property),i=e.errors[e.path]??(e.path.startsWith(`fields.`)?e.errors[e.path.slice(7)]:void 0),a=cr[R(e.property,e.name)],o=[r?`${t}-help`:``,i?`${t}-error`:``].filter(Boolean).join(` `)||void 0;return(0,N.jsxs)(`div`,{className:`metadata-property`,children:[(0,N.jsxs)(`div`,{className:`metadata-label-row`,children:[(0,N.jsxs)(`label`,{id:`${t}-label`,htmlFor:t,children:[n,e.required&&(0,N.jsx)(`span`,{"aria-hidden":`true`,children:` *`})]}),!e.required&&e.value!==void 0&&e.property.type!==`boolean`&&(0,N.jsx)(A,{icon:Ze,size:`sm`,label:`Reset ${n.toLowerCase()}`,onClick:()=>e.onValue(void 0)})]}),e.property.type===`boolean`&&!e.required?(0,N.jsxs)(`select`,{id:t,className:`editor-control`,"aria-describedby":o,"aria-invalid":!!i||void 0,value:e.value===void 0?``:String(e.value),onChange:t=>e.onValue(t.target.value===``?void 0:t.target.value===`true`),children:[(0,N.jsx)(`option`,{value:``,children:`Use default`}),(0,N.jsx)(`option`,{value:`true`,children:`Yes`}),(0,N.jsx)(`option`,{value:`false`,children:`No`})]}):(0,N.jsx)(a,{id:t,labelId:`${t}-label`,name:e.path,property:e.property,value:e.value,required:e.required,describedBy:o,invalid:!!i,onChange:(t,n)=>e.onValue(n)}),e.sources?.[e.path]&&(0,N.jsxs)(`p`,{className:`metadata-source`,children:[`Copied from `,e.sources[e.path]]}),r&&(0,N.jsx)(`p`,{id:`${t}-help`,className:`metadata-help`,children:r}),i&&(0,N.jsx)(`p`,{id:`${t}-error`,role:`alert`,children:i})]})}function dr(e){let t=new Set(e.property.required??[]),n=e.property.properties??{},r=e.property.additionalProperties,i=r!==void 0&&r!==!1;return(0,N.jsxs)(N.Fragment,{children:[Object.entries(n).filter(([t])=>e.path!==`fields`||!wn.has(t)).map(([n,r])=>(0,N.jsx)(H,{name:n,path:`${e.path}.${n}`,property:r,value:e.values[n],required:t.has(n),errors:e.errors,sources:e.sources,onValue:t=>{let r={...e.values};t===void 0?delete r[n]:r[n]=t,e.onValues(r)}},n)),i&&(0,N.jsx)(pr,{...e,properties:n,additional:typeof r==`object`?r:{}}),!i&&Object.entries(e.values).filter(([e])=>!Object.hasOwn(n,e)).map(([t,n])=>(0,N.jsxs)(`div`,{className:`metadata-property`,children:[(0,N.jsxs)(`p`,{children:[V(t,{}),`:`,` `,typeof n==`string`?n:JSON.stringify(n)]}),(0,N.jsx)(`p`,{children:`This property is outside the current content form. Review it before removing it.`}),(0,N.jsxs)(k,{variant:`ghost`,size:`sm`,onClick:()=>{let n={...e.values};delete n[t],e.onValues(n)},children:[`Remove `,V(t,{})]})]},t))]})}function fr(e){return Array.isArray(e)?{type:`array`,items:fr(e[0])}:typeof e==`object`&&e?{type:`object`,additionalProperties:!0}:{type:typeof e==`boolean`?`boolean`:typeof e==`number`?`number`:`string`}}function pr(e){let[t,n]=(0,M.useState)(``),r=(0,M.useId)();return(0,N.jsxs)(`div`,{className:`metadata-record`,children:[Object.entries(e.values).filter(([t])=>!Object.hasOwn(e.properties,t)).map(([t,n])=>(0,N.jsx)(H,{name:t,path:`${e.path}.${t}`,value:n,property:e.additional.type?e.additional:fr(n),required:!1,errors:e.errors,sources:e.sources,onValue:n=>{let r={...e.values};n===void 0?delete r[t]:r[t]=n,e.onValues(r)}},t)),(0,N.jsx)(`label`,{htmlFor:r,children:`New property name`}),(0,N.jsx)(`input`,{id:r,value:t,onChange:e=>n(e.target.value)}),(0,N.jsx)(k,{size:`sm`,disabled:!t.trim()||Object.hasOwn(e.values,t.trim())||[`__proto__`,`constructor`,`prototype`].includes(t.trim()),onClick:()=>{e.onValues({...e.values,[t.trim()]:e.additional.default??``}),n(``)},children:`Add property`})]})}function mr(e){let t=L(Object.keys(e.fields)),n={title:Cn(t,`title`,e.fields),description:Cn(t,`description`,e.fields)};function r(t,n){let r={...e.values};n===void 0?delete r[t]:r[t]=n,e.onValues(r)}function i(t,n){return(0,N.jsx)(H,{name:t,path:`${e.path}.${t}`,property:{...e.schema.properties?.[t],title:n},value:e.values[t],required:!1,errors:e.errors,sources:e.sources,onValue:e=>r(t,e)})}return(0,N.jsxs)(`div`,{className:`metadata-sharing`,children:[[`title`,`description`].map(t=>(0,N.jsxs)(`div`,{className:`metadata-search-value`,children:[e.values[t]===void 0?(0,N.jsxs)(`div`,{className:`metadata-label-row`,children:[(0,N.jsxs)(`span`,{children:[`Search `,t,` `,(0,N.jsxs)(`span`,{className:`metadata-default-label`,children:[`uses the page `,t]})]}),!e.readOnly&&(0,N.jsx)(k,{className:`metadata-change`,size:`sm`,variant:`secondary`,"aria-label":`Write a different search ${t}`,onClick:()=>{let e=n[t];r(t,typeof e==`string`?e:``)},children:`Write your own`})]}):i(t,`Search ${t}`),e.below?.[t]]},t)),i(`image`,`Sharing image`),e.below?.image,(0,N.jsxs)(`details`,{className:`metadata-advanced`,children:[(0,N.jsx)(`summary`,{children:`Advanced search settings`}),i(`canonicalUrl`,`Canonical URL`),i(`index`,`Show in search results`),i(`follow`,`Allow search engines to follow links`)]})]})}function hr(e){let{meta:t}=e,n=t.changedBy?`saved by ${D(t.changedBy)}, ${it(t.createdAt)}`:`saved ${it(t.createdAt)}`;return(0,N.jsxs)(`p`,{className:`metadata-system`,title:l(t.createdAt),children:[(0,N.jsx)(`span`,{className:`visually-hidden`,children:`System: `}),[ge[te(t)],`v${t.version}`,t.locale.toUpperCase(),n].join(` · `)]})}function gr(e,t){return Object.fromEntries(e.flatMap(e=>e.paths.flatMap(n=>{let r=n.slice(1).split(`/`).map(e=>e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`)),i=t;for(let e of r.slice(1)){if(!i||typeof i!=`object`)return[];i=i[e]}return JSON.stringify(i)===JSON.stringify(e.values[n])?[[r.join(`.`),`${e.collection}/${e.slug} · v${e.version}`]]:[]})))}var _r=`krantho/sharing`;function vr(e,t){return e===`all`||t.id===_r==(e===`sharing`)}function yr(e){let{group:t,slot:n}=e,r=(0,N.jsxs)(N.Fragment,{children:[t.label,(0,N.jsx)(`code`,{className:`metadata-key`,title:`The name your page reads it by`,children:n}),t.required&&(0,N.jsx)(`span`,{className:`metadata-help`,children:` · Required`})]});return e.bare?(0,N.jsx)(`div`,{className:`metadata-group metadata-group--bare`,children:e.children}):e.sharing?(0,N.jsxs)(`details`,{className:`metadata-group`,open:t.required||e.invalid,children:[(0,N.jsx)(`summary`,{children:t.label}),e.children]}):(0,N.jsxs)(`section`,{className:`metadata-group`,"aria-label":t.label,children:[(0,N.jsx)(`h4`,{className:`metadata-group-title`,children:r}),e.children]})}function U(e){let t=e.scope??`all`,n=Object.entries(e.contract.metadata).filter(([,e])=>vr(t,e)),r=Object.entries(e.metadata).filter(([n])=>t!==`sharing`&&!Object.hasOwn(e.contract.metadata,n));if(n.length===0&&r.length===0)return null;let i=gr(e.defaults??[],e.metadata),a=t===`sharing`?`Search and sharing`:`Metadata`;return(0,N.jsxs)(`section`,{className:`editor-metadata`,"aria-label":a,children:[(0,N.jsx)(`h3`,{children:a}),(0,N.jsx)(`p`,{className:`metadata-intro`,children:t===`sharing`?`How this page appears in search results and when it is shared.`:`Saved with the page, and published with it.`}),(0,N.jsxs)(`fieldset`,{disabled:e.readOnly,className:`metadata-groups`,children:[n.map(([n,r])=>{let a=e.metadata[n],o=a!==void 0||r.required,s=t=>e.onMetadata({...e.metadata,[n]:t});return n===`seo`&&r.schema.properties?.entities?(0,N.jsxs)(`div`,{className:`metadata-group metadata-graph-link`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`strong`,{children:`Structured data`}),(0,N.jsx)(`p`,{className:`metadata-help`,children:`Manage how this page is described to search engines.`})]}),e.onOpenData?(0,N.jsx)(k,{size:`sm`,variant:`secondary`,onClick:e.onOpenData,children:`Open graph editor`}):(0,N.jsx)(`p`,{className:`metadata-help`,children:`Available in Data view.`})]},n):!o&&r.id!==_r?(0,N.jsxs)(`div`,{className:`metadata-group metadata-group--absent`,children:[(0,N.jsx)(`strong`,{children:r.label}),!e.readOnly&&(0,N.jsx)(k,{variant:`secondary`,size:`sm`,onClick:()=>s({}),children:`Add`})]},n):(0,N.jsxs)(yr,{sharing:r.id===_r,bare:t===`sharing`,group:r,slot:n,invalid:Object.keys(e.errors).some(e=>e.startsWith(`metadata.${n}`)),children:[r.id===_r?(0,N.jsx)(mr,{below:e.checks,fields:e.fields??{},values:a??{},schema:r.schema,path:`metadata.${n}`,errors:e.errors,sources:i,readOnly:e.readOnly,onValues:s}):(0,N.jsx)(dr,{property:r.schema,values:a??{},path:`metadata.${n}`,errors:e.errors,sources:i,onValues:s}),o&&!r.required&&!e.readOnly&&(0,N.jsxs)(k,{className:`metadata-remove-group`,variant:`ghost`,size:`sm`,onClick:()=>{let t={...e.metadata};delete t[n],e.onMetadata(t)},children:[`Remove `,r.label.toLowerCase()]}),!e.readOnly&&e.groupActions?.(n),e.errors[`metadata.${n}`]&&(0,N.jsx)(`p`,{role:`alert`,children:e.errors[`metadata.${n}`]})]},n)}),r.map(([t,n])=>(0,N.jsxs)(`details`,{className:`metadata-group`,children:[(0,N.jsx)(`summary`,{children:V(t,{})}),(0,N.jsx)(`p`,{children:`These details are outside the current content form. Review them before removing them from this draft.`}),(0,N.jsx)(`dl`,{children:Object.entries(n).map(([e,t])=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{children:V(e,{})}),(0,N.jsx)(`dd`,{children:typeof t==`string`?t:JSON.stringify(t)})]},e))}),(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>{let n={...e.metadata};delete n[t],e.onMetadata(n)},children:`Remove these details`})]},t))]}),e.system&&t!==`sharing`&&(0,N.jsx)(hr,{meta:e.system})]})}function br(e){let{collection:t,slug:n,locale:r,version:i}=e,a=(0,M.useCallback)(async()=>{let e=await nn(t,n,i,r),a=Xe.sanitize(await Ye.parse(e.body));return{...e,html:a}},[t,n,r,i]),{loaded:o,reload:s}=Le(a,`This snapshot could not be read`);return(0,N.jsxs)(w,{title:`Snapshot v${i}`,onClose:e.onClose,actions:(0,N.jsx)(k,{onClick:e.onClose,children:`Close`}),children:[(0,N.jsx)(`p`,{className:`snapshot-preview-note`,children:`Read-only snapshot. Your draft is unchanged.`}),o.state===`loading`&&(0,N.jsx)(`p`,{role:`status`,children:`Reading the snapshot…`}),o.state===`error`&&(0,N.jsxs)(`div`,{role:`alert`,children:[(0,N.jsx)(`p`,{children:o.message}),(0,N.jsx)(k,{onClick:s,children:`Retry`})]}),o.state===`ready`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`time`,{dateTime:o.data.createdAt,children:p(o.data.createdAt)}),(0,N.jsxs)(`details`,{className:`snapshot-fields`,children:[(0,N.jsx)(`summary`,{children:`Fields`}),(0,N.jsx)(`pre`,{children:JSON.stringify(o.data.fields,null,2)})]}),o.data.contract&&(0,N.jsx)(U,{contract:o.data.contract,metadata:o.data.metadata,fields:o.data.fields,defaults:o.data.defaults,readOnly:!0,errors:{},onMetadata:()=>{}}),typeof o.data.fields.title==`string`&&(0,N.jsx)(`h3`,{children:o.data.fields.title}),(0,N.jsx)(`article`,{className:`snapshot-body`,dangerouslySetInnerHTML:{__html:o.data.html}})]})]})}function xr(e){let[t,n]=(0,M.useState)(!1),r=(0,M.useRef)(null),i=(0,M.useRef)(null),a=(0,M.useId)();return(0,M.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.target;t?.closest(`.ui-modal-layer`)||r.current?.contains(t)||n(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[t]),(0,N.jsxs)(`fieldset`,{ref:r,className:`snapshot-disclosure`,onKeyDown:e=>{e.key===`Escape`&&t&&(e.stopPropagation(),n(!1),i.current?.focus())},children:[(0,N.jsxs)(k,{ref:i,size:`sm`,variant:`ghost`,"aria-label":`Snapshot details`,"aria-expanded":t,"aria-controls":a,onClick:()=>n(!t),children:[`v`,e.entry.version,` · Details`,t?(0,N.jsx)(Bt,{size:14,"aria-hidden":`true`}):(0,N.jsx)(Ge,{size:14,"aria-hidden":`true`})]}),t&&(0,N.jsxs)(`section`,{id:a,className:`snapshot-popover`,"aria-label":`Selected snapshot`,children:[(0,N.jsxs)(`strong`,{children:[`Snapshot v`,e.entry.version]}),(0,N.jsx)(`time`,{dateTime:e.entry.createdAt,children:p(e.entry.createdAt)}),(0,N.jsx)(`span`,{children:e.entry.changedBy?D(e.entry.changedBy):`Unknown author`}),(0,N.jsxs)(`div`,{className:`snapshot-actions`,children:[(0,N.jsx)(k,{size:`sm`,variant:`ghost`,icon:Ht,onClick:e.onPreview,children:`Preview snapshot`}),e.actions]})]})]})}function Sr(e){let[t,n]=(0,M.useState)(null),r=t?.saved===e.saved.version?t.version:e.saved.version,[i,a]=(0,M.useState)(null),[o,s]=(0,M.useState)(null),c=o??e.versions.length>1,l=(0,M.useRef)(null),u=(0,M.useId)(),d=Math.max(0,e.versions.findIndex(e=>e.version===r)),f=e.versions[d],m=[...e.versions].reverse(),h=m.length-1-d,g=(0,M.useRef)(!1),_=()=>{let e=l.current,t=e?.querySelector(`[aria-pressed="true"]`);if(!e||!t)return;let n=t.offsetLeft-(e.clientWidth-t.offsetWidth)/2;e.scrollTo?.({left:n,behavior:`instant`})};(0,M.useEffect)(()=>{c&&!g.current&&_()},[h,c]);let v=t=>{let r=m[t];r&&n({saved:e.saved.version,version:r.version})};return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`snapshot-heading`,children:[(0,N.jsxs)(k,{size:`sm`,variant:`ghost`,icon:Je,"aria-label":c?`Collapse snapshot timeline`:`Expand snapshot timeline`,"aria-expanded":c,"aria-controls":u,onClick:()=>s(!c),children:[`Snapshots `,(0,N.jsx)(`small`,{children:e.versions.length}),c?(0,N.jsx)(Bt,{size:14,"aria-hidden":`true`}):(0,N.jsx)(Ge,{size:14,"aria-hidden":`true`})]}),e.unsaved&&(0,N.jsx)(O,{tone:`accent`,children:`Unsaved changes`}),f&&(0,N.jsx)(xr,{entry:f,actions:e.actions(d),onPreview:()=>a(f.version)})]}),c&&(0,N.jsxs)(`div`,{id:u,className:`snapshot-navigation`,children:[(0,N.jsx)(A,{icon:He,label:`Older snapshot`,size:`sm`,disabled:h<=0,onClick:()=>v(h-1)}),(0,N.jsx)(`div`,{ref:l,className:`snapshot-viewport`,children:(0,N.jsxs)(`div`,{className:`snapshot-ruler`,style:{minWidth:`${Math.max(1,m.length)*104}px`,"--snapshot-edge":`${50/Math.max(1,m.length)}%`},children:[(0,N.jsx)(`ol`,{className:`snapshot-markers`,"aria-label":`Saved snapshots`,children:m.map((t,n)=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`snapshot-stop`,"aria-label":`Select snapshot v${t.version}`,"aria-pressed":n===h,title:p(t.createdAt),onClick:()=>v(n),children:[(0,N.jsxs)(`span`,{className:`snapshot-label`,children:[`v`,t.version,t.version===e.saved.version&&(0,N.jsx)(`span`,{children:`Current`}),t.version===e.saved.liveVersion&&(0,N.jsx)(`span`,{className:`snapshot-live`,children:`Live`})]}),(0,N.jsx)(`span`,{className:`snapshot-tick`,"aria-hidden":`true`}),(0,N.jsx)(`time`,{dateTime:t.createdAt,children:new Date(t.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`})})]})},t.version))}),m.length>1&&(0,N.jsx)(`input`,{className:`snapshot-slider`,onPointerDown:()=>{g.current=!0},onPointerUp:()=>{g.current=!1,_()},onPointerCancel:()=>{g.current=!1,_()},type:`range`,"aria-label":`Snapshot selection`,min:0,max:m.length-1,step:1,value:h,"aria-valuetext":`v${f?.version}: ${p(f?.createdAt??``)}`,onChange:e=>v(Number(e.target.value))}),m.length===1&&(0,N.jsx)(`span`,{className:`snapshot-single`,"aria-hidden":`true`})]})}),(0,N.jsx)(A,{icon:ye,label:`Newer snapshot`,size:`sm`,disabled:h>=m.length-1,onClick:()=>v(h+1)})]}),i!==null&&(0,N.jsx)(br,{collection:e.collection,slug:e.slug,locale:e.locale,version:i,onClose:()=>a(null)})]})}function Cr(e){let{collection:t,slug:n,locale:r}=e,i=(0,M.useCallback)(()=>tn(t,n,r).then(e=>e.versions),[t,n,r]),{loaded:a,reload:o}=Le(i,`The history could not be read`),s=(0,M.useRef)(e.saved.version);return(0,M.useEffect)(()=>{s.current!==e.saved.version&&(s.current=e.saved.version,o())},[e.saved.version,o]),{loaded:a,reload:o}}function wr(e){let[t,n]=(0,M.useState)(null),r=(0,M.useRef)(null),i=(0,M.useRef)(0);return{comparison:t,show:t=>{r.current=document.activeElement instanceof HTMLElement?document.activeElement:null,e(null);let a=++i.current;t().then(e=>{a===i.current&&n(e)}).catch(t=>{a===i.current&&e(T(t,`The versions to compare could not be read`))})},close:()=>{n(null),r.current?.focus()}}}function Tr(e,t,n,r){let i=t=>nn(e.collection,e.slug,t,e.locale);return a=>{let o=t[a];if(!o)return{diff:null,compare:null,restore:null};let s=t[a+1],c=async e=>{let[t,n]=await Promise.all([i(e),i(o.version)]);return{base:t,compare:n,form:!1}},l=async()=>({base:await i(o.version),compare:sn(t,e.draft),form:!0});return{diff:s?()=>n(()=>c(s.version)):null,compare:e.unsaved||a>0?()=>n(l):null,restore:e.canRestore&&a>0?()=>r(o.version):null}}}function Er(e,t){let[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(!1),o=fe(),s=async n=>{t(null);let r;try{r=await rn(e.collection,e.slug,n,e.locale)}catch(e){t(ln(n,T(e,`the store refused it`)));return}try{await e.onRestored()}catch{t(un(n,r.version));return}o({text:`v${n} restored as v${r.version}. The live page is unchanged until you publish.`})};return{asked:n,restoring:i,ask:r,cancel:()=>r(null),confirm:()=>{n===null||i||(r(null),a(!0),s(n).finally(()=>a(!1)))}}}function Dr(e){let[t,n]=(0,M.useState)(null),r=wr(n),[i,a]=(0,M.useState)(null);async function o(t){try{let n=await nn(e.collection,e.slug,t,e.locale);e.onPrepare({fields:n.fields,metadata:n.metadata,body:n.body,defaults:n.defaults}),a(null)}catch(e){n(T(e,`The snapshot could not be read`))}}let s=Er(e,n),c=Tr(e,e.versions,r.show,s.ask);return(0,N.jsxs)(N.Fragment,{children:[t&&(0,N.jsx)(an,{children:t}),e.canRestore&&e.versions.length>1&&(0,N.jsxs)(`details`,{className:`data-disclosure`,children:[(0,N.jsx)(`summary`,{children:`Prepare an earlier snapshot as a draft`}),(0,N.jsx)(`p`,{children:`Bring its values into the current content form for review and correction. Nothing is saved or published.`}),e.versions.slice(1).map(e=>(0,N.jsxs)(k,{size:`sm`,onClick:()=>a(e.version),children:[`Prepare v`,e.version]},e.version))]}),i!==null&&(0,N.jsx)(w,{title:`Prepare v${i} as a draft?`,onClose:()=>a(null),actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:()=>a(null),children:`Cancel`}),(0,N.jsx)(k,{onClick:()=>{o(i)},children:`Prepare draft`})]}),children:(0,N.jsxs)(`p`,{children:[`Replace the current form with this snapshot’s values. Review them against today’s content form before saving.`,e.unsaved?` Your unsaved form changes will be replaced.`:``]})}),e.timeline?(0,N.jsx)(Sr,{...e,actions:t=>(0,N.jsx)(fn,{n:e.versions[t]?.version??0,actions:c(t),restoring:s.restoring})}):(0,N.jsx)(`ol`,{className:`data-versions`,"aria-label":`Versions`,children:e.versions.map((t,n)=>(0,N.jsx)(pn,{version:t,props:e,actions:c(n),restoring:s.restoring},t.version))}),r.comparison&&(0,N.jsx)(bn,{comparison:r.comparison,onClose:r.close}),s.asked!==null&&(0,N.jsx)(dn,{version:s.asked,unsaved:e.unsaved,onConfirm:s.confirm,onClose:s.cancel})]})}function Or(e){let{loaded:t,reload:n}=Cr(e),r=(0,N.jsxs)(N.Fragment,{children:[t.state===`loading`&&(0,N.jsx)(F,{children:`Reading the history…`}),t.state===`error`&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(F,{tone:`error`,children:t.message}),(0,N.jsx)(k,{size:`sm`,onClick:n,children:`Retry history`})]}),t.state===`ready`&&(t.data.length===0?(0,N.jsx)(F,{children:`No version history yet.`}):(0,N.jsx)(Dr,{...e,versions:t.data}))]});return e.timeline?(0,N.jsx)(`section`,{className:`snapshot-timeline`,"aria-label":`Article snapshots`,children:r}):(0,N.jsx)(P,{title:`History`,lead:`The ${e.locale.toUpperCase()} version's saved versions, newest first. Restore saves an earlier one again as a new version.`,children:r})}var kr=0,Ar=new Set;function jr(e){return Ar.add(e),()=>Ar.delete(e)}function Mr(){return kr}function Nr(){kr+=1;for(let e of Ar)e()}function Pr(){return(0,M.useSyncExternalStore)(jr,Mr,Mr)}function Fr(e,t,n){let r=t.items.find(e=>e.collection===n.collection&&e.slug===n.slug);return r?r.status===`complete`?{step:e,state:`generated`,text:r.result??`Filled`}:r.status===`error`?{step:e,state:`error`,text:r.error??`Failed`}:{step:e,state:`skipped`,text:r.result??`Nothing missing`}:{step:e,state:`skipped`,text:`Not part of the job`}}function Ir(e){return e.saved?!e.canEdit||!e.admin?`Enrichment is run by an admin.`:e.lockedBy?`${D(e.lockedBy)} is editing: enrichment waits until they finish.`:e.defaultLocaleName===null?`The site's locales could not be read: enrichment works on the default locale's version only.`:e.defaultLocale?e.dirty?`Save or discard your changes first: enrichment saves a new version of the document.`:null:`Enrichment reads and writes the ${e.defaultLocaleName.toUpperCase()} version: open it to enrich.`:`Save the page first: enrichment works on saved documents.`}function Lr(e){return e.some(e=>e.step===`meta-descriptions`&&e.state===`generated`)}async function Rr(e,t,n){let r=await bt(e,{scope:`item`,...t},n);return r?r.state===`empty`?{step:e,state:`skipped`,text:r.message}:Fr(e,r.status,t):null}function zr(e,t){let[n,r]=(0,M.useState)({state:`idle`}),i=(0,M.useRef)(!0);(0,M.useEffect)(()=>(i.current=!0,()=>{i.current=!1}),[]);let a=(0,M.useRef)(t);(0,M.useLayoutEffect)(()=>{a.current=t});let o=(0,M.useRef)(!1),{collection:s,slug:c}=e;return{run:n,start:(0,M.useCallback)(e=>{if(o.current)return;o.current=!0;let t=()=>i.current;(async()=>{let n=[];try{for(let i of e){r({state:`running`,step:i});let e=await Rr(i,{collection:s,slug:c},t);if(!e)return;n.push(e)}if(!t())return;r({state:`done`,outcomes:n}),a.current(n)}catch(e){if(!t())return;r({state:`failed`,message:T(e,`Enrichment failed`)}),n.length>0&&a.current(n)}finally{o.current=!1}})()},[s,c])}}var Br={generated:E,skipped:st,error:vt};function Vr({outcomes:e}){return(0,N.jsx)(`ul`,{className:`data-outcomes`,children:e.map(e=>{let t=Br[e.state];return(0,N.jsxs)(`li`,{className:`data-outcome data-outcome--${e.state}`,children:[(0,N.jsx)(t,{"aria-hidden":`true`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`strong`,{children:yt[e.step]}),` · `,e.text]})]},e.step)})})}function Hr(e){switch(e.state){case`running`:return`Enriching · ${yt[e.step]}…`;case`failed`:return`Enrichment failed: ${e.message}`;case`done`:return`Enrichment finished. ${e.outcomes.map(e=>`${yt[e.step]}: ${e.text}`).join(`. `)}`;default:return``}}function Ur({run:e}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:Hr(e)}),e.state===`running`&&(0,N.jsxs)(F,{children:[`Enriching · `,yt[e.step],`…`]}),e.state===`failed`&&(0,N.jsx)(F,{tone:`error`,children:e.message}),e.state===`done`&&(0,N.jsx)(Vr,{outcomes:e.outcomes})]})}function Wr(){return(0,N.jsxs)(F,{children:[`No language model is set up. Set one up in `,(0,N.jsx)(s,{to:Ae,children:`Setup › AI provider`}),`.`]})}function Gr(e){let{run:t,start:n}=zr(e.target,e.onFinished),r=xt(),i=t.state===`running`,a=i?`Enrichment is running.`:r.state===`running`?`A run across the site is going, and the API runs one job at a time. Enrich this document when it ends.`:Ir(e.facts);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`data-actions`,children:(0,N.jsx)(Ct,{reason:a,variant:`primary`,icon:St,onClick:()=>n([`meta-descriptions`,`archetype`]),children:`Enrich this document`})}),a&&!i&&(0,N.jsx)(F,{children:a}),(0,N.jsx)(Ur,{run:t})]})}function Kr(e){let t=gt();return(0,N.jsxs)(P,{title:`Enrichment`,lead:(0,N.jsxs)(N.Fragment,{children:[`Fills what is `,(0,N.jsx)(`em`,{children:`missing`}),` — a meta description and the Schema.org properties no one has set — with the language model set up in Setup › AI provider. It never overwrites a value someone set. What it fills is saved to the document at once: the meta description as a new version and in the document's SEO settings, the Schema.org properties in those settings. The SEO settings have no versions, so the structured data on the live page — and the meta description the site reads from them first — changes straight away.`]}),children:[t===`loading`&&(0,N.jsx)(F,{children:`Reading the AI provider…`}),t===`missing`&&(0,N.jsx)(Wr,{}),(t===`configured`||t===`unknown`)&&(0,N.jsx)(Gr,{...e})]})}var qr={error:{icon:vt,label:`Error`,order:0},warning:{icon:Et,label:`Warning`,order:1},info:{icon:Tt,label:`Note`,order:2}};function Jr({finding:e,reader:t}){let{icon:n,label:r}=qr[e.severity];return(0,N.jsxs)(`li`,{className:`editor-finding editor-finding--${e.severity}`,children:[(0,N.jsx)(n,{className:`editor-finding-icon`,role:`img`,"aria-label":r}),(0,N.jsxs)(`span`,{className:`editor-finding-text`,children:[t&&(0,N.jsxs)(`span`,{className:`editor-finding-reader`,children:[t,`: `]}),e.message,e.property&&(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsxs)(`code`,{children:[e.type?`${e.type}.`:``,e.property]})]}),e.source&&(0,N.jsxs)(`a`,{className:`editor-finding-source`,href:e.source,target:`_blank`,rel:`noreferrer`,children:[`Documentation`,(0,N.jsx)(wt,{"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`visually-hidden`,children:` (opens in a new tab)`})]})]})]})}function Yr(e,t){let n=[{id:`page`,label:`Title and meta description`,findings:[]},{id:`schema.org`,label:`Schema.org`,findings:[]},...t.map(e=>({id:e.id,label:e.name,findings:[]}))];for(let t of e){let e=t.check===`structured-data`?t.reader??`schema.org`:`page`,r=n.find(t=>t.id===e);r||(r={id:e,label:e,findings:[]},n.push(r)),r.findings.push(t)}let r=e=>qr[e.severity].order;for(let e of n)e.findings.sort((e,t)=>r(e)-r(t));return n}function Xr(e){let t=e.filter(e=>e.severity===`error`).length,n=e.filter(e=>e.severity===`warning`).length;return t>0?{tone:`danger`,text:`${t} error${t===1?``:`s`}`}:n>0?{tone:`warning`,text:`${n} warning${n===1?``:`s`}`}:{tone:`success`,text:`Passes`}}function Zr({group:e}){let t=(0,M.useId)(),{tone:n,text:r}=Xr(e.findings);return(0,N.jsxs)(`section`,{className:`data-finding-group`,"aria-labelledby":t,children:[(0,N.jsxs)(`div`,{className:`data-finding-head`,children:[(0,N.jsx)(`h3`,{id:t,className:`data-finding-title`,children:e.label}),(0,N.jsx)(O,{tone:n,children:r})]}),e.findings.length===0?(0,N.jsxs)(`p`,{className:`data-finding-clean`,children:[(0,N.jsx)(E,{"aria-hidden":`true`}),`No findings.`]}):(0,N.jsx)(`ul`,{className:`data-finding-list`,children:e.findings.map((e,t)=>(0,N.jsx)(Jr,{finding:e},`${e.code??e.check}-${e.property??``}-${t}`))})]})}function Qr({findings:e,readers:t}){return(0,N.jsx)(`div`,{className:`data-findings`,children:Yr(e,t).map(e=>(0,N.jsx)(Zr,{group:e},e.id))})}function $r({findings:e,version:t}){return(0,N.jsxs)(P,{title:`Findings per search engine`,lead:`The saved version, v${t}, checked against Schema.org and the rules of each search engine the site targets. Errors make the markup invalid; warnings keep the page from a search feature.`,children:[e.state===`loading`&&(0,N.jsx)(F,{children:`Checking…`}),e.state===`error`&&(0,N.jsx)(F,{tone:`error`,children:e.message}),e.state===`ready`&&(0,N.jsx)(Qr,{findings:e.data.findings,readers:e.data.readers})]})}var ei=(0,M.lazy)(()=>t(()=>import(`./GraphBrowser-BBKTzzRV.js`).then(e=>({default:e.GraphBrowser})),__vite__mapDeps([2,1,3,4,0,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])));function ti(e){let{source:t,collection:n,slug:r,readOnly:i,onStage:a}=e,o=fe();async function s(e){a(e),o({text:`Graph added to your draft. Save draft, then publish when ready.`})}return(0,N.jsxs)(`div`,{className:`data-graph-editor`,children:[i?(0,N.jsx)(F,{children:i}):(0,N.jsx)(F,{children:`Apply adds your graph changes to this document’s draft. Save draft keeps a snapshot; Publish updates the live page.`}),(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(F,{children:`Loading the graph editor…`}),children:(0,N.jsx)(ei,{saveLabel:`Apply to draft`,model:t.model,catalogTypes:t.catalogTypes,catalogDetails:t.catalogDetails,rawData:t.emitted,collection:n,slug:r,configData:i?void 0:e.draftConfig??t.editable,onSave:i?void 0:s})})]})}function ni(e,t){return(0,M.useMemo)(()=>{if(e.state!==`ready`||t.state!==`ready`)return[];let n=new Set(t.data.catalogTypes.filter(e=>e.siteLevel).map(e=>e.type));return pt({nodes:t.data.nodes,resolved:e.data,siteTypes:n})},[e,t])}function ri({resolved:e,graph:t}){let n=ni(e,t),r=[e,t].find(e=>e.state===`error`);return r?.state===`error`?(0,N.jsx)(F,{tone:`error`,children:r.message}):e.state===`loading`||t.state===`loading`?(0,N.jsx)(F,{children:`Reading the structured data…`}):n.length===0?(0,N.jsx)(F,{children:`The page emits no entities.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ct,{counts:dt(n)}),(0,N.jsx)(ut,{views:n})]})}function ii({graph:e}){return e.state===`loading`?(0,N.jsx)(F,{children:`Composing the JSON-LD…`}):e.state===`error`?(0,N.jsx)(F,{tone:`error`,children:e.message}):(0,N.jsxs)(`details`,{className:`data-disclosure`,children:[(0,N.jsx)(`summary`,{children:`What the page emits · view-source`}),(0,N.jsx)(lt,{data:e.data.emitted,label:`application/ld+json`})]})}function ai({open:e,readOnly:t,controls:n,onToggle:r}){return(0,N.jsx)(k,{size:`sm`,icon:t?we:Dt,"aria-expanded":e,"aria-controls":n,onClick:r,children:e?`Close the graph editor`:t?`Browse the graph`:`Edit the graph`})}function oi(e){let{graph:t}=e,[n,r]=(0,M.useState)(e.initialOpen??!1),i=(0,M.useId)();return(0,N.jsxs)(P,{title:`JSON-LD graph · what this page emits`,lead:`Every node the page emits, with its type, @id and scope, and each value with where it comes from; a value krantho adds while composing the page reads computed. Sources are read for the saved version, v${e.version}.`,aside:t.state===`ready`?(0,N.jsx)(ai,{open:n,readOnly:e.readOnly,controls:i,onToggle:()=>r(e=>!e)}):null,children:[(0,N.jsx)(ri,{resolved:e.resolved,graph:t}),(0,N.jsx)(ii,{graph:t}),(0,N.jsx)(`div`,{id:i,children:n&&t.state===`ready`&&(0,N.jsx)(ti,{source:t.data,collection:e.collection,slug:e.slug,readOnly:e.readOnly,onStage:e.onStage,draftConfig:e.draftConfig})})]})}function W(e){return typeof e==`string`&&e.trim()!==``?e:``}function si(e){let{fields:t,documentSeo:n,siteSeo:r}=e,i=L(Object.keys(t)),a=e=>W(Cn(i,e,t)),o=W(n.headline)||W(n.name)||a(`title`)||e.slug,s=W(n.description)||a(`description`),c=W(n.image)||a(`image`)||W(r[`og-default-image`]),l=a(`ogImage`)||c;return{title:o,description:s,url:W(n.url)||a(`canonicalUrl`)||e.pageUrl,social:{title:a(`ogTitle`)||o,description:a(`ogDescription`)||s,image:l||null,type:a(`ogType`)||`website`,siteName:W(r.name)||e.siteName},twitterCard:l?`summary_large_image`:`summary`}}function ci(e){if(!e)return{host:``,trail:``};try{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean).map(decodeURIComponent);return{host:t.host,trail:n.map(e=>` › ${e}`).join(``)}}catch{return{host:e,trail:``}}}function li(e){return/^(https?:)?\/\//.test(e)||e.startsWith(`/`)?e:`/api/media/${encodeURIComponent(e)}/image?preset=lg`}function ui(e){return e?.entities[0]?.properties??{}}function di(e){switch(e.state){case`not-live`:return`Checked once the page is live: the search engines read the live page.`;case`other-locale`:return`Checked for the default locale's live page only.`;case`unlisted`:return`Not among the site's checked live pages.`;case`error`:return`The rich results could not be read.`;default:return null}}function fi({feature:e}){return(0,N.jsxs)(`li`,{className:`data-rich`,children:[e.eligible?(0,N.jsx)(E,{className:`data-rich-icon data-rich-icon--eligible`,"aria-hidden":`true`}):(0,N.jsx)(st,{className:`data-rich-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`data-rich-name`,children:e.feature}),(0,N.jsxs)(`span`,{className:`data-rich-reader`,children:[e.reader,` · `,(0,N.jsx)(`code`,{children:e.type})]}),(0,N.jsx)(O,{tone:e.eligible?`success`:`neutral`,children:e.eligible?`Eligible`:`Not eligible`})]})}function pi({rich:e}){if(e.state===`loading`)return(0,N.jsx)(F,{children:`Reading the rich results…`});if(e.state===`error`)return(0,N.jsx)(F,{tone:`error`,children:e.message});let t=di(e.data);if(t)return(0,N.jsx)(F,{children:t});let n=e.data.state===`listed`?e.data.features:[];return n.length===0?(0,N.jsx)(F,{children:`No search feature the readers still show applies to this page.`}):(0,N.jsx)(`ul`,{className:`data-rich-list`,"aria-label":`Rich results`,children:n.map(e=>(0,N.jsx)(fi,{feature:e},`${e.reader}-${e.feature}-${e.type}`))})}function mi({rich:e}){return(0,N.jsx)(P,{title:`Rich results`,lead:`From the search engines' own rules: only the features they still show. What keeps the page from one is under Findings.`,children:(0,N.jsx)(pi,{rich:e})})}function hi(e,t){let n=L(Object.keys(e)),r={};for(let i of t)r[i]=Cn(n,i,e);return r}function gi(e,t){let n=t?.title.maxChars;return e.length===0?{label:`Page title`,pass:!1,hint:`Missing title`}:n===void 0?{label:`Page title`,pass:!0,hint:`${e.length} chars`}:{label:`Page title`,pass:e.length<=n,hint:e.length>n?`Too long (${e.length}/${n})`:`${e.length}/${n} chars`}}function _i(e,t){let n=`Meta description`,r=e.length;if(r===0)return{label:n,pass:!1,hint:`Missing`};if(!t)return{label:n,pass:!0,hint:`${r} chars`};let{minChars:i,maxChars:a}=t.metaDescription;return r<i?{label:n,pass:!1,hint:`Too short (${r}/${i}–${a})`}:r>a?{label:n,pass:!1,hint:`Too long (${r}/${a})`}:{label:n,pass:!0,hint:`${r}/${a} chars`}}function vi(e,t,n){let{description:r,title:i}=hi(e,[`description`,`title`]),a=[gi(i,n),_i(r,n)];a.push({label:`Body content`,pass:t.length>100,hint:t.length===0?`Empty body`:t.length<100?`Very short content`:`${t.length} chars`});let o=(t.match(/^## /gm)??[]).length;a.push({label:`Heading structure`,pass:o>0,hint:o===0?`No ## headings found`:`${o} section heading(s)`});let s=(t.match(/\[.*?\]\(.*?\)/g)??[]).length;return a.push({label:`Links`,pass:s>0,hint:s===0?`No links in content`:`${s} link(s)`}),a}function yi({id:e,label:t,help:n,children:r}){return(0,N.jsxs)(`div`,{className:`data-field`,children:[(0,N.jsx)(`label`,{htmlFor:e,className:`data-field-label`,children:t}),r,n&&(0,N.jsx)(`p`,{id:`${e}-help`,className:`data-field-help`,children:n})]})}function bi(e){return typeof e==`string`?e:``}function xi({title:e,description:t,url:n}){let{host:r,trail:i}=ci(n);return(0,N.jsxs)(`div`,{className:`serp-preview`,children:[(0,N.jsxs)(`div`,{className:`serp-preview-url-row`,children:[(0,N.jsx)(`span`,{className:`serp-preview-favicon`,"aria-hidden":`true`}),(0,N.jsxs)(`div`,{className:`serp-preview-url-group`,children:[(0,N.jsx)(`span`,{className:`serp-preview-site-name`,children:r||`Address not known`}),(0,N.jsxs)(`span`,{className:`serp-preview-breadcrumb`,children:[r,i]})]})]}),(0,N.jsx)(`p`,{className:`serp-preview-title`,children:e}),(0,N.jsx)(`p`,{className:`serp-preview-description`,children:t||`No description: a search engine picks text from the page.`})]})}function Si({preview:e}){return(0,N.jsx)(P,{title:`Search result`,lead:`From the draft's current values, before you save. The live page changes when you publish.`,children:(0,N.jsx)(xi,{title:e.title,description:e.description,url:e.url})})}function Ci({draft:e,limits:t}){let n=vi(e.fields,e.body,t),r=n.filter(e=>!e.pass).length;return(0,N.jsx)(P,{title:`Checks`,aside:(0,N.jsx)(O,{tone:r===0?`success`:`warning`,children:r===0?`All pass`:`${r} to review`}),children:(0,N.jsx)(`ul`,{className:`data-checks`,"aria-label":`Checks`,children:n.map(e=>(0,N.jsxs)(`li`,{className:e.pass?`data-check`:`data-check data-check--open`,children:[e.pass?(0,N.jsx)(E,{className:`data-check-icon`,role:`img`,"aria-label":`Passes`}):(0,N.jsx)(pe,{className:`data-check-icon`,role:`img`,"aria-label":`To review`}),(0,N.jsx)(`span`,{className:`data-check-label`,children:e.label}),(0,N.jsx)(`span`,{className:`data-check-hint`,children:e.hint})]},e.label))})})}function wi({name:e,label:t,hint:n,fields:r,onField:i}){return(0,N.jsxs)(`label`,{className:`data-toggle`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:r[e]!==!1,onChange:t=>i(e,t.target.checked)}),(0,N.jsx)(`span`,{children:t}),(0,N.jsx)(`span`,{className:`data-toggle-hint`,children:n})]})}function Ti({fields:e,pageUrl:t,onField:n}){let r=(0,M.useId)();return(0,N.jsx)(yi,{id:r,label:`canonical-url`,help:t?`Empty: the page's own address, ${t}`:void 0,children:(0,N.jsx)(`input`,{id:r,type:`url`,className:`editor-control`,value:bi(e[`canonical-url`]),placeholder:t??void 0,"aria-describedby":t?`${r}-help`:void 0,onChange:e=>n(`canonical-url`,e.target.value)})})}function Ei({fields:e,pageUrl:t,readOnly:n,onField:r}){let i=e[`robots-index`]===!1?`noindex`:`index`,a=e[`robots-follow`]===!1?`nofollow`:`follow`;return(0,N.jsx)(P,{title:`Indexing`,lead:`Saved with the draft, as the fields canonical-url, robots-index and robots-follow.`,children:(0,N.jsxs)(`fieldset`,{className:`data-fields`,disabled:n,children:[(0,N.jsx)(`legend`,{className:`visually-hidden`,children:`Indexing`}),(0,N.jsx)(Ti,{fields:e,pageUrl:t,onField:r}),(0,N.jsx)(wi,{name:`robots-index`,label:`Index`,hint:`Search engines may list the page`,fields:e,onField:r}),(0,N.jsx)(wi,{name:`robots-follow`,label:`Follow`,hint:`Search engines may follow its links`,fields:e,onField:r}),(0,N.jsx)(`code`,{className:`data-tag`,children:`<meta name="robots" content="${i}, ${a}" />`})]})})}function Di({image:e}){let[t,n]=(0,M.useState)(null);return!e||t===e?(0,N.jsxs)(`div`,{className:`social-card-image social-card-image--empty`,children:[(0,N.jsx)(qe,{"aria-hidden":`true`}),(0,N.jsx)(`span`,{children:e?`The image could not load`:`No social image`})]}):(0,N.jsx)(`div`,{className:`social-card-image`,children:(0,N.jsx)(`img`,{src:li(e),alt:``,onError:()=>n(e)})})}function Oi(e){if(!e)return``;try{return new URL(e).host}catch{return e}}function ki({preview:e}){let{social:t,twitterCard:n}=e,r=Oi(e.url),i=n===`summary_large_image`;return(0,N.jsxs)(`div`,{className:`social-previews`,children:[(0,N.jsxs)(`figure`,{className:`social-preview`,children:[(0,N.jsxs)(`figcaption`,{className:`social-preview-label`,children:[`Open Graph · og:type `,t.type]}),(0,N.jsxs)(`div`,{className:`social-card`,children:[(0,N.jsx)(Di,{image:t.image}),(0,N.jsxs)(`div`,{className:`social-card-text`,children:[(0,N.jsx)(`span`,{className:`social-card-site`,children:t.siteName||r}),(0,N.jsx)(`span`,{className:`social-card-title`,children:t.title}),(0,N.jsx)(`span`,{className:`social-card-description`,children:t.description})]})]})]}),(0,N.jsxs)(`figure`,{className:`social-preview`,children:[(0,N.jsxs)(`figcaption`,{className:`social-preview-label`,children:[`X · `,n]}),(0,N.jsxs)(`div`,{className:i?`social-card`:`social-card social-card--summary`,children:[i?(0,N.jsx)(Di,{image:t.image}):null,(0,N.jsxs)(`div`,{className:`social-card-text`,children:[(0,N.jsx)(`span`,{className:`social-card-title`,children:t.title}),(0,N.jsx)(`span`,{className:`social-card-site`,children:r})]})]})]})]})}var Ai=[`website`,`article`,`product`,`profile`];function ji({value:e,chooseRef:t,onChoose:n,onClear:r}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:t,size:`sm`,onClick:n,children:e?`Change`:`Choose image`}),e&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>{r(),t.current?.focus()},children:`Clear`})]})}function Mi({fields:e,readOnly:t,onField:n}){let r=bi(e[`og-image`]),[i,a]=(0,M.useState)(!1),o=(0,M.useRef)(null);function s(e){n(`og-image`,e.url),a(!1)}return(0,N.jsxs)(`fieldset`,{className:`data-field data-image-field`,disabled:t,children:[(0,N.jsx)(`legend`,{className:`data-field-label`,children:`og-image`}),(0,N.jsxs)(`div`,{className:`data-image-choice`,children:[(0,N.jsx)(`code`,{className:`data-image-value`,children:r||`None: the page image or the site default`}),(0,N.jsx)(ji,{value:r,chooseRef:o,onChoose:()=>a(!0),onClear:()=>n(`og-image`,``)})]}),(0,N.jsx)(`p`,{className:`data-field-help`,children:`1200 × 630 pixels suits most networks.`}),i&&(0,N.jsx)(Vn,{onSelect:s,onUpload:s,onClose:()=>a(!1)})]})}function Ni({name:e,help:t,area:n,fields:r,onField:i}){let a=(0,M.useId)(),o={id:a,value:bi(r[e]),"aria-describedby":`${a}-help`,onChange:t=>i(e,t.target.value)};return(0,N.jsx)(yi,{id:a,label:e,help:t,children:n?(0,N.jsx)(`textarea`,{...o,className:`editor-control editor-control--area`,rows:2}):(0,N.jsx)(`input`,{...o,className:`editor-control`})})}function Pi({fields:e,onField:t}){let n=(0,M.useId)();return(0,N.jsx)(yi,{id:n,label:`og-type`,help:`Auto: website.`,children:(0,N.jsxs)(`select`,{id:n,className:`editor-control editor-control--short`,value:bi(e[`og-type`]),"aria-describedby":`${n}-help`,onChange:e=>t(`og-type`,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Auto`}),Ai.map(e=>(0,N.jsx)(`option`,{value:e,children:e},e))]})})}function Fi(e){let{fields:t,readOnly:n,onField:r}=e;return(0,N.jsxs)(P,{title:`Social cards`,lead:`From the draft's current values. The overrides are fields of the document, saved with the draft.`,children:[(0,N.jsx)(ki,{preview:e.preview}),(0,N.jsxs)(`fieldset`,{className:`data-fields`,disabled:n,children:[(0,N.jsx)(`legend`,{className:`data-fields-legend`,children:`Overrides for sharing`}),(0,N.jsx)(Ni,{name:`og-title`,help:`Empty: the page title.`,area:!1,fields:t,onField:r}),(0,N.jsx)(Ni,{name:`og-description`,help:`Empty: the meta description.`,area:!0,fields:t,onField:r}),(0,N.jsx)(Pi,{fields:t,onField:r})]}),(0,N.jsx)(Mi,{fields:t,readOnly:n,onField:r})]})}async function Ii(e){if(!e.live)return{state:`not-live`};if(!e.defaultLocale)return{state:`other-locale`};try{let{pages:t,readers:n}=await kt(),r=t.find(t=>t.collection===e.collection&&t.slug===e.slug);if(!r)return{state:`unlisted`};let i=e=>n.find(t=>t.id===e)?.name??e;return{state:`listed`,features:r.features.map(e=>({feature:e.feature,type:e.type,reader:i(e.reader),eligible:e.eligible}))}}catch{return{state:`error`}}}async function Li(e){try{return(await Mt(e)).config?.config??null}catch(e){if(e instanceof Fe&&e.status===501)return null;throw e}}async function Ri(e){let t=await Promise.allSettled(e.map(Nt)),n=new Map;for(let e of t)e.status===`fulfilled`&&n.set(e.value.type.type,e.value);return n}async function zi(e,t,n){let[r,i,a,o,s]=await Promise.all([Pt(e,t,n),Li(`doc:${e}/${t}`),Li(`collection:${e}`),Li(`site`),jt().catch(()=>({types:[]}))]),c=ft(r),l={document:i,collection:a,site:o};return{emitted:r,nodes:c,model:_t(r),editable:ht(c,l),configs:l,catalogTypes:s.types,catalogDetails:await Ri(mt(c))}}function Bi(e,t,n){let{loaded:r,reload:i}=Le(e,t),a=(0,M.useRef)(n);return(0,M.useEffect)(()=>{a.current!==n&&(a.current=n,i())},[n,i]),r}function Vi(e,t){let{collection:n,slug:r,locale:i,live:a,defaultLocale:o}=e,s=(0,M.useCallback)(()=>Ot(n,r,i).then(e=>e.entities),[n,r,i]),c=(0,M.useCallback)(()=>At(n,r,i),[n,r,i]),l=(0,M.useCallback)(()=>Ii({collection:n,slug:r,live:a,defaultLocale:o}),[n,r,a,o]),u=(0,M.useCallback)(()=>zi(n,r,i),[n,r,i]),d=`${e.version}:${t}`;return{resolved:Bi(s,`The structured data could not be read`,d),findings:Bi(c,`The findings could not be read`,d),rich:Bi(l,`The rich results could not be read`,d),graph:Bi(u,`The emitted graph could not be read`,d)}}function Hi(e,t){let n=e.collection?xe(e.collection,t):null,r=e.site?.site.baseUrl;return n!==null&&r?je(r,n):null}function Ui(e,t,n,r){return si({fields:e.draft.draft.fields,slug:n.meta.slug,pageUrl:Hi(t,n.meta.slug),documentSeo:Sn(e.draft.draft.metadata),siteSeo:ui(r?.configs.site??null),siteName:t.site?.site.name??``})}function Wi(e,t){let{meta:n}=e;return{collection:n.collection,slug:n.slug,locale:n.locale,version:n.version,live:n.liveVersion!==null,defaultLocale:t.locales!==null&&n.locale===t.locales.defaultLocale}}function Gi(e,t,n){return{saved:!0,admin:e.isAdmin,canEdit:e.canEdit,lockedBy:e.facts.lockedBy,dirty:e.draft.dirty,defaultLocale:n.defaultLocale,defaultLocaleName:t.locales?.defaultLocale??null}}function Ki(e){return e.readOnly?`Read-only: the graph can be browsed and exported, not changed.`:e.schema?.contract.metadata.seo?null:`This content form does not include structured data overrides.`}function qi({ws:e,source:t,document:n,preview:r}){let{fields:i}=e.draft.draft;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Si,{preview:r}),(0,N.jsx)(Fi,{preview:r,fields:i,readOnly:e.readOnly,onField:e.setField}),(0,N.jsx)(Ei,{fields:i,pageUrl:Hi(t,n.meta.slug),readOnly:e.readOnly,onField:e.setField}),(0,N.jsx)(Ci,{draft:e.draft.draft,limits:t.site?.seo.limits??null})]})}function Ji(e,t){let{reloadDocument:n}=e;return(0,M.useCallback)(e=>{t(),Lr(e)&&n()},[t,n])}function Yi({ws:e,source:t,document:n,initialGraphOpen:r}){let[i,a]=(0,M.useState)(0),o=Wi(n,t),s=Vi(o,i),c=Ji(e,(0,M.useCallback)(()=>{a(e=>e+1),Nr()},[])),l=s.graph.state===`ready`?s.graph.data:null,{meta:u}=n;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(qi,{ws:e,source:t,document:n,preview:Ui(e,t,n,l)}),(0,N.jsx)(oi,{initialOpen:r,resolved:s.resolved,graph:s.graph,collection:u.collection,slug:u.slug,version:u.version,readOnly:Ki(e),onStage:t=>e.draft.setMetadata({...e.draft.draft.metadata,seo:t}),draftConfig:e.draft.draft.metadata.seo}),(0,N.jsx)(mi,{rich:s.rich}),(0,N.jsx)($r,{findings:s.findings,version:u.version}),(0,N.jsx)(Kr,{target:{collection:u.collection,slug:u.slug},facts:Gi(e,t,o),onFinished:c})]})}function Xi({seo:e}){return(0,N.jsx)(P,{title:`Structured data`,children:(0,N.jsx)(F,{children:e?`This collection's documents have no page, so they emit no structured data and search engines do not read them.`:`SEO is off on this site: no structured data, previews or findings are made.`})})}function Zi({ws:e,document:t}){let{meta:n}=t;return(0,N.jsx)(Or,{collection:n.collection,slug:n.slug,locale:n.locale,saved:{version:n.version,liveVersion:n.liveVersion},draft:e.draft.draft,unsaved:e.draft.dirty,canRestore:e.isAdmin&&!e.readOnly,onRestored:e.reloadDocument,onPrepare:e.prepareSnapshot})}function Qi({ws:e,source:t,initialGraphOpen:n}){let r=h(u(),`seo`),{document:i}=e;if(!i)return(0,N.jsx)(`div`,{className:`data-mode`,children:(0,N.jsx)(ot,{icon:Wt,title:`Nothing saved yet`,children:`Data mode reads the saved page: its structured data, findings and history. Save a draft first.`})});let a=t.collection?.pages??!1;return(0,N.jsxs)(`div`,{className:`data-mode`,children:[r&&a?(0,N.jsx)(Yi,{ws:e,source:t,document:i,initialGraphOpen:n}):(0,N.jsx)(Xi,{seo:r}),(0,N.jsx)(Zi,{ws:e,document:i})]})}function $i(e){return e?te(e):`draft`}function ea(e){if(!e)return`Not saved yet`;let{version:t,liveVersion:n}=e;return n===null?`Draft v${t} · nothing is live`:n>=t?`v${t} is live`:`Draft v${t} · live is v${n}`}function ta(e){return e.canEdit?e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.saved&&!e.dirty&&!e.rebased?`No unsaved changes`:null:`Your role cannot edit`}function na(e){return e.canEdit?e.saved?e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.dirty?`Save the draft first: Publish makes the saved version live`:$i(e.saved)===`live`?`v${e.saved.version} is live`:null:`Save the draft first`:`Your role cannot publish`}function ra(e){return e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.conflict?`Answer the version conflict first`:e.dirty||e.rebased?`Save the draft first`:null}function ia(e){let{version:t,liveVersion:n}=e;return n!==null&&n>=t?`Saved · v${t}. It is live: this store publishes every save.`:n===null?`Draft saved · v${t}. Nothing is live until you publish.`:`Draft saved · v${t}. The live page is unchanged until you publish.`}function aa(e,t){return`Publish ${e} v${t}?`}function oa(e){return e.liveVersion===null?`Nothing is live yet. Visitors will see v${e.version}.`:`Visitors see v${e.liveVersion} now and will see v${e.version}.`}function sa(e){let{collection:t,slug:n,liveVersion:r,preview:i,baseUrl:a}=e,o=t?xe(t,n):null;return!t||o===null?null:i?{kind:`preview`,href:`/api/preview?${new URLSearchParams({collection:t.name,slug:n})}`}:r===null||!a?null:{kind:`live`,href:je(a,o)}}function ca(e){let{seo:t,collection:n,slug:r,locale:i,version:a}=e,[o,s]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{if(!t)return;let e=!0;return s({state:`loading`}),At(n,r,i).then(t=>e&&s({state:`ready`,...t})).catch(()=>e&&s({state:`error`})),()=>{e=!1}},[t,n,r,i,a]),t?o:{state:`off`}}function la(e,t){return`${e} ${t}${e===1?``:`s`}`}function ua(e){return e.filter(e=>e.severity!==`info`).sort((e,t)=>qr[e.severity].order-qr[t.severity].order)}function da({findings:e,version:t}){if(e.state===`off`)return null;if(e.state===`loading`)return(0,N.jsx)(`p`,{role:`status`,className:`editor-publish-findings`,children:`Checking the page's SEO findings…`});if(e.state===`error`)return(0,N.jsx)(`p`,{className:`editor-publish-findings`,children:`The page's SEO findings could not be read. Publishing still works.`});let n=ua(e.findings);if(n.length===0)return(0,N.jsxs)(`p`,{className:`editor-publish-findings`,children:[`No SEO errors or warnings in v`,t,`.`]});let r=n.filter(e=>e.severity===`error`).length,i=new Map(e.readers.map(e=>[e.id,e.name]));return(0,N.jsxs)(`div`,{className:`editor-publish-findings`,children:[(0,N.jsxs)(`p`,{children:[`SEO findings in v`,t,`: `,la(r,`error`),` ·`,` `,la(n.length-r,`warning`),`. They do not stop publishing.`]}),(0,N.jsx)(`ul`,{className:`editor-findings`,children:n.map((e,t)=>(0,N.jsx)(Jr,{finding:e,reader:e.reader?i.get(e.reader)??e.reader:void 0},`${e.code??e.check}-${e.property??``}-${t}`))})]})}function fa(e,t,n){let[r,i]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let r=!0;return ae(e,t,n).then(e=>r&&i({state:`ready`,impact:e})).catch(()=>r&&i({state:`error`})),()=>{r=!1}},[e,t,n]),r}function pa({impact:e}){return(0,N.jsxs)(`ul`,{className:`editor-impact`,children:[e.paths.map(e=>(0,N.jsxs)(`li`,{children:[`the page `,(0,N.jsx)(`code`,{children:e})]},e)),e.lists.map(e=>(0,N.jsxs)(`li`,{children:[`the lists of `,m(e).toLowerCase()]},e)),e.everyPageReading&&(0,N.jsx)(`li`,{children:`every page that reads it, as visitors open them`}),e.cachedEntries!==null&&(0,N.jsxs)(`li`,{children:[e.cachedEntries===1?`1 cached entry`:`${e.cachedEntries} cached entries`,` `,`carrying it`]})]})}function ma({impact:e}){return e.state===`loading`?(0,N.jsx)(`p`,{role:`status`,children:`Reading what publishing refreshes…`}):e.state===`error`?(0,N.jsx)(`p`,{children:`What publishing refreshes could not be read. Publishing still works.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{children:`Publishing refreshes:`}),(0,N.jsx)(pa,{impact:e.impact})]})}function ha(e){let{collection:t,slug:n,locale:r,saved:i,hasPage:a,busy:o,onConfirm:s,onClose:c}=e,l=fa(t,n,r),d=ca({seo:h(u(),`seo`)&&a,collection:t,slug:n,locale:r,version:i.version}),f=(0,M.useRef)(null);return(0,N.jsxs)(w,{title:aa(n,i.version),onClose:o?()=>void 0:c,initialFocus:f,busy:o,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:o?void 0:c,"aria-disabled":o,children:`Cancel`}),(0,N.jsx)(k,{ref:f,variant:`primary`,onClick:o?void 0:s,"aria-disabled":o,children:o?`Publishing…`:`Publish`})]}),children:[(0,N.jsx)(`p`,{children:oa(i)}),(0,N.jsx)(ma,{impact:l}),(0,N.jsx)(da,{findings:d,version:i.version})]})}var ga=`A global has no page of its own. Publishing it marks every page that reads it stale; they refresh as visitors open them.`;function _a(){return(0,N.jsxs)(`p`,{className:`globals-banner`,role:`note`,children:[(0,N.jsx)(Tt,{className:`globals-banner-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{children:ga})]})}function va(e){return`${e===1?`1 cached entry`:`${e} cached entries`} in the site's shared page cache carry it now — pages and data alike, so not a count of pages.`}function ya({impact:e}){let{paths:t,everyPageReading:n,cachedEntries:r}=e;return(0,N.jsxs)(N.Fragment,{children:[t.length>0&&(0,N.jsx)(`ul`,{className:`globals-paths`,"aria-label":`The pages publishing refreshes`,children:t.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsx)(`code`,{children:e})},e))}),n&&(0,N.jsx)(`p`,{className:`globals-rule`,children:`Every page that reads it. krantho knows this rule, not a list of those pages, so none is named here.`}),r!==null&&(0,N.jsx)(F,{children:va(r)})]})}function ba({meta:e}){let t=fa(e.collection,e.slug,e.locale);return(0,N.jsxs)(P,{title:`Pages that read it`,lead:`As far as krantho knows: what publishing it refreshes.`,children:[t.state===`loading`&&(0,N.jsx)(F,{children:`Reading which pages read it…`}),t.state===`error`&&(0,N.jsx)(F,{tone:`error`,children:`Which pages read it could not be read.`}),t.state===`ready`&&(0,N.jsx)(ya,{impact:t.impact})]})}function xa({ws:e}){let{document:t}=e;return(0,N.jsxs)(`div`,{className:`data-mode`,children:[(0,N.jsx)(_a,{}),t?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ba,{meta:t.meta}),(0,N.jsx)(Zi,{ws:e,document:t})]}):(0,N.jsx)(ot,{icon:Wt,title:`Nothing saved yet`,children:`Where it appears reads the saved global and its history. Save it first.`})]})}function Sa(){return(0,N.jsx)(`p`,{className:`live-toolbar side-note`,role:`status`,children:`No element of this page carries the document’s marks: edit it in Structure mode.`})}function Ca({marks:e}){return e.length===0?(0,N.jsx)(Sa,{}):(0,N.jsx)(`p`,{className:`live-toolbar side-note`,children:`Click text on the page to edit it. To edit with the keyboard, use Structure.`})}function wa({frame:e,onReload:t}){let{state:n}=e;return n.kind===`ready`?(0,N.jsx)(Ca,{marks:e.marks}):n.kind===`moved`?(0,N.jsxs)(`div`,{className:`live-toolbar live-moved`,role:`alert`,children:[(0,N.jsxs)(`p`,{children:[`The preview moved to `,(0,N.jsx)(`code`,{children:n.path})]}),(0,N.jsx)(k,{size:`sm`,onClick:t,children:`Back to the page`})]}):(0,N.jsx)(`p`,{className:`live-toolbar side-note`,role:`status`,children:`Loading the draft preview…`})}var Ta=`__lead`,Ea=/^##\s+(.+?)\s*#*\s*$/,Da=/^\s*(`{3,}|~{3,})/;function Oa(e){return Da.exec(e)?.[1]}function G(e){let t=[],n=[],r;for(let i of e.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-diff-DGCTJYJ4.js","assets/rolldown-runtime-COiEfhsA.js","assets/GraphBrowser-Cm5q82MJ.js","assets/save-ClSXW9cb.js","assets/createLucideIcon-BklFHeMd.js","assets/createLucideIcon-DO6kYgVn.css","assets/upload-CaqQJaUr.js","assets/graph-config-CgXhm7XP.js","assets/use-loaded-BNCu0C-c.js","assets/index-d5j-az5g.js","assets/vendor-react-CXaWJ_ii.js","assets/vendor-react-DLioOiRN.css","assets/vendor-router-B4czwg8X.js","assets/auth-CIpilSKF.js","assets/format-C3ZX9yGM.js","assets/api-client-BRi_ki2Y.js","assets/index-Buq8auz3.css","assets/copy-V85khWct.js","assets/corner-down-right-BpwOGRFR.js","assets/findability-BrhtZ2yD.js","assets/layers-0VWe0rKm.js","assets/guards-BFEDbduR.js","assets/graph-config-mZyX0Lqo.css","assets/catalog-offer-CeRRk2Zo.js","assets/circle-check-big-DQjpuxcC.js","assets/circle-x-peGpq98w.js","assets/trash-DzRCm500.js","assets/export-helpers-C_HVpJN9.js","assets/triangle-exclamation-point-ttN5lZI0.js","assets/external-link-Dh7p8Ii6.js","assets/GraphBrowser-U_-D112C.css","assets/live-markdown-editor-DSsCNBWR.js","assets/arrow-down-B5kfR2lG.js","assets/arrow-left-7opbl8fu.js","assets/use-drawer-actions-BeAi2hJS.js","assets/media-model-D4F1Farw.js","assets/action-button-DIrhqMRc.js","assets/use-drawer-actions-DeFJMhBn.css"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{a as t,o as n,s as r}from"./vendor-diff-DGCTJYJ4.js";import{f as i,r as a,s as o,t as s,u as c}from"./vendor-router-B4czwg8X.js";import{a as l,d as u,i as d,o as f,r as p,t as m,u as h}from"./format-C3ZX9yGM.js";import{$ as g,B as _,C as v,D as y,Et as b,F as ee,G as x,H as S,M as te,Q as ne,S as re,Tt as ie,U as ae,V as oe,Y as se,Z as ce,_t as le,at as ue,c as C,ct as de,d as w,et as fe,f as T,ft as pe,g as me,gt as he,j as ge,lt as _e,m as ve,mt as ye,n as be,o as xe,ot as Se,p as Ce,pt as E,r as D,s as O,st as we,t as Te,tt as Ee,u as De,vt as Oe,x as ke,xt as Ae}from"./index-d5j-az5g.js";import{a as je,f as Me}from"./site-model-BXHOxNij.js";import{i as Ne,r as Pe,t as Fe}from"./api-client-BRi_ki2Y.js";import{n as Ie,t as Le}from"./use-loaded-BNCu0C-c.js";import{i as Re,n as k,r as A,t as j}from"./createLucideIcon-BklFHeMd.js";import{a as ze,c as Be,d as Ve,f as He,i as Ue,l as We,p as Ge,s as Ke,u as qe}from"./use-drawer-actions-BeAi2hJS.js";import{t as Je}from"./clock-DoBIVjZO.js";import{n as Ye,r as Xe}from"./vendor-markdown-BeOOOWTF.js";import{t as Ze}from"./rotate-ccw-BgARBEK3.js";import{E as Qe,k as $e,r as et,y as tt}from"./media-model-D4F1Farw.js";import{m as nt}from"./vendor-react-CXaWJ_ii.js";import{i as rt}from"./auth-CIpilSKF.js";import{i as it,t as at}from"./meter-ZOLJ0WhG.js";import{t as ot}from"./empty-state-CeUZocHx.js";import{D as st,a as ct,d as lt,i as ut,l as dt,n as ft,o as pt,r as mt,t as ht,u as gt,x as _t}from"./graph-config-CgXhm7XP.js";import{t as vt}from"./circle-x-peGpq98w.js";import{c as yt,l as bt,s as xt,u as St}from"./fill-job-CKtHKXwV.js";import{t as Ct}from"./action-button-DIrhqMRc.js";import{t as wt}from"./external-link-Dh7p8Ii6.js";import{t as Tt}from"./info-Cxkabti5.js";import{t as Et}from"./triangle-exclamation-point-ttN5lZI0.js";import{t as Dt}from"./pen-line-B524Nue8.js";import{d as Ot,f as kt,l as At,o as jt,s as Mt,t as Nt,u as Pt,y as Ft}from"./api-seo-DeG5gsh6.js";import{t as It}from"./arrow-left-7opbl8fu.js";import{t as Lt}from"./findability-BrhtZ2yD.js";import{n as Rt}from"./use-locale-versions-CcJ_us1I.js";var zt={name:`chevron-up`,size:24,node:[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]};zt.node;var Bt=j(zt),Vt={name:`eye`,size:24,node:[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};Vt.node;var Ht=j(Vt),Ut={name:`file-question-mark`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 9.5a3 2.5 0 016 0c0 2-2 2-3 3.5`,key:`1awbb0`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`file-question`]};Ut.node;var Wt=j(Ut),Gt={name:`lock-open`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]],aliases:[`unlock`]};Gt.node;var Kt=j(Gt),qt={name:`monitor-x`,size:24,node:[[`path`,{d:`m14.5 12.5-5-5`,key:`1jahn5`}],[`path`,{d:`m9.5 12.5 5-5`,key:`1k2t7b`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};qt.node;var Jt=j(qt),Yt={name:`panel-right-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]};Yt.node;var Xt=j(Yt),Zt={name:`panel-right-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]};Zt.node;var Qt=j(Zt),$t={name:`scan-search`,size:24,node:[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`path`,{d:`m16 16-1.9-1.9`,key:`1dq9hf`}]]};$t.node;var en=j($t);async function tn(e,t,n){return Ne(`/content/${e}/${t}/versions${Pe(n)}`)}async function nn(e,t,n,r){let i=await Ne(`/content/${e}/${t}/versions/${n}${Pe(r)}`);return{version:i.meta.version,metadata:i.metadata,contract:i.contract,defaults:i.defaults,repositoryBasis:i.repositoryBasis,fields:i.fields,body:i.body,changedBy:i.meta.changedBy,createdAt:i.meta.createdAt}}async function rn(e,t,n,r){return Ne(`/content/${e}/${t}/restore/${n}${Pe(r)}`,{method:`POST`})}var M=e(r(),1),N=n();function P({title:e,lead:t,aside:n,children:r}){let i=(0,M.useId)();return(0,N.jsxs)(`section`,{className:`data-card`,"aria-labelledby":i,children:[(0,N.jsxs)(`div`,{className:`data-card-head`,children:[(0,N.jsx)(`h2`,{id:i,className:`data-card-title`,children:e}),n&&(0,N.jsx)(`div`,{className:`data-card-aside`,children:n})]}),t&&(0,N.jsx)(`p`,{className:`data-card-lead`,children:t}),r]})}function F({children:e,tone:t}){return(0,N.jsx)(`p`,{className:t===`error`?`data-note data-note--error`:`data-note`,children:e})}function an({children:e}){return(0,N.jsx)(`p`,{role:`alert`,className:`data-note data-note--error`,children:e})}function on(e,t){return{live:e===t.liveVersion,current:e===t.version}}function sn(e,t){return{version:(e[0]?.version??0)+1,metadata:t.metadata,contract:null,defaults:[],repositoryBasis:null,fields:t.fields,body:t.body,changedBy:null,createdAt:new Date().toISOString()}}function cn(e,t){let n=`v${e} is saved again as the newest version; the versions in between stay, and the live page is unchanged until you publish.`;return t?`${n} Your unsaved changes in the form will be lost.`:n}function ln(e,t){return`v${e} could not be restored: ${t}`}function un(e,t){return`v${e} was restored as v${t}, but the page could not be refreshed. Reload it to see the restored version.`}function dn(e){let t=(0,M.useRef)(null);return(0,N.jsx)(w,{title:`Restore v${e.version}?`,onClose:e.onClose,initialFocus:t,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:t,onClick:e.onClose,children:`Cancel`}),(0,N.jsx)(k,{variant:`danger`,onClick:e.onConfirm,children:`Restore`})]}),children:(0,N.jsx)(`p`,{children:cn(e.version,e.unsaved)})})}function fn({n:e,actions:t,restoring:n}){return(0,N.jsxs)(`span`,{className:`data-version-actions`,children:[t.diff&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,"aria-label":`Diff v${e} with the version before`,onClick:t.diff,children:`Diff`}),t.compare&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,"aria-label":`Compare v${e} with your form`,onClick:t.compare,children:`Compare`}),t.restore&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Restore v${e}`,"aria-disabled":n,title:n?`A restore is under way.`:void 0,onClick:n?void 0:t.restore,children:`Restore`})]})}function pn({version:e,props:t,actions:n,restoring:r}){let i=on(e.version,t.saved);return(0,N.jsxs)(`li`,{className:`data-version`,children:[(0,N.jsxs)(`span`,{className:`data-version-number`,children:[`v`,e.version]}),(0,N.jsxs)(`span`,{className:`data-version-meta`,children:[(0,N.jsx)(`time`,{dateTime:e.createdAt,children:p(e.createdAt)}),(0,N.jsx)(`span`,{children:e.changedBy?D(e.changedBy):`Unknown author`})]}),(0,N.jsxs)(`span`,{className:`data-version-chips`,children:[i.live&&(0,N.jsx)(O,{tone:`success`,children:`live`}),i.current&&(0,N.jsx)(O,{tone:`accent`,children:`current`})]}),(0,N.jsx)(fn,{n:e.version,actions:n,restoring:r})]})}var mn=(0,M.lazy)(()=>t(()=>import(`./vendor-diff-DGCTJYJ4.js`).then(e=>e.t),__vite__mapDeps([0,1])));function hn(){let e=document.documentElement.getAttribute(`data-theme`);return e===`dark`?!0:e===`light`?!1:window.matchMedia?.(`(prefers-color-scheme: dark)`).matches??!1}function gn(){let[e,t]=(0,M.useState)(hn);return(0,M.useEffect)(()=>{let e=()=>t(hn()),n=new MutationObserver(e);n.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]});let r=window.matchMedia?.(`(prefers-color-scheme: dark)`);return r?.addEventListener(`change`,e),()=>{n.disconnect(),r?.removeEventListener(`change`,e)}},[]),e}function _n(e,t){return t?`Your form`:`v${e.version}`}function vn({pressed:e,onPress:t,children:n}){return(0,N.jsx)(k,{size:`sm`,variant:e?`secondary`:`ghost`,"aria-pressed":e,onClick:t,children:n})}function yn({view:e,onView:t,onClose:n}){return(0,N.jsxs)(`div`,{className:`data-diff-controls`,children:[(0,N.jsx)(vn,{pressed:e.part===`fields`,onPress:()=>t({...e,part:`fields`}),children:`Fields`}),(0,N.jsx)(vn,{pressed:e.part===`metadata`,onPress:()=>t({...e,part:`metadata`}),children:`Details`}),(0,N.jsx)(vn,{pressed:e.part===`body`,onPress:()=>t({...e,part:`body`}),children:`Body`}),(0,N.jsx)(vn,{pressed:e.split,onPress:()=>t({...e,split:!e.split}),children:`Split`}),(0,N.jsx)(A,{icon:Ee,label:`Close the diff`,size:`sm`,onClick:n})]})}function bn({comparison:e,onClose:t}){let[n,r]=(0,M.useState)({part:`fields`,split:!1}),i=gn(),a=(0,M.useId)(),o=(0,M.useRef)(null),{base:s,compare:c,form:l}=e;(0,M.useEffect)(()=>o.current?.focus(),[e]);let u=e=>n.part===`body`?e.body:JSON.stringify(n.part===`fields`?e.fields:e.metadata,null,2);return(0,N.jsxs)(`section`,{className:`data-diff`,"aria-labelledby":a,children:[(0,N.jsxs)(`div`,{className:`data-diff-head`,children:[(0,N.jsxs)(`h3`,{id:a,ref:o,tabIndex:-1,className:`data-diff-title`,children:[`v`,s.version,` → `,_n(c,l)]}),(0,N.jsx)(yn,{view:n,onView:r,onClose:t})]}),(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(F,{children:`Loading the diff…`}),children:(0,N.jsx)(`div`,{className:`data-diff-body`,children:(0,N.jsx)(mn,{oldValue:u(s),newValue:u(c),splitView:n.split,useDarkTheme:i,leftTitle:`v${s.version}`,rightTitle:_n(c,l)})})})]})}function xn(e){let t=e.seo;return!t||!Array.isArray(t.entities)?null:t}function Sn(e){let t=xn(e)?.entities[0]?.properties??{},n=e.sharing??{},r=e.editorial??{},i=e.publication??{};return{...t,...n.title===void 0?{}:{headline:n.title},...n.description===void 0?{}:{description:n.description},...n.image===void 0?{}:{image:n.image},...n.canonicalUrl===void 0?{}:{url:n.canonicalUrl},...r.byline===void 0?{}:{author:r.byline},...i.date===void 0?{}:{datePublished:i.date}}}var I={title:[`title`,`name`],description:[`meta-description`,`description`,`ingress`,`excerpt`],author:[`author`],datePublished:[`published-date`,`date`],image:[`og-image`,`image`,`hero-image`],canonicalUrl:[`canonical-url`],robotsIndex:[`robots-index`],robotsFollow:[`robots-follow`],ogTitle:[`og-title`],ogDescription:[`og-description`],ogImage:[`og-image`,`image`],ogType:[`og-type`]};function L(e){let t=new Set(e);function n(e){return e.find(e=>t.has(e))??null}return{title:n(I.title),description:n(I.description),author:n(I.author),datePublished:n(I.datePublished),image:n(I.image),canonicalUrl:n(I.canonicalUrl),robotsIndex:n(I.robotsIndex),robotsFollow:n(I.robotsFollow),ogTitle:n(I.ogTitle),ogDescription:n(I.ogDescription),ogImage:n(I.ogImage),ogType:n(I.ogType)}}function Cn(e,t,n){let r=e[t];if(!r)return``;let i=n[r];return typeof i==`string`&&i.length>0?i:``}var wn=new Set([`status`]);function Tn(e){return e.description?.match(/^ref:(\w+)/)?.[1]??null}function En(e,t){return e.format===`date`||e.format===`date-time`?`date`:t.includes(`color`)||t.includes(`colour`)?`color`:e.maxLength!==void 0&&e.maxLength>200||t.includes(`description`)||t.includes(`ingress`)||t.includes(`intro`)?`textarea`:`text`}function R(e,t){return e.description===`media`?`media`:Tn(e)?`reference`:e.enum?`enum`:e.type===`boolean`?`boolean`:e.type===`number`||e.type===`integer`?`number`:e.type===`array`&&e.items?.type===`string`?`tags`:e.type===`string`?En(e,t):`text`}function Dn(e,t){return e.type===`string`?e.format===`uri`||e.format===`url`?`url`:e.format===`email`?`email`:e.format===`date`?`date`:e.format===`date-time`?`datetime-local`:t.includes(`url`)||t.includes(`link`)||t.includes(`href`)?`url`:t.includes(`email`)||t.includes(`e-mail`)?`email`:`text`:`text`}function On(e,t){return e.format===`date-time`?`date and time`:e.format===`date`?`date`:e.format===`uri`||e.format===`url`?`web address`:e.format===`email`?`email`:t.endsWith(`-slug`)||t===`slug`?`URL name`:`text`}var kn={media:`image or file`,reference:`link to a page`,enum:`choice`,color:`color`};function An(e,t){return kn[R(e,t)]||(e.type===`array`?e.items?.type===`string`?`list of text`:`list`:e.type===`string`?On(e,t):e.type===`integer`?`number`:e.type===`boolean`?`yes/no`:e.type===`object`?`group`:e.type??`text`)}function jn(e){return e.description===`media`||Tn(e)!==null?null:e.description?.trim()||null}var Mn={title:`title`,description:`meta description`,author:`author`,datePublished:`date published`,image:`image`,canonicalUrl:`canonical address`,robotsIndex:`search indexing`,robotsFollow:`link following`,ogTitle:`sharing title`,ogDescription:`sharing description`,ogImage:`sharing image`,ogType:`sharing type`},Nn=Object.keys(I);function Pn(e,t,n){let r=e.get(t)??[];r.includes(n)||r.push(n),e.set(t,r)}function Fn(e){let t=new Set(e),n=L(e),r=new Map,i=new Map;for(let e of Nn)for(let a of I[e])t.has(a)&&Pn(n[e]===a?r:i,a,Mn[e]);let a=new Map;for(let t of e){let e=r.get(t),n=i.get(t)?.filter(t=>!e?.includes(t)),o=[...e??[],...n?.length?[`backup for ${n.join(`, `)}`]:[]];o.length>0&&a.set(t,o.join(` · `))}return a}var In=nt(),Ln=20;function Rn(e){let[t,n]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let t=!0;return n({state:`loading`}),Qe({limit:Ln,offset:e*Ln}).then(e=>t&&n({state:`ready`,...e})).catch(e=>t&&n({state:`failed`,message:T(e,`Media could not be read`)})),()=>{t=!1}},[e]),t}function zn({library:e,onSelect:t}){return e.state===`loading`?(0,N.jsx)(`p`,{role:`status`,children:`Loading media…`}):e.state===`failed`?(0,N.jsx)(`p`,{role:`alert`,children:e.message}):e.items.length===0?(0,N.jsx)(`p`,{children:`No media yet. Upload an image above.`}):(0,N.jsx)(`ul`,{className:`media-picker-grid`,"aria-label":`Library`,children:e.items.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`media-picker-file`,onClick:()=>t(e),children:[(0,N.jsx)(`img`,{src:tt(e,`sm`),alt:``}),(0,N.jsx)(`span`,{className:`media-picker-name`,children:e.filename})]})},e.id))})}function Bn({onSelect:e,onUpload:t,onClose:n}){let[r,i]=(0,M.useState)(0),a=Rn(r),{hasRole:o}=rt(),s=a.state===`ready`?Math.ceil(a.total/Ln):0;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Be,{multiple:!1,blocked:o(`editor`)?null:et,onUploaded:([e])=>e&&t(e)}),(0,N.jsx)(zn,{library:a,onSelect:e}),(0,N.jsx)(Ke,{page:r,count:s,onPage:i}),(0,N.jsx)(`div`,{className:`media-picker-actions`,children:(0,N.jsx)(k,{onClick:n,children:`Cancel`})})]})}function Vn(e){let t=(0,M.useRef)(null),n=(0,M.useId)();g(t,!0);function r(t){t.key===`Escape`&&(t.stopPropagation(),e.onClose())}return(0,In.createPortal)((0,N.jsxs)(`div`,{className:`media-picker-layer`,children:[(0,N.jsx)(`div`,{className:`media-picker-scrim`,"aria-hidden":`true`,onClick:e.onClose}),(0,N.jsxs)(`div`,{ref:t,className:`media-picker`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":n,tabIndex:-1,onKeyDown:r,children:[(0,N.jsx)(`h2`,{id:n,className:`media-picker-title`,children:`Choose an image`}),(0,N.jsx)(Bn,{...e})]})]}),document.body)}function Hn(e){let[t,n]=(0,M.useState)({state:e?`loading`:`none`});return(0,M.useEffect)(()=>{if(!e){n({state:`none`});return}let t=!0;return n(t=>t.state===`ready`&&t.item.id===e?t:{state:`loading`}),$e(e).then(e=>t&&n({state:`ready`,item:e})).catch(()=>t&&n({state:`missing`,id:e})),()=>{t=!1}},[e]),[t,e=>n({state:`ready`,item:e})]}function Un({item:e}){let t=e.altText.trim()!==``;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`img`,{className:`editor-media-thumb`,src:tt(e,`sm`),alt:``}),(0,N.jsxs)(`div`,{className:`editor-media-text`,children:[(0,N.jsx)(`span`,{className:`editor-media-name`,children:e.filename}),(0,N.jsxs)(`span`,{className:`editor-media-meta`,children:[e.width!==null&&e.height!==null&&`${e.width} × ${e.height} · `,d(e.size)]}),(0,N.jsxs)(`span`,{className:t?`editor-media-alt`:`editor-media-alt editor-media-alt--missing`,children:[t?(0,N.jsx)(E,{"aria-hidden":`true`}):(0,N.jsx)(pe,{"aria-hidden":`true`}),t?`Alt text set`:`No alt text`]})]})]})}function Wn({selected:e}){if(e.state===`ready`)return(0,N.jsx)(Un,{item:e.item});let t=e.state===`loading`?`Loading…`:e.state===`missing`?`Media ${e.id} was not found`:`No image chosen`;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`editor-media-thumb editor-media-thumb--empty`,"aria-hidden":`true`,children:(0,N.jsx)(qe,{})}),(0,N.jsx)(`span`,{className:`editor-media-text editor-media-meta`,children:t})]})}function Gn({id:e,current:t,describedBy:n,changeRef:r,onPick:i,onClear:a}){return(0,N.jsxs)(`div`,{className:`editor-media-actions`,children:[(0,N.jsx)(k,{id:e,ref:r,size:`sm`,"aria-describedby":n,onClick:i,children:t?`Change`:`Choose image`}),t&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>{a(),r.current?.focus()},children:`Clear`})]})}function Kn(e,t){let n=[e?`Required`:null,t?`not valid`:null].filter(Boolean);return n.length>0?n.join(`, `):null}function qn(e){let{id:t,labelId:n,name:r,value:i,onChange:a}=e,o=typeof i==`string`?i:``,[s,c]=Hn(o),[l,u]=(0,M.useState)(!1),d=(0,M.useRef)(null),f=Kn(e.required,e.invalid),p=[f?`${t}-state`:null,e.describedBy].filter(Boolean).join(` `)||void 0;function m(e){c(e),a(r,e.id),u(!1)}return(0,N.jsxs)(`fieldset`,{className:`editor-media`,"aria-labelledby":n,"aria-describedby":p,children:[f&&(0,N.jsx)(`span`,{id:`${t}-state`,className:`visually-hidden`,children:f}),(0,N.jsx)(Wn,{selected:s}),(0,N.jsx)(Gn,{id:t,current:o,describedBy:p,changeRef:d,onPick:()=>u(!0),onClear:()=>a(r,``)}),l&&(0,N.jsx)(Vn,{onSelect:m,onUpload:m,onClose:()=>u(!1)})]})}function Jn(e){let[t,n]=(0,M.useState)(null);return(0,M.useEffect)(()=>{let t=!0;return _(e).then(({items:e})=>{t&&n(e.map(({meta:e,fields:t})=>({slug:e.slug,label:typeof t.title==`string`?t.title:e.slug})))}).catch(()=>{t&&n([])}),()=>{t=!1}},[e]),t}function Yn(e){let{id:t,name:n,property:r,value:i,describedBy:a,invalid:o,required:s,onChange:c}=e,l=Tn(r)??``,u=Jn(l),d=typeof i==`string`?i:``,f=d!==``&&u!==null&&!u.some(e=>e.slug===d);return(0,N.jsxs)(`select`,{id:t,name:n,className:`editor-control editor-control--short`,value:d,"aria-describedby":a,"aria-invalid":o||void 0,"aria-required":s||void 0,"aria-busy":u===null||void 0,onChange:e=>c(n,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:u===null?`Loading…`:`Choose from ${l}…`}),f&&(0,N.jsx)(`option`,{value:d,children:d}),u?.map(e=>(0,N.jsx)(`option`,{value:e.slug,children:e.label},e.slug))]})}function Xn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Zn({tags:e,onRemove:t}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`editor-tags-list`,children:e.map((e,n)=>(0,N.jsxs)(`li`,{className:`editor-tag`,children:[e,(0,N.jsx)(`button`,{type:`button`,className:`editor-tag-remove`,"aria-label":`Remove ${e}`,onClick:()=>t(n),children:(0,N.jsx)(Ee,{"aria-hidden":`true`})})]},`${e}-${n}`))})}function Qn(e){let{id:t,name:n,value:r,describedBy:i,invalid:a,required:o,onChange:s}=e,[c,l]=(0,M.useState)(``),u=(0,M.useRef)(null),d=Xn(r);function f(e){e.key===`Enter`&&c.trim()&&(e.preventDefault(),s(n,[...d,c.trim()]),l(``))}function p(e){s(n,d.filter((t,n)=>n!==e)),u.current?.focus()}return(0,N.jsxs)(`div`,{className:`editor-tags`,children:[(0,N.jsx)(Zn,{tags:d,onRemove:p}),(0,N.jsx)(`input`,{ref:u,id:t,name:n,type:`text`,className:`editor-control`,placeholder:`Type and press Enter`,value:c,"aria-describedby":i,"aria-invalid":a||void 0,"aria-required":o||void 0,onChange:e=>l(e.target.value),onKeyDown:f})]})}function $n(e){if(typeof e!=`string`||e===``)return``;let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=e=>String(e).padStart(2,`0`);return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`}T${n(t.getHours())}:${n(t.getMinutes())}`}function er(e){if(e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toISOString().slice(0,19)}Z`}function z(e){return typeof e==`string`?e:``}function B(e){return{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}}function tr(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsx)(`input`,{...B(e),type:Dn(n,t),className:`editor-control`,value:z(r),maxLength:n.maxLength,pattern:n.pattern,onChange:e=>i(t,e.target.value)})}function nr(e){let{id:t,name:n,property:r,value:i,onChange:a}=e,o=z(i).length,s=r.maxLength!==void 0,c=`${t}-count`,l=[e.describedBy,s?c:null].filter(Boolean).join(` `);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`textarea`,{...B(e),"aria-describedby":l||void 0,className:`editor-control editor-control--area`,value:z(i),rows:3,maxLength:r.maxLength,onChange:e=>a(n,e.target.value)}),s&&(0,N.jsxs)(`span`,{id:c,className:`editor-field-counter`,children:[o,` of `,r.maxLength,` characters`]})]})}function rr(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsx)(`input`,{...B(e),type:`number`,className:`editor-control editor-control--short`,value:typeof r==`number`&&!Number.isNaN(r)?r:``,min:n.minimum,max:n.maximum,onChange:e=>i(t,e.target.value===``?void 0:e.target.valueAsNumber)})}function ir(e){let{name:t,value:n,onChange:r}=e;return(0,N.jsx)(`input`,{...B(e),type:`checkbox`,className:`editor-checkbox`,checked:n===!0,onChange:e=>r(t,e.target.checked)})}function ar(e){let{name:t,property:n,value:r,onChange:i}=e;return(0,N.jsxs)(`select`,{...B(e),className:`editor-control editor-control--short`,value:z(r),onChange:e=>i(t,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Choose…`}),n.enum?.map(e=>(0,N.jsx)(`option`,{value:e,children:e},e))]})}function or(e){let{name:t,value:n,onChange:r}=e;return(0,N.jsxs)(`span`,{className:`editor-color`,children:[(0,N.jsx)(`input`,{type:`color`,className:`editor-color-swatch`,"aria-label":`${t}, colour picker`,value:z(n),onChange:e=>r(t,e.target.value)}),(0,N.jsx)(`input`,{...B(e),type:`text`,className:`editor-control editor-control--short`,value:z(n),placeholder:`#rrggbb`,onChange:e=>r(t,e.target.value)})]})}function sr(e){let{name:t,property:n,value:r,onChange:i}=e,a=Dn(n,t),o=a===`datetime-local`,s=(0,N.jsx)(`input`,{...B(e),type:a,className:`editor-control editor-control--short`,value:o?$n(r):z(r).slice(0,10),onChange:e=>{let n=e.target.value;i(t,o?er(n):n)}});return o?(0,N.jsxs)(`span`,{className:`editor-timestamp`,children:[s,(0,N.jsx)(`small`,{className:`editor-timestamp-shown`,children:l(r)})]}):s}var cr={media:qn,reference:Yn,enum:ar,boolean:ir,number:rr,tags:Qn,textarea:nr,color:or,date:sr,text:tr};function V(e,t){let n=e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/[-_]/g,` `);return t.title??n.charAt(0).toUpperCase()+n.slice(1)}function lr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function H(e){let{property:t,value:n,onValue:r}=e,i=V(e.name,t),a=t.anyOf??t.oneOf;if(a?.some(e=>e.type===`null`)){let o=a.find(e=>e.type!==`null`)??{};return(0,N.jsxs)(`div`,{className:`metadata-property`,children:[n===null?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`p`,{children:[i,`: No value`]}),(0,N.jsxs)(k,{size:`sm`,onClick:()=>r(o.default??(o.type===`object`?{}:o.type===`array`?[]:o.type===`boolean`?!1:o.type===`number`?0:``)),children:[`Set `,i.toLowerCase()]})]}):(0,N.jsx)(H,{...e,property:{...t,...o,anyOf:void 0,oneOf:void 0}}),n!==null&&(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>r(null),children:`Use no value`})]})}if(t.type===`object`)return(0,N.jsxs)(`fieldset`,{className:`metadata-object`,children:[(0,N.jsx)(`legend`,{children:i}),(0,N.jsx)(dr,{property:t,values:lr(n),path:e.path,errors:e.errors,sources:e.sources,onValues:r})]});if(t.type===`array`&&t.items?.type!==`string`){let a=Array.isArray(n)?n:[];return(0,N.jsxs)(`fieldset`,{className:`metadata-array`,children:[(0,N.jsx)(`legend`,{children:i}),a.map((n,o)=>(0,N.jsxs)(`div`,{className:`metadata-array-item`,children:[(0,N.jsx)(H,{...e,name:`${i} ${o+1}`,path:`${e.path}.${o}`,property:t.items??{},value:n,onValue:e=>r(a.map((t,n)=>n===o?e:t))}),(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>r(a.filter((e,t)=>t!==o)),children:`Remove`})]},`${e.path}.${o}`)),(0,N.jsx)(k,{variant:`secondary`,size:`sm`,onClick:()=>r([...a,t.items?.type===`object`?{}:``]),children:`Add item`})]})}return(0,N.jsx)(ur,{...e})}function ur(e){let t=(0,M.useId)(),n=V(e.name,e.property),r=jn(e.property),i=e.errors[e.path]??(e.path.startsWith(`fields.`)?e.errors[e.path.slice(7)]:void 0),a=cr[R(e.property,e.name)],o=[r?`${t}-help`:``,i?`${t}-error`:``].filter(Boolean).join(` `)||void 0;return(0,N.jsxs)(`div`,{className:`metadata-property`,children:[(0,N.jsxs)(`div`,{className:`metadata-label-row`,children:[(0,N.jsxs)(`label`,{id:`${t}-label`,htmlFor:t,children:[n,e.required&&(0,N.jsx)(`span`,{"aria-hidden":`true`,children:` *`})]}),!e.required&&e.value!==void 0&&e.property.type!==`boolean`&&(0,N.jsx)(A,{icon:Ze,size:`sm`,label:`Reset ${n.toLowerCase()}`,onClick:()=>e.onValue(void 0)})]}),e.property.type===`boolean`&&!e.required?(0,N.jsxs)(`select`,{id:t,className:`editor-control`,"aria-describedby":o,"aria-invalid":!!i||void 0,value:e.value===void 0?``:String(e.value),onChange:t=>e.onValue(t.target.value===``?void 0:t.target.value===`true`),children:[(0,N.jsx)(`option`,{value:``,children:`Use default`}),(0,N.jsx)(`option`,{value:`true`,children:`Yes`}),(0,N.jsx)(`option`,{value:`false`,children:`No`})]}):(0,N.jsx)(a,{id:t,labelId:`${t}-label`,name:e.path,property:e.property,value:e.value,required:e.required,describedBy:o,invalid:!!i,onChange:(t,n)=>e.onValue(n)}),e.sources?.[e.path]&&(0,N.jsxs)(`p`,{className:`metadata-source`,children:[`Copied from `,e.sources[e.path]]}),r&&(0,N.jsx)(`p`,{id:`${t}-help`,className:`metadata-help`,children:r}),i&&(0,N.jsx)(`p`,{id:`${t}-error`,role:`alert`,children:i})]})}function dr(e){let t=new Set(e.property.required??[]),n=e.property.properties??{},r=e.property.additionalProperties,i=r!==void 0&&r!==!1;return(0,N.jsxs)(N.Fragment,{children:[Object.entries(n).filter(([t])=>e.path!==`fields`||!wn.has(t)).map(([n,r])=>(0,N.jsx)(H,{name:n,path:`${e.path}.${n}`,property:r,value:e.values[n],required:t.has(n),errors:e.errors,sources:e.sources,onValue:t=>{let r={...e.values};t===void 0?delete r[n]:r[n]=t,e.onValues(r)}},n)),i&&(0,N.jsx)(pr,{...e,properties:n,additional:typeof r==`object`?r:{}}),!i&&Object.entries(e.values).filter(([e])=>!Object.hasOwn(n,e)).map(([t,n])=>(0,N.jsxs)(`div`,{className:`metadata-property`,children:[(0,N.jsxs)(`p`,{children:[V(t,{}),`:`,` `,typeof n==`string`?n:JSON.stringify(n)]}),(0,N.jsx)(`p`,{children:`This property is outside the current content form. Review it before removing it.`}),(0,N.jsxs)(k,{variant:`ghost`,size:`sm`,onClick:()=>{let n={...e.values};delete n[t],e.onValues(n)},children:[`Remove `,V(t,{})]})]},t))]})}function fr(e){return Array.isArray(e)?{type:`array`,items:fr(e[0])}:typeof e==`object`&&e?{type:`object`,additionalProperties:!0}:{type:typeof e==`boolean`?`boolean`:typeof e==`number`?`number`:`string`}}function pr(e){let[t,n]=(0,M.useState)(``),r=(0,M.useId)();return(0,N.jsxs)(`div`,{className:`metadata-record`,children:[Object.entries(e.values).filter(([t])=>!Object.hasOwn(e.properties,t)).map(([t,n])=>(0,N.jsx)(H,{name:t,path:`${e.path}.${t}`,value:n,property:e.additional.type?e.additional:fr(n),required:!1,errors:e.errors,sources:e.sources,onValue:n=>{let r={...e.values};n===void 0?delete r[t]:r[t]=n,e.onValues(r)}},t)),(0,N.jsx)(`label`,{htmlFor:r,children:`New property name`}),(0,N.jsx)(`input`,{id:r,value:t,onChange:e=>n(e.target.value)}),(0,N.jsx)(k,{size:`sm`,disabled:!t.trim()||Object.hasOwn(e.values,t.trim())||[`__proto__`,`constructor`,`prototype`].includes(t.trim()),onClick:()=>{e.onValues({...e.values,[t.trim()]:e.additional.default??``}),n(``)},children:`Add property`})]})}function mr(e){let t=L(Object.keys(e.fields)),n={title:Cn(t,`title`,e.fields),description:Cn(t,`description`,e.fields)};function r(t,n){let r={...e.values};n===void 0?delete r[t]:r[t]=n,e.onValues(r)}function i(t,n){return(0,N.jsx)(H,{name:t,path:`${e.path}.${t}`,property:{...e.schema.properties?.[t],title:n},value:e.values[t],required:!1,errors:e.errors,sources:e.sources,onValue:e=>r(t,e)})}return(0,N.jsxs)(`div`,{className:`metadata-sharing`,children:[[`title`,`description`].map(t=>(0,N.jsxs)(`div`,{className:`metadata-search-value`,children:[e.values[t]===void 0?(0,N.jsxs)(`div`,{className:`metadata-label-row`,children:[(0,N.jsxs)(`span`,{children:[`Search `,t,` `,(0,N.jsxs)(`span`,{className:`metadata-default-label`,children:[`uses the page `,t]})]}),!e.readOnly&&(0,N.jsx)(k,{className:`metadata-change`,size:`sm`,variant:`secondary`,"aria-label":`Write a different search ${t}`,onClick:()=>{let e=n[t];r(t,typeof e==`string`?e:``)},children:`Write your own`})]}):i(t,`Search ${t}`),e.below?.[t]]},t)),i(`image`,`Sharing image`),e.below?.image,(0,N.jsxs)(`details`,{className:`metadata-advanced`,children:[(0,N.jsx)(`summary`,{children:`Advanced search settings`}),i(`canonicalUrl`,`Canonical URL`),i(`index`,`Show in search results`),i(`follow`,`Allow search engines to follow links`)]})]})}function hr(e){let{meta:t}=e,n=t.changedBy?`saved by ${D(t.changedBy)}, ${it(t.createdAt)}`:`saved ${it(t.createdAt)}`;return(0,N.jsxs)(`p`,{className:`metadata-system`,title:l(t.createdAt),children:[(0,N.jsx)(`span`,{className:`visually-hidden`,children:`System: `}),[ge[te(t)],`v${t.version}`,t.locale.toUpperCase(),n].join(` · `)]})}function gr(e,t){return Object.fromEntries(e.flatMap(e=>e.paths.flatMap(n=>{let r=n.slice(1).split(`/`).map(e=>e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`)),i=t;for(let e of r.slice(1)){if(!i||typeof i!=`object`)return[];i=i[e]}return JSON.stringify(i)===JSON.stringify(e.values[n])?[[r.join(`.`),`${e.collection}/${e.slug} · v${e.version}`]]:[]})))}var _r=`krantho/sharing`;function vr(e,t){return e===`all`||t.id===_r==(e===`sharing`)}function yr(e){let{group:t,slot:n}=e,r=(0,N.jsxs)(N.Fragment,{children:[t.label,(0,N.jsx)(`code`,{className:`metadata-key`,title:`The name your page reads it by`,children:n}),t.required&&(0,N.jsx)(`span`,{className:`metadata-help`,children:` · Required`})]});return e.bare?(0,N.jsx)(`div`,{className:`metadata-group metadata-group--bare`,children:e.children}):e.sharing?(0,N.jsxs)(`details`,{className:`metadata-group`,open:t.required||e.invalid,children:[(0,N.jsx)(`summary`,{children:t.label}),e.children]}):(0,N.jsxs)(`section`,{className:`metadata-group`,"aria-label":t.label,children:[(0,N.jsx)(`h4`,{className:`metadata-group-title`,children:r}),e.children]})}function U(e){let t=e.scope??`all`,n=Object.entries(e.contract.metadata).filter(([,e])=>vr(t,e)),r=Object.entries(e.metadata).filter(([n])=>t!==`sharing`&&!Object.hasOwn(e.contract.metadata,n));if(n.length===0&&r.length===0)return null;let i=gr(e.defaults??[],e.metadata),a=t===`sharing`?`Search and sharing`:`Metadata`;return(0,N.jsxs)(`section`,{className:`editor-metadata`,"aria-label":a,children:[(0,N.jsx)(`h3`,{children:a}),(0,N.jsx)(`p`,{className:`metadata-intro`,children:t===`sharing`?`How this page appears in search results and when it is shared.`:`Saved with the page, and published with it.`}),(0,N.jsxs)(`fieldset`,{disabled:e.readOnly,className:`metadata-groups`,children:[n.map(([n,r])=>{let a=e.metadata[n],o=a!==void 0||r.required,s=t=>e.onMetadata({...e.metadata,[n]:t});return n===`seo`&&r.schema.properties?.entities?(0,N.jsxs)(`div`,{className:`metadata-group metadata-graph-link`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`strong`,{children:`Structured data`}),(0,N.jsx)(`p`,{className:`metadata-help`,children:`Manage how this page is described to search engines.`})]}),e.onOpenData?(0,N.jsx)(k,{size:`sm`,variant:`secondary`,onClick:e.onOpenData,children:`Open graph editor`}):(0,N.jsx)(`p`,{className:`metadata-help`,children:`Available in Data view.`})]},n):!o&&r.id!==_r?(0,N.jsxs)(`div`,{className:`metadata-group metadata-group--absent`,children:[(0,N.jsx)(`strong`,{children:r.label}),!e.readOnly&&(0,N.jsx)(k,{variant:`secondary`,size:`sm`,onClick:()=>s({}),children:`Add`})]},n):(0,N.jsxs)(yr,{sharing:r.id===_r,bare:t===`sharing`,group:r,slot:n,invalid:Object.keys(e.errors).some(e=>e.startsWith(`metadata.${n}`)),children:[r.id===_r?(0,N.jsx)(mr,{below:e.checks,fields:e.fields??{},values:a??{},schema:r.schema,path:`metadata.${n}`,errors:e.errors,sources:i,readOnly:e.readOnly,onValues:s}):(0,N.jsx)(dr,{property:r.schema,values:a??{},path:`metadata.${n}`,errors:e.errors,sources:i,onValues:s}),o&&!r.required&&!e.readOnly&&(0,N.jsxs)(k,{className:`metadata-remove-group`,variant:`ghost`,size:`sm`,onClick:()=>{let t={...e.metadata};delete t[n],e.onMetadata(t)},children:[`Remove `,r.label.toLowerCase()]}),!e.readOnly&&e.groupActions?.(n),e.errors[`metadata.${n}`]&&(0,N.jsx)(`p`,{role:`alert`,children:e.errors[`metadata.${n}`]})]},n)}),r.map(([t,n])=>(0,N.jsxs)(`details`,{className:`metadata-group`,children:[(0,N.jsx)(`summary`,{children:V(t,{})}),(0,N.jsx)(`p`,{children:`These details are outside the current content form. Review them before removing them from this draft.`}),(0,N.jsx)(`dl`,{children:Object.entries(n).map(([e,t])=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{children:V(e,{})}),(0,N.jsx)(`dd`,{children:typeof t==`string`?t:JSON.stringify(t)})]},e))}),(0,N.jsx)(k,{variant:`ghost`,size:`sm`,onClick:()=>{let n={...e.metadata};delete n[t],e.onMetadata(n)},children:`Remove these details`})]},t))]}),e.system&&t!==`sharing`&&(0,N.jsx)(hr,{meta:e.system})]})}function br(e){let{collection:t,slug:n,locale:r,version:i}=e,a=(0,M.useCallback)(async()=>{let e=await nn(t,n,i,r),a=Xe.sanitize(await Ye.parse(e.body));return{...e,html:a}},[t,n,r,i]),{loaded:o,reload:s}=Le(a,`This snapshot could not be read`);return(0,N.jsxs)(w,{title:`Snapshot v${i}`,onClose:e.onClose,actions:(0,N.jsx)(k,{onClick:e.onClose,children:`Close`}),children:[(0,N.jsx)(`p`,{className:`snapshot-preview-note`,children:`Read-only snapshot. Your draft is unchanged.`}),o.state===`loading`&&(0,N.jsx)(`p`,{role:`status`,children:`Reading the snapshot…`}),o.state===`error`&&(0,N.jsxs)(`div`,{role:`alert`,children:[(0,N.jsx)(`p`,{children:o.message}),(0,N.jsx)(k,{onClick:s,children:`Retry`})]}),o.state===`ready`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`time`,{dateTime:o.data.createdAt,children:p(o.data.createdAt)}),(0,N.jsxs)(`details`,{className:`snapshot-fields`,children:[(0,N.jsx)(`summary`,{children:`Fields`}),(0,N.jsx)(`pre`,{children:JSON.stringify(o.data.fields,null,2)})]}),o.data.contract&&(0,N.jsx)(U,{contract:o.data.contract,metadata:o.data.metadata,fields:o.data.fields,defaults:o.data.defaults,readOnly:!0,errors:{},onMetadata:()=>{}}),typeof o.data.fields.title==`string`&&(0,N.jsx)(`h3`,{children:o.data.fields.title}),(0,N.jsx)(`article`,{className:`snapshot-body`,dangerouslySetInnerHTML:{__html:o.data.html}})]})]})}function xr(e){let[t,n]=(0,M.useState)(!1),r=(0,M.useRef)(null),i=(0,M.useRef)(null),a=(0,M.useId)();return(0,M.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.target;t?.closest(`.ui-modal-layer`)||r.current?.contains(t)||n(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[t]),(0,N.jsxs)(`fieldset`,{ref:r,className:`snapshot-disclosure`,onKeyDown:e=>{e.key===`Escape`&&t&&(e.stopPropagation(),n(!1),i.current?.focus())},children:[(0,N.jsxs)(k,{ref:i,size:`sm`,variant:`ghost`,"aria-label":`Snapshot details`,"aria-expanded":t,"aria-controls":a,onClick:()=>n(!t),children:[`v`,e.entry.version,` · Details`,t?(0,N.jsx)(Bt,{size:14,"aria-hidden":`true`}):(0,N.jsx)(Ge,{size:14,"aria-hidden":`true`})]}),t&&(0,N.jsxs)(`section`,{id:a,className:`snapshot-popover`,"aria-label":`Selected snapshot`,children:[(0,N.jsxs)(`strong`,{children:[`Snapshot v`,e.entry.version]}),(0,N.jsx)(`time`,{dateTime:e.entry.createdAt,children:p(e.entry.createdAt)}),(0,N.jsx)(`span`,{children:e.entry.changedBy?D(e.entry.changedBy):`Unknown author`}),(0,N.jsxs)(`div`,{className:`snapshot-actions`,children:[(0,N.jsx)(k,{size:`sm`,variant:`ghost`,icon:Ht,onClick:e.onPreview,children:`Preview snapshot`}),e.actions]})]})]})}function Sr(e){let[t,n]=(0,M.useState)(null),r=t?.saved===e.saved.version?t.version:e.saved.version,[i,a]=(0,M.useState)(null),[o,s]=(0,M.useState)(null),c=o??e.versions.length>1,l=(0,M.useRef)(null),u=(0,M.useId)(),d=Math.max(0,e.versions.findIndex(e=>e.version===r)),f=e.versions[d],m=[...e.versions].reverse(),h=m.length-1-d,g=(0,M.useRef)(!1),_=()=>{let e=l.current,t=e?.querySelector(`[aria-pressed="true"]`);if(!e||!t)return;let n=t.offsetLeft-(e.clientWidth-t.offsetWidth)/2;e.scrollTo?.({left:n,behavior:`instant`})};(0,M.useEffect)(()=>{c&&!g.current&&_()},[h,c]);let v=t=>{let r=m[t];r&&n({saved:e.saved.version,version:r.version})};return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`snapshot-heading`,children:[(0,N.jsxs)(k,{size:`sm`,variant:`ghost`,icon:Je,"aria-label":c?`Collapse snapshot timeline`:`Expand snapshot timeline`,"aria-expanded":c,"aria-controls":u,onClick:()=>s(!c),children:[`Snapshots `,(0,N.jsx)(`small`,{children:e.versions.length}),c?(0,N.jsx)(Bt,{size:14,"aria-hidden":`true`}):(0,N.jsx)(Ge,{size:14,"aria-hidden":`true`})]}),e.unsaved&&(0,N.jsx)(O,{tone:`accent`,children:`Unsaved changes`}),f&&(0,N.jsx)(xr,{entry:f,actions:e.actions(d),onPreview:()=>a(f.version)})]}),c&&(0,N.jsxs)(`div`,{id:u,className:`snapshot-navigation`,children:[(0,N.jsx)(A,{icon:He,label:`Older snapshot`,size:`sm`,disabled:h<=0,onClick:()=>v(h-1)}),(0,N.jsx)(`div`,{ref:l,className:`snapshot-viewport`,children:(0,N.jsxs)(`div`,{className:`snapshot-ruler`,style:{minWidth:`${Math.max(1,m.length)*104}px`,"--snapshot-edge":`${50/Math.max(1,m.length)}%`},children:[(0,N.jsx)(`ol`,{className:`snapshot-markers`,"aria-label":`Saved snapshots`,children:m.map((t,n)=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`snapshot-stop`,"aria-label":`Select snapshot v${t.version}`,"aria-pressed":n===h,title:p(t.createdAt),onClick:()=>v(n),children:[(0,N.jsxs)(`span`,{className:`snapshot-label`,children:[`v`,t.version,t.version===e.saved.version&&(0,N.jsx)(`span`,{children:`Current`}),t.version===e.saved.liveVersion&&(0,N.jsx)(`span`,{className:`snapshot-live`,children:`Live`})]}),(0,N.jsx)(`span`,{className:`snapshot-tick`,"aria-hidden":`true`}),(0,N.jsx)(`time`,{dateTime:t.createdAt,children:new Date(t.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`})})]})},t.version))}),m.length>1&&(0,N.jsx)(`input`,{className:`snapshot-slider`,onPointerDown:()=>{g.current=!0},onPointerUp:()=>{g.current=!1,_()},onPointerCancel:()=>{g.current=!1,_()},type:`range`,"aria-label":`Snapshot selection`,min:0,max:m.length-1,step:1,value:h,"aria-valuetext":`v${f?.version}: ${p(f?.createdAt??``)}`,onChange:e=>v(Number(e.target.value))}),m.length===1&&(0,N.jsx)(`span`,{className:`snapshot-single`,"aria-hidden":`true`})]})}),(0,N.jsx)(A,{icon:ye,label:`Newer snapshot`,size:`sm`,disabled:h>=m.length-1,onClick:()=>v(h+1)})]}),i!==null&&(0,N.jsx)(br,{collection:e.collection,slug:e.slug,locale:e.locale,version:i,onClose:()=>a(null)})]})}function Cr(e){let{collection:t,slug:n,locale:r}=e,i=(0,M.useCallback)(()=>tn(t,n,r).then(e=>e.versions),[t,n,r]),{loaded:a,reload:o}=Le(i,`The history could not be read`),s=(0,M.useRef)(e.saved.version);return(0,M.useEffect)(()=>{s.current!==e.saved.version&&(s.current=e.saved.version,o())},[e.saved.version,o]),{loaded:a,reload:o}}function wr(e){let[t,n]=(0,M.useState)(null),r=(0,M.useRef)(null),i=(0,M.useRef)(0);return{comparison:t,show:t=>{r.current=document.activeElement instanceof HTMLElement?document.activeElement:null,e(null);let a=++i.current;t().then(e=>{a===i.current&&n(e)}).catch(t=>{a===i.current&&e(T(t,`The versions to compare could not be read`))})},close:()=>{n(null),r.current?.focus()}}}function Tr(e,t,n,r){let i=t=>nn(e.collection,e.slug,t,e.locale);return a=>{let o=t[a];if(!o)return{diff:null,compare:null,restore:null};let s=t[a+1],c=async e=>{let[t,n]=await Promise.all([i(e),i(o.version)]);return{base:t,compare:n,form:!1}},l=async()=>({base:await i(o.version),compare:sn(t,e.draft),form:!0});return{diff:s?()=>n(()=>c(s.version)):null,compare:e.unsaved||a>0?()=>n(l):null,restore:e.canRestore&&a>0?()=>r(o.version):null}}}function Er(e,t){let[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(!1),o=fe(),s=async n=>{t(null);let r;try{r=await rn(e.collection,e.slug,n,e.locale)}catch(e){t(ln(n,T(e,`the store refused it`)));return}try{await e.onRestored()}catch{t(un(n,r.version));return}o({text:`v${n} restored as v${r.version}. The live page is unchanged until you publish.`})};return{asked:n,restoring:i,ask:r,cancel:()=>r(null),confirm:()=>{n===null||i||(r(null),a(!0),s(n).finally(()=>a(!1)))}}}function Dr(e){let[t,n]=(0,M.useState)(null),r=wr(n),[i,a]=(0,M.useState)(null);async function o(t){try{let n=await nn(e.collection,e.slug,t,e.locale);e.onPrepare({fields:n.fields,metadata:n.metadata,body:n.body,defaults:n.defaults}),a(null)}catch(e){n(T(e,`The snapshot could not be read`))}}let s=Er(e,n),c=Tr(e,e.versions,r.show,s.ask);return(0,N.jsxs)(N.Fragment,{children:[t&&(0,N.jsx)(an,{children:t}),e.canRestore&&e.versions.length>1&&(0,N.jsxs)(`details`,{className:`data-disclosure`,children:[(0,N.jsx)(`summary`,{children:`Prepare an earlier snapshot as a draft`}),(0,N.jsx)(`p`,{children:`Bring its values into the current content form for review and correction. Nothing is saved or published.`}),e.versions.slice(1).map(e=>(0,N.jsxs)(k,{size:`sm`,onClick:()=>a(e.version),children:[`Prepare v`,e.version]},e.version))]}),i!==null&&(0,N.jsx)(w,{title:`Prepare v${i} as a draft?`,onClose:()=>a(null),actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:()=>a(null),children:`Cancel`}),(0,N.jsx)(k,{onClick:()=>{o(i)},children:`Prepare draft`})]}),children:(0,N.jsxs)(`p`,{children:[`Replace the current form with this snapshot’s values. Review them against today’s content form before saving.`,e.unsaved?` Your unsaved form changes will be replaced.`:``]})}),e.timeline?(0,N.jsx)(Sr,{...e,actions:t=>(0,N.jsx)(fn,{n:e.versions[t]?.version??0,actions:c(t),restoring:s.restoring})}):(0,N.jsx)(`ol`,{className:`data-versions`,"aria-label":`Versions`,children:e.versions.map((t,n)=>(0,N.jsx)(pn,{version:t,props:e,actions:c(n),restoring:s.restoring},t.version))}),r.comparison&&(0,N.jsx)(bn,{comparison:r.comparison,onClose:r.close}),s.asked!==null&&(0,N.jsx)(dn,{version:s.asked,unsaved:e.unsaved,onConfirm:s.confirm,onClose:s.cancel})]})}function Or(e){let{loaded:t,reload:n}=Cr(e),r=(0,N.jsxs)(N.Fragment,{children:[t.state===`loading`&&(0,N.jsx)(F,{children:`Reading the history…`}),t.state===`error`&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(F,{tone:`error`,children:t.message}),(0,N.jsx)(k,{size:`sm`,onClick:n,children:`Retry history`})]}),t.state===`ready`&&(t.data.length===0?(0,N.jsx)(F,{children:`No version history yet.`}):(0,N.jsx)(Dr,{...e,versions:t.data}))]});return e.timeline?(0,N.jsx)(`section`,{className:`snapshot-timeline`,"aria-label":`Article snapshots`,children:r}):(0,N.jsx)(P,{title:`History`,lead:`The ${e.locale.toUpperCase()} version's saved versions, newest first. Restore saves an earlier one again as a new version.`,children:r})}var kr=0,Ar=new Set;function jr(e){return Ar.add(e),()=>Ar.delete(e)}function Mr(){return kr}function Nr(){kr+=1;for(let e of Ar)e()}function Pr(){return(0,M.useSyncExternalStore)(jr,Mr,Mr)}function Fr(e,t,n){let r=t.items.find(e=>e.collection===n.collection&&e.slug===n.slug);return r?r.status===`complete`?{step:e,state:`generated`,text:r.result??`Filled`}:r.status===`error`?{step:e,state:`error`,text:r.error??`Failed`}:{step:e,state:`skipped`,text:r.result??`Nothing missing`}:{step:e,state:`skipped`,text:`Not part of the job`}}function Ir(e){return e.saved?!e.canEdit||!e.admin?`Enrichment is run by an admin.`:e.lockedBy?`${D(e.lockedBy)} is editing: enrichment waits until they finish.`:e.defaultLocaleName===null?`The site's locales could not be read: enrichment works on the default locale's version only.`:e.defaultLocale?e.dirty?`Save or discard your changes first: enrichment saves a new version of the document.`:null:`Enrichment reads and writes the ${e.defaultLocaleName.toUpperCase()} version: open it to enrich.`:`Save the page first: enrichment works on saved documents.`}function Lr(e){return e.some(e=>e.step===`meta-descriptions`&&e.state===`generated`)}async function Rr(e,t,n){let r=await bt(e,{scope:`item`,...t},n);return r?r.state===`empty`?{step:e,state:`skipped`,text:r.message}:Fr(e,r.status,t):null}function zr(e,t){let[n,r]=(0,M.useState)({state:`idle`}),i=(0,M.useRef)(!0);(0,M.useEffect)(()=>(i.current=!0,()=>{i.current=!1}),[]);let a=(0,M.useRef)(t);(0,M.useLayoutEffect)(()=>{a.current=t});let o=(0,M.useRef)(!1),{collection:s,slug:c}=e;return{run:n,start:(0,M.useCallback)(e=>{if(o.current)return;o.current=!0;let t=()=>i.current;(async()=>{let n=[];try{for(let i of e){r({state:`running`,step:i});let e=await Rr(i,{collection:s,slug:c},t);if(!e)return;n.push(e)}if(!t())return;r({state:`done`,outcomes:n}),a.current(n)}catch(e){if(!t())return;r({state:`failed`,message:T(e,`Enrichment failed`)}),n.length>0&&a.current(n)}finally{o.current=!1}})()},[s,c])}}var Br={generated:E,skipped:st,error:vt};function Vr({outcomes:e}){return(0,N.jsx)(`ul`,{className:`data-outcomes`,children:e.map(e=>{let t=Br[e.state];return(0,N.jsxs)(`li`,{className:`data-outcome data-outcome--${e.state}`,children:[(0,N.jsx)(t,{"aria-hidden":`true`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`strong`,{children:yt[e.step]}),` · `,e.text]})]},e.step)})})}function Hr(e){switch(e.state){case`running`:return`Enriching · ${yt[e.step]}…`;case`failed`:return`Enrichment failed: ${e.message}`;case`done`:return`Enrichment finished. ${e.outcomes.map(e=>`${yt[e.step]}: ${e.text}`).join(`. `)}`;default:return``}}function Ur({run:e}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:Hr(e)}),e.state===`running`&&(0,N.jsxs)(F,{children:[`Enriching · `,yt[e.step],`…`]}),e.state===`failed`&&(0,N.jsx)(F,{tone:`error`,children:e.message}),e.state===`done`&&(0,N.jsx)(Vr,{outcomes:e.outcomes})]})}function Wr(){return(0,N.jsxs)(F,{children:[`No language model is set up. Set one up in `,(0,N.jsx)(s,{to:Ae,children:`Setup › AI provider`}),`.`]})}function Gr(e){let{run:t,start:n}=zr(e.target,e.onFinished),r=xt(),i=t.state===`running`,a=i?`Enrichment is running.`:r.state===`running`?`A run across the site is going, and the API runs one job at a time. Enrich this document when it ends.`:Ir(e.facts);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`data-actions`,children:(0,N.jsx)(Ct,{reason:a,variant:`primary`,icon:St,onClick:()=>n([`meta-descriptions`,`archetype`]),children:`Enrich this document`})}),a&&!i&&(0,N.jsx)(F,{children:a}),(0,N.jsx)(Ur,{run:t})]})}function Kr(e){let t=gt();return(0,N.jsxs)(P,{title:`Enrichment`,lead:(0,N.jsxs)(N.Fragment,{children:[`Fills what is `,(0,N.jsx)(`em`,{children:`missing`}),` — a meta description and the Schema.org properties no one has set — with the language model set up in Setup › AI provider. It never overwrites a value someone set. What it fills is saved to the document at once: the meta description as a new version and in the document's SEO settings, the Schema.org properties in those settings. The SEO settings have no versions, so the structured data on the live page — and the meta description the site reads from them first — changes straight away.`]}),children:[t===`loading`&&(0,N.jsx)(F,{children:`Reading the AI provider…`}),t===`missing`&&(0,N.jsx)(Wr,{}),(t===`configured`||t===`unknown`)&&(0,N.jsx)(Gr,{...e})]})}var qr={error:{icon:vt,label:`Error`,order:0},warning:{icon:Et,label:`Warning`,order:1},info:{icon:Tt,label:`Note`,order:2}};function Jr({finding:e,reader:t}){let{icon:n,label:r}=qr[e.severity];return(0,N.jsxs)(`li`,{className:`editor-finding editor-finding--${e.severity}`,children:[(0,N.jsx)(n,{className:`editor-finding-icon`,role:`img`,"aria-label":r}),(0,N.jsxs)(`span`,{className:`editor-finding-text`,children:[t&&(0,N.jsxs)(`span`,{className:`editor-finding-reader`,children:[t,`: `]}),e.message,e.property&&(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsxs)(`code`,{children:[e.type?`${e.type}.`:``,e.property]})]}),e.source&&(0,N.jsxs)(`a`,{className:`editor-finding-source`,href:e.source,target:`_blank`,rel:`noreferrer`,children:[`Documentation`,(0,N.jsx)(wt,{"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`visually-hidden`,children:` (opens in a new tab)`})]})]})]})}function Yr(e,t){let n=[{id:`page`,label:`Title and meta description`,findings:[]},{id:`schema.org`,label:`Schema.org`,findings:[]},...t.map(e=>({id:e.id,label:e.name,findings:[]}))];for(let t of e){let e=t.check===`structured-data`?t.reader??`schema.org`:`page`,r=n.find(t=>t.id===e);r||(r={id:e,label:e,findings:[]},n.push(r)),r.findings.push(t)}let r=e=>qr[e.severity].order;for(let e of n)e.findings.sort((e,t)=>r(e)-r(t));return n}function Xr(e){let t=e.filter(e=>e.severity===`error`).length,n=e.filter(e=>e.severity===`warning`).length;return t>0?{tone:`danger`,text:`${t} error${t===1?``:`s`}`}:n>0?{tone:`warning`,text:`${n} warning${n===1?``:`s`}`}:{tone:`success`,text:`Passes`}}function Zr({group:e}){let t=(0,M.useId)(),{tone:n,text:r}=Xr(e.findings);return(0,N.jsxs)(`section`,{className:`data-finding-group`,"aria-labelledby":t,children:[(0,N.jsxs)(`div`,{className:`data-finding-head`,children:[(0,N.jsx)(`h3`,{id:t,className:`data-finding-title`,children:e.label}),(0,N.jsx)(O,{tone:n,children:r})]}),e.findings.length===0?(0,N.jsxs)(`p`,{className:`data-finding-clean`,children:[(0,N.jsx)(E,{"aria-hidden":`true`}),`No findings.`]}):(0,N.jsx)(`ul`,{className:`data-finding-list`,children:e.findings.map((e,t)=>(0,N.jsx)(Jr,{finding:e},`${e.code??e.check}-${e.property??``}-${t}`))})]})}function Qr({findings:e,readers:t}){return(0,N.jsx)(`div`,{className:`data-findings`,children:Yr(e,t).map(e=>(0,N.jsx)(Zr,{group:e},e.id))})}function $r({findings:e,version:t}){return(0,N.jsxs)(P,{title:`Findings per search engine`,lead:`The saved version, v${t}, checked against Schema.org and the rules of each search engine the site targets. Errors make the markup invalid; warnings keep the page from a search feature.`,children:[e.state===`loading`&&(0,N.jsx)(F,{children:`Checking…`}),e.state===`error`&&(0,N.jsx)(F,{tone:`error`,children:e.message}),e.state===`ready`&&(0,N.jsx)(Qr,{findings:e.data.findings,readers:e.data.readers})]})}var ei=(0,M.lazy)(()=>t(()=>import(`./GraphBrowser-Cm5q82MJ.js`).then(e=>({default:e.GraphBrowser})),__vite__mapDeps([2,1,3,4,0,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])));function ti(e){let{source:t,collection:n,slug:r,readOnly:i,onStage:a}=e,o=fe();async function s(e){a(e),o({text:`Graph added to your draft. Save draft, then publish when ready.`})}return(0,N.jsxs)(`div`,{className:`data-graph-editor`,children:[i?(0,N.jsx)(F,{children:i}):(0,N.jsx)(F,{children:`Apply adds your graph changes to this document’s draft. Save draft keeps a snapshot; Publish updates the live page.`}),(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(F,{children:`Loading the graph editor…`}),children:(0,N.jsx)(ei,{saveLabel:`Apply to draft`,model:t.model,catalogTypes:t.catalogTypes,catalogDetails:t.catalogDetails,rawData:t.emitted,collection:n,slug:r,configData:i?void 0:e.draftConfig??t.editable,onSave:i?void 0:s})})]})}function ni(e,t){return(0,M.useMemo)(()=>{if(e.state!==`ready`||t.state!==`ready`)return[];let n=new Set(t.data.catalogTypes.filter(e=>e.siteLevel).map(e=>e.type));return pt({nodes:t.data.nodes,resolved:e.data,siteTypes:n})},[e,t])}function ri({resolved:e,graph:t}){let n=ni(e,t),r=[e,t].find(e=>e.state===`error`);return r?.state===`error`?(0,N.jsx)(F,{tone:`error`,children:r.message}):e.state===`loading`||t.state===`loading`?(0,N.jsx)(F,{children:`Reading the structured data…`}):n.length===0?(0,N.jsx)(F,{children:`The page emits no entities.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ct,{counts:dt(n)}),(0,N.jsx)(ut,{views:n})]})}function ii({graph:e}){return e.state===`loading`?(0,N.jsx)(F,{children:`Composing the JSON-LD…`}):e.state===`error`?(0,N.jsx)(F,{tone:`error`,children:e.message}):(0,N.jsxs)(`details`,{className:`data-disclosure`,children:[(0,N.jsx)(`summary`,{children:`What the page emits · view-source`}),(0,N.jsx)(lt,{data:e.data.emitted,label:`application/ld+json`})]})}function ai({open:e,readOnly:t,controls:n,onToggle:r}){return(0,N.jsx)(k,{size:`sm`,icon:t?we:Dt,"aria-expanded":e,"aria-controls":n,onClick:r,children:e?`Close the graph editor`:t?`Browse the graph`:`Edit the graph`})}function oi(e){let{graph:t}=e,[n,r]=(0,M.useState)(e.initialOpen??!1),i=(0,M.useId)();return(0,N.jsxs)(P,{title:`JSON-LD graph · what this page emits`,lead:`Every node the page emits, with its type, @id and scope, and each value with where it comes from; a value krantho adds while composing the page reads computed. Sources are read for the saved version, v${e.version}.`,aside:t.state===`ready`?(0,N.jsx)(ai,{open:n,readOnly:e.readOnly,controls:i,onToggle:()=>r(e=>!e)}):null,children:[(0,N.jsx)(ri,{resolved:e.resolved,graph:t}),(0,N.jsx)(ii,{graph:t}),(0,N.jsx)(`div`,{id:i,children:n&&t.state===`ready`&&(0,N.jsx)(ti,{source:t.data,collection:e.collection,slug:e.slug,readOnly:e.readOnly,onStage:e.onStage,draftConfig:e.draftConfig})})]})}function W(e){return typeof e==`string`&&e.trim()!==``?e:``}function si(e){let{fields:t,documentSeo:n,siteSeo:r}=e,i=L(Object.keys(t)),a=e=>W(Cn(i,e,t)),o=W(n.headline)||W(n.name)||a(`title`)||e.slug,s=W(n.description)||a(`description`),c=W(n.image)||a(`image`)||W(r[`og-default-image`]),l=a(`ogImage`)||c;return{title:o,description:s,url:W(n.url)||a(`canonicalUrl`)||e.pageUrl,social:{title:a(`ogTitle`)||o,description:a(`ogDescription`)||s,image:l||null,type:a(`ogType`)||`website`,siteName:W(r.name)||e.siteName},twitterCard:l?`summary_large_image`:`summary`}}function ci(e){if(!e)return{host:``,trail:``};try{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean).map(decodeURIComponent);return{host:t.host,trail:n.map(e=>` › ${e}`).join(``)}}catch{return{host:e,trail:``}}}function li(e){return/^(https?:)?\/\//.test(e)||e.startsWith(`/`)?e:`/api/media/${encodeURIComponent(e)}/image?preset=lg`}function ui(e){return e?.entities[0]?.properties??{}}function di(e){switch(e.state){case`not-live`:return`Checked once the page is live: the search engines read the live page.`;case`other-locale`:return`Checked for the default locale's live page only.`;case`unlisted`:return`Not among the site's checked live pages.`;case`error`:return`The rich results could not be read.`;default:return null}}function fi({feature:e}){return(0,N.jsxs)(`li`,{className:`data-rich`,children:[e.eligible?(0,N.jsx)(E,{className:`data-rich-icon data-rich-icon--eligible`,"aria-hidden":`true`}):(0,N.jsx)(st,{className:`data-rich-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`data-rich-name`,children:e.feature}),(0,N.jsxs)(`span`,{className:`data-rich-reader`,children:[e.reader,` · `,(0,N.jsx)(`code`,{children:e.type})]}),(0,N.jsx)(O,{tone:e.eligible?`success`:`neutral`,children:e.eligible?`Eligible`:`Not eligible`})]})}function pi({rich:e}){if(e.state===`loading`)return(0,N.jsx)(F,{children:`Reading the rich results…`});if(e.state===`error`)return(0,N.jsx)(F,{tone:`error`,children:e.message});let t=di(e.data);if(t)return(0,N.jsx)(F,{children:t});let n=e.data.state===`listed`?e.data.features:[];return n.length===0?(0,N.jsx)(F,{children:`No search feature the readers still show applies to this page.`}):(0,N.jsx)(`ul`,{className:`data-rich-list`,"aria-label":`Rich results`,children:n.map(e=>(0,N.jsx)(fi,{feature:e},`${e.reader}-${e.feature}-${e.type}`))})}function mi({rich:e}){return(0,N.jsx)(P,{title:`Rich results`,lead:`From the search engines' own rules: only the features they still show. What keeps the page from one is under Findings.`,children:(0,N.jsx)(pi,{rich:e})})}function hi(e,t){let n=L(Object.keys(e)),r={};for(let i of t)r[i]=Cn(n,i,e);return r}function gi(e,t){let n=t?.title.maxChars;return e.length===0?{label:`Page title`,pass:!1,hint:`Missing title`}:n===void 0?{label:`Page title`,pass:!0,hint:`${e.length} chars`}:{label:`Page title`,pass:e.length<=n,hint:e.length>n?`Too long (${e.length}/${n})`:`${e.length}/${n} chars`}}function _i(e,t){let n=`Meta description`,r=e.length;if(r===0)return{label:n,pass:!1,hint:`Missing`};if(!t)return{label:n,pass:!0,hint:`${r} chars`};let{minChars:i,maxChars:a}=t.metaDescription;return r<i?{label:n,pass:!1,hint:`Too short (${r}/${i}–${a})`}:r>a?{label:n,pass:!1,hint:`Too long (${r}/${a})`}:{label:n,pass:!0,hint:`${r}/${a} chars`}}function vi(e,t,n){let{description:r,title:i}=hi(e,[`description`,`title`]),a=[gi(i,n),_i(r,n)];a.push({label:`Body content`,pass:t.length>100,hint:t.length===0?`Empty body`:t.length<100?`Very short content`:`${t.length} chars`});let o=(t.match(/^## /gm)??[]).length;a.push({label:`Heading structure`,pass:o>0,hint:o===0?`No ## headings found`:`${o} section heading(s)`});let s=(t.match(/\[.*?\]\(.*?\)/g)??[]).length;return a.push({label:`Links`,pass:s>0,hint:s===0?`No links in content`:`${s} link(s)`}),a}function yi({id:e,label:t,help:n,children:r}){return(0,N.jsxs)(`div`,{className:`data-field`,children:[(0,N.jsx)(`label`,{htmlFor:e,className:`data-field-label`,children:t}),r,n&&(0,N.jsx)(`p`,{id:`${e}-help`,className:`data-field-help`,children:n})]})}function bi(e){return typeof e==`string`?e:``}function xi({title:e,description:t,url:n}){let{host:r,trail:i}=ci(n);return(0,N.jsxs)(`div`,{className:`serp-preview`,children:[(0,N.jsxs)(`div`,{className:`serp-preview-url-row`,children:[(0,N.jsx)(`span`,{className:`serp-preview-favicon`,"aria-hidden":`true`}),(0,N.jsxs)(`div`,{className:`serp-preview-url-group`,children:[(0,N.jsx)(`span`,{className:`serp-preview-site-name`,children:r||`Address not known`}),(0,N.jsxs)(`span`,{className:`serp-preview-breadcrumb`,children:[r,i]})]})]}),(0,N.jsx)(`p`,{className:`serp-preview-title`,children:e}),(0,N.jsx)(`p`,{className:`serp-preview-description`,children:t||`No description: a search engine picks text from the page.`})]})}function Si({preview:e}){return(0,N.jsx)(P,{title:`Search result`,lead:`From the draft's current values, before you save. The live page changes when you publish.`,children:(0,N.jsx)(xi,{title:e.title,description:e.description,url:e.url})})}function Ci({draft:e,limits:t}){let n=vi(e.fields,e.body,t),r=n.filter(e=>!e.pass).length;return(0,N.jsx)(P,{title:`Checks`,aside:(0,N.jsx)(O,{tone:r===0?`success`:`warning`,children:r===0?`All pass`:`${r} to review`}),children:(0,N.jsx)(`ul`,{className:`data-checks`,"aria-label":`Checks`,children:n.map(e=>(0,N.jsxs)(`li`,{className:e.pass?`data-check`:`data-check data-check--open`,children:[e.pass?(0,N.jsx)(E,{className:`data-check-icon`,role:`img`,"aria-label":`Passes`}):(0,N.jsx)(pe,{className:`data-check-icon`,role:`img`,"aria-label":`To review`}),(0,N.jsx)(`span`,{className:`data-check-label`,children:e.label}),(0,N.jsx)(`span`,{className:`data-check-hint`,children:e.hint})]},e.label))})})}function wi({name:e,label:t,hint:n,fields:r,onField:i}){return(0,N.jsxs)(`label`,{className:`data-toggle`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:r[e]!==!1,onChange:t=>i(e,t.target.checked)}),(0,N.jsx)(`span`,{children:t}),(0,N.jsx)(`span`,{className:`data-toggle-hint`,children:n})]})}function Ti({fields:e,pageUrl:t,onField:n}){let r=(0,M.useId)();return(0,N.jsx)(yi,{id:r,label:`canonical-url`,help:t?`Empty: the page's own address, ${t}`:void 0,children:(0,N.jsx)(`input`,{id:r,type:`url`,className:`editor-control`,value:bi(e[`canonical-url`]),placeholder:t??void 0,"aria-describedby":t?`${r}-help`:void 0,onChange:e=>n(`canonical-url`,e.target.value)})})}function Ei({fields:e,pageUrl:t,readOnly:n,onField:r}){let i=e[`robots-index`]===!1?`noindex`:`index`,a=e[`robots-follow`]===!1?`nofollow`:`follow`;return(0,N.jsx)(P,{title:`Indexing`,lead:`Saved with the draft, as the fields canonical-url, robots-index and robots-follow.`,children:(0,N.jsxs)(`fieldset`,{className:`data-fields`,disabled:n,children:[(0,N.jsx)(`legend`,{className:`visually-hidden`,children:`Indexing`}),(0,N.jsx)(Ti,{fields:e,pageUrl:t,onField:r}),(0,N.jsx)(wi,{name:`robots-index`,label:`Index`,hint:`Search engines may list the page`,fields:e,onField:r}),(0,N.jsx)(wi,{name:`robots-follow`,label:`Follow`,hint:`Search engines may follow its links`,fields:e,onField:r}),(0,N.jsx)(`code`,{className:`data-tag`,children:`<meta name="robots" content="${i}, ${a}" />`})]})})}function Di({image:e}){let[t,n]=(0,M.useState)(null);return!e||t===e?(0,N.jsxs)(`div`,{className:`social-card-image social-card-image--empty`,children:[(0,N.jsx)(qe,{"aria-hidden":`true`}),(0,N.jsx)(`span`,{children:e?`The image could not load`:`No social image`})]}):(0,N.jsx)(`div`,{className:`social-card-image`,children:(0,N.jsx)(`img`,{src:li(e),alt:``,onError:()=>n(e)})})}function Oi(e){if(!e)return``;try{return new URL(e).host}catch{return e}}function ki({preview:e}){let{social:t,twitterCard:n}=e,r=Oi(e.url),i=n===`summary_large_image`;return(0,N.jsxs)(`div`,{className:`social-previews`,children:[(0,N.jsxs)(`figure`,{className:`social-preview`,children:[(0,N.jsxs)(`figcaption`,{className:`social-preview-label`,children:[`Open Graph · og:type `,t.type]}),(0,N.jsxs)(`div`,{className:`social-card`,children:[(0,N.jsx)(Di,{image:t.image}),(0,N.jsxs)(`div`,{className:`social-card-text`,children:[(0,N.jsx)(`span`,{className:`social-card-site`,children:t.siteName||r}),(0,N.jsx)(`span`,{className:`social-card-title`,children:t.title}),(0,N.jsx)(`span`,{className:`social-card-description`,children:t.description})]})]})]}),(0,N.jsxs)(`figure`,{className:`social-preview`,children:[(0,N.jsxs)(`figcaption`,{className:`social-preview-label`,children:[`X · `,n]}),(0,N.jsxs)(`div`,{className:i?`social-card`:`social-card social-card--summary`,children:[i?(0,N.jsx)(Di,{image:t.image}):null,(0,N.jsxs)(`div`,{className:`social-card-text`,children:[(0,N.jsx)(`span`,{className:`social-card-title`,children:t.title}),(0,N.jsx)(`span`,{className:`social-card-site`,children:r})]})]})]})]})}var Ai=[`website`,`article`,`product`,`profile`];function ji({value:e,chooseRef:t,onChoose:n,onClear:r}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:t,size:`sm`,onClick:n,children:e?`Change`:`Choose image`}),e&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>{r(),t.current?.focus()},children:`Clear`})]})}function Mi({fields:e,readOnly:t,onField:n}){let r=bi(e[`og-image`]),[i,a]=(0,M.useState)(!1),o=(0,M.useRef)(null);function s(e){n(`og-image`,e.url),a(!1)}return(0,N.jsxs)(`fieldset`,{className:`data-field data-image-field`,disabled:t,children:[(0,N.jsx)(`legend`,{className:`data-field-label`,children:`og-image`}),(0,N.jsxs)(`div`,{className:`data-image-choice`,children:[(0,N.jsx)(`code`,{className:`data-image-value`,children:r||`None: the page image or the site default`}),(0,N.jsx)(ji,{value:r,chooseRef:o,onChoose:()=>a(!0),onClear:()=>n(`og-image`,``)})]}),(0,N.jsx)(`p`,{className:`data-field-help`,children:`1200 × 630 pixels suits most networks.`}),i&&(0,N.jsx)(Vn,{onSelect:s,onUpload:s,onClose:()=>a(!1)})]})}function Ni({name:e,help:t,area:n,fields:r,onField:i}){let a=(0,M.useId)(),o={id:a,value:bi(r[e]),"aria-describedby":`${a}-help`,onChange:t=>i(e,t.target.value)};return(0,N.jsx)(yi,{id:a,label:e,help:t,children:n?(0,N.jsx)(`textarea`,{...o,className:`editor-control editor-control--area`,rows:2}):(0,N.jsx)(`input`,{...o,className:`editor-control`})})}function Pi({fields:e,onField:t}){let n=(0,M.useId)();return(0,N.jsx)(yi,{id:n,label:`og-type`,help:`Auto: website.`,children:(0,N.jsxs)(`select`,{id:n,className:`editor-control editor-control--short`,value:bi(e[`og-type`]),"aria-describedby":`${n}-help`,onChange:e=>t(`og-type`,e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Auto`}),Ai.map(e=>(0,N.jsx)(`option`,{value:e,children:e},e))]})})}function Fi(e){let{fields:t,readOnly:n,onField:r}=e;return(0,N.jsxs)(P,{title:`Social cards`,lead:`From the draft's current values. The overrides are fields of the document, saved with the draft.`,children:[(0,N.jsx)(ki,{preview:e.preview}),(0,N.jsxs)(`fieldset`,{className:`data-fields`,disabled:n,children:[(0,N.jsx)(`legend`,{className:`data-fields-legend`,children:`Overrides for sharing`}),(0,N.jsx)(Ni,{name:`og-title`,help:`Empty: the page title.`,area:!1,fields:t,onField:r}),(0,N.jsx)(Ni,{name:`og-description`,help:`Empty: the meta description.`,area:!0,fields:t,onField:r}),(0,N.jsx)(Pi,{fields:t,onField:r})]}),(0,N.jsx)(Mi,{fields:t,readOnly:n,onField:r})]})}async function Ii(e){if(!e.live)return{state:`not-live`};if(!e.defaultLocale)return{state:`other-locale`};try{let{pages:t,readers:n}=await kt(),r=t.find(t=>t.collection===e.collection&&t.slug===e.slug);if(!r)return{state:`unlisted`};let i=e=>n.find(t=>t.id===e)?.name??e;return{state:`listed`,features:r.features.map(e=>({feature:e.feature,type:e.type,reader:i(e.reader),eligible:e.eligible}))}}catch{return{state:`error`}}}async function Li(e){try{return(await Mt(e)).config?.config??null}catch(e){if(e instanceof Fe&&e.status===501)return null;throw e}}async function Ri(e){let t=await Promise.allSettled(e.map(Nt)),n=new Map;for(let e of t)e.status===`fulfilled`&&n.set(e.value.type.type,e.value);return n}async function zi(e,t,n){let[r,i,a,o,s]=await Promise.all([Pt(e,t,n),Li(`doc:${e}/${t}`),Li(`collection:${e}`),Li(`site`),jt().catch(()=>({types:[]}))]),c=ft(r),l={document:i,collection:a,site:o};return{emitted:r,nodes:c,model:_t(r),editable:ht(c,l),configs:l,catalogTypes:s.types,catalogDetails:await Ri(mt(c))}}function Bi(e,t,n){let{loaded:r,reload:i}=Le(e,t),a=(0,M.useRef)(n);return(0,M.useEffect)(()=>{a.current!==n&&(a.current=n,i())},[n,i]),r}function Vi(e,t){let{collection:n,slug:r,locale:i,live:a,defaultLocale:o}=e,s=(0,M.useCallback)(()=>Ot(n,r,i).then(e=>e.entities),[n,r,i]),c=(0,M.useCallback)(()=>At(n,r,i),[n,r,i]),l=(0,M.useCallback)(()=>Ii({collection:n,slug:r,live:a,defaultLocale:o}),[n,r,a,o]),u=(0,M.useCallback)(()=>zi(n,r,i),[n,r,i]),d=`${e.version}:${t}`;return{resolved:Bi(s,`The structured data could not be read`,d),findings:Bi(c,`The findings could not be read`,d),rich:Bi(l,`The rich results could not be read`,d),graph:Bi(u,`The emitted graph could not be read`,d)}}function Hi(e,t){let n=e.collection?xe(e.collection,t):null,r=e.site?.site.baseUrl;return n!==null&&r?je(r,n):null}function Ui(e,t,n,r){return si({fields:e.draft.draft.fields,slug:n.meta.slug,pageUrl:Hi(t,n.meta.slug),documentSeo:Sn(e.draft.draft.metadata),siteSeo:ui(r?.configs.site??null),siteName:t.site?.site.name??``})}function Wi(e,t){let{meta:n}=e;return{collection:n.collection,slug:n.slug,locale:n.locale,version:n.version,live:n.liveVersion!==null,defaultLocale:t.locales!==null&&n.locale===t.locales.defaultLocale}}function Gi(e,t,n){return{saved:!0,admin:e.isAdmin,canEdit:e.canEdit,lockedBy:e.facts.lockedBy,dirty:e.draft.dirty,defaultLocale:n.defaultLocale,defaultLocaleName:t.locales?.defaultLocale??null}}function Ki(e){return e.readOnly?`Read-only: the graph can be browsed and exported, not changed.`:e.schema?.contract.metadata.seo?null:`This content form does not include structured data overrides.`}function qi({ws:e,source:t,document:n,preview:r}){let{fields:i}=e.draft.draft;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Si,{preview:r}),(0,N.jsx)(Fi,{preview:r,fields:i,readOnly:e.readOnly,onField:e.setField}),(0,N.jsx)(Ei,{fields:i,pageUrl:Hi(t,n.meta.slug),readOnly:e.readOnly,onField:e.setField}),(0,N.jsx)(Ci,{draft:e.draft.draft,limits:t.site?.seo.limits??null})]})}function Ji(e,t){let{reloadDocument:n}=e;return(0,M.useCallback)(e=>{t(),Lr(e)&&n()},[t,n])}function Yi({ws:e,source:t,document:n,initialGraphOpen:r}){let[i,a]=(0,M.useState)(0),o=Wi(n,t),s=Vi(o,i),c=Ji(e,(0,M.useCallback)(()=>{a(e=>e+1),Nr()},[])),l=s.graph.state===`ready`?s.graph.data:null,{meta:u}=n;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(qi,{ws:e,source:t,document:n,preview:Ui(e,t,n,l)}),(0,N.jsx)(oi,{initialOpen:r,resolved:s.resolved,graph:s.graph,collection:u.collection,slug:u.slug,version:u.version,readOnly:Ki(e),onStage:t=>e.draft.setMetadata({...e.draft.draft.metadata,seo:t}),draftConfig:e.draft.draft.metadata.seo}),(0,N.jsx)(mi,{rich:s.rich}),(0,N.jsx)($r,{findings:s.findings,version:u.version}),(0,N.jsx)(Kr,{target:{collection:u.collection,slug:u.slug},facts:Gi(e,t,o),onFinished:c})]})}function Xi({seo:e}){return(0,N.jsx)(P,{title:`Structured data`,children:(0,N.jsx)(F,{children:e?`This collection's documents have no page, so they emit no structured data and search engines do not read them.`:`SEO is off on this site: no structured data, previews or findings are made.`})})}function Zi({ws:e,document:t}){let{meta:n}=t;return(0,N.jsx)(Or,{collection:n.collection,slug:n.slug,locale:n.locale,saved:{version:n.version,liveVersion:n.liveVersion},draft:e.draft.draft,unsaved:e.draft.dirty,canRestore:e.isAdmin&&!e.readOnly,onRestored:e.reloadDocument,onPrepare:e.prepareSnapshot})}function Qi({ws:e,source:t,initialGraphOpen:n}){let r=h(u(),`seo`),{document:i}=e;if(!i)return(0,N.jsx)(`div`,{className:`data-mode`,children:(0,N.jsx)(ot,{icon:Wt,title:`Nothing saved yet`,children:`Data mode reads the saved page: its structured data, findings and history. Save a draft first.`})});let a=t.collection?.pages??!1;return(0,N.jsxs)(`div`,{className:`data-mode`,children:[r&&a?(0,N.jsx)(Yi,{ws:e,source:t,document:i,initialGraphOpen:n}):(0,N.jsx)(Xi,{seo:r}),(0,N.jsx)(Zi,{ws:e,document:i})]})}function $i(e){return e?te(e):`draft`}function ea(e){if(!e)return`Not saved yet`;let{version:t,liveVersion:n}=e;return n===null?`Draft v${t} · nothing is live`:n>=t?`v${t} is live`:`Draft v${t} · live is v${n}`}function ta(e){return e.canEdit?e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.saved&&!e.dirty&&!e.rebased?`No unsaved changes`:null:`Your role cannot edit`}function na(e){return e.canEdit?e.saved?e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.dirty?`Save the draft first: Publish makes the saved version live`:$i(e.saved)===`live`?`v${e.saved.version} is live`:null:`Save the draft first`:`Your role cannot publish`}function ra(e){return e.lockedBy?`${e.lockedBy} is editing`:e.busy?`Working…`:e.conflict?`Answer the version conflict first`:e.dirty||e.rebased?`Save the draft first`:null}function ia(e){let{version:t,liveVersion:n}=e;return n!==null&&n>=t?`Saved · v${t}. It is live: this store publishes every save.`:n===null?`Draft saved · v${t}. Nothing is live until you publish.`:`Draft saved · v${t}. The live page is unchanged until you publish.`}function aa(e,t){return`Publish ${e} v${t}?`}function oa(e){return e.liveVersion===null?`Nothing is live yet. Visitors will see v${e.version}.`:`Visitors see v${e.liveVersion} now and will see v${e.version}.`}function sa(e){let{collection:t,slug:n,liveVersion:r,preview:i,baseUrl:a}=e,o=t?xe(t,n):null;return!t||o===null?null:i?{kind:`preview`,href:`/api/preview?${new URLSearchParams({collection:t.name,slug:n})}`}:r===null||!a?null:{kind:`live`,href:je(a,o)}}function ca(e){let{seo:t,collection:n,slug:r,locale:i,version:a}=e,[o,s]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{if(!t)return;let e=!0;return s({state:`loading`}),At(n,r,i).then(t=>e&&s({state:`ready`,...t})).catch(()=>e&&s({state:`error`})),()=>{e=!1}},[t,n,r,i,a]),t?o:{state:`off`}}function la(e,t){return`${e} ${t}${e===1?``:`s`}`}function ua(e){return e.filter(e=>e.severity!==`info`).sort((e,t)=>qr[e.severity].order-qr[t.severity].order)}function da({findings:e,version:t}){if(e.state===`off`)return null;if(e.state===`loading`)return(0,N.jsx)(`p`,{role:`status`,className:`editor-publish-findings`,children:`Checking the page's SEO findings…`});if(e.state===`error`)return(0,N.jsx)(`p`,{className:`editor-publish-findings`,children:`The page's SEO findings could not be read. Publishing still works.`});let n=ua(e.findings);if(n.length===0)return(0,N.jsxs)(`p`,{className:`editor-publish-findings`,children:[`No SEO errors or warnings in v`,t,`.`]});let r=n.filter(e=>e.severity===`error`).length,i=new Map(e.readers.map(e=>[e.id,e.name]));return(0,N.jsxs)(`div`,{className:`editor-publish-findings`,children:[(0,N.jsxs)(`p`,{children:[`SEO findings in v`,t,`: `,la(r,`error`),` ·`,` `,la(n.length-r,`warning`),`. They do not stop publishing.`]}),(0,N.jsx)(`ul`,{className:`editor-findings`,children:n.map((e,t)=>(0,N.jsx)(Jr,{finding:e,reader:e.reader?i.get(e.reader)??e.reader:void 0},`${e.code??e.check}-${e.property??``}-${t}`))})]})}function fa(e,t,n){let[r,i]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let r=!0;return ae(e,t,n).then(e=>r&&i({state:`ready`,impact:e})).catch(()=>r&&i({state:`error`})),()=>{r=!1}},[e,t,n]),r}function pa({impact:e}){return(0,N.jsxs)(`ul`,{className:`editor-impact`,children:[e.paths.map(e=>(0,N.jsxs)(`li`,{children:[`the page `,(0,N.jsx)(`code`,{children:e})]},e)),e.lists.map(e=>(0,N.jsxs)(`li`,{children:[`the lists of `,m(e).toLowerCase()]},e)),e.everyPageReading&&(0,N.jsx)(`li`,{children:`every page that reads it, as visitors open them`}),e.cachedEntries!==null&&(0,N.jsxs)(`li`,{children:[e.cachedEntries===1?`1 cached entry`:`${e.cachedEntries} cached entries`,` `,`carrying it`]})]})}function ma({impact:e}){return e.state===`loading`?(0,N.jsx)(`p`,{role:`status`,children:`Reading what publishing refreshes…`}):e.state===`error`?(0,N.jsx)(`p`,{children:`What publishing refreshes could not be read. Publishing still works.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{children:`Publishing refreshes:`}),(0,N.jsx)(pa,{impact:e.impact})]})}function ha(e){let{collection:t,slug:n,locale:r,saved:i,hasPage:a,busy:o,onConfirm:s,onClose:c}=e,l=fa(t,n,r),d=ca({seo:h(u(),`seo`)&&a,collection:t,slug:n,locale:r,version:i.version}),f=(0,M.useRef)(null);return(0,N.jsxs)(w,{title:aa(n,i.version),onClose:o?()=>void 0:c,initialFocus:f,busy:o,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:o?void 0:c,"aria-disabled":o,children:`Cancel`}),(0,N.jsx)(k,{ref:f,variant:`primary`,onClick:o?void 0:s,"aria-disabled":o,children:o?`Publishing…`:`Publish`})]}),children:[(0,N.jsx)(`p`,{children:oa(i)}),(0,N.jsx)(ma,{impact:l}),(0,N.jsx)(da,{findings:d,version:i.version})]})}var ga=`A global has no page of its own. Publishing it marks every page that reads it stale; they refresh as visitors open them.`;function _a(){return(0,N.jsxs)(`p`,{className:`globals-banner`,role:`note`,children:[(0,N.jsx)(Tt,{className:`globals-banner-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{children:ga})]})}function va(e){return`${e===1?`1 cached entry`:`${e} cached entries`} in the site's shared page cache carry it now — pages and data alike, so not a count of pages.`}function ya({impact:e}){let{paths:t,everyPageReading:n,cachedEntries:r}=e;return(0,N.jsxs)(N.Fragment,{children:[t.length>0&&(0,N.jsx)(`ul`,{className:`globals-paths`,"aria-label":`The pages publishing refreshes`,children:t.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsx)(`code`,{children:e})},e))}),n&&(0,N.jsx)(`p`,{className:`globals-rule`,children:`Every page that reads it. krantho knows this rule, not a list of those pages, so none is named here.`}),r!==null&&(0,N.jsx)(F,{children:va(r)})]})}function ba({meta:e}){let t=fa(e.collection,e.slug,e.locale);return(0,N.jsxs)(P,{title:`Pages that read it`,lead:`As far as krantho knows: what publishing it refreshes.`,children:[t.state===`loading`&&(0,N.jsx)(F,{children:`Reading which pages read it…`}),t.state===`error`&&(0,N.jsx)(F,{tone:`error`,children:`Which pages read it could not be read.`}),t.state===`ready`&&(0,N.jsx)(ya,{impact:t.impact})]})}function xa({ws:e}){let{document:t}=e;return(0,N.jsxs)(`div`,{className:`data-mode`,children:[(0,N.jsx)(_a,{}),t?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(ba,{meta:t.meta}),(0,N.jsx)(Zi,{ws:e,document:t})]}):(0,N.jsx)(ot,{icon:Wt,title:`Nothing saved yet`,children:`Where it appears reads the saved global and its history. Save it first.`})]})}function Sa(){return(0,N.jsx)(`p`,{className:`live-toolbar side-note`,role:`status`,children:`No element of this page carries the document’s marks: edit it in Structure mode.`})}function Ca({marks:e}){return e.length===0?(0,N.jsx)(Sa,{}):(0,N.jsx)(`p`,{className:`live-toolbar side-note`,children:`Click text on the page to edit it. To edit with the keyboard, use Structure.`})}function wa({frame:e,onReload:t}){let{state:n}=e;return n.kind===`ready`?(0,N.jsx)(Ca,{marks:e.marks}):n.kind===`moved`?(0,N.jsxs)(`div`,{className:`live-toolbar live-moved`,role:`alert`,children:[(0,N.jsxs)(`p`,{children:[`The preview moved to `,(0,N.jsx)(`code`,{children:n.path})]}),(0,N.jsx)(k,{size:`sm`,onClick:t,children:`Back to the page`})]}):(0,N.jsx)(`p`,{className:`live-toolbar side-note`,role:`status`,children:`Loading the draft preview…`})}var Ta=`__lead`,Ea=/^##\s+(.+?)\s*#*\s*$/,Da=/^\s*(`{3,}|~{3,})/;function Oa(e){return Da.exec(e)?.[1]}function G(e){let t=[],n=[],r;for(let i of e.split(`
3
3
  `)){let e=Oa(i);e&&(!r||e[0]===r[0]&&e.length>=r.length)&&(r=r?void 0:e);let a=r||e?null:Ea.exec(i);if(a?.[1]){n.push({heading:a[1],lines:[]});continue}let o=n.at(-1);o?o.lines.push(i):t.push(i)}return{lead:t.join(`
4
4
  `).trim(),sections:n.map(e=>({heading:e.heading,markdown:e.lines.join(`
5
5
  `).trim()}))}}function ka(e,t){let n=`sections`in e?e.sections:e,r=t.trim().toLowerCase();return n.find(e=>e.heading.toLowerCase()===r)}var Aa=`data-krantho-document`,ja=`data-krantho-field`,Ma=`data-krantho-section`;Object.freeze({});function K(e,t){let n={heading:e,markdown:``};return t.some(e=>ka([n],e)!==void 0)}function Na(e,t){let n=G(e),r=t.map(e=>{let t=ka(n,e);return{name:e,found:t?{heading:t.heading,index:n.sections.indexOf(t)}:null}}),i=n.sections.map((e,t)=>({heading:e.heading,index:t})).filter(e=>!K(e.heading,t));return{lead:n.lead,designed:r,prose:i,present:r.filter(e=>e.found!==null).length}}function Pa(e){let t=[0];for(let n=e.indexOf(`
@@ -24,4 +24,4 @@ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{a as t,o as n,s as r}f
24
24
  `);return`${e.prefix}${r}${n}${i?e.eol:``}${e.suffix}`}function Ga(e,t,n){let{sections:r}=G(e),i=r[n];if(i?.heading===t)return{section:i,index:n};let a=r.flatMap((e,n)=>e.heading===t?[n]:[]),[o]=a;if(a.length!==1||o===void 0)return null;let s=r[o];return s?{section:s,index:o}:null}function Ka(e){return G(e).lead}function qa(e){if(typeof Intl.Segmenter==`function`){let t=new Intl.Segmenter(void 0,{granularity:`word`}).segment(e),n=0;for(let e of t)e.isWordLike&&n++;return n}return e.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length}function Ja(e){return`meta-description-${e}`}function Ya(e){return`sections[${JSON.stringify(e)}]`}function Xa(e,t){return`${e}/${t}`}function Za(e,t){let n=[];for(let r of e.querySelectorAll(`[${Aa}]`)){if(r.getAttribute(`data-krantho-document`)!==t)continue;let e=r.getAttribute(ja),i=r.getAttribute(Ma);e?n.push({element:r,target:{kind:`field`,name:e}}):i===`__lead`?n.push({element:r,target:{kind:`lead`}}):i&&n.push({element:r,target:{kind:`section`,heading:i,occurrence:null}})}return n}function Qa(e){return e.ownerDocument.defaultView?.getComputedStyle(e).display===`contents`}function $a(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.closest==`function`?e:t.parentElement??null}function eo(e,t){return e.getAttribute(`data-krantho-document`)===t?e.hasAttribute(`data-krantho-field`)||e.hasAttribute(`data-krantho-section`):!1}function to(e,t){let n=`[${Aa}]`,r=$a(e)?.closest(n)??null;for(;r&&!eo(r,t);)r=r.parentElement?.closest(n)??null;return r}function q(e){return e.kind===`field`?`field:${e.name}`:e.kind===`section`?`section:${e.occurrence??`own`}:${e.heading}`:`lead`}function no(e){let t=e.filter(e=>e!==null);if(t.length===0)return null;let n=Math.min(...t.map(e=>e.top)),r=Math.min(...t.map(e=>e.left)),i=Math.max(...t.map(e=>e.top+e.height));return{top:n,left:r,width:Math.max(...t.map(e=>e.left+e.width))-r,height:i-n}}function ro(e){if(Qa(e))return no([...e.children].map(ro));let t=e.getBoundingClientRect();return t.width===0&&t.height===0?null:{top:t.top,left:t.left,width:t.width,height:t.height}}function io(e,t){if(e.kind===`field`)return`field · ${e.name}`;if(e.kind===`lead`)return`section · lead`;let n=K(e.heading,t)?`designed`:`prose`;return`section · ${e.heading} · ${n}`}function ao(e){let t=new Set,n=new Set;for(let{target:r}of e)r.kind===`field`?t.add(r.name):n.add(r.kind===`lead`?Ta:r.heading);return{fields:t,sections:n}}function oo(e,t,n){let r=t.schema.properties?.[e];if(!r)return typeof n.fields[e]==`string`?`text`:`other`;let i=R(r,e);return i===`media`?`media`:i===`text`||i===`textarea`?`text`:`other`}function so(e,t){let n=t.schema.properties?.[e];return n!==void 0&&R(n,e)===`textarea`}function co(e,t){for(let n of e)n.textContent=t}function lo(e){return Xe.sanitize(Ye.parse(e,{async:!1}))}function uo(e,t,n){e.innerHTML=lo(n!==null&&e.firstElementChild?.tagName===`H2`?`## ${n}\n\n${t}`:t)}var fo=3,po=`http://www.w3.org/1999/xhtml`,mo=new Set([`img`,`input`,`textarea`,`select`,`video`,`audio`,`canvas`,`iframe`,`object`,`embed`]);function ho(e){return e.namespaceURI!==po||mo.has(e.localName)||Qa(e)?!1:[...e.childNodes].every(e=>e.nodeType===fo)}function go(e){return e.textContent??``}function _o(e,t){let n=e,r=n.caretPositionFromPoint?.(t.x,t.y);if(r)return{node:r.offsetNode,offset:r.offset};let i=n.caretRangeFromPoint?.(t.x,t.y);return i?{node:i.startContainer,offset:i.startOffset}:null}function vo(e,t){let n=e.ownerDocument,r=n.getSelection();if(!r)return;let i=n.createRange(),a=t?_o(n,t):null;a&&e.contains(a.node)?(i.setStart(a.node,a.offset),i.collapse(!0)):(i.selectNodeContents(e),i.collapse(!1)),r.removeAllRanges(),r.addRange(i)}function yo(e,t,n){let r=e.getAttribute(t);return e.setAttribute(t,n),()=>r===null?e.removeAttribute(t):e.setAttribute(t,r)}function bo(e){let t=yo(e,`contenteditable`,`plaintext-only`);return e.contentEditable===`inherit`?(e.setAttribute(`contenteditable`,`true`),{plain:!1,restore:t}):{plain:!0,restore:t}}function xo(e){return e.style.setProperty(`white-space`,`pre-wrap`),()=>{e.style.removeProperty(`white-space`),e.getAttribute(`style`)===``&&e.removeAttribute(`style`)}}function So(e,t,n){let r=[yo(e,`role`,`textbox`),yo(e,`aria-label`,t),yo(e,`aria-multiline`,String(n))];return()=>{for(let e of r)e()}}function Co(e,t,n){let r=e.ownerDocument,i=r;if(n.plain&&i.execCommand?.(`insertText`,!1,t))return;let a=r.getSelection();if(!a||a.rangeCount===0)return;let o=a.getRangeAt(0);o.deleteContents();let s=r.createTextNode(t);o.insertNode(s),o.setStartAfter(s),o.collapse(!0),a.removeAllRanges(),a.addRange(o),n.onText(go(e))}function wo(e,t){let n=e.clipboardData?.getData(`text/plain`);return n===void 0?null:t?n.replace(/\r\n?/g,`
25
25
  `):n.replace(/\s*[\r\n]+\s*/g,` `)}function To(e){return e.ownerDocument.activeElement!==e||document.hasFocus()}function Eo(e,t,n){let{multiline:r,onText:i,onClose:a,onDismiss:o}=n,s,c={input:()=>i(go(e)),keydown:n=>{let o=n,s=o.key===`Enter`&&!o.isComposing;o.key!==`Escape`&&!s||s&&r&&t||(o.preventDefault(),o.stopPropagation(),o.key===`Escape`||!r?a():Co(e,`
26
26
  `,{plain:t,onText:i}))},paste:n=>{let a=wo(n,r);a!==null&&(n.preventDefault(),Co(e,a,{plain:t,onText:i}))},drop:e=>e.preventDefault(),blur:()=>{s=setTimeout(()=>{To(e)&&o()})}};for(let[t,n]of Object.entries(c))e.addEventListener(t,n);return{stop:()=>{clearTimeout(s);for(let[t,n]of Object.entries(c))e.removeEventListener(t,n)}}}function Do(e,t){let{plain:n,restore:r}=bo(e),i=[r,So(e,t.label,t.multiline)];t.multiline&&i.push(xo(e));let a=Eo(e,n,t);return e.focus({preventScroll:!0}),vo(e,t.point),()=>{a.stop(),e.ownerDocument.activeElement===e&&e.blur(),e.textContent=go(e);for(let e of i)e()}}function Oo(e,t){let{sections:n}=G(e),r=e=>n.flatMap((t,n)=>e(t.heading)?[n]:[]),i=r(e=>e===t);if(i.length>0)return i;let a=t.trim().toLowerCase();return r(e=>e.toLowerCase()===a)}function ko(e,t){let n=e?t.get(e):void 0;if(n&&n.kind!==`field`)return n.kind===`lead`?null:n.heading}function Ao(e,t,n){let r=e;ko(r,n)===null&&(r=r.nextElementSibling);let i=[];for(let e of t){if(!r||ko(r,n)!==e)return null;i.push(r),r=r.nextElementSibling}return i}function jo(e,t){let n=new Map;return new Map(e.map((e,r)=>{let i=t[r]??``,a=n.get(i)??0;return n.set(i,a+1),[e,a]}))}function Mo(e,t){let n=G(t).sections.map(e=>e.heading),r=new Map;for(let{element:t,target:n}of e)n.kind!==`field`&&Qa(t)&&r.set(t,n);let i=(n.length===0?[]:[...r.keys()]).map(e=>Ao(e,n,r)).filter(e=>e!==null),a=new Set(i.map(e=>e[0])),[o]=i;if(!o||a.size!==1)return[...e];let s=jo(o,n);return e.map(e=>{let t=s.get(e.element);return t===void 0||e.target.kind!==`section`?e:{element:e.element,target:{...e.target,occurrence:t}}})}function No(e,t,n){let r=Oo(e,t),[i]=r;if(i===void 0)return{kind:`missing`};if(r.length===1)return{kind:`index`,index:i};if(n===null)return{kind:`ambiguous`};let a=r[n];return a===void 0?{kind:`missing`}:{kind:`index`,index:a}}function Po(e,t){if(t.kind!==`section`)return null;let n=No(e,t.heading,t.occurrence);return n.kind===`index`?n.index:null}function Fo(e,t,n){let r=Po(n,t),i=q(t);return e.filter(e=>r===null?q(e.target)===i:Po(n,e.target)===r).map(e=>e.element)}function Io(e,t,n){let r=e.filter(e=>Po(t,e.target)===n);return r.find(({target:e})=>e.kind===`section`&&e.occurrence!==null)??r[0]??null}function Lo(e,t,n){let r=Na(e,t).designed,i=t=>{let r=t.found?Io(n,e,t.found.index):null;return r&&t.found?{mark:r,heading:t.found.heading}:null},a=e=>e.map(i).find(e=>e!==null)??null;return r.flatMap((e,t)=>{if(e.found)return[];let n=a(r.slice(0,t).reverse());if(n)return[{name:e.name,side:`after`,...Ro(n)}];let i=a(r.slice(t+1));return i?[{name:e.name,side:`before`,...Ro(i)}]:[{name:e.name,side:`after`,mark:null,neighbour:null}]})}function Ro(e){return{mark:e.mark,neighbour:e.heading}}var zo={kind:`none`};function Bo(e,t){return e.kind===`field`&&t.kind===`field`?e.name===t.name:e.kind===`section`&&t.kind===`section`?e.index===t.index&&e.heading===t.heading&&!e.ambiguous==!t.ambiguous:e.kind===t.kind}function Vo(e,t){let n=e.indexOf(`
27
- `,Math.max(0,t)),r=G(n===-1?e:e.slice(0,n)).sections,i=r.length-1,a=r[i];return a?{kind:`section`,heading:G(e).sections[i]?.heading??a.heading,index:i}:{kind:`lead`}}function Ho(e){switch(e.kind){case`field`:return`Field · ${e.name}`;case`section`:return`Section · ${e.heading}`;case`lead`:return`Lead`;default:return`Page overview`}}function Uo(e){return e.length===1||e===`Backspace`||e===`Delete`||e===`Enter`}var Wo=`The section changed elsewhere; open it again to edit.`,Go=`The field changed elsewhere; open it again to edit.`;function Ko(e,t){if(e.kind===`field`)return{kind:`field`,name:e.name};if(e.kind===`lead`)return{kind:`lead`};let n=No(t,e.heading,e.occurrence);if(n.kind===`ambiguous`)return{kind:`section`,heading:e.heading,index:-1,ambiguous:!0};let r=n.kind===`index`?n.index:-1;return{kind:`section`,heading:G(t).sections[r]?.heading??e.heading,index:r}}function qo(e,t){return t.readOnly?!1:e.kind===`field`?oo(e.name,t.schema,t.draft)===`text`:e.kind===`lead`||No(t.draft.body,e.heading,e.occurrence).kind===`index`}function Jo(e,t){return e?.kind===`field`?t.fields[e.name]:t.body}function Yo(e,t,n){let r=t?q(t):null,i=Jo(t,e),a=(0,M.useRef)({key:r,value:i}),o=t?.kind===`field`?Go:Wo;return(0,M.useLayoutEffect)(()=>{let e=a.current;r===null||e.key!==r?a.current={key:r,value:i}:Object.is(i,e.value)||n(o)},[r,i,o,n]),(0,M.useCallback)(e=>{a.current={...a.current,value:e}},[])}function Xo(e,t){let n=e.kind===`none`;(0,M.useEffect)(()=>{n&&t()},[n,t])}function Zo(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(``);return{selected:e,setSelected:t,edit:n,setEdit:r,notice:i,setNotice:a,closeOnly:(0,M.useCallback)(e=>{r(null),a(e)},[]),clear:(0,M.useCallback)(()=>{t(null),r(null)},[])}}function Qo(e,t,n){if(!t.element)return null;if(e.kind!==`field`){let e=t.element.ownerDocument.defaultView;return e&&t.element instanceof e.HTMLElement?{element:t.element,point:t.point}:null}if(!ho(t.element))return null;let r=n.fields[e.name];return t.element.textContent===(typeof r==`string`?r:``)?{element:t.element,point:t.point}:null}function $o(e,t){return{onBody:n=>{e(n),t.onBody(n)},onField:(n,r)=>{e(r),t.onField(n,r)}}}function es(e){let t=Zo(),{selected:n,notice:r,closeOnly:i,clear:a}=t,o=t.edit?.target??null,s=(0,M.useRef)(null),c=Yo(e.draft,o,i);Xo(e.selection,a);function l(n,r,i){let a=qo(n,e);a&&i.element&&i.element===t.edit?.inPlace?.element||(t.setSelected(n),t.setNotice(``),e.onSelect(Ko(n,e.draft.body),!a),s.current=r,t.setEdit(a?{target:n,inPlace:Qo(n,i,e.draft)}:null))}function u(){a(),e.onSelect(zo)}let d=()=>{u(),s.current?.focus()},f=(0,M.useCallback)(()=>i(``),[i]);return{selected:n,editing:e.readOnly?null:o,inPlace:e.readOnly?null:t.edit?.inPlace??null,notice:r,pick:l,close:d,dismiss:u,closeFirst:f,...$o(c,e)}}function J(e){try{e()}catch{}}function ts(e){try{return e()}catch{return null}}function ns(e){let t=e;try{t=decodeURIComponent(e)}catch{}return t.length>1?t.replace(/\/+$/,``):t}function rs(e,t){return ns(e)===ns(t)}function is(e){return e.defaultView?.performance?.getEntriesByType?.(`navigation`)[0]?.responseStatus??0}function as(e,t,n){try{let r=e?.contentDocument??null;if(!r)return{kind:`unreadable`};if(r.URL===`about:blank`&&t!==`about:blank`)return{kind:`blank`};let i=new URL(r.URL).pathname,a=is(r);return r.contentType!==`text/html`||a>=400?{kind:`error`,path:i,status:a}:rs(i,n)?{kind:`page`,doc:r}:{kind:`other`,path:i}}catch{return{kind:`unreadable`}}}function os(e,t){let n=e.kind===`ready`||e.kind===`moved`;switch(t.kind){case`blank`:return e;case`page`:return e.kind===`ready`&&e.doc===t.doc?e:{kind:`ready`,doc:t.doc};case`timeout`:return e.kind===`loading`?{kind:`failed`,why:`timeout`}:e;case`unreadable`:return{kind:`failed`,why:n?`left`:`unreadable`};default:if(!n){let e=t.kind===`error`?t.status:0;return{kind:`failed`,why:`error`,path:t.path,status:e}}return e.kind===`moved`&&e.path===t.path?e:{kind:`moved`,path:t.path}}}function ss(){let e=document.activeElement;return!e||e===document.body||!e.isConnected}function cs(e,t){let n=(0,M.useRef)(!1),r=t.state.kind===`ready`?ts(()=>t.frameRef.current?.contentDocument):null;return(0,M.useEffect)(()=>{let t=t=>{let r=t.target;n.current=r instanceof Node&&(e.current?.contains(r)??!1)};document.addEventListener(`focusin`,t);let i=()=>{n.current=!0};return J(()=>r?.addEventListener(`focusin`,i)),()=>{document.removeEventListener(`focusin`,t),J(()=>r?.removeEventListener(`focusin`,i))}},[e,r]),n}function ls(e,t,n,r){let i=cs(e,t),a=`${t.reload}:${t.state.kind}:${n}`,o=(0,M.useRef)(a);(0,M.useLayoutEffect)(()=>{if(a===o.current)return;o.current=a;let n=i.current||r.current;r.current=!1,n&&ss()&&(e.current?.querySelector(`.live-moved button`)??t.frameRef.current)?.focus()},[a,i,r,e,t.frameRef]);let s=t.state.kind===`ready`;(0,M.useEffect)(()=>{let e=t.frameRef.current;s&&e&&document.activeElement===e&&J(()=>e.contentWindow?.focus())},[s,t.frameRef])}function us(e){let t=(0,M.useRef)(null);return(0,M.useEffect)(()=>{e&&ss()&&t.current?.focus()},[e]),t}function ds(e){let{title:t,detail:n,tried:r,onReload:i,onStructure:a,announce:o=!1}=e,s=us(o);return(0,N.jsx)(`div`,{className:`live-empty`,role:o?`alert`:void 0,children:(0,N.jsxs)(`div`,{className:`ui-empty-state`,children:[(0,N.jsx)(`span`,{className:`ui-empty-state-icon`,"aria-hidden":`true`,children:(0,N.jsx)(Jt,{})}),(0,N.jsx)(`h2`,{ref:s,tabIndex:-1,className:`ui-empty-state-title`,children:t}),(0,N.jsxs)(`div`,{className:`ui-empty-state-body`,children:[(0,N.jsx)(`p`,{children:n}),r&&(0,N.jsxs)(`p`,{children:[`Tried `,(0,N.jsx)(`code`,{className:`live-empty-url`,children:r})]}),(0,N.jsx)(`p`,{children:`Every field and section can still be edited in Structure mode.`})]}),(0,N.jsxs)(`div`,{className:`ui-empty-state-action`,children:[i&&(0,N.jsx)(k,{icon:Ft,onClick:i,children:`Reload the preview`}),(0,N.jsx)(k,{onClick:a,children:`Switch to Structure mode`})]})]})})}var fs=`The preview answered with an error — for example, your sign-in expired. Reload Studio and try again.`;function ps(e,t){let n=`The page preview did not load`;return t===404?{title:`The site has no page for this document`,detail:`${e} answered 404: the site’s page templates do not render this document.`}:t>=400&&t!==401&&t!==403?{title:n,detail:`${e} answered ${t}.`}:{title:n,detail:fs}}function ms(e){if(e.kind===`failed`&&e.why===`error`)return ps(e.path,e.status);let t=e.kind===`failed`?e.why:`unreadable`;if(t===`left`)return{title:`The preview left the page`,detail:`It went to a page Studio cannot read — another site, or the browser’s own error page.`};let n=`The page preview did not load`;return t===`timeout`?{title:n,detail:`The preview took too long to load.`}:{title:n,detail:`Studio cannot read the preview: it did not load, or it is not on this site’s origin.`}}function hs(e){return e.map(e=>({anchor:e,box:e.mark?ro(e.mark.element):null}))}function gs(e,t,n){let r=t===`after`?e.top+e.height:e.top,i=Math.max(0,e.left),a=n.width>0?Math.min(e.left+e.width,n.width):e.left+e.width;return{top:r,left:i,width:Math.max(0,a-i)}}function _s({placed:e,layer:t}){let n=e.filter(e=>e.box!==null);return n.length===0?null:(0,N.jsx)(`div`,{className:`live-placeholder-markers`,"aria-hidden":`true`,children:n.map(({anchor:e,box:n})=>(0,N.jsx)(`div`,{className:`live-placeholder-marker`,"data-section":e.name,style:gs(n,e.side,t),children:(0,N.jsx)(`span`,{className:`live-placeholder-marker-tag`,children:`${e.name} · not written`})},e.name))})}function vs(e){return e.neighbour?`${e.side} ${e.neighbour}`:null}function ys({placed:e,readOnly:t,onAdd:n}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`live-missing`,"aria-label":`Designed sections not written`,children:e.map(({anchor:e})=>(0,N.jsxs)(`li`,{className:`live-placeholder`,"data-section":e.name,children:[(0,N.jsxs)(`p`,{children:[e.name,` is in this page's section contract but hasn't been written. The page leaves it out.`,vs(e)&&(0,N.jsxs)(`span`,{className:`live-placeholder-at`,children:[` In the page: `,vs(e),`.`]})]}),(0,N.jsx)(k,{size:`sm`,icon:Se,disabled:t,"aria-label":`Add section ${e.name}`,onClick:()=>n(e.name),children:`Add section`})]},e.name))})}var bs=5e3,xs=50;function Ss(e,t){let n,r=null;J(()=>{let i=e.defaultView;i&&(r=new i.MutationObserver(()=>{n??=setTimeout(()=>{n=void 0,t()},xs)}),r.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Aa,ja,Ma]}))});let i=setTimeout(()=>J(()=>r?.disconnect()),bs);return()=>{clearTimeout(i),n!==void 0&&clearTimeout(n),J(()=>r?.disconnect())}}function Y(e,t,n,r={}){return J(()=>e?.addEventListener(t,n,r)),()=>J(()=>e?.removeEventListener(t,n,r))}function Cs(e){let t=e;return t.detail>0?{x:t.clientX,y:t.clientY}:null}function ws(e,t){let n=null,r=()=>e.stillThere();return{over:i=>{if(!r())return;let a=to(i.target,e.documentId);a!==n&&(n=a,e.events.current.onHover(a?t(a):null))},leave:()=>{n=null,e.events.current.onHover(null)},click:n=>{if(!r()||n.target?.closest?.(`.live-markdown-root`))return;let i=to(n.target,e.documentId),a=i?t(i):null;a?(n.preventDefault(),n.stopPropagation(),e.events.current.onPick(a,Cs(n))):e.events.current.onOutsideClick()},key:t=>{t.key===`Escape`&&e.events.current.onEscape()}}}function Ts(e){let t=[],n=()=>{e.stillThere()&&(J(()=>{t=Za(e.doc,e.documentId)}),e.onMarks(t),e.moved())},r=e=>t.find(t=>t.element===e)||(n(),t.find(t=>t.element===e)??null);n();let i=ws(e,r),a=ts(()=>e.doc.defaultView),o=ts(()=>e.doc.documentElement),s=[Ss(e.doc,n),Y(e.doc,`mouseover`,i.over),Y(o,`mouseleave`,i.leave),Y(e.doc,`click`,i.click,{capture:!0}),Y(e.doc,`keydown`,i.key),Y(e.doc,`scroll`,e.moved,{capture:!0,passive:!0}),Y(a,`resize`,e.moved),Y(window,`resize`,e.moved)];return{rescan:n,detach:()=>{for(let e of s)e()}}}var Es=2e4,Ds=500;function Os(e){let t=null;return{notify:()=>{t??=requestAnimationFrame(()=>{t=null,e()})},cancel:()=>{t!==null&&cancelAnimationFrame(t)}}}function ks(e,t){(0,M.useEffect)(()=>{if(e===null)return;let n=setTimeout(t,Es);return()=>clearTimeout(n)},[e,t])}var As={kind:`loading`};function js(e,t){let{src:n,path:r,reload:i}=e,[a,o]=(0,M.useState)({reload:i,state:As}),s=(0,M.useRef)(i);s.current=i;let c=a.reload===i?a.state:As,l=(0,M.useCallback)(e=>{o(t=>{let n=t.reload===s.current?t.state:As;return{reload:s.current,state:os(n,e)}})},[]),u=(0,M.useCallback)(()=>l({kind:`timeout`}),[l]);return ks(c.kind===`loading`?i:null,u),[c,l,(0,M.useCallback)(()=>l(as(t.current,n,r)),[l,t,n,r])]}function Ms(e,t){let{src:n,path:r,documentId:i,body:a,reload:o}=e,s=(0,M.useRef)(null),[c,l,u]=js(e,s),d=(0,M.useCallback)(()=>as(s.current,n,r),[n,r]),f=(0,M.useRef)([]),p=(0,M.useRef)(a);p.current=a;let m=(0,M.useRef)(t);m.current=Ns(t,()=>Mo(f.current,p.current));let h=Is({state:c,documentId:i,events:m,look:d,see:l,raw:f});Ps(c,s,d,l);let g=(0,M.useMemo)(()=>Mo(h.marks,a),[h.marks,a]);return{src:n,reload:o,frameRef:s,state:c,onLoad:u,rescan:h.rescan,marks:g}}function Ns(e,t){let n=e=>t().find(t=>t.element===e.element)??e;return{onHover:t=>e.onHover(t&&n(t)),onPick:(t,r)=>e.onPick(n(t),r),onEscape:e.onEscape,onOutsideClick:e.onOutsideClick}}function Ps(e,t,n,r){let i=e.kind===`moved`;(0,M.useEffect)(()=>{if(!i)return;let e=()=>r(n()),a=setInterval(e,Ds),o=Y(ts(()=>t.current?.contentWindow),`popstate`,e);return()=>{clearInterval(a),o()}},[i,t,n,r])}function Fs(e,t,n){return()=>{let r=t();return r.kind===`page`&&r.doc===e||(n(r),!1)}}function Is(e){let{state:t,documentId:n,events:r,look:i,see:a,raw:o}=e,[s,c]=(0,M.useState)([]),[,l]=(0,M.useState)(0),u=(0,M.useRef)(()=>void 0);return(0,M.useEffect)(()=>{if(t.kind!==`ready`){o.current=[],c([]);return}let e=Os(()=>l(e=>e+1)),s=Fs(t.doc,i,a),d=Ts({doc:t.doc,documentId:n,events:r,onMarks:e=>{o.current=e,c(e)},moved:e.notify,stillThere:s});u.current=d.rescan;let f=setInterval(s,Ds);return()=>{clearInterval(f),u.current=()=>void 0,d.detach(),e.cancel()}},[t,n,r,i,a,o]),{marks:s,rescan:(0,M.useCallback)(()=>u.current(),[])}}var Ls=20,Rs=7;function zs(e,t,n){return Math.max(t,Math.min(e,n))}function Bs(e,t){return e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height}function Vs(e,t,n,r=null){let i=zs(-e.top,0,Math.max(0,e.height-Ls)),a=e.top>=Ls?-20:i,o=e.top+e.height+Ls<=t.height?e.height:i,s=Math.min(n.length*Rs+16,t.width),c=zs(e.left,0,Math.max(0,t.width-s)),l=[a,i,o].find(t=>r===null||!Bs({top:e.top+t,left:c,width:s,height:Ls},r));return l===void 0?null:{top:l,left:c-e.left,maxWidth:Math.max(s,t.width-c)}}function Hs(e,t){let n=t.width-16;return!e||n<=0?null:Math.min(Math.max(e.width,360),n)}function Us(e,t,n,r=!1){let i=r?Hs(e,t):null,a=t.height-16,o=zs(e?.left??8,8,t.width-8-(i??n.width));if(a>0&&n.height>a)return{top:8,left:o,maxHeight:a,width:i};if(!e||a<=0)return{top:8,left:o,maxHeight:null,width:i};let s=t.height-8-n.height,c=e.top+e.height+8,l=e.top-8-n.height;return{top:zs(c<=s?c:l>=8?l:c,8,s),left:o,maxHeight:null,width:i}}function Ws(e,t,n){let r=Math.max(0,t.width-16),i=r>0?Math.min(Math.max(e?.width??n.width,200),r):null,a=Us(e,t,{...n,width:i??n.width});if(!e||t.height<=0)return{...a,width:i};let o=e.top+e.height+5,s=o+n.height<=t.height-8;return{...a,top:s?Math.max(8,o):a.top,width:i}}function Gs(e){let t=`live-outline`;return e===`hovered`?t:e===`selected`?`${t} ${t}--selected`:`${t} ${t}--selected ${t}--editing`}function Ks({target:e,elements:t,designed:n,state:r,layer:i,avoid:a}){let o=t.map(ro).filter(e=>e!==null),s=io(e,n),c=Gs(r);return(0,N.jsx)(N.Fragment,{children:o.map((e,t)=>(0,N.jsx)(`div`,{className:c,style:{top:e.top,left:e.left,width:e.width,height:e.height},children:t===0&&r!==`editing`&&(0,N.jsx)(qs,{box:e,layer:i,text:s,avoid:a})},t))})}function qs(e){let t=Vs(e.box,e.layer,e.text,e.avoid);return t?(0,N.jsx)(`span`,{className:`live-tag`,title:e.text,style:t,children:e.text}):null}function Js(e){if(e.kind===`lead`)return`Introduction`;if(e.kind===`section`)return`${e.heading} section`;if(e.name===`title`)return`Page title`;let t=e.name.replace(/[-_]+/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Ys(e){return e.kind===`field`?`Edit field ${e.name}`:e.kind===`lead`?`Edit the lead`:`Edit section ${e.heading}`}function Xs({props:e,id:t}){let{target:n,draft:r,schema:i,elements:a,onField:o,onPatched:s}=e;if(n.kind!==`field`)return null;let c=r.fields[n.name],l=typeof c==`string`?c:``,u=e=>{o(n.name,e),co(a,e),s()};return so(n.name,i)?(0,N.jsx)(`textarea`,{id:t,className:`editor-control editor-control--area`,rows:3,value:l,onChange:e=>u(e.target.value)}):(0,N.jsx)(`input`,{id:t,className:`editor-control`,value:l,onChange:e=>u(e.target.value)})}function Zs(e,t){if(e.kind===`lead`)return Ua(t);let n=Po(t,e);return n===null?null:Ha(t,n)}function Qs(e){let[t,n]=(0,M.useState)({width:0,height:0}),[,r]=(0,M.useState)(0);return(0,M.useLayoutEffect)(()=>{let r=e.current;if(!r)return;let i=r.offsetHeight-r.clientHeight,a={width:r.offsetWidth,height:r.scrollHeight+i};(a.width!==t.width||a.height!==t.height)&&n(a)}),(0,M.useEffect)(()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>r(e=>e+1));return n.observe(t),()=>n.disconnect()},[e]),t}function $s(e,t){let{elements:n,stage:r,onPlaced:i}=e,a=(0,M.useRef)(null),o=n[0],s=o?ro(o):null,c={width:r?.clientWidth??0,height:r?.clientHeight??0},l=e.target.kind!==`field`,u=e.toolbar?Ws(s,c,t):Us(s,c,t,l),d=s||!a.current?u:a.current;a.current=d;let f=d.maxHeight??t.height,p=d.width??t.width;return(0,M.useLayoutEffect)(()=>{i({top:d.top,left:d.left,width:p,height:f})},[i,d.top,d.left,p,f]),(0,M.useLayoutEffect)(()=>()=>i(null),[i]),d}function ec(e){let t=(0,M.useId)(),n=(0,M.useRef)(null),{target:r,onClose:i}=e;(0,M.useEffect)(()=>{n.current?.querySelector(`input, textarea, button`)?.focus()},[]);let a=$s(e,Qs(n));function o(e){e.key===`Escape`&&(e.preventDefault(),i())}let s={top:a.top,left:a.left,width:a.width??void 0,maxHeight:a.maxHeight??void 0};return(0,N.jsxs)(`div`,{ref:n,className:`live-editor`,style:s,onKeyDown:o,children:[(0,N.jsx)(`label`,{htmlFor:t,className:`live-editor-label`,children:Ys(r)}),(0,N.jsx)(Xs,{props:e,id:t}),(0,N.jsxs)(`div`,{className:`live-editor-actions`,children:[(0,N.jsx)(`span`,{className:`side-note`,children:`Saved with the draft.`}),(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:i,children:`Done`})]})]})}function tc(e){let t=(0,M.useRef)(null),n={kind:`field`,name:e.name},r=$s({...e,target:n,elements:[e.element],toolbar:!0},Qs(t)),i=(0,M.useRef)(e);i.current=e;let{name:a,element:o,multiline:s,point:c}=e,l=(0,M.useRef)(o.textContent??``);return(0,M.useEffect)(()=>Do(o,{label:Ys({kind:`field`,name:a}),multiline:s,point:c,onText:e=>{let{elements:t,onField:n,onPatched:r}=i.current;n(a,e),co(t.filter(e=>e!==o),e),r()},onClose:()=>i.current.onClose(),onDismiss:()=>{t.current?.contains(document.activeElement)||i.current.onDismiss()}}),[a,o,s,c]),(0,N.jsxs)(`fieldset`,{ref:t,className:`live-context`,"aria-label":`Editing ${Js(n)}`,style:{top:r.top,left:r.left,width:r.width??void 0,maxHeight:r.maxHeight??void 0},onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),e.onClose())},onBlur:t=>{if(t.currentTarget.contains(t.relatedTarget))return;let n=o.ownerDocument.defaultView?.frameElement;(t.relatedTarget!==n||o.ownerDocument.activeElement!==o)&&e.onDismiss()},children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`strong`,{children:Js(n)}),(0,N.jsx)(`span`,{className:`side-note`,children:`Draft`})]}),(0,N.jsxs)(`div`,{className:`live-context-actions`,children:[(0,N.jsx)(A,{icon:Ee,label:`Cancel this element’s edit`,className:`live-context-cancel`,size:`sm`,onPointerDown:e=>e.preventDefault(),onClick:()=>{e.onField(a,l.current),co(e.elements,l.current),e.onPatched(),e.onClose()}}),(0,N.jsx)(A,{icon:Ie,label:`Done editing`,className:`live-context-done`,size:`sm`,onPointerDown:e=>e.preventDefault(),onClick:e.onClose})]})]})}var nc=(0,M.lazy)(()=>t(()=>import(`./live-markdown-editor-DM8hYG3n.js`).then(e=>({default:e.LiveMarkdownEditor})),__vite__mapDeps([31,1,0,8,4,5,9,10,11,12,13,14,15,16,32,33,34,6,35,36,37,26])));function rc(e){let{frame:t,body:n,designed:r,hovered:i,selected:a,placed:o,size:s,editor:c,inPlace:l}=e,u=(e,t,n)=>(0,N.jsx)(Ks,{target:e,elements:t,designed:r,state:n,layer:s,avoid:c});return(0,N.jsxs)(`div`,{className:`live-layer`,"aria-hidden":`true`,children:[(0,N.jsx)(_s,{placed:o,layer:s}),i&&!(l&&a&&q(i.target)===q(a))&&u(i.target,[i.element],`hovered`),a&&u(a,Fo(t.marks,a,n),l?`editing`:`selected`)]})}function ic(e){return{width:e?.clientWidth??0,height:e?.clientHeight??0}}function ac(e,t){return e===null||t===null?e===t:e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height}function oc(){let[e,t]=(0,M.useState)(null);return[e,(0,M.useCallback)(e=>{t(t=>ac(t,e)?t:e)},[])]}function sc({props:e,frame:t,editing:n,target:r,stage:i,onPlaced:a}){let{draft:o,schema:s}=e,c=Fo(t.marks,r,o.body),l=n.inPlace?.element,u=l&&c.includes(l)?[l,...c.filter(e=>e!==l)]:c,d={onField:n.onField,onPatched:t.rescan,onClose:n.close};if(r.kind===`field`&&n.inPlace){let{element:e,point:t}=n.inPlace,o=so(r.name,s),c=n.dismiss;return(0,N.jsx)(tc,{stage:i,onPlaced:a,...d,name:r.name,element:e,elements:u,multiline:o,point:t,onDismiss:c},q(r))}return r.kind===`field`?(0,N.jsx)(ec,{...d,target:r,elements:u,stage:i,schema:s,draft:o,onPlaced:a,onBody:n.onBody},q(r)):(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(`span`,{className:`live-loading`,role:`status`,children:`Loading editor…`}),children:(0,N.jsx)(nc,{...d,target:r,elements:u,stage:i,schema:s,draft:o,onPlaced:a,onBody:n.onBody},q(r))})}function cc({props:e,frame:t,title:n,hovered:r,editing:i,placed:a}){let o=(0,M.useRef)(null),[s,c]=oc(),{draft:l,designed:u}=e,d=t.state.kind,f=d===`ready`||d===`loading`?i.editing:null,p={frame:t,body:l.body,designed:u,hovered:r,placed:a,editor:s,inPlace:f!==null&&(i.inPlace!==null||f.kind!==`field`)},m={ref:t.frameRef,title:n,src:t.src,onLoad:t.onLoad};return(0,N.jsxs)(`div`,{ref:o,className:`live-stage`,children:[(0,N.jsx)(`iframe`,{className:`live-frame`,...m},t.reload),d===`ready`&&(0,N.jsx)(rc,{...p,selected:i.selected,size:ic(o.current)}),f&&(0,N.jsx)(sc,{props:e,frame:t,editing:i,target:f,stage:o.current,onPlaced:c})]})}function lc(e,t,n){(0,M.useEffect)(()=>{n(e.kind===`ready`?ao(t):null)},[e,t,n]),(0,M.useEffect)(()=>()=>n(null),[n])}function uc(e,t,n){t.closeFirst();let r=Ra(e.draft.body,e.designed,n);e.onBody(r.body),e.onSelect({kind:`section`,heading:n,index:r.index},!0)}function dc(e,t){let{src:n,path:r,documentId:i,draft:a,reload:o}=e,[s,c]=(0,M.useState)(null),l=es(e),u=Ms({src:n,path:r,documentId:i,body:a.body,reload:o},{onHover:c,onPick:(e,t)=>l.pick(e.target,u.frameRef.current,{element:e.element,point:t}),onEscape:l.dismiss,onOutsideClick:l.dismiss});(0,M.useEffect)(()=>{if(!l.editing)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.live-editor, .live-context`)||t===u.frameRef.current||l.dismiss())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[l.editing,l.dismiss,u.frameRef]),lc(u.state,u.marks,e.onFound);let d=u.state.kind===`moved`||u.state.kind===`failed`,f=l.inPlace?.element,p=f!==void 0&&!u.marks.some(e=>e.element===f),{closeFirst:m}=l;return(0,M.useEffect)(()=>{(d||p)&&m()},[d,p,m]),ls(t,u,l.editing!==null,e.focusRequested),{editing:l,frame:u,hovered:u.state.kind===`ready`&&s&&u.marks.some(e=>e.element===s.element)?s:null}}function fc(e){let{src:t,documentId:n,designed:r,draft:i,onReload:a,onStructure:o}=e,s=(0,M.useRef)(null),{editing:c,frame:l,hovered:u}=dc(e,s);if(l.state.kind===`failed`){let e=ms(l.state);return(0,N.jsx)(ds,{...e,tried:t,onReload:a,onStructure:o,announce:!0})}let d=hs(l.state.kind===`ready`?Lo(i.body,r,l.marks):[]),f=`Draft preview of ${n}`;return(0,N.jsxs)(`div`,{ref:s,className:`live-mode`,children:[(0,N.jsx)(wa,{frame:l,onReload:a}),(0,N.jsx)(`p`,{className:`live-notice side-note`,role:`status`,children:c.notice}),(0,N.jsx)(cc,{props:e,frame:l,title:f,editing:c,placed:d,hovered:u}),(0,N.jsx)(ys,{placed:d,readOnly:e.readOnly,onAdd:t=>uc(e,c,t)})]})}function pc(e){let[t,n]=(0,M.useState)(0),r=(0,M.useRef)(e),i=(0,M.useRef)(!1);return(0,M.useEffect)(()=>{r.current!==null&&e!==r.current&&n(e=>e+1),r.current=e},[e]),{reload:t,onReload:(0,M.useCallback)(()=>{i.current=!0,n(e=>e+1)},[]),focusRequested:i}}function mc(e){let t=pc(e.savedVersion),{preview:n,slug:r,onStructure:i}=e;if(n.src===null||r===null){let e=n.src===null?n.title:`The document has no page yet`,t=n.src===null?n.detail:`Save it first.`;return(0,N.jsx)(ds,{title:e,detail:t,onStructure:i})}return(0,N.jsx)(fc,{...e,...t,src:n.src,path:n.path,documentId:Xa(e.collection,r)})}function hc(e,t){return{src:null,title:e,detail:t}}function gc(e){let{collection:t,slug:n,locale:r,defaultLocale:i,sitePreview:a,canEdit:o}=e;if(n===null)return hc(`The document has no page yet`,`Save it first.`);if(!a)return hc(`The site does not render drafts for editors`,`Live mode needs the site’s draft preview (sitePreview).`);if(!o)return hc(`Your role cannot open the draft preview.`,`The preview is for editors.`);if(r===null||r!==i)return hc(`The site’s preview has no locale`,`Live mode previews the site’s default-locale page; the site’s preview has no locale. Edit ${r??`this version`} in Structure mode.`);let s=sa({collection:t,slug:n,liveVersion:null,preview:!0,baseUrl:null}),c=t?xe(t,n):null;return s?.kind!==`preview`||c===null?hc(`This collection renders no pages`,`There is no page to show.`):{src:s.href,path:c}}function _c({ws:e,slot:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(``),[c,l]=(0,M.useState)(``),[u,d]=(0,M.useState)(null),[f,p]=(0,M.useState)(!1),[m,h]=(0,M.useState)(null),g=e.document?.meta,v=e.schema.contract.metadata[t];if(!g||!v)return null;async function y(e){p(!0),h(null);try{await e()}catch(e){h(T(e,`Shared defaults could not be read`))}finally{p(!1)}}async function b(e){if(s(e),l(``),d(null),!e){a([]);return}let t=await _(e,{locale:g?.locale});a(t.items)}async function ee(n){if(!g||e.draft.dirty)return;let r=await Ne(`/content/${encodeURIComponent(g.collection)}/${encodeURIComponent(g.slug)}/defaults`,{method:`POST`,body:JSON.stringify({sourceCollection:o,slots:[t],sourceSlug:c,locale:g.locale,apply:n,_version:u?.version??g.version,sourceVersion:u?.sourceVersion})});n?(d(null),await e.reloadDocument()):d(r)}return(0,N.jsxs)(`details`,{className:`metadata-defaults`,onToggle:e=>{e.currentTarget.open&&!n.length&&y(async()=>r(await oe()))},children:[(0,N.jsx)(`summary`,{children:`Copy from another page`}),(0,N.jsx)(`p`,{children:`Review details to copy from a shared document. Saved snapshots keep their copied values.`}),e.draft.dirty&&(0,N.jsx)(`p`,{children:`Save your draft before applying shared defaults.`}),(0,N.jsxs)(`fieldset`,{disabled:e.readOnly||f||e.draft.dirty,className:`metadata-defaults-fields`,children:[(0,N.jsxs)(`label`,{children:[`Source collection`,(0,N.jsxs)(`select`,{className:`editor-control`,value:o,onChange:e=>{y(()=>b(e.target.value))},children:[(0,N.jsx)(`option`,{value:``,children:`Choose collection`}),n.map(e=>(0,N.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,N.jsxs)(`label`,{children:[`Source document`,(0,N.jsxs)(`select`,{className:`editor-control`,value:c,onChange:e=>l(e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Choose document`}),i.map(e=>(0,N.jsx)(`option`,{value:e.meta.slug,children:String(e.fields.title??e.meta.slug)},e.meta.slug))]})]}),(0,N.jsx)(k,{size:`sm`,disabled:!c,onClick:()=>{y(()=>ee(!1))},children:`Review defaults`})]}),m&&(0,N.jsx)(`p`,{role:`alert`,children:m}),u&&(0,N.jsxs)(w,{title:`Review shared defaults`,onClose:()=>d(null),actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:()=>d(null),children:`Cancel`}),(0,N.jsx)(k,{disabled:f||e.readOnly||e.draft.dirty||!u.paths.length,onClick:()=>{y(()=>ee(!0))},children:`Apply to draft`})]}),children:[(0,N.jsx)(`p`,{children:u.paths.length?`${u.paths.length} ${u.paths.length===1?`value`:`values`} will be copied from snapshot v${u.sourceVersion}. Your authored overrides stay.`:`No missing or inherited values need updating.`}),m&&(0,N.jsx)(`p`,{role:`alert`,children:m}),(0,N.jsx)(U,{contract:{...e.schema.contract,metadata:{[t]:v}},metadata:u.metadata[t]?{[t]:u.metadata[t]}:{},fields:e.draft.draft.fields,readOnly:!0,errors:{},onMetadata:()=>{}})]})]})}function vc(e,t){return e===0?`missing`:e<t.minChars?`under`:e>t.maxChars?`over`:`within`}function yc(e,t){return e===0?`missing`:e>t?`over`:`within`}var bc={missing:`muted`,under:`ahead`,within:`live`,over:`danger`};function xc(e,t,n){return{segments:[{value:e,tone:bc[t]}],max:Math.max(n,e)}}function Sc(e,t){switch(e){case`missing`:return`none`;case`under`:return`under the target`;case`over`:return t===`range`?`over the target`:`over the limit`;default:return t===`range`?`within the target`:`within the limit`}}function Cc(e,t,n,r){let i=r.has(`meta-description`)?`meta-description`:null,a=[];if(e.source===null){let e=i??(r.has(`description`)?`description`:null);a.push({text:`No meta description: search engines pick text from the page.`,field:e})}if(e.source===`description`&&a.push(i?{text:`Search results show the description. Write a meta description of its own.`,field:i}:{text:`Search results show the description: this collection has no meta-description field.`,field:null}),t===`over`&&e.source){let t=`The meta description is ${e.text.length} characters; search results cut it near ${n.maxChars}.`;a.push({text:t,field:r.has(e.source)?e.source:null})}return a}function wc(e){return e.kind===`range`?`target ${e.min}–${e.max}`:`limit ${e.max}`}function Tc({label:e,length:t,state:n,target:r,note:i}){let{segments:a,max:o}=xc(t,n,r.max);return(0,N.jsxs)(`div`,{className:`side-length side-length--${n}`,"data-length-state":n,children:[(0,N.jsxs)(`div`,{className:`side-length-head`,children:[(0,N.jsx)(`span`,{className:`side-length-label`,children:e}),(0,N.jsxs)(`span`,{className:`side-length-figure`,children:[t,` chars · `,wc(r)]})]}),(0,N.jsx)(at,{segments:a,max:o}),(0,N.jsx)(`span`,{className:`side-length-state`,children:Sc(n,r.kind)}),i&&(0,N.jsx)(`span`,{className:`side-length-note`,children:i})]})}function X({title:e,summary:t,children:n}){let r=(0,M.useId)();return e===void 0?(0,N.jsxs)(`div`,{className:`side-card`,children:[t&&(0,N.jsx)(`div`,{className:`side-card-head`,children:t}),n]}):(0,N.jsxs)(`section`,{className:`side-card`,"aria-labelledby":r,children:[(0,N.jsxs)(`div`,{className:`side-card-head`,children:[(0,N.jsx)(`h3`,{id:r,className:`side-card-title`,children:e}),t]}),n]})}function Z({label:e,children:t}){return(0,N.jsxs)(`div`,{className:`side-fact`,children:[(0,N.jsx)(`dt`,{children:e}),(0,N.jsx)(`dd`,{children:t})]})}function Q({children:e}){return(0,N.jsx)(`p`,{className:`side-note`,children:e})}function Ec(e){let[t,n]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let t=!0;return n({state:`loading`}),$e(e).then(e=>t&&n({state:`ready`,item:e})).catch(()=>t&&n({state:`missing`})),()=>{t=!1}},[e]),[t,e=>n({state:`ready`,item:e})]}function Dc({item:e,disabled:t,onReplaced:n}){let r=(0,M.useRef)(null),{busy:i,run:a}=Ue(e,n);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{ref:r,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&a(t)}}),(0,N.jsx)(k,{size:`sm`,icon:We,disabled:t||i,onClick:()=>r.current?.click(),children:i?`Replacing…`:`Replace`})]})}function Oc({item:e,disabled:t,onSaved:n}){let r=(0,M.useId)(),[i,a]=(0,M.useState)(e.altText);(0,M.useEffect)(()=>a(e.altText),[e.altText]);let{busy:o,run:s}=ze(e,n),c=o||i===e.altText;return(0,N.jsxs)(`div`,{className:`side-field`,children:[(0,N.jsx)(`label`,{htmlFor:r,className:`side-field-label`,children:`Alt text`}),(0,N.jsx)(`input`,{id:r,className:`editor-control`,value:i,disabled:t,"aria-describedby":`${r}-note`,onChange:e=>a(e.target.value)}),(0,N.jsx)(`p`,{id:`${r}-note`,className:`side-note`,children:`Saved on the media file at once, for every page that uses it — not in this draft.`}),(0,N.jsx)(kc,{disabled:t,unchanged:c,busy:o,onSave:()=>void s(i)})]})}function kc(e){return(0,N.jsx)(k,{size:`sm`,disabled:e.disabled,"aria-disabled":e.unchanged,onClick:e.unchanged?void 0:e.onSave,children:e.busy?`Saving…`:`Save alt text`})}function Ac({id:e,readOnly:t}){return h(u(),`media`)?t?(0,N.jsx)(k,{size:`sm`,icon:Ve,disabled:!0,children:`Crop & hotspot`}):(0,N.jsxs)(s,{to:b(e),className:Re(`secondary`,`sm`),children:[(0,N.jsx)(Ve,{className:`ui-button-icon`,"aria-hidden":`true`}),`Crop & hotspot`]}):null}function jc({id:e,readOnly:t}){let[n,r]=Ec(e);if(n.state===`loading`)return(0,N.jsx)(Q,{children:`Reading the media file…`});if(n.state===`missing`)return(0,N.jsxs)(Q,{children:[`Media `,e,` was not found.`]});let{item:i}=n;return(0,N.jsxs)(`div`,{className:`side-media`,children:[(0,N.jsx)(`p`,{className:`side-media-name`,children:i.filename}),(0,N.jsxs)(`div`,{className:`side-actions`,children:[(0,N.jsx)(Ac,{id:i.id,readOnly:t}),(0,N.jsx)(Dc,{item:i,disabled:t,onReplaced:r})]}),(0,N.jsx)(Q,{children:`Replacing keeps the id, so pages update without a content change.`}),(0,N.jsx)(Oc,{item:i,disabled:t,onSaved:r},i.id)]})}function Mc(e){return Object.keys(e.schema.properties??{})}function Nc(e,t){return e.seoReadsFields?Fn(Mc(e.schema)).get(t)??`No SEO output`:`Nothing: SEO does not read this document`}function Pc(e,t,n){if(!t.fields.has(n))return`Not found marked by Live mode`;let r=oo(n,e.schema,e.draft);return r===`media`?`Found by Live mode; media changes after Save`:e.readOnly?`Found by Live mode; read-only`:r===`other`?`Found by Live mode; not a text field: edit it in Structure mode`:`Found by Live mode: editable in place`}function Fc(e,t){return t===e?`Search results show this field.`:t===null?`Neither meta-description nor description is set.`:e===`description`?`The fallback: search results show meta-description while it is set.`:`Empty, so search results fall back to description.`}function Ic({doc:e,name:t,limits:n}){let{fields:r}=e.draft;if(t===`meta-description`||t===`description`){let e=Lt(r),{minChars:i,maxChars:a}=n.metaDescription;return(0,N.jsx)(Tc,{label:`Meta description, effective`,length:e.text.length,state:vc(e.text.length,n.metaDescription),target:{kind:`range`,min:i,max:a},note:Fc(t,e.source)})}if(L(Mc(e.schema)).title!==t)return null;let i=r[t],a=typeof i==`string`?i.length:0;return(0,N.jsx)(Tc,{label:`Title`,length:a,state:yc(a,n.title.maxChars),target:{kind:`limit`,max:n.title.maxChars}})}function Lc({doc:e,name:t}){let n=e.draft.fields[t],r=typeof n==`string`?n:``;return r?(0,N.jsx)(jc,{id:r,readOnly:e.readOnly}):(0,N.jsx)(Q,{children:`No file chosen. Choose one in the form.`})}function Rc({doc:e,name:t}){let n=(e.schema.schema.properties??{})[t],r=(e.schema.schema.required??[]).includes(t);return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{children:r?`required`:`optional`}),children:[(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Type`,children:n?(0,N.jsx)(`code`,{children:An(n,t)}):`Not in the schema (custom field)`}),(0,N.jsx)(Z,{label:`Required`,children:r?`Yes`:`No`}),(0,N.jsx)(Z,{label:`Read by`,children:Nc(e,t)}),e.live&&(0,N.jsx)(Z,{label:`On the page`,children:Pc(e,e.live,t)})]}),e.seoReadsFields&&e.limits&&(0,N.jsx)(Ic,{doc:e,name:t,limits:e.limits}),n&&R(n,t)===`media`&&(0,N.jsx)(Lc,{doc:e,name:t})]})}function zc({doc:e,onSelect:t}){let n=e.schema.schema.properties??{},r=Object.keys(n).filter(e=>!wn.has(e));return(0,N.jsxs)(X,{title:`Fields`,children:[(0,N.jsx)(Q,{children:`The form is read-only. Choose a field to see what reads it.`}),(0,N.jsx)(`ul`,{className:`side-rows`,"aria-label":`Fields`,children:r.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:()=>t({kind:`field`,name:e}),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsx)(`span`,{className:`side-row-state`,children:An(n[e]??{},e)})]})},e))})]})}var Bc=[];function Vc({found:e,onSelect:t}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:()=>t({kind:`section`,...e}),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e.heading}),` `,(0,N.jsxs)(`span`,{className:`side-row-state`,children:[(0,N.jsx)(E,{className:`side-row-icon side-row-icon--present`,"aria-hidden":`true`}),`present`]})]})})}function Hc({name:e,readOnly:t,onAdd:n}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row side-row--missing`,disabled:t,onClick:()=>n(e),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsxs)(`span`,{className:`side-row-state`,children:[(0,N.jsx)(Se,{className:`side-row-icon`,"aria-hidden":`true`}),`Add section`]})]})})}function Uc({row:e,readOnly:t,onSelect:n,onAdd:r}){return e.found?(0,N.jsx)(Vc,{found:e.found,onSelect:n}):(0,N.jsx)(Hc,{name:e.name,readOnly:t,onAdd:r})}function Wc({name:e,state:t,onClick:n}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:n,children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsx)(`span`,{className:`side-row-state`,children:t})]})})}function Gc({parts:e,readOnly:t,onSelect:n,onAdd:r}){return(0,N.jsxs)(`ul`,{className:`side-rows`,"aria-label":`Sections`,children:[e.lead!==``&&(0,N.jsx)(Wc,{name:`Lead`,state:`before first ##`,onClick:()=>n({kind:`lead`})}),e.designed.map(e=>(0,N.jsx)(Uc,{row:e,readOnly:t,onSelect:n,onAdd:r},e.name)),e.prose.map(e=>(0,N.jsx)(Wc,{name:e.heading,state:`prose`,onClick:()=>n({kind:`section`,...e})},`${e.index}-${e.heading}`))]})}function Kc({doc:e,onSelect:t}){let n=e.info?.sections??Bc,{body:r}=e.draft,i=(0,M.useMemo)(()=>Na(r,n),[r,n]);function a(i){let a=Ra(r,n,i);e.onBody(a.body),t({kind:`section`,heading:i,index:a.index})}let o=(0,N.jsx)(O,{tone:`accent`,children:`${i.present} / ${n.length} designed`});return(0,N.jsxs)(X,{title:`Page & sections`,summary:o,children:[n.length===0&&(0,N.jsx)(Q,{children:`The page template designs no sections, so each renders as prose.`}),(0,N.jsx)(Gc,{parts:i,readOnly:e.readOnly,onSelect:t,onAdd:a})]})}function qc(e,t){let{collection:n,slug:r,defaultLocale:i}=e;return ie(n,r,t===i?void 0:t)}function Jc(e,t,n){let[r,i]=(0,M.useState)(!1),[a,o]=(0,M.useState)(null),s=c(),l=fe(),u=t.toUpperCase();async function d(){i(!0),o(null);try{await n(t),l({text:`${u} draft created from ${e.defaultLocale.toUpperCase()}.`}),s(qc(e,t))}catch(e){o(T(e,`The ${u} draft could not be created`)),i(!1)}}return{busy:r,error:a,confirm:d}}function Yc({busy:e,confirmRef:t,onCancel:n,onConfirm:r}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:e?void 0:n,"aria-disabled":e,children:`Cancel`}),(0,N.jsx)(k,{ref:t,variant:`primary`,onClick:e?void 0:r,"aria-disabled":e,children:e?`Creating…`:`Create draft`})]})}function Xc({locale:e,props:t,create:n,onClose:r}){let{busy:i,error:a,confirm:o}=Jc(t,e,n),s=(0,M.useRef)(null),c=e.toUpperCase(),l=(0,N.jsx)(Yc,{busy:i,confirmRef:s,onCancel:r,onConfirm:()=>void o()});return(0,N.jsxs)(w,{title:`Create the ${c} draft of ${t.slug}?`,onClose:i?()=>void 0:r,initialFocus:s,busy:i,actions:l,children:[(0,N.jsxs)(`p`,{children:[`Copies the `,t.defaultLocale.toUpperCase(),` version's fields and body into a new `,c,` `,`draft with its own history. Nothing is published.`]}),a&&(0,N.jsx)(`p`,{className:`editor-modal-error`,role:`alert`,children:a})]})}function Zc({locale:e,note:t}){let n=e.toUpperCase();return(0,N.jsxs)(`span`,{className:C(`neutral`,`editor-locale editor-locale--quiet`),title:t,"data-locale":e,children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,children:n}),(0,N.jsxs)(`span`,{className:`visually-hidden`,children:[n,`: `,t]})]})}function Qc({locale:e,onCreate:t}){let n=e.toUpperCase();return(0,N.jsxs)(`button`,{type:`button`,"data-locale":e,className:C(`neutral`,`editor-locale editor-locale--missing`),"aria-label":`Create ${n} draft`,onClick:t,children:[(0,N.jsx)(Se,{className:`ui-chip-icon`,"aria-hidden":`true`}),n]})}function $c({props:e,locale:t,state:n,onCreate:r}){let i=t.toUpperCase(),a=t===e.current;return!a&&n===void 0?(0,N.jsx)(Zc,{locale:t,note:`checking`}):!a&&n===`unknown`?(0,N.jsx)(Zc,{locale:t,note:`whether this version exists could not be checked`}):!a&&n===`missing`?e.canCreate?(0,N.jsx)(Qc,{locale:t,onCreate:r}):null:(0,N.jsx)(s,{to:qc(e,t),className:C(a?`accent`:`neutral`,`editor-locale`),"aria-current":a?`true`:void 0,"aria-label":`${i} version`,"data-locale":t,children:i})}function el(e,t){let[n,r]=(0,M.useState)(null);return(0,M.useEffect)(()=>{if(t!==null||n===null)return;r(null);let i=document.activeElement;if(i&&i!==document.body&&i.isConnected)return;let a=e.current?.querySelector(`[data-locale="${n}"]`);(a&&a.tabIndex>=0?a:e.current)?.focus()},[t,n,e]),r}function tl(e){let{collection:t,slug:n,locales:r,defaultLocale:i}=e,a=Rt(t,n,r,i),[o,s]=(0,M.useState)(null),c=(0,M.useRef)(null),l=el(c,o);if(r.length<2)return null;let u=e=>{l(e),s(null)};return(0,N.jsxs)(`div`,{ref:c,className:`editor-locales`,role:`group`,"aria-label":`Locales`,tabIndex:-1,children:[r.map(t=>(0,N.jsx)($c,{props:e,locale:t,state:a.states?.get(t),onCreate:()=>s(t)},t)),o&&(0,N.jsx)(Xc,{locale:o,props:e,create:a.create,onClose:()=>u(o)})]})}function nl({target:e,locale:t,current:n,status:r,versions:i,canCreate:a,onCreate:o}){let c=t.toUpperCase(),l=n?`exists`:i.states?.get(t);return(0,N.jsxs)(`li`,{className:`side-locale`,"data-locale":t,children:[l===`exists`?(0,N.jsx)(s,{to:qc(e,t),"aria-current":n?`true`:void 0,children:c}):(0,N.jsx)(`span`,{className:`side-locale-name`,children:c}),(0,N.jsx)(rl,{state:l,status:r}),l===`missing`&&a&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Create draft in ${c}`,onClick:o,children:`Create draft`})]})}function rl({state:e,status:t}){return e===`exists`&&t?(0,N.jsxs)(`span`,{className:`side-locale-state`,children:[(0,N.jsx)(ke,{status:t,decorative:!0}),ge[t]]}):(0,N.jsx)(`span`,{className:`side-locale-state side-locale-state--quiet`,children:e===`missing`?`Missing`:e===`unknown`?`Could not be checked`:`Checking…`})}function il({meta:e,locales:t,versions:n,canCreate:r,onCreate:i}){let a={collection:e.collection,slug:e.slug,defaultLocale:t.defaultLocale};return(0,N.jsx)(`ul`,{className:`side-locales`,"aria-label":`Locales`,children:t.supportedLocales.map(t=>{let o=t===e.locale;return(0,N.jsx)(nl,{target:a,locale:t,current:o,status:o?te(e):n.statuses?.get(t)??null,versions:n,canCreate:r,onCreate:()=>i(t)},t)})})}function al({meta:e,locales:t,canCreate:n}){let{supportedLocales:r,defaultLocale:i}=t,a=Rt(e.collection,e.slug,r,i),[o,s]=(0,M.useState)(null);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(il,{meta:e,locales:t,versions:a,canCreate:n,onCreate:s}),o&&(0,N.jsx)(Xc,{locale:o,props:{collection:e.collection,slug:e.slug,defaultLocale:i},create:a.create,onClose:()=>s(null)})]})}function ol({meta:e}){let t=fa(e.collection,e.slug,e.locale);return t.state===`loading`?(0,N.jsx)(Q,{children:`Reading what publishing refreshes…`}):t.state===`error`?(0,N.jsx)(Q,{children:`What publishing refreshes could not be read.`}):(0,N.jsxs)(`div`,{className:`side-refreshes`,children:[(0,N.jsx)(`p`,{className:`side-subtitle`,children:`Publishing refreshes`}),(0,N.jsx)(pa,{impact:t.impact})]})}function sl({doc:e}){let{meta:t,locales:n}=e;return t?(0,N.jsxs)(X,{title:`Reach`,children:[n?(0,N.jsx)(al,{meta:t,locales:n,canCreate:e.canEdit}):(0,N.jsx)(Q,{children:`The site's locales could not be read.`}),e.info?.pages&&(0,N.jsx)(ol,{meta:t})]}):(0,N.jsx)(X,{title:`Reach`,children:(0,N.jsx)(Q,{children:`Save the page first: its locale versions follow.`})})}var cl={document:{},site:{}};async function ll(e){try{return ui(await Li(e))}catch{return{}}}function ul(e,t){let[n,r]=(0,M.useState)(cl),i=Pr();return(0,M.useEffect)(()=>{let n=!0;return Promise.all([t===null?Promise.resolve({}):ll(`doc:${e}/${t}`),ll(`site`)]).then(([e,t])=>{n&&r({document:e,site:t})}),()=>{n=!1}},[e,t,i]),n}function dl(e){let{collection:t,slug:n,fields:r}=e,i=ul(t,n);return si({fields:r,slug:n??``,pageUrl:null,documentSeo:i.document,siteSeo:i.site,siteName:``}).social.image}function fl(e){let t=Sn(e.draft.metadata).description;return typeof t==`string`&&t.trim()?{text:t,source:`metadata`}:Lt(e.draft.fields)}function pl(e,t){let n=Sn(e.draft.metadata),r=n.headline??n.name;return typeof r==`string`&&r.trim()?r:Cn(L(t),`title`,e.draft.fields)}function ml(e){return[...new Set([...Mc(e.schema),...Object.keys(e.draft.fields)])]}function hl(e){let{meta:t,limits:n,label:r}=e,{minChars:i,maxChars:a}=n.metaDescription,o=t.source===`metadata`?`Your own search description`:t.source===`description`?`Falls back to description`:t.source===null?`Neither meta-description nor description is set`:`From meta-description`;return(0,N.jsx)(Tc,{label:r,length:t.text.length,state:vc(t.text.length,n.metaDescription),target:{kind:`range`,min:i,max:a},note:o})}function gl(e){let{title:t,limits:n,label:r}=e;return(0,N.jsx)(Tc,{label:r,length:t.length,state:yc(t.length,n.title.maxChars),target:{kind:`limit`,max:n.title.maxChars}})}function _l({doc:e}){let t=dl({collection:e.collection,slug:e.meta?.slug??null,fields:{...e.draft.fields,...Sn(e.draft.metadata)}});return(0,N.jsx)(Z,{label:`Social image`,children:t?(0,N.jsxs)(N.Fragment,{children:[`Set `,(0,N.jsx)(`code`,{children:t})]}):`None`})}function vl({advice:e,readOnly:t,onEditField:n}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`side-advice`,children:e.map(e=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{children:e.text}),e.field&&!t&&(0,N.jsx)(`button`,{type:`button`,className:`side-link`,"aria-label":`Edit ${e.field}`,onClick:()=>e.field&&n(e.field),children:`Edit`})]},e.text))})}function yl({doc:e,limits:t,names:n,onEditField:r}){let i=fl(e),a=new Set(Mc(e.schema)),o=vc(i.text.length,t.metaDescription);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(hl,{meta:i,limits:t,label:`Meta description`}),(0,N.jsx)(gl,{title:pl(e,n),limits:t,label:`Title`}),(0,N.jsx)(vl,{advice:Cc(i,o,t.metaDescription,a),readOnly:e.readOnly,onEditField:r})]})}function bl(e,t){let n=e.draft.metadata.sharing?.image!==void 0;return{description:(0,N.jsx)(hl,{meta:fl(e),limits:t,label:`Length`}),title:(0,N.jsx)(gl,{title:pl(e,ml(e)),limits:t,label:`Length`}),image:n?void 0:(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(_l,{doc:e})})}}function xl(e){let{doc:t,onEditField:n,renderFields:r}=e,i=h(u(),`seo`)&&(t.info?.pages??!0)?t.limits:null;if(r){let e=r(i?bl(t,i):{});if(e)return e}return i?(0,N.jsxs)(X,{title:`Search and sharing`,children:[(0,N.jsx)(yl,{doc:t,limits:i,names:ml(t),onEditField:n}),(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(_l,{doc:t})})]}):null}var Sl=`Not in the contract. Rename it to a contract heading to get the designed layout, or keep it as prose.`;function Cl({doc:e,heading:t}){let n=(0,M.useId)(),r=Ja(t),i=e.draft.fields[r],a=typeof i==`string`?i:``,o=e.limits?.metaDescription;return(0,N.jsxs)(`div`,{className:`side-field`,children:[(0,N.jsxs)(`div`,{className:`side-field-head`,children:[(0,N.jsx)(`label`,{htmlFor:n,className:`side-field-label`,children:(0,N.jsx)(`code`,{children:r})}),(0,N.jsx)(`span`,{className:`side-field-optional`,children:`optional`})]}),(0,N.jsx)(`textarea`,{id:n,className:`editor-control editor-control--area`,rows:3,value:a,disabled:e.readOnly,"aria-describedby":`${n}-note`,onChange:t=>e.onField(r,t.target.value||void 0)}),(0,N.jsx)(`p`,{id:`${n}-note`,className:`side-note`,children:`This section's own meta description, for a section with its own URL. Saved with the draft.`}),o&&a!==``&&(0,N.jsx)(Tc,{label:`Length`,length:a.length,state:vc(a.length,o),target:{kind:`range`,min:o.minChars,max:o.maxChars}})]})}function wl({doc:e,heading:t,index:n}){let r=Ga(e.draft.body,t,n);if(!r)return(0,N.jsx)(X,{children:(0,N.jsx)(Q,{children:`This section is no longer in the body.`})});let i=K(t,e.info?.sections??[]);return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{tone:i?`accent`:`neutral`,children:i?`designed`:`prose`}),children:[(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Key`,children:(0,N.jsx)(`code`,{children:Ya(t)})}),(0,N.jsx)(Z,{label:`Words`,children:qa(r.section.markdown)})]}),!i&&(0,N.jsx)(Q,{children:Sl}),Object.hasOwn(e.schema.schema.properties??{},Ja(t))&&(0,N.jsx)(Cl,{doc:e,heading:t})]})}function Tl({doc:e,heading:t}){let n=K(t,e.info?.sections??[]);return(0,N.jsx)(X,{summary:(0,N.jsx)(O,{tone:n?`accent`:`neutral`,children:n?`designed`:`prose`}),children:(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Key`,children:(0,N.jsx)(`code`,{children:Ya(t)})}),(0,N.jsx)(Z,{label:`On the page`,children:`This heading appears more than once in the body: edit it in Structure mode.`})]})})}function El({doc:e}){return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{children:`before first ##`}),children:[(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(Z,{label:`Words`,children:qa(Ka(e.draft.body))})}),(0,N.jsx)(Q,{children:`The markdown before the first ## heading.`})]})}function Dl(e){let{doc:t,control:n,onEditField:r,onOpenData:i}=e,{selection:a}=n,o=e=>n.select(e,!0),s=e.mode!==`structure`,c=e.mode!==`live`,l={contract:t.schema.contract,metadata:t.draft.metadata,fields:t.draft.fields,onOpenData:i?e.onOpenGraph??i:null,groupActions:e.groupActions,defaults:t.defaults,readOnly:t.readOnly,errors:t.fieldErrors,onMetadata:t.onMetadata};switch(a.kind){case`field`:return(0,N.jsx)(Rc,{doc:t,name:a.name});case`section`:return a.ambiguous?(0,N.jsx)(Tl,{doc:t,heading:a.heading}):(0,N.jsx)(wl,{doc:t,heading:a.heading,index:a.index});case`lead`:return(0,N.jsx)(El,{doc:t});default:return(0,N.jsxs)(N.Fragment,{children:[s&&(0,N.jsx)(U,{scope:`metadata`,...l,system:t.meta}),(0,N.jsx)(xl,{doc:t,onEditField:r,renderFields:s?e=>(0,N.jsx)(U,{scope:`sharing`,checks:e,...l}):null}),t.readOnly&&t.meta&&(0,N.jsx)(zc,{doc:t,onSelect:o}),c&&(0,N.jsx)(Kc,{doc:t,onSelect:o}),c&&(0,N.jsx)(sl,{doc:t})]})}}function Ol(e){let t=(0,M.useRef)(null);return(0,M.useEffect)(()=>{e>0&&t.current?.focus()},[e]),t}function kl(e){let[t,n]=(0,M.useState)(``),r=(0,M.useRef)(!0);return(0,M.useEffect)(()=>{r.current?r.current=!1:n(`Side panel: ${e}`)},[e]),t}function Al(e){let{control:t}=e,n=Ho(t.selection),r=Ol(t.focusTick),i=kl(n),a=t.selection.kind!==`none`;function o(e){e.key===`Escape`&&!e.defaultPrevented&&a&&(e.preventDefault(),t.select(zo,!0))}return(0,N.jsxs)(`aside`,{id:e.id,className:`side-panel`,"aria-label":`Side panel`,onKeyDown:o,children:[(0,N.jsxs)(`div`,{className:`side-panel-head`,children:[(0,N.jsx)(`h2`,{ref:r,tabIndex:-1,className:`side-panel-title`,children:n}),a&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,icon:It,onClick:()=>t.select(zo,!0),children:`Page overview`}),(0,N.jsx)(A,{id:`${e.id}-hide`,icon:Xt,label:`Hide side panel`,size:`sm`,"aria-expanded":`true`,"aria-controls":e.id,onClick:e.onCollapse})]}),(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:i}),(0,N.jsx)(`div`,{className:`side-panel-body`,children:(0,N.jsx)(Dl,{...e})})]})}function jl(){let[e,t]=(0,M.useState)(zo),[n,r]=(0,M.useState)(0);return{selection:e,select:(0,M.useCallback)((e,n)=>{t(t=>Bo(t,e)?t:e),n&&r(e=>e+1)},[]),focusTick:n}}function Ml(e){return typeof e==`string`?e:JSON.stringify(e)}function Nl({props:e,name:t,value:n}){let r=`${e.idPrefix}-custom-${t}`;return(0,N.jsxs)(`div`,{className:`editor-field editor-custom-field`,children:[(0,N.jsxs)(`div`,{className:`editor-field-head`,children:[(0,N.jsx)(`label`,{className:`editor-field-label`,htmlFor:r,children:t}),(0,N.jsx)(`span`,{className:`editor-field-optional`,children:`custom`})]}),(0,N.jsxs)(`div`,{className:`editor-custom-line`,children:[(0,N.jsx)(`input`,{id:r,type:`text`,className:`editor-control`,value:Ml(n),onChange:n=>e.onChange(t,n.target.value)}),e.canPromote&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Promote ${t} to a schema field`,onClick:()=>e.onPromote(t,n),children:`Promote`})]})]})}function Pl(e){let t=(0,M.useId)();return e.entries.length===0?null:(0,N.jsxs)(`section`,{className:`editor-custom-fields`,"aria-labelledby":t,children:[(0,N.jsx)(`h2`,{id:t,className:`editor-subtitle`,children:`Custom fields`}),(0,N.jsxs)(`p`,{className:`editor-note`,children:[`Not in the collection's schema.`,e.canPromote&&` Promote one to add it to the schema.`]}),e.entries.map(([t,n])=>(0,N.jsx)(Nl,{props:e,name:t,value:n},t))]})}function Fl({pill:e,seoUse:t}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:C(`neutral`,`editor-field-pill`),children:[(0,N.jsx)(`span`,{className:`visually-hidden`,children:`type `}),e]}),t&&(0,N.jsxs)(`span`,{className:C(`accent`,`editor-field-pill`),children:[(0,N.jsx)(en,{className:`ui-chip-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`visually-hidden`,children:`used for search as `}),t]})]})}function Il({id:e,labelId:t,name:n,required:r,pill:i,seoUse:a,isGroup:o}){return(0,N.jsxs)(`div`,{className:`editor-field-head`,children:[(0,N.jsxs)(o?`span`:`label`,{id:t,className:`editor-field-label`,...o?{}:{htmlFor:e},children:[n,r&&(0,N.jsx)(`span`,{className:`editor-field-required`,"aria-hidden":`true`,children:`*`})]}),!r&&(0,N.jsx)(`span`,{className:`editor-field-optional`,children:`optional`}),(0,N.jsx)(Fl,{pill:i,seoUse:a})]})}function Ll(e,t,n){return[t?`${e}-help`:null,n?`${e}-error`:null].filter(Boolean).join(` `)||void 0}function Rl({id:e,help:t,error:n}){return(0,N.jsxs)(N.Fragment,{children:[t&&(0,N.jsx)(`p`,{id:`${e}-help`,className:`editor-field-help`,children:t}),n&&(0,N.jsx)(`p`,{id:`${e}-error`,className:`editor-field-error`,children:n})]})}function zl(e){if(e.property.type===`object`||e.property.type===`array`&&e.property.items?.type!==`string`)return(0,N.jsx)(H,{name:e.name,path:`fields.${e.name}`,property:e.property,value:e.value,required:e.required,errors:e.error?{[`fields.${e.name}`]:e.error}:{},onValue:t=>e.onChange(e.name,t)});let{idPrefix:t,name:n,property:r,value:i,required:a,seoUse:o,error:s,onChange:c}=e,l=R(r,n),u=cr[l],d=`${t}-${n}`,f=`${d}-label`,p=jn(r);return(0,N.jsxs)(`div`,{className:s?`editor-field editor-field--invalid`:`editor-field`,"data-field":n,children:[(0,N.jsx)(Il,{id:d,labelId:f,name:n,required:a,pill:An(r,n),seoUse:o,isGroup:l===`media`}),(0,N.jsx)(u,{id:d,labelId:f,name:n,property:r,value:i,required:a,describedBy:Ll(d,p,s),invalid:s!==void 0,onChange:c}),(0,N.jsx)(Rl,{id:d,help:p,error:s})]})}function Bl(e,t){let[n,r]=(0,M.useState)(``);return(0,M.useEffect)(()=>{if(!t)return;let n=!0;return Promise.resolve(Ye.parse(e)).then(e=>{n&&r(Xe.sanitize(e))}).catch(()=>{n&&r(``)}),()=>{n=!1}},[e,t]),n}function Vl(e){if(!e)return{};let t=t=>{let n=t.currentTarget;e(n.value,n.selectionStart)};return{onSelect:t,onClick:t,onFocus:t}}function Hl({view:e,own:t,label:n,onView:r}){let i=e===t;return(0,N.jsx)(`button`,{type:`button`,className:`editor-body-toggle`,"aria-pressed":i,onClick:()=>r(i?`write`:t),children:n})}function Ul({headingId:e,hintId:t,view:n,onView:r}){return(0,N.jsxs)(`div`,{className:`editor-body-head`,children:[(0,N.jsx)(`h2`,{id:e,className:`editor-body-title`,children:`Body`}),(0,N.jsxs)(`span`,{id:t,className:`editor-body-hint`,children:[`markdown · `,(0,N.jsx)(`code`,{children:`##`}),` headings become sections`]}),(0,N.jsxs)(`span`,{className:`editor-body-views`,children:[(0,N.jsx)(Hl,{view:n,own:`split`,label:`Split`,onView:r}),(0,N.jsx)(Hl,{view:n,own:`preview`,label:`Preview`,onView:r})]})]})}function Wl({html:e}){return(0,N.jsx)(`div`,{className:`editor-body-preview`,children:(0,N.jsx)(`div`,{dangerouslySetInnerHTML:{__html:e}})})}function Gl({headingId:e,hintId:t,props:n}){let{value:r,onChange:i,disabled:a,onCaret:o}=n;return(0,N.jsx)(`textarea`,{className:`editor-body-textarea`,"aria-labelledby":e,"aria-describedby":t,value:r,rows:20,spellCheck:!1,disabled:a,...Vl(o),onChange:e=>{i(e.target.value),o?.(e.target.value,e.target.selectionStart)}})}function Kl(e){let[t,n]=(0,M.useState)(`write`),r=Bl(e.value,t!==`write`),i=(0,M.useId)(),a=(0,M.useId)();return(0,N.jsxs)(`section`,{className:`editor-body`,"aria-labelledby":i,children:[(0,N.jsx)(Ul,{headingId:i,hintId:a,view:t,onView:n}),(0,N.jsxs)(`div`,{className:t===`split`?`editor-body-panes editor-body-panes--split`:`editor-body-panes`,children:[t!==`preview`&&(0,N.jsx)(Gl,{headingId:i,hintId:a,props:e}),t!==`write`&&(0,N.jsx)(Wl,{html:r})]})]})}function ql(e,t){if(!(e instanceof Element))return null;let n=e.closest(`[data-field]`)?.getAttribute(`data-field`)??null;return n===`slug`&&t?null:n}function Jl(e){let t=t=>{let n=ql(t.target,e.newSlug);n&&e.onSelectField?.(n)};return{onFocus:t,onClick:t,onKeyUp:e=>{Uo(e.key)&&t(e)}}}var Yl={type:`string`,description:`Part of the page's address: lowercase words joined by hyphens, suggested from the title.`};function Xl({idPrefix:e,slug:t,error:n}){return(0,N.jsx)(zl,{idPrefix:e,name:`slug`,property:Yl,value:t.value,required:!0,seoUse:null,error:n,onChange:(e,n)=>t.onChange(typeof n==`string`?n:``)})}function Zl(e){let{schema:t,kind:n,openedFields:r}=e;return(0,M.useMemo)(()=>{let e=Object.keys(t.schema.properties??{}).filter(e=>!wn.has(e));return n===`global`?e.filter(e=>r.includes(e)):e},[t,n,r])}function Ql(e,t){return(0,M.useMemo)(()=>t?Fn(Object.keys(e.schema.properties??{})):new Map,[t,e])}function $l({props:e,idPrefix:t}){let{schema:n,draft:r,fieldErrors:i,onField:a}=e,o=Zl(e),s=Ql(n,e.seoReadsFields),c=n.schema.properties??{},l=new Set(n.schema.required??[]);return o.map(e=>(0,N.jsx)(zl,{idPrefix:t,name:e,property:c[e]??{},value:r.fields[e],required:l.has(e),seoUse:s.get(e)??null,error:i[e],onChange:a},e))}function eu(e){let{schema:t,draft:n,newSlug:r,readOnly:i}=e,a=(0,M.useId)(),o=t.schema.properties??{},s=Object.entries(n.fields).filter(([e])=>!(e in o)&&!wn.has(e));return(0,N.jsxs)(`div`,{className:`editor-structure`,children:[(0,N.jsxs)(`fieldset`,{className:`editor-structure-fields`,disabled:i,...Jl(e),children:[(0,N.jsx)(`legend`,{className:`visually-hidden`,children:`Fields`}),r&&(0,N.jsx)(Xl,{idPrefix:a,slug:r,error:e.fieldErrors.slug}),(0,N.jsx)($l,{props:e,idPrefix:a}),(0,N.jsx)(Pl,{idPrefix:a,entries:s,onChange:e.onField,onPromote:(t,n)=>{e.onPromote(t,n).then(()=>{document.getElementById(`${a}-${t}`)?.focus()})},canPromote:e.canPromote})]}),t.contract.body===`none`&&n.body.length>0&&(0,N.jsxs)(`div`,{role:`alert`,children:[(0,N.jsx)(`p`,{children:`This content form has no text body. Remove the text before saving.`}),(0,N.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>e.onBody(``),children:`Remove the text body`})]}),e.kind===`page`&&(t.contract.body!==`none`||n.body.length>0)&&(0,N.jsx)(Kl,{value:n.body,onChange:e.onBody,disabled:i,onCaret:e.onCaret}),(0,N.jsx)(U,{contract:t.contract,metadata:n.metadata,fields:n.fields,defaults:e.defaults,groupActions:e.groupActions,onOpenData:e.onOpenData,readOnly:i,errors:e.fieldErrors,onMetadata:e.onMetadata})]})}var tu=`krantho-studio-panel`,nu={min:300,max:640,fallback:380};function ru(){let{collapsed:e,width:t}=le(tu);return{collapsed:e===!0,width:Oe(t,nu,nu.fallback)}}function iu(){let[e,t]=he(tu,ru),n=(0,M.useCallback)(e=>t(t=>({...t,...e})),[t]);return{...e,setCollapsed:(0,M.useCallback)(e=>n({collapsed:e}),[n]),setWidth:(0,M.useCallback)(e=>n({width:e}),[n])}}function au(e){return e.readOnly?e.creating?`Creating the document…`:e.canEdit?`Read-only: ${e.facts.lockedBy??`Someone else`} is editing. Saving and publishing wait until they finish or the lock expires.`:`Read-only: your role can view documents but not edit them.`:null}function ou(e){let t=document.activeElement;return!t||t===document.body||t.matches(`:disabled`)||!!e?.closest(`.editor-canvas`)?.contains(t)}function su(e,t){let[n,r]=(0,M.useState)(!1),i=(0,M.useRef)(e);return(0,M.useEffect)(()=>{i.current&&!e&&r(!0),e&&r(!1),i.current=e},[e]),(0,M.useEffect)(()=>r(!1),[t]),n}function cu({ws:e}){let t=au(e),n=su(e.facts.lockedBy!==null,e.draft.draft),r=(0,M.useRef)(null),i=(0,M.useRef)(e.readOnly);(0,M.useEffect)(()=>{let t=e.readOnly!==i.current;i.current=e.readOnly,t&&!e.creating&&ou(r.current)&&r.current?.focus()},[e.readOnly,e.creating]);let a=t??(n?`Editing is open again.`:null);return(0,N.jsxs)(`p`,{ref:r,role:`status`,tabIndex:-1,className:a?`editor-readonly`:`editor-readonly editor-readonly--empty`,children:[t&&(0,N.jsx)(de,{className:`editor-notice-icon`,"aria-hidden":`true`}),n&&!t&&(0,N.jsx)(Kt,{className:`editor-notice-icon`,"aria-hidden":`true`}),a]})}function lu(e){let{ws:t,source:n,collection:r,control:i,onMode:a,onFound:o}=e,s=u(),c=t.document?.meta,l=c?.slug??null,d=gc({collection:n.collection,slug:l,locale:c?.locale??null,defaultLocale:n.locales?.defaultLocale??null,sitePreview:h(s,`sitePreview`),canEdit:t.canEdit});return(0,N.jsx)(mc,{preview:d,collection:r,slug:l,schema:t.schema,draft:t.draft.draft,designed:n.collection?.sections??[],readOnly:t.readOnly,savedVersion:c?.version??null,selection:i.selection,onField:t.setField,onBody:t.draft.setBody,onSelect:i.select,onFound:o,onStructure:()=>a(`structure`)})}function uu(e){let{ws:t,kind:n,mode:r,source:i,control:a}=e,{select:o}=a,s=u(),{document:c,draft:l}=t,d=i.collection?.pages??!1;return r===`live`?(0,N.jsx)(lu,{...e}):r===`data`?(0,N.jsx)(Qi,{ws:t,source:i,initialGraphOpen:e.initialGraphOpen}):r===`where`?(0,N.jsx)(xa,{ws:t}):(0,N.jsx)(eu,{kind:n,schema:t.schema,draft:l.draft,openedFields:t.openedFields,newSlug:c?null:t.newSlug,readOnly:t.readOnly,fieldErrors:t.actions.failure?.fieldErrors??{},seoReadsFields:n===`page`&&d&&h(s,`seo`),canPromote:t.isAdmin&&!t.readOnly,onField:t.setField,onBody:l.setBody,onMetadata:l.setMetadata,defaults:c?.defaults,groupActions:e=>(0,N.jsx)(_c,{ws:t,slot:e}),onOpenData:e.onOpenGraph,onPromote:t.promote,onSelectField:e=>o({kind:`field`,name:e}),onCaret:(e,t)=>o(Vo(e,t))})}function du(e,t,n,r,i){return{collection:n,info:t.collection,schema:e.schema,onMetadata:e.draft.setMetadata,defaults:e.document?.defaults??[],fieldErrors:e.actions.failure?.fieldErrors??{},draft:e.draft.draft,meta:e.document?.meta??null,limits:t.site?.seo.limits??null,locales:t.locales,readOnly:e.readOnly,canEdit:e.canEdit,seoReadsFields:r,live:i,onField:e.setField,onBody:e.draft.setBody}}function fu(e,t){(e?.querySelector(`[data-field="${t.replace(/["\\]/g,`\\$&`)}"]`))?.querySelector(`input, textarea, select, button`)?.focus()}function pu(e){let{mode:t,onMode:n,ids:r,canvasRef:i}=e,a=(0,M.useRef)(null);(0,M.useEffect)(()=>{t===`structure`&&a.current!==null&&(fu(i.current,a.current),a.current=null)},[t,i]);let o=(0,M.useCallback)(e=>{t===`structure`?fu(i.current,e):(a.current=e,n(`structure`))},[t,n,i]),s=(0,M.useCallback)(()=>{n(`data`),requestAnimationFrame(()=>document.getElementById(`${r}-mode-data`)?.focus())},[n,r]);return{editField:o,openData:t===`data`?null:s}}function mu(e){let{ws:t,ids:n,mode:r,showPanel:i,canvasRef:a}=e,o=jl(),s=pu(e),[c,l]=(0,M.useState)(!1);(0,M.useEffect)(()=>{r!==`data`&&l(!1)},[r]);let d=()=>{l(!0),e.onMode(`data`)},[f,p]=(0,M.useState)(null),m=h(u(),`seo`)&&e.kind===`page`&&(e.source.collection?.pages??!1),g=r===`live`?f:null,_=du(t,e.source,e.collection,m,g);function v(e){e.key!==`Escape`||e.defaultPrevented||e.currentTarget.contains(e.target)&&o.select(zo)}let y=iu(),b=`${n}-panel`;function ee(e){y.setCollapsed(e),requestAnimationFrame(()=>document.getElementById(`${b}-${e?`show`:`hide`}`)?.focus())}let x=[`editor-columns`];return i?y.collapsed&&x.push(`editor-columns--collapsed`):x.push(`editor-columns--single`),(0,N.jsxs)(`div`,{className:x.join(` `),style:{"--panel-width":`${y.width}px`},children:[(0,N.jsxs)(`div`,{ref:a,id:`${n}-canvas`,role:`tabpanel`,"aria-labelledby":`${n}-mode-${r}`,className:`editor-canvas`,tabIndex:-1,onKeyDown:v,children:[(0,N.jsx)(cu,{ws:t}),(0,N.jsx)(uu,{...e,control:o,onFound:p,initialGraphOpen:c,onOpenGraph:d})]}),i&&y.collapsed&&(0,N.jsx)(A,{id:`${b}-show`,className:`editor-panel-show`,icon:Qt,label:`Show side panel`,"aria-expanded":`false`,onClick:()=>ee(!1)}),i&&!y.collapsed&&(0,N.jsxs)(`div`,{className:`editor-side`,children:[(0,N.jsx)(De,{label:`Resize side panel`,value:y.width,min:nu.min,max:nu.max,grows:`left`,onChange:y.setWidth,onReset:()=>y.setWidth(nu.fallback),controls:b}),(0,N.jsx)(Al,{id:b,onCollapse:()=>ee(!0),doc:_,mode:r,control:o,onEditField:s.editField,onOpenData:s.openData,onOpenGraph:d,groupActions:e=>(0,N.jsx)(_c,{ws:t,slot:e})})]})]})}function hu(e){return JSON.stringify(e,(e,t)=>{if(typeof t!=`object`||!t||Array.isArray(t))return t;let n=Object.entries(t);return Object.fromEntries(n.sort(([e],[t])=>e.localeCompare(t)))})??`undefined`}function $(e,t){return hu(e)===hu(t)}function gu(e,t){return e.body===t.body&&$(e.fields,t.fields)&&$(e.metadata,t.metadata)&&$(e.defaults??[],t.defaults??[])}function _u(e,t,n){let r={},i=new Set([...Object.keys(n.fields),...Object.keys(e.fields)]);for(let a of i){let i=$(e.fields[a],t.fields[a])?n.fields[a]:e.fields[a];i!==void 0&&(r[a]=i)}let a=e.body===t.body?n.body:e.body,o=vu(e.metadata,t.metadata,n.metadata),s=$(e.defaults??[],t.defaults??[])?n.defaults:e.defaults;return{fields:r,body:a,metadata:o,...s?.length?{defaults:s}:{}}}function vu(e,t,n){let r={};for(let i of new Set([...Object.keys(n),...Object.keys(e)])){if($(e[i],t[i])){n[i]!==void 0&&(r[i]=n[i]);continue}if(!e[i])continue;let a={};for(let r of new Set([...Object.keys(n[i]??{}),...Object.keys(e[i]??{})])){let o=$(e[i]?.[r],t[i]?.[r])?n[i]?.[r]:e[i]?.[r];o!==void 0&&(a[r]=o)}r[i]=a}return r}var yu=[`title`,`name`];function bu(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function xu(e){return yu.includes(e)}function Su(e,t,n){return`krantho-autosave-${e}-${t}-${n}`}function Cu(e,t){let n=`krantho-autosave-new-${e}`;return t?`${n}-${t}`:n}function wu(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.savedAt==`string`&&t.metadata!==null&&typeof t.metadata==`object`&&!Array.isArray(t.metadata)&&typeof t.body==`string`&&t.fields!==null&&typeof t.fields==`object`&&!Array.isArray(t.fields)}function Tu(e){try{let t=localStorage.getItem(e);if(!t)return null;let n=JSON.parse(t);return wu(n)?n:null}catch{return null}}function Eu(e,t,n={},r=new Date){try{let i={...t,...n,savedAt:r.toISOString()};return localStorage.setItem(e,JSON.stringify(i)),!0}catch{return!1}}function Du(e){try{localStorage.removeItem(e)}catch{}}function Ou(){let e=`krantho-autosave-probe`;try{return localStorage.setItem(e,`1`),localStorage.removeItem(e),!0}catch{return!1}}function ku(e,t,n){return!e||n&&typeof e.baseVersion!=`number`?!1:!gu(e,t)||!!e.slug}function Au(e,t){return e.baseVersion===void 0||t===null?null:e.baseVersion===t?`made on v${e.baseVersion}`:`made on v${e.baseVersion} — the document is now v${t}`}function ju(e,t){let n=`Your changes to ${e} are not saved.`;return t===`kept`?`${n} They stay in this browser and are offered back when you open it again.`:t===`offer-pending`?`${n} They are not kept: changes from an earlier visit wait to be restored or discarded, and leaving loses what you typed since.`:`${n} This browser cannot keep them, so leaving loses them.`}function Mu({message:e,onStay:t,onLeave:n}){let r=(0,M.useRef)(null);return(0,N.jsx)(w,{title:`Leave without saving?`,onClose:t,initialFocus:r,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:r,onClick:t,children:`Stay`}),(0,N.jsx)(k,{variant:`danger`,onClick:n,children:`Leave`})]}),children:(0,N.jsx)(`p`,{children:e})})}var Nu={unpublish:{title:e=>`Unpublish ${e}?`,verb:`Unpublish`,busy:`Unpublishing…`,says:`Visitors stop seeing it. The change is recorded as a new version, and publishing makes it live again.`,danger:!0},archive:{title:e=>`Archive ${e}?`,verb:`Archive`,busy:`Archiving…`,says:`Visitors stop seeing it and it is marked archived, recorded as a new version. Its versions stay.`,danger:!0},unarchive:{title:e=>`Restore ${e} to draft?`,verb:`Restore to draft`,busy:`Restoring…`,says:`It is no longer archived and becomes a draft again, recorded as a new version. Nothing is published.`,danger:!1}};function Pu(e){let{change:t,name:n,busy:r,onConfirm:i,onClose:a}=e,o=(0,M.useRef)(null),s=Nu[t],c=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:o,onClick:r?void 0:a,"aria-disabled":r,children:`Cancel`}),(0,N.jsx)(k,{variant:s.danger?`danger`:`primary`,onClick:r?void 0:i,"aria-disabled":r,children:r?s.busy:s.verb})]});return(0,N.jsx)(w,{title:s.title(n),onClose:r?()=>void 0:a,initialFocus:o,busy:r,actions:c,children:(0,N.jsx)(`p`,{children:s.says})})}function Fu({ws:e,hasPage:t,dialog:n,close:r}){let{document:i,actions:a,facts:o}=e;if(!i||!o.saved)return null;let s=a.busy===`publish`,c=e=>{a.changePublication(e).then(r)},{collection:l,slug:u,locale:d}=i.meta;if(n.kind===`status`){let{change:e}=n;return(0,N.jsx)(Pu,{change:e,name:u,busy:s,onConfirm:()=>c(e),onClose:r})}return(0,N.jsx)(ha,{collection:l,slug:u,locale:d,saved:o.saved,hasPage:t,busy:s,onConfirm:()=>c(`publish`),onClose:r})}function Iu({ws:e,hasPage:t,dialog:n,close:r}){let{blocker:i}=e.guard;return i.state===`blocked`?(0,N.jsx)(Mu,{message:ju(e.document?.meta.slug??`the new document`,e.autosave.keeping),onStay:()=>i.reset(),onLeave:()=>i.proceed()}):n?(0,N.jsx)(Fu,{ws:e,hasPage:t,dialog:n,close:r}):null}var Lu=16;function Ru(e,t,n){return e<Lu?Lu-e:t>n-Lu?Math.max(Lu-e,n-Lu-t):0}function zu(e,t){(0,M.useLayoutEffect)(()=>{let n=t.current;if(!e||!n)return;n.style.translate=``;let{left:r,right:i}=n.getBoundingClientRect(),a=Ru(r,i,window.innerWidth);a!==0&&(n.style.translate=`${a}px 0`)},[e,t])}function Bu(e,t,n){(0,M.useEffect)(()=>{if(!e)return;function r(e){t.current?.contains(e.target)||n()}return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e,t,n])}function Vu(){let[e,t]=(0,M.useState)(!1),n=(0,M.useRef)(null),r=(0,M.useRef)(null);Bu(e,n,(0,M.useCallback)(()=>t(!1),[]));let i=(0,M.useCallback)(()=>{t(!1),r.current?.focus()},[]);function a(t){t.key===`Escape`&&e&&(t.stopPropagation(),i())}function o(e){n.current?.contains(e.relatedTarget)||t(!1)}return{open:e,toggle:()=>t(e=>!e),dismiss:i,wrapperRef:n,buttonRef:r,onKeyDown:a,onBlur:o}}function Hu({label:e,tone:t,icon:n,children:r}){let{open:i,toggle:a,dismiss:o,wrapperRef:s,buttonRef:c,onKeyDown:l,onBlur:u}=Vu(),d=(0,M.useId)(),f=(0,M.useRef)(null);return zu(i,f),(0,N.jsxs)(`div`,{ref:s,className:`editor-popover`,onKeyDown:l,onBlur:u,children:[(0,N.jsxs)(`button`,{ref:c,type:`button`,className:C(t,`editor-chip-button`),"aria-expanded":i,"aria-controls":d,onClick:a,children:[n&&(0,N.jsx)(n,{className:`ui-chip-icon`,"aria-hidden":`true`}),e,(0,N.jsx)(Ge,{className:`ui-chip-icon editor-chip-caret`,"aria-hidden":`true`})]}),(0,N.jsx)(`div`,{ref:f,id:d,className:`editor-popover-panel`,hidden:!i,children:typeof r==`function`?r(o):r})]})}var Uu={live:`success`,ahead:`warning`,draft:`neutral`};function Wu(e){let{modes:t,mode:n,onMode:r,tabId:i,panelId:a}=e,o=(0,M.useRef)(null);function s(e){let a={ArrowRight:1,ArrowLeft:-1}[e.key];if(a===void 0)return;e.preventDefault();let s=t.findIndex(e=>e.id===n),c=t[(s+a+t.length)%t.length];c&&(r(c.id),o.current?.querySelector(`#${CSS.escape(i(c.id))}`)?.focus())}return(0,N.jsx)(`div`,{ref:o,role:`tablist`,"aria-label":`Mode`,className:`editor-modes`,onKeyDown:s,children:t.map(e=>(0,N.jsx)(`button`,{id:i(e.id),type:`button`,role:`tab`,className:`editor-mode`,"aria-selected":e.id===n,"aria-controls":a,tabIndex:e.id===n?0:-1,onClick:()=>r(e.id),children:e.label},e.id))})}function Gu(e){return e.state===`held`?`You hold the edit lock`:e.state===`foreign`?`${e.holder} is editing`:e.state===`unavailable`?`Not locked: this store keeps no edit locks`:`Not locked`}function Ku({props:e,dismiss:t}){let{facts:n,record:r,onStatusChange:i}=e;if(!i)return null;let a=n.saved!==null&&n.saved.liveVersion!==null,o=r?.status===`archived`,s=ra(n),c=e=>()=>{t(),i(e)};return(0,N.jsxs)(`div`,{className:`editor-detail-actions`,children:[a&&(0,N.jsx)(Ct,{size:`sm`,reason:s,onClick:c(`unpublish`),children:`Unpublish`}),(0,N.jsx)(Ct,{size:`sm`,reason:s,onClick:c(o?`unarchive`:`archive`),children:o?`Restore to draft`:`Archive`}),s&&(0,N.jsx)(`p`,{className:`editor-detail-text`,children:s})]})}function qu({props:e,dismiss:t}){let{facts:n,record:r,lock:i}=e;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`dl`,{className:`editor-detail`,children:[(0,N.jsx)(`dt`,{children:`Versions`}),(0,N.jsx)(`dd`,{children:ea(n.saved)}),(0,N.jsx)(`dt`,{children:`Edit lock`}),(0,N.jsx)(`dd`,{children:Gu(i)}),r&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`dt`,{children:`Last save`}),(0,N.jsxs)(`dd`,{children:[p(r.createdAt),r.changedBy&&` by ${D(r.changedBy)}`,r.status===`archived`&&` · archived`]})]})]}),(0,N.jsx)(Ku,{props:e,dismiss:t})]})}function Ju({lock:e}){return e.state===`foreign`?(0,N.jsx)(Hu,{label:`${e.holder} is editing`,tone:`warning`,icon:de,children:(0,N.jsxs)(`p`,{className:`editor-detail-text`,children:[e.expiresAt&&`Their lock runs until ${p(e.expiresAt)}. `,`The editor is read-only until they finish or the lock expires; it opens for you then.`]})}):null}function Yu({link:e}){let t=e.kind===`preview`?`the saved draft`:`the live page`;return(0,N.jsxs)(`a`,{className:Re(`ghost`,`md`,`editor-site-link`),href:e.href,target:`_blank`,rel:`noreferrer`,title:`Opens ${t} in a new tab`,children:[(0,N.jsx)(wt,{className:`ui-button-icon`,"aria-hidden":`true`}),`Open on site`,(0,N.jsxs)(`span`,{className:`visually-hidden`,children:[` (`,t,`, opens in a new tab)`]})]})}function Xu(e){let{facts:t,siteLink:n,onSave:r,onPublish:i}=e,a=$i(t.saved),o=ta(t),s=na(t);return(0,N.jsxs)(`div`,{className:`editor-header`,children:[(0,N.jsx)(Wu,{...e}),(0,N.jsx)(`span`,{className:`editor-header-spacer`}),(0,N.jsx)(Hu,{label:ge[a],tone:Uu[a],children:t=>(0,N.jsx)(qu,{props:e,dismiss:t})}),(0,N.jsx)(Ju,{lock:e.lock}),e.locales,n&&(0,N.jsx)(Yu,{link:n}),t.canEdit&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Ct,{reason:o,onClick:r,children:e.saving?`Saving…`:`Save draft`}),(0,N.jsx)(Ct,{reason:s,variant:`primary`,onClick:i,children:`Publish`})]})]})}function Zu(e,t){let n=e.savedAt?` from ${p(e.savedAt)}`:``,r=Au(e,t);return`${n}${r?`, ${r}`:``}`}function Qu({offer:e,currentVersion:t,onRestore:n,onDiscard:r}){return(0,N.jsxs)(`section`,{className:`editor-notice`,"aria-label":`Unsaved changes kept in this browser`,children:[(0,N.jsx)(ue,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`p`,{className:`editor-notice-text`,children:[`Unsaved changes`,Zu(e,t),` are kept in this browser.`]}),(0,N.jsxs)(`span`,{className:`editor-notice-actions`,children:[(0,N.jsx)(k,{size:`sm`,variant:`primary`,onClick:n,children:`Restore`}),(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:r,children:`Discard`})]})]})}function $u(e,t){return e===`kept`?` They are also kept in this browser; reload to see v${t}.`:e===`offer-pending`?` They are not kept in this browser while earlier changes wait to be restored or discarded: reloading loses them.`:` This browser cannot keep them: reloading loses them.`}function ed({failure:e,keeping:t,onOverwrite:n}){let r=e.conflictWith;return(0,N.jsxs)(`div`,{className:`editor-notice editor-notice--error`,children:[(0,N.jsx)(Et,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`p`,{className:`editor-notice-text`,children:[e.message,r!==void 0&&$u(t,r)]}),r!==void 0&&(0,N.jsxs)(k,{size:`sm`,variant:`danger`,onClick:()=>n(r),children:[`Overwrite v`,r,` with my changes`]})]})}function td({slug:e,asked:t,editing:n}){return(0,N.jsxs)(`p`,{className:`editor-notice`,children:[(0,N.jsx)(_e,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`editor-notice-text`,children:[e,` has no `,t.toUpperCase(),` version yet. You are editing the `,n.toUpperCase(),` `,`version.`]})]})}function nd({workspace:e,onAnswered:t}){let{actions:n}=e;return(0,N.jsx)(`div`,{role:`alert`,className:`editor-alert-region`,children:n.failure&&(0,N.jsx)(ed,{failure:n.failure,keeping:e.autosave.keeping,onOverwrite:e=>{t(),n.save(e)}})})}function rd({workspace:e,missingLocale:t,onAnswered:n}){let{autosave:r,document:i}=e,a=e=>()=>{e(),n()};return(0,N.jsxs)(`div`,{className:`editor-notices`,children:[(0,N.jsx)(nd,{workspace:e,onAnswered:n}),r.offer&&(0,N.jsx)(Qu,{offer:r.offer,currentVersion:i?.meta.version??null,onRestore:a(e.restoreKept),onDiscard:a(r.discard)}),t&&i&&(0,N.jsx)(td,{slug:i.meta.slug,asked:t,editing:i.meta.locale})]})}var id={page:[{id:`live`,label:`Live`},{id:`structure`,label:`Structure`},{id:`data`,label:`Data`}],global:[{id:`fields`,label:`Fields`},{id:`where`,label:`Where it appears`}]},ad=`mode`;function od(e,t=!0){let n=id[e];return t?n:n.filter(e=>e.id!==`live`)}function sd(e,t,n={}){let r=od(t,n.hasPage??!0),i=r.find(t=>t.id===e);if(i)return i.id;let a=r[0]?.id??`structure`;return a===`live`&&n.isNew?`structure`:a}var cd=null;function ld(){return cd??=y().catch(()=>(cd=null,null)),cd}async function ud(e){try{let[t,n,r,i,a]=await Promise.all([x(e.collection),oe().catch(()=>[]),e.slug?S(e.collection,e.slug,e.locale):null,ld(),v().catch(()=>null)]);return{schema:t,collection:n.find(t=>t.name===e.collection)??null,document:r,site:i,locales:a}}catch(e){if(Ce(e))return null;throw e}}function dd(e){let{collection:t,slug:n,locale:r}=e,i=(0,M.useCallback)(()=>ud({collection:t,slug:n,locale:r}),[t,n,r]);return Le(i,`The document could not load`)}var fd=800;function pd(e,t,n){let{key:r,draft:i,dirty:a,context:o}=e,{baseVersion:s,slug:c}=o;(0,M.useEffect)(()=>{if(!r||t||n.forgotten)return;if(!a){Du(r);return}let e=setTimeout(()=>Eu(r,i,{baseVersion:s,slug:c}),fd);return()=>clearTimeout(e)},[r,i,a,s,c,t,n])}function md(e,t){(0,M.useEffect)(()=>{if(!e)return;let n=()=>{let{input:n,offer:r,forgotten:i}=t;n.dirty&&!r&&!i&&Eu(e,n.draft,n.context)};return window.addEventListener(`pagehide`,n),()=>{window.removeEventListener(`pagehide`,n),n()}},[e,t])}function hd(e){let{key:t}=e,[n,r]=(0,M.useState)(()=>{let n=t?Tu(t):null;return ku(n,e.opened,e.context.baseVersion!==void 0)?n:null}),[i]=(0,M.useState)(Ou),a=(0,M.useRef)({input:e,offer:n,forgotten:!1}).current;a.input=e,a.offer=n,pd(e,n,a),md(t,a);let o=(0,M.useCallback)(()=>(r(null),n),[n]),s=(0,M.useCallback)(()=>{t&&Du(t),r(null)},[t]),c=(0,M.useCallback)(()=>{a.forgotten=!0,t&&Du(t)},[t,a]);return{offer:n,keeping:n?`offer-pending`:t&&i?`kept`:`unavailable`,restore:o,discard:s,forget:c}}function gd(e){let t={};for(let[n,r]of Object.entries(e))r.default!==void 0&&(t[n]=r.default);return t}function _d(e,t){return e?{fields:e.fields,body:e.body,metadata:e.metadata,...e.defaults.length?{defaults:e.defaults}:{}}:{fields:t,body:``,metadata:{}}}function vd(e){let[t,n]=(0,M.useState)(e),[r,i]=(0,M.useState)(e),a=(0,M.useMemo)(()=>!gu(r,t),[r,t]),o=(0,M.useCallback)((e,t)=>{i(n=>{let r={...n.fields};return t===void 0?delete r[e]:r[e]=t,{...n,fields:r}})},[]),s=(0,M.useCallback)(e=>{i(t=>({...t,metadata:e}))},[]);return{draft:r,baseline:t,dirty:a,setField:o,setBody:(0,M.useCallback)(e=>{i(t=>({...t,body:e}))},[]),setMetadata:s,replace:i,reset:(0,M.useCallback)(e=>{n(e),i(e)},[]),rebase:(0,M.useCallback)((e,t)=>{n(e),i(n=>_u(n,t,e))},[])}}function yd(e){let[t,n]=(0,M.useState)(e.document),[r,i]=(0,M.useState)(e.document?.meta.version??null),a=(0,M.useMemo)(()=>gd(e.schema.schema.properties??{}),[e]),o=(0,M.useMemo)(()=>_d(e.document,a),[e,a]),s=vd(o),c=(0,M.useMemo)(()=>Object.keys(o.fields).filter(e=>o.fields[e]!==void 0),[o]),{rebase:l,reset:u}=s,d=(0,M.useCallback)((e,t)=>{n(e),i(e.meta.version),l(_d(e,a),t)},[l,a]),f=(0,M.useCallback)(e=>{n(e),i(e.meta.version),u(_d(e,a))},[u,a]);return{document:t,draft:s,opened:o,openedFields:c,baseVersion:r,restoredOn:(0,M.useCallback)(e=>{e!==void 0&&i(e)},[]),onSaved:d,onReplaced:f}}var bd=5e3,xd=6e4,Sd=3e4,Cd=5e3,wd=6e4;function Td(e){return e.locked?{state:`held`,expiresAt:e.expiresAt??null}:e.status===423&&e.lockedBy?{state:`foreign`,holder:D(e.lockedBy),expiresAt:e.expiresAt??null}:e.status===501?{state:`unavailable`}:null}function Ed(e){return Math.min(wd,Cd*2**Math.max(0,e-1))}function Dd(e,t=Date.now()){if(e.state===`foreign`)return Sd;if(e.state!==`held`)return null;if(!e.expiresAt)return xd;let n=new Date(e.expiresAt).getTime()-t;return Math.max(bd,Math.floor(n/2))}function Od(e,t){let{collection:n,slug:r,locale:i}=e,a=!0,o=!1,s=0,c=null,l=null,u=e=>(s=e?0:s+1,e?(o=e.state===`held`,a&&t(e),Dd(e)):Ed(s)),d=()=>{l=ve(n,r,i).then(e=>{l=null;let t=u(Td(e));a&&t!==null&&(c=setTimeout(d,t))})};return d(),()=>{a=!1,c&&clearTimeout(c);let e=()=>{o&&me(n,r,i)};l?l.then(e):e()}}function kd(e){let[t,n]=(0,M.useState)({state:`none`}),r=e?.collection,i=e?.slug,a=e?.locale;return(0,M.useEffect)(()=>{if(!r||!i||!a)return;let e=Od({collection:r,slug:i,locale:a},n);return()=>{e(),n({state:`none`})}},[r,i,a]),t}var Ad=class extends Error{field;constructor(e,t){super(t),this.name=`FieldRefusal`,this.field=e}};function jd(e){let t={};if(!Array.isArray(e))return t;for(let n of e){if(typeof n!=`object`||!n)continue;let{field:e,message:r}=n;typeof e==`string`&&typeof r==`string`&&(t[e.startsWith(`fields.`)?e.slice(7):e]=r)}return t}function Md(e,t){return{message:`v${e} was saved after ${typeof t==`number`?`v${t}`:`the version you opened`}, the version your changes are based on. Nothing was saved; your changes are still in the form.`,fieldErrors:{},conflictWith:e}}function Nd(e,t){let{body:n}=e;if(e.status===409&&typeof n.currentVersion==`number`)return Md(n.currentVersion,n.yourVersion);if(e.status===423&&typeof n.lockedBy==`string`){let e=D(n.lockedBy);return{message:`${e} is editing this document.`,fieldErrors:{},lockedBy:e}}let r=jd(n.details);return Object.keys(r).length>0?{message:`Some fields are not valid. Fix the marked fields and save again.`,fieldErrors:r}:{message:e.message||t,fieldErrors:{}}}function Pd(e,t){return e instanceof Ad?{message:e.message,fieldErrors:{[e.field]:e.message}}:e instanceof Fe?Nd(e,t):{message:e instanceof Error?e.message:t,fieldErrors:{}}}var Fd={publish:`published`,unpublish:`draft`,archive:`archived`,unarchive:`draft`},Id={unpublish:e=>`Unpublished ${e}. Visitors no longer see it.`,archive:e=>`Archived ${e}. Visitors no longer see it.`,unarchive:e=>`${e} is a draft again. Nothing is live until you publish.`};async function Ld(e,t,n){try{let r=await S(e,t,n);return n===void 0||r.meta.locale===n}catch(e){if(e instanceof Fe&&e.status===404)return!1;throw e}}async function Rd(e){let{collection:t,draft:n,newLocale:r}=e,i=e.newSlug.trim();if(!i)throw new Ad(`slug`,`A new document needs a slug.`);if(await Ld(t,i,r))throw new Ad(`slug`,`${t} already has a document at "${i}". Choose another slug.`);let a=await ee(t,{slug:i,...n,locale:r});return e.onCreated(a.slug),ia(a)}async function zd(e,t){let{collection:n,saved:r,draft:i}=e;if(!r)return Rd(e);let{slug:a,locale:o}=r.meta,s=t??e.baseVersion??r.meta.version,c=await ne(n,a,{...i,_version:s,locale:o});return e.onSaved(await Bd(e,r,c),i),ia(c)}async function Bd(e,t,n){let{slug:r,locale:i}=t.meta;try{return await S(e.collection,r,i)}catch{let r={...t.meta,version:n.version,liveVersion:n.liveVersion};return{...t,...e.draft,defaults:e.draft.defaults??t.defaults,meta:r}}}function Vd(e,t,n){return n===null||n===t?`Published ${e} · v${t} is live.`:`Published ${e} · v${t} is live, recorded as v${n}.`}async function Hd(e,t){let{collection:n,saved:r}=e;if(!r)throw Error(`Save the draft first.`);let{slug:i,locale:a,version:o}=r.meta,s=await se(n,i,{status:Fd[t],locale:a});return e.onReplaced(await S(n,i,a)),t===`publish`?Vd(i,o,s.version):Id[t](i)}function Ud(e){let[t,n]=(0,M.useState)(null),[r,i]=(0,M.useState)(null),a=fe(),o=Te(),s=(0,M.useRef)(!1);async function c(e,t,r){if(s.current)return!1;s.current=!0,n(e),i(null);let c;try{c=await t()}catch(e){return i(Pd(e,r)),!1}finally{s.current=!1,n(null)}return a({text:c}),o(),!0}return{busy:t,failure:r,save:async t=>{await c(`save`,()=>zd(e,t),`The draft could not be saved`)},changePublication:t=>c(`publish`,()=>Hd(e,t),`The change could not be made`)}}function Wd(e){let t=new URLSearchParams(e);return t.delete(ad),t.sort(),t.toString()}function Gd(e,t){return e.pathname!==t.pathname||Wd(e.search)!==Wd(t.search)}function Kd(e){let t=(0,M.useRef)(e);t.current=e;let n=(0,M.useRef)(!1),r=(0,M.useCallback)(({currentLocation:e,nextLocation:r})=>n.current||!t.current?!1:Gd(e,r),[]),i=o(r);return(0,M.useEffect)(()=>{if(!e)return;function t(e){e.preventDefault(),e.returnValue=``}return window.addEventListener(`beforeunload`,t),()=>window.removeEventListener(`beforeunload`,t)},[e]),{blocker:i,release:(0,M.useCallback)(()=>{n.current=!0},[])}}function qd(){let[e,t]=(0,M.useState)(``),[n,r]=(0,M.useState)(!1);return{value:e,onChange:(0,M.useCallback)(e=>{t(e),r(!0)},[]),suggestFrom:(0,M.useCallback)((e,r)=>{!n&&xu(e)&&typeof r==`string`&&t(bu(r))},[n])}}function Jd(e){return typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:typeof e==`string`?/^\d{4}-\d{2}-\d{2}/.test(e)?`date`:/^https?:\/\//.test(e)?`url`:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(e)?`email`:/^#[0-9a-f]{3,8}$/i.test(e)?`color`:`string`:`string`}function Yd(e,t){let[n,r]=(0,M.useState)(t),i=fe();return[n,(0,M.useCallback)(async(t,n)=>{try{await ce(e,{name:t,type:Jd(n),required:!1}),r(await x(e)),i({text:`${t} is now a field of the schema.`})}catch(e){i({text:T(e,`${t} could not be promoted`),tone:`error`})}},[e,i])]}function Xd(e,t){let{setField:n}=e,{suggestFrom:r}=t;return(0,M.useCallback)((e,t)=>{n(e,t),r(e,t)},[n,r])}function Zd(e,t){if(!t)return Cu(e.collection,e.locale);let{slug:n,locale:r}=t.meta;return Su(e.collection,n,r)}function Qd(e,t){return e.draft.dirty||e.document===null&&t.value.trim()!==``}function $d(e,t,n){let r=rt().hasRole(`editor`),i=t.document?.meta,a=kd(r&&i?{collection:e.collection,slug:i.slug,locale:i.locale}:null),o=Qd(t,n);return{canEdit:r,lock:a,autosave:hd({key:Zd(e,t.document),draft:t.draft.draft,dirty:o,opened:t.opened,context:{baseVersion:t.baseVersion??void 0,slug:t.document?void 0:n.value}}),dirty:o,guard:Kd(o)}}function ef(e,t,n,r){let i=c(),{collection:a,locale:o}=e,{release:s}=r.guard,{forget:l}=r.autosave,u=(0,M.useCallback)(e=>{l(),s();let t=ie(a,e,o);i(`${t}${t.includes(`?`)?`&`:`?`}${ad}=structure`)},[l,s,i,a,o]);return Ud({collection:a,saved:t.document,baseVersion:t.baseVersion,newLocale:o,draft:t.draft.draft,newSlug:n.value,onSaved:t.onSaved,onReplaced:t.onReplaced,onCreated:u})}function tf(e,t){return e.state===`foreign`?e.holder:e.state===`held`?null:t.failure?.lockedBy??null}function nf(e,t,n,r,i){let a=e.document?.meta;return{saved:a?{version:a.version,liveVersion:a.liveVersion}:null,dirty:t,busy:n.busy!==null,canEdit:r,lockedBy:i,rebased:a!==void 0&&e.baseVersion!==a.version,conflict:n.failure?.conflictWith!==void 0}}function rf(e,t,n){let{replace:r}=e.draft,{restoredOn:i}=e,{onChange:a}=t,{restore:o}=n;return(0,M.useCallback)(()=>{let e=o();e&&(r({fields:e.fields,body:e.body,metadata:e.metadata,defaults:e.defaults}),i(e.baseVersion),e.slug&&a(e.slug))},[o,r,i,a])}function af(e,t){let{collection:n}=t,[r,i]=Yd(n,e.schema),a=yd(e),{document:o,draft:s,onReplaced:c}=a,l=qd(),{canEdit:u,lock:d,autosave:f,dirty:p,guard:m}=$d(t,a,l),h=ef(t,a,l,{guard:m,autosave:f}),g=tf(d,h),_=rt().hasRole(`admin`),v=o===null&&h.busy===`save`,y=o?.meta,b=(0,M.useCallback)(async()=>{y&&c(await S(n,y.slug,y.locale))},[n,y,c]);return{prepareSnapshot:e=>s.replace(e),schema:r,document:o,draft:s,newSlug:l,lock:d,autosave:f,actions:h,guard:m,canEdit:u,isAdmin:_,creating:v,readOnly:!u||g!==null||v,facts:nf(a,p,h,u,g),baseVersion:a.baseVersion,openedFields:a.openedFields,setField:Xd(s,l),restoreKept:rf(a,l,f),promote:i,reloadDocument:b}}function of(e){(0,M.useEffect)(()=>{let t=document.activeElement;t&&t!==document.body||e.current?.focus()},[e])}function sf({ws:e,source:t}){let{locales:n}=t;return!e.document||!n||!re(n)?null:(0,N.jsx)(tl,{collection:e.document.meta.collection,slug:e.document.meta.slug,current:e.document.meta.locale,locales:n.supportedLocales,defaultLocale:n.defaultLocale,canCreate:e.canEdit})}function cf(e,{source:t,target:n}){let r=u(),i=n.collection===`globals`?`global`:`page`,a=e.document?.meta,o=a?sa({collection:t.collection,slug:a.slug,liveVersion:a.liveVersion,preview:e.canEdit&&h(r,`sitePreview`),baseUrl:t.site?.site.baseUrl??null}):null,s=t.collection?.pages??!1;return{kind:i,hasPage:s,modes:od(i,s),title:a?a.slug:`New ${f(n.collection)}`,siteLink:o,missingLocale:a&&n.locale&&n.locale!==a.locale?n.locale:null,showPanel:i===`page`}}function lf({ws:e,view:t,ids:n,mode:r,onMode:i,openDialog:a,source:o}){let s=e.document?.meta,c=s?{status:s.status,createdAt:s.createdAt,changedBy:s.changedBy}:null;return(0,N.jsx)(Xu,{modes:t.modes,mode:r,onMode:i,tabId:e=>`${n}-mode-${e}`,panelId:`${n}-canvas`,facts:e.facts,saving:e.actions.busy===`save`,record:c,lock:e.lock,locales:(0,N.jsx)(sf,{ws:e,source:o}),siteLink:t.siteLink,onSave:()=>void e.actions.save(),onPublish:()=>a({kind:`publish`}),onStatusChange:s&&!e.readOnly?e=>a({kind:`status`,change:e}):null})}function uf(e,t){let[n,r]=a();return[sd(n.get(ad),e,t),(0,M.useCallback)(e=>{r(t=>{let n=new URLSearchParams(t);return n.set(ad,e),n},{replace:!0})},[r])]}function df(e){let t=af(e.source,e.target),n=cf(t,e),r=e.target.slug===void 0,[i,a]=uf(n.kind,{isNew:r,hasPage:n.hasPage}),[o,s]=(0,M.useState)(null),c=(0,M.useId)(),l=(0,M.useRef)(null),u=(0,M.useRef)(null);of(l);let d=(0,M.useCallback)(()=>s(null),[]),f={...e,ws:t,view:n,ids:c,mode:i};return(0,N.jsxs)(`section`,{ref:l,className:`editor`,tabIndex:-1,"aria-labelledby":`${c}-title`,children:[(0,N.jsx)(`h1`,{id:`${c}-title`,className:`visually-hidden`,children:n.title}),(0,N.jsx)(lf,{...f,onMode:a,openDialog:s}),(0,N.jsx)(rd,{workspace:t,missingLocale:n.missingLocale,onAnswered:()=>u.current?.focus()}),n.kind===`page`&&i!==`data`&&t.document&&(0,N.jsx)(Or,{timeline:!0,collection:t.document.meta.collection,slug:t.document.meta.slug,locale:t.document.meta.locale,saved:{version:t.document.meta.version,liveVersion:t.document.meta.liveVersion},draft:t.draft.draft,unsaved:t.draft.dirty,canRestore:t.isAdmin&&!t.readOnly,onRestored:t.reloadDocument,onPrepare:t.prepareSnapshot}),(0,N.jsx)(mu,{ws:t,kind:n.kind,source:e.source,collection:e.target.collection,ids:c,mode:i,onMode:a,showPanel:n.showPanel,canvasRef:u}),(0,N.jsx)(Iu,{ws:t,hasPage:n.hasPage,dialog:o,close:d})]})}function ff(){return(0,N.jsxs)(`div`,{className:`editor`,"aria-busy":`true`,children:[(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:`Loading the document…`}),(0,N.jsx)(`div`,{className:`editor-header editor-skeleton`,"aria-hidden":`true`}),(0,N.jsx)(`div`,{className:`editor-structure editor-skeleton editor-skeleton--canvas`,"aria-hidden":`true`})]})}function pf({target:e}){let{loaded:t,reload:n}=dd(e);return t.state===`loading`?(0,N.jsx)(ff,{}):t.state===`error`?(0,N.jsx)(Me,{title:`The document could not load`,message:t.message,onRetry:n}):t.data?(0,N.jsx)(df,{source:t.data,target:e}):(0,N.jsx)(be,{})}function mf({collection:e}){let t=i(),[n]=a(),r=e??t.collection,o=n.get(`locale`)??void 0;if(!r)return(0,N.jsx)(be,{});let{slug:s}=t;return(0,N.jsx)(pf,{target:{collection:r,slug:s,locale:o}},`${r}/${s??``}/${o??``}`)}export{mf as EditorPage,$s as a,Bt as c,Qs as i,Ys as n,uo as o,Zs as r,Wa as s,Js as t};
27
+ `,Math.max(0,t)),r=G(n===-1?e:e.slice(0,n)).sections,i=r.length-1,a=r[i];return a?{kind:`section`,heading:G(e).sections[i]?.heading??a.heading,index:i}:{kind:`lead`}}function Ho(e){switch(e.kind){case`field`:return`Field · ${e.name}`;case`section`:return`Section · ${e.heading}`;case`lead`:return`Lead`;default:return`Page overview`}}function Uo(e){return e.length===1||e===`Backspace`||e===`Delete`||e===`Enter`}var Wo=`The section changed elsewhere; open it again to edit.`,Go=`The field changed elsewhere; open it again to edit.`;function Ko(e,t){if(e.kind===`field`)return{kind:`field`,name:e.name};if(e.kind===`lead`)return{kind:`lead`};let n=No(t,e.heading,e.occurrence);if(n.kind===`ambiguous`)return{kind:`section`,heading:e.heading,index:-1,ambiguous:!0};let r=n.kind===`index`?n.index:-1;return{kind:`section`,heading:G(t).sections[r]?.heading??e.heading,index:r}}function qo(e,t){return t.readOnly?!1:e.kind===`field`?oo(e.name,t.schema,t.draft)===`text`:e.kind===`lead`||No(t.draft.body,e.heading,e.occurrence).kind===`index`}function Jo(e,t){return e?.kind===`field`?t.fields[e.name]:t.body}function Yo(e,t,n){let r=t?q(t):null,i=Jo(t,e),a=(0,M.useRef)({key:r,value:i}),o=t?.kind===`field`?Go:Wo;return(0,M.useLayoutEffect)(()=>{let e=a.current;r===null||e.key!==r?a.current={key:r,value:i}:Object.is(i,e.value)||n(o)},[r,i,o,n]),(0,M.useCallback)(e=>{a.current={...a.current,value:e}},[])}function Xo(e,t){let n=e.kind===`none`;(0,M.useEffect)(()=>{n&&t()},[n,t])}function Zo(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(``);return{selected:e,setSelected:t,edit:n,setEdit:r,notice:i,setNotice:a,closeOnly:(0,M.useCallback)(e=>{r(null),a(e)},[]),clear:(0,M.useCallback)(()=>{t(null),r(null)},[])}}function Qo(e,t,n){if(!t.element)return null;if(e.kind!==`field`){let e=t.element.ownerDocument.defaultView;return e&&t.element instanceof e.HTMLElement?{element:t.element,point:t.point}:null}if(!ho(t.element))return null;let r=n.fields[e.name];return t.element.textContent===(typeof r==`string`?r:``)?{element:t.element,point:t.point}:null}function $o(e,t){return{onBody:n=>{e(n),t.onBody(n)},onField:(n,r)=>{e(r),t.onField(n,r)}}}function es(e){let t=Zo(),{selected:n,notice:r,closeOnly:i,clear:a}=t,o=t.edit?.target??null,s=(0,M.useRef)(null),c=Yo(e.draft,o,i);Xo(e.selection,a);function l(n,r,i){let a=qo(n,e);a&&i.element&&i.element===t.edit?.inPlace?.element||(t.setSelected(n),t.setNotice(``),e.onSelect(Ko(n,e.draft.body),!a),s.current=r,t.setEdit(a?{target:n,inPlace:Qo(n,i,e.draft)}:null))}function u(){a(),e.onSelect(zo)}let d=()=>{u(),s.current?.focus()},f=(0,M.useCallback)(()=>i(``),[i]);return{selected:n,editing:e.readOnly?null:o,inPlace:e.readOnly?null:t.edit?.inPlace??null,notice:r,pick:l,close:d,dismiss:u,closeFirst:f,...$o(c,e)}}function J(e){try{e()}catch{}}function ts(e){try{return e()}catch{return null}}function ns(e){let t=e;try{t=decodeURIComponent(e)}catch{}return t.length>1?t.replace(/\/+$/,``):t}function rs(e,t){return ns(e)===ns(t)}function is(e){return e.defaultView?.performance?.getEntriesByType?.(`navigation`)[0]?.responseStatus??0}function as(e,t,n){try{let r=e?.contentDocument??null;if(!r)return{kind:`unreadable`};if(r.URL===`about:blank`&&t!==`about:blank`)return{kind:`blank`};let i=new URL(r.URL).pathname,a=is(r);return r.contentType!==`text/html`||a>=400?{kind:`error`,path:i,status:a}:rs(i,n)?{kind:`page`,doc:r}:{kind:`other`,path:i}}catch{return{kind:`unreadable`}}}function os(e,t){let n=e.kind===`ready`||e.kind===`moved`;switch(t.kind){case`blank`:return e;case`page`:return e.kind===`ready`&&e.doc===t.doc?e:{kind:`ready`,doc:t.doc};case`timeout`:return e.kind===`loading`?{kind:`failed`,why:`timeout`}:e;case`unreadable`:return{kind:`failed`,why:n?`left`:`unreadable`};default:if(!n){let e=t.kind===`error`?t.status:0;return{kind:`failed`,why:`error`,path:t.path,status:e}}return e.kind===`moved`&&e.path===t.path?e:{kind:`moved`,path:t.path}}}function ss(){let e=document.activeElement;return!e||e===document.body||!e.isConnected}function cs(e,t){let n=(0,M.useRef)(!1),r=t.state.kind===`ready`?ts(()=>t.frameRef.current?.contentDocument):null;return(0,M.useEffect)(()=>{let t=t=>{let r=t.target;n.current=r instanceof Node&&(e.current?.contains(r)??!1)};document.addEventListener(`focusin`,t);let i=()=>{n.current=!0};return J(()=>r?.addEventListener(`focusin`,i)),()=>{document.removeEventListener(`focusin`,t),J(()=>r?.removeEventListener(`focusin`,i))}},[e,r]),n}function ls(e,t,n,r){let i=cs(e,t),a=`${t.reload}:${t.state.kind}:${n}`,o=(0,M.useRef)(a);(0,M.useLayoutEffect)(()=>{if(a===o.current)return;o.current=a;let n=i.current||r.current;r.current=!1,n&&ss()&&(e.current?.querySelector(`.live-moved button`)??t.frameRef.current)?.focus()},[a,i,r,e,t.frameRef]);let s=t.state.kind===`ready`;(0,M.useEffect)(()=>{let e=t.frameRef.current;s&&e&&document.activeElement===e&&J(()=>e.contentWindow?.focus())},[s,t.frameRef])}function us(e){let t=(0,M.useRef)(null);return(0,M.useEffect)(()=>{e&&ss()&&t.current?.focus()},[e]),t}function ds(e){let{title:t,detail:n,tried:r,onReload:i,onStructure:a,announce:o=!1}=e,s=us(o);return(0,N.jsx)(`div`,{className:`live-empty`,role:o?`alert`:void 0,children:(0,N.jsxs)(`div`,{className:`ui-empty-state`,children:[(0,N.jsx)(`span`,{className:`ui-empty-state-icon`,"aria-hidden":`true`,children:(0,N.jsx)(Jt,{})}),(0,N.jsx)(`h2`,{ref:s,tabIndex:-1,className:`ui-empty-state-title`,children:t}),(0,N.jsxs)(`div`,{className:`ui-empty-state-body`,children:[(0,N.jsx)(`p`,{children:n}),r&&(0,N.jsxs)(`p`,{children:[`Tried `,(0,N.jsx)(`code`,{className:`live-empty-url`,children:r})]}),(0,N.jsx)(`p`,{children:`Every field and section can still be edited in Structure mode.`})]}),(0,N.jsxs)(`div`,{className:`ui-empty-state-action`,children:[i&&(0,N.jsx)(k,{icon:Ft,onClick:i,children:`Reload the preview`}),(0,N.jsx)(k,{onClick:a,children:`Switch to Structure mode`})]})]})})}var fs=`The preview answered with an error — for example, your sign-in expired. Reload Studio and try again.`;function ps(e,t){let n=`The page preview did not load`;return t===404?{title:`The site has no page for this document`,detail:`${e} answered 404: the site’s page templates do not render this document.`}:t>=400&&t!==401&&t!==403?{title:n,detail:`${e} answered ${t}.`}:{title:n,detail:fs}}function ms(e){if(e.kind===`failed`&&e.why===`error`)return ps(e.path,e.status);let t=e.kind===`failed`?e.why:`unreadable`;if(t===`left`)return{title:`The preview left the page`,detail:`It went to a page Studio cannot read — another site, or the browser’s own error page.`};let n=`The page preview did not load`;return t===`timeout`?{title:n,detail:`The preview took too long to load.`}:{title:n,detail:`Studio cannot read the preview: it did not load, or it is not on this site’s origin.`}}function hs(e){return e.map(e=>({anchor:e,box:e.mark?ro(e.mark.element):null}))}function gs(e,t,n){let r=t===`after`?e.top+e.height:e.top,i=Math.max(0,e.left),a=n.width>0?Math.min(e.left+e.width,n.width):e.left+e.width;return{top:r,left:i,width:Math.max(0,a-i)}}function _s({placed:e,layer:t}){let n=e.filter(e=>e.box!==null);return n.length===0?null:(0,N.jsx)(`div`,{className:`live-placeholder-markers`,"aria-hidden":`true`,children:n.map(({anchor:e,box:n})=>(0,N.jsx)(`div`,{className:`live-placeholder-marker`,"data-section":e.name,style:gs(n,e.side,t),children:(0,N.jsx)(`span`,{className:`live-placeholder-marker-tag`,children:`${e.name} · not written`})},e.name))})}function vs(e){return e.neighbour?`${e.side} ${e.neighbour}`:null}function ys({placed:e,readOnly:t,onAdd:n}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`live-missing`,"aria-label":`Designed sections not written`,children:e.map(({anchor:e})=>(0,N.jsxs)(`li`,{className:`live-placeholder`,"data-section":e.name,children:[(0,N.jsxs)(`p`,{children:[e.name,` is in this page's section contract but hasn't been written. The page leaves it out.`,vs(e)&&(0,N.jsxs)(`span`,{className:`live-placeholder-at`,children:[` In the page: `,vs(e),`.`]})]}),(0,N.jsx)(k,{size:`sm`,icon:Se,disabled:t,"aria-label":`Add section ${e.name}`,onClick:()=>n(e.name),children:`Add section`})]},e.name))})}var bs=5e3,xs=50;function Ss(e,t){let n,r=null;J(()=>{let i=e.defaultView;i&&(r=new i.MutationObserver(()=>{n??=setTimeout(()=>{n=void 0,t()},xs)}),r.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Aa,ja,Ma]}))});let i=setTimeout(()=>J(()=>r?.disconnect()),bs);return()=>{clearTimeout(i),n!==void 0&&clearTimeout(n),J(()=>r?.disconnect())}}function Y(e,t,n,r={}){return J(()=>e?.addEventListener(t,n,r)),()=>J(()=>e?.removeEventListener(t,n,r))}function Cs(e){let t=e;return t.detail>0?{x:t.clientX,y:t.clientY}:null}function ws(e,t){let n=null,r=()=>e.stillThere();return{over:i=>{if(!r())return;let a=to(i.target,e.documentId);a!==n&&(n=a,e.events.current.onHover(a?t(a):null))},leave:()=>{n=null,e.events.current.onHover(null)},click:n=>{if(!r()||n.target?.closest?.(`.live-markdown-root`))return;let i=to(n.target,e.documentId),a=i?t(i):null;a?(n.preventDefault(),n.stopPropagation(),e.events.current.onPick(a,Cs(n))):e.events.current.onOutsideClick()},key:t=>{t.key===`Escape`&&e.events.current.onEscape()}}}function Ts(e){let t=[],n=()=>{e.stillThere()&&(J(()=>{t=Za(e.doc,e.documentId)}),e.onMarks(t),e.moved())},r=e=>t.find(t=>t.element===e)||(n(),t.find(t=>t.element===e)??null);n();let i=ws(e,r),a=ts(()=>e.doc.defaultView),o=ts(()=>e.doc.documentElement),s=[Ss(e.doc,n),Y(e.doc,`mouseover`,i.over),Y(o,`mouseleave`,i.leave),Y(e.doc,`click`,i.click,{capture:!0}),Y(e.doc,`keydown`,i.key),Y(e.doc,`scroll`,e.moved,{capture:!0,passive:!0}),Y(a,`resize`,e.moved),Y(window,`resize`,e.moved)];return{rescan:n,detach:()=>{for(let e of s)e()}}}var Es=2e4,Ds=500;function Os(e){let t=null;return{notify:()=>{t??=requestAnimationFrame(()=>{t=null,e()})},cancel:()=>{t!==null&&cancelAnimationFrame(t)}}}function ks(e,t){(0,M.useEffect)(()=>{if(e===null)return;let n=setTimeout(t,Es);return()=>clearTimeout(n)},[e,t])}var As={kind:`loading`};function js(e,t){let{src:n,path:r,reload:i}=e,[a,o]=(0,M.useState)({reload:i,state:As}),s=(0,M.useRef)(i);s.current=i;let c=a.reload===i?a.state:As,l=(0,M.useCallback)(e=>{o(t=>{let n=t.reload===s.current?t.state:As;return{reload:s.current,state:os(n,e)}})},[]),u=(0,M.useCallback)(()=>l({kind:`timeout`}),[l]);return ks(c.kind===`loading`?i:null,u),[c,l,(0,M.useCallback)(()=>l(as(t.current,n,r)),[l,t,n,r])]}function Ms(e,t){let{src:n,path:r,documentId:i,body:a,reload:o}=e,s=(0,M.useRef)(null),[c,l,u]=js(e,s),d=(0,M.useCallback)(()=>as(s.current,n,r),[n,r]),f=(0,M.useRef)([]),p=(0,M.useRef)(a);p.current=a;let m=(0,M.useRef)(t);m.current=Ns(t,()=>Mo(f.current,p.current));let h=Is({state:c,documentId:i,events:m,look:d,see:l,raw:f});Ps(c,s,d,l);let g=(0,M.useMemo)(()=>Mo(h.marks,a),[h.marks,a]);return{src:n,reload:o,frameRef:s,state:c,onLoad:u,rescan:h.rescan,marks:g}}function Ns(e,t){let n=e=>t().find(t=>t.element===e.element)??e;return{onHover:t=>e.onHover(t&&n(t)),onPick:(t,r)=>e.onPick(n(t),r),onEscape:e.onEscape,onOutsideClick:e.onOutsideClick}}function Ps(e,t,n,r){let i=e.kind===`moved`;(0,M.useEffect)(()=>{if(!i)return;let e=()=>r(n()),a=setInterval(e,Ds),o=Y(ts(()=>t.current?.contentWindow),`popstate`,e);return()=>{clearInterval(a),o()}},[i,t,n,r])}function Fs(e,t,n){return()=>{let r=t();return r.kind===`page`&&r.doc===e||(n(r),!1)}}function Is(e){let{state:t,documentId:n,events:r,look:i,see:a,raw:o}=e,[s,c]=(0,M.useState)([]),[,l]=(0,M.useState)(0),u=(0,M.useRef)(()=>void 0);return(0,M.useEffect)(()=>{if(t.kind!==`ready`){o.current=[],c([]);return}let e=Os(()=>l(e=>e+1)),s=Fs(t.doc,i,a),d=Ts({doc:t.doc,documentId:n,events:r,onMarks:e=>{o.current=e,c(e)},moved:e.notify,stillThere:s});u.current=d.rescan;let f=setInterval(s,Ds);return()=>{clearInterval(f),u.current=()=>void 0,d.detach(),e.cancel()}},[t,n,r,i,a,o]),{marks:s,rescan:(0,M.useCallback)(()=>u.current(),[])}}var Ls=20,Rs=7;function zs(e,t,n){return Math.max(t,Math.min(e,n))}function Bs(e,t){return e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height}function Vs(e,t,n,r=null){let i=zs(-e.top,0,Math.max(0,e.height-Ls)),a=e.top>=Ls?-20:i,o=e.top+e.height+Ls<=t.height?e.height:i,s=Math.min(n.length*Rs+16,t.width),c=zs(e.left,0,Math.max(0,t.width-s)),l=[a,i,o].find(t=>r===null||!Bs({top:e.top+t,left:c,width:s,height:Ls},r));return l===void 0?null:{top:l,left:c-e.left,maxWidth:Math.max(s,t.width-c)}}function Hs(e,t){let n=t.width-16;return!e||n<=0?null:Math.min(Math.max(e.width,360),n)}function Us(e,t,n,r=!1){let i=r?Hs(e,t):null,a=t.height-16,o=zs(e?.left??8,8,t.width-8-(i??n.width));if(a>0&&n.height>a)return{top:8,left:o,maxHeight:a,width:i};if(!e||a<=0)return{top:8,left:o,maxHeight:null,width:i};let s=t.height-8-n.height,c=e.top+e.height+8,l=e.top-8-n.height;return{top:zs(c<=s?c:l>=8?l:c,8,s),left:o,maxHeight:null,width:i}}function Ws(e,t,n){let r=Math.max(0,t.width-16),i=r>0?Math.min(Math.max(e?.width??n.width,200),r):null,a=Us(e,t,{...n,width:i??n.width});if(!e||t.height<=0)return{...a,width:i};let o=e.top+e.height+5,s=o+n.height<=t.height-8;return{...a,top:s?Math.max(8,o):a.top,width:i}}function Gs(e){let t=`live-outline`;return e===`hovered`?t:e===`selected`?`${t} ${t}--selected`:`${t} ${t}--selected ${t}--editing`}function Ks({target:e,elements:t,designed:n,state:r,layer:i,avoid:a}){let o=t.map(ro).filter(e=>e!==null),s=io(e,n),c=Gs(r);return(0,N.jsx)(N.Fragment,{children:o.map((e,t)=>(0,N.jsx)(`div`,{className:c,style:{top:e.top,left:e.left,width:e.width,height:e.height},children:t===0&&r!==`editing`&&(0,N.jsx)(qs,{box:e,layer:i,text:s,avoid:a})},t))})}function qs(e){let t=Vs(e.box,e.layer,e.text,e.avoid);return t?(0,N.jsx)(`span`,{className:`live-tag`,title:e.text,style:t,children:e.text}):null}function Js(e){if(e.kind===`lead`)return`Introduction`;if(e.kind===`section`)return`${e.heading} section`;if(e.name===`title`)return`Page title`;let t=e.name.replace(/[-_]+/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Ys(e){return e.kind===`field`?`Edit field ${e.name}`:e.kind===`lead`?`Edit the lead`:`Edit section ${e.heading}`}function Xs({props:e,id:t}){let{target:n,draft:r,schema:i,elements:a,onField:o,onPatched:s}=e;if(n.kind!==`field`)return null;let c=r.fields[n.name],l=typeof c==`string`?c:``,u=e=>{o(n.name,e),co(a,e),s()};return so(n.name,i)?(0,N.jsx)(`textarea`,{id:t,className:`editor-control editor-control--area`,rows:3,value:l,onChange:e=>u(e.target.value)}):(0,N.jsx)(`input`,{id:t,className:`editor-control`,value:l,onChange:e=>u(e.target.value)})}function Zs(e,t){if(e.kind===`lead`)return Ua(t);let n=Po(t,e);return n===null?null:Ha(t,n)}function Qs(e){let[t,n]=(0,M.useState)({width:0,height:0}),[,r]=(0,M.useState)(0);return(0,M.useLayoutEffect)(()=>{let r=e.current;if(!r)return;let i=r.offsetHeight-r.clientHeight,a={width:r.offsetWidth,height:r.scrollHeight+i};(a.width!==t.width||a.height!==t.height)&&n(a)}),(0,M.useEffect)(()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>r(e=>e+1));return n.observe(t),()=>n.disconnect()},[e]),t}function $s(e,t){let{elements:n,stage:r,onPlaced:i}=e,a=(0,M.useRef)(null),o=n[0],s=o?ro(o):null,c={width:r?.clientWidth??0,height:r?.clientHeight??0},l=e.target.kind!==`field`,u=e.toolbar?Ws(s,c,t):Us(s,c,t,l),d=s||!a.current?u:a.current;a.current=d;let f=d.maxHeight??t.height,p=d.width??t.width;return(0,M.useLayoutEffect)(()=>{i({top:d.top,left:d.left,width:p,height:f})},[i,d.top,d.left,p,f]),(0,M.useLayoutEffect)(()=>()=>i(null),[i]),d}function ec(e){let t=(0,M.useId)(),n=(0,M.useRef)(null),{target:r,onClose:i}=e;(0,M.useEffect)(()=>{n.current?.querySelector(`input, textarea, button`)?.focus()},[]);let a=$s(e,Qs(n));function o(e){e.key===`Escape`&&(e.preventDefault(),i())}let s={top:a.top,left:a.left,width:a.width??void 0,maxHeight:a.maxHeight??void 0};return(0,N.jsxs)(`div`,{ref:n,className:`live-editor`,style:s,onKeyDown:o,children:[(0,N.jsx)(`label`,{htmlFor:t,className:`live-editor-label`,children:Ys(r)}),(0,N.jsx)(Xs,{props:e,id:t}),(0,N.jsxs)(`div`,{className:`live-editor-actions`,children:[(0,N.jsx)(`span`,{className:`side-note`,children:`Saved with the draft.`}),(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:i,children:`Done`})]})]})}function tc(e){let t=(0,M.useRef)(null),n={kind:`field`,name:e.name},r=$s({...e,target:n,elements:[e.element],toolbar:!0},Qs(t)),i=(0,M.useRef)(e);i.current=e;let{name:a,element:o,multiline:s,point:c}=e,l=(0,M.useRef)(o.textContent??``);return(0,M.useEffect)(()=>Do(o,{label:Ys({kind:`field`,name:a}),multiline:s,point:c,onText:e=>{let{elements:t,onField:n,onPatched:r}=i.current;n(a,e),co(t.filter(e=>e!==o),e),r()},onClose:()=>i.current.onClose(),onDismiss:()=>{t.current?.contains(document.activeElement)||i.current.onDismiss()}}),[a,o,s,c]),(0,N.jsxs)(`fieldset`,{ref:t,className:`live-context`,"aria-label":`Editing ${Js(n)}`,style:{top:r.top,left:r.left,width:r.width??void 0,maxHeight:r.maxHeight??void 0},onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),e.onClose())},onBlur:t=>{if(t.currentTarget.contains(t.relatedTarget))return;let n=o.ownerDocument.defaultView?.frameElement;(t.relatedTarget!==n||o.ownerDocument.activeElement!==o)&&e.onDismiss()},children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`strong`,{children:Js(n)}),(0,N.jsx)(`span`,{className:`side-note`,children:`Draft`})]}),(0,N.jsxs)(`div`,{className:`live-context-actions`,children:[(0,N.jsx)(A,{icon:Ee,label:`Cancel this element’s edit`,className:`live-context-cancel`,size:`sm`,onPointerDown:e=>e.preventDefault(),onClick:()=>{e.onField(a,l.current),co(e.elements,l.current),e.onPatched(),e.onClose()}}),(0,N.jsx)(A,{icon:Ie,label:`Done editing`,className:`live-context-done`,size:`sm`,onPointerDown:e=>e.preventDefault(),onClick:e.onClose})]})]})}var nc=(0,M.lazy)(()=>t(()=>import(`./live-markdown-editor-DSsCNBWR.js`).then(e=>({default:e.LiveMarkdownEditor})),__vite__mapDeps([31,1,0,8,4,5,9,10,11,12,13,14,15,16,32,33,34,6,35,36,37,26])));function rc(e){let{frame:t,body:n,designed:r,hovered:i,selected:a,placed:o,size:s,editor:c,inPlace:l}=e,u=(e,t,n)=>(0,N.jsx)(Ks,{target:e,elements:t,designed:r,state:n,layer:s,avoid:c});return(0,N.jsxs)(`div`,{className:`live-layer`,"aria-hidden":`true`,children:[(0,N.jsx)(_s,{placed:o,layer:s}),i&&!(l&&a&&q(i.target)===q(a))&&u(i.target,[i.element],`hovered`),a&&u(a,Fo(t.marks,a,n),l?`editing`:`selected`)]})}function ic(e){return{width:e?.clientWidth??0,height:e?.clientHeight??0}}function ac(e,t){return e===null||t===null?e===t:e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height}function oc(){let[e,t]=(0,M.useState)(null);return[e,(0,M.useCallback)(e=>{t(t=>ac(t,e)?t:e)},[])]}function sc({props:e,frame:t,editing:n,target:r,stage:i,onPlaced:a}){let{draft:o,schema:s}=e,c=Fo(t.marks,r,o.body),l=n.inPlace?.element,u=l&&c.includes(l)?[l,...c.filter(e=>e!==l)]:c,d={onField:n.onField,onPatched:t.rescan,onClose:n.close};if(r.kind===`field`&&n.inPlace){let{element:e,point:t}=n.inPlace,o=so(r.name,s),c=n.dismiss;return(0,N.jsx)(tc,{stage:i,onPlaced:a,...d,name:r.name,element:e,elements:u,multiline:o,point:t,onDismiss:c},q(r))}return r.kind===`field`?(0,N.jsx)(ec,{...d,target:r,elements:u,stage:i,schema:s,draft:o,onPlaced:a,onBody:n.onBody},q(r)):(0,N.jsx)(M.Suspense,{fallback:(0,N.jsx)(`span`,{className:`live-loading`,role:`status`,children:`Loading editor…`}),children:(0,N.jsx)(nc,{...d,target:r,elements:u,stage:i,schema:s,draft:o,onPlaced:a,onBody:n.onBody},q(r))})}function cc({props:e,frame:t,title:n,hovered:r,editing:i,placed:a}){let o=(0,M.useRef)(null),[s,c]=oc(),{draft:l,designed:u}=e,d=t.state.kind,f=d===`ready`||d===`loading`?i.editing:null,p={frame:t,body:l.body,designed:u,hovered:r,placed:a,editor:s,inPlace:f!==null&&(i.inPlace!==null||f.kind!==`field`)},m={ref:t.frameRef,title:n,src:t.src,onLoad:t.onLoad};return(0,N.jsxs)(`div`,{ref:o,className:`live-stage`,children:[(0,N.jsx)(`iframe`,{className:`live-frame`,...m},t.reload),d===`ready`&&(0,N.jsx)(rc,{...p,selected:i.selected,size:ic(o.current)}),f&&(0,N.jsx)(sc,{props:e,frame:t,editing:i,target:f,stage:o.current,onPlaced:c})]})}function lc(e,t,n){(0,M.useEffect)(()=>{n(e.kind===`ready`?ao(t):null)},[e,t,n]),(0,M.useEffect)(()=>()=>n(null),[n])}function uc(e,t,n){t.closeFirst();let r=Ra(e.draft.body,e.designed,n);e.onBody(r.body),e.onSelect({kind:`section`,heading:n,index:r.index},!0)}function dc(e,t){let{src:n,path:r,documentId:i,draft:a,reload:o}=e,[s,c]=(0,M.useState)(null),l=es(e),u=Ms({src:n,path:r,documentId:i,body:a.body,reload:o},{onHover:c,onPick:(e,t)=>l.pick(e.target,u.frameRef.current,{element:e.element,point:t}),onEscape:l.dismiss,onOutsideClick:l.dismiss});(0,M.useEffect)(()=>{if(!l.editing)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.live-editor, .live-context`)||t===u.frameRef.current||l.dismiss())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[l.editing,l.dismiss,u.frameRef]),lc(u.state,u.marks,e.onFound);let d=u.state.kind===`moved`||u.state.kind===`failed`,f=l.inPlace?.element,p=f!==void 0&&!u.marks.some(e=>e.element===f),{closeFirst:m}=l;return(0,M.useEffect)(()=>{(d||p)&&m()},[d,p,m]),ls(t,u,l.editing!==null,e.focusRequested),{editing:l,frame:u,hovered:u.state.kind===`ready`&&s&&u.marks.some(e=>e.element===s.element)?s:null}}function fc(e){let{src:t,documentId:n,designed:r,draft:i,onReload:a,onStructure:o}=e,s=(0,M.useRef)(null),{editing:c,frame:l,hovered:u}=dc(e,s);if(l.state.kind===`failed`){let e=ms(l.state);return(0,N.jsx)(ds,{...e,tried:t,onReload:a,onStructure:o,announce:!0})}let d=hs(l.state.kind===`ready`?Lo(i.body,r,l.marks):[]),f=`Draft preview of ${n}`;return(0,N.jsxs)(`div`,{ref:s,className:`live-mode`,children:[(0,N.jsx)(wa,{frame:l,onReload:a}),(0,N.jsx)(`p`,{className:`live-notice side-note`,role:`status`,children:c.notice}),(0,N.jsx)(cc,{props:e,frame:l,title:f,editing:c,placed:d,hovered:u}),(0,N.jsx)(ys,{placed:d,readOnly:e.readOnly,onAdd:t=>uc(e,c,t)})]})}function pc(e){let[t,n]=(0,M.useState)(0),r=(0,M.useRef)(e),i=(0,M.useRef)(!1);return(0,M.useEffect)(()=>{r.current!==null&&e!==r.current&&n(e=>e+1),r.current=e},[e]),{reload:t,onReload:(0,M.useCallback)(()=>{i.current=!0,n(e=>e+1)},[]),focusRequested:i}}function mc(e){let t=pc(e.savedVersion),{preview:n,slug:r,onStructure:i}=e;if(n.src===null||r===null){let e=n.src===null?n.title:`The document has no page yet`,t=n.src===null?n.detail:`Save it first.`;return(0,N.jsx)(ds,{title:e,detail:t,onStructure:i})}return(0,N.jsx)(fc,{...e,...t,src:n.src,path:n.path,documentId:Xa(e.collection,r)})}function hc(e,t){return{src:null,title:e,detail:t}}function gc(e){let{collection:t,slug:n,locale:r,defaultLocale:i,sitePreview:a,canEdit:o}=e;if(n===null)return hc(`The document has no page yet`,`Save it first.`);if(!a)return hc(`The site does not render drafts for editors`,`Live mode needs the site’s draft preview (sitePreview).`);if(!o)return hc(`Your role cannot open the draft preview.`,`The preview is for editors.`);if(r===null||r!==i)return hc(`The site’s preview has no locale`,`Live mode previews the site’s default-locale page; the site’s preview has no locale. Edit ${r??`this version`} in Structure mode.`);let s=sa({collection:t,slug:n,liveVersion:null,preview:!0,baseUrl:null}),c=t?xe(t,n):null;return s?.kind!==`preview`||c===null?hc(`This collection renders no pages`,`There is no page to show.`):{src:s.href,path:c}}function _c({ws:e,slot:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(``),[c,l]=(0,M.useState)(``),[u,d]=(0,M.useState)(null),[f,p]=(0,M.useState)(!1),[m,h]=(0,M.useState)(null),g=e.document?.meta,v=e.schema.contract.metadata[t];if(!g||!v)return null;async function y(e){p(!0),h(null);try{await e()}catch(e){h(T(e,`Shared defaults could not be read`))}finally{p(!1)}}async function b(e){if(s(e),l(``),d(null),!e){a([]);return}let t=await _(e,{locale:g?.locale});a(t.items)}async function ee(n){if(!g||e.draft.dirty)return;let r=await Ne(`/content/${encodeURIComponent(g.collection)}/${encodeURIComponent(g.slug)}/defaults`,{method:`POST`,body:JSON.stringify({sourceCollection:o,slots:[t],sourceSlug:c,locale:g.locale,apply:n,_version:u?.version??g.version,sourceVersion:u?.sourceVersion})});n?(d(null),await e.reloadDocument()):d(r)}return(0,N.jsxs)(`details`,{className:`metadata-defaults`,onToggle:e=>{e.currentTarget.open&&!n.length&&y(async()=>r(await oe()))},children:[(0,N.jsx)(`summary`,{children:`Copy from another page`}),(0,N.jsx)(`p`,{children:`Review details to copy from a shared document. Saved snapshots keep their copied values.`}),e.draft.dirty&&(0,N.jsx)(`p`,{children:`Save your draft before applying shared defaults.`}),(0,N.jsxs)(`fieldset`,{disabled:e.readOnly||f||e.draft.dirty,className:`metadata-defaults-fields`,children:[(0,N.jsxs)(`label`,{children:[`Source collection`,(0,N.jsxs)(`select`,{className:`editor-control`,value:o,onChange:e=>{y(()=>b(e.target.value))},children:[(0,N.jsx)(`option`,{value:``,children:`Choose collection`}),n.map(e=>(0,N.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,N.jsxs)(`label`,{children:[`Source document`,(0,N.jsxs)(`select`,{className:`editor-control`,value:c,onChange:e=>l(e.target.value),children:[(0,N.jsx)(`option`,{value:``,children:`Choose document`}),i.map(e=>(0,N.jsx)(`option`,{value:e.meta.slug,children:String(e.fields.title??e.meta.slug)},e.meta.slug))]})]}),(0,N.jsx)(k,{size:`sm`,disabled:!c,onClick:()=>{y(()=>ee(!1))},children:`Review defaults`})]}),m&&(0,N.jsx)(`p`,{role:`alert`,children:m}),u&&(0,N.jsxs)(w,{title:`Review shared defaults`,onClose:()=>d(null),actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:()=>d(null),children:`Cancel`}),(0,N.jsx)(k,{disabled:f||e.readOnly||e.draft.dirty||!u.paths.length,onClick:()=>{y(()=>ee(!0))},children:`Apply to draft`})]}),children:[(0,N.jsx)(`p`,{children:u.paths.length?`${u.paths.length} ${u.paths.length===1?`value`:`values`} will be copied from snapshot v${u.sourceVersion}. Your authored overrides stay.`:`No missing or inherited values need updating.`}),m&&(0,N.jsx)(`p`,{role:`alert`,children:m}),(0,N.jsx)(U,{contract:{...e.schema.contract,metadata:{[t]:v}},metadata:u.metadata[t]?{[t]:u.metadata[t]}:{},fields:e.draft.draft.fields,readOnly:!0,errors:{},onMetadata:()=>{}})]})]})}function vc(e,t){return e===0?`missing`:e<t.minChars?`under`:e>t.maxChars?`over`:`within`}function yc(e,t){return e===0?`missing`:e>t?`over`:`within`}var bc={missing:`muted`,under:`ahead`,within:`live`,over:`danger`};function xc(e,t,n){return{segments:[{value:e,tone:bc[t]}],max:Math.max(n,e)}}function Sc(e,t){switch(e){case`missing`:return`none`;case`under`:return`under the target`;case`over`:return t===`range`?`over the target`:`over the limit`;default:return t===`range`?`within the target`:`within the limit`}}function Cc(e,t,n,r){let i=r.has(`meta-description`)?`meta-description`:null,a=[];if(e.source===null){let e=i??(r.has(`description`)?`description`:null);a.push({text:`No meta description: search engines pick text from the page.`,field:e})}if(e.source===`description`&&a.push(i?{text:`Search results show the description. Write a meta description of its own.`,field:i}:{text:`Search results show the description: this collection has no meta-description field.`,field:null}),t===`over`&&e.source){let t=`The meta description is ${e.text.length} characters; search results cut it near ${n.maxChars}.`;a.push({text:t,field:r.has(e.source)?e.source:null})}return a}function wc(e){return e.kind===`range`?`target ${e.min}–${e.max}`:`limit ${e.max}`}function Tc({label:e,length:t,state:n,target:r,note:i}){let{segments:a,max:o}=xc(t,n,r.max);return(0,N.jsxs)(`div`,{className:`side-length side-length--${n}`,"data-length-state":n,children:[(0,N.jsxs)(`div`,{className:`side-length-head`,children:[(0,N.jsx)(`span`,{className:`side-length-label`,children:e}),(0,N.jsxs)(`span`,{className:`side-length-figure`,children:[t,` chars · `,wc(r)]})]}),(0,N.jsx)(at,{segments:a,max:o}),(0,N.jsx)(`span`,{className:`side-length-state`,children:Sc(n,r.kind)}),i&&(0,N.jsx)(`span`,{className:`side-length-note`,children:i})]})}function X({title:e,summary:t,children:n}){let r=(0,M.useId)();return e===void 0?(0,N.jsxs)(`div`,{className:`side-card`,children:[t&&(0,N.jsx)(`div`,{className:`side-card-head`,children:t}),n]}):(0,N.jsxs)(`section`,{className:`side-card`,"aria-labelledby":r,children:[(0,N.jsxs)(`div`,{className:`side-card-head`,children:[(0,N.jsx)(`h3`,{id:r,className:`side-card-title`,children:e}),t]}),n]})}function Z({label:e,children:t}){return(0,N.jsxs)(`div`,{className:`side-fact`,children:[(0,N.jsx)(`dt`,{children:e}),(0,N.jsx)(`dd`,{children:t})]})}function Q({children:e}){return(0,N.jsx)(`p`,{className:`side-note`,children:e})}function Ec(e){let[t,n]=(0,M.useState)({state:`loading`});return(0,M.useEffect)(()=>{let t=!0;return n({state:`loading`}),$e(e).then(e=>t&&n({state:`ready`,item:e})).catch(()=>t&&n({state:`missing`})),()=>{t=!1}},[e]),[t,e=>n({state:`ready`,item:e})]}function Dc({item:e,disabled:t,onReplaced:n}){let r=(0,M.useRef)(null),{busy:i,run:a}=Ue(e,n);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{ref:r,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&a(t)}}),(0,N.jsx)(k,{size:`sm`,icon:We,disabled:t||i,onClick:()=>r.current?.click(),children:i?`Replacing…`:`Replace`})]})}function Oc({item:e,disabled:t,onSaved:n}){let r=(0,M.useId)(),[i,a]=(0,M.useState)(e.altText);(0,M.useEffect)(()=>a(e.altText),[e.altText]);let{busy:o,run:s}=ze(e,n),c=o||i===e.altText;return(0,N.jsxs)(`div`,{className:`side-field`,children:[(0,N.jsx)(`label`,{htmlFor:r,className:`side-field-label`,children:`Alt text`}),(0,N.jsx)(`input`,{id:r,className:`editor-control`,value:i,disabled:t,"aria-describedby":`${r}-note`,onChange:e=>a(e.target.value)}),(0,N.jsx)(`p`,{id:`${r}-note`,className:`side-note`,children:`Saved on the media file at once, for every page that uses it — not in this draft.`}),(0,N.jsx)(kc,{disabled:t,unchanged:c,busy:o,onSave:()=>void s(i)})]})}function kc(e){return(0,N.jsx)(k,{size:`sm`,disabled:e.disabled,"aria-disabled":e.unchanged,onClick:e.unchanged?void 0:e.onSave,children:e.busy?`Saving…`:`Save alt text`})}function Ac({id:e,readOnly:t}){return h(u(),`media`)?t?(0,N.jsx)(k,{size:`sm`,icon:Ve,disabled:!0,children:`Crop & hotspot`}):(0,N.jsxs)(s,{to:b(e),className:Re(`secondary`,`sm`),children:[(0,N.jsx)(Ve,{className:`ui-button-icon`,"aria-hidden":`true`}),`Crop & hotspot`]}):null}function jc({id:e,readOnly:t}){let[n,r]=Ec(e);if(n.state===`loading`)return(0,N.jsx)(Q,{children:`Reading the media file…`});if(n.state===`missing`)return(0,N.jsxs)(Q,{children:[`Media `,e,` was not found.`]});let{item:i}=n;return(0,N.jsxs)(`div`,{className:`side-media`,children:[(0,N.jsx)(`p`,{className:`side-media-name`,children:i.filename}),(0,N.jsxs)(`div`,{className:`side-actions`,children:[(0,N.jsx)(Ac,{id:i.id,readOnly:t}),(0,N.jsx)(Dc,{item:i,disabled:t,onReplaced:r})]}),(0,N.jsx)(Q,{children:`Replacing keeps the id, so pages update without a content change.`}),(0,N.jsx)(Oc,{item:i,disabled:t,onSaved:r},i.id)]})}function Mc(e){return Object.keys(e.schema.properties??{})}function Nc(e,t){return e.seoReadsFields?Fn(Mc(e.schema)).get(t)??`No SEO output`:`Nothing: SEO does not read this document`}function Pc(e,t,n){if(!t.fields.has(n))return`Not found marked by Live mode`;let r=oo(n,e.schema,e.draft);return r===`media`?`Found by Live mode; media changes after Save`:e.readOnly?`Found by Live mode; read-only`:r===`other`?`Found by Live mode; not a text field: edit it in Structure mode`:`Found by Live mode: editable in place`}function Fc(e,t){return t===e?`Search results show this field.`:t===null?`Neither meta-description nor description is set.`:e===`description`?`The fallback: search results show meta-description while it is set.`:`Empty, so search results fall back to description.`}function Ic({doc:e,name:t,limits:n}){let{fields:r}=e.draft;if(t===`meta-description`||t===`description`){let e=Lt(r),{minChars:i,maxChars:a}=n.metaDescription;return(0,N.jsx)(Tc,{label:`Meta description, effective`,length:e.text.length,state:vc(e.text.length,n.metaDescription),target:{kind:`range`,min:i,max:a},note:Fc(t,e.source)})}if(L(Mc(e.schema)).title!==t)return null;let i=r[t],a=typeof i==`string`?i.length:0;return(0,N.jsx)(Tc,{label:`Title`,length:a,state:yc(a,n.title.maxChars),target:{kind:`limit`,max:n.title.maxChars}})}function Lc({doc:e,name:t}){let n=e.draft.fields[t],r=typeof n==`string`?n:``;return r?(0,N.jsx)(jc,{id:r,readOnly:e.readOnly}):(0,N.jsx)(Q,{children:`No file chosen. Choose one in the form.`})}function Rc({doc:e,name:t}){let n=(e.schema.schema.properties??{})[t],r=(e.schema.schema.required??[]).includes(t);return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{children:r?`required`:`optional`}),children:[(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Type`,children:n?(0,N.jsx)(`code`,{children:An(n,t)}):`Not in the schema (custom field)`}),(0,N.jsx)(Z,{label:`Required`,children:r?`Yes`:`No`}),(0,N.jsx)(Z,{label:`Read by`,children:Nc(e,t)}),e.live&&(0,N.jsx)(Z,{label:`On the page`,children:Pc(e,e.live,t)})]}),e.seoReadsFields&&e.limits&&(0,N.jsx)(Ic,{doc:e,name:t,limits:e.limits}),n&&R(n,t)===`media`&&(0,N.jsx)(Lc,{doc:e,name:t})]})}function zc({doc:e,onSelect:t}){let n=e.schema.schema.properties??{},r=Object.keys(n).filter(e=>!wn.has(e));return(0,N.jsxs)(X,{title:`Fields`,children:[(0,N.jsx)(Q,{children:`The form is read-only. Choose a field to see what reads it.`}),(0,N.jsx)(`ul`,{className:`side-rows`,"aria-label":`Fields`,children:r.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:()=>t({kind:`field`,name:e}),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsx)(`span`,{className:`side-row-state`,children:An(n[e]??{},e)})]})},e))})]})}var Bc=[];function Vc({found:e,onSelect:t}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:()=>t({kind:`section`,...e}),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e.heading}),` `,(0,N.jsxs)(`span`,{className:`side-row-state`,children:[(0,N.jsx)(E,{className:`side-row-icon side-row-icon--present`,"aria-hidden":`true`}),`present`]})]})})}function Hc({name:e,readOnly:t,onAdd:n}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row side-row--missing`,disabled:t,onClick:()=>n(e),children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsxs)(`span`,{className:`side-row-state`,children:[(0,N.jsx)(Se,{className:`side-row-icon`,"aria-hidden":`true`}),`Add section`]})]})})}function Uc({row:e,readOnly:t,onSelect:n,onAdd:r}){return e.found?(0,N.jsx)(Vc,{found:e.found,onSelect:n}):(0,N.jsx)(Hc,{name:e.name,readOnly:t,onAdd:r})}function Wc({name:e,state:t,onClick:n}){return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`side-row`,onClick:n,children:[(0,N.jsx)(`span`,{className:`side-row-name`,children:e}),` `,(0,N.jsx)(`span`,{className:`side-row-state`,children:t})]})})}function Gc({parts:e,readOnly:t,onSelect:n,onAdd:r}){return(0,N.jsxs)(`ul`,{className:`side-rows`,"aria-label":`Sections`,children:[e.lead!==``&&(0,N.jsx)(Wc,{name:`Lead`,state:`before first ##`,onClick:()=>n({kind:`lead`})}),e.designed.map(e=>(0,N.jsx)(Uc,{row:e,readOnly:t,onSelect:n,onAdd:r},e.name)),e.prose.map(e=>(0,N.jsx)(Wc,{name:e.heading,state:`prose`,onClick:()=>n({kind:`section`,...e})},`${e.index}-${e.heading}`))]})}function Kc({doc:e,onSelect:t}){let n=e.info?.sections??Bc,{body:r}=e.draft,i=(0,M.useMemo)(()=>Na(r,n),[r,n]);function a(i){let a=Ra(r,n,i);e.onBody(a.body),t({kind:`section`,heading:i,index:a.index})}let o=(0,N.jsx)(O,{tone:`accent`,children:`${i.present} / ${n.length} designed`});return(0,N.jsxs)(X,{title:`Page & sections`,summary:o,children:[n.length===0&&(0,N.jsx)(Q,{children:`The page template designs no sections, so each renders as prose.`}),(0,N.jsx)(Gc,{parts:i,readOnly:e.readOnly,onSelect:t,onAdd:a})]})}function qc(e,t){let{collection:n,slug:r,defaultLocale:i}=e;return ie(n,r,t===i?void 0:t)}function Jc(e,t,n){let[r,i]=(0,M.useState)(!1),[a,o]=(0,M.useState)(null),s=c(),l=fe(),u=t.toUpperCase();async function d(){i(!0),o(null);try{await n(t),l({text:`${u} draft created from ${e.defaultLocale.toUpperCase()}.`}),s(qc(e,t))}catch(e){o(T(e,`The ${u} draft could not be created`)),i(!1)}}return{busy:r,error:a,confirm:d}}function Yc({busy:e,confirmRef:t,onCancel:n,onConfirm:r}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{onClick:e?void 0:n,"aria-disabled":e,children:`Cancel`}),(0,N.jsx)(k,{ref:t,variant:`primary`,onClick:e?void 0:r,"aria-disabled":e,children:e?`Creating…`:`Create draft`})]})}function Xc({locale:e,props:t,create:n,onClose:r}){let{busy:i,error:a,confirm:o}=Jc(t,e,n),s=(0,M.useRef)(null),c=e.toUpperCase(),l=(0,N.jsx)(Yc,{busy:i,confirmRef:s,onCancel:r,onConfirm:()=>void o()});return(0,N.jsxs)(w,{title:`Create the ${c} draft of ${t.slug}?`,onClose:i?()=>void 0:r,initialFocus:s,busy:i,actions:l,children:[(0,N.jsxs)(`p`,{children:[`Copies the `,t.defaultLocale.toUpperCase(),` version's fields and body into a new `,c,` `,`draft with its own history. Nothing is published.`]}),a&&(0,N.jsx)(`p`,{className:`editor-modal-error`,role:`alert`,children:a})]})}function Zc({locale:e,note:t}){let n=e.toUpperCase();return(0,N.jsxs)(`span`,{className:C(`neutral`,`editor-locale editor-locale--quiet`),title:t,"data-locale":e,children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,children:n}),(0,N.jsxs)(`span`,{className:`visually-hidden`,children:[n,`: `,t]})]})}function Qc({locale:e,onCreate:t}){let n=e.toUpperCase();return(0,N.jsxs)(`button`,{type:`button`,"data-locale":e,className:C(`neutral`,`editor-locale editor-locale--missing`),"aria-label":`Create ${n} draft`,onClick:t,children:[(0,N.jsx)(Se,{className:`ui-chip-icon`,"aria-hidden":`true`}),n]})}function $c({props:e,locale:t,state:n,onCreate:r}){let i=t.toUpperCase(),a=t===e.current;return!a&&n===void 0?(0,N.jsx)(Zc,{locale:t,note:`checking`}):!a&&n===`unknown`?(0,N.jsx)(Zc,{locale:t,note:`whether this version exists could not be checked`}):!a&&n===`missing`?e.canCreate?(0,N.jsx)(Qc,{locale:t,onCreate:r}):null:(0,N.jsx)(s,{to:qc(e,t),className:C(a?`accent`:`neutral`,`editor-locale`),"aria-current":a?`true`:void 0,"aria-label":`${i} version`,"data-locale":t,children:i})}function el(e,t){let[n,r]=(0,M.useState)(null);return(0,M.useEffect)(()=>{if(t!==null||n===null)return;r(null);let i=document.activeElement;if(i&&i!==document.body&&i.isConnected)return;let a=e.current?.querySelector(`[data-locale="${n}"]`);(a&&a.tabIndex>=0?a:e.current)?.focus()},[t,n,e]),r}function tl(e){let{collection:t,slug:n,locales:r,defaultLocale:i}=e,a=Rt(t,n,r,i),[o,s]=(0,M.useState)(null),c=(0,M.useRef)(null),l=el(c,o);if(r.length<2)return null;let u=e=>{l(e),s(null)};return(0,N.jsxs)(`div`,{ref:c,className:`editor-locales`,role:`group`,"aria-label":`Locales`,tabIndex:-1,children:[r.map(t=>(0,N.jsx)($c,{props:e,locale:t,state:a.states?.get(t),onCreate:()=>s(t)},t)),o&&(0,N.jsx)(Xc,{locale:o,props:e,create:a.create,onClose:()=>u(o)})]})}function nl({target:e,locale:t,current:n,status:r,versions:i,canCreate:a,onCreate:o}){let c=t.toUpperCase(),l=n?`exists`:i.states?.get(t);return(0,N.jsxs)(`li`,{className:`side-locale`,"data-locale":t,children:[l===`exists`?(0,N.jsx)(s,{to:qc(e,t),"aria-current":n?`true`:void 0,children:c}):(0,N.jsx)(`span`,{className:`side-locale-name`,children:c}),(0,N.jsx)(rl,{state:l,status:r}),l===`missing`&&a&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Create draft in ${c}`,onClick:o,children:`Create draft`})]})}function rl({state:e,status:t}){return e===`exists`&&t?(0,N.jsxs)(`span`,{className:`side-locale-state`,children:[(0,N.jsx)(ke,{status:t,decorative:!0}),ge[t]]}):(0,N.jsx)(`span`,{className:`side-locale-state side-locale-state--quiet`,children:e===`missing`?`Missing`:e===`unknown`?`Could not be checked`:`Checking…`})}function il({meta:e,locales:t,versions:n,canCreate:r,onCreate:i}){let a={collection:e.collection,slug:e.slug,defaultLocale:t.defaultLocale};return(0,N.jsx)(`ul`,{className:`side-locales`,"aria-label":`Locales`,children:t.supportedLocales.map(t=>{let o=t===e.locale;return(0,N.jsx)(nl,{target:a,locale:t,current:o,status:o?te(e):n.statuses?.get(t)??null,versions:n,canCreate:r,onCreate:()=>i(t)},t)})})}function al({meta:e,locales:t,canCreate:n}){let{supportedLocales:r,defaultLocale:i}=t,a=Rt(e.collection,e.slug,r,i),[o,s]=(0,M.useState)(null);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(il,{meta:e,locales:t,versions:a,canCreate:n,onCreate:s}),o&&(0,N.jsx)(Xc,{locale:o,props:{collection:e.collection,slug:e.slug,defaultLocale:i},create:a.create,onClose:()=>s(null)})]})}function ol({meta:e}){let t=fa(e.collection,e.slug,e.locale);return t.state===`loading`?(0,N.jsx)(Q,{children:`Reading what publishing refreshes…`}):t.state===`error`?(0,N.jsx)(Q,{children:`What publishing refreshes could not be read.`}):(0,N.jsxs)(`div`,{className:`side-refreshes`,children:[(0,N.jsx)(`p`,{className:`side-subtitle`,children:`Publishing refreshes`}),(0,N.jsx)(pa,{impact:t.impact})]})}function sl({doc:e}){let{meta:t,locales:n}=e;return t?(0,N.jsxs)(X,{title:`Reach`,children:[n?(0,N.jsx)(al,{meta:t,locales:n,canCreate:e.canEdit}):(0,N.jsx)(Q,{children:`The site's locales could not be read.`}),e.info?.pages&&(0,N.jsx)(ol,{meta:t})]}):(0,N.jsx)(X,{title:`Reach`,children:(0,N.jsx)(Q,{children:`Save the page first: its locale versions follow.`})})}var cl={document:{},site:{}};async function ll(e){try{return ui(await Li(e))}catch{return{}}}function ul(e,t){let[n,r]=(0,M.useState)(cl),i=Pr();return(0,M.useEffect)(()=>{let n=!0;return Promise.all([t===null?Promise.resolve({}):ll(`doc:${e}/${t}`),ll(`site`)]).then(([e,t])=>{n&&r({document:e,site:t})}),()=>{n=!1}},[e,t,i]),n}function dl(e){let{collection:t,slug:n,fields:r}=e,i=ul(t,n);return si({fields:r,slug:n??``,pageUrl:null,documentSeo:i.document,siteSeo:i.site,siteName:``}).social.image}function fl(e){let t=Sn(e.draft.metadata).description;return typeof t==`string`&&t.trim()?{text:t,source:`metadata`}:Lt(e.draft.fields)}function pl(e,t){let n=Sn(e.draft.metadata),r=n.headline??n.name;return typeof r==`string`&&r.trim()?r:Cn(L(t),`title`,e.draft.fields)}function ml(e){return[...new Set([...Mc(e.schema),...Object.keys(e.draft.fields)])]}function hl(e){let{meta:t,limits:n,label:r}=e,{minChars:i,maxChars:a}=n.metaDescription,o=t.source===`metadata`?`Your own search description`:t.source===`description`?`Falls back to description`:t.source===null?`Neither meta-description nor description is set`:`From meta-description`;return(0,N.jsx)(Tc,{label:r,length:t.text.length,state:vc(t.text.length,n.metaDescription),target:{kind:`range`,min:i,max:a},note:o})}function gl(e){let{title:t,limits:n,label:r}=e;return(0,N.jsx)(Tc,{label:r,length:t.length,state:yc(t.length,n.title.maxChars),target:{kind:`limit`,max:n.title.maxChars}})}function _l({doc:e}){let t=dl({collection:e.collection,slug:e.meta?.slug??null,fields:{...e.draft.fields,...Sn(e.draft.metadata)}});return(0,N.jsx)(Z,{label:`Social image`,children:t?(0,N.jsxs)(N.Fragment,{children:[`Set `,(0,N.jsx)(`code`,{children:t})]}):`None`})}function vl({advice:e,readOnly:t,onEditField:n}){return e.length===0?null:(0,N.jsx)(`ul`,{className:`side-advice`,children:e.map(e=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{children:e.text}),e.field&&!t&&(0,N.jsx)(`button`,{type:`button`,className:`side-link`,"aria-label":`Edit ${e.field}`,onClick:()=>e.field&&n(e.field),children:`Edit`})]},e.text))})}function yl({doc:e,limits:t,names:n,onEditField:r}){let i=fl(e),a=new Set(Mc(e.schema)),o=vc(i.text.length,t.metaDescription);return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(hl,{meta:i,limits:t,label:`Meta description`}),(0,N.jsx)(gl,{title:pl(e,n),limits:t,label:`Title`}),(0,N.jsx)(vl,{advice:Cc(i,o,t.metaDescription,a),readOnly:e.readOnly,onEditField:r})]})}function bl(e,t){let n=e.draft.metadata.sharing?.image!==void 0;return{description:(0,N.jsx)(hl,{meta:fl(e),limits:t,label:`Length`}),title:(0,N.jsx)(gl,{title:pl(e,ml(e)),limits:t,label:`Length`}),image:n?void 0:(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(_l,{doc:e})})}}function xl(e){let{doc:t,onEditField:n,renderFields:r}=e,i=h(u(),`seo`)&&(t.info?.pages??!0)?t.limits:null;if(r){let e=r(i?bl(t,i):{});if(e)return e}return i?(0,N.jsxs)(X,{title:`Search and sharing`,children:[(0,N.jsx)(yl,{doc:t,limits:i,names:ml(t),onEditField:n}),(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(_l,{doc:t})})]}):null}var Sl=`Not in the contract. Rename it to a contract heading to get the designed layout, or keep it as prose.`;function Cl({doc:e,heading:t}){let n=(0,M.useId)(),r=Ja(t),i=e.draft.fields[r],a=typeof i==`string`?i:``,o=e.limits?.metaDescription;return(0,N.jsxs)(`div`,{className:`side-field`,children:[(0,N.jsxs)(`div`,{className:`side-field-head`,children:[(0,N.jsx)(`label`,{htmlFor:n,className:`side-field-label`,children:(0,N.jsx)(`code`,{children:r})}),(0,N.jsx)(`span`,{className:`side-field-optional`,children:`optional`})]}),(0,N.jsx)(`textarea`,{id:n,className:`editor-control editor-control--area`,rows:3,value:a,disabled:e.readOnly,"aria-describedby":`${n}-note`,onChange:t=>e.onField(r,t.target.value||void 0)}),(0,N.jsx)(`p`,{id:`${n}-note`,className:`side-note`,children:`This section's own meta description, for a section with its own URL. Saved with the draft.`}),o&&a!==``&&(0,N.jsx)(Tc,{label:`Length`,length:a.length,state:vc(a.length,o),target:{kind:`range`,min:o.minChars,max:o.maxChars}})]})}function wl({doc:e,heading:t,index:n}){let r=Ga(e.draft.body,t,n);if(!r)return(0,N.jsx)(X,{children:(0,N.jsx)(Q,{children:`This section is no longer in the body.`})});let i=K(t,e.info?.sections??[]);return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{tone:i?`accent`:`neutral`,children:i?`designed`:`prose`}),children:[(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Key`,children:(0,N.jsx)(`code`,{children:Ya(t)})}),(0,N.jsx)(Z,{label:`Words`,children:qa(r.section.markdown)})]}),!i&&(0,N.jsx)(Q,{children:Sl}),Object.hasOwn(e.schema.schema.properties??{},Ja(t))&&(0,N.jsx)(Cl,{doc:e,heading:t})]})}function Tl({doc:e,heading:t}){let n=K(t,e.info?.sections??[]);return(0,N.jsx)(X,{summary:(0,N.jsx)(O,{tone:n?`accent`:`neutral`,children:n?`designed`:`prose`}),children:(0,N.jsxs)(`dl`,{className:`side-facts`,children:[(0,N.jsx)(Z,{label:`Key`,children:(0,N.jsx)(`code`,{children:Ya(t)})}),(0,N.jsx)(Z,{label:`On the page`,children:`This heading appears more than once in the body: edit it in Structure mode.`})]})})}function El({doc:e}){return(0,N.jsxs)(X,{summary:(0,N.jsx)(O,{children:`before first ##`}),children:[(0,N.jsx)(`dl`,{className:`side-facts`,children:(0,N.jsx)(Z,{label:`Words`,children:qa(Ka(e.draft.body))})}),(0,N.jsx)(Q,{children:`The markdown before the first ## heading.`})]})}function Dl(e){let{doc:t,control:n,onEditField:r,onOpenData:i}=e,{selection:a}=n,o=e=>n.select(e,!0),s=e.mode!==`structure`,c=e.mode!==`live`,l={contract:t.schema.contract,metadata:t.draft.metadata,fields:t.draft.fields,onOpenData:i?e.onOpenGraph??i:null,groupActions:e.groupActions,defaults:t.defaults,readOnly:t.readOnly,errors:t.fieldErrors,onMetadata:t.onMetadata};switch(a.kind){case`field`:return(0,N.jsx)(Rc,{doc:t,name:a.name});case`section`:return a.ambiguous?(0,N.jsx)(Tl,{doc:t,heading:a.heading}):(0,N.jsx)(wl,{doc:t,heading:a.heading,index:a.index});case`lead`:return(0,N.jsx)(El,{doc:t});default:return(0,N.jsxs)(N.Fragment,{children:[s&&(0,N.jsx)(U,{scope:`metadata`,...l,system:t.meta}),(0,N.jsx)(xl,{doc:t,onEditField:r,renderFields:s?e=>(0,N.jsx)(U,{scope:`sharing`,checks:e,...l}):null}),t.readOnly&&t.meta&&(0,N.jsx)(zc,{doc:t,onSelect:o}),c&&(0,N.jsx)(Kc,{doc:t,onSelect:o}),c&&(0,N.jsx)(sl,{doc:t})]})}}function Ol(e){let t=(0,M.useRef)(null);return(0,M.useEffect)(()=>{e>0&&t.current?.focus()},[e]),t}function kl(e){let[t,n]=(0,M.useState)(``),r=(0,M.useRef)(!0);return(0,M.useEffect)(()=>{r.current?r.current=!1:n(`Side panel: ${e}`)},[e]),t}function Al(e){let{control:t}=e,n=Ho(t.selection),r=Ol(t.focusTick),i=kl(n),a=t.selection.kind!==`none`;function o(e){e.key===`Escape`&&!e.defaultPrevented&&a&&(e.preventDefault(),t.select(zo,!0))}return(0,N.jsxs)(`aside`,{id:e.id,className:`side-panel`,"aria-label":`Side panel`,onKeyDown:o,children:[(0,N.jsxs)(`div`,{className:`side-panel-head`,children:[(0,N.jsx)(`h2`,{ref:r,tabIndex:-1,className:`side-panel-title`,children:n}),a&&(0,N.jsx)(k,{size:`sm`,variant:`ghost`,icon:It,onClick:()=>t.select(zo,!0),children:`Page overview`}),(0,N.jsx)(A,{id:`${e.id}-hide`,icon:Xt,label:`Hide side panel`,size:`sm`,"aria-expanded":`true`,"aria-controls":e.id,onClick:e.onCollapse})]}),(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:i}),(0,N.jsx)(`div`,{className:`side-panel-body`,children:(0,N.jsx)(Dl,{...e})})]})}function jl(){let[e,t]=(0,M.useState)(zo),[n,r]=(0,M.useState)(0);return{selection:e,select:(0,M.useCallback)((e,n)=>{t(t=>Bo(t,e)?t:e),n&&r(e=>e+1)},[]),focusTick:n}}function Ml(e){return typeof e==`string`?e:JSON.stringify(e)}function Nl({props:e,name:t,value:n}){let r=`${e.idPrefix}-custom-${t}`;return(0,N.jsxs)(`div`,{className:`editor-field editor-custom-field`,children:[(0,N.jsxs)(`div`,{className:`editor-field-head`,children:[(0,N.jsx)(`label`,{className:`editor-field-label`,htmlFor:r,children:t}),(0,N.jsx)(`span`,{className:`editor-field-optional`,children:`custom`})]}),(0,N.jsxs)(`div`,{className:`editor-custom-line`,children:[(0,N.jsx)(`input`,{id:r,type:`text`,className:`editor-control`,value:Ml(n),onChange:n=>e.onChange(t,n.target.value)}),e.canPromote&&(0,N.jsx)(k,{size:`sm`,"aria-label":`Promote ${t} to a schema field`,onClick:()=>e.onPromote(t,n),children:`Promote`})]})]})}function Pl(e){let t=(0,M.useId)();return e.entries.length===0?null:(0,N.jsxs)(`section`,{className:`editor-custom-fields`,"aria-labelledby":t,children:[(0,N.jsx)(`h2`,{id:t,className:`editor-subtitle`,children:`Custom fields`}),(0,N.jsxs)(`p`,{className:`editor-note`,children:[`Not in the collection's schema.`,e.canPromote&&` Promote one to add it to the schema.`]}),e.entries.map(([t,n])=>(0,N.jsx)(Nl,{props:e,name:t,value:n},t))]})}function Fl({pill:e,seoUse:t}){return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:C(`neutral`,`editor-field-pill`),children:[(0,N.jsx)(`span`,{className:`visually-hidden`,children:`type `}),e]}),t&&(0,N.jsxs)(`span`,{className:C(`accent`,`editor-field-pill`),children:[(0,N.jsx)(en,{className:`ui-chip-icon`,"aria-hidden":`true`}),(0,N.jsx)(`span`,{className:`visually-hidden`,children:`used for search as `}),t]})]})}function Il({id:e,labelId:t,name:n,required:r,pill:i,seoUse:a,isGroup:o}){return(0,N.jsxs)(`div`,{className:`editor-field-head`,children:[(0,N.jsxs)(o?`span`:`label`,{id:t,className:`editor-field-label`,...o?{}:{htmlFor:e},children:[n,r&&(0,N.jsx)(`span`,{className:`editor-field-required`,"aria-hidden":`true`,children:`*`})]}),!r&&(0,N.jsx)(`span`,{className:`editor-field-optional`,children:`optional`}),(0,N.jsx)(Fl,{pill:i,seoUse:a})]})}function Ll(e,t,n){return[t?`${e}-help`:null,n?`${e}-error`:null].filter(Boolean).join(` `)||void 0}function Rl({id:e,help:t,error:n}){return(0,N.jsxs)(N.Fragment,{children:[t&&(0,N.jsx)(`p`,{id:`${e}-help`,className:`editor-field-help`,children:t}),n&&(0,N.jsx)(`p`,{id:`${e}-error`,className:`editor-field-error`,children:n})]})}function zl(e){if(e.property.type===`object`||e.property.type===`array`&&e.property.items?.type!==`string`)return(0,N.jsx)(H,{name:e.name,path:`fields.${e.name}`,property:e.property,value:e.value,required:e.required,errors:e.error?{[`fields.${e.name}`]:e.error}:{},onValue:t=>e.onChange(e.name,t)});let{idPrefix:t,name:n,property:r,value:i,required:a,seoUse:o,error:s,onChange:c}=e,l=R(r,n),u=cr[l],d=`${t}-${n}`,f=`${d}-label`,p=jn(r);return(0,N.jsxs)(`div`,{className:s?`editor-field editor-field--invalid`:`editor-field`,"data-field":n,children:[(0,N.jsx)(Il,{id:d,labelId:f,name:n,required:a,pill:An(r,n),seoUse:o,isGroup:l===`media`}),(0,N.jsx)(u,{id:d,labelId:f,name:n,property:r,value:i,required:a,describedBy:Ll(d,p,s),invalid:s!==void 0,onChange:c}),(0,N.jsx)(Rl,{id:d,help:p,error:s})]})}function Bl(e,t){let[n,r]=(0,M.useState)(``);return(0,M.useEffect)(()=>{if(!t)return;let n=!0;return Promise.resolve(Ye.parse(e)).then(e=>{n&&r(Xe.sanitize(e))}).catch(()=>{n&&r(``)}),()=>{n=!1}},[e,t]),n}function Vl(e){if(!e)return{};let t=t=>{let n=t.currentTarget;e(n.value,n.selectionStart)};return{onSelect:t,onClick:t,onFocus:t}}function Hl({view:e,own:t,label:n,onView:r}){let i=e===t;return(0,N.jsx)(`button`,{type:`button`,className:`editor-body-toggle`,"aria-pressed":i,onClick:()=>r(i?`write`:t),children:n})}function Ul({headingId:e,hintId:t,view:n,onView:r}){return(0,N.jsxs)(`div`,{className:`editor-body-head`,children:[(0,N.jsx)(`h2`,{id:e,className:`editor-body-title`,children:`Body`}),(0,N.jsxs)(`span`,{id:t,className:`editor-body-hint`,children:[`markdown · `,(0,N.jsx)(`code`,{children:`##`}),` headings become sections`]}),(0,N.jsxs)(`span`,{className:`editor-body-views`,children:[(0,N.jsx)(Hl,{view:n,own:`split`,label:`Split`,onView:r}),(0,N.jsx)(Hl,{view:n,own:`preview`,label:`Preview`,onView:r})]})]})}function Wl({html:e}){return(0,N.jsx)(`div`,{className:`editor-body-preview`,children:(0,N.jsx)(`div`,{dangerouslySetInnerHTML:{__html:e}})})}function Gl({headingId:e,hintId:t,props:n}){let{value:r,onChange:i,disabled:a,onCaret:o}=n;return(0,N.jsx)(`textarea`,{className:`editor-body-textarea`,"aria-labelledby":e,"aria-describedby":t,value:r,rows:20,spellCheck:!1,disabled:a,...Vl(o),onChange:e=>{i(e.target.value),o?.(e.target.value,e.target.selectionStart)}})}function Kl(e){let[t,n]=(0,M.useState)(`write`),r=Bl(e.value,t!==`write`),i=(0,M.useId)(),a=(0,M.useId)();return(0,N.jsxs)(`section`,{className:`editor-body`,"aria-labelledby":i,children:[(0,N.jsx)(Ul,{headingId:i,hintId:a,view:t,onView:n}),(0,N.jsxs)(`div`,{className:t===`split`?`editor-body-panes editor-body-panes--split`:`editor-body-panes`,children:[t!==`preview`&&(0,N.jsx)(Gl,{headingId:i,hintId:a,props:e}),t!==`write`&&(0,N.jsx)(Wl,{html:r})]})]})}function ql(e,t){if(!(e instanceof Element))return null;let n=e.closest(`[data-field]`)?.getAttribute(`data-field`)??null;return n===`slug`&&t?null:n}function Jl(e){let t=t=>{let n=ql(t.target,e.newSlug);n&&e.onSelectField?.(n)};return{onFocus:t,onClick:t,onKeyUp:e=>{Uo(e.key)&&t(e)}}}var Yl={type:`string`,description:`Part of the page's address: lowercase words joined by hyphens, suggested from the title.`};function Xl({idPrefix:e,slug:t,error:n}){return(0,N.jsx)(zl,{idPrefix:e,name:`slug`,property:Yl,value:t.value,required:!0,seoUse:null,error:n,onChange:(e,n)=>t.onChange(typeof n==`string`?n:``)})}function Zl(e){let{schema:t,kind:n,openedFields:r}=e;return(0,M.useMemo)(()=>{let e=Object.keys(t.schema.properties??{}).filter(e=>!wn.has(e));return n===`global`?e.filter(e=>r.includes(e)):e},[t,n,r])}function Ql(e,t){return(0,M.useMemo)(()=>t?Fn(Object.keys(e.schema.properties??{})):new Map,[t,e])}function $l({props:e,idPrefix:t}){let{schema:n,draft:r,fieldErrors:i,onField:a}=e,o=Zl(e),s=Ql(n,e.seoReadsFields),c=n.schema.properties??{},l=new Set(n.schema.required??[]);return o.map(e=>(0,N.jsx)(zl,{idPrefix:t,name:e,property:c[e]??{},value:r.fields[e],required:l.has(e),seoUse:s.get(e)??null,error:i[e],onChange:a},e))}function eu(e){let{schema:t,draft:n,newSlug:r,readOnly:i}=e,a=(0,M.useId)(),o=t.schema.properties??{},s=Object.entries(n.fields).filter(([e])=>!(e in o)&&!wn.has(e));return(0,N.jsxs)(`div`,{className:`editor-structure`,children:[(0,N.jsxs)(`fieldset`,{className:`editor-structure-fields`,disabled:i,...Jl(e),children:[(0,N.jsx)(`legend`,{className:`visually-hidden`,children:`Fields`}),r&&(0,N.jsx)(Xl,{idPrefix:a,slug:r,error:e.fieldErrors.slug}),(0,N.jsx)($l,{props:e,idPrefix:a}),(0,N.jsx)(Pl,{idPrefix:a,entries:s,onChange:e.onField,onPromote:(t,n)=>{e.onPromote(t,n).then(()=>{document.getElementById(`${a}-${t}`)?.focus()})},canPromote:e.canPromote})]}),t.contract.body===`none`&&n.body.length>0&&(0,N.jsxs)(`div`,{role:`alert`,children:[(0,N.jsx)(`p`,{children:`This content form has no text body. Remove the text before saving.`}),(0,N.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>e.onBody(``),children:`Remove the text body`})]}),e.kind===`page`&&(t.contract.body!==`none`||n.body.length>0)&&(0,N.jsx)(Kl,{value:n.body,onChange:e.onBody,disabled:i,onCaret:e.onCaret}),(0,N.jsx)(U,{contract:t.contract,metadata:n.metadata,fields:n.fields,defaults:e.defaults,groupActions:e.groupActions,onOpenData:e.onOpenData,readOnly:i,errors:e.fieldErrors,onMetadata:e.onMetadata})]})}var tu=`krantho-studio-panel`,nu={min:300,max:640,fallback:380};function ru(){let{collapsed:e,width:t}=le(tu);return{collapsed:e===!0,width:Oe(t,nu,nu.fallback)}}function iu(){let[e,t]=he(tu,ru),n=(0,M.useCallback)(e=>t(t=>({...t,...e})),[t]);return{...e,setCollapsed:(0,M.useCallback)(e=>n({collapsed:e}),[n]),setWidth:(0,M.useCallback)(e=>n({width:e}),[n])}}function au(e){return e.readOnly?e.creating?`Creating the document…`:e.canEdit?`Read-only: ${e.facts.lockedBy??`Someone else`} is editing. Saving and publishing wait until they finish or the lock expires.`:`Read-only: your role can view documents but not edit them.`:null}function ou(e){let t=document.activeElement;return!t||t===document.body||t.matches(`:disabled`)||!!e?.closest(`.editor-canvas`)?.contains(t)}function su(e,t){let[n,r]=(0,M.useState)(!1),i=(0,M.useRef)(e);return(0,M.useEffect)(()=>{i.current&&!e&&r(!0),e&&r(!1),i.current=e},[e]),(0,M.useEffect)(()=>r(!1),[t]),n}function cu({ws:e}){let t=au(e),n=su(e.facts.lockedBy!==null,e.draft.draft),r=(0,M.useRef)(null),i=(0,M.useRef)(e.readOnly);(0,M.useEffect)(()=>{let t=e.readOnly!==i.current;i.current=e.readOnly,t&&!e.creating&&ou(r.current)&&r.current?.focus()},[e.readOnly,e.creating]);let a=t??(n?`Editing is open again.`:null);return(0,N.jsxs)(`p`,{ref:r,role:`status`,tabIndex:-1,className:a?`editor-readonly`:`editor-readonly editor-readonly--empty`,children:[t&&(0,N.jsx)(de,{className:`editor-notice-icon`,"aria-hidden":`true`}),n&&!t&&(0,N.jsx)(Kt,{className:`editor-notice-icon`,"aria-hidden":`true`}),a]})}function lu(e){let{ws:t,source:n,collection:r,control:i,onMode:a,onFound:o}=e,s=u(),c=t.document?.meta,l=c?.slug??null,d=gc({collection:n.collection,slug:l,locale:c?.locale??null,defaultLocale:n.locales?.defaultLocale??null,sitePreview:h(s,`sitePreview`),canEdit:t.canEdit});return(0,N.jsx)(mc,{preview:d,collection:r,slug:l,schema:t.schema,draft:t.draft.draft,designed:n.collection?.sections??[],readOnly:t.readOnly,savedVersion:c?.version??null,selection:i.selection,onField:t.setField,onBody:t.draft.setBody,onSelect:i.select,onFound:o,onStructure:()=>a(`structure`)})}function uu(e){let{ws:t,kind:n,mode:r,source:i,control:a}=e,{select:o}=a,s=u(),{document:c,draft:l}=t,d=i.collection?.pages??!1;return r===`live`?(0,N.jsx)(lu,{...e}):r===`data`?(0,N.jsx)(Qi,{ws:t,source:i,initialGraphOpen:e.initialGraphOpen}):r===`where`?(0,N.jsx)(xa,{ws:t}):(0,N.jsx)(eu,{kind:n,schema:t.schema,draft:l.draft,openedFields:t.openedFields,newSlug:c?null:t.newSlug,readOnly:t.readOnly,fieldErrors:t.actions.failure?.fieldErrors??{},seoReadsFields:n===`page`&&d&&h(s,`seo`),canPromote:t.isAdmin&&!t.readOnly,onField:t.setField,onBody:l.setBody,onMetadata:l.setMetadata,defaults:c?.defaults,groupActions:e=>(0,N.jsx)(_c,{ws:t,slot:e}),onOpenData:e.onOpenGraph,onPromote:t.promote,onSelectField:e=>o({kind:`field`,name:e}),onCaret:(e,t)=>o(Vo(e,t))})}function du(e,t,n,r,i){return{collection:n,info:t.collection,schema:e.schema,onMetadata:e.draft.setMetadata,defaults:e.document?.defaults??[],fieldErrors:e.actions.failure?.fieldErrors??{},draft:e.draft.draft,meta:e.document?.meta??null,limits:t.site?.seo.limits??null,locales:t.locales,readOnly:e.readOnly,canEdit:e.canEdit,seoReadsFields:r,live:i,onField:e.setField,onBody:e.draft.setBody}}function fu(e,t){(e?.querySelector(`[data-field="${t.replace(/["\\]/g,`\\$&`)}"]`))?.querySelector(`input, textarea, select, button`)?.focus()}function pu(e){let{mode:t,onMode:n,ids:r,canvasRef:i}=e,a=(0,M.useRef)(null);(0,M.useEffect)(()=>{t===`structure`&&a.current!==null&&(fu(i.current,a.current),a.current=null)},[t,i]);let o=(0,M.useCallback)(e=>{t===`structure`?fu(i.current,e):(a.current=e,n(`structure`))},[t,n,i]),s=(0,M.useCallback)(()=>{n(`data`),requestAnimationFrame(()=>document.getElementById(`${r}-mode-data`)?.focus())},[n,r]);return{editField:o,openData:t===`data`?null:s}}function mu(e){let{ws:t,ids:n,mode:r,showPanel:i,canvasRef:a}=e,o=jl(),s=pu(e),[c,l]=(0,M.useState)(!1);(0,M.useEffect)(()=>{r!==`data`&&l(!1)},[r]);let d=()=>{l(!0),e.onMode(`data`)},[f,p]=(0,M.useState)(null),m=h(u(),`seo`)&&e.kind===`page`&&(e.source.collection?.pages??!1),g=r===`live`?f:null,_=du(t,e.source,e.collection,m,g);function v(e){e.key!==`Escape`||e.defaultPrevented||e.currentTarget.contains(e.target)&&o.select(zo)}let y=iu(),b=`${n}-panel`;function ee(e){y.setCollapsed(e),requestAnimationFrame(()=>document.getElementById(`${b}-${e?`show`:`hide`}`)?.focus())}let x=[`editor-columns`];return i?y.collapsed&&x.push(`editor-columns--collapsed`):x.push(`editor-columns--single`),(0,N.jsxs)(`div`,{className:x.join(` `),style:{"--panel-width":`${y.width}px`},children:[(0,N.jsxs)(`div`,{ref:a,id:`${n}-canvas`,role:`tabpanel`,"aria-labelledby":`${n}-mode-${r}`,className:`editor-canvas`,tabIndex:-1,onKeyDown:v,children:[(0,N.jsx)(cu,{ws:t}),(0,N.jsx)(uu,{...e,control:o,onFound:p,initialGraphOpen:c,onOpenGraph:d})]}),i&&y.collapsed&&(0,N.jsx)(A,{id:`${b}-show`,className:`editor-panel-show`,icon:Qt,label:`Show side panel`,"aria-expanded":`false`,onClick:()=>ee(!1)}),i&&!y.collapsed&&(0,N.jsxs)(`div`,{className:`editor-side`,children:[(0,N.jsx)(De,{label:`Resize side panel`,value:y.width,min:nu.min,max:nu.max,grows:`left`,onChange:y.setWidth,onReset:()=>y.setWidth(nu.fallback),controls:b}),(0,N.jsx)(Al,{id:b,onCollapse:()=>ee(!0),doc:_,mode:r,control:o,onEditField:s.editField,onOpenData:s.openData,onOpenGraph:d,groupActions:e=>(0,N.jsx)(_c,{ws:t,slot:e})})]})]})}function hu(e){return JSON.stringify(e,(e,t)=>{if(typeof t!=`object`||!t||Array.isArray(t))return t;let n=Object.entries(t);return Object.fromEntries(n.sort(([e],[t])=>e.localeCompare(t)))})??`undefined`}function $(e,t){return hu(e)===hu(t)}function gu(e,t){return e.body===t.body&&$(e.fields,t.fields)&&$(e.metadata,t.metadata)&&$(e.defaults??[],t.defaults??[])}function _u(e,t,n){let r={},i=new Set([...Object.keys(n.fields),...Object.keys(e.fields)]);for(let a of i){let i=$(e.fields[a],t.fields[a])?n.fields[a]:e.fields[a];i!==void 0&&(r[a]=i)}let a=e.body===t.body?n.body:e.body,o=vu(e.metadata,t.metadata,n.metadata),s=$(e.defaults??[],t.defaults??[])?n.defaults:e.defaults;return{fields:r,body:a,metadata:o,...s?.length?{defaults:s}:{}}}function vu(e,t,n){let r={};for(let i of new Set([...Object.keys(n),...Object.keys(e)])){if($(e[i],t[i])){n[i]!==void 0&&(r[i]=n[i]);continue}if(!e[i])continue;let a={};for(let r of new Set([...Object.keys(n[i]??{}),...Object.keys(e[i]??{})])){let o=$(e[i]?.[r],t[i]?.[r])?n[i]?.[r]:e[i]?.[r];o!==void 0&&(a[r]=o)}r[i]=a}return r}var yu=[`title`,`name`];function bu(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function xu(e){return yu.includes(e)}function Su(e,t,n){return`krantho-autosave-${e}-${t}-${n}`}function Cu(e,t){let n=`krantho-autosave-new-${e}`;return t?`${n}-${t}`:n}function wu(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.savedAt==`string`&&t.metadata!==null&&typeof t.metadata==`object`&&!Array.isArray(t.metadata)&&typeof t.body==`string`&&t.fields!==null&&typeof t.fields==`object`&&!Array.isArray(t.fields)}function Tu(e){try{let t=localStorage.getItem(e);if(!t)return null;let n=JSON.parse(t);return wu(n)?n:null}catch{return null}}function Eu(e,t,n={},r=new Date){try{let i={...t,...n,savedAt:r.toISOString()};return localStorage.setItem(e,JSON.stringify(i)),!0}catch{return!1}}function Du(e){try{localStorage.removeItem(e)}catch{}}function Ou(){let e=`krantho-autosave-probe`;try{return localStorage.setItem(e,`1`),localStorage.removeItem(e),!0}catch{return!1}}function ku(e,t,n){return!e||n&&typeof e.baseVersion!=`number`?!1:!gu(e,t)||!!e.slug}function Au(e,t){return e.baseVersion===void 0||t===null?null:e.baseVersion===t?`made on v${e.baseVersion}`:`made on v${e.baseVersion} — the document is now v${t}`}function ju(e,t){let n=`Your changes to ${e} are not saved.`;return t===`kept`?`${n} They stay in this browser and are offered back when you open it again.`:t===`offer-pending`?`${n} They are not kept: changes from an earlier visit wait to be restored or discarded, and leaving loses what you typed since.`:`${n} This browser cannot keep them, so leaving loses them.`}function Mu({message:e,onStay:t,onLeave:n}){let r=(0,M.useRef)(null);return(0,N.jsx)(w,{title:`Leave without saving?`,onClose:t,initialFocus:r,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:r,onClick:t,children:`Stay`}),(0,N.jsx)(k,{variant:`danger`,onClick:n,children:`Leave`})]}),children:(0,N.jsx)(`p`,{children:e})})}var Nu={unpublish:{title:e=>`Unpublish ${e}?`,verb:`Unpublish`,busy:`Unpublishing…`,says:`Visitors stop seeing it. The change is recorded as a new version, and publishing makes it live again.`,danger:!0},archive:{title:e=>`Archive ${e}?`,verb:`Archive`,busy:`Archiving…`,says:`Visitors stop seeing it and it is marked archived, recorded as a new version. Its versions stay.`,danger:!0},unarchive:{title:e=>`Restore ${e} to draft?`,verb:`Restore to draft`,busy:`Restoring…`,says:`It is no longer archived and becomes a draft again, recorded as a new version. Nothing is published.`,danger:!1}};function Pu(e){let{change:t,name:n,busy:r,onConfirm:i,onClose:a}=e,o=(0,M.useRef)(null),s=Nu[t],c=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(k,{ref:o,onClick:r?void 0:a,"aria-disabled":r,children:`Cancel`}),(0,N.jsx)(k,{variant:s.danger?`danger`:`primary`,onClick:r?void 0:i,"aria-disabled":r,children:r?s.busy:s.verb})]});return(0,N.jsx)(w,{title:s.title(n),onClose:r?()=>void 0:a,initialFocus:o,busy:r,actions:c,children:(0,N.jsx)(`p`,{children:s.says})})}function Fu({ws:e,hasPage:t,dialog:n,close:r}){let{document:i,actions:a,facts:o}=e;if(!i||!o.saved)return null;let s=a.busy===`publish`,c=e=>{a.changePublication(e).then(r)},{collection:l,slug:u,locale:d}=i.meta;if(n.kind===`status`){let{change:e}=n;return(0,N.jsx)(Pu,{change:e,name:u,busy:s,onConfirm:()=>c(e),onClose:r})}return(0,N.jsx)(ha,{collection:l,slug:u,locale:d,saved:o.saved,hasPage:t,busy:s,onConfirm:()=>c(`publish`),onClose:r})}function Iu({ws:e,hasPage:t,dialog:n,close:r}){let{blocker:i}=e.guard;return i.state===`blocked`?(0,N.jsx)(Mu,{message:ju(e.document?.meta.slug??`the new document`,e.autosave.keeping),onStay:()=>i.reset(),onLeave:()=>i.proceed()}):n?(0,N.jsx)(Fu,{ws:e,hasPage:t,dialog:n,close:r}):null}var Lu=16;function Ru(e,t,n){return e<Lu?Lu-e:t>n-Lu?Math.max(Lu-e,n-Lu-t):0}function zu(e,t){(0,M.useLayoutEffect)(()=>{let n=t.current;if(!e||!n)return;n.style.translate=``;let{left:r,right:i}=n.getBoundingClientRect(),a=Ru(r,i,window.innerWidth);a!==0&&(n.style.translate=`${a}px 0`)},[e,t])}function Bu(e,t,n){(0,M.useEffect)(()=>{if(!e)return;function r(e){t.current?.contains(e.target)||n()}return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e,t,n])}function Vu(){let[e,t]=(0,M.useState)(!1),n=(0,M.useRef)(null),r=(0,M.useRef)(null);Bu(e,n,(0,M.useCallback)(()=>t(!1),[]));let i=(0,M.useCallback)(()=>{t(!1),r.current?.focus()},[]);function a(t){t.key===`Escape`&&e&&(t.stopPropagation(),i())}function o(e){n.current?.contains(e.relatedTarget)||t(!1)}return{open:e,toggle:()=>t(e=>!e),dismiss:i,wrapperRef:n,buttonRef:r,onKeyDown:a,onBlur:o}}function Hu({label:e,tone:t,icon:n,children:r}){let{open:i,toggle:a,dismiss:o,wrapperRef:s,buttonRef:c,onKeyDown:l,onBlur:u}=Vu(),d=(0,M.useId)(),f=(0,M.useRef)(null);return zu(i,f),(0,N.jsxs)(`div`,{ref:s,className:`editor-popover`,onKeyDown:l,onBlur:u,children:[(0,N.jsxs)(`button`,{ref:c,type:`button`,className:C(t,`editor-chip-button`),"aria-expanded":i,"aria-controls":d,onClick:a,children:[n&&(0,N.jsx)(n,{className:`ui-chip-icon`,"aria-hidden":`true`}),e,(0,N.jsx)(Ge,{className:`ui-chip-icon editor-chip-caret`,"aria-hidden":`true`})]}),(0,N.jsx)(`div`,{ref:f,id:d,className:`editor-popover-panel`,hidden:!i,children:typeof r==`function`?r(o):r})]})}var Uu={live:`success`,ahead:`warning`,draft:`neutral`};function Wu(e){let{modes:t,mode:n,onMode:r,tabId:i,panelId:a}=e,o=(0,M.useRef)(null);function s(e){let a={ArrowRight:1,ArrowLeft:-1}[e.key];if(a===void 0)return;e.preventDefault();let s=t.findIndex(e=>e.id===n),c=t[(s+a+t.length)%t.length];c&&(r(c.id),o.current?.querySelector(`#${CSS.escape(i(c.id))}`)?.focus())}return(0,N.jsx)(`div`,{ref:o,role:`tablist`,"aria-label":`Mode`,className:`editor-modes`,onKeyDown:s,children:t.map(e=>(0,N.jsx)(`button`,{id:i(e.id),type:`button`,role:`tab`,className:`editor-mode`,"aria-selected":e.id===n,"aria-controls":a,tabIndex:e.id===n?0:-1,onClick:()=>r(e.id),children:e.label},e.id))})}function Gu(e){return e.state===`held`?`You hold the edit lock`:e.state===`foreign`?`${e.holder} is editing`:e.state===`unavailable`?`Not locked: this store keeps no edit locks`:`Not locked`}function Ku({props:e,dismiss:t}){let{facts:n,record:r,onStatusChange:i}=e;if(!i)return null;let a=n.saved!==null&&n.saved.liveVersion!==null,o=r?.status===`archived`,s=ra(n),c=e=>()=>{t(),i(e)};return(0,N.jsxs)(`div`,{className:`editor-detail-actions`,children:[a&&(0,N.jsx)(Ct,{size:`sm`,reason:s,onClick:c(`unpublish`),children:`Unpublish`}),(0,N.jsx)(Ct,{size:`sm`,reason:s,onClick:c(o?`unarchive`:`archive`),children:o?`Restore to draft`:`Archive`}),s&&(0,N.jsx)(`p`,{className:`editor-detail-text`,children:s})]})}function qu({props:e,dismiss:t}){let{facts:n,record:r,lock:i}=e;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`dl`,{className:`editor-detail`,children:[(0,N.jsx)(`dt`,{children:`Versions`}),(0,N.jsx)(`dd`,{children:ea(n.saved)}),(0,N.jsx)(`dt`,{children:`Edit lock`}),(0,N.jsx)(`dd`,{children:Gu(i)}),r&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`dt`,{children:`Last save`}),(0,N.jsxs)(`dd`,{children:[p(r.createdAt),r.changedBy&&` by ${D(r.changedBy)}`,r.status===`archived`&&` · archived`]})]})]}),(0,N.jsx)(Ku,{props:e,dismiss:t})]})}function Ju({lock:e}){return e.state===`foreign`?(0,N.jsx)(Hu,{label:`${e.holder} is editing`,tone:`warning`,icon:de,children:(0,N.jsxs)(`p`,{className:`editor-detail-text`,children:[e.expiresAt&&`Their lock runs until ${p(e.expiresAt)}. `,`The editor is read-only until they finish or the lock expires; it opens for you then.`]})}):null}function Yu({link:e}){let t=e.kind===`preview`?`the saved draft`:`the live page`;return(0,N.jsxs)(`a`,{className:Re(`ghost`,`md`,`editor-site-link`),href:e.href,target:`_blank`,rel:`noreferrer`,title:`Opens ${t} in a new tab`,children:[(0,N.jsx)(wt,{className:`ui-button-icon`,"aria-hidden":`true`}),`Open on site`,(0,N.jsxs)(`span`,{className:`visually-hidden`,children:[` (`,t,`, opens in a new tab)`]})]})}function Xu(e){let{facts:t,siteLink:n,onSave:r,onPublish:i}=e,a=$i(t.saved),o=ta(t),s=na(t);return(0,N.jsxs)(`div`,{className:`editor-header`,children:[(0,N.jsx)(Wu,{...e}),(0,N.jsx)(`span`,{className:`editor-header-spacer`}),(0,N.jsx)(Hu,{label:ge[a],tone:Uu[a],children:t=>(0,N.jsx)(qu,{props:e,dismiss:t})}),(0,N.jsx)(Ju,{lock:e.lock}),e.locales,n&&(0,N.jsx)(Yu,{link:n}),t.canEdit&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(Ct,{reason:o,onClick:r,children:e.saving?`Saving…`:`Save draft`}),(0,N.jsx)(Ct,{reason:s,variant:`primary`,onClick:i,children:`Publish`})]})]})}function Zu(e,t){let n=e.savedAt?` from ${p(e.savedAt)}`:``,r=Au(e,t);return`${n}${r?`, ${r}`:``}`}function Qu({offer:e,currentVersion:t,onRestore:n,onDiscard:r}){return(0,N.jsxs)(`section`,{className:`editor-notice`,"aria-label":`Unsaved changes kept in this browser`,children:[(0,N.jsx)(ue,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`p`,{className:`editor-notice-text`,children:[`Unsaved changes`,Zu(e,t),` are kept in this browser.`]}),(0,N.jsxs)(`span`,{className:`editor-notice-actions`,children:[(0,N.jsx)(k,{size:`sm`,variant:`primary`,onClick:n,children:`Restore`}),(0,N.jsx)(k,{size:`sm`,variant:`ghost`,onClick:r,children:`Discard`})]})]})}function $u(e,t){return e===`kept`?` They are also kept in this browser; reload to see v${t}.`:e===`offer-pending`?` They are not kept in this browser while earlier changes wait to be restored or discarded: reloading loses them.`:` This browser cannot keep them: reloading loses them.`}function ed({failure:e,keeping:t,onOverwrite:n}){let r=e.conflictWith;return(0,N.jsxs)(`div`,{className:`editor-notice editor-notice--error`,children:[(0,N.jsx)(Et,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`p`,{className:`editor-notice-text`,children:[e.message,r!==void 0&&$u(t,r)]}),r!==void 0&&(0,N.jsxs)(k,{size:`sm`,variant:`danger`,onClick:()=>n(r),children:[`Overwrite v`,r,` with my changes`]})]})}function td({slug:e,asked:t,editing:n}){return(0,N.jsxs)(`p`,{className:`editor-notice`,children:[(0,N.jsx)(_e,{className:`editor-notice-icon`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`editor-notice-text`,children:[e,` has no `,t.toUpperCase(),` version yet. You are editing the `,n.toUpperCase(),` `,`version.`]})]})}function nd({workspace:e,onAnswered:t}){let{actions:n}=e;return(0,N.jsx)(`div`,{role:`alert`,className:`editor-alert-region`,children:n.failure&&(0,N.jsx)(ed,{failure:n.failure,keeping:e.autosave.keeping,onOverwrite:e=>{t(),n.save(e)}})})}function rd({workspace:e,missingLocale:t,onAnswered:n}){let{autosave:r,document:i}=e,a=e=>()=>{e(),n()};return(0,N.jsxs)(`div`,{className:`editor-notices`,children:[(0,N.jsx)(nd,{workspace:e,onAnswered:n}),r.offer&&(0,N.jsx)(Qu,{offer:r.offer,currentVersion:i?.meta.version??null,onRestore:a(e.restoreKept),onDiscard:a(r.discard)}),t&&i&&(0,N.jsx)(td,{slug:i.meta.slug,asked:t,editing:i.meta.locale})]})}var id={page:[{id:`live`,label:`Live`},{id:`structure`,label:`Structure`},{id:`data`,label:`Data`}],global:[{id:`fields`,label:`Fields`},{id:`where`,label:`Where it appears`}]},ad=`mode`;function od(e,t=!0){let n=id[e];return t?n:n.filter(e=>e.id!==`live`)}function sd(e,t,n={}){let r=od(t,n.hasPage??!0),i=r.find(t=>t.id===e);if(i)return i.id;let a=r[0]?.id??`structure`;return a===`live`&&n.isNew?`structure`:a}var cd=null;function ld(){return cd??=y().catch(()=>(cd=null,null)),cd}async function ud(e){try{let[t,n,r,i,a]=await Promise.all([x(e.collection),oe().catch(()=>[]),e.slug?S(e.collection,e.slug,e.locale):null,ld(),v().catch(()=>null)]);return{schema:t,collection:n.find(t=>t.name===e.collection)??null,document:r,site:i,locales:a}}catch(e){if(Ce(e))return null;throw e}}function dd(e){let{collection:t,slug:n,locale:r}=e,i=(0,M.useCallback)(()=>ud({collection:t,slug:n,locale:r}),[t,n,r]);return Le(i,`The document could not load`)}var fd=800;function pd(e,t,n){let{key:r,draft:i,dirty:a,context:o}=e,{baseVersion:s,slug:c}=o;(0,M.useEffect)(()=>{if(!r||t||n.forgotten)return;if(!a){Du(r);return}let e=setTimeout(()=>Eu(r,i,{baseVersion:s,slug:c}),fd);return()=>clearTimeout(e)},[r,i,a,s,c,t,n])}function md(e,t){(0,M.useEffect)(()=>{if(!e)return;let n=()=>{let{input:n,offer:r,forgotten:i}=t;n.dirty&&!r&&!i&&Eu(e,n.draft,n.context)};return window.addEventListener(`pagehide`,n),()=>{window.removeEventListener(`pagehide`,n),n()}},[e,t])}function hd(e){let{key:t}=e,[n,r]=(0,M.useState)(()=>{let n=t?Tu(t):null;return ku(n,e.opened,e.context.baseVersion!==void 0)?n:null}),[i]=(0,M.useState)(Ou),a=(0,M.useRef)({input:e,offer:n,forgotten:!1}).current;a.input=e,a.offer=n,pd(e,n,a),md(t,a);let o=(0,M.useCallback)(()=>(r(null),n),[n]),s=(0,M.useCallback)(()=>{t&&Du(t),r(null)},[t]),c=(0,M.useCallback)(()=>{a.forgotten=!0,t&&Du(t)},[t,a]);return{offer:n,keeping:n?`offer-pending`:t&&i?`kept`:`unavailable`,restore:o,discard:s,forget:c}}function gd(e){let t={};for(let[n,r]of Object.entries(e))r.default!==void 0&&(t[n]=r.default);return t}function _d(e,t){return e?{fields:e.fields,body:e.body,metadata:e.metadata,...e.defaults.length?{defaults:e.defaults}:{}}:{fields:t,body:``,metadata:{}}}function vd(e){let[t,n]=(0,M.useState)(e),[r,i]=(0,M.useState)(e),a=(0,M.useMemo)(()=>!gu(r,t),[r,t]),o=(0,M.useCallback)((e,t)=>{i(n=>{let r={...n.fields};return t===void 0?delete r[e]:r[e]=t,{...n,fields:r}})},[]),s=(0,M.useCallback)(e=>{i(t=>({...t,metadata:e}))},[]);return{draft:r,baseline:t,dirty:a,setField:o,setBody:(0,M.useCallback)(e=>{i(t=>({...t,body:e}))},[]),setMetadata:s,replace:i,reset:(0,M.useCallback)(e=>{n(e),i(e)},[]),rebase:(0,M.useCallback)((e,t)=>{n(e),i(n=>_u(n,t,e))},[])}}function yd(e){let[t,n]=(0,M.useState)(e.document),[r,i]=(0,M.useState)(e.document?.meta.version??null),a=(0,M.useMemo)(()=>gd(e.schema.schema.properties??{}),[e]),o=(0,M.useMemo)(()=>_d(e.document,a),[e,a]),s=vd(o),c=(0,M.useMemo)(()=>Object.keys(o.fields).filter(e=>o.fields[e]!==void 0),[o]),{rebase:l,reset:u}=s,d=(0,M.useCallback)((e,t)=>{n(e),i(e.meta.version),l(_d(e,a),t)},[l,a]),f=(0,M.useCallback)(e=>{n(e),i(e.meta.version),u(_d(e,a))},[u,a]);return{document:t,draft:s,opened:o,openedFields:c,baseVersion:r,restoredOn:(0,M.useCallback)(e=>{e!==void 0&&i(e)},[]),onSaved:d,onReplaced:f}}var bd=5e3,xd=6e4,Sd=3e4,Cd=5e3,wd=6e4;function Td(e){return e.locked?{state:`held`,expiresAt:e.expiresAt??null}:e.status===423&&e.lockedBy?{state:`foreign`,holder:D(e.lockedBy),expiresAt:e.expiresAt??null}:e.status===501?{state:`unavailable`}:null}function Ed(e){return Math.min(wd,Cd*2**Math.max(0,e-1))}function Dd(e,t=Date.now()){if(e.state===`foreign`)return Sd;if(e.state!==`held`)return null;if(!e.expiresAt)return xd;let n=new Date(e.expiresAt).getTime()-t;return Math.max(bd,Math.floor(n/2))}function Od(e,t){let{collection:n,slug:r,locale:i}=e,a=!0,o=!1,s=0,c=null,l=null,u=e=>(s=e?0:s+1,e?(o=e.state===`held`,a&&t(e),Dd(e)):Ed(s)),d=()=>{l=ve(n,r,i).then(e=>{l=null;let t=u(Td(e));a&&t!==null&&(c=setTimeout(d,t))})};return d(),()=>{a=!1,c&&clearTimeout(c);let e=()=>{o&&me(n,r,i)};l?l.then(e):e()}}function kd(e){let[t,n]=(0,M.useState)({state:`none`}),r=e?.collection,i=e?.slug,a=e?.locale;return(0,M.useEffect)(()=>{if(!r||!i||!a)return;let e=Od({collection:r,slug:i,locale:a},n);return()=>{e(),n({state:`none`})}},[r,i,a]),t}var Ad=class extends Error{field;constructor(e,t){super(t),this.name=`FieldRefusal`,this.field=e}};function jd(e){let t={};if(!Array.isArray(e))return t;for(let n of e){if(typeof n!=`object`||!n)continue;let{field:e,message:r}=n;typeof e==`string`&&typeof r==`string`&&(t[e.startsWith(`fields.`)?e.slice(7):e]=r)}return t}function Md(e,t){return{message:`v${e} was saved after ${typeof t==`number`?`v${t}`:`the version you opened`}, the version your changes are based on. Nothing was saved; your changes are still in the form.`,fieldErrors:{},conflictWith:e}}function Nd(e,t){let{body:n}=e;if(e.status===409&&typeof n.currentVersion==`number`)return Md(n.currentVersion,n.yourVersion);if(e.status===423&&typeof n.lockedBy==`string`){let e=D(n.lockedBy);return{message:`${e} is editing this document.`,fieldErrors:{},lockedBy:e}}let r=jd(n.details);return Object.keys(r).length>0?{message:`Some fields are not valid. Fix the marked fields and save again.`,fieldErrors:r}:{message:e.message||t,fieldErrors:{}}}function Pd(e,t){return e instanceof Ad?{message:e.message,fieldErrors:{[e.field]:e.message}}:e instanceof Fe?Nd(e,t):{message:e instanceof Error?e.message:t,fieldErrors:{}}}var Fd={publish:`published`,unpublish:`draft`,archive:`archived`,unarchive:`draft`},Id={unpublish:e=>`Unpublished ${e}. Visitors no longer see it.`,archive:e=>`Archived ${e}. Visitors no longer see it.`,unarchive:e=>`${e} is a draft again. Nothing is live until you publish.`};async function Ld(e,t,n){try{let r=await S(e,t,n);return n===void 0||r.meta.locale===n}catch(e){if(e instanceof Fe&&e.status===404)return!1;throw e}}async function Rd(e){let{collection:t,draft:n,newLocale:r}=e,i=e.newSlug.trim();if(!i)throw new Ad(`slug`,`A new document needs a slug.`);if(await Ld(t,i,r))throw new Ad(`slug`,`${t} already has a document at "${i}". Choose another slug.`);let a=await ee(t,{slug:i,...n,locale:r});return e.onCreated(a.slug),ia(a)}async function zd(e,t){let{collection:n,saved:r,draft:i}=e;if(!r)return Rd(e);let{slug:a,locale:o}=r.meta,s=t??e.baseVersion??r.meta.version,c=await ne(n,a,{...i,_version:s,locale:o});return e.onSaved(await Bd(e,r,c),i),ia(c)}async function Bd(e,t,n){let{slug:r,locale:i}=t.meta;try{return await S(e.collection,r,i)}catch{let r={...t.meta,version:n.version,liveVersion:n.liveVersion};return{...t,...e.draft,defaults:e.draft.defaults??t.defaults,meta:r}}}function Vd(e,t,n){return n===null||n===t?`Published ${e} · v${t} is live.`:`Published ${e} · v${t} is live, recorded as v${n}.`}async function Hd(e,t){let{collection:n,saved:r}=e;if(!r)throw Error(`Save the draft first.`);let{slug:i,locale:a,version:o}=r.meta,s=await se(n,i,{status:Fd[t],locale:a});return e.onReplaced(await S(n,i,a)),t===`publish`?Vd(i,o,s.version):Id[t](i)}function Ud(e){let[t,n]=(0,M.useState)(null),[r,i]=(0,M.useState)(null),a=fe(),o=Te(),s=(0,M.useRef)(!1);async function c(e,t,r){if(s.current)return!1;s.current=!0,n(e),i(null);let c;try{c=await t()}catch(e){return i(Pd(e,r)),!1}finally{s.current=!1,n(null)}return a({text:c}),o(),!0}return{busy:t,failure:r,save:async t=>{await c(`save`,()=>zd(e,t),`The draft could not be saved`)},changePublication:t=>c(`publish`,()=>Hd(e,t),`The change could not be made`)}}function Wd(e){let t=new URLSearchParams(e);return t.delete(ad),t.sort(),t.toString()}function Gd(e,t){return e.pathname!==t.pathname||Wd(e.search)!==Wd(t.search)}function Kd(e){let t=(0,M.useRef)(e);t.current=e;let n=(0,M.useRef)(!1),r=(0,M.useCallback)(({currentLocation:e,nextLocation:r})=>n.current||!t.current?!1:Gd(e,r),[]),i=o(r);return(0,M.useEffect)(()=>{if(!e)return;function t(e){e.preventDefault(),e.returnValue=``}return window.addEventListener(`beforeunload`,t),()=>window.removeEventListener(`beforeunload`,t)},[e]),{blocker:i,release:(0,M.useCallback)(()=>{n.current=!0},[])}}function qd(){let[e,t]=(0,M.useState)(``),[n,r]=(0,M.useState)(!1);return{value:e,onChange:(0,M.useCallback)(e=>{t(e),r(!0)},[]),suggestFrom:(0,M.useCallback)((e,r)=>{!n&&xu(e)&&typeof r==`string`&&t(bu(r))},[n])}}function Jd(e){return typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:typeof e==`string`?/^\d{4}-\d{2}-\d{2}/.test(e)?`date`:/^https?:\/\//.test(e)?`url`:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(e)?`email`:/^#[0-9a-f]{3,8}$/i.test(e)?`color`:`string`:`string`}function Yd(e,t){let[n,r]=(0,M.useState)(t),i=fe();return[n,(0,M.useCallback)(async(t,n)=>{try{await ce(e,{name:t,type:Jd(n),required:!1}),r(await x(e)),i({text:`${t} is now a field of the schema.`})}catch(e){i({text:T(e,`${t} could not be promoted`),tone:`error`})}},[e,i])]}function Xd(e,t){let{setField:n}=e,{suggestFrom:r}=t;return(0,M.useCallback)((e,t)=>{n(e,t),r(e,t)},[n,r])}function Zd(e,t){if(!t)return Cu(e.collection,e.locale);let{slug:n,locale:r}=t.meta;return Su(e.collection,n,r)}function Qd(e,t){return e.draft.dirty||e.document===null&&t.value.trim()!==``}function $d(e,t,n){let r=rt().hasRole(`editor`),i=t.document?.meta,a=kd(r&&i?{collection:e.collection,slug:i.slug,locale:i.locale}:null),o=Qd(t,n);return{canEdit:r,lock:a,autosave:hd({key:Zd(e,t.document),draft:t.draft.draft,dirty:o,opened:t.opened,context:{baseVersion:t.baseVersion??void 0,slug:t.document?void 0:n.value}}),dirty:o,guard:Kd(o)}}function ef(e,t,n,r){let i=c(),{collection:a,locale:o}=e,{release:s}=r.guard,{forget:l}=r.autosave,u=(0,M.useCallback)(e=>{l(),s();let t=ie(a,e,o);i(`${t}${t.includes(`?`)?`&`:`?`}${ad}=structure`)},[l,s,i,a,o]);return Ud({collection:a,saved:t.document,baseVersion:t.baseVersion,newLocale:o,draft:t.draft.draft,newSlug:n.value,onSaved:t.onSaved,onReplaced:t.onReplaced,onCreated:u})}function tf(e,t){return e.state===`foreign`?e.holder:e.state===`held`?null:t.failure?.lockedBy??null}function nf(e,t,n,r,i){let a=e.document?.meta;return{saved:a?{version:a.version,liveVersion:a.liveVersion}:null,dirty:t,busy:n.busy!==null,canEdit:r,lockedBy:i,rebased:a!==void 0&&e.baseVersion!==a.version,conflict:n.failure?.conflictWith!==void 0}}function rf(e,t,n){let{replace:r}=e.draft,{restoredOn:i}=e,{onChange:a}=t,{restore:o}=n;return(0,M.useCallback)(()=>{let e=o();e&&(r({fields:e.fields,body:e.body,metadata:e.metadata,defaults:e.defaults}),i(e.baseVersion),e.slug&&a(e.slug))},[o,r,i,a])}function af(e,t){let{collection:n}=t,[r,i]=Yd(n,e.schema),a=yd(e),{document:o,draft:s,onReplaced:c}=a,l=qd(),{canEdit:u,lock:d,autosave:f,dirty:p,guard:m}=$d(t,a,l),h=ef(t,a,l,{guard:m,autosave:f}),g=tf(d,h),_=rt().hasRole(`admin`),v=o===null&&h.busy===`save`,y=o?.meta,b=(0,M.useCallback)(async()=>{y&&c(await S(n,y.slug,y.locale))},[n,y,c]);return{prepareSnapshot:e=>s.replace(e),schema:r,document:o,draft:s,newSlug:l,lock:d,autosave:f,actions:h,guard:m,canEdit:u,isAdmin:_,creating:v,readOnly:!u||g!==null||v,facts:nf(a,p,h,u,g),baseVersion:a.baseVersion,openedFields:a.openedFields,setField:Xd(s,l),restoreKept:rf(a,l,f),promote:i,reloadDocument:b}}function of(e){(0,M.useEffect)(()=>{let t=document.activeElement;t&&t!==document.body||e.current?.focus()},[e])}function sf({ws:e,source:t}){let{locales:n}=t;return!e.document||!n||!re(n)?null:(0,N.jsx)(tl,{collection:e.document.meta.collection,slug:e.document.meta.slug,current:e.document.meta.locale,locales:n.supportedLocales,defaultLocale:n.defaultLocale,canCreate:e.canEdit})}function cf(e,{source:t,target:n}){let r=u(),i=n.collection===`globals`?`global`:`page`,a=e.document?.meta,o=a?sa({collection:t.collection,slug:a.slug,liveVersion:a.liveVersion,preview:e.canEdit&&h(r,`sitePreview`),baseUrl:t.site?.site.baseUrl??null}):null,s=t.collection?.pages??!1;return{kind:i,hasPage:s,modes:od(i,s),title:a?a.slug:`New ${f(n.collection)}`,siteLink:o,missingLocale:a&&n.locale&&n.locale!==a.locale?n.locale:null,showPanel:i===`page`}}function lf({ws:e,view:t,ids:n,mode:r,onMode:i,openDialog:a,source:o}){let s=e.document?.meta,c=s?{status:s.status,createdAt:s.createdAt,changedBy:s.changedBy}:null;return(0,N.jsx)(Xu,{modes:t.modes,mode:r,onMode:i,tabId:e=>`${n}-mode-${e}`,panelId:`${n}-canvas`,facts:e.facts,saving:e.actions.busy===`save`,record:c,lock:e.lock,locales:(0,N.jsx)(sf,{ws:e,source:o}),siteLink:t.siteLink,onSave:()=>void e.actions.save(),onPublish:()=>a({kind:`publish`}),onStatusChange:s&&!e.readOnly?e=>a({kind:`status`,change:e}):null})}function uf(e,t){let[n,r]=a();return[sd(n.get(ad),e,t),(0,M.useCallback)(e=>{r(t=>{let n=new URLSearchParams(t);return n.set(ad,e),n},{replace:!0})},[r])]}function df(e){let t=af(e.source,e.target),n=cf(t,e),r=e.target.slug===void 0,[i,a]=uf(n.kind,{isNew:r,hasPage:n.hasPage}),[o,s]=(0,M.useState)(null),c=(0,M.useId)(),l=(0,M.useRef)(null),u=(0,M.useRef)(null);of(l);let d=(0,M.useCallback)(()=>s(null),[]),f={...e,ws:t,view:n,ids:c,mode:i};return(0,N.jsxs)(`section`,{ref:l,className:`editor`,tabIndex:-1,"aria-labelledby":`${c}-title`,children:[(0,N.jsx)(`h1`,{id:`${c}-title`,className:`visually-hidden`,children:n.title}),(0,N.jsx)(lf,{...f,onMode:a,openDialog:s}),(0,N.jsx)(rd,{workspace:t,missingLocale:n.missingLocale,onAnswered:()=>u.current?.focus()}),n.kind===`page`&&i!==`data`&&t.document&&(0,N.jsx)(Or,{timeline:!0,collection:t.document.meta.collection,slug:t.document.meta.slug,locale:t.document.meta.locale,saved:{version:t.document.meta.version,liveVersion:t.document.meta.liveVersion},draft:t.draft.draft,unsaved:t.draft.dirty,canRestore:t.isAdmin&&!t.readOnly,onRestored:t.reloadDocument,onPrepare:t.prepareSnapshot}),(0,N.jsx)(mu,{ws:t,kind:n.kind,source:e.source,collection:e.target.collection,ids:c,mode:i,onMode:a,showPanel:n.showPanel,canvasRef:u}),(0,N.jsx)(Iu,{ws:t,hasPage:n.hasPage,dialog:o,close:d})]})}function ff(){return(0,N.jsxs)(`div`,{className:`editor`,"aria-busy":`true`,children:[(0,N.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:`Loading the document…`}),(0,N.jsx)(`div`,{className:`editor-header editor-skeleton`,"aria-hidden":`true`}),(0,N.jsx)(`div`,{className:`editor-structure editor-skeleton editor-skeleton--canvas`,"aria-hidden":`true`})]})}function pf({target:e}){let{loaded:t,reload:n}=dd(e);return t.state===`loading`?(0,N.jsx)(ff,{}):t.state===`error`?(0,N.jsx)(Me,{title:`The document could not load`,message:t.message,onRetry:n}):t.data?(0,N.jsx)(df,{source:t.data,target:e}):(0,N.jsx)(be,{})}function mf({collection:e}){let t=i(),[n]=a(),r=e??t.collection,o=n.get(`locale`)??void 0;if(!r)return(0,N.jsx)(be,{});let{slug:s}=t;return(0,N.jsx)(pf,{target:{collection:r,slug:s,locale:o}},`${r}/${s??``}/${o??``}`)}export{mf as EditorPage,$s as a,Bt as c,Qs as i,Ys as n,uo as o,Zs as r,Wa as s,Js as t};