headroom-cms 0.1.10 → 0.2.0

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 (154) hide show
  1. package/README.md +11 -6
  2. package/admin/.well-known/headroom.json +9 -0
  3. package/admin/assets/{AdminsPage-BIWASote.js → AdminsPage-DUMTsCEp.js} +1 -1
  4. package/admin/assets/{AllContentPage-1gXe2OC7.js → AllContentPage-D5ey5AOV.js} +1 -1
  5. package/admin/assets/{ApiKeysPage-BBW4ATBx.js → ApiKeysPage-CzUOSoz_.js} +1 -1
  6. package/admin/assets/{AuditPage-B5GGFWGG.js → AuditPage-CYAg4dbI.js} +1 -1
  7. package/admin/assets/BackupsPage-04_oMy3v.js +1 -0
  8. package/admin/assets/{BlockEditor-ClskiZoX.js → BlockEditor-s0CRZsjy.js} +3 -3
  9. package/admin/assets/BlockTypeEditPage-D1OFIlJZ.js +1 -0
  10. package/admin/assets/{BlockTypesPage-D8Me6OeX.js → BlockTypesPage-cJNR25fN.js} +1 -1
  11. package/admin/assets/{BulkActionBar--35xjnOP.js → BulkActionBar-BWysX7Wo.js} +1 -1
  12. package/admin/assets/CollectionEditPage-DRmCA_73.js +1 -0
  13. package/admin/assets/{CollectionsPage-BQmGXpvW.js → CollectionsPage-CeQB5e9u.js} +1 -1
  14. package/admin/assets/{ContentCreatePage-DlgxamOe.js → ContentCreatePage-Cq8Pi8EF.js} +1 -1
  15. package/admin/assets/ContentEditPage-CEJ7I3WH.js +1 -0
  16. package/admin/assets/{ContentField-D04Uo1Ov.js → ContentField-BZT4OUfI.js} +1 -1
  17. package/admin/assets/ContentListPage-BCEQrYVs.js +1 -0
  18. package/admin/assets/{CustomBlockPreview-Cs9bFDh4.js → CustomBlockPreview-Kc6bb3oq.js} +1 -1
  19. package/admin/assets/FieldRenderer-CT-DgCbC.js +2 -0
  20. package/admin/assets/FileTypeIcon-CNHtffHC.js +1 -0
  21. package/admin/assets/FloatingComposerController-D4uLQfUX-0_Y8mkGU.js +1 -0
  22. package/admin/assets/IconPicker-BpPlHJO0.js +3 -0
  23. package/admin/assets/{LoginPage-Bi7TBzK4.js → LoginPage-Dya8sF_P.js} +1 -1
  24. package/admin/assets/MediaField-C3qFf3g5.js +1 -0
  25. package/admin/assets/MediaPage-BNxc0wLq.js +1 -0
  26. package/admin/assets/{Pagination-CuHwUPHi.js → Pagination-Dx8h11Rn.js} +1 -1
  27. package/admin/assets/{RelationshipPicker-Dv7GaLcU.js → RelationshipPicker-C2MTxrhl.js} +1 -1
  28. package/admin/assets/{SiteSettingsPage-nBT7NzkA.js → SiteSettingsPage-BDZaUBmf.js} +1 -1
  29. package/admin/assets/{SiteUserEditPage-DroUTii9.js → SiteUserEditPage-MfzhPW7v.js} +1 -1
  30. package/admin/assets/{SiteUsersPage-iVXPCBPe.js → SiteUsersPage-CrYugXpx.js} +1 -1
  31. package/admin/assets/{SitesPage-BefZeWuJ.js → SitesPage-Cl8V3Hb7.js} +1 -1
  32. package/admin/assets/SubmissionDetailPage-BnVlsGb-.js +1 -0
  33. package/admin/assets/SubmissionEditPage-B0Kq52fb.js +1 -0
  34. package/admin/assets/SubmissionListPage-K665VwMp.js +1 -0
  35. package/admin/assets/{TagInput-d-Hw1fkL.js → TagInput-C6tcB5Xw.js} +1 -1
  36. package/admin/assets/{TagsPage-BZzDvcKa.js → TagsPage-BONR6bSu.js} +1 -1
  37. package/admin/assets/{UsersPage-CnQAOOGF.js → UsersPage-C2iCy0UR.js} +1 -1
  38. package/admin/assets/{WebhookEditPage-KeS8hmdW.js → WebhookEditPage-DjZFxT72.js} +1 -1
  39. package/admin/assets/{WebhooksPage-CASjmlPN.js → WebhooksPage-g_a224a4.js} +1 -1
  40. package/admin/assets/{card-CZTHR2Qa.js → card-DlfsF8lU.js} +1 -1
  41. package/admin/assets/{checkbox-DEgzM8H9.js → checkbox-BX8EcGFf.js} +1 -1
  42. package/admin/assets/{command-CdzYw11U.js → command-DaTsImUa.js} +1 -1
  43. package/admin/assets/{contentStatus-CkPi9Dh6.js → contentStatus-WXGfd7vX.js} +1 -1
  44. package/admin/assets/format-BRcflvs9.js +1 -0
  45. package/admin/assets/index-9sbb3-yI.css +1 -0
  46. package/admin/assets/{index-BA3y7HJs.js → index-DC1UyCW2.js} +10 -10
  47. package/admin/assets/listCellValue-CBqXAwce.js +1 -0
  48. package/admin/assets/media-url-DdCoIedP.js +1 -0
  49. package/admin/assets/{popover-BFw_h3j6.js → popover-BA-47SRI.js} +1 -1
  50. package/admin/assets/{select-dX9e6VDt.js → select-waaVyoQ5.js} +1 -1
  51. package/admin/assets/serializeToText-CjHhyvXp.js +2 -0
  52. package/admin/assets/{table-Dk7eeOt2.js → table-Br-QgtTL.js} +1 -1
  53. package/admin/assets/{textarea-CpDSUg2s.js → textarea-BILv1DQB.js} +1 -1
  54. package/admin/assets/useAdminResolver-CbDzGoDp.js +1 -0
  55. package/admin/assets/useContent-Bp4f9qe0.js +1 -0
  56. package/admin/assets/{useContentSearch-_bwacEth.js → useContentSearch-DbiA8aG-.js} +1 -1
  57. package/admin/assets/{usePageTitle-DYvuJQp6.js → usePageTitle-DOEFrHbj.js} +1 -1
  58. package/admin/assets/{useSiteUsers-CKtC_8Jc.js → useSiteUsers-BFYAbJNT.js} +1 -1
  59. package/admin/assets/{useTags-ybsMbCst.js → useTags-DJlXwDyc.js} +1 -1
  60. package/admin/assets/{useWebhooks-BAB-3sLa.js → useWebhooks-BkpJKNLN.js} +1 -1
  61. package/admin/favicon-16x16.png +0 -0
  62. package/admin/favicon-32x32.png +0 -0
  63. package/admin/icons/icon-180x180.png +0 -0
  64. package/admin/icons/icon-192x192.png +0 -0
  65. package/admin/icons/icon-512x512.png +0 -0
  66. package/admin/icons/maskable-icon-512x512.png +0 -0
  67. package/admin/index.html +2 -2
  68. package/admin/sw.js +1 -1
  69. package/admin/workbox-362996ec.js +1 -0
  70. package/dist/admin-site.d.ts +4 -2
  71. package/dist/admin-site.d.ts.map +1 -1
  72. package/dist/admin-site.js +49 -6
  73. package/dist/admin-site.js.map +1 -1
  74. package/dist/api.d.ts +2 -0
  75. package/dist/api.d.ts.map +1 -1
  76. package/dist/api.js +57 -5
  77. package/dist/api.js.map +1 -1
  78. package/dist/backup.d.ts +29 -0
  79. package/dist/backup.d.ts.map +1 -0
  80. package/dist/backup.js +95 -0
  81. package/dist/backup.js.map +1 -0
  82. package/dist/cdn-api.d.ts +25 -0
  83. package/dist/cdn-api.d.ts.map +1 -0
  84. package/dist/{cdn.js → cdn-api.js} +27 -158
  85. package/dist/cdn-api.js.map +1 -0
  86. package/dist/cdn-media.d.ts +26 -0
  87. package/dist/cdn-media.d.ts.map +1 -0
  88. package/dist/cdn-media.js +202 -0
  89. package/dist/cdn-media.js.map +1 -0
  90. package/dist/image.d.ts +8 -1
  91. package/dist/image.d.ts.map +1 -1
  92. package/dist/image.js +26 -6
  93. package/dist/image.js.map +1 -1
  94. package/dist/index.d.ts +18 -3
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +52 -10
  97. package/dist/index.js.map +1 -1
  98. package/dist/storage.d.ts +1 -0
  99. package/dist/storage.d.ts.map +1 -1
  100. package/dist/storage.js +21 -0
  101. package/dist/storage.js.map +1 -1
  102. package/dist/webhooks.d.ts +4 -3
  103. package/dist/webhooks.d.ts.map +1 -1
  104. package/dist/webhooks.js +22 -35
  105. package/dist/webhooks.js.map +1 -1
  106. package/lambda/api/bootstrap +0 -0
  107. package/lambda/backup-worker/bootstrap +0 -0
  108. package/lambda/image-lambda/index.mjs +30 -6
  109. package/lambda/image-lambda/node_modules/.package-lock.json +3 -3
  110. package/lambda/image-lambda/node_modules/semver/README.md +19 -4
  111. package/lambda/image-lambda/node_modules/semver/bin/semver.js +14 -10
  112. package/lambda/image-lambda/node_modules/semver/classes/range.js +7 -0
  113. package/lambda/image-lambda/node_modules/semver/functions/truncate.js +48 -0
  114. package/lambda/image-lambda/node_modules/semver/index.js +2 -0
  115. package/lambda/image-lambda/node_modules/semver/internal/re.js +1 -1
  116. package/lambda/image-lambda/node_modules/semver/package.json +3 -3
  117. package/lambda/image-lambda/node_modules/semver/range.bnf +5 -4
  118. package/lambda/image-lambda/node_modules/semver/ranges/subset.js +2 -2
  119. package/lambda/webhook-worker/bootstrap +0 -0
  120. package/package.json +1 -1
  121. package/src/admin-site.ts +53 -8
  122. package/src/api.ts +58 -5
  123. package/src/backup.ts +114 -0
  124. package/src/{cdn.ts → cdn-api.ts} +28 -183
  125. package/src/cdn-media.ts +250 -0
  126. package/src/image.ts +30 -6
  127. package/src/index.ts +71 -12
  128. package/src/sst-env.d.ts +4 -0
  129. package/src/storage.ts +22 -0
  130. package/src/webhooks.ts +22 -39
  131. package/admin/assets/BlockTypeEditPage-CY0gCPei.js +0 -1
  132. package/admin/assets/CollectionEditPage-y8t0ZO89.js +0 -1
  133. package/admin/assets/ContentEditPage-WkSbCnnG.js +0 -1
  134. package/admin/assets/ContentListPage-BDMx7pWb.js +0 -1
  135. package/admin/assets/FieldRenderer-wE-mtqZB.js +0 -2
  136. package/admin/assets/FilterBar-kFcOLffg.js +0 -1
  137. package/admin/assets/FloatingComposerController-D4uLQfUX-C0Lhbmda.js +0 -1
  138. package/admin/assets/IconPicker-BrgSAsa_.js +0 -3
  139. package/admin/assets/MediaField-B-Cz8TlK.js +0 -1
  140. package/admin/assets/MediaPage-C84p9d1U.js +0 -1
  141. package/admin/assets/SubmissionDetailPage-ktmzzOE1.js +0 -1
  142. package/admin/assets/SubmissionEditPage-C-ykTI2t.js +0 -1
  143. package/admin/assets/SubmissionListPage-DA-8deUy.js +0 -1
  144. package/admin/assets/format-C88SDH8g.js +0 -1
  145. package/admin/assets/index-c7UygSvP.css +0 -1
  146. package/admin/assets/media-url-DIg_vSyf.js +0 -1
  147. package/admin/assets/serializeToText-Zin3gYPm.js +0 -2
  148. package/admin/assets/useAdminResolver-Bljb4XGQ.js +0 -1
  149. package/admin/assets/useContent-CW0tm0FY.js +0 -1
  150. package/admin/assets/useMedia-Cu5N4rY8.js +0 -1
  151. package/admin/workbox-7d58179f.js +0 -1
  152. package/dist/cdn.d.ts +0 -27
  153. package/dist/cdn.d.ts.map +0 -1
  154. package/dist/cdn.js.map +0 -1
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as R,f as U,r as o}from"./react-vendor-C2CvUxFh.js";import{W as b,aF as V,S as T,aG as G,aH as W,aI as z,x as J,L as u,I as K,a0 as B,B as x,a as Q,D as X,i as Y,T as Z,k as ee,l as se,m as te,n as ae,o as ie,v as h}from"./index-BA3y7HJs.js";import{I as ne,a as re,F as le}from"./IconPicker-BrgSAsa_.js";import{i as oe}from"./format-C88SDH8g.js";import{T as ce}from"./textarea-CpDSUg2s.js";import{C as de,a as me,b as pe,c as ue}from"./card-CZTHR2Qa.js";import{C as $,a as D,b as F}from"./collapsible-D3d29uJp.js";import{C as xe}from"./CustomBlockPreview-Cs9bFDh4.js";import{F as he}from"./FieldRenderer-wE-mtqZB.js";import{u as N}from"./useContentSearch-_bwacEth.js";import{u as je}from"./usePageTitle-DYvuJQp6.js";import"./radix-C5ZmWuuL.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./select-dX9e6VDt.js";import"./checkbox-DEgzM8H9.js";import"./popover-BFw_h3j6.js";import"./media-url-DIg_vSyf.js";import"./MediaField-B-Cz8TlK.js";import"./useMedia-Cu5N4rY8.js";import"./ContentField-D04Uo1Ov.js";import"./command-CdzYw11U.js";function fe({fields:a,previewTemplate:s,previewData:t,onPreviewDataChange:i,blockTypeName:l,blockTypeLabel:d,blockTypeIcon:v}){const n=N(s,300),g=N(t,300);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{fields:a,values:t,onChange:i}),e.jsx(b,{}),e.jsx("div",{className:"overflow-hidden rounded-md border p-4",children:e.jsx(xe,{blockType:{name:l,label:d,icon:v,fields:a,previewTemplate:n},props:g,blocksToHTML:()=>""})})]})}function Ue(){const{host:a,name:s}=R(),t=s==="new",{data:i,isLoading:l}=V(a,t?"":s);return!t&&l?e.jsxs("div",{className:"space-y-4",children:[e.jsx(T,{className:"h-8 w-64"}),e.jsx(T,{className:"h-64 w-full"})]}):t?e.jsx(C,{host:a,isNew:!0}):i?e.jsx(C,{host:a,isNew:!1,blockType:i},i.name):e.jsx("p",{className:"text-muted-foreground",children:"Block type not found."})}function C({host:a,isNew:s,blockType:t}){const i=U(),l=G(a),d=W(a,t?.name??""),v=z(a,t?.name??""),[n,g]=o.useState(t?.name??""),[j,y]=o.useState(t?.label??""),[f,P]=o.useState(t?.icon??""),[S,L]=o.useState(!s),I=new Set((t?.fields??[]).map(r=>r.name).filter(Boolean)),[c,E]=o.useState(t?.fields??[]),[m,O]=o.useState(t?.previewTemplate??""),[p,q]=o.useState(t?.previewData??{}),[H,w]=o.useState(!1),_=J();je({title:s?"New Block Type":t?.label??n,showBack:!0,backTo:`/sites/${a}/settings/block-types`});async function A(r){r.preventDefault();try{s?(await l.mutateAsync({name:n,label:j,icon:f,fields:c,previewTemplate:m||void 0,previewData:Object.keys(p).length>0?p:void 0}),h.success("Block type created"),i(`/sites/${a}/settings/block-types/${n}`)):(await d.mutateAsync({label:j,icon:f,fields:c,previewTemplate:m||void 0,previewData:Object.keys(p).length>0?p:void 0}),h.success("Block type updated"))}catch(k){h.error(s?"Failed to create":"Failed to update",{description:k instanceof Error?k.message:void 0})}}async function M(){try{await v.mutateAsync(),h.success("Block type deleted"),i(`/sites/${a}/settings/block-types`)}catch(r){h.error("Failed to delete",{description:r instanceof Error?r.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!_&&e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:s?"New Block Type":`Edit: ${t?.label??n}`}),e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(pe,{children:"Block Type Settings"})}),e.jsx(ue,{children:e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"name",children:"Name"}),e.jsx(ne,{id:"name",value:n,onChange:g,onBlur:()=>{n&&!S&&y(oe(n))},readOnly:!s,placeholder:"e.g. hero_banner",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"label",children:"Label"}),e.jsx(K,{id:"label",value:j,onChange:r=>{y(r.target.value),L(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Icon"}),e.jsx(re,{value:f,onChange:P})]}),e.jsx(b,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Block Fields"}),e.jsx(le,{fields:c,onChange:E,existingFieldNames:I})]}),e.jsx(b,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"preview-template",children:"Preview Template (Liquid + Tailwind)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Use Liquid syntax to render a preview. Tailwind utility classes are supported."}),e.jsx(ce,{id:"preview-template",value:m,onChange:r=>O(r.target.value),rows:6,placeholder:'<div class="p-4">{{ title }}</div>',className:"font-mono text-sm"}),c.length>0&&e.jsx(ge,{fields:c})]}),(m||c.length>0)&&e.jsxs($,{children:[e.jsxs(D,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(B,{className:"h-4 w-4 transition-transform [[data-state=open]>&]:rotate-90"}),"Preview"]}),e.jsx(F,{className:"mt-2",children:e.jsx(fe,{fields:c,previewTemplate:m,previewData:p,onPreviewDataChange:q,blockTypeName:n,blockTypeLabel:j,blockTypeIcon:f})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{type:"submit",disabled:l.isPending||d.isPending,children:[(l.isPending||d.isPending)&&e.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),s?"Create":"Save"]}),e.jsx(x,{type:"button",variant:"outline",onClick:()=>i(`/sites/${a}/settings/block-types`),children:"Cancel"})]})]})})]}),!s&&e.jsx("div",{className:"mt-6",children:e.jsxs(X,{open:H,onOpenChange:w,children:[e.jsx(Y,{asChild:!0,children:e.jsxs(x,{variant:"destructive",children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),"Delete Block Type"]})}),e.jsxs(ee,{children:[e.jsxs(se,{children:[e.jsx(te,{children:"Delete block type?"}),e.jsx(ae,{children:"This will permanently delete this block type."})]}),e.jsxs(ie,{children:[e.jsx(x,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),e.jsx(x,{variant:"destructive",onClick:M,children:"Delete"})]})]})]})})]})}function ve(a){const s=a.name;switch(a.type){case"media":return`{{ ${s}.url | media_url }} {{ ${s}.alt }} {{ ${s}.width }}`;case"content":return`{{ ${s}.title }} {{ ${s}.id }}`;case"boolean":return`{% if ${s} %}...{% endif %}`;case"array":{const t=a.options?.itemFields;if(t&&t.length>0){const i=t.map(l=>`item.${l.name}`).join(" }} {{ ");return`{% for item in ${s} %}{{ ${i} }}{% endfor %}`}return`{% for item in ${s} %}{{ item }}{% endfor %}`}case"select":return a.options?.multiple?`{% for item in ${s} %}{{ item }}{% endfor %}`:`{{ ${s} }}`;case"container":{const t=a.options?.fields;return t&&t.length>0?t.map(i=>`{{ ${s}.${i.name} }}`).join(" "):`{{ ${s}.fieldName }}`}case"blocks":return`{{ ${s} | blocks_html }} or {{ ${s} | blocks_text }}`;default:return`{{ ${s} }}`}}function ge({fields:a}){return e.jsxs($,{children:[e.jsxs(D,{className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:[e.jsx(B,{className:"h-3 w-3 transition-transform [[data-state=open]>&]:rotate-90"}),"Template variables"]}),e.jsx(F,{children:e.jsx("div",{className:"mt-1 rounded-md border bg-muted/50 p-2 font-mono text-xs space-y-0.5",children:a.map(s=>e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("span",{className:"text-muted-foreground shrink-0",children:[s.label,":"]}),e.jsx("code",{children:ve(s)})]},s.name))})})]})}export{Ue as BlockTypeEditPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r,u as je,f as be}from"./react-vendor-C2CvUxFh.js";import{ai as pe,a0 as fe,y as ve,ax as Ce,B as N,T as K,I as L,P as Se,ay as Ne,S as U,x as ye,w as ke,az as De,aA as Ee,aB as Pe,L as m,aC as Ie,W as z,a as Fe,D as Le,i as Re,k as Te,l as Ae,m as Be,n as we,o as Oe,v as P}from"./index-BA3y7HJs.js";import{I as Q,F as qe,a as $e}from"./IconPicker-BrgSAsa_.js";import{i as Z,c as Me}from"./format-C88SDH8g.js";import{C as O}from"./checkbox-DEgzM8H9.js";import{C as W,a as Y,b as G,c as X}from"./card-CZTHR2Qa.js";import{u as _e}from"./usePageTitle-DYvuJQp6.js";import{S as q,a as $,b as M,c as _,d as g}from"./select-dX9e6VDt.js";import{C as Ve,b as He,c as Ue,P as ze,D as We,e as Ye}from"./core.esm-DdQHdRkd.js";import{u as Ge,S as Xe,v as Je,a as Ke}from"./sortable.esm-qVEMoaTg.js";import{C as Qe,a as Ze,b as es}from"./collapsible-D3d29uJp.js";import"./radix-C5ZmWuuL.js";import"./textarea-CpDSUg2s.js";import"./popover-BFw_h3j6.js";function ss({id:l,relationship:s,onChange:a,onRemove:u,collections:j,readOnlyName:p,defaultExpanded:f}){const[b,k]=r.useState(f??!1),[d,D]=r.useState(!!s.label),{attributes:v,listeners:o,setNodeRef:i,transform:c,transition:C}=Ge({id:l}),y={transform:Ve.Transform.toString(c),transition:C};function x(n){a({...s,...n})}const I=j.find(n=>n.name===s.targetCollection)?.label??s.targetCollection;return e.jsx("div",{ref:i,style:y,className:"rounded-md border bg-card",children:e.jsxs(Qe,{open:b,onOpenChange:k,children:[e.jsxs("div",{className:"flex items-center gap-2 p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...v,...o,children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx(Ze,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(fe,{className:ve("h-4 w-4 transition-transform",b&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx(Ce,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:I}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:u,className:"text-destructive",children:e.jsx(K,{className:"h-3 w-3"})})]}),e.jsx(es,{children:e.jsxs("div",{className:"space-y-3 border-t p-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(Q,{value:s.name,onChange:n=>x({name:n}),onBlur:()=>{s.name&&!d&&x({label:Z(s.name)})},readOnly:p,className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Label"}),e.jsx(L,{value:s.label,onChange:n=>{x({label:n.target.value}),D(!0)},className:"h-8 text-sm"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Target Collection"}),e.jsxs(q,{value:s.targetCollection,onValueChange:n=>x({targetCollection:n}),children:[e.jsx($,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select collection..."})}),e.jsx(_,{children:j.map(n=>e.jsx(g,{value:n.name,children:n.label},n.name))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:`${l}-multiple`,checked:s.multiple,onCheckedChange:n=>x({multiple:!!n})}),e.jsx("label",{htmlFor:`${l}-multiple`,className:"text-sm",children:"Allow multiple"})]})]})})]})})}function ts({relationships:l,onChange:s,collections:a,existingRelNames:u}){const j=He(Ue(ze)),p=l.map((o,i)=>`rel-${i}`),[f,b]=r.useState(null);function k(){b(l.length),s([...l,{name:"",label:"",targetCollection:"",multiple:!1}])}function d(o,i){const c=[...l];c[o]=i,s(c)}function D(o){s(l.filter((i,c)=>c!==o))}function v(o){const{active:i,over:c}=o;if(c&&i.id!==c.id){const C=p.indexOf(String(i.id)),y=p.indexOf(String(c.id));s(Ke(l,C,y))}}return e.jsx(We,{sensors:j,collisionDetection:Ye,onDragEnd:v,children:e.jsx(Xe,{items:p,strategy:Je,children:e.jsxs("div",{className:"space-y-2",children:[l.map((o,i)=>e.jsx(ss,{id:`rel-${i}`,relationship:o,onChange:c=>d(i,c),onRemove:()=>D(i),collections:a,readOnlyName:!!(u?.has(o.name)&&o.name),defaultExpanded:i===f},`rel-${i}`)),e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:k,children:[e.jsx(Se,{className:"mr-2 h-3 w-3"})," Add Relationship"]})]})})})}const as=["text","textarea","number","boolean","select","array"],ls=["url","email","date","content","blocks"];function vs(){const{host:l,name:s}=je(),a=s==="new",{data:u,isLoading:j}=Ne(l,a?"":s);return!a&&j?e.jsxs("div",{className:"space-y-4",children:[e.jsx(U,{className:"h-8 w-64"}),e.jsx(U,{className:"h-64 w-full"})]}):a?e.jsx(J,{host:l,isNew:!0}):u?e.jsx(J,{host:l,isNew:!1,collection:u},u.name):e.jsx("p",{className:"text-muted-foreground",children:"Collection not found."})}function J({host:l,isNew:s,collection:a}){const u=be(),j=ye(),{collections:p}=ke(),f=De(l),b=Ee(l,a?.name??""),k=Pe(l,a?.name??""),[d,D]=r.useState(a?.name??""),[v,o]=r.useState(a?.label??""),[i,c]=r.useState(a?.labelSingular??""),[C,y]=r.useState(a?.slug??""),[x,I]=r.useState(a?.singleton??!1),[n,ee]=r.useState(a?.mode??"content"),[R,se]=r.useState(a?.requireAuth??!1),h=n==="submission",[te,ae]=r.useState(!s),[le,ne]=r.useState(!s),[ie,re]=r.useState(!s),oe=new Set((a?.fields??[]).map(t=>t.name).filter(Boolean)),T=[{name:"blocks",label:"Blocks",type:"blocks",options:{}}],[E,F]=r.useState(a?.fields??(s&&!x?T:[])),[A,ce]=r.useState(a?.relationships??[]),de=new Set((a?.relationships??[]).map(t=>t.name).filter(Boolean)),[B,ue]=r.useState(a?.mobileNavPriority??0),[w,me]=r.useState(a?.icon??""),[xe,V]=r.useState(!1);_e({title:s?"New Collection":a?.label??d,showBack:!0,backTo:`/sites/${l}/settings/collections`});function he(){if(!d)return;const t=Z(d);te||o(t),le||c(Me(t)),ie||y(d.replace(/_/g,"-"))}async function H(t){t?.preventDefault();try{s?(await f.mutateAsync({name:d,label:v,labelSingular:i,slug:C,singleton:h?!1:x,fields:E,relationships:A,mobileNavPriority:B,icon:w,mode:n,requireAuth:h?R:void 0}),P.success("Collection created"),u(`/sites/${l}/settings/collections/${d}`)):(await b.mutateAsync({label:v,labelSingular:i,slug:h?void 0:C,singleton:h?!1:x,fields:E,relationships:A,mobileNavPriority:B,icon:w,mode:n,requireAuth:h?R:void 0}),P.success("Collection updated"))}catch(S){P.error(s?"Failed to create":"Failed to update",{description:S instanceof Error?S.message:void 0})}}async function ge(){try{await k.mutateAsync(),P.success("Collection deleted"),u(`/sites/${l}/settings/collections`)}catch(t){P.error("Failed to delete",{description:t instanceof Error?t.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!j&&e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:s?"New Collection":`Edit: ${a?.label??d}`}),e.jsxs(W,{children:[e.jsx(Y,{children:e.jsx(G,{children:"Collection Settings"})}),e.jsx(X,{children:e.jsxs("form",{onSubmit:H,className:"space-y-4","aria-label":"Collection settings",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"name",children:"Name"}),e.jsx(Q,{id:"name",value:d,onChange:D,onBlur:he,readOnly:!s,placeholder:"e.g. blog_posts",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"mode",children:"Mode"}),e.jsxs(q,{value:n,onValueChange:t=>{ee(t),t==="submission"&&s&&(I(!1),F(E.filter(S=>as.includes(S.type)))),t==="content"&&s&&E.length===0&&F(T)},disabled:!s,children:[e.jsx($,{id:"mode",children:e.jsx(M,{})}),e.jsxs(_,{children:[e.jsx(g,{value:"content",children:"Content"}),e.jsx(g,{value:"submission",children:"Submissions"})]})]}),!s&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Mode cannot be changed after creation."})]}),h&&e.jsx("div",{className:"rounded-md border border-blue-200 bg-blue-50 p-3 text-sm text-blue-800 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-200",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Submission Collection"}),e.jsxs("p",{className:"mt-1",children:["Submissions are created via the API:"," ",e.jsxs("code",{className:"rounded bg-blue-100 px-1 dark:bg-blue-900",children:["POST /v1/","{site}","/submit/",d||"{collection}"]})]})]})]})}),h&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:"requireAuth",checked:R,onCheckedChange:t=>se(!!t)}),e.jsx(m,{htmlFor:"requireAuth",children:"Require authentication (site users must be logged in to submit)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"label",children:"Label"}),e.jsx(L,{id:"label",value:v,onChange:t=>{o(t.target.value),ae(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"label-singular",children:"Label Singular"}),e.jsx(L,{id:"label-singular",value:i,onChange:t=>{c(t.target.value),ne(!0)},required:!0})]}),!h&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"slug",children:"Slug"}),e.jsx(L,{id:"slug",value:C,onChange:t=>{y(t.target.value),re(!0)},required:!0})]}),!h&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:"singleton",checked:x,onCheckedChange:t=>{const S=!!t;I(S),s&&F(S?[]:T)},disabled:!s}),e.jsx(m,{htmlFor:"singleton",children:"Singleton (single entry, no list)"})]}),e.jsx(z,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Fields"}),e.jsx(qe,{fields:E,onChange:F,excludeTypes:h?ls:void 0,existingFieldNames:oe})]}),e.jsx(z,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Relationships"}),e.jsx(ts,{relationships:A,onChange:ce,collections:p,existingRelNames:de})]})]})})]}),e.jsxs(W,{className:"mt-6",children:[e.jsx(Y,{children:e.jsx(G,{children:"Navigation"})}),e.jsxs(X,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Icon"}),e.jsx($e,{value:w,onChange:me})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"mobileNavPriority",children:"Bottom Nav Priority"}),e.jsxs(q,{value:String(B),onValueChange:t=>ue(Number(t)),children:[e.jsx($,{id:"mobileNavPriority",children:e.jsx(M,{})}),e.jsxs(_,{children:[e.jsx(g,{value:"0",children:"0 - Hidden"}),e.jsx(g,{value:"1",children:"1"}),e.jsx(g,{value:"2",children:"2"}),e.jsx(g,{value:"3",children:"3"}),e.jsx(g,{value:"4",children:"4"}),e.jsx(g,{value:"5",children:"5 - Highest"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Collections with priority > 0 appear in the mobile bottom navigation bar."})]})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"outline",onClick:()=>u(`/sites/${l}/settings/collections`),children:"Cancel"}),e.jsxs(N,{onClick:H,disabled:f.isPending||b.isPending,children:[(f.isPending||b.isPending)&&e.jsx(Fe,{className:"mr-2 h-4 w-4 animate-spin"}),s?"Create":"Save"]})]}),!s&&e.jsx("div",{className:"mt-6",children:e.jsxs(Le,{open:xe,onOpenChange:V,children:[e.jsx(Re,{asChild:!0,children:e.jsxs(N,{variant:"destructive",children:[e.jsx(K,{className:"mr-2 h-4 w-4"}),"Delete Collection"]})}),e.jsxs(Te,{children:[e.jsxs(Ae,{children:[e.jsx(Be,{children:"Delete collection?"}),e.jsx(we,{children:"This will permanently delete the collection and all its content."})]}),e.jsxs(Oe,{children:[e.jsx(N,{variant:"outline",onClick:()=>V(!1),children:"Cancel"}),e.jsx(N,{variant:"destructive",onClick:ge,children:"Delete"})]})]})]})})]})}export{vs as CollectionEditPage};
@@ -1 +0,0 @@
1
- import{a as Ft,u as It,b as Ot,j as e}from"./tanstack-Bs3zYPPV.js";import{r,u as qt,f as $t,m as Vt,L as _t}from"./react-vendor-C2CvUxFh.js";import{f as Bt,g as Ms,h as Mt,i as Hs,j as Ht,k as Jt,l as zt,m as Yt,n as Kt,o as Gt,p as Qt,q as Wt,r as Js}from"./useContent-CW0tm0FY.js";import{C as Ee,v as U,E as cs,e as Oe,u as os,F as Xt,G as Zt,B as P,y as qe,J as ea,K as sa,M as ta,N as aa,S as Z,O as zs,Q as Ys,R as Te,V as Ue,W as Ks,Y as Gs,Z as Qs,_ as Ws,U as na,$ as ia,w as la,x as ra,L as Le,I as Ps,a0 as Xs,X as Ds,a1 as ca,a2 as Ls,a3 as oa,a4 as Rs,a5 as da,j as ua,a as te,a6 as As,a7 as Es,a8 as ha,a9 as Ts,aa as Ke,ab as ma,ac as fa,D as ss,k as ts,l as as,m as ns,n as is,o as ls,i as pa,T as ba}from"./index-BA3y7HJs.js";import{A as ds,a as us,b as hs,c as ms,d as fs,e as ps,f as bs,g as Zs,T as ga}from"./TagInput-d-Hw1fkL.js";import{u as xa}from"./useAdminResolver-Bljb4XGQ.js";import{u as va}from"./usePageTitle-DYvuJQp6.js";import{s as me,T as ja,d as ya}from"./serializeToText-Zin3gYPm.js";import{S as ka,a as Ca,b as wa,c as Sa,d as Ge,e as Na,f as Pa,g as Da}from"./select-dX9e6VDt.js";import{f as ne,a as Qe}from"./format-C88SDH8g.js";import{T as La}from"./textarea-CpDSUg2s.js";import{C as ue,c as he,a as Us,b as Fs}from"./card-CZTHR2Qa.js";import{C as et,a as st,b as tt}from"./collapsible-D3d29uJp.js";import{u as Ra}from"./useTags-ybsMbCst.js";import{M as Aa}from"./MediaField-B-Cz8TlK.js";import{m as Ea}from"./media-url-DIg_vSyf.js";import{R as Ta}from"./RelationshipPicker-Dv7GaLcU.js";import{A as Ua,a as Fa,i as Ia,F as Oa,b as Re,C as qa}from"./FieldRenderer-wE-mtqZB.js";import{g as $a,a as Va,b as _a}from"./contentStatus-CkPi9Dh6.js";import{O as Ba,f as Ma,g as Fe,e as at,w as We,a as Ha,t as Ja,r as Xe,b as za,c as Ya,d as Ka,h as Ga,i as Is,j as Qa,D as Wa}from"./yjs-tXBm_srz.js";import"./radix-C5ZmWuuL.js";import"./useMedia-Cu5N4rY8.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./ContentField-D04Uo1Ov.js";import"./popover-BFw_h3j6.js";import"./command-CdzYw11U.js";import"./useContentSearch-_bwacEth.js";import"./checkbox-DEgzM8H9.js";const Xa=3e3,Za="__HEADROOM_API_URL__".replace(/\/+$/,"");function en(a,s,n,t,l,c=Xa,d){const f=Bt(a,s),u=r.useRef(null),m=r.useRef(n?JSON.stringify(n):""),v=r.useRef(void 0),[w,p]=r.useState(null),[S,b]=r.useState(null),L=r.useRef(!1),y=r.useRef(d);r.useEffect(()=>{y.current=d},[d]);const h=r.useCallback(A=>{JSON.stringify(A)!==m.current&&(u.current=A,clearTimeout(v.current),v.current=window.setTimeout(()=>{if(u.current){const F=u.current,E=JSON.stringify(F);u.current=null,f.mutate(F,{onSuccess:T=>{if(L.current){L.current=!1;return}m.current=E,p(Date.now()),T?.blockId&&b(T.blockId),y.current?.(T)},onError:T=>{T instanceof Ee&&T.code==="SLUG_TAKEN"?t?.():T instanceof Ee&&T.code==="LOCK_HELD"?l?.(T):T instanceof Ee&&T.status===400&&U.error("Auto-save failed",{description:T.message})}})}},c))},[f,t,l,c]),g=r.useCallback(async A=>{if(clearTimeout(v.current),u.current){const o={...u.current};A?.createVersion&&(o.createVersion=!0);const F=JSON.stringify(u.current);u.current=null;const E=await f.mutateAsync(o);m.current=F,p(Date.now()),E?.blockId&&b(E.blockId)}else if(A?.createVersion&&m.current){const F={...JSON.parse(m.current),createVersion:!0},E=await f.mutateAsync(F);p(Date.now()),E?.blockId&&b(E.blockId)}},[f]),N=r.useCallback(()=>{clearTimeout(v.current),u.current=null},[]),_=r.useCallback(A=>{m.current=JSON.stringify(A)},[]),R=r.useCallback(()=>{clearTimeout(v.current),u.current=null,L.current=!0,b(null)},[]);return r.useEffect(()=>()=>{if(clearTimeout(v.current),u.current){const A=JSON.stringify(u.current),o=cs(),F=`${Za}/v1/admin/sites/${a}/content/${s}/draft`;fetch(F,{method:"PUT",body:A,headers:{"Content-Type":"application/json",...o?{Authorization:`Bearer ${o}`}:{}},keepalive:!0}).catch(()=>{}),u.current=null}},[a,s]),{schedule:h,flush:g,cancel:N,resetBaseline:_,discard:R,isSaving:f.isPending,lastSavedAt:w,lastSavedBlockId:S}}const sn="__HEADROOM_API_URL__".replace(/\/+$/,""),tn=5e3,an=3600*1e3;function nn(a){const s=`headroom:editSession:${a}`;let n=sessionStorage.getItem(s);return n||(n=Xt(),sessionStorage.setItem(s,n)),n}const Ze=new Map;function ln(a,s){const n=Oe(),{user:t}=os(),l=Ft(),[c,d]=r.useState("loading"),[f,u]=r.useState(null),[m,v]=r.useState(null),[w,p]=r.useState([]),[S,b]=r.useState(!1),[L,y]=r.useState(!1),h=s?nn(s):"",g=r.useRef(0),N=r.useRef(!1),_=r.useRef(!1),R=r.useCallback(async(j=!1)=>{if(!a||!s||!h)return null;const x=`${a}:${s}`,O=Ze.get(x);if(O)return O;const q=n.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock`,{method:"POST",body:JSON.stringify({sessionId:h,force:j,email:t?.email,name:t?.name})}).finally(()=>{Ze.delete(x)});return Ze.set(x,q),q},[n,a,s,h,t?.email,t?.name]),A=r.useCallback(async()=>{if(!(!a||!s||!h))try{await n.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock`,{method:"DELETE",body:JSON.stringify({sessionId:h})})}catch{}},[n,a,s,h]);r.useEffect(()=>{if(!a||!s||!h)return;const j=()=>{if(!N.current)return;const x=cs(),O=`${sn}/v1/admin/sites/${a}/content/${s}/edit-lock`;fetch(O,{method:"DELETE",body:JSON.stringify({sessionId:h}),headers:{"Content-Type":"application/json",...x?{Authorization:`Bearer ${x}`}:{}},keepalive:!0}).catch(()=>{})};return window.addEventListener("beforeunload",j),()=>window.removeEventListener("beforeunload",j)},[a,s,h]),r.useEffect(()=>{if(!a||!s||!h||!t)return;_.current=!1;let j=!1;return(async()=>{try{const x=await R();if(j||!x)return;x.acquired?(N.current=!0,d("acquired"),u(x.lockHolder??null),v(x.takeoverReason),y(x.collaborationEnabled)):x.lockHolder&&x.lockHolder.sub===t.sub&&x.lockHolder.sessionId!==h?(d("same-user-other-tab"),u(x.lockHolder)):(d("read-only"),u(x.lockHolder??null),g.current=Date.now())}catch(x){if(!j){const O=x;if(O.status===409){const q=O.body?.lockHolder??null,V=O.body?.collaborationEnabled??!1;q&&q.sub===t.sub&&q.sessionId!==h?(d("same-user-other-tab"),u(q)):(d("read-only"),u(q),y(V),g.current=Date.now())}else d("error")}}})(),()=>{j=!0,N.current&&!_.current&&(_.current=!0,N.current=!1,A())}},[a,s,h,t,R,A]);const o=c==="read-only"&&!S,F=r.useCallback(j=>{if(g.current&&Date.now()-g.current>an){b(!0),d("poll-ceiling");return}const x=j.lock;if(!x)u(null),y(!1),p([]);else{u(x.heldBy),y(x.collaborationEnabled);const O=(x.accessRequests??[]).filter(q=>q.sub!==t?.sub);p(O)}},[t?.sub]);It({queryKey:["sites",a,"edit-lock",s],queryFn:async()=>{try{const j=await n.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock`);return F(j),j}catch{return{lock:f?{heldBy:f,expiresAt:0,collaborationEnabled:L,accessRequests:[]}:null}}},enabled:o,refetchInterval:o?tn:!1,refetchIntervalInBackground:!1,retry:!1});const E=Ot({mutationFn:()=>n.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock/access-requests`,{method:"POST",body:JSON.stringify({sessionId:h,email:t?.email,name:t?.name})})}),T=r.useCallback(async()=>{const j=await R(!0);return j?.acquired&&(N.current=!0,d("acquired"),u(j.lockHolder??null),v(j.takeoverReason),y(j.collaborationEnabled),l.invalidateQueries({queryKey:["sites",a,"edit-lock",s]})),j},[R,l,a,s]),re=r.useCallback(async()=>{const j=await R(!1);return j?.acquired&&(N.current=!0,d("acquired"),u(j.lockHolder??null),v(j.takeoverReason),y(j.collaborationEnabled),l.invalidateQueries({queryKey:["sites",a,"edit-lock",s]})),j},[R,l,a,s]),k=r.useCallback(j=>{N.current=!1,d("expired"),u(j.lockHolder??null),v(j.takeoverReason??null)},[]),ce=r.useCallback(()=>{N.current=!1,d("read-only"),g.current=Date.now()},[]);return{status:c,lockHolder:f,takeoverReason:m,accessRequests:w,sessionId:h,pollCeiling:S,collaborationEnabled:L,acquireLock:R,releaseLock:A,requestCollaboration:E,forceTakeover:T,takeEditing:re,onAutosaveConflict:k,dismissModal:ce,setAccessRequests:p,setCollaborationEnabled:y}}function $e(){return"__HEADROOM_COLLAB_ENABLED__"!=="false"}function rn({lockHolder:a,onRequestCollaboration:s,onForceTakeover:n,isRequesting:t,requestSent:l}){const c=$e();return e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mb-4","data-testid":"edit-lock-banner",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Zt,{className:"h-5 w-5 text-amber-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"font-medium text-amber-900",children:["Editing: ",a.name||a.email]}),e.jsx("p",{className:"text-sm text-amber-700 mt-1",children:c?"This content is being edited. You can view it read-only or ask to collaborate.":"This content is being edited. You can view it read-only until the editor is finished."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[c&&e.jsx(P,{size:"sm",variant:"outline",onClick:s,disabled:t||l,"data-testid":"request-collaboration-btn",children:l?"Request sent":"Request collaboration"}),n&&e.jsx(P,{size:"sm",variant:"destructive",onClick:n,"data-testid":"force-takeover-btn",children:"Take over"})]})]})]})})}function cn({open:a,lockHolder:s,takeoverReason:n,currentUserSub:t,onRequestCollaboration:l,onViewReadOnly:c}){let d="Your edit lock expired",f="";return n==="expired"?f=s?`${s.name||s.email} is now editing this content. Your latest changes have not been saved.`:"Another user is now editing this content. Your latest changes have not been saved.":n==="forced"?s&&s.sub===t?(d="Editing moved to another tab",f="This content is now being edited in another tab of yours."):(d="Edit session taken over",f=s?`A super-admin has taken over this edit session — ${s.name||s.email} is now editing.`:"A super-admin has taken over this edit session."):f=s?`${s.name||s.email} is now editing this content. Your latest changes have not been saved.`:"Your edit lock has expired.",e.jsx(ds,{open:a,children:e.jsxs(us,{"data-testid":"lock-expired-modal",children:[e.jsxs(hs,{children:[e.jsx(ms,{children:d}),e.jsx(fs,{children:f})]}),e.jsxs(ps,{children:[$e()&&e.jsx(P,{variant:"outline",onClick:l,"data-testid":"lock-expired-request-collab",children:"Request collaboration"}),e.jsx(bs,{onClick:c,"data-testid":"lock-expired-view-readonly",children:"View read-only"})]})]})})}function on({open:a,onTakeOver:s,onCancel:n}){return e.jsx(ds,{open:a,children:e.jsxs(us,{"data-testid":"same-user-other-tab-modal",children:[e.jsxs(hs,{children:[e.jsx(ms,{children:"Already editing in another tab"}),e.jsx(fs,{children:"You're already editing this content in another tab. Taking over here will end the editing session in the other tab."})]}),e.jsxs(ps,{children:[e.jsx(Zs,{onClick:n,children:"Cancel"}),e.jsx(bs,{onClick:s,"data-testid":"take-over-btn",children:"Take over here"})]})]})})}function dn({lines:a}){return e.jsx("div",{className:"font-mono text-sm leading-relaxed",children:a.map((s,n)=>e.jsx("div",{style:{paddingLeft:`${s.indent*1.5}rem`},className:qe("min-h-[1.5em]",s.type==="label"&&"text-muted-foreground font-semibold mt-1",s.type==="heading"&&"font-bold",s.type==="empty"&&"h-2"),children:s.text},n))})}function rs(a){switch(a.kind){case"draft":return"Draft";case"published":return"Published";case"history":return ne(a.createdAt)}}function Ie(a){switch(a.kind){case"draft":return"draft";case"published":return"published";case"history":return`history:${a.blockId}`}}function Os({value:a,onChange:s,isPublished:n,versions:t,exclude:l,size:c}){const d=l?Ie(l):null;function f(u){if(u==="draft")s({kind:"draft"});else if(u==="published")s({kind:"published"});else if(u.startsWith("history:")){const m=u.slice(8),v=t.find(w=>w.blockId===m);v&&s({kind:"history",blockId:v.blockId,createdAt:v.createdAt,title:v.title})}}return e.jsxs(ka,{value:Ie(a),onValueChange:f,children:[e.jsx(Ca,{size:c,children:e.jsx(wa,{children:rs(a)})}),e.jsxs(Sa,{position:"popper",children:[d!=="draft"&&e.jsx(Ge,{value:"draft",children:"Draft"}),n&&d!=="published"&&e.jsx(Ge,{value:"published",children:"Published"}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Na,{}),e.jsxs(Pa,{children:[e.jsx(Da,{children:"Version History"}),t.map(u=>{const m=`history:${u.blockId}`;return m===d?null:e.jsx(Ge,{value:m,children:ne(u.createdAt)},m)})]})]})]})]})}function qs({ref:a,host:s,contentId:n,collectionFields:t,isSingleton:l,draftBody:c,draftMetadata:d,collectionRelationships:f,draftRelationships:u}){const m=a?.kind==="published",v=a?.kind==="history",w=v?a.blockId:null,{data:p,isLoading:S}=Ms(s,n,m),{data:b,isLoading:L}=Mt(s,n,v?w:null),y=r.useMemo(()=>(f??[]).map(N=>({name:N.name,label:N.label})),[f]);function h(N){if(y.length!==0)return{defs:y,values:N??{}}}const g=r.useMemo(()=>{if(!a)return[];if(a.kind==="draft")return c?me(t,c,l?void 0:d,h(u)):[];if(a.kind==="published"){if(!p)return[];const R=l?void 0:{title:p.title,slug:p.slug,snippet:p.snippet,tags:p.tags},A=p.relationships;return me(t,p.fields??{},R,h(A))}if(!b)return[];const N=l?void 0:{title:b.title,slug:b.slug,snippet:b.snippet,tags:b.tags},_=b.relationships;return me(t,b.body??{},N,h(_))},[a,c,d,u,p,b,t,l,y]);return a?a.kind==="draft"?{lines:g,isLoading:!1,hasData:!!c}:a.kind==="published"?{lines:g,isLoading:S,hasData:!!p}:{lines:g,isLoading:L,hasData:!!b}:{lines:[],isLoading:!1,hasData:!1}}function un({open:a,onOpenChange:s,host:n,contentId:t,collectionFields:l,isSingleton:c,isPublished:d,draftBody:f,draftMetadata:u,initialVersion:m,collectionRelationships:v,draftRelationships:w}){const[p,S]=r.useState(m??{kind:"published"}),[b,L]=r.useState({kind:"draft"}),[y,h]=r.useState(a),[g,N]=r.useState(m);if((a!==y||m!==g)&&(h(a),N(m),a)){const T=m??{kind:"published"};S(T),L(T.kind==="draft"?{kind:"published"}:{kind:"draft"})}Ie(p)===Ie(b)&&(p.kind!=="draft"?L({kind:"draft"}):d&&L({kind:"published"}));const{data:_}=Hs(n,t),R=_?.items??[],A={host:n,contentId:t,collectionFields:l,isSingleton:c,draftBody:f,draftMetadata:u,collectionRelationships:v,draftRelationships:w},o=qs({ref:a?p:null,...A}),F=qs({ref:a?b:null,...A}),E=o.isLoading;return e.jsx(ea,{open:a,onOpenChange:s,children:e.jsxs(sa,{className:"w-[calc(100vw-2rem)] sm:max-w-2xl overflow-y-auto pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)]",children:[e.jsx(ta,{children:e.jsxs(aa,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-sm font-normal",children:"Viewing"}),e.jsx(Os,{value:p,onChange:S,isPublished:d,versions:R,size:"sm"})]})}),E&&e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(Z,{className:"h-6 w-48"}),e.jsx(Z,{className:"h-4 w-full"}),e.jsx(Z,{className:"h-4 w-full"}),e.jsx(Z,{className:"h-4 w-2/3"})]}),!E&&!o.hasData&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No data available for this version."}),!E&&o.hasData&&e.jsx("div",{className:"p-4",children:e.jsxs(zs,{defaultValue:"changes",children:[e.jsxs(Ys,{variant:"line",className:"mb-4",children:[e.jsx(Te,{value:"content",children:"Content"}),e.jsx(Te,{value:"changes",children:"Changes"})]}),e.jsx(Ue,{value:"content",children:e.jsx(dn,{lines:o.lines})}),e.jsxs(Ue,{value:"changes",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Compare with"}),e.jsx(Os,{value:b,onChange:L,isPublished:d,versions:R,exclude:p,size:"sm"})]}),F.isLoading?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Z,{className:"h-4 w-full"}),e.jsx(Z,{className:"h-4 w-full"}),e.jsx(Z,{className:"h-4 w-2/3"})]}):F.hasData?e.jsx(ja,{left:F.lines,right:o.lines,leftLabel:rs(b),rightLabel:rs(p)}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No data available for comparison."})]})]})})]})})}const es=3e4;class hn extends Ba{constructor(s){super(),this.doc=s,this.clientID=s.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=Fe();this.getLocalState()!==null&&es/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const t=[];this.meta.forEach((l,c)=>{c!==this.clientID&&es<=n-l.lastUpdated&&this.states.has(c)&&t.push(c)}),t.length>0&&mn(this,t,"timeout")},Ma(es/10)),s.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(s){const n=this.clientID,t=this.meta.get(n),l=t===void 0?0:t.clock+1,c=this.states.get(n);s===null?this.states.delete(n):this.states.set(n,s),this.meta.set(n,{clock:l,lastUpdated:Fe()});const d=[],f=[],u=[],m=[];s===null?m.push(n):c==null?s!=null&&d.push(n):(f.push(n),at(c,s)||u.push(n)),(d.length>0||u.length>0||m.length>0)&&this.emit("change",[{added:d,updated:u,removed:m},"local"]),this.emit("update",[{added:d,updated:f,removed:m},"local"])}setLocalStateField(s,n){const t=this.getLocalState();t!==null&&this.setLocalState({...t,[s]:n})}getStates(){return this.states}}const mn=(a,s,n)=>{const t=[];for(let l=0;l<s.length;l++){const c=s[l];if(a.states.has(c)){if(a.states.delete(c),c===a.clientID){const d=a.meta.get(c);a.meta.set(c,{clock:d.clock+1,lastUpdated:Fe()})}t.push(c)}}t.length>0&&(a.emit("change",[{added:[],updated:[],removed:t},n]),a.emit("update",[{added:[],updated:[],removed:t},n]))},$s=(a,s,n=a.states)=>{const t=s.length,l=Ya();We(l,t);for(let c=0;c<t;c++){const d=s[c],f=n.get(d)||null,u=a.meta.get(d).clock;We(l,d),We(l,u),Ha(l,JSON.stringify(f))}return Ja(l)},fn=(a,s,n)=>{const t=Ka(s),l=Fe(),c=[],d=[],f=[],u=[],m=Xe(t);for(let v=0;v<m;v++){const w=Xe(t);let p=Xe(t);const S=JSON.parse(za(t)),b=a.meta.get(w),L=a.states.get(w),y=b===void 0?0:b.clock;(y<p||y===p&&S===null&&a.states.has(w))&&(S===null?w===a.clientID&&a.getLocalState()!=null?p++:a.states.delete(w):a.states.set(w,S),a.meta.set(w,{clock:p,lastUpdated:l}),b===void 0&&S!==null?c.push(w):b!==void 0&&S===null?u.push(w):S!==null&&(at(S,L)||f.push(w),d.push(w)))}(c.length>0||f.length>0||u.length>0)&&a.emit("change",[{added:c,updated:f,removed:u},n]),(c.length>0||d.length>0||u.length>0)&&a.emit("update",[{added:c,updated:d,removed:u},n])},Vs=[1e3,2e3,4e3,8e3,16e3];class gs{awareness;ws=null;doc;room;wsUrl;ticket;getTicket;reconnectAttempt=0;reconnectTimer=null;connected=!1;destroyed=!1;pendingUpdates=[];pendingFieldUpdates=[];static MAX_PENDING_FIELD_UPDATES=100;statusListeners=new Set;constructor(s){this.doc=s.doc,this.room=s.room,this.wsUrl=s.wsUrl,this.ticket=s.ticket,this.getTicket=s.getTicket,this.awareness=new hn(this.doc),this.awareness.setLocalStateField("user",s.user),this.doc.on("update",this.handleDocUpdate),this.awareness.on("update",this.handleAwarenessUpdate),this.connect()}onStatus(s){return this.statusListeners.add(s),()=>{this.statusListeners.delete(s)}}connect(){if(this.destroyed)return;this.statusListeners.forEach(n=>n("connecting"));const s=`${this.wsUrl}?ticket=${encodeURIComponent(this.ticket)}&room=${encodeURIComponent(this.room)}`;this.ws=new WebSocket(s),this.ws.onopen=()=>{this.connected=!0,this.reconnectAttempt=0,this.statusListeners.forEach(l=>l("connected"));const n=Ga(this.doc);this.ws.send(JSON.stringify({action:"yjs",type:"sync-step-1",data:de(n)}));const t=$s(this.awareness,[this.doc.clientID]);this.ws.send(JSON.stringify({action:"awareness",data:de(t)}))},this.ws.onmessage=n=>{const t=JSON.parse(n.data);switch(t.action){case"yjs":this.handleYjsMessage(t);break;case"field":this.fieldListeners.forEach(l=>l(t));break;case"awareness":this.handleAwarenessMessage(t);break;case"presence":this.presenceListeners.forEach(l=>l(t));break;case"leader-change":this.leaderChangeListeners.forEach(l=>l(t));break;case"collaboration-disabled":this.collabDisabledListeners.forEach(l=>l());break;case"publish-requested":this.publishRequestedListeners.forEach(l=>l(t));break;case"save-version-requested":this.saveVersionRequestedListeners.forEach(l=>l(t));break;case"publish-in-progress":this.publishInProgressListeners.forEach(l=>l());break;case"published":this.publishedListeners.forEach(l=>l(t));break}},this.ws.onclose=()=>{this.connected=!1,this.statusListeners.forEach(n=>n("disconnected")),this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}handleDocUpdate=(s,n)=>{n!=="remote"&&(this.connected?this.sendYjsUpdate(s):this.pendingUpdates.push(s))};sendYjsUpdate(s){this.ws?.send(JSON.stringify({action:"yjs",type:"update",data:de(s)}))}flushPendingUpdates(){for(const s of this.pendingUpdates)this.sendYjsUpdate(s);this.pendingUpdates=[]}handleYjsMessage(s){const n=_s(s.data);switch(s.type){case"sync-step-1":{const t=Qa(this.doc,n);this.ws.send(JSON.stringify({action:"yjs",type:"sync-step-2",data:de(t)}));break}case"sync-step-2":Is(this.doc,n,"remote"),this.flushPendingUpdates(),this.flushPendingFieldUpdates();break;case"update":Is(this.doc,n,"remote");break}}fieldListeners=new Set;onFieldUpdate(s){return this.fieldListeners.add(s),()=>{this.fieldListeners.delete(s)}}sendFieldUpdate(s,n){if(!this.connected){const t=this.pendingFieldUpdates.findIndex(l=>l.field===s);t>=0?this.pendingFieldUpdates[t]={field:s,value:n}:(this.pendingFieldUpdates.length>=gs.MAX_PENDING_FIELD_UPDATES&&this.pendingFieldUpdates.shift(),this.pendingFieldUpdates.push({field:s,value:n}));return}this.ws?.send(JSON.stringify({action:"field",field:s,value:n}))}flushPendingFieldUpdates(){for(const{field:s,value:n}of this.pendingFieldUpdates)this.ws?.send(JSON.stringify({action:"field",field:s,value:n}));this.pendingFieldUpdates=[]}presenceListeners=new Set;onPresence(s){return this.presenceListeners.add(s),()=>{this.presenceListeners.delete(s)}}leaderChangeListeners=new Set;onLeaderChange(s){return this.leaderChangeListeners.add(s),()=>{this.leaderChangeListeners.delete(s)}}collabDisabledListeners=new Set;onCollabDisabled(s){return this.collabDisabledListeners.add(s),()=>{this.collabDisabledListeners.delete(s)}}sendDisableCollab(){this.connected&&this.ws?.send(JSON.stringify({action:"disable-collab"}))}publishRequestedListeners=new Set;onPublishRequested(s){return this.publishRequestedListeners.add(s),()=>{this.publishRequestedListeners.delete(s)}}saveVersionRequestedListeners=new Set;onSaveVersionRequested(s){return this.saveVersionRequestedListeners.add(s),()=>{this.saveVersionRequestedListeners.delete(s)}}publishInProgressListeners=new Set;onPublishInProgress(s){return this.publishInProgressListeners.add(s),()=>{this.publishInProgressListeners.delete(s)}}publishedListeners=new Set;onPublished(s){return this.publishedListeners.add(s),()=>{this.publishedListeners.delete(s)}}sendRequestPublish(){this.connected&&this.ws?.send(JSON.stringify({action:"request-publish"}))}sendRequestSaveVersion(){this.connected&&this.ws?.send(JSON.stringify({action:"request-save-version"}))}sendPublishInProgress(){this.connected&&this.ws?.send(JSON.stringify({action:"publish-in-progress"}))}sendPublished(s){this.connected&&this.ws?.send(JSON.stringify({action:"published",...s?.contentId?{contentId:s.contentId}:{},...s?.version!==void 0?{version:s.version}:{}}))}handleAwarenessUpdate=({added:s,updated:n,removed:t})=>{if(!this.connected)return;const l=$s(this.awareness,[...s,...n,...t]);this.ws?.send(JSON.stringify({action:"awareness",data:de(l)}))};handleAwarenessMessage(s){const n=_s(s.data);fn(this.awareness,n,"remote")}scheduleReconnect(){if(this.destroyed)return;const s=Vs[Math.min(this.reconnectAttempt,Vs.length-1)];this.reconnectAttempt++,this.reconnectTimer=window.setTimeout(async()=>{try{this.ticket=await this.getTicket()}catch{this.statusListeners.forEach(n=>n("disconnected"));return}this.connect()},s)}destroy(){this.destroyed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.doc.off("update",this.handleDocUpdate),this.awareness.off("update",this.handleAwarenessUpdate),this.awareness.destroy(),this.ws?.close()}}function de(a){let s="";for(let t=0;t<a.length;t+=8192)s+=String.fromCharCode(...a.subarray(t,t+8192));return btoa(s)}function _s(a){const s=atob(a),n=new Uint8Array(s.length);for(let t=0;t<s.length;t++)n[t]=s.charCodeAt(t);return n}const Ae=["#3b82f6","#ef4444","#10b981","#f59e0b","#8b5cf6","#ec4899","#14b8a6","#f97316"];function pn(a,s,n,t){const{user:l}=os(),[c,d]=r.useState(null),[f,u]=r.useState("disconnected"),[m,v]=r.useState([]),[w,p]=r.useState({}),S=r.useRef(null),b=r.useRef(t?.onCollabDisabled),L=r.useRef(t?.onPublishRequested),y=r.useRef(t?.onSaveVersionRequested),h=r.useRef(t?.onPublishInProgress),g=r.useRef(t?.onPublished);r.useEffect(()=>{b.current=t?.onCollabDisabled,L.current=t?.onPublishRequested,y.current=t?.onSaveVersionRequested,h.current=t?.onPublishInProgress,g.current=t?.onPublished},[t?.onCollabDisabled,t?.onPublishRequested,t?.onSaveVersionRequested,t?.onPublishInProgress,t?.onPublished]);const N="__HEADROOM_COLLAB_WS_URL__",_=$e(),R=_&&!!c&&f==="connected";r.useEffect(()=>{if(!_||!N||!l||!n)return;const C=new Wa;S.current=C;const I=`${a}/${s}`,Y=async()=>{const M=cs();if(!M)throw new Error("No access token");const ee="__HEADROOM_API_URL__".replace(/\/+$/,""),H=await fetch(`${ee}/v1/admin/sites/${a}/content/${s}/collab/ticket`,{method:"POST",headers:{Authorization:`Bearer ${M}`,"Content-Type":"application/json"},body:JSON.stringify({room:I})});if(!H.ok)throw new Error(`Ticket request failed: ${H.status}`);return(await H.json()).ticket};let B=!1,$=null;return Y().then(M=>{if(B)return;const ee=Bs(l.sub)%Ae.length;$=new gs({wsUrl:N,room:I,ticket:M,getTicket:Y,doc:C,user:{sub:l.sub,name:l.name||l.email,color:Ae[ee]}}),$.onStatus(u),$.onPresence(H=>{v(H.connections.filter(J=>J.connectionId!==H.youAre).map(J=>({sub:J.adminSub,name:J.adminName,color:J.color})));const G=H.connections.find(J=>J.connectionId===H.youAre);V(G?.isLeader??!1)}),$.onCollabDisabled(()=>{b.current?.()}),$.onPublishRequested(()=>L.current?.()),$.onSaveVersionRequested(()=>y.current?.()),$.onPublishInProgress(()=>h.current?.()),$.onPublished(H=>g.current?.({contentId:H.contentId,version:H.version})),d($)}).catch(()=>{B||u("disconnected")}),()=>{B=!0,$?.destroy(),C.destroy(),d(null),u("disconnected")}},[a,s,l?.sub,n,N]);const A=r.useCallback(C=>{if(!c||!l||!S.current)return;const I=S.current.getXmlFragment(`document-store-${C}`),Y=Bs(l.sub)%Ae.length;return{provider:c,fragment:I,user:{name:l.email,color:Ae[Y]}}},[c,l]);r.useEffect(()=>{if(!c){p({});return}const C=()=>{const I={};c.awareness.getStates().forEach(B=>{const $=B?.user?.sub;if(!$)return;const M=B.activeField??null;I[$]=M}),p(I)};return C(),c.awareness.on("change",C),()=>{c.awareness.off("change",C)}},[c]);const o=r.useMemo(()=>m.map(C=>({...C,activeField:w[C.sub]??null})),[m,w]),F=r.useCallback(C=>{c&&c.awareness.setLocalStateField("activeField",C)},[c]),E=r.useRef(new Set),T=r.useCallback(C=>(E.current.add(C),()=>{E.current.delete(C)}),[]);r.useEffect(()=>{if(c)return c.onFieldUpdate(C=>{E.current.forEach(I=>I(C.field,C.value))})},[c]);const re=r.useCallback((C,I)=>{c?.sendFieldUpdate(C,I)},[c]),k=r.useCallback(()=>{c?.sendDisableCollab()},[c]),ce=r.useCallback(()=>{c?.sendRequestPublish()},[c]),j=r.useCallback(()=>{c?.sendRequestSaveVersion()},[c]),x=r.useCallback(()=>{c?.sendPublishInProgress()},[c]),O=r.useCallback(C=>{c?.sendPublished(C)},[c]),[q,V]=r.useState(!1);return r.useEffect(()=>{if(c)return c.onLeaderChange(C=>{V(C.leaderSub===l?.sub)})},[c,l]),{active:R,status:f,editors:o,isLeader:q,getBlockNoteCollab:A,updateField:re,onRemoteFieldChange:T,setActiveField:F,sendDisableCollab:k,sendRequestPublish:ce,sendRequestSaveVersion:j,sendPublishInProgress:x,sendPublished:O}}function Bs(a){let s=0;for(let n=0;n<a.length;n++)s=(s<<5)-s+a.charCodeAt(n)|0;return Math.abs(s)}function bn({status:a,editors:s}){return s.length===0&&a==="connected"?null:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-muted/50 rounded-md text-sm","data-testid":"collaboration-bar",children:[e.jsxs("div",{className:"flex items-center gap-1.5","aria-label":a,children:[e.jsx("span",{"data-testid":"collaboration-bar-status-dot","data-status":a,className:qe("h-2 w-2 rounded-full",a==="connected"&&"bg-green-500",a==="connecting"&&"bg-yellow-500 animate-pulse",a==="disconnected"&&"bg-red-500")}),e.jsx("span",{className:"text-muted-foreground text-xs",children:a==="connected"?"Live":a==="connecting"?"Connecting...":"Offline"})]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ks,{orientation:"vertical",className:"h-4"}),e.jsx("div",{className:"flex -space-x-1.5",children:s.map(n=>e.jsxs(Gs,{children:[e.jsx(Qs,{asChild:!0,children:e.jsx(Ua,{className:"h-6 w-6 border-2",style:{borderColor:n.color},"aria-label":n.name,children:e.jsx(Fa,{className:"text-[10px]",style:{backgroundColor:n.color+"20"},children:Ia(n.name)})})}),e.jsx(Ws,{children:n.name})]},n.sub))}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[s.length," other ",s.length===1?"editor":"editors"]})]})]})}function gn({host:a,contentId:s,collaborationEnabled:n,hasConnectedPeers:t,isLockHolder:l,sessionId:c,onChange:d,onBeforeDisable:f}){const[u,m]=r.useState(!1),v=Oe();if(!$e()||!l)return null;const w=async()=>{const y=!n;m(!0);try{if(!y)try{f?.()}catch{}await v.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock/collaboration`,{method:"POST",body:JSON.stringify({collaborationEnabled:y,sessionId:c})}),d(y)}catch{U.error("Failed to update collaboration setting")}finally{m(!1)}},p=n&&t,S=u||p,b=p?"Cannot stop sharing while other editors are connected":null,L=e.jsxs(P,{variant:n?"default":"outline",size:"sm",disabled:S,onClick:w,"aria-pressed":n,children:[n?e.jsx(na,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"}),n?"Collaborating":"Collaborate"]});return b?e.jsxs(Gs,{children:[e.jsx(Qs,{asChild:!0,children:L}),e.jsx(Ws,{children:b})]}):L}function xn(a,s,n,t,l){const c=r.useRef(new Set),d=Oe();r.useEffect(()=>{const f=new Set(t.map(u=>u.sub));for(const u of Array.from(c.current))f.has(u)||c.current.delete(u)},[t]),r.useEffect(()=>{for(const f of t){if(c.current.has(f.sub))continue;c.current.add(f.sub);const u=f.name||f.email||"Someone";U(`${u} wants to collaborate`,{action:{label:"Allow",onClick:()=>{d.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock/collaboration`,{method:"POST",body:JSON.stringify({collaborationEnabled:!0,sessionId:n})}).then(()=>l()).catch(()=>U.error("Failed to enable collaboration"))}},cancel:{label:"Decline",onClick:()=>{d.apiFetch(`/v1/admin/sites/${a}/content/${s}/edit-lock/access-requests/${f.sub}?sessionId=${n}`,{method:"DELETE"}).catch(()=>U.error("Failed to decline request"))}},duration:1/0})}},[t,a,s,n,l,d])}function Xn(){const{host:a,collection:s,id:n}=qt(),{data:t,isLoading:l}=Ht(a,n);return l?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Z,{className:"h-8 w-64"}),e.jsx(Z,{className:"h-64 w-full"})]}):t?.content?e.jsx(vn,{host:a,collection:s,contentId:n,content:t.content,draft:t.draft,publishedBlockId:t.publishedBlockId}):e.jsx("p",{className:"text-muted-foreground",children:"Content not found."})}function vn({host:a,collection:s,contentId:n,content:t,draft:l,publishedBlockId:c}){const d=$t(),f=Oe(),{collections:u}=la(),m=Jt(a,n),v=zt(a,n),w=Yt(a,n),p=Kt(a,n),S=Gt(a,n),b=Qt(a,n),L=l?{title:l.title??t.title,slug:l.slug??t.slug??"",snippet:l.snippet??t.snippet??"",tags:l.tags??t.tags??[],cover:l.cover??t.cover??null,body:l.body??{},relationships:l.relationships??{}}:void 0,{user:y}=os(),h=ln(a,n),g=(h.status==="read-only"||h.status==="poll-ceiling")&&!h.collaborationEnabled,N=r.useRef(()=>{}),_=r.useRef(()=>{}),[R,A]=r.useState(!1),o=pn(a,n,h.collaborationEnabled,{onCollabDisabled:()=>h.setCollaborationEnabled(!1),onPublishRequested:()=>N.current(),onSaveVersionRequested:()=>_.current(),onPublishInProgress:()=>A(!0),onPublished:()=>{A(!1),U.success("Content published")}}),[F,E]=r.useState(null),T=o.active?1e4:void 0,re=r.useCallback(i=>{const ae=(i?.accessRequests??[]).filter(De=>De.sub!==y?.sub);h.setAccessRequests(ae)},[h,y?.sub]),k=en(a,n,L,()=>{E("This slug is already in use by another item in this collection")},i=>{h.onAutosaveConflict({lockHolder:i.body?.lockHolder??void 0,takeoverReason:i.body?.takeoverReason??"expired"})},T,re);xn(a,n,h.sessionId,h.accessRequests,()=>h.setCollaborationEnabled(!0));const{data:ce}=Ra(a),j=ce?.map(i=>i.tag),x=u.find(i=>i.name===s),O=r.useMemo(()=>x?.fields??[],[x?.fields]),q=r.useMemo(()=>x?.relationships??[],[x?.relationships]),V=x?.singleton??!1,C=ra(),[I,Y]=r.useState(l?.title??t.title),[B,$]=r.useState(l?.slug??t.slug??""),[M,ee]=r.useState(l?.snippet??t.snippet??""),H=l?.autoSnippet??"",[G,J]=r.useState(l?.tags??t.tags??[]),[Q,fe]=r.useState(l?.cover??t.cover??null),[ie,pe]=r.useState(l?.body??{}),[le,be]=r.useState(l?.relationships??{}),[nt,it]=r.useState(0),[lt,rt]=r.useState(!1),[ct,ge]=r.useState(!1),[ot,oe]=r.useState(!1),[dt,xe]=r.useState(null),[Ve,ve]=r.useState(!1),[ut,je]=r.useState(!1),[ht,ye]=r.useState(!1),[ke,xs]=r.useState(""),[mt,_e]=r.useState(!1),[Be,vs]=r.useState(""),js=Wt(a,n),K=r.useCallback(()=>({title:I,slug:B,snippet:M,tags:G,cover:Q,body:ie,relationships:le,...h.sessionId?{sessionId:h.sessionId}:{}}),[I,B,M,G,Q,ie,le,h.sessionId]),ft=o.active?i=>{Y(i),o.updateField("title",i)}:i=>{Y(i),k.schedule({...K(),title:i})},pt=o.active?i=>{$(i),E(null),o.updateField("slug",i)}:i=>{$(i),E(null),k.schedule({...K(),slug:i})},bt=o.active?i=>{ee(i),o.updateField("snippet",i)}:i=>{ee(i),k.schedule({...K(),snippet:i})},gt=o.active?i=>{J(i),o.updateField("tags",i)}:i=>{J(i),k.schedule({...K(),tags:i})},ys=o.active?i=>{fe(i),o.updateField("cover",i)}:i=>{fe(i),k.schedule({...K(),cover:i})},xt=o.active?i=>{pe(i),o.updateField("body",i)}:i=>{pe(i),k.schedule({...K(),body:i})},vt=o.active?i=>{be(i),o.updateField("relationships",i)}:i=>{be(i),k.schedule({...K(),relationships:i})},Ce=o.active,we=o.setActiveField,Me=r.useCallback(i=>{Ce&&we(i)},[Ce,we]),He=r.useCallback(()=>{Ce&&we(null)},[Ce,we]);r.useEffect(()=>{if(o.active)return o.onRemoteFieldChange((i,D)=>{switch(i){case"title":Y(D);break;case"slug":$(D);break;case"snippet":ee(D);break;case"tags":J(D);break;case"cover":fe(D);break;case"body":pe(D);break;case"relationships":be(D);break}o.isLeader&&k.schedule(K())})},[o.active,o.onRemoteFieldChange,o.isLeader]);const ks=o.active?o.isLeader:!0;r.useEffect(()=>{if(!o.active||!ks)return;k.schedule(K());const i=window.setInterval(()=>{k.schedule(K())},1e4);return()=>window.clearInterval(i)},[ks,o.active]);const jt=k.lastSavedBlockId??l?.blockId,W=$a(t.publishedAt,t.lastPublishedAt,c,jt,t.scheduledAt,t.scheduledFailed),Se=Va(W),Ne=_a(W),{data:se}=Ms(a,n,!!t.publishedAt),X=r.useMemo(()=>{if(!Ve||!se)return null;const i=V?void 0:{title:se.title,slug:se.slug,snippet:se.snippet,tags:se.tags},D=q.map(z=>({name:z.name,label:z.label})),ae=se.relationships,De=D.length>0?{defs:D,values:ae??{}}:void 0,Rt=me(O,se.fields??{},i,De),At=V?void 0:{title:I,slug:B,snippet:M,tags:G},Et=D.length>0?{defs:D,values:le}:void 0,Tt=me(O,ie,At,Et),Ut=ya(Rt,Tt,{comparator:(z,Ye)=>z.text===Ye.text&&z.indent===Ye.indent&&z.type===Ye.type});let Ss=0,Ns=0;for(const z of Ut)z.added?Ss+=z.count??0:z.removed&&(Ns+=z.count??0);return{added:Ss,removed:Ns}},[Ve,se,O,q,V,I,B,M,G,ie,le]),[yt]=Vt(),kt=yt.get("from")==="recent"?`/sites/${a}/content`:`/sites/${a}/content/${s}`;va({title:V?x?.label??s:I||"Untitled",showBack:!V,backTo:V?void 0:kt,badge:{label:Se.label,variant:Se.variant}});function Pe(){if(o.active&&!o.isLeader){o.sendRequestPublish();return}if(t.publishedAt&&t.slug&&B!==t.slug){je(!0);return}W==="published-changes"?ve(!0):Je()}async function Je(){o.active&&o.isLeader&&o.sendPublishInProgress();try{await k.flush({createVersion:!0}),await m.mutateAsync(void 0),k.discard(),U.success("Content published"),o.active&&o.isLeader&&o.sendPublished({contentId:n})}catch(i){if(i instanceof Ee&&i.code==="SLUG_TAKEN"){E("This slug is already in use by another item in this collection"),U.error("Slug already in use",{description:"Please choose a different slug before publishing."});return}U.error("Failed to publish",{description:i instanceof Error?i.message:void 0})}finally{}}function Ct(){if(o.active&&!o.isLeader){o.sendRequestSaveVersion();return}k.flush({createVersion:!0})}r.useEffect(()=>{N.current=Pe,_.current=()=>{k.flush({createVersion:!0})}});async function wt(){try{await v.mutateAsync(),oe(!1),U.success("Content unpublished")}catch(i){U.error("Failed to unpublish",{description:i instanceof Error?i.message:void 0})}}async function St(){try{k.discard();const i=await f.apiFetch(`/v1/admin/sites/${a}/content/${n}/published`);await js.mutateAsync();const D={title:i.title??"",slug:i.slug??"",snippet:i.snippet??"",tags:i.tags??[],cover:i.cover??null,body:i.fields??{},relationships:i.relationships??{}};Y(D.title),$(D.slug),ee(D.snippet),J(D.tags),fe(D.cover),pe(D.body),be(D.relationships),it(ae=>ae+1),k.resetBaseline(D),U.success("Changes discarded")}catch(i){U.error("Failed to discard changes",{description:i instanceof Error?i.message:void 0})}}async function Nt(){try{await w.mutateAsync(),U.success("Content deleted"),d(`/sites/${a}/content/${s}`)}catch(i){U.error("Failed to delete",{description:i instanceof Error?i.message:void 0})}}async function Pt(){if(ke)try{await k.flush({createVersion:!0});const i=new Date(ke).getTime();await S.mutateAsync(i),ye(!1),xs(""),U.success("Content scheduled for publishing")}catch(i){U.error("Failed to schedule",{description:i instanceof Error?i.message:void 0})}}async function Dt(){try{await b.mutateAsync(),U.success("Schedule cancelled")}catch(i){U.error("Failed to cancel schedule",{description:i instanceof Error?i.message:void 0})}}async function Lt(){if(Be)try{const i=new Date(Be).getTime();await p.mutateAsync(i),_e(!1),U.success("Publish date updated")}catch(i){U.error("Failed to update publish date",{description:i instanceof Error?i.message:void 0})}}function ze(i){const D=new Date(i),ae=D.getTimezoneOffset();return new Date(D.getTime()-ae*6e4).toISOString().slice(0,16)}const Cs=e.jsx("div",{className:`space-y-6 ${g?"pointer-events-none opacity-60 select-none":""}`,"aria-readonly":g||void 0,children:O.length>0?e.jsx(Oa,{fields:O,values:ie,onChange:xt},nt):e.jsx(ue,{children:e.jsx(he,{className:"py-8 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No fields defined for this collection."," ",e.jsx(_t,{to:`/sites/${a}/settings/collections/${s}`,className:"underline",children:"Configure fields"})]})})})}),ws=e.jsxs("div",{className:`space-y-6 ${g?"pointer-events-none opacity-60 select-none":""}`,"aria-readonly":g||void 0,children:[!V&&e.jsx(ue,{children:e.jsxs(he,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Le,{htmlFor:"title",className:"flex items-center",children:["Title",e.jsx(Re,{field:"title",editors:o.editors})]}),e.jsx(Ps,{id:"title",value:I,onChange:i=>ft(i.target.value),onFocus:()=>Me("title"),onBlur:He})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Le,{htmlFor:"slug",className:"flex items-center",children:["Slug",e.jsx(Re,{field:"slug",editors:o.editors})]}),e.jsx(Ps,{id:"slug",value:B,onChange:i=>pt(i.target.value),onFocus:()=>Me("slug"),onBlur:He,className:F?"border-destructive":""}),F&&e.jsx("p",{className:"text-sm text-destructive",children:F})]}),e.jsxs(et,{defaultOpen:!!M,children:[e.jsxs(st,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(Xs,{className:"h-4 w-4 transition-transform [[data-state=open]>&]:rotate-90"}),"Snippet",e.jsx("span",{className:"text-xs text-muted-foreground",children:"(auto-generated if empty)"}),e.jsx(Re,{field:"snippet",editors:o.editors})]}),e.jsxs(tt,{className:"mt-2 space-y-2",children:[e.jsx(La,{id:"snippet",value:M,onChange:i=>bt(i.target.value),onFocus:()=>Me("snippet"),onBlur:He,rows:3,placeholder:"Brief summary of this content..."}),!M&&H&&e.jsxs("p",{className:"text-xs italic text-muted-foreground",children:["Auto-generated: ",H]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Le,{children:"Cover Image"}),Q?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>ge(!0),children:[e.jsx("img",{src:Ea(Q.url),alt:Q.alt??Q.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:Q.filename??Q.alt??Q.id}),e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:i=>{i.stopPropagation(),ys(null)},children:e.jsx(Ds,{className:"h-3 w-3"})})]}):e.jsxs(P,{type:"button",variant:"outline",className:"w-full",onClick:()=>ge(!0),children:[e.jsx(ca,{className:"mr-2 h-4 w-4"}),"Select Image"]}),e.jsx(Aa,{open:ct,onClose:()=>ge(!1),onSelect:i=>{ys({id:i.mediaId,url:i.url,width:i.width??0,height:i.height??0,alt:i.alt,caption:i.caption,filename:i.filename}),ge(!1)},allowedTypes:["image/*"]})]})]})}),!V&&e.jsxs(ue,{children:[e.jsx(Us,{children:e.jsxs(Fs,{className:"flex items-center",children:["Tags",e.jsx(Re,{field:"tags",editors:o.editors})]})}),e.jsx(he,{children:e.jsx(ga,{tags:G,onChange:gt,suggestions:j})})]}),q.length>0&&e.jsx(Ta,{relationships:q,values:le,onChange:vt,host:a}),e.jsxs(ue,{children:[e.jsx(Us,{children:e.jsx(Fs,{children:"Info"})}),e.jsxs(he,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Collection"}),e.jsx("span",{children:t.collection})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"ID"}),e.jsx("span",{className:"font-mono text-xs",children:t.contentId})]}),t.publishedAt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Published"}),mt?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"datetime-local",value:Be,onChange:i=>vs(i.target.value),className:"text-xs border rounded px-1 py-0.5",max:ze(Date.now())}),e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Lt,disabled:p.isPending,children:e.jsx(Ls,{className:"h-3 w-3"})}),e.jsx(P,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>_e(!1),children:e.jsx(Ds,{className:"h-3 w-3"})})]}):e.jsxs("span",{className:"cursor-pointer hover:underline",title:ne(t.publishedAt),onClick:()=>{vs(ze(t.publishedAt)),_e(!0)},children:[Qe(t.publishedAt),e.jsx(oa,{className:"inline ml-1 h-3 w-3 text-muted-foreground"})]})]}),t.lastPublishedAt&&t.lastPublishedAt!==t.publishedAt&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:ne(t.lastPublishedAt),children:Qe(t.lastPublishedAt)})]})]}):t.lastPublishedAt?e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:ne(t.lastPublishedAt),children:Qe(t.lastPublishedAt)})]}):null,W==="scheduled"&&t.scheduledAt&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Scheduled for"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Rs,{className:"h-3 w-3"}),ne(t.scheduledAt)]})]}),W==="schedule-failed"&&e.jsx("div",{className:"text-destructive text-xs",children:"Scheduled publishing failed after multiple attempts."}),t.publishedAt&&e.jsxs(P,{variant:"outline",size:"sm",className:"w-full mt-2",onClick:()=>{xe({kind:"published"}),oe(!0)},children:[e.jsx(da,{className:"mr-2 h-4 w-4"}),"View published"]})]})]}),e.jsx(kn,{host:a,contentId:n,onViewVersion:i=>{xe({kind:"history",blockId:i.blockId,createdAt:i.createdAt,title:i.title}),oe(!0)}}),!V&&e.jsx(yn,{deleteOpen:lt,setDeleteOpen:rt,onDelete:Nt,host:a,contentId:n})]});return e.jsx(qa.Provider,{value:o.active?o:null,children:e.jsxs("div",{className:"mx-auto max-w-6xl",children:[h.collaborationEnabled&&e.jsx("div",{className:"mb-3",children:e.jsx(bn,{status:o.status,editors:o.editors})}),g&&h.lockHolder&&e.jsx(rn,{lockHolder:h.lockHolder,onRequestCollaboration:()=>h.requestCollaboration.mutate(),isRequesting:h.requestCollaboration.isPending,requestSent:h.requestCollaboration.isSuccess}),g&&!h.lockHolder&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200 rounded-lg p-4 mb-4 flex items-center justify-between gap-3","data-testid":"lock-available-banner",children:[e.jsx("p",{className:"text-sm text-emerald-900",children:"Lock available — you can take over editing now."}),e.jsx(P,{size:"sm",onClick:()=>void h.takeEditing(),"data-testid":"take-editing-btn",children:"Take editing"})]}),e.jsx(cn,{open:h.status==="expired",lockHolder:h.lockHolder,takeoverReason:h.takeoverReason,currentUserSub:y?.sub??"",onRequestCollaboration:()=>{h.requestCollaboration.mutate(),h.dismissModal()},onViewReadOnly:()=>h.dismissModal()}),e.jsx(on,{open:h.status==="same-user-other-tab",onTakeOver:()=>void h.forceTakeover(),onCancel:()=>h.dismissModal()}),!C&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 md:mb-6 md:flex-nowrap md:gap-3 md:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 md:gap-3",children:[e.jsx("h1",{className:"truncate text-xl font-semibold md:text-2xl",children:V?x?.label??s:I||"Untitled"}),e.jsx(ua,{variant:Se.variant,children:Se.label}),k.isSaving&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(te,{className:"h-3 w-3 animate-spin"}),"Saving..."]}),!k.isSaving&&k.lastSavedAt&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ls,{className:"h-3 w-3"}),"Saved"]})]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsx(gn,{host:a,contentId:n,collaborationEnabled:h.collaborationEnabled,hasConnectedPeers:o.editors.length>0,isLockHolder:h.status==="acquired",sessionId:h.sessionId,onChange:i=>h.setCollaborationEnabled(i),onBeforeDisable:o.sendDisableCollab}),e.jsxs(P,{variant:"outline",size:"sm",onClick:Ct,disabled:k.isSaving||g,className:"px-3",children:[k.isSaving&&e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),"Save Draft"]}),W==="scheduled"&&e.jsxs(e.Fragment,{children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:Dt,disabled:b.isPending||g,className:"px-3",children:[b.isPending&&e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel Schedule"]}),e.jsxs(P,{size:"sm",onClick:Pe,disabled:m.isPending||R||g,className:"px-3",children:[(m.isPending||R)&&e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish Now"]})]}),W!=="scheduled"&&Ne&&e.jsxs("div",{className:"flex",children:[e.jsxs(P,{size:"sm",onClick:Pe,disabled:m.isPending||R||g,className:qe("px-3",!t.publishedAt&&"rounded-r-none"),children:[(m.isPending||R)&&e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),Ne]}),!t.publishedAt&&e.jsxs(As,{children:[e.jsx(Es,{asChild:!0,children:e.jsx(P,{size:"sm",className:"rounded-l-none border-l px-2",disabled:m.isPending||R||g,children:e.jsx(ha,{className:"h-4 w-4"})})}),e.jsx(Ts,{align:"end",children:e.jsxs(Ke,{onClick:()=>ye(!0),disabled:g,children:[e.jsx(Rs,{className:"mr-2 h-4 w-4"}),"Schedule for later"]})})]})]}),t.publishedAt&&e.jsxs(As,{children:[e.jsx(Es,{asChild:!0,children:e.jsx(P,{variant:"outline",size:"sm",className:"size-8 p-0",disabled:g,children:e.jsx(ma,{className:"h-4 w-4"})})}),e.jsxs(Ts,{align:"end",children:[W==="published-changes"&&e.jsxs(Ke,{onClick:St,disabled:js.isPending||g,children:[e.jsx(fa,{className:"mr-2 h-4 w-4"}),"Discard Changes"]}),e.jsx(Ke,{onClick:wt,className:"text-destructive focus:text-destructive",disabled:g,children:"Unpublish"})]})]})]})]}),C?e.jsxs(zs,{defaultValue:"content",children:[e.jsxs("div",{className:"mb-2 flex items-center",children:[e.jsxs(Ys,{variant:"line",children:[e.jsx(Te,{value:"content",children:"Content"}),e.jsx(Te,{value:"info",children:"Info"})]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>k.flush({createVersion:!0}),disabled:k.isSaving||g,children:[k.isSaving&&e.jsx(te,{className:"mr-1 h-3 w-3 animate-spin"}),"Save"]}),W!=="scheduled"&&Ne&&e.jsxs(P,{size:"sm",onClick:Pe,disabled:m.isPending||g,children:[m.isPending&&e.jsx(te,{className:"mr-1 h-3 w-3 animate-spin"}),Ne]})]})]}),e.jsx(Ue,{value:"content",className:"mt-0",children:Cs}),e.jsx(Ue,{value:"info",className:"mt-0",children:ws})]}):e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:Cs}),e.jsx("div",{children:ws})]}),e.jsx(un,{open:ot,onOpenChange:i=>{oe(i),i||xe(null)},host:a,contentId:n,collectionFields:O,isSingleton:V,isPublished:!!t.publishedAt,draftBody:ie,draftMetadata:V?void 0:{title:I,slug:B,snippet:M,tags:G},initialVersion:dt,collectionRelationships:q,draftRelationships:le}),e.jsx(ds,{open:Ve,onOpenChange:ve,children:e.jsxs(us,{children:[e.jsxs(hs,{children:[e.jsx(ms,{children:"Publish changes?"}),e.jsx(fs,{children:X?e.jsxs(e.Fragment,{children:[X.added>0&&e.jsxs("span",{className:"text-green-600",children:["+",X.added," added"]}),X.added>0&&X.removed>0&&", ",X.removed>0&&e.jsxs("span",{className:"text-red-600",children:["-",X.removed," removed"]}),X.added===0&&X.removed===0&&e.jsx("span",{children:"No visible changes detected."})]}):"This will update the published version with your current changes."})]}),e.jsx("div",{className:"mb-2",children:e.jsx(P,{variant:"link",className:"p-0 h-auto text-sm",onClick:()=>{ve(!1),xe({kind:"draft"}),oe(!0)},children:"View full diff"})}),e.jsxs(ps,{children:[e.jsx(Zs,{children:"Cancel"}),e.jsx(bs,{onClick:()=>{ve(!1),Je()},children:"Publish Update"})]})]})}),e.jsx(ss,{open:ut,onOpenChange:je,children:e.jsxs(ts,{children:[e.jsxs(as,{children:[e.jsx(ns,{children:"Slug change detected"}),e.jsxs(is,{children:["You are changing the slug from “",t.slug,"” to “",B,"”. This may break external bookmarks and SEO links."]})]}),e.jsx(jn,{host:a,contentId:n}),e.jsxs(ls,{children:[e.jsx(P,{variant:"outline",onClick:()=>je(!1),children:"Cancel"}),e.jsx(P,{onClick:()=>{je(!1),Je()},children:"Publish Anyway"})]})]})}),e.jsx(ss,{open:ht,onOpenChange:ye,children:e.jsxs(ts,{children:[e.jsxs(as,{children:[e.jsx(ns,{children:"Schedule publishing"}),e.jsx(is,{children:"Choose a date and time to automatically publish this content. Times are rounded to the nearest 15-minute interval."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Le,{htmlFor:"schedule-date",children:"Publish at"}),e.jsx("input",{id:"schedule-date",type:"datetime-local",value:ke,onChange:i=>xs(i.target.value),min:ze(Date.now()+1200*1e3),className:"w-full rounded-md border px-3 py-2 text-sm",step:"900"})]}),e.jsxs(ls,{children:[e.jsx(P,{variant:"outline",onClick:()=>ye(!1),children:"Cancel"}),e.jsxs(P,{onClick:Pt,disabled:!ke||S.isPending,children:[S.isPending&&e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),"Schedule"]})]})]})})]})})}function jn({host:a,contentId:s}){const{data:n}=Js(a,s,!0);return!n||n.count===0?null:e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-50 p-3 text-sm dark:bg-yellow-950/30",children:[e.jsxs("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:["This content is referenced by ",n.count," other"," ",n.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[n.items.slice(0,5).map(t=>e.jsxs("li",{children:[t.title," (",t.collection,")"]},`${t.contentId}-${t.fieldName}`)),n.items.length>5&&e.jsxs("li",{children:["and ",n.items.length-5," more..."]})]})]})}function yn({deleteOpen:a,setDeleteOpen:s,onDelete:n,host:t,contentId:l}){const{data:c}=Js(t,l,a);return e.jsxs(e.Fragment,{children:[e.jsx(Ks,{}),e.jsxs(ss,{open:a,onOpenChange:s,children:[e.jsx(pa,{asChild:!0,children:e.jsxs(P,{variant:"destructive",className:"w-full",children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(ts,{children:[e.jsxs(as,{children:[e.jsx(ns,{children:"Delete content?"}),e.jsx(is,{children:"This action cannot be undone. The content will be permanently deleted."})]}),c&&c.count>0&&e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-50 p-3 text-sm dark:bg-yellow-950/30",children:[e.jsxs("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:["This content is referenced by ",c.count," other"," ",c.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[c.items.slice(0,5).map(d=>e.jsxs("li",{children:[d.title," (",d.collection,")"]},`${d.contentId}-${d.fieldName}`)),c.items.length>5&&e.jsxs("li",{children:["and ",c.items.length-5," more..."]})]})]}),e.jsxs(ls,{children:[e.jsx(P,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(P,{variant:"destructive",onClick:n,children:"Delete"})]})]})]})]})}function kn({host:a,contentId:s,onViewVersion:n}){const{data:t}=Hs(a,s),[l,c]=r.useState(!1),d=t?.items??[],f=d.map(m=>m.createdBy).filter(Boolean),{resolve:u}=xa(f);return d.length===0?null:e.jsx(ue,{children:e.jsx(he,{className:"pt-4",children:e.jsxs(et,{open:l,onOpenChange:c,children:[e.jsxs(st,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(Xs,{className:qe("h-4 w-4 transition",l&&"rotate-90")}),"Version History (",d.length,")"]}),e.jsx(tt,{className:"mt-2",children:e.jsx("div",{className:"space-y-1",children:d.map((m,v)=>e.jsxs("button",{className:"py-1 text-sm hover:bg-muted rounded px-1 -mx-1 transition-colors w-full text-left",onClick:()=>n(m),children:[e.jsx("span",{children:ne(m.createdAt)}),m.createdBy&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:u(m.createdBy)}),m.title&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:m.title})]},`${m.createdAt}-${v}`))})})]})})})}export{Xn as ContentEditPage};
@@ -1 +0,0 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as Ce,f as ke,r as S}from"./react-vendor-C2CvUxFh.js";import{w as ye,x as Ae,B as R,P as ie,v as w,z as de,I as oe,X as B,A as Pe,L as z,j as T,S as Te,a as _e,y as Ie}from"./index-BA3y7HJs.js";import{d as $e,e as Fe,a as Ve,b as Be,c as De}from"./useContent-CW0tm0FY.js";import{u as Le}from"./useTags-ybsMbCst.js";import{u as Ue}from"./useContentSearch-_bwacEth.js";import{u as qe}from"./usePageTitle-DYvuJQp6.js";import{u as Me}from"./useFilterParams-DYdEuWPE.js";import{m as ue}from"./media-url-DIg_vSyf.js";import{u as Re,F as ze}from"./FilterBar-kFcOLffg.js";import{C as Oe,c as Ee}from"./card-CZTHR2Qa.js";import{C as Z}from"./checkbox-DEgzM8H9.js";import{P as He,a as We,b as Xe}from"./popover-BFw_h3j6.js";import{S as C,a as k,b as y,c as A,d as o}from"./select-dX9e6VDt.js";import{T as Ze,a as Ge,b as he,c as D,d as Qe,e as L}from"./table-Dk7eeOt2.js";import{a as I,f as xe}from"./format-C88SDH8g.js";import{g as me,a as ge}from"./contentStatus-CkPi9Dh6.js";import{B as Je}from"./BulkActionBar--35xjnOP.js";import{P as Ke}from"./Pagination-CuHwUPHi.js";import"./radix-C5ZmWuuL.js";import"./command-CdzYw11U.js";const O=3,fe=[{value:"updated_desc",label:"Last updated"},{value:"updated_asc",label:"Oldest updated"},{value:"title_asc",label:"Title A–Z",requiresCollection:!0},{value:"title_desc",label:"Title Z–A",requiresCollection:!0},{value:"created_desc",label:"Newest created"},{value:"created_asc",label:"Oldest created"}],G=[{value:"all",label:"All statuses"},{value:"draft",label:"Draft"},{value:"published",label:"Published"},{value:"changed",label:"Changed"},{value:"unpublished",label:"Unpublished"},{value:"scheduled",label:"Scheduled"}];function bs(){const{host:c,collection:r}=Ce(),_=ke(),{collections:pe}=ye(),[i,a]=Me([{key:"q",defaultValue:""},{key:"search",defaultValue:"prefix"},{key:"tag",defaultValue:""},{key:"status",defaultValue:""},{key:"sort",defaultValue:"updated_desc"},{key:"relatedTo",defaultValue:""},{key:"relField",defaultValue:""},{key:"page",defaultValue:"1"},{key:"perPage",defaultValue:"20"},{key:"after",defaultValue:""}]),$=i.search,x=i.tag||void 0,m=i.status||void 0,g=i.sort,j=i.relatedTo,v=i.relField,b=Number(i.page)||1,E=Number(i.perPage)||20,Q=S.useMemo(()=>{const e=i.after;return e?e.split(","):[]},[i.after]),[F,V]=S.useState(i.q),[u,t]=S.useState(new Set),H=Ae(),f=pe.find(e=>e.name===r),U=f?.relationships??[],{data:J}=Re(c,j||void 0),K=S.useMemo(()=>{if(!j||!v)return null;const e=U.find(n=>n.name===v);return{type:"relationship",relName:v,relLabel:e?.label??v,contentId:j,contentTitle:J??"Loading..."}},[j,v,U,J]);qe({title:f?.label??r??"",actions:f?.singleton?void 0:s.jsx(R,{size:"sm",onClick:()=>_(`/sites/${c}/content/${r}/new`),children:s.jsx(ie,{className:"h-4 w-4"})})});const h=Ue(F,300);S.useEffect(()=>{h!==i.q&&a({q:h})},[h,i.q,a]);const N=S.useCallback(()=>{a({page:"1",after:""}),t(new Set)},[a]),je=S.useMemo(()=>{const e={};return h&&(e.q=h,e.search=$),x&&(e.tag=x),m&&(e.status=m),g!=="updated_desc"&&(e.sort=g),j&&(e.relatedTo=j),v&&(e.relField=v),e.limit=E,e},[h,$,x,m,g,j,v,E]),ve=b>1?Q[b-2]:void 0,{data:P,isLoading:be}=$e(c,r,je,ve),W=Fe(c),Y=Ve(c),ee=Be(c),se=De(c),{data:ae}=Le(c),q=S.useMemo(()=>ae?.map(e=>e.tag)??[],[ae]);if(f?.singleton&&P?.items.length===1)return _(`/sites/${c}/content/${r}/${P.items[0].contentId}`,{replace:!0}),null;const M=P?.items,X=M?.map(e=>e.contentId)??[],te=X.length>0&&X.every(e=>u.has(e));function le(e){t(n=>{const l=new Set(n);return l.has(e)?l.delete(e):l.add(e),l})}function Ne(){t(te?new Set:new Set(X))}const ne=!!(h||x||m||j),re=!!h,ce=[$!=="prefix"?1:0,x?1:0,m?1:0,g!=="updated_desc"?1:0].reduce((e,n)=>e+n,0),Se=Y.isPending||ee.isPending||se.isPending;async function we(){try{const e=await W.mutateAsync({collection:r,title:f?.label??r});w.success("Singleton content recreated"),_(`/sites/${c}/content/${r}/${e.contentId}`)}catch(e){w.error("Failed to recreate singleton",{description:e instanceof Error?e.message:void 0})}}return s.jsxs("div",{children:[!H&&s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:f?.label??r}),!f?.singleton&&s.jsxs(R,{onClick:()=>_(`/sites/${c}/content/${r}/new`),children:[s.jsx(ie,{className:"mr-2 h-4 w-4"}),"New"]})]}),u.size>0?s.jsx(Je,{selectedCount:u.size,onPublish:async()=>{const e=[...u],l=(await Y.mutateAsync(e)).filter(d=>d.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to publish`):w.success(`${e.length} item(s) published`),N()},onUnpublish:async()=>{const e=[...u],l=(await ee.mutateAsync(e)).filter(d=>d.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to unpublish`):w.success(`${e.length} item(s) unpublished`),N()},onDelete:async()=>{const e=[...u],l=(await se.mutateAsync(e)).filter(d=>d.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to delete`):w.success(`${e.length} item(s) deleted`),N()},onClear:()=>t(new Set),isPending:Se}):H?s.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(de,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),s.jsx(oe,{placeholder:"Search...",value:F,onChange:e=>{V(e.target.value),N()},className:"pl-8 pr-8"}),F&&s.jsx("button",{onClick:()=>{V(""),N()},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:s.jsx(B,{className:"h-4 w-4"})})]}),s.jsxs(He,{children:[s.jsx(We,{asChild:!0,children:s.jsxs(R,{variant:"outline",size:"icon",className:"relative shrink-0","aria-label":"Filters",children:[s.jsx(Pe,{className:"h-4 w-4"}),ce>0&&s.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] text-primary-foreground",children:ce})]})}),s.jsxs(Xe,{className:"w-64 space-y-3",align:"end",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(z,{className:"text-xs font-medium",children:"Search Mode"}),s.jsxs(C,{value:$,onValueChange:e=>{a({search:e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{children:s.jsx(y,{})}),s.jsxs(A,{children:[s.jsx(o,{value:"prefix",children:"Starts with"}),s.jsx(o,{value:"full",children:"Contains"})]})]})]}),q.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(z,{className:"text-xs font-medium",children:"Tag"}),s.jsxs(C,{value:x??"__all__",onValueChange:e=>{a({tag:e==="__all__"?"":e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{children:s.jsx(y,{})}),s.jsxs(A,{children:[s.jsx(o,{value:"__all__",children:"All tags"}),q.map(e=>s.jsx(o,{value:e,children:e},e))]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(z,{className:"text-xs font-medium",children:"Status"}),s.jsxs(C,{value:m??"all",onValueChange:e=>{a({status:e==="all"?"":e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{children:s.jsx(y,{})}),s.jsx(A,{children:G.map(e=>s.jsx(o,{value:e.value??"all",children:e.label},e.value??"all"))})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(z,{className:"text-xs font-medium",children:"Sort"}),s.jsxs(C,{value:g,onValueChange:e=>{a({sort:e,page:"1",after:""}),t(new Set)},disabled:re,children:[s.jsx(k,{children:s.jsx(y,{})}),s.jsx(A,{children:fe.map(e=>s.jsx(o,{value:e.value,disabled:e.requiresCollection&&!r,children:e.label},e.value))})]})]})]})]})]}):s.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"relative flex items-center",children:[s.jsx(de,{className:"absolute left-2.5 h-4 w-4 text-muted-foreground"}),s.jsx(oe,{placeholder:"Search titles...",value:F,onChange:e=>{V(e.target.value),N()},className:"w-56 pl-8 pr-8"}),F&&s.jsx("button",{onClick:()=>{V(""),N()},className:"absolute right-2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{className:"h-4 w-4"})})]}),s.jsxs(C,{value:$,onValueChange:e=>{a({search:e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{className:"w-[130px]",children:s.jsx(y,{})}),s.jsxs(A,{children:[s.jsx(o,{value:"prefix",children:"Starts with"}),s.jsx(o,{value:"full",children:"Contains"})]})]}),q.length>0&&s.jsxs(C,{value:x??"__all__",onValueChange:e=>{a({tag:e==="__all__"?"":e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{className:"w-[140px]",children:s.jsx(y,{placeholder:"Tag"})}),s.jsxs(A,{children:[s.jsx(o,{value:"__all__",children:"All tags"}),q.map(e=>s.jsx(o,{value:e,children:e},e))]})]}),s.jsxs(C,{value:m??"all",onValueChange:e=>{a({status:e==="all"?"":e,page:"1",after:""}),t(new Set)},children:[s.jsx(k,{className:"w-[150px]",children:s.jsx(y,{})}),s.jsx(A,{children:G.map(e=>s.jsx(o,{value:e.value??"all",children:e.label},e.value??"all"))})]}),s.jsx("div",{className:"ml-auto",children:s.jsxs(C,{value:g,onValueChange:e=>{a({sort:e,page:"1",after:""}),t(new Set)},disabled:re,children:[s.jsx(k,{className:"w-[170px]",children:s.jsx(y,{})}),s.jsx(A,{children:fe.map(e=>s.jsx(o,{value:e.value,disabled:e.requiresCollection&&!r,children:e.label},e.value))})]})})]}),U.length>0&&s.jsx("div",{className:"mb-3",children:s.jsx(ze,{relationships:U,activeFilters:K?[K]:[],onFilterAdd:e=>{a({relatedTo:e.contentId,relField:e.relName,page:"1",after:""}),t(new Set)},onFilterRemove:()=>{a({relatedTo:"",relField:"",page:"1",after:""}),t(new Set)}})}),ne&&u.size===0&&s.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[h&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Search: ",h,s.jsx("button",{onClick:()=>{V(""),N()},children:s.jsx(B,{className:"h-3 w-3"})})]}),x&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Tag: ",x,s.jsx("button",{onClick:()=>{a({tag:"",page:"1",after:""}),t(new Set)},children:s.jsx(B,{className:"h-3 w-3"})})]}),m&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Status: ",G.find(e=>e.value===m)?.label,s.jsx("button",{onClick:()=>{a({status:"",page:"1",after:""}),t(new Set)},children:s.jsx(B,{className:"h-3 w-3"})})]})]}),be?s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,n)=>s.jsx(Te,{className:"h-12 w-full"},n))}):M?.length?s.jsxs(s.Fragment,{children:[H?s.jsx("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"content-card-view",children:M.map(e=>{const n=me(e.publishedAt,e.lastPublishedAt,e.publishedBlockId,e.lastDraftBlockId,e.scheduledAt,e.scheduledFailed),l=ge(n),d=e.tags??[];return s.jsx(Oe,{className:Ie("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",u.has(e.contentId)&&"ring-2 ring-primary"),onClick:()=>_(`/sites/${c}/content/${r}/${e.contentId}`),children:s.jsxs(Ee,{className:"p-3",children:[s.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.cover?.url&&s.jsx("img",{src:ue(e.cover.url),alt:e.cover.alt??"",className:"h-12 w-12 rounded object-cover flex-shrink-0"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"font-medium truncate",children:e.draftTitle||e.title||"Untitled"}),s.jsx(T,{variant:l.variant,className:"shrink-0",children:l.label})]}),(e.draftSlug||e.slug)&&s.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["/",e.draftSlug||e.slug]}),s.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:g.startsWith("created")?e.createdAt?I(e.createdAt):"—":e.lastDraftAt?I(e.lastDraftAt):"—"})]}),s.jsx(Z,{checked:u.has(e.contentId),onCheckedChange:()=>le(e.contentId),onClick:p=>p.stopPropagation(),className:"mt-1"})]}),d.length>0&&s.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:d.slice(0,O).map(p=>s.jsx(T,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:p},p))})]})},e.contentId)})}):s.jsxs(Ze,{children:[s.jsx(Ge,{children:s.jsxs(he,{children:[s.jsx(D,{className:"w-10",children:s.jsx(Z,{checked:te,onCheckedChange:Ne,"aria-label":"Select all"})}),s.jsx(D,{children:"Title"}),s.jsx(D,{children:"Slug"}),s.jsx(D,{children:"Status"}),s.jsx(D,{children:g.startsWith("created")?"Created":"Updated"})]})}),s.jsx(Qe,{children:M.map(e=>{const n=me(e.publishedAt,e.lastPublishedAt,e.publishedBlockId,e.lastDraftBlockId),l=ge(n),d=e.tags??[];return s.jsxs(he,{className:"cursor-pointer",onClick:()=>_(`/sites/${c}/content/${r}/${e.contentId}`),children:[s.jsx(L,{onClick:p=>p.stopPropagation(),children:s.jsx(Z,{checked:u.has(e.contentId),onCheckedChange:()=>le(e.contentId),"aria-label":`Select ${e.draftTitle||e.title||"Untitled"}`})}),s.jsx(L,{className:"font-medium",children:s.jsxs("div",{className:"flex items-center gap-3",children:[e.cover?.url&&s.jsx("img",{src:ue(e.cover.url),alt:e.cover.alt??"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("span",{children:e.draftTitle||e.title||"Untitled"}),d.length>0&&s.jsxs("div",{className:"mt-0.5 flex flex-wrap gap-1",children:[d.slice(0,O).map(p=>s.jsx(T,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal text-muted-foreground",children:p},p)),d.length>O&&s.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",d.length-O," more"]})]})]})]})}),s.jsx(L,{className:"text-muted-foreground text-sm",children:e.draftSlug||e.slug||"—"}),s.jsx(L,{children:s.jsx(T,{variant:l.variant,children:l.label})}),s.jsx(L,{className:"text-muted-foreground",children:g.startsWith("created")?e.createdAt?I(e.createdAt):"—":e.scheduledAt&&!e.publishedAt?s.jsxs("span",{title:xe(e.scheduledAt),children:["Scheduled ",I(e.scheduledAt)]}):e.publishedAt?s.jsx("span",{title:xe(e.publishedAt),children:I(e.publishedAt)}):e.lastDraftAt?I(e.lastDraftAt):"—"})]},e.contentId)})})]}),s.jsx(Ke,{page:b,hasNext:!!P?.hasMore,hasPrevious:b>1,onNext:()=>{if(P?.items.length){const e=P.items[P.items.length-1].contentId,n=[...Q.slice(0,b-1),e];a({page:String(b+1),after:n.join(",")})}else a({page:String(b+1)});t(new Set)},onPrevious:()=>{const e=b-1;a(e<=1?{page:"1",after:""}:{page:String(e)}),t(new Set)},perPage:E,onPerPageChange:e=>{a({perPage:String(e),page:"1",after:""}),t(new Set)}})]}):f?.singleton?s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-muted-foreground",children:"Singleton content is missing. Click below to recreate it."}),s.jsxs(R,{onClick:we,disabled:W.isPending,children:[W.isPending&&s.jsx(_e,{className:"mr-2 h-4 w-4 animate-spin"}),"Recreate ",f.label]})]}):s.jsx("p",{className:"text-muted-foreground",children:ne?"No content matches the current filters.":"No content yet."})]})}export{bs as ContentListPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlockEditor-ClskiZoX.js","assets/tanstack-Bs3zYPPV.js","assets/react-vendor-C2CvUxFh.js","assets/index-BA3y7HJs.js","assets/radix-C5ZmWuuL.js","assets/index-c7UygSvP.css","assets/yjs-tXBm_srz.js","assets/command-CdzYw11U.js","assets/MediaField-B-Cz8TlK.js","assets/useMedia-Cu5N4rY8.js","assets/select-dX9e6VDt.js","assets/card-CZTHR2Qa.js","assets/media-url-DIg_vSyf.js","assets/CustomBlockPreview-Cs9bFDh4.js","assets/ContentField-D04Uo1Ov.js","assets/core.esm-DdQHdRkd.js","assets/sortable.esm-qVEMoaTg.js","assets/popover-BFw_h3j6.js","assets/useContentSearch-_bwacEth.js","assets/BlockEditor-CQpF8tYb.css"])))=>i.map(i=>d[i]);
2
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{I as b,B as g,P as A,ai as I,T as B,aJ as _,x as z,S as E,aK as L,y,Y as P,Z as w,_ as D,L as M}from"./index-BA3y7HJs.js";import{T as q}from"./textarea-CpDSUg2s.js";import{C as R}from"./checkbox-DEgzM8H9.js";import{S as $,a as O,b as V,c as K,d as U}from"./select-dX9e6VDt.js";import{a as G}from"./MediaField-B-Cz8TlK.js";import{b as H,c as J,P as X,D as Y,e as Z,C as Q}from"./core.esm-DdQHdRkd.js";import{S as W,v as ee,a as te,u as se}from"./sortable.esm-qVEMoaTg.js";import{C,c as v}from"./card-CZTHR2Qa.js";import{r as x}from"./react-vendor-C2CvUxFh.js";import{C as re}from"./ContentField-D04Uo1Ov.js";import{K as ae,M as ne}from"./radix-C5ZmWuuL.js";function j({field:s,value:t,onChange:r}){const a=s.options;return e.jsx(b,{value:t??"",onChange:n=>r(n.target.value),placeholder:a?.placeholder,maxLength:a?.maxLength,required:!!a?.required,type:s.type==="url"?"url":s.type==="email"?"email":"text"})}function oe({field:s,value:t,onChange:r}){const a=s.options;return e.jsx(q,{value:t??"",onChange:n=>r(n.target.value),placeholder:a?.placeholder,maxLength:a?.maxLength,required:!!a?.required,rows:4})}function ie({field:s,value:t,onChange:r}){const a=s.options;return e.jsx(b,{type:"number",value:t??"",onChange:n=>r(n.target.value===""?void 0:Number(n.target.value)),min:a?.min,max:a?.max,step:a?.step,required:!!a?.required})}function ce({field:s,value:t,onChange:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{id:`field-${s.name}`,checked:!!t,onCheckedChange:a=>r(!!a)}),e.jsx("label",{htmlFor:`field-${s.name}`,className:"text-sm text-muted-foreground",children:s.label})]})}function le({field:s,value:t,onChange:r}){const n=s.options?.choices??[];return e.jsxs($,{value:t??"",onValueChange:i=>r(i),children:[e.jsx(O,{children:e.jsx(V,{placeholder:"Select..."})}),e.jsx(K,{children:n.map(i=>e.jsx(U,{value:i,children:i},i))})]})}function de({field:s,value:t,onChange:r}){const a=H(J(X)),n=Array.isArray(t)?t:[],d=s.options?.itemFields??[],o=n.map((u,c)=>`item-${c}`);function m(){r([...n,{}])}function p(u){r(n.filter((c,l)=>l!==u))}function h(u,c){const l=[...n];l[u]=c,r(l)}function N(u){const{active:c,over:l}=u;if(l&&c.id!==l.id){const k=o.indexOf(String(c.id)),T=o.indexOf(String(l.id));r(te(n,k,T))}}return e.jsx(Y,{sensors:a,collisionDetection:Z,onDragEnd:N,children:e.jsx(W,{items:o,strategy:ee,children:e.jsxs("div",{className:"space-y-3",children:[n.map((u,c)=>e.jsx(me,{id:`item-${c}`,itemFields:d,item:u,onUpdate:l=>h(c,l),onRemove:()=>p(c)},`item-${c}`)),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:m,children:[e.jsx(A,{className:"mr-2 h-3 w-3"})," Add Item"]})]})})})}function me({id:s,itemFields:t,item:r,onUpdate:a,onRemove:n}){const{attributes:i,listeners:d,setNodeRef:o,transform:m,transition:p}=se({id:s}),h={transform:Q.Transform.toString(m),transition:p};return e.jsx(C,{ref:o,style:h,children:e.jsxs(v,{className:"flex gap-2 p-3",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...i,...d,children:e.jsx(I,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(F,{fields:t,values:r,onChange:a})}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"text-destructive",children:e.jsx(B,{className:"h-3 w-3"})})]})})}const ue=x.createContext(null);function S(){return x.useContext(ue)}const xe=x.lazy(()=>L(()=>import("./BlockEditor-ClskiZoX.js").then(s=>s.a),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]))),pe=2,f=x.createContext(0);function he({field:s,value:t,onChange:r,compact:a=!0}){const n=x.useContext(f),d=_()?.blockTypes??[],o=z(),p=S()?.getBlockNoteCollab(s.name);return n>=pe?e.jsx("div",{className:"rounded-md border border-muted p-4 text-sm text-muted-foreground",children:"Maximum nesting depth reached. Cannot embed another block editor here."}):e.jsx(f.Provider,{value:n+1,children:e.jsx("div",{className:o?"":"rounded-md border",children:e.jsx(x.Suspense,{fallback:e.jsx(E,{className:"h-48"}),children:e.jsx(xe,{initialBlocks:Array.isArray(t)?t:[],onChange:r,blockTypes:d,compact:a,collaboration:p})})})})}function je({field:s,value:t,onChange:r}){const n=s.options?.fields??[],i=t&&typeof t=="object"&&!Array.isArray(t)?t:{};return e.jsx(C,{children:e.jsx(v,{className:"p-3",children:e.jsx(F,{fields:n,values:i,onChange:d=>r(d)})})})}function fe({className:s,size:t="default",...r}){return e.jsx(ae,{"data-slot":"avatar","data-size":t,className:y("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6",s),...r})}function be({className:s,...t}){return e.jsx(ne,{"data-slot":"avatar-fallback",className:y("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs",s),...t})}function ge(s){const t=s.trim().split(/\s+/).filter(Boolean);return t.length>=2?(t[0][0]+t[1][0]).toUpperCase():(t[0]?.[0]??"?").toUpperCase()}function ye({field:s,editors:t}){const r=t.filter(a=>a.activeField===s);return r.length===0?null:e.jsx("span",{className:"inline-flex items-center -space-x-1 ml-2 align-middle","data-testid":"field-presence-indicator",children:r.map(a=>e.jsxs(P,{children:[e.jsx(w,{asChild:!0,children:e.jsx(fe,{className:"h-4 w-4 border-2 ring-1 ring-background",style:{borderColor:a.color},"aria-label":`${a.name} is editing`,children:e.jsx(be,{className:"text-[8px] font-medium",style:{backgroundColor:a.color+"20",color:a.color},children:ge(a.name)})})}),e.jsxs(D,{children:[a.name," is editing"]})]},a.sub))})}function F({fields:s,values:t,onChange:r}){const a=S();function n(o,m){r({...t,[o]:m})}function i(o){a?.setActiveField(o)}function d(o){o.currentTarget.contains(o.relatedTarget)||a?.setActiveField(null)}return e.jsx("div",{className:"space-y-4",children:s.map(o=>e.jsxs("div",{className:"space-y-2",onFocusCapture:()=>i(o.name),onBlurCapture:d,children:[o.type!=="boolean"&&e.jsxs(M,{className:"flex items-center",children:[o.label,a&&e.jsx(ye,{field:o.name,editors:a.editors})]}),Ce(o,t[o.name],m=>n(o.name,m))]},o.name))})}function Ce(s,t,r){switch(s.type){case"text":case"url":case"email":return e.jsx(j,{field:s,value:t,onChange:r});case"textarea":return e.jsx(oe,{field:s,value:t,onChange:r});case"number":return e.jsx(ie,{field:s,value:t,onChange:r});case"boolean":return e.jsx(ce,{field:s,value:t,onChange:r});case"select":return e.jsx(le,{field:s,value:t,onChange:r});case"media":return e.jsx(G,{field:s,value:t,onChange:r});case"content":return e.jsx(re,{field:s,value:t,onChange:r});case"blocks":return e.jsx(he,{field:s,value:t,onChange:r});case"array":return e.jsx(de,{field:s,value:t,onChange:r});case"container":return e.jsx(je,{field:s,value:t,onChange:r});case"date":return e.jsx(j,{field:{...s,type:"text"},value:t,onChange:r});default:return e.jsx(j,{field:s,value:t,onChange:r})}}export{fe as A,ue as C,F,be as a,ye as b,ge as i};
@@ -1 +0,0 @@
1
- import{u as N,j as e}from"./tanstack-Bs3zYPPV.js";import{u as v,r as h}from"./react-vendor-C2CvUxFh.js";import{e as w,j as x,X as y,a6 as S,a7 as F,B as p,ba as j,a9 as R,aa as I,ad as P}from"./index-BA3y7HJs.js";import{P as T,a as L,b as D}from"./popover-BFw_h3j6.js";import{C as B,a as M,b as $,c as k,d as q,e as E}from"./command-CdzYw11U.js";import{u as Q,a as z}from"./useContentSearch-_bwacEth.js";function H({relationships:s,activeFilters:a,onFilterAdd:o,onFilterRemove:i}){const{host:u}=v(),[l,c]=h.useState(null),[d,r]=h.useState(""),n=Q(d,300);if(s.length===0)return null;const g=new Set(a.map(t=>t.relName)),m=s.filter(t=>!g.has(t.name));function C(t){c(t),r("")}function f(t){l&&(o({type:"relationship",relName:l.name,relLabel:l.label,contentId:t.contentId,contentTitle:t.title}),c(null),r(""))}function b(){c(null),r("")}return e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-testid":"filter-bar",children:[a.map(t=>e.jsxs(x,{variant:"secondary",className:"gap-1 pl-2",children:[t.relLabel,": ",t.contentTitle,e.jsx("button",{onClick:()=>i(t.relName),className:"ml-0.5 hover:text-foreground","aria-label":`Remove ${t.relLabel} filter`,children:e.jsx(y,{className:"h-3 w-3"})})]},t.relName)),m.length>0&&(l?e.jsx(A,{host:u,rel:l,query:d,debouncedQuery:n,onQueryChange:r,onSelect:f,onClose:b}):e.jsxs(S,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm","data-testid":"add-filter-button",children:[e.jsx(j,{className:"mr-1.5 h-3.5 w-3.5"}),"Add filter"]})}),e.jsx(R,{align:"start",children:m.map(t=>e.jsx(I,{onSelect:()=>C(t),children:t.label},t.name))})]}))]})}function A({host:s,rel:a,query:o,debouncedQuery:i,onQueryChange:u,onSelect:l,onClose:c}){const{data:d,isLoading:r}=z(s,i,[a.targetCollection],"published");return e.jsxs(T,{open:!0,onOpenChange:n=>{n||c()},children:[e.jsx(L,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm",children:[e.jsx(j,{className:"mr-1.5 h-3.5 w-3.5"}),a.label,"..."]})}),e.jsx(D,{className:"w-80 p-0",align:"start",children:e.jsxs(B,{shouldFilter:!1,children:[e.jsx(M,{placeholder:`Search ${a.label.toLowerCase()}...`,value:o,onValueChange:u,autoFocus:!0}),e.jsx($,{children:r?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(k,{children:"No published content found."}),e.jsx(q,{heading:i.length===0?"Recent":void 0,children:d?.items.map(n=>e.jsxs(E,{value:n.contentId,onSelect:()=>l({contentId:n.contentId,collection:n.collection,slug:n.slug??"",title:n.title}),children:[e.jsx(P,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:n.title}),e.jsx(x,{variant:"outline",className:"text-xs",children:n.collection})]},n.contentId))})]})})]})})]})}function J(s,a){const o=w();return N({queryKey:["sites",s,"content-detail",a,"filter-title"],queryFn:async()=>(await o.apiFetch(`/v1/admin/sites/${s}/content/${a}`)).content?.title||"Untitled",enabled:!!s&&!!a,staleTime:6e4})}export{H as F,J as u};
@@ -1 +0,0 @@
1
- import{t as c,N as m,v as s,z as d,B as f,G as u,X as b,K as g,w as h,M as x,P as v,U as C,o as j,s as y,f as O,W as P}from"./BlockEditor-ClskiZoX.js";import{r as I}from"./react-vendor-C2CvUxFh.js";import{j as r}from"./tanstack-Bs3zYPPV.js";import"./index-BA3y7HJs.js";import"./radix-C5ZmWuuL.js";import"./yjs-tXBm_srz.js";import"./command-CdzYw11U.js";import"./MediaField-B-Cz8TlK.js";import"./useMedia-Cu5N4rY8.js";import"./select-dX9e6VDt.js";import"./card-CZTHR2Qa.js";import"./media-url-DIg_vSyf.js";import"./FieldRenderer-wE-mtqZB.js";import"./textarea-CpDSUg2s.js";import"./checkbox-DEgzM8H9.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./ContentField-D04Uo1Ov.js";import"./popover-BFw_h3j6.js";import"./useContentSearch-_bwacEth.js";import"./CustomBlockPreview-Cs9bFDh4.js";function S(){let o=m(s),t=d(),n=f(),e=u({trailingBlock:!1,dictionary:{...n,placeholders:{emptyDocument:n.placeholders.new_comment}},schema:o.commentEditorSchema||b});return r.jsx(t.Comments.Card,{className:"bn-thread",children:r.jsx(g,{autoFocus:!0,editable:!0,editor:e,actions:({isEmpty:a})=>r.jsx(t.Generic.Toolbar.Root,{className:h("bn-action-toolbar","bn-comment-actions"),variant:"action-toolbar",children:r.jsx(t.Generic.Toolbar.Button,{className:"bn-button",mainTooltip:"Save",variant:"compact",isDisabled:a,onClick:async()=>{await o.createThread({initialComment:{body:e.document}}),o.stopPendingComment()},children:"Save"})})})})}var L=c({default:()=>U});function U(o){let t=x(),n=m(s),e=v(s,{editor:t,selector:i=>i.pendingComment}),a=C({editor:t,selector:({editor:i})=>e?{from:i.prosemirrorState.selection.from,to:i.prosemirrorState.selection.to}:void 0}),p=I.useMemo(()=>({...o.floatingUIOptions,useFloatingOptions:{open:!!e,onOpenChange:i=>{i||(n.stopPendingComment(),t.focus())},placement:"bottom",middleware:[j(10),y(),O()],...o.floatingUIOptions?.useFloatingOptions},focusManagerProps:{disabled:!1},elementProps:{style:{zIndex:60},...o.floatingUIOptions?.elementProps}}),[n,t,e,o.floatingUIOptions]),l=o.floatingComposer||S;return r.jsx(P,{position:a,...p,children:r.jsx(l,{})})}export{L as n,S as r,U as t};
@@ -1,3 +0,0 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as j}from"./react-vendor-C2CvUxFh.js";import{C as z,b as A,c as R,P as U,D as q,e as V}from"./core.esm-DdQHdRkd.js";import{u as $,S as G,v as H,a as _}from"./sortable.esm-qVEMoaTg.js";import{I as x,y as F,aJ as J,L as o,ai as K,a0 as W,B as S,T as Y,P as Z,aL as T,aE as L}from"./index-BA3y7HJs.js";import{S as P,a as B,b as M,c as O,d as D}from"./select-dX9e6VDt.js";import{d as E,i as Q}from"./format-C88SDH8g.js";import{C as X,a as ee,b as ae}from"./collapsible-D3d29uJp.js";import{C as y}from"./checkbox-DEgzM8H9.js";import{T as se}from"./textarea-CpDSUg2s.js";import{P as te,a as le,b as ne}from"./popover-BFw_h3j6.js";function re({value:t,onChange:s,onBlur:u,readOnly:m,className:l,...a}){const[n,r]=j.useState(!1),p=j.useRef(void 0);j.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const v=j.useCallback(g=>{const N=g.target.value,f=E(N,"leading");s(f),N!==f&&N.length>0?(r(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>r(!1),2e3)):r(!1)},[s]),C=j.useCallback(()=>{const g=E(t,"all");g!==t&&s(g),u?.()},[t,s,u]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{value:t,onChange:v,onBlur:C,disabled:m,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:F("font-mono",l),...a}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function ce({type:t,options:s,onChange:u}){const m=J();function l(a,n){u({...s,[a]:n})}return e.jsxs("div",{className:"space-y-3",children:[!["boolean","blocks","array","container"].includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-required",checked:!!s.required,onCheckedChange:a=>l("required",!!a)}),e.jsx(o,{htmlFor:"opt-required",className:"text-sm",children:"Required"})]}),["text","textarea"].includes(t)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Placeholder"}),e.jsx(x,{value:s.placeholder??"",onChange:a=>l("placeholder",a.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Length"}),e.jsx(x,{type:"number",value:s.maxLength??"",onChange:a=>l("maxLength",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="number"&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Min"}),e.jsx(x,{type:"number",value:s.min??"",onChange:a=>l("min",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max"}),e.jsx(x,{type:"number",value:s.max??"",onChange:a=>l("max",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Step"}),e.jsx(x,{type:"number",value:s.step??"",onChange:a=>l("step",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="select"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(se,{value:(s.choices??[]).join(`
2
- `),onChange:a=>l("choices",a.target.value.split(`
3
- `).map(n=>n.trim()).filter(Boolean)),rows:4,className:"text-sm"})]}),t==="media"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Types (e.g., image/*, video/*)"}),e.jsx(x,{value:(s.allowedTypes??[]).join(", "),onChange:a=>l("allowedTypes",a.target.value.split(",").map(n=>n.trim()).filter(Boolean)),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Folder"}),e.jsx(x,{value:s.folder??"",onChange:a=>l("folder",a.target.value||void 0),placeholder:"e.g., submissions/photos",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Accept (MIME filter)"}),e.jsx(x,{value:s.accept??"",onChange:a=>l("accept",a.target.value||void 0),placeholder:"e.g., image/*",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Size (bytes)"}),e.jsx(x,{type:"number",value:s.maxSize??"",onChange:a=>l("maxSize",a.target.value?Number(a.target.value):void 0),placeholder:"5242880 (5MB)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-media-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-media-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="content"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Collections"}),m&&m.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:m.collections.map(a=>{const n=s.collections??[],r=n.includes(a.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(y,{id:`col-${a.name}`,checked:r,onCheckedChange:p=>{p?l("collections",[...n,a.name]):l("collections",n.filter(v=>v!==a.name))}}),e.jsx(o,{htmlFor:`col-${a.name}`,className:"text-xs font-normal",children:a.label||a.name})]},a.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(x,{value:(s.collections??[]).join(", "),onChange:a=>l("collections",a.target.value.split(",").map(n=>n.trim()).filter(Boolean)),placeholder:"Comma-separated, leave empty for all",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="container"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Fields"}),e.jsx(I,{fields:s.fields??[],onChange:a=>l("fields",a),excludeTypes:["container","blocks"]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Item Fields"}),e.jsx(I,{fields:s.itemFields??[],onChange:a=>l("itemFields",a),excludeTypes:["array","container"]})]})]})}const w=[{value:"text",label:"Text"},{value:"textarea",label:"Textarea"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"select",label:"Select"},{value:"url",label:"URL"},{value:"email",label:"Email"},{value:"date",label:"Date"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"},{value:"container",label:"Container"}];function ie({id:t,field:s,onChange:u,onRemove:m,excludeTypes:l,readOnlyName:a,defaultExpanded:n}){const[r,p]=j.useState(n??!1),[v,C]=j.useState(!!s.label),{attributes:g,listeners:N,setNodeRef:f,transform:k,transition:c}=$({id:t}),d=l?w.filter(i=>!l.includes(i.value)):w,h={transform:z.Transform.toString(k),transition:c};function b(i){u({...s,...i})}return e.jsx("div",{ref:f,style:h,className:"rounded-md border bg-card",children:e.jsxs(X,{open:r,onOpenChange:p,children:[e.jsxs("div",{className:"flex items-center gap-2 p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...g,...N,children:e.jsx(K,{className:"h-4 w-4"})}),e.jsx(ee,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(W,{className:F("h-4 w-4 transition-transform",r&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:m,className:"text-destructive",children:e.jsx(Y,{className:"h-3 w-3"})})]}),e.jsx(ae,{children:e.jsxs("div",{className:"space-y-3 border-t p-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(re,{value:s.name,onChange:i=>b({name:i}),onBlur:()=>{s.name&&!v&&b({label:Q(s.name)})},readOnly:a,className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Label"}),e.jsx(x,{value:s.label,onChange:i=>{b({label:i.target.value}),C(!0)},className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Type"}),e.jsxs(P,{value:s.type,onValueChange:i=>b({type:i,options:{}}),children:[e.jsx(B,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsx(O,{children:d.map(i=>e.jsx(D,{value:i.value,children:i.label},i.value))})]})]})]}),e.jsx(ce,{type:s.type,options:s.options??{},onChange:i=>b({options:i})})]})})]})})}function I({fields:t,onChange:s,excludeTypes:u,existingFieldNames:m}){const l=A(R(U)),a=t.map((c,d)=>`field-${d}`),[n,r]=j.useState("text"),[p,v]=j.useState(null),C=u?w.filter(c=>!u.includes(c.value)):w;function g(){v(t.length),s([...t,{name:"",label:"",type:n,options:{}}])}function N(c,d){const h=[...t];h[c]=d,s(h)}function f(c){s(t.filter((d,h)=>h!==c))}function k(c){const{active:d,over:h}=c;if(h&&d.id!==h.id){const b=a.indexOf(String(d.id)),i=a.indexOf(String(h.id));s(_(t,b,i))}}return e.jsx(q,{sensors:l,collisionDetection:V,onDragEnd:k,children:e.jsx(G,{items:a,strategy:H,children:e.jsxs("div",{className:"space-y-2",children:[t.map((c,d)=>e.jsx(ie,{id:`field-${d}`,field:c,onChange:h=>N(d,h),onRemove:()=>f(d),excludeTypes:u,readOnlyName:!!(m?.has(c.name)&&c.name),defaultExpanded:d===p},`field-${d}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{value:n,onValueChange:r,children:[e.jsx(B,{className:"h-8 w-[130px] text-sm",children:e.jsx(M,{})}),e.jsx(O,{children:C.map(c=>e.jsx(D,{value:c.value,children:c.label},c.value))})]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(Z,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}const oe=["Newspaper","FileText","BookOpen","PenLine","Edit","Image","Camera","Video","Music","Mic","ShoppingCart","Store","Package","Tag","Gift","Users","User","UserPlus","Contact","Building","Calendar","Clock","Timer","CalendarDays","CalendarCheck","Star","Heart","ThumbsUp","Award","Trophy","Map","MapPin","Globe","Compass","Navigation","MessageSquare","Mail","Send","Phone","Bell","Folder","FolderOpen","Archive","Database","HardDrive","Settings","Wrench","Cog","Sliders","SlidersHorizontal","BarChart","PieChart","TrendingUp","Activity","LineChart","Code","Terminal","Braces","Bug","Puzzle","Home","Layout","Grid","List","Layers","Lightbulb","Zap","Flame","Sun","Moon","Link","ExternalLink","Share","Download","Upload","Lock","Unlock","Shield","Key","Eye"];function fe({value:t,onChange:s}){const[u,m]=j.useState(!1),[l,a]=j.useState(""),n=l?Object.keys(T).filter(r=>r.toLowerCase().includes(l.toLowerCase())).slice(0,120):[...oe];return e.jsxs(te,{open:u,onOpenChange:m,children:[e.jsx(le,{asChild:!0,children:e.jsx(S,{variant:"outline",className:"gap-2 w-full justify-start",children:t?e.jsxs(e.Fragment,{children:[e.jsx(L,{name:t,className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:t})]}):e.jsx("span",{className:"text-muted-foreground",children:"Select icon..."})})}),e.jsxs(ne,{className:"w-72 p-2",align:"start",children:[e.jsx(x,{placeholder:"Search icons...",value:l,onChange:r=>a(r.target.value),className:"mb-2",autoFocus:!0}),e.jsxs("div",{className:"grid grid-cols-6 gap-1 max-h-48 overflow-y-auto",children:[n.map(r=>r in T?e.jsx("button",{type:"button",title:r,className:F("flex items-center justify-center rounded-md p-2 hover:bg-accent transition-colors",t===r&&"bg-accent ring-1 ring-primary"),onClick:()=>{s(r),m(!1),a("")},children:e.jsx(L,{name:r,className:"h-4 w-4"})},r):null),n.length===0&&e.jsx("p",{className:"col-span-6 text-center text-sm text-muted-foreground py-4",children:"No matching icons"})]}),t&&e.jsx("div",{className:"border-t mt-2 pt-2",children:e.jsx(S,{variant:"ghost",size:"sm",className:"w-full",onClick:()=>{s(""),m(!1),a("")},children:"Clear icon"})})]})]})}export{I as F,re as I,fe as a};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as F,r as f}from"./react-vendor-C2CvUxFh.js";import{D as R,k as $,l as q,m as B,n as E,I,B as g,a as k,an as O,a1 as L,ah as D,v as V,X as H,L as M}from"./index-BA3y7HJs.js";import{h as X,i as G,d as J,m as K,n as Q}from"./useMedia-Cu5N4rY8.js";import{S as Y,a as Z,b as ee,c as ae,d as _}from"./select-dX9e6VDt.js";import{C as se}from"./card-CZTHR2Qa.js";import{m as P}from"./media-url-DIg_vSyf.js";function te({open:i,onSelect:l,onClose:r,allowedTypes:n}){const{host:c}=F(),[d,m]=f.useState(""),[u,j]=f.useState("__all__"),t=f.useRef(null),N=X(c),o=G(c),{data:v}=J(c),h=v?.items??[],y=u==="__all__"?void 0:u==="__unfiled__"?"":u,{data:w,fetchNextPage:s,hasNextPage:C,isFetchingNextPage:b}=K(c,{folderId:y}),[S,T]=f.useState(!1),U=(w?.pages.flatMap(a=>a.items)??[]).filter(a=>n&&!n.some(x=>x.endsWith("/*")?a.mimeType.startsWith(x.slice(0,-1)):a.mimeType===x)?!1:d?a.filename.toLowerCase().includes(d.toLowerCase())||a.alt?.toLowerCase().includes(d.toLowerCase()):!0);async function A(a){T(!0);try{const{uploadUrl:p,mediaId:x}=await N.mutateAsync({filename:a.name,contentType:a.type,size:a.size});await fetch(p,{method:"PUT",body:a,headers:{"Content-Type":a.type}});const z=await o.mutateAsync({mediaId:x,filename:a.name});l(z),r()}catch(p){V.error("Upload failed",{description:p instanceof Error?p.message:void 0})}finally{T(!1)}}function W(a){return a.startsWith("image/")}return e.jsx(R,{open:i,onOpenChange:()=>r(),children:e.jsxs($,{className:"max-w-3xl",children:[e.jsxs(q,{children:[e.jsx(B,{children:"Select Media"}),e.jsx(E,{className:"sr-only",children:"Browse and select media files"})]}),e.jsxs("div",{className:"mb-4 flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{placeholder:"Search by filename...",value:d,onChange:a=>m(a.target.value),className:"max-w-xs"}),h.length>0&&e.jsxs(Y,{value:u,onValueChange:j,children:[e.jsx(Z,{className:"w-[150px]",children:e.jsx(ee,{})}),e.jsxs(ae,{children:[e.jsx(_,{value:"__all__",children:"All folders"}),h.map(a=>e.jsx(_,{value:a.folderId,children:a.name},a.folderId)),e.jsx(_,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:t,type:"file",className:"hidden",accept:n?.join(",")??void 0,onChange:a=>a.target.files?.[0]&&A(a.target.files[0])}),e.jsxs(g,{variant:"outline",onClick:()=>t.current?.click(),disabled:S,children:[S?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(O,{className:"mr-2 h-4 w-4"}),"Upload New"]})]})]}),e.jsx("div",{className:"grid max-h-96 grid-cols-4 gap-3 overflow-y-auto",children:U.map(a=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{l(a),r()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:W(a.mimeType)?e.jsx("img",{src:P(a.urls?.thumb_md??a.url),alt:a.alt??a.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[a.mimeType.startsWith("image/")?e.jsx(L,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(D,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:a.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:a.filename})})]},a.mediaId))}),U.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),C&&e.jsxs(g,{variant:"ghost",className:"mt-2 w-full",onClick:()=>s(),disabled:b,children:[b?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function le(i){if(!i)return null;if(typeof i=="string")return{id:i,url:""};const l=i,r=l.id??l.mediaId??"";return r?{id:r,url:l.url??"",mimeType:l.mimeType,width:l.width,height:l.height,alt:l.alt,caption:l.caption,filename:l.filename}:null}function ie(i){return i?i.startsWith("image/"):!0}function pe({field:i,value:l,onChange:r,disabled:n}){const{host:c}=F(),[d,m]=f.useState(!1),j=i.options?.allowedTypes,t=le(l),N=t?.id??"",{data:o}=Q(c,N),v=t?.mimeType??o?.mimeType,h=ie(v),y=s=>{t&&r({...t,alt:s})},w=s=>{t&&r({...t,caption:s})};return e.jsxs("div",{children:[t?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!n&&m(!0),children:[h&&o?.url?e.jsx("img",{src:P(o.urls?.thumb_sm??o.url),alt:t.alt??o?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}):e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded bg-muted","aria-label":"File",children:e.jsx(D,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.filename??o?.filename??"Loading..."}),!n&&e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:s=>{s.stopPropagation(),r("")},children:e.jsx(H,{className:"h-3 w-3"})})]}),!n&&h&&e.jsxs("div",{className:"grid grid-cols-1 gap-3 pl-1 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-alt`,className:"text-xs font-normal text-muted-foreground",children:"Alt text"}),e.jsx(I,{id:`${t.id}-alt`,type:"text","aria-label":"Alt text",value:t.alt??"",onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-caption`,className:"text-xs font-normal text-muted-foreground",children:"Caption"}),e.jsx(I,{id:`${t.id}-caption`,type:"text","aria-label":"Caption",value:t.caption??"",onChange:s=>w(s.target.value)})]})]})]}):e.jsxs(g,{type:"button",variant:"outline",onClick:()=>m(!0),disabled:n,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!n&&e.jsx(te,{open:d,onClose:()=>m(!1),onSelect:s=>{const C={id:s.mediaId,url:s.url,mimeType:s.mimeType,width:s.width,height:s.height,alt:s.alt??"",caption:s.caption??"",filename:s.filename};r(C),m(!1)},allowedTypes:j})]})}export{te as M,pe as a};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as g,R as T,L as Dt,u as kt}from"./react-vendor-C2CvUxFh.js";import{u as St}from"./useFilterParams-DYdEuWPE.js";import{u as Tt,a as It,b as Mt,c as Rt,d as ct,e as _t,f as At,g as Et,h as Ft,i as zt,j as $t,k as Pt,l as Ot}from"./useMedia-Cu5N4rY8.js";import{ad as dt,y as P,ae as Ut,af as Lt,ag as Ht,ah as Xt,ai as Yt,aj as Ne,Y as De,Z as ke,_ as Se,B as D,ak as Oe,v as I,D as oe,k as ce,l as de,m as he,n as ue,L,I as K,o as me,a as J,al as Bt,j as Ue,T as Kt,X as ge,P as Wt,am as ee,a6 as Vt,a7 as qt,ab as Qt,a9 as Gt,aa as nt,an as pe,ao as Zt,ap as Jt,a2 as es,aq as ts,ar as ss,a0 as as,x as ns,J as rs,K as is,N as ls,z as rt,as as os,at as cs,au as ds,S as hs,av as us}from"./index-BA3y7HJs.js";import{C as ms,c as xs}from"./card-CZTHR2Qa.js";import{C as Ie}from"./checkbox-DEgzM8H9.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-dX9e6VDt.js";import{u as ht,a as ps,b as gs,c as fs,D as ws,d as js,P as vs}from"./core.esm-DdQHdRkd.js";import{b as ye,a as Le,f as He}from"./format-C88SDH8g.js";import{m as W}from"./media-url-DIg_vSyf.js";import{T as ys,a as bs,b as ut,c as X,d as Cs,e as Y}from"./table-Dk7eeOt2.js";import{T as Pe,A as Xe,h as Ns,a as Ye,b as Be,c as Ke,d as We,e as Ve,g as qe,f as Qe}from"./TagInput-d-Hw1fkL.js";import{u as Ds}from"./usePageTitle-DYvuJQp6.js";import"./radix-C5ZmWuuL.js";function Me({mimeType:a,className:t}){return a==="application/pdf"?e.jsx(dt,{className:P("text-blue-500",t)}):a.startsWith("video/")?e.jsx(Ut,{className:P("text-purple-500",t)}):a.startsWith("audio/")?e.jsx(Lt,{className:P("text-green-500",t)}):a==="image/svg+xml"?e.jsx(Ht,{className:P("text-orange-500",t)}):e.jsx(Xt,{className:P("text-muted-foreground",t)})}function ks(a){return a==="application/pdf"?"PDF":a==="image/svg+xml"?"SVG":a.startsWith("image/")?"Image":a.startsWith("video/")?"Video":a.startsWith("audio/")?"Audio":a.split("/")[1]?.toUpperCase()??"File"}function Ss({item:a,selected:t,onToggle:s,onSelect:l,onLightbox:n,folderName:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";return e.jsxs(ut,{ref:o,className:P("cursor-pointer",r&&"opacity-50"),onClick:l,children:[e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsx(Y,{className:"w-6 p-1 hidden md:table-cell",children:e.jsx("div",{className:"cursor-grab text-muted-foreground",...d,...h,children:e.jsx(Yt,{className:"h-4 w-4"})})}),e.jsx(Y,{className:"p-1",children:x?e.jsx("img",{src:W(a.urls?.thumb_sm??a.url),alt:a.alt||a.filename,className:P("h-8 w-8 rounded object-cover",n&&"cursor-zoom-in"),onClick:n?p=>{p.stopPropagation(),n()}:void 0}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-5 w-5"})})}),e.jsxs(Y,{className:"max-w-[200px]",children:[i&&e.jsx("span",{className:"text-muted-foreground block truncate text-xs",children:i}),e.jsx("span",{className:"block truncate text-sm font-medium",children:a.filename})]}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ks(a.mimeType)})}),e.jsx(Y,{className:"text-right",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)})}),e.jsx(Y,{className:"hidden lg:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:a.width&&a.height?`${a.width}×${a.height}`:"—"})}),e.jsx(Y,{className:"hidden lg:table-cell",children:a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(p=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]",children:p},p)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})}),e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")},children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})})]})}function Ts({items:a,host:t,onSelect:s,selectedIds:l,onToggle:n,onToggleAll:i,allSelected:d,onLightbox:h,folderMap:o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ys,{children:[e.jsx(bs,{children:e.jsxs(ut,{children:[e.jsx(X,{className:"w-10",children:e.jsx(Ie,{checked:d,onCheckedChange:i,"aria-label":"Select all"})}),e.jsx(X,{className:"w-6 hidden md:table-cell"}),e.jsx(X,{className:"w-12"}),e.jsx(X,{children:"Filename"}),e.jsx(X,{className:"w-20 hidden md:table-cell",children:"Type"}),e.jsx(X,{className:"w-24 text-right",children:"Size"}),e.jsx(X,{className:"w-28 hidden lg:table-cell",children:"Dimensions"}),e.jsx(X,{className:"w-40 hidden lg:table-cell",children:"Tags"}),e.jsx(X,{className:"w-32 hidden md:table-cell",children:"Uploaded"}),e.jsx(X,{className:"w-10"})]})}),e.jsx(Cs,{children:a.map(r=>e.jsx(Ss,{item:r,host:t,selected:l.has(r.mediaId),onToggle:()=>n(r.mediaId),onSelect:()=>s(r),folderName:o?.get(r.folderId??""),onLightbox:h&&r.mimeType.startsWith("image/")&&r.mimeType!=="image/svg+xml"?()=>h(r):void 0},r.mediaId))})]})})}var Is=Object.defineProperty,Ms=(a,t,s)=>t in a?Is(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>Ms(a,typeof t!="symbol"?t+"":t,s);const Te={x:0,y:0,width:0,height:0,unit:"px"},re=(a,t,s)=>Math.min(Math.max(a,t),s),Rs=(...a)=>a.filter(t=>t&&typeof t=="string").join(" "),it=(a,t)=>a===t||a.width===t.width&&a.height===t.height&&a.x===t.x&&a.y===t.y&&a.unit===t.unit;function ie(a,t,s){return a.unit==="%"?{...Te,...a,unit:"%"}:{unit:"%",x:a.x?a.x/t*100:0,y:a.y?a.y/s*100:0,width:a.width?a.width/t*100:0,height:a.height?a.height/s*100:0}}function G(a,t,s){return a.unit?a.unit==="px"?{...Te,...a,unit:"px"}:{unit:"px",x:a.x?a.x*t/100:0,y:a.y?a.y*s/100:0,width:a.width?a.width*t/100:0,height:a.height?a.height*s/100:0}:{...Te,...a,unit:"px"}}function lt(a,t,s,l,n,i=0,d=0,h=l,o=n){const r={...a};let x=Math.min(i,l),p=Math.min(d,n),f=Math.min(h,l),c=Math.min(o,n);t&&(t>1?(x=d?d*t:x,p=x/t,f=h*t):(p=i?i/t:p,x=p*t,c=o/t)),r.y<0&&(r.height=Math.max(r.height+r.y,p),r.y=0),r.x<0&&(r.width=Math.max(r.width+r.x,x),r.x=0);const b=l-(r.x+r.width);b<0&&(r.x=Math.min(r.x,l-x),r.width+=b);const m=n-(r.y+r.height);if(m<0&&(r.y=Math.min(r.y,n-p),r.height+=m),r.width<x&&((s==="sw"||s=="nw")&&(r.x-=x-r.width),r.width=x),r.height<p&&((s==="nw"||s=="ne")&&(r.y-=p-r.height),r.height=p),r.width>f&&((s==="sw"||s=="nw")&&(r.x-=f-r.width),r.width=f),r.height>c&&((s==="nw"||s=="ne")&&(r.y-=c-r.height),r.height=c),t){const N=r.width/r.height;if(N<t){const w=Math.max(r.width/t,p);(s==="nw"||s=="ne")&&(r.y-=w-r.height),r.height=w}else if(N>t){const w=Math.max(r.height*t,x);(s==="sw"||s=="nw")&&(r.x-=w-r.width),r.width=w}}return r}function _s(a,t,s,l){const n={...a};return t==="ArrowLeft"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="w"?(n.x-=s,n.width+=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="e"?n.width-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowRight"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="w"?(n.x+=s,n.width-=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="e"?n.width+=s:l==="se"&&(n.width+=s,n.height+=s)),t==="ArrowUp"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="n"?(n.y-=s,n.height+=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="s"?n.height-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowDown"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="n"?(n.y+=s,n.height-=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="s"?n.height+=s:l==="se"&&(n.width+=s,n.height+=s)),n}const le={capture:!0,passive:!1};let As=0;const Z=class U extends g.PureComponent{constructor(){super(...arguments),_(this,"docMoveBound",!1),_(this,"mouseDownOnCrop",!1),_(this,"dragStarted",!1),_(this,"evData",{startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0}),_(this,"componentRef",g.createRef()),_(this,"mediaRef",g.createRef()),_(this,"resizeObserver"),_(this,"initChangeCalled",!1),_(this,"instanceId",`rc-${As++}`),_(this,"state",{cropIsActive:!1,newCropIsBeingDrawn:!1}),_(this,"onCropPointerDown",t=>{const{crop:s,disabled:l}=this.props,n=this.getBox();if(!s)return;const i=G(s,n.width,n.height);if(l)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const d=t.target.dataset.ord,h=!!d;let o=t.clientX,r=t.clientY,x=i.x,p=i.y;if(d){const f=t.clientX-n.x,c=t.clientY-n.y;let b=0,m=0;d==="ne"||d=="e"?(b=f-(i.x+i.width),m=c-i.y,x=i.x,p=i.y+i.height):d==="se"||d==="s"?(b=f-(i.x+i.width),m=c-(i.y+i.height),x=i.x,p=i.y):d==="sw"||d=="w"?(b=f-i.x,m=c-(i.y+i.height),x=i.x+i.width,p=i.y):(d==="nw"||d=="n")&&(b=f-i.x,m=c-i.y,x=i.x+i.width,p=i.y+i.height),o=x+n.x+b,r=p+n.y+m}this.evData={startClientX:o,startClientY:r,startCropX:x,startCropY:p,clientX:t.clientX,clientY:t.clientY,isResize:h,ord:d},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})}),_(this,"onComponentPointerDown",t=>{const{crop:s,disabled:l,locked:n,keepSelection:i,onChange:d}=this.props,h=this.getBox();if(l||n||i&&s)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const o=t.clientX-h.x,r=t.clientY-h.y,x={unit:"px",x:o,y:r,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:o,startCropY:r,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,d(G(x,h.width,h.height),ie(x,h.width,h.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})}),_(this,"onDocPointerMove",t=>{const{crop:s,disabled:l,onChange:n,onDragStart:i}=this.props,d=this.getBox();if(l||!s||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,i&&i(t));const{evData:h}=this;h.clientX=t.clientX,h.clientY=t.clientY;let o;h.isResize?o=this.resizeCrop():o=this.dragCrop(),it(s,o)||n(G(o,d.width,d.height),ie(o,d.width,d.height))}),_(this,"onComponentKeyDown",t=>{const{crop:s,disabled:l,onChange:n,onComplete:i}=this.props;if(l)return;const d=t.key;let h=!1;if(!s)return;const o=this.getBox(),r=this.makePixelCrop(o),x=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep;if(d==="ArrowLeft"?(r.x-=x,h=!0):d==="ArrowRight"?(r.x+=x,h=!0):d==="ArrowUp"?(r.y-=x,h=!0):d==="ArrowDown"&&(r.y+=x,h=!0),h){t.cancelable&&t.preventDefault(),r.x=re(r.x,0,o.width-r.width),r.y=re(r.y,0,o.height-r.height);const p=G(r,o.width,o.height),f=ie(r,o.width,o.height);n(p,f),i&&i(p,f)}}),_(this,"onHandlerKeyDown",(t,s)=>{const{aspect:l=0,crop:n,disabled:i,minWidth:d=0,minHeight:h=0,maxWidth:o,maxHeight:r,onChange:x,onComplete:p}=this.props,f=this.getBox();if(i||!n)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const c=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep,b=G(n,f.width,f.height),m=_s(b,t.key,c,s),N=lt(m,l,s,f.width,f.height,d,h,o,r);if(!it(n,N)){const w=ie(N,f.width,f.height);x(N,w),p&&p(N,w)}}),_(this,"onDocPointerDone",t=>{const{crop:s,disabled:l,onComplete:n,onDragEnd:i}=this.props,d=this.getBox();this.unbindDocMove(),!(l||!s)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,i&&i(t),n&&n(G(s,d.width,d.height),ie(s,d.width,d.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))}),_(this,"onDragFocus",()=>{var t;(t=this.componentRef.current)==null||t.scrollTo(0,0)})}get document(){return document}getBox(){const t=this.mediaRef.current;if(!t)return{x:0,y:0,width:0,height:0};const{x:s,y:l,width:n,height:i}=t.getBoundingClientRect();return{x:s,y:l,width:n,height:i}}componentDidUpdate(t){const{crop:s,onComplete:l}=this.props;if(l&&!t.crop&&s){const{width:n,height:i}=this.getBox();n&&i&&l(G(s,n,i),ie(s,n,i))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,le),this.document.addEventListener("pointerup",this.onDocPointerDone,le),this.document.addEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,le),this.document.removeEventListener("pointerup",this.onDocPointerDone,le),this.document.removeEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!1)}getCropStyle(){const{crop:t}=this.props;if(t)return{top:`${t.y}${t.unit}`,left:`${t.x}${t.unit}`,width:`${t.width}${t.unit}`,height:`${t.height}${t.unit}`}}dragCrop(){const{evData:t}=this,s=this.getBox(),l=this.makePixelCrop(s),n=t.clientX-t.startClientX,i=t.clientY-t.startClientY;return l.x=re(t.startCropX+n,0,s.width-l.width),l.y=re(t.startCropY+i,0,s.height-l.height),l}getPointRegion(t,s,l,n){const{evData:i}=this,d=i.clientX-t.x,h=i.clientY-t.y;let o;n&&s?o=s==="nw"||s==="n"||s==="ne":o=h<i.startCropY;let r;return l&&s?r=s==="nw"||s==="w"||s==="sw":r=d<i.startCropX,r?o?"nw":"sw":o?"ne":"se"}resolveMinDimensions(t,s,l=0,n=0){const i=Math.min(l,t.width),d=Math.min(n,t.height);return!s||!i&&!d?[i,d]:s>1?i?[i,i/s]:[d*s,d]:d?[d*s,d]:[i,i/s]}resizeCrop(){const{evData:t}=this,{aspect:s=0,maxWidth:l,maxHeight:n}=this.props,i=this.getBox(),[d,h]=this.resolveMinDimensions(i,s,this.props.minWidth,this.props.minHeight);let o=this.makePixelCrop(i);const r=this.getPointRegion(i,t.ord,d,h),x=t.ord||r;let p=t.clientX-t.startClientX,f=t.clientY-t.startClientY;(d&&x==="nw"||x==="w"||x==="sw")&&(p=Math.min(p,-d)),(h&&x==="nw"||x==="n"||x==="ne")&&(f=Math.min(f,-h));const c={unit:"px",x:0,y:0,width:0,height:0};r==="ne"?(c.x=t.startCropX,c.width=p,s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY-c.height)):r==="se"?(c.x=t.startCropX,c.y=t.startCropY,c.width=p,s?c.height=c.width/s:c.height=f):r==="sw"?(c.x=t.startCropX+p,c.y=t.startCropY,c.width=Math.abs(p),s?c.height=c.width/s:c.height=f):r==="nw"&&(c.x=t.startCropX+p,c.width=Math.abs(p),s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY+f));const b=lt(c,s,r,i.width,i.height,d,h,l,n);return s||U.xyOrds.indexOf(x)>-1?o=b:U.xOrds.indexOf(x)>-1?(o.x=b.x,o.width=b.width):U.yOrds.indexOf(x)>-1&&(o.y=b.y,o.height=b.height),o.x=re(o.x,0,i.width-o.width),o.y=re(o.y,0,i.height-o.height),o}renderCropSelection(){const{ariaLabels:t=U.defaultProps.ariaLabels,disabled:s,locked:l,renderSelectionAddon:n,ruleOfThirds:i,crop:d}=this.props,h=this.getCropStyle();if(d)return T.createElement("div",{style:h,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!s&&!l&&T.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},T.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw",tabIndex:0,"aria-label":t.nwDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"nw"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n",tabIndex:0,"aria-label":t.nDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"n"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne",tabIndex:0,"aria-label":t.neDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"ne"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e",tabIndex:0,"aria-label":t.eDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"e"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se",tabIndex:0,"aria-label":t.seDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"se"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s",tabIndex:0,"aria-label":t.sDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"s"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw",tabIndex:0,"aria-label":t.swDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"sw"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w",tabIndex:0,"aria-label":t.wDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"w"),role:"button"})),n&&T.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:o=>o.stopPropagation()},n(this.state)),i&&T.createElement(T.Fragment,null,T.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),T.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const s={...Te,...this.props.crop||{}};return G(s,t.width,t.height)}render(){const{aspect:t,children:s,circularCrop:l,className:n,crop:i,disabled:d,locked:h,style:o,ruleOfThirds:r}=this.props,{cropIsActive:x,newCropIsBeingDrawn:p}=this.state,f=i?this.renderCropSelection():null,c=Rs("ReactCrop",n,x&&"ReactCrop--active",d&&"ReactCrop--disabled",h&&"ReactCrop--locked",p&&"ReactCrop--new-crop",i&&t&&"ReactCrop--fixed-aspect",i&&l&&"ReactCrop--circular-crop",i&&r&&"ReactCrop--rule-of-thirds",!this.dragStarted&&i&&!i.width&&!i.height&&"ReactCrop--invisible-crop",l&&"ReactCrop--no-animate");return T.createElement("div",{ref:this.componentRef,className:c,style:o},T.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},s),i?T.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},T.createElement("defs",null,T.createElement("mask",{id:`hole-${this.instanceId}`},T.createElement("rect",{width:"100%",height:"100%",fill:"white"}),l?T.createElement("ellipse",{cx:`${i.x+i.width/2}${i.unit}`,cy:`${i.y+i.height/2}${i.unit}`,rx:`${i.width/2}${i.unit}`,ry:`${i.height/2}${i.unit}`,fill:"black"}):T.createElement("rect",{x:`${i.x}${i.unit}`,y:`${i.y}${i.unit}`,width:`${i.width}${i.unit}`,height:`${i.height}${i.unit}`,fill:"black"}))),T.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,f)}};_(Z,"xOrds",["e","w"]),_(Z,"yOrds",["n","s"]),_(Z,"xyOrds",["nw","ne","se","sw"]),_(Z,"nudgeStep",1),_(Z,"nudgeStepMedium",10),_(Z,"nudgeStepLarge",100),_(Z,"defaultProps",{ariaLabels:{cropArea:"Use the arrow keys to move the crop selection area",nwDragHandle:"Use the arrow keys to move the north west drag handle to change the crop selection area",nDragHandle:"Use the up and down arrow keys to move the north drag handle to change the crop selection area",neDragHandle:"Use the arrow keys to move the north east drag handle to change the crop selection area",eDragHandle:"Use the up and down arrow keys to move the east drag handle to change the crop selection area",seDragHandle:"Use the arrow keys to move the south east drag handle to change the crop selection area",sDragHandle:"Use the up and down arrow keys to move the south drag handle to change the crop selection area",swDragHandle:"Use the arrow keys to move the south west drag handle to change the crop selection area",wDragHandle:"Use the up and down arrow keys to move the west drag handle to change the crop selection area"}});let Es=Z;const Fs=[{label:"Free",value:""},{label:"1:1 Square",value:"1"},{label:"4:3",value:"4/3"},{label:"3:2",value:"3/2"},{label:"16:9",value:"16/9"},{label:"2:3",value:"2/3"},{label:"3:4",value:"3/4"}],mt=[{label:"Original",value:"",ext:""},{label:"JPEG",value:"jpeg",ext:".jpg"},{label:"PNG",value:"png",ext:".png"},{label:"WebP",value:"webp",ext:".webp"},{label:"AVIF",value:"avif",ext:".avif"}],zs={"image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/tiff":".tiff"};function ze(a,t){return a?mt.find(s=>s.value===a)?.ext||`.${a}`:zs[t]||".jpg"}function $s(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ps({host:a,media:t,onClose:s,onSaved:l}){const n=g.useRef(null),[i,d]=g.useState(),[h,o]=g.useState(),[r,x]=g.useState(""),[p,f]=g.useState(""),[c,b]=g.useState(""),[m,N]=g.useState(""),[w,S]=g.useState("80"),[R,A]=g.useState(()=>{const y=ze("",t.mimeType),M=t.filename.lastIndexOf(".");return`${M>0?t.filename.substring(0,M):t.filename}-transformed${y}`});function F(y){const M=y==="__original__"?"":y;N(M);const q=ze(M,t.mimeType);A(ae=>$s(ae,q))}const z=Tt(a,t.mediaId),[j,v]=g.useState(null),$=g.useCallback(()=>{if(!h||!j)return null;const y=(t.width??j.width)/j.width,M=(t.height??j.height)/j.height;return{cropX:Math.round(h.x*y),cropY:Math.round(h.y*M),cropW:Math.round(h.width*y),cropH:Math.round(h.height*M)}},[h,t.width,t.height,j]),B=g.useMemo(()=>$(),[$]);async function se(){const y=B,M=p?parseInt(p):void 0,q=c?parseInt(c):void 0;if(!y&&!M&&!q&&!m){I.error("Please specify a crop, resize, or format change");return}if(!R.trim()){I.error("Filename is required");return}const ae=ze(m,t.mimeType);if(!R.trim().toLowerCase().endsWith(ae)){I.error(`Filename must end with ${ae} to match the output format`);return}try{const ne=await z.mutateAsync({...y??{},...M?{width:M}:{},...q?{height:q}:{},...m?{format:m}:{},...w?{quality:parseInt(w)}:{},filename:R.trim()});I.success("Transform saved as new media"),l?.(ne),s()}catch(ne){I.error("Transform failed",{description:ne instanceof Error?ne.message:void 0})}}function xe(y){x(y==="__free__"?"":y),d(void 0),o(void 0)}function V(y){if(!y)return;const M=y.split("/");return M.length===2?Number(M[0])/Number(M[1]):Number(y)||void 0}const Ge=V(r);return e.jsx(oe,{open:!0,onOpenChange:()=>s(),children:e.jsxs(ce,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(de,{children:[e.jsx(he,{children:"Transform Image"}),e.jsx(ue,{className:"sr-only",children:"Crop, resize, or convert image format"})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_280px] gap-6",children:[e.jsx("div",{className:"min-h-0 overflow-hidden rounded border bg-muted/30 flex items-center justify-center",children:e.jsx(Es,{crop:i,onChange:y=>d(y),onComplete:y=>o(y),aspect:Ge,children:e.jsx("img",{ref:n,src:W(t.url),alt:t.alt||t.filename,className:"max-h-[60vh] max-w-full object-contain",onLoad:y=>{const M=y.currentTarget;v({width:M.naturalWidth,height:M.naturalHeight})}})})}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:["Original: ",t.width,"×",t.height]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Crop aspect ratio"}),e.jsxs(fe,{value:r||"__free__",onValueChange:xe,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Free"})}),e.jsx(ve,{children:Fs.map(y=>e.jsx(te,{value:y.value||"__free__",children:y.label},y.value||"__free__"))})]}),h&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Crop: ",B?.cropW,"×",B?.cropH," at (",B?.cropX,", ",B?.cropY,")"]}),h&&e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{d(void 0),o(void 0)},children:"Clear crop"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Resize (optional)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Width",value:p,onChange:y=>f(y.target.value),min:1,max:2048})}),e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Height",value:c,onChange:y=>b(y.target.value),min:1,max:2048})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Output format"}),e.jsxs(fe,{value:m||"__original__",onValueChange:F,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Original"})}),e.jsx(ve,{children:mt.map(y=>e.jsx(te,{value:y.value||"__original__",children:y.label},y.value||"__original__"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Quality (1-100)"}),e.jsx(K,{type:"number",value:w,onChange:y=>S(y.target.value),min:1,max:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Save as filename"}),e.jsx(K,{value:R,onChange:y=>A(y.target.value)})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs(D,{onClick:se,disabled:z.isPending,children:[z.isPending&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save as New Image"]})]})]})})}const Os=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Us({host:a,media:t,onClose:s,onDeleted:l,folders:n,tagSuggestions:i}){const[d,h]=g.useState(t.alt??""),[o,r]=g.useState(t.caption??""),[x,p]=g.useState(t.userTags??[]),[f,c]=g.useState(t.folderId||"__none__"),[b,m]=g.useState(!1),N=Os.has(t.mimeType),w=It(a,t.mediaId),S=Mt(a,t.mediaId),{data:R,isLoading:A}=Rt(a,t.mediaId),F=t.tags.filter(v=>!t.userTags?.includes(v));async function z(){try{await w.mutateAsync({alt:d,caption:o,userTags:x,folderId:f==="__none__"?"":f}),I.success("Media updated"),s()}catch(v){I.error("Failed to update",{description:v instanceof Error?v.message:void 0})}}async function j(){try{await S.mutateAsync(),I.success("Media deleted"),l?.(t.mediaId),s()}catch(v){I.error("Failed to delete",{description:v instanceof Error?v.message:void 0})}}return e.jsxs(oe,{open:!0,onOpenChange:()=>s(),children:[e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(he,{children:t.filename}),e.jsx(ue,{className:"sr-only",children:"View and edit media details"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:[t.mimeType," · ",ye(t.size),t.width&&t.height&&` · ${t.width}×${t.height}`," · ",He(t.uploadedAt)]}),e.jsxs("div",{className:"flex gap-2",children:[N&&e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Transform"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(W(t.url)),I.success("URL copied to clipboard")},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),"Copy URL"]})]})]}),F.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Auto-detected tags"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:F.map(v=>e.jsx(Ue,{variant:"outline",className:"text-xs",children:v},v))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Tags"}),e.jsx(Pe,{tags:x,onChange:p,placeholder:"Add tags...",suggestions:i})]}),n&&n.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Folder"}),e.jsxs(fe,{value:f,onValueChange:c,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"No folder"})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__none__",children:"No folder"}),n.map(v=>e.jsx(te,{value:v.folderId,children:v.name},v.folderId))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"alt",children:"Alt text"}),e.jsx(K,{id:"alt",value:d,onChange:v=>h(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"caption",children:"Caption"}),e.jsx(K,{id:"caption",value:o,onChange:v=>r(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Used in"}),A?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}),"Checking usage..."]}):R?.references.length?e.jsxs("div",{className:"space-y-1",children:[R.references.map(v=>e.jsxs(Dt,{to:`/sites/${a}/content/${v.collection}/${v.contentId}`,className:"flex items-center gap-2 rounded px-2 py-1 text-sm hover:bg-muted",onClick:s,children:[e.jsx(dt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:v.title||v.contentId}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",v.collection,")"]})]},v.contentId)),R.note&&e.jsx("p",{className:"text-muted-foreground text-xs italic",children:R.note})]}):e.jsx("p",{className:"text-muted-foreground text-sm",children:"Not referenced in any content."})]})]}),e.jsxs(me,{className:"flex justify-between",children:[e.jsxs(Xe,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(D,{variant:"destructive",size:"sm",children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete media?"}),e.jsxs(We,{children:["This will permanently delete “",t.filename,"”. This action cannot be undone."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(D,{onClick:z,children:"Save"})]})]})]}),b&&e.jsx(Ps,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ls({tags:a,activeTag:t,onTagChange:s}){return a.length===0?null:e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-1.5",children:[a.map(l=>e.jsx(Ue,{variant:t===l?"default":"secondary",className:"cursor-pointer select-none",onClick:()=>s(t===l?void 0:l),children:l},l)),t&&e.jsxs(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s(void 0),children:[e.jsx(ge,{className:"mr-1 h-3 w-3"}),"Clear"]})]})}function $e({id:a,children:t}){const{setNodeRef:s,isOver:l}=ps({id:a,data:{type:"folder"}});return e.jsx("div",{ref:s,children:t(l)})}function ot({host:a,selectedFolderId:t,onSelect:s}){const{data:l}=ct(a),n=_t(a),i=At(a),d=Et(a),[h,o]=g.useState(!1),[r,x]=g.useState(""),[p,f]=g.useState(null),[c,b]=g.useState(""),[m,N]=g.useState(null),w=g.useRef(null),S=g.useRef(null),R=l?.items??[];g.useEffect(()=>{h&&w.current?.focus()},[h]),g.useEffect(()=>{p&&S.current?.focus()},[p]);async function A(){const j=r.trim();if(!j){o(!1),x("");return}try{await n.mutateAsync(j),I.success("Folder created")}catch(v){I.error("Failed to create folder",{description:v instanceof Error?v.message:void 0})}o(!1),x("")}async function F(j){const v=c.trim();if(!v){f(null);return}try{await i.mutateAsync({folderId:j,name:v}),I.success("Folder renamed")}catch($){I.error("Failed to rename folder",{description:$ instanceof Error?$.message:void 0})}f(null)}async function z(){if(m){try{await d.mutateAsync(m.folderId),I.success("Folder deleted"),t===m.folderId&&s(null)}catch(j){I.error("Failed to delete folder",{description:j instanceof Error?j.message:void 0})}N(null)}}return e.jsxs("div",{className:"flex w-48 shrink-0 flex-col border-r",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Folders"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>o(!0),children:e.jsx(Wt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[e.jsx($e,{id:"all-media",children:j=>e.jsx("button",{className:P("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t===null&&"bg-accent font-medium",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s(null),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"All Media"]})})}),R.map(j=>e.jsx($e,{id:j.folderId,children:v=>e.jsx("div",{className:P("group flex w-full items-center justify-between px-3 py-1.5 text-sm hover:bg-accent/50",t===j.folderId&&"bg-accent font-medium",v&&"ring-2 ring-primary bg-primary/10"),children:p===j.folderId?e.jsx(K,{ref:S,value:c,onChange:$=>b($.target.value),onKeyDown:$=>{$.key==="Enter"&&F(j.folderId),$.key==="Escape"&&f(null)},onBlur:()=>F(j.folderId),className:"h-6 text-sm"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"flex flex-1 items-center gap-2 text-left",onClick:()=>s(j.folderId),children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:j.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:j.count}),e.jsxs(Vt,{children:[e.jsx(qt,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100",children:e.jsx(Qt,{className:"h-3.5 w-3.5"})})}),e.jsxs(Gt,{align:"end",children:[e.jsx(nt,{onClick:()=>{f(j.folderId),b(j.name)},children:"Rename"}),e.jsx(nt,{disabled:j.count>0,onClick:()=>N(j),children:"Delete"})]})]})]})]})})},j.folderId)),e.jsx($e,{id:"unfiled",children:j=>e.jsx("button",{className:P("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t==="unfiled"&&"bg-accent font-medium",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s("unfiled"),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Unfiled"]})})}),h&&e.jsx("div",{className:"px-3 py-1.5",children:e.jsx(K,{ref:w,value:r,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&A(),j.key==="Escape"&&(o(!1),x(""))},onBlur:A,placeholder:"Folder name...",className:"h-7 text-sm"})})]}),e.jsx(Xe,{open:!!m,onOpenChange:()=>N(null),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete folder?"}),e.jsxs(We,{children:["This will delete the folder “",m?.name,"”. Media items in this folder will become unfiled."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:z,children:"Delete"})]})]})})]})}function Hs({selectedCount:a,folders:t,onDelete:s,onMove:l,onAddTags:n,onRemoveTags:i,onClear:d,isPending:h}){const[o,r]=g.useState(null),[x,p]=g.useState(""),[f,c]=g.useState([]);function b(){r(null),p(""),c([])}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 min-w-0",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:[a," selected"]}),e.jsx(D,{size:"sm",variant:"ghost",onClick:d,disabled:h,children:e.jsx(ge,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto rounded-md border bg-muted/50 px-3 py-2 max-w-[calc(100vw-1.5rem)]",children:[e.jsx(D,{size:"sm",variant:"destructive",onClick:()=>r("delete"),disabled:h,className:"shrink-0",children:"Delete"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("move"),disabled:h,className:"shrink-0",children:"Move to…"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("addTags"),disabled:h,className:"shrink-0",children:"Add tags"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("removeTags"),disabled:h,className:"shrink-0",children:"Remove tags"})]})]}),e.jsx(oe,{open:o==="delete",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Delete ",a," item",a!==1?"s":"","?"]}),e.jsx(ue,{children:"This action cannot be undone. The selected media items will be permanently deleted."})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{variant:"destructive",onClick:async()=>{b(),await s()},disabled:h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})}),e.jsx(oe,{open:o==="move",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Move ",a," item",a!==1?"s":""]}),e.jsx(ue,{children:"Choose a destination folder."})]}),e.jsxs(fe,{value:x,onValueChange:p,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Select folder..."})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__unfiled__",children:"Unfiled"}),t.map(m=>e.jsx(te,{value:m.folderId,children:m.name},m.folderId))]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=x==="__unfiled__"?"":x;b(),await l(m)},disabled:!x||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Move"]})]})]})}),e.jsx(oe,{open:o==="addTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Add tags to ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to add to the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Add tags..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await n(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Add"]})]})]})}),e.jsx(oe,{open:o==="removeTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Remove tags from ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to remove from the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Tags to remove..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await i(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Remove"]})]})]})})]})}function Xs({onFiles:a,children:t}){const[s,l]=g.useState(!1),n=g.useRef(0),i=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.types.includes("Files")&&(n.current++,l(!0))},[]),d=g.useCallback(r=>{r.preventDefault(),n.current--,n.current===0&&l(!1)},[]),h=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.dropEffect="copy"},[]),o=g.useCallback(r=>{r.preventDefault(),n.current=0,l(!1);const x=Array.from(r.dataTransfer.files);x.length>0&&a(x)},[a]);return e.jsxs("div",{className:"relative flex-1",onDragEnter:i,onDragLeave:d,onDragOver:h,onDrop:o,children:[t,s&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/5",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg bg-background/90 px-6 py-4 shadow-lg",children:[e.jsx(pe,{className:"h-8 w-8 text-primary"}),e.jsx("p",{className:"text-lg font-medium",children:"Drop files to upload"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Files will be uploaded to the current folder"})]})})]})}function Ys({queue:a}){const{items:t,retry:s,dismiss:l,clearCompleted:n}=a,[i,d]=g.useState(!1),h=t.filter(c=>c.status==="uploading").length,o=t.filter(c=>c.status==="pending").length,r=t.filter(c=>c.status==="complete").length,x=t.filter(c=>c.status==="error").length,p=h===0&&o===0;if(g.useEffect(()=>{if(p&&t.length>0){const c=setTimeout(()=>d(!0),2e3);return()=>clearTimeout(c)}},[p,t.length]),t.length===0)return null;const f=p?`${r} uploaded${x?`, ${x} failed`:""}`:`Uploading ${h+o} file${h+o!==1?"s":""}`;return e.jsxs("div",{className:"fixed bottom-4 right-4 z-50 w-80 rounded-lg border bg-background shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:f}),e.jsxs("div",{className:"flex items-center gap-1",children:[p&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:n,children:"Clear"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(!i),children:i?e.jsx(Zt,{className:"h-4 w-4"}):e.jsx(Jt,{className:"h-4 w-4"})})]})]}),!i&&e.jsx("div",{className:"max-h-60 overflow-y-auto",children:t.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-sm",children:[c.status==="uploading"&&e.jsx(J,{className:"h-4 w-4 shrink-0 animate-spin"}),c.status==="complete"&&e.jsx(es,{className:"h-4 w-4 shrink-0 text-green-500"}),c.status==="error"&&e.jsx(ge,{className:"h-4 w-4 shrink-0 text-destructive"}),c.status==="pending"&&e.jsx("div",{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate",children:c.file.name}),c.status==="uploading"&&e.jsx("div",{className:"bg-muted mt-0.5 h-1 w-full rounded-full",children:e.jsx("div",{className:"bg-primary h-full rounded-full transition-all",style:{width:`${c.progress}%`}})}),c.status==="error"&&e.jsx("p",{className:"text-destructive truncate text-xs",children:c.error})]}),c.status==="error"&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>s(c.id),children:e.jsx(ts,{className:"h-3 w-3"})}),(c.status==="complete"||c.status==="error")&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>l(c.id),children:e.jsx(ge,{className:"h-3 w-3"})})]},c.id))})]})}const Bs=3;let Ks=0;function Ws(a,t){const[s,l]=g.useState([]),n=Ft(a),i=zt(a),d=g.useRef(0),h=g.useRef(s);h.current=s;const o=g.useRef(new Map),r=g.useCallback(async m=>{d.current++,l(N=>N.map(w=>w.id===m.id?{...w,status:"uploading",progress:0}:w));try{const{uploadUrl:N,mediaId:w}=await n.mutateAsync({filename:m.file.name,contentType:m.file.type,size:m.file.size});await new Promise((S,R)=>{const A=new XMLHttpRequest;o.current.set(m.id,A),A.upload.onprogress=F=>{if(F.lengthComputable){const z=Math.round(F.loaded/F.total*100);l(j=>j.map(v=>v.id===m.id?{...v,progress:z}:v))}},A.onload=()=>{o.current.delete(m.id),A.status>=200&&A.status<300?S():R(new Error(`Upload failed: ${A.status}`))},A.onerror=()=>{o.current.delete(m.id),R(new Error("Network error"))},A.onabort=()=>{o.current.delete(m.id),R(new Error("Upload aborted"))},A.open("PUT",N),A.setRequestHeader("Content-Type",m.file.type),A.send(m.file)}),await i.mutateAsync({mediaId:w,filename:m.file.name,folderId:m.folderId}),l(S=>S.map(R=>R.id===m.id?{...R,status:"complete",progress:100}:R))}catch(N){l(w=>w.map(S=>S.id===m.id?{...S,status:"error",error:N instanceof Error?N.message:"Upload failed"}:S))}finally{d.current--}},[n,i]),x=g.useRef(r);x.current=r,g.useEffect(()=>{const m=s.filter(w=>w.status==="pending"),N=Bs-d.current;for(let w=0;w<Math.min(m.length,N);w++)x.current(m[w])},[s]),g.useEffect(()=>{const m=o.current;return()=>{m.forEach(N=>N.abort())}},[]);const p=g.useCallback(m=>{const N=Array.from(m).map(w=>({id:`upload-${Ks++}`,file:w,folderId:t||void 0,status:"pending",progress:0}));l(w=>[...w,...N])},[t]),f=g.useCallback(m=>{l(N=>N.map(w=>w.id===m?{...w,status:"pending",progress:0,error:void 0}:w))},[]),c=g.useCallback(m=>{l(N=>N.filter(w=>w.id!==m))},[]),b=g.useCallback(()=>{l(m=>m.filter(N=>N.status!=="complete"&&N.status!=="error"))},[]);return{items:s,addFiles:p,retry:f,dismiss:c,clearCompleted:b}}function Vs({items:a,currentIndex:t,onClose:s,onNavigate:l}){const n=a[t],i=t>0,d=t<a.length-1,h=g.useRef(null),o=g.useCallback(r=>{r.key==="Escape"?s():r.key==="ArrowLeft"&&i?l(t-1):r.key==="ArrowRight"&&d&&l(t+1)},[s,l,t,i,d]);return g.useEffect(()=>(document.addEventListener("keydown",o),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",o),document.body.style.overflow=""}),[o]),n?e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-black/90",onClick:s,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 pt-[max(0.75rem,env(safe-area-inset-top,0px))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))] text-white",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"min-w-0 flex-1 text-sm",children:[e.jsx("span",{className:"font-medium truncate block",children:n.filename}),e.jsxs("span",{className:"opacity-70 text-xs",children:[n.width&&n.height&&`${n.width}×${n.height} · `,ye(n.size)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"text-sm opacity-70",children:[t+1," / ",a.length]}),e.jsx(D,{variant:"ghost",size:"icon",className:"text-white hover:bg-white/20",onClick:s,children:e.jsx(ge,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center px-4 md:px-16",onClick:r=>r.stopPropagation(),onTouchStart:r=>{h.current=r.touches[0].clientX},onTouchEnd:r=>{if(h.current===null)return;const x=r.changedTouches[0].clientX-h.current;h.current=null,x>50&&i?l(t-1):x<-50&&d&&l(t+1)},children:[e.jsx("img",{src:W(n.url),alt:n.alt||n.filename,className:"max-h-full max-w-full object-contain"}),i&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute left-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t-1),children:e.jsx(ss,{className:"h-8 w-8"})}),d&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t+1),children:e.jsx(as,{className:"h-8 w-8"})})]})]}):null}function qs({open:a,duplicates:t,fileCount:s,onContinue:l,onCancel:n}){return e.jsx(Xe,{open:a,onOpenChange:i=>!i&&n(),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Possible duplicates found"}),e.jsx(We,{children:s===1?"A file with the same name and size already exists:":`${t.length} of ${s} files may already exist:`})]}),e.jsx("div",{className:"max-h-48 space-y-2 overflow-y-auto",children:t.map(i=>e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[i.mimeType.startsWith("image/")&&i.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(i.urls?.thumb_sm??i.url),alt:i.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(Me,{mimeType:i.mimeType,className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:i.filename}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[ye(i.size)," ·"," ",Le(i.uploadedAt)]})]})]},i.mediaId))}),e.jsxs(Ve,{children:[e.jsx(qe,{onClick:n,children:"Cancel"}),e.jsx(Qe,{onClick:l,children:"Upload Anyway"})]})]})})}const Qs=({activatorEvent:a,draggingNodeRect:t,transform:s})=>{if(a&&t){const l=a;if(l.clientX!==void 0)return{...s,x:s.x+l.clientX-t.left-t.width/2,y:s.y+l.clientY-t.top-t.height/2}}return s},Gs=[{value:"date_desc",label:"Newest first"},{value:"date_asc",label:"Oldest first"},{value:"name_asc",label:"Name A-Z"},{value:"name_desc",label:"Name Z-A"},{value:"size_desc",label:"Size (largest)"},{value:"size_asc",label:"Size (smallest)"}];function Zs({item:a,selected:t,onToggle:s,onClick:l,folderName:n,onLightbox:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";function p(f){f.stopPropagation(),navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")}return e.jsx(ms,{ref:o,...d,...h,className:P("group relative cursor-pointer overflow-hidden",r&&"opacity-50",t&&"ring-2 ring-primary"),onClick:l,children:e.jsxs(xs,{className:"p-0",children:[e.jsx("div",{className:P("absolute left-2 top-2 z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100 [@media(hover:none)]:rounded [@media(hover:none)]:bg-black/30 [@media(hover:none)]:p-0.5",t&&"opacity-100"),onPointerDown:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsxs("div",{className:"absolute right-2 top-2 z-10 flex gap-1 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onPointerDown:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:[e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:p,children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"Copy URL"})]})}),x&&i&&e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:f=>{f.stopPropagation(),i()},children:e.jsx(us,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"View full size"})]})})]}),x?e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx("img",{src:W(a.urls?.thumb_md??a.url),alt:a.alt||a.filename,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-12 w-12"})}),e.jsxs("div",{className:"p-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:a.filename}),n&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(ee,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate text-xs",children:n})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)}),e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})]}),a.tags.length>0&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(f=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]",children:f},f)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})]})]})})}function xa(){const{host:a}=kt(),t=ns(),[s,l]=St([{key:"tag",defaultValue:""},{key:"folder",defaultValue:""},{key:"q",defaultValue:""},{key:"sort",defaultValue:"date_desc"},{key:"view",defaultValue:"grid"}]),n=s.view,i=u=>l({view:u}),d=s.sort,h=u=>l({sort:u}),o=s.tag||void 0,r=s.folder===""?null:s.folder,x=u=>l({folder:u??""}),[p,f]=g.useState(s.q),[c,b]=g.useState(s.q),[m,N]=g.useState(null),[w,S]=g.useState(new Set),[R,A]=g.useState(null),[F,z]=g.useState(null),[j,v]=g.useState(null),[$,B]=g.useState([]),[se,xe]=g.useState(!1),V=g.useRef(null);Ds({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Ws(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=gs(fs(vs,{activationConstraint:{distance:t?1e5:8}}));g.useEffect(()=>{const u=setTimeout(()=>{b(C=>{const k=p;return C!==k&&(S(new Set),l({q:k})),k})},300);return()=>clearTimeout(u)},[p,l]);const ne=r===null?void 0:r==="unfiled"?"":r,{data:O,isLoading:xt}=Ot(a,{sort:d,q:c||void 0,folderId:ne,tag:o}),{data:Ze}=ct(a),be=g.useMemo(()=>Ze?.items??[],[Ze?.items]),Re=g.useMemo(()=>{const u=new Map;for(const C of be)u.set(C.folderId,C.name);return u},[be]),Ce=g.useMemo(()=>(O?.items??[]).filter(u=>u.mimeType.startsWith("image/")&&u.mimeType!=="image/svg+xml"),[O?.items]),_e=g.useMemo(()=>{const u=new Map;return Ce.forEach((C,k)=>u.set(C.mediaId,k)),u},[Ce]),{allTags:pt,allUserTags:gt}=g.useMemo(()=>{const u=O?.items??[],C=new Set,k=new Set;for(const E of u){for(const H of E.tags)C.add(H);for(const H of E.userTags??[])k.add(H)}return{allTags:Array.from(C).sort(),allUserTags:Array.from(k).sort()}},[O?.items]),Ae=O?.items.map(u=>u.mediaId)??[],Ee=Ae.length>0&&Ae.every(u=>w.has(u));function Je(u){S(C=>{const k=new Set(C);return k.has(u)?k.delete(u):k.add(u),k})}function et(){S(Ee?new Set:new Set(Ae))}async function ft(){const u=[...w],k=(await M.mutateAsync({mediaIds:u,action:"delete"})).failed.length;k?I.error(`${k} of ${u.length} failed to delete`):I.success(`${u.length} item(s) deleted`),S(new Set)}async function wt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"move",folderId:u})).failed.length;E?I.error(`${E} of ${C.length} failed to move`):I.success(`${C.length} item(s) moved`),S(new Set)}async function jt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"addTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags added to ${C.length} item(s)`),S(new Set)}async function vt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"removeTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags removed from ${C.length} item(s)`),S(new Set)}async function tt(u){const C=Array.from(u),k=C.slice(0,5),E=[];for(const H of k)try{const Fe=await q.mutateAsync({filename:H.name,size:H.size});E.push(...Fe.duplicates)}catch{}E.length>0?(v(C),B(E)):y.addFiles(C)}function yt(u){u.target.files&&tt(u.target.files),V.current&&(V.current.value="")}function bt(u){A(String(u.active.id))}function Ct(u){A(null);const{active:C,over:k}=u;if(!k||k.data.current?.type!=="folder")return;const E=k.id==="unfiled"||k.id==="all-media"?"":String(k.id),H=w.has(String(C.id))?[...w]:[String(C.id)];M.mutateAsync({mediaIds:H,action:"move",folderId:E}).then(Fe=>{const at=Fe.failed.length;at?I.error(`${at} of ${H.length} failed to move`):I.success(`${H.length} item(s) moved`)})}function Nt(){A(null)}const Q=R?O?.items.find(u=>u.mediaId===R):null,st=R&&w.has(R)?w.size:1;return e.jsxs(ws,{sensors:ae,modifiers:[Qs],onDragStart:bt,onDragEnd:Ct,onDragCancel:Nt,children:[e.jsxs("div",{className:"-m-2 md:-m-6 relative flex min-h-[calc(100dvh-3.5rem)] md:h-[calc(100vh-3.5rem)]",children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set)}})}),e.jsx(rs,{open:se,onOpenChange:xe,children:e.jsxs(is,{side:"left",className:"w-64 p-0 pt-[env(safe-area-inset-top,0px)] pl-[env(safe-area-inset-left,0px)] [&_[data-slot=sheet-close]]:top-[calc(1rem+env(safe-area-inset-top,0px))]","data-testid":"folder-overlay-backdrop",children:[e.jsx(ls,{className:"sr-only",children:"Folders"}),e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set),xe(!1)}})]})}),e.jsxs(Xs,{onFiles:u=>tt(u),children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-2 md:p-6",children:[!t&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Media"}),e.jsx("div",{children:e.jsxs(D,{onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})})]}),e.jsx("input",{ref:V,type:"file",multiple:!0,className:"hidden",onChange:yt}),w.size>0?e.jsx(Hs,{selectedCount:w.size,folders:be,onDelete:ft,onMove:wt,onAddTags:jt,onRemoveTags:vt,onClear:()=>S(new Set),isPending:M.isPending}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative min-w-[200px] max-w-sm flex-1",children:[e.jsx(rt,{className:"text-muted-foreground absolute left-2.5 top-2.5 h-4 w-4"}),e.jsx(K,{placeholder:"Search media...",value:p,onChange:u=>f(u.target.value),className:"pl-9"})]}),e.jsxs(fe,{value:d,onValueChange:h,children:[e.jsx(we,{className:"w-[160px]",children:e.jsx(je,{})}),e.jsx(ve,{children:Gs.map(u=>e.jsx(te,{value:u.value,children:u.label},u.value))})]}),e.jsx(D,{variant:se?"secondary":"ghost",size:"sm",className:"md:hidden px-2",onClick:()=>xe(!se),"aria-label":"Toggle folders",children:e.jsx(os,{className:"h-4 w-4"})}),!se&&r!==null&&t&&e.jsxs(Ue,{variant:"secondary",className:"gap-1 md:hidden",children:[e.jsx(ee,{className:"h-3 w-3"}),r==="unfiled"?"Unfiled":Re.get(r)??"All Media"]}),e.jsxs("div",{className:"flex rounded-md border",children:[e.jsx(D,{variant:n==="grid"?"secondary":"ghost",size:"sm",className:"rounded-r-none px-2",onClick:()=>i("grid"),children:e.jsx(cs,{className:"h-4 w-4"})}),e.jsx(D,{variant:n==="list"?"secondary":"ghost",size:"sm",className:"rounded-l-none px-2",onClick:()=>i("list"),children:e.jsx(ds,{className:"h-4 w-4"})})]})]}),e.jsx(Ls,{tags:pt,activeTag:o,onTagChange:u=>{l({tag:u??""}),S(new Set)}}),n==="grid"&&(O?.items.length??0)>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Ie,{checked:Ee,onCheckedChange:et,"aria-label":"Select all"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:w.size>0?`${w.size} of ${O.items.length} selected`:"Select all"})]}),xt?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:Array.from({length:8}).map((u,C)=>e.jsx(hs,{className:"aspect-square"},C))}):O?.items.length?n==="list"?e.jsx(Ts,{items:O.items,host:a,onSelect:N,selectedIds:w,onToggle:Je,onToggleAll:et,allSelected:Ee,folderMap:r===null?Re:void 0,onLightbox:u=>{const C=_e.get(u.mediaId);C!==void 0&&z(C)}}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:O.items.map(u=>e.jsx(Zs,{item:u,selected:w.has(u.mediaId),onToggle:()=>Je(u.mediaId),onClick:()=>N(u),folderName:r===null?Re.get(u.folderId??""):void 0,onLightbox:_e.has(u.mediaId)?()=>z(_e.get(u.mediaId)):void 0},u.mediaId))}):e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:c||o?e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No results found"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Try adjusting your search or filters."})]}):r==="unfiled"?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No unfiled media"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"All media items are organized in folders."})]}):r?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"This folder is empty"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload files or drag media into this folder."})]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No media yet"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload your first file to get started."}),e.jsxs(D,{className:"mt-4",onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})]})}),m&&e.jsx(Us,{host:a,media:m,onClose:()=>N(null),onDeleted:u=>{S(C=>{if(!C.has(u))return C;const k=new Set(C);return k.delete(u),k})},folders:be,tagSuggestions:gt})]}),e.jsx(Ys,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(Vs,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(qs,{open:$.length>0,host:a,duplicates:$,fileCount:j?Array.from(j).length:0,onContinue:()=>{j&&y.addFiles(j),v(null),B([])},onCancel:()=>{v(null),B([])}}),e.jsx(js,{children:R&&Q&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-background p-2 shadow-lg",children:[Q.mimeType.startsWith("image/")&&Q.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(Q.urls?.thumb_sm??Q.url),alt:Q.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(Me,{mimeType:Q.mimeType,className:"h-6 w-6"})}),e.jsx("span",{className:"text-sm font-medium",children:st>1?`Moving ${st} items`:Q.filename})]})})]})}export{xa as MediaPage};
@@ -1 +0,0 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as F,f as B,r as L,L as C}from"./react-vendor-C2CvUxFh.js";import{j as S,m as O}from"./useContent-CW0tm0FY.js";import{x as E,w as P,S as b,B as r,bb as M,a3 as U,W as z,D as H,i as V,T as W,k as Y,l as _,m as q,n as G,o as J,ad as K,j as Q,v as g}from"./index-BA3y7HJs.js";import{u as X}from"./usePageTitle-DYvuJQp6.js";import{C as y,a as v,b as D,c as w}from"./card-CZTHR2Qa.js";import{f as Z}from"./format-C88SDH8g.js";import{a as ss}from"./MediaField-B-Cz8TlK.js";import"./radix-C5ZmWuuL.js";import"./useMedia-Cu5N4rY8.js";import"./select-dX9e6VDt.js";import"./media-url-DIg_vSyf.js";function es({host:i,ref:t}){const c=!t.title&&!!t.contentId,{data:o}=S(i,c?t.contentId:""),d=c&&o?.content?o.content:null,u=t.title||d?.title||t.contentId,a=t.collection||d?.collection||"";return s.jsxs(C,{to:`/sites/${i}/content/${a}/${t.contentId}`,className:"flex items-center gap-3 rounded-md border p-2 transition-colors hover:bg-muted",children:[s.jsx(K,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"flex-1 truncate text-sm",children:u}),a&&s.jsx(Q,{variant:"secondary",children:a})]})}function us(){const{host:i,collection:t,id:c}=F(),o=B(),d=E(),{collections:u}=P(),{data:a,isLoading:$}=S(i,c),k=O(i,c),[T,p]=L.useState(!1),m=u.find(e=>e.name===t),f=m?.relationships??[];if(X({title:"Submission Detail",showBack:!0,backTo:`/sites/${i}/submissions/${t}`}),$)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(b,{className:"h-8 w-64"}),s.jsx(b,{className:"h-64 w-full"})]});if(!a?.content)return s.jsx("p",{className:"text-muted-foreground",children:"Submission not found."});const l=a.content,x=a.body??l.body,h=l.siteUser,j=l.relationships;function I(e,n){return n==null?"—":typeof n=="boolean"?n?"Yes":"No":Array.isArray(n)?n.join(", "):String(n)}async function R(){try{await k.mutateAsync(),g.success("Submission deleted"),o(`/sites/${i}/submissions/${t}`)}catch(e){g.error("Failed to delete",{description:e instanceof Error?e.message:void 0})}}const A=f.length>0&&j&&Object.keys(j).length>0;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!d&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>o(`/sites/${i}/submissions/${t}`),children:[s.jsx(M,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:"Submission Detail"}),s.jsx("div",{className:"ml-auto",children:s.jsxs(r,{variant:"outline",size:"sm",onClick:()=>o(`/sites/${i}/submissions/${t}/${c}/edit`),children:[s.jsx(U,{className:"mr-1.5 h-4 w-4"}),"Edit"]})})]}),s.jsxs(y,{children:[s.jsx(v,{children:s.jsx(D,{children:l.title||"Untitled"})}),s.jsxs(w,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2 text-sm",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"ID"}),s.jsx("span",{className:"font-mono text-xs",children:l.contentId})]}),!!l.publishedAt&&s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Submitted"}),s.jsx("span",{children:Z(l.publishedAt)})]}),h&&s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Submitted by"}),s.jsx(C,{to:`/sites/${i}/settings/site-users/${h.userId}`,className:"text-primary hover:underline",children:h.name||h.email})]})]}),s.jsx(z,{}),s.jsxs("div",{className:"space-y-3",children:[m?.fields?.map(e=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:e.label||e.name}),e.type==="media"?s.jsx(ss,{field:e,value:x?.[e.name],onChange:()=>{},disabled:!0}):s.jsx("p",{className:"text-sm whitespace-pre-wrap",children:I(e,x?.[e.name])})]},e.name)),(!m?.fields||m.fields.length===0)&&x&&s.jsx("div",{className:"space-y-3",children:Object.entries(x).map(([e,n])=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:e}),s.jsx("p",{className:"text-sm whitespace-pre-wrap",children:n==null?"—":String(n)})]},e))})]})]})]}),A&&s.jsxs(y,{className:"mt-6",children:[s.jsx(v,{children:s.jsx(D,{children:"Relationships"})}),s.jsx(w,{className:"space-y-4",children:f.map(e=>{const n=j?.[e.name]??[];return n.length===0?null:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-medium",children:e.label}),s.jsx("div",{className:"space-y-2",children:n.map(N=>s.jsx(es,{host:i,ref:N},N.contentId))})]},e.name)})})]}),s.jsx("div",{className:"mt-6",children:s.jsxs(H,{open:T,onOpenChange:p,children:[s.jsx(V,{asChild:!0,children:s.jsxs(r,{variant:"destructive",children:[s.jsx(W,{className:"mr-2 h-4 w-4"}),"Delete Submission"]})}),s.jsxs(Y,{children:[s.jsxs(_,{children:[s.jsx(q,{children:"Delete submission?"}),s.jsx(G,{children:"This will permanently delete this submission."})]}),s.jsxs(J,{children:[s.jsx(r,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),s.jsx(r,{variant:"destructive",onClick:R,children:"Delete"})]})]})]})})]})}export{us as SubmissionDetailPage};
@@ -1 +0,0 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as O,f as z,r as u}from"./react-vendor-C2CvUxFh.js";import{x as U,w as V,e as D,S as E,B as P,bb as H,L as q,bc as G,I as x,v as j}from"./index-BA3y7HJs.js";import{j as J,s as K,t as Q}from"./useContent-CW0tm0FY.js";import{u as W}from"./usePageTitle-DYvuJQp6.js";import{T as X}from"./textarea-CpDSUg2s.js";import{C as Y}from"./checkbox-DEgzM8H9.js";import{S as Z,a as _,b as ee,c as se,d as te}from"./select-dX9e6VDt.js";import{C as ae,a as ne,b as ie,c as oe}from"./card-CZTHR2Qa.js";import{a as re}from"./MediaField-B-Cz8TlK.js";import{R as ce}from"./RelationshipPicker-Dv7GaLcU.js";import"./radix-C5ZmWuuL.js";import"./useMedia-Cu5N4rY8.js";import"./media-url-DIg_vSyf.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./ContentField-D04Uo1Ov.js";import"./popover-BFw_h3j6.js";import"./command-CdzYw11U.js";import"./useContentSearch-_bwacEth.js";function Fe(){const{host:i,collection:c,id:m}=O(),b=z(),R=U(),{collections:A}=V(),o=!!m,d=A.find(t=>t.name===c),v=u.useMemo(()=>d?.relationships??[],[d?.relationships]),h=v.length>0,{data:p,isLoading:T}=J(i,m??""),S=D(),C=K(i),f=Q(i,m??""),[y,$]=u.useState({}),[w,N]=u.useState({}),[k,L]=u.useState(!o);W({title:o?"Edit Submission":"New Submission",showBack:!0,backTo:o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`});const I=u.useCallback(async t=>{const a={};for(const[e,n]of Object.entries(t))a[e]=await Promise.all(n.map(async r=>{if(r.title)return r;try{const g=await S.apiFetch(`/v1/admin/sites/${i}/content/${r.contentId}`);return{contentId:r.contentId,collection:g.content.collection??r.collection??"",slug:g.content.slug??r.slug??"",title:g.content.title??r.contentId}}catch{return r}}));return a},[S,i]);if(u.useEffect(()=>{if(o&&p&&!k){const t=p.body;t&&$({...t});const e=p.content?.relationships;e&&Object.keys(e).length>0&&I(e).then(N),L(!0)}},[o,p,k,I]),o&&T)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(E,{className:"h-8 w-64"}),s.jsx(E,{className:"h-64 w-full"})]});function l(t,a){$(e=>({...e,[t]:a}))}function B(t){const a=y[t.name];switch(t.type){case"text":return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)});case"textarea":return s.jsx(X,{value:a??"",onChange:e=>l(t.name,e.target.value),rows:4});case"number":return s.jsx(x,{type:"number",value:a!=null?String(a):"",onChange:e=>l(t.name,e.target.value===""?void 0:Number(e.target.value))});case"boolean":return s.jsx(Y,{checked:!!a,onCheckedChange:e=>l(t.name,!!e)});case"select":{const e=t.options?.choices??[];return s.jsxs(Z,{value:a??"",onValueChange:n=>l(t.name,n),children:[s.jsx(_,{children:s.jsx(ee,{placeholder:"Select..."})}),s.jsx(se,{children:e.map(n=>s.jsx(te,{value:n,children:n},n))})]})}case"array":return s.jsx(x,{value:Array.isArray(a)?a.join(", "):a??"",onChange:e=>l(t.name,e.target.value?e.target.value.split(",").map(n=>n.trim()):[]),placeholder:"Comma-separated values"});case"media":return s.jsx(re,{field:t,value:a,onChange:()=>{},disabled:!0});default:return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)})}}async function M(){const t={};for(const[e,n]of Object.entries(y))n!==void 0&&n!==""&&(t[e]=n);const a={};if(h)for(const[e,n]of Object.entries(w))a[e]=n.map(r=>({contentId:r.contentId}));try{if(o)await f.mutateAsync({fields:t,...h?{relationships:a}:{}}),j.success("Submission updated"),b(`/sites/${i}/submissions/${c}/${m}`);else{const e=await C.mutateAsync({collection:c,fields:t,...h?{relationships:a}:{}});j.success("Submission created"),b(`/sites/${i}/submissions/${c}/${e.contentId}`)}}catch(e){const n=e instanceof Error?e.message:typeof e=="object"&&e!==null&&"message"in e?String(e.message):String(e);j.error(o?"Failed to update":"Failed to create",{description:n})}}const F=C.isPending||f.isPending;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!R&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>b(o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`),children:[s.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:o?"Edit Submission":"New Submission"})]}),s.jsxs(ae,{children:[s.jsx(ne,{children:s.jsx(ie,{children:d?.label??c})}),s.jsxs(oe,{className:"space-y-4",children:[d?.fields?.map(t=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(q,{htmlFor:`field-${t.name}`,children:t.label||t.name}),s.jsx("div",{id:`field-${t.name}`,children:B(t)})]},t.name)),s.jsx("div",{className:"pt-4",children:s.jsxs(P,{onClick:M,disabled:F,children:[s.jsx(G,{className:"mr-1.5 h-4 w-4"}),F?"Saving...":o?"Update":"Create"]})})]})]}),h&&s.jsx("div",{className:"mt-6",children:s.jsx(ce,{relationships:v,values:w,onChange:N,host:i})})]})}export{Fe as SubmissionEditPage};
@@ -1 +0,0 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as G,f as J,r as p}from"./react-vendor-C2CvUxFh.js";import{u as K}from"./useFilterParams-DYdEuWPE.js";import{w as Q,x as W,B as L,P as X,T as Z,v as R,S as ee,y as se}from"./index-BA3y7HJs.js";import{d as te,c as ae}from"./useContent-CW0tm0FY.js";import{u as le}from"./usePageTitle-DYvuJQp6.js";import{u as ne,F as re}from"./FilterBar-kFcOLffg.js";import{C as ie,c as oe}from"./card-CZTHR2Qa.js";import{C as k}from"./checkbox-DEgzM8H9.js";import{S as ce,a as de,b as ue,c as me,d as he}from"./select-dX9e6VDt.js";import{T as fe,a as pe,b as _,c as S,d as xe,e as N}from"./table-Dk7eeOt2.js";import{a as B,f as ge}from"./format-C88SDH8g.js";import{P as be}from"./Pagination-CuHwUPHi.js";import"./radix-C5ZmWuuL.js";import"./popover-BFw_h3j6.js";import"./command-CdzYw11U.js";import"./useContentSearch-_bwacEth.js";const je=[{value:"created_desc",label:"Newest first"},{value:"created_asc",label:"Oldest first"}];function Re(){const{host:h,collection:c}=G(),v=J(),{collections:D}=Q(),[d,l]=K([{key:"sort",defaultValue:"created_desc"},{key:"relatedTo",defaultValue:""},{key:"relField",defaultValue:""},{key:"page",defaultValue:"1"},{key:"perPage",defaultValue:"20"},{key:"after",defaultValue:""}]),g=d.sort,u=d.relatedTo,n=d.relField,r=Number(d.page)||1,w=Number(d.perPage)||20,T=p.useMemo(()=>{const e=d.after;return e?e.split(","):[]},[d.after]),[m,a]=p.useState(new Set),P=W(),f=D.find(e=>e.name===c),b=f?.relationships??[];le({title:f?.label??c??""});const{data:F}=ne(h,u||void 0),A=p.useMemo(()=>{if(!u||!n)return null;const e=b.find(t=>t.name===n);return{type:"relationship",relName:n,relLabel:e?.label??n,contentId:u,contentTitle:F??"Loading..."}},[u,n,b,F]),O=p.useCallback(()=>{l({page:"1",after:""}),a(new Set)},[l]),z=p.useMemo(()=>{const e={};return g!=="created_desc"&&(e.sort=g),u&&(e.relatedTo=u),n&&(e.relField=n),e.limit=w,e},[g,u,n,w]),q=r>1?T[r-2]:void 0,{data:x,isLoading:E}=te(h,c,z,q),$=ae(h),j=x?.items,C=f?.fields,V=p.useMemo(()=>C?C.filter(e=>["text","number","boolean","select"].includes(e.type)).slice(0,4):[],[C]),I=j?.map(e=>e.contentId)??[],M=I.length>0&&I.every(e=>m.has(e));function U(e){a(t=>{const i=new Set(t);return i.has(e)?i.delete(e):i.add(e),i})}function H(){a(M?new Set:new Set(I))}function Y(e,t){const o=e.fields?.[t];if(o==null)return"—";if(typeof o=="boolean")return o?"Yes":"No";if(typeof o=="number")return String(o);const y=String(o);return y.length>60?y.slice(0,60)+"…":y}return s.jsxs("div",{children:[!P&&s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:f?.label??c}),s.jsxs(L,{onClick:()=>v(`/sites/${h}/submissions/${c}/new`),children:[s.jsx(X,{className:"mr-1.5 h-4 w-4"}),"New Submission"]})]}),s.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[b.length>0&&s.jsx(re,{relationships:b,activeFilters:A?[A]:[],onFilterAdd:e=>{l({relatedTo:e.contentId,relField:e.relName,page:"1",after:""}),a(new Set)},onFilterRemove:()=>{l({relatedTo:"",relField:"",page:"1",after:""}),a(new Set)}}),s.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[m.size>0&&s.jsxs(L,{variant:"destructive",size:"sm",onClick:async()=>{const e=[...m],i=(await $.mutateAsync(e)).filter(o=>o.status==="rejected").length;i?R.error(`${i} of ${e.length} failed to delete`):R.success(`${e.length} submission(s) deleted`),O()},disabled:$.isPending,children:[s.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete (",m.size,")"]}),s.jsxs(ce,{value:g,onValueChange:e=>{l({sort:e,page:"1",after:""}),a(new Set)},children:[s.jsx(de,{className:"w-[150px]",children:s.jsx(ue,{})}),s.jsx(me,{children:je.map(e=>s.jsx(he,{value:e.value,children:e.label},e.value))})]})]})]}),E?s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,t)=>s.jsx(ee,{className:"h-12 w-full"},t))}):j?.length?s.jsxs(s.Fragment,{children:[P?s.jsx("div",{className:"grid gap-3","data-testid":"submission-card-view",children:j.map(e=>s.jsx(ie,{className:se("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",m.has(e.contentId)&&"ring-2 ring-primary"),onClick:()=>v(`/sites/${h}/submissions/${c}/${e.contentId}`),children:s.jsx(oe,{className:"p-3",children:s.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"font-medium truncate",children:["Submission ",e.contentId.slice(-6)]}),s.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:e.publishedAt?B(e.publishedAt):"—"}),e.siteUser&&s.jsxs("p",{className:"text-xs text-muted-foreground",children:["by ",e.siteUser.name||e.siteUser.userId]})]}),s.jsx(k,{checked:m.has(e.contentId),onCheckedChange:()=>U(e.contentId),onClick:t=>t.stopPropagation(),className:"mt-1"})]})})},e.contentId))}):s.jsxs(fe,{children:[s.jsx(pe,{children:s.jsxs(_,{children:[s.jsx(S,{className:"w-10",children:s.jsx(k,{checked:M,onCheckedChange:H,"aria-label":"Select all"})}),V.map(e=>s.jsx(S,{children:e.label||e.name},e.name)),f?.requireAuth&&s.jsx(S,{children:"Submitted by"}),s.jsx(S,{children:"Submitted"})]})}),s.jsx(xe,{children:j.map(e=>s.jsxs(_,{className:"cursor-pointer",onClick:()=>v(`/sites/${h}/submissions/${c}/${e.contentId}`),children:[s.jsx(N,{onClick:t=>t.stopPropagation(),children:s.jsx(k,{checked:m.has(e.contentId),onCheckedChange:()=>U(e.contentId),"aria-label":`Select submission ${e.contentId.slice(-6)}`})}),V.map(t=>s.jsx(N,{className:"text-muted-foreground text-sm",children:Y(e,t.name)},t.name)),f?.requireAuth&&s.jsx(N,{className:"text-muted-foreground text-sm",children:e.siteUser?e.siteUser.name||e.siteUser.userId:"—"}),s.jsx(N,{className:"text-muted-foreground",children:e.publishedAt?s.jsx("span",{title:ge(e.publishedAt),children:B(e.publishedAt)}):"—"})]},e.contentId))})]}),s.jsx(be,{page:r,hasNext:!!x?.hasMore,hasPrevious:r>1,onNext:()=>{if(x?.items.length){const e=x.items[x.items.length-1].contentId,t=[...T.slice(0,r-1),e];l({page:String(r+1),after:t.join(",")})}else l({page:String(r+1)});a(new Set)},onPrevious:()=>{const e=r-1;l(e<=1?{page:"1",after:""}:{page:String(e)}),a(new Set)},perPage:w,onPerPageChange:e=>{l({perPage:String(e),page:"1",after:""}),a(new Set)}})]}):s.jsx("p",{className:"text-muted-foreground",children:"No submissions yet."})]})}export{Re as SubmissionListPage};