@blinkk/root-cms 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/{chunk-7Z5IRD2G.js → chunk-RLZFZT42.js} +2 -2
  3. package/dist/plugin.js +5 -5
  4. package/dist/ui/{AIPage-2LUC2PWC.js → AIPage-YI3RFK5F.js} +1 -1
  5. package/dist/ui/{AssetsPage-PODV4QAB.js → AssetsPage-4JNAOFYF.js} +1 -1
  6. package/dist/ui/{CollectionPage-4DMKW5YB.js → CollectionPage-JWHH5G55.js} +1 -1
  7. package/dist/ui/{ComparePage-JMJE5A5Y.js → ComparePage-YZE3EMU4.js} +1 -1
  8. package/dist/ui/{DataPage-MVLZT2BU.js → DataPage-VRCQSZZG.js} +1 -1
  9. package/dist/ui/{DataSourcePage-4RPBXRI2.js → DataSourcePage-WMSPBZ3W.js} +1 -1
  10. package/dist/ui/{DocTranslationsPage-XJSPKGVX.js → DocTranslationsPage-RY2LOZBX.js} +1 -1
  11. package/dist/ui/{DocumentPage-R2PVNG24.js → DocumentPage-EEGTJMIW.js} +1 -1
  12. package/dist/ui/{EditDataSourcePage-3SHAARNL.js → EditDataSourcePage-LLCX6K4J.js} +1 -1
  13. package/dist/ui/{EditReleasePage-G5VW2OGW.js → EditReleasePage-WQYXXMZQ.js} +1 -1
  14. package/dist/ui/{LogsPage-K6KYEG2P.js → LogsPage-IP2DKEYR.js} +1 -1
  15. package/dist/ui/{NewDataSourcePage-O2VQEOJG.js → NewDataSourcePage-RDYJC4DH.js} +1 -1
  16. package/dist/ui/{NewReleasePage-RSVS32RZ.js → NewReleasePage-DGMFU2JN.js} +1 -1
  17. package/dist/ui/{NotFoundPage-ZYD5ILG6.js → NotFoundPage-WDZ2K7EF.js} +1 -1
  18. package/dist/ui/{ProjectPage-X3YQBWL4.js → ProjectPage-HYJOQUWR.js} +1 -1
  19. package/dist/ui/{ReleasePage-FJHHXNNB.js → ReleasePage-2KSF23TK.js} +1 -1
  20. package/dist/ui/{ReleasesPage-VGWIBNEZ.js → ReleasesPage-NZIBBXU4.js} +1 -1
  21. package/dist/ui/{SettingsPage-C4RXOQ6T.js → SettingsPage-36XFWV62.js} +1 -1
  22. package/dist/ui/{SidebarToolsPage-ZBOKPEMP.js → SidebarToolsPage-5C6YBWJ7.js} +1 -1
  23. package/dist/ui/{TaskPage-BQ4OX5WN.js → TaskPage-SPIFPGPP.js} +1 -1
  24. package/dist/ui/{TasksPage-3IGQYVYS.js → TasksPage-ZOXRPBQV.js} +1 -1
  25. package/dist/ui/{TranslationsArbPage-GGHCWPQL.js → TranslationsArbPage-UHANA7JD.js} +1 -1
  26. package/dist/ui/{TranslationsEditPage-E2BCMKYV.js → TranslationsEditPage-PQY6W5YG.js} +1 -1
  27. package/dist/ui/{TranslationsPage-MC4O4ZNI.js → TranslationsPage-V2PQFCN5.js} +1 -1
  28. package/dist/ui/{chunk-UEON4JAT.js → chunk-FBJURT7Z.js} +1 -1
  29. package/dist/ui/{chunk-B6BLDN24.js → chunk-JT5L6GPZ.js} +57 -57
  30. package/dist/ui/chunk-P3NETZZP.js +1 -0
  31. package/dist/ui/chunk-TJBVMFNQ.js +1 -0
  32. package/dist/ui/ui.css +1 -1
  33. package/dist/ui/ui.js +1 -1
  34. package/package.json +3 -3
  35. package/dist/ui/chunk-6IFGKSIE.js +0 -1
  36. package/dist/ui/chunk-IU36W2TB.js +0 -1
  37. /package/dist/ui/{chunk-B6BLDN24.js.LEGAL.txt → chunk-JT5L6GPZ.js.LEGAL.txt} +0 -0
@@ -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};