@chaibuilder/sdk 4.0.0-beta.1 → 4.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -20
- package/dist/2SSKDMRQ-BnsZi3K3.cjs +1 -0
- package/dist/2SSKDMRQ-CnSDkQcy.js +42 -0
- package/dist/AP7HFJJL-B31839PG.cjs +1228 -0
- package/dist/AP7HFJJL-CymCmW14.js +9214 -0
- package/dist/IconPicker-B1rWC-Ex.js +59 -0
- package/dist/IconPicker-DREyo007.cjs +1 -0
- package/dist/WDYDFRGG-BUVnbAci.js +33 -0
- package/dist/WDYDFRGG-BxhOCHc3.cjs +1 -0
- package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
- package/dist/_commonjsHelpers-DwGv2jUC.cjs +1 -0
- package/dist/actions-registery-CZ1w0NKa.js +15545 -0
- package/dist/actions-registery-YnFmU21O.cjs +418 -0
- package/dist/actions.cjs +1 -0
- package/dist/actions.d.ts +3202 -0
- package/dist/actions.js +216 -0
- package/dist/active-in-another-tab-B47YjQGN.cjs +1 -0
- package/dist/active-in-another-tab-CyjngVA6.js +34 -0
- package/dist/add-new-language-page-88xzrUy8.cjs +1 -0
- package/dist/add-new-language-page-WmlCnytQ.js +401 -0
- package/dist/add-new-page-VW2wAYZp.js +31 -0
- package/dist/add-new-page-soZ8GAkN.cjs +1 -0
- package/dist/ai-panel-content-7zCil042.cjs +1 -0
- package/dist/ai-panel-content-D_o7Q_A-.js +61 -0
- package/dist/ai-panel-default-lang-COYaxNwn.cjs +3 -0
- package/dist/ai-panel-default-lang-DnElspF0.js +341 -0
- package/dist/ai-panel-other-lang-CkynNlAU.cjs +1 -0
- package/dist/ai-panel-other-lang-Dp0E9_Hx.js +162 -0
- package/dist/ai-prompt-input-Bhc0ds7X.js +655 -0
- package/dist/ai-prompt-input-CThbVp0_.cjs +1 -0
- package/dist/ai-translation-prompt-C2kJQFDX.cjs +1 -0
- package/dist/ai-translation-prompt-CZ55HQmo.js +28 -0
- package/dist/apply-binding-6iwlED02.js +833 -0
- package/dist/apply-binding-KKp5PnpZ.cjs +1 -0
- package/dist/code-display-BnqzqzoP.cjs +1 -0
- package/dist/{code-display-337R7Dev.js → code-display-DhD_RBcg.js} +1 -1
- package/dist/code-editor-DRIAnNbb.js +50 -0
- package/dist/code-editor-o3___nu2.cjs +1 -0
- package/dist/common-functions-B3a4xKt_.cjs +1 -0
- package/dist/common-functions-D2lMFR6K.js +13 -0
- package/dist/continue-editing-in-this-client-CS2aQ7yY.js +24 -0
- package/dist/continue-editing-in-this-client-CtMYsk-A.cjs +1 -0
- package/dist/core-BoRDjj4h.cjs +1 -0
- package/dist/core-yvI6kCyw.js +56 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +51 -383
- package/dist/core.js +39 -106
- package/dist/{css-import-modal-DA2L6kwP.js → css-import-modal-Byg6wV0O.js} +36 -36
- package/dist/css-import-modal-CyqkXWCO.cjs +13 -0
- package/dist/delete-design-token-BRZZiWtQ.js +40 -0
- package/dist/delete-design-token-DkVs1oBf.cjs +1 -0
- package/dist/delete-page-BzyX9TN-.js +70 -0
- package/dist/delete-page-DxX7PFIE.cjs +1 -0
- package/dist/design-token-usage-CAHzEGgJ.cjs +1 -0
- package/dist/design-token-usage-xQs6SlaJ.js +113 -0
- package/dist/digital-asset-manager--uO8Agia.cjs +1 -0
- package/dist/digital-asset-manager-DbtwzxRz.js +876 -0
- package/dist/duplicate-page-BR7Dlo9d.js +133 -0
- package/dist/duplicate-page-CaNAbXwV.cjs +1 -0
- package/dist/dynamic-page-selector-Cb5r_W8s.js +85 -0
- package/dist/dynamic-page-selector-Cxk_gjni.cjs +1 -0
- package/dist/fonts-B-Xt29pe.cjs +1 -0
- package/dist/fonts-DRly3Wzd.js +78 -0
- package/dist/{get-chai-builder-tailwind-config-C6MHaUM0.cjs → get-chai-builder-tailwind-config-B9rCyiQo.cjs} +1 -1
- package/dist/{get-chai-builder-tailwind-config-BqaIvg8p.js → get-chai-builder-tailwind-config-DjoVOuAf.js} +13 -10
- package/dist/{get-chai-builder-theme-D0IsUvK4.js → get-chai-builder-theme-BYtp20KD.js} +4 -4
- package/dist/get-chai-builder-theme-Dl72X7cz.cjs +1 -0
- package/dist/get-seo-defaults-9zHebckY.js +65 -0
- package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
- package/dist/image-compression-DZ9WMmyn.cjs +1 -0
- package/dist/image-compression-DsZ1oqpb.js +37 -0
- package/dist/image-editor-DV8kUKhl.js +108 -0
- package/dist/image-editor-G-K28aTS.cjs +1 -0
- package/dist/index-B-rSiAp_.cjs +1 -0
- package/dist/index-Ct7ElCGK.js +19069 -0
- package/dist/index-DF5DEvqb.cjs +160 -0
- package/dist/index-Dxfyt4d4.js +39 -0
- package/dist/index-WQwzsC7A.cjs +5 -0
- package/dist/index-ZuacEL1j.js +4732 -0
- package/dist/json-diff-viewer-D7z4zNvv.cjs +8 -0
- package/dist/json-diff-viewer-krslPepD.js +258 -0
- package/dist/lang-panel-BwIewMyw.js +215 -0
- package/dist/lang-panel-DT96k1xg.cjs +1 -0
- package/dist/manage-design-tokens-Caz_20VK.js +240 -0
- package/dist/manage-design-tokens-CrmLe7UT.cjs +1 -0
- package/dist/mark-as-template-D295ZQtU.js +156 -0
- package/dist/mark-as-template-W3LmpiqN.cjs +1 -0
- package/dist/models-5gOsRC56.cjs +1 -0
- package/dist/models-D95ZYr_x.js +70 -0
- package/dist/nested-path-selector-content-CKYYK-C5.js +87 -0
- package/dist/nested-path-selector-content-CoS_d3dc.cjs +1 -0
- package/dist/no-language-page-content-BvqRBP6y.js +42 -0
- package/dist/no-language-page-content-DkfeMl90.cjs +1 -0
- package/dist/no-language-page-dialog-BcEoqyQB.cjs +1 -0
- package/dist/no-language-page-dialog-PjNqTUpl.js +10 -0
- package/dist/page-creator-C4gc5NSC.cjs +1 -0
- package/dist/page-creator-DiOITEMw.js +795 -0
- package/dist/page-lock-BdYmCks0.cjs +1 -0
- package/dist/page-lock-Bfbs6RgL.js +30 -0
- package/dist/page-locked-dialog-B1FAtK92.cjs +1 -0
- package/dist/page-locked-dialog-B6MKTRfY.js +133 -0
- package/dist/page-manager-new-CHDueBDk.cjs +1 -0
- package/dist/page-manager-new-CzX22g2n.js +394 -0
- package/dist/page-manager-search-and-filter-CM0UMb6U.js +201 -0
- package/dist/page-manager-search-and-filter-DkkRIH86.cjs +1 -0
- package/dist/page-revisions-content-ChY-4f2V.cjs +1 -0
- package/dist/page-revisions-content-NH9JK4Ey.js +445 -0
- package/dist/pages.cjs +1 -0
- package/dist/pages.d.ts +491 -0
- package/dist/pages.js +27 -0
- package/dist/plugin-3ZKK6RXm.js +245 -0
- package/dist/plugin-C6rgJDNQ.cjs +22 -0
- package/dist/publish-pages-content-D9aixMN5.js +178 -0
- package/dist/publish-pages-content-x-JuSFJ9.cjs +1 -0
- package/dist/register-partial-type-BjtdfKHE.js +36 -0
- package/dist/register-partial-type-ig9fUWIJ.cjs +1 -0
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +26 -13
- package/dist/render.js +130 -124
- package/dist/rte-widget-modal-BaHIuEjF.cjs +1 -0
- package/dist/rte-widget-modal-DOJEXLIf.js +38 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.d.ts +306 -7
- package/dist/runtime.js +44 -1
- package/dist/save-to-lib-Cgpxw8-g.cjs +1 -0
- package/dist/save-to-lib-eiOc_SSN.js +422 -0
- package/dist/sdk.css +1 -1
- package/dist/selected-block-display-BgRY82CT.cjs +16 -0
- package/dist/selected-block-display-CBFePS19.js +319 -0
- package/dist/seo-panel-C1-iMOR1.js +798 -0
- package/dist/seo-panel-DfAb8U7W.cjs +2 -0
- package/dist/shared-json-ld-B4PxAM_0.js +565 -0
- package/dist/shared-json-ld-DzG398hr.cjs +1 -0
- package/dist/slug-input-AwNJs9im.js +86 -0
- package/dist/slug-input-C_ijLQ_X.cjs +1 -0
- package/dist/supabase-actions.cjs +1 -0
- package/dist/supabase-actions.d.ts +284 -0
- package/dist/supabase-actions.js +524 -0
- package/dist/take-over-request-BNxcjY2j.cjs +1 -0
- package/dist/take-over-request-C4FeDtN_.js +63 -0
- package/dist/theme-panel-footer-Cq9pljro.cjs +1 -0
- package/dist/theme-panel-footer-uBQqSJXm.js +25 -0
- package/dist/translation-warning-modal-B64YqlbI.js +26 -0
- package/dist/translation-warning-modal-BZAcwM2_.cjs +1 -0
- package/dist/unmark-as-template-CZ9sQp_P.js +39 -0
- package/dist/unmark-as-template-EVvk0vmp.cjs +1 -0
- package/dist/unpublish-page-D4VwOlxc.js +27 -0
- package/dist/unpublish-page-bdSmwAVQ.cjs +1 -0
- package/dist/use-page-expand-manager-B6XTvk0E.cjs +1 -0
- package/dist/use-page-expand-manager-Cf4MUEJw.js +85 -0
- package/dist/{tailwind.cjs → utils.cjs} +1 -1
- package/dist/{tailwind.d.ts → utils.d.ts} +12 -11
- package/dist/utils.js +7 -0
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.d.ts +0 -6
- package/dist/web-blocks.js +248 -241
- package/dist/web-preview-Cio70gk5.cjs +1 -0
- package/dist/web-preview-Djy6WIyj.js +73 -0
- package/package.json +175 -105
- package/dist/IconPicker-CGWn9C4u.cjs +0 -1
- package/dist/IconPicker-QvxJ-4Ez.js +0 -64
- package/dist/apply-binding-DCno1xQL.js +0 -711
- package/dist/apply-binding-DvHNFLQD.cjs +0 -1
- package/dist/code-display-BZ1x7SqI.cjs +0 -1
- package/dist/code-editor-B28LoECM.cjs +0 -1
- package/dist/code-editor-CfG2FhJ-.js +0 -58
- package/dist/common-functions-BGzDsf1z.js +0 -14
- package/dist/common-functions-BZmyleS1.cjs +0 -1
- package/dist/css-import-modal-CENUYvcl.cjs +0 -13
- package/dist/get-chai-builder-theme-Ck_Z4Q-M.cjs +0 -1
- package/dist/index-CaGNHF7f.js +0 -12209
- package/dist/index-Gn6pJt2v.cjs +0 -166
- package/dist/mockServiceWorker.js +0 -307
- package/dist/plugin-B5627hMN.js +0 -195
- package/dist/plugin-UxTRfDum.cjs +0 -22
- package/dist/rte-widget-modal-DL739qeQ.cjs +0 -1
- package/dist/rte-widget-modal-Dte0od04.js +0 -41
- package/dist/tailwind.js +0 -7
- package/dist/tooltip-A4qGk781.cjs +0 -1
- package/dist/tooltip-tLiIOgjq.js +0 -1067
- package/dist/ui.cjs +0 -1
- package/dist/ui.d.ts +0 -415
- package/dist/ui.js +0 -129
- package/dist/vite.svg +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-WQwzsC7A.cjs"),n=require("./index-DF5DEvqb.cjs"),u=require("lodash-es"),N=require("react"),ce=require("react-i18next"),D=require("sonner"),ie=require("@tanstack/react-query"),z=require("lucide-react"),V=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=n.useLanguages(),{data:p,isFetching:o}=i.useLanguagePages();return{data:N.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:o}},ue=()=>{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(m=>h.removeAttribute(m.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>/,"")},C=({keyword:t,onComplete:p,field:o})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:v,fallbackLang:x}=n.useLanguages(),{mutate:h,isPending:m}=ie.useMutation({mutationFn:async()=>{const O=ue();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:o,lang:v||x,pageContent:O,keyword:t}})},onSuccess:O=>{p({fieldValue:O.field})},onError:O=>{p({fieldValue:null,error:O.message})}});return e.jsx(n.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:m?e.jsx(z.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(z.Wand2Icon,{className:"text-yellow-500"})})},pe=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let o=t;if(typeof o=="string"&&(/^".*"$/.test(o)&&(o=o.replace(/^"(.*)"$/,"$1"),o=o.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
|
|
2
|
+
`).replace(/\\"/g,'"').replace(/___DOUBLE_BACKSLASH___/g,"\\")),p==="jsonLD"||p==="metaOther")){o.includes("```")&&(o=o.replace(/^```json\s*/i,"").replace(/^```\s*/,"").replace(/\s*```$/m,"")),o=o.trim();try{JSON.parse(o)}catch{return{success:!1,error:"The AI response is not valid JSON. Please try again or edit manually."}}}return{success:!0,value:o}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error occurred"}}},he=({isOpen:t,onClose:p,onSave:o,onDiscard:d,isSaving:l=!1,fromLanguage:v,toLanguage:x})=>{const h=i.LANGUAGES[v]||v,m=i.LANGUAGES[x]||x;return e.jsx(n.Dialog,{open:t,onOpenChange:p,children:e.jsxs(n.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(n.DialogDescription,{children:['You have unsaved changes in the SEO for "',h,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(n.Button,{variant:"outline",onClick:d,disabled:l,children:"Discard Changes"}),e.jsx(n.Button,{onClick:o,disabled:l,children:l?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},ge=(t,p)=>{const o=t.selectionStart||0,d=t.selectionEnd||0,l=t.value,v=l.substring(0,o),x=l.substring(d),h=`{{${p}}}`,m=v+""+h+x,O=o+0+h.length;return{value:m,newCursorPos:O}},K=()=>{const{t}=ce.useTranslation(),[,p]=n.useSidebarActivePanel(),{data:o}=i.useChaiCurrentPage(),{data:d}=i.useBuilderPageData(),{data:l,isFetching:v}=de(),x=l==null?void 0:l.seo,h=N.useRef(null),[m,O]=N.useState("seo"),R=o==null?void 0:o.id,Q=o==null?void 0:o.pageType,L=i.usePageType(Q),{selectedLang:G,fallbackLang:Y}=n.useLanguages(),g=G||Y,[M,J]=N.useState(!1),[X,H]=N.useState(!1),[Z,P]=N.useState(!1),[w,q]=N.useState(null),[a,b]=N.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...x}),T=N.useRef({}),{mutate:ee,isPending:B}=i.useUpdatePage(),f=B||M||X,{hasPermission:se}=n.usePermissions(),r=se(i.PAGES_PERMISSIONS.EDIT_SEO),[te]=i.usePagesProps(),ne=u.get(te,"features.canResetSeoToDefault",!1),$=!G||a.jsonLD!=="{}";N.useEffect(()=>{if(!v&&x&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...x};b(s),T.current[g]=s}},[v,x,g,R]),N.useEffect(()=>{const s=c=>{const{fromLang:j,toLang:F,switchHandler:S}=c.detail,U=T.current[g];(U?!u.isEqual(U,a):!1)?(q({fromLang:j,toLang:F,switchHandler:S}),P(!0)):S()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,a,g]);const oe=async()=>{if(!(!L||!g))try{J(!0);const s=V.getSeoDefaults(L,g),c={...a,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","")};b(c),D.toast.success(t("SEO fields reset to defaults"))}catch(s){D.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},ae=async()=>{if(!(!L||!g))try{H(!0);const s=V.getSeoDefaults(L,g),c={...a,jsonLD:u.get(s,"seo.jsonLD","")};b(c),D.toast.success(t("JSON-LD reset to default"))}catch(s){D.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{H(!1)}},re=async()=>{if(!(!L||!g))try{J(!0);const s=V.getSeoDefaults(L,g),c={...a,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","{}")};b(c),D.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){D.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},W=async()=>{ee({id:l==null?void 0:l.id,seo:a,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",a),T.current[g]=a,D.toast.success("SEO & JSON-LD updated successfully")}})},I=(s,c)=>{const j=document.getElementById(c);if(j){const{value:F,newCursorPos:S}=ge(j,s);h.current={id:c,position:S},j.tagName.toLowerCase()==="input"?(j.value=F,b(k=>({...k,[j.name]:F})),j.focus(),j.setSelectionRange(S,S),[0,10,50,100,200].forEach(k=>{setTimeout(()=>{const _=document.getElementById(c);_&&(_.focus(),_.setSelectionRange(S,S))},k)})):(b(E=>({...E,[j.name]:F})),requestAnimationFrame(()=>{const E=document.getElementById(c);E&&(E.focus(),E.setSelectionRange(S,S),setTimeout(()=>{const k=document.getElementById(c);k&&(k.focus(),k.setSelectionRange(S,S))},50))}))}},y=s=>{const c={...a,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};b(c)},A=s=>c=>{if(!u.isEmpty(c.fieldValue)){const j=pe(c.fieldValue,s);j.success?y({target:{name:s,value:j.value}}):D.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to process AI response:"}),e.jsx("p",{children:j.error})]}))}c.error&&D.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:c.error})]}))},le=()=>{const s=u.get(o,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){D.toast.error("Default page JSON-LD is empty");return}y({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!r&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(n.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(n.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,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(n.Tabs,{value:m,onValueChange:O,className:"w-full",children:[e.jsxs(n.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(n.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(n.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(n.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="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(n.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>I(s,"keyword")})]}),e.jsx(n.Input,{type:"text",id:"keyword",name:"keyword",value:a.keyword,onChange:y,disabled:f||!r,placeholder:t("Enter keyword"),readOnly:!r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(C,{keyword:a.keyword,onComplete:A("title"),field:"title"}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>I(s,"title")})]})]}),e.jsx(n.Input,{type:"text",id:"title",name:"title",value:a.title,onChange:y,disabled:f||!r,placeholder:t("Enter SEO title"),readOnly:!r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{keyword:a.keyword,onComplete:A("description"),field:"description"}),r&&e.jsx(i.NestedPathSelector,{data:d??{},onSelect:s=>I(s,"description")})]})]}),e.jsx(n.Textarea,{id:"description",name:"description",rows:5,value:a.description,onChange:y,disabled:f||!r,placeholder:t("Enter SEO description"),readOnly:!r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>I(s,"canonicalUrl")})]}),e.jsx(n.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:a.canonicalUrl,onChange:y,disabled:f||!r,placeholder:t("Enter Canonical URL"),readOnly:!r})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(n.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:a.noIndex,onChange:y,disabled:f||!r,className:"h-4 w-4"}),e.jsx(n.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(n.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:a.noFollow,onChange:y,disabled:f||!r,className:"h-4 w-4"}),e.jsx(n.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:m==="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(n.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{keyword:a.keyword,onComplete:A("ogTitle"),field:"ogTitle"}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>I(s,"ogTitle")})]})]}),e.jsx(n.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:a.ogTitle,onChange:y,disabled:f||!r,placeholder:t("Enter OG title"),readOnly:!r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{keyword:a.keyword,onComplete:A("ogDescription"),field:"ogDescription"}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>I(s,"ogDescription")})]})]}),e.jsx(n.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:a.ogDescription,onChange:y,disabled:f||!r,placeholder:t("Enter OG description"),readOnly:!r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),r&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>{b({...a,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:a.ogImageId,assetUrl:a.ogImage,onChange:s=>{b({...a,ogImage:s.url,ogImageId:s.id})},disabled:f||!r,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(n.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(C,{keyword:a.keyword,onComplete:A("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:a.metaOther,onChange:s=>{y({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!r,readOnly:!r,pageData:d||{},rows:8,handleFieldInsert:I})]})]})]})})}),e.jsx("div",{className:m==="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(n.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),$&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(C,{keyword:a.keyword,onComplete:A("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(d)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:a.jsonLD,onChange:s=>{y({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!r,readOnly:!r,pageData:d||{},rows:12,handleFieldInsert:I,hasJsonLdForSelectedLang:$,copyJsonLDFromDefaultPage:le})]})})})]})})]}),r&&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:[ne?e.jsx(n.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?ae():m==="opengraph"?re():oe()},disabled:f||!r||!L,children:t(M?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(n.Button,{onClick:W,disabled:!me(a==null?void 0:a.jsonLD)||(T.current[g]?u.isEqual(T.current[g],a):!1)||f||!r,children:t(B?"Saving...":"Save")}),e.jsx(n.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>p("outline"),children:t("Cancel")})]})]}),e.jsx(he,{isOpen:Z,onClose:()=>{P(!1),q(null)},onSave:async()=>{w&&(await W(),w.switchHandler(),P(!1),q(null))},onDiscard:()=>{if(w){const s=T.current[g];s&&b(s),w.switchHandler(),P(!1),q(null)}},isSaving:B,fromLanguage:(w==null?void 0:w.fromLang)||g,toLanguage:(w==null?void 0:w.toLang)||""})]})};K.displayName="SeoPanel";exports.default=K;
|
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import { jsx as e, jsxs as n, Fragment as G } from "react/jsx-runtime";
|
|
2
|
+
import { D as W, d as Y, e as $, f as X, A as me, av as he, L as y, I as j, B as v, G as U, J as R, K as _, M, O as H, Q as q, R as Q, U as K, n as ue, w as E, x as J, y as O, a5 as ge, W as fe, X as pe, Y as xe, H as Ne, Z as be, T as ye } from "./index-Ct7ElCGK.js";
|
|
3
|
+
import { ar as ve, as as we, A as V, aw as te, aC as Ae, aD as se, aE as re, aF as de, aG as Ce, aH as Se, aI as Pe, l as Te, aJ as De } from "./index-ZuacEL1j.js";
|
|
4
|
+
import { useQuery as Le, useQueryClient as Ee } from "@tanstack/react-query";
|
|
5
|
+
import { filter as Je, find as Oe } from "lodash-es";
|
|
6
|
+
import { Info as Fe, Loader as F, Plus as ke, Eye as Ge, Edit as je, Trash as Be } from "lucide-react";
|
|
7
|
+
import { useState as g, useEffect as Z, useMemo as z } from "react";
|
|
8
|
+
import { toast as B } from "sonner";
|
|
9
|
+
const oe = () => {
|
|
10
|
+
const l = ve(), i = we();
|
|
11
|
+
return Le({
|
|
12
|
+
queryKey: [V.GET_GLOBAL_JSONLD_ITEMS],
|
|
13
|
+
queryFn: async () => i(l, { action: V.GET_GLOBAL_JSONLD_ITEMS })
|
|
14
|
+
});
|
|
15
|
+
}, Ie = ({
|
|
16
|
+
show: l,
|
|
17
|
+
onClose: i,
|
|
18
|
+
initialData: a
|
|
19
|
+
}) => /* @__PURE__ */ e(W, { open: l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(ze, { show: l, onClose: i, initialData: a }) }), ze = ({
|
|
20
|
+
show: l,
|
|
21
|
+
onClose: i,
|
|
22
|
+
initialData: a
|
|
23
|
+
}) => {
|
|
24
|
+
const [d, f] = g({
|
|
25
|
+
name: "",
|
|
26
|
+
content: "",
|
|
27
|
+
description: "",
|
|
28
|
+
enabledByDefaultForNewPages: !1
|
|
29
|
+
}), [x, S] = g(!1), { data: u } = te(), { mutateAsync: C, isPending: p } = Ae(), { mutateAsync: c } = se(), w = Ee();
|
|
30
|
+
Z(() => {
|
|
31
|
+
f(a ? {
|
|
32
|
+
name: a.name,
|
|
33
|
+
description: a.description,
|
|
34
|
+
content: JSON.stringify(a.jsonld, null, 2),
|
|
35
|
+
enabledByDefaultForNewPages: !1
|
|
36
|
+
} : { name: "", description: "", content: "", enabledByDefaultForNewPages: !1 }), S(!1);
|
|
37
|
+
}, [l, a]);
|
|
38
|
+
const o = async () => {
|
|
39
|
+
if (!d.name || !d.content) {
|
|
40
|
+
B.error("Please enter a name and content");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const t = de(d.content);
|
|
44
|
+
if (!t.isValid) {
|
|
45
|
+
B.error("Invalid JSON-LD content");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const N = {
|
|
49
|
+
name: d.name,
|
|
50
|
+
jsonld: t.parsed,
|
|
51
|
+
addToExistingPages: x,
|
|
52
|
+
addToNewPages: d.enabledByDefaultForNewPages,
|
|
53
|
+
description: d.description
|
|
54
|
+
};
|
|
55
|
+
a != null && a.primaryPageId && (N.primaryPage = a.primaryPageId);
|
|
56
|
+
const A = await C(N);
|
|
57
|
+
u != null && u.id && (A != null && A.id) && !(a != null && a.primaryPageId) && (await c({
|
|
58
|
+
schemaId: A.id,
|
|
59
|
+
pageId: u.id,
|
|
60
|
+
enabled: !0
|
|
61
|
+
}), w.invalidateQueries({
|
|
62
|
+
queryKey: [V.GET_LANGUAGE_PAGES, u.id]
|
|
63
|
+
})), i();
|
|
64
|
+
};
|
|
65
|
+
return /* @__PURE__ */ n(Y, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
|
|
66
|
+
/* @__PURE__ */ e($, { children: /* @__PURE__ */ e(X, { children: "Add New Shared JSON-LD Schema" }) }),
|
|
67
|
+
/* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
|
|
68
|
+
(a == null ? void 0 : a.languageCode) && /* @__PURE__ */ n(me, { className: "border-blue-200 bg-blue-50", children: [
|
|
69
|
+
/* @__PURE__ */ e(Fe, { className: "h-4 w-4 text-blue-600" }),
|
|
70
|
+
/* @__PURE__ */ n(he, { className: "text-sm text-blue-800", children: [
|
|
71
|
+
"You are creating a ",
|
|
72
|
+
/* @__PURE__ */ e("span", { className: "font-semibold", children: a.languageCode }),
|
|
73
|
+
" language version of this schema. This will be linked to the default language schema."
|
|
74
|
+
] })
|
|
75
|
+
] }),
|
|
76
|
+
/* @__PURE__ */ n("div", { children: [
|
|
77
|
+
/* @__PURE__ */ e(y, { htmlFor: "new-name", children: "Schema Name" }),
|
|
78
|
+
/* @__PURE__ */ e(
|
|
79
|
+
j,
|
|
80
|
+
{
|
|
81
|
+
id: "new-name",
|
|
82
|
+
value: d.name,
|
|
83
|
+
onChange: (t) => f({ ...d, name: t.target.value }),
|
|
84
|
+
placeholder: "e.g., Product Schema",
|
|
85
|
+
className: "text-xs"
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ n("div", { children: [
|
|
90
|
+
/* @__PURE__ */ e(y, { htmlFor: "new-description", children: "Description" }),
|
|
91
|
+
/* @__PURE__ */ e(
|
|
92
|
+
j,
|
|
93
|
+
{
|
|
94
|
+
id: "new-description",
|
|
95
|
+
value: d.description || "",
|
|
96
|
+
onChange: (t) => f({ ...d, description: t.target.value }),
|
|
97
|
+
placeholder: "Brief description of this schema"
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
] }),
|
|
101
|
+
/* @__PURE__ */ n("div", { children: [
|
|
102
|
+
/* @__PURE__ */ e(y, { htmlFor: "new-content", children: "JSON-LD Content" }),
|
|
103
|
+
/* @__PURE__ */ e(
|
|
104
|
+
re,
|
|
105
|
+
{
|
|
106
|
+
id: "new-content",
|
|
107
|
+
value: d.content || "{}",
|
|
108
|
+
onChange: (t) => f({ ...d, content: t }),
|
|
109
|
+
placeholder: "Enter JSON-LD markup...",
|
|
110
|
+
rows: 10
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] }),
|
|
114
|
+
!(a != null && a.primaryPageId) && /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 pt-2", children: [
|
|
115
|
+
/* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
|
|
116
|
+
/* @__PURE__ */ e(
|
|
117
|
+
"input",
|
|
118
|
+
{
|
|
119
|
+
type: "checkbox",
|
|
120
|
+
id: "add-to-all-existing",
|
|
121
|
+
checked: x,
|
|
122
|
+
onChange: (t) => S(t.target.checked),
|
|
123
|
+
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
/* @__PURE__ */ n(y, { htmlFor: "add-to-all-existing", children: [
|
|
127
|
+
/* @__PURE__ */ e("div", { children: "Add to all existing pages" }),
|
|
128
|
+
/* @__PURE__ */ e("div", { className: "text-xs font-light text-muted-foreground", children: "This schema will be added to all existing pages on your site" })
|
|
129
|
+
] })
|
|
130
|
+
] }),
|
|
131
|
+
/* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
|
|
132
|
+
/* @__PURE__ */ e(
|
|
133
|
+
"input",
|
|
134
|
+
{
|
|
135
|
+
type: "checkbox",
|
|
136
|
+
id: "new-enabled",
|
|
137
|
+
checked: d.enabledByDefaultForNewPages,
|
|
138
|
+
onChange: (t) => f({ ...d, enabledByDefaultForNewPages: t.target.checked }),
|
|
139
|
+
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
/* @__PURE__ */ n(y, { htmlFor: "new-enabled", children: [
|
|
143
|
+
/* @__PURE__ */ e("div", { children: "Enabled by default for new pages" }),
|
|
144
|
+
/* @__PURE__ */ e("div", { className: "text-xs font-light text-muted-foreground", children: "New pages will automatically include this schema" })
|
|
145
|
+
] })
|
|
146
|
+
] })
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ e("div", { className: "border-t pt-3", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-end gap-2", children: [
|
|
149
|
+
/* @__PURE__ */ e(v, { disabled: p, variant: "outline", type: "button", size: "sm", onClick: () => i(), children: "Cancel" }),
|
|
150
|
+
/* @__PURE__ */ e(v, { disabled: p, type: "button", size: "sm", onClick: o, children: p ? /* @__PURE__ */ n(G, { children: [
|
|
151
|
+
/* @__PURE__ */ e(F, { className: "h-4 w-4 animate-spin" }),
|
|
152
|
+
" Adding"
|
|
153
|
+
] }) : /* @__PURE__ */ n(G, { children: [
|
|
154
|
+
"Add Schema",
|
|
155
|
+
(a == null ? void 0 : a.languageCode) && ` (${a.languageCode})`
|
|
156
|
+
] }) })
|
|
157
|
+
] }) })
|
|
158
|
+
] })
|
|
159
|
+
] });
|
|
160
|
+
}, Ue = ({ id: l, onClose: i }) => /* @__PURE__ */ e(W, { open: !!l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(Re, { id: l, onClose: i }) }), Re = ({ id: l, onClose: i }) => {
|
|
161
|
+
const [a, d] = g({
|
|
162
|
+
name: "",
|
|
163
|
+
content: "",
|
|
164
|
+
description: "",
|
|
165
|
+
enabledByDefaultForNewPages: !1
|
|
166
|
+
}), [f, x] = g(!1), [S, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Ce(), { mutateAsync: t } = Se(), { mutateAsync: N } = Pe();
|
|
167
|
+
Z(() => {
|
|
168
|
+
var m, T;
|
|
169
|
+
if (l && c) {
|
|
170
|
+
const b = c.find((L) => L.id === l);
|
|
171
|
+
b && (d({
|
|
172
|
+
name: b.name,
|
|
173
|
+
description: ((m = b.metadata) == null ? void 0 : m.description) || "",
|
|
174
|
+
content: JSON.stringify(b.jsonld, null, 2),
|
|
175
|
+
enabledByDefaultForNewPages: ((T = b.metadata) == null ? void 0 : T.addToNewPages) || !1
|
|
176
|
+
}), p(!!b.primaryPage));
|
|
177
|
+
}
|
|
178
|
+
}, [l, c]);
|
|
179
|
+
const A = async () => {
|
|
180
|
+
if (!a.name || !a.content) {
|
|
181
|
+
B.error("Please enter a name and content");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const m = de(a.content);
|
|
185
|
+
if (!m.isValid) {
|
|
186
|
+
B.error("Invalid JSON-LD content");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const T = {
|
|
190
|
+
id: l,
|
|
191
|
+
name: a.name,
|
|
192
|
+
jsonld: m.parsed,
|
|
193
|
+
addToNewPages: a.enabledByDefaultForNewPages,
|
|
194
|
+
description: a.description
|
|
195
|
+
};
|
|
196
|
+
await w(T), i();
|
|
197
|
+
}, I = async () => {
|
|
198
|
+
try {
|
|
199
|
+
await t(l);
|
|
200
|
+
} finally {
|
|
201
|
+
x(!1);
|
|
202
|
+
}
|
|
203
|
+
}, P = async () => {
|
|
204
|
+
try {
|
|
205
|
+
await N(l);
|
|
206
|
+
} finally {
|
|
207
|
+
u(!1);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
return /* @__PURE__ */ n(Y, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
|
|
211
|
+
/* @__PURE__ */ e($, { children: /* @__PURE__ */ e(X, { children: "Edit Shared JSON-LD Schema" }) }),
|
|
212
|
+
/* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
|
|
213
|
+
!C && /* @__PURE__ */ n("div", { className: "flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2", children: [
|
|
214
|
+
/* @__PURE__ */ n("div", { children: [
|
|
215
|
+
/* @__PURE__ */ e("div", { className: "text-sm font-medium text-blue-900", children: "Manage Existing Pages" }),
|
|
216
|
+
/* @__PURE__ */ e("div", { className: "text-xs text-blue-700", children: "Add or remove this schema from all existing pages on your site" })
|
|
217
|
+
] }),
|
|
218
|
+
/* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
219
|
+
/* @__PURE__ */ e(v, { size: "sm", className: "text-xs", variant: "outline", onClick: () => x(!0), children: "Add to all existing" }),
|
|
220
|
+
/* @__PURE__ */ e(v, { size: "sm", variant: "ghost", className: "text-xs", onClick: () => u(!0), children: "Remove from all" })
|
|
221
|
+
] })
|
|
222
|
+
] }),
|
|
223
|
+
/* @__PURE__ */ n("div", { children: [
|
|
224
|
+
/* @__PURE__ */ e(y, { htmlFor: "edit-name", children: "Schema Name" }),
|
|
225
|
+
/* @__PURE__ */ e(
|
|
226
|
+
j,
|
|
227
|
+
{
|
|
228
|
+
id: "edit-name",
|
|
229
|
+
value: a.name,
|
|
230
|
+
onChange: (m) => d({ ...a, name: m.target.value }),
|
|
231
|
+
placeholder: "e.g., Product Schema",
|
|
232
|
+
className: "text-xs"
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
] }),
|
|
236
|
+
/* @__PURE__ */ n("div", { children: [
|
|
237
|
+
/* @__PURE__ */ e(y, { htmlFor: "edit-description", children: "Description" }),
|
|
238
|
+
/* @__PURE__ */ e(
|
|
239
|
+
j,
|
|
240
|
+
{
|
|
241
|
+
id: "edit-description",
|
|
242
|
+
value: a.description || "",
|
|
243
|
+
onChange: (m) => d({ ...a, description: m.target.value }),
|
|
244
|
+
placeholder: "Brief description of this schema"
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
] }),
|
|
248
|
+
/* @__PURE__ */ n("div", { children: [
|
|
249
|
+
/* @__PURE__ */ e(y, { htmlFor: "edit-content", children: "JSON-LD Content" }),
|
|
250
|
+
/* @__PURE__ */ e(
|
|
251
|
+
re,
|
|
252
|
+
{
|
|
253
|
+
id: "edit-content",
|
|
254
|
+
value: a.content || "{}",
|
|
255
|
+
onChange: (m) => d({ ...a, content: m }),
|
|
256
|
+
placeholder: "Enter JSON-LD markup...",
|
|
257
|
+
rows: 10
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
] }),
|
|
261
|
+
!C && /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
|
|
262
|
+
/* @__PURE__ */ e(
|
|
263
|
+
"input",
|
|
264
|
+
{
|
|
265
|
+
type: "checkbox",
|
|
266
|
+
id: "edit-enabled",
|
|
267
|
+
checked: a.enabledByDefaultForNewPages,
|
|
268
|
+
onChange: (m) => d({ ...a, enabledByDefaultForNewPages: m.target.checked }),
|
|
269
|
+
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
270
|
+
}
|
|
271
|
+
),
|
|
272
|
+
/* @__PURE__ */ n(y, { htmlFor: "edit-enabled", children: [
|
|
273
|
+
/* @__PURE__ */ e("div", { children: "Enabled by default for new pages" }),
|
|
274
|
+
/* @__PURE__ */ e("div", { className: "text-xs font-light text-muted-foreground", children: "New pages will automatically include this schema" })
|
|
275
|
+
] })
|
|
276
|
+
] }),
|
|
277
|
+
/* @__PURE__ */ e("div", { className: "border-t pt-3", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-end gap-2", children: [
|
|
278
|
+
/* @__PURE__ */ e(v, { disabled: o, variant: "outline", type: "button", size: "sm", onClick: () => i(), children: "Cancel" }),
|
|
279
|
+
/* @__PURE__ */ e(v, { disabled: o, type: "button", size: "sm", onClick: A, children: o ? /* @__PURE__ */ n(G, { children: [
|
|
280
|
+
/* @__PURE__ */ e(F, { className: "h-4 w-4 animate-spin" }),
|
|
281
|
+
" Updating"
|
|
282
|
+
] }) : "Update Schema" })
|
|
283
|
+
] }) })
|
|
284
|
+
] }),
|
|
285
|
+
/* @__PURE__ */ e(U, { open: f, onOpenChange: x, children: /* @__PURE__ */ n(R, { children: [
|
|
286
|
+
/* @__PURE__ */ n(_, { children: [
|
|
287
|
+
/* @__PURE__ */ e(M, { children: "Add to All Existing Pages?" }),
|
|
288
|
+
/* @__PURE__ */ n(H, { children: [
|
|
289
|
+
"This will add the schema ",
|
|
290
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: a.name }),
|
|
291
|
+
" to all existing pages on your site. This action cannot be undone automatically."
|
|
292
|
+
] })
|
|
293
|
+
] }),
|
|
294
|
+
/* @__PURE__ */ n(q, { children: [
|
|
295
|
+
/* @__PURE__ */ e(Q, { children: "Cancel" }),
|
|
296
|
+
/* @__PURE__ */ e(K, { onClick: I, children: "Add to All" })
|
|
297
|
+
] })
|
|
298
|
+
] }) }),
|
|
299
|
+
/* @__PURE__ */ e(U, { open: S, onOpenChange: u, children: /* @__PURE__ */ n(R, { children: [
|
|
300
|
+
/* @__PURE__ */ n(_, { children: [
|
|
301
|
+
/* @__PURE__ */ e(M, { children: "Remove from All Pages?" }),
|
|
302
|
+
/* @__PURE__ */ n(H, { children: [
|
|
303
|
+
"This will remove the schema ",
|
|
304
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: a.name }),
|
|
305
|
+
" from all existing pages on your site. This action cannot be undone automatically."
|
|
306
|
+
] })
|
|
307
|
+
] }),
|
|
308
|
+
/* @__PURE__ */ n(q, { children: [
|
|
309
|
+
/* @__PURE__ */ e(Q, { children: "Cancel" }),
|
|
310
|
+
/* @__PURE__ */ e(K, { onClick: P, className: "bg-red-500 hover:bg-red-600", children: "Remove from All" })
|
|
311
|
+
] })
|
|
312
|
+
] }) })
|
|
313
|
+
] });
|
|
314
|
+
};
|
|
315
|
+
function $e() {
|
|
316
|
+
const [l, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [S, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = ue(), { data: t } = te(), { 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) => {
|
|
317
|
+
const h = o ? Oe(c, (D) => D.primaryPage === r.id && D.lang === o) : null;
|
|
318
|
+
return {
|
|
319
|
+
defaultSchema: r,
|
|
320
|
+
languageVersion: h,
|
|
321
|
+
// Use language version if available, otherwise use default
|
|
322
|
+
displayItem: h || r,
|
|
323
|
+
hasLanguageVersion: !!h
|
|
324
|
+
};
|
|
325
|
+
}) : [], [c, o]), [b, L] = g([]), k = b.length > 0 ? b : (t == null ? void 0 : t.globalJsonLds) || [];
|
|
326
|
+
Z(() => {
|
|
327
|
+
t != null && t.globalJsonLds && L(t.globalJsonLds);
|
|
328
|
+
}, [t == null ? void 0 : t.globalJsonLds]);
|
|
329
|
+
const ie = async (s) => {
|
|
330
|
+
if (!(t != null && t.id)) return;
|
|
331
|
+
p(s);
|
|
332
|
+
const r = k.includes(s), h = r ? k.filter((D) => D !== s) : [...k, s];
|
|
333
|
+
L(h);
|
|
334
|
+
try {
|
|
335
|
+
await I({
|
|
336
|
+
schemaId: s,
|
|
337
|
+
pageId: t.id,
|
|
338
|
+
enabled: !r
|
|
339
|
+
});
|
|
340
|
+
} catch {
|
|
341
|
+
L(t.globalJsonLds);
|
|
342
|
+
} finally {
|
|
343
|
+
p(null);
|
|
344
|
+
}
|
|
345
|
+
}, ce = async (s) => {
|
|
346
|
+
p(s);
|
|
347
|
+
try {
|
|
348
|
+
await A(s);
|
|
349
|
+
} finally {
|
|
350
|
+
p(null);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
return /* @__PURE__ */ n("div", { className: "rounded border bg-muted p-2", children: [
|
|
354
|
+
/* @__PURE__ */ n("div", { className: "flex items-center justify-between pb-2", children: [
|
|
355
|
+
/* @__PURE__ */ n("div", { children: [
|
|
356
|
+
/* @__PURE__ */ e("div", { className: "text-xs font-medium", children: "Shared JSON-LD Templates" }),
|
|
357
|
+
/* @__PURE__ */ e("div", { className: "w-full text-xs text-gray-500", children: "Manage reusable JSON-LD schemas that can be applied across multiple pages" })
|
|
358
|
+
] }),
|
|
359
|
+
!o && /* @__PURE__ */ n(E, { delayDuration: 0, children: [
|
|
360
|
+
/* @__PURE__ */ e(
|
|
361
|
+
J,
|
|
362
|
+
{
|
|
363
|
+
type: "button",
|
|
364
|
+
disabled: w,
|
|
365
|
+
className: "rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",
|
|
366
|
+
onClick: (s) => {
|
|
367
|
+
s.stopPropagation(), i(!0);
|
|
368
|
+
},
|
|
369
|
+
children: w ? /* @__PURE__ */ e(F, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(ke, { className: "h-4 w-4" })
|
|
370
|
+
}
|
|
371
|
+
),
|
|
372
|
+
/* @__PURE__ */ e(O, { children: "Add new schema" })
|
|
373
|
+
] })
|
|
374
|
+
] }),
|
|
375
|
+
/* @__PURE__ */ n(ge, { className: "max-h-96 overflow-y-auto", children: [
|
|
376
|
+
/* @__PURE__ */ n("div", { className: "space-y-2", children: [
|
|
377
|
+
(!c || (c == null ? void 0 : c.length) === 0) && !w && /* @__PURE__ */ e("div", { className: "flex items-center justify-center px-2 py-4 text-xs", children: "No shared JSON-LD found" }),
|
|
378
|
+
T.map(({ defaultSchema: s, displayItem: r, hasLanguageVersion: h }) => {
|
|
379
|
+
var ae, le;
|
|
380
|
+
const D = k.includes(r.id), ee = m.includes(s.id), ne = h && o ? ee : D;
|
|
381
|
+
return /* @__PURE__ */ n(
|
|
382
|
+
fe,
|
|
383
|
+
{
|
|
384
|
+
className: `relative border-gray-300 p-0 shadow-none transition-all ${C === r.id ? "pointer-events-none" : ""}`,
|
|
385
|
+
children: [
|
|
386
|
+
C === 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(F, { className: "h-5 w-5 animate-spin text-primary" }) }),
|
|
387
|
+
/* @__PURE__ */ e(pe, { className: "p-2", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
|
|
388
|
+
/* @__PURE__ */ n("div", { className: "flex items-center gap-3", children: [
|
|
389
|
+
(h || !o) && /* @__PURE__ */ n(E, { delayDuration: 0, children: [
|
|
390
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
391
|
+
"input",
|
|
392
|
+
{
|
|
393
|
+
type: "checkbox",
|
|
394
|
+
checked: ne,
|
|
395
|
+
onChange: () => ie(s.id),
|
|
396
|
+
disabled: !!(h && o),
|
|
397
|
+
className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
|
|
398
|
+
}
|
|
399
|
+
) }),
|
|
400
|
+
h && o && /* @__PURE__ */ e(O, { children: "Using the default language state" })
|
|
401
|
+
] }),
|
|
402
|
+
/* @__PURE__ */ n("div", { children: [
|
|
403
|
+
/* @__PURE__ */ n(xe, { className: "flex items-center gap-2 text-sm leading-none", children: [
|
|
404
|
+
r.name,
|
|
405
|
+
h && o && /* @__PURE__ */ n("span", { className: "text-xs font-normal text-muted-foreground", children: [
|
|
406
|
+
"(",
|
|
407
|
+
o,
|
|
408
|
+
")"
|
|
409
|
+
] }),
|
|
410
|
+
ne && /* @__PURE__ */ e("span", { className: "sr-only text-xs font-normal text-muted-foreground", children: "Enabled" })
|
|
411
|
+
] }),
|
|
412
|
+
((ae = r == null ? void 0 : r.metadata) == null ? void 0 : ae.description) && /* @__PURE__ */ e("p", { className: "mt-1 text-xs leading-none text-muted-foreground", children: (le = r == null ? void 0 : r.metadata) == null ? void 0 : le.description })
|
|
413
|
+
] })
|
|
414
|
+
] }),
|
|
415
|
+
/* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
416
|
+
/* @__PURE__ */ e("div", { className: "mx-2 h-6 w-px bg-border" }),
|
|
417
|
+
/* @__PURE__ */ n(E, { delayDuration: 0, children: [
|
|
418
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
419
|
+
v,
|
|
420
|
+
{
|
|
421
|
+
type: "button",
|
|
422
|
+
variant: "ghost",
|
|
423
|
+
size: "icon",
|
|
424
|
+
className: "h-5 w-5 p-0",
|
|
425
|
+
onClick: () => u(r.id),
|
|
426
|
+
children: /* @__PURE__ */ e(Ge, { className: "h-4 w-4" })
|
|
427
|
+
}
|
|
428
|
+
) }),
|
|
429
|
+
/* @__PURE__ */ e(O, { children: "View schema" })
|
|
430
|
+
] }),
|
|
431
|
+
(h || !o) && /* @__PURE__ */ n(G, { children: [
|
|
432
|
+
/* @__PURE__ */ n(E, { delayDuration: 0, children: [
|
|
433
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(
|
|
434
|
+
v,
|
|
435
|
+
{
|
|
436
|
+
type: "button",
|
|
437
|
+
variant: "ghost",
|
|
438
|
+
size: "icon",
|
|
439
|
+
className: "h-5 w-5 p-0",
|
|
440
|
+
onClick: () => x(r.id),
|
|
441
|
+
children: /* @__PURE__ */ e(je, { className: "h-4 w-4" })
|
|
442
|
+
}
|
|
443
|
+
) }),
|
|
444
|
+
/* @__PURE__ */ e(O, { children: "Edit schema" })
|
|
445
|
+
] }),
|
|
446
|
+
/* @__PURE__ */ n(U, { children: [
|
|
447
|
+
/* @__PURE__ */ n(E, { delayDuration: 0, children: [
|
|
448
|
+
/* @__PURE__ */ e(J, { asChild: !0, children: /* @__PURE__ */ e(Ne, { 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" }) }) }),
|
|
449
|
+
/* @__PURE__ */ e(O, { children: "Delete schema" })
|
|
450
|
+
] }),
|
|
451
|
+
/* @__PURE__ */ n(R, { children: [
|
|
452
|
+
/* @__PURE__ */ n(_, { children: [
|
|
453
|
+
/* @__PURE__ */ e(M, { children: "Delete Schema" }),
|
|
454
|
+
/* @__PURE__ */ n(H, { children: [
|
|
455
|
+
"Are you sure you want to delete",
|
|
456
|
+
" ",
|
|
457
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: r.name }),
|
|
458
|
+
"? This action cannot be undone."
|
|
459
|
+
] })
|
|
460
|
+
] }),
|
|
461
|
+
/* @__PURE__ */ n(q, { children: [
|
|
462
|
+
/* @__PURE__ */ e(Q, { type: "button", children: "Cancel" }),
|
|
463
|
+
/* @__PURE__ */ e(
|
|
464
|
+
K,
|
|
465
|
+
{
|
|
466
|
+
type: "button",
|
|
467
|
+
onClick: () => ce(r.id),
|
|
468
|
+
className: "bg-red-500 text-white hover:bg-red-600",
|
|
469
|
+
children: "Delete"
|
|
470
|
+
}
|
|
471
|
+
)
|
|
472
|
+
] })
|
|
473
|
+
] })
|
|
474
|
+
] })
|
|
475
|
+
] })
|
|
476
|
+
] })
|
|
477
|
+
] }) }),
|
|
478
|
+
!h && o && /* @__PURE__ */ e(be, { className: "px-2 pb-2", children: /* @__PURE__ */ n("div", { className: "flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3", children: [
|
|
479
|
+
/* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
|
|
480
|
+
/* @__PURE__ */ n("div", { className: "max-w-xl text-center text-xs text-gray-500", children: [
|
|
481
|
+
"Not available in '",
|
|
482
|
+
o,
|
|
483
|
+
"' language. Default language JSONLD will be used."
|
|
484
|
+
] }),
|
|
485
|
+
ee && /* @__PURE__ */ e("span", { className: "rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700", children: "Enabled in default" })
|
|
486
|
+
] }),
|
|
487
|
+
/* @__PURE__ */ e(
|
|
488
|
+
v,
|
|
489
|
+
{
|
|
490
|
+
type: "button",
|
|
491
|
+
size: "sm",
|
|
492
|
+
variant: "outline",
|
|
493
|
+
className: "mt-2",
|
|
494
|
+
onClick: () => {
|
|
495
|
+
d({
|
|
496
|
+
name: s.name,
|
|
497
|
+
description: s.description || "",
|
|
498
|
+
jsonld: s.jsonld,
|
|
499
|
+
languageCode: o,
|
|
500
|
+
primaryPageId: s.id
|
|
501
|
+
}), i(!0);
|
|
502
|
+
},
|
|
503
|
+
children: "Copy & Edit from default language"
|
|
504
|
+
}
|
|
505
|
+
)
|
|
506
|
+
] }) })
|
|
507
|
+
]
|
|
508
|
+
},
|
|
509
|
+
s.id
|
|
510
|
+
);
|
|
511
|
+
})
|
|
512
|
+
] }),
|
|
513
|
+
w && /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-4", children: /* @__PURE__ */ e(F, { className: "h-5 w-5 animate-spin" }) })
|
|
514
|
+
] }),
|
|
515
|
+
/* @__PURE__ */ e(
|
|
516
|
+
Ie,
|
|
517
|
+
{
|
|
518
|
+
show: l,
|
|
519
|
+
onClose: () => {
|
|
520
|
+
i(!1), d(void 0);
|
|
521
|
+
},
|
|
522
|
+
initialData: a
|
|
523
|
+
}
|
|
524
|
+
),
|
|
525
|
+
/* @__PURE__ */ e(Ue, { id: f, onClose: () => x(null) }),
|
|
526
|
+
/* @__PURE__ */ e(
|
|
527
|
+
_e,
|
|
528
|
+
{
|
|
529
|
+
schema: c == null ? void 0 : c.find((s) => s.id === S),
|
|
530
|
+
onClose: () => u(null)
|
|
531
|
+
}
|
|
532
|
+
)
|
|
533
|
+
] });
|
|
534
|
+
}
|
|
535
|
+
const _e = ({ schema: l, onClose: i }) => /* @__PURE__ */ e(W, { open: !!l, onOpenChange: i, children: /* @__PURE__ */ n(Y, { className: "max-w-2xl", children: [
|
|
536
|
+
/* @__PURE__ */ e($, { children: /* @__PURE__ */ n(X, { className: "flex items-center gap-2", children: [
|
|
537
|
+
l == null ? void 0 : l.name,
|
|
538
|
+
(l == null ? void 0 : l.lang) && /* @__PURE__ */ n("span", { className: "text-sm font-normal text-muted-foreground", children: [
|
|
539
|
+
"(",
|
|
540
|
+
l.lang,
|
|
541
|
+
")"
|
|
542
|
+
] })
|
|
543
|
+
] }) }),
|
|
544
|
+
/* @__PURE__ */ n("div", { className: "space-y-3", children: [
|
|
545
|
+
(l == null ? void 0 : l.description) && /* @__PURE__ */ n("div", { children: [
|
|
546
|
+
/* @__PURE__ */ e("div", { className: "text-xs font-medium text-muted-foreground", children: "Description" }),
|
|
547
|
+
/* @__PURE__ */ e("div", { className: "text-sm", children: l.description })
|
|
548
|
+
] }),
|
|
549
|
+
/* @__PURE__ */ n("div", { children: [
|
|
550
|
+
/* @__PURE__ */ e("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: "JSON-LD Schema" }),
|
|
551
|
+
/* @__PURE__ */ e(
|
|
552
|
+
ye,
|
|
553
|
+
{
|
|
554
|
+
value: JSON.stringify(l == null ? void 0 : l.jsonld, null, 2),
|
|
555
|
+
readOnly: !0,
|
|
556
|
+
className: "font-mono text-xs",
|
|
557
|
+
rows: 15
|
|
558
|
+
}
|
|
559
|
+
)
|
|
560
|
+
] })
|
|
561
|
+
] })
|
|
562
|
+
] }) });
|
|
563
|
+
export {
|
|
564
|
+
$e as default
|
|
565
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DF5DEvqb.cjs"),c=require("./index-WQwzsC7A.cjs"),I=require("@tanstack/react-query"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},M=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(U,{show:t,onClose:d,initialData:n})}),U=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,S]=x.useState(!1),{data:g}=c.useChaiCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),S(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.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(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.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(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...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(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...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=>p({...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:N,onChange:l=>S(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=>p({...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(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},_=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(H,{id:t,onClose:d})}),H=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[S,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,T;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((T=y.metadata)==null?void 0:T.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const T={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(T),d()},F=async()=>{try{await l(t)}finally{N(!1)}},C=async()=>{try{await b(t)}finally{g(!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:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange: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(s.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})]}),!A&&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(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,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:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:S,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:C,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function Q(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[S,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=s.useLanguages(),{data:l}=c.useChaiCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),C=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(C==null?void 0:C.globalJsonLds)||[],[C]),T=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,D=>D.primaryPage===o.id&&D.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(D=>D!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(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:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.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)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),T.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const D=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:D;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===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(f.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:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&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,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.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(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.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(f.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:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&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."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{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)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(M,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(_,{id:p,onClose:()=>N(null)}),e.jsx(V,{schema:u==null?void 0:u.find(a=>a.id===S),onClose:()=>g(null)})]})}const V=({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=Q;
|