@grapesjs/studio-sdk-plugins 1.0.35 → 1.0.36

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 (88) hide show
  1. package/dist/accordionComponent/index.cjs.js +7 -7
  2. package/dist/accordionComponent/index.es.js +175 -162
  3. package/dist/accordionComponent/index.umd.js +7 -7
  4. package/dist/aiChat/index.cjs.js +64 -64
  5. package/dist/aiChat/index.es.js +5785 -5757
  6. package/dist/aiChat/index.js +64 -64
  7. package/dist/aiChat/index.umd.js +63 -63
  8. package/dist/animationComponent/index.cjs.js +3 -3
  9. package/dist/animationComponent/index.es.js +204 -191
  10. package/dist/animationComponent/index.umd.js +3 -3
  11. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  12. package/dist/canvasAbsoluteMode/index.es.js +183 -170
  13. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  14. package/dist/canvasEmptyState/index.cjs.js +1 -1
  15. package/dist/canvasEmptyState/index.es.js +134 -121
  16. package/dist/canvasEmptyState/index.umd.js +1 -1
  17. package/dist/canvasFullSize/index.cjs.js +9 -9
  18. package/dist/canvasFullSize/index.es.js +165 -152
  19. package/dist/canvasFullSize/index.umd.js +9 -9
  20. package/dist/canvasGridMode/index.cjs.js +5 -5
  21. package/dist/canvasGridMode/index.es.js +245 -232
  22. package/dist/canvasGridMode/index.umd.js +4 -4
  23. package/dist/canvasScreenshot/index.cjs.js +1 -1
  24. package/dist/canvasScreenshot/index.es.js +155 -142
  25. package/dist/canvasScreenshot/index.umd.js +1 -1
  26. package/dist/dataSourceEjs/index.cjs.js +9 -9
  27. package/dist/dataSourceEjs/index.es.js +257 -244
  28. package/dist/dataSourceEjs/index.umd.js +9 -9
  29. package/dist/dataSourceHandlebars/index.cjs.js +8 -8
  30. package/dist/dataSourceHandlebars/index.es.js +216 -203
  31. package/dist/dataSourceHandlebars/index.umd.js +7 -7
  32. package/dist/dialogComponent/index.cjs.js +14 -14
  33. package/dist/dialogComponent/index.es.js +141 -128
  34. package/dist/dialogComponent/index.umd.js +14 -14
  35. package/dist/flexComponent/index.cjs.js +13 -13
  36. package/dist/flexComponent/index.es.js +484 -471
  37. package/dist/flexComponent/index.umd.js +13 -13
  38. package/dist/fsLightboxComponent/index.cjs.js +3 -3
  39. package/dist/fsLightboxComponent/index.es.js +173 -160
  40. package/dist/fsLightboxComponent/index.umd.js +3 -3
  41. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  42. package/dist/googleFontsAssetProvider/index.es.js +160 -147
  43. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  44. package/dist/iconifyComponent/index.cjs.js +2 -2
  45. package/dist/iconifyComponent/index.es.js +196 -183
  46. package/dist/iconifyComponent/index.umd.js +2 -2
  47. package/dist/index.cjs.js +25 -25
  48. package/dist/index.es.js +121 -108
  49. package/dist/index.umd.js +18 -18
  50. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  51. package/dist/layoutSidebarButtons/index.es.js +157 -144
  52. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  53. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  54. package/dist/lightGalleryComponent/index.es.js +245 -232
  55. package/dist/lightGalleryComponent/index.umd.js +1 -1
  56. package/dist/linkImageComponent/index.cjs.js +2 -2
  57. package/dist/linkImageComponent/index.es.js +106 -93
  58. package/dist/linkImageComponent/index.umd.js +2 -2
  59. package/dist/listPagesComponent/index.cjs.js +5 -5
  60. package/dist/listPagesComponent/index.es.js +157 -144
  61. package/dist/listPagesComponent/index.umd.js +5 -5
  62. package/dist/presetPrintable/index.cjs.js +3 -3
  63. package/dist/presetPrintable/index.es.js +181 -168
  64. package/dist/presetPrintable/index.umd.js +3 -3
  65. package/dist/prosemirror/index.cjs.js +7 -7
  66. package/dist/prosemirror/index.es.js +385 -372
  67. package/dist/prosemirror/index.umd.js +8 -8
  68. package/dist/rendererReact/index.cjs.js +1 -1
  69. package/dist/rendererReact/index.es.js +200 -187
  70. package/dist/rendererReact/index.js +1 -1
  71. package/dist/rendererReact/index.umd.js +1 -1
  72. package/dist/rteTinyMce/index.cjs.js +2 -2
  73. package/dist/rteTinyMce/index.es.js +118 -105
  74. package/dist/rteTinyMce/index.umd.js +2 -2
  75. package/dist/shapeDividerComponent/index.cjs.js +4 -4
  76. package/dist/shapeDividerComponent/index.es.js +129 -116
  77. package/dist/shapeDividerComponent/index.umd.js +4 -4
  78. package/dist/swiperComponent/index.cjs.js +9 -9
  79. package/dist/swiperComponent/index.es.js +203 -190
  80. package/dist/swiperComponent/index.umd.js +7 -7
  81. package/dist/tableComponent/index.cjs.js +1 -1
  82. package/dist/tableComponent/index.es.js +257 -244
  83. package/dist/tableComponent/index.umd.js +1 -1
  84. package/dist/types.d.ts +1 -1
  85. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  86. package/dist/youtubeAssetProvider/index.es.js +121 -108
  87. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  88. package/package.json +1 -1
@@ -1,21 +1,21 @@
1
- (function(g,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(g=typeof globalThis<"u"?globalThis:g||self,g.StudioSdkPlugins_dataSourceEjs=m())})(this,function(){"use strict";const g="app.grapesjs.com",m="app-stage.grapesjs.com",$=[g,"app2.grapesjs.com",m,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",w="license:check:end",P=()=>typeof window<"u",O=({isDev:o,isStage:t,isPlatform:e})=>`${o?"":`https://${t?m:g}`}/${e?"platform-api":"api"}`,N=()=>{const o=P()&&window.location.hostname;return!!o&&($.includes(o)||$.some(t=>o.endsWith(t)))};async function T({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const i=`${t||O({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const l=n?new URLSearchParams(n).toString():"",u=l?`?${l}`:"",p=await fetch(`${i}${u}`,c);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var y=(o=>(o.free="free",o.startup="startup",o.business="business",o.enterprise="enterprise",o))(y||{});const b={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function v(o){const t=o;return t.init=e=>s=>o(s,e),t}const k=o=>v(o);async function L({editor:o,plan:t,pluginName:e,licenseKey:s,onLicenseCheckResponse:n,cleanup:r}){let a="",i=!1;const c=N(),l=p=>{console.warn("Cleanup plugin:",e,"Reason:",p),r()},u=(p={})=>{var E;const{error:h,sdkLicense:S}=p,d=(E=p.plan)==null?void 0:E.category;if(!(S||p.license)||h)l(h||"Invalid license");else if(d){const x=b[t],G=b[d];x>G&&l({pluginRequiredPlan:t,licensePlan:d})}};o.on(I,p=>{a=p==null?void 0:p.baseApiUrl,i=!0}),o.on(w,p=>{n==null||n(p),u(p)}),setTimeout(async()=>{if(!i){if(c)return;if(s){const p=await A({licenseKey:s,pluginName:e,baseApiUrl:a});n==null||n(p),p&&u(p)}else l("The `licenseKey` option not provided")}},2e3)}async function A(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await T({baseApiUrl:s,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 C=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},M=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),B=(o,t)=>{const e=n=>{const{input:r}=n,{contains:a}=t;(!a||r.includes(a))&&(n.input=t.importer.import(r))},s=o.Parser.events.htmlBefore;return o.on(s,e),()=>{o.off(s,e)}};class _{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,s=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${s}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:s,startIndex:n,endIndex:r}=t,a=(s==null?void 0:s.path)||e||"",i=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const l=n??0,u=r!==void 0?r:"";c=`.slice(${l}${u!==""?`, ${u}`:""})`}return`<% ${a}${c}.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"],P="license:check:end",v=()=>typeof window<"u",O=({isDev:s,isStage:t,isPlatform:e})=>`${s?"":`https://${t?y:f}`}/${e?"platform-api":"api"}`,T=()=>{const s=v()&&window.location.hostname;return!!s&&(I.includes(s)||I.some(t=>s.endsWith(t)))};async function w({path:s,baseApiUrl:t,method:e="GET",headers:r={},params:n,body:a}){const i=`${t||O({isDev:!1,isStage:!1})}${s}`,l={method:e,headers:{"Content-Type":"application/json",...r}};a&&(l.body=JSON.stringify(a));const c=n?new URLSearchParams(n).toString():"",u=c?`?${c}`:"",p=await fetch(`${i}${u}`,l);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var E=(s=>(s.free="free",s.startup="startup",s.business="business",s.enterprise="enterprise",s))(E||{}),S=(s=>(s.toastAdd="studio:toastAdd",s.toastRemove="studio:toastRemove",s.dialogOpen="studio:dialogOpen",s.dialogClose="studio:dialogClose",s.dialogExportCode="studio:dialogExportCode",s.dialogImportCode="studio:dialogImportCode",s.sidebarLeftSet="studio:sidebarLeft:set",s.sidebarLeftGet="studio:sidebarLeft:get",s.sidebarLeftToggle="studio:sidebarLeft:toggle",s.sidebarRightSet="studio:sidebarRight:set",s.sidebarRightGet="studio:sidebarRight:get",s.sidebarRightToggle="studio:sidebarRight:toggle",s.sidebarTopSet="studio:sidebarTop:set",s.sidebarTopGet="studio:sidebarTop:get",s.sidebarTopToggle="studio:sidebarTop:toggle",s.sidebarBottomSet="studio:sidebarBottom:set",s.sidebarBottomGet="studio:sidebarBottom:get",s.sidebarBottomToggle="studio:sidebarBottom:toggle",s.symbolAdd="studio:symbolAdd",s.symbolDetach="studio:symbolDetach",s.symbolOverride="studio:symbolOverride",s.symbolPropagateStyles="studio:propagateStyles",s.getPagesConfig="studio:getPagesConfig",s.setPagesConfig="studio:setPagesConfig",s.getPageSettings="studio:getPageSettings",s.setPageSettings="studio:setPageSettings",s.clearPage="studio:clearPage",s.projectFiles="studio:projectFiles",s.validateCode="studio:validateCode",s.canvasReload="studio:canvasReload",s.getBlocksPanel="studio:getBlocksPanel",s.setBlocksPanel="studio:setBlocksPanel",s.getStateContextMenu="studio:getStateContextMenu",s.setStateContextMenu="studio:setStateContextMenu",s.contextMenuComponent="studio:contextMenuComponent",s.layoutAdd="studio:layoutAdd",s.layoutRemove="studio:layoutRemove",s.layoutToggle="studio:layoutToggle",s.layoutUpdate="studio:layoutUpdate",s.layoutGet="studio:layoutGet",s.layoutConfigGet="studio:layoutConfigGet",s.layoutConfigSet="studio:layoutConfigSet",s.layoutComponentAdd="studio:layoutComponentAdd",s.layoutComponentGet="studio:layoutComponentGet",s.layoutComponentRemove="studio:layoutComponentRemove",s.layoutComponentRender="studio:layoutComponentRender",s.getStateTheme="studio:getStateTheme",s.setStateTheme="studio:setStateTheme",s.settings="studio:settings",s.assetProviderGet="studio:assetProviderGet",s.assetProviderAdd="studio:assetProviderAdd",s.assetProviderRemove="studio:assetProviderRemove",s.fontGet="studio:fontGet",s.fontAdd="studio:fontAdd",s.fontRemove="studio:fontRemove",s.fontManagerOpen="studio:fontManagerOpen",s.menuFontLoad="studio:menuFontLoad",s.toggleStateDataSource="studio:toggleStateDataSource",s.getStateDataSource="studio:getStateDataSource",s.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",s.dataSourceSetImporter="studio:dataSourceSetImporter",s.dataSourceSetExporter="studio:dataSourceSetExporter",s.setDragAbsolute="studio:setDragAbsolute",s))(S||{});const m={[E.free]:0,[E.startup]:10,[E.business]:20,[E.enterprise]:30};function L(s){const t=s;return t.init=e=>r=>s(r,e),t}const k=s=>L(s);async function A({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 $=m[t],V=m[d];$>V&&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 B({licenseKey:r,pluginName:e,baseApiUrl:o});u(p)}else l("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const p=N(i);u(p);return}s.on(P,p=>u(p))}const N=s=>({sdkLicense:s.license,license:s.license,error:s.licenseError,plan:s.licensePlan});async function B(s){const{licenseKey:t,pluginName:e,baseApiUrl:r}=s;try{return(await w({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 M=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}),D=(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 G{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:s}){return(t?[this._sanitizeVariableName(t),s,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(C(t)){const e=t.statements.map(r=>this._parseCondition(r)),s=j[t.logicalOperator];let n=e.length>1?`(${e.join(`)${s}(`)})`:e[0];return t.logicalOperator==="xor"&&(n=`!!(${n})`),n}else{const e=this._parseValue(t.left),s=this._parseValue(t.right);switch(t.operator){case"equals":return`${e} === ${s}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${e} ${t.operator} ${s}`;case"contains":return`${e}?.includes(${s})`;case"startsWith":return`${e}?.startsWith(${s})`;case"endsWith":return`${e}?.endsWith(${s})`;case"equalsIgnoreCase":return`${e}?.toLowerCase() === ${s}?.toLowerCase()`;case"trimEquals":return`${e}?.trim() === ${s}?.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} ${s}`}}}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}}const j={and:"&&",or:"||",xor:"^"},W=["===","==","!==","!=","<=",">=","<",">","&&","||"],J={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class F{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 s=0;for(;s<t.length;){const n=t.indexOf("<%",s);if(n===-1){s<t.length&&e.push(this.createAppendLiteral(t.slice(s)));break}n>s&&e.push(this.createAppendLiteral(t.slice(s,n)));const r=t.indexOf("%>",n);if(r===-1)throw new Error("Unclosed EJS tag");const a=t.slice(n+2,r).trim();if(s=r+2,a.startsWith("=")||a.startsWith("-")){const i=a.slice(1).trim();e.push(this.createAppendExpression(i))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const i=this.parseIfStatement(a,t,s);e.push(i),s=i.endPos||s}else if(a.startsWith("for")){const i=this.parseForStatement(a,t,s);e.push(i),s=i.endPos||s}else{const i=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(i){const c=i[1],l=i[2],u=this.parseForEachStatement(c,l,t,s);e.push(u),s=u.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${a}`)}}}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,s){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const r=this.parseJsExpression(n[1]),{body:a,endPos:i}=this.parseTemplateBlock(e,s);let c=null,l=i;const u=e.indexOf("<%",l);if(u===l){const p=e.indexOf("%>",u);if(p!==-1){const h=e.slice(u+2,p).trim(),S=p+2-u;if(h.startsWith("} else if")){l=u+S;const d=h.substring(h.indexOf("if")).trim(),f=this.parseIfStatement(d,e,l);c={type:"IfStatement",test:f.test,consequent:f.consequent,alternate:f.alternate},l=f.endPos}else if(h.startsWith("} else")){l=u+S;const{body:d,endPos:f}=this.parseTemplateBlock(e,l);c={type:"BlockStatement",body:d},l=f;const E=e.indexOf("<%",l),x=e.indexOf("%>",E);E===l&&e.slice(E+2,x).trim()==="}"&&(l=x+2)}else h==="}"&&(l=u+S)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:a},alternate:c,endPos:l}}parseForStatement(t,e,s){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const r=n[1].split("of");if(r.length!==2)throw new Error("Only for...of loops are supported");const a=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),i=r[1].trim(),{body:c,endPos:l}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:this.parseJsExpression(i)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const u=e.indexOf("<%",l),p=e.indexOf("%>",u);return u===l&&e.slice(u+2,p).trim()==="}"?p+2:l})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:a}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const i=s.indexOf("<%",a),c=s.indexOf("%>",i);return i===a&&s.slice(i+2,c).trim()==="}"?c+2:a})()}}parseTemplateBlock(t,e){const s=[];let n=e;for(;n<t.length;){const r=t.indexOf("<%",n);if(r===-1){n<t.length&&s.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}r>n&&s.push(this.createAppendLiteral(t.slice(n,r)));const a=t.indexOf("%>",r);if(a===-1)throw new Error("Unclosed EJS tag within block");const i=t.slice(r+2,a).trim();if(i==="}"||i.startsWith("} else")){n=r;break}if(n=a+2,i.startsWith("=")||i.startsWith("-")){const c=i.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const c=this.parseIfStatement(i,t,n);s.push(c),n=c.endPos||n}else if(i.startsWith("for")){const c=this.parseForStatement(i,t,n);s.push(c),n=c.endPos||n}else{const c=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const l=c[1],u=c[2],p=this.parseForEachStatement(l,u,t,n);s.push(p),n=p.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${i}`)}}}return{body:s,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 r=t.lastIndexOf(n);if(r>0&&t[r-1]!=="!"&&t[r-1]!=="="&&t[r-1]!=="<"&&t[r-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:J[n],left:this.parseJsExpression(t.slice(0,r).trim()),right:this.parseJsExpression(t.slice(r+n.length).trim())}}const e=t.indexOf("."),s=t.indexOf("[");if(e>0&&(s===-1||e<s)||s>0&&(e===-1||s<e)){const n=e>0&&(s===-1||e<s)?e:s;let r,a,i=!1;if(n===e)r=t.slice(0,e),a={type:"Identifier",name:t.slice(e+1)},i=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const l=t.slice(s+1,c);a=/^(['"]).*\1$/.test(l)||/^-?\d+(\.\d+)?$/.test(l)?this.parseJsExpression(l):{type:"Identifier",name:l},i=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:a,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 s of t.body)e+=this.astToGrapesJS(s);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),s=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(M(t)){const e=t.statements.map(a=>this._parseCondition(a)),r=F[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 F={and:"&&",or:"||",xor:"^"},_=["===","==","!==","!=","<=",">=","<",">","&&","||"],J={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class W{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 _){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:J[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
- <data-condition-true-content>${s}</data-condition-true-content>
6
+ <data-condition-true-content>${r}</data-condition-true-content>
7
7
  <data-condition-false-content>${n}</data-condition-false-content>
8
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 s="";if(e.init)s=this.getExpressionString(e.init);else return this.addMessage("warning","For loop collection is undefined"),"";const n=e.id.name,r=n;this.collectionStack.push(n);const a=this.astToGrapesJS(t.body);return this.collectionStack.pop(),`
10
- <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:s},collectionId:r})}'>
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
11
  <data-collection-item>
12
- ${a}
12
+ ${o}
13
13
  </data-collection-item>
14
14
  </data-collection>
15
- `}handleForEachStatement(t){const e=this.getExpressionString(t.collection),s=t.itemIdentifier.name,n=s;this.collectionStack.push(s);const r=this.astToGrapesJS(t.body);return this.collectionStack.pop(),`
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
16
  <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
17
17
  <data-collection-item>
18
- ${r}
18
+ ${a}
19
19
  </data-collection-item>
20
20
  </data-collection>
21
- `}handleBlockStatement(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const s=this.collectionStack[this.collectionStack.length-1];t.name===s&&(e={collectionId:s,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 r=this.collectionStack[this.collectionStack.length-1];let a=t;const i=[];for(;a.type==="MemberExpression";)a.property.type==="Identifier"&&!a.computed?i.unshift(a.property.name):a.property.type==="Literal"&&a.computed?i.unshift(String(a.property.value)):i.unshift(this.getExpressionString(a.property)),a=a.object;if(a.type==="Identifier"&&a.name===r){const c=i.join(".");n={...e,collectionId:r,variableType:"currentItem",path:c}}}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 s=((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: ${s}`),""}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),s="isTruthy";return e.startsWith("!!")?(s="isTruthy",e=e.slice(2)):e.startsWith("!")&&(s="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:s}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),s=this.getConditionExpression(t.right);return`${e} ${t.operator} ${s}`}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),s=this.getExpressionString(t.property);return t.computed?`${e}[${s}]`:`${e}.${s}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const D="dataSourceEjs",U=y.startup;return k(function(o,t={}){const e=M(o,new _),s=B(o,{contains:"<%",importer:new F});L({editor:o,licenseKey:t.licenseKey,plan:U,pluginName:D,cleanup:()=>{e(),s()}})})});
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 R="dataSourceEjs",U=E.startup;return k(function(s,t={}){const e=j(s,new G),r=D(s,{contains:"<%",importer:new W});A({editor:s,licenseKey:t.licenseKey,plan:U,pluginName:R,cleanup:()=>{e(),r()}})})});
@@ -1,10 +1,10 @@
1
- "use strict";const v=require("handlebars/dist/cjs/handlebars"),y="app.grapesjs.com",$="app-stage.grapesjs.com",C="app2.grapesjs.com",N="app-stage2.grapesjs.com",P=[y,C,$,N,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],_="license:check:start",k="license:check:end",T=()=>typeof window<"u",w=({isDev:a,isStage:t,isPlatform:e})=>`${a?"":`https://${t?$:y}`}/${e?"platform-api":"api"}`,O=()=>{const a=T()&&window.location.hostname;return!!a&&(P.includes(a)||P.some(t=>a.endsWith(t)))};async function A({path:a,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:i}){const l=`${t||w({isDev:!1,isStage:!1})}${a}`,u={method:e,headers:{"Content-Type":"application/json",...n}};i&&(u.body=JSON.stringify(i));const c=s?new URLSearchParams(s).toString():"",h=c?`?${c}`:"",o=await fetch(`${l}${h}`,u);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o.json()}var p=(a=>(a.free="free",a.startup="startup",a.business="business",a.enterprise="enterprise",a))(p||{});const S={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function L(a){const t=a;return t.init=e=>n=>a(n,e),t}const j=a=>L(a);async function D({editor:a,plan:t,pluginName:e,licenseKey:n,onLicenseCheckResponse:s,cleanup:i}){let r="",l=!1;const u=O(),c=o=>{console.warn("Cleanup plugin:",e,"Reason:",o),i()},h=(o={})=>{var f;const{error:g,sdkLicense:x}=o,m=(f=o.plan)==null?void 0:f.category;if(!(x||o.license)||g)c(g||"Invalid license");else if(m){const E=S[t],I=S[m];E>I&&c({pluginRequiredPlan:t,licensePlan:m})}};a.on(_,o=>{r=o==null?void 0:o.baseApiUrl,l=!0}),a.on(k,o=>{s==null||s(o),h(o)}),setTimeout(async()=>{if(!l){if(u)return;if(n){const o=await M({licenseKey:n,pluginName:e,baseApiUrl:r});s==null||s(o),o&&h(o)}else c("The `licenseKey` option not provided")}},2e3)}async function M(a){const{licenseKey:t,pluginName:e,baseApiUrl:n}=a;try{return(await A({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(s){return console.error("Error during SDK license check:",s),!1}}const H=(a,t)=>(a.config.optsHtml={...a.config.optsHtml,exporter:t},()=>{a.config.optsHtml.exporter=void 0}),U=(a,t)=>{const e=s=>{const{input:i}=s,{contains:r}=t;(!r||i.includes(r))&&(s.input=t.importer.import(i))},n=a.Parser.events.htmlBefore;return a.on(n,e),()=>{a.off(n,e)}},b={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},B={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},W={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},V={...b,...B,...W};class G{getHelperId(t){return V[t]||t}getFullPath({collectionId:t,path:e}){let n=e;return t&&(n=[this._sanitizeVariableName(t),e].filter(Boolean).join(".")),n||""}getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,n=this.getFullPath(t);return e?`{{#if ${n}}}{{{${n}}}}{{else}}${e}{{/if}}`:`{{{${n}}}}`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:n}=t,s=n==null?void 0:n.path;let i="";if(t.startIndex!==void 0||t.endIndex!==void 0){const c=t.startIndex??0,h=t.endIndex!==void 0?t.endIndex:"";h!==""?i=` (slice ${s} ${c} ${h})`:i=` (slice ${s} ${c})`}const l=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${i||s}${l}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:t}){const e=t.condition;if(!e)return"";const n=e,s=e;if(s.statements&&s.logicalOperator==="and"||s.logicalOperator==="or"){const{statements:i}=s,r=s.logicalOperator,l=i.map(c=>this._parseCondition(c)).join(" ");return`{{#if ${i.length>1?`(${r} ${l})`:l}}}`}else return`{{#if ${this._parseCondition(n)}}}`}_parseCondition(t){if(!t)return"";const e=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:s}=n,i=n.logicalOperator,r=n.statements.map(l=>this._parseCondition(l)).join(" ");return s.length>1?`(${i} ${r})`:r}else{const s=e.operator,i=this.getHelperId(s),r=this._parseValue(e.left),l=this._parseValue(e.right);return this.getExpressionStr(i,r,l)}}getExpressionStr(t,e,n){return b[t]?t==="isTruthy"?e:t==="isFalsy"?`!${e}`:`${t} ${e}`:`(${t} ${e} ${n})`}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class q{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return v.parse(t)}catch(e){if(e instanceof Error&&e.message.includes("Parse error")){const n=e.message.match(/line (\d+)/),s=n?parseInt(n[1]):0,i=e.message.match(/column (\d+)/),r=i?parseInt(i[1]):0;throw new Error(`Handlebars syntax error at line ${s}, column ${r}: ${e.message}`)}throw e}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"ContentStatement":return this.handleContentStatement(t);case"MustacheStatement":return this.handleMustacheStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"PartialStatement":return this.handlePartialStatement(t);case"CommentStatement":return this.handleCommentStatement(t);case"ElementNode":return this.handleElementNode(t);case"TextNode":return this.handleTextNode(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`,t.loc),""}}handleProgram(t){let e="";if(t.body)for(const n of t.body)e+=this.astToGrapesJS(n);return e}handleContentStatement(t){return t.value||""}handleMustacheStatement(t,e={}){const n=this.getExpressionString(t.path),s={...e};return this.collectionStack.length>0?this.processPathWithCollectionContext(n,s):s.path=n,`<data-variable data-gjs-data-resolver='${JSON.stringify(s)}'></data-variable>`}processPathWithCollectionContext(t,e){t.startsWith("@")?this.handleDirectCollectionReference(t,e):this.handleRelativePathReference(t,e)}handleDirectCollectionReference(t,e){if(this.isSpecialIterationVariable(t)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],t,e);return}const[n,...s]=t.substring(1).split("/"),i=s.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,i,e):this.handleParentReferenceFallback(t,e)}isSpecialIterationVariable(t){return["index","@index","key","@key"].includes(t)}setSpecialVariableResolver(t,e,n){n.collectionId=t;const s={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};n.variableType=s[e]}setCurrentItemResolver(t,e,n){n.collectionId=t,n.variableType="currentItem",e&&(n.path=e)}handleRelativePathReference(t,e){const n=d(t),{parentLevel:s,remainingPathParts:i}=this.calculateParentLevel(n),r=i.join("."),l=this.collectionStack.length-1-s;l>=0&&l<this.collectionStack.length?this.resolveRelativePath(r,l,e):e.path=i.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(i=>i===t[0]);if(e!==-1)return{parentLevel:this.collectionStack.length-1-e,remainingPathParts:t.slice(1)};let n=0;const s=[...t];for(;s[0]==="..";)n++,s.shift();return{parentLevel:n,remainingPathParts:s}}resolveRelativePath(t,e,n){const s=this.collectionStack[e];n.collectionId=s,n.variableType="currentItem",t!=="this"&&(n.path=t.startsWith("this.")?t.split(".").slice(1).join("."):t)}handleParentReferenceFallback(t,e){const n=d(t),{parentLevel:s,remainingPathParts:i}=this.calculateParentLevel(n),r=i.join("."),l=this.collectionStack.length-1-s;l>=0&&l<this.collectionStack.length?this.resolveRelativePath(r,l,e):e.path=i.join(".")}handleBlockStatement(t){const e=t.path.original;switch(e){case"if":case"unless":return this.handleConditionalBlock(t,e);case"each":return this.handleEachBlock(t);default:return this.addMessage("warning",`Unsupported block helper: ${e}`,t.loc),this.handleGenericBlock(t)}}handleConditionalBlock(t,e){const i={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:e==="unless"?"isFalsy":"isTruthy"}]},r=this.handleProgram(t.program),l=t.inverse?this.handleProgram(t.inverse):"";return`
2
- <data-condition data-gjs-data-resolver='${JSON.stringify({condition:i})}'>
3
- <data-condition-true-content>${r}</data-condition-true-content>
4
- <data-condition-false-content>${l}</data-condition-false-content>
1
+ "use strict";const T=require("handlebars/dist/cjs/handlebars"),$="app.grapesjs.com",x="app-stage.grapesjs.com",k="app2.grapesjs.com",A="app-stage2.grapesjs.com",b=[$,k,x,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:end",N=()=>typeof window<"u",R=({isDev:e,isStage:t,isPlatform:s})=>`${e?"":`https://${t?x:$}`}/${s?"platform-api":"api"}`,O=()=>{const e=N()&&window.location.hostname;return!!e&&(b.includes(e)||b.some(t=>e.endsWith(t)))};async function _({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:a,body:r}){const i=`${t||R({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};r&&(c.body=JSON.stringify(r));const u=a?new URLSearchParams(a).toString():"",h=u?`?${u}`:"",l=await fetch(`${i}${h}`,c);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),d=(e=>(e.toastAdd="studio:toastAdd",e.toastRemove="studio:toastRemove",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.dialogExportCode="studio:dialogExportCode",e.dialogImportCode="studio:dialogImportCode",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.clearPage="studio:clearPage",e.projectFiles="studio:projectFiles",e.validateCode="studio:validateCode",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.layoutComponentAdd="studio:layoutComponentAdd",e.layoutComponentGet="studio:layoutComponentGet",e.layoutComponentRemove="studio:layoutComponentRemove",e.layoutComponentRender="studio:layoutComponentRender",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.settings="studio:settings",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(d||{});const m={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function w(e){const t=e;return t.init=s=>n=>e(n,s),t}const D=e=>w(e);async function G({editor:e,plan:t,pluginName:s,licenseKey:n,onLicenseCheckResponse:a,cleanup:r}){let o="",i;const c=l=>{console.warn("Cleanup plugin:",s,"Reason:",l),r()},u=(l={})=>{var P;const{error:y,sdkLicense:E}=l,g=(P=l.plan)==null?void 0:P.category;if(!(E||l.license)||y)c(y||"Invalid license");else if(g){const I=m[t],S=m[g];I>S&&c({pluginRequiredPlan:t,licensePlan:g})}};e.Commands.has(d.settings)&&(i=e.runCommand(d.settings),o=(i==null?void 0:i.baseUrl)||"");const h=l=>{a==null||a(l),l&&u(l)};if(!i){e.onReady(async()=>{if(!O())if(n){const l=await B({licenseKey:n,pluginName:s,baseApiUrl:o});h(l)}else c("The `licenseKey` option not provided")});return}if(i.licensePlan||i.licenseError){const l=M(i);h(l);return}e.on(L,l=>h(l))}const M=e=>({sdkLicense:e.license,license:e.license,error:e.licenseError,plan:e.licensePlan});async function B(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await _({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}const j=(e,t)=>(e.config.optsHtml={...e.config.optsHtml,exporter:t},()=>{e.config.optsHtml.exporter=void 0}),U=(e,t)=>{const s=a=>{const{input:r}=a,{contains:o}=t;(!o||r.includes(o))&&(a.input=t.importer.import(r))},n=e.Parser.events.htmlBefore;return e.on(n,s),()=>{e.off(n,s)}},v={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},H={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},W={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},V={...v,...H,...W};class F{getHelperId(t){return V[t]||t}getFullPath({collectionId:t,path:s}){let n=s;return t&&(n=[this._sanitizeVariableName(t),s].filter(Boolean).join(".")),n||""}getVariableSyntax({dataResolver:t}){const{defaultValue:s}=t,n=this.getFullPath(t);return s?`{{#if ${n}}}{{{${n}}}}{{else}}${s}{{/if}}`:`{{{${n}}}}`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:s,dataSource:n}=t,a=n==null?void 0:n.path;let r="";if(t.startIndex!==void 0||t.endIndex!==void 0){const u=t.startIndex??0,h=t.endIndex!==void 0?t.endIndex:"";h!==""?r=` (slice ${a} ${u} ${h})`:r=` (slice ${a} ${u})`}const i=` as |${this._sanitizeVariableName(s)}|`;return`{{#each ${r||a}${i}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:t}){const s=t.condition;if(!s)return"";const n=s,a=s;if(a.statements&&a.logicalOperator==="and"||a.logicalOperator==="or"){const{statements:r}=a,o=a.logicalOperator,i=r.map(u=>this._parseCondition(u)).join(" ");return`{{#if ${r.length>1?`(${o} ${i})`:i}}}`}else return`{{#if ${this._parseCondition(n)}}}`}_parseCondition(t){if(!t)return"";const s=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:a}=n,r=n.logicalOperator,o=n.statements.map(i=>this._parseCondition(i)).join(" ");return a.length>1?`(${r} ${o})`:o}else{const a=s.operator,r=this.getHelperId(a),o=this._parseValue(s.left),i=this._parseValue(s.right);return this.getExpressionStr(r,o,i)}}getExpressionStr(t,s,n){return v[t]?t==="isTruthy"?s:t==="isFalsy"?`!${s}`:`${t} ${s}`:`(${t} ${s} ${n})`}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class C{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const s=this.parse(t);return this.astToGrapesJS(s)}parse(t){try{return T.parse(t)}catch(s){if(s instanceof Error&&s.message.includes("Parse error")){const n=s.message.match(/line (\d+)/),a=n?parseInt(n[1]):0,r=s.message.match(/column (\d+)/),o=r?parseInt(r[1]):0;throw new Error(`Handlebars syntax error at line ${a}, column ${o}: ${s.message}`)}throw s}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"ContentStatement":return this.handleContentStatement(t);case"MustacheStatement":return this.handleMustacheStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"PartialStatement":return this.handlePartialStatement(t);case"CommentStatement":return this.handleCommentStatement(t);case"ElementNode":return this.handleElementNode(t);case"TextNode":return this.handleTextNode(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`,t.loc),""}}handleProgram(t){let s="";if(t.body)for(const n of t.body)s+=this.astToGrapesJS(n);return s}handleContentStatement(t){return t.value||""}handleMustacheStatement(t,s={}){const n=this.getExpressionString(t.path),a={...s};return this.collectionStack.length>0?this.processPathWithCollectionContext(n,a):a.path=n,`<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`}processPathWithCollectionContext(t,s){t.startsWith("@")?this.handleDirectCollectionReference(t,s):this.handleRelativePathReference(t,s)}handleDirectCollectionReference(t,s){if(this.isSpecialIterationVariable(t)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],t,s);return}const[n,...a]=t.substring(1).split("/"),r=a.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,r,s):this.handleParentReferenceFallback(t,s)}isSpecialIterationVariable(t){return["index","@index","key","@key"].includes(t)}setSpecialVariableResolver(t,s,n){n.collectionId=t;const a={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};n.variableType=a[s]}setCurrentItemResolver(t,s,n){n.collectionId=t,n.variableType="currentItem",s&&(n.path=s)}handleRelativePathReference(t,s){const n=f(t),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(n),o=r.join("."),i=this.collectionStack.length-1-a;i>=0&&i<this.collectionStack.length?this.resolveRelativePath(o,i,s):s.path=r.join(".")}calculateParentLevel(t){const s=this.collectionStack.findLastIndex(r=>r===t[0]);if(s!==-1)return{parentLevel:this.collectionStack.length-1-s,remainingPathParts:t.slice(1)};let n=0;const a=[...t];for(;a[0]==="..";)n++,a.shift();return{parentLevel:n,remainingPathParts:a}}resolveRelativePath(t,s,n){const a=this.collectionStack[s];n.collectionId=a,n.variableType="currentItem",t!=="this"&&(n.path=t.startsWith("this.")?t.split(".").slice(1).join("."):t)}handleParentReferenceFallback(t,s){const n=f(t),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(n),o=r.join("."),i=this.collectionStack.length-1-a;i>=0&&i<this.collectionStack.length?this.resolveRelativePath(o,i,s):s.path=r.join(".")}handleBlockStatement(t){const s=t.path.original;switch(s){case"if":case"unless":return this.handleConditionalBlock(t,s);case"each":return this.handleEachBlock(t);default:return this.addMessage("warning",`Unsupported block helper: ${s}`,t.loc),this.handleGenericBlock(t)}}handleConditionalBlock(t,s){const r={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:s==="unless"?"isFalsy":"isTruthy"}]},o=this.handleProgram(t.program),i=t.inverse?this.handleProgram(t.inverse):"";return`
2
+ <data-condition data-gjs-data-resolver='${JSON.stringify({condition:r})}'>
3
+ <data-condition-true-content>${o}</data-condition-true-content>
4
+ <data-condition-false-content>${i}</data-condition-false-content>
5
5
  </data-condition>
6
- `}handleEachBlock(t){var i,r,l;const e=this.getExpressionString(t.params[0]);let n;t.params.length>=3&&t.params[1]==="as"&&((i=t.params[2])==null?void 0:i.type)==="PathExpression"?n=t.params[2].original:(l=(r=t.program)==null?void 0:r.blockParams)!=null&&l.length?n=t.program.blockParams[0]:n=`collection-${Math.random().toString(36).substring(2,10)}`,this.collectionStack.push(n);const s=this.handleProgram(t.program);return this.collectionStack.pop(),`
7
- <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
8
- <data-collection-item>${s}</data-collection-item>
6
+ `}handleEachBlock(t){var r,o,i;const s=this.getExpressionString(t.params[0]);let n;t.params.length>=3&&t.params[1]==="as"&&((r=t.params[2])==null?void 0:r.type)==="PathExpression"?n=t.params[2].original:(i=(o=t.program)==null?void 0:o.blockParams)!=null&&i.length?n=t.program.blockParams[0]:n=`collection-${Math.random().toString(36).substring(2,10)}`,this.collectionStack.push(n);const a=this.handleProgram(t.program);return this.collectionStack.pop(),`
7
+ <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:s},collectionId:n})}'>
8
+ <data-collection-item>${a}</data-collection-item>
9
9
  </data-collection>
10
- `}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let e="";if(t.attributes)for(const s of t.attributes)s.value.type==="TextNode"?e+=` ${s.name}="${s.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${s.name}`,t.loc),e+=` ${s.name}="${this.getExpressionString(s.value)}"`);let n="";if(t.children)for(const s of t.children)n+=this.astToGrapesJS(s);return`<${t.tag}${e}>${n}</${t.tag}>`}handleTextNode(t){return t.chars||""}handlePartialStatement(t){return this.addMessage("warning",`Partials are not fully supported: ${t.name.original}`,t.loc),`{{> ${t.name.original}}}`}handleGenericBlock(t){const e=this.handleProgram(t.program);return`<!-- Unsupported block: ${t.path.original} -->${e}`}getExpressionString(t){return t.type==="PathExpression"?t.original:t.type==="StringLiteral"?t.value:t.type==="NumberLiteral"?t.value.toString():t.type==="BooleanLiteral"?t.value?"true":"false":t.type==="SubExpression"?this.getExpressionString(t.params[0]):t.type==="Hash"?`{${t.pairs.map(n=>`${n.key}=${this.getExpressionString(n.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${t.type}`,t.loc),"")}addMessage(t,e,n){this.messages.push({type:t,message:e,location:n?{line:n.start.line,column:n.start.column}:void 0})}}const d=a=>{if(a==null||a==="")return[];if(a===".")return["this"];if(a===".."||a==="../")return[".."];if(a.startsWith("../")){const r=a.substring(3);return["..",...d(r)]}const t=[];let e=0,n=a.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(r,l,u,c)=>{const h=u!==void 0?u:c||"";return t[e]=h,`__HANDLEBARS_PLACEHOLDER_${e++}__`});n=n.replace(/\//g,".");const s=n.split("."),i=[];for(const r of s){const l=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);if(l){const u=parseInt(l[1],10);i.push(t[u])}else r!==""&&i.push(r)}return i},F="dataSourceHandlebars",R=p.startup,J=function(a,t={}){const e=H(a,new G),n=U(a,{contains:"{{",importer:new q});D({editor:a,licenseKey:t.licenseKey,plan:R,pluginName:F,cleanup:()=>{e(),n()}})},K=j(J);module.exports=K;
10
+ `}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let s="";if(t.attributes)for(const a of t.attributes)a.value.type==="TextNode"?s+=` ${a.name}="${a.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${a.name}`,t.loc),s+=` ${a.name}="${this.getExpressionString(a.value)}"`);let n="";if(t.children)for(const a of t.children)n+=this.astToGrapesJS(a);return`<${t.tag}${s}>${n}</${t.tag}>`}handleTextNode(t){return t.chars||""}handlePartialStatement(t){return this.addMessage("warning",`Partials are not fully supported: ${t.name.original}`,t.loc),`{{> ${t.name.original}}}`}handleGenericBlock(t){const s=this.handleProgram(t.program);return`<!-- Unsupported block: ${t.path.original} -->${s}`}getExpressionString(t){return t.type==="PathExpression"?t.original:t.type==="StringLiteral"?t.value:t.type==="NumberLiteral"?t.value.toString():t.type==="BooleanLiteral"?t.value?"true":"false":t.type==="SubExpression"?this.getExpressionString(t.params[0]):t.type==="Hash"?`{${t.pairs.map(n=>`${n.key}=${this.getExpressionString(n.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${t.type}`,t.loc),"")}addMessage(t,s,n){this.messages.push({type:t,message:s,location:n?{line:n.start.line,column:n.start.column}:void 0})}}const f=e=>{if(e==null||e==="")return[];if(e===".")return["this"];if(e===".."||e==="../")return[".."];if(e.startsWith("../")){const o=e.substring(3);return["..",...f(o)]}const t=[];let s=0,n=e.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(o,i,c,u)=>{const h=c!==void 0?c:u||"";return t[s]=h,`__HANDLEBARS_PLACEHOLDER_${s++}__`});n=n.replace(/\//g,".");const a=n.split("."),r=[];for(const o of a){const i=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(o);if(i){const c=parseInt(i[1],10);r.push(t[c])}else o!==""&&r.push(o)}return r},q="dataSourceHandlebars",J=p.startup,z=function(e,t={}){const s=j(e,new F),n=U(e,{contains:"{{",importer:new C});G({editor:e,licenseKey:t.licenseKey,plan:J,pluginName:q,cleanup:()=>{s(),n()}})},K=D(z);module.exports=K;