@blinkk/root-cms 3.1.3 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/app.js +3 -5
  2. package/dist/{chunk-4VZTYUQ7.js → chunk-6CTCV2PN.js} +192 -14
  3. package/dist/{chunk-AFBSITEO.js → chunk-ETHWZSNM.js} +4 -0
  4. package/dist/chunk-MUXSUGFF.js +764 -0
  5. package/dist/cli.js +1 -1
  6. package/dist/client.js +1 -1
  7. package/dist/core/ai-tools.d.ts +82 -42
  8. package/dist/core/ai.d.ts +54 -218
  9. package/dist/core/plugin.d.ts +10 -4
  10. package/dist/core/schema.d.ts +88 -3
  11. package/dist/core.js +1 -1
  12. package/dist/functions.js +2 -3
  13. package/dist/plugin.js +43 -209
  14. package/dist/shared/ai/models.d.ts +110 -0
  15. package/dist/shared/ai/prompt-utils.d.ts +59 -0
  16. package/dist/ui/AIPage-25WICIOT.js +1 -0
  17. package/dist/ui/AssetsPage-WKTM2J2G.js +1 -0
  18. package/dist/ui/CollectionPage-5ZOVG7IG.js +1 -0
  19. package/dist/ui/ComparePage-DDIFYYTK.js +1 -0
  20. package/dist/ui/DataPage-RFNGSDDN.js +1 -0
  21. package/dist/ui/DataSourcePage-U46CDIH2.js +1 -0
  22. package/dist/ui/DocTranslationsPage-BFCM2PE3.js +1 -0
  23. package/dist/ui/DocumentPage-OTBXM55S.js +1 -0
  24. package/dist/ui/EditDataSourcePage-NKKIF6AD.js +1 -0
  25. package/dist/ui/EditReleasePage-TKNOUT7A.js +1 -0
  26. package/dist/ui/EmbeddedAIPage-4AX7VO3T.js +1 -0
  27. package/dist/ui/EmbeddedDocumentPage-2CNQJTW5.js +1 -0
  28. package/dist/ui/{ImageEditorDialog-GGS4VFEA.js → ImageEditorDialog-YDKOGVJV.js} +1 -1
  29. package/dist/ui/LogsPage-SCECIAZH.js +1 -0
  30. package/dist/ui/NewDataSourcePage-FAOPK2RZ.js +1 -0
  31. package/dist/ui/NewReleasePage-HD6T6UV2.js +1 -0
  32. package/dist/ui/{NotFoundPage-WXEZQZK6.js → NotFoundPage-JRYFUENW.js} +1 -1
  33. package/dist/ui/ProjectPage-2WIMWCSX.js +1 -0
  34. package/dist/ui/ReleasePage-GUMEMLF6.js +1 -0
  35. package/dist/ui/ReleasesPage-AW6PICTQ.js +1 -0
  36. package/dist/ui/SettingsPage-KFLNZ356.js +1 -0
  37. package/dist/ui/{SidebarToolsPage-API53RRR.js → SidebarToolsPage-3R7BQ2F7.js} +1 -1
  38. package/dist/ui/TaskPage-GZGPKIL5.js +1 -0
  39. package/dist/ui/TasksPage-G3GBTV3L.js +1 -0
  40. package/dist/ui/TranslationsArbPage-K272JEAA.js +2 -0
  41. package/dist/ui/TranslationsEditPage-XWXPNKRQ.js +1 -0
  42. package/dist/ui/{TranslationsPage-NGGZB4L6.js → TranslationsPage-7KUHVTLK.js} +1 -1
  43. package/dist/ui/ai-tools-7S4URTMT.js +1 -0
  44. package/dist/ui/{chunk-TVYAZN2Q.js → chunk-2FQMT5AB.js} +1 -1
  45. package/dist/ui/{chunk-J5E457OI.js → chunk-2PTLQRTU.js} +1 -1
  46. package/dist/ui/{chunk-UPDL6UXI.js → chunk-2RRM4HEQ.js} +1 -1
  47. package/dist/ui/{chunk-WYJJZTCI.js → chunk-34W6H4YG.js} +1 -1
  48. package/dist/ui/{chunk-4FGASIIX.js → chunk-44ZU5WMI.js} +1 -1
  49. package/dist/ui/{chunk-3E6CASIN.js → chunk-535JU7FU.js} +1 -1
  50. package/dist/ui/chunk-5KSGCGYY.js +1 -0
  51. package/dist/ui/{chunk-ZMS6NIGG.js → chunk-75NMQ3LW.js} +1 -1
  52. package/dist/ui/{chunk-Y3MCFLQU.js → chunk-7UHZS56B.js} +57 -57
  53. package/dist/ui/chunk-AAR7DBEN.js +110 -0
  54. package/dist/ui/{chunk-JS6TK4OP.js → chunk-ATTW36EM.js} +1 -1
  55. package/dist/ui/{chunk-DIFPCF7I.js → chunk-DWV5J2W7.js} +1 -1
  56. package/dist/ui/chunk-DZYYWCHX.js +3 -0
  57. package/dist/ui/chunk-F7RQT4XN.js +1 -0
  58. package/dist/ui/chunk-FVWSVOOY.js +1 -0
  59. package/dist/ui/chunk-GCSN3YEC.js +31 -0
  60. package/dist/ui/{chunk-CAY5NM4Z.js → chunk-H37RXS4R.js} +1 -1
  61. package/dist/ui/{chunk-JTIQBW33.js → chunk-HV3JJ5UT.js} +1 -1
  62. package/dist/ui/{chunk-MSYTAJBV.js → chunk-HXSB6YB2.js} +1 -1
  63. package/dist/ui/chunk-IGZDFHVM.js +1 -0
  64. package/dist/ui/chunk-ISUGBMXC.js +1 -0
  65. package/dist/ui/{chunk-G5ZZDHWA.js → chunk-JBLSUM6W.js} +1 -1
  66. package/dist/ui/{chunk-T77VOWHP.js → chunk-N5RJIILP.js} +1 -1
  67. package/dist/ui/{chunk-BW2MKGNP.js → chunk-NCZD5IWS.js} +1 -1
  68. package/dist/ui/chunk-NXWYS4HG.js +19 -0
  69. package/dist/ui/{chunk-FXIR2RBE.js → chunk-OWBT6YUM.js} +1 -1
  70. package/dist/ui/chunk-OWYV43BT.js +1 -0
  71. package/dist/ui/{chunk-QHJOTXYB.js → chunk-PIJ3E47R.js} +1 -1
  72. package/dist/ui/{chunk-ENQKSLGJ.js → chunk-PLYSJ7W5.js} +1 -1
  73. package/dist/ui/{chunk-FJLNXXE3.js → chunk-QFDU6FXP.js} +1 -1
  74. package/dist/ui/{chunk-P2Z66DHV.js → chunk-QLIIVG5Q.js} +1 -1
  75. package/dist/ui/{chunk-HARRKJFZ.js → chunk-QRAFYIAW.js} +1 -1
  76. package/dist/ui/{chunk-2EPQJUGM.js → chunk-QWB6MAPJ.js} +1 -1
  77. package/dist/ui/{chunk-W6LP22IK.js → chunk-RB23LLKL.js} +1 -1
  78. package/dist/ui/chunk-RN4XVVWD.js +1 -0
  79. package/dist/ui/{chunk-BOER3EAW.js → chunk-SYDHFYRC.js} +1 -1
  80. package/dist/ui/{chunk-NSI5JSVV.js → chunk-T5BJNOWE.js} +1 -1
  81. package/dist/ui/chunk-TNW2GNUR.js +1 -0
  82. package/dist/ui/{chunk-WFQU7V3W.js → chunk-UCYWQEAS.js} +1 -1
  83. package/dist/ui/{chunk-GT5EQSEX.js → chunk-UJX25CXD.js} +1 -1
  84. package/dist/ui/chunk-UPN3EMUS.js +1 -0
  85. package/dist/ui/{chunk-NJMNOITA.js → chunk-VPZHG7JL.js} +1 -1
  86. package/dist/ui/{chunk-BUNR5EU3.js → chunk-WASID5UU.js} +1 -1
  87. package/dist/ui/chunk-WC7KMPEQ.js +1 -0
  88. package/dist/ui/chunk-WRA24P66.js +7 -0
  89. package/dist/ui/{chunk-LROR6N3B.js.LEGAL.txt → chunk-WRA24P66.js.LEGAL.txt} +5 -1
  90. package/dist/ui/chunk-XACLTYBB.js +5 -0
  91. package/dist/ui/{chunk-VD6G5NV4.js → chunk-XOWWPE7X.js} +12 -12
  92. package/dist/ui/chunk-XUBZH4ON.js +1 -0
  93. package/dist/ui/{chunk-QF3GPZTI.js → chunk-Y5EOMMNI.js} +1 -1
  94. package/dist/ui/{chunk-NSOTG64N.js → chunk-YBHFGQ3Z.js} +1 -1
  95. package/dist/ui/chunk-YP6ZH3MT.js +1 -0
  96. package/dist/ui/{chunk-UUVAD4U4.js → chunk-Z3ZJJWFT.js} +1 -1
  97. package/dist/ui/ui.css +1 -1
  98. package/dist/ui/ui.js +1 -1
  99. package/package.json +3 -3
  100. package/dist/chunk-4G7S2LJH.js +0 -1411
  101. package/dist/chunk-AJDMNTZQ.js +0 -187
  102. package/dist/ui/AIPage-VOTAEVJE.js +0 -1
  103. package/dist/ui/AssetsPage-EWGRMRPJ.js +0 -1
  104. package/dist/ui/CollectionPage-N5JIAUDS.js +0 -1
  105. package/dist/ui/ComparePage-JDPVU2VA.js +0 -1
  106. package/dist/ui/DataPage-37D4CMLZ.js +0 -1
  107. package/dist/ui/DataSourcePage-LX5ASYQN.js +0 -1
  108. package/dist/ui/DocTranslationsPage-V5M4KB7X.js +0 -1
  109. package/dist/ui/DocumentPage-SURTQJPG.js +0 -1
  110. package/dist/ui/EditDataSourcePage-O7DOV5LX.js +0 -1
  111. package/dist/ui/EditReleasePage-NDYTKGXY.js +0 -1
  112. package/dist/ui/EmbeddedAIPage-RJOUIPF2.js +0 -1
  113. package/dist/ui/EmbeddedDocumentPage-SLEULNNI.js +0 -1
  114. package/dist/ui/LogsPage-ZGBP3I35.js +0 -1
  115. package/dist/ui/NewDataSourcePage-GQONTMP4.js +0 -1
  116. package/dist/ui/NewReleasePage-7ZKXHDTD.js +0 -1
  117. package/dist/ui/ProjectPage-F7W7X6YO.js +0 -1
  118. package/dist/ui/ReleasePage-ZKMNYPML.js +0 -1
  119. package/dist/ui/ReleasesPage-JHCE6AEJ.js +0 -1
  120. package/dist/ui/SettingsPage-MWCPZPGE.js +0 -1
  121. package/dist/ui/TaskPage-73NLAR4J.js +0 -1
  122. package/dist/ui/TasksPage-IKPW2OQO.js +0 -1
  123. package/dist/ui/TranslationsArbPage-QVN66DIW.js +0 -2
  124. package/dist/ui/TranslationsEditPage-ZOELF5PK.js +0 -1
  125. package/dist/ui/ai-tools-4DWMFQS6.js +0 -1
  126. package/dist/ui/chunk-2RAVKX2Z.js +0 -19
  127. package/dist/ui/chunk-344GZOGG.js +0 -84
  128. package/dist/ui/chunk-4ISFTE2G.js +0 -5
  129. package/dist/ui/chunk-BT2NTAW2.js +0 -1
  130. package/dist/ui/chunk-C2BLMTPR.js +0 -3
  131. package/dist/ui/chunk-D3UIZHRK.js +0 -1
  132. package/dist/ui/chunk-DS27MO63.js +0 -1
  133. package/dist/ui/chunk-HO3W4RVG.js +0 -1
  134. package/dist/ui/chunk-IOR72US3.js +0 -1
  135. package/dist/ui/chunk-KRNQ6L35.js +0 -1
  136. package/dist/ui/chunk-LROR6N3B.js +0 -7
  137. package/dist/ui/chunk-N3JSLTMV.js +0 -1
  138. package/dist/ui/chunk-PPYM4O5N.js +0 -1
  139. package/dist/ui/chunk-TOGLZDK3.js +0 -1
  140. package/dist/ui/chunk-TPJCPCRR.js +0 -1
  141. package/dist/ui/chunk-VPHBKJ3I.js +0 -1
  142. package/dist/ui/chunk-YUU6LWQK.js +0 -1
  143. package/dist/ui/chunk-Z6DBYLIM.js +0 -1
  144. /package/dist/ui/{ImageEditorDialog-GGS4VFEA.js.LEGAL.txt → ImageEditorDialog-YDKOGVJV.js.LEGAL.txt} +0 -0
  145. /package/dist/ui/{chunk-Y3MCFLQU.js.LEGAL.txt → chunk-7UHZS56B.js.LEGAL.txt} +0 -0
  146. /package/dist/ui/{chunk-NJMNOITA.js.LEGAL.txt → chunk-VPZHG7JL.js.LEGAL.txt} +0 -0
  147. /package/dist/ui/{chunk-VD6G5NV4.js.LEGAL.txt → chunk-XOWWPE7X.js.LEGAL.txt} +0 -0
@@ -1 +1 @@
1
- import{c as x,n as y}from"./chunk-VD6G5NV4.js";import{a as d,c as g,j as R}from"./chunk-LROR6N3B.js";var v=3600*1e3,p=new Map,P=new Map,h=new Set;function A(e){return e.trim().toLowerCase()}function E(e){let r=p.get(e);if(r){if(Date.now()-r.fetchedAt>v){p.delete(e);return}return r}}function M(){h.forEach(e=>e())}function T(e){let r=window.firebase.db,s=window.__ROOT_CTX.rootConfig.projectId;return x(r,"Projects",s,"UserProfiles",e)}function a(e){if(!e)return null;let r=E(A(e));return r?r.value:void 0}async function U(e){if(!e)return null;let r=A(e),s=E(r);if(s)return s.value;let n=P.get(r);if(n)return n;let i=(async()=>{try{let t=await y(T(r)),l=t.exists()?t.data():null;return p.set(r,{value:l,fetchedAt:Date.now()}),M(),l}catch(t){return console.error("failed to fetch user profile:",e,t),p.set(r,{value:null,fetchedAt:Date.now()}),null}finally{P.delete(r)}})();return P.set(r,i),i}function b(e){return h.add(e),()=>{h.delete(e)}}function O(e,r){if(!(r||e||"").trim())return"?";if(r){let t=r.trim().split(/\s+/).map(l=>l.replace(/[^a-zA-Z0-9]/g,"")).filter(Boolean);if(t.length>=2)return(t[0][0]+t[1][0]).toUpperCase();if(t.length===1&&t[0].length>0)return t[0].slice(0,2).toUpperCase()}let i=(e.split("@")[0]||e).replace(/[^a-zA-Z0-9]/g,"");return i.length===0?"?":i.slice(0,2).toUpperCase()}function S(e){let r=e.trim();if(!r)return"?";let[s,n=""]=r.split("@"),t=(_(r)?n:s||r).replace(/[^a-zA-Z0-9]/g,"");return t.length===0?"?":t[0].toUpperCase()}function _(e){return e.trim().startsWith("*@")}function z(e){let r=["#1f6feb","#0e7490","#0f766e","#15803d","#9333ea","#c026d3","#db2777","#dc2626","#ea580c","#b45309"],s=0;for(let n=0;n<e.length;n++)s=s*31+e.charCodeAt(n)>>>0;return r[s%r.length]}R();function H(e){let r=e?a(e):null,[s,n]=d(r??null),[i,t]=d(!!e&&r===void 0);return g(()=>{if(!e){n(null),t(!1);return}let l=!1,o=a(e);o!==void 0?(n(o),t(!1)):(t(!0),U(e).then(f=>{l||(n(f),t(!1))}));let c=b(()=>{if(l||!e)return;let f=a(e);f!==void 0&&n(f)});return()=>{l=!0,c()}},[e]),{profile:s,loading:i}}function W(e){let r=e.filter(o=>!!o).map(o=>o.toLowerCase()),s=r.slice().sort().join(","),[n,i]=d(()=>{let o=new Map;return r.forEach(c=>{let f=a(c);f!==void 0&&o.set(c,f)}),o}),[t,l]=d(r.length>0);return g(()=>{if(r.length===0){i(new Map),l(!1);return}let o=!1;function c(){let u=new Map,w=!1;r.forEach(C=>{let m=a(C);m===void 0?w=!0:u.set(C,m)}),i(u),l(w)}c(),Promise.all(r.filter(u=>a(u)===void 0).map(u=>U(u))).then(()=>{o||c()});let f=b(()=>{o||c()});return()=>{o=!0,f()}},[s]),{profiles:n,loading:t}}export{O as a,S as b,_ as c,z as d,H as e,W as f};
1
+ import{c as x,n as y}from"./chunk-XOWWPE7X.js";import{a as d,c as g,j as R}from"./chunk-WRA24P66.js";var v=3600*1e3,p=new Map,P=new Map,h=new Set;function A(e){return e.trim().toLowerCase()}function E(e){let r=p.get(e);if(r){if(Date.now()-r.fetchedAt>v){p.delete(e);return}return r}}function M(){h.forEach(e=>e())}function T(e){let r=window.firebase.db,s=window.__ROOT_CTX.rootConfig.projectId;return x(r,"Projects",s,"UserProfiles",e)}function a(e){if(!e)return null;let r=E(A(e));return r?r.value:void 0}async function U(e){if(!e)return null;let r=A(e),s=E(r);if(s)return s.value;let n=P.get(r);if(n)return n;let i=(async()=>{try{let t=await y(T(r)),l=t.exists()?t.data():null;return p.set(r,{value:l,fetchedAt:Date.now()}),M(),l}catch(t){return console.error("failed to fetch user profile:",e,t),p.set(r,{value:null,fetchedAt:Date.now()}),null}finally{P.delete(r)}})();return P.set(r,i),i}function b(e){return h.add(e),()=>{h.delete(e)}}function O(e,r){if(!(r||e||"").trim())return"?";if(r){let t=r.trim().split(/\s+/).map(l=>l.replace(/[^a-zA-Z0-9]/g,"")).filter(Boolean);if(t.length>=2)return(t[0][0]+t[1][0]).toUpperCase();if(t.length===1&&t[0].length>0)return t[0].slice(0,2).toUpperCase()}let i=(e.split("@")[0]||e).replace(/[^a-zA-Z0-9]/g,"");return i.length===0?"?":i.slice(0,2).toUpperCase()}function S(e){let r=e.trim();if(!r)return"?";let[s,n=""]=r.split("@"),t=(_(r)?n:s||r).replace(/[^a-zA-Z0-9]/g,"");return t.length===0?"?":t[0].toUpperCase()}function _(e){return e.trim().startsWith("*@")}function z(e){let r=["#1f6feb","#0e7490","#0f766e","#15803d","#9333ea","#c026d3","#db2777","#dc2626","#ea580c","#b45309"],s=0;for(let n=0;n<e.length;n++)s=s*31+e.charCodeAt(n)>>>0;return r[s%r.length]}R();function H(e){let r=e?a(e):null,[s,n]=d(r??null),[i,t]=d(!!e&&r===void 0);return g(()=>{if(!e){n(null),t(!1);return}let l=!1,o=a(e);o!==void 0?(n(o),t(!1)):(t(!0),U(e).then(f=>{l||(n(f),t(!1))}));let c=b(()=>{if(l||!e)return;let f=a(e);f!==void 0&&n(f)});return()=>{l=!0,c()}},[e]),{profile:s,loading:i}}function W(e){let r=e.filter(o=>!!o).map(o=>o.toLowerCase()),s=r.slice().sort().join(","),[n,i]=d(()=>{let o=new Map;return r.forEach(c=>{let f=a(c);f!==void 0&&o.set(c,f)}),o}),[t,l]=d(r.length>0);return g(()=>{if(r.length===0){i(new Map),l(!1);return}let o=!1;function c(){let u=new Map,w=!1;r.forEach(C=>{let m=a(C);m===void 0?w=!0:u.set(C,m)}),i(u),l(w)}c(),Promise.all(r.filter(u=>a(u)===void 0).map(u=>U(u))).then(()=>{o||c()});let f=b(()=>{o||c()});return()=>{o=!0,f()}},[s]),{profiles:n,loading:t}}export{O as a,S as b,_ as c,z as d,H as e,W as f};
@@ -1 +1 @@
1
- import{i as t,j as i}from"./chunk-LROR6N3B.js";import{j as r,k as o}from"./chunk-KUCVLANF.js";o();i();var s=r(null);function n(){let e=t(s);if(!e)throw new Error("useFirebase() should be called within a <FirebaseProvider>");return e}export{s as a,n as b};
1
+ import{i as t,j as i}from"./chunk-WRA24P66.js";import{j as r,k as o}from"./chunk-KUCVLANF.js";o();i();var s=r(null);function n(){let e=t(s);if(!e)throw new Error("useFirebase() should be called within a <FirebaseProvider>");return e}export{s as a,n as b};
@@ -1 +1 @@
1
- import{e as n}from"./chunk-BUNR5EU3.js";import{Ga as t}from"./chunk-LROR6N3B.js";function f(a){let{className:r,as:h,size:e,weight:o,color:i,children:g,...s}=a;return t(h||"h2",{...s,className:n(r,"heading",e&&`size:${e}`,o&&`weight:${o}`,i&&`color:${i}`),children:g})}export{f as a};
1
+ import{e as n}from"./chunk-WASID5UU.js";import{Ga as t}from"./chunk-WRA24P66.js";function f(a){let{className:r,as:h,size:e,weight:o,color:i,children:g,...s}=a;return t(h||"h2",{...s,className:n(r,"heading",e&&`size:${e}`,o&&`weight:${o}`,i&&`color:${i}`),children:g})}export{f as a};
@@ -0,0 +1 @@
1
+ import{a as G}from"./chunk-WC7KMPEQ.js";import{a as Y}from"./chunk-F7RQT4XN.js";import{a as J}from"./chunk-DWV5J2W7.js";import{g as W}from"./chunk-TNW2GNUR.js";import{b as O,d as U,e as V,j as $}from"./chunk-FVWSVOOY.js";import{a as A}from"./chunk-JDW4UORS.js";import{a as K}from"./chunk-UJX25CXD.js";import{c as L}from"./chunk-RN4XVVWD.js";import{a as q}from"./chunk-W5DOO6ID.js";import{a as j}from"./chunk-YBHFGQ3Z.js";import{b as B}from"./chunk-2PTLQRTU.js";import{a as S}from"./chunk-PIJ3E47R.js";import{d as M}from"./chunk-WASID5UU.js";import{$ as C,Fa as N,Ga as e,Qa as H,Vc as y,W as x,a as d,c as w,da as I,e as z,j as le,na as k,pa as E,ua as T}from"./chunk-WRA24P66.js";le();function F(o){let{route:c}=M(),f=z(null),[l,i]=d(!1),[v,u]=d(""),[p,_]=d(!!o.releaseId),[Q,P]=d(null),[R,b]=d([]),[g,h]=d([]),X=J(),Z=G(),{roles:ee}=j(),oe=window.firebase.user.email||"",m=q(ee,oe);async function ae(r){console.log(r),await B(async()=>{let t=await U(r);P(t),b(t?.docIds||[]),h(t?.dataSourceIds||[])}),_(!1)}w(()=>{o.releaseId&&(_(!0),ae(o.releaseId))},[o.releaseId]);async function se(){u("");let r=f.current;function t(n){let D=r.elements[n];return D?D.value.trim():""}let a=o.releaseId||t("id");if(!a){u("missing id");return}if(!A(a)){u("id is invalid (alphanumeric characters and dashes only)");return}let s={id:a,description:t("description"),docIds:R,dataSourceIds:g};try{P(s),i(!0),o.releaseId?(await V(o.releaseId,s),S({title:"Saved release",message:`Updated ${a}`,autoClose:5e3}),i(!1)):(await O(a,s),S({title:"Added release",message:`Successfully added ${a}`,autoClose:5e3}),i(!1)),c(`/cms/releases/${a}`)}catch(n){console.error(n),S({title:"Failed to save release",message:String(n),color:"red",autoClose:!1}),i(!1)}}function re(){X.open({multiSelect:!0,selectedDocIds:R,onChangeMulti:(r,t)=>{b(a=>{let s=[...a];if(t)s.push(r);else{let n=s.findIndex(D=>D===r);n>-1&&s.splice(n,1)}return console.log(s),s.sort()})}})}function te(){Z.open({selectedDataSourceIds:g,onChange:(r,t)=>{h(a=>{let s=[...a];if(t)s.push(r);else{let n=s.indexOf(r);n>-1&&s.splice(n,1)}return s.sort()})}})}function ie(r){console.log("onRemoveDoc()",r),b(t=>{let a=[...t],s=a.indexOf(r);return s!==-1&&a.splice(s,1),console.log(a),a})}function ne(r){h(t=>{let a=[...t],s=a.indexOf(r);return s!==-1&&a.splice(s,1),a})}return e("form",{className:"ReleaseForm",ref:f,onSubmit:r=>{r.preventDefault(),se()},children:[e(E,{visible:p}),e(T,{className:"ReleaseForm__input",name:"id",label:"ID",description:"Unique identifier for the release. Use alphanumeric characters and dashes only, e.g. grogus-favorite-meals",size:"xs",radius:0,defaultValue:o.releaseId||$(),disabled:!!o.releaseId}),e(k,{className:"ReleaseForm__input",name:"description",label:"Description",description:"Optional.",size:"xs",radius:0,value:Q?.description,disabled:!m}),e(C,{className:"ReleaseForm__input",label:"Docs",description:"Select one or more docs to add to the release. Note: you can add or edit this list at a later time, if needed.",size:"xs",children:[R.length>0&&e(F.DocPreviewCards,{docIds:R,onRemoveDoc:ie,canEdit:m}),e(I,{className:"ReleaseForm__docSelectButton",color:"dark",size:"xs",onClick:()=>re(),disabled:!m,children:"Select"})]}),e(C,{className:"ReleaseForm__input",label:"Data Sources",description:"Optional. Data sources to publish with the release.",size:"xs",children:[g.length>0&&e(F.DataSourceIds,{ids:g,onRemove:ne,canEdit:m}),e(I,{className:"ReleaseForm__docSelectButton",color:"dark",size:"xs",onClick:()=>te(),disabled:!m,children:"Select"})]}),e("div",{className:"ReleaseForm__submit__buttons",children:e(K,{label:"You don't have access to create or edit releases",condition:!m,children:e("span",{children:e(I,{className:"ReleaseForm__submit",color:"blue",size:"xs",type:"submit",loading:l,disabled:!m,children:o.buttonLabel||"Save"})})})}),v&&e("div",{className:"ReleaseForm__error",children:["Error: ",v]})]})}F.DocPreviewCards=o=>e("div",{className:"ReleaseForm__DocPreviewCards",children:o.docIds.map(c=>e("div",{className:"ReleaseForm__DocPreviewCards__card",children:[e(W,{className:"ReleaseForm__DocPreviewCards__card__preview",docId:c}),e("div",{className:"ReleaseForm__DocPreviewCards__card__controls",children:[o.canEdit&&e("div",{className:"ReleaseForm__DocPreviewCards__card__controls__remove",children:e(N,{label:"Remove",children:e(x,{className:"ReleaseForm__DocPreviewCards__card__controls__remove__icon",onClick:()=>o.onRemoveDoc(c),children:e(y,{size:16})})})}),e("div",{className:"ReleaseForm__DocPreviewCards__card__controls__open",children:e(N,{label:"Open",children:e(x,{component:"a",className:"ReleaseForm__DocPreviewCards__card__controls__open__icon",href:`/cms/content/${c}`,target:"_blank",children:e(H,{size:16})})})})]})]},c))});F.DataSourceIds=o=>{let[c,f]=d({});return w(()=>{let l=!1;async function i(){let v=await Promise.all(o.ids.map(async p=>{let _=await L(p);return[p,_]}));if(l)return;let u={};for(let[p,_]of v)_&&(u[p]=_);f(u)}return i(),()=>{l=!0}},[o.ids.join(",")]),e("div",{className:"ReleaseForm__DataSourceIds",children:o.ids.map(l=>{let i=c[l];return e("div",{className:"ReleaseForm__DataSourceIds__item",children:[e(Y,{className:"ReleaseForm__DataSourceIds__item__icon",type:i?.type}),e("div",{className:"ReleaseForm__DataSourceIds__item__info",children:[e("div",{className:"ReleaseForm__DataSourceIds__item__id",children:l}),i?.description&&e("div",{className:"ReleaseForm__DataSourceIds__item__description",children:i.description})]}),o.canEdit&&e(x,{className:"ReleaseForm__DataSourceIds__item__remove",onClick:()=>o.onRemove(l),children:e(y,{size:16})})]},l)})})};export{F as a};
@@ -0,0 +1 @@
1
+ import{a as se,g as oe,h as X,i as ne,j as ie,m as re}from"./chunk-DZYYWCHX.js";import{D as p,a as k,b as F,c as l,f as Y,g as x,h as D,i as O,j as M,l as Z,n as B,o as j,p as v,q as w,r as ee,t as N,u as R,v as m,w as te,x as T}from"./chunk-XOWWPE7X.js";import{k as U}from"./chunk-7SK47HHZ.js";function ce(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null}function ae(e){return ce(e)&&Array.isArray(e.blocks)&&e.blocks.length>0}var q=new Map,E=new Map;function De(e){return q.get(e)||null}async function Je(e){let t=De(e);if(t)return t;let s=E.get(e);if(s)return s;let n=(async()=>{let o=b(e),r=(await B(o)).data();return Ce(e,r),r})().finally(()=>{E.delete(e)});return E.set(e,n),n}function Ce(e,t){q.set(e,t)}function G(e){q.delete(e),E.delete(e)}function L(e){for(let t of e)G(t)}function le(e){e||(e=6);let t=[],s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=s.length;for(let o=0;o<e;o++)t.push(s.charAt(Math.floor(Math.random()*n)));return t.join("")}var P=class extends Error{},de=200,Te=/[/\\\u0000-\u001f]/;function C(){let e=window.__ROOT_CTX.rootConfig.projectId,t=window.firebase.db;return F(t,"Projects",e,"Assets")}var Be="root-cms:assetPicker:lastFolder";function me(){let e=window.__ROOT_CTX.rootConfig.projectId;return`${Be}:${e}`}function ct(){try{return localStorage.getItem(me())||""}catch{return""}}function at(e){try{localStorage.setItem(me(),e||"")}catch{}}function Q(e){let t=(e||"").trim();if(!t)throw new P("Name is required.");if(t.length>de)throw new P(`Name is too long (max ${de} chars).`);if(Te.test(t))throw new P("Name cannot contain slashes.");if(t==="."||t==="..")throw new P("Invalid name.");return t}function _(e,t){return e?`${e}/${t}`:t}function lt(e){return e?e.split("/").filter(Boolean):[]}function V(e){return`folder-${encodeURIComponent(e)}`}function pe(e){return e.sort((t,s)=>t.type!==s.type?t.type==="folder"?-1:1:(t.name||"").localeCompare(s.name||"",void 0,{numeric:!0,sensitivity:"base"}))}function ge(e){return!!e&&typeof e.name=="string"&&(e.type==="file"||e.type==="folder")}async function je(e){let t=C(),s=x(t,D("parent","==",e||"")),n=await j(s),o=[];return n.forEach(i=>{let r=i.data();ge(r)&&o.push(r)}),pe(o)}var fe=1e3;async function dt(e){let t=C(),s;e?s=x(t,D("parent",">=",e),D("parent","<=",`${e}\uF8FF`),M(fe)):s=x(t,M(fe));let n=await j(s),o=[];return n.forEach(i=>{let r=i.data();ge(r)&&(!e||K(r.parent,e))&&o.push(r)}),pe(o)}function ft(e,t){return t?e===t?"":e.startsWith(`${t}/`)?e.slice(t.length+1):e:e}async function I(e){let t=l(C(),e),s=await B(t);return s.exists()?s.data():null}async function ut(e,t){let s=Q(t),n=_(e,s),o=V(n),i=l(C(),o),r={id:o,type:"folder",parent:e||"",name:s,createdAt:m(),createdBy:window.firebase.user.email,modifiedAt:m(),modifiedBy:window.firebase.user.email};return await v(i,r,{merge:!0}),p("asset.folder_create",{metadata:{folder:n}}),await I(o)}async function mt(e){let t=J(e.file),s=Q(e.name||t.filename||Pe(t.src)),n=le(12),o=l(C(),n);return await v(o,{id:n,type:"file",parent:e.parent||"",name:s,file:t,createdAt:m(),createdBy:window.firebase.user.email,modifiedAt:m(),modifiedBy:window.firebase.user.email}),p("asset.upload",{metadata:{assetId:n,name:s}}),await I(n)}async function pt(e,t){let s=Q(t);if(s===e.name)return;if(e.type==="folder"){let o=_(e.parent,e.name),i=_(e.parent,s);await ye(e,i,s,e.parent),p("asset.rename",{metadata:{from:o,to:i}});return}let n=l(C(),e.id);await w(n,{name:s,modifiedAt:m(),modifiedBy:window.firebase.user.email}),p("asset.rename",{metadata:{assetId:e.id,from:e.name,to:s}})}async function gt(e,t){let s=t||"";if(s===e.parent)return;if(e.type==="folder"){let o=_(e.parent,e.name),i=_(s,e.name);if(i===o||K(i,o))throw new Error("Cannot move a folder into itself.");await ye(e,i,e.name,s),p("asset.move",{metadata:{from:o,to:i}});return}let n=l(C(),e.id);await w(n,{parent:s,modifiedAt:m(),modifiedBy:window.firebase.user.email}),p("asset.move",{metadata:{assetId:e.id,from:e.parent,to:s}})}function K(e,t){return e===t||e.startsWith(`${t}/`)}async function ye(e,t,s,n){let o=_(e.parent,e.name),i=C(),r=window.firebase.db,c=x(i,D("parent",">=",o),D("parent","<=",`${o}\uF8FF`)),a=await j(c),f=[];a.forEach(h=>{let A=h.data();K(A.parent,o)&&f.push(A)});let d=T(r),g=0,y=async()=>{g+=1,g>=400&&(await d.commit(),d=T(r),g=0)},u=V(t);d.set(l(i,u),{id:u,type:"folder",parent:n,name:s,createdAt:e.createdAt??m(),createdBy:e.createdBy??window.firebase.user.email,modifiedAt:m(),modifiedBy:window.firebase.user.email}),await y();for(let h of f){let A=t+h.parent.slice(o.length);if(h.type==="folder"){let S=_(A,h.name);d.set(l(i,V(S)),{...h,id:V(S),parent:A,modifiedAt:m(),modifiedBy:window.firebase.user.email}),await y(),d.delete(l(i,h.id)),await y()}else d.update(l(i,h.id),{parent:A,modifiedAt:m(),modifiedBy:window.firebase.user.email}),await y()}u!==e.id&&(d.delete(l(i,e.id)),g+=1),g>0&&await d.commit()}async function yt(e){if(e.type==="folder"){let t=_(e.parent,e.name);if((await je(t)).length>0)throw new Error("Folder is not empty.")}await ee(l(C(),e.id)),p("asset.delete",{metadata:{assetId:e.id,name:e.name}})}async function ht(e,t){let s=J(t);!s.alt&&e.file?.alt&&(s.alt=e.file.alt),e.file?.altDisabled&&(s.altDisabled=!0);let n=l(C(),e.id),o={file:s,modifiedAt:m(),modifiedBy:window.firebase.user.email},i=U(s.filename||s.src||""),r=_e(e.name,i);return r!==e.name&&(o.name=r),await w(n,o),p("asset.replace",{metadata:{assetId:e.id,name:e.name}}),await I(e.id)}function _e(e,t){let s=(e||"").lastIndexOf(".");return!t||s<=0||U(e)===t?e:`${e.slice(0,s)}.${t}`}async function wt(e,t){let s=l(C(),e.id);return await w(s,{"file.alt":t||"",modifiedAt:m(),modifiedBy:window.firebase.user.email}),await I(e.id)}async function bt(e,t){let s=l(C(),e.id);return await w(s,{"file.altDisabled":t?!0:R(),modifiedAt:m(),modifiedBy:window.firebase.user.email}),p("asset.alt_disabled",{metadata:{assetId:e.id,name:e.name,disabled:t}}),await I(e.id)}function ke(e){let t={...J(e.file),assetId:e.id};return t.altDisabled&&(t.alt=""),t}function z(e){let t=new Set;return H(e,t),Array.from(t).sort()}function H(e,t){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let s of e)H(s,t);return}if(typeof e.toMillis!="function"){if(W(e)){t.add(e.assetId);return}for(let s of Object.keys(e))H(e[s],t)}}}function W(e){return typeof e?.assetId=="string"&&typeof e?.src=="string"}function ue(e){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let t of e)if(ue(t))return!0;return!1}if(typeof e.toMillis=="function")return!1;if(W(e))return!0;for(let t of Object.keys(e))if(ue(e[t]))return!0;return!1}async function Fe(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,n=Object.keys(window.__ROOT_CTX.collections||{});return(await Promise.all(n.map(async r=>{let c=F(s,"Projects",t,"Collections",r,"Drafts"),a=x(c,D("sys.assets","array-contains",e)),f=await j(a),d=[];return f.forEach(g=>{d.push(g.data())}),d}))).flat().sort((r,c)=>r.id.localeCompare(c.id))}async function At(e,t={}){let s=window.__ROOT_CTX.rootConfig.projectId,n=window.firebase.db,o=t.docs??await Fe(e.id),i=[],r=[];for(let c of o){let a=[];if(he(c.fields,e.id,"fields",a),a.length===0)continue;let f={};for(let u of a)f[u.path]=Me(e,u.value,t.previousFile);f["sys.modifiedAt"]=m(),f["sys.modifiedBy"]=window.firebase.user.email;let[d,g]=c.id.split("/"),y=l(n,"Projects",s,"Collections",d,"Drafts",g);try{await w(y,f),i.push(c.id)}catch(u){console.error(`failed to sync asset ${e.id} to ${c.id}:`,u),r.push(c.id)}}return i.length>0&&(L(i),p("asset.sync",{metadata:{assetId:e.id,name:e.name,docIds:i}})),{updatedDocIds:i,failedDocIds:r}}function he(e,t,s,n){if(!(!e||typeof e!="object")&&!Array.isArray(e)&&typeof e.toMillis!="function"){if(W(e)){e.assetId===t&&n.push({path:s,value:e});return}for(let o of Object.keys(e))he(e[o],t,`${s}.${o}`,n)}}function Me(e,t,s){let n=ke(e);if(!e.file?.altDisabled){let i=s?.alt??e.file?.alt??"",r=t?.alt||"";r&&r!==i&&(n.alt=r)}let o=s?.canvasBgColor??e.file?.canvasBgColor;return t?.canvasBgColor&&t.canvasBgColor!==o&&(n.canvasBgColor=t.canvasBgColor),n}function J(e){let t={};return Object.entries(e||{}).forEach(([s,n])=>{n!==void 0&&(t[s]=n)}),t}function Pe(e){return(e||"").split("?")[0].split("/").pop()||"untitled"}async function Pt(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/"),i=l(s,"Projects",t,"Collections",n,"Drafts",o),r=l(s,"Projects",t,"Collections",n,"Published",o),c=l(s,"Projects",t,"Collections",n,"Scheduled",o),a=T(s);a.delete(i),a.delete(r),a.delete(c),await a.commit(),console.log(`deleted doc: ${e}`),p("doc.delete",{metadata:{docId:e}})}async function vt(e,t){await ve([e],t)}async function ve(e,t){if(e.length===0){console.log("no docs to publish");return}let s=window.firebase.db;if(e.length>100)throw new Error("publish docs exceeds limit of 100 docs. break up your request into multiple calls.");let n=await $e(e),o=t?.batch||T(s),i=["published"];t?.releaseId&&i.push(`release:${t.releaseId}`),e.forEach(r=>{let c=n[r];if(!c)throw new Error(`doc does not exist: ${r}`);Ie(o,r,c,i,t?.publishMessage)}),await o.commit(),e.length===1?console.log(`published ${e[0]}`):console.log(`published ${e.length} docs: ${e.join(", ")}`);for(let r of e){let c={docId:r};t?.publishMessage&&(c.publishMessage=t.publishMessage),p("doc.publish",{metadata:c})}L(e)}function Ie(e,t,s,n,o){if(Oe(s))throw new Error(`publishing is locked for doc: ${s.id}`);if(Se(s))throw new Error(`cannot publish archived doc: ${s.id}`);let i=window.__ROOT_CTX.rootConfig.projectId,r=window.firebase.db,[c,a]=t.split("/"),f=l(r,"Projects",i,"Collections",c,"Drafts",a),d=l(r,"Projects",i,"Collections",c,"Scheduled",a),g=l(r,"Projects",i,"Collections",c,"Published",a),y={...s},u=y.sys??{};u.modifiedAt=m(),u.modifiedBy=window.firebase.user.email,u.publishedAt=m(),u.publishedBy=window.firebase.user.email,u.firstPublishedAt??=m(),u.firstPublishedBy??=window.firebase.user.email,delete u.scheduledAt,delete u.scheduledBy,e.update(f,{sys:u}),e.set(g,{...y,sys:u}),e.delete(d);let h=l(r,"Projects",i,"Collections",c,"Drafts",a,"Versions",String(Date.now())),A={id:t,collection:c,slug:a,fields:y.fields||{},sys:u};n?.length&&(A.tags=n),o&&(A.publishMessage=o),e.set(h,A)}async function It(e,t,s){let n=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,[i,r]=e.split("/"),c=l(o,"Projects",n,"Collections",i,"Drafts",r),a=l(o,"Projects",n,"Collections",i,"Scheduled",r);await N(o,async d=>{let g=await d.get(c);if(!g.exists())throw new Error(`${c.id} does not exist`);let y={...g.data()},u=y.sys??{};u.modifiedAt=m(),u.modifiedBy=window.firebase.user.email,u.scheduledAt=k.fromMillis(t),u.scheduledBy=window.firebase.user.email,d.update(c,{sys:u});let h={...y,sys:u};s?.publishMessage&&(h.scheduledPublishMessage=s.publishMessage),d.set(a,h)}),console.log(`saved ${a.id}`);let f={docId:e,scheduledAt:t};s?.publishMessage&&(f.publishMessage=s.publishMessage),p("doc.schedule",{metadata:f})}async function St(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/"),i=l(s,"Projects",t,"Collections",n,"Drafts",o),r=l(s,"Projects",t,"Collections",n,"Scheduled",o),c=l(s,"Projects",t,"Collections",n,"Published",o),a=T(s);a.update(i,{"sys.modifiedAt":m(),"sys.modifiedBy":window.firebase.user.email,"sys.publishedAt":R(),"sys.publishedBy":R(),"sys.firstPublishedAt":R(),"sys.firstPublishedBy":R()}),a.delete(r),a.delete(c),await a.commit(),console.log(`unpublished ${e}`),p("doc.unpublish",{metadata:{docId:e}}),G(e)}async function Ot(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/"),i=l(s,"Projects",t,"Collections",n,"Drafts",o),r=l(s,"Projects",t,"Collections",n,"Published",o);await N(s,async c=>{let a=await c.get(r);if(!a.exists())throw new Error(`${r.id} does not exist`);let f=a.data();c.set(i,f)}),console.log(`reverted draft ${e}`),p("doc.revert",{metadata:{docId:e}})}async function Et(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/"),i=l(s,"Projects",t,"Collections",n,"Drafts",o),r=l(s,"Projects",t,"Collections",n,"Scheduled",o),c=T(s);c.update(i,{"sys.modifiedAt":m(),"sys.modifiedBy":window.firebase.user.email,"sys.scheduledAt":R(),"sys.scheduledBy":R()}),c.delete(r),await c.commit(),console.log(`unscheduled ${e}`),p("doc.unschedule",{metadata:{docId:e}})}async function Lt(e,t){let s={lockedAt:m(),lockedBy:window.firebase.user.email,reason:t.reason||`Locked by ${window.firebase.user.email}.`};t.until&&(s.until=k.fromMillis(t.until));let n=b(e);await w(n,{"sys.publishingLocked":s});let i={docId:e,reason:t.reason};t.until&&(i.until=t.until),p("doc.lock_publishing",{metadata:i})}async function Vt(e){let t=b(e),s={"sys.publishingLocked":R()};await w(t,s),p("doc.unlock_publishing",{metadata:{docId:e}})}async function $t(e){let t=b(e);await w(t,{"sys.archivedAt":m(),"sys.archivedBy":window.firebase.user.email}),p("doc.archive",{metadata:{docId:e}})}async function Nt(e){let t=b(e);await w(t,{"sys.archivedAt":R(),"sys.archivedBy":R()}),p("doc.unarchive",{metadata:{docId:e}})}function Se(e){return!!e?.sys?.archivedAt}function Ut(e){let t=k.now().toMillis();return(e?.sys?.scheduledAt?.toMillis()||0)>t}function Oe(e){if(e?.sys?.publishingLocked){if(e.sys.publishingLocked.until){let t=k.now().toMillis(),s=e.sys.publishingLocked.until.toMillis();return t<s}return!0}return!1}async function Xt(e,t,s){let n=b(e),o=await B(n);if(!o.exists())throw new Error(`doc ${e} does not exist`);let i=o.data(),r=i.fields??{},c=i.sys?.locales;await Ee(t,{fields:r,locales:c,overwrite:s?.overwrite})}async function Ee(e,t){let[s,n]=e.split("/"),o=b(e),i=await B(o);if(i.exists()&&!t?.overwrite)throw new Error(`${e} already exists`);let r=t?.fields??{},c={id:e,collection:s,slug:n,sys:{createdAt:m(),createdBy:window.firebase.user.email,modifiedAt:m(),modifiedBy:window.firebase.user.email,locales:t?.locales??["en"]},fields:r};if(i.exists()&&t?.overwrite){let f=i.data();c.sys={...f.sys,locales:t?.locales??f.sys.locales,modifiedAt:m(),modifiedBy:window.firebase.user.email}}let a=z(r);a.length>0?c.sys.assets=a:delete c.sys.assets,await v(o,c),p("doc.create",{metadata:{docId:e}})}async function qt(e,t,s){let n={};for(let d of t){if(!d.source)continue;let g={source:X(d.source)},y={},u={};Object.entries(d).forEach(([A,S])=>{if(A==="source")return;let xe=ie(A);for(let $ of re(A)){if(ne($))continue;let Re=$===xe?u:y;Re[$]=X(S||"")}}),Object.assign(g,y,u);let h=await oe(g.source);n[h]=g}let i=[e.split("/")[0],e];s?.tags&&i.push(...s.tags);let r=se(),c=window.firebase.db,a=T(c),f=0;for(let d in n){let g=n[d],y=l(r,d);a.set(y,{...g,tags:te(...i)},{merge:!0}),f+=1,f>=500&&(await a.commit(),a=T(c),console.log(`saved ${f} strings`),f=0)}return f>0&&(await a.commit(),console.log(`saved ${f} strings`)),p("doc.import_translations",{metadata:{docId:e,...s?.actionMetadata},links:s?.actionLinks}),n}function b(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/");return l(s,"Projects",t,"Collections",n,"Drafts",o)}function Le(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,[n,o]=e.split("/");return l(s,"Projects",t,"Collections",n,"Published",o)}function Ve(e,t){let s=window.__ROOT_CTX.rootConfig.projectId,n=window.firebase.db,[o,i]=e.split("/");return l(n,"Projects",s,"Collections",o,"Drafts",i,"Versions",t)}async function $e(e){let t=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,n={};e.forEach(i=>{let[r,c]=i.split("/");r in n?n[r].push(c):n[r]=[c]});let o={};return await Promise.all(Object.entries(n).map(async([i,r])=>{let c=F(s,"Projects",t,"Collections",i,"Drafts"),a=x(c,D(Y(),"in",r));(await j(a)).forEach(d=>{let g=`${i}/${d.id}`;o[g]=d.data()})})),o}async function Gt(e,t){let s=window.firebase.db,n=b(e),o=F(s,n.path,"Versions"),i=t?.limit??50,r=x(o,O("sys.modifiedAt","desc"),M(i));t?.tags&&(r=x(r,D("tags","array-contains-any",t.tags))),t?.cursor&&(r=x(r,Z(t.cursor)));let c=await j(r),a=[],f=null;return c.forEach(d=>{let g={...d.data(),_versionId:d.id};a.push(g),f=d}),{versions:a,lastDoc:f,hasMore:c.size===i}}async function Ht(e,t){let s=b(e),n={"sys.modifiedAt":m(),"sys.modifiedBy":window.firebase.user.email,"sys.assets":z(t.fields||{}),fields:t.fields||{}};await w(s,n),p("doc.restore_version",{metadata:{docId:e,versionModifiedAt:t.sys?.modifiedAt,versionModifiedBy:t.sys?.modifiedBy}})}var Ne=/^(before|after):(\d+)$/,Ue=10*1e3;async function Xe(e,t){let s=String(t).match(Ne);if(s)return await qe(e,s[1],parseInt(s[2]));let n;t==="draft"?n=b(e):t==="published"?n=Le(e):n=Ve(e,t);let o=await B(n);return o.exists()?o.data():null}async function qe(e,t,s){let n=window.firebase.db,o=b(e),i=F(n,o.path,"Versions"),r=k.fromMillis(s-Ue),c;t==="before"?c=x(i,D("sys.modifiedAt","<",r),O("sys.modifiedAt","desc"),M(1)):c=x(i,D("sys.modifiedAt",">=",r),O("sys.modifiedAt","asc"),M(1));let a=await j(c);return a.empty?t==="after"?await Xe(e,"draft"):null:a.docs[0].data()}async function Qt(e,t){if(!t?.spreadsheetId)throw new Error("no spreadsheet id");let s=b(e),n={"sys.l10nSheet":{spreadsheetId:t.spreadsheetId,gid:t.gid||0,linkedAt:m(),linkedBy:window.firebase.user.email}};await w(s,n),p("doc.link_sheet",{metadata:{docId:e,sheetId:t}})}async function Kt(e){let t=b(e),s={"sys.l10nSheet":R()};await w(t,s),p("doc.unlink_sheet",{metadata:{docId:e}})}async function zt(e){let t=b(e),o=(await B(t)).data()?.sys?.l10nSheet||{};return o?.spreadsheetId?{spreadsheetId:o.spreadsheetId,gid:o.gid||0}:null}function we(e,t){let s={};for(let n in e){let o=e[n];if(Ae(o))if(o.toMillis)s[n]=o.toMillis();else if(Object.hasOwn(o,"_array")&&Array.isArray(o._array)){let i=o._array.map(r=>{let c={...we(o[r]||{},t),_arrayKey:r};return t?.removeArrayKey&&delete c._arrayKey,c});s[n]=i}else s[n]=we(o,t);else s[n]=o}return s}async function Wt(e,t){let s=await window.fetch("/cms/api/ai.diff",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({docId:e,beforeVersion:t?.beforeVersion||"published",afterVersion:t?.afterVersion||"draft"})}),n=await s.text(),o=null;try{o=JSON.parse(n)}catch{}if(!s.ok||o?.success===!1){let i=o&&(o.error||o.message)||n;throw new Error(i||"Failed to fetch AI summary")}return typeof o?.summary=="string"?o.summary:typeof o?.data?.summary=="string"?o.data.summary:!o&&n?n:""}function Ae(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null}function Jt(e){let[t,s]=e.split("/");return{id:e,collection:t,slug:s}}function be(e){if(Ge(e))return k.fromMillis(e.seconds*1e3);if(ae(e))return e.time=Date.now(),e;if(Array.isArray(e))return e.map(t=>be(t));if(Ae(e)){let t={};return Object.keys(e).forEach(s=>{t[s]=be(e[s])}),t}return e}function Ge(e){return e?.type==="firestore/timestamp/1.0"}export{ae as a,Je as b,Ce as c,le as d,ct as e,at as f,_ as g,lt as h,je as i,dt as j,ft as k,I as l,ut as m,mt as n,pt as o,gt as p,yt as q,ht as r,_e as s,wt as t,bt as u,ke as v,z as w,ue as x,Fe as y,At as z,Pt as A,vt as B,ve as C,It as D,St as E,Ot as F,Et as G,Lt as H,Vt as I,$t as J,Nt as K,Se as L,Ut as M,Oe as N,Xt as O,Ee as P,qt as Q,$e as R,Gt as S,Ht as T,Xe as U,Qt as V,Kt as W,zt as X,we as Y,Wt as Z,Jt as _,be as $};
@@ -1 +1 @@
1
- import{a as mt,b as ut,c as gt}from"./chunk-UPDL6UXI.js";import{a as pt}from"./chunk-ENQKSLGJ.js";import{g as oe,h as Ke,i as Me,j as Ze,k as Je,l as Qe,m as Ye,n as et,o as tt,p as st,q as ce,r as ot,s as Fe,t as at,u as me,y as _e,z as fe}from"./chunk-Z6DBYLIM.js";import{a as ft}from"./chunk-W5DOO6ID.js";import{a as _t}from"./chunk-NSOTG64N.js";import{b as M}from"./chunk-J5E457OI.js";import{a as A,b as He,c as Oe}from"./chunk-QHJOTXYB.js";import{b as Ve,d as Ce}from"./chunk-KRNQ6L35.js";import{e as ue}from"./chunk-BUNR5EU3.js";import{$a as Ne,Ab as he,Cc as dt,Da as re,Db as it,Eb as ve,Fa as Ge,Fb as ze,Ga as e,Pb as rt,Rc as W,Uc as ct,V as te,W as se,a as i,c as U,da as g,ea as G,g as $e,j as Le,lb as ge,mc as Ie,na as je,qa as k,ra as S,tb as De,ua as H,vb as pe,wb as lt,zb as nt}from"./chunk-LROR6N3B.js";import{d as C}from"./chunk-KUCVLANF.js";import{g as We,h as de,k as D,l as O,m as ke,n as V,o as Xe,p as qe}from"./chunk-7SK47HHZ.js";Le();Le();function ht(t){let o=t.file||{},a=o.src||"",l=o.filename||a,r={"--asset-thumb-size":`${t.size}px`};if(a&&O(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("img",{src:Te(o,t.size*2),alt:o.alt||"",loading:"lazy"})});if(a&&V(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("video",{src:a,muted:!0,playsInline:!0,preload:"metadata"})});let m=D(l);return e("div",{className:"AssetBrowser__thumb",style:r,children:m&&m.length<=4?e("div",{className:"AssetBrowser__thumb__ext",children:m}):e(he,{size:20,stroke:"1.5"})})}function Te(t,o){let a=t?.src||"";return a.startsWith(We)&&o?`${a}=s${o}`:a}function we(t){let o=t?.src||"";ke(o)&&(o=o.split("=")[0]+"=s0"),navigator.clipboard.writeText(o).then(()=>{A({message:"Copied URL to clipboard.",autoClose:2e3})})}function be(t){let o=t?.src||"";if(o)if(ke(o)){let a=document.createElement("a");a.href=qe(o),t.filename&&(a.download=t.filename),document.body.appendChild(a),a.click(),document.body.removeChild(a)}else window.open(o,"_blank")}function vt(t){let[o,a]=i(t.asset),[l,r]=i(t.asset.file?.alt||""),[m,d]=i(!1),[x,v]=i(!1),[f,B]=i(null),[w,F]=i(null),n=o.file||{},u=n.filename||o.name,N=O(u),R=V(u),X=l!==(n.alt||""),q=n.altDisabled===!0;U(()=>{_e(o.id).then(c=>F(c)).catch(c=>{console.error("failed to fetch asset usage:",c),F([])})},[o.id]);async function z(c,b){let p=await fe(c,{previousFile:b});p.failedDocIds.length>0?A({title:"Some docs failed to update",message:`Failed to update: ${p.failedDocIds.join(", ")}. Re-save the asset to retry.`,color:"red",autoClose:!1}):p.updatedDocIds.length>0&&A({message:`Updated ${p.updatedDocIds.length} doc(s) that use this asset.`,color:"green"})}async function K(){d(!0),await M(async()=>{let c={...n},b=await at(o,l);a(b),t.onChanged(b),await z(b,c)}),d(!1)}function E(){let c=document.createElement("input");c.type="file",c.onchange=()=>{let b=c.files?.[0];if(!b)return;let p=D(u),y=D(b.name);if(p&&y&&p!==y){B(b);return}$(b)},c.click(),c.remove()}async function $(c){B(null),d(!0),await M(async()=>{let b={...n},p=await de(c),y=await ot(o,p);a(y),r(y.file?.alt||""),t.onChanged(y),await z(y,b)}),d(!1)}async function P(c){d(!0),await M(async()=>{let b={...n},p=await me(o,c);a(p),r(p.file?.alt||""),t.onChanged(p),await z(p,b)}),d(!1)}async function Z(){d(!0),await M(async()=>{await ce(o),A({message:`Deleted "${o.name}".`,color:"green"}),t.onDeleted()}),d(!1)}return e(S,{className:"AssetBrowser__detailsModal",opened:!0,onClose:t.onClose,title:o.name,size:720,overflow:"outside",centered:!0,children:e("div",{className:"AssetBrowser__details",children:[e("div",{className:"AssetBrowser__details__preview",children:N?e("img",{src:Te(n,800),alt:n.alt||"",style:n.canvasBgColor==="dark"?{background:"#000"}:{}}):R?e("video",{src:n.src,controls:!0,muted:!0,preload:"metadata"}):e("div",{className:"AssetBrowser__details__preview__placeholder",children:[e(he,{size:48,stroke:"1"}),e("div",{children:u})]})}),e(re,{className:"AssetBrowser__details__table",verticalSpacing:"xs",fontSize:"xs",children:e("tbody",{children:[e("tr",{children:[e("td",{children:e("b",{children:"Filename"})}),e("td",{children:u})]}),!!(n.width&&n.height)&&e("tr",{children:[e("td",{children:e("b",{children:"Dimensions"})}),e("td",{children:[n.width,"x",n.height]})]}),o.createdAt&&e("tr",{children:[e("td",{children:e("b",{children:"Uploaded"})}),e("td",{children:[Ce(o.createdAt),o.createdBy&&e(C,{children:[" by ",o.createdBy]})]})]}),o.modifiedAt&&e("tr",{children:[e("td",{children:e("b",{children:"Modified"})}),e("td",{children:[Ce(o.modifiedAt),o.modifiedBy&&e(C,{children:[" by ",o.modifiedBy]})]})]}),e("tr",{children:[e("td",{children:e("b",{children:"URL"})}),e("td",{children:e("div",{className:"AssetBrowser__details__url",children:[e(H,{readOnly:!0,value:n.src||"",size:"xs",radius:"xs",onClick:c=>c.target.select(),styles:{root:{flex:1,minWidth:0}}}),e(Ge,{label:"Copy URL",transition:"pop",children:e(se,{size:"sm",onClick:()=>we(n),children:e(ge,{size:16})})})]})})]})]})}),(N||R)&&e("div",{className:"AssetBrowser__details__alt",children:[q?e("div",{className:"AssetBrowser__details__alt__disabledNote",children:"Alt text is disabled for this asset. Docs that use it hide the alt text input and render no alt text."}):e(C,{children:[e(je,{label:"Alt text",description:"Used as the default alt text when the asset is selected in a doc. Updating it syncs docs that use this asset.",autosize:!0,minRows:1,size:"xs",value:l,disabled:!t.canManage||m,onChange:c=>r(c.currentTarget.value)}),t.canManage&&X&&e(g,{size:"xs",color:"dark",mt:8,loading:m,onClick:()=>K(),children:"Save alt text"})]}),t.canManage&&e(G,{className:"AssetBrowser__details__alt__disableCheckbox",label:"Disable alt text (e.g. decorative images)",size:"xs",mt:8,checked:q,disabled:m,onChange:c=>P(c.currentTarget.checked)})]}),e("div",{className:"AssetBrowser__details__usage",children:[e("div",{className:"AssetBrowser__details__usage__title",children:"Used in"}),w===null?e(te,{color:"gray",size:"sm"}):w.length===0?e("div",{className:"AssetBrowser__details__usage__empty",children:"No docs use this asset."}):e("div",{className:"AssetBrowser__details__usage__list",children:w.map(c=>e("a",{className:"AssetBrowser__details__usage__doc",href:`/cms/content/${c.id}`,target:"_blank",rel:"noreferrer",children:[e("span",{children:c.id}),e(lt,{size:14})]},c.id))})]}),e("div",{className:"AssetBrowser__details__buttons",children:[e(g,{variant:"default",size:"xs",leftIcon:e(pe,{size:14}),onClick:()=>be(n),children:"Download"}),t.canManage&&e(C,{children:[e(g,{variant:"default",size:"xs",leftIcon:e(nt,{size:14}),loading:m,onClick:()=>E(),children:"Replace file"}),e(g,{className:"AssetBrowser__details__buttons__delete",color:"red",variant:"filled",size:"xs",leftIcon:e(W,{size:14}),disabled:m,onClick:()=>v(!0),children:"Delete"})]})]}),f&&e("div",{className:"AssetBrowser__details__confirmReplace",children:[e("div",{children:["The new file has a different type (",e("b",{children:[".",D(u)]})," ","\u2192 ",e("b",{children:[".",D(f.name)]}),"). Replacing will change the asset's file extension and serving URL",Fe(o.name,D(f.name))!==o.name&&e(C,{children:[", and the asset will be renamed to"," ",e("b",{children:Fe(o.name,D(f.name))})]}),". Docs that use this asset will be updated."]}),e("div",{className:"AssetBrowser__details__confirmReplace__buttons",children:[e(g,{variant:"default",size:"xs",onClick:()=>B(null),disabled:m,children:"Cancel"}),e(g,{color:"dark",size:"xs",loading:m,onClick:()=>$(f),children:"Replace"})]})]}),x&&e("div",{className:"AssetBrowser__details__confirmDelete",children:[e("div",{children:["Delete ",e("b",{children:o.name})," from the asset library?",w&&w.length>0&&e(C,{children:[" ","This asset is used in ",w.length," doc(s); those docs keep their copy of the file but will no longer receive updates."]})]}),e("div",{className:"AssetBrowser__details__confirmDelete__buttons",children:[e(g,{variant:"default",size:"xs",onClick:()=>v(!1),disabled:m,children:"Cancel"}),e(g,{color:"red",size:"xs",loading:m,onClick:()=>Z(),children:"Delete"})]})]})]})})}var Mt=100;function Ue(t){let[o,a]=i(t.folder??t.initialFolder??""),l=t.folder??o,[r,m]=i([]),[d,x]=i(!0),[v,f]=i(""),[B,w]=i(!1),[F,n]=i(!1),[u,N]=i(null),[R,X]=i(!1),[q,z]=i(null),[K,E]=i(null),[$,P]=i(null),[Z,c]=i(null),[b,p]=i(null),[y,ae]=i(new Map),{roles:At}=_t(),xt=window.firebase.user.email||"",J=ft(At,xt),Q=v.trim().length>0;function L(s){a(s),f(""),t.onFolderChange&&t.onFolderChange(s)}async function I(s){x(!0),N(null),ae(new Map),await M(async()=>{let _=await Me(s);m(_)}),x(!1)}U(()=>{I(l)},[l]),U(()=>{if(!Q||u!==null)return;let s=!1;return(async()=>{let _=[];await M(async()=>{_=await Ze(l)}),s||N(_)})(),()=>{s=!0}},[Q,u,l]);let Ae=t.mode==="manage"?t.initialAssetId:"";U(()=>{Ae&&M(async()=>{let s=await Qe(Ae);s&&s.type==="file"&&(L(s.parent),p(s))})},[Ae]);let Se=$e(()=>{let s=v.trim().toLowerCase(),_=s?u||[]:r;return t.mode==="pick"&&(_=_.filter(h=>h.type==="folder"||Xe(h.file?.filename||h.name,t.accept))),s&&(_=_.filter(h=>h.name.toLowerCase().includes(s))),_},[r,u,v,t.mode,t.accept]),T=mt(Se,{pageSize:Mt,resetDeps:[l,v]}),j=T.pageItems;async function Ee(s){if(s.length===0||F)return;let _="asset-browser-upload";n(!0),A({id:_,message:`Uploading ${s.length} file(s)...`,loading:!0,autoClose:!1,disallowClose:!0});let h=[],Be=[];for(let ne=0;ne<s.length;ne++){let ie=s[ne];He({id:_,message:`Uploading ${ie.name} (${ne+1} of ${s.length})...`,loading:!0,autoClose:!1,disallowClose:!0});try{let ye=await de(ie),kt=await et({parent:l,file:ye});h.push(kt)}catch(ye){console.error(`failed to upload ${ie.name}:`,ye),Be.push(ie.name)}}Oe(_),n(!1),Be.length>0?A({title:"Upload failed",message:`Failed to upload: ${Be.join(", ")}`,color:"red",autoClose:!1}):A({message:`Uploaded ${h.length} file(s).`,color:"green"}),await I(l),t.mode==="pick"&&h.length===1&&s.length===1&&t.onPickFile&&t.onPickFile(h[0])}function Bt(){let s=document.createElement("input");s.type="file",s.multiple=!0,t.mode==="pick"&&t.accept&&t.accept.length>0&&(s.accept=t.accept.join(",")),s.onchange=()=>{Ee(Array.from(s.files||[]))},s.click(),s.remove()}function yt(s){t.onPickFile&&t.onPickFile(s)}let Y=J,le=t.mode==="manage"&&J,ee=Array.from(y.values()),Pe=ee.filter(s=>s.type==="file"&&!s.file?.altDisabled&&(O(s.file?.filename||s.name)||V(s.file?.filename||s.name))),xe=j.length>0&&j.every(s=>y.has(s.id));function Re(s){ae(_=>{let h=new Map(_);return h.has(s.id)?h.delete(s.id):h.set(s.id,s),h})}function Ct(){ae(s=>{let _=new Map(s);return xe?j.forEach(h=>_.delete(h.id)):j.forEach(h=>_.set(h.id,h)),_})}return e("div",{className:ue("AssetBrowser",t.className,`AssetBrowser--${t.mode}`),children:[e("div",{className:"AssetBrowser__toolbar",children:[e(Ue.Breadcrumbs,{folder:l,onNavigate:L}),e("div",{className:"AssetBrowser__toolbar__actions",children:[e(H,{className:"AssetBrowser__toolbar__filter",placeholder:"Search by name",size:"xs",icon:e(dt,{size:14}),value:v,onChange:s=>f(s.currentTarget.value)}),Y&&t.mode==="manage"&&e(g,{variant:"default",size:"xs",leftIcon:e(it,{size:16}),onClick:()=>X(!0),children:"New folder"}),Y&&e(g,{color:"dark",size:"xs",leftIcon:e(ct,{size:16}),loading:F,onClick:()=>Bt(),children:"Upload"})]})]}),le&&ee.length>0&&e("div",{className:"AssetBrowser__selectionBar",children:[e("div",{className:"AssetBrowser__selectionBar__count",children:[ee.length," selected"]}),e("div",{className:"AssetBrowser__selectionBar__actions",children:[e(g,{variant:"default",size:"xs",leftIcon:e(ve,{size:14}),onClick:()=>E(ee),children:"Move"}),Pe.length>0&&e(g,{variant:"default",size:"xs",onClick:()=>c(Pe),children:"Disable alt text"}),e(g,{color:"red",size:"xs",leftIcon:e(W,{size:14}),onClick:()=>P(ee),children:"Delete"}),e(g,{variant:"subtle",color:"gray",size:"xs",onClick:()=>ae(new Map),children:"Clear"})]})]}),e("div",{className:ue("AssetBrowser__listing",B&&"dragging"),onDragOver:s=>{Y&&(s.preventDefault(),w(!0))},onDragLeave:s=>{s.preventDefault(),w(!1)},onDrop:s=>{s.preventDefault(),w(!1),Y&&Ee(Array.from(s.dataTransfer?.files||[]))},children:d||Q&&u===null?e("div",{className:"AssetBrowser__loading",children:e(te,{color:"gray",size:"lg"})}):Se.length===0?e("div",{className:"AssetBrowser__empty","data-testid":"asset-browser-empty",children:v?e("div",{children:['No assets match "',v,'" in this folder or its subfolders.']}):e(C,{children:[e("div",{children:"This folder is empty."}),Y&&e("div",{className:"AssetBrowser__empty__hint",children:'Drop files here or click "Upload" to add assets.'})]})}):e(re,{className:"AssetBrowser__table",verticalSpacing:"xs",fontSize:"xs",highlightOnHover:!0,children:[e("thead",{children:e("tr",{children:[le&&e("th",{className:"AssetBrowser__table__checkboxCol",children:e(G,{size:"xs","aria-label":"Select all",checked:xe,indeterminate:!xe&&j.some(s=>y.has(s.id)),onChange:()=>Ct()})}),e("th",{children:"name"}),e("th",{className:"AssetBrowser__table__modifiedCol",children:"modified"}),e("th",{className:"AssetBrowser__table__actionsCol"})]})}),e("tbody",{children:j.map(s=>s.type==="folder"?e("tr",{className:"AssetBrowser__row AssetBrowser__row--folder",onClick:()=>L(oe(s.parent,s.name)),children:[le&&e("td",{className:"AssetBrowser__checkboxCell",onClick:_=>_.stopPropagation(),children:e(G,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>Re(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e("div",{className:"AssetBrowser__thumb",children:e(ze,{size:24,stroke:"1.5"})}),e("div",{className:"AssetBrowser__nameCell__text",children:[e("div",{className:"AssetBrowser__nameCell__name",children:s.name}),e(wt,{asset:s,folder:l,searching:Q,onNavigate:L})]})]})}),e("td",{children:e(bt,{asset:s})}),e("td",{onClick:_=>_.stopPropagation(),children:e("div",{className:"AssetBrowser__actionsCell",children:t.mode==="manage"&&J&&e(k,{shadow:"sm",position:"bottom",placement:"end",control:e(se,{size:"sm",children:e(De,{size:16})}),children:[e(k.Item,{icon:e(Ie,{size:14}),onClick:()=>z(s),children:"Rename"}),e(k.Item,{icon:e(ve,{size:14}),onClick:()=>E([s]),children:"Move"}),e(k.Item,{color:"red",icon:e(W,{size:14}),onClick:()=>P([s]),children:"Delete"})]})})})]},s.id):e("tr",{className:"AssetBrowser__row AssetBrowser__row--file",onClick:()=>{t.mode==="pick"?yt(s):p(s)},children:[le&&e("td",{className:"AssetBrowser__checkboxCell",onClick:_=>_.stopPropagation(),children:e(G,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>Re(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e(ht,{file:s.file,size:36}),e("div",{className:"AssetBrowser__nameCell__text",children:[e("div",{className:"AssetBrowser__nameCell__name",children:[s.name,!!(s.file?.width&&s.file?.height)&&e("span",{className:"AssetBrowser__nameCell__dimens",children:[" ","(",s.file.width,"x",s.file.height,")"]})]}),e(wt,{asset:s,folder:l,searching:Q,onNavigate:L})]})]})}),e("td",{children:e(bt,{asset:s})}),e("td",{onClick:_=>_.stopPropagation(),children:e("div",{className:"AssetBrowser__actionsCell",children:t.mode!=="pick"&&e(Ft,{asset:s,canManage:J,onDetails:()=>p(s),onRename:()=>z(s),onMove:()=>E([s]),onDelete:()=>P([s])})})})]},s.id))})]})}),T.totalPages>1&&e("div",{className:"AssetBrowser__footer",children:[e(gt,{start:T.start,end:T.end,total:T.totalItems,noun:"asset"}),e(ut,{total:T.totalPages,page:T.page,onChange:T.setPage})]}),e(Nt,{opened:R,parent:l,onClose:()=>X(!1),onCreated:s=>{X(!1),L(oe(l,s))}}),q&&e(Dt,{asset:q,onClose:()=>z(null),onRenamed:()=>{z(null),I(l)}}),K&&K.length>0&&e(zt,{assets:K,onClose:()=>E(null),onMoved:()=>{E(null),I(l)}}),$&&$.length>0&&e(Tt,{assets:$,onClose:()=>P(null),onDeleted:()=>{P(null),I(l)}}),Z&&Z.length>0&&e(Ut,{assets:Z,onClose:()=>c(null),onDone:()=>{c(null),I(l)}}),b&&e(vt,{asset:b,canManage:J,onClose:()=>p(null),onChanged:()=>I(l),onDeleted:()=>{p(null),I(l)}})]})}Ue.Breadcrumbs=t=>{let o=Ke(t.folder),a=[{label:"Assets",path:""}];return o.forEach((l,r)=>{a.push({label:l,path:o.slice(0,r+1).join("/")})}),e("div",{className:"AssetBrowser__breadcrumbs",children:a.map((l,r)=>e("div",{className:"AssetBrowser__breadcrumbs__crumb",children:[r>0&&e(Ne,{className:"AssetBrowser__breadcrumbs__divider",size:14}),e("button",{className:ue("AssetBrowser__breadcrumbs__link",r===a.length-1&&"active"),disabled:r===a.length-1,onClick:()=>t.onNavigate(l.path),children:l.label})]},l.path))})};function Ft(t){let o=t.asset;return e(k,{shadow:"sm",position:"bottom",placement:"end",control:e(se,{size:"sm",children:e(De,{size:16})}),children:[e(k.Item,{icon:e(rt,{size:14}),onClick:t.onDetails,children:"Details"}),e(k.Item,{icon:e(ge,{size:14}),onClick:()=>we(o.file),children:"Copy URL"}),e(k.Item,{icon:e(pe,{size:14}),onClick:()=>be(o.file),children:"Download"}),t.canManage&&e(C,{children:[e(k.Item,{icon:e(Ie,{size:14}),onClick:t.onRename,children:"Rename"}),e(k.Item,{icon:e(ve,{size:14}),onClick:t.onMove,children:"Move"}),e(k.Item,{color:"red",icon:e(W,{size:14}),onClick:t.onDelete,children:"Delete"})]})]})}function wt(t){let o=t.asset;return!t.searching||o.parent===t.folder?null:e("button",{className:"AssetBrowser__nameCell__path",title:"Go to folder",onClick:a=>{a.stopPropagation(),t.onNavigate(o.parent)},children:["in ",Je(o.parent,t.folder)]})}function bt(t){let o=t.asset.modifiedAt||t.asset.createdAt,a=t.asset.modifiedBy||t.asset.createdBy||"",l=o&&typeof o.toMillis=="function"?o.toMillis():0;return e("div",{className:"AssetBrowser__modifiedCell",children:[a&&e(pt,{email:a,size:20}),e("span",{children:l?Ve(l):"\u2014"})]})}function Nt(t){let[o,a]=i(""),[l,r]=i(!1);async function m(){r(!0),await M(async()=>{let d=await Ye(t.parent,o);a(""),t.onCreated(d.name)}),r(!1)}return e(S,{opened:t.opened,onClose:t.onClose,title:"New folder",size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),m()},children:[e(H,{"data-autofocus":!0,placeholder:"Folder name",value:o,onChange:d=>a(d.currentTarget.value)}),e(g,{type:"submit",color:"dark",loading:l,disabled:!o,children:"Create"})]})})}function Dt(t){let[o,a]=i(t.asset.name),[l,r]=i(!1);async function m(){r(!0),await M(async()=>{await tt(t.asset,o),t.onRenamed()}),r(!1)}return e(S,{opened:!0,onClose:t.onClose,title:`Rename ${t.asset.type}`,size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),m()},children:[e(H,{"data-autofocus":!0,value:o,onChange:d=>a(d.currentTarget.value)}),e(g,{type:"submit",color:"dark",loading:l,disabled:!o,children:"Rename"})]})})}function zt(t){let o=t.assets,[a,l]=i(o[0]?.parent||""),[r,m]=i([]),[d,x]=i(!0),[v,f]=i(!1);U(()=>{x(!0),M(async()=>{let n=await Me(a);m(n.filter(u=>u.type==="folder"))}).then(()=>x(!1))},[a]);let B=o.filter(n=>n.type==="folder").map(n=>oe(n.parent,n.name));function w(n){return B.some(u=>n===u||n.startsWith(`${u}/`))}async function F(){f(!0);let n=[],u=0;for(let N of o)try{await st(N,a),u+=1}catch(R){console.error(`failed to move ${N.name}:`,R),n.push(N.name)}f(!1),n.length>0&&A({title:"Move failed",message:`Failed to move: ${n.join(", ")}`,color:"red",autoClose:!1}),u>0&&A({message:o.length===1?`Moved "${o[0].name}" to ${a||"Assets"}.`:`Moved ${u} item(s) to ${a||"Assets"}.`,color:"green"}),t.onMoved()}return e(S,{opened:!0,onClose:t.onClose,title:o.length===1?`Move "${o[0].name}"`:`Move ${o.length} items`,size:"md",centered:!0,children:e("div",{className:"AssetBrowser__moveModal",children:[e(Ue.Breadcrumbs,{folder:a,onNavigate:l}),e("div",{className:"AssetBrowser__moveModal__folders",children:d?e(te,{color:"gray",size:"sm"}):r.length===0?e("div",{className:"AssetBrowser__moveModal__empty",children:"No subfolders."}):r.map(n=>{let u=oe(n.parent,n.name);return e("button",{className:"AssetBrowser__moveModal__folder",disabled:w(u),onClick:()=>l(u),children:[e(ze,{size:16,stroke:"1.5"}),e("span",{children:n.name}),e(Ne,{size:14})]},n.id)})}),e(g,{color:"dark",fullWidth:!0,loading:v,disabled:o.every(n=>n.parent===a),onClick:()=>F(),children:"Move here"})]})})}var It=20;function Tt(t){let o=t.assets,[a,l]=i(!1),[r,m]=i(null),d=o.filter(f=>f.type==="file"),x=o.some(f=>f.type==="folder");U(()=>{d.length===0||d.length>It||Promise.all(d.map(f=>_e(f.id))).then(f=>{let B=new Set(f.flat().map(w=>w.id));m(B.size)}).catch(()=>m(null))},[o.map(f=>f.id).join(",")]);async function v(){l(!0);let f=[],B=0;for(let w of o)try{await ce(w),B+=1}catch(F){console.error(`failed to delete ${w.name}:`,F),f.push(w.name)}l(!1),f.length>0&&A({title:"Delete failed",message:`Failed to delete: ${f.join(", ")}. Note that folders must be empty before they can be deleted.`,color:"red",autoClose:!1}),B>0&&A({message:o.length===1?`Deleted "${o[0].name}".`:`Deleted ${B} item(s).`,color:"green"}),t.onDeleted()}return e(S,{opened:!0,onClose:t.onClose,title:o.length===1?`Delete ${o[0].type}?`:`Delete ${o.length} items?`,size:"sm",centered:!0,children:e("div",{className:"AssetBrowser__deleteModal",children:[e("div",{className:"AssetBrowser__deleteModal__text",children:["Are you sure you want to delete"," ",o.length===1?e("b",{children:o[0].name}):e("b",{children:[o.length," items"]})," ","from the asset manager?",d.length>0&&e(C,{children:[" ","The underlying files are not deleted from GCS, and docs that currently use the assets keep their copy of the files."]}),x&&e(C,{children:" Folders must be empty before they can be deleted."})]}),r!==null&&r>0&&e("div",{className:"AssetBrowser__deleteModal__warning",children:[o.length===1?"This asset is":"These assets are"," ","currently used in ",r," doc(s). Those docs will no longer receive updates when the asset changes."]}),e("div",{className:"AssetBrowser__deleteModal__buttons",children:[e(g,{variant:"default",onClick:t.onClose,disabled:a,children:"Cancel"}),e(g,{color:"red",loading:a,onClick:()=>v(),children:"Delete"})]})]})})}function Ut(t){let o=t.assets,[a,l]=i(!1);async function r(){l(!0);let m=[],d=0;for(let x of o)try{let v=x.file,f=await me(x,!0);await fe(f,{previousFile:v}),d+=1}catch(v){console.error(`failed to disable alt text for ${x.name}:`,v),m.push(x.name)}l(!1),m.length>0&&A({title:"Failed to disable alt text",message:`Failed to update: ${m.join(", ")}`,color:"red",autoClose:!1}),d>0&&A({message:`Disabled alt text for ${d} file(s).`,color:"green"}),t.onDone()}return e(S,{opened:!0,onClose:t.onClose,title:"Disable alt text?",size:"sm",centered:!0,children:e("div",{className:"AssetBrowser__deleteModal",children:[e("div",{className:"AssetBrowser__deleteModal__text",children:["Disable alt text for ",e("b",{children:[o.length," file(s)"]}),"? The alt text input is hidden in docs that use these assets and their embedded alt text is cleared. Alt text can be re-enabled per asset from its details."]}),e("div",{className:"AssetBrowser__deleteModal__buttons",children:[e(g,{variant:"default",onClick:t.onClose,disabled:a,children:"Cancel"}),e(g,{color:"dark",loading:a,onClick:()=>r(),children:"Disable alt text"})]})]})})}export{Ue as a};
1
+ import{a as _t,b as gt,c as pt}from"./chunk-2RRM4HEQ.js";import{a as lt}from"./chunk-PLYSJ7W5.js";import{a as ut}from"./chunk-W5DOO6ID.js";import{a as ft}from"./chunk-YBHFGQ3Z.js";import{b as M}from"./chunk-2PTLQRTU.js";import{a as A,b as He,c as Oe}from"./chunk-PIJ3E47R.js";import{g as oe,h as Ke,i as Me,j as Ze,k as Je,l as Qe,m as Ye,n as et,o as tt,p as st,q as ce,r as ot,s as Fe,t as at,u as me,y as _e,z as fe}from"./chunk-ISUGBMXC.js";import{B as Ce,z as Ve}from"./chunk-XOWWPE7X.js";import{e as ue}from"./chunk-WASID5UU.js";import{Ab as nt,Da as re,Db as it,Eb as he,Fa as Ge,Ga as e,Gc as ct,Hb as rt,Ib as ve,Jb as ze,Tb as dt,V as te,Vc as W,W as se,Yc as mt,a as i,bb as Ne,c as U,da as g,ea as G,g as $e,j as Le,na as je,pb as ge,qa as k,qc as Ie,ra as S,ua as H,xb as De,zb as pe}from"./chunk-WRA24P66.js";import{d as C}from"./chunk-KUCVLANF.js";import{g as We,h as de,k as D,l as O,m as ke,n as V,o as Xe,p as qe}from"./chunk-7SK47HHZ.js";Le();Le();function ht(t){let o=t.file||{},a=o.src||"",l=o.filename||a,r={"--asset-thumb-size":`${t.size}px`};if(a&&O(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("img",{src:Te(o,t.size*2),alt:o.alt||"",loading:"lazy"})});if(a&&V(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("video",{src:a,muted:!0,playsInline:!0,preload:"metadata"})});let m=D(l);return e("div",{className:"AssetBrowser__thumb",style:r,children:m&&m.length<=4?e("div",{className:"AssetBrowser__thumb__ext",children:m}):e(he,{size:20,stroke:"1.5"})})}function Te(t,o){let a=t?.src||"";return a.startsWith(We)&&o?`${a}=s${o}`:a}function we(t){let o=t?.src||"";ke(o)&&(o=o.split("=")[0]+"=s0"),navigator.clipboard.writeText(o).then(()=>{A({message:"Copied URL to clipboard.",autoClose:2e3})})}function be(t){let o=t?.src||"";if(o)if(ke(o)){let a=document.createElement("a");a.href=qe(o),t.filename&&(a.download=t.filename),document.body.appendChild(a),a.click(),document.body.removeChild(a)}else window.open(o,"_blank")}function vt(t){let[o,a]=i(t.asset),[l,r]=i(t.asset.file?.alt||""),[m,d]=i(!1),[x,v]=i(!1),[f,B]=i(null),[w,F]=i(null),n=o.file||{},u=n.filename||o.name,N=O(u),R=V(u),X=l!==(n.alt||""),q=n.altDisabled===!0;U(()=>{_e(o.id).then(c=>F(c)).catch(c=>{console.error("failed to fetch asset usage:",c),F([])})},[o.id]);async function z(c,b){let p=await fe(c,{previousFile:b});p.failedDocIds.length>0?A({title:"Some docs failed to update",message:`Failed to update: ${p.failedDocIds.join(", ")}. Re-save the asset to retry.`,color:"red",autoClose:!1}):p.updatedDocIds.length>0&&A({message:`Updated ${p.updatedDocIds.length} doc(s) that use this asset.`,color:"green"})}async function K(){d(!0),await M(async()=>{let c={...n},b=await at(o,l);a(b),t.onChanged(b),await z(b,c)}),d(!1)}function E(){let c=document.createElement("input");c.type="file",c.onchange=()=>{let b=c.files?.[0];if(!b)return;let p=D(u),y=D(b.name);if(p&&y&&p!==y){B(b);return}$(b)},c.click(),c.remove()}async function $(c){B(null),d(!0),await M(async()=>{let b={...n},p=await de(c),y=await ot(o,p);a(y),r(y.file?.alt||""),t.onChanged(y),await z(y,b)}),d(!1)}async function P(c){d(!0),await M(async()=>{let b={...n},p=await me(o,c);a(p),r(p.file?.alt||""),t.onChanged(p),await z(p,b)}),d(!1)}async function Z(){d(!0),await M(async()=>{await ce(o),A({message:`Deleted "${o.name}".`,color:"green"}),t.onDeleted()}),d(!1)}return e(S,{className:"AssetBrowser__detailsModal",opened:!0,onClose:t.onClose,title:o.name,size:720,overflow:"outside",centered:!0,children:e("div",{className:"AssetBrowser__details",children:[e("div",{className:"AssetBrowser__details__preview",children:N?e("img",{src:Te(n,800),alt:n.alt||"",style:n.canvasBgColor==="dark"?{background:"#000"}:{}}):R?e("video",{src:n.src,controls:!0,muted:!0,preload:"metadata"}):e("div",{className:"AssetBrowser__details__preview__placeholder",children:[e(he,{size:48,stroke:"1"}),e("div",{children:u})]})}),e(re,{className:"AssetBrowser__details__table",verticalSpacing:"xs",fontSize:"xs",children:e("tbody",{children:[e("tr",{children:[e("td",{children:e("b",{children:"Filename"})}),e("td",{children:u})]}),!!(n.width&&n.height)&&e("tr",{children:[e("td",{children:e("b",{children:"Dimensions"})}),e("td",{children:[n.width,"x",n.height]})]}),o.createdAt&&e("tr",{children:[e("td",{children:e("b",{children:"Uploaded"})}),e("td",{children:[Ce(o.createdAt),o.createdBy&&e(C,{children:[" by ",o.createdBy]})]})]}),o.modifiedAt&&e("tr",{children:[e("td",{children:e("b",{children:"Modified"})}),e("td",{children:[Ce(o.modifiedAt),o.modifiedBy&&e(C,{children:[" by ",o.modifiedBy]})]})]}),e("tr",{children:[e("td",{children:e("b",{children:"URL"})}),e("td",{children:e("div",{className:"AssetBrowser__details__url",children:[e(H,{readOnly:!0,value:n.src||"",size:"xs",radius:"xs",onClick:c=>c.target.select(),styles:{root:{flex:1,minWidth:0}}}),e(Ge,{label:"Copy URL",transition:"pop",children:e(se,{size:"sm",onClick:()=>we(n),children:e(ge,{size:16})})})]})})]})]})}),(N||R)&&e("div",{className:"AssetBrowser__details__alt",children:[q?e("div",{className:"AssetBrowser__details__alt__disabledNote",children:"Alt text is disabled for this asset. Docs that use it hide the alt text input and render no alt text."}):e(C,{children:[e(je,{label:"Alt text",description:"Used as the default alt text when the asset is selected in a doc. Updating it syncs docs that use this asset.",autosize:!0,minRows:1,size:"xs",value:l,disabled:!t.canManage||m,onChange:c=>r(c.currentTarget.value)}),t.canManage&&X&&e(g,{size:"xs",color:"dark",mt:8,loading:m,onClick:()=>K(),children:"Save alt text"})]}),t.canManage&&e(G,{className:"AssetBrowser__details__alt__disableCheckbox",label:"Disable alt text (e.g. decorative images)",size:"xs",mt:8,checked:q,disabled:m,onChange:c=>P(c.currentTarget.checked)})]}),e("div",{className:"AssetBrowser__details__usage",children:[e("div",{className:"AssetBrowser__details__usage__title",children:"Used in"}),w===null?e(te,{color:"gray",size:"sm"}):w.length===0?e("div",{className:"AssetBrowser__details__usage__empty",children:"No docs use this asset."}):e("div",{className:"AssetBrowser__details__usage__list",children:w.map(c=>e("a",{className:"AssetBrowser__details__usage__doc",href:`/cms/content/${c.id}`,target:"_blank",rel:"noreferrer",children:[e("span",{children:c.id}),e(nt,{size:14})]},c.id))})]}),e("div",{className:"AssetBrowser__details__buttons",children:[e(g,{variant:"default",size:"xs",leftIcon:e(pe,{size:14}),onClick:()=>be(n),children:"Download"}),t.canManage&&e(C,{children:[e(g,{variant:"default",size:"xs",leftIcon:e(it,{size:14}),loading:m,onClick:()=>E(),children:"Replace file"}),e(g,{className:"AssetBrowser__details__buttons__delete",color:"red",variant:"filled",size:"xs",leftIcon:e(W,{size:14}),disabled:m,onClick:()=>v(!0),children:"Delete"})]})]}),f&&e("div",{className:"AssetBrowser__details__confirmReplace",children:[e("div",{children:["The new file has a different type (",e("b",{children:[".",D(u)]})," ","\u2192 ",e("b",{children:[".",D(f.name)]}),"). Replacing will change the asset's file extension and serving URL",Fe(o.name,D(f.name))!==o.name&&e(C,{children:[", and the asset will be renamed to"," ",e("b",{children:Fe(o.name,D(f.name))})]}),". Docs that use this asset will be updated."]}),e("div",{className:"AssetBrowser__details__confirmReplace__buttons",children:[e(g,{variant:"default",size:"xs",onClick:()=>B(null),disabled:m,children:"Cancel"}),e(g,{color:"dark",size:"xs",loading:m,onClick:()=>$(f),children:"Replace"})]})]}),x&&e("div",{className:"AssetBrowser__details__confirmDelete",children:[e("div",{children:["Delete ",e("b",{children:o.name})," from the asset library?",w&&w.length>0&&e(C,{children:[" ","This asset is used in ",w.length," doc(s); those docs keep their copy of the file but will no longer receive updates."]})]}),e("div",{className:"AssetBrowser__details__confirmDelete__buttons",children:[e(g,{variant:"default",size:"xs",onClick:()=>v(!1),disabled:m,children:"Cancel"}),e(g,{color:"red",size:"xs",loading:m,onClick:()=>Z(),children:"Delete"})]})]})]})})}var Mt=100;function Ue(t){let[o,a]=i(t.folder??t.initialFolder??""),l=t.folder??o,[r,m]=i([]),[d,x]=i(!0),[v,f]=i(""),[B,w]=i(!1),[F,n]=i(!1),[u,N]=i(null),[R,X]=i(!1),[q,z]=i(null),[K,E]=i(null),[$,P]=i(null),[Z,c]=i(null),[b,p]=i(null),[y,ae]=i(new Map),{roles:At}=ft(),xt=window.firebase.user.email||"",J=ut(At,xt),Q=v.trim().length>0;function L(s){a(s),f(""),t.onFolderChange&&t.onFolderChange(s)}async function I(s){x(!0),N(null),ae(new Map),await M(async()=>{let _=await Me(s);m(_)}),x(!1)}U(()=>{I(l)},[l]),U(()=>{if(!Q||u!==null)return;let s=!1;return(async()=>{let _=[];await M(async()=>{_=await Ze(l)}),s||N(_)})(),()=>{s=!0}},[Q,u,l]);let Ae=t.mode==="manage"?t.initialAssetId:"";U(()=>{Ae&&M(async()=>{let s=await Qe(Ae);s&&s.type==="file"&&(L(s.parent),p(s))})},[Ae]);let Se=$e(()=>{let s=v.trim().toLowerCase(),_=s?u||[]:r;return t.mode==="pick"&&(_=_.filter(h=>h.type==="folder"||Xe(h.file?.filename||h.name,t.accept))),s&&(_=_.filter(h=>h.name.toLowerCase().includes(s))),_},[r,u,v,t.mode,t.accept]),T=_t(Se,{pageSize:Mt,resetDeps:[l,v]}),j=T.pageItems;async function Ee(s){if(s.length===0||F)return;let _="asset-browser-upload";n(!0),A({id:_,message:`Uploading ${s.length} file(s)...`,loading:!0,autoClose:!1,disallowClose:!0});let h=[],Be=[];for(let ne=0;ne<s.length;ne++){let ie=s[ne];He({id:_,message:`Uploading ${ie.name} (${ne+1} of ${s.length})...`,loading:!0,autoClose:!1,disallowClose:!0});try{let ye=await de(ie),kt=await et({parent:l,file:ye});h.push(kt)}catch(ye){console.error(`failed to upload ${ie.name}:`,ye),Be.push(ie.name)}}Oe(_),n(!1),Be.length>0?A({title:"Upload failed",message:`Failed to upload: ${Be.join(", ")}`,color:"red",autoClose:!1}):A({message:`Uploaded ${h.length} file(s).`,color:"green"}),await I(l),t.mode==="pick"&&h.length===1&&s.length===1&&t.onPickFile&&t.onPickFile(h[0])}function Bt(){let s=document.createElement("input");s.type="file",s.multiple=!0,t.mode==="pick"&&t.accept&&t.accept.length>0&&(s.accept=t.accept.join(",")),s.onchange=()=>{Ee(Array.from(s.files||[]))},s.click(),s.remove()}function yt(s){t.onPickFile&&t.onPickFile(s)}let Y=J,le=t.mode==="manage"&&J,ee=Array.from(y.values()),Pe=ee.filter(s=>s.type==="file"&&!s.file?.altDisabled&&(O(s.file?.filename||s.name)||V(s.file?.filename||s.name))),xe=j.length>0&&j.every(s=>y.has(s.id));function Re(s){ae(_=>{let h=new Map(_);return h.has(s.id)?h.delete(s.id):h.set(s.id,s),h})}function Ct(){ae(s=>{let _=new Map(s);return xe?j.forEach(h=>_.delete(h.id)):j.forEach(h=>_.set(h.id,h)),_})}return e("div",{className:ue("AssetBrowser",t.className,`AssetBrowser--${t.mode}`),children:[e("div",{className:"AssetBrowser__toolbar",children:[e(Ue.Breadcrumbs,{folder:l,onNavigate:L}),e("div",{className:"AssetBrowser__toolbar__actions",children:[e(H,{className:"AssetBrowser__toolbar__filter",placeholder:"Search by name",size:"xs",icon:e(ct,{size:14}),value:v,onChange:s=>f(s.currentTarget.value)}),Y&&t.mode==="manage"&&e(g,{variant:"default",size:"xs",leftIcon:e(rt,{size:16}),onClick:()=>X(!0),children:"New folder"}),Y&&e(g,{color:"dark",size:"xs",leftIcon:e(mt,{size:16}),loading:F,onClick:()=>Bt(),children:"Upload"})]})]}),le&&ee.length>0&&e("div",{className:"AssetBrowser__selectionBar",children:[e("div",{className:"AssetBrowser__selectionBar__count",children:[ee.length," selected"]}),e("div",{className:"AssetBrowser__selectionBar__actions",children:[e(g,{variant:"default",size:"xs",leftIcon:e(ve,{size:14}),onClick:()=>E(ee),children:"Move"}),Pe.length>0&&e(g,{variant:"default",size:"xs",onClick:()=>c(Pe),children:"Disable alt text"}),e(g,{color:"red",size:"xs",leftIcon:e(W,{size:14}),onClick:()=>P(ee),children:"Delete"}),e(g,{variant:"subtle",color:"gray",size:"xs",onClick:()=>ae(new Map),children:"Clear"})]})]}),e("div",{className:ue("AssetBrowser__listing",B&&"dragging"),onDragOver:s=>{Y&&(s.preventDefault(),w(!0))},onDragLeave:s=>{s.preventDefault(),w(!1)},onDrop:s=>{s.preventDefault(),w(!1),Y&&Ee(Array.from(s.dataTransfer?.files||[]))},children:d||Q&&u===null?e("div",{className:"AssetBrowser__loading",children:e(te,{color:"gray",size:"lg"})}):Se.length===0?e("div",{className:"AssetBrowser__empty","data-testid":"asset-browser-empty",children:v?e("div",{children:['No assets match "',v,'" in this folder or its subfolders.']}):e(C,{children:[e("div",{children:"This folder is empty."}),Y&&e("div",{className:"AssetBrowser__empty__hint",children:'Drop files here or click "Upload" to add assets.'})]})}):e(re,{className:"AssetBrowser__table",verticalSpacing:"xs",fontSize:"xs",highlightOnHover:!0,children:[e("thead",{children:e("tr",{children:[le&&e("th",{className:"AssetBrowser__table__checkboxCol",children:e(G,{size:"xs","aria-label":"Select all",checked:xe,indeterminate:!xe&&j.some(s=>y.has(s.id)),onChange:()=>Ct()})}),e("th",{children:"name"}),e("th",{className:"AssetBrowser__table__modifiedCol",children:"modified"}),e("th",{className:"AssetBrowser__table__actionsCol"})]})}),e("tbody",{children:j.map(s=>s.type==="folder"?e("tr",{className:"AssetBrowser__row AssetBrowser__row--folder",onClick:()=>L(oe(s.parent,s.name)),children:[le&&e("td",{className:"AssetBrowser__checkboxCell",onClick:_=>_.stopPropagation(),children:e(G,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>Re(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e("div",{className:"AssetBrowser__thumb",children:e(ze,{size:24,stroke:"1.5"})}),e("div",{className:"AssetBrowser__nameCell__text",children:[e("div",{className:"AssetBrowser__nameCell__name",children:s.name}),e(wt,{asset:s,folder:l,searching:Q,onNavigate:L})]})]})}),e("td",{children:e(bt,{asset:s})}),e("td",{onClick:_=>_.stopPropagation(),children:e("div",{className:"AssetBrowser__actionsCell",children:t.mode==="manage"&&J&&e(k,{shadow:"sm",position:"bottom",placement:"end",control:e(se,{size:"sm",children:e(De,{size:16})}),children:[e(k.Item,{icon:e(Ie,{size:14}),onClick:()=>z(s),children:"Rename"}),e(k.Item,{icon:e(ve,{size:14}),onClick:()=>E([s]),children:"Move"}),e(k.Item,{color:"red",icon:e(W,{size:14}),onClick:()=>P([s]),children:"Delete"})]})})})]},s.id):e("tr",{className:"AssetBrowser__row AssetBrowser__row--file",onClick:()=>{t.mode==="pick"?yt(s):p(s)},children:[le&&e("td",{className:"AssetBrowser__checkboxCell",onClick:_=>_.stopPropagation(),children:e(G,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>Re(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e(ht,{file:s.file,size:36}),e("div",{className:"AssetBrowser__nameCell__text",children:[e("div",{className:"AssetBrowser__nameCell__name",children:[s.name,!!(s.file?.width&&s.file?.height)&&e("span",{className:"AssetBrowser__nameCell__dimens",children:[" ","(",s.file.width,"x",s.file.height,")"]})]}),e(wt,{asset:s,folder:l,searching:Q,onNavigate:L})]})]})}),e("td",{children:e(bt,{asset:s})}),e("td",{onClick:_=>_.stopPropagation(),children:e("div",{className:"AssetBrowser__actionsCell",children:t.mode!=="pick"&&e(Ft,{asset:s,canManage:J,onDetails:()=>p(s),onRename:()=>z(s),onMove:()=>E([s]),onDelete:()=>P([s])})})})]},s.id))})]})}),T.totalPages>1&&e("div",{className:"AssetBrowser__footer",children:[e(pt,{start:T.start,end:T.end,total:T.totalItems,noun:"asset"}),e(gt,{total:T.totalPages,page:T.page,onChange:T.setPage})]}),e(Nt,{opened:R,parent:l,onClose:()=>X(!1),onCreated:s=>{X(!1),L(oe(l,s))}}),q&&e(Dt,{asset:q,onClose:()=>z(null),onRenamed:()=>{z(null),I(l)}}),K&&K.length>0&&e(zt,{assets:K,onClose:()=>E(null),onMoved:()=>{E(null),I(l)}}),$&&$.length>0&&e(Tt,{assets:$,onClose:()=>P(null),onDeleted:()=>{P(null),I(l)}}),Z&&Z.length>0&&e(Ut,{assets:Z,onClose:()=>c(null),onDone:()=>{c(null),I(l)}}),b&&e(vt,{asset:b,canManage:J,onClose:()=>p(null),onChanged:()=>I(l),onDeleted:()=>{p(null),I(l)}})]})}Ue.Breadcrumbs=t=>{let o=Ke(t.folder),a=[{label:"Assets",path:""}];return o.forEach((l,r)=>{a.push({label:l,path:o.slice(0,r+1).join("/")})}),e("div",{className:"AssetBrowser__breadcrumbs",children:a.map((l,r)=>e("div",{className:"AssetBrowser__breadcrumbs__crumb",children:[r>0&&e(Ne,{className:"AssetBrowser__breadcrumbs__divider",size:14}),e("button",{className:ue("AssetBrowser__breadcrumbs__link",r===a.length-1&&"active"),disabled:r===a.length-1,onClick:()=>t.onNavigate(l.path),children:l.label})]},l.path))})};function Ft(t){let o=t.asset;return e(k,{shadow:"sm",position:"bottom",placement:"end",control:e(se,{size:"sm",children:e(De,{size:16})}),children:[e(k.Item,{icon:e(dt,{size:14}),onClick:t.onDetails,children:"Details"}),e(k.Item,{icon:e(ge,{size:14}),onClick:()=>we(o.file),children:"Copy URL"}),e(k.Item,{icon:e(pe,{size:14}),onClick:()=>be(o.file),children:"Download"}),t.canManage&&e(C,{children:[e(k.Item,{icon:e(Ie,{size:14}),onClick:t.onRename,children:"Rename"}),e(k.Item,{icon:e(ve,{size:14}),onClick:t.onMove,children:"Move"}),e(k.Item,{color:"red",icon:e(W,{size:14}),onClick:t.onDelete,children:"Delete"})]})]})}function wt(t){let o=t.asset;return!t.searching||o.parent===t.folder?null:e("button",{className:"AssetBrowser__nameCell__path",title:"Go to folder",onClick:a=>{a.stopPropagation(),t.onNavigate(o.parent)},children:["in ",Je(o.parent,t.folder)]})}function bt(t){let o=t.asset.modifiedAt||t.asset.createdAt,a=t.asset.modifiedBy||t.asset.createdBy||"",l=o&&typeof o.toMillis=="function"?o.toMillis():0;return e("div",{className:"AssetBrowser__modifiedCell",children:[a&&e(lt,{email:a,size:20}),e("span",{children:l?Ve(l):"\u2014"})]})}function Nt(t){let[o,a]=i(""),[l,r]=i(!1);async function m(){r(!0),await M(async()=>{let d=await Ye(t.parent,o);a(""),t.onCreated(d.name)}),r(!1)}return e(S,{opened:t.opened,onClose:t.onClose,title:"New folder",size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),m()},children:[e(H,{"data-autofocus":!0,placeholder:"Folder name",value:o,onChange:d=>a(d.currentTarget.value)}),e(g,{type:"submit",color:"dark",loading:l,disabled:!o,children:"Create"})]})})}function Dt(t){let[o,a]=i(t.asset.name),[l,r]=i(!1);async function m(){r(!0),await M(async()=>{await tt(t.asset,o),t.onRenamed()}),r(!1)}return e(S,{opened:!0,onClose:t.onClose,title:`Rename ${t.asset.type}`,size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),m()},children:[e(H,{"data-autofocus":!0,value:o,onChange:d=>a(d.currentTarget.value)}),e(g,{type:"submit",color:"dark",loading:l,disabled:!o,children:"Rename"})]})})}function zt(t){let o=t.assets,[a,l]=i(o[0]?.parent||""),[r,m]=i([]),[d,x]=i(!0),[v,f]=i(!1);U(()=>{x(!0),M(async()=>{let n=await Me(a);m(n.filter(u=>u.type==="folder"))}).then(()=>x(!1))},[a]);let B=o.filter(n=>n.type==="folder").map(n=>oe(n.parent,n.name));function w(n){return B.some(u=>n===u||n.startsWith(`${u}/`))}async function F(){f(!0);let n=[],u=0;for(let N of o)try{await st(N,a),u+=1}catch(R){console.error(`failed to move ${N.name}:`,R),n.push(N.name)}f(!1),n.length>0&&A({title:"Move failed",message:`Failed to move: ${n.join(", ")}`,color:"red",autoClose:!1}),u>0&&A({message:o.length===1?`Moved "${o[0].name}" to ${a||"Assets"}.`:`Moved ${u} item(s) to ${a||"Assets"}.`,color:"green"}),t.onMoved()}return e(S,{opened:!0,onClose:t.onClose,title:o.length===1?`Move "${o[0].name}"`:`Move ${o.length} items`,size:"md",centered:!0,children:e("div",{className:"AssetBrowser__moveModal",children:[e(Ue.Breadcrumbs,{folder:a,onNavigate:l}),e("div",{className:"AssetBrowser__moveModal__folders",children:d?e(te,{color:"gray",size:"sm"}):r.length===0?e("div",{className:"AssetBrowser__moveModal__empty",children:"No subfolders."}):r.map(n=>{let u=oe(n.parent,n.name);return e("button",{className:"AssetBrowser__moveModal__folder",disabled:w(u),onClick:()=>l(u),children:[e(ze,{size:16,stroke:"1.5"}),e("span",{children:n.name}),e(Ne,{size:14})]},n.id)})}),e(g,{color:"dark",fullWidth:!0,loading:v,disabled:o.every(n=>n.parent===a),onClick:()=>F(),children:"Move here"})]})})}var It=20;function Tt(t){let o=t.assets,[a,l]=i(!1),[r,m]=i(null),d=o.filter(f=>f.type==="file"),x=o.some(f=>f.type==="folder");U(()=>{d.length===0||d.length>It||Promise.all(d.map(f=>_e(f.id))).then(f=>{let B=new Set(f.flat().map(w=>w.id));m(B.size)}).catch(()=>m(null))},[o.map(f=>f.id).join(",")]);async function v(){l(!0);let f=[],B=0;for(let w of o)try{await ce(w),B+=1}catch(F){console.error(`failed to delete ${w.name}:`,F),f.push(w.name)}l(!1),f.length>0&&A({title:"Delete failed",message:`Failed to delete: ${f.join(", ")}. Note that folders must be empty before they can be deleted.`,color:"red",autoClose:!1}),B>0&&A({message:o.length===1?`Deleted "${o[0].name}".`:`Deleted ${B} item(s).`,color:"green"}),t.onDeleted()}return e(S,{opened:!0,onClose:t.onClose,title:o.length===1?`Delete ${o[0].type}?`:`Delete ${o.length} items?`,size:"sm",centered:!0,children:e("div",{className:"AssetBrowser__deleteModal",children:[e("div",{className:"AssetBrowser__deleteModal__text",children:["Are you sure you want to delete"," ",o.length===1?e("b",{children:o[0].name}):e("b",{children:[o.length," items"]})," ","from the asset manager?",d.length>0&&e(C,{children:[" ","The underlying files are not deleted from GCS, and docs that currently use the assets keep their copy of the files."]}),x&&e(C,{children:" Folders must be empty before they can be deleted."})]}),r!==null&&r>0&&e("div",{className:"AssetBrowser__deleteModal__warning",children:[o.length===1?"This asset is":"These assets are"," ","currently used in ",r," doc(s). Those docs will no longer receive updates when the asset changes."]}),e("div",{className:"AssetBrowser__deleteModal__buttons",children:[e(g,{variant:"default",onClick:t.onClose,disabled:a,children:"Cancel"}),e(g,{color:"red",loading:a,onClick:()=>v(),children:"Delete"})]})]})})}function Ut(t){let o=t.assets,[a,l]=i(!1);async function r(){l(!0);let m=[],d=0;for(let x of o)try{let v=x.file,f=await me(x,!0);await fe(f,{previousFile:v}),d+=1}catch(v){console.error(`failed to disable alt text for ${x.name}:`,v),m.push(x.name)}l(!1),m.length>0&&A({title:"Failed to disable alt text",message:`Failed to update: ${m.join(", ")}`,color:"red",autoClose:!1}),d>0&&A({message:`Disabled alt text for ${d} file(s).`,color:"green"}),t.onDone()}return e(S,{opened:!0,onClose:t.onClose,title:"Disable alt text?",size:"sm",centered:!0,children:e("div",{className:"AssetBrowser__deleteModal",children:[e("div",{className:"AssetBrowser__deleteModal__text",children:["Disable alt text for ",e("b",{children:[o.length," file(s)"]}),"? The alt text input is hidden in docs that use these assets and their embedded alt text is cleared. Alt text can be re-enabled per asset from its details."]}),e("div",{className:"AssetBrowser__deleteModal__buttons",children:[e(g,{variant:"default",onClick:t.onClose,disabled:a,children:"Cancel"}),e(g,{color:"dark",loading:a,onClick:()=>r(),children:"Disable alt text"})]})]})})}export{Ue as a};
@@ -1 +1 @@
1
- import{d as eo}from"./chunk-PPYM4O5N.js";import{f as He}from"./chunk-DS27MO63.js";import{b as Le,c as $e,e as Ve,j as Se}from"./chunk-IOR72US3.js";import{a as N,c as H}from"./chunk-HARRKJFZ.js";import{a as _e,b as ge,c as ae}from"./chunk-JDW4UORS.js";import{A as ye,E as ve,F as xe,G as Ce,H as Ie,I as le,J as ke,K as Ae,L as we,M as De,N as Te,O as Re,P as Pe,S as de,T as Ne,U as ze}from"./chunk-Z6DBYLIM.js";import{b as be,f as Me}from"./chunk-C2BLMTPR.js";import{a as Je,b as Ke}from"./chunk-W5DOO6ID.js";import{a as Xe}from"./chunk-NSOTG64N.js";import{b as U}from"./chunk-J5E457OI.js";import{a as _,b as F}from"./chunk-QHJOTXYB.js";import{a as M}from"./chunk-BW2MKGNP.js";import{e as he}from"./chunk-KRNQ6L35.js";import{d as fe}from"./chunk-BUNR5EU3.js";import{$ as ue,Da as pe,Ga as e,Ha as Ee,Ka as Ue,La as Be,Na as Oe,Nb as je,Qa as Fe,Rc as Ge,V as J,W as Q,a as c,c as j,cc as Y,da as b,dc as ee,e as ce,ea as ie,ib as qe,ic as Qe,j as X,kc as Ye,lb as K,qa as P,tb as We,ua as me,xa as ne,yc as Ze}from"./chunk-LROR6N3B.js";import{d as S}from"./chunk-KUCVLANF.js";X();var oo="AddToReleaseModal";function so(s){let t=N(),u=H();return{open:()=>{t.openContextModal(oo,{...u,title:"Add docs to a release",innerProps:s,size:"600px"})}}}function mo(s){let{innerProps:t,context:u,id:l}=s,d=N(),[o,y]=c(""),[p,v]=c(!1),[m,k]=c(!1),[g,A]=c([]),[a,D]=c(""),[x,T]=c(Se()),[w,f]=c("");j(()=>{async function n(){v(!0),await U(async()=>{let E=(await $e()).filter(R=>!R.publishedAt&&!R.archivedAt);A(E)}),v(!1)}n()},[]);async function I(){o==="new"?await L():o==="existing"&&await $()}async function L(){if(!x){_({title:"Missing ID",message:"Please enter a release ID.",color:"red",autoClose:5e3});return}if(!_e(x)){_({title:"Invalid ID",message:"Release ID must use alphanumeric characters and dashes only.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let n={docIds:t.docIds};w&&(n.description=w),await Le(x,n),_({title:`Release created: ${x}`,message:e("span",{children:["Created release with ",t.docIds.length," doc(s)."," ",e("a",{href:`/cms/releases/${x}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}async function $(){if(!a){_({title:"No release selected",message:"Please select a release.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let C=g.find(z=>z.id===a)?.docIds||[],E=Array.from(new Set([...C,...t.docIds])).sort();await Ve(a,{docIds:E});let R=E.length-C.length;_({title:`Docs added to release: ${a}`,message:e("span",{children:["Added ",R," new doc(s) to release."," ",e("a",{href:`/cms/releases/${a}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}let r=!0;return(o==="new"&&x||o==="existing"&&a)&&(r=!1),e("div",{className:"AddToReleaseModal",children:e("div",{className:"AddToReleaseModal__content",children:[e("div",{className:"AddToReleaseModal__docs",children:[e("div",{className:"AddToReleaseModal__docs__label",children:["Docs to add (",t.docIds.length,")"]}),e("div",{className:"AddToReleaseModal__docs__list",children:t.docIds.map(n=>e(He,{docId:n,variant:"compact",statusBadges:!0},n))})]}),e("div",{className:"AddToReleaseModal__mode",children:[e("label",{className:`AddToReleaseModal__mode__option${o==="new"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"new",checked:o==="new",onChange:()=>y("new")})," ","New release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Create a new release with these docs."})]}),e("label",{className:`AddToReleaseModal__mode__option${o==="existing"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"existing",checked:o==="existing",onChange:()=>y("existing")})," ","Existing release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Add to an existing release."})]})]}),o==="new"&&e("div",{className:"AddToReleaseModal__form",children:[e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Release ID"}),e("input",{type:"text",placeholder:"e.g. my-release",value:x,onInput:n=>{T(n.target.value)}})]}),e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Description (optional)"}),e("textarea",{rows:2,placeholder:"Describe this release",value:w,onInput:n=>{f(n.target.value)}})]})]}),o==="existing"&&e("div",{className:"AddToReleaseModal__releases",children:p?e("div",{className:"AddToReleaseModal__releases__empty",children:e(J,{color:"gray",size:"sm"})}):g.length===0?e("div",{className:"AddToReleaseModal__releases__empty",children:"No unpublished releases found. Create a new one instead."}):g.map(n=>e("div",{className:`AddToReleaseModal__release${a===n.id?" AddToReleaseModal__release--selected":""}`,onClick:()=>D(n.id),children:[e("input",{type:"radio",name:"existing-release",checked:a===n.id,onChange:()=>D(n.id)}),e("div",{className:"AddToReleaseModal__release__info",children:[e("div",{className:"AddToReleaseModal__release__info__id",children:n.id}),n.description&&e("div",{className:"AddToReleaseModal__release__info__description",children:n.description})]}),e("div",{className:"AddToReleaseModal__release__docCount",children:[n.docIds?.length||0," doc(s)"]})]},n.id))}),e("div",{className:"AddToReleaseModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",disabled:r,loading:m,onClick:I,children:o==="new"?"Create release":"Add to release"})]})]})})}mo.id=oo;X();var to="CopyDocModal";function oe(s){let t=N(),u=H();return{open:l=>{t.openContextModal(to,{...u,innerProps:{...s,...l}})}}}function po(s){let{innerProps:t,context:u,id:l}=s,{route:d}=fe(),[o,y]=c(""),[p,v]=c(""),[m,k]=c(""),[g,A]=c(""),[a,D]=c(!1),[x,T]=c(!1),[w,f]=c({}),I=t.fromDocId,L=I.split("/")[0],$=t.fromLabel||I;j(()=>{be({tags:[I]}).then(f)},[I]);function r(C,E){let R=ae(C),z=window.__ROOT_CTX.collections[E]?.slugRegex;return R?ge(R,z):""}async function n(C){if(C.preventDefault(),T(!0),A(""),!L){A("Please select a collection."),T(!1);return}if(r(p,o)){T(!1);return}let R=ae(p),z=`${o}/${R}`;try{t.fields?await Pe(z,{fields:t.fields,overwrite:a}):await Re(I,z,{overwrite:a});let O=Object.keys(w);if(O.length>0){let i=O.map(h=>({hash:h,tags:[z]}));await Me(i,{mode:"union"})}u.closeModal(l);let q=`/cms/content/${o}/${R}`;_({title:"Copied!",message:e("div",{children:[e("div",{children:`Successfully copied ${$} to ${z}.`}),e(b,{className:"CopyDocModal__notificationButton",component:"a",href:q,size:"xs",compact:!0,variant:"default",children:"Open doc"})]}),autoClose:1e4}),t.onSuccess&&t.onSuccess(z)}catch(O){let q=String(O);A(q),q.includes("already exists")&&D(!0),T(!1);return}T(!1),d(`/cms/content/${o}/${R}`)}return e("div",{className:"CopyDocModal",children:e("form",{onSubmit:C=>n(C),children:[e("div",{className:"CopyDocModal__from",children:[e(M,{className:"CopyDocModal__from__label",size:"body",weight:"bold",children:"From:"}),e(M,{className:"CopyDocModal__from__value",size:"body-sm",children:e("code",{children:$})})]}),e("div",{className:"CopyDocModal__to",children:[e(M,{className:"CopyDocModal__to__label",size:"body",weight:"bold",children:"To:"}),e(eo,{className:"CopyDocModal__slug",collectionId:L,onChange:C=>{y(C.collectionId),v(C.slug),k(r(C.slug,C.collectionId)),A(""),D(!1)}})]}),g&&e("div",{className:"CopyDocModal__error",children:g}),e("div",{className:"CopyDocModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",type:"submit",size:"xs",color:"dark",loading:x,disabled:!!m||!!g&&!a,children:a?"Overwrite?":"Submit"})]})]})})}po.id=to;X();function B(s){return e("div",{className:"DocIdBadge",children:e("code",{"data-testid":"doc-id",children:s.docId})})}var io="LockPublishingModal";function no(s){let t=N(),u=H();return{open:l=>{let d={...s,...l},o;d.unlock?o=`Unlock publishing for ${s.docId}`:d.existingLock?o=`Edit publishing lock for ${s.docId}`:o=`Lock publishing for ${s.docId}`,t.openContextModal(io,{...u,title:o,innerProps:{...s,...l},size:"600px"})}}}function fo(s){let t=l=>l<10?"0"+l:l,u=new Date(s);return`${u.getFullYear()}-${t(u.getMonth()+1)}-${t(u.getDate())}T${t(u.getHours())}:${t(u.getMinutes())}`}function Z(s){let{innerProps:t}=s;return t.unlock?e(Z.Unlock,{...s}):e(Z.Lock,{...s})}Z.Lock=s=>{let{innerProps:t,context:u,id:l}=s,d=!!t.existingLock,[o,y]=c(t.existingLock?.reason||""),[p,v]=c(t.existingLock?.until||0),[m,k]=c(!1),[g,A]=c(!1),a=N();function D(f){return f?Math.floor(new Date(f).getTime()):0}async function x(f){f.preventDefault(),k(!0),await U(async()=>{await Ie(t.docId,{reason:o,until:p}),_({title:d?"Updated!":"Locked!",message:d?`Publishing lock updated for ${t.docId}.`:`Publishing is locked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("locked")}),k(!1)}async function T(){A(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("unlocked")}),A(!1)}return e("div",{className:"LockPublishingModal LockPublishingModal--lock",children:[e(M,{className:"LockPublishingModal__body",size:"body-sm",children:d?"Publishing is currently locked. Update the publishing lock details below, or remove the lock to re\u2011enable publishing.":"Are you sure you want to lock publishing? Content editors will not be able to publish until publishing is unlocked."}),e("form",{className:"LockPublishingModal__form",onSubmit:f=>x(f),children:[e("div",{className:"LockPublishingModal__form__section",children:e(me,{name:"reason",label:"Reason",description:"Specify a short reason so other content editors know why publishing is locked.",size:"xs",radius:0,value:o,onChange:f=>{y(f.currentTarget.value)}})}),e("div",{className:"LockPublishingModal__form__section",children:e(ue,{label:"Lock until",description:"Optional. Publishing is unlocked at the specified time. If not provided, publishing will be locked indefinitely.",size:"xs",children:e("div",{className:"DocEditor__DateTimeField",children:[e("input",{name:"until",type:"datetime-local",min:he(),defaultValue:p?fo(p):"",onChange:f=>{let L=f.target.value;v(D(L))}}),e("div",{className:"DocEditor__DateTimeField__timezone",children:["timezone: ",Intl.DateTimeFormat().resolvedOptions().timeZone]})]})})}),e("div",{className:"LockPublishingModal__buttons",children:[d&&e(b,{variant:"filled",size:"xs",color:"red",type:"button",leftIcon:e(Y,{size:14}),loading:g,disabled:m,onClick:()=>T(),className:"LockPublishingModal__buttons__unlock",children:"Unlock"}),e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(ee,{size:14}),disabled:!o||g,type:"submit",loading:m,children:d?"Save":"Lock"})]})]})]})};Z.Unlock=s=>{let{innerProps:t,context:u,id:l}=s,[d,o]=c(!1),y=N();async function p(){o(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),y.closeModal(l),t.onChange&&t.onChange("unlocked")})}return e("div",{className:"LockPublishingModal LockPublishingModal--unlock",children:[e(M,{className:"LockPublishingModal__body",children:"Are you sure you want to unlock publishing for the following doc? This will re-enable content editors to publish the doc."}),e(B,{docId:t.docId}),e("div",{className:"LockPublishingModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(Y,{size:14}),loading:d,onClick:()=>p(),children:"Unlock"})]})]})};Z.id=io;X();var ro="VersionHistoryModal",ao=50;function co(s){let t=N(),u=H();return{open:()=>{t.openContextModal(ro,{...u,title:`Version history: ${s.docId}`,innerProps:s,overflow:"inside",size:"min(calc(100% - 32px), 720px)"})}}}function _o(s){let{innerProps:t,context:u,id:l}=s,d=t.docId,[o,y]=c(!0),[p,v]=c(!1),[m,k]=c([]),[g,A]=c(!1),[a,D]=c([]),[x,T]=c(!1),[w,f]=c(null),I=ce(null),L=oe({fromDocId:d}),$=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});async function r(){y(!0);let[i,h]=await Promise.all([de(d,{limit:ao}),ze(d,"draft")]);I.current=i.lastDoc,A(i.hasMore);let V={_versionId:"draft",sys:{modifiedAt:h?.sys?.modifiedAt||{toDate:()=>new Date},modifiedBy:h?.sys?.modifiedBy||"Unknown"}};k([V,...i.versions]),D(["draft"]),y(!1)}async function n(){if(!g||p)return;v(!0);let i=await de(d,{limit:ao,cursor:I.current});I.current=i.lastDoc,A(i.hasMore),k(h=>[...h,...i.versions]),v(!1)}async function C(i){await Ne(d,i),_({title:"Saved!",message:`Restored ${d} to ${$.format(i.sys.modifiedAt.toDate())}.`,autoClose:5e3}),t.onRestore&&t.onRestore({version:i})}function E(i){let h=`${d}@${i._versionId}`,V=i.sys?.modifiedAt?.toDate();if(V){let W=go(V);h=`${d}@${W}`}L.open({fields:i.fields||{},fromLabel:h,onSuccess:()=>{u.closeModal(l)}})}function R(i){a.includes(i)?D(a.filter(h=>h!==i)):a.length<2&&D([...a,i])}function z(){if(a.length!==2)return"#";let i=m.find(te=>te._versionId===a[0]),h=m.find(te=>te._versionId===a[1]);if(!i||!h)return"#";let V=m.indexOf(i),W=m.indexOf(h),re=V>W?i:h,G=V>W?h:i,se=lo(d,re._versionId),uo=lo(d,G._versionId);return`/cms/compare?left=${se}&right=${uo}`}j(()=>{r()},[]);let O=m.filter(i=>i._versionId==="draft"||!x?!0:i.tags?.includes("published")),q=m.some(i=>i.tags?.includes("published"));return o?e(J,{}):e("div",{className:"VersionHistoryModal",children:[e("div",{className:"VersionHistoryModal__actions",children:[e(b,{component:a.length===2?"a":"button",variant:"filled",size:"xs",disabled:a.length!==2,href:a.length===2?z():void 0,target:a.length===2?"_blank":void 0,rightIcon:e(Fe,{size:16}),children:"Compare"}),q&&e(ie,{size:"xs",label:"Published versions only",checked:x,onChange:i=>T(i.currentTarget.checked)})]}),O.length===0?e(M,{className:"VersionHistoryModal__versionsEmpty",size:"body",children:[e("p",{children:"No versions found."}),e("p",{className:"VersionHistoryModal__versionsEmpty__developer",children:"For developers: Configure the Root CMS cron job to populate versions."})]}):e(S,{children:[e(pe,{className:"VersionHistoryModal__versions",children:[e("thead",{children:e("tr",{children:[e("th",{children:e("span",{className:"VersionHistoryModal__versions__selectLabel",children:"Select"})}),e("th",{children:"modified at"}),e("th",{children:"modified by"}),e("th",{children:"actions"})]})}),e("tbody",{children:O.map(i=>{let h=i._versionId==="draft",V=a.includes(i._versionId),W=!V&&a.length>=2;return e("tr",{children:[e("td",{children:e(ie,{size:"xs",checked:V,disabled:W,onChange:()=>R(i._versionId),className:"VersionHistoryModal__versions__checkbox"})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__modifiedAt",children:[e(M,{size:"body-sm",className:"VersionHistoryModal__versions__modifiedAt__text",children:h?e("span",{title:"Current Draft",children:[$.format(i.sys.modifiedAt.toDate())," ","(Latest)"]}):e(S,{children:[$.format(i.sys.modifiedAt.toDate()),i.tags?.includes("published")&&e("span",{className:"VersionHistoryModal__publishedLabel",children:"(Published)"})]})}),i.publishMessage&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-message`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,classNames:{body:"VersionHistoryModal__popover__body",arrow:"VersionHistoryModal__popover__arrow",close:"VersionHistoryModal__popover__close"},target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-message`?null:`${i._versionId}-message`),children:e(Qe,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:i.publishMessage})}),(()=>{let G=i.tags?.find(se=>se.startsWith("release:"))?.replace("release:","");return G&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-release`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-release`?null:`${i._versionId}-release`),children:e(Ze,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:[e("strong",{children:"Release:"})," ",G]})})})()]})}),e("td",{children:e(M,{size:"body-sm",children:i.sys.modifiedBy})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__buttons",children:!h&&e(S,{children:[e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>C(i),children:"restore"}),e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>E(i),leftIcon:e(K,{size:12}),children:"copy to doc"})]})})})]},i._versionId)})})]}),g&&e("div",{className:"VersionHistoryModal__loadMore",children:e(b,{variant:"subtle",size:"xs",loading:p,onClick:n,children:"Load more versions"})})]})]})}function lo(s,t){return encodeURIComponent(`${s}@${t}`).replaceAll("%2F","/").replaceAll("%40","@")}function go(s){let t=s.getFullYear(),u=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0"),d=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${t}-${u}-${l}T${d}:${o}`}_o.id=ro;function Js(s){let{roles:t}=Xe(),u=window.firebase.user.email||"",l=Ke(t,u),d=Je(t,u),o=s.docId,y=s.data||{},p=y.sys||{},v=we(y),m=N(),k=oe({fromDocId:o,onSuccess:r=>{s.onAction&&s.onAction({action:"copy",newDocId:r})}}),g=H(),A=co({docId:o}),a=no({docId:o}),D=so({docIds:[o]}),x=()=>{let r=`revert-draft-${o}`,n=m.openConfirmModal({...g,title:`Discard draft edits for ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to discard draft changes for the following doc? The doc data will revert to the published version. There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Discard draft edits",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Discarding draft edits",message:`Discarding draft edits of ${o}...`,loading:!0,autoClose:!1}),await xe(o),F({id:r,title:"Discarded draft edits",message:`Successfully reverted ${o} back to its published version`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"revert-draft"})}})},T=()=>{let r=`unpublish-doc-${o}`,n=m.openConfirmModal({...g,title:`Unpublish ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unpublish the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Unpublish",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unpublishing doc",message:`Requesting unpublish of ${o}...`,loading:!0,autoClose:!1}),await ve(o),F({id:r,title:"Unpublished!",message:`Successfully unpublished ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unpublish"})}})},w=r=>{s.onAction&&s.onAction({action:r})},f=()=>{let r=`unschedule-doc-${o}`,n=m.openConfirmModal({...g,title:`Unschedule ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unschedule the following doc?"}),e(B,{docId:o})]}),labels:{confirm:"Unschedule",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unschedule doc",message:`Requesting unschedule of ${o}...`,loading:!0,autoClose:!1}),await Ce(o),F({id:r,title:"Unscheduled!",message:`Successfully unscheduled ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unschedule"})}})},I=()=>{let r=`archive-doc-${o}`,n=m.openConfirmModal({...g,title:`Archive ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to archive the following doc? Archived docs are hidden from the collection list by default but can be restored later."}),e(B,{docId:o})]}),labels:{confirm:"Archive",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Archiving doc",message:`Requesting archive of ${o}...`,loading:!0,autoClose:!1}),await ke(o),F({id:r,title:"Archived!",message:`Successfully archived ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"archive"})}})},L=async()=>{let r=`unarchive-doc-${o}`;_({id:r,title:"Unarchiving doc",message:`Requesting unarchive of ${o}...`,loading:!0,autoClose:!1}),await Ae(o),F({id:r,title:"Unarchived!",message:`Successfully unarchived ${o}!`,loading:!1,autoClose:5e3}),s.onAction&&s.onAction({action:"unarchive"})},$=()=>{let r=`delete-doc-${o}`,n=m.openConfirmModal({...g,title:"Delete doc",children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to delete the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Delete",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Deleting doc",message:`Requesting deletion of ${o}...`,loading:!0,autoClose:!1}),await ye(o),F({id:r,title:"Deleted!",message:`Successfully deleted ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onDelete&&s.onDelete(),s.onAction&&s.onAction({action:"delete"})}})};return e(P,{className:"CollectionPage__collection__docsList__doc__controls__menu",position:"bottom",control:e(Q,{className:"DocEditor__ArrayField__item__header__controls__dots",children:e(We,{size:16})}),children:[!v&&e(P.Item,{icon:e(Ye,{size:20}),onClick:()=>D.open(),disabled:!d,children:"Add to release"}),e(P.Item,{icon:e(je,{size:20}),onClick:()=>A.open(),children:"Version history"}),e(P.Item,{icon:e(K,{size:20}),onClick:()=>k.open(),disabled:!l,children:"Copy"}),!v&&p.modifiedAt&&p.publishedAt&&p.modifiedAt>p.publishedAt&&e(P.Item,{icon:e(Oe,{size:20}),onClick:()=>x(),disabled:!l,children:"Discard draft edits"}),!v&&p.firstPublishedAt&&e(P.Item,{icon:e(qe,{size:20}),onClick:()=>T(),disabled:!d,children:"Unpublish"}),!v&&p.scheduledAt&&e(P.Item,{icon:e(Ee,{size:20}),onClick:()=>f(),disabled:!d,children:"Unschedule"}),!v&&(Te(y)?e(P.Item,{icon:e(Y,{size:20}),onClick:()=>a.open({unlock:!0,onChange:w}),disabled:!l,children:"Unlock publishing"}):e(P.Item,{icon:e(ee,{size:20}),onClick:()=>a.open({unlock:!1,onChange:w}),disabled:!l||De(y),children:"Lock publishing"})),v?e(P.Item,{icon:e(Ue,{size:20}),onClick:()=>L(),disabled:!l,children:"Unarchive"}):!p.publishedAt&&e(P.Item,{icon:e(Be,{size:20}),onClick:()=>I(),disabled:!l,children:"Archive"}),e(P.Item,{icon:e(Ge,{size:20}),onClick:()=>$(),disabled:!l,children:"Delete"})]})}export{so as a,mo as b,po as c,B as d,no as e,Z as f,_o as g,Js as h};
1
+ import{d as eo}from"./chunk-UPN3EMUS.js";import{g as He}from"./chunk-TNW2GNUR.js";import{b as Le,c as $e,e as Ve,j as Se}from"./chunk-FVWSVOOY.js";import{a as _e,b as ge,c as ae}from"./chunk-JDW4UORS.js";import{a as N,c as H}from"./chunk-QRAFYIAW.js";import{a as Je,b as Ke}from"./chunk-W5DOO6ID.js";import{a as Xe}from"./chunk-YBHFGQ3Z.js";import{b as U}from"./chunk-2PTLQRTU.js";import{a as _,b as F}from"./chunk-PIJ3E47R.js";import{a as M}from"./chunk-NCZD5IWS.js";import{A as ye,E as ve,F as xe,G as Ce,H as Ie,I as le,J as ke,K as Ae,L as we,M as De,N as Te,O as Re,P as Pe,S as de,T as Ne,U as ze}from"./chunk-ISUGBMXC.js";import{b as be,f as Me}from"./chunk-DZYYWCHX.js";import{C as he}from"./chunk-XOWWPE7X.js";import{d as fe}from"./chunk-WASID5UU.js";import{$ as ue,Cc as Ze,Da as pe,Ga as e,Ha as Ee,Ka as Ue,La as Be,Na as Oe,Qa as Fe,Rb as je,V as J,Vc as Ge,W as Q,a as c,c as j,da as b,e as ce,ea as ie,gc as Y,hc as ee,j as X,lb as qe,mc as Qe,oc as Ye,pb as K,qa as P,ua as me,xa as ne,xb as We}from"./chunk-WRA24P66.js";import{d as S}from"./chunk-KUCVLANF.js";X();var oo="AddToReleaseModal";function so(s){let t=N(),u=H();return{open:()=>{t.openContextModal(oo,{...u,title:"Add docs to a release",innerProps:s,size:"600px"})}}}function mo(s){let{innerProps:t,context:u,id:l}=s,d=N(),[o,y]=c(""),[p,v]=c(!1),[m,k]=c(!1),[g,A]=c([]),[a,D]=c(""),[x,T]=c(Se()),[w,f]=c("");j(()=>{async function n(){v(!0),await U(async()=>{let E=(await $e()).filter(R=>!R.publishedAt&&!R.archivedAt);A(E)}),v(!1)}n()},[]);async function I(){o==="new"?await L():o==="existing"&&await $()}async function L(){if(!x){_({title:"Missing ID",message:"Please enter a release ID.",color:"red",autoClose:5e3});return}if(!_e(x)){_({title:"Invalid ID",message:"Release ID must use alphanumeric characters and dashes only.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let n={docIds:t.docIds};w&&(n.description=w),await Le(x,n),_({title:`Release created: ${x}`,message:e("span",{children:["Created release with ",t.docIds.length," doc(s)."," ",e("a",{href:`/cms/releases/${x}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}async function $(){if(!a){_({title:"No release selected",message:"Please select a release.",color:"red",autoClose:5e3});return}k(!0),await U(async()=>{let C=g.find(z=>z.id===a)?.docIds||[],E=Array.from(new Set([...C,...t.docIds])).sort();await Ve(a,{docIds:E});let R=E.length-C.length;_({title:`Docs added to release: ${a}`,message:e("span",{children:["Added ",R," new doc(s) to release."," ",e("a",{href:`/cms/releases/${a}`,children:"View release"})]}),autoClose:1e4}),d.closeAll()}),k(!1)}let r=!0;return(o==="new"&&x||o==="existing"&&a)&&(r=!1),e("div",{className:"AddToReleaseModal",children:e("div",{className:"AddToReleaseModal__content",children:[e("div",{className:"AddToReleaseModal__docs",children:[e("div",{className:"AddToReleaseModal__docs__label",children:["Docs to add (",t.docIds.length,")"]}),e("div",{className:"AddToReleaseModal__docs__list",children:t.docIds.map(n=>e(He,{docId:n,variant:"compact",statusBadges:!0},n))})]}),e("div",{className:"AddToReleaseModal__mode",children:[e("label",{className:`AddToReleaseModal__mode__option${o==="new"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"new",checked:o==="new",onChange:()=>y("new")})," ","New release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Create a new release with these docs."})]}),e("label",{className:`AddToReleaseModal__mode__option${o==="existing"?" AddToReleaseModal__mode__option--selected":o?" AddToReleaseModal__mode__option--unselected":""}`,children:[e("div",{className:"AddToReleaseModal__mode__option__input",children:[e("input",{type:"radio",name:"release-mode",value:"existing",checked:o==="existing",onChange:()=>y("existing")})," ","Existing release"]}),e("div",{className:"AddToReleaseModal__mode__option__help",children:"Add to an existing release."})]})]}),o==="new"&&e("div",{className:"AddToReleaseModal__form",children:[e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Release ID"}),e("input",{type:"text",placeholder:"e.g. my-release",value:x,onInput:n=>{T(n.target.value)}})]}),e("div",{className:"AddToReleaseModal__form__field",children:[e("label",{children:"Description (optional)"}),e("textarea",{rows:2,placeholder:"Describe this release",value:w,onInput:n=>{f(n.target.value)}})]})]}),o==="existing"&&e("div",{className:"AddToReleaseModal__releases",children:p?e("div",{className:"AddToReleaseModal__releases__empty",children:e(J,{color:"gray",size:"sm"})}):g.length===0?e("div",{className:"AddToReleaseModal__releases__empty",children:"No unpublished releases found. Create a new one instead."}):g.map(n=>e("div",{className:`AddToReleaseModal__release${a===n.id?" AddToReleaseModal__release--selected":""}`,onClick:()=>D(n.id),children:[e("input",{type:"radio",name:"existing-release",checked:a===n.id,onChange:()=>D(n.id)}),e("div",{className:"AddToReleaseModal__release__info",children:[e("div",{className:"AddToReleaseModal__release__info__id",children:n.id}),n.description&&e("div",{className:"AddToReleaseModal__release__info__description",children:n.description})]}),e("div",{className:"AddToReleaseModal__release__docCount",children:[n.docIds?.length||0," doc(s)"]})]},n.id))}),e("div",{className:"AddToReleaseModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",disabled:r,loading:m,onClick:I,children:o==="new"?"Create release":"Add to release"})]})]})})}mo.id=oo;X();var to="CopyDocModal";function oe(s){let t=N(),u=H();return{open:l=>{t.openContextModal(to,{...u,innerProps:{...s,...l}})}}}function po(s){let{innerProps:t,context:u,id:l}=s,{route:d}=fe(),[o,y]=c(""),[p,v]=c(""),[m,k]=c(""),[g,A]=c(""),[a,D]=c(!1),[x,T]=c(!1),[w,f]=c({}),I=t.fromDocId,L=I.split("/")[0],$=t.fromLabel||I;j(()=>{be({tags:[I]}).then(f)},[I]);function r(C,E){let R=ae(C),z=window.__ROOT_CTX.collections[E]?.slugRegex;return R?ge(R,z):""}async function n(C){if(C.preventDefault(),T(!0),A(""),!L){A("Please select a collection."),T(!1);return}if(r(p,o)){T(!1);return}let R=ae(p),z=`${o}/${R}`;try{t.fields?await Pe(z,{fields:t.fields,overwrite:a}):await Re(I,z,{overwrite:a});let O=Object.keys(w);if(O.length>0){let i=O.map(h=>({hash:h,tags:[z]}));await Me(i,{mode:"union"})}u.closeModal(l);let q=`/cms/content/${o}/${R}`;_({title:"Copied!",message:e("div",{children:[e("div",{children:`Successfully copied ${$} to ${z}.`}),e(b,{className:"CopyDocModal__notificationButton",component:"a",href:q,size:"xs",compact:!0,variant:"default",children:"Open doc"})]}),autoClose:1e4}),t.onSuccess&&t.onSuccess(z)}catch(O){let q=String(O);A(q),q.includes("already exists")&&D(!0),T(!1);return}T(!1),d(`/cms/content/${o}/${R}`)}return e("div",{className:"CopyDocModal",children:e("form",{onSubmit:C=>n(C),children:[e("div",{className:"CopyDocModal__from",children:[e(M,{className:"CopyDocModal__from__label",size:"body",weight:"bold",children:"From:"}),e(M,{className:"CopyDocModal__from__value",size:"body-sm",children:e("code",{children:$})})]}),e("div",{className:"CopyDocModal__to",children:[e(M,{className:"CopyDocModal__to__label",size:"body",weight:"bold",children:"To:"}),e(eo,{className:"CopyDocModal__slug",collectionId:L,onChange:C=>{y(C.collectionId),v(C.slug),k(r(C.slug,C.collectionId)),A(""),D(!1)}})]}),g&&e("div",{className:"CopyDocModal__error",children:g}),e("div",{className:"CopyDocModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",type:"submit",size:"xs",color:"dark",loading:x,disabled:!!m||!!g&&!a,children:a?"Overwrite?":"Submit"})]})]})})}po.id=to;X();function B(s){return e("div",{className:"DocIdBadge",children:e("code",{"data-testid":"doc-id",children:s.docId})})}var io="LockPublishingModal";function no(s){let t=N(),u=H();return{open:l=>{let d={...s,...l},o;d.unlock?o=`Unlock publishing for ${s.docId}`:d.existingLock?o=`Edit publishing lock for ${s.docId}`:o=`Lock publishing for ${s.docId}`,t.openContextModal(io,{...u,title:o,innerProps:{...s,...l},size:"600px"})}}}function fo(s){let t=l=>l<10?"0"+l:l,u=new Date(s);return`${u.getFullYear()}-${t(u.getMonth()+1)}-${t(u.getDate())}T${t(u.getHours())}:${t(u.getMinutes())}`}function Z(s){let{innerProps:t}=s;return t.unlock?e(Z.Unlock,{...s}):e(Z.Lock,{...s})}Z.Lock=s=>{let{innerProps:t,context:u,id:l}=s,d=!!t.existingLock,[o,y]=c(t.existingLock?.reason||""),[p,v]=c(t.existingLock?.until||0),[m,k]=c(!1),[g,A]=c(!1),a=N();function D(f){return f?Math.floor(new Date(f).getTime()):0}async function x(f){f.preventDefault(),k(!0),await U(async()=>{await Ie(t.docId,{reason:o,until:p}),_({title:d?"Updated!":"Locked!",message:d?`Publishing lock updated for ${t.docId}.`:`Publishing is locked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("locked")}),k(!1)}async function T(){A(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),a.closeModal(l),t.onChange&&t.onChange("unlocked")}),A(!1)}return e("div",{className:"LockPublishingModal LockPublishingModal--lock",children:[e(M,{className:"LockPublishingModal__body",size:"body-sm",children:d?"Publishing is currently locked. Update the publishing lock details below, or remove the lock to re\u2011enable publishing.":"Are you sure you want to lock publishing? Content editors will not be able to publish until publishing is unlocked."}),e("form",{className:"LockPublishingModal__form",onSubmit:f=>x(f),children:[e("div",{className:"LockPublishingModal__form__section",children:e(me,{name:"reason",label:"Reason",description:"Specify a short reason so other content editors know why publishing is locked.",size:"xs",radius:0,value:o,onChange:f=>{y(f.currentTarget.value)}})}),e("div",{className:"LockPublishingModal__form__section",children:e(ue,{label:"Lock until",description:"Optional. Publishing is unlocked at the specified time. If not provided, publishing will be locked indefinitely.",size:"xs",children:e("div",{className:"DocEditor__DateTimeField",children:[e("input",{name:"until",type:"datetime-local",min:he(),defaultValue:p?fo(p):"",onChange:f=>{let L=f.target.value;v(D(L))}}),e("div",{className:"DocEditor__DateTimeField__timezone",children:["timezone: ",Intl.DateTimeFormat().resolvedOptions().timeZone]})]})})}),e("div",{className:"LockPublishingModal__buttons",children:[d&&e(b,{variant:"filled",size:"xs",color:"red",type:"button",leftIcon:e(Y,{size:14}),loading:g,disabled:m,onClick:()=>T(),className:"LockPublishingModal__buttons__unlock",children:"Unlock"}),e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(ee,{size:14}),disabled:!o||g,type:"submit",loading:m,children:d?"Save":"Lock"})]})]})]})};Z.Unlock=s=>{let{innerProps:t,context:u,id:l}=s,[d,o]=c(!1),y=N();async function p(){o(!0),await U(async()=>{await le(t.docId),_({title:"Unlocked!",message:`Publishing is unlocked for ${t.docId}.`,autoClose:1e4}),y.closeModal(l),t.onChange&&t.onChange("unlocked")})}return e("div",{className:"LockPublishingModal LockPublishingModal--unlock",children:[e(M,{className:"LockPublishingModal__body",children:"Are you sure you want to unlock publishing for the following doc? This will re-enable content editors to publish the doc."}),e(B,{docId:t.docId}),e("div",{className:"LockPublishingModal__buttons",children:[e(b,{variant:"outline",onClick:()=>u.closeModal(l),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(b,{variant:"filled",size:"xs",color:"dark",leftIcon:e(Y,{size:14}),loading:d,onClick:()=>p(),children:"Unlock"})]})]})};Z.id=io;X();var ro="VersionHistoryModal",ao=50;function co(s){let t=N(),u=H();return{open:()=>{t.openContextModal(ro,{...u,title:`Version history: ${s.docId}`,innerProps:s,overflow:"inside",size:"min(calc(100% - 32px), 720px)"})}}}function _o(s){let{innerProps:t,context:u,id:l}=s,d=t.docId,[o,y]=c(!0),[p,v]=c(!1),[m,k]=c([]),[g,A]=c(!1),[a,D]=c([]),[x,T]=c(!1),[w,f]=c(null),I=ce(null),L=oe({fromDocId:d}),$=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});async function r(){y(!0);let[i,h]=await Promise.all([de(d,{limit:ao}),ze(d,"draft")]);I.current=i.lastDoc,A(i.hasMore);let V={_versionId:"draft",sys:{modifiedAt:h?.sys?.modifiedAt||{toDate:()=>new Date},modifiedBy:h?.sys?.modifiedBy||"Unknown"}};k([V,...i.versions]),D(["draft"]),y(!1)}async function n(){if(!g||p)return;v(!0);let i=await de(d,{limit:ao,cursor:I.current});I.current=i.lastDoc,A(i.hasMore),k(h=>[...h,...i.versions]),v(!1)}async function C(i){await Ne(d,i),_({title:"Saved!",message:`Restored ${d} to ${$.format(i.sys.modifiedAt.toDate())}.`,autoClose:5e3}),t.onRestore&&t.onRestore({version:i})}function E(i){let h=`${d}@${i._versionId}`,V=i.sys?.modifiedAt?.toDate();if(V){let W=go(V);h=`${d}@${W}`}L.open({fields:i.fields||{},fromLabel:h,onSuccess:()=>{u.closeModal(l)}})}function R(i){a.includes(i)?D(a.filter(h=>h!==i)):a.length<2&&D([...a,i])}function z(){if(a.length!==2)return"#";let i=m.find(te=>te._versionId===a[0]),h=m.find(te=>te._versionId===a[1]);if(!i||!h)return"#";let V=m.indexOf(i),W=m.indexOf(h),re=V>W?i:h,G=V>W?h:i,se=lo(d,re._versionId),uo=lo(d,G._versionId);return`/cms/compare?left=${se}&right=${uo}`}j(()=>{r()},[]);let O=m.filter(i=>i._versionId==="draft"||!x?!0:i.tags?.includes("published")),q=m.some(i=>i.tags?.includes("published"));return o?e(J,{}):e("div",{className:"VersionHistoryModal",children:[e("div",{className:"VersionHistoryModal__actions",children:[e(b,{component:a.length===2?"a":"button",variant:"filled",size:"xs",disabled:a.length!==2,href:a.length===2?z():void 0,target:a.length===2?"_blank":void 0,rightIcon:e(Fe,{size:16}),children:"Compare"}),q&&e(ie,{size:"xs",label:"Published versions only",checked:x,onChange:i=>T(i.currentTarget.checked)})]}),O.length===0?e(M,{className:"VersionHistoryModal__versionsEmpty",size:"body",children:[e("p",{children:"No versions found."}),e("p",{className:"VersionHistoryModal__versionsEmpty__developer",children:"For developers: Configure the Root CMS cron job to populate versions."})]}):e(S,{children:[e(pe,{className:"VersionHistoryModal__versions",children:[e("thead",{children:e("tr",{children:[e("th",{children:e("span",{className:"VersionHistoryModal__versions__selectLabel",children:"Select"})}),e("th",{children:"modified at"}),e("th",{children:"modified by"}),e("th",{children:"actions"})]})}),e("tbody",{children:O.map(i=>{let h=i._versionId==="draft",V=a.includes(i._versionId),W=!V&&a.length>=2;return e("tr",{children:[e("td",{children:e(ie,{size:"xs",checked:V,disabled:W,onChange:()=>R(i._versionId),className:"VersionHistoryModal__versions__checkbox"})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__modifiedAt",children:[e(M,{size:"body-sm",className:"VersionHistoryModal__versions__modifiedAt__text",children:h?e("span",{title:"Current Draft",children:[$.format(i.sys.modifiedAt.toDate())," ","(Latest)"]}):e(S,{children:[$.format(i.sys.modifiedAt.toDate()),i.tags?.includes("published")&&e("span",{className:"VersionHistoryModal__publishedLabel",children:"(Published)"})]})}),i.publishMessage&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-message`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,classNames:{body:"VersionHistoryModal__popover__body",arrow:"VersionHistoryModal__popover__arrow",close:"VersionHistoryModal__popover__close"},target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-message`?null:`${i._versionId}-message`),children:e(Qe,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:i.publishMessage})}),(()=>{let G=i.tags?.find(se=>se.startsWith("release:"))?.replace("release:","");return G&&e(ne,{withCloseButton:!0,opened:w===`${i._versionId}-release`,onClose:()=>f(null),position:"right",withArrow:!0,shadow:"md",width:320,target:e(Q,{size:"xs",variant:"light",className:"VersionHistoryModal__messageIcon",onClick:()=>f(w===`${i._versionId}-release`?null:`${i._versionId}-release`),children:e(Ze,{size:18})}),children:e("div",{className:"VersionHistoryModal__message",children:[e("strong",{children:"Release:"})," ",G]})})})()]})}),e("td",{children:e(M,{size:"body-sm",children:i.sys.modifiedBy})}),e("td",{children:e("div",{className:"VersionHistoryModal__versions__buttons",children:!h&&e(S,{children:[e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>C(i),children:"restore"}),e(b,{variant:"default",size:"xs",compact:!0,onClick:()=>E(i),leftIcon:e(K,{size:12}),children:"copy to doc"})]})})})]},i._versionId)})})]}),g&&e("div",{className:"VersionHistoryModal__loadMore",children:e(b,{variant:"subtle",size:"xs",loading:p,onClick:n,children:"Load more versions"})})]})]})}function lo(s,t){return encodeURIComponent(`${s}@${t}`).replaceAll("%2F","/").replaceAll("%40","@")}function go(s){let t=s.getFullYear(),u=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0"),d=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${t}-${u}-${l}T${d}:${o}`}_o.id=ro;function Js(s){let{roles:t}=Xe(),u=window.firebase.user.email||"",l=Ke(t,u),d=Je(t,u),o=s.docId,y=s.data||{},p=y.sys||{},v=we(y),m=N(),k=oe({fromDocId:o,onSuccess:r=>{s.onAction&&s.onAction({action:"copy",newDocId:r})}}),g=H(),A=co({docId:o}),a=no({docId:o}),D=so({docIds:[o]}),x=()=>{let r=`revert-draft-${o}`,n=m.openConfirmModal({...g,title:`Discard draft edits for ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to discard draft changes for the following doc? The doc data will revert to the published version. There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Discard draft edits",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Discarding draft edits",message:`Discarding draft edits of ${o}...`,loading:!0,autoClose:!1}),await xe(o),F({id:r,title:"Discarded draft edits",message:`Successfully reverted ${o} back to its published version`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"revert-draft"})}})},T=()=>{let r=`unpublish-doc-${o}`,n=m.openConfirmModal({...g,title:`Unpublish ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unpublish the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Unpublish",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unpublishing doc",message:`Requesting unpublish of ${o}...`,loading:!0,autoClose:!1}),await ve(o),F({id:r,title:"Unpublished!",message:`Successfully unpublished ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unpublish"})}})},w=r=>{s.onAction&&s.onAction({action:r})},f=()=>{let r=`unschedule-doc-${o}`,n=m.openConfirmModal({...g,title:`Unschedule ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to unschedule the following doc?"}),e(B,{docId:o})]}),labels:{confirm:"Unschedule",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Unschedule doc",message:`Requesting unschedule of ${o}...`,loading:!0,autoClose:!1}),await Ce(o),F({id:r,title:"Unscheduled!",message:`Successfully unscheduled ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"unschedule"})}})},I=()=>{let r=`archive-doc-${o}`,n=m.openConfirmModal({...g,title:`Archive ${o}`,children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to archive the following doc? Archived docs are hidden from the collection list by default but can be restored later."}),e(B,{docId:o})]}),labels:{confirm:"Archive",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Archiving doc",message:`Requesting archive of ${o}...`,loading:!0,autoClose:!1}),await ke(o),F({id:r,title:"Archived!",message:`Successfully archived ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onAction&&s.onAction({action:"archive"})}})},L=async()=>{let r=`unarchive-doc-${o}`;_({id:r,title:"Unarchiving doc",message:`Requesting unarchive of ${o}...`,loading:!0,autoClose:!1}),await Ae(o),F({id:r,title:"Unarchived!",message:`Successfully unarchived ${o}!`,loading:!1,autoClose:5e3}),s.onAction&&s.onAction({action:"unarchive"})},$=()=>{let r=`delete-doc-${o}`,n=m.openConfirmModal({...g,title:"Delete doc",children:e(S,{children:[e(M,{size:"body-sm",weight:"semi-bold",className:"DocActionsMenu__confirmText",children:"Are you sure you want to delete the following doc? There is no undo."}),e(B,{docId:o})]}),labels:{confirm:"Delete",cancel:"Cancel"},cancelProps:{size:"xs"},confirmProps:{color:"red",size:"xs"},onCancel:()=>console.log("Cancel"),closeOnConfirm:!1,onConfirm:async()=>{_({id:r,title:"Deleting doc",message:`Requesting deletion of ${o}...`,loading:!0,autoClose:!1}),await ye(o),F({id:r,title:"Deleted!",message:`Successfully deleted ${o}!`,loading:!1,autoClose:5e3}),m.closeModal(n),s.onDelete&&s.onDelete(),s.onAction&&s.onAction({action:"delete"})}})};return e(P,{className:"CollectionPage__collection__docsList__doc__controls__menu",position:"bottom",control:e(Q,{className:"DocEditor__ArrayField__item__header__controls__dots",children:e(We,{size:16})}),children:[!v&&e(P.Item,{icon:e(Ye,{size:20}),onClick:()=>D.open(),disabled:!d,children:"Add to release"}),e(P.Item,{icon:e(je,{size:20}),onClick:()=>A.open(),children:"Version history"}),e(P.Item,{icon:e(K,{size:20}),onClick:()=>k.open(),disabled:!l,children:"Copy"}),!v&&p.modifiedAt&&p.publishedAt&&p.modifiedAt>p.publishedAt&&e(P.Item,{icon:e(Oe,{size:20}),onClick:()=>x(),disabled:!l,children:"Discard draft edits"}),!v&&p.firstPublishedAt&&e(P.Item,{icon:e(qe,{size:20}),onClick:()=>T(),disabled:!d,children:"Unpublish"}),!v&&p.scheduledAt&&e(P.Item,{icon:e(Ee,{size:20}),onClick:()=>f(),disabled:!d,children:"Unschedule"}),!v&&(Te(y)?e(P.Item,{icon:e(Y,{size:20}),onClick:()=>a.open({unlock:!0,onChange:w}),disabled:!l,children:"Unlock publishing"}):e(P.Item,{icon:e(ee,{size:20}),onClick:()=>a.open({unlock:!1,onChange:w}),disabled:!l||De(y),children:"Lock publishing"})),v?e(P.Item,{icon:e(Ue,{size:20}),onClick:()=>L(),disabled:!l,children:"Unarchive"}):!p.publishedAt&&e(P.Item,{icon:e(Be,{size:20}),onClick:()=>I(),disabled:!l,children:"Archive"}),e(P.Item,{icon:e(Ge,{size:20}),onClick:()=>$(),disabled:!l,children:"Delete"})]})}export{so as a,mo as b,po as c,B as d,no as e,Z as f,_o as g,Js as h};
@@ -1 +1 @@
1
- import{e as r}from"./chunk-BUNR5EU3.js";import{Ga as i}from"./chunk-LROR6N3B.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{e as r}from"./chunk-WASID5UU.js";import{Ga as i}from"./chunk-WRA24P66.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};
@@ -0,0 +1,19 @@
1
+ import{a as Nt,b as Pt,c as Et,d as St,e as zt,f as jt,g as Dt,h as Lt,i as $t,j as Bt,k as Ut,l as Ot,m as Wt,n as Ht,o as nt}from"./chunk-GCSN3YEC.js";import{a as wt}from"./chunk-QWB6MAPJ.js";import{a as Tt,c as at}from"./chunk-VPZHG7JL.js";import{P as kt,T as Mt}from"./chunk-AAR7DBEN.js";import{f as Y}from"./chunk-5MV6XVGA.js";import{b as _t,c as mt,g as ut,h as ht,j as ft,n as q,o as gt,p as xt,r as Ct,v as G}from"./chunk-XOWWPE7X.js";import{d as At,e as N}from"./chunk-WASID5UU.js";import{$a as Q,Bc as j,Fa as H,Ga as o,Hc as yt,V as J,Vc as Rt,W as P,a as h,ab as Z,ad as U,ba as X,bb as tt,c as k,da as z,e as v,g as pt,h as M,j as oe,kc as et,pb as vt,pc as ot,qa as B,qc as bt}from"./chunk-WRA24P66.js";import{d as ct}from"./chunk-KUCVLANF.js";import{h as It}from"./chunk-7SK47HHZ.js";oe();var ae=500;function Ft(){return window.firebase.db}function Vt(){return window.__ROOT_CTX.rootConfig.projectId}function it(){return window.firebase.user?.email||""}function ne(){return _t(Ft(),"Projects",Vt(),"AiChats")}function rt(t){return mt(Ft(),"Projects",Vt(),"AiChats",t)}function D(t){return t&&typeof t.toMillis=="function"?t.toMillis():typeof t=="number"?t:0}async function Kt(t){let e=it();if(!e)return[];let a=t?.limit,n=typeof a=="number"&&Number.isFinite(a)&&a>0?Math.min(Math.floor(a),100):50,p=ut(ne(),ht("createdBy","==",e),ft(ae)),s=(await gt(p)).docs.map(l=>l.data());return s.sort((l,g)=>D(g.modifiedAt)-D(l.modifiedAt)),s.slice(0,n).map(l=>({id:l.id,title:l.title,modelId:l.modelId,createdAt:D(l.createdAt),modifiedAt:D(l.modifiedAt)}))}async function st(t){let e=await q(rt(t));if(!e.exists())return null;let a=e.data();return a.createdBy!==it()?null:{id:a.id||t,title:a.title,modelId:a.modelId,createdAt:D(a.createdAt),modifiedAt:D(a.modifiedAt),messages:a.messages||[]}}async function Jt(t,e){let a=it(),n=rt(t),p=await q(n);if(p.exists()&&p.data().createdBy!==a)throw new Error("chat is owned by another user");let _={id:t,createdBy:a,modifiedAt:G(),messages:$t(e.messages)};p.exists()||(_.createdAt=G()),e.modelId&&(_.modelId=e.modelId),e.title&&(_.title=e.title),await xt(n,_,{merge:!0})}async function Xt(t){await st(t)&&await Ct(rt(t))}async function qt(t,e){let a=St(e);if(a==="New chat")return a;let n=zt(e);if(!n)return a;try{let p=Et(Pt(t)),_=await kt({model:p,system:Dt,prompt:Lt(n),maxOutputTokens:64,temperature:.3}),s=jt(_.text);if(s)return s}catch(p){console.error("failed to generate chat title:",p)}return a}function Gt(t){let{size:e=14}=t,a=e*3.57,n=e*2;return o("div",{className:"BouncingLoader",style:{"--dot-size":`${e}px`,width:`${a}px`,height:`${n}px`}})}var lt=[{id:"read",label:"Read only",description:"Inspect CMS content without planning or applying writes."},{id:"approve",label:"Ask before writing",description:"Read freely, then pause for approval before draft edits."},{id:"auto",label:"Auto-apply draft edits",description:"Apply draft-only writes without approval in this chat."}],te="root-cms.ai.executionMode",ee="root-cms.ai.selectedModel";function ie(t){return lt.some(e=>e.id===t)}function re(){if(typeof window>"u")return"approve";try{let t=window.localStorage.getItem(te);if(ie(t))return t}catch(t){console.error("failed to read AI execution mode preference",t)}return"approve"}function se(t){if(typeof window>"u")return null;try{let e=window.localStorage.getItem(ee);if(e&&t.some(a=>a.id===e))return e}catch(e){console.error("failed to read AI model preference",e)}return null}function le(t){if(!(typeof window>"u"))try{window.localStorage.setItem(ee,t)}catch(e){console.error("failed to save AI model preference",e)}}function de(t){if(!(typeof window>"u"))try{window.localStorage.setItem(te,t)}catch(e){console.error("failed to save AI execution mode preference",e)}}var F="";function mo(t){let[e,a]=h(null),[n,p]=h("");k(()=>{let s=!0;return fetch("/cms/api/ai.config",{credentials:"include"}).then(async l=>{let g=await l.json();s&&a(g)}).catch(l=>{s&&p(String(l))}),()=>{s=!1}},[]);let _=!!e?.enabled&&(e.models?.length||0)>0;return o("div",{className:N("RootAIChat",`RootAIChat--${t.variant}`),children:!e&&!n?o("div",{className:"RootAIChat__loading",children:o(J,{size:"md",color:"gray"})}):_?o(pe,{variant:t.variant,config:e,initialChatId:t.variant==="panel"?void 0:t.initialChatId,docContext:t.docContext,onClose:t.onClose}):o(ce,{error:n,onClose:t.onClose})})}function ce(t){return o("div",{className:"RootAIChat__notEnabled",children:[t.onClose&&o(P,{className:"RootAIChat__notEnabled__close",onClick:t.onClose,title:"Close",children:o(U,{size:16})}),o("div",{className:"RootAIChat__notEnabled__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__notEnabled__title",children:"Root AI is not configured for this project."}),o("div",{className:"RootAIChat__notEnabled__body",children:["Add an ",o("code",{children:"ai.models"})," entry to ",o("code",{children:"cmsPlugin()"})," in"," ",o("code",{children:"root.config.ts"}),"."]}),t.error&&o("pre",{className:"RootAIChat__notEnabled__error",children:t.error})]})}function pe(t){let e=t.variant==="panel",{route:a}=At(),n=t.config.models||[],p=()=>se(n)||t.config.defaultModel||n[0]?.id||"",[_,s]=h(p),[l,g]=h(re),[f,b]=h(t.initialChatId||F),[y,C]=h(t.initialChatId||F),[E,d]=h([]),[x,A]=h(""),[I,T]=h([]),[V,O]=h(0),S=async()=>{if(!e)try{let i=await Kt();T(i)}catch(i){console.error("failed to load chat list",i)}};k(()=>{S(),!e&&t.initialChatId&&K(t.initialChatId)},[]),k(()=>{de(l)},[l]);let L=async i=>{try{let u=await st(i);return u?(b(i),C(i),d(u.messages||[]),A(u.title||""),u.modelId&&n.find(R=>R.id===u.modelId)&&s(u.modelId),O(w=>w+1),!0):!1}catch(u){return console.error("failed to load chat",u),!1}},K=i=>L(i),$=()=>{s(p()),b(F),C(F),d([]),A(""),O(i=>i+1),e||a("/cms/ai")},W=async i=>{if(i===y)return;await L(i)&&!e&&a(`/cms/ai/chat/${i}`)},r=async i=>{try{await Xt(i),y===i&&$(),S()}catch(u){console.error("failed to delete chat",u)}},m=n.find(i=>i.id===_)||n[0],c=i=>{s(i),le(i)};return o("div",{className:"RootAIChat__layout",children:[!e&&o(me,{chats:I,activeChatId:y,onSelect:W,onNew:$,onDelete:r}),o("div",{className:"RootAIChat__main",children:[e&&o(_e,{onNewChat:$,onClose:t.onClose}),o(he,{initialChatId:f,initialTitle:x,model:m,initialMessages:E,executionMode:l,canAutoApply:t.config.canAutoApply??!1,models:n,selectedModel:m,docContext:t.docContext,onSelectModel:c,onSelectExecutionMode:g,onChatPersisted:i=>{C(i),S(),e||window.history.replaceState(null,"",`/cms/ai/chat/${i}`)}},V)]})]})}function _e(t){return o("div",{className:"RootAIChat__panelHeader",children:[o("div",{className:"RootAIChat__panelHeader__title",children:[o(j,{size:14}),o("span",{children:"Root AI"})]}),o("div",{className:"RootAIChat__panelHeader__actions",children:[o(H,{label:"New chat",children:o(P,{size:"xs",onClick:t.onNewChat,children:o(et,{size:14})})}),t.onClose&&o(H,{label:"Close (\u2318 + i)",children:o(P,{size:"xs",onClick:t.onClose,children:o(U,{size:14})})})]})]})}function me(t){return o("aside",{className:"RootAIChat__sidebar",children:[o("button",{type:"button",className:"RootAIChat__sidebar__newButton",onClick:t.onNew,children:[o(et,{size:18}),o("span",{children:"New chat"})]}),o("div",{className:"RootAIChat__sidebar__list",children:[t.chats.length===0&&o("div",{className:"RootAIChat__sidebar__empty",children:"No chats yet."}),t.chats.map(e=>o("div",{className:N("RootAIChat__sidebar__item",e.id===t.activeChatId&&"RootAIChat__sidebar__item--active"),onClick:()=>t.onSelect(e.id),children:[o("div",{className:"RootAIChat__sidebar__item__title",title:e.title||"Untitled chat",children:e.title||"Untitled chat"}),o("button",{type:"button",className:"RootAIChat__sidebar__item__delete",title:"Delete chat",onClick:a=>{a.stopPropagation(),window.confirm("Delete this chat?")&&t.onDelete(e.id)},children:o(Rt,{size:14})})]},e.id))]})]})}function ue(t){let e=t.canAutoApply?lt:lt.filter(n=>n.id!=="auto"),a=e.find(n=>n.id===t.executionMode)||e[0];return o("div",{className:"RootAIChat__options",children:[o(B,{control:o(z,{type:"button",className:"RootAIChat__modePicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(bt,{size:16}),children:a.label}),children:e.map(n=>o(B.Item,{onClick:()=>t.onSelectExecutionMode(n.id),children:o("div",{className:"RootAIChat__modePicker__option",children:[o("div",{className:"RootAIChat__modePicker__option__label",children:n.label}),o("div",{className:"RootAIChat__modePicker__option__description",children:n.description})]})},n.id))}),o(B,{control:o(z,{type:"button",className:"RootAIChat__modelPicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(j,{size:16}),children:t.selectedModel?.label||"Select model"}),children:t.models.map(n=>o(B.Item,{onClick:()=>t.onSelectModel(n.id),children:o("div",{className:"RootAIChat__modelPicker__option",children:[o("div",{className:"RootAIChat__modelPicker__option__label",children:n.label}),n.description&&o("div",{className:"RootAIChat__modelPicker__option__description",children:n.description})]})},n.id))})]})}function he(t){let[e]=h(()=>t.initialChatId||Se()),a=v(t.model?.id);a.current=t.model?.id;let n=v(t.executionMode);n.current=t.executionMode;let p=v(t.docContext);p.current=t.docContext;let _=v(t.onChatPersisted);_.current=t.onChatPersisted;let s=v(null),l=v(t.executionMode),g=v(t.initialTitle),f=v(null),[b,y]=h({}),C=v({});k(()=>()=>{for(let r of Object.values(C.current))r("reject");C.current={}},[]);let E=M((r,m,c,i)=>new Promise(u=>{C.current[r]=u,y(w=>({...w,[r]:{toolCallId:r,toolName:m,input:c,preview:i,status:"pending"}}))}),[]),d=M(r=>{y(m=>{let c=m[r];return c?{...m,[r]:{...c,status:"executing"}}:m}),C.current[r]?.("approve"),delete C.current[r]},[]),x=M(r=>{y(m=>{let c={...m};return delete c[r],c}),C.current[r]?.("reject"),delete C.current[r]},[]),A=M(async r=>{if(!Wt(r.toolName))return await nt(r.toolName,r.input);let m=l.current;if(m==="read")return{success:!1,error:"WRITE_BLOCKED_BY_MODE",message:"The current execution mode is read only. Do not call write tools."};let c;try{c=await Ht(r.toolName,r.input)}catch(i){return{success:!1,error:"PREVIEW_FAILED",message:i?.message||String(i)}}if(c.error)return{success:!1,error:c.error,message:c.summary,errors:c.errors,hint:c.hint};if(m==="approve"&&await E(r.toolCallId,r.toolName,r.input,c)==="reject")return{success:!1,error:"USER_REJECTED",message:"The user rejected this draft change. Do not retry unless they ask for a revised version."};try{return await nt(r.toolName,r.input)}finally{y(i=>{if(!i[r.toolCallId])return i;let u={...i};return delete u[r.toolCallId],u})}},[E]),I=M(async r=>{let m=s.current;try{let c=g.current;if(!c&&m){let i=await qt(m,r);i&&i!=="New chat"&&(c=i,g.current=i)}await Jt(e,{messages:r,modelId:m?.id||a.current,title:c||void 0})}catch(c){console.error("failed to persist chat history",c)}_.current(e)},[e]),T=pt(()=>Bt({loadTurnConfig:async()=>{let r=a.current,m=n.current,c=p.current?.docId,i=`${r}|${m}|${c||""}`,u=f.current;if(u&&u.key===i)return u.config;let w=await fetch("/cms/api/ai.chat.prepare",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({modelId:r,executionMode:m,docId:c})}),R=await w.json();if(!w.ok||!R.success)throw new Error(R.error||`ai.chat.prepare failed: ${w.status}`);let dt={model:R.model,system:R.system,maxSteps:R.maxSteps};return s.current=R.model,l.current=R.executionMode||m,f.current={key:i,config:dt},dt},buildTools:r=>r.capabilities.tools?l.current==="read"?Ot():Ut():{},onFinish:I}),[I]),{messages:V,sendMessage:O,status:S,error:L,stop:K,addToolOutput:$}=Nt({id:e,messages:t.initialMessages,transport:T,sendAutomaticallyWhen:Mt,onToolCall:async({toolCall:r})=>{let m=await A(r);$({tool:r.toolName,toolCallId:r.toolCallId,output:m})}}),W=S==="streaming"||S==="submitted";return o(ct,{children:[o(fe,{messages:V,isStreaming:W,emptyMessage:t.model?void 0:"Select a model to start.",toolApprovals:{approvals:b,onApprove:d,onReject:x}}),L&&o("div",{className:"RootAIChat__error",children:[o("strong",{children:"Error:"})," ",L.message]}),o(ke,{disabled:!t.model,canAttach:t.model?.capabilities.attachments??!1,isStreaming:W,onStop:K,controls:o(ue,{models:t.models,selectedModel:t.selectedModel,onSelectModel:t.onSelectModel,executionMode:t.executionMode,canAutoApply:t.canAutoApply,onSelectExecutionMode:t.onSelectExecutionMode}),onSend:(r,m)=>{if(!r&&m.length===0)return;let c=Me(m),i=[r,c.text].filter(Boolean).join(`
2
+
3
+ `);O({text:i,files:c.files.map(u=>({type:"file",mediaType:u.mediaType,url:u.url,filename:u.filename}))})}})]})}function fe(t){let e=v(null);return k(()=>{let a=e.current;a&&(a.scrollTop=a.scrollHeight)},[t.messages]),t.messages.length===0?o("div",{className:"RootAIChat__transcript RootAIChat__transcript--empty",ref:e,children:o("div",{className:"RootAIChat__welcome",children:[o("div",{className:"RootAIChat__welcome__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__welcome__title",children:"Root AI"}),o("div",{className:"RootAIChat__welcome__body",children:t.emptyMessage||"What are we going to get done today?"})]})}):o("div",{className:"RootAIChat__transcript",ref:e,children:o("div",{className:"RootAIChat__transcript__inner",children:[t.messages.map(a=>o(ge,{message:a,toolApprovals:t.toolApprovals},a.id)),t.isStreaming&&o("div",{className:"RootAIChat__streamingIndicator",children:o(Gt,{size:6})})]})})}function ge(t){let e=t.message,a=e.role==="user",n=a?"You":"Root AI",p=a?window.firebase.user?.photoURL:null,[_,s]=h(!1),l=M(()=>(e.parts||[]).filter(f=>f.type==="text"&&f.text).map(f=>f.text).join(`
4
+
5
+ `),[e.parts]),g=M(async()=>{let f=l();if(!f)return;let b=Tt.parse(f);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([b],{type:"text/html"}),"text/plain":new Blob([f],{type:"text/plain"})})]),s(!0),setTimeout(()=>s(!1),2e3)}catch{await navigator.clipboard.writeText(f),s(!0),setTimeout(()=>s(!1),2e3)}},[l]);return o("div",{className:N("RootAIChat__message",`RootAIChat__message--${e.role}`),children:[o("div",{className:"RootAIChat__message__avatar",children:p?o("img",{src:p,alt:n}):o(j,{size:20})}),o("div",{className:"RootAIChat__message__body",children:[o("div",{className:"RootAIChat__message__username",children:n}),o("div",{className:"RootAIChat__message__parts",children:(e.parts||[]).map((f,b)=>o(xe,{part:f,toolApprovals:t.toolApprovals},b))}),o("button",{type:"button",className:N("RootAIChat__message__copy",_&&"RootAIChat__message__copy--copied"),title:_?"Copied!":"Copy message",onClick:g,children:_?o(Q,{size:14}):o(vt,{size:14})})]})]})}function xe(t){let e=t.part;return e.type==="text"?e.text?o("div",{className:"RootAIChat__textPart",children:o(at,{code:e.text})}):null:e.type==="reasoning"?o(Ce,{text:e.text}):e.type==="file"?o(Ae,{part:e}):e.type==="source-url"?o("a",{className:"RootAIChat__sourcePart",href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.title||e.url}):typeof e.type=="string"&&e.type.startsWith("tool-")?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="dynamic-tool"?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="step-start"?null:o("div",{className:"RootAIChat__unknownPart",children:o("pre",{children:JSON.stringify(e,null,2)})})}function Ce(t){let[e,a]=h(!1);return t.text?o("div",{className:N("RootAIChat__reasoning",e&&"RootAIChat__reasoning--open"),children:[o("button",{type:"button",className:"RootAIChat__reasoning__toggle",onClick:()=>a(!e),children:[o(Z,{size:14,style:{transform:e?"rotate(0deg)":"rotate(-90deg)"}}),o("span",{children:"Thinking"})]}),e&&o("div",{className:"RootAIChat__reasoning__body",children:o(at,{code:t.text})})]}):null}function Ae(t){let e=t.part;return e.mediaType?.startsWith("image/")?o("div",{className:"RootAIChat__filePart",children:o("img",{src:e.url,alt:e.filename||"attachment"})}):o("a",{className:"RootAIChat__filePart RootAIChat__filePart--link",href:e.url,target:"_blank",rel:"noopener noreferrer",children:[o(ot,{size:14}),o("span",{children:e.filename||e.url})]})}function Yt(t){let e=t.part,a=typeof e.type=="string"&&e.type.startsWith("tool-")?e.type.slice(5):e.toolName||"tool",n=e.state||"",p=Ie(e),_=t.toolApprovals,s=p?_?.approvals[p]:void 0,[l,g]=h(!!s);return k(()=>{s&&g(!0)},[s]),o("div",{className:"RootAIChat__tool",children:[o("button",{type:"button",className:"RootAIChat__tool__header",onClick:()=>g(!l),children:[o(Z,{className:N("RootAIChat__tool__header__icon",l&&"RootAIChat__tool__header__icon--open"),size:14}),o(X,{color:"dark",variant:"filled",size:"xs",children:a}),o("span",{className:"RootAIChat__tool__title",children:ve(a,e.input)}),o("span",{className:"RootAIChat__tool__state",children:s?Re(s.status):we(n)})]}),l&&o("div",{className:"RootAIChat__tool__body",children:[s&&_&&o(be,{approval:s,onApprove:()=>_.onApprove(s.toolCallId),onReject:()=>_.onReject(s.toolCallId)}),e.output?.receipt&&o(ye,{output:e.output}),e.input&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Input"})]}),o("pre",{children:JSON.stringify(e.input,null,2)})]}),e.output&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Output"})]}),o("pre",{children:JSON.stringify(e.output,null,2)})]}),e.errorText&&o("div",{className:"RootAIChat__tool__error",children:e.errorText})]})]})}function Ie(t){return t.toolCallId||t.id||""}function ve(t,e){switch(t){case"collections_list":return"List collections";case"docs_list":return`List ${e?.collectionId||"documents"}`;case"docs_search":return`Search docs${e?.query?` for "${e.query}"`:""}`;case"doc_get":return`Read ${e?.docId||"document"}`;case"doc_getVersion":return`Read ${e?.docId||"document"} version`;case"doc_set":return`Replace ${e?.docId||"draft fields"}`;case"doc_create":return`Create ${e?.docId||"draft document"}`;case"doc_updateField":return`Update ${e?.path||"field"}`;case"doc_edit":return`Edit ${e?.docId||"document"}`;case"doc_duplicate":return`Duplicate ${e?.fromDocId||"document"}`;case"doc_listVersions":return`List versions for ${e?.docId||"document"}`;case"doc_translateField":return"Translate field text";case"schema_get":return`Read ${e?.collectionId||"collection"} schema`;default:return t}}function be(t){let e=t.approval.preview,a=e.before!==void 0&&e.after!==void 0;return o("div",{className:"RootAIChat__approval",children:[o("div",{className:"RootAIChat__approval__header",children:[o("div",{children:[o("div",{className:"RootAIChat__approval__title",children:e.title}),o("div",{className:"RootAIChat__approval__summary",children:e.summary})]}),o(X,{className:"RootAIChat__approval__status",variant:"light",color:"gray",children:t.approval.status==="executing"?"Applying":"Review"})]}),e.details.length>0&&o("div",{className:"RootAIChat__approval__details",children:e.details.map(n=>o("div",{children:[o("span",{children:n.label}),o("strong",{children:n.value})]},`${n.label}:${n.value}`))}),a&&o(wt,{className:"RootAIChat__approval__diff",oldCode:Y(e.before),newCode:Y(e.after)}),o("div",{className:"RootAIChat__approval__actions",children:[o(z,{variant:"default",color:"dark",size:"xs",type:"button",className:"RootAIChat__approval__button",disabled:t.approval.status==="executing",onClick:t.onReject,children:"Reject"}),o(z,{variant:"filled",color:"green",size:"xs",type:"button",className:"RootAIChat__approval__button RootAIChat__approval__button--primary",disabled:t.approval.status==="executing",onClick:t.onApprove,children:"Approve draft edit"})]})]})}function ye(t){let e=t.output.receipt;return o("div",{className:"RootAIChat__receipt",children:[o("div",{className:"RootAIChat__receipt__title",children:[o(Q,{size:14}),o("span",{children:e.title})]}),o("div",{className:"RootAIChat__receipt__summary",children:e.summary}),e.details?.length>0&&o("div",{className:"RootAIChat__receipt__details",children:e.details.map(a=>o("div",{children:[o("span",{children:a.label}),o("strong",{children:a.value})]},`${a.label}:${a.value}`))}),e.adminUrl&&o(z,{component:"a",className:"RootAIChat__receipt__link",variant:"default",size:"xs",compact:!0,href:e.adminUrl,children:"Open document"})]})}function Re(t){return t==="executing"?"applying\u2026":"waiting for approval"}function we(t){switch(t){case"input-streaming":return"preparing\u2026";case"input-available":return"running\u2026";case"output-available":return"done";case"output-error":return"error";default:return t}}function ke(t){let[e,a]=h(""),[n,p]=h([]),[_,s]=h(!1),l=v(null),g=v(null);k(()=>{window.requestAnimationFrame(()=>{let d=g.current;d&&(d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,240)}px`)})},[e,n]);let b=()=>{t.disabled||t.isStreaming||!e&&n.length===0||(t.onSend(e,n),a(""),p([]),l.current&&(l.current.value=""))},y=d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),b())},C=async d=>{s(!0);try{let x=d.type||Ee(d.name),A=await Te(d,x),I=await It(d,{disableGci:!0});p(T=>[...T,{url:I.src,filename:I.filename||d.name,mediaType:x,textContent:A?.text,textTruncated:A?.truncated,width:I.width,height:I.height}])}catch(x){console.error("upload failed",x)}finally{s(!1),l.current&&(l.current.value="")}},E=d=>{let x=d.target;Array.from(x.files||[]).forEach(C)};return o("div",{className:"RootAIChat__composer",children:[n.length>0&&o("div",{className:"RootAIChat__composer__attachments",children:n.map((d,x)=>o("div",{className:"RootAIChat__composer__attachment",children:[d.mediaType.startsWith("image/")?o("img",{src:d.url,alt:d.filename}):o("span",{className:"RootAIChat__composer__attachment__name",children:d.filename}),o("button",{type:"button",className:"RootAIChat__composer__attachment__remove",onClick:()=>p(A=>A.filter((I,T)=>T!==x)),children:o(U,{size:12})})]},x))}),o("div",{className:"RootAIChat__composer__row",children:[o(H,{label:t.canAttach?"Attach file":"Model doesn't support attachments",className:"RootAIChat__composer__attachTooltip",children:o(P,{component:"label",radius:"xl",className:N("RootAIChat__composer__attach",!t.canAttach&&"RootAIChat__composer__attach--disabled"),disabled:!t.canAttach,children:[_?o(J,{size:"xs"}):o(ot,{size:18}),o("input",{ref:l,type:"file",style:{display:"none"},onChange:E})]})}),o("textarea",{ref:g,className:"RootAIChat__composer__textarea",placeholder:t.disabled?"Select a model\u2026":"Ask anything\u2026",value:e,rows:1,autofocus:!0,disabled:t.disabled,onKeyDown:y,onChange:d=>a(d.target.value),onPaste:d=>{let x=d.clipboardData?.items||[];for(let A of x)if(A.kind==="file"){let I=A.getAsFile();I&&t.canAttach&&C(I)}}}),t.isStreaming?o(P,{className:"RootAIChat__composer__button RootAIChat__composer__stopButton",radius:"xl",color:"dark",variant:"filled",onClick:t.onStop,title:"Stop",children:o(U,{size:18})}):o(P,{className:"RootAIChat__composer__button RootAIChat__composer__submitButton",radius:"xl",color:"dark",variant:"filled",disabled:t.disabled||_||!e&&n.length===0,onClick:b,title:"Send",children:o(yt,{size:18})})]}),t.controls]})}var Qt=1e5;function Me(t){let e=t.filter(Zt),a=t.filter(n=>!Zt(n)).map(Ne);return{files:e,text:a.length?`Attached files:
6
+
7
+ ${a.join(`
8
+
9
+ `)}`:""}}function Zt(t){return t.mediaType.startsWith("image/")}function Ne(t){let e=`File: ${t.filename} (${t.mediaType})`;if(t.textContent!==void 0){let a=t.textTruncated?`
10
+
11
+ [Content truncated before sending to the model.]`:"";return`${e}
12
+ URL: ${t.url}
13
+
14
+ ~~~
15
+ ${t.textContent}${a}
16
+ ~~~`}return`${e}
17
+ URL: ${t.url}
18
+
19
+ [The file was uploaded, but its binary content was not inlined into this chat message.]`}async function Te(t,e){if(!Pe(t.name,e))return null;let a=await t.text();return a.length<=Qt?{text:a,truncated:!1}:{text:a.slice(0,Qt),truncated:!0}}function Pe(t,e){return e.startsWith("text/")?!0:[".css",".js",".jsx",".json",".md",".mdx",".mjs",".scss",".ts",".tsx",".txt",".yaml",".yml"].some(a=>t.toLowerCase().endsWith(a))}function Ee(t){let e=t.toLowerCase();return e.endsWith(".png")?"image/png":e.endsWith(".webp")?"image/webp":e.endsWith(".jpg")||e.endsWith(".jpeg")?"image/jpeg":e.endsWith(".gif")?"image/gif":e.endsWith(".svg")?"image/svg+xml":e.endsWith(".pdf")?"application/pdf":e.endsWith(".json")?"application/json":e.endsWith(".csv")?"text/csv":e.endsWith(".md")?"text/markdown":e.endsWith(".txt")?"text/plain":"application/octet-stream"}function Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}export{mo as a};