@grapesjs/studio-sdk-plugins 1.0.38-rc.0 → 1.0.39-rc.0
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 +5 -5
- package/dist/accordionComponent/index.es.js +70 -67
- package/dist/accordionComponent/index.js +39 -0
- package/dist/accordionComponent/index.umd.js +4 -4
- package/dist/aiChat/components/AiChatHeader.d.ts +4 -5
- package/dist/aiChat/components/AiChatInput/index.d.ts +4 -5
- package/dist/aiChat/components/AiChatMessage.d.ts +7 -8
- package/dist/aiChat/components/index.d.ts +1 -1
- package/dist/aiChat/components/utils.d.ts +1 -1
- package/dist/aiChat/index.cjs.js +10 -376
- package/dist/aiChat/index.es.js +4569 -28851
- package/dist/aiChat/index.js +10 -376
- package/dist/aiChat/index.umd.js +11 -377
- package/dist/aiChat/server/index.cjs.d.ts +0 -1
- package/dist/aiChat/server/index.cjs.js +45 -45
- package/dist/aiChat/server/index.d.ts +0 -1
- package/dist/aiChat/server/index.es.d.ts +0 -1
- package/dist/aiChat/server/index.es.js +371 -427
- package/dist/aiChat/server/index.js +45 -45
- package/dist/aiChat/server/index.umd.js +41 -41
- package/dist/aiChat/server/stream.test.d.ts +1 -0
- package/dist/aiChat/types.d.ts +18 -4
- package/dist/aiChat/typesSchema.d.ts +13 -0
- package/dist/animationComponent/index.cjs.js +3 -3
- package/dist/animationComponent/index.es.js +49 -46
- package/dist/animationComponent/index.js +519 -0
- package/dist/animationComponent/index.umd.js +3 -3
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
- package/dist/canvasAbsoluteMode/index.es.js +115 -112
- package/dist/canvasAbsoluteMode/index.js +1 -0
- package/dist/canvasAbsoluteMode/index.umd.js +1 -1
- package/dist/canvasEmptyState/index.cjs.js +1 -1
- package/dist/canvasEmptyState/index.es.js +71 -68
- package/dist/canvasEmptyState/index.js +1 -0
- package/dist/canvasEmptyState/index.umd.js +1 -1
- package/dist/canvasFullSize/index.cjs.js +3 -3
- package/dist/canvasFullSize/index.es.js +69 -66
- package/dist/canvasFullSize/index.js +10 -0
- package/dist/canvasFullSize/index.umd.js +4 -4
- package/dist/canvasGridMode/index.cjs.js +7 -7
- package/dist/canvasGridMode/index.es.js +142 -139
- package/dist/canvasGridMode/index.js +26 -0
- package/dist/canvasGridMode/index.umd.js +7 -7
- package/dist/canvasScreenshot/index.cjs.js +1 -1
- package/dist/canvasScreenshot/index.es.js +78 -75
- package/dist/canvasScreenshot/index.js +1 -0
- package/dist/canvasScreenshot/index.umd.js +1 -1
- package/dist/dataSourceEjs/EjsExporter.d.ts +1 -1
- package/dist/dataSourceEjs/index.cjs.js +3 -3
- package/dist/dataSourceEjs/index.es.js +40 -37
- package/dist/dataSourceEjs/index.js +21 -0
- package/dist/dataSourceEjs/index.umd.js +3 -3
- package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
- package/dist/dataSourceHandlebars/constants.d.ts +1 -1
- package/dist/dataSourceHandlebars/index.cjs.js +4 -4
- package/dist/dataSourceHandlebars/index.es.js +58 -55
- package/dist/dataSourceHandlebars/index.js +10 -0
- package/dist/dataSourceHandlebars/index.umd.js +2 -2
- package/dist/dialogComponent/index.cjs.js +11 -11
- package/dist/dialogComponent/index.es.js +72 -69
- package/dist/dialogComponent/index.js +59 -0
- package/dist/dialogComponent/index.umd.js +11 -11
- package/dist/flexComponent/index.cjs.js +6 -6
- package/dist/flexComponent/index.es.js +151 -142
- package/dist/flexComponent/index.js +33 -0
- package/dist/flexComponent/index.umd.js +8 -8
- package/dist/flexComponent/typesSchema.d.ts +1 -1
- package/dist/fsLightboxComponent/index.cjs.js +3 -3
- package/dist/fsLightboxComponent/index.es.js +93 -90
- package/dist/fsLightboxComponent/index.js +6 -0
- package/dist/fsLightboxComponent/index.umd.js +3 -3
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +112 -109
- package/dist/googleFontsAssetProvider/index.js +1 -0
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/googleFontsAssetProvider/utils.d.ts +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +80 -77
- package/dist/iconifyComponent/index.js +3 -0
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +970 -82
- package/dist/index.d.ts +1 -0
- package/dist/index.es.d.ts +1 -0
- package/dist/index.es.js +7422 -6145
- package/dist/index.umd.js +975 -87
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +95 -92
- package/dist/layoutSidebarButtons/index.js +1 -0
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/lightGalleryComponent/index.cjs.js +1 -1
- package/dist/lightGalleryComponent/index.es.js +164 -161
- package/dist/lightGalleryComponent/index.js +1 -0
- package/dist/lightGalleryComponent/index.umd.js +1 -1
- package/dist/lightGalleryComponent/utils.d.ts +1 -1
- package/dist/linkImageComponent/index.cjs.js +2 -2
- package/dist/linkImageComponent/index.es.js +60 -57
- package/dist/linkImageComponent/index.js +12 -0
- package/dist/linkImageComponent/index.umd.js +2 -2
- package/dist/listPagesComponent/index.cjs.js +4 -4
- package/dist/listPagesComponent/index.es.js +57 -54
- package/dist/listPagesComponent/index.js +11 -0
- package/dist/listPagesComponent/index.umd.js +4 -4
- package/dist/listPagesComponent/utils.d.ts +1 -1
- package/dist/presetBlockLibrary/blocks.d.ts +6 -0
- package/dist/presetBlockLibrary/blocks.test.d.ts +2 -0
- package/dist/presetBlockLibrary/emailBlocks.d.ts +53 -0
- package/dist/presetBlockLibrary/index.cjs.d.ts +3 -0
- package/dist/presetBlockLibrary/index.cjs.js +889 -0
- package/dist/presetBlockLibrary/index.d.ts +3 -0
- package/dist/presetBlockLibrary/index.es.d.ts +3 -0
- package/dist/presetBlockLibrary/index.es.js +1408 -0
- package/dist/presetBlockLibrary/index.js +889 -0
- package/dist/presetBlockLibrary/index.test.d.ts +1 -0
- package/dist/presetBlockLibrary/index.umd.js +889 -0
- package/dist/presetBlockLibrary/shared.d.ts +3 -0
- package/dist/presetBlockLibrary/types.d.ts +24 -0
- package/dist/presetBlockLibrary/typesSchema.d.ts +47 -0
- package/dist/presetPrintable/index.cjs.js +3 -3
- package/dist/presetPrintable/index.es.js +133 -130
- package/dist/presetPrintable/index.js +32 -0
- package/dist/presetPrintable/index.umd.js +4 -4
- package/dist/prosemirror/index.cjs.js +8 -8
- package/dist/prosemirror/index.es.js +552 -549
- package/dist/prosemirror/index.js +10 -0
- package/dist/prosemirror/index.umd.js +9 -9
- package/dist/prosemirror/toolbar.d.ts +2 -2
- package/dist/prosemirror/types.d.ts +5 -5
- package/dist/rendererReact/index.cjs.js +1 -1
- package/dist/rendererReact/index.es.js +137 -134
- 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 -71
- package/dist/rteTinyMce/index.js +104 -0
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/shapeDividerComponent/index.cjs.js +4 -4
- package/dist/shapeDividerComponent/index.es.js +91 -88
- package/dist/shapeDividerComponent/index.js +97 -0
- package/dist/shapeDividerComponent/index.umd.js +4 -4
- package/dist/swiperComponent/index.cjs.js +7 -7
- package/dist/swiperComponent/index.es.js +95 -92
- package/dist/swiperComponent/index.js +45 -0
- package/dist/swiperComponent/index.umd.js +5 -5
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +181 -178
- package/dist/tableComponent/index.js +1 -0
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/tableComponent/types.d.ts +3 -3
- package/dist/types.d.ts +14 -14
- package/dist/utils.d.ts +3 -2
- package/dist/utilsDataSources.d.ts +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +90 -87
- package/dist/youtubeAssetProvider/index.js +1 -0
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +182 -34
- package/dist/aiChat/server/models.d.ts +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@studio/
|
|
1
|
+
import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@grapesjs/studio-sdk/dist/typeConfigs/dataSources';
|
|
2
2
|
import { DataConditionProps } from 'grapesjs';
|
|
3
3
|
export declare class EjsExporter implements IDataSourceExporter {
|
|
4
4
|
getVariableSyntax({ dataResolver }: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const I="app.grapesjs.com",P="app-stage.grapesjs.com",w="app2.grapesjs.com",O="app-stage2.grapesjs.com",$=[I,w,P,O,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],T="license:check:end",L=()=>typeof window<"u",k=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?P:I}`}/${e?"platform-api":"api"}`,B=()=>{if(!L())return"";const{hostname:s}=window.location;if(s)return s;try{return window.parent.location.hostname||""}catch{return""}},A=()=>{const s=B();return!!s&&($.includes(s)||$.some(t=>s.endsWith(t)))};async function N({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||k({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.openEditCode="studio:openEditCode",s.openBlocks="studio:openBlocks",s.appendComponent="studio:appendComponent",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 M(s,t){const e=s;return e.init=r=>{const n=a=>s(a,r);return n.__gjsPluginId=t,n},e}const j=(s,t)=>M(s,t);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(s,e)},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],v=S[g];x>v&&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 F({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=D(i);u(p);return}s.on(T,p=>u(p))}const D=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function F(s){const{licenseKey:t,pluginName:e,baseApiUrl:r}=s;try{return(await N({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 _=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 R{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(_(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=U[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 U={and:"&&",or:"||",xor:"^"},V=["===","==","!==","!=","<=",">=","<",">","&&","||"],q={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class H{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 V){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:q[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 m="dataSourceEjs",C=y.startup,K=function(s,t={}){const e=J(s,new R),r=W(s,{contains:"<%",importer:new H});G({editor:s,licenseKey:t.licenseKey,plan:C,pluginName:m,cleanup:()=>{e(),r()}})},z=j(K,m);module.exports=z;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
m,
|
|
3
|
-
v,
|
|
1
|
+
const I = "app.grapesjs.com", P = "app-stage.grapesjs.com", w = "app2.grapesjs.com", O = "app-stage2.grapesjs.com", $ = [
|
|
4
2
|
I,
|
|
5
3
|
w,
|
|
4
|
+
P,
|
|
5
|
+
O,
|
|
6
6
|
"localhost",
|
|
7
7
|
"127.0.0.1",
|
|
8
8
|
".local-credentialless.webcontainer.io",
|
|
@@ -15,12 +15,12 @@ const m = "app.grapesjs.com", I = "app-stage.grapesjs.com", v = "app2.grapesjs.c
|
|
|
15
15
|
// For Claude mcp app
|
|
16
16
|
".web-sandbox.oaiusercontent.com"
|
|
17
17
|
// For OpenAI mcp app
|
|
18
|
-
],
|
|
18
|
+
], T = "license:check:end", L = () => typeof window < "u", k = ({
|
|
19
19
|
isDev: s,
|
|
20
20
|
isStage: t,
|
|
21
21
|
isPlatform: e
|
|
22
|
-
}) => `${s ? "" : `https://${t ?
|
|
23
|
-
if (!
|
|
22
|
+
}) => `${s ? "" : `https://${t ? P : I}`}/${e ? "platform-api" : "api"}`, B = () => {
|
|
23
|
+
if (!L()) return "";
|
|
24
24
|
const { hostname: s } = window.location;
|
|
25
25
|
if (s) return s;
|
|
26
26
|
try {
|
|
@@ -29,10 +29,10 @@ const m = "app.grapesjs.com", I = "app-stage.grapesjs.com", v = "app2.grapesjs.c
|
|
|
29
29
|
return "";
|
|
30
30
|
}
|
|
31
31
|
}, A = () => {
|
|
32
|
-
const s =
|
|
32
|
+
const s = B();
|
|
33
33
|
return !!s && ($.includes(s) || $.some((t) => s.endsWith(t)));
|
|
34
34
|
};
|
|
35
|
-
async function
|
|
35
|
+
async function N({
|
|
36
36
|
path: s,
|
|
37
37
|
baseApiUrl: t,
|
|
38
38
|
method: e = "GET",
|
|
@@ -40,7 +40,7 @@ async function B({
|
|
|
40
40
|
params: n,
|
|
41
41
|
body: a
|
|
42
42
|
}) {
|
|
43
|
-
const i = `${t ||
|
|
43
|
+
const i = `${t || k({ isDev: !1, isStage: !1 })}${s}`, l = {
|
|
44
44
|
method: e,
|
|
45
45
|
headers: {
|
|
46
46
|
"Content-Type": "application/json",
|
|
@@ -53,18 +53,21 @@ async function B({
|
|
|
53
53
|
throw new Error(`HTTP error! status: ${p.status}`);
|
|
54
54
|
return p.json();
|
|
55
55
|
}
|
|
56
|
-
var y = /* @__PURE__ */ ((s) => (s.free = "free", s.startup = "startup", s.business = "business", s.enterprise = "enterprise", s))(y || {}), b = /* @__PURE__ */ ((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.openEditCode = "studio:openEditCode", 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 || {});
|
|
56
|
+
var y = /* @__PURE__ */ ((s) => (s.free = "free", s.startup = "startup", s.business = "business", s.enterprise = "enterprise", s))(y || {}), b = /* @__PURE__ */ ((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.openEditCode = "studio:openEditCode", s.openBlocks = "studio:openBlocks", s.appendComponent = "studio:appendComponent", 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 || {});
|
|
57
57
|
const S = {
|
|
58
58
|
[y.free]: 0,
|
|
59
59
|
[y.startup]: 10,
|
|
60
60
|
[y.business]: 20,
|
|
61
61
|
[y.enterprise]: 30
|
|
62
62
|
};
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
return
|
|
63
|
+
function M(s, t) {
|
|
64
|
+
const e = s;
|
|
65
|
+
return e.init = (r) => {
|
|
66
|
+
const n = (a) => s(a, r);
|
|
67
|
+
return n.__gjsPluginId = t, n;
|
|
68
|
+
}, e;
|
|
66
69
|
}
|
|
67
|
-
const
|
|
70
|
+
const j = (s, t) => /* @__PURE__ */ M(s, t);
|
|
68
71
|
async function G({
|
|
69
72
|
editor: s,
|
|
70
73
|
plan: t,
|
|
@@ -75,15 +78,15 @@ async function G({
|
|
|
75
78
|
}) {
|
|
76
79
|
let o = "", i;
|
|
77
80
|
const l = (p) => {
|
|
78
|
-
console.warn("Cleanup plugin:", e, "Reason:", p), a();
|
|
81
|
+
console.warn("Cleanup plugin:", e, "Reason:", p), a(s, e);
|
|
79
82
|
}, c = (p = {}) => {
|
|
80
83
|
var f;
|
|
81
84
|
const { error: h, sdkLicense: E } = p, g = (f = p.plan) == null ? void 0 : f.category;
|
|
82
85
|
if (!(E || p.license) || h)
|
|
83
86
|
l(h || "Invalid license");
|
|
84
87
|
else if (g) {
|
|
85
|
-
const x = S[t],
|
|
86
|
-
x >
|
|
88
|
+
const x = S[t], v = S[g];
|
|
89
|
+
x > v && l({ pluginRequiredPlan: t, licensePlan: g });
|
|
87
90
|
}
|
|
88
91
|
};
|
|
89
92
|
s.Commands.has(b.settings) && (i = s.runCommand(b.settings), o = (i == null ? void 0 : i.baseUrl) || "");
|
|
@@ -94,7 +97,7 @@ async function G({
|
|
|
94
97
|
s.onReady(async () => {
|
|
95
98
|
if (!A())
|
|
96
99
|
if (r) {
|
|
97
|
-
const p = await
|
|
100
|
+
const p = await F({ licenseKey: r, pluginName: e, baseApiUrl: o });
|
|
98
101
|
u(p);
|
|
99
102
|
} else
|
|
100
103
|
l("The `licenseKey` option not provided");
|
|
@@ -102,22 +105,22 @@ async function G({
|
|
|
102
105
|
return;
|
|
103
106
|
}
|
|
104
107
|
if (i.licensePlan || i.licenseError) {
|
|
105
|
-
const p =
|
|
108
|
+
const p = D(i);
|
|
106
109
|
u(p);
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
|
-
s.on(
|
|
112
|
+
s.on(T, (p) => u(p));
|
|
110
113
|
}
|
|
111
|
-
const
|
|
114
|
+
const D = (s) => ({
|
|
112
115
|
sdkLicense: s.license,
|
|
113
116
|
license: s.license,
|
|
114
117
|
error: s.licenseError,
|
|
115
118
|
plan: s.licensePlan
|
|
116
119
|
});
|
|
117
|
-
async function
|
|
120
|
+
async function F(s) {
|
|
118
121
|
const { licenseKey: t, pluginName: e, baseApiUrl: r } = s;
|
|
119
122
|
try {
|
|
120
|
-
return (await
|
|
123
|
+
return (await N({
|
|
121
124
|
baseApiUrl: r,
|
|
122
125
|
path: `/sdk/${t || "na"}`,
|
|
123
126
|
method: "POST",
|
|
@@ -130,7 +133,7 @@ async function D(s) {
|
|
|
130
133
|
return console.error("Error during SDK license check:", n), !1;
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
|
-
const
|
|
136
|
+
const _ = (s) => {
|
|
134
137
|
const t = s;
|
|
135
138
|
return t.logicalOperator === "and" || t.logicalOperator === "or";
|
|
136
139
|
}, J = (s, t) => (s.config.optsHtml = {
|
|
@@ -147,7 +150,7 @@ const F = (s) => {
|
|
|
147
150
|
s.off(r, e);
|
|
148
151
|
};
|
|
149
152
|
};
|
|
150
|
-
class
|
|
153
|
+
class R {
|
|
151
154
|
getVariableSyntax({ dataResolver: t }) {
|
|
152
155
|
const { defaultValue: e } = t, r = this.getFullPath(t), n = e ? ` || \`${e}\`` : "";
|
|
153
156
|
return `<%= ${r}${n} %>`;
|
|
@@ -184,8 +187,8 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
184
187
|
}
|
|
185
188
|
_parseCondition(t) {
|
|
186
189
|
if (!t) return "";
|
|
187
|
-
if (
|
|
188
|
-
const e = t.statements.map((a) => this._parseCondition(a)), r =
|
|
190
|
+
if (_(t)) {
|
|
191
|
+
const e = t.statements.map((a) => this._parseCondition(a)), r = U[t.logicalOperator];
|
|
189
192
|
let n = e.length > 1 ? `(${e.join(`)${r}(`)})` : e[0];
|
|
190
193
|
return t.logicalOperator === "xor" && (n = `!!(${n})`), n;
|
|
191
194
|
} else {
|
|
@@ -239,11 +242,11 @@ const ${i}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
|
|
|
239
242
|
return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
|
-
const
|
|
245
|
+
const U = {
|
|
243
246
|
and: "&&",
|
|
244
247
|
or: "||",
|
|
245
248
|
xor: "^"
|
|
246
|
-
},
|
|
249
|
+
}, V = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], q = {
|
|
247
250
|
"===": "=",
|
|
248
251
|
"==": "=",
|
|
249
252
|
"!==": "!=",
|
|
@@ -255,7 +258,7 @@ const R = {
|
|
|
255
258
|
"&&": "&&",
|
|
256
259
|
"||": "||"
|
|
257
260
|
};
|
|
258
|
-
class
|
|
261
|
+
class H {
|
|
259
262
|
constructor() {
|
|
260
263
|
this.messages = [], this.collectionStack = [];
|
|
261
264
|
}
|
|
@@ -485,12 +488,12 @@ class q {
|
|
|
485
488
|
type: "Literal",
|
|
486
489
|
value: t === "true"
|
|
487
490
|
};
|
|
488
|
-
for (const n of
|
|
491
|
+
for (const n of V) {
|
|
489
492
|
const a = t.lastIndexOf(n);
|
|
490
493
|
if (a > 0 && t[a - 1] !== "!" && t[a - 1] !== "=" && t[a - 1] !== "<" && t[a - 1] !== ">")
|
|
491
494
|
return {
|
|
492
495
|
type: n === "&&" || n === "||" ? "LogicalExpression" : "BinaryExpression",
|
|
493
|
-
operator:
|
|
496
|
+
operator: q[n],
|
|
494
497
|
left: this.parseJsExpression(t.slice(0, a).trim()),
|
|
495
498
|
right: this.parseJsExpression(t.slice(a + n.length).trim())
|
|
496
499
|
};
|
|
@@ -730,21 +733,21 @@ class q {
|
|
|
730
733
|
});
|
|
731
734
|
}
|
|
732
735
|
}
|
|
733
|
-
const
|
|
734
|
-
const e = J(s, new
|
|
736
|
+
const m = "dataSourceEjs", C = y.startup, K = function(s, t = {}) {
|
|
737
|
+
const e = J(s, new R()), r = W(s, {
|
|
735
738
|
contains: "<%",
|
|
736
|
-
importer: new
|
|
739
|
+
importer: new H()
|
|
737
740
|
});
|
|
738
741
|
G({
|
|
739
742
|
editor: s,
|
|
740
743
|
licenseKey: t.licenseKey,
|
|
741
744
|
plan: C,
|
|
742
|
-
pluginName:
|
|
745
|
+
pluginName: m,
|
|
743
746
|
cleanup: () => {
|
|
744
747
|
e(), r();
|
|
745
748
|
}
|
|
746
749
|
});
|
|
747
|
-
}, z =
|
|
750
|
+
}, z = j(K, m);
|
|
748
751
|
export {
|
|
749
752
|
z as default
|
|
750
753
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";const I="app.grapesjs.com",P="app-stage.grapesjs.com",w="app2.grapesjs.com",O="app-stage2.grapesjs.com",$=[I,w,P,O,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io",".claudemcpcontent.com",".web-sandbox.oaiusercontent.com"],T="license:check:end",L=()=>typeof window<"u",k=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?P:I}`}/${e?"platform-api":"api"}`,B=()=>{if(!L())return"";const{hostname:s}=window.location;if(s)return s;try{return window.parent.location.hostname||""}catch{return""}},A=()=>{const s=B();return!!s&&($.includes(s)||$.some(t=>s.endsWith(t)))};async function N({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||k({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.openEditCode="studio:openEditCode",s.openBlocks="studio:openBlocks",s.appendComponent="studio:appendComponent",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 M(s,t){const e=s;return e.init=r=>{const n=a=>s(a,r);return n.__gjsPluginId=t,n},e}const j=(s,t)=>M(s,t);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(s,e)},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],v=S[g];x>v&&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 F({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=D(i);u(p);return}s.on(T,p=>u(p))}const D=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function F(s){const{licenseKey:t,pluginName:e,baseApiUrl:r}=s;try{return(await N({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 _=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 R{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
|
+
const startIndex = parseInt(${n??0}, 10);
|
|
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(_(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=U[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 U={and:"&&",or:"||",xor:"^"},V=["===","==","!==","!=","<=",">=","<",">","&&","||"],q={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class H{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 V){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:q[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
|
+
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:e})}'>
|
|
6
|
+
<data-condition-true-content>${r}</data-condition-true-content>
|
|
7
|
+
<data-condition-false-content>${n}</data-condition-false-content>
|
|
8
|
+
</data-condition>
|
|
9
|
+
`}handleForStatement(t){var i;if(((i=t.init)==null?void 0:i.type)!=="VariableDeclaration"||t.init.declarations.length===0)return this.addMessage("warning","Unsupported for loop init format"),"";const e=t.init.declarations[0];if(e.id.type!=="Identifier")return this.addMessage("warning","Unsupported for loop variable declaration id"),"";let r="";if(e.init)r=this.getExpressionString(e.init);else return this.addMessage("warning","For loop collection is undefined"),"";const n=e.id.name,a=n;this.collectionStack.push(n);const o=this.astToGrapesJS(t.body);return this.collectionStack.pop(),`
|
|
10
|
+
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:r},collectionId:a})}'>
|
|
11
|
+
<data-collection-item>
|
|
12
|
+
${o}
|
|
13
|
+
</data-collection-item>
|
|
14
|
+
</data-collection>
|
|
15
|
+
`}handleForEachStatement(t){const e=this.getExpressionString(t.collection),r=t.itemIdentifier.name,n=r;this.collectionStack.push(r);const a=this.astToGrapesJS(t.body);return this.collectionStack.pop(),`
|
|
16
|
+
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
|
|
17
|
+
<data-collection-item>
|
|
18
|
+
${a}
|
|
19
|
+
</data-collection-item>
|
|
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 m="dataSourceEjs",C=y.startup,K=function(s,t={}){const e=J(s,new R),r=W(s,{contains:"<%",importer:new H});G({editor:s,licenseKey:t.licenseKey,plan:C,pluginName:m,cleanup:()=>{e(),r()}})},z=j(K,m);module.exports=z;
|
|
@@ -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",I=[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"],v="license:check:end",O=()=>typeof window<"u",w=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?y:f}`}/${e?"platform-api":"api"}`,T=()=>{if(!O())return"";const{hostname:s}=window.location;if(s)return s;try{return window.parent.location.hostname||""}catch{return""}},k=()=>{const s=T();return!!s&&(I.includes(s)||I.some(t=>s.endsWith(t)))};async function L({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||w({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.openEditCode="studio:openEditCode",s.openBlocks="studio:openBlocks",s.appendComponent="studio:appendComponent",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 m={[E.free]:0,[E.startup]:10,[E.business]:20,[E.enterprise]:30};function A(s,t){const e=s;return e.init=r=>{const n=a=>s(a,r);return n.__gjsPluginId=t,n},e}const B=(s,t)=>A(s,t);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(s,e)},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 $=m[t],q=m[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(!k())if(r){const p=await j({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=M(i);u(p);return}s.on(v,p=>u(p))}const M=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function j(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 D=s=>{const t=s;return t.logicalOperator==="and"||t.logicalOperator==="or"},G=(s,t)=>(s.config.optsHtml={...s.config.optsHtml,exporter:t},()=>{s.config.optsHtml.exporter=void 0}),_=(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(D(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=J[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 J={and:"&&",or:"||",xor:"^"},W=["===","==","!==","!=","<=",">=","<",">","&&","||"],R={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class U{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 W){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:R[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 P="dataSourceEjs",V=E.startup;return B(function(s,t={}){const e=G(s,new F),r=_(s,{contains:"<%",importer:new U});N({editor:s,licenseKey:t.licenseKey,plan:V,pluginName:P,cleanup:()=>{e(),r()}})},P)});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Operator } from '@studio/
|
|
2
|
-
import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@studio/
|
|
1
|
+
import { Operator } from '@grapesjs/studio-sdk/dist/components/DataConditionPicker/statementTypes';
|
|
2
|
+
import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@grapesjs/studio-sdk/dist/typeConfigs/dataSources';
|
|
3
3
|
import { DataConditionProps } from 'grapesjs';
|
|
4
4
|
export declare class HandlebarsExporter implements IDataSourceExporter {
|
|
5
5
|
getHelperId(operator: Operator): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Operator } from '@studio/
|
|
1
|
+
import { Operator } from '@grapesjs/studio-sdk/dist/components/DataConditionPicker/statementTypes';
|
|
2
2
|
export declare const ANYTYPE_OPERATION: {
|
|
3
3
|
equals: string;
|
|
4
4
|
isTruthy: string;
|