@chaibuilder/pages 0.15.5 → 0.15.7
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-D4uLyw6-.cjs → 2AITGKQY-BGvx_OEz.cjs} +1 -1
- package/dist/{2AITGKQY-DYwNjBFe.js → 2AITGKQY-CCad8XK8.js} +2 -2
- package/dist/{NCMVHL6D-C-L7-X3f.cjs → NCMVHL6D-C_u5lHQe.cjs} +1 -1
- package/dist/{NCMVHL6D-DVB60g_2.js → NCMVHL6D-Iv9ufIUy.js} +2 -2
- package/dist/{ZDWCUMSJ-BORULBXb.cjs → ZDWCUMSJ-BqZPKNlU.cjs} +1 -1
- package/dist/{ZDWCUMSJ-Dp6ML_tn.js → ZDWCUMSJ-DT4dg62a.js} +1 -1
- package/dist/add-new-language-page-CfH8Ernl.js +401 -0
- package/dist/add-new-language-page-DlQjzp--.cjs +1 -0
- package/dist/add-new-page-DH-nv7ae.cjs +1 -0
- package/dist/add-new-page-DX1aQA56.js +31 -0
- package/dist/delete-page-DE-nabXs.js +40 -0
- package/dist/delete-page-WPGzECyJ.cjs +1 -0
- package/dist/digital-asset-manager-CGLE6VEW.cjs +1 -0
- package/dist/digital-asset-manager-DtWIJGhf.js +913 -0
- package/dist/duplicate-page-C1r3iBDY.js +133 -0
- package/dist/duplicate-page-CByLwz0z.cjs +1 -0
- package/dist/{dynamic-page-selector-8g1-84iW.js → dynamic-page-selector-Bk8_xgFx.js} +1 -1
- package/dist/{dynamic-page-selector-Cz6zWaKo.cjs → dynamic-page-selector-GwGV0Q6Z.cjs} +1 -1
- package/dist/image-editor-CeSSNbFY.js +108 -0
- package/dist/image-editor-CnDnY97s.cjs +1 -0
- package/dist/index-BELYt0c9.cjs +5 -0
- package/dist/{index-zaGKeGBW.js → index-Djepisz3.js} +1168 -1219
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/{json-diff-viewer-c3ft4c4A.cjs → json-diff-viewer-BUhKwjf9.cjs} +1 -1
- package/dist/{json-diff-viewer-BF0qFBif.js → json-diff-viewer-zKpzQFxw.js} +1 -1
- package/dist/lang-panel-BYF6aLAt.cjs +1 -0
- package/dist/lang-panel-CtpuO-KH.js +225 -0
- package/dist/mark-as-template-0kikl0oL.js +153 -0
- package/dist/mark-as-template-wRAGJGtp.cjs +1 -0
- package/dist/no-language-page-content-B1M_x_U7.js +42 -0
- package/dist/no-language-page-content-DX9WXKXs.cjs +1 -0
- package/dist/{page-creator-Crc5BzeB.js → page-creator-BDJ6iDX9.js} +2 -2
- package/dist/{page-creator-CsZpQ7Gy.cjs → page-creator-DuN5JD41.cjs} +1 -1
- package/dist/page-lock-request-Bc_vwJhy.js +75 -0
- package/dist/page-lock-request-PRQo0DDm.cjs +1 -0
- package/dist/page-locked-by-dialog-DiKNpVwH.js +68 -0
- package/dist/page-locked-by-dialog-Dk0G2l7a.cjs +1 -0
- package/dist/page-manager-new-CUHqC9Og.js +354 -0
- package/dist/page-manager-new-KBhn93Yd.cjs +1 -0
- package/dist/page-manager-search-and-filter-CJ4AK1_7.js +201 -0
- package/dist/page-manager-search-and-filter-Ck5_TfNx.cjs +1 -0
- package/dist/{page-revisions-content-dSFvGFEO.cjs → page-revisions-content-Cw2cumYS.cjs} +1 -1
- package/dist/{page-revisions-content-PRgwV04S.js → page-revisions-content-q1Ch2-IQ.js} +18 -18
- package/dist/{publish-pages-content-akIgltlm.cjs → publish-pages-content-B8Uuw29Q.cjs} +1 -1
- package/dist/{publish-pages-content-C24iBibw.js → publish-pages-content-DEHD8qkl.js} +6 -6
- package/dist/{save-to-lib-C3H1ZPb-.cjs → save-to-lib-B83ZH4XX.cjs} +1 -1
- package/dist/{save-to-lib-DSPvtFSd.js → save-to-lib-QEOpf_Bd.js} +1 -1
- package/dist/{seo-panel-rZ8s88c0.js → seo-panel-DEQfOfZs.js} +17 -17
- package/dist/{seo-panel-Ce6aTIyt.cjs → seo-panel-DvDEatlO.cjs} +1 -1
- package/dist/{shared-json-ld-DMYOwp6B.js → shared-json-ld-Cyv9JitF.js} +26 -25
- package/dist/{shared-json-ld-hCiviuBf.cjs → shared-json-ld-D5F8RuF2.cjs} +1 -1
- package/dist/{slug-input-BN8eQgxP.cjs → slug-input-3vWL9FPC.cjs} +1 -1
- package/dist/{slug-input-Dhzaobv6.js → slug-input-D4e2anEs.js} +1 -1
- package/dist/theme-panel-footer-4dbLfEph.cjs +1 -0
- package/dist/theme-panel-footer-D3Gub87c.js +25 -0
- package/dist/unmark-as-template-BENGNo7g.js +39 -0
- package/dist/unmark-as-template-Dkc7zLZr.cjs +1 -0
- package/dist/unpublish-page-Cui0tgvd.cjs +1 -0
- package/dist/unpublish-page-D5tWKVLY.js +27 -0
- package/dist/{web-preview-BEyjKFDL.js → web-preview-CHNZZcqH.js} +1 -1
- package/dist/{web-preview-TTKtpSUi.cjs → web-preview-CcPTcMio.cjs} +1 -1
- package/package.json +3 -3
- package/dist/add-new-language-page-D4VPifNs.cjs +0 -1
- package/dist/add-new-language-page-DENCjC_f.js +0 -390
- package/dist/add-new-page-BuK6We-q.cjs +0 -1
- package/dist/add-new-page-CD-9ppdS.js +0 -30
- package/dist/delete-page-B-TP6nJ7.cjs +0 -1
- package/dist/delete-page-CatRlDfx.js +0 -38
- package/dist/digital-asset-manager-DL2nAqUC.cjs +0 -1
- package/dist/digital-asset-manager-KakxBkBC.js +0 -917
- package/dist/duplicate-page-D4Oiy71Q.cjs +0 -1
- package/dist/duplicate-page-DEmh0df0.js +0 -120
- package/dist/image-editor-D9MPdtxC.js +0 -107
- package/dist/image-editor-Da6lrqkL.cjs +0 -1
- package/dist/index-Blg1T7nL.cjs +0 -5
- package/dist/lang-panel-D1FKTNui.js +0 -218
- package/dist/lang-panel-ExS97Zgk.cjs +0 -1
- package/dist/mark-as-template-CcnkROAU.cjs +0 -1
- package/dist/mark-as-template-v-I05xcZ.js +0 -146
- package/dist/no-language-page-content-Bm5CcsUo.js +0 -35
- package/dist/no-language-page-content-Ddz2hnYs.cjs +0 -1
- package/dist/page-lock-request-Dx6OrOwM.cjs +0 -1
- package/dist/page-lock-request-WKfG7Sd3.js +0 -64
- package/dist/page-locked-by-dialog-BvdAXZPw.cjs +0 -1
- package/dist/page-locked-by-dialog-jy3lYV3l.js +0 -63
- package/dist/page-manager-new-CNHlSwfe.js +0 -354
- package/dist/page-manager-new-CUlpwqpH.cjs +0 -1
- package/dist/page-manager-search-and-filter-CuAn82Db.js +0 -197
- package/dist/page-manager-search-and-filter-eFsGtm5W.cjs +0 -1
- package/dist/theme-panel-footer-0GrdOHO_.cjs +0 -1
- package/dist/theme-panel-footer-BzEy5bsg.js +0 -25
- package/dist/unmark-as-template-DXEs6foh.cjs +0 -1
- package/dist/unmark-as-template-Dsiyocm9.js +0 -38
- package/dist/unpublish-page-c1mqQEa_.cjs +0 -1
- package/dist/unpublish-page-yGyz2jiw.js +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-BELYt0c9.cjs"),m=[{title:"mobile_xs_title",content:"mobile_xs_content",icon:e.jsx(n.Smartphone,{className:"h-4 w-4"}),width:400},{title:"tablet_md_title",content:"tablet_md_content",icon:e.jsx(n.Tablet,{className:"h-4 w-4"}),width:800},{title:"desktop_xl_title",content:"desktop_xl_content",icon:e.jsx(n.Laptop,{className:"h-4 w-4"}),width:1200},{title:"large_desktop_2xl_title",content:"large_desktop_2xl_content",icon:e.jsx(n.LaptopMinimal,{className:"h-4 w-4"}),width:1600}],w=({currentWidth:t,width:s,icon:l,setIframeWidth:i})=>e.jsx(a.Button,{className:"px-3 py-3",onClick:()=>i(s),variant:s===t?"default":"ghost",children:l}),p=()=>{const[t,s]=o.useState(1200),l=r=>s(r),[i,d]=h.useAtom(c.previewUrlAtom);if(!i)return null;const u=()=>{d("")};return e.jsxs("div",{className:"absolute inset-0 z-[999999] flex h-screen w-screen flex-col overflow-hidden bg-gray-100",children:[e.jsxs("div",{className:"flex h-[50px] items-center justify-center border-b border-gray-200 px-4 shadow-sm",children:[e.jsx("div",{className:"flex items-center justify-center rounded-md border border-gray-300",children:x.map(m,r=>o.createElement(w,{...r,setIframeWidth:l,key:r.title,currentWidth:t}))})," ",e.jsx(c.Tooltip,{content:"Exit Preview",delayDuration:0,children:e.jsx(a.Button,{variant:"destructive",size:"sm",onClick:u,children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M2 3C2 2.44772 2.44772 2 3 2H12C12.5523 2 13 2.44772 13 3V12C13 12.5523 12.5523 13 12 13H3C2.44772 13 2 12.5523 2 12V3ZM12 3H3V12H12V3Z",fill:"currentColor","fill-rule":"evenodd","clip-rule":"evenodd"})})})})]}),e.jsx("iframe",{style:{width:`${t}px`,transition:"width 0.3s ease-in-out"},className:"no-scrollbar mx-auto h-full overflow-y-auto border bg-white",src:i})]})};exports.default=p;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Suraj Air",
|
|
4
4
|
"license": "Private",
|
|
5
5
|
"homepage": "https://chaibuilder.com",
|
|
6
|
-
"version": "0.15.
|
|
6
|
+
"version": "0.15.7",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@chaibuilder/runtime": "2.2.0",
|
|
68
|
-
"@chaibuilder/sdk": "3.0.
|
|
68
|
+
"@chaibuilder/sdk": "3.0.10",
|
|
69
69
|
"@types/react": "*",
|
|
70
70
|
"@types/react-dom": "*",
|
|
71
71
|
"jotai": "2.14.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@chaibuilder/runtime": "2.2.0",
|
|
85
|
-
"@chaibuilder/sdk": "3.0.
|
|
85
|
+
"@chaibuilder/sdk": "3.0.10",
|
|
86
86
|
"@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
|
|
87
87
|
"@radix-ui/react-icons": "^1.3.2",
|
|
88
88
|
"@supabase/supabase-js": "2.50.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("./slug-input-BN8eQgxP.cjs"),t=require("./index-Blg1T7nL.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,390 +0,0 @@
|
|
|
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-Dhzaobv6.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-zaGKeGBW.js";
|
|
4
|
-
import { useLanguages as vn, useSidebarActivePanel as Ln } from "@chaibuilder/sdk";
|
|
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
|
-
import { filter as $n, find as In, startsWith as Rn } from "lodash-es";
|
|
7
|
-
import { Loader as kn } from "lucide-react";
|
|
8
|
-
import { useMemo as F, useState as T, useEffect as Q } from "react";
|
|
9
|
-
const Z = ({
|
|
10
|
-
edit: u,
|
|
11
|
-
lang: r,
|
|
12
|
-
languages: l,
|
|
13
|
-
name: i,
|
|
14
|
-
setLang: e,
|
|
15
|
-
setName: c,
|
|
16
|
-
primaryPageObject: o
|
|
17
|
-
}) => /* @__PURE__ */ h("div", { className: "space-y-1", children: [
|
|
18
|
-
/* @__PURE__ */ t(k, { htmlFor: "lang", children: f.LANGUAGE }),
|
|
19
|
-
/* @__PURE__ */ h(
|
|
20
|
-
"select",
|
|
21
|
-
{
|
|
22
|
-
value: u ? "" : r,
|
|
23
|
-
disabled: u || !l.length,
|
|
24
|
-
onChange: (n) => {
|
|
25
|
-
const a = n.target.value;
|
|
26
|
-
e(a), !u && (Rn(i, o == null ? void 0 : o.name) || i.length === 0) && c(`${o == null ? void 0 : o.name} - ${L[a]}`);
|
|
27
|
-
},
|
|
28
|
-
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",
|
|
29
|
-
children: [
|
|
30
|
-
/* @__PURE__ */ t("option", { value: "", disabled: !0, children: u ? L[r] || r : l.length ? f.CHOOSE_LANGUAGE : f.ALL_AVAILABLE_LANGUAGE_PAGE }),
|
|
31
|
-
l.map((n) => /* @__PURE__ */ t("option", { value: n, children: L[n] || n }, n))
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
)
|
|
35
|
-
] }), b = ({ lang: u, name: r, setName: l, parentHasSelectedLanguagePage: i }) => /* @__PURE__ */ h("div", { className: "space-y-1", children: [
|
|
36
|
-
/* @__PURE__ */ t(k, { htmlFor: "name", children: f.PAGE_NAME }),
|
|
37
|
-
/* @__PURE__ */ t(
|
|
38
|
-
Tn,
|
|
39
|
-
{
|
|
40
|
-
id: "name",
|
|
41
|
-
value: u ? r : "",
|
|
42
|
-
onChange: (e) => l(e.target.value),
|
|
43
|
-
required: !0,
|
|
44
|
-
placeholder: u ? f.ENTER_PAGE_NAME : f.CHOOSE_LANGUAGE_TO_ADD_SLUG,
|
|
45
|
-
disabled: !i || !u
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
] }), Wn = ({
|
|
49
|
-
dynamic: u,
|
|
50
|
-
isNonSlugPageType: r,
|
|
51
|
-
isRootPage: l,
|
|
52
|
-
lang: i,
|
|
53
|
-
useLanguagePrefix: e,
|
|
54
|
-
setUseLanguagePrefix: c,
|
|
55
|
-
isHomePage: o,
|
|
56
|
-
parentSlug: n,
|
|
57
|
-
parentHasSelectedLanguagePage: a,
|
|
58
|
-
slug: A,
|
|
59
|
-
setSlug: d,
|
|
60
|
-
setIsSlugValid: E,
|
|
61
|
-
getSlug: N
|
|
62
|
-
}) => r ? null : /* @__PURE__ */ h("div", { className: "space-y-1", children: [
|
|
63
|
-
l && i && /* @__PURE__ */ h("div", { className: "flex items-center space-x-2 pb-1", children: [
|
|
64
|
-
/* @__PURE__ */ t(
|
|
65
|
-
"input",
|
|
66
|
-
{
|
|
67
|
-
type: "checkbox",
|
|
68
|
-
id: "useLanguagePrefix",
|
|
69
|
-
checked: e,
|
|
70
|
-
onChange: (S) => c(S.target.checked),
|
|
71
|
-
className: "rounded border-gray-300"
|
|
72
|
-
}
|
|
73
|
-
),
|
|
74
|
-
/* @__PURE__ */ h(k, { htmlFor: "useLanguagePrefix", className: "text-sm font-normal leading-tight", children: [
|
|
75
|
-
"Add language code (",
|
|
76
|
-
/* @__PURE__ */ h("span", { className: "font-mono text-gray-900", children: [
|
|
77
|
-
"/",
|
|
78
|
-
i
|
|
79
|
-
] }),
|
|
80
|
-
") as slug prefix"
|
|
81
|
-
] })
|
|
82
|
-
] }),
|
|
83
|
-
/* @__PURE__ */ t(k, { htmlFor: "slug", children: f.SLUG }),
|
|
84
|
-
u ? /* @__PURE__ */ t(X, { 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" }) : /* @__PURE__ */ t(
|
|
85
|
-
An,
|
|
86
|
-
{
|
|
87
|
-
disabled: !i || !a,
|
|
88
|
-
value: A,
|
|
89
|
-
onChange: d,
|
|
90
|
-
placeholder: i ? o && e ? "Leave empty for home page" : f.ENTER_PAGE_SLUG : f.CHOOSE_LANGUAGE_TO_ADD_SLUG,
|
|
91
|
-
parentSlug: n,
|
|
92
|
-
onValidationChange: E,
|
|
93
|
-
fullSlug: N()
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
] }), y = ({
|
|
97
|
-
parentHasSelectedLanguagePage: u,
|
|
98
|
-
name: r,
|
|
99
|
-
lang: l,
|
|
100
|
-
slug: i,
|
|
101
|
-
edit: e,
|
|
102
|
-
id: c,
|
|
103
|
-
primaryPageObject: o,
|
|
104
|
-
pages: n,
|
|
105
|
-
isNonSlugPageType: a,
|
|
106
|
-
isHomePage: A,
|
|
107
|
-
useLanguagePrefix: d,
|
|
108
|
-
isSlugValid: E,
|
|
109
|
-
isPending: N
|
|
110
|
-
}) => {
|
|
111
|
-
const S = N || !r || !l || n.some((m) => (e ? m.id !== c : !0) && m.parent === (o == null ? void 0 : o.id) && m.lang === l) || !a && !(A && d) && (!E || !i);
|
|
112
|
-
return /* @__PURE__ */ t(wn, { children: u ? /* @__PURE__ */ h(rn, { children: [
|
|
113
|
-
/* @__PURE__ */ t(Cn, { type: "submit", disabled: S && !o.dynamic, children: N ? /* @__PURE__ */ h("span", { className: "flex items-center gap-2", children: [
|
|
114
|
-
/* @__PURE__ */ t("span", { className: "loader mr-2" }),
|
|
115
|
-
e ? f.UPDATING : f.ADDING
|
|
116
|
-
] }) : e ? f.UPDATE : f.ADD_NEW_LANGUAGE }),
|
|
117
|
-
n.some(
|
|
118
|
-
(m) => (e ? m.id !== c : !0) && m.parent === (o == null ? void 0 : o.id) && m.lang === l
|
|
119
|
-
) && /* @__PURE__ */ t("p", { className: "mt-2 text-xs text-red-500", children: "A page for this language already exists." })
|
|
120
|
-
] }) : l && /* @__PURE__ */ t(X, { variant: "destructive", children: /* @__PURE__ */ h("p", { className: "mx-auto w-5/6 text-center", children: [
|
|
121
|
-
"You need to create the ",
|
|
122
|
-
/* @__PURE__ */ t("span", { className: "font-medium", children: L[l] }),
|
|
123
|
-
" page in the parent to add here."
|
|
124
|
-
] }) }) });
|
|
125
|
-
}, Bn = ({
|
|
126
|
-
onSubmit: u,
|
|
127
|
-
edit: r,
|
|
128
|
-
lang: l,
|
|
129
|
-
languages: i,
|
|
130
|
-
name: e,
|
|
131
|
-
setLang: c,
|
|
132
|
-
setName: o,
|
|
133
|
-
primaryPageObject: n,
|
|
134
|
-
parentHasSelectedLanguagePage: a,
|
|
135
|
-
id: A,
|
|
136
|
-
pages: d,
|
|
137
|
-
isNonSlugPageType: E,
|
|
138
|
-
isHomePage: N,
|
|
139
|
-
useLanguagePrefix: S,
|
|
140
|
-
slug: m,
|
|
141
|
-
isSlugValid: U,
|
|
142
|
-
isPending: g
|
|
143
|
-
}) => /* @__PURE__ */ h("form", { onSubmit: u, children: [
|
|
144
|
-
/* @__PURE__ */ h("div", { className: "grid gap-4 py-4", children: [
|
|
145
|
-
/* @__PURE__ */ t(
|
|
146
|
-
Z,
|
|
147
|
-
{
|
|
148
|
-
edit: r,
|
|
149
|
-
lang: l,
|
|
150
|
-
languages: i,
|
|
151
|
-
name: e,
|
|
152
|
-
setLang: c,
|
|
153
|
-
setName: o,
|
|
154
|
-
primaryPageObject: n
|
|
155
|
-
}
|
|
156
|
-
),
|
|
157
|
-
/* @__PURE__ */ t(
|
|
158
|
-
b,
|
|
159
|
-
{
|
|
160
|
-
lang: l,
|
|
161
|
-
name: e,
|
|
162
|
-
setName: o,
|
|
163
|
-
parentHasSelectedLanguagePage: a
|
|
164
|
-
}
|
|
165
|
-
)
|
|
166
|
-
] }),
|
|
167
|
-
/* @__PURE__ */ t(
|
|
168
|
-
y,
|
|
169
|
-
{
|
|
170
|
-
parentHasSelectedLanguagePage: a,
|
|
171
|
-
name: e,
|
|
172
|
-
lang: l,
|
|
173
|
-
slug: m,
|
|
174
|
-
edit: r,
|
|
175
|
-
id: A,
|
|
176
|
-
primaryPageObject: n,
|
|
177
|
-
pages: d,
|
|
178
|
-
isNonSlugPageType: E,
|
|
179
|
-
isHomePage: N,
|
|
180
|
-
useLanguagePrefix: S,
|
|
181
|
-
isSlugValid: U,
|
|
182
|
-
isPending: g
|
|
183
|
-
}
|
|
184
|
-
)
|
|
185
|
-
] }), Mn = ({
|
|
186
|
-
loading: u,
|
|
187
|
-
onSubmit: r,
|
|
188
|
-
edit: l,
|
|
189
|
-
lang: i,
|
|
190
|
-
languages: e,
|
|
191
|
-
name: c,
|
|
192
|
-
setLang: o,
|
|
193
|
-
setName: n,
|
|
194
|
-
primaryPageObject: a,
|
|
195
|
-
parentHasSelectedLanguagePage: A,
|
|
196
|
-
isNonSlugPageType: d,
|
|
197
|
-
isRootPage: E,
|
|
198
|
-
useLanguagePrefix: N,
|
|
199
|
-
setUseLanguagePrefix: S,
|
|
200
|
-
isHomePage: m,
|
|
201
|
-
parentSlug: U,
|
|
202
|
-
slug: g,
|
|
203
|
-
setSlug: w,
|
|
204
|
-
isSlugValid: p,
|
|
205
|
-
setIsSlugValid: W,
|
|
206
|
-
getSlug: B,
|
|
207
|
-
isPending: C,
|
|
208
|
-
id: $,
|
|
209
|
-
pages: v
|
|
210
|
-
}) => u ? /* @__PURE__ */ t("div", { className: "flex h-80 items-center justify-center", children: /* @__PURE__ */ t(kn, { className: "animate-spin" }) }) : d ? /* @__PURE__ */ t(
|
|
211
|
-
Bn,
|
|
212
|
-
{
|
|
213
|
-
onSubmit: r,
|
|
214
|
-
edit: l,
|
|
215
|
-
lang: i,
|
|
216
|
-
languages: e,
|
|
217
|
-
name: c,
|
|
218
|
-
setLang: o,
|
|
219
|
-
setName: n,
|
|
220
|
-
primaryPageObject: a,
|
|
221
|
-
parentHasSelectedLanguagePage: A,
|
|
222
|
-
id: $,
|
|
223
|
-
pages: v,
|
|
224
|
-
isNonSlugPageType: d,
|
|
225
|
-
isHomePage: m,
|
|
226
|
-
useLanguagePrefix: N,
|
|
227
|
-
slug: g,
|
|
228
|
-
isSlugValid: p,
|
|
229
|
-
isPending: C
|
|
230
|
-
}
|
|
231
|
-
) : /* @__PURE__ */ h("form", { onSubmit: r, children: [
|
|
232
|
-
/* @__PURE__ */ h("div", { className: "grid gap-4 py-4", children: [
|
|
233
|
-
/* @__PURE__ */ t(
|
|
234
|
-
Z,
|
|
235
|
-
{
|
|
236
|
-
edit: l,
|
|
237
|
-
lang: i,
|
|
238
|
-
languages: e,
|
|
239
|
-
name: c,
|
|
240
|
-
setLang: o,
|
|
241
|
-
setName: n,
|
|
242
|
-
primaryPageObject: a
|
|
243
|
-
}
|
|
244
|
-
),
|
|
245
|
-
/* @__PURE__ */ t(
|
|
246
|
-
b,
|
|
247
|
-
{
|
|
248
|
-
lang: i,
|
|
249
|
-
name: c,
|
|
250
|
-
setName: n,
|
|
251
|
-
parentHasSelectedLanguagePage: A
|
|
252
|
-
}
|
|
253
|
-
),
|
|
254
|
-
/* @__PURE__ */ t(
|
|
255
|
-
Wn,
|
|
256
|
-
{
|
|
257
|
-
dynamic: a == null ? void 0 : a.dynamic,
|
|
258
|
-
isNonSlugPageType: d,
|
|
259
|
-
isRootPage: E,
|
|
260
|
-
lang: i,
|
|
261
|
-
useLanguagePrefix: N,
|
|
262
|
-
setUseLanguagePrefix: S,
|
|
263
|
-
isHomePage: m,
|
|
264
|
-
parentSlug: U,
|
|
265
|
-
parentHasSelectedLanguagePage: A,
|
|
266
|
-
slug: g,
|
|
267
|
-
setSlug: w,
|
|
268
|
-
isSlugValid: p,
|
|
269
|
-
setIsSlugValid: W,
|
|
270
|
-
getSlug: B
|
|
271
|
-
}
|
|
272
|
-
)
|
|
273
|
-
] }),
|
|
274
|
-
/* @__PURE__ */ t(
|
|
275
|
-
y,
|
|
276
|
-
{
|
|
277
|
-
parentHasSelectedLanguagePage: A,
|
|
278
|
-
name: c,
|
|
279
|
-
lang: i,
|
|
280
|
-
slug: g,
|
|
281
|
-
edit: l,
|
|
282
|
-
id: $,
|
|
283
|
-
primaryPageObject: a,
|
|
284
|
-
pages: v,
|
|
285
|
-
isNonSlugPageType: d,
|
|
286
|
-
isHomePage: m,
|
|
287
|
-
useLanguagePrefix: N,
|
|
288
|
-
isSlugValid: p,
|
|
289
|
-
isPending: C
|
|
290
|
-
}
|
|
291
|
-
)
|
|
292
|
-
] }), Xn = ({
|
|
293
|
-
id: u,
|
|
294
|
-
isOpen: r,
|
|
295
|
-
onClose: l,
|
|
296
|
-
primaryPage: i,
|
|
297
|
-
edit: e = !1,
|
|
298
|
-
preselectedLang: c
|
|
299
|
-
}) => {
|
|
300
|
-
const { data: o = [] } = Nn(), n = F(() => o.find((s) => s.id === i), [o, i]), [a, A] = T(""), [d, E] = T(""), [N, S] = T(""), [m, U] = T(!0), [g, w] = T(!0), { mutate: p, isPending: W } = mn(), { mutate: B, isPending: C } = En(), $ = W || C, { data: v, isFetching: P } = Sn(), q = gn(), { data: D, isFetching: O } = K(i), { data: G = [], isFetching: j } = K(
|
|
301
|
-
n == null ? void 0 : n.parent
|
|
302
|
-
), { data: Y = [], isFetching: nn } = xn(), { setSelectedLang: sn } = vn(), [, en] = Gn(), [, tn] = Ln(), on = P || O || j || nn, _ = F(() => $n(v == null ? void 0 : v.languages, (s) => !In(D, { lang: s })), [v, D]), M = F(
|
|
303
|
-
() => Y.find((s) => s.key === (n == null ? void 0 : n.pageType)),
|
|
304
|
-
[Y, n == null ? void 0 : n.pageType]
|
|
305
|
-
), z = !(M != null && M.hasSlug), V = (n == null ? void 0 : n.slug) === "/";
|
|
306
|
-
Q(() => {
|
|
307
|
-
if (!e && n && c && (E(c), A(`${n.name} - ${L[c]}`)), !e || !n) return;
|
|
308
|
-
const s = D == null ? void 0 : D.find((cn) => cn.id === u);
|
|
309
|
-
if (!s) return;
|
|
310
|
-
A(s.name), E(s.lang);
|
|
311
|
-
const x = s.slug || "", { initSlug: R, prefix: un } = hn(x, n);
|
|
312
|
-
S(R), w(un);
|
|
313
|
-
}, [e, u, D, n, c]), Q(() => {
|
|
314
|
-
if (c)
|
|
315
|
-
E(c);
|
|
316
|
-
else if ((_ == null ? void 0 : _.length) === 1 && !e) {
|
|
317
|
-
const s = _[0];
|
|
318
|
-
if (!s || !L[s]) return;
|
|
319
|
-
E(s), (!a || a === (n == null ? void 0 : n.name)) && A(`${n == null ? void 0 : n.name} - ${L[s]}`);
|
|
320
|
-
}
|
|
321
|
-
}, [c, _, e, a, n]);
|
|
322
|
-
const { parentSlug: H, isRootPage: I } = F(() => {
|
|
323
|
-
if (V || !d)
|
|
324
|
-
return { parentSlug: void 0, isRootPage: !(n != null && n.parent) };
|
|
325
|
-
if (!(n != null && n.parent))
|
|
326
|
-
return {
|
|
327
|
-
parentSlug: g ? `/${d}` : void 0,
|
|
328
|
-
isRootPage: !0
|
|
329
|
-
};
|
|
330
|
-
const s = G == null ? void 0 : G.find((x) => x.lang === d);
|
|
331
|
-
return { parentSlug: s == null ? void 0 : s.slug, isRootPage: !1 };
|
|
332
|
-
}, [n == null ? void 0 : n.parent, G, g, d, V]), ln = F(() => I ? !0 : !!(G != null && G.some((s) => (s == null ? void 0 : s.lang) === d)), [d, G, I]), J = () => {
|
|
333
|
-
let s = "";
|
|
334
|
-
return I ? s = `/${g ? [d, N].filter(Boolean).join("/") : N}` : s = `${fn(H)}/${N}`, s.replace(/\/{2,}/g, "/").replace(/\/$/, "");
|
|
335
|
-
}, dn = (s) => {
|
|
336
|
-
const x = new URLSearchParams(window.location.search);
|
|
337
|
-
q && s === q ? x.delete("lang") : x.set("lang", s), en(x), window.dispatchEvent(new PopStateEvent("popstate"));
|
|
338
|
-
}, an = (s) => {
|
|
339
|
-
s.preventDefault();
|
|
340
|
-
const x = {
|
|
341
|
-
name: a,
|
|
342
|
-
lang: d,
|
|
343
|
-
primaryPage: n == null ? void 0 : n.id,
|
|
344
|
-
slug: z ? "" : J(),
|
|
345
|
-
pageType: n == null ? void 0 : n.pageType,
|
|
346
|
-
...e && { id: u }
|
|
347
|
-
}, R = () => {
|
|
348
|
-
!e && d && (sn(d), dn(d)), tn("outline"), l();
|
|
349
|
-
};
|
|
350
|
-
e ? B(x, { onSuccess: R }) : p(x, { onSuccess: R });
|
|
351
|
-
};
|
|
352
|
-
return /* @__PURE__ */ t(Dn, { open: r, onOpenChange: l, children: r && /* @__PURE__ */ h(_n, { className: "text-slate-600 sm:max-w-[425px]", children: [
|
|
353
|
-
/* @__PURE__ */ h(Un, { children: [
|
|
354
|
-
/* @__PURE__ */ t(pn, { children: e ? f.EDIT_LANGUAGE : f.ADD_NEW_LANGUAGE }),
|
|
355
|
-
/* @__PURE__ */ t(Fn, { className: "font-light", children: f.ENTER_LANGUAGE_DETAILS })
|
|
356
|
-
] }),
|
|
357
|
-
/* @__PURE__ */ t(
|
|
358
|
-
Mn,
|
|
359
|
-
{
|
|
360
|
-
id: u,
|
|
361
|
-
pages: o,
|
|
362
|
-
loading: on,
|
|
363
|
-
onSubmit: an,
|
|
364
|
-
edit: e,
|
|
365
|
-
lang: d,
|
|
366
|
-
languages: _,
|
|
367
|
-
name: a,
|
|
368
|
-
setLang: E,
|
|
369
|
-
setName: A,
|
|
370
|
-
primaryPageObject: n,
|
|
371
|
-
parentHasSelectedLanguagePage: ln,
|
|
372
|
-
isNonSlugPageType: z,
|
|
373
|
-
isRootPage: I,
|
|
374
|
-
useLanguagePrefix: g,
|
|
375
|
-
setUseLanguagePrefix: w,
|
|
376
|
-
isHomePage: V,
|
|
377
|
-
parentSlug: H,
|
|
378
|
-
slug: N,
|
|
379
|
-
setSlug: S,
|
|
380
|
-
isSlugValid: m,
|
|
381
|
-
setIsSlugValid: U,
|
|
382
|
-
getSlug: J,
|
|
383
|
-
isPending: $
|
|
384
|
-
}
|
|
385
|
-
)
|
|
386
|
-
] }) });
|
|
387
|
-
};
|
|
388
|
-
export {
|
|
389
|
-
Xn as default
|
|
390
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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-CsZpQ7Gy.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,30 +0,0 @@
|
|
|
1
|
-
import { jsx as o, jsxs as n } from "react/jsx-runtime";
|
|
2
|
-
import { Dialog as c, DialogContent as a, DialogHeader as t, DialogTitle as p, DialogDescription as m } from "@chaibuilder/sdk/ui";
|
|
3
|
-
import { lazy as h, Suspense as D } from "react";
|
|
4
|
-
const f = h(() => import("./page-creator-Crc5BzeB.js")), N = ({
|
|
5
|
-
addEditPage: e,
|
|
6
|
-
setAddEditPage: r,
|
|
7
|
-
closePanel: s
|
|
8
|
-
}) => {
|
|
9
|
-
const l = !!(e != null && e.id), i = !!e;
|
|
10
|
-
return /* @__PURE__ */ o(c, { open: i, onOpenChange: () => r(void 0), children: i && /* @__PURE__ */ n(a, { className: "sm:max-w-[425px]", children: [
|
|
11
|
-
/* @__PURE__ */ n(t, { children: [
|
|
12
|
-
/* @__PURE__ */ n(p, { children: [
|
|
13
|
-
l ? "Edit" : "Add New",
|
|
14
|
-
" "
|
|
15
|
-
] }),
|
|
16
|
-
/* @__PURE__ */ o(m, { children: l ? "Update your page name" : "Enter details to create a new page" })
|
|
17
|
-
] }),
|
|
18
|
-
/* @__PURE__ */ o(D, { fallback: /* @__PURE__ */ o("div", { className: "min-h-40" }), children: /* @__PURE__ */ o(
|
|
19
|
-
f,
|
|
20
|
-
{
|
|
21
|
-
closePanel: s,
|
|
22
|
-
addEditPage: e,
|
|
23
|
-
close: () => r(void 0)
|
|
24
|
-
}
|
|
25
|
-
) })
|
|
26
|
-
] }) });
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
N as default
|
|
30
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),i=require("./index-Blg1T7nL.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,38 +0,0 @@
|
|
|
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-zaGKeGBW.js";
|
|
3
|
-
import { useLanguages as S, useSidebarActivePanel as v } from "@chaibuilder/sdk";
|
|
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
|
-
import { get as g } from "lodash-es";
|
|
6
|
-
function b({ page: e, onClose: r }) {
|
|
7
|
-
const [, s] = D(), { mutate: c, isPending: a } = f(), { data: l } = w(), { setSelectedLang: d, fallbackLang: m } = S(), [, u] = v(), h = () => {
|
|
8
|
-
a || c(e, {
|
|
9
|
-
onSuccess: () => {
|
|
10
|
-
e != null && e.primaryPage ? (window.history.replaceState({}, "", `/?page=${e.primaryPage}`), s(new URLSearchParams({ page: e.primaryPage }))) : (window.history.replaceState({}, "", "/"), s(new URLSearchParams())), window.dispatchEvent(new PopStateEvent("popstate")), d(m), u("outline"), r();
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
}, t = l == null ? void 0 : l.find((P) => P.key === (e == null ? void 0 : e.pageType));
|
|
14
|
-
return /* @__PURE__ */ n(L, { open: !!e, onOpenChange: r, children: /* @__PURE__ */ i(x, { children: [
|
|
15
|
-
/* @__PURE__ */ i(A, { children: [
|
|
16
|
-
/* @__PURE__ */ n(k, { children: "Confirm Deletion" }),
|
|
17
|
-
/* @__PURE__ */ i(C, { className: "py-4 text-slate-500", children: [
|
|
18
|
-
/* @__PURE__ */ i("div", { children: [
|
|
19
|
-
"Are you sure you want to remove ",
|
|
20
|
-
/* @__PURE__ */ n("b", { children: (e == null ? void 0 : e.name) ?? (e == null ? void 0 : e.slug) }),
|
|
21
|
-
" ",
|
|
22
|
-
t != null && t.hasSlug ? (t == null ? void 0 : t.name) + "?" : `page? ${e != null && e.primaryPage ? "" : "This will also delete all associated language pages."}`
|
|
23
|
-
] }),
|
|
24
|
-
e.lang && /* @__PURE__ */ i("div", { className: "py-2 text-sm", children: [
|
|
25
|
-
"Language: ",
|
|
26
|
-
/* @__PURE__ */ n("span", { className: "font-medium text-gray-500", children: g(y, e.lang, e.lang) })
|
|
27
|
-
] })
|
|
28
|
-
] })
|
|
29
|
-
] }),
|
|
30
|
-
/* @__PURE__ */ i(N, { children: [
|
|
31
|
-
/* @__PURE__ */ n(o, { variant: "outline", onClick: r, children: "Cancel" }),
|
|
32
|
-
/* @__PURE__ */ n(o, { variant: "destructive", disabled: a, onClick: h, children: a ? "Deleting..." : "Delete" })
|
|
33
|
-
] })
|
|
34
|
-
] }) });
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
b as default
|
|
38
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),Z=require("@chaibuilder/sdk"),l=require("@chaibuilder/sdk/ui"),D=require("lodash-es"),f=require("lucide-react"),o=require("react"),xe=require("react-dropzone"),p=require("./index-Blg1T7nL.cjs"),A=require("sonner"),J=require("./image-compression-DZ9WMmyn.cjs"),k=require("@tanstack/react-query"),fe=()=>{const r=p.useAssetsApiUrl(),a=k.useQueryClient(),m=p.useFetch();return k.useMutation({mutationFn:async s=>{const h=s.map(async v=>m(r,{action:p.ACTIONS.UPLOAD_ASSET,data:v}));return await Promise.all(h)},onSuccess:s=>{var h;if(s!=null&&s.some(i=>i.error))throw new Error(((h=s==null?void 0:s.find(i=>i.error))==null?void 0:h.error)||"Failed to upload asset");{a.invalidateQueries({queryKey:[p.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")}})},pe=()=>{const r=p.useAssetsApiUrl(),a=k.useQueryClient(),m=p.useFetch();return k.useMutation({mutationFn:async s=>m(r,{action:p.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[p.ACTIONS.GET_ASSETS]}),A.toast.success("Asset deleted successfully")},onError:()=>{A.toast.error("Failed to delete asset")}})},ge=()=>{const r=p.useAssetsApiUrl(),a=k.useQueryClient(),m=p.useFetch();return k.useMutation({mutationFn:async s=>m(r,{action:p.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[p.ACTIONS.GET_ASSETS]}),s!=null&&s.id&&a.invalidateQueries({queryKey:[p.ACTIONS.GET_ASSET,s.id]}),A.toast.success("Asset updated successfully")},onError:()=>{A.toast.error("Failed to update asset")}})};function je({currentPage:r,totalPages:a,onPageChange:m,pageRangeDisplayed:s=3,showPageInput:h=!0,className:i=""}){const[v,y]=o.useState(String(r)),b=o.useMemo(()=>{const c=Math.floor(s/2);let n=Math.max(1,r-c),d=Math.min(a,r+c);d-n+1<s&&(n===1?d=Math.min(a,n+s-1):d===a&&(n=Math.max(1,d-s+1)));const j=[];n>1&&(j.push(1),n>2&&j.push("..."));for(let N=n;N<=d;N++)j.push(N);return d<a&&(d<a-1&&j.push("..."),j.push(a)),j},[r,a,s]),g=c=>{c!==r&&c>=1&&c<=a&&(m(c),y(String(c)))},w=()=>{r>1&&g(r-1)},S=()=>{r<a&&g(r+1)},C=()=>{const c=Number(v);!isNaN(c)&&c>=1&&c<=a&&g(c)},x=c=>{c.key==="Enter"&&C()};return a<=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(l.Button,{variant:"outline",size:"sm",onClick:w,disabled:r===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:b.map((c,n)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${n}`);const d=c,j=d===r;return e.jsx(l.Button,{variant:j?"default":"outline",size:"sm",onClick:()=>g(d),className:j?"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:d},d)})}),e.jsxs(l.Button,{variant:"outline",size:"sm",onClick:S,disabled:r===a,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),h&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(l.Input,{type:"number",min:1,max:a,value:v,onChange:c=>{const n=c.target.value.replace(/[^\d]/g,"");y(n)},onKeyDown:x,className:"h-8 w-16 px-2 py-1"}),e.jsx(l.Button,{variant:"outline",size:"sm",onClick:C,disabled:v===""||Number(v)<1||Number(v)>a,children:"Go"})]})]})}const ve=(r={})=>{const a=p.useAssetsApiUrl(),m=p.useFetch(),{search:s,page:h=1,limit:i=30}=r;return k.useQuery({queryKey:[p.ACTIONS.GET_ASSETS,s,h,i],queryFn:async()=>{const v=await m(a,{action:p.ACTIONS.GET_ASSETS,data:{search:s,page:h,limit:i}});return v.page=h,v.limit=i,v},staleTime:1/0,retry:1})},ye=r=>{const a=p.useAssetsApiUrl(),m=p.useFetch();return k.useQuery({queryKey:[p.ACTIONS.GET_ASSET,r],queryFn:async()=>r?await m(a,{action:p.ACTIONS.GET_ASSET,data:{id:r}}):null,staleTime:1/0,retry:1})};function Ne(r){const a=isNaN(r)?0:typeof r=="number"?r:parseInt(r);return a?a<1024?`${a.toFixed(2)} B`:a<1024*1024?`${(a/1024).toFixed(2)} KB`:`${(a/(1024*1024)).toFixed(2)} MB`:"0 B"}function H(r){if(!r)return"N/A";const a=new Date(r);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(a)}function X(r,a){let m=r,s=a==null?void 0:a.description;return(!s||typeof s!="string")&&(s=""),(!m||typeof m!="string")&&(m=""),m!==s}const be=({assetId:r,onBack:a,onEdit:m,onSave:s,isSaving:h})=>{var x,c;const{data:i,isLoading:v,isError:y}=ye(r||""),[b,g]=o.useState(""),[w,S]=o.useState(!1);o.useEffect(()=>{const n=new Image;return n.src=(i==null?void 0:i.url)||"",n.onload=()=>S(!0),()=>{n.onload=null}},[i]);const C=async(n,d)=>{try{await navigator.clipboard.writeText(n),A.toast.success(`${d} copied to clipboard`)}catch(j){A.toast.error(`Failed to copy ${d}`,{description:j==null?void 0:j.message})}};return o.useEffect(()=>{i!=null&&i.description&&g(i.description)},[i]),v||!w?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):y||!(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(f.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:y?"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(l.Button,{variant:"outline",onClick:a,children:"Back to Assets"}),y&&e.jsx(l.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(l.Button,{variant:"outline",size:"sm",onClick:a,disabled:h,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l.Button,{variant:"outline",onClick:a,disabled:h,children:"Cancel"}),e.jsxs(l.Button,{variant:"outline",onClick:()=>C(i.url,"Asset URL"),disabled:h,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),"Copy URL"]}),e.jsxs(l.Button,{variant:"default",onClick:()=>m(i),disabled:h,children:[e.jsx(f.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,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(l.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:((x=i.metadata)==null?void 0:x.format)||i.type,capitalize:!0},{label:"Size",value:Ne(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:H(i.createdAt)},{label:"Updated",value:H(((c=i.metadata)==null?void 0:c.updatedAt)||(i==null?void 0:i.updatedAt)||i.createdAt)},{label:"URL",value:i.url,copyable:!0}].map(n=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(l.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:n.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(n.capitalize?" capitalize":""),children:n.value}),n.copyable&&e.jsx(l.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>C(n.value,n.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},n.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(l.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((n,d)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:n.name}),e.jsxs("div",{className:"text-gray-500",children:["(",n.slug,")"]})]},d))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(l.Label,{className:"w-full text-center",children:"Description"}),e.jsx(l.Textarea,{id:"description",value:b,placeholder:"Enter a description for the asset",onChange:n=>g(n.target.value),rows:3,disabled:h,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(b),disabled:h||!X(b,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${h||!X(b,i)?"opacity-50 cursor-not-allowed":""}`,children:h?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},we=o.lazy(()=>Promise.resolve().then(()=>require("./image-editor-Da6lrqkL.cjs"))),Ce=25*1024*1024,Ae=({isUpdatingAsset:r,allowedTypes:a,uploadAssets:m,isUploadingAsset:s,onUploaded:h})=>{const[i,v]=o.useState(()=>{const x=localStorage.getItem("chai_optimize_images");return x!==null?x==="true":!0});o.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const y=r||s,b=o.useCallback(async x=>{try{const c=x;if(!c.every(N=>N.type.startsWith("image/")))return A.toast.error("Invalid file type. Please upload a valid file."),Promise.reject(new Error("Invalid file type"));const n=c.map(async N=>{let F=N;return N.type.startsWith("image/")&&(F=await J.compressImageIfNeeded(N)),new Promise((P,U)=>{const B=new FileReader;B.readAsDataURL(F),B.onload=async()=>{P({file:B.result,folderId:void 0,name:N.name,optimize:i})},B.onerror=()=>U(null)})}),d=await Promise.all(n),j=await m(d);return(j==null?void 0:j.length)===1&&h(j[0]),j}catch(c){return Promise.reject(c)}},[m,i,h]),g=x=>{const c=[];let n=0;return x.forEach(d=>{d.size>Ce?n++:c.push(d)}),n>0&&A.toast.error(`${n===1&&x.length===1?"File":n+(n===1?" file":" files")} exceed the maximum size limit of 10MB.`),D.isEmpty(c)?[]:b(c)},{getRootProps:w,getInputProps:S,isDragActive:C}=xe.useDropzone({onDrop:g,accept:{"image/*":a.includes("image")?[]:[]},disabled:r||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 ${y?"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:Z.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",y?"items-start":"items-center",C?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...S()}),y?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(f.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:r?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:["Please wait while we ",r?"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(f.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:a.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(l.Switch,{checked:i,onCheckedChange:x=>{v(x)},onClick:x=>{x.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${i?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(l.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 Se({close:r,onSelect:a,mode:m="image",assetId:s}){const v=o.useMemo(()=>[m],[m]),[y,b]=o.useState(null),[g,w]=o.useState(null),[S,C]=o.useState(null),[x,c]=o.useState({show:!1,file:""}),[n,d]=o.useState(!1),[j,N]=o.useState(s?"details":"grid"),[F,P]=o.useState(""),[U,B]=o.useState(""),[O,$]=o.useState(1),[Q]=o.useState(30),[T,_]=o.useState([]);o.useEffect(()=>{s&&(b(s),N("details"))},[s]),o.useEffect(()=>{const t=setTimeout(()=>{P(U),$(1)},300);return()=>clearTimeout(t)},[U]);const{data:L,isLoading:M,refetch:Y}=ve({search:F.toLowerCase().trim(),page:O,limit:Q}),z=(L==null?void 0:L.assets)||[],ee=(L==null?void 0:L.total)||0,E=Math.ceil(ee/Q);o.useEffect(()=>{M||E<=0||$(t=>t>E?E:t<1?1:t)},[M,E]);const te=(z==null?void 0:z.length)>0,{mutate:se}=pe(),{mutateAsync:G,isPending:ie}=fe(),{mutateAsync:R,isPending:le}=ge(),K=o.useCallback(t=>{const u=Math.min(Math.max(1,t),Math.max(1,E));u!==O&&$(u)},[E,O]),ae=t=>{B(t.target.value)},re=o.useCallback(t=>{_(u=>D.find(u,{id:t.id})?[]:[t])},[!1]),ne=o.useCallback(()=>{_([])},[]),W=t=>{(t==null?void 0:t.length)!==0&&(a(D.pick(D.first(t||T),["id","url","width","height","description"])),r())},ce=async t=>{w(t)},oe=async()=>{g&&(C(g==null?void 0:g.id),await se(g.id,{onSuccess:()=>{C(null),w(null)},onError:()=>{C(null)}}),w(null))},de=t=>{b(t.id),N("details")},ue=async(t,u)=>{try{const q=localStorage.getItem("chai_optimize_images")!=="false";if(u){const I=await G([{file:t,folderId:void 0,name:x.name||"",optimize:q}]);if((I==null?void 0:I.length)>0){const V=I[0];a({...D.pick(V,["id","width","height","description"]),url:V.url})}}else{const I=await R({id:x.id||"",file:t});I&&a({...D.pick(I,["id","width","height","description"]),url:I.url})}c({show:!1,file:""}),r()}catch(q){console.error("Error saving edited image:",q)}},me=o.useCallback(t=>{_([t])},[]),he=o.useCallback(t=>{K(t)},[K]);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"}),j==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{maxFileSize:10,allowedTypes:v,uploadAssets:G,isUpdatingAsset:le,isUploadingAsset:ie,onUploaded:me}),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(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${U.length>0?"text-indigo-800":""}`}),e.jsx(l.Input,{placeholder:"Search assets...",onChange:ae,value:U,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(l.Button,{variant:"outline",size:"sm",onClick:()=>ne(),title:"Clear selection",children:"Clear"})}),e.jsx(l.Button,{size:"sm",onClick:()=>W(T),disabled:T.length===0,children:"Select Asset"})]})}):null,e.jsx(l.Button,{variant:"ghost",size:"icon",onClick:()=>Y(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:M?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"})]}):!M&&!te?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(f.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:F.length>0?"No assets found for your search: "+F:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:z==null?void 0:z.map(t=>e.jsxs("div",{className:Z.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(u=>u.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:()=>re(t),onDoubleClick:()=>W([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(f.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(u=>u.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.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:J.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(u=>u.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(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:u=>{u.stopPropagation(),de(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:"View Details"})})]})}),e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:u=>{u.stopPropagation(),navigator.clipboard.writeText(t.url),A.toast.success("Asset URL copied to clipboard")},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:"Copy URL"})})]})}),e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:u=>{u.stopPropagation(),c({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:"Edit Image"})})]})}),e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:u=>{u.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:"Delete Asset"})})]})})]})}),T.some(u=>u.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(f.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(p.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:"Error loading pagination"}),children:e.jsx(je,{currentPage:O,totalPages:E,onPageChange:he,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(be,{assetId:y||s||"",onBack:()=>{N("grid"),b(null)},onEdit:t=>{c({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(y){d(!0);try{const u=z.find(q=>q.id===y);u&&await R(D.merge(u,{description:t}))}finally{d(!1)}}},isSaving:n})]}),x.show&&e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(we,{imageUrl:x.file,onSave:ue,onClose:()=>c({show:!1,file:""}),defaultSavedImageName:x.name,isEditing:!!x.id})}),g&&e.jsx(l.Dialog,{open:!!g,onOpenChange:()=>w(null),children:e.jsxs(l.DialogContent,{children:[e.jsxs(l.DialogHeader,{children:[e.jsx(l.DialogTitle,{children:"Delete Asset"}),e.jsxs(l.DialogDescription,{children:['Are you sure you want to delete "',g.name,'"? This action cannot be undone.']})]}),e.jsxs(l.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(l.Button,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),e.jsx(l.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=Se;
|