headroom-cms 0.1.11 → 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 (126) hide show
  1. package/admin/.well-known/headroom.json +9 -0
  2. package/admin/assets/{AdminsPage-BnzH9TL3.js → AdminsPage-DUMTsCEp.js} +1 -1
  3. package/admin/assets/{AllContentPage-BtObN6oy.js → AllContentPage-D5ey5AOV.js} +1 -1
  4. package/admin/assets/{ApiKeysPage-DEAa8eyC.js → ApiKeysPage-CzUOSoz_.js} +1 -1
  5. package/admin/assets/{AuditPage-BN9yNsxh.js → AuditPage-CYAg4dbI.js} +1 -1
  6. package/admin/assets/BackupsPage-04_oMy3v.js +1 -0
  7. package/admin/assets/{BlockEditor-3wnisTOZ.js → BlockEditor-s0CRZsjy.js} +3 -3
  8. package/admin/assets/BlockTypeEditPage-D1OFIlJZ.js +1 -0
  9. package/admin/assets/{BlockTypesPage-Dhkho6T_.js → BlockTypesPage-cJNR25fN.js} +1 -1
  10. package/admin/assets/{BulkActionBar-BxdfUSrN.js → BulkActionBar-BWysX7Wo.js} +1 -1
  11. package/admin/assets/{CollectionEditPage-lOb4hEZy.js → CollectionEditPage-DRmCA_73.js} +1 -1
  12. package/admin/assets/{CollectionsPage-CgtOloa1.js → CollectionsPage-CeQB5e9u.js} +1 -1
  13. package/admin/assets/{ContentCreatePage-LeQjahp_.js → ContentCreatePage-Cq8Pi8EF.js} +1 -1
  14. package/admin/assets/ContentEditPage-CEJ7I3WH.js +1 -0
  15. package/admin/assets/{ContentField-pilCbdnA.js → ContentField-BZT4OUfI.js} +1 -1
  16. package/admin/assets/ContentListPage-BCEQrYVs.js +1 -0
  17. package/admin/assets/{CustomBlockPreview-DNnTFM0z.js → CustomBlockPreview-Kc6bb3oq.js} +1 -1
  18. package/admin/assets/FieldRenderer-CT-DgCbC.js +2 -0
  19. package/admin/assets/FileTypeIcon-CNHtffHC.js +1 -0
  20. package/admin/assets/FloatingComposerController-D4uLQfUX-0_Y8mkGU.js +1 -0
  21. package/admin/assets/{IconPicker-CpIgiQTC.js → IconPicker-BpPlHJO0.js} +2 -2
  22. package/admin/assets/{LoginPage-D9ZsGLIi.js → LoginPage-Dya8sF_P.js} +1 -1
  23. package/admin/assets/MediaField-C3qFf3g5.js +1 -0
  24. package/admin/assets/MediaPage-BNxc0wLq.js +1 -0
  25. package/admin/assets/{Pagination-Df9nQ7Z0.js → Pagination-Dx8h11Rn.js} +1 -1
  26. package/admin/assets/{RelationshipPicker-B3Ftmqxp.js → RelationshipPicker-C2MTxrhl.js} +1 -1
  27. package/admin/assets/{SiteSettingsPage-6NvH7CiQ.js → SiteSettingsPage-BDZaUBmf.js} +1 -1
  28. package/admin/assets/{SiteUserEditPage-D5VaQ1Xq.js → SiteUserEditPage-MfzhPW7v.js} +1 -1
  29. package/admin/assets/{SiteUsersPage-BYVduiqs.js → SiteUsersPage-CrYugXpx.js} +1 -1
  30. package/admin/assets/{SitesPage-rfWWE0yK.js → SitesPage-Cl8V3Hb7.js} +1 -1
  31. package/admin/assets/SubmissionDetailPage-BnVlsGb-.js +1 -0
  32. package/admin/assets/SubmissionEditPage-B0Kq52fb.js +1 -0
  33. package/admin/assets/SubmissionListPage-K665VwMp.js +1 -0
  34. package/admin/assets/{TagInput-57c4DG1w.js → TagInput-C6tcB5Xw.js} +1 -1
  35. package/admin/assets/{TagsPage-BEO5AwCv.js → TagsPage-BONR6bSu.js} +1 -1
  36. package/admin/assets/{UsersPage-BpIRorJ1.js → UsersPage-C2iCy0UR.js} +1 -1
  37. package/admin/assets/{WebhookEditPage-D5xgi56h.js → WebhookEditPage-DjZFxT72.js} +1 -1
  38. package/admin/assets/{WebhooksPage-BY7AaiGr.js → WebhooksPage-g_a224a4.js} +1 -1
  39. package/admin/assets/{card-C9hfyHXf.js → card-DlfsF8lU.js} +1 -1
  40. package/admin/assets/{checkbox-DVJcwUt1.js → checkbox-BX8EcGFf.js} +1 -1
  41. package/admin/assets/{command-Bfmj0MEL.js → command-DaTsImUa.js} +1 -1
  42. package/admin/assets/{contentStatus-CkPi9Dh6.js → contentStatus-WXGfd7vX.js} +1 -1
  43. package/admin/assets/format-BRcflvs9.js +1 -0
  44. package/admin/assets/index-9sbb3-yI.css +1 -0
  45. package/admin/assets/{index-Ce5pmRMj.js → index-DC1UyCW2.js} +10 -10
  46. package/admin/assets/listCellValue-CBqXAwce.js +1 -0
  47. package/admin/assets/{popover-CzaQYEEP.js → popover-BA-47SRI.js} +1 -1
  48. package/admin/assets/{select-CrRhFGIi.js → select-waaVyoQ5.js} +1 -1
  49. package/admin/assets/{serializeToText-2VrsuRUh.js → serializeToText-CjHhyvXp.js} +1 -1
  50. package/admin/assets/{table-_3bMY0_z.js → table-Br-QgtTL.js} +1 -1
  51. package/admin/assets/{textarea-6fq0R6VV.js → textarea-BILv1DQB.js} +1 -1
  52. package/admin/assets/useAdminResolver-CbDzGoDp.js +1 -0
  53. package/admin/assets/useContent-Bp4f9qe0.js +1 -0
  54. package/admin/assets/{useContentSearch-B3aTjuCu.js → useContentSearch-DbiA8aG-.js} +1 -1
  55. package/admin/assets/{usePageTitle-C1r1-C00.js → usePageTitle-DOEFrHbj.js} +1 -1
  56. package/admin/assets/{useSiteUsers-DIaqgNSp.js → useSiteUsers-BFYAbJNT.js} +1 -1
  57. package/admin/assets/{useTags-B-HgMVwo.js → useTags-DJlXwDyc.js} +1 -1
  58. package/admin/assets/{useWebhooks-BvZjUJkJ.js → useWebhooks-BkpJKNLN.js} +1 -1
  59. package/admin/index.html +2 -2
  60. package/admin/sw.js +1 -1
  61. package/admin/workbox-362996ec.js +1 -0
  62. package/dist/admin-site.d.ts.map +1 -1
  63. package/dist/admin-site.js +46 -3
  64. package/dist/admin-site.js.map +1 -1
  65. package/dist/api.d.ts +2 -0
  66. package/dist/api.d.ts.map +1 -1
  67. package/dist/api.js +57 -5
  68. package/dist/api.js.map +1 -1
  69. package/dist/backup.d.ts +29 -0
  70. package/dist/backup.d.ts.map +1 -0
  71. package/dist/backup.js +95 -0
  72. package/dist/backup.js.map +1 -0
  73. package/dist/cdn-api.d.ts.map +1 -1
  74. package/dist/cdn-api.js +20 -19
  75. package/dist/cdn-api.js.map +1 -1
  76. package/dist/image.d.ts +8 -1
  77. package/dist/image.d.ts.map +1 -1
  78. package/dist/image.js +26 -6
  79. package/dist/image.js.map +1 -1
  80. package/dist/index.d.ts +3 -0
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +33 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/storage.d.ts +1 -0
  85. package/dist/storage.d.ts.map +1 -1
  86. package/dist/storage.js +21 -0
  87. package/dist/storage.js.map +1 -1
  88. package/dist/webhooks.d.ts +4 -3
  89. package/dist/webhooks.d.ts.map +1 -1
  90. package/dist/webhooks.js +22 -35
  91. package/dist/webhooks.js.map +1 -1
  92. package/lambda/api/bootstrap +0 -0
  93. package/lambda/backup-worker/bootstrap +0 -0
  94. package/lambda/image-lambda/index.mjs +30 -6
  95. package/lambda/image-lambda/node_modules/.package-lock.json +3 -3
  96. package/lambda/image-lambda/node_modules/semver/classes/range.js +7 -0
  97. package/lambda/image-lambda/node_modules/semver/package.json +1 -1
  98. package/lambda/image-lambda/node_modules/semver/ranges/subset.js +2 -2
  99. package/lambda/webhook-worker/bootstrap +0 -0
  100. package/package.json +1 -1
  101. package/src/admin-site.ts +46 -3
  102. package/src/api.ts +58 -5
  103. package/src/backup.ts +114 -0
  104. package/src/cdn-api.ts +20 -22
  105. package/src/image.ts +30 -6
  106. package/src/index.ts +37 -1
  107. package/src/sst-env.d.ts +4 -0
  108. package/src/storage.ts +22 -0
  109. package/src/webhooks.ts +22 -39
  110. package/admin/assets/BlockTypeEditPage-C2evAESK.js +0 -1
  111. package/admin/assets/ContentEditPage-xczr4d_h.js +0 -1
  112. package/admin/assets/ContentListPage-BAKDn1Xy.js +0 -1
  113. package/admin/assets/FieldRenderer-DiOKvkWV.js +0 -2
  114. package/admin/assets/FilterBar-BZoa63zh.js +0 -1
  115. package/admin/assets/FloatingComposerController-D4uLQfUX-BMIvFCoE.js +0 -1
  116. package/admin/assets/MediaField-CxccCFGQ.js +0 -1
  117. package/admin/assets/MediaPage-QvMaH2YJ.js +0 -1
  118. package/admin/assets/SubmissionDetailPage-BSUR685F.js +0 -1
  119. package/admin/assets/SubmissionEditPage-DjLXHjWU.js +0 -1
  120. package/admin/assets/SubmissionListPage-DBxNEvde.js +0 -1
  121. package/admin/assets/format-C88SDH8g.js +0 -1
  122. package/admin/assets/index-BB9Syqw2.css +0 -1
  123. package/admin/assets/useAdminResolver-BJNPz3OG.js +0 -1
  124. package/admin/assets/useContent-Bs7nel7C.js +0 -1
  125. package/admin/assets/useMedia-ae3s_ajC.js +0 -1
  126. package/admin/workbox-7d58179f.js +0 -1
@@ -0,0 +1 @@
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{Z as b,aD as V,S as T,aE as G,aF as Z,aG as z,x as J,L as u,I as K,a2 as B,B as x,a as Q,D as W,i as X,T as Y,k as ee,l as se,m as te,n as ae,o as ie,v as h}from"./index-DC1UyCW2.js";import{I as re,a as ne,F as le}from"./IconPicker-BpPlHJO0.js";import{i as oe}from"./format-BRcflvs9.js";import{T as ce}from"./textarea-BILv1DQB.js";import{C as de,a as me,b as pe,c as ue}from"./card-DlfsF8lU.js";import{C as D,a as $,b as F}from"./collapsible-D3d29uJp.js";import{C as xe}from"./CustomBlockPreview-Kc6bb3oq.js";import{F as he}from"./FieldRenderer-CT-DgCbC.js";import{u as N}from"./useContentSearch-DbiA8aG-.js";import{u as je}from"./usePageTitle-DOEFrHbj.js";import"./radix-C5ZmWuuL.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./select-waaVyoQ5.js";import"./checkbox-BX8EcGFf.js";import"./popover-BA-47SRI.js";import"./media-url-DdCoIedP.js";import"./MediaField-C3qFf3g5.js";import"./FileTypeIcon-CNHtffHC.js";import"./table-Br-QgtTL.js";import"./ContentField-BZT4OUfI.js";import"./command-DaTsImUa.js";function fe({fields:a,previewTemplate:s,previewData:t,onPreviewDataChange:i,blockTypeName:l,blockTypeLabel:d,blockTypeIcon:v}){const r=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:r},props:g,blocksToHTML:()=>""})})]})}function Ve(){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=Z(a,t?.name??""),v=z(a,t?.name??""),[r,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(n=>n.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??r,showBack:!0,backTo:`/sites/${a}/settings/block-types`});async function A(n){n.preventDefault();try{s?(await l.mutateAsync({name:r,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/${r}`)):(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(n){h.error("Failed to delete",{description:n instanceof Error?n.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??r}`}),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(re,{id:"name",value:r,onChange:g,onBlur:()=>{r&&!S&&y(oe(r))},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:n=>{y(n.target.value),L(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Icon"}),e.jsx(ne,{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:n=>O(n.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(D,{children:[e.jsxs($,{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:r,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(W,{open:H,onOpenChange:w,children:[e.jsx(X,{asChild:!0,children:e.jsxs(x,{variant:"destructive",children:[e.jsx(Y,{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(D,{children:[e.jsxs($,{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{Ve as BlockTypeEditPage};
@@ -1 +1 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as h,f as j}from"./react-vendor-C2CvUxFh.js";import{aD as p,x as u,B as c,P as o,S as f,aE as N}from"./index-Ce5pmRMj.js";import{T as g,a as y,b as r,c as l,d as k,e as n}from"./table-_3bMY0_z.js";import{u as T}from"./usePageTitle-C1r1-C00.js";import"./radix-C5ZmWuuL.js";function $(){const{host:a}=h(),i=j(),{data:t,isLoading:m}=p(a),d=u();return T({title:"Block Types",actions:s.jsx(c,{size:"sm",onClick:()=>i(`/sites/${a}/settings/block-types/new`),children:s.jsx(o,{className:"h-4 w-4"})})}),s.jsxs("div",{children:[!d&&s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:"Block Types"}),s.jsxs(c,{onClick:()=>i(`/sites/${a}/settings/block-types/new`),children:[s.jsx(o,{className:"mr-2 h-4 w-4"}),"New Block Type"]})]}),m?s.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((e,x)=>s.jsx(f,{className:"h-12 w-full"},x))}):t?.items.length?s.jsxs(g,{children:[s.jsx(y,{children:s.jsxs(r,{children:[s.jsx(l,{children:"Name"}),s.jsx(l,{children:"Label"}),s.jsx(l,{children:"Icon"}),s.jsx(l,{children:"Fields"})]})}),s.jsx(k,{children:t.items.map(e=>s.jsxs(r,{className:"cursor-pointer",onClick:()=>i(`/sites/${a}/settings/block-types/${e.name}`),children:[s.jsx(n,{className:"font-mono text-sm",children:e.name}),s.jsx(n,{children:e.label}),s.jsx(n,{children:e.icon?s.jsx(N,{name:e.icon,className:"h-4 w-4 text-muted-foreground"}):s.jsx("span",{className:"text-muted-foreground",children:"—"})}),s.jsx(n,{className:"text-muted-foreground",children:e.fields?.length??0})]},e.name))})]}):s.jsx("p",{className:"text-muted-foreground",children:"No block types defined."})]})}export{$ as BlockTypesPage};
1
+ import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as h,f as j}from"./react-vendor-C2CvUxFh.js";import{aB as p,x as u,B as c,P as o,S as f,aC as N}from"./index-DC1UyCW2.js";import{T as g,a as y,b as r,c as l,d as k,e as n}from"./table-Br-QgtTL.js";import{u as T}from"./usePageTitle-DOEFrHbj.js";import"./radix-C5ZmWuuL.js";function $(){const{host:a}=h(),i=j(),{data:t,isLoading:m}=p(a),d=u();return T({title:"Block Types",actions:s.jsx(c,{size:"sm",onClick:()=>i(`/sites/${a}/settings/block-types/new`),children:s.jsx(o,{className:"h-4 w-4"})})}),s.jsxs("div",{children:[!d&&s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:"Block Types"}),s.jsxs(c,{onClick:()=>i(`/sites/${a}/settings/block-types/new`),children:[s.jsx(o,{className:"mr-2 h-4 w-4"}),"New Block Type"]})]}),m?s.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((e,x)=>s.jsx(f,{className:"h-12 w-full"},x))}):t?.items.length?s.jsxs(g,{children:[s.jsx(y,{children:s.jsxs(r,{children:[s.jsx(l,{children:"Name"}),s.jsx(l,{children:"Label"}),s.jsx(l,{children:"Icon"}),s.jsx(l,{children:"Fields"})]})}),s.jsx(k,{children:t.items.map(e=>s.jsxs(r,{className:"cursor-pointer",onClick:()=>i(`/sites/${a}/settings/block-types/${e.name}`),children:[s.jsx(n,{className:"font-mono text-sm",children:e.name}),s.jsx(n,{children:e.label}),s.jsx(n,{children:e.icon?s.jsx(N,{name:e.icon,className:"h-4 w-4 text-muted-foreground"}):s.jsx("span",{className:"text-muted-foreground",children:"—"})}),s.jsx(n,{className:"text-muted-foreground",children:e.fields?.length??0})]},e.name))})]}):s.jsx("p",{className:"text-muted-foreground",children:"No block types defined."})]})}export{$ as BlockTypesPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as m}from"./react-vendor-C2CvUxFh.js";import{B as a,a as t,X as x,D as h,k as j,l as p,m as u,n as D,o as b}from"./index-Ce5pmRMj.js";function k({selectedCount:i,onPublish:n,onUnpublish:r,onDelete:o,onClear:c,isPending:s}){const[d,l]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-md border bg-muted/50 px-4 py-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:[i," selected"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a,{size:"sm",variant:"outline",onClick:n,disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Publish"]}),e.jsx(a,{size:"sm",variant:"outline",onClick:r,disabled:s,children:"Unpublish"}),e.jsx(a,{size:"sm",variant:"destructive",onClick:()=>l(!0),disabled:s,children:"Delete"})]}),e.jsx(a,{size:"sm",variant:"ghost",onClick:c,className:"ml-auto",disabled:s,children:e.jsx(x,{className:"h-4 w-4"})})]}),e.jsx(h,{open:d,onOpenChange:l,children:e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsxs(u,{children:["Delete ",i," item",i!==1?"s":"","?"]}),e.jsx(D,{children:"This action cannot be undone. The selected content items will be permanently deleted."})]}),e.jsxs(b,{children:[e.jsx(a,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(a,{variant:"destructive",onClick:async()=>{l(!1),await o()},disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})})]})}export{k as B};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as m}from"./react-vendor-C2CvUxFh.js";import{B as a,a as t,X as x,D as h,k as j,l as p,m as u,n as D,o as b}from"./index-DC1UyCW2.js";function k({selectedCount:i,onPublish:n,onUnpublish:r,onDelete:o,onClear:c,isPending:s}){const[d,l]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-md border bg-muted/50 px-4 py-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:[i," selected"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a,{size:"sm",variant:"outline",onClick:n,disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Publish"]}),e.jsx(a,{size:"sm",variant:"outline",onClick:r,disabled:s,children:"Unpublish"}),e.jsx(a,{size:"sm",variant:"destructive",onClick:()=>l(!0),disabled:s,children:"Delete"})]}),e.jsx(a,{size:"sm",variant:"ghost",onClick:c,className:"ml-auto",disabled:s,children:e.jsx(x,{className:"h-4 w-4"})})]}),e.jsx(h,{open:d,onOpenChange:l,children:e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsxs(u,{children:["Delete ",i," item",i!==1?"s":"","?"]}),e.jsx(D,{children:"This action cannot be undone. The selected content items will be permanently deleted."})]}),e.jsxs(b,{children:[e.jsx(a,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(a,{variant:"destructive",onClick:async()=>{l(!1),await o()},disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})})]})}export{k as B};
@@ -1 +1 @@
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-Ce5pmRMj.js";import{I as Q,F as qe,a as $e}from"./IconPicker-CpIgiQTC.js";import{i as Z,c as Me}from"./format-C88SDH8g.js";import{C as O}from"./checkbox-DVJcwUt1.js";import{C as W,a as Y,b as G,c as X}from"./card-C9hfyHXf.js";import{u as _e}from"./usePageTitle-C1r1-C00.js";import{S as q,a as $,b as M,c as _,d as g}from"./select-CrRhFGIi.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-6fq0R6VV.js";import"./popover-CzaQYEEP.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","datetime","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
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r,u as je,f as be}from"./react-vendor-C2CvUxFh.js";import{af as pe,a2 as fe,y as ve,av as Ce,B as N,T as J,I as L,P as Se,aw as Ne,S as U,x as ye,w as ke,ax as De,ay as Ee,az as Pe,L as m,aA as Ie,Z as z,a as Fe,D as Le,i as Re,k as Te,l as we,m as Ae,n as Be,o as Oe,v as P}from"./index-DC1UyCW2.js";import{I as K,F as qe,a as $e}from"./IconPicker-BpPlHJO0.js";import{i as Q,c as Me}from"./format-BRcflvs9.js";import{C as O}from"./checkbox-BX8EcGFf.js";import{C as Y,a as G,b as W,c as X}from"./card-DlfsF8lU.js";import{u as _e}from"./usePageTitle-DOEFrHbj.js";import{S as q,a as $,b as M,c as _,d as g}from"./select-waaVyoQ5.js";import{C as Ve,b as He,c as Ue,P as ze,D as Ye,e as Ge}from"./core.esm-DdQHdRkd.js";import{u as We,S as Xe,v as Ze,a as Je}from"./sortable.esm-qVEMoaTg.js";import{C as Ke,a as Qe,b as es}from"./collapsible-D3d29uJp.js";import"./radix-C5ZmWuuL.js";import"./textarea-BILv1DQB.js";import"./popover-BA-47SRI.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}=We({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(Ke,{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(Qe,{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(J,{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(K,{value:s.name,onChange:n=>x({name:n}),onBlur:()=>{s.name&&!d&&x({label:Q(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(Je(l,C,y))}}return e.jsx(Ye,{sensors:j,collisionDetection:Ge,onDragEnd:v,children:e.jsx(Xe,{items:p,strategy:Ze,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","datetime","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(Z,{host:l,isNew:!0}):u?e.jsx(Z,{host:l,isNew:!1,collection:u},u.name):e.jsx("p",{className:"text-muted-foreground",children:"Collection not found."})}function Z({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:[])),[w,ce]=r.useState(a?.relationships??[]),de=new Set((a?.relationships??[]).map(t=>t.name).filter(Boolean)),[A,ue]=r.useState(a?.mobileNavPriority??0),[B,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=Q(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:w,mobileNavPriority:A,icon:B,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:w,mobileNavPriority:A,icon:B,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(Y,{children:[e.jsx(G,{children:e.jsx(W,{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(K,{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:w,onChange:ce,collections:p,existingRelNames:de})]})]})})]}),e.jsxs(Y,{className:"mt-6",children:[e.jsx(G,{children:e.jsx(W,{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:B,onChange:me})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"mobileNavPriority",children:"Bottom Nav Priority"}),e.jsxs(q,{value:String(A),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(J,{className:"mr-2 h-4 w-4"}),"Delete Collection"]})}),e.jsxs(Te,{children:[e.jsxs(we,{children:[e.jsx(Ae,{children:"Delete collection?"}),e.jsx(Be,{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 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as j,f as u}from"./react-vendor-C2CvUxFh.js";import{aw as f,x as g,B as o,P as c,S as b,j as r}from"./index-Ce5pmRMj.js";import{T as p,a as N,b as d,c as i,d as C,e as n}from"./table-_3bMY0_z.js";import{u as w}from"./usePageTitle-C1r1-C00.js";import"./radix-C5ZmWuuL.js";function $(){const{host:l}=j(),a=u(),{data:t,isLoading:m}=f(l),x=g();return w({title:"Collections",actions:e.jsx(o,{size:"sm",onClick:()=>a(`/sites/${l}/settings/collections/new`),children:e.jsx(c,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[!x&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Collections"}),e.jsxs(o,{onClick:()=>a(`/sites/${l}/settings/collections/new`),children:[e.jsx(c,{className:"mr-2 h-4 w-4"}),"New Collection"]})]}),m?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((s,h)=>e.jsx(b,{className:"h-12 w-full"},h))}):t?.items.length?e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(d,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Label"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Fields"})]})}),e.jsx(C,{children:t.items.map(s=>e.jsxs(d,{className:"cursor-pointer",onClick:()=>a(`/sites/${l}/settings/collections/${s.name}`),children:[e.jsx(n,{className:"font-mono text-sm",children:s.name}),e.jsx(n,{children:s.label}),e.jsx(n,{children:s.singleton?e.jsx(r,{variant:"secondary",children:"Singleton"}):e.jsx(r,{variant:"outline",children:"Collection"})}),e.jsx(n,{className:"text-muted-foreground",children:s.fields?.length??0})]},s.name))})]}):e.jsx("p",{className:"text-muted-foreground",children:"No collections defined."})]})}export{$ as CollectionsPage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as j,f as u}from"./react-vendor-C2CvUxFh.js";import{au as f,x as g,B as o,P as c,S as b,j as r}from"./index-DC1UyCW2.js";import{T as p,a as N,b as d,c as i,d as C,e as n}from"./table-Br-QgtTL.js";import{u as T}from"./usePageTitle-DOEFrHbj.js";import"./radix-C5ZmWuuL.js";function $(){const{host:l}=j(),a=u(),{data:t,isLoading:m}=f(l),x=g();return T({title:"Collections",actions:e.jsx(o,{size:"sm",onClick:()=>a(`/sites/${l}/settings/collections/new`),children:e.jsx(c,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[!x&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Collections"}),e.jsxs(o,{onClick:()=>a(`/sites/${l}/settings/collections/new`),children:[e.jsx(c,{className:"mr-2 h-4 w-4"}),"New Collection"]})]}),m?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((s,h)=>e.jsx(b,{className:"h-12 w-full"},h))}):t?.items.length?e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(d,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Label"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Fields"})]})}),e.jsx(C,{children:t.items.map(s=>e.jsxs(d,{className:"cursor-pointer",onClick:()=>a(`/sites/${l}/settings/collections/${s.name}`),children:[e.jsx(n,{className:"font-mono text-sm",children:s.name}),e.jsx(n,{children:s.label}),e.jsx(n,{children:s.singleton?e.jsx(r,{variant:"secondary",children:"Singleton"}):e.jsx(r,{variant:"outline",children:"Collection"})}),e.jsx(n,{className:"text-muted-foreground",children:s.fields?.length??0})]},s.name))})]}):e.jsx("p",{className:"text-muted-foreground",children:"No collections defined."})]})}export{$ as CollectionsPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as E,f as P,r as i,m as I,N as T}from"./react-vendor-C2CvUxFh.js";import{w as F,x as k,L as g,I as h,B as f,a as A,v as p,C as B}from"./index-Ce5pmRMj.js";import{e as L}from"./useContent-Bs7nel7C.js";import{C as D,a as H,b as M,c as q}from"./card-C9hfyHXf.js";import{u as R}from"./usePageTitle-C1r1-C00.js";import{s as z}from"./format-C88SDH8g.js";import"./radix-C5ZmWuuL.js";function X(){const{host:a,collection:s}=E(),c=P(),{collections:C}=F(),o=L(a),[l,j]=i.useState(""),[u,d]=i.useState(""),[v,b]=i.useState(!1),[m,x]=i.useState(null),N=k(),[S]=I(),r=C.find(t=>t.name===s),$=S.get("from")==="recent"?`/sites/${a}/content`:`/sites/${a}/content/${s}`;if(R({title:`New ${r?.labelSingular??s}`,showBack:!0,backTo:$}),r?.singleton){const t=r.singletonContentId?`/sites/${a}/content/${s}/${r.singletonContentId}`:`/sites/${a}/content/${s}`;return e.jsx(T,{to:t,replace:!0})}function y(t){j(t),v||d(z(t))}async function w(t){t.preventDefault(),x(null);try{const n=await o.mutateAsync({collection:s,title:l,slug:u||void 0});p.success("Content created"),c(`/sites/${a}/content/${s}/${n.contentId}`)}catch(n){n instanceof B&&n.status===409?x("A content item with this slug already exists. Choose a different slug."):p.error("Failed to create content",{description:n instanceof Error?n.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!N&&e.jsxs("h1",{className:"mb-6 text-2xl font-semibold",children:["New ",r?.labelSingular??s]}),e.jsxs(D,{children:[e.jsx(H,{children:e.jsx(M,{children:"Details"})}),e.jsx(q,{children:e.jsxs("form",{onSubmit:w,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"title",children:"Title"}),e.jsx(h,{id:"title",value:l,onChange:t=>y(t.target.value),required:!0,autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"slug",children:"Slug"}),e.jsx(h,{id:"slug",value:u,onChange:t=>{d(t.target.value),b(!0)}})]}),m&&e.jsx("p",{className:"text-sm text-destructive",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{type:"submit",disabled:!l||o.isPending,children:[o.isPending&&e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create"]}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>c(-1),children:"Cancel"})]})]})})]})]})}export{X as ContentCreatePage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as E,f as P,r as i,m as I,N as T}from"./react-vendor-C2CvUxFh.js";import{w as F,x as k,L as g,I as h,B as f,a as A,v as p,C as B}from"./index-DC1UyCW2.js";import{e as L}from"./useContent-Bp4f9qe0.js";import{C as D,a as H,b as M,c as q}from"./card-DlfsF8lU.js";import{u as R}from"./usePageTitle-DOEFrHbj.js";import{s as z}from"./format-BRcflvs9.js";import"./radix-C5ZmWuuL.js";function X(){const{host:a,collection:s}=E(),c=P(),{collections:C}=F(),o=L(a),[l,j]=i.useState(""),[u,d]=i.useState(""),[v,b]=i.useState(!1),[m,x]=i.useState(null),N=k(),[S]=I(),r=C.find(t=>t.name===s),$=S.get("from")==="recent"?`/sites/${a}/content`:`/sites/${a}/content/${s}`;if(R({title:`New ${r?.labelSingular??s}`,showBack:!0,backTo:$}),r?.singleton){const t=r.singletonContentId?`/sites/${a}/content/${s}/${r.singletonContentId}`:`/sites/${a}/content/${s}`;return e.jsx(T,{to:t,replace:!0})}function y(t){j(t),v||d(z(t))}async function w(t){t.preventDefault(),x(null);try{const n=await o.mutateAsync({collection:s,title:l,slug:u||void 0});p.success("Content created"),c(`/sites/${a}/content/${s}/${n.contentId}`)}catch(n){n instanceof B&&n.status===409?x("A content item with this slug already exists. Choose a different slug."):p.error("Failed to create content",{description:n instanceof Error?n.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!N&&e.jsxs("h1",{className:"mb-6 text-2xl font-semibold",children:["New ",r?.labelSingular??s]}),e.jsxs(D,{children:[e.jsx(H,{children:e.jsx(M,{children:"Details"})}),e.jsx(q,{children:e.jsxs("form",{onSubmit:w,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"title",children:"Title"}),e.jsx(h,{id:"title",value:l,onChange:t=>y(t.target.value),required:!0,autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"slug",children:"Slug"}),e.jsx(h,{id:"slug",value:u,onChange:t=>{d(t.target.value),b(!0)}})]}),m&&e.jsx("p",{className:"text-sm text-destructive",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{type:"submit",disabled:!l||o.isPending,children:[o.isPending&&e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create"]}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>c(-1),children:"Cancel"})]})]})})]})]})}export{X as ContentCreatePage};
@@ -0,0 +1 @@
1
+ import{a as Vt,u as On,b as Bn,j as e}from"./tanstack-Bs3zYPPV.js";import{r as t,u as qn,f as _n,m as $n,L as Vn}from"./react-vendor-C2CvUxFh.js";import{f as Mn,g as Es,h as Hn,i as Ps,j as Jn,k as zn,l as Kn,m as Yn,n as Qn,o as Wn,p as Gn,q as Xn,r as Ls}from"./useContent-Bp4f9qe0.js";import{C as Ce,E as os,F as lt,v as J,G as Mt,e as ft,u as Ht,J as Nt,B as F,K as Zn,y as mt,M as ea,N as ta,O as sa,Q as na,S as ve,R as Ts,V as Is,W as ot,Y as dt,Z as Us,_ as Fs,$ as Os,a0 as Bs,U as aa,a1 as ra,w as ia,d as la,x as ca,L as at,I as ds,a2 as qs,X as us,a3 as oa,a4 as hs,a5 as da,a6 as fs,a7 as ua,j as ha,a as we,a8 as ms,a9 as ps,aa as fa,ab as gs,ac as At,ad as ma,ae as pa,D as Ut,k as Ft,l as Ot,m as Bt,n as qt,o as _t,i as ga,T as ba}from"./index-DC1UyCW2.js";import{A as _s,a as $s,b as Vs,c as Ms,d as Hs,e as Js,f as zs,g as Ks,T as xa}from"./TagInput-C6tcB5Xw.js";import{a as ct,f as Ne}from"./format-BRcflvs9.js";import{u as Ys}from"./useAdminResolver-CbDzGoDp.js";import{u as va}from"./usePageTitle-DOEFrHbj.js";import{s as Me,T as ya,d as ka}from"./serializeToText-CjHhyvXp.js";import{S as ja,a as Sa,b as wa,c as Ca,d as Dt,e as Ra,f as Na,g as Aa}from"./select-waaVyoQ5.js";import{T as Da}from"./textarea-BILv1DQB.js";import{C as $e,c as Ve,a as bs,b as xs}from"./card-DlfsF8lU.js";import{C as Qs,a as Ws,b as Gs}from"./collapsible-D3d29uJp.js";import{u as Ea}from"./useTags-DJlXwDyc.js";import{M as Pa}from"./MediaField-C3qFf3g5.js";import{m as La}from"./media-url-DdCoIedP.js";import{R as Ta}from"./RelationshipPicker-C2MTxrhl.js";import{A as Ia,a as Ua,i as Fa,F as Oa,b as rt,C as Ba}from"./FieldRenderer-CT-DgCbC.js";import{g as qa,a as _a,b as $a}from"./contentStatus-WXGfd7vX.js";import{O as Va,f as Ma,g as ut,e as Xs,w as Et,a as Ha,t as Ja,r as Pt,b as za,c as Ka,d as Ya,h as Qa,i as vs,j as Wa,D as Ga}from"./yjs-tXBm_srz.js";import"./radix-C5ZmWuuL.js";import"./FileTypeIcon-CNHtffHC.js";import"./table-Br-QgtTL.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./ContentField-BZT4OUfI.js";import"./popover-BA-47SRI.js";import"./command-DaTsImUa.js";import"./useContentSearch-DbiA8aG-.js";import"./checkbox-BX8EcGFf.js";const Xa=3e3,Za="__HEADROOM_API_URL__".replace(/\/+$/,""),er=4;function tr(i,s,r,a,l,c=Xa,f,d={}){const p=Mn(i,s),o=t.useRef(null),y=t.useRef(r?JSON.stringify(r):""),x=t.useRef(void 0),[R,P]=t.useState(null),[j,O]=t.useState(null),A=t.useRef(!1),D=t.useRef(!1),v=t.useRef(!1),S=t.useRef(!1),L=t.useRef(!1),B=t.useRef(!1),q=t.useRef(0),U=t.useRef(null),X=t.useCallback(N=>{const k=1e3*Math.pow(3,N);return Math.min(k,3e4)},[]),T=t.useRef(null),E=t.useRef(null),[ne,ae]=t.useState(!1),se=t.useRef(!1),M=t.useCallback(N=>{se.current!==N&&(se.current=N,ae(N))},[]),re=t.useRef(f);t.useEffect(()=>{re.current=f},[f]);const G=t.useRef(d.onBeforeFirstSave);t.useEffect(()=>{G.current=d.onBeforeFirstSave},[d.onBeforeFirstSave]);const Z=t.useRef(d.onStaleBaseConflict);t.useEffect(()=>{Z.current=d.onStaleBaseConflict},[d.onStaleBaseConflict]);const _=t.useRef(d.getCurrentParams);t.useEffect(()=>{_.current=d.getCurrentParams},[d.getCurrentParams]);const w=t.useRef(d.getBaseUpdatedAt);t.useEffect(()=>{w.current=d.getBaseUpdatedAt},[d.getBaseUpdatedAt]);const $=t.useRef(d.onNetworkError);t.useEffect(()=>{$.current=d.onNetworkError},[d.onNetworkError]);const u=t.useRef(()=>{}),m=t.useCallback(()=>{if(B.current||!o.current)return;const N=X(q.current);q.current=Math.min(q.current+1,er),clearTimeout(x.current),x.current=window.setTimeout(()=>u.current(),N)},[X]),H=t.useCallback(N=>{if(N instanceof Ce&&N.status>=500)return $.current?.({kind:"server-error",status:N.status,retryAttempt:q.current}),!0;const k=N;if(k?.name==="AbortError"){const K=k.cause;return(K&&typeof K=="object"&&"message"in K?String(K.message??""):String(K??""))===os&&$.current?.({kind:"timeout",retryAttempt:q.current}),!0}return N instanceof Ce?!1:($.current?.({kind:"network",retryAttempt:q.current}),!0)},[]),Y=t.useCallback(async()=>{if(B.current||L.current||!o.current||v.current||D.current)return;v.current=!0,T.current=new Promise(h=>{E.current=h});const N=()=>{const h=E.current;E.current=null,T.current=null,h?.()};if(!S.current&&G.current)try{if(!(await G.current()).ok){v.current=!1,N();return}S.current=!0}catch{v.current=!1,N();return}if(B.current||!o.current){v.current=!1,N();return}if(D.current){v.current=!1,N();return}const k=o.current,K=w.current?.();U.current||(U.current=lt());const ce={...k,...typeof K=="number"&&K>0?{baseUpdatedAt:K}:{},idempotencyKey:U.current},Q=JSON.stringify(ce);p.mutate(ce,{onSuccess:h=>{if(v.current=!1,N(),q.current=0,A.current){A.current=!1;return}U.current=null,o.current===k&&(o.current=null,M(!1)),y.current=Q,P(Date.now()),h?.blockId&&O(h.blockId),re.current?.(h),!B.current&&o.current&&(clearTimeout(x.current),x.current=window.setTimeout(()=>u.current(),500))},onError:h=>{if(v.current=!1,N(),h instanceof Ce&&h.code==="SLUG_TAKEN"){a?.();return}if(h instanceof Ce&&h.code==="LOCK_HELD"){S.current=!1,l?.(h);return}if(h instanceof Ce&&h.code==="STALE_BASE"){const C=h.body;Z.current?.(C?.currentUpdatedAt??0,C?.currentBlockId??"");return}if(h instanceof Ce&&h.status===400){J.error("Auto-save failed",{description:h.message});return}if(h instanceof Ce&&h.status>=500){$.current?.({kind:"server-error",status:h.status,retryAttempt:q.current}),m();return}const I=h;if(I?.name==="AbortError"){const C=I.cause;(C&&typeof C=="object"&&"message"in C?String(C.message??""):String(C??""))===os&&($.current?.({kind:"timeout",retryAttempt:q.current}),m());return}$.current?.({kind:"network",retryAttempt:q.current}),m()}})},[p,a,l,M,m]);t.useEffect(()=>{u.current=Y},[Y]);const ue=t.useCallback(N=>{L.current||JSON.stringify(N)===y.current||(U.current=lt(),o.current=N,M(!0),clearTimeout(x.current),x.current=window.setTimeout(Y,c))},[c,M,Y]),z=t.useCallback(async N=>{if(clearTimeout(x.current),D.current=!0,T.current)try{await T.current}catch{}try{let k=null;if(o.current?k={...o.current}:N?.createVersion&&_.current&&(k=_.current()),!k)return;const K=w.current?.();if(typeof K=="number"&&K>0&&(k.baseUpdatedAt=K),U.current||(U.current=lt()),k.idempotencyKey=U.current,N?.createVersion&&(k.createVersion=!0),!S.current&&G.current)try{if(!(await G.current()).ok)return;S.current=!0}catch{return}const ce=JSON.stringify(k);o.current=null,M(!1);try{const Q=await p.mutateAsync(k);y.current=ce,P(Date.now()),Q?.blockId&&O(Q.blockId),U.current=null}catch(Q){if(o.current||(o.current=k,M(!0)),!H(Q))throw Q}}finally{D.current=!1}},[p,M,H]),pe=t.useCallback(()=>{clearTimeout(x.current),o.current=null,M(!1),U.current=null},[M]),te=t.useCallback(()=>{S.current=!1},[]),Oe=t.useCallback(N=>{y.current=JSON.stringify(N),S.current=!1,U.current=null},[]),Ae=t.useCallback(()=>{clearTimeout(x.current),o.current=null,M(!1),A.current=!0,O(null),S.current=!1,U.current=null},[M]),Be=t.useCallback(()=>{L.current=!0,clearTimeout(x.current)},[]),b=t.useCallback(()=>{L.current=!1},[]);return t.useEffect(()=>(B.current=!1,()=>{if(B.current=!0,clearTimeout(x.current),o.current){const{sessionId:N,...k}=o.current,K=w.current?.(),ce={...k,...typeof K=="number"&&K>0?{baseUpdatedAt:K}:{}},Q=JSON.stringify(ce),h=Mt(),I=`${Za}/v1/admin/sites/${i}/content/${s}/draft`;fetch(I,{method:"PUT",body:Q,headers:{"Content-Type":"application/json",...h?{Authorization:`Bearer ${h}`}:{}},keepalive:!0}).catch(()=>{}),o.current=null}}),[i,s]),{schedule:ue,flush:z,cancel:pe,resetBaseline:Oe,discard:Ae,pause:Be,resume:b,markLockReleased:te,isDirty:ne,isSaving:p.isPending,lastSavedAt:R,lastSavedBlockId:j,adoptServerBlockId:N=>{O(N)},getIsSavingSync:()=>v.current||D.current,getHasPending:()=>o.current!==null}}const ys="headroom:idleHintShown",sr="__HEADROOM_API_URL__".replace(/\/+$/,""),nr=5e3,ar=3600*1e3,rr=6e4,Lt=2e3;function ir(i){const s=`headroom:editSession:${i}`;let r=sessionStorage.getItem(s);return r||(r=lt(),sessionStorage.setItem(s,r)),r}const Tt=new Map;function lr(i,s,r={}){const a=ft(),{user:l}=Ht(),c=Vt(),[f,d]=t.useState("viewing"),[p,o]=t.useState(null),[y,x]=t.useState(null),[R,P]=t.useState([]),[j,O]=t.useState(!1),[A,D]=t.useState(!1),v=s?ir(s):"",S=t.useRef(0),L=t.useRef(!1),B=t.useRef(!1),q=t.useRef(!1),U=t.useRef(null),X=t.useRef(null),T=t.useRef(0),E=t.useRef(null),ne=t.useRef(r.getIsDirty),ae=t.useRef(r.getIsSaving),se=t.useRef(r.getIsSavingSync),M=t.useRef(r.onIdleRelease),re=t.useRef(r.onLockAcquired);t.useEffect(()=>{ne.current=r.getIsDirty,ae.current=r.getIsSaving,se.current=r.getIsSavingSync,M.current=r.onIdleRelease,re.current=r.onLockAcquired});const G=t.useCallback(async(h=!1)=>{if(!i||!s||!v)return null;const I=`${i}:${s}:${h?"force":"edit"}`,C=Tt.get(I);if(C)return C;const he=a.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock`,{method:"POST",body:JSON.stringify({sessionId:v,force:h,email:l?.email,name:l?.name})}).finally(()=>{Tt.delete(I)});return Tt.set(I,he),he},[a,i,s,v,l?.email,l?.name]),Z=t.useCallback(async()=>{if(!(!i||!s||!v)&&!B.current&&!q.current){B.current=!0,q.current=!0;try{await a.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock`,{method:"DELETE",body:JSON.stringify({sessionId:v})})}catch{}finally{q.current=!1}}},[a,i,s,v]),_=t.useCallback(()=>{U.current&&(clearTimeout(U.current),U.current=null),X.current&&(clearTimeout(X.current),X.current=null)},[]),w=t.useRef(()=>{}),$=t.useCallback(()=>{const h=ne.current?ne.current():!1,I=ae.current?ae.current():!1,C=se.current?se.current():!1;if(h||I||C){X.current=setTimeout(()=>w.current(),1e3);return}if(L.current){L.current=!1,Z(),M.current?.(),d("idle-released"),o(null),x(null),P([]),D(!1);try{typeof window<"u"&&window.sessionStorage&&(window.sessionStorage.getItem(ys)||(J("Released editing — others can edit now."),window.sessionStorage.setItem(ys,"1")))}catch{}}},[Z]);t.useEffect(()=>{w.current=$},[$]);const u=t.useCallback(()=>{_(),U.current=setTimeout($,rr)},[_,$]),m=t.useCallback(()=>{if(A){_();return}L.current&&u()},[A,_,u]),H=t.useRef(A);t.useEffect(()=>{const h=H.current;H.current=A,h!==A&&(A?_():L.current&&u())},[A,_,u]);const Y=t.useCallback(async()=>{if(!i||!s||!v||!l)return{ok:!1,holder:null};if(Date.now()<T.current)return{ok:!1,holder:E.current};try{const h=await G(!1);if(!h||!h.acquired){const I=h?.lockHolder??null;return T.current=Date.now()+Lt,E.current=I,d("blocked-edit"),o(I),D(h?.collaborationEnabled??!1),S.current||(S.current=Date.now()),{ok:!1,holder:I}}return L.current=!0,B.current=!1,T.current=0,E.current=null,d("editing"),o(h.lockHolder??null),x(h.takeoverReason),D(h.collaborationEnabled),u(),re.current?.(h.updatedAt??0),{ok:!0}}catch(h){const I=h;if(I.status===409){const C=I.body?.lockHolder??null,he=I.body?.collaborationEnabled??!1;if(C&&C.sub===l.sub&&C.sessionId!==v)try{const ee=await G(!1);if(ee?.acquired)return L.current=!0,B.current=!1,T.current=0,E.current=null,d("editing"),o(ee.lockHolder??null),x(ee.takeoverReason),D(ee.collaborationEnabled),u(),re.current?.(ee.updatedAt??0),{ok:!0}}catch{}return T.current=Date.now()+Lt,E.current=C,d("blocked-edit"),o(C),D(he),S.current||(S.current=Date.now()),{ok:!1,holder:C}}return d("error"),{ok:!1,holder:null}}},[i,s,v,l,G,u]);t.useEffect(()=>{if(!i||!s||!v)return;const h=()=>{if(!L.current||B.current||q.current)return;B.current=!0;const I=Mt(),C=`${sr}/v1/admin/sites/${i}/content/${s}/edit-lock`;fetch(C,{method:"DELETE",body:JSON.stringify({sessionId:v}),headers:{"Content-Type":"application/json",...I?{Authorization:`Bearer ${I}`}:{}},keepalive:!0}).catch(()=>{})};return window.addEventListener("beforeunload",h),()=>window.removeEventListener("beforeunload",h)},[i,s,v]);const ue=t.useRef(Z),z=t.useRef(_);t.useEffect(()=>{ue.current=Z,z.current=_},[Z,_]),t.useEffect(()=>()=>{z.current(),L.current&&(L.current=!1,ue.current())},[i,s,v]);const pe=f==="blocked-edit"&&!j,te=t.useCallback(h=>{if(S.current&&Date.now()-S.current>ar){O(!0),d("poll-ceiling");return}const I=h.lock;if(!I)T.current=0,E.current=null,o(null),D(!1),P([]),d("idle-released"),S.current=0;else{o(I.heldBy),D(I.collaborationEnabled);const C=(I.accessRequests??[]).filter(he=>he.sub!==l?.sub);P(C)}},[l?.sub]);On({queryKey:["sites",i,"edit-lock",s],queryFn:async()=>{try{const h=await a.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock`);return te(h),h}catch{return{lock:p?{heldBy:p,expiresAt:0,collaborationEnabled:A,accessRequests:[]}:null}}},enabled:pe,refetchInterval:pe?nr:!1,refetchIntervalInBackground:!1,retry:!1});const Oe=Bn({mutationFn:()=>a.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock/access-requests`,{method:"POST",body:JSON.stringify({sessionId:v,email:l?.email,name:l?.name})})}),Ae=t.useCallback(async()=>{const h=await G(!0);return h?.acquired&&(L.current=!0,B.current=!1,T.current=0,E.current=null,d("editing"),o(h.lockHolder??null),x(h.takeoverReason),D(h.collaborationEnabled),u(),re.current?.(h.updatedAt??0),c.invalidateQueries({queryKey:["sites",i,"edit-lock",s]})),h},[G,c,i,s,u]),Be=t.useCallback(async()=>Y(),[Y]),b=t.useCallback(h=>{L.current=!1,_(),T.current=Date.now()+Lt,E.current=h.lockHolder??null,d("blocked-edit"),o(h.lockHolder??null),x(h.takeoverReason??null),S.current||(S.current=Date.now())},[_]),N=t.useCallback(()=>{_(),L.current&&(L.current=!1,Z()),T.current=0,E.current=null,d("viewing"),o(null),x(null),D(!1),P([]),S.current=0},[_,Z]),k=t.useCallback(()=>{_(),d("stale-reload-pending")},[_]),K=t.useCallback(()=>{d("editing"),L.current&&u()},[u]),ce=t.useCallback(()=>{_(),T.current=0,E.current=null,d("read-only-explicit")},[_]),Q=t.useCallback(()=>{d("viewing")},[]);return{status:f,lockHolder:p,takeoverReason:y,accessRequests:R,sessionId:v,pollCeiling:j,collaborationEnabled:A,acquireLock:G,releaseLock:Z,tryAcquireForEdit:Y,bumpIdleTimer:m,requestCollaboration:Oe,forceTakeover:Ae,takeEditing:Be,endEditing:N,setStaleReloadPending:k,resumeEditingAfterStale:K,setReadOnlyExplicit:ce,exitReadOnly:Q,onAutosaveConflict:b,setAccessRequests:P,setCollaborationEnabled:D}}function cr({host:i,contentId:s,isDirty:r,serverBlockId:a,serverUpdatedAt:l,onSilentReload:c,onStaleWithDirty:f,onTabHidden:d,onTabVisibleResume:p,minHiddenMs:o=3e4}){const y=Vt(),x=t.useRef(null),R=t.useRef(r),P=t.useRef(a),j=t.useRef(l),O=t.useRef(c),A=t.useRef(f),D=t.useRef(d),v=t.useRef(p),S=t.useRef(o);t.useEffect(()=>{R.current=r,P.current=a,j.current=l,O.current=c,A.current=f,D.current=d,v.current=p,S.current=o},[r,a,l,c,f,d,p,o]),t.useEffect(()=>{if(typeof document>"u"||!i||!s)return;const L=["sites",i,"content-detail",s];let B=!1;const q=async()=>{if(typeof document>"u")return;if(document.visibilityState==="hidden"){x.current=Date.now(),D.current&&D.current();return}if(document.visibilityState!=="visible")return;const U=x.current;if(x.current=null,U==null)return;if(Date.now()-U<S.current){v.current&&v.current();return}if(await y.refetchQueries({queryKey:[...L],exact:!0}),B)return;const T=y.getQueryData([...L]);if(!T){v.current&&v.current();return}const E=T.draft?.updatedAt,ne=T.draft?.blockId,ae=j.current??0,se=P.current??null;if(!(typeof E=="number"&&E>ae||ne!=null&&ne!==se)){v.current&&v.current();return}B||(R.current?A.current(T):(v.current&&v.current(),O.current(T)))};return document.addEventListener("visibilitychange",q),()=>{B=!0,document.removeEventListener("visibilitychange",q)}},[i,s,y])}function Jt(){return"__HEADROOM_COLLAB_ENABLED__"!=="false"}function ks({variant:i="read-only-explicit",lockHolder:s,onRequestCollaboration:r,onForceTakeover:a,onDiscardPending:l,onViewReadOnly:c,onResumeEditing:f,isRequesting:d,requestSent:p}){if(i==="poll-ceiling")return e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mb-4","data-testid":"edit-lock-banner","data-variant":"poll-ceiling",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Nt,{className:"h-5 w-5 text-amber-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-amber-900",children:"Lock check paused"}),e.jsx("p",{className:"text-sm text-amber-700 mt-1",children:"Refresh the page to retry."})]})]})});const o=Jt(),y=s?.name||s?.email||"another user";return i==="blocked-edit"?e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mb-4","data-testid":"edit-lock-banner","data-variant":"blocked-edit",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Nt,{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:[y," is editing this content"]}),e.jsxs("p",{className:"text-sm text-amber-700 mt-1",children:["Your changes are pending and will be saved when ",y," finishes."]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-3 items-center",children:[o&&r&&e.jsx(F,{size:"sm",variant:"outline",onClick:r,disabled:d||p,"data-testid":"request-collaboration-btn",children:p?"Request sent":"Request collaboration"}),l&&e.jsx(F,{size:"sm",variant:"ghost",onClick:l,"data-testid":"discard-pending-btn",children:"Discard pending changes"}),c&&e.jsx(F,{size:"sm",variant:"ghost",onClick:c,"data-testid":"view-read-only-btn",children:"View read-only"}),a&&e.jsx(F,{size:"sm",variant:"destructive",onClick:a,"data-testid":"force-takeover-btn",children:"Take over"})]})]})]})}):e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mb-4","data-testid":"edit-lock-banner","data-variant":"read-only-explicit",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Nt,{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: ",y]}),e.jsx("p",{className:"text-sm text-amber-700 mt-1",children:o?"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:[o&&r&&e.jsx(F,{size:"sm",variant:"outline",onClick:r,disabled:d||p,"data-testid":"request-collaboration-btn",children:p?"Request sent":"Request collaboration"}),f&&e.jsx(F,{size:"sm",variant:"ghost",onClick:f,"data-testid":"resume-editing-btn",children:"Resume editing"})]})]})]})})}const js={serverUnreachable:"We can't reach the server — your changes are kept here and will save when we're back online.",deviceOffline:"Your device is offline — your changes are kept here and will save when we're back online."};function or({status:i}){if(i.kind===null)return null;const s=i.isDeviceOffline?js.deviceOffline:js.serverUnreachable,a=i.retryAttempt>=1?`Attempt ${i.retryAttempt+1} — retrying…`:null;return e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mb-4","data-testid":"network-status-banner","data-kind":i.kind,role:"status","aria-live":"polite",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Zn,{className:"h-5 w-5 text-amber-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-amber-900",children:s}),a&&e.jsx("p",{className:"text-sm text-amber-700 mt-1","data-testid":"network-status-retry",children:a})]})]})})}const Ss={kind:null,retryAttempt:0,isDeviceOffline:!1};function dr(){const[i,s]=t.useState(Ss),r=t.useRef(!1),a=t.useCallback(c=>{const f=c.kind==="network"?"offline":c.kind;r.current=!0,s({kind:f,retryAttempt:c.retryAttempt,isDeviceOffline:typeof navigator<"u"&&navigator.onLine===!1})},[]),l=t.useCallback(()=>{r.current&&(r.current=!1,s(Ss),J.success("Reconnected",{description:"Your changes are saving again.",duration:3e3}))},[]);return{status:i,onNetworkError:a,onSaveSuccess:l}}function ur({open:i,trigger:s,updatedBy:r,updatedAt:a,onReload:l,onCancel:c}){const f=a>0?ct(a):"just now";return e.jsx(_s,{open:i,children:e.jsxs($s,{"data-testid":"stale-reload-modal","data-trigger":s,onEscapeKeyDown:d=>d.preventDefault(),children:[e.jsxs(Vs,{children:[e.jsx(Ms,{children:"This content was updated"}),e.jsx(Hs,{children:s==="save-conflict"?e.jsxs(e.Fragment,{children:["Your save couldn't go through —"," ",e.jsx("strong",{"data-testid":"stale-reload-updated-by",children:r})," ",e.jsxs("span",{className:"text-muted-foreground","data-testid":"stale-reload-updated-at",children:["(",f,")"]})," ","updated this content since you started editing. Reload to see the latest version (your unsaved changes will be lost), or cancel to keep your edits —"," ",e.jsx("strong",{children:"your next save will overwrite the other version"}),"."]}):e.jsxs(e.Fragment,{children:["This content was updated by"," ",e.jsx("strong",{"data-testid":"stale-reload-updated-by",children:r})," ",e.jsxs("span",{className:"text-muted-foreground","data-testid":"stale-reload-updated-at",children:["(",f,")"]})," ","while this tab was inactive. Reload to see the latest version (your unsaved changes will be lost), or cancel to keep editing your version — the next save will be rejected if it conflicts."]})})]}),e.jsxs(Js,{children:[e.jsx(zs,{onClick:c,"data-testid":"stale-reload-cancel-btn",children:"Cancel"}),e.jsx(Ks,{onClick:l,"data-testid":"stale-reload-reload-btn",children:"Reload"})]})]})})}function hr({lines:i}){return e.jsx("div",{className:"font-mono text-sm leading-relaxed",children:i.map((s,r)=>e.jsx("div",{style:{paddingLeft:`${s.indent*1.5}rem`},className:mt("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},r))})}function $t(i){switch(i.kind){case"draft":return"Draft";case"published":return"Published";case"history":return Ne(i.createdAt)}}function ht(i){switch(i.kind){case"draft":return"draft";case"published":return"published";case"history":return`history:${i.blockId}`}}function ws({value:i,onChange:s,isPublished:r,versions:a,exclude:l,size:c}){const f=l?ht(l):null;function d(p){if(p==="draft")s({kind:"draft"});else if(p==="published")s({kind:"published"});else if(p.startsWith("history:")){const o=p.slice(8),y=a.find(x=>x.blockId===o);y&&s({kind:"history",blockId:y.blockId,createdAt:y.createdAt,title:y.title})}}return e.jsxs(ja,{value:ht(i),onValueChange:d,children:[e.jsx(Sa,{size:c,children:e.jsx(wa,{children:$t(i)})}),e.jsxs(Ca,{position:"popper",children:[f!=="draft"&&e.jsx(Dt,{value:"draft",children:"Draft"}),r&&f!=="published"&&e.jsx(Dt,{value:"published",children:"Published"}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ra,{}),e.jsxs(Na,{children:[e.jsx(Aa,{children:"Version History"}),a.map(p=>{const o=`history:${p.blockId}`;return o===f?null:e.jsx(Dt,{value:o,children:Ne(p.createdAt)},o)})]})]})]})]})}function Cs({ref:i,host:s,contentId:r,collectionFields:a,isSingleton:l,draftBody:c,draftMetadata:f,collectionRelationships:d,draftRelationships:p}){const o=i?.kind==="published",y=i?.kind==="history",x=y?i.blockId:null,{data:R,isLoading:P}=Es(s,r,o),{data:j,isLoading:O}=Hn(s,r,y?x:null),A=t.useMemo(()=>(d??[]).map(S=>({name:S.name,label:S.label})),[d]);function D(S){if(A.length!==0)return{defs:A,values:S??{}}}const v=t.useMemo(()=>{if(!i)return[];if(i.kind==="draft")return c?Me(a,c,l?void 0:f,D(p)):[];if(i.kind==="published"){if(!R)return[];const B=l?void 0:{title:R.title,slug:R.slug,snippet:R.snippet,tags:R.tags},q=R.relationships;return Me(a,R.fields??{},B,D(q))}if(!j)return[];const S=l?void 0:{title:j.title,slug:j.slug,snippet:j.snippet,tags:j.tags},L=j.relationships;return Me(a,j.body??{},S,D(L))},[i,c,f,p,R,j,a,l,A]);return i?i.kind==="draft"?{lines:v,isLoading:!1,hasData:!!c}:i.kind==="published"?{lines:v,isLoading:P,hasData:!!R}:{lines:v,isLoading:O,hasData:!!j}:{lines:[],isLoading:!1,hasData:!1}}function fr({open:i,onOpenChange:s,host:r,contentId:a,collectionFields:l,isSingleton:c,isPublished:f,draftBody:d,draftMetadata:p,initialVersion:o,collectionRelationships:y,draftRelationships:x}){const[R,P]=t.useState(o??{kind:"published"}),[j,O]=t.useState({kind:"draft"}),[A,D]=t.useState(i),[v,S]=t.useState(o);if((i!==A||o!==v)&&(D(i),S(o),i)){const E=o??{kind:"published"};P(E),O(E.kind==="draft"?{kind:"published"}:{kind:"draft"})}ht(R)===ht(j)&&(R.kind!=="draft"?O({kind:"draft"}):f&&O({kind:"published"}));const{data:L}=Ps(r,a),B=L?.items??[],q={host:r,contentId:a,collectionFields:l,isSingleton:c,draftBody:d,draftMetadata:p,collectionRelationships:y,draftRelationships:x},U=Cs({ref:i?R:null,...q}),X=Cs({ref:i?j:null,...q}),T=U.isLoading;return e.jsx(ea,{open:i,onOpenChange:s,children:e.jsxs(ta,{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(sa,{children:e.jsxs(na,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-sm font-normal",children:"Viewing"}),e.jsx(ws,{value:R,onChange:P,isPublished:f,versions:B,size:"sm"})]})}),T&&e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(ve,{className:"h-6 w-48"}),e.jsx(ve,{className:"h-4 w-full"}),e.jsx(ve,{className:"h-4 w-full"}),e.jsx(ve,{className:"h-4 w-2/3"})]}),!T&&!U.hasData&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No data available for this version."}),!T&&U.hasData&&e.jsx("div",{className:"p-4",children:e.jsxs(Ts,{defaultValue:"changes",children:[e.jsxs(Is,{variant:"line",className:"mb-4",children:[e.jsx(ot,{value:"content",children:"Content"}),e.jsx(ot,{value:"changes",children:"Changes"})]}),e.jsx(dt,{value:"content",children:e.jsx(hr,{lines:U.lines})}),e.jsxs(dt,{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(ws,{value:j,onChange:O,isPublished:f,versions:B,exclude:R,size:"sm"})]}),X.isLoading?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ve,{className:"h-4 w-full"}),e.jsx(ve,{className:"h-4 w-full"}),e.jsx(ve,{className:"h-4 w-2/3"})]}):X.hasData?e.jsx(ya,{left:X.lines,right:U.lines,leftLabel:$t(j),rightLabel:$t(R)}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No data available for comparison."})]})]})})]})})}const It=3e4;class mr extends Va{constructor(s){super(),this.doc=s,this.clientID=s.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const r=ut();this.getLocalState()!==null&&It/2<=r-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const a=[];this.meta.forEach((l,c)=>{c!==this.clientID&&It<=r-l.lastUpdated&&this.states.has(c)&&a.push(c)}),a.length>0&&pr(this,a,"timeout")},Ma(It/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 r=this.clientID,a=this.meta.get(r),l=a===void 0?0:a.clock+1,c=this.states.get(r);s===null?this.states.delete(r):this.states.set(r,s),this.meta.set(r,{clock:l,lastUpdated:ut()});const f=[],d=[],p=[],o=[];s===null?o.push(r):c==null?s!=null&&f.push(r):(d.push(r),Xs(c,s)||p.push(r)),(f.length>0||p.length>0||o.length>0)&&this.emit("change",[{added:f,updated:p,removed:o},"local"]),this.emit("update",[{added:f,updated:d,removed:o},"local"])}setLocalStateField(s,r){const a=this.getLocalState();a!==null&&this.setLocalState({...a,[s]:r})}getStates(){return this.states}}const pr=(i,s,r)=>{const a=[];for(let l=0;l<s.length;l++){const c=s[l];if(i.states.has(c)){if(i.states.delete(c),c===i.clientID){const f=i.meta.get(c);i.meta.set(c,{clock:f.clock+1,lastUpdated:ut()})}a.push(c)}}a.length>0&&(i.emit("change",[{added:[],updated:[],removed:a},r]),i.emit("update",[{added:[],updated:[],removed:a},r]))},Rs=(i,s,r=i.states)=>{const a=s.length,l=Ka();Et(l,a);for(let c=0;c<a;c++){const f=s[c],d=r.get(f)||null,p=i.meta.get(f).clock;Et(l,f),Et(l,p),Ha(l,JSON.stringify(d))}return Ja(l)},gr=(i,s,r)=>{const a=Ya(s),l=ut(),c=[],f=[],d=[],p=[],o=Pt(a);for(let y=0;y<o;y++){const x=Pt(a);let R=Pt(a);const P=JSON.parse(za(a)),j=i.meta.get(x),O=i.states.get(x),A=j===void 0?0:j.clock;(A<R||A===R&&P===null&&i.states.has(x))&&(P===null?x===i.clientID&&i.getLocalState()!=null?R++:i.states.delete(x):i.states.set(x,P),i.meta.set(x,{clock:R,lastUpdated:l}),j===void 0&&P!==null?c.push(x):j!==void 0&&P===null?p.push(x):P!==null&&(Xs(P,O)||d.push(x),f.push(x)))}(c.length>0||d.length>0||p.length>0)&&i.emit("change",[{added:c,updated:d,removed:p},r]),(c.length>0||f.length>0||p.length>0)&&i.emit("update",[{added:c,updated:f,removed:p},r])},Ns=[1e3,2e3,4e3,8e3,16e3];class zt{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 mr(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(r=>r("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 r=Qa(this.doc);this.ws.send(JSON.stringify({action:"yjs",type:"sync-step-1",data:_e(r)}));const a=Rs(this.awareness,[this.doc.clientID]);this.ws.send(JSON.stringify({action:"awareness",data:_e(a)}))},this.ws.onmessage=r=>{const a=JSON.parse(r.data);switch(a.action){case"yjs":this.handleYjsMessage(a);break;case"field":this.fieldListeners.forEach(l=>l(a));break;case"awareness":this.handleAwarenessMessage(a);break;case"presence":this.presenceListeners.forEach(l=>l(a));break;case"leader-change":this.leaderChangeListeners.forEach(l=>l(a));break;case"collaboration-disabled":this.collabDisabledListeners.forEach(l=>l());break;case"publish-requested":this.publishRequestedListeners.forEach(l=>l(a));break;case"save-version-requested":this.saveVersionRequestedListeners.forEach(l=>l(a));break;case"publish-in-progress":this.publishInProgressListeners.forEach(l=>l());break;case"published":this.publishedListeners.forEach(l=>l(a));break}},this.ws.onclose=()=>{this.connected=!1,this.statusListeners.forEach(r=>r("disconnected")),this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}handleDocUpdate=(s,r)=>{r!=="remote"&&(this.connected?this.sendYjsUpdate(s):this.pendingUpdates.push(s))};sendYjsUpdate(s){this.ws?.send(JSON.stringify({action:"yjs",type:"update",data:_e(s)}))}flushPendingUpdates(){for(const s of this.pendingUpdates)this.sendYjsUpdate(s);this.pendingUpdates=[]}handleYjsMessage(s){const r=As(s.data);switch(s.type){case"sync-step-1":{const a=Wa(this.doc,r);this.ws.send(JSON.stringify({action:"yjs",type:"sync-step-2",data:_e(a)}));break}case"sync-step-2":vs(this.doc,r,"remote"),this.flushPendingUpdates(),this.flushPendingFieldUpdates();break;case"update":vs(this.doc,r,"remote");break}}fieldListeners=new Set;onFieldUpdate(s){return this.fieldListeners.add(s),()=>{this.fieldListeners.delete(s)}}sendFieldUpdate(s,r){if(!this.connected){const a=this.pendingFieldUpdates.findIndex(l=>l.field===s);a>=0?this.pendingFieldUpdates[a]={field:s,value:r}:(this.pendingFieldUpdates.length>=zt.MAX_PENDING_FIELD_UPDATES&&this.pendingFieldUpdates.shift(),this.pendingFieldUpdates.push({field:s,value:r}));return}this.ws?.send(JSON.stringify({action:"field",field:s,value:r}))}flushPendingFieldUpdates(){for(const{field:s,value:r}of this.pendingFieldUpdates)this.ws?.send(JSON.stringify({action:"field",field:s,value:r}));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:r,removed:a})=>{if(!this.connected)return;const l=Rs(this.awareness,[...s,...r,...a]);this.ws?.send(JSON.stringify({action:"awareness",data:_e(l)}))};handleAwarenessMessage(s){const r=As(s.data);gr(this.awareness,r,"remote")}scheduleReconnect(){if(this.destroyed)return;const s=Ns[Math.min(this.reconnectAttempt,Ns.length-1)];this.reconnectAttempt++,this.reconnectTimer=window.setTimeout(async()=>{try{this.ticket=await this.getTicket()}catch{this.statusListeners.forEach(r=>r("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 _e(i){let s="";for(let a=0;a<i.length;a+=8192)s+=String.fromCharCode(...i.subarray(a,a+8192));return btoa(s)}function As(i){const s=atob(i),r=new Uint8Array(s.length);for(let a=0;a<s.length;a++)r[a]=s.charCodeAt(a);return r}const it=["#3b82f6","#ef4444","#10b981","#f59e0b","#8b5cf6","#ec4899","#14b8a6","#f97316"];function br(i,s,r,a){const{user:l}=Ht(),[c,f]=t.useState(null),[d,p]=t.useState("disconnected"),[o,y]=t.useState([]),[x,R]=t.useState({}),P=t.useRef(null),j=t.useRef(a?.onCollabDisabled),O=t.useRef(a?.onPublishRequested),A=t.useRef(a?.onSaveVersionRequested),D=t.useRef(a?.onPublishInProgress),v=t.useRef(a?.onPublished);t.useEffect(()=>{j.current=a?.onCollabDisabled,O.current=a?.onPublishRequested,A.current=a?.onSaveVersionRequested,D.current=a?.onPublishInProgress,v.current=a?.onPublished},[a?.onCollabDisabled,a?.onPublishRequested,a?.onSaveVersionRequested,a?.onPublishInProgress,a?.onPublished]);const S="__HEADROOM_COLLAB_WS_URL__",L=Jt(),B=L&&!!c&&d==="connected";t.useEffect(()=>{if(!L||!S||!l||!r)return;const w=new Ga;P.current=w;const $=`${i}/${s}`,u=async()=>{const Y=Mt();if(!Y)throw new Error("No access token");const ue="__HEADROOM_API_URL__".replace(/\/+$/,""),z=await fetch(`${ue}/v1/admin/sites/${i}/content/${s}/collab/ticket`,{method:"POST",headers:{Authorization:`Bearer ${Y}`,"Content-Type":"application/json"},body:JSON.stringify({room:$})});if(!z.ok)throw new Error(`Ticket request failed: ${z.status}`);return(await z.json()).ticket};let m=!1,H=null;return u().then(Y=>{if(m)return;const ue=Ds(l.sub)%it.length;H=new zt({wsUrl:S,room:$,ticket:Y,getTicket:u,doc:w,user:{sub:l.sub,name:l.name||l.email,color:it[ue]}}),H.onStatus(p),H.onPresence(z=>{y(z.connections.filter(te=>te.connectionId!==z.youAre).map(te=>({sub:te.adminSub,name:te.adminName,color:te.color})));const pe=z.connections.find(te=>te.connectionId===z.youAre);_(pe?.isLeader??!1)}),H.onCollabDisabled(()=>{j.current?.()}),H.onPublishRequested(()=>O.current?.()),H.onSaveVersionRequested(()=>A.current?.()),H.onPublishInProgress(()=>D.current?.()),H.onPublished(z=>v.current?.({contentId:z.contentId,version:z.version})),f(H)}).catch(()=>{m||p("disconnected")}),()=>{m=!0,H?.destroy(),w.destroy(),f(null),p("disconnected")}},[i,s,l?.sub,r,S]);const q=t.useCallback(w=>{if(!c||!l||!P.current)return;const $=P.current.getXmlFragment(`document-store-${w}`),u=Ds(l.sub)%it.length;return{provider:c,fragment:$,user:{name:l.email,color:it[u]}}},[c,l]);t.useEffect(()=>{if(!c){R({});return}const w=()=>{const $={};c.awareness.getStates().forEach(m=>{const H=m?.user?.sub;if(!H)return;const Y=m.activeField??null;$[H]=Y}),R($)};return w(),c.awareness.on("change",w),()=>{c.awareness.off("change",w)}},[c]);const U=t.useMemo(()=>o.map(w=>({...w,activeField:x[w.sub]??null})),[o,x]),X=t.useCallback(w=>{c&&c.awareness.setLocalStateField("activeField",w)},[c]),T=t.useRef(new Set),E=t.useCallback(w=>(T.current.add(w),()=>{T.current.delete(w)}),[]);t.useEffect(()=>{if(c)return c.onFieldUpdate(w=>{T.current.forEach($=>$(w.field,w.value))})},[c]);const ne=t.useCallback((w,$)=>{c?.sendFieldUpdate(w,$)},[c]),ae=t.useCallback(()=>{c?.sendDisableCollab()},[c]),se=t.useCallback(()=>{c?.sendRequestPublish()},[c]),M=t.useCallback(()=>{c?.sendRequestSaveVersion()},[c]),re=t.useCallback(()=>{c?.sendPublishInProgress()},[c]),G=t.useCallback(w=>{c?.sendPublished(w)},[c]),[Z,_]=t.useState(!1);return t.useEffect(()=>{if(c)return c.onLeaderChange(w=>{_(w.leaderSub===l?.sub)})},[c,l]),{active:B,status:d,editors:U,isLeader:Z,getBlockNoteCollab:q,updateField:ne,onRemoteFieldChange:E,setActiveField:X,sendDisableCollab:ae,sendRequestPublish:se,sendRequestSaveVersion:M,sendPublishInProgress:re,sendPublished:G}}function Ds(i){let s=0;for(let r=0;r<i.length;r++)s=(s<<5)-s+i.charCodeAt(r)|0;return Math.abs(s)}function xr({status:i,editors:s}){return s.length===0&&i==="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":i,children:[e.jsx("span",{"data-testid":"collaboration-bar-status-dot","data-status":i,className:mt("h-2 w-2 rounded-full",i==="connected"&&"bg-green-500",i==="connecting"&&"bg-yellow-500 animate-pulse",i==="disconnected"&&"bg-red-500")}),e.jsx("span",{className:"text-muted-foreground text-xs",children:i==="connected"?"Live":i==="connecting"?"Connecting...":"Offline"})]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Us,{orientation:"vertical",className:"h-4"}),e.jsx("div",{className:"flex -space-x-1.5",children:s.map(r=>e.jsxs(Fs,{children:[e.jsx(Os,{asChild:!0,children:e.jsx(Ia,{className:"h-6 w-6 border-2",style:{borderColor:r.color},"aria-label":r.name,children:e.jsx(Ua,{className:"text-[10px]",style:{backgroundColor:r.color+"20"},children:Fa(r.name)})})}),e.jsx(Bs,{children:r.name})]},r.sub))}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[s.length," other ",s.length===1?"editor":"editors"]})]})]})}function vr({host:i,contentId:s,collaborationEnabled:r,hasConnectedPeers:a,isLockHolder:l,sessionId:c,onChange:f,onBeforeDisable:d}){const[p,o]=t.useState(!1),y=ft();if(!Jt()||!l)return null;const x=async()=>{const A=!r;o(!0);try{if(!A)try{d?.()}catch{}await y.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock/collaboration`,{method:"POST",body:JSON.stringify({collaborationEnabled:A,sessionId:c})}),f(A)}catch{J.error("Failed to update collaboration setting")}finally{o(!1)}},R=r&&a,P=p||R,j=R?"Cannot stop sharing while other editors are connected":null,O=e.jsxs(F,{variant:r?"default":"outline",size:"sm",disabled:P,onClick:x,"aria-pressed":r,children:[r?e.jsx(aa,{className:"h-4 w-4"}):e.jsx(ra,{className:"h-4 w-4"}),r?"Collaborating":"Collaborate"]});return j?e.jsxs(Fs,{children:[e.jsx(Os,{asChild:!0,children:O}),e.jsx(Bs,{children:j})]}):O}function yr(i,s,r,a,l){const c=t.useRef(new Set),f=ft();t.useEffect(()=>{const d=new Set(a.map(p=>p.sub));for(const p of Array.from(c.current))d.has(p)||c.current.delete(p)},[a]),t.useEffect(()=>{for(const d of a){if(c.current.has(d.sub))continue;c.current.add(d.sub);const p=d.name||d.email||"Someone";J(`${p} wants to collaborate`,{action:{label:"Allow",onClick:()=>{f.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock/collaboration`,{method:"POST",body:JSON.stringify({collaborationEnabled:!0,sessionId:r})}).then(()=>l()).catch(()=>J.error("Failed to enable collaboration"))}},cancel:{label:"Decline",onClick:()=>{f.apiFetch(`/v1/admin/sites/${i}/content/${s}/edit-lock/access-requests/${d.sub}?sessionId=${r}`,{method:"DELETE"}).catch(()=>J.error("Failed to decline request"))}},duration:1/0})}},[a,i,s,r,l,f])}function ti(){const{host:i,collection:s,id:r}=qn(),{data:a,isLoading:l}=Jn(i,r);return l?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ve,{className:"h-8 w-64"}),e.jsx(ve,{className:"h-64 w-full"})]}):a?.content?e.jsx(kr,{host:i,collection:s,contentId:r,content:a.content,draft:a.draft,publishedBlockId:a.publishedBlockId}):e.jsx("p",{className:"text-muted-foreground",children:"Content not found."})}function kr({host:i,collection:s,contentId:r,content:a,draft:l,publishedBlockId:c}){const f=_n(),d=ft(),p=Vt(),{collections:o}=ia(),y=zn(i,r),x=Kn(i,r),R=Yn(i,r),P=Qn(i,r),j=Wn(i,r),O=Gn(i,r),A=l?{title:l.title??a.title,slug:l.slug??a.slug??"",snippet:l.snippet??a.snippet??"",tags:l.tags??a.tags??[],cover:l.cover??a.cover??null,body:l.body??{},relationships:l.relationships??{}}:void 0,{user:D}=Ht(),{data:v}=la(),S=D?(v?.superAdminIds??[]).includes(D.sub):!1,L=t.useRef(null),B=t.useCallback(async()=>{const n=L.current;return n?n():{ok:!0}},[]),q=typeof l?.updatedAt=="number"?l.updatedAt:0,[U,X]=t.useState(q),T=t.useRef(q),E=t.useCallback(n=>{T.current=n,X(n)},[]),ne=t.useCallback(()=>T.current,[]),ae=t.useRef(()=>{}),se=t.useRef(()=>{}),[M,re]=t.useState(!1),G=t.useRef(!1),Z=t.useRef(!1),_=t.useRef(()=>!1),w=t.useRef(()=>!1),$=t.useRef(null),u=lr(i,r,{getIsDirty:()=>_.current()||G.current,getIsSaving:()=>Z.current,getIsSavingSync:()=>w.current(),onIdleRelease:()=>$.current?.(),onLockAcquired:n=>{typeof n=="number"&&n>0&&E(n)}}),m=br(i,r,u.collaborationEnabled,{onCollabDisabled:()=>u.setCollaborationEnabled(!1),onPublishRequested:()=>ae.current(),onSaveVersionRequested:()=>se.current(),onPublishInProgress:()=>re(!0),onPublished:()=>{re(!1),J.success("Content published")}}),[H,Y]=t.useState(null),ue=m.active?1e4:void 0,z=dr(),pe=t.useCallback(n=>{const g=n,W=(g?.accessRequests??[]).filter(xe=>xe.sub!==D?.sub);u.setAccessRequests(W),typeof g?.updatedAt=="number"&&(E(g.updatedAt),jt(!1)),z.onSaveSuccess()},[u,D?.sub,E,z]),te=t.useRef(null),Oe=t.useCallback(()=>{te.current?.()},[]),Ae=t.useRef(null),Be=t.useCallback(()=>Ae.current?.()??{},[]),b=tr(i,r,A,()=>{Y("This slug is already in use by another item in this collection")},n=>{u.onAutosaveConflict({lockHolder:n.body?.lockHolder??void 0,takeoverReason:n.body?.takeoverReason??"expired"})},ue,pe,{onBeforeFirstSave:B,onStaleBaseConflict:Oe,getCurrentParams:Be,getBaseUpdatedAt:ne,onNetworkError:z.onNetworkError});L.current=u.tryAcquireForEdit,G.current=b.isDirty,Z.current=b.isSaving,_.current=b.getHasPending,w.current=b.getIsSavingSync,$.current=b.markLockReleased;const N=u.bumpIdleTimer;t.useEffect(()=>{b.lastSavedAt!=null&&N()},[b.lastSavedAt,N]);const k=(u.status==="blocked-edit"||u.status==="read-only-explicit"||u.status==="stale-reload-pending"||u.status==="poll-ceiling")&&!u.collaborationEnabled;yr(i,r,u.sessionId,u.accessRequests,()=>u.setCollaborationEnabled(!0));const{data:K}=Ea(i),ce=K?.map(n=>n.tag),Q=o.find(n=>n.name===s),h=t.useMemo(()=>Q?.fields??[],[Q?.fields]),I=t.useMemo(()=>Q?.relationships??[],[Q?.relationships]),C=Q?.singleton??!1,he=ca(),[ee,De]=t.useState(l?.title??a.title),[fe,Ee]=t.useState(l?.slug??a.slug??""),[me,Pe]=t.useState(l?.snippet??a.snippet??""),Kt=l?.autoSnippet??"",[ye,Le]=t.useState(l?.tags??a.tags??[]),[oe,Te]=t.useState(l?.cover??a.cover??null),[ke,Ie]=t.useState(l?.body??{}),[je,Ue]=t.useState(l?.relationships??{}),[Zs,pt]=t.useState(0),[en,tn]=t.useState(!1),[sn,He]=t.useState(!1),[nn,qe]=t.useState(!1),[an,Je]=t.useState(null),[gt,ze]=t.useState(!1),[rn,Ke]=t.useState(!1),[ln,Ye]=t.useState(!1),[Qe,Yt]=t.useState(""),[cn,bt]=t.useState(!1),[xt,Qt]=t.useState(""),Wt=Xn(i,r),ie=t.useCallback(()=>({title:ee,slug:fe,snippet:me,tags:ye,cover:oe,body:ke,relationships:je,...u.sessionId?{sessionId:u.sessionId}:{}}),[ee,fe,me,ye,oe,ke,je,u.sessionId]);t.useEffect(()=>{Ae.current=ie},[ie]);const on=m.active?n=>{De(n),m.updateField("title",n)}:n=>{De(n),b.schedule({...ie(),title:n})},dn=m.active?n=>{Ee(n),Y(null),m.updateField("slug",n)}:n=>{Ee(n),Y(null),b.schedule({...ie(),slug:n})},un=m.active?n=>{Pe(n),m.updateField("snippet",n)}:n=>{Pe(n),b.schedule({...ie(),snippet:n})},hn=m.active?n=>{Le(n),m.updateField("tags",n)}:n=>{Le(n),b.schedule({...ie(),tags:n})},Gt=m.active?n=>{Te(n),m.updateField("cover",n)}:n=>{Te(n),b.schedule({...ie(),cover:n})},fn=m.active?n=>{Ie(n),m.updateField("body",n)}:n=>{Ie(n),b.schedule({...ie(),body:n})},mn=m.active?n=>{Ue(n),m.updateField("relationships",n)}:n=>{Ue(n),b.schedule({...ie(),relationships:n})},We=m.active,Ge=m.setActiveField,vt=t.useCallback(n=>{We&&Ge(n)},[We,Ge]),yt=t.useCallback(()=>{We&&Ge(null)},[We,Ge]);t.useEffect(()=>{if(m.active)return m.onRemoteFieldChange((n,g)=>{switch(n){case"title":De(g);break;case"slug":Ee(g);break;case"snippet":Pe(g);break;case"tags":Le(g);break;case"cover":Te(g);break;case"body":Ie(g);break;case"relationships":Ue(g);break}m.isLeader&&b.schedule(ie())})},[m.active,m.onRemoteFieldChange,m.isLeader]);const Xt=m.active?m.isLeader:!0;t.useEffect(()=>{if(!m.active||!Xt)return;b.schedule(ie());const n=window.setInterval(()=>{b.schedule(ie())},1e4);return()=>window.clearInterval(n)},[Xt,m.active]);const Zt=b.lastSavedBlockId??l?.blockId,Re=t.useCallback(n=>{const g=n.draft,V=n.content;if(!g&&!V)return;const W={title:g?.title??V?.title??"",slug:g?.slug??V?.slug??"",snippet:g?.snippet??V?.snippet??"",tags:g?.tags??V?.tags??[],cover:g?.cover??V?.cover??null,body:g?.body??{},relationships:g?.relationships??{}};De(W.title),Ee(W.slug),Pe(W.snippet),Le(W.tags),Te(W.cover),Ie(W.body),Ue(W.relationships);const xe=g?.updatedAt??0;E(xe),b.resetBaseline(W),pt(Ct=>Ct+1)},[b,E]),[le,kt]=t.useState(null),pn=t.useMemo(()=>le?.updatedBy?[le.updatedBy]:[],[le?.updatedBy]),{resolve:es}=Ys(pn),gn=t.useMemo(()=>{const n=le?.updatedBy??"";if(!n)return"another admin";const g=es(n);return!g||g===n?"another admin":g},[le?.updatedBy,es]),[bn,jt]=t.useState(!1),Xe=t.useRef(null),ts=u.setStaleReloadPending,Ze=t.useCallback((n,g)=>{b.pause(),Xe.current={title:ee,slug:fe,snippet:me,tags:ye,cover:oe,body:ke,relationships:je};const V=n.draft?.updatedAt??0,W=n.draft?.updatedBy??"";kt({trigger:g,updatedBy:W,updatedAt:V,latest:n}),ts()},[b,ts,ee,fe,me,ye,oe,ke,je]),et=u.endEditing,xn=t.useCallback(()=>{const n=le;n&&Re(n.latest),Xe.current=null,kt(null),jt(!1),b.resume(),et()},[le,Re,b,et]),ss=u.resumeEditingAfterStale,vn=t.useCallback(()=>{const n=Xe.current,g=le;if(n&&(De(n.title),Ee(n.slug),Pe(n.snippet),Le(n.tags),Te(n.cover),Ie(n.body),Ue(n.relationships),pt(V=>V+1),b.resetBaseline(n),Xe.current=null),g?.trigger==="save-conflict"&&g.latest){const V=g.latest.draft,W=V?.updatedAt,xe=V?.blockId;typeof W=="number"&&W>0&&E(W),typeof xe=="string"&&xe!==""&&b.adoptServerBlockId(xe)}kt(null),jt(!0),b.resume(),ss()},[b,ss,le,E]),Fe=t.useCallback(async()=>(await p.invalidateQueries({queryKey:["sites",i,"content-detail",r]}),p.getQueryData(["sites",i,"content-detail",r])??null),[p,i,r]),yn=t.useCallback(async()=>{b.cancel();const n=await Fe();n&&Re(n),et()},[b,Fe,Re,et]),ns=u.setReadOnlyExplicit,kn=t.useCallback(async()=>{b.cancel();const n=await Fe();n&&Re(n),ns()},[b,Fe,Re,ns]),as=t.useCallback(async()=>{const n=await Fe();n&&Ze(n,"save-conflict")},[Fe,Ze]);t.useEffect(()=>{te.current=()=>void as()},[as]);const jn=t.useCallback(()=>{b.pause()},[b]),Sn=t.useCallback(()=>{b.resume()},[b]),wn=t.useCallback(n=>{Ze(n,"tab-refocus")},[Ze]);cr({host:i,contentId:r,isDirty:b.isDirty,serverBlockId:Zt,serverUpdatedAt:U,onSilentReload:Re,onStaleWithDirty:wn,onTabHidden:jn,onTabVisibleResume:Sn});const ge=qa(a.publishedAt,a.lastPublishedAt,c,Zt,a.scheduledAt,a.scheduledFailed),tt=_a(ge),st=$a(ge),{data:Se}=Es(i,r,!!a.publishedAt),be=t.useMemo(()=>{if(!gt||!Se)return null;const n=C?void 0:{title:Se.title,slug:Se.slug,snippet:Se.snippet,tags:Se.tags},g=I.map(de=>({name:de.name,label:de.label})),V=Se.relationships,W=g.length>0?{defs:g,values:V??{}}:void 0,xe=Me(h,Se.fields??{},n,W),Ct=C?void 0:{title:ee,slug:fe,snippet:me,tags:ye},In=g.length>0?{defs:g,values:je}:void 0,Un=Me(h,ke,Ct,In),Fn=ka(xe,Un,{comparator:(de,Rt)=>de.text===Rt.text&&de.indent===Rt.indent&&de.type===Rt.type});let ls=0,cs=0;for(const de of Fn)de.added?ls+=de.count??0:de.removed&&(cs+=de.count??0);return{added:ls,removed:cs}},[gt,Se,h,I,C,ee,fe,me,ye,ke,je]),[Cn]=$n(),Rn=Cn.get("from")==="recent"?`/sites/${i}/content`:`/sites/${i}/content/${s}`;va({title:C?Q?.label??s:ee||"Untitled",showBack:!C,backTo:C?void 0:Rn,badge:{label:tt.label,variant:tt.variant}});function nt(){if(m.active&&!m.isLeader){m.sendRequestPublish();return}if(a.publishedAt&&a.slug&&fe!==a.slug){Ke(!0);return}ge==="published-changes"?ze(!0):St()}async function St(){m.active&&m.isLeader&&m.sendPublishInProgress();try{await b.flush({createVersion:!0});const g=(await y.mutateAsync(void 0))?.updatedAt;typeof g=="number"&&g>0&&E(g),b.discard(),u.endEditing(),J.success("Content published"),m.active&&m.isLeader&&m.sendPublished({contentId:r})}catch(n){if(n instanceof Ce&&n.code==="SLUG_TAKEN"){Y("This slug is already in use by another item in this collection"),J.error("Slug already in use",{description:"Please choose a different slug before publishing."});return}J.error("Failed to publish",{description:n instanceof Error?n.message:void 0})}finally{}}function Nn(){if(m.active&&!m.isLeader){m.sendRequestSaveVersion();return}b.flush({createVersion:!0})}t.useEffect(()=>{ae.current=nt,se.current=()=>{b.flush({createVersion:!0})}});async function An(){try{const g=(await x.mutateAsync())?.updatedAt;typeof g=="number"&&g>0&&E(g),qe(!1),u.endEditing(),J.success("Content unpublished")}catch(n){J.error("Failed to unpublish",{description:n instanceof Error?n.message:void 0})}}async function Dn(){try{b.discard();const n=await d.apiFetch(`/v1/admin/sites/${i}/content/${r}/published`);await Wt.mutateAsync();const g={title:n.title??"",slug:n.slug??"",snippet:n.snippet??"",tags:n.tags??[],cover:n.cover??null,body:n.fields??{},relationships:n.relationships??{}};De(g.title),Ee(g.slug),Pe(g.snippet),Le(g.tags),Te(g.cover),Ie(g.body),Ue(g.relationships),pt(V=>V+1),b.resetBaseline(g),J.success("Changes discarded")}catch(n){J.error("Failed to discard changes",{description:n instanceof Error?n.message:void 0})}}async function En(){try{await R.mutateAsync(),u.endEditing(),J.success("Content deleted"),f(`/sites/${i}/content/${s}`)}catch(n){J.error("Failed to delete",{description:n instanceof Error?n.message:void 0})}}async function Pn(){if(Qe)try{await b.flush({createVersion:!0});const n=new Date(Qe).getTime(),V=(await j.mutateAsync(n))?.updatedAt;typeof V=="number"&&V>0&&E(V),Ye(!1),Yt(""),u.endEditing(),J.success("Content scheduled for publishing")}catch(n){J.error("Failed to schedule",{description:n instanceof Error?n.message:void 0})}}async function Ln(){try{const g=(await O.mutateAsync())?.updatedAt;typeof g=="number"&&g>0&&E(g),u.endEditing(),J.success("Schedule cancelled")}catch(n){J.error("Failed to cancel schedule",{description:n instanceof Error?n.message:void 0})}}async function Tn(){if(xt)try{const n=new Date(xt).getTime();await P.mutateAsync(n),bt(!1),J.success("Publish date updated")}catch(n){J.error("Failed to update publish date",{description:n instanceof Error?n.message:void 0})}}function wt(n){const g=new Date(n),V=g.getTimezoneOffset();return new Date(g.getTime()-V*6e4).toISOString().slice(0,16)}const rs=e.jsx("div",{className:`space-y-6 ${k?"pointer-events-none opacity-60 select-none":""}`,"aria-readonly":k||void 0,children:h.length>0?e.jsx(Oa,{fields:h,values:ke,onChange:fn},Zs):e.jsx($e,{children:e.jsx(Ve,{className:"py-8 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No fields defined for this collection."," ",e.jsx(Vn,{to:`/sites/${i}/settings/collections/${s}`,className:"underline",children:"Configure fields"})]})})})}),is=e.jsxs("div",{className:`space-y-6 ${k?"pointer-events-none opacity-60 select-none":""}`,"aria-readonly":k||void 0,children:[!C&&e.jsx($e,{children:e.jsxs(Ve,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(at,{htmlFor:"title",className:"flex items-center",children:["Title",e.jsx(rt,{field:"title",editors:m.editors})]}),e.jsx(ds,{id:"title",value:ee,onChange:n=>on(n.target.value),onFocus:()=>vt("title"),onBlur:yt})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(at,{htmlFor:"slug",className:"flex items-center",children:["Slug",e.jsx(rt,{field:"slug",editors:m.editors})]}),e.jsx(ds,{id:"slug",value:fe,onChange:n=>dn(n.target.value),onFocus:()=>vt("slug"),onBlur:yt,className:H?"border-destructive":""}),H&&e.jsx("p",{className:"text-sm text-destructive",children:H})]}),e.jsxs(Qs,{defaultOpen:!!me,children:[e.jsxs(Ws,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(qs,{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(rt,{field:"snippet",editors:m.editors})]}),e.jsxs(Gs,{className:"mt-2 space-y-2",children:[e.jsx(Da,{id:"snippet",value:me,onChange:n=>un(n.target.value),onFocus:()=>vt("snippet"),onBlur:yt,rows:3,placeholder:"Brief summary of this content..."}),!me&&Kt&&e.jsxs("p",{className:"text-xs italic text-muted-foreground",children:["Auto-generated: ",Kt]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(at,{children:"Cover Image"}),oe?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>He(!0),children:[e.jsx("img",{src:La(oe.url),alt:oe.alt??oe.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:oe.filename??oe.alt??oe.id}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),Gt(null)},children:e.jsx(us,{className:"h-3 w-3"})})]}):e.jsxs(F,{type:"button",variant:"outline",className:"w-full",onClick:()=>He(!0),children:[e.jsx(oa,{className:"mr-2 h-4 w-4"}),"Select Image"]}),e.jsx(Pa,{open:sn,onClose:()=>He(!1),onSelect:n=>{Gt({id:n.mediaId,url:n.url,width:n.width??0,height:n.height??0,alt:n.alt,caption:n.caption,filename:n.filename}),He(!1)},allowedTypes:["image/*"]})]})]})}),!C&&e.jsxs($e,{children:[e.jsx(bs,{children:e.jsxs(xs,{className:"flex items-center",children:["Tags",e.jsx(rt,{field:"tags",editors:m.editors})]})}),e.jsx(Ve,{children:e.jsx(xa,{tags:ye,onChange:hn,suggestions:ce})})]}),I.length>0&&e.jsx(Ta,{relationships:I,values:je,onChange:mn,host:i}),e.jsxs($e,{children:[e.jsx(bs,{children:e.jsx(xs,{children:"Info"})}),e.jsxs(Ve,{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:a.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:a.contentId})]}),a.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"}),cn?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"datetime-local",value:xt,onChange:n=>Qt(n.target.value),className:"text-xs border rounded px-1 py-0.5",max:wt(Date.now())}),e.jsx(F,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Tn,disabled:P.isPending,children:e.jsx(hs,{className:"h-3 w-3"})}),e.jsx(F,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>bt(!1),children:e.jsx(us,{className:"h-3 w-3"})})]}):e.jsxs("span",{className:"cursor-pointer hover:underline",title:Ne(a.publishedAt),onClick:()=>{Qt(wt(a.publishedAt)),bt(!0)},children:[ct(a.publishedAt),e.jsx(da,{className:"inline ml-1 h-3 w-3 text-muted-foreground"})]})]}),a.lastPublishedAt&&a.lastPublishedAt!==a.publishedAt&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:Ne(a.lastPublishedAt),children:ct(a.lastPublishedAt)})]})]}):a.lastPublishedAt?e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:Ne(a.lastPublishedAt),children:ct(a.lastPublishedAt)})]}):null,ge==="scheduled"&&a.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(fs,{className:"h-3 w-3"}),Ne(a.scheduledAt)]})]}),ge==="schedule-failed"&&e.jsx("div",{className:"text-destructive text-xs",children:"Scheduled publishing failed after multiple attempts."}),a.publishedAt&&e.jsxs(F,{variant:"outline",size:"sm",className:"w-full mt-2",onClick:()=>{Je({kind:"published"}),qe(!0)},children:[e.jsx(ua,{className:"mr-2 h-4 w-4"}),"View published"]})]})]}),e.jsx(wr,{host:i,contentId:r,onViewVersion:n=>{Je({kind:"history",blockId:n.blockId,createdAt:n.createdAt,title:n.title}),qe(!0)}}),!C&&e.jsx(Sr,{deleteOpen:en,setDeleteOpen:tn,onDelete:En,host:i,contentId:r})]});return e.jsx(Ba.Provider,{value:m.active?m:null,children:e.jsxs("div",{className:"mx-auto max-w-6xl",children:[u.collaborationEnabled&&e.jsx("div",{className:"mb-3",children:e.jsx(xr,{status:m.status,editors:m.editors})}),e.jsx(or,{status:z.status}),u.status==="poll-ceiling"&&e.jsx(ks,{variant:"poll-ceiling"}),(u.status==="blocked-edit"||u.status==="read-only-explicit")&&u.lockHolder&&e.jsx(ks,{variant:u.status,lockHolder:u.lockHolder,onRequestCollaboration:()=>u.requestCollaboration.mutate(),isRequesting:u.requestCollaboration.isPending,requestSent:u.requestCollaboration.isSuccess,onDiscardPending:u.status==="blocked-edit"?()=>void yn():void 0,onViewReadOnly:u.status==="blocked-edit"?()=>void kn():void 0,onResumeEditing:u.status==="read-only-explicit"?()=>u.exitReadOnly():void 0,onForceTakeover:u.status==="blocked-edit"&&S?()=>void u.forceTakeover():void 0}),u.status==="read-only-explicit"&&!u.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(F,{size:"sm",onClick:()=>void u.takeEditing(),"data-testid":"take-editing-btn",children:"Take editing"})]}),!he&&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:C?Q?.label??s:ee||"Untitled"}),e.jsx(ha,{variant:tt.variant,children:tt.label}),b.isSaving&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(we,{className:"h-3 w-3 animate-spin"}),"Saving..."]}),!b.isSaving&&b.lastSavedAt&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(hs,{className:"h-3 w-3"}),"Saved"]}),bn&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-amber-700",title:"Your edits are based on an older version. The next save may be rejected.","data-testid":"stale-base-indicator",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-amber-500"}),"Older version"]})]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsx(vr,{host:i,contentId:r,collaborationEnabled:u.collaborationEnabled,hasConnectedPeers:m.editors.length>0,isLockHolder:u.status==="editing",sessionId:u.sessionId,onChange:n=>u.setCollaborationEnabled(n),onBeforeDisable:m.sendDisableCollab}),e.jsxs(F,{variant:"outline",size:"sm",onClick:Nn,disabled:b.isSaving||k,className:"px-3",children:[b.isSaving&&e.jsx(we,{className:"mr-2 h-4 w-4 animate-spin"}),"Save Draft"]}),ge==="scheduled"&&e.jsxs(e.Fragment,{children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:Ln,disabled:O.isPending||k,className:"px-3",children:[O.isPending&&e.jsx(we,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel Schedule"]}),e.jsxs(F,{size:"sm",onClick:nt,disabled:y.isPending||M||k,className:"px-3",children:[(y.isPending||M)&&e.jsx(we,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish Now"]})]}),ge!=="scheduled"&&st&&e.jsxs("div",{className:"flex",children:[e.jsxs(F,{size:"sm",onClick:nt,disabled:y.isPending||M||k,className:mt("px-3",!a.publishedAt&&"rounded-r-none"),children:[(y.isPending||M)&&e.jsx(we,{className:"mr-2 h-4 w-4 animate-spin"}),st]}),!a.publishedAt&&e.jsxs(ms,{children:[e.jsx(ps,{asChild:!0,children:e.jsx(F,{size:"sm",className:"rounded-l-none border-l px-2",disabled:y.isPending||M||k,children:e.jsx(fa,{className:"h-4 w-4"})})}),e.jsx(gs,{align:"end",children:e.jsxs(At,{onClick:()=>Ye(!0),disabled:k,children:[e.jsx(fs,{className:"mr-2 h-4 w-4"}),"Schedule for later"]})})]})]}),a.publishedAt&&e.jsxs(ms,{children:[e.jsx(ps,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",className:"size-8 p-0",disabled:k,children:e.jsx(ma,{className:"h-4 w-4"})})}),e.jsxs(gs,{align:"end",children:[ge==="published-changes"&&e.jsxs(At,{onClick:Dn,disabled:Wt.isPending||k,children:[e.jsx(pa,{className:"mr-2 h-4 w-4"}),"Discard Changes"]}),e.jsx(At,{onClick:An,className:"text-destructive focus:text-destructive",disabled:k,children:"Unpublish"})]})]})]})]}),he?e.jsxs(Ts,{defaultValue:"content",children:[e.jsxs("div",{className:"mb-2 flex items-center",children:[e.jsxs(Is,{variant:"line",children:[e.jsx(ot,{value:"content",children:"Content"}),e.jsx(ot,{value:"info",children:"Info"})]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>b.flush({createVersion:!0}),disabled:b.isSaving||k,children:[b.isSaving&&e.jsx(we,{className:"mr-1 h-3 w-3 animate-spin"}),"Save"]}),ge!=="scheduled"&&st&&e.jsxs(F,{size:"sm",onClick:nt,disabled:y.isPending||k,children:[y.isPending&&e.jsx(we,{className:"mr-1 h-3 w-3 animate-spin"}),st]})]})]}),e.jsx(dt,{value:"content",className:"mt-0",children:rs}),e.jsx(dt,{value:"info",className:"mt-0",children:is})]}):e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:rs}),e.jsx("div",{children:is})]}),e.jsx(fr,{open:nn,onOpenChange:n=>{qe(n),n||Je(null)},host:i,contentId:r,collectionFields:h,isSingleton:C,isPublished:!!a.publishedAt,draftBody:ke,draftMetadata:C?void 0:{title:ee,slug:fe,snippet:me,tags:ye},initialVersion:an,collectionRelationships:I,draftRelationships:je}),e.jsx(ur,{open:!!le,trigger:le?.trigger??"tab-refocus",updatedBy:gn,updatedAt:le?.updatedAt??0,onReload:xn,onCancel:vn}),e.jsx(_s,{open:gt,onOpenChange:ze,children:e.jsxs($s,{children:[e.jsxs(Vs,{children:[e.jsx(Ms,{children:"Publish changes?"}),e.jsx(Hs,{children:be?e.jsxs(e.Fragment,{children:[be.added>0&&e.jsxs("span",{className:"text-green-600",children:["+",be.added," added"]}),be.added>0&&be.removed>0&&", ",be.removed>0&&e.jsxs("span",{className:"text-red-600",children:["-",be.removed," removed"]}),be.added===0&&be.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(F,{variant:"link",className:"p-0 h-auto text-sm",onClick:()=>{ze(!1),Je({kind:"draft"}),qe(!0)},children:"View full diff"})}),e.jsxs(Js,{children:[e.jsx(zs,{children:"Cancel"}),e.jsx(Ks,{onClick:()=>{ze(!1),St()},children:"Publish Update"})]})]})}),e.jsx(Ut,{open:rn,onOpenChange:Ke,children:e.jsxs(Ft,{children:[e.jsxs(Ot,{children:[e.jsx(Bt,{children:"Slug change detected"}),e.jsxs(qt,{children:["You are changing the slug from “",a.slug,"” to “",fe,"”. This may break external bookmarks and SEO links."]})]}),e.jsx(jr,{host:i,contentId:r}),e.jsxs(_t,{children:[e.jsx(F,{variant:"outline",onClick:()=>Ke(!1),children:"Cancel"}),e.jsx(F,{onClick:()=>{Ke(!1),St()},children:"Publish Anyway"})]})]})}),e.jsx(Ut,{open:ln,onOpenChange:Ye,children:e.jsxs(Ft,{children:[e.jsxs(Ot,{children:[e.jsx(Bt,{children:"Schedule publishing"}),e.jsx(qt,{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(at,{htmlFor:"schedule-date",children:"Publish at"}),e.jsx("input",{id:"schedule-date",type:"datetime-local",value:Qe,onChange:n=>Yt(n.target.value),min:wt(Date.now()+1200*1e3),className:"w-full rounded-md border px-3 py-2 text-sm",step:"900"})]}),e.jsxs(_t,{children:[e.jsx(F,{variant:"outline",onClick:()=>Ye(!1),children:"Cancel"}),e.jsxs(F,{onClick:Pn,disabled:!Qe||j.isPending,children:[j.isPending&&e.jsx(we,{className:"mr-2 h-4 w-4 animate-spin"}),"Schedule"]})]})]})})]})})}function jr({host:i,contentId:s}){const{data:r}=Ls(i,s,!0);return!r||r.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 ",r.count," other"," ",r.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[r.items.slice(0,5).map(a=>e.jsxs("li",{children:[a.title," (",a.collection,")"]},`${a.contentId}-${a.fieldName}`)),r.items.length>5&&e.jsxs("li",{children:["and ",r.items.length-5," more..."]})]})]})}function Sr({deleteOpen:i,setDeleteOpen:s,onDelete:r,host:a,contentId:l}){const{data:c}=Ls(a,l,i);return e.jsxs(e.Fragment,{children:[e.jsx(Us,{}),e.jsxs(Ut,{open:i,onOpenChange:s,children:[e.jsx(ga,{asChild:!0,children:e.jsxs(F,{variant:"destructive",className:"w-full",children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ft,{children:[e.jsxs(Ot,{children:[e.jsx(Bt,{children:"Delete content?"}),e.jsx(qt,{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(f=>e.jsxs("li",{children:[f.title," (",f.collection,")"]},`${f.contentId}-${f.fieldName}`)),c.items.length>5&&e.jsxs("li",{children:["and ",c.items.length-5," more..."]})]})]}),e.jsxs(_t,{children:[e.jsx(F,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(F,{variant:"destructive",onClick:r,children:"Delete"})]})]})]})]})}function wr({host:i,contentId:s,onViewVersion:r}){const{data:a}=Ps(i,s),[l,c]=t.useState(!1),f=a?.items??[],d=f.map(o=>o.createdBy).filter(Boolean),{resolve:p}=Ys(d);return f.length===0?null:e.jsx($e,{children:e.jsx(Ve,{className:"pt-4",children:e.jsxs(Qs,{open:l,onOpenChange:c,children:[e.jsxs(Ws,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(qs,{className:mt("h-4 w-4 transition",l&&"rotate-90")}),"Version History (",f.length,")"]}),e.jsx(Gs,{className:"mt-2",children:e.jsx("div",{className:"space-y-1",children:f.map((o,y)=>e.jsxs("button",{className:"py-1 text-sm hover:bg-muted rounded px-1 -mx-1 transition-colors w-full text-left",onClick:()=>r(o),children:[e.jsx("span",{children:Ne(o.createdAt)}),o.createdBy&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:p(o.createdBy)}),o.title&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:o.title})]},`${o.createdAt}-${y}`))})})]})})})}export{ti as ContentEditPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as C,u as P}from"./react-vendor-C2CvUxFh.js";import{C as w,b as D,c as F,P as k,D as E,e as O}from"./core.esm-DdQHdRkd.js";import{u as R,S as z,v as B,a as L}from"./sortable.esm-qVEMoaTg.js";import{ai as T,ad as h,j as v,B as p,X as b,P as V}from"./index-Ce5pmRMj.js";import{P as G,a as M,b as Q}from"./popover-CzaQYEEP.js";import{C as q,a as A,b as X,c as _,d as H,e as J}from"./command-Bfmj0MEL.js";import{u as K,a as U}from"./useContentSearch-B3aTjuCu.js";function ce({field:l,value:r,onChange:s}){const{host:o}=P(),c=l.options,i=!!c?.multiple,a=c?.collections;return i?e.jsx(Y,{host:o,collections:a,value:r??[],onChange:s}):e.jsx(W,{host:o,collections:a,value:r,onChange:s})}function W({host:l,collections:r,value:s,onChange:o}){const[c,i]=C.useState(!1),a=s?[s.contentId]:[];function n(d){o(d),i(!1)}return e.jsx("div",{children:s?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:s.title}),e.jsx(v,{variant:"secondary",children:s.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(b,{className:"h-3 w-3"})})]}):e.jsx(y,{host:l,collections:r,selectedIds:a,open:c,onOpenChange:i,onSelect:n,trigger:e.jsxs(p,{type:"button",variant:"outline",children:[e.jsx(h,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function Y({host:l,collections:r,value:s,onChange:o}){const c=D(F(k)),[i,a]=C.useState(!1),n=s??[],d=n.map(t=>t.contentId),j=n.map(t=>t.contentId);function x(t){o([...n,t]),a(!1)}function f(t){o(n.filter((m,u)=>u!==t))}function g(t){const{active:m,over:u}=t;if(u&&m.id!==u.id){const I=n.findIndex(S=>S.contentId===String(m.id)),N=n.findIndex(S=>S.contentId===String(u.id));I!==-1&&N!==-1&&o(L(n,I,N))}}return e.jsx(E,{sensors:c,collisionDetection:O,onDragEnd:g,children:e.jsx(z,{items:d,strategy:B,children:e.jsxs("div",{className:"space-y-2",children:[n.map(t=>e.jsx(Z,{id:t.contentId,contentRef:t,onRemove:()=>f(n.indexOf(t))},t.contentId)),e.jsx(y,{host:l,collections:r,selectedIds:j,open:i,onOpenChange:a,onSelect:x,trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(V,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function Z({id:l,contentRef:r,onRemove:s}){const{attributes:o,listeners:c,setNodeRef:i,transform:a,transition:n}=R({id:l}),d={transform:w.Transform.toString(a),transition:n};return e.jsxs("div",{ref:i,style:d,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...o,...c,children:e.jsx(T,{className:"h-4 w-4"})}),e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:r.title}),e.jsx(v,{variant:"secondary",children:r.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:s,className:"text-destructive",children:e.jsx(b,{className:"h-3 w-3"})})]})}function y({host:l,collections:r,selectedIds:s,open:o,onOpenChange:c,onSelect:i,trigger:a,status:n}){const[d,j]=C.useState(""),x=K(d,300),{data:f,isLoading:g}=U(l,x,r,n);return e.jsxs(G,{open:o,onOpenChange:c,children:[e.jsx(M,{asChild:!0,children:a}),e.jsx(Q,{className:"w-80 p-0",align:"start",children:e.jsxs(q,{shouldFilter:!1,children:[e.jsx(A,{placeholder:"Search content...",value:d,onValueChange:j}),e.jsx(X,{children:g?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(_,{children:"No content found."}),e.jsx(H,{heading:x.length===0?"Recent":void 0,children:f?.items.map(t=>{const m=s.includes(t.contentId);return e.jsxs(J,{value:t.contentId,disabled:m,onSelect:()=>i({contentId:t.contentId,collection:t.collection,slug:t.slug??"",title:t.title}),children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:t.title}),e.jsx(v,{variant:"outline",className:"text-xs",children:t.collection})]},t.contentId)})})]})})]})})]})}export{ce as C,Z as S,y as a};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as C,u as P}from"./react-vendor-C2CvUxFh.js";import{C as w,b as D,c as F,P as k,D as E,e as O}from"./core.esm-DdQHdRkd.js";import{u as R,S as z,v as B,a as L}from"./sortable.esm-qVEMoaTg.js";import{af as T,aj as h,j as v,B as p,X as b,P as V}from"./index-DC1UyCW2.js";import{P as G,a as M,b as Q}from"./popover-BA-47SRI.js";import{C as q,a as A,b as X,c as _,d as H,e as J}from"./command-DaTsImUa.js";import{u as K,a as U}from"./useContentSearch-DbiA8aG-.js";function ce({field:l,value:r,onChange:s}){const{host:o}=P(),c=l.options,i=!!c?.multiple,a=c?.collections;return i?e.jsx(Y,{host:o,collections:a,value:r??[],onChange:s}):e.jsx(W,{host:o,collections:a,value:r,onChange:s})}function W({host:l,collections:r,value:s,onChange:o}){const[c,i]=C.useState(!1),a=s?[s.contentId]:[];function n(d){o(d),i(!1)}return e.jsx("div",{children:s?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:s.title}),e.jsx(v,{variant:"secondary",children:s.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(b,{className:"h-3 w-3"})})]}):e.jsx(y,{host:l,collections:r,selectedIds:a,open:c,onOpenChange:i,onSelect:n,trigger:e.jsxs(p,{type:"button",variant:"outline",children:[e.jsx(h,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function Y({host:l,collections:r,value:s,onChange:o}){const c=D(F(k)),[i,a]=C.useState(!1),n=s??[],d=n.map(t=>t.contentId),j=n.map(t=>t.contentId);function x(t){o([...n,t]),a(!1)}function f(t){o(n.filter((m,u)=>u!==t))}function g(t){const{active:m,over:u}=t;if(u&&m.id!==u.id){const I=n.findIndex(S=>S.contentId===String(m.id)),N=n.findIndex(S=>S.contentId===String(u.id));I!==-1&&N!==-1&&o(L(n,I,N))}}return e.jsx(E,{sensors:c,collisionDetection:O,onDragEnd:g,children:e.jsx(z,{items:d,strategy:B,children:e.jsxs("div",{className:"space-y-2",children:[n.map(t=>e.jsx(Z,{id:t.contentId,contentRef:t,onRemove:()=>f(n.indexOf(t))},t.contentId)),e.jsx(y,{host:l,collections:r,selectedIds:j,open:i,onOpenChange:a,onSelect:x,trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(V,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function Z({id:l,contentRef:r,onRemove:s}){const{attributes:o,listeners:c,setNodeRef:i,transform:a,transition:n}=R({id:l}),d={transform:w.Transform.toString(a),transition:n};return e.jsxs("div",{ref:i,style:d,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...o,...c,children:e.jsx(T,{className:"h-4 w-4"})}),e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:r.title}),e.jsx(v,{variant:"secondary",children:r.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:s,className:"text-destructive",children:e.jsx(b,{className:"h-3 w-3"})})]})}function y({host:l,collections:r,selectedIds:s,open:o,onOpenChange:c,onSelect:i,trigger:a,status:n}){const[d,j]=C.useState(""),x=K(d,300),{data:f,isLoading:g}=U(l,x,r,n);return e.jsxs(G,{open:o,onOpenChange:c,children:[e.jsx(M,{asChild:!0,children:a}),e.jsx(Q,{className:"w-80 p-0",align:"start",children:e.jsxs(q,{shouldFilter:!1,children:[e.jsx(A,{placeholder:"Search content...",value:d,onValueChange:j}),e.jsx(X,{children:g?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(_,{children:"No content found."}),e.jsx(H,{heading:x.length===0?"Recent":void 0,children:f?.items.map(t=>{const m=s.includes(t.contentId);return e.jsxs(J,{value:t.contentId,disabled:m,onSelect:()=>i({contentId:t.contentId,collection:t.collection,slug:t.slug??"",title:t.title}),children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:t.title}),e.jsx(v,{variant:"outline",className:"text-xs",children:t.collection})]},t.contentId)})})]})})]})})]})}export{ce as C,Z as S,y as a};
@@ -0,0 +1 @@
1
+ import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as Ae,f as Pe,r as j}from"./react-vendor-C2CvUxFh.js";import{w as Te,x as _e,B as R,P as oe,v as w,z as ue,I as he,X as L,A as Ie,L as z,j as T,S as $e,a as Fe,y as Ve}from"./index-DC1UyCW2.js";import{d as Be,e as De,a as Le,b as Me,c as Ue}from"./useContent-Bp4f9qe0.js";import{u as qe}from"./useTags-DJlXwDyc.js";import{u as Re}from"./useContentSearch-DbiA8aG-.js";import{u as ze}from"./usePageTitle-DOEFrHbj.js";import{u as Oe}from"./useFilterParams-DYdEuWPE.js";import{m as xe}from"./media-url-DdCoIedP.js";import{u as Ee,F as He,g as me}from"./listCellValue-CBqXAwce.js";import{C as We,c as Xe}from"./card-DlfsF8lU.js";import{C as Q}from"./checkbox-BX8EcGFf.js";import{P as Ze,a as Ge,b as Qe}from"./popover-BA-47SRI.js";import{S as C,a as k,b as y,c as A,d as u}from"./select-waaVyoQ5.js";import{T as Je,a as Ke,b as ge,c as I,d as Ye,e as $}from"./table-Br-QgtTL.js";import{a as F,f as pe}from"./format-BRcflvs9.js";import{g as fe,a as je}from"./contentStatus-WXGfd7vX.js";import{B as es}from"./BulkActionBar-BWysX7Wo.js";import{P as ss}from"./Pagination-Dx8h11Rn.js";import"./radix-C5ZmWuuL.js";import"./command-DaTsImUa.js";const O=3,ve=[{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"}],J=[{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 ws(){const{host:i,collection:c}=Ae(),_=Pe(),{collections:be}=Te(),[d,a]=Oe([{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:""}]),V=d.search,g=d.tag||void 0,p=d.status||void 0,f=d.sort,v=d.relatedTo,b=d.relField,N=Number(d.page)||1,E=Number(d.perPage)||20,K=j.useMemo(()=>{const e=d.after;return e?e.split(","):[]},[d.after]),[B,D]=j.useState(d.q),[h,t]=j.useState(new Set),H=_e(),x=be.find(e=>e.name===c),M=x?.relationships??[],{data:Y}=Ee(i,v||void 0),ee=j.useMemo(()=>{if(!v||!b)return null;const e=M.find(r=>r.name===b);return{type:"relationship",relName:b,relLabel:e?.label??b,contentId:v,contentTitle:Y??"Loading..."}},[v,b,M,Y]);ze({title:x?.label??c??"",actions:x?.singleton?void 0:s.jsx(R,{size:"sm",onClick:()=>_(`/sites/${i}/content/${c}/new`),children:s.jsx(oe,{className:"h-4 w-4"})})});const m=Re(B,300);j.useEffect(()=>{m!==d.q&&a({q:m})},[m,d.q,a]);const S=j.useCallback(()=>{a({page:"1",after:""}),t(new Set)},[a]),Ne=j.useMemo(()=>{const e={};return m&&(e.q=m,e.search=V),g&&(e.tag=g),p&&(e.status=p),f!=="updated_desc"&&(e.sort=f),v&&(e.relatedTo=v),b&&(e.relField=b),e.limit=E,e},[m,V,g,p,f,v,b,E]),Se=N>1?K[N-2]:void 0,{data:P,isLoading:we}=Be(i,c,Ne,Se),W=De(i),se=Le(i),ae=Me(i),te=Ue(i),{data:le}=qe(i),U=j.useMemo(()=>le?.map(e=>e.tag)??[],[le]),X=x?.fields,Z=j.useMemo(()=>X?X.filter(e=>(e.options??{}).listColumn===!0):[],[X]);if(x?.singleton&&P?.items.length===1)return _(`/sites/${i}/content/${c}/${P.items[0].contentId}`,{replace:!0}),null;const q=P?.items,G=q?.map(e=>e.contentId)??[],ne=G.length>0&&G.every(e=>h.has(e));function re(e){t(r=>{const l=new Set(r);return l.has(e)?l.delete(e):l.add(e),l})}function Ce(){t(ne?new Set:new Set(G))}const ce=!!(m||g||p||v),ie=!!m,de=[V!=="prefix"?1:0,g?1:0,p?1:0,f!=="updated_desc"?1:0].reduce((e,r)=>e+r,0),ke=se.isPending||ae.isPending||te.isPending;async function ye(){try{const e=await W.mutateAsync({collection:c,title:x?.label??c});w.success("Singleton content recreated"),_(`/sites/${i}/content/${c}/${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:x?.label??c}),!x?.singleton&&s.jsxs(R,{onClick:()=>_(`/sites/${i}/content/${c}/new`),children:[s.jsx(oe,{className:"mr-2 h-4 w-4"}),"New"]})]}),h.size>0?s.jsx(es,{selectedCount:h.size,onPublish:async()=>{const e=[...h],l=(await se.mutateAsync(e)).filter(o=>o.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to publish`):w.success(`${e.length} item(s) published`),S()},onUnpublish:async()=>{const e=[...h],l=(await ae.mutateAsync(e)).filter(o=>o.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to unpublish`):w.success(`${e.length} item(s) unpublished`),S()},onDelete:async()=>{const e=[...h],l=(await te.mutateAsync(e)).filter(o=>o.status==="rejected").length;l?w.error(`${l} of ${e.length} failed to delete`):w.success(`${e.length} item(s) deleted`),S()},onClear:()=>t(new Set),isPending:ke}):H?s.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(ue,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),s.jsx(he,{placeholder:"Search...",value:B,onChange:e=>{D(e.target.value),S()},className:"pl-8 pr-8"}),B&&s.jsx("button",{onClick:()=>{D(""),S()},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:s.jsx(L,{className:"h-4 w-4"})})]}),s.jsxs(Ze,{children:[s.jsx(Ge,{asChild:!0,children:s.jsxs(R,{variant:"outline",size:"icon",className:"relative shrink-0","aria-label":"Filters",children:[s.jsx(Ie,{className:"h-4 w-4"}),de>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:de})]})}),s.jsxs(Qe,{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:V,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(u,{value:"prefix",children:"Starts with"}),s.jsx(u,{value:"full",children:"Contains"})]})]})]}),U.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(z,{className:"text-xs font-medium",children:"Tag"}),s.jsxs(C,{value:g??"__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(u,{value:"__all__",children:"All tags"}),U.map(e=>s.jsx(u,{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:p??"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:J.map(e=>s.jsx(u,{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:f,onValueChange:e=>{a({sort:e,page:"1",after:""}),t(new Set)},disabled:ie,children:[s.jsx(k,{children:s.jsx(y,{})}),s.jsx(A,{children:ve.map(e=>s.jsx(u,{value:e.value,disabled:e.requiresCollection&&!c,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(ue,{className:"absolute left-2.5 h-4 w-4 text-muted-foreground"}),s.jsx(he,{placeholder:"Search titles...",value:B,onChange:e=>{D(e.target.value),S()},className:"w-56 pl-8 pr-8"}),B&&s.jsx("button",{onClick:()=>{D(""),S()},className:"absolute right-2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{className:"h-4 w-4"})})]}),s.jsxs(C,{value:V,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(u,{value:"prefix",children:"Starts with"}),s.jsx(u,{value:"full",children:"Contains"})]})]}),U.length>0&&s.jsxs(C,{value:g??"__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(u,{value:"__all__",children:"All tags"}),U.map(e=>s.jsx(u,{value:e,children:e},e))]})]}),s.jsxs(C,{value:p??"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:J.map(e=>s.jsx(u,{value:e.value??"all",children:e.label},e.value??"all"))})]}),s.jsx("div",{className:"ml-auto",children:s.jsxs(C,{value:f,onValueChange:e=>{a({sort:e,page:"1",after:""}),t(new Set)},disabled:ie,children:[s.jsx(k,{className:"w-[170px]",children:s.jsx(y,{})}),s.jsx(A,{children:ve.map(e=>s.jsx(u,{value:e.value,disabled:e.requiresCollection&&!c,children:e.label},e.value))})]})})]}),M.length>0&&s.jsx("div",{className:"mb-3",children:s.jsx(He,{relationships:M,activeFilters:ee?[ee]:[],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)}})}),ce&&h.size===0&&s.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[m&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Search: ",m,s.jsx("button",{onClick:()=>{D(""),S()},children:s.jsx(L,{className:"h-3 w-3"})})]}),g&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Tag: ",g,s.jsx("button",{onClick:()=>{a({tag:"",page:"1",after:""}),t(new Set)},children:s.jsx(L,{className:"h-3 w-3"})})]}),p&&s.jsxs(T,{variant:"secondary",className:"gap-1",children:["Status: ",J.find(e=>e.value===p)?.label,s.jsx("button",{onClick:()=>{a({status:"",page:"1",after:""}),t(new Set)},children:s.jsx(L,{className:"h-3 w-3"})})]})]}),we?s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,r)=>s.jsx($e,{className:"h-12 w-full"},r))}):q?.length?s.jsxs(s.Fragment,{children:[H?s.jsx("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"content-card-view",children:q.map(e=>{const r=fe(e.publishedAt,e.lastPublishedAt,e.publishedBlockId,e.lastDraftBlockId,e.scheduledAt,e.scheduledFailed),l=je(r),o=e.tags??[];return s.jsx(We,{className:Ve("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",h.has(e.contentId)&&"ring-2 ring-primary"),onClick:()=>_(`/sites/${i}/content/${c}/${e.contentId}`),children:s.jsxs(Xe,{className:"p-3",children:[s.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.cover?.url&&s.jsx("img",{src:xe(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]}),Z.filter(n=>n.type!=="media").slice(0,3).map(n=>s.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:me(e,n)},n.name)),s.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f.startsWith("created")?e.createdAt?F(e.createdAt):"—":e.lastDraftAt?F(e.lastDraftAt):"—"})]}),s.jsx(Q,{checked:h.has(e.contentId),onCheckedChange:()=>re(e.contentId),onClick:n=>n.stopPropagation(),className:"mt-1"})]}),o.length>0&&s.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:o.slice(0,O).map(n=>s.jsx(T,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:n},n))})]})},e.contentId)})}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs(Je,{children:[s.jsx(Ke,{children:s.jsxs(ge,{children:[s.jsx(I,{className:"w-10",children:s.jsx(Q,{checked:ne,onCheckedChange:Ce,"aria-label":"Select all"})}),s.jsx(I,{children:"Title"}),s.jsx(I,{children:"Slug"}),Z.map(e=>s.jsx(I,{children:e.label||e.name},e.name)),s.jsx(I,{children:"Status"}),s.jsx(I,{children:f.startsWith("created")?"Created":"Updated"})]})}),s.jsx(Ye,{children:q.map(e=>{const r=fe(e.publishedAt,e.lastPublishedAt,e.publishedBlockId,e.lastDraftBlockId),l=je(r),o=e.tags??[];return s.jsxs(ge,{className:"cursor-pointer",onClick:()=>_(`/sites/${i}/content/${c}/${e.contentId}`),children:[s.jsx($,{onClick:n=>n.stopPropagation(),children:s.jsx(Q,{checked:h.has(e.contentId),onCheckedChange:()=>re(e.contentId),"aria-label":`Select ${e.draftTitle||e.title||"Untitled"}`})}),s.jsx($,{className:"font-medium",children:s.jsxs("div",{className:"flex items-center gap-3",children:[e.cover?.url&&s.jsx("img",{src:xe(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"}),o.length>0&&s.jsxs("div",{className:"mt-0.5 flex flex-wrap gap-1",children:[o.slice(0,O).map(n=>s.jsx(T,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal text-muted-foreground",children:n},n)),o.length>O&&s.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",o.length-O," more"]})]})]})]})}),s.jsx($,{className:"text-muted-foreground text-sm",children:e.draftSlug||e.slug||"—"}),Z.map(n=>s.jsx($,{className:"text-muted-foreground text-sm",children:me(e,n)},n.name)),s.jsx($,{children:s.jsx(T,{variant:l.variant,children:l.label})}),s.jsx($,{className:"text-muted-foreground",children:f.startsWith("created")?e.createdAt?F(e.createdAt):"—":e.scheduledAt&&!e.publishedAt?s.jsxs("span",{title:pe(e.scheduledAt),children:["Scheduled ",F(e.scheduledAt)]}):e.publishedAt?s.jsx("span",{title:pe(e.publishedAt),children:F(e.publishedAt)}):e.lastDraftAt?F(e.lastDraftAt):"—"})]},e.contentId)})})]})}),s.jsx(ss,{page:N,hasNext:!!P?.hasMore,hasPrevious:N>1,onNext:()=>{if(P?.items.length){const e=P.items[P.items.length-1].contentId,r=[...K.slice(0,N-1),e];a({page:String(N+1),after:r.join(",")})}else a({page:String(N+1)});t(new Set)},onPrevious:()=>{const e=N-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)}})]}):x?.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:ye,disabled:W.isPending,children:[W.isPending&&s.jsx(Fe,{className:"mr-2 h-4 w-4 animate-spin"}),"Recreate ",x.label]})]}):s.jsx("p",{className:"text-muted-foreground",children:ce?"No content matches the current filters.":"No content yet."})]})}export{ws as ContentListPage};
@@ -1,4 +1,4 @@
1
- import{aK as Xt}from"./index-Ce5pmRMj.js";import{j as I}from"./tanstack-Bs3zYPPV.js";import{r as G}from"./react-vendor-C2CvUxFh.js";import{m as Kt}from"./media-url-DdCoIedP.js";class z{constructor(e,n,r,s,i){this.kind=e,this.input=n,this.begin=r,this.end=s,this.file=i}getText(){return this.input.slice(this.begin,this.end)}getPosition(){let[e,n]=[1,1];for(let r=0;r<this.begin;r++)this.input[r]===`
1
+ import{aI as Xt}from"./index-DC1UyCW2.js";import{j as I}from"./tanstack-Bs3zYPPV.js";import{r as G}from"./react-vendor-C2CvUxFh.js";import{m as Kt}from"./media-url-DdCoIedP.js";class z{constructor(e,n,r,s,i){this.kind=e,this.input=n,this.begin=r,this.end=s,this.file=i}getText(){return this.input.slice(this.begin,this.end)}getPosition(){let[e,n]=[1,1];for(let r=0;r<this.begin;r++)this.input[r]===`
2
2
  `?(e++,n=1):n++;return[e,n]}size(){return this.end-this.begin}}class J{liquidMethodMissing(e,n){}}const en=Object.prototype.toString,We=String.prototype.toLowerCase,Ee=Object.hasOwnProperty;function d(t){return typeof t=="string"}function T(t){return typeof t=="function"}function tn(t){return t&&T(t.then)}function ue(t){return t&&T(t.next)&&T(t.throw)&&T(t.return)}function nn(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function u(t){return t=p(t),d(t)?t:O(t)?"":_(t)?t.map(e=>u(e)).join(""):String(t)}function oe(t){return t=p(t),_(t)?t:d(t)&&t.length>0?[t]:sn(t)?Array.from(t):ye(t)?Object.keys(t).map(e=>[e,t[e]]):[]}function v(t){return t=p(t),O(t)?[]:_(t)?t:[t]}function p(t){return t instanceof J&&T(t.valueOf)?t.valueOf():t}function Fe(t){return+p(t)||0}function me(t){return typeof t=="number"}function bt(t){return t&&T(t.toLiquid)?bt(t.toLiquid()):t}function O(t){return t==null}function rn(t){return t===void 0}function _(t){return en.call(t)==="[object Array]"}function xt(t){return t&&me(t.length)}function sn(t){return ye(t)&&Symbol.iterator in t}function Ye(t,e){t=t||{};for(const n in t)if(Ee.call(t,n)&&e(t[n],n,t)===!1)break;return t}function Tt(t){return t[t.length-1]}function ye(t){const e=typeof t;return t!==null&&(e==="object"||e==="function")}function vt(t,e,n=1){const r=[];for(let s=t;s<e;s+=n)r.push(s);return r}function ie(t,e,n=" "){return _t(t,e,n,(r,s)=>s+r)}function on(t,e,n=" "){return _t(t,e,n,(r,s)=>r+s)}function _t(t,e,n,r){t=String(t);let s=e-t.length;for(;s-- >0;)t=r(t,n);return t}function St(t){return t}function ln(t){return[...t].some(n=>n>="a"&&n<="z")?t.toUpperCase():t.toLowerCase()}function an(t,e){return t.length>e?t.slice(0,e-3)+"...":t}function Je(t,e){return t==null&&e==null?0:t==null?1:e==null||(t=We.call(t),e=We.call(e),t<e)?-1:t>e?1:0}function ke(t){return function(...e){return t.call(this,...e.map(p))}}function j(t){return function(...e){return t.call(this,...e.map(Fe))}}function Ae(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function*le(t){const e=new Set;for(const n of t){const r=JSON.stringify(n);e.has(r)||(e.add(r),yield n)}}const Ze="__liquidClass__";class Z extends Error{constructor(e,n){super(typeof e=="string"?e:e.message),this.context="",typeof e!="string"&&Object.defineProperty(this,"originalError",{value:e,enumerable:!1}),Object.defineProperty(this,"token",{value:n,enumerable:!1}),Object.defineProperty(this,Ze,{value:"LiquidError",enumerable:!1})}update(){Object.defineProperty(this,"context",{value:gn(this.token),enumerable:!1}),this.message=mn(this.message,this.token),this.stack=this.message+`
3
3
  `+this.context+`
4
4
  `+this.stack,this.originalError&&(this.stack+=`
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlockEditor-s0CRZsjy.js","assets/tanstack-Bs3zYPPV.js","assets/react-vendor-C2CvUxFh.js","assets/index-DC1UyCW2.js","assets/radix-C5ZmWuuL.js","assets/index-9sbb3-yI.css","assets/yjs-tXBm_srz.js","assets/command-DaTsImUa.js","assets/MediaField-C3qFf3g5.js","assets/FileTypeIcon-CNHtffHC.js","assets/select-waaVyoQ5.js","assets/table-Br-QgtTL.js","assets/media-url-DdCoIedP.js","assets/format-BRcflvs9.js","assets/CustomBlockPreview-Kc6bb3oq.js","assets/ContentField-BZT4OUfI.js","assets/core.esm-DdQHdRkd.js","assets/sortable.esm-qVEMoaTg.js","assets/popover-BA-47SRI.js","assets/useContentSearch-DbiA8aG-.js","assets/BlockEditor-CQpF8tYb.css"])))=>i.map(i=>d[i]);
2
+ import{j as t}from"./tanstack-Bs3zYPPV.js";import{I as h,B as g,P as I,af as A,T as D,aH as B,x as $,S as _,aI as z,y as N,_ as E,$ as L,a0 as M,L as P}from"./index-DC1UyCW2.js";import{T as q}from"./textarea-BILv1DQB.js";import{C as w}from"./checkbox-BX8EcGFf.js";import{S as O,a as R,b as V,c as U,d as H}from"./select-waaVyoQ5.js";import{a as K}from"./MediaField-C3qFf3g5.js";import{b as G,c as X,P as Y,D as J,e as Q,C as W}from"./core.esm-DdQHdRkd.js";import{S as Z,v as ee,a as te,u as se}from"./sortable.esm-qVEMoaTg.js";import{C as y,c as C}from"./card-DlfsF8lU.js";import{r as x}from"./react-vendor-C2CvUxFh.js";import{C as re}from"./ContentField-BZT4OUfI.js";import{K as ne,M as ae}from"./radix-C5ZmWuuL.js";function j({field:e,value:s,onChange:r}){const n=e.options;return t.jsx(h,{value:s??"",onChange:a=>r(a.target.value),placeholder:n?.placeholder,maxLength:n?.maxLength,required:!!n?.required,type:e.type==="url"?"url":e.type==="email"?"email":"text"})}function oe({field:e,value:s,onChange:r}){const n=e.options;return t.jsx(q,{value:s??"",onChange:a=>r(a.target.value),placeholder:n?.placeholder,maxLength:n?.maxLength,required:!!n?.required,rows:4})}function ie({field:e,value:s,onChange:r}){const n=e.options;return t.jsx(h,{type:"number",value:s??"",onChange:a=>r(a.target.value===""?void 0:Number(a.target.value)),min:n?.min,max:n?.max,step:n?.step,required:!!n?.required})}function ce({field:e,value:s,onChange:r}){return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(w,{id:`field-${e.name}`,checked:!!s,onCheckedChange:n=>r(!!n)}),t.jsx("label",{htmlFor:`field-${e.name}`,className:"text-sm text-muted-foreground",children:e.label})]})}function le({field:e,value:s,onChange:r}){const a=e.options?.choices??[];return t.jsxs(O,{value:s??"",onValueChange:i=>r(i),children:[t.jsx(R,{children:t.jsx(V,{placeholder:"Select..."})}),t.jsx(U,{children:a.map(i=>t.jsx(H,{value:i,children:i},i))})]})}function de({field:e,value:s,onChange:r}){const n=G(X(Y)),a=Array.isArray(s)?s:[],l=e.options?.itemFields??[],o=a.map((m,c)=>`item-${c}`);function d(){r([...a,{}])}function p(m){r(a.filter((c,u)=>u!==m))}function f(m,c){const u=[...a];u[m]=c,r(u)}function v(m){const{active:c,over:u}=m;if(u&&c.id!==u.id){const T=o.indexOf(String(c.id)),k=o.indexOf(String(u.id));r(te(a,T,k))}}return t.jsx(J,{sensors:n,collisionDetection:Q,onDragEnd:v,children:t.jsx(Z,{items:o,strategy:ee,children:t.jsxs("div",{className:"space-y-3",children:[a.map((m,c)=>t.jsx(ue,{id:`item-${c}`,itemFields:l,item:m,onUpdate:u=>f(c,u),onRemove:()=>p(c)},`item-${c}`)),t.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:d,children:[t.jsx(I,{className:"mr-2 h-3 w-3"})," Add Item"]})]})})})}function ue({id:e,itemFields:s,item:r,onUpdate:n,onRemove:a}){const{attributes:i,listeners:l,setNodeRef:o,transform:d,transition:p}=se({id:e}),f={transform:W.Transform.toString(d),transition:p};return t.jsx(y,{ref:o,style:f,children:t.jsxs(C,{className:"flex gap-2 p-3",children:[t.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...i,...l,children:t.jsx(A,{className:"h-4 w-4"})}),t.jsx("div",{className:"flex-1",children:t.jsx(F,{fields:s,values:r,onChange:n})}),t.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:a,className:"text-destructive",children:t.jsx(D,{className:"h-3 w-3"})})]})})}const me=x.createContext(null);function S(){return x.useContext(me)}const xe=x.lazy(()=>z(()=>import("./BlockEditor-s0CRZsjy.js").then(e=>e.a),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]))),pe=2,b=x.createContext(0);function fe({field:e,value:s,onChange:r,compact:n=!0}){const a=x.useContext(b),l=B()?.blockTypes??[],o=$(),p=S()?.getBlockNoteCollab(e.name);return a>=pe?t.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."}):t.jsx(b.Provider,{value:a+1,children:t.jsx("div",{className:o?"":"rounded-md border",children:t.jsx(x.Suspense,{fallback:t.jsx(_,{className:"h-48"}),children:t.jsx(xe,{initialBlocks:Array.isArray(s)?s:[],onChange:r,blockTypes:l,compact:n,collaboration:p})})})})}function he({field:e,value:s,onChange:r}){const a=e.options?.fields??[],i=s&&typeof s=="object"&&!Array.isArray(s)?s:{};return t.jsx(y,{children:t.jsx(C,{className:"p-3",children:t.jsx(F,{fields:a,values:i,onChange:l=>r(l)})})})}function je({field:e,value:s,onChange:r}){const n=e.options,a=e.type==="datetime",i=be(s,a);function l(o){if(!o){r(void 0);return}const d=a?new Date(o).getTime():Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10)));if(Number.isNaN(d)){r(void 0);return}r(d)}return t.jsx(h,{type:a?"datetime-local":"date",value:i,onChange:o=>l(o.target.value),required:!!n?.required})}function be(e,s){if(e==null||e==="")return"";let r;if(typeof e=="number")r=e;else if(typeof e=="string"){const a=/^-?\d+$/.test(e)?Number(e):Date.parse(e);if(Number.isNaN(a))return"";r=a}else return"";const n=new Date(r);if(Number.isNaN(n.getTime()))return"";if(s){const a=i=>String(i).padStart(2,"0");return`${n.getFullYear()}-${a(n.getMonth()+1)}-${a(n.getDate())}T${a(n.getHours())}:${a(n.getMinutes())}`}return n.toISOString().slice(0,10)}function ge({className:e,size:s="default",...r}){return t.jsx(ne,{"data-slot":"avatar","data-size":s,className:N("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6",e),...r})}function Ne({className:e,...s}){return t.jsx(ae,{"data-slot":"avatar-fallback",className:N("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs",e),...s})}function ye(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?(s[0][0]+s[1][0]).toUpperCase():(s[0]?.[0]??"?").toUpperCase()}function Ce({field:e,editors:s}){const r=s.filter(n=>n.activeField===e);return r.length===0?null:t.jsx("span",{className:"inline-flex items-center -space-x-1 ml-2 align-middle","data-testid":"field-presence-indicator",children:r.map(n=>t.jsxs(E,{children:[t.jsx(L,{asChild:!0,children:t.jsx(ge,{className:"h-4 w-4 border-2 ring-1 ring-background",style:{borderColor:n.color},"aria-label":`${n.name} is editing`,children:t.jsx(Ne,{className:"text-[8px] font-medium",style:{backgroundColor:n.color+"20",color:n.color},children:ye(n.name)})})}),t.jsxs(M,{children:[n.name," is editing"]})]},n.sub))})}function F({fields:e,values:s,onChange:r}){const n=S();function a(o,d){r({...s,[o]:d})}function i(o){n?.setActiveField(o)}function l(o){o.currentTarget.contains(o.relatedTarget)||n?.setActiveField(null)}return t.jsx("div",{className:"space-y-4",children:e.map(o=>t.jsxs("div",{className:"space-y-2",onFocusCapture:()=>i(o.name),onBlurCapture:l,children:[o.type!=="boolean"&&t.jsxs(P,{className:"flex items-center",children:[o.label,n&&t.jsx(Ce,{field:o.name,editors:n.editors})]}),Se(o,s[o.name],d=>a(o.name,d))]},o.name))})}function Se(e,s,r){switch(e.type){case"text":case"url":case"email":return t.jsx(j,{field:e,value:s,onChange:r});case"textarea":return t.jsx(oe,{field:e,value:s,onChange:r});case"number":return t.jsx(ie,{field:e,value:s,onChange:r});case"boolean":return t.jsx(ce,{field:e,value:s,onChange:r});case"select":return t.jsx(le,{field:e,value:s,onChange:r});case"media":return t.jsx(K,{field:e,value:s,onChange:r});case"content":return t.jsx(re,{field:e,value:s,onChange:r});case"blocks":return t.jsx(fe,{field:e,value:s,onChange:r});case"array":return t.jsx(de,{field:e,value:s,onChange:r});case"container":return t.jsx(he,{field:e,value:s,onChange:r});case"date":case"datetime":return t.jsx(je,{field:e,value:s,onChange:r});default:return t.jsx(j,{field:e,value:s,onChange:r})}}export{ge as A,me as C,F,Ne as a,Ce as b,ye as i};
@@ -0,0 +1 @@
1
+ import{a as u,b as r,u as c,d as l,j as o}from"./tanstack-Bs3zYPPV.js";import{e as a,aj as f,y as d,be as m,bf as F,bg as y,bd as g}from"./index-DC1UyCW2.js";function S(e,i){const n=a();return c({queryKey:["sites",e,"media","item",i],queryFn:()=>n.apiFetch(`/v1/admin/sites/${e}/media/${i}`),enabled:!!e&&!!i})}function $(e,i){const n=a(),t=new URLSearchParams;i?.tag&&t.set("tag",i.tag),i?.folderId!==void 0&&t.set("folderId",i.folderId),i?.q&&t.set("q",i.q),i?.sort&&t.set("sort",i.sort),i?.limit&&t.set("limit",String(i.limit));const s=t.toString();return c({queryKey:["sites",e,"media",i],queryFn:()=>n.apiFetch(`/v1/admin/sites/${e}/media${s?`?${s}`:""}`),enabled:!!e})}function b(e,i){const n=a();return l({queryKey:["sites",e,"media","infinite",i],queryFn:({pageParam:t})=>{const s=new URLSearchParams;return t&&s.set("cursor",t),i?.tag&&s.set("tag",i.tag),i?.folderId!==void 0&&s.set("folderId",i.folderId),i?.q&&s.set("q",i.q),i?.sort&&s.set("sort",i.sort),i?.limit&&s.set("limit",String(i.limit)),n.apiFetch(`/v1/admin/sites/${e}/media?${s.toString()}`)},initialPageParam:void 0,getNextPageParam:t=>t.hasMore?t.cursor??void 0:void 0,enabled:!!e})}function h(e){const i=a();return r({mutationFn:n=>i.apiFetch(`/v1/admin/sites/${e}/media/upload-url`,{method:"POST",body:JSON.stringify(n)})})}function p(e){const i=a(),n=u();return r({mutationFn:t=>i.apiFetch(`/v1/admin/sites/${e}/media/${t.mediaId}/complete`,{method:"POST",body:JSON.stringify({filename:t.filename,alt:t.alt,caption:t.caption,folderId:t.folderId})}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",e,"media"]})})}function x(e,i){const n=a(),t=u();return r({mutationFn:s=>n.apiFetch(`/v1/admin/sites/${e}/media/${i}`,{method:"PUT",body:JSON.stringify(s)}),onSuccess:()=>t.invalidateQueries({queryKey:["sites",e,"media"]})})}function M(e,i){const n=a(),t=u();return r({mutationFn:()=>n.apiFetch(`/v1/admin/sites/${e}/media/${i}`,{method:"DELETE"}),onSuccess:()=>t.invalidateQueries({queryKey:["sites",e,"media"]})})}function P(e){const i=a();return c({queryKey:["sites",e,"media","folders"],queryFn:()=>i.apiFetch(`/v1/admin/sites/${e}/media/folders`),enabled:!!e})}function K(e){const i=a(),n=u();return r({mutationFn:t=>i.apiFetch(`/v1/admin/sites/${e}/media/folders`,{method:"POST",body:JSON.stringify({name:t})}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",e,"media","folders"]})})}function O(e){const i=a(),n=u();return r({mutationFn:({folderId:t,name:s})=>i.apiFetch(`/v1/admin/sites/${e}/media/folders/${t}`,{method:"PUT",body:JSON.stringify({name:s})}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",e,"media","folders"]})})}function I(e){const i=a(),n=u();return r({mutationFn:t=>i.apiFetch(`/v1/admin/sites/${e}/media/folders/${t}`,{method:"DELETE"}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",e,"media","folders"]})})}function U(e){const i=a(),n=u();return r({mutationFn:t=>i.apiFetch(`/v1/admin/sites/${e}/media/bulk`,{method:"POST",body:JSON.stringify(t)}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",e,"media"]})})}function Q(e){const i=a();return r({mutationFn:({filename:n,size:t})=>i.apiFetch(`/v1/admin/sites/${e}/media/check-duplicate?filename=${encodeURIComponent(n)}&size=${t}`)})}function j(e,i){const n=a(),t=u();return r({mutationFn:s=>n.apiFetch(`/v1/admin/sites/${e}/media/${i}/save-transform`,{method:"POST",body:JSON.stringify(s)}),onSuccess:()=>t.invalidateQueries({queryKey:["sites",e,"media"]})})}function N(e,i){const n=a();return c({queryKey:["sites",e,"media","usage",i],queryFn:()=>n.apiFetch(`/v1/admin/sites/${e}/media/${i}/usage`),enabled:!!e&&!!i})}function C({mimeType:e,className:i}){return e==="application/pdf"?o.jsx(f,{className:d("text-blue-500",i)}):e.startsWith("video/")?o.jsx(m,{className:d("text-purple-500",i)}):e.startsWith("audio/")?o.jsx(F,{className:d("text-green-500",i)}):e==="image/svg+xml"?o.jsx(y,{className:d("text-orange-500",i)}):o.jsx(g,{className:d("text-muted-foreground",i)})}function E(e){return e.startsWith("image/")&&e!=="image/svg+xml"}function J(e){return e==="application/pdf"?"PDF":e==="image/svg+xml"?"SVG":e.startsWith("image/")?"Image":e.startsWith("video/")?"Video":e.startsWith("audio/")?"Audio":e.split("/")[1]?.toUpperCase()??"File"}export{C as F,x as a,M as b,N as c,P as d,K as e,O as f,J as g,I as h,h as i,p as j,U as k,Q as l,$ as m,b as n,E as o,S as p,j as u};
@@ -0,0 +1 @@
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-s0CRZsjy.js";import{r as I}from"./react-vendor-C2CvUxFh.js";import{j as r}from"./tanstack-Bs3zYPPV.js";import"./index-DC1UyCW2.js";import"./radix-C5ZmWuuL.js";import"./yjs-tXBm_srz.js";import"./command-DaTsImUa.js";import"./MediaField-C3qFf3g5.js";import"./FileTypeIcon-CNHtffHC.js";import"./select-waaVyoQ5.js";import"./table-Br-QgtTL.js";import"./media-url-DdCoIedP.js";import"./format-BRcflvs9.js";import"./FieldRenderer-CT-DgCbC.js";import"./textarea-BILv1DQB.js";import"./checkbox-BX8EcGFf.js";import"./core.esm-DdQHdRkd.js";import"./sortable.esm-qVEMoaTg.js";import"./card-DlfsF8lU.js";import"./ContentField-BZT4OUfI.js";import"./popover-BA-47SRI.js";import"./useContentSearch-DbiA8aG-.js";import"./CustomBlockPreview-Kc6bb3oq.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 V=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{V as n,S as r,U as t};
@@ -1,3 +1,3 @@
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-Ce5pmRMj.js";import{S as P,a as B,b as M,c as D,d as O}from"./select-CrRhFGIi.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-DVJcwUt1.js";import{T as se}from"./textarea-6fq0R6VV.js";import{P as te,a as le,b as ne}from"./popover-CzaQYEEP.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(`
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 _,e as q}from"./core.esm-DdQHdRkd.js";import{u as G,S as H,v as V,a as $}from"./sortable.esm-qVEMoaTg.js";import{I as x,y as T,aH as Y,L as i,af as J,a2 as K,B as S,T as W,P as Z,aJ as F,aC as L}from"./index-DC1UyCW2.js";import{S as P,a as B,b as M,c as O,d as D}from"./select-waaVyoQ5.js";import{d as E,i as Q}from"./format-BRcflvs9.js";import{C as X,a as ee,b as ae}from"./collapsible-D3d29uJp.js";import{C as y}from"./checkbox-BX8EcGFf.js";import{T as se}from"./textarea-BILv1DQB.js";import{P as te,a as le,b as ne}from"./popover-BA-47SRI.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:T("font-mono",l),...a}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only letters, numbers, hyphens, and underscores."})]})}const ce=["text","number","boolean","select","media","url","email","date","datetime"];function ie({type:t,options:s,onChange:u}){const m=Y();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(i,{htmlFor:"opt-required",className:"text-sm",children:"Required"})]}),ce.includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-list-column",checked:!!s.listColumn,onCheckedChange:a=>l("listColumn",!!a)}),e.jsx(i,{htmlFor:"opt-list-column",className:"text-sm",children:"Show as column in list view"})]}),["text","textarea"].includes(t)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(i,{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(i,{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(i,{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(i,{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(i,{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(i,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(se,{value:(s.choices??[]).join(`
2
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:"datetime",label:"Date & Time"},{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(D,{children:d.map(i=>e.jsx(O,{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(D,{children:C.map(c=>e.jsx(O,{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};
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(i,{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(i,{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(i,{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(i,{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(i,{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(i,{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(i,{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(i,{htmlFor:"opt-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="container"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(i,{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(i,{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:"datetime",label:"Date & Time"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"},{value:"container",label:"Container"}];function oe({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}=G({id:t}),d=l?w.filter(o=>!l.includes(o.value)):w,h={transform:z.Transform.toString(k),transition:c};function b(o){u({...s,...o})}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(J,{className:"h-4 w-4"})}),e.jsx(ee,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(K,{className:T("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(W,{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:o=>b({name:o}),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:o=>{b({label:o.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:o=>b({type:o,options:{}}),children:[e.jsx(B,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsx(O,{children:d.map(o=>e.jsx(D,{value:o.value,children:o.label},o.value))})]})]})]}),e.jsx(ie,{type:s.type,options:s.options??{},onChange:o=>b({options:o})})]})})]})})}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)),o=a.indexOf(String(h.id));s($(t,b,o))}}return e.jsx(_,{sensors:l,collisionDetection:q,onDragEnd:k,children:e.jsx(H,{items:a,strategy:V,children:e.jsxs("div",{className:"space-y-2",children:[t.map((c,d)=>e.jsx(oe,{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 de=["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 Ce({value:t,onChange:s}){const[u,m]=j.useState(!1),[l,a]=j.useState(""),n=l?Object.keys(F).filter(r=>r.toLowerCase().includes(l.toLowerCase())).slice(0,120):[...de];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 F?e.jsx("button",{type:"button",title:r,className:T("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,Ce as a};