@grapesjs/studio-sdk-plugins 1.0.33-rc.1 → 1.0.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 (130) hide show
  1. package/dist/accordionComponent/index.cjs.js +7 -7
  2. package/dist/accordionComponent/index.es.js +161 -156
  3. package/dist/accordionComponent/index.umd.js +9 -9
  4. package/dist/aiChat/chatManager.d.ts +15 -0
  5. package/dist/aiChat/clientTools.d.ts +3 -3
  6. package/dist/aiChat/clientToolsProcessors.d.ts +14 -1
  7. package/dist/aiChat/components/AiChatEmptyState.d.ts +4 -6
  8. package/dist/aiChat/components/AiChatError.d.ts +2 -1
  9. package/dist/aiChat/components/AiChatHeader.d.ts +2 -1
  10. package/dist/aiChat/components/AiChatInput/AssetsSection.d.ts +7 -0
  11. package/dist/aiChat/components/AiChatInput/AttachButton.d.ts +10 -0
  12. package/dist/aiChat/components/AiChatInput/ContextSection.d.ts +5 -0
  13. package/dist/aiChat/components/AiChatInput/DictateButton.d.ts +7 -0
  14. package/dist/aiChat/components/AiChatInput/TextAreaWithAutoResize.d.ts +6 -0
  15. package/dist/aiChat/components/AiChatInput/constants.d.ts +6 -0
  16. package/dist/aiChat/components/AiChatInput/hooks/useSpeechToText.d.ts +15 -0
  17. package/dist/aiChat/components/AiChatInput/index.d.ts +37 -0
  18. package/dist/aiChat/components/AiChatLoadingState.d.ts +2 -1
  19. package/dist/aiChat/components/AiChatMessage.d.ts +21 -9
  20. package/dist/aiChat/components/AiChatMessages.d.ts +5 -7
  21. package/dist/aiChat/components/AiChatMessagesStatus.d.ts +5 -0
  22. package/dist/aiChat/components/AiChatPanel.d.ts +2 -3
  23. package/dist/aiChat/components/AiChatProvider.d.ts +14 -0
  24. package/dist/aiChat/components/MemoizedMarkdown.d.ts +9 -0
  25. package/dist/aiChat/components/index.d.ts +24 -25
  26. package/dist/aiChat/components/utils.d.ts +12 -4
  27. package/dist/aiChat/index.cjs.d.ts +5 -0
  28. package/dist/aiChat/index.cjs.js +453 -0
  29. package/dist/aiChat/index.d.ts +4 -3
  30. package/dist/aiChat/index.es.d.ts +5 -0
  31. package/dist/aiChat/index.es.js +30930 -0
  32. package/dist/aiChat/index.js +453 -0
  33. package/dist/aiChat/index.umd.js +453 -0
  34. package/dist/aiChat/locales/en.d.ts +64 -0
  35. package/dist/aiChat/server/index.cjs.d.ts +4 -0
  36. package/dist/aiChat/server/index.cjs.js +309 -0
  37. package/dist/aiChat/server/index.d.ts +0 -50
  38. package/dist/aiChat/server/index.es.d.ts +4 -0
  39. package/dist/aiChat/server/index.es.js +876 -0
  40. package/dist/aiChat/server/index.js +309 -0
  41. package/dist/aiChat/server/index.umd.js +309 -0
  42. package/dist/aiChat/server/stream.d.ts +0 -6
  43. package/dist/aiChat/server/tools.d.ts +157 -51
  44. package/dist/aiChat/server/types.d.ts +108 -64
  45. package/dist/aiChat/types.d.ts +148 -108
  46. package/dist/aiChat/typesSchema.d.ts +238 -25
  47. package/dist/animationComponent/index.cjs.js +3 -3
  48. package/dist/animationComponent/index.es.js +174 -169
  49. package/dist/animationComponent/index.umd.js +3 -3
  50. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  51. package/dist/canvasAbsoluteMode/index.es.js +161 -156
  52. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  53. package/dist/canvasEmptyState/index.cjs.js +1 -1
  54. package/dist/canvasEmptyState/index.es.js +113 -108
  55. package/dist/canvasEmptyState/index.umd.js +1 -1
  56. package/dist/canvasFullSize/index.cjs.js +9 -9
  57. package/dist/canvasFullSize/index.es.js +137 -132
  58. package/dist/canvasFullSize/index.umd.js +9 -9
  59. package/dist/canvasGridMode/index.cjs.js +4 -4
  60. package/dist/canvasGridMode/index.es.js +168 -163
  61. package/dist/canvasGridMode/index.umd.js +8 -8
  62. package/dist/canvasScreenshot/index.cjs.js +1 -1
  63. package/dist/canvasScreenshot/index.es.js +132 -127
  64. package/dist/canvasScreenshot/index.umd.js +1 -1
  65. package/dist/dataSourceEjs/index.cjs.js +5 -5
  66. package/dist/dataSourceEjs/index.es.js +151 -146
  67. package/dist/dataSourceEjs/index.umd.js +5 -5
  68. package/dist/dataSourceHandlebars/index.cjs.js +4 -4
  69. package/dist/dataSourceHandlebars/index.es.js +91 -86
  70. package/dist/dataSourceHandlebars/index.umd.js +5 -5
  71. package/dist/dialogComponent/index.cjs.js +16 -16
  72. package/dist/dialogComponent/index.es.js +117 -112
  73. package/dist/dialogComponent/index.umd.js +16 -16
  74. package/dist/flexComponent/index.cjs.js +11 -11
  75. package/dist/flexComponent/index.es.js +416 -411
  76. package/dist/flexComponent/index.umd.js +11 -11
  77. package/dist/fsLightboxComponent/index.cjs.js +3 -3
  78. package/dist/fsLightboxComponent/index.es.js +152 -147
  79. package/dist/fsLightboxComponent/index.umd.js +3 -3
  80. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  81. package/dist/googleFontsAssetProvider/index.es.js +127 -122
  82. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  83. package/dist/iconifyComponent/index.cjs.js +2 -2
  84. package/dist/iconifyComponent/index.es.js +170 -165
  85. package/dist/iconifyComponent/index.umd.js +2 -2
  86. package/dist/index.cjs.js +1 -1
  87. package/dist/index.es.js +27 -22
  88. package/dist/index.umd.js +1 -1
  89. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  90. package/dist/layoutSidebarButtons/index.es.js +156 -151
  91. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  92. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  93. package/dist/lightGalleryComponent/index.es.js +197 -192
  94. package/dist/lightGalleryComponent/index.umd.js +1 -1
  95. package/dist/linkImageComponent/index.cjs.js +2 -2
  96. package/dist/linkImageComponent/index.es.js +86 -81
  97. package/dist/linkImageComponent/index.umd.js +2 -2
  98. package/dist/listPagesComponent/index.cjs.js +5 -5
  99. package/dist/listPagesComponent/index.es.js +121 -116
  100. package/dist/listPagesComponent/index.umd.js +5 -5
  101. package/dist/presetPrintable/index.cjs.js +4 -4
  102. package/dist/presetPrintable/index.es.js +180 -175
  103. package/dist/presetPrintable/index.umd.js +4 -4
  104. package/dist/prosemirror/index.cjs.js +6 -6
  105. package/dist/prosemirror/index.es.js +128 -123
  106. package/dist/prosemirror/index.umd.js +8 -8
  107. package/dist/rendererReact/index.cjs.js +1 -1
  108. package/dist/rendererReact/index.es.js +127 -122
  109. package/dist/rendererReact/index.js +1 -1
  110. package/dist/rendererReact/index.umd.js +1 -1
  111. package/dist/rteTinyMce/index.cjs.js +2 -2
  112. package/dist/rteTinyMce/index.es.js +160 -155
  113. package/dist/rteTinyMce/index.umd.js +2 -2
  114. package/dist/shapeDividerComponent/index.cjs.js +25 -25
  115. package/dist/shapeDividerComponent/index.es.js +127 -122
  116. package/dist/shapeDividerComponent/index.umd.js +25 -25
  117. package/dist/swiperComponent/index.cjs.js +9 -9
  118. package/dist/swiperComponent/index.es.js +197 -192
  119. package/dist/swiperComponent/index.umd.js +9 -9
  120. package/dist/tableComponent/index.cjs.js +1 -1
  121. package/dist/tableComponent/index.es.js +227 -222
  122. package/dist/tableComponent/index.umd.js +1 -1
  123. package/dist/types.d.ts +1 -1
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  126. package/dist/youtubeAssetProvider/index.es.js +124 -119
  127. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  128. package/package.json +5 -2
  129. package/dist/aiChat/components/AiChatInput.d.ts +0 -17
  130. package/dist/aiChat/server/stream-utils.d.ts +0 -16
@@ -1 +1 @@
1
- "use strict";const y=require("react/jsx-runtime"),g=require("react"),U=require("react-dom/client"),L="app.grapesjs.com",D="app-stage.grapesjs.com",W="app2.grapesjs.com",B="app-stage2.grapesjs.com",N=[L,W,D,B,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",F="license:check:end",K=()=>typeof window<"u",M=({isDev:e,isStage:t})=>`${e?"":`https://${t?D:L}`}/api`,V=()=>{const e=K()&&window.location.hostname;return!!e&&(N.includes(e)||N.some(t=>e.endsWith(t)))},z=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(t,n)=>(n?"-":"")+t.toLowerCase()),T=e=>typeof e=="string";function q(e){return typeof e=="function"}async function G({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:o}){const c=`${t||M({isDev:!1,isStage:!1})}${e}`,i={method:n,headers:{"Content-Type":"application/json",...s}};o&&(i.body=JSON.stringify(o));const u=r?new URLSearchParams(r).toString():"",l=u?`?${u}`:"",d=await fetch(`${c}${l}`,i);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var C=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(C||{});const P={[C.free]:0,[C.startup]:10,[C.business]:20,[C.enterprise]:30};function J(e){const t=e;return t.init=n=>s=>e(s,n),t}const H=e=>J(e);async function Z({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let o="",a=!1;const c=V(),i=l=>{console.warn("Cleanup plugin:",n,"Reason:",l),r()},u=(l={})=>{var h;const{error:d,sdkLicense:m}=l,f=(h=l.plan)==null?void 0:h.category;if(!(m||l.license)||d)i(d||"Invalid license");else if(f){const k=P[t],w=P[f];k>w&&i({pluginRequiredPlan:t,licensePlan:f})}};e.on($,l=>{o=l==null?void 0:l.baseApiUrl,a=!0}),e.on(F,l=>{u(l)}),setTimeout(async()=>{if(!a){if(c)return;if(s){const l=await Q({licenseKey:s,pluginName:n,baseApiUrl:o});l&&u(l)}else i("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await G({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function X(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const s=z(n);t[s]=e[n]}return t}const Y=(e,t)=>{const n=e.components||{};for(const s in n){const r=n[s];if(r.component===t)return{cmpConfig:r,type:s}}};function O(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const o=s.includes("-")?s.replace(/-([a-z])/g,a=>a[1].toUpperCase()):s;t[o]=r,n=!0}}return n?t:void 0}function ee(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),o=n.substring(s+1).trim();if(r&&o){const a=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[a]=o}}}),Object.keys(t).length>0?t:void 0}function te(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return O(e);if(typeof e=="string"){let t=ee(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=O(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const o=s.replace(/-([a-z])/g,a=>a[1].toUpperCase());t[o]=r}}}),Object.keys(t).length>0?t:void 0}}}function ne(e){return j[e]?j[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function oe(e){var n;const t={};for(const[s,r]of Object.entries(e))if(s==="style")t.style=te(r);else if(s.startsWith("data-"))t[s]=r;else{const o=ne(s);((n=e.xmlns)==null?void 0:n.includes("svg"))||e.viewBox!==void 0||e.d!==void 0||re.has(o)||o.startsWith("svg")?t[o]=r:!se.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=r:t[o]=r}return t}const se=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),re=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),j={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},A=e=>(e==null?void 0:e.$$typeof)&&typeof e.props=="object";function ce(e){return t=>{const n=t.getContent();A(n)&&t.set({content:b({...e,model:n}),reactContent:n})}}const ae=e=>t=>{const n=t.component;A(n)&&(t.component={components:b({...e,model:n})})};function b(e){const{model:t,editor:n,config:s}=e;if(A(t)){const r=t,o={},{type:a,props:c={}}=r,{children:i,className:u,style:l,...d}=c,m=p=>({type:"textnode",content:p}),f=typeof a=="symbol";if(q(a)){const p=Y(s,a);o.type=p==null?void 0:p.type}else n.Components.getType(a)?o.type=a:f||(o.tagName=a);if(u&&(o.classes=u),l&&(o.style=X(l)),Array.isArray(i)?o.components=i.map(p=>T(p)?m(p):b({...e,model:p})).filter(Boolean):T(i)&&(o.components=m(i)),Object.keys(d).length){const p=n.Parser.parserHtml.splitPropsFromAttr(d);o.attributes=p.attrs,Object.assign(o,p.props)}return o}}function ie(e){const{component:t}=e,[n,s]=g.useState(0),[r,o]=g.useState();return g.useEffect(()=>{if(!t)return()=>{};const c=()=>s(p=>p+1),i=()=>{[...t.views].forEach(h=>h.remove()),o(void 0)},{em:u}=t,l=u.Components.events,m=[...["components","attributes","classes"].map(p=>`${l.update}:${p}`),"rerender"].join(" "),f=[l.removed,"rerender"].join(" ");return t.on(m,c),t.on(f,i),()=>{t.off(m,c),t.off(f,i),i()}},[t]),{key:n,view:r,connectDom:c=>{if(!c)return;const i=le({...e,el:c});o(i)}}}function le(e){var i;const{editor:t,component:n,el:s,frameView:r}=e,{em:o,Components:a}=t;let c=n.getView(r.model);if((c==null?void 0:c.el)===s)return c;if(!c){const{ComponentView:u}=a,l=n.attributes.type||"default",d=((i=a.getType(l))==null?void 0:i.view)||u,m={...a.config,frameView:r,em:o},f=d.extend({initComponents(){},_createElement(){return s},_removeElement(){},__clearAttributes(){},render(){var p;return this._ensureElement(),this._setData(),this.renderAttributes(),(p=this.updateSrc)==null||p.call(this),this}});c=new f({el:s,config:m,model:n})}return c.el=s,c.render(),c}function pe(e,t){const{Components:n}=e,s=r=>{const{id:o,model:a}=r;n.addType(o,{model:{toJSON(...c){const i=a.prototype.toJSON.apply(this,c);return i.tagName=this.tagName,i}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,o])=>{var m,f;const{allowPropClassName:a,allowPropId:c,allowChildren:i}=o,u=!c&&!a,l=()=>({disabled:u}),d=()=>({disableClasses:!a,disableComponent:!c});n.addType(r,{isComponent:p=>(p==null?void 0:p.tagName)===r,model:{defaults:{type:r,traits:((m=o.props)==null?void 0:m.call(o))||[],droppable:!!i,stylable:!u,styleManager:l,selectorManager:d,...((f=o.model)==null?void 0:f.defaults)||{}}}})})}function _(e){var x;const{component:t,config:n,editor:s,frameView:r,onMount:o,tagName:a,children:c}=e,{key:i,view:u,connectDom:l}=ie(e);g.useEffect(()=>{if(!u&&!o)return;const v=setTimeout(()=>{u&&(o==null||o(u),setTimeout(()=>u.postRender()))});return()=>clearTimeout(v)},[u]);const d=t.get("type")||"default",m=t.content,f=(x=n.components)==null?void 0:x[d],p=(f==null?void 0:f.component)||a||t.tagName||"div",h=t.components(),k=h.length?h.map(v=>y.jsx(_,{component:v,config:n,editor:s,frameView:r},v.cid)):[m||void 0],w=oe(t.getAttributes()),E=f==null?void 0:f.editorRender,S=[...k,c].filter(v=>v??!1),R=S.length?S:null;if(E)return y.jsx(E,{props:w,editor:s,component:t,connectDom:l,children:R});if(f!=null&&f.component)return y.jsx("gjs-wrapper",{ref:l,style:f.wrapperStyle,children:y.jsx(p,{...w,children:R})});if(t.isInstanceOf("textnode"))return m;const I=t.isInstanceOf("text")?i:void 0;return g.createElement(p,{...w,ref:l,key:I},t.get("void")?null:R)}const ue=e=>{const{frame:t,window:n,onMount:s,editor:r}=e,o=r.Canvas.events,{root:a}=t;try{const c=U.createRoot(n.document.body);c.render(y.jsx(fe,{...e,component:a,onMount:s}));const i=()=>c.unmount();t.once(o.frameUnload,i),n.addEventListener("unload",i)}catch(c){console.warn(c)}return a.getView()};function fe(e){const{editor:t,component:n,window:s,frameView:r,config:o,onMount:a}=e,c=s.document,i=o.rootComponent||g.Fragment,u=o.rootComponent?{editorProps:{doc:c,editor:t,frameView:r}}:{},l=(o==null?void 0:o.bodyAfter)||g.Fragment;return y.jsx(i,{...u,children:y.jsx(_,{tagName:"div",component:n,config:o,editor:t,frameView:r,onMount:a,children:y.jsx(l,{...u})})})}const de="rendererReact",me=C.startup,ye=function(e,t={}){const{Blocks:n,Pages:s}=e,r=n.events,o=s.events;e.Canvas.config.customRenderer=c=>ue({...c,config:t}),e.Components.config.processor=c=>b({model:c,editor:e,config:t}),pe(e,t);const a=[[r.add,ce({editor:e,config:t})],[o.addBefore,ae({editor:e,config:t})]];a.forEach(([c,i])=>e.on(c,i)),Z({editor:e,licenseKey:t.licenseKey,plan:me,pluginName:de,cleanup:()=>{e.Canvas.config.customRenderer=void 0,e.Components.config.processor=void 0,a.forEach(([c,i])=>e.off(c,i))}})},he=H(ye);module.exports=he;
1
+ "use strict";const y=require("react/jsx-runtime"),h=require("react"),W=require("react-dom/client"),D="app.grapesjs.com",_="app-stage.grapesjs.com",$="app2.grapesjs.com",B="app-stage2.grapesjs.com",R=[D,$,_,B,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",F="license:check:end",K=()=>typeof window<"u",M=({isDev:e,isStage:t,isPlatform:n})=>`${e?"":`https://${t?_:D}`}/${n?"platform-api":"api"}`,V=()=>{const e=K()&&window.location.hostname;return!!e&&(R.includes(e)||R.some(t=>e.endsWith(t)))},z=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(t,n)=>(n?"-":"")+t.toLowerCase()),T=e=>typeof e=="string";function q(e){return typeof e=="function"}async function G({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:o}){const c=`${t||M({isDev:!1,isStage:!1})}${e}`,i={method:n,headers:{"Content-Type":"application/json",...s}};o&&(i.body=JSON.stringify(o));const u=r?new URLSearchParams(r).toString():"",d=u?`?${u}`:"",p=await fetch(`${c}${d}`,i);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var v=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(v||{});const P={[v.free]:0,[v.startup]:10,[v.business]:20,[v.enterprise]:30};function J(e){const t=e;return t.init=n=>s=>e(s,n),t}const H=e=>J(e);async function Z({editor:e,plan:t,pluginName:n,licenseKey:s,onLicenseCheckResponse:r,cleanup:o}){let a="",c=!1;const i=V(),u=p=>{console.warn("Cleanup plugin:",n,"Reason:",p),o()},d=(p={})=>{var b;const{error:m,sdkLicense:f}=p,l=(b=p.plan)==null?void 0:b.category;if(!(f||p.license)||m)u(m||"Invalid license");else if(l){const C=P[t],A=P[l];C>A&&u({pluginRequiredPlan:t,licensePlan:l})}};e.on(L,p=>{a=p==null?void 0:p.baseApiUrl,c=!0}),e.on(F,p=>{r==null||r(p),d(p)}),setTimeout(async()=>{if(!c){if(i)return;if(s){const p=await Q({licenseKey:s,pluginName:n,baseApiUrl:a});r==null||r(p),p&&d(p)}else u("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await G({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function X(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const s=z(n);t[s]=e[n]}return t}const Y=(e,t)=>{const n=e.components||{};for(const s in n){const r=n[s];if(r.component===t)return{cmpConfig:r,type:s}}};function O(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const o=s.includes("-")?s.replace(/-([a-z])/g,a=>a[1].toUpperCase()):s;t[o]=r,n=!0}}return n?t:void 0}function ee(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),o=n.substring(s+1).trim();if(r&&o){const a=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[a]=o}}}),Object.keys(t).length>0?t:void 0}function te(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return O(e);if(typeof e=="string"){let t=ee(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=O(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const o=s.replace(/-([a-z])/g,a=>a[1].toUpperCase());t[o]=r}}}),Object.keys(t).length>0?t:void 0}}}function ne(e){return j[e]?j[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function oe(e){var n;const t={};for(const[s,r]of Object.entries(e))if(s==="style")t.style=te(r);else if(s.startsWith("data-"))t[s]=r;else{const o=ne(s);((n=e.xmlns)==null?void 0:n.includes("svg"))||e.viewBox!==void 0||e.d!==void 0||re.has(o)||o.startsWith("svg")?t[o]=r:!se.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=r:t[o]=r}return t}const se=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),re=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),j={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},S=e=>(e==null?void 0:e.$$typeof)&&typeof e.props=="object";function ce(e){return t=>{const n=t.getContent();S(n)&&t.set({content:E({...e,model:n}),reactContent:n})}}const ae=e=>t=>{const n=t.component;S(n)&&(t.component={components:E({...e,model:n})})};function E(e){const{model:t,editor:n,config:s}=e;if(S(t)){const r=t,o={},{type:a,props:c={}}=r,{children:i,className:u,style:d,...p}=c,m=l=>({type:"textnode",content:l}),f=typeof a=="symbol";if(q(a)){const l=Y(s,a);o.type=l==null?void 0:l.type}else n.Components.getType(a)?o.type=a:f||(o.tagName=a);if(u&&(o.classes=u),d&&(o.style=X(d)),Array.isArray(i)?o.components=i.map(l=>T(l)?m(l):E({...e,model:l})).filter(Boolean):T(i)&&(o.components=m(i)),Object.keys(p).length){const l=n.Parser.parserHtml.splitPropsFromAttr(p);o.attributes=l.attrs,Object.assign(o,l.props)}return o}}function ie(e){const{component:t}=e,[n,s]=h.useState(0),[r,o]=h.useState();return h.useEffect(()=>{if(!t)return()=>{};const c=()=>s(l=>l+1),i=()=>{[...t.views].forEach(w=>w.remove()),o(void 0)},{em:u}=t,d=u.Components.events,m=[...["components","attributes","classes"].map(l=>`${d.update}:${l}`),"rerender"].join(" "),f=[d.removed,"rerender"].join(" ");return t.on(m,c),t.on(f,i),()=>{t.off(m,c),t.off(f,i),i()}},[t]),{key:n,view:r,connectDom:c=>{if(!c)return;const i=le({...e,el:c});o(i)}}}function le(e){var i;const{editor:t,component:n,el:s,frameView:r}=e,{em:o,Components:a}=t;let c=n.getView(r.model);if((c==null?void 0:c.el)===s)return c;if(!c){const{ComponentView:u}=a,d=n.attributes.type||"default",p=((i=a.getType(d))==null?void 0:i.view)||u,m={...a.config,frameView:r,em:o},f=p.extend({initComponents(){},_createElement(){return s},_removeElement(){},__clearAttributes(){},render(){var l;return this._ensureElement(),this._setData(),this.renderAttributes(),(l=this.updateSrc)==null||l.call(this),this}});c=new f({el:s,config:m,model:n})}return c.el=s,c.render(),c}function pe(e,t){const{Components:n}=e,s=r=>{const{id:o,model:a}=r;n.addType(o,{model:{toJSON(...c){const i=a.prototype.toJSON.apply(this,c);return i.tagName=this.tagName,i}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,o])=>{var m,f;const{allowPropClassName:a,allowPropId:c,allowChildren:i}=o,u=!c&&!a,d=()=>({disabled:u}),p=()=>({disableClasses:!a,disableComponent:!c});n.addType(r,{isComponent:l=>(l==null?void 0:l.tagName)===r,model:{defaults:{type:r,traits:((m=o.props)==null?void 0:m.call(o))||[],droppable:!!i,stylable:!u,styleManager:d,selectorManager:p,...((f=o.model)==null?void 0:f.defaults)||{}}}})})}function I(e){var N;const{component:t,config:n,editor:s,frameView:r,onMount:o,tagName:a,children:c}=e,{key:i,view:u,connectDom:d}=ie(e);h.useEffect(()=>{if(!u&&!o)return;const g=setTimeout(()=>{u&&(o==null||o(u),setTimeout(()=>u.postRender()))});return()=>clearTimeout(g)},[u]);const p=t.get("type")||"default",m=t.content,f=(N=n.components)==null?void 0:N[p],l=(f==null?void 0:f.component)||a||t.tagName||"div",w=t.components(),b=w.length?w.map(g=>y.jsx(I,{component:g,config:n,editor:s,frameView:r},g.cid)):[m||void 0],C=oe(t.getAttributes()),A=f==null?void 0:f.editorRender,x=[...b,c].filter(g=>g??!1),k=x.length?x:null;if(A)return y.jsx(A,{props:C,editor:s,component:t,connectDom:d,children:k});if(f!=null&&f.component)return y.jsx("gjs-wrapper",{ref:d,style:f.wrapperStyle,children:y.jsx(l,{...C,children:k})});if(t.isInstanceOf("textnode"))return m;const U=t.isInstanceOf("text")?i:void 0;return h.createElement(l,{...C,ref:d,key:U},t.get("void")?null:k)}const ue=e=>{const{frame:t,window:n,onMount:s,editor:r}=e,o=r.Canvas.events,{root:a}=t;try{const c=W.createRoot(n.document.body);c.render(y.jsx(fe,{...e,component:a,onMount:s}));const i=()=>c.unmount();t.once(o.frameUnload,i),n.addEventListener("unload",i)}catch(c){console.warn(c)}return a.getView()};function fe(e){const{editor:t,component:n,window:s,frameView:r,config:o,onMount:a}=e,c=s.document,i=o.rootComponent||h.Fragment,u=o.rootComponent?{editorProps:{doc:c,editor:t,frameView:r}}:{},d=(o==null?void 0:o.bodyAfter)||h.Fragment;return y.jsx(i,{...u,children:y.jsx(I,{tagName:"div",component:n,config:o,editor:t,frameView:r,onMount:a,children:y.jsx(d,{...u})})})}const de="rendererReact",me=v.startup,ye=function(e,t={}){const{Blocks:n,Pages:s}=e,r=n.events,o=s.events;e.Canvas.config.customRenderer=c=>ue({...c,config:t}),e.Components.config.processor=c=>E({model:c,editor:e,config:t}),pe(e,t);const a=[[r.add,ce({editor:e,config:t})],[o.addBefore,ae({editor:e,config:t})]];a.forEach(([c,i])=>e.on(c,i)),Z({editor:e,licenseKey:t.licenseKey,plan:me,pluginName:de,cleanup:()=>{e.Canvas.config.customRenderer=void 0,e.Components.config.processor=void 0,a.forEach(([c,i])=>e.off(c,i))}})},he=H(ye);module.exports=he;
@@ -1,10 +1,10 @@
1
1
  import { jsx as y } from "react/jsx-runtime";
2
- import { useState as N, useEffect as _, createElement as B, Fragment as T } from "react";
3
- import { createRoot as $ } from "react-dom/client";
4
- const I = "app.grapesjs.com", U = "app-stage.grapesjs.com", K = "app2.grapesjs.com", F = "app-stage2.grapesjs.com", P = [
5
- I,
6
- K,
2
+ import { useState as R, useEffect as I, createElement as B, Fragment as T } from "react";
3
+ import { createRoot as L } from "react-dom/client";
4
+ const U = "app.grapesjs.com", W = "app-stage.grapesjs.com", K = "app2.grapesjs.com", F = "app-stage2.grapesjs.com", P = [
7
5
  U,
6
+ K,
7
+ W,
8
8
  F,
9
9
  "localhost",
10
10
  "127.0.0.1",
@@ -14,7 +14,11 @@ const I = "app.grapesjs.com", U = "app-stage.grapesjs.com", K = "app2.grapesjs.c
14
14
  // For stackblitz.com demos
15
15
  "-sandpack.codesandbox.io"
16
16
  // For Sandpack demos
17
- ], M = "license:check:start", V = "license:check:end", z = () => typeof window < "u", G = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? U : I}`}/api`, J = () => {
17
+ ], M = "license:check:start", V = "license:check:end", z = () => typeof window < "u", G = ({
18
+ isDev: e,
19
+ isStage: t,
20
+ isPlatform: n
21
+ }) => `${e ? "" : `https://${t ? W : U}`}/${n ? "platform-api" : "api"}`, J = () => {
18
22
  const e = z() && window.location.hostname;
19
23
  return !!e && (P.includes(e) || P.some((t) => e.endsWith(t)));
20
24
  }, q = (e) => e.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (t, n) => (n ? "-" : "") + t.toLowerCase()), x = (e) => typeof e == "string";
@@ -29,7 +33,7 @@ async function Z({
29
33
  params: r,
30
34
  body: o
31
35
  }) {
32
- const c = `${t || G({ isDev: !1, isStage: !1 })}${e}`, i = {
36
+ const a = `${t || G({ isDev: !1, isStage: !1 })}${e}`, i = {
33
37
  method: n,
34
38
  headers: {
35
39
  "Content-Type": "application/json",
@@ -37,17 +41,17 @@ async function Z({
37
41
  }
38
42
  };
39
43
  o && (i.body = JSON.stringify(o));
40
- const f = r ? new URLSearchParams(r).toString() : "", l = f ? `?${f}` : "", d = await fetch(`${c}${l}`, i);
41
- if (!d.ok)
42
- throw new Error(`HTTP error! status: ${d.status}`);
43
- return d.json();
44
+ const f = r ? new URLSearchParams(r).toString() : "", d = f ? `?${f}` : "", p = await fetch(`${a}${d}`, i);
45
+ if (!p.ok)
46
+ throw new Error(`HTTP error! status: ${p.status}`);
47
+ return p.json();
44
48
  }
45
- var v = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(v || {});
49
+ var g = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(g || {});
46
50
  const O = {
47
- [v.free]: 0,
48
- [v.startup]: 10,
49
- [v.business]: 20,
50
- [v.enterprise]: 30
51
+ [g.free]: 0,
52
+ [g.startup]: 10,
53
+ [g.business]: 20,
54
+ [g.enterprise]: 30
51
55
  };
52
56
  function Q(e) {
53
57
  const t = e;
@@ -59,33 +63,34 @@ async function Y({
59
63
  plan: t,
60
64
  pluginName: n,
61
65
  licenseKey: s,
62
- cleanup: r
66
+ onLicenseCheckResponse: r,
67
+ cleanup: o
63
68
  }) {
64
- let o = "", a = !1;
65
- const c = J(), i = (l) => {
66
- console.warn("Cleanup plugin:", n, "Reason:", l), r();
67
- }, f = (l = {}) => {
68
- var h;
69
- const { error: d, sdkLicense: m } = l, u = (h = l.plan) == null ? void 0 : h.category;
70
- if (!(m || l.license) || d)
71
- i(d || "Invalid license");
72
- else if (u) {
73
- const b = O[t], C = O[u];
74
- b > C && i({ pluginRequiredPlan: t, licensePlan: u });
69
+ let c = "", a = !1;
70
+ const i = J(), f = (p) => {
71
+ console.warn("Cleanup plugin:", n, "Reason:", p), o();
72
+ }, d = (p = {}) => {
73
+ var C;
74
+ const { error: m, sdkLicense: u } = p, l = (C = p.plan) == null ? void 0 : C.category;
75
+ if (!(u || p.license) || m)
76
+ f(m || "Invalid license");
77
+ else if (l) {
78
+ const w = O[t], b = O[l];
79
+ w > b && f({ pluginRequiredPlan: t, licensePlan: l });
75
80
  }
76
81
  };
77
- e.on(M, (l) => {
78
- o = l == null ? void 0 : l.baseApiUrl, a = !0;
79
- }), e.on(V, (l) => {
80
- f(l);
82
+ e.on(M, (p) => {
83
+ c = p == null ? void 0 : p.baseApiUrl, a = !0;
84
+ }), e.on(V, (p) => {
85
+ r == null || r(p), d(p);
81
86
  }), setTimeout(async () => {
82
87
  if (!a) {
83
- if (c) return;
88
+ if (i) return;
84
89
  if (s) {
85
- const l = await ee({ licenseKey: s, pluginName: n, baseApiUrl: o });
86
- l && f(l);
90
+ const p = await ee({ licenseKey: s, pluginName: n, baseApiUrl: c });
91
+ r == null || r(p), p && d(p);
87
92
  } else
88
- i("The `licenseKey` option not provided");
93
+ f("The `licenseKey` option not provided");
89
94
  }
90
95
  }, 2e3);
91
96
  }
@@ -122,14 +127,14 @@ const ne = (e, t) => {
122
127
  return { cmpConfig: r, type: s };
123
128
  }
124
129
  };
125
- function L(e) {
130
+ function D(e) {
126
131
  const t = {};
127
132
  let n = !1;
128
133
  for (const s in e)
129
134
  if (Object.prototype.hasOwnProperty.call(e, s)) {
130
135
  const r = e[s];
131
136
  if (typeof r == "string" || typeof r == "number") {
132
- const o = s.includes("-") ? s.replace(/-([a-z])/g, (a) => a[1].toUpperCase()) : s;
137
+ const o = s.includes("-") ? s.replace(/-([a-z])/g, (c) => c[1].toUpperCase()) : s;
133
138
  t[o] = r, n = !0;
134
139
  }
135
140
  }
@@ -143,8 +148,8 @@ function oe(e) {
143
148
  if (s > 0) {
144
149
  const r = n.substring(0, s).trim(), o = n.substring(s + 1).trim();
145
150
  if (r && o) {
146
- const a = r.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
147
- t[a] = o;
151
+ const c = r.replace(/-([a-z])/g, (a) => a[1].toUpperCase());
152
+ t[c] = o;
148
153
  }
149
154
  }
150
155
  }), Object.keys(t).length > 0 ? t : void 0;
@@ -152,13 +157,13 @@ function oe(e) {
152
157
  function se(e) {
153
158
  if (e) {
154
159
  if (typeof e == "object" && !Array.isArray(e))
155
- return L(e);
160
+ return D(e);
156
161
  if (typeof e == "string") {
157
162
  let t = oe(e);
158
163
  if (!t)
159
164
  try {
160
165
  const n = JSON.parse(e);
161
- typeof n == "object" && n !== null && !Array.isArray(n) && (t = L(n));
166
+ typeof n == "object" && n !== null && !Array.isArray(n) && (t = D(n));
162
167
  } catch (n) {
163
168
  console.error("Failed to parse style string as JSON", n);
164
169
  }
@@ -170,7 +175,7 @@ function se(e) {
170
175
  if (typeof n == "object" && n !== null) {
171
176
  const s = n.name || n.property, r = n.value;
172
177
  if (typeof s == "string" && s && r !== void 0 && r !== "") {
173
- const o = s.replace(/-([a-z])/g, (a) => a[1].toUpperCase());
178
+ const o = s.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
174
179
  t[o] = r;
175
180
  }
176
181
  }
@@ -179,9 +184,9 @@ function se(e) {
179
184
  }
180
185
  }
181
186
  function re(e) {
182
- return D[e] ? D[e] : e.includes("-") ? e.replace(/-([a-z])/g, (t, n) => n.toUpperCase()) : e;
187
+ return _[e] ? _[e] : e.includes("-") ? e.replace(/-([a-z])/g, (t, n) => n.toUpperCase()) : e;
183
188
  }
184
- function ce(e) {
189
+ function ae(e) {
185
190
  var n;
186
191
  const t = {};
187
192
  for (const [s, r] of Object.entries(e))
@@ -191,11 +196,11 @@ function ce(e) {
191
196
  t[s] = r;
192
197
  else {
193
198
  const o = re(s);
194
- ((n = e.xmlns) == null ? void 0 : n.includes("svg")) || e.viewBox !== void 0 || e.d !== void 0 || ie.has(o) || o.startsWith("svg") ? t[o] = r : !ae.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[s] = r : t[o] = r;
199
+ ((n = e.xmlns) == null ? void 0 : n.includes("svg")) || e.viewBox !== void 0 || e.d !== void 0 || ie.has(o) || o.startsWith("svg") ? t[o] = r : !ce.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[s] = r : t[o] = r;
195
200
  }
196
201
  return t;
197
202
  }
198
- const ae = /* @__PURE__ */ new Set([
203
+ const ce = /* @__PURE__ */ new Set([
199
204
  "className",
200
205
  "id",
201
206
  "style",
@@ -279,7 +284,7 @@ const ae = /* @__PURE__ */ new Set([
279
284
  "clipPath",
280
285
  "overflow",
281
286
  "pointerEvents"
282
- ]), D = {
287
+ ]), _ = {
283
288
  class: "className",
284
289
  for: "htmlFor",
285
290
  "http-equiv": "httpEquiv",
@@ -296,60 +301,60 @@ const ae = /* @__PURE__ */ new Set([
296
301
  "font-family": "fontFamily",
297
302
  "font-size": "fontSize",
298
303
  "text-anchor": "textAnchor"
299
- }, R = (e) => (e == null ? void 0 : e.$$typeof) && typeof e.props == "object";
304
+ }, E = (e) => (e == null ? void 0 : e.$$typeof) && typeof e.props == "object";
300
305
  function le(e) {
301
306
  return (t) => {
302
307
  const n = t.getContent();
303
- R(n) && t.set({
304
- content: w({ ...e, model: n }),
308
+ E(n) && t.set({
309
+ content: A({ ...e, model: n }),
305
310
  reactContent: n
306
311
  });
307
312
  };
308
313
  }
309
314
  const pe = (e) => (t) => {
310
315
  const n = t.component;
311
- R(n) && (t.component = { components: w({ ...e, model: n }) });
316
+ E(n) && (t.component = { components: A({ ...e, model: n }) });
312
317
  };
313
- function w(e) {
318
+ function A(e) {
314
319
  const { model: t, editor: n, config: s } = e;
315
- if (R(t)) {
316
- const r = t, o = {}, { type: a, props: c = {} } = r, { children: i, className: f, style: l, ...d } = c, m = (p) => ({ type: "textnode", content: p }), u = typeof a == "symbol";
317
- if (H(a)) {
318
- const p = ne(s, a);
319
- o.type = p == null ? void 0 : p.type;
320
- } else n.Components.getType(a) ? o.type = a : u || (o.tagName = a);
321
- if (f && (o.classes = f), l && (o.style = te(l)), Array.isArray(i) ? o.components = i.map((p) => x(p) ? m(p) : w({ ...e, model: p })).filter(Boolean) : x(i) && (o.components = m(i)), Object.keys(d).length) {
322
- const p = n.Parser.parserHtml.splitPropsFromAttr(d);
323
- o.attributes = p.attrs, Object.assign(o, p.props);
320
+ if (E(t)) {
321
+ const r = t, o = {}, { type: c, props: a = {} } = r, { children: i, className: f, style: d, ...p } = a, m = (l) => ({ type: "textnode", content: l }), u = typeof c == "symbol";
322
+ if (H(c)) {
323
+ const l = ne(s, c);
324
+ o.type = l == null ? void 0 : l.type;
325
+ } else n.Components.getType(c) ? o.type = c : u || (o.tagName = c);
326
+ if (f && (o.classes = f), d && (o.style = te(d)), Array.isArray(i) ? o.components = i.map((l) => x(l) ? m(l) : A({ ...e, model: l })).filter(Boolean) : x(i) && (o.components = m(i)), Object.keys(p).length) {
327
+ const l = n.Parser.parserHtml.splitPropsFromAttr(p);
328
+ o.attributes = l.attrs, Object.assign(o, l.props);
324
329
  }
325
330
  return o;
326
331
  }
327
332
  }
328
333
  function fe(e) {
329
- const { component: t } = e, [n, s] = N(0), [r, o] = N();
330
- return _(() => {
334
+ const { component: t } = e, [n, s] = R(0), [r, o] = R();
335
+ return I(() => {
331
336
  if (!t) return () => {
332
337
  };
333
- const c = () => s((p) => p + 1), i = () => {
334
- [...t.views].forEach((h) => h.remove()), o(void 0);
335
- }, { em: f } = t, l = f.Components.events, m = [...["components", "attributes", "classes"].map((p) => `${l.update}:${p}`), "rerender"].join(" "), u = [l.removed, "rerender"].join(" ");
336
- return t.on(m, c), t.on(u, i), () => {
337
- t.off(m, c), t.off(u, i), i();
338
+ const a = () => s((l) => l + 1), i = () => {
339
+ [...t.views].forEach((v) => v.remove()), o(void 0);
340
+ }, { em: f } = t, d = f.Components.events, m = [...["components", "attributes", "classes"].map((l) => `${d.update}:${l}`), "rerender"].join(" "), u = [d.removed, "rerender"].join(" ");
341
+ return t.on(m, a), t.on(u, i), () => {
342
+ t.off(m, a), t.off(u, i), i();
338
343
  };
339
- }, [t]), { key: n, view: r, connectDom: (c) => {
340
- if (!c) return;
341
- const i = ue({ ...e, el: c });
344
+ }, [t]), { key: n, view: r, connectDom: (a) => {
345
+ if (!a) return;
346
+ const i = ue({ ...e, el: a });
342
347
  o(i);
343
348
  } };
344
349
  }
345
350
  function ue(e) {
346
351
  var i;
347
- const { editor: t, component: n, el: s, frameView: r } = e, { em: o, Components: a } = t;
348
- let c = n.getView(r.model);
349
- if ((c == null ? void 0 : c.el) === s)
350
- return c;
351
- if (!c) {
352
- const { ComponentView: f } = a, l = n.attributes.type || "default", d = ((i = a.getType(l)) == null ? void 0 : i.view) || f, m = { ...a.config, frameView: r, em: o }, u = d.extend({
352
+ const { editor: t, component: n, el: s, frameView: r } = e, { em: o, Components: c } = t;
353
+ let a = n.getView(r.model);
354
+ if ((a == null ? void 0 : a.el) === s)
355
+ return a;
356
+ if (!a) {
357
+ const { ComponentView: f } = c, d = n.attributes.type || "default", p = ((i = c.getType(d)) == null ? void 0 : i.view) || f, m = { ...c.config, frameView: r, em: o }, u = p.extend({
353
358
  initComponents() {
354
359
  },
355
360
  _createElement() {
@@ -360,21 +365,21 @@ function ue(e) {
360
365
  __clearAttributes() {
361
366
  },
362
367
  render() {
363
- var p;
364
- return this._ensureElement(), this._setData(), this.renderAttributes(), (p = this.updateSrc) == null || p.call(this), this;
368
+ var l;
369
+ return this._ensureElement(), this._setData(), this.renderAttributes(), (l = this.updateSrc) == null || l.call(this), this;
365
370
  }
366
371
  });
367
- c = new u({ el: s, config: m, model: n });
372
+ a = new u({ el: s, config: m, model: n });
368
373
  }
369
- return c.el = s, c.render(), c;
374
+ return a.el = s, a.render(), a;
370
375
  }
371
376
  function de(e, t) {
372
377
  const { Components: n } = e, s = (r) => {
373
- const { id: o, model: a } = r;
378
+ const { id: o, model: c } = r;
374
379
  n.addType(o, {
375
380
  model: {
376
- toJSON(...c) {
377
- const i = a.prototype.toJSON.apply(this, c);
381
+ toJSON(...a) {
382
+ const i = c.prototype.toJSON.apply(this, a);
378
383
  return i.tagName = this.tagName, i;
379
384
  }
380
385
  }
@@ -382,92 +387,92 @@ function de(e, t) {
382
387
  };
383
388
  n.getTypes().forEach(s), e.on("component:type:add", s), Object.entries(t.components || {}).forEach(([r, o]) => {
384
389
  var m, u;
385
- const { allowPropClassName: a, allowPropId: c, allowChildren: i } = o, f = !c && !a, l = () => ({
390
+ const { allowPropClassName: c, allowPropId: a, allowChildren: i } = o, f = !a && !c, d = () => ({
386
391
  disabled: f
387
- }), d = () => ({
388
- disableClasses: !a,
389
- disableComponent: !c
392
+ }), p = () => ({
393
+ disableClasses: !c,
394
+ disableComponent: !a
390
395
  });
391
396
  n.addType(r, {
392
- isComponent: (p) => (p == null ? void 0 : p.tagName) === r,
397
+ isComponent: (l) => (l == null ? void 0 : l.tagName) === r,
393
398
  model: {
394
399
  defaults: {
395
400
  type: r,
396
401
  traits: ((m = o.props) == null ? void 0 : m.call(o)) || [],
397
402
  droppable: !!i,
398
403
  stylable: !f,
399
- styleManager: l,
400
- selectorManager: d,
404
+ styleManager: d,
405
+ selectorManager: p,
401
406
  ...((u = o.model) == null ? void 0 : u.defaults) || {}
402
407
  }
403
408
  }
404
409
  });
405
410
  });
406
411
  }
407
- function W(e) {
408
- var S;
409
- const { component: t, config: n, editor: s, frameView: r, onMount: o, tagName: a, children: c } = e, { key: i, view: f, connectDom: l } = fe(e);
410
- _(() => {
412
+ function j(e) {
413
+ var N;
414
+ const { component: t, config: n, editor: s, frameView: r, onMount: o, tagName: c, children: a } = e, { key: i, view: f, connectDom: d } = fe(e);
415
+ I(() => {
411
416
  if (!f && !o) return;
412
- const g = setTimeout(() => {
417
+ const h = setTimeout(() => {
413
418
  f && (o == null || o(f), setTimeout(() => f.postRender()));
414
419
  });
415
- return () => clearTimeout(g);
420
+ return () => clearTimeout(h);
416
421
  }, [f]);
417
- const d = t.get("type") || "default", m = t.content, u = (S = n.components) == null ? void 0 : S[d], p = (u == null ? void 0 : u.component) || a || t.tagName || "div", h = t.components(), b = h.length ? h.map((g) => /* @__PURE__ */ y(W, { component: g, config: n, editor: s, frameView: r }, g.cid)) : [m || void 0], C = ce(t.getAttributes()), A = u == null ? void 0 : u.editorRender, E = [...b, c].filter((g) => g ?? !1), k = E.length ? E : null;
418
- if (A)
419
- return /* @__PURE__ */ y(A, { props: C, editor: s, component: t, connectDom: l, children: k });
422
+ const p = t.get("type") || "default", m = t.content, u = (N = n.components) == null ? void 0 : N[p], l = (u == null ? void 0 : u.component) || c || t.tagName || "div", v = t.components(), C = v.length ? v.map((h) => /* @__PURE__ */ y(j, { component: h, config: n, editor: s, frameView: r }, h.cid)) : [m || void 0], w = ae(t.getAttributes()), b = u == null ? void 0 : u.editorRender, S = [...C, a].filter((h) => h ?? !1), k = S.length ? S : null;
423
+ if (b)
424
+ return /* @__PURE__ */ y(b, { props: w, editor: s, component: t, connectDom: d, children: k });
420
425
  if (u != null && u.component)
421
- return /* @__PURE__ */ y("gjs-wrapper", { ref: l, style: u.wrapperStyle, children: /* @__PURE__ */ y(p, { ...C, children: k }) });
426
+ return /* @__PURE__ */ y("gjs-wrapper", { ref: d, style: u.wrapperStyle, children: /* @__PURE__ */ y(l, { ...w, children: k }) });
422
427
  if (t.isInstanceOf("textnode"))
423
428
  return m;
424
- const j = t.isInstanceOf("text") ? i : void 0;
425
- return /* @__PURE__ */ B(p, { ...C, ref: l, key: j }, t.get("void") ? null : k);
429
+ const $ = t.isInstanceOf("text") ? i : void 0;
430
+ return /* @__PURE__ */ B(l, { ...w, ref: d, key: $ }, t.get("void") ? null : k);
426
431
  }
427
432
  const me = (e) => {
428
- const { frame: t, window: n, onMount: s, editor: r } = e, o = r.Canvas.events, { root: a } = t;
433
+ const { frame: t, window: n, onMount: s, editor: r } = e, o = r.Canvas.events, { root: c } = t;
429
434
  try {
430
- const c = $(n.document.body);
431
- c.render(/* @__PURE__ */ y(ye, { ...e, component: a, onMount: s }));
432
- const i = () => c.unmount();
435
+ const a = L(n.document.body);
436
+ a.render(/* @__PURE__ */ y(ye, { ...e, component: c, onMount: s }));
437
+ const i = () => a.unmount();
433
438
  t.once(o.frameUnload, i), n.addEventListener("unload", i);
434
- } catch (c) {
435
- console.warn(c);
439
+ } catch (a) {
440
+ console.warn(a);
436
441
  }
437
- return a.getView();
442
+ return c.getView();
438
443
  };
439
444
  function ye(e) {
440
- const { editor: t, component: n, window: s, frameView: r, config: o, onMount: a } = e, c = s.document, i = o.rootComponent || T, f = o.rootComponent ? { editorProps: { doc: c, editor: t, frameView: r } } : {}, l = (o == null ? void 0 : o.bodyAfter) || T;
445
+ const { editor: t, component: n, window: s, frameView: r, config: o, onMount: c } = e, a = s.document, i = o.rootComponent || T, f = o.rootComponent ? { editorProps: { doc: a, editor: t, frameView: r } } : {}, d = (o == null ? void 0 : o.bodyAfter) || T;
441
446
  return /* @__PURE__ */ y(i, { ...f, children: /* @__PURE__ */ y(
442
- W,
447
+ j,
443
448
  {
444
449
  tagName: "div",
445
450
  component: n,
446
451
  config: o,
447
452
  editor: t,
448
453
  frameView: r,
449
- onMount: a,
450
- children: /* @__PURE__ */ y(l, { ...f })
454
+ onMount: c,
455
+ children: /* @__PURE__ */ y(d, { ...f })
451
456
  }
452
457
  ) });
453
458
  }
454
- const he = "rendererReact", ge = v.startup, ve = function(e, t = {}) {
459
+ const he = "rendererReact", ge = g.startup, ve = function(e, t = {}) {
455
460
  const { Blocks: n, Pages: s } = e, r = n.events, o = s.events;
456
- e.Canvas.config.customRenderer = (c) => me({ ...c, config: t }), e.Components.config.processor = (c) => w({ model: c, editor: e, config: t }), de(e, t);
457
- const a = [
461
+ e.Canvas.config.customRenderer = (a) => me({ ...a, config: t }), e.Components.config.processor = (a) => A({ model: a, editor: e, config: t }), de(e, t);
462
+ const c = [
458
463
  [r.add, le({ editor: e, config: t })],
459
464
  [o.addBefore, pe({ editor: e, config: t })]
460
465
  ];
461
- a.forEach(([c, i]) => e.on(c, i)), Y({
466
+ c.forEach(([a, i]) => e.on(a, i)), Y({
462
467
  editor: e,
463
468
  licenseKey: t.licenseKey,
464
469
  plan: ge,
465
470
  pluginName: he,
466
471
  cleanup: () => {
467
- e.Canvas.config.customRenderer = void 0, e.Components.config.processor = void 0, a.forEach(([c, i]) => e.off(c, i));
472
+ e.Canvas.config.customRenderer = void 0, e.Components.config.processor = void 0, c.forEach(([a, i]) => e.off(a, i));
468
473
  }
469
474
  });
470
- }, ke = X(ve);
475
+ }, Ae = X(ve);
471
476
  export {
472
- ke as default
477
+ Ae as default
473
478
  };
@@ -1 +1 @@
1
- "use strict";const y=require("react/jsx-runtime"),g=require("react"),U=require("react-dom/client"),L="app.grapesjs.com",D="app-stage.grapesjs.com",W="app2.grapesjs.com",B="app-stage2.grapesjs.com",N=[L,W,D,B,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",F="license:check:end",K=()=>typeof window<"u",M=({isDev:e,isStage:t})=>`${e?"":`https://${t?D:L}`}/api`,V=()=>{const e=K()&&window.location.hostname;return!!e&&(N.includes(e)||N.some(t=>e.endsWith(t)))},z=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(t,n)=>(n?"-":"")+t.toLowerCase()),T=e=>typeof e=="string";function q(e){return typeof e=="function"}async function G({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:o}){const c=`${t||M({isDev:!1,isStage:!1})}${e}`,i={method:n,headers:{"Content-Type":"application/json",...s}};o&&(i.body=JSON.stringify(o));const u=r?new URLSearchParams(r).toString():"",l=u?`?${u}`:"",d=await fetch(`${c}${l}`,i);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var C=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(C||{});const P={[C.free]:0,[C.startup]:10,[C.business]:20,[C.enterprise]:30};function J(e){const t=e;return t.init=n=>s=>e(s,n),t}const H=e=>J(e);async function Z({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let o="",a=!1;const c=V(),i=l=>{console.warn("Cleanup plugin:",n,"Reason:",l),r()},u=(l={})=>{var h;const{error:d,sdkLicense:m}=l,f=(h=l.plan)==null?void 0:h.category;if(!(m||l.license)||d)i(d||"Invalid license");else if(f){const k=P[t],w=P[f];k>w&&i({pluginRequiredPlan:t,licensePlan:f})}};e.on($,l=>{o=l==null?void 0:l.baseApiUrl,a=!0}),e.on(F,l=>{u(l)}),setTimeout(async()=>{if(!a){if(c)return;if(s){const l=await Q({licenseKey:s,pluginName:n,baseApiUrl:o});l&&u(l)}else i("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await G({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function X(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const s=z(n);t[s]=e[n]}return t}const Y=(e,t)=>{const n=e.components||{};for(const s in n){const r=n[s];if(r.component===t)return{cmpConfig:r,type:s}}};function O(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const o=s.includes("-")?s.replace(/-([a-z])/g,a=>a[1].toUpperCase()):s;t[o]=r,n=!0}}return n?t:void 0}function ee(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),o=n.substring(s+1).trim();if(r&&o){const a=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[a]=o}}}),Object.keys(t).length>0?t:void 0}function te(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return O(e);if(typeof e=="string"){let t=ee(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=O(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const o=s.replace(/-([a-z])/g,a=>a[1].toUpperCase());t[o]=r}}}),Object.keys(t).length>0?t:void 0}}}function ne(e){return j[e]?j[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function oe(e){var n;const t={};for(const[s,r]of Object.entries(e))if(s==="style")t.style=te(r);else if(s.startsWith("data-"))t[s]=r;else{const o=ne(s);((n=e.xmlns)==null?void 0:n.includes("svg"))||e.viewBox!==void 0||e.d!==void 0||re.has(o)||o.startsWith("svg")?t[o]=r:!se.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=r:t[o]=r}return t}const se=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),re=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),j={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},A=e=>(e==null?void 0:e.$$typeof)&&typeof e.props=="object";function ce(e){return t=>{const n=t.getContent();A(n)&&t.set({content:b({...e,model:n}),reactContent:n})}}const ae=e=>t=>{const n=t.component;A(n)&&(t.component={components:b({...e,model:n})})};function b(e){const{model:t,editor:n,config:s}=e;if(A(t)){const r=t,o={},{type:a,props:c={}}=r,{children:i,className:u,style:l,...d}=c,m=p=>({type:"textnode",content:p}),f=typeof a=="symbol";if(q(a)){const p=Y(s,a);o.type=p==null?void 0:p.type}else n.Components.getType(a)?o.type=a:f||(o.tagName=a);if(u&&(o.classes=u),l&&(o.style=X(l)),Array.isArray(i)?o.components=i.map(p=>T(p)?m(p):b({...e,model:p})).filter(Boolean):T(i)&&(o.components=m(i)),Object.keys(d).length){const p=n.Parser.parserHtml.splitPropsFromAttr(d);o.attributes=p.attrs,Object.assign(o,p.props)}return o}}function ie(e){const{component:t}=e,[n,s]=g.useState(0),[r,o]=g.useState();return g.useEffect(()=>{if(!t)return()=>{};const c=()=>s(p=>p+1),i=()=>{[...t.views].forEach(h=>h.remove()),o(void 0)},{em:u}=t,l=u.Components.events,m=[...["components","attributes","classes"].map(p=>`${l.update}:${p}`),"rerender"].join(" "),f=[l.removed,"rerender"].join(" ");return t.on(m,c),t.on(f,i),()=>{t.off(m,c),t.off(f,i),i()}},[t]),{key:n,view:r,connectDom:c=>{if(!c)return;const i=le({...e,el:c});o(i)}}}function le(e){var i;const{editor:t,component:n,el:s,frameView:r}=e,{em:o,Components:a}=t;let c=n.getView(r.model);if((c==null?void 0:c.el)===s)return c;if(!c){const{ComponentView:u}=a,l=n.attributes.type||"default",d=((i=a.getType(l))==null?void 0:i.view)||u,m={...a.config,frameView:r,em:o},f=d.extend({initComponents(){},_createElement(){return s},_removeElement(){},__clearAttributes(){},render(){var p;return this._ensureElement(),this._setData(),this.renderAttributes(),(p=this.updateSrc)==null||p.call(this),this}});c=new f({el:s,config:m,model:n})}return c.el=s,c.render(),c}function pe(e,t){const{Components:n}=e,s=r=>{const{id:o,model:a}=r;n.addType(o,{model:{toJSON(...c){const i=a.prototype.toJSON.apply(this,c);return i.tagName=this.tagName,i}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,o])=>{var m,f;const{allowPropClassName:a,allowPropId:c,allowChildren:i}=o,u=!c&&!a,l=()=>({disabled:u}),d=()=>({disableClasses:!a,disableComponent:!c});n.addType(r,{isComponent:p=>(p==null?void 0:p.tagName)===r,model:{defaults:{type:r,traits:((m=o.props)==null?void 0:m.call(o))||[],droppable:!!i,stylable:!u,styleManager:l,selectorManager:d,...((f=o.model)==null?void 0:f.defaults)||{}}}})})}function _(e){var x;const{component:t,config:n,editor:s,frameView:r,onMount:o,tagName:a,children:c}=e,{key:i,view:u,connectDom:l}=ie(e);g.useEffect(()=>{if(!u&&!o)return;const v=setTimeout(()=>{u&&(o==null||o(u),setTimeout(()=>u.postRender()))});return()=>clearTimeout(v)},[u]);const d=t.get("type")||"default",m=t.content,f=(x=n.components)==null?void 0:x[d],p=(f==null?void 0:f.component)||a||t.tagName||"div",h=t.components(),k=h.length?h.map(v=>y.jsx(_,{component:v,config:n,editor:s,frameView:r},v.cid)):[m||void 0],w=oe(t.getAttributes()),E=f==null?void 0:f.editorRender,S=[...k,c].filter(v=>v??!1),R=S.length?S:null;if(E)return y.jsx(E,{props:w,editor:s,component:t,connectDom:l,children:R});if(f!=null&&f.component)return y.jsx("gjs-wrapper",{ref:l,style:f.wrapperStyle,children:y.jsx(p,{...w,children:R})});if(t.isInstanceOf("textnode"))return m;const I=t.isInstanceOf("text")?i:void 0;return g.createElement(p,{...w,ref:l,key:I},t.get("void")?null:R)}const ue=e=>{const{frame:t,window:n,onMount:s,editor:r}=e,o=r.Canvas.events,{root:a}=t;try{const c=U.createRoot(n.document.body);c.render(y.jsx(fe,{...e,component:a,onMount:s}));const i=()=>c.unmount();t.once(o.frameUnload,i),n.addEventListener("unload",i)}catch(c){console.warn(c)}return a.getView()};function fe(e){const{editor:t,component:n,window:s,frameView:r,config:o,onMount:a}=e,c=s.document,i=o.rootComponent||g.Fragment,u=o.rootComponent?{editorProps:{doc:c,editor:t,frameView:r}}:{},l=(o==null?void 0:o.bodyAfter)||g.Fragment;return y.jsx(i,{...u,children:y.jsx(_,{tagName:"div",component:n,config:o,editor:t,frameView:r,onMount:a,children:y.jsx(l,{...u})})})}const de="rendererReact",me=C.startup,ye=function(e,t={}){const{Blocks:n,Pages:s}=e,r=n.events,o=s.events;e.Canvas.config.customRenderer=c=>ue({...c,config:t}),e.Components.config.processor=c=>b({model:c,editor:e,config:t}),pe(e,t);const a=[[r.add,ce({editor:e,config:t})],[o.addBefore,ae({editor:e,config:t})]];a.forEach(([c,i])=>e.on(c,i)),Z({editor:e,licenseKey:t.licenseKey,plan:me,pluginName:de,cleanup:()=>{e.Canvas.config.customRenderer=void 0,e.Components.config.processor=void 0,a.forEach(([c,i])=>e.off(c,i))}})},he=H(ye);module.exports=he;
1
+ "use strict";const y=require("react/jsx-runtime"),h=require("react"),W=require("react-dom/client"),D="app.grapesjs.com",_="app-stage.grapesjs.com",$="app2.grapesjs.com",B="app-stage2.grapesjs.com",R=[D,$,_,B,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",F="license:check:end",K=()=>typeof window<"u",M=({isDev:e,isStage:t,isPlatform:n})=>`${e?"":`https://${t?_:D}`}/${n?"platform-api":"api"}`,V=()=>{const e=K()&&window.location.hostname;return!!e&&(R.includes(e)||R.some(t=>e.endsWith(t)))},z=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(t,n)=>(n?"-":"")+t.toLowerCase()),T=e=>typeof e=="string";function q(e){return typeof e=="function"}async function G({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:o}){const c=`${t||M({isDev:!1,isStage:!1})}${e}`,i={method:n,headers:{"Content-Type":"application/json",...s}};o&&(i.body=JSON.stringify(o));const u=r?new URLSearchParams(r).toString():"",d=u?`?${u}`:"",p=await fetch(`${c}${d}`,i);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var v=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(v||{});const P={[v.free]:0,[v.startup]:10,[v.business]:20,[v.enterprise]:30};function J(e){const t=e;return t.init=n=>s=>e(s,n),t}const H=e=>J(e);async function Z({editor:e,plan:t,pluginName:n,licenseKey:s,onLicenseCheckResponse:r,cleanup:o}){let a="",c=!1;const i=V(),u=p=>{console.warn("Cleanup plugin:",n,"Reason:",p),o()},d=(p={})=>{var b;const{error:m,sdkLicense:f}=p,l=(b=p.plan)==null?void 0:b.category;if(!(f||p.license)||m)u(m||"Invalid license");else if(l){const C=P[t],A=P[l];C>A&&u({pluginRequiredPlan:t,licensePlan:l})}};e.on(L,p=>{a=p==null?void 0:p.baseApiUrl,c=!0}),e.on(F,p=>{r==null||r(p),d(p)}),setTimeout(async()=>{if(!c){if(i)return;if(s){const p=await Q({licenseKey:s,pluginName:n,baseApiUrl:a});r==null||r(p),p&&d(p)}else u("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await G({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function X(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const s=z(n);t[s]=e[n]}return t}const Y=(e,t)=>{const n=e.components||{};for(const s in n){const r=n[s];if(r.component===t)return{cmpConfig:r,type:s}}};function O(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const o=s.includes("-")?s.replace(/-([a-z])/g,a=>a[1].toUpperCase()):s;t[o]=r,n=!0}}return n?t:void 0}function ee(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),o=n.substring(s+1).trim();if(r&&o){const a=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[a]=o}}}),Object.keys(t).length>0?t:void 0}function te(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return O(e);if(typeof e=="string"){let t=ee(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=O(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const o=s.replace(/-([a-z])/g,a=>a[1].toUpperCase());t[o]=r}}}),Object.keys(t).length>0?t:void 0}}}function ne(e){return j[e]?j[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function oe(e){var n;const t={};for(const[s,r]of Object.entries(e))if(s==="style")t.style=te(r);else if(s.startsWith("data-"))t[s]=r;else{const o=ne(s);((n=e.xmlns)==null?void 0:n.includes("svg"))||e.viewBox!==void 0||e.d!==void 0||re.has(o)||o.startsWith("svg")?t[o]=r:!se.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=r:t[o]=r}return t}const se=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),re=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),j={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},S=e=>(e==null?void 0:e.$$typeof)&&typeof e.props=="object";function ce(e){return t=>{const n=t.getContent();S(n)&&t.set({content:E({...e,model:n}),reactContent:n})}}const ae=e=>t=>{const n=t.component;S(n)&&(t.component={components:E({...e,model:n})})};function E(e){const{model:t,editor:n,config:s}=e;if(S(t)){const r=t,o={},{type:a,props:c={}}=r,{children:i,className:u,style:d,...p}=c,m=l=>({type:"textnode",content:l}),f=typeof a=="symbol";if(q(a)){const l=Y(s,a);o.type=l==null?void 0:l.type}else n.Components.getType(a)?o.type=a:f||(o.tagName=a);if(u&&(o.classes=u),d&&(o.style=X(d)),Array.isArray(i)?o.components=i.map(l=>T(l)?m(l):E({...e,model:l})).filter(Boolean):T(i)&&(o.components=m(i)),Object.keys(p).length){const l=n.Parser.parserHtml.splitPropsFromAttr(p);o.attributes=l.attrs,Object.assign(o,l.props)}return o}}function ie(e){const{component:t}=e,[n,s]=h.useState(0),[r,o]=h.useState();return h.useEffect(()=>{if(!t)return()=>{};const c=()=>s(l=>l+1),i=()=>{[...t.views].forEach(w=>w.remove()),o(void 0)},{em:u}=t,d=u.Components.events,m=[...["components","attributes","classes"].map(l=>`${d.update}:${l}`),"rerender"].join(" "),f=[d.removed,"rerender"].join(" ");return t.on(m,c),t.on(f,i),()=>{t.off(m,c),t.off(f,i),i()}},[t]),{key:n,view:r,connectDom:c=>{if(!c)return;const i=le({...e,el:c});o(i)}}}function le(e){var i;const{editor:t,component:n,el:s,frameView:r}=e,{em:o,Components:a}=t;let c=n.getView(r.model);if((c==null?void 0:c.el)===s)return c;if(!c){const{ComponentView:u}=a,d=n.attributes.type||"default",p=((i=a.getType(d))==null?void 0:i.view)||u,m={...a.config,frameView:r,em:o},f=p.extend({initComponents(){},_createElement(){return s},_removeElement(){},__clearAttributes(){},render(){var l;return this._ensureElement(),this._setData(),this.renderAttributes(),(l=this.updateSrc)==null||l.call(this),this}});c=new f({el:s,config:m,model:n})}return c.el=s,c.render(),c}function pe(e,t){const{Components:n}=e,s=r=>{const{id:o,model:a}=r;n.addType(o,{model:{toJSON(...c){const i=a.prototype.toJSON.apply(this,c);return i.tagName=this.tagName,i}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,o])=>{var m,f;const{allowPropClassName:a,allowPropId:c,allowChildren:i}=o,u=!c&&!a,d=()=>({disabled:u}),p=()=>({disableClasses:!a,disableComponent:!c});n.addType(r,{isComponent:l=>(l==null?void 0:l.tagName)===r,model:{defaults:{type:r,traits:((m=o.props)==null?void 0:m.call(o))||[],droppable:!!i,stylable:!u,styleManager:d,selectorManager:p,...((f=o.model)==null?void 0:f.defaults)||{}}}})})}function I(e){var N;const{component:t,config:n,editor:s,frameView:r,onMount:o,tagName:a,children:c}=e,{key:i,view:u,connectDom:d}=ie(e);h.useEffect(()=>{if(!u&&!o)return;const g=setTimeout(()=>{u&&(o==null||o(u),setTimeout(()=>u.postRender()))});return()=>clearTimeout(g)},[u]);const p=t.get("type")||"default",m=t.content,f=(N=n.components)==null?void 0:N[p],l=(f==null?void 0:f.component)||a||t.tagName||"div",w=t.components(),b=w.length?w.map(g=>y.jsx(I,{component:g,config:n,editor:s,frameView:r},g.cid)):[m||void 0],C=oe(t.getAttributes()),A=f==null?void 0:f.editorRender,x=[...b,c].filter(g=>g??!1),k=x.length?x:null;if(A)return y.jsx(A,{props:C,editor:s,component:t,connectDom:d,children:k});if(f!=null&&f.component)return y.jsx("gjs-wrapper",{ref:d,style:f.wrapperStyle,children:y.jsx(l,{...C,children:k})});if(t.isInstanceOf("textnode"))return m;const U=t.isInstanceOf("text")?i:void 0;return h.createElement(l,{...C,ref:d,key:U},t.get("void")?null:k)}const ue=e=>{const{frame:t,window:n,onMount:s,editor:r}=e,o=r.Canvas.events,{root:a}=t;try{const c=W.createRoot(n.document.body);c.render(y.jsx(fe,{...e,component:a,onMount:s}));const i=()=>c.unmount();t.once(o.frameUnload,i),n.addEventListener("unload",i)}catch(c){console.warn(c)}return a.getView()};function fe(e){const{editor:t,component:n,window:s,frameView:r,config:o,onMount:a}=e,c=s.document,i=o.rootComponent||h.Fragment,u=o.rootComponent?{editorProps:{doc:c,editor:t,frameView:r}}:{},d=(o==null?void 0:o.bodyAfter)||h.Fragment;return y.jsx(i,{...u,children:y.jsx(I,{tagName:"div",component:n,config:o,editor:t,frameView:r,onMount:a,children:y.jsx(d,{...u})})})}const de="rendererReact",me=v.startup,ye=function(e,t={}){const{Blocks:n,Pages:s}=e,r=n.events,o=s.events;e.Canvas.config.customRenderer=c=>ue({...c,config:t}),e.Components.config.processor=c=>E({model:c,editor:e,config:t}),pe(e,t);const a=[[r.add,ce({editor:e,config:t})],[o.addBefore,ae({editor:e,config:t})]];a.forEach(([c,i])=>e.on(c,i)),Z({editor:e,licenseKey:t.licenseKey,plan:me,pluginName:de,cleanup:()=>{e.Canvas.config.customRenderer=void 0,e.Components.config.processor=void 0,a.forEach(([c,i])=>e.off(c,i))}})},he=H(ye);module.exports=he;