@chaibuilder/pages 0.15.1 → 0.15.3
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-a-BJOrVj.js → 2AITGKQY-DhC0sF1x.js} +2 -2
- package/dist/{2AITGKQY-GcbF_G3s.cjs → 2AITGKQY-o6FgGSqg.cjs} +1 -1
- package/dist/{NCMVHL6D-fz7uxKMS.cjs → NCMVHL6D-BPM6RHYa.cjs} +1 -1
- package/dist/{NCMVHL6D-CCFQEIik.js → NCMVHL6D-D7HU3akD.js} +2 -2
- package/dist/{ZDWCUMSJ-B87y4E-s.js → ZDWCUMSJ-Cr1v3giV.js} +1 -1
- package/dist/{ZDWCUMSJ-D40Aht5l.cjs → ZDWCUMSJ-NVCxv9uE.cjs} +1 -1
- package/dist/{add-new-language-page-CxNpkd0L.js → add-new-language-page-8q4Ku3eg.js} +2 -2
- package/dist/{add-new-language-page-Dyh26P7i.cjs → add-new-language-page-D3PSLiUv.cjs} +1 -1
- package/dist/{add-new-page-DGQqN1GO.js → add-new-page-BpvpSM4X.js} +1 -1
- package/dist/{add-new-page-jWn3_pZ4.cjs → add-new-page-YpzILOYq.cjs} +1 -1
- package/dist/{delete-page-WnsCggnJ.js → delete-page-CXRJjJ4o.js} +1 -1
- package/dist/{delete-page-Bxl1t_Ue.cjs → delete-page-w64MO7db.cjs} +1 -1
- package/dist/digital-asset-manager-B2m5T22s.js +1001 -0
- package/dist/digital-asset-manager-BGyKKd_6.cjs +1 -0
- package/dist/{duplicate-page-DOloolXy.js → duplicate-page-CSQs2MOp.js} +2 -2
- package/dist/{duplicate-page-CDtfdgyJ.cjs → duplicate-page-DB_c7V2t.cjs} +1 -1
- package/dist/{dynamic-page-selector-CcYIfKlO.cjs → dynamic-page-selector-CF9nb6i_.cjs} +1 -1
- package/dist/{dynamic-page-selector-B-8TUdTG.js → dynamic-page-selector-DTk4oull.js} +1 -1
- package/dist/image-editor-D9MPdtxC.js +107 -0
- package/dist/image-editor-Da6lrqkL.cjs +1 -0
- package/dist/{index-CguzNa4U.js → index-BuXZJnGo.js} +15 -15
- package/dist/{index-CffopOpP.cjs → index-Cds1vIhw.cjs} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-diff-viewer-CxFGgqa_.js → json-diff-viewer-oyxMD3Hc.js} +1 -1
- package/dist/{json-diff-viewer-DcR1gbkd.cjs → json-diff-viewer-zBoPBSd3.cjs} +1 -1
- package/dist/{lang-panel-Bi427DLp.js → lang-panel-B_HcsPPo.js} +2 -2
- package/dist/{lang-panel-XonHaLBn.cjs → lang-panel-D2YUMeJZ.cjs} +1 -1
- package/dist/{mark-as-template-BtI1QfuI.cjs → mark-as-template-C4wH4UKf.cjs} +1 -1
- package/dist/{mark-as-template-CS68JVP8.js → mark-as-template-CPEPYXg7.js} +1 -1
- package/dist/{no-language-page-content-C5t9cDI4.js → no-language-page-content-CVyOpT9h.js} +1 -1
- package/dist/{no-language-page-content-DMqw1cTK.cjs → no-language-page-content-ECt0SxFX.cjs} +1 -1
- package/dist/{page-creator-BkKT_Xy1.cjs → page-creator-BG2hc82u.cjs} +1 -1
- package/dist/{page-creator-BY2w99Ez.js → page-creator-y6kl3nw5.js} +2 -2
- package/dist/{page-lock-request-Z1sTGi6N.js → page-lock-request-DC62b588.js} +1 -1
- package/dist/{page-lock-request-CIRTswpw.cjs → page-lock-request-fGZbOFTp.cjs} +1 -1
- package/dist/{page-locked-by-dialog-DpBpQ0oI.cjs → page-locked-by-dialog-BIC-c0Jl.cjs} +1 -1
- package/dist/{page-locked-by-dialog-B2C1M_bK.js → page-locked-by-dialog-D-vXaoga.js} +1 -1
- package/dist/{page-manager-new-tWV46glN.cjs → page-manager-new-CUfjlMed.cjs} +1 -1
- package/dist/{page-manager-new-CSqFLJBd.js → page-manager-new-Cto2r7Va.js} +2 -2
- package/dist/{page-manager-search-and-filter-B9VZzJQd.js → page-manager-search-and-filter-sVnGlF46.js} +1 -1
- package/dist/{page-manager-search-and-filter-CwuukvKn.cjs → page-manager-search-and-filter-z2b4sgvb.cjs} +1 -1
- package/dist/{page-revisions-content-WoIu0uan.js → page-revisions-content-BaTqBnko.js} +2 -2
- package/dist/{page-revisions-content-BWhJz0_7.cjs → page-revisions-content-Tb3T6zvU.cjs} +1 -1
- package/dist/{publish-pages-content-BHDTLdGv.cjs → publish-pages-content-BGkEZ3GK.cjs} +1 -1
- package/dist/{publish-pages-content-CkWvQGbm.js → publish-pages-content-C9CgEWo0.js} +2 -2
- package/dist/{save-to-lib-AkbnWUxR.js → save-to-lib-DGtyTG6H.js} +1 -1
- package/dist/{save-to-lib-C0ZfwiAE.cjs → save-to-lib-DNK4GPNw.cjs} +1 -1
- package/dist/{seo-panel-CiKkn5Jp.cjs → seo-panel-CrK7z4bR.cjs} +1 -1
- package/dist/{seo-panel-Gu3HZveQ.js → seo-panel-DESVAQM5.js} +1 -1
- package/dist/shared-json-ld-BMfQzOWc.js +650 -0
- package/dist/shared-json-ld-_ozYsSHn.cjs +1 -0
- package/dist/{slug-input-B4w0Ihxn.cjs → slug-input-DMYhARDW.cjs} +1 -1
- package/dist/{slug-input-BXNj3cZf.js → slug-input-DfAsMPg8.js} +1 -1
- package/dist/{theme-panel-footer-DnZs9SzB.cjs → theme-panel-footer-Bj2yHtxO.cjs} +1 -1
- package/dist/{theme-panel-footer-68bQaQeh.js → theme-panel-footer-RrxiDGoD.js} +1 -1
- package/dist/{unmark-as-template-MpXMyb0Q.js → unmark-as-template-BjetSrYF.js} +1 -1
- package/dist/{unmark-as-template-DFxmzyx4.cjs → unmark-as-template-C8hTjRVk.cjs} +1 -1
- package/dist/{unpublish-page-Bzouoco9.js → unpublish-page-BTPEVAkv.js} +1 -1
- package/dist/{unpublish-page-CCPyMoaC.cjs → unpublish-page-gtGfNOAq.cjs} +1 -1
- package/dist/{web-preview-B3-o8BoT.cjs → web-preview-BcULgiw_.cjs} +1 -1
- package/dist/{web-preview-D9PcexXy.js → web-preview-DNgPjdgZ.js} +1 -1
- package/package.json +1 -1
- package/dist/digital-asset-manager-ClyooOJY.js +0 -976
- package/dist/digital-asset-manager-DrXotZ_n.cjs +0 -1
- package/dist/image-editor-BWLJT1mr.cjs +0 -1
- package/dist/image-editor-CzFST20j.js +0 -104
- package/dist/shared-json-ld-BPaeG1gf.cjs +0 -1
- package/dist/shared-json-ld-CsyZjZdT.js +0 -557
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),I=require("@chaibuilder/sdk/ui"),S=require("lodash-es"),p=require("lucide-react"),t=require("react"),R=require("react-filerobot-image-editor"),b=t.memo(({imageUrl:n,onSave:r,onClose:d,defaultSavedImageName:g,isEditing:c=!1})=>{const[x,u]=t.useState(!0),[h,v]=t.useState(!1);t.useEffect(()=>{const e=new Image;return e.src=n,e.onload=()=>v(!0),()=>{e.onload=null}},[n]);const m=t.useMemo(()=>S.debounce(async(e,a=!1)=>{const o=e.imageBase64;await r(o,a),u(!1)},300),[r]),s=t.useCallback((e,a=!1)=>{m(e,a)},[m]),f=t.useCallback(()=>{u(!1),d()},[d]),l=t.useMemo(()=>({tabsIds:["Adjust","Annotate","Watermark","Finetune","Resize","Filters"],toolsIds:["Rotate"],defaultTabId:"Adjust",defaultToolId:"Rotate"}),[]),y=t.useMemo(()=>({colors:{primary:"#000000",secondary:"#000000",tertiary:"#000000"}}),[]),C=t.useMemo(()=>c?[{label:"Update this file",onClick:(e,a)=>a((...o)=>{s(o[0],!1)}),icon:p.Save},{label:"Save as new file",onClick:(e,a)=>a((...o)=>{s(o[0],!0)}),icon:p.Copy}]:[],[c,s]);return i.jsx(I.Dialog,{open:!0,onOpenChange:e=>!e&&f(),children:i.jsx(I.DialogContent,{id:"chai-image-editor-container",className:"max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col p-0",children:x&&h&&i.jsx(R,{theme:y,source:n,onSave:s,onClose:f,Text:{text:"Add text here"},Rotate:{angle:90,componentType:"slider"},tabsIds:l.tabsIds,defaultTabId:l.defaultTabId,defaultToolId:l.defaultToolId,savingPixelRatio:2,previewPixelRatio:1,defaultSavedImageName:g,moreSaveOptions:C,useZoomPresetsMenu:!0,closeAfterSave:!0})})})});b.displayName="ImageEditor";exports.default=b;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { Dialog as y, DialogContent as T } from "@chaibuilder/sdk/ui";
|
|
3
|
-
import { debounce as w } from "lodash-es";
|
|
4
|
-
import { Save as S, Copy as R } from "lucide-react";
|
|
5
|
-
import { memo as A, useState as p, useEffect as E, useMemo as s, useCallback as I } from "react";
|
|
6
|
-
import O from "react-filerobot-image-editor";
|
|
7
|
-
const k = A(
|
|
8
|
-
({ imageUrl: n, onSave: d, onClose: i, defaultSavedImageName: g, isEditing: m = !1 }) => {
|
|
9
|
-
const [b, c] = p(!0), [h, x] = p(!1);
|
|
10
|
-
E(() => {
|
|
11
|
-
const e = new Image();
|
|
12
|
-
return e.src = n, e.onload = () => x(!0), () => {
|
|
13
|
-
e.onload = null;
|
|
14
|
-
};
|
|
15
|
-
}, [n]);
|
|
16
|
-
const f = s(
|
|
17
|
-
() => w(async (e, t = !1) => {
|
|
18
|
-
const o = e.imageBase64;
|
|
19
|
-
await d(o, t), c(!1);
|
|
20
|
-
}, 300),
|
|
21
|
-
[d]
|
|
22
|
-
), a = I(
|
|
23
|
-
(e, t = !1) => {
|
|
24
|
-
f(e, t);
|
|
25
|
-
},
|
|
26
|
-
[f]
|
|
27
|
-
), u = I(() => {
|
|
28
|
-
c(!1), i();
|
|
29
|
-
}, [i]), l = s(
|
|
30
|
-
() => ({
|
|
31
|
-
tabsIds: [
|
|
32
|
-
"Adjust",
|
|
33
|
-
"Annotate",
|
|
34
|
-
"Watermark",
|
|
35
|
-
"Finetune",
|
|
36
|
-
"Resize",
|
|
37
|
-
"Filters"
|
|
38
|
-
],
|
|
39
|
-
toolsIds: ["Rotate"],
|
|
40
|
-
defaultTabId: "Adjust",
|
|
41
|
-
defaultToolId: "Rotate"
|
|
42
|
-
}),
|
|
43
|
-
[]
|
|
44
|
-
), v = s(
|
|
45
|
-
() => ({
|
|
46
|
-
colors: {
|
|
47
|
-
primary: "#000000",
|
|
48
|
-
secondary: "#000000",
|
|
49
|
-
tertiary: "#000000"
|
|
50
|
-
}
|
|
51
|
-
}),
|
|
52
|
-
[]
|
|
53
|
-
), C = s(
|
|
54
|
-
() => m ? [
|
|
55
|
-
{
|
|
56
|
-
label: "Update this file",
|
|
57
|
-
onClick: (e, t) => t((...o) => {
|
|
58
|
-
a(o[0], !1);
|
|
59
|
-
}),
|
|
60
|
-
icon: S
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
label: "Save as new file",
|
|
64
|
-
onClick: (e, t) => t((...o) => {
|
|
65
|
-
a(o[0], !0);
|
|
66
|
-
}),
|
|
67
|
-
icon: R
|
|
68
|
-
}
|
|
69
|
-
] : [],
|
|
70
|
-
[m, a]
|
|
71
|
-
);
|
|
72
|
-
return /* @__PURE__ */ r(y, { open: !0, onOpenChange: (e) => !e && u(), children: /* @__PURE__ */ r(
|
|
73
|
-
T,
|
|
74
|
-
{
|
|
75
|
-
id: "chai-image-editor-container",
|
|
76
|
-
className: "max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col p-0",
|
|
77
|
-
children: b && h && /* @__PURE__ */ r(
|
|
78
|
-
O,
|
|
79
|
-
{
|
|
80
|
-
theme: v,
|
|
81
|
-
source: n,
|
|
82
|
-
onSave: a,
|
|
83
|
-
onClose: u,
|
|
84
|
-
Text: { text: "Add text here" },
|
|
85
|
-
Rotate: { angle: 90, componentType: "slider" },
|
|
86
|
-
tabsIds: l.tabsIds,
|
|
87
|
-
defaultTabId: l.defaultTabId,
|
|
88
|
-
defaultToolId: l.defaultToolId,
|
|
89
|
-
savingPixelRatio: 2,
|
|
90
|
-
previewPixelRatio: 1,
|
|
91
|
-
defaultSavedImageName: g,
|
|
92
|
-
moreSaveOptions: C,
|
|
93
|
-
useZoomPresetsMenu: !0,
|
|
94
|
-
closeAfterSave: !0
|
|
95
|
-
}
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
) });
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
k.displayName = "ImageEditor";
|
|
102
|
-
export {
|
|
103
|
-
k as default
|
|
104
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),E=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-CffopOpP.cjs"),s=require("@chaibuilder/sdk/ui"),u=require("lucide-react"),i=require("react"),J=require("sonner"),O=()=>{const d=c.useApiUrl(),h=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>h(d,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},k=({show:d,onClose:h,initialData:x})=>e.jsx(s.Dialog,{open:d,onOpenChange:()=>h(),children:d&&e.jsx(B,{show:d,onClose:h,initialData:x})}),B=({show:d,onClose:h,initialData:x})=>{const[v,g]=i.useState("edit"),[p,n]=i.useState(""),[t,m]=i.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[j,N]=i.useState(!1),{data:l}=c.useCurrentPage(),{mutateAsync:f,isPending:w}=c.useAddGlobalSchema(),{mutateAsync:S}=c.useTogglePageGlobalSchema();i.useEffect(()=>{g("edit"),m(x?{name:x.name,description:x.description,content:JSON.stringify(x.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),N(!1)},[d,x]),i.useEffect(()=>{const o=c.parseJSONWithPlaceholders(t.content);n(o.isValid?JSON.stringify(o.parsed,null,2):"")},[t.content]);const y=async()=>{if(!t.name||!t.content){J.toast.error("Please enter a name and content");return}const o=c.parseJSONWithPlaceholders(t.content);if(!o.isValid){J.toast.error("Invalid JSON-LD content");return}const A={name:t.name,jsonld:o.parsed,addToExistingPages:j,addToNewPages:t.enabledByDefaultForNewPages,description:t.description},b=await f(A);l!=null&&l.id&&(b!=null&&b.id)&&await S({schemaId:b.id,pageId:l.id,enabled:!0}),h()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{children:["Add New Shared JSON-LD Schema",(x==null?void 0:x.languageCode)&&e.jsxs("span",{className:"ml-2 text-sm font-normal text-muted-foreground",children:["(",x.languageCode,")"]})]})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:t.name,onChange:o=>m({...t,name:o.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:t.description||"",onChange:o=>m({...t,description:o.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsxs(s.Tabs,{value:v,onValueChange:g,className:"w-full",children:[e.jsxs("div",{className:"mb-2 flex w-full items-center justify-between",children:[e.jsxs(s.TabsList,{className:"w-max",children:[e.jsxs(s.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[e.jsx(u.Code,{className:"h-4 w-4"}),e.jsx("span",{children:"Edit"})]}),e.jsxs(s.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!p,children:[e.jsx(u.Eye,{className:"h-4 w-4"}),e.jsx("span",{children:"Preview"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:v==="edit"&&e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>m({...t,content:p}),disabled:!p,children:"Format"})})]}),e.jsxs(s.TabsContent,{value:"edit",children:[e.jsx(s.Textarea,{id:"new-content",value:t.content||"{}",onChange:o=>m({...t,content:o.target.value}),className:"font-mono text-sm",placeholder:"Enter JSON-LD markup...",rows:10}),!p&&t.content?e.jsx("p",{className:"pt-px text-xs text-red-500",children:"Invalid JSON-LD"}):e.jsx("p",{})]}),e.jsx(s.TabsContent,{value:"preview",children:e.jsx(s.Textarea,{id:"new-content",value:p||"{}",className:"bg-muted font-mono text-sm",placeholder:"{}",rows:10,readOnly:!0})})]})]}),!x&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Switch,{id:"add-to-all-existing",checked:j,onCheckedChange:o=>N(o)}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Switch,{id:"new-enabled",checked:t.enabledByDefaultForNewPages,onCheckedChange:o=>m({...t,enabledByDefaultForNewPages:o})}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("div",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{disabled:w,variant:"outline",type:"button",size:"sm",onClick:()=>h(),children:"Cancel"}),e.jsx(s.Button,{disabled:w||!p,type:"button",size:"sm",onClick:y,children:w?e.jsxs(e.Fragment,{children:[e.jsx(u.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):"Add Schema"})]})]})]})]})},G=({id:d,onClose:h})=>e.jsx(s.Dialog,{open:!!d,onOpenChange:()=>h(),children:d&&e.jsx(z,{id:d,onClose:h})}),z=({id:d,onClose:h})=>{const[x,v]=i.useState("edit"),[g,p]=i.useState(""),[n,t]=i.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[m,j]=i.useState(!1),[N,l]=i.useState(!1),{data:f}=O(),{mutateAsync:w,isPending:S}=c.useUpdateGlobalSchema(),{mutateAsync:y}=c.useApplySchemaToAllPages(),{mutateAsync:o}=c.useRemoveSchemaFromAllPages();i.useEffect(()=>{var r,D;if(v("edit"),d&&f){const a=f.find(T=>T.id===d);a&&t({name:a.name,description:((r=a.metadata)==null?void 0:r.description)||"",content:JSON.stringify(a.jsonld,null,2),enabledByDefaultForNewPages:((D=a.metadata)==null?void 0:D.addToNewPages)||!1})}},[d,f]),i.useEffect(()=>{const r=c.parseJSONWithPlaceholders(n.content);p(r.isValid?JSON.stringify(r.parsed,null,2):"")},[n.content]);const A=async()=>{if(!n.name||!n.content){J.toast.error("Please enter a name and content");return}const r=c.parseJSONWithPlaceholders(n.content);if(!r.isValid){J.toast.error("Invalid JSON-LD content");return}const D={id:d,name:n.name,jsonld:r.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),h()},b=async()=>{try{await y(d)}finally{j(!1)}},C=async()=>{try{await o(d)}finally{l(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:r=>t({...n,name:r.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:r=>t({...n,description:r.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsxs(s.Tabs,{value:x,onValueChange:v,className:"w-full",children:[e.jsxs("div",{className:"mb-2 flex w-full items-center justify-between",children:[e.jsxs(s.TabsList,{className:"w-max",children:[e.jsxs(s.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[e.jsx(u.Code,{className:"h-4 w-4"}),e.jsx("span",{children:"Edit"})]}),e.jsxs(s.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!g,children:[e.jsx(u.Eye,{className:"h-4 w-4"}),e.jsx("span",{children:"Preview"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:x==="edit"&&e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>t({...n,content:g}),disabled:!g,children:"Format"})})]}),e.jsxs(s.TabsContent,{value:"edit",children:[e.jsx(s.Textarea,{id:"edit-content",value:n.content||"{}",onChange:r=>t({...n,content:r.target.value}),className:"font-mono text-sm",placeholder:"Enter JSON-LD markup...",rows:10}),!g&&n.content?e.jsx("p",{className:"pt-px text-xs text-red-500",children:"Invalid JSON-LD"}):e.jsx("p",{})]}),e.jsx(s.TabsContent,{value:"preview",children:e.jsx(s.Textarea,{id:"edit-content-preview",value:g||"{}",className:"bg-muted font-mono text-sm",placeholder:"{}",rows:10,readOnly:!0})})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:()=>j(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>l(!0),children:"Remove from all"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Switch,{id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onCheckedChange:r=>t({...n,enabledByDefaultForNewPages:r})}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{disabled:S,variant:"outline",type:"button",size:"sm",onClick:()=>h(),children:"Cancel"}),e.jsx(s.Button,{disabled:S||!g,type:"button",size:"sm",onClick:A,children:S?e.jsxs(e.Fragment,{children:[e.jsx(u.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})]})]}),e.jsx(s.AlertDialog,{open:m,onOpenChange:j,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:b,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:N,onOpenChange:l,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:C,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function q(){const[d,h]=i.useState(!1),[x,v]=i.useState(void 0),[g,p]=i.useState(null),[n,t]=i.useState(null),{data:m,isLoading:j}=O(),{selectedLang:N}=E.useLanguages(),{data:l}=c.useCurrentPage(),{data:f}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:S}=c.useTogglePageGlobalSchema(),y=i.useMemo(()=>f==null?void 0:f.find(a=>a.primaryPage===!0),[f]),o=i.useMemo(()=>(y==null?void 0:y.globalJsonLds)||[],[y]),[A,b]=i.useState([]),C=A.length>0?A:(l==null?void 0:l.globalJsonLds)||[];i.useEffect(()=>{l!=null&&l.globalJsonLds&&b(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const r=async a=>{if(!(l!=null&&l.id))return;t(a);const T=C.includes(a),L=T?C.filter(P=>P!==a):[...C,a];b(L);try{await S({schemaId:a,pageId:l.id,enabled:!T})}catch{b(l.globalJsonLds)}finally{t(null)}},D=async a=>{t(a);try{await w(a)}finally{t(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!N&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:j,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),h(!0)},children:j?e.jsx(u.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(u.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!m||(m==null?void 0:m.length)===0)&&!j&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),m==null?void 0:m.map(a=>{const T=a.jsonld,L=!N,P=C.includes(a.id),F=o.includes(a.id);return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${n===a.id?"pointer-events-none":""}`,children:[n===a.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(u.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[L&&e.jsx(s.Switch,{checked:P,onCheckedChange:()=>r(a.id)}),e.jsxs("div",{children:[e.jsx(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:a.name}),(a==null?void 0:a.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:a==null?void 0:a.description})]})]}),L&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(a.id),children:e.jsx(u.Edit,{className:"h-4 w-4"})}),e.jsxs(s.AlertDialog,{children:[e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(u.Trash,{className:"h-4 w-4"})}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete ",e.jsx("span",{className:"font-medium",children:a.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>D(a.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})}),e.jsx(s.CardContent,{className:"px-2 pb-2",children:L?e.jsx(s.Textarea,{id:a.id,rows:1,readOnly:!0,value:JSON.stringify(T,null,2),className:"no-scrollbar cursor-text overflow-hidden rounded-md border-none bg-gray-100/80 text-xs"}):e.jsxs("div",{className:"flex h-20 w-full flex-col items-center justify-center rounded-lg border bg-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"max-w-xl text-center text-xs text-gray-500",children:"Not available in selected language, but available in default language."}),F&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{v({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:N}),h(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),j&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(u.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(k,{show:d,onClose:()=>{h(!1),v(void 0)},initialData:x}),e.jsx(G,{id:g,onClose:()=>p(null)})]})}exports.default=q;
|