@grapesjs/studio-sdk-plugins 1.0.33-rc.1 → 1.0.33

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 (130) hide show
  1. package/dist/accordionComponent/index.cjs.js +7 -7
  2. package/dist/accordionComponent/index.es.js +161 -156
  3. package/dist/accordionComponent/index.umd.js +9 -9
  4. package/dist/aiChat/chatManager.d.ts +15 -0
  5. package/dist/aiChat/clientTools.d.ts +3 -3
  6. package/dist/aiChat/clientToolsProcessors.d.ts +14 -1
  7. package/dist/aiChat/components/AiChatEmptyState.d.ts +4 -6
  8. package/dist/aiChat/components/AiChatError.d.ts +2 -1
  9. package/dist/aiChat/components/AiChatHeader.d.ts +2 -1
  10. package/dist/aiChat/components/AiChatInput/AssetsSection.d.ts +7 -0
  11. package/dist/aiChat/components/AiChatInput/AttachButton.d.ts +10 -0
  12. package/dist/aiChat/components/AiChatInput/ContextSection.d.ts +5 -0
  13. package/dist/aiChat/components/AiChatInput/DictateButton.d.ts +7 -0
  14. package/dist/aiChat/components/AiChatInput/TextAreaWithAutoResize.d.ts +6 -0
  15. package/dist/aiChat/components/AiChatInput/constants.d.ts +6 -0
  16. package/dist/aiChat/components/AiChatInput/hooks/useSpeechToText.d.ts +15 -0
  17. package/dist/aiChat/components/AiChatInput/index.d.ts +37 -0
  18. package/dist/aiChat/components/AiChatLoadingState.d.ts +2 -1
  19. package/dist/aiChat/components/AiChatMessage.d.ts +21 -9
  20. package/dist/aiChat/components/AiChatMessages.d.ts +5 -7
  21. package/dist/aiChat/components/AiChatMessagesStatus.d.ts +5 -0
  22. package/dist/aiChat/components/AiChatPanel.d.ts +2 -3
  23. package/dist/aiChat/components/AiChatProvider.d.ts +14 -0
  24. package/dist/aiChat/components/MemoizedMarkdown.d.ts +9 -0
  25. package/dist/aiChat/components/index.d.ts +24 -25
  26. package/dist/aiChat/components/utils.d.ts +12 -4
  27. package/dist/aiChat/index.cjs.d.ts +5 -0
  28. package/dist/aiChat/index.cjs.js +453 -0
  29. package/dist/aiChat/index.d.ts +4 -3
  30. package/dist/aiChat/index.es.d.ts +5 -0
  31. package/dist/aiChat/index.es.js +30930 -0
  32. package/dist/aiChat/index.js +453 -0
  33. package/dist/aiChat/index.umd.js +453 -0
  34. package/dist/aiChat/locales/en.d.ts +64 -0
  35. package/dist/aiChat/server/index.cjs.d.ts +4 -0
  36. package/dist/aiChat/server/index.cjs.js +309 -0
  37. package/dist/aiChat/server/index.d.ts +0 -50
  38. package/dist/aiChat/server/index.es.d.ts +4 -0
  39. package/dist/aiChat/server/index.es.js +876 -0
  40. package/dist/aiChat/server/index.js +309 -0
  41. package/dist/aiChat/server/index.umd.js +309 -0
  42. package/dist/aiChat/server/stream.d.ts +0 -6
  43. package/dist/aiChat/server/tools.d.ts +157 -51
  44. package/dist/aiChat/server/types.d.ts +108 -64
  45. package/dist/aiChat/types.d.ts +148 -108
  46. package/dist/aiChat/typesSchema.d.ts +238 -25
  47. package/dist/animationComponent/index.cjs.js +3 -3
  48. package/dist/animationComponent/index.es.js +174 -169
  49. package/dist/animationComponent/index.umd.js +3 -3
  50. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  51. package/dist/canvasAbsoluteMode/index.es.js +161 -156
  52. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  53. package/dist/canvasEmptyState/index.cjs.js +1 -1
  54. package/dist/canvasEmptyState/index.es.js +113 -108
  55. package/dist/canvasEmptyState/index.umd.js +1 -1
  56. package/dist/canvasFullSize/index.cjs.js +9 -9
  57. package/dist/canvasFullSize/index.es.js +137 -132
  58. package/dist/canvasFullSize/index.umd.js +9 -9
  59. package/dist/canvasGridMode/index.cjs.js +4 -4
  60. package/dist/canvasGridMode/index.es.js +168 -163
  61. package/dist/canvasGridMode/index.umd.js +8 -8
  62. package/dist/canvasScreenshot/index.cjs.js +1 -1
  63. package/dist/canvasScreenshot/index.es.js +132 -127
  64. package/dist/canvasScreenshot/index.umd.js +1 -1
  65. package/dist/dataSourceEjs/index.cjs.js +5 -5
  66. package/dist/dataSourceEjs/index.es.js +151 -146
  67. package/dist/dataSourceEjs/index.umd.js +5 -5
  68. package/dist/dataSourceHandlebars/index.cjs.js +4 -4
  69. package/dist/dataSourceHandlebars/index.es.js +91 -86
  70. package/dist/dataSourceHandlebars/index.umd.js +5 -5
  71. package/dist/dialogComponent/index.cjs.js +16 -16
  72. package/dist/dialogComponent/index.es.js +117 -112
  73. package/dist/dialogComponent/index.umd.js +16 -16
  74. package/dist/flexComponent/index.cjs.js +11 -11
  75. package/dist/flexComponent/index.es.js +416 -411
  76. package/dist/flexComponent/index.umd.js +11 -11
  77. package/dist/fsLightboxComponent/index.cjs.js +3 -3
  78. package/dist/fsLightboxComponent/index.es.js +152 -147
  79. package/dist/fsLightboxComponent/index.umd.js +3 -3
  80. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  81. package/dist/googleFontsAssetProvider/index.es.js +127 -122
  82. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  83. package/dist/iconifyComponent/index.cjs.js +2 -2
  84. package/dist/iconifyComponent/index.es.js +170 -165
  85. package/dist/iconifyComponent/index.umd.js +2 -2
  86. package/dist/index.cjs.js +1 -1
  87. package/dist/index.es.js +27 -22
  88. package/dist/index.umd.js +1 -1
  89. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  90. package/dist/layoutSidebarButtons/index.es.js +156 -151
  91. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  92. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  93. package/dist/lightGalleryComponent/index.es.js +197 -192
  94. package/dist/lightGalleryComponent/index.umd.js +1 -1
  95. package/dist/linkImageComponent/index.cjs.js +2 -2
  96. package/dist/linkImageComponent/index.es.js +86 -81
  97. package/dist/linkImageComponent/index.umd.js +2 -2
  98. package/dist/listPagesComponent/index.cjs.js +5 -5
  99. package/dist/listPagesComponent/index.es.js +121 -116
  100. package/dist/listPagesComponent/index.umd.js +5 -5
  101. package/dist/presetPrintable/index.cjs.js +4 -4
  102. package/dist/presetPrintable/index.es.js +180 -175
  103. package/dist/presetPrintable/index.umd.js +4 -4
  104. package/dist/prosemirror/index.cjs.js +6 -6
  105. package/dist/prosemirror/index.es.js +128 -123
  106. package/dist/prosemirror/index.umd.js +8 -8
  107. package/dist/rendererReact/index.cjs.js +1 -1
  108. package/dist/rendererReact/index.es.js +127 -122
  109. package/dist/rendererReact/index.js +1 -1
  110. package/dist/rendererReact/index.umd.js +1 -1
  111. package/dist/rteTinyMce/index.cjs.js +2 -2
  112. package/dist/rteTinyMce/index.es.js +160 -155
  113. package/dist/rteTinyMce/index.umd.js +2 -2
  114. package/dist/shapeDividerComponent/index.cjs.js +25 -25
  115. package/dist/shapeDividerComponent/index.es.js +127 -122
  116. package/dist/shapeDividerComponent/index.umd.js +25 -25
  117. package/dist/swiperComponent/index.cjs.js +9 -9
  118. package/dist/swiperComponent/index.es.js +197 -192
  119. package/dist/swiperComponent/index.umd.js +9 -9
  120. package/dist/tableComponent/index.cjs.js +1 -1
  121. package/dist/tableComponent/index.es.js +227 -222
  122. package/dist/tableComponent/index.umd.js +1 -1
  123. package/dist/types.d.ts +1 -1
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  126. package/dist/youtubeAssetProvider/index.es.js +124 -119
  127. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  128. package/package.json +5 -2
  129. package/dist/aiChat/components/AiChatInput.d.ts +0 -17
  130. package/dist/aiChat/server/stream-utils.d.ts +0 -16
@@ -1,15 +1,15 @@
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})=>`${o?"":`https://${t?m:g}`}/api`,k=()=>{const o=P()&&window.location.hostname;return!!o&&($.includes(o)||$.some(t=>o.endsWith(t)))};async function L({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const a=`${t||O({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const p=n?new URLSearchParams(n).toString():"",l=p?`?${p}`:"",u=await fetch(`${a}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.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 N(o){const t=o;return t.init=e=>s=>o(s,e),t}const T=o=>N(o);async function C({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=k(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),n()},p=(l={})=>{var h;const{error:u,sdkLicense:d}=l,f=(h=l.plan)==null?void 0:h.category;if(!(d||l.license)||u)c(u||"Invalid license");else if(f){const E=b[t],x=b[f];E>x&&c({pluginRequiredPlan:t,licensePlan:f})}};o.on(I,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),o.on(w,l=>{p(l)}),setTimeout(async()=>{if(!i){if(a)return;if(s){const l=await v({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function v(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await L({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 A=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:i}=t;(!i||r.includes(i))&&(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,i=(s==null?void 0:s.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const p=n??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
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) {
2
2
  const startIndex = parseInt(${n??0}, 10);
3
3
  const endIndex = startIndex + arr.length;
4
- const ${a}={ 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(A(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 i=t.slice(n+2,r).trim();if(s=r+2,i.startsWith("=")||i.startsWith("-")){const a=i.slice(1).trim();e.push(this.createAppendExpression(a))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const a=this.parseIfStatement(i,t,s);e.push(a),s=a.endPos||s}else if(i.startsWith("for")){const a=this.parseForStatement(i,t,s);e.push(a),s=a.endPos||s}else{const a=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(a){const c=a[1],p=a[2],l=this.parseForEachStatement(c,p,t,s);e.push(l),s=l.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${i}`)}}}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:i,endPos:a}=this.parseTemplateBlock(e,s);let c=null,p=a;const l=e.indexOf("<%",p);if(l===p){const u=e.indexOf("%>",l);if(u!==-1){const d=e.slice(l+2,u).trim(),f=u+2-l;if(d.startsWith("} else if")){p=l+f;const S=d.substring(d.indexOf("if")).trim(),h=this.parseIfStatement(S,e,p);c={type:"IfStatement",test:h.test,consequent:h.consequent,alternate:h.alternate},p=h.endPos}else if(d.startsWith("} else")){p=l+f;const{body:S,endPos:h}=this.parseTemplateBlock(e,p);c={type:"BlockStatement",body:S},p=h;const E=e.indexOf("<%",p),x=e.indexOf("%>",E);E===p&&e.slice(E+2,x).trim()==="}"&&(p=x+2)}else d==="}"&&(p=l+f)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:i},alternate:c,endPos:p}}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 i=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),a=r[1].trim(),{body:c,endPos:p}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:this.parseJsExpression(a)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const l=e.indexOf("<%",p),u=e.indexOf("%>",l);return l===p&&e.slice(l+2,u).trim()==="}"?u+2:p})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:i}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const a=s.indexOf("<%",i),c=s.indexOf("%>",a);return a===i&&s.slice(a+2,c).trim()==="}"?c+2:i})()}}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 i=t.indexOf("%>",r);if(i===-1)throw new Error("Unclosed EJS tag within block");const a=t.slice(r+2,i).trim();if(a==="}"||a.startsWith("} else")){n=r;break}if(n=i+2,a.startsWith("=")||a.startsWith("-")){const c=a.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const c=this.parseIfStatement(a,t,n);s.push(c),n=c.endPos||n}else if(a.startsWith("for")){const c=this.parseForStatement(a,t,n);s.push(c),n=c.endPos||n}else{const c=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const p=c[1],l=c[2],u=this.parseForEachStatement(p,l,t,n);s.push(u),n=u.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${a}`)}}}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,i,a=!1;if(n===e)r=t.slice(0,e),i={type:"Identifier",name:t.slice(e+1)},a=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const p=t.slice(s+1,c);i=/^(['"]).*\1$/.test(p)||/^-?\d+(\.\d+)?$/.test(p)?this.parseJsExpression(p):{type:"Identifier",name:p},a=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:i,computed:a}}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: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)),`
5
5
  <data-condition data-gjs-data-resolver='${JSON.stringify({condition:e})}'>
6
6
  <data-condition-true-content>${s}</data-condition-true-content>
7
7
  <data-condition-false-content>${n}</data-condition-false-content>
8
8
  </data-condition>
9
- `}handleForStatement(t){var a;if(((a=t.init)==null?void 0:a.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 i=this.astToGrapesJS(t.body);return this.collectionStack.pop(),`
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
10
  <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:s},collectionId:r})}'>
11
11
  <data-collection-item>
12
- ${i}
12
+ ${a}
13
13
  </data-collection-item>
14
14
  </data-collection>
15
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(),`
@@ -18,4 +18,4 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
18
18
  ${r}
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 i=t;const a=[];for(;i.type==="MemberExpression";)i.property.type==="Identifier"&&!i.computed?a.unshift(i.property.name):i.property.type==="Literal"&&i.computed?a.unshift(String(i.property.value)):a.unshift(this.getExpressionString(i.property)),i=i.object;if(i.type==="Identifier"&&i.name===r){const c=a.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 T(function(o,t={}){const e=M(o,new _),s=B(o,{contains:"<%",importer:new F});C({editor:o,licenseKey:t.licenseKey,plan:U,pluginName:D,cleanup:()=>{e(),s()}})})});
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()}})})});
@@ -1,10 +1,10 @@
1
- "use strict";const I=require("handlebars/dist/cjs/handlebars"),S="app.grapesjs.com",y="app-stage.grapesjs.com",C="app2.grapesjs.com",k="app-stage2.grapesjs.com",f=[S,C,y,k,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],v="license:check:start",N="license:check:end",_=()=>typeof window<"u",T=({isDev:a,isStage:t})=>`${a?"":`https://${t?y:S}`}/api`,L=()=>{const a=_()&&window.location.hostname;return!!a&&(f.includes(a)||f.some(t=>a.endsWith(t)))};async function w({path:a,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:i}){const o=`${t||T({isDev:!1,isStage:!1})}${a}`,c={method:e,headers:{"Content-Type":"application/json",...n}};i&&(c.body=JSON.stringify(i));const h=s?new URLSearchParams(s).toString():"",l=h?`?${h}`:"",u=await fetch(`${o}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}var p=(a=>(a.free="free",a.startup="startup",a.business="business",a.enterprise="enterprise",a))(p||{});const P={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function O(a){const t=a;return t.init=e=>n=>a(n,e),t}const A=a=>O(a);async function j({editor:a,plan:t,pluginName:e,licenseKey:n,cleanup:s}){let i="",r=!1;const o=L(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),s()},h=(l={})=>{var g;const{error:u,sdkLicense:b}=l,m=(g=l.plan)==null?void 0:g.category;if(!(b||l.license)||u)c(u||"Invalid license");else if(m){const x=P[t],E=P[m];x>E&&c({pluginRequiredPlan:t,licensePlan:m})}};a.on(v,l=>{i=l==null?void 0:l.baseApiUrl,r=!0}),a.on(N,l=>{h(l)}),setTimeout(async()=>{if(!r){if(o)return;if(n){const l=await D({licenseKey:n,pluginName:e,baseApiUrl:i});l&&h(l)}else c("The `licenseKey` option not provided")}},2e3)}async function D(a){const{licenseKey:t,pluginName:e,baseApiUrl:n}=a;try{return(await w({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 M=(a,t)=>(a.config.optsHtml={...a.config.optsHtml,exporter:t},()=>{a.config.optsHtml.exporter=void 0}),H=(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)}},$={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},R={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},U={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},B={...$,...R,...U};class W{getHelperId(t){return B[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 h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?i=` (slice ${s} ${h} ${l})`:i=` (slice ${s} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${i||s}${o}}}`}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,o=i.map(h=>this._parseCondition(h)).join(" ");return`{{#if ${i.length>1?`(${r} ${o})`:o}}}`}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(o=>this._parseCondition(o)).join(" ");return s.length>1?`(${i} ${r})`:r}else{const s=e.operator,i=this.getHelperId(s),r=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(i,r,o)}}getExpressionStr(t,e,n){return $[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 V{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return I.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("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,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("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,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),o=t.inverse?this.handleProgram(t.inverse):"";return`
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
2
  <data-condition data-gjs-data-resolver='${JSON.stringify({condition:i})}'>
3
3
  <data-condition-true-content>${r}</data-condition-true-content>
4
- <data-condition-false-content>${o}</data-condition-false-content>
4
+ <data-condition-false-content>${l}</data-condition-false-content>
5
5
  </data-condition>
6
- `}handleEachBlock(t){var i,r,o;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:(o=(r=t.program)==null?void 0:r.blockParams)!=null&&o.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(),`
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
7
  <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
8
8
  <data-collection-item>${s}</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,o,c,h)=>{const l=c!==void 0?c:h||"";return t[e]=l,`__HANDLEBARS_PLACEHOLDER_${e++}__`});n=n.replace(/\//g,".");const s=n.split("."),i=[];for(const r of s){const o=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);if(o){const c=parseInt(o[1],10);i.push(t[c])}else r!==""&&i.push(r)}return i},G="dataSourceHandlebars",q=p.startup,F=function(a,t={}){const e=M(a,new W),n=H(a,{contains:"{{",importer:new V});j({editor:a,licenseKey:t.licenseKey,plan:q,pluginName:G,cleanup:()=>{e(),n()}})},J=A(F);module.exports=J;
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;
@@ -1,9 +1,9 @@
1
- import I from "handlebars/dist/cjs/handlebars";
2
- const S = "app.grapesjs.com", y = "app-stage.grapesjs.com", C = "app2.grapesjs.com", k = "app-stage2.grapesjs.com", f = [
3
- S,
4
- C,
1
+ import v from "handlebars/dist/cjs/handlebars";
2
+ const y = "app.grapesjs.com", $ = "app-stage.grapesjs.com", C = "app2.grapesjs.com", N = "app-stage2.grapesjs.com", P = [
5
3
  y,
6
- k,
4
+ C,
5
+ $,
6
+ N,
7
7
  "localhost",
8
8
  "127.0.0.1",
9
9
  ".local-credentialless.webcontainer.io",
@@ -12,11 +12,15 @@ const S = "app.grapesjs.com", y = "app-stage.grapesjs.com", C = "app2.grapesjs.c
12
12
  // For stackblitz.com demos
13
13
  "-sandpack.codesandbox.io"
14
14
  // For Sandpack demos
15
- ], v = "license:check:start", N = "license:check:end", _ = () => typeof window < "u", T = ({ isDev: a, isStage: t }) => `${a ? "" : `https://${t ? y : S}`}/api`, L = () => {
16
- const a = _() && window.location.hostname;
17
- return !!a && (f.includes(a) || f.some((t) => a.endsWith(t)));
15
+ ], _ = "license:check:start", k = "license:check:end", T = () => typeof window < "u", w = ({
16
+ isDev: a,
17
+ isStage: t,
18
+ isPlatform: e
19
+ }) => `${a ? "" : `https://${t ? $ : y}`}/${e ? "platform-api" : "api"}`, O = () => {
20
+ const a = T() && window.location.hostname;
21
+ return !!a && (P.includes(a) || P.some((t) => a.endsWith(t)));
18
22
  };
19
- async function w({
23
+ async function A({
20
24
  path: a,
21
25
  baseApiUrl: t,
22
26
  method: e = "GET",
@@ -24,70 +28,71 @@ async function w({
24
28
  params: s,
25
29
  body: i
26
30
  }) {
27
- const o = `${t || T({ isDev: !1, isStage: !1 })}${a}`, c = {
31
+ const l = `${t || w({ isDev: !1, isStage: !1 })}${a}`, u = {
28
32
  method: e,
29
33
  headers: {
30
34
  "Content-Type": "application/json",
31
35
  ...n
32
36
  }
33
37
  };
34
- i && (c.body = JSON.stringify(i));
35
- const h = s ? new URLSearchParams(s).toString() : "", l = h ? `?${h}` : "", u = await fetch(`${o}${l}`, c);
36
- if (!u.ok)
37
- throw new Error(`HTTP error! status: ${u.status}`);
38
- return u.json();
38
+ i && (u.body = JSON.stringify(i));
39
+ const c = s ? new URLSearchParams(s).toString() : "", h = c ? `?${c}` : "", o = await fetch(`${l}${h}`, u);
40
+ if (!o.ok)
41
+ throw new Error(`HTTP error! status: ${o.status}`);
42
+ return o.json();
39
43
  }
40
44
  var p = /* @__PURE__ */ ((a) => (a.free = "free", a.startup = "startup", a.business = "business", a.enterprise = "enterprise", a))(p || {});
41
- const P = {
45
+ const S = {
42
46
  [p.free]: 0,
43
47
  [p.startup]: 10,
44
48
  [p.business]: 20,
45
49
  [p.enterprise]: 30
46
50
  };
47
- function O(a) {
51
+ function L(a) {
48
52
  const t = a;
49
53
  return t.init = (e) => (n) => a(n, e), t;
50
54
  }
51
- const A = (a) => /* @__PURE__ */ O(a);
52
- async function j({
55
+ const j = (a) => /* @__PURE__ */ L(a);
56
+ async function D({
53
57
  editor: a,
54
58
  plan: t,
55
59
  pluginName: e,
56
60
  licenseKey: n,
57
- cleanup: s
61
+ onLicenseCheckResponse: s,
62
+ cleanup: i
58
63
  }) {
59
- let i = "", r = !1;
60
- const o = L(), c = (l) => {
61
- console.warn("Cleanup plugin:", e, "Reason:", l), s();
62
- }, h = (l = {}) => {
63
- var g;
64
- const { error: u, sdkLicense: b } = l, m = (g = l.plan) == null ? void 0 : g.category;
65
- if (!(b || l.license) || u)
66
- c(u || "Invalid license");
64
+ let r = "", l = !1;
65
+ const u = O(), c = (o) => {
66
+ console.warn("Cleanup plugin:", e, "Reason:", o), i();
67
+ }, h = (o = {}) => {
68
+ var f;
69
+ const { error: g, sdkLicense: x } = o, m = (f = o.plan) == null ? void 0 : f.category;
70
+ if (!(x || o.license) || g)
71
+ c(g || "Invalid license");
67
72
  else if (m) {
68
- const x = P[t], E = P[m];
69
- x > E && c({ pluginRequiredPlan: t, licensePlan: m });
73
+ const E = S[t], I = S[m];
74
+ E > I && c({ pluginRequiredPlan: t, licensePlan: m });
70
75
  }
71
76
  };
72
- a.on(v, (l) => {
73
- i = l == null ? void 0 : l.baseApiUrl, r = !0;
74
- }), a.on(N, (l) => {
75
- h(l);
77
+ a.on(_, (o) => {
78
+ r = o == null ? void 0 : o.baseApiUrl, l = !0;
79
+ }), a.on(k, (o) => {
80
+ s == null || s(o), h(o);
76
81
  }), setTimeout(async () => {
77
- if (!r) {
78
- if (o) return;
82
+ if (!l) {
83
+ if (u) return;
79
84
  if (n) {
80
- const l = await D({ licenseKey: n, pluginName: e, baseApiUrl: i });
81
- l && h(l);
85
+ const o = await M({ licenseKey: n, pluginName: e, baseApiUrl: r });
86
+ s == null || s(o), o && h(o);
82
87
  } else
83
88
  c("The `licenseKey` option not provided");
84
89
  }
85
90
  }, 2e3);
86
91
  }
87
- async function D(a) {
92
+ async function M(a) {
88
93
  const { licenseKey: t, pluginName: e, baseApiUrl: n } = a;
89
94
  try {
90
- return (await w({
95
+ return (await A({
91
96
  baseApiUrl: n,
92
97
  path: `/sdk/${t || "na"}`,
93
98
  method: "POST",
@@ -100,12 +105,12 @@ async function D(a) {
100
105
  return console.error("Error during SDK license check:", s), !1;
101
106
  }
102
107
  }
103
- const M = (a, t) => (a.config.optsHtml = {
108
+ const H = (a, t) => (a.config.optsHtml = {
104
109
  ...a.config.optsHtml,
105
110
  exporter: t
106
111
  }, () => {
107
112
  a.config.optsHtml.exporter = void 0;
108
- }), H = (a, t) => {
113
+ }), U = (a, t) => {
109
114
  const e = (s) => {
110
115
  const { input: i } = s, { contains: r } = t;
111
116
  (!r || i.includes(r)) && (s.input = t.importer.import(i));
@@ -113,7 +118,7 @@ const M = (a, t) => (a.config.optsHtml = {
113
118
  return a.on(n, e), () => {
114
119
  a.off(n, e);
115
120
  };
116
- }, $ = {
121
+ }, b = {
117
122
  equals: "equals",
118
123
  isTruthy: "isTruthy",
119
124
  isFalsy: "isFalsy",
@@ -126,27 +131,27 @@ const M = (a, t) => (a.config.optsHtml = {
126
131
  isNumber: "isNumber",
127
132
  isBoolean: "isBoolean",
128
133
  isDefaultValue: "isDefaultValue"
129
- }, R = {
134
+ }, B = {
130
135
  ">": "numGt",
131
136
  "<": "numLt",
132
137
  ">=": "numGte",
133
138
  "<=": "numLte",
134
139
  "=": "numEq",
135
140
  "!=": "numNeq"
136
- }, U = {
141
+ }, W = {
137
142
  contains: "strContains",
138
143
  startsWith: "strStartsWith",
139
144
  endsWith: "strEndsWith",
140
145
  equalsIgnoreCase: "strEqualsIgnoreCase",
141
146
  trimEquals: "strTrimEquals"
142
- }, B = {
143
- ...$,
144
- ...R,
145
- ...U
147
+ }, V = {
148
+ ...b,
149
+ ...B,
150
+ ...W
146
151
  };
147
- class W {
152
+ class G {
148
153
  getHelperId(t) {
149
- return B[t] || t;
154
+ return V[t] || t;
150
155
  }
151
156
  getFullPath({ collectionId: t, path: e }) {
152
157
  let n = e;
@@ -160,11 +165,11 @@ class W {
160
165
  const { collectionId: e, dataSource: n } = t, s = n == null ? void 0 : n.path;
161
166
  let i = "";
162
167
  if (t.startIndex !== void 0 || t.endIndex !== void 0) {
163
- const h = t.startIndex ?? 0, l = t.endIndex !== void 0 ? t.endIndex : "";
164
- l !== "" ? i = ` (slice ${s} ${h} ${l})` : i = ` (slice ${s} ${h})`;
168
+ const c = t.startIndex ?? 0, h = t.endIndex !== void 0 ? t.endIndex : "";
169
+ h !== "" ? i = ` (slice ${s} ${c} ${h})` : i = ` (slice ${s} ${c})`;
165
170
  }
166
- const o = ` as |${this._sanitizeVariableName(e)}|`;
167
- return `{{#each ${i || s}${o}}}`;
171
+ const l = ` as |${this._sanitizeVariableName(e)}|`;
172
+ return `{{#each ${i || s}${l}}}`;
168
173
  }
169
174
  getCollectionEndSyntax() {
170
175
  return "{{/each}}";
@@ -174,8 +179,8 @@ class W {
174
179
  if (!e) return "";
175
180
  const n = e, s = e;
176
181
  if (s.statements && s.logicalOperator === "and" || s.logicalOperator === "or") {
177
- const { statements: i } = s, r = s.logicalOperator, o = i.map((h) => this._parseCondition(h)).join(" ");
178
- return `{{#if ${i.length > 1 ? `(${r} ${o})` : o}}}`;
182
+ const { statements: i } = s, r = s.logicalOperator, l = i.map((c) => this._parseCondition(c)).join(" ");
183
+ return `{{#if ${i.length > 1 ? `(${r} ${l})` : l}}}`;
179
184
  } else
180
185
  return `{{#if ${this._parseCondition(n)}}}`;
181
186
  }
@@ -183,15 +188,15 @@ class W {
183
188
  if (!t) return "";
184
189
  const e = t, n = t;
185
190
  if (n.statements && n.logicalOperator === "and" || n.logicalOperator === "or") {
186
- const { statements: s } = n, i = n.logicalOperator, r = n.statements.map((o) => this._parseCondition(o)).join(" ");
191
+ const { statements: s } = n, i = n.logicalOperator, r = n.statements.map((l) => this._parseCondition(l)).join(" ");
187
192
  return s.length > 1 ? `(${i} ${r})` : r;
188
193
  } else {
189
- const s = e.operator, i = this.getHelperId(s), r = this._parseValue(e.left), o = this._parseValue(e.right);
190
- return this.getExpressionStr(i, r, o);
194
+ const s = e.operator, i = this.getHelperId(s), r = this._parseValue(e.left), l = this._parseValue(e.right);
195
+ return this.getExpressionStr(i, r, l);
191
196
  }
192
197
  }
193
198
  getExpressionStr(t, e, n) {
194
- return $[t] ? t === "isTruthy" ? e : t === "isFalsy" ? `!${e}` : `${t} ${e}` : `(${t} ${e} ${n})`;
199
+ return b[t] ? t === "isTruthy" ? e : t === "isFalsy" ? `!${e}` : `${t} ${e}` : `(${t} ${e} ${n})`;
195
200
  }
196
201
  _parseValue(t) {
197
202
  return typeof t == "object" ? this.getFullPath(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
@@ -206,7 +211,7 @@ class W {
206
211
  return "{{/if}}";
207
212
  }
208
213
  }
209
- class V {
214
+ class q {
210
215
  constructor() {
211
216
  this.messages = [], this.collectionStack = [];
212
217
  }
@@ -217,7 +222,7 @@ class V {
217
222
  }
218
223
  parse(t) {
219
224
  try {
220
- return I.parse(t);
225
+ return v.parse(t);
221
226
  } catch (e) {
222
227
  if (e instanceof Error && e.message.includes("Parse error")) {
223
228
  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;
@@ -290,8 +295,8 @@ class V {
290
295
  n.collectionId = t, n.variableType = "currentItem", e && (n.path = e);
291
296
  }
292
297
  handleRelativePathReference(t, e) {
293
- const n = d(t), { parentLevel: s, remainingPathParts: i } = this.calculateParentLevel(n), r = i.join("."), o = this.collectionStack.length - 1 - s;
294
- o >= 0 && o < this.collectionStack.length ? this.resolveRelativePath(r, o, e) : e.path = i.join(".");
298
+ const n = d(t), { parentLevel: s, remainingPathParts: i } = this.calculateParentLevel(n), r = i.join("."), l = this.collectionStack.length - 1 - s;
299
+ l >= 0 && l < this.collectionStack.length ? this.resolveRelativePath(r, l, e) : e.path = i.join(".");
295
300
  }
296
301
  calculateParentLevel(t) {
297
302
  const e = this.collectionStack.findLastIndex((i) => i === t[0]);
@@ -308,8 +313,8 @@ class V {
308
313
  n.collectionId = s, n.variableType = "currentItem", t !== "this" && (n.path = t.startsWith("this.") ? t.split(".").slice(1).join(".") : t);
309
314
  }
310
315
  handleParentReferenceFallback(t, e) {
311
- const n = d(t), { parentLevel: s, remainingPathParts: i } = this.calculateParentLevel(n), r = i.join("."), o = this.collectionStack.length - 1 - s;
312
- o >= 0 && o < this.collectionStack.length ? this.resolveRelativePath(r, o, e) : e.path = i.join(".");
316
+ const n = d(t), { parentLevel: s, remainingPathParts: i } = this.calculateParentLevel(n), r = i.join("."), l = this.collectionStack.length - 1 - s;
317
+ l >= 0 && l < this.collectionStack.length ? this.resolveRelativePath(r, l, e) : e.path = i.join(".");
313
318
  }
314
319
  handleBlockStatement(t) {
315
320
  const e = t.path.original;
@@ -332,19 +337,19 @@ class V {
332
337
  operator: e === "unless" ? "isFalsy" : "isTruthy"
333
338
  }
334
339
  ]
335
- }, r = this.handleProgram(t.program), o = t.inverse ? this.handleProgram(t.inverse) : "";
340
+ }, r = this.handleProgram(t.program), l = t.inverse ? this.handleProgram(t.inverse) : "";
336
341
  return `
337
342
  <data-condition data-gjs-data-resolver='${JSON.stringify({ condition: i })}'>
338
343
  <data-condition-true-content>${r}</data-condition-true-content>
339
- <data-condition-false-content>${o}</data-condition-false-content>
344
+ <data-condition-false-content>${l}</data-condition-false-content>
340
345
  </data-condition>
341
346
  `;
342
347
  }
343
348
  handleEachBlock(t) {
344
- var i, r, o;
349
+ var i, r, l;
345
350
  const e = this.getExpressionString(t.params[0]);
346
351
  let n;
347
- t.params.length >= 3 && t.params[1] === "as" && ((i = t.params[2]) == null ? void 0 : i.type) === "PathExpression" ? n = t.params[2].original : (o = (r = t.program) == null ? void 0 : r.blockParams) != null && o.length ? n = t.program.blockParams[0] : n = `collection-${Math.random().toString(36).substring(2, 10)}`, this.collectionStack.push(n);
352
+ 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);
348
353
  const s = this.handleProgram(t.program);
349
354
  return this.collectionStack.pop(), `
350
355
  <data-collection data-gjs-data-resolver='${JSON.stringify({
@@ -404,36 +409,36 @@ const d = (a) => {
404
409
  const t = [];
405
410
  let e = 0, n = a.replace(
406
411
  /\[(?:(['"])(.*?)\1|([^\]]*))\]/g,
407
- (r, o, c, h) => {
408
- const l = c !== void 0 ? c : h || "";
409
- return t[e] = l, `__HANDLEBARS_PLACEHOLDER_${e++}__`;
412
+ (r, l, u, c) => {
413
+ const h = u !== void 0 ? u : c || "";
414
+ return t[e] = h, `__HANDLEBARS_PLACEHOLDER_${e++}__`;
410
415
  }
411
416
  );
412
417
  n = n.replace(/\//g, ".");
413
418
  const s = n.split("."), i = [];
414
419
  for (const r of s) {
415
- const o = /^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);
416
- if (o) {
417
- const c = parseInt(o[1], 10);
418
- i.push(t[c]);
420
+ const l = /^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);
421
+ if (l) {
422
+ const u = parseInt(l[1], 10);
423
+ i.push(t[u]);
419
424
  } else r !== "" && i.push(r);
420
425
  }
421
426
  return i;
422
- }, G = "dataSourceHandlebars", q = p.startup, F = function(a, t = {}) {
423
- const e = M(a, new W()), n = H(a, {
427
+ }, F = "dataSourceHandlebars", R = p.startup, J = function(a, t = {}) {
428
+ const e = H(a, new G()), n = U(a, {
424
429
  contains: "{{",
425
- importer: new V()
430
+ importer: new q()
426
431
  });
427
- j({
432
+ D({
428
433
  editor: a,
429
434
  licenseKey: t.licenseKey,
430
- plan: q,
431
- pluginName: G,
435
+ plan: R,
436
+ pluginName: F,
432
437
  cleanup: () => {
433
438
  e(), n();
434
439
  }
435
440
  });
436
- }, z = A(F);
441
+ }, Y = j(J);
437
442
  export {
438
- z as default
443
+ Y as default
439
444
  };