@grapesjs/studio-sdk-plugins 1.0.2 → 1.0.3

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.
@@ -0,0 +1,3 @@
1
+ import { PluginOptions } from '../utils';
2
+ declare const _default: import('../utils').PluginWithInit<PluginOptions>;
3
+ export default _default;
@@ -0,0 +1,59 @@
1
+ "use strict";require("react");const b="app.grapesjs.com",w="app-stage.grapesjs.com",E=[b,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],S="license:check:start",_="license:check:end",P=()=>typeof window<"u",k=({isDev:n,isStage:t})=>`${n?"":`https://${t?w:b}`}/api`,x=()=>{const n=P()&&window.location.hostname;return!!n&&(E.includes(n)||E.some(t=>n.endsWith(t)))},N=()=>(P()&&window.location.hostname)===b;var j={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.3",STUDIO_NPM_PACKAGE_VERSION:"1.0.20-rc.0"};const D=j.NODE_ENV!=="production";async function $({path:n,method:t="GET",headers:l={},body:o}){const s=`${k({isDev:D,isStage:!N()})}${n}`,a={method:t,headers:{"Content-Type":"application/json",...l}};o&&(a.body=JSON.stringify(o));const i=await fetch(s,a);if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i.json()}function A(n){const t=n;return t.init=l=>o=>n(o,l),t}const I=n=>A(n);async function X({editor:n,pluginName:t,licenseKey:l,cleanup:o}){let g=!1;const s=x();n.on(S,()=>{g=!0}),n.on(_,({sdkLicense:a})=>{a||o()}),setTimeout(async()=>{if(!g){if(s)return;l&&await q({licenseKey:l,pluginName:t})||o()}},2e3)}async function q({licenseKey:n,pluginName:t}){try{const l=await $({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:t})}),{license:o}=l.result||{};return!!o}catch(l){return console.error("Error during SDK license check:",l),!1}}const W=(...n)=>n.map(t=>`[data-gjs-type="${t}"]`).join(","),M="dialogComponent",U=function(n,t={}){const{Blocks:l,Components:o}=n,{licenseKey:g}=t,s="gjs-plg-dialog",a="gjs-plg-dialog-overlay",i="gjs-plg-dialog-content",h="gjs-plg-dialog-close",u="gjs-plg-dialog-title",y="gjs-plg-dialog-body",m="gjs-plg-dialog-description",f="gjs-plg-dialog-placeholder";l.add(s,{label:"Dialog",media:`
2
+ <svg viewBox="0 0 24 24">
3
+ <path d="M4 4h16v10H8l-4 4V4z"></path>
4
+ </svg>
5
+ `,category:"Extra",content:{type:s},activate:!0,...t.block}),o.addType(s,{model:{defaults:{tagName:"div",attributes:{class:s,"data-type-role":s},components:[{type:a},{type:f}],draggable:W("wrapper"),droppable:W(s),styles:`
6
+ .${s} {
7
+ position: relative;
8
+ z-index: 1;
9
+ }
10
+ `,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(r){var e;(e=r.getSelected())==null||e.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(r){const e=this;function C(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),d=e.querySelector('[data-type-role="gjs-plg-dialog-close"]');function v(){p.style.display="none"}c?(e._onCloseWhenPressingX=v,d.addEventListener("click",e._onCloseWhenPressingX)):(d.removeEventListener("click",e._onCloseWhenPressingX),e._onCloseWhenPressingX=null)}function O(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(v){v.key==="Escape"&&(p.style.display="none")}c?(e._onCloseWhenPressingEsc=d,e.addEventListener("keydown",e._onCloseWhenPressingEsc)):(e.removeEventListener("keydown",e._onCloseWhenPressingEsc),e._onCloseWhenPressingEsc=null)}function T(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(){p.style.display="flex"}c?(e._onOpenWhenLeavingWindow=d,document.addEventListener("mouseleave",e._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",e._onOpenWhenLeavingWindow),e._onOpenWhenLeavingWindow=null)}function L(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(){const v=document.documentElement.scrollTop;c&&v>=Number(c)&&(p.style.display="flex")}c?(e._onOpenWhenScrollingToLevel=d,document.addEventListener("scroll",e._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",e._onOpenWhenScrollingToLevel),e._onOpenWhenScrollingToLevel=null)}C(r.closeWhenPressingX),O(r.closeWhenPressingEsc),T(r.openWhenLeavingWindow),L(r.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const e=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');e.style.display="flex"})}},view:{onActive(){const r=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');r.style.display="flex"}}}),o.addType(a,{model:{defaults:{tagName:"div",attributes:{class:a,"data-type-role":a},components:{type:i},droppable:!1,draggable:!1,styles:`
11
+ .${a} {
12
+ position: fixed;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ display: none;
18
+ align-items: center;
19
+ justify-content: center;
20
+ background-color: rgba(0, 0, 0, 0.5);
21
+ }
22
+ `}}}),o.addType(i,{model:{defaults:{tagName:"div",attributes:{class:i,"data-type-role":i},components:[{type:h},{type:u},{type:y}],droppable:!1,draggable:!1,styles:`
23
+ .${i} {
24
+ position: relative;
25
+ background-color: #fff;
26
+ border-radius: 10px;
27
+ border: 1px solid #eee;
28
+ padding: 20px;
29
+ width: 800px;
30
+ height: 600px;
31
+ box-sizing: border-box;
32
+ }
33
+ `}}}),o.addType(h,{model:{defaults:{tagName:"button",attributes:{class:h,"data-type-role":h},components:"&times;",droppable:!1,draggable:!1,styles:`
34
+ .${h} {
35
+ position: absolute;
36
+ top: 10px;
37
+ right: 10px;
38
+ width: 30px;
39
+ height: 30px;
40
+ background: none;
41
+ border: none;
42
+ font-size: 20px;
43
+ cursor: pointer;
44
+ }
45
+ `}}}),o.addType(u,{model:{defaults:{tagName:"h2",attributes:{class:u,"data-type-role":u},components:"Dialog Title",editable:!0,droppable:!1,draggable:!1,styles:`
46
+ .${u} {
47
+ margin: 0;
48
+ padding: 0 40px 20px 0;
49
+ }
50
+ `}}}),o.addType(y,{model:{defaults:{tagName:"div",attributes:{class:y,"data-type-role":y},components:[{type:m}],styles:`
51
+ .${y} {
52
+ height: 90%;
53
+ overflow: auto;
54
+ }
55
+ `}}}),o.addType(m,{model:{defaults:{tagName:"p",attributes:{class:m,"data-type-role":m},components:"This is a customizable dialog!",editable:!0,styles:`
56
+ .${m} {
57
+ margin: 0;
58
+ }
59
+ `}}}),o.addType(f,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:f,"data-type-role":f},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){this.listenTo(this.em,"run:core:preview",()=>{this.el.style.display="none"}),this.listenTo(this.em,"stop:core:preview",()=>{this.el.style.display=""})}}}),X({editor:n,licenseKey:g,pluginName:M,cleanup:()=>{l.remove(s),o.removeType(s)}})},V=I(U);module.exports=V;
@@ -0,0 +1,3 @@
1
+ import { PluginOptions } from '../utils';
2
+ declare const _default: import('../utils').PluginWithInit<PluginOptions>;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { PluginOptions } from '../utils';
2
+ declare const _default: import('../utils').PluginWithInit<PluginOptions>;
3
+ export default _default;
@@ -0,0 +1,350 @@
1
+ import "react";
2
+ const b = "app.grapesjs.com", w = "app-stage.grapesjs.com", E = [
3
+ b,
4
+ w,
5
+ "localhost",
6
+ "127.0.0.1",
7
+ ".local-credentialless.webcontainer.io",
8
+ // For stackblitz.com demos
9
+ ".local.webcontainer.io",
10
+ // For stackblitz.com demos
11
+ "-sandpack.codesandbox.io"
12
+ // For Sandpack demos
13
+ ], S = "license:check:start", _ = "license:check:end", P = () => typeof window < "u", k = ({ isDev: n, isStage: t }) => `${n ? "" : `https://${t ? w : b}`}/api`, x = () => {
14
+ const n = P() && window.location.hostname;
15
+ return !!n && (E.includes(n) || E.some((t) => n.endsWith(t)));
16
+ }, N = () => (P() && window.location.hostname) === b;
17
+ var j = { NODE_ENV: "production", NPM_PACKAGE_VERSION: "1.0.3", STUDIO_NPM_PACKAGE_VERSION: "1.0.20-rc.0" };
18
+ const D = j.NODE_ENV !== "production";
19
+ async function $({
20
+ path: n,
21
+ method: t = "GET",
22
+ headers: l = {},
23
+ body: o
24
+ }) {
25
+ const s = `${k({ isDev: D, isStage: !N() })}${n}`, a = {
26
+ method: t,
27
+ headers: {
28
+ "Content-Type": "application/json",
29
+ ...l
30
+ }
31
+ };
32
+ o && (a.body = JSON.stringify(o));
33
+ const i = await fetch(s, a);
34
+ if (!i.ok)
35
+ throw new Error(`HTTP error! status: ${i.status}`);
36
+ return i.json();
37
+ }
38
+ function A(n) {
39
+ const t = n;
40
+ return t.init = (l) => (o) => n(o, l), t;
41
+ }
42
+ const I = (n) => /* @__PURE__ */ A(n);
43
+ async function X({
44
+ editor: n,
45
+ pluginName: t,
46
+ licenseKey: l,
47
+ cleanup: o
48
+ }) {
49
+ let g = !1;
50
+ const s = x();
51
+ n.on(S, () => {
52
+ g = !0;
53
+ }), n.on(_, ({ sdkLicense: a }) => {
54
+ a || o();
55
+ }), setTimeout(async () => {
56
+ if (!g) {
57
+ if (s) return;
58
+ l && await q({ licenseKey: l, pluginName: t }) || o();
59
+ }
60
+ }, 2e3);
61
+ }
62
+ async function q({ licenseKey: n, pluginName: t }) {
63
+ try {
64
+ const l = await $({
65
+ path: `/sdk/${n}`,
66
+ method: "POST",
67
+ body: JSON.stringify({
68
+ d: window.location.hostname,
69
+ pn: t
70
+ })
71
+ }), { license: o } = l.result || {};
72
+ return !!o;
73
+ } catch (l) {
74
+ return console.error("Error during SDK license check:", l), !1;
75
+ }
76
+ }
77
+ const W = (...n) => n.map((t) => `[data-gjs-type="${t}"]`).join(","), M = "dialogComponent", U = function(n, t = {}) {
78
+ const { Blocks: l, Components: o } = n, { licenseKey: g } = t, s = "gjs-plg-dialog", a = "gjs-plg-dialog-overlay", i = "gjs-plg-dialog-content", h = "gjs-plg-dialog-close", u = "gjs-plg-dialog-title", y = "gjs-plg-dialog-body", m = "gjs-plg-dialog-description", f = "gjs-plg-dialog-placeholder";
79
+ l.add(s, {
80
+ label: "Dialog",
81
+ media: `
82
+ <svg viewBox="0 0 24 24">
83
+ <path d="M4 4h16v10H8l-4 4V4z"></path>
84
+ </svg>
85
+ `,
86
+ category: "Extra",
87
+ content: { type: s },
88
+ activate: !0,
89
+ ...t.block
90
+ }), o.addType(s, {
91
+ model: {
92
+ defaults: {
93
+ tagName: "div",
94
+ attributes: { class: s, "data-type-role": s },
95
+ components: [{ type: a }, { type: f }],
96
+ draggable: W("wrapper"),
97
+ droppable: W(s),
98
+ styles: `
99
+ .${s} {
100
+ position: relative;
101
+ z-index: 1;
102
+ }
103
+ `,
104
+ traits: [
105
+ {
106
+ type: "button",
107
+ label: "Open dialog",
108
+ name: "onActive",
109
+ changeProp: !0,
110
+ command(r) {
111
+ var e;
112
+ (e = r.getSelected()) == null || e.trigger("active");
113
+ }
114
+ },
115
+ {
116
+ type: "checkbox",
117
+ label: "Close when pressing X",
118
+ name: "closeWhenPressingX",
119
+ default: !0,
120
+ changeProp: !0
121
+ },
122
+ {
123
+ type: "checkbox",
124
+ label: "Close when pressing ESC",
125
+ name: "closeWhenPressingEsc",
126
+ default: !0,
127
+ changeProp: !0
128
+ },
129
+ {
130
+ type: "checkbox",
131
+ label: "Open when leaving the window",
132
+ name: "openWhenLeavingWindow",
133
+ default: !1,
134
+ changeProp: !0
135
+ },
136
+ {
137
+ type: "number",
138
+ label: "Open when scrolling to level",
139
+ name: "openWhenScrollingToLevel",
140
+ default: 0,
141
+ changeProp: !0
142
+ }
143
+ ],
144
+ "script-props": [
145
+ "closeWhenPressingX",
146
+ "closeWhenPressingEsc",
147
+ "openWhenLeavingWindow",
148
+ "openWhenScrollingToLevel"
149
+ ],
150
+ script: function(r) {
151
+ const e = this;
152
+ function C(c) {
153
+ const p = e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'), d = e.querySelector('[data-type-role="gjs-plg-dialog-close"]');
154
+ function v() {
155
+ p.style.display = "none";
156
+ }
157
+ c ? (e._onCloseWhenPressingX = v, d.addEventListener("click", e._onCloseWhenPressingX)) : (d.removeEventListener("click", e._onCloseWhenPressingX), e._onCloseWhenPressingX = null);
158
+ }
159
+ function O(c) {
160
+ const p = e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');
161
+ function d(v) {
162
+ v.key === "Escape" && (p.style.display = "none");
163
+ }
164
+ c ? (e._onCloseWhenPressingEsc = d, e.addEventListener("keydown", e._onCloseWhenPressingEsc)) : (e.removeEventListener("keydown", e._onCloseWhenPressingEsc), e._onCloseWhenPressingEsc = null);
165
+ }
166
+ function T(c) {
167
+ const p = e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');
168
+ function d() {
169
+ p.style.display = "flex";
170
+ }
171
+ c ? (e._onOpenWhenLeavingWindow = d, document.addEventListener("mouseleave", e._onOpenWhenLeavingWindow)) : (document.removeEventListener("mouseleave", e._onOpenWhenLeavingWindow), e._onOpenWhenLeavingWindow = null);
172
+ }
173
+ function L(c) {
174
+ const p = e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');
175
+ function d() {
176
+ const v = document.documentElement.scrollTop;
177
+ c && v >= Number(c) && (p.style.display = "flex");
178
+ }
179
+ c ? (e._onOpenWhenScrollingToLevel = d, document.addEventListener("scroll", e._onOpenWhenScrollingToLevel)) : (document.removeEventListener("scroll", e._onOpenWhenScrollingToLevel), e._onOpenWhenScrollingToLevel = null);
180
+ }
181
+ C(r.closeWhenPressingX), O(r.closeWhenPressingEsc), T(r.openWhenLeavingWindow), L(r.openWhenScrollingToLevel);
182
+ }
183
+ },
184
+ init() {
185
+ this.on("active", this.handleOpenWhenClickPlaceholder);
186
+ },
187
+ handleOpenWhenClickPlaceholder() {
188
+ this.view.el.querySelector(
189
+ '[data-type-role="gjs-plg-dialog-placeholder"]'
190
+ ).addEventListener("click", () => {
191
+ const e = this.view.el.querySelector(
192
+ '[data-type-role="gjs-plg-dialog-overlay"]'
193
+ );
194
+ e.style.display = "flex";
195
+ });
196
+ }
197
+ },
198
+ view: {
199
+ onActive() {
200
+ const r = this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');
201
+ r.style.display = "flex";
202
+ }
203
+ }
204
+ }), o.addType(a, {
205
+ model: {
206
+ defaults: {
207
+ tagName: "div",
208
+ attributes: { class: a, "data-type-role": a },
209
+ components: { type: i },
210
+ droppable: !1,
211
+ draggable: !1,
212
+ styles: `
213
+ .${a} {
214
+ position: fixed;
215
+ top: 0;
216
+ left: 0;
217
+ width: 100%;
218
+ height: 100%;
219
+ display: none;
220
+ align-items: center;
221
+ justify-content: center;
222
+ background-color: rgba(0, 0, 0, 0.5);
223
+ }
224
+ `
225
+ }
226
+ }
227
+ }), o.addType(i, {
228
+ model: {
229
+ defaults: {
230
+ tagName: "div",
231
+ attributes: { class: i, "data-type-role": i },
232
+ components: [{ type: h }, { type: u }, { type: y }],
233
+ droppable: !1,
234
+ draggable: !1,
235
+ styles: `
236
+ .${i} {
237
+ position: relative;
238
+ background-color: #fff;
239
+ border-radius: 10px;
240
+ border: 1px solid #eee;
241
+ padding: 20px;
242
+ width: 800px;
243
+ height: 600px;
244
+ box-sizing: border-box;
245
+ }
246
+ `
247
+ }
248
+ }
249
+ }), o.addType(h, {
250
+ model: {
251
+ defaults: {
252
+ tagName: "button",
253
+ attributes: { class: h, "data-type-role": h },
254
+ components: "&times;",
255
+ droppable: !1,
256
+ draggable: !1,
257
+ styles: `
258
+ .${h} {
259
+ position: absolute;
260
+ top: 10px;
261
+ right: 10px;
262
+ width: 30px;
263
+ height: 30px;
264
+ background: none;
265
+ border: none;
266
+ font-size: 20px;
267
+ cursor: pointer;
268
+ }
269
+ `
270
+ }
271
+ }
272
+ }), o.addType(u, {
273
+ model: {
274
+ defaults: {
275
+ tagName: "h2",
276
+ attributes: { class: u, "data-type-role": u },
277
+ components: "Dialog Title",
278
+ editable: !0,
279
+ droppable: !1,
280
+ draggable: !1,
281
+ styles: `
282
+ .${u} {
283
+ margin: 0;
284
+ padding: 0 40px 20px 0;
285
+ }
286
+ `
287
+ }
288
+ }
289
+ }), o.addType(y, {
290
+ model: {
291
+ defaults: {
292
+ tagName: "div",
293
+ attributes: { class: y, "data-type-role": y },
294
+ components: [{ type: m }],
295
+ styles: `
296
+ .${y} {
297
+ height: 90%;
298
+ overflow: auto;
299
+ }
300
+ `
301
+ }
302
+ }
303
+ }), o.addType(m, {
304
+ model: {
305
+ defaults: {
306
+ tagName: "p",
307
+ attributes: { class: m, "data-type-role": m },
308
+ components: "This is a customizable dialog!",
309
+ editable: !0,
310
+ styles: `
311
+ .${m} {
312
+ margin: 0;
313
+ }
314
+ `
315
+ }
316
+ }
317
+ }), o.addType(f, {
318
+ model: {
319
+ toHTML() {
320
+ return "";
321
+ },
322
+ defaults: {
323
+ tagName: "button",
324
+ attributes: { class: f, "data-type-role": f },
325
+ components: "Dialog (click me to open)",
326
+ droppable: !1,
327
+ draggable: !1
328
+ }
329
+ },
330
+ view: {
331
+ init() {
332
+ this.listenTo(this.em, "run:core:preview", () => {
333
+ this.el.style.display = "none";
334
+ }), this.listenTo(this.em, "stop:core:preview", () => {
335
+ this.el.style.display = "";
336
+ });
337
+ }
338
+ }
339
+ }), X({
340
+ editor: n,
341
+ licenseKey: g,
342
+ pluginName: M,
343
+ cleanup: () => {
344
+ l.remove(s), o.removeType(s);
345
+ }
346
+ });
347
+ }, z = I(U);
348
+ export {
349
+ z as default
350
+ };
@@ -0,0 +1,59 @@
1
+ (function(p,u){typeof exports=="object"&&typeof module<"u"?module.exports=u(require("react")):typeof define=="function"&&define.amd?define(["react"],u):(p=typeof globalThis<"u"?globalThis:p||self,p.StudioSdkPlugins_dialogComponent=u())})(this,function(){"use strict";const p="app.grapesjs.com",u="app-stage.grapesjs.com",W=[p,u,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],T="license:check:start",C="license:check:end",w=()=>typeof window<"u",O=({isDev:n,isStage:t})=>`${n?"":`https://${t?u:p}`}/api`,S=()=>{const n=w()&&window.location.hostname;return!!n&&(W.includes(n)||W.some(t=>n.endsWith(t)))},L=()=>(w()&&window.location.hostname)===p;var _={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.3",STUDIO_NPM_PACKAGE_VERSION:"1.0.20-rc.0"};const k=_.NODE_ENV!=="production";async function x({path:n,method:t="GET",headers:l={},body:o}){const s=`${O({isDev:k,isStage:!L()})}${n}`,i={method:t,headers:{"Content-Type":"application/json",...l}};o&&(i.body=JSON.stringify(o));const a=await fetch(s,i);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return a.json()}function N(n){const t=n;return t.init=l=>o=>n(o,l),t}const j=n=>N(n);async function D({editor:n,pluginName:t,licenseKey:l,cleanup:o}){let h=!1;const s=S();n.on(T,()=>{h=!0}),n.on(C,({sdkLicense:i})=>{i||o()}),setTimeout(async()=>{if(!h){if(s)return;l&&await $({licenseKey:l,pluginName:t})||o()}},2e3)}async function $({licenseKey:n,pluginName:t}){try{const l=await x({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:t})}),{license:o}=l.result||{};return!!o}catch(l){return console.error("Error during SDK license check:",l),!1}}const P=(...n)=>n.map(t=>`[data-gjs-type="${t}"]`).join(","),A="dialogComponent";return j(function(n,t={}){const{Blocks:l,Components:o}=n,{licenseKey:h}=t,s="gjs-plg-dialog",i="gjs-plg-dialog-overlay",a="gjs-plg-dialog-content",y="gjs-plg-dialog-close",f="gjs-plg-dialog-title",m="gjs-plg-dialog-body",v="gjs-plg-dialog-description",E="gjs-plg-dialog-placeholder";l.add(s,{label:"Dialog",media:`
2
+ <svg viewBox="0 0 24 24">
3
+ <path d="M4 4h16v10H8l-4 4V4z"></path>
4
+ </svg>
5
+ `,category:"Extra",content:{type:s},activate:!0,...t.block}),o.addType(s,{model:{defaults:{tagName:"div",attributes:{class:s,"data-type-role":s},components:[{type:i},{type:E}],draggable:P("wrapper"),droppable:P(s),styles:`
6
+ .${s} {
7
+ position: relative;
8
+ z-index: 1;
9
+ }
10
+ `,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(r){var e;(e=r.getSelected())==null||e.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(r){const e=this;function I(d){const g=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),c=e.querySelector('[data-type-role="gjs-plg-dialog-close"]');function b(){g.style.display="none"}d?(e._onCloseWhenPressingX=b,c.addEventListener("click",e._onCloseWhenPressingX)):(c.removeEventListener("click",e._onCloseWhenPressingX),e._onCloseWhenPressingX=null)}function X(d){const g=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function c(b){b.key==="Escape"&&(g.style.display="none")}d?(e._onCloseWhenPressingEsc=c,e.addEventListener("keydown",e._onCloseWhenPressingEsc)):(e.removeEventListener("keydown",e._onCloseWhenPressingEsc),e._onCloseWhenPressingEsc=null)}function q(d){const g=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function c(){g.style.display="flex"}d?(e._onOpenWhenLeavingWindow=c,document.addEventListener("mouseleave",e._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",e._onOpenWhenLeavingWindow),e._onOpenWhenLeavingWindow=null)}function M(d){const g=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function c(){const b=document.documentElement.scrollTop;d&&b>=Number(d)&&(g.style.display="flex")}d?(e._onOpenWhenScrollingToLevel=c,document.addEventListener("scroll",e._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",e._onOpenWhenScrollingToLevel),e._onOpenWhenScrollingToLevel=null)}I(r.closeWhenPressingX),X(r.closeWhenPressingEsc),q(r.openWhenLeavingWindow),M(r.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const e=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');e.style.display="flex"})}},view:{onActive(){const r=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');r.style.display="flex"}}}),o.addType(i,{model:{defaults:{tagName:"div",attributes:{class:i,"data-type-role":i},components:{type:a},droppable:!1,draggable:!1,styles:`
11
+ .${i} {
12
+ position: fixed;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ display: none;
18
+ align-items: center;
19
+ justify-content: center;
20
+ background-color: rgba(0, 0, 0, 0.5);
21
+ }
22
+ `}}}),o.addType(a,{model:{defaults:{tagName:"div",attributes:{class:a,"data-type-role":a},components:[{type:y},{type:f},{type:m}],droppable:!1,draggable:!1,styles:`
23
+ .${a} {
24
+ position: relative;
25
+ background-color: #fff;
26
+ border-radius: 10px;
27
+ border: 1px solid #eee;
28
+ padding: 20px;
29
+ width: 800px;
30
+ height: 600px;
31
+ box-sizing: border-box;
32
+ }
33
+ `}}}),o.addType(y,{model:{defaults:{tagName:"button",attributes:{class:y,"data-type-role":y},components:"&times;",droppable:!1,draggable:!1,styles:`
34
+ .${y} {
35
+ position: absolute;
36
+ top: 10px;
37
+ right: 10px;
38
+ width: 30px;
39
+ height: 30px;
40
+ background: none;
41
+ border: none;
42
+ font-size: 20px;
43
+ cursor: pointer;
44
+ }
45
+ `}}}),o.addType(f,{model:{defaults:{tagName:"h2",attributes:{class:f,"data-type-role":f},components:"Dialog Title",editable:!0,droppable:!1,draggable:!1,styles:`
46
+ .${f} {
47
+ margin: 0;
48
+ padding: 0 40px 20px 0;
49
+ }
50
+ `}}}),o.addType(m,{model:{defaults:{tagName:"div",attributes:{class:m,"data-type-role":m},components:[{type:v}],styles:`
51
+ .${m} {
52
+ height: 90%;
53
+ overflow: auto;
54
+ }
55
+ `}}}),o.addType(v,{model:{defaults:{tagName:"p",attributes:{class:v,"data-type-role":v},components:"This is a customizable dialog!",editable:!0,styles:`
56
+ .${v} {
57
+ margin: 0;
58
+ }
59
+ `}}}),o.addType(E,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:E,"data-type-role":E},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){this.listenTo(this.em,"run:core:preview",()=>{this.el.style.display="none"}),this.listenTo(this.em,"stop:core:preview",()=>{this.el.style.display=""})}}}),D({editor:n,licenseKey:h,pluginName:A,cleanup:()=>{l.remove(s),o.removeType(s)}})})});
@@ -1,2 +1 @@
1
- export { default as initPluginOne } from './initPluginOne';
2
- export { default as initPluginTwo } from './initPluginTwo';
1
+ export { default as dialogComponent } from './dialogComponent';
package/dist/index.cjs.js CHANGED
@@ -1 +1,59 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react");const r="app.grapesjs.com",u="app-stage.grapesjs.com",l=[r,u,"localhost","127.0.0.1",".local-credentialless.webcontainer.io","-sandpack.codesandbox.io"],m="license:check:start",f="license:check:end",d=()=>typeof window<"u",g=({isDev:n,isStage:o})=>`${n?"":`https://${o?u:r}`}/api`,E=()=>{const n=d()&&window.location.hostname;return!!n&&(l.includes(n)||l.some(o=>n.endsWith(o)))},N=()=>(d()&&window.location.hostname)===r;var w={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.2",STUDIO_NPM_PACKAGE_VERSION:"1.0.19-rc.1"};const _=w.NODE_ENV!=="production";async function y({path:n,method:o="GET",headers:t={},body:e}){const c=`${g({isDev:_,isStage:!N()})}${n}`,i={method:o,headers:{"Content-Type":"application/json",...t}};e&&(i.body=JSON.stringify(e));const a=await fetch(c,i);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return a.json()}function P(n){const o=n;return o.init=t=>e=>n(e,t),o}const p=n=>P(n);async function h({editor:n,pluginName:o,licenseKey:t,cleanup:e}){let s=!1;const c=E();n.on(m,()=>{s=!0}),n.on(f,({sdkLicense:i})=>{i||e()}),setTimeout(async()=>{if(!s){if(c)return;t&&await S({licenseKey:t,pluginName:o})||e()}},2e3)}async function S({licenseKey:n,pluginName:o}){try{const t=await y({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:o})}),{license:e}=t.result||{};return!!e}catch(t){return console.error("Error during SDK license check:",t),!1}}const O="initPluginOne",T=function(n,o={}){const{Blocks:t}=n,{licenseKey:e}=o,s="test-plugin-one";t.add(s,{label:s,content:{type:s,components:`initPluginOne, licenseKey: ${e}`}}),h({editor:n,licenseKey:e,pluginName:O,cleanup:()=>t.remove(s)})},k=p(T),I="initPluginTwo",b=function(n,o={}){const{Blocks:t}=n,{licenseKey:e}=o,s="test-plugin-two";t.add(s,{label:s,content:{type:s,components:`initPluginTwo, licenseKey: ${e}`}}),h({editor:n,licenseKey:e,pluginName:I,cleanup:()=>t.remove(s)})},C=p(b);exports.initPluginOne=k;exports.initPluginTwo=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react");const b="app.grapesjs.com",w="app-stage.grapesjs.com",E=[b,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",_="license:check:end",P=()=>typeof window<"u",k=({isDev:n,isStage:t})=>`${n?"":`https://${t?w:b}`}/api`,x=()=>{const n=P()&&window.location.hostname;return!!n&&(E.includes(n)||E.some(t=>n.endsWith(t)))},N=()=>(P()&&window.location.hostname)===b;var j={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.3",STUDIO_NPM_PACKAGE_VERSION:"1.0.20-rc.0"};const D=j.NODE_ENV!=="production";async function $({path:n,method:t="GET",headers:l={},body:o}){const s=`${k({isDev:D,isStage:!N()})}${n}`,a={method:t,headers:{"Content-Type":"application/json",...l}};o&&(a.body=JSON.stringify(o));const i=await fetch(s,a);if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i.json()}function A(n){const t=n;return t.init=l=>o=>n(o,l),t}const I=n=>A(n);async function X({editor:n,pluginName:t,licenseKey:l,cleanup:o}){let g=!1;const s=x();n.on(L,()=>{g=!0}),n.on(_,({sdkLicense:a})=>{a||o()}),setTimeout(async()=>{if(!g){if(s)return;l&&await q({licenseKey:l,pluginName:t})||o()}},2e3)}async function q({licenseKey:n,pluginName:t}){try{const l=await $({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:t})}),{license:o}=l.result||{};return!!o}catch(l){return console.error("Error during SDK license check:",l),!1}}const W=(...n)=>n.map(t=>`[data-gjs-type="${t}"]`).join(","),M="dialogComponent",U=function(n,t={}){const{Blocks:l,Components:o}=n,{licenseKey:g}=t,s="gjs-plg-dialog",a="gjs-plg-dialog-overlay",i="gjs-plg-dialog-content",h="gjs-plg-dialog-close",u="gjs-plg-dialog-title",y="gjs-plg-dialog-body",m="gjs-plg-dialog-description",f="gjs-plg-dialog-placeholder";l.add(s,{label:"Dialog",media:`
2
+ <svg viewBox="0 0 24 24">
3
+ <path d="M4 4h16v10H8l-4 4V4z"></path>
4
+ </svg>
5
+ `,category:"Extra",content:{type:s},activate:!0,...t.block}),o.addType(s,{model:{defaults:{tagName:"div",attributes:{class:s,"data-type-role":s},components:[{type:a},{type:f}],draggable:W("wrapper"),droppable:W(s),styles:`
6
+ .${s} {
7
+ position: relative;
8
+ z-index: 1;
9
+ }
10
+ `,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(r){var e;(e=r.getSelected())==null||e.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(r){const e=this;function C(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),d=e.querySelector('[data-type-role="gjs-plg-dialog-close"]');function v(){p.style.display="none"}c?(e._onCloseWhenPressingX=v,d.addEventListener("click",e._onCloseWhenPressingX)):(d.removeEventListener("click",e._onCloseWhenPressingX),e._onCloseWhenPressingX=null)}function O(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(v){v.key==="Escape"&&(p.style.display="none")}c?(e._onCloseWhenPressingEsc=d,e.addEventListener("keydown",e._onCloseWhenPressingEsc)):(e.removeEventListener("keydown",e._onCloseWhenPressingEsc),e._onCloseWhenPressingEsc=null)}function T(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(){p.style.display="flex"}c?(e._onOpenWhenLeavingWindow=d,document.addEventListener("mouseleave",e._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",e._onOpenWhenLeavingWindow),e._onOpenWhenLeavingWindow=null)}function S(c){const p=e.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function d(){const v=document.documentElement.scrollTop;c&&v>=Number(c)&&(p.style.display="flex")}c?(e._onOpenWhenScrollingToLevel=d,document.addEventListener("scroll",e._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",e._onOpenWhenScrollingToLevel),e._onOpenWhenScrollingToLevel=null)}C(r.closeWhenPressingX),O(r.closeWhenPressingEsc),T(r.openWhenLeavingWindow),S(r.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const e=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');e.style.display="flex"})}},view:{onActive(){const r=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');r.style.display="flex"}}}),o.addType(a,{model:{defaults:{tagName:"div",attributes:{class:a,"data-type-role":a},components:{type:i},droppable:!1,draggable:!1,styles:`
11
+ .${a} {
12
+ position: fixed;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ display: none;
18
+ align-items: center;
19
+ justify-content: center;
20
+ background-color: rgba(0, 0, 0, 0.5);
21
+ }
22
+ `}}}),o.addType(i,{model:{defaults:{tagName:"div",attributes:{class:i,"data-type-role":i},components:[{type:h},{type:u},{type:y}],droppable:!1,draggable:!1,styles:`
23
+ .${i} {
24
+ position: relative;
25
+ background-color: #fff;
26
+ border-radius: 10px;
27
+ border: 1px solid #eee;
28
+ padding: 20px;
29
+ width: 800px;
30
+ height: 600px;
31
+ box-sizing: border-box;
32
+ }
33
+ `}}}),o.addType(h,{model:{defaults:{tagName:"button",attributes:{class:h,"data-type-role":h},components:"&times;",droppable:!1,draggable:!1,styles:`
34
+ .${h} {
35
+ position: absolute;
36
+ top: 10px;
37
+ right: 10px;
38
+ width: 30px;
39
+ height: 30px;
40
+ background: none;
41
+ border: none;
42
+ font-size: 20px;
43
+ cursor: pointer;
44
+ }
45
+ `}}}),o.addType(u,{model:{defaults:{tagName:"h2",attributes:{class:u,"data-type-role":u},components:"Dialog Title",editable:!0,droppable:!1,draggable:!1,styles:`
46
+ .${u} {
47
+ margin: 0;
48
+ padding: 0 40px 20px 0;
49
+ }
50
+ `}}}),o.addType(y,{model:{defaults:{tagName:"div",attributes:{class:y,"data-type-role":y},components:[{type:m}],styles:`
51
+ .${y} {
52
+ height: 90%;
53
+ overflow: auto;
54
+ }
55
+ `}}}),o.addType(m,{model:{defaults:{tagName:"p",attributes:{class:m,"data-type-role":m},components:"This is a customizable dialog!",editable:!0,styles:`
56
+ .${m} {
57
+ margin: 0;
58
+ }
59
+ `}}}),o.addType(f,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:f,"data-type-role":f},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){this.listenTo(this.em,"run:core:preview",()=>{this.el.style.display="none"}),this.listenTo(this.em,"stop:core:preview",()=>{this.el.style.display=""})}}}),X({editor:n,licenseKey:g,pluginName:M,cleanup:()=>{l.remove(s),o.removeType(s)}})},V=I(U);exports.dialogComponent=V;
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- export { default as initPluginOne } from './initPluginOne';
2
- export { default as initPluginTwo } from './initPluginTwo';
1
+ export { default as dialogComponent } from './dialogComponent';
@@ -1,2 +1 @@
1
- export { default as initPluginOne } from './initPluginOne';
2
- export { default as initPluginTwo } from './initPluginTwo';
1
+ export { default as dialogComponent } from './dialogComponent';