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