@blinkk/root-cms 3.0.4 → 3.0.6

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 (106) hide show
  1. package/dist/app.js +4 -2
  2. package/dist/{chunk-RLZFZT42.js → chunk-7L5OI5ES.js} +9 -9
  3. package/dist/core/plugin.d.ts +17 -0
  4. package/dist/core/schema.d.ts +20 -0
  5. package/dist/plugin.js +12 -1
  6. package/dist/shared/auto-slug-words.d.ts +7 -0
  7. package/dist/shared/auto-slug.d.ts +14 -0
  8. package/dist/ui/AIPage-JPZ4QUB4.js +1 -0
  9. package/dist/ui/{AssetsPage-4JNAOFYF.js → AssetsPage-GDJMKS3M.js} +1 -1
  10. package/dist/ui/{CollectionPage-JWHH5G55.js → CollectionPage-5DVXJEET.js} +1 -1
  11. package/dist/ui/ComparePage-LIXA6G66.js +1 -0
  12. package/dist/ui/{DataPage-VRCQSZZG.js → DataPage-AP4Z5JPS.js} +1 -1
  13. package/dist/ui/{DataSourcePage-WMSPBZ3W.js → DataSourcePage-WO3ZKMFI.js} +1 -1
  14. package/dist/ui/DocTranslationsPage-QKYFIVHP.js +1 -0
  15. package/dist/ui/DocumentPage-ON43I5KM.js +1 -0
  16. package/dist/ui/{EditDataSourcePage-LLCX6K4J.js → EditDataSourcePage-XVMEV2LJ.js} +1 -1
  17. package/dist/ui/{EditReleasePage-WQYXXMZQ.js → EditReleasePage-A2NB5TFG.js} +1 -1
  18. package/dist/ui/{ImageEditorDialog-4H665KK2.js → ImageEditorDialog-QEULJAT2.js} +2 -2
  19. package/dist/ui/LogsPage-4LZJX3O4.js +1 -0
  20. package/dist/ui/{NewDataSourcePage-RDYJC4DH.js → NewDataSourcePage-4YWX7IOG.js} +1 -1
  21. package/dist/ui/NewReleasePage-HWLVTEXX.js +1 -0
  22. package/dist/ui/{NotFoundPage-WDZ2K7EF.js → NotFoundPage-72AXQAYX.js} +1 -1
  23. package/dist/ui/{ProjectPage-HYJOQUWR.js → ProjectPage-L4GYDIA5.js} +1 -1
  24. package/dist/ui/ReleasePage-43BSWL5B.js +1 -0
  25. package/dist/ui/{ReleasesPage-NZIBBXU4.js → ReleasesPage-CJXAZBP6.js} +1 -1
  26. package/dist/ui/SettingsPage-SYXAMKSF.js +1 -0
  27. package/dist/ui/{SidebarToolsPage-5C6YBWJ7.js → SidebarToolsPage-OFF5BOXP.js} +1 -1
  28. package/dist/ui/TaskPage-HBDLHFI5.js +1 -0
  29. package/dist/ui/TasksPage-OLCDTQNB.js +1 -0
  30. package/dist/ui/{TranslationsArbPage-UHANA7JD.js → TranslationsArbPage-E3NCMAMS.js} +1 -1
  31. package/dist/ui/{TranslationsEditPage-PQY6W5YG.js → TranslationsEditPage-IWOI7Y5G.js} +1 -1
  32. package/dist/ui/{TranslationsPage-V2PQFCN5.js → TranslationsPage-OBN6CQZZ.js} +31 -31
  33. package/dist/ui/{ai-tools-5E5ELLZX.js → ai-tools-4DWMFQS6.js} +1 -1
  34. package/dist/ui/{chunk-KYDOSLTO.js → chunk-2225WAJ2.js} +1 -1
  35. package/dist/ui/chunk-32LRQ5MJ.js +1 -0
  36. package/dist/ui/{chunk-HKINZLMW.js → chunk-344GZOGG.js} +45 -45
  37. package/dist/ui/{chunk-FBJURT7Z.js → chunk-3HVDIPSS.js} +1 -1
  38. package/dist/ui/{chunk-BZIRGB4W.js → chunk-3IDOZ4MG.js} +1 -1
  39. package/dist/ui/{chunk-HHMG665Z.js → chunk-3XYCOR6Z.js} +1 -1
  40. package/dist/ui/chunk-4CUWZQXT.js +7 -0
  41. package/dist/ui/{chunk-3IYZCUPI.js → chunk-4IXGYXA2.js} +1 -1
  42. package/dist/ui/{chunk-PHBMVORG.js → chunk-6E7PGMZX.js} +1 -1
  43. package/dist/ui/{chunk-VMT7JFAM.js → chunk-6GPTGBA7.js} +1 -1
  44. package/dist/ui/{chunk-767BAQ53.js → chunk-6MOPIV5T.js} +1 -1
  45. package/dist/ui/{chunk-E2RCCK2T.js → chunk-AOCBDKLV.js} +1 -1
  46. package/dist/ui/chunk-AXETBZ6T.js +1 -0
  47. package/dist/ui/{chunk-54DVDYU6.js → chunk-BEDUTYQP.js} +1 -1
  48. package/dist/ui/{chunk-62UWGWON.js → chunk-CVGYBXVH.js} +1 -1
  49. package/dist/ui/{chunk-L4RHGQUG.js → chunk-D37DCENS.js} +1 -1
  50. package/dist/ui/{chunk-4W73RW5I.js → chunk-DXKEDMEI.js} +1 -1
  51. package/dist/ui/{chunk-C5NH23G4.js → chunk-EMYXSVTD.js} +1 -1
  52. package/dist/ui/{chunk-PWKJDYE2.js → chunk-GDSSFO5R.js} +1 -1
  53. package/dist/ui/{chunk-KFAZBEPV.js → chunk-HYARD7BK.js} +1 -1
  54. package/dist/ui/chunk-IDYKCAAL.js +1 -0
  55. package/dist/ui/chunk-IKED2IGU.js +1 -0
  56. package/dist/ui/{chunk-KKEWCXVV.js → chunk-J3EGGI57.js} +1 -1
  57. package/dist/ui/{chunk-HRGYNHZ3.js → chunk-KPJ53X55.js} +1 -1
  58. package/dist/ui/{chunk-W3BJ2EZX.js → chunk-KYKFNAX4.js} +1 -1
  59. package/dist/ui/{chunk-TJBVMFNQ.js → chunk-MZP6RIG2.js} +1 -1
  60. package/dist/ui/chunk-N4DFAIC5.js +7 -0
  61. package/dist/ui/{chunk-HLMBCVRX.js → chunk-N5Y5OWTV.js} +1 -1
  62. package/dist/ui/chunk-NMBXHKIJ.js +81 -0
  63. package/dist/ui/chunk-NQ5ARARP.js +1 -0
  64. package/dist/ui/{chunk-X2WHBGTP.js → chunk-NQB37NMX.js} +1 -1
  65. package/dist/ui/chunk-OVRTVMO5.js +1 -0
  66. package/dist/ui/{chunk-JT5L6GPZ.js → chunk-RI2JWWU3.js} +53 -53
  67. package/dist/ui/{chunk-AL3TN2KI.js → chunk-RPOP6MVJ.js} +1 -1
  68. package/dist/ui/{chunk-JHBAMPGB.js → chunk-RQKL4KXY.js} +1 -1
  69. package/dist/ui/{chunk-P3NETZZP.js → chunk-SEUH7LN2.js} +1 -1
  70. package/dist/ui/{chunk-V7S4IAGB.js → chunk-T47V6AGW.js} +1 -1
  71. package/dist/ui/{chunk-ONTGW2VA.js → chunk-TDKVKTW4.js} +1 -1
  72. package/dist/ui/chunk-TZEZEMRQ.js +1 -0
  73. package/dist/ui/{chunk-RSVO46S3.js → chunk-UA7UCTX5.js} +1 -1
  74. package/dist/ui/chunk-UFQSZ6J2.js +3 -0
  75. package/dist/ui/{chunk-DEGMKEHP.js → chunk-UHWNLNP4.js} +1 -1
  76. package/dist/ui/{chunk-CGCKJFL4.js → chunk-V7RAXP2W.js} +1 -1
  77. package/dist/ui/{chunk-JYFLU7DM.js → chunk-WKOX3VFN.js} +1 -1
  78. package/dist/ui/{chunk-SQRKKWRG.js → chunk-XYBHH5L4.js} +1 -1
  79. package/dist/ui/ui.css +1 -1
  80. package/dist/ui/ui.js +1 -1
  81. package/package.json +10 -10
  82. package/dist/ui/AIPage-YI3RFK5F.js +0 -1
  83. package/dist/ui/ComparePage-YZE3EMU4.js +0 -1
  84. package/dist/ui/DocTranslationsPage-RY2LOZBX.js +0 -1
  85. package/dist/ui/DocumentPage-EEGTJMIW.js +0 -1
  86. package/dist/ui/LogsPage-IP2DKEYR.js +0 -1
  87. package/dist/ui/NewReleasePage-DGMFU2JN.js +0 -1
  88. package/dist/ui/ReleasePage-2KSF23TK.js +0 -1
  89. package/dist/ui/SettingsPage-36XFWV62.js +0 -1
  90. package/dist/ui/TaskPage-SPIFPGPP.js +0 -1
  91. package/dist/ui/TasksPage-ZOXRPBQV.js +0 -1
  92. package/dist/ui/chunk-AFWBSIPL.js +0 -1
  93. package/dist/ui/chunk-GXSAEPU3.js +0 -1
  94. package/dist/ui/chunk-I6ICVKEC.js +0 -1
  95. package/dist/ui/chunk-JZFTZ4X4.js +0 -87
  96. package/dist/ui/chunk-MDUBCXU2.js +0 -1
  97. package/dist/ui/chunk-NXQVLOTK.js +0 -1
  98. package/dist/ui/chunk-NZHF733K.js +0 -7
  99. package/dist/ui/chunk-PJA7YP4A.js +0 -1
  100. package/dist/ui/chunk-XOQ3KDSR.js +0 -3
  101. package/dist/ui/chunk-YFA6U2CV.js +0 -1
  102. /package/dist/ui/{ImageEditorDialog-4H665KK2.js.LEGAL.txt → ImageEditorDialog-QEULJAT2.js.LEGAL.txt} +0 -0
  103. /package/dist/ui/{chunk-NZHF733K.js.LEGAL.txt → chunk-4CUWZQXT.js.LEGAL.txt} +0 -0
  104. /package/dist/ui/{chunk-JZFTZ4X4.js.LEGAL.txt → chunk-NMBXHKIJ.js.LEGAL.txt} +0 -0
  105. /package/dist/ui/{chunk-JT5L6GPZ.js.LEGAL.txt → chunk-RI2JWWU3.js.LEGAL.txt} +0 -0
  106. /package/dist/ui/{prerender-Q4YSDCPB.js → prerender-M47IWV5Q.js} +0 -0
@@ -1 +1 @@
1
- import{a as bt}from"./chunk-CGCKJFL4.js";import{f as ft,g as ht,h as mt,i as ke,j as R,k as Ae,l as Q,m as vt}from"./chunk-SKEP5WYH.js";import{c as nt}from"./chunk-AFWBSIPL.js";import{a as at}from"./chunk-62UWGWON.js";import{a as w,c as we}from"./chunk-I6ICVKEC.js";import{a as ce,f as ot}from"./chunk-ORXEMIQC.js";import{a as N,d as Se}from"./chunk-5MV6XVGA.js";import{c as et,q as tt,r as it,t as de,u as xe}from"./chunk-EGEB6N4J.js";import{f as j}from"./chunk-AL3TN2KI.js";import{$ as Fe,A as qe,Aa as le,Ab as Ce,Ca as se,Ea as Qe,Ec as Y,Fc as Ie,Ga as re,Ha as i,Ob as ut,Pc as gt,R as $e,V as We,W as X,Wc as Ee,Y as G,a as g,c as z,e as ve,ea as A,fa as Ke,g as J,ga as B,ha as Je,i as oe,j as be,jc as pt,lc as De,m as _e,ma as Xe,mb as lt,mc as Te,o as Ve,oa as Z,ob as st,p as He,qa as Ze,ra as T,sa as ye,ub as rt,va as ne,w as je,wb as dt,xb as ct,za as Ye}from"./chunk-NZHF733K.js";import{d as M,j as ae,k as Le}from"./chunk-KUCVLANF.js";Le();be();function _t(e,l){let t;return(...a)=>{window.clearTimeout(t),t=window.setTimeout(()=>{e(...a)},l)}}function Ft(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 q=class{constructor(){this.events=new Map}on(l,t){let a=Ft(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 ue=class{constructor(){this.subscribers=new Set;this.subtreeSubscribers=new Set;this.children=new Map}},pe=class extends q{constructor(t){super();this.root=new ue;this.data=t||{}}get(t){return this.getValueFromPath(t,this.data)}set(t,a){if(t===""){N(a)&&this.setData(a);return}this.update({[t]:a})}update(t){let a=new Map,o=(s,r,d)=>{if(a.set(s,d),!N(r)&&!N(d))return;let u=N(r)?Object.keys(r):[],m=N(d)?Object.keys(d):[];new Set([...u,...m]).forEach(h=>{let p=N(r)?r[h]:void 0,b=N(d)?d[h]:void 0;Se(p,b)||o(`${s}.${h}`,p,b)})};Object.entries(t).forEach(([s,r])=>{let d=this.data,u=s.split("."),m=u.pop();for(let h of u)d[h]||(d[h]={}),d=d[h];let F=d[m];d[m]=r,this.dispatch("VALUE_CHANGE",s,r),o(s,F,r)});let n=new Map;a.forEach((s,r)=>{this.collectSubtreeNotifications(r,n)}),a.forEach((s,r)=>{let d=this.getTrieNode(r);d&&d.subscribers.size>0&&d.subscribers.forEach(u=>u(s))}),n.forEach((s,r)=>{let d=this.get(r);s.subtreeSubscribers.forEach(u=>u(d))}),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),r=this.getValueFromPath(a,n);Se(s,r)||(t.subscribers.forEach(d=>d(r)),t.subtreeSubscribers.forEach(d=>d(r))),t.children.forEach((d,u)=>{let m=a?`${a}.${u}`:u;this.notifyOnUpdate(d,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 ue);else return;n=n.children.get(s)}return n}};var yt=3*ce.second,kt=5*ce.minute;var At=30*ce.second,Pe=class extends q{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=_t(()=>this.flush(),yt);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=et(this.db,"Projects",this.projectId,"Collections",a,"Drafts",o),this.store=new pe({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,r)=>{this.dispatch("VALUE_CHANGE",s,r)});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=it(this.docRef,t=>{if(t.metadata.hasPendingWrites)return;let a=t.data()||{};this.pendingUpdates.size>0&&wt(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.setPendingUpdate(t,de()):this.setPendingUpdate(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.setPendingUpdate(a,de()):this.setPendingUpdate(a,o)}this.store.update(t),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges()}}async removeKey(t){this.readOnly||(this.setPendingUpdate(t,de()),this.store.set(t,void 0),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges())}setPendingUpdate(t,a){for(let o of this.pendingUpdates.keys())Ut(o,t)&&this.pendingUpdates.delete(o);this.pendingUpdates.set(t,a)}getPendingUpdates(){return Nt(Object.fromEntries(this.pendingUpdates))}setSaveState(t){let a=this.saveState;t==="SAVED"&&a!=="SAVING"||(this.saveState=t,t==="SAVED"&&window.setTimeout(()=>{this.saveState==="SAVED"&&this.setSaveState("NO_CHANGES")},yt),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=this.getPendingUpdates();a["sys.modifiedAt"]=xe(),a["sys.modifiedBy"]=window.firebase.user.email,this.autolock&&!this.autolockApplied&&!this.store.get("sys.publishingLocked")&&(this.autolockApplied=!0,a["sys.publishingLocked"]={lockedAt:xe(),lockedBy:window.firebase.user.email,reason:this.autolockReason}),this.pendingUpdates.clear();try{this.setSaveState("SAVING"),await tt(this.docRef,a),this.setSaveState("SAVED"),t?.quiet||this.dispatch("FLUSH"),ot("doc.save",{metadata:{docId:this.docId},throttle:kt,throttleId:this.docId})}catch(o){console.error("failed to update doc:",o),this.setSaveState("ERROR");let n=at(o);w({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 wt(e,l){for(let t in l){let a=l[t];if(t.includes(".")){let[o,n]=Pt(t);e[o]??={},wt(e[o],{[n]:a})}else typeof a>"u"?delete e[t]:e[t]=a}}function Pt(e){let l=e.indexOf("."),t=e.substring(0,l),a=e.substring(l+1);return[t,a]}function Nt(e){let l={...e};for(let t in l)Ot(t,l)&&delete l[t];return l}function Ot(e,l){let t=e.split(".");for(let a=1;a<t.length;a++)if(t.slice(0,a).join(".")in l)return!0;return!1}function Ut(e,l){return e.startsWith(`${l}.`)}var Ne=ae(null);function hi(e){let[l,t]=g(!0),a=J(()=>new Pe(e.docId),[e.docId]);a.readOnly=e.readOnly??!1,a.autoSave=e.autoSave??!0,a.flushOnStop=e.flushOnStop??!0,z(()=>(t(!0),a.onChange(n=>{t(!1),nt(n.id,n)}),a.start(),()=>a.dispose()),[a]),z(()=>{let n,s=()=>{document.hidden||document.visibilityState!=="visible"?n=window.setTimeout(()=>{a.stop()},At):(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(Ne.Provider,{value:o,children:e.children})}function mi(e){return i(Ne.Provider,{value:e.value,children:e.children})}function ge(){let e=oe(Ne);if(!e)throw new Error("useDraftDoc() should be used within a <DraftDocProvider>");return e}function vi(e){let{controller:l}=ge();z(()=>l.onSaveStateChange(e),[l])}function bi(e){let{controller:l}=ge();z(()=>l.onChange(e),[l])}function _i(e,l){let{controller:t}=ge();z(()=>t.subscribe(e,l),[t])}function Oe(e,l){let{controller:t}=ge(),[a,o]=g(t.getValue(e)??l);return z(()=>t.subscribe(e,s=>{o(s)}),[t]),[a,s=>{o(s),s==null?t.removeKey(e):t.updateKey(e,s)}]}Le();je();je();be();var Mt=["drive.google.com","docs.google.com"];function fe(e){try{let l=new URL(e);if(!Mt.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}`}})]),r=n.result;if(!s.ok)throw new Error(`Failed to download file from Drive: ${s.statusText}`);let d=await s.blob();return new File([d],r.name,{type:r.mimeType})}be();var zt=["1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"],Gt=["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"];function St(e){let[l,t]=g("simple"),[a,o]=g(!1),[n,s]=g(!1),[r,d]=g(null),[u,m]=g(""),[F,h]=g(e.initialWidth||1600),[p,b]=g(e.initialHeight||900),[S,$]=g("16:9"),W=!!(window.__ROOT_CTX?.experiments||{}).ai;async function L(){if(!u){w({title:"Prompt required",message:"Please enter a prompt to generate an image.",color:"red"});return}o(!0);try{let _=await(await fetch("/cms/api/ai.generate_image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:u,aspectRatio:S})})).json();if(_.success&&_.image)d(_.image);else throw new Error(_.error||"Failed to generate image")}catch(f){console.error(f),w({title:"Generation failed",message:f.message||"Unknown error",color:"red"})}finally{o(!1)}}function te(f){f.preventDefault();let _=new FormData(f.target),y=parseInt(_.get("width"),10),D=parseInt(_.get("height"),10),V=_.get("backgroundColor"),O=_.get("label")||`${y}x${D}`,E=[];if(E.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${y}" height="${D}" viewBox="0 0 ${y} ${D}"><rect width="${y}" height="${D}" fill="${V}" />`),O){let me=y*.5/(O.length*.6);E.push(`<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-size="${me}" fill="#fff">${O}</text>`)}E.push("</svg>");let H=E.join(""),U=new TextEncoder().encode(H),he={src:`data:image/svg+xml;base64,${btoa(String.fromCharCode(...U))}`,filename:"placeholder.svg",width:y,height:D,alt:""};e.onSubmit(he)}async function K(){if(r){s(!0);try{let _=await(await fetch(r)).blob(),y=new File([_],"generated-image.png",{type:"image/png"}),{uploadFileToGCS:D}=await import("./gcs-L33FIRZU.js"),V=await D(y),[O,E]=S.split(":").map(Number),H=1600,ie=Math.round(H*E/O),U={...V,width:H,height:ie,alt:u};e.onSubmit(U)}catch(f){console.error(f),w({title:"Save failed",message:f.message||"Failed to upload image",color:"red"})}finally{s(!1)}}}return i(se,{gap:"md",children:[W&&i(Ye,{value:l,onChange:f=>t(f),data:[{label:"Simple",value:"simple"},{label:i(B,{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:F,onChange:f=>h(parseInt(f.currentTarget.value,10)),"data-autofocus":!0}),i(ne,{label:"Height",name:"height",type:"number",value:p,onChange:f=>b(parseInt(f.currentTarget.value,10))}),i(ne,{name:"label",label:"Label",defaultValue:""}),i(Je,{name:"backgroundColor",label:"Background color",format:"hex",defaultValue:"#868e96",swatches:Gt})]}),i(B,{justify:"flex-end",mt:"md",children:i(A,{variant:"filled",type:"submit",children:"Create"})})]}):i(se,{gap:"xs",children:[i(le,{label:"Aspect Ratio",data:zt,value:S,onChange:f=>$(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}),r&&i(Xe,{src:r,alt:"Generated preview",height:200,fit:"contain"}),i(B,{justify:"flex-end",mt:"md",children:[i(A,{variant:"light",onClick:L,loading:a,disabled:n||!u,leftIcon:i(Y,{size:16}),children:a?"Generating...":"Preview"}),i(A,{variant:"filled",onClick:K,loading:n,disabled:!r||a,children:n?"Saving...":"Save"})]})]})]})}var Bt=["image/gif","image/jpeg","image/png","image/svg+xml","image/webp"],Ct=ae(null),Rt=He(()=>import("./ImageEditorDialog-4H665KK2.js").then(e=>({default:e.ImageEditorDialog})));function ee(){let e=oe(Ct);if(!e)throw new Error("useFileField() should be called within a <FileFieldContext.Provider>");return e}function Lt(e){let{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n}=e,s=qe(),r=ve(null),[d,u]=g(!1),[m,F]=g(!1),[h,p]=g(!1),b=bt(),S=e.allowEditing!==!1,[$,Ue]=g("hash"),[W,L]=g(null),[te,K]=g(!1),[f,_]=g(null),y=e.accept??l.exts??(e.variant==="image"?Bt:[]),D=t?.alt||"",V=e.altDisabledByMetadata===!0,O=l.alt!==!1&&!V;async function E(c,C,v){try{n("loading");let P=v?.namingMode||(l.preserveFilename?"clean":"hash"),k=l.cacheControl||(P==="clean"?"no-cache":void 0),x=await ft(c,{namingMode:P,checkExists:v?.checkExists??!1,cacheControl:k});!x.alt&&Dt(x.filename)&&D&&(x.alt=D),C&&(x.originalSrc=C),a(x),n("complete"),L(null),_(null)}catch(P){console.error("upload failed"),console.error(P),n("error"),w({title:"Upload failed",message:"Failed to upload: "+String(P),color:"red",autoClose:!1})}}async function H(){n("loading");try{let c=t?.gcsPath||t?.src;c&&await ht(c),a(null),n(null),w({message:"File deleted from GCS",color:"green"})}catch(c){console.error(c),n("error"),w({title:"Delete failed",message:String(c),color:"red"})}finally{F(!1)}}function ie(){if(!S&&t?.src){F(!0);return}a(null)}async function U(c,C){if(!c)return;if(L(null),_(null),K(!1),typeof c=="string"&&!C?.as){let k=fe(c);if(k){try{if(!b.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"),w({message:"Downloading from Google Drive...",loading:!0,autoClose:!1,id:"gdrive-download"});let x=await xt(b,k);we("gdrive-download"),U(x)}catch(x){console.error(x),n("error"),we("gdrive-download"),w({title:"Google Drive import failed",message:x.message||"Failed to download",color:"red"})}return}}C?.as==="svg"&&typeof c=="string"&&(c=new File([new Blob([c],{type:"image/svg+xml"})],"untitled.svg",{type:"image/svg+xml"}));let v=c,P=ke(v.name);if(y.length>0&&!y.some(k=>k.endsWith(P)||k===`*/${P}`||k==="*/*"||k===v.type)){w({title:"Invalid file type",message:`File type ${P} is not allowed.`,color:"red",autoClose:!0});return}if($==="clean"&&e.showNamingOptions){n("loading");let x=`${window.__ROOT_CTX.rootConfig.projectId}/uploads/${v.name}`;try{if(await mt(x)){L(v),_(`https://storage.googleapis.com/${window.firebase.storage.app.options.storageBucket}/${x}`),n(null);return}}catch(Re){console.warn("Failed to check file existence",Re)}}E(v,void 0,{namingMode:$})}function Me(){r.current?.focus()}function he(){if(t?.src)if(Ae(t.src)){let c=document.createElement("a");c.href=vt(t.src),t.filename&&(c.download=t.filename),document.body.appendChild(c),c.click(),document.body.removeChild(c)}else window.open(t.src,"_blank")}function ze(){let c=document.createElement("input");c.type="file",y.length>0&&(c.accept=y.join(",")),c.onchange=C=>{let v=C.target;v.files&&v.files.length>0&&U(v.files[0])},c.click(),c.remove()}function Ge(){u(!0)}function me(){p(!0)}function Be(c){t?.src&&a({...t,alt:c||""})}async function Et(){let c=t;if(c?.src){n("loading");try{let C=await window.fetch("/cms/api/ai.generate_alt_text",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({imageUrl:c.src})}),v=await C.json();if(!C.ok||!v.success)throw new Error(v.error||"Failed to generate alt text");v.altText&&Be(v.altText)}catch(C){w({title:"Sorry, something went wrong.",message:C.message||"Unknown error",color:"red",autoClose:!0})}finally{n("complete")}}}return i(Ct.Provider,{value:{field:l,variant:e.variant,value:t,setValue:a,loadingState:o,removeFile:ie,acceptedFileTypes:y,handleFile:U,focusDropZone:Me,requestGenerateAltText:Et,requestFileUpload:ze,requestFileDownload:he,requestPlaceholderModalOpen:Ge,requestImageEditorOpen:me,showAltText:O,altText:D,setAltText:Be,altDisabledByMetadata:V,setAltDisabledByMetadata:e.setAltDisabledByMetadata,allowEditing:S},children:[i(ye,{size:"sm",opened:d,onClose:()=>u(!1),title:"Placeholder image",centered:!0,overlayColor:s.colorScheme==="dark"?s.colors.dark[9]:s.colors.gray[2],children:i(St,{onSubmit:c=>{a(c),u(!1)}})}),i(ye,{size:"sm",opened:m,onClose:()=>F(!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(B,{grow:!0,spacing:"xs",children:[i(A,{variant:"default",onClick:()=>F(!1),disabled:o==="loading",children:"Cancel"}),i(A,{color:"red",onClick:H,loading:o==="loading",children:"Delete"})]})]}),h&&t?.src&&i(Ve,{fallback:null,children:i(Rt,{opened:h,onClose:()=>p(!1),src:t.src,originalSrc:t.originalSrc,filename:t.filename,initialWidth:parseInt(t.width),initialHeight:parseInt(t.height),onSave:c=>{E(c,t.originalSrc||t.src),p(!1)}},t.src)}),W?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:W.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(ct,{size:12})]})}),i("div",{className:"FileField__overwriteWarning__checkbox",children:i(Ke,{label:"Confirm overwrite",checked:te,onChange:c=>K(c.currentTarget.checked)})}),i(B,{grow:!0,spacing:"xs",className:"FileField__overwriteWarning__actions",children:[i(A,{variant:"default",onClick:()=>{L(null),_(null),K(!1)},disabled:o==="loading",children:"Cancel"}),i(A,{disabled:!te,onClick:()=>E(W,void 0,{namingMode:"clean"}),color:"red",loading:o==="loading",children:"Overwrite"})]})]}):i(M,{children:[i("div",{className:j("FileField",e.showNamingOptions&&"FileField--withOptions"),children:[i(I.Dropzone,{ref:r}),t?.src?i(I.Preview,{}):i(I.InvisibleDropzone,{children:i(I.Empty,{})})]}),e.showNamingOptions&&!t&&i("div",{className:"FileField__settings",style:{marginTop:8},children:i(le,{label:"File name options",size:"xs",itemComponent:Vt,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:$,onChange:c=>Ue(c||"hash"),disabled:o==="loading"||!!t})})]})]})}function I(e){let l=e.field,[t,a]=Oe(e.deepKey),[o,n]=g(null),s=jt(e.deepKey),[r,d]=Oe(s),u=r?.alt===!1,m=F=>{let h={...r||{}};F?h.alt=!1:delete h.alt,d(Object.keys(h).length===0?null:h)};return i(Lt,{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n,variant:e.variant,allowEditing:e.allowEditing,altDisabledByMetadata:u,setAltDisabledByMetadata:e.variant==="image"&&l.alt!==!1?m:void 0})}I.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,r=e.value?.filename||"",d=Q(r),u=R(r)||d&&s,[m,F]=g(!u),h=ve(e.value?.src);if(e.value?.src!==h.current){h.current=e.value?.src;let p=e.value?.filename||"",b=R(p)||Q(p)&&s;!b&&!m?F(!0):b&&m&&F(!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:()=>F(p=>!p),size:"sm",variant:"outline",className:"FileField__Preview__InfoButton__Icon","aria-label":"Toggle file info",children:i(ut,{size:16})})}),i(T,{shadow:"sm",control:i(X,{variant:"outline",size:"sm",radius:"sm",c:"black",className:"FileField__Preview__InfoButton__Icon",children:i(rt,{size:16})}),children:[e.allowEditing&&i(M,{children:[i(T.Label,{size:"sm",children:"REPLACE"}),i(T.Item,{icon:e.variant==="image"?i(Te,{size:16}):i(Ce,{size:16}),onClick:()=>e.requestFileUpload(),children:["Upload ",e.variant==="image"?"image":"file"]}),Tt(e.acceptedFileTypes)&&i(T.Item,{disabled:!e.value?.src,icon:i(De,{size:16}),onClick:()=>{e.requestPlaceholderModalOpen()},children:"Placeholder image"}),R(e.value?.src)&&!e.value?.src?.endsWith(".svg")&&i(T.Item,{disabled:!e.value?.src,icon:i(st,{size:16}),closeMenuOnClick:!0,onClick:()=>{e.requestImageEditorOpen()},children:"Edit image"}),i(Fe,{})]}),i(T.Item,{disabled:e.value?.src?.startsWith("data:"),onClick:()=>{e?.requestFileDownload()},icon:i(dt,{size:16}),children:"Download file"}),i(T.Item,{closeOnItemClick:!1,icon:i(lt,{size:16}),onClick:()=>{o(!1);let p=e.value?.src||"";Ae(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&&R(e.value?.src||"")&&e.value?.canvasBgColor&&i(T.Item,{icon:e.value?.canvasBgColor==="dark"?i(Ee,{size:16}):i(Ie,{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"}),e.allowEditing&&e.setAltDisabledByMetadata&&i(T.Item,{icon:e.altDisabledByMetadata?i(Ee,{size:16}):i(Ie,{size:16,style:{opacity:.25}}),closeOnItemClick:!1,onClick:()=>{e.setAltDisabledByMetadata?.(!e.altDisabledByMetadata)},children:"Disable alt text"}),i(Fe,{}),i(T.Item,{color:"red",onClick:()=>{e?.removeFile()},icon:i(gt,{size:16}),children:"Remove file"})]})]}),i("div",{className:j("FileField__Canvas",m&&"FileField__Canvas--infoOpened",l&&"dragging"),style:Ht(e.value),onDragOver:p=>{p.preventDefault(),t(!0)},onDragLeave:p=>{p.preventDefault(),t(!1)},onDrop:p=>{p.preventDefault(),t(!1);let b=p.dataTransfer?.files[0];b&&e&&e.handleFile(b)},onPaste:p=>{p.preventDefault();let b=p.clipboardData?.files[0];if(b){e.handleFile(b);return}let S=p.clipboardData?.getData("text/plain");if(S){if(fe(S)){e.handleFile(S);return}if(It(S)){e.handleFile(S,{as:"svg"});return}}},children:[i(Ze,{visible:e.loadingState==="loading"}),m?i("div",{className:"FileField__Canvas__Info",children:[i(pt,{size:16,className:"FileField__Canvas__Info__Icon"}),i(Qe,{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(M,{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(M,{children:[!!(e.value?.width&&e.value?.height)&&i($e,{radius:"sm",className:"FileField__Preview__Info",children:[e.value.width,"x",e.value.height]}),R(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(M,{children:i("video",{className:"FileField__Preview__Image",controls:!0,muted:!0,preload:"metadata",children:i("source",{src:e.value.src,type:`video/${ke(e.value.src)}`})})})]}),e.allowEditing&&i("div",{className:"FileField__reupload",children:i(I.UploadButton,{className:"FileField__reupload__button",compact:!0})})]}),e.allowEditing&&e.showAltText&&(e.altText||Dt(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};I.UploadButton=e=>{let l=ee(),t=l.loadingState==="loading",a=e.compact?14:16;return i(A,{color:"black",variant:"default",disabled:t,size:e.compact?"compact-xs":"compact-md",className:j("FileField__FileUploadButton",e.compact&&"FileField__FileUploadButton--compact"),onClick:()=>{l.requestFileUpload()},leftIcon:i(M,{children:t&&!e.compact?i(We,{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"})};I.InvisibleDropzone=e=>{let[l,t]=g(!1),a=ee();return i("div",{className:j("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})};I.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(I.UploadButton,{}),Tt(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]})})]})};I.Dropzone=_e((e,l)=>{let[t,a]=g(!1),o=ee();return i("button",{ref:l,className:j("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 r=n.clipboardData?.files[0];if(r){o.handleFile(r);return}let d=n.clipboardData?.getData("text/plain");if(d){if(fe(d)){o.handleFile(d);return}if(It(d)){o.handleFile(d,{as:"svg"});return}}},title:"Drop or paste to upload a file"})});var Vt=_e(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 Dt(e){return e?R(e)||Q(e):!1}function Tt(e){return e.some(l=>l.startsWith("image/"))||e.length===0}function Ht(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 jt(e){let l=e.split("."),t=l.pop();return[...l,`@${t}`].join(".")}function It(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{_t as a,Ft as b,q as c,hi as d,mi as e,ge as f,vi as g,bi as h,_i as i,Oe as j,Lt as k,I as l};
1
+ import{a as bt}from"./chunk-V7RAXP2W.js";import{f as ft,g as ht,h as mt,i as ke,j as R,k as Ae,l as Q,m as vt}from"./chunk-SKEP5WYH.js";import{c as nt}from"./chunk-NQ5ARARP.js";import{a as at}from"./chunk-CVGYBXVH.js";import{a as w,c as we}from"./chunk-AXETBZ6T.js";import{a as ce,f as ot}from"./chunk-ORXEMIQC.js";import{a as N,d as Se}from"./chunk-5MV6XVGA.js";import{c as et,q as tt,r as it,t as de,u as xe}from"./chunk-EGEB6N4J.js";import{f as j}from"./chunk-RPOP6MVJ.js";import{A as qe,Ba as se,Da as Qe,Dc as Y,Ec as Ie,Fa as re,Ga as i,Nb as ut,Oc as gt,R as $e,V as We,Vc as Ee,W as X,Y as G,_ as Fe,a as g,c as z,da as A,e as ve,ea as Ke,fa as B,g as J,ga as Je,i as oe,ic as pt,j as be,kc as De,la as Xe,lb as lt,lc as Te,m as _e,na as Z,nb as st,o as Ve,p as He,pa as Ze,qa as T,ra as ye,tb as rt,ua as ne,vb as dt,w as je,wb as ct,ya as Ye,za as le,zb as Ce}from"./chunk-4CUWZQXT.js";import{d as M,j as ae,k as Le}from"./chunk-KUCVLANF.js";Le();be();function _t(e,l){let t;return(...a)=>{window.clearTimeout(t),t=window.setTimeout(()=>{e(...a)},l)}}function Ft(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 q=class{constructor(){this.events=new Map}on(l,t){let a=Ft(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 ue=class{constructor(){this.subscribers=new Set;this.subtreeSubscribers=new Set;this.children=new Map}},pe=class extends q{constructor(t){super();this.root=new ue;this.data=t||{}}get(t){return this.getValueFromPath(t,this.data)}set(t,a){if(t===""){N(a)&&this.setData(a);return}this.update({[t]:a})}update(t){let a=new Map,o=(s,r,d)=>{if(a.set(s,d),!N(r)&&!N(d))return;let u=N(r)?Object.keys(r):[],m=N(d)?Object.keys(d):[];new Set([...u,...m]).forEach(h=>{let p=N(r)?r[h]:void 0,b=N(d)?d[h]:void 0;Se(p,b)||o(`${s}.${h}`,p,b)})};Object.entries(t).forEach(([s,r])=>{let d=this.data,u=s.split("."),m=u.pop();for(let h of u)d[h]||(d[h]={}),d=d[h];let F=d[m];d[m]=r,this.dispatch("VALUE_CHANGE",s,r),o(s,F,r)});let n=new Map;a.forEach((s,r)=>{this.collectSubtreeNotifications(r,n)}),a.forEach((s,r)=>{let d=this.getTrieNode(r);d&&d.subscribers.size>0&&d.subscribers.forEach(u=>u(s))}),n.forEach((s,r)=>{let d=this.get(r);s.subtreeSubscribers.forEach(u=>u(d))}),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),r=this.getValueFromPath(a,n);Se(s,r)||(t.subscribers.forEach(d=>d(r)),t.subtreeSubscribers.forEach(d=>d(r))),t.children.forEach((d,u)=>{let m=a?`${a}.${u}`:u;this.notifyOnUpdate(d,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 ue);else return;n=n.children.get(s)}return n}};var yt=3*ce.second,kt=5*ce.minute;var At=30*ce.second,Pe=class extends q{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=_t(()=>this.flush(),yt);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=et(this.db,"Projects",this.projectId,"Collections",a,"Drafts",o),this.store=new pe({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,r)=>{this.dispatch("VALUE_CHANGE",s,r)});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=it(this.docRef,t=>{if(t.metadata.hasPendingWrites)return;let a=t.data()||{};this.pendingUpdates.size>0&&wt(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.setPendingUpdate(t,de()):this.setPendingUpdate(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.setPendingUpdate(a,de()):this.setPendingUpdate(a,o)}this.store.update(t),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges()}}async removeKey(t){this.readOnly||(this.setPendingUpdate(t,de()),this.store.set(t,void 0),this.setSaveState("UPDATE_PENDING"),this.autoSave&&this.queueChanges())}setPendingUpdate(t,a){for(let o of this.pendingUpdates.keys())Ut(o,t)&&this.pendingUpdates.delete(o);this.pendingUpdates.set(t,a)}getPendingUpdates(){return Nt(Object.fromEntries(this.pendingUpdates))}setSaveState(t){let a=this.saveState;t==="SAVED"&&a!=="SAVING"||(this.saveState=t,t==="SAVED"&&window.setTimeout(()=>{this.saveState==="SAVED"&&this.setSaveState("NO_CHANGES")},yt),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=this.getPendingUpdates();a["sys.modifiedAt"]=xe(),a["sys.modifiedBy"]=window.firebase.user.email,this.autolock&&!this.autolockApplied&&!this.store.get("sys.publishingLocked")&&(this.autolockApplied=!0,a["sys.publishingLocked"]={lockedAt:xe(),lockedBy:window.firebase.user.email,reason:this.autolockReason}),this.pendingUpdates.clear();try{this.setSaveState("SAVING"),await tt(this.docRef,a),this.setSaveState("SAVED"),t?.quiet||this.dispatch("FLUSH"),ot("doc.save",{metadata:{docId:this.docId},throttle:kt,throttleId:this.docId})}catch(o){console.error("failed to update doc:",o),this.setSaveState("ERROR");let n=at(o);w({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 wt(e,l){for(let t in l){let a=l[t];if(t.includes(".")){let[o,n]=Pt(t);e[o]??={},wt(e[o],{[n]:a})}else typeof a>"u"?delete e[t]:e[t]=a}}function Pt(e){let l=e.indexOf("."),t=e.substring(0,l),a=e.substring(l+1);return[t,a]}function Nt(e){let l={...e};for(let t in l)Ot(t,l)&&delete l[t];return l}function Ot(e,l){let t=e.split(".");for(let a=1;a<t.length;a++)if(t.slice(0,a).join(".")in l)return!0;return!1}function Ut(e,l){return e.startsWith(`${l}.`)}var Ne=ae(null);function hi(e){let[l,t]=g(!0),a=J(()=>new Pe(e.docId),[e.docId]);a.readOnly=e.readOnly??!1,a.autoSave=e.autoSave??!0,a.flushOnStop=e.flushOnStop??!0,z(()=>(t(!0),a.onChange(n=>{t(!1),nt(n.id,n)}),a.start(),()=>a.dispose()),[a]),z(()=>{let n,s=()=>{document.hidden||document.visibilityState!=="visible"?n=window.setTimeout(()=>{a.stop()},At):(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(Ne.Provider,{value:o,children:e.children})}function mi(e){return i(Ne.Provider,{value:e.value,children:e.children})}function ge(){let e=oe(Ne);if(!e)throw new Error("useDraftDoc() should be used within a <DraftDocProvider>");return e}function vi(e){let{controller:l}=ge();z(()=>l.onSaveStateChange(e),[l])}function bi(e){let{controller:l}=ge();z(()=>l.onChange(e),[l])}function _i(e,l){let{controller:t}=ge();z(()=>t.subscribe(e,l),[t])}function Oe(e,l){let{controller:t}=ge(),[a,o]=g(t.getValue(e)??l);return z(()=>t.subscribe(e,s=>{o(s)}),[t]),[a,s=>{o(s),s==null?t.removeKey(e):t.updateKey(e,s)}]}Le();je();je();be();var Mt=["drive.google.com","docs.google.com"];function fe(e){try{let l=new URL(e);if(!Mt.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}`}})]),r=n.result;if(!s.ok)throw new Error(`Failed to download file from Drive: ${s.statusText}`);let d=await s.blob();return new File([d],r.name,{type:r.mimeType})}be();var zt=["1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"],Gt=["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"];function St(e){let[l,t]=g("simple"),[a,o]=g(!1),[n,s]=g(!1),[r,d]=g(null),[u,m]=g(""),[F,h]=g(e.initialWidth||1600),[p,b]=g(e.initialHeight||900),[S,$]=g("16:9"),W=!!(window.__ROOT_CTX?.experiments||{}).ai;async function L(){if(!u){w({title:"Prompt required",message:"Please enter a prompt to generate an image.",color:"red"});return}o(!0);try{let _=await(await fetch("/cms/api/ai.generate_image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:u,aspectRatio:S})})).json();if(_.success&&_.image)d(_.image);else throw new Error(_.error||"Failed to generate image")}catch(f){console.error(f),w({title:"Generation failed",message:f.message||"Unknown error",color:"red"})}finally{o(!1)}}function te(f){f.preventDefault();let _=new FormData(f.target),y=parseInt(_.get("width"),10),D=parseInt(_.get("height"),10),V=_.get("backgroundColor"),O=_.get("label")||`${y}x${D}`,E=[];if(E.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${y}" height="${D}" viewBox="0 0 ${y} ${D}"><rect width="${y}" height="${D}" fill="${V}" />`),O){let me=y*.5/(O.length*.6);E.push(`<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-size="${me}" fill="#fff">${O}</text>`)}E.push("</svg>");let H=E.join(""),U=new TextEncoder().encode(H),he={src:`data:image/svg+xml;base64,${btoa(String.fromCharCode(...U))}`,filename:"placeholder.svg",width:y,height:D,alt:""};e.onSubmit(he)}async function K(){if(r){s(!0);try{let _=await(await fetch(r)).blob(),y=new File([_],"generated-image.png",{type:"image/png"}),{uploadFileToGCS:D}=await import("./gcs-L33FIRZU.js"),V=await D(y),[O,E]=S.split(":").map(Number),H=1600,ie=Math.round(H*E/O),U={...V,width:H,height:ie,alt:u};e.onSubmit(U)}catch(f){console.error(f),w({title:"Save failed",message:f.message||"Failed to upload image",color:"red"})}finally{s(!1)}}}return i(se,{gap:"md",children:[W&&i(Ye,{value:l,onChange:f=>t(f),data:[{label:"Simple",value:"simple"},{label:i(B,{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:F,onChange:f=>h(parseInt(f.currentTarget.value,10)),"data-autofocus":!0}),i(ne,{label:"Height",name:"height",type:"number",value:p,onChange:f=>b(parseInt(f.currentTarget.value,10))}),i(ne,{name:"label",label:"Label",defaultValue:""}),i(Je,{name:"backgroundColor",label:"Background color",format:"hex",defaultValue:"#868e96",swatches:Gt})]}),i(B,{justify:"flex-end",mt:"md",children:i(A,{variant:"filled",type:"submit",children:"Create"})})]}):i(se,{gap:"xs",children:[i(le,{label:"Aspect Ratio",data:zt,value:S,onChange:f=>$(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}),r&&i(Xe,{src:r,alt:"Generated preview",height:200,fit:"contain"}),i(B,{justify:"flex-end",mt:"md",children:[i(A,{variant:"light",onClick:L,loading:a,disabled:n||!u,leftIcon:i(Y,{size:16}),children:a?"Generating...":"Preview"}),i(A,{variant:"filled",onClick:K,loading:n,disabled:!r||a,children:n?"Saving...":"Save"})]})]})]})}var Bt=["image/gif","image/jpeg","image/png","image/svg+xml","image/webp"],Ct=ae(null),Rt=He(()=>import("./ImageEditorDialog-QEULJAT2.js").then(e=>({default:e.ImageEditorDialog})));function ee(){let e=oe(Ct);if(!e)throw new Error("useFileField() should be called within a <FileFieldContext.Provider>");return e}function Lt(e){let{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n}=e,s=qe(),r=ve(null),[d,u]=g(!1),[m,F]=g(!1),[h,p]=g(!1),b=bt(),S=e.allowEditing!==!1,[$,Ue]=g("hash"),[W,L]=g(null),[te,K]=g(!1),[f,_]=g(null),y=e.accept??l.exts??(e.variant==="image"?Bt:[]),D=t?.alt||"",V=e.altDisabledByMetadata===!0,O=l.alt!==!1&&!V;async function E(c,C,v){try{n("loading");let P=v?.namingMode||(l.preserveFilename?"clean":"hash"),k=l.cacheControl||(P==="clean"?"no-cache":void 0),x=await ft(c,{namingMode:P,checkExists:v?.checkExists??!1,cacheControl:k});!x.alt&&Dt(x.filename)&&D&&(x.alt=D),C&&(x.originalSrc=C),a(x),n("complete"),L(null),_(null)}catch(P){console.error("upload failed"),console.error(P),n("error"),w({title:"Upload failed",message:"Failed to upload: "+String(P),color:"red",autoClose:!1})}}async function H(){n("loading");try{let c=t?.gcsPath||t?.src;c&&await ht(c),a(null),n(null),w({message:"File deleted from GCS",color:"green"})}catch(c){console.error(c),n("error"),w({title:"Delete failed",message:String(c),color:"red"})}finally{F(!1)}}function ie(){if(!S&&t?.src){F(!0);return}a(null)}async function U(c,C){if(!c)return;if(L(null),_(null),K(!1),typeof c=="string"&&!C?.as){let k=fe(c);if(k){try{if(!b.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"),w({message:"Downloading from Google Drive...",loading:!0,autoClose:!1,id:"gdrive-download"});let x=await xt(b,k);we("gdrive-download"),U(x)}catch(x){console.error(x),n("error"),we("gdrive-download"),w({title:"Google Drive import failed",message:x.message||"Failed to download",color:"red"})}return}}C?.as==="svg"&&typeof c=="string"&&(c=new File([new Blob([c],{type:"image/svg+xml"})],"untitled.svg",{type:"image/svg+xml"}));let v=c,P=ke(v.name);if(y.length>0&&!y.some(k=>k.endsWith(P)||k===`*/${P}`||k==="*/*"||k===v.type)){w({title:"Invalid file type",message:`File type ${P} is not allowed.`,color:"red",autoClose:!0});return}if($==="clean"&&e.showNamingOptions){n("loading");let x=`${window.__ROOT_CTX.rootConfig.projectId}/uploads/${v.name}`;try{if(await mt(x)){L(v),_(`https://storage.googleapis.com/${window.firebase.storage.app.options.storageBucket}/${x}`),n(null);return}}catch(Re){console.warn("Failed to check file existence",Re)}}E(v,void 0,{namingMode:$})}function Me(){r.current?.focus()}function he(){if(t?.src)if(Ae(t.src)){let c=document.createElement("a");c.href=vt(t.src),t.filename&&(c.download=t.filename),document.body.appendChild(c),c.click(),document.body.removeChild(c)}else window.open(t.src,"_blank")}function ze(){let c=document.createElement("input");c.type="file",y.length>0&&(c.accept=y.join(",")),c.onchange=C=>{let v=C.target;v.files&&v.files.length>0&&U(v.files[0])},c.click(),c.remove()}function Ge(){u(!0)}function me(){p(!0)}function Be(c){t?.src&&a({...t,alt:c||""})}async function Et(){let c=t;if(c?.src){n("loading");try{let C=await window.fetch("/cms/api/ai.generate_alt_text",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({imageUrl:c.src})}),v=await C.json();if(!C.ok||!v.success)throw new Error(v.error||"Failed to generate alt text");v.altText&&Be(v.altText)}catch(C){w({title:"Sorry, something went wrong.",message:C.message||"Unknown error",color:"red",autoClose:!0})}finally{n("complete")}}}return i(Ct.Provider,{value:{field:l,variant:e.variant,value:t,setValue:a,loadingState:o,removeFile:ie,acceptedFileTypes:y,handleFile:U,focusDropZone:Me,requestGenerateAltText:Et,requestFileUpload:ze,requestFileDownload:he,requestPlaceholderModalOpen:Ge,requestImageEditorOpen:me,showAltText:O,altText:D,setAltText:Be,altDisabledByMetadata:V,setAltDisabledByMetadata:e.setAltDisabledByMetadata,allowEditing:S},children:[i(ye,{size:"sm",opened:d,onClose:()=>u(!1),title:"Placeholder image",centered:!0,overlayColor:s.colorScheme==="dark"?s.colors.dark[9]:s.colors.gray[2],children:i(St,{onSubmit:c=>{a(c),u(!1)}})}),i(ye,{size:"sm",opened:m,onClose:()=>F(!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(B,{grow:!0,spacing:"xs",children:[i(A,{variant:"default",onClick:()=>F(!1),disabled:o==="loading",children:"Cancel"}),i(A,{color:"red",onClick:H,loading:o==="loading",children:"Delete"})]})]}),h&&t?.src&&i(Ve,{fallback:null,children:i(Rt,{opened:h,onClose:()=>p(!1),src:t.src,originalSrc:t.originalSrc,filename:t.filename,initialWidth:parseInt(t.width),initialHeight:parseInt(t.height),onSave:c=>{E(c,t.originalSrc||t.src),p(!1)}},t.src)}),W?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:W.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(ct,{size:12})]})}),i("div",{className:"FileField__overwriteWarning__checkbox",children:i(Ke,{label:"Confirm overwrite",checked:te,onChange:c=>K(c.currentTarget.checked)})}),i(B,{grow:!0,spacing:"xs",className:"FileField__overwriteWarning__actions",children:[i(A,{variant:"default",onClick:()=>{L(null),_(null),K(!1)},disabled:o==="loading",children:"Cancel"}),i(A,{disabled:!te,onClick:()=>E(W,void 0,{namingMode:"clean"}),color:"red",loading:o==="loading",children:"Overwrite"})]})]}):i(M,{children:[i("div",{className:j("FileField",e.showNamingOptions&&"FileField--withOptions"),children:[i(I.Dropzone,{ref:r}),t?.src?i(I.Preview,{}):i(I.InvisibleDropzone,{children:i(I.Empty,{})})]}),e.showNamingOptions&&!t&&i("div",{className:"FileField__settings",style:{marginTop:8},children:i(le,{label:"File name options",size:"xs",itemComponent:Vt,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:$,onChange:c=>Ue(c||"hash"),disabled:o==="loading"||!!t})})]})]})}function I(e){let l=e.field,[t,a]=Oe(e.deepKey),[o,n]=g(null),s=jt(e.deepKey),[r,d]=Oe(s),u=r?.alt===!1,m=F=>{let h={...r||{}};F?h.alt=!1:delete h.alt,d(Object.keys(h).length===0?null:h)};return i(Lt,{field:l,value:t,setValue:a,loadingState:o,setLoadingState:n,variant:e.variant,allowEditing:e.allowEditing,altDisabledByMetadata:u,setAltDisabledByMetadata:e.variant==="image"&&l.alt!==!1?m:void 0})}I.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,r=e.value?.filename||"",d=Q(r),u=R(r)||d&&s,[m,F]=g(!u),h=ve(e.value?.src);if(e.value?.src!==h.current){h.current=e.value?.src;let p=e.value?.filename||"",b=R(p)||Q(p)&&s;!b&&!m?F(!0):b&&m&&F(!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:()=>F(p=>!p),size:"sm",variant:"outline",className:"FileField__Preview__InfoButton__Icon","aria-label":"Toggle file info",children:i(ut,{size:16})})}),i(T,{shadow:"sm",control:i(X,{variant:"outline",size:"sm",radius:"sm",c:"black",className:"FileField__Preview__InfoButton__Icon",children:i(rt,{size:16})}),children:[e.allowEditing&&i(M,{children:[i(T.Label,{size:"sm",children:"REPLACE"}),i(T.Item,{icon:e.variant==="image"?i(Te,{size:16}):i(Ce,{size:16}),onClick:()=>e.requestFileUpload(),children:["Upload ",e.variant==="image"?"image":"file"]}),Tt(e.acceptedFileTypes)&&i(T.Item,{disabled:!e.value?.src,icon:i(De,{size:16}),onClick:()=>{e.requestPlaceholderModalOpen()},children:"Placeholder image"}),R(e.value?.src)&&!e.value?.src?.endsWith(".svg")&&i(T.Item,{disabled:!e.value?.src,icon:i(st,{size:16}),closeMenuOnClick:!0,onClick:()=>{e.requestImageEditorOpen()},children:"Edit image"}),i(Fe,{})]}),i(T.Item,{disabled:e.value?.src?.startsWith("data:"),onClick:()=>{e?.requestFileDownload()},icon:i(dt,{size:16}),children:"Download file"}),i(T.Item,{closeOnItemClick:!1,icon:i(lt,{size:16}),onClick:()=>{o(!1);let p=e.value?.src||"";Ae(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&&R(e.value?.src||"")&&e.value?.canvasBgColor&&i(T.Item,{icon:e.value?.canvasBgColor==="dark"?i(Ee,{size:16}):i(Ie,{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"}),e.allowEditing&&e.setAltDisabledByMetadata&&i(T.Item,{icon:e.altDisabledByMetadata?i(Ee,{size:16}):i(Ie,{size:16,style:{opacity:.25}}),closeOnItemClick:!1,onClick:()=>{e.setAltDisabledByMetadata?.(!e.altDisabledByMetadata)},children:"Disable alt text"}),i(Fe,{}),i(T.Item,{color:"red",onClick:()=>{e?.removeFile()},icon:i(gt,{size:16}),children:"Remove file"})]})]}),i("div",{className:j("FileField__Canvas",m&&"FileField__Canvas--infoOpened",l&&"dragging"),style:Ht(e.value),onDragOver:p=>{p.preventDefault(),t(!0)},onDragLeave:p=>{p.preventDefault(),t(!1)},onDrop:p=>{p.preventDefault(),t(!1);let b=p.dataTransfer?.files[0];b&&e&&e.handleFile(b)},onPaste:p=>{p.preventDefault();let b=p.clipboardData?.files[0];if(b){e.handleFile(b);return}let S=p.clipboardData?.getData("text/plain");if(S){if(fe(S)){e.handleFile(S);return}if(It(S)){e.handleFile(S,{as:"svg"});return}}},children:[i(Ze,{visible:e.loadingState==="loading"}),m?i("div",{className:"FileField__Canvas__Info",children:[i(pt,{size:16,className:"FileField__Canvas__Info__Icon"}),i(Qe,{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(M,{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(M,{children:[!!(e.value?.width&&e.value?.height)&&i($e,{radius:"sm",className:"FileField__Preview__Info",children:[e.value.width,"x",e.value.height]}),R(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(M,{children:i("video",{className:"FileField__Preview__Image",controls:!0,muted:!0,preload:"metadata",children:i("source",{src:e.value.src,type:`video/${ke(e.value.src)}`})})})]}),e.allowEditing&&i("div",{className:"FileField__reupload",children:i(I.UploadButton,{className:"FileField__reupload__button",compact:!0})})]}),e.allowEditing&&e.showAltText&&(e.altText||Dt(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};I.UploadButton=e=>{let l=ee(),t=l.loadingState==="loading",a=e.compact?14:16;return i(A,{color:"black",variant:"default",disabled:t,size:e.compact?"compact-xs":"compact-md",className:j("FileField__FileUploadButton",e.compact&&"FileField__FileUploadButton--compact"),onClick:()=>{l.requestFileUpload()},leftIcon:i(M,{children:t&&!e.compact?i(We,{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"})};I.InvisibleDropzone=e=>{let[l,t]=g(!1),a=ee();return i("div",{className:j("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})};I.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(I.UploadButton,{}),Tt(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]})})]})};I.Dropzone=_e((e,l)=>{let[t,a]=g(!1),o=ee();return i("button",{ref:l,className:j("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 r=n.clipboardData?.files[0];if(r){o.handleFile(r);return}let d=n.clipboardData?.getData("text/plain");if(d){if(fe(d)){o.handleFile(d);return}if(It(d)){o.handleFile(d,{as:"svg"});return}}},title:"Drop or paste to upload a file"})});var Vt=_e(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 Dt(e){return e?R(e)||Q(e):!1}function Tt(e){return e.some(l=>l.startsWith("image/"))||e.length===0}function Ht(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 jt(e){let l=e.split("."),t=l.pop();return[...l,`@${t}`].join(".")}function It(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{_t as a,Ft as b,q as c,hi as d,mi as e,ge as f,vi as g,bi as h,_i as i,Oe as j,Lt as k,I as l};
@@ -0,0 +1,7 @@
1
+ import{f as k}from"./chunk-5MV6XVGA.js";import{f as b}from"./chunk-RPOP6MVJ.js";import{Ga as a,a as M,c as y,e as z,g as P,j as O}from"./chunk-4CUWZQXT.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 +1 @@
1
- import{f as r}from"./chunk-AL3TN2KI.js";import{Ha as i}from"./chunk-NZHF733K.js";function f(n){let{className:a,as:l,size:t,weight:e,color:o,children:s,...x}=n;return i(l||"div",{...x,className:r(a,"text",t&&`size:${t}`,e&&`weight:${e}`,o&&`color:${o}`),children:s})}export{f as a};
1
+ import{f as r}from"./chunk-RPOP6MVJ.js";import{Ga as i}from"./chunk-4CUWZQXT.js";function f(n){let{className:a,as:l,size:t,weight:e,color:o,children:s,...x}=n;return i(l||"div",{...x,className:r(a,"text",t&&`size:${t}`,e&&`weight:${e}`,o&&`color:${o}`),children:s})}export{f as a};