@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.
Files changed (158) hide show
  1. package/dist/accordionComponent/index.cjs.js +5 -5
  2. package/dist/accordionComponent/index.es.js +70 -67
  3. package/dist/accordionComponent/index.js +39 -0
  4. package/dist/accordionComponent/index.umd.js +4 -4
  5. package/dist/aiChat/components/AiChatHeader.d.ts +4 -5
  6. package/dist/aiChat/components/AiChatInput/index.d.ts +4 -5
  7. package/dist/aiChat/components/AiChatMessage.d.ts +7 -8
  8. package/dist/aiChat/components/index.d.ts +1 -1
  9. package/dist/aiChat/components/utils.d.ts +1 -1
  10. package/dist/aiChat/index.cjs.js +10 -376
  11. package/dist/aiChat/index.es.js +4569 -28851
  12. package/dist/aiChat/index.js +10 -376
  13. package/dist/aiChat/index.umd.js +11 -377
  14. package/dist/aiChat/server/index.cjs.d.ts +0 -1
  15. package/dist/aiChat/server/index.cjs.js +45 -45
  16. package/dist/aiChat/server/index.d.ts +0 -1
  17. package/dist/aiChat/server/index.es.d.ts +0 -1
  18. package/dist/aiChat/server/index.es.js +371 -427
  19. package/dist/aiChat/server/index.js +45 -45
  20. package/dist/aiChat/server/index.umd.js +41 -41
  21. package/dist/aiChat/server/stream.test.d.ts +1 -0
  22. package/dist/aiChat/types.d.ts +18 -4
  23. package/dist/aiChat/typesSchema.d.ts +13 -0
  24. package/dist/animationComponent/index.cjs.js +3 -3
  25. package/dist/animationComponent/index.es.js +49 -46
  26. package/dist/animationComponent/index.js +519 -0
  27. package/dist/animationComponent/index.umd.js +3 -3
  28. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  29. package/dist/canvasAbsoluteMode/index.es.js +115 -112
  30. package/dist/canvasAbsoluteMode/index.js +1 -0
  31. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  32. package/dist/canvasEmptyState/index.cjs.js +1 -1
  33. package/dist/canvasEmptyState/index.es.js +71 -68
  34. package/dist/canvasEmptyState/index.js +1 -0
  35. package/dist/canvasEmptyState/index.umd.js +1 -1
  36. package/dist/canvasFullSize/index.cjs.js +3 -3
  37. package/dist/canvasFullSize/index.es.js +69 -66
  38. package/dist/canvasFullSize/index.js +10 -0
  39. package/dist/canvasFullSize/index.umd.js +4 -4
  40. package/dist/canvasGridMode/index.cjs.js +7 -7
  41. package/dist/canvasGridMode/index.es.js +142 -139
  42. package/dist/canvasGridMode/index.js +26 -0
  43. package/dist/canvasGridMode/index.umd.js +7 -7
  44. package/dist/canvasScreenshot/index.cjs.js +1 -1
  45. package/dist/canvasScreenshot/index.es.js +78 -75
  46. package/dist/canvasScreenshot/index.js +1 -0
  47. package/dist/canvasScreenshot/index.umd.js +1 -1
  48. package/dist/dataSourceEjs/EjsExporter.d.ts +1 -1
  49. package/dist/dataSourceEjs/index.cjs.js +3 -3
  50. package/dist/dataSourceEjs/index.es.js +40 -37
  51. package/dist/dataSourceEjs/index.js +21 -0
  52. package/dist/dataSourceEjs/index.umd.js +3 -3
  53. package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
  54. package/dist/dataSourceHandlebars/constants.d.ts +1 -1
  55. package/dist/dataSourceHandlebars/index.cjs.js +4 -4
  56. package/dist/dataSourceHandlebars/index.es.js +58 -55
  57. package/dist/dataSourceHandlebars/index.js +10 -0
  58. package/dist/dataSourceHandlebars/index.umd.js +2 -2
  59. package/dist/dialogComponent/index.cjs.js +11 -11
  60. package/dist/dialogComponent/index.es.js +72 -69
  61. package/dist/dialogComponent/index.js +59 -0
  62. package/dist/dialogComponent/index.umd.js +11 -11
  63. package/dist/flexComponent/index.cjs.js +6 -6
  64. package/dist/flexComponent/index.es.js +151 -142
  65. package/dist/flexComponent/index.js +33 -0
  66. package/dist/flexComponent/index.umd.js +8 -8
  67. package/dist/flexComponent/typesSchema.d.ts +1 -1
  68. package/dist/fsLightboxComponent/index.cjs.js +3 -3
  69. package/dist/fsLightboxComponent/index.es.js +93 -90
  70. package/dist/fsLightboxComponent/index.js +6 -0
  71. package/dist/fsLightboxComponent/index.umd.js +3 -3
  72. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  73. package/dist/googleFontsAssetProvider/index.es.js +112 -109
  74. package/dist/googleFontsAssetProvider/index.js +1 -0
  75. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  76. package/dist/googleFontsAssetProvider/utils.d.ts +1 -1
  77. package/dist/iconifyComponent/index.cjs.js +2 -2
  78. package/dist/iconifyComponent/index.es.js +80 -77
  79. package/dist/iconifyComponent/index.js +3 -0
  80. package/dist/iconifyComponent/index.umd.js +2 -2
  81. package/dist/index.cjs.d.ts +1 -0
  82. package/dist/index.cjs.js +970 -82
  83. package/dist/index.d.ts +1 -0
  84. package/dist/index.es.d.ts +1 -0
  85. package/dist/index.es.js +7422 -6145
  86. package/dist/index.umd.js +975 -87
  87. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  88. package/dist/layoutSidebarButtons/index.es.js +95 -92
  89. package/dist/layoutSidebarButtons/index.js +1 -0
  90. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  91. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  92. package/dist/lightGalleryComponent/index.es.js +164 -161
  93. package/dist/lightGalleryComponent/index.js +1 -0
  94. package/dist/lightGalleryComponent/index.umd.js +1 -1
  95. package/dist/lightGalleryComponent/utils.d.ts +1 -1
  96. package/dist/linkImageComponent/index.cjs.js +2 -2
  97. package/dist/linkImageComponent/index.es.js +60 -57
  98. package/dist/linkImageComponent/index.js +12 -0
  99. package/dist/linkImageComponent/index.umd.js +2 -2
  100. package/dist/listPagesComponent/index.cjs.js +4 -4
  101. package/dist/listPagesComponent/index.es.js +57 -54
  102. package/dist/listPagesComponent/index.js +11 -0
  103. package/dist/listPagesComponent/index.umd.js +4 -4
  104. package/dist/listPagesComponent/utils.d.ts +1 -1
  105. package/dist/presetBlockLibrary/blocks.d.ts +6 -0
  106. package/dist/presetBlockLibrary/blocks.test.d.ts +2 -0
  107. package/dist/presetBlockLibrary/emailBlocks.d.ts +53 -0
  108. package/dist/presetBlockLibrary/index.cjs.d.ts +3 -0
  109. package/dist/presetBlockLibrary/index.cjs.js +889 -0
  110. package/dist/presetBlockLibrary/index.d.ts +3 -0
  111. package/dist/presetBlockLibrary/index.es.d.ts +3 -0
  112. package/dist/presetBlockLibrary/index.es.js +1408 -0
  113. package/dist/presetBlockLibrary/index.js +889 -0
  114. package/dist/presetBlockLibrary/index.test.d.ts +1 -0
  115. package/dist/presetBlockLibrary/index.umd.js +889 -0
  116. package/dist/presetBlockLibrary/shared.d.ts +3 -0
  117. package/dist/presetBlockLibrary/types.d.ts +24 -0
  118. package/dist/presetBlockLibrary/typesSchema.d.ts +47 -0
  119. package/dist/presetPrintable/index.cjs.js +3 -3
  120. package/dist/presetPrintable/index.es.js +133 -130
  121. package/dist/presetPrintable/index.js +32 -0
  122. package/dist/presetPrintable/index.umd.js +4 -4
  123. package/dist/prosemirror/index.cjs.js +8 -8
  124. package/dist/prosemirror/index.es.js +552 -549
  125. package/dist/prosemirror/index.js +10 -0
  126. package/dist/prosemirror/index.umd.js +9 -9
  127. package/dist/prosemirror/toolbar.d.ts +2 -2
  128. package/dist/prosemirror/types.d.ts +5 -5
  129. package/dist/rendererReact/index.cjs.js +1 -1
  130. package/dist/rendererReact/index.es.js +137 -134
  131. package/dist/rendererReact/index.js +1 -1
  132. package/dist/rendererReact/index.umd.js +1 -1
  133. package/dist/rteTinyMce/index.cjs.js +2 -2
  134. package/dist/rteTinyMce/index.es.js +74 -71
  135. package/dist/rteTinyMce/index.js +104 -0
  136. package/dist/rteTinyMce/index.umd.js +2 -2
  137. package/dist/shapeDividerComponent/index.cjs.js +4 -4
  138. package/dist/shapeDividerComponent/index.es.js +91 -88
  139. package/dist/shapeDividerComponent/index.js +97 -0
  140. package/dist/shapeDividerComponent/index.umd.js +4 -4
  141. package/dist/swiperComponent/index.cjs.js +7 -7
  142. package/dist/swiperComponent/index.es.js +95 -92
  143. package/dist/swiperComponent/index.js +45 -0
  144. package/dist/swiperComponent/index.umd.js +5 -5
  145. package/dist/tableComponent/index.cjs.js +1 -1
  146. package/dist/tableComponent/index.es.js +181 -178
  147. package/dist/tableComponent/index.js +1 -0
  148. package/dist/tableComponent/index.umd.js +1 -1
  149. package/dist/tableComponent/types.d.ts +3 -3
  150. package/dist/types.d.ts +14 -14
  151. package/dist/utils.d.ts +3 -2
  152. package/dist/utilsDataSources.d.ts +1 -1
  153. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  154. package/dist/youtubeAssetProvider/index.es.js +90 -87
  155. package/dist/youtubeAssetProvider/index.js +1 -0
  156. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  157. package/package.json +182 -34
  158. package/dist/aiChat/server/models.d.ts +0 -15
@@ -1,4 +1,4 @@
1
- import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@studio/editor/src/typeConfigs/dataSources';
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 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.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||{});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) {
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(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)),`
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 H="dataSourceEjs",C=y.startup,K=function(s,t={}){const e=J(s,new _),r=W(s,{contains:"<%",importer:new q});G({editor:s,licenseKey:t.licenseKey,plan:C,pluginName:H,cleanup:()=>{e(),r()}})},z=M(K);module.exports=z;
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 m = "app.grapesjs.com", I = "app-stage.grapesjs.com", v = "app2.grapesjs.com", w = "app-stage2.grapesjs.com", $ = [
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
- ], O = "license:check:end", T = () => typeof window < "u", L = ({
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 ? I : m}`}/${e ? "platform-api" : "api"}`, k = () => {
23
- if (!T()) return "";
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 = k();
32
+ const s = B();
33
33
  return !!s && ($.includes(s) || $.some((t) => s.endsWith(t)));
34
34
  };
35
- async function B({
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 || L({ isDev: !1, isStage: !1 })}${s}`, l = {
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 N(s) {
64
- const t = s;
65
- return t.init = (e) => (r) => s(r, e), t;
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 M = (s) => /* @__PURE__ */ N(s);
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], P = S[g];
86
- x > P && l({ pluginRequiredPlan: t, licensePlan: g });
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 D({ licenseKey: r, pluginName: e, baseApiUrl: o });
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 = j(i);
108
+ const p = D(i);
106
109
  u(p);
107
110
  return;
108
111
  }
109
- s.on(O, (p) => u(p));
112
+ s.on(T, (p) => u(p));
110
113
  }
111
- const j = (s) => ({
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 D(s) {
120
+ async function F(s) {
118
121
  const { licenseKey: t, pluginName: e, baseApiUrl: r } = s;
119
122
  try {
120
- return (await B({
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 F = (s) => {
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 (F(t)) {
188
- const e = t.statements.map((a) => this._parseCondition(a)), r = R[t.logicalOperator];
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 R = {
245
+ const U = {
243
246
  and: "&&",
244
247
  or: "||",
245
248
  xor: "^"
246
- }, U = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], V = {
249
+ }, V = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], q = {
247
250
  "===": "=",
248
251
  "==": "=",
249
252
  "!==": "!=",
@@ -255,7 +258,7 @@ const R = {
255
258
  "&&": "&&",
256
259
  "||": "||"
257
260
  };
258
- class q {
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 U) {
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: V[n],
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 H = "dataSourceEjs", C = y.startup, K = function(s, t = {}) {
734
- const e = J(s, new _()), r = W(s, {
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 q()
739
+ importer: new H()
737
740
  });
738
741
  G({
739
742
  editor: s,
740
743
  licenseKey: t.licenseKey,
741
744
  plan: C,
742
- pluginName: H,
745
+ pluginName: m,
743
746
  cleanup: () => {
744
747
  e(), r();
745
748
  }
746
749
  });
747
- }, z = M(K);
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",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.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))(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) {
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(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)),`
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 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()}})})});
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/editor/src/components/DataConditionPicker/statementTypes';
2
- import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@studio/editor/src/typeConfigs/dataSources';
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/editor/src/components/DataConditionPicker/statementTypes';
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;