@grapesjs/studio-sdk-plugins 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- const C = "app.grapesjs.com", w = "app-stage.grapesjs.com", b = [
2
- C,
3
- w,
1
+ const $ = "app.grapesjs.com", b = "app-stage.grapesjs.com", S = [
2
+ $,
3
+ b,
4
4
  "localhost",
5
5
  "127.0.0.1",
6
6
  ".local-credentialless.webcontainer.io",
@@ -9,83 +9,83 @@ const C = "app.grapesjs.com", w = "app-stage.grapesjs.com", b = [
9
9
  // For stackblitz.com demos
10
10
  "-sandpack.codesandbox.io"
11
11
  // For Sandpack demos
12
- ], P = "license:check:start", L = "license:check:end", v = () => typeof window < "u", O = ({ isDev: o, isStage: t }) => `${o ? "" : `https://${t ? w : C}`}/api`, k = () => {
13
- const o = v() && window.location.hostname;
14
- return !!o && (b.includes(o) || b.some((t) => o.endsWith(t)));
12
+ ], I = "license:check:start", w = "license:check:end", P = () => typeof window < "u", k = ({ isDev: o, isStage: t }) => `${o ? "" : `https://${t ? b : $}`}/api`, O = () => {
13
+ const o = P() && window.location.hostname;
14
+ return !!o && (S.includes(o) || S.some((t) => o.endsWith(t)));
15
15
  };
16
- async function T({
16
+ async function L({
17
17
  path: o,
18
18
  baseApiUrl: t,
19
19
  method: e = "GET",
20
- headers: n = {},
21
- params: s,
20
+ headers: s = {},
21
+ params: n,
22
22
  body: r
23
23
  }) {
24
- const a = `${t || O({ isDev: !1, isStage: !1 })}${o}`, c = {
24
+ const a = `${t || k({ isDev: !1, isStage: !1 })}${o}`, c = {
25
25
  method: e,
26
26
  headers: {
27
27
  "Content-Type": "application/json",
28
- ...n
28
+ ...s
29
29
  }
30
30
  };
31
31
  r && (c.body = JSON.stringify(r));
32
- const p = s ? new URLSearchParams(s).toString() : "", l = p ? `?${p}` : "", h = await fetch(`${a}${l}`, c);
32
+ const p = n ? new URLSearchParams(n).toString() : "", l = p ? `?${p}` : "", h = await fetch(`${a}${l}`, c);
33
33
  if (!h.ok)
34
34
  throw new Error(`HTTP error! status: ${h.status}`);
35
35
  return h.json();
36
36
  }
37
37
  var g = /* @__PURE__ */ ((o) => (o.free = "free", o.startup = "startup", o.business = "business", o.enterprise = "enterprise", o))(g || {});
38
- const I = {
38
+ const x = {
39
39
  [g.free]: 0,
40
40
  [g.startup]: 10,
41
41
  [g.business]: 20,
42
42
  [g.enterprise]: 30
43
43
  };
44
- function N(o) {
44
+ function C(o) {
45
45
  const t = o;
46
- return t.init = (e) => (n) => o(n, e), t;
46
+ return t.init = (e) => (s) => o(s, e), t;
47
47
  }
48
- const M = (o) => /* @__PURE__ */ N(o);
49
- async function B({
48
+ const v = (o) => /* @__PURE__ */ C(o);
49
+ async function N({
50
50
  editor: o,
51
51
  plan: t,
52
52
  pluginName: e,
53
- licenseKey: n,
54
- cleanup: s
53
+ licenseKey: s,
54
+ cleanup: n
55
55
  }) {
56
56
  let r = "", i = !1;
57
- const a = k(), c = (l) => {
58
- console.warn("Cleanup plugin:", e, "Reason:", l), s();
57
+ const a = O(), c = (l) => {
58
+ console.warn("Cleanup plugin:", e, "Reason:", l), n();
59
59
  }, p = (l = {}) => {
60
60
  var u;
61
61
  const { error: h, sdkLicense: d } = l, f = (u = l.plan) == null ? void 0 : u.category;
62
62
  if (!(d || l.license) || h)
63
63
  c(h || "Invalid license");
64
64
  else if (f) {
65
- const m = I[t], S = I[f];
66
- m > S && c({ pluginRequiredPlan: t, licensePlan: f });
65
+ const m = x[t], E = x[f];
66
+ m > E && c({ pluginRequiredPlan: t, licensePlan: f });
67
67
  }
68
68
  };
69
- o.on(P, (l) => {
69
+ o.on(I, (l) => {
70
70
  r = l == null ? void 0 : l.baseApiUrl, i = !0;
71
- }), o.on(L, (l) => {
71
+ }), o.on(w, (l) => {
72
72
  p(l);
73
73
  }), setTimeout(async () => {
74
74
  if (!i) {
75
75
  if (a) return;
76
- if (n) {
77
- const l = await _({ licenseKey: n, pluginName: e, baseApiUrl: r });
76
+ if (s) {
77
+ const l = await T({ licenseKey: s, pluginName: e, baseApiUrl: r });
78
78
  l && p(l);
79
79
  } else
80
80
  c("The `licenseKey` option not provided");
81
81
  }
82
82
  }, 2e3);
83
83
  }
84
- async function _(o) {
85
- const { licenseKey: t, pluginName: e, baseApiUrl: n } = o;
84
+ async function T(o) {
85
+ const { licenseKey: t, pluginName: e, baseApiUrl: s } = o;
86
86
  try {
87
- return (await T({
88
- baseApiUrl: n,
87
+ return (await L({
88
+ baseApiUrl: s,
89
89
  path: `/sdk/${t || "na"}`,
90
90
  method: "POST",
91
91
  params: {
@@ -93,164 +93,41 @@ async function _(o) {
93
93
  pn: e
94
94
  }
95
95
  })).result || {};
96
- } catch (s) {
97
- return console.error("Error during SDK license check:", s), !1;
96
+ } catch (n) {
97
+ return console.error("Error during SDK license check:", n), !1;
98
98
  }
99
99
  }
100
- var y = /* @__PURE__ */ ((o) => (o.variable = "data-variable", o.condition = "data-condition", o.conditionTrue = "data-condition-true-content", o.conditionFalse = "data-condition-false-content", o.collection = "data-collection", o.collectionItem = "data-collection-item", o))(y || {});
101
- class W {
102
- constructor(t) {
103
- this.strategy = t, this.requiredHelpers = /* @__PURE__ */ new Set(), this.helperLibrary = {};
104
- }
105
- registerHelper(t) {
106
- this.helperLibrary[t] && this.requiredHelpers.add(t);
107
- }
108
- generateVariable(t) {
109
- return this.strategy.getVariableSyntax(t);
110
- }
111
- generateCollectionStart(t) {
112
- return this.registerHelper("slice"), this.strategy.getCollectionStartSyntax(t);
113
- }
114
- generateCollectionEnd() {
115
- return this.strategy.getCollectionEndSyntax();
116
- }
117
- generateConditionalStart(t) {
118
- return this.strategy.getConditionalStartSyntax(t);
119
- }
120
- generateConditionElse() {
121
- return this.strategy.getConditionElseSyntax();
122
- }
123
- generateConditionalEnd() {
124
- return this.strategy.getConditionalEndSyntax();
125
- }
126
- reset() {
127
- this.requiredHelpers.clear();
128
- }
129
- }
130
- function j(o) {
131
- return typeof o == "object" && o.type === y.variable;
132
- }
133
- function x({
134
- component: o,
135
- value: t,
136
- getCustomPath: e
137
- }) {
138
- if (j(t) && !t.collectionId && e) {
139
- const n = t.path ?? "", s = n.split(".");
140
- return {
141
- ...t,
142
- path: e({ component: o, path: n, paths: s })
143
- };
144
- }
145
- return t;
146
- }
147
- const A = (o) => {
148
- $(o, y.variable, {
149
- toHTML(t) {
150
- var i;
151
- const e = this.tagName, n = this.__attrToString(t), s = (i = this.getDataResolver) == null ? void 0 : i.call(this), r = x({
152
- component: this,
153
- value: s,
154
- getCustomPath: t == null ? void 0 : t.getCustomPath
155
- });
156
- return `<${e}${n ? ` ${n}` : ""}>${t.exporter.generateVariable(r)}</${e}>`;
157
- }
158
- }), $(o, y.condition, {
159
- toHTML(t) {
160
- var l, h;
161
- const e = t.exporter, n = t == null ? void 0 : t.getCustomPath, s = this.components(), [r, i] = (s == null ? void 0 : s.models) ?? [], a = (l = this.getDataResolver) == null ? void 0 : l.call(this), c = ((h = this.resolveCondition) == null ? void 0 : h.call(this, a == null ? void 0 : a.condition, n)) ?? {};
162
- let p = "";
163
- return i && (p = `
164
- ${e.generateConditionElse()}
165
- ${i.toHTML(t) ?? ""}`), `
166
- ${e.generateConditionalStart(c)}
167
- ${(r == null ? void 0 : r.toHTML(t)) ?? ""}${p}
168
- ${e.generateConditionalEnd()}
169
- `;
170
- },
171
- resolveCondition(t, e) {
172
- var s, r;
173
- if (!t) return {};
174
- if (t.operator === "and" || t.operator === "or")
175
- return {
176
- operator: t.operator,
177
- statements: ((r = (s = t.statements) == null ? void 0 : s.map) == null ? void 0 : r.call(s, (i) => {
178
- var a;
179
- return ((a = this.resolveCondition) == null ? void 0 : a.call(this, i, e)) ?? {};
180
- })) ?? []
181
- };
182
- const n = { component: this, getCustomPath: e };
183
- return {
184
- ...t,
185
- left: x({ ...n, value: t.left }),
186
- right: x({ ...n, value: t.right })
187
- };
188
- }
189
- }), $(o, y.collection, {
190
- toHTML(t) {
191
- const e = t.exporter, n = this.tagName, s = this.__attrToString(t), r = this.getDataResolver(), i = {
192
- ...r,
193
- dataSource: x({
194
- component: this,
195
- value: r == null ? void 0 : r.dataSource,
196
- getCustomPath: t == null ? void 0 : t.getCustomPath
197
- })
198
- }, a = this.components().at(0);
199
- return `
200
- <${n}${s ? ` ${s}` : ""}>${e.generateCollectionStart(i)}
201
- ${(a == null ? void 0 : a.toHTML(t)) ?? ""}
202
- ${e.generateCollectionEnd()}</${n}>
203
- `;
204
- }
205
- });
206
- }, $ = (o, t, e) => {
207
- const n = o.Components.getType(t);
208
- if (!n) {
209
- console.warn(`Component type ${t} not found`);
210
- return;
211
- }
212
- const { model: s } = n;
213
- o.Components.addType(t, {
214
- model: {
215
- ...e,
216
- toHTML(r = {}) {
217
- var a;
218
- const { exporter: i } = r;
219
- return i ? i.export ? i.export({ component: this }) : ((a = e.toHTML) == null ? void 0 : a.call(this, r)) ?? "" : s.prototype.toHTML.call(this, r) ?? "";
220
- }
221
- }
222
- });
223
- }, J = (o) => {
100
+ const B = (o) => {
224
101
  const t = o;
225
102
  return t.logicalOperator === "and" || t.logicalOperator === "or";
226
- }, F = (o, t) => (o.config.optsHtml = {
103
+ }, M = (o, t) => (o.config.optsHtml = {
227
104
  ...o.config.optsHtml,
228
- exporter: new W(t)
229
- }, A(o), () => {
105
+ exporter: t
106
+ }, () => {
230
107
  o.config.optsHtml.exporter = void 0;
231
- }), H = (o, t) => {
232
- const e = (s) => {
233
- const { input: r } = s, { contains: i } = t;
234
- (!i || r.includes(i)) && (s.input = t.importer.import(r));
235
- }, n = o.Parser.events.htmlBefore;
236
- return o.on(n, e), () => {
237
- o.off(n, e);
108
+ }), W = (o, t) => {
109
+ const e = (n) => {
110
+ const { input: r } = n, { contains: i } = t;
111
+ (!i || r.includes(i)) && (n.input = t.importer.import(r));
112
+ }, s = o.Parser.events.htmlBefore;
113
+ return o.on(s, e), () => {
114
+ o.off(s, e);
238
115
  };
239
116
  };
240
- class U {
241
- getVariableSyntax(t) {
242
- const { defaultValue: e } = t, n = this.getFullPath(t), s = e ? ` || \`${e}\`` : "";
243
- return `<%= ${n}${s} %>`;
117
+ class A {
118
+ getVariableSyntax({ dataResolver: t }) {
119
+ const { defaultValue: e } = t, s = this.getFullPath(t), n = e ? ` || \`${e}\`` : "";
120
+ return `<%= ${s}${n} %>`;
244
121
  }
245
- getCollectionStartSyntax(t) {
246
- const { collectionId: e, dataSource: n, startIndex: s, endIndex: r } = t, i = (n == null ? void 0 : n.path) || e || "", a = this._sanitizeVariableName(e);
122
+ getCollectionStartSyntax({ dataResolver: t }) {
123
+ const { collectionId: e, dataSource: s, startIndex: n, endIndex: r } = t, i = (s == null ? void 0 : s.path) || e || "", a = this._sanitizeVariableName(e);
247
124
  let c = "";
248
- if (s !== void 0 || r !== void 0) {
249
- const p = s ?? 0, l = r !== void 0 ? r : "";
125
+ if (n !== void 0 || r !== void 0) {
126
+ const p = n ?? 0, l = r !== void 0 ? r : "";
250
127
  c = `.slice(${p}${l !== "" ? `, ${l}` : ""})`;
251
128
  }
252
129
  return `<% ${i}${c}.forEach(function(currentItem, index, arr) {
253
- const startIndex = parseInt(${s ?? 0}, 10);
130
+ const startIndex = parseInt(${n ?? 0}, 10);
254
131
  const endIndex = startIndex + arr.length;
255
132
  const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`;
256
133
  }
@@ -260,8 +137,8 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
260
137
  getCollectionEndSyntax() {
261
138
  return "<% }) %>";
262
139
  }
263
- getConditionalStartSyntax(t) {
264
- return `<% if (${this._parseCondition(t)}) { %>`;
140
+ getConditionalStartSyntax({ dataResolver: t }) {
141
+ return `<% if (${this._parseCondition(t.condition)}) { %>`;
265
142
  }
266
143
  getConditionElseSyntax() {
267
144
  return "<% } else { %>";
@@ -269,37 +146,37 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
269
146
  getConditionalEndSyntax() {
270
147
  return "<% } %>";
271
148
  }
272
- getFullPath({ collectionId: t, path: e, variableType: n }) {
273
- return (t ? [this._sanitizeVariableName(t), n, e].filter(Boolean).join(".") : e) || "";
149
+ getFullPath({ collectionId: t, path: e, variableType: s }) {
150
+ return (t ? [this._sanitizeVariableName(t), s, e].filter(Boolean).join(".") : e) || "";
274
151
  }
275
152
  _parseCondition(t) {
276
153
  if (!t) return "";
277
- if (J(t)) {
278
- const e = t.statements.map((r) => this._parseCondition(r)), n = D[t.logicalOperator];
279
- let s = e.length > 1 ? `(${e.join(`)${n}(`)})` : e[0];
280
- return t.logicalOperator === "xor" && (s = `!!(${s})`), s;
154
+ if (B(t)) {
155
+ const e = t.statements.map((r) => this._parseCondition(r)), s = J[t.logicalOperator];
156
+ let n = e.length > 1 ? `(${e.join(`)${s}(`)})` : e[0];
157
+ return t.logicalOperator === "xor" && (n = `!!(${n})`), n;
281
158
  } else {
282
- const e = this._parseValue(t.left), n = this._parseValue(t.right);
159
+ const e = this._parseValue(t.left), s = this._parseValue(t.right);
283
160
  switch (t.operator) {
284
161
  case "equals":
285
- return `${e} === ${n}`;
162
+ return `${e} === ${s}`;
286
163
  case ">":
287
164
  case "<":
288
165
  case ">=":
289
166
  case "<=":
290
167
  case "=":
291
168
  case "!=":
292
- return `${e} ${t.operator} ${n}`;
169
+ return `${e} ${t.operator} ${s}`;
293
170
  case "contains":
294
- return `${e}?.includes(${n})`;
171
+ return `${e}?.includes(${s})`;
295
172
  case "startsWith":
296
- return `${e}?.startsWith(${n})`;
173
+ return `${e}?.startsWith(${s})`;
297
174
  case "endsWith":
298
- return `${e}?.endsWith(${n})`;
175
+ return `${e}?.endsWith(${s})`;
299
176
  case "equalsIgnoreCase":
300
- return `${e}?.toLowerCase() === ${n}?.toLowerCase()`;
177
+ return `${e}?.toLowerCase() === ${s}?.toLowerCase()`;
301
178
  case "trimEquals":
302
- return `${e}?.trim() === ${n}?.trim()`;
179
+ return `${e}?.trim() === ${s}?.trim()`;
303
180
  case "isTruthy":
304
181
  return `!!${e}`;
305
182
  case "isFalsy":
@@ -321,7 +198,7 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
321
198
  case "isBoolean":
322
199
  return `typeof ${e} === 'boolean'`;
323
200
  default:
324
- return `${e} ${t.operator} ${n}`;
201
+ return `${e} ${t.operator} ${s}`;
325
202
  }
326
203
  }
327
204
  }
@@ -329,11 +206,11 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
329
206
  return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
330
207
  }
331
208
  }
332
- const D = {
209
+ const J = {
333
210
  and: "&&",
334
211
  or: "||",
335
212
  xor: "^"
336
- }, V = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], q = {
213
+ }, j = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], _ = {
337
214
  "===": "=",
338
215
  "==": "=",
339
216
  "!==": "!=",
@@ -345,7 +222,7 @@ const D = {
345
222
  "&&": "&&",
346
223
  "||": "||"
347
224
  };
348
- class G {
225
+ class F {
349
226
  constructor() {
350
227
  this.messages = [], this.collectionStack = [];
351
228
  }
@@ -360,35 +237,35 @@ class G {
360
237
  }
361
238
  parseEjsTemplate(t) {
362
239
  const e = [];
363
- let n = 0;
364
- for (; n < t.length; ) {
365
- const s = t.indexOf("<%", n);
366
- if (s === -1) {
367
- n < t.length && e.push(this.createAppendLiteral(t.slice(n)));
240
+ let s = 0;
241
+ for (; s < t.length; ) {
242
+ const n = t.indexOf("<%", s);
243
+ if (n === -1) {
244
+ s < t.length && e.push(this.createAppendLiteral(t.slice(s)));
368
245
  break;
369
246
  }
370
- s > n && e.push(this.createAppendLiteral(t.slice(n, s)));
371
- const r = t.indexOf("%>", s);
247
+ n > s && e.push(this.createAppendLiteral(t.slice(s, n)));
248
+ const r = t.indexOf("%>", n);
372
249
  if (r === -1)
373
250
  throw new Error("Unclosed EJS tag");
374
- const i = t.slice(s + 2, r).trim();
375
- if (n = r + 2, i.startsWith("=") || i.startsWith("-")) {
251
+ const i = t.slice(n + 2, r).trim();
252
+ if (s = r + 2, i.startsWith("=") || i.startsWith("-")) {
376
253
  const a = i.slice(1).trim();
377
254
  e.push(this.createAppendExpression(a));
378
255
  } else {
379
256
  if (i.startsWith("#"))
380
257
  continue;
381
258
  if (i.startsWith("if")) {
382
- const a = this.parseIfStatement(i, t, n);
383
- e.push(a), n = a.endPos || n;
259
+ const a = this.parseIfStatement(i, t, s);
260
+ e.push(a), s = a.endPos || s;
384
261
  } else if (i.startsWith("for")) {
385
- const a = this.parseForStatement(i, t, n);
386
- e.push(a), n = a.endPos || n;
262
+ const a = this.parseForStatement(i, t, s);
263
+ e.push(a), s = a.endPos || s;
387
264
  } else {
388
265
  const a = i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);
389
266
  if (a) {
390
- const c = a[1], p = a[2], l = this.parseForEachStatement(c, p, t, n);
391
- e.push(l), n = l.endPos || n;
267
+ const c = a[1], p = a[2], l = this.parseForEachStatement(c, p, t, s);
268
+ e.push(l), s = l.endPos || s;
392
269
  } else
393
270
  this.addMessage("info", `Unsupported scriptlet content: ${i}`);
394
271
  }
@@ -419,11 +296,11 @@ class G {
419
296
  }
420
297
  };
421
298
  }
422
- parseIfStatement(t, e, n) {
423
- const s = t.match(/if\s*\((.*)\)\s*\{?/);
424
- if (!s)
299
+ parseIfStatement(t, e, s) {
300
+ const n = t.match(/if\s*\((.*)\)\s*\{?/);
301
+ if (!n)
425
302
  throw new Error("Invalid if statement syntax");
426
- const r = this.parseJsExpression(s[1]), { body: i, endPos: a } = this.parseTemplateBlock(e, n);
303
+ const r = this.parseJsExpression(n[1]), { body: i, endPos: a } = this.parseTemplateBlock(e, s);
427
304
  let c = null, p = a;
428
305
  const l = e.indexOf("<%", p);
429
306
  if (l === p) {
@@ -432,7 +309,7 @@ class G {
432
309
  const d = e.slice(l + 2, h).trim(), f = h + 2 - l;
433
310
  if (d.startsWith("} else if")) {
434
311
  p = l + f;
435
- const E = d.substring(d.indexOf("if")).trim(), u = this.parseIfStatement(E, e, p);
312
+ const y = d.substring(d.indexOf("if")).trim(), u = this.parseIfStatement(y, e, p);
436
313
  c = {
437
314
  type: "IfStatement",
438
315
  test: u.test,
@@ -441,13 +318,13 @@ class G {
441
318
  }, p = u.endPos;
442
319
  } else if (d.startsWith("} else")) {
443
320
  p = l + f;
444
- const { body: E, endPos: u } = this.parseTemplateBlock(e, p);
321
+ const { body: y, endPos: u } = this.parseTemplateBlock(e, p);
445
322
  c = {
446
323
  type: "BlockStatement",
447
- body: E
324
+ body: y
448
325
  }, p = u;
449
- const m = e.indexOf("<%", p), S = e.indexOf("%>", m);
450
- m === p && e.slice(m + 2, S).trim() === "}" && (p = S + 2);
326
+ const m = e.indexOf("<%", p), E = e.indexOf("%>", m);
327
+ m === p && e.slice(m + 2, E).trim() === "}" && (p = E + 2);
451
328
  } else d === "}" && (p = l + f);
452
329
  }
453
330
  }
@@ -462,14 +339,14 @@ class G {
462
339
  endPos: p
463
340
  };
464
341
  }
465
- parseForStatement(t, e, n) {
466
- const s = t.match(/for\s*\((.*)\)\s*\{?/);
467
- if (!s)
342
+ parseForStatement(t, e, s) {
343
+ const n = t.match(/for\s*\((.*)\)\s*\{?/);
344
+ if (!n)
468
345
  throw new Error("Invalid for statement syntax");
469
- const r = s[1].split("of");
346
+ const r = n[1].split("of");
470
347
  if (r.length !== 2)
471
348
  throw new Error("Only for...of loops are supported");
472
- const i = r[0].trim().replace(/^let\s+|^const\s+|^var\s+/, ""), a = r[1].trim(), { body: c, endPos: p } = this.parseTemplateBlock(e, n);
349
+ const i = r[0].trim().replace(/^let\s+|^const\s+|^var\s+/, ""), a = r[1].trim(), { body: c, endPos: p } = this.parseTemplateBlock(e, s);
473
350
  return {
474
351
  type: "ForStatement",
475
352
  init: {
@@ -496,8 +373,8 @@ class G {
496
373
  })()
497
374
  };
498
375
  }
499
- parseForEachStatement(t, e, n, s) {
500
- const { body: r, endPos: i } = this.parseTemplateBlock(n, s);
376
+ parseForEachStatement(t, e, s, n) {
377
+ const { body: r, endPos: i } = this.parseTemplateBlock(s, n);
501
378
  return {
502
379
  type: "ForEachStatement",
503
380
  collection: this.parseJsExpression(t),
@@ -507,52 +384,52 @@ class G {
507
384
  body: r
508
385
  },
509
386
  endPos: (() => {
510
- const a = n.indexOf("<%", i), c = n.indexOf("%>", a);
511
- return a === i && n.slice(a + 2, c).trim() === "}" ? c + 2 : i;
387
+ const a = s.indexOf("<%", i), c = s.indexOf("%>", a);
388
+ return a === i && s.slice(a + 2, c).trim() === "}" ? c + 2 : i;
512
389
  })()
513
390
  };
514
391
  }
515
392
  parseTemplateBlock(t, e) {
516
- const n = [];
517
- let s = e;
518
- for (; s < t.length; ) {
519
- const r = t.indexOf("<%", s);
393
+ const s = [];
394
+ let n = e;
395
+ for (; n < t.length; ) {
396
+ const r = t.indexOf("<%", n);
520
397
  if (r === -1) {
521
- s < t.length && n.push(this.createAppendLiteral(t.slice(s))), s = t.length;
398
+ n < t.length && s.push(this.createAppendLiteral(t.slice(n))), n = t.length;
522
399
  break;
523
400
  }
524
- r > s && n.push(this.createAppendLiteral(t.slice(s, r)));
401
+ r > n && s.push(this.createAppendLiteral(t.slice(n, r)));
525
402
  const i = t.indexOf("%>", r);
526
403
  if (i === -1)
527
404
  throw new Error("Unclosed EJS tag within block");
528
405
  const a = t.slice(r + 2, i).trim();
529
406
  if (a === "}" || a.startsWith("} else")) {
530
- s = r;
407
+ n = r;
531
408
  break;
532
409
  }
533
- if (s = i + 2, a.startsWith("=") || a.startsWith("-")) {
410
+ if (n = i + 2, a.startsWith("=") || a.startsWith("-")) {
534
411
  const c = a.slice(1).trim();
535
- n.push(this.createAppendExpression(c));
412
+ s.push(this.createAppendExpression(c));
536
413
  } else {
537
414
  if (a.startsWith("#"))
538
415
  continue;
539
416
  if (a.startsWith("if")) {
540
- const c = this.parseIfStatement(a, t, s);
541
- n.push(c), s = c.endPos || s;
417
+ const c = this.parseIfStatement(a, t, n);
418
+ s.push(c), n = c.endPos || n;
542
419
  } else if (a.startsWith("for")) {
543
- const c = this.parseForStatement(a, t, s);
544
- n.push(c), s = c.endPos || s;
420
+ const c = this.parseForStatement(a, t, n);
421
+ s.push(c), n = c.endPos || n;
545
422
  } else {
546
423
  const c = a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);
547
424
  if (c) {
548
- const p = c[1], l = c[2], h = this.parseForEachStatement(p, l, t, s);
549
- n.push(h), s = h.endPos || s;
425
+ const p = c[1], l = c[2], h = this.parseForEachStatement(p, l, t, n);
426
+ s.push(h), n = h.endPos || n;
550
427
  } else
551
428
  this.addMessage("info", `Unsupported scriptlet content within block: ${a}`);
552
429
  }
553
430
  }
554
431
  }
555
- return { body: n, endPos: s };
432
+ return { body: s, endPos: n };
556
433
  }
557
434
  parseJsExpression(t) {
558
435
  if (/^(['"]).*\1$/.test(t))
@@ -575,28 +452,28 @@ class G {
575
452
  type: "Literal",
576
453
  value: t === "true"
577
454
  };
578
- for (const s of V) {
579
- const r = t.lastIndexOf(s);
455
+ for (const n of j) {
456
+ const r = t.lastIndexOf(n);
580
457
  if (r > 0 && t[r - 1] !== "!" && t[r - 1] !== "=" && t[r - 1] !== "<" && t[r - 1] !== ">")
581
458
  return {
582
- type: s === "&&" || s === "||" ? "LogicalExpression" : "BinaryExpression",
583
- operator: q[s],
459
+ type: n === "&&" || n === "||" ? "LogicalExpression" : "BinaryExpression",
460
+ operator: _[n],
584
461
  left: this.parseJsExpression(t.slice(0, r).trim()),
585
- right: this.parseJsExpression(t.slice(r + s.length).trim())
462
+ right: this.parseJsExpression(t.slice(r + n.length).trim())
586
463
  };
587
464
  }
588
- const e = t.indexOf("."), n = t.indexOf("[");
589
- if (e > 0 && (n === -1 || e < n) || n > 0 && (e === -1 || n < e)) {
590
- const s = e > 0 && (n === -1 || e < n) ? e : n;
465
+ const e = t.indexOf("."), s = t.indexOf("[");
466
+ if (e > 0 && (s === -1 || e < s) || s > 0 && (e === -1 || s < e)) {
467
+ const n = e > 0 && (s === -1 || e < s) ? e : s;
591
468
  let r, i, a = !1;
592
- if (s === e)
469
+ if (n === e)
593
470
  r = t.slice(0, e), i = { type: "Identifier", name: t.slice(e + 1) }, a = !1;
594
471
  else {
595
- r = t.slice(0, n);
596
- const c = t.indexOf("]", n);
472
+ r = t.slice(0, s);
473
+ const c = t.indexOf("]", s);
597
474
  if (c === -1)
598
475
  throw new Error("Unclosed bracket in expression");
599
- const p = t.slice(n + 1, c);
476
+ const p = t.slice(s + 1, c);
600
477
  i = /^(['"]).*\1$/.test(p) || /^-?\d+(\.\d+)?$/.test(p) ? this.parseJsExpression(p) : { type: "Identifier", name: p }, a = !0;
601
478
  }
602
479
  return {
@@ -645,8 +522,8 @@ class G {
645
522
  }
646
523
  handleProgram(t) {
647
524
  let e = "";
648
- for (const n of t.body)
649
- e += this.astToGrapesJS(n);
525
+ for (const s of t.body)
526
+ e += this.astToGrapesJS(s);
650
527
  return e;
651
528
  }
652
529
  handleVariableDeclaration(t) {
@@ -656,12 +533,12 @@ class G {
656
533
  return t.expression.type === "CallExpression" && t.expression.callee.type === "Identifier" && t.expression.callee.name === "__append" && t.expression.arguments.length > 0 ? this.astToGrapesJS(t.expression.arguments[0]) : "";
657
534
  }
658
535
  handleIfStatement(t) {
659
- const e = this.getConditionExpression(t.test), n = this.astToGrapesJS(t.consequent);
660
- let s = "";
661
- return t.alternate && (s = this.astToGrapesJS(t.alternate)), `
536
+ const e = this.getConditionExpression(t.test), s = this.astToGrapesJS(t.consequent);
537
+ let n = "";
538
+ return t.alternate && (n = this.astToGrapesJS(t.alternate)), `
662
539
  <data-condition data-gjs-data-resolver='${JSON.stringify({ condition: e })}'>
663
- <data-condition-true-content>${n}</data-condition-true-content>
664
- <data-condition-false-content>${s}</data-condition-false-content>
540
+ <data-condition-true-content>${s}</data-condition-true-content>
541
+ <data-condition-false-content>${n}</data-condition-false-content>
665
542
  </data-condition>
666
543
  `;
667
544
  }
@@ -672,17 +549,17 @@ class G {
672
549
  const e = t.init.declarations[0];
673
550
  if (e.id.type !== "Identifier")
674
551
  return this.addMessage("warning", "Unsupported for loop variable declaration id"), "";
675
- let n = "";
552
+ let s = "";
676
553
  if (e.init)
677
- n = this.getExpressionString(e.init);
554
+ s = this.getExpressionString(e.init);
678
555
  else
679
556
  return this.addMessage("warning", "For loop collection is undefined"), "";
680
- const s = e.id.name, r = s;
681
- this.collectionStack.push(s);
557
+ const n = e.id.name, r = n;
558
+ this.collectionStack.push(n);
682
559
  const i = this.astToGrapesJS(t.body);
683
560
  return this.collectionStack.pop(), `
684
561
  <data-collection data-gjs-data-resolver='${JSON.stringify({
685
- dataSource: { type: "data-variable", path: n },
562
+ dataSource: { type: "data-variable", path: s },
686
563
  collectionId: r
687
564
  })}'>
688
565
  <data-collection-item>
@@ -692,13 +569,13 @@ class G {
692
569
  `;
693
570
  }
694
571
  handleForEachStatement(t) {
695
- const e = this.getExpressionString(t.collection), n = t.itemIdentifier.name, s = n;
696
- this.collectionStack.push(n);
572
+ const e = this.getExpressionString(t.collection), s = t.itemIdentifier.name, n = s;
573
+ this.collectionStack.push(s);
697
574
  const r = this.astToGrapesJS(t.body);
698
575
  return this.collectionStack.pop(), `
699
576
  <data-collection data-gjs-data-resolver='${JSON.stringify({
700
577
  dataSource: { type: "data-variable", path: e },
701
- collectionId: s
578
+ collectionId: n
702
579
  })}'>
703
580
  <data-collection-item>
704
581
  ${r}
@@ -708,8 +585,8 @@ class G {
708
585
  }
709
586
  handleBlockStatement(t) {
710
587
  let e = "";
711
- for (const n of t.body)
712
- e += this.astToGrapesJS(n);
588
+ for (const s of t.body)
589
+ e += this.astToGrapesJS(s);
713
590
  return e;
714
591
  }
715
592
  handleLiteral(t) {
@@ -718,16 +595,16 @@ class G {
718
595
  handleIdentifier(t) {
719
596
  let e = { path: t.name };
720
597
  if (this.collectionStack.length > 0) {
721
- const n = this.collectionStack[this.collectionStack.length - 1];
722
- t.name === n && (e = {
723
- collectionId: n,
598
+ const s = this.collectionStack[this.collectionStack.length - 1];
599
+ t.name === s && (e = {
600
+ collectionId: s,
724
601
  variableType: "currentItem"
725
602
  });
726
603
  }
727
604
  return `<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`;
728
605
  }
729
606
  handleMemberExpression(t, e = {}) {
730
- let s = { path: this.getExpressionString(t), ...e };
607
+ let n = { path: this.getExpressionString(t), ...e };
731
608
  if (this.collectionStack.length > 0) {
732
609
  const r = this.collectionStack[this.collectionStack.length - 1];
733
610
  let i = t;
@@ -736,7 +613,7 @@ class G {
736
613
  i.property.type === "Identifier" && !i.computed ? a.unshift(i.property.name) : i.property.type === "Literal" && i.computed ? a.unshift(String(i.property.value)) : a.unshift(this.getExpressionString(i.property)), i = i.object;
737
614
  if (i.type === "Identifier" && i.name === r) {
738
615
  const c = a.join(".");
739
- s = {
616
+ n = {
740
617
  ...e,
741
618
  collectionId: r,
742
619
  variableType: "currentItem",
@@ -744,7 +621,7 @@ class G {
744
621
  };
745
622
  }
746
623
  }
747
- return `<data-variable data-gjs-data-resolver='${JSON.stringify(s)}'></data-variable>`;
624
+ return `<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`;
748
625
  }
749
626
  handleBinaryExpression(t) {
750
627
  return `${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`;
@@ -757,8 +634,8 @@ class G {
757
634
  handleCallExpression(t) {
758
635
  var e;
759
636
  if (t.callee.type === "Identifier" && t.callee.name === "include") {
760
- const n = ((e = t.arguments[0]) == null ? void 0 : e.type) === "Literal" ? String(t.arguments[0].value) : "";
761
- return this.addMessage("info", `Partial includes are not fully supported: ${n}`), "";
637
+ const s = ((e = t.arguments[0]) == null ? void 0 : e.type) === "Literal" ? String(t.arguments[0].value) : "";
638
+ return this.addMessage("info", `Partial includes are not fully supported: ${s}`), "";
762
639
  }
763
640
  return "";
764
641
  }
@@ -774,20 +651,20 @@ class G {
774
651
  ]
775
652
  };
776
653
  if (t.type === "MemberExpression") {
777
- let e = this.getExpressionString(t), n = "isTruthy";
778
- return e.startsWith("!!") ? (n = "isTruthy", e = e.slice(2)) : e.startsWith("!") && (n = "isFalsy", e = e.slice(1)), {
654
+ let e = this.getExpressionString(t), s = "isTruthy";
655
+ return e.startsWith("!!") ? (s = "isTruthy", e = e.slice(2)) : e.startsWith("!") && (s = "isFalsy", e = e.slice(1)), {
779
656
  logicalOperator: "and",
780
657
  statements: [
781
658
  {
782
659
  left: { type: "data-variable", path: e },
783
- operator: n
660
+ operator: s
784
661
  }
785
662
  ]
786
663
  };
787
664
  }
788
665
  if (t.type === "BinaryExpression" || t.type === "LogicalExpression") {
789
- const e = this.getConditionExpression(t.left), n = this.getConditionExpression(t.right);
790
- return `${e} ${t.operator} ${n}`;
666
+ const e = this.getConditionExpression(t.left), s = this.getConditionExpression(t.right);
667
+ return `${e} ${t.operator} ${s}`;
791
668
  }
792
669
  return t.type === "Literal" ? typeof t.value == "string" ? `'${t.value}'` : String(t.value ?? "") : this.getExpressionString(t);
793
670
  }
@@ -798,16 +675,16 @@ class G {
798
675
  case "Literal":
799
676
  return String(t.value ?? "");
800
677
  case "MemberExpression": {
801
- const e = this.getExpressionString(t.object), n = this.getExpressionString(t.property);
802
- return t.computed ? `${e}[${n}]` : `${e}.${n}`;
678
+ const e = this.getExpressionString(t.object), s = this.getExpressionString(t.property);
679
+ return t.computed ? `${e}[${s}]` : `${e}.${s}`;
803
680
  }
804
681
  case "BinaryExpression": {
805
- const e = this.getExpressionString(t.left), n = this.getExpressionString(t.right);
806
- return `${e} ${t.operator} ${n}`;
682
+ const e = this.getExpressionString(t.left), s = this.getExpressionString(t.right);
683
+ return `${e} ${t.operator} ${s}`;
807
684
  }
808
685
  case "LogicalExpression": {
809
- const e = this.getExpressionString(t.left), n = this.getExpressionString(t.right);
810
- return `${e} ${t.operator} ${n}`;
686
+ const e = this.getExpressionString(t.left), s = this.getExpressionString(t.right);
687
+ return `${e} ${t.operator} ${s}`;
811
688
  }
812
689
  default:
813
690
  return this.addMessage("warning", `Unsupported expression type for getExpressionString: ${t.type}`), "";
@@ -820,21 +697,21 @@ class G {
820
697
  });
821
698
  }
822
699
  }
823
- const R = "dataSourceEjs", K = g.startup, z = function(o, t = {}) {
824
- const e = F(o, new U()), n = H(o, {
700
+ const U = "dataSourceEjs", D = g.startup, V = function(o, t = {}) {
701
+ const e = M(o, new A()), s = W(o, {
825
702
  contains: "<%",
826
- importer: new G()
703
+ importer: new F()
827
704
  });
828
- B({
705
+ N({
829
706
  editor: o,
830
707
  licenseKey: t.licenseKey,
831
- plan: K,
832
- pluginName: R,
708
+ plan: D,
709
+ pluginName: U,
833
710
  cleanup: () => {
834
- e(), n();
711
+ e(), s();
835
712
  }
836
713
  });
837
- }, Z = M(z);
714
+ }, G = v(V);
838
715
  export {
839
- Z as default
716
+ G as default
840
717
  };