@grapesjs/studio-sdk-plugins 1.0.16 → 1.0.17

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.
@@ -1,5 +1,9 @@
1
- "use strict";function j(e,a,n){let t,o,c,p,d;const r=a;function u(){const l=Date.now()-p;l<r&&l>=0?t=setTimeout(u,r-l):(t=null,d=e.apply(c,o),c=o=null)}const s=function(){return c=this,o=arguments,p=Date.now(),t||(t=setTimeout(u,r)),d};return s.clear=function(){t&&(clearTimeout(t),t=null)},s.flush=function(){t&&(d=e.apply(c,o),c=o=null,clearTimeout(t),t=null)},s}const R="app.grapesjs.com",U="app-stage.grapesjs.com",k=[R,U,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],K="license:check:start",F="license:check:end",q=()=>typeof window<"u",V=({isDev:e,isStage:a})=>`${e?"":`https://${a?U:R}`}/api`,X=()=>{const e=q()&&window.location.hostname;return!!e&&(k.includes(e)||k.some(a=>e.endsWith(a)))};async function Y({path:e,baseApiUrl:a,method:n="GET",headers:t={},params:o,body:c}){const d=`${a||V({isDev:!1,isStage:!1})}${e}`,r={method:n,headers:{"Content-Type":"application/json",...t}};c&&(r.body=JSON.stringify(c));const u=o?new URLSearchParams(o).toString():"",s=u?`?${u}`:"",l=await fetch(`${d}${s}`,r);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var b=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(b||{});const z={[b.free]:0,[b.startup]:10,[b.business]:20,[b.enterprise]:30};function B(e){const a=e;return a.init=n=>t=>e(t,n),a}const G=e=>B(e);async function Z({editor:e,plan:a,pluginName:n,licenseKey:t,cleanup:o}){let c="",p=!1;const d=X(),r=s=>{console.warn("Cleanup plugin:",n,"Reason:",s),o()},u=(s={})=>{var C;const{error:l,sdkLicense:D}=s,y=(C=s.plan)==null?void 0:C.category;if(!(D||s.license)||l)r(l||"Invalid license");else if(y){const S=z[a],T=z[y];S>T&&r({pluginRequiredPlan:a,licensePlan:y})}};e.on(K,s=>{c=s==null?void 0:s.baseApiUrl,p=!0}),e.on(F,s=>{u(s)}),setTimeout(async()=>{if(!p){if(d)return;if(t){const s=await J({licenseKey:t,pluginName:n,baseApiUrl:c});s&&u(s)}else r("The `licenseKey` option not provided")}},2e3)}async function J(e){const{licenseKey:a,pluginName:n,baseApiUrl:t}=e;try{return(await Y({baseApiUrl:t,path:`/sdk/${a||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const N="canvasFullSize",Q=function(e,a={}){const{Canvas:n,Commands:t,Devices:o}=e,c={deviceMaxWidth:1200,deviceMinHeigth:500,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,frameBorderRadius:5,frameTransition:.3,...a},{canvasOffsetY:p,canvasOffsetX:d,canvasTransition:r,deviceMaxWidth:u,deviceMinHeigth:s,frameBorderRadius:l,frameTransition:D}=c,y=`${s}px`,E=n.events,C=`${t.events.stopCommand}core:preview`,S=n.getConfig(),T=`${N}:disable`,P=o.getAll().map(i=>({...i.attributes}));S.scrollableCanvas=!0,o.getAll().map(i=>{!i.get("width")&&i.set("width",`${u}px`),!i.get("height")&&i.set("height","auto"),!i.get("minHeight")&&i.set("minHeight",y)});const L=i=>{const v="data-gs-plg-full-size",f=document.querySelector(`style[${v}]`);if(i&&f)return f.remove();const m=f||document.createElement("style"),h=n.getZoomMultiplier();m.setAttribute(v,"true"),m.innerHTML=`
1
+ "use strict";function F(e,a,n){let t,o,c,p,m;const r=a;function u(){const l=Date.now()-p;l<r&&l>=0?t=setTimeout(u,r-l):(t=null,m=e.apply(c,o),c=o=null)}const s=function(){return c=this,o=arguments,p=Date.now(),t||(t=setTimeout(u,r)),m};return s.clear=function(){t&&(clearTimeout(t),t=null)},s.flush=function(){t&&(m=e.apply(c,o),c=o=null,clearTimeout(t),t=null)},s}const R="app.grapesjs.com",U="app-stage.grapesjs.com",z=[R,U,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],q="license:check:start",V="license:check:end",X=()=>typeof window<"u",Y=({isDev:e,isStage:a})=>`${e?"":`https://${a?U:R}`}/api`,B=()=>{const e=X()&&window.location.hostname;return!!e&&(z.includes(e)||z.some(a=>e.endsWith(a)))};async function G({path:e,baseApiUrl:a,method:n="GET",headers:t={},params:o,body:c}){const m=`${a||Y({isDev:!1,isStage:!1})}${e}`,r={method:n,headers:{"Content-Type":"application/json",...t}};c&&(r.body=JSON.stringify(c));const u=o?new URLSearchParams(o).toString():"",s=u?`?${u}`:"",l=await fetch(`${m}${s}`,r);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var b=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(b||{});const N={[b.free]:0,[b.startup]:10,[b.business]:20,[b.enterprise]:30};function Z(e){const a=e;return a.init=n=>t=>e(t,n),a}const J=e=>Z(e);async function Q({editor:e,plan:a,pluginName:n,licenseKey:t,cleanup:o}){let c="",p=!1;const m=B(),r=s=>{console.warn("Cleanup plugin:",n,"Reason:",s),o()},u=(s={})=>{var C;const{error:l,sdkLicense:D}=s,v=(C=s.plan)==null?void 0:C.category;if(!(D||s.license)||l)r(l||"Invalid license");else if(v){const E=N[a],S=N[v];E>S&&r({pluginRequiredPlan:a,licensePlan:v})}};e.on(q,s=>{c=s==null?void 0:s.baseApiUrl,p=!0}),e.on(V,s=>{u(s)}),setTimeout(async()=>{if(!p){if(m)return;if(t){const s=await ee({licenseKey:t,pluginName:n,baseApiUrl:c});s&&u(s)}else r("The `licenseKey` option not provided")}},2e3)}async function ee(e){const{licenseKey:a,pluginName:n,baseApiUrl:t}=e;try{return(await G({baseApiUrl:t,path:`/sdk/${a||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const P="canvasFullSize",te=function(e,a={}){const{Canvas:n,Commands:t,Devices:o}=e,c={deviceMaxWidth:1200,deviceMinHeigth:500,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,frameBorderRadius:5,frameTransition:.3,...a},{canvasOffsetY:p,canvasOffsetX:m,canvasTransition:r,deviceMaxWidth:u,deviceMinHeigth:s,frameBorderRadius:l,frameTransition:D}=c,v=`${s}px`,$=n.events,C="core:preview",E=`${t.events.stopCommand}${C}`,S=n.getConfig(),A=`${P}:disable`,_=o.getAll().map(i=>({...i.attributes}));S.scrollableCanvas=!0,o.getAll().map(i=>{!i.get("width")&&i.set("width",`${u}px`),!i.get("height")&&i.set("height","auto"),!i.get("minHeight")&&i.set("minHeight",v)});const L=i=>{const w="data-gs-plg-full-size",d=document.querySelector(`style[${w}]`);if(i&&d)return d.remove();const f=d||document.createElement("style"),h=n.getZoomMultiplier();f.setAttribute(w,"true"),f.innerHTML=`
2
2
  .gjs-frame-wrapper { transition: width ${D}s !important; }
3
3
  .gjs-frame-wrapper__bottom { height: ${p*h}px }
4
4
  .gjs-frame { border-radius: ${l}px }
5
- `,!f&&document.body.appendChild(m)};e.on(E.frameLoadHead,i=>{if(!S.scrollableCanvas)return;const{window:v}=i,f=v.document,m=f.head,h="data-gs-plg-wrapper-style",w=m.querySelector(`style[${h}]`)||f.createElement("style");w.setAttribute(h,"true"),w.innerHTML=`[data-gjs-type="wrapper"] { min-height: ${y}; }`,!m.contains(w)&&m.appendChild(w)}),e.onReady(()=>{const i=n.getSpotsEl(),v=n.getElement(),f=n.getFramesEl(),m=r*1e3,h=v.style;h.overflowX="hidden",f.style.transition=`transform ${r}s`;const w={x:d,y:p};L();const A=()=>i.style.display="none",_=()=>i.style.display="",$=j(()=>{n.fitViewport({zoom:g=>g>100?100:g,ignoreHeight:!0,gap:w}),L(),setTimeout(()=>{var g,W;e.em.destroyed||((W=(g=e.getSelected())==null?void 0:g.getEl())==null||W.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),_())},m)},100),H=new ResizeObserver(()=>{A(),$()});H.observe(v.parentElement);const M=()=>{A(),$()},O=(g={})=>{g.options&&g.options.from!=="fitViewport"&&n.fitViewport({zoom:n.getZoom(),ignoreHeight:!0,gap:w})},x=()=>{h.overflowX="hidden",h.overflowY="auto"},I=()=>{H.disconnect(),$.clear()};e.on(o.events.select,M),e.on(E.zoom,O),e.on(C,x),e.on(e.events.destroy,I),$(),t.add(T,()=>{o.devices.reset(P),S.scrollableCanvas=!1,n.getModel().updateDevice(),n.setZoom(100),n.setCoords(0,0),h.overflowY="hidden",L(!0),e.off(o.events.select,M),e.off(E.zoom,O),e.off(C,x),I(),t.run("studio:canvasReload")})}),Z({editor:e,licenseKey:c.licenseKey,plan:b.startup,pluginName:N,cleanup:()=>{e.runCommand(T)}})},ee=G(Q);module.exports=ee;
5
+ `,!d&&document.body.appendChild(f)};e.on($.frameLoadHead,i=>{if(!S.scrollableCanvas)return;const{window:w}=i,d=w.document,f=d.head,h="data-gs-plg-wrapper-style",y=f.querySelector(`style[${h}]`)||d.createElement("style");y.setAttribute(h,"true"),y.innerHTML=`
6
+ [data-gjs-type="wrapper"] { min-height: ${v}; }
7
+ [data-gjs-type="mjml"] { min-height: ${v} !important; }
8
+ [data-gjs-type="mj-body"] { min-height: ${v} !important; }
9
+ `,!f.contains(y)&&f.appendChild(y)}),e.onReady(()=>{const i=n.getSpotsEl(),w=n.getElement(),d=n.getFramesEl(),f=r*1e3,h=w.style;h.overflowX="hidden",d.style.transition=`transform ${r}s`;const y={x:m,y:p};L();const H=()=>i.style.display="none",K=()=>i.style.display="",T=F(()=>{n.fitViewport({zoom:g=>g>100?100:g,ignoreHeight:!0,gap:y}),L(),setTimeout(()=>{var W,k;const{em:g}=e;g.destroyed||((k=(W=e.getSelected())==null?void 0:W.getEl())==null||k.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),K(),t.isActive(C)?g.stopDefault():g.runDefault())},f)},100),j=new ResizeObserver(()=>{H(),T()});j.observe(w.parentElement);const M=()=>{H(),T()},O=(g={})=>{g.options&&g.options.from!=="fitViewport"&&n.fitViewport({zoom:n.getZoom(),ignoreHeight:!0,gap:y})},x=()=>{h.overflowX="hidden",h.overflowY="auto"},I=()=>{j.disconnect(),T.clear()};e.on(o.events.select,M),e.on($.zoom,O),e.on(E,x),e.on(e.events.destroy,I),T(),t.add(A,()=>{o.devices.reset(_),S.scrollableCanvas=!1,n.getModel().updateDevice(),n.setZoom(100),n.setCoords(0,0),h.overflowY="hidden",L(!0),e.off(o.events.select,M),e.off($.zoom,O),e.off(E,x),I(),t.run("studio:canvasReload")})}),Q({editor:e,licenseKey:c.licenseKey,plan:b.startup,pluginName:P,cleanup:()=>{e.runCommand(A)}})},ne=J(te);module.exports=ne;
@@ -1,20 +1,20 @@
1
- function j(e, a, n) {
2
- let t, o, c, p, d;
1
+ function F(e, a, n) {
2
+ let t, o, c, p, m;
3
3
  const r = a;
4
4
  function u() {
5
5
  const l = Date.now() - p;
6
- l < r && l >= 0 ? t = setTimeout(u, r - l) : (t = null, d = e.apply(c, o), c = o = null);
6
+ l < r && l >= 0 ? t = setTimeout(u, r - l) : (t = null, m = e.apply(c, o), c = o = null);
7
7
  }
8
8
  const s = function() {
9
- return c = this, o = arguments, p = Date.now(), t || (t = setTimeout(u, r)), d;
9
+ return c = this, o = arguments, p = Date.now(), t || (t = setTimeout(u, r)), m;
10
10
  };
11
11
  return s.clear = function() {
12
12
  t && (clearTimeout(t), t = null);
13
13
  }, s.flush = function() {
14
- t && (d = e.apply(c, o), c = o = null, clearTimeout(t), t = null);
14
+ t && (m = e.apply(c, o), c = o = null, clearTimeout(t), t = null);
15
15
  }, s;
16
16
  }
17
- const R = "app.grapesjs.com", U = "app-stage.grapesjs.com", k = [
17
+ const R = "app.grapesjs.com", U = "app-stage.grapesjs.com", z = [
18
18
  R,
19
19
  U,
20
20
  "localhost",
@@ -25,11 +25,11 @@ const R = "app.grapesjs.com", U = "app-stage.grapesjs.com", k = [
25
25
  // For stackblitz.com demos
26
26
  "-sandpack.codesandbox.io"
27
27
  // For Sandpack demos
28
- ], K = "license:check:start", F = "license:check:end", q = () => typeof window < "u", V = ({ isDev: e, isStage: a }) => `${e ? "" : `https://${a ? U : R}`}/api`, X = () => {
29
- const e = q() && window.location.hostname;
30
- return !!e && (k.includes(e) || k.some((a) => e.endsWith(a)));
28
+ ], q = "license:check:start", V = "license:check:end", X = () => typeof window < "u", Y = ({ isDev: e, isStage: a }) => `${e ? "" : `https://${a ? U : R}`}/api`, B = () => {
29
+ const e = X() && window.location.hostname;
30
+ return !!e && (z.includes(e) || z.some((a) => e.endsWith(a)));
31
31
  };
32
- async function Y({
32
+ async function G({
33
33
  path: e,
34
34
  baseApiUrl: a,
35
35
  method: n = "GET",
@@ -37,7 +37,7 @@ async function Y({
37
37
  params: o,
38
38
  body: c
39
39
  }) {
40
- const d = `${a || V({ isDev: !1, isStage: !1 })}${e}`, r = {
40
+ const m = `${a || Y({ isDev: !1, isStage: !1 })}${e}`, r = {
41
41
  method: n,
42
42
  headers: {
43
43
  "Content-Type": "application/json",
@@ -45,24 +45,24 @@ async function Y({
45
45
  }
46
46
  };
47
47
  c && (r.body = JSON.stringify(c));
48
- const u = o ? new URLSearchParams(o).toString() : "", s = u ? `?${u}` : "", l = await fetch(`${d}${s}`, r);
48
+ const u = o ? new URLSearchParams(o).toString() : "", s = u ? `?${u}` : "", l = await fetch(`${m}${s}`, r);
49
49
  if (!l.ok)
50
50
  throw new Error(`HTTP error! status: ${l.status}`);
51
51
  return l.json();
52
52
  }
53
53
  var b = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(b || {});
54
- const z = {
54
+ const N = {
55
55
  [b.free]: 0,
56
56
  [b.startup]: 10,
57
57
  [b.business]: 20,
58
58
  [b.enterprise]: 30
59
59
  };
60
- function B(e) {
60
+ function Z(e) {
61
61
  const a = e;
62
62
  return a.init = (n) => (t) => e(t, n), a;
63
63
  }
64
- const G = (e) => /* @__PURE__ */ B(e);
65
- async function Z({
64
+ const J = (e) => /* @__PURE__ */ Z(e);
65
+ async function Q({
66
66
  editor: e,
67
67
  plan: a,
68
68
  pluginName: n,
@@ -70,37 +70,37 @@ async function Z({
70
70
  cleanup: o
71
71
  }) {
72
72
  let c = "", p = !1;
73
- const d = X(), r = (s) => {
73
+ const m = B(), r = (s) => {
74
74
  console.warn("Cleanup plugin:", n, "Reason:", s), o();
75
75
  }, u = (s = {}) => {
76
76
  var C;
77
- const { error: l, sdkLicense: D } = s, y = (C = s.plan) == null ? void 0 : C.category;
77
+ const { error: l, sdkLicense: D } = s, v = (C = s.plan) == null ? void 0 : C.category;
78
78
  if (!(D || s.license) || l)
79
79
  r(l || "Invalid license");
80
- else if (y) {
81
- const S = z[a], T = z[y];
82
- S > T && r({ pluginRequiredPlan: a, licensePlan: y });
80
+ else if (v) {
81
+ const E = N[a], S = N[v];
82
+ E > S && r({ pluginRequiredPlan: a, licensePlan: v });
83
83
  }
84
84
  };
85
- e.on(K, (s) => {
85
+ e.on(q, (s) => {
86
86
  c = s == null ? void 0 : s.baseApiUrl, p = !0;
87
- }), e.on(F, (s) => {
87
+ }), e.on(V, (s) => {
88
88
  u(s);
89
89
  }), setTimeout(async () => {
90
90
  if (!p) {
91
- if (d) return;
91
+ if (m) return;
92
92
  if (t) {
93
- const s = await J({ licenseKey: t, pluginName: n, baseApiUrl: c });
93
+ const s = await ee({ licenseKey: t, pluginName: n, baseApiUrl: c });
94
94
  s && u(s);
95
95
  } else
96
96
  r("The `licenseKey` option not provided");
97
97
  }
98
98
  }, 2e3);
99
99
  }
100
- async function J(e) {
100
+ async function ee(e) {
101
101
  const { licenseKey: a, pluginName: n, baseApiUrl: t } = e;
102
102
  try {
103
- return (await Y({
103
+ return (await G({
104
104
  baseApiUrl: t,
105
105
  path: `/sdk/${a || "na"}`,
106
106
  method: "POST",
@@ -113,7 +113,7 @@ async function J(e) {
113
113
  return console.error("Error during SDK license check:", o), !1;
114
114
  }
115
115
  }
116
- const N = "canvasFullSize", Q = function(e, a = {}) {
116
+ const P = "canvasFullSize", te = function(e, a = {}) {
117
117
  const { Canvas: n, Commands: t, Devices: o } = e, c = {
118
118
  deviceMaxWidth: 1200,
119
119
  deviceMinHeigth: 500,
@@ -125,75 +125,80 @@ const N = "canvasFullSize", Q = function(e, a = {}) {
125
125
  ...a
126
126
  }, {
127
127
  canvasOffsetY: p,
128
- canvasOffsetX: d,
128
+ canvasOffsetX: m,
129
129
  canvasTransition: r,
130
130
  deviceMaxWidth: u,
131
131
  deviceMinHeigth: s,
132
132
  frameBorderRadius: l,
133
133
  frameTransition: D
134
- } = c, y = `${s}px`, E = n.events, C = `${t.events.stopCommand}core:preview`, S = n.getConfig(), T = `${N}:disable`, P = o.getAll().map((i) => ({ ...i.attributes }));
134
+ } = c, v = `${s}px`, $ = n.events, C = "core:preview", E = `${t.events.stopCommand}${C}`, S = n.getConfig(), A = `${P}:disable`, _ = o.getAll().map((i) => ({ ...i.attributes }));
135
135
  S.scrollableCanvas = !0, o.getAll().map((i) => {
136
- !i.get("width") && i.set("width", `${u}px`), !i.get("height") && i.set("height", "auto"), !i.get("minHeight") && i.set("minHeight", y);
136
+ !i.get("width") && i.set("width", `${u}px`), !i.get("height") && i.set("height", "auto"), !i.get("minHeight") && i.set("minHeight", v);
137
137
  });
138
138
  const L = (i) => {
139
- const v = "data-gs-plg-full-size", f = document.querySelector(`style[${v}]`);
140
- if (i && f)
141
- return f.remove();
142
- const m = f || document.createElement("style"), h = n.getZoomMultiplier();
143
- m.setAttribute(v, "true"), m.innerHTML = `
139
+ const w = "data-gs-plg-full-size", d = document.querySelector(`style[${w}]`);
140
+ if (i && d)
141
+ return d.remove();
142
+ const f = d || document.createElement("style"), h = n.getZoomMultiplier();
143
+ f.setAttribute(w, "true"), f.innerHTML = `
144
144
  .gjs-frame-wrapper { transition: width ${D}s !important; }
145
145
  .gjs-frame-wrapper__bottom { height: ${p * h}px }
146
146
  .gjs-frame { border-radius: ${l}px }
147
- `, !f && document.body.appendChild(m);
147
+ `, !d && document.body.appendChild(f);
148
148
  };
149
- e.on(E.frameLoadHead, (i) => {
149
+ e.on($.frameLoadHead, (i) => {
150
150
  if (!S.scrollableCanvas) return;
151
- const { window: v } = i, f = v.document, m = f.head, h = "data-gs-plg-wrapper-style", w = m.querySelector(`style[${h}]`) || f.createElement("style");
152
- w.setAttribute(h, "true"), w.innerHTML = `[data-gjs-type="wrapper"] { min-height: ${y}; }`, !m.contains(w) && m.appendChild(w);
151
+ const { window: w } = i, d = w.document, f = d.head, h = "data-gs-plg-wrapper-style", y = f.querySelector(`style[${h}]`) || d.createElement("style");
152
+ y.setAttribute(h, "true"), y.innerHTML = `
153
+ [data-gjs-type="wrapper"] { min-height: ${v}; }
154
+ [data-gjs-type="mjml"] { min-height: ${v} !important; }
155
+ [data-gjs-type="mj-body"] { min-height: ${v} !important; }
156
+ `, !f.contains(y) && f.appendChild(y);
153
157
  }), e.onReady(() => {
154
- const i = n.getSpotsEl(), v = n.getElement(), f = n.getFramesEl(), m = r * 1e3, h = v.style;
155
- h.overflowX = "hidden", f.style.transition = `transform ${r}s`;
156
- const w = { x: d, y: p };
158
+ const i = n.getSpotsEl(), w = n.getElement(), d = n.getFramesEl(), f = r * 1e3, h = w.style;
159
+ h.overflowX = "hidden", d.style.transition = `transform ${r}s`;
160
+ const y = { x: m, y: p };
157
161
  L();
158
- const A = () => i.style.display = "none", _ = () => i.style.display = "", $ = j(() => {
162
+ const H = () => i.style.display = "none", K = () => i.style.display = "", T = F(() => {
159
163
  n.fitViewport({
160
164
  zoom: (g) => g > 100 ? 100 : g,
161
165
  ignoreHeight: !0,
162
- gap: w
166
+ gap: y
163
167
  }), L(), setTimeout(() => {
164
- var g, W;
165
- e.em.destroyed || ((W = (g = e.getSelected()) == null ? void 0 : g.getEl()) == null || W.scrollIntoView({ block: "nearest" }), e.refresh({ tools: !0 }), _());
166
- }, m);
167
- }, 100), H = new ResizeObserver(() => {
168
- A(), $();
168
+ var W, k;
169
+ const { em: g } = e;
170
+ g.destroyed || ((k = (W = e.getSelected()) == null ? void 0 : W.getEl()) == null || k.scrollIntoView({ block: "nearest" }), e.refresh({ tools: !0 }), K(), t.isActive(C) ? g.stopDefault() : g.runDefault());
171
+ }, f);
172
+ }, 100), j = new ResizeObserver(() => {
173
+ H(), T();
169
174
  });
170
- H.observe(v.parentElement);
175
+ j.observe(w.parentElement);
171
176
  const M = () => {
172
- A(), $();
177
+ H(), T();
173
178
  }, O = (g = {}) => {
174
179
  g.options && g.options.from !== "fitViewport" && n.fitViewport({
175
180
  zoom: n.getZoom(),
176
181
  ignoreHeight: !0,
177
- gap: w
182
+ gap: y
178
183
  });
179
184
  }, x = () => {
180
185
  h.overflowX = "hidden", h.overflowY = "auto";
181
186
  }, I = () => {
182
- H.disconnect(), $.clear();
187
+ j.disconnect(), T.clear();
183
188
  };
184
- e.on(o.events.select, M), e.on(E.zoom, O), e.on(C, x), e.on(e.events.destroy, I), $(), t.add(T, () => {
185
- o.devices.reset(P), S.scrollableCanvas = !1, n.getModel().updateDevice(), n.setZoom(100), n.setCoords(0, 0), h.overflowY = "hidden", L(!0), e.off(o.events.select, M), e.off(E.zoom, O), e.off(C, x), I(), t.run("studio:canvasReload");
189
+ e.on(o.events.select, M), e.on($.zoom, O), e.on(E, x), e.on(e.events.destroy, I), T(), t.add(A, () => {
190
+ o.devices.reset(_), S.scrollableCanvas = !1, n.getModel().updateDevice(), n.setZoom(100), n.setCoords(0, 0), h.overflowY = "hidden", L(!0), e.off(o.events.select, M), e.off($.zoom, O), e.off(E, x), I(), t.run("studio:canvasReload");
186
191
  });
187
- }), Z({
192
+ }), Q({
188
193
  editor: e,
189
194
  licenseKey: c.licenseKey,
190
195
  plan: b.startup,
191
- pluginName: N,
196
+ pluginName: P,
192
197
  cleanup: () => {
193
- e.runCommand(T);
198
+ e.runCommand(A);
194
199
  }
195
200
  });
196
- }, ee = G(Q);
201
+ }, ne = J(te);
197
202
  export {
198
- ee as default
203
+ ne as default
199
204
  };
@@ -1,5 +1,9 @@
1
- (function(C,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(C=typeof globalThis<"u"?globalThis:C||self,C.StudioSdkPlugins_canvasFullSize=y())})(this,function(){"use strict";function C(e,i,n){let t,o,c,p,d;const r=i;function u(){const l=Date.now()-p;l<r&&l>=0?t=setTimeout(u,r-l):(t=null,d=e.apply(c,o),c=o=null)}const s=function(){return c=this,o=arguments,p=Date.now(),t||(t=setTimeout(u,r)),d};return s.clear=function(){t&&(clearTimeout(t),t=null)},s.flush=function(){t&&(d=e.apply(c,o),c=o=null,clearTimeout(t),t=null)},s}const y="app.grapesjs.com",H="app-stage.grapesjs.com",M=[y,H,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],_="license:check:start",j="license:check:end",F=()=>typeof window<"u",K=({isDev:e,isStage:i})=>`${e?"":`https://${i?H:y}`}/api`,q=()=>{const e=F()&&window.location.hostname;return!!e&&(M.includes(e)||M.some(i=>e.endsWith(i)))};async function V({path:e,baseApiUrl:i,method:n="GET",headers:t={},params:o,body:c}){const d=`${i||K({isDev:!1,isStage:!1})}${e}`,r={method:n,headers:{"Content-Type":"application/json",...t}};c&&(r.body=JSON.stringify(c));const u=o?new URLSearchParams(o).toString():"",s=u?`?${u}`:"",l=await fetch(`${d}${s}`,r);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var b=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(b||{});const O={[b.free]:0,[b.startup]:10,[b.business]:20,[b.enterprise]:30};function X(e){const i=e;return i.init=n=>t=>e(t,n),i}const Y=e=>X(e);async function B({editor:e,plan:i,pluginName:n,licenseKey:t,cleanup:o}){let c="",p=!1;const d=q(),r=s=>{console.warn("Cleanup plugin:",n,"Reason:",s),o()},u=(s={})=>{var T;const{error:l,sdkLicense:x}=s,S=(T=s.plan)==null?void 0:T.category;if(!(x||s.license)||l)r(l||"Invalid license");else if(S){const E=O[i],D=O[S];E>D&&r({pluginRequiredPlan:i,licensePlan:S})}};e.on(_,s=>{c=s==null?void 0:s.baseApiUrl,p=!0}),e.on(j,s=>{u(s)}),setTimeout(async()=>{if(!p){if(d)return;if(t){const s=await G({licenseKey:t,pluginName:n,baseApiUrl:c});s&&u(s)}else r("The `licenseKey` option not provided")}},2e3)}async function G(e){const{licenseKey:i,pluginName:n,baseApiUrl:t}=e;try{return(await V({baseApiUrl:t,path:`/sdk/${i||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const k="canvasFullSize";return Y(function(e,i={}){const{Canvas:n,Commands:t,Devices:o}=e,c={deviceMaxWidth:1200,deviceMinHeigth:500,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,frameBorderRadius:5,frameTransition:.3,...i},{canvasOffsetY:p,canvasOffsetX:d,canvasTransition:r,deviceMaxWidth:u,deviceMinHeigth:s,frameBorderRadius:l,frameTransition:x}=c,S=`${s}px`,$=n.events,T=`${t.events.stopCommand}core:preview`,E=n.getConfig(),D=`${k}:disable`,Z=o.getAll().map(a=>({...a.attributes}));E.scrollableCanvas=!0,o.getAll().map(a=>{!a.get("width")&&a.set("width",`${u}px`),!a.get("height")&&a.set("height","auto"),!a.get("minHeight")&&a.set("minHeight",S)});const A=a=>{const v="data-gs-plg-full-size",f=document.querySelector(`style[${v}]`);if(a&&f)return f.remove();const m=f||document.createElement("style"),h=n.getZoomMultiplier();m.setAttribute(v,"true"),m.innerHTML=`
2
- .gjs-frame-wrapper { transition: width ${x}s !important; }
1
+ (function(C,b){typeof exports=="object"&&typeof module<"u"?module.exports=b():typeof define=="function"&&define.amd?define(b):(C=typeof globalThis<"u"?globalThis:C||self,C.StudioSdkPlugins_canvasFullSize=b())})(this,function(){"use strict";function C(e,i,n){let t,o,c,p,d;const r=i;function u(){const l=Date.now()-p;l<r&&l>=0?t=setTimeout(u,r-l):(t=null,d=e.apply(c,o),c=o=null)}const s=function(){return c=this,o=arguments,p=Date.now(),t||(t=setTimeout(u,r)),d};return s.clear=function(){t&&(clearTimeout(t),t=null)},s.flush=function(){t&&(d=e.apply(c,o),c=o=null,clearTimeout(t),t=null)},s}const b="app.grapesjs.com",x="app-stage.grapesjs.com",H=[b,x,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],F="license:check:start",K="license:check:end",q=()=>typeof window<"u",V=({isDev:e,isStage:i})=>`${e?"":`https://${i?x:b}`}/api`,X=()=>{const e=q()&&window.location.hostname;return!!e&&(H.includes(e)||H.some(i=>e.endsWith(i)))};async function Y({path:e,baseApiUrl:i,method:n="GET",headers:t={},params:o,body:c}){const d=`${i||V({isDev:!1,isStage:!1})}${e}`,r={method:n,headers:{"Content-Type":"application/json",...t}};c&&(r.body=JSON.stringify(c));const u=o?new URLSearchParams(o).toString():"",s=u?`?${u}`:"",l=await fetch(`${d}${s}`,r);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var S=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(S||{});const M={[S.free]:0,[S.startup]:10,[S.business]:20,[S.enterprise]:30};function B(e){const i=e;return i.init=n=>t=>e(t,n),i}const G=e=>B(e);async function Z({editor:e,plan:i,pluginName:n,licenseKey:t,cleanup:o}){let c="",p=!1;const d=X(),r=s=>{console.warn("Cleanup plugin:",n,"Reason:",s),o()},u=(s={})=>{var T;const{error:l,sdkLicense:A}=s,v=(T=s.plan)==null?void 0:T.category;if(!(A||s.license)||l)r(l||"Invalid license");else if(v){const D=M[i],$=M[v];D>$&&r({pluginRequiredPlan:i,licensePlan:v})}};e.on(F,s=>{c=s==null?void 0:s.baseApiUrl,p=!0}),e.on(K,s=>{u(s)}),setTimeout(async()=>{if(!p){if(d)return;if(t){const s=await J({licenseKey:t,pluginName:n,baseApiUrl:c});s&&u(s)}else r("The `licenseKey` option not provided")}},2e3)}async function J(e){const{licenseKey:i,pluginName:n,baseApiUrl:t}=e;try{return(await Y({baseApiUrl:t,path:`/sdk/${i||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const O="canvasFullSize";return G(function(e,i={}){const{Canvas:n,Commands:t,Devices:o}=e,c={deviceMaxWidth:1200,deviceMinHeigth:500,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,frameBorderRadius:5,frameTransition:.3,...i},{canvasOffsetY:p,canvasOffsetX:d,canvasTransition:r,deviceMaxWidth:u,deviceMinHeigth:s,frameBorderRadius:l,frameTransition:A}=c,v=`${s}px`,E=n.events,T="core:preview",D=`${t.events.stopCommand}${T}`,$=n.getConfig(),k=`${O}:disable`,Q=o.getAll().map(a=>({...a.attributes}));$.scrollableCanvas=!0,o.getAll().map(a=>{!a.get("width")&&a.set("width",`${u}px`),!a.get("height")&&a.set("height","auto"),!a.get("minHeight")&&a.set("minHeight",v)});const j=a=>{const y="data-gs-plg-full-size",f=document.querySelector(`style[${y}]`);if(a&&f)return f.remove();const m=f||document.createElement("style"),h=n.getZoomMultiplier();m.setAttribute(y,"true"),m.innerHTML=`
2
+ .gjs-frame-wrapper { transition: width ${A}s !important; }
3
3
  .gjs-frame-wrapper__bottom { height: ${p*h}px }
4
4
  .gjs-frame { border-radius: ${l}px }
5
- `,!f&&document.body.appendChild(m)};e.on($.frameLoadHead,a=>{if(!E.scrollableCanvas)return;const{window:v}=a,f=v.document,m=f.head,h="data-gs-plg-wrapper-style",w=m.querySelector(`style[${h}]`)||f.createElement("style");w.setAttribute(h,"true"),w.innerHTML=`[data-gjs-type="wrapper"] { min-height: ${S}; }`,!m.contains(w)&&m.appendChild(w)}),e.onReady(()=>{const a=n.getSpotsEl(),v=n.getElement(),f=n.getFramesEl(),m=r*1e3,h=v.style;h.overflowX="hidden",f.style.transition=`transform ${r}s`;const w={x:d,y:p};A();const z=()=>a.style.display="none",J=()=>a.style.display="",L=C(()=>{n.fitViewport({zoom:g=>g>100?100:g,ignoreHeight:!0,gap:w}),A(),setTimeout(()=>{var g,U;e.em.destroyed||((U=(g=e.getSelected())==null?void 0:g.getEl())==null||U.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),J())},m)},100),I=new ResizeObserver(()=>{z(),L()});I.observe(v.parentElement);const W=()=>{z(),L()},N=(g={})=>{g.options&&g.options.from!=="fitViewport"&&n.fitViewport({zoom:n.getZoom(),ignoreHeight:!0,gap:w})},P=()=>{h.overflowX="hidden",h.overflowY="auto"},R=()=>{I.disconnect(),L.clear()};e.on(o.events.select,W),e.on($.zoom,N),e.on(T,P),e.on(e.events.destroy,R),L(),t.add(D,()=>{o.devices.reset(Z),E.scrollableCanvas=!1,n.getModel().updateDevice(),n.setZoom(100),n.setCoords(0,0),h.overflowY="hidden",A(!0),e.off(o.events.select,W),e.off($.zoom,N),e.off(T,P),R(),t.run("studio:canvasReload")})}),B({editor:e,licenseKey:c.licenseKey,plan:b.startup,pluginName:k,cleanup:()=>{e.runCommand(D)}})})});
5
+ `,!f&&document.body.appendChild(m)};e.on(E.frameLoadHead,a=>{if(!$.scrollableCanvas)return;const{window:y}=a,f=y.document,m=f.head,h="data-gs-plg-wrapper-style",w=m.querySelector(`style[${h}]`)||f.createElement("style");w.setAttribute(h,"true"),w.innerHTML=`
6
+ [data-gjs-type="wrapper"] { min-height: ${v}; }
7
+ [data-gjs-type="mjml"] { min-height: ${v} !important; }
8
+ [data-gjs-type="mj-body"] { min-height: ${v} !important; }
9
+ `,!m.contains(w)&&m.appendChild(w)}),e.onReady(()=>{const a=n.getSpotsEl(),y=n.getElement(),f=n.getFramesEl(),m=r*1e3,h=y.style;h.overflowX="hidden",f.style.transition=`transform ${r}s`;const w={x:d,y:p};j();const z=()=>a.style.display="none",ee=()=>a.style.display="",L=C(()=>{n.fitViewport({zoom:g=>g>100?100:g,ignoreHeight:!0,gap:w}),j(),setTimeout(()=>{var U,_;const{em:g}=e;g.destroyed||((_=(U=e.getSelected())==null?void 0:U.getEl())==null||_.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),ee(),t.isActive(T)?g.stopDefault():g.runDefault())},m)},100),I=new ResizeObserver(()=>{z(),L()});I.observe(y.parentElement);const P=()=>{z(),L()},W=(g={})=>{g.options&&g.options.from!=="fitViewport"&&n.fitViewport({zoom:n.getZoom(),ignoreHeight:!0,gap:w})},N=()=>{h.overflowX="hidden",h.overflowY="auto"},R=()=>{I.disconnect(),L.clear()};e.on(o.events.select,P),e.on(E.zoom,W),e.on(D,N),e.on(e.events.destroy,R),L(),t.add(k,()=>{o.devices.reset(Q),$.scrollableCanvas=!1,n.getModel().updateDevice(),n.setZoom(100),n.setCoords(0,0),h.overflowY="hidden",j(!0),e.off(o.events.select,P),e.off(E.zoom,W),e.off(D,N),R(),t.run("studio:canvasReload")})}),Z({editor:e,licenseKey:c.licenseKey,plan:S.startup,pluginName:O,cleanup:()=>{e.runCommand(k)}})})});
@@ -1,30 +1,37 @@
1
1
  import { SDKPluginOptions } from '../utils';
2
2
  export interface CanvasFullSizeOptions extends SDKPluginOptions {
3
3
  /**
4
+ * Default max width for the devices.
4
5
  * @default 1200
5
6
  */
6
7
  deviceMaxWidth?: number;
7
8
  /**
9
+ * Default min height for the devices.
8
10
  * @default 500
9
11
  */
10
12
  deviceMinHeigth?: number;
11
13
  /**
14
+ * Offset for the canvas on the Y axis (margin between the canvas and content frame).
12
15
  * @default 30
13
16
  */
14
17
  canvasOffsetY?: number;
15
18
  /**
19
+ * Offset for the canvas on the X axis (margin between the canvas and content frame).
16
20
  * @default 50
17
21
  */
18
22
  canvasOffsetX?: number;
19
23
  /**
24
+ * Transition time for the canvas when the screen size changes (in seconds).
20
25
  * @default 0.3
21
26
  */
22
27
  canvasTransition?: number;
23
28
  /**
29
+ * Border radius for the content frame (in px).
24
30
  * @default 5
25
31
  */
26
32
  frameBorderRadius?: number;
27
33
  /**
34
+ * Transition time for the content frame when the device changes (in seconds).
28
35
  * @default 0.3
29
36
  */
30
37
  frameTransition?: number;