@grapesjs/studio-sdk-plugins 1.0.25 → 1.0.26-rc.1

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 (65) hide show
  1. package/dist/dataSourceEjs/EjsExporter.d.ts +2 -2
  2. package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
  3. package/dist/flexComponent/index.cjs.js +1 -1
  4. package/dist/flexComponent/index.es.js +1 -1
  5. package/dist/flexComponent/index.umd.js +1 -1
  6. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  7. package/dist/googleFontsAssetProvider/index.es.js +4 -4
  8. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  9. package/dist/iconifyComponent/index.cjs.js +1 -1
  10. package/dist/iconifyComponent/index.es.js +1 -1
  11. package/dist/iconifyComponent/index.umd.js +1 -1
  12. package/dist/index.cjs.js +21 -21
  13. package/dist/index.es.js +219 -216
  14. package/dist/index.umd.js +2 -2
  15. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  16. package/dist/layoutSidebarButtons/index.es.js +19 -19
  17. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  18. package/dist/layoutSidebarButtons/types.d.ts +2 -1
  19. package/dist/presetPrintable/index.cjs.js +3 -3
  20. package/dist/presetPrintable/index.es.js +101 -101
  21. package/dist/presetPrintable/index.umd.js +1 -1
  22. package/dist/prosemirror/index.cjs.js +1 -1
  23. package/dist/prosemirror/index.es.js +1 -1
  24. package/dist/prosemirror/index.umd.js +1 -1
  25. package/dist/rendererReact/index.cjs.d.ts +3 -2
  26. package/dist/rendererReact/index.cjs.js +1 -1
  27. package/dist/rendererReact/index.d.ts +3 -2
  28. package/dist/rendererReact/index.es.d.ts +3 -2
  29. package/dist/rendererReact/index.es.js +219 -153
  30. package/dist/rendererReact/index.js +1 -0
  31. package/dist/rendererReact/index.umd.js +1 -1
  32. package/dist/rendererReact/rendererCanvas/RenderCanvasComponent.d.ts +4 -2
  33. package/dist/rendererReact/rendererCanvas/customRenderer.d.ts +2 -2
  34. package/dist/rendererReact/rendererCanvas/util.d.ts +27 -7
  35. package/dist/rendererReact/rendererProject/RenderComponent.d.ts +2 -0
  36. package/dist/rendererReact/rendererProject/RenderError.d.ts +2 -0
  37. package/dist/rendererReact/rendererProject/RenderPage.d.ts +2 -0
  38. package/dist/rendererReact/rendererProject/RenderProject.d.ts +3 -0
  39. package/dist/rendererReact/rendererProject/index.cjs.d.ts +1 -2
  40. package/dist/rendererReact/rendererProject/index.cjs.js +2 -10
  41. package/dist/rendererReact/rendererProject/index.d.ts +1 -2
  42. package/dist/rendererReact/rendererProject/index.es.d.ts +1 -2
  43. package/dist/rendererReact/rendererProject/index.es.js +206 -227
  44. package/dist/rendererReact/rendererProject/index.js +2 -10
  45. package/dist/rendererReact/rendererProject/index.umd.js +2 -10
  46. package/dist/rendererReact/rendererProject/parser/parser.d.ts +34 -53
  47. package/dist/rendererReact/rendererProject/types.d.ts +18 -4
  48. package/dist/rendererReact/rendererProject/util.d.ts +0 -11
  49. package/dist/rendererReact/shared/shared.d.ts +3 -0
  50. package/dist/rendererReact/shared/types.d.ts +150 -44
  51. package/dist/rendererReact/shared/util.d.ts +7 -1
  52. package/dist/rendererReact/types.d.ts +9 -12
  53. package/dist/rendererReact/typesSchema.d.ts +116 -49
  54. package/dist/rteTinyMce/index.cjs.js +1 -1
  55. package/dist/rteTinyMce/index.es.js +1 -1
  56. package/dist/rteTinyMce/index.umd.js +1 -1
  57. package/dist/tableComponent/index.cjs.js +1 -1
  58. package/dist/tableComponent/index.es.js +15 -12
  59. package/dist/tableComponent/index.umd.js +1 -1
  60. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  61. package/dist/youtubeAssetProvider/index.es.js +6 -6
  62. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  63. package/package.json +14 -2
  64. package/dist/rendererReact/rendererProject/GrapesJSProject.d.ts +0 -3
  65. package/dist/rendererReact/rendererProject/RenderProjectComponent.d.ts +0 -12
@@ -1,3 +1,4 @@
1
- import { ReactRendererPluginOptions } from './types';
2
- declare const _default: import('../utils').PluginWithInit<ReactRendererPluginOptions>;
1
+ import { RendererReactOptions } from './types';
2
+ export type * from './types';
3
+ declare const _default: import('../utils').PluginWithInit<RendererReactOptions>;
3
4
  export default _default;
@@ -1 +1 @@
1
- "use strict";const m=require("react/jsx-runtime"),h=require("react"),D=require("react-dom/client"),A="app.grapesjs.com",N="app-stage.grapesjs.com",x=[A,N,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",O="license:check:end",U=()=>typeof window<"u",j=({isDev:e,isStage:t})=>`${e?"":`https://${t?N:A}`}/api`,W=()=>{const e=U()&&window.location.hostname;return!!e&&(x.includes(e)||x.some(t=>e.endsWith(t)))};async function P({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:i}){const c=`${t||j({isDev:!1,isStage:!1})}${e}`,l={method:n,headers:{"Content-Type":"application/json",...s}};i&&(l.body=JSON.stringify(i));const u=r?new URLSearchParams(r).toString():"",a=u?`?${u}`:"",d=await fetch(`${c}${a}`,l);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var g=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(g||{});const R={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function I(e){const t=e;return t.init=n=>s=>e(s,n),t}const K=e=>I(e);async function $({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let i="",o=!1;const c=W(),l=a=>{console.warn("Cleanup plugin:",n,"Reason:",a),r()},u=(a={})=>{var y;const{error:d,sdkLicense:p}=a,f=(y=a.plan)==null?void 0:y.category;if(!(p||a.license)||d)l(d||"Invalid license");else if(f){const w=R[t],v=R[f];w>v&&l({pluginRequiredPlan:t,licensePlan:f})}};e.on(L,a=>{i=a==null?void 0:a.baseApiUrl,o=!0}),e.on(O,a=>{u(a)}),setTimeout(async()=>{if(!o){if(c)return;if(s){const a=await V({licenseKey:s,pluginName:n,baseApiUrl:i});a&&u(a)}else l("The `licenseKey` option not provided")}},2e3)}async function V(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await P({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 E(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 i=s.includes("-")?s.replace(/-([a-z])/g,o=>o[1].toUpperCase()):s;t[i]=r,n=!0}}return n?t:void 0}function M(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(),i=n.substring(s+1).trim();if(r&&i){const o=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[o]=i}}}),Object.keys(t).length>0?t:void 0}function q(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return E(e);if(typeof e=="string"){let t=M(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=E(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 i=s.replace(/-([a-z])/g,o=>o[1].toUpperCase());t[i]=r}}}),Object.keys(t).length>0?t:void 0}}}function z(e){return S[e]?S[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function F(e){var s;const t={},n=((s=e.xmlns)==null?void 0:s.includes("svg"))||e.viewBox!==void 0||e.d!==void 0;for(const[r,i]of Object.entries(e))if(r==="style")t.style=q(i);else if(r.startsWith("data-"))t[r]=i;else{const o=z(r);n||J.has(o)||o.startsWith("svg")?t[o]=i:!B.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[`data-${r.toLowerCase()}`]=i:t[o]=i}return t}const B=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"]),J=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"]),S={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"};function G(e,t,n){const[s,r]=h.useState();return{connectDom:h.useCallback(o=>{if(!o)return;const c=Q(e,t,o,n);r(c)},[s]),view:s}}function H(e){const[t,n]=h.useState(0);return h.useEffect(()=>{if(!e)return()=>{};const s=()=>n(c=>c+1),{em:r}=e,o=`${r.Components.events.update}:components`;return e.on(o,s),()=>e.off(o,s)},[e]),t}function Q(e,t,n,s){var c;const{em:r,Components:i}=e;let o=t.getView();if((o==null?void 0:o.el)===n)return o;if(!o){const{ComponentView:l}=i,{draggableComponents:u}=i.config,a=t.attributes.type||"default",d=((c=i.getType(a))==null?void 0:c.view)||l,p={draggableComponents:u,frameView:s,em:r},f=d.extend({initComponents(){},_createElement(){return n},render(){return this._ensureElement(),this._setData(),this.renderAttributes(),this.postRender(),this}});o=new f({el:n,config:p,model:t})}return o.el=n,o.render(),o}function X(e,t){const{Components:n}=e,s=r=>{const{id:i,model:o}=r;n.addType(i,{model:{toJSON(...c){const l=o.prototype.toJSON.apply(this,c);return l.tagName=this.tagName,l}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,i])=>{var o;n.addType(r,{isComponent:c=>(c==null?void 0:c.tagName)===r,model:{defaults:{type:r,traits:i.props?i.props():[],...((o=i.model)==null?void 0:o.defaults)||{}}}})})}function T(e){var b;const{component:t,config:n,editor:s,frameView:r,onMount:i,tagName:o}=e,{connectDom:c,view:l}=G(s,t,r),u=H(t);h.useEffect(()=>{if(!l||!i)return;const C=setTimeout(()=>i(l));return()=>clearTimeout(C)},[l]);const a=t.get("type")||"default",d=t.content,p=(b=n.components)==null?void 0:b[a],f=(p==null?void 0:p.component)||o||t.tagName||"div",k=t.components(),y=k.length?k.map(C=>m.jsx(T,{component:C,config:n,editor:s,frameView:r},C.cid)):d,w=F(t.getAttributes()),v=p==null?void 0:p.editorRender;if(v)return m.jsx(v,{props:w,editor:s,component:t,connectDom:c,children:y});if(p!=null&&p.component)return m.jsx("gjs-wrapper",{ref:c,children:m.jsx(f,{...w,children:y})});if(t.isInstanceOf("textnode"))return d;const _=t.isInstanceOf("text")?u:void 0;return h.createElement(f,{...w,ref:c,key:_},t.get("void")?null:y)}const Y=e=>{var i;const{frame:t,window:n,onMount:s}=e,{root:r}=t;try{(i=n.__reactRoot)==null||i.unmount(),n.__reactRoot=void 0;const o=D.createRoot(n.document.body);o.render(m.jsx(Z,{...e,component:r,onMount:s})),n.__reactRoot=o}catch(o){console.error("Error setting up React renderer",o)}return r.getView()};function Z(e){const{editor:t,component:n,window:s,frameView:r,config:i,onMount:o}=e,c=s.document,l=i.wrapper||h.Fragment,u={editorProps:{doc:c,editor:t,frameView:r}},a=i.wrapper?u:{};return m.jsx(l,{...a,children:m.jsx(T,{tagName:"div",component:n,config:i,editor:t,frameView:r,onMount:o})})}const ee="rendererReact",te=function(e,t={}){e.Canvas.config.customRenderer=n=>Y({...n,config:t}),X(e,t),$({editor:e,licenseKey:t.licenseKey,plan:g.startup,pluginName:ee,cleanup:()=>{e.Canvas.config.customRenderer=void 0}})},ne=K(te);module.exports=ne;
1
+ "use strict";const y=require("react/jsx-runtime"),g=require("react"),I=require("react-dom/client"),j="app.grapesjs.com",U="app-stage.grapesjs.com",N=[j,U,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],W="license:check:start",B="license:check:end",$=()=>typeof window<"u",F=({isDev:e,isStage:t})=>`${e?"":`https://${t?U:j}`}/api`,K=()=>{const e=$()&&window.location.hostname;return!!e&&(N.includes(e)||N.some(t=>e.endsWith(t)))},V=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(t,n)=>(n?"-":"")+t.toLowerCase()),T=e=>typeof e=="string";function z(e){return typeof e=="function"}async function M({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:o}){const c=`${t||F({isDev:!1,isStage:!1})}${e}`,a={method:n,headers:{"Content-Type":"application/json",...s}};o&&(a.body=JSON.stringify(o));const u=r?new URLSearchParams(r).toString():"",l=u?`?${u}`:"",d=await fetch(`${c}${l}`,a);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 q(e){const t=e;return t.init=n=>s=>e(s,n),t}const J=e=>q(e);async function G({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let o="",i=!1;const c=K(),a=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)a(d||"Invalid license");else if(f){const k=P[t],w=P[f];k>w&&a({pluginRequiredPlan:t,licensePlan:f})}};e.on(W,l=>{o=l==null?void 0:l.baseApiUrl,i=!0}),e.on(B,l=>{u(l)}),setTimeout(async()=>{if(!i){if(c)return;if(s){const l=await H({licenseKey:s,pluginName:n,baseApiUrl:o});l&&u(l)}else a("The `licenseKey` option not provided")}},2e3)}async function H(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await M({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 Z(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const s=V(n);t[s]=e[n]}return t}const Q=(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,i=>i[1].toUpperCase()):s;t[o]=r,n=!0}}return n?t:void 0}function X(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 i=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[i]=o}}}),Object.keys(t).length>0?t:void 0}function Y(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return O(e);if(typeof e=="string"){let t=X(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,i=>i[1].toUpperCase());t[o]=r}}}),Object.keys(t).length>0?t:void 0}}}function ee(e){return L[e]?L[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function te(e){var n;const t={};for(const[s,r]of Object.entries(e))if(s==="style")t.style=Y(r);else if(s.startsWith("data-"))t[s]=r;else{const o=ee(s);((n=e.xmlns)==null?void 0:n.includes("svg"))||e.viewBox!==void 0||e.d!==void 0||oe.has(o)||o.startsWith("svg")?t[o]=r:!ne.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=r:t[o]=r}return t}const ne=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"]),oe=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"]),L={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"},E=e=>(e==null?void 0:e.$$typeof)&&typeof e.props=="object";function se(e){return t=>{const n=t.getContent();E(n)&&t.set({content:b({...e,model:n}),reactContent:n})}}const re=e=>t=>{const n=t.component;E(n)&&(t.component={components:b({...e,model:n})})};function b(e){const{model:t,editor:n,config:s}=e;if(E(t)){const r=t,o={},{type:i,props:c={}}=r,{children:a,className:u,style:l,...d}=c,m=p=>({type:"textnode",content:p}),f=typeof i=="symbol";if(z(i)){const p=Q(s,i);o.type=p==null?void 0:p.type}else n.Components.getType(i)?o.type=i:f||(o.tagName=i);if(u&&(o.classes=u),l&&(o.style=Z(l)),Array.isArray(a)?o.components=a.map(p=>T(p)?m(p):b({...e,model:p})).filter(Boolean):T(a)&&(o.components=m(a)),Object.keys(d).length){const p=n.Parser.parserHtml.splitPropsFromAttr(d);o.attributes=p.attrs,Object.assign(o,p.props)}return o}}function ce(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),a=()=>{[...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,a),()=>{t.off(m,c),t.off(f,a),a()}},[t]),{key:n,view:r,connectDom:c=>{if(!c)return;const a=ie({...e,el:c});o(a)}}}function ie(e){var a;const{editor:t,component:n,el:s,frameView:r}=e,{em:o,Components:i}=t;let c=n.getView(r.model);if((c==null?void 0:c.el)===s)return c;if(!c){const{ComponentView:u}=i,l=n.attributes.type||"default",d=((a=i.getType(l))==null?void 0:a.view)||u,m={...i.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 ae(e,t){const{Components:n}=e,s=r=>{const{id:o,model:i}=r;n.addType(o,{model:{toJSON(...c){const a=i.prototype.toJSON.apply(this,c);return a.tagName=this.tagName,a}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,o])=>{var m,f;const{allowPropClassName:i,allowPropId:c,allowChildren:a}=o,u=!c&&!i,l=()=>({disabled:u}),d=()=>({disableClasses:!i,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:!!a,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:i,children:c}=e,{key:a,view:u,connectDom:l}=ce(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)||i||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=te(t.getAttributes()),A=f==null?void 0:f.editorRender,S=[...k,c].filter(v=>v??!1),R=S.length?S:null;if(A)return y.jsx(A,{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 D=t.isInstanceOf("text")?a:void 0;return g.createElement(p,{...w,ref:l,key:D},t.get("void")?null:R)}const le=e=>{const{frame:t,window:n,onMount:s,editor:r}=e,o=r.Canvas.events,{root:i}=t;try{const c=I.createRoot(n.document.body);c.render(y.jsx(pe,{...e,component:i,onMount:s}));const a=()=>c.unmount();t.once(o.frameUnload,a),n.addEventListener("unload",a)}catch(c){console.warn(c)}return i.getView()};function pe(e){const{editor:t,component:n,window:s,frameView:r,config:o,onMount:i}=e,c=s.document,a=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(a,{...u,children:y.jsx(_,{tagName:"div",component:n,config:o,editor:t,frameView:r,onMount:i,children:y.jsx(l,{...u})})})}const ue="rendererReact",fe=C.startup,de=function(e,t={}){const{Blocks:n,Pages:s}=e,r=n.events,o=s.events;e.Canvas.config.customRenderer=c=>le({...c,config:t}),e.Components.config.processor=c=>b({model:c,editor:e,config:t}),ae(e,t);const i=[[r.add,se({editor:e,config:t})],[o.addBefore,re({editor:e,config:t})]];i.forEach(([c,a])=>e.on(c,a)),G({editor:e,licenseKey:t.licenseKey,plan:fe,pluginName:ue,cleanup:()=>{e.Canvas.config.customRenderer=void 0,e.Components.config.processor=void 0,i.forEach(([c,a])=>e.off(c,a))}})},me=J(de);module.exports=me;
@@ -1,3 +1,4 @@
1
- import { ReactRendererPluginOptions } from './types';
2
- declare const _default: import('../utils').PluginWithInit<ReactRendererPluginOptions>;
1
+ import { RendererReactOptions } from './types';
2
+ export type * from './types';
3
+ declare const _default: import('../utils').PluginWithInit<RendererReactOptions>;
3
4
  export default _default;
@@ -1,3 +1,4 @@
1
- import { ReactRendererPluginOptions } from './types';
2
- declare const _default: import('../utils').PluginWithInit<ReactRendererPluginOptions>;
1
+ import { RendererReactOptions } from './types';
2
+ export type * from './types';
3
+ declare const _default: import('../utils').PluginWithInit<RendererReactOptions>;
3
4
  export default _default;
@@ -1,9 +1,9 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import { useState as A, useCallback as L, useEffect as x, createElement as O, Fragment as U } from "react";
3
- import { createRoot as W } from "react-dom/client";
4
- const N = "app.grapesjs.com", T = "app-stage.grapesjs.com", b = [
5
- N,
6
- T,
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import { useState as N, useEffect as _, createElement as $, Fragment as T } from "react";
3
+ import { createRoot as j } from "react-dom/client";
4
+ const D = "app.grapesjs.com", I = "app-stage.grapesjs.com", x = [
5
+ D,
6
+ I,
7
7
  "localhost",
8
8
  "127.0.0.1",
9
9
  ".local-credentialless.webcontainer.io",
@@ -12,82 +12,85 @@ const N = "app.grapesjs.com", T = "app-stage.grapesjs.com", b = [
12
12
  // For stackblitz.com demos
13
13
  "-sandpack.codesandbox.io"
14
14
  // For Sandpack demos
15
- ], P = "license:check:start", I = "license:check:end", K = () => typeof window < "u", j = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? T : N}`}/api`, $ = () => {
16
- const e = K() && window.location.hostname;
17
- return !!e && (b.includes(e) || b.some((t) => e.endsWith(t)));
18
- };
19
- async function V({
15
+ ], K = "license:check:start", F = "license:check:end", V = () => typeof window < "u", z = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? I : D}`}/api`, M = () => {
16
+ const e = V() && window.location.hostname;
17
+ return !!e && (x.includes(e) || x.some((t) => e.endsWith(t)));
18
+ }, J = (e) => e.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (t, n) => (n ? "-" : "") + t.toLowerCase()), P = (e) => typeof e == "string";
19
+ function q(e) {
20
+ return typeof e == "function";
21
+ }
22
+ async function G({
20
23
  path: e,
21
24
  baseApiUrl: t,
22
25
  method: n = "GET",
23
26
  headers: s = {},
24
27
  params: r,
25
- body: i
28
+ body: o
26
29
  }) {
27
- const c = `${t || j({ isDev: !1, isStage: !1 })}${e}`, l = {
30
+ const c = `${t || z({ isDev: !1, isStage: !1 })}${e}`, a = {
28
31
  method: n,
29
32
  headers: {
30
33
  "Content-Type": "application/json",
31
34
  ...s
32
35
  }
33
36
  };
34
- i && (l.body = JSON.stringify(i));
35
- const u = r ? new URLSearchParams(r).toString() : "", a = u ? `?${u}` : "", d = await fetch(`${c}${a}`, l);
37
+ o && (a.body = JSON.stringify(o));
38
+ const f = r ? new URLSearchParams(r).toString() : "", l = f ? `?${f}` : "", d = await fetch(`${c}${l}`, a);
36
39
  if (!d.ok)
37
40
  throw new Error(`HTTP error! status: ${d.status}`);
38
41
  return d.json();
39
42
  }
40
- var y = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(y || {});
41
- const R = {
42
- [y.free]: 0,
43
- [y.startup]: 10,
44
- [y.business]: 20,
45
- [y.enterprise]: 30
43
+ var v = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(v || {});
44
+ const O = {
45
+ [v.free]: 0,
46
+ [v.startup]: 10,
47
+ [v.business]: 20,
48
+ [v.enterprise]: 30
46
49
  };
47
- function M(e) {
50
+ function H(e) {
48
51
  const t = e;
49
52
  return t.init = (n) => (s) => e(s, n), t;
50
53
  }
51
- const z = (e) => /* @__PURE__ */ M(e);
52
- async function F({
54
+ const Z = (e) => /* @__PURE__ */ H(e);
55
+ async function Q({
53
56
  editor: e,
54
57
  plan: t,
55
58
  pluginName: n,
56
59
  licenseKey: s,
57
60
  cleanup: r
58
61
  }) {
59
- let i = "", o = !1;
60
- const c = $(), l = (a) => {
61
- console.warn("Cleanup plugin:", n, "Reason:", a), r();
62
- }, u = (a = {}) => {
62
+ let o = "", i = !1;
63
+ const c = M(), a = (l) => {
64
+ console.warn("Cleanup plugin:", n, "Reason:", l), r();
65
+ }, f = (l = {}) => {
63
66
  var h;
64
- const { error: d, sdkLicense: p } = a, f = (h = a.plan) == null ? void 0 : h.category;
65
- if (!(p || a.license) || d)
66
- l(d || "Invalid license");
67
- else if (f) {
68
- const g = R[t], w = R[f];
69
- g > w && l({ pluginRequiredPlan: t, licensePlan: f });
67
+ const { error: d, sdkLicense: m } = l, u = (h = l.plan) == null ? void 0 : h.category;
68
+ if (!(m || l.license) || d)
69
+ a(d || "Invalid license");
70
+ else if (u) {
71
+ const b = O[t], C = O[u];
72
+ b > C && a({ pluginRequiredPlan: t, licensePlan: u });
70
73
  }
71
74
  };
72
- e.on(P, (a) => {
73
- i = a == null ? void 0 : a.baseApiUrl, o = !0;
74
- }), e.on(I, (a) => {
75
- u(a);
75
+ e.on(K, (l) => {
76
+ o = l == null ? void 0 : l.baseApiUrl, i = !0;
77
+ }), e.on(F, (l) => {
78
+ f(l);
76
79
  }), setTimeout(async () => {
77
- if (!o) {
80
+ if (!i) {
78
81
  if (c) return;
79
82
  if (s) {
80
- const a = await B({ licenseKey: s, pluginName: n, baseApiUrl: i });
81
- a && u(a);
83
+ const l = await X({ licenseKey: s, pluginName: n, baseApiUrl: o });
84
+ l && f(l);
82
85
  } else
83
- l("The `licenseKey` option not provided");
86
+ a("The `licenseKey` option not provided");
84
87
  }
85
88
  }, 2e3);
86
89
  }
87
- async function B(e) {
90
+ async function X(e) {
88
91
  const { licenseKey: t, pluginName: n, baseApiUrl: s } = e;
89
92
  try {
90
- return (await V({
93
+ return (await G({
91
94
  baseApiUrl: s,
92
95
  path: `/sdk/${t || "na"}`,
93
96
  method: "POST",
@@ -100,43 +103,60 @@ async function B(e) {
100
103
  return console.error("Error during SDK license check:", r), !1;
101
104
  }
102
105
  }
103
- function E(e) {
106
+ function Y(e) {
107
+ const t = {};
108
+ for (const n in e)
109
+ if (Object.prototype.hasOwnProperty.call(e, n)) {
110
+ const s = J(n);
111
+ t[s] = e[n];
112
+ }
113
+ return t;
114
+ }
115
+ const ee = (e, t) => {
116
+ const n = e.components || {};
117
+ for (const s in n) {
118
+ const r = n[s];
119
+ if (r.component === t)
120
+ return { cmpConfig: r, type: s };
121
+ }
122
+ };
123
+ function L(e) {
104
124
  const t = {};
105
125
  let n = !1;
106
126
  for (const s in e)
107
127
  if (Object.prototype.hasOwnProperty.call(e, s)) {
108
128
  const r = e[s];
109
129
  if (typeof r == "string" || typeof r == "number") {
110
- const i = s.includes("-") ? s.replace(/-([a-z])/g, (o) => o[1].toUpperCase()) : s;
111
- t[i] = r, n = !0;
130
+ const o = s.includes("-") ? s.replace(/-([a-z])/g, (i) => i[1].toUpperCase()) : s;
131
+ t[o] = r, n = !0;
112
132
  }
113
133
  }
114
134
  return n ? t : void 0;
115
135
  }
116
- function J(e) {
136
+ function te(e) {
117
137
  const t = {};
118
138
  return e.split(";").forEach((n) => {
119
139
  if (!n.trim()) return;
120
140
  const s = n.indexOf(":");
121
141
  if (s > 0) {
122
- const r = n.substring(0, s).trim(), i = n.substring(s + 1).trim();
123
- if (r && i) {
124
- const o = r.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
125
- t[o] = i;
142
+ const r = n.substring(0, s).trim(), o = n.substring(s + 1).trim();
143
+ if (r && o) {
144
+ const i = r.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
145
+ t[i] = o;
126
146
  }
127
147
  }
128
148
  }), Object.keys(t).length > 0 ? t : void 0;
129
149
  }
130
- function q(e) {
150
+ function ne(e) {
131
151
  if (e) {
132
152
  if (typeof e == "object" && !Array.isArray(e))
133
- return E(e);
153
+ return L(e);
134
154
  if (typeof e == "string") {
135
- let t = J(e);
155
+ let t = te(e);
136
156
  if (!t)
137
157
  try {
138
158
  const n = JSON.parse(e);
139
- typeof n == "object" && n !== null && !Array.isArray(n) && (t = E(n));
159
+ typeof n == "object" && n !== null && !Array.isArray(n) && (t = L(n));
140
160
  } catch (n) {
141
161
  console.error("Failed to parse style string as JSON", n);
142
162
  }
@@ -148,32 +168,32 @@ function q(e) {
148
168
  if (typeof n == "object" && n !== null) {
149
169
  const s = n.name || n.property, r = n.value;
150
170
  if (typeof s == "string" && s && r !== void 0 && r !== "") {
151
- const i = s.replace(/-([a-z])/g, (o) => o[1].toUpperCase());
152
- t[i] = r;
171
+ const o = s.replace(/-([a-z])/g, (i) => i[1].toUpperCase());
172
+ t[o] = r;
153
173
  }
154
174
  }
155
175
  }), Object.keys(t).length > 0 ? t : void 0;
156
176
  }
157
177
  }
158
178
  }
159
- function G(e) {
160
- return S[e] ? S[e] : e.includes("-") ? e.replace(/-([a-z])/g, (t, n) => n.toUpperCase()) : e;
179
+ function oe(e) {
180
+ return U[e] ? U[e] : e.includes("-") ? e.replace(/-([a-z])/g, (t, n) => n.toUpperCase()) : e;
161
181
  }
162
- function H(e) {
163
- var s;
164
- const t = {}, n = ((s = e.xmlns) == null ? void 0 : s.includes("svg")) || e.viewBox !== void 0 || e.d !== void 0;
165
- for (const [r, i] of Object.entries(e))
166
- if (r === "style")
167
- t.style = q(i);
168
- else if (r.startsWith("data-"))
169
- t[r] = i;
182
+ function se(e) {
183
+ var n;
184
+ const t = {};
185
+ for (const [s, r] of Object.entries(e))
186
+ if (s === "style")
187
+ t.style = ne(r);
188
+ else if (s.startsWith("data-"))
189
+ t[s] = r;
170
190
  else {
171
- const o = G(r);
172
- n || X.has(o) || o.startsWith("svg") ? t[o] = i : !Q.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[`data-${r.toLowerCase()}`] = i : t[o] = i;
191
+ const o = oe(s);
192
+ ((n = e.xmlns) == null ? void 0 : n.includes("svg")) || e.viewBox !== void 0 || e.d !== void 0 || ce.has(o) || o.startsWith("svg") ? t[o] = r : !re.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[s] = r : t[o] = r;
173
193
  }
174
194
  return t;
175
195
  }
176
- const Q = /* @__PURE__ */ new Set([
196
+ const re = /* @__PURE__ */ new Set([
177
197
  "className",
178
198
  "id",
179
199
  "style",
@@ -214,7 +234,7 @@ const Q = /* @__PURE__ */ new Set([
214
234
  "aria-labelledby",
215
235
  "aria-describedby",
216
236
  "role"
217
- ]), X = /* @__PURE__ */ new Set([
237
+ ]), ce = /* @__PURE__ */ new Set([
218
238
  "x",
219
239
  "y",
220
240
  "d",
@@ -257,7 +277,7 @@ const Q = /* @__PURE__ */ new Set([
257
277
  "clipPath",
258
278
  "overflow",
259
279
  "pointerEvents"
260
- ]), S = {
280
+ ]), U = {
261
281
  class: "className",
262
282
  for: "htmlFor",
263
283
  "http-equiv": "httpEquiv",
@@ -274,132 +294,178 @@ const Q = /* @__PURE__ */ new Set([
274
294
  "font-family": "fontFamily",
275
295
  "font-size": "fontSize",
276
296
  "text-anchor": "textAnchor"
277
- };
278
- function Y(e, t, n) {
279
- const [s, r] = A();
280
- return {
281
- connectDom: L(
282
- (o) => {
283
- if (!o) return;
284
- const c = ee(e, t, o, n);
285
- r(c);
286
- },
287
- [s]
288
- ),
289
- view: s
297
+ }, R = (e) => (e == null ? void 0 : e.$$typeof) && typeof e.props == "object";
298
+ function ie(e) {
299
+ return (t) => {
300
+ const n = t.getContent();
301
+ R(n) && t.set({
302
+ content: w({ ...e, model: n }),
303
+ reactContent: n
304
+ });
290
305
  };
291
306
  }
292
- function Z(e) {
293
- const [t, n] = A(0);
294
- return x(() => {
295
- if (!e) return () => {
307
+ const ae = (e) => (t) => {
308
+ const n = t.component;
309
+ R(n) && (t.component = { components: w({ ...e, model: n }) });
310
+ };
311
+ function w(e) {
312
+ const { model: t, editor: n, config: s } = e;
313
+ if (R(t)) {
314
+ const r = t, o = {}, { type: i, props: c = {} } = r, { children: a, className: f, style: l, ...d } = c, m = (p) => ({ type: "textnode", content: p }), u = typeof i == "symbol";
315
+ if (q(i)) {
316
+ const p = ee(s, i);
317
+ o.type = p == null ? void 0 : p.type;
318
+ } else n.Components.getType(i) ? o.type = i : u || (o.tagName = i);
319
+ if (f && (o.classes = f), l && (o.style = Y(l)), Array.isArray(a) ? o.components = a.map((p) => P(p) ? m(p) : w({ ...e, model: p })).filter(Boolean) : P(a) && (o.components = m(a)), Object.keys(d).length) {
320
+ const p = n.Parser.parserHtml.splitPropsFromAttr(d);
321
+ o.attributes = p.attrs, Object.assign(o, p.props);
322
+ }
323
+ return o;
324
+ }
325
+ }
326
+ function le(e) {
327
+ const { component: t } = e, [n, s] = N(0), [r, o] = N();
328
+ return _(() => {
329
+ if (!t) return () => {
296
330
  };
297
- const s = () => n((c) => c + 1), { em: r } = e, o = `${r.Components.events.update}:components`;
298
- return e.on(o, s), () => e.off(o, s);
299
- }, [e]), t;
331
+ const c = () => s((p) => p + 1), a = () => {
332
+ [...t.views].forEach((h) => h.remove()), o(void 0);
333
+ }, { em: f } = t, l = f.Components.events, m = [...["components", "attributes", "classes"].map((p) => `${l.update}:${p}`), "rerender"].join(" "), u = [l.removed, "rerender"].join(" ");
334
+ return t.on(m, c), t.on(u, a), () => {
335
+ t.off(m, c), t.off(u, a), a();
336
+ };
337
+ }, [t]), { key: n, view: r, connectDom: (c) => {
338
+ if (!c) return;
339
+ const a = pe({ ...e, el: c });
340
+ o(a);
341
+ } };
300
342
  }
301
- function ee(e, t, n, s) {
302
- var c;
303
- const { em: r, Components: i } = e;
304
- let o = t.getView();
305
- if ((o == null ? void 0 : o.el) === n)
306
- return o;
307
- if (!o) {
308
- const { ComponentView: l } = i, { draggableComponents: u } = i.config, a = t.attributes.type || "default", d = ((c = i.getType(a)) == null ? void 0 : c.view) || l, p = { draggableComponents: u, frameView: s, em: r }, f = d.extend({
343
+ function pe(e) {
344
+ var a;
345
+ const { editor: t, component: n, el: s, frameView: r } = e, { em: o, Components: i } = t;
346
+ let c = n.getView(r.model);
347
+ if ((c == null ? void 0 : c.el) === s)
348
+ return c;
349
+ if (!c) {
350
+ const { ComponentView: f } = i, l = n.attributes.type || "default", d = ((a = i.getType(l)) == null ? void 0 : a.view) || f, m = { ...i.config, frameView: r, em: o }, u = d.extend({
309
351
  initComponents() {
310
352
  },
311
353
  _createElement() {
312
- return n;
354
+ return s;
355
+ },
356
+ _removeElement() {
357
+ },
358
+ __clearAttributes() {
313
359
  },
314
360
  render() {
315
- return this._ensureElement(), this._setData(), this.renderAttributes(), this.postRender(), this;
361
+ var p;
362
+ return this._ensureElement(), this._setData(), this.renderAttributes(), (p = this.updateSrc) == null || p.call(this), this;
316
363
  }
317
364
  });
318
- o = new f({ el: n, config: p, model: t });
365
+ c = new u({ el: s, config: m, model: n });
319
366
  }
320
- return o.el = n, o.render(), o;
367
+ return c.el = s, c.render(), c;
321
368
  }
322
- function te(e, t) {
369
+ function fe(e, t) {
323
370
  const { Components: n } = e, s = (r) => {
324
- const { id: i, model: o } = r;
325
- n.addType(i, {
371
+ const { id: o, model: i } = r;
372
+ n.addType(o, {
326
373
  model: {
327
374
  toJSON(...c) {
328
- const l = o.prototype.toJSON.apply(this, c);
329
- return l.tagName = this.tagName, l;
375
+ const a = i.prototype.toJSON.apply(this, c);
376
+ return a.tagName = this.tagName, a;
330
377
  }
331
378
  }
332
379
  });
333
380
  };
334
- n.getTypes().forEach(s), e.on("component:type:add", s), Object.entries(t.components || {}).forEach(([r, i]) => {
335
- var o;
381
+ n.getTypes().forEach(s), e.on("component:type:add", s), Object.entries(t.components || {}).forEach(([r, o]) => {
382
+ var m, u;
383
+ const { allowPropClassName: i, allowPropId: c, allowChildren: a } = o, f = !c && !i, l = () => ({
384
+ disabled: f
385
+ }), d = () => ({
386
+ disableClasses: !i,
387
+ disableComponent: !c
388
+ });
336
389
  n.addType(r, {
337
- isComponent: (c) => (c == null ? void 0 : c.tagName) === r,
390
+ isComponent: (p) => (p == null ? void 0 : p.tagName) === r,
338
391
  model: {
339
392
  defaults: {
340
393
  type: r,
341
- traits: i.props ? i.props() : [],
342
- ...((o = i.model) == null ? void 0 : o.defaults) || {}
394
+ traits: ((m = o.props) == null ? void 0 : m.call(o)) || [],
395
+ droppable: !!a,
396
+ stylable: !f,
397
+ styleManager: l,
398
+ selectorManager: d,
399
+ ...((u = o.model) == null ? void 0 : u.defaults) || {}
343
400
  }
344
401
  }
345
402
  });
346
403
  });
347
404
  }
348
- function _(e) {
349
- var k;
350
- const { component: t, config: n, editor: s, frameView: r, onMount: i, tagName: o } = e, { connectDom: c, view: l } = Y(s, t, r), u = Z(t);
351
- x(() => {
352
- if (!l || !i) return;
353
- const v = setTimeout(() => i(l));
354
- return () => clearTimeout(v);
355
- }, [l]);
356
- const a = t.get("type") || "default", d = t.content, p = (k = n.components) == null ? void 0 : k[a], f = (p == null ? void 0 : p.component) || o || t.tagName || "div", C = t.components(), h = C.length ? C.map((v) => /* @__PURE__ */ m(_, { component: v, config: n, editor: s, frameView: r }, v.cid)) : d, g = H(t.getAttributes()), w = p == null ? void 0 : p.editorRender;
357
- if (w)
358
- return /* @__PURE__ */ m(w, { props: g, editor: s, component: t, connectDom: c, children: h });
359
- if (p != null && p.component)
360
- return /* @__PURE__ */ m("gjs-wrapper", { ref: c, children: /* @__PURE__ */ m(f, { ...g, children: h }) });
405
+ function W(e) {
406
+ var S;
407
+ const { component: t, config: n, editor: s, frameView: r, onMount: o, tagName: i, children: c } = e, { key: a, view: f, connectDom: l } = le(e);
408
+ _(() => {
409
+ if (!f && !o) return;
410
+ const g = setTimeout(() => {
411
+ f && (o == null || o(f), setTimeout(() => f.postRender()));
412
+ });
413
+ return () => clearTimeout(g);
414
+ }, [f]);
415
+ 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) || i || 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 = se(t.getAttributes()), E = u == null ? void 0 : u.editorRender, A = [...b, c].filter((g) => g ?? !1), k = A.length ? A : null;
416
+ if (E)
417
+ return /* @__PURE__ */ y(E, { props: C, editor: s, component: t, connectDom: l, children: k });
418
+ if (u != null && u.component)
419
+ return /* @__PURE__ */ y("gjs-wrapper", { ref: l, style: u.wrapperStyle, children: /* @__PURE__ */ y(p, { ...C, children: k }) });
361
420
  if (t.isInstanceOf("textnode"))
362
- return d;
363
- const D = t.isInstanceOf("text") ? u : void 0;
364
- return /* @__PURE__ */ O(f, { ...g, ref: c, key: D }, t.get("void") ? null : h);
421
+ return m;
422
+ const B = t.isInstanceOf("text") ? a : void 0;
423
+ return /* @__PURE__ */ $(p, { ...C, ref: l, key: B }, t.get("void") ? null : k);
365
424
  }
366
- const ne = (e) => {
367
- var i;
368
- const { frame: t, window: n, onMount: s } = e, { root: r } = t;
425
+ const ue = (e) => {
426
+ const { frame: t, window: n, onMount: s, editor: r } = e, o = r.Canvas.events, { root: i } = t;
369
427
  try {
370
- (i = n.__reactRoot) == null || i.unmount(), n.__reactRoot = void 0;
371
- const o = W(n.document.body);
372
- o.render(/* @__PURE__ */ m(oe, { ...e, component: r, onMount: s })), n.__reactRoot = o;
373
- } catch (o) {
374
- console.error("Error setting up React renderer", o);
428
+ const c = j(n.document.body);
429
+ c.render(/* @__PURE__ */ y(de, { ...e, component: i, onMount: s }));
430
+ const a = () => c.unmount();
431
+ t.once(o.frameUnload, a), n.addEventListener("unload", a);
432
+ } catch (c) {
433
+ console.warn(c);
375
434
  }
376
- return r.getView();
435
+ return i.getView();
377
436
  };
378
- function oe(e) {
379
- const { editor: t, component: n, window: s, frameView: r, config: i, onMount: o } = e, c = s.document, l = i.wrapper || U, u = { editorProps: { doc: c, editor: t, frameView: r } }, a = i.wrapper ? u : {};
380
- return /* @__PURE__ */ m(l, { ...a, children: /* @__PURE__ */ m(
381
- _,
437
+ function de(e) {
438
+ const { editor: t, component: n, window: s, frameView: r, config: o, onMount: i } = e, c = s.document, a = o.rootComponent || T, f = o.rootComponent ? { editorProps: { doc: c, editor: t, frameView: r } } : {}, l = (o == null ? void 0 : o.bodyAfter) || T;
439
+ return /* @__PURE__ */ y(a, { ...f, children: /* @__PURE__ */ y(
440
+ W,
382
441
  {
383
442
  tagName: "div",
384
443
  component: n,
385
- config: i,
444
+ config: o,
386
445
  editor: t,
387
446
  frameView: r,
388
- onMount: o
447
+ onMount: i,
448
+ children: /* @__PURE__ */ y(l, { ...f })
389
449
  }
390
450
  ) });
391
451
  }
392
- const se = "rendererReact", re = function(e, t = {}) {
393
- e.Canvas.config.customRenderer = (n) => ne({ ...n, config: t }), te(e, t), F({
452
+ const me = "rendererReact", ye = v.startup, he = function(e, t = {}) {
453
+ const { Blocks: n, Pages: s } = e, r = n.events, o = s.events;
454
+ e.Canvas.config.customRenderer = (c) => ue({ ...c, config: t }), e.Components.config.processor = (c) => w({ model: c, editor: e, config: t }), fe(e, t);
455
+ const i = [
456
+ [r.add, ie({ editor: e, config: t })],
457
+ [o.addBefore, ae({ editor: e, config: t })]
458
+ ];
459
+ i.forEach(([c, a]) => e.on(c, a)), Q({
394
460
  editor: e,
395
461
  licenseKey: t.licenseKey,
396
- plan: y.startup,
397
- pluginName: se,
462
+ plan: ye,
463
+ pluginName: me,
398
464
  cleanup: () => {
399
- e.Canvas.config.customRenderer = void 0;
465
+ e.Canvas.config.customRenderer = void 0, e.Components.config.processor = void 0, i.forEach(([c, a]) => e.off(c, a));
400
466
  }
401
467
  });
402
- }, le = z(re);
468
+ }, we = Z(he);
403
469
  export {
404
- le as default
470
+ we as default
405
471
  };