headroom-cms 0.1.4 → 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.
- package/admin/assets/AdminsPage-BqfhR4Zc.js +1 -0
- package/admin/assets/AllContentPage-C11eeRMt.js +1 -0
- package/admin/assets/ApiKeysPage-DJjOSLoR.js +1 -0
- package/admin/assets/AuditPage-DJNk7IaW.js +1 -0
- package/admin/assets/{BlockEditor-uSyk_TPt.js → BlockEditor-DDsml97y.js} +54 -54
- package/admin/assets/BlockTypeEditPage-Cg7BifaZ.js +1 -0
- package/admin/assets/BlockTypesPage-BDFj8TSL.js +1 -0
- package/admin/assets/BulkActionBar-CastJGEP.js +1 -0
- package/admin/assets/CollectionEditPage-DGW4iMfo.js +1 -0
- package/admin/assets/CollectionsPage-C8XNxRda.js +1 -0
- package/admin/assets/ContentCreatePage-CX4aOzTR.js +1 -0
- package/admin/assets/ContentEditPage-Dj3RK2BF.js +2 -0
- package/admin/assets/ContentListPage-CoDanHrR.js +1 -0
- package/admin/assets/{CustomBlockPreview-ers8OdZ0.js → CustomBlockPreview-DfDOcbmR.js} +1 -1
- package/admin/assets/FieldBuilder-8VVLG_j0.js +3 -0
- package/admin/assets/FilterBar-JCp03kkK.js +1 -0
- package/admin/assets/{LoginPage-uxiw8K1J.js → LoginPage-gPNC9XRN.js} +1 -1
- package/admin/assets/MediaField-Du7_gRse.js +1 -0
- package/admin/assets/MediaPage-D9763lEk.js +1 -0
- package/admin/assets/RelationshipPicker-D7dFI43Q.js +1 -0
- package/admin/assets/SiteSettingsPage-Tfiex2yn.js +1 -0
- package/admin/assets/SiteUsersPage-CSV8syR3.js +1 -0
- package/admin/assets/SitesPage-BFIZ3Y5K.js +1 -0
- package/admin/assets/SubmissionDetailPage-8vtUQsLd.js +1 -0
- package/admin/assets/SubmissionEditPage-PgowJuvq.js +1 -0
- package/admin/assets/SubmissionListPage-HFDQxPhn.js +1 -0
- package/admin/assets/TagInput-CDkKZboX.js +1 -0
- package/admin/assets/TagsPage-BW15-W4H.js +1 -0
- package/admin/assets/UsersPage-C-zlDeTy.js +1 -0
- package/admin/assets/WebhookEditPage-cPPALIbH.js +1 -0
- package/admin/assets/WebhooksPage-vkPC4m9a.js +1 -0
- package/admin/assets/{card-C7fgQS_U.js → card-10FqkZPA.js} +1 -1
- package/admin/assets/checkbox-fC1QPb_4.js +1 -0
- package/admin/assets/collapsible-B414SspL.js +1 -0
- package/admin/assets/command-BeacdV75.js +1 -0
- package/admin/assets/{core.esm-DRuhixPo.js → core.esm-B_kcYf6n.js} +2 -2
- package/admin/assets/index-Do_SK4Zl.css +1 -0
- package/admin/assets/index-wYNPRVrc.js +18 -0
- package/admin/assets/media-url-DIg_vSyf.js +1 -0
- package/admin/assets/popover-BJDj8C6y.js +1 -0
- package/admin/assets/{radix-lA_IxTIV.js → radix-C1kb_NqW.js} +2 -2
- package/admin/assets/react-vendor-C2CvUxFh.js +4 -0
- package/admin/assets/select-BV3jemT6.js +1 -0
- package/admin/assets/serializeToText-BJy0Ms5I.js +2 -0
- package/admin/assets/sortable.esm-QyXA6fio.js +1 -0
- package/admin/assets/{table-BjSue8Ev.js → table-WkEcC9MH.js} +1 -1
- package/admin/assets/{tanstack-oFmRhGwV.js → tanstack-Bs3zYPPV.js} +1 -1
- package/admin/assets/textarea-CHQ9tT69.js +1 -0
- package/admin/assets/useAdminResolver-CpZj93vH.js +1 -0
- package/admin/assets/useContent-D8yDRTTy.js +1 -0
- package/admin/assets/useContentSearch-B-_p0_QX.js +1 -0
- package/admin/assets/{useDebouncedValue-DHUCnm9B.js → useDebouncedValue-C-cQUcLG.js} +1 -1
- package/admin/assets/useFilterParams-DYdEuWPE.js +1 -0
- package/admin/assets/useMedia-m6zKB__r.js +1 -0
- package/admin/assets/usePageTitle-Bwf-MpTD.js +1 -0
- package/admin/assets/useSiteUsers-QbiItSH1.js +1 -0
- package/admin/assets/{useTags-BuXf7_7H.js → useTags-CLPWVUB3.js} +1 -1
- package/admin/assets/{useWebhooks-Cx9tbBME.js → useWebhooks-no0l3-mF.js} +1 -1
- package/admin/favicon-16x16.png +0 -0
- package/admin/favicon-32x32.png +0 -0
- package/admin/index.html +8 -7
- package/admin/sw.js +1 -1
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +8 -0
- package/dist/api.js.map +1 -1
- package/dist/cdn.js +1 -1
- package/dist/cdn.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/scheduler.d.ts +25 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +64 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +16 -0
- package/dist/storage.js.map +1 -1
- package/lambda/api/bootstrap +0 -0
- package/lambda/image-lambda/index.mjs +1 -1
- package/lambda/webhook-worker/bootstrap +0 -0
- package/package.json +1 -1
- package/src/api.ts +9 -0
- package/src/cdn.ts +1 -1
- package/src/index.ts +17 -2
- package/src/scheduler.ts +83 -0
- package/src/sst-env.d.ts +4 -0
- package/src/storage.ts +17 -0
- package/admin/assets/AdminsPage-Cvqw6UOu.js +0 -1
- package/admin/assets/AllContentPage-Cnkt8Fgm.js +0 -1
- package/admin/assets/ApiKeysPage-FLex3Chc.js +0 -1
- package/admin/assets/AuditPage-ClgwR_8y.js +0 -1
- package/admin/assets/BlockTypeEditPage-Dr_yNLDI.js +0 -1
- package/admin/assets/BlockTypesPage-CwsGPuAZ.js +0 -1
- package/admin/assets/BulkActionBar-C-88Wnqw.js +0 -1
- package/admin/assets/CollectionEditPage-Cimkb84B.js +0 -1
- package/admin/assets/CollectionsPage-CxnSFPCH.js +0 -1
- package/admin/assets/ContentCreatePage-DZCyOcte.js +0 -1
- package/admin/assets/ContentEditPage-RtHbU_l4.js +0 -3
- package/admin/assets/ContentListPage-qFcZVzg9.js +0 -1
- package/admin/assets/FieldBuilder-Ds-agLm7.js +0 -3
- package/admin/assets/MediaPage-CeepVDHQ.js +0 -1
- package/admin/assets/SiteSettingsPage-xkngL15i.js +0 -1
- package/admin/assets/SitesPage-BD9tou9-.js +0 -1
- package/admin/assets/TagsPage-BxSwTLpQ.js +0 -1
- package/admin/assets/UsersPage-BayuQyLh.js +0 -1
- package/admin/assets/WebhookEditPage-BrXm8Dht.js +0 -1
- package/admin/assets/WebhooksPage-BUE6XuIP.js +0 -1
- package/admin/assets/badge-B8OxObuF.js +0 -1
- package/admin/assets/check-CxKAR64t.js +0 -1
- package/admin/assets/checkbox-BV2kjQBe.js +0 -1
- package/admin/assets/command-qGFnWxcS.js +0 -1
- package/admin/assets/copy-CgYzmj06.js +0 -1
- package/admin/assets/index-DX9xeoQx.js +0 -18
- package/admin/assets/index-PpbsYFRh.css +0 -1
- package/admin/assets/plus-HdRn2U0S.js +0 -1
- package/admin/assets/popover-Cou924mw.js +0 -1
- package/admin/assets/react-vendor-B0Dih9Pj.js +0 -4
- package/admin/assets/search-C-3Q9nn7.js +0 -1
- package/admin/assets/select-CHW5R8qv.js +0 -1
- package/admin/assets/sortable.esm-CBJBhe4k.js +0 -1
- package/admin/assets/trash-2-CWWRVuRB.js +0 -1
- package/admin/assets/use-mobile-C1r2eP64.js +0 -1
- package/admin/assets/useAdminResolver-D6B6RXnk.js +0 -1
- package/admin/assets/useContent-f19XHVlJ.js +0 -1
- package/admin/assets/useMedia-DkvP1QLG.js +0 -1
- package/admin/vite.svg +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};
|
|
@@ -0,0 +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-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};
|
|
@@ -0,0 +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-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};
|
|
@@ -0,0 +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-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};
|
|
@@ -0,0 +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-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-
|
|
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+=`
|
|
@@ -0,0 +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 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
|
+
`),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}=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-
|
|
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};
|
|
@@ -0,0 +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,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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as g,R as T,L as Dt,u as kt}from"./react-vendor-C2CvUxFh.js";import{u as St}from"./useFilterParams-DYdEuWPE.js";import{a as Tt,b as It,c as Mt,d as Rt,e as ct,f as _t,g as At,h as Et,i as Ft,j as zt,k as $t,l as Pt,m as Ot}from"./useMedia-m6zKB__r.js";import{y as P,aa as dt,ab as Ut,ac as Lt,ad as Ht,ae as Xt,R as Yt,B as D,af as Oe,v as I,D as oe,k as ce,l as de,m as he,n as ue,L,I as K,o as me,a as J,ag as Bt,j as Ue,T as Kt,X as ge,P as Wt,ah as ee,a2 as Vt,a3 as qt,a7 as Qt,a5 as Gt,a6 as nt,ai as pe,aj as Zt,ak as Jt,Z as es,al as ts,am as ss,W as as,x as ns,F as rs,G as is,K as ls,z as rt,an as os,ao as cs,ap as ds,S as hs,aq as us}from"./index-wYNPRVrc.js";import{C as ms,c as xs}from"./card-10FqkZPA.js";import{C as Ie}from"./checkbox-fC1QPb_4.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-BV3jemT6.js";import{s as ps,t as gs,u as fs,v as ws,w as js,A as vs}from"./radix-C1kb_NqW.js";import{b as ht,d as ys,u as bs,a as Cs,D as Ns,e as Ds,P as ks}from"./core.esm-B_kcYf6n.js";import{b as ye,a as Le,f as He}from"./format-C88SDH8g.js";import{m as W}from"./media-url-DIg_vSyf.js";import{T as Ss,a as Ts,b as ut,c as X,d as Is,e as Y}from"./table-WkEcC9MH.js";import{T as Pe,A as Xe,h as Ms,a as Ye,b as Be,c as Ke,d as We,e as Ve,f as qe,g as Qe}from"./TagInput-CDkKZboX.js";import{u as Rs}from"./usePageTitle-Bwf-MpTD.js";function Ne({delayDuration:a=0,...t}){return e.jsx(ps,{"data-slot":"tooltip-provider",delayDuration:a,...t})}function De({...a}){return e.jsx(gs,{"data-slot":"tooltip",...a})}function ke({...a}){return e.jsx(fs,{"data-slot":"tooltip-trigger",...a})}function Se({className:a,sideOffset:t=0,children:s,...l}){return e.jsx(ws,{children:e.jsxs(js,{"data-slot":"tooltip-content",sideOffset:t,className:P("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...l,children:[s,e.jsx(vs,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function Me({mimeType:a,className:t}){return a==="application/pdf"?e.jsx(dt,{className:P("text-blue-500",t)}):a.startsWith("video/")?e.jsx(Ut,{className:P("text-purple-500",t)}):a.startsWith("audio/")?e.jsx(Lt,{className:P("text-green-500",t)}):a==="image/svg+xml"?e.jsx(Ht,{className:P("text-orange-500",t)}):e.jsx(Xt,{className:P("text-muted-foreground",t)})}function _s(a){return a==="application/pdf"?"PDF":a==="image/svg+xml"?"SVG":a.startsWith("image/")?"Image":a.startsWith("video/")?"Video":a.startsWith("audio/")?"Audio":a.split("/")[1]?.toUpperCase()??"File"}function As({item:a,selected:t,onToggle:s,onSelect:l,onLightbox:n,folderName:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";return e.jsxs(ut,{ref:o,className:P("cursor-pointer",r&&"opacity-50"),onClick:l,children:[e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsx(Y,{className:"w-6 p-1 hidden md:table-cell",children:e.jsx("div",{className:"cursor-grab text-muted-foreground",...d,...h,children:e.jsx(Yt,{className:"h-4 w-4"})})}),e.jsx(Y,{className:"p-1",children:x?e.jsx("img",{src:W(a.urls?.thumb_sm??a.url),alt:a.alt||a.filename,className:P("h-8 w-8 rounded object-cover",n&&"cursor-zoom-in"),onClick:n?p=>{p.stopPropagation(),n()}:void 0}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-5 w-5"})})}),e.jsxs(Y,{className:"max-w-[200px]",children:[i&&e.jsx("span",{className:"text-muted-foreground block truncate text-xs",children:i}),e.jsx("span",{className:"block truncate text-sm font-medium",children:a.filename})]}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:_s(a.mimeType)})}),e.jsx(Y,{className:"text-right",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)})}),e.jsx(Y,{className:"hidden lg:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:a.width&&a.height?`${a.width}×${a.height}`:"—"})}),e.jsx(Y,{className:"hidden lg:table-cell",children:a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(p=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]",children:p},p)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})}),e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")},children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})})]})}function Es({items:a,host:t,onSelect:s,selectedIds:l,onToggle:n,onToggleAll:i,allSelected:d,onLightbox:h,folderMap:o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ss,{children:[e.jsx(Ts,{children:e.jsxs(ut,{children:[e.jsx(X,{className:"w-10",children:e.jsx(Ie,{checked:d,onCheckedChange:i,"aria-label":"Select all"})}),e.jsx(X,{className:"w-6 hidden md:table-cell"}),e.jsx(X,{className:"w-12"}),e.jsx(X,{children:"Filename"}),e.jsx(X,{className:"w-20 hidden md:table-cell",children:"Type"}),e.jsx(X,{className:"w-24 text-right",children:"Size"}),e.jsx(X,{className:"w-28 hidden lg:table-cell",children:"Dimensions"}),e.jsx(X,{className:"w-40 hidden lg:table-cell",children:"Tags"}),e.jsx(X,{className:"w-32 hidden md:table-cell",children:"Uploaded"}),e.jsx(X,{className:"w-10"})]})}),e.jsx(Is,{children:a.map(r=>e.jsx(As,{item:r,host:t,selected:l.has(r.mediaId),onToggle:()=>n(r.mediaId),onSelect:()=>s(r),folderName:o?.get(r.folderId??""),onLightbox:h&&r.mimeType.startsWith("image/")&&r.mimeType!=="image/svg+xml"?()=>h(r):void 0},r.mediaId))})]})})}var Fs=Object.defineProperty,zs=(a,t,s)=>t in a?Fs(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>zs(a,typeof t!="symbol"?t+"":t,s);const Te={x:0,y:0,width:0,height:0,unit:"px"},re=(a,t,s)=>Math.min(Math.max(a,t),s),$s=(...a)=>a.filter(t=>t&&typeof t=="string").join(" "),it=(a,t)=>a===t||a.width===t.width&&a.height===t.height&&a.x===t.x&&a.y===t.y&&a.unit===t.unit;function ie(a,t,s){return a.unit==="%"?{...Te,...a,unit:"%"}:{unit:"%",x:a.x?a.x/t*100:0,y:a.y?a.y/s*100:0,width:a.width?a.width/t*100:0,height:a.height?a.height/s*100:0}}function G(a,t,s){return a.unit?a.unit==="px"?{...Te,...a,unit:"px"}:{unit:"px",x:a.x?a.x*t/100:0,y:a.y?a.y*s/100:0,width:a.width?a.width*t/100:0,height:a.height?a.height*s/100:0}:{...Te,...a,unit:"px"}}function lt(a,t,s,l,n,i=0,d=0,h=l,o=n){const r={...a};let x=Math.min(i,l),p=Math.min(d,n),f=Math.min(h,l),c=Math.min(o,n);t&&(t>1?(x=d?d*t:x,p=x/t,f=h*t):(p=i?i/t:p,x=p*t,c=o/t)),r.y<0&&(r.height=Math.max(r.height+r.y,p),r.y=0),r.x<0&&(r.width=Math.max(r.width+r.x,x),r.x=0);const b=l-(r.x+r.width);b<0&&(r.x=Math.min(r.x,l-x),r.width+=b);const m=n-(r.y+r.height);if(m<0&&(r.y=Math.min(r.y,n-p),r.height+=m),r.width<x&&((s==="sw"||s=="nw")&&(r.x-=x-r.width),r.width=x),r.height<p&&((s==="nw"||s=="ne")&&(r.y-=p-r.height),r.height=p),r.width>f&&((s==="sw"||s=="nw")&&(r.x-=f-r.width),r.width=f),r.height>c&&((s==="nw"||s=="ne")&&(r.y-=c-r.height),r.height=c),t){const N=r.width/r.height;if(N<t){const w=Math.max(r.width/t,p);(s==="nw"||s=="ne")&&(r.y-=w-r.height),r.height=w}else if(N>t){const w=Math.max(r.height*t,x);(s==="sw"||s=="nw")&&(r.x-=w-r.width),r.width=w}}return r}function Ps(a,t,s,l){const n={...a};return t==="ArrowLeft"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="w"?(n.x-=s,n.width+=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="e"?n.width-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowRight"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="w"?(n.x+=s,n.width-=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="e"?n.width+=s:l==="se"&&(n.width+=s,n.height+=s)),t==="ArrowUp"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="n"?(n.y-=s,n.height+=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="s"?n.height-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowDown"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="n"?(n.y+=s,n.height-=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="s"?n.height+=s:l==="se"&&(n.width+=s,n.height+=s)),n}const le={capture:!0,passive:!1};let Os=0;const Z=class U extends g.PureComponent{constructor(){super(...arguments),_(this,"docMoveBound",!1),_(this,"mouseDownOnCrop",!1),_(this,"dragStarted",!1),_(this,"evData",{startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0}),_(this,"componentRef",g.createRef()),_(this,"mediaRef",g.createRef()),_(this,"resizeObserver"),_(this,"initChangeCalled",!1),_(this,"instanceId",`rc-${Os++}`),_(this,"state",{cropIsActive:!1,newCropIsBeingDrawn:!1}),_(this,"onCropPointerDown",t=>{const{crop:s,disabled:l}=this.props,n=this.getBox();if(!s)return;const i=G(s,n.width,n.height);if(l)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const d=t.target.dataset.ord,h=!!d;let o=t.clientX,r=t.clientY,x=i.x,p=i.y;if(d){const f=t.clientX-n.x,c=t.clientY-n.y;let b=0,m=0;d==="ne"||d=="e"?(b=f-(i.x+i.width),m=c-i.y,x=i.x,p=i.y+i.height):d==="se"||d==="s"?(b=f-(i.x+i.width),m=c-(i.y+i.height),x=i.x,p=i.y):d==="sw"||d=="w"?(b=f-i.x,m=c-(i.y+i.height),x=i.x+i.width,p=i.y):(d==="nw"||d=="n")&&(b=f-i.x,m=c-i.y,x=i.x+i.width,p=i.y+i.height),o=x+n.x+b,r=p+n.y+m}this.evData={startClientX:o,startClientY:r,startCropX:x,startCropY:p,clientX:t.clientX,clientY:t.clientY,isResize:h,ord:d},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})}),_(this,"onComponentPointerDown",t=>{const{crop:s,disabled:l,locked:n,keepSelection:i,onChange:d}=this.props,h=this.getBox();if(l||n||i&&s)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const o=t.clientX-h.x,r=t.clientY-h.y,x={unit:"px",x:o,y:r,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:o,startCropY:r,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,d(G(x,h.width,h.height),ie(x,h.width,h.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})}),_(this,"onDocPointerMove",t=>{const{crop:s,disabled:l,onChange:n,onDragStart:i}=this.props,d=this.getBox();if(l||!s||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,i&&i(t));const{evData:h}=this;h.clientX=t.clientX,h.clientY=t.clientY;let o;h.isResize?o=this.resizeCrop():o=this.dragCrop(),it(s,o)||n(G(o,d.width,d.height),ie(o,d.width,d.height))}),_(this,"onComponentKeyDown",t=>{const{crop:s,disabled:l,onChange:n,onComplete:i}=this.props;if(l)return;const d=t.key;let h=!1;if(!s)return;const o=this.getBox(),r=this.makePixelCrop(o),x=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep;if(d==="ArrowLeft"?(r.x-=x,h=!0):d==="ArrowRight"?(r.x+=x,h=!0):d==="ArrowUp"?(r.y-=x,h=!0):d==="ArrowDown"&&(r.y+=x,h=!0),h){t.cancelable&&t.preventDefault(),r.x=re(r.x,0,o.width-r.width),r.y=re(r.y,0,o.height-r.height);const p=G(r,o.width,o.height),f=ie(r,o.width,o.height);n(p,f),i&&i(p,f)}}),_(this,"onHandlerKeyDown",(t,s)=>{const{aspect:l=0,crop:n,disabled:i,minWidth:d=0,minHeight:h=0,maxWidth:o,maxHeight:r,onChange:x,onComplete:p}=this.props,f=this.getBox();if(i||!n)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const c=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep,b=G(n,f.width,f.height),m=Ps(b,t.key,c,s),N=lt(m,l,s,f.width,f.height,d,h,o,r);if(!it(n,N)){const w=ie(N,f.width,f.height);x(N,w),p&&p(N,w)}}),_(this,"onDocPointerDone",t=>{const{crop:s,disabled:l,onComplete:n,onDragEnd:i}=this.props,d=this.getBox();this.unbindDocMove(),!(l||!s)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,i&&i(t),n&&n(G(s,d.width,d.height),ie(s,d.width,d.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))}),_(this,"onDragFocus",()=>{var t;(t=this.componentRef.current)==null||t.scrollTo(0,0)})}get document(){return document}getBox(){const t=this.mediaRef.current;if(!t)return{x:0,y:0,width:0,height:0};const{x:s,y:l,width:n,height:i}=t.getBoundingClientRect();return{x:s,y:l,width:n,height:i}}componentDidUpdate(t){const{crop:s,onComplete:l}=this.props;if(l&&!t.crop&&s){const{width:n,height:i}=this.getBox();n&&i&&l(G(s,n,i),ie(s,n,i))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,le),this.document.addEventListener("pointerup",this.onDocPointerDone,le),this.document.addEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,le),this.document.removeEventListener("pointerup",this.onDocPointerDone,le),this.document.removeEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!1)}getCropStyle(){const{crop:t}=this.props;if(t)return{top:`${t.y}${t.unit}`,left:`${t.x}${t.unit}`,width:`${t.width}${t.unit}`,height:`${t.height}${t.unit}`}}dragCrop(){const{evData:t}=this,s=this.getBox(),l=this.makePixelCrop(s),n=t.clientX-t.startClientX,i=t.clientY-t.startClientY;return l.x=re(t.startCropX+n,0,s.width-l.width),l.y=re(t.startCropY+i,0,s.height-l.height),l}getPointRegion(t,s,l,n){const{evData:i}=this,d=i.clientX-t.x,h=i.clientY-t.y;let o;n&&s?o=s==="nw"||s==="n"||s==="ne":o=h<i.startCropY;let r;return l&&s?r=s==="nw"||s==="w"||s==="sw":r=d<i.startCropX,r?o?"nw":"sw":o?"ne":"se"}resolveMinDimensions(t,s,l=0,n=0){const i=Math.min(l,t.width),d=Math.min(n,t.height);return!s||!i&&!d?[i,d]:s>1?i?[i,i/s]:[d*s,d]:d?[d*s,d]:[i,i/s]}resizeCrop(){const{evData:t}=this,{aspect:s=0,maxWidth:l,maxHeight:n}=this.props,i=this.getBox(),[d,h]=this.resolveMinDimensions(i,s,this.props.minWidth,this.props.minHeight);let o=this.makePixelCrop(i);const r=this.getPointRegion(i,t.ord,d,h),x=t.ord||r;let p=t.clientX-t.startClientX,f=t.clientY-t.startClientY;(d&&x==="nw"||x==="w"||x==="sw")&&(p=Math.min(p,-d)),(h&&x==="nw"||x==="n"||x==="ne")&&(f=Math.min(f,-h));const c={unit:"px",x:0,y:0,width:0,height:0};r==="ne"?(c.x=t.startCropX,c.width=p,s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY-c.height)):r==="se"?(c.x=t.startCropX,c.y=t.startCropY,c.width=p,s?c.height=c.width/s:c.height=f):r==="sw"?(c.x=t.startCropX+p,c.y=t.startCropY,c.width=Math.abs(p),s?c.height=c.width/s:c.height=f):r==="nw"&&(c.x=t.startCropX+p,c.width=Math.abs(p),s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY+f));const b=lt(c,s,r,i.width,i.height,d,h,l,n);return s||U.xyOrds.indexOf(x)>-1?o=b:U.xOrds.indexOf(x)>-1?(o.x=b.x,o.width=b.width):U.yOrds.indexOf(x)>-1&&(o.y=b.y,o.height=b.height),o.x=re(o.x,0,i.width-o.width),o.y=re(o.y,0,i.height-o.height),o}renderCropSelection(){const{ariaLabels:t=U.defaultProps.ariaLabels,disabled:s,locked:l,renderSelectionAddon:n,ruleOfThirds:i,crop:d}=this.props,h=this.getCropStyle();if(d)return T.createElement("div",{style:h,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!s&&!l&&T.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},T.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw",tabIndex:0,"aria-label":t.nwDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"nw"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n",tabIndex:0,"aria-label":t.nDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"n"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne",tabIndex:0,"aria-label":t.neDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"ne"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e",tabIndex:0,"aria-label":t.eDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"e"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se",tabIndex:0,"aria-label":t.seDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"se"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s",tabIndex:0,"aria-label":t.sDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"s"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw",tabIndex:0,"aria-label":t.swDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"sw"),role:"button"}),T.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w",tabIndex:0,"aria-label":t.wDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"w"),role:"button"})),n&&T.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:o=>o.stopPropagation()},n(this.state)),i&&T.createElement(T.Fragment,null,T.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),T.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const s={...Te,...this.props.crop||{}};return G(s,t.width,t.height)}render(){const{aspect:t,children:s,circularCrop:l,className:n,crop:i,disabled:d,locked:h,style:o,ruleOfThirds:r}=this.props,{cropIsActive:x,newCropIsBeingDrawn:p}=this.state,f=i?this.renderCropSelection():null,c=$s("ReactCrop",n,x&&"ReactCrop--active",d&&"ReactCrop--disabled",h&&"ReactCrop--locked",p&&"ReactCrop--new-crop",i&&t&&"ReactCrop--fixed-aspect",i&&l&&"ReactCrop--circular-crop",i&&r&&"ReactCrop--rule-of-thirds",!this.dragStarted&&i&&!i.width&&!i.height&&"ReactCrop--invisible-crop",l&&"ReactCrop--no-animate");return T.createElement("div",{ref:this.componentRef,className:c,style:o},T.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},s),i?T.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},T.createElement("defs",null,T.createElement("mask",{id:`hole-${this.instanceId}`},T.createElement("rect",{width:"100%",height:"100%",fill:"white"}),l?T.createElement("ellipse",{cx:`${i.x+i.width/2}${i.unit}`,cy:`${i.y+i.height/2}${i.unit}`,rx:`${i.width/2}${i.unit}`,ry:`${i.height/2}${i.unit}`,fill:"black"}):T.createElement("rect",{x:`${i.x}${i.unit}`,y:`${i.y}${i.unit}`,width:`${i.width}${i.unit}`,height:`${i.height}${i.unit}`,fill:"black"}))),T.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,f)}};_(Z,"xOrds",["e","w"]),_(Z,"yOrds",["n","s"]),_(Z,"xyOrds",["nw","ne","se","sw"]),_(Z,"nudgeStep",1),_(Z,"nudgeStepMedium",10),_(Z,"nudgeStepLarge",100),_(Z,"defaultProps",{ariaLabels:{cropArea:"Use the arrow keys to move the crop selection area",nwDragHandle:"Use the arrow keys to move the north west drag handle to change the crop selection area",nDragHandle:"Use the up and down arrow keys to move the north drag handle to change the crop selection area",neDragHandle:"Use the arrow keys to move the north east drag handle to change the crop selection area",eDragHandle:"Use the up and down arrow keys to move the east drag handle to change the crop selection area",seDragHandle:"Use the arrow keys to move the south east drag handle to change the crop selection area",sDragHandle:"Use the up and down arrow keys to move the south drag handle to change the crop selection area",swDragHandle:"Use the arrow keys to move the south west drag handle to change the crop selection area",wDragHandle:"Use the up and down arrow keys to move the west drag handle to change the crop selection area"}});let Us=Z;const Ls=[{label:"Free",value:""},{label:"1:1 Square",value:"1"},{label:"4:3",value:"4/3"},{label:"3:2",value:"3/2"},{label:"16:9",value:"16/9"},{label:"2:3",value:"2/3"},{label:"3:4",value:"3/4"}],mt=[{label:"Original",value:"",ext:""},{label:"JPEG",value:"jpeg",ext:".jpg"},{label:"PNG",value:"png",ext:".png"},{label:"WebP",value:"webp",ext:".webp"},{label:"AVIF",value:"avif",ext:".avif"}],Hs={"image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/tiff":".tiff"};function ze(a,t){return a?mt.find(s=>s.value===a)?.ext||`.${a}`:Hs[t]||".jpg"}function Xs(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ys({host:a,media:t,onClose:s,onSaved:l}){const n=g.useRef(null),[i,d]=g.useState(),[h,o]=g.useState(),[r,x]=g.useState(""),[p,f]=g.useState(""),[c,b]=g.useState(""),[m,N]=g.useState(""),[w,S]=g.useState("80"),[R,A]=g.useState(()=>{const y=ze("",t.mimeType),M=t.filename.lastIndexOf(".");return`${M>0?t.filename.substring(0,M):t.filename}-transformed${y}`});function F(y){const M=y==="__original__"?"":y;N(M);const q=ze(M,t.mimeType);A(ae=>Xs(ae,q))}const z=Tt(a,t.mediaId),[j,v]=g.useState(null),$=g.useCallback(()=>{if(!h||!j)return null;const y=(t.width??j.width)/j.width,M=(t.height??j.height)/j.height;return{cropX:Math.round(h.x*y),cropY:Math.round(h.y*M),cropW:Math.round(h.width*y),cropH:Math.round(h.height*M)}},[h,t.width,t.height,j]),B=g.useMemo(()=>$(),[$]);async function se(){const y=B,M=p?parseInt(p):void 0,q=c?parseInt(c):void 0;if(!y&&!M&&!q&&!m){I.error("Please specify a crop, resize, or format change");return}if(!R.trim()){I.error("Filename is required");return}const ae=ze(m,t.mimeType);if(!R.trim().toLowerCase().endsWith(ae)){I.error(`Filename must end with ${ae} to match the output format`);return}try{const ne=await z.mutateAsync({...y??{},...M?{width:M}:{},...q?{height:q}:{},...m?{format:m}:{},...w?{quality:parseInt(w)}:{},filename:R.trim()});I.success("Transform saved as new media"),l?.(ne),s()}catch(ne){I.error("Transform failed",{description:ne instanceof Error?ne.message:void 0})}}function xe(y){x(y==="__free__"?"":y),d(void 0),o(void 0)}function V(y){if(!y)return;const M=y.split("/");return M.length===2?Number(M[0])/Number(M[1]):Number(y)||void 0}const Ge=V(r);return e.jsx(oe,{open:!0,onOpenChange:()=>s(),children:e.jsxs(ce,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(de,{children:[e.jsx(he,{children:"Transform Image"}),e.jsx(ue,{className:"sr-only",children:"Crop, resize, or convert image format"})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_280px] gap-6",children:[e.jsx("div",{className:"min-h-0 overflow-hidden rounded border bg-muted/30 flex items-center justify-center",children:e.jsx(Us,{crop:i,onChange:y=>d(y),onComplete:y=>o(y),aspect:Ge,children:e.jsx("img",{ref:n,src:W(t.url),alt:t.alt||t.filename,className:"max-h-[60vh] max-w-full object-contain",onLoad:y=>{const M=y.currentTarget;v({width:M.naturalWidth,height:M.naturalHeight})}})})}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:["Original: ",t.width,"×",t.height]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Crop aspect ratio"}),e.jsxs(fe,{value:r||"__free__",onValueChange:xe,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Free"})}),e.jsx(ve,{children:Ls.map(y=>e.jsx(te,{value:y.value||"__free__",children:y.label},y.value||"__free__"))})]}),h&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Crop: ",B?.cropW,"×",B?.cropH," at (",B?.cropX,", ",B?.cropY,")"]}),h&&e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{d(void 0),o(void 0)},children:"Clear crop"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Resize (optional)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Width",value:p,onChange:y=>f(y.target.value),min:1,max:2048})}),e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Height",value:c,onChange:y=>b(y.target.value),min:1,max:2048})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Output format"}),e.jsxs(fe,{value:m||"__original__",onValueChange:F,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Original"})}),e.jsx(ve,{children:mt.map(y=>e.jsx(te,{value:y.value||"__original__",children:y.label},y.value||"__original__"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Quality (1-100)"}),e.jsx(K,{type:"number",value:w,onChange:y=>S(y.target.value),min:1,max:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Save as filename"}),e.jsx(K,{value:R,onChange:y=>A(y.target.value)})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs(D,{onClick:se,disabled:z.isPending,children:[z.isPending&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save as New Image"]})]})]})})}const Bs=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Ks({host:a,media:t,onClose:s,onDeleted:l,folders:n,tagSuggestions:i}){const[d,h]=g.useState(t.alt??""),[o,r]=g.useState(t.caption??""),[x,p]=g.useState(t.userTags??[]),[f,c]=g.useState(t.folderId||"__none__"),[b,m]=g.useState(!1),N=Bs.has(t.mimeType),w=It(a,t.mediaId),S=Mt(a,t.mediaId),{data:R,isLoading:A}=Rt(a,t.mediaId),F=t.tags.filter(v=>!t.userTags?.includes(v));async function z(){try{await w.mutateAsync({alt:d,caption:o,userTags:x,folderId:f==="__none__"?"":f}),I.success("Media updated"),s()}catch(v){I.error("Failed to update",{description:v instanceof Error?v.message:void 0})}}async function j(){try{await S.mutateAsync(),I.success("Media deleted"),l?.(t.mediaId),s()}catch(v){I.error("Failed to delete",{description:v instanceof Error?v.message:void 0})}}return e.jsxs(oe,{open:!0,onOpenChange:()=>s(),children:[e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(he,{children:t.filename}),e.jsx(ue,{className:"sr-only",children:"View and edit media details"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:[t.mimeType," · ",ye(t.size),t.width&&t.height&&` · ${t.width}×${t.height}`," · ",He(t.uploadedAt)]}),e.jsxs("div",{className:"flex gap-2",children:[N&&e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Transform"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(W(t.url)),I.success("URL copied to clipboard")},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),"Copy URL"]})]})]}),F.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Auto-detected tags"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:F.map(v=>e.jsx(Ue,{variant:"outline",className:"text-xs",children:v},v))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Tags"}),e.jsx(Pe,{tags:x,onChange:p,placeholder:"Add tags...",suggestions:i})]}),n&&n.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Folder"}),e.jsxs(fe,{value:f,onValueChange:c,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"No folder"})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__none__",children:"No folder"}),n.map(v=>e.jsx(te,{value:v.folderId,children:v.name},v.folderId))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"alt",children:"Alt text"}),e.jsx(K,{id:"alt",value:d,onChange:v=>h(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"caption",children:"Caption"}),e.jsx(K,{id:"caption",value:o,onChange:v=>r(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Used in"}),A?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}),"Checking usage..."]}):R?.references.length?e.jsxs("div",{className:"space-y-1",children:[R.references.map(v=>e.jsxs(Dt,{to:`/sites/${a}/content/${v.collection}/${v.contentId}`,className:"flex items-center gap-2 rounded px-2 py-1 text-sm hover:bg-muted",onClick:s,children:[e.jsx(dt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:v.title||v.contentId}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",v.collection,")"]})]},v.contentId)),R.note&&e.jsx("p",{className:"text-muted-foreground text-xs italic",children:R.note})]}):e.jsx("p",{className:"text-muted-foreground text-sm",children:"Not referenced in any content."})]})]}),e.jsxs(me,{className:"flex justify-between",children:[e.jsxs(Xe,{children:[e.jsx(Ms,{asChild:!0,children:e.jsxs(D,{variant:"destructive",size:"sm",children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete media?"}),e.jsxs(We,{children:["This will permanently delete “",t.filename,"”. This action cannot be undone."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(D,{onClick:z,children:"Save"})]})]})]}),b&&e.jsx(Ys,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ws({tags:a,activeTag:t,onTagChange:s}){return a.length===0?null:e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-1.5",children:[a.map(l=>e.jsx(Ue,{variant:t===l?"default":"secondary",className:"cursor-pointer select-none",onClick:()=>s(t===l?void 0:l),children:l},l)),t&&e.jsxs(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s(void 0),children:[e.jsx(ge,{className:"mr-1 h-3 w-3"}),"Clear"]})]})}function $e({id:a,children:t}){const{setNodeRef:s,isOver:l}=ys({id:a,data:{type:"folder"}});return e.jsx("div",{ref:s,children:t(l)})}function ot({host:a,selectedFolderId:t,onSelect:s}){const{data:l}=ct(a),n=_t(a),i=At(a),d=Et(a),[h,o]=g.useState(!1),[r,x]=g.useState(""),[p,f]=g.useState(null),[c,b]=g.useState(""),[m,N]=g.useState(null),w=g.useRef(null),S=g.useRef(null),R=l?.items??[];g.useEffect(()=>{h&&w.current?.focus()},[h]),g.useEffect(()=>{p&&S.current?.focus()},[p]);async function A(){const j=r.trim();if(!j){o(!1),x("");return}try{await n.mutateAsync(j),I.success("Folder created")}catch(v){I.error("Failed to create folder",{description:v instanceof Error?v.message:void 0})}o(!1),x("")}async function F(j){const v=c.trim();if(!v){f(null);return}try{await i.mutateAsync({folderId:j,name:v}),I.success("Folder renamed")}catch($){I.error("Failed to rename folder",{description:$ instanceof Error?$.message:void 0})}f(null)}async function z(){if(m){try{await d.mutateAsync(m.folderId),I.success("Folder deleted"),t===m.folderId&&s(null)}catch(j){I.error("Failed to delete folder",{description:j instanceof Error?j.message:void 0})}N(null)}}return e.jsxs("div",{className:"flex w-48 shrink-0 flex-col border-r",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Folders"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>o(!0),children:e.jsx(Wt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[e.jsx($e,{id:"all-media",children:j=>e.jsx("button",{className:P("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t===null&&"bg-accent font-medium",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s(null),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"All Media"]})})}),R.map(j=>e.jsx($e,{id:j.folderId,children:v=>e.jsx("div",{className:P("group flex w-full items-center justify-between px-3 py-1.5 text-sm hover:bg-accent/50",t===j.folderId&&"bg-accent font-medium",v&&"ring-2 ring-primary bg-primary/10"),children:p===j.folderId?e.jsx(K,{ref:S,value:c,onChange:$=>b($.target.value),onKeyDown:$=>{$.key==="Enter"&&F(j.folderId),$.key==="Escape"&&f(null)},onBlur:()=>F(j.folderId),className:"h-6 text-sm"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"flex flex-1 items-center gap-2 text-left",onClick:()=>s(j.folderId),children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:j.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:j.count}),e.jsxs(Vt,{children:[e.jsx(qt,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100",children:e.jsx(Qt,{className:"h-3.5 w-3.5"})})}),e.jsxs(Gt,{align:"end",children:[e.jsx(nt,{onClick:()=>{f(j.folderId),b(j.name)},children:"Rename"}),e.jsx(nt,{disabled:j.count>0,onClick:()=>N(j),children:"Delete"})]})]})]})]})})},j.folderId)),e.jsx($e,{id:"unfiled",children:j=>e.jsx("button",{className:P("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t==="unfiled"&&"bg-accent font-medium",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s("unfiled"),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Unfiled"]})})}),h&&e.jsx("div",{className:"px-3 py-1.5",children:e.jsx(K,{ref:w,value:r,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&A(),j.key==="Escape"&&(o(!1),x(""))},onBlur:A,placeholder:"Folder name...",className:"h-7 text-sm"})})]}),e.jsx(Xe,{open:!!m,onOpenChange:()=>N(null),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete folder?"}),e.jsxs(We,{children:["This will delete the folder “",m?.name,"”. Media items in this folder will become unfiled."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:z,children:"Delete"})]})]})})]})}function Vs({selectedCount:a,folders:t,onDelete:s,onMove:l,onAddTags:n,onRemoveTags:i,onClear:d,isPending:h}){const[o,r]=g.useState(null),[x,p]=g.useState(""),[f,c]=g.useState([]);function b(){r(null),p(""),c([])}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 min-w-0",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:[a," selected"]}),e.jsx(D,{size:"sm",variant:"ghost",onClick:d,disabled:h,children:e.jsx(ge,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto rounded-md border bg-muted/50 px-3 py-2 max-w-[calc(100vw-1.5rem)]",children:[e.jsx(D,{size:"sm",variant:"destructive",onClick:()=>r("delete"),disabled:h,className:"shrink-0",children:"Delete"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("move"),disabled:h,className:"shrink-0",children:"Move to…"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("addTags"),disabled:h,className:"shrink-0",children:"Add tags"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("removeTags"),disabled:h,className:"shrink-0",children:"Remove tags"})]})]}),e.jsx(oe,{open:o==="delete",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Delete ",a," item",a!==1?"s":"","?"]}),e.jsx(ue,{children:"This action cannot be undone. The selected media items will be permanently deleted."})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{variant:"destructive",onClick:async()=>{b(),await s()},disabled:h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})}),e.jsx(oe,{open:o==="move",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Move ",a," item",a!==1?"s":""]}),e.jsx(ue,{children:"Choose a destination folder."})]}),e.jsxs(fe,{value:x,onValueChange:p,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Select folder..."})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__unfiled__",children:"Unfiled"}),t.map(m=>e.jsx(te,{value:m.folderId,children:m.name},m.folderId))]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=x==="__unfiled__"?"":x;b(),await l(m)},disabled:!x||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Move"]})]})]})}),e.jsx(oe,{open:o==="addTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Add tags to ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to add to the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Add tags..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await n(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Add"]})]})]})}),e.jsx(oe,{open:o==="removeTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Remove tags from ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to remove from the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Tags to remove..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await i(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Remove"]})]})]})})]})}function qs({onFiles:a,children:t}){const[s,l]=g.useState(!1),n=g.useRef(0),i=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.types.includes("Files")&&(n.current++,l(!0))},[]),d=g.useCallback(r=>{r.preventDefault(),n.current--,n.current===0&&l(!1)},[]),h=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.dropEffect="copy"},[]),o=g.useCallback(r=>{r.preventDefault(),n.current=0,l(!1);const x=Array.from(r.dataTransfer.files);x.length>0&&a(x)},[a]);return e.jsxs("div",{className:"relative flex-1",onDragEnter:i,onDragLeave:d,onDragOver:h,onDrop:o,children:[t,s&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/5",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg bg-background/90 px-6 py-4 shadow-lg",children:[e.jsx(pe,{className:"h-8 w-8 text-primary"}),e.jsx("p",{className:"text-lg font-medium",children:"Drop files to upload"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Files will be uploaded to the current folder"})]})})]})}function Qs({queue:a}){const{items:t,retry:s,dismiss:l,clearCompleted:n}=a,[i,d]=g.useState(!1),h=t.filter(c=>c.status==="uploading").length,o=t.filter(c=>c.status==="pending").length,r=t.filter(c=>c.status==="complete").length,x=t.filter(c=>c.status==="error").length,p=h===0&&o===0;if(g.useEffect(()=>{if(p&&t.length>0){const c=setTimeout(()=>d(!0),2e3);return()=>clearTimeout(c)}},[p,t.length]),t.length===0)return null;const f=p?`${r} uploaded${x?`, ${x} failed`:""}`:`Uploading ${h+o} file${h+o!==1?"s":""}`;return e.jsxs("div",{className:"fixed bottom-4 right-4 z-50 w-80 rounded-lg border bg-background shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:f}),e.jsxs("div",{className:"flex items-center gap-1",children:[p&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:n,children:"Clear"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(!i),children:i?e.jsx(Zt,{className:"h-4 w-4"}):e.jsx(Jt,{className:"h-4 w-4"})})]})]}),!i&&e.jsx("div",{className:"max-h-60 overflow-y-auto",children:t.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-sm",children:[c.status==="uploading"&&e.jsx(J,{className:"h-4 w-4 shrink-0 animate-spin"}),c.status==="complete"&&e.jsx(es,{className:"h-4 w-4 shrink-0 text-green-500"}),c.status==="error"&&e.jsx(ge,{className:"h-4 w-4 shrink-0 text-destructive"}),c.status==="pending"&&e.jsx("div",{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate",children:c.file.name}),c.status==="uploading"&&e.jsx("div",{className:"bg-muted mt-0.5 h-1 w-full rounded-full",children:e.jsx("div",{className:"bg-primary h-full rounded-full transition-all",style:{width:`${c.progress}%`}})}),c.status==="error"&&e.jsx("p",{className:"text-destructive truncate text-xs",children:c.error})]}),c.status==="error"&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>s(c.id),children:e.jsx(ts,{className:"h-3 w-3"})}),(c.status==="complete"||c.status==="error")&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>l(c.id),children:e.jsx(ge,{className:"h-3 w-3"})})]},c.id))})]})}const Gs=3;let Zs=0;function Js(a,t){const[s,l]=g.useState([]),n=Ft(a),i=zt(a),d=g.useRef(0),h=g.useRef(s);h.current=s;const o=g.useRef(new Map),r=g.useCallback(async m=>{d.current++,l(N=>N.map(w=>w.id===m.id?{...w,status:"uploading",progress:0}:w));try{const{uploadUrl:N,mediaId:w}=await n.mutateAsync({filename:m.file.name,contentType:m.file.type,size:m.file.size});await new Promise((S,R)=>{const A=new XMLHttpRequest;o.current.set(m.id,A),A.upload.onprogress=F=>{if(F.lengthComputable){const z=Math.round(F.loaded/F.total*100);l(j=>j.map(v=>v.id===m.id?{...v,progress:z}:v))}},A.onload=()=>{o.current.delete(m.id),A.status>=200&&A.status<300?S():R(new Error(`Upload failed: ${A.status}`))},A.onerror=()=>{o.current.delete(m.id),R(new Error("Network error"))},A.onabort=()=>{o.current.delete(m.id),R(new Error("Upload aborted"))},A.open("PUT",N),A.setRequestHeader("Content-Type",m.file.type),A.send(m.file)}),await i.mutateAsync({mediaId:w,filename:m.file.name,folderId:m.folderId}),l(S=>S.map(R=>R.id===m.id?{...R,status:"complete",progress:100}:R))}catch(N){l(w=>w.map(S=>S.id===m.id?{...S,status:"error",error:N instanceof Error?N.message:"Upload failed"}:S))}finally{d.current--}},[n,i]),x=g.useRef(r);x.current=r,g.useEffect(()=>{const m=s.filter(w=>w.status==="pending"),N=Gs-d.current;for(let w=0;w<Math.min(m.length,N);w++)x.current(m[w])},[s]),g.useEffect(()=>{const m=o.current;return()=>{m.forEach(N=>N.abort())}},[]);const p=g.useCallback(m=>{const N=Array.from(m).map(w=>({id:`upload-${Zs++}`,file:w,folderId:t||void 0,status:"pending",progress:0}));l(w=>[...w,...N])},[t]),f=g.useCallback(m=>{l(N=>N.map(w=>w.id===m?{...w,status:"pending",progress:0,error:void 0}:w))},[]),c=g.useCallback(m=>{l(N=>N.filter(w=>w.id!==m))},[]),b=g.useCallback(()=>{l(m=>m.filter(N=>N.status!=="complete"&&N.status!=="error"))},[]);return{items:s,addFiles:p,retry:f,dismiss:c,clearCompleted:b}}function ea({items:a,currentIndex:t,onClose:s,onNavigate:l}){const n=a[t],i=t>0,d=t<a.length-1,h=g.useRef(null),o=g.useCallback(r=>{r.key==="Escape"?s():r.key==="ArrowLeft"&&i?l(t-1):r.key==="ArrowRight"&&d&&l(t+1)},[s,l,t,i,d]);return g.useEffect(()=>(document.addEventListener("keydown",o),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",o),document.body.style.overflow=""}),[o]),n?e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-black/90",onClick:s,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 pt-[max(0.75rem,env(safe-area-inset-top,0px))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))] text-white",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"min-w-0 flex-1 text-sm",children:[e.jsx("span",{className:"font-medium truncate block",children:n.filename}),e.jsxs("span",{className:"opacity-70 text-xs",children:[n.width&&n.height&&`${n.width}×${n.height} · `,ye(n.size)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"text-sm opacity-70",children:[t+1," / ",a.length]}),e.jsx(D,{variant:"ghost",size:"icon",className:"text-white hover:bg-white/20",onClick:s,children:e.jsx(ge,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center px-4 md:px-16",onClick:r=>r.stopPropagation(),onTouchStart:r=>{h.current=r.touches[0].clientX},onTouchEnd:r=>{if(h.current===null)return;const x=r.changedTouches[0].clientX-h.current;h.current=null,x>50&&i?l(t-1):x<-50&&d&&l(t+1)},children:[e.jsx("img",{src:W(n.url),alt:n.alt||n.filename,className:"max-h-full max-w-full object-contain"}),i&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute left-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t-1),children:e.jsx(ss,{className:"h-8 w-8"})}),d&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t+1),children:e.jsx(as,{className:"h-8 w-8"})})]})]}):null}function ta({open:a,duplicates:t,fileCount:s,onContinue:l,onCancel:n}){return e.jsx(Xe,{open:a,onOpenChange:i=>!i&&n(),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Possible duplicates found"}),e.jsx(We,{children:s===1?"A file with the same name and size already exists:":`${t.length} of ${s} files may already exist:`})]}),e.jsx("div",{className:"max-h-48 space-y-2 overflow-y-auto",children:t.map(i=>e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[i.mimeType.startsWith("image/")&&i.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(i.urls?.thumb_sm??i.url),alt:i.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(Me,{mimeType:i.mimeType,className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:i.filename}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[ye(i.size)," ·"," ",Le(i.uploadedAt)]})]})]},i.mediaId))}),e.jsxs(Ve,{children:[e.jsx(qe,{onClick:n,children:"Cancel"}),e.jsx(Qe,{onClick:l,children:"Upload Anyway"})]})]})})}const sa=({activatorEvent:a,draggingNodeRect:t,transform:s})=>{if(a&&t){const l=a;if(l.clientX!==void 0)return{...s,x:s.x+l.clientX-t.left-t.width/2,y:s.y+l.clientY-t.top-t.height/2}}return s},aa=[{value:"date_desc",label:"Newest first"},{value:"date_asc",label:"Oldest first"},{value:"name_asc",label:"Name A-Z"},{value:"name_desc",label:"Name Z-A"},{value:"size_desc",label:"Size (largest)"},{value:"size_asc",label:"Size (smallest)"}];function na({item:a,selected:t,onToggle:s,onClick:l,folderName:n,onLightbox:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";function p(f){f.stopPropagation(),navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")}return e.jsx(ms,{ref:o,...d,...h,className:P("group relative cursor-pointer overflow-hidden",r&&"opacity-50",t&&"ring-2 ring-primary"),onClick:l,children:e.jsxs(xs,{className:"p-0",children:[e.jsx("div",{className:P("absolute left-2 top-2 z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100 [@media(hover:none)]:rounded [@media(hover:none)]:bg-black/30 [@media(hover:none)]:p-0.5",t&&"opacity-100"),onPointerDown:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsxs("div",{className:"absolute right-2 top-2 z-10 flex gap-1 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onPointerDown:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:[e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:p,children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"Copy URL"})]})}),x&&i&&e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:f=>{f.stopPropagation(),i()},children:e.jsx(us,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"View full size"})]})})]}),x?e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx("img",{src:W(a.urls?.thumb_md??a.url),alt:a.alt||a.filename,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-12 w-12"})}),e.jsxs("div",{className:"p-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:a.filename}),n&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(ee,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate text-xs",children:n})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)}),e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})]}),a.tags.length>0&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(f=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]",children:f},f)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})]})]})})}function va(){const{host:a}=kt(),t=ns(),[s,l]=St([{key:"tag",defaultValue:""},{key:"folder",defaultValue:""},{key:"q",defaultValue:""},{key:"sort",defaultValue:"date_desc"},{key:"view",defaultValue:"grid"}]),n=s.view,i=u=>l({view:u}),d=s.sort,h=u=>l({sort:u}),o=s.tag||void 0,r=s.folder===""?null:s.folder,x=u=>l({folder:u??""}),[p,f]=g.useState(s.q),[c,b]=g.useState(s.q),[m,N]=g.useState(null),[w,S]=g.useState(new Set),[R,A]=g.useState(null),[F,z]=g.useState(null),[j,v]=g.useState(null),[$,B]=g.useState([]),[se,xe]=g.useState(!1),V=g.useRef(null);Rs({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Js(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=bs(Cs(ks,{activationConstraint:{distance:t?1e5:8}}));g.useEffect(()=>{const u=setTimeout(()=>{b(C=>{const k=p;return C!==k&&(S(new Set),l({q:k})),k})},300);return()=>clearTimeout(u)},[p,l]);const ne=r===null?void 0:r==="unfiled"?"":r,{data:O,isLoading:xt}=Ot(a,{sort:d,q:c||void 0,folderId:ne,tag:o}),{data:Ze}=ct(a),be=g.useMemo(()=>Ze?.items??[],[Ze?.items]),Re=g.useMemo(()=>{const u=new Map;for(const C of be)u.set(C.folderId,C.name);return u},[be]),Ce=g.useMemo(()=>(O?.items??[]).filter(u=>u.mimeType.startsWith("image/")&&u.mimeType!=="image/svg+xml"),[O?.items]),_e=g.useMemo(()=>{const u=new Map;return Ce.forEach((C,k)=>u.set(C.mediaId,k)),u},[Ce]),{allTags:pt,allUserTags:gt}=g.useMemo(()=>{const u=O?.items??[],C=new Set,k=new Set;for(const E of u){for(const H of E.tags)C.add(H);for(const H of E.userTags??[])k.add(H)}return{allTags:Array.from(C).sort(),allUserTags:Array.from(k).sort()}},[O?.items]),Ae=O?.items.map(u=>u.mediaId)??[],Ee=Ae.length>0&&Ae.every(u=>w.has(u));function Je(u){S(C=>{const k=new Set(C);return k.has(u)?k.delete(u):k.add(u),k})}function et(){S(Ee?new Set:new Set(Ae))}async function ft(){const u=[...w],k=(await M.mutateAsync({mediaIds:u,action:"delete"})).failed.length;k?I.error(`${k} of ${u.length} failed to delete`):I.success(`${u.length} item(s) deleted`),S(new Set)}async function wt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"move",folderId:u})).failed.length;E?I.error(`${E} of ${C.length} failed to move`):I.success(`${C.length} item(s) moved`),S(new Set)}async function jt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"addTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags added to ${C.length} item(s)`),S(new Set)}async function vt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"removeTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags removed from ${C.length} item(s)`),S(new Set)}async function tt(u){const C=Array.from(u),k=C.slice(0,5),E=[];for(const H of k)try{const Fe=await q.mutateAsync({filename:H.name,size:H.size});E.push(...Fe.duplicates)}catch{}E.length>0?(v(C),B(E)):y.addFiles(C)}function yt(u){u.target.files&&tt(u.target.files),V.current&&(V.current.value="")}function bt(u){A(String(u.active.id))}function Ct(u){A(null);const{active:C,over:k}=u;if(!k||k.data.current?.type!=="folder")return;const E=k.id==="unfiled"||k.id==="all-media"?"":String(k.id),H=w.has(String(C.id))?[...w]:[String(C.id)];M.mutateAsync({mediaIds:H,action:"move",folderId:E}).then(Fe=>{const at=Fe.failed.length;at?I.error(`${at} of ${H.length} failed to move`):I.success(`${H.length} item(s) moved`)})}function Nt(){A(null)}const Q=R?O?.items.find(u=>u.mediaId===R):null,st=R&&w.has(R)?w.size:1;return e.jsxs(Ns,{sensors:ae,modifiers:[sa],onDragStart:bt,onDragEnd:Ct,onDragCancel:Nt,children:[e.jsxs("div",{className:"-m-2 md:-m-6 relative flex min-h-[calc(100dvh-3.5rem)] md:h-[calc(100vh-3.5rem)]",children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set)}})}),e.jsx(rs,{open:se,onOpenChange:xe,children:e.jsxs(is,{side:"left",className:"w-64 p-0 pt-[env(safe-area-inset-top,0px)] pl-[env(safe-area-inset-left,0px)] [&_[data-slot=sheet-close]]:top-[calc(1rem+env(safe-area-inset-top,0px))]","data-testid":"folder-overlay-backdrop",children:[e.jsx(ls,{className:"sr-only",children:"Folders"}),e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set),xe(!1)}})]})}),e.jsxs(qs,{onFiles:u=>tt(u),children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-2 md:p-6",children:[!t&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Media"}),e.jsx("div",{children:e.jsxs(D,{onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})})]}),e.jsx("input",{ref:V,type:"file",multiple:!0,className:"hidden",onChange:yt}),w.size>0?e.jsx(Vs,{selectedCount:w.size,folders:be,onDelete:ft,onMove:wt,onAddTags:jt,onRemoveTags:vt,onClear:()=>S(new Set),isPending:M.isPending}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative min-w-[200px] max-w-sm flex-1",children:[e.jsx(rt,{className:"text-muted-foreground absolute left-2.5 top-2.5 h-4 w-4"}),e.jsx(K,{placeholder:"Search media...",value:p,onChange:u=>f(u.target.value),className:"pl-9"})]}),e.jsxs(fe,{value:d,onValueChange:h,children:[e.jsx(we,{className:"w-[160px]",children:e.jsx(je,{})}),e.jsx(ve,{children:aa.map(u=>e.jsx(te,{value:u.value,children:u.label},u.value))})]}),e.jsx(D,{variant:se?"secondary":"ghost",size:"sm",className:"md:hidden px-2",onClick:()=>xe(!se),"aria-label":"Toggle folders",children:e.jsx(os,{className:"h-4 w-4"})}),!se&&r!==null&&t&&e.jsxs(Ue,{variant:"secondary",className:"gap-1 md:hidden",children:[e.jsx(ee,{className:"h-3 w-3"}),r==="unfiled"?"Unfiled":Re.get(r)??"All Media"]}),e.jsxs("div",{className:"flex rounded-md border",children:[e.jsx(D,{variant:n==="grid"?"secondary":"ghost",size:"sm",className:"rounded-r-none px-2",onClick:()=>i("grid"),children:e.jsx(cs,{className:"h-4 w-4"})}),e.jsx(D,{variant:n==="list"?"secondary":"ghost",size:"sm",className:"rounded-l-none px-2",onClick:()=>i("list"),children:e.jsx(ds,{className:"h-4 w-4"})})]})]}),e.jsx(Ws,{tags:pt,activeTag:o,onTagChange:u=>{l({tag:u??""}),S(new Set)}}),n==="grid"&&(O?.items.length??0)>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Ie,{checked:Ee,onCheckedChange:et,"aria-label":"Select all"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:w.size>0?`${w.size} of ${O.items.length} selected`:"Select all"})]}),xt?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:Array.from({length:8}).map((u,C)=>e.jsx(hs,{className:"aspect-square"},C))}):O?.items.length?n==="list"?e.jsx(Es,{items:O.items,host:a,onSelect:N,selectedIds:w,onToggle:Je,onToggleAll:et,allSelected:Ee,folderMap:r===null?Re:void 0,onLightbox:u=>{const C=_e.get(u.mediaId);C!==void 0&&z(C)}}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:O.items.map(u=>e.jsx(na,{item:u,selected:w.has(u.mediaId),onToggle:()=>Je(u.mediaId),onClick:()=>N(u),folderName:r===null?Re.get(u.folderId??""):void 0,onLightbox:_e.has(u.mediaId)?()=>z(_e.get(u.mediaId)):void 0},u.mediaId))}):e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:c||o?e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No results found"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Try adjusting your search or filters."})]}):r==="unfiled"?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No unfiled media"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"All media items are organized in folders."})]}):r?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"This folder is empty"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload files or drag media into this folder."})]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No media yet"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload your first file to get started."}),e.jsxs(D,{className:"mt-4",onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})]})}),m&&e.jsx(Ks,{host:a,media:m,onClose:()=>N(null),onDeleted:u=>{S(C=>{if(!C.has(u))return C;const k=new Set(C);return k.delete(u),k})},folders:be,tagSuggestions:gt})]}),e.jsx(Qs,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(ea,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(ta,{open:$.length>0,host:a,duplicates:$,fileCount:j?Array.from(j).length:0,onContinue:()=>{j&&y.addFiles(j),v(null),B([])},onCancel:()=>{v(null),B([])}}),e.jsx(Ds,{children:R&&Q&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-background p-2 shadow-lg",children:[Q.mimeType.startsWith("image/")&&Q.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(Q.urls?.thumb_sm??Q.url),alt:Q.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(Me,{mimeType:Q.mimeType,className:"h-6 w-6"})}),e.jsx("span",{className:"text-sm font-medium",children:st>1?`Moving ${st} items`:Q.filename})]})})]})}export{va as MediaPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as b,u as B}from"./react-vendor-C2CvUxFh.js";import{C as L,u as w,a as P,P as R,D as k,c as O}from"./core.esm-B_kcYf6n.js";import{u as M,S as D,v as F,a as E}from"./sortable.esm-QyXA6fio.js";import{R as V,aa as f,j as C,B as h,X as y,P as z}from"./index-wYNPRVrc.js";import{C as A,a as G,b as Q,c as _}from"./card-10FqkZPA.js";import{P as q,a as H,b as X}from"./popover-BJDj8C6y.js";import{C as J,a as K,b as U,c as W,d as Y,e as Z}from"./command-BeacdV75.js";import{u as $}from"./useContentSearch-B-_p0_QX.js";import{u as ee}from"./useDebouncedValue-C-cQUcLG.js";function pe({field:i,value:t,onChange:a}){const{host:o}=B(),s=i.options,c=!!s?.multiple,d=s?.collections;return c?e.jsx(ne,{host:o,collections:d,value:t??[],onChange:a}):e.jsx(te,{host:o,collections:d,value:t,onChange:a})}function te({host:i,collections:t,value:a,onChange:o}){const[s,c]=b.useState(!1),d=a?[a.contentId]:[];function r(x){o(x),c(!1)}return e.jsx("div",{children:a?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:a.title}),e.jsx(C,{variant:"secondary",children:a.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:i,collections:t,selectedIds:d,open:s,onOpenChange:c,onSelect:r,trigger:e.jsxs(h,{type:"button",variant:"outline",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function ne({host:i,collections:t,value:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=a??[],x=r.map(n=>n.contentId),g=r.map(n=>n.contentId);function p(n){o([...r,n]),d(!1)}function I(n){o(r.filter((m,u)=>u!==n))}function l(n){const{active:m,over:u}=n;if(u&&m.id!==u.id){const S=r.findIndex(v=>v.contentId===String(m.id)),j=r.findIndex(v=>v.contentId===String(u.id));S!==-1&&j!==-1&&o(E(r,S,j))}}return e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:l,children:e.jsx(D,{items:x,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[r.map(n=>e.jsx(T,{id:n.contentId,contentRef:n,onRemove:()=>I(r.indexOf(n))},n.contentId)),e.jsx(N,{host:i,collections:t,selectedIds:g,open:c,onOpenChange:d,onSelect:p,trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function T({id:i,contentRef:t,onRemove:a}){const{attributes:o,listeners:s,setNodeRef:c,transform:d,transition:r}=M({id:i}),x={transform:L.Transform.toString(d),transition:r};return e.jsxs("div",{ref:c,style:x,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...o,...s,children:e.jsx(V,{className:"h-4 w-4"})}),e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:a,className:"text-destructive",children:e.jsx(y,{className:"h-3 w-3"})})]})}function N({host:i,collections:t,selectedIds:a,open:o,onOpenChange:s,onSelect:c,trigger:d,status:r}){const[x,g]=b.useState(""),p=ee(x,300),{data:I,isLoading:l}=$(i,p,t,r);return e.jsxs(q,{open:o,onOpenChange:s,children:[e.jsx(H,{asChild:!0,children:d}),e.jsx(X,{className:"w-80 p-0",align:"start",children:e.jsxs(J,{shouldFilter:!1,children:[e.jsx(K,{placeholder:"Search content...",value:x,onValueChange:g}),e.jsx(U,{children:l?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(W,{children:"No content found."}),e.jsx(Y,{heading:p.length===0?"Recent":void 0,children:I?.items.map(n=>{const m=a.includes(n.contentId);return e.jsxs(Z,{value:n.contentId,disabled:m,onSelect:()=>c({contentId:n.contentId,collection:n.collection,slug:n.slug??"",title:n.title}),children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:n.title}),e.jsx(C,{variant:"outline",className:"text-xs",children:n.collection})]},n.contentId)})})]})})]})})]})}function je({relationships:i,values:t,onChange:a,host:o}){return e.jsxs(A,{children:[e.jsx(G,{children:e.jsx(Q,{children:"Relationships"})}),e.jsx(_,{className:"space-y-4",children:i.map(s=>s.multiple?e.jsx(oe,{rel:s,items:t[s.name]??[],host:o,onChange:c=>a({...t,[s.name]:c})},s.name):e.jsx(se,{rel:s,value:t[s.name]?.[0]??null,host:o,onChange:c=>a({...t,[s.name]:c?[c]:[]})},s.name))})]})}function se({rel:i,value:t,host:a,onChange:o}){const[s,c]=b.useState(!1),d=t?[t.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),t?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:d,open:s,onOpenChange:c,onSelect:r=>{o(r),c(!1)},status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select ",i.label]})})]})}function oe({rel:i,items:t,host:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=t.map(l=>l.contentId),x=t.map(l=>l.contentId);function g(l){o([...t,l]),d(!1)}function p(l){o(t.filter((n,m)=>m!==l))}function I(l){const{active:n,over:m}=l;if(m&&n.id!==m.id){const u=t.findIndex(j=>j.contentId===String(n.id)),S=t.findIndex(j=>j.contentId===String(m.id));u!==-1&&S!==-1&&o(E(t,u,S))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:I,children:e.jsx(D,{items:r,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[t.map(l=>e.jsx(T,{id:l.contentId,contentRef:l,onRemove:()=>p(t.indexOf(l))},l.contentId)),e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:x,open:c,onOpenChange:d,onSelect:g,status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add ",i.label]})})]})})})]})}export{pe as C,je as R,N as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,a as V}from"./tanstack-Bs3zYPPV.js";import{r as m,u as X,f as z}from"./react-vendor-C2CvUxFh.js";import{L as r,I as o,B as d,v as l,aG as J,S as D,aX as W,aY as $,aZ as ee,aF as se,x as ae,j as te,a as S,aM as ie,D as P,k,l as L,m as B,n as M,o as O}from"./index-wYNPRVrc.js";import{C as N,a as C,b,d as ne,c as w}from"./card-10FqkZPA.js";import{f as re}from"./format-C88SDH8g.js";import{u as le}from"./usePageTitle-Bwf-MpTD.js";import{u as ce,a as de,b as oe}from"./useSiteUsers-QbiItSH1.js";import{C as q}from"./checkbox-fC1QPb_4.js";import{T as U}from"./textarea-CHQ9tT69.js";import"./radix-C1kb_NqW.js";function me({host:a}){const{data:c,isLoading:n}=ce(a),x=de(a),j=oe(a),[i,h]=m.useState({}),[u,g]=m.useState("");m.useEffect(()=>{c&&h(c)},[c]);async function p(){try{await x.mutateAsync(i),l.success("Auth settings saved")}catch(s){l.error("Failed to save",{description:s instanceof Error?s.message:void 0})}}async function A(){if(u)try{await j.mutateAsync(u),l.success("Test email sent")}catch(s){l.error("Failed to send test email",{description:s instanceof Error?s.message:void 0})}}return n||!c?null:e.jsxs(N,{children:[e.jsxs(C,{children:[e.jsx(b,{children:"Site Authentication"}),e.jsx(ne,{children:"Enable email OTP authentication for site visitors."})]}),e.jsxs(w,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(q,{id:"auth-enabled",checked:i.enabled??!1,onCheckedChange:s=>h({...i,enabled:s})}),e.jsx(r,{htmlFor:"auth-enabled",children:"Enable site auth"})]}),i.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(q,{id:"allow-signup",checked:i.allowSignup??!1,onCheckedChange:s=>h({...i,allowSignup:s})}),e.jsx(r,{htmlFor:"allow-signup",children:"Allow self-registration"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"session-ttl",children:"Session duration (days)"}),e.jsx(o,{id:"session-ttl",type:"number",min:1,value:Math.round((i.sessionTtl??2592e3)/86400),onChange:s=>h({...i,sessionTtl:parseInt(s.target.value)*86400})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-subject",children:"Email subject (Liquid)"}),e.jsx(o,{id:"email-subject",placeholder:"Your login code for {{ site_name }}",value:i.emailSubject??"",onChange:s=>h({...i,emailSubject:s.target.value})}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:["Variables: ","{{ code }}",", ","{{ site_name }}",", ","{{ user_email }}",", ","{{ user_name }}",", ","{{ expires_minutes }}"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-body",children:"Email HTML body (Liquid)"}),e.jsx(U,{id:"email-body",rows:5,placeholder:"<p>Your code: <strong>{{ code }}</strong></p>",value:i.emailBody??"",onChange:s=>h({...i,emailBody:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-text",children:"Email text body (Liquid)"}),e.jsx(U,{id:"email-text",rows:3,placeholder:"Your code: {{ code }}",value:i.emailTextBody??"",onChange:s=>h({...i,emailTextBody:s.target.value})})]}),e.jsx("div",{className:"border-t pt-4",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(r,{htmlFor:"test-email",children:"Send test email"}),e.jsx(o,{id:"test-email",type:"email",placeholder:"admin@example.com",value:u,onChange:s=>g(s.target.value)})]}),e.jsx(d,{variant:"outline",onClick:A,disabled:j.isPending||!u,children:"Send"})]})})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(d,{onClick:p,disabled:x.isPending,children:"Save"})})]})]})}function Ce(){const{host:a}=X(),{data:c,isLoading:n}=J(a);return n?e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{className:"h-8 w-64"}),e.jsx(D,{className:"h-48 w-full"})]}):c?e.jsx(he,{site:c},c.host):e.jsx("p",{className:"text-muted-foreground",children:"Site not found."})}function he({site:a}){const c=V(),n=W(a.host),x=$(a.host),j=ee(a.host),i=z(),u=se()==="admin",g=a.status==="archived",[p,A]=m.useState(a.name),[s,_]=m.useState(a.fromEmail??""),[F,H]=m.useState(a.fromName??""),[I,v]=m.useState(!1),[Y,f]=m.useState(!1),[E,y]=m.useState(""),G=ae();le({title:"Configuration"});async function Q(t){t.preventDefault();try{await n.mutateAsync({name:p,fromEmail:s,fromName:F}),l.success("Site updated")}catch(T){l.error("Failed to update site",{description:T instanceof Error?T.message:void 0})}}async function R(){try{await n.mutateAsync({status:"archived"}),l.success("Site archived"),v(!1),i("/sites")}catch(t){l.error("Failed to archive site",{description:t instanceof Error?t.message:void 0})}}async function Z(){try{await n.mutateAsync({status:"active"}),l.success("Site unarchived")}catch(t){l.error("Failed to unarchive site",{description:t instanceof Error?t.message:void 0})}}async function K(){try{await x.mutateAsync(),await j.mutateAsync(),await c.invalidateQueries({queryKey:["sites"]}),l.success("Site deleted"),f(!1),y(""),i("/sites")}catch(t){l.error("Failed to delete site",{description:t instanceof Error?t.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!G&&e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:"Site Settings"}),e.jsxs(N,{children:[e.jsx(C,{children:e.jsx(b,{children:"General"})}),e.jsx(w,{children:e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"name",children:"Site Name"}),e.jsx(o,{id:"name",value:p,onChange:t=>A(t.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"fromEmail",children:"Sender email (optional)"}),e.jsx(o,{id:"fromEmail",type:"email",placeholder:"Uses global default",value:s,onChange:t=>_(t.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'"From" address for emails sent by this site. Must be verified in SES.'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"fromName",children:"Sender name (optional)"}),e.jsx(o,{id:"fromName",placeholder:"My Site",value:F,onChange:t=>H(t.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display name shown alongside the sender email address."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Host"}),e.jsx(o,{value:a.host,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Status"}),e.jsx("div",{className:"flex items-center gap-2",children:g?e.jsx(te,{variant:"outline",children:"Archived"}):e.jsx(o,{value:a.status,disabled:!0})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Created"}),e.jsx(o,{value:re(a.createdAt),disabled:!0})]}),e.jsxs(d,{type:"submit",disabled:n.isPending,children:[n.isPending&&e.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})]})})]}),u&&e.jsxs(N,{className:"mt-6",children:[e.jsx(C,{children:e.jsx(b,{children:"Site Status"})}),e.jsx(w,{className:"space-y-4",children:g?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"This site is archived. Unarchive it to allow content changes."}),e.jsxs(d,{variant:"outline",onClick:Z,disabled:n.isPending,children:[n.isPending&&e.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Unarchive Site"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Archiving a site makes it read-only. Content cannot be created or modified while archived."}),e.jsxs(d,{variant:"outline",onClick:()=>v(!0),children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Archive Site"]}),e.jsx(P,{open:I,onOpenChange:v,children:e.jsxs(k,{children:[e.jsxs(L,{children:[e.jsx(B,{children:"Archive Site"}),e.jsxs(M,{children:["Are you sure you want to archive ",e.jsx("strong",{children:a.host}),"? The site will become read-only."]})]}),e.jsxs(O,{children:[e.jsx(d,{variant:"outline",onClick:()=>v(!1),children:"Cancel"}),e.jsxs(d,{onClick:R,disabled:n.isPending,children:[n.isPending&&e.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Archive"]})]})]})})]})})]}),u&&e.jsx("div",{className:"mt-6",children:e.jsx(me,{host:a.host})}),u&&g&&e.jsxs(N,{className:"border-destructive mt-6",children:[e.jsx(C,{children:e.jsx(b,{className:"text-destructive",children:"Danger Zone"})}),e.jsxs(w,{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Permanently delete this site and all its content, media, collections, and block types. This action cannot be undone."}),e.jsx(d,{variant:"destructive",onClick:()=>f(!0),children:"Delete Site"}),e.jsx(P,{open:Y,onOpenChange:t=>{f(t),t||y("")},children:e.jsxs(k,{children:[e.jsxs(L,{children:[e.jsx(B,{children:"Delete Site"}),e.jsxs(M,{children:["This will permanently delete this site and all its content. Type ",e.jsx("strong",{children:a.host})," to confirm."]})]}),e.jsx(o,{placeholder:a.host,value:E,onChange:t=>y(t.target.value)}),e.jsxs(O,{children:[e.jsx(d,{variant:"outline",onClick:()=>{f(!1),y("")},children:"Cancel"}),e.jsxs(d,{variant:"destructive",onClick:K,disabled:E!==a.host||x.isPending||j.isPending,children:[(x.isPending||j.isPending)&&e.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete Everything"]})]})]})})]})]})]})}export{Ce as SiteSettingsPage};
|