@blinkk/root-cms 3.1.2 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/app.js +1 -4
  2. package/dist/chunk-MYN76V3L.js +764 -0
  3. package/dist/{chunk-4VZTYUQ7.js → chunk-NC3CRIFA.js} +191 -13
  4. package/dist/core/ai-tools.d.ts +82 -42
  5. package/dist/core/ai.d.ts +54 -218
  6. package/dist/core/plugin.d.ts +10 -4
  7. package/dist/functions.js +1 -2
  8. package/dist/plugin.js +42 -208
  9. package/dist/shared/ai/models.d.ts +110 -0
  10. package/dist/shared/ai/prompt-utils.d.ts +59 -0
  11. package/dist/ui/AIPage-4W4MFELY.js +1 -0
  12. package/dist/ui/{AssetsPage-KLGNE6D6.js → AssetsPage-QUL2NBWK.js} +1 -1
  13. package/dist/ui/CollectionPage-7VU6SUUP.js +1 -0
  14. package/dist/ui/ComparePage-DCP5QHDE.js +1 -0
  15. package/dist/ui/DataPage-TUVFBALT.js +1 -0
  16. package/dist/ui/DataSourcePage-YE2ZOHYI.js +1 -0
  17. package/dist/ui/DocTranslationsPage-3ILTQOP2.js +1 -0
  18. package/dist/ui/DocumentPage-JFQ3Y2GH.js +1 -0
  19. package/dist/ui/EditDataSourcePage-WHPZDMD4.js +1 -0
  20. package/dist/ui/EditReleasePage-QKWHIURV.js +1 -0
  21. package/dist/ui/EmbeddedAIPage-SQLOV4IT.js +1 -0
  22. package/dist/ui/{EmbeddedDocumentPage-4TLMCDSO.js → EmbeddedDocumentPage-6FYHUHTE.js} +1 -1
  23. package/dist/ui/{ImageEditorDialog-GGS4VFEA.js → ImageEditorDialog-Q44YTLB5.js} +1 -1
  24. package/dist/ui/LogsPage-RC5O722W.js +1 -0
  25. package/dist/ui/NewDataSourcePage-QXW54CHQ.js +1 -0
  26. package/dist/ui/NewReleasePage-TKYWVTOH.js +1 -0
  27. package/dist/ui/{NotFoundPage-A6OCYREA.js → NotFoundPage-RMNPVSD3.js} +1 -1
  28. package/dist/ui/{ProjectPage-UHRXNN7O.js → ProjectPage-VY4EJX6J.js} +1 -1
  29. package/dist/ui/ReleasePage-VZAL4KUI.js +1 -0
  30. package/dist/ui/ReleasesPage-A4BLUNJE.js +1 -0
  31. package/dist/ui/SettingsPage-MP3YHQDP.js +1 -0
  32. package/dist/ui/{SidebarToolsPage-VXVRZ2C3.js → SidebarToolsPage-S5DMIEQ6.js} +1 -1
  33. package/dist/ui/{TaskPage-LDPRN3G6.js → TaskPage-LCBDMA4I.js} +1 -1
  34. package/dist/ui/TasksPage-72KVSUQY.js +1 -0
  35. package/dist/ui/TranslationsArbPage-B7TIRREV.js +2 -0
  36. package/dist/ui/TranslationsEditPage-VQG4YHA6.js +1 -0
  37. package/dist/ui/{TranslationsPage-674JU6L4.js → TranslationsPage-6VCVMNXI.js} +1 -1
  38. package/dist/ui/ai-tools-7S4URTMT.js +1 -0
  39. package/dist/ui/chunk-2PDMFZBF.js +1 -0
  40. package/dist/ui/{chunk-SKQECSUR.js → chunk-3WQCVKK4.js} +1 -1
  41. package/dist/ui/{chunk-WMICEDOT.js → chunk-4N6CPIOQ.js} +1 -1
  42. package/dist/ui/{chunk-NJMNOITA.js → chunk-5SY2SVEX.js} +1 -1
  43. package/dist/ui/chunk-62VPTZJL.js +1 -0
  44. package/dist/ui/{chunk-GT5EQSEX.js → chunk-6P75AZ3B.js} +1 -1
  45. package/dist/ui/{chunk-CAY5NM4Z.js → chunk-74OB6FM4.js} +1 -1
  46. package/dist/ui/{chunk-XWX2622O.js → chunk-76PG55CM.js} +1 -1
  47. package/dist/ui/chunk-AAR7DBEN.js +110 -0
  48. package/dist/ui/{chunk-JS6TK4OP.js → chunk-ATTW36EM.js} +1 -1
  49. package/dist/ui/chunk-AZ2SK2ZK.js +1 -0
  50. package/dist/ui/chunk-CSUKZZK5.js +1 -0
  51. package/dist/ui/chunk-DZYYWCHX.js +3 -0
  52. package/dist/ui/{chunk-NSOTG64N.js → chunk-EIMRPYCD.js} +1 -1
  53. package/dist/ui/{chunk-HARRKJFZ.js → chunk-ELKXEMOU.js} +1 -1
  54. package/dist/ui/{chunk-LROR6N3B.js → chunk-ETPZ3TXX.js} +2 -2
  55. package/dist/ui/{chunk-LROR6N3B.js.LEGAL.txt → chunk-ETPZ3TXX.js.LEGAL.txt} +1 -0
  56. package/dist/ui/{chunk-J5E457OI.js → chunk-EYVQCOAD.js} +1 -1
  57. package/dist/ui/{chunk-Q7IU4QCY.js → chunk-F4F5MH7A.js} +1 -1
  58. package/dist/ui/chunk-FF4CLAZS.js +1 -0
  59. package/dist/ui/{chunk-W6LP22IK.js → chunk-GCMX5V3P.js} +1 -1
  60. package/dist/ui/{chunk-FJLNXXE3.js → chunk-H3PYPGNR.js} +1 -1
  61. package/dist/ui/{chunk-WFQU7V3W.js → chunk-HVYNDEA7.js} +1 -1
  62. package/dist/ui/{chunk-TVYAZN2Q.js → chunk-IMXZTYAA.js} +1 -1
  63. package/dist/ui/{chunk-YXSXWFLZ.js → chunk-J5KDO4RM.js} +1 -1
  64. package/dist/ui/chunk-JSWRHHTZ.js +1 -0
  65. package/dist/ui/{chunk-MSYTAJBV.js → chunk-K3UM5OQF.js} +1 -1
  66. package/dist/ui/{chunk-BW2MKGNP.js → chunk-KBJ4AK5O.js} +1 -1
  67. package/dist/ui/{chunk-4FGASIIX.js → chunk-L3O3CLWO.js} +1 -1
  68. package/dist/ui/{chunk-JTIQBW33.js → chunk-LC6WLVRS.js} +1 -1
  69. package/dist/ui/{chunk-VJUMFJIX.js → chunk-MAZJRNAL.js} +1 -1
  70. package/dist/ui/{chunk-3E6CASIN.js → chunk-MYKJ6VAM.js} +1 -1
  71. package/dist/ui/chunk-NEA3XU6N.js +19 -0
  72. package/dist/ui/{chunk-UUVAD4U4.js → chunk-PR7NB5VK.js} +1 -1
  73. package/dist/ui/{chunk-QF3GPZTI.js → chunk-QHOZXW7Y.js} +1 -1
  74. package/dist/ui/chunk-RN4XVVWD.js +1 -0
  75. package/dist/ui/{chunk-PTPYMVFW.js → chunk-SLLTYDVX.js} +1 -1
  76. package/dist/ui/chunk-SWTNOWNE.js +1 -0
  77. package/dist/ui/{chunk-JBHRZ4EX.js → chunk-SYDHFYRC.js} +1 -1
  78. package/dist/ui/{chunk-ZMS6NIGG.js → chunk-UHK5N75L.js} +1 -1
  79. package/dist/ui/chunk-V3G3554T.js +31 -0
  80. package/dist/ui/chunk-VB5VMEN7.js +1 -0
  81. package/dist/ui/{chunk-2EPQJUGM.js → chunk-VRRRFAIV.js} +1 -1
  82. package/dist/ui/{chunk-4ALFT4ES.js → chunk-W2ZAVRAT.js} +56 -56
  83. package/dist/ui/{chunk-P2Z66DHV.js → chunk-W3ICOHMF.js} +1 -1
  84. package/dist/ui/{chunk-ENQKSLGJ.js → chunk-WAT22UHZ.js} +1 -1
  85. package/dist/ui/chunk-WN7HUDGY.js +1 -0
  86. package/dist/ui/{chunk-BUNR5EU3.js → chunk-WS37MDM3.js} +1 -1
  87. package/dist/ui/chunk-XACLTYBB.js +5 -0
  88. package/dist/ui/chunk-XJUQOX4E.js +1 -0
  89. package/dist/ui/{chunk-QHJOTXYB.js → chunk-XM35ZJBQ.js} +1 -1
  90. package/dist/ui/{chunk-VD6G5NV4.js → chunk-XOWWPE7X.js} +12 -12
  91. package/dist/ui/chunk-YV5SGR24.js +1 -0
  92. package/dist/ui/ui.css +1 -1
  93. package/dist/ui/ui.js +1 -1
  94. package/package.json +3 -3
  95. package/dist/chunk-AJDMNTZQ.js +0 -187
  96. package/dist/chunk-X5CNR4CK.js +0 -1411
  97. package/dist/ui/AIPage-2N5UYBRX.js +0 -1
  98. package/dist/ui/CollectionPage-D7IG6526.js +0 -1
  99. package/dist/ui/ComparePage-726NIJW5.js +0 -1
  100. package/dist/ui/DataPage-YMSQCIVK.js +0 -1
  101. package/dist/ui/DataSourcePage-7VPFUG3K.js +0 -1
  102. package/dist/ui/DocTranslationsPage-FO7O76VK.js +0 -1
  103. package/dist/ui/DocumentPage-M7SJ4ITQ.js +0 -1
  104. package/dist/ui/EditDataSourcePage-Y7YK6IWT.js +0 -1
  105. package/dist/ui/EditReleasePage-XZ4RHHRT.js +0 -1
  106. package/dist/ui/EmbeddedAIPage-RJOUIPF2.js +0 -1
  107. package/dist/ui/LogsPage-IGDDZGEI.js +0 -1
  108. package/dist/ui/NewDataSourcePage-YUPRHL7F.js +0 -1
  109. package/dist/ui/NewReleasePage-6HHLYOQP.js +0 -1
  110. package/dist/ui/ReleasePage-V2JMPWX7.js +0 -1
  111. package/dist/ui/ReleasesPage-SCR4SVKN.js +0 -1
  112. package/dist/ui/SettingsPage-5XKHPG6K.js +0 -1
  113. package/dist/ui/TasksPage-DIXUWYXM.js +0 -1
  114. package/dist/ui/TranslationsArbPage-QPD3ZBT4.js +0 -2
  115. package/dist/ui/TranslationsEditPage-475Z7UPC.js +0 -1
  116. package/dist/ui/ai-tools-4DWMFQS6.js +0 -1
  117. package/dist/ui/chunk-2RAVKX2Z.js +0 -19
  118. package/dist/ui/chunk-2S5HMST6.js +0 -1
  119. package/dist/ui/chunk-344GZOGG.js +0 -84
  120. package/dist/ui/chunk-4ISFTE2G.js +0 -5
  121. package/dist/ui/chunk-AGFPVTBA.js +0 -1
  122. package/dist/ui/chunk-D3UIZHRK.js +0 -1
  123. package/dist/ui/chunk-HO3W4RVG.js +0 -1
  124. package/dist/ui/chunk-KRNQ6L35.js +0 -1
  125. package/dist/ui/chunk-N3JSLTMV.js +0 -1
  126. package/dist/ui/chunk-NWHGT476.js +0 -1
  127. package/dist/ui/chunk-RHAJNURN.js +0 -1
  128. package/dist/ui/chunk-SENZVSVZ.js +0 -1
  129. package/dist/ui/chunk-TOGLZDK3.js +0 -1
  130. package/dist/ui/chunk-TPJCPCRR.js +0 -1
  131. package/dist/ui/chunk-XMESZUC5.js +0 -1
  132. package/dist/ui/chunk-YMBBWVBB.js +0 -3
  133. /package/dist/ui/{ImageEditorDialog-GGS4VFEA.js.LEGAL.txt → ImageEditorDialog-Q44YTLB5.js.LEGAL.txt} +0 -0
  134. /package/dist/ui/{chunk-NJMNOITA.js.LEGAL.txt → chunk-5SY2SVEX.js.LEGAL.txt} +0 -0
  135. /package/dist/ui/{chunk-4ALFT4ES.js.LEGAL.txt → chunk-W2ZAVRAT.js.LEGAL.txt} +0 -0
  136. /package/dist/ui/{chunk-VD6G5NV4.js.LEGAL.txt → chunk-XOWWPE7X.js.LEGAL.txt} +0 -0
@@ -1,5 +0,0 @@
1
- import{f as c}from"./chunk-KRNQ6L35.js";import{a as p,b,c as g,g as E,i as C,n as x,p as _,q as A,s as w,t as h,v as u,w as D}from"./chunk-VD6G5NV4.js";var q="tasks",H=20;function K(){let t=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId;return g(t,"Projects",e)}function T(t){let e=window.firebase.db,n=window.__ROOT_CTX.rootConfig.projectId;return g(e,"Projects",n,"Tasks",t)}function N(){let t=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId;return g(t,"Projects",e,"Counters",q)}function v(){let t=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId;return b(t,"Projects",e,"Tasks")}function O(t){let e=window.firebase.db,n=window.__ROOT_CTX.rootConfig.projectId;return b(e,"Projects",n,"Tasks",t,"Comments")}function P(t,e){let n=window.firebase.db,s=window.__ROOT_CTX.rootConfig.projectId;return g(n,"Projects",s,"Tasks",t,"Comments",e)}function R(t){let e=window.firebase.db,n=window.__ROOT_CTX.rootConfig.projectId;return b(e,"Projects",n,"Tasks",t,"Events")}function G(t){return g(R(t))}async function J(){let t=await x(K());return t.exists()&&(t.data()||{}).settings?.defaultAssignee||null}async function st(t){if(!t.title)throw new Error("missing task title");let e=window.firebase.db,n=t.assignee??await J(),s=t.priority||"normal",a="new",i=L(t.targetLaunchDate),d=await h(e,async r=>{let o=N(),l=(await r.get(o)).data()||{},f=typeof l.lastTaskId=="number"?l.lastTaskId:0,k=Math.floor(f)+1;for(let B=0;B<H;B++){let j=T(String(k));if(!(await r.get(j)).exists())return r.set(o,{lastTaskId:k,updatedAt:u()},{merge:!0}),r.set(j,{id:String(k),title:t.title,description:t.description||"",assignee:n??null,priority:s,status:a,targetLaunchDate:i,createdAt:u(),createdBy:window.firebase.user.email||"",updatedAt:u(),updatedBy:window.firebase.user.email||""}),String(k);k+=1}throw new Error("unable to allocate a task id")});return c("tasks.create",{metadata:{taskId:d}}),d}function L(t){return t instanceof Date?p.fromDate(t):t??null}function Q(t){let e=W(t);return!["closed","complete","completed","done","resolved"].includes(e)}function W(t){let e=(t||"new").trim().toLowerCase();return e==="open"?"new":e==="blocked"?"in-progress":["done","complete","completed","resolved"].includes(e)?"closed":e}function Y(t){return t.sort((e,n)=>{let s=e.createdAt?.toMillis?.()||0;return(n.createdAt?.toMillis?.()||0)-s})}function M(t){return Y(t.docs.map(e=>({...e.data(),id:e.id})))}function at(t,e){return w(v(),n=>{t(M(n))},e)}function it(t,e){return w(v(),n=>{t(M(n).filter(s=>Q(s.status)))},e)}function rt(t,e,n){return w(T(t),s=>{if(!s.exists()){e(null);return}e({...s.data(),id:s.id})},n)}function ot(t,e,n){return w(E(O(t),C("createdAt","asc")),s=>{e(s.docs.map(a=>({...a.data(),id:a.id})))},n)}function dt(t,e,n){return w(E(R(t),C("createdAt","asc")),s=>{e(s.docs.map(a=>({...a.data(),id:a.id})))},n)}async function ct(t,e){if(!t)throw new Error("missing task id");let n=e?.trim()||null;await y(t,"assignee",n)&&c("tasks.updateAssignee",{metadata:{taskId:t,assignee:n}})}async function ut(t,e){if(!t)throw new Error("missing task id");let n=e.trim();if(!n)throw new Error("missing title");await y(t,"title",n)&&c("tasks.updateTitle",{metadata:{taskId:t}})}async function mt(t,e){if(!t)throw new Error("missing task id");if(!e)throw new Error("missing status");let n=e.trim();await y(t,"status",n)&&c("tasks.updateStatus",{metadata:{taskId:t,status:e}})}async function lt(t,e){if(!t)throw new Error("missing task id");await y(t,"priority",e)&&c("tasks.updatePriority",{metadata:{taskId:t,priority:e}})}async function ft(t,e){if(!t)throw new Error("missing task id");let n=L(e);await y(t,"targetLaunchDate",n)&&c("tasks.updateTargetLaunchDate",{metadata:{taskId:t}})}async function pt(t,e){if(!t)throw new Error("missing task id");await A(T(t),{description:e,updatedAt:u(),updatedBy:window.firebase.user.email||""}),c("tasks.updateDescription",{metadata:{taskId:t}})}async function gt(t,e){if(!t)throw new Error("missing task id");if(!e?.src)throw new Error("missing attachment file");let n=window.firebase.db,s=T(t),a=window.firebase.user.email||"",i={...e,id:g(R(t)).id,attachedAt:p.now(),attachedBy:a};return await h(n,async d=>{let r=await d.get(s);if(!r.exists())throw new Error("task not found");let o=r.data(),m=S(o.attachments);d.update(s,{attachments:[...m,i],updatedAt:u(),updatedBy:a})}),c("tasks.attachment.add",{metadata:{taskId:t,attachmentId:i.id,filename:i.filename||i.src}}),i}async function wt(t,e){if(!t||!e)throw new Error("missing task or attachment id");let n=window.firebase.db,s=T(t),a=window.firebase.user.email||"",i;await h(n,async r=>{let o=await r.get(s);if(!o.exists())throw new Error("task not found");let m=o.data(),l=S(m.attachments);return i=l.find(f=>f.id===e),i?(r.update(s,{attachments:l.filter(f=>f.id!==e),updatedAt:u(),updatedBy:a}),!0):!1})&&c("tasks.attachment.remove",{metadata:{taskId:t,attachmentId:e,filename:i?.filename||i?.src||""}})}async function y(t,e,n){let s=window.firebase.db,a=T(t),i=G(t),d=window.firebase.user.email||"";return h(s,async r=>{let o=await r.get(a);if(!o.exists())throw new Error("task not found");let m=o.data(),l=U(m[e]),f=U(n);return Z(l,f)?!1:(r.update(a,{[e]:f,updatedAt:u(),updatedBy:d}),r.set(i,{id:i.id,taskId:t,type:"metadata",field:e,oldValue:l,newValue:f,createdAt:u(),createdBy:d}),!0)})}function U(t){return t instanceof p||typeof t=="string"?t:null}function Z(t,e){return t instanceof p&&e instanceof p?t.toMillis()===e.toMillis():t===e}function S(t){return Array.isArray(t)?t.filter(e=>!!(e?.id&&e?.src)):[]}async function Tt(t,e,n,s){if(!t)throw new Error("missing task id");if(!e)throw new Error("missing comment content");let a=z(e),i=typeof e=="string"?e:F(e);if(!i.trim()&&!a)throw new Error("missing comment content");let d=g(O(t)),r=d.id,o=(s?.mentions||[]).map(m=>m.toLowerCase());return await _(d,{id:r,taskId:t,parentId:n||null,content:i,body:a,mentions:o,createdAt:u(),createdBy:window.firebase.user.email||"",history:[]}),c("tasks.comment.add",{metadata:{taskId:t,commentId:r,parentId:n||null,mentions:o}}),r}async function kt(t,e,n,s){if(!t||!e)throw new Error("missing task or comment id");if(!n)throw new Error("missing comment content");let a=z(n),i=typeof n=="string"?n:F(n);if(!i.trim()&&!a)throw new Error("missing comment content");let d=P(t,e),r=await x(d);if(!r.exists())throw new Error("comment not found");let o=r.data(),m=(s?.mentions||[]).map(l=>l.toLowerCase());await A(d,{content:i,body:a,mentions:m,updatedAt:u(),updatedBy:window.firebase.user.email||"",isDeleted:!1,history:D({action:"edit",content:o.content,body:o.body||null,changedAt:p.now(),changedBy:window.firebase.user.email||""})}),c("tasks.comment.edit",{metadata:{taskId:t,commentId:e,mentions:m}})}function z(t){return typeof t=="string"?null:t}function F(t){return t?.blocks?.length?t.blocks.map(e=>$(e)).filter(Boolean).join(`
2
- `).trim():""}function $(t){switch(t.type){case"paragraph":case"heading":case"quote":return V(t.data?.text||"");case"orderedList":case"unorderedList":return(t.data?.items||[]).map(e=>X(e)).filter(Boolean).join(`
3
- `);case"image":return t.data?.file?.alt||t.data?.file?.url||"";default:return""}}function X(t){let e=[V(t.content||"")];return t.items?.length&&e.push(t.items.map(n=>X(n)).filter(Boolean).join(`
4
- `)),e.filter(Boolean).join(`
5
- `)}function V(t){return t.replace(/<[^>]+>/g,"")}async function ht(t,e){if(!t||!e)throw new Error("missing task or comment id");let n=P(t,e),s=await x(n);if(!s.exists())throw new Error("comment not found");let a=s.data();await A(n,{content:"",isDeleted:!0,deletedAt:u(),deletedBy:window.firebase.user.email||"",history:D({action:"delete",content:a.content,changedAt:p.now(),changedBy:window.firebase.user.email||""})}),c("tasks.comment.delete",{metadata:{taskId:t,commentId:e}})}export{st as a,Q as b,W as c,at as d,it as e,rt as f,ot as g,dt as h,ct as i,ut as j,mt as k,lt as l,ft as m,pt as n,gt as o,wt as p,Tt as q,kt as r,ht as s};
@@ -1 +0,0 @@
1
- import{a as te,f as se,g as U,h as oe,i as ne,l as ie}from"./chunk-YMBBWVBB.js";import{f as p}from"./chunk-KRNQ6L35.js";import{a as k,b as I,c as l,f as J,g as x,h as D,i as O,j as F,l as Y,n as B,o as j,p as M,q as w,r as Z,t as $,u as R,v as m,w as ee,x as T}from"./chunk-VD6G5NV4.js";import{k as N}from"./chunk-7SK47HHZ.js";function re(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null}function ce(e){return re(e)&&Array.isArray(e.blocks)&&e.blocks.length>0}var X=new Map;function Re(e){return X.get(e)||null}async function We(e){let t=Re(e);if(t)return t;let s=b(e),o=(await B(s)).data();return De(e,o),o}function De(e,t){X.set(e,t)}function q(e){X.delete(e)}function L(e){for(let t of e)q(t)}function ae(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 v=class extends Error{},le=200,Ce=/[/\\\u0000-\u001f]/;function C(){let e=window.__ROOT_CTX.rootConfig.projectId,t=window.firebase.db;return I(t,"Projects",e,"Assets")}var Te="root-cms:assetPicker:lastFolder";function ue(){let e=window.__ROOT_CTX.rootConfig.projectId;return`${Te}:${e}`}function rt(){try{return localStorage.getItem(ue())||""}catch{return""}}function ct(e){try{localStorage.setItem(ue(),e||"")}catch{}}function H(e){let t=(e||"").trim();if(!t)throw new v("Name is required.");if(t.length>le)throw new v(`Name is too long (max ${le} chars).`);if(Ce.test(t))throw new v("Name cannot contain slashes.");if(t==="."||t==="..")throw new v("Invalid name.");return t}function _(e,t){return e?`${e}/${t}`:t}function at(e){return e?e.split("/").filter(Boolean):[]}function E(e){return`folder-${encodeURIComponent(e)}`}function me(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 pe(e){return!!e&&typeof e.name=="string"&&(e.type==="file"||e.type==="folder")}async function Be(e){let t=C(),s=x(t,D("parent","==",e||"")),n=await j(s),o=[];return n.forEach(i=>{let r=i.data();pe(r)&&o.push(r)}),me(o)}var de=1e3;async function lt(e){let t=C(),s;e?s=x(t,D("parent",">=",e),D("parent","<=",`${e}\uF8FF`),F(de)):s=x(t,F(de));let n=await j(s),o=[];return n.forEach(i=>{let r=i.data();pe(r)&&(!e||Q(r.parent,e))&&o.push(r)}),me(o)}function dt(e,t){return t?e===t?"":e.startsWith(`${t}/`)?e.slice(t.length+1):e:e}async function P(e){let t=l(C(),e),s=await B(t);return s.exists()?s.data():null}async function ft(e,t){let s=H(t),n=_(e,s),o=E(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 M(i,r,{merge:!0}),p("asset.folder_create",{metadata:{folder:n}}),await P(o)}async function ut(e){let t=W(e.file),s=H(e.name||t.filename||Fe(t.src)),n=ae(12),o=l(C(),n);return await M(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 P(n)}async function mt(e,t){let s=H(t);if(s===e.name)return;if(e.type==="folder"){let o=_(e.parent,e.name),i=_(e.parent,s);await ge(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 pt(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||Q(i,o))throw new Error("Cannot move a folder into itself.");await ge(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 Q(e,t){return e===t||e.startsWith(`${t}/`)}async function ge(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();Q(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=E(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,E(S)),{...h,id:E(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 gt(e){if(e.type==="folder"){let t=_(e.parent,e.name);if((await Be(t)).length>0)throw new Error("Folder is not empty.")}await Z(l(C(),e.id)),p("asset.delete",{metadata:{assetId:e.id,name:e.name}})}async function yt(e,t){let s=W(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=N(s.filename||s.src||""),r=je(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 P(e.id)}function je(e,t){let s=(e||"").lastIndexOf(".");return!t||s<=0||N(e)===t?e:`${e.slice(0,s)}.${t}`}async function ht(e,t){let s=l(C(),e.id);return await w(s,{"file.alt":t||"",modifiedAt:m(),modifiedBy:window.firebase.user.email}),await P(e.id)}async function wt(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 P(e.id)}function _e(e){let t={...W(e.file),assetId:e.id};return t.altDisabled&&(t.alt=""),t}function K(e){let t=new Set;return G(e,t),Array.from(t).sort()}function G(e,t){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let s of e)G(s,t);return}if(typeof e.toMillis!="function"){if(z(e)){t.add(e.assetId);return}for(let s of Object.keys(e))G(e[s],t)}}}function z(e){return typeof e?.assetId=="string"&&typeof e?.src=="string"}function fe(e){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let t of e)if(fe(t))return!0;return!1}if(typeof e.toMillis=="function")return!1;if(z(e))return!0;for(let t of Object.keys(e))if(fe(e[t]))return!0;return!1}async function ke(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=I(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 bt(e,t={}){let s=window.__ROOT_CTX.rootConfig.projectId,n=window.firebase.db,o=t.docs??await ke(e.id),i=[],r=[];for(let c of o){let a=[];if(ye(c.fields,e.id,"fields",a),a.length===0)continue;let f={};for(let u of a)f[u.path]=Ie(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 ye(e,t,s,n){if(!(!e||typeof e!="object")&&!Array.isArray(e)&&typeof e.toMillis!="function"){if(z(e)){e.assetId===t&&n.push({path:s,value:e});return}for(let o of Object.keys(e))ye(e[o],t,`${s}.${o}`,n)}}function Ie(e,t,s){let n=_e(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 W(e){let t={};return Object.entries(e||{}).forEach(([s,n])=>{n!==void 0&&(t[s]=n)}),t}function Fe(e){return(e||"").split("?")[0].split("/").pop()||"untitled"}async function Ft(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 Ve(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}`);Me(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 Me(e,t,s,n,o){if(Se(s))throw new Error(`publishing is locked for doc: ${s.id}`);if(Pe(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 Mt(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 $(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 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,"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}}),q(e)}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,"Published",o);await $(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 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,"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 Et(e){let t=b(e),s={"sys.publishingLocked":R()};await w(t,s),p("doc.unlock_publishing",{metadata:{docId:e}})}async function Vt(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 $t(e){let t=b(e);await w(t,{"sys.archivedAt":R(),"sys.archivedBy":R()}),p("doc.unarchive",{metadata:{docId:e}})}function Pe(e){return!!e?.sys?.archivedAt}function Nt(e){let t=k.now().toMillis();return(e?.sys?.scheduledAt?.toMillis()||0)>t}function Se(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 Ut(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 Oe(t,{fields:r,locales:c,overwrite:s?.overwrite})}async function Oe(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=K(r);a.length>0?c.sys.assets=a:delete c.sys.assets,await M(o,c),p("doc.create",{metadata:{docId:e}})}async function Xt(e,t,s){let n={};for(let d of t){if(!d.source)continue;let g={source:U(d.source)},y={},u={};Object.entries(d).forEach(([A,S])=>{if(A==="source")return;let Ae=ne(A);for(let V of ie(A)){if(oe(V))continue;let xe=V===Ae?u:y;xe[V]=U(S||"")}}),Object.assign(g,y,u);let h=await se(g.source);n[h]=g}let i=[e.split("/")[0],e];s?.tags&&i.push(...s.tags);let r=te(),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:ee(...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 Ee(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 Ve(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=I(s,"Projects",t,"Collections",i,"Drafts"),a=x(c,D(J(),"in",r));(await j(a)).forEach(d=>{let g=`${i}/${d.id}`;o[g]=d.data()})})),o}async function qt(e,t){let s=window.firebase.db,n=b(e),o=I(s,n.path,"Versions"),i=t?.limit??50,r=x(o,O("sys.modifiedAt","desc"),F(i));t?.tags&&(r=x(r,D("tags","array-contains-any",t.tags))),t?.cursor&&(r=x(r,Y(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 Gt(e,t){let s=b(e),n={"sys.modifiedAt":m(),"sys.modifiedBy":window.firebase.user.email,"sys.assets":K(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 $e=/^(before|after):(\d+)$/,Ne=10*1e3;async function Ue(e,t){let s=String(t).match($e);if(s)return await Xe(e,s[1],parseInt(s[2]));let n;t==="draft"?n=b(e):t==="published"?n=Le(e):n=Ee(e,t);let o=await B(n);return o.exists()?o.data():null}async function Xe(e,t,s){let n=window.firebase.db,o=b(e),i=I(n,o.path,"Versions"),r=k.fromMillis(s-Ne),c;t==="before"?c=x(i,D("sys.modifiedAt","<",r),O("sys.modifiedAt","desc"),F(1)):c=x(i,D("sys.modifiedAt",">=",r),O("sys.modifiedAt","asc"),F(1));let a=await j(c);return a.empty?t==="after"?await Ue(e,"draft"):null:a.docs[0].data()}async function Ht(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 Qt(e){let t=b(e),s={"sys.l10nSheet":R()};await w(t,s),p("doc.unlink_sheet",{metadata:{docId:e}})}async function Kt(e){let t=b(e),o=(await B(t)).data()?.sys?.l10nSheet||{};return o?.spreadsheetId?{spreadsheetId:o.spreadsheetId,gid:o.gid||0}:null}function he(e,t){let s={};for(let n in e){let o=e[n];if(be(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={...he(o[r]||{},t),_arrayKey:r};return t?.removeArrayKey&&delete c._arrayKey,c});s[n]=i}else s[n]=he(o,t);else s[n]=o}return s}async function zt(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 be(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null}function Wt(e){let[t,s]=e.split("/");return{id:e,collection:t,slug:s}}function we(e){if(qe(e))return k.fromMillis(e.seconds*1e3);if(ce(e))return e.time=Date.now(),e;if(Array.isArray(e))return e.map(t=>we(t));if(be(e)){let t={};return Object.keys(e).forEach(s=>{t[s]=we(e[s])}),t}return e}function qe(e){return e?.type==="firestore/timestamp/1.0"}export{ce as a,We as b,De as c,ae as d,rt as e,ct as f,_ as g,at as h,Be as i,lt as j,dt as k,P as l,ft as m,ut as n,mt as o,pt as p,gt as q,yt as r,je as s,ht as t,wt as u,_e as v,K as w,fe as x,ke as y,bt as z,Ft as A,vt as B,ve as C,Mt as D,Pt as E,St as F,Ot as G,Lt as H,Et as I,Vt as J,$t as K,Pe as L,Nt as M,Se as N,Ut as O,Oe as P,Xt as Q,Ve as R,qt as S,Gt as T,Ue as U,Ht as V,Qt as W,Kt as X,he as Y,zt as Z,Wt as _,we as $};
@@ -1 +0,0 @@
1
- import{a as _,c as P}from"./chunk-JS6TK4OP.js";import{f as u}from"./chunk-KRNQ6L35.js";import{a as w,b as j,c as n,g as T,n as b,o as R,p as I,q as m,u as h,v as l,x as f}from"./chunk-VD6G5NV4.js";async function F(t,a){if(!t)throw new Error("missing data source id");let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await I(s,{...a,id:t,createdAt:l(),createdBy:window.firebase.user.email}),u("datasource.create",{metadata:{datasourceId:t}})}async function G(){let t=window.__ROOT_CTX.rootConfig.projectId,a=window.firebase.db,o=j(a,"Projects",t,"DataSources"),e=T(o),s=await R(e),r=[];return s.forEach(c=>{r.push(c.data())}),r}async function S(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=await b(e);return s.exists()?s.data():null}async function O(t,a){let o=a?.mode||"draft",e=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,r=n(s,"Projects",e,"DataSources",t,"Data",o),c=await b(r);return c.exists()?c.data():null}async function U(t,a){let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await m(s,a),u("datasource.save",{metadata:{datasourceId:t}})}async function q(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:l(),archivedBy:window.firebase.user.email}),u("datasource.archive",{metadata:{datasourceId:t}})}async function H(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:h(),archivedBy:h()}),u("datasource.unarchive",{metadata:{datasourceId:t}})}async function W(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);if(a.type==="http"&&a.url&&!C(a.url)){let o=await fetch("/cms/api/data.sync",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id:a.id})});if(o.status!==200){let e=await o.text();throw new Error(`sync failed: ${e}`)}}else{let{data:o,headers:e}=await x(a),s=window.__ROOT_CTX.rootConfig.projectId,r=window.firebase.db,c=n(r,"Projects",s,"DataSources",t),d=n(r,"Projects",s,"DataSources",t,"Data","draft"),p={...a,syncedAt:w.now(),syncedBy:window.firebase.user.email},i=f(r);i.set(d,{dataSource:p,data:o,...e?{headers:e}:{}}),i.update(c,{syncedAt:w.now(),syncedBy:window.firebase.user.email}),await i.commit()}console.log(`synced data source: ${t}`),u("datasource.sync",{metadata:{datasourceId:t}})}async function M(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=await O(t,{mode:"draft"}),p={...a,publishedAt:w.now(),publishedBy:window.firebase.user.email},i=f(e);i.set(c,{dataSource:p,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),i.update(r,{dataSource:p}),i.update(s,{publishedAt:w.now(),publishedBy:window.firebase.user.email}),await i.commit(),console.log(`published data ${t}`),u("datasource.publish",{metadata:{datasourceId:t}})}async function k(t){if(!await S(t))throw new Error(`data source not found: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=f(e);d.update(s,{publishedAt:h(),publishedBy:h()}),(await b(r)).exists()&&d.update(r,{"dataSource.publishedAt":h(),"dataSource.publishedBy":h()}),d.delete(c),await d.commit(),console.log(`unpublished data source: ${t}`),u("datasource.unpublish",{metadata:{datasourceId:t}})}async function J(t,a){if(t.length===0)return;let o=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId,s=a?.batch||f(o);for(let r of t){let c=await S(r);if(!c)throw new Error(`data source not found: ${r}`);if(c.archivedAt)throw new Error(`data source is archived: ${r}`);let d=await O(r,{mode:"draft"}),p=n(o,"Projects",e,"DataSources",r),i=n(o,"Projects",e,"DataSources",r,"Data","draft"),y=n(o,"Projects",e,"DataSources",r,"Data","published"),D={...c,publishedAt:l(),publishedBy:window.firebase.user.email};s.set(y,{dataSource:D,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),s.update(i,{dataSource:D}),s.update(p,{publishedAt:l(),publishedBy:window.firebase.user.email}),u("datasource.publish",{metadata:{datasourceId:r}})}(!a?.batch||a?.commitBatch)&&await s.commit()}async function N(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=n(o,"Projects",a,"DataSources",t,"Data","draft"),r=n(o,"Projects",a,"DataSources",t,"Data","published"),c=f(o);c.delete(s),c.delete(r),c.delete(e),await c.commit(),console.log(`deleted data source ${t}`),u("datasource.delete",{metadata:{datasourceId:t}})}async function x(t){if(t.type==="http")return{data:await B(t)};if(t.type==="gsheet")return await v(t);throw new Error(`unsupported data source: ${t.type}`)}async function v(t){let a=P(t.url);if(!a?.spreadsheetId)throw new Error(`failed to parse google sheet url: ${t.url}`);let e=await new _(a.spreadsheetId).getSheet(a.gid??0);if(!e)throw new Error(`could not find sheet: ${t.url}`);let s=t.dataFormat||"map",[r,c]=await e.getValues();return s==="array"?{data:[r,c],headers:r}:{data:c.map(p=>{let i={};return p.forEach((y,D)=>{let g=r[D];g&&(i[g]=String(y||""))}),i}),headers:r}}async function B(t){if(!C(t.url))throw new Error(`unsupported url: ${t.url}`);let a=await fetch(t.url,{method:t.httpOptions?.method||"GET",headers:t.httpOptions?.headers||[],body:t.httpOptions?.body||void 0});if(a.status!==200){let e=await a.text();throw new Error(`req failed: ${e}`)}return String(a.headers.get("content-type")).includes("application/json")?await a.json():a.text()}function C(t){return t&&t.startsWith("/")}export{F as a,G as b,S as c,O as d,U as e,q as f,H as g,W as h,M as i,k as j,J as k,N as l};
@@ -1 +0,0 @@
1
- import{c as Q,e as z,f as N,g as Z}from"./chunk-344GZOGG.js";import{a as ee}from"./chunk-YDO2EDVY.js";import{a as G,c as K,n as g,p as P,q as B,v as b}from"./chunk-VD6G5NV4.js";import{c as V,e as O,h as S,k as L,y as j}from"./chunk-LROR6N3B.js";import{b as ie,d as ne}from"./chunk-PVAE643M.js";var re=ie((ke,te)=>{"use strict";function fe(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let r,o=0;return function(...a){clearTimeout(r);let n=Date.now(),c=n-o,d=t-c;d<=0?(o=n,e.apply(this,a)):r=setTimeout(()=>{o=Date.now(),e.apply(this,a)},d)}}te.exports=fe});j();var se=ne(re(),1);j();j();var oe=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},i=(e,t,r)=>(oe(e,t,"read from private field"),r?r.call(e):t.get(e)),p=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},C=(e,t,r,o)=>(oe(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);function me(e,t){return t!=null?(0,se.default)(e,t):e}var y,U,W,$,k,R,A,J,X,Ie=class{constructor(e=[]){p(this,y,void 0),p(this,U,"ready"),p(this,W,void 0),p(this,$,new Set),p(this,k,new Set),p(this,R,new Set),this.pushMessage=t=>{C(this,y,i(this,y).concat(t)),i(this,A).call(this)},this.popMessage=()=>{C(this,y,i(this,y).slice(0,-1)),i(this,A).call(this)},this.replaceMessage=(t,r)=>{C(this,y,[...i(this,y).slice(0,t),this.snapshot(r),...i(this,y).slice(t+1)]),i(this,A).call(this)},this.snapshot=t=>structuredClone(t),this["~registerMessagesCallback"]=(t,r)=>{let o=r?me(t,r):t;return i(this,$).add(o),()=>{i(this,$).delete(o)}},this["~registerStatusCallback"]=t=>(i(this,k).add(t),()=>{i(this,k).delete(t)}),this["~registerErrorCallback"]=t=>(i(this,R).add(t),()=>{i(this,R).delete(t)}),p(this,A,()=>{i(this,$).forEach(t=>t())}),p(this,J,()=>{i(this,k).forEach(t=>t())}),p(this,X,()=>{i(this,R).forEach(t=>t())}),C(this,y,e)}get status(){return i(this,U)}set status(e){C(this,U,e),i(this,J).call(this)}get error(){return i(this,W)}set error(e){C(this,W,e),i(this,X).call(this)}get messages(){return i(this,y)}set messages(e){C(this,y,[...e]),i(this,A).call(this)}};y=new WeakMap;U=new WeakMap;W=new WeakMap;$=new WeakMap;k=new WeakMap;R=new WeakMap;A=new WeakMap;J=new WeakMap;X=new WeakMap;var x,ae=class extends Q{constructor({messages:e,...t}){let r=new Ie(e);super({...t,state:r}),p(this,x,void 0),this["~registerMessagesCallback"]=(o,s)=>i(this,x)["~registerMessagesCallback"](o,s),this["~registerStatusCallback"]=o=>i(this,x)["~registerStatusCallback"](o),this["~registerErrorCallback"]=o=>i(this,x)["~registerErrorCallback"](o),C(this,x,r)}};x=new WeakMap;function Le({experimental_throttle:e,resume:t=!1,...r}={}){let o=O("chat"in r?{}:{onToolCall:r.onToolCall,onData:r.onData,onFinish:r.onFinish,onError:r.onError,sendAutomaticallyWhen:r.sendAutomaticallyWhen});"chat"in r||(o.current={onToolCall:r.onToolCall,onData:r.onData,onFinish:r.onFinish,onError:r.onError,sendAutomaticallyWhen:r.sendAutomaticallyWhen});let s={...r,onToolCall:u=>{var h,m;return(m=(h=o.current).onToolCall)==null?void 0:m.call(h,u)},onData:u=>{var h,m;return(m=(h=o.current).onData)==null?void 0:m.call(h,u)},onFinish:u=>{var h,m;return(m=(h=o.current).onFinish)==null?void 0:m.call(h,u)},onError:u=>{var h,m;return(m=(h=o.current).onError)==null?void 0:m.call(h,u)},sendAutomaticallyWhen:u=>{var h,m,H;return(H=(m=(h=o.current).sendAutomaticallyWhen)==null?void 0:m.call(h,u))!=null?H:!1}},a=O("chat"in r?r.chat:new ae(s));("chat"in r&&r.chat!==a.current||"id"in r&&a.current.id!==r.id)&&(a.current="chat"in r?r.chat:new ae(s));let c=S(u=>a.current["~registerMessagesCallback"](u,e),[e,a.current.id]),d=L(c,()=>a.current.messages,()=>a.current.messages),f=L(a.current["~registerStatusCallback"],()=>a.current.status,()=>a.current.status),l=L(a.current["~registerErrorCallback"],()=>a.current.error,()=>a.current.error),I=S(u=>{typeof u=="function"&&(u=u(a.current.messages)),a.current.messages=u},[a]);return V(()=>{t&&a.current.resumeStream()},[t,a]),{id:a.current.id,messages:d,setMessages:I,sendMessage:a.current.sendMessage,regenerate:a.current.regenerate,clearError:a.current.clearError,stop:a.current.stop,error:l,resumeStream:a.current.resumeStream,status:f,addToolResult:a.current.addToolOutput,addToolOutput:a.current.addToolOutput,addToolApprovalResponse:a.current.addToolApprovalResponse}}var Y=null;function _(){return Y||(Y=import("./ai-tools-4DWMFQS6.js")),Y}var ge=["doc_set","doc_create","doc_updateField","doc_edit","doc_duplicate"];function ye(e){return ge.includes(e)}function E(){let e=window;return{rootConfig:e.__ROOT_CTX.rootConfig,firebase:e.firebase}}function ve(e){let{collection:t,slug:r}=D(e);return`/cms/content/${encodeURIComponent(t)}/${encodeURIComponent(r)}`}function D(e){let t=e.indexOf("/");if(t<=0||t===e.length-1)throw new Error(`invalid docId: "${e}" (expected "Collection/slug")`);return{collection:e.slice(0,t),slug:e.slice(t+1).replace(/\//g,"--")}}function w(e){let{collection:t,slug:r}=D(e),{firebase:o,rootConfig:s}=E();return K(o.db,"Projects",s.projectId,"Collections",t,"Drafts",r)}function M(e){return Z(e,{isTimestamp:t=>t instanceof G,timestampToValue:t=>t.toMillis()})}function we(e){return JSON.parse(JSON.stringify(e??null))}function q(e){if(typeof e!="string")return e;let t=e.trim();if(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]"))try{return JSON.parse(t)}catch{return e}return e}function ce(e){return Array.isArray(e)?e.map(t=>{let r={op:t?.op,path:t?.path};return t&&"value"in t&&(r.value=q(t.value)),t&&t.index!==void 0&&t.index!==null&&(r.index=t.index),r}):[]}function de(e){switch(e.op){case"set":return`Set ${e.path}`;case"insert_item":return e.index===void 0?`Insert into ${e.path} (append)`:`Insert into ${e.path} at ${e.index}`;case"remove_item":return`Remove ${e.path}[${e.index}]`;default:return`${e.op} ${e.path}`}}function De(e,t,r){let o=t.split("."),s=e;for(let c=0;c<o.length-1;c++){let d=o[c],f=Array.isArray(s)?Number(d):d,l=o[c+1];(s[f]===void 0||s[f]===null)&&(s[f]=/^\d+$/.test(l)?[]:{}),s=s[f]}let a=o[o.length-1],n=Array.isArray(s)?Number(a):a;s[n]=r}async function le(e){let t=await g(w(e));if(!t.exists())return{found:!1,fields:{}};let r=t.data();return{found:!0,fields:M(r.fields||{}),raw:r}}function F(e){return{type:"cms-write-receipt",title:e.title,summary:e.summary,docId:e.docId,adminUrl:e.docId?ve(e.docId):void 0,details:[...e.details||[],{label:"Status",value:"Saved to draft"},{label:"Publishing",value:"Manual publish still required"}]}}function v(e){return{toolName:e.toolName,title:e.title,summary:e.summary,docId:e.docId,path:e.path,details:e.details||[],error:e.error,errors:e.errors,hint:e.hint}}async function Xe(e,t){if(!ye(e))throw new Error(`not a write tool: ${e}`);switch(e){case"doc_set":return pe(t);case"doc_create":return be(t);case"doc_updateField":return Ce(t);case"doc_edit":return _e(t);case"doc_duplicate":return Te(t)}}async function pe(e){let{collection:t}=D(e.docId),r=await T(t),{validateFields:o}=await _(),s=o(e.fields,r);if(s.length>0)return v({toolName:"doc_set",title:"Replace draft fields",summary:`Could not validate the replacement fields for ${e.docId}.`,docId:e.docId,error:"VALIDATION_FAILED",errors:s,hint:"The fields payload does not match the collection schema. Read the doc and schema, then retry with a valid payload."});let a=await le(e.docId);return{toolName:"doc_set",title:"Replace draft fields",summary:`Replace all draft fields for ${e.docId}.`,docId:e.docId,before:a.found?a.fields:{},after:e.fields||{},details:[{label:"Document",value:e.docId},{label:"Operation",value:a.found?"Replace draft":"Create draft"}]}}async function be(e){let{collection:t}=D(e.docId);if((await g(w(e.docId))).exists())return v({toolName:"doc_create",title:"Create draft document",summary:`${e.docId} already exists.`,docId:e.docId,error:"ALREADY_EXISTS",hint:"Use an unused slug, or use an update tool for the existing draft."});if(e.fields){let o=await T(t),{validateFields:s}=await _(),a=s(e.fields,o);if(a.length>0)return v({toolName:"doc_create",title:"Create draft document",summary:`Could not validate the initial fields for ${e.docId}.`,docId:e.docId,error:"VALIDATION_FAILED",errors:a,hint:"The fields payload does not match the collection schema."})}return{toolName:"doc_create",title:"Create draft document",summary:`Create ${e.docId} as a new draft document.`,docId:e.docId,before:{},after:e.fields||{},details:[{label:"Document",value:e.docId},{label:"Operation",value:"Create draft"}]}}async function Ce(e){let t=q(e.value),{collection:r}=D(e.docId),o=await T(r),{validateValueAtPath:s}=await _(),a=s(o,e.path,t);if(a.length>0)return v({toolName:"doc_updateField",title:"Update draft field",summary:`Could not validate ${e.path} for ${e.docId}.`,docId:e.docId,path:e.path,error:"VALIDATION_FAILED",errors:a,hint:"The value does not match the field schema. Inspect the doc and schema, then retry with a valid value."});let n=w(e.docId),c=await g(n);if(!c.exists())return v({toolName:"doc_updateField",title:"Update draft field",summary:`${e.docId} does not exist.`,docId:e.docId,path:e.path,error:"NOT_FOUND",hint:`Doc "${e.docId}" does not exist.`});let d=c.data(),f=z(d.fields||{},e.path);if(!f.ok)return v({toolName:"doc_updateField",title:"Update draft field",summary:`Could not resolve ${e.path} in ${e.docId}.`,docId:e.docId,path:e.path,error:"VALIDATION_FAILED",errors:[f.error],hint:"Use zero-based array indices for existing array items, or set the whole array field when appending or removing items."});let l=M(d.fields||{}),I=we(l);return De(I,e.path,t),{toolName:"doc_updateField",title:"Update draft field",summary:`Update ${e.path} in ${e.docId}.`,docId:e.docId,path:e.path,before:l,after:I,details:[{label:"Document",value:e.docId},{label:"Field path",value:e.path},{label:"Operation",value:"Update draft field"}]}}async function _e(e){let t=ce(e.operations),{collection:r}=D(e.docId),o=await T(r),s=await le(e.docId);if(!s.found)return v({toolName:"doc_edit",title:"Edit draft document",summary:`${e.docId} does not exist.`,docId:e.docId,error:"NOT_FOUND",hint:`Doc "${e.docId}" does not exist. Create it with \`doc_create\` first.`});let{applyDocEdits:a,validateFields:n}=await _(),c=a(s.fields,t);if(!c.ok)return v({toolName:"doc_edit",title:"Edit draft document",summary:`Operation ${c.error.opIndex+1} (${c.error.op}) could not be applied to ${e.docId}.`,docId:e.docId,error:"INVALID_OPERATION",errors:[c.error],hint:"Fix the failing operation. Use zero-based array indices, target arrays for insert_item/remove_item, and read the doc with `doc_get` to confirm the current shape."});let d=n(c.fields,o);return d.length>0?v({toolName:"doc_edit",title:"Edit draft document",summary:`The edits to ${e.docId} did not match the collection schema.`,docId:e.docId,error:"VALIDATION_FAILED",errors:d,hint:"The resulting fields do not match the collection schema. Inspect the doc and schema, then retry with valid values."}):{toolName:"doc_edit",title:"Edit draft document",summary:`Apply ${t.length} edit${t.length===1?"":"s"} to ${e.docId}.`,docId:e.docId,before:s.fields,after:c.fields,details:[{label:"Document",value:e.docId},...t.map((f,l)=>({label:`Operation ${l+1}`,value:de(f)}))]}}async function Te(e){let t=w(e.fromDocId),r=await g(t);if(!r.exists())return v({toolName:"doc_duplicate",title:"Duplicate draft document",summary:`${e.fromDocId} does not exist.`,docId:e.toDocId,error:"NOT_FOUND",hint:`Source doc "${e.fromDocId}" does not exist.`,details:[{label:"Source",value:e.fromDocId}]});let o=w(e.toDocId);if((await g(o)).exists())return v({toolName:"doc_duplicate",title:"Duplicate draft document",summary:`${e.toDocId} already exists.`,docId:e.toDocId,error:"ALREADY_EXISTS",hint:`Target doc "${e.toDocId}" already exists.`,details:[{label:"Source",value:e.fromDocId},{label:"Target",value:e.toDocId}]});let a=r.data(),n=M(a.fields||{});return{toolName:"doc_duplicate",title:"Duplicate draft document",summary:`Duplicate ${e.fromDocId} to ${e.toDocId}.`,docId:e.toDocId,before:{},after:n,details:[{label:"Source",value:e.fromDocId},{label:"Target",value:e.toDocId},{label:"Operation",value:"Create draft copy"}]}}async function T(e){return await ee(e)}async function Ae(e){let{collection:t,slug:r}=D(e.docId),o=await T(t),{validateFields:s}=await _(),a=s(e.fields,o);if(a.length>0)return{success:!1,docId:e.docId,error:"VALIDATION_FAILED",errors:a,hint:"The fields payload did not match the collection schema. Read the doc with `doc_get` for an example of the expected shape, then retry with a valid payload."};let{firebase:n}=E(),c=w(e.docId),d=await g(c),l=(d.exists()?d.data():{}).sys||{},I=n.user?.email||"root-cms-ai",u={id:e.docId,collection:t,slug:r,sys:{...l,createdAt:l.createdAt??b(),createdBy:l.createdBy??I,modifiedAt:b(),modifiedBy:I,locales:l.locales??["en"]},fields:N(e.fields)};return await P(c,u),{success:!0,docId:e.docId,receipt:F({title:"Updated draft document",summary:`Replaced all draft fields for ${e.docId}.`,docId:e.docId,details:[{label:"Document",value:e.docId},{label:"Operation",value:"Replace draft fields"}]})}}async function xe(e){let{collection:t,slug:r}=D(e.docId),o=w(e.docId);if((await g(o)).exists())return{success:!1,docId:e.docId,error:"ALREADY_EXISTS",hint:"A doc with this id already exists. Use `doc_set` to overwrite."};if(e.fields){let d=await T(t),{validateFields:f}=await _(),l=f(e.fields,d);if(l.length>0)return{success:!1,docId:e.docId,error:"VALIDATION_FAILED",errors:l,hint:"The fields payload did not match the collection schema."}}let{firebase:a}=E(),n=a.user?.email||"root-cms-ai",c={id:e.docId,collection:t,slug:r,sys:{createdAt:b(),createdBy:n,modifiedAt:b(),modifiedBy:n,locales:["en"]},fields:e.fields?N(e.fields):{}};return await P(o,c),{success:!0,docId:e.docId,receipt:F({title:"Created draft document",summary:`Created ${e.docId} as a new draft document.`,docId:e.docId,details:[{label:"Document",value:e.docId},{label:"Operation",value:"Create draft"}]})}}async function Ee(e){let t=q(e.value),{collection:r}=D(e.docId),o=await T(r),{validateValueAtPath:s}=await _(),a=s(o,e.path,t);if(a.length>0)return{success:!1,docId:e.docId,path:e.path,error:"VALIDATION_FAILED",errors:a,hint:"The value did not match the field schema. Inspect the doc with `doc_get` to see the expected shape, then retry with a valid value."};let n=w(e.docId),c=await g(n);if(!c.exists())return{success:!1,docId:e.docId,path:e.path,error:"NOT_FOUND",hint:`Doc "${e.docId}" does not exist.`};let d=c.data(),f=z(d.fields||{},e.path);if(!f.ok)return{success:!1,docId:e.docId,path:e.path,error:"VALIDATION_FAILED",errors:[f.error],hint:"The path could not be resolved against the current draft. Use zero-based array indices for existing array items, or set the whole array field when appending or removing items."};let{firebase:l}=E(),I=`fields.${f.path}`,u=N(t);return await B(n,{[I]:u,"sys.modifiedAt":b(),"sys.modifiedBy":l.user?.email||"root-cms-ai"}),{success:!0,docId:e.docId,path:e.path,receipt:F({title:"Updated draft field",summary:`Updated ${e.path} in ${e.docId}.`,docId:e.docId,details:[{label:"Document",value:e.docId},{label:"Field path",value:e.path},{label:"Operation",value:"Update draft field"}]})}}async function Oe(e){let t=ce(e.operations),{collection:r}=D(e.docId),o=await T(r),s=w(e.docId),a=await g(s);if(!a.exists())return{success:!1,docId:e.docId,error:"NOT_FOUND",hint:`Doc "${e.docId}" does not exist.`};let n=a.data(),c=M(n.fields||{}),{applyDocEdits:d,validateFields:f}=await _(),l=d(c,t);if(!l.ok)return{success:!1,docId:e.docId,error:"INVALID_OPERATION",errors:[l.error],hint:"Fix the failing operation. Use zero-based array indices, target arrays for insert_item/remove_item, and read the doc with `doc_get` to confirm the current shape."};let I=f(l.fields,o);if(I.length>0)return{success:!1,docId:e.docId,error:"VALIDATION_FAILED",errors:I,hint:"The resulting fields did not match the collection schema. Inspect the doc with `doc_get`, then retry with valid values."};let{firebase:u}=E();return await B(s,{fields:N(l.fields),"sys.modifiedAt":b(),"sys.modifiedBy":u.user?.email||"root-cms-ai"}),{success:!0,docId:e.docId,receipt:F({title:"Edited draft document",summary:`Applied ${t.length} edit${t.length===1?"":"s"} to ${e.docId}.`,docId:e.docId,details:[{label:"Document",value:e.docId},{label:"Operations",value:String(t.length)},...t.map((h,m)=>({label:`Operation ${m+1}`,value:de(h)}))]})}}async function Se(e){let t=w(e.fromDocId),r=await g(t);if(!r.exists())return{success:!1,error:"NOT_FOUND",hint:`Source doc "${e.fromDocId}" does not exist.`};let o=w(e.toDocId);if((await g(o)).exists())return{success:!1,error:"ALREADY_EXISTS",hint:`Target doc "${e.toDocId}" already exists.`};let{collection:a,slug:n}=D(e.toDocId),{firebase:c}=E(),d=c.user?.email||"root-cms-ai",f=r.data(),l={id:e.toDocId,collection:a,slug:n,sys:{createdAt:b(),createdBy:d,modifiedAt:b(),modifiedBy:d,locales:f.sys?.locales??["en"]},fields:f.fields||{}};return await P(o,l),{success:!0,fromDocId:e.fromDocId,toDocId:e.toDocId,receipt:F({title:"Duplicated draft document",summary:`Duplicated ${e.fromDocId} to ${e.toDocId}.`,docId:e.toDocId,details:[{label:"Source",value:e.fromDocId},{label:"Target",value:e.toDocId},{label:"Operation",value:"Create draft copy"}]})}}async function Ne(e){let t=await fetch("/cms/api/ai.translate",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({sourceText:e.sourceText,targetLocales:e.targetLocales,description:e.description})});if(!t.ok)throw new Error(`ai.translate failed: ${t.status}`);let r=await t.json();if(!r.success)throw new Error(r.error||"translation failed");return{translations:r.translations}}var $e={doc_set:Ae,doc_create:xe,doc_updateField:Ee,doc_edit:Oe,doc_duplicate:Se,doc_translateField:Ne};async function Ye(e,t){let r=$e[e];if(!r)return{error:"UNKNOWN_TOOL",toolName:e};try{return await r(t)}catch(o){return console.error(`tool ${e} failed:`,o),{error:"TOOL_EXECUTION_FAILED",message:o?.message||String(o)}}}export{Le as a,ye as b,Xe as c,Ye as d};
@@ -1 +0,0 @@
1
- import{b as g,g as d,i as l,j as p,o as h}from"./chunk-VD6G5NV4.js";var r={year:31536e6,month:2628e6,week:6048e5,day:864e5,hour:36e5,minute:6e4,second:1e3};function w(e,t){let n=Math.abs(e-new Date().getTime());if(n<r.second)return"just now";let i=t||{numeric:"auto"},o=new Intl.RelativeTimeFormat("en",i);return n<r.minute?o.format(Math.round(-n/r.second),"second"):n<r.hour?o.format(Math.round(-n/r.minute),"minute"):n<r.day?o.format(Math.round(-n/r.hour),"hour"):n<r.week?o.format(Math.round(-n/r.day),"day"):new Date(e).toLocaleDateString("en",{year:"numeric",month:"short",day:"numeric"})}function f(){return Math.floor(new Date().getTime())}function I(e){return new Date(e.toMillis()).toLocaleDateString("en",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function M(){let e=a=>a<10?"0"+a:a,t=new Date,n=t.getFullYear(),i=e(t.getMonth()+1),o=e(t.getDate()),s=e(t.getHours()),u=e(t.getMinutes());return`${n}-${i}-${o}T${s}:${u}`}var y={};async function O(e,t){let n=t?.throttle||0,i=t?.throttleId?`${e}::${t.throttleId}`:e;if(b(i,n))return;let o=await fetch("/cms/api/actions.log",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:e,metadata:t?.metadata||{},links:t?.links})});if(o.status!==200){let s=await o.text();console.error(`failed to log action "${e}":`,s);return}y[i]=f()}async function k(e){let t=window.__ROOT_CTX.rootConfig.projectId,n=window.firebase.db,i=g(n,"Projects",t,"ActionLogs"),o=e?.limit,s;if(o){let c=Math.ceil(o*1.5);s=d(i,l("timestamp","desc"),p(c))}else s=d(i,l("timestamp","desc"));let u=await h(s),a=[];function T(c){if(a.length===0)return!1;let m=a.at(-1);return c.action==="doc.save"&&m.action==="doc.save"&&c.by===m.by&&c.metadata.docId===m.metadata.docId&&c.timestamp.toMillis()-m.timestamp.toMillis()<60*r.minute}for(let c of u.docs){if(o&&a.length>=o)break;let m=c.data();T(m)||a.push(m)}return a}function b(e,t){if(t===0)return!1;let n=y[e];return n?f()-n<t:!1}export{r as a,w as b,f as c,I as d,M as e,O as f,k as g};
@@ -1 +0,0 @@
1
- import{b as _}from"./chunk-D3UIZHRK.js";import{a as S,c as u}from"./chunk-HARRKJFZ.js";import{Ga as e,V as n,a as l,c as d,da as c,j as x}from"./chunk-LROR6N3B.js";x();var r="DataSourceSelectModal";function L(){let a=S(),t=u();return{open:i=>{a.openContextModal(r,{...t,innerProps:i,size:"600px",overflow:"inside"})},close:()=>{a.closeModal(r)}}}function h(a){let{innerProps:t}=a,[i,m]=l(!0),[s,p]=l([]),D=t.selectedDataSourceIds||[];d(()=>{async function o(){let v=await _();p(v.filter(g=>!g.archivedAt)),m(!1)}o()},[]);function f(o){t.onChange&&t.onChange(o,!0)}function M(o){t.onChange&&t.onChange(o,!1)}return e("div",{className:"DataSourceSelectModal",children:i?e("div",{className:"DataSourceSelectModal__loading",children:e(n,{color:"gray",size:"xl"})}):s.length===0?e("div",{className:"DataSourceSelectModal__empty",children:"No data sources."}):e("div",{className:"DataSourceSelectModal__list",children:s.map(o=>e("div",{className:"DataSourceSelectModal__item",children:[e("div",{className:"DataSourceSelectModal__item__info",children:[e("div",{className:"DataSourceSelectModal__item__id",children:o.id}),e("div",{className:"DataSourceSelectModal__item__description",children:o.description||""})]}),e("div",{className:"DataSourceSelectModal__item__action",children:D.includes(o.id)?e(c,{variant:"light",color:"blue",size:"xs",onClick:()=>M(o.id),children:"Unselect"}):e(c,{variant:"filled",color:"blue",size:"xs",onClick:()=>f(o.id),children:"Select"})})]},o.id))})})}h.id=r;export{L as a,h as b};
@@ -1 +0,0 @@
1
- import{a as k}from"./chunk-ENQKSLGJ.js";import{a as J}from"./chunk-TOGLZDK3.js";import{b as U}from"./chunk-JS6TK4OP.js";import{g as B}from"./chunk-KRNQ6L35.js";import{a as b}from"./chunk-VD6G5NV4.js";import{e as I}from"./chunk-BUNR5EU3.js";import{Cc as H,Da as F,F as O,Fa as f,Ga as t,U as w,V as N,a as l,c as v,da as m,g as A,j as et,sa as C,ua as z,wa as j,za as E}from"./chunk-LROR6N3B.js";import{d as D}from"./chunk-KUCVLANF.js";et();var S=50,at=["doc.save","doc.publish","doc.restore_version","doc.import_translations","doc.revert"],ot=[{value:"all",label:"All time"},{value:"1h",label:"Last hour"},{value:"24h",label:"Last 24 hours"},{value:"7d",label:"Last 7 days"},{value:"30d",label:"Last 30 days"}];function Q(e){let[a,o]=l(!0),[n,s]=l([]);return v(()=>{B(e?{limit:e}:void 0).then(d=>{s(d),o(!1)})},[e]),{loading:a,actions:n}}function $t(e){if(e.compact)return t(ct,{...e});let[a,o]=l(""),[n]=O(a,300),[s,d]=l([]),[h,q]=l([]),[p,X]=l("all"),[L,M]=l(1),{actions:r,loading:Y}=Q(),Z=A(()=>{let i=new Set;return r.forEach(c=>i.add(c.action)),Array.from(i).sort()},[r]),K=A(()=>{let i=new Set;return r.forEach(c=>{c.by&&i.add(c.by)}),Array.from(i).sort()},[r]),g=A(()=>{let i=Date.now();return r.filter(c=>{if(n){let u=n.toLowerCase(),x=c.action.toLowerCase().includes(u),_=c.by?.toLowerCase().includes(u),tt=ut(c.metadata).toLowerCase().includes(u);if(!x&&!_&&!tt)return!1}if(s.length>0&&!s.includes(c.action)||h.length>0&&(!c.by||!h.includes(c.by)))return!1;if(p&&p!=="all"){let u=T(c.timestamp);if(!u)return!1;let x=u.toMillis(),_=0;switch(p){case"1h":_=i-3600*1e3;break;case"24h":_=i-1440*60*1e3;break;case"7d":_=i-10080*60*1e3;break;case"30d":_=i-720*60*60*1e3;break}if(x<_)return!1}return!0})},[r,n,s,h,p]),P=e.compact?1:Math.ceil(g.length/S),y=A(()=>{if(e.compact)return g;let i=(L-1)*S;return g.slice(i,i+S)},[g,L,e.compact]);return v(()=>{M(1)},[n,s,h,p]),Y?t("div",{className:`ActionsLog ActionsLog--loading ${e.className||""}`,children:t(N,{color:"gray",size:"xl"})}):t("div",{className:`ActionsLog ${e.className||""}`,children:[!e.compact&&t("div",{className:"ActionsLog__tableHeader",children:[t("div",{className:"ActionsLog__filters",children:[t(z,{className:"ActionsLog__filters__search",placeholder:"Search actions...",icon:t(H,{size:16}),value:a,onChange:i=>o(i.target.value)}),t(C,{className:"ActionsLog__filters__select",placeholder:"Filter by action",clearable:!0,searchable:!0,data:Z,value:s,onChange:d}),t(C,{className:"ActionsLog__filters__select",placeholder:"Filter by user",clearable:!0,searchable:!0,data:K,value:h,onChange:q}),t(E,{className:"ActionsLog__filters__select",placeholder:"Filter by time",data:ot,value:p,onChange:X})]}),t("div",{className:"ActionsLog__summary",children:["Showing ",y.length," of ",g.length," ","actions",g.length!==r.length&&` (filtered from ${r.length} total)`]})]}),t(J,{className:"ActionsLog__tableSurface",children:t(F,{className:"ActionsLog__table",children:[t("thead",{children:t("tr",{className:"ActionsLogs__table__row ActionsLogs__table__row--header",children:[t("th",{className:"ActionsLogs__table__header",children:"Timestamp"}),t("th",{className:"ActionsLogs__table__header",children:"User"}),t("th",{className:"ActionsLogs__table__header",children:"Action"}),t("th",{className:"ActionsLogs__table__header",children:"Details"}),t("th",{className:"ActionsLogs__table__header",children:"Links"})]})}),t("tbody",{children:[y.map((i,c)=>t("tr",{className:"ActionsLogs__table__row",children:[t("td",{className:"ActionsLogs__table__col ActionsLogs__table__col--nowrap",children:t(R,{timestamp:i.timestamp,format:"long"})}),t("td",{className:"ActionsLogs__table__col ActionsLogs__table__col--nowrap",children:t("span",{className:"ActionsLogs__user",children:i.by?t(D,{children:[t(k,{email:i.by,size:20}),t("span",{className:"ActionsLogs__user__email",children:i.by})]}):"\u2014"})}),t("td",{className:"ActionsLogs__table__col ActionsLogs__table__col--action",children:t("span",{className:"ActionsLogs__action",children:i.action})}),t("td",{className:"ActionsLogs__table__col ActionsLogs__table__col--metadata",children:t(G,{metadata:i.metadata})}),t("td",{className:"ActionsLogs__table__col ActionsLogs__table__col--links",children:t($,{action:i})})]},c)),y.length===0&&t("tr",{children:t("td",{colSpan:5,className:"ActionsLogs__table__col ActionsLogs__table__col--empty",children:"No actions found matching your filters."})})]})]})}),!e.compact&&P>1&&t("div",{className:"ActionsLog__pagination",children:t(j,{total:P,value:L,onChange:M,size:"sm"})})]})}function G(e){let{metadata:a}=e;if(!a||Object.keys(a).length===0)return t("span",{className:"ActionsLogs__metadata--empty",children:"\u2014"});let o=Object.entries(a);return t("div",{className:"ActionsLogs__metadata",children:o.map(([n,s])=>t("div",{className:"ActionsLogs__metadata__item",children:[t("span",{className:"ActionsLogs__metadata__key",children:[n,":"]})," ",t("span",{className:"ActionsLogs__metadata__value",children:nt(s)})]},n))})}function nt(e){if(e==null)return"\u2014";if(Array.isArray(e))return e.length===0?"[]":e.length<=3?e.join(", "):`${e.slice(0,3).join(", ")} (+${e.length-3} more)`;if(typeof e=="object"){let a=st(e);try{return JSON.stringify(a)}catch(o){console.error(o),console.error("failed to stringify json:",a)}}return String(e)}function st(e){let a={};return Object.entries(e).forEach(([o,n])=>{o.startsWith("_")||(a[o]=n)}),a}function $(e){let{action:a}=e,o=[];function n(s){return e.label||s}if(a.action!=="doc.delete"&&a.metadata?.docId&&o.push(t(f,{transition:"pop",label:a.metadata.docId,children:t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:`/cms/content/${a.metadata.docId}`,children:n("Open doc")})},"doc")),at.includes(a.action)&&a.metadata?.docId){let s=T(a.timestamp)?.toMillis();s&&o.push(t(f,{transition:"pop",label:`Show changes to ${a.metadata.docId}`,children:t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:it(a.metadata.docId,s),children:n("Show changes")})},"changes"))}return a.action!=="datasource.delete"&&a.metadata?.datasourceId&&o.push(t(f,{transition:"pop",label:a.metadata.datasourceId,children:t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:`/cms/data/${a.metadata.datasourceId}`,children:n("Open data source")})},"datasource")),a.action!=="release.delete"&&a.metadata?.releaseId&&o.push(t(f,{transition:"pop",label:a.metadata.releaseId,children:t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:`/cms/releases/${a.metadata.releaseId}`,children:n("Open release")})},"release")),a.metadata?.sheetId&&o.push(t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:U(a.metadata.sheetId),target:"_blank",children:n("Open sheet")},"sheet")),a.action.startsWith("acls.")&&o.push(t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:"/cms/settings",children:n("Open settings")},"settings")),a.links&&a.links.forEach((s,d)=>{o.push(t(m,{component:"a",variant:"default",size:"xs",compact:!0,href:s.url,target:s.target,children:s.label},`link-${d}`))}),o.length===0?t("span",{className:"ActionsLogs__links--empty"}):(e.limit&&(o=o.slice(0,e.limit)),t("div",{className:"ActionsLogs__table__buttons",children:o}))}function it(e,a){let o=W(e,`before:${a}`),n=W(e,`after:${a}`);return`/cms/compare?left=${o}&right=${n}`}function W(e,a){return encodeURIComponent(`${e}@${a}`).replaceAll("%2F","/").replaceAll("%40","@").replaceAll("%3A",":")}function ct(e){let{actions:a,loading:o}=Q(e.limit||10);return o?t("div",{className:I(e.className,"ActionLogsCompact","ActionLogsCompact--loading"),children:t(N,{color:"gray",size:"xl"})}):t("div",{className:I(e.className,"ActionLogsCompact"),children:t(w,{className:"ActionLogsCompact__table",multiple:!0,children:a.map((n,s)=>t(w.Item,{label:t(rt,{action:n}),children:t(lt,{action:n})},s))})})}function rt(e){let a=e.action,o=mt(a),n=e.action.by||"";return t("div",{className:"ActionLogsCompactItemPreview",children:[t("div",{className:"ActionLogsCompactItemPreview__user",children:t(k,{email:n,size:20})}),t("div",{className:"ActionLogsCompactItemPreview__timestamp",children:t(R,{timestamp:a.timestamp})}),t("div",{className:"ActionLogsCompactItemPreview__action",children:a.action}),t("div",{className:"ActionLogsCompactItemPreview__actionMetaId",children:o}),t("div",{className:"ActionLogsCompactItemPreview__buttons",children:t($,{action:a,label:"Open",limit:1})})]})}function lt(e){let a=e.action,o={user:a.by,...a.metadata};return t("div",{className:"ActionLogsCompactItemDetails",children:[t(G,{metadata:o}),t($,{action:a})]})}function mt(e){for(let a of Object.keys(e.metadata||{}))if(a.toLowerCase().endsWith("id"))return e.metadata[a];return""}function T(e){return e?e instanceof b?e:typeof e=="object"&&typeof e._seconds=="number"?new b(e._seconds,e._nanoseconds||0):typeof e=="object"&&typeof e.seconds=="number"?new b(e.seconds,e.nanoseconds||0):typeof e=="number"?b.fromMillis(e):null:null}function R(e){let a=T(e.timestamp)?.toMillis()||0;if(!a)return t("span",{children:"Invalid date"});let o=e.format==="long"?pt(a):_t(a);return t(f,{transition:"pop",label:gt(a),children:t("span",{className:"ActionsLogs__timestamp",children:o})})}var dt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function V(e){let a=e.getHours(),o=a<12?"AM":"PM",n=String(a%12||12).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0");return`${n}:${s} ${o}`}function _t(e){let a=new Date(e),o=String(a.getDate()).padStart(2,"0");return`${dt[a.getMonth()]} ${o}, ${V(a)}`}function pt(e){let a=new Date(e),o=a.toLocaleDateString("en",{month:"long"}),n=String(a.getDate()).padStart(2,"0");return`${o} ${n}, ${a.getFullYear()} ${V(a)}`}function gt(e){return new Date(e).toLocaleString("en",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}function ut(e){function a(o){return o===null?"null":typeof o>"u"?"undefined":typeof o=="string"?`"${o.replaceAll('"','\\"')}"`:typeof o!="object"?String(o):Array.isArray(o)?`[${o.map(a).join(", ")}]`:`{${Object.entries(o).map(([s,d])=>`${s}: ${a(d)}`).join(", ")}}`}return a(e)}export{$t as a};
@@ -1 +0,0 @@
1
- import{i as M}from"./chunk-2S5HMST6.js";import{a as n,c as _}from"./chunk-HARRKJFZ.js";import{b as h}from"./chunk-J5E457OI.js";import{a as u}from"./chunk-QHJOTXYB.js";import{e as f}from"./chunk-KRNQ6L35.js";import{a as m}from"./chunk-VD6G5NV4.js";import{Ga as e,a as i,da as d,e as c,j as I}from"./chunk-LROR6N3B.js";I();var S="ScheduleReleaseModal";function F(l){let t=n(),a=_();return{open:()=>{t.openContextModal(S,{...a,title:`Schedule release: ${l.releaseId}`,innerProps:l})}}}function T(l){let{innerProps:t,context:a,id:g}=l,[s,x]=i(""),[R,r]=i(!1),v=c(null),b=n();async function w(){r(!0),await h(async()=>{let o=Math.floor(new Date(s).getTime());if(Math.floor(new Date().getTime())>=o)throw new Error("bad datetime, please choose a date in the future");let y=m.fromMillis(o);await M(t.releaseId,o),u({title:"Scheduled!",message:`Release ${t.releaseId} will go live ${s}.`,autoClose:1e4}),b.closeAll(),t.onScheduled&&t.onScheduled(y)}),r(!1)}return e("div",{className:"ScheduleReleaseModal",children:e("div",{className:"ScheduleReleaseModal__content",children:e("form",{className:"ScheduleReleaseModal__form",onSubmit:o=>{o.preventDefault(),w()},children:[e("div",{className:"ScheduleReleaseModal__form__description",children:"Content in the release will go live at the datetime specified below."}),e("div",{className:"ScheduleReleaseModal__form__dateInput",children:[e("input",{ref:v,type:"datetime-local",value:s,min:f(),onChange:o=>{let p=o.target;x(p.value)}}),e("div",{className:"ScheduleReleaseModal__form__dateInput__help",children:["timezone: ",Intl.DateTimeFormat().resolvedOptions().timeZone]})]}),e("div",{className:"ScheduleReleaseModal__form__buttons",children:[e(d,{variant:"outline",onClick:()=>a.closeModal(g),type:"button",size:"xs",color:"dark",children:"Cancel"}),e(d,{variant:"filled",size:"xs",color:"dark",loading:R,type:"submit",children:"Schedule"})]})]})})})}T.id=S;export{F as a,T as b};
@@ -1 +0,0 @@
1
- import{a as H}from"./chunk-N3JSLTMV.js";import{a as j}from"./chunk-XWX2622O.js";import{f as U}from"./chunk-PTPYMVFW.js";import{b as B,d as L,e as O,j as A}from"./chunk-2S5HMST6.js";import{a as q}from"./chunk-GT5EQSEX.js";import{a as T}from"./chunk-JDW4UORS.js";import{a as W}from"./chunk-W5DOO6ID.js";import{a as $}from"./chunk-NSOTG64N.js";import{b as M}from"./chunk-J5E457OI.js";import{a as v}from"./chunk-QHJOTXYB.js";import{d as k}from"./chunk-BUNR5EU3.js";import{$ as D,Fa as I,Ga as e,Qa as V,Rc as F,W as p,a as c,c as N,da as f,e as P,j as ie,na as y,pa as z,ua as E}from"./chunk-LROR6N3B.js";ie();function R(s){let{route:i}=k(),S=P(null),[Y,d]=c(!1),[w,g]=c(""),[G,h]=c(!!s.releaseId),[J,C]=c(null),[m,x]=c([]),[_,b]=c([]),K=j(),Q=H(),{roles:X}=$(),Z=window.firebase.user.email||"",n=W(X,Z);async function ee(r){console.log(r),await M(async()=>{let t=await L(r);C(t),x(t?.docIds||[]),b(t?.dataSourceIds||[])}),h(!1)}N(()=>{s.releaseId&&(h(!0),ee(s.releaseId))},[s.releaseId]);async function oe(){g("");let r=S.current;function t(l){let u=r.elements[l];return u?u.value.trim():""}let o=s.releaseId||t("id");if(!o){g("missing id");return}if(!T(o)){g("id is invalid (alphanumeric characters and dashes only)");return}let a={id:o,description:t("description"),docIds:m,dataSourceIds:_};try{C(a),d(!0),s.releaseId?(await O(s.releaseId,a),v({title:"Saved release",message:`Updated ${o}`,autoClose:5e3}),d(!1)):(await B(o,a),v({title:"Added release",message:`Successfully added ${o}`,autoClose:5e3}),d(!1)),i(`/cms/releases/${o}`)}catch(l){console.error(l),v({title:"Failed to save release",message:String(l),color:"red",autoClose:!1}),d(!1)}}function ae(){K.open({multiSelect:!0,selectedDocIds:m,onChangeMulti:(r,t)=>{x(o=>{let a=[...o];if(t)a.push(r);else{let l=a.findIndex(u=>u===r);l>-1&&a.splice(l,1)}return console.log(a),a.sort()})}})}function se(){Q.open({selectedDataSourceIds:_,onChange:(r,t)=>{b(o=>{let a=[...o];if(t)a.push(r);else{let l=a.indexOf(r);l>-1&&a.splice(l,1)}return a.sort()})}})}function re(r){console.log("onRemoveDoc()",r),x(t=>{let o=[...t],a=o.indexOf(r);return a!==-1&&o.splice(a,1),console.log(o),o})}function te(r){b(t=>{let o=[...t],a=o.indexOf(r);return a!==-1&&o.splice(a,1),o})}return e("form",{className:"ReleaseForm",ref:S,onSubmit:r=>{r.preventDefault(),oe()},children:[e(z,{visible:G}),e(E,{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:s.releaseId||A(),disabled:!!s.releaseId}),e(y,{className:"ReleaseForm__input",name:"description",label:"Description",description:"Optional.",size:"xs",radius:0,value:J?.description,disabled:!n}),e(D,{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:[m.length>0&&e(R.DocPreviewCards,{docIds:m,onRemoveDoc:re,canEdit:n}),e(f,{className:"ReleaseForm__docSelectButton",color:"dark",size:"xs",onClick:()=>ae(),disabled:!n,children:"Select"})]}),e(D,{className:"ReleaseForm__input",label:"Data Sources",description:"Optional. Data sources to publish with the release.",size:"xs",children:[_.length>0&&e(R.DataSourceIds,{ids:_,onRemove:te,canEdit:n}),e(f,{className:"ReleaseForm__docSelectButton",color:"dark",size:"xs",onClick:()=>se(),disabled:!n,children:"Select"})]}),e("div",{className:"ReleaseForm__submit__buttons",children:e(q,{label:"You don't have access to create or edit releases",condition:!n,children:e("span",{children:e(f,{className:"ReleaseForm__submit",color:"blue",size:"xs",type:"submit",loading:Y,disabled:!n,children:s.buttonLabel||"Save"})})})}),w&&e("div",{className:"ReleaseForm__error",children:["Error: ",w]})]})}R.DocPreviewCards=s=>e("div",{className:"ReleaseForm__DocPreviewCards",children:s.docIds.map(i=>e("div",{className:"ReleaseForm__DocPreviewCards__card",children:[e(U,{className:"ReleaseForm__DocPreviewCards__card__preview",docId:i}),e("div",{className:"ReleaseForm__DocPreviewCards__card__controls",children:[s.canEdit&&e("div",{className:"ReleaseForm__DocPreviewCards__card__controls__remove",children:e(I,{label:"Remove",children:e(p,{className:"ReleaseForm__DocPreviewCards__card__controls__remove__icon",onClick:()=>s.onRemoveDoc(i),children:e(F,{size:16})})})}),e("div",{className:"ReleaseForm__DocPreviewCards__card__controls__open",children:e(I,{label:"Open",children:e(p,{component:"a",className:"ReleaseForm__DocPreviewCards__card__controls__open__icon",href:`/cms/content/${i}`,target:"_blank",children:e(V,{size:16})})})})]})]},i))});R.DataSourceIds=s=>e("div",{className:"ReleaseForm__DataSourceIds",children:s.ids.map(i=>e("div",{className:"ReleaseForm__DataSourceIds__item",children:[e("span",{className:"ReleaseForm__DataSourceIds__item__id",children:i}),s.canEdit&&e(p,{className:"ReleaseForm__DataSourceIds__item__remove",onClick:()=>s.onRemove(i),children:e(F,{size:16})})]},i))});export{R as a};
@@ -1 +0,0 @@
1
- import{e}from"./chunk-BUNR5EU3.js";import{Ga as o}from"./chunk-LROR6N3B.js";function n(r){return o("div",{className:e(r.className,"Surface"),children:r.children})}export{n as a};
@@ -1 +0,0 @@
1
- import{a as P}from"./chunk-3E6CASIN.js";import{a as $}from"./chunk-GT5EQSEX.js";import{h as w,i as A}from"./chunk-D3UIZHRK.js";import{a as C}from"./chunk-W5DOO6ID.js";import{a as B}from"./chunk-NSOTG64N.js";import{a as v,b as S}from"./chunk-QHJOTXYB.js";import{b as l}from"./chunk-KRNQ6L35.js";import{a as D}from"./chunk-VD6G5NV4.js";import{Fa as c,Ga as o,a as e,c as y,da as T,j as g}from"./chunk-LROR6N3B.js";g();g();function x(t){let i=k(t.timestamp),[s,a]=e(i>0?l(i,{style:"short"}):"never");return i?(y(()=>{let u=window.setInterval(()=>{a(l(i,{style:"short"}))},6e4);return()=>window.clearInterval(u)},[]),o(c,{transition:"pop",label:`${U(i)} by ${t.email}`,children:l(i,{style:"short"})})):o("div",{children:s})}function U(t){return new Date(t).toLocaleDateString("en",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function k(t){return typeof t=="number"?t:t?.toMillis?t.toMillis():0}function et(t){let i=t.dataSource,[s,a]=e(!1),[u,N]=e(t.action==="sync"?i.syncedAt:i.publishedAt),[I,L]=e(t.action==="sync"?i.syncedBy:i.publishedBy),b=P(),{roles:_}=B(),E=window.firebase.user.email||"",m=C(_,E),d=t.action==="publish",r=!!i.archivedAt;async function M(){a(!0);let p=`data-source-${t.action}-${i.id}`;v({id:p,loading:!0,title:`Running Data Source ${t.action}`,message:`Updating ${i.id}...`,autoClose:!1,disallowClose:!0});try{t.action==="sync"?(i.type==="gsheet"&&!b.isLoggedIn()&&await b.login(),await w(i.id)):t.action==="publish"&&await A(i.id),N(D.now()),L(window.firebase.user.email),a(!1),t.onAction&&t.onAction(),S({id:p,title:"Success",message:`Updated Data Source ${i.id}`,autoClose:!1})}catch(n){console.error(n);let h=n;typeof n=="object"&&n.body&&(h=String(n.body)),a(!1),S({id:p,title:`Data Source ${t.action} failed`,message:String(h),color:"red",autoClose:!1})}}let f="";return t.action==="sync"?f="Sync data to a draft state":t.action==="publish"&&(f="Publish synced data to prod"),o("div",{className:"DataSourceStatusButton",children:[o("div",{className:"DataSourceStatusButton__label",children:!s&&o(x,{timestamp:u,email:I})}),o("div",{className:"DataSourceStatusButton__button",children:o($,{label:r?"Data source is archived":"You don't have access to publish this data source",condition:r||d&&!m,children:o(c,{transition:"pop",label:f,disabled:r||d&&!m,children:o(T,{variant:"default",size:"xs",compact:!0,onClick:()=>M(),loading:s,disabled:r||d&&!m,children:t.action})})})})]})}export{et as a};
@@ -1 +0,0 @@
1
- import{a as _t}from"./chunk-ENQKSLGJ.js";import{g as oe,h as Xe,i as ke,j as qe,k as Ke,l as Je,m as Qe,n as Ye,o as Ze,p as et,q as de,r as tt,s as Me,t as st,u as ce,y as _e,z as me}from"./chunk-AGFPVTBA.js";import{a as ct}from"./chunk-W5DOO6ID.js";import{a as dt}from"./chunk-NSOTG64N.js";import{b as M}from"./chunk-J5E457OI.js";import{a as b,b as je,c as Ge}from"./chunk-QHJOTXYB.js";import{b as He,d as ye}from"./chunk-KRNQ6L35.js";import{e as fe}from"./chunk-BUNR5EU3.js";import{$a as Fe,Ab as pe,Cc as it,Da as ie,Db as lt,Eb as he,Fa as Le,Fb as De,Ga as e,Pb as nt,Rc as O,Uc as rt,V as te,W as se,a as i,c as T,da as g,ea as L,g as Se,j as Ee,lb as ue,mc as ze,na as Pe,qa as k,ra as U,tb as Ne,ua as j,vb as ge,wb as ot,zb as at}from"./chunk-LROR6N3B.js";import{d as C}from"./chunk-KUCVLANF.js";import{g as Oe,h as re,k as D,l as G,m as Ce,n as H,o as Ve,p as We}from"./chunk-7SK47HHZ.js";Ee();Ee();function mt(t){let o=t.file||{},a=o.src||"",l=o.filename||a,r={"--asset-thumb-size":`${t.size}px`};if(a&&G(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("img",{src:Ie(o,t.size*2),alt:o.alt||"",loading:"lazy"})});if(a&&H(l))return e("div",{className:"AssetBrowser__thumb",style:r,children:e("video",{src:a,muted:!0,playsInline:!0,preload:"metadata"})});let _=D(l);return e("div",{className:"AssetBrowser__thumb",style:r,children:_&&_.length<=4?e("div",{className:"AssetBrowser__thumb__ext",children:_}):e(pe,{size:20,stroke:"1.5"})})}function Ie(t,o){let a=t?.src||"";return a.startsWith(Oe)&&o?`${a}=s${o}`:a}function ve(t){let o=t?.src||"";Ce(o)&&(o=o.split("=")[0]+"=s0"),navigator.clipboard.writeText(o).then(()=>{b({message:"Copied URL to clipboard.",autoClose:2e3})})}function we(t){let o=t?.src||"";if(o)if(Ce(o)){let a=document.createElement("a");a.href=We(o),t.filename&&(a.download=t.filename),document.body.appendChild(a),a.click(),document.body.removeChild(a)}else window.open(o,"_blank")}function ft(t){let[o,a]=i(t.asset),[l,r]=i(t.asset.file?.alt||""),[_,d]=i(!1),[x,v]=i(!1),[m,B]=i(null),[h,F]=i(null),n=o.file||{},f=n.filename||o.name,N=G(f),S=H(f),V=l!==(n.alt||""),W=n.altDisabled===!0;T(()=>{_e(o.id).then(c=>F(c)).catch(c=>{console.error("failed to fetch asset usage:",c),F([])})},[o.id]);async function z(c,w){let p=await me(c,{previousFile:w});p.failedDocIds.length>0?b({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&&b({message:`Updated ${p.updatedDocIds.length} doc(s) that use this asset.`,color:"green"})}async function X(){d(!0),await M(async()=>{let c={...n},w=await st(o,l);a(w),t.onChanged(w),await z(w,c)}),d(!1)}function R(){let c=document.createElement("input");c.type="file",c.onchange=()=>{let w=c.files?.[0];if(!w)return;let p=D(f),y=D(w.name);if(p&&y&&p!==y){B(w);return}E(w)},c.click(),c.remove()}async function E(c){B(null),d(!0),await M(async()=>{let w={...n},p=await re(c),y=await tt(o,p);a(y),r(y.file?.alt||""),t.onChanged(y),await z(y,w)}),d(!1)}async function $(c){d(!0),await M(async()=>{let w={...n},p=await ce(o,c);a(p),r(p.file?.alt||""),t.onChanged(p),await z(p,w)}),d(!1)}async function q(){d(!0),await M(async()=>{await de(o),b({message:`Deleted "${o.name}".`,color:"green"}),t.onDeleted()}),d(!1)}return e(U,{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:Ie(n,800),alt:n.alt||"",style:n.canvasBgColor==="dark"?{background:"#000"}:{}}):S?e("video",{src:n.src,controls:!0,muted:!0,preload:"metadata"}):e("div",{className:"AssetBrowser__details__preview__placeholder",children:[e(pe,{size:48,stroke:"1"}),e("div",{children:f})]})}),e(ie,{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:f})]}),!!(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:[ye(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:[ye(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(j,{readOnly:!0,value:n.src||"",size:"xs",radius:"xs",onClick:c=>c.target.select(),styles:{root:{flex:1,minWidth:0}}}),e(Le,{label:"Copy URL",transition:"pop",children:e(se,{size:"sm",onClick:()=>ve(n),children:e(ue,{size:16})})})]})})]})]})}),(N||S)&&e("div",{className:"AssetBrowser__details__alt",children:[W?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(Pe,{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||_,onChange:c=>r(c.currentTarget.value)}),t.canManage&&V&&e(g,{size:"xs",color:"dark",mt:8,loading:_,onClick:()=>X(),children:"Save alt text"})]}),t.canManage&&e(L,{className:"AssetBrowser__details__alt__disableCheckbox",label:"Disable alt text (e.g. decorative images)",size:"xs",mt:8,checked:W,disabled:_,onChange:c=>$(c.currentTarget.checked)})]}),e("div",{className:"AssetBrowser__details__usage",children:[e("div",{className:"AssetBrowser__details__usage__title",children:"Used in"}),h===null?e(te,{color:"gray",size:"sm"}):h.length===0?e("div",{className:"AssetBrowser__details__usage__empty",children:"No docs use this asset."}):e("div",{className:"AssetBrowser__details__usage__list",children:h.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(ot,{size:14})]},c.id))})]}),e("div",{className:"AssetBrowser__details__buttons",children:[e(g,{variant:"default",size:"xs",leftIcon:e(ge,{size:14}),onClick:()=>we(n),children:"Download"}),t.canManage&&e(C,{children:[e(g,{variant:"default",size:"xs",leftIcon:e(at,{size:14}),loading:_,onClick:()=>R(),children:"Replace file"}),e(g,{className:"AssetBrowser__details__buttons__delete",color:"red",variant:"filled",size:"xs",leftIcon:e(O,{size:14}),disabled:_,onClick:()=>v(!0),children:"Delete"})]})]}),m&&e("div",{className:"AssetBrowser__details__confirmReplace",children:[e("div",{children:["The new file has a different type (",e("b",{children:[".",D(f)]})," ","\u2192 ",e("b",{children:[".",D(m.name)]}),"). Replacing will change the asset's file extension and serving URL",Me(o.name,D(m.name))!==o.name&&e(C,{children:[", and the asset will be renamed to"," ",e("b",{children:Me(o.name,D(m.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:_,children:"Cancel"}),e(g,{color:"dark",size:"xs",loading:_,onClick:()=>E(m),children:"Replace"})]})]}),x&&e("div",{className:"AssetBrowser__details__confirmDelete",children:[e("div",{children:["Delete ",e("b",{children:o.name})," from the asset library?",h&&h.length>0&&e(C,{children:[" ","This asset is used in ",h.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:_,children:"Cancel"}),e(g,{color:"red",size:"xs",loading:_,onClick:()=>q(),children:"Delete"})]})]})]})})}function Te(t){let[o,a]=i(t.folder??t.initialFolder??""),l=t.folder??o,[r,_]=i([]),[d,x]=i(!0),[v,m]=i(""),[B,h]=i(!1),[F,n]=i(!1),[f,N]=i(null),[S,V]=i(!1),[W,z]=i(null),[X,R]=i(null),[E,$]=i(null),[q,c]=i(null),[w,p]=i(null),[y,K]=i(new Map),{roles:pt}=dt(),ht=window.firebase.user.email||"",J=ct(pt,ht),Q=v.trim().length>0;function P(s){a(s),m(""),t.onFolderChange&&t.onFolderChange(s)}async function I(s){x(!0),N(null),K(new Map),await M(async()=>{let u=await ke(s);_(u)}),x(!1)}T(()=>{I(l)},[l]),T(()=>{if(!Q||f!==null)return;let s=!1;return(async()=>{let u=[];await M(async()=>{u=await qe(l)}),s||N(u)})(),()=>{s=!0}},[Q,f,l]);let be=t.mode==="manage"?t.initialAssetId:"";T(()=>{be&&M(async()=>{let s=await Je(be);s&&s.type==="file"&&(P(s.parent),p(s))})},[be]);let Y=Se(()=>{let s=v.trim().toLowerCase(),u=s?f||[]:r;return t.mode==="pick"&&(u=u.filter(A=>A.type==="folder"||Ve(A.file?.filename||A.name,t.accept))),s&&(u=u.filter(A=>A.name.toLowerCase().includes(s))),u},[r,f,v,t.mode,t.accept]);async function Ue(s){if(s.length===0||F)return;let u="asset-browser-upload";n(!0),b({id:u,message:`Uploading ${s.length} file(s)...`,loading:!0,autoClose:!1,disallowClose:!0});let A=[],xe=[];for(let le=0;le<s.length;le++){let ne=s[le];je({id:u,message:`Uploading ${ne.name} (${le+1} of ${s.length})...`,loading:!0,autoClose:!1,disallowClose:!0});try{let Be=await re(ne),At=await Ye({parent:l,file:Be});A.push(At)}catch(Be){console.error(`failed to upload ${ne.name}:`,Be),xe.push(ne.name)}}Ge(u),n(!1),xe.length>0?b({title:"Upload failed",message:`Failed to upload: ${xe.join(", ")}`,color:"red",autoClose:!1}):b({message:`Uploaded ${A.length} file(s).`,color:"green"}),await I(l),t.mode==="pick"&&A.length===1&&s.length===1&&t.onPickFile&&t.onPickFile(A[0])}function vt(){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=()=>{Ue(Array.from(s.files||[]))},s.click(),s.remove()}function wt(s){t.onPickFile&&t.onPickFile(s)}let Z=J,ae=t.mode==="manage"&&J,ee=Array.from(y.values()),Re=ee.filter(s=>s.type==="file"&&!s.file?.altDisabled&&(G(s.file?.filename||s.name)||H(s.file?.filename||s.name))),Ae=Y.length>0&&Y.every(s=>y.has(s.id));function $e(s){K(u=>{let A=new Map(u);return A.has(s.id)?A.delete(s.id):A.set(s.id,s),A})}function bt(){K(Ae?new Map:new Map(Y.map(s=>[s.id,s])))}return e("div",{className:fe("AssetBrowser",t.className,`AssetBrowser--${t.mode}`),children:[e("div",{className:"AssetBrowser__toolbar",children:[e(Te.Breadcrumbs,{folder:l,onNavigate:P}),e("div",{className:"AssetBrowser__toolbar__actions",children:[e(j,{className:"AssetBrowser__toolbar__filter",placeholder:"Search by name",size:"xs",icon:e(it,{size:14}),value:v,onChange:s=>m(s.currentTarget.value)}),Z&&t.mode==="manage"&&e(g,{variant:"default",size:"xs",leftIcon:e(lt,{size:16}),onClick:()=>V(!0),children:"New folder"}),Z&&e(g,{color:"dark",size:"xs",leftIcon:e(rt,{size:16}),loading:F,onClick:()=>vt(),children:"Upload"})]})]}),ae&&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(he,{size:14}),onClick:()=>R(ee),children:"Move"}),Re.length>0&&e(g,{variant:"default",size:"xs",onClick:()=>c(Re),children:"Disable alt text"}),e(g,{color:"red",size:"xs",leftIcon:e(O,{size:14}),onClick:()=>$(ee),children:"Delete"}),e(g,{variant:"subtle",color:"gray",size:"xs",onClick:()=>K(new Map),children:"Clear"})]})]}),e("div",{className:fe("AssetBrowser__listing",B&&"dragging"),onDragOver:s=>{Z&&(s.preventDefault(),h(!0))},onDragLeave:s=>{s.preventDefault(),h(!1)},onDrop:s=>{s.preventDefault(),h(!1),Z&&Ue(Array.from(s.dataTransfer?.files||[]))},children:d||Q&&f===null?e("div",{className:"AssetBrowser__loading",children:e(te,{color:"gray",size:"lg"})}):Y.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."}),Z&&e("div",{className:"AssetBrowser__empty__hint",children:'Drop files here or click "Upload" to add assets.'})]})}):e(ie,{className:"AssetBrowser__table",verticalSpacing:"xs",fontSize:"xs",highlightOnHover:!0,children:[e("thead",{children:e("tr",{children:[ae&&e("th",{className:"AssetBrowser__table__checkboxCol",children:e(L,{size:"xs","aria-label":"Select all",checked:Ae,indeterminate:!Ae&&y.size>0,onChange:()=>bt()})}),e("th",{children:"name"}),e("th",{className:"AssetBrowser__table__modifiedCol",children:"modified"}),e("th",{className:"AssetBrowser__table__actionsCol"})]})}),e("tbody",{children:Y.map(s=>s.type==="folder"?e("tr",{className:"AssetBrowser__row AssetBrowser__row--folder",onClick:()=>P(oe(s.parent,s.name)),children:[ae&&e("td",{className:"AssetBrowser__checkboxCell",onClick:u=>u.stopPropagation(),children:e(L,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>$e(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e("div",{className:"AssetBrowser__thumb",children:e(De,{size:24,stroke:"1.5"})}),e("div",{className:"AssetBrowser__nameCell__text",children:[e("div",{className:"AssetBrowser__nameCell__name",children:s.name}),e(ut,{asset:s,folder:l,searching:Q,onNavigate:P})]})]})}),e("td",{children:e(gt,{asset:s})}),e("td",{onClick:u=>u.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(Ne,{size:16})}),children:[e(k.Item,{icon:e(ze,{size:14}),onClick:()=>z(s),children:"Rename"}),e(k.Item,{icon:e(he,{size:14}),onClick:()=>R([s]),children:"Move"}),e(k.Item,{color:"red",icon:e(O,{size:14}),onClick:()=>$([s]),children:"Delete"})]})})})]},s.id):e("tr",{className:"AssetBrowser__row AssetBrowser__row--file",onClick:()=>{t.mode==="pick"?wt(s):p(s)},children:[ae&&e("td",{className:"AssetBrowser__checkboxCell",onClick:u=>u.stopPropagation(),children:e(L,{size:"xs","aria-label":`Select ${s.name}`,checked:y.has(s.id),onChange:()=>$e(s)})}),e("td",{children:e("div",{className:"AssetBrowser__nameCell",children:[e(mt,{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(ut,{asset:s,folder:l,searching:Q,onNavigate:P})]})]})}),e("td",{children:e(gt,{asset:s})}),e("td",{onClick:u=>u.stopPropagation(),children:e("div",{className:"AssetBrowser__actionsCell",children:t.mode!=="pick"&&e(xt,{asset:s,canManage:J,onDetails:()=>p(s),onRename:()=>z(s),onMove:()=>R([s]),onDelete:()=>$([s])})})})]},s.id))})]})}),e(Bt,{opened:S,parent:l,onClose:()=>V(!1),onCreated:s=>{V(!1),P(oe(l,s))}}),W&&e(yt,{asset:W,onClose:()=>z(null),onRenamed:()=>{z(null),I(l)}}),X&&X.length>0&&e(Ct,{assets:X,onClose:()=>R(null),onMoved:()=>{R(null),I(l)}}),E&&E.length>0&&e(Mt,{assets:E,onClose:()=>$(null),onDeleted:()=>{$(null),I(l)}}),q&&q.length>0&&e(Ft,{assets:q,onClose:()=>c(null),onDone:()=>{c(null),I(l)}}),w&&e(ft,{asset:w,canManage:J,onClose:()=>p(null),onChanged:()=>I(l),onDeleted:()=>{p(null),I(l)}})]})}Te.Breadcrumbs=t=>{let o=Xe(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(Fe,{className:"AssetBrowser__breadcrumbs__divider",size:14}),e("button",{className:fe("AssetBrowser__breadcrumbs__link",r===a.length-1&&"active"),disabled:r===a.length-1,onClick:()=>t.onNavigate(l.path),children:l.label})]},l.path))})};function xt(t){let o=t.asset;return e(k,{shadow:"sm",position:"bottom",placement:"end",control:e(se,{size:"sm",children:e(Ne,{size:16})}),children:[e(k.Item,{icon:e(nt,{size:14}),onClick:t.onDetails,children:"Details"}),e(k.Item,{icon:e(ue,{size:14}),onClick:()=>ve(o.file),children:"Copy URL"}),e(k.Item,{icon:e(ge,{size:14}),onClick:()=>we(o.file),children:"Download"}),t.canManage&&e(C,{children:[e(k.Item,{icon:e(ze,{size:14}),onClick:t.onRename,children:"Rename"}),e(k.Item,{icon:e(he,{size:14}),onClick:t.onMove,children:"Move"}),e(k.Item,{color:"red",icon:e(O,{size:14}),onClick:t.onDelete,children:"Delete"})]})]})}function ut(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 ",Ke(o.parent,t.folder)]})}function gt(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(_t,{email:a,size:20}),e("span",{children:l?He(l):"\u2014"})]})}function Bt(t){let[o,a]=i(""),[l,r]=i(!1);async function _(){r(!0),await M(async()=>{let d=await Qe(t.parent,o);a(""),t.onCreated(d.name)}),r(!1)}return e(U,{opened:t.opened,onClose:t.onClose,title:"New folder",size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),_()},children:[e(j,{"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 yt(t){let[o,a]=i(t.asset.name),[l,r]=i(!1);async function _(){r(!0),await M(async()=>{await Ze(t.asset,o),t.onRenamed()}),r(!1)}return e(U,{opened:!0,onClose:t.onClose,title:`Rename ${t.asset.type}`,size:"sm",centered:!0,children:e("form",{className:"AssetBrowser__modalForm",onSubmit:d=>{d.preventDefault(),_()},children:[e(j,{"data-autofocus":!0,value:o,onChange:d=>a(d.currentTarget.value)}),e(g,{type:"submit",color:"dark",loading:l,disabled:!o,children:"Rename"})]})})}function Ct(t){let o=t.assets,[a,l]=i(o[0]?.parent||""),[r,_]=i([]),[d,x]=i(!0),[v,m]=i(!1);T(()=>{x(!0),M(async()=>{let n=await ke(a);_(n.filter(f=>f.type==="folder"))}).then(()=>x(!1))},[a]);let B=o.filter(n=>n.type==="folder").map(n=>oe(n.parent,n.name));function h(n){return B.some(f=>n===f||n.startsWith(`${f}/`))}async function F(){m(!0);let n=[],f=0;for(let N of o)try{await et(N,a),f+=1}catch(S){console.error(`failed to move ${N.name}:`,S),n.push(N.name)}m(!1),n.length>0&&b({title:"Move failed",message:`Failed to move: ${n.join(", ")}`,color:"red",autoClose:!1}),f>0&&b({message:o.length===1?`Moved "${o[0].name}" to ${a||"Assets"}.`:`Moved ${f} item(s) to ${a||"Assets"}.`,color:"green"}),t.onMoved()}return e(U,{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(Te.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 f=oe(n.parent,n.name);return e("button",{className:"AssetBrowser__moveModal__folder",disabled:h(f),onClick:()=>l(f),children:[e(De,{size:16,stroke:"1.5"}),e("span",{children:n.name}),e(Fe,{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 kt=20;function Mt(t){let o=t.assets,[a,l]=i(!1),[r,_]=i(null),d=o.filter(m=>m.type==="file"),x=o.some(m=>m.type==="folder");T(()=>{d.length===0||d.length>kt||Promise.all(d.map(m=>_e(m.id))).then(m=>{let B=new Set(m.flat().map(h=>h.id));_(B.size)}).catch(()=>_(null))},[o.map(m=>m.id).join(",")]);async function v(){l(!0);let m=[],B=0;for(let h of o)try{await de(h),B+=1}catch(F){console.error(`failed to delete ${h.name}:`,F),m.push(h.name)}l(!1),m.length>0&&b({title:"Delete failed",message:`Failed to delete: ${m.join(", ")}. Note that folders must be empty before they can be deleted.`,color:"red",autoClose:!1}),B>0&&b({message:o.length===1?`Deleted "${o[0].name}".`:`Deleted ${B} item(s).`,color:"green"}),t.onDeleted()}return e(U,{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 Ft(t){let o=t.assets,[a,l]=i(!1);async function r(){l(!0);let _=[],d=0;for(let x of o)try{let v=x.file,m=await ce(x,!0);await me(m,{previousFile:v}),d+=1}catch(v){console.error(`failed to disable alt text for ${x.name}:`,v),_.push(x.name)}l(!1),_.length>0&&b({title:"Failed to disable alt text",message:`Failed to update: ${_.join(", ")}`,color:"red",autoClose:!1}),d>0&&b({message:`Disabled alt text for ${d} file(s).`,color:"green"}),t.onDone()}return e(U,{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{Te as a};
@@ -1,3 +0,0 @@
1
- import{a as y,f as L}from"./chunk-KRNQ6L35.js";import{b as R,c as l,g as d,h as C,n as m,o as x,q as _,w as T,x as p}from"./chunk-VD6G5NV4.js";function f(n,o){let t=n.translationLanguages||{},a=String(o).toLowerCase();for(let[e,s]of Object.entries(t))if(e.toLowerCase()===a)return s;return o}function b(n,o){let t=[];for(let a of o){let e=f(n,a);t.includes(e)||t.push(e)}return t}function w(n,o){let t=n.locales||["en"],a=String(o).toLowerCase(),e=[];for(let s of t)(String(s).toLowerCase()===a||f(n,s).toLowerCase()===a)&&e.push(s);return e}function O(n,o,t){for(let a of w(n,t)){let e=o[a];if(typeof e=="string"&&e)return e}return""}function A(){let n=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db;return R(o,"Projects",n,"Translations")}async function B(n){let o=A(),t=n?.tags?d(o,C("tags","array-contains-any",n.tags)):d(o),a=await x(t),e={};return a.forEach(s=>{let r=s.id;e[r]=s.data()}),e}async function D(n){let o=window.__ROOT_CTX.rootConfig.projectId,t=window.firebase.db,a=l(t,"Projects",o,"Translations",n);return(await m(a)).data()}async function G(n,o){let t=window.__ROOT_CTX.rootConfig.projectId,a=window.firebase.db,e=l(a,"Projects",t,"Translations",n),s={};for(let r in o){if(r==="tags"){s.tags=o.tags;continue}for(let i of S(r))s[i]=o[r]}console.log("updating translations: ",s),await _(e,s),L("translations.save",{metadata:{hash:n},throttle:5*y.minute,throttleId:n})}async function N(n,o){let t=o?.mode??"replace",a=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=500;for(let r=0;r<n.length;r+=s){let i=p(e);n.slice(r,r+s).forEach(({hash:g,tags:u})=>{let c=l(e,"Projects",a,"Translations",g);t==="union"?i.update(c,{tags:T(...u)}):i.update(c,{tags:u})}),await i.commit()}}async function P(n){return k(I(n))}async function k(n){let t=new TextEncoder().encode(n),a=await crypto.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(a)).map(r=>r.toString(16).padStart(2,"0")).join("")}function I(n){return String(n).trim().split(`
2
- `).map(t=>v(t)).join(`
3
- `)}function v(n){return String(n).trimEnd().replace(/&nbsp;$/,"")}var j=new Map;function M(n){let o=j.get(n);if(o)return o;let t=n.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),a=new RegExp(`^${t}$`,"i");return j.set(n,a),a}function W(n){return(window.__ROOT_CTX.excludeLocalesFromTranslations||[]).some(t=>M(t).test(n))}function J(n){let t=(window.__ROOT_CTX.rootConfig.i18n||{}).locales||["en"];for(let a of t)if(String(a).toLowerCase()===n.toLowerCase())return a;return null}function K(n){let o=window.__ROOT_CTX.rootConfig.i18n||{};return f(o,n)}function Q(n){let o=window.__ROOT_CTX.rootConfig.i18n||{};return b(o,n)}function S(n){let o=window.__ROOT_CTX.rootConfig.i18n||{};return w(o,n)}function V(n,o){let t=window.__ROOT_CTX.rootConfig.i18n||{};return O(t,n,o)}async function Y(n,o){let t=window.__ROOT_CTX.rootConfig.projectId,a=window.firebase.db,e=500,s=await Promise.all(n.map(async r=>({hash:await P(r.source),locales:r.locales,source:r.source})));for(let r=0;r<s.length;r+=e){let i=p(a),h=s.slice(r,r+e);for(let g of h){let u=l(a,"Projects",t,"Translations",g.hash),c={source:g.source};for(let[E,X]of Object.entries(g.locales))for(let F of S(E))c[F]=I(X);o?.tags?.length&&(c.tags=T(...o.tags)),i.set(u,c,{merge:!0})}await i.commit()}L("translations.batch_save",{metadata:{count:n.length}})}export{A as a,B as b,D as c,G as d,N as e,P as f,I as g,W as h,J as i,K as j,Q as k,S as l,V as m,Y as n};