@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.
- package/dist/animationComponent/components/Animation.d.ts +6 -0
- package/dist/animationComponent/components/AnimationGroup.d.ts +4 -0
- package/dist/animationComponent/index.cjs.d.ts +3 -0
- package/dist/animationComponent/index.cjs.js +507 -0
- package/dist/animationComponent/index.d.ts +3 -0
- package/dist/animationComponent/index.es.d.ts +3 -0
- package/dist/animationComponent/index.es.js +1111 -0
- package/dist/animationComponent/index.umd.js +507 -0
- package/dist/animationComponent/shared.d.ts +3 -0
- package/dist/animationComponent/types.d.ts +28 -0
- package/dist/animationComponent/typesSchema.d.ts +48 -0
- package/dist/animationComponent/utils.d.ts +19 -0
- package/dist/dataSourceEjs/EjsExporter.d.ts +13 -0
- package/dist/dataSourceEjs/EjsImporter.d.ts +29 -0
- package/dist/dataSourceEjs/index.cjs.d.ts +2 -2
- package/dist/dataSourceEjs/index.cjs.js +24 -3
- package/dist/dataSourceEjs/index.d.ts +2 -2
- package/dist/dataSourceEjs/index.es.d.ts +2 -2
- package/dist/dataSourceEjs/index.es.js +697 -114
- package/dist/dataSourceEjs/index.umd.js +24 -3
- package/dist/dataSourceEjs/shared.d.ts +3 -0
- package/dist/dataSourceEjs/types.d.ts +2 -2
- package/dist/dataSourceEjs/typesSchema.d.ts +3 -0
- package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +16 -0
- package/dist/dataSourceHandlebars/HandlebarsImporter.d.ts +20 -0
- package/dist/dataSourceHandlebars/helperImplementations.d.ts +1 -0
- package/dist/dataSourceHandlebars/index.cjs.js +20 -1
- package/dist/dataSourceHandlebars/index.es.js +401 -99
- package/dist/dataSourceHandlebars/index.umd.js +20 -1
- package/dist/dataSourceHandlebars/shared.d.ts +3 -0
- package/dist/dataSourceHandlebars/types.d.ts +2 -2
- package/dist/dataSourceHandlebars/typesSchema.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +29 -29
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +64 -64
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +587 -51
- package/dist/index.d.ts +1 -0
- package/dist/index.es.d.ts +1 -0
- package/dist/index.es.js +4809 -3046
- package/dist/index.umd.js +584 -48
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +59 -59
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/presetPrintable/index.cjs.js +3 -3
- package/dist/presetPrintable/index.es.js +136 -131
- package/dist/presetPrintable/index.umd.js +4 -4
- package/dist/prosemirror/index.cjs.js +1 -1
- package/dist/prosemirror/index.es.js +1 -1
- package/dist/prosemirror/index.umd.js +1 -1
- package/dist/rteTinyMce/index.cjs.js +2 -2
- package/dist/rteTinyMce/index.es.js +67 -67
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +14 -14
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/utilsDataSources.d.ts +28 -0
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +26 -26
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +2 -1
- package/dist/dataSourceEjs/EjsStrategy.d.ts +0 -15
- package/dist/dataSourceHandlebars/HandlebarsStrategy.d.ts +0 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
],
|
|
14
|
-
const
|
|
15
|
-
return !!
|
|
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
|
|
18
|
-
path:
|
|
17
|
+
async function N({
|
|
18
|
+
path: r,
|
|
19
19
|
baseApiUrl: t,
|
|
20
|
-
method:
|
|
21
|
-
headers:
|
|
22
|
-
params:
|
|
23
|
-
body:
|
|
20
|
+
method: n = "GET",
|
|
21
|
+
headers: e = {},
|
|
22
|
+
params: a,
|
|
23
|
+
body: s
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
26
|
-
method:
|
|
25
|
+
const o = `${t || L({ isDev: !1, isStage: !1 })}${r}`, h = {
|
|
26
|
+
method: n,
|
|
27
27
|
headers: {
|
|
28
28
|
"Content-Type": "application/json",
|
|
29
|
-
...
|
|
29
|
+
...e
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
throw new Error(`HTTP error! status: ${
|
|
36
|
-
return
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
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
|
|
45
|
-
const t =
|
|
46
|
-
return t.init = (
|
|
45
|
+
function H(r) {
|
|
46
|
+
const t = r;
|
|
47
|
+
return t.init = (n) => (e) => r(e, n), t;
|
|
47
48
|
}
|
|
48
|
-
const
|
|
49
|
-
async function
|
|
50
|
-
editor:
|
|
49
|
+
const M = (r) => /* @__PURE__ */ H(r);
|
|
50
|
+
async function _({
|
|
51
|
+
editor: r,
|
|
51
52
|
plan: t,
|
|
52
|
-
pluginName:
|
|
53
|
-
licenseKey:
|
|
54
|
-
cleanup:
|
|
53
|
+
pluginName: n,
|
|
54
|
+
licenseKey: e,
|
|
55
|
+
cleanup: a
|
|
55
56
|
}) {
|
|
56
|
-
let
|
|
57
|
-
const
|
|
58
|
-
console.warn("Cleanup plugin:",
|
|
59
|
-
},
|
|
60
|
-
var
|
|
61
|
-
const { error:
|
|
62
|
-
if (!(
|
|
63
|
-
|
|
64
|
-
else if (
|
|
65
|
-
const
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
}),
|
|
72
|
-
|
|
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 (!
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
-
|
|
81
|
+
h("The `licenseKey` option not provided");
|
|
81
82
|
}
|
|
82
83
|
}, 2e3);
|
|
83
84
|
}
|
|
84
|
-
async function
|
|
85
|
-
const { licenseKey: t, pluginName:
|
|
85
|
+
async function j(r) {
|
|
86
|
+
const { licenseKey: t, pluginName: n, baseApiUrl: e } = r;
|
|
86
87
|
try {
|
|
87
|
-
return (await
|
|
88
|
-
baseApiUrl:
|
|
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:
|
|
94
|
+
pn: n
|
|
94
95
|
}
|
|
95
96
|
})).result || {};
|
|
96
|
-
} catch (
|
|
97
|
-
return console.error("Error during SDK license check:",
|
|
97
|
+
} catch (a) {
|
|
98
|
+
return console.error("Error during SDK license check:", a), !1;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
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: `${
|
|
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
|
-
|
|
132
|
-
let
|
|
133
|
-
return t && (
|
|
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:
|
|
137
|
-
let
|
|
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
|
|
140
|
-
|
|
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
|
|
143
|
-
return `{{#each ${
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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(
|
|
296
|
+
return `{{#if ${this._parseCondition(n)}}}`;
|
|
155
297
|
}
|
|
156
298
|
_parseCondition(t) {
|
|
157
299
|
if (!t) return "";
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
|
163
|
-
return `(${
|
|
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.
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
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:
|
|
194
|
-
pluginName:
|
|
495
|
+
plan: G,
|
|
496
|
+
pluginName: A,
|
|
195
497
|
cleanup: () => {
|
|
196
|
-
|
|
498
|
+
n(), e();
|
|
197
499
|
}
|
|
198
500
|
});
|
|
199
|
-
},
|
|
501
|
+
}, K = M(R);
|
|
200
502
|
export {
|
|
201
|
-
|
|
503
|
+
K as default
|
|
202
504
|
};
|