@grapesjs/studio-sdk-plugins 1.0.36 → 1.0.37
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 +4 -4
- package/dist/accordionComponent/index.es.js +83 -70
- package/dist/accordionComponent/index.umd.js +4 -4
- package/dist/aiChat/clientToolsProcessors.d.ts +1 -2
- package/dist/aiChat/components/utils.d.ts +1 -0
- package/dist/aiChat/components/utilsTw.d.ts +11 -0
- package/dist/aiChat/index.cjs.js +70 -70
- package/dist/aiChat/index.es.js +8627 -8161
- package/dist/aiChat/index.js +70 -70
- package/dist/aiChat/index.umd.js +70 -70
- package/dist/aiChat/projectGeneration.d.ts +17 -0
- package/dist/animationComponent/index.cjs.js +3 -3
- package/dist/animationComponent/index.es.js +55 -42
- package/dist/animationComponent/index.umd.js +3 -3
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
- package/dist/canvasAbsoluteMode/index.es.js +67 -54
- package/dist/canvasAbsoluteMode/index.umd.js +1 -1
- package/dist/canvasEmptyState/index.cjs.js +1 -1
- package/dist/canvasEmptyState/index.es.js +59 -46
- package/dist/canvasEmptyState/index.umd.js +1 -1
- package/dist/canvasFullSize/index.cjs.js +4 -4
- package/dist/canvasFullSize/index.es.js +59 -46
- package/dist/canvasFullSize/index.umd.js +4 -4
- package/dist/canvasGridMode/index.cjs.js +2 -2
- package/dist/canvasGridMode/index.es.js +70 -57
- package/dist/canvasGridMode/index.umd.js +4 -4
- package/dist/canvasScreenshot/index.cjs.js +1 -1
- package/dist/canvasScreenshot/index.es.js +37 -24
- package/dist/canvasScreenshot/index.umd.js +1 -1
- package/dist/dataSourceEjs/index.cjs.js +3 -3
- package/dist/dataSourceEjs/index.es.js +51 -38
- package/dist/dataSourceEjs/index.umd.js +3 -3
- package/dist/dataSourceHandlebars/index.cjs.js +2 -2
- package/dist/dataSourceHandlebars/index.es.js +50 -37
- package/dist/dataSourceHandlebars/index.umd.js +6 -6
- package/dist/dialogComponent/index.cjs.js +9 -9
- package/dist/dialogComponent/index.es.js +58 -45
- package/dist/dialogComponent/index.umd.js +3 -3
- package/dist/flexComponent/index.cjs.js +6 -6
- package/dist/flexComponent/index.es.js +82 -69
- package/dist/flexComponent/index.umd.js +6 -6
- package/dist/fsLightboxComponent/index.cjs.js +2 -2
- package/dist/fsLightboxComponent/index.es.js +70 -57
- package/dist/fsLightboxComponent/index.umd.js +2 -2
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +84 -71
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +82 -69
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.js +36 -36
- package/dist/index.es.js +843 -830
- package/dist/index.umd.js +36 -36
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +81 -68
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/lightGalleryComponent/index.cjs.js +1 -1
- package/dist/lightGalleryComponent/index.es.js +86 -73
- package/dist/lightGalleryComponent/index.umd.js +1 -1
- package/dist/linkImageComponent/index.cjs.js +2 -2
- package/dist/linkImageComponent/index.es.js +70 -57
- package/dist/linkImageComponent/index.umd.js +2 -2
- package/dist/listPagesComponent/index.cjs.js +3 -3
- package/dist/listPagesComponent/index.es.js +49 -36
- package/dist/listPagesComponent/index.umd.js +3 -3
- package/dist/presetPrintable/index.cjs.js +3 -3
- package/dist/presetPrintable/index.es.js +130 -117
- package/dist/presetPrintable/index.umd.js +3 -3
- package/dist/prosemirror/index.cjs.js +1 -1
- package/dist/prosemirror/index.es.js +96 -83
- package/dist/prosemirror/index.umd.js +1 -1
- package/dist/rendererReact/index.cjs.js +1 -1
- package/dist/rendererReact/index.es.js +143 -131
- 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 +74 -61
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/shapeDividerComponent/index.cjs.js +3 -3
- package/dist/shapeDividerComponent/index.es.js +33 -20
- package/dist/shapeDividerComponent/index.umd.js +3 -3
- package/dist/swiperComponent/index.cjs.js +5 -5
- package/dist/swiperComponent/index.es.js +105 -92
- package/dist/swiperComponent/index.umd.js +5 -5
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +163 -150
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +36 -23
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +2 -2
|
@@ -9,10 +9,14 @@ const D = "app.grapesjs.com", L = "app-stage.grapesjs.com", G = "app2.grapesjs.c
|
|
|
9
9
|
// For stackblitz.com demos
|
|
10
10
|
".local.webcontainer.io",
|
|
11
11
|
// For stackblitz.com demos
|
|
12
|
-
"-sandpack.codesandbox.io"
|
|
12
|
+
"-sandpack.codesandbox.io",
|
|
13
13
|
// For Sandpack demos
|
|
14
|
+
".claudemcpcontent.com",
|
|
15
|
+
// For Claude mcp app
|
|
16
|
+
".web-sandbox.oaiusercontent.com"
|
|
17
|
+
// For OpenAI mcp app
|
|
14
18
|
], x = "license:check:end", O = () => typeof window < "u", B = (e, o = {}) => {
|
|
15
|
-
const n =
|
|
19
|
+
const n = _(e) ? { id: e, src: e } : e;
|
|
16
20
|
return new Promise((r, a) => {
|
|
17
21
|
var p, d;
|
|
18
22
|
const { loadedScripts: i } = o, { id: c, src: s } = n, l = document.querySelector(`script[src="${s}"]`);
|
|
@@ -47,10 +51,19 @@ const D = "app.grapesjs.com", L = "app-stage.grapesjs.com", G = "app2.grapesjs.c
|
|
|
47
51
|
isStage: o,
|
|
48
52
|
isPlatform: n
|
|
49
53
|
}) => `${e ? "" : `https://${o ? L : D}`}/${n ? "platform-api" : "api"}`, $ = () => {
|
|
50
|
-
|
|
54
|
+
if (!O()) return "";
|
|
55
|
+
const { hostname: e } = window.location;
|
|
56
|
+
if (e) return e;
|
|
57
|
+
try {
|
|
58
|
+
return window.parent.location.hostname || "";
|
|
59
|
+
} catch {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}, j = () => {
|
|
63
|
+
const e = $();
|
|
51
64
|
return !!e && (A.includes(e) || A.some((o) => e.endsWith(o)));
|
|
52
|
-
},
|
|
53
|
-
async function
|
|
65
|
+
}, _ = (e) => typeof e == "string";
|
|
66
|
+
async function W({
|
|
54
67
|
path: e,
|
|
55
68
|
baseApiUrl: o,
|
|
56
69
|
method: n = "GET",
|
|
@@ -78,12 +91,12 @@ const R = {
|
|
|
78
91
|
[h.business]: 20,
|
|
79
92
|
[h.enterprise]: 30
|
|
80
93
|
};
|
|
81
|
-
function
|
|
94
|
+
function k(e) {
|
|
82
95
|
const o = e;
|
|
83
96
|
return o.init = (n) => (r) => e(r, n), o;
|
|
84
97
|
}
|
|
85
|
-
const
|
|
86
|
-
async function
|
|
98
|
+
const F = (e) => /* @__PURE__ */ k(e);
|
|
99
|
+
async function H({
|
|
87
100
|
editor: e,
|
|
88
101
|
plan: o,
|
|
89
102
|
pluginName: n,
|
|
@@ -110,9 +123,9 @@ async function F({
|
|
|
110
123
|
};
|
|
111
124
|
if (!s) {
|
|
112
125
|
e.onReady(async () => {
|
|
113
|
-
if (
|
|
126
|
+
if (!j())
|
|
114
127
|
if (r) {
|
|
115
|
-
const t = await
|
|
128
|
+
const t = await S({ licenseKey: r, pluginName: n, baseApiUrl: c });
|
|
116
129
|
g(t);
|
|
117
130
|
} else
|
|
118
131
|
l("The `licenseKey` option not provided");
|
|
@@ -120,22 +133,22 @@ async function F({
|
|
|
120
133
|
return;
|
|
121
134
|
}
|
|
122
135
|
if (s.licensePlan || s.licenseError) {
|
|
123
|
-
const t =
|
|
136
|
+
const t = K(s);
|
|
124
137
|
g(t);
|
|
125
138
|
return;
|
|
126
139
|
}
|
|
127
140
|
e.on(x, (t) => g(t));
|
|
128
141
|
}
|
|
129
|
-
const
|
|
142
|
+
const K = (e) => ({
|
|
130
143
|
sdkLicense: e.license,
|
|
131
144
|
license: e.license,
|
|
132
145
|
error: e.licenseError,
|
|
133
146
|
plan: e.licensePlan
|
|
134
147
|
});
|
|
135
|
-
async function
|
|
148
|
+
async function S(e) {
|
|
136
149
|
const { licenseKey: o, pluginName: n, baseApiUrl: r } = e;
|
|
137
150
|
try {
|
|
138
|
-
return (await
|
|
151
|
+
return (await W({
|
|
139
152
|
baseApiUrl: r,
|
|
140
153
|
path: `/sdk/${o || "na"}`,
|
|
141
154
|
method: "POST",
|
|
@@ -148,13 +161,13 @@ async function K(e) {
|
|
|
148
161
|
return console.error("Error during SDK license check:", a), !1;
|
|
149
162
|
}
|
|
150
163
|
}
|
|
151
|
-
const
|
|
164
|
+
const q = "canvasScreenshot", J = h.startup;
|
|
152
165
|
var E = /* @__PURE__ */ ((e) => (e.screenshot = "studioPlugin:screenshot", e))(E || {});
|
|
153
|
-
const
|
|
166
|
+
const z = async (e) => await N([{ id: "html-to-image", src: e }]), Q = async (e, o = {}, n = {}) => {
|
|
154
167
|
const { cdnScript: r } = n;
|
|
155
168
|
if (!window.htmlToImage) {
|
|
156
169
|
if (!r) return;
|
|
157
|
-
await
|
|
170
|
+
await z(r);
|
|
158
171
|
}
|
|
159
172
|
return new Promise((a, i) => {
|
|
160
173
|
(async () => {
|
|
@@ -181,14 +194,14 @@ const J = async (e) => await N([{ id: "html-to-image", src: e }]), z = async (e,
|
|
|
181
194
|
}
|
|
182
195
|
})();
|
|
183
196
|
});
|
|
184
|
-
}, w = E.screenshot,
|
|
197
|
+
}, w = E.screenshot, V = function(e, o = {}) {
|
|
185
198
|
const { Commands: n, Canvas: r, Storage: a } = e, i = a.events.afterStore, c = {
|
|
186
199
|
cdnScript: "https://cdnjs.cloudflare.com/ajax/libs/html-to-image/1.11.13/html-to-image.min.js",
|
|
187
200
|
...o
|
|
188
201
|
};
|
|
189
202
|
n.add(w, async (u, g, t) => {
|
|
190
203
|
const { el: p, ...d } = t;
|
|
191
|
-
return await
|
|
204
|
+
return await Q(p, d, c);
|
|
192
205
|
});
|
|
193
206
|
const s = async () => {
|
|
194
207
|
var g;
|
|
@@ -217,14 +230,14 @@ const J = async (e) => await N([{ id: "html-to-image", src: e }]), z = async (e,
|
|
|
217
230
|
const l = () => {
|
|
218
231
|
delete n.commands[w], e.off(i, s);
|
|
219
232
|
};
|
|
220
|
-
|
|
233
|
+
H({
|
|
221
234
|
editor: e,
|
|
222
235
|
licenseKey: o.licenseKey,
|
|
223
|
-
plan:
|
|
224
|
-
pluginName:
|
|
236
|
+
plan: J,
|
|
237
|
+
pluginName: q,
|
|
225
238
|
cleanup: l
|
|
226
239
|
});
|
|
227
|
-
},
|
|
240
|
+
}, X = F(V);
|
|
228
241
|
export {
|
|
229
|
-
|
|
242
|
+
X as default
|
|
230
243
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(f=typeof globalThis<"u"?globalThis:f||self,f.StudioSdkPlugins_canvasScreenshot=h())})(this,function(){"use strict";const f="app.grapesjs.com",h="app-stage.grapesjs.com",R=[f,"app2.grapesjs.com",h,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:end",L=()=>typeof window<"u",
|
|
1
|
+
(function(f,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(f=typeof globalThis<"u"?globalThis:f||self,f.StudioSdkPlugins_canvasScreenshot=h())})(this,function(){"use strict";const f="app.grapesjs.com",h="app-stage.grapesjs.com",R=[f,"app2.grapesjs.com",h,"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",L=()=>typeof window<"u",x=(e,o={})=>{const s=_(e)?{id:e,src:e}:e;return new Promise((r,a)=>{var p,d;const{loadedScripts:i}=o,{id:c,src:n}=s,l=document.querySelector(`script[src="${n}"]`);if(l){if((p=o.onScript)==null||p.call(o,l),i&&!i.get(n)){l.addEventListener("load",()=>r(c)),l.addEventListener("error",()=>a(c));return}return r(c)}const g=window.define;window.define=void 0;const u=()=>{i==null||i.set(n,!0),window.define=g},t=document.createElement("script");t.src=n,t.onload=()=>{r(c),u()},t.onerror=()=>{a(c),u()},document.head.appendChild(t),(d=o.onScript)==null||d.call(o,t)})},O=e=>{const o=e.map(s=>x(s));return Promise.allSettled(o)},M=async e=>{const o=window.define;window.define=void 0;const s=await O(e);return window.define=o,s},N=({isDev:e,isStage:o,isPlatform:s})=>`${e?"":`https://${o?h:f}`}/${s?"platform-api":"api"}`,B=()=>{if(!L())return"";const{hostname:e}=window.location;if(e)return e;try{return window.parent.location.hostname||""}catch{return""}},U=()=>{const e=B();return!!e&&(R.includes(e)||R.some(o=>e.endsWith(o)))},_=e=>typeof e=="string";async function j({path:e,baseApiUrl:o,method:s="GET",headers:r={},params:a,body:i}){const n=`${o||N({isDev:!1,isStage:!1})}${e}`,l={method:s,headers:{"Content-Type":"application/json",...r}};i&&(l.body=JSON.stringify(i));const g=a?new URLSearchParams(a).toString():"",u=g?`?${g}`:"",t=await fetch(`${n}${u}`,l);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()}var y=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(y||{}),P=(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))(P||{});const D={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function $(e){const o=e;return o.init=s=>r=>e(r,s),o}const k=e=>$(e);async function S({editor:e,plan:o,pluginName:s,licenseKey:r,onLicenseCheckResponse:a,cleanup:i}){let c="",n;const l=t=>{console.warn("Cleanup plugin:",s,"Reason:",t),i()},g=(t={})=>{var A;const{error:p,sdkLicense:d}=t,b=(A=t.plan)==null?void 0:A.category;if(!(d||t.license)||p)l(p||"Invalid license");else if(b){const v=D[o],w=D[b];v>w&&l({pluginRequiredPlan:o,licensePlan:b})}};e.Commands.has(P.settings)&&(n=e.runCommand(P.settings),c=(n==null?void 0:n.baseUrl)||"");const u=t=>{a==null||a(t),t&&g(t)};if(!n){e.onReady(async()=>{if(!U())if(r){const t=await F({licenseKey:r,pluginName:s,baseApiUrl:c});u(t)}else l("The `licenseKey` option not provided")});return}if(n.licensePlan||n.licenseError){const t=W(n);u(t);return}e.on(I,t=>u(t))}const W=e=>({sdkLicense:e.license,license:e.license,error:e.licenseError,plan:e.licensePlan});async function F(e){const{licenseKey:o,pluginName:s,baseApiUrl:r}=e;try{return(await j({baseApiUrl:r,path:`/sdk/${o||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}const H="canvasScreenshot",K=y.startup;var E=(e=>(e.screenshot="studioPlugin:screenshot",e))(E||{});const q=async e=>await M([{id:"html-to-image",src:e}]),J=async(e,o={},s={})=>{const{cdnScript:r}=s;if(!window.htmlToImage){if(!r)return;await q(r)}return new Promise((a,i)=>{(async()=>{try{const{canvasWidth:n,canvasHeight:l,width:g,height:u,type:t,quality:p,addOptions:d}=o,b={pixelRatio:1,width:g,height:u,canvasWidth:n,canvasHeight:l},G=(d==null?void 0:d(b))||b,v=await window.htmlToImage.toCanvas(e,G);v.toBlob(w=>{w?a({file:w,canvas:v}):i(new Error("Failed to create file from canvas"))},t,p)}catch(n){i(n)}})()})},T=E.screenshot;return k(function(e,o={}){const{Commands:s,Canvas:r,Storage:a}=e,i=a.events.afterStore,c={cdnScript:"https://cdnjs.cloudflare.com/ajax/libs/html-to-image/1.11.13/html-to-image.min.js",...o};s.add(T,async(g,u,t)=>{const{el:p,...d}=t;return await J(p,d,c)});const n=async()=>{var u;const g=r.getBody();if(!g)return e.log("Canvas element not found");try{const t=await e.runCommand(T,{el:g,canvasWidth:400,canvasHeight:225,width:1200,height:675,type:"image/jpeg"});(u=c.screenshotOnSave)==null||u.call(c,{...t,editor:e})}catch(t){console.error("Screenshot error",t)}};c.screenshotOnSave&&e.on(i,n);const l=()=>{delete s.commands[T],e.off(i,n)};S({editor:e,licenseKey:o.licenseKey,plan:K,pluginName:H,cleanup:l})})});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const m="app.grapesjs.com",I="app-stage.grapesjs.com",v="app2.grapesjs.com",w="app-stage2.grapesjs.com",$=[m,v,I,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],O="license:check:end",T=()=>typeof window<"u",L=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?I:m}`}/${e?"platform-api":"api"}`,k=()=>{if(!T())return"";const{hostname:s}=window.location;if(s)return s;try{return window.parent.location.hostname||""}catch{return""}},A=()=>{const s=k();return!!s&&($.includes(s)||$.some(t=>s.endsWith(t)))};async function B({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||L({isDev:!1,isStage:!1})}${s}`,l={method:e,headers:{"Content-Type":"application/json",...r}};a&&(l.body=JSON.stringify(a));const c=n?new URLSearchParams(n).toString():"",u=c?`?${c}`:"",p=await fetch(`${i}${u}`,l);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var y=(s=>(s.free="free",s.startup="startup",s.business="business",s.enterprise="enterprise",s))(y||{}),b=(s=>(s.toastAdd="studio:toastAdd",s.toastRemove="studio:toastRemove",s.dialogOpen="studio:dialogOpen",s.dialogClose="studio:dialogClose",s.dialogExportCode="studio:dialogExportCode",s.dialogImportCode="studio:dialogImportCode",s.sidebarLeftSet="studio:sidebarLeft:set",s.sidebarLeftGet="studio:sidebarLeft:get",s.sidebarLeftToggle="studio:sidebarLeft:toggle",s.sidebarRightSet="studio:sidebarRight:set",s.sidebarRightGet="studio:sidebarRight:get",s.sidebarRightToggle="studio:sidebarRight:toggle",s.sidebarTopSet="studio:sidebarTop:set",s.sidebarTopGet="studio:sidebarTop:get",s.sidebarTopToggle="studio:sidebarTop:toggle",s.sidebarBottomSet="studio:sidebarBottom:set",s.sidebarBottomGet="studio:sidebarBottom:get",s.sidebarBottomToggle="studio:sidebarBottom:toggle",s.symbolAdd="studio:symbolAdd",s.symbolDetach="studio:symbolDetach",s.symbolOverride="studio:symbolOverride",s.symbolPropagateStyles="studio:propagateStyles",s.getPagesConfig="studio:getPagesConfig",s.setPagesConfig="studio:setPagesConfig",s.getPageSettings="studio:getPageSettings",s.setPageSettings="studio:setPageSettings",s.clearPage="studio:clearPage",s.projectFiles="studio:projectFiles",s.validateCode="studio:validateCode",s.canvasReload="studio:canvasReload",s.getBlocksPanel="studio:getBlocksPanel",s.setBlocksPanel="studio:setBlocksPanel",s.getStateContextMenu="studio:getStateContextMenu",s.setStateContextMenu="studio:setStateContextMenu",s.contextMenuComponent="studio:contextMenuComponent",s.layoutAdd="studio:layoutAdd",s.layoutRemove="studio:layoutRemove",s.layoutToggle="studio:layoutToggle",s.layoutUpdate="studio:layoutUpdate",s.layoutGet="studio:layoutGet",s.layoutConfigGet="studio:layoutConfigGet",s.layoutConfigSet="studio:layoutConfigSet",s.layoutComponentAdd="studio:layoutComponentAdd",s.layoutComponentGet="studio:layoutComponentGet",s.layoutComponentRemove="studio:layoutComponentRemove",s.layoutComponentRender="studio:layoutComponentRender",s.getStateTheme="studio:getStateTheme",s.setStateTheme="studio:setStateTheme",s.settings="studio:settings",s.assetProviderGet="studio:assetProviderGet",s.assetProviderAdd="studio:assetProviderAdd",s.assetProviderRemove="studio:assetProviderRemove",s.fontGet="studio:fontGet",s.fontAdd="studio:fontAdd",s.fontRemove="studio:fontRemove",s.fontManagerOpen="studio:fontManagerOpen",s.menuFontLoad="studio:menuFontLoad",s.toggleStateDataSource="studio:toggleStateDataSource",s.getStateDataSource="studio:getStateDataSource",s.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",s.dataSourceSetImporter="studio:dataSourceSetImporter",s.dataSourceSetExporter="studio:dataSourceSetExporter",s.setDragAbsolute="studio:setDragAbsolute",s))(b||{});const S={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function N(s){const t=s;return t.init=e=>r=>s(r,e),t}const M=s=>N(s);async function G({editor:s,plan:t,pluginName:e,licenseKey:r,onLicenseCheckResponse:n,cleanup:a}){let o="",i;const l=p=>{console.warn("Cleanup plugin:",e,"Reason:",p),a()},c=(p={})=>{var f;const{error:h,sdkLicense:E}=p,g=(f=p.plan)==null?void 0:f.category;if(!(E||p.license)||h)l(h||"Invalid license");else if(g){const x=S[t],P=S[g];x>P&&l({pluginRequiredPlan:t,licensePlan:g})}};s.Commands.has(b.settings)&&(i=s.runCommand(b.settings),o=(i==null?void 0:i.baseUrl)||"");const u=p=>{n==null||n(p),p&&c(p)};if(!i){s.onReady(async()=>{if(!A())if(r){const p=await D({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=j(i);u(p);return}s.on(O,p=>u(p))}const j=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function D(s){const{licenseKey:t,pluginName:e,baseApiUrl:r}=s;try{return(await B({baseApiUrl:r,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const F=s=>{const t=s;return t.logicalOperator==="and"||t.logicalOperator==="or"},J=(s,t)=>(s.config.optsHtml={...s.config.optsHtml,exporter:t},()=>{s.config.optsHtml.exporter=void 0}),W=(s,t)=>{const e=n=>{const{input:a}=n,{contains:o}=t;(!o||a.includes(o))&&(n.input=t.importer.import(a))},r=s.Parser.events.htmlBefore;return s.on(r,e),()=>{s.off(r,e)}};class _{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,r=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${r}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:r,startIndex:n,endIndex:a}=t,o=(r==null?void 0:r.path)||e||"",i=this._sanitizeVariableName(e);let l="";if(n!==void 0||a!==void 0){const c=n??0,u=a!==void 0?a:"";l=`.slice(${c}${u!==""?`, ${u}`:""})`}return`<% ${o}${l}.forEach(function(currentItem, index, arr) {
|
|
2
2
|
const startIndex = parseInt(${n??0}, 10);
|
|
3
3
|
const endIndex = startIndex + arr.length;
|
|
4
|
-
const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:r}){return(t?[this._sanitizeVariableName(t),r,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(
|
|
4
|
+
const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:r}){return(t?[this._sanitizeVariableName(t),r,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(F(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=R[t.logicalOperator];let n=e.length>1?`(${e.join(`)${r}(`)})`:e[0];return t.logicalOperator==="xor"&&(n=`!!(${n})`),n}else{const e=this._parseValue(t.left),r=this._parseValue(t.right);switch(t.operator){case"equals":return`${e} === ${r}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${e} ${t.operator} ${r}`;case"contains":return`${e}?.includes(${r})`;case"startsWith":return`${e}?.startsWith(${r})`;case"endsWith":return`${e}?.endsWith(${r})`;case"equalsIgnoreCase":return`${e}?.toLowerCase() === ${r}?.toLowerCase()`;case"trimEquals":return`${e}?.trim() === ${r}?.trim()`;case"isTruthy":return`!!${e}`;case"isFalsy":return`!${e}`;case"isDefined":return`${e} !== undefined`;case"isNull":return`${e} === null`;case"isUndefined":return`${e} === undefined`;case"isArray":return`Array.isArray(${e})`;case"isObject":return`typeof ${e} === 'object' && ${e} !== null && !Array.isArray(${e})`;case"isString":return`typeof ${e} === 'string'`;case"isNumber":return`typeof ${e} === 'number' && !isNaN(${e})`;case"isBoolean":return`typeof ${e} === 'boolean'`;default:return`${e} ${t.operator} ${r}`}}}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}}const R={and:"&&",or:"||",xor:"^"},U=["===","==","!==","!=","<=",">=","<",">","&&","||"],V={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class q{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let r=0;for(;r<t.length;){const n=t.indexOf("<%",r);if(n===-1){r<t.length&&e.push(this.createAppendLiteral(t.slice(r)));break}n>r&&e.push(this.createAppendLiteral(t.slice(r,n)));const a=t.indexOf("%>",n);if(a===-1)throw new Error("Unclosed EJS tag");const o=t.slice(n+2,a).trim();if(r=a+2,o.startsWith("=")||o.startsWith("-")){const i=o.slice(1).trim();e.push(this.createAppendExpression(i))}else{if(o.startsWith("#"))continue;if(o.startsWith("if")){const i=this.parseIfStatement(o,t,r);e.push(i),r=i.endPos||r}else if(o.startsWith("for")){const i=this.parseForStatement(o,t,r);e.push(i),r=i.endPos||r}else{const i=o.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(i){const l=i[1],c=i[2],u=this.parseForEachStatement(l,c,t,r);e.push(u),r=u.endPos||r}else this.addMessage("info",`Unsupported scriptlet content: ${o}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,r){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const a=this.parseJsExpression(n[1]),{body:o,endPos:i}=this.parseTemplateBlock(e,r);let l=null,c=i;const u=e.indexOf("<%",c);if(u===c){const p=e.indexOf("%>",u);if(p!==-1){const h=e.slice(u+2,p).trim(),E=p+2-u;if(h.startsWith("} else if")){c=u+E;const g=h.substring(h.indexOf("if")).trim(),d=this.parseIfStatement(g,e,c);l={type:"IfStatement",test:d.test,consequent:d.consequent,alternate:d.alternate},c=d.endPos}else if(h.startsWith("} else")){c=u+E;const{body:g,endPos:d}=this.parseTemplateBlock(e,c);l={type:"BlockStatement",body:g},c=d;const f=e.indexOf("<%",c),x=e.indexOf("%>",f);f===c&&e.slice(f+2,x).trim()==="}"&&(c=x+2)}else h==="}"&&(c=u+E)}}return{type:"IfStatement",test:a,consequent:{type:"BlockStatement",body:o},alternate:l,endPos:c}}parseForStatement(t,e,r){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const a=n[1].split("of");if(a.length!==2)throw new Error("Only for...of loops are supported");const o=a[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),i=a[1].trim(),{body:l,endPos:c}=this.parseTemplateBlock(e,r);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:this.parseJsExpression(i)}]},test:null,update:null,body:{type:"BlockStatement",body:l},endPos:(()=>{const u=e.indexOf("<%",c),p=e.indexOf("%>",u);return u===c&&e.slice(u+2,p).trim()==="}"?p+2:c})()}}parseForEachStatement(t,e,r,n){const{body:a,endPos:o}=this.parseTemplateBlock(r,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:a},endPos:(()=>{const i=r.indexOf("<%",o),l=r.indexOf("%>",i);return i===o&&r.slice(i+2,l).trim()==="}"?l+2:o})()}}parseTemplateBlock(t,e){const r=[];let n=e;for(;n<t.length;){const a=t.indexOf("<%",n);if(a===-1){n<t.length&&r.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}a>n&&r.push(this.createAppendLiteral(t.slice(n,a)));const o=t.indexOf("%>",a);if(o===-1)throw new Error("Unclosed EJS tag within block");const i=t.slice(a+2,o).trim();if(i==="}"||i.startsWith("} else")){n=a;break}if(n=o+2,i.startsWith("=")||i.startsWith("-")){const l=i.slice(1).trim();r.push(this.createAppendExpression(l))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const l=this.parseIfStatement(i,t,n);r.push(l),n=l.endPos||n}else if(i.startsWith("for")){const l=this.parseForStatement(i,t,n);r.push(l),n=l.endPos||n}else{const l=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(l){const c=l[1],u=l[2],p=this.parseForEachStatement(c,u,t,n);r.push(p),n=p.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${i}`)}}}return{body:r,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of U){const a=t.lastIndexOf(n);if(a>0&&t[a-1]!=="!"&&t[a-1]!=="="&&t[a-1]!=="<"&&t[a-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:V[n],left:this.parseJsExpression(t.slice(0,a).trim()),right:this.parseJsExpression(t.slice(a+n.length).trim())}}const e=t.indexOf("."),r=t.indexOf("[");if(e>0&&(r===-1||e<r)||r>0&&(e===-1||r<e)){const n=e>0&&(r===-1||e<r)?e:r;let a,o,i=!1;if(n===e)a=t.slice(0,e),o={type:"Identifier",name:t.slice(e+1)},i=!1;else{a=t.slice(0,r);const l=t.indexOf("]",r);if(l===-1)throw new Error("Unclosed bracket in expression");const c=t.slice(r+1,l);o=/^(['"]).*\1$/.test(c)||/^-?\d+(\.\d+)?$/.test(c)?this.parseJsExpression(c):{type:"Identifier",name:c},i=!0}return{type:"MemberExpression",object:this.parseJsExpression(a),property:o,computed:i}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),r=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
|
|
5
5
|
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:e})}'>
|
|
6
6
|
<data-condition-true-content>${r}</data-condition-true-content>
|
|
7
7
|
<data-condition-false-content>${n}</data-condition-false-content>
|
|
@@ -18,4 +18,4 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
18
18
|
${a}
|
|
19
19
|
</data-collection-item>
|
|
20
20
|
</data-collection>
|
|
21
|
-
`}handleBlockStatement(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];t.name===r&&(e={collectionId:r,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const a=this.collectionStack[this.collectionStack.length-1];let o=t;const i=[];for(;o.type==="MemberExpression";)o.property.type==="Identifier"&&!o.computed?i.unshift(o.property.name):o.property.type==="Literal"&&o.computed?i.unshift(String(o.property.value)):i.unshift(this.getExpressionString(o.property)),o=o.object;if(o.type==="Identifier"&&o.name===a){const l=i.join(".");n={...e,collectionId:a,variableType:"currentItem",path:l}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const r=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${r}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),r="isTruthy";return e.startsWith("!!")?(r="isTruthy",e=e.slice(2)):e.startsWith("!")&&(r="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:r}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),r=this.getConditionExpression(t.right);return`${e} ${t.operator} ${r}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),r=this.getExpressionString(t.property);return t.computed?`${e}[${r}]`:`${e}.${r}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const
|
|
21
|
+
`}handleBlockStatement(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];t.name===r&&(e={collectionId:r,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const a=this.collectionStack[this.collectionStack.length-1];let o=t;const i=[];for(;o.type==="MemberExpression";)o.property.type==="Identifier"&&!o.computed?i.unshift(o.property.name):o.property.type==="Literal"&&o.computed?i.unshift(String(o.property.value)):i.unshift(this.getExpressionString(o.property)),o=o.object;if(o.type==="Identifier"&&o.name===a){const l=i.join(".");n={...e,collectionId:a,variableType:"currentItem",path:l}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const r=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${r}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),r="isTruthy";return e.startsWith("!!")?(r="isTruthy",e=e.slice(2)):e.startsWith("!")&&(r="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:r}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),r=this.getConditionExpression(t.right);return`${e} ${t.operator} ${r}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),r=this.getExpressionString(t.property);return t.computed?`${e}[${r}]`:`${e}.${r}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const H="dataSourceEjs",K=y.startup,z=function(s,t={}){const e=J(s,new _),r=W(s,{contains:"<%",importer:new q});G({editor:s,licenseKey:t.licenseKey,plan:K,pluginName:H,cleanup:()=>{e(),r()}})},C=M(z);module.exports=C;
|
|
@@ -1,25 +1,38 @@
|
|
|
1
|
-
const
|
|
2
|
-
I,
|
|
3
|
-
v,
|
|
1
|
+
const m = "app.grapesjs.com", I = "app-stage.grapesjs.com", v = "app2.grapesjs.com", w = "app-stage2.grapesjs.com", $ = [
|
|
4
2
|
m,
|
|
5
|
-
|
|
3
|
+
v,
|
|
4
|
+
I,
|
|
5
|
+
w,
|
|
6
6
|
"localhost",
|
|
7
7
|
"127.0.0.1",
|
|
8
8
|
".local-credentialless.webcontainer.io",
|
|
9
9
|
// For stackblitz.com demos
|
|
10
10
|
".local.webcontainer.io",
|
|
11
11
|
// For stackblitz.com demos
|
|
12
|
-
"-sandpack.codesandbox.io"
|
|
12
|
+
"-sandpack.codesandbox.io",
|
|
13
13
|
// For Sandpack demos
|
|
14
|
-
|
|
14
|
+
".claudemcpcontent.com",
|
|
15
|
+
// For Claude mcp app
|
|
16
|
+
".web-sandbox.oaiusercontent.com"
|
|
17
|
+
// For OpenAI mcp app
|
|
18
|
+
], O = "license:check:end", T = () => typeof window < "u", L = ({
|
|
15
19
|
isDev: s,
|
|
16
20
|
isStage: t,
|
|
17
21
|
isPlatform: e
|
|
18
|
-
}) => `${s ? "" : `https://${t ?
|
|
19
|
-
|
|
22
|
+
}) => `${s ? "" : `https://${t ? I : m}`}/${e ? "platform-api" : "api"}`, k = () => {
|
|
23
|
+
if (!T()) return "";
|
|
24
|
+
const { hostname: s } = window.location;
|
|
25
|
+
if (s) return s;
|
|
26
|
+
try {
|
|
27
|
+
return window.parent.location.hostname || "";
|
|
28
|
+
} catch {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}, A = () => {
|
|
32
|
+
const s = k();
|
|
20
33
|
return !!s && ($.includes(s) || $.some((t) => s.endsWith(t)));
|
|
21
34
|
};
|
|
22
|
-
async function
|
|
35
|
+
async function B({
|
|
23
36
|
path: s,
|
|
24
37
|
baseApiUrl: t,
|
|
25
38
|
method: e = "GET",
|
|
@@ -47,12 +60,12 @@ const S = {
|
|
|
47
60
|
[y.business]: 20,
|
|
48
61
|
[y.enterprise]: 30
|
|
49
62
|
};
|
|
50
|
-
function
|
|
63
|
+
function N(s) {
|
|
51
64
|
const t = s;
|
|
52
65
|
return t.init = (e) => (r) => s(r, e), t;
|
|
53
66
|
}
|
|
54
|
-
const
|
|
55
|
-
async function
|
|
67
|
+
const M = (s) => /* @__PURE__ */ N(s);
|
|
68
|
+
async function G({
|
|
56
69
|
editor: s,
|
|
57
70
|
plan: t,
|
|
58
71
|
pluginName: e,
|
|
@@ -79,9 +92,9 @@ async function M({
|
|
|
79
92
|
};
|
|
80
93
|
if (!i) {
|
|
81
94
|
s.onReady(async () => {
|
|
82
|
-
if (!
|
|
95
|
+
if (!A())
|
|
83
96
|
if (r) {
|
|
84
|
-
const p = await
|
|
97
|
+
const p = await D({ licenseKey: r, pluginName: e, baseApiUrl: o });
|
|
85
98
|
u(p);
|
|
86
99
|
} else
|
|
87
100
|
l("The `licenseKey` option not provided");
|
|
@@ -89,22 +102,22 @@ async function M({
|
|
|
89
102
|
return;
|
|
90
103
|
}
|
|
91
104
|
if (i.licensePlan || i.licenseError) {
|
|
92
|
-
const p =
|
|
105
|
+
const p = j(i);
|
|
93
106
|
u(p);
|
|
94
107
|
return;
|
|
95
108
|
}
|
|
96
|
-
s.on(
|
|
109
|
+
s.on(O, (p) => u(p));
|
|
97
110
|
}
|
|
98
|
-
const
|
|
111
|
+
const j = (s) => ({
|
|
99
112
|
sdkLicense: s.license,
|
|
100
113
|
license: s.license,
|
|
101
114
|
error: s.licenseError,
|
|
102
115
|
plan: s.licensePlan
|
|
103
116
|
});
|
|
104
|
-
async function
|
|
117
|
+
async function D(s) {
|
|
105
118
|
const { licenseKey: t, pluginName: e, baseApiUrl: r } = s;
|
|
106
119
|
try {
|
|
107
|
-
return (await
|
|
120
|
+
return (await B({
|
|
108
121
|
baseApiUrl: r,
|
|
109
122
|
path: `/sdk/${t || "na"}`,
|
|
110
123
|
method: "POST",
|
|
@@ -117,15 +130,15 @@ async function j(s) {
|
|
|
117
130
|
return console.error("Error during SDK license check:", n), !1;
|
|
118
131
|
}
|
|
119
132
|
}
|
|
120
|
-
const
|
|
133
|
+
const F = (s) => {
|
|
121
134
|
const t = s;
|
|
122
135
|
return t.logicalOperator === "and" || t.logicalOperator === "or";
|
|
123
|
-
},
|
|
136
|
+
}, J = (s, t) => (s.config.optsHtml = {
|
|
124
137
|
...s.config.optsHtml,
|
|
125
138
|
exporter: t
|
|
126
139
|
}, () => {
|
|
127
140
|
s.config.optsHtml.exporter = void 0;
|
|
128
|
-
}),
|
|
141
|
+
}), W = (s, t) => {
|
|
129
142
|
const e = (n) => {
|
|
130
143
|
const { input: a } = n, { contains: o } = t;
|
|
131
144
|
(!o || a.includes(o)) && (n.input = t.importer.import(a));
|
|
@@ -134,7 +147,7 @@ const D = (s) => {
|
|
|
134
147
|
s.off(r, e);
|
|
135
148
|
};
|
|
136
149
|
};
|
|
137
|
-
class
|
|
150
|
+
class _ {
|
|
138
151
|
getVariableSyntax({ dataResolver: t }) {
|
|
139
152
|
const { defaultValue: e } = t, r = this.getFullPath(t), n = e ? ` || \`${e}\`` : "";
|
|
140
153
|
return `<%= ${r}${n} %>`;
|
|
@@ -171,8 +184,8 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
171
184
|
}
|
|
172
185
|
_parseCondition(t) {
|
|
173
186
|
if (!t) return "";
|
|
174
|
-
if (
|
|
175
|
-
const e = t.statements.map((a) => this._parseCondition(a)), r =
|
|
187
|
+
if (F(t)) {
|
|
188
|
+
const e = t.statements.map((a) => this._parseCondition(a)), r = R[t.logicalOperator];
|
|
176
189
|
let n = e.length > 1 ? `(${e.join(`)${r}(`)})` : e[0];
|
|
177
190
|
return t.logicalOperator === "xor" && (n = `!!(${n})`), n;
|
|
178
191
|
} else {
|
|
@@ -226,11 +239,11 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
226
239
|
return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
|
|
227
240
|
}
|
|
228
241
|
}
|
|
229
|
-
const
|
|
242
|
+
const R = {
|
|
230
243
|
and: "&&",
|
|
231
244
|
or: "||",
|
|
232
245
|
xor: "^"
|
|
233
|
-
},
|
|
246
|
+
}, U = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], V = {
|
|
234
247
|
"===": "=",
|
|
235
248
|
"==": "=",
|
|
236
249
|
"!==": "!=",
|
|
@@ -242,7 +255,7 @@ const _ = {
|
|
|
242
255
|
"&&": "&&",
|
|
243
256
|
"||": "||"
|
|
244
257
|
};
|
|
245
|
-
class
|
|
258
|
+
class q {
|
|
246
259
|
constructor() {
|
|
247
260
|
this.messages = [], this.collectionStack = [];
|
|
248
261
|
}
|
|
@@ -472,12 +485,12 @@ class V {
|
|
|
472
485
|
type: "Literal",
|
|
473
486
|
value: t === "true"
|
|
474
487
|
};
|
|
475
|
-
for (const n of
|
|
488
|
+
for (const n of U) {
|
|
476
489
|
const a = t.lastIndexOf(n);
|
|
477
490
|
if (a > 0 && t[a - 1] !== "!" && t[a - 1] !== "=" && t[a - 1] !== "<" && t[a - 1] !== ">")
|
|
478
491
|
return {
|
|
479
492
|
type: n === "&&" || n === "||" ? "LogicalExpression" : "BinaryExpression",
|
|
480
|
-
operator:
|
|
493
|
+
operator: V[n],
|
|
481
494
|
left: this.parseJsExpression(t.slice(0, a).trim()),
|
|
482
495
|
right: this.parseJsExpression(t.slice(a + n.length).trim())
|
|
483
496
|
};
|
|
@@ -717,21 +730,21 @@ class V {
|
|
|
717
730
|
});
|
|
718
731
|
}
|
|
719
732
|
}
|
|
720
|
-
const
|
|
721
|
-
const e =
|
|
733
|
+
const H = "dataSourceEjs", K = y.startup, z = function(s, t = {}) {
|
|
734
|
+
const e = J(s, new _()), r = W(s, {
|
|
722
735
|
contains: "<%",
|
|
723
|
-
importer: new
|
|
736
|
+
importer: new q()
|
|
724
737
|
});
|
|
725
|
-
|
|
738
|
+
G({
|
|
726
739
|
editor: s,
|
|
727
740
|
licenseKey: t.licenseKey,
|
|
728
|
-
plan:
|
|
729
|
-
pluginName:
|
|
741
|
+
plan: K,
|
|
742
|
+
pluginName: H,
|
|
730
743
|
cleanup: () => {
|
|
731
744
|
e(), r();
|
|
732
745
|
}
|
|
733
746
|
});
|
|
734
|
-
},
|
|
747
|
+
}, C = M(z);
|
|
735
748
|
export {
|
|
736
|
-
|
|
749
|
+
C as default
|
|
737
750
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(f,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(f=typeof globalThis<"u"?globalThis:f||self,f.StudioSdkPlugins_dataSourceEjs=y())})(this,function(){"use strict";const f="app.grapesjs.com",y="app-stage.grapesjs.com",
|
|
1
|
+
(function(f,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(f=typeof globalThis<"u"?globalThis:f||self,f.StudioSdkPlugins_dataSourceEjs=y())})(this,function(){"use strict";const f="app.grapesjs.com",y="app-stage.grapesjs.com",m=[f,"app2.grapesjs.com",y,"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"],P="license:check:end",v=()=>typeof window<"u",O=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?y:f}`}/${e?"platform-api":"api"}`,w=()=>{if(!v())return"";const{hostname:s}=window.location;if(s)return s;try{return window.parent.location.hostname||""}catch{return""}},T=()=>{const s=w();return!!s&&(m.includes(s)||m.some(t=>s.endsWith(t)))};async function L({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||O({isDev:!1,isStage:!1})}${s}`,l={method:e,headers:{"Content-Type":"application/json",...r}};a&&(l.body=JSON.stringify(a));const c=n?new URLSearchParams(n).toString():"",u=c?`?${c}`:"",p=await fetch(`${i}${u}`,l);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var E=(s=>(s.free="free",s.startup="startup",s.business="business",s.enterprise="enterprise",s))(E||{}),S=(s=>(s.toastAdd="studio:toastAdd",s.toastRemove="studio:toastRemove",s.dialogOpen="studio:dialogOpen",s.dialogClose="studio:dialogClose",s.dialogExportCode="studio:dialogExportCode",s.dialogImportCode="studio:dialogImportCode",s.sidebarLeftSet="studio:sidebarLeft:set",s.sidebarLeftGet="studio:sidebarLeft:get",s.sidebarLeftToggle="studio:sidebarLeft:toggle",s.sidebarRightSet="studio:sidebarRight:set",s.sidebarRightGet="studio:sidebarRight:get",s.sidebarRightToggle="studio:sidebarRight:toggle",s.sidebarTopSet="studio:sidebarTop:set",s.sidebarTopGet="studio:sidebarTop:get",s.sidebarTopToggle="studio:sidebarTop:toggle",s.sidebarBottomSet="studio:sidebarBottom:set",s.sidebarBottomGet="studio:sidebarBottom:get",s.sidebarBottomToggle="studio:sidebarBottom:toggle",s.symbolAdd="studio:symbolAdd",s.symbolDetach="studio:symbolDetach",s.symbolOverride="studio:symbolOverride",s.symbolPropagateStyles="studio:propagateStyles",s.getPagesConfig="studio:getPagesConfig",s.setPagesConfig="studio:setPagesConfig",s.getPageSettings="studio:getPageSettings",s.setPageSettings="studio:setPageSettings",s.clearPage="studio:clearPage",s.projectFiles="studio:projectFiles",s.validateCode="studio:validateCode",s.canvasReload="studio:canvasReload",s.getBlocksPanel="studio:getBlocksPanel",s.setBlocksPanel="studio:setBlocksPanel",s.getStateContextMenu="studio:getStateContextMenu",s.setStateContextMenu="studio:setStateContextMenu",s.contextMenuComponent="studio:contextMenuComponent",s.layoutAdd="studio:layoutAdd",s.layoutRemove="studio:layoutRemove",s.layoutToggle="studio:layoutToggle",s.layoutUpdate="studio:layoutUpdate",s.layoutGet="studio:layoutGet",s.layoutConfigGet="studio:layoutConfigGet",s.layoutConfigSet="studio:layoutConfigSet",s.layoutComponentAdd="studio:layoutComponentAdd",s.layoutComponentGet="studio:layoutComponentGet",s.layoutComponentRemove="studio:layoutComponentRemove",s.layoutComponentRender="studio:layoutComponentRender",s.getStateTheme="studio:getStateTheme",s.setStateTheme="studio:setStateTheme",s.settings="studio:settings",s.assetProviderGet="studio:assetProviderGet",s.assetProviderAdd="studio:assetProviderAdd",s.assetProviderRemove="studio:assetProviderRemove",s.fontGet="studio:fontGet",s.fontAdd="studio:fontAdd",s.fontRemove="studio:fontRemove",s.fontManagerOpen="studio:fontManagerOpen",s.menuFontLoad="studio:menuFontLoad",s.toggleStateDataSource="studio:toggleStateDataSource",s.getStateDataSource="studio:getStateDataSource",s.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",s.dataSourceSetImporter="studio:dataSourceSetImporter",s.dataSourceSetExporter="studio:dataSourceSetExporter",s.setDragAbsolute="studio:setDragAbsolute",s))(S||{});const I={[E.free]:0,[E.startup]:10,[E.business]:20,[E.enterprise]:30};function k(s){const t=s;return t.init=e=>r=>s(r,e),t}const A=s=>k(s);async function N({editor:s,plan:t,pluginName:e,licenseKey:r,onLicenseCheckResponse:n,cleanup:a}){let o="",i;const l=p=>{console.warn("Cleanup plugin:",e,"Reason:",p),a()},c=(p={})=>{var x;const{error:h,sdkLicense:b}=p,d=(x=p.plan)==null?void 0:x.category;if(!(b||p.license)||h)l(h||"Invalid license");else if(d){const $=I[t],q=I[d];$>q&&l({pluginRequiredPlan:t,licensePlan:d})}};s.Commands.has(S.settings)&&(i=s.runCommand(S.settings),o=(i==null?void 0:i.baseUrl)||"");const u=p=>{n==null||n(p),p&&c(p)};if(!i){s.onReady(async()=>{if(!T())if(r){const p=await M({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=B(i);u(p);return}s.on(P,p=>u(p))}const B=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function M(s){const{licenseKey:t,pluginName:e,baseApiUrl:r}=s;try{return(await L({baseApiUrl:r,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const j=s=>{const t=s;return t.logicalOperator==="and"||t.logicalOperator==="or"},D=(s,t)=>(s.config.optsHtml={...s.config.optsHtml,exporter:t},()=>{s.config.optsHtml.exporter=void 0}),G=(s,t)=>{const e=n=>{const{input:a}=n,{contains:o}=t;(!o||a.includes(o))&&(n.input=t.importer.import(a))},r=s.Parser.events.htmlBefore;return s.on(r,e),()=>{s.off(r,e)}};class F{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,r=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${r}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:r,startIndex:n,endIndex:a}=t,o=(r==null?void 0:r.path)||e||"",i=this._sanitizeVariableName(e);let l="";if(n!==void 0||a!==void 0){const c=n??0,u=a!==void 0?a:"";l=`.slice(${c}${u!==""?`, ${u}`:""})`}return`<% ${o}${l}.forEach(function(currentItem, index, arr) {
|
|
2
2
|
const startIndex = parseInt(${n??0}, 10);
|
|
3
3
|
const endIndex = startIndex + arr.length;
|
|
4
|
-
const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:r}){return(t?[this._sanitizeVariableName(t),r,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(
|
|
4
|
+
const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:r}){return(t?[this._sanitizeVariableName(t),r,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(j(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=_[t.logicalOperator];let n=e.length>1?`(${e.join(`)${r}(`)})`:e[0];return t.logicalOperator==="xor"&&(n=`!!(${n})`),n}else{const e=this._parseValue(t.left),r=this._parseValue(t.right);switch(t.operator){case"equals":return`${e} === ${r}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${e} ${t.operator} ${r}`;case"contains":return`${e}?.includes(${r})`;case"startsWith":return`${e}?.startsWith(${r})`;case"endsWith":return`${e}?.endsWith(${r})`;case"equalsIgnoreCase":return`${e}?.toLowerCase() === ${r}?.toLowerCase()`;case"trimEquals":return`${e}?.trim() === ${r}?.trim()`;case"isTruthy":return`!!${e}`;case"isFalsy":return`!${e}`;case"isDefined":return`${e} !== undefined`;case"isNull":return`${e} === null`;case"isUndefined":return`${e} === undefined`;case"isArray":return`Array.isArray(${e})`;case"isObject":return`typeof ${e} === 'object' && ${e} !== null && !Array.isArray(${e})`;case"isString":return`typeof ${e} === 'string'`;case"isNumber":return`typeof ${e} === 'number' && !isNaN(${e})`;case"isBoolean":return`typeof ${e} === 'boolean'`;default:return`${e} ${t.operator} ${r}`}}}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}}const _={and:"&&",or:"||",xor:"^"},J=["===","==","!==","!=","<=",">=","<",">","&&","||"],W={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class R{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let r=0;for(;r<t.length;){const n=t.indexOf("<%",r);if(n===-1){r<t.length&&e.push(this.createAppendLiteral(t.slice(r)));break}n>r&&e.push(this.createAppendLiteral(t.slice(r,n)));const a=t.indexOf("%>",n);if(a===-1)throw new Error("Unclosed EJS tag");const o=t.slice(n+2,a).trim();if(r=a+2,o.startsWith("=")||o.startsWith("-")){const i=o.slice(1).trim();e.push(this.createAppendExpression(i))}else{if(o.startsWith("#"))continue;if(o.startsWith("if")){const i=this.parseIfStatement(o,t,r);e.push(i),r=i.endPos||r}else if(o.startsWith("for")){const i=this.parseForStatement(o,t,r);e.push(i),r=i.endPos||r}else{const i=o.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(i){const l=i[1],c=i[2],u=this.parseForEachStatement(l,c,t,r);e.push(u),r=u.endPos||r}else this.addMessage("info",`Unsupported scriptlet content: ${o}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,r){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const a=this.parseJsExpression(n[1]),{body:o,endPos:i}=this.parseTemplateBlock(e,r);let l=null,c=i;const u=e.indexOf("<%",c);if(u===c){const p=e.indexOf("%>",u);if(p!==-1){const h=e.slice(u+2,p).trim(),b=p+2-u;if(h.startsWith("} else if")){c=u+b;const d=h.substring(h.indexOf("if")).trim(),g=this.parseIfStatement(d,e,c);l={type:"IfStatement",test:g.test,consequent:g.consequent,alternate:g.alternate},c=g.endPos}else if(h.startsWith("} else")){c=u+b;const{body:d,endPos:g}=this.parseTemplateBlock(e,c);l={type:"BlockStatement",body:d},c=g;const x=e.indexOf("<%",c),$=e.indexOf("%>",x);x===c&&e.slice(x+2,$).trim()==="}"&&(c=$+2)}else h==="}"&&(c=u+b)}}return{type:"IfStatement",test:a,consequent:{type:"BlockStatement",body:o},alternate:l,endPos:c}}parseForStatement(t,e,r){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const a=n[1].split("of");if(a.length!==2)throw new Error("Only for...of loops are supported");const o=a[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),i=a[1].trim(),{body:l,endPos:c}=this.parseTemplateBlock(e,r);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:this.parseJsExpression(i)}]},test:null,update:null,body:{type:"BlockStatement",body:l},endPos:(()=>{const u=e.indexOf("<%",c),p=e.indexOf("%>",u);return u===c&&e.slice(u+2,p).trim()==="}"?p+2:c})()}}parseForEachStatement(t,e,r,n){const{body:a,endPos:o}=this.parseTemplateBlock(r,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:a},endPos:(()=>{const i=r.indexOf("<%",o),l=r.indexOf("%>",i);return i===o&&r.slice(i+2,l).trim()==="}"?l+2:o})()}}parseTemplateBlock(t,e){const r=[];let n=e;for(;n<t.length;){const a=t.indexOf("<%",n);if(a===-1){n<t.length&&r.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}a>n&&r.push(this.createAppendLiteral(t.slice(n,a)));const o=t.indexOf("%>",a);if(o===-1)throw new Error("Unclosed EJS tag within block");const i=t.slice(a+2,o).trim();if(i==="}"||i.startsWith("} else")){n=a;break}if(n=o+2,i.startsWith("=")||i.startsWith("-")){const l=i.slice(1).trim();r.push(this.createAppendExpression(l))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const l=this.parseIfStatement(i,t,n);r.push(l),n=l.endPos||n}else if(i.startsWith("for")){const l=this.parseForStatement(i,t,n);r.push(l),n=l.endPos||n}else{const l=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(l){const c=l[1],u=l[2],p=this.parseForEachStatement(c,u,t,n);r.push(p),n=p.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${i}`)}}}return{body:r,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of J){const a=t.lastIndexOf(n);if(a>0&&t[a-1]!=="!"&&t[a-1]!=="="&&t[a-1]!=="<"&&t[a-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:W[n],left:this.parseJsExpression(t.slice(0,a).trim()),right:this.parseJsExpression(t.slice(a+n.length).trim())}}const e=t.indexOf("."),r=t.indexOf("[");if(e>0&&(r===-1||e<r)||r>0&&(e===-1||r<e)){const n=e>0&&(r===-1||e<r)?e:r;let a,o,i=!1;if(n===e)a=t.slice(0,e),o={type:"Identifier",name:t.slice(e+1)},i=!1;else{a=t.slice(0,r);const l=t.indexOf("]",r);if(l===-1)throw new Error("Unclosed bracket in expression");const c=t.slice(r+1,l);o=/^(['"]).*\1$/.test(c)||/^-?\d+(\.\d+)?$/.test(c)?this.parseJsExpression(c):{type:"Identifier",name:c},i=!0}return{type:"MemberExpression",object:this.parseJsExpression(a),property:o,computed:i}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),r=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
|
|
5
5
|
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:e})}'>
|
|
6
6
|
<data-condition-true-content>${r}</data-condition-true-content>
|
|
7
7
|
<data-condition-false-content>${n}</data-condition-false-content>
|
|
@@ -18,4 +18,4 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
18
18
|
${a}
|
|
19
19
|
</data-collection-item>
|
|
20
20
|
</data-collection>
|
|
21
|
-
`}handleBlockStatement(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];t.name===r&&(e={collectionId:r,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const a=this.collectionStack[this.collectionStack.length-1];let o=t;const i=[];for(;o.type==="MemberExpression";)o.property.type==="Identifier"&&!o.computed?i.unshift(o.property.name):o.property.type==="Literal"&&o.computed?i.unshift(String(o.property.value)):i.unshift(this.getExpressionString(o.property)),o=o.object;if(o.type==="Identifier"&&o.name===a){const l=i.join(".");n={...e,collectionId:a,variableType:"currentItem",path:l}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const r=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${r}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),r="isTruthy";return e.startsWith("!!")?(r="isTruthy",e=e.slice(2)):e.startsWith("!")&&(r="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:r}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),r=this.getConditionExpression(t.right);return`${e} ${t.operator} ${r}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),r=this.getExpressionString(t.property);return t.computed?`${e}[${r}]`:`${e}.${r}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const
|
|
21
|
+
`}handleBlockStatement(t){let e="";for(const r of t.body)e+=this.astToGrapesJS(r);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];t.name===r&&(e={collectionId:r,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const a=this.collectionStack[this.collectionStack.length-1];let o=t;const i=[];for(;o.type==="MemberExpression";)o.property.type==="Identifier"&&!o.computed?i.unshift(o.property.name):o.property.type==="Literal"&&o.computed?i.unshift(String(o.property.value)):i.unshift(this.getExpressionString(o.property)),o=o.object;if(o.type==="Identifier"&&o.name===a){const l=i.join(".");n={...e,collectionId:a,variableType:"currentItem",path:l}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const r=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${r}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),r="isTruthy";return e.startsWith("!!")?(r="isTruthy",e=e.slice(2)):e.startsWith("!")&&(r="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:r}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),r=this.getConditionExpression(t.right);return`${e} ${t.operator} ${r}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),r=this.getExpressionString(t.property);return t.computed?`${e}[${r}]`:`${e}.${r}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),r=this.getExpressionString(t.right);return`${e} ${t.operator} ${r}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const U="dataSourceEjs",V=E.startup;return A(function(s,t={}){const e=D(s,new F),r=G(s,{contains:"<%",importer:new R});N({editor:s,licenseKey:t.licenseKey,plan:V,pluginName:U,cleanup:()=>{e(),r()}})})});
|