@grapesjs/studio-sdk-plugins 1.0.21 → 1.0.22

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 (66) hide show
  1. package/dist/animationComponent/components/Animation.d.ts +6 -0
  2. package/dist/animationComponent/components/AnimationGroup.d.ts +4 -0
  3. package/dist/animationComponent/index.cjs.d.ts +3 -0
  4. package/dist/animationComponent/index.cjs.js +507 -0
  5. package/dist/animationComponent/index.d.ts +3 -0
  6. package/dist/animationComponent/index.es.d.ts +3 -0
  7. package/dist/animationComponent/index.es.js +1111 -0
  8. package/dist/animationComponent/index.umd.js +507 -0
  9. package/dist/animationComponent/shared.d.ts +3 -0
  10. package/dist/animationComponent/types.d.ts +28 -0
  11. package/dist/animationComponent/typesSchema.d.ts +48 -0
  12. package/dist/animationComponent/utils.d.ts +19 -0
  13. package/dist/dataSourceEjs/EjsExporter.d.ts +13 -0
  14. package/dist/dataSourceEjs/EjsImporter.d.ts +29 -0
  15. package/dist/dataSourceEjs/index.cjs.d.ts +2 -2
  16. package/dist/dataSourceEjs/index.cjs.js +24 -3
  17. package/dist/dataSourceEjs/index.d.ts +2 -2
  18. package/dist/dataSourceEjs/index.es.d.ts +2 -2
  19. package/dist/dataSourceEjs/index.es.js +697 -114
  20. package/dist/dataSourceEjs/index.umd.js +24 -3
  21. package/dist/dataSourceEjs/shared.d.ts +3 -0
  22. package/dist/dataSourceEjs/types.d.ts +2 -2
  23. package/dist/dataSourceEjs/typesSchema.d.ts +3 -0
  24. package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +16 -0
  25. package/dist/dataSourceHandlebars/HandlebarsImporter.d.ts +20 -0
  26. package/dist/dataSourceHandlebars/helperImplementations.d.ts +1 -0
  27. package/dist/dataSourceHandlebars/index.cjs.js +20 -1
  28. package/dist/dataSourceHandlebars/index.es.js +401 -99
  29. package/dist/dataSourceHandlebars/index.umd.js +20 -1
  30. package/dist/dataSourceHandlebars/shared.d.ts +3 -0
  31. package/dist/dataSourceHandlebars/types.d.ts +2 -2
  32. package/dist/dataSourceHandlebars/typesSchema.d.ts +3 -0
  33. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  34. package/dist/googleFontsAssetProvider/index.es.js +29 -29
  35. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  36. package/dist/iconifyComponent/index.cjs.js +2 -2
  37. package/dist/iconifyComponent/index.es.js +64 -64
  38. package/dist/iconifyComponent/index.umd.js +2 -2
  39. package/dist/index.cjs.d.ts +1 -0
  40. package/dist/index.cjs.js +587 -51
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.es.d.ts +1 -0
  43. package/dist/index.es.js +4809 -3046
  44. package/dist/index.umd.js +584 -48
  45. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  46. package/dist/layoutSidebarButtons/index.es.js +59 -59
  47. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  48. package/dist/presetPrintable/index.cjs.js +3 -3
  49. package/dist/presetPrintable/index.es.js +136 -131
  50. package/dist/presetPrintable/index.umd.js +4 -4
  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 +2 -2
  55. package/dist/rteTinyMce/index.es.js +67 -67
  56. package/dist/rteTinyMce/index.umd.js +2 -2
  57. package/dist/tableComponent/index.cjs.js +1 -1
  58. package/dist/tableComponent/index.es.js +14 -14
  59. package/dist/tableComponent/index.umd.js +1 -1
  60. package/dist/utilsDataSources.d.ts +28 -0
  61. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  62. package/dist/youtubeAssetProvider/index.es.js +26 -26
  63. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  64. package/package.json +2 -1
  65. package/dist/dataSourceEjs/EjsStrategy.d.ts +0 -15
  66. package/dist/dataSourceHandlebars/HandlebarsStrategy.d.ts +0 -17
@@ -1,7 +1,7 @@
1
- var g = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(g || {}), y = /* @__PURE__ */ ((e) => (e.toastAdd = "studio:toastAdd", e.dialogOpen = "studio:dialogOpen", e.dialogClose = "studio:dialogClose", e.sidebarLeftSet = "studio:sidebarLeft:set", e.sidebarLeftGet = "studio:sidebarLeft:get", e.sidebarLeftToggle = "studio:sidebarLeft:toggle", e.sidebarRightSet = "studio:sidebarRight:set", e.sidebarRightGet = "studio:sidebarRight:get", e.sidebarRightToggle = "studio:sidebarRight:toggle", e.sidebarTopSet = "studio:sidebarTop:set", e.sidebarTopGet = "studio:sidebarTop:get", e.sidebarTopToggle = "studio:sidebarTop:toggle", e.sidebarBottomSet = "studio:sidebarBottom:set", e.sidebarBottomGet = "studio:sidebarBottom:get", e.sidebarBottomToggle = "studio:sidebarBottom:toggle", e.symbolAdd = "studio:symbolAdd", e.symbolDetach = "studio:symbolDetach", e.symbolOverride = "studio:symbolOverride", e.symbolPropagateStyles = "studio:propagateStyles", e.getPagesConfig = "studio:getPagesConfig", e.setPagesConfig = "studio:setPagesConfig", e.getPageSettings = "studio:getPageSettings", e.setPageSettings = "studio:setPageSettings", e.projectFiles = "studio:projectFiles", e.canvasReload = "studio:canvasReload", e.getBlocksPanel = "studio:getBlocksPanel", e.setBlocksPanel = "studio:setBlocksPanel", e.getStateContextMenu = "studio:getStateContextMenu", e.setStateContextMenu = "studio:setStateContextMenu", e.contextMenuComponent = "studio:contextMenuComponent", e.layoutAdd = "studio:layoutAdd", e.layoutRemove = "studio:layoutRemove", e.layoutToggle = "studio:layoutToggle", e.layoutUpdate = "studio:layoutUpdate", e.layoutGet = "studio:layoutGet", e.layoutConfigGet = "studio:layoutConfigGet", e.layoutConfigSet = "studio:layoutConfigSet", e.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.assetProviderGet = "studio:assetProviderGet", e.assetProviderAdd = "studio:assetProviderAdd", e.assetProviderRemove = "studio:assetProviderRemove", e.fontGet = "studio:fontGet", e.fontAdd = "studio:fontAdd", e.fontRemove = "studio:fontRemove", e.fontManagerOpen = "studio:fontManagerOpen", e.menuFontLoad = "studio:menuFontLoad", e.toggleStateDataSource = "studio:toggleStateDataSource", e.getStateDataSource = "studio:getStateDataSource", e.setDragAbsolute = "studio:setDragAbsolute", e))(y || {});
2
- const $ = "app.grapesjs.com", P = "app-stage.grapesjs.com", h = [
3
- $,
4
- P,
1
+ import I from "handlebars/dist/cjs/handlebars";
2
+ const b = "app.grapesjs.com", x = "app-stage.grapesjs.com", y = [
3
+ b,
4
+ x,
5
5
  "localhost",
6
6
  "127.0.0.1",
7
7
  ".local-credentialless.webcontainer.io",
@@ -10,98 +10,235 @@ const $ = "app.grapesjs.com", P = "app-stage.grapesjs.com", h = [
10
10
  // For stackblitz.com demos
11
11
  "-sandpack.codesandbox.io"
12
12
  // For Sandpack demos
13
- ], v = "license:check:start", A = "license:check:end", E = () => typeof window < "u", L = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? P : $}`}/api`, _ = () => {
14
- const e = E() && window.location.hostname;
15
- return !!e && (h.includes(e) || h.some((t) => e.endsWith(t)));
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;
15
+ return !!r && (y.includes(r) || y.some((t) => r.endsWith(t)));
16
16
  };
17
- async function D({
18
- path: e,
17
+ async function N({
18
+ path: r,
19
19
  baseApiUrl: t,
20
- method: r = "GET",
21
- headers: s = {},
22
- params: n,
23
- body: a
20
+ method: n = "GET",
21
+ headers: e = {},
22
+ params: a,
23
+ body: s
24
24
  }) {
25
- const u = `${t || L({ isDev: !1, isStage: !1 })}${e}`, l = {
26
- method: r,
25
+ const o = `${t || L({ isDev: !1, isStage: !1 })}${r}`, h = {
26
+ method: n,
27
27
  headers: {
28
28
  "Content-Type": "application/json",
29
- ...s
29
+ ...e
30
30
  }
31
31
  };
32
- a && (l.body = JSON.stringify(a));
33
- const o = n ? new URLSearchParams(n).toString() : "", i = o ? `?${o}` : "", c = await fetch(`${u}${i}`, l);
34
- if (!c.ok)
35
- throw new Error(`HTTP error! status: ${c.status}`);
36
- return c.json();
32
+ s && (h.body = JSON.stringify(s));
33
+ const l = a ? new URLSearchParams(a).toString() : "", c = l ? `?${l}` : "", u = await fetch(`${o}${c}`, h);
34
+ if (!u.ok)
35
+ throw new Error(`HTTP error! status: ${u.status}`);
36
+ return u.json();
37
37
  }
38
- const b = {
39
- [g.free]: 0,
40
- [g.startup]: 10,
41
- [g.business]: 20,
42
- [g.enterprise]: 30
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
43
44
  };
44
- function R(e) {
45
- const t = e;
46
- return t.init = (r) => (s) => e(s, r), t;
45
+ function H(r) {
46
+ const t = r;
47
+ return t.init = (n) => (e) => r(e, n), t;
47
48
  }
48
- const w = (e) => /* @__PURE__ */ R(e);
49
- async function G({
50
- editor: e,
49
+ const M = (r) => /* @__PURE__ */ H(r);
50
+ async function _({
51
+ editor: r,
51
52
  plan: t,
52
- pluginName: r,
53
- licenseKey: s,
54
- cleanup: n
53
+ pluginName: n,
54
+ licenseKey: e,
55
+ cleanup: a
55
56
  }) {
56
- let a = "", p = !1;
57
- const u = _(), l = (i) => {
58
- console.warn("Cleanup plugin:", r, "Reason:", i), n();
59
- }, o = (i = {}) => {
60
- var d;
61
- const { error: c, sdkLicense: T } = i, f = (d = i.plan) == null ? void 0 : d.category;
62
- if (!(T || i.license) || c)
63
- l(c || "Invalid license");
64
- else if (f) {
65
- const x = b[t], I = b[f];
66
- x > I && l({ pluginRequiredPlan: t, licensePlan: f });
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");
65
+ else if (m) {
66
+ const E = $[t], v = $[m];
67
+ E > v && h({ pluginRequiredPlan: t, licensePlan: m });
67
68
  }
68
69
  };
69
- e.on(v, (i) => {
70
- a = i == null ? void 0 : i.baseApiUrl, p = !0;
71
- }), e.on(A, (i) => {
72
- o(i);
70
+ r.on(P, (c) => {
71
+ s = c == null ? void 0 : c.baseApiUrl, i = !0;
72
+ }), r.on(T, (c) => {
73
+ l(c);
73
74
  }), setTimeout(async () => {
74
- if (!p) {
75
- if (u) return;
76
- if (s) {
77
- const i = await N({ licenseKey: s, pluginName: r, baseApiUrl: a });
78
- i && o(i);
75
+ if (!i) {
76
+ if (o) return;
77
+ if (e) {
78
+ const c = await j({ licenseKey: e, pluginName: n, baseApiUrl: s });
79
+ c && l(c);
79
80
  } else
80
- l("The `licenseKey` option not provided");
81
+ h("The `licenseKey` option not provided");
81
82
  }
82
83
  }, 2e3);
83
84
  }
84
- async function N(e) {
85
- const { licenseKey: t, pluginName: r, baseApiUrl: s } = e;
85
+ async function j(r) {
86
+ const { licenseKey: t, pluginName: n, baseApiUrl: e } = r;
86
87
  try {
87
- return (await D({
88
- baseApiUrl: s,
88
+ return (await N({
89
+ baseApiUrl: e,
89
90
  path: `/sdk/${t || "na"}`,
90
91
  method: "POST",
91
92
  params: {
92
93
  d: window.location.hostname,
93
- pn: r
94
+ pn: n
94
95
  }
95
96
  })).result || {};
96
- } catch (n) {
97
- return console.error("Error during SDK license check:", n), !1;
97
+ } catch (a) {
98
+ return console.error("Error during SDK license check:", a), !1;
98
99
  }
99
100
  }
100
- class O {
101
- getHelperId(t, r) {
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 {
103
+ constructor(t) {
104
+ this.strategy = t, this.requiredHelpers = /* @__PURE__ */ new Set(), this.helperLibrary = {};
105
+ }
106
+ registerHelper(t) {
107
+ this.helperLibrary[t] && this.requiredHelpers.add(t);
108
+ }
109
+ generateVariable(t) {
110
+ return this.strategy.getVariableSyntax(t);
111
+ }
112
+ generateCollectionStart(t) {
113
+ return this.registerHelper("slice"), this.strategy.getCollectionStartSyntax(t);
114
+ }
115
+ generateCollectionEnd() {
116
+ return this.strategy.getCollectionEndSyntax();
117
+ }
118
+ generateConditionalStart(t) {
119
+ return this.strategy.getConditionalStartSyntax(t);
120
+ }
121
+ generateConditionElse() {
122
+ return this.strategy.getConditionElseSyntax();
123
+ }
124
+ generateConditionalEnd() {
125
+ return this.strategy.getConditionalEndSyntax();
126
+ }
127
+ reset() {
128
+ this.requiredHelpers.clear();
129
+ }
130
+ }
131
+ function O(r) {
132
+ return typeof r == "object" && r.type === d.variable;
133
+ }
134
+ function g({
135
+ component: r,
136
+ value: t,
137
+ getCustomPath: n
138
+ }) {
139
+ if (O(t) && !t.collectionId && n) {
140
+ const e = t.path ?? "", a = e.split(".");
141
+ return {
142
+ ...t,
143
+ path: n({ component: r, path: e, paths: a })
144
+ };
145
+ }
146
+ return t;
147
+ }
148
+ const D = (r) => {
149
+ f(r, d.variable, {
150
+ toHTML(t) {
151
+ var i;
152
+ const n = this.tagName, e = this.__attrToString(t), a = (i = this.getDataResolver) == null ? void 0 : i.call(this), s = g({
153
+ component: this,
154
+ value: a,
155
+ getCustomPath: t == null ? void 0 : t.getCustomPath
156
+ });
157
+ return `<${n}${e ? ` ${e}` : ""}>${t.exporter.generateVariable(s)}</${n}>`;
158
+ }
159
+ }), f(r, d.condition, {
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()}
169
+ `;
170
+ },
171
+ resolveCondition(t, n) {
172
+ var a, s;
173
+ if (!t) return {};
174
+ if (t.operator === "and" || t.operator === "or")
175
+ return {
176
+ operator: t.operator,
177
+ statements: ((s = (a = t.statements) == null ? void 0 : a.map) == null ? void 0 : s.call(a, (i) => {
178
+ var o;
179
+ return ((o = this.resolveCondition) == null ? void 0 : o.call(this, i, n)) ?? {};
180
+ })) ?? []
181
+ };
182
+ const e = { component: this, getCustomPath: n };
183
+ return {
184
+ ...t,
185
+ left: g({ ...e, value: t.left }),
186
+ right: g({ ...e, value: t.right })
187
+ };
188
+ }
189
+ }), f(r, d.collection, {
190
+ toHTML(t) {
191
+ const n = t.exporter, e = this.tagName, a = this.__attrToString(t), s = this.getDataResolver(), i = {
192
+ ...s,
193
+ dataSource: g({
194
+ component: this,
195
+ value: s == null ? void 0 : s.dataSource,
196
+ getCustomPath: t == null ? void 0 : t.getCustomPath
197
+ })
198
+ }, o = this.components().at(0);
199
+ return `
200
+ <${e}${a ? ` ${a}` : ""}>${n.generateCollectionStart(i)}
201
+ ${(o == null ? void 0 : o.toHTML(t)) ?? ""}
202
+ ${n.generateCollectionEnd()}</${e}>
203
+ `;
204
+ }
205
+ });
206
+ }, f = (r, t, n) => {
207
+ const e = r.Components.getType(t);
208
+ if (!e) {
209
+ console.warn(`Component type ${t} not found`);
210
+ return;
211
+ }
212
+ const { model: a } = e;
213
+ r.Components.addType(t, {
214
+ model: {
215
+ ...n,
216
+ toHTML(s = {}) {
217
+ var o;
218
+ 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
+ }
221
+ }
222
+ });
223
+ }, V = (r, t) => (r.config.optsHtml = {
224
+ ...r.config.optsHtml,
225
+ exporter: new B(t)
226
+ }, D(r), () => {
227
+ r.config.optsHtml.exporter = void 0;
228
+ }), U = (r, t) => {
229
+ const n = (a) => {
230
+ const { input: s } = a, { contains: i } = t;
231
+ (!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);
235
+ };
236
+ };
237
+ class W {
238
+ getHelperId(t, n) {
102
239
  return {
103
240
  // AnyTypeOperation
104
- equals: `${r === "string" ? "str" : r === "number" ? "num" : "any"}Equals`,
241
+ equals: `${n === "string" ? "str" : n === "number" ? "num" : "any"}Equals`,
105
242
  isTruthy: "isTruthy",
106
243
  isFalsy: "isFalsy",
107
244
  isDefined: "isDefined",
@@ -128,46 +265,52 @@ class O {
128
265
  trimEquals: "strTrimEquals"
129
266
  }[t] || t;
130
267
  }
131
- getVariableSyntax({ collectionId: t, variableType: r, path: s, defaultValue: n }) {
132
- let a = s;
133
- return t && (a = [this._sanitizeVariableName(t), r, s].filter(Boolean).join(".")), n ? `{{#if ${s}}}{{{${a}}}}{{else}}${n}{{/if}}` : `{{{${a}}}}`;
268
+ getFullPath({ collectionId: t, path: n }) {
269
+ let e = n;
270
+ return t && (e = [this._sanitizeVariableName(t), n].filter(Boolean).join(".")), e || "";
271
+ }
272
+ getVariableSyntax(t) {
273
+ const { defaultValue: n } = t, e = this.getFullPath(t);
274
+ return n ? `{{#if ${e}}}{{{${e}}}}{{else}}${n}{{/if}}` : `{{{${e}}}}`;
134
275
  }
135
276
  getCollectionStartSyntax(t) {
136
- const { collectionId: r, dataSource: s } = t, n = s == null ? void 0 : s.path;
137
- let a = "";
277
+ const { collectionId: n, dataSource: e } = t, a = e == null ? void 0 : e.path;
278
+ let s = "";
138
279
  if (t.startIndex !== void 0 || t.endIndex !== void 0) {
139
- const o = t.startIndex ?? 0, i = t.endIndex !== void 0 ? t.endIndex : "";
140
- i !== "" ? a = ` (slice ${n} ${o} ${i})` : a = ` (slice ${n} ${o})`;
280
+ const l = t.startIndex ?? 0, c = t.endIndex !== void 0 ? t.endIndex : "";
281
+ c !== "" ? s = ` (slice ${a} ${l} ${c})` : s = ` (slice ${a} ${l})`;
141
282
  }
142
- const u = ` as |${this._sanitizeVariableName(r)}|`;
143
- return `{{#each ${a || n}${u}}}`;
283
+ const o = ` as |${this._sanitizeVariableName(n)}|`;
284
+ return `{{#each ${s || a}${o}}}`;
144
285
  }
145
286
  getCollectionEndSyntax() {
146
287
  return "{{/each}}";
147
288
  }
148
289
  getConditionalStartSyntax(t) {
149
290
  if (!t) return "";
150
- if (t.logicalOperator === "and" || t.logicalOperator === "or") {
151
- const r = this.getHelperId(t.logicalOperator), s = t.statements.map((n) => this._parseCondition(n)).join(", ");
152
- return `{{#if (${r} ${s})}}`;
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(", ");
294
+ return `{{#if ${a.length > 1 ? `(${s} ${i})` : i}}}`;
153
295
  } else
154
- return `{{#if ${this._parseCondition(t)}}}`;
296
+ return `{{#if ${this._parseCondition(n)}}}`;
155
297
  }
156
298
  _parseCondition(t) {
157
299
  if (!t) return "";
158
- if (t.operator === "and" || t.operator === "or") {
159
- const r = this.getHelperId(t.operator), s = t.statements.map((n) => this._parseCondition(n)).join(" ");
160
- return `(${r} ${s})`;
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(" ");
303
+ return a.length > 1 ? `(${s} ${i})` : i;
161
304
  } else {
162
- const r = this.getHelperId(t.operator, this._getTypeHint(t)), s = this._parseValue(t.left), n = this._parseValue(t.right);
163
- return `(${r} ${s} ${n})`;
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})`;
164
307
  }
165
308
  }
166
309
  _getTypeHint(t) {
167
310
  return ["contains", "startsWith", "endsWith", "equalsIgnoreCase", "trimEquals"].includes(t.operator) ? "string" : [">", "<", ">=", "<=", "=", "!="].includes(t.operator) ? "number" : "any";
168
311
  }
169
312
  _parseValue(t) {
170
- return typeof t == "object" ? this.getVariableSyntax(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
313
+ return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
171
314
  }
172
315
  _sanitizeVariableName(t) {
173
316
  return t.replace(/[^a-zA-Z0-9_$]/g, "_");
@@ -179,24 +322,183 @@ class O {
179
322
  return "{{/if}}";
180
323
  }
181
324
  }
182
- const j = "dataSourceHandlebars", B = function(e, t = {}) {
183
- const r = ({ options: n }) => {
184
- const a = n.exportConfig;
185
- a.exportPreset === "handlebarsjs" && (n.exportConfig = {
186
- ...a,
187
- exportStrategy: new O()
325
+ class q {
326
+ constructor() {
327
+ this.messages = [], this.collectionStack = [];
328
+ }
329
+ import(t) {
330
+ this.messages = [], this.collectionStack = [];
331
+ const n = this.parse(t);
332
+ return this.astToGrapesJS(n);
333
+ }
334
+ parse(t) {
335
+ 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}`);
341
+ }
342
+ throw n;
343
+ }
344
+ }
345
+ astToGrapesJS(t) {
346
+ switch (t.type) {
347
+ case "Program":
348
+ return this.handleProgram(t);
349
+ case "ContentStatement":
350
+ return this.handleContentStatement(t);
351
+ case "MustacheStatement":
352
+ return this.handleMustacheStatement(t);
353
+ case "BlockStatement":
354
+ return this.handleBlockStatement(t);
355
+ case "PartialStatement":
356
+ return this.handlePartialStatement(t);
357
+ case "CommentStatement":
358
+ return this.handleCommentStatement(t);
359
+ case "ElementNode":
360
+ return this.handleElementNode(t);
361
+ case "TextNode":
362
+ return this.handleTextNode(t);
363
+ default:
364
+ return this.addMessage("warning", `Unsupported node type: ${t.type}`, t.loc), "";
365
+ }
366
+ }
367
+ handleProgram(t) {
368
+ let n = "";
369
+ if (t.body)
370
+ for (const e of t.body)
371
+ n += this.astToGrapesJS(e);
372
+ return n;
373
+ }
374
+ handleContentStatement(t) {
375
+ return t.value || "";
376
+ }
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>`;
407
+ }
408
+ handleBlockStatement(t) {
409
+ const n = t.path.original;
410
+ switch (n) {
411
+ case "if":
412
+ case "unless":
413
+ return this.handleConditionalBlock(t, n);
414
+ case "each":
415
+ return this.handleEachBlock(t);
416
+ default:
417
+ return this.addMessage("warning", `Unsupported block helper: ${n}`, t.loc), this.handleGenericBlock(t);
418
+ }
419
+ }
420
+ handleConditionalBlock(t, n) {
421
+ const s = {
422
+ logicalOperator: "and",
423
+ statements: [
424
+ {
425
+ left: { type: "data-variable", path: this.getExpressionString(t.params[0]) },
426
+ operator: n === "unless" ? "isFalsy" : "isTruthy"
427
+ }
428
+ ]
429
+ }, 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
+ }) : `
433
+ <data-condition data-gjs-data-resolver='${JSON.stringify({ condition: s })}'>
434
+ <data-condition-true-content>${i}</data-condition-true-content>
435
+ <data-condition-false-content>${o}</data-condition-false-content>
436
+ </data-condition>
437
+ `;
438
+ }
439
+ handleEachBlock(t) {
440
+ const n = this.getExpressionString(t.params[0]), e = `collection-${Math.random().toString(36).substring(2, 10)}`;
441
+ this.collectionStack.push(e);
442
+ const a = this.handleProgram(t.program);
443
+ return this.collectionStack.pop(), `
444
+ <data-collection data-gjs-data-resolver='${JSON.stringify({
445
+ dataSource: { type: "data-variable", path: n },
446
+ collectionId: e
447
+ })}'>
448
+ <data-collection-item>${a}</data-collection-item>
449
+ </data-collection>
450
+ `;
451
+ }
452
+ handleCommentStatement(t) {
453
+ return `<!--${t.value}-->`;
454
+ }
455
+ handleElementNode(t) {
456
+ let n = "";
457
+ if (t.attributes)
458
+ 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 = "";
461
+ if (t.children)
462
+ for (const a of t.children)
463
+ e += this.astToGrapesJS(a);
464
+ return `<${t.tag}${n}>${e}</${t.tag}>`;
465
+ }
466
+ handleTextNode(t) {
467
+ return t.chars || "";
468
+ }
469
+ handlePartialStatement(t) {
470
+ return this.addMessage("warning", `Partials are not fully supported: ${t.name.original}`, t.loc), `{{> ${t.name.original}}}`;
471
+ }
472
+ handleGenericBlock(t) {
473
+ const n = this.handleProgram(t.program);
474
+ return `<!-- Unsupported block: ${t.path.original} -->${n}`;
475
+ }
476
+ 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), "");
478
+ }
479
+ addMessage(t, n, e) {
480
+ this.messages.push({
481
+ type: t,
482
+ message: n,
483
+ location: e ? { line: e.start.line, column: e.start.column } : void 0
188
484
  });
189
- }, s = `${e.Commands.events.runBeforeCommand}${y.projectFiles}`;
190
- e.on(s, r), G({
191
- editor: e,
485
+ }
486
+ }
487
+ const A = "dataSourceHandlebars", G = p.startup, R = function(r, t = {}) {
488
+ const n = V(r, new W()), e = U(r, {
489
+ contains: "{{",
490
+ importer: new q()
491
+ });
492
+ _({
493
+ editor: r,
192
494
  licenseKey: t.licenseKey,
193
- plan: g.startup,
194
- pluginName: j,
495
+ plan: G,
496
+ pluginName: A,
195
497
  cleanup: () => {
196
- e.off(s, r);
498
+ n(), e();
197
499
  }
198
500
  });
199
- }, W = w(B);
501
+ }, K = M(R);
200
502
  export {
201
- W as default
503
+ K as default
202
504
  };