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