@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.
- package/dist/dataSourceEjs/EjsImporter.d.ts +2 -1
- package/dist/dataSourceEjs/index.cjs.js +23 -17
- package/dist/dataSourceEjs/index.es.js +339 -290
- package/dist/dataSourceEjs/index.umd.js +23 -17
- package/dist/dataSourceEjs/tests/EjsExporter.test.d.ts +1 -0
- package/dist/dataSourceEjs/tests/EjsImporter.test.d.ts +1 -0
- package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
- package/dist/dataSourceHandlebars/HandlebarsImporter.d.ts +9 -0
- package/dist/dataSourceHandlebars/constants.d.ts +16 -0
- package/dist/dataSourceHandlebars/index.cjs.js +13 -13
- package/dist/dataSourceHandlebars/index.es.js +272 -217
- package/dist/dataSourceHandlebars/index.umd.js +13 -13
- package/dist/dataSourceHandlebars/tests/HandlebarsExporter.test.d.ts +1 -0
- package/dist/dataSourceHandlebars/tests/HandlebarsImporter.test.d.ts +1 -0
- package/dist/index.cjs.js +70 -63
- package/dist/index.es.js +3297 -3187
- package/dist/index.umd.js +70 -63
- package/dist/presetPrintable/index.cjs.js +7 -6
- package/dist/presetPrintable/index.es.js +204 -197
- package/dist/presetPrintable/index.umd.js +7 -6
- package/dist/presetPrintable/shared.d.ts +3 -0
- package/dist/presetPrintable/types.d.ts +4 -1
- package/dist/presetPrintable/typesSchema.d.ts +18 -0
- package/dist/presetPrintable/utils.d.ts +11 -0
- package/jest.config.js +9 -0
- package/package.json +4 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
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
|
-
],
|
|
14
|
-
const r =
|
|
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
|
|
17
|
+
async function H({
|
|
18
18
|
path: r,
|
|
19
19
|
baseApiUrl: t,
|
|
20
|
-
method:
|
|
21
|
-
headers:
|
|
20
|
+
method: e = "GET",
|
|
21
|
+
headers: n = {},
|
|
22
22
|
params: a,
|
|
23
23
|
body: s
|
|
24
24
|
}) {
|
|
25
|
-
const o = `${t ||
|
|
26
|
-
method:
|
|
25
|
+
const o = `${t || _({ isDev: !1, isStage: !1 })}${r}`, c = {
|
|
26
|
+
method: e,
|
|
27
27
|
headers: {
|
|
28
28
|
"Content-Type": "application/json",
|
|
29
|
-
...
|
|
29
|
+
...n
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
s && (
|
|
33
|
-
const
|
|
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
|
|
39
|
-
const
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
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
|
|
45
|
+
function M(r) {
|
|
46
46
|
const t = r;
|
|
47
|
-
return t.init = (
|
|
47
|
+
return t.init = (e) => (n) => r(n, e), t;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
async function
|
|
49
|
+
const O = (r) => /* @__PURE__ */ M(r);
|
|
50
|
+
async function R({
|
|
51
51
|
editor: r,
|
|
52
52
|
plan: t,
|
|
53
|
-
pluginName:
|
|
54
|
-
licenseKey:
|
|
53
|
+
pluginName: e,
|
|
54
|
+
licenseKey: n,
|
|
55
55
|
cleanup: a
|
|
56
56
|
}) {
|
|
57
57
|
let s = "", i = !1;
|
|
58
|
-
const o = w(),
|
|
59
|
-
console.warn("Cleanup plugin:",
|
|
60
|
-
},
|
|
61
|
-
var
|
|
62
|
-
const { error: u, sdkLicense:
|
|
63
|
-
if (!(
|
|
64
|
-
|
|
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
|
|
67
|
-
|
|
66
|
+
const v = P[t], I = P[m];
|
|
67
|
+
v > I && c({ pluginRequiredPlan: t, licensePlan: m });
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
r.on(
|
|
71
|
-
s =
|
|
72
|
-
}), r.on(T, (
|
|
73
|
-
l
|
|
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 (
|
|
78
|
-
const
|
|
79
|
-
|
|
77
|
+
if (n) {
|
|
78
|
+
const l = await A({ licenseKey: n, pluginName: e, baseApiUrl: s });
|
|
79
|
+
l && h(l);
|
|
80
80
|
} else
|
|
81
|
-
|
|
81
|
+
c("The `licenseKey` option not provided");
|
|
82
82
|
}
|
|
83
83
|
}, 2e3);
|
|
84
84
|
}
|
|
85
|
-
async function
|
|
86
|
-
const { licenseKey: t, pluginName:
|
|
85
|
+
async function A(r) {
|
|
86
|
+
const { licenseKey: t, pluginName: e, baseApiUrl: n } = r;
|
|
87
87
|
try {
|
|
88
|
-
return (await
|
|
89
|
-
baseApiUrl:
|
|
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:
|
|
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
|
|
102
|
-
class
|
|
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
|
|
132
|
-
return typeof r == "object" && r.type ===
|
|
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:
|
|
137
|
+
getCustomPath: e
|
|
138
138
|
}) {
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
139
|
+
if (j(t) && !t.collectionId && e) {
|
|
140
|
+
const n = t.path ?? "", a = n.split(".");
|
|
141
141
|
return {
|
|
142
142
|
...t,
|
|
143
|
-
path:
|
|
143
|
+
path: e({ component: r, path: n, paths: a })
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
return t;
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
f(r,
|
|
148
|
+
const V = (r) => {
|
|
149
|
+
f(r, p.variable, {
|
|
150
150
|
toHTML(t) {
|
|
151
151
|
var i;
|
|
152
|
-
const
|
|
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 `<${
|
|
157
|
+
return `<${e}${n ? ` ${n}` : ""}>${t.exporter.generateVariable(s)}</${e}>`;
|
|
158
158
|
}
|
|
159
|
-
}), f(r,
|
|
159
|
+
}), f(r, p.condition, {
|
|
160
160
|
toHTML(t) {
|
|
161
|
-
var l,
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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,
|
|
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,
|
|
180
|
+
return ((o = this.resolveCondition) == null ? void 0 : o.call(this, i, e)) ?? {};
|
|
180
181
|
})) ?? []
|
|
181
182
|
};
|
|
182
|
-
const
|
|
183
|
+
const n = { component: this, getCustomPath: e };
|
|
183
184
|
return {
|
|
184
185
|
...t,
|
|
185
|
-
left: g({ ...
|
|
186
|
-
right: g({ ...
|
|
186
|
+
left: g({ ...n, value: t.left }),
|
|
187
|
+
right: g({ ...n, value: t.right })
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
|
-
}), f(r,
|
|
190
|
+
}), f(r, p.collection, {
|
|
190
191
|
toHTML(t) {
|
|
191
|
-
const
|
|
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
|
-
<${
|
|
201
|
+
<${n}${a ? ` ${a}` : ""}>${e.generateCollectionStart(i)}
|
|
201
202
|
${(o == null ? void 0 : o.toHTML(t)) ?? ""}
|
|
202
|
-
|
|
203
|
+
${e.generateCollectionEnd()}</${n}>
|
|
203
204
|
`;
|
|
204
205
|
}
|
|
205
206
|
});
|
|
206
|
-
}, f = (r, t,
|
|
207
|
-
const
|
|
208
|
-
if (!
|
|
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 } =
|
|
213
|
+
const { model: a } = n;
|
|
213
214
|
r.Components.addType(t, {
|
|
214
215
|
model: {
|
|
215
|
-
...
|
|
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 =
|
|
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
|
-
},
|
|
224
|
+
}, B = (r, t) => (r.config.optsHtml = {
|
|
224
225
|
...r.config.optsHtml,
|
|
225
|
-
exporter: new
|
|
226
|
-
},
|
|
226
|
+
exporter: new D(t)
|
|
227
|
+
}, V(r), () => {
|
|
227
228
|
r.config.optsHtml.exporter = void 0;
|
|
228
229
|
}), U = (r, t) => {
|
|
229
|
-
const
|
|
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
|
-
},
|
|
233
|
-
return r.on(
|
|
234
|
-
r.off(
|
|
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
|
|
238
|
-
getHelperId(t
|
|
239
|
-
return
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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:
|
|
274
|
-
return
|
|
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:
|
|
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
|
|
281
|
-
|
|
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(
|
|
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
|
|
292
|
-
if (
|
|
293
|
-
const { statements: a } =
|
|
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(
|
|
300
|
+
return `{{#if ${this._parseCondition(e)}}}`;
|
|
297
301
|
}
|
|
298
302
|
_parseCondition(t) {
|
|
299
303
|
if (!t) return "";
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
const { statements: a } =
|
|
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 =
|
|
306
|
-
return
|
|
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
|
-
|
|
310
|
-
return [
|
|
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
|
|
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
|
|
332
|
-
return this.astToGrapesJS(
|
|
335
|
+
const e = this.parse(t);
|
|
336
|
+
return this.astToGrapesJS(e);
|
|
333
337
|
}
|
|
334
338
|
parse(t) {
|
|
335
339
|
try {
|
|
336
|
-
return
|
|
337
|
-
} catch (
|
|
338
|
-
if (
|
|
339
|
-
const
|
|
340
|
-
throw new Error(`Handlebars syntax error at line ${a}, column ${i}: ${
|
|
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
|
|
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
|
|
372
|
+
let e = "";
|
|
369
373
|
if (t.body)
|
|
370
|
-
for (const
|
|
371
|
-
|
|
372
|
-
return
|
|
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,
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
|
410
|
-
switch (
|
|
435
|
+
const e = t.path.original;
|
|
436
|
+
switch (e) {
|
|
411
437
|
case "if":
|
|
412
438
|
case "unless":
|
|
413
|
-
return this.handleConditionalBlock(t,
|
|
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: ${
|
|
443
|
+
return this.addMessage("warning", `Unsupported block helper: ${e}`, t.loc), this.handleGenericBlock(t);
|
|
418
444
|
}
|
|
419
445
|
}
|
|
420
|
-
handleConditionalBlock(t,
|
|
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:
|
|
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
|
|
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
|
-
|
|
441
|
-
this.
|
|
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:
|
|
446
|
-
collectionId:
|
|
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
|
|
482
|
+
let e = "";
|
|
457
483
|
if (t.attributes)
|
|
458
484
|
for (const a of t.attributes)
|
|
459
|
-
a.value.type === "TextNode" ?
|
|
460
|
-
let
|
|
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
|
-
|
|
464
|
-
return `<${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
|
|
474
|
-
return `<!-- Unsupported block: ${t.path.original} -->${
|
|
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((
|
|
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,
|
|
505
|
+
addMessage(t, e, n) {
|
|
480
506
|
this.messages.push({
|
|
481
507
|
type: t,
|
|
482
|
-
message:
|
|
483
|
-
location:
|
|
508
|
+
message: e,
|
|
509
|
+
location: n ? { line: n.start.line, column: n.start.column } : void 0
|
|
484
510
|
});
|
|
485
511
|
}
|
|
486
512
|
}
|
|
487
|
-
const
|
|
488
|
-
|
|
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
|
|
545
|
+
importer: new J()
|
|
491
546
|
});
|
|
492
|
-
|
|
547
|
+
R({
|
|
493
548
|
editor: r,
|
|
494
549
|
licenseKey: t.licenseKey,
|
|
495
|
-
plan:
|
|
496
|
-
pluginName:
|
|
550
|
+
plan: z,
|
|
551
|
+
pluginName: K,
|
|
497
552
|
cleanup: () => {
|
|
498
|
-
|
|
553
|
+
e(), n();
|
|
499
554
|
}
|
|
500
555
|
});
|
|
501
|
-
},
|
|
556
|
+
}, X = O(Y);
|
|
502
557
|
export {
|
|
503
|
-
|
|
558
|
+
X as default
|
|
504
559
|
};
|