headroom-cms 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/admin/assets/{AdminsPage-C4tJy6Vj.js → AdminsPage-BqfhR4Zc.js} +1 -1
  2. package/admin/assets/{AllContentPage-DL0-UlYh.js → AllContentPage-C11eeRMt.js} +1 -1
  3. package/admin/assets/{ApiKeysPage-pZ6nKCZ_.js → ApiKeysPage-DJjOSLoR.js} +1 -1
  4. package/admin/assets/AuditPage-DJNk7IaW.js +1 -0
  5. package/admin/assets/{BlockEditor-D0Jk8u7w.js → BlockEditor-DDsml97y.js} +2 -2
  6. package/admin/assets/BlockTypeEditPage-Cg7BifaZ.js +1 -0
  7. package/admin/assets/{BlockTypesPage-Q7keQKxn.js → BlockTypesPage-BDFj8TSL.js} +1 -1
  8. package/admin/assets/{BulkActionBar-BGDrNwCg.js → BulkActionBar-CastJGEP.js} +1 -1
  9. package/admin/assets/CollectionEditPage-DGW4iMfo.js +1 -0
  10. package/admin/assets/{CollectionsPage-DDZ-5H7Y.js → CollectionsPage-C8XNxRda.js} +1 -1
  11. package/admin/assets/{ContentCreatePage-C3jn0Etf.js → ContentCreatePage-CX4aOzTR.js} +1 -1
  12. package/admin/assets/ContentEditPage-Dj3RK2BF.js +2 -0
  13. package/admin/assets/ContentListPage-CoDanHrR.js +1 -0
  14. package/admin/assets/{CustomBlockPreview-f9j4g35U.js → CustomBlockPreview-DfDOcbmR.js} +1 -1
  15. package/admin/assets/{FieldBuilder-p1Y8RubR.js → FieldBuilder-8VVLG_j0.js} +2 -2
  16. package/admin/assets/FilterBar-JCp03kkK.js +1 -0
  17. package/admin/assets/{LoginPage-9YUPS1YH.js → LoginPage-gPNC9XRN.js} +1 -1
  18. package/admin/assets/{MediaField-DJpYbUA8.js → MediaField-Du7_gRse.js} +1 -1
  19. package/admin/assets/MediaPage-D9763lEk.js +1 -0
  20. package/admin/assets/RelationshipPicker-D7dFI43Q.js +1 -0
  21. package/admin/assets/SiteSettingsPage-Tfiex2yn.js +1 -0
  22. package/admin/assets/{SiteUsersPage-CtVaB0vq.js → SiteUsersPage-CSV8syR3.js} +1 -1
  23. package/admin/assets/{SitesPage-B-sNyP-Y.js → SitesPage-BFIZ3Y5K.js} +1 -1
  24. package/admin/assets/SubmissionDetailPage-8vtUQsLd.js +1 -0
  25. package/admin/assets/SubmissionEditPage-PgowJuvq.js +1 -0
  26. package/admin/assets/SubmissionListPage-HFDQxPhn.js +1 -0
  27. package/admin/assets/{TagInput-CrI2BIuz.js → TagInput-CDkKZboX.js} +1 -1
  28. package/admin/assets/{TagsPage-BSX5KQvZ.js → TagsPage-BW15-W4H.js} +1 -1
  29. package/admin/assets/{UsersPage-BCTpWULa.js → UsersPage-C-zlDeTy.js} +1 -1
  30. package/admin/assets/{WebhookEditPage-CQO3nmaT.js → WebhookEditPage-cPPALIbH.js} +1 -1
  31. package/admin/assets/{WebhooksPage-ByaTlUGU.js → WebhooksPage-vkPC4m9a.js} +1 -1
  32. package/admin/assets/{card-uKxSQehY.js → card-10FqkZPA.js} +1 -1
  33. package/admin/assets/{checkbox-z1kYnX5o.js → checkbox-fC1QPb_4.js} +1 -1
  34. package/admin/assets/collapsible-B414SspL.js +1 -0
  35. package/admin/assets/{command-CuWC4GrT.js → command-BeacdV75.js} +1 -1
  36. package/admin/assets/{index-HoCNSqv2.css → index-Do_SK4Zl.css} +1 -1
  37. package/admin/assets/{index-b-u0-VCO.js → index-wYNPRVrc.js} +12 -12
  38. package/admin/assets/{popover-rcnajqN6.js → popover-BJDj8C6y.js} +1 -1
  39. package/admin/assets/{select-BKaV0BO_.js → select-BV3jemT6.js} +1 -1
  40. package/admin/assets/{serializeToText-BfR2RCzd.js → serializeToText-BJy0Ms5I.js} +1 -1
  41. package/admin/assets/sortable.esm-QyXA6fio.js +1 -0
  42. package/admin/assets/{table-Bozosvl6.js → table-WkEcC9MH.js} +1 -1
  43. package/admin/assets/{textarea-BnjAxJtk.js → textarea-CHQ9tT69.js} +1 -1
  44. package/admin/assets/{useAdminResolver-B0ady82Q.js → useAdminResolver-CpZj93vH.js} +1 -1
  45. package/admin/assets/useContent-D8yDRTTy.js +1 -0
  46. package/admin/assets/useContentSearch-B-_p0_QX.js +1 -0
  47. package/admin/assets/useFilterParams-DYdEuWPE.js +1 -0
  48. package/admin/assets/{useMedia-CXQpRNYL.js → useMedia-m6zKB__r.js} +1 -1
  49. package/admin/assets/usePageTitle-Bwf-MpTD.js +1 -0
  50. package/admin/assets/{useSiteUsers-BfzIdhvs.js → useSiteUsers-QbiItSH1.js} +1 -1
  51. package/admin/assets/{useTags-B6FtXCHF.js → useTags-CLPWVUB3.js} +1 -1
  52. package/admin/assets/{useWebhooks-iPRX5y4s.js → useWebhooks-no0l3-mF.js} +1 -1
  53. package/admin/index.html +3 -3
  54. package/admin/sw.js +1 -1
  55. package/dist/api.d.ts +1 -0
  56. package/dist/api.d.ts.map +1 -1
  57. package/dist/api.js +1 -1
  58. package/dist/api.js.map +1 -1
  59. package/dist/cdn.js +1 -1
  60. package/dist/cdn.js.map +1 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -0
  63. package/dist/index.js.map +1 -1
  64. package/lambda/api/bootstrap +0 -0
  65. package/lambda/image-lambda/index.mjs +1 -1
  66. package/lambda/webhook-worker/bootstrap +0 -0
  67. package/package.json +1 -1
  68. package/src/api.ts +2 -1
  69. package/src/cdn.ts +1 -1
  70. package/src/index.ts +1 -0
  71. package/admin/assets/AuditPage-aVmcP6Ts.js +0 -1
  72. package/admin/assets/BlockTypeEditPage-DIe2yYEr.js +0 -1
  73. package/admin/assets/CollectionEditPage-Bq75MpXk.js +0 -1
  74. package/admin/assets/ContentEditPage-9tODvFEv.js +0 -2
  75. package/admin/assets/ContentListPage-VCT6GTCF.js +0 -1
  76. package/admin/assets/MediaPage-BgDRQR21.js +0 -1
  77. package/admin/assets/SiteSettingsPage-Diy-PauR.js +0 -1
  78. package/admin/assets/SubmissionDetailPage-DW6QJvAy.js +0 -1
  79. package/admin/assets/SubmissionEditPage-CxYPdI9-.js +0 -1
  80. package/admin/assets/SubmissionListPage-BHF82NF3.js +0 -1
  81. package/admin/assets/sortable.esm-BHilUL-2.js +0 -1
  82. package/admin/assets/useContent-B2MUK4An.js +0 -1
  83. package/admin/assets/usePageTitle-Do4xyFdL.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as H,f as M,r as o}from"./react-vendor-C2CvUxFh.js";import{L as d,I as y,a9 as C,aA as R,S as T,aB as U,aC as V,aD as W,x as _,W as z,B as h,a as G,D as J,i as K,T as Q,k as X,l as Y,m as Z,n as ee,o as ae,v as j}from"./index-wYNPRVrc.js";import{I as se,F as te}from"./FieldBuilder-8VVLG_j0.js";import{i as le}from"./format-C88SDH8g.js";import{T as ie}from"./textarea-CHQ9tT69.js";import{C as ne,a as re,b as oe,c as ce}from"./card-10FqkZPA.js";import{C as de,a as me,b as pe}from"./collapsible-B414SspL.js";import{C as ue}from"./CustomBlockPreview-DfDOcbmR.js";import{u as B}from"./useDebouncedValue-C-cQUcLG.js";import{u as xe}from"./usePageTitle-Bwf-MpTD.js";import"./radix-C1kb_NqW.js";import"./core.esm-B_kcYf6n.js";import"./sortable.esm-QyXA6fio.js";import"./select-BV3jemT6.js";import"./checkbox-fC1QPb_4.js";function he({fields:s,previewTemplate:t,previewData:a,onPreviewDataChange:r,blockTypeName:c,blockTypeLabel:m,blockTypeIcon:b}){const i=B(t,300),f=B(a,300);return e.jsxs("div",{className:"space-y-4",children:[s.map(n=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:n.label}),e.jsx(y,{value:String(a[n.name]??""),onChange:v=>r({...a,[n.name]:v.target.value}),placeholder:`Sample ${n.label}...`})]},n.name)),e.jsx(C,{}),e.jsx("div",{className:"rounded-md border p-4",children:e.jsx(ue,{blockType:{name:c,label:m,icon:b,fields:s,previewTemplate:i},props:f})})]})}function Le(){const{host:s,name:t}=H(),a=t==="new",{data:r,isLoading:c}=R(s,a?"":t);return!a&&c?e.jsxs("div",{className:"space-y-4",children:[e.jsx(T,{className:"h-8 w-64"}),e.jsx(T,{className:"h-64 w-full"})]}):a?e.jsx(N,{host:s,isNew:!0}):r?e.jsx(N,{host:s,isNew:!1,blockType:r},r.name):e.jsx("p",{className:"text-muted-foreground",children:"Block type not found."})}function N({host:s,isNew:t,blockType:a}){const r=M(),c=U(s),m=V(s,a?.name??""),b=W(s,a?.name??""),[i,f]=o.useState(a?.name??""),[n,v]=o.useState(a?.label??""),[g,D]=o.useState(a?.icon??""),[S,P]=o.useState(!t),F=new Set((a?.fields??[]).map(l=>l.name).filter(Boolean)),[p,L]=o.useState(a?.fields??[]),[u,I]=o.useState(a?.previewTemplate??""),[x,E]=o.useState(a?.previewData??{}),[O,k]=o.useState(!1),$=_();xe({title:t?"New Block Type":a?.label??i,showBack:!0,backTo:`/sites/${s}/settings/block-types`});async function q(l){l.preventDefault();try{t?(await c.mutateAsync({name:i,label:n,icon:g,fields:p,previewTemplate:u||void 0,previewData:Object.keys(x).length>0?x:void 0}),j.success("Block type created"),r(`/sites/${s}/settings/block-types/${i}`)):(await m.mutateAsync({label:n,icon:g,fields:p,previewTemplate:u||void 0,previewData:Object.keys(x).length>0?x:void 0}),j.success("Block type updated"))}catch(w){j.error(t?"Failed to create":"Failed to update",{description:w instanceof Error?w.message:void 0})}}async function A(){try{await b.mutateAsync(),j.success("Block type deleted"),r(`/sites/${s}/settings/block-types`)}catch(l){j.error("Failed to delete",{description:l instanceof Error?l.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:t?"New Block Type":`Edit: ${a?.label??i}`}),e.jsxs(ne,{children:[e.jsx(re,{children:e.jsx(oe,{children:"Block Type Settings"})}),e.jsx(ce,{children:e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"name",children:"Name"}),e.jsx(se,{id:"name",value:i,onChange:f,onBlur:()=>{i&&!S&&v(le(i))},readOnly:!t,placeholder:"e.g. hero_banner",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"label",children:"Label"}),e.jsx(y,{id:"label",value:n,onChange:l=>{v(l.target.value),P(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"icon",children:"Icon"}),e.jsx(y,{id:"icon",value:g,onChange:l=>D(l.target.value)})]}),e.jsx(C,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{children:"Block Fields"}),e.jsx(te,{fields:p,onChange:L,existingFieldNames:F})]}),e.jsx(C,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{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. Block field values are available as template variables."}),e.jsx(ie,{id:"preview-template",value:u,onChange:l=>I(l.target.value),rows:6,placeholder:'<div class="p-4">{{ title }}</div>',className:"font-mono text-sm"})]}),(u||p.length>0)&&e.jsxs(de,{children:[e.jsxs(me,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(z,{className:"h-4 w-4 transition-transform [[data-state=open]>&]:rotate-90"}),"Preview"]}),e.jsx(pe,{className:"mt-2",children:e.jsx(he,{fields:p,previewTemplate:u,previewData:x,onPreviewDataChange:E,blockTypeName:i,blockTypeLabel:n,blockTypeIcon:g})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(h,{type:"submit",disabled:c.isPending||m.isPending,children:[(c.isPending||m.isPending)&&e.jsx(G,{className:"mr-2 h-4 w-4 animate-spin"}),t?"Create":"Save"]}),e.jsx(h,{type:"button",variant:"outline",onClick:()=>r(`/sites/${s}/settings/block-types`),children:"Cancel"})]})]})})]}),!t&&e.jsx("div",{className:"mt-6",children:e.jsxs(J,{open:O,onOpenChange:k,children:[e.jsx(K,{asChild:!0,children:e.jsxs(h,{variant:"destructive",children:[e.jsx(Q,{className:"mr-2 h-4 w-4"}),"Delete Block Type"]})}),e.jsxs(X,{children:[e.jsxs(Y,{children:[e.jsx(Z,{children:"Delete block type?"}),e.jsx(ee,{children:"This will permanently delete this block type."})]}),e.jsxs(ae,{children:[e.jsx(h,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),e.jsx(h,{variant:"destructive",onClick:A,children:"Delete"})]})]})]})})]})}export{Le 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{az as p,x as u,B as c,P as o,S as f}from"./index-b-u0-VCO.js";import{T as N,a as b,b as r,c as a,d as g,e as i}from"./table-Bozosvl6.js";import{u as k}from"./usePageTitle-Do4xyFdL.js";import"./radix-C1kb_NqW.js";function C(){const{host:l}=h(),n=j(),{data:t,isLoading:m}=p(l),d=u();return k({title:"Block Types",actions:s.jsx(c,{size:"sm",onClick:()=>n(`/sites/${l}/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:()=>n(`/sites/${l}/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(N,{children:[s.jsx(b,{children:s.jsxs(r,{children:[s.jsx(a,{children:"Name"}),s.jsx(a,{children:"Label"}),s.jsx(a,{children:"Icon"}),s.jsx(a,{children:"Fields"})]})}),s.jsx(g,{children:t.items.map(e=>s.jsxs(r,{className:"cursor-pointer",onClick:()=>n(`/sites/${l}/settings/block-types/${e.name}`),children:[s.jsx(i,{className:"font-mono text-sm",children:e.name}),s.jsx(i,{children:e.label}),s.jsx(i,{children:e.icon}),s.jsx(i,{className:"text-muted-foreground",children:e.fields?.length??0})]},e.name))})]}):s.jsx("p",{className:"text-muted-foreground",children:"No block types defined."})]})}export{C as BlockTypesPage};
1
+ import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as h,f as j}from"./react-vendor-C2CvUxFh.js";import{az as p,x as u,B as c,P as o,S as f}from"./index-wYNPRVrc.js";import{T as N,a as b,b as r,c as a,d as g,e as i}from"./table-WkEcC9MH.js";import{u as k}from"./usePageTitle-Bwf-MpTD.js";import"./radix-C1kb_NqW.js";function C(){const{host:l}=h(),n=j(),{data:t,isLoading:m}=p(l),d=u();return k({title:"Block Types",actions:s.jsx(c,{size:"sm",onClick:()=>n(`/sites/${l}/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:()=>n(`/sites/${l}/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(N,{children:[s.jsx(b,{children:s.jsxs(r,{children:[s.jsx(a,{children:"Name"}),s.jsx(a,{children:"Label"}),s.jsx(a,{children:"Icon"}),s.jsx(a,{children:"Fields"})]})}),s.jsx(g,{children:t.items.map(e=>s.jsxs(r,{className:"cursor-pointer",onClick:()=>n(`/sites/${l}/settings/block-types/${e.name}`),children:[s.jsx(i,{className:"font-mono text-sm",children:e.name}),s.jsx(i,{children:e.label}),s.jsx(i,{children:e.icon}),s.jsx(i,{className:"text-muted-foreground",children:e.fields?.length??0})]},e.name))})]}):s.jsx("p",{className:"text-muted-foreground",children:"No block types defined."})]})}export{C 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-b-u0-VCO.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-wYNPRVrc.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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as i,u as fe,f as Ce}from"./react-vendor-C2CvUxFh.js";import{R as ve,W as Se,y as Q,as as Ne,B as C,T as ee,I as E,P as ye,at as V,au as ke,S as z,x as Pe,w as De,av as Le,aw as Ee,ax as Te,L as h,ay as we,a9 as G,a as Fe,D as Ie,i as Be,k as Ae,l as Re,m as Oe,n as Me,o as qe,v as L}from"./index-wYNPRVrc.js";import{I as se,F as Ue}from"./FieldBuilder-8VVLG_j0.js";import{i as ae,c as $e}from"./format-C88SDH8g.js";import{C as O}from"./checkbox-fC1QPb_4.js";import{C as W,a as Y,b as K,c as X}from"./card-10FqkZPA.js";import{u as _e}from"./usePageTitle-Bwf-MpTD.js";import{S as M,a as q,b as U,c as $,d as f}from"./select-BV3jemT6.js";import{C as He,u as Ve,a as ze,P as Ge,D as We,c as Ye}from"./core.esm-B_kcYf6n.js";import{u as Ke,S as Xe,v as Ze,a as Je}from"./sortable.esm-QyXA6fio.js";import{C as Qe,a as es,b as ss}from"./collapsible-B414SspL.js";import{P as as,a as ts,b as ls}from"./popover-BJDj8C6y.js";import"./radix-C1kb_NqW.js";import"./textarea-CHQ9tT69.js";function ns({id:a,relationship:s,onChange:t,onRemove:u,collections:x,readOnlyName:g,defaultExpanded:j}){const[o,k]=i.useState(j??!1),[m,P]=i.useState(!!s.label),{attributes:v,listeners:c,setNodeRef:r,transform:d,transition:S}=Ke({id:a}),y={transform:He.Transform.toString(d),transition:S};function p(n){t({...s,...n})}const T=x.find(n=>n.name===s.targetCollection)?.label??s.targetCollection;return e.jsx("div",{ref:r,style:y,className:"rounded-md border bg-card",children:e.jsxs(Qe,{open:o,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,...c,children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx(es,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(Se,{className:Q("h-4 w-4 transition-transform",o&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx(Ne,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:T}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(C,{type:"button",variant:"ghost",size:"sm",onClick:u,className:"text-destructive",children:e.jsx(ee,{className:"h-3 w-3"})})]}),e.jsx(ss,{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(se,{value:s.name,onChange:n=>p({name:n}),onBlur:()=>{s.name&&!m&&p({label:ae(s.name)})},readOnly:g,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(E,{value:s.label,onChange:n=>{p({label:n.target.value}),P(!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(M,{value:s.targetCollection,onValueChange:n=>p({targetCollection:n}),children:[e.jsx(q,{className:"h-8 text-sm",children:e.jsx(U,{placeholder:"Select collection..."})}),e.jsx($,{children:x.map(n=>e.jsx(f,{value:n.name,children:n.label},n.name))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:`${a}-multiple`,checked:s.multiple,onCheckedChange:n=>p({multiple:!!n})}),e.jsx("label",{htmlFor:`${a}-multiple`,className:"text-sm",children:"Allow multiple"})]})]})})]})})}function is({relationships:a,onChange:s,collections:t,existingRelNames:u}){const x=Ve(ze(Ge)),g=a.map((c,r)=>`rel-${r}`),[j,o]=i.useState(null);function k(){o(a.length),s([...a,{name:"",label:"",targetCollection:"",multiple:!1}])}function m(c,r){const d=[...a];d[c]=r,s(d)}function P(c){s(a.filter((r,d)=>d!==c))}function v(c){const{active:r,over:d}=c;if(d&&r.id!==d.id){const S=g.indexOf(String(r.id)),y=g.indexOf(String(d.id));s(Je(a,S,y))}}return e.jsx(We,{sensors:x,collisionDetection:Ye,onDragEnd:v,children:e.jsx(Xe,{items:g,strategy:Ze,children:e.jsxs("div",{className:"space-y-2",children:[a.map((c,r)=>e.jsx(ns,{id:`rel-${r}`,relationship:c,onChange:d=>m(r,d),onRemove:()=>P(r),collections:t,readOnlyName:!!(u?.has(c.name)&&c.name),defaultExpanded:r===j},`rel-${r}`)),e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:k,children:[e.jsx(ye,{className:"mr-2 h-3 w-3"})," Add Relationship"]})]})})})}const Z=["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 rs({value:a,onChange:s}){const[t,u]=i.useState(!1),[x,g]=i.useState(""),j=x?Z.filter(o=>o.toLowerCase().includes(x.toLowerCase())):Z;return e.jsxs(as,{open:t,onOpenChange:u,children:[e.jsx(ts,{asChild:!0,children:e.jsxs(C,{variant:"outline",className:"gap-2 w-full justify-start",children:[e.jsx(V,{name:a||"FileText",className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:a||"Select icon..."})]})}),e.jsxs(ls,{className:"w-72 p-2",align:"start",children:[e.jsx(E,{placeholder:"Search icons...",value:x,onChange:o=>g(o.target.value),className:"mb-2",autoFocus:!0}),e.jsxs("div",{className:"grid grid-cols-6 gap-1 max-h-48 overflow-y-auto",children:[j.map(o=>e.jsx("button",{type:"button",title:o,className:Q("flex items-center justify-center rounded-md p-2 hover:bg-accent transition-colors",a===o&&"bg-accent ring-1 ring-primary"),onClick:()=>{s(o),u(!1),g("")},children:e.jsx(V,{name:o,className:"h-4 w-4"})},o)),j.length===0&&e.jsx("p",{className:"col-span-6 text-center text-sm text-muted-foreground py-4",children:"No matching icons"})]})]})]})}const os=["text","textarea","number","boolean","select","array"],cs=["url","email","date","content","blocks"];function ks(){const{host:a,name:s}=fe(),t=s==="new",{data:u,isLoading:x}=ke(a,t?"":s);return!t&&x?e.jsxs("div",{className:"space-y-4",children:[e.jsx(z,{className:"h-8 w-64"}),e.jsx(z,{className:"h-64 w-full"})]}):t?e.jsx(J,{host:a,isNew:!0}):u?e.jsx(J,{host:a,isNew:!1,collection:u},u.name):e.jsx("p",{className:"text-muted-foreground",children:"Collection not found."})}function J({host:a,isNew:s,collection:t}){const u=Ce(),x=Pe(),{collections:g}=De(),j=Le(a),o=Ee(a,t?.name??""),k=Te(a,t?.name??""),[m,P]=i.useState(t?.name??""),[v,c]=i.useState(t?.label??""),[r,d]=i.useState(t?.labelSingular??""),[S,y]=i.useState(t?.slug??""),[p,T]=i.useState(t?.singleton??!1),[n,te]=i.useState(t?.mode??"content"),[F,le]=i.useState(t?.requireAuth??!1),b=n==="submission",[ne,ie]=i.useState(!s),[re,oe]=i.useState(!s),[ce,de]=i.useState(!s),ue=new Set((t?.fields??[]).map(l=>l.name).filter(Boolean)),I=[{name:"blocks",label:"Blocks",type:"blocks",options:{}}],[D,w]=i.useState(t?.fields??(s&&!p?I:[])),[B,me]=i.useState(t?.relationships??[]),xe=new Set((t?.relationships??[]).map(l=>l.name).filter(Boolean)),[A,he]=i.useState(t?.mobileNavPriority??0),[R,ge]=i.useState(t?.icon??""),[je,_]=i.useState(!1);_e({title:s?"New Collection":t?.label??m,showBack:!0,backTo:`/sites/${a}/settings/collections`});function pe(){if(!m)return;const l=ae(m);ne||c(l),re||d($e(l)),ce||y(m.replace(/_/g,"-"))}async function H(l){l?.preventDefault();try{s?(await j.mutateAsync({name:m,label:v,labelSingular:r,slug:S,singleton:b?!1:p,fields:D,relationships:B,mobileNavPriority:A,icon:R,mode:n,requireAuth:b?F:void 0}),L.success("Collection created"),u(`/sites/${a}/settings/collections/${m}`)):(await o.mutateAsync({label:v,labelSingular:r,slug:b?void 0:S,singleton:b?!1:p,fields:D,relationships:B,mobileNavPriority:A,icon:R,mode:n,requireAuth:b?F:void 0}),L.success("Collection updated"))}catch(N){L.error(s?"Failed to create":"Failed to update",{description:N instanceof Error?N.message:void 0})}}async function be(){try{await k.mutateAsync(),L.success("Collection deleted"),u(`/sites/${a}/settings/collections`)}catch(l){L.error("Failed to delete",{description:l instanceof Error?l.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!x&&e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:s?"New Collection":`Edit: ${t?.label??m}`}),e.jsxs(W,{children:[e.jsx(Y,{children:e.jsx(K,{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(h,{htmlFor:"name",children:"Name"}),e.jsx(se,{id:"name",value:m,onChange:P,onBlur:pe,readOnly:!s,placeholder:"e.g. blog_posts",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"mode",children:"Mode"}),e.jsxs(M,{value:n,onValueChange:l=>{te(l),l==="submission"&&s&&(T(!1),w(D.filter(N=>os.includes(N.type)))),l==="content"&&s&&D.length===0&&w(I)},disabled:!s,children:[e.jsx(q,{id:"mode",children:e.jsx(U,{})}),e.jsxs($,{children:[e.jsx(f,{value:"content",children:"Content"}),e.jsx(f,{value:"submission",children:"Submissions"})]})]}),!s&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Mode cannot be changed after creation."})]}),b&&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(we,{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/",m||"{collection}"]})]})]})]})}),b&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:"requireAuth",checked:F,onCheckedChange:l=>le(!!l)}),e.jsx(h,{htmlFor:"requireAuth",children:"Require authentication (site users must be logged in to submit)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"label",children:"Label"}),e.jsx(E,{id:"label",value:v,onChange:l=>{c(l.target.value),ie(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"label-singular",children:"Label Singular"}),e.jsx(E,{id:"label-singular",value:r,onChange:l=>{d(l.target.value),oe(!0)},required:!0})]}),!b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"slug",children:"Slug"}),e.jsx(E,{id:"slug",value:S,onChange:l=>{y(l.target.value),de(!0)},required:!0})]}),!b&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:"singleton",checked:p,onCheckedChange:l=>{const N=!!l;T(N),s&&w(N?[]:I)},disabled:!s}),e.jsx(h,{htmlFor:"singleton",children:"Singleton (single entry, no list)"})]}),e.jsx(G,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Fields"}),e.jsx(Ue,{fields:D,onChange:w,excludeTypes:b?cs:void 0,existingFieldNames:ue})]}),e.jsx(G,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Relationships"}),e.jsx(is,{relationships:B,onChange:me,collections:g,existingRelNames:xe})]})]})})]}),e.jsxs(W,{className:"mt-6",children:[e.jsx(Y,{children:e.jsx(K,{children:"Navigation"})}),e.jsxs(X,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Icon"}),e.jsx(rs,{value:R,onChange:ge})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"mobileNavPriority",children:"Bottom Nav Priority"}),e.jsxs(M,{value:String(A),onValueChange:l=>he(Number(l)),children:[e.jsx(q,{id:"mobileNavPriority",children:e.jsx(U,{})}),e.jsxs($,{children:[e.jsx(f,{value:"0",children:"0 - Hidden"}),e.jsx(f,{value:"1",children:"1"}),e.jsx(f,{value:"2",children:"2"}),e.jsx(f,{value:"3",children:"3"}),e.jsx(f,{value:"4",children:"4"}),e.jsx(f,{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(C,{type:"button",variant:"outline",onClick:()=>u(`/sites/${a}/settings/collections`),children:"Cancel"}),e.jsxs(C,{onClick:H,disabled:j.isPending||o.isPending,children:[(j.isPending||o.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(Ie,{open:je,onOpenChange:_,children:[e.jsx(Be,{asChild:!0,children:e.jsxs(C,{variant:"destructive",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Delete Collection"]})}),e.jsxs(Ae,{children:[e.jsxs(Re,{children:[e.jsx(Oe,{children:"Delete collection?"}),e.jsx(Me,{children:"This will permanently delete the collection and all its content."})]}),e.jsxs(qe,{children:[e.jsx(C,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),e.jsx(C,{variant:"destructive",onClick:be,children:"Delete"})]})]})]})})]})}export{ks 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{ar as f,x as g,B as o,P as c,S as b,j as r}from"./index-b-u0-VCO.js";import{T as p,a as N,b as d,c as i,d as C,e as n}from"./table-Bozosvl6.js";import{u as T}from"./usePageTitle-Do4xyFdL.js";import"./radix-C1kb_NqW.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
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as j,f as u}from"./react-vendor-C2CvUxFh.js";import{ar as f,x as g,B as o,P as c,S as b,j as r}from"./index-wYNPRVrc.js";import{T as p,a as N,b as d,c as i,d as C,e as n}from"./table-WkEcC9MH.js";import{u as T}from"./usePageTitle-Bwf-MpTD.js";import"./radix-C1kb_NqW.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-b-u0-VCO.js";import{e as L}from"./useContent-B2MUK4An.js";import{C as D,a as H,b as M,c as q}from"./card-uKxSQehY.js";import{u as R}from"./usePageTitle-Do4xyFdL.js";import{s as z}from"./format-C88SDH8g.js";import"./radix-C1kb_NqW.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-wYNPRVrc.js";import{e as L}from"./useContent-D8yDRTTy.js";import{C as D,a as H,b as M,c as q}from"./card-10FqkZPA.js";import{u as R}from"./usePageTitle-Bwf-MpTD.js";import{s as z}from"./format-C88SDH8g.js";import"./radix-C1kb_NqW.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,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlockEditor-DDsml97y.js","assets/tanstack-Bs3zYPPV.js","assets/react-vendor-C2CvUxFh.js","assets/index-wYNPRVrc.js","assets/radix-C1kb_NqW.js","assets/index-Do_SK4Zl.css","assets/command-BeacdV75.js","assets/MediaField-Du7_gRse.js","assets/useMedia-m6zKB__r.js","assets/select-BV3jemT6.js","assets/card-10FqkZPA.js","assets/media-url-DIg_vSyf.js","assets/CustomBlockPreview-DfDOcbmR.js","assets/RelationshipPicker-D7dFI43Q.js","assets/core.esm-B_kcYf6n.js","assets/sortable.esm-QyXA6fio.js","assets/popover-BJDj8C6y.js","assets/useContentSearch-B-_p0_QX.js","assets/useDebouncedValue-C-cQUcLG.js","assets/useContent-D8yDRTTy.js","assets/useAdminResolver-CpZj93vH.js","assets/usePageTitle-Bwf-MpTD.js","assets/serializeToText-BJy0Ms5I.js","assets/format-C88SDH8g.js","assets/textarea-CHQ9tT69.js","assets/TagInput-CDkKZboX.js","assets/collapsible-B414SspL.js","assets/useTags-CLPWVUB3.js","assets/checkbox-fC1QPb_4.js","assets/contentStatus-BmaiYVOm.js","assets/BlockEditor-Cp_wZ2xN.css"])))=>i.map(i=>d[i]);
2
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as c,u as it,f as lt,m as rt,L as ct}from"./react-vendor-C2CvUxFh.js";import{f as ot,g as hs,h as dt,i as ms,j as ut,k as ht,l as mt,m as xt,n as pt,o as gt,p as ft,q as jt,r as xs}from"./useContent-D8yDRTTy.js";import{C as Ce,v as S,E as bt,y as ps,F as vt,G as yt,J as Nt,K as Ct,S as F,M as gs,N as fs,O as de,Q as ue,I as he,B as g,P as St,R as wt,T as js,V as kt,x as bs,_ as Dt,L as X,e as Pt,w as At,W as vs,X as ss,Y as Tt,Z as ts,$ as It,a0 as as,a1 as Lt,j as Ft,a as $,a2 as ns,a3 as is,a4 as Rt,a5 as ls,a6 as ve,a7 as Ot,a8 as Mt,D as Se,k as we,l as ke,m as De,n as Pe,o as Ae,a9 as Vt,i as Et}from"./index-wYNPRVrc.js";import{u as Bt}from"./useAdminResolver-CpZj93vH.js";import{u as $t}from"./usePageTitle-Bwf-MpTD.js";import{s as Q,T as Ut,d as _t}from"./serializeToText-BJy0Ms5I.js";import{S as ys,a as Ns,b as Cs,c as Ss,d as oe,e as Ht,f as zt,g as Wt}from"./select-BV3jemT6.js";import{f as _,a as ye}from"./format-C88SDH8g.js";import{T as ws}from"./textarea-CHQ9tT69.js";import{C as H,c as z,a as rs,b as cs}from"./card-10FqkZPA.js";import{T as Jt,A as Kt,a as qt,b as Gt,c as Yt,d as Xt,e as Qt,f as Zt,g as ea}from"./TagInput-CDkKZboX.js";import{C as ks,a as Ds,b as Ps}from"./collapsible-B414SspL.js";import{u as sa}from"./useTags-CLPWVUB3.js";import{M as ta,a as aa}from"./MediaField-Du7_gRse.js";import{u as na}from"./useMedia-m6zKB__r.js";import{m as ia}from"./media-url-DIg_vSyf.js";import{C as la,R as ra}from"./RelationshipPicker-D7dFI43Q.js";import{C as ca}from"./checkbox-fC1QPb_4.js";import{u as oa,a as da,P as ua,D as ha,c as ma,C as xa}from"./core.esm-B_kcYf6n.js";import{S as pa,v as ga,a as fa,u as ja}from"./sortable.esm-QyXA6fio.js";import{g as ba,a as va,b as ya}from"./contentStatus-BmaiYVOm.js";const Na=3e3,Ca="__HEADROOM_API_URL__".replace(/\/+$/,"");function Sa(s,l,n,t){const i=ot(s,l),r=c.useRef(null),u=c.useRef(n?JSON.stringify(n):""),x=c.useRef(void 0),[f,o]=c.useState(null),[y,w]=c.useState(null),h=c.useRef(!1),p=c.useCallback(d=>{JSON.stringify(d)!==u.current&&(r.current=d,clearTimeout(x.current),x.current=window.setTimeout(()=>{if(r.current){const k=r.current,b=JSON.stringify(k);r.current=null,i.mutate(k,{onSuccess:v=>{if(h.current){h.current=!1;return}u.current=b,o(Date.now()),v?.blockId&&w(v.blockId)},onError:v=>{v instanceof Ce&&v.code==="SLUG_TAKEN"?t?.():v instanceof Ce&&v.status===400&&S.error("Auto-save failed",{description:v.message})}})}},Na))},[i,t]),m=c.useCallback(async d=>{if(clearTimeout(x.current),r.current){const N={...r.current};d?.createVersion&&(N.createVersion=!0);const k=JSON.stringify(r.current);r.current=null;const b=await i.mutateAsync(N);u.current=k,o(Date.now()),b?.blockId&&w(b.blockId)}else if(d?.createVersion&&u.current){const k={...JSON.parse(u.current),createVersion:!0},b=await i.mutateAsync(k);o(Date.now()),b?.blockId&&w(b.blockId)}},[i]),P=c.useCallback(()=>{clearTimeout(x.current),r.current=null},[]),D=c.useCallback(d=>{u.current=JSON.stringify(d)},[]),A=c.useCallback(()=>{clearTimeout(x.current),r.current=null,h.current=!0,w(null)},[]);return c.useEffect(()=>()=>{if(clearTimeout(x.current),r.current){const d=JSON.stringify(r.current),N=bt(),k=`${Ca}/v1/admin/sites/${s}/content/${l}/draft`;fetch(k,{method:"PUT",body:d,headers:{"Content-Type":"application/json",...N?{Authorization:`Bearer ${N}`}:{}},keepalive:!0}).catch(()=>{}),r.current=null}},[s,l]),{schedule:p,flush:m,cancel:P,resetBaseline:D,discard:A,isSaving:i.isPending,lastSavedAt:f,lastSavedBlockId:y}}function wa({lines:s}){return e.jsx("div",{className:"font-mono text-sm leading-relaxed",children:s.map((l,n)=>e.jsx("div",{style:{paddingLeft:`${l.indent*1.5}rem`},className:ps("min-h-[1.5em]",l.type==="label"&&"text-muted-foreground font-semibold mt-1",l.type==="heading"&&"font-bold",l.type==="empty"&&"h-2"),children:l.text},n))})}function Te(s){switch(s.kind){case"draft":return"Draft";case"published":return"Published";case"history":return _(s.createdAt)}}function me(s){switch(s.kind){case"draft":return"draft";case"published":return"published";case"history":return`history:${s.blockId}`}}function os({value:s,onChange:l,isPublished:n,versions:t,exclude:i,size:r}){const u=i?me(i):null;function x(f){if(f==="draft")l({kind:"draft"});else if(f==="published")l({kind:"published"});else if(f.startsWith("history:")){const o=f.slice(8),y=t.find(w=>w.blockId===o);y&&l({kind:"history",blockId:y.blockId,createdAt:y.createdAt,title:y.title})}}return e.jsxs(ys,{value:me(s),onValueChange:x,children:[e.jsx(Ns,{size:r,children:e.jsx(Cs,{children:Te(s)})}),e.jsxs(Ss,{position:"popper",children:[u!=="draft"&&e.jsx(oe,{value:"draft",children:"Draft"}),n&&u!=="published"&&e.jsx(oe,{value:"published",children:"Published"}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ht,{}),e.jsxs(zt,{children:[e.jsx(Wt,{children:"Version History"}),t.map(f=>{const o=`history:${f.blockId}`;return o===u?null:e.jsx(oe,{value:o,children:_(f.createdAt)},o)})]})]})]})]})}function ds({ref:s,host:l,contentId:n,collectionFields:t,isSingleton:i,draftBody:r,draftMetadata:u,collectionRelationships:x,draftRelationships:f}){const o=s?.kind==="published",y=s?.kind==="history",w=y?s.blockId:null,{data:h,isLoading:p}=hs(l,n,o),{data:m,isLoading:P}=dt(l,n,y?w:null),D=c.useMemo(()=>(x??[]).map(N=>({name:N.name,label:N.label})),[x]);function A(N){if(D.length!==0)return{defs:D,values:N??{}}}const d=c.useMemo(()=>{if(!s)return[];if(s.kind==="draft")return r?Q(t,r,i?void 0:u,A(f)):[];if(s.kind==="published"){if(!h)return[];const b=i?void 0:{title:h.title,slug:h.slug,snippet:h.snippet,tags:h.tags},v=h.relationships;return Q(t,h.body??{},b,A(v))}if(!m)return[];const N=i?void 0:{title:m.title,slug:m.slug,snippet:m.snippet,tags:m.tags},k=m.relationships;return Q(t,m.body??{},N,A(k))},[s,r,u,f,h,m,t,i,D]);return s?s.kind==="draft"?{lines:d,isLoading:!1,hasData:!!r}:s.kind==="published"?{lines:d,isLoading:p,hasData:!!h}:{lines:d,isLoading:P,hasData:!!m}:{lines:[],isLoading:!1,hasData:!1}}function ka({open:s,onOpenChange:l,host:n,contentId:t,collectionFields:i,isSingleton:r,isPublished:u,draftBody:x,draftMetadata:f,initialVersion:o,collectionRelationships:y,draftRelationships:w}){const[h,p]=c.useState(o??{kind:"published"}),[m,P]=c.useState({kind:"draft"}),[D,A]=c.useState(s),[d,N]=c.useState(o);if((s!==D||o!==d)&&(A(s),N(o),s)){const I=o??{kind:"published"};p(I),P(I.kind==="draft"?{kind:"published"}:{kind:"draft"})}me(h)===me(m)&&(h.kind!=="draft"?P({kind:"draft"}):u&&P({kind:"published"}));const{data:k}=ms(n,t),b=k?.items??[],v={host:n,contentId:t,collectionFields:i,isSingleton:r,draftBody:x,draftMetadata:f,collectionRelationships:y,draftRelationships:w},T=ds({ref:h,...v}),C=ds({ref:m,...v}),W=T.isLoading;return e.jsx(vt,{open:s,onOpenChange:l,children:e.jsxs(yt,{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(Nt,{children:e.jsxs(Ct,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-sm font-normal",children:"Viewing"}),e.jsx(os,{value:h,onChange:p,isPublished:u,versions:b,size:"sm"})]})}),W&&e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(F,{className:"h-6 w-48"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-2/3"})]}),!W&&!T.hasData&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No data available for this version."}),!W&&T.hasData&&e.jsx("div",{className:"p-4",children:e.jsxs(gs,{defaultValue:"changes",children:[e.jsxs(fs,{variant:"line",className:"mb-4",children:[e.jsx(de,{value:"content",children:"Content"}),e.jsx(de,{value:"changes",children:"Changes"})]}),e.jsx(ue,{value:"content",children:e.jsx(wa,{lines:T.lines})}),e.jsxs(ue,{value:"changes",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Compare with"}),e.jsx(os,{value:m,onChange:P,isPublished:u,versions:b,exclude:h,size:"sm"})]}),C.isLoading?e.jsxs("div",{className:"space-y-4",children:[e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-2/3"})]}):C.hasData?e.jsx(Ut,{published:T.lines,draft:C.lines,leftLabel:Te(h),rightLabel:Te(m)}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No data available for comparison."})]})]})})]})})}function Ne({field:s,value:l,onChange:n}){const t=s.options;return e.jsx(he,{value:l??"",onChange:i=>n(i.target.value),placeholder:t?.placeholder,maxLength:t?.maxLength,required:!!t?.required,type:s.type==="url"?"url":s.type==="email"?"email":"text"})}function Da({field:s,value:l,onChange:n}){const t=s.options;return e.jsx(ws,{value:l??"",onChange:i=>n(i.target.value),placeholder:t?.placeholder,maxLength:t?.maxLength,required:!!t?.required,rows:4})}function Pa({field:s,value:l,onChange:n}){const t=s.options;return e.jsx(he,{type:"number",value:l??"",onChange:i=>n(i.target.value===""?void 0:Number(i.target.value)),min:t?.min,max:t?.max,step:t?.step,required:!!t?.required})}function Aa({field:s,value:l,onChange:n}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ca,{id:`field-${s.name}`,checked:!!l,onCheckedChange:t=>n(!!t)}),e.jsx("label",{htmlFor:`field-${s.name}`,className:"text-sm text-muted-foreground",children:s.label})]})}function Ta({field:s,value:l,onChange:n}){const i=s.options?.choices??[];return e.jsxs(ys,{value:l??"",onValueChange:r=>n(r),children:[e.jsx(Ns,{children:e.jsx(Cs,{placeholder:"Select..."})}),e.jsx(Ss,{children:i.map(r=>e.jsx(oe,{value:r,children:r},r))})]})}function Ia({field:s,value:l,onChange:n}){const t=oa(da(ua)),i=l??[],u=s.options?.itemFields??[],x=i.map((h,p)=>`item-${p}`);function f(){n([...i,{}])}function o(h){n(i.filter((p,m)=>m!==h))}function y(h,p){const m=[...i];m[h]=p,n(m)}function w(h){const{active:p,over:m}=h;if(m&&p.id!==m.id){const P=x.indexOf(String(p.id)),D=x.indexOf(String(m.id));n(fa(i,P,D))}}return e.jsx(ha,{sensors:t,collisionDetection:ma,onDragEnd:w,children:e.jsx(pa,{items:x,strategy:ga,children:e.jsxs("div",{className:"space-y-3",children:[i.map((h,p)=>e.jsx(La,{id:`item-${p}`,itemFields:u,item:h,onUpdate:m=>y(p,m),onRemove:()=>o(p)},`item-${p}`)),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:f,children:[e.jsx(St,{className:"mr-2 h-3 w-3"})," Add Item"]})]})})})}function La({id:s,itemFields:l,item:n,onUpdate:t,onRemove:i}){const{attributes:r,listeners:u,setNodeRef:x,transform:f,transition:o}=ja({id:s}),y={transform:xa.Transform.toString(f),transition:o};return e.jsx(H,{ref:x,style:y,children:e.jsxs(z,{className:"flex gap-2 p-3",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...r,...u,children:e.jsx(wt,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Ie,{fields:l,values:n,onChange:t})}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:i,className:"text-destructive",children:e.jsx(js,{className:"h-3 w-3"})})]})})}const Fa=c.lazy(()=>Dt(()=>import("./BlockEditor-DDsml97y.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]))),Ra=2,us=c.createContext(0);function Oa({value:s,onChange:l,compact:n=!0}){const t=c.useContext(us),r=kt()?.blockTypes??[],u=bs();return t>=Ra?e.jsx("div",{className:"rounded-md border border-muted p-4 text-sm text-muted-foreground",children:"Maximum nesting depth reached. Cannot embed another block editor here."}):e.jsx(us.Provider,{value:t+1,children:e.jsx("div",{className:u?"":"rounded-md border",children:e.jsx(c.Suspense,{fallback:e.jsx(F,{className:"h-48"}),children:e.jsx(Fa,{initialBlocks:s??[],onChange:l,blockTypes:r,compact:n})})})})}function Ma({field:s,value:l,onChange:n}){const i=s.options?.fields??[],r=l&&typeof l=="object"&&!Array.isArray(l)?l:{};return e.jsx(H,{children:e.jsx(z,{className:"p-3",children:e.jsx(Ie,{fields:i,values:r,onChange:u=>n(u)})})})}function Ie({fields:s,values:l,onChange:n}){function t(i,r){n({...l,[i]:r})}return e.jsx("div",{className:"space-y-4",children:s.map(i=>e.jsxs("div",{className:"space-y-2",children:[i.type!=="boolean"&&e.jsx(X,{children:i.label}),Va(i,l[i.name],r=>t(i.name,r))]},i.name))})}function Va(s,l,n){switch(s.type){case"text":case"url":case"email":return e.jsx(Ne,{field:s,value:l,onChange:n});case"textarea":return e.jsx(Da,{field:s,value:l,onChange:n});case"number":return e.jsx(Pa,{field:s,value:l,onChange:n});case"boolean":return e.jsx(Aa,{field:s,value:l,onChange:n});case"select":return e.jsx(Ta,{field:s,value:l,onChange:n});case"media":return e.jsx(ta,{field:s,value:l,onChange:n});case"content":return e.jsx(la,{field:s,value:l,onChange:n});case"blocks":return e.jsx(Oa,{field:s,value:l,onChange:n});case"array":return e.jsx(Ia,{field:s,value:l,onChange:n});case"container":return e.jsx(Ma,{field:s,value:l,onChange:n});case"date":return e.jsx(Ne,{field:{...s,type:"text"},value:l,onChange:n});default:return e.jsx(Ne,{field:s,value:l,onChange:n})}}function Ea(){const{host:s,collection:l,id:n}=it(),{data:t,isLoading:i}=ut(s,n);return i?e.jsxs("div",{className:"space-y-4",children:[e.jsx(F,{className:"h-8 w-64"}),e.jsx(F,{className:"h-64 w-full"})]}):t?.content?e.jsx(Ba,{host:s,collection:l,contentId:n,content:t.content,draft:t.draft,publishedBlockId:t.publishedBlockId}):e.jsx("p",{className:"text-muted-foreground",children:"Content not found."})}function Ba({host:s,collection:l,contentId:n,content:t,draft:i,publishedBlockId:r}){const u=lt(),x=Pt(),{collections:f}=At(),o=ht(s,n),y=mt(s,n),w=xt(s,n),h=pt(s,n),p=gt(s,n),m=ft(s,n),P=i?{title:i.title??t.title,slug:i.slug??t.slug??"",snippet:i.snippet??t.snippet??"",tags:i.tags??t.tags??[],coverUrl:i.coverUrl??t.coverUrl??"",coverMediaId:i.coverMediaId??t.coverMediaId??"",coverWidth:i.coverWidth??t.coverWidth??0,coverHeight:i.coverHeight??t.coverHeight??0,body:i.body??{},relationships:i.relationships??{}}:void 0,[D,A]=c.useState(null),d=Sa(s,n,P,()=>{A("This slug is already in use by another item in this collection")}),{data:N}=sa(s),k=N?.map(a=>a.tag),b=f.find(a=>a.name===l),v=c.useMemo(()=>b?.fields??[],[b?.fields]),T=c.useMemo(()=>b?.relationships??[],[b?.relationships]),C=b?.singleton??!1,W=bs(),[I,Le]=c.useState(i?.title??t.title),[M,Fe]=c.useState(i?.slug??t.slug??""),[V,Re]=c.useState(i?.snippet??t.snippet??""),Oe=i?.autoSnippet??"",[J,Me]=c.useState(i?.tags??t.tags??[]),[xe,Ve]=c.useState(i?.coverUrl??t.coverUrl??""),[Z,Ee]=c.useState(i?.coverMediaId??t.coverMediaId??""),[Be,$e]=c.useState(i?.coverWidth??t.coverWidth??0),[Ue,_e]=c.useState(i?.coverHeight??t.coverHeight??0),[K,He]=c.useState(i?.body??{}),[q,ze]=c.useState(i?.relationships??{}),[As,Ts]=c.useState(0),[Is,Ls]=c.useState(!1),[Fs,ee]=c.useState(!1),[Rs,G]=c.useState(!1),[Os,se]=c.useState(null),[pe,te]=c.useState(!1),[Ms,ae]=c.useState(!1),[Vs,ne]=c.useState(!1),[ie,We]=c.useState(""),[Es,ge]=c.useState(!1),[fe,Je]=c.useState(""),Ke=jt(s,n),{data:qe}=na(s,Z),U=c.useCallback(()=>({title:I,slug:M,snippet:V,tags:J,coverUrl:xe,coverMediaId:Z,coverWidth:Be,coverHeight:Ue,body:K,relationships:q}),[I,M,V,J,xe,Z,Be,Ue,K,q]);function Bs(a){Le(a),d.schedule({...U(),title:a})}function $s(a){Fe(a),A(null),d.schedule({...U(),slug:a})}function Us(a){Re(a),d.schedule({...U(),snippet:a})}function _s(a){Me(a),d.schedule({...U(),tags:a})}function Ge(a,j,B,Y){Ve(a),Ee(j),$e(B),_e(Y),d.schedule({...U(),coverUrl:a,coverMediaId:j,coverWidth:B,coverHeight:Y})}function Hs(a){He(a),d.schedule({...U(),body:a})}function zs(a){ze(a),d.schedule({...U(),relationships:a})}const Ws=d.lastSavedBlockId??i?.blockId,R=ba(t.publishedAt,t.lastPublishedAt,r,Ws,t.scheduledAt,t.scheduledFailed),le=va(R),re=ya(R),{data:E}=hs(s,n,!!t.publishedAt),O=c.useMemo(()=>{if(!pe||!E)return null;const a=C?void 0:{title:E.title,slug:E.slug,snippet:E.snippet,tags:E.tags},j=T.map(L=>({name:L.name,label:L.label})),B=E.relationships,Y=j.length>0?{defs:j,values:B??{}}:void 0,et=Q(v,E.body??{},a,Y),st=C?void 0:{title:I,slug:M,snippet:V,tags:J},tt=j.length>0?{defs:j,values:q}:void 0,at=Q(v,K,st,tt),nt=_t(et,at,{comparator:(L,be)=>L.text===be.text&&L.indent===be.indent&&L.type===be.type});let Ze=0,es=0;for(const L of nt)L.added?Ze+=L.count??0:L.removed&&(es+=L.count??0);return{added:Ze,removed:es}},[pe,E,v,T,C,I,M,V,J,K,q]),[Js]=rt(),Ks=Js.get("from")==="recent"?`/sites/${s}/content`:`/sites/${s}/content/${l}`;$t({title:C?b?.label??l:I||"Untitled",showBack:!C,backTo:C?void 0:Ks,badge:{label:le.label,variant:le.variant}});function Ye(){if(t.publishedAt&&t.slug&&M!==t.slug){ae(!0);return}R==="published-changes"?te(!0):ce()}async function ce(){try{d.cancel(),await d.flush({createVersion:!0}),await o.mutateAsync(void 0),S.success("Content published")}catch(a){if(a instanceof Ce&&a.code==="SLUG_TAKEN"){A("This slug is already in use by another item in this collection"),S.error("Slug already in use",{description:"Please choose a different slug before publishing."});return}S.error("Failed to publish",{description:a instanceof Error?a.message:void 0})}}async function qs(){try{await y.mutateAsync(),G(!1),S.success("Content unpublished")}catch(a){S.error("Failed to unpublish",{description:a instanceof Error?a.message:void 0})}}async function Gs(){try{d.discard();const a=await x.apiFetch(`/v1/admin/sites/${s}/content/${n}/published`);await Ke.mutateAsync();const j={title:a.title??"",slug:a.slug??"",snippet:a.snippet??"",tags:a.tags??[],coverUrl:a.coverUrl??"",coverMediaId:a.coverMediaId??"",coverWidth:a.coverWidth??0,coverHeight:a.coverHeight??0,body:a.body??{},relationships:a.relationships??{}};Le(j.title),Fe(j.slug),Re(j.snippet),Me(j.tags),Ve(j.coverUrl),Ee(j.coverMediaId),$e(j.coverWidth),_e(j.coverHeight),He(j.body),ze(j.relationships),Ts(B=>B+1),d.resetBaseline(j),S.success("Changes discarded")}catch(a){S.error("Failed to discard changes",{description:a instanceof Error?a.message:void 0})}}async function Ys(){try{await w.mutateAsync(),S.success("Content deleted"),u(`/sites/${s}/content/${l}`)}catch(a){S.error("Failed to delete",{description:a instanceof Error?a.message:void 0})}}async function Xs(){if(ie)try{d.cancel(),await d.flush({createVersion:!0});const a=new Date(ie).getTime();await p.mutateAsync(a),ne(!1),We(""),S.success("Content scheduled for publishing")}catch(a){S.error("Failed to schedule",{description:a instanceof Error?a.message:void 0})}}async function Qs(){try{await m.mutateAsync(),S.success("Schedule cancelled")}catch(a){S.error("Failed to cancel schedule",{description:a instanceof Error?a.message:void 0})}}async function Zs(){if(fe)try{const a=new Date(fe).getTime();await h.mutateAsync(a),ge(!1),S.success("Publish date updated")}catch(a){S.error("Failed to update publish date",{description:a instanceof Error?a.message:void 0})}}function je(a){const j=new Date(a),B=j.getTimezoneOffset();return new Date(j.getTime()-B*6e4).toISOString().slice(0,16)}const Xe=e.jsx("div",{className:"space-y-6",children:v.length>0?e.jsx(Ie,{fields:v,values:K,onChange:Hs},As):e.jsx(H,{children:e.jsx(z,{className:"py-8 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No fields defined for this collection."," ",e.jsx(ct,{to:`/sites/${s}/settings/collections/${l}`,className:"underline",children:"Configure fields"})]})})})}),Qe=e.jsxs("div",{className:"space-y-6",children:[!C&&e.jsx(H,{children:e.jsxs(z,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{htmlFor:"title",children:"Title"}),e.jsx(he,{id:"title",value:I,onChange:a=>Bs(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{htmlFor:"slug",children:"Slug"}),e.jsx(he,{id:"slug",value:M,onChange:a=>$s(a.target.value),className:D?"border-destructive":""}),D&&e.jsx("p",{className:"text-sm text-destructive",children:D})]}),e.jsxs(ks,{defaultOpen:!!V,children:[e.jsxs(Ds,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(vs,{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.jsxs(Ps,{className:"mt-2 space-y-2",children:[e.jsx(ws,{id:"snippet",value:V,onChange:a=>Us(a.target.value),rows:3,placeholder:"Brief summary of this content..."}),!V&&Oe&&e.jsxs("p",{className:"text-xs italic text-muted-foreground",children:["Auto-generated: ",Oe]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:"Cover Image"}),Z?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>ee(!0),children:[e.jsx("img",{src:ia(xe),alt:qe?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:qe?.filename??"Loading..."}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:a=>{a.stopPropagation(),Ge("","",0,0)},children:e.jsx(ss,{className:"h-3 w-3"})})]}):e.jsxs(g,{type:"button",variant:"outline",className:"w-full",onClick:()=>ee(!0),children:[e.jsx(Tt,{className:"mr-2 h-4 w-4"}),"Select Image"]}),e.jsx(aa,{open:Fs,onClose:()=>ee(!1),onSelect:a=>{Ge(a.url,a.mediaId,a.width??0,a.height??0),ee(!1)},allowedTypes:["image/*"]})]})]})}),!C&&e.jsxs(H,{children:[e.jsx(rs,{children:e.jsx(cs,{children:"Tags"})}),e.jsx(z,{children:e.jsx(Jt,{tags:J,onChange:_s,suggestions:k})})]}),T.length>0&&e.jsx(ra,{relationships:T,values:q,onChange:zs,host:s}),e.jsxs(H,{children:[e.jsx(rs,{children:e.jsx(cs,{children:"Info"})}),e.jsxs(z,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Collection"}),e.jsx("span",{children:t.collection})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"ID"}),e.jsx("span",{className:"font-mono text-xs",children:t.contentId})]}),t.publishedAt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Published"}),Es?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"datetime-local",value:fe,onChange:a=>Je(a.target.value),className:"text-xs border rounded px-1 py-0.5",max:je(Date.now())}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Zs,disabled:h.isPending,children:e.jsx(ts,{className:"h-3 w-3"})}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>ge(!1),children:e.jsx(ss,{className:"h-3 w-3"})})]}):e.jsxs("span",{className:"cursor-pointer hover:underline",title:_(t.publishedAt),onClick:()=>{Je(je(t.publishedAt)),ge(!0)},children:[ye(t.publishedAt),e.jsx(It,{className:"inline ml-1 h-3 w-3 text-muted-foreground"})]})]}),t.lastPublishedAt&&t.lastPublishedAt!==t.publishedAt&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:_(t.lastPublishedAt),children:ye(t.lastPublishedAt)})]})]}):t.lastPublishedAt?e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:_(t.lastPublishedAt),children:ye(t.lastPublishedAt)})]}):null,R==="scheduled"&&t.scheduledAt&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Scheduled for"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(as,{className:"h-3 w-3"}),_(t.scheduledAt)]})]}),R==="schedule-failed"&&e.jsx("div",{className:"text-destructive text-xs",children:"Scheduled publishing failed after multiple attempts."}),t.publishedAt&&e.jsxs(g,{variant:"outline",size:"sm",className:"w-full mt-2",onClick:()=>{se({kind:"published"}),G(!0)},children:[e.jsx(Lt,{className:"mr-2 h-4 w-4"}),"View published"]})]})]}),e.jsx(_a,{host:s,contentId:n,onViewVersion:a=>{se({kind:"history",blockId:a.blockId,createdAt:a.createdAt,title:a.title}),G(!0)}}),!C&&e.jsx(Ua,{deleteOpen:Is,setDeleteOpen:Ls,onDelete:Ys,host:s,contentId:n})]});return e.jsxs("div",{className:"mx-auto max-w-6xl",children:[!W&&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?b?.label??l:I||"Untitled"}),e.jsx(Ft,{variant:le.variant,children:le.label}),d.isSaving&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx($,{className:"h-3 w-3 animate-spin"}),"Saving..."]}),!d.isSaving&&d.lastSavedAt&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(ts,{className:"h-3 w-3"}),"Saved"]})]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(g,{variant:"outline",onClick:()=>d.flush({createVersion:!0}),disabled:d.isSaving,children:[d.isSaving&&e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Save Draft"]}),R==="scheduled"&&e.jsxs(e.Fragment,{children:[e.jsxs(g,{variant:"outline",onClick:Qs,disabled:m.isPending,children:[m.isPending&&e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel Schedule"]}),e.jsxs(g,{onClick:()=>void ce(),disabled:o.isPending,children:[o.isPending&&e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish Now"]})]}),R!=="scheduled"&&re&&e.jsxs("div",{className:"flex",children:[e.jsxs(g,{onClick:Ye,disabled:o.isPending,className:"rounded-r-none",children:[o.isPending&&e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),re]}),!t.publishedAt&&e.jsxs(ns,{children:[e.jsx(is,{asChild:!0,children:e.jsx(g,{className:"rounded-l-none border-l px-2",disabled:o.isPending,children:e.jsx(Rt,{className:"h-4 w-4"})})}),e.jsx(ls,{align:"end",children:e.jsxs(ve,{onClick:()=>ne(!0),children:[e.jsx(as,{className:"mr-2 h-4 w-4"}),"Schedule for later"]})})]})]}),t.publishedAt&&e.jsxs(ns,{children:[e.jsx(is,{asChild:!0,children:e.jsx(g,{variant:"outline",size:"icon",children:e.jsx(Ot,{className:"h-4 w-4"})})}),e.jsxs(ls,{align:"end",children:[R==="published-changes"&&e.jsxs(ve,{onClick:Gs,disabled:Ke.isPending,children:[e.jsx(Mt,{className:"mr-2 h-4 w-4"}),"Discard Changes"]}),e.jsx(ve,{onClick:qs,className:"text-destructive focus:text-destructive",children:"Unpublish"})]})]})]})]}),W?e.jsxs(gs,{defaultValue:"content",children:[e.jsxs("div",{className:"mb-2 flex items-center",children:[e.jsxs(fs,{variant:"line",children:[e.jsx(de,{value:"content",children:"Content"}),e.jsx(de,{value:"info",children:"Info"})]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>d.flush({createVersion:!0}),disabled:d.isSaving,children:[d.isSaving&&e.jsx($,{className:"mr-1 h-3 w-3 animate-spin"}),"Save"]}),R!=="scheduled"&&re&&e.jsxs(g,{size:"sm",onClick:Ye,disabled:o.isPending,children:[o.isPending&&e.jsx($,{className:"mr-1 h-3 w-3 animate-spin"}),re]})]})]}),e.jsx(ue,{value:"content",className:"mt-0",children:Xe}),e.jsx(ue,{value:"info",className:"mt-0",children:Qe})]}):e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:Xe}),e.jsx("div",{children:Qe})]}),e.jsx(ka,{open:Rs,onOpenChange:a=>{G(a),a||se(null)},host:s,contentId:n,collectionFields:v,isSingleton:C,isPublished:!!t.publishedAt,draftBody:K,draftMetadata:C?void 0:{title:I,slug:M,snippet:V,tags:J},initialVersion:Os,collectionRelationships:T,draftRelationships:q}),e.jsx(Kt,{open:pe,onOpenChange:te,children:e.jsxs(qt,{children:[e.jsxs(Gt,{children:[e.jsx(Yt,{children:"Publish changes?"}),e.jsx(Xt,{children:O?e.jsxs(e.Fragment,{children:[O.added>0&&e.jsxs("span",{className:"text-green-600",children:["+",O.added," added"]}),O.added>0&&O.removed>0&&", ",O.removed>0&&e.jsxs("span",{className:"text-red-600",children:["-",O.removed," removed"]}),O.added===0&&O.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(g,{variant:"link",className:"p-0 h-auto text-sm",onClick:()=>{te(!1),se({kind:"published"}),G(!0)},children:"View full diff"})}),e.jsxs(Qt,{children:[e.jsx(Zt,{children:"Cancel"}),e.jsx(ea,{onClick:()=>{te(!1),ce()},children:"Publish Update"})]})]})}),e.jsx(Se,{open:Ms,onOpenChange:ae,children:e.jsxs(we,{children:[e.jsxs(ke,{children:[e.jsx(De,{children:"Slug change detected"}),e.jsxs(Pe,{children:["You are changing the slug from “",t.slug,"” to “",M,"”. This may break external bookmarks and SEO links."]})]}),e.jsx($a,{host:s,contentId:n}),e.jsxs(Ae,{children:[e.jsx(g,{variant:"outline",onClick:()=>ae(!1),children:"Cancel"}),e.jsx(g,{onClick:()=>{ae(!1),ce()},children:"Publish Anyway"})]})]})}),e.jsx(Se,{open:Vs,onOpenChange:ne,children:e.jsxs(we,{children:[e.jsxs(ke,{children:[e.jsx(De,{children:"Schedule publishing"}),e.jsx(Pe,{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(X,{htmlFor:"schedule-date",children:"Publish at"}),e.jsx("input",{id:"schedule-date",type:"datetime-local",value:ie,onChange:a=>We(a.target.value),min:je(Date.now()+1200*1e3),className:"w-full rounded-md border px-3 py-2 text-sm",step:"900"})]}),e.jsxs(Ae,{children:[e.jsx(g,{variant:"outline",onClick:()=>ne(!1),children:"Cancel"}),e.jsxs(g,{onClick:Xs,disabled:!ie||p.isPending,children:[p.isPending&&e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Schedule"]})]})]})})]})}function $a({host:s,contentId:l}){const{data:n}=xs(s,l,!0);return!n||n.count===0?null:e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-50 p-3 text-sm dark:bg-yellow-950/30",children:[e.jsxs("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:["This content is referenced by ",n.count," other"," ",n.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[n.items.slice(0,5).map(t=>e.jsxs("li",{children:[t.title," (",t.collection,")"]},`${t.contentId}-${t.fieldName}`)),n.items.length>5&&e.jsxs("li",{children:["and ",n.items.length-5," more..."]})]})]})}function Ua({deleteOpen:s,setDeleteOpen:l,onDelete:n,host:t,contentId:i}){const{data:r}=xs(t,i,s);return e.jsxs(e.Fragment,{children:[e.jsx(Vt,{}),e.jsxs(Se,{open:s,onOpenChange:l,children:[e.jsx(Et,{asChild:!0,children:e.jsxs(g,{variant:"destructive",className:"w-full",children:[e.jsx(js,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(we,{children:[e.jsxs(ke,{children:[e.jsx(De,{children:"Delete content?"}),e.jsx(Pe,{children:"This action cannot be undone. The content will be permanently deleted."})]}),r&&r.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 ",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(u=>e.jsxs("li",{children:[u.title," (",u.collection,")"]},`${u.contentId}-${u.fieldName}`)),r.items.length>5&&e.jsxs("li",{children:["and ",r.items.length-5," more..."]})]})]}),e.jsxs(Ae,{children:[e.jsx(g,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(g,{variant:"destructive",onClick:n,children:"Delete"})]})]})]})]})}function _a({host:s,contentId:l,onViewVersion:n}){const{data:t}=ms(s,l),[i,r]=c.useState(!1),u=t?.items??[],x=u.map(o=>o.createdBy).filter(Boolean),{resolve:f}=Bt(x);return u.length===0?null:e.jsx(H,{children:e.jsx(z,{className:"pt-4",children:e.jsxs(ks,{open:i,onOpenChange:r,children:[e.jsxs(Ds,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(vs,{className:ps("h-4 w-4 transition",i&&"rotate-90")}),"Version History (",u.length,")"]}),e.jsx(Ps,{className:"mt-2",children:e.jsx("div",{className:"space-y-1",children:u.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:()=>n(o),children:[e.jsx("span",{children:_(o.createdAt)}),o.createdBy&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:f(o.createdBy)}),o.title&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:o.title})]},`${o.createdAt}-${y}`))})})]})})})}const hn=Object.freeze(Object.defineProperty({__proto__:null,ContentEditPage:Ea},Symbol.toStringTag,{value:"Module"}));export{hn as C,Ie as F};
@@ -0,0 +1 @@
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as Ce,f as Se,r as v}from"./react-vendor-C2CvUxFh.js";import{w as we,x as ke,B as F,P as re,v as b,z as ce,I as ie,X as V,A as ye,L as M,j as y,S as _e,a as Ae,y as Te}from"./index-wYNPRVrc.js";import{d as Ie,e as Pe,a as $e,b as Fe,c as Ve}from"./useContent-D8yDRTTy.js";import{u as Be}from"./useTags-CLPWVUB3.js";import{u as Ue}from"./useDebouncedValue-C-cQUcLG.js";import{u as De}from"./usePageTitle-Bwf-MpTD.js";import{u as Le}from"./useFilterParams-DYdEuWPE.js";import{m as de}from"./media-url-DIg_vSyf.js";import{u as qe,F as Me}from"./FilterBar-JCp03kkK.js";import{C as Re,c as ze}from"./card-10FqkZPA.js";import{C as X}from"./checkbox-fC1QPb_4.js";import{P as Oe,a as Ee,b as He}from"./popover-BJDj8C6y.js";import{S as N,a as C,b as S,c as w,d}from"./select-BV3jemT6.js";import{T as Xe,a as Ze,b as oe,c as B,d as Ge,e as U}from"./table-WkEcC9MH.js";import{a as R,f as ue}from"./format-C88SDH8g.js";import{g as he,a as xe}from"./contentStatus-BmaiYVOm.js";import{B as Qe}from"./BulkActionBar-CastJGEP.js";import"./radix-C1kb_NqW.js";import"./command-BeacdV75.js";import"./useContentSearch-B-_p0_QX.js";const z=3,me=[{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"}],Z=[{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 gs(){const{host:c,collection:t}=Ce(),_=Se(),{collections:je}=we(),[h,n]=Le([{key:"q",defaultValue:""},{key:"search",defaultValue:"prefix"},{key:"tag",defaultValue:""},{key:"status",defaultValue:""},{key:"sort",defaultValue:"updated_desc"},{key:"relatedTo",defaultValue:""},{key:"relField",defaultValue:""}]),T=h.search,x=h.tag||void 0,m=h.status||void 0,A=h.sort,g=h.relatedTo,f=h.relField,[I,P]=v.useState(h.q),[pe,G]=v.useState(),[o,k]=v.useState(new Set),O=ke(),j=je.find(s=>s.name===t),D=j?.relationships??[],{data:Q}=qe(c,g||void 0),J=v.useMemo(()=>{if(!g||!f)return null;const s=D.find(r=>r.name===f);return{type:"relationship",relName:f,relLabel:s?.label??f,contentId:g,contentTitle:Q??"Loading..."}},[g,f,D,Q]);De({title:j?.label??t??"",actions:j?.singleton?void 0:e.jsx(F,{size:"sm",onClick:()=>_(`/sites/${c}/content/${t}/new`),children:e.jsx(re,{className:"h-4 w-4"})})});const u=Ue(I,300);v.useEffect(()=>{u!==h.q&&n({q:u})},[u,h.q,n]);const a=v.useCallback(()=>G(void 0),[]),ge=v.useMemo(()=>{const s={};return u&&(s.q=u,s.search=T),x&&(s.tag=x),m&&(s.status=m),A!=="updated_desc"&&(s.sort=A),g&&(s.relatedTo=g),f&&(s.relField=f),s},[u,T,x,m,A,g,f]),{data:$,isLoading:fe}=Ie(c,t,ge,pe),E=Pe(c),K=$e(c),W=Fe(c),Y=Ve(c),{data:ee}=Be(c),L=v.useMemo(()=>ee?.map(s=>s.tag)??[],[ee]);if(j?.singleton&&$?.items.length===1)return _(`/sites/${c}/content/${t}/${$.items[0].contentId}`,{replace:!0}),null;const q=$?.items,H=q?.map(s=>s.contentId)??[],se=H.length>0&&H.every(s=>o.has(s));function le(s){k(r=>{const l=new Set(r);return l.has(s)?l.delete(s):l.add(s),l})}function ve(){k(se?new Set:new Set(H))}const ae=!!(u||x||m||g),te=!!u,ne=[T!=="prefix"?1:0,x?1:0,m?1:0,A!=="updated_desc"?1:0].reduce((s,r)=>s+r,0),be=K.isPending||W.isPending||Y.isPending;async function Ne(){try{const s=await E.mutateAsync({collection:t,title:j?.label??t});b.success("Singleton content recreated"),_(`/sites/${c}/content/${t}/${s.contentId}`)}catch(s){b.error("Failed to recreate singleton",{description:s instanceof Error?s.message:void 0})}}return e.jsxs("div",{children:[!O&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:j?.label??t}),!j?.singleton&&e.jsxs(F,{onClick:()=>_(`/sites/${c}/content/${t}/new`),children:[e.jsx(re,{className:"mr-2 h-4 w-4"}),"New"]})]}),o.size>0?e.jsx(Qe,{selectedCount:o.size,onPublish:async()=>{const s=[...o],l=(await K.mutateAsync(s)).filter(i=>i.status==="rejected").length;l?b.error(`${l} of ${s.length} failed to publish`):b.success(`${s.length} item(s) published`),k(new Set)},onUnpublish:async()=>{const s=[...o],l=(await W.mutateAsync(s)).filter(i=>i.status==="rejected").length;l?b.error(`${l} of ${s.length} failed to unpublish`):b.success(`${s.length} item(s) unpublished`),k(new Set)},onDelete:async()=>{const s=[...o],l=(await Y.mutateAsync(s)).filter(i=>i.status==="rejected").length;l?b.error(`${l} of ${s.length} failed to delete`):b.success(`${s.length} item(s) deleted`),k(new Set)},onClear:()=>k(new Set),isPending:be}):O?e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"Search...",value:I,onChange:s=>{P(s.target.value),a()},className:"pl-8 pr-8"}),I&&e.jsx("button",{onClick:()=>{P(""),a()},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs(Oe,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"icon",className:"relative shrink-0","aria-label":"Filters",children:[e.jsx(ye,{className:"h-4 w-4"}),ne>0&&e.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:ne})]})}),e.jsxs(He,{className:"w-64 space-y-3",align:"end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-xs font-medium",children:"Search Mode"}),e.jsxs(N,{value:T,onValueChange:s=>{n({search:s}),a()},children:[e.jsx(C,{children:e.jsx(S,{})}),e.jsxs(w,{children:[e.jsx(d,{value:"prefix",children:"Starts with"}),e.jsx(d,{value:"full",children:"Contains"})]})]})]}),L.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-xs font-medium",children:"Tag"}),e.jsxs(N,{value:x??"__all__",onValueChange:s=>{n({tag:s==="__all__"?"":s}),a()},children:[e.jsx(C,{children:e.jsx(S,{})}),e.jsxs(w,{children:[e.jsx(d,{value:"__all__",children:"All tags"}),L.map(s=>e.jsx(d,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-xs font-medium",children:"Status"}),e.jsxs(N,{value:m??"all",onValueChange:s=>{n({status:s==="all"?"":s}),a()},children:[e.jsx(C,{children:e.jsx(S,{})}),e.jsx(w,{children:Z.map(s=>e.jsx(d,{value:s.value??"all",children:s.label},s.value??"all"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{className:"text-xs font-medium",children:"Sort"}),e.jsxs(N,{value:A,onValueChange:s=>{n({sort:s}),a()},disabled:te,children:[e.jsx(C,{children:e.jsx(S,{})}),e.jsx(w,{children:me.map(s=>e.jsx(d,{value:s.value,disabled:s.requiresCollection&&!t,children:s.label},s.value))})]})]})]})]})]}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(ce,{className:"absolute left-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"Search titles...",value:I,onChange:s=>{P(s.target.value),a()},className:"w-56 pl-8 pr-8"}),I&&e.jsx("button",{onClick:()=>{P(""),a()},className:"absolute right-2 text-muted-foreground hover:text-foreground",children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs(N,{value:T,onValueChange:s=>{n({search:s}),a()},children:[e.jsx(C,{className:"w-[130px]",children:e.jsx(S,{})}),e.jsxs(w,{children:[e.jsx(d,{value:"prefix",children:"Starts with"}),e.jsx(d,{value:"full",children:"Contains"})]})]}),L.length>0&&e.jsxs(N,{value:x??"__all__",onValueChange:s=>{n({tag:s==="__all__"?"":s}),a()},children:[e.jsx(C,{className:"w-[140px]",children:e.jsx(S,{placeholder:"Tag"})}),e.jsxs(w,{children:[e.jsx(d,{value:"__all__",children:"All tags"}),L.map(s=>e.jsx(d,{value:s,children:s},s))]})]}),e.jsxs(N,{value:m??"all",onValueChange:s=>{n({status:s==="all"?"":s}),a()},children:[e.jsx(C,{className:"w-[150px]",children:e.jsx(S,{})}),e.jsx(w,{children:Z.map(s=>e.jsx(d,{value:s.value??"all",children:s.label},s.value??"all"))})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(N,{value:A,onValueChange:s=>{n({sort:s}),a()},disabled:te,children:[e.jsx(C,{className:"w-[170px]",children:e.jsx(S,{})}),e.jsx(w,{children:me.map(s=>e.jsx(d,{value:s.value,disabled:s.requiresCollection&&!t,children:s.label},s.value))})]})})]}),D.length>0&&e.jsx("div",{className:"mb-3",children:e.jsx(Me,{relationships:D,activeFilters:J?[J]:[],onFilterAdd:s=>{n({relatedTo:s.contentId,relField:s.relName}),a()},onFilterRemove:()=>{n({relatedTo:"",relField:""}),a()}})}),ae&&o.size===0&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[u&&e.jsxs(y,{variant:"secondary",className:"gap-1",children:["Search: ",u,e.jsx("button",{onClick:()=>{P(""),a()},children:e.jsx(V,{className:"h-3 w-3"})})]}),x&&e.jsxs(y,{variant:"secondary",className:"gap-1",children:["Tag: ",x,e.jsx("button",{onClick:()=>{n({tag:""}),a()},children:e.jsx(V,{className:"h-3 w-3"})})]}),m&&e.jsxs(y,{variant:"secondary",className:"gap-1",children:["Status: ",Z.find(s=>s.value===m)?.label,e.jsx("button",{onClick:()=>{n({status:""}),a()},children:e.jsx(V,{className:"h-3 w-3"})})]})]}),fe?e.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((s,r)=>e.jsx(_e,{className:"h-12 w-full"},r))}):q?.length?e.jsxs(e.Fragment,{children:[O?e.jsx("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"content-card-view",children:q.map(s=>{const r=he(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId,s.scheduledAt,s.scheduledFailed),l=xe(r),i=s.tags??[];return e.jsx(Re,{className:Te("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",o.has(s.contentId)&&"ring-2 ring-primary"),onClick:()=>_(`/sites/${c}/content/${t}/${s.contentId}`),children:e.jsxs(ze,{className:"p-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[s.coverUrl&&e.jsx("img",{src:de(s.coverUrl),alt:"",className:"h-12 w-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"font-medium truncate",children:s.title||"Untitled"}),e.jsx(y,{variant:l.variant,className:"shrink-0",children:l.label})]}),s.slug&&e.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["/",s.slug]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.lastDraftAt?R(s.lastDraftAt):"—"})]}),e.jsx(X,{checked:o.has(s.contentId),onCheckedChange:()=>le(s.contentId),onClick:p=>p.stopPropagation(),className:"mt-1"})]}),i.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:i.slice(0,z).map(p=>e.jsx(y,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:p},p))})]})},s.contentId)})}):e.jsxs(Xe,{children:[e.jsx(Ze,{children:e.jsxs(oe,{children:[e.jsx(B,{className:"w-10",children:e.jsx(X,{checked:se,onCheckedChange:ve,"aria-label":"Select all"})}),e.jsx(B,{children:"Title"}),e.jsx(B,{children:"Slug"}),e.jsx(B,{children:"Status"}),e.jsx(B,{children:"Updated"})]})}),e.jsx(Ge,{children:q.map(s=>{const r=he(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId),l=xe(r),i=s.tags??[];return e.jsxs(oe,{className:"cursor-pointer",onClick:()=>_(`/sites/${c}/content/${t}/${s.contentId}`),children:[e.jsx(U,{onClick:p=>p.stopPropagation(),children:e.jsx(X,{checked:o.has(s.contentId),onCheckedChange:()=>le(s.contentId),"aria-label":`Select ${s.title||"Untitled"}`})}),e.jsx(U,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-3",children:[s.coverUrl&&e.jsx("img",{src:de(s.coverUrl),alt:"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:s.title||"Untitled"}),i.length>0&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap gap-1",children:[i.slice(0,z).map(p=>e.jsx(y,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal text-muted-foreground",children:p},p)),i.length>z&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",i.length-z," more"]})]})]})]})}),e.jsx(U,{className:"text-muted-foreground text-sm",children:s.slug||"—"}),e.jsx(U,{children:e.jsx(y,{variant:l.variant,children:l.label})}),e.jsx(U,{className:"text-muted-foreground",children:s.scheduledAt&&!s.publishedAt?e.jsxs("span",{title:ue(s.scheduledAt),children:["Scheduled ",R(s.scheduledAt)]}):s.publishedAt?e.jsx("span",{title:ue(s.publishedAt),children:R(s.publishedAt)}):s.lastDraftAt?R(s.lastDraftAt):"—"})]},s.contentId)})})]}),$?.hasMore&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(F,{variant:"outline",onClick:()=>G($.cursor??void 0),children:"Load More"})})]}):j?.singleton?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Singleton content is missing. Click below to recreate it."}),e.jsxs(F,{onClick:Ne,disabled:E.isPending,children:[E.isPending&&e.jsx(Ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Recreate ",j.label]})]}):e.jsx("p",{className:"text-muted-foreground",children:ae?"No content matches the current filters.":"No content yet."})]})}export{gs as ContentListPage};
@@ -1,4 +1,4 @@
1
- import{_ as Qt}from"./index-b-u0-VCO.js";import{j as q}from"./tanstack-Bs3zYPPV.js";import{r as ie}from"./react-vendor-C2CvUxFh.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{_ as Qt}from"./index-wYNPRVrc.js";import{j as q}from"./tanstack-Bs3zYPPV.js";import{r as ie}from"./react-vendor-C2CvUxFh.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 Gt=Object.prototype.toString,He=String.prototype.toLowerCase,Re=Object.hasOwnProperty;function f(t){return typeof t=="string"}function T(t){return typeof t=="function"}function Xt(t){return t&&T(t.then)}function he(t){return t&&T(t.next)&&T(t.throw)&&T(t.return)}function Kt(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function u(t){return t=p(t),f(t)?t:O(t)?"":_(t)?t.map(e=>u(e)).join(""):String(t)}function se(t){return t=p(t),_(t)?t:f(t)&&t.length>0?[t]:tn(t)?Array.from(t):me(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 Se(t){return+p(t)||0}function ge(t){return typeof t=="number"}function wt(t){return t&&T(t.toLiquid)?wt(t.toLiquid()):t}function O(t){return t==null}function en(t){return t===void 0}function _(t){return Gt.call(t)==="[object Array]"}function bt(t){return t&&ge(t.length)}function tn(t){return me(t)&&Symbol.iterator in t}function We(t,e){t=t||{};for(const n in t)if(Re.call(t,n)&&e(t[n],n,t)===!1)break;return t}function xt(t){return t[t.length-1]}function me(t){const e=typeof t;return t!==null&&(e==="object"||e==="function")}function Tt(t,e,n=1){const r=[];for(let s=t;s<e;s+=n)r.push(s);return r}function re(t,e,n=" "){return vt(t,e,n,(r,s)=>s+r)}function nn(t,e,n=" "){return vt(t,e,n,(r,s)=>r+s)}function vt(t,e,n,r){t=String(t);let s=e-t.length;for(;s-- >0;)t=r(t,n);return t}function _t(t){return t}function rn(t){return[...t].some(n=>n>="a"&&n<="z")?t.toUpperCase():t.toLowerCase()}function sn(t,e){return t.length>e?t.slice(0,e-3)+"...":t}function Ye(t,e){return t==null&&e==null?0:t==null?1:e==null||(t=He.call(t),e=He.call(e),t<e)?-1:t>e?1:0}function ye(t){return function(...e){return t.call(this,...e.map(p))}}function D(t){return function(...e){return t.call(this,...e.map(Se))}}function Ee(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function*oe(t){const e=new Set;for(const n of t){const r=JSON.stringify(n);e.has(r)||(e.add(r),yield n)}}const Je="__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,Je,{value:"LiquidError",enumerable:!1})}update(){Object.defineProperty(this,"context",{value:fn(this.token),enumerable:!1}),this.message=dn(this.message,this.token),this.stack=this.message+`
3
3
  `+this.context+`
4
4
  `+this.stack,this.originalError&&(this.stack+=`
@@ -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 O,u as z,a as A,P as D,D as P,c as q}from"./core.esm-B_kcYf6n.js";import{u as $,C as V,b as _,c as Y,S as G,v as U,a as W}from"./sortable.esm-BHilUL-2.js";import{I as m,y as k,W as H,L as i,R as J,Y as K,B as E,T as Q,P as X}from"./index-b-u0-VCO.js";import{S as I,a as L,b as B,c as M,d as R}from"./select-BKaV0BO_.js";import{d as w,i as Z}from"./format-C88SDH8g.js";import{C}from"./checkbox-z1kYnX5o.js";import{T as ee}from"./textarea-BnjAxJtk.js";function se({value:t,onChange:a,onBlur:u,readOnly:p,className:l,...s}){const[n,h]=j.useState(!1),x=j.useRef(void 0);j.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]);const g=j.useCallback(v=>{const N=v.target.value,f=w(N,"leading");a(f),N!==f&&N.length>0?(h(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>h(!1),2e3)):h(!1)},[a]),y=j.useCallback(()=>{const v=w(t,"all");v!==t&&a(v),u?.()},[t,a,u]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(m,{value:t,onChange:g,onBlur:y,disabled:p,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:k("font-mono",l),...s}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function ae({type:t,options:a,onChange:u}){const p=H();function l(s,n){u({...a,[s]: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(C,{id:"opt-required",checked:!!a.required,onCheckedChange:s=>l("required",!!s)}),e.jsx(i,{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(i,{className:"text-xs",children:"Placeholder"}),e.jsx(m,{value:a.placeholder??"",onChange:s=>l("placeholder",s.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(m,{type:"number",value:a.maxLength??"",onChange:s=>l("maxLength",s.target.value?Number(s.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(m,{type:"number",value:a.min??"",onChange:s=>l("min",s.target.value?Number(s.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(m,{type:"number",value:a.max??"",onChange:s=>l("max",s.target.value?Number(s.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(m,{type:"number",value:a.step??"",onChange:s=>l("step",s.target.value?Number(s.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(ee,{value:(a.choices??[]).join(`
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as j}from"./react-vendor-C2CvUxFh.js";import{C as O,u as z,a as A,P as D,D as P,c as q}from"./core.esm-B_kcYf6n.js";import{u as V,S as $,v as _,a as G}from"./sortable.esm-QyXA6fio.js";import{I as m,y as k,V as U,L as i,R as W,W as Y,B as E,T as H,P as J}from"./index-wYNPRVrc.js";import{S as I,a as L,b as B,c as M,d as R}from"./select-BV3jemT6.js";import{d as w,i as K}from"./format-C88SDH8g.js";import{C as Q,a as X,b as Z}from"./collapsible-B414SspL.js";import{C}from"./checkbox-fC1QPb_4.js";import{T as ee}from"./textarea-CHQ9tT69.js";function se({value:t,onChange:a,onBlur:u,readOnly:p,className:l,...s}){const[n,h]=j.useState(!1),x=j.useRef(void 0);j.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]);const g=j.useCallback(v=>{const N=v.target.value,f=w(N,"leading");a(f),N!==f&&N.length>0?(h(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>h(!1),2e3)):h(!1)},[a]),y=j.useCallback(()=>{const v=w(t,"all");v!==t&&a(v),u?.()},[t,a,u]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(m,{value:t,onChange:g,onBlur:y,disabled:p,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:k("font-mono",l),...s}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function ae({type:t,options:a,onChange:u}){const p=U();function l(s,n){u({...a,[s]: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(C,{id:"opt-required",checked:!!a.required,onCheckedChange:s=>l("required",!!s)}),e.jsx(i,{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(i,{className:"text-xs",children:"Placeholder"}),e.jsx(m,{value:a.placeholder??"",onChange:s=>l("placeholder",s.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(m,{type:"number",value:a.maxLength??"",onChange:s=>l("maxLength",s.target.value?Number(s.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(m,{type:"number",value:a.min??"",onChange:s=>l("min",s.target.value?Number(s.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(m,{type:"number",value:a.max??"",onChange:s=>l("max",s.target.value?Number(s.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(m,{type:"number",value:a.step??"",onChange:s=>l("step",s.target.value?Number(s.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(ee,{value:(a.choices??[]).join(`
2
2
  `),onChange:s=>l("choices",s.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(i,{className:"text-xs",children:"Allowed Types (e.g., image/*, video/*)"}),e.jsx(m,{value:(a.allowedTypes??[]).join(", "),onChange:s=>l("allowedTypes",s.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(m,{value:a.folder??"",onChange:s=>l("folder",s.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(m,{value:a.accept??"",onChange:s=>l("accept",s.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(m,{type:"number",value:a.maxSize??"",onChange:s=>l("maxSize",s.target.value?Number(s.target.value):void 0),placeholder:"5242880 (5MB)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{id:"opt-media-multiple",checked:!!a.multiple,onCheckedChange:s=>l("multiple",!!s)}),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"}),p&&p.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:p.collections.map(s=>{const n=a.collections??[],h=n.includes(s.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(C,{id:`col-${s.name}`,checked:h,onCheckedChange:x=>{x?l("collections",[...n,s.name]):l("collections",n.filter(g=>g!==s.name))}}),e.jsx(i,{htmlFor:`col-${s.name}`,className:"text-xs font-normal",children:s.label||s.name})]},s.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(m,{value:(a.collections??[]).join(", "),onChange:s=>l("collections",s.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(C,{id:"opt-multiple",checked:!!a.multiple,onCheckedChange:s=>l("multiple",!!s)}),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(T,{fields:a.fields??[],onChange:s=>l("fields",s),excludeTypes:["container","blocks"]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(i,{className:"text-xs",children:"Item Fields"}),e.jsx(T,{fields:a.itemFields??[],onChange:s=>l("itemFields",s),excludeTypes:["array","container"]})]})]})}const S=[{value:"text",label:"Text"},{value:"textarea",label:"Textarea"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"select",label:"Select"},{value:"url",label:"URL"},{value:"email",label:"Email"},{value:"date",label:"Date"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"},{value:"container",label:"Container"}];function le({id:t,field:a,onChange:u,onRemove:p,excludeTypes:l,readOnlyName:s,defaultExpanded:n}){const[h,x]=j.useState(n??!1),[g,y]=j.useState(!!a.label),{attributes:v,listeners:N,setNodeRef:f,transform:F,transition:r}=$({id:t}),o=l?S.filter(c=>!l.includes(c.value)):S,d={transform:O.Transform.toString(F),transition:r};function b(c){u({...a,...c})}return e.jsx("div",{ref:f,style:d,className:"rounded-md border bg-card",children:e.jsxs(V,{open:h,onOpenChange:x,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,...N,children:e.jsx(J,{className:"h-4 w-4"})}),e.jsx(_,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(K,{className:k("h-4 w-4 transition-transform",h&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:a.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:a.label}),e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:p,className:"text-destructive",children:e.jsx(Q,{className:"h-3 w-3"})})]}),e.jsx(Y,{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(se,{value:a.name,onChange:c=>b({name:c}),onBlur:()=>{a.name&&!g&&b({label:Z(a.name)})},readOnly:s,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(m,{value:a.label,onChange:c=>{b({label:c.target.value}),y(!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(I,{value:a.type,onValueChange:c=>b({type:c,options:{}}),children:[e.jsx(L,{className:"h-8 text-sm",children:e.jsx(B,{})}),e.jsx(M,{children:o.map(c=>e.jsx(R,{value:c.value,children:c.label},c.value))})]})]})]}),e.jsx(ae,{type:a.type,options:a.options??{},onChange:c=>b({options:c})})]})})]})})}function T({fields:t,onChange:a,excludeTypes:u,existingFieldNames:p}){const l=z(A(D)),s=t.map((r,o)=>`field-${o}`),[n,h]=j.useState("text"),[x,g]=j.useState(null),y=u?S.filter(r=>!u.includes(r.value)):S;function v(){g(t.length),a([...t,{name:"",label:"",type:n,options:{}}])}function N(r,o){const d=[...t];d[r]=o,a(d)}function f(r){a(t.filter((o,d)=>d!==r))}function F(r){const{active:o,over:d}=r;if(d&&o.id!==d.id){const b=s.indexOf(String(o.id)),c=s.indexOf(String(d.id));a(W(t,b,c))}}return e.jsx(P,{sensors:l,collisionDetection:q,onDragEnd:F,children:e.jsx(G,{items:s,strategy:U,children:e.jsxs("div",{className:"space-y-2",children:[t.map((r,o)=>e.jsx(le,{id:`field-${o}`,field:r,onChange:d=>N(o,d),onRemove:()=>f(o),excludeTypes:u,readOnlyName:!!(p?.has(r.name)&&r.name),defaultExpanded:o===x},`field-${o}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(I,{value:n,onValueChange:h,children:[e.jsx(L,{className:"h-8 w-[130px] text-sm",children:e.jsx(B,{})}),e.jsx(M,{children:y.map(r=>e.jsx(R,{value:r.value,children:r.label},r.value))})]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:v,children:[e.jsx(X,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}export{T as F,se as I};
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(m,{value:(a.allowedTypes??[]).join(", "),onChange:s=>l("allowedTypes",s.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(m,{value:a.folder??"",onChange:s=>l("folder",s.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(m,{value:a.accept??"",onChange:s=>l("accept",s.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(m,{type:"number",value:a.maxSize??"",onChange:s=>l("maxSize",s.target.value?Number(s.target.value):void 0),placeholder:"5242880 (5MB)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{id:"opt-media-multiple",checked:!!a.multiple,onCheckedChange:s=>l("multiple",!!s)}),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"}),p&&p.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:p.collections.map(s=>{const n=a.collections??[],h=n.includes(s.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(C,{id:`col-${s.name}`,checked:h,onCheckedChange:x=>{x?l("collections",[...n,s.name]):l("collections",n.filter(g=>g!==s.name))}}),e.jsx(i,{htmlFor:`col-${s.name}`,className:"text-xs font-normal",children:s.label||s.name})]},s.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(m,{value:(a.collections??[]).join(", "),onChange:s=>l("collections",s.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(C,{id:"opt-multiple",checked:!!a.multiple,onCheckedChange:s=>l("multiple",!!s)}),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(T,{fields:a.fields??[],onChange:s=>l("fields",s),excludeTypes:["container","blocks"]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(i,{className:"text-xs",children:"Item Fields"}),e.jsx(T,{fields:a.itemFields??[],onChange:s=>l("itemFields",s),excludeTypes:["array","container"]})]})]})}const S=[{value:"text",label:"Text"},{value:"textarea",label:"Textarea"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"select",label:"Select"},{value:"url",label:"URL"},{value:"email",label:"Email"},{value:"date",label:"Date"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"},{value:"container",label:"Container"}];function le({id:t,field:a,onChange:u,onRemove:p,excludeTypes:l,readOnlyName:s,defaultExpanded:n}){const[h,x]=j.useState(n??!1),[g,y]=j.useState(!!a.label),{attributes:v,listeners:N,setNodeRef:f,transform:F,transition:r}=V({id:t}),o=l?S.filter(c=>!l.includes(c.value)):S,d={transform:O.Transform.toString(F),transition:r};function b(c){u({...a,...c})}return e.jsx("div",{ref:f,style:d,className:"rounded-md border bg-card",children:e.jsxs(Q,{open:h,onOpenChange:x,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,...N,children:e.jsx(W,{className:"h-4 w-4"})}),e.jsx(X,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(Y,{className:k("h-4 w-4 transition-transform",h&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:a.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:a.label}),e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:p,className:"text-destructive",children:e.jsx(H,{className:"h-3 w-3"})})]}),e.jsx(Z,{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(se,{value:a.name,onChange:c=>b({name:c}),onBlur:()=>{a.name&&!g&&b({label:K(a.name)})},readOnly:s,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(m,{value:a.label,onChange:c=>{b({label:c.target.value}),y(!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(I,{value:a.type,onValueChange:c=>b({type:c,options:{}}),children:[e.jsx(L,{className:"h-8 text-sm",children:e.jsx(B,{})}),e.jsx(M,{children:o.map(c=>e.jsx(R,{value:c.value,children:c.label},c.value))})]})]})]}),e.jsx(ae,{type:a.type,options:a.options??{},onChange:c=>b({options:c})})]})})]})})}function T({fields:t,onChange:a,excludeTypes:u,existingFieldNames:p}){const l=z(A(D)),s=t.map((r,o)=>`field-${o}`),[n,h]=j.useState("text"),[x,g]=j.useState(null),y=u?S.filter(r=>!u.includes(r.value)):S;function v(){g(t.length),a([...t,{name:"",label:"",type:n,options:{}}])}function N(r,o){const d=[...t];d[r]=o,a(d)}function f(r){a(t.filter((o,d)=>d!==r))}function F(r){const{active:o,over:d}=r;if(d&&o.id!==d.id){const b=s.indexOf(String(o.id)),c=s.indexOf(String(d.id));a(G(t,b,c))}}return e.jsx(P,{sensors:l,collisionDetection:q,onDragEnd:F,children:e.jsx($,{items:s,strategy:_,children:e.jsxs("div",{className:"space-y-2",children:[t.map((r,o)=>e.jsx(le,{id:`field-${o}`,field:r,onChange:d=>N(o,d),onRemove:()=>f(o),excludeTypes:u,readOnlyName:!!(p?.has(r.name)&&r.name),defaultExpanded:o===x},`field-${o}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(I,{value:n,onValueChange:h,children:[e.jsx(L,{className:"h-8 w-[130px] text-sm",children:e.jsx(B,{})}),e.jsx(M,{children:y.map(r=>e.jsx(R,{value:r.value,children:r.label},r.value))})]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:v,children:[e.jsx(J,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}export{T as F,se as I};
@@ -0,0 +1 @@
1
+ import{u as N,j as e}from"./tanstack-Bs3zYPPV.js";import{u as v,r as h}from"./react-vendor-C2CvUxFh.js";import{e as w,j as x,X as y,a2 as S,a3 as F,B as p,a_ as j,a5 as R,a6 as I,aa as P}from"./index-wYNPRVrc.js";import{P as T,a as L,b as D}from"./popover-BJDj8C6y.js";import{C as B,a as M,b as $,c as k,d as q,e as E}from"./command-BeacdV75.js";import{u as Q}from"./useContentSearch-B-_p0_QX.js";import{u as z}from"./useDebouncedValue-C-cQUcLG.js";function H({relationships:s,activeFilters:a,onFilterAdd:o,onFilterRemove:i}){const{host:u}=v(),[l,c]=h.useState(null),[d,r]=h.useState(""),n=z(d,300);if(s.length===0)return null;const f=new Set(a.map(t=>t.relName)),m=s.filter(t=>!f.has(t.name));function g(t){c(t),r("")}function C(t){l&&(o({type:"relationship",relName:l.name,relLabel:l.label,contentId:t.contentId,contentTitle:t.title}),c(null),r(""))}function b(){c(null),r("")}return e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-testid":"filter-bar",children:[a.map(t=>e.jsxs(x,{variant:"secondary",className:"gap-1 pl-2",children:[t.relLabel,": ",t.contentTitle,e.jsx("button",{onClick:()=>i(t.relName),className:"ml-0.5 hover:text-foreground","aria-label":`Remove ${t.relLabel} filter`,children:e.jsx(y,{className:"h-3 w-3"})})]},t.relName)),m.length>0&&(l?e.jsx(A,{host:u,rel:l,query:d,debouncedQuery:n,onQueryChange:r,onSelect:C,onClose:b}):e.jsxs(S,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm","data-testid":"add-filter-button",children:[e.jsx(j,{className:"mr-1.5 h-3.5 w-3.5"}),"Add filter"]})}),e.jsx(R,{align:"start",children:m.map(t=>e.jsx(I,{onSelect:()=>g(t),children:t.label},t.name))})]}))]})}function A({host:s,rel:a,query:o,debouncedQuery:i,onQueryChange:u,onSelect:l,onClose:c}){const{data:d,isLoading:r}=Q(s,i,[a.targetCollection],"published");return e.jsxs(T,{open:!0,onOpenChange:n=>{n||c()},children:[e.jsx(L,{asChild:!0,children:e.jsxs(p,{variant:"outline",size:"sm",children:[e.jsx(j,{className:"mr-1.5 h-3.5 w-3.5"}),a.label,"..."]})}),e.jsx(D,{className:"w-80 p-0",align:"start",children:e.jsxs(B,{shouldFilter:!1,children:[e.jsx(M,{placeholder:`Search ${a.label.toLowerCase()}...`,value:o,onValueChange:u,autoFocus:!0}),e.jsx($,{children:r?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(k,{children:"No published content found."}),e.jsx(q,{heading:i.length===0?"Recent":void 0,children:d?.items.map(n=>e.jsxs(E,{value:n.contentId,onSelect:()=>l({contentId:n.contentId,collection:n.collection,slug:n.slug??"",title:n.title}),children:[e.jsx(P,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:n.title}),e.jsx(x,{variant:"outline",className:"text-xs",children:n.collection})]},n.contentId))})]})})]})})]})}function J(s,a){const o=w();return N({queryKey:["sites",s,"content-detail",a,"filter-title"],queryFn:async()=>(await o.apiFetch(`/v1/admin/sites/${s}/content/${a}`)).content?.title||"Untitled",enabled:!!s&&!!a,staleTime:6e4})}export{H as F,J as u};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as o,N as Y}from"./react-vendor-C2CvUxFh.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-b-u0-VCO.js";import{C as J,a as X,b as Z,c as $}from"./card-uKxSQehY.js";import"./radix-C1kb_NqW.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as o,N as Y}from"./react-vendor-C2CvUxFh.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-wYNPRVrc.js";import{C as J,a as X,b as Z,c as $}from"./card-10FqkZPA.js";import"./radix-C1kb_NqW.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as C,r as f}from"./react-vendor-C2CvUxFh.js";import{D as A,k as R,l as W,m as q,n as z,I as B,B as p,a as I,ai as E,Z as S,ae as O,v as V,X as H}from"./index-b-u0-VCO.js";import{i as X,j as Z,e as G,n as J,u as K}from"./useMedia-CXQpRNYL.js";import{S as Q,a as Y,b as $,c as ee,d as j}from"./select-BKaV0BO_.js";import{C as se}from"./card-uKxSQehY.js";import{m as b}from"./media-url-DIg_vSyf.js";function ae({open:x,onSelect:r,onClose:n,allowedTypes:t}){const{host:i}=C(),[o,c]=f.useState(""),[d,g]=f.useState("__all__"),m=f.useRef(null),l=X(i),a=Z(i),{data:U}=G(i),N=U?.items??[],k=d==="__all__"?void 0:d==="__unfiled__"?"":d,{data:M,fetchNextPage:D,hasNextPage:P,isFetchingNextPage:v}=J(i,{folderId:k}),[w,y]=f.useState(!1),_=(M?.pages.flatMap(s=>s.items)??[]).filter(s=>t&&!t.some(h=>h.endsWith("/*")?s.mimeType.startsWith(h.slice(0,-1)):s.mimeType===h)?!1:o?s.filename.toLowerCase().includes(o.toLowerCase())||s.alt?.toLowerCase().includes(o.toLowerCase()):!0);async function T(s){y(!0);try{const{uploadUrl:u,mediaId:h}=await l.mutateAsync({filename:s.name,contentType:s.type,size:s.size});await fetch(u,{method:"PUT",body:s,headers:{"Content-Type":s.type}});const F=await a.mutateAsync({mediaId:h,filename:s.name});r(F),n()}catch(u){V.error("Upload failed",{description:u instanceof Error?u.message:void 0})}finally{y(!1)}}function L(s){return s.startsWith("image/")}return e.jsx(A,{open:x,onOpenChange:()=>n(),children:e.jsxs(R,{className:"max-w-3xl",children:[e.jsxs(W,{children:[e.jsx(q,{children:"Select Media"}),e.jsx(z,{className:"sr-only",children:"Browse and select media files"})]}),e.jsxs("div",{className:"mb-4 flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{placeholder:"Search by filename...",value:o,onChange:s=>c(s.target.value),className:"max-w-xs"}),N.length>0&&e.jsxs(Q,{value:d,onValueChange:g,children:[e.jsx(Y,{className:"w-[150px]",children:e.jsx($,{})}),e.jsxs(ee,{children:[e.jsx(j,{value:"__all__",children:"All folders"}),N.map(s=>e.jsx(j,{value:s.folderId,children:s.name},s.folderId)),e.jsx(j,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:m,type:"file",className:"hidden",accept:t?.join(",")??void 0,onChange:s=>s.target.files?.[0]&&T(s.target.files[0])}),e.jsxs(p,{variant:"outline",onClick:()=>m.current?.click(),disabled:w,children:[w?e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(E,{className:"mr-2 h-4 w-4"}),"Upload New"]})]})]}),e.jsx("div",{className:"grid max-h-96 grid-cols-4 gap-3 overflow-y-auto",children:_.map(s=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{r(s),n()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:L(s.mimeType)?e.jsx("img",{src:b(s.urls?.thumb_md??s.url),alt:s.alt??s.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[s.mimeType.startsWith("image/")?e.jsx(S,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(O,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:s.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:s.filename})})]},s.mediaId))}),_.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),P&&e.jsxs(p,{variant:"ghost",className:"mt-2 w-full",onClick:()=>D(),disabled:v,children:[v?e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function me({field:x,value:r,onChange:n,disabled:t}){const{host:i}=C(),[o,c]=f.useState(!1),g=x.options?.allowedTypes,m=typeof r=="string"?r:r?.mediaId??"",{data:l}=K(i,m);return e.jsxs("div",{children:[m?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!t&&c(!0),children:[l?.url&&e.jsx("img",{src:b(l.urls?.thumb_sm??l.url),alt:l?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:l?.filename??"Loading..."}),!t&&e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:a=>{a.stopPropagation(),n("")},children:e.jsx(H,{className:"h-3 w-3"})})]}):e.jsxs(p,{type:"button",variant:"outline",onClick:()=>c(!0),disabled:t,children:[e.jsx(S,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!t&&e.jsx(ae,{open:o,onClose:()=>c(!1),onSelect:a=>{n({mediaId:a.mediaId,url:a.url,width:a.width??0,height:a.height??0,filename:a.filename}),c(!1)},allowedTypes:g})]})}export{me as M,ae as a};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as C,r as f}from"./react-vendor-C2CvUxFh.js";import{D as A,k as R,l as W,m as q,n as z,I as B,B as p,a as I,ai as E,Y as S,ae as O,v as V,X as H}from"./index-wYNPRVrc.js";import{i as X,j as Y,e as G,n as J,u as K}from"./useMedia-m6zKB__r.js";import{S as Q,a as Z,b as $,c as ee,d as j}from"./select-BV3jemT6.js";import{C as se}from"./card-10FqkZPA.js";import{m as b}from"./media-url-DIg_vSyf.js";function ae({open:x,onSelect:r,onClose:n,allowedTypes:t}){const{host:i}=C(),[o,c]=f.useState(""),[d,g]=f.useState("__all__"),m=f.useRef(null),l=X(i),a=Y(i),{data:U}=G(i),N=U?.items??[],k=d==="__all__"?void 0:d==="__unfiled__"?"":d,{data:M,fetchNextPage:D,hasNextPage:P,isFetchingNextPage:v}=J(i,{folderId:k}),[w,y]=f.useState(!1),_=(M?.pages.flatMap(s=>s.items)??[]).filter(s=>t&&!t.some(h=>h.endsWith("/*")?s.mimeType.startsWith(h.slice(0,-1)):s.mimeType===h)?!1:o?s.filename.toLowerCase().includes(o.toLowerCase())||s.alt?.toLowerCase().includes(o.toLowerCase()):!0);async function T(s){y(!0);try{const{uploadUrl:u,mediaId:h}=await l.mutateAsync({filename:s.name,contentType:s.type,size:s.size});await fetch(u,{method:"PUT",body:s,headers:{"Content-Type":s.type}});const F=await a.mutateAsync({mediaId:h,filename:s.name});r(F),n()}catch(u){V.error("Upload failed",{description:u instanceof Error?u.message:void 0})}finally{y(!1)}}function L(s){return s.startsWith("image/")}return e.jsx(A,{open:x,onOpenChange:()=>n(),children:e.jsxs(R,{className:"max-w-3xl",children:[e.jsxs(W,{children:[e.jsx(q,{children:"Select Media"}),e.jsx(z,{className:"sr-only",children:"Browse and select media files"})]}),e.jsxs("div",{className:"mb-4 flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{placeholder:"Search by filename...",value:o,onChange:s=>c(s.target.value),className:"max-w-xs"}),N.length>0&&e.jsxs(Q,{value:d,onValueChange:g,children:[e.jsx(Z,{className:"w-[150px]",children:e.jsx($,{})}),e.jsxs(ee,{children:[e.jsx(j,{value:"__all__",children:"All folders"}),N.map(s=>e.jsx(j,{value:s.folderId,children:s.name},s.folderId)),e.jsx(j,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:m,type:"file",className:"hidden",accept:t?.join(",")??void 0,onChange:s=>s.target.files?.[0]&&T(s.target.files[0])}),e.jsxs(p,{variant:"outline",onClick:()=>m.current?.click(),disabled:w,children:[w?e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(E,{className:"mr-2 h-4 w-4"}),"Upload New"]})]})]}),e.jsx("div",{className:"grid max-h-96 grid-cols-4 gap-3 overflow-y-auto",children:_.map(s=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{r(s),n()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:L(s.mimeType)?e.jsx("img",{src:b(s.urls?.thumb_md??s.url),alt:s.alt??s.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[s.mimeType.startsWith("image/")?e.jsx(S,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(O,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:s.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:s.filename})})]},s.mediaId))}),_.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),P&&e.jsxs(p,{variant:"ghost",className:"mt-2 w-full",onClick:()=>D(),disabled:v,children:[v?e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function me({field:x,value:r,onChange:n,disabled:t}){const{host:i}=C(),[o,c]=f.useState(!1),g=x.options?.allowedTypes,m=typeof r=="string"?r:r?.mediaId??"",{data:l}=K(i,m);return e.jsxs("div",{children:[m?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!t&&c(!0),children:[l?.url&&e.jsx("img",{src:b(l.urls?.thumb_sm??l.url),alt:l?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:l?.filename??"Loading..."}),!t&&e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:a=>{a.stopPropagation(),n("")},children:e.jsx(H,{className:"h-3 w-3"})})]}):e.jsxs(p,{type:"button",variant:"outline",onClick:()=>c(!0),disabled:t,children:[e.jsx(S,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!t&&e.jsx(ae,{open:o,onClose:()=>c(!1),onSelect:a=>{n({mediaId:a.mediaId,url:a.url,width:a.width??0,height:a.height??0,filename:a.filename}),c(!1)},allowedTypes:g})]})}export{me as M,ae as a};