@blinkk/root-cms 3.0.3 → 3.0.5

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 (47) hide show
  1. package/dist/app.js +2 -1
  2. package/dist/{chunk-7Z5IRD2G.js → chunk-VSPPZPMP.js} +2 -2
  3. package/dist/core/schema.d.ts +20 -0
  4. package/dist/plugin.js +5 -5
  5. package/dist/shared/auto-slug-words.d.ts +7 -0
  6. package/dist/shared/auto-slug.d.ts +14 -0
  7. package/dist/ui/{AIPage-2LUC2PWC.js → AIPage-F3NNYM5E.js} +1 -1
  8. package/dist/ui/{AssetsPage-PODV4QAB.js → AssetsPage-DZQHAENZ.js} +1 -1
  9. package/dist/ui/{CollectionPage-4DMKW5YB.js → CollectionPage-WVVG62NR.js} +1 -1
  10. package/dist/ui/{ComparePage-JMJE5A5Y.js → ComparePage-CRDHP45W.js} +1 -1
  11. package/dist/ui/{DataPage-MVLZT2BU.js → DataPage-WMLBCPGF.js} +1 -1
  12. package/dist/ui/{DataSourcePage-4RPBXRI2.js → DataSourcePage-POZAQFPU.js} +1 -1
  13. package/dist/ui/{DocTranslationsPage-XJSPKGVX.js → DocTranslationsPage-UR5D2RF2.js} +1 -1
  14. package/dist/ui/DocumentPage-SQ7ROBMC.js +1 -0
  15. package/dist/ui/{EditDataSourcePage-3SHAARNL.js → EditDataSourcePage-PUA2AJ4C.js} +1 -1
  16. package/dist/ui/{EditReleasePage-G5VW2OGW.js → EditReleasePage-CENP46EO.js} +1 -1
  17. package/dist/ui/{LogsPage-K6KYEG2P.js → LogsPage-FZRN6MBJ.js} +1 -1
  18. package/dist/ui/{NewDataSourcePage-O2VQEOJG.js → NewDataSourcePage-FTILYFJY.js} +1 -1
  19. package/dist/ui/{NewReleasePage-RSVS32RZ.js → NewReleasePage-MHJC66KK.js} +1 -1
  20. package/dist/ui/{NotFoundPage-ZYD5ILG6.js → NotFoundPage-EP2OE4JV.js} +1 -1
  21. package/dist/ui/{ProjectPage-X3YQBWL4.js → ProjectPage-6J7QCG75.js} +1 -1
  22. package/dist/ui/{ReleasePage-FJHHXNNB.js → ReleasePage-IZ3DNGT4.js} +1 -1
  23. package/dist/ui/{ReleasesPage-VGWIBNEZ.js → ReleasesPage-RWFOJ5VG.js} +1 -1
  24. package/dist/ui/SettingsPage-M4SIDBTI.js +1 -0
  25. package/dist/ui/{SidebarToolsPage-ZBOKPEMP.js → SidebarToolsPage-GAX3XJ7W.js} +1 -1
  26. package/dist/ui/{TaskPage-BQ4OX5WN.js → TaskPage-UCATTNZ5.js} +1 -1
  27. package/dist/ui/{TasksPage-3IGQYVYS.js → TasksPage-4AQLQ4IT.js} +1 -1
  28. package/dist/ui/{TranslationsArbPage-GGHCWPQL.js → TranslationsArbPage-JGQGATCS.js} +1 -1
  29. package/dist/ui/{TranslationsEditPage-E2BCMKYV.js → TranslationsEditPage-7AGZGHKS.js} +1 -1
  30. package/dist/ui/{TranslationsPage-MC4O4ZNI.js → TranslationsPage-WIDVSTYF.js} +1 -1
  31. package/dist/ui/{chunk-UEON4JAT.js → chunk-7MTDTPYB.js} +1 -1
  32. package/dist/ui/{chunk-GXSAEPU3.js → chunk-7UIUAHC4.js} +1 -1
  33. package/dist/ui/{chunk-B6BLDN24.js → chunk-AEWL2RWR.js} +57 -57
  34. package/dist/ui/{chunk-MDUBCXU2.js → chunk-JKCZGT6B.js} +1 -1
  35. package/dist/ui/chunk-P3NETZZP.js +1 -0
  36. package/dist/ui/chunk-P4U2LUTF.js +1 -0
  37. package/dist/ui/{chunk-V7S4IAGB.js → chunk-QGBR3J2Y.js} +1 -1
  38. package/dist/ui/chunk-TJBVMFNQ.js +1 -0
  39. package/dist/ui/ui.css +1 -1
  40. package/dist/ui/ui.js +1 -1
  41. package/package.json +3 -3
  42. package/dist/ui/DocumentPage-R2PVNG24.js +0 -1
  43. package/dist/ui/SettingsPage-C4RXOQ6T.js +0 -1
  44. package/dist/ui/chunk-6IFGKSIE.js +0 -1
  45. package/dist/ui/chunk-IU36W2TB.js +0 -1
  46. package/dist/ui/chunk-NXQVLOTK.js +0 -1
  47. /package/dist/ui/{chunk-B6BLDN24.js.LEGAL.txt → chunk-AEWL2RWR.js.LEGAL.txt} +0 -0
@@ -1 +0,0 @@
1
- import{a as je}from"./chunk-767BAQ53.js";import{c as Le,i as Ve,j as $e,k as We,m as Fe}from"./chunk-B6BLDN24.js";import"./chunk-HHMG665Z.js";import"./chunk-YFA6U2CV.js";import"./chunk-4W73RW5I.js";import"./chunk-IU36W2TB.js";import"./chunk-V7S4IAGB.js";import"./chunk-KFAZBEPV.js";import"./chunk-KYDOSLTO.js";import{a as Ue}from"./chunk-JYFLU7DM.js";import"./chunk-PHBMVORG.js";import{d as Ee}from"./chunk-JZFTZ4X4.js";import"./chunk-HKINZLMW.js";import{a as Me,d as Ae,f as X,h as Oe}from"./chunk-6IFGKSIE.js";import"./chunk-CGCKJFL4.js";import"./chunk-VMT7JFAM.js";import"./chunk-SKEP5WYH.js";import"./chunk-GXSAEPU3.js";import{b as Re,c as ae,g as Te}from"./chunk-NXQVLOTK.js";import"./chunk-3IYZCUPI.js";import"./chunk-RSVO46S3.js";import"./chunk-54DVDYU6.js";import{a as T}from"./chunk-X2WHBGTP.js";import{b as Be,c as se}from"./chunk-ONTGW2VA.js";import"./chunk-4KE2SZKH.js";import{a as ze}from"./chunk-L4RHGQUG.js";import"./chunk-HRGYNHZ3.js";import"./chunk-W3HIZQ4Z.js";import"./chunk-JDW4UORS.js";import"./chunk-YDO2EDVY.js";import"./chunk-AFWBSIPL.js";import"./chunk-XOQ3KDSR.js";import"./chunk-62UWGWON.js";import"./chunk-I6ICVKEC.js";import"./chunk-HLMBCVRX.js";import"./chunk-ORXEMIQC.js";import{a as He,b as Xe}from"./chunk-UEON4JAT.js";import"./chunk-5MV6XVGA.js";import"./chunk-EGEB6N4J.js";import{f as I}from"./chunk-AL3TN2KI.js";import{Aa as _e,Ac as Ie,Ga as L,Ha as e,Ja as pe,P as me,Pa as ge,Ra as oe,Ta as fe,Tc as Ne,Uc as ne,Va as ve,Vb as De,W as E,Wb as Ce,_a as Pe,a as y,c as x,ca as he,e as P,ea as H,g as M,h as C,j as te,pc as Se,qb as we,rb as xe,sb as be,tb as ke,tc as ye}from"./chunk-NZHF733K.js";import{d as V,j as ue,k as et}from"./chunk-KUCVLANF.js";import"./chunk-DTMZLUNY.js";import"./chunk-PVAE643M.js";te();te();async function qe(t,o){let a=await(await fetch("/cms/api/check.test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({check:t,docId:o})})).json();if(!a.success)throw new Error(a.error||"Check failed.");return a.data}function Ke(t){let o=window.__ROOT_CTX.checks||[],n=t.docId.split("/")[0],a=o.filter(c=>!c.collections||c.collections.includes(n)),[i,r]=y({}),s=C(async c=>{r(m=>({...m,[c]:{loading:!0}}));try{let m=await qe(c,t.docId);r(h=>({...h,[c]:{loading:!1,result:m}}))}catch(m){r(h=>({...h,[c]:{loading:!1,error:m.message||"Unknown error."}}))}},[t.docId]),l=C(async()=>{let c={};for(let m of a)c[m.id]={loading:!0};r(c);for(let m of a)try{let h=await qe(m.id,t.docId);r(_=>({..._,[m.id]:{loading:!1,result:h}}))}catch(h){r(_=>({..._,[m.id]:{loading:!1,error:h.message||"Unknown error."}}))}},[t.docId,a]);return e("div",{className:"ChecksPanel",children:[e("div",{className:"ChecksPanel__header",children:[e("div",{className:"ChecksPanel__header__title",children:"Checks"}),e(H,{variant:"default",size:"xs",compact:!0,leftIcon:e(Se,{size:12}),onClick:l,children:"Run All"})]}),e("div",{className:"ChecksPanel__body",children:e("div",{className:"ChecksPanel__checks",children:a.map(c=>{let m=i[c.id];return e(tt,{check:c,state:m,onRun:()=>s(c.id)},c.id)})})})]})}function tt(t){let{check:o,state:n,onRun:a}=t;return e("div",{className:"ChecksPanel__check",children:[e("div",{className:"ChecksPanel__check__header",children:[e("div",{className:"ChecksPanel__check__label",children:[o.label,n?.result&&e(at,{status:n.result.status})]}),e(H,{className:"ChecksPanel__check__runButton",variant:"default",size:"xs",compact:!0,loading:n?.loading,onClick:a,children:"Run"})]}),o.description&&e("div",{className:"ChecksPanel__check__description",children:o.description}),n?.result&&e("div",{className:I("ChecksPanel__check__result",`ChecksPanel__check__result--${n.result.status}`),children:e(Ee,{code:n.result.message})}),n?.error&&e("div",{className:"ChecksPanel__check__error",children:n.error})]})}var ot={success:"green",warning:"yellow",error:"red"},nt={success:Pe,warning:pe,error:ne};function at(t){let o=ot[t.status],n=nt[t.status],a=t.status.charAt(0).toUpperCase()+t.status.slice(1);return e(he,{className:"ChecksPanel__statusBadge",color:o,size:"sm",variant:"filled",leftSection:e(n,{size:10}),children:a})}function Je(t){let{device:o,expandVertically:n,iframeUrl:a,localeOptions:i,selectedLocale:r,onToggleDevice:s,onToggleExpandVertically:l,onReloadClick:c,onOpenNewTab:m,onLocaleChange:h}=t;return e("div",{className:"DocumentPagePreviewBar",children:[e("div",{className:"DocumentPagePreviewBar__devices",children:[e(L,{label:"Mobile",children:e(E,{className:I("DocumentPagePreviewBar__device",o==="mobile"&&"active"),onClick:()=>s("mobile"),children:e(ke,{size:16})})}),e(L,{label:"Tablet",children:e(E,{className:I("DocumentPagePreviewBar__device",o==="tablet"&&"active"),onClick:()=>s("tablet"),children:e(be,{size:16})})}),e(L,{label:"Desktop",children:e(E,{className:I("DocumentPagePreviewBar__device",o==="desktop"&&"active"),onClick:()=>s("desktop"),children:e(we,{size:16})})}),e(L,{label:"Expand",children:e(E,{className:I("DocumentPagePreviewBar__device",n&&"active"),"aria-pressed":n,disabled:o==="",onClick:l,children:e(fe,{size:16})})})]}),e("div",{className:"DocumentPagePreviewBar__navbar",children:e("div",{className:"DocumentPagePreviewBar__navbar__url",children:a})}),e("div",{className:"DocumentPagePreviewBar__locales",children:e(_e,{data:i,placeholder:"Locale",radius:"xl",size:"xs",required:!0,icon:e(Ne,{size:16,strokeWidth:1.5}),value:r,onChange:_=>{h(_)}})}),e("div",{className:"DocumentPagePreviewBar__buttons",children:[e(L,{label:"Reload",children:e(E,{className:"DocumentPagePreviewBar__button DocumentPagePreviewBar__button--reload",onClick:c,children:e(ye,{size:16})})}),e(L,{label:"Open new tab",children:e(E,{className:"DocumentPagePreviewBar__button DocumentPagePreviewBar__button--openNewTab",onClick:m,children:e(oe,{size:16})})})]})]})}te();function Ye(t){let o=t.docId.split("/")[0],n=Te(o),a=X(),i=P(null),[r,s]=y(""),[l,c]=y([]),[m,h]=y(!1),_=P("");_.current=r;let g=P(n.schema?.fields||[]);g.current=n.schema?.fields||[];let k=P(n.schema?.types||{});k.current=n.schema?.types||{};let w=M(()=>Me(d=>{let b=d.trim();if(!b){c([]),h(!1);return}let S=a.controller?.getData()?.fields||{},z=We(b,S,g.current,k.current);c(z),h(!0)},150),[a.controller]);x(()=>{w(r)},[r,w]),Oe(()=>{_.current.trim()&&w(_.current)}),x(()=>{t.autoFocus&&requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()})},[t.autoFocus]),x(()=>{let d=()=>{i.current?.focus(),i.current?.select()};return window.addEventListener("root:focus-search",d),()=>window.removeEventListener("root:focus-search",d)},[]);let p=d=>{ct(d)};return e("div",{className:"SearchPanel",children:[e("div",{className:"SearchPanel__header",children:[e("div",{className:"SearchPanel__header__title",children:"Search"}),t.onClose&&e(E,{size:"xs",onClick:t.onClose,title:"Close search",children:e(ne,{size:14})})]}),e("div",{className:"SearchPanel__searchInput",children:[e("span",{className:"SearchPanel__searchInput__icon",children:e(Ie,{size:14})}),e("input",{ref:i,type:"text",className:"SearchPanel__searchInput__input",value:r,onInput:d=>s(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&t.onClose&&(d.preventDefault(),t.onClose())},placeholder:"Search field values\u2026",autoComplete:"off",spellcheck:!1})]}),e("div",{className:"SearchPanel__body",children:[!m&&!r.trim()&&e("div",{className:"SearchPanel__empty",children:"Type a query above to search field values in this document."}),m&&l.length===0&&e("div",{className:"SearchPanel__empty",children:["No matches for ",e("strong",{children:r}),"."]}),l.length>0&&e(V,{children:[e("div",{className:"SearchPanel__resultsCount",children:[l.length," ",l.length===1?"match":"matches"]}),e("ul",{className:"SearchPanel__results",children:l.map((d,b)=>e(it,{result:d,onClick:()=>p(d)},`${d.deepKey}:${b}`))})]})]})]})}function it(t){let{result:o}=t;return e("li",{className:"SearchPanel__result",children:e("button",{type:"button",className:"SearchPanel__result__button",onClick:t.onClick,children:[e("div",{className:"SearchPanel__result__label",children:o.label}),e("div",{className:"SearchPanel__result__snippet",children:rt(o.snippet,o.matches)}),e("div",{className:"SearchPanel__result__meta",children:[e("span",{className:"SearchPanel__result__type",children:o.fieldType}),o.richTextBlock&&e("span",{className:"SearchPanel__result__badge",children:"in block"}),o.richTextInline&&e("span",{className:"SearchPanel__result__badge",children:"inline"})]})]})})}function rt(t,o){if(!o||o.length===0)return t;let n=[],a=0;for(let i of o)i.start>a&&n.push({text:t.slice(a,i.start),match:!1}),n.push({text:t.slice(i.start,i.end),match:!0}),a=i.end;return a<t.length&&n.push({text:t.slice(a),match:!1}),n.map((i,r)=>i.match?e("mark",{children:i.text},r):e("span",{children:i.text},r))}function ct(t){if(window.postMessage({scrollToDeeplink:{deepKey:t.deepKey}},"*"),t.richTextBlock){let o=t.richTextBlock;setTimeout(()=>{window.dispatchEvent(new CustomEvent(Ve,{detail:o}))},350)}else if(t.richTextInline){let o=t.richTextInline;setTimeout(()=>{window.dispatchEvent(new CustomEvent($e,{detail:o}))},350)}}et();te();var st=ue(null);function j(t){let{className:o,localStorageId:n,children:a}=t,[i,r]=T(`root::SplitPanel:${n}`,350),[s,l]=y(!1),[c,m]=y(0),h=M(()=>new Set,[]),_=P(null),g=P(null),k={onResize:p=>(h.add(p),()=>{h.delete(p)})};if(x(()=>{let p=()=>l(!1);window.addEventListener("mouseup",p);let d=_.current;return d&&m(d.getBoundingClientRect().left),()=>window.removeEventListener("mouseup",p)},[]),x(()=>{let p=d=>{let b=d.clientX-c;r(b),h.forEach(S=>S())};return s&&window.addEventListener("mousemove",p),()=>window.removeEventListener("mousemove",p)},[s]),a?.length!==2)throw new Error("SplitPanel should have two <SplitPanel.Item> children.");let w={"--panel-size":`${i}px`};return e(st.Provider,{value:k,children:e("div",{className:I(o,"SplitPanel",s&&"dragging"),ref:_,style:w,children:[a[0],e("div",{className:"SplitPanel__divider",ref:g,onMouseDown:()=>l(!0)}),a[1]]})})}j.Item=t=>e("div",{className:I("SplitPanel__item",t.className,t.fluid?"fluid":"static"),children:t.children});function le(t,o,n=""){let a=ae({collectionId:t,slug:o}),i=new URLSearchParams(window.location.search);i.set("preview","true"),i.delete("locale"),i.delete("modal");let r=`${i.toString()}${window.location.hash}`;return n?`${ae({collectionId:t,slug:o,locale:n})}?${r}`:`${a}?${r}`}function Ge(t){let o=t.collection,n=t.slug,a=`${o}/${n}`,{roles:i}=ze(),r=window.firebase.user.email||"",s=Be(i,r);return e(Ae,{docId:a,readOnly:!s,children:e(lt,{...t,canEdit:s})})}function lt(t){let o=t.canEdit,n=t.collection,a=t.slug,i=`${n}/${a}`;He(i);let r=window.__ROOT_CTX.collections[n],s=X(),l=!!r?.url,[c,m]=T(`root::DocumentPage::previewVisible::${n}`,l),h=M(()=>(window.__ROOT_CTX.checks||[]).some(f=>!f.collections||f.collections.includes(n)),[n]),[_,g]=T("root::DocumentPage::checksVisible",!1),k=P(_);k.current=_;let[w,p]=T("root::DocumentPage::searchVisible",!1),d=P(w);d.current=w;let b=!!(window.__ROOT_CTX.ai||window.__ROOT_CTX.experiments?.ai),[S,z]=T("root::DocumentPage::aiVisible",!1),O=P(S);O.current=S,x(()=>{window.dispatchEvent(new CustomEvent("root:checks-visible",{detail:_}))},[_]),x(()=>{window.dispatchEvent(new CustomEvent("root:search-visible",{detail:w}))},[w]),x(()=>{window.dispatchEvent(new CustomEvent("root:ai-visible",{detail:S}))},[S]);let[F,q]=T("root::DocumentPage::searchPanelWidth",360),[U,K]=y(F),[$,J]=y(!1),Y=P(null);if(x(()=>{let v=()=>{let f=!k.current;g(()=>f),f&&(p(()=>!1),z(()=>!1))};return window.addEventListener("root:toggle-checks",v),()=>window.removeEventListener("root:toggle-checks",v)},[]),x(()=>{let v=()=>{let f=!d.current;p(()=>f),f&&(g(()=>!1),z(()=>!1),requestAnimationFrame(()=>{window.dispatchEvent(new CustomEvent("root:focus-search"))}))};return window.addEventListener("root:toggle-search",v),()=>window.removeEventListener("root:toggle-search",v)},[]),x(()=>{let v=()=>{let f=!O.current;z(()=>f),f&&(g(()=>!1),p(()=>!1))};return window.addEventListener("root:toggle-ai",v),()=>window.removeEventListener("root:toggle-ai",v)},[]),x(()=>{if(!$)return;let v=A=>{let G=Y.current;if(!G)return;let re=G.getBoundingClientRect(),ce=Math.max(240,Math.min(re.right-A.clientX,800));K(ce)},f=()=>{J(!1),K(A=>(q(()=>A),A))};return window.addEventListener("mousemove",v),window.addEventListener("mouseup",f),()=>{window.removeEventListener("mousemove",v),window.removeEventListener("mouseup",f)}},[$]),!r)return e("div",{children:"Could not find collection."});let ie=C(()=>{if(!l)return;let v=le(n,a),f=window.open(v,"_blank","noopener,noreferrer");f&&f.focus()},[l,n,a]),Q=C(()=>{o&&s.controller&&s.controller.flush()},[o,s.controller]),W=Le(),u=C(()=>{let v=s.controller?.getData()?.fields||{};W.open({data:v,onSave:f=>{s.controller&&f&&typeof f=="object"&&(s.controller.updateKey("fields",f),s.controller.flush()),W.close()}})},[s.controller]),D=C(()=>{window.dispatchEvent(new CustomEvent("root:toggle-search"))},[]),N=C(()=>{b&&window.dispatchEvent(new CustomEvent("root:toggle-ai"))},[b]),R=C(()=>{z(()=>!1)},[z]);return me([["mod+S",Q],["mod+shift+F",D],["mod+I",N]]),e(Xe,{children:e("div",{className:I("DocumentPage__layout",$&&"DocumentPage__layout--dragging"),ref:Y,children:[e(j,{className:"DocumentPage",localStorageId:"DocumentPage",children:[e(j.Item,{className:I("DocumentPage__side",(!l||!c)&&"DocumentPage__side--expanded"),children:[e("div",{className:"DocumentPage__side__header",children:[e("div",{className:"DocumentPage__side__header__nav",children:[e("a",{href:`/cms/content/${n}`,children:e(E,{className:"DocumentPage__side__header__back",children:e(ge,{size:16})})}),e("div",{className:"DocumentPage__side__header__docId",children:i})]}),e("div",{className:"DocumentPage__side__header__buttons",children:[e(se,{label:"You don't have access to edit this document",condition:!o,children:e(H,{className:"DocumentPage__side__header__saveButton",variant:"filled",color:"dark",size:"xs",compact:!0,leftIcon:e(xe,{size:16}),onClick:()=>Q(),disabled:!o,children:"Save"})}),e(se,{label:"You don't have access to edit this document",condition:!o,children:e(L,{label:"Edit JSON",disabled:!o,children:e(E,{className:"DocumentPage__side__header__editJson",onClick:()=>u(),disabled:!o,children:e(ve,{size:14})})})}),l&&e(V,{children:[e(L,{label:c?"Hide preview":"Show preview",children:e(E,{className:"DocumentPage__side__header__previewToggle",onClick:()=>m(!c),children:c?e(De,{size:16}):e(Ce,{size:16})})}),!c&&e(L,{label:"Open preview in new tab",children:e(E,{className:"DocumentPage__side__header__openNewTab",onClick:ie,children:e(oe,{size:16})})})]})]})]}),e("div",{className:I("DocumentPage__side__editor",(!l||!c)&&!_&&!w&&!S&&"DocumentPage__side__editor--centered"),children:e(Fe,{docId:i})})]}),e(j.Item,{className:I("DocumentPage__main",(!l||!c)&&"DocumentPage__main--hidden"),fluid:!0,children:l&&c&&e(Ge.Preview,{docId:i},i)})]}),h&&_&&e(ut,{docId:i}),w&&e(V,{children:[e("div",{className:"DocumentPage__searchDivider",onMouseDown:()=>J(!0)}),e("div",{className:"DocumentPage__search",style:{flexBasis:`${U}px`},children:e(Ye,{docId:i,autoFocus:!0,onClose:()=>p(()=>!1)})})]}),b&&S&&e(dt,{docId:i,onClose:R})]})})}function dt(t){let[o,n]=T("root::DocumentPage::aiPanelWidth",420),[a,i]=y(o),r=P(null),s=P(a),l=P(),c=M(()=>e(Ue,{variant:"panel",docContext:{docId:t.docId},onClose:t.onClose}),[t.docId,t.onClose]),m=C(()=>{let h=r.current?.parentElement;if(!h)return;s.current=a,h.classList.add("DocumentPage__layout--dragging");let _=w=>{let p=r.current?.parentElement;if(!p)return;let d=p.getBoundingClientRect(),b=Math.max(280,Math.min(d.right-w.clientX,800));s.current=b,i(b)},g=()=>{h.classList.remove("DocumentPage__layout--dragging"),window.removeEventListener("mousemove",_),window.removeEventListener("mouseup",k),l.current=void 0},k=()=>{g(),n(()=>s.current)};l.current=g,window.addEventListener("mousemove",_),window.addEventListener("mouseup",k)},[a,n]);return x(()=>()=>l.current?.(),[]),e(V,{children:[e("div",{className:"DocumentPage__aiDivider",ref:r,onMouseDown:m}),e("div",{className:"DocumentPage__ai",style:{flexBasis:`${a}px`},children:c})]})}function ut(t){let[o,n]=T("root::DocumentPage::checksPanelWidth",360),[a,i]=y(o),r=P(null),s=P(a),l=P(),c=M(()=>e(Ke,{docId:t.docId}),[t.docId]),m=C(()=>{let h=r.current?.parentElement;if(!h)return;s.current=a,h.classList.add("DocumentPage__layout--dragging");let _=w=>{let p=r.current?.parentElement;if(!p)return;let d=p.getBoundingClientRect(),b=Math.max(200,Math.min(d.right-w.clientX,800));s.current=b,i(b)},g=()=>{h.classList.remove("DocumentPage__layout--dragging"),window.removeEventListener("mousemove",_),window.removeEventListener("mouseup",k),l.current=void 0},k=()=>{g(),n(()=>s.current)};l.current=g,window.addEventListener("mousemove",_),window.addEventListener("mouseup",k)},[a,n]);return x(()=>()=>l.current?.(),[]),e(V,{children:[e("div",{className:"DocumentPage__checksDivider",ref:r,onMouseDown:m}),e("div",{className:"DocumentPage__checks",style:{flexBasis:`${a}px`},children:c})]})}var Qe={mobile:[430,932],tablet:[768,1024],desktop:[1440,800]};function mt(t){let o=new Intl.DisplayNames(["en"],{type:"language"}),a=t.split("_")[0];return`${o.of(a)||t} (${t})`}Ge.Preview=t=>{let o=X();if(o.loading)return null;let[n,a]=t.docId.split("/"),r=window.__ROOT_CTX.collections[n];if(!r)throw new Error(`collection not found: ${n}`);if(!r.url)return null;let s=r.domain||window.__ROOT_CTX.rootConfig.domain||"https://example.com",l=Re({collectionId:n,slug:a}),c=ae({collectionId:n,slug:a}),m=`${s}${l}`,[h,_]=y(m),[g,k]=T("root::DocumentPage::preview::device",""),[w,p]=T("root::DocumentPage::preview::expandVertically",!1),[d,b]=y({"--iframe-width":"100%","--iframe-height":"100%","--iframe-scale":"1"}),[S,z]=je("locale",""),O=P(null),F=P(null),q=o.controller.getLocales()||[],U=le(n,a,S),K=M(()=>[{value:"",label:"Select locale"},...q.map(u=>({value:u,label:mt(u)}))],[q]);function $(){if(document.hidden)return;let u=O.current;u.src="about:blank",window.requestAnimationFrame(()=>{u.src!==U?u.src=U:u.contentWindow.location.reload()})}x(()=>{let u=O.current;function D(){let R=u.contentWindow;if(R&&c===l&&!R.location.href.startsWith("about:blank")){let v=R.location.pathname;_(`${s}${v}`)}}u.addEventListener("load",D);let N=o.controller?.onFlush(()=>{$()});return()=>{N(),u.removeEventListener("load",D)}},[]),x(()=>{let u=O.current;u.src=U},[S]);let J=C(u=>{k(D=>{let N=D===u?"":u;return N===""&&p(!1),N})},[k,p]),Y=C(()=>{k(u=>(u&&p(D=>!D),u))},[k,p]),ie=C(()=>{o.controller&&o.controller.flush().then(()=>$())},[o.controller]),Q=C(()=>{let u=le(n,a,S),D=window.open(u,"_blank","noopener,noreferrer");D&&D.focus()},[n,a,S]),W=C(()=>{if(g===""){let B={"--iframe-width":"100%","--iframe-height":"100%","--iframe-scale":"1"};b(ee=>ee["--iframe-width"]===B["--iframe-width"]&&ee["--iframe-height"]===B["--iframe-height"]&&ee["--iframe-scale"]===B["--iframe-scale"]?ee:B);return}let u=F.current;if(!u)return;let D=u.getBoundingClientRect(),[N,R]=Qe[g],v=20,f=Math.max(D.width-2*v,0),A=Math.max(D.height-2*v,0),G=f>0&&N>0?f/N:1,re=A>0&&R>0?A/R:1,ce=Math.min(G,re,1),de=Number(ce.toFixed(4))||1,Ze=w?`${A/de}px`:`${R}px`,Z={"--iframe-width":`${N}px`,"--iframe-height":Ze,"--iframe-scale":String(de)};b(B=>B["--iframe-width"]===Z["--iframe-width"]&&B["--iframe-height"]===Z["--iframe-height"]&&B["--iframe-scale"]===Z["--iframe-scale"]?B:Z)},[g,w]);return x(()=>{W();let u=F.current;if(!u)return;let D=0,N=()=>{window.cancelAnimationFrame(D),D=window.requestAnimationFrame(W)},R=new window.ResizeObserver(N);return R.observe(u),window.addEventListener("resize",N),()=>{window.cancelAnimationFrame(D),R.disconnect(),window.removeEventListener("resize",N)}},[W]),e("div",{className:"DocumentPage__main__preview",children:[e(Je,{device:g,expandVertically:w,iframeUrl:h,localeOptions:K,selectedLocale:S,onToggleDevice:J,onToggleExpandVertically:Y,onReloadClick:ie,onOpenNewTab:Q,onLocaleChange:z}),e("div",{className:"DocumentPage__main__previewFrame","data-device":g||"full",ref:F,style:d,children:[e("div",{className:"DocumentPage__main__previewFrame__deviceLabel",style:{display:g?void 0:"none"},children:g?`${g}: ${Qe[g].join("x")}`:""}),e("div",{className:"DocumentPage__main__previewFrame__iframeWrap",children:e("iframe",{ref:O,title:"iframe preview"})})]})]})};export{Ge as DocumentPage};
@@ -1 +0,0 @@
1
- import{b as ae}from"./chunk-BZIRGB4W.js";import{a as te,c as ne,e as me}from"./chunk-HHMG665Z.js";import{b as ce,c as O,d as de,f as z}from"./chunk-KYDOSLTO.js";import{a as y}from"./chunk-VMT7JFAM.js";import"./chunk-54DVDYU6.js";import{a as le}from"./chunk-L4RHGQUG.js";import"./chunk-W3HIZQ4Z.js";import{a as I}from"./chunk-PJA7YP4A.js";import{b as ee}from"./chunk-62UWGWON.js";import{a as U}from"./chunk-I6ICVKEC.js";import{a as u}from"./chunk-HLMBCVRX.js";import{f as oe}from"./chunk-ORXEMIQC.js";import{a as ue,b as _e}from"./chunk-UEON4JAT.js";import{c as se}from"./chunk-5MV6XVGA.js";import{c as V,n as Y,p as Q,q as Z}from"./chunk-EGEB6N4J.js";import{f as w}from"./chunk-AL3TN2KI.js";import{Aa as A,Da as q,Ha as e,Pc as ie,U as L,Uc as re,W as $,a as g,c as B,ca as J,e as W,ea as v,g as C,j as T,oa as F,qa as K,ta as X,va as G}from"./chunk-NZHF733K.js";import"./chunk-KUCVLANF.js";import"./chunk-DTMZLUNY.js";import"./chunk-PVAE643M.js";T();T();var be={ADMIN:4,EDITOR:3,CONTRIBUTOR:2,VIEWER:1};function ge(o){return be[o]??0}function Se(o,s){return ge(o)>=ge(s)?o:s}function H(o,s,a){let t=o[s];o[s]=t?Se(t,a):a}function pe(o,s={}){let a={...s},t={};for(let n of o){let d=(n.users||[]).filter(Boolean);if(d.length===0)continue;let _=(n.collections||[]).filter(Boolean);if(_.length===0)for(let c of d)H(a,c,n.role);else{for(let c of d)H(a,c,"VIEWER");for(let c of _){t[c]||(t[c]={});for(let p of d)H(t[c],p,n.role)}}}return{projectRoles:a,collectionRoles:t}}function fe(o={}){return{id:o.id||`g_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`,name:o.name||"",role:o.role||"VIEWER",collections:o.collections?[...o.collections]:[],users:o.users?[...o.users]:[]}}T();function k(o){let s=o.size||28,[a,t]=g(!1),n=o.profile?.photoURL||"",d=o.profile?.displayName||o.email,_=w("EmailAvatar",o.className),c={width:s,height:s};return n&&!a?e("img",{className:_,style:c,src:n,alt:d,onError:()=>t(!0)}):e("svg",{className:_,style:c,viewBox:"0 0 28 28",role:"img","aria-label":d,children:[e("circle",{cx:"14",cy:"14",r:"14",fill:de(o.email)}),e("text",{x:"14",y:"14",textAnchor:"middle",dominantBaseline:"central",fill:"#fff",fontSize:"13",fontWeight:"600",children:ce(o.email)})]})}var ye=[{value:"ADMIN",label:"ADMIN"},{value:"EDITOR",label:"EDITOR"},{value:"CONTRIBUTOR",label:"CONTRIBUTOR"},{value:"VIEWER",label:"VIEWER"}];function xe(o){let{groups:s,onChange:a,collections:t,disabled:n}=o,d=C(()=>t.map(l=>({value:l,label:l})),[t]),[_,c]=g({});function p(l,i){a(s.map(m=>m.id===l?i(m):m))}function f(l){a(s.filter(i=>i.id!==l))}function P(){let l=s.length;a([...s,fe({name:"New group"})]),c(i=>({...i,[l]:!0}))}return e("div",{className:w(o.className,"PermissionGroupsBox"),children:[s.length===0?e("div",{className:"PermissionGroupsBox__empty",children:e(u,{size:"body-sm",weight:"semi-bold",color:"gray",children:"No permission groups yet. Create one to organize users by role and optionally scope access to specific collections."})}):e(L,{className:"PermissionGroupsBox__accordion",offsetIcon:!1,multiple:!0,state:_,onChange:c,children:s.map(l=>e(L.Item,{label:e("div",{className:"PermissionGroupsBox__trigger",children:[e("span",{className:"PermissionGroupsBox__trigger__name",children:l.name||"Untitled group"}),e(J,{color:"gray",radius:"sm",size:"xs",variant:"light",className:"PermissionGroupsBox__trigger__badge",children:[l.users.length," ",l.users.length===1?"user":"users"]})]}),children:e(Re,{group:l,collectionOptions:d,disabled:n,onChange:i=>p(l.id,()=>i),onDelete:()=>f(l.id)})},l.id))}),e("div",{className:"PermissionGroupsBox__addGroup",children:e(v,{variant:"default",size:"xs",radius:0,disabled:n,onClick:P,children:"+ Add group"})})]})}function Re(o){let{group:s,collectionOptions:a,disabled:t}=o,[n,d]=g(""),_=s.users.filter(r=>!O(r)),{profiles:c}=z(_);function p(r){o.onChange({...s,name:r})}function f(r){o.onChange({...s,role:r})}function P(r){o.onChange({...s,collections:r})}function l(r){let x=r.trim();if(!x||s.users.includes(x)){d("");return}o.onChange({...s,users:[...s.users,x]}),d("")}function i(r){o.onChange({...s,users:s.users.filter(x=>x!==r)})}function m(){window.confirm(`Delete the "${s.name||"Untitled group"}" group? This will remove its role assignments on next save.`)&&o.onDelete()}return e("div",{className:"PermissionGroupsBox__editor",children:[e("div",{className:"PermissionGroupsBox__editor__row",children:[e(G,{className:"PermissionGroupsBox__editor__name",label:"Group name",placeholder:"e.g. Blog Post Editors",value:s.name,radius:0,size:"xs",disabled:t,onChange:r=>p(r.target.value)}),e(A,{className:"PermissionGroupsBox__editor__role",label:"Role",data:ye,value:s.role,radius:0,size:"xs",disabled:t,onChange:r=>f(r)})]}),e(X,{className:"PermissionGroupsBox__editor__collections",label:"Collections",description:"Leave empty to apply project-wide. Otherwise restrict the group's role to the selected collections.",data:a,value:s.collections,radius:0,size:"xs",searchable:!0,clearable:!0,placeholder:"All collections (project-wide)",disabled:t,onChange:r=>P(r),dropdownComponent:"div"}),e("div",{className:"PermissionGroupsBox__editor__users",children:[e(u,{size:"body-sm",weight:"semi-bold",children:"Users"}),e("form",{className:"PermissionGroupsBox__editor__addUser",onSubmit:r=>{r.preventDefault(),l(n)},children:[e(G,{className:"PermissionGroupsBox__editor__addUser__email",placeholder:"grogu@example.com",type:"email",value:n,onChange:r=>d(r.target.value),radius:0,size:"xs",disabled:t}),e(v,{size:"xs",radius:0,color:"dark",type:"submit",disabled:t||!n.trim(),children:"Add user"})]}),s.users.length>0&&e("ul",{className:"PermissionGroupsBox__editor__userList",children:s.users.map(r=>{let x=c.get(r.toLowerCase())||null;return e("li",{className:"PermissionGroupsBox__editor__userItem",children:[e(k,{className:"PermissionGroupsBox__editor__userItem__avatar",email:r,profile:x,size:24}),e("span",{className:"PermissionGroupsBox__editor__userItem__email",children:r}),e($,{size:"sm",variant:"transparent",disabled:t,onClick:()=>i(r),title:`Remove ${r}`,children:e(re,{size:14})})]},r)})})]}),e("div",{className:"PermissionGroupsBox__editor__footer",children:e(v,{variant:"subtle",size:"xs",color:"red",compact:!0,disabled:t,leftIcon:e(ie,{size:14}),onClick:m,children:"Delete group"})})]})}T();function D(o){let{roles:s,onChange:a,currentUserIsAdmin:t}=o,[n,d]=g(""),_=Object.keys(s).filter(i=>!O(i)),{profiles:c}=z(_);function p(i,m){a({...s,[i]:m})}function f(i){let m={...s};delete m[i],a(m)}function P(i){let m=i.trim();d(""),!(!m||m in s)&&a({...s,[m]:"EDITOR"})}let l=se(Object.keys(s).map(i=>({email:i,role:s[i],profile:c.get(i.toLowerCase())||null})),"email");return e("div",{className:w(o.className,"ShareBox"),children:[e("form",{className:"ShareBox__addUser",onSubmit:i=>{i.preventDefault(),P(n)},children:[e(G,{className:"ShareBox__addUser__email",placeholder:"grogu@example.com",type:"email",value:n,onChange:i=>d(i.target.value),radius:0,size:"xs",disabled:!t}),e(v,{className:"ShareBox__addUser__button",size:"xs",radius:0,color:"dark",type:"submit",disabled:!t,children:"Add user"})]}),e("div",{className:"ShareBox__users",children:l.map(i=>e(D.User,{...i,currentUserIsAdmin:t,onRoleChange:p,onRemove:f},i.email))})]})}D.User=o=>{let s=o.email===window.firebase.user.email;return e("div",{className:"ShareBox__user",children:[e(k,{className:"ShareBox__user__avatar",email:o.email,profile:o.profile,size:24}),e(u,{className:"ShareBox__user__email",size:"body-sm",weight:"semi-bold",color:"gray",children:[o.email,s&&" (you)"]}),e("div",{className:"ShareBox__user__roleSelect",children:e(A,{data:[{value:"ADMIN",label:"ADMIN"},{value:"EDITOR",label:"EDITOR"},{value:"CONTRIBUTOR",label:"CONTRIBUTOR"},{value:"VIEWER",label:"VIEWER"},{value:"REMOVE",label:"REMOVE"}],value:o.role,radius:0,size:"xs",disabled:s||!o.currentUserIsAdmin,onChange:a=>{a==="REMOVE"?o.onRemove(o.email):o.onRoleChange(o.email,a)}})})]})};function we(o){if(!o)return"never";let s=Date.now()-o;return s<6e4?"just now":s<60*6e4?`${Math.floor(s/6e4)} min ago`:s<1440*6e4?`${Math.floor(s/(60*6e4))} hr ago`:new Date(o).toLocaleString()}function he(o){let s=window.firebase?.user?.email;if(!s)return!1;if(o[s]==="ADMIN")return!0;let a=s.split("@").at(-1);return!!(a&&o[`*@${a}`]==="ADMIN")}function Ne(){let o=ae(),[s,a]=g(!1),[t,n]=g(!1),[d,_]=g(!1),c=W(null);function p(){c.current!==null&&(window.clearInterval(c.current),c.current=null),n(!1),_(!1)}B(()=>p,[]),B(()=>{t&&o.running&&_(!0)},[t,o.running]);async function f(x){if(!(s||t)){a(!0);try{let S=await fetch("/cms/api/search.rebuild",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:x})});if(!S.ok){let j=await S.text().catch(()=>"");throw new Error(`HTTP ${S.status}: ${j||"rebuild failed"}`)}U({title:"Search index",message:x?"Full rebuild started.":"Incremental rebuild started.",color:"blue",autoClose:4e3}),n(!0),c.current=window.setInterval(()=>{o.refresh()},2e3),window.setTimeout(p,10*6e4)}catch(S){U({title:"Error",message:S?.message||String(S),color:"red",autoClose:!1})}finally{a(!1)}}}B(()=>{t&&d&&!o.running&&(p(),U({title:"Search index",message:"Rebuild complete.",color:"green",autoClose:3e3}))},[t,d,o.running]);let P=o.status.lastRun,l=o.status.docCount,i=o.status.fieldCount,m=o.status.shardCount,r=o.running||s;return e("div",{className:"SettingsPage__section",children:[e("div",{className:"SettingsPage__section__left",children:[e(y,{className:"SettingsPage__section__left__title",children:"Site Admin"}),e(u,{className:"SettingsPage__section__body",size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:"Project-wide administrative actions. Only admins see this section."})})]}),e(I,{className:"SettingsPage__section__right",children:e("div",{className:"SettingsPage__section__setting",children:[e(u,{size:"body",weight:"semi-bold",children:"Search index"}),e(u,{size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:"Powers the Cmd+K global search. Rebuilds run automatically on a schedule; trigger a manual rebuild here if you want immediate results (e.g. after a schema change)."})}),e("div",{className:"SettingsPage__siteAdmin__searchStats",children:[e("div",{children:[e("strong",{children:"Last indexed:"})," ",we(P)]}),e("div",{children:[e("strong",{children:"Indexed docs:"})," ",l.toLocaleString()]}),e("div",{children:[e("strong",{children:"Indexed fields:"})," ",i.toLocaleString()]}),e("div",{children:[e("strong",{children:"Shards:"})," ",m]})]}),e("div",{className:"SettingsPage__siteAdmin__searchButtons",children:[e(v,{variant:"default",size:"xs",compact:!0,loading:r,onClick:()=>f(!1),children:"Rebuild incremental"}),e(v,{variant:"default",size:"xs",compact:!0,loading:r,onClick:()=>{window.confirm("Force a full rebuild? This wipes the existing index and reindexes every doc from scratch.")&&f(!0)},children:"Force full rebuild"})]})]})})]})}function Be(o,s){return JSON.stringify(o)===JSON.stringify(s)}function Ge(){let o=window.__ROOT_CTX.rootConfig.projectId||"default",s=window.__ROOT_CTX.collections||{},a=C(()=>Object.keys(s).sort(),[s]),t=window.firebase.db,n=V(t,"Projects",o),[d,_]=g(!0),[c,p]=g(!1),[f,P]=g({roles:{},permissionGroups:[]}),[l,i]=g({roles:{},permissionGroups:[]});B(()=>{Y(n).then(h=>{let b=h.data()||{},N={roles:b.roles||{},permissionGroups:b.permissionGroups||[]};P(N),i({roles:{...N.roles},permissionGroups:N.permissionGroups.map(E=>({...E}))}),_(!1)})},[]);let m=he(f.roles),r=!Be(f,l);function x(h){i(b=>({...b,roles:h}))}function S(h){i(b=>({...b,permissionGroups:h}))}function j(){i({roles:{...f.roles},permissionGroups:f.permissionGroups.map(h=>({...h}))})}async function ve(){c||!r||(p(!0),await ee(async()=>{let{projectRoles:h,collectionRoles:b}=pe(l.permissionGroups,l.roles);await Z(n,{roles:h,permissionGroups:l.permissionGroups});let N=f.permissionGroups.flatMap(R=>R.collections||[]),E=new Set([...Object.keys(b),...N]);for(let R of E){let Pe=V(t,"Projects",o,"Collections",R);await Q(Pe,{roles:b[R]||{}},{merge:!0})}let M={roles:h,permissionGroups:l.permissionGroups};P(M),i({roles:{...M.roles},permissionGroups:M.permissionGroups.map(R=>({...R}))}),oe("acls.save_groups",{metadata:{groupCount:l.permissionGroups.length,userCount:Object.keys(h).length,collections:Array.from(E)}}),U({title:"Saved",message:"Sharing settings updated.",color:"green",autoClose:3e3})}),p(!1))}return e("div",{className:"SettingsPage__section SettingsPage__section__users",children:[e("div",{className:"SettingsPage__section__left",children:[e(y,{className:"SettingsPage__section__left__title",children:"Share"}),e(u,{className:"SettingsPage__section__body",size:"body-sm",weight:"semi-bold",color:"gray",children:[e("p",{children:"Share access to the CMS. To share with everyone in a domain, use *@example.com."}),e("ul",{children:[e("li",{children:"VIEWER: view docs but not edit"}),e("li",{children:"CONTRIBUTOR: view and edit docs, but not publish"}),e("li",{children:"EDITOR: view, edit, and publish docs"}),e("li",{children:"ADMIN: all of the above and change sharing settings"})]}),e("p",{children:["Use ",e("strong",{children:"groups"})," to manage many users at once and optionally scope a role to specific collections."]})]})]}),e(I,{className:"SettingsPage__section__right",children:e("div",{className:"SettingsPage__share",children:[e(K,{visible:d,loaderProps:{color:"gray",size:"xl"}}),e("div",{className:"SettingsPage__share__subsection",children:[e(y,{className:"SettingsPage__section__right__title",size:"h3",children:"Users"}),e(D,{className:"SettingsPage__section__users__sharebox",roles:l.roles,onChange:x,currentUserIsAdmin:m})]}),e("div",{className:"SettingsPage__share__subsection",children:[e(y,{className:"SettingsPage__section__right__title",size:"h3",children:"Groups"}),e(xe,{groups:l.permissionGroups,onChange:S,collections:a,disabled:!m})]}),e("div",{className:"SettingsPage__share__saveBar",children:[e(u,{size:"body-sm",weight:"semi-bold",color:"gray",children:r?"You have unsaved changes.":"All changes saved."}),e("div",{className:"SettingsPage__share__saveBar__actions",children:[e(v,{variant:"default",size:"xs",radius:0,disabled:!r||c,onClick:j,children:"Discard"}),e(v,{size:"xs",radius:0,color:"dark",loading:c,disabled:!r||!m,onClick:ve,children:"Save changes"})]})]})]})})]})}function Do(){ue("Settings");let o=me(),s=ne(),a=le(),t=!a.loading&&he(a.roles);return e(_e,{children:e("div",{className:"SettingsPage",children:[e(Ge,{}),e("div",{className:"SettingsPage__section",children:[e("div",{className:"SettingsPage__section__left",children:[e(y,{className:"SettingsPage__section__left__title",children:"Site Settings"}),e(u,{className:"SettingsPage__section__body",size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:"These settings apply to the project. Only admins can change them."})})]}),e(I,{className:"SettingsPage__section__right",children:te.map(n=>e("div",{className:"SettingsPage__section__setting",children:[e(u,{size:"body",weight:"semi-bold",children:n.name}),e(u,{size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:n.description})}),e(F,{autosize:!0,minRows:2,maxRows:4,value:s.settings[n.key]||"",placeholder:n.placeholder,onChange:d=>s.setSettings(n.key,d.currentTarget.value)}),n.ui&&e("div",{children:n.ui(s.settings[n.key])})]},n.key))})]}),t&&e(Ne,{}),e("div",{className:"SettingsPage__section",children:[e("div",{className:"SettingsPage__section__left",children:[e(y,{className:"SettingsPage__section__left__title",children:"User Preferences"}),e(u,{className:"SettingsPage__section__body",size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:"These settings are for you only."})})]}),e(I,{className:"SettingsPage__section__right",children:e("div",{className:"SettingsPage__section__userPref",children:[e("div",{className:"SettingsPage__section__userPref__description",children:[e(u,{className:"SettingsPage__section__userPref__description__title",size:"body",weight:"semi-bold",children:"Enable EditorJS Editor (legacy)"}),e(u,{className:"SettingsPage__section__userPref__description__body",size:"body-sm",weight:"semi-bold",color:"gray",children:e("p",{children:["Replaces the"," ",e("a",{href:"https://lexical.dev/",target:"_blank",rel:"noopener noreferrer nofollow",children:"Lexical"})," ","(default) rich text editor with the"," ",e("a",{href:"https://editorjs.io/",target:"_blank",rel:"noopener noreferrer nofollow",children:"EditorJS"})," ","(legacy) version."]})})]}),e("div",{className:"SettingsPage__section__userPref__input",children:e(q,{color:"dark",checked:o.preferences.EnableEditorJSEditor,onChange:n=>{let d=n.currentTarget.checked;o.setPreference("EnableEditorJSEditor",d)}})})]})})]})]})})}export{Do as SettingsPage};
@@ -1 +0,0 @@
1
- import{a as mt}from"./chunk-CGCKJFL4.js";import{f as pt,g as gt,h as ft,i as Ie,j as M,k as Ee,l as Q,m as ht}from"./chunk-SKEP5WYH.js";import{c as tt}from"./chunk-AFWBSIPL.js";import{a as Qe}from"./chunk-62UWGWON.js";import{a as F,c as xe}from"./chunk-I6ICVKEC.js";import{a as ce,f as et}from"./chunk-ORXEMIQC.js";import{a as ue,d as Se}from"./chunk-5MV6XVGA.js";import{c as Xe,q as Ze,r as Ye,t as de,u as ye}from"./chunk-EGEB6N4J.js";import{f as B}from"./chunk-AL3TN2KI.js";import{$ as Fe,A as Ve,Aa as le,Ab as Ce,Ca as se,Ea as Je,Ec as Y,Fc as dt,Ga as re,Ha as i,Ob as st,Pc as ct,R as Be,V as He,W as X,Wc as ut,Y as G,a as g,c as U,e as ve,ea as E,fa as qe,g as J,ga as z,ha as $e,i as oe,j as _e,jc as rt,lc as De,m as be,ma as je,mb as it,mc as Te,o as Me,oa as Z,ob as at,p as Le,qa as We,ra as k,sa as we,ub as ot,va as ne,w as Re,wb as nt,xb as lt,za as Ke}from"./chunk-NZHF733K.js";import{d as O,j as ae,k as ze}from"./chunk-KUCVLANF.js";ze();_e();function vt(e,l){let t;return(...a)=>{window.clearTimeout(t),t=window.setTimeout(()=>{e(...a)},l)}}function _t(e){e||(e=6);let l=[],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",a=t.length;for(let o=0;o<e;o++)l.push(t.charAt(Math.floor(Math.random()*a)));return l.join("")}var H=class{constructor(){this.events=new Map}on(l,t){let a=_t(6),o=this.events.get(l);return o||(o=new Map,this.events.set(l,o)),o.set(a,t),()=>{this.off(l,a)}}off(l,t){let a=this.events.get(l);a&&(a.delete(t),a.size===0&&this.events.delete(l))}dispatch(l,...t){let a=this.events.get(l);a&&a.forEach(o=>o(...t))}dispose(){this.events.clear()}};var pe=class{constructor(){this.subscribers=new Set;this.subtreeSubscribers=new Set;this.children=new Map}},ge=class extends H{constructor(t){super();this.root=new pe;this.data=t||{}}get(t){return this.getValueFromPath(t,this.data)}set(t,a){if(t===""){ue(a)&&this.setData(a);return}this.update({[t]:a})}update(t){let a=new Map,o=(s,d,c)=>{a.set(s,c),ue(d)&&ue(c)&&(Object.entries(c).forEach(([u,m])=>{let _=d[u];Se(_,m)||o(`${s}.${u}`,_,m)}),Object.keys(d).forEach(u=>{u in c||o(`${s}.${u}`,d[u],void 0)}))};Object.entries(t).forEach(([s,d])=>{let c=this.data,u=s.split("."),m=u.pop();for(let C of u)c[C]||(c[C]={}),c=c[C];let _=c[m];c[m]=d,this.dispatch("VALUE_CHANGE",s,d),o(s,_,d)});let n=new Map;a.forEach((s,d)=>{this.collectSubtreeNotifications(d,n)}),a.forEach((s,d)=>{let c=this.getTrieNode(d);c&&c.subscribers.size>0&&c.subscribers.forEach(u=>u(s))}),n.forEach((s,d)=>{let c=this.get(d);s.subtreeSubscribers.forEach(u=>u(c))}),this.dispatch("CHANGE",this.data)}setData(t){let a=this.data;this.notifyOnUpdate(this.root,"",a,t),this.data=t,this.dispatch("CHANGE",this.data)}subscribe(t,a){let o=this.getTrieNode(t,!0);return o.subscribers.add(a),window.setTimeout(()=>{let n=this.get(t);n!==void 0&&a(n)}),()=>{o.subscribers.delete(a)}}subscribeSubtree(t,a){let o=this.getTrieNode(t,!0);return o.subtreeSubscribers.add(a),window.setTimeout(()=>{let n=this.get(t);n!==void 0&&a(n)}),()=>{o.subtreeSubscribers.delete(a)}}getDataSnapshot(){return this.data}dispose(){super.dispose(),this.data={},this.root.subscribers.clear(),this.root.subtreeSubscribers.clear(),this.root.children.clear()}notifyOnUpdate(t,a,o,n){let s=this.getValueFromPath(a,o),d=this.getValueFromPath(a,n);Se(s,d)||(t.subscribers.forEach(c=>c(d)),t.subtreeSubscribers.forEach(c=>c(d))),t.children.forEach((c,u)=>{let m=a?`${a}.${u}`:u;this.notifyOnUpdate(c,m,o,n)})}collectSubtreeNotifications(t,a){let o=this.root;if(o.subtreeSubscribers.size>0&&a.set("",o),!t)return;let n="";for(let s of t.split(".")){if(o=o.children.get(s),!o)return;n=n?`${n}.${s}`:s,o.subtreeSubscribers.size>0&&a.set(n,o)}}getValueFromPath(t,a){if(!t)return a;let o=t.split("."),n=a;for(let s of o){if(n===null||typeof n!="object"||!(s in n))return;n=n[s]}return n}getTrieNode(t,a=!1){if(!t)return this.root;let o=t.split("."),n=this.root;for(let s of o){if(!n.children.has(s))if(a)n.children.set(s,new pe);else return;n=n.children.get(s)}return n}};var bt=3*ce.second,Et=5*ce.minute;var kt=30*ce.second,ke=class extends H{constructor(t){super();this.pendingUpdates=new Map;this.saveState="NO_CHANGES";this.autolock=!1;this.autolockReason="autolock";this.autolockApplied=!1;this.readOnly=!1;this.autoSave=!0;this.flushOnStop=!0;this.started=!1;this.queueChanges=vt(()=>this.flush(),bt);this.projectId=window.__ROOT_CTX.rootConfig.projectId;let[a,o]=t.split("/");this.docId=t,this.collectionId=a,this.slug=o,this.db=window.firebase.db,this.docRef=Xe(this.db,"Projects",this.projectId,"Collections",a,"Drafts",o),this.store=new ge({id:this.docId,collection:this.collectionId,slug:this.slug,sys:{}}),this.store.on("CHANGE",s=>{this.dispatch("CHANGE",s)}),this.store.on("VALUE_CHANGE",(s,d)=>{this.dispatch("VALUE_CHANGE",s,d)});let n=window.__ROOT_CTX.collections[a];n&&(this.autolock=!!n.autolock,n.autolockReason&&(this.autolockReason=n.autolockReason))}async start(){this.started||(this.started=!0,this.dbUnsubscribe=Ye(this.docRef,t=>{if(t.metadata.hasPendingWrites)return;let a=t.data()||{};this.pendingUpdates.size>0&&Ft(a,Object.fromEntries(this.pendingUpdates)),this.store.setData(a)}))}stop(){this.started&&(this.dbUnsubscribe&&this.dbUnsubscribe(),this.flushOnStop&&this.flush(),this.started=!1)}onChange(t){return this.on("CHANGE",t)}onSaveStateChange(t){return this.on("SAVE_STATE_CHANGE",t)}onFlush(t){return this.on("FLUSH",t)}subscribe(t,a){return this.store.subscribe(t,a)}subscribeSubtree(t,a){return this.store.subscribeSubtree(t,a)}getData(){return this.store.getDataSnapshot()}getValue(t){return this.store.get(t)}async updateKey(t,a){this.readOnly||(a===void 0?this.pendingUpdates.set(t,de()):this.pendingUpdates.set(t,a),this.store.set(t,a),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges())}async updateKeys(t){if(!this.readOnly){for(let a in t){let o=t[a];o==null?this.pendingUpdates.set(a,de()):this.pendingUpdates.set(a,o)}this.store.update(t),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges()}}async removeKey(t){this.readOnly||(this.pendingUpdates.set(t,de()),this.store.set(t,void 0),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges())}setSaveState(t){let a=this.saveState;t==="SAVED"&&a!=="SAVING"||(this.saveState=t,t==="SAVED"&&window.setTimeout(()=>{this.saveState==="SAVED"&&this.setSaveState("NO_CHANGES")},bt),this.dispatch("SAVE_STATE_CHANGE",t))}removePublishingLock(){this.autolockApplied=!0,this.removeKey("sys.publishingLocked"),this.flush()}async flush(t){if(this.readOnly||this.pendingUpdates.size===0)return;let a=Object.fromEntries(this.pendingUpdates);a["sys.modifiedAt"]=ye(),a["sys.modifiedBy"]=window.firebase.user.email,this.autolock&&!this.autolockApplied&&!this.store.get("sys.publishingLocked")&&(this.autolockApplied=!0,a["sys.publishingLocked"]={lockedAt:ye(),lockedBy:window.firebase.user.email,reason:this.autolockReason}),this.pendingUpdates.clear();try{this.setSaveState("SAVING"),await Ze(this.docRef,a),this.setSaveState("SAVED"),t?.quiet||this.dispatch("FLUSH"),et("doc.save",{metadata:{docId:this.docId},throttle:Et,throttleId:this.docId})}catch(o){console.error("failed to update doc:",o),this.setSaveState("ERROR");let n=Qe(o);F({title:`Failed to save ${this.slug}`,message:n||`Something went wrong while saving ${this.slug}`,color:"red",autoClose:!1});for(let s in a)s.startsWith("sys.")||this.pendingUpdates.has(s)||(this.pendingUpdates.set(s,a[s]),this.queueChanges(),console.log("re-queued updates"),console.log(this.pendingUpdates))}}getLocales(){let t=this.store.get("sys.locales");return t||["en"]}setLocales(t){this.updateKey("sys.locales",t)}async dispose(){super.dispose(),this.stop()}};function Ft(e,l){for(let t in l){let a=l[t];if(t.includes(".")){let[o,n]=At(t);e[o]??={},Ft(e[o],{[n]:a})}else typeof a>"u"?delete e[t]:e[t]=a}}function At(e){let l=e.indexOf("."),t=e.substring(0,l),a=e.substring(l+1);return[t,a]}var Ae=ae(null);function ci(e){let[l,t]=g(!0),a=J(()=>new ke(e.docId),[e.docId]);a.readOnly=e.readOnly??!1,a.autoSave=e.autoSave??!0,a.flushOnStop=e.flushOnStop??!0,U(()=>(t(!0),a.onChange(n=>{t(!1),tt(n.id,n)}),a.start(),()=>a.dispose()),[a]),U(()=>{let n,s=()=>{document.hidden||document.visibilityState!=="visible"?n=window.setTimeout(()=>{a.stop()},kt):(n&&(clearTimeout(n),n=void 0),a.started||a.start())};return document.addEventListener("visibilitychange",s),()=>{document.removeEventListener("visibilitychange",s),n&&clearTimeout(n)}},[a]);let o=J(()=>({loading:l,controller:a}),[l,a]);return i(Ae.Provider,{value:o,children:e.children})}function ui(e){return i(Ae.Provider,{value:e.value,children:e.children})}function fe(){let e=oe(Ae);if(!e)throw new Error("useDraftDoc() should be used within a <DraftDocProvider>");return e}function pi(e){let{controller:l}=fe();U(()=>l.onSaveStateChange(e),[l])}function gi(e){let{controller:l}=fe();U(()=>l.onChange(e),[l])}function fi(e,l){let{controller:t}=fe();U(()=>t.subscribe(e,l),[t])}function wt(e,l){let{controller:t}=fe(),[a,o]=g(t.getValue(e)??l);return U(()=>t.subscribe(e,s=>{o(s)}),[t]),[a,s=>{o(s),s==null?t.removeKey(e):t.updateKey(e,s)}]}ze();Re();Re();_e();var Pt=["drive.google.com","docs.google.com"];function he(e){try{let l=new URL(e);if(!Pt.includes(l.hostname))return null;if(l.searchParams.has("id"))return l.searchParams.get("id");let t=l.pathname.split("/"),a=t.findIndex(o=>o==="d");if(a!==-1&&a<t.length-1)return t[a+1]}catch{return null}return null}async function xt(e,l){let t="https://www.googleapis.com/auth/drive.readonly";(!e.isLoggedIn()||!e.hasScope(t))&&await e.login({scopes:[t]});let a=window.gapi;if(!a||!a.client||!a.client.drive)throw new Error("Google Drive API not loaded");let o=a.auth.getToken()?.access_token;if(!o)throw new Error("No Google Drive access token found");let[n,s]=await Promise.all([a.client.drive.files.get({fileId:l,fields:"name,mimeType,size",supportsAllDrives:!0}),fetch(`https://www.googleapis.com/drive/v3/files/${l}?alt=media&supportsAllDrives=true`,{headers:{Authorization:`Bearer ${o}`}})]),d=n.result;if(!s.ok)throw new Error(`Failed to download file from Drive: ${s.statusText}`);let c=await s.blob();return new File([c],d.name,{type:d.mimeType})}_e();var Nt=["1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"],Ot=["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"];function yt(e){let[l,t]=g("simple"),[a,o]=g(!1),[n,s]=g(!1),[d,c]=g(null),[u,m]=g(""),[_,C]=g(e.initialWidth||1600),[p,w]=g(e.initialHeight||900),[y,q]=g("16:9"),$=!!(window.__ROOT_CTX?.experiments||{}).ai;async function L(){if(!u){F({title:"Prompt required",message:"Please enter a prompt to generate an image.",color:"red"});return}o(!0);try{let v=await(await fetch("/cms/api/ai.generate_image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:u,aspectRatio:y})})).json();if(v.success&&v.image)c(v.image);else throw new Error(v.error||"Failed to generate image")}catch(f){console.error(f),F({title:"Generation failed",message:f.message||"Unknown error",color:"red"})}finally{o(!1)}}function te(f){f.preventDefault();let v=new FormData(f.target),b=parseInt(v.get("width"),10),D=parseInt(v.get("height"),10),W=v.get("backgroundColor"),A=v.get("label")||`${b}x${D}`,N=[];if(N.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${b}" height="${D}" viewBox="0 0 ${b} ${D}"><rect width="${b}" height="${D}" fill="${W}" />`),A){let ie=b*.5/(A.length*.6);N.push(`<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-size="${ie}" fill="#fff">${A}</text>`)}N.push("</svg>");let R=N.join(""),K=new TextEncoder().encode(R),me={src:`data:image/svg+xml;base64,${btoa(String.fromCharCode(...K))}`,filename:"placeholder.svg",width:b,height:D,alt:""};e.onSubmit(me)}async function j(){if(d){s(!0);try{let v=await(await fetch(d)).blob(),b=new File([v],"generated-image.png",{type:"image/png"}),{uploadFileToGCS:D}=await import("./gcs-L33FIRZU.js"),W=await D(b),[A,N]=y.split(":").map(Number),R=1600,V=Math.round(R*N/A),K={...W,width:R,height:V,alt:u};e.onSubmit(K)}catch(f){console.error(f),F({title:"Save failed",message:f.message||"Failed to upload image",color:"red"})}finally{s(!1)}}}return i(se,{gap:"md",children:[$&&i(Ke,{value:l,onChange:f=>t(f),data:[{label:"Simple",value:"simple"},{label:i(z,{gap:5,children:[i(Y,{size:16}),i("span",{children:"Generate with AI"})]}),value:"ai"}],fullWidth:!0}),l==="simple"?i("form",{onSubmit:te,children:[i(se,{gap:"xs",children:[i(ne,{label:"Width",name:"width",type:"number",value:_,onChange:f=>C(parseInt(f.currentTarget.value,10)),"data-autofocus":!0}),i(ne,{label:"Height",name:"height",type:"number",value:p,onChange:f=>w(parseInt(f.currentTarget.value,10))}),i(ne,{name:"label",label:"Label",defaultValue:""}),i($e,{name:"backgroundColor",label:"Background color",format:"hex",defaultValue:"#868e96",swatches:Ot})]}),i(z,{justify:"flex-end",mt:"md",children:i(E,{variant:"filled",type:"submit",children:"Create"})})]}):i(se,{gap:"xs",children:[i(le,{label:"Aspect Ratio",data:Nt,value:y,onChange:f=>q(f)}),i(Z,{label:"Prompt",placeholder:"Describe the image you want to generate...",minRows:3,value:u,onChange:f=>m(f.currentTarget.value),"data-autofocus":!0,required:!0}),d&&i(je,{src:d,alt:"Generated preview",height:200,fit:"contain"}),i(z,{justify:"flex-end",mt:"md",children:[i(E,{variant:"light",onClick:L,loading:a,disabled:n||!u,leftIcon:i(Y,{size:16}),children:a?"Generating...":"Preview"}),i(E,{variant:"filled",onClick:j,loading:n,disabled:!d||a,children:n?"Saving...":"Save"})]})]})]})}var Ut=["image/gif","image/jpeg","image/png","image/svg+xml","image/webp"],St=ae(null),Gt=Le(()=>import("./ImageEditorDialog-4H665KK2.js").then(e=>({default:e.ImageEditorDialog})));function ee(){let e=oe(St);if(!e)throw new Error("useFileField() should be called within a <FileFieldContext.Provider>");return e}function zt(e){let{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n}=e,s=Ve(),d=ve(null),[c,u]=g(!1),[m,_]=g(!1),[C,p]=g(!1),w=mt(),y=e.allowEditing!==!1,[q,Pe]=g("hash"),[$,L]=g(null),[te,j]=g(!1),[f,v]=g(null),b=e.accept??l.exts??(e.variant==="image"?Ut:[]),D=t?.alt||"",W=l.alt!==!1;async function A(r,S,h){try{n("loading");let P=h?.namingMode||(l.preserveFilename?"clean":"hash"),I=l.cacheControl||(P==="clean"?"no-cache":void 0),x=await pt(r,{namingMode:P,checkExists:h?.checkExists??!1,cacheControl:I});!x.alt&&Ct(x.filename)&&D&&(x.alt=D),S&&(x.originalSrc=S),a(x),n("complete"),L(null),v(null)}catch(P){console.error("upload failed"),console.error(P),n("error"),F({title:"Upload failed",message:"Failed to upload: "+String(P),color:"red",autoClose:!1})}}async function N(){n("loading");try{let r=t?.gcsPath||t?.src;r&&await gt(r),a(null),n(null),F({message:"File deleted from GCS",color:"green"})}catch(r){console.error(r),n("error"),F({title:"Delete failed",message:String(r),color:"red"})}finally{_(!1)}}function R(){if(!y&&t?.src){_(!0);return}a(null)}async function V(r,S){if(!r)return;if(L(null),v(null),j(!1),typeof r=="string"&&!S?.as){let I=he(r);if(I){try{if(!w.enabled){console.warn("Google API integration is not enabled for this project. Specify the `gapi` config in your root.config.ts to enable pasting from Google Drive URLs.");return}n("loading"),F({message:"Downloading from Google Drive...",loading:!0,autoClose:!1,id:"gdrive-download"});let x=await xt(w,I);xe("gdrive-download"),V(x)}catch(x){console.error(x),n("error"),xe("gdrive-download"),F({title:"Google Drive import failed",message:x.message||"Failed to download",color:"red"})}return}}S?.as==="svg"&&typeof r=="string"&&(r=new File([new Blob([r],{type:"image/svg+xml"})],"untitled.svg",{type:"image/svg+xml"}));let h=r,P=Ie(h.name);if(b.length>0&&!b.some(I=>I.endsWith(P)||I===`*/${P}`||I==="*/*"||I===h.type)){F({title:"Invalid file type",message:`File type ${P} is not allowed.`,color:"red",autoClose:!0});return}if(q==="clean"&&e.showNamingOptions){n("loading");let x=`${window.__ROOT_CTX.rootConfig.projectId}/uploads/${h.name}`;try{if(await ft(x)){L(h),v(`https://storage.googleapis.com/${window.firebase.storage.app.options.storageBucket}/${x}`),n(null);return}}catch(Ge){console.warn("Failed to check file existence",Ge)}}A(h,void 0,{namingMode:q})}function K(){d.current?.focus()}function Ne(){if(t?.src)if(Ee(t.src)){let r=document.createElement("a");r.href=ht(t.src),t.filename&&(r.download=t.filename),document.body.appendChild(r),r.click(),document.body.removeChild(r)}else window.open(t.src,"_blank")}function me(){let r=document.createElement("input");r.type="file",b.length>0&&(r.accept=b.join(",")),r.onchange=S=>{let h=S.target;h.files&&h.files.length>0&&V(h.files[0])},r.click(),r.remove()}function Oe(){u(!0)}function Ue(){p(!0)}function ie(r){t?.src&&a({...t,alt:r||""})}async function It(){let r=t;if(r?.src){n("loading");try{let S=await window.fetch("/cms/api/ai.generate_alt_text",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({imageUrl:r.src})}),h=await S.json();if(!S.ok||!h.success)throw new Error(h.error||"Failed to generate alt text");h.altText&&ie(h.altText)}catch(S){F({title:"Sorry, something went wrong.",message:S.message||"Unknown error",color:"red",autoClose:!0})}finally{n("complete")}}}return i(St.Provider,{value:{field:l,variant:e.variant,value:t,setValue:a,loadingState:o,removeFile:R,acceptedFileTypes:b,handleFile:V,focusDropZone:K,requestGenerateAltText:It,requestFileUpload:me,requestFileDownload:Ne,requestPlaceholderModalOpen:Oe,requestImageEditorOpen:Ue,showAltText:W,altText:D,setAltText:ie,allowEditing:y},children:[i(we,{size:"sm",opened:c,onClose:()=>u(!1),title:"Placeholder image",centered:!0,overlayColor:s.colorScheme==="dark"?s.colors.dark[9]:s.colors.gray[2],children:i(yt,{onSubmit:r=>{a(r),u(!1)}})}),i(we,{size:"sm",opened:m,onClose:()=>_(!1),title:"Delete file?",centered:!0,overlayColor:s.colorScheme==="dark"?s.colors.dark[9]:s.colors.gray[2],children:[i(G,{size:"sm",mb:"lg",children:"Are you sure you want to delete this file from GCS? This action cannot be undone."}),i(z,{grow:!0,spacing:"xs",children:[i(E,{variant:"default",onClick:()=>_(!1),disabled:o==="loading",children:"Cancel"}),i(E,{color:"red",onClick:N,loading:o==="loading",children:"Delete"})]})]}),C&&t?.src&&i(Me,{fallback:null,children:i(Gt,{opened:C,onClose:()=>p(!1),src:t.src,originalSrc:t.originalSrc,filename:t.filename,initialWidth:parseInt(t.width),initialHeight:parseInt(t.height),onSave:r=>{A(r,t.originalSrc||t.src),p(!1)}},t.src)}),$?i("div",{className:"FileField__overwriteWarning",children:[i("div",{className:"FileField__overwriteWarning__header",children:i(G,{size:"sm",color:"red",weight:700,children:"File already exists"})}),i(G,{size:"sm",children:["A file named ",i("strong",{children:$.name})," already exists."]}),f&&i(G,{size:"sm",className:"FileField__overwriteWarning__link",children:i("a",{href:f,target:"_blank",rel:"noopener noreferrer",children:["View existing file ",i(lt,{size:12})]})}),i("div",{className:"FileField__overwriteWarning__checkbox",children:i(qe,{label:"Confirm overwrite",checked:te,onChange:r=>j(r.currentTarget.checked)})}),i(z,{grow:!0,spacing:"xs",className:"FileField__overwriteWarning__actions",children:[i(E,{variant:"default",onClick:()=>{L(null),v(null),j(!1)},disabled:o==="loading",children:"Cancel"}),i(E,{disabled:!te,onClick:()=>A($,void 0,{namingMode:"clean"}),color:"red",loading:o==="loading",children:"Overwrite"})]})]}):i(O,{children:[i("div",{className:B("FileField",e.showNamingOptions&&"FileField--withOptions"),children:[i(T.Dropzone,{ref:d}),t?.src?i(T.Preview,{}):i(T.InvisibleDropzone,{children:i(T.Empty,{})})]}),e.showNamingOptions&&!t&&i("div",{className:"FileField__settings",style:{marginTop:8},children:i(le,{label:"File name options",size:"xs",itemComponent:Mt,data:[{value:"hash",label:"Hash the file name",description:"The filename will be hashed so the file's original name won't be exposed."},{value:"hash-path",label:"Use a hashed path with the original file name",description:"Use the original file name, but put it inside a hashed directory."},{value:"clean",label:"Use the original file name only",description:"The file will be uploaded to the bucket as-is, without a hashed directory."}],value:q,onChange:r=>Pe(r||"hash"),disabled:o==="loading"||!!t})})]})]})}function T(e){let l=e.field,[t,a]=wt(e.deepKey),[o,n]=g(null);return i(zt,{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n,variant:e.variant,allowEditing:e.allowEditing})}T.Preview=()=>{let e=ee(),[l,t]=g(!1),[a,o]=g(!1),n=window.__ROOT_CTX.experiments||{},s=!!e.value?.width&&!!e.value?.height&&Number(e.value.width)>0&&Number(e.value.height)>0,d=e.value?.filename||"",c=Q(d),u=M(d)||c&&s,[m,_]=g(!u),C=ve(e.value?.src);if(e.value?.src!==C.current){C.current=e.value?.src;let p=e.value?.filename||"",w=M(p)||Q(p)&&s;!w&&!m?_(!0):w&&m&&_(!1)}return e.value?.src?i("div",{className:"FileField__Preview",children:[i("div",{className:"FileField__Preview__InfoButton",children:[u&&i(re,{label:"Toggle file info",position:"top",withArrow:!0,children:i(X,{onClick:()=>_(p=>!p),size:"sm",variant:"outline",className:"FileField__Preview__InfoButton__Icon","aria-label":"Toggle file info",children:i(st,{size:16})})}),i(k,{shadow:"sm",control:i(X,{variant:"outline",size:"sm",radius:"sm",c:"black",className:"FileField__Preview__InfoButton__Icon",children:i(ot,{size:16})}),children:[e.allowEditing&&i(O,{children:[i(k.Label,{size:"sm",children:"REPLACE"}),i(k.Item,{icon:e.variant==="image"?i(Te,{size:16}):i(Ce,{size:16}),onClick:()=>e.requestFileUpload(),children:["Upload ",e.variant==="image"?"image":"file"]}),Dt(e.acceptedFileTypes)&&i(k.Item,{disabled:!e.value?.src,icon:i(De,{size:16}),onClick:()=>{e.requestPlaceholderModalOpen()},children:"Placeholder image"}),M(e.value?.src)&&!e.value?.src?.endsWith(".svg")&&i(k.Item,{disabled:!e.value?.src,icon:i(at,{size:16}),closeMenuOnClick:!0,onClick:()=>{e.requestImageEditorOpen()},children:"Edit image"}),i(Fe,{})]}),i(k.Item,{disabled:e.value?.src?.startsWith("data:"),onClick:()=>{e?.requestFileDownload()},icon:i(nt,{size:16}),children:"Download file"}),i(k.Item,{closeOnItemClick:!1,icon:i(it,{size:16}),onClick:()=>{o(!1);let p=e.value?.src||"";Ee(p)&&(p=p.split("=")[0]+"=s0"),navigator.clipboard.writeText(p).then(()=>o(!0)).finally(()=>setTimeout(()=>{o(!1)},2e3))},children:a?"Copied!":"Copy URL"}),e.allowEditing&&M(e.value?.src||"")&&e.value?.canvasBgColor&&i(k.Item,{icon:e.value?.canvasBgColor==="dark"?i(ut,{size:16}):i(dt,{size:16,style:{opacity:.25}}),closeOnItemClick:!1,onClick:()=>{let p=e.value?.canvasBgColor==="dark"?"light":"dark";e.value&&e.setValue({...e.value,canvasBgColor:p})},children:"Use dark canvas"}),i(Fe,{}),i(k.Item,{color:"red",onClick:()=>{e?.removeFile()},icon:i(ct,{size:16}),children:"Remove file"})]})]}),i("div",{className:B("FileField__Canvas",m&&"FileField__Canvas--infoOpened",l&&"dragging"),style:Lt(e.value),onDragOver:p=>{p.preventDefault(),t(!0)},onDragLeave:p=>{p.preventDefault(),t(!1)},onDrop:p=>{p.preventDefault(),t(!1);let w=p.dataTransfer?.files[0];w&&e&&e.handleFile(w)},onPaste:p=>{p.preventDefault();let w=p.clipboardData?.files[0];if(w){e.handleFile(w);return}let y=p.clipboardData?.getData("text/plain");if(y){if(he(y)){e.handleFile(y);return}if(Tt(y)){e.handleFile(y,{as:"svg"});return}}},children:[i(We,{visible:e.loadingState==="loading"}),m?i("div",{className:"FileField__Canvas__Info",children:[i(rt,{size:16,className:"FileField__Canvas__Info__Icon"}),i(Je,{className:"FileField__Canvas__Info__Table",verticalSpacing:"xs",fontSize:"xs",children:i("tbody",{children:[e.value?.filename&&i("tr",{children:[i("td",{children:i("b",{children:"Name"})}),i("td",{children:e.value.filename})]}),e.value?.uploadedAt&&i("tr",{children:[i("td",{children:i("b",{children:"Uploaded"})}),i("td",{children:[new Date(parseInt(e.value.uploadedAt,10)).toLocaleString(),e.value.uploadedBy&&i(O,{children:[" by ",e.value.uploadedBy]})]})]}),!!(e.value?.width&&e.value?.height)&&i("tr",{children:[i("td",{children:i("b",{children:"Dimensions"})}),i("td",{children:[e.value.width,"x",e.value.height]})]}),i("tr",{children:[i("td",{children:i("b",{children:"URL"})}),i("td",{children:i(Z,{readOnly:!0,value:e.value?.src,size:"xs",radius:0,autosize:!0,maxRows:10})})]})]})})]}):i(O,{children:[!!(e.value?.width&&e.value?.height)&&i(Be,{radius:"sm",className:"FileField__Preview__Info",children:[e.value.width,"x",e.value.height]}),M(e.value?.src)&&i("img",{onClick:()=>{e?.focusDropZone()},onDblClick:()=>{e.allowEditing&&e?.requestFileUpload()},src:e.value.src,alt:e.value.alt||"Uploaded file preview",className:"FileField__Preview__Image"}),Q(e.value?.src)&&i(O,{children:i("video",{className:"FileField__Preview__Image",controls:!0,muted:!0,preload:"metadata",children:i("source",{src:e.value.src,type:`video/${Ie(e.value.src)}`})})})]}),e.allowEditing&&i("div",{className:"FileField__reupload",children:i(T.UploadButton,{className:"FileField__reupload__button",compact:!0})})]}),e.allowEditing&&e.showAltText&&(e.altText||Ct(e.value?.filename)||e.variant==="image")&&i("div",{className:"DocEditor__ImageField__imagePreview__Image__Alt",children:[i(Z,{radius:0,className:"DocEditor__ImageField__imagePreview__Image__Alt__Textarea",value:e.altText,placeholder:"Alt text",size:"xs",autosize:!0,disabled:e.loadingState==="loading",onChange:p=>{e?.setAltText(p.currentTarget.value)}}),n.ai&&!e.altText&&e.value?.src?.startsWith("http")&&i(re,{label:"Generate alt text with AI",position:"top",withArrow:!0,children:i(X,{className:"DocEditor__ImageField__imagePreview__Image__Alt__AiButton",onClick:()=>{e.requestGenerateAltText()},disabled:e.loadingState==="loading",children:i(Y,{size:20,stroke:"1.75"})})})]})]}):null};T.UploadButton=e=>{let l=ee(),t=l.loadingState==="loading",a=e.compact?14:16;return i(E,{color:"black",variant:"default",disabled:t,size:e.compact?"compact-xs":"compact-md",className:B("FileField__FileUploadButton",e.compact&&"FileField__FileUploadButton--compact"),onClick:()=>{l.requestFileUpload()},leftIcon:i(O,{children:t&&!e.compact?i(He,{size:a}):l?.variant==="image"?i(Te,{size:a}):i(Ce,{size:a})}),children:t&&!e.compact?"Uploading...":l.value?.src?"Upload":"Paste, drop, or click to upload"})};T.InvisibleDropzone=e=>{let[l,t]=g(!1),a=ee();return i("div",{className:B("FileField__InvisibleDropzone",l&&"dragging"),onDragOver:o=>{o.preventDefault(),o.stopPropagation(),t(!0)},onDragLeave:o=>{o.preventDefault(),o.stopPropagation(),t(!1)},onDrop:o=>{o.preventDefault(),o.stopPropagation(),t(!1);let n=o.dataTransfer?.files[0];n&&a.handleFile(n)},children:e.children})};T.Empty=()=>{let e=ee(),l=J(()=>{if(e.acceptedFileTypes.length===0)return"";let t=e.acceptedFileTypes.filter(a=>a!=="*/*"&&a!=="*");return t.length===0?"":t.map(a=>a.split("/").pop().split("+")[0].replaceAll(".","")).sort().join(", ")},[e.acceptedFileTypes]);return i("div",{className:"FileField__Empty",children:[i("div",{className:"FileField__Empty__Label",children:[i(T.UploadButton,{}),Dt(e.acceptedFileTypes)&&i("div",{children:i(re,{label:"Create placeholder image",children:i(X,{className:"FileField__Empty__Label__PlaceholderButton",onClick:()=>{e.requestPlaceholderModalOpen()},title:"Create placeholder image",children:i(De,{size:16})})})})]}),l&&i("div",{children:i("div",{className:"FileField__Empty__AcceptTypes",children:["Allowed file types: ",l]})})]})};T.Dropzone=be((e,l)=>{let[t,a]=g(!1),o=ee();return i("button",{ref:l,className:B("FileField__Dropzone",t&&"dragging"),onDblClick:()=>{o?.requestFileUpload()},onCopy:n=>{o.value?.src&&(n.preventDefault(),n.clipboardData?.setData("text/plain",o.value.src),n.clipboardData?.setData("application/json",JSON.stringify(o.value)))},onKeyDown:n=>{((n.metaKey||n.ctrlKey)&&n.key==="Backspace"||n.key==="Delete")&&(n.preventDefault(),o.value?.src&&o.removeFile())},onDragOver:n=>{n.preventDefault(),a(!0)},onDragLeave:n=>{n.preventDefault(),a(!1)},onDrop:n=>{n.preventDefault(),a(!1);let s=n.dataTransfer?.files[0];s&&o&&o.handleFile(s)},onPaste:n=>{if(n.preventDefault(),!o)return;let s=n.clipboardData?.getData("application/json");if(s)try{let u=JSON.parse(s);if(u&&u.src&&u.filename&&o){console.log("Parsed JSON file:",u),o.setValue(u);return}}catch(u){console.error("error parsing json",u)}let d=n.clipboardData?.files[0];if(d){o.handleFile(d);return}let c=n.clipboardData?.getData("text/plain");if(c){if(he(c)){o.handleFile(c);return}if(Tt(c)){o.handleFile(c,{as:"svg"});return}}},title:"Drop or paste to upload a file"})});var Mt=be(e=>{let{label:l,description:t,...a}=e;return i("div",{className:"FileField__NamingModeItem",...a,children:[i(G,{size:"sm",weight:500,children:l}),i(G,{size:"xs",color:"dimmed",children:t})]})});function Ct(e){return e?M(e)||Q(e):!1}function Dt(e){return e.some(l=>l.startsWith("image/"))||e.length===0}function Lt(e){let l={};if(e.width&&e.height){l["--canvas-aspect-ratio"]=`${e.width} / ${e.height}`,l["--canvas-asset-width"]=`${e.width}px`;let t=Math.min(e.height,280);t<80&&(t=80),l["--canvas-max-height"]=`${t}px`}return e.canvasBgColor==="dark"&&(l["--canvas-bg-color"]="#000"),l}function Tt(e){return/^(?:\uFEFF)?\s*(?:<!--[\s\S]*?-->\s*)*(?:<\?xml[\s\S]*?\?>\s*)?(?:<!DOCTYPE\s+svg[\s\S]*?>\s*)?<svg\b[^>]*?(?:\/>|>[\s\S]*?<\/svg>)\s*$/.test(e)}export{vt as a,_t as b,H as c,ci as d,ui as e,fe as f,pi as g,gi as h,fi as i,wt as j,zt as k,T as l};
@@ -1 +0,0 @@
1
- import{a as h}from"./chunk-YDO2EDVY.js";import{g as y}from"./chunk-XOQ3KDSR.js";import{a as x}from"./chunk-5MV6XVGA.js";import{c as f,n as g}from"./chunk-EGEB6N4J.js";async function b(e){let t=window.firebase.db,s=window.__ROOT_CTX.rootConfig.projectId,[a,c]=e.split("/",2),o=await h(a),r=f(t,"Projects",s,"Collections",a,"Drafts",c),i=(await g(r)).data()||{},p=new Set;return m(p,o.fields,i.fields||{},o.types||{}),Array.from(p)}async function C(e){let t=window.firebase.db,s=window.__ROOT_CTX.rootConfig.projectId,[a,c]=e.split("/",2),o=await h(a),r=f(t,"Projects",s,"Collections",a,"Drafts",c),i=(await g(r)).data()||{},p=new Map;return d(p,o.fields,i.fields||{},o.types||{}),p}function m(e,t,s,a={}){t.forEach(c=>{if(!c.id)return;let o=s[c.id],r=`@${c.id}`;s[r]?.disableTranslations||R(e,c,o,a)})}function d(e,t,s,a={}){t.forEach(c=>{if(!c.id)return;let o=s[c.id],r=`@${c.id}`,n=s[r];if(n?.disableTranslations)return;let i=n?.description;S(e,c,o,a,i)})}function R(e,t,s,a={}){if(!s)return;function c(o){let r=y(o);r&&e.add(r)}if(t.type==="object")m(e,t.fields||[],s,a);else if(t.type==="array"){let o=s._array||[];for(let r of o)R(e,t.of,s[r],a)}else if(t.type==="string"||t.type==="select")t.translate&&c(s);else if(t.type==="image")t.translate&&s&&s.alt&&t.alt!==!1&&c(s.alt);else if(t.type==="multiselect"){if(t.translate&&Array.isArray(s))for(let o of s)c(o)}else if(t.type==="oneof"){let o=t.types||[],r;typeof o[0]=="string"?o.includes(s._type)&&(r=a[s._type]):r=o.find(n=>n.name===s._type),r&&m(e,r.fields||[],s,a)}else t.type==="richtext"?t.translate&&T(e,s):console.log(`extract: ignoring field, id=${t.id}, type=${t.type}`)}function S(e,t,s,a={},c){if(!s)return;function o(r){let n=y(r);if(n){let i=e.get(n);(!i||!i.description)&&e.set(n,{description:c})}}if(t.type==="object")d(e,t.fields||[],s,a);else if(t.type==="array"){let r=s._array||[];for(let n of r)S(e,t.of,s[n],a,c)}else if(t.type==="string"||t.type==="select")t.translate&&o(s);else if(t.type==="image")t.translate&&s&&s.alt&&t.alt!==!1&&o(s.alt);else if(t.type==="multiselect"){if(t.translate&&Array.isArray(s))for(let r of s)o(r)}else if(t.type==="oneof"){let r=t.types||[],n;typeof r[0]=="string"?r.includes(s._type)&&(n=a[s._type]):n=r.find(i=>i.name===s._type),n&&d(e,n.fields||[],s,a)}else if(t.type==="richtext"&&t.translate){let r=new Set;T(r,s),r.forEach(n=>o(n))}}function T(e,t){(t?.blocks||[]).forEach(a=>{w(e,a)})}function w(e,t){if(!t?.type)return;function s(r){if(!r)return;let n=y(r);n&&e.add(n)}function a(r){r&&Object.values(r).forEach(n=>{c(n)})}function c(r){if(typeof r=="string"){s(r);return}if(Array.isArray(r)){r.forEach(n=>c(n));return}x(r)&&Object.values(r).forEach(n=>c(n))}function o(r){r&&r.forEach(n=>{s(n.content),a(n.components),o(n.items)})}t.type==="heading"||t.type==="paragraph"?(s(t.data?.text),a(t.data?.components)):t.type==="orderedList"||t.type==="unorderedList"?o(t.data?.items):t.type==="html"?s(t.data?.html):t.type==="table"&&(t.data?.rows||[]).forEach(n=>{(n.cells||[]).forEach(p=>{(p.blocks||[]).forEach(_=>{w(e,_)})})})}export{b as a,C as b,R as c};
@@ -1 +0,0 @@
1
- import{b as ie}from"./chunk-54DVDYU6.js";import{a as ee,b as M,c as D}from"./chunk-JDW4UORS.js";import{a as se}from"./chunk-YDO2EDVY.js";import{c as oe,s as ne}from"./chunk-AFWBSIPL.js";import{b as te}from"./chunk-62UWGWON.js";import{a as $}from"./chunk-I6ICVKEC.js";import{a as j}from"./chunk-HLMBCVRX.js";import{a as L}from"./chunk-5MV6XVGA.js";import{b as K,f as U,g as _,i as y,o as Y}from"./chunk-EGEB6N4J.js";import{d as Z,f as re}from"./chunk-AL3TN2KI.js";import{A as G,Aa as J,Ha as d,a as p,c as w,e as C,ea as P,g as B,h as R,i as W,j as T,sa as Q,va as q}from"./chunk-NZHF733K.js";import{j as X,k as pe}from"./chunk-KUCVLANF.js";function z(e){let t=window.__ROOT_CTX.collections[e.collectionId];if(!t)throw new Error(`collection not found: ${e.collectionId}`);if(!t.url)return"";let n=t.domain||window.__ROOT_CTX.rootConfig.domain||"https://example.com",s=he(e);return`${n}${s}`}function he(e){let o=window.__ROOT_CTX.collections,{collectionId:t,slug:n,locale:s}=e,r=o[t];if(!r)throw new Error(`collection not found: ${t}`);if(!r.url)return"";let c=window.__ROOT_CTX.rootConfig,g=c.base||"/",u="/[base]/[path]";s&&(u=c.i18n.urlFormat||"/[locale]/[base]/[path]");let m="",a=r?.url;if(a)if(n){let l=a.replace(/\[.*slug\]/,n).replaceAll("--","/").replace(/\/+/g,"/");l==="/index"&&(l="/"),m=l}else m=a;return ce(u,{base:g,path:m,locale:s||"",slug:n})}function we(e){let o=window.__ROOT_CTX.collections,{collectionId:t,slug:n,locale:s}=e,r=o[t];if(!r)throw new Error(`collection not found: ${t}`);let c=window.__ROOT_CTX.rootConfig,g=c.base||"/",u="/[base]/[path]";s&&(u=c.i18n.urlFormat||"/[locale]/[base]/[path]");let m="",a=r?.previewUrl||r?.url;if(a)if(n){let l=a.replace(/\[.*slug\]/,n).replaceAll("--","/").replace(/\/+/g,"/");l==="/index"&&(l="/"),m=l}else m=a;return ce(u,{base:g,path:m,locale:s||"",slug:n})}function ce(e,o){let t=e.replaceAll(/\[\[?(\.\.\.)?([\w\-_]*)\]?\]/g,(n,s,r)=>o[r]??n);return Se(t,{trailingSlash:window.__ROOT_CTX.rootConfig.server.trailingSlash})}function Se(e,o){return e=e.replace(/\/+/g,"/"),o?.trailingSlash===!1&&e!=="/"&&e.endsWith("/")&&(e=e.replace(/\/*$/g,"")),(e.endsWith("/index")||e.endsWith("/index/"))&&(e=e.slice(0,-6)),e.startsWith("/")||(e=`/${e}`),o?.trailingSlash&&!e.endsWith("/")&&(e=`${e}/`),e}T();function Ne(e,o){let[t,n]=p([]),[s,r]=p(!0),g=ie().db,u=window.__ROOT_CTX.rootConfig.projectId||"default",m=o.includeArchived??!1,a=async()=>{r(!0);let l=K(g,"Projects",u,"Collections",e,"Drafts"),i=l,f=o.orderBy;if(f==="modifiedAt")i=_(l,y("sys.modifiedAt","desc"));else if(f==="newest")i=_(l,y("sys.createdAt","desc"));else if(f==="oldest")i=_(l,y("sys.createdAt"));else if(f==="slug")i=_(l,y(U()));else if(f==="slugDesc")i=_(l,y(U(),"desc"));else{let h=window.__ROOT_CTX.collections[e]?.sortOptions?.find(v=>v.id===f);h&&(i=h.direction==="desc"?_(l,y(h.field,"desc")):_(l,y(h.field)))}await te(async()=>{let S=await Y(i),h=[];S.docs.forEach(v=>{let E=v.data(),b=v.id,x=`${e}/${b}`,O={...E,id:x,slug:b};oe(x,O),!(!m&&O?.sys?.archivedAt)&&h.push(O)}),n(h)}),r(!1)};return w(()=>{r(!0),a()},[e,o.orderBy,m]),[s,a,t]}pe();T();var N={CONNECTED:"connected",SCHEMA_CHANGED:"schemaChanged"};function le(e){let t=new URLSearchParams(window.location.search).get("e");return t?t.split(",").includes(e):!1}var Ee="/cms/api/sse.connect",A=le("EnableVerboseLogging"),ae=window.location.hostname==="localhost",F=class{constructor(){this.map=new Map}on(o,t){return this.map.has(o)||this.map.set(o,new Set),this.map.get(o).add(t),()=>{this.map.get(o)?.delete(t)}}emit(o,t,n){this.map.get(o)?.forEach(s=>s(t,n)),this.map.get("*")?.forEach(s=>s({type:o,data:t},n))}},de=X(null);function je(e){let t=C(new F).current,n=C(null),s=C(!1),r=C({attempt:0,timer:0}),c=C(""),g=()=>{n.current&&(n.current.close(),n.current=null)},u=R(()=>{A&&console.log("[sse] connecting..."),g();let a=new EventSource(Ee);n.current=a,a.addEventListener(N.CONNECTED,i=>{if(A&&console.log("[sse] connected"),s.current=!1,r.current.attempt=0,ae){let S=ue(i.data)?.serverVersion||"";c.current?c.current!==S&&(console.log(`server version changed: ${c.current} -> ${S}`),console.log("reloading..."),window.location.reload()):c.current=S}});let l=i=>{if(!i||!i.type)return;let f=ue(i.data);A&&console.log("[sse] event:",i.type,f),t.emit(i.type,f,i)};Object.values(N).forEach(i=>{a.addEventListener(i,l)}),a.addEventListener("error",()=>{A&&console.log("[sse] disconnected"),a.readyState===EventSource.CLOSED&&!s.current&&(s.current=!0,(()=>{let f=++r.current.attempt,S=Math.min(3e4,Math.pow(2,f)*500),h=Math.random()*.3*S,v=S+h;window.clearTimeout(r.current.timer),r.current.timer=window.setTimeout(()=>{s.current=!1,u()},v)})())})},[t]);w(()=>{if(!ae)return;u();let a=()=>{document.visibilityState==="visible"&&n.current?.readyState!==EventSource.OPEN&&u()};return document.addEventListener("visibilitychange",a),()=>{document.removeEventListener("visibilitychange",a),window.clearTimeout(r.current.timer),g()}},[u]);let m=B(()=>({emitter:t}),[t]);return d(de.Provider,{value:m,children:e.children})}function ue(e){try{return JSON.parse(e)}catch{return e}}function fe(e,o){let t=W(de);if(!t)throw new Error("useSSE() must be used within an <SSEProvider>");let n=C(o);w(()=>{n.current=o},[o]),w(()=>t.emitter.on(e,(s,r)=>n.current(s,r)),[t,e])}T();T();function ge(e){let[o,t]=p(!0),[n,s]=p(null),r=R(async()=>{try{let c=await se(e);s(c)}catch(c){console.error(c),$({title:`Failed to load collection: ${e}`,message:String(c),color:"red",autoClose:!1})}t(!1)},[e]);return w(()=>{r()},[e]),fe(N.SCHEMA_CHANGED,async c=>{await r();let g=c.file?`Applied updates from changes to ${c.file}.`:"Applied updates from changes to a .schema.ts file.";$({title:"Updated schema!",message:g})}),{loading:o,schema:n}}function H(e){let o={_array:[]};return e.forEach(t=>{let n=Ce();o._array.push(n),o[n]=t}),o}function Ce(){let e=[],o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=o.length;for(let n=0;n<6;n++)e.push(o.charAt(Math.floor(Math.random()*t)));return e.join("")}function V(e){let o={};return e.fields.forEach(t=>{t.id&&(t.type==="array"&&t.default&&Array.isArray(t.default)?o[t.id]=H(t.default):t.default?o[t.id]=t.default:t.type==="object"&&(o[t.id]=V(t)))}),o}function k(e,o,t){let n={...o};return e.fields.forEach(s=>{if(!s.id)return;let r=n[s.id];if(r!=null){if(s.type==="array"&&Array.isArray(r)){let c=r.map(g=>ve(s.of,g,t));n[s.id]=H(c)}else if(s.type==="object"&&L(r))n[s.id]=k(s,r,t);else if(s.type==="oneof"&&L(r)&&typeof r._type=="string"&&t){let c=t[r._type];c&&(n[s.id]=k(c,r,t))}}}),n}function ve(e,o,t){if(!L(o))return o;if(e.type==="object")return k(e,o,t);if(e.type==="oneof"&&typeof o._type=="string"&&t){let n=t[o._type];if(n)return k(n,o,t)}return o}T();function me(e){let[o,t]=p(e.collectionId||""),n=C(null),[s,r]=p(""),c=window.__ROOT_CTX.collections[o],g=[];e.collectionId&&e.collectionDisabled?g.push({value:e.collectionId,label:e.collectionId}):Object.keys(window.__ROOT_CTX.collections).forEach(i=>{g.push({value:i,label:i})});let u="",m="";if(c?.url){if(s){let i=D(s),f=c?.slugRegex;ee(i,f)?u=z({collectionId:o,slug:i}):m=M(i,f)}else u=z({collectionId:o,slug:"[slug]"});u.endsWith("/index")&&(u=u.replace(/\/index$/,"/"))}function a(i){t(i),e.onChange&&e.onChange({collectionId:i,slug:s})}function l(i){r(i),e.onChange&&e.onChange({collectionId:o,slug:i})}return d("div",{className:re(e.className,"SlugInput"),children:[d("div",{className:"SlugInput__inputs",children:[d(J,{className:"SlugInput__collection",placeholder:"Collection",size:"xs",data:g,onChange:i=>a(i),value:o,disabled:!!e.collectionDisabled}),d("div",{className:"SlugInput__divider",children:"/"}),d(q,{className:"SlugInput__slug",name:"slug",ref:n,value:s,onChange:i=>{l(i.currentTarget.value)},placeholder:"slug",autoComplete:"off",size:"xs"})]}),u&&d(j,{className:"SlugInput__urlHelp",size:"body-sm",children:u}),m&&d(j,{className:"SlugInput__slugError",size:"body-sm",children:m})]})}function wt(e){let{route:o}=Z(),[t,n]=p(""),[s,r]=p(!1),[c,g]=p(""),[u,m]=p(""),a=G(),l=e.collection,i=window.__ROOT_CTX.collections[l];if(!i)throw new Error(`collection not found: ${l}`);let f=ge(l);function S(E){let b=D(E);return b?M(b,i.slugRegex):""}function h(){e.onClose&&e.onClose()}async function v(E){if(E.preventDefault(),r(!0),g(""),S(t)){r(!1);return}let x=D(t),O=`${l}/${x}`;try{let I={};!f.loading&&f.schema&&(I=await V(f.schema)),await ne(O,{fields:I})}catch(I){m(String(I)),r(!1);return}r(!1),e.skipNavigation?h():o(`/cms/content/${e.collection}/${x}`)}return d(Q,{className:"NewDocModal",opened:e.opened||!1,onClose:()=>h(),title:"New",size:"500px",overlayColor:a.colorScheme==="dark"?a.colors.dark[9]:a.colors.gray[2],children:[d("div",{className:"NewDocModal__body",children:"Enter a slug for the new doc. The slug is the ID of the page and is what's used in the URL. Use only lowercase letters, numbers, and dashes."}),d("form",{onSubmit:E=>v(E),children:[d(me,{className:"NewDocModal__slug",collectionId:l,onChange:E=>{n(E.slug),g(S(E.slug)),m("")}}),u&&d("div",{className:"NewDocModal__slugError",children:u}),d("div",{className:"NewDocModal__buttons",children:[d(P,{variant:"outline",onClick:()=>h(),type:"button",size:"xs",color:"dark",children:"Cancel"}),d(P,{variant:"filled",type:"submit",size:"xs",color:"dark",loading:f.loading||s,disabled:!!c||!!u,children:"Submit"})]})]})]})}export{z as a,he as b,we as c,me as d,Ne as e,je as f,ge as g,V as h,k as i,wt as j};