@grapesjs/studio-sdk-plugins 1.0.22 → 1.0.23

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,7 +1,7 @@
1
- import I from "handlebars/dist/cjs/handlebars";
2
- const b = "app.grapesjs.com", x = "app-stage.grapesjs.com", y = [
1
+ import L from "handlebars/dist/cjs/handlebars";
2
+ const C = "app.grapesjs.com", b = "app-stage.grapesjs.com", y = [
3
+ C,
3
4
  b,
4
- x,
5
5
  "localhost",
6
6
  "127.0.0.1",
7
7
  ".local-credentialless.webcontainer.io",
@@ -10,96 +10,96 @@ const b = "app.grapesjs.com", x = "app-stage.grapesjs.com", y = [
10
10
  // For stackblitz.com demos
11
11
  "-sandpack.codesandbox.io"
12
12
  // For Sandpack demos
13
- ], P = "license:check:start", T = "license:check:end", k = () => typeof window < "u", L = ({ isDev: r, isStage: t }) => `${r ? "" : `https://${t ? x : b}`}/api`, w = () => {
14
- const r = k() && window.location.hostname;
13
+ ], k = "license:check:start", T = "license:check:end", N = () => typeof window < "u", _ = ({ isDev: r, isStage: t }) => `${r ? "" : `https://${t ? b : C}`}/api`, w = () => {
14
+ const r = N() && window.location.hostname;
15
15
  return !!r && (y.includes(r) || y.some((t) => r.endsWith(t)));
16
16
  };
17
- async function N({
17
+ async function H({
18
18
  path: r,
19
19
  baseApiUrl: t,
20
- method: n = "GET",
21
- headers: e = {},
20
+ method: e = "GET",
21
+ headers: n = {},
22
22
  params: a,
23
23
  body: s
24
24
  }) {
25
- const o = `${t || L({ isDev: !1, isStage: !1 })}${r}`, h = {
26
- method: n,
25
+ const o = `${t || _({ isDev: !1, isStage: !1 })}${r}`, c = {
26
+ method: e,
27
27
  headers: {
28
28
  "Content-Type": "application/json",
29
- ...e
29
+ ...n
30
30
  }
31
31
  };
32
- s && (h.body = JSON.stringify(s));
33
- const l = a ? new URLSearchParams(a).toString() : "", c = l ? `?${l}` : "", u = await fetch(`${o}${c}`, h);
32
+ s && (c.body = JSON.stringify(s));
33
+ const h = a ? new URLSearchParams(a).toString() : "", l = h ? `?${h}` : "", u = await fetch(`${o}${l}`, c);
34
34
  if (!u.ok)
35
35
  throw new Error(`HTTP error! status: ${u.status}`);
36
36
  return u.json();
37
37
  }
38
- var p = /* @__PURE__ */ ((r) => (r.free = "free", r.startup = "startup", r.business = "business", r.enterprise = "enterprise", r))(p || {});
39
- const $ = {
40
- [p.free]: 0,
41
- [p.startup]: 10,
42
- [p.business]: 20,
43
- [p.enterprise]: 30
38
+ var d = /* @__PURE__ */ ((r) => (r.free = "free", r.startup = "startup", r.business = "business", r.enterprise = "enterprise", r))(d || {});
39
+ const P = {
40
+ [d.free]: 0,
41
+ [d.startup]: 10,
42
+ [d.business]: 20,
43
+ [d.enterprise]: 30
44
44
  };
45
- function H(r) {
45
+ function M(r) {
46
46
  const t = r;
47
- return t.init = (n) => (e) => r(e, n), t;
47
+ return t.init = (e) => (n) => r(n, e), t;
48
48
  }
49
- const M = (r) => /* @__PURE__ */ H(r);
50
- async function _({
49
+ const O = (r) => /* @__PURE__ */ M(r);
50
+ async function R({
51
51
  editor: r,
52
52
  plan: t,
53
- pluginName: n,
54
- licenseKey: e,
53
+ pluginName: e,
54
+ licenseKey: n,
55
55
  cleanup: a
56
56
  }) {
57
57
  let s = "", i = !1;
58
- const o = w(), h = (c) => {
59
- console.warn("Cleanup plugin:", n, "Reason:", c), a();
60
- }, l = (c = {}) => {
61
- var S;
62
- const { error: u, sdkLicense: C } = c, m = (S = c.plan) == null ? void 0 : S.category;
63
- if (!(C || c.license) || u)
64
- h(u || "Invalid license");
58
+ const o = w(), c = (l) => {
59
+ console.warn("Cleanup plugin:", e, "Reason:", l), a();
60
+ }, h = (l = {}) => {
61
+ var $;
62
+ const { error: u, sdkLicense: E } = l, m = ($ = l.plan) == null ? void 0 : $.category;
63
+ if (!(E || l.license) || u)
64
+ c(u || "Invalid license");
65
65
  else if (m) {
66
- const E = $[t], v = $[m];
67
- E > v && h({ pluginRequiredPlan: t, licensePlan: m });
66
+ const v = P[t], I = P[m];
67
+ v > I && c({ pluginRequiredPlan: t, licensePlan: m });
68
68
  }
69
69
  };
70
- r.on(P, (c) => {
71
- s = c == null ? void 0 : c.baseApiUrl, i = !0;
72
- }), r.on(T, (c) => {
73
- l(c);
70
+ r.on(k, (l) => {
71
+ s = l == null ? void 0 : l.baseApiUrl, i = !0;
72
+ }), r.on(T, (l) => {
73
+ h(l);
74
74
  }), setTimeout(async () => {
75
75
  if (!i) {
76
76
  if (o) return;
77
- if (e) {
78
- const c = await j({ licenseKey: e, pluginName: n, baseApiUrl: s });
79
- c && l(c);
77
+ if (n) {
78
+ const l = await A({ licenseKey: n, pluginName: e, baseApiUrl: s });
79
+ l && h(l);
80
80
  } else
81
- h("The `licenseKey` option not provided");
81
+ c("The `licenseKey` option not provided");
82
82
  }
83
83
  }, 2e3);
84
84
  }
85
- async function j(r) {
86
- const { licenseKey: t, pluginName: n, baseApiUrl: e } = r;
85
+ async function A(r) {
86
+ const { licenseKey: t, pluginName: e, baseApiUrl: n } = r;
87
87
  try {
88
- return (await N({
89
- baseApiUrl: e,
88
+ return (await H({
89
+ baseApiUrl: n,
90
90
  path: `/sdk/${t || "na"}`,
91
91
  method: "POST",
92
92
  params: {
93
93
  d: window.location.hostname,
94
- pn: n
94
+ pn: e
95
95
  }
96
96
  })).result || {};
97
97
  } catch (a) {
98
98
  return console.error("Error during SDK license check:", a), !1;
99
99
  }
100
100
  }
101
- var d = /* @__PURE__ */ ((r) => (r.variable = "data-variable", r.condition = "data-condition", r.conditionTrue = "data-condition-true-content", r.conditionFalse = "data-condition-false-content", r.collection = "data-collection", r.collectionItem = "data-collection-item", r))(d || {});
102
- class B {
101
+ var p = /* @__PURE__ */ ((r) => (r.variable = "data-variable", r.condition = "data-condition", r.conditionTrue = "data-condition-true-content", r.conditionFalse = "data-condition-false-content", r.collection = "data-collection", r.collectionItem = "data-collection-item", r))(p || {});
102
+ class D {
103
103
  constructor(t) {
104
104
  this.strategy = t, this.requiredHelpers = /* @__PURE__ */ new Set(), this.helperLibrary = {};
105
105
  }
@@ -128,47 +128,48 @@ class B {
128
128
  this.requiredHelpers.clear();
129
129
  }
130
130
  }
131
- function O(r) {
132
- return typeof r == "object" && r.type === d.variable;
131
+ function j(r) {
132
+ return typeof r == "object" && r.type === p.variable;
133
133
  }
134
134
  function g({
135
135
  component: r,
136
136
  value: t,
137
- getCustomPath: n
137
+ getCustomPath: e
138
138
  }) {
139
- if (O(t) && !t.collectionId && n) {
140
- const e = t.path ?? "", a = e.split(".");
139
+ if (j(t) && !t.collectionId && e) {
140
+ const n = t.path ?? "", a = n.split(".");
141
141
  return {
142
142
  ...t,
143
- path: n({ component: r, path: e, paths: a })
143
+ path: e({ component: r, path: n, paths: a })
144
144
  };
145
145
  }
146
146
  return t;
147
147
  }
148
- const D = (r) => {
149
- f(r, d.variable, {
148
+ const V = (r) => {
149
+ f(r, p.variable, {
150
150
  toHTML(t) {
151
151
  var i;
152
- const n = this.tagName, e = this.__attrToString(t), a = (i = this.getDataResolver) == null ? void 0 : i.call(this), s = g({
152
+ const e = this.tagName, n = this.__attrToString(t), a = (i = this.getDataResolver) == null ? void 0 : i.call(this), s = g({
153
153
  component: this,
154
154
  value: a,
155
155
  getCustomPath: t == null ? void 0 : t.getCustomPath
156
156
  });
157
- return `<${n}${e ? ` ${e}` : ""}>${t.exporter.generateVariable(s)}</${n}>`;
157
+ return `<${e}${n ? ` ${n}` : ""}>${t.exporter.generateVariable(s)}</${e}>`;
158
158
  }
159
- }), f(r, d.condition, {
159
+ }), f(r, p.condition, {
160
160
  toHTML(t) {
161
- var l, c;
162
- const n = t.exporter, e = t == null ? void 0 : t.getCustomPath, a = this.components(), [s, i] = (a == null ? void 0 : a.models) ?? [], o = (l = this.getDataResolver) == null ? void 0 : l.call(this), h = ((c = this.resolveCondition) == null ? void 0 : c.call(this, o == null ? void 0 : o.condition, e)) ?? {};
163
- return `
164
- ${n.generateConditionalStart(h)}
165
- ${(s == null ? void 0 : s.toHTML(t)) ?? ""}
166
- ${n.generateConditionElse()}
167
- ${(i == null ? void 0 : i.toHTML(t)) ?? ""}
168
- ${n.generateConditionalEnd()}
161
+ var l, u;
162
+ const e = t.exporter, n = t == null ? void 0 : t.getCustomPath, a = this.components(), [s, i] = (a == null ? void 0 : a.models) ?? [], o = (l = this.getDataResolver) == null ? void 0 : l.call(this), c = ((u = this.resolveCondition) == null ? void 0 : u.call(this, o == null ? void 0 : o.condition, n)) ?? {};
163
+ let h = "";
164
+ return i && (h = `
165
+ ${e.generateConditionElse()}
166
+ ${i.toHTML(t) ?? ""}`), `
167
+ ${e.generateConditionalStart(c)}
168
+ ${(s == null ? void 0 : s.toHTML(t)) ?? ""}${h}
169
+ ${e.generateConditionalEnd()}
169
170
  `;
170
171
  },
171
- resolveCondition(t, n) {
172
+ resolveCondition(t, e) {
172
173
  var a, s;
173
174
  if (!t) return {};
174
175
  if (t.operator === "and" || t.operator === "or")
@@ -176,19 +177,19 @@ ${n.generateConditionalStart(h)}
176
177
  operator: t.operator,
177
178
  statements: ((s = (a = t.statements) == null ? void 0 : a.map) == null ? void 0 : s.call(a, (i) => {
178
179
  var o;
179
- return ((o = this.resolveCondition) == null ? void 0 : o.call(this, i, n)) ?? {};
180
+ return ((o = this.resolveCondition) == null ? void 0 : o.call(this, i, e)) ?? {};
180
181
  })) ?? []
181
182
  };
182
- const e = { component: this, getCustomPath: n };
183
+ const n = { component: this, getCustomPath: e };
183
184
  return {
184
185
  ...t,
185
- left: g({ ...e, value: t.left }),
186
- right: g({ ...e, value: t.right })
186
+ left: g({ ...n, value: t.left }),
187
+ right: g({ ...n, value: t.right })
187
188
  };
188
189
  }
189
- }), f(r, d.collection, {
190
+ }), f(r, p.collection, {
190
191
  toHTML(t) {
191
- const n = t.exporter, e = this.tagName, a = this.__attrToString(t), s = this.getDataResolver(), i = {
192
+ const e = t.exporter, n = this.tagName, a = this.__attrToString(t), s = this.getDataResolver(), i = {
192
193
  ...s,
193
194
  dataSource: g({
194
195
  component: this,
@@ -197,90 +198,93 @@ ${n.generateConditionalStart(h)}
197
198
  })
198
199
  }, o = this.components().at(0);
199
200
  return `
200
- <${e}${a ? ` ${a}` : ""}>${n.generateCollectionStart(i)}
201
+ <${n}${a ? ` ${a}` : ""}>${e.generateCollectionStart(i)}
201
202
  ${(o == null ? void 0 : o.toHTML(t)) ?? ""}
202
- ${n.generateCollectionEnd()}</${e}>
203
+ ${e.generateCollectionEnd()}</${n}>
203
204
  `;
204
205
  }
205
206
  });
206
- }, f = (r, t, n) => {
207
- const e = r.Components.getType(t);
208
- if (!e) {
207
+ }, f = (r, t, e) => {
208
+ const n = r.Components.getType(t);
209
+ if (!n) {
209
210
  console.warn(`Component type ${t} not found`);
210
211
  return;
211
212
  }
212
- const { model: a } = e;
213
+ const { model: a } = n;
213
214
  r.Components.addType(t, {
214
215
  model: {
215
- ...n,
216
+ ...e,
216
217
  toHTML(s = {}) {
217
218
  var o;
218
219
  const { exporter: i } = s;
219
- return i ? i.export ? i.export({ component: this }) : ((o = n.toHTML) == null ? void 0 : o.call(this, s)) ?? "" : a.prototype.toHTML.call(this, s) ?? "";
220
+ return i ? i.export ? i.export({ component: this }) : ((o = e.toHTML) == null ? void 0 : o.call(this, s)) ?? "" : a.prototype.toHTML.call(this, s) ?? "";
220
221
  }
221
222
  }
222
223
  });
223
- }, V = (r, t) => (r.config.optsHtml = {
224
+ }, B = (r, t) => (r.config.optsHtml = {
224
225
  ...r.config.optsHtml,
225
- exporter: new B(t)
226
- }, D(r), () => {
226
+ exporter: new D(t)
227
+ }, V(r), () => {
227
228
  r.config.optsHtml.exporter = void 0;
228
229
  }), U = (r, t) => {
229
- const n = (a) => {
230
+ const e = (a) => {
230
231
  const { input: s } = a, { contains: i } = t;
231
232
  (!i || s.includes(i)) && (a.input = t.importer.import(s));
232
- }, e = r.Parser.events.htmlBefore;
233
- return r.on(e, n), () => {
234
- r.off(e, n);
233
+ }, n = r.Parser.events.htmlBefore;
234
+ return r.on(n, e), () => {
235
+ r.off(n, e);
235
236
  };
237
+ }, x = {
238
+ equals: "equals",
239
+ isTruthy: "isTruthy",
240
+ isFalsy: "isFalsy",
241
+ isDefined: "isDefined",
242
+ isNull: "isNull",
243
+ isUndefined: "isUndefined",
244
+ isArray: "isArray",
245
+ isObject: "isObject",
246
+ isString: "isString",
247
+ isNumber: "isNumber",
248
+ isBoolean: "isBoolean",
249
+ isDefaultValue: "isDefaultValue"
250
+ }, W = {
251
+ ">": "numGt",
252
+ "<": "numLt",
253
+ ">=": "numGte",
254
+ "<=": "numLte",
255
+ "=": "numEq",
256
+ "!=": "numNeq"
257
+ }, q = {
258
+ contains: "strContains",
259
+ startsWith: "strStartsWith",
260
+ endsWith: "strEndsWith",
261
+ equalsIgnoreCase: "strEqualsIgnoreCase",
262
+ trimEquals: "strTrimEquals"
263
+ }, G = {
264
+ ...x,
265
+ ...W,
266
+ ...q
236
267
  };
237
- class W {
238
- getHelperId(t, n) {
239
- return {
240
- // AnyTypeOperation
241
- equals: `${n === "string" ? "str" : n === "number" ? "num" : "any"}Equals`,
242
- isTruthy: "isTruthy",
243
- isFalsy: "isFalsy",
244
- isDefined: "isDefined",
245
- isNull: "isNull",
246
- isUndefined: "isUndefined",
247
- isArray: "isArray",
248
- isObject: "isObject",
249
- isString: "isString",
250
- isNumber: "isNumber",
251
- isBoolean: "isBoolean",
252
- isDefaultValue: "isDefaultValue",
253
- // NumberOperation
254
- ">": "numGt",
255
- "<": "numLt",
256
- ">=": "numGte",
257
- "<=": "numLte",
258
- "=": "numEq",
259
- "!=": "numNeq",
260
- // StringOperation
261
- contains: "strContains",
262
- startsWith: "strStartsWith",
263
- endsWith: "strEndsWith",
264
- equalsIgnoreCase: "strEqualsIgnoreCase",
265
- trimEquals: "strTrimEquals"
266
- }[t] || t;
267
- }
268
- getFullPath({ collectionId: t, path: n }) {
269
- let e = n;
270
- return t && (e = [this._sanitizeVariableName(t), n].filter(Boolean).join(".")), e || "";
268
+ class F {
269
+ getHelperId(t) {
270
+ return G[t] || t;
271
+ }
272
+ getFullPath({ collectionId: t, path: e }) {
273
+ let n = e;
274
+ return t && (n = [this._sanitizeVariableName(t), e].filter(Boolean).join(".")), n || "";
271
275
  }
272
276
  getVariableSyntax(t) {
273
- const { defaultValue: n } = t, e = this.getFullPath(t);
274
- return n ? `{{#if ${e}}}{{{${e}}}}{{else}}${n}{{/if}}` : `{{{${e}}}}`;
277
+ const { defaultValue: e } = t, n = this.getFullPath(t);
278
+ return e ? `{{#if ${n}}}{{{${n}}}}{{else}}${e}{{/if}}` : `{{{${n}}}}`;
275
279
  }
276
280
  getCollectionStartSyntax(t) {
277
- const { collectionId: n, dataSource: e } = t, a = e == null ? void 0 : e.path;
281
+ const { collectionId: e, dataSource: n } = t, a = n == null ? void 0 : n.path;
278
282
  let s = "";
279
283
  if (t.startIndex !== void 0 || t.endIndex !== void 0) {
280
- const l = t.startIndex ?? 0, c = t.endIndex !== void 0 ? t.endIndex : "";
281
- c !== "" ? s = ` (slice ${a} ${l} ${c})` : s = ` (slice ${a} ${l})`;
284
+ const h = t.startIndex ?? 0, l = t.endIndex !== void 0 ? t.endIndex : "";
285
+ l !== "" ? s = ` (slice ${a} ${h} ${l})` : s = ` (slice ${a} ${h})`;
282
286
  }
283
- const o = ` as |${this._sanitizeVariableName(n)}|`;
287
+ const o = ` as |${this._sanitizeVariableName(e)}|`;
284
288
  return `{{#each ${s || a}${o}}}`;
285
289
  }
286
290
  getCollectionEndSyntax() {
@@ -288,26 +292,26 @@ class W {
288
292
  }
289
293
  getConditionalStartSyntax(t) {
290
294
  if (!t) return "";
291
- const n = t, e = t;
292
- if (e.statements && e.logicalOperator === "and" || e.logicalOperator === "or") {
293
- const { statements: a } = e, s = e.logicalOperator, i = a.map((h) => this._parseCondition(h)).join(", ");
295
+ const e = t, n = t;
296
+ if (n.statements && n.logicalOperator === "and" || n.logicalOperator === "or") {
297
+ const { statements: a } = n, s = n.logicalOperator, i = a.map((c) => this._parseCondition(c)).join(" ");
294
298
  return `{{#if ${a.length > 1 ? `(${s} ${i})` : i}}}`;
295
299
  } else
296
- return `{{#if ${this._parseCondition(n)}}}`;
300
+ return `{{#if ${this._parseCondition(e)}}}`;
297
301
  }
298
302
  _parseCondition(t) {
299
303
  if (!t) return "";
300
- const n = t, e = t;
301
- if (e.statements && e.logicalOperator === "and" || e.logicalOperator === "or") {
302
- const { statements: a } = e, s = e.logicalOperator, i = e.statements.map((o) => this._parseCondition(o)).join(" ");
304
+ const e = t, n = t;
305
+ if (n.statements && n.logicalOperator === "and" || n.logicalOperator === "or") {
306
+ const { statements: a } = n, s = n.logicalOperator, i = n.statements.map((o) => this._parseCondition(o)).join(" ");
303
307
  return a.length > 1 ? `(${s} ${i})` : i;
304
308
  } else {
305
- const a = this.getHelperId(n.operator, this._getTypeHint(t)), s = this._parseValue(n.left), i = this._parseValue(n.right);
306
- return `(${a} ${s} ${i})`;
309
+ const a = e.operator, s = this.getHelperId(a), i = this._parseValue(e.left), o = this._parseValue(e.right);
310
+ return this.getExpressionStr(s, i, o);
307
311
  }
308
312
  }
309
- _getTypeHint(t) {
310
- return ["contains", "startsWith", "endsWith", "equalsIgnoreCase", "trimEquals"].includes(t.operator) ? "string" : [">", "<", ">=", "<=", "=", "!="].includes(t.operator) ? "number" : "any";
313
+ getExpressionStr(t, e, n) {
314
+ return x[t] ? t === "isTruthy" ? e : t === "isFalsy" ? `!${e}` : `${t} ${e}` : `(${t} ${e} ${n})`;
311
315
  }
312
316
  _parseValue(t) {
313
317
  return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
@@ -322,24 +326,24 @@ class W {
322
326
  return "{{/if}}";
323
327
  }
324
328
  }
325
- class q {
329
+ class J {
326
330
  constructor() {
327
331
  this.messages = [], this.collectionStack = [];
328
332
  }
329
333
  import(t) {
330
334
  this.messages = [], this.collectionStack = [];
331
- const n = this.parse(t);
332
- return this.astToGrapesJS(n);
335
+ const e = this.parse(t);
336
+ return this.astToGrapesJS(e);
333
337
  }
334
338
  parse(t) {
335
339
  try {
336
- return I.parse(t);
337
- } catch (n) {
338
- if (n instanceof Error && n.message.includes("Parse error")) {
339
- const e = n.message.match(/line (\d+)/), a = e ? parseInt(e[1]) : 0, s = n.message.match(/column (\d+)/), i = s ? parseInt(s[1]) : 0;
340
- throw new Error(`Handlebars syntax error at line ${a}, column ${i}: ${n.message}`);
340
+ return L.parse(t);
341
+ } catch (e) {
342
+ if (e instanceof Error && e.message.includes("Parse error")) {
343
+ const n = e.message.match(/line (\d+)/), a = n ? parseInt(n[1]) : 0, s = e.message.match(/column (\d+)/), i = s ? parseInt(s[1]) : 0;
344
+ throw new Error(`Handlebars syntax error at line ${a}, column ${i}: ${e.message}`);
341
345
  }
342
- throw n;
346
+ throw e;
343
347
  }
344
348
  }
345
349
  astToGrapesJS(t) {
@@ -365,71 +369,91 @@ class q {
365
369
  }
366
370
  }
367
371
  handleProgram(t) {
368
- let n = "";
372
+ let e = "";
369
373
  if (t.body)
370
- for (const e of t.body)
371
- n += this.astToGrapesJS(e);
372
- return n;
374
+ for (const n of t.body)
375
+ e += this.astToGrapesJS(n);
376
+ return e;
373
377
  }
374
378
  handleContentStatement(t) {
375
379
  return t.value || "";
376
380
  }
377
- handleMustacheStatement(t, n = {}) {
378
- const e = this.getExpressionString(t.path), a = n;
379
- if (this.collectionStack.length > 0)
380
- if (e.startsWith("@")) {
381
- const s = e.split("/");
382
- let i = 0;
383
- const o = s[s.length - 1];
384
- for (let l = 0; l < s.length - 1; l++)
385
- s[l] === ".." && i++;
386
- const h = Math.max(0, this.collectionStack.length - 1 - i);
387
- if (h >= 0 && h < this.collectionStack.length) {
388
- const l = this.collectionStack[h];
389
- o === "index" || o === "@index" ? (a.collectionId = l, a.variableType = "currentIndex") : o === "key" || o === "@key" ? (a.collectionId = l, a.variableType = "currentKey") : o === "first" || o === "@first" ? (a.collectionId = l, a.variableType = "isFirst") : o === "last" || o === "@last" ? (a.collectionId = l, a.variableType = "isLast") : a.path = e;
390
- } else
391
- a.path = e;
392
- } else {
393
- const s = e.split("/");
394
- let i = 0;
395
- for (; s[0] === ".."; )
396
- i++, s.shift();
397
- const o = s.join("/"), h = this.collectionStack.length - 1 - i;
398
- if (h >= 0 && h < this.collectionStack.length) {
399
- const l = this.collectionStack[h];
400
- o === "this" ? (a.collectionId = l, a.variableType = "currentItem") : (a.collectionId = l, a.variableType = "currentItem", a.path = o.startsWith("this.") ? o.split(".").slice(1).join(".") : o);
401
- } else
402
- a.path = `globalData.${s.join(".")}`;
403
- }
404
- else
405
- a.path = e;
406
- return `<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`;
381
+ handleMustacheStatement(t, e = {}) {
382
+ const n = this.getExpressionString(t.path), a = { ...e };
383
+ return this.collectionStack.length > 0 ? this.processPathWithCollectionContext(n, a) : a.path = n, `<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`;
384
+ }
385
+ processPathWithCollectionContext(t, e) {
386
+ t.startsWith("@") ? this.handleDirectCollectionReference(t, e) : this.handleRelativePathReference(t, e);
387
+ }
388
+ handleDirectCollectionReference(t, e) {
389
+ if (this.isSpecialIterationVariable(t)) {
390
+ this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length - 1], t, e);
391
+ return;
392
+ }
393
+ const [n, ...a] = t.substring(1).split("/"), s = a.join(".");
394
+ this.collectionStack.includes(n) ? this.setCurrentItemResolver(n, s, e) : this.handleParentReferenceFallback(t, e);
395
+ }
396
+ isSpecialIterationVariable(t) {
397
+ return ["index", "@index", "key", "@key"].includes(t);
398
+ }
399
+ setSpecialVariableResolver(t, e, n) {
400
+ n.collectionId = t;
401
+ const a = {
402
+ index: "currentIndex",
403
+ "@index": "currentIndex",
404
+ key: "currentKey",
405
+ "@key": "currentKey"
406
+ };
407
+ n.variableType = a[e];
408
+ }
409
+ setCurrentItemResolver(t, e, n) {
410
+ n.collectionId = t, n.variableType = "currentItem", e && (n.path = e);
411
+ }
412
+ handleRelativePathReference(t, e) {
413
+ const n = S(t), { parentLevel: a, remainingPathParts: s } = this.calculateParentLevel(n), i = s.join("."), o = this.collectionStack.length - 1 - a;
414
+ o >= 0 && o < this.collectionStack.length ? this.resolveRelativePath(i, o, e) : e.path = s.join(".");
415
+ }
416
+ calculateParentLevel(t) {
417
+ const e = this.collectionStack.findLastIndex((s) => s === t[0]);
418
+ if (e !== -1)
419
+ return { parentLevel: this.collectionStack.length - 1 - e, remainingPathParts: t.slice(1) };
420
+ let n = 0;
421
+ const a = [...t];
422
+ for (; a[0] === ".."; )
423
+ n++, a.shift();
424
+ return { parentLevel: n, remainingPathParts: a };
425
+ }
426
+ resolveRelativePath(t, e, n) {
427
+ const a = this.collectionStack[e];
428
+ n.collectionId = a, n.variableType = "currentItem", t !== "this" && (n.path = t.startsWith("this.") ? t.split(".").slice(1).join(".") : t);
429
+ }
430
+ handleParentReferenceFallback(t, e) {
431
+ const n = S(t), { parentLevel: a, remainingPathParts: s } = this.calculateParentLevel(n), i = s.join("."), o = this.collectionStack.length - 1 - a;
432
+ o >= 0 && o < this.collectionStack.length ? this.resolveRelativePath(i, o, e) : e.path = s.join(".");
407
433
  }
408
434
  handleBlockStatement(t) {
409
- const n = t.path.original;
410
- switch (n) {
435
+ const e = t.path.original;
436
+ switch (e) {
411
437
  case "if":
412
438
  case "unless":
413
- return this.handleConditionalBlock(t, n);
439
+ return this.handleConditionalBlock(t, e);
414
440
  case "each":
415
441
  return this.handleEachBlock(t);
416
442
  default:
417
- return this.addMessage("warning", `Unsupported block helper: ${n}`, t.loc), this.handleGenericBlock(t);
443
+ return this.addMessage("warning", `Unsupported block helper: ${e}`, t.loc), this.handleGenericBlock(t);
418
444
  }
419
445
  }
420
- handleConditionalBlock(t, n) {
446
+ handleConditionalBlock(t, e) {
421
447
  const s = {
422
448
  logicalOperator: "and",
423
449
  statements: [
424
450
  {
425
451
  left: { type: "data-variable", path: this.getExpressionString(t.params[0]) },
426
- operator: n === "unless" ? "isFalsy" : "isTruthy"
452
+ operator: e === "unless" ? "isFalsy" : "isTruthy"
427
453
  }
428
454
  ]
429
455
  }, i = this.handleProgram(t.program), o = t.inverse ? this.handleProgram(t.inverse) : "";
430
- return t.params[0].type === "PathExpression" ? this.handleMustacheStatement(t.program.body[0], {
431
- defaultValue: o
432
- }) : `
456
+ return `
433
457
  <data-condition data-gjs-data-resolver='${JSON.stringify({ condition: s })}'>
434
458
  <data-condition-true-content>${i}</data-condition-true-content>
435
459
  <data-condition-false-content>${o}</data-condition-false-content>
@@ -437,13 +461,15 @@ class q {
437
461
  `;
438
462
  }
439
463
  handleEachBlock(t) {
440
- const n = this.getExpressionString(t.params[0]), e = `collection-${Math.random().toString(36).substring(2, 10)}`;
441
- this.collectionStack.push(e);
464
+ var s, i, o;
465
+ const e = this.getExpressionString(t.params[0]);
466
+ let n;
467
+ t.params.length >= 3 && t.params[1] === "as" && ((s = t.params[2]) == null ? void 0 : s.type) === "PathExpression" ? n = t.params[2].original : (o = (i = t.program) == null ? void 0 : i.blockParams) != null && o.length ? n = t.program.blockParams[0] : n = `collection-${Math.random().toString(36).substring(2, 10)}`, this.collectionStack.push(n);
442
468
  const a = this.handleProgram(t.program);
443
469
  return this.collectionStack.pop(), `
444
470
  <data-collection data-gjs-data-resolver='${JSON.stringify({
445
- dataSource: { type: "data-variable", path: n },
446
- collectionId: e
471
+ dataSource: { type: "data-variable", path: e },
472
+ collectionId: n
447
473
  })}'>
448
474
  <data-collection-item>${a}</data-collection-item>
449
475
  </data-collection>
@@ -453,15 +479,15 @@ class q {
453
479
  return `<!--${t.value}-->`;
454
480
  }
455
481
  handleElementNode(t) {
456
- let n = "";
482
+ let e = "";
457
483
  if (t.attributes)
458
484
  for (const a of t.attributes)
459
- a.value.type === "TextNode" ? n += ` ${a.name}="${a.value.chars}"` : (this.addMessage("warning", `Complex attribute values not fully supported: ${a.name}`, t.loc), n += ` ${a.name}="${this.getExpressionString(a.value)}"`);
460
- let e = "";
485
+ a.value.type === "TextNode" ? e += ` ${a.name}="${a.value.chars}"` : (this.addMessage("warning", `Complex attribute values not fully supported: ${a.name}`, t.loc), e += ` ${a.name}="${this.getExpressionString(a.value)}"`);
486
+ let n = "";
461
487
  if (t.children)
462
488
  for (const a of t.children)
463
- e += this.astToGrapesJS(a);
464
- return `<${t.tag}${n}>${e}</${t.tag}>`;
489
+ n += this.astToGrapesJS(a);
490
+ return `<${t.tag}${e}>${n}</${t.tag}>`;
465
491
  }
466
492
  handleTextNode(t) {
467
493
  return t.chars || "";
@@ -470,35 +496,64 @@ class q {
470
496
  return this.addMessage("warning", `Partials are not fully supported: ${t.name.original}`, t.loc), `{{> ${t.name.original}}}`;
471
497
  }
472
498
  handleGenericBlock(t) {
473
- const n = this.handleProgram(t.program);
474
- return `<!-- Unsupported block: ${t.path.original} -->${n}`;
499
+ const e = this.handleProgram(t.program);
500
+ return `<!-- Unsupported block: ${t.path.original} -->${e}`;
475
501
  }
476
502
  getExpressionString(t) {
477
- return t.type === "PathExpression" ? t.original : t.type === "StringLiteral" ? t.value : t.type === "NumberLiteral" ? t.value.toString() : t.type === "BooleanLiteral" ? t.value ? "true" : "false" : t.type === "SubExpression" ? this.getExpressionString(t.params[0]) : t.type === "Hash" ? `{${t.pairs.map((e) => `${e.key}=${this.getExpressionString(e.value)}`).join(", ")}}` : (this.addMessage("warning", `Complex expression type not fully supported: ${t.type}`, t.loc), "");
503
+ return t.type === "PathExpression" ? t.original : t.type === "StringLiteral" ? t.value : t.type === "NumberLiteral" ? t.value.toString() : t.type === "BooleanLiteral" ? t.value ? "true" : "false" : t.type === "SubExpression" ? this.getExpressionString(t.params[0]) : t.type === "Hash" ? `{${t.pairs.map((n) => `${n.key}=${this.getExpressionString(n.value)}`).join(", ")}}` : (this.addMessage("warning", `Complex expression type not fully supported: ${t.type}`, t.loc), "");
478
504
  }
479
- addMessage(t, n, e) {
505
+ addMessage(t, e, n) {
480
506
  this.messages.push({
481
507
  type: t,
482
- message: n,
483
- location: e ? { line: e.start.line, column: e.start.column } : void 0
508
+ message: e,
509
+ location: n ? { line: n.start.line, column: n.start.column } : void 0
484
510
  });
485
511
  }
486
512
  }
487
- const A = "dataSourceHandlebars", G = p.startup, R = function(r, t = {}) {
488
- const n = V(r, new W()), e = U(r, {
513
+ const S = (r) => {
514
+ if (r == null || r === "")
515
+ return [];
516
+ if (r === ".")
517
+ return ["this"];
518
+ if (r === ".." || r === "../")
519
+ return [".."];
520
+ if (r.startsWith("../")) {
521
+ const i = r.substring(3);
522
+ return ["..", ...S(i)];
523
+ }
524
+ const t = [];
525
+ let e = 0, n = r.replace(
526
+ /\[(?:(['"])(.*?)\1|([^\]]*))\]/g,
527
+ (i, o, c, h) => {
528
+ const l = c !== void 0 ? c : h || "";
529
+ return t[e] = l, `__HANDLEBARS_PLACEHOLDER_${e++}__`;
530
+ }
531
+ );
532
+ n = n.replace(/\//g, ".");
533
+ const a = n.split("."), s = [];
534
+ for (const i of a) {
535
+ const o = /^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(i);
536
+ if (o) {
537
+ const c = parseInt(o[1], 10);
538
+ s.push(t[c]);
539
+ } else i !== "" && s.push(i);
540
+ }
541
+ return s;
542
+ }, K = "dataSourceHandlebars", z = d.startup, Y = function(r, t = {}) {
543
+ const e = B(r, new F()), n = U(r, {
489
544
  contains: "{{",
490
- importer: new q()
545
+ importer: new J()
491
546
  });
492
- _({
547
+ R({
493
548
  editor: r,
494
549
  licenseKey: t.licenseKey,
495
- plan: G,
496
- pluginName: A,
550
+ plan: z,
551
+ pluginName: K,
497
552
  cleanup: () => {
498
- n(), e();
553
+ e(), n();
499
554
  }
500
555
  });
501
- }, K = M(R);
556
+ }, X = O(Y);
502
557
  export {
503
- K as default
558
+ X as default
504
559
  };