@grapesjs/studio-sdk-plugins 1.0.14 → 1.0.15-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/accordionComponent/components/Accordion.d.ts +4 -0
  2. package/dist/accordionComponent/components/AccordionContent.d.ts +3 -0
  3. package/dist/accordionComponent/components/AccordionGroup.d.ts +4 -0
  4. package/dist/accordionComponent/components/AccordionHeader.d.ts +4 -0
  5. package/dist/accordionComponent/components/AccordionMarker.d.ts +3 -0
  6. package/dist/accordionComponent/index.cjs.d.ts +3 -0
  7. package/dist/accordionComponent/index.cjs.js +39 -0
  8. package/dist/accordionComponent/index.d.ts +3 -0
  9. package/dist/accordionComponent/index.es.d.ts +3 -0
  10. package/dist/accordionComponent/index.es.js +360 -0
  11. package/dist/accordionComponent/index.umd.js +39 -0
  12. package/dist/accordionComponent/types.d.ts +6 -0
  13. package/dist/accordionComponent/typesSchema.d.ts +22 -0
  14. package/dist/accordionComponent/utils.d.ts +22 -0
  15. package/dist/canvasEmptyState/index.cjs.js +1 -1
  16. package/dist/canvasEmptyState/index.es.js +15 -15
  17. package/dist/canvasEmptyState/index.umd.js +1 -1
  18. package/dist/canvasFullSize/index.cjs.js +5 -5
  19. package/dist/canvasFullSize/index.es.js +138 -118
  20. package/dist/canvasFullSize/index.umd.js +5 -5
  21. package/dist/canvasFullSize/typesSchema.d.ts +12 -8
  22. package/dist/flexComponent/blocks.d.ts +3 -0
  23. package/dist/flexComponent/components/FlexColumn.d.ts +4 -0
  24. package/dist/flexComponent/components/FlexRow.d.ts +4 -0
  25. package/dist/flexComponent/handlers.d.ts +19 -0
  26. package/dist/flexComponent/index.cjs.d.ts +3 -0
  27. package/dist/flexComponent/index.cjs.js +33 -0
  28. package/dist/flexComponent/index.d.ts +3 -0
  29. package/dist/flexComponent/index.es.d.ts +3 -0
  30. package/dist/flexComponent/index.es.js +715 -0
  31. package/dist/flexComponent/index.umd.js +33 -0
  32. package/dist/flexComponent/resizeDecorator.d.ts +50 -0
  33. package/dist/flexComponent/spots.d.ts +3 -0
  34. package/dist/flexComponent/types.d.ts +32 -0
  35. package/dist/flexComponent/typesSchema.d.ts +112 -0
  36. package/dist/flexComponent/utils.d.ts +63 -0
  37. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  38. package/dist/googleFontsAssetProvider/index.es.js +128 -91
  39. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  40. package/dist/googleFontsAssetProvider/types.d.ts +7 -2
  41. package/dist/googleFontsAssetProvider/utils.d.ts +5 -0
  42. package/dist/iconifyComponent/index.cjs.js +2 -2
  43. package/dist/iconifyComponent/index.es.js +39 -39
  44. package/dist/iconifyComponent/index.umd.js +2 -2
  45. package/dist/index.cjs.d.ts +2 -0
  46. package/dist/index.cjs.js +105 -35
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.es.d.ts +2 -0
  49. package/dist/index.es.js +6286 -5366
  50. package/dist/index.umd.js +105 -35
  51. package/dist/prosemirror/index.cjs.js +1 -1
  52. package/dist/prosemirror/index.es.js +1 -1
  53. package/dist/prosemirror/index.umd.js +1 -1
  54. package/dist/rteTinyMce/index.cjs.js +1 -1
  55. package/dist/rteTinyMce/index.es.js +28 -28
  56. package/dist/rteTinyMce/index.umd.js +1 -1
  57. package/dist/tableComponent/index.cjs.js +1 -1
  58. package/dist/tableComponent/index.es.js +31 -30
  59. package/dist/tableComponent/index.umd.js +1 -1
  60. package/dist/types.d.ts +3 -1
  61. package/dist/utils.d.ts +4 -0
  62. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  63. package/dist/youtubeAssetProvider/index.es.js +11 -11
  64. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  65. package/package.json +2 -2
@@ -0,0 +1,715 @@
1
+ import "grapesjs";
2
+ const de = "app.grapesjs.com", ue = "app-stage.grapesjs.com", ie = [
3
+ de,
4
+ ue,
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
+ ], Se = "license:check:start", be = "license:check:end", Ce = () => typeof window < "u", Pe = ({ isDev: n, isStage: e }) => `${n ? "" : `https://${e ? ue : de}`}/api`, ze = () => {
14
+ const n = Ce() && window.location.hostname;
15
+ return !!n && (ie.includes(n) || ie.some((e) => n.endsWith(e)));
16
+ };
17
+ function xe(n) {
18
+ return typeof n == "function";
19
+ }
20
+ async function we({
21
+ path: n,
22
+ baseApiUrl: e,
23
+ method: t = "GET",
24
+ headers: s = {},
25
+ params: i,
26
+ body: a
27
+ }) {
28
+ const l = `${e || Pe({ isDev: !1, isStage: !1 })}${n}`, c = {
29
+ method: t,
30
+ headers: {
31
+ "Content-Type": "application/json",
32
+ ...s
33
+ }
34
+ };
35
+ a && (c.body = JSON.stringify(a));
36
+ const g = i ? new URLSearchParams(i).toString() : "", p = g ? `?${g}` : "", u = await fetch(`${l}${p}`, c);
37
+ if (!u.ok)
38
+ throw new Error(`HTTP error! status: ${u.status}`);
39
+ return u.json();
40
+ }
41
+ var $ = /* @__PURE__ */ ((n) => (n.free = "free", n.startup = "startup", n.business = "business", n.enterprise = "enterprise", n))($ || {}), he = /* @__PURE__ */ ((n) => (n.web = "web", n.email = "email", n))(he || {});
42
+ const ae = {
43
+ [$.free]: 0,
44
+ [$.startup]: 10,
45
+ [$.business]: 20,
46
+ [$.enterprise]: 30
47
+ };
48
+ function ve(n) {
49
+ const e = n;
50
+ return e.init = (t) => (s) => n(s, t), e;
51
+ }
52
+ const Ie = (n) => /* @__PURE__ */ ve(n);
53
+ async function Re({
54
+ editor: n,
55
+ plan: e,
56
+ pluginName: t,
57
+ licenseKey: s,
58
+ cleanup: i
59
+ }) {
60
+ let a = "", o = !1;
61
+ const l = ze(), c = (p) => {
62
+ console.warn("Cleanup plugin:", t, "Reason:", p), i();
63
+ }, g = (p = {}) => {
64
+ var S;
65
+ const { error: u, sdkLicense: f } = p, v = (S = p.plan) == null ? void 0 : S.category;
66
+ if (!(f || p.license) || u)
67
+ c(u || "Invalid license");
68
+ else if (v) {
69
+ const I = ae[e], R = ae[v];
70
+ I > R && c({ pluginRequiredPlan: e, licensePlan: v });
71
+ }
72
+ };
73
+ n.on(Se, (p) => {
74
+ a = p == null ? void 0 : p.baseApiUrl, o = !0;
75
+ }), n.on(be, (p) => {
76
+ g(p);
77
+ }), setTimeout(async () => {
78
+ if (!o) {
79
+ if (l) return;
80
+ if (s) {
81
+ const p = await Ee({ licenseKey: s, pluginName: t, baseApiUrl: a });
82
+ p && g(p);
83
+ } else
84
+ c("The `licenseKey` option not provided");
85
+ }
86
+ }, 2e3);
87
+ }
88
+ async function Ee(n) {
89
+ const { licenseKey: e, pluginName: t, baseApiUrl: s } = n;
90
+ try {
91
+ return (await we({
92
+ baseApiUrl: s,
93
+ path: `/sdk/${e || "na"}`,
94
+ method: "POST",
95
+ params: {
96
+ d: window.location.hostname,
97
+ pn: t
98
+ }
99
+ })).result || {};
100
+ } catch (i) {
101
+ return console.error("Error during SDK license check:", i), !1;
102
+ }
103
+ }
104
+ const ge = (n) => (e) => {
105
+ var t;
106
+ return ((t = e.getAttribute) == null ? void 0 : t.call(e, ne)) === n;
107
+ }, Ge = (...n) => (e) => n.some((t) => e.is(t)), Te = (...n) => (e, t) => n.some((s) => t.is(s)), fe = "gjs-plg-", ne = "data-type-role", j = class j {
108
+ constructor(e) {
109
+ this.config = e;
110
+ }
111
+ getSize(e) {
112
+ var t;
113
+ return (t = this.config) != null && t.getSize ? this.config.getSize(e) : se(e.componentColumn, j.CSS_FLEX_BASIS);
114
+ }
115
+ setSize(e) {
116
+ var t;
117
+ if ((t = this.config) != null && t.setSize)
118
+ this.config.setSize(e);
119
+ else {
120
+ const { componentColumn: s, sizeValue: i, partial: a } = e;
121
+ s.addStyle({ [j.CSS_FLEX_BASIS]: i }, { partial: a });
122
+ }
123
+ }
124
+ };
125
+ j.CSS_FLEX_BASIS = "flex-basis";
126
+ let K = j;
127
+ const N = class N {
128
+ constructor(e) {
129
+ this.config = e;
130
+ }
131
+ isGapSupported() {
132
+ return !0;
133
+ }
134
+ getGap(e) {
135
+ var t;
136
+ return (t = this.config) != null && t.getGap ? this.config.getGap(e) : se(e.componentRow, N.CSS_GAP);
137
+ }
138
+ setGap(e) {
139
+ var t;
140
+ if ((t = this.config) != null && t.setGap)
141
+ this.config.setGap(e);
142
+ else {
143
+ const { componentRow: s, gapValue: i, partial: a } = e;
144
+ s.addStyle({ [N.CSS_GAP]: i }, { partial: a });
145
+ }
146
+ }
147
+ };
148
+ N.CSS_GAP = "gap";
149
+ let J = N;
150
+ const Y = class Y {
151
+ constructor(e) {
152
+ this.config = e;
153
+ }
154
+ getParentSize(e) {
155
+ var a;
156
+ if ((a = this.config) != null && a.getParentSize) return this.config.getParentSize(e);
157
+ const { componentRow: t, isVertical: s } = e, i = t.getEl();
158
+ return i ? s ? i.clientHeight : i.clientWidth : 0;
159
+ }
160
+ isLayoutVertical(e) {
161
+ var s;
162
+ if ((s = this.config) != null && s.isParentVertical) return this.config.isParentVertical(e);
163
+ const t = se(e.componentRow, Y.CSS_FLEX_DIRECTION, !0);
164
+ return t === "column" || t === "column-reverse";
165
+ }
166
+ };
167
+ Y.CSS_FLEX_DIRECTION = "flex-direction";
168
+ let q = Y;
169
+ const _ = class _ {
170
+ constructor(e) {
171
+ this.config = e;
172
+ }
173
+ getSize(e) {
174
+ var s;
175
+ if ((s = this.config) != null && s.getSize) return this.config.getSize(e);
176
+ const t = e.componentColumn;
177
+ if (t.is(_.MJML_COLUMN_TYPE)) {
178
+ const a = t.getAttributes().width;
179
+ if (a && (a.includes("%") || !isNaN(parseFloat(a))))
180
+ return parseFloat(a);
181
+ const o = t.parent();
182
+ return 100 / (o ? o.components().length : 1);
183
+ }
184
+ return 0;
185
+ }
186
+ setSize(e) {
187
+ var t;
188
+ if ((t = this.config) != null && t.setSize)
189
+ this.config.setSize(e);
190
+ else {
191
+ const { componentColumn: s, sizeValue: i, partial: a } = e;
192
+ s.is(_.MJML_COLUMN_TYPE) && s.addAttributes({ width: `${parseFloat(i)}%` }, { partial: a });
193
+ }
194
+ }
195
+ };
196
+ _.MJML_COLUMN_TYPE = "mj-column";
197
+ let Z = _;
198
+ const U = class U {
199
+ constructor(e) {
200
+ this.config = e;
201
+ }
202
+ isGapSupported() {
203
+ return !1;
204
+ }
205
+ getGap(e) {
206
+ var s;
207
+ if ((s = this.config) != null && s.getGap) return this.config.getGap(e);
208
+ const { componentRow: t } = e;
209
+ if (t.is(U.MJML_SECTION_TYPE)) {
210
+ const i = t.getAttributes();
211
+ if (i && i.padding)
212
+ return parseInt(i.padding, 10) || 0;
213
+ }
214
+ return 0;
215
+ }
216
+ setGap(e) {
217
+ var t, s;
218
+ (s = (t = this.config) == null ? void 0 : t.setGap) == null || s.call(t, e);
219
+ }
220
+ };
221
+ U.MJML_SECTION_TYPE = "mj-section";
222
+ let Q = U;
223
+ class Le {
224
+ constructor(e) {
225
+ this.config = e;
226
+ }
227
+ getParentSize(e) {
228
+ var o;
229
+ if ((o = this.config) != null && o.getParentSize) return this.config.getParentSize(e);
230
+ const { componentRow: t, isVertical: s } = e, i = t.getEl();
231
+ if (!i) return 0;
232
+ let a = i;
233
+ if (i.tagName !== "TABLE") {
234
+ const l = i.querySelectorAll("table");
235
+ l.length && (a = l[0]);
236
+ }
237
+ return s ? a.clientHeight : a.clientWidth;
238
+ }
239
+ isLayoutVertical(e) {
240
+ var t;
241
+ return (t = this.config) != null && t.isParentVertical ? this.config.isParentVertical(e) : !1;
242
+ }
243
+ }
244
+ class H {
245
+ constructor() {
246
+ this.handlerCache = /* @__PURE__ */ new Map();
247
+ }
248
+ static getInstance() {
249
+ return H.instance || (H.instance = new H()), H.instance;
250
+ }
251
+ getHandlers(e) {
252
+ const t = `${e.projectType}-${e.disableGapHandler ? "nogap" : "gap"}`;
253
+ return this.handlerCache.has(t) || (A(e) ? this.handlerCache.set(t, {
254
+ sizeHandler: new Z(e),
255
+ gapHandler: new Q(e),
256
+ parentSizeHandler: new Le(e)
257
+ }) : this.handlerCache.set(t, {
258
+ sizeHandler: new K(e),
259
+ gapHandler: new J(e),
260
+ parentSizeHandler: new q(e)
261
+ })), this.handlerCache.get(t);
262
+ }
263
+ }
264
+ function G(n) {
265
+ return H.getInstance().getHandlers(n);
266
+ }
267
+ const oe = (n) => {
268
+ n.style.display = "none";
269
+ }, re = (n) => {
270
+ n.style.display = "block";
271
+ }, V = (n) => +parseFloat(`${n}`).toFixed(2), A = (n) => n.projectType === he.email, k = (n, e) => {
272
+ const t = n.Canvas.getFramesEl();
273
+ t && (t.style.pointerEvents = e ? "none" : "");
274
+ }, $e = (n) => n ? ["top", "bottom"] : ["left", "right"], He = (n) => {
275
+ const e = n.parent();
276
+ return e ? e.components().models.indexOf(n) === 0 : !1;
277
+ }, Ae = (n) => {
278
+ const e = n.parent();
279
+ if (!e) return !1;
280
+ const t = e.components().models;
281
+ return t.indexOf(n) === t.length - 1;
282
+ }, Ve = (n) => {
283
+ const e = n.parent();
284
+ if (!e) return !1;
285
+ const t = e.components().models;
286
+ return t.length > 1 && n.index() === t.length - 1;
287
+ }, Me = (n, e, t, s) => {
288
+ const a = n + (t ? e === "top" ? -1 : e === "bottom" ? 1 : 0 : e === "left" ? -1 : e === "right" ? 1 : 0);
289
+ return a >= 0 && a < s ? a : -1;
290
+ }, O = (n) => n === "top" || n === "bottom", je = (n, e) => !!(He(n) && (e === "left" || e === "top") || Ae(n) && (e === "right" || e === "bottom")), Ne = (n) => {
291
+ const e = n.parent();
292
+ return e ? e.components().models.length > 1 : !1;
293
+ }, ce = (n, e) => n === "right" || n === "bottom" ? e > 0 : e < 0, se = (n, e, t = !1) => {
294
+ const s = !t, i = n.getEl();
295
+ if (!i)
296
+ return s ? 0 : "";
297
+ const o = window.getComputedStyle(i)[e] || "";
298
+ if (s) {
299
+ let l;
300
+ return typeof o == "string" ? (l = parseFloat(o.replace(/[^-\d.]/g, "")), isNaN(l) && (l = 0)) : l = Number(o) || 0, l;
301
+ }
302
+ return o;
303
+ }, le = (n, e, t) => {
304
+ const s = ee({ componentRow: n, isVertical: e }, t), i = n.components().models;
305
+ return s * (i.length - 1);
306
+ }, F = (n, e) => G(e).parentSizeHandler.isLayoutVertical({ componentRow: n }), B = (n, e) => G(e).sizeHandler.getSize(n), ee = (n, e) => {
307
+ if (e != null && e.disableGapHandler) return 0;
308
+ const { gapHandler: t, parentSizeHandler: s } = G(e);
309
+ if (!t.isGapSupported()) return 0;
310
+ const i = t.getGap(n), a = s.getParentSize(n);
311
+ return i / 100 * a;
312
+ }, te = (n, e) => G(e).parentSizeHandler.getParentSize(n), M = (n, e) => {
313
+ G(e).sizeHandler.setSize(n);
314
+ }, me = (n, e) => {
315
+ const t = B(n, e);
316
+ M({ ...n, sizeValue: `${t}%`, partial: !1 }, e);
317
+ }, ye = (n, e) => {
318
+ if (e != null && e.disableGapHandler) return;
319
+ const { gapHandler: t } = G(e);
320
+ t.isGapSupported() && t.setGap(n);
321
+ }, _e = (n, e) => {
322
+ const t = n.getStyle().gap;
323
+ if (!t) return;
324
+ const s = n.components().models, i = { componentRow: n, isVertical: F(n, e) };
325
+ s.map((a) => me({ ...i, componentColumn: a }, e)), ye({ ...i, gapValue: String(t), partial: !1 }, e);
326
+ };
327
+ function Fe(n, e) {
328
+ const { Blocks: t } = n, { typeColumn: s, typeRow: i, blocks: a } = e;
329
+ if (a === !1 || A(e)) return;
330
+ const o = (u) => ({
331
+ type: i,
332
+ components: u.map((f) => ({
333
+ type: s,
334
+ style: { "flex-basis": `${f}%` }
335
+ }))
336
+ }), l = (u) => `<div class="gs-block-item__flex-row" style="display: flex; height: 1.75rem; width: 100%; flex-wrap: nowrap; gap: 0.5rem;">
337
+ ${u.map((f) => `<div style="flex-basis: ${f}%; border-color: currentColor; border-width: 2px; border-radius: 0.12rem;"></div>`).join("")}
338
+ </div>`, c = (u, f) => ({
339
+ id: `flex-row-${f.join("-")}`,
340
+ label: u,
341
+ category: "Layout",
342
+ select: !0,
343
+ full: !0,
344
+ attributes: { class: "gs-block-item__flex gs-utl-w-full" },
345
+ media: l(f),
346
+ content: o(f)
347
+ }), g = [
348
+ c("1 Column", [100]),
349
+ c("2 Columns 50/50", [50, 50]),
350
+ c("2 Columns 25/75", [25, 75]),
351
+ c("2 Columns 75/25", [75, 25]),
352
+ c("3 Columns", [33.33, 33.33, 33.33]),
353
+ c("3 Columns 50/25/25", [50, 25, 25]),
354
+ c("3 Columns 25/50/25", [25, 50, 25]),
355
+ c("3 Columns 25/25/50", [25, 25, 50]),
356
+ c("4 Columns", [25, 25, 25, 25]),
357
+ c("5 Columns", [20, 20, 20, 20, 20])
358
+ ], p = xe(a) ? a({ blocks: g }) : g;
359
+ return p.forEach((u) => t.add(u.id, u)), () => {
360
+ p.forEach((u) => t.remove(u.id));
361
+ };
362
+ }
363
+ const Be = (n, e) => {
364
+ const { Components: t } = n, { typeRow: s, typeColumn: i, extendTypeColumn: a } = e, o = `${fe}${i}`, c = !!i && !!t.getType(i) && !a;
365
+ if (!(!i || c || A(e)))
366
+ return t.addType(i, {
367
+ isComponent: ge(i),
368
+ model: {
369
+ defaults: {
370
+ name: "Column",
371
+ resizable: !1,
372
+ emptyState: !0,
373
+ classes: o,
374
+ icon: '<svg viewBox="0 0 24 24"><path d="M14.5 2.3A1.8 1.8 0 0 0 12.7 4v16c0 1 .8 1.8 1.8 1.8h3a1.8 1.8 0 0 0 1.8-1.8V4a1.8 1.8 0 0 0-1.8-1.8zm-8 0A1.8 1.8 0 0 0 4.7 4v16c0 1 .8 1.8 1.8 1.8h3a1.8 1.8 0 0 0 1.8-1.8V4a1.8 1.8 0 0 0-1.8-1.8z"/></svg>',
375
+ draggable: Te(s),
376
+ attributes: { [ne]: i },
377
+ styles: `
378
+ .${o} {
379
+ flex-grow: 1;
380
+ }
381
+ `
382
+ }
383
+ }
384
+ }), () => {
385
+ t.removeType(i);
386
+ };
387
+ }, De = (n, e) => {
388
+ const { Components: t } = n, { typeRow: s, typeColumn: i, extendTypeRow: a } = e, o = `${fe}${s}`, c = !!s && !!t.getType(s) && !a;
389
+ if (!(!s || c || A(e)))
390
+ return t.addType(s, {
391
+ isComponent: ge(s),
392
+ model: {
393
+ defaults: {
394
+ name: "Row",
395
+ classes: o,
396
+ icon: '<svg viewBox="0 0 24 24"><path d="M4 4.8a1.8 1.8 0 0 0-1.8 1.7v3c0 1 .8 1.8 1.8 1.8h16a1.8 1.8 0 0 0 1.8-1.8v-3A1.8 1.8 0 0 0 20 4.7zm0 8a1.8 1.8 0 0 0-1.8 1.7v3c0 1 .8 1.8 1.8 1.8h16a1.8 1.8 0 0 0 1.8-1.8v-3a1.8 1.8 0 0 0-1.8-1.8z"/></svg>',
397
+ emptyState: { styleIn: "width: 100%" },
398
+ attributes: { [ne]: s },
399
+ droppable: Ge(i),
400
+ traits: [
401
+ // {
402
+ // type: 'number',
403
+ // name: 'columns',
404
+ // label: 'Columns',
405
+ // min: 1,
406
+ // max: 12,
407
+ // step: 1,
408
+ // default: 3
409
+ // },
410
+ // {
411
+ // type: 'button',
412
+ // text: 'Set column count',
413
+ // full: true,
414
+ // command: (_, trait) => {
415
+ // const columnCount = trait.component.getTrait('columns').props().value;
416
+ // createEqualColumns(columnLayoutComponent, columnCount, 2);
417
+ // }
418
+ // },
419
+ {
420
+ type: "checkbox",
421
+ name: "snap",
422
+ label: "Enable Snap",
423
+ default: e.snapEnabled,
424
+ changeProp: !0
425
+ },
426
+ {
427
+ type: "number",
428
+ name: "snap-divisions",
429
+ label: "Snap Divisions",
430
+ min: 1,
431
+ max: 12,
432
+ step: 1,
433
+ default: e.snapDivisions,
434
+ changeProp: !0
435
+ }
436
+ ],
437
+ resizable: {
438
+ tl: 0,
439
+ tc: 0,
440
+ tr: 0,
441
+ cl: 0,
442
+ bl: 0,
443
+ br: 0
444
+ },
445
+ styles: `
446
+ .${o} {
447
+ display: flex;
448
+ align-items: stretch;
449
+ flex-wrap: nowrap;
450
+ }
451
+ `
452
+ }
453
+ }
454
+ }), () => {
455
+ t.removeType(s);
456
+ };
457
+ };
458
+ class ke {
459
+ constructor() {
460
+ this.resizableChildTypes = /* @__PURE__ */ new Set(), this.gapAdjustableParentTypes = /* @__PURE__ */ new Set(), this.typeRelationships = /* @__PURE__ */ new Map();
461
+ }
462
+ registerResizableChild(e) {
463
+ this.resizableChildTypes.add(e);
464
+ }
465
+ registerGapAdjustableParent(e) {
466
+ this.gapAdjustableParentTypes.add(e);
467
+ }
468
+ registerTypeRelationship(e, t) {
469
+ this.typeRelationships.has(e) || this.typeRelationships.set(e, /* @__PURE__ */ new Set()), this.typeRelationships.get(e).add(t), this.registerResizableChild(t), this.registerGapAdjustableParent(e);
470
+ }
471
+ isResizableChild(e) {
472
+ return this.resizableChildTypes.has(e.get("type"));
473
+ }
474
+ isGapAdjustableParent(e) {
475
+ return this.gapAdjustableParentTypes.has(e.get("type"));
476
+ }
477
+ isValidRelationship(e, t) {
478
+ const s = e.get("type"), i = t.get("type");
479
+ return this.typeRelationships.has(s) ? this.typeRelationships.get(s).has(i) : !1;
480
+ }
481
+ }
482
+ class Oe {
483
+ constructor(e, t, s) {
484
+ this.editor = e, this.registry = t, this.opts = s, this.resizeState = /* @__PURE__ */ new WeakMap();
485
+ }
486
+ getState(e) {
487
+ return this.resizeState.has(e) || this.resizeState.set(e, {}), this.resizeState.get(e);
488
+ }
489
+ clearState(e) {
490
+ return this.resizeState.delete(e);
491
+ }
492
+ startResize(e, t, s) {
493
+ const { opts: i } = this, a = this.getState(e);
494
+ a.direction = t, a.startX = s.clientX, a.startY = s.clientY, a.resizing = !0, a.lastSnappedPercent = void 0;
495
+ const o = e.parent();
496
+ if (!o || !this.registry.isValidRelationship(o, e)) return;
497
+ a.snapEnabled = o.get("snap") ?? i.snapEnabled, a.snapDivisions = o.get("snap-divisions") ?? i.snapDivisions ?? 12;
498
+ const l = o.components().models, c = l.findIndex((f) => f.cid === e.cid), g = F(o, i), p = Me(c, t, g, l.length);
499
+ p !== -1 && (a.adjacentIdx = p);
500
+ const u = { componentColumn: e, componentRow: o, isVertical: g };
501
+ if (a.startPercent = B(u, i), typeof a.adjacentIdx < "u") {
502
+ const f = l[a.adjacentIdx];
503
+ a.neighborStartPercent = B({ ...u, componentColumn: f }, i);
504
+ }
505
+ }
506
+ updateResizeByDelta(e, t, s) {
507
+ const i = this.getState(e), a = e.parent();
508
+ !i.resizing || !a || (i.snapEnabled ? this.updateSnapResize(e, t, s) : this.updateContinuesResize(e, t, s));
509
+ }
510
+ finishResize(e) {
511
+ const t = e.parent(), s = t == null ? void 0 : t.components().models, i = { componentRow: t, isVertical: !!t && F(t, this.opts) };
512
+ s == null || s.forEach((a) => me({ ...i, componentColumn: a }, this.opts)), this.clearState(e);
513
+ }
514
+ updateContinuesResize(e, t, s) {
515
+ const i = this.getState(e), a = e.parent(), { opts: o } = this;
516
+ if (!a) return;
517
+ const l = o.minItemPercent ?? 0, c = O(t), g = te({ componentRow: a, isVertical: c }, o), p = le(a, c, this.opts), f = 100 - p / g * 100, v = s / (g - p) * f, { startPercent: P = 0, neighborStartPercent: S = 0 } = i, I = { componentRow: a, isVertical: c, componentColumn: e, partial: !0 }, R = ce(t, s) ? P + Math.abs(v) : P - Math.abs(v);
518
+ if (typeof i.adjacentIdx < "u") {
519
+ const z = a.components().models[i.adjacentIdx], x = P + S, b = x - l, r = Math.min(b, Math.max(l, R)), d = x - r;
520
+ M({ ...I, sizeValue: `${V(r)}%` }, o), M(
521
+ { ...I, componentColumn: z, sizeValue: `${V(d)}%` },
522
+ o
523
+ );
524
+ } else {
525
+ const z = Math.max(l, Math.min(f, R));
526
+ M({ ...I, sizeValue: `${V(z)}%` }, o);
527
+ }
528
+ }
529
+ updateSnapResize(e, t, s) {
530
+ const i = this.getState(e), a = e.parent(), o = O(t), l = te({ componentRow: a, isVertical: o }, this.opts), c = le(a, o, this.opts), g = l - c, p = s / g * 100, u = ce(t, s), { startPercent: f = 0, snapDivisions: v = 12 } = i, P = u ? f + Math.abs(p) : f - Math.abs(p), S = 100 / v, I = Math.floor(P / S) * S, R = Math.ceil(P / S) * S, z = Math.abs(R - P), x = Math.abs(P - I), b = S * 0.2, C = z < x ? R : I;
531
+ if (C > 0 && C < 100 && (z < b || x < b) && i.lastSnappedPercent !== C) {
532
+ i.lastSnappedPercent = C;
533
+ let m = Math.abs(C - f) / 100 * g;
534
+ (u && (t === "left" || t === "top") || !u && (t === "right" || t === "bottom")) && (m = -m), this.updateContinuesResize(e, t, m);
535
+ } else z >= b && x >= b && (i.lastSnappedPercent = void 0);
536
+ }
537
+ }
538
+ class Xe {
539
+ constructor(e, t, s) {
540
+ this.editor = e, this.registry = t, this.opts = s;
541
+ }
542
+ updateGapByDelta(e, t, s, i) {
543
+ if (!this.registry.isGapAdjustableParent(e)) return;
544
+ const { opts: a } = this, o = Math.max(0, s + t), l = te({ componentRow: e, isVertical: i }, a), c = o / l * 100, g = e.components().models, p = g.length - 1, u = { componentRow: e, isVertical: i }, f = g.reduce(
545
+ (b, C) => b + B({ ...u, componentColumn: C }, a),
546
+ 0
547
+ ), P = 100 - c * p, S = a.minItemPercent || 5;
548
+ if (P < S * g.length)
549
+ return;
550
+ const R = 100 - p * c, z = f - R, x = { componentRow: e, isVertical: i, partial: !0 };
551
+ g.map((b) => {
552
+ const C = B({ ...u, componentColumn: b }, a), r = C - C / f * z;
553
+ M({ ...x, componentColumn: b, sizeValue: `${V(r)}%` }, a);
554
+ }), ye({ ...x, gapValue: `${V(c)}%` }, a);
555
+ }
556
+ finishGapAdjust(e) {
557
+ _e(e, this.opts);
558
+ }
559
+ }
560
+ class Ye {
561
+ constructor(e, t, s) {
562
+ this.editor = e, this.registry = t, this.opts = s, this.resizeHandler = new Oe(e, t, s), this.gapHandler = new Xe(e, t, s);
563
+ }
564
+ startResize(e, t, s) {
565
+ this.resizeHandler.startResize(e, t, s);
566
+ }
567
+ updateResizeByDelta(e, t, s) {
568
+ this.resizeHandler.updateResizeByDelta(e, t, s);
569
+ }
570
+ finishResize(e) {
571
+ this.resizeHandler.finishResize(e);
572
+ }
573
+ updateGapByDelta(e, t, s, i) {
574
+ this.gapHandler.updateGapByDelta(e, t, s, i);
575
+ }
576
+ finishGapAdjust(e) {
577
+ this.gapHandler.finishGapAdjust(e);
578
+ }
579
+ canResize(e) {
580
+ const t = e.parent();
581
+ return t ? this.registry.isValidRelationship(t, e) : !1;
582
+ }
583
+ canAdjustGap(e) {
584
+ return this.registry.isGapAdjustableParent(e);
585
+ }
586
+ }
587
+ const X = "gs-flex-spots", pe = `${X}__handle-size`, Ue = `${X}__handle-gap`;
588
+ function We(n, e) {
589
+ const { Canvas: t } = n, s = "flex-resize-spot";
590
+ let i, a, o, l, c = null, g = null;
591
+ const p = new ke(), u = new Ye(n, p, e), f = () => {
592
+ var r;
593
+ i = document.createElement("div"), i.className = X, i.style.display = "none", a = document.createElement("div"), a.className = `${X}__handles`, a.style.position = "absolute", a.style.pointerEvents = "none", a.style.zIndex = "21", o = {
594
+ left: document.createElement("div"),
595
+ right: document.createElement("div"),
596
+ top: document.createElement("div"),
597
+ bottom: document.createElement("div")
598
+ }, Object.entries(o).forEach(([d, m]) => {
599
+ const y = d, h = O(y);
600
+ m.className = `${pe} ${pe}-${y} gjs-resizer-h gjs-cv-unscale`, m.style.cssText = `
601
+ pointer-events: all;
602
+ position: absolute;
603
+ z-index: 1;
604
+ cursor: ${h ? "ns-resize" : "ew-resize"};
605
+ ${h ? "left: 50%;" : "top: 50%;"}
606
+ ${y === "left" ? "left: 0px;" : ""}
607
+ ${y === "right" ? "right: 0px;" : ""}
608
+ ${y === "top" ? "top: 0px;" : ""}
609
+ ${y === "bottom" ? "bottom: 0px;" : ""}
610
+ `, m.addEventListener("pointerdown", v(y)), a.appendChild(m);
611
+ }), !e.disableGapHandler && !A(e) && (l = document.createElement("div"), l.className = Ue, l.style.cssText = `
612
+ position: absolute;
613
+ background-color: #3b97e3;
614
+ border-width: 2px;
615
+ border-radius: 9999px;
616
+ border-color: #fff;
617
+ box-sizing: content-box;
618
+ pointer-events: all;
619
+ max-width: 3rem;
620
+ max-height: 3rem;
621
+ `, l.addEventListener("pointerdown", P()), a.appendChild(l)), i.append(a), (r = t.getSpotsEl()) == null || r.appendChild(i);
622
+ }, v = (r) => (d) => {
623
+ if (!c) return;
624
+ k(n, !0), d.stopPropagation(), d.preventDefault(), u.startResize(c, r, d);
625
+ const m = d.clientX, y = d.clientY;
626
+ d.target.setPointerCapture(d.pointerId);
627
+ const h = (T) => {
628
+ const E = n.Canvas.getZoomMultiplier(), L = (T.clientX - m) * E, D = (T.clientY - y) * E, W = O(r) ? D : L;
629
+ u.updateResizeByDelta(c, r, W);
630
+ }, w = () => {
631
+ k(n, !1), u.finishResize(c), d.target.releasePointerCapture(d.pointerId), document.removeEventListener("pointermove", h), document.removeEventListener("pointerup", w);
632
+ };
633
+ document.addEventListener("pointermove", h), document.addEventListener("pointerup", w);
634
+ }, P = () => (r) => {
635
+ if (!g) return;
636
+ const d = g;
637
+ k(n, !0), r.stopPropagation(), r.preventDefault();
638
+ const m = F(d, e), y = ee({ componentRow: d, isVertical: m }, e), h = r.clientX, w = r.clientY;
639
+ r.target.setPointerCapture(r.pointerId);
640
+ const T = (L) => {
641
+ const D = n.Canvas.getZoomMultiplier(), W = m ? (L.clientY - w) * D : (L.clientX - h) * D;
642
+ u.updateGapByDelta(d, W, y, m);
643
+ }, E = () => {
644
+ k(n, !1), u.finishGapAdjust(d), r.target.releasePointerCapture(r.pointerId), document.removeEventListener("pointermove", T), document.removeEventListener("pointerup", E);
645
+ };
646
+ document.addEventListener("pointermove", T), document.addEventListener("pointerup", E);
647
+ }, S = (r) => {
648
+ const d = r.component;
649
+ if (!d || !i || (c = d, g = d.parent(), !g)) return;
650
+ const m = g;
651
+ re(i);
652
+ const y = r.getStyle();
653
+ a && Object.assign(a.style, y);
654
+ const h = F(m, e), w = $e(h);
655
+ if (Object.values(o).forEach(oe), w.forEach((E) => {
656
+ if (je(d, E)) return;
657
+ const L = o[E];
658
+ re(L);
659
+ }), G(e).gapHandler.isGapSupported() && l && Ne(d)) {
660
+ const E = ee({ componentRow: m, isVertical: h }, e);
661
+ I(E, h, Ve(d));
662
+ }
663
+ }, I = (r, d, m = !1) => {
664
+ const y = e.gapHandleSize, h = l.style;
665
+ if (d) {
666
+ h.height = `${y}px`;
667
+ const w = l.offsetHeight;
668
+ m ? (h.top = `-${(r + w) / 2}px`, h.bottom = "") : (h.bottom = `-${(r + w) / 2}px`, h.top = ""), h.width = "50%", h.left = "50%", h.transform = "translateX(-50%)", h.cursor = "row-resize";
669
+ } else {
670
+ h.width = `${y}px`;
671
+ const w = l.offsetWidth;
672
+ m ? (h.left = `-${(r + w) / 2}px`, h.right = "") : (h.right = `-${(r + w) / 2}px`, h.left = ""), h.height = "50%", h.top = "50%", h.transform = "translateY(-50%)", h.cursor = "col-resize";
673
+ }
674
+ }, R = () => {
675
+ i && (oe(i), c = null, g = null);
676
+ }, z = () => {
677
+ t.removeSpots({ type: s });
678
+ const r = n.getSelected(), d = r == null ? void 0 : r.parent();
679
+ r && d && p.isValidRelationship(d, r) ? t.addSpot({ type: s, component: r }) : R();
680
+ }, x = () => {
681
+ const r = t.getSpots().filter((d) => d.type === s)[0];
682
+ r && S(r);
683
+ }, b = (r, d) => {
684
+ p.registerTypeRelationship(r, d);
685
+ };
686
+ n.onReady(() => {
687
+ f(), A(e) ? b("mj-section", "mj-column") : b(e.typeRow, e.typeColumn);
688
+ });
689
+ const C = "component:toggled";
690
+ return n.on(t.events.spot, x), n.on(C, z), () => {
691
+ n.off(t.events.spot, x), n.off(C, z);
692
+ };
693
+ }
694
+ const Ke = "flexComponent", Je = function(n, e = {}) {
695
+ const t = {
696
+ typeRow: "flex-row",
697
+ typeColumn: "flex-column",
698
+ gapHandleSize: 3,
699
+ snapDivisions: 12,
700
+ minItemPercent: 5,
701
+ ...e
702
+ }, s = [De(n, t), Be(n, t)], i = We(n, t), a = Fe(n, t);
703
+ Re({
704
+ editor: n,
705
+ licenseKey: t.licenseKey,
706
+ plan: $.startup,
707
+ pluginName: Ke,
708
+ cleanup: () => {
709
+ s.forEach((o) => o == null ? void 0 : o()), i(), a == null || a();
710
+ }
711
+ });
712
+ }, Ze = Ie(Je);
713
+ export {
714
+ Ze as default
715
+ };