@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.
- package/dist/dialogComponent/index.cjs.d.ts +3 -0
- package/dist/dialogComponent/index.cjs.js +59 -0
- package/dist/dialogComponent/index.d.ts +3 -0
- package/dist/dialogComponent/index.es.d.ts +3 -0
- package/dist/dialogComponent/index.es.js +350 -0
- package/dist/dialogComponent/index.umd.js +59 -0
- package/dist/index.cjs.d.ts +1 -2
- package/dist/index.cjs.js +59 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.es.d.ts +1 -2
- package/dist/index.es.js +317 -68
- package/dist/index.umd.js +59 -1
- package/package.json +1 -1
- package/dist/initPluginOne/index.cjs.d.ts +0 -2
- package/dist/initPluginOne/index.cjs.js +0 -1
- package/dist/initPluginOne/index.d.ts +0 -2
- package/dist/initPluginOne/index.es.d.ts +0 -2
- package/dist/initPluginOne/index.es.js +0 -89
- package/dist/initPluginOne/index.umd.js +0 -1
- package/dist/initPluginTwo/index.cjs.d.ts +0 -2
- package/dist/initPluginTwo/index.cjs.js +0 -1
- package/dist/initPluginTwo/index.d.ts +0 -2
- package/dist/initPluginTwo/index.es.d.ts +0 -2
- package/dist/initPluginTwo/index.es.js +0 -89
- package/dist/initPluginTwo/index.umd.js +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,101 +1,350 @@
|
|
|
1
1
|
import "react";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const b = "app.grapesjs.com", w = "app-stage.grapesjs.com", E = [
|
|
3
|
+
b,
|
|
4
|
+
w,
|
|
5
5
|
"localhost",
|
|
6
6
|
"127.0.0.1",
|
|
7
7
|
".local-credentialless.webcontainer.io",
|
|
8
8
|
// For stackblitz.com demos
|
|
9
|
+
".local.webcontainer.io",
|
|
10
|
+
// For stackblitz.com demos
|
|
9
11
|
"-sandpack.codesandbox.io"
|
|
10
12
|
// For Sandpack demos
|
|
11
|
-
],
|
|
12
|
-
const n =
|
|
13
|
-
return !!n && (
|
|
14
|
-
}, N = () => (
|
|
15
|
-
var
|
|
16
|
-
const
|
|
17
|
-
async function
|
|
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 $({
|
|
18
20
|
path: n,
|
|
19
|
-
method:
|
|
20
|
-
headers:
|
|
21
|
-
body:
|
|
21
|
+
method: t = "GET",
|
|
22
|
+
headers: l = {},
|
|
23
|
+
body: o
|
|
22
24
|
}) {
|
|
23
|
-
const
|
|
24
|
-
method:
|
|
25
|
+
const s = `${k({ isDev: D, isStage: !N() })}${n}`, a = {
|
|
26
|
+
method: t,
|
|
25
27
|
headers: {
|
|
26
28
|
"Content-Type": "application/json",
|
|
27
|
-
...
|
|
29
|
+
...l
|
|
28
30
|
}
|
|
29
31
|
};
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
throw new Error(`HTTP error! status: ${
|
|
34
|
-
return
|
|
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();
|
|
35
37
|
}
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
-
return
|
|
38
|
+
function A(n) {
|
|
39
|
+
const t = n;
|
|
40
|
+
return t.init = (l) => (o) => n(o, l), t;
|
|
39
41
|
}
|
|
40
|
-
const
|
|
41
|
-
async function
|
|
42
|
+
const I = (n) => /* @__PURE__ */ A(n);
|
|
43
|
+
async function X({
|
|
42
44
|
editor: n,
|
|
43
|
-
pluginName:
|
|
44
|
-
licenseKey:
|
|
45
|
-
cleanup:
|
|
45
|
+
pluginName: t,
|
|
46
|
+
licenseKey: l,
|
|
47
|
+
cleanup: o
|
|
46
48
|
}) {
|
|
47
|
-
let
|
|
48
|
-
const
|
|
49
|
-
n.on(
|
|
50
|
-
|
|
51
|
-
}), n.on(
|
|
52
|
-
|
|
49
|
+
let g = !1;
|
|
50
|
+
const s = x();
|
|
51
|
+
n.on(S, () => {
|
|
52
|
+
g = !0;
|
|
53
|
+
}), n.on(_, ({ sdkLicense: a }) => {
|
|
54
|
+
a || o();
|
|
53
55
|
}), setTimeout(async () => {
|
|
54
|
-
if (!
|
|
55
|
-
if (
|
|
56
|
-
|
|
56
|
+
if (!g) {
|
|
57
|
+
if (s) return;
|
|
58
|
+
l && await q({ licenseKey: l, pluginName: t }) || o();
|
|
57
59
|
}
|
|
58
60
|
}, 2e3);
|
|
59
61
|
}
|
|
60
|
-
async function
|
|
62
|
+
async function q({ licenseKey: n, pluginName: t }) {
|
|
61
63
|
try {
|
|
62
|
-
const
|
|
64
|
+
const l = await $({
|
|
63
65
|
path: `/sdk/${n}`,
|
|
64
66
|
method: "POST",
|
|
65
67
|
body: JSON.stringify({
|
|
66
68
|
d: window.location.hostname,
|
|
67
|
-
pn:
|
|
69
|
+
pn: t
|
|
68
70
|
})
|
|
69
|
-
}), { license:
|
|
70
|
-
return !!
|
|
71
|
-
} catch (
|
|
72
|
-
return console.error("Error during SDK license check:",
|
|
71
|
+
}), { license: o } = l.result || {};
|
|
72
|
+
return !!o;
|
|
73
|
+
} catch (l) {
|
|
74
|
+
return console.error("Error during SDK license check:", l), !1;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
const
|
|
76
|
-
const { Blocks:
|
|
77
|
-
|
|
78
|
-
label:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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: "×",
|
|
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({
|
|
92
340
|
editor: n,
|
|
93
|
-
licenseKey:
|
|
94
|
-
pluginName:
|
|
95
|
-
cleanup: () =>
|
|
341
|
+
licenseKey: g,
|
|
342
|
+
pluginName: M,
|
|
343
|
+
cleanup: () => {
|
|
344
|
+
l.remove(s), o.removeType(s);
|
|
345
|
+
}
|
|
96
346
|
});
|
|
97
|
-
},
|
|
347
|
+
}, z = I(U);
|
|
98
348
|
export {
|
|
99
|
-
|
|
100
|
-
b as initPluginTwo
|
|
349
|
+
z as dialogComponent
|
|
101
350
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1,59 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u.StudioSdkPlugins={}))})(this,function(u){"use strict";const p="app.grapesjs.com",W="app-stage.grapesjs.com",w=[p,W,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],S="license:check:start",C="license:check:end",P=()=>typeof window<"u",O=({isDev:n,isStage:t})=>`${n?"":`https://${t?W:p}`}/api`,L=()=>{const n=P()&&window.location.hostname;return!!n&&(w.includes(n)||w.some(t=>n.endsWith(t)))},_=()=>(P()&&window.location.hostname)===p;var k={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.3",STUDIO_NPM_PACKAGE_VERSION:"1.0.20-rc.0"};const x=k.NODE_ENV!=="production";async function N({path:n,method:t="GET",headers:l={},body:o}){const s=`${O({isDev:x,isStage:!_()})}${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 j(n){const t=n;return t.init=l=>o=>n(o,l),t}const D=n=>j(n);async function $({editor:n,pluginName:t,licenseKey:l,cleanup:o}){let h=!1;const s=L();n.on(S,()=>{h=!0}),n.on(C,({sdkLicense:i})=>{i||o()}),setTimeout(async()=>{if(!h){if(s)return;l&&await A({licenseKey:l,pluginName:t})||o()}},2e3)}async function A({licenseKey:n,pluginName:t}){try{const l=await N({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 T=(...n)=>n.map(t=>`[data-gjs-type="${t}"]`).join(","),I="dialogComponent",X=D(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:T("wrapper"),droppable:T(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 q(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 M(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 U(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 V(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)}q(r.closeWhenPressingX),M(r.closeWhenPressingEsc),U(r.openWhenLeavingWindow),V(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:"×",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=""})}}}),$({editor:n,licenseKey:h,pluginName:I,cleanup:()=>{l.remove(s),o.removeType(s)}})});u.dialogComponent=X,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";require("react");const a="app.grapesjs.com",d="app-stage.grapesjs.com",l=[a,d,"localhost","127.0.0.1",".local-credentialless.webcontainer.io","-sandpack.codesandbox.io"],p="license:check:start",h="license:check:end",u=()=>typeof window<"u",f=({isDev:n,isStage:t})=>`${n?"":`https://${t?d:a}`}/api`,m=()=>{const n=u()&&window.location.hostname;return!!n&&(l.includes(n)||l.some(t=>n.endsWith(t)))},E=()=>(u()&&window.location.hostname)===a;var N={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.2",STUDIO_NPM_PACKAGE_VERSION:"1.0.19-rc.1"};const _=N.NODE_ENV!=="production";async function w({path:n,method:t="GET",headers:e={},body:s}){const c=`${f({isDev:_,isStage:!E()})}${n}`,i={method:t,headers:{"Content-Type":"application/json",...e}};s&&(i.body=JSON.stringify(s));const r=await fetch(c,i);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return r.json()}function g(n){const t=n;return t.init=e=>s=>n(s,e),t}const S=n=>g(n);async function k({editor:n,pluginName:t,licenseKey:e,cleanup:s}){let o=!1;const c=m();n.on(p,()=>{o=!0}),n.on(h,({sdkLicense:i})=>{i||s()}),setTimeout(async()=>{if(!o){if(c)return;e&&await O({licenseKey:e,pluginName:t})||s()}},2e3)}async function O({licenseKey:n,pluginName:t}){try{const e=await w({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:t})}),{license:s}=e.result||{};return!!s}catch(e){return console.error("Error during SDK license check:",e),!1}}const y="initPluginOne",C=function(n,t={}){const{Blocks:e}=n,{licenseKey:s}=t,o="test-plugin-one";e.add(o,{label:o,content:{type:o,components:`initPluginOne, licenseKey: ${s}`}}),k({editor:n,licenseKey:s,pluginName:y,cleanup:()=>e.remove(o)})},D=S(C);module.exports=D;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import "react";
|
|
2
|
-
const r = "app.grapesjs.com", d = "app-stage.grapesjs.com", l = [
|
|
3
|
-
r,
|
|
4
|
-
d,
|
|
5
|
-
"localhost",
|
|
6
|
-
"127.0.0.1",
|
|
7
|
-
".local-credentialless.webcontainer.io",
|
|
8
|
-
// For stackblitz.com demos
|
|
9
|
-
"-sandpack.codesandbox.io"
|
|
10
|
-
// For Sandpack demos
|
|
11
|
-
], p = "license:check:start", h = "license:check:end", u = () => typeof window < "u", f = ({ isDev: n, isStage: t }) => `${n ? "" : `https://${t ? d : r}`}/api`, m = () => {
|
|
12
|
-
const n = u() && window.location.hostname;
|
|
13
|
-
return !!n && (l.includes(n) || l.some((t) => n.endsWith(t)));
|
|
14
|
-
}, E = () => (u() && window.location.hostname) === r;
|
|
15
|
-
var N = { NODE_ENV: "production", NPM_PACKAGE_VERSION: "1.0.2", STUDIO_NPM_PACKAGE_VERSION: "1.0.19-rc.1" };
|
|
16
|
-
const _ = N.NODE_ENV !== "production";
|
|
17
|
-
async function w({
|
|
18
|
-
path: n,
|
|
19
|
-
method: t = "GET",
|
|
20
|
-
headers: e = {},
|
|
21
|
-
body: s
|
|
22
|
-
}) {
|
|
23
|
-
const c = `${f({ isDev: _, isStage: !E() })}${n}`, i = {
|
|
24
|
-
method: t,
|
|
25
|
-
headers: {
|
|
26
|
-
"Content-Type": "application/json",
|
|
27
|
-
...e
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
s && (i.body = JSON.stringify(s));
|
|
31
|
-
const a = await fetch(c, i);
|
|
32
|
-
if (!a.ok)
|
|
33
|
-
throw new Error(`HTTP error! status: ${a.status}`);
|
|
34
|
-
return a.json();
|
|
35
|
-
}
|
|
36
|
-
function g(n) {
|
|
37
|
-
const t = n;
|
|
38
|
-
return t.init = (e) => (s) => n(s, e), t;
|
|
39
|
-
}
|
|
40
|
-
const S = (n) => /* @__PURE__ */ g(n);
|
|
41
|
-
async function k({
|
|
42
|
-
editor: n,
|
|
43
|
-
pluginName: t,
|
|
44
|
-
licenseKey: e,
|
|
45
|
-
cleanup: s
|
|
46
|
-
}) {
|
|
47
|
-
let o = !1;
|
|
48
|
-
const c = m();
|
|
49
|
-
n.on(p, () => {
|
|
50
|
-
o = !0;
|
|
51
|
-
}), n.on(h, ({ sdkLicense: i }) => {
|
|
52
|
-
i || s();
|
|
53
|
-
}), setTimeout(async () => {
|
|
54
|
-
if (!o) {
|
|
55
|
-
if (c) return;
|
|
56
|
-
e && await O({ licenseKey: e, pluginName: t }) || s();
|
|
57
|
-
}
|
|
58
|
-
}, 2e3);
|
|
59
|
-
}
|
|
60
|
-
async function O({ licenseKey: n, pluginName: t }) {
|
|
61
|
-
try {
|
|
62
|
-
const e = await w({
|
|
63
|
-
path: `/sdk/${n}`,
|
|
64
|
-
method: "POST",
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
d: window.location.hostname,
|
|
67
|
-
pn: t
|
|
68
|
-
})
|
|
69
|
-
}), { license: s } = e.result || {};
|
|
70
|
-
return !!s;
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return console.error("Error during SDK license check:", e), !1;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const y = "initPluginOne", C = function(n, t = {}) {
|
|
76
|
-
const { Blocks: e } = n, { licenseKey: s } = t, o = "test-plugin-one";
|
|
77
|
-
e.add(o, {
|
|
78
|
-
label: o,
|
|
79
|
-
content: { type: o, components: `initPluginOne, licenseKey: ${s}` }
|
|
80
|
-
}), k({
|
|
81
|
-
editor: n,
|
|
82
|
-
licenseKey: s,
|
|
83
|
-
pluginName: y,
|
|
84
|
-
cleanup: () => e.remove(o)
|
|
85
|
-
});
|
|
86
|
-
}, I = S(C);
|
|
87
|
-
export {
|
|
88
|
-
I as default
|
|
89
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(o,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("react")):typeof define=="function"&&define.amd?define(["react"],c):(o=typeof globalThis<"u"?globalThis:o||self,o.StudioSdkPlugins_initPluginOne=c())})(this,function(){"use strict";const o="app.grapesjs.com",c="app-stage.grapesjs.com",l=[o,c,"localhost","127.0.0.1",".local-credentialless.webcontainer.io","-sandpack.codesandbox.io"],p="license:check:start",f="license:check:end",u=()=>typeof window<"u",h=({isDev:n,isStage:e})=>`${n?"":`https://${e?c:o}`}/api`,m=()=>{const n=u()&&window.location.hostname;return!!n&&(l.includes(n)||l.some(e=>n.endsWith(e)))},E=()=>(u()&&window.location.hostname)===o;var g={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.2",STUDIO_NPM_PACKAGE_VERSION:"1.0.19-rc.1"};const N=g.NODE_ENV!=="production";async function _({path:n,method:e="GET",headers:t={},body:s}){const a=`${h({isDev:N,isStage:!E()})}${n}`,r={method:e,headers:{"Content-Type":"application/json",...t}};s&&(r.body=JSON.stringify(s));const d=await fetch(a,r);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}function S(n){const e=n;return e.init=t=>s=>n(s,t),e}const w=n=>S(n);async function k({editor:n,pluginName:e,licenseKey:t,cleanup:s}){let i=!1;const a=m();n.on(p,()=>{i=!0}),n.on(f,({sdkLicense:r})=>{r||s()}),setTimeout(async()=>{if(!i){if(a)return;t&&await y({licenseKey:t,pluginName:e})||s()}},2e3)}async function y({licenseKey:n,pluginName:e}){try{const t=await _({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:e})}),{license:s}=t.result||{};return!!s}catch(t){return console.error("Error during SDK license check:",t),!1}}const O="initPluginOne";return w(function(n,e={}){const{Blocks:t}=n,{licenseKey:s}=e,i="test-plugin-one";t.add(i,{label:i,content:{type:i,components:`initPluginOne, licenseKey: ${s}`}}),k({editor:n,licenseKey:s,pluginName:O,cleanup:()=>t.remove(i)})})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";require("react");const a="app.grapesjs.com",d="app-stage.grapesjs.com",l=[a,d,"localhost","127.0.0.1",".local-credentialless.webcontainer.io","-sandpack.codesandbox.io"],p="license:check:start",h="license:check:end",u=()=>typeof window<"u",f=({isDev:n,isStage:t})=>`${n?"":`https://${t?d:a}`}/api`,m=()=>{const n=u()&&window.location.hostname;return!!n&&(l.includes(n)||l.some(t=>n.endsWith(t)))},E=()=>(u()&&window.location.hostname)===a;var w={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.2",STUDIO_NPM_PACKAGE_VERSION:"1.0.19-rc.1"};const N=w.NODE_ENV!=="production";async function _({path:n,method:t="GET",headers:e={},body:s}){const c=`${f({isDev:N,isStage:!E()})}${n}`,i={method:t,headers:{"Content-Type":"application/json",...e}};s&&(i.body=JSON.stringify(s));const r=await fetch(c,i);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return r.json()}function g(n){const t=n;return t.init=e=>s=>n(s,e),t}const S=n=>g(n);async function k({editor:n,pluginName:t,licenseKey:e,cleanup:s}){let o=!1;const c=m();n.on(p,()=>{o=!0}),n.on(h,({sdkLicense:i})=>{i||s()}),setTimeout(async()=>{if(!o){if(c)return;e&&await T({licenseKey:e,pluginName:t})||s()}},2e3)}async function T({licenseKey:n,pluginName:t}){try{const e=await _({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:t})}),{license:s}=e.result||{};return!!s}catch(e){return console.error("Error during SDK license check:",e),!1}}const y="initPluginTwo",C=function(n,t={}){const{Blocks:e}=n,{licenseKey:s}=t,o="test-plugin-two";e.add(o,{label:o,content:{type:o,components:`initPluginTwo, licenseKey: ${s}`}}),k({editor:n,licenseKey:s,pluginName:y,cleanup:()=>e.remove(o)})},D=S(C);module.exports=D;
|