@grapesjs/studio-sdk-plugins 1.0.37 → 1.0.38
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/accordionComponent/index.cjs.js +3 -3
- package/dist/accordionComponent/index.es.js +12 -12
- package/dist/accordionComponent/index.umd.js +3 -3
- package/dist/aiChat/index.cjs.js +85 -85
- package/dist/aiChat/index.es.js +9759 -9332
- package/dist/aiChat/index.js +85 -85
- package/dist/aiChat/index.umd.js +86 -86
- package/dist/aiChat/locales/en.d.ts +11 -0
- package/dist/aiChat/server/index.cjs.js +1 -1
- package/dist/aiChat/server/index.es.js +1 -1
- package/dist/aiChat/server/index.js +1 -1
- package/dist/aiChat/server/index.umd.js +1 -1
- package/dist/aiChat/types.d.ts +1 -1
- package/dist/animationComponent/index.cjs.js +3 -3
- package/dist/animationComponent/index.es.js +10 -10
- package/dist/animationComponent/index.umd.js +3 -3
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
- package/dist/canvasAbsoluteMode/index.es.js +10 -10
- package/dist/canvasAbsoluteMode/index.umd.js +1 -1
- package/dist/canvasEmptyState/index.cjs.js +1 -1
- package/dist/canvasEmptyState/index.es.js +1 -1
- package/dist/canvasEmptyState/index.umd.js +1 -1
- package/dist/canvasFullSize/index.cjs.js +4 -4
- package/dist/canvasFullSize/index.es.js +15 -15
- package/dist/canvasFullSize/index.umd.js +3 -3
- package/dist/canvasGridMode/index.cjs.js +2 -2
- package/dist/canvasGridMode/index.es.js +233 -228
- package/dist/canvasGridMode/index.umd.js +2 -2
- package/dist/canvasScreenshot/index.cjs.js +1 -1
- package/dist/canvasScreenshot/index.es.js +11 -11
- package/dist/canvasScreenshot/index.umd.js +1 -1
- package/dist/dataSourceEjs/index.cjs.js +2 -2
- package/dist/dataSourceEjs/index.es.js +5 -5
- package/dist/dataSourceEjs/index.umd.js +1 -1
- package/dist/dataSourceHandlebars/index.cjs.js +1 -1
- package/dist/dataSourceHandlebars/index.es.js +105 -105
- package/dist/dataSourceHandlebars/index.umd.js +5 -5
- package/dist/dialogComponent/index.cjs.js +3 -3
- package/dist/dialogComponent/index.es.js +18 -18
- package/dist/dialogComponent/index.umd.js +3 -3
- package/dist/flexComponent/index.cjs.js +1 -1
- package/dist/flexComponent/index.es.js +1 -1
- package/dist/flexComponent/index.umd.js +3 -3
- package/dist/fsLightboxComponent/index.cjs.js +1 -1
- package/dist/fsLightboxComponent/index.es.js +7 -7
- package/dist/fsLightboxComponent/index.umd.js +2 -2
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +12 -12
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +61 -61
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.js +24 -24
- package/dist/index.es.js +335 -330
- package/dist/index.umd.js +25 -25
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +15 -15
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/lightGalleryComponent/index.cjs.js +1 -1
- package/dist/lightGalleryComponent/index.es.js +20 -20
- package/dist/lightGalleryComponent/index.umd.js +1 -1
- package/dist/linkImageComponent/index.cjs.js +1 -1
- package/dist/linkImageComponent/index.es.js +1 -1
- package/dist/linkImageComponent/index.umd.js +2 -2
- package/dist/listPagesComponent/index.cjs.js +2 -2
- package/dist/listPagesComponent/index.es.js +10 -10
- package/dist/listPagesComponent/index.umd.js +2 -2
- package/dist/presetPrintable/index.cjs.js +5 -5
- package/dist/presetPrintable/index.es.js +47 -47
- 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/rendererReact/index.cjs.js +1 -1
- package/dist/rendererReact/index.es.js +16 -16
- package/dist/rendererReact/index.js +1 -1
- package/dist/rendererReact/index.umd.js +1 -1
- package/dist/rteTinyMce/index.cjs.js +2 -2
- package/dist/rteTinyMce/index.es.js +27 -27
- package/dist/rteTinyMce/index.umd.js +1 -1
- package/dist/shapeDividerComponent/index.cjs.js +1 -1
- package/dist/shapeDividerComponent/index.es.js +10 -10
- package/dist/shapeDividerComponent/index.umd.js +2 -2
- package/dist/swiperComponent/index.cjs.js +1 -1
- package/dist/swiperComponent/index.es.js +1 -1
- package/dist/swiperComponent/index.umd.js +1 -1
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +9 -9
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +5 -5
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +1 -1
|
@@ -19,8 +19,8 @@ const x = "app.grapesjs.com", $ = "app-stage.grapesjs.com", k = "app2.grapesjs.c
|
|
|
19
19
|
], L = "license:check:end", N = () => typeof window < "u", R = ({
|
|
20
20
|
isDev: e,
|
|
21
21
|
isStage: t,
|
|
22
|
-
isPlatform:
|
|
23
|
-
}) => `${e ? "" : `https://${t ? $ : x}`}/${
|
|
22
|
+
isPlatform: n
|
|
23
|
+
}) => `${e ? "" : `https://${t ? $ : x}`}/${n ? "platform-api" : "api"}`, O = () => {
|
|
24
24
|
if (!N()) return "";
|
|
25
25
|
const { hostname: e } = window.location;
|
|
26
26
|
if (e) return e;
|
|
@@ -36,16 +36,16 @@ const x = "app.grapesjs.com", $ = "app-stage.grapesjs.com", k = "app2.grapesjs.c
|
|
|
36
36
|
async function w({
|
|
37
37
|
path: e,
|
|
38
38
|
baseApiUrl: t,
|
|
39
|
-
method:
|
|
40
|
-
headers:
|
|
39
|
+
method: n = "GET",
|
|
40
|
+
headers: s = {},
|
|
41
41
|
params: a,
|
|
42
42
|
body: r
|
|
43
43
|
}) {
|
|
44
44
|
const i = `${t || R({ isDev: !1, isStage: !1 })}${e}`, c = {
|
|
45
|
-
method:
|
|
45
|
+
method: n,
|
|
46
46
|
headers: {
|
|
47
47
|
"Content-Type": "application/json",
|
|
48
|
-
...
|
|
48
|
+
...s
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
r && (c.body = JSON.stringify(r));
|
|
@@ -54,7 +54,7 @@ async function w({
|
|
|
54
54
|
throw new Error(`HTTP error! status: ${l.status}`);
|
|
55
55
|
return l.json();
|
|
56
56
|
}
|
|
57
|
-
var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}), d = /* @__PURE__ */ ((e) => (e.toastAdd = "studio:toastAdd", e.toastRemove = "studio:toastRemove", e.dialogOpen = "studio:dialogOpen", e.dialogClose = "studio:dialogClose", e.dialogExportCode = "studio:dialogExportCode", e.dialogImportCode = "studio:dialogImportCode", 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.clearPage = "studio:clearPage", e.projectFiles = "studio:projectFiles", e.validateCode = "studio:validateCode", 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.layoutComponentAdd = "studio:layoutComponentAdd", e.layoutComponentGet = "studio:layoutComponentGet", e.layoutComponentRemove = "studio:layoutComponentRemove", e.layoutComponentRender = "studio:layoutComponentRender", e.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.settings = "studio:settings", 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.dataSourceSetGlobalData = "studio:dataSourceSetGlobalData", e.dataSourceSetImporter = "studio:dataSourceSetImporter", e.dataSourceSetExporter = "studio:dataSourceSetExporter", e.setDragAbsolute = "studio:setDragAbsolute", e))(d || {});
|
|
57
|
+
var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}), d = /* @__PURE__ */ ((e) => (e.toastAdd = "studio:toastAdd", e.toastRemove = "studio:toastRemove", e.dialogOpen = "studio:dialogOpen", e.dialogClose = "studio:dialogClose", e.dialogExportCode = "studio:dialogExportCode", e.dialogImportCode = "studio:dialogImportCode", e.openEditCode = "studio:openEditCode", 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.clearPage = "studio:clearPage", e.projectFiles = "studio:projectFiles", e.validateCode = "studio:validateCode", 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.layoutComponentAdd = "studio:layoutComponentAdd", e.layoutComponentGet = "studio:layoutComponentGet", e.layoutComponentRemove = "studio:layoutComponentRemove", e.layoutComponentRender = "studio:layoutComponentRender", e.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.settings = "studio:settings", 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.dataSourceSetGlobalData = "studio:dataSourceSetGlobalData", e.dataSourceSetImporter = "studio:dataSourceSetImporter", e.dataSourceSetExporter = "studio:dataSourceSetExporter", e.setDragAbsolute = "studio:setDragAbsolute", e))(d || {});
|
|
58
58
|
const m = {
|
|
59
59
|
[p.free]: 0,
|
|
60
60
|
[p.startup]: 10,
|
|
@@ -63,20 +63,20 @@ const m = {
|
|
|
63
63
|
};
|
|
64
64
|
function D(e) {
|
|
65
65
|
const t = e;
|
|
66
|
-
return t.init = (
|
|
66
|
+
return t.init = (n) => (s) => e(s, n), t;
|
|
67
67
|
}
|
|
68
68
|
const G = (e) => /* @__PURE__ */ D(e);
|
|
69
69
|
async function M({
|
|
70
70
|
editor: e,
|
|
71
71
|
plan: t,
|
|
72
|
-
pluginName:
|
|
73
|
-
licenseKey:
|
|
72
|
+
pluginName: n,
|
|
73
|
+
licenseKey: s,
|
|
74
74
|
onLicenseCheckResponse: a,
|
|
75
75
|
cleanup: r
|
|
76
76
|
}) {
|
|
77
77
|
let o = "", i;
|
|
78
78
|
const c = (l) => {
|
|
79
|
-
console.warn("Cleanup plugin:",
|
|
79
|
+
console.warn("Cleanup plugin:", n, "Reason:", l), r();
|
|
80
80
|
}, u = (l = {}) => {
|
|
81
81
|
var b;
|
|
82
82
|
const { error: y, sdkLicense: E } = l, g = (b = l.plan) == null ? void 0 : b.category;
|
|
@@ -94,8 +94,8 @@ async function M({
|
|
|
94
94
|
if (!i) {
|
|
95
95
|
e.onReady(async () => {
|
|
96
96
|
if (!_())
|
|
97
|
-
if (
|
|
98
|
-
const l = await j({ licenseKey:
|
|
97
|
+
if (s) {
|
|
98
|
+
const l = await j({ licenseKey: s, pluginName: n, baseApiUrl: o });
|
|
99
99
|
h(l);
|
|
100
100
|
} else
|
|
101
101
|
c("The `licenseKey` option not provided");
|
|
@@ -116,15 +116,15 @@ const B = (e) => ({
|
|
|
116
116
|
plan: e.licensePlan
|
|
117
117
|
});
|
|
118
118
|
async function j(e) {
|
|
119
|
-
const { licenseKey: t, pluginName:
|
|
119
|
+
const { licenseKey: t, pluginName: n, baseApiUrl: s } = e;
|
|
120
120
|
try {
|
|
121
121
|
return (await w({
|
|
122
|
-
baseApiUrl:
|
|
122
|
+
baseApiUrl: s,
|
|
123
123
|
path: `/sdk/${t || "na"}`,
|
|
124
124
|
method: "POST",
|
|
125
125
|
params: {
|
|
126
126
|
d: window.location.hostname,
|
|
127
|
-
pn:
|
|
127
|
+
pn: n
|
|
128
128
|
}
|
|
129
129
|
})).result || {};
|
|
130
130
|
} catch (a) {
|
|
@@ -137,12 +137,12 @@ const U = (e, t) => (e.config.optsHtml = {
|
|
|
137
137
|
}, () => {
|
|
138
138
|
e.config.optsHtml.exporter = void 0;
|
|
139
139
|
}), H = (e, t) => {
|
|
140
|
-
const
|
|
140
|
+
const n = (a) => {
|
|
141
141
|
const { input: r } = a, { contains: o } = t;
|
|
142
142
|
(!o || r.includes(o)) && (a.input = t.importer.import(r));
|
|
143
|
-
},
|
|
144
|
-
return e.on(
|
|
145
|
-
e.off(
|
|
143
|
+
}, s = e.Parser.events.htmlBefore;
|
|
144
|
+
return e.on(s, n), () => {
|
|
145
|
+
e.off(s, n);
|
|
146
146
|
};
|
|
147
147
|
}, v = {
|
|
148
148
|
equals: "equals",
|
|
@@ -179,50 +179,50 @@ class C {
|
|
|
179
179
|
getHelperId(t) {
|
|
180
180
|
return F[t] || t;
|
|
181
181
|
}
|
|
182
|
-
getFullPath({ collectionId: t, path:
|
|
183
|
-
let
|
|
184
|
-
return t && (
|
|
182
|
+
getFullPath({ collectionId: t, path: n }) {
|
|
183
|
+
let s = n;
|
|
184
|
+
return t && (s = [this._sanitizeVariableName(t), n].filter(Boolean).join(".")), s || "";
|
|
185
185
|
}
|
|
186
186
|
getVariableSyntax({ dataResolver: t }) {
|
|
187
|
-
const { defaultValue:
|
|
188
|
-
return
|
|
187
|
+
const { defaultValue: n } = t, s = this.getFullPath(t);
|
|
188
|
+
return n ? `{{#if ${s}}}{{{${s}}}}{{else}}${n}{{/if}}` : `{{{${s}}}}`;
|
|
189
189
|
}
|
|
190
190
|
getCollectionStartSyntax({ dataResolver: t }) {
|
|
191
|
-
const { collectionId:
|
|
191
|
+
const { collectionId: n, dataSource: s } = t, a = s == null ? void 0 : s.path;
|
|
192
192
|
let r = "";
|
|
193
193
|
if (t.startIndex !== void 0 || t.endIndex !== void 0) {
|
|
194
194
|
const u = t.startIndex ?? 0, h = t.endIndex !== void 0 ? t.endIndex : "";
|
|
195
195
|
h !== "" ? r = ` (slice ${a} ${u} ${h})` : r = ` (slice ${a} ${u})`;
|
|
196
196
|
}
|
|
197
|
-
const i = ` as |${this._sanitizeVariableName(
|
|
197
|
+
const i = ` as |${this._sanitizeVariableName(n)}|`;
|
|
198
198
|
return `{{#each ${r || a}${i}}}`;
|
|
199
199
|
}
|
|
200
200
|
getCollectionEndSyntax() {
|
|
201
201
|
return "{{/each}}";
|
|
202
202
|
}
|
|
203
203
|
getConditionalStartSyntax({ dataResolver: t }) {
|
|
204
|
-
const
|
|
205
|
-
if (!
|
|
206
|
-
const
|
|
204
|
+
const n = t.condition;
|
|
205
|
+
if (!n) return "";
|
|
206
|
+
const s = n, a = n;
|
|
207
207
|
if (a.statements && a.logicalOperator === "and" || a.logicalOperator === "or") {
|
|
208
208
|
const { statements: r } = a, o = a.logicalOperator, i = r.map((u) => this._parseCondition(u)).join(" ");
|
|
209
209
|
return `{{#if ${r.length > 1 ? `(${o} ${i})` : i}}}`;
|
|
210
210
|
} else
|
|
211
|
-
return `{{#if ${this._parseCondition(
|
|
211
|
+
return `{{#if ${this._parseCondition(s)}}}`;
|
|
212
212
|
}
|
|
213
213
|
_parseCondition(t) {
|
|
214
214
|
if (!t) return "";
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
const { statements: a } =
|
|
215
|
+
const n = t, s = t;
|
|
216
|
+
if (s.statements && s.logicalOperator === "and" || s.logicalOperator === "or") {
|
|
217
|
+
const { statements: a } = s, r = s.logicalOperator, o = s.statements.map((i) => this._parseCondition(i)).join(" ");
|
|
218
218
|
return a.length > 1 ? `(${r} ${o})` : o;
|
|
219
219
|
} else {
|
|
220
|
-
const a =
|
|
220
|
+
const a = n.operator, r = this.getHelperId(a), o = this._parseValue(n.left), i = this._parseValue(n.right);
|
|
221
221
|
return this.getExpressionStr(r, o, i);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
getExpressionStr(t,
|
|
225
|
-
return v[t] ? t === "isTruthy" ?
|
|
224
|
+
getExpressionStr(t, n, s) {
|
|
225
|
+
return v[t] ? t === "isTruthy" ? n : t === "isFalsy" ? `!${n}` : `${t} ${n}` : `(${t} ${n} ${s})`;
|
|
226
226
|
}
|
|
227
227
|
_parseValue(t) {
|
|
228
228
|
return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
|
|
@@ -243,18 +243,18 @@ class q {
|
|
|
243
243
|
}
|
|
244
244
|
import(t) {
|
|
245
245
|
this.messages = [], this.collectionStack = [];
|
|
246
|
-
const
|
|
247
|
-
return this.astToGrapesJS(
|
|
246
|
+
const n = this.parse(t);
|
|
247
|
+
return this.astToGrapesJS(n);
|
|
248
248
|
}
|
|
249
249
|
parse(t) {
|
|
250
250
|
try {
|
|
251
251
|
return T.parse(t);
|
|
252
|
-
} catch (
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
throw new Error(`Handlebars syntax error at line ${a}, column ${o}: ${
|
|
252
|
+
} catch (n) {
|
|
253
|
+
if (n instanceof Error && n.message.includes("Parse error")) {
|
|
254
|
+
const s = n.message.match(/line (\d+)/), a = s ? parseInt(s[1]) : 0, r = n.message.match(/column (\d+)/), o = r ? parseInt(r[1]) : 0;
|
|
255
|
+
throw new Error(`Handlebars syntax error at line ${a}, column ${o}: ${n.message}`);
|
|
256
256
|
}
|
|
257
|
-
throw
|
|
257
|
+
throw n;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
astToGrapesJS(t) {
|
|
@@ -280,87 +280,87 @@ class q {
|
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
handleProgram(t) {
|
|
283
|
-
let
|
|
283
|
+
let n = "";
|
|
284
284
|
if (t.body)
|
|
285
|
-
for (const
|
|
286
|
-
|
|
287
|
-
return
|
|
285
|
+
for (const s of t.body)
|
|
286
|
+
n += this.astToGrapesJS(s);
|
|
287
|
+
return n;
|
|
288
288
|
}
|
|
289
289
|
handleContentStatement(t) {
|
|
290
290
|
return t.value || "";
|
|
291
291
|
}
|
|
292
|
-
handleMustacheStatement(t,
|
|
293
|
-
const
|
|
294
|
-
return this.collectionStack.length > 0 ? this.processPathWithCollectionContext(
|
|
292
|
+
handleMustacheStatement(t, n = {}) {
|
|
293
|
+
const s = this.getExpressionString(t.path), a = { ...n };
|
|
294
|
+
return this.collectionStack.length > 0 ? this.processPathWithCollectionContext(s, a) : a.path = s, `<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`;
|
|
295
295
|
}
|
|
296
|
-
processPathWithCollectionContext(t,
|
|
297
|
-
t.startsWith("@") ? this.handleDirectCollectionReference(t,
|
|
296
|
+
processPathWithCollectionContext(t, n) {
|
|
297
|
+
t.startsWith("@") ? this.handleDirectCollectionReference(t, n) : this.handleRelativePathReference(t, n);
|
|
298
298
|
}
|
|
299
|
-
handleDirectCollectionReference(t,
|
|
299
|
+
handleDirectCollectionReference(t, n) {
|
|
300
300
|
if (this.isSpecialIterationVariable(t)) {
|
|
301
|
-
this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length - 1], t,
|
|
301
|
+
this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length - 1], t, n);
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
|
-
const [
|
|
305
|
-
this.collectionStack.includes(
|
|
304
|
+
const [s, ...a] = t.substring(1).split("/"), r = a.join(".");
|
|
305
|
+
this.collectionStack.includes(s) ? this.setCurrentItemResolver(s, r, n) : this.handleParentReferenceFallback(t, n);
|
|
306
306
|
}
|
|
307
307
|
isSpecialIterationVariable(t) {
|
|
308
308
|
return ["index", "@index", "key", "@key"].includes(t);
|
|
309
309
|
}
|
|
310
|
-
setSpecialVariableResolver(t,
|
|
311
|
-
|
|
310
|
+
setSpecialVariableResolver(t, n, s) {
|
|
311
|
+
s.collectionId = t;
|
|
312
312
|
const a = {
|
|
313
313
|
index: "currentIndex",
|
|
314
314
|
"@index": "currentIndex",
|
|
315
315
|
key: "currentKey",
|
|
316
316
|
"@key": "currentKey"
|
|
317
317
|
};
|
|
318
|
-
|
|
318
|
+
s.variableType = a[n];
|
|
319
319
|
}
|
|
320
|
-
setCurrentItemResolver(t,
|
|
321
|
-
|
|
320
|
+
setCurrentItemResolver(t, n, s) {
|
|
321
|
+
s.collectionId = t, s.variableType = "currentItem", n && (s.path = n);
|
|
322
322
|
}
|
|
323
|
-
handleRelativePathReference(t,
|
|
324
|
-
const
|
|
325
|
-
i >= 0 && i < this.collectionStack.length ? this.resolveRelativePath(o, i,
|
|
323
|
+
handleRelativePathReference(t, n) {
|
|
324
|
+
const s = f(t), { parentLevel: a, remainingPathParts: r } = this.calculateParentLevel(s), o = r.join("."), i = this.collectionStack.length - 1 - a;
|
|
325
|
+
i >= 0 && i < this.collectionStack.length ? this.resolveRelativePath(o, i, n) : n.path = r.join(".");
|
|
326
326
|
}
|
|
327
327
|
calculateParentLevel(t) {
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
330
|
-
return { parentLevel: this.collectionStack.length - 1 -
|
|
331
|
-
let
|
|
328
|
+
const n = this.collectionStack.findLastIndex((r) => r === t[0]);
|
|
329
|
+
if (n !== -1)
|
|
330
|
+
return { parentLevel: this.collectionStack.length - 1 - n, remainingPathParts: t.slice(1) };
|
|
331
|
+
let s = 0;
|
|
332
332
|
const a = [...t];
|
|
333
333
|
for (; a[0] === ".."; )
|
|
334
|
-
|
|
335
|
-
return { parentLevel:
|
|
334
|
+
s++, a.shift();
|
|
335
|
+
return { parentLevel: s, remainingPathParts: a };
|
|
336
336
|
}
|
|
337
|
-
resolveRelativePath(t,
|
|
338
|
-
const a = this.collectionStack[
|
|
339
|
-
|
|
337
|
+
resolveRelativePath(t, n, s) {
|
|
338
|
+
const a = this.collectionStack[n];
|
|
339
|
+
s.collectionId = a, s.variableType = "currentItem", t !== "this" && (s.path = t.startsWith("this.") ? t.split(".").slice(1).join(".") : t);
|
|
340
340
|
}
|
|
341
|
-
handleParentReferenceFallback(t,
|
|
342
|
-
const
|
|
343
|
-
i >= 0 && i < this.collectionStack.length ? this.resolveRelativePath(o, i,
|
|
341
|
+
handleParentReferenceFallback(t, n) {
|
|
342
|
+
const s = f(t), { parentLevel: a, remainingPathParts: r } = this.calculateParentLevel(s), o = r.join("."), i = this.collectionStack.length - 1 - a;
|
|
343
|
+
i >= 0 && i < this.collectionStack.length ? this.resolveRelativePath(o, i, n) : n.path = r.join(".");
|
|
344
344
|
}
|
|
345
345
|
handleBlockStatement(t) {
|
|
346
|
-
const
|
|
347
|
-
switch (
|
|
346
|
+
const n = t.path.original;
|
|
347
|
+
switch (n) {
|
|
348
348
|
case "if":
|
|
349
349
|
case "unless":
|
|
350
|
-
return this.handleConditionalBlock(t,
|
|
350
|
+
return this.handleConditionalBlock(t, n);
|
|
351
351
|
case "each":
|
|
352
352
|
return this.handleEachBlock(t);
|
|
353
353
|
default:
|
|
354
|
-
return this.addMessage("warning", `Unsupported block helper: ${
|
|
354
|
+
return this.addMessage("warning", `Unsupported block helper: ${n}`, t.loc), this.handleGenericBlock(t);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
handleConditionalBlock(t,
|
|
357
|
+
handleConditionalBlock(t, n) {
|
|
358
358
|
const r = {
|
|
359
359
|
logicalOperator: "and",
|
|
360
360
|
statements: [
|
|
361
361
|
{
|
|
362
362
|
left: { type: "data-variable", path: this.getExpressionString(t.params[0]) },
|
|
363
|
-
operator:
|
|
363
|
+
operator: n === "unless" ? "isFalsy" : "isTruthy"
|
|
364
364
|
}
|
|
365
365
|
]
|
|
366
366
|
}, o = this.handleProgram(t.program), i = t.inverse ? this.handleProgram(t.inverse) : "";
|
|
@@ -373,14 +373,14 @@ class q {
|
|
|
373
373
|
}
|
|
374
374
|
handleEachBlock(t) {
|
|
375
375
|
var r, o, i;
|
|
376
|
-
const
|
|
377
|
-
let
|
|
378
|
-
t.params.length >= 3 && t.params[1] === "as" && ((r = t.params[2]) == null ? void 0 : r.type) === "PathExpression" ?
|
|
376
|
+
const n = this.getExpressionString(t.params[0]);
|
|
377
|
+
let s;
|
|
378
|
+
t.params.length >= 3 && t.params[1] === "as" && ((r = t.params[2]) == null ? void 0 : r.type) === "PathExpression" ? s = t.params[2].original : (i = (o = t.program) == null ? void 0 : o.blockParams) != null && i.length ? s = t.program.blockParams[0] : s = `collection-${Math.random().toString(36).substring(2, 10)}`, this.collectionStack.push(s);
|
|
379
379
|
const a = this.handleProgram(t.program);
|
|
380
380
|
return this.collectionStack.pop(), `
|
|
381
381
|
<data-collection data-gjs-data-resolver='${JSON.stringify({
|
|
382
|
-
dataSource: { type: "data-variable", path:
|
|
383
|
-
collectionId:
|
|
382
|
+
dataSource: { type: "data-variable", path: n },
|
|
383
|
+
collectionId: s
|
|
384
384
|
})}'>
|
|
385
385
|
<data-collection-item>${a}</data-collection-item>
|
|
386
386
|
</data-collection>
|
|
@@ -390,15 +390,15 @@ class q {
|
|
|
390
390
|
return `<!--${t.value}-->`;
|
|
391
391
|
}
|
|
392
392
|
handleElementNode(t) {
|
|
393
|
-
let
|
|
393
|
+
let n = "";
|
|
394
394
|
if (t.attributes)
|
|
395
395
|
for (const a of t.attributes)
|
|
396
|
-
a.value.type === "TextNode" ?
|
|
397
|
-
let
|
|
396
|
+
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)}"`);
|
|
397
|
+
let s = "";
|
|
398
398
|
if (t.children)
|
|
399
399
|
for (const a of t.children)
|
|
400
|
-
|
|
401
|
-
return `<${t.tag}${
|
|
400
|
+
s += this.astToGrapesJS(a);
|
|
401
|
+
return `<${t.tag}${n}>${s}</${t.tag}>`;
|
|
402
402
|
}
|
|
403
403
|
handleTextNode(t) {
|
|
404
404
|
return t.chars || "";
|
|
@@ -407,17 +407,17 @@ class q {
|
|
|
407
407
|
return this.addMessage("warning", `Partials are not fully supported: ${t.name.original}`, t.loc), `{{> ${t.name.original}}}`;
|
|
408
408
|
}
|
|
409
409
|
handleGenericBlock(t) {
|
|
410
|
-
const
|
|
411
|
-
return `<!-- Unsupported block: ${t.path.original} -->${
|
|
410
|
+
const n = this.handleProgram(t.program);
|
|
411
|
+
return `<!-- Unsupported block: ${t.path.original} -->${n}`;
|
|
412
412
|
}
|
|
413
413
|
getExpressionString(t) {
|
|
414
|
-
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((
|
|
414
|
+
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((s) => `${s.key}=${this.getExpressionString(s.value)}`).join(", ")}}` : (this.addMessage("warning", `Complex expression type not fully supported: ${t.type}`, t.loc), "");
|
|
415
415
|
}
|
|
416
|
-
addMessage(t,
|
|
416
|
+
addMessage(t, n, s) {
|
|
417
417
|
this.messages.push({
|
|
418
418
|
type: t,
|
|
419
|
-
message:
|
|
420
|
-
location:
|
|
419
|
+
message: n,
|
|
420
|
+
location: s ? { line: s.start.line, column: s.start.column } : void 0
|
|
421
421
|
});
|
|
422
422
|
}
|
|
423
423
|
}
|
|
@@ -433,15 +433,15 @@ const f = (e) => {
|
|
|
433
433
|
return ["..", ...f(o)];
|
|
434
434
|
}
|
|
435
435
|
const t = [];
|
|
436
|
-
let
|
|
436
|
+
let n = 0, s = e.replace(
|
|
437
437
|
/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,
|
|
438
438
|
(o, i, c, u) => {
|
|
439
439
|
const h = c !== void 0 ? c : u || "";
|
|
440
|
-
return t[
|
|
440
|
+
return t[n] = h, `__HANDLEBARS_PLACEHOLDER_${n++}__`;
|
|
441
441
|
}
|
|
442
442
|
);
|
|
443
|
-
|
|
444
|
-
const a =
|
|
443
|
+
s = s.replace(/\//g, ".");
|
|
444
|
+
const a = s.split("."), r = [];
|
|
445
445
|
for (const o of a) {
|
|
446
446
|
const i = /^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(o);
|
|
447
447
|
if (i) {
|
|
@@ -451,7 +451,7 @@ const f = (e) => {
|
|
|
451
451
|
}
|
|
452
452
|
return r;
|
|
453
453
|
}, J = "dataSourceHandlebars", z = p.startup, K = function(e, t = {}) {
|
|
454
|
-
const
|
|
454
|
+
const n = U(e, new C()), s = H(e, {
|
|
455
455
|
contains: "{{",
|
|
456
456
|
importer: new q()
|
|
457
457
|
});
|
|
@@ -461,7 +461,7 @@ const f = (e) => {
|
|
|
461
461
|
plan: z,
|
|
462
462
|
pluginName: J,
|
|
463
463
|
cleanup: () => {
|
|
464
|
-
|
|
464
|
+
n(), s();
|
|
465
465
|
}
|
|
466
466
|
});
|
|
467
467
|
}, Q = G(K);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(p,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("handlebars/dist/cjs/handlebars")):typeof define=="function"&&define.amd?define(["handlebars/dist/cjs/handlebars"],g):(p=typeof globalThis<"u"?globalThis:p||self,p.StudioSdkPlugins_dataSourceHandlebars=g(p.Handlebars))})(this,function(p){"use strict";const g="app.grapesjs.com",P="app-stage.grapesjs.com",m=[g,"app2.grapesjs.com",P,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],I="license:check:end",S=()=>typeof window<"u",T=({isDev:t,isStage:e,isPlatform:n})=>`${t?"":`https://${e?P:g}`}/${n?"platform-api":"api"}`,k=()=>{if(!S())return"";const{hostname:t}=window.location;if(t)return t;try{return window.parent.location.hostname||""}catch{return""}},A=()=>{const t=k();return!!t&&(m.includes(t)||m.some(e=>t.endsWith(e)))};async function N({path:t,baseApiUrl:e,method:n="GET",headers:s={},params:a,body:r}){const i=`${e||T({isDev:!1,isStage:!1})}${t}`,c={method:n,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const u=a?new URLSearchParams(a).toString():"",h=u?`?${u}`:"",l=await fetch(`${i}${h}`,c);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var d=(t=>(t.free="free",t.startup="startup",t.business="business",t.enterprise="enterprise",t))(d||{}),f=(t=>(t.toastAdd="studio:toastAdd",t.toastRemove="studio:toastRemove",t.dialogOpen="studio:dialogOpen",t.dialogClose="studio:dialogClose",t.dialogExportCode="studio:dialogExportCode",t.dialogImportCode="studio:dialogImportCode",t.sidebarLeftSet="studio:sidebarLeft:set",t.sidebarLeftGet="studio:sidebarLeft:get",t.sidebarLeftToggle="studio:sidebarLeft:toggle",t.sidebarRightSet="studio:sidebarRight:set",t.sidebarRightGet="studio:sidebarRight:get",t.sidebarRightToggle="studio:sidebarRight:toggle",t.sidebarTopSet="studio:sidebarTop:set",t.sidebarTopGet="studio:sidebarTop:get",t.sidebarTopToggle="studio:sidebarTop:toggle",t.sidebarBottomSet="studio:sidebarBottom:set",t.sidebarBottomGet="studio:sidebarBottom:get",t.sidebarBottomToggle="studio:sidebarBottom:toggle",t.symbolAdd="studio:symbolAdd",t.symbolDetach="studio:symbolDetach",t.symbolOverride="studio:symbolOverride",t.symbolPropagateStyles="studio:propagateStyles",t.getPagesConfig="studio:getPagesConfig",t.setPagesConfig="studio:setPagesConfig",t.getPageSettings="studio:getPageSettings",t.setPageSettings="studio:setPageSettings",t.clearPage="studio:clearPage",t.projectFiles="studio:projectFiles",t.validateCode="studio:validateCode",t.canvasReload="studio:canvasReload",t.getBlocksPanel="studio:getBlocksPanel",t.setBlocksPanel="studio:setBlocksPanel",t.getStateContextMenu="studio:getStateContextMenu",t.setStateContextMenu="studio:setStateContextMenu",t.contextMenuComponent="studio:contextMenuComponent",t.layoutAdd="studio:layoutAdd",t.layoutRemove="studio:layoutRemove",t.layoutToggle="studio:layoutToggle",t.layoutUpdate="studio:layoutUpdate",t.layoutGet="studio:layoutGet",t.layoutConfigGet="studio:layoutConfigGet",t.layoutConfigSet="studio:layoutConfigSet",t.layoutComponentAdd="studio:layoutComponentAdd",t.layoutComponentGet="studio:layoutComponentGet",t.layoutComponentRemove="studio:layoutComponentRemove",t.layoutComponentRender="studio:layoutComponentRender",t.getStateTheme="studio:getStateTheme",t.setStateTheme="studio:setStateTheme",t.settings="studio:settings",t.assetProviderGet="studio:assetProviderGet",t.assetProviderAdd="studio:assetProviderAdd",t.assetProviderRemove="studio:assetProviderRemove",t.fontGet="studio:fontGet",t.fontAdd="studio:fontAdd",t.fontRemove="studio:fontRemove",t.fontManagerOpen="studio:fontManagerOpen",t.menuFontLoad="studio:menuFontLoad",t.toggleStateDataSource="studio:toggleStateDataSource",t.getStateDataSource="studio:getStateDataSource",t.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",t.dataSourceSetImporter="studio:dataSourceSetImporter",t.dataSourceSetExporter="studio:dataSourceSetExporter",t.setDragAbsolute="studio:setDragAbsolute",t))(f||{});const x={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function O(t){const e=t;return e.init=n=>s=>t(s,n),e}const R=t=>O(t);async function _({editor:t,plan:e,pluginName:n,licenseKey:s,onLicenseCheckResponse:a,cleanup:r}){let o="",i;const c=l=>{console.warn("Cleanup plugin:",n,"Reason:",l),r()},u=(l={})=>{var E;const{error:v,sdkLicense:W}=l,y=(E=l.plan)==null?void 0:E.category;if(!(W||l.license)||v)c(v||"Invalid license");else if(y){const V=x[e],F=x[y];V>F&&c({pluginRequiredPlan:e,licensePlan:y})}};t.Commands.has(f.settings)&&(i=t.runCommand(f.settings),o=(i==null?void 0:i.baseUrl)||"");const h=l=>{a==null||a(l),l&&u(l)};if(!i){t.onReady(async()=>{if(!A())if(s){const l=await w({licenseKey:s,pluginName:n,baseApiUrl:o});h(l)}else c("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const l=L(i);h(l);return}t.on(I,l=>h(l))}const L=t=>({sdkLicense:t.license,license:t.license,error:t.licenseError,plan:t.licensePlan});async function w(t){const{licenseKey:e,pluginName:n,baseApiUrl:s}=t;try{return(await N({baseApiUrl:s,path:`/sdk/${e||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}const D=(t,e)=>(t.config.optsHtml={...t.config.optsHtml,exporter:e},()=>{t.config.optsHtml.exporter=void 0}),G=(t,e)=>{const n=a=>{const{input:r}=a,{contains:o}=e;(!o||r.includes(o))&&(a.input=e.importer.import(r))},s=t.Parser.events.htmlBefore;return t.on(s,n),()=>{t.off(s,n)}},$={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},M={...$,...{">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},...{contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"}};class B{getHelperId(e){return M[e]||e}getFullPath({collectionId:e,path:n}){let s=n;return e&&(s=[this._sanitizeVariableName(e),n].filter(Boolean).join(".")),s||""}getVariableSyntax({dataResolver:e}){const{defaultValue:n}=e,s=this.getFullPath(e);return n?`{{#if ${s}}}{{{${s}}}}{{else}}${n}{{/if}}`:`{{{${s}}}}`}getCollectionStartSyntax({dataResolver:e}){const{collectionId:n,dataSource:s}=e,a=s==null?void 0:s.path;let r="";if(e.startIndex!==void 0||e.endIndex!==void 0){const u=e.startIndex??0,h=e.endIndex!==void 0?e.endIndex:"";h!==""?r=` (slice ${a} ${u} ${h})`:r=` (slice ${a} ${u})`}const i=` as |${this._sanitizeVariableName(n)}|`;return`{{#each ${r||a}${i}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:e}){const n=e.condition;if(!n)return"";const s=n,a=n;if(a.statements&&a.logicalOperator==="and"||a.logicalOperator==="or"){const{statements:r}=a,o=a.logicalOperator,i=r.map(u=>this._parseCondition(u)).join(" ");return`{{#if ${r.length>1?`(${o} ${i})`:i}}}`}else return`{{#if ${this._parseCondition(s)}}}`}_parseCondition(e){if(!e)return"";const n=e,s=e;if(s.statements&&s.logicalOperator==="and"||s.logicalOperator==="or"){const{statements:a}=s,r=s.logicalOperator,o=s.statements.map(i=>this._parseCondition(i)).join(" ");return a.length>1?`(${r} ${o})`:o}else{const a=n.operator,r=this.getHelperId(a),o=this._parseValue(n.left),i=this._parseValue(n.right);return this.getExpressionStr(r,o,i)}}getExpressionStr(e,n,s){return $[e]?e==="isTruthy"?n:e==="isFalsy"?`!${n}`:`${e} ${n}`:`(${e} ${n} ${s})`}_parseValue(e){return typeof e=="object"?this.getFullPath(e):typeof e=="string"?`'${e.replace(/'/g,"\\'")}'`:String(e)}_sanitizeVariableName(e){return e.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class j{constructor(){this.messages=[],this.collectionStack=[]}import(e){this.messages=[],this.collectionStack=[];const n=this.parse(e);return this.astToGrapesJS(n)}parse(e){try{return p.parse(e)}catch(n){if(n instanceof Error&&n.message.includes("Parse error")){const s=n.message.match(/line (\d+)/),a=s?parseInt(s[1]):0,r=n.message.match(/column (\d+)/),o=r?parseInt(r[1]):0;throw new Error(`Handlebars syntax error at line ${a}, column ${o}: ${n.message}`)}throw n}}astToGrapesJS(e){switch(e.type){case"Program":return this.handleProgram(e);case"ContentStatement":return this.handleContentStatement(e);case"MustacheStatement":return this.handleMustacheStatement(e);case"BlockStatement":return this.handleBlockStatement(e);case"PartialStatement":return this.handlePartialStatement(e);case"CommentStatement":return this.handleCommentStatement(e);case"ElementNode":return this.handleElementNode(e);case"TextNode":return this.handleTextNode(e);default:return this.addMessage("warning",`Unsupported node type: ${e.type}`,e.loc),""}}handleProgram(e){let n="";if(e.body)for(const s of e.body)n+=this.astToGrapesJS(s);return n}handleContentStatement(e){return e.value||""}handleMustacheStatement(e,n={}){const s=this.getExpressionString(e.path),a={...n};return this.collectionStack.length>0?this.processPathWithCollectionContext(s,a):a.path=s,`<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`}processPathWithCollectionContext(e,n){e.startsWith("@")?this.handleDirectCollectionReference(e,n):this.handleRelativePathReference(e,n)}handleDirectCollectionReference(e,n){if(this.isSpecialIterationVariable(e)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],e,n);return}const[s,...a]=e.substring(1).split("/"),r=a.join(".");this.collectionStack.includes(s)?this.setCurrentItemResolver(s,r,n):this.handleParentReferenceFallback(e,n)}isSpecialIterationVariable(e){return["index","@index","key","@key"].includes(e)}setSpecialVariableResolver(e,n,s){s.collectionId=e;const a={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};s.variableType=a[n]}setCurrentItemResolver(e,n,s){s.collectionId=e,s.variableType="currentItem",n&&(s.path=n)}handleRelativePathReference(e,n){const s=b(e),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(s),o=r.join("."),i=this.collectionStack.length-1-a;i>=0&&i<this.collectionStack.length?this.resolveRelativePath(o,i,n):n.path=r.join(".")}calculateParentLevel(e){const n=this.collectionStack.findLastIndex(r=>r===e[0]);if(n!==-1)return{parentLevel:this.collectionStack.length-1-n,remainingPathParts:e.slice(1)};let s=0;const a=[...e];for(;a[0]==="..";)s++,a.shift();return{parentLevel:s,remainingPathParts:a}}resolveRelativePath(e,n,s){const a=this.collectionStack[n];s.collectionId=a,s.variableType="currentItem",e!=="this"&&(s.path=e.startsWith("this.")?e.split(".").slice(1).join("."):e)}handleParentReferenceFallback(e,n){const s=b(e),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(s),o=r.join("."),i=this.collectionStack.length-1-a;i>=0&&i<this.collectionStack.length?this.resolveRelativePath(o,i,n):n.path=r.join(".")}handleBlockStatement(e){const n=e.path.original;switch(n){case"if":case"unless":return this.handleConditionalBlock(e,n);case"each":return this.handleEachBlock(e);default:return this.addMessage("warning",`Unsupported block helper: ${n}`,e.loc),this.handleGenericBlock(e)}}handleConditionalBlock(e,n){const r={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(e.params[0])},operator:n==="unless"?"isFalsy":"isTruthy"}]},o=this.handleProgram(e.program),i=e.inverse?this.handleProgram(e.inverse):"";return`
|
|
2
|
-
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:
|
|
1
|
+
(function(p,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("handlebars/dist/cjs/handlebars")):typeof define=="function"&&define.amd?define(["handlebars/dist/cjs/handlebars"],g):(p=typeof globalThis<"u"?globalThis:p||self,p.StudioSdkPlugins_dataSourceHandlebars=g(p.Handlebars))})(this,function(p){"use strict";const g="app.grapesjs.com",P="app-stage.grapesjs.com",m=[g,"app2.grapesjs.com",P,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],I="license:check:end",T=()=>typeof window<"u",S=({isDev:t,isStage:e,isPlatform:n})=>`${t?"":`https://${e?P:g}`}/${n?"platform-api":"api"}`,k=()=>{if(!T())return"";const{hostname:t}=window.location;if(t)return t;try{return window.parent.location.hostname||""}catch{return""}},A=()=>{const t=k();return!!t&&(m.includes(t)||m.some(e=>t.endsWith(e)))};async function N({path:t,baseApiUrl:e,method:n="GET",headers:s={},params:a,body:i}){const r=`${e||S({isDev:!1,isStage:!1})}${t}`,c={method:n,headers:{"Content-Type":"application/json",...s}};i&&(c.body=JSON.stringify(i));const u=a?new URLSearchParams(a).toString():"",h=u?`?${u}`:"",l=await fetch(`${r}${h}`,c);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var d=(t=>(t.free="free",t.startup="startup",t.business="business",t.enterprise="enterprise",t))(d||{}),f=(t=>(t.toastAdd="studio:toastAdd",t.toastRemove="studio:toastRemove",t.dialogOpen="studio:dialogOpen",t.dialogClose="studio:dialogClose",t.dialogExportCode="studio:dialogExportCode",t.dialogImportCode="studio:dialogImportCode",t.openEditCode="studio:openEditCode",t.sidebarLeftSet="studio:sidebarLeft:set",t.sidebarLeftGet="studio:sidebarLeft:get",t.sidebarLeftToggle="studio:sidebarLeft:toggle",t.sidebarRightSet="studio:sidebarRight:set",t.sidebarRightGet="studio:sidebarRight:get",t.sidebarRightToggle="studio:sidebarRight:toggle",t.sidebarTopSet="studio:sidebarTop:set",t.sidebarTopGet="studio:sidebarTop:get",t.sidebarTopToggle="studio:sidebarTop:toggle",t.sidebarBottomSet="studio:sidebarBottom:set",t.sidebarBottomGet="studio:sidebarBottom:get",t.sidebarBottomToggle="studio:sidebarBottom:toggle",t.symbolAdd="studio:symbolAdd",t.symbolDetach="studio:symbolDetach",t.symbolOverride="studio:symbolOverride",t.symbolPropagateStyles="studio:propagateStyles",t.getPagesConfig="studio:getPagesConfig",t.setPagesConfig="studio:setPagesConfig",t.getPageSettings="studio:getPageSettings",t.setPageSettings="studio:setPageSettings",t.clearPage="studio:clearPage",t.projectFiles="studio:projectFiles",t.validateCode="studio:validateCode",t.canvasReload="studio:canvasReload",t.getBlocksPanel="studio:getBlocksPanel",t.setBlocksPanel="studio:setBlocksPanel",t.getStateContextMenu="studio:getStateContextMenu",t.setStateContextMenu="studio:setStateContextMenu",t.contextMenuComponent="studio:contextMenuComponent",t.layoutAdd="studio:layoutAdd",t.layoutRemove="studio:layoutRemove",t.layoutToggle="studio:layoutToggle",t.layoutUpdate="studio:layoutUpdate",t.layoutGet="studio:layoutGet",t.layoutConfigGet="studio:layoutConfigGet",t.layoutConfigSet="studio:layoutConfigSet",t.layoutComponentAdd="studio:layoutComponentAdd",t.layoutComponentGet="studio:layoutComponentGet",t.layoutComponentRemove="studio:layoutComponentRemove",t.layoutComponentRender="studio:layoutComponentRender",t.getStateTheme="studio:getStateTheme",t.setStateTheme="studio:setStateTheme",t.settings="studio:settings",t.assetProviderGet="studio:assetProviderGet",t.assetProviderAdd="studio:assetProviderAdd",t.assetProviderRemove="studio:assetProviderRemove",t.fontGet="studio:fontGet",t.fontAdd="studio:fontAdd",t.fontRemove="studio:fontRemove",t.fontManagerOpen="studio:fontManagerOpen",t.menuFontLoad="studio:menuFontLoad",t.toggleStateDataSource="studio:toggleStateDataSource",t.getStateDataSource="studio:getStateDataSource",t.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",t.dataSourceSetImporter="studio:dataSourceSetImporter",t.dataSourceSetExporter="studio:dataSourceSetExporter",t.setDragAbsolute="studio:setDragAbsolute",t))(f||{});const x={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function O(t){const e=t;return e.init=n=>s=>t(s,n),e}const R=t=>O(t);async function _({editor:t,plan:e,pluginName:n,licenseKey:s,onLicenseCheckResponse:a,cleanup:i}){let o="",r;const c=l=>{console.warn("Cleanup plugin:",n,"Reason:",l),i()},u=(l={})=>{var v;const{error:E,sdkLicense:W}=l,y=(v=l.plan)==null?void 0:v.category;if(!(W||l.license)||E)c(E||"Invalid license");else if(y){const V=x[e],F=x[y];V>F&&c({pluginRequiredPlan:e,licensePlan:y})}};t.Commands.has(f.settings)&&(r=t.runCommand(f.settings),o=(r==null?void 0:r.baseUrl)||"");const h=l=>{a==null||a(l),l&&u(l)};if(!r){t.onReady(async()=>{if(!A())if(s){const l=await w({licenseKey:s,pluginName:n,baseApiUrl:o});h(l)}else c("The `licenseKey` option not provided")});return}if(r.licensePlan||r.licenseError){const l=L(r);h(l);return}t.on(I,l=>h(l))}const L=t=>({sdkLicense:t.license,license:t.license,error:t.licenseError,plan:t.licensePlan});async function w(t){const{licenseKey:e,pluginName:n,baseApiUrl:s}=t;try{return(await N({baseApiUrl:s,path:`/sdk/${e||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}const D=(t,e)=>(t.config.optsHtml={...t.config.optsHtml,exporter:e},()=>{t.config.optsHtml.exporter=void 0}),G=(t,e)=>{const n=a=>{const{input:i}=a,{contains:o}=e;(!o||i.includes(o))&&(a.input=e.importer.import(i))},s=t.Parser.events.htmlBefore;return t.on(s,n),()=>{t.off(s,n)}},$={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},M={...$,...{">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},...{contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"}};class B{getHelperId(e){return M[e]||e}getFullPath({collectionId:e,path:n}){let s=n;return e&&(s=[this._sanitizeVariableName(e),n].filter(Boolean).join(".")),s||""}getVariableSyntax({dataResolver:e}){const{defaultValue:n}=e,s=this.getFullPath(e);return n?`{{#if ${s}}}{{{${s}}}}{{else}}${n}{{/if}}`:`{{{${s}}}}`}getCollectionStartSyntax({dataResolver:e}){const{collectionId:n,dataSource:s}=e,a=s==null?void 0:s.path;let i="";if(e.startIndex!==void 0||e.endIndex!==void 0){const u=e.startIndex??0,h=e.endIndex!==void 0?e.endIndex:"";h!==""?i=` (slice ${a} ${u} ${h})`:i=` (slice ${a} ${u})`}const r=` as |${this._sanitizeVariableName(n)}|`;return`{{#each ${i||a}${r}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:e}){const n=e.condition;if(!n)return"";const s=n,a=n;if(a.statements&&a.logicalOperator==="and"||a.logicalOperator==="or"){const{statements:i}=a,o=a.logicalOperator,r=i.map(u=>this._parseCondition(u)).join(" ");return`{{#if ${i.length>1?`(${o} ${r})`:r}}}`}else return`{{#if ${this._parseCondition(s)}}}`}_parseCondition(e){if(!e)return"";const n=e,s=e;if(s.statements&&s.logicalOperator==="and"||s.logicalOperator==="or"){const{statements:a}=s,i=s.logicalOperator,o=s.statements.map(r=>this._parseCondition(r)).join(" ");return a.length>1?`(${i} ${o})`:o}else{const a=n.operator,i=this.getHelperId(a),o=this._parseValue(n.left),r=this._parseValue(n.right);return this.getExpressionStr(i,o,r)}}getExpressionStr(e,n,s){return $[e]?e==="isTruthy"?n:e==="isFalsy"?`!${n}`:`${e} ${n}`:`(${e} ${n} ${s})`}_parseValue(e){return typeof e=="object"?this.getFullPath(e):typeof e=="string"?`'${e.replace(/'/g,"\\'")}'`:String(e)}_sanitizeVariableName(e){return e.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class j{constructor(){this.messages=[],this.collectionStack=[]}import(e){this.messages=[],this.collectionStack=[];const n=this.parse(e);return this.astToGrapesJS(n)}parse(e){try{return p.parse(e)}catch(n){if(n instanceof Error&&n.message.includes("Parse error")){const s=n.message.match(/line (\d+)/),a=s?parseInt(s[1]):0,i=n.message.match(/column (\d+)/),o=i?parseInt(i[1]):0;throw new Error(`Handlebars syntax error at line ${a}, column ${o}: ${n.message}`)}throw n}}astToGrapesJS(e){switch(e.type){case"Program":return this.handleProgram(e);case"ContentStatement":return this.handleContentStatement(e);case"MustacheStatement":return this.handleMustacheStatement(e);case"BlockStatement":return this.handleBlockStatement(e);case"PartialStatement":return this.handlePartialStatement(e);case"CommentStatement":return this.handleCommentStatement(e);case"ElementNode":return this.handleElementNode(e);case"TextNode":return this.handleTextNode(e);default:return this.addMessage("warning",`Unsupported node type: ${e.type}`,e.loc),""}}handleProgram(e){let n="";if(e.body)for(const s of e.body)n+=this.astToGrapesJS(s);return n}handleContentStatement(e){return e.value||""}handleMustacheStatement(e,n={}){const s=this.getExpressionString(e.path),a={...n};return this.collectionStack.length>0?this.processPathWithCollectionContext(s,a):a.path=s,`<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`}processPathWithCollectionContext(e,n){e.startsWith("@")?this.handleDirectCollectionReference(e,n):this.handleRelativePathReference(e,n)}handleDirectCollectionReference(e,n){if(this.isSpecialIterationVariable(e)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],e,n);return}const[s,...a]=e.substring(1).split("/"),i=a.join(".");this.collectionStack.includes(s)?this.setCurrentItemResolver(s,i,n):this.handleParentReferenceFallback(e,n)}isSpecialIterationVariable(e){return["index","@index","key","@key"].includes(e)}setSpecialVariableResolver(e,n,s){s.collectionId=e;const a={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};s.variableType=a[n]}setCurrentItemResolver(e,n,s){s.collectionId=e,s.variableType="currentItem",n&&(s.path=n)}handleRelativePathReference(e,n){const s=b(e),{parentLevel:a,remainingPathParts:i}=this.calculateParentLevel(s),o=i.join("."),r=this.collectionStack.length-1-a;r>=0&&r<this.collectionStack.length?this.resolveRelativePath(o,r,n):n.path=i.join(".")}calculateParentLevel(e){const n=this.collectionStack.findLastIndex(i=>i===e[0]);if(n!==-1)return{parentLevel:this.collectionStack.length-1-n,remainingPathParts:e.slice(1)};let s=0;const a=[...e];for(;a[0]==="..";)s++,a.shift();return{parentLevel:s,remainingPathParts:a}}resolveRelativePath(e,n,s){const a=this.collectionStack[n];s.collectionId=a,s.variableType="currentItem",e!=="this"&&(s.path=e.startsWith("this.")?e.split(".").slice(1).join("."):e)}handleParentReferenceFallback(e,n){const s=b(e),{parentLevel:a,remainingPathParts:i}=this.calculateParentLevel(s),o=i.join("."),r=this.collectionStack.length-1-a;r>=0&&r<this.collectionStack.length?this.resolveRelativePath(o,r,n):n.path=i.join(".")}handleBlockStatement(e){const n=e.path.original;switch(n){case"if":case"unless":return this.handleConditionalBlock(e,n);case"each":return this.handleEachBlock(e);default:return this.addMessage("warning",`Unsupported block helper: ${n}`,e.loc),this.handleGenericBlock(e)}}handleConditionalBlock(e,n){const i={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(e.params[0])},operator:n==="unless"?"isFalsy":"isTruthy"}]},o=this.handleProgram(e.program),r=e.inverse?this.handleProgram(e.inverse):"";return`
|
|
2
|
+
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:i})}'>
|
|
3
3
|
<data-condition-true-content>${o}</data-condition-true-content>
|
|
4
|
-
<data-condition-false-content>${
|
|
4
|
+
<data-condition-false-content>${r}</data-condition-false-content>
|
|
5
5
|
</data-condition>
|
|
6
|
-
`}handleEachBlock(e){var
|
|
6
|
+
`}handleEachBlock(e){var i,o,r;const n=this.getExpressionString(e.params[0]);let s;e.params.length>=3&&e.params[1]==="as"&&((i=e.params[2])==null?void 0:i.type)==="PathExpression"?s=e.params[2].original:(r=(o=e.program)==null?void 0:o.blockParams)!=null&&r.length?s=e.program.blockParams[0]:s=`collection-${Math.random().toString(36).substring(2,10)}`,this.collectionStack.push(s);const a=this.handleProgram(e.program);return this.collectionStack.pop(),`
|
|
7
7
|
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:n},collectionId:s})}'>
|
|
8
8
|
<data-collection-item>${a}</data-collection-item>
|
|
9
9
|
</data-collection>
|
|
10
|
-
`}handleCommentStatement(e){return`<!--${e.value}-->`}handleElementNode(e){let n="";if(e.attributes)for(const a of e.attributes)a.value.type==="TextNode"?n+=` ${a.name}="${a.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${a.name}`,e.loc),n+=` ${a.name}="${this.getExpressionString(a.value)}"`);let s="";if(e.children)for(const a of e.children)s+=this.astToGrapesJS(a);return`<${e.tag}${n}>${s}</${e.tag}>`}handleTextNode(e){return e.chars||""}handlePartialStatement(e){return this.addMessage("warning",`Partials are not fully supported: ${e.name.original}`,e.loc),`{{> ${e.name.original}}}`}handleGenericBlock(e){const n=this.handleProgram(e.program);return`<!-- Unsupported block: ${e.path.original} -->${n}`}getExpressionString(e){return e.type==="PathExpression"?e.original:e.type==="StringLiteral"?e.value:e.type==="NumberLiteral"?e.value.toString():e.type==="BooleanLiteral"?e.value?"true":"false":e.type==="SubExpression"?this.getExpressionString(e.params[0]):e.type==="Hash"?`{${e.pairs.map(s=>`${s.key}=${this.getExpressionString(s.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${e.type}`,e.loc),"")}addMessage(e,n,s){this.messages.push({type:e,message:n,location:s?{line:s.start.line,column:s.start.column}:void 0})}}const b=t=>{if(t==null||t==="")return[];if(t===".")return["this"];if(t===".."||t==="../")return[".."];if(t.startsWith("../")){const o=t.substring(3);return["..",...b(o)]}const e=[];let n=0,s=t.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(o,
|
|
10
|
+
`}handleCommentStatement(e){return`<!--${e.value}-->`}handleElementNode(e){let n="";if(e.attributes)for(const a of e.attributes)a.value.type==="TextNode"?n+=` ${a.name}="${a.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${a.name}`,e.loc),n+=` ${a.name}="${this.getExpressionString(a.value)}"`);let s="";if(e.children)for(const a of e.children)s+=this.astToGrapesJS(a);return`<${e.tag}${n}>${s}</${e.tag}>`}handleTextNode(e){return e.chars||""}handlePartialStatement(e){return this.addMessage("warning",`Partials are not fully supported: ${e.name.original}`,e.loc),`{{> ${e.name.original}}}`}handleGenericBlock(e){const n=this.handleProgram(e.program);return`<!-- Unsupported block: ${e.path.original} -->${n}`}getExpressionString(e){return e.type==="PathExpression"?e.original:e.type==="StringLiteral"?e.value:e.type==="NumberLiteral"?e.value.toString():e.type==="BooleanLiteral"?e.value?"true":"false":e.type==="SubExpression"?this.getExpressionString(e.params[0]):e.type==="Hash"?`{${e.pairs.map(s=>`${s.key}=${this.getExpressionString(s.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${e.type}`,e.loc),"")}addMessage(e,n,s){this.messages.push({type:e,message:n,location:s?{line:s.start.line,column:s.start.column}:void 0})}}const b=t=>{if(t==null||t==="")return[];if(t===".")return["this"];if(t===".."||t==="../")return[".."];if(t.startsWith("../")){const o=t.substring(3);return["..",...b(o)]}const e=[];let n=0,s=t.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(o,r,c,u)=>{const h=c!==void 0?c:u||"";return e[n]=h,`__HANDLEBARS_PLACEHOLDER_${n++}__`});s=s.replace(/\//g,".");const a=s.split("."),i=[];for(const o of a){const r=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(o);if(r){const c=parseInt(r[1],10);i.push(e[c])}else o!==""&&i.push(o)}return i},U="dataSourceHandlebars",H=d.startup;return R(function(t,e={}){const n=D(t,new B),s=G(t,{contains:"{{",importer:new j});_({editor:t,licenseKey:e.licenseKey,plan:H,pluginName:U,cleanup:()=>{n(),s()}})})});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const A="app.grapesjs.com",k="app-stage.grapesjs.com",R="app2.grapesjs.com",_="app-stage2.grapesjs.com",x=[A,R,k,_,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],$="license:check:end",G=()=>typeof window<"u",N=({isDev:e,isStage:s,isPlatform:r})=>`${e?"":`https://${s?k:A}`}/${r?"platform-api":"api"}`,B=()=>{if(!G())return"";const{hostname:e}=window.location;if(e)return e;try{return window.parent.location.hostname||""}catch{return""}},
|
|
1
|
+
"use strict";const A="app.grapesjs.com",k="app-stage.grapesjs.com",R="app2.grapesjs.com",_="app-stage2.grapesjs.com",x=[A,R,k,_,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],$="license:check:end",G=()=>typeof window<"u",N=({isDev:e,isStage:s,isPlatform:r})=>`${e?"":`https://${s?k:A}`}/${r?"platform-api":"api"}`,B=()=>{if(!G())return"";const{hostname:e}=window.location;if(e)return e;try{return window.parent.location.hostname||""}catch{return""}},M=()=>{const e=B();return!!e&&(x.includes(e)||x.some(s=>e.endsWith(s)))};async function I({path:e,baseApiUrl:s,method:r="GET",headers:n={},params:c,body:i}){const a=`${s||N({isDev:!1,isStage:!1})}${e}`,g={method:r,headers:{"Content-Type":"application/json",...n}};i&&(g.body=JSON.stringify(i));const p=c?new URLSearchParams(c).toString():"",d=p?`?${p}`:"",o=await fetch(`${a}${d}`,g);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o.json()}var E=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(E||{}),T=(e=>(e.toastAdd="studio:toastAdd",e.toastRemove="studio:toastRemove",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.dialogExportCode="studio:dialogExportCode",e.dialogImportCode="studio:dialogImportCode",e.openEditCode="studio:openEditCode",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.clearPage="studio:clearPage",e.projectFiles="studio:projectFiles",e.validateCode="studio:validateCode",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.layoutComponentAdd="studio:layoutComponentAdd",e.layoutComponentGet="studio:layoutComponentGet",e.layoutComponentRemove="studio:layoutComponentRemove",e.layoutComponentRender="studio:layoutComponentRender",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.settings="studio:settings",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.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(T||{});const O={[E.free]:0,[E.startup]:10,[E.business]:20,[E.enterprise]:30};function m(e){const s=e;return s.init=r=>n=>e(n,r),s}const U=e=>m(e);async function q({editor:e,plan:s,pluginName:r,licenseKey:n,onLicenseCheckResponse:c,cleanup:i}){let u="",a;const g=o=>{console.warn("Cleanup plugin:",r,"Reason:",o),i()},p=(o={})=>{var b;const{error:v,sdkLicense:L}=o,l=(b=o.plan)==null?void 0:b.category;if(!(L||o.license)||v)g(v||"Invalid license");else if(l){const P=O[s],w=O[l];P>w&&g({pluginRequiredPlan:s,licensePlan:l})}};e.Commands.has(T.settings)&&(a=e.runCommand(T.settings),u=(a==null?void 0:a.baseUrl)||"");const d=o=>{c==null||c(o),o&&p(o)};if(!a){e.onReady(async()=>{if(!M())if(n){const o=await F({licenseKey:n,pluginName:r,baseApiUrl:u});d(o)}else g("The `licenseKey` option not provided")});return}if(a.licensePlan||a.licenseError){const o=X(a);d(o);return}e.on($,o=>d(o))}const X=e=>({sdkLicense:e.license,license:e.license,error:e.licenseError,plan:e.licensePlan});async function F(e){const{licenseKey:s,pluginName:r,baseApiUrl:n}=e;try{return(await I({baseApiUrl:n,path:`/sdk/${s||"na"}`,method:"POST",params:{d:window.location.hostname,pn:r}})).result||{}}catch(c){return console.error("Error during SDK license check:",c),!1}}const j=(...e)=>e.map(s=>`[data-gjs-type="${s}"]`).join(","),z="dialogComponent",H=function(e,s={}){const{Blocks:r,Components:n}=e,{licenseKey:c}=s,i="gjs-plg-dialog",u="gjs-plg-dialog-overlay",a="gjs-plg-dialog-content",g="gjs-plg-dialog-close",p="gjs-plg-dialog-title",d="gjs-plg-dialog-body",o="gjs-plg-dialog-description",v="gjs-plg-dialog-placeholder";r.add(i,{label:"Dialog",media:`
|
|
2
2
|
<svg viewBox="0 0 24 24">
|
|
3
3
|
<path d="M4 4h16v10H8l-4 4V4z"></path>
|
|
4
4
|
</svg>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
position: relative;
|
|
8
8
|
z-index: 1;
|
|
9
9
|
}
|
|
10
|
-
`,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(l){var t;(t=l.getSelected())==null||t.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(l){const t=this;function b(y){const f=t.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),h=t.querySelector('[data-type-role="gjs-plg-dialog-close"]');function
|
|
10
|
+
`,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(l){var t;(t=l.getSelected())==null||t.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(l){const t=this;function b(y){const f=t.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),h=t.querySelector('[data-type-role="gjs-plg-dialog-close"]');function W(){f.style.display="none"}y?(t._onCloseWhenPressingX=W,h.addEventListener("click",t._onCloseWhenPressingX)):(h.removeEventListener("click",t._onCloseWhenPressingX),t._onCloseWhenPressingX=null)}function P(y){const f=t.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function h(W){W.key==="Escape"&&(f.style.display="none")}y?(t._onCloseWhenPressingEsc=h,t.addEventListener("keydown",t._onCloseWhenPressingEsc)):(t.removeEventListener("keydown",t._onCloseWhenPressingEsc),t._onCloseWhenPressingEsc=null)}function w(y){const f=t.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function h(){f.style.display="flex"}y?(t._onOpenWhenLeavingWindow=h,document.addEventListener("mouseleave",t._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",t._onOpenWhenLeavingWindow),t._onOpenWhenLeavingWindow=null)}function D(y){const f=t.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function h(){const W=document.documentElement.scrollTop;y&&W>=Number(y)&&(f.style.display="flex")}y?(t._onOpenWhenScrollingToLevel=h,document.addEventListener("scroll",t._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",t._onOpenWhenScrollingToLevel),t._onOpenWhenScrollingToLevel=null)}b(l.closeWhenPressingX),P(l.closeWhenPressingEsc),w(l.openWhenLeavingWindow),D(l.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const t=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');t.style.display="flex"})}},view:{onActive(){const l=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');l.style.display="flex"}}}),n.addType(u,{model:{defaults:{tagName:"div",attributes:{class:u,"data-type-role":u},components:{type:a},droppable:!1,draggable:!1,styles:`
|
|
11
11
|
.${u} {
|
|
12
12
|
position: fixed;
|
|
13
13
|
top: 0;
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
.${o} {
|
|
57
57
|
margin: 0;
|
|
58
58
|
}
|
|
59
|
-
`}}}),n.addType(v,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:v,"data-type-role":v},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){const{em:l,el:t}=this,b="core:preview",P=l.Commands.events;this.listenTo(l,`${P.runCommand}${b}`,()=>{t.style.display="none"}),this.listenTo(l,`${P.stopCommand}${b}`,()=>{t.style.display=""})}}}),q({editor:e,licenseKey:c,plan:
|
|
59
|
+
`}}}),n.addType(v,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:v,"data-type-role":v},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){const{em:l,el:t}=this,b="core:preview",P=l.Commands.events;this.listenTo(l,`${P.runCommand}${b}`,()=>{t.style.display="none"}),this.listenTo(l,`${P.stopCommand}${b}`,()=>{t.style.display=""})}}}),q({editor:e,licenseKey:c,plan:E.startup,pluginName:z,cleanup:()=>{r.remove(i),n.removeType(i)}})},K=U(H);module.exports=K;
|