@chaibuilder/sdk 4.0.0-beta.24 → 4.0.0-beta.25
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-DTcPSOGn.js → 2SSKDMRQ-Bk_4y8lw.js} +2 -2
- package/dist/{2SSKDMRQ-C6XmPkPR.cjs → 2SSKDMRQ-vWeQ_IyI.cjs} +1 -1
- package/dist/{AP7HFJJL-6aBLUYOi.cjs → AP7HFJJL-CMPLeI6t.cjs} +1 -1
- package/dist/{AP7HFJJL-CVazlaEj.js → AP7HFJJL-D_mI2XSw.js} +1 -1
- package/dist/{IconPicker-sbWeQ9M9.cjs → IconPicker-DB_PpKvH.cjs} +1 -1
- package/dist/{IconPicker-CcBoA1K0.js → IconPicker-jc6_JzXf.js} +1 -1
- package/dist/{WDYDFRGG-CwiYliX0.js → WDYDFRGG-B4H3RPcp.js} +2 -2
- package/dist/{WDYDFRGG-BtzyRDmj.cjs → WDYDFRGG-D7vzbPjk.cjs} +1 -1
- package/dist/{active-in-another-tab-B4O3FEEg.js → active-in-another-tab-CDhFxBU7.js} +2 -2
- package/dist/{active-in-another-tab-DRJY0QqU.cjs → active-in-another-tab-CMPHyyHE.cjs} +1 -1
- package/dist/{add-new-language-page-BfYL9jXF.js → add-new-language-page-BliZ46WW.js} +3 -3
- package/dist/{add-new-language-page-CKIRTFjr.cjs → add-new-language-page-IbMzbf4v.cjs} +1 -1
- package/dist/{add-new-page-dzN_CD2c.cjs → add-new-page-BJJqSKp0.cjs} +1 -1
- package/dist/{add-new-page-DVgxz4fs.js → add-new-page-DUCKfyWo.js} +2 -2
- package/dist/{ai-panel-content-Dyw4RHCV.cjs → ai-panel-content-DWOqjq3Z.cjs} +1 -1
- package/dist/{ai-panel-content-D5eFLI_B.js → ai-panel-content-GeQIaXy8.js} +3 -3
- package/dist/{ai-panel-default-lang-DEj9Qx2M.cjs → ai-panel-default-lang-DGNDrfam.cjs} +2 -2
- package/dist/{ai-panel-default-lang-Cj7meZBD.js → ai-panel-default-lang-VQsV6KB3.js} +3 -3
- package/dist/{ai-panel-other-lang-Da2XLEcm.cjs → ai-panel-other-lang-DvXF0Nn5.cjs} +1 -1
- package/dist/{ai-panel-other-lang-Cbi6HKzd.js → ai-panel-other-lang-SuC8jyfr.js} +3 -3
- package/dist/{ai-prompt-input-B6QoqT9B.js → ai-prompt-input-CB6iQAmE.js} +1 -1
- package/dist/{ai-prompt-input-DXS8gzex.cjs → ai-prompt-input-a8s-JrZb.cjs} +1 -1
- package/dist/{ai-translation-prompt-Dmq_Ahjf.js → ai-translation-prompt-CoNVDclG.js} +1 -1
- package/dist/{ai-translation-prompt-Uswft8iz.cjs → ai-translation-prompt-Qn1Sz4BI.cjs} +1 -1
- package/dist/change-password-modal-BtdsU0mm.cjs +1 -0
- package/dist/change-password-modal-CMEo8lEm.js +137 -0
- package/dist/{code-editor-wQWmwFKW.js → code-editor-CTMQr0aU.js} +1 -1
- package/dist/{code-editor-DbSBrsUA.cjs → code-editor-CjatfjZe.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-Dkkzk8YZ.cjs → continue-editing-in-this-client-7swLl0kq.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-BV0OrgEU.js → continue-editing-in-this-client-CNVJZvXQ.js} +2 -2
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{css-import-modal-Co_YLkLB.js → css-import-modal-B3XY8Hzw.js} +1 -1
- package/dist/{css-import-modal-C3f5sphx.cjs → css-import-modal-D2RqE-V0.cjs} +1 -1
- package/dist/{delete-design-token-CJPAcsWp.js → delete-design-token-DEyYFVHU.js} +1 -1
- package/dist/{delete-design-token-zzNmNYLR.cjs → delete-design-token-Dd3b86G7.cjs} +1 -1
- package/dist/{delete-page-CQTjB7ZZ.js → delete-page-BSn5mRvk.js} +2 -2
- package/dist/{delete-page-6lInxYM_.cjs → delete-page-BfsmsTek.cjs} +1 -1
- package/dist/{design-token-usage-blwlGuEE.cjs → design-token-usage-BY8meqAt.cjs} +1 -1
- package/dist/{design-token-usage-BQY6eqzE.js → design-token-usage-f20BdlHE.js} +1 -1
- package/dist/{digital-asset-manager-cGUpTcu3.cjs → digital-asset-manager-Pi0YiB35.cjs} +1 -1
- package/dist/{digital-asset-manager-lPKoJ4FH.js → digital-asset-manager-iXt27NlP.js} +3 -3
- package/dist/{duplicate-page-Dmgqp93w.js → duplicate-page-BuVub6uY.js} +3 -3
- package/dist/{duplicate-page-rYeBMwHR.cjs → duplicate-page-g5hiQkrZ.cjs} +1 -1
- package/dist/{dynamic-page-selector-CVyA9Zp0.js → dynamic-page-selector-NZ-rKLo3.js} +2 -2
- package/dist/{dynamic-page-selector-zqGqpcww.cjs → dynamic-page-selector-z6UGEjk1.cjs} +1 -1
- package/dist/{get-chai-builder-theme-CfJkQYZc.js → get-chai-builder-theme-CHXhAcdV.js} +1 -1
- package/dist/{get-chai-builder-theme-Dm1z70lQ.cjs → get-chai-builder-theme-CMypjJk8.cjs} +1 -1
- package/dist/{image-editor-mVBb0VD_.js → image-editor--WT9183_.js} +1 -1
- package/dist/{image-editor-Cn1DgrNp.cjs → image-editor-C6cZZNbB.cjs} +1 -1
- package/dist/index-BGGNVIKx.cjs +5 -0
- package/dist/{index-EFWvSWoi.cjs → index-CfsIhbT2.cjs} +3 -3
- package/dist/{index-GfOB5KV1.js → index-ckjNCVor.js} +990 -978
- package/dist/{index-lm46VtIP.js → index-iRqgNs2O.js} +14 -10
- package/dist/{json-diff-viewer-D5yJoFh1.js → json-diff-viewer-DAQ-qSHk.js} +2 -2
- package/dist/{json-diff-viewer-BeSMdSd5.cjs → json-diff-viewer-DheqS084.cjs} +1 -1
- package/dist/{lang-panel-7qTejsLm.js → lang-panel-DRDPvY1i.js} +3 -3
- package/dist/{lang-panel-B-QUotOn.cjs → lang-panel-oLc-QyU4.cjs} +1 -1
- package/dist/{manage-design-tokens-TeWNZekH.cjs → manage-design-tokens-Hu25ejcC.cjs} +1 -1
- package/dist/{manage-design-tokens-DeH-yNJN.js → manage-design-tokens-rEzXQJRW.js} +2 -2
- package/dist/{mark-as-template-RkfNETRW.js → mark-as-template-BNbn5zQG.js} +2 -2
- package/dist/{mark-as-template-Co00KkhA.cjs → mark-as-template-DEThYoS6.cjs} +1 -1
- package/dist/{nested-path-selector-content-Dimjyy8J.js → nested-path-selector-content-BERhs6_L.js} +1 -1
- package/dist/{nested-path-selector-content-hBvmT_2A.cjs → nested-path-selector-content-Dz3-bNqT.cjs} +1 -1
- package/dist/{no-language-page-content-Bk3sTsdM.js → no-language-page-content-CPVIz5rC.js} +2 -2
- package/dist/{no-language-page-content-CLovr1bL.cjs → no-language-page-content-CrUkIrUJ.cjs} +1 -1
- package/dist/{no-language-page-dialog-C21Fq-UD.cjs → no-language-page-dialog-964r8feg.cjs} +1 -1
- package/dist/{no-language-page-dialog-Cx-YOrAd.js → no-language-page-dialog-DPDJ6gkQ.js} +2 -2
- package/dist/{page-creator-BBuYY84G.js → page-creator-CDcfL4al.js} +3 -3
- package/dist/{page-creator-BDmospqO.cjs → page-creator-kvymje2i.cjs} +1 -1
- package/dist/{page-lock-BrGWj326.js → page-lock-BpUGSiCT.js} +2 -2
- package/dist/{page-lock-DG5IvZaG.cjs → page-lock-gOE-Tt7g.cjs} +1 -1
- package/dist/{page-locked-dialog-DUktYJzU.js → page-locked-dialog-UQeYxWz1.js} +2 -2
- package/dist/{page-locked-dialog-DKnQpIMB.cjs → page-locked-dialog-aJFtoEzq.cjs} +1 -1
- package/dist/{page-manager-new-iYsDkUzG.cjs → page-manager-new-DBomYOFT.cjs} +1 -1
- package/dist/{page-manager-new-BfKYDWs7.js → page-manager-new-Dg02OZtc.js} +22 -22
- package/dist/{page-manager-search-and-filter-DVAGxnlw.js → page-manager-search-and-filter-CCTh5gkC.js} +2 -2
- package/dist/{page-manager-search-and-filter-CIspvIW2.cjs → page-manager-search-and-filter-pWHXOgMJ.cjs} +1 -1
- package/dist/{page-revisions-content-B84UtAxm.cjs → page-revisions-content-BDY8RXJW.cjs} +1 -1
- package/dist/{page-revisions-content-DB4mj_Cw.js → page-revisions-content-C6YjUAx9.js} +7 -7
- package/dist/pages.cjs +1 -1
- package/dist/pages.js +12 -12
- package/dist/{plugin-DVNaUexn.js → plugin-DH3BDqys.js} +7 -7
- package/dist/{plugin-BfC_qpW2.cjs → plugin-DO5QAuc1.cjs} +7 -7
- package/dist/{publish-pages-content-BRKsIr9W.js → publish-pages-content-8MQN9iLc.js} +17 -17
- package/dist/{publish-pages-content-ysv37LxZ.cjs → publish-pages-content-DjUd9oWi.cjs} +1 -1
- package/dist/render.cjs +1 -1
- package/dist/render.js +2 -2
- package/dist/{rte-widget-modal-Dj5BvA-1.js → rte-widget-modal-Bj7lxFEs.js} +1 -1
- package/dist/{rte-widget-modal-BS040t_9.cjs → rte-widget-modal-O31cHitM.cjs} +1 -1
- package/dist/{save-to-lib-D3kp0ovZ.js → save-to-lib-BMlowHNl.js} +2 -2
- package/dist/{save-to-lib-ClCCNy6W.cjs → save-to-lib-vxpiXsok.cjs} +1 -1
- package/dist/sdk.css +1 -1
- package/dist/{selected-block-display-BvRoOMt9.cjs → selected-block-display-BjhZTfSL.cjs} +1 -1
- package/dist/{selected-block-display-BtlTAkei.js → selected-block-display-BxHTDLna.js} +2 -2
- package/dist/{seo-panel-C_Cnwj1-.js → seo-panel-197ULlty.js} +2 -2
- package/dist/{seo-panel-CHGdB8_7.cjs → seo-panel-MrGhioya.cjs} +1 -1
- package/dist/{shared-json-ld-DA0wz-k3.cjs → shared-json-ld-6ovlKZ7L.cjs} +1 -1
- package/dist/{shared-json-ld-DPr0Douk.js → shared-json-ld-B2kfIim8.js} +24 -24
- package/dist/{slug-input-CqhlfgAe.js → slug-input-CSqTWSv8.js} +1 -1
- package/dist/{slug-input-DltqfQ3y.cjs → slug-input-CV-Dvosn.cjs} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.d.ts +34 -0
- package/dist/supabase-actions.js +231 -192
- package/dist/{take-over-request-Bq7OF5Gp.cjs → take-over-request-BFZbLBOK.cjs} +1 -1
- package/dist/{take-over-request-ByUlm_HK.js → take-over-request-Ds_-1dOv.js} +2 -2
- package/dist/{theme-panel-footer-DG7Z5YjD.js → theme-panel-footer-C1f2KMBq.js} +2 -2
- package/dist/{theme-panel-footer-XYoM6sn5.cjs → theme-panel-footer-dHh8VGgj.cjs} +1 -1
- package/dist/{translation-warning-modal-DaBUipEY.js → translation-warning-modal-DPdVK3CD.js} +1 -1
- package/dist/{translation-warning-modal-DTxxfo0H.cjs → translation-warning-modal-HD8Mlj1e.cjs} +1 -1
- package/dist/{unmark-as-template-C9EXTj0X.cjs → unmark-as-template-D8wEsu9z.cjs} +1 -1
- package/dist/{unmark-as-template-BOFHOO0_.js → unmark-as-template-DLVNotM_.js} +2 -2
- package/dist/{unpublish-page-B5rev9W3.cjs → unpublish-page-Cl2R_dfN.cjs} +1 -1
- package/dist/{unpublish-page-KDM7kEEV.js → unpublish-page-ik9a66Rz.js} +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +23 -22
- package/dist/{web-preview-CvpevNzM.cjs → web-preview-CE39XTw0.cjs} +1 -1
- package/dist/{web-preview-BDgUTTr8.js → web-preview-ztlGD_Xm.js} +1 -1
- package/package.json +1 -1
- package/dist/index-B5qvHqN5.cjs +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DWTuRU53.cjs"),f=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DWTuRU53.cjs"),f=require("./index-CfsIhbT2.cjs"),r=require("./index-BGGNVIKx.cjs"),U=require("./page-manager-search-and-filter-pWHXOgMJ.cjs"),F=require("@tanstack/react-query"),t=require("lodash-es"),b=require("lucide-react"),a=require("react"),M=()=>{const l=r.useApiUrl(),d=r.useFetch();return F.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>d(l,{action:r.ACTIONS.GET_CHANGES})})},G=({page:l,selectedPages:d,handleCheckboxChange:N,getPageType:y,hasSlug:h,currentOwnerId:c})=>{const x=r.useUserId(),{data:u}=r.useChaiUserInfo(c),o=c===x?null:u==null?void 0:u.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${o?"opacity-50":""}`,children:[o?e.jsx(b.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(d,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),N(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",h(l.pageType)?e.jsx(b.File,{className:"h-4 w-4"}):e.jsx(b.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:y(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:o&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(b.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:o})," is editing this page"]})})]},l==null?void 0:l.id)},O=({onClose:l=()=>{},isPending:d,publishPage:N})=>{const y=r.useUserId(),{pageToUser:h}=r.usePageToUser(),[c,x]=a.useState([]),u=r.useFallbackLang(),[o,p]=a.useState(u),{data:T,isFetching:C}=M(),{data:m}=r.usePageTypes(),k=a.useCallback(s=>{var n;return(n=t.find(m,{key:s}))==null?void 0:n.hasSlug},[m]),j=a.useMemo(()=>t.filter(m,s=>!k(s.key)).map(s=>s.key),[k,m]),P=t.uniq(t.map(T,"lang")).filter(Boolean),i=a.useMemo(()=>t.filter(T,s=>s.pageType==="theme"?!1:o===u?s.lang===o||s.lang==="":s.lang===o),[T,o,u]),w=a.useMemo(()=>t.filter(i,s=>!j.includes(s.pageType)),[i,j]),S=a.useMemo(()=>t.filter(i,s=>j.includes(s.pageType)),[i,j]);a.useEffect(()=>{const s=t.map(t.filter(i,{online:!0}),"id");a.startTransition(()=>x(s))},[i]),a.useEffect(()=>{const s=t.filter(t.keys(h),n=>t.get(h,[n,"userId"])!==y);a.startTransition(()=>x(n=>t.filter(n,g=>!t.includes(s,g))))},[h,y]);const v=c.length===(i==null?void 0:i.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,g=>g!==s):t.concat(n,s))},B=()=>{x(v?[]:t.map(i,"id"))},I=()=>{N({ids:t.uniq(c)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(u)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(m,{key:s});return n?n==null?void 0:n.name:s},L=a.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(g=>g.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(f.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(f.DialogHeader,{children:[e.jsx(f.DialogTitle,{children:"Publish changes"}),e.jsx(f.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(U.LanguageSelector,{languages:[u,...P],selectedLanguage:o,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:C?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:v,onClick:s=>{s.stopPropagation(),B()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(L,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(G,{page:s,selectedPages:c,handleCheckboxChange:E,getPageType:A,hasSlug:k,currentOwnerId:t.get(h,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(f.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[c.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[c.length," Page",c.length!==1?"s":""," Selected"]}),e.jsx(q.Button,{disabled:d,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(q.Button,{disabled:d||C||t.isEmpty(c),onClick:I,children:d?"Publishing...":"Publish Selected"})]})]})};exports.default=O;
|
package/dist/render.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./plugin-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./plugin-DO5QAuc1.cjs"),d=require("./apply-binding-nqrhHgIz.cjs"),m=require("react/jsx-runtime"),t=require("lodash-es"),g=require("react"),b=require("./core-BWQrViOY.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),j=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/container-queries"),K=require("@tailwindcss/forms"),M=require("@tailwindcss/typography"),x=require("./get-chai-builder-theme-CMypjJk8.cjs");async function O(e){const a={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},n=await e.dataProvider(a);return t.has(n,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,n.$metadata),e.children({...t.omit(n,"$metadata")})}const N=()=>m.jsx("div",{}),H=e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f}=e,p=b.getRegisteredChaiBlock(a._type),u=t.get(p,"component",null),k=t.get(e.repeaterData,"index",-1),_=t.get(e.repeaterData,"dataKey",""),P=n===s?"":n??"",y=d.applyBindingToBlockProps(d.applyLanguage(a,P,p),l??{},{index:k,key:_}),h=d.getBlockTagAttributes(a,!1),T=D(o,a._id,d.getBlockRuntimeProps(a._type)),I=t.has(p,"dataProvider")&&t.isFunction(p.dataProvider),v={...y,...h,...T},B={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...v},C=t.get(v,"_show",!0);if(t.isNull(u)||!C)return null;if(I){const $=t.get(p,"suspenseFallback",N);return m.jsx(g.Suspense,{fallback:g.createElement($),children:m.jsx(O,{lang:n??"",pageProps:c,block:v,dataProvider:p.dataProvider,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:S=>g.createElement(u,{...B,...S,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})})}return m.jsx(g.Suspense,{children:g.createElement(u,{...B,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})},E=e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link"||i==="Span")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,(r,c)=>r?g.createElement(H,{...e,key:r._id?`${r._id}-${c}`:`block-${c}`,block:r},({_id:f,_type:p,repeaterItems:u,$repeaterItemsKey:k})=>p==="Repeater"?t.isArray(u)&&u.map((_,P)=>g.createElement(E,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${c}-${P}`,repeaterData:{index:P,dataKey:k}})):o(f)?g.createElement(E,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${c}`,repeaterData:s,type:r._type}):null):null)},D=(e,a,n)=>t.isEmpty(n)?{}:Object.entries(n).reduce((s,[i,l])=>{const o=[];let r=t.find(e,{_id:a});for(;r;)o.push(r),r=t.find(e,{_id:r._parent});const c=t.find(o,{_type:l.block});return c&&(s[i]=t.get(c,t.get(l,"prop"),null)),s},{});function J(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;return m.jsx(E,{...e,lang:a,fallbackLang:n})}async function V(e){const a=await e.dataProvider;return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const W=()=>m.jsx("div",{}),U=async e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f,dataProviders:p}=e,u=b.getRegisteredChaiBlock(a._type),k=t.get(u,"component",null),_=t.get(e.repeaterData,"index",-1),P=t.get(e.repeaterData,"dataKey",""),y=n===s?"":n??"en",h=d.applyBindingToBlockProps(d.applyLanguage(a,y,u),l??{},{index:_,key:P}),T=d.getBlockTagAttributes(a,!1),I=D(o,a._id,d.getBlockRuntimeProps(a._type)),v=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...h,...T,...I},C={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...B},$=t.get(B,"_show",!0);if(t.isNull(k)||!$)return null;if(v){const S=t.get(p,a._id,Promise.resolve({})),R=t.get(u,"suspenseFallback",W);return m.jsx(g.Suspense,{fallback:g.createElement(R),children:m.jsx(V,{lang:n??"",pageProps:c,block:B,dataProvider:S,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:A=>g.createElement(k,{...C,...A,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})})})}return g.createElement(k,{...C,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})},w=async e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,r=>r?g.createElement(U,{...e,dataProviders:e.dataProviders,key:r._id,block:r},({_id:c,_type:f,repeaterItems:p,$repeaterItemsKey:u})=>f==="Repeater"?t.isArray(p)&&p.map((k,_)=>g.createElement(w,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${_}`,repeaterData:{index:_,dataKey:u}})):o(c)?g.createElement(w,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)};async function G(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;if(e.dataProviders)return m.jsx(w,{...e,lang:a,fallbackLang:n,dataProviders:e.dataProviders});const i=e.blocks.filter(l=>{const o=b.getRegisteredChaiBlock(l._type);return!!(t.has(o,"dataProvider")&&t.isFunction(o.dataProvider))}).reduce((l,o)=>{const r=b.getRegisteredChaiBlock(o._type);if(!r||!r.dataProvider)return l;const c={pageProps:e.pageProps,block:o,lang:e.lang,draft:e.draft,inBuilder:!1};return l[o._id]=Promise.resolve(r.dataProvider(c)),l},{});return m.jsx(w,{...e,lang:a,fallbackLang:n,dataProviders:i})}function Q(e,a){const n=e.filter(s=>s._type==="GlobalBlock"||s._type==="PartialBlock");for(let s=0;s<n.length;s++){const i=n[s],l=t.get(i,"partialBlockId",t.get(i,"globalBlock",""));if(l==="")continue;let o=t.cloneDeep(t.get(a,l,[]));i._parent&&(o==null?void 0:o.length)>0&&(o=o.map(c=>(t.isEmpty(c._parent)&&(c._parent=i._parent),c)));const r=e.indexOf(i);e.splice(r,1,...o)}return e}const z=e=>{if(!e)return[];try{return JSON.parse(X(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function X(e){const a=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(a,n=>{const s=decodeURIComponent(n),i=s.indexOf("public");return i!==-1?s.substring(i+6):s})}async function Y(e,a=[],n=!1){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:{...x.getChaiBuilderTheme(),keyframes:{"accordion-down":{from:{height:"0"},to:{height:"var(--radix-accordion-content-height)"}},"accordion-up":{from:{height:"var(--radix-accordion-content-height)"},to:{height:"0"}}},animation:{"accordion-down":"accordion-down 0.2s ease-out","accordion-up":"accordion-up 0.2s ease-out"}}},plugins:[K,M,j,q,x.chaiBuilderPlugin],corePlugins:{preflight:n}}}).generateStylesFromContent(` ${n?"@tailwind base;":""}
|
|
2
2
|
@tailwind components;
|
|
3
3
|
@tailwind utilities;`,e)}const Z=(e,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,i)=>`#styles:${i.replace(/^,/g," ")}`.replace(/#styles:/g,""));return Y([n],[],a)},ee=async(e,a=!1)=>await Z(e,a);exports.getChaiThemeCssVariables=L.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=L.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=L.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=d.applyChaiDataBinding;exports.applyDesignTokens=d.applyDesignTokens;exports.convertHTMLToChaiBlocks=d.getBlocksFromHTML;exports.AsyncRenderChaiBlocks=G;exports.RenderChaiBlocks=J;exports.convertToBlocks=z;exports.getMergedPartialBlocks=Q;exports.getStylesForBlocks=ee;
|
package/dist/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as De, b as xe, c as Ke } from "./plugin-
|
|
1
|
+
import { a as De, b as xe, c as Ke } from "./plugin-DH3BDqys.js";
|
|
2
2
|
import { a as O, b as N, c as E, d as J, e as C, f as j } from "./apply-binding-Bk2y-y_A.js";
|
|
3
3
|
import { h as Ae, i as Fe, g as Me } from "./apply-binding-Bk2y-y_A.js";
|
|
4
4
|
import { jsx as m } from "react/jsx-runtime";
|
|
@@ -10,7 +10,7 @@ import Y from "@tailwindcss/aspect-ratio";
|
|
|
10
10
|
import Z from "@tailwindcss/container-queries";
|
|
11
11
|
import ee from "@tailwindcss/forms";
|
|
12
12
|
import te from "@tailwindcss/typography";
|
|
13
|
-
import { c as ae, g as re } from "./get-chai-builder-theme-
|
|
13
|
+
import { c as ae, g as re } from "./get-chai-builder-theme-CHXhAcdV.js";
|
|
14
14
|
async function ne(e) {
|
|
15
15
|
const t = {
|
|
16
16
|
pageProps: e.pageProps,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as l } from "react/jsx-runtime";
|
|
2
|
-
import { h as D, D as N, e as S, f as j, g as v, N as w } from "./index-
|
|
2
|
+
import { h as D, D as N, e as S, f as j, g as v, N as w } from "./index-iRqgNs2O.js";
|
|
3
3
|
import { B } from "./register-chai-top-bar-CX_JkRJn.js";
|
|
4
4
|
const M = ({
|
|
5
5
|
isOpen: f,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-CfsIhbT2.cjs"),p=require("./register-chai-top-bar-DWTuRU53.cjs"),S=({isOpen:m,onClose:r,editor:t,rteElement:f})=>{const a=s.usePageExternalData(),u=o=>{if(!t)return;const i=`{{${o}}}`;t.commands.focus();const{from:j,to:g}=t.state.selection;if(j!==g)t.chain().deleteSelection().insertContent(i).run();else{const{state:c}=t,n=c.selection.from,x=c.doc.textBetween(Math.max(0,n-1),n),l=c.doc.textBetween(n,Math.min(n+1,c.doc.content.size));let d="";n>0&&x!==" "&&!/[.,!?;:]/.test(x)&&(d=" ");let h="";l&&l!==" "&&!/[.,!?;:]/.test(l)&&(h=" "),t.chain().insertContent(d+i+h).run()}};return e.jsx(s.Dialog,{open:m,onOpenChange:o=>!o&&r(),children:e.jsxs(s.DialogContent,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[800px]",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center justify-between pr-8",children:[e.jsx("span",{children:"Rich Text Editor"}),a&&Object.keys(a).length>0&&e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"mr-2 text-sm text-muted-foreground",children:"Add field:"}),e.jsx("div",{className:"rte-path-selector",children:e.jsx(s.NestedPathSelector,{data:a,onSelect:u})})]})]})}),f,e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(p.Button,{onClick:r,children:"Done"})})]})})};exports.default=S;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
2
|
import { B as b, z as L } from "./register-chai-top-bar-CX_JkRJn.js";
|
|
3
|
-
import { az as ne, c as M, a7 as ie, a8 as oe, P as le, aA as ce, ai as de, aB as ue, q as P } from "./index-
|
|
4
|
-
import { ar as D, as as G, A as _, ay as me } from "./index-
|
|
3
|
+
import { az as ne, c as M, a7 as ie, a8 as oe, P as le, aA as ce, ai as de, aB as ue, q as P } from "./index-iRqgNs2O.js";
|
|
4
|
+
import { ar as D, as as G, A as _, ay as me } from "./index-ckjNCVor.js";
|
|
5
5
|
import { useQuery as K, useMutation as A, useQueryClient as pe } from "@tanstack/react-query";
|
|
6
6
|
import { useSetAtom as fe } from "jotai";
|
|
7
7
|
import { toast as N } from "sonner";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DWTuRU53.cjs"),x=require("./index-EFWvSWoi.cjs"),b=require("./index-B5qvHqN5.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),Z=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:b.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},ee=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useQuery({staleTime:"static",queryKey:[b.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:b.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},te=s=>{const r=b.useApiUrl(),l=b.useFetch(),t=X.useSetAtom(x.libraryBlocksAtom);return C.useMutation({mutationFn:async c=>l(r,{action:b.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:c}}),onSuccess:()=>{t(c=>{const m={...c};return Object.keys(m).forEach(u=>{m[u]={loading:"idle",blocks:[],error:!1}}),m}),s?s():j.toast.success("Block deleted successfully")},onError:c=>{console.error("Error deleting block:",c),j.toast.error("Failed to delete block",{description:c instanceof Error?c.message:"Unknown error"})}})},se=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:c,trigger:m})=>{const[u,o]=i.useState(!1),d=x.useUpdateBlocksPropsRealtime(),y=te(()=>{d([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),h=()=>{o(!0),y.mutate(r)},g=e.jsxs(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:f=>f.preventDefault(),disabled:u,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(x.Popover,{open:l,onOpenChange:f=>!f&&t(),children:[e.jsx(x.PopoverTrigger,{asChild:!0,children:m||g}),e.jsx(x.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',c,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:h,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},re=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:c="",close:m})=>{const[u,o]=i.useState(!1);return e.jsx(se,{blockId:s,libBlockId:r,isOpen:u,onClose:()=>{o(!1),m()},blockName:l,trigger:e.jsxs(p.Button,{type:"button",variant:"destructive",size:t,className:c,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},ne=()=>{const s=b.useApiUrl(),r=b.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:c,error:m}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=C.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),j.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:c,error:m,createGroup:u,isCreating:o}},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[c,m]=i.useState(""),u=i.useRef(null),{groups:o}=ne(),[d,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),h=i.useMemo(()=>[...o,...d.filter(n=>!o.some(B=>B.id===n.id))],[o,d]),g=()=>{const n=c.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),m(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const f=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!h.some(n=>n.id===s)&&r("")},[s,h,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(p.Input,{ref:u,placeholder:"Enter new group name",value:c,onChange:n=>m(n.target.value),onKeyDown:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(p.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(p.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},oe=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),c=i.useRef(null),m=i.useCallback(async d=>{var h;const y=(h=d.target.files)==null?void 0:h[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await J.compressImageIfNeeded(y));const f=new FileReader;f.onloadend=()=>{r(f.result),t(!1)},f.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),u=()=>{r(""),c.current&&(c.current.value="")},o=()=>{var d;(d=c.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.Input,{type:"file",ref:c,onChange:m,accept:"image/*",className:"hidden"}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(p.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},ie=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartailBlocks:c}=x.usePartialBlocksStore(),m=r.find(a=>a._id===t),u=m==null?void 0:m._libBlockId,o=!!u,d=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const k of r)if(k._type==="PartialBlock"||k._type==="GlobalBlock"){let v=c(k.partialBlockId);k._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",k._parent),T))),a=[...a,...v]}else a.push(k);return a},[r,c]),[h,g]=i.useState(""),[f,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,U]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=x.usePermissions(),Q=Y(b.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=x.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=ee(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=h.trim().length>=2,k=f.trim()!=="";M(a&&k)},[h,f]);const W=()=>{const a={};return h.trim()?h.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",f||(a.group="Group is required"),U(a),Object.keys(a).length===0},{resetLibrary:$}=x.useLibraryBlocks({id:""}),A=Z(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const k=y.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));A.mutate({name:h.trim(),group:f,blocks:k,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=A.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(p.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(p.Input,{id:"name",placeholder:"Enter block name",value:h,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ae,{value:f,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(p.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(oe,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(re,{blockId:t,libBlockId:u,blockName:h,className:"mr-auto",close:l}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(p.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=ie;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DWTuRU53.cjs"),x=require("./index-CfsIhbT2.cjs"),b=require("./index-BGGNVIKx.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),Z=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:b.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},ee=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useQuery({staleTime:"static",queryKey:[b.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:b.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},te=s=>{const r=b.useApiUrl(),l=b.useFetch(),t=X.useSetAtom(x.libraryBlocksAtom);return C.useMutation({mutationFn:async c=>l(r,{action:b.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:c}}),onSuccess:()=>{t(c=>{const m={...c};return Object.keys(m).forEach(u=>{m[u]={loading:"idle",blocks:[],error:!1}}),m}),s?s():j.toast.success("Block deleted successfully")},onError:c=>{console.error("Error deleting block:",c),j.toast.error("Failed to delete block",{description:c instanceof Error?c.message:"Unknown error"})}})},se=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:c,trigger:m})=>{const[u,o]=i.useState(!1),d=x.useUpdateBlocksPropsRealtime(),y=te(()=>{d([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),h=()=>{o(!0),y.mutate(r)},g=e.jsxs(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:f=>f.preventDefault(),disabled:u,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(x.Popover,{open:l,onOpenChange:f=>!f&&t(),children:[e.jsx(x.PopoverTrigger,{asChild:!0,children:m||g}),e.jsx(x.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',c,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:h,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},re=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:c="",close:m})=>{const[u,o]=i.useState(!1);return e.jsx(se,{blockId:s,libBlockId:r,isOpen:u,onClose:()=>{o(!1),m()},blockName:l,trigger:e.jsxs(p.Button,{type:"button",variant:"destructive",size:t,className:c,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},ne=()=>{const s=b.useApiUrl(),r=b.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:c,error:m}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=C.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),j.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:c,error:m,createGroup:u,isCreating:o}},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[c,m]=i.useState(""),u=i.useRef(null),{groups:o}=ne(),[d,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),h=i.useMemo(()=>[...o,...d.filter(n=>!o.some(B=>B.id===n.id))],[o,d]),g=()=>{const n=c.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),m(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const f=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!h.some(n=>n.id===s)&&r("")},[s,h,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(p.Input,{ref:u,placeholder:"Enter new group name",value:c,onChange:n=>m(n.target.value),onKeyDown:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(p.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(p.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},oe=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),c=i.useRef(null),m=i.useCallback(async d=>{var h;const y=(h=d.target.files)==null?void 0:h[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await J.compressImageIfNeeded(y));const f=new FileReader;f.onloadend=()=>{r(f.result),t(!1)},f.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),u=()=>{r(""),c.current&&(c.current.value="")},o=()=>{var d;(d=c.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.Input,{type:"file",ref:c,onChange:m,accept:"image/*",className:"hidden"}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(p.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},ie=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartailBlocks:c}=x.usePartialBlocksStore(),m=r.find(a=>a._id===t),u=m==null?void 0:m._libBlockId,o=!!u,d=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const k of r)if(k._type==="PartialBlock"||k._type==="GlobalBlock"){let v=c(k.partialBlockId);k._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",k._parent),T))),a=[...a,...v]}else a.push(k);return a},[r,c]),[h,g]=i.useState(""),[f,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,U]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=x.usePermissions(),Q=Y(b.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=x.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=ee(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=h.trim().length>=2,k=f.trim()!=="";M(a&&k)},[h,f]);const W=()=>{const a={};return h.trim()?h.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",f||(a.group="Group is required"),U(a),Object.keys(a).length===0},{resetLibrary:$}=x.useLibraryBlocks({id:""}),A=Z(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const k=y.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));A.mutate({name:h.trim(),group:f,blocks:k,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=A.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(p.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(p.Input,{id:"name",placeholder:"Enter block name",value:h,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ae,{value:f,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(p.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(oe,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(re,{blockId:t,libBlockId:u,blockName:h,className:"mr-auto",close:l}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(p.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=ie;
|