headroom-cms 0.1.8 → 0.1.10
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-Bt_ekZen.js → AdminsPage-BIWASote.js} +1 -1
- package/admin/assets/AllContentPage-1gXe2OC7.js +1 -0
- package/admin/assets/{ApiKeysPage-BfWCxGhC.js → ApiKeysPage-BBW4ATBx.js} +1 -1
- package/admin/assets/AuditPage-B5GGFWGG.js +1 -0
- package/admin/assets/BlockEditor-CQpF8tYb.css +1 -0
- package/admin/assets/BlockEditor-ClskiZoX.js +176 -0
- package/admin/assets/BlockTypeEditPage-CY0gCPei.js +1 -0
- package/admin/assets/BlockTypesPage-D8Me6OeX.js +1 -0
- package/admin/assets/{BulkActionBar-TRiXXLQd.js → BulkActionBar--35xjnOP.js} +1 -1
- package/admin/assets/CollectionEditPage-y8t0ZO89.js +1 -0
- package/admin/assets/{CollectionsPage-ClplrxNn.js → CollectionsPage-BQmGXpvW.js} +1 -1
- package/admin/assets/{ContentCreatePage-DfYcEH1u.js → ContentCreatePage-DlgxamOe.js} +1 -1
- package/admin/assets/ContentEditPage-WkSbCnnG.js +1 -0
- package/admin/assets/ContentField-D04Uo1Ov.js +1 -0
- package/admin/assets/ContentListPage-BDMx7pWb.js +1 -0
- package/admin/assets/CustomBlockPreview-Cs9bFDh4.js +479 -0
- package/admin/assets/FieldRenderer-wE-mtqZB.js +2 -0
- package/admin/assets/FilterBar-kFcOLffg.js +1 -0
- package/admin/assets/FloatingComposerController-D4uLQfUX-C0Lhbmda.js +1 -0
- package/admin/assets/IconPicker-BrgSAsa_.js +3 -0
- package/admin/assets/{LoginPage-DutieANA.js → LoginPage-Bi7TBzK4.js} +1 -1
- package/admin/assets/MediaField-B-Cz8TlK.js +1 -0
- package/admin/assets/MediaPage-C84p9d1U.js +1 -0
- package/admin/assets/Pagination-CuHwUPHi.js +1 -0
- package/admin/assets/RelationshipPicker-Dv7GaLcU.js +1 -0
- package/admin/assets/{SiteSettingsPage-BtCC3RKc.js → SiteSettingsPage-nBT7NzkA.js} +1 -1
- package/admin/assets/{SiteUserEditPage-ClHmp0T-.js → SiteUserEditPage-DroUTii9.js} +1 -1
- package/admin/assets/SiteUsersPage-iVXPCBPe.js +1 -0
- package/admin/assets/{SitesPage-Bw_WBN6v.js → SitesPage-BefZeWuJ.js} +1 -1
- package/admin/assets/{SubmissionDetailPage-DS08LGxd.js → SubmissionDetailPage-ktmzzOE1.js} +1 -1
- package/admin/assets/SubmissionEditPage-C-ykTI2t.js +1 -0
- package/admin/assets/SubmissionListPage-DA-8deUy.js +1 -0
- package/admin/assets/{TagInput-BILCaC9b.js → TagInput-d-Hw1fkL.js} +1 -1
- package/admin/assets/{TagsPage-DdeZokow.js → TagsPage-BZzDvcKa.js} +1 -1
- package/admin/assets/{UsersPage-B0vLxjrg.js → UsersPage-CnQAOOGF.js} +1 -1
- package/admin/assets/{WebhookEditPage-SlJE4d3z.js → WebhookEditPage-KeS8hmdW.js} +1 -1
- package/admin/assets/{WebhooksPage-C6lGZLpr.js → WebhooksPage-CASjmlPN.js} +1 -1
- package/admin/assets/{card-hXVtlM0q.js → card-CZTHR2Qa.js} +1 -1
- package/admin/assets/checkbox-DEgzM8H9.js +1 -0
- package/admin/assets/{collapsible-B414SspL.js → collapsible-D3d29uJp.js} +1 -1
- package/admin/assets/{command-fvBFHye4.js → command-CdzYw11U.js} +1 -1
- package/admin/assets/contentStatus-CkPi9Dh6.js +1 -0
- package/admin/assets/{core.esm-B_kcYf6n.js → core.esm-DdQHdRkd.js} +2 -2
- package/admin/assets/index-BA3y7HJs.js +18 -0
- package/admin/assets/index-c7UygSvP.css +1 -0
- package/admin/assets/popover-BFw_h3j6.js +1 -0
- package/admin/assets/radix-C5ZmWuuL.js +51 -0
- package/admin/assets/select-dX9e6VDt.js +1 -0
- package/admin/assets/{serializeToText-DR_WnxiI.js → serializeToText-Zin3gYPm.js} +1 -1
- package/admin/assets/{sortable.esm-QyXA6fio.js → sortable.esm-qVEMoaTg.js} +1 -1
- package/admin/assets/{table-DLoIbCQ5.js → table-Dk7eeOt2.js} +1 -1
- package/admin/assets/{textarea-vSXNxwTe.js → textarea-CpDSUg2s.js} +1 -1
- package/admin/assets/useAdminResolver-Bljb4XGQ.js +1 -0
- package/admin/assets/useContent-CW0tm0FY.js +1 -0
- package/admin/assets/useContentSearch-_bwacEth.js +1 -0
- package/admin/assets/{useMedia-e3sqWm_t.js → useMedia-Cu5N4rY8.js} +1 -1
- package/admin/assets/usePageTitle-DYvuJQp6.js +1 -0
- package/admin/assets/useSiteUsers-CKtC_8Jc.js +1 -0
- package/admin/assets/{useTags-f7AVSLuj.js → useTags-ybsMbCst.js} +1 -1
- package/admin/assets/{useWebhooks-BH_r8-Mo.js → useWebhooks-BAB-3sLa.js} +1 -1
- package/admin/assets/yjs-tXBm_srz.js +5 -0
- package/admin/index.html +3 -3
- package/admin/sw.js +1 -1
- package/dist/admin-site.d.ts +12 -0
- package/dist/admin-site.d.ts.map +1 -1
- package/dist/admin-site.js +8 -1
- package/dist/admin-site.js.map +1 -1
- package/dist/api.d.ts +7 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +8 -1
- package/dist/api.js.map +1 -1
- package/dist/collaboration.d.ts +55 -0
- package/dist/collaboration.d.ts.map +1 -0
- package/dist/collaboration.js +141 -0
- package/dist/collaboration.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/storage.d.ts +2 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +33 -0
- package/dist/storage.js.map +1 -1
- package/lambda/api/bootstrap +0 -0
- package/lambda/webhook-worker/bootstrap +0 -0
- package/package.json +1 -1
- package/src/admin-site.ts +20 -1
- package/src/api.ts +15 -1
- package/src/collaboration.ts +187 -0
- package/src/index.ts +44 -4
- package/src/sst-env.d.ts +28 -0
- package/src/storage.ts +35 -0
- package/admin/assets/AllContentPage-CFqEMAl9.js +0 -1
- package/admin/assets/AuditPage-BE0XIUl2.js +0 -1
- package/admin/assets/BlockEditor-6wqsThJ7.js +0 -179
- package/admin/assets/BlockEditor-Cp_wZ2xN.css +0 -1
- package/admin/assets/BlockTypeEditPage-CuNJfZw0.js +0 -1
- package/admin/assets/BlockTypesPage-BIMBVxBs.js +0 -1
- package/admin/assets/CollectionEditPage-BqX_0cC2.js +0 -1
- package/admin/assets/ContentEditPage-D3Rvlktk.js +0 -2
- package/admin/assets/ContentListPage-zmO8Is4d.js +0 -1
- package/admin/assets/CustomBlockPreview-C6HqS4xv.js +0 -479
- package/admin/assets/FieldBuilder-36tfpSyM.js +0 -3
- package/admin/assets/FilterBar-DhRwTqFv.js +0 -1
- package/admin/assets/MediaField-J2TLG_fu.js +0 -1
- package/admin/assets/MediaPage-DZZKMGF4.js +0 -1
- package/admin/assets/RelationshipPicker-CDFs4TMW.js +0 -1
- package/admin/assets/SiteUsersPage-AyJvcVM7.js +0 -1
- package/admin/assets/SubmissionEditPage-Brf-DK2X.js +0 -1
- package/admin/assets/SubmissionListPage-DNMzQZHS.js +0 -1
- package/admin/assets/checkbox-WGrS3sUr.js +0 -1
- package/admin/assets/contentStatus-BmaiYVOm.js +0 -1
- package/admin/assets/index-Cir9tY_P.js +0 -18
- package/admin/assets/index-DACBYsKM.css +0 -1
- package/admin/assets/popover-D5_HjjUC.js +0 -1
- package/admin/assets/radix-C1kb_NqW.js +0 -51
- package/admin/assets/select-_uJYxzeZ.js +0 -1
- package/admin/assets/useAdminResolver-D-LlmquD.js +0 -1
- package/admin/assets/useContent-e8beBIuq.js +0 -1
- package/admin/assets/useContentSearch-DOjveB9t.js +0 -1
- package/admin/assets/useDebouncedValue-C-cQUcLG.js +0 -1
- package/admin/assets/usePageTitle-BNSba9_L.js +0 -1
- package/admin/assets/useSiteUsers-BdnvuM2E.js +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as j}from"./react-vendor-C2CvUxFh.js";import{C as 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-Cir9tY_P.js";import{S as I,a as L,b as B,c as M,d as R}from"./select-_uJYxzeZ.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-WGrS3sUr.js";import{T as ee}from"./textarea-vSXNxwTe.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};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as N,j as e}from"./tanstack-Bs3zYPPV.js";import{u as v,r as h}from"./react-vendor-C2CvUxFh.js";import{e as w,j as x,X as y,a2 as S,a3 as F,B as p,b2 as j,a5 as R,a6 as I,aa as P}from"./index-Cir9tY_P.js";import{P as T,a as L,b as D}from"./popover-D5_HjjUC.js";import{C as B,a as M,b as $,c as k,d as q,e as E}from"./command-fvBFHye4.js";import{u as Q}from"./useContentSearch-DOjveB9t.js";import{u as z}from"./useDebouncedValue-C-cQUcLG.js";function J({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 W(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{J as F,W as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as F,r as f}from"./react-vendor-C2CvUxFh.js";import{D as R,k as $,l as q,m as B,n as E,I,B as g,a as k,ai as O,Y as L,ae as D,v as V,X as H,L as M}from"./index-Cir9tY_P.js";import{h as X,i as Y,d as G,m as J,n as K}from"./useMedia-e3sqWm_t.js";import{S as Q,a as Z,b as ee,c as ae,d as _}from"./select-_uJYxzeZ.js";import{C as se}from"./card-hXVtlM0q.js";import{m as P}from"./media-url-DIg_vSyf.js";function te({open:i,onSelect:l,onClose:r,allowedTypes:n}){const{host:c}=F(),[d,m]=f.useState(""),[u,j]=f.useState("__all__"),t=f.useRef(null),N=X(c),o=Y(c),{data:v}=G(c),h=v?.items??[],y=u==="__all__"?void 0:u==="__unfiled__"?"":u,{data:w,fetchNextPage:s,hasNextPage:C,isFetchingNextPage:b}=J(c,{folderId:y}),[S,T]=f.useState(!1),U=(w?.pages.flatMap(a=>a.items)??[]).filter(a=>n&&!n.some(x=>x.endsWith("/*")?a.mimeType.startsWith(x.slice(0,-1)):a.mimeType===x)?!1:d?a.filename.toLowerCase().includes(d.toLowerCase())||a.alt?.toLowerCase().includes(d.toLowerCase()):!0);async function A(a){T(!0);try{const{uploadUrl:p,mediaId:x}=await N.mutateAsync({filename:a.name,contentType:a.type,size:a.size});await fetch(p,{method:"PUT",body:a,headers:{"Content-Type":a.type}});const z=await o.mutateAsync({mediaId:x,filename:a.name});l(z),r()}catch(p){V.error("Upload failed",{description:p instanceof Error?p.message:void 0})}finally{T(!1)}}function W(a){return a.startsWith("image/")}return e.jsx(R,{open:i,onOpenChange:()=>r(),children:e.jsxs($,{className:"max-w-3xl",children:[e.jsxs(q,{children:[e.jsx(B,{children:"Select Media"}),e.jsx(E,{className:"sr-only",children:"Browse and select media files"})]}),e.jsxs("div",{className:"mb-4 flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{placeholder:"Search by filename...",value:d,onChange:a=>m(a.target.value),className:"max-w-xs"}),h.length>0&&e.jsxs(Q,{value:u,onValueChange:j,children:[e.jsx(Z,{className:"w-[150px]",children:e.jsx(ee,{})}),e.jsxs(ae,{children:[e.jsx(_,{value:"__all__",children:"All folders"}),h.map(a=>e.jsx(_,{value:a.folderId,children:a.name},a.folderId)),e.jsx(_,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:t,type:"file",className:"hidden",accept:n?.join(",")??void 0,onChange:a=>a.target.files?.[0]&&A(a.target.files[0])}),e.jsxs(g,{variant:"outline",onClick:()=>t.current?.click(),disabled:S,children:[S?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(O,{className:"mr-2 h-4 w-4"}),"Upload New"]})]})]}),e.jsx("div",{className:"grid max-h-96 grid-cols-4 gap-3 overflow-y-auto",children:U.map(a=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{l(a),r()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:W(a.mimeType)?e.jsx("img",{src:P(a.urls?.thumb_md??a.url),alt:a.alt??a.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[a.mimeType.startsWith("image/")?e.jsx(L,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(D,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:a.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:a.filename})})]},a.mediaId))}),U.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),C&&e.jsxs(g,{variant:"ghost",className:"mt-2 w-full",onClick:()=>s(),disabled:b,children:[b?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function le(i){if(!i)return null;if(typeof i=="string")return{id:i,url:""};const l=i,r=l.id??l.mediaId??"";return r?{id:r,url:l.url??"",mimeType:l.mimeType,width:l.width,height:l.height,alt:l.alt,caption:l.caption,filename:l.filename}:null}function ie(i){return i?i.startsWith("image/"):!0}function pe({field:i,value:l,onChange:r,disabled:n}){const{host:c}=F(),[d,m]=f.useState(!1),j=i.options?.allowedTypes,t=le(l),N=t?.id??"",{data:o}=K(c,N),v=t?.mimeType??o?.mimeType,h=ie(v),y=s=>{t&&r({...t,alt:s})},w=s=>{t&&r({...t,caption:s})};return e.jsxs("div",{children:[t?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!n&&m(!0),children:[h&&o?.url?e.jsx("img",{src:P(o.urls?.thumb_sm??o.url),alt:t.alt??o?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}):e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded bg-muted","aria-label":"File",children:e.jsx(D,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.filename??o?.filename??"Loading..."}),!n&&e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:s=>{s.stopPropagation(),r("")},children:e.jsx(H,{className:"h-3 w-3"})})]}),!n&&h&&e.jsxs("div",{className:"grid grid-cols-1 gap-3 pl-1 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-alt`,className:"text-xs font-normal text-muted-foreground",children:"Alt text"}),e.jsx(I,{id:`${t.id}-alt`,type:"text","aria-label":"Alt text",value:t.alt??"",onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-caption`,className:"text-xs font-normal text-muted-foreground",children:"Caption"}),e.jsx(I,{id:`${t.id}-caption`,type:"text","aria-label":"Caption",value:t.caption??"",onChange:s=>w(s.target.value)})]})]})]}):e.jsxs(g,{type:"button",variant:"outline",onClick:()=>m(!0),disabled:n,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!n&&e.jsx(te,{open:d,onClose:()=>m(!1),onSelect:s=>{const C={id:s.mediaId,url:s.url,mimeType:s.mimeType,width:s.width,height:s.height,alt:s.alt??"",caption:s.caption??"",filename:s.filename};r(C),m(!1)},allowedTypes:j})]})}export{pe as M,te as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as g,R as T,L as Dt,u as kt}from"./react-vendor-C2CvUxFh.js";import{u as St}from"./useFilterParams-DYdEuWPE.js";import{u as Tt,a as It,b as Mt,c as Rt,d as ct,e as _t,f as At,g as Et,h as Ft,i as zt,j as $t,k as Pt,l as Ot}from"./useMedia-e3sqWm_t.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-Cir9tY_P.js";import{C as ms,c as xs}from"./card-hXVtlM0q.js";import{C as Ie}from"./checkbox-WGrS3sUr.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-_uJYxzeZ.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-DLoIbCQ5.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-BILCaC9b.js";import{u as Rs}from"./usePageTitle-BNSba9_L.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};
|
|
@@ -1 +0,0 @@
|
|
|
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-Cir9tY_P.js";import{C as A,a as G,b as Q,c as _}from"./card-hXVtlM0q.js";import{P as q,a as H,b as X}from"./popover-D5_HjjUC.js";import{C as J,a as K,b as U,c as W,d as Y,e as Z}from"./command-fvBFHye4.js";import{u as $}from"./useContentSearch-DOjveB9t.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};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as q,f as z,r as i}from"./react-vendor-C2CvUxFh.js";import{d as G,e as J,f as K}from"./useSiteUsers-BdnvuM2E.js";import{x as Q,B as a,P as b,I as x,S as V,j as C,D as S,k as D,l as w,m as T,n as U,L as P,o as F,v as d}from"./index-Cir9tY_P.js";import{T as W,a as X,b as k,c as l,d as Y,e as n}from"./table-DLoIbCQ5.js";import{f as Z}from"./format-C88SDH8g.js";import{u as _}from"./usePageTitle-BNSba9_L.js";import"./radix-C1kb_NqW.js";function ce(){const{host:r}=q(),E=z(),[u,I]=i.useState(""),{data:A,isLoading:L,hasNextPage:M,fetchNextPage:B,isFetchingNextPage:j}=G(r,{tag:u||void 0}),p=J(r),g=K(r),[O,c]=i.useState(!1),[o,f]=i.useState(""),[v,N]=i.useState(""),[m,h]=i.useState(null),H=Q();_({title:"Site Users",actions:e.jsx(a,{size:"sm",onClick:()=>c(!0),children:e.jsx(b,{className:"h-4 w-4"})})});async function R(s){s.preventDefault();try{await p.mutateAsync({email:o,name:v||void 0}),c(!1),f(""),N(""),d.success("User created")}catch(t){d.error("Failed to create user",{description:t instanceof Error?t.message:void 0})}}async function $(){if(m)try{await g.mutateAsync(m),h(null),d.success("User deleted")}catch(s){d.error("Failed to delete user",{description:s instanceof Error?s.message:void 0})}}const y=A?.pages.flatMap(s=>s.items)??[];return e.jsxs("div",{children:[!H&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Site Users"}),e.jsxs(a,{onClick:()=>c(!0),children:[e.jsx(b,{className:"mr-2 h-4 w-4"}),"Add User"]})]}),e.jsx("div",{className:"mb-4",children:e.jsx(x,{placeholder:"Filter by tag...",value:u,onChange:s=>I(s.target.value),className:"max-w-xs"})}),L?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx(V,{className:"h-12 w-full"},s))}):y.length===0?e.jsx("p",{className:"text-muted-foreground py-8 text-center",children:"No site users yet"}):e.jsxs(W,{children:[e.jsx(X,{children:e.jsxs(k,{children:[e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Name"}),e.jsx(l,{children:"Status"}),e.jsx(l,{children:"Tags"}),e.jsx(l,{children:"Created"})]})}),e.jsx(Y,{children:y.map(s=>e.jsxs(k,{className:"cursor-pointer",onClick:()=>E(`/sites/${r}/settings/site-users/${s.userId}`),children:[e.jsx(n,{className:"font-medium",children:s.email}),e.jsx(n,{children:s.name||"—"}),e.jsx(n,{children:e.jsx(C,{variant:s.status==="active"?"default":"secondary",children:s.status})}),e.jsx(n,{children:s.tags?.map(t=>e.jsx(C,{variant:"outline",className:"mr-1",children:t},t))}),e.jsx(n,{children:Z(s.createdAt)})]},s.userId))})]}),M&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(a,{variant:"outline",onClick:()=>B(),disabled:j,children:j?"Loading...":"Load more"})}),e.jsx(S,{open:O,onOpenChange:c,children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(T,{children:"Add Site User"}),e.jsx(U,{children:"Create a new user for this site."})]}),e.jsxs("form",{onSubmit:R,children:[e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"email",children:"Email"}),e.jsx(x,{id:"email",type:"email",value:o,onChange:s=>f(s.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"name",children:"Name (optional)"}),e.jsx(x,{id:"name",value:v,onChange:s=>N(s.target.value)})]})]}),e.jsx(F,{children:e.jsx(a,{type:"submit",disabled:p.isPending||!o,children:"Create"})})]})]})}),e.jsx(S,{open:!!m,onOpenChange:()=>h(null),children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(T,{children:"Delete User"}),e.jsx(U,{children:"This will permanently delete this user and all their identities."})]}),e.jsxs(F,{children:[e.jsx(a,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),e.jsx(a,{variant:"destructive",onClick:$,disabled:g.isPending,children:"Delete"})]})]})})]})}export{ce as SiteUsersPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as O,f as z,r as u}from"./react-vendor-C2CvUxFh.js";import{x as U,w as V,e as D,S as E,B as P,b3 as H,L as q,b4 as G,I as x,v as j}from"./index-Cir9tY_P.js";import{j as J,s as K,t as Q}from"./useContent-e8beBIuq.js";import{u as W}from"./usePageTitle-BNSba9_L.js";import{T as X}from"./textarea-vSXNxwTe.js";import{C as Y}from"./checkbox-WGrS3sUr.js";import{S as Z,a as _,b as ee,c as se,d as te}from"./select-_uJYxzeZ.js";import{C as ae,a as ne,b as ie,c as oe}from"./card-hXVtlM0q.js";import{M as re}from"./MediaField-J2TLG_fu.js";import{R as ce}from"./RelationshipPicker-CDFs4TMW.js";import"./radix-C1kb_NqW.js";import"./useMedia-e3sqWm_t.js";import"./media-url-DIg_vSyf.js";import"./core.esm-B_kcYf6n.js";import"./sortable.esm-QyXA6fio.js";import"./popover-D5_HjjUC.js";import"./command-fvBFHye4.js";import"./useContentSearch-DOjveB9t.js";import"./useDebouncedValue-C-cQUcLG.js";function Fe(){const{host:i,collection:c,id:m}=O(),b=z(),R=U(),{collections:A}=V(),o=!!m,d=A.find(t=>t.name===c),v=u.useMemo(()=>d?.relationships??[],[d?.relationships]),h=v.length>0,{data:p,isLoading:T}=J(i,m??""),S=D(),C=K(i),f=Q(i,m??""),[y,$]=u.useState({}),[w,N]=u.useState({}),[k,L]=u.useState(!o);W({title:o?"Edit Submission":"New Submission",showBack:!0,backTo:o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`});const I=u.useCallback(async t=>{const a={};for(const[e,n]of Object.entries(t))a[e]=await Promise.all(n.map(async r=>{if(r.title)return r;try{const g=await S.apiFetch(`/v1/admin/sites/${i}/content/${r.contentId}`);return{contentId:r.contentId,collection:g.content.collection??r.collection??"",slug:g.content.slug??r.slug??"",title:g.content.title??r.contentId}}catch{return r}}));return a},[S,i]);if(u.useEffect(()=>{if(o&&p&&!k){const t=p.body;t&&$({...t});const e=p.content?.relationships;e&&Object.keys(e).length>0&&I(e).then(N),L(!0)}},[o,p,k,I]),o&&T)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(E,{className:"h-8 w-64"}),s.jsx(E,{className:"h-64 w-full"})]});function l(t,a){$(e=>({...e,[t]:a}))}function M(t){const a=y[t.name];switch(t.type){case"text":return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)});case"textarea":return s.jsx(X,{value:a??"",onChange:e=>l(t.name,e.target.value),rows:4});case"number":return s.jsx(x,{type:"number",value:a!=null?String(a):"",onChange:e=>l(t.name,e.target.value===""?void 0:Number(e.target.value))});case"boolean":return s.jsx(Y,{checked:!!a,onCheckedChange:e=>l(t.name,!!e)});case"select":{const e=t.options?.choices??[];return s.jsxs(Z,{value:a??"",onValueChange:n=>l(t.name,n),children:[s.jsx(_,{children:s.jsx(ee,{placeholder:"Select..."})}),s.jsx(se,{children:e.map(n=>s.jsx(te,{value:n,children:n},n))})]})}case"array":return s.jsx(x,{value:Array.isArray(a)?a.join(", "):a??"",onChange:e=>l(t.name,e.target.value?e.target.value.split(",").map(n=>n.trim()):[]),placeholder:"Comma-separated values"});case"media":return s.jsx(re,{field:t,value:a,onChange:()=>{},disabled:!0});default:return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)})}}async function B(){const t={};for(const[e,n]of Object.entries(y))n!==void 0&&n!==""&&(t[e]=n);const a={};if(h)for(const[e,n]of Object.entries(w))a[e]=n.map(r=>({contentId:r.contentId}));try{if(o)await f.mutateAsync({fields:t,...h?{relationships:a}:{}}),j.success("Submission updated"),b(`/sites/${i}/submissions/${c}/${m}`);else{const e=await C.mutateAsync({collection:c,fields:t,...h?{relationships:a}:{}});j.success("Submission created"),b(`/sites/${i}/submissions/${c}/${e.contentId}`)}}catch(e){const n=e instanceof Error?e.message:typeof e=="object"&&e!==null&&"message"in e?String(e.message):String(e);j.error(o?"Failed to update":"Failed to create",{description:n})}}const F=C.isPending||f.isPending;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!R&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>b(o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`),children:[s.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:o?"Edit Submission":"New Submission"})]}),s.jsxs(ae,{children:[s.jsx(ne,{children:s.jsx(ie,{children:d?.label??c})}),s.jsxs(oe,{className:"space-y-4",children:[d?.fields?.map(t=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(q,{htmlFor:`field-${t.name}`,children:t.label||t.name}),s.jsx("div",{id:`field-${t.name}`,children:M(t)})]},t.name)),s.jsx("div",{className:"pt-4",children:s.jsxs(P,{onClick:B,disabled:F,children:[s.jsx(G,{className:"mr-1.5 h-4 w-4"}),F?"Saving...":o?"Update":"Create"]})})]})]}),h&&s.jsx("div",{className:"mt-6",children:s.jsx(ce,{relationships:v,values:w,onChange:N,host:i})})]})}export{Fe as SubmissionEditPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as E,f as H,r as u}from"./react-vendor-C2CvUxFh.js";import{u as Y}from"./useFilterParams-DYdEuWPE.js";import{w as G,x as J,B as y,P as K,T as Q,v as V,S as W,y as X}from"./index-Cir9tY_P.js";import{d as Z,c as ee}from"./useContent-e8beBIuq.js";import{u as se}from"./usePageTitle-BNSba9_L.js";import{u as te,F as le}from"./FilterBar-DhRwTqFv.js";import{C as ae,c as ne}from"./card-hXVtlM0q.js";import{C as I}from"./checkbox-WGrS3sUr.js";import{S as re,a as ie,b as oe,c as ce,d as de}from"./select-_uJYxzeZ.js";import{T as ue,a as me,b as L,c as b,d as he,e as j}from"./table-DLoIbCQ5.js";import{a as R,f as xe}from"./format-C88SDH8g.js";import"./radix-C1kb_NqW.js";import"./popover-D5_HjjUC.js";import"./command-fvBFHye4.js";import"./useContentSearch-DOjveB9t.js";import"./useDebouncedValue-C-cQUcLG.js";const fe=[{value:"created_desc",label:"Newest first"},{value:"created_asc",label:"Oldest first"}];function Me(){const{host:c,collection:r}=E(),g=H(),{collections:_}=G(),[v,N]=Y([{key:"sort",defaultValue:"created_desc"},{key:"relatedTo",defaultValue:""},{key:"relField",defaultValue:""}]),m=v.sort,i=v.relatedTo,l=v.relField,[B,h]=u.useState(),[o,x]=u.useState(new Set),k=J(),d=_.find(e=>e.name===r),f=d?.relationships??[];se({title:d?.label??r??""});const{data:F}=te(c,i||void 0),$=u.useMemo(()=>{if(!i||!l)return null;const e=f.find(t=>t.name===l);return{type:"relationship",relName:l,relLabel:e?.label??l,contentId:i,contentTitle:F??"Loading..."}},[i,l,f,F]),D=u.useMemo(()=>{const e={};return m!=="created_desc"&&(e.sort=m),i&&(e.relatedTo=i),l&&(e.relField=l),e},[m,i,l]),{data:S,isLoading:O}=Z(c,r,D,B),A=ee(c),p=S?.items,C=d?.fields,P=u.useMemo(()=>C?C.filter(e=>["text","number","boolean","select"].includes(e.type)).slice(0,4):[],[C]),w=p?.map(e=>e.contentId)??[],M=w.length>0&&w.every(e=>o.has(e));function U(e){x(t=>{const a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})}function z(){x(M?new Set:new Set(w))}function q(e,t){const n=e.fields?.[t];if(n==null)return"—";if(typeof n=="boolean")return n?"Yes":"No";if(typeof n=="number")return String(n);const T=String(n);return T.length>60?T.slice(0,60)+"…":T}return s.jsxs("div",{children:[!k&&s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:d?.label??r}),s.jsxs(y,{onClick:()=>g(`/sites/${c}/submissions/${r}/new`),children:[s.jsx(K,{className:"mr-1.5 h-4 w-4"}),"New Submission"]})]}),s.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[f.length>0&&s.jsx(le,{relationships:f,activeFilters:$?[$]:[],onFilterAdd:e=>{N({relatedTo:e.contentId,relField:e.relName}),h(void 0)},onFilterRemove:()=>{N({relatedTo:"",relField:""}),h(void 0)}}),s.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[o.size>0&&s.jsxs(y,{variant:"destructive",size:"sm",onClick:async()=>{const e=[...o],a=(await A.mutateAsync(e)).filter(n=>n.status==="rejected").length;a?V.error(`${a} of ${e.length} failed to delete`):V.success(`${e.length} submission(s) deleted`),x(new Set)},disabled:A.isPending,children:[s.jsx(Q,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete (",o.size,")"]}),s.jsxs(re,{value:m,onValueChange:e=>{N({sort:e}),h(void 0)},children:[s.jsx(ie,{className:"w-[150px]",children:s.jsx(oe,{})}),s.jsx(ce,{children:fe.map(e=>s.jsx(de,{value:e.value,children:e.label},e.value))})]})]})]}),O?s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,t)=>s.jsx(W,{className:"h-12 w-full"},t))}):p?.length?s.jsxs(s.Fragment,{children:[k?s.jsx("div",{className:"grid gap-3","data-testid":"submission-card-view",children:p.map(e=>s.jsx(ae,{className:X("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",o.has(e.contentId)&&"ring-2 ring-primary"),onClick:()=>g(`/sites/${c}/submissions/${r}/${e.contentId}`),children:s.jsx(ne,{className:"p-3",children:s.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"font-medium truncate",children:["Submission ",e.contentId.slice(-6)]}),s.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:e.publishedAt?R(e.publishedAt):"—"}),e.siteUser&&s.jsxs("p",{className:"text-xs text-muted-foreground",children:["by ",e.siteUser.name||e.siteUser.userId]})]}),s.jsx(I,{checked:o.has(e.contentId),onCheckedChange:()=>U(e.contentId),onClick:t=>t.stopPropagation(),className:"mt-1"})]})})},e.contentId))}):s.jsxs(ue,{children:[s.jsx(me,{children:s.jsxs(L,{children:[s.jsx(b,{className:"w-10",children:s.jsx(I,{checked:M,onCheckedChange:z,"aria-label":"Select all"})}),P.map(e=>s.jsx(b,{children:e.label||e.name},e.name)),d?.requireAuth&&s.jsx(b,{children:"Submitted by"}),s.jsx(b,{children:"Submitted"})]})}),s.jsx(he,{children:p.map(e=>s.jsxs(L,{className:"cursor-pointer",onClick:()=>g(`/sites/${c}/submissions/${r}/${e.contentId}`),children:[s.jsx(j,{onClick:t=>t.stopPropagation(),children:s.jsx(I,{checked:o.has(e.contentId),onCheckedChange:()=>U(e.contentId),"aria-label":`Select submission ${e.contentId.slice(-6)}`})}),P.map(t=>s.jsx(j,{className:"text-muted-foreground text-sm",children:q(e,t.name)},t.name)),d?.requireAuth&&s.jsx(j,{className:"text-muted-foreground text-sm",children:e.siteUser?e.siteUser.name||e.siteUser.userId:"—"}),s.jsx(j,{className:"text-muted-foreground",children:e.publishedAt?s.jsx("span",{title:xe(e.publishedAt),children:R(e.publishedAt)}):"—"})]},e.contentId))})]}),S?.hasMore&&s.jsx("div",{className:"mt-4 flex justify-center",children:s.jsx(y,{variant:"outline",onClick:()=>h(S.cursor??void 0),children:"Load More"})})]}):s.jsx("p",{className:"text-muted-foreground",children:"No submissions yet."})]})}export{Me as SubmissionListPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as r}from"./tanstack-Bs3zYPPV.js";import"./react-vendor-C2CvUxFh.js";import{Z as i,y as t}from"./index-Cir9tY_P.js";import{$ as s,a0 as o}from"./radix-C1kb_NqW.js";function b({className:e,...a}){return r.jsx(s,{"data-slot":"checkbox",className:t("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...a,children:r.jsx(o,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(i,{className:"size-3.5"})})})}export{b as C};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function n(e,r,u,a,s,t){return s&&!e?t?"schedule-failed":"scheduled":e?!u||!a||u===a?"published":"published-changes":r?"unpublished":"draft"}function l(e){switch(e){case"draft":return"Publish";case"published":return"";case"published-changes":return"Publish Changes";case"unpublished":return"Republish";case"scheduled":return"";case"schedule-failed":return"Publish"}}function i(e){switch(e){case"draft":return{label:"Draft",variant:"secondary"};case"published":return{label:"Published",variant:"default"};case"published-changes":return{label:"Unsaved changes",variant:"outline"};case"unpublished":return{label:"Unpublished",variant:"destructive"};case"scheduled":return{label:"Scheduled",variant:"outline"};case"schedule-failed":return{label:"Schedule failed",variant:"destructive"}}}export{i as a,l as b,n as g};
|