@chaibuilder/pages 0.15.0 → 0.15.1
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/dist/{2AITGKQY-CpxlNmec.cjs → 2AITGKQY-GcbF_G3s.cjs} +1 -1
- package/dist/{2AITGKQY-gEvxLMa5.js → 2AITGKQY-a-BJOrVj.js} +2 -2
- package/dist/{NCMVHL6D-DpycZ17L.js → NCMVHL6D-CCFQEIik.js} +2 -2
- package/dist/{NCMVHL6D-sV6MElOb.cjs → NCMVHL6D-fz7uxKMS.cjs} +1 -1
- package/dist/{ZDWCUMSJ-BbzwbqTE.js → ZDWCUMSJ-B87y4E-s.js} +1 -1
- package/dist/{ZDWCUMSJ-BPT9OZay.cjs → ZDWCUMSJ-D40Aht5l.cjs} +1 -1
- package/dist/{add-new-language-page-C8LIaHl6.js → add-new-language-page-CxNpkd0L.js} +2 -2
- package/dist/{add-new-language-page-B4_z4O8a.cjs → add-new-language-page-Dyh26P7i.cjs} +1 -1
- package/dist/{add-new-page-JY6dRnC4.js → add-new-page-DGQqN1GO.js} +1 -1
- package/dist/{add-new-page-CQRr6Z8g.cjs → add-new-page-jWn3_pZ4.cjs} +1 -1
- package/dist/{delete-page-z88W-Ikh.cjs → delete-page-Bxl1t_Ue.cjs} +1 -1
- package/dist/{delete-page-Dfa2vyQB.js → delete-page-WnsCggnJ.js} +1 -1
- package/dist/{digital-asset-manager-hqMwBWhb.js → digital-asset-manager-ClyooOJY.js} +23 -23
- package/dist/{digital-asset-manager-Zh-mlMF5.cjs → digital-asset-manager-DrXotZ_n.cjs} +1 -1
- package/dist/{duplicate-page-Welcro7Y.cjs → duplicate-page-CDtfdgyJ.cjs} +1 -1
- package/dist/{duplicate-page-B0urG1pP.js → duplicate-page-DOloolXy.js} +14 -14
- package/dist/{dynamic-page-selector-CyhZ0SRO.js → dynamic-page-selector-B-8TUdTG.js} +1 -1
- package/dist/{dynamic-page-selector-Dn_j_r-h.cjs → dynamic-page-selector-CcYIfKlO.cjs} +1 -1
- package/dist/index-CffopOpP.cjs +5 -0
- package/dist/{index-BSEA_u0X.js → index-CguzNa4U.js} +1446 -1368
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/{json-diff-viewer-DVlb4YWD.js → json-diff-viewer-CxFGgqa_.js} +1 -1
- package/dist/{json-diff-viewer-BIJ4iNWb.cjs → json-diff-viewer-DcR1gbkd.cjs} +1 -1
- package/dist/{lang-panel-D0IN38gF.js → lang-panel-Bi427DLp.js} +29 -29
- package/dist/{lang-panel-l6Teik-4.cjs → lang-panel-XonHaLBn.cjs} +1 -1
- package/dist/{mark-as-template-DBPJ1gIK.cjs → mark-as-template-BtI1QfuI.cjs} +1 -1
- package/dist/{mark-as-template-B22EANHN.js → mark-as-template-CS68JVP8.js} +1 -1
- package/dist/{no-language-page-content-DNNu8wd0.js → no-language-page-content-C5t9cDI4.js} +1 -1
- package/dist/{no-language-page-content-BUHXqSKG.cjs → no-language-page-content-DMqw1cTK.cjs} +1 -1
- package/dist/{page-creator-BPgx7zdJ.js → page-creator-BY2w99Ez.js} +2 -2
- package/dist/{page-creator-DbN3Nvq6.cjs → page-creator-BkKT_Xy1.cjs} +1 -1
- package/dist/{page-lock-request-BFkpw5VN.cjs → page-lock-request-CIRTswpw.cjs} +1 -1
- package/dist/{page-lock-request-Br9S1AsA.js → page-lock-request-Z1sTGi6N.js} +10 -10
- package/dist/{page-locked-by-dialog-DyLcMu33.js → page-locked-by-dialog-B2C1M_bK.js} +1 -1
- package/dist/{page-locked-by-dialog-2h8cv1tO.cjs → page-locked-by-dialog-DpBpQ0oI.cjs} +1 -1
- package/dist/{page-manager-new-B2oBm4pU.js → page-manager-new-CSqFLJBd.js} +37 -37
- package/dist/{page-manager-new-CAj6WV-C.cjs → page-manager-new-tWV46glN.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-WQYVXUAt.js → page-manager-search-and-filter-B9VZzJQd.js} +1 -1
- package/dist/{page-manager-search-and-filter-CWMXLTqE.cjs → page-manager-search-and-filter-CwuukvKn.cjs} +1 -1
- package/dist/{page-revisions-content-AMH8AxBU.cjs → page-revisions-content-BWhJz0_7.cjs} +1 -1
- package/dist/{page-revisions-content-DM-ngq3R.js → page-revisions-content-WoIu0uan.js} +17 -17
- package/dist/{publish-pages-content-Dkv0Lok8.cjs → publish-pages-content-BHDTLdGv.cjs} +1 -1
- package/dist/{publish-pages-content-Dast4sG6.js → publish-pages-content-CkWvQGbm.js} +2 -2
- package/dist/{save-to-lib-B5k0MVbW.js → save-to-lib-AkbnWUxR.js} +12 -12
- package/dist/{save-to-lib-DWtmtrUj.cjs → save-to-lib-C0ZfwiAE.cjs} +1 -1
- package/dist/{seo-panel-dBvEEfi9.cjs → seo-panel-CiKkn5Jp.cjs} +1 -1
- package/dist/{seo-panel-D75jQH_j.js → seo-panel-Gu3HZveQ.js} +34 -34
- package/dist/shared-json-ld-BPaeG1gf.cjs +1 -0
- package/dist/shared-json-ld-CsyZjZdT.js +557 -0
- package/dist/{slug-input-BITq28nI.cjs → slug-input-B4w0Ihxn.cjs} +1 -1
- package/dist/{slug-input-BEegJ8bv.js → slug-input-BXNj3cZf.js} +1 -1
- package/dist/{theme-panel-footer-zLXS6SHh.js → theme-panel-footer-68bQaQeh.js} +1 -1
- package/dist/{theme-panel-footer-DcASH9l1.cjs → theme-panel-footer-DnZs9SzB.cjs} +1 -1
- package/dist/{unmark-as-template-ChmjL4-w.cjs → unmark-as-template-DFxmzyx4.cjs} +1 -1
- package/dist/{unmark-as-template-DXFRY_pc.js → unmark-as-template-MpXMyb0Q.js} +1 -1
- package/dist/{unpublish-page-DMteaCpR.js → unpublish-page-Bzouoco9.js} +1 -1
- package/dist/{unpublish-page-BxN0deJK.cjs → unpublish-page-CCPyMoaC.cjs} +1 -1
- package/dist/{web-preview-DM11qhOe.cjs → web-preview-B3-o8BoT.cjs} +1 -1
- package/dist/{web-preview-BDTdFQ2h.js → web-preview-D9PcexXy.js} +1 -1
- package/package.json +1 -1
- package/dist/index-MlpQJHWW.cjs +0 -5
- package/dist/shared-json-ld-BvWyXBz_.cjs +0 -1
- package/dist/shared-json-ld-ZtwsYt9H.js +0 -337
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t, jsxs as h, Fragment as rn } from "react/jsx-runtime";
|
|
2
|
-
import { p as hn, r as fn, S as An } from "./slug-input-
|
|
3
|
-
import { b as Nn, c as mn, d as En, e as Sn, f as gn, g as K, h as xn, i as Gn, L, C as f } from "./index-
|
|
2
|
+
import { p as hn, r as fn, S as An } from "./slug-input-BXNj3cZf.js";
|
|
3
|
+
import { b as Nn, c as mn, d as En, e as Sn, f as gn, g as K, h as xn, i as Gn, L, C as f } from "./index-CguzNa4U.js";
|
|
4
4
|
import { useLanguages as vn, useSidebarActivePanel as Ln } from "@chaibuilder/sdk";
|
|
5
5
|
import { Dialog as Dn, DialogContent as _n, DialogHeader as Un, DialogTitle as pn, DialogDescription as Fn, Label as k, Input as Tn, Alert as X, DialogFooter as wn, Button as Cn } from "@chaibuilder/sdk/ui";
|
|
6
6
|
import { filter as $n, find as In, startsWith as Rn } from "lodash-es";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("./slug-input-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("./slug-input-B4w0Ihxn.cjs"),t=require("./index-CffopOpP.cjs"),H=require("@chaibuilder/sdk"),E=require("@chaibuilder/sdk/ui"),W=require("lodash-es"),us=require("lucide-react"),T=require("react"),J=({edit:a,lang:h,languages:i,name:u,setLang:o,setName:r,primaryPageObject:l})=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(E.Label,{htmlFor:"lang",children:t.CONTENT.LANGUAGE}),e.jsxs("select",{value:a?"":h,disabled:a||!i.length,onChange:s=>{const c=s.target.value;o(c),!a&&(W.startsWith(u,l==null?void 0:l.name)||u.length===0)&&r(`${l==null?void 0:l.name} - ${t.LANGUAGES[c]}`)},className:"col-span-3 flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("option",{value:"",disabled:!0,children:a?t.LANGUAGES[h]||h:i.length?t.CONTENT.CHOOSE_LANGUAGE:t.CONTENT.ALL_AVAILABLE_LANGUAGE_PAGE}),i.map(s=>e.jsx("option",{value:s,children:t.LANGUAGES[s]||s},s))]})]}),K=({lang:a,name:h,setName:i,parentHasSelectedLanguagePage:u})=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(E.Label,{htmlFor:"name",children:t.CONTENT.PAGE_NAME}),e.jsx(E.Input,{id:"name",value:a?h:"",onChange:o=>i(o.target.value),required:!0,placeholder:a?t.CONTENT.ENTER_PAGE_NAME:t.CONTENT.CHOOSE_LANGUAGE_TO_ADD_SLUG,disabled:!u||!a})]}),ds=({dynamic:a,isNonSlugPageType:h,isRootPage:i,lang:u,useLanguagePrefix:o,setUseLanguagePrefix:r,isHomePage:l,parentSlug:s,parentHasSelectedLanguagePage:c,slug:N,setSlug:d,setIsSlugValid:A,getSlug:x})=>h?null:e.jsxs("div",{className:"space-y-1",children:[i&&u&&e.jsxs("div",{className:"flex items-center space-x-2 pb-1",children:[e.jsx("input",{type:"checkbox",id:"useLanguagePrefix",checked:o,onChange:S=>r(S.target.checked),className:"rounded border-gray-300"}),e.jsxs(E.Label,{htmlFor:"useLanguagePrefix",className:"text-sm font-normal leading-tight",children:["Add language code (",e.jsxs("span",{className:"font-mono text-gray-900",children:["/",u]}),") as slug prefix"]})]}),e.jsx(E.Label,{htmlFor:"slug",children:t.CONTENT.SLUG}),a?e.jsx(E.Alert,{variant:"default",className:"p-2 text-xs font-medium italic text-muted-foreground",children:"This page will use dynamic slug as defined in primary page"}):e.jsx(M.SlugInput,{disabled:!u||!c,value:N,onChange:d,placeholder:u?l&&o?"Leave empty for home page":t.CONTENT.ENTER_PAGE_SLUG:t.CONTENT.CHOOSE_LANGUAGE_TO_ADD_SLUG,parentSlug:s,onValidationChange:A,fullSlug:x()})]}),Q=({parentHasSelectedLanguagePage:a,name:h,lang:i,slug:u,edit:o,id:r,primaryPageObject:l,pages:s,isNonSlugPageType:c,isHomePage:N,useLanguagePrefix:d,isSlugValid:A,isPending:x})=>{const S=x||!h||!i||s.some(f=>(o?f.id!==r:!0)&&f.parent===(l==null?void 0:l.id)&&f.lang===i)||!c&&!(N&&d)&&(!A||!u);return e.jsx(E.DialogFooter,{children:a?e.jsxs(e.Fragment,{children:[e.jsx(E.Button,{type:"submit",disabled:S&&!l.dynamic,children:x?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"loader mr-2"}),o?t.CONTENT.UPDATING:t.CONTENT.ADDING]}):o?t.CONTENT.UPDATE:t.CONTENT.ADD_NEW_LANGUAGE}),s.some(f=>(o?f.id!==r:!0)&&f.parent===(l==null?void 0:l.id)&&f.lang===i)&&e.jsx("p",{className:"mt-2 text-xs text-red-500",children:"A page for this language already exists."})]}):i&&e.jsx(E.Alert,{variant:"destructive",children:e.jsxs("p",{className:"mx-auto w-5/6 text-center",children:["You need to create the ",e.jsx("span",{className:"font-medium",children:t.LANGUAGES[i]})," page in the parent to add here."]})})})},cs=({onSubmit:a,edit:h,lang:i,languages:u,name:o,setLang:r,setName:l,primaryPageObject:s,parentHasSelectedLanguagePage:c,id:N,pages:d,isNonSlugPageType:A,isHomePage:x,useLanguagePrefix:S,slug:f,isSlugValid:U,isPending:G})=>e.jsxs("form",{onSubmit:a,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(J,{edit:h,lang:i,languages:u,name:o,setLang:r,setName:l,primaryPageObject:s}),e.jsx(K,{lang:i,name:o,setName:l,parentHasSelectedLanguagePage:c})]}),e.jsx(Q,{parentHasSelectedLanguagePage:c,name:o,lang:i,slug:f,edit:h,id:N,primaryPageObject:s,pages:d,isNonSlugPageType:A,isHomePage:x,useLanguagePrefix:S,isSlugValid:U,isPending:G})]}),as=({loading:a,onSubmit:h,edit:i,lang:u,languages:o,name:r,setLang:l,setName:s,primaryPageObject:c,parentHasSelectedLanguagePage:N,isNonSlugPageType:d,isRootPage:A,useLanguagePrefix:x,setUseLanguagePrefix:S,isHomePage:f,parentSlug:U,slug:G,setSlug:_,isSlugValid:D,setIsSlugValid:$,getSlug:I,isPending:F,id:w,pages:v})=>a?e.jsx("div",{className:"flex h-80 items-center justify-center",children:e.jsx(us.Loader,{className:"animate-spin"})}):d?e.jsx(cs,{onSubmit:h,edit:i,lang:u,languages:o,name:r,setLang:l,setName:s,primaryPageObject:c,parentHasSelectedLanguagePage:N,id:w,pages:v,isNonSlugPageType:d,isHomePage:f,useLanguagePrefix:x,slug:G,isSlugValid:D,isPending:F}):e.jsxs("form",{onSubmit:h,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(J,{edit:i,lang:u,languages:o,name:r,setLang:l,setName:s,primaryPageObject:c}),e.jsx(K,{lang:u,name:r,setName:s,parentHasSelectedLanguagePage:N}),e.jsx(ds,{dynamic:c==null?void 0:c.dynamic,isNonSlugPageType:d,isRootPage:A,lang:u,useLanguagePrefix:x,setUseLanguagePrefix:S,isHomePage:f,parentSlug:U,parentHasSelectedLanguagePage:N,slug:G,setSlug:_,isSlugValid:D,setIsSlugValid:$,getSlug:I})]}),e.jsx(Q,{parentHasSelectedLanguagePage:N,name:r,lang:u,slug:G,edit:i,id:w,primaryPageObject:c,pages:v,isNonSlugPageType:d,isHomePage:f,useLanguagePrefix:x,isSlugValid:D,isPending:F})]}),rs=({id:a,isOpen:h,onClose:i,primaryPage:u,edit:o=!1,preselectedLang:r})=>{const{data:l=[]}=t.useWebsitePages(),s=T.useMemo(()=>l.find(n=>n.id===u),[l,u]),[c,N]=T.useState(""),[d,A]=T.useState(""),[x,S]=T.useState(""),[f,U]=T.useState(!0),[G,_]=T.useState(!0),{mutate:D,isPending:$}=t.useCreatePage(),{mutate:I,isPending:F}=t.useUpdatePage(),w=$||F,{data:v,isFetching:X}=t.useWebsiteSetting(),B=t.useFallbackLang(),{data:m,isFetching:Z}=t.useLanguagePages(u),{data:L=[],isFetching:b}=t.useLanguagePages(s==null?void 0:s.parent),{data:V=[],isFetching:y}=t.usePageTypes(),{setSelectedLang:O}=H.useLanguages(),[,P]=t.useSearchParams(),[,ss]=H.useSidebarActivePanel(),es=X||Z||b||y,C=T.useMemo(()=>W.filter(v==null?void 0:v.languages,n=>!W.find(m,{lang:n})),[v,m]),q=T.useMemo(()=>V.find(n=>n.key===(s==null?void 0:s.pageType)),[V,s==null?void 0:s.pageType]),Y=!(q!=null&&q.hasSlug),k=(s==null?void 0:s.slug)==="/";T.useEffect(()=>{if(!o&&s&&r&&(A(r),N(`${s.name} - ${t.LANGUAGES[r]}`)),!o||!s)return;const n=m==null?void 0:m.find(is=>is.id===a);if(!n)return;N(n.name),A(n.lang);const g=n.slug||"",{initSlug:R,prefix:ls}=M.parseSlugForEdit(g,s);S(R),_(ls)},[o,a,m,s,r]),T.useEffect(()=>{if(r)A(r);else if((C==null?void 0:C.length)===1&&!o){const n=C[0];if(!n||!t.LANGUAGES[n])return;A(n),(!c||c===(s==null?void 0:s.name))&&N(`${s==null?void 0:s.name} - ${t.LANGUAGES[n]}`)}},[r,C,o,c,s]);const{parentSlug:j,isRootPage:p}=T.useMemo(()=>{if(k||!d)return{parentSlug:void 0,isRootPage:!(s!=null&&s.parent)};if(!(s!=null&&s.parent))return{parentSlug:G?`/${d}`:void 0,isRootPage:!0};const n=L==null?void 0:L.find(g=>g.lang===d);return{parentSlug:n==null?void 0:n.slug,isRootPage:!1}},[s==null?void 0:s.parent,L,G,d,k]),ns=T.useMemo(()=>p?!0:!!(L!=null&&L.some(n=>(n==null?void 0:n.lang)===d)),[d,L,p]),z=()=>{let n="";return p?n=`/${G?[d,x].filter(Boolean).join("/"):x}`:n=`${M.removeSlugExtension(j)}/${x}`,n.replace(/\/{2,}/g,"/").replace(/\/$/,"")},ts=n=>{const g=new URLSearchParams(window.location.search);B&&n===B?g.delete("lang"):g.set("lang",n),P(g),window.dispatchEvent(new PopStateEvent("popstate"))},os=n=>{n.preventDefault();const g={name:c,lang:d,primaryPage:s==null?void 0:s.id,slug:Y?"":z(),pageType:s==null?void 0:s.pageType,...o&&{id:a}},R=()=>{!o&&d&&(O(d),ts(d)),ss("outline"),i()};o?I(g,{onSuccess:R}):D(g,{onSuccess:R})};return e.jsx(E.Dialog,{open:h,onOpenChange:i,children:h&&e.jsxs(E.DialogContent,{className:"text-slate-600 sm:max-w-[425px]",children:[e.jsxs(E.DialogHeader,{children:[e.jsx(E.DialogTitle,{children:o?t.CONTENT.EDIT_LANGUAGE:t.CONTENT.ADD_NEW_LANGUAGE}),e.jsx(E.DialogDescription,{className:"font-light",children:t.CONTENT.ENTER_LANGUAGE_DETAILS})]}),e.jsx(as,{id:a,pages:l,loading:es,onSubmit:os,edit:o,lang:d,languages:C,name:c,setLang:A,setName:N,primaryPageObject:s,parentHasSelectedLanguagePage:ns,isNonSlugPageType:Y,isRootPage:p,useLanguagePrefix:G,setUseLanguagePrefix:_,isHomePage:k,parentSlug:j,slug:x,setSlug:S,isSlugValid:f,setIsSlugValid:U,getSlug:z,isPending:w})]})})};exports.default=rs;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as o, jsxs as n } from "react/jsx-runtime";
|
|
2
2
|
import { Dialog as c, DialogContent as a, DialogHeader as t, DialogTitle as p, DialogDescription as m } from "@chaibuilder/sdk/ui";
|
|
3
3
|
import { lazy as h, Suspense as D } from "react";
|
|
4
|
-
const f = h(() => import("./page-creator-
|
|
4
|
+
const f = h(() => import("./page-creator-BY2w99Ez.js")), N = ({
|
|
5
5
|
addEditPage: e,
|
|
6
6
|
setAddEditPage: r,
|
|
7
7
|
closePanel: s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),l=require("react"),t=l.lazy(()=>Promise.resolve().then(()=>require("./page-creator-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),l=require("react"),t=l.lazy(()=>Promise.resolve().then(()=>require("./page-creator-BkKT_Xy1.cjs"))),a=({addEditPage:s,setAddEditPage:o,closePanel:c})=>{const r=!!(s!=null&&s.id),i=!!s;return e.jsx(n.Dialog,{open:i,onOpenChange:()=>o(void 0),children:i&&e.jsxs(n.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(n.DialogHeader,{children:[e.jsxs(n.DialogTitle,{children:[r?"Edit":"Add New"," "]}),e.jsx(n.DialogDescription,{children:r?"Update your page name":"Enter details to create a new page"})]}),e.jsx(l.Suspense,{fallback:e.jsx("div",{className:"min-h-40"}),children:e.jsx(t,{closePanel:c,addEditPage:s,close:()=>o(void 0)})})]})})};exports.default=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("./index-CffopOpP.cjs"),c=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),D=require("lodash-es");function y({page:e,onClose:r}){const[,o]=i.useSearchParams(),{mutate:d,isPending:l}=i.useDeletePage(),{data:a}=i.usePageTypes(),{setSelectedLang:u,fallbackLang:h}=c.useLanguages(),[,m]=c.useSidebarActivePanel(),x=()=>{l||d(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),o(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),o(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),u(h),m("outline"),r()}})},s=a==null?void 0:a.find(P=>P.key===(e==null?void 0:e.pageType));return n.jsx(t.Dialog,{open:!!e,onOpenChange:r,children:n.jsxs(t.DialogContent,{children:[n.jsxs(t.DialogHeader,{children:[n.jsx(t.DialogTitle,{children:"Confirm Deletion"}),n.jsxs(t.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:["Are you sure you want to remove ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",s!=null&&s.hasSlug?(s==null?void 0:s.name)+"?":`page? ${e!=null&&e.primaryPage?"":"This will also delete all associated language pages."}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:["Language: ",n.jsx("span",{className:"font-medium text-gray-500",children:D.get(i.LANGUAGES,e.lang,e.lang)})]})]})]}),n.jsxs(t.DialogFooter,{children:[n.jsx(t.Button,{variant:"outline",onClick:r,children:"Cancel"}),n.jsx(t.Button,{variant:"destructive",disabled:l,onClick:x,children:l?"Deleting...":"Delete"})]})]})})}exports.default=y;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as n, jsxs as i } from "react/jsx-runtime";
|
|
2
|
-
import { i as D, m as f, h as w, L as y } from "./index-
|
|
2
|
+
import { i as D, m as f, h as w, L as y } from "./index-CguzNa4U.js";
|
|
3
3
|
import { useLanguages as S, useSidebarActivePanel as v } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as L, DialogContent as x, DialogHeader as A, DialogTitle as k, DialogDescription as C, DialogFooter as N, Button as o } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { get as g } from "lodash-es";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as l, jsx as e, Fragment as Q } from "react/jsx-runtime";
|
|
2
2
|
import { mergeClasses as ce } from "@chaibuilder/sdk";
|
|
3
|
-
import { Button as g, Input as oe, Label as _, Textarea as ze, TooltipProvider as
|
|
3
|
+
import { Button as g, Input as oe, Label as _, Textarea as ze, TooltipProvider as M, Tooltip as B, TooltipTrigger as $, TooltipContent as P, Dialog as De, DialogContent as je, DialogHeader as Fe, DialogTitle as Ue, DialogDescription as Le, DialogFooter as Me, Switch as Be } from "@chaibuilder/sdk/ui";
|
|
4
4
|
import { find as $e, merge as Pe, pick as Oe, first as qe, isEmpty as Ke } from "lodash-es";
|
|
5
5
|
import { ChevronLeft as de, ChevronRight as Ge, Loader as O, AlertCircle as Re, Copy as me, Pencil as _e, Link as Qe, Search as We, RefreshCwIcon as Ve, Archive as He, Film as Xe, ImageIcon as Ze, Edit as Je, Trash2 as Ye, Check as et, Upload as tt, AlertTriangle as it } from "lucide-react";
|
|
6
6
|
import ue, { createContext as rt, Component as at, createElement as le, useState as b, useMemo as he, useEffect as W, useCallback as L, Suspense as lt } from "react";
|
|
@@ -8,7 +8,7 @@ import { useDropzone as nt } from "react-dropzone";
|
|
|
8
8
|
import { toast as A } from "sonner";
|
|
9
9
|
import { f as st, c as ct } from "./image-compression-DsZ1oqpb.js";
|
|
10
10
|
import { useQueryClient as J, useMutation as Y, useQuery as fe } from "@tanstack/react-query";
|
|
11
|
-
import {
|
|
11
|
+
import { aM as q, am as K, A as E } from "./index-CguzNa4U.js";
|
|
12
12
|
const ot = rt(null), Z = {
|
|
13
13
|
didCatch: !1,
|
|
14
14
|
error: null
|
|
@@ -601,7 +601,7 @@ const yt = ({
|
|
|
601
601
|
/* @__PURE__ */ e("span", { className: r ? "text-indigo-600" : "text-gray-400", children: r ? "On" : "Off" })
|
|
602
602
|
] }),
|
|
603
603
|
/* @__PURE__ */ e(
|
|
604
|
-
|
|
604
|
+
Be,
|
|
605
605
|
{
|
|
606
606
|
checked: r,
|
|
607
607
|
onCheckedChange: (f) => {
|
|
@@ -614,7 +614,7 @@ const yt = ({
|
|
|
614
614
|
}
|
|
615
615
|
)
|
|
616
616
|
] }),
|
|
617
|
-
/* @__PURE__ */ e(
|
|
617
|
+
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ l(B, { children: [
|
|
618
618
|
/* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(
|
|
619
619
|
"span",
|
|
620
620
|
{
|
|
@@ -654,16 +654,16 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
654
654
|
search: z.toLowerCase().trim(),
|
|
655
655
|
page: G,
|
|
656
656
|
limit: ee
|
|
657
|
-
}),
|
|
657
|
+
}), I = (F == null ? void 0 : F.assets) || [], ge = (F == null ? void 0 : F.total) || 0, T = Math.ceil(ge / ee);
|
|
658
658
|
W(() => {
|
|
659
|
-
R ||
|
|
660
|
-
}, [R,
|
|
661
|
-
const ve = (
|
|
659
|
+
R || T <= 0 || H((t) => t > T ? T : t < 1 ? 1 : t);
|
|
660
|
+
}, [R, T]);
|
|
661
|
+
const ve = (I == null ? void 0 : I.length) > 0, { mutate: xe } = ht(), { mutateAsync: te, isPending: ye } = ut(), { mutate: ie, isPending: Ne } = ft(), re = L(
|
|
662
662
|
(t) => {
|
|
663
|
-
const u = Math.min(Math.max(1, t), Math.max(1,
|
|
663
|
+
const u = Math.min(Math.max(1, t), Math.max(1, T));
|
|
664
664
|
u !== G && H(u);
|
|
665
665
|
},
|
|
666
|
-
[
|
|
666
|
+
[T, G]
|
|
667
667
|
), be = (t) => {
|
|
668
668
|
j(t.target.value);
|
|
669
669
|
}, we = L(
|
|
@@ -705,9 +705,9 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
705
705
|
} catch (U) {
|
|
706
706
|
console.error("Error saving edited image:", U);
|
|
707
707
|
}
|
|
708
|
-
},
|
|
708
|
+
}, Te = L((t) => {
|
|
709
709
|
X([t]);
|
|
710
|
-
}, []),
|
|
710
|
+
}, []), Ie = L(
|
|
711
711
|
(t) => {
|
|
712
712
|
re(t);
|
|
713
713
|
},
|
|
@@ -725,7 +725,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
725
725
|
uploadAssets: te,
|
|
726
726
|
isUpdatingAsset: Ne,
|
|
727
727
|
isUploadingAsset: ye,
|
|
728
|
-
onUploaded:
|
|
728
|
+
onUploaded: Te
|
|
729
729
|
}
|
|
730
730
|
),
|
|
731
731
|
/* @__PURE__ */ l("div", { className: "relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2", children: [
|
|
@@ -789,7 +789,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
789
789
|
/* @__PURE__ */ e("div", { className: "text-lg text-muted-foreground", children: "No assets found" }),
|
|
790
790
|
/* @__PURE__ */ e("div", { className: "text-sm text-muted-foreground", children: z.length > 0 ? "No assets found for your search: " + z : "Start uploading assets to get started" }),
|
|
791
791
|
/* @__PURE__ */ e("br", {})
|
|
792
|
-
] }) : /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-3 p-1", children:
|
|
792
|
+
] }) : /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-3 p-1", children: I == null ? void 0 : I.map((t) => /* @__PURE__ */ l(
|
|
793
793
|
"div",
|
|
794
794
|
{
|
|
795
795
|
className: ce(
|
|
@@ -827,7 +827,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
827
827
|
/* @__PURE__ */ e("div", { className: "flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground", children: /* @__PURE__ */ e("span", { children: st((t == null ? void 0 : t.size) || 0) }) })
|
|
828
828
|
] }),
|
|
829
829
|
!k.some((u) => u.id === t.id) && /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100", children: /* @__PURE__ */ l("div", { className: "grid grid-cols-4 gap-2 p-2", children: [
|
|
830
|
-
/* @__PURE__ */ e(
|
|
830
|
+
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ l(B, { children: [
|
|
831
831
|
/* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(
|
|
832
832
|
g,
|
|
833
833
|
{
|
|
@@ -842,7 +842,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
842
842
|
) }),
|
|
843
843
|
/* @__PURE__ */ e(P, { children: /* @__PURE__ */ e("p", { children: "View Details" }) })
|
|
844
844
|
] }) }),
|
|
845
|
-
/* @__PURE__ */ e(
|
|
845
|
+
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ l(B, { children: [
|
|
846
846
|
/* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(
|
|
847
847
|
g,
|
|
848
848
|
{
|
|
@@ -857,7 +857,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
857
857
|
) }),
|
|
858
858
|
/* @__PURE__ */ e(P, { children: /* @__PURE__ */ e("p", { children: "Copy URL" }) })
|
|
859
859
|
] }) }),
|
|
860
|
-
/* @__PURE__ */ e(
|
|
860
|
+
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ l(B, { children: [
|
|
861
861
|
/* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(
|
|
862
862
|
g,
|
|
863
863
|
{
|
|
@@ -877,7 +877,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
877
877
|
) }),
|
|
878
878
|
/* @__PURE__ */ e(P, { children: /* @__PURE__ */ e("p", { children: "Edit Image" }) })
|
|
879
879
|
] }) }),
|
|
880
|
-
/* @__PURE__ */ e(
|
|
880
|
+
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ l(B, { children: [
|
|
881
881
|
/* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(
|
|
882
882
|
g,
|
|
883
883
|
{
|
|
@@ -898,12 +898,12 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
898
898
|
},
|
|
899
899
|
t.id
|
|
900
900
|
)) }) }),
|
|
901
|
-
|
|
901
|
+
T > 1 && /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 border-t bg-white p-4", children: /* @__PURE__ */ e(dt, { fallback: /* @__PURE__ */ e("div", { className: "text-red-500", children: "Error loading pagination" }), children: /* @__PURE__ */ e(
|
|
902
902
|
pt,
|
|
903
903
|
{
|
|
904
904
|
currentPage: G,
|
|
905
|
-
totalPages:
|
|
906
|
-
onPageChange:
|
|
905
|
+
totalPages: T,
|
|
906
|
+
onPageChange: Ie,
|
|
907
907
|
pageRangeDisplayed: 3,
|
|
908
908
|
showPageInput: !0
|
|
909
909
|
}
|
|
@@ -928,7 +928,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
928
928
|
if (v) {
|
|
929
929
|
h(!0);
|
|
930
930
|
try {
|
|
931
|
-
const u =
|
|
931
|
+
const u = I.find((U) => U.id === v);
|
|
932
932
|
u && await ie(Pe(u, { description: t }));
|
|
933
933
|
} finally {
|
|
934
934
|
h(!1);
|
|
@@ -964,7 +964,7 @@ function Ut({ close: s, onSelect: a, mode: c = "image", assetId: i }) {
|
|
|
964
964
|
'"? This action cannot be undone.'
|
|
965
965
|
] })
|
|
966
966
|
] }),
|
|
967
|
-
/* @__PURE__ */ l(
|
|
967
|
+
/* @__PURE__ */ l(Me, { className: "gap-2 sm:gap-0", children: [
|
|
968
968
|
/* @__PURE__ */ e(g, { variant: "outline", onClick: () => w(null), children: "Cancel" }),
|
|
969
969
|
/* @__PURE__ */ e(g, { variant: "destructive", onClick: Se, children: "Delete" })
|
|
970
970
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),X=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),L=require("lodash-es"),p=require("lucide-react"),d=require("react"),he=require("react-dropzone"),A=require("sonner"),Z=require("./image-compression-DZ9WMmyn.cjs"),k=require("@tanstack/react-query"),j=require("./index-MlpQJHWW.cjs"),xe=d.createContext(null),K={didCatch:!1,error:null};class fe extends d.Component{constructor(r){super(r),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=K}static getDerivedStateFromError(r){return{didCatch:!0,error:r}}resetErrorBoundary(){const{error:r}=this.state;if(r!==null){for(var o,s,c=arguments.length,i=new Array(c),u=0;u<c;u++)i[u]=arguments[u];(o=(s=this.props).onReset)===null||o===void 0||o.call(s,{args:i,reason:"imperative-api"}),this.setState(K)}}componentDidCatch(r,o){var s,c;(s=(c=this.props).onError)===null||s===void 0||s.call(c,r,o)}componentDidUpdate(r,o){const{didCatch:s}=this.state,{resetKeys:c}=this.props;if(s&&o.error!==null&&pe(r.resetKeys,c)){var i,u;(i=(u=this.props).onReset)===null||i===void 0||i.call(u,{next:c,prev:r.resetKeys,reason:"keys"}),this.setState(K)}}render(){const{children:r,fallbackRender:o,FallbackComponent:s,fallback:c}=this.props,{didCatch:i,error:u}=this.state;let v=r;if(i){const N={error:u,resetErrorBoundary:this.resetErrorBoundary};if(typeof o=="function")v=o(N);else if(s)v=d.createElement(s,N);else if(c!==void 0)v=c;else throw u}return d.createElement(xe.Provider,{value:{didCatch:i,error:u,resetErrorBoundary:this.resetErrorBoundary}},v)}}function pe(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return n.length!==r.length||n.some((o,s)=>!Object.is(o,r[s]))}const ge=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>{const c=s.map(async u=>o(n,{action:j.ACTIONS.UPLOAD_ASSET,data:u}));return await Promise.all(c)},onSuccess:s=>{var c;if(s!=null&&s.some(i=>i.error))throw new Error(((c=s==null?void 0:s.find(i=>i.error))==null?void 0:c.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]});const i=s==null?void 0:s.length;A.toast.success(`${i===1?"Asset":i+" Assets"} uploaded successfully`)}},onError:()=>{A.toast.error("Failed to upload asset")}})},je=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset deleted successfully")},onError:()=>{A.toast.error("Failed to delete asset")}})},ve=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset updated successfully")},onError:()=>{A.toast.error("Failed to update asset")}})};function ye({currentPage:n,totalPages:r,onPageChange:o,pageRangeDisplayed:s=3,showPageInput:c=!0,className:i=""}){const[u,v]=d.useState(String(n)),N=d.useMemo(()=>{const l=Math.floor(s/2);let m=Math.max(1,n-l),x=Math.min(r,n+l);x-m+1<s&&(m===1?x=Math.min(r,m+s-1):x===r&&(m=Math.max(1,x-s+1)));const y=[];m>1&&(y.push(1),m>2&&y.push("..."));for(let b=m;b<=x;b++)y.push(b);return x<r&&(x<r-1&&y.push("..."),y.push(r)),y},[n,r,s]),g=l=>{l!==n&&l>=1&&l<=r&&(o(l),v(String(l)))},w=()=>{n>1&&g(n-1)},S=()=>{n<r&&g(n+1)},C=()=>{const l=Number(u);!isNaN(l)&&l>=1&&l<=r&&g(l)},f=l=>{l.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${i}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:w,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(p.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((l,m)=>{if(l==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const x=l,y=x===n;return e.jsx(a.Button,{variant:y?"default":"outline",size:"sm",onClick:()=>g(x),className:y?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:x},x)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:S,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(p.ChevronRight,{className:" h-4 w-4"})]})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:u,onChange:l=>{const m=l.target.value.replace(/[^\d]/g,"");v(m)},onKeyDown:f,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:u===""||Number(u)<1||Number(u)>r,children:"Go"})]})]})}const Ne=(n={})=>{const r=j.useAssetsApiUrl(),o=j.useFetch(),{search:s,page:c=1,limit:i=30}=n;return k.useQuery({queryKey:[j.ACTIONS.GET_ASSETS,s,c,i],queryFn:async()=>{const u=await o(r,{action:j.ACTIONS.GET_ASSETS,data:{search:s,page:c,limit:i}});return u.page=c,u.limit=i,u},staleTime:1/0,retry:1})},be=n=>{const r=j.useAssetsApiUrl(),o=j.useFetch();return k.useQuery({queryKey:[j.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await o(r,{action:j.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function we(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function V(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function H(n,r){let o=n,s=r==null?void 0:r.description;return(!s||typeof s!="string")&&(s=""),(!o||typeof o!="string")&&(o=""),o!==s}const Ce=({assetId:n,onBack:r,onEdit:o,onSave:s,isSaving:c})=>{var S,C,f;const{data:i,isLoading:u,isError:v}=be(n||""),[N,g]=d.useState(""),w=async(l,m)=>{try{await navigator.clipboard.writeText(l),A.toast.success(`${m} copied to clipboard`)}catch(x){A.toast.error(`Failed to copy ${m}`,{description:x==null?void 0:x.message})}};return d.useEffect(()=>{i!=null&&i.description&&g(i.description)},[i]),u?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}):v||!(i!=null&&i.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(p.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:v?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed."}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:"Back to Assets"}),v&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:c,children:[e.jsx(p.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:c,children:"Cancel"}),e.jsxs(a.Button,{variant:"outline",onClick:()=>w(i.url,"Asset URL"),disabled:c,children:[e.jsx(p.Copy,{className:"h-4 w-4 mr-2"}),"Copy URL"]}),e.jsxs(a.Button,{variant:"default",onClick:()=>o(i),disabled:c,children:[e.jsx(p.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:`${i.url}?v=${((S=i.metadata)==null?void 0:S.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Details"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((C=i.metadata)==null?void 0:C.format)||i.type,capitalize:!0},{label:"Size",value:we(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:V(i.createdAt)},{label:"Updated",value:V(((f=i.metadata)==null?void 0:f.updatedAt)||i.createdAt)},{label:"URL",value:i.url,copyable:!0}].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:l.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(l.capitalize?" capitalize":""),children:l.value}),l.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>w(l.value,l.label),children:e.jsx(p.Link,{className:"h-3 w-3"})})]})]},l.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:"Used On"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((l,m)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:l.name}),e.jsxs("div",{className:"text-gray-500",children:["(",l.slug,")"]})]},m))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Description"}),e.jsx(a.Textarea,{id:"description",value:N,placeholder:"Enter a description for the asset",onChange:l=>g(l.target.value),rows:3,disabled:c,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>s(N),disabled:c||!H(N,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${c||!H(N,i)?"opacity-50 cursor-not-allowed":""}`,children:c?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},Ae=d.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs"))),Se=25*1024*1024,Te=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:o,isUploadingAsset:s,onUploaded:c})=>{const[i,u]=d.useState(()=>{const f=localStorage.getItem("chai_optimize_images");return f!==null?f==="true":!0});d.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const v=n||s,N=d.useCallback(async f=>{try{const l=f;if(!l.every(b=>b.type.startsWith("image/")))return A.toast.error("Invalid file type. Please upload a valid file."),Promise.reject(new Error("Invalid file type"));const m=l.map(async b=>{let z=b;return b.type.startsWith("image/")&&(z=await Z.compressImageIfNeeded(b)),new Promise((M,D)=>{const F=new FileReader;F.readAsDataURL(z),F.onload=async()=>{M({file:F.result,folderId:void 0,name:b.name,optimize:i})},F.onerror=()=>D(null)})}),x=await Promise.all(m),y=await o(x);return(y==null?void 0:y.length)===1&&c(y[0]),y}catch(l){return Promise.reject(l)}},[o,i,c]),g=f=>{const l=[];let m=0;return f.forEach(x=>{x.size>Se?m++:l.push(x)}),m>0&&A.toast.error(`${m===1&&f.length===1?"File":m+(m===1?" file":" files")} exceed the maximum size limit of 10MB.`),L.isEmpty(l)?[]:N(l)},{getRootProps:w,getInputProps:S,isDragActive:C}=he.useDropzone({onDrop:g,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||s,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${v?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...w(),className:X.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",v?"items-start":"items-center",C?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...S()}),v?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(p.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:n?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:["Please wait while we ",n?"update":"upload"," your file..."]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(p.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:"browse"})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:["Accepted file types: ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:["Optimization:"," ",e.jsx("span",{className:i?"text-indigo-600":"text-gray-400",children:i?"On":"Off"})]}),e.jsx(a.Switch,{checked:i,onCheckedChange:f=>{u(f)},onClick:f=>{f.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${i?"invisible":""}`,children:e.jsx(p.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsxs("p",{className:"text-xs text-white",children:["Warning: Unoptimized images may affect ",e.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function Ee({close:n,onSelect:r,mode:o="image",assetId:s}){const u=d.useMemo(()=>[o],[o]),[v,N]=d.useState(null),[g,w]=d.useState(null),[S,C]=d.useState(null),[f,l]=d.useState({show:!1,file:""}),[m,x]=d.useState(!1),[y,b]=d.useState(s?"details":"grid"),[z,M]=d.useState(""),[D,F]=d.useState(""),[q,P]=d.useState(1),[Q]=d.useState(30),[T,$]=d.useState([]);d.useEffect(()=>{s&&(N(s),b("details"))},[s]),d.useEffect(()=>{const t=setTimeout(()=>{M(D),P(1)},300);return()=>clearTimeout(t)},[D]);const{data:B,isLoading:O,refetch:J}=Ne({search:z.toLowerCase().trim(),page:q,limit:Q}),I=(B==null?void 0:B.assets)||[],Y=(B==null?void 0:B.total)||0,E=Math.ceil(Y/Q);d.useEffect(()=>{O||E<=0||P(t=>t>E?E:t<1?1:t)},[O,E]);const ee=(I==null?void 0:I.length)>0,{mutate:te}=je(),{mutateAsync:G,isPending:se}=ge(),{mutate:R,isPending:ie}=ve(),W=d.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,E));h!==q&&P(h)},[E,q]),re=t=>{F(t.target.value)},ae=d.useCallback(t=>{$(h=>L.find(h,{id:t.id})?[]:[t])},[!1]),le=d.useCallback(()=>{$([])},[]),_=t=>{(t==null?void 0:t.length)!==0&&(r(L.pick(L.first(t||T),["id","url","width","height","description"])),n())},ne=async t=>{w(t)},oe=async()=>{g&&(C(g==null?void 0:g.id),await te(g.id,{onSuccess:()=>{C(null),w(null)},onError:()=>{C(null)}}),w(null))},ce=t=>{N(t.id),b("details")},de=async(t,h)=>{try{const U=localStorage.getItem("chai_optimize_images")!=="false";h?(await G([{file:t,folderId:void 0,name:f.name||"",optimize:U}]),l({show:!1,file:""})):(await R({id:f.id||"",file:t}),l({show:!1,file:""}))}catch(U){console.error("Error saving edited image:",U)}},ue=d.useCallback(t=>{$([t])},[]),me=d.useCallback(t=>{W(t)},[W]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Te,{maxFileSize:10,allowedTypes:u,uploadAssets:G,isUpdatingAsset:ie,isUploadingAsset:se,onUploaded:ue}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(p.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${D.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:"Search assets...",onChange:re,value:D,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>le(),title:"Clear selection",children:"Clear"})}),e.jsx(a.Button,{size:"sm",onClick:()=>_(T),disabled:T.length===0,children:"Select Asset"})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>J(),children:e.jsx(p.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:O?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!O&&!ee?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(p.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:"No assets found"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:z.length>0?"No assets found for your search: "+z:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:I==null?void 0:I.map(t=>e.jsxs("div",{className:X.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",S&&(g==null?void 0:g.id)===t.id?"pointer-events-none opacity-50":"",S===t.id?"pointer-events-none opacity-50":""),onClick:()=>ae(t),onDoubleClick:()=>_([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[S===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(p.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Z.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(p.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"View Details"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),A.toast.success("Asset URL copied to clipboard")},children:e.jsx(p.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Copy URL"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),l({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(p.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Edit Image"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ne(t)},children:e.jsx(p.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Delete Asset"})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(p.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),E>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(fe,{fallback:e.jsx("div",{className:"text-red-500",children:"Error loading pagination"}),children:e.jsx(ye,{currentPage:q,totalPages:E,onPageChange:me,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(Ce,{assetId:v||s||"",onBack:()=>{b("grid"),N(null)},onEdit:t=>{l({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(v){x(!0);try{const h=I.find(U=>U.id===v);h&&await R(L.merge(h,{description:t}))}finally{x(!1)}}},isSaving:m})]}),f.show&&e.jsx(d.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ae,{imageUrl:f.file,onSave:de,onClose:()=>l({show:!1,file:""}),defaultSavedImageName:f.name,isEditing:!!f.id})}),g&&e.jsx(a.Dialog,{open:!!g,onOpenChange:()=>w(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Asset"}),e.jsxs(a.DialogDescription,{children:['Are you sure you want to delete "',g.name,'"? This action cannot be undone.']})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=Ee;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),X=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),L=require("lodash-es"),p=require("lucide-react"),d=require("react"),he=require("react-dropzone"),A=require("sonner"),Z=require("./image-compression-DZ9WMmyn.cjs"),k=require("@tanstack/react-query"),j=require("./index-CffopOpP.cjs"),xe=d.createContext(null),K={didCatch:!1,error:null};class fe extends d.Component{constructor(r){super(r),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=K}static getDerivedStateFromError(r){return{didCatch:!0,error:r}}resetErrorBoundary(){const{error:r}=this.state;if(r!==null){for(var o,s,c=arguments.length,i=new Array(c),u=0;u<c;u++)i[u]=arguments[u];(o=(s=this.props).onReset)===null||o===void 0||o.call(s,{args:i,reason:"imperative-api"}),this.setState(K)}}componentDidCatch(r,o){var s,c;(s=(c=this.props).onError)===null||s===void 0||s.call(c,r,o)}componentDidUpdate(r,o){const{didCatch:s}=this.state,{resetKeys:c}=this.props;if(s&&o.error!==null&&pe(r.resetKeys,c)){var i,u;(i=(u=this.props).onReset)===null||i===void 0||i.call(u,{next:c,prev:r.resetKeys,reason:"keys"}),this.setState(K)}}render(){const{children:r,fallbackRender:o,FallbackComponent:s,fallback:c}=this.props,{didCatch:i,error:u}=this.state;let v=r;if(i){const N={error:u,resetErrorBoundary:this.resetErrorBoundary};if(typeof o=="function")v=o(N);else if(s)v=d.createElement(s,N);else if(c!==void 0)v=c;else throw u}return d.createElement(xe.Provider,{value:{didCatch:i,error:u,resetErrorBoundary:this.resetErrorBoundary}},v)}}function pe(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return n.length!==r.length||n.some((o,s)=>!Object.is(o,r[s]))}const ge=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>{const c=s.map(async u=>o(n,{action:j.ACTIONS.UPLOAD_ASSET,data:u}));return await Promise.all(c)},onSuccess:s=>{var c;if(s!=null&&s.some(i=>i.error))throw new Error(((c=s==null?void 0:s.find(i=>i.error))==null?void 0:c.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]});const i=s==null?void 0:s.length;A.toast.success(`${i===1?"Asset":i+" Assets"} uploaded successfully`)}},onError:()=>{A.toast.error("Failed to upload asset")}})},je=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset deleted successfully")},onError:()=>{A.toast.error("Failed to delete asset")}})},ve=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset updated successfully")},onError:()=>{A.toast.error("Failed to update asset")}})};function ye({currentPage:n,totalPages:r,onPageChange:o,pageRangeDisplayed:s=3,showPageInput:c=!0,className:i=""}){const[u,v]=d.useState(String(n)),N=d.useMemo(()=>{const l=Math.floor(s/2);let m=Math.max(1,n-l),x=Math.min(r,n+l);x-m+1<s&&(m===1?x=Math.min(r,m+s-1):x===r&&(m=Math.max(1,x-s+1)));const y=[];m>1&&(y.push(1),m>2&&y.push("..."));for(let b=m;b<=x;b++)y.push(b);return x<r&&(x<r-1&&y.push("..."),y.push(r)),y},[n,r,s]),g=l=>{l!==n&&l>=1&&l<=r&&(o(l),v(String(l)))},w=()=>{n>1&&g(n-1)},S=()=>{n<r&&g(n+1)},C=()=>{const l=Number(u);!isNaN(l)&&l>=1&&l<=r&&g(l)},f=l=>{l.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${i}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:w,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(p.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((l,m)=>{if(l==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const x=l,y=x===n;return e.jsx(a.Button,{variant:y?"default":"outline",size:"sm",onClick:()=>g(x),className:y?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:x},x)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:S,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(p.ChevronRight,{className:" h-4 w-4"})]})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:u,onChange:l=>{const m=l.target.value.replace(/[^\d]/g,"");v(m)},onKeyDown:f,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:u===""||Number(u)<1||Number(u)>r,children:"Go"})]})]})}const Ne=(n={})=>{const r=j.useAssetsApiUrl(),o=j.useFetch(),{search:s,page:c=1,limit:i=30}=n;return k.useQuery({queryKey:[j.ACTIONS.GET_ASSETS,s,c,i],queryFn:async()=>{const u=await o(r,{action:j.ACTIONS.GET_ASSETS,data:{search:s,page:c,limit:i}});return u.page=c,u.limit=i,u},staleTime:1/0,retry:1})},be=n=>{const r=j.useAssetsApiUrl(),o=j.useFetch();return k.useQuery({queryKey:[j.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await o(r,{action:j.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function we(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function V(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function H(n,r){let o=n,s=r==null?void 0:r.description;return(!s||typeof s!="string")&&(s=""),(!o||typeof o!="string")&&(o=""),o!==s}const Ce=({assetId:n,onBack:r,onEdit:o,onSave:s,isSaving:c})=>{var S,C,f;const{data:i,isLoading:u,isError:v}=be(n||""),[N,g]=d.useState(""),w=async(l,m)=>{try{await navigator.clipboard.writeText(l),A.toast.success(`${m} copied to clipboard`)}catch(x){A.toast.error(`Failed to copy ${m}`,{description:x==null?void 0:x.message})}};return d.useEffect(()=>{i!=null&&i.description&&g(i.description)},[i]),u?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}):v||!(i!=null&&i.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(p.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:v?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed."}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:"Back to Assets"}),v&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:c,children:[e.jsx(p.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:c,children:"Cancel"}),e.jsxs(a.Button,{variant:"outline",onClick:()=>w(i.url,"Asset URL"),disabled:c,children:[e.jsx(p.Copy,{className:"h-4 w-4 mr-2"}),"Copy URL"]}),e.jsxs(a.Button,{variant:"default",onClick:()=>o(i),disabled:c,children:[e.jsx(p.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:`${i.url}?v=${((S=i.metadata)==null?void 0:S.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Details"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((C=i.metadata)==null?void 0:C.format)||i.type,capitalize:!0},{label:"Size",value:we(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:V(i.createdAt)},{label:"Updated",value:V(((f=i.metadata)==null?void 0:f.updatedAt)||i.createdAt)},{label:"URL",value:i.url,copyable:!0}].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:l.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(l.capitalize?" capitalize":""),children:l.value}),l.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>w(l.value,l.label),children:e.jsx(p.Link,{className:"h-3 w-3"})})]})]},l.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:"Used On"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((l,m)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:l.name}),e.jsxs("div",{className:"text-gray-500",children:["(",l.slug,")"]})]},m))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Description"}),e.jsx(a.Textarea,{id:"description",value:N,placeholder:"Enter a description for the asset",onChange:l=>g(l.target.value),rows:3,disabled:c,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>s(N),disabled:c||!H(N,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${c||!H(N,i)?"opacity-50 cursor-not-allowed":""}`,children:c?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},Ae=d.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs"))),Se=25*1024*1024,Te=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:o,isUploadingAsset:s,onUploaded:c})=>{const[i,u]=d.useState(()=>{const f=localStorage.getItem("chai_optimize_images");return f!==null?f==="true":!0});d.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const v=n||s,N=d.useCallback(async f=>{try{const l=f;if(!l.every(b=>b.type.startsWith("image/")))return A.toast.error("Invalid file type. Please upload a valid file."),Promise.reject(new Error("Invalid file type"));const m=l.map(async b=>{let z=b;return b.type.startsWith("image/")&&(z=await Z.compressImageIfNeeded(b)),new Promise((M,D)=>{const F=new FileReader;F.readAsDataURL(z),F.onload=async()=>{M({file:F.result,folderId:void 0,name:b.name,optimize:i})},F.onerror=()=>D(null)})}),x=await Promise.all(m),y=await o(x);return(y==null?void 0:y.length)===1&&c(y[0]),y}catch(l){return Promise.reject(l)}},[o,i,c]),g=f=>{const l=[];let m=0;return f.forEach(x=>{x.size>Se?m++:l.push(x)}),m>0&&A.toast.error(`${m===1&&f.length===1?"File":m+(m===1?" file":" files")} exceed the maximum size limit of 10MB.`),L.isEmpty(l)?[]:N(l)},{getRootProps:w,getInputProps:S,isDragActive:C}=he.useDropzone({onDrop:g,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||s,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${v?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...w(),className:X.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",v?"items-start":"items-center",C?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...S()}),v?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(p.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:n?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:["Please wait while we ",n?"update":"upload"," your file..."]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(p.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:"browse"})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:["Accepted file types: ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:["Optimization:"," ",e.jsx("span",{className:i?"text-indigo-600":"text-gray-400",children:i?"On":"Off"})]}),e.jsx(a.Switch,{checked:i,onCheckedChange:f=>{u(f)},onClick:f=>{f.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${i?"invisible":""}`,children:e.jsx(p.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsxs("p",{className:"text-xs text-white",children:["Warning: Unoptimized images may affect ",e.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function Ee({close:n,onSelect:r,mode:o="image",assetId:s}){const u=d.useMemo(()=>[o],[o]),[v,N]=d.useState(null),[g,w]=d.useState(null),[S,C]=d.useState(null),[f,l]=d.useState({show:!1,file:""}),[m,x]=d.useState(!1),[y,b]=d.useState(s?"details":"grid"),[z,M]=d.useState(""),[D,F]=d.useState(""),[q,P]=d.useState(1),[Q]=d.useState(30),[T,$]=d.useState([]);d.useEffect(()=>{s&&(N(s),b("details"))},[s]),d.useEffect(()=>{const t=setTimeout(()=>{M(D),P(1)},300);return()=>clearTimeout(t)},[D]);const{data:B,isLoading:O,refetch:J}=Ne({search:z.toLowerCase().trim(),page:q,limit:Q}),I=(B==null?void 0:B.assets)||[],Y=(B==null?void 0:B.total)||0,E=Math.ceil(Y/Q);d.useEffect(()=>{O||E<=0||P(t=>t>E?E:t<1?1:t)},[O,E]);const ee=(I==null?void 0:I.length)>0,{mutate:te}=je(),{mutateAsync:G,isPending:se}=ge(),{mutate:R,isPending:ie}=ve(),W=d.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,E));h!==q&&P(h)},[E,q]),re=t=>{F(t.target.value)},ae=d.useCallback(t=>{$(h=>L.find(h,{id:t.id})?[]:[t])},[!1]),le=d.useCallback(()=>{$([])},[]),_=t=>{(t==null?void 0:t.length)!==0&&(r(L.pick(L.first(t||T),["id","url","width","height","description"])),n())},ne=async t=>{w(t)},oe=async()=>{g&&(C(g==null?void 0:g.id),await te(g.id,{onSuccess:()=>{C(null),w(null)},onError:()=>{C(null)}}),w(null))},ce=t=>{N(t.id),b("details")},de=async(t,h)=>{try{const U=localStorage.getItem("chai_optimize_images")!=="false";h?(await G([{file:t,folderId:void 0,name:f.name||"",optimize:U}]),l({show:!1,file:""})):(await R({id:f.id||"",file:t}),l({show:!1,file:""}))}catch(U){console.error("Error saving edited image:",U)}},ue=d.useCallback(t=>{$([t])},[]),me=d.useCallback(t=>{W(t)},[W]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Te,{maxFileSize:10,allowedTypes:u,uploadAssets:G,isUpdatingAsset:ie,isUploadingAsset:se,onUploaded:ue}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(p.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${D.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:"Search assets...",onChange:re,value:D,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>le(),title:"Clear selection",children:"Clear"})}),e.jsx(a.Button,{size:"sm",onClick:()=>_(T),disabled:T.length===0,children:"Select Asset"})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>J(),children:e.jsx(p.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:O?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!O&&!ee?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(p.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:"No assets found"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:z.length>0?"No assets found for your search: "+z:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:I==null?void 0:I.map(t=>e.jsxs("div",{className:X.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",S&&(g==null?void 0:g.id)===t.id?"pointer-events-none opacity-50":"",S===t.id?"pointer-events-none opacity-50":""),onClick:()=>ae(t),onDoubleClick:()=>_([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[S===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(p.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Z.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(p.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"View Details"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),A.toast.success("Asset URL copied to clipboard")},children:e.jsx(p.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Copy URL"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),l({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(p.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Edit Image"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ne(t)},children:e.jsx(p.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Delete Asset"})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(p.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),E>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(fe,{fallback:e.jsx("div",{className:"text-red-500",children:"Error loading pagination"}),children:e.jsx(ye,{currentPage:q,totalPages:E,onPageChange:me,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(Ce,{assetId:v||s||"",onBack:()=>{b("grid"),N(null)},onEdit:t=>{l({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(v){x(!0);try{const h=I.find(U=>U.id===v);h&&await R(L.merge(h,{description:t}))}finally{x(!1)}}},isSaving:m})]}),f.show&&e.jsx(d.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ae,{imageUrl:f.file,onSave:de,onClose:()=>l({show:!1,file:""}),defaultSavedImageName:f.name,isEditing:!!f.id})}),g&&e.jsx(a.Dialog,{open:!!g,onOpenChange:()=>w(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Asset"}),e.jsxs(a.DialogDescription,{children:['Are you sure you want to delete "',g.name,'"? This action cannot be undone.']})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=Ee;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-CffopOpP.cjs"),S=require("@tanstack/react-query"),N=require("sonner"),a=require("@chaibuilder/sdk/ui"),v=require("lodash-es"),E=require("lucide-react"),g=require("react"),q=require("./slug-input-B4w0Ihxn.cjs"),C=()=>{const t=p.useApiUrl(),r=S.useQueryClient(),h=p.useFetch();return S.useMutation({mutationFn:async({pageId:c,name:u,slug:o})=>{const s={pageId:c,name:u};return o&&(s.slug=o),await h(t,{action:"DUPLICATE_PAGE",data:s})},onSuccess:()=>{r.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),N.toast.success("Page duplicated successfully")},onError:c=>{N.toast.error("Failed to duplicate page",{description:c.message||"An error occurred while duplicating the page"})}})},A=({page:t,onClose:r,closePanel:h=()=>{}})=>{const{mutate:c,isPending:u}=C(),[o,s]=g.useState(null),[d,P]=g.useState(`${t.name} (Copy)`),D=p.useChangePage(),i=v.isEmpty(t.slug),[m,b]=g.useState(i?"":`${t.slug.split("/").pop()}-copy`),j=i?"":v.initial(t.slug.split("/")).join("/"),[f,x]=g.useState(!1),I=n=>{if(n.preventDefault(),!d.trim()){s("Name is required");return}if(!i&&!m.trim()){s("Slug is required");return}s(null),x(!0);const y={pageId:t.id,name:d};i||(y.slug=`${j}/${m}`),c(y,{onSuccess:l=>{x(!1),r(),D(l.id,h)},onError:l=>{x(!1),l.code==="SLUG_EXISTS"?s("A page with this slug already exists. Please choose a different slug."):l.code==="INVALID_SLUG"?s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens."):l.code==="PERMISSION_DENIED"?s("You don't have permission to duplicate this page."):s(l.message||"Failed to duplicate page. Please try again later.")}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Duplicate Page"}),e.jsx(a.DialogDescription,{children:"Create a copy of the page with a new name and slug"})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsx("h3",{className:"mb-1 text-sm font-medium",children:"Duplicating:"}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Name:"})," ",t.name]}),!i&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Slug:"})," ",t.slug]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Type:"})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:I,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(a.Input,{id:"name",value:d,onChange:n=>P(n.target.value),required:!0})]}),!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx(q.SlugInput,{value:m,onChange:n=>b(n),parentSlug:j,onValidationChange:n=>{s(n?null:"Invalid slug")}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(E.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:r,disabled:u,children:"Cancel"}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!i&&!m.trim()||u||f,children:u||f?"Duplicating...":"Duplicate"})]})]})]})})};exports.default=A;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { al as b, am as C, A, an as T } from "./index-CguzNa4U.js";
|
|
3
3
|
import { useQueryClient as w, useMutation as F } from "@tanstack/react-query";
|
|
4
4
|
import { toast as S } from "sonner";
|
|
5
|
-
import { Dialog as _, DialogContent as
|
|
6
|
-
import { isEmpty as O, initial as
|
|
7
|
-
import { AlertCircle as
|
|
5
|
+
import { Dialog as _, DialogContent as q, DialogHeader as G, DialogTitle as L, DialogDescription as U, Label as v, Input as j, Alert as $, Button as D } from "@chaibuilder/sdk/ui";
|
|
6
|
+
import { isEmpty as O, initial as B } from "lodash-es";
|
|
7
|
+
import { AlertCircle as M } from "lucide-react";
|
|
8
8
|
import { useState as p } from "react";
|
|
9
|
-
import { S as
|
|
10
|
-
const
|
|
9
|
+
import { S as Q } from "./slug-input-BXNj3cZf.js";
|
|
10
|
+
const V = () => {
|
|
11
11
|
const t = b(), r = w(), g = C();
|
|
12
12
|
return F({
|
|
13
13
|
mutationFn: async ({ pageId: c, name: o, slug: u }) => {
|
|
@@ -37,7 +37,7 @@ const Q = () => {
|
|
|
37
37
|
closePanel: g = () => {
|
|
38
38
|
}
|
|
39
39
|
}) => {
|
|
40
|
-
const { mutate: c, isPending: o } =
|
|
40
|
+
const { mutate: c, isPending: o } = V(), [u, a] = p(null), [m, P] = p(`${t.name} (Copy)`), x = T(), i = O(t.slug), [d, I] = p(i ? "" : `${t.slug.split("/").pop()}-copy`), f = i ? "" : B(t.slug.split("/")).join("/"), [y, h] = p(!1), E = (l) => {
|
|
41
41
|
if (l.preventDefault(), !m.trim()) {
|
|
42
42
|
a("Name is required");
|
|
43
43
|
return;
|
|
@@ -60,10 +60,10 @@ const Q = () => {
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
-
return /* @__PURE__ */ e(_, { open: !!t, onOpenChange: r, children: /* @__PURE__ */ s(
|
|
64
|
-
/* @__PURE__ */ s(
|
|
65
|
-
/* @__PURE__ */ e(
|
|
66
|
-
/* @__PURE__ */ e(
|
|
63
|
+
return /* @__PURE__ */ e(_, { open: !!t, onOpenChange: r, children: /* @__PURE__ */ s(q, { className: "sm:max-w-[425px]", children: [
|
|
64
|
+
/* @__PURE__ */ s(G, { children: [
|
|
65
|
+
/* @__PURE__ */ e(L, { children: "Duplicate Page" }),
|
|
66
|
+
/* @__PURE__ */ e(U, { children: "Create a copy of the page with a new name and slug" })
|
|
67
67
|
] }),
|
|
68
68
|
/* @__PURE__ */ s("div", { className: "mb-4 rounded-md bg-gray-50 p-3", children: [
|
|
69
69
|
/* @__PURE__ */ e("h3", { className: "mb-1 text-sm font-medium", children: "Duplicating:" }),
|
|
@@ -88,12 +88,12 @@ const Q = () => {
|
|
|
88
88
|
/* @__PURE__ */ s("form", { onSubmit: E, className: "space-y-4", children: [
|
|
89
89
|
/* @__PURE__ */ s("div", { className: "space-y-2", children: [
|
|
90
90
|
/* @__PURE__ */ e(v, { htmlFor: "name", className: "text-sm", children: "Name" }),
|
|
91
|
-
/* @__PURE__ */ e(
|
|
91
|
+
/* @__PURE__ */ e(j, { id: "name", value: m, onChange: (l) => P(l.target.value), required: !0 })
|
|
92
92
|
] }),
|
|
93
93
|
!i && /* @__PURE__ */ s("div", { className: "space-y-2", children: [
|
|
94
94
|
/* @__PURE__ */ e(v, { htmlFor: "slug", className: "text-sm", children: "Slug" }),
|
|
95
95
|
/* @__PURE__ */ e(
|
|
96
|
-
|
|
96
|
+
Q,
|
|
97
97
|
{
|
|
98
98
|
value: d,
|
|
99
99
|
onChange: (l) => I(l),
|
|
@@ -105,7 +105,7 @@ const Q = () => {
|
|
|
105
105
|
)
|
|
106
106
|
] }),
|
|
107
107
|
u && /* @__PURE__ */ s($, { variant: "destructive", className: "py-2", children: [
|
|
108
|
-
/* @__PURE__ */ e(
|
|
108
|
+
/* @__PURE__ */ e(M, { className: "h-4 w-4" }),
|
|
109
109
|
/* @__PURE__ */ e("span", { className: "text-sm", children: u })
|
|
110
110
|
] }),
|
|
111
111
|
/* @__PURE__ */ s("div", { className: "flex justify-end gap-2", children: [
|
|
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
|
|
|
4
4
|
import { get as v } from "lodash-es";
|
|
5
5
|
import { ChevronDown as w } from "lucide-react";
|
|
6
6
|
import { useRef as b, useEffect as N } from "react";
|
|
7
|
-
import { k as y } from "./index-
|
|
7
|
+
import { k as y } from "./index-CguzNa4U.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-CffopOpP.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
|