@chaibuilder/sdk 4.0.0-beta.47 → 4.0.0-beta.49
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/{2SSKDMRQ-CVHl6i14.cjs → 2SSKDMRQ-CjvuNdPo.cjs} +1 -1
- package/dist/{2SSKDMRQ-D9rlRpnI.js → 2SSKDMRQ-Dvf9zadl.js} +2 -2
- package/dist/{AP7HFJJL-D18sv0Wh.cjs → AP7HFJJL-DYFttFoI.cjs} +1 -1
- package/dist/{AP7HFJJL-CBrphwP9.js → AP7HFJJL-q4dJdyFs.js} +1 -1
- package/dist/{IconPicker-CSewv0kY.js → IconPicker-Bf163F7t.js} +1 -1
- package/dist/{IconPicker-CxEGCcVZ.cjs → IconPicker-JWhYq2Gp.cjs} +1 -1
- package/dist/{WDYDFRGG-C0G8c0hR.cjs → WDYDFRGG-BEksfGMC.cjs} +1 -1
- package/dist/{WDYDFRGG-BCmjXFs0.js → WDYDFRGG-O9GIrtX0.js} +2 -2
- package/dist/{actions-registery-BQ31lpix.cjs → actions-registery-BHbZHkE3.cjs} +11 -3
- package/dist/{actions-registery-B1VeX52Y.js → actions-registery-gJb_wq2F.js} +25 -13
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.ts +10 -3
- package/dist/actions.js +6 -4
- package/dist/{active-in-another-tab-BhbPijx9.js → active-in-another-tab-B4Ur0JP7.js} +2 -2
- package/dist/{active-in-another-tab-CMmhCRma.cjs → active-in-another-tab-BPdx4lWh.cjs} +1 -1
- package/dist/{add-new-language-page-ChQgjFwb.cjs → add-new-language-page-BfUp5Ua2.cjs} +1 -1
- package/dist/{add-new-language-page-C0sayTSF.js → add-new-language-page-CRR93tLq.js} +3 -3
- package/dist/{add-new-page-DLf5Tfb7.cjs → add-new-page-B8NGK6WS.cjs} +1 -1
- package/dist/{add-new-page-DLKzuaNM.js → add-new-page-Ppy5-y5j.js} +2 -2
- package/dist/ai-panel-default-lang-BXYQye3N.js +333 -0
- package/dist/ai-panel-default-lang-VhgmHFoQ.cjs +3 -0
- package/dist/ai-panel-other-lang-DaCf-cq4.js +148 -0
- package/dist/ai-panel-other-lang-Ds0EXeUC.cjs +1 -0
- package/dist/{ai-prompt-input-DNb1FKXQ.js → ai-prompt-input-7iWk72w5.js} +253 -258
- package/dist/ai-prompt-input-nZ5_Dm7X.cjs +1 -0
- package/dist/{ai-translation-prompt-B2MfzTjb.js → ai-translation-prompt-1OUs1P7n.js} +1 -1
- package/dist/{ai-translation-prompt-CL3yk8K1.cjs → ai-translation-prompt-B16cK-1Q.cjs} +1 -1
- package/dist/{change-password-modal-CbMifP62.js → change-password-modal-CdvJR1Ln.js} +10 -10
- package/dist/{change-password-modal-D_NFPZxI.cjs → change-password-modal-D5eXjiYq.cjs} +1 -1
- package/dist/{code-editor-53rOkfhX.js → code-editor-CyLjDiEp.js} +1 -1
- package/dist/{code-editor-CCsljULB.cjs → code-editor-SWbfFj1E.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-hB4O3CHJ.js → continue-editing-in-this-client-BrSvK-Ay.js} +2 -2
- package/dist/{continue-editing-in-this-client-3QLL7tQH.cjs → continue-editing-in-this-client-Cmi-GkYZ.cjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{css-import-modal-Bmi3LrEJ.cjs → css-import-modal-Bdwgd05S.cjs} +1 -1
- package/dist/{css-import-modal-DCivkVh2.js → css-import-modal-Be47CBJn.js} +1 -1
- package/dist/{delete-page-BW2NxLZu.js → delete-page-C99K2qzS.js} +15 -15
- package/dist/{delete-page-CxVfKrBz.cjs → delete-page-DLohaU-U.cjs} +1 -1
- package/dist/{design-token-usage-WTVjf9c-.js → design-token-usage-D1lWCJ3L.js} +1 -1
- package/dist/{design-token-usage-5jsa9ojN.cjs → design-token-usage-eY2wQ0l3.cjs} +1 -1
- package/dist/{digital-asset-manager-dNK-BYdI.js → digital-asset-manager-BZMb6sC7.js} +3 -3
- package/dist/{digital-asset-manager-DlFCWUP4.cjs → digital-asset-manager-Z5aJxkq0.cjs} +1 -1
- package/dist/{duplicate-page-BbB2anQO.js → duplicate-page-CDc2X0eW.js} +12 -12
- package/dist/{duplicate-page-0o6G-oY_.cjs → duplicate-page-D5Gtvqdv.cjs} +1 -1
- package/dist/{dynamic-page-selector-Ds3MqxTF.cjs → dynamic-page-selector-DZHhX008.cjs} +1 -1
- package/dist/{dynamic-page-selector-rFO8457w.js → dynamic-page-selector-DvNBXo6o.js} +2 -2
- package/dist/{image-editor-BnVkes6Q.js → image-editor-BBvvi9Vm.js} +1 -1
- package/dist/{image-editor-DqItmbk1.cjs → image-editor-DwhTYkVR.cjs} +1 -1
- package/dist/index-BVwFJWDq.cjs +5 -0
- package/dist/{index-DTNHTRZu.cjs → index-DCJDQs1a.cjs} +8 -8
- package/dist/{index-BYjniKhj.js → index-LBTm1Jmk.js} +838 -806
- package/dist/{index-B7HAfx-2.js → index-OuHV9Ann.js} +16 -9
- package/dist/{json-diff-viewer-B4rnFiN_.cjs → json-diff-viewer-Cb1CmRqP.cjs} +1 -1
- package/dist/{json-diff-viewer-CKlyO9eW.js → json-diff-viewer-DG6qMOBS.js} +6 -6
- package/dist/{lang-panel-YT96E5Xj.js → lang-panel-B3USOxGq.js} +9 -9
- package/dist/{lang-panel-DiVz4Cay.cjs → lang-panel-DxoJ0v4y.cjs} +1 -1
- package/dist/{manage-design-tokens-LwImeKaK.js → manage-design-tokens-6YGIctip.js} +2 -2
- package/dist/{manage-design-tokens-modal-BEElCTcN.cjs → manage-design-tokens-modal-BSSCXH8Y.cjs} +1 -1
- package/dist/{manage-design-tokens-modal-DFVcoyra.js → manage-design-tokens-modal-CzsnN49F.js} +2 -2
- package/dist/{manage-design-tokens-BwrIc6dS.cjs → manage-design-tokens-udLBvkHA.cjs} +1 -1
- package/dist/{mark-as-template-DtDkh6jB.cjs → mark-as-template-B9yLcasI.cjs} +1 -1
- package/dist/{mark-as-template-D2Hpz0IE.js → mark-as-template-CP_F9ZQ4.js} +2 -2
- package/dist/{models-D0RH2u4C.cjs → models-CQaC3EBW.cjs} +1 -1
- package/dist/{models-BCu-p_QK.js → models-DZ9C6CvE.js} +4 -5
- package/dist/{nested-path-selector-content-TqjBbNys.js → nested-path-selector-content-DmtCI3q9.js} +1 -1
- package/dist/{nested-path-selector-content-CJfN8Hhw.cjs → nested-path-selector-content-aTdu-o0e.cjs} +1 -1
- package/dist/{no-language-page-content-CcD-fgMa.cjs → no-language-page-content-C-MCdPXt.cjs} +1 -1
- package/dist/{no-language-page-content-Ce3wniZT.js → no-language-page-content-D8t5dfgh.js} +2 -2
- package/dist/{no-language-page-dialog-CU1zXsYv.js → no-language-page-dialog-C_fHI2zI.js} +2 -2
- package/dist/{no-language-page-dialog-B7fhPdob.cjs → no-language-page-dialog-D4QIAHnE.cjs} +1 -1
- package/dist/{page-creator-C7XEqUx_.cjs → page-creator-Cz_ah-qE.cjs} +1 -1
- package/dist/{page-creator-wg3uymVG.js → page-creator-DKEkuGCO.js} +33 -33
- package/dist/{page-lock-BuVma3e5.js → page-lock-CwZKJ4IE.js} +2 -2
- package/dist/{page-lock-CINb2air.cjs → page-lock-DdCvtA-I.cjs} +1 -1
- package/dist/{page-locked-dialog-s-3ROcy0.cjs → page-locked-dialog-CrTDBoC4.cjs} +1 -1
- package/dist/{page-locked-dialog-C7_1gjO5.js → page-locked-dialog-DqLlooUz.js} +11 -11
- package/dist/{page-manager-new-CKWSLVrb.cjs → page-manager-new-ah6QYar2.cjs} +1 -1
- package/dist/{page-manager-new-zlobCGqL.js → page-manager-new-ttsrxdW9.js} +42 -42
- package/dist/{page-manager-search-and-filter-BaOsl_5u.cjs → page-manager-search-and-filter-D7AupT6_.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-BU_iNmHy.js → page-manager-search-and-filter-bsqZ6wnI.js} +2 -2
- package/dist/{page-revisions-content-BmaNPNoS.cjs → page-revisions-content-B6hsIla7.cjs} +1 -1
- package/dist/{page-revisions-content-D6l_d2jW.js → page-revisions-content-C5O8_Fms.js} +16 -16
- package/dist/pages.cjs +1 -1
- package/dist/pages.d.ts +66 -1
- package/dist/pages.js +19 -19
- package/dist/{publish-pages-content-2LG6JOrm.cjs → publish-pages-content-BrajJUcP.cjs} +1 -1
- package/dist/{publish-pages-content-CQteRtBA.js → publish-pages-content-KZVMHT6V.js} +32 -32
- package/dist/{rte-widget-modal-KzT2hLFt.cjs → rte-widget-modal-CiTwsXTr.cjs} +1 -1
- package/dist/{rte-widget-modal-CFk0Izg5.js → rte-widget-modal-IU8JzPuZ.js} +1 -1
- package/dist/{save-to-lib-D1V3bNZX.js → save-to-lib-DMnv7ENo.js} +50 -50
- package/dist/{save-to-lib-D82Vrekv.cjs → save-to-lib-Dc700Aop.cjs} +1 -1
- package/dist/{selected-block-display-BHx9N14K.cjs → selected-block-display-CAFEOrLV.cjs} +1 -1
- package/dist/{selected-block-display-BbUH5RaW.js → selected-block-display-CidmQ-wz.js} +2 -2
- package/dist/{seo-panel-CyBmGg6k.js → seo-panel-Br8gxDxu.js} +148 -158
- package/dist/{seo-panel-CPsjZLtL.cjs → seo-panel-CMY-adM-.cjs} +2 -2
- package/dist/{shared-json-ld-DyU9wqrE.cjs → shared-json-ld-CMH-eRUq.cjs} +1 -1
- package/dist/{shared-json-ld-SGykyppC.js → shared-json-ld-uvMmwCYp.js} +26 -26
- package/dist/{slug-input-BzpnOdXG.cjs → slug-input-CiHC5l3r.cjs} +1 -1
- package/dist/{slug-input-DpMI4nEB.js → slug-input-DLWTMTsO.js} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.js +1 -1
- package/dist/{take-over-request-wTVLAotu.cjs → take-over-request-IRLgF1dG.cjs} +1 -1
- package/dist/{take-over-request-D97Fg-xB.js → take-over-request-KdR1_h_K.js} +5 -5
- package/dist/{translation-warning-modal-Xk6oYGFS.cjs → translation-warning-modal-CLZ9tC1F.cjs} +1 -1
- package/dist/{translation-warning-modal-Du-CnfyH.js → translation-warning-modal-CzNt6LDO.js} +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/{unmark-as-template-BHk2F0ck.js → unmark-as-template-C5ovsEBP.js} +2 -2
- package/dist/{unmark-as-template-BRnMhh7n.cjs → unmark-as-template-F7TdgWjI.cjs} +1 -1
- package/dist/{unpublish-page-BOEjCHLB.js → unpublish-page-0fR1o0b7.js} +8 -8
- package/dist/{unpublish-page-Bu75lH33.cjs → unpublish-page-CUr8Xub6.cjs} +1 -1
- package/dist/{unpublished-partials-modal-C0_0qNvV.js → unpublished-partials-modal-BhNAub_z.js} +1 -1
- package/dist/{unpublished-partials-modal-BS_GddEG.cjs → unpublished-partials-modal-Cv5R9-hi.cjs} +1 -1
- package/dist/{web-preview-DcOhTGup.cjs → web-preview-CuMYekVJ.cjs} +1 -1
- package/dist/{web-preview-C3bbIF6T.js → web-preview-D9pXonAv.js} +1 -1
- package/package.json +1 -1
- package/dist/ai-panel-default-lang-DsGjoITc.cjs +0 -3
- package/dist/ai-panel-default-lang-Dy_4L5pH.js +0 -317
- package/dist/ai-panel-other-lang-1RYtb71B.js +0 -132
- package/dist/ai-panel-other-lang-CL3coL7Z.cjs +0 -1
- package/dist/ai-prompt-input-BhTL_-mT.cjs +0 -1
- package/dist/index-BeGLwvqs.cjs +0 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-
|
|
2
|
-
`).replace(/\\"/g,'"').replace(/___DOUBLE_BACKSLASH___/g,"\\")),p==="jsonLD"||p==="metaOther")){n.includes("```")&&(n=n.replace(/^```json\s*/i,"").replace(/^```\s*/,"").replace(/\s*```$/m,"")),n=n.trim();try{JSON.parse(n)}catch{return{success:!1,error:"The AI response is not valid JSON. Please try again or edit manually."}}}return{success:!0,value:n}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ge=({isOpen:t,onClose:p,onSave:n,onDiscard:d,isSaving:l=!1,fromLanguage:N,toLanguage:x})=>{const h=i.LANGUAGES[N]||N,g=i.LANGUAGES[x]||x;return e.jsx(r.Dialog,{open:t,onOpenChange:p,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(r.DialogDescription,{children:['You have unsaved changes in the SEO for "',h,'" version. Do you want to save these changes before switching to "',g,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(f.Button,{variant:"outline",onClick:d,disabled:l,children:"Discard Changes"}),e.jsx(f.Button,{onClick:n,disabled:l,children:l?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},xe=(t,p)=>{const n=t.selectionStart||0,d=t.selectionEnd||0,l=t.value,N=l.substring(0,n),x=l.substring(d),h=`{{${p}}}`,g=N+""+h+x,I=n+0+h.length;return{value:g,newCursorPos:I}},Q=()=>{const{t}=ie.useTranslation(),[,p]=r.useSidebarActivePanel(),{data:n}=i.usePrimaryPage(),{data:d}=i.useBuilderPageData(),{data:l,isFetching:N}=ue(),x=l==null?void 0:l.seo,h=w.useRef(null),[g,I]=w.useState("seo"),F=n==null?void 0:n.id,Y=n==null?void 0:n.pageType,E=i.usePageType(Y),{selectedLang:M,fallbackLang:X}=r.useLanguages(),m=M||X,[H,P]=w.useState(!1),[Z,$]=w.useState(!1),[ee,q]=w.useState(!1),[b,B]=w.useState(null),[o,D]=w.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...x}),A=w.useRef({}),{mutate:se,isPending:U}=i.useUpdatePage(),y=U||H||Z,{hasPermission:te}=r.usePermissions(),a=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ne]=i.usePagesProps(),oe=u.get(ne,"flags.resetSeoToDefault",!1),W=!M||o.jsonLD!=="{}";w.useEffect(()=>{if(!N&&x&&F){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...x};D(s),A.current[m]=s}},[N,x,m,F]),w.useEffect(()=>{const s=c=>{const{fromLang:j,toLang:J,switchHandler:v}=c.detail,_=A.current[m];(_?!u.isEqual(_,o):!1)?(B({fromLang:j,toLang:J,switchHandler:v}),q(!0)):v()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[F,o,m]);const ae=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,keyword:u.get(s,"seo.keyword",""),title:u.get(s,"seo.title",""),description:u.get(s,"seo.description",""),cononicalUrl:u.get(s,"seo.canonicalUrl",""),noIndex:u.get(s,"seo.noIndex",!1),noFollow:u.get(s,"seo.noFollow",!1),ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription","")};D(c),O.toast.success(t("SEO fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{P(!1)}},re=async()=>{if(!(!E||!m))try{$(!0);const s=G.getSeoDefaults(E,m),c={...o,jsonLD:u.get(s,"seo.jsonLD","")};D(c),O.toast.success(t("JSON-LD reset to default"))}catch(s){O.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{$(!1)}},le=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription",""),ogImage:u.get(s,"seo.ogImage",""),ogImageId:u.get(s,"seo.ogImageId",""),metaOther:u.get(s,"seo.metaOther","{}")};D(c),O.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{P(!1)}},z=async()=>{se({id:l==null?void 0:l.id,seo:o,primaryPage:F},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",o),A.current[m]=o,O.toast.success("SEO & JSON-LD updated successfully")}})},L=(s,c)=>{const j=document.getElementById(c);if(j){const{value:J,newCursorPos:v}=xe(j,s);h.current={id:c,position:v},j.tagName.toLowerCase()==="input"?(j.value=J,D(k=>({...k,[j.name]:J})),j.focus(),j.setSelectionRange(v,v),[0,10,50,100,200].forEach(k=>{setTimeout(()=>{const V=document.getElementById(c);V&&(V.focus(),V.setSelectionRange(v,v))},k)})):(D(T=>({...T,[j.name]:J})),requestAnimationFrame(()=>{const T=document.getElementById(c);T&&(T.focus(),T.setSelectionRange(v,v),setTimeout(()=>{const k=document.getElementById(c);k&&(k.focus(),k.setSelectionRange(v,v))},50))}))}},S=s=>{const c={...o,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};D(c)},C=s=>c=>{if(!u.isEmpty(c.fieldValue)){const j=he(c.fieldValue,s);j.success?S({target:{name:s,value:j.value}}):O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to process AI response:"}),e.jsx("p",{children:j.error})]}))}c.error&&O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:c.error})]}))},ce=()=>{const s=u.get(n,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){O.toast.error("Default page JSON-LD is empty");return}S({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!a&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(f.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(f.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:l==null?void 0:l.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:l==null?void 0:l.slug})]}),e.jsx(i.LanguageSwitcher,{showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Tabs,{value:g,onValueChange:I,className:"w-full",children:[e.jsxs(r.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(r.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(r.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(r.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:g==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"keyword")})]}),e.jsx(f.Input,{type:"text",id:"keyword",name:"keyword",value:o.keyword,onChange:S,disabled:y||!a,placeholder:t("Enter keyword"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("title"),field:"title"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"title")})]})]}),e.jsx(f.Input,{type:"text",id:"title",name:"title",value:o.title,onChange:S,disabled:y||!a,placeholder:t("Enter SEO title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("description"),field:"description"}),a&&e.jsx(i.NestedPathSelector,{data:d??{},onSelect:s=>L(s,"description")})]})]}),e.jsx(r.Textarea,{id:"description",name:"description",rows:5,value:o.description,onChange:S,disabled:y||!a,placeholder:t("Enter SEO description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"canonicalUrl")})]}),e.jsx(f.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:o.canonicalUrl,onChange:S,disabled:y||!a,placeholder:t("Enter Canonical URL"),readOnly:!a})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:o.noIndex,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:o.noFollow,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:g==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogTitle"),field:"ogTitle"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogTitle")})]})]}),e.jsx(f.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:o.ogTitle,onChange:S,disabled:y||!a,placeholder:t("Enter OG title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogDescription"),field:"ogDescription"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogDescription")})]})]}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:o.ogDescription,onChange:S,disabled:y||!a,placeholder:t("Enter OG description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>{D({...o,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:o.ogImageId,assetUrl:o.ogImage,onChange:s=>{D({...o,ogImage:s.url,ogImageId:s.id})},disabled:y||!a,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:o.metaOther,onChange:s=>{S({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:8,handleFieldInsert:L})]})]})]})})}),e.jsx("div",{className:g==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),W&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(d)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:o.jsonLD,onChange:s=>{S({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:12,handleFieldInsert:L,hasJsonLdForSelectedLang:W,copyJsonLDFromDefaultPage:ce})]})})})]})})]}),a&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[oe?e.jsx(f.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{g==="jsonld"?re():g==="opengraph"?le():ae()},disabled:y||!a||!E,children:t(H?"Resetting...":`Reset to ${g==="jsonld"?"Default JSON-LD":g==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f.Button,{onClick:z,disabled:!me(o==null?void 0:o.jsonLD)||(A.current[m]?u.isEqual(A.current[m],o):!1)||y||!a,children:t(U?"Saving...":"Save")}),e.jsx(f.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>p("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{q(!1),B(null)},onSave:async()=>{b&&(await z(),b.switchHandler(),q(!1),B(null))},onDiscard:()=>{if(b){const s=A.current[m];s&&D(s),b.switchHandler(),q(!1),B(null)}},isSaving:U,fromLanguage:(b==null?void 0:b.fromLang)||m,toLanguage:(b==null?void 0:b.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-BVwFJWDq.cjs"),r=require("./index-DCJDQs1a.cjs"),u=require("lodash-es"),w=require("react"),f=require("./register-chai-top-bar-DyW9GPzV.cjs"),ie=require("react-i18next"),I=require("sonner"),de=require("@tanstack/react-query"),K=require("lucide-react"),G=require("./get-seo-defaults-Cw7vFt-B.cjs"),ue=()=>{const{selectedLang:t}=r.useLanguages(),{data:p,isFetching:n}=i.useLanguagePages();return{data:w.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:n}},pe=()=>{var x;const p=(x=document.getElementById("canvas-iframe").contentDocument)==null?void 0:x.body.innerHTML;if(!p)return null;const d=new DOMParser().parseFromString(p,"text/html");d.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(h=>h.remove()),d.querySelectorAll("*").forEach(h=>{Array.from(h.attributes).forEach(g=>h.removeAttribute(g.name))});const l=d.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(l).map(h=>`<${h.tagName.toLowerCase()}>${h.innerHTML}</${h.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},J=({keyword:t,onComplete:p,field:n})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:N,fallbackLang:x}=r.useLanguages(),{mutate:h,isPending:g}=de.useMutation({mutationFn:async()=>{const O=pe();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:n,lang:N||x,pageContent:O,keyword:t}})},onSuccess:O=>{p({fieldValue:O.field})},onError:O=>{p({fieldValue:null,error:O.message})}});return e.jsx(f.Button,{disabled:g,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:g?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},he=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let n=t;if(typeof n=="string"&&(/^".*"$/.test(n)&&(n=n.replace(/^"(.*)"$/,"$1"),n=n.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
|
|
2
|
+
`).replace(/\\"/g,'"').replace(/___DOUBLE_BACKSLASH___/g,"\\")),p==="jsonLD"||p==="metaOther")){n.includes("```")&&(n=n.replace(/^```json\s*/i,"").replace(/^```\s*/,"").replace(/\s*```$/m,"")),n=n.trim();try{JSON.parse(n)}catch{return{success:!1,error:"The AI response is not valid JSON. Please try again or edit manually."}}}return{success:!0,value:n}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ge=({isOpen:t,onClose:p,onSave:n,onDiscard:d,isSaving:l=!1,fromLanguage:N,toLanguage:x})=>{const h=i.LANGUAGES[N]||N,g=i.LANGUAGES[x]||x;return e.jsx(r.Dialog,{open:t,onOpenChange:p,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(r.DialogDescription,{children:['You have unsaved changes in the SEO for "',h,'" version. Do you want to save these changes before switching to "',g,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(f.Button,{variant:"outline",onClick:d,disabled:l,children:"Discard Changes"}),e.jsx(f.Button,{onClick:n,disabled:l,children:l?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},xe=(t,p)=>{const n=t.selectionStart||0,d=t.selectionEnd||0,l=t.value,N=l.substring(0,n),x=l.substring(d),h=`{{${p}}}`,g=N+""+h+x,O=n+0+h.length;return{value:g,newCursorPos:O}},Q=()=>{const{t}=ie.useTranslation(),[,p]=r.useSidebarActivePanel(),{data:n}=i.usePrimaryPage(),{data:d}=i.useBuilderPageData(),{data:l,isFetching:N}=ue(),x=l==null?void 0:l.seo,h=w.useRef(null),[g,O]=w.useState("seo"),C=n==null?void 0:n.id,Y=n==null?void 0:n.pageType,E=i.usePageType(Y),{selectedLang:M,fallbackLang:X}=r.useLanguages(),m=M||X,[H,P]=w.useState(!1),[Z,$]=w.useState(!1),[ee,q]=w.useState(!1),[b,B]=w.useState(null),[o,D]=w.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...x}),A=w.useRef({}),{mutate:se,isPending:U}=i.useUpdatePage(),y=U||H||Z,{hasPermission:te}=r.usePermissions(),a=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ne]=i.usePagesProps(),oe=u.get(ne,"flags.resetSeoToDefault",!1),W=!M||o.jsonLD!=="{}";w.useEffect(()=>{if(!N&&x&&C){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...x};D(s),A.current[m]=s}},[N,x,m,C]),w.useEffect(()=>{const s=c=>{const{fromLang:j,toLang:F,switchHandler:v}=c.detail,_=A.current[m];(_?!u.isEqual(_,o):!1)?(B({fromLang:j,toLang:F,switchHandler:v}),q(!0)):v()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[C,o,m]);const ae=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,keyword:u.get(s,"seo.keyword",""),title:u.get(s,"seo.title",""),description:u.get(s,"seo.description",""),cononicalUrl:u.get(s,"seo.canonicalUrl",""),noIndex:u.get(s,"seo.noIndex",!1),noFollow:u.get(s,"seo.noFollow",!1),ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription","")};D(c),I.toast.success(t("SEO fields reset to defaults"))}catch(s){I.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{P(!1)}},re=async()=>{if(!(!E||!m))try{$(!0);const s=G.getSeoDefaults(E,m),c={...o,jsonLD:u.get(s,"seo.jsonLD","")};D(c),I.toast.success(t("JSON-LD reset to default"))}catch(s){I.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{$(!1)}},le=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription",""),ogImage:u.get(s,"seo.ogImage",""),ogImageId:u.get(s,"seo.ogImageId",""),metaOther:u.get(s,"seo.metaOther","{}")};D(c),I.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){I.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{P(!1)}},z=async()=>{se({id:l==null?void 0:l.id,seo:o,primaryPage:C},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",o),A.current[m]=o,I.toast.success("SEO & JSON-LD updated successfully")}})},L=(s,c)=>{const j=document.getElementById(c);if(j){const{value:F,newCursorPos:v}=xe(j,s);h.current={id:c,position:v},j.tagName.toLowerCase()==="input"?(j.value=F,D(k=>({...k,[j.name]:F})),j.focus(),j.setSelectionRange(v,v),[0,10,50,100,200].forEach(k=>{setTimeout(()=>{const V=document.getElementById(c);V&&(V.focus(),V.setSelectionRange(v,v))},k)})):(D(T=>({...T,[j.name]:F})),requestAnimationFrame(()=>{const T=document.getElementById(c);T&&(T.focus(),T.setSelectionRange(v,v),setTimeout(()=>{const k=document.getElementById(c);k&&(k.focus(),k.setSelectionRange(v,v))},50))}))}},S=s=>{const c={...o,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};D(c)},R=s=>c=>{if(!u.isEmpty(c.fieldValue)){const j=he(c.fieldValue,s);j.success?S({target:{name:s,value:j.value}}):I.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to process AI response:"}),e.jsx("p",{children:j.error})]}))}c.error&&I.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:c.error})]}))},ce=()=>{const s=u.get(n,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){I.toast.error("Default page JSON-LD is empty");return}S({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!a&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(f.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(f.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:l==null?void 0:l.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:l==null?void 0:l.slug})]}),e.jsx(i.LanguageSwitcher,{showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Tabs,{value:g,onValueChange:O,className:"w-full",children:[e.jsxs(r.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(r.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(r.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(r.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:g==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"keyword")})]}),e.jsx(f.Input,{type:"text",id:"keyword",name:"keyword",value:o.keyword,onChange:S,disabled:y||!a,placeholder:t("Enter keyword"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(J,{keyword:o.keyword,onComplete:R("title"),field:"title"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"title")})]})]}),e.jsx(f.Input,{type:"text",id:"title",name:"title",value:o.title,onChange:S,disabled:y||!a,placeholder:t("Enter SEO title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{keyword:o.keyword,onComplete:R("description"),field:"description"}),a&&e.jsx(i.NestedPathSelector,{data:d??{},onSelect:s=>L(s,"description")})]})]}),e.jsx(r.Textarea,{id:"description",name:"description",rows:5,value:o.description,onChange:S,disabled:y||!a,placeholder:t("Enter SEO description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"canonicalUrl")})]}),e.jsx(f.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:o.canonicalUrl,onChange:S,disabled:y||!a,placeholder:t("Enter Canonical URL"),readOnly:!a})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:o.noIndex,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:o.noFollow,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:g==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{keyword:o.keyword,onComplete:R("ogTitle"),field:"ogTitle"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogTitle")})]})]}),e.jsx(f.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:o.ogTitle,onChange:S,disabled:y||!a,placeholder:t("Enter OG title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{keyword:o.keyword,onComplete:R("ogDescription"),field:"ogDescription"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogDescription")})]})]}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:o.ogDescription,onChange:S,disabled:y||!a,placeholder:t("Enter OG description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>{D({...o,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:o.ogImageId,assetUrl:o.ogImage,onChange:s=>{D({...o,ogImage:s.url,ogImageId:s.id})},disabled:y||!a,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")})}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:o.metaOther,onChange:s=>{S({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:8,handleFieldInsert:L})]})]})]})})}),e.jsx("div",{className:g==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),W&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(J,{keyword:o.keyword,onComplete:R("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(d)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:o.jsonLD,onChange:s=>{S({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:12,handleFieldInsert:L,hasJsonLdForSelectedLang:W,copyJsonLDFromDefaultPage:ce})]})})})]})})]}),a&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[oe?e.jsx(f.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{g==="jsonld"?re():g==="opengraph"?le():ae()},disabled:y||!a||!E,children:t(H?"Resetting...":`Reset to ${g==="jsonld"?"Default JSON-LD":g==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f.Button,{onClick:z,disabled:!me(o==null?void 0:o.jsonLD)||(A.current[m]?u.isEqual(A.current[m],o):!1)||y||!a,children:t(U?"Saving...":"Save")}),e.jsx(f.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>p("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{q(!1),B(null)},onSave:async()=>{b&&(await z(),b.switchHandler(),q(!1),B(null))},onDiscard:()=>{if(b){const s=A.current[m];s&&D(s),b.switchHandler(),q(!1),B(null)}},isSaving:U,fromLanguage:(b==null?void 0:b.fromLang)||m,toLanguage:(b==null?void 0:b.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DTNHTRZu.cjs"),h=require("./register-chai-top-bar-DyW9GPzV.cjs"),c=require("./index-BeGLwvqs.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.usePrimaryPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.id]})),d()};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:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(h.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(h.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(h.Input,{id:"new-name",value:r.name,onChange:l=>j({...r,name:l.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(h.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>j({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&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("input",{type:"checkbox",id:"add-to-all-existing",checked:b,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>j({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(h.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(h.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((m=v.metadata)==null?void 0:m.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!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:[!S&&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(h.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(h.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(h.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.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(h.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(h.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(h.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,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:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,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:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.usePrimaryPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(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"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.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:[(!u||(u==null?void 0:u.length)===0)&&!w&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:g})=>{var B,G;const P=E.includes(o.id),J=m.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===o.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(N.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:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,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(N.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),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:o.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:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),J&&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(h.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DCJDQs1a.cjs"),h=require("./register-chai-top-bar-DyW9GPzV.cjs"),c=require("./index-BVwFJWDq.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.usePrimaryPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.id]})),d()};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:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(h.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(h.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(h.Input,{id:"new-name",value:r.name,onChange:l=>j({...r,name:l.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(h.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>j({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&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("input",{type:"checkbox",id:"add-to-all-existing",checked:b,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>j({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(h.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(h.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((m=v.metadata)==null?void 0:m.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!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:[!S&&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(h.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(h.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(h.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.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(h.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),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.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(h.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(h.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,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:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,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:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.usePrimaryPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(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"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.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:[(!u||(u==null?void 0:u.length)===0)&&!w&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:g})=>{var B,G;const P=E.includes(o.id),J=m.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===o.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(N.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:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,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(N.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),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:o.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:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),J&&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(h.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as e, jsxs as n, Fragment as j } from "react/jsx-runtime";
|
|
2
|
-
import { D as $, e as W, f as Y, g as X, p as y, a1 as U, a2 as _, at as R, a3 as M, a4 as q, au as H, a5 as K, a6 as Q, d as me, z as L, A as
|
|
2
|
+
import { D as $, e as W, f as Y, g as X, p as y, a1 as U, a2 as _, at as R, a3 as M, a4 as q, au as H, a5 as K, a6 as Q, d as me, z as L, A as J, E as F, a7 as he, J as ue, K as ge, M as fe, av as pe, O as xe, T as Ne } from "./index-OuHV9Ann.js";
|
|
3
3
|
import { D as be, F as ye, z as G, B as v } from "./register-chai-top-bar-D6GjnauV.js";
|
|
4
|
-
import {
|
|
4
|
+
import { aq as ve, ar as we, A as V, av as le, aD as Ae, aE as se, aF as re, aG as de, aH as Se, aI as Ce, aJ as Pe, j as Te, aK as De } from "./index-LBTm1Jmk.js";
|
|
5
5
|
import { useQuery as Ee, useQueryClient as Le } from "@tanstack/react-query";
|
|
6
|
-
import { filter as
|
|
6
|
+
import { filter as Je, find as Fe } from "lodash-es";
|
|
7
7
|
import { Info as Oe, Loader as O, Plus as ke, Eye as je, Edit as Ge, Trash as Be } from "lucide-react";
|
|
8
8
|
import { useState as g, useEffect as Z, useMemo as z } from "react";
|
|
9
9
|
import { toast as B } from "sonner";
|
|
@@ -27,14 +27,14 @@ const oe = () => {
|
|
|
27
27
|
content: "",
|
|
28
28
|
description: "",
|
|
29
29
|
enabledByDefaultForNewPages: !1
|
|
30
|
-
}), [x,
|
|
30
|
+
}), [x, C] = g(!1), { data: u } = le(), { mutateAsync: S, isPending: p } = Ae(), { mutateAsync: c } = se(), w = Le();
|
|
31
31
|
Z(() => {
|
|
32
32
|
f(a ? {
|
|
33
33
|
name: a.name,
|
|
34
34
|
description: a.description,
|
|
35
35
|
content: JSON.stringify(a.jsonld, null, 2),
|
|
36
36
|
enabledByDefaultForNewPages: !1
|
|
37
|
-
} : { name: "", description: "", content: "", enabledByDefaultForNewPages: !1 }),
|
|
37
|
+
} : { name: "", description: "", content: "", enabledByDefaultForNewPages: !1 }), C(!1);
|
|
38
38
|
}, [t, a]);
|
|
39
39
|
const o = async () => {
|
|
40
40
|
if (!d.name || !d.content) {
|
|
@@ -54,7 +54,7 @@ const oe = () => {
|
|
|
54
54
|
description: d.description
|
|
55
55
|
};
|
|
56
56
|
a != null && a.primaryPageId && (N.primaryPage = a.primaryPageId);
|
|
57
|
-
const A = await
|
|
57
|
+
const A = await S(N);
|
|
58
58
|
u != null && u.id && (A != null && A.id) && !(a != null && a.primaryPageId) && (await c({
|
|
59
59
|
schemaId: A.id,
|
|
60
60
|
pageId: u.id,
|
|
@@ -120,7 +120,7 @@ const oe = () => {
|
|
|
120
120
|
type: "checkbox",
|
|
121
121
|
id: "add-to-all-existing",
|
|
122
122
|
checked: x,
|
|
123
|
-
onChange: (l) =>
|
|
123
|
+
onChange: (l) => C(l.target.checked),
|
|
124
124
|
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
125
125
|
}
|
|
126
126
|
),
|
|
@@ -164,7 +164,7 @@ const oe = () => {
|
|
|
164
164
|
content: "",
|
|
165
165
|
description: "",
|
|
166
166
|
enabledByDefaultForNewPages: !1
|
|
167
|
-
}), [f, x] = g(!1), [
|
|
167
|
+
}), [f, x] = g(!1), [C, u] = g(!1), [S, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Se(), { mutateAsync: l } = Ce(), { mutateAsync: N } = Pe();
|
|
168
168
|
Z(() => {
|
|
169
169
|
var m, T;
|
|
170
170
|
if (t && c) {
|
|
@@ -211,7 +211,7 @@ const oe = () => {
|
|
|
211
211
|
return /* @__PURE__ */ n(W, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
|
|
212
212
|
/* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(X, { children: "Edit Shared JSON-LD Schema" }) }),
|
|
213
213
|
/* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
|
|
214
|
-
!
|
|
214
|
+
!S && /* @__PURE__ */ n("div", { className: "flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2", children: [
|
|
215
215
|
/* @__PURE__ */ n("div", { children: [
|
|
216
216
|
/* @__PURE__ */ e("div", { className: "text-sm font-medium text-blue-900", children: "Manage Existing Pages" }),
|
|
217
217
|
/* @__PURE__ */ e("div", { className: "text-xs text-blue-700", children: "Add or remove this schema from all existing pages on your site" })
|
|
@@ -259,7 +259,7 @@ const oe = () => {
|
|
|
259
259
|
}
|
|
260
260
|
)
|
|
261
261
|
] }),
|
|
262
|
-
!
|
|
262
|
+
!S && /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
|
|
263
263
|
/* @__PURE__ */ e(
|
|
264
264
|
"input",
|
|
265
265
|
{
|
|
@@ -297,7 +297,7 @@ const oe = () => {
|
|
|
297
297
|
/* @__PURE__ */ e(Q, { onClick: I, children: "Add to All" })
|
|
298
298
|
] })
|
|
299
299
|
] }) }),
|
|
300
|
-
/* @__PURE__ */ e(U, { open:
|
|
300
|
+
/* @__PURE__ */ e(U, { open: C, onOpenChange: u, children: /* @__PURE__ */ n(_, { children: [
|
|
301
301
|
/* @__PURE__ */ n(R, { children: [
|
|
302
302
|
/* @__PURE__ */ e(M, { children: "Remove from All Pages?" }),
|
|
303
303
|
/* @__PURE__ */ n(q, { children: [
|
|
@@ -314,8 +314,8 @@ const oe = () => {
|
|
|
314
314
|
] });
|
|
315
315
|
};
|
|
316
316
|
function Xe() {
|
|
317
|
-
const [t, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [
|
|
318
|
-
const h = o ?
|
|
317
|
+
const [t, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [C, u] = g(null), [S, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: l } = le(), { data: N } = Te(), { mutateAsync: A } = De(), { mutateAsync: I } = se(), P = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (P == null ? void 0 : P.globalJsonLds) || [], [P]), T = z(() => c ? Je(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
|
|
318
|
+
const h = o ? Fe(c, (D) => D.primaryPage === r.id && D.lang === o) : null;
|
|
319
319
|
return {
|
|
320
320
|
defaultSchema: r,
|
|
321
321
|
languageVersion: h,
|
|
@@ -359,7 +359,7 @@ function Xe() {
|
|
|
359
359
|
] }),
|
|
360
360
|
!o && /* @__PURE__ */ n(L, { delayDuration: 0, children: [
|
|
361
361
|
/* @__PURE__ */ e(
|
|
362
|
-
|
|
362
|
+
J,
|
|
363
363
|
{
|
|
364
364
|
type: "button",
|
|
365
365
|
disabled: w,
|
|
@@ -370,7 +370,7 @@ function Xe() {
|
|
|
370
370
|
children: w ? /* @__PURE__ */ e(O, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(ke, { className: "h-4 w-4" })
|
|
371
371
|
}
|
|
372
372
|
),
|
|
373
|
-
/* @__PURE__ */ e(
|
|
373
|
+
/* @__PURE__ */ e(F, { children: "Add new schema" })
|
|
374
374
|
] })
|
|
375
375
|
] }),
|
|
376
376
|
/* @__PURE__ */ n(he, { className: "max-h-96 overflow-y-auto", children: [
|
|
@@ -382,13 +382,13 @@ function Xe() {
|
|
|
382
382
|
return /* @__PURE__ */ n(
|
|
383
383
|
ue,
|
|
384
384
|
{
|
|
385
|
-
className: `relative border-gray-300 p-0 shadow-none transition-all ${
|
|
385
|
+
className: `relative border-gray-300 p-0 shadow-none transition-all ${S === r.id ? "pointer-events-none" : ""}`,
|
|
386
386
|
children: [
|
|
387
|
-
|
|
387
|
+
S === r.id && /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80", children: /* @__PURE__ */ e(O, { className: "h-5 w-5 animate-spin text-primary" }) }),
|
|
388
388
|
/* @__PURE__ */ e(ge, { className: "p-2", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
|
|
389
389
|
/* @__PURE__ */ n("div", { className: "flex items-center gap-3", children: [
|
|
390
390
|
(h || !o) && /* @__PURE__ */ n(L, { delayDuration: 0, children: [
|
|
391
|
-
/* @__PURE__ */ e(
|
|
391
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
392
392
|
"input",
|
|
393
393
|
{
|
|
394
394
|
type: "checkbox",
|
|
@@ -398,7 +398,7 @@ function Xe() {
|
|
|
398
398
|
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
399
399
|
}
|
|
400
400
|
) }),
|
|
401
|
-
h && o && /* @__PURE__ */ e(
|
|
401
|
+
h && o && /* @__PURE__ */ e(F, { children: "Using the default language state" })
|
|
402
402
|
] }),
|
|
403
403
|
/* @__PURE__ */ n("div", { children: [
|
|
404
404
|
/* @__PURE__ */ n(fe, { className: "flex items-center gap-2 text-sm leading-none", children: [
|
|
@@ -416,7 +416,7 @@ function Xe() {
|
|
|
416
416
|
/* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
417
417
|
/* @__PURE__ */ e("div", { className: "mx-2 h-6 w-px bg-border" }),
|
|
418
418
|
/* @__PURE__ */ n(L, { delayDuration: 0, children: [
|
|
419
|
-
/* @__PURE__ */ e(
|
|
419
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
420
420
|
v,
|
|
421
421
|
{
|
|
422
422
|
type: "button",
|
|
@@ -427,11 +427,11 @@ function Xe() {
|
|
|
427
427
|
children: /* @__PURE__ */ e(je, { className: "h-4 w-4" })
|
|
428
428
|
}
|
|
429
429
|
) }),
|
|
430
|
-
/* @__PURE__ */ e(
|
|
430
|
+
/* @__PURE__ */ e(F, { children: "View schema" })
|
|
431
431
|
] }),
|
|
432
432
|
(h || !o) && /* @__PURE__ */ n(j, { children: [
|
|
433
433
|
/* @__PURE__ */ n(L, { delayDuration: 0, children: [
|
|
434
|
-
/* @__PURE__ */ e(
|
|
434
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
435
435
|
v,
|
|
436
436
|
{
|
|
437
437
|
type: "button",
|
|
@@ -442,12 +442,12 @@ function Xe() {
|
|
|
442
442
|
children: /* @__PURE__ */ e(Ge, { className: "h-4 w-4" })
|
|
443
443
|
}
|
|
444
444
|
) }),
|
|
445
|
-
/* @__PURE__ */ e(
|
|
445
|
+
/* @__PURE__ */ e(F, { children: "Edit schema" })
|
|
446
446
|
] }),
|
|
447
447
|
/* @__PURE__ */ n(U, { children: [
|
|
448
448
|
/* @__PURE__ */ n(L, { delayDuration: 0, children: [
|
|
449
|
-
/* @__PURE__ */ e(
|
|
450
|
-
/* @__PURE__ */ e(
|
|
449
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(pe, { className: "flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800", children: /* @__PURE__ */ e(Be, { className: "h-4 w-4" }) }) }),
|
|
450
|
+
/* @__PURE__ */ e(F, { children: "Delete schema" })
|
|
451
451
|
] }),
|
|
452
452
|
/* @__PURE__ */ n(_, { children: [
|
|
453
453
|
/* @__PURE__ */ n(R, { children: [
|
|
@@ -527,7 +527,7 @@ function Xe() {
|
|
|
527
527
|
/* @__PURE__ */ e(
|
|
528
528
|
Re,
|
|
529
529
|
{
|
|
530
|
-
schema: c == null ? void 0 : c.find((s) => s.id ===
|
|
530
|
+
schema: c == null ? void 0 : c.find((s) => s.id === C),
|
|
531
531
|
onClose: () => u(null)
|
|
532
532
|
}
|
|
533
533
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DyW9GPzV.cjs"),u=require("./index-
|
|
1
|
+
"use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DyW9GPzV.cjs"),u=require("./index-DCJDQs1a.cjs"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const o=t.pop()||"";a=!!u.LANGUAGES[o]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:o}){const[g,p]=d.useState(e),[l,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:l?"border-red-500":""}),l&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:l})]}),o&&o!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:o})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as i, jsx as o } from "react/jsx-runtime";
|
|
2
2
|
import { z as v } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { L as d } from "./index-
|
|
3
|
+
import { L as d } from "./index-OuHV9Ann.js";
|
|
4
4
|
import { useState as x, useEffect as C } from "react";
|
|
5
5
|
const y = (e) => {
|
|
6
6
|
if (!e) return { base: e, extension: null };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var k=(u,t,e)=>t in u?x(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e;var E=(u,t,e)=>k(u,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./actions-registery-BQ31lpix.cjs"),A=require("lodash-es"),n=require("zod"),p=class p{constructor(t,e,r){this.appId=t,this.userId=e,this.supabase=r}appendUpdatedAtToUrl(t,e){if(A.isEmpty(t))return"";const r=new URL(t),a=new Date(e).getTime();return r.searchParams.set("t",a.toString()),`${r.origin}${r.pathname}${r.search}${r.hash}`}getBufferFromBase64(t){try{const e=t.split(",")[1]||t;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}getMimeType(t){var a;const e=((a=t.split(".").pop())==null?void 0:a.toLowerCase())||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}[e]||"application/octet-stream"}getImageDimensions(t){if(t.length>=p.MIN_PNG_LENGTH&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(t.length>=p.MIN_GIF_LENGTH&&t[0]===71&&t[1]===73&&t[2]===70)return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(t.length>=12&&t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70&&t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80){if(t.length>=p.MIN_WEBP_VP8L_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===76){const e=t.readUInt32LE(21);return{width:(e&16383)+1,height:(e>>14&16383)+1}}if(t.length>=p.MIN_WEBP_VP8X_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===88)return{width:1+(t[24]|t[25]<<8|t[26]<<16),height:1+(t[27]|t[28]<<8|t[29]<<16)};if(t.length>=p.MIN_WEBP_VP8_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===32)return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383}}if(t.length>=2&&t[0]===255&&t[1]===216){let e=2;for(;e<t.length-1;){if(t[e]!==255){e++;continue}const r=t[e+1];if(r>=192&&r<=195||r>=197&&r<=199||r>=201&&r<=203||r>=205&&r<=207){if(e+p.MIN_JPEG_SOF_BYTES_FROM_MARKER<=t.length)return{width:t.readUInt16BE(e+7),height:t.readUInt16BE(e+5)};break}if(e+4>t.length)break;const a=t.readUInt16BE(e+2);e+=2+a}}return{width:0,height:0}}async uploadImageFile(t,e,r,a){try{const s=this.getBufferFromBase64(t),i=this.getMimeType(r);if(!["image/jpeg","image/png","image/webp","image/gif","image/tiff"].includes(i))throw new Error(`Invalid image format: ${i}`);const d=r.split("."),o=d.length>1?d.slice(0,-1).join("."):r,l=d.length>1?d[d.length-1].toLowerCase():"png",w=`${A.kebabCase(o)}.${l}`,h=this.appId,m=e?`${h}/${e}`:h,S=g.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:s.toString("base64"),fileName:w,contentType:i,folder:m});if(U.error)throw new Error(U.error);const{width:T,height:b}=this.getImageDimensions(s);return{url:U.data.url,thumbnailUrl:U.data.url,size:s.length,width:T,height:b,mimeType:i}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(t,e,r){try{const a=this.getBufferFromBase64(t);let s,i;try{const S=a.toString("utf-8"),U=S.match(/\bwidth=["'](\d+)/),T=S.match(/\bheight=["'](\d+)/);U&&(s=parseInt(U[1],10)),T&&(i=parseInt(T[1],10))}catch{}const c=r.split("."),d=c.length>1?c.slice(0,-1).join("."):r,o=`${A.kebabCase(d)}.svg`,l=this.appId,w=e?`${l}/${e}`:l,h=g.getChaiAction("UPLOAD_TO_STORAGE");if(!h)throw new Error("UPLOAD_TO_STORAGE action not found");h.setContext({appId:this.appId,userId:this.userId});const m=await h.execute({file:a.toString("base64"),fileName:o,contentType:"image/svg+xml",folder:w});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:a.length,width:s,height:i,mimeType:"image/svg+xml"}}catch(a){return console.error("SVG upload error:",a),{error:a instanceof Error?a.message:"Unknown error"}}}async upload({file:t,folderId:e,name:r,optimize:a=!0}){var s;try{const c=r.toLowerCase().endsWith(".svg")||t.includes("data:image/svg+xml")?await this.uploadSvgFile(t,e,r):await this.uploadImageFile(t,e,r,a??!0);if("error"in c)return c;const d={name:r,app:this.appId,url:c.url,thumbnailUrl:c.thumbnailUrl,size:(s=c.size)==null?void 0:s.toString(),width:c.width,height:c.height,format:c.mimeType.split("/")[1],folderId:e,type:c.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:o,error:l}=await this.supabase.from("app_assets").insert(d).select("*").single();if(l)throw new Error(`Failed to store asset in database: ${l.message}`);return{id:o.id,name:o.name,type:o.type,url:this.appendUpdatedAtToUrl(o.url,o.updatedAt),size:o.size,thumbnailUrl:this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt),width:o.width,height:o.height,format:o.format,folderId:o.folderId,createdBy:o.createdBy||"",createdAt:o.createdAt,updatedAt:o.updatedAt}}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}async getAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);return A.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),A.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:t="",page:e=1,limit:r=20}={}){try{const a=(e-1)*r;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});t&&(s=s.or(`name.ilike.%${t}%,description.ilike.%${t}%`));const{data:i,error:c,count:d}=await s.range(a,a+r-1);if(c)throw new Error(c.message);return{assets:i.map(l=>(A.set(l,"url",this.appendUpdatedAtToUrl(l.url,l.updatedAt)),A.set(l,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(l.thumbnailUrl||"",l.updatedAt)),l)),total:d||0,page:e,pageSize:r}}catch(a){throw console.error("Error fetching assets:",a),a}}async deleteAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);if(e.url)try{const i=new URL(e.url).pathname.split("/"),c=i.indexOf("dam-assets");if(c!==-1){const d=i.slice(c+1).join("/"),o=g.getChaiAction("DELETE_FROM_STORAGE");if(o&&(o.setContext({appId:this.appId,userId:this.userId}),await o.execute({key:d})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const w=new URL(e.thumbnailUrl).pathname.split("/"),h=w.indexOf("dam-assets");if(h!==-1){const m=w.slice(h+1).join("/");o&&await o.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:a}=await this.supabase.from("app_assets").delete().eq("id",t);if(a)throw new Error(`Failed to delete asset: ${a.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:t,file:e,description:r}){var a,s;try{const{data:i,error:c}=await this.supabase.from("app_assets").select("*").eq("id",t).single();if(c)throw new Error(`Failed to fetch asset: ${c.message}`);const d={};if(r!==void 0&&(d.description=r,d.updatedAt=new Date().toISOString()),e){const h=((a=i.format)==null?void 0:a.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,i.folderId,i.name):await this.uploadImageFile(e,i.folderId,i.name,!0);if("error"in h)return h;d.url=h.url,d.thumbnailUrl=h.thumbnailUrl,d.size=(s=h.size)==null?void 0:s.toString(),d.width=h.width,d.height=h.height,d.format=h.mimeType.split("/")[1],d.updatedAt=new Date().toISOString()}const{data:o,error:l}=await this.supabase.from("app_assets").update(d).eq("id",t).select().single();if(l)throw new Error(`Failed to update asset: ${l.message}`);return A.set(o,"url",this.appendUpdatedAtToUrl(o.url,o.updatedAt)),A.set(o,"thumbnailUrl",this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt)),o}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}};E(p,"MIN_PNG_LENGTH",24),E(p,"MIN_GIF_LENGTH",10),E(p,"MIN_WEBP_VP8L_LENGTH",25),E(p,"MIN_WEBP_VP8X_LENGTH",30),E(p,"MIN_WEBP_VP8_LENGTH",30),E(p,"MIN_JPEG_SOF_BYTES_FROM_MARKER",9);let I=p;const P=n.z.object({name:n.z.string(),file:n.z.string(),folderId:n.z.string().optional().nullable(),optimize:n.z.boolean().optional()});class z extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return P}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).upload(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const f=n.z.object({id:n.z.string()});class O extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return f}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).getAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const D=n.z.object({search:n.z.string().optional(),page:n.z.number().optional(),limit:n.z.number().optional()});class L extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return D}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).getAssets(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const G=n.z.object({id:n.z.string()});class N extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return G}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).deleteAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const F=n.z.object({id:n.z.string(),file:n.z.string().optional(),description:n.z.string().optional()});class B extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return F}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).updateAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const M=n.z.object({userId:n.z.string()});class C extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return M}async execute(t){var e,r,a,s,i,c;try{const{userId:d}=t,{data:o,error:l}=await this.supabase.auth.admin.getUserById(d);return l?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=o.user)==null?void 0:e.id)||"unknown",email:((r=o.user)==null?void 0:r.email)||"unknown@chaibuilder.com",name:((s=(a=o.user)==null?void 0:a.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((c=(i=o.user)==null?void 0:i.user_metadata)==null?void 0:c.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const v=n.z.object({email:n.z.string().email(),oldPassword:n.z.string().min(1,"Old password is required"),newPassword:n.z.string().min(8,"New password must be at least 8 characters"),confirmPassword:n.z.string().min(1,"Confirm password is required")}).refine(u=>u.newPassword===u.confirmPassword,{message:"Confirm password does not match",path:["confirmPassword"]});class R extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return v}async execute(t){try{const{email:e,oldPassword:r,newPassword:a}=t,{error:s}=await this.supabase.auth.signInWithPassword({email:e,password:r});if(s)throw new g.ActionError("Current password is incorrect","INVALID_PASSWORD",400);const{error:i}=await this.supabase.auth.updateUser({password:a});if(i)throw new g.ActionError(i.message||"Failed to update password","UPDATE_FAILED",400);return{data:{message:"Password changed successfully"},status:200}}catch(e){throw e}}}const $=n.z.object({key:n.z.string()});class y extends g.ChaiBaseAction{constructor(e){super();E(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return $}async execute(e){try{const{key:r}=e,{error:a}=await this.supabase.storage.from(this.bucketName).remove([r]);return a?{error:`Failed to delete from Supabase Storage: ${a.message}`,status:500}:{data:{success:!0},status:200}}catch(r){return console.error("DELETE_FROM_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const j=n.z.object({file:n.z.string(),fileName:n.z.string(),contentType:n.z.string().optional(),folder:n.z.string().optional(),metadata:n.z.record(n.z.string(),n.z.any()).optional()});class _ extends g.ChaiBaseAction{constructor(e){super();E(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return j}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:r}=this.context,{file:a,fileName:s,contentType:i,folder:c,metadata:d}=e;let o;if(typeof a=="string"){const S=a.split(",")[1]||a;o=Buffer.from(S,"base64")}else o=a;const l=c?`${c}/${s}`:`${r}/${s}`,{data:w,error:h}=await this.supabase.storage.from(this.bucketName).upload(l,o,{contentType:i||"application/octet-stream",upsert:!0,...d&&{metadata:d}});if(h)return{error:`Failed to upload to Supabase Storage: ${h.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(l);return{data:{url:m,key:w.path,size:o.length,metadata:d},status:200}}catch(r){return console.error("UPLOAD_TO_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const q=u=>({GET_CHAI_USER:new C(u),CHANGE_PASSWORD:new R(u)}),V=u=>({UPLOAD_ASSET:new z(u),GET_ASSET:new O(u),GET_ASSETS:new L(u),DELETE_ASSET:new N(u),UPDATE_ASSET:new B(u),UPLOAD_TO_STORAGE:new _(u),DELETE_FROM_STORAGE:new y(u)});exports.DeleteFromStorageAction=y;exports.SupabaseAuthActions=q;exports.SupabaseStorageActions=V;exports.UploadToStorageAction=_;
|
|
1
|
+
"use strict";var x=Object.defineProperty;var k=(u,t,e)=>t in u?x(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e;var E=(u,t,e)=>k(u,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./actions-registery-BHbZHkE3.cjs"),A=require("lodash-es"),n=require("zod"),p=class p{constructor(t,e,r){this.appId=t,this.userId=e,this.supabase=r}appendUpdatedAtToUrl(t,e){if(A.isEmpty(t))return"";const r=new URL(t),a=new Date(e).getTime();return r.searchParams.set("t",a.toString()),`${r.origin}${r.pathname}${r.search}${r.hash}`}getBufferFromBase64(t){try{const e=t.split(",")[1]||t;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}getMimeType(t){var a;const e=((a=t.split(".").pop())==null?void 0:a.toLowerCase())||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}[e]||"application/octet-stream"}getImageDimensions(t){if(t.length>=p.MIN_PNG_LENGTH&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(t.length>=p.MIN_GIF_LENGTH&&t[0]===71&&t[1]===73&&t[2]===70)return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(t.length>=12&&t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70&&t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80){if(t.length>=p.MIN_WEBP_VP8L_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===76){const e=t.readUInt32LE(21);return{width:(e&16383)+1,height:(e>>14&16383)+1}}if(t.length>=p.MIN_WEBP_VP8X_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===88)return{width:1+(t[24]|t[25]<<8|t[26]<<16),height:1+(t[27]|t[28]<<8|t[29]<<16)};if(t.length>=p.MIN_WEBP_VP8_LENGTH&&t[12]===86&&t[13]===80&&t[14]===56&&t[15]===32)return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383}}if(t.length>=2&&t[0]===255&&t[1]===216){let e=2;for(;e<t.length-1;){if(t[e]!==255){e++;continue}const r=t[e+1];if(r>=192&&r<=195||r>=197&&r<=199||r>=201&&r<=203||r>=205&&r<=207){if(e+p.MIN_JPEG_SOF_BYTES_FROM_MARKER<=t.length)return{width:t.readUInt16BE(e+7),height:t.readUInt16BE(e+5)};break}if(e+4>t.length)break;const a=t.readUInt16BE(e+2);e+=2+a}}return{width:0,height:0}}async uploadImageFile(t,e,r,a){try{const s=this.getBufferFromBase64(t),i=this.getMimeType(r);if(!["image/jpeg","image/png","image/webp","image/gif","image/tiff"].includes(i))throw new Error(`Invalid image format: ${i}`);const d=r.split("."),o=d.length>1?d.slice(0,-1).join("."):r,l=d.length>1?d[d.length-1].toLowerCase():"png",w=`${A.kebabCase(o)}.${l}`,h=this.appId,m=e?`${h}/${e}`:h,S=g.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:s.toString("base64"),fileName:w,contentType:i,folder:m});if(U.error)throw new Error(U.error);const{width:T,height:b}=this.getImageDimensions(s);return{url:U.data.url,thumbnailUrl:U.data.url,size:s.length,width:T,height:b,mimeType:i}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(t,e,r){try{const a=this.getBufferFromBase64(t);let s,i;try{const S=a.toString("utf-8"),U=S.match(/\bwidth=["'](\d+)/),T=S.match(/\bheight=["'](\d+)/);U&&(s=parseInt(U[1],10)),T&&(i=parseInt(T[1],10))}catch{}const c=r.split("."),d=c.length>1?c.slice(0,-1).join("."):r,o=`${A.kebabCase(d)}.svg`,l=this.appId,w=e?`${l}/${e}`:l,h=g.getChaiAction("UPLOAD_TO_STORAGE");if(!h)throw new Error("UPLOAD_TO_STORAGE action not found");h.setContext({appId:this.appId,userId:this.userId});const m=await h.execute({file:a.toString("base64"),fileName:o,contentType:"image/svg+xml",folder:w});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:a.length,width:s,height:i,mimeType:"image/svg+xml"}}catch(a){return console.error("SVG upload error:",a),{error:a instanceof Error?a.message:"Unknown error"}}}async upload({file:t,folderId:e,name:r,optimize:a=!0}){var s;try{const c=r.toLowerCase().endsWith(".svg")||t.includes("data:image/svg+xml")?await this.uploadSvgFile(t,e,r):await this.uploadImageFile(t,e,r,a??!0);if("error"in c)return c;const d={name:r,app:this.appId,url:c.url,thumbnailUrl:c.thumbnailUrl,size:(s=c.size)==null?void 0:s.toString(),width:c.width,height:c.height,format:c.mimeType.split("/")[1],folderId:e,type:c.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:o,error:l}=await this.supabase.from("app_assets").insert(d).select("*").single();if(l)throw new Error(`Failed to store asset in database: ${l.message}`);return{id:o.id,name:o.name,type:o.type,url:this.appendUpdatedAtToUrl(o.url,o.updatedAt),size:o.size,thumbnailUrl:this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt),width:o.width,height:o.height,format:o.format,folderId:o.folderId,createdBy:o.createdBy||"",createdAt:o.createdAt,updatedAt:o.updatedAt}}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}async getAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);return A.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),A.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:t="",page:e=1,limit:r=20}={}){try{const a=(e-1)*r;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});t&&(s=s.or(`name.ilike.%${t}%,description.ilike.%${t}%`));const{data:i,error:c,count:d}=await s.range(a,a+r-1);if(c)throw new Error(c.message);return{assets:i.map(l=>(A.set(l,"url",this.appendUpdatedAtToUrl(l.url,l.updatedAt)),A.set(l,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(l.thumbnailUrl||"",l.updatedAt)),l)),total:d||0,page:e,pageSize:r}}catch(a){throw console.error("Error fetching assets:",a),a}}async deleteAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);if(e.url)try{const i=new URL(e.url).pathname.split("/"),c=i.indexOf("dam-assets");if(c!==-1){const d=i.slice(c+1).join("/"),o=g.getChaiAction("DELETE_FROM_STORAGE");if(o&&(o.setContext({appId:this.appId,userId:this.userId}),await o.execute({key:d})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const w=new URL(e.thumbnailUrl).pathname.split("/"),h=w.indexOf("dam-assets");if(h!==-1){const m=w.slice(h+1).join("/");o&&await o.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:a}=await this.supabase.from("app_assets").delete().eq("id",t);if(a)throw new Error(`Failed to delete asset: ${a.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:t,file:e,description:r}){var a,s;try{const{data:i,error:c}=await this.supabase.from("app_assets").select("*").eq("id",t).single();if(c)throw new Error(`Failed to fetch asset: ${c.message}`);const d={};if(r!==void 0&&(d.description=r,d.updatedAt=new Date().toISOString()),e){const h=((a=i.format)==null?void 0:a.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,i.folderId,i.name):await this.uploadImageFile(e,i.folderId,i.name,!0);if("error"in h)return h;d.url=h.url,d.thumbnailUrl=h.thumbnailUrl,d.size=(s=h.size)==null?void 0:s.toString(),d.width=h.width,d.height=h.height,d.format=h.mimeType.split("/")[1],d.updatedAt=new Date().toISOString()}const{data:o,error:l}=await this.supabase.from("app_assets").update(d).eq("id",t).select().single();if(l)throw new Error(`Failed to update asset: ${l.message}`);return A.set(o,"url",this.appendUpdatedAtToUrl(o.url,o.updatedAt)),A.set(o,"thumbnailUrl",this.appendUpdatedAtToUrl(o.thumbnailUrl||"",o.updatedAt)),o}catch(i){return{error:i instanceof Error?i.message:"Unknown error occurred"}}}};E(p,"MIN_PNG_LENGTH",24),E(p,"MIN_GIF_LENGTH",10),E(p,"MIN_WEBP_VP8L_LENGTH",25),E(p,"MIN_WEBP_VP8X_LENGTH",30),E(p,"MIN_WEBP_VP8_LENGTH",30),E(p,"MIN_JPEG_SOF_BYTES_FROM_MARKER",9);let I=p;const P=n.z.object({name:n.z.string(),file:n.z.string(),folderId:n.z.string().optional().nullable(),optimize:n.z.boolean().optional()});class z extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return P}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).upload(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const f=n.z.object({id:n.z.string()});class O extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return f}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).getAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const D=n.z.object({search:n.z.string().optional(),page:n.z.number().optional(),limit:n.z.number().optional()});class L extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return D}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).getAssets(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const G=n.z.object({id:n.z.string()});class N extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return G}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).deleteAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const F=n.z.object({id:n.z.string(),file:n.z.string().optional(),description:n.z.string().optional()});class B extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return F}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new I(e,r,this.supabase).updateAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const M=n.z.object({userId:n.z.string()});class C extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return M}async execute(t){var e,r,a,s,i,c;try{const{userId:d}=t,{data:o,error:l}=await this.supabase.auth.admin.getUserById(d);return l?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=o.user)==null?void 0:e.id)||"unknown",email:((r=o.user)==null?void 0:r.email)||"unknown@chaibuilder.com",name:((s=(a=o.user)==null?void 0:a.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((c=(i=o.user)==null?void 0:i.user_metadata)==null?void 0:c.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const v=n.z.object({email:n.z.string().email(),oldPassword:n.z.string().min(1,"Old password is required"),newPassword:n.z.string().min(8,"New password must be at least 8 characters"),confirmPassword:n.z.string().min(1,"Confirm password is required")}).refine(u=>u.newPassword===u.confirmPassword,{message:"Confirm password does not match",path:["confirmPassword"]});class R extends g.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return v}async execute(t){try{const{email:e,oldPassword:r,newPassword:a}=t,{error:s}=await this.supabase.auth.signInWithPassword({email:e,password:r});if(s)throw new g.ActionError("Current password is incorrect","INVALID_PASSWORD",400);const{error:i}=await this.supabase.auth.updateUser({password:a});if(i)throw new g.ActionError(i.message||"Failed to update password","UPDATE_FAILED",400);return{data:{message:"Password changed successfully"},status:200}}catch(e){throw e}}}const $=n.z.object({key:n.z.string()});class y extends g.ChaiBaseAction{constructor(e){super();E(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return $}async execute(e){try{const{key:r}=e,{error:a}=await this.supabase.storage.from(this.bucketName).remove([r]);return a?{error:`Failed to delete from Supabase Storage: ${a.message}`,status:500}:{data:{success:!0},status:200}}catch(r){return console.error("DELETE_FROM_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const j=n.z.object({file:n.z.string(),fileName:n.z.string(),contentType:n.z.string().optional(),folder:n.z.string().optional(),metadata:n.z.record(n.z.string(),n.z.any()).optional()});class _ extends g.ChaiBaseAction{constructor(e){super();E(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return j}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:r}=this.context,{file:a,fileName:s,contentType:i,folder:c,metadata:d}=e;let o;if(typeof a=="string"){const S=a.split(",")[1]||a;o=Buffer.from(S,"base64")}else o=a;const l=c?`${c}/${s}`:`${r}/${s}`,{data:w,error:h}=await this.supabase.storage.from(this.bucketName).upload(l,o,{contentType:i||"application/octet-stream",upsert:!0,...d&&{metadata:d}});if(h)return{error:`Failed to upload to Supabase Storage: ${h.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(l);return{data:{url:m,key:w.path,size:o.length,metadata:d},status:200}}catch(r){return console.error("UPLOAD_TO_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const q=u=>({GET_CHAI_USER:new C(u),CHANGE_PASSWORD:new R(u)}),V=u=>({UPLOAD_ASSET:new z(u),GET_ASSET:new O(u),GET_ASSETS:new L(u),DELETE_ASSET:new N(u),UPDATE_ASSET:new B(u),UPLOAD_TO_STORAGE:new _(u),DELETE_FROM_STORAGE:new y(u)});exports.DeleteFromStorageAction=y;exports.SupabaseAuthActions=q;exports.SupabaseStorageActions=V;exports.UploadToStorageAction=_;
|
package/dist/supabase-actions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var k = Object.defineProperty;
|
|
2
2
|
var P = (u, t, e) => t in u ? k(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e;
|
|
3
3
|
var w = (u, t, e) => P(u, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { g as y, C as E, A as _ } from "./actions-registery-
|
|
4
|
+
import { g as y, C as E, A as _ } from "./actions-registery-gJb_wq2F.js";
|
|
5
5
|
import { isEmpty as f, kebabCase as x, set as I } from "lodash-es";
|
|
6
6
|
import { z as o } from "zod";
|
|
7
7
|
const h = class h {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("./register-chai-top-bar-DyW9GPzV.cjs"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("./register-chai-top-bar-DyW9GPzV.cjs"),r=require("./index-DCJDQs1a.cjs"),t=require("./index-BVwFJWDq.cjs"),l=require("lucide-react"),j=require("react"),p=require("react-i18next"),T=()=>{const i=t.useSendRealtimeEvent(),{pageLockMeta:n}=t.usePageLockMeta(),{setPageStatus:d}=t.usePageLockStatus(),{savePageAsync:x}=r.useSavePage(),h=n==null?void 0:n.requestingUserId,{data:s,isFetching:g}=t.useChaiUserInfo(h||""),o=g?"Fetching user...":(s==null?void 0:s.name)||"Current editor",[u,c]=j.useState(!1),N=async()=>{c(!0),await x(),i(t.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT,n),d(t.PAGE_STATUS.CHECKING),setTimeout(()=>c(!1),2e3)},f=()=>{c(!0),i(t.EVENT.TAKE_OVER_REJECTED,n),d(t.PAGE_STATUS.EDITING),setTimeout(()=>c(!1),2e3)},{t:a}=p.useTranslation();return e.jsx(t.BlurContainer,{children:e.jsxs(r.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(r.CardHeader,{className:"space-y-1",children:e.jsxs(r.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(l.AlertCircle,{className:"h-8 w-8 rounded-md bg-amber-500/20 p-1.5 text-amber-500"}),a("Take Over Requested")]})}),e.jsxs(r.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Requested by"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black text-white"}):e.jsx(l.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:o}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-gray-700",children:o})," ",a("has requested to")," ",e.jsx("span",{className:"font-medium text-gray-500",children:"take over"})," ",a("editing this page."),"."," ",a("Do you want to allow them to continue?")]})]}),e.jsxs(r.CardFooter,{className:"flex gap-2",children:[e.jsxs(m.Button,{disabled:u,variant:"default",onClick:N,className:"flex-1 gap-2",children:[e.jsx(l.Check,{className:"h-4 w-4"}),a("Accept")]}),e.jsxs(m.Button,{disabled:u,variant:"outline",onClick:f,className:"flex-1 gap-2",children:[e.jsx(l.X,{className:"h-4 w-4"}),a("Reject")]})]})]})})};exports.default=T;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as a, jsxs as t } from "react/jsx-runtime";
|
|
2
2
|
import { B as m } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { I as N, J as C, K as b, M as v, O as E, Q as T } from "./index-
|
|
4
|
-
import {
|
|
3
|
+
import { I as N, J as C, K as b, M as v, O as E, Q as T } from "./index-OuHV9Ann.js";
|
|
4
|
+
import { an as w, b as I, a as k, ao as y, B as R, E as d, P as u } from "./index-LBTm1Jmk.js";
|
|
5
5
|
import { AlertCircle as S, UserIcon as A, Check as P, X as _ } from "lucide-react";
|
|
6
6
|
import { useState as q } from "react";
|
|
7
7
|
import { useTranslation as U } from "react-i18next";
|
|
8
8
|
const K = () => {
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const l = w(), { pageLockMeta: r } = I(), { setPageStatus: c } = k(), { savePageAsync: h } = N(), f = r == null ? void 0 : r.requestingUserId, { data: e, isFetching: x } = y(f || ""), i = x ? "Fetching user..." : (e == null ? void 0 : e.name) || "Current editor", [o, n] = q(!1), p = async () => {
|
|
10
|
+
n(!0), await h(), l(d.CONTINUE_EDITING_IN_THIS_CLIENT, r), c(u.CHECKING), setTimeout(() => n(!1), 2e3);
|
|
11
11
|
}, g = () => {
|
|
12
|
-
|
|
12
|
+
n(!0), l(d.TAKE_OVER_REJECTED, r), c(u.EDITING), setTimeout(() => n(!1), 2e3);
|
|
13
13
|
}, { t: s } = U();
|
|
14
14
|
return /* @__PURE__ */ a(R, { children: /* @__PURE__ */ t(C, { className: "mx-auto w-full max-w-md", children: [
|
|
15
15
|
/* @__PURE__ */ a(b, { className: "space-y-1", children: /* @__PURE__ */ t(v, { className: "flex items-center gap-2 text-xl", children: [
|
package/dist/{translation-warning-modal-Xk6oYGFS.cjs → translation-warning-modal-CLZ9tC1F.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./register-chai-top-bar-DyW9GPzV.cjs"),n=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./register-chai-top-bar-DyW9GPzV.cjs"),n=require("./index-DCJDQs1a.cjs"),u=({isOpen:o,onClose:i,onContinue:t,isPending:a=!1,title:r="Translation Warning",description:s="Some blocks need translations before publishing. Do you want to continue anyway?"})=>{const c=()=>{i()},d=()=>{t()};return e.jsx(n.Dialog,{open:o,onOpenChange:i,children:o&&e.jsxs(n.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{children:r}),e.jsx(n.DialogDescription,{children:s})]}),e.jsxs(n.DialogFooter,{className:"flex gap-2",children:[e.jsx(l.Button,{variant:"outline",onClick:c,disabled:a,children:"Cancel"}),e.jsx(l.Button,{onClick:d,disabled:a,children:a?"Publishing...":"Continue Anyway"})]})]})})};exports.default=u;
|
package/dist/{translation-warning-modal-Du-CnfyH.js → translation-warning-modal-CzNt6LDO.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as n, jsxs as e } from "react/jsx-runtime";
|
|
2
2
|
import { B as i } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { D as c, e as d, f as h, g, o as m, q as u } from "./index-
|
|
3
|
+
import { D as c, e as d, f as h, g, o as m, q as u } from "./index-OuHV9Ann.js";
|
|
4
4
|
const x = ({
|
|
5
5
|
isOpen: o,
|
|
6
6
|
onClose: l,
|
package/dist/types.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export declare type AIChatOptions = {
|
|
|
10
10
|
systemPrompt?: string;
|
|
11
11
|
initiator?: string | null;
|
|
12
12
|
model?: string;
|
|
13
|
+
context?: AIContext;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare type AIContext = {
|
|
17
|
+
site?: Record<string, any>;
|
|
18
|
+
page?: Record<string, any>;
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
export declare type AssetsParams = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as a, jsxs as n } from "react/jsx-runtime";
|
|
2
2
|
import { B as r } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { D as p, e as u, f as d, g as f, o as g, q as h } from "./index-
|
|
4
|
-
import {
|
|
3
|
+
import { D as p, e as u, f as d, g as f, o as g, q as h } from "./index-OuHV9Ann.js";
|
|
4
|
+
import { s as k } from "./index-LBTm1Jmk.js";
|
|
5
5
|
import { useState as D } from "react";
|
|
6
6
|
import { useTranslation as x } from "react-i18next";
|
|
7
7
|
const j = ({ page: i, onClose: t }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-DCJDQs1a.cjs"),p=require("./index-BVwFJWDq.cjs"),d=require("react"),m=require("react-i18next"),g=({page:i,onClose:n})=>{const{t:a}=m.useTranslation(),[r,s]=d.useState(!1),l=p.useUnmarkAsTemplate(),c=()=>{s(!0),l.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(o.Button,{variant:"outline",onClick:u=>{u.stopPropagation(),n()},children:a("Cancel")}),e.jsx(o.Button,{variant:"default",disabled:r,onClick:c,children:a("Unmark as template")})]})]})})};exports.default=g;
|