@chaibuilder/sdk 4.0.0-beta.31 → 4.0.0-beta.33

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.
Files changed (152) hide show
  1. package/dist/{2SSKDMRQ-gmj-yWTy.js → 2SSKDMRQ-BXAXoR9y.js} +5 -5
  2. package/dist/{2SSKDMRQ-BksFOLpD.cjs → 2SSKDMRQ-BqOsh3tf.cjs} +1 -1
  3. package/dist/{AP7HFJJL-kVgc0R61.js → AP7HFJJL-B78LfetW.js} +1 -1
  4. package/dist/{AP7HFJJL-CO-deD_p.cjs → AP7HFJJL-Cv6sqAAd.cjs} +1 -1
  5. package/dist/{IconPicker-D_GRfhwS.js → IconPicker-BlO5Pnyu.js} +1 -1
  6. package/dist/{IconPicker-BJHUCDn4.cjs → IconPicker-D4yq_b-k.cjs} +1 -1
  7. package/dist/{WDYDFRGG-C9_E3QW0.js → WDYDFRGG-BE7jgVqa.js} +4 -4
  8. package/dist/{WDYDFRGG-KPpWFul_.cjs → WDYDFRGG-Dz9d3cVW.cjs} +1 -1
  9. package/dist/{actions-registery-Bj-j1k5i.js → actions-registery-D3-4Yha7.js} +1108 -1061
  10. package/dist/{actions-registery-Cy1lqUVI.cjs → actions-registery-vPaY-3dZ.cjs} +25 -25
  11. package/dist/actions.cjs +1 -1
  12. package/dist/actions.js +2 -2
  13. package/dist/{active-in-another-tab-1GoKTVcF.js → active-in-another-tab-CA47uafJ.js} +2 -2
  14. package/dist/{active-in-another-tab-iEd5fZD0.cjs → active-in-another-tab-CNn_R-55.cjs} +1 -1
  15. package/dist/{add-new-language-page-B3GUvWdP.js → add-new-language-page-B-kPbhFd.js} +3 -3
  16. package/dist/{add-new-language-page-Cq8R42Ro.cjs → add-new-language-page-QAZbAFQe.cjs} +1 -1
  17. package/dist/{add-new-page-DiHnECAR.cjs → add-new-page-D4nbAHOp.cjs} +1 -1
  18. package/dist/add-new-page-Y0d9tHh0.js +31 -0
  19. package/dist/{ai-panel-content-BPpawv4D.cjs → ai-panel-content-DXbebC-m.cjs} +1 -1
  20. package/dist/{ai-panel-content-tExD3yhH.js → ai-panel-content-WMOeK5pF.js} +5 -5
  21. package/dist/{ai-panel-default-lang-DnYLHSaS.js → ai-panel-default-lang-CM_psX_h.js} +7 -7
  22. package/dist/{ai-panel-default-lang-C6N4wUUF.cjs → ai-panel-default-lang-hmfyAYPM.cjs} +2 -2
  23. package/dist/{ai-panel-other-lang-D1pCJluY.js → ai-panel-other-lang-BKANRJAb.js} +13 -13
  24. package/dist/{ai-panel-other-lang-C65lVVtZ.cjs → ai-panel-other-lang-D4GL1b-W.cjs} +1 -1
  25. package/dist/{ai-prompt-input-Dws5BHhQ.cjs → ai-prompt-input-Dwd0-pcD.cjs} +1 -1
  26. package/dist/{ai-prompt-input-B2q30bhR.js → ai-prompt-input-mxXtWptn.js} +13 -13
  27. package/dist/{ai-translation-prompt-DnwG2BmF.cjs → ai-translation-prompt-7M2aEZ1w.cjs} +1 -1
  28. package/dist/{ai-translation-prompt-Dnn6i_t3.js → ai-translation-prompt-C_Pb7BE4.js} +1 -1
  29. package/dist/{apply-binding-chfbBKi2.js → apply-binding-BYCW1k2l.js} +1 -1
  30. package/dist/{apply-binding-9XSrYzAE.cjs → apply-binding-xiigK7eK.cjs} +1 -1
  31. package/dist/{change-password-modal-LKtYY-8V.cjs → change-password-modal-BYZoefwT.cjs} +1 -1
  32. package/dist/{change-password-modal-C0MMizgl.js → change-password-modal-Dqf_mleR.js} +5 -5
  33. package/dist/{code-editor-CWOmKcUc.js → code-editor-1fSEocLK.js} +1 -1
  34. package/dist/{code-editor-Cim6jQVF.cjs → code-editor-uN7W7KMD.cjs} +1 -1
  35. package/dist/{continue-editing-in-this-client-oxYWGWON.js → continue-editing-in-this-client-DD7bBhjD.js} +2 -2
  36. package/dist/{continue-editing-in-this-client-Dd6nKIvX.cjs → continue-editing-in-this-client-DDM65ror.cjs} +1 -1
  37. package/dist/{core-BWQrViOY.cjs → core-czmLeR0h.cjs} +1 -1
  38. package/dist/{core-QlWEXm1d.js → core-nSRy3D7z.js} +16 -15
  39. package/dist/core.cjs +1 -1
  40. package/dist/core.d.ts +14 -2
  41. package/dist/core.js +19 -19
  42. package/dist/{css-import-modal-CXulmaB4.cjs → css-import-modal-BU7bJAaT.cjs} +1 -1
  43. package/dist/{css-import-modal-6bMTRlCg.js → css-import-modal-pBNRVmGj.js} +1 -1
  44. package/dist/default-theme-options-DN-3gIjM.cjs +22 -0
  45. package/dist/{plugin-BSjgGgwo.js → default-theme-options-saBIkWGT.js} +114 -114
  46. package/dist/{delete-page-D0tdn6VW.cjs → delete-page-8oEYsHPE.cjs} +1 -1
  47. package/dist/delete-page-B53nkF74.js +71 -0
  48. package/dist/{design-token-usage-D-hrcKz1.cjs → design-token-usage-Cm9m4AMz.cjs} +1 -1
  49. package/dist/{design-token-usage-lf7N_uOk.js → design-token-usage-DzWav2ip.js} +14 -14
  50. package/dist/{digital-asset-manager-DJhRhLGC.js → digital-asset-manager-1yLYGPuf.js} +5 -5
  51. package/dist/digital-asset-manager-BaTvMY8Q.cjs +1 -0
  52. package/dist/{duplicate-page-ChSp1TYN.cjs → duplicate-page-C2DZI4U0.cjs} +1 -1
  53. package/dist/{duplicate-page-CXzYy7vx.js → duplicate-page-DCRVR-kF.js} +6 -6
  54. package/dist/{dynamic-page-selector-btGtkyyv.cjs → dynamic-page-selector-CZJQnc-Q.cjs} +1 -1
  55. package/dist/{dynamic-page-selector-r5IR9_7k.js → dynamic-page-selector-DCGWkLVV.js} +12 -12
  56. package/dist/get-chai-builder-theme-C_qofMh_.cjs +1 -0
  57. package/dist/{get-chai-builder-theme-BpuwSLeS.js → get-chai-builder-theme-CyOkIlte.js} +1 -1
  58. package/dist/{image-compression-DsZ1oqpb.js → image-compression-DPFITwOL.js} +2 -2
  59. package/dist/image-compression-UaU7Bwqe.cjs +1 -0
  60. package/dist/{image-editor-CilPMtAC.js → image-editor-C0EYZJY_.js} +1 -1
  61. package/dist/{image-editor-BdW476J8.cjs → image-editor-DkgZrSGr.cjs} +1 -1
  62. package/dist/{index-DtMksfXx.js → index-BDrc0HJQ.js} +1729 -1680
  63. package/dist/index-BuXfCtgR.cjs +5 -0
  64. package/dist/{index-DsQXiNA_.js → index-C7bidKtE.js} +2786 -2752
  65. package/dist/index-DKjYF53r.cjs +160 -0
  66. package/dist/{json-diff-viewer-BkrnLb3B.cjs → json-diff-viewer-88jEhq8D.cjs} +1 -1
  67. package/dist/{json-diff-viewer-D3N3w3Ax.js → json-diff-viewer-wmzIZcuQ.js} +34 -34
  68. package/dist/{lang-panel-BAaaP4Qc.js → lang-panel--kWBnU_W.js} +7 -7
  69. package/dist/{lang-panel-BjDRrpwN.cjs → lang-panel-I_ABfjOZ.cjs} +1 -1
  70. package/dist/manage-design-tokens-CslCEOXU.cjs +1 -0
  71. package/dist/manage-design-tokens-JdVKj09s.js +445 -0
  72. package/dist/manage-design-tokens-modal-DA15ou0u.cjs +1 -0
  73. package/dist/{manage-design-tokens-modal-9qpcb-EC.js → manage-design-tokens-modal-xKxC72Bc.js} +9 -9
  74. package/dist/{mark-as-template-DNHYNjI9.js → mark-as-template-AbZrkEYl.js} +7 -7
  75. package/dist/{mark-as-template-IYRjta97.cjs → mark-as-template-ClQjC2p2.cjs} +1 -1
  76. package/dist/{nested-path-selector-content-Be-pbnVl.js → nested-path-selector-content-B04k-PPB.js} +1 -1
  77. package/dist/{nested-path-selector-content-CWmPgU-L.cjs → nested-path-selector-content-dFwZaM1r.cjs} +1 -1
  78. package/dist/{no-language-page-content-C-ltY7bj.js → no-language-page-content-CbUqxuC4.js} +2 -2
  79. package/dist/{no-language-page-content-8_J6y-cm.cjs → no-language-page-content-pzkWJAg6.cjs} +1 -1
  80. package/dist/{no-language-page-dialog-D5NXpDHi.js → no-language-page-dialog-AavD_Mmc.js} +2 -2
  81. package/dist/{no-language-page-dialog-BOZZZzqx.cjs → no-language-page-dialog-DhlOVXUm.cjs} +1 -1
  82. package/dist/{page-creator-BuHHnqiQ.js → page-creator-2OZveMsR.js} +95 -95
  83. package/dist/{page-creator-wtbae2U7.cjs → page-creator-DMjnStPf.cjs} +1 -1
  84. package/dist/{page-lock-pPGlTxj7.js → page-lock-5MwwTWe8.js} +2 -2
  85. package/dist/{page-lock-DN4iJc-V.cjs → page-lock-B3CpoFTs.cjs} +1 -1
  86. package/dist/{page-locked-dialog-Bl-ojgIW.js → page-locked-dialog-BhNZC9wZ.js} +13 -13
  87. package/dist/{page-locked-dialog-B_vdgv24.cjs → page-locked-dialog-ZOvjnxRI.cjs} +1 -1
  88. package/dist/page-manager-new-BcI-1Dms.cjs +1 -0
  89. package/dist/{page-manager-new-Bg8H6yrg.js → page-manager-new-l68-Lc9h.js} +85 -88
  90. package/dist/{page-manager-search-and-filter-CDXunXNd.cjs → page-manager-search-and-filter-BOpne6v-.cjs} +1 -1
  91. package/dist/{page-manager-search-and-filter-CyfO7O96.js → page-manager-search-and-filter-DJn98D02.js} +31 -30
  92. package/dist/{page-revisions-content-BKT8S9_g.cjs → page-revisions-content-B00tDCzu.cjs} +1 -1
  93. package/dist/{page-revisions-content-B-egQgoZ.js → page-revisions-content-Bqp-9bae.js} +23 -23
  94. package/dist/pages.cjs +1 -1
  95. package/dist/pages.d.ts +14 -2
  96. package/dist/pages.js +12 -12
  97. package/dist/{publish-pages-content-D2B_ScCQ.js → publish-pages-content-CtZLSG6O.js} +68 -75
  98. package/dist/publish-pages-content-DfYG0biw.cjs +1 -0
  99. package/dist/render.cjs +1 -1
  100. package/dist/render.js +5 -5
  101. package/dist/{rte-widget-modal-c3T09VeO.js → rte-widget-modal-DGEWoQ1b.js} +1 -1
  102. package/dist/{rte-widget-modal-CC1KcrAT.cjs → rte-widget-modal-DX66uSPv.cjs} +1 -1
  103. package/dist/runtime.cjs +6 -6
  104. package/dist/runtime.d.ts +2 -0
  105. package/dist/runtime.js +36 -35
  106. package/dist/{save-to-lib-dT1NDd5w.js → save-to-lib-CCxX5ZmQ.js} +26 -26
  107. package/dist/{save-to-lib-CiM0wiIr.cjs → save-to-lib-DmAjdhzU.cjs} +1 -1
  108. package/dist/sdk.css +1 -1
  109. package/dist/{selected-block-display-BgqcPsXI.cjs → selected-block-display-Csce27bR.cjs} +1 -1
  110. package/dist/{selected-block-display-BQndDPcY.js → selected-block-display-Cv6jBhJD.js} +20 -20
  111. package/dist/{seo-panel-DXZvGYEM.cjs → seo-panel-BZYXeYzE.cjs} +1 -1
  112. package/dist/{seo-panel-Z93Zf_bz.js → seo-panel-Ctstjs-d.js} +25 -25
  113. package/dist/{shared-json-ld-DwvUDGAS.cjs → shared-json-ld-BDWtjHgw.cjs} +1 -1
  114. package/dist/{shared-json-ld-Ct68RlWD.js → shared-json-ld-BNHGmUBd.js} +45 -45
  115. package/dist/{slug-input-CAqkFZBq.js → slug-input-Bui1Qmvh.js} +1 -1
  116. package/dist/{slug-input-Curnt2n3.cjs → slug-input-IAl_jfHr.cjs} +1 -1
  117. package/dist/supabase-actions.cjs +1 -1
  118. package/dist/supabase-actions.js +272 -206
  119. package/dist/{take-over-request-D6y2HcDr.cjs → take-over-request-Bl6jS1cK.cjs} +1 -1
  120. package/dist/{take-over-request-C6ngP1QR.js → take-over-request-Ceuqyk5K.js} +13 -13
  121. package/dist/{translation-warning-modal-B876S5yp.cjs → translation-warning-modal-CCmmwz1C.cjs} +1 -1
  122. package/dist/{translation-warning-modal-kRcfrPgo.js → translation-warning-modal-DA5dt2FA.js} +9 -9
  123. package/dist/types.d.ts +14 -2
  124. package/dist/{unmark-as-template-DeeWUTco.js → unmark-as-template-CKVMibvu.js} +13 -13
  125. package/dist/{unmark-as-template-f1dl_YTz.cjs → unmark-as-template-OEUqo0uc.cjs} +1 -1
  126. package/dist/unpublish-page-A5qn6E6g.js +28 -0
  127. package/dist/{unpublish-page-DEPFjGuu.cjs → unpublish-page-C81bYHLI.cjs} +1 -1
  128. package/dist/{unpublished-partials-modal-Ts5ZhAK9.js → unpublished-partials-modal-FqzTp5el.js} +3 -3
  129. package/dist/{unpublished-partials-modal-CEFXp1D1.cjs → unpublished-partials-modal-af5uDL7Y.cjs} +1 -1
  130. package/dist/utils.cjs +1 -1
  131. package/dist/utils.js +1 -1
  132. package/dist/web-blocks.cjs +1 -1
  133. package/dist/web-blocks.js +1 -1
  134. package/dist/{web-preview-CoT8r96b.js → web-preview-vge6uUSa.js} +1 -1
  135. package/dist/{web-preview-DTDoIE-c.cjs → web-preview-xtKkQOXy.cjs} +1 -1
  136. package/package.json +2 -7
  137. package/dist/add-new-page-C5HlQfzy.js +0 -31
  138. package/dist/delete-page-LnzR01A8.js +0 -71
  139. package/dist/digital-asset-manager-eCJHNSjj.cjs +0 -1
  140. package/dist/get-chai-builder-theme-B5RkBTsB.cjs +0 -1
  141. package/dist/image-compression-DZ9WMmyn.cjs +0 -1
  142. package/dist/index-CAhDwfHE.cjs +0 -5
  143. package/dist/index-mPCp0j2h.cjs +0 -160
  144. package/dist/manage-design-tokens-BknGNAKE.cjs +0 -1
  145. package/dist/manage-design-tokens-Co5677WS.js +0 -428
  146. package/dist/manage-design-tokens-modal-BcgdwEXE.cjs +0 -1
  147. package/dist/page-manager-new-5W5M9_ue.cjs +0 -1
  148. package/dist/plugin-DHpuZZXz.cjs +0 -22
  149. package/dist/publish-pages-content-WJHTVYnx.cjs +0 -1
  150. package/dist/theme-panel-footer-CGZL2F7R.js +0 -26
  151. package/dist/theme-panel-footer-IgGj-_OA.cjs +0 -1
  152. package/dist/unpublish-page-U_79Pwc0.js +0 -28
package/dist/render.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./plugin-DHpuZZXz.cjs"),d=require("./apply-binding-9XSrYzAE.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-B5RkBTsB.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)),$=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($){const w=t.get(p,"suspenseFallback",N);return m.jsx(g.Suspense,{fallback:g.createElement(w),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),$=D(o,a._id,d.getBlockRuntimeProps(a._type)),v=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...h,...T,...$},C={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...B},w=t.get(B,"_show",!0);if(t.isNull(k)||!w)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}:{}})})},I=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(I,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${_}`,repeaterData:{index:_,dataKey:u}})):o(c)?g.createElement(I,{...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(I,{...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(I,{...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;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./default-theme-options-DN-3gIjM.cjs"),d=require("./apply-binding-xiigK7eK.cjs"),m=require("react/jsx-runtime"),t=require("lodash-es"),g=require("react"),b=require("./core-czmLeR0h.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-C_qofMh_.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),I=D(o,a._id,d.getBlockRuntimeProps(a._type)),$=t.has(p,"dataProvider")&&t.isFunction(p.dataProvider),v={...y,...h,...I},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($){const w=t.get(p,"suspenseFallback",N);return m.jsx(g.Suspense,{fallback:g.createElement(w),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}),I=d.getBlockTagAttributes(a,!1),$=D(o,a._id,d.getBlockRuntimeProps(a._type)),v=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...h,...I,...$},C={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...B},w=t.get(B,"_show",!0);if(t.isNull(k)||!w)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}:{}})})},T=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(T,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${_}`,repeaterData:{index:_,dataKey:u}})):o(c)?g.createElement(T,{...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(T,{...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(T,{...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,16 +1,16 @@
1
- import { c as De, e as xe, f as Ke } from "./plugin-BSjgGgwo.js";
2
- import { a as O, b as N, c as E, d as J, e as C, f as j } from "./apply-binding-chfbBKi2.js";
3
- import { h as Ae, i as Fe, g as Me } from "./apply-binding-chfbBKi2.js";
1
+ import { c as De, e as xe, f as Ke } from "./default-theme-options-saBIkWGT.js";
2
+ import { a as O, b as N, c as E, d as J, e as C, f as j } from "./apply-binding-BYCW1k2l.js";
3
+ import { h as Ae, i as Fe, g as Me } from "./apply-binding-BYCW1k2l.js";
4
4
  import { jsx as m } from "react/jsx-runtime";
5
5
  import { has as P, isFunction as I, omit as q, get as d, isNull as H, isArray as B, uniqBy as W, filter as S, isEmpty as h, map as U, find as A, cloneDeep as z } from "lodash-es";
6
6
  import { Suspense as F, createElement as g } from "react";
7
- import { e as L } from "./core-QlWEXm1d.js";
7
+ import { f as L } from "./core-nSRy3D7z.js";
8
8
  import { createTailwindcss as X } from "@mhsdesign/jit-browser-tailwindcss";
9
9
  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-BpuwSLeS.js";
13
+ import { c as ae, g as re } from "./get-chai-builder-theme-CyOkIlte.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-DsQXiNA_.js";
2
+ import { h as D, D as N, e as S, f as j, g as v, N as w } from "./index-C7bidKtE.js";
3
3
  import { B } from "./register-chai-top-bar-D6GjnauV.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-mPCp0j2h.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DKjYF53r.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.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;
package/dist/runtime.cjs CHANGED
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./STRINGS-FNnfjF5H.cjs"),t=require("lodash-es"),i=require("./register-partial-type-ig9fUWIJ.cjs"),s=require("./core-BWQrViOY.cjs"),c=require("./fonts-D5fTqvSS.cjs"),C=e=>{const r=t.filter(t.compact(t.map(e,c.getRegisteredFont)),o=>t.has(o,"src"));return d(r)},d=e=>!e||e.length===0?"":t.uniqBy(e,"family").map(r=>r.src.map(o=>`@font-face {
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./STRINGS-FNnfjF5H.cjs"),t=require("lodash-es"),i=require("./register-partial-type-ig9fUWIJ.cjs"),o=require("./core-czmLeR0h.cjs"),c=require("./fonts-D5fTqvSS.cjs"),C=e=>{const r=t.filter(t.compact(t.map(e,c.getRegisteredFont)),s=>t.has(s,"src"));return d(r)},d=e=>!e||e.length===0?"":t.uniqBy(e,"family").map(r=>r.src.map(s=>`@font-face {
2
2
  font-family: "${r.family}";
3
- src: url("${o.url}") format("${o.format}");
3
+ src: url("${s.url}") format("${s.format}");
4
4
  font-display: swap;
5
5
  font-optical-sizing: auto;
6
- ${o.fontWeight?`font-weight: ${o.fontWeight};`:""}
7
- ${o.fontStyle?`font-style: ${o.fontStyle};`:""}
8
- ${o.fontStretch?`font-stretch: ${o.fontStretch};`:""}
6
+ ${s.fontWeight?`font-weight: ${s.fontWeight};`:""}
7
+ ${s.fontStyle?`font-style: ${s.fontStyle};`:""}
8
+ ${s.fontStretch?`font-stretch: ${s.fontStretch};`:""}
9
9
  }`).join(`
10
10
  `)).join(`
11
- `),P=async(e,r)=>{const o=C([e,r]),n=[];return[e,...e!==r?[r]:[]].forEach(l=>{const a=c.getRegisteredFont(l);a&&t.has(a,"src")&&a.src&&a.src.length>0&&n.push(a.src[0].url)}),{fontStyles:o,preloads:t.uniqBy(n,l=>l)}},B=s.setChaiServerBlockDataProvider,y=e=>(console.warn("registerChaiBlockSchema is deprecated, use registerChaiBlockProps instead"),u(e)),u=e=>{const r=["_type","_id","_parent","_bindings","_name"],o=["$loading","blockProps","inBuilder","lang","draft","pageProps","pageData","children"],n=t.keys(e.properties);if(t.intersection(n,r).length>0)throw new Error(`Reserved props are not allowed: ${t.intersection(n,r).join(", ")}`);if(t.intersection(n,o).length>0)throw new Error(`Runtime props are not allowed in schema: ${t.intersection(n,o).join(", ")}`);const g=t.get(e,"properties",{}),l={};return t.each(g,(a,p)=>{t.isEmpty(a.ui)||(l[p]={...a.ui},delete g[p].ui)}),{schema:t.isEmpty(g)?{}:{...t.omit(e,["ui"])},uiSchema:{...t.get(e,"ui",{}),...l}}},S=e=>{var r;return((r=e.props)==null?void 0:r.schema)||e.schema},m=e=>{var r;return((r=e.props)==null?void 0:r.uiSchema)||e.uiSchema},f=(e="")=>(console.warn("StylesProp is deprecated, use stylesProp instead"),{type:"string",styles:!0,default:`${h.STYLES_KEY},${e}`,ui:{"ui:widget":"hidden"}}),k=(e="")=>({type:"string",styles:!0,default:`${h.STYLES_KEY},${e}`,ui:{"ui:widget":"hidden"}}),T=e=>(console.warn("runtimeProp is deprecated, use builderProp instead"),{runtime:!0,...e}),R=e=>({builderProp:!0,...e}),D=e=>`${h.STYLES_KEY},${e}`;Object.defineProperty(exports,"CHAI_GLOBAL_DATA_PROVIDER",{enumerable:!0,get:()=>i.CHAI_GLOBAL_DATA_PROVIDER});exports.COLLECTIONS=i.COLLECTIONS;exports.PAGE_TYPES=i.PAGE_TYPES;exports.getChaiCollection=i.getChaiCollection;exports.getChaiCollections=i.getChaiCollections;exports.getChaiGlobalData=i.getChaiGlobalData;exports.getChaiPageType=i.getChaiPageType;exports.getChaiPageTypes=i.getChaiPageTypes;exports.registerChaiCollection=i.registerChaiCollection;exports.registerChaiGlobalDataProvider=i.registerChaiGlobalDataProvider;exports.registerChaiPageType=i.registerChaiPageType;exports.registerChaiPartialType=i.registerChaiPartialType;exports.closestBlockProp=s.closestBlockProp;exports.getAIBlockProps=s.getAIBlockProps;exports.getBlockFormSchemas=s.getBlockFormSchemas;exports.getDefaultBlockProps=s.getDefaultBlockProps;exports.getI18nBlockProps=s.getI18nBlockProps;exports.getRegisteredChaiBlock=s.getRegisteredChaiBlock;exports.registerChaiBlock=s.registerChaiBlock;exports.registerChaiServerBlock=s.registerChaiServerBlock;exports.setChaiBlockComponent=s.setChaiBlockComponent;exports.setChaiServerBlockDataProvider=s.setChaiServerBlockDataProvider;exports.syncBlocksWithDefaultProps=s.syncBlocksWithDefaultProps;exports.syncBlocksWithDefaults=s.syncBlocksWithDefaults;exports.useRegisteredChaiBlock=s.useRegisteredChaiBlock;exports.useRegisteredChaiBlocks=s.useRegisteredChaiBlocks;exports.getAllRegisteredFonts=c.getAllRegisteredFonts;exports.getRegisteredFont=c.getRegisteredFont;exports.registerChaiFont=c.registerChaiFont;exports.useRegisteredFonts=c.useRegisteredFonts;exports.StylesProp=f;exports.builderProp=R;exports.defaultChaiStyles=D;exports.getBlockSchema=S;exports.getBlockUiSchema=m;exports.getFontStyles=P;exports.registerChaiBlockProps=u;exports.registerChaiBlockSchema=y;exports.runtimeProp=T;exports.setChaiBlockDataProvider=B;exports.stylesProp=k;
11
+ `),P=async(e,r)=>{const s=C([e,r]),n=[];return[e,...e!==r?[r]:[]].forEach(l=>{const a=c.getRegisteredFont(l);a&&t.has(a,"src")&&a.src&&a.src.length>0&&n.push(a.src[0].url)}),{fontStyles:s,preloads:t.uniqBy(n,l=>l)}},B=o.setChaiServerBlockDataProvider,y=e=>(console.warn("registerChaiBlockSchema is deprecated, use registerChaiBlockProps instead"),u(e)),u=e=>{const r=["_type","_id","_parent","_bindings","_name"],s=["$loading","blockProps","inBuilder","lang","draft","pageProps","pageData","children"],n=t.keys(e.properties);if(t.intersection(n,r).length>0)throw new Error(`Reserved props are not allowed: ${t.intersection(n,r).join(", ")}`);if(t.intersection(n,s).length>0)throw new Error(`Runtime props are not allowed in schema: ${t.intersection(n,s).join(", ")}`);const g=t.get(e,"properties",{}),l={};return t.each(g,(a,p)=>{t.isEmpty(a.ui)||(l[p]={...a.ui},delete g[p].ui)}),{schema:t.isEmpty(g)?{}:{...t.omit(e,["ui"])},uiSchema:{...t.get(e,"ui",{}),...l}}},S=e=>{var r;return((r=e.props)==null?void 0:r.schema)||e.schema},f=e=>{var r;return((r=e.props)==null?void 0:r.uiSchema)||e.uiSchema},m=(e="")=>(console.warn("StylesProp is deprecated, use stylesProp instead"),{type:"string",styles:!0,default:`${h.STYLES_KEY},${e}`,ui:{"ui:widget":"hidden"}}),k=(e="")=>({type:"string",styles:!0,default:`${h.STYLES_KEY},${e}`,ui:{"ui:widget":"hidden"}}),D=e=>(console.warn("runtimeProp is deprecated, use builderProp instead"),{runtime:!0,...e}),T=e=>({builderProp:!0,...e}),R=e=>`${h.STYLES_KEY},${e}`;Object.defineProperty(exports,"CHAI_GLOBAL_DATA_PROVIDER",{enumerable:!0,get:()=>i.CHAI_GLOBAL_DATA_PROVIDER});exports.COLLECTIONS=i.COLLECTIONS;exports.PAGE_TYPES=i.PAGE_TYPES;exports.getChaiCollection=i.getChaiCollection;exports.getChaiCollections=i.getChaiCollections;exports.getChaiGlobalData=i.getChaiGlobalData;exports.getChaiPageType=i.getChaiPageType;exports.getChaiPageTypes=i.getChaiPageTypes;exports.registerChaiCollection=i.registerChaiCollection;exports.registerChaiGlobalDataProvider=i.registerChaiGlobalDataProvider;exports.registerChaiPageType=i.registerChaiPageType;exports.registerChaiPartialType=i.registerChaiPartialType;exports.closestBlockProp=o.closestBlockProp;exports.getAIBlockProps=o.getAIBlockProps;exports.getBlockDefaultProps=o.getBlockDefaultProps;exports.getBlockFormSchemas=o.getBlockFormSchemas;exports.getDefaultBlockProps=o.getDefaultBlockProps;exports.getI18nBlockProps=o.getI18nBlockProps;exports.getRegisteredChaiBlock=o.getRegisteredChaiBlock;exports.registerChaiBlock=o.registerChaiBlock;exports.registerChaiServerBlock=o.registerChaiServerBlock;exports.setChaiBlockComponent=o.setChaiBlockComponent;exports.setChaiServerBlockDataProvider=o.setChaiServerBlockDataProvider;exports.syncBlocksWithDefaultProps=o.syncBlocksWithDefaultProps;exports.syncBlocksWithDefaults=o.syncBlocksWithDefaults;exports.useRegisteredChaiBlock=o.useRegisteredChaiBlock;exports.useRegisteredChaiBlocks=o.useRegisteredChaiBlocks;exports.getAllRegisteredFonts=c.getAllRegisteredFonts;exports.getRegisteredFont=c.getRegisteredFont;exports.registerChaiFont=c.registerChaiFont;exports.useRegisteredFonts=c.useRegisteredFonts;exports.StylesProp=m;exports.builderProp=T;exports.defaultChaiStyles=R;exports.getBlockSchema=S;exports.getBlockUiSchema=f;exports.getFontStyles=P;exports.registerChaiBlockProps=u;exports.registerChaiBlockSchema=y;exports.runtimeProp=D;exports.setChaiBlockDataProvider=B;exports.stylesProp=k;
package/dist/runtime.d.ts CHANGED
@@ -245,6 +245,8 @@ export declare const getAIBlockProps: (type: keyof typeof REGISTERED_CHAI_BLOCKS
245
245
 
246
246
  export declare const getAllRegisteredFonts: () => ChaiFont[];
247
247
 
248
+ export declare const getBlockDefaultProps: (type: keyof typeof REGISTERED_CHAI_BLOCKS) => Record<string, any>;
249
+
248
250
  export declare const getBlockFormSchemas: (type: keyof typeof REGISTERED_CHAI_BLOCKS) => {
249
251
  schema: RJSFSchema;
250
252
  uiSchema: UiSchema;
package/dist/runtime.js CHANGED
@@ -1,44 +1,44 @@
1
1
  import { S as l } from "./STRINGS-BExFecZW.js";
2
- import { has as g, uniqBy as u, filter as d, compact as f, map as C, keys as P, intersection as n, get as p, each as y, isEmpty as h, omit as S } from "lodash-es";
2
+ import { has as g, uniqBy as u, filter as m, compact as d, map as C, keys as P, intersection as n, get as p, each as y, isEmpty as h, omit as B } from "lodash-es";
3
3
  import { b as Y, C as K, P as q, a as z, g as H, d as N, f as U, e as V, r as J, c as M, h as Q, i as X } from "./register-partial-type-BjtdfKHE.js";
4
- import { s as B } from "./core-QlWEXm1d.js";
5
- import { c as ee, g as te, a as re, b as se, d as oe, e as ae, r as ie, f as ne, h as le, i as ce, j as pe, u as he, k as ge } from "./core-QlWEXm1d.js";
6
- import { g as m } from "./fonts-B3UYxuJI.js";
7
- import { a as me, r as de, u as fe } from "./fonts-B3UYxuJI.js";
4
+ import { s as S } from "./core-nSRy3D7z.js";
5
+ import { c as ee, g as te, a as se, b as re, d as oe, e as ae, f as ie, r as ne, h as le, i as ce, j as pe, k as he, u as ge, l as ue } from "./core-nSRy3D7z.js";
6
+ import { g as f } from "./fonts-B3UYxuJI.js";
7
+ import { a as me, r as de, u as Ce } from "./fonts-B3UYxuJI.js";
8
8
  const k = (e) => {
9
- const t = d(f(C(e, m)), (r) => g(r, "src"));
9
+ const t = m(d(C(e, f)), (s) => g(s, "src"));
10
10
  return $(t);
11
11
  }, $ = (e) => !e || e.length === 0 ? "" : u(e, "family").map(
12
12
  (t) => t.src.map(
13
- (r) => `@font-face {
13
+ (s) => `@font-face {
14
14
  font-family: "${t.family}";
15
- src: url("${r.url}") format("${r.format}");
15
+ src: url("${s.url}") format("${s.format}");
16
16
  font-display: swap;
17
17
  font-optical-sizing: auto;
18
- ${r.fontWeight ? `font-weight: ${r.fontWeight};` : ""}
19
- ${r.fontStyle ? `font-style: ${r.fontStyle};` : ""}
20
- ${r.fontStretch ? `font-stretch: ${r.fontStretch};` : ""}
18
+ ${s.fontWeight ? `font-weight: ${s.fontWeight};` : ""}
19
+ ${s.fontStyle ? `font-style: ${s.fontStyle};` : ""}
20
+ ${s.fontStretch ? `font-stretch: ${s.fontStretch};` : ""}
21
21
  }`
22
22
  ).join(`
23
23
  `)
24
24
  ).join(`
25
25
  `), _ = async (e, t) => {
26
- const r = k([e, t]), o = [];
26
+ const s = k([e, t]), o = [];
27
27
  return [e, ...e !== t ? [t] : []].forEach((a) => {
28
- const s = m(a);
29
- s && g(s, "src") && s.src && s.src.length > 0 && o.push(s.src[0].url);
30
- }), { fontStyles: r, preloads: u(o, (a) => a) };
31
- }, v = B, A = (e) => (console.warn("registerChaiBlockSchema is deprecated, use registerChaiBlockProps instead"), w(e)), w = (e) => {
32
- const t = ["_type", "_id", "_parent", "_bindings", "_name"], r = ["$loading", "blockProps", "inBuilder", "lang", "draft", "pageProps", "pageData", "children"], o = P(e.properties);
28
+ const r = f(a);
29
+ r && g(r, "src") && r.src && r.src.length > 0 && o.push(r.src[0].url);
30
+ }), { fontStyles: s, preloads: u(o, (a) => a) };
31
+ }, v = S, A = (e) => (console.warn("registerChaiBlockSchema is deprecated, use registerChaiBlockProps instead"), w(e)), w = (e) => {
32
+ const t = ["_type", "_id", "_parent", "_bindings", "_name"], s = ["$loading", "blockProps", "inBuilder", "lang", "draft", "pageProps", "pageData", "children"], o = P(e.properties);
33
33
  if (n(o, t).length > 0)
34
34
  throw new Error(`Reserved props are not allowed: ${n(o, t).join(", ")}`);
35
- if (n(o, r).length > 0)
36
- throw new Error(`Runtime props are not allowed in schema: ${n(o, r).join(", ")}`);
35
+ if (n(o, s).length > 0)
36
+ throw new Error(`Runtime props are not allowed in schema: ${n(o, s).join(", ")}`);
37
37
  const i = p(e, "properties", {}), a = {};
38
- return y(i, (s, c) => {
39
- h(s.ui) || (a[c] = { ...s.ui }, delete i[c].ui);
38
+ return y(i, (r, c) => {
39
+ h(r.ui) || (a[c] = { ...r.ui }, delete i[c].ui);
40
40
  }), {
41
- schema: h(i) ? {} : { ...S(e, ["ui"]) },
41
+ schema: h(i) ? {} : { ...B(e, ["ui"]) },
42
42
  uiSchema: { ...p(e, "ui", {}), ...a }
43
43
  };
44
44
  }, F = (e) => {
@@ -74,6 +74,7 @@ export {
74
74
  G as defaultChaiStyles,
75
75
  te as getAIBlockProps,
76
76
  me as getAllRegisteredFonts,
77
+ se as getBlockDefaultProps,
77
78
  re as getBlockFormSchemas,
78
79
  F as getBlockSchema,
79
80
  j as getBlockUiSchema,
@@ -82,12 +83,12 @@ export {
82
83
  N as getChaiGlobalData,
83
84
  U as getChaiPageType,
84
85
  V as getChaiPageTypes,
85
- se as getDefaultBlockProps,
86
+ oe as getDefaultBlockProps,
86
87
  _ as getFontStyles,
87
- oe as getI18nBlockProps,
88
- ae as getRegisteredChaiBlock,
89
- m as getRegisteredFont,
90
- ie as registerChaiBlock,
88
+ ae as getI18nBlockProps,
89
+ ie as getRegisteredChaiBlock,
90
+ f as getRegisteredFont,
91
+ ne as registerChaiBlock,
91
92
  w as registerChaiBlockProps,
92
93
  A as registerChaiBlockSchema,
93
94
  J as registerChaiCollection,
@@ -95,15 +96,15 @@ export {
95
96
  M as registerChaiGlobalDataProvider,
96
97
  Q as registerChaiPageType,
97
98
  X as registerChaiPartialType,
98
- ne as registerChaiServerBlock,
99
+ le as registerChaiServerBlock,
99
100
  b as runtimeProp,
100
- le as setChaiBlockComponent,
101
+ ce as setChaiBlockComponent,
101
102
  v as setChaiBlockDataProvider,
102
- B as setChaiServerBlockDataProvider,
103
+ S as setChaiServerBlockDataProvider,
103
104
  L as stylesProp,
104
- ce as syncBlocksWithDefaultProps,
105
- pe as syncBlocksWithDefaults,
106
- he as useRegisteredChaiBlock,
107
- ge as useRegisteredChaiBlocks,
108
- fe as useRegisteredFonts
105
+ pe as syncBlocksWithDefaultProps,
106
+ he as syncBlocksWithDefaults,
107
+ ge as useRegisteredChaiBlock,
108
+ ue as useRegisteredChaiBlocks,
109
+ Ce as useRegisteredFonts
109
110
  };
@@ -1,15 +1,15 @@
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-D6GjnauV.js";
3
- import { aE as ne, c as M, X as ie, Y as oe, P as le, aF as ce, aw as de, aG as ue, q as P } from "./index-DsQXiNA_.js";
4
- import { ar as D, as as G, A as _, ay as me } from "./index-DtMksfXx.js";
3
+ import { aF as ne, c as M, W as ie, X as oe, P as le, aG as ce, ax as de, aH as ue, p as P } from "./index-C7bidKtE.js";
4
+ import { as as D, at as G, A as _, az as me } from "./index-BDrc0HJQ.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";
8
8
  import { Trash2 as Y, Plus as he, ImageIcon as ge, X as be, AlertCircle as ye } from "lucide-react";
9
- import { useState as h, useRef as V, useMemo as S, useEffect as I, useCallback as ke } from "react";
10
- import { c as ve } from "./image-compression-DsZ1oqpb.js";
9
+ import { useState as h, useRef as W, useMemo as S, useEffect as w, useCallback as ke } from "react";
10
+ import { c as ve } from "./image-compression-DPFITwOL.js";
11
11
  import { isEmpty as Ne, set as Be, has as Ce } from "lodash-es";
12
- const we = (r) => {
12
+ const Ie = (r) => {
13
13
  const a = D(), o = G();
14
14
  return A({
15
15
  mutationFn: async (t) => o(a, {
@@ -25,7 +25,7 @@ const we = (r) => {
25
25
  });
26
26
  }
27
27
  });
28
- }, Ie = (r) => {
28
+ }, we = (r) => {
29
29
  const a = D(), o = G();
30
30
  return K({
31
31
  staleTime: "static",
@@ -191,7 +191,7 @@ const we = (r) => {
191
191
  isCreating: c
192
192
  };
193
193
  }, _e = ({ value: r, onChange: a }) => {
194
- const [o, t] = h(!1), [l, m] = h(""), u = V(null), { groups: c } = Le(), [d, y] = h([
194
+ const [o, t] = h(!1), [l, m] = h(""), u = W(null), { groups: c } = Le(), [d, y] = h([
195
195
  { id: "hero", name: "Hero" },
196
196
  { id: "feature", name: "Feature" },
197
197
  { id: "footer", name: "Footer" },
@@ -231,13 +231,13 @@ const we = (r) => {
231
231
  const B = { id: s, name: s };
232
232
  y((E) => [...E, B]), a(B.id), m(""), t(!1);
233
233
  };
234
- I(() => {
234
+ w(() => {
235
235
  o && u.current && u.current.focus();
236
236
  }, [o]);
237
237
  const p = (s) => {
238
238
  s.key === "Enter" && (s.preventDefault(), g());
239
239
  };
240
- return I(() => {
240
+ return w(() => {
241
241
  r && !f.some((s) => s.id === r) && a("");
242
242
  }, [r, f, a]), o ? /* @__PURE__ */ i("div", { className: "space-y-2", children: [
243
243
  /* @__PURE__ */ e(
@@ -271,7 +271,7 @@ const we = (r) => {
271
271
  /* @__PURE__ */ e(b, { type: "button", size: "icon", variant: "outline", onClick: () => t(!0), children: /* @__PURE__ */ e(he, { className: "h-4 w-4" }) })
272
272
  ] });
273
273
  }, De = ({ value: r, onChange: a }) => {
274
- const [o, t] = h(!1), l = V(null), m = ke(
274
+ const [o, t] = h(!1), l = W(null), m = ke(
275
275
  async (d) => {
276
276
  var f;
277
277
  const y = (f = d.target.files) == null ? void 0 : f[0];
@@ -321,30 +321,30 @@ const we = (r) => {
321
321
  } else
322
322
  n.push(k);
323
323
  return n;
324
- }, [a, l]), [f, g] = h(""), [p, s] = h(""), [B, E] = h(""), [x, U] = h(""), [C, W] = h({}), [Q, $] = h(!1), [X, q] = h(c), [H, J] = h(!1), { hasPermission: Z } = de(), ee = Z(me.DELETE_LIBRARY_BLOCK), O = M(), te = () => {
325
- O([t], { _libBlockId: void 0 }), N.success("Block delinked from library"), o();
324
+ }, [a, l]), [f, g] = h(""), [p, s] = h(""), [B, E] = h(""), [x, U] = h(""), [C, V] = h({}), [Q, $] = h(!1), [H, q] = h(c), [X, J] = h(!1), { hasPermission: Z } = de(), ee = Z(me.DELETE_LIBRARY_BLOCK), z = M(), te = () => {
325
+ z([t], { _libBlockId: void 0 }), N.success("Block delinked from library"), o();
326
326
  }, {
327
- data: w,
327
+ data: I,
328
328
  isLoading: F,
329
- isError: j
330
- } = Ie(u);
331
- I(() => {
332
- j && c && (J(!0), q(!1));
333
- }, [j, c]), I(() => {
334
- w && !F && (g(w.name || ""), s(w.group || ""), E(w.description || ""), U(w.preview || ""), q(!1));
335
- }, [w, F]), I(() => {
329
+ isError: O
330
+ } = we(u);
331
+ w(() => {
332
+ O && c && (J(!0), q(!1));
333
+ }, [O, c]), w(() => {
334
+ I && !F && (g(I.name || ""), s(I.group || ""), E(I.description || ""), U(I.preview || ""), q(!1));
335
+ }, [I, F]), w(() => {
336
336
  const n = f.trim().length >= 2, k = p.trim() !== "";
337
337
  $(n && k);
338
338
  }, [f, p]);
339
339
  const re = () => {
340
340
  const n = {};
341
- return f.trim() ? f.length < 2 && (n.name = "Name must be at least 2 characters") : n.name = "Name is required", p || (n.group = "Group is required"), W(n), Object.keys(n).length === 0;
342
- }, { resetLibrary: ae } = ue({ id: "" }), z = we((n) => {
343
- c || O([t], { _libBlockId: n.id }), N.success(`Block ${c ? "updated" : "saved"} successfully`), ae(n.library), o();
341
+ return f.trim() ? f.length < 2 && (n.name = "Name must be at least 2 characters") : n.name = "Name is required", p || (n.group = "Group is required"), V(n), Object.keys(n).length === 0;
342
+ }, { resetLibrary: ae } = ue({ id: "" }), j = Ie((n) => {
343
+ c || z([t], { _libBlockId: n.id }), N.success(`Block ${c ? "updated" : "saved"} successfully`), ae(n.library), o();
344
344
  }), se = async (n) => {
345
345
  if (n.preventDefault(), !re()) return;
346
346
  const k = y.map((v) => (Ce(v, "_libBlockId") && delete v._libBlockId, v));
347
- z.mutate({
347
+ j.mutate({
348
348
  name: f.trim(),
349
349
  group: p,
350
350
  blocks: k,
@@ -354,8 +354,8 @@ const we = (r) => {
354
354
  // Include id if in edit mode
355
355
  ...c ? { id: u } : {}
356
356
  });
357
- }, T = z.isPending;
358
- return X || F ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ e("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }) }) : H ? /* @__PURE__ */ i("div", { className: "space-y-4 p-6", children: [
357
+ }, T = j.isPending;
358
+ return H || F ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ e("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }) }) : X ? /* @__PURE__ */ i("div", { className: "space-y-4 p-6", children: [
359
359
  /* @__PURE__ */ e("div", { className: "font-medium text-destructive", children: "Block Not Found" }),
360
360
  /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "This block could not be found on the server. It may have been deleted." }),
361
361
  /* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-4", children: [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),x=require("./index-mPCp0j2h.cjs"),b=require("./index-CAhDwfHE.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,{getPartialBlocks: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-DyW9GPzV.cjs"),x=require("./index-DKjYF53r.cjs"),b=require("./index-BuXfCtgR.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-UaU7Bwqe.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,{getPartialBlocks: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;