@blinkk/root-cms 3.1.5 → 3.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +1 -1
- package/dist/{chunk-MUXSUGFF.js → chunk-NIBAHWGP.js} +2 -2
- package/dist/{chunk-ETHWZSNM.js → chunk-PLSNGCYU.js} +196 -22
- package/dist/{chunk-6CTCV2PN.js → chunk-Z2CTQVYR.js} +1 -1
- package/dist/cli.js +1 -1
- package/dist/client.js +1 -1
- package/dist/core/client.d.ts +30 -2
- package/dist/core/cron-schedule.d.ts +63 -0
- package/dist/core/plugin.d.ts +6 -1
- package/dist/core.js +1 -1
- package/dist/functions.js +2 -2
- package/dist/plugin.js +7 -5
- package/dist/richtext.js +1 -1
- package/dist/shared/embed-protocol.d.ts +19 -0
- package/dist/ui/AIPage-XPE7F5AF.js +1 -0
- package/dist/ui/AssetsPage-C3ZEENBO.js +1 -0
- package/dist/ui/CollectionPage-VQ4WJHJB.js +1 -0
- package/dist/ui/ComparePage-VKOXKID4.js +1 -0
- package/dist/ui/{DataPage-RFNGSDDN.js → DataPage-JXZ2Z3DG.js} +1 -1
- package/dist/ui/{DataSourcePage-U46CDIH2.js → DataSourcePage-X3NSUOTP.js} +1 -1
- package/dist/ui/{DocTranslationsPage-BFCM2PE3.js → DocTranslationsPage-AJGT52XQ.js} +1 -1
- package/dist/ui/DocumentPage-ZFD2KE3A.js +1 -0
- package/dist/ui/{EditDataSourcePage-NKKIF6AD.js → EditDataSourcePage-EMK3F6HD.js} +1 -1
- package/dist/ui/EditReleasePage-3IAERDSH.js +1 -0
- package/dist/ui/EmbeddedAIPage-2W5F7QFL.js +1 -0
- package/dist/ui/{EmbeddedDocumentPage-2CNQJTW5.js → EmbeddedDocumentPage-BESFW2YZ.js} +1 -1
- package/dist/ui/{ImageEditorDialog-YDKOGVJV.js → ImageEditorDialog-JDXMU2FC.js} +1 -1
- package/dist/ui/LogsPage-KCD4XZ2N.js +1 -0
- package/dist/ui/NewDataSourcePage-EZDU7HGA.js +1 -0
- package/dist/ui/NewReleasePage-FFTRUIP4.js +1 -0
- package/dist/ui/{NotFoundPage-JRYFUENW.js → NotFoundPage-JGG2NTUE.js} +1 -1
- package/dist/ui/{ProjectPage-2WIMWCSX.js → ProjectPage-HT5JKR33.js} +1 -1
- package/dist/ui/ReleasePage-OYWLGV4D.js +1 -0
- package/dist/ui/{ReleasesPage-AW6PICTQ.js → ReleasesPage-XEII7FBC.js} +1 -1
- package/dist/ui/{SettingsPage-KFLNZ356.js → SettingsPage-7GIBTPB5.js} +1 -1
- package/dist/ui/SidebarToolsPage-GQYTZDAC.js +1 -0
- package/dist/ui/{TaskPage-GZGPKIL5.js → TaskPage-SNDDYDZY.js} +1 -1
- package/dist/ui/TasksPage-CEVWOY67.js +1 -0
- package/dist/ui/{TranslationsArbPage-K272JEAA.js → TranslationsArbPage-ADRLLAIW.js} +1 -1
- package/dist/ui/{TranslationsEditPage-XWXPNKRQ.js → TranslationsEditPage-PSKA7K44.js} +1 -1
- package/dist/ui/{TranslationsPage-7KUHVTLK.js → TranslationsPage-NGCLDSK7.js} +2 -2
- package/dist/ui/{chunk-75NMQ3LW.js → chunk-3YBRRPAN.js} +1 -1
- package/dist/ui/{chunk-QLIIVG5Q.js → chunk-5F5XJPKD.js} +1 -1
- package/dist/ui/{chunk-7UHZS56B.js → chunk-6ZVMJXLE.js} +53 -53
- package/dist/ui/chunk-7OU4ERTS.js +87 -0
- package/dist/ui/chunk-A2JZYRE3.js +1 -0
- package/dist/ui/chunk-B74M7NEV.js +1 -0
- package/dist/ui/chunk-BLHXP3SR.js +3 -0
- package/dist/ui/{chunk-UJX25CXD.js → chunk-BOIY4J2R.js} +1 -1
- package/dist/ui/chunk-CEWU5VSJ.js +1 -0
- package/dist/ui/{chunk-34W6H4YG.js → chunk-CXMVFNX3.js} +1 -1
- package/dist/ui/{chunk-F7RQT4XN.js → chunk-EET5AS64.js} +1 -1
- package/dist/ui/{chunk-WASID5UU.js → chunk-GJ7ES2LA.js} +1 -1
- package/dist/ui/{chunk-2RRM4HEQ.js → chunk-H5JL376P.js} +1 -1
- package/dist/ui/{chunk-H37RXS4R.js → chunk-HKCOKHA2.js} +1 -1
- package/dist/ui/{chunk-5KSGCGYY.js → chunk-HUYP5U4K.js} +1 -1
- package/dist/ui/{chunk-NCZD5IWS.js → chunk-HWON6MV4.js} +1 -1
- package/dist/ui/{chunk-HXSB6YB2.js → chunk-I3H465Z6.js} +1 -1
- package/dist/ui/{chunk-535JU7FU.js → chunk-ILFWJKSS.js} +1 -1
- package/dist/ui/chunk-K7IG7PO2.js +1 -0
- package/dist/ui/chunk-LKTN7YVM.js +31 -0
- package/dist/ui/{chunk-PLYSJ7W5.js → chunk-LS2JH5QF.js} +1 -1
- package/dist/ui/{chunk-QFDU6FXP.js → chunk-MALK5YEV.js} +1 -1
- package/dist/ui/{chunk-YP6ZH3MT.js → chunk-MFRPYPCF.js} +1 -1
- package/dist/ui/chunk-MYPLMHFW.js +1 -0
- package/dist/ui/{chunk-RB23LLKL.js → chunk-OKNBFTYR.js} +1 -1
- package/dist/ui/{chunk-OWBT6YUM.js → chunk-P2RVKNG4.js} +1 -1
- package/dist/ui/{chunk-JBLSUM6W.js → chunk-P57AFOMR.js} +1 -1
- package/dist/ui/{chunk-HV3JJ5UT.js → chunk-PLTI4NG7.js} +1 -1
- package/dist/ui/chunk-PY4JH5SN.js +1 -0
- package/dist/ui/{chunk-44ZU5WMI.js → chunk-SBAY52SC.js} +1 -1
- package/dist/ui/{chunk-Y5EOMMNI.js → chunk-TCKR2BL4.js} +1 -1
- package/dist/ui/{chunk-WC7KMPEQ.js → chunk-TCRDGNM4.js} +1 -1
- package/dist/ui/chunk-TCWN5YRW.js +1 -0
- package/dist/ui/{chunk-DWV5J2W7.js → chunk-TZWCCNSA.js} +1 -1
- package/dist/ui/{chunk-2PTLQRTU.js → chunk-U5OXKKBN.js} +1 -1
- package/dist/ui/{chunk-XUBZH4ON.js → chunk-VZGDXWRK.js} +1 -1
- package/dist/ui/{chunk-IGZDFHVM.js → chunk-X3VDQDHP.js} +1 -1
- package/dist/ui/chunk-XBYMUPZF.js +19 -0
- package/dist/ui/{chunk-QRAFYIAW.js → chunk-XYXL5HSZ.js} +1 -1
- package/dist/ui/chunk-Y7RYSRP7.js +7 -0
- package/dist/ui/{chunk-WRA24P66.js.LEGAL.txt → chunk-Y7RYSRP7.js.LEGAL.txt} +1 -0
- package/dist/ui/chunk-YIKHJONY.js +1 -0
- package/dist/ui/chunk-Z2CRNO3I.js +1 -0
- package/dist/ui/{chunk-UCYWQEAS.js → chunk-ZD3ORGA6.js} +1 -1
- package/dist/ui/{chunk-YBHFGQ3Z.js → chunk-ZQDUWURP.js} +1 -1
- package/dist/ui/{chunk-PIJ3E47R.js → chunk-ZYSR5UIW.js} +1 -1
- package/dist/ui/ui.css +1 -1
- package/dist/ui/ui.js +1 -1
- package/package.json +3 -3
- package/dist/ui/AIPage-25WICIOT.js +0 -1
- package/dist/ui/AssetsPage-WKTM2J2G.js +0 -1
- package/dist/ui/CollectionPage-5ZOVG7IG.js +0 -1
- package/dist/ui/ComparePage-DDIFYYTK.js +0 -1
- package/dist/ui/DocumentPage-OTBXM55S.js +0 -1
- package/dist/ui/EditReleasePage-TKNOUT7A.js +0 -1
- package/dist/ui/EmbeddedAIPage-4AX7VO3T.js +0 -1
- package/dist/ui/LogsPage-SCECIAZH.js +0 -1
- package/dist/ui/NewDataSourcePage-FAOPK2RZ.js +0 -1
- package/dist/ui/NewReleasePage-HD6T6UV2.js +0 -1
- package/dist/ui/ReleasePage-GUMEMLF6.js +0 -1
- package/dist/ui/SidebarToolsPage-3R7BQ2F7.js +0 -1
- package/dist/ui/TasksPage-G3GBTV3L.js +0 -1
- package/dist/ui/chunk-2FQMT5AB.js +0 -3
- package/dist/ui/chunk-FVWSVOOY.js +0 -1
- package/dist/ui/chunk-GCSN3YEC.js +0 -31
- package/dist/ui/chunk-N5RJIILP.js +0 -1
- package/dist/ui/chunk-NXWYS4HG.js +0 -19
- package/dist/ui/chunk-OWYV43BT.js +0 -1
- package/dist/ui/chunk-QWB6MAPJ.js +0 -7
- package/dist/ui/chunk-RN4XVVWD.js +0 -1
- package/dist/ui/chunk-T5BJNOWE.js +0 -1
- package/dist/ui/chunk-TNW2GNUR.js +0 -1
- package/dist/ui/chunk-UPN3EMUS.js +0 -1
- package/dist/ui/chunk-VPZHG7JL.js +0 -81
- package/dist/ui/chunk-WRA24P66.js +0 -7
- package/dist/ui/chunk-Z3ZJJWFT.js +0 -1
- /package/dist/ui/{ImageEditorDialog-YDKOGVJV.js.LEGAL.txt → ImageEditorDialog-JDXMU2FC.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-7UHZS56B.js.LEGAL.txt → chunk-6ZVMJXLE.js.LEGAL.txt} +0 -0
- /package/dist/ui/{chunk-VPZHG7JL.js.LEGAL.txt → chunk-7OU4ERTS.js.LEGAL.txt} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as eo}from"./chunk-UPN3EMUS.js";import{g as He}from"./chunk-TNW2GNUR.js";import{b as Le,c as $e,e as Ve,j as Se}from"./chunk-FVWSVOOY.js";import{a as _e,b as ge,c as ae}from"./chunk-JDW4UORS.js";import{a as N,c as H}from"./chunk-QRAFYIAW.js";import{a as Je,b as Ke}from"./chunk-W5DOO6ID.js";import{a as Xe}from"./chunk-YBHFGQ3Z.js";import{b as U}from"./chunk-2PTLQRTU.js";import{a as _,b as F}from"./chunk-PIJ3E47R.js";import{a as M}from"./chunk-NCZD5IWS.js";import{A as ye,E as ve,F as xe,G as Ce,H as Ie,I as le,J as ke,K as Ae,L as we,M as De,N as Te,O as Re,P as Pe,S as de,T as Ne,U as ze}from"./chunk-ISUGBMXC.js";import{b as be,f as Me}from"./chunk-DZYYWCHX.js";import{C as he}from"./chunk-XOWWPE7X.js";import{d as fe}from"./chunk-WASID5UU.js";import{$ as ue,Cc as Ze,Da as pe,Ga as e,Ha as Ee,Ka as Ue,La as Be,Na as Oe,Qa as Fe,Rb as je,V as J,Vc as Ge,W as Q,a as c,c as j,da as b,e as ce,ea as ie,gc as Y,hc as ee,j as X,lb as qe,mc as Qe,oc as Ye,pb as K,qa as P,ua as me,xa as ne,xb as We}from"./chunk-WRA24P66.js";import{d as S}from"./chunk-KUCVLANF.js";X();var oo="AddToReleaseModal";function so(s){let t=N(),u=H();return{open:()=>{t.openContextModal(oo,{...u,title:"Add docs to a release",innerProps:s,size:"600px"})}}}function mo(s){let{innerProps:t,context:u,id:l}=s,d=N(),[o,y]=c(""),[p,v]=c(!1),[m,k]=c(!1),[g,A]=c([]),[a,D]=c(""),[x,T]=c(Se()),[w,f]=c("");j(()=>{async function n(){v(!0),await U(async()=>{let E=(await $e()).filter(R=>!R.publishedAt&&!R.archivedAt);A(E)}),v(!1)}n()},[]);async function I(){o==="new"?await L():o==="existing"&&await $()}async function L(){if(!x){_({title:"Missing ID",message:"Please enter a release ID.",color:"red",autoClose:5e3});return}if(!_e(x)){_({title:"Invalid ID",message:"Release ID must use alphanumeric characters and dashes only.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let n={docIds:t.docIds};w&&(n.description=w),await Le(x,n),_({title:`Release created: ${x}`,message:e("span",{children:["Created release with ",t.docIds.length," doc(s)."," ",e("a",{href:`/cms/releases/${x}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}async function $(){if(!a){_({title:"No release selected",message:"Please select a release.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let C=g.find(z=>z.id===a)?.docIds||[],E=Array.from(new Set([...C,...t.docIds])).sort();await Ve(a,{docIds:E});let R=E.length-C.length;_({title:`Docs added to release: ${a}`,message:e("span",{children:["Added ",R," new doc(s) to release."," ",e("a",{href:`/cms/releases/${a}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}let r=!0;return(o==="new"&&x||o==="existing"&&a)&&(r=!1),e("div",{className:"AddToReleaseModal",children:e("div",{className:"AddToReleaseModal__content",children:[e("div",{className:"AddToReleaseModal__docs",children:[e("div",{className:"AddToReleaseModal__docs__label",children:["Docs to add (",t.docIds.length,")"]}),e("div",{className:"AddToReleaseModal__docs__list",children:t.docIds.map(n=>e(He,{docId:n,variant:"compact",statusBadges:!0},n))})]}),e("div",{className:"AddToReleaseModal__mode",children:[e("label",{className:`AddToReleaseModal__mode__option${o==="new"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"new",checked:o==="new",onChange:()=>y("new")})," ","New release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Create a new release with these docs."})]}),e("label",{className:`AddToReleaseModal__mode__option${o==="existing"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"existing",checked:o==="existing",onChange:()=>y("existing")})," ","Existing release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Add to an existing release."})]})]}),o==="new"&&e("div",{className:"AddToReleaseModal__form",children:[e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Release ID"}),e("input",{type:"text",placeholder:"e.g. my-release",value:x,onInput:n=>{T(n.target.value)}})]}),e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Description (optional)"}),e("textarea",{rows:2,placeholder:"Describe this release",value:w,onInput:n=>{f(n.target.value)}})]})]}),o==="existing"&&e("div",{className:"AddToReleaseModal__releases",children:p?e("div",{className:"AddToReleaseModal__releases__empty",children:e(J,{color:"gray",size:"sm"})}):g.length===0?e("div",{className:"AddToReleaseModal__releases__empty",children:"No unpublished releases found. Create a new one instead."}):g.map(n=>e("div",{className:`AddToReleaseModal__release${a===n.id?" AddToReleaseModal__release--selected":""}`,onClick:()=>D(n.id),children:[e("input",{type:"radio",name:"existing-release",checked:a===n.id,onChange:()=>D(n.id)}),e("div",{className:"AddToReleaseModal__release__info",children:[e("div",{className:"AddToReleaseModal__release__info__id",children:n.id}),n.description&&e("div",{className:"AddToReleaseModal__release__info__description",children:n.description})]}),e("div",{className:"AddToReleaseModal__release__docCount",children:[n.docIds?.length||0," doc(s)"]})]},n.id))}),e("div",{className:"AddToReleaseModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",disabled:r,loading:m,onClick:I,children:o==="new"?"Create release":"Add to release"})]})]})})}mo.id=oo;X();var to="CopyDocModal";function oe(s){let t=N(),u=H();return{open:l=>{t.openContextModal(to,{...u,innerProps:{...s,...l}})}}}function po(s){let{innerProps:t,context:u,id:l}=s,{route:d}=fe(),[o,y]=c(""),[p,v]=c(""),[m,k]=c(""),[g,A]=c(""),[a,D]=c(!1),[x,T]=c(!1),[w,f]=c({}),I=t.fromDocId,L=I.split("/")[0],$=t.fromLabel||I;j(()=>{be({tags:[I]}).then(f)},[I]);function r(C,E){let R=ae(C),z=window.__ROOT_CTX.collections[E]?.slugRegex;return R?ge(R,z):""}async function n(C){if(C.preventDefault(),T(!0),A(""),!L){A("Please select a collection."),T(!1);return}if(r(p,o)){T(!1);return}let R=ae(p),z=`${o}/${R}`;try{t.fields?await Pe(z,{fields:t.fields,overwrite:a}):await Re(I,z,{overwrite:a});let O=Object.keys(w);if(O.length>0){let i=O.map(h=>({hash:h,tags:[z]}));await Me(i,{mode:"union"})}u.closeModal(l);let q=`/cms/content/${o}/${R}`;_({title:"Copied!",message:e("div",{children:[e("div",{children:`Successfully copied ${$} to ${z}.`}),e(b,{className:"CopyDocModal__notificationButton",component:"a",href:q,size:"xs",compact:!0,variant:"default",children:"Open doc"})]}),autoClose:1e4}),t.onSuccess&&t.onSuccess(z)}catch(O){let q=String(O);A(q),q.includes("already exists")&&D(!0),T(!1);return}T(!1),d(`/cms/content/${o}/${R}`)}return e("div",{className:"CopyDocModal",children:e("form",{onSubmit:C=>n(C),children:[e("div",{className:"CopyDocModal__from",children:[e(M,{className:"CopyDocModal__from__label",size:"body",weight:"bold",children:"From:"}),e(M,{className:"CopyDocModal__from__value",size:"body-sm",children:e("code",{children:$})})]}),e("div",{className:"CopyDocModal__to",children:[e(M,{className:"CopyDocModal__to__label",size:"body",weight:"bold",children:"To:"}),e(eo,{className:"CopyDocModal__slug",collectionId:L,onChange:C=>{y(C.collectionId),v(C.slug),k(r(C.slug,C.collectionId)),A(""),D(!1)}})]}),g&&e("div",{className:"CopyDocModal__error",children:g}),e("div",{className:"CopyDocModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",type:"submit",size:"xs",color:"dark",loading:x,disabled:!!m||!!g&&!a,children:a?"Overwrite?":"Submit"})]})]})})}po.id=to;X();function B(s){return e("div",{className:"DocIdBadge",children:e("code",{"data-testid":"doc-id",children:s.docId})})}var io="LockPublishingModal";function no(s){let t=N(),u=H();return{open:l=>{let d={...s,...l},o;d.unlock?o=`Unlock publishing for ${s.docId}`:d.existingLock?o=`Edit publishing lock for ${s.docId}`:o=`Lock publishing for ${s.docId}`,t.openContextModal(io,{...u,title:o,innerProps:{...s,...l},size:"600px"})}}}function fo(s){let t=l=>l<10?"0"+l:l,u=new Date(s);return`${u.getFullYear()}-${t(u.getMonth()+1)}-${t(u.getDate())}T${t(u.getHours())}:${t(u.getMinutes())}`}function Z(s){let{innerProps:t}=s;return t.unlock?e(Z.Unlock,{...s}):e(Z.Lock,{...s})}Z.Lock=s=>{let{innerProps:t,context:u,id:l}=s,d=!!t.existingLock,[o,y]=c(t.existingLock?.reason||""),[p,v]=c(t.existingLock?.until||0),[m,k]=c(!1),[g,A]=c(!1),a=N();function D(f){return f?Math.floor(new Date(f).getTime()):0}async function x(f){f.preventDefault(),k(!0),await U(async()=>{await Ie(t.docId,{reason:o,until:p}),_({title:d?"Updated!":"Locked!",message:d?`Publishing lock updated for ${t.docId}.`:`Publishing is locked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("locked")}),k(!1)}async function T(){A(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("unlocked")}),A(!1)}return e("div",{className:"LockPublishingModal LockPublishingModal--lock",children:[e(M,{className:"LockPublishingModal__body",size:"body-sm",children:d?"Publishing is currently locked. Update the publishing lock details below, or remove the lock to re\u2011enable publishing.":"Are you sure you want to lock publishing? Content editors will not be able to publish until publishing is unlocked."}),e("form",{className:"LockPublishingModal__form",onSubmit:f=>x(f),children:[e("div",{className:"LockPublishingModal__form__section",children:e(me,{name:"reason",label:"Reason",description:"Specify a short reason so other content editors know why publishing is locked.",size:"xs",radius:0,value:o,onChange:f=>{y(f.currentTarget.value)}})}),e("div",{className:"LockPublishingModal__form__section",children:e(ue,{label:"Lock until",description:"Optional. Publishing is unlocked at the specified time. If not provided, publishing will be locked indefinitely.",size:"xs",children:e("div",{className:"DocEditor__DateTimeField",children:[e("input",{name:"until",type:"datetime-local",min:he(),defaultValue:p?fo(p):"",onChange:f=>{let L=f.target.value;v(D(L))}}),e("div",{className:"DocEditor__DateTimeField__timezone",children:["timezone: ",Intl.DateTimeFormat().resolvedOptions().timeZone]})]})})}),e("div",{className:"LockPublishingModal__buttons",children:[d&&e(b,{variant:"filled",size:"xs",color:"red",type:"button",leftIcon:e(Y,{size:14}),loading:g,disabled:m,onClick:()=>T(),className:"LockPublishingModal__buttons__unlock",children:"Unlock"}),e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(ee,{size:14}),disabled:!o||g,type:"submit",loading:m,children:d?"Save":"Lock"})]})]})]})};Z.Unlock=s=>{let{innerProps:t,context:u,id:l}=s,[d,o]=c(!1),y=N();async function p(){o(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),y.closeModal(l),t.onChange&&t.onChange("unlocked")})}return e("div",{className:"LockPublishingModal LockPublishingModal--unlock",children:[e(M,{className:"LockPublishingModal__body",children:"Are you sure you want to unlock publishing for the following doc? This will re-enable content editors to publish the doc."}),e(B,{docId:t.docId}),e("div",{className:"LockPublishingModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(Y,{size:14}),loading:d,onClick:()=>p(),children:"Unlock"})]})]})};Z.id=io;X();var ro="VersionHistoryModal",ao=50;function co(s){let t=N(),u=H();return{open:()=>{t.openContextModal(ro,{...u,title:`Version history: ${s.docId}`,innerProps:s,overflow:"inside",size:"min(calc(100% - 32px), 720px)"})}}}function _o(s){let{innerProps:t,context:u,id:l}=s,d=t.docId,[o,y]=c(!0),[p,v]=c(!1),[m,k]=c([]),[g,A]=c(!1),[a,D]=c([]),[x,T]=c(!1),[w,f]=c(null),I=ce(null),L=oe({fromDocId:d}),$=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});async function r(){y(!0);let[i,h]=await Promise.all([de(d,{limit:ao}),ze(d,"draft")]);I.current=i.lastDoc,A(i.hasMore);let V={_versionId:"draft",sys:{modifiedAt:h?.sys?.modifiedAt||{toDate:()=>new Date},modifiedBy:h?.sys?.modifiedBy||"Unknown"}};k([V,...i.versions]),D(["draft"]),y(!1)}async function n(){if(!g||p)return;v(!0);let i=await de(d,{limit:ao,cursor:I.current});I.current=i.lastDoc,A(i.hasMore),k(h=>[...h,...i.versions]),v(!1)}async function C(i){await Ne(d,i),_({title:"Saved!",message:`Restored ${d} to ${$.format(i.sys.modifiedAt.toDate())}.`,autoClose:5e3}),t.onRestore&&t.onRestore({version:i})}function E(i){let h=`${d}@${i._versionId}`,V=i.sys?.modifiedAt?.toDate();if(V){let W=go(V);h=`${d}@${W}`}L.open({fields:i.fields||{},fromLabel:h,onSuccess:()=>{u.closeModal(l)}})}function R(i){a.includes(i)?D(a.filter(h=>h!==i)):a.length<2&&D([...a,i])}function z(){if(a.length!==2)return"#";let i=m.find(te=>te._versionId===a[0]),h=m.find(te=>te._versionId===a[1]);if(!i||!h)return"#";let V=m.indexOf(i),W=m.indexOf(h),re=V>W?i:h,G=V>W?h:i,se=lo(d,re._versionId),uo=lo(d,G._versionId);return`/cms/compare?left=${se}&right=${uo}`}j(()=>{r()},[]);let O=m.filter(i=>i._versionId==="draft"||!x?!0:i.tags?.includes("published")),q=m.some(i=>i.tags?.includes("published"));return o?e(J,{}):e("div",{className:"VersionHistoryModal",children:[e("div",{className:"VersionHistoryModal__actions",children:[e(b,{component:a.length===2?"a":"button",variant:"filled",size:"xs",disabled:a.length!==2,href:a.length===2?z():void 0,target:a.length===2?"_blank":void 0,rightIcon:e(Fe,{size:16}),children:"Compare"}),q&&e(ie,{size:"xs",label:"Published versions only",checked:x,onChange:i=>T(i.currentTarget.checked)})]}),O.length===0?e(M,{className:"VersionHistoryModal__versionsEmpty",size:"body",children:[e("p",{children:"No versions found."}),e("p",{className:"VersionHistoryModal__versionsEmpty__developer",children:"For developers: Configure the Root CMS cron job to populate versions."})]}):e(S,{children:[e(pe,{className:"VersionHistoryModal__versions",children:[e("thead",{children:e("tr",{children:[e("th",{children:e("span",{className:"VersionHistoryModal__versions__selectLabel",children:"Select"})}),e("th",{children:"modified at"}),e("th",{children:"modified by"}),e("th",{children:"actions"})]})}),e("tbody",{children:O.map(i=>{let h=i._versionId==="draft",V=a.includes(i._versionId),W=!V&&a.length>=2;return e("tr",{children:[e("td",{children:e(ie,{size:"xs",checked:V,disabled:W,onChange:()=>R(i._versionId),className:"VersionHistoryModal__versions__checkbox"})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__modifiedAt",children:[e(M,{size:"body-sm",className:"VersionHistoryModal__versions__modifiedAt__text",children:h?e("span",{title:"Current Draft",children:[$.format(i.sys.modifiedAt.toDate())," ","(Latest)"]}):e(S,{children:[$.format(i.sys.modifiedAt.toDate()),i.tags?.includes("published")&&e("span",{className:"VersionHistoryModal__publishedLabel",children:"(Published)"})]})}),i.publishMessage&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-message`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,classNames:{body:"VersionHistoryModal__popover__body",arrow:"VersionHistoryModal__popover__arrow",close:"VersionHistoryModal__popover__close"},target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-message`?null:`${i._versionId}-message`),children:e(Qe,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:i.publishMessage})}),(()=>{let G=i.tags?.find(se=>se.startsWith("release:"))?.replace("release:","");return G&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-release`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-release`?null:`${i._versionId}-release`),children:e(Ze,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:[e("strong",{children:"Release:"})," ",G]})})})()]})}),e("td",{children:e(M,{size:"body-sm",children:i.sys.modifiedBy})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__buttons",children:!h&&e(S,{children:[e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>C(i),children:"restore"}),e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>E(i),leftIcon:e(K,{size:12}),children:"copy to doc"})]})})})]},i._versionId)})})]}),g&&e("div",{className:"VersionHistoryModal__loadMore",children:e(b,{variant:"subtle",size:"xs",loading:p,onClick:n,children:"Load more versions"})})]})]})}function lo(s,t){return encodeURIComponent(`${s}@${t}`).replaceAll("%2F","/").replaceAll("%40","@")}function go(s){let t=s.getFullYear(),u=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0"),d=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${t}-${u}-${l}T${d}:${o}`}_o.id=ro;function Js(s){let{roles:t}=Xe(),u=window.firebase.user.email||"",l=Ke(t,u),d=Je(t,u),o=s.docId,y=s.data||{},p=y.sys||{},v=we(y),m=N(),k=oe({fromDocId:o,onSuccess:r=>{s.onAction&&s.onAction({action:"copy",newDocId:r})}}),g=H(),A=co({docId:o}),a=no({docId:o}),D=so({docIds:[o]}),x=()=>{let r=`revert-draft-${o}`,n=m.openConfirmModal({...g,title:`Discard draft edits for ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to discard draft changes for the following doc? The doc data will revert to the published version. There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Discard draft edits",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Discarding draft edits",message:`Discarding draft edits of ${o}...`,loading:!0,autoClose:!1}),await xe(o),F({id:r,title:"Discarded draft edits",message:`Successfully reverted ${o} back to its published version`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"revert-draft"})}})},T=()=>{let r=`unpublish-doc-${o}`,n=m.openConfirmModal({...g,title:`Unpublish ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unpublish the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Unpublish",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unpublishing doc",message:`Requesting unpublish of ${o}...`,loading:!0,autoClose:!1}),await ve(o),F({id:r,title:"Unpublished!",message:`Successfully unpublished ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unpublish"})}})},w=r=>{s.onAction&&s.onAction({action:r})},f=()=>{let r=`unschedule-doc-${o}`,n=m.openConfirmModal({...g,title:`Unschedule ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unschedule the following doc?"}),e(B,{docId:o})]}),labels:{confirm:"Unschedule",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unschedule doc",message:`Requesting unschedule of ${o}...`,loading:!0,autoClose:!1}),await Ce(o),F({id:r,title:"Unscheduled!",message:`Successfully unscheduled ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unschedule"})}})},I=()=>{let r=`archive-doc-${o}`,n=m.openConfirmModal({...g,title:`Archive ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to archive the following doc? Archived docs are hidden from the collection list by default but can be restored later."}),e(B,{docId:o})]}),labels:{confirm:"Archive",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Archiving doc",message:`Requesting archive of ${o}...`,loading:!0,autoClose:!1}),await ke(o),F({id:r,title:"Archived!",message:`Successfully archived ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"archive"})}})},L=async()=>{let r=`unarchive-doc-${o}`;_({id:r,title:"Unarchiving doc",message:`Requesting unarchive of ${o}...`,loading:!0,autoClose:!1}),await Ae(o),F({id:r,title:"Unarchived!",message:`Successfully unarchived ${o}!`,loading:!1,autoClose:5e3}),s.onAction&&s.onAction({action:"unarchive"})},$=()=>{let r=`delete-doc-${o}`,n=m.openConfirmModal({...g,title:"Delete doc",children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to delete the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Delete",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Deleting doc",message:`Requesting deletion of ${o}...`,loading:!0,autoClose:!1}),await ye(o),F({id:r,title:"Deleted!",message:`Successfully deleted ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onDelete&&s.onDelete(),s.onAction&&s.onAction({action:"delete"})}})};return e(P,{className:"CollectionPage__collection__docsList__doc__controls__menu",position:"bottom",control:e(Q,{className:"DocEditor__ArrayField__item__header__controls__dots",children:e(We,{size:16})}),children:[!v&&e(P.Item,{icon:e(Ye,{size:20}),onClick:()=>D.open(),disabled:!d,children:"Add to release"}),e(P.Item,{icon:e(je,{size:20}),onClick:()=>A.open(),children:"Version history"}),e(P.Item,{icon:e(K,{size:20}),onClick:()=>k.open(),disabled:!l,children:"Copy"}),!v&&p.modifiedAt&&p.publishedAt&&p.modifiedAt>p.publishedAt&&e(P.Item,{icon:e(Oe,{size:20}),onClick:()=>x(),disabled:!l,children:"Discard draft edits"}),!v&&p.firstPublishedAt&&e(P.Item,{icon:e(qe,{size:20}),onClick:()=>T(),disabled:!d,children:"Unpublish"}),!v&&p.scheduledAt&&e(P.Item,{icon:e(Ee,{size:20}),onClick:()=>f(),disabled:!d,children:"Unschedule"}),!v&&(Te(y)?e(P.Item,{icon:e(Y,{size:20}),onClick:()=>a.open({unlock:!0,onChange:w}),disabled:!l,children:"Unlock publishing"}):e(P.Item,{icon:e(ee,{size:20}),onClick:()=>a.open({unlock:!1,onChange:w}),disabled:!l||De(y),children:"Lock publishing"})),v?e(P.Item,{icon:e(Ue,{size:20}),onClick:()=>L(),disabled:!l,children:"Unarchive"}):!p.publishedAt&&e(P.Item,{icon:e(Be,{size:20}),onClick:()=>I(),disabled:!l,children:"Archive"}),e(P.Item,{icon:e(Ge,{size:20}),onClick:()=>$(),disabled:!l,children:"Delete"})]})}export{so as a,mo as b,po as c,B as d,no as e,Z as f,_o as g,Js as h};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import{a as Nt,b as Pt,c as Et,d as St,e as zt,f as jt,g as Dt,h as Lt,i as $t,j as Bt,k as Ut,l as Ot,m as Wt,n as Ht,o as nt}from"./chunk-GCSN3YEC.js";import{a as wt}from"./chunk-QWB6MAPJ.js";import{a as Tt,c as at}from"./chunk-VPZHG7JL.js";import{P as kt,T as Mt}from"./chunk-AAR7DBEN.js";import{f as Y}from"./chunk-5MV6XVGA.js";import{b as _t,c as mt,g as ut,h as ht,j as ft,n as q,o as gt,p as xt,r as Ct,v as G}from"./chunk-XOWWPE7X.js";import{d as At,e as N}from"./chunk-WASID5UU.js";import{$a as Q,Bc as j,Fa as H,Ga as o,Hc as yt,V as J,Vc as Rt,W as P,a as h,ab as Z,ad as U,ba as X,bb as tt,c as k,da as z,e as v,g as pt,h as M,j as oe,kc as et,pb as vt,pc as ot,qa as B,qc as bt}from"./chunk-WRA24P66.js";import{d as ct}from"./chunk-KUCVLANF.js";import{h as It}from"./chunk-7SK47HHZ.js";oe();var ae=500;function Ft(){return window.firebase.db}function Vt(){return window.__ROOT_CTX.rootConfig.projectId}function it(){return window.firebase.user?.email||""}function ne(){return _t(Ft(),"Projects",Vt(),"AiChats")}function rt(t){return mt(Ft(),"Projects",Vt(),"AiChats",t)}function D(t){return t&&typeof t.toMillis=="function"?t.toMillis():typeof t=="number"?t:0}async function Kt(t){let e=it();if(!e)return[];let a=t?.limit,n=typeof a=="number"&&Number.isFinite(a)&&a>0?Math.min(Math.floor(a),100):50,p=ut(ne(),ht("createdBy","==",e),ft(ae)),s=(await gt(p)).docs.map(l=>l.data());return s.sort((l,g)=>D(g.modifiedAt)-D(l.modifiedAt)),s.slice(0,n).map(l=>({id:l.id,title:l.title,modelId:l.modelId,createdAt:D(l.createdAt),modifiedAt:D(l.modifiedAt)}))}async function st(t){let e=await q(rt(t));if(!e.exists())return null;let a=e.data();return a.createdBy!==it()?null:{id:a.id||t,title:a.title,modelId:a.modelId,createdAt:D(a.createdAt),modifiedAt:D(a.modifiedAt),messages:a.messages||[]}}async function Jt(t,e){let a=it(),n=rt(t),p=await q(n);if(p.exists()&&p.data().createdBy!==a)throw new Error("chat is owned by another user");let _={id:t,createdBy:a,modifiedAt:G(),messages:$t(e.messages)};p.exists()||(_.createdAt=G()),e.modelId&&(_.modelId=e.modelId),e.title&&(_.title=e.title),await xt(n,_,{merge:!0})}async function Xt(t){await st(t)&&await Ct(rt(t))}async function qt(t,e){let a=St(e);if(a==="New chat")return a;let n=zt(e);if(!n)return a;try{let p=Et(Pt(t)),_=await kt({model:p,system:Dt,prompt:Lt(n),maxOutputTokens:64,temperature:.3}),s=jt(_.text);if(s)return s}catch(p){console.error("failed to generate chat title:",p)}return a}function Gt(t){let{size:e=14}=t,a=e*3.57,n=e*2;return o("div",{className:"BouncingLoader",style:{"--dot-size":`${e}px`,width:`${a}px`,height:`${n}px`}})}var lt=[{id:"read",label:"Read only",description:"Inspect CMS content without planning or applying writes."},{id:"approve",label:"Ask before writing",description:"Read freely, then pause for approval before draft edits."},{id:"auto",label:"Auto-apply draft edits",description:"Apply draft-only writes without approval in this chat."}],te="root-cms.ai.executionMode",ee="root-cms.ai.selectedModel";function ie(t){return lt.some(e=>e.id===t)}function re(){if(typeof window>"u")return"approve";try{let t=window.localStorage.getItem(te);if(ie(t))return t}catch(t){console.error("failed to read AI execution mode preference",t)}return"approve"}function se(t){if(typeof window>"u")return null;try{let e=window.localStorage.getItem(ee);if(e&&t.some(a=>a.id===e))return e}catch(e){console.error("failed to read AI model preference",e)}return null}function le(t){if(!(typeof window>"u"))try{window.localStorage.setItem(ee,t)}catch(e){console.error("failed to save AI model preference",e)}}function de(t){if(!(typeof window>"u"))try{window.localStorage.setItem(te,t)}catch(e){console.error("failed to save AI execution mode preference",e)}}var F="";function mo(t){let[e,a]=h(null),[n,p]=h("");k(()=>{let s=!0;return fetch("/cms/api/ai.config",{credentials:"include"}).then(async l=>{let g=await l.json();s&&a(g)}).catch(l=>{s&&p(String(l))}),()=>{s=!1}},[]);let _=!!e?.enabled&&(e.models?.length||0)>0;return o("div",{className:N("RootAIChat",`RootAIChat--${t.variant}`),children:!e&&!n?o("div",{className:"RootAIChat__loading",children:o(J,{size:"md",color:"gray"})}):_?o(pe,{variant:t.variant,config:e,initialChatId:t.variant==="panel"?void 0:t.initialChatId,docContext:t.docContext,onClose:t.onClose}):o(ce,{error:n,onClose:t.onClose})})}function ce(t){return o("div",{className:"RootAIChat__notEnabled",children:[t.onClose&&o(P,{className:"RootAIChat__notEnabled__close",onClick:t.onClose,title:"Close",children:o(U,{size:16})}),o("div",{className:"RootAIChat__notEnabled__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__notEnabled__title",children:"Root AI is not configured for this project."}),o("div",{className:"RootAIChat__notEnabled__body",children:["Add an ",o("code",{children:"ai.models"})," entry to ",o("code",{children:"cmsPlugin()"})," in"," ",o("code",{children:"root.config.ts"}),"."]}),t.error&&o("pre",{className:"RootAIChat__notEnabled__error",children:t.error})]})}function pe(t){let e=t.variant==="panel",{route:a}=At(),n=t.config.models||[],p=()=>se(n)||t.config.defaultModel||n[0]?.id||"",[_,s]=h(p),[l,g]=h(re),[f,b]=h(t.initialChatId||F),[y,C]=h(t.initialChatId||F),[E,d]=h([]),[x,A]=h(""),[I,T]=h([]),[V,O]=h(0),S=async()=>{if(!e)try{let i=await Kt();T(i)}catch(i){console.error("failed to load chat list",i)}};k(()=>{S(),!e&&t.initialChatId&&K(t.initialChatId)},[]),k(()=>{de(l)},[l]);let L=async i=>{try{let u=await st(i);return u?(b(i),C(i),d(u.messages||[]),A(u.title||""),u.modelId&&n.find(R=>R.id===u.modelId)&&s(u.modelId),O(w=>w+1),!0):!1}catch(u){return console.error("failed to load chat",u),!1}},K=i=>L(i),$=()=>{s(p()),b(F),C(F),d([]),A(""),O(i=>i+1),e||a("/cms/ai")},W=async i=>{if(i===y)return;await L(i)&&!e&&a(`/cms/ai/chat/${i}`)},r=async i=>{try{await Xt(i),y===i&&$(),S()}catch(u){console.error("failed to delete chat",u)}},m=n.find(i=>i.id===_)||n[0],c=i=>{s(i),le(i)};return o("div",{className:"RootAIChat__layout",children:[!e&&o(me,{chats:I,activeChatId:y,onSelect:W,onNew:$,onDelete:r}),o("div",{className:"RootAIChat__main",children:[e&&o(_e,{onNewChat:$,onClose:t.onClose}),o(he,{initialChatId:f,initialTitle:x,model:m,initialMessages:E,executionMode:l,canAutoApply:t.config.canAutoApply??!1,models:n,selectedModel:m,docContext:t.docContext,onSelectModel:c,onSelectExecutionMode:g,onChatPersisted:i=>{C(i),S(),e||window.history.replaceState(null,"",`/cms/ai/chat/${i}`)}},V)]})]})}function _e(t){return o("div",{className:"RootAIChat__panelHeader",children:[o("div",{className:"RootAIChat__panelHeader__title",children:[o(j,{size:14}),o("span",{children:"Root AI"})]}),o("div",{className:"RootAIChat__panelHeader__actions",children:[o(H,{label:"New chat",children:o(P,{size:"xs",onClick:t.onNewChat,children:o(et,{size:14})})}),t.onClose&&o(H,{label:"Close (\u2318 + i)",children:o(P,{size:"xs",onClick:t.onClose,children:o(U,{size:14})})})]})]})}function me(t){return o("aside",{className:"RootAIChat__sidebar",children:[o("button",{type:"button",className:"RootAIChat__sidebar__newButton",onClick:t.onNew,children:[o(et,{size:18}),o("span",{children:"New chat"})]}),o("div",{className:"RootAIChat__sidebar__list",children:[t.chats.length===0&&o("div",{className:"RootAIChat__sidebar__empty",children:"No chats yet."}),t.chats.map(e=>o("div",{className:N("RootAIChat__sidebar__item",e.id===t.activeChatId&&"RootAIChat__sidebar__item--active"),onClick:()=>t.onSelect(e.id),children:[o("div",{className:"RootAIChat__sidebar__item__title",title:e.title||"Untitled chat",children:e.title||"Untitled chat"}),o("button",{type:"button",className:"RootAIChat__sidebar__item__delete",title:"Delete chat",onClick:a=>{a.stopPropagation(),window.confirm("Delete this chat?")&&t.onDelete(e.id)},children:o(Rt,{size:14})})]},e.id))]})]})}function ue(t){let e=t.canAutoApply?lt:lt.filter(n=>n.id!=="auto"),a=e.find(n=>n.id===t.executionMode)||e[0];return o("div",{className:"RootAIChat__options",children:[o(B,{control:o(z,{type:"button",className:"RootAIChat__modePicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(bt,{size:16}),children:a.label}),children:e.map(n=>o(B.Item,{onClick:()=>t.onSelectExecutionMode(n.id),children:o("div",{className:"RootAIChat__modePicker__option",children:[o("div",{className:"RootAIChat__modePicker__option__label",children:n.label}),o("div",{className:"RootAIChat__modePicker__option__description",children:n.description})]})},n.id))}),o(B,{control:o(z,{type:"button",className:"RootAIChat__modelPicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(j,{size:16}),children:t.selectedModel?.label||"Select model"}),children:t.models.map(n=>o(B.Item,{onClick:()=>t.onSelectModel(n.id),children:o("div",{className:"RootAIChat__modelPicker__option",children:[o("div",{className:"RootAIChat__modelPicker__option__label",children:n.label}),n.description&&o("div",{className:"RootAIChat__modelPicker__option__description",children:n.description})]})},n.id))})]})}function he(t){let[e]=h(()=>t.initialChatId||Se()),a=v(t.model?.id);a.current=t.model?.id;let n=v(t.executionMode);n.current=t.executionMode;let p=v(t.docContext);p.current=t.docContext;let _=v(t.onChatPersisted);_.current=t.onChatPersisted;let s=v(null),l=v(t.executionMode),g=v(t.initialTitle),f=v(null),[b,y]=h({}),C=v({});k(()=>()=>{for(let r of Object.values(C.current))r("reject");C.current={}},[]);let E=M((r,m,c,i)=>new Promise(u=>{C.current[r]=u,y(w=>({...w,[r]:{toolCallId:r,toolName:m,input:c,preview:i,status:"pending"}}))}),[]),d=M(r=>{y(m=>{let c=m[r];return c?{...m,[r]:{...c,status:"executing"}}:m}),C.current[r]?.("approve"),delete C.current[r]},[]),x=M(r=>{y(m=>{let c={...m};return delete c[r],c}),C.current[r]?.("reject"),delete C.current[r]},[]),A=M(async r=>{if(!Wt(r.toolName))return await nt(r.toolName,r.input);let m=l.current;if(m==="read")return{success:!1,error:"WRITE_BLOCKED_BY_MODE",message:"The current execution mode is read only. Do not call write tools."};let c;try{c=await Ht(r.toolName,r.input)}catch(i){return{success:!1,error:"PREVIEW_FAILED",message:i?.message||String(i)}}if(c.error)return{success:!1,error:c.error,message:c.summary,errors:c.errors,hint:c.hint};if(m==="approve"&&await E(r.toolCallId,r.toolName,r.input,c)==="reject")return{success:!1,error:"USER_REJECTED",message:"The user rejected this draft change. Do not retry unless they ask for a revised version."};try{return await nt(r.toolName,r.input)}finally{y(i=>{if(!i[r.toolCallId])return i;let u={...i};return delete u[r.toolCallId],u})}},[E]),I=M(async r=>{let m=s.current;try{let c=g.current;if(!c&&m){let i=await qt(m,r);i&&i!=="New chat"&&(c=i,g.current=i)}await Jt(e,{messages:r,modelId:m?.id||a.current,title:c||void 0})}catch(c){console.error("failed to persist chat history",c)}_.current(e)},[e]),T=pt(()=>Bt({loadTurnConfig:async()=>{let r=a.current,m=n.current,c=p.current?.docId,i=`${r}|${m}|${c||""}`,u=f.current;if(u&&u.key===i)return u.config;let w=await fetch("/cms/api/ai.chat.prepare",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({modelId:r,executionMode:m,docId:c})}),R=await w.json();if(!w.ok||!R.success)throw new Error(R.error||`ai.chat.prepare failed: ${w.status}`);let dt={model:R.model,system:R.system,maxSteps:R.maxSteps};return s.current=R.model,l.current=R.executionMode||m,f.current={key:i,config:dt},dt},buildTools:r=>r.capabilities.tools?l.current==="read"?Ot():Ut():{},onFinish:I}),[I]),{messages:V,sendMessage:O,status:S,error:L,stop:K,addToolOutput:$}=Nt({id:e,messages:t.initialMessages,transport:T,sendAutomaticallyWhen:Mt,onToolCall:async({toolCall:r})=>{let m=await A(r);$({tool:r.toolName,toolCallId:r.toolCallId,output:m})}}),W=S==="streaming"||S==="submitted";return o(ct,{children:[o(fe,{messages:V,isStreaming:W,emptyMessage:t.model?void 0:"Select a model to start.",toolApprovals:{approvals:b,onApprove:d,onReject:x}}),L&&o("div",{className:"RootAIChat__error",children:[o("strong",{children:"Error:"})," ",L.message]}),o(ke,{disabled:!t.model,canAttach:t.model?.capabilities.attachments??!1,isStreaming:W,onStop:K,controls:o(ue,{models:t.models,selectedModel:t.selectedModel,onSelectModel:t.onSelectModel,executionMode:t.executionMode,canAutoApply:t.canAutoApply,onSelectExecutionMode:t.onSelectExecutionMode}),onSend:(r,m)=>{if(!r&&m.length===0)return;let c=Me(m),i=[r,c.text].filter(Boolean).join(`
|
|
2
|
-
|
|
3
|
-
`);O({text:i,files:c.files.map(u=>({type:"file",mediaType:u.mediaType,url:u.url,filename:u.filename}))})}})]})}function fe(t){let e=v(null);return k(()=>{let a=e.current;a&&(a.scrollTop=a.scrollHeight)},[t.messages]),t.messages.length===0?o("div",{className:"RootAIChat__transcript RootAIChat__transcript--empty",ref:e,children:o("div",{className:"RootAIChat__welcome",children:[o("div",{className:"RootAIChat__welcome__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__welcome__title",children:"Root AI"}),o("div",{className:"RootAIChat__welcome__body",children:t.emptyMessage||"What are we going to get done today?"})]})}):o("div",{className:"RootAIChat__transcript",ref:e,children:o("div",{className:"RootAIChat__transcript__inner",children:[t.messages.map(a=>o(ge,{message:a,toolApprovals:t.toolApprovals},a.id)),t.isStreaming&&o("div",{className:"RootAIChat__streamingIndicator",children:o(Gt,{size:6})})]})})}function ge(t){let e=t.message,a=e.role==="user",n=a?"You":"Root AI",p=a?window.firebase.user?.photoURL:null,[_,s]=h(!1),l=M(()=>(e.parts||[]).filter(f=>f.type==="text"&&f.text).map(f=>f.text).join(`
|
|
4
|
-
|
|
5
|
-
`),[e.parts]),g=M(async()=>{let f=l();if(!f)return;let b=Tt.parse(f);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([b],{type:"text/html"}),"text/plain":new Blob([f],{type:"text/plain"})})]),s(!0),setTimeout(()=>s(!1),2e3)}catch{await navigator.clipboard.writeText(f),s(!0),setTimeout(()=>s(!1),2e3)}},[l]);return o("div",{className:N("RootAIChat__message",`RootAIChat__message--${e.role}`),children:[o("div",{className:"RootAIChat__message__avatar",children:p?o("img",{src:p,alt:n}):o(j,{size:20})}),o("div",{className:"RootAIChat__message__body",children:[o("div",{className:"RootAIChat__message__username",children:n}),o("div",{className:"RootAIChat__message__parts",children:(e.parts||[]).map((f,b)=>o(xe,{part:f,toolApprovals:t.toolApprovals},b))}),o("button",{type:"button",className:N("RootAIChat__message__copy",_&&"RootAIChat__message__copy--copied"),title:_?"Copied!":"Copy message",onClick:g,children:_?o(Q,{size:14}):o(vt,{size:14})})]})]})}function xe(t){let e=t.part;return e.type==="text"?e.text?o("div",{className:"RootAIChat__textPart",children:o(at,{code:e.text})}):null:e.type==="reasoning"?o(Ce,{text:e.text}):e.type==="file"?o(Ae,{part:e}):e.type==="source-url"?o("a",{className:"RootAIChat__sourcePart",href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.title||e.url}):typeof e.type=="string"&&e.type.startsWith("tool-")?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="dynamic-tool"?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="step-start"?null:o("div",{className:"RootAIChat__unknownPart",children:o("pre",{children:JSON.stringify(e,null,2)})})}function Ce(t){let[e,a]=h(!1);return t.text?o("div",{className:N("RootAIChat__reasoning",e&&"RootAIChat__reasoning--open"),children:[o("button",{type:"button",className:"RootAIChat__reasoning__toggle",onClick:()=>a(!e),children:[o(Z,{size:14,style:{transform:e?"rotate(0deg)":"rotate(-90deg)"}}),o("span",{children:"Thinking"})]}),e&&o("div",{className:"RootAIChat__reasoning__body",children:o(at,{code:t.text})})]}):null}function Ae(t){let e=t.part;return e.mediaType?.startsWith("image/")?o("div",{className:"RootAIChat__filePart",children:o("img",{src:e.url,alt:e.filename||"attachment"})}):o("a",{className:"RootAIChat__filePart RootAIChat__filePart--link",href:e.url,target:"_blank",rel:"noopener noreferrer",children:[o(ot,{size:14}),o("span",{children:e.filename||e.url})]})}function Yt(t){let e=t.part,a=typeof e.type=="string"&&e.type.startsWith("tool-")?e.type.slice(5):e.toolName||"tool",n=e.state||"",p=Ie(e),_=t.toolApprovals,s=p?_?.approvals[p]:void 0,[l,g]=h(!!s);return k(()=>{s&&g(!0)},[s]),o("div",{className:"RootAIChat__tool",children:[o("button",{type:"button",className:"RootAIChat__tool__header",onClick:()=>g(!l),children:[o(Z,{className:N("RootAIChat__tool__header__icon",l&&"RootAIChat__tool__header__icon--open"),size:14}),o(X,{color:"dark",variant:"filled",size:"xs",children:a}),o("span",{className:"RootAIChat__tool__title",children:ve(a,e.input)}),o("span",{className:"RootAIChat__tool__state",children:s?Re(s.status):we(n)})]}),l&&o("div",{className:"RootAIChat__tool__body",children:[s&&_&&o(be,{approval:s,onApprove:()=>_.onApprove(s.toolCallId),onReject:()=>_.onReject(s.toolCallId)}),e.output?.receipt&&o(ye,{output:e.output}),e.input&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Input"})]}),o("pre",{children:JSON.stringify(e.input,null,2)})]}),e.output&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Output"})]}),o("pre",{children:JSON.stringify(e.output,null,2)})]}),e.errorText&&o("div",{className:"RootAIChat__tool__error",children:e.errorText})]})]})}function Ie(t){return t.toolCallId||t.id||""}function ve(t,e){switch(t){case"collections_list":return"List collections";case"docs_list":return`List ${e?.collectionId||"documents"}`;case"docs_search":return`Search docs${e?.query?` for "${e.query}"`:""}`;case"doc_get":return`Read ${e?.docId||"document"}`;case"doc_getVersion":return`Read ${e?.docId||"document"} version`;case"doc_set":return`Replace ${e?.docId||"draft fields"}`;case"doc_create":return`Create ${e?.docId||"draft document"}`;case"doc_updateField":return`Update ${e?.path||"field"}`;case"doc_edit":return`Edit ${e?.docId||"document"}`;case"doc_duplicate":return`Duplicate ${e?.fromDocId||"document"}`;case"doc_listVersions":return`List versions for ${e?.docId||"document"}`;case"doc_translateField":return"Translate field text";case"schema_get":return`Read ${e?.collectionId||"collection"} schema`;default:return t}}function be(t){let e=t.approval.preview,a=e.before!==void 0&&e.after!==void 0;return o("div",{className:"RootAIChat__approval",children:[o("div",{className:"RootAIChat__approval__header",children:[o("div",{children:[o("div",{className:"RootAIChat__approval__title",children:e.title}),o("div",{className:"RootAIChat__approval__summary",children:e.summary})]}),o(X,{className:"RootAIChat__approval__status",variant:"light",color:"gray",children:t.approval.status==="executing"?"Applying":"Review"})]}),e.details.length>0&&o("div",{className:"RootAIChat__approval__details",children:e.details.map(n=>o("div",{children:[o("span",{children:n.label}),o("strong",{children:n.value})]},`${n.label}:${n.value}`))}),a&&o(wt,{className:"RootAIChat__approval__diff",oldCode:Y(e.before),newCode:Y(e.after)}),o("div",{className:"RootAIChat__approval__actions",children:[o(z,{variant:"default",color:"dark",size:"xs",type:"button",className:"RootAIChat__approval__button",disabled:t.approval.status==="executing",onClick:t.onReject,children:"Reject"}),o(z,{variant:"filled",color:"green",size:"xs",type:"button",className:"RootAIChat__approval__button RootAIChat__approval__button--primary",disabled:t.approval.status==="executing",onClick:t.onApprove,children:"Approve draft edit"})]})]})}function ye(t){let e=t.output.receipt;return o("div",{className:"RootAIChat__receipt",children:[o("div",{className:"RootAIChat__receipt__title",children:[o(Q,{size:14}),o("span",{children:e.title})]}),o("div",{className:"RootAIChat__receipt__summary",children:e.summary}),e.details?.length>0&&o("div",{className:"RootAIChat__receipt__details",children:e.details.map(a=>o("div",{children:[o("span",{children:a.label}),o("strong",{children:a.value})]},`${a.label}:${a.value}`))}),e.adminUrl&&o(z,{component:"a",className:"RootAIChat__receipt__link",variant:"default",size:"xs",compact:!0,href:e.adminUrl,children:"Open document"})]})}function Re(t){return t==="executing"?"applying\u2026":"waiting for approval"}function we(t){switch(t){case"input-streaming":return"preparing\u2026";case"input-available":return"running\u2026";case"output-available":return"done";case"output-error":return"error";default:return t}}function ke(t){let[e,a]=h(""),[n,p]=h([]),[_,s]=h(!1),l=v(null),g=v(null);k(()=>{window.requestAnimationFrame(()=>{let d=g.current;d&&(d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,240)}px`)})},[e,n]);let b=()=>{t.disabled||t.isStreaming||!e&&n.length===0||(t.onSend(e,n),a(""),p([]),l.current&&(l.current.value=""))},y=d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),b())},C=async d=>{s(!0);try{let x=d.type||Ee(d.name),A=await Te(d,x),I=await It(d,{disableGci:!0});p(T=>[...T,{url:I.src,filename:I.filename||d.name,mediaType:x,textContent:A?.text,textTruncated:A?.truncated,width:I.width,height:I.height}])}catch(x){console.error("upload failed",x)}finally{s(!1),l.current&&(l.current.value="")}},E=d=>{let x=d.target;Array.from(x.files||[]).forEach(C)};return o("div",{className:"RootAIChat__composer",children:[n.length>0&&o("div",{className:"RootAIChat__composer__attachments",children:n.map((d,x)=>o("div",{className:"RootAIChat__composer__attachment",children:[d.mediaType.startsWith("image/")?o("img",{src:d.url,alt:d.filename}):o("span",{className:"RootAIChat__composer__attachment__name",children:d.filename}),o("button",{type:"button",className:"RootAIChat__composer__attachment__remove",onClick:()=>p(A=>A.filter((I,T)=>T!==x)),children:o(U,{size:12})})]},x))}),o("div",{className:"RootAIChat__composer__row",children:[o(H,{label:t.canAttach?"Attach file":"Model doesn't support attachments",className:"RootAIChat__composer__attachTooltip",children:o(P,{component:"label",radius:"xl",className:N("RootAIChat__composer__attach",!t.canAttach&&"RootAIChat__composer__attach--disabled"),disabled:!t.canAttach,children:[_?o(J,{size:"xs"}):o(ot,{size:18}),o("input",{ref:l,type:"file",style:{display:"none"},onChange:E})]})}),o("textarea",{ref:g,className:"RootAIChat__composer__textarea",placeholder:t.disabled?"Select a model\u2026":"Ask anything\u2026",value:e,rows:1,autofocus:!0,disabled:t.disabled,onKeyDown:y,onChange:d=>a(d.target.value),onPaste:d=>{let x=d.clipboardData?.items||[];for(let A of x)if(A.kind==="file"){let I=A.getAsFile();I&&t.canAttach&&C(I)}}}),t.isStreaming?o(P,{className:"RootAIChat__composer__button RootAIChat__composer__stopButton",radius:"xl",color:"dark",variant:"filled",onClick:t.onStop,title:"Stop",children:o(U,{size:18})}):o(P,{className:"RootAIChat__composer__button RootAIChat__composer__submitButton",radius:"xl",color:"dark",variant:"filled",disabled:t.disabled||_||!e&&n.length===0,onClick:b,title:"Send",children:o(yt,{size:18})})]}),t.controls]})}var Qt=1e5;function Me(t){let e=t.filter(Zt),a=t.filter(n=>!Zt(n)).map(Ne);return{files:e,text:a.length?`Attached files:
|
|
6
|
-
|
|
7
|
-
${a.join(`
|
|
8
|
-
|
|
9
|
-
`)}`:""}}function Zt(t){return t.mediaType.startsWith("image/")}function Ne(t){let e=`File: ${t.filename} (${t.mediaType})`;if(t.textContent!==void 0){let a=t.textTruncated?`
|
|
10
|
-
|
|
11
|
-
[Content truncated before sending to the model.]`:"";return`${e}
|
|
12
|
-
URL: ${t.url}
|
|
13
|
-
|
|
14
|
-
~~~
|
|
15
|
-
${t.textContent}${a}
|
|
16
|
-
~~~`}return`${e}
|
|
17
|
-
URL: ${t.url}
|
|
18
|
-
|
|
19
|
-
[The file was uploaded, but its binary content was not inlined into this chat message.]`}async function Te(t,e){if(!Pe(t.name,e))return null;let a=await t.text();return a.length<=Qt?{text:a,truncated:!1}:{text:a.slice(0,Qt),truncated:!0}}function Pe(t,e){return e.startsWith("text/")?!0:[".css",".js",".jsx",".json",".md",".mdx",".mjs",".scss",".ts",".tsx",".txt",".yaml",".yml"].some(a=>t.toLowerCase().endsWith(a))}function Ee(t){let e=t.toLowerCase();return e.endsWith(".png")?"image/png":e.endsWith(".webp")?"image/webp":e.endsWith(".jpg")||e.endsWith(".jpeg")?"image/jpeg":e.endsWith(".gif")?"image/gif":e.endsWith(".svg")?"image/svg+xml":e.endsWith(".pdf")?"application/pdf":e.endsWith(".json")?"application/json":e.endsWith(".csv")?"text/csv":e.endsWith(".md")?"text/markdown":e.endsWith(".txt")?"text/plain":"application/octet-stream"}function Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}export{mo as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{e}from"./chunk-WASID5UU.js";import{Ga as o}from"./chunk-WRA24P66.js";function n(r){return o("div",{className:e(r.className,"Surface"),children:r.children})}export{n as a};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{f as k}from"./chunk-5MV6XVGA.js";import{e as b}from"./chunk-WASID5UU.js";import{Ga as a,a as M,c as y,e as z,g as P,j as O}from"./chunk-WRA24P66.js";var L=class{diff(e,o,n={}){let i;typeof n=="function"?(i=n,n={}):"callback"in n&&(i=n.callback);let l=this.castInput(e,n),c=this.castInput(o,n),h=this.removeEmpty(this.tokenize(l,n)),r=this.removeEmpty(this.tokenize(c,n));return this.diffWithOptionsObj(h,r,n,i)}diffWithOptionsObj(e,o,n,i){var l;let c=t=>{if(t=this.postProcess(t,n),i){setTimeout(function(){i(t)},0);return}else return t},h=o.length,r=e.length,s=1,f=h+r;n.maxEditLength!=null&&(f=Math.min(f,n.maxEditLength));let m=(l=n.timeout)!==null&&l!==void 0?l:1/0,g=Date.now()+m,d=[{oldPos:-1,lastComponent:void 0}],u=this.extractCommon(d[0],o,e,0,n);if(d[0].oldPos+1>=r&&u+1>=h)return c(this.buildValues(d[0].lastComponent,o,e));let x=-1/0,p=1/0,_=()=>{for(let t=Math.max(x,-s);t<=Math.min(p,s);t+=2){let C,w=d[t-1],D=d[t+1];w&&(d[t-1]=void 0);let J=!1;if(D){let I=D.oldPos-t;J=D&&0<=I&&I<h}let T=w&&w.oldPos+1<r;if(!J&&!T){d[t]=void 0;continue}if(!T||J&&w.oldPos<D.oldPos?C=this.addToPath(D,!0,!1,0,n):C=this.addToPath(w,!1,!0,1,n),u=this.extractCommon(C,o,e,t,n),C.oldPos+1>=r&&u+1>=h)return c(this.buildValues(C.lastComponent,o,e))||!0;d[t]=C,C.oldPos+1>=r&&(p=Math.min(p,t-1)),u+1>=h&&(x=Math.max(x,t+1))}s++};if(i)(function t(){setTimeout(function(){if(s>f||Date.now()>g)return i(void 0);_()||t()},0)})();else for(;s<=f&&Date.now()<=g;){let t=_();if(t)return t}}addToPath(e,o,n,i,l){let c=e.lastComponent;return c&&!l.oneChangePerToken&&c.added===o&&c.removed===n?{oldPos:e.oldPos+i,lastComponent:{count:c.count+1,added:o,removed:n,previousComponent:c.previousComponent}}:{oldPos:e.oldPos+i,lastComponent:{count:1,added:o,removed:n,previousComponent:c}}}extractCommon(e,o,n,i,l){let c=o.length,h=n.length,r=e.oldPos,s=r-i,f=0;for(;s+1<c&&r+1<h&&this.equals(n[r+1],o[s+1],l);)s++,r++,f++,l.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return f&&!l.oneChangePerToken&&(e.lastComponent={count:f,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=r,s}equals(e,o,n){return n.comparator?n.comparator(e,o):e===o||!!n.ignoreCase&&e.toLowerCase()===o.toLowerCase()}removeEmpty(e){let o=[];for(let n=0;n<e.length;n++)e[n]&&o.push(e[n]);return o}castInput(e,o){return e}tokenize(e,o){return Array.from(e)}join(e){return e.join("")}postProcess(e,o){return e}get useLongestToken(){return!1}buildValues(e,o,n){let i=[],l;for(;e;)i.push(e),l=e.previousComponent,delete e.previousComponent,e=l;i.reverse();let c=i.length,h=0,r=0,s=0;for(;h<c;h++){let f=i[h];if(f.removed)f.value=this.join(n.slice(s,s+f.count)),s+=f.count;else{if(!f.added&&this.useLongestToken){let m=o.slice(r,r+f.count);m=m.map(function(g,d){let u=n[s+d];return u.length>g.length?u:g}),f.value=this.join(m)}else f.value=this.join(o.slice(r,r+f.count));r+=f.count,f.added||(s+=f.count)}}return i}};var N=class extends L{constructor(){super(...arguments),this.tokenize=A}equals(e,o,n){return n.ignoreWhitespace?((!n.newlineIsToken||!e.includes(`
|
|
2
|
-
`))&&(e=e.trim()),(!n.newlineIsToken||!o.includes(`
|
|
3
|
-
`))&&(o=o.trim())):n.ignoreNewlineAtEof&&!n.newlineIsToken&&(e.endsWith(`
|
|
4
|
-
`)&&(e=e.slice(0,-1)),o.endsWith(`
|
|
5
|
-
`)&&(o=o.slice(0,-1))),super.equals(e,o,n)}},j=new N;function E(v,e,o){return j.diff(v,e,o)}function A(v,e){e.stripTrailingCr&&(v=v.replace(/\r\n/g,`
|
|
6
|
-
`));let o=[],n=v.split(/(\n|\r\n)/);n[n.length-1]||n.pop();for(let i=0;i<n.length;i++){let l=n[i];i%2&&!e.newlineIsToken?o[o.length-1]+=l:o.push(l)}return o}O();var R=4;function oe(v){let{oldCode:e,newCode:o,className:n=""}=v,[i,l]=M({}),c=P(()=>{let m=W(e),g=W(o);return m!==void 0&&g!==void 0?{oldCode:k(m),newCode:k(g)}:{oldCode:e,newCode:o}},[e,o]),h=P(()=>E(c.oldCode,c.newCode),[c]);y(()=>{l({})},[c]);let r=z(null);y(()=>{if(r.current){let m=r.current.querySelector(".JsDiff__diffLine--added, .JsDiff__diffLine--removed");m&&m.scrollIntoView({behavior:"smooth",block:"center"})}},[c]);let s=P(()=>{let m=[],g=0;return h.forEach((d,u)=>{let x=d.added?"+":d.removed?"-":" ",p=d.added?"added":d.removed?"removed":"unchanged",_=d.value.split(`
|
|
7
|
-
`);_.forEach((t,C)=>{(t.length>0||C<_.length-1)&&m.push({key:`${u}-${C}`,type:p,lineNumber:++g,sign:x,text:t})})}),m},[h]),f=()=>{let m=new Set;s.forEach((p,_)=>{p.type!=="unchanged"&&m.add(_)});let g=new Set;if(s.forEach((p,_)=>{if(m.has(_)){g.add(_);for(let t=1;t<=R;t++)_-t>=0&&g.add(_-t),_+t<s.length&&g.add(_+t)}}),m.size===0)return s.map(p=>a(S,{line:p},p.key));let d=[],u=0,x=0;for(;u<s.length;)if(g.has(u))d.push(a(S,{line:s[u]},s[u].key)),u++;else{let p=x++,_=u;for(;u<s.length&&!g.has(u);)u++;let t=s.slice(_,u),C=t.length;i[p]?(d.push(a("div",{className:"JsDiff__collapsed",onClick:()=>l(D=>({...D,[p]:!1})),children:[a(V,{}),a("span",{children:["Hide ",C," unchanged line",C!==1?"s":""]})]},`collapse-${p}`)),d.push(...t.map(D=>a(S,{line:D},D.key)))):d.push(a("div",{className:"JsDiff__collapsed",onClick:()=>l(D=>({...D,[p]:!0})),children:[a(q,{}),a("span",{children:[C," unchanged line",C!==1?"s":""," hidden"]})]},`collapse-${p}`))}return d};return a("div",{className:b("JsDiff__container",n),children:a("div",{className:"JsDiff__content",ref:r,children:f()})})}function S(v){let{line:e}=v;return a("div",{className:b("JsDiff__diffLine",e.type==="added"&&"JsDiff__diffLine--added",e.type==="removed"&&"JsDiff__diffLine--removed",e.type==="unchanged"&&"JsDiff__diffLine--unchanged"),children:[a("span",{className:"JsDiff__lineNumber",children:e.lineNumber}),a("span",{className:"JsDiff__lineContent",children:[a("span",{className:"JsDiff__sign",children:e.sign}),a("span",{children:e.text||" "})]})]})}function W(v){try{return JSON.parse(v)}catch{return}}function q(){return a("svg",{className:"JsDiff__collapsed__icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",children:a("path",{d:"M4 6l4 4 4-4"})})}function V(){return a("svg",{className:"JsDiff__collapsed__icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round",children:a("path",{d:"M4 10l4-4 4 4"})})}export{oe as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as _,c as P}from"./chunk-ATTW36EM.js";import{D as u,a as w,b as j,c as n,g as T,n as b,o as R,p as I,q as m,u as h,v as l,x as f}from"./chunk-XOWWPE7X.js";async function F(t,a){if(!t)throw new Error("missing data source id");let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await I(s,{...a,id:t,createdAt:l(),createdBy:window.firebase.user.email}),u("datasource.create",{metadata:{datasourceId:t}})}async function G(){let t=window.__ROOT_CTX.rootConfig.projectId,a=window.firebase.db,o=j(a,"Projects",t,"DataSources"),e=T(o),s=await R(e),r=[];return s.forEach(c=>{r.push(c.data())}),r}async function S(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=await b(e);return s.exists()?s.data():null}async function O(t,a){let o=a?.mode||"draft",e=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,r=n(s,"Projects",e,"DataSources",t,"Data",o),c=await b(r);return c.exists()?c.data():null}async function U(t,a){let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await m(s,a),u("datasource.save",{metadata:{datasourceId:t}})}async function q(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:l(),archivedBy:window.firebase.user.email}),u("datasource.archive",{metadata:{datasourceId:t}})}async function H(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:h(),archivedBy:h()}),u("datasource.unarchive",{metadata:{datasourceId:t}})}async function W(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);if(a.type==="http"&&a.url&&!C(a.url)){let o=await fetch("/cms/api/data.sync",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id:a.id})});if(o.status!==200){let e=await o.text();throw new Error(`sync failed: ${e}`)}}else{let{data:o,headers:e}=await x(a),s=window.__ROOT_CTX.rootConfig.projectId,r=window.firebase.db,c=n(r,"Projects",s,"DataSources",t),d=n(r,"Projects",s,"DataSources",t,"Data","draft"),p={...a,syncedAt:w.now(),syncedBy:window.firebase.user.email},i=f(r);i.set(d,{dataSource:p,data:o,...e?{headers:e}:{}}),i.update(c,{syncedAt:w.now(),syncedBy:window.firebase.user.email}),await i.commit()}console.log(`synced data source: ${t}`),u("datasource.sync",{metadata:{datasourceId:t}})}async function M(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=await O(t,{mode:"draft"}),p={...a,publishedAt:w.now(),publishedBy:window.firebase.user.email},i=f(e);i.set(c,{dataSource:p,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),i.update(r,{dataSource:p}),i.update(s,{publishedAt:w.now(),publishedBy:window.firebase.user.email}),await i.commit(),console.log(`published data ${t}`),u("datasource.publish",{metadata:{datasourceId:t}})}async function k(t){if(!await S(t))throw new Error(`data source not found: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=f(e);d.update(s,{publishedAt:h(),publishedBy:h()}),(await b(r)).exists()&&d.update(r,{"dataSource.publishedAt":h(),"dataSource.publishedBy":h()}),d.delete(c),await d.commit(),console.log(`unpublished data source: ${t}`),u("datasource.unpublish",{metadata:{datasourceId:t}})}async function J(t,a){if(t.length===0)return;let o=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId,s=a?.batch||f(o);for(let r of t){let c=await S(r);if(!c)throw new Error(`data source not found: ${r}`);if(c.archivedAt)throw new Error(`data source is archived: ${r}`);let d=await O(r,{mode:"draft"}),p=n(o,"Projects",e,"DataSources",r),i=n(o,"Projects",e,"DataSources",r,"Data","draft"),y=n(o,"Projects",e,"DataSources",r,"Data","published"),D={...c,publishedAt:l(),publishedBy:window.firebase.user.email};s.set(y,{dataSource:D,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),s.update(i,{dataSource:D}),s.update(p,{publishedAt:l(),publishedBy:window.firebase.user.email}),u("datasource.publish",{metadata:{datasourceId:r}})}(!a?.batch||a?.commitBatch)&&await s.commit()}async function N(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=n(o,"Projects",a,"DataSources",t,"Data","draft"),r=n(o,"Projects",a,"DataSources",t,"Data","published"),c=f(o);c.delete(s),c.delete(r),c.delete(e),await c.commit(),console.log(`deleted data source ${t}`),u("datasource.delete",{metadata:{datasourceId:t}})}async function x(t){if(t.type==="http")return{data:await B(t)};if(t.type==="gsheet")return await v(t);throw new Error(`unsupported data source: ${t.type}`)}async function v(t){let a=P(t.url);if(!a?.spreadsheetId)throw new Error(`failed to parse google sheet url: ${t.url}`);let e=await new _(a.spreadsheetId).getSheet(a.gid??0);if(!e)throw new Error(`could not find sheet: ${t.url}`);let s=t.dataFormat||"map",[r,c]=await e.getValues();return s==="array"?{data:[r,c],headers:r}:{data:c.map(p=>{let i={};return p.forEach((y,D)=>{let g=r[D];g&&(i[g]=String(y||""))}),i}),headers:r}}async function B(t){if(!C(t.url))throw new Error(`unsupported url: ${t.url}`);let a=await fetch(t.url,{method:t.httpOptions?.method||"GET",headers:t.httpOptions?.headers||[],body:t.httpOptions?.body||void 0});if(a.status!==200){let e=await a.text();throw new Error(`req failed: ${e}`)}return String(a.headers.get("content-type")).includes("application/json")?await a.json():a.text()}function C(t){return t&&t.startsWith("/")}export{F as a,G as b,S as c,O as d,U as e,q as f,H as g,W as h,M as i,k as j,J as k,N as l};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as z}from"./chunk-QWB6MAPJ.js";import{c as C}from"./chunk-VPZHG7JL.js";import{f as h}from"./chunk-5MV6XVGA.js";import{a as x}from"./chunk-NCZD5IWS.js";import{a as P}from"./chunk-AAHM6RYJ.js";import{U as b,Y as A,Z as I}from"./chunk-ISUGBMXC.js";import{e as D}from"./chunk-WASID5UU.js";import{Ga as e,Kc as N,U as y,V as u,a as t,bd as k,c as v,da as S,e as w,j as V}from"./chunk-WRA24P66.js";import{d as g}from"./chunk-KUCVLANF.js";V();V();function R(o){let r=o.docId,[i,d]=t("idle"),[c,f]=t(""),[s,l]=t(""),m=w(!1);async function p(){d("loading");try{let n=await I(r,{beforeVersion:o.beforeVersion,afterVersion:o.afterVersion});f(n),d("success")}catch(n){console.error(n),l(n instanceof Error?n.message:"Unknown error"),d("error")}}function _(){m.current||(m.current=!0,p())}let a;return i==="idle"||i==="loading"?a=e("div",{className:"AiSummary__loading",children:e(u,{size:"md",color:"gray"})}):i==="error"?a=e(x,{className:"AiSummary__content",size:"body-sm",color:"gray",children:["Failed to load AI summary.",s&&e(g,{children:[e("br",{}),s]})]}):c?a=e(C,{className:"AiSummary__content",code:c}):a=e(x,{className:"AiSummary__content",size:"body-sm",color:"gray",children:"No AI summary available for this draft yet."}),e("div",{className:D(o.className,"AiSummary"),children:e(y,{iconPosition:"right",onChange:()=>_(),disableIconRotation:!0,children:e(y.Item,{label:"Summarize changes",icon:e(N,{stroke:"1.5"}),iconPosition:"left",children:a})})})}function me(o){let r=o.left,i=o.right,[d,c]=t(!1),[f,s]=t(null),[l,m]=t(null),p=P()&&r.docId===i.docId&&o.showAiSummary!==!1,_=h(E(f?.fields||{})),a=h(E(l?.fields||{})),n=!d&&f&&l&&_===a,M=`/cms/compare?left=${F(r)}&right=${F(i)}`;async function $(){c(!0);let[j,T]=await Promise.all([b(r.docId,r.versionId),b(i.docId,i.versionId)]);s(j),m(T),c(!1)}return v(()=>{$()},[]),d?e("div",{className:"DocDiffViewer DocDiffViewer--loading",children:e(u,{size:"md",color:"gray"})}):e(g,{children:[p&&e(R,{className:"DocDiffViewer__aiSummary",docId:r.docId,beforeVersion:String(r.versionId),afterVersion:String(i.versionId)}),e("div",{className:D(o.className,"DocDiffViewer"),children:[o.showExpandButton&&e("div",{className:"DocDiffViewer__expand",children:e(S,{component:"a",variant:"default",size:"xs",compact:!0,href:M,target:"_blank",children:"Open in new tab"})}),e("div",{className:"DocDiffViewer__header",children:[e("div",{className:"DocDiffViewer__header__label",children:[e("div",{className:"DocDiffViewer__header__label__title",children:[o.left.docId,"@",o.left.versionId]}),e("div",{className:"DocDiffViewer__header__label__meta",children:B(f)})]}),e("div",{className:"DocDiffViewer__header__label",children:[e("div",{className:"DocDiffViewer__header__label__title",children:[o.right.docId,"@",o.right.versionId]}),e("div",{className:"DocDiffViewer__header__label__meta",children:B(l)})]})]}),e("div",{className:"DocDiffViewer__diff",children:n?e("div",{className:"DocDiffViewer__identical",children:[e(k,{size:20}),e("span",{children:"No changes. Both versions are identical."})]}):e(z,{oldCode:_,newCode:a})})]})]})}function B(o){if(!o?.sys?.modifiedAt)return"never";let r=o.sys.modifiedAt.toDate();return`${new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)} by ${o.sys.modifiedBy}`}function E(o){return A(o,{removeArrayKey:!0})}function F(o){return encodeURIComponent(`${o.docId}@${o.versionId}`).replaceAll("%2F","/").replaceAll("%40","@")}export{R as a,me as b};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as F}from"./chunk-FVWSVOOY.js";import{b as _}from"./chunk-5MV6XVGA.js";import{a as U}from"./chunk-PLYSJ7W5.js";import{b as L}from"./chunk-2PTLQRTU.js";import{N as S,b as I}from"./chunk-ISUGBMXC.js";import{B as v,z as P}from"./chunk-XOWWPE7X.js";import{e as b}from"./chunk-WASID5UU.js";import{Fa as p,Ga as t,V as B,a as g,ba as c,c as h,e as A,i as T,j as R,la as N}from"./chunk-WRA24P66.js";import{d as y,j as k,k as O}from"./chunk-KUCVLANF.js";O();R();var $=k(null);function Z(e){let[i,n]=g([]),[o,r]=g(!1),a=A("idle");function u(){a.current==="idle"&&(a.current="fetching",r(!0),F().then(l=>{let d=l.filter(f=>!f.publishedAt&&!f.archivedAt);n(d)}).catch(l=>{console.error("Failed to fetch pending releases:",l)}).finally(()=>{a.current="done",r(!1)}))}function s(l){return i.filter(d=>d.docIds?.includes(l))}return t($.Provider,{value:{releases:i,getReleasesForDoc:s,loading:o,fetchReleases:u},children:e.children})}function z(){let e=T($);if(!e)throw new Error("usePendingReleases must be used within a <PendingReleasesProvider>");let{fetchReleases:i,...n}=e;return h(()=>{i()},[]),n}function m(e){let{message:i,detail:n,user:o}=e;return t(p,{label:t("div",{className:"UserActionTooltip",children:[o&&t(U,{email:o,size:20,withTooltip:!1}),t("div",{className:"UserActionTooltip__text",children:[t("span",{children:i}),n&&t("span",{className:"UserActionTooltip__detail",children:n}),o&&t("span",{children:["by ",o]})]})]}),position:e.position,transition:e.transition??"pop",withArrow:e.withArrow??!0,children:e.children})}function M(e){let i={transition:"pop"},n=e.doc,o=n.sys;return t("div",{className:"DocStatusBadges",children:[(!o.publishedAt||!o.modifiedAt||o.modifiedAt>o.publishedAt)&&t(m,{position:e.tooltipPosition,message:`Modified ${C(o.modifiedAt)}`,user:o.modifiedBy,children:t(c,{size:"xs",variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:"Draft"})}),!!o.publishedAt&&t(m,{position:e.tooltipPosition,message:`Published ${C(o.publishedAt)}`,user:o.publishedBy,children:t(c,{size:"xs",variant:"gradient",gradient:{from:"teal",to:"lime",deg:105},children:"Published"})}),!!o.scheduledAt&&t(m,{position:e.tooltipPosition,message:`Scheduled ${v(o.scheduledAt)}`,user:o.scheduledBy,children:t(c,{size:"xs",variant:"gradient",gradient:{from:"grape",to:"pink",deg:35},children:"Scheduled"})}),!e.hideReleases&&t(X,{docId:e.docId||n.id,tooltipProps:i}),S(n)&&t(m,{position:e.tooltipPosition,message:K(n),detail:n.sys?.publishingLocked?.reason,user:n.sys?.publishingLocked?.lockedBy,children:t(c,{size:"xs",variant:"gradient",gradient:{from:"orange",to:"red"},className:e.onPublishingLockClick?"DocStatusBadges__badge--clickable":void 0,style:e.onPublishingLockClick?{cursor:"pointer"}:void 0,role:e.onPublishingLockClick?"button":void 0,tabIndex:e.onPublishingLockClick?0:void 0,onClick:e.onPublishingLockClick,onKeyDown:e.onPublishingLockClick?r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),e.onPublishingLockClick())}:void 0,children:"Locked"})}),!!o.archivedAt&&t(m,{position:e.tooltipPosition,message:`Archived ${C(o.archivedAt)}`,user:o.archivedBy,children:t(c,{size:"xs",variant:"gradient",gradient:{from:"gray",to:"dark"},children:"Archived"})})]})}function K(e){let i=e.sys?.publishingLocked;return i?.until?`Locked until ${v(i.until)}`:"Locked"}function ve(e){let i=e.sys?.publishingLocked;return i?i.until?`Locked until ${v(i.until)} by ${i.lockedBy}: "${i.reason}"`:`Locked by ${i.lockedBy}: "${i.reason}"`:""}function X(e){let{getReleasesForDoc:i}=z(),n=i(e.docId);return n.length===0?null:t(y,{children:n.map(o=>t(p,{...e.tooltipProps,label:`In release: ${o.id}`,children:t(c,{component:"a",href:`/cms/releases/${o.id}`,size:"xs",variant:"gradient",gradient:{from:"violet",to:"grape"},style:{cursor:"pointer"},children:o.id})},o.id))})}function C(e){return e?P(e.toMillis()):P(new Date().getTime())}function E(e){let{file:i,width:n,height:o,withPlaceholder:r,className:a,alt:u}=e,s=typeof i=="string"?i:i?.src;return q(i)?t(G,{className:a,src:s,width:n,height:o}):t(N,{className:a,src:s,width:n,height:o,withPlaceholder:r,alt:u})}function q(e){if(!e)return!1;if(typeof e=="string")return/\.mp4($|\?)/i.test(e);if(typeof e.mimeType=="string")return e.mimeType.toLowerCase()==="video/mp4";let i=e.src;return typeof i!="string"?!1:/\.mp4($|\?)/i.test(i)}function G(e){return t("video",{className:e.className,src:e.src,width:e.width,height:e.height,muted:!0,playsInline:!0,preload:"metadata",style:{width:`${e.width}px`,height:`${e.height}px`,backgroundColor:"#f1f3f5",objectFit:"cover",display:"block"}})}R();function Se(e){let i=e.docId,[n,o]=g(e.doc),[r,a]=g(!e.doc);async function u(){a(!0),await L(async()=>{let V=await I(i);o(V)}),a(!1)}if(h(()=>{u()},[i]),r)return t("div",{className:b(e.className,"DocPreviewCard","DocPreviewCard--loading",e.variant&&`DocPreviewCard--${e.variant}`),children:t(B,{color:"gray",size:"sm"})});if(!n)return;let[s]=i.split("/"),l=n.fields||{},d=window.__ROOT_CTX.collections[s];if(!d)return console.error(`could not find collection: ${s}`),t("div",{className:"DocPreviewCard",children:["Collection ",t("b",{children:s})," not found."]});let f=_(l,d.preview?.title||"meta.title"),x=_(l,d.preview?.image||"meta.image")||d.preview?.defaultImage,D="div",w={};return e.clickable&&(D="a",w.href=`/cms/content/${e.docId}`,w.target="_blank"),t(D,{className:b(e.className,"DocPreviewCard",e.variant&&`DocPreviewCard--${e.variant}`),...w,children:[t("div",{className:"DocPreviewCard__image",children:t(E,{file:x,width:80,height:60,withPlaceholder:!x?.src})}),t("div",{className:"DocPreviewCard__content",children:[t("div",{className:"DocPreviewCard__content__header",children:t("div",{className:"DocPreviewCard__content__header__docId",children:n.id})}),t("div",{className:"DocPreviewCard__content__title",children:f||"[UNTITLED]"}),e.statusBadges&&n&&t("div",{className:"DocPreviewCard__content__badges",children:t(M,{doc:n,hideReleases:e.hideReleases})})]})]})}export{Z as a,z as b,m as c,M as d,ve as e,E as f,Se as g};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as le}from"./chunk-HV3JJ5UT.js";import{a as oe}from"./chunk-FVWSVOOY.js";import{a as ee,b as A,c as T}from"./chunk-JDW4UORS.js";import{a as ie}from"./chunk-YDO2EDVY.js";import{a as M}from"./chunk-5MV6XVGA.js";import{b as te}from"./chunk-2PTLQRTU.js";import{a as U}from"./chunk-PIJ3E47R.js";import{a as j}from"./chunk-NCZD5IWS.js";import{P as re,c as ne}from"./chunk-ISUGBMXC.js";import{b as K,f as R,g as C,i as v,o as Y}from"./chunk-XOWWPE7X.js";import{d as Z,e as se}from"./chunk-WASID5UU.js";import{A as G,Ga as g,a as S,c as y,da as $,e as _,g as B,h as I,i as W,j as O,ra as Q,ua as q,za as J}from"./chunk-WRA24P66.js";import{j as X,k as Se}from"./chunk-KUCVLANF.js";function F(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",r=Ee(e);return`${n}${r}`}function Ee(e){let o=window.__ROOT_CTX.collections,{collectionId:t,slug:n,locale:r}=e,i=o[t];if(!i)throw new Error(`collection not found: ${t}`);if(!i.url)return"";let l=window.__ROOT_CTX.rootConfig,m=l.base||"/",u="/[base]/[path]";r&&(u=l.i18n.urlFormat||"/[locale]/[base]/[path]");let f="",a=i?.url;if(a)if(n){let c=a.replace(/\[.*slug\]/,n).replaceAll("--","/").replace(/\/+/g,"/");c==="/index"&&(c="/"),f=c}else f=a;return ce(u,{base:m,path:f,locale:r||"",slug:n})}function be(e){let o=window.__ROOT_CTX.collections,{collectionId:t,slug:n,locale:r}=e,i=o[t];if(!i)throw new Error(`collection not found: ${t}`);let l=window.__ROOT_CTX.rootConfig,m=l.base||"/",u="/[base]/[path]";r&&(u=l.i18n.urlFormat||"/[locale]/[base]/[path]");let f="",a=i?.previewUrl||i?.url;if(a)if(n){let c=a.replace(/\[.*slug\]/,n).replaceAll("--","/").replace(/\/+/g,"/");c==="/index"&&(c="/"),f=c}else f=a;return ce(u,{base:m,path:f,locale:r||"",slug:n})}function ce(e,o){let t=e.replaceAll(/\[\[?(\.\.\.)?([\w\-_]*)\]?\]/g,(n,r,i)=>o[i]??n);return Ce(t,{trailingSlash:window.__ROOT_CTX.rootConfig.server.trailingSlash})}function Ce(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}O();function Ae(e,o){let[t,n]=S([]),[r,i]=S(!0),m=le().db,u=window.__ROOT_CTX.rootConfig.projectId||"default",f=o.includeArchived??!1,a=async()=>{i(!0);let c=K(m,"Projects",u,"Collections",e,"Drafts"),s=c,d=o.orderBy;if(d==="modifiedAt")s=C(c,v("sys.modifiedAt","desc"));else if(d==="modifiedAtAsc")s=C(c,v("sys.modifiedAt"));else if(d==="newest")s=C(c,v("sys.createdAt","desc"));else if(d==="oldest")s=C(c,v("sys.createdAt"));else if(d==="slug")s=C(c,v(R()));else if(d==="slugDesc")s=C(c,v(R(),"desc"));else if(d==="title"||d==="titleDesc"){let p=d==="titleDesc"?"desc":"asc",h=ve(e);s=h?C(c,v(h,p)):C(c,v(R(),p))}else{let h=window.__ROOT_CTX.collections[e]?.sortOptions?.find(w=>w.id===d);h&&(s=h.direction==="desc"?C(c,v(h.field,"desc")):C(c,v(h.field)))}await te(async()=>{let p=await Y(s),h=[];p.docs.forEach(w=>{let P=w.data(),E=w.id,b=`${e}/${E}`,x={...P,id:b,slug:E};ne(b,x),!(!f&&x?.sys?.archivedAt)&&h.push(x)}),n(h)}),i(!1)};return y(()=>{i(!0),a()},[e,o.orderBy,f]),[r,a,t]}function ve(e){let t=window.__ROOT_CTX.collections[e]?.preview?.title??"meta.title";return Array.isArray(t)&&(t=t[0]),typeof t!="string"||!t||t.includes("{")?"":`fields.${t}`}Se();O();var D={CONNECTED:"connected",SCHEMA_CHANGED:"schemaChanged"};function ae(e){let t=new URLSearchParams(window.location.search).get("e");return t?t.split(",").includes(e):!1}var we="/cms/api/sse.connect",L=ae("EnableVerboseLogging"),ue=window.location.hostname==="localhost",z=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(r=>r(t,n)),this.map.get("*")?.forEach(r=>r({type:o,data:t},n))}},fe=X(null);function He(e){let t=_(new z).current,n=_(null),r=_(!1),i=_({attempt:0,timer:0}),l=_(""),m=()=>{n.current&&(n.current.close(),n.current=null)},u=I(()=>{L&&console.log("[sse] connecting..."),m();let a=new EventSource(we);n.current=a,a.addEventListener(D.CONNECTED,s=>{if(L&&console.log("[sse] connected"),r.current=!1,i.current.attempt=0,ue){let p=de(s.data)?.serverVersion||"";l.current?l.current!==p&&(console.log(`server version changed: ${l.current} -> ${p}`),console.log("reloading..."),window.location.reload()):l.current=p}});let c=s=>{if(!s||!s.type)return;let d=de(s.data);L&&console.log("[sse] event:",s.type,d),t.emit(s.type,d,s)};Object.values(D).forEach(s=>{a.addEventListener(s,c)}),a.addEventListener("error",()=>{L&&console.log("[sse] disconnected"),a.readyState===EventSource.CLOSED&&!r.current&&(r.current=!0,(()=>{let d=++i.current.attempt,p=Math.min(3e4,Math.pow(2,d)*500),h=Math.random()*.3*p,w=p+h;window.clearTimeout(i.current.timer),i.current.timer=window.setTimeout(()=>{r.current=!1,u()},w)})())})},[t]);y(()=>{if(!ue)return;u();let a=()=>{document.visibilityState==="visible"&&n.current?.readyState!==EventSource.OPEN&&u()};return document.addEventListener("visibilitychange",a),()=>{document.removeEventListener("visibilitychange",a),window.clearTimeout(i.current.timer),m()}},[u]);let f=B(()=>({emitter:t}),[t]);return g(fe.Provider,{value:f,children:e.children})}function de(e){try{return JSON.parse(e)}catch{return e}}function ge(e,o){let t=W(fe);if(!t)throw new Error("useSSE() must be used within an <SSEProvider>");let n=_(o);y(()=>{n.current=o},[o]),y(()=>t.emitter.on(e,(r,i)=>n.current(r,i)),[t,e])}O();O();function me(e){let[o,t]=S(!0),[n,r]=S(null),i=I(async()=>{try{let l=await ie(e);r(l)}catch(l){console.error(l),U({title:`Failed to load collection: ${e}`,message:String(l),color:"red",autoClose:!1})}t(!1)},[e]);return y(()=>{i()},[e]),ge(D.SCHEMA_CHANGED,async l=>{await i();let m=l.file?`Applied updates from changes to ${l.file}.`:"Applied updates from changes to a .schema.ts file.";U({title:"Updated schema!",message:m})}),{loading:o,schema:n}}function H(e){let o={_array:[]};return e.forEach(t=>{let n=_e();o._array.push(n),o[n]=t}),o}function _e(){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(r=>{if(!r.id)return;let i=n[r.id];if(i!=null){if(r.type==="array"&&Array.isArray(i)){let l=i.map(m=>ye(r.of,m,t));n[r.id]=H(l)}else if(r.type==="object"&&M(i))n[r.id]=k(r,i,t);else if(r.type==="oneof"&&M(i)&&typeof i._type=="string"&&t){let l=t[i._type];l&&(n[r.id]=k(l,i,t))}}}),n}function ye(e,o,t){if(!M(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}O();function pe(e){let[o,t]=S(e.collectionId||""),n=_(null),[r,i]=S(e.initialSlug||""),l=window.__ROOT_CTX.collections[o],m=[];e.collectionId&&e.collectionDisabled?m.push({value:e.collectionId,label:e.collectionId}):Object.keys(window.__ROOT_CTX.collections).forEach(s=>{m.push({value:s,label:s})});let u="",f="";if(l?.url){if(r){let s=T(r),d=l?.slugRegex;ee(s,d)?u=F({collectionId:o,slug:s}):f=A(s,d)}else u=F({collectionId:o,slug:"[slug]"});u.endsWith("/index")&&(u=u.replace(/\/index$/,"/"))}function a(s){t(s),e.onChange&&e.onChange({collectionId:s,slug:r})}function c(s){i(s),e.onChange&&e.onChange({collectionId:o,slug:s})}return g("div",{className:se(e.className,"SlugInput"),children:[g("div",{className:"SlugInput__inputs",children:[g(J,{className:"SlugInput__collection",placeholder:"Collection",size:"xs",data:m,onChange:s=>a(s),value:o,disabled:!!e.collectionDisabled}),g("div",{className:"SlugInput__divider",children:"/"}),g(q,{className:"SlugInput__slug",name:"slug",ref:n,value:r,onChange:s=>{c(s.currentTarget.value)},placeholder:"slug",autoComplete:"off",size:"xs"})]}),u&&g(j,{className:"SlugInput__urlHelp",size:"body-sm",children:u}),f&&g(j,{className:"SlugInput__slugError",size:"body-sm",children:f})]})}function xt(e){let{route:o}=Z(),t=G(),n=e.collection,r=window.__ROOT_CTX.collections[n];if(!r)throw new Error(`collection not found: ${n}`);let[i]=S(()=>r.autoSlug?oe(r.autoSlug):""),[l,m]=S(i),[u,f]=S(!1),[a,c]=S(()=>h(i)),[s,d]=S(""),p=me(n);function h(E){let b=T(E);return b?A(b,r.slugRegex):""}function w(){e.onClose&&e.onClose()}async function P(E){if(E.preventDefault(),f(!0),c(""),h(l)){f(!1);return}let x=T(l),he=`${n}/${x}`;try{let N={};!p.loading&&p.schema&&(N=await V(p.schema)),await re(he,{fields:N})}catch(N){d(String(N)),f(!1);return}f(!1),e.skipNavigation?w():o(`/cms/content/${e.collection}/${x}`)}return g(Q,{className:"NewDocModal",opened:e.opened||!1,onClose:()=>w(),title:"New",size:"500px",overlayColor:t.colorScheme==="dark"?t.colors.dark[9]:t.colors.gray[2],children:[g("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."}),g("form",{onSubmit:E=>P(E),children:[g(pe,{className:"NewDocModal__slug",collectionId:n,initialSlug:i,onChange:E=>{m(E.slug),c(h(E.slug)),d("")}}),s&&g("div",{className:"NewDocModal__slugError",children:s}),g("div",{className:"NewDocModal__buttons",children:[g($,{variant:"outline",onClick:()=>w(),type:"button",size:"xs",color:"dark",children:"Cancel"}),g($,{variant:"filled",type:"submit",size:"xs",color:"dark",loading:p.loading||u,disabled:!!a||!!s,children:"Submit"})]})]})]})}export{F as a,Ee as b,be as c,pe as d,Ae as e,He as f,me as g,V as h,k as i,xt as j};
|