@grapesjs/studio-sdk-plugins 1.0.22 → 1.0.23

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.
@@ -1,20 +1,20 @@
1
- (function(h,d){typeof exports=="object"&&typeof module<"u"?module.exports=d(require("handlebars/dist/cjs/handlebars")):typeof define=="function"&&define.amd?define(["handlebars/dist/cjs/handlebars"],d):(h=typeof globalThis<"u"?globalThis:h||self,h.StudioSdkPlugins_dataSourceHandlebars=d(h.Handlebars))})(this,function(h){"use strict";const d="app.grapesjs.com",$="app-stage.grapesjs.com",b=[d,$,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],E="license:check:start",v="license:check:end",I=()=>typeof window<"u",P=({isDev:s,isStage:t})=>`${s?"":`https://${t?$:d}`}/api`,T=()=>{const s=I()&&window.location.hostname;return!!s&&(b.includes(s)||b.some(t=>s.endsWith(t)))};async function k({path:s,baseApiUrl:t,method:n="GET",headers:e={},params:a,body:r}){const o=`${t||P({isDev:!1,isStage:!1})}${s}`,u={method:n,headers:{"Content-Type":"application/json",...e}};r&&(u.body=JSON.stringify(r));const l=a?new URLSearchParams(a).toString():"",c=l?`?${l}`:"",g=await fetch(`${o}${c}`,u);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}var p=(s=>(s.free="free",s.startup="startup",s.business="business",s.enterprise="enterprise",s))(p||{});const x={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function L(s){const t=s;return t.init=n=>e=>s(e,n),t}const w=s=>L(s);async function N({editor:s,plan:t,pluginName:n,licenseKey:e,cleanup:a}){let r="",i=!1;const o=T(),u=c=>{console.warn("Cleanup plugin:",n,"Reason:",c),a()},l=(c={})=>{var C;const{error:g,sdkLicense:W}=c,y=(C=c.plan)==null?void 0:C.category;if(!(W||c.license)||g)u(g||"Invalid license");else if(y){const A=x[t],G=x[y];A>G&&u({pluginRequiredPlan:t,licensePlan:y})}};s.on(E,c=>{r=c==null?void 0:c.baseApiUrl,i=!0}),s.on(v,c=>{l(c)}),setTimeout(async()=>{if(!i){if(o)return;if(e){const c=await H({licenseKey:e,pluginName:n,baseApiUrl:r});c&&l(c)}else u("The `licenseKey` option not provided")}},2e3)}async function H(s){const{licenseKey:t,pluginName:n,baseApiUrl:e}=s;try{return(await k({baseApiUrl:e,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}var m=(s=>(s.variable="data-variable",s.condition="data-condition",s.conditionTrue="data-condition-true-content",s.conditionFalse="data-condition-false-content",s.collection="data-collection",s.collectionItem="data-collection-item",s))(m||{});class M{constructor(t){this.strategy=t,this.requiredHelpers=new Set,this.helperLibrary={}}registerHelper(t){this.helperLibrary[t]&&this.requiredHelpers.add(t)}generateVariable(t){return this.strategy.getVariableSyntax(t)}generateCollectionStart(t){return this.registerHelper("slice"),this.strategy.getCollectionStartSyntax(t)}generateCollectionEnd(){return this.strategy.getCollectionEndSyntax()}generateConditionalStart(t){return this.strategy.getConditionalStartSyntax(t)}generateConditionElse(){return this.strategy.getConditionElseSyntax()}generateConditionalEnd(){return this.strategy.getConditionalEndSyntax()}reset(){this.requiredHelpers.clear()}}function _(s){return typeof s=="object"&&s.type===m.variable}function f({component:s,value:t,getCustomPath:n}){if(_(t)&&!t.collectionId&&n){const e=t.path??"",a=e.split(".");return{...t,path:n({component:s,path:e,paths:a})}}return t}const j=s=>{S(s,m.variable,{toHTML(t){var i;const n=this.tagName,e=this.__attrToString(t),a=(i=this.getDataResolver)==null?void 0:i.call(this),r=f({component:this,value:a,getCustomPath:t==null?void 0:t.getCustomPath});return`<${n}${e?` ${e}`:""}>${t.exporter.generateVariable(r)}</${n}>`}}),S(s,m.condition,{toHTML(t){var l,c;const n=t.exporter,e=t==null?void 0:t.getCustomPath,a=this.components(),[r,i]=(a==null?void 0:a.models)??[],o=(l=this.getDataResolver)==null?void 0:l.call(this),u=((c=this.resolveCondition)==null?void 0:c.call(this,o==null?void 0:o.condition,e))??{};return`
2
- ${n.generateConditionalStart(u)}
3
- ${(r==null?void 0:r.toHTML(t))??""}
4
- ${n.generateConditionElse()}
5
- ${(i==null?void 0:i.toHTML(t))??""}
6
- ${n.generateConditionalEnd()}
7
- `},resolveCondition(t,n){var a,r;if(!t)return{};if(t.operator==="and"||t.operator==="or")return{operator:t.operator,statements:((r=(a=t.statements)==null?void 0:a.map)==null?void 0:r.call(a,i=>{var o;return((o=this.resolveCondition)==null?void 0:o.call(this,i,n))??{}}))??[]};const e={component:this,getCustomPath:n};return{...t,left:f({...e,value:t.left}),right:f({...e,value:t.right})}}}),S(s,m.collection,{toHTML(t){const n=t.exporter,e=this.tagName,a=this.__attrToString(t),r=this.getDataResolver(),i={...r,dataSource:f({component:this,value:r==null?void 0:r.dataSource,getCustomPath:t==null?void 0:t.getCustomPath})},o=this.components().at(0);return`
8
- <${e}${a?` ${a}`:""}>${n.generateCollectionStart(i)}
1
+ (function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("handlebars/dist/cjs/handlebars")):typeof define=="function"&&define.amd?define(["handlebars/dist/cjs/handlebars"],p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_dataSourceHandlebars=p(d.Handlebars))})(this,function(d){"use strict";const p="app.grapesjs.com",P="app-stage.grapesjs.com",b=[p,P,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],v="license:check:start",I="license:check:end",T=()=>typeof window<"u",k=({isDev:s,isStage:t})=>`${s?"":`https://${t?P:p}`}/api`,L=()=>{const s=T()&&window.location.hostname;return!!s&&(b.includes(s)||b.some(t=>s.endsWith(t)))};async function N({path:s,baseApiUrl:t,method:e="GET",headers:n={},params:a,body:r}){const o=`${t||k({isDev:!1,isStage:!1})}${s}`,c={method:e,headers:{"Content-Type":"application/json",...n}};r&&(c.body=JSON.stringify(r));const h=a?new URLSearchParams(a).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 g=(s=>(s.free="free",s.startup="startup",s.business="business",s.enterprise="enterprise",s))(g||{});const x={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function _(s){const t=s;return t.init=e=>n=>s(n,e),t}const H=s=>_(s);async function w({editor:s,plan:t,pluginName:e,licenseKey:n,cleanup:a}){let r="",i=!1;const o=L(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),a()},h=(l={})=>{var E;const{error:u,sdkLicense:G}=l,$=(E=l.plan)==null?void 0:E.category;if(!(G||l.license)||u)c(u||"Invalid license");else if($){const F=x[t],J=x[$];F>J&&c({pluginRequiredPlan:t,licensePlan:$})}};s.on(v,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),s.on(I,l=>{h(l)}),setTimeout(async()=>{if(!i){if(o)return;if(n){const l=await O({licenseKey:n,pluginName:e,baseApiUrl:r});l&&h(l)}else c("The `licenseKey` option not provided")}},2e3)}async function O(s){const{licenseKey:t,pluginName:e,baseApiUrl:n}=s;try{return(await N({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}var m=(s=>(s.variable="data-variable",s.condition="data-condition",s.conditionTrue="data-condition-true-content",s.conditionFalse="data-condition-false-content",s.collection="data-collection",s.collectionItem="data-collection-item",s))(m||{});class M{constructor(t){this.strategy=t,this.requiredHelpers=new Set,this.helperLibrary={}}registerHelper(t){this.helperLibrary[t]&&this.requiredHelpers.add(t)}generateVariable(t){return this.strategy.getVariableSyntax(t)}generateCollectionStart(t){return this.registerHelper("slice"),this.strategy.getCollectionStartSyntax(t)}generateCollectionEnd(){return this.strategy.getCollectionEndSyntax()}generateConditionalStart(t){return this.strategy.getConditionalStartSyntax(t)}generateConditionElse(){return this.strategy.getConditionElseSyntax()}generateConditionalEnd(){return this.strategy.getConditionalEndSyntax()}reset(){this.requiredHelpers.clear()}}function R(s){return typeof s=="object"&&s.type===m.variable}function f({component:s,value:t,getCustomPath:e}){if(R(t)&&!t.collectionId&&e){const n=t.path??"",a=n.split(".");return{...t,path:e({component:s,path:n,paths:a})}}return t}const A=s=>{S(s,m.variable,{toHTML(t){var i;const e=this.tagName,n=this.__attrToString(t),a=(i=this.getDataResolver)==null?void 0:i.call(this),r=f({component:this,value:a,getCustomPath:t==null?void 0:t.getCustomPath});return`<${e}${n?` ${n}`:""}>${t.exporter.generateVariable(r)}</${e}>`}}),S(s,m.condition,{toHTML(t){var l,u;const e=t.exporter,n=t==null?void 0:t.getCustomPath,a=this.components(),[r,i]=(a==null?void 0:a.models)??[],o=(l=this.getDataResolver)==null?void 0:l.call(this),c=((u=this.resolveCondition)==null?void 0:u.call(this,o==null?void 0:o.condition,n))??{};let h="";return i&&(h=`
2
+ ${e.generateConditionElse()}
3
+ ${i.toHTML(t)??""}`),`
4
+ ${e.generateConditionalStart(c)}
5
+ ${(r==null?void 0:r.toHTML(t))??""}${h}
6
+ ${e.generateConditionalEnd()}
7
+ `},resolveCondition(t,e){var a,r;if(!t)return{};if(t.operator==="and"||t.operator==="or")return{operator:t.operator,statements:((r=(a=t.statements)==null?void 0:a.map)==null?void 0:r.call(a,i=>{var o;return((o=this.resolveCondition)==null?void 0:o.call(this,i,e))??{}}))??[]};const n={component:this,getCustomPath:e};return{...t,left:f({...n,value:t.left}),right:f({...n,value:t.right})}}}),S(s,m.collection,{toHTML(t){const e=t.exporter,n=this.tagName,a=this.__attrToString(t),r=this.getDataResolver(),i={...r,dataSource:f({component:this,value:r==null?void 0:r.dataSource,getCustomPath:t==null?void 0:t.getCustomPath})},o=this.components().at(0);return`
8
+ <${n}${a?` ${a}`:""}>${e.generateCollectionStart(i)}
9
9
  ${(o==null?void 0:o.toHTML(t))??""}
10
- ${n.generateCollectionEnd()}</${e}>
11
- `}})},S=(s,t,n)=>{const e=s.Components.getType(t);if(!e){console.warn(`Component type ${t} not found`);return}const{model:a}=e;s.Components.addType(t,{model:{...n,toHTML(r={}){var o;const{exporter:i}=r;return i?i.export?i.export({component:this}):((o=n.toHTML)==null?void 0:o.call(this,r))??"":a.prototype.toHTML.call(this,r)??""}}})},B=(s,t)=>(s.config.optsHtml={...s.config.optsHtml,exporter:new M(t)},j(s),()=>{s.config.optsHtml.exporter=void 0}),O=(s,t)=>{const n=a=>{const{input:r}=a,{contains:i}=t;(!i||r.includes(i))&&(a.input=t.importer.import(r))},e=s.Parser.events.htmlBefore;return s.on(e,n),()=>{s.off(e,n)}};class D{getHelperId(t,n){return{equals:`${n==="string"?"str":n==="number"?"num":"any"}Equals`,isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue",">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq",contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"}[t]||t}getFullPath({collectionId:t,path:n}){let e=n;return t&&(e=[this._sanitizeVariableName(t),n].filter(Boolean).join(".")),e||""}getVariableSyntax(t){const{defaultValue:n}=t,e=this.getFullPath(t);return n?`{{#if ${e}}}{{{${e}}}}{{else}}${n}{{/if}}`:`{{{${e}}}}`}getCollectionStartSyntax(t){const{collectionId:n,dataSource:e}=t,a=e==null?void 0:e.path;let r="";if(t.startIndex!==void 0||t.endIndex!==void 0){const l=t.startIndex??0,c=t.endIndex!==void 0?t.endIndex:"";c!==""?r=` (slice ${a} ${l} ${c})`:r=` (slice ${a} ${l})`}const o=` as |${this._sanitizeVariableName(n)}|`;return`{{#each ${r||a}${o}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax(t){if(!t)return"";const n=t,e=t;if(e.statements&&e.logicalOperator==="and"||e.logicalOperator==="or"){const{statements:a}=e,r=e.logicalOperator,i=a.map(u=>this._parseCondition(u)).join(", ");return`{{#if ${a.length>1?`(${r} ${i})`:i}}}`}else return`{{#if ${this._parseCondition(n)}}}`}_parseCondition(t){if(!t)return"";const n=t,e=t;if(e.statements&&e.logicalOperator==="and"||e.logicalOperator==="or"){const{statements:a}=e,r=e.logicalOperator,i=e.statements.map(o=>this._parseCondition(o)).join(" ");return a.length>1?`(${r} ${i})`:i}else{const a=this.getHelperId(n.operator,this._getTypeHint(t)),r=this._parseValue(n.left),i=this._parseValue(n.right);return`(${a} ${r} ${i})`}}_getTypeHint(t){return["contains","startsWith","endsWith","equalsIgnoreCase","trimEquals"].includes(t.operator)?"string":[">","<",">=","<=","=","!="].includes(t.operator)?"number":"any"}_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 n=this.parse(t);return this.astToGrapesJS(n)}parse(t){try{return h.parse(t)}catch(n){if(n instanceof Error&&n.message.includes("Parse error")){const e=n.message.match(/line (\d+)/),a=e?parseInt(e[1]):0,r=n.message.match(/column (\d+)/),i=r?parseInt(r[1]):0;throw new Error(`Handlebars syntax error at line ${a}, column ${i}: ${n.message}`)}throw n}}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 n="";if(t.body)for(const e of t.body)n+=this.astToGrapesJS(e);return n}handleContentStatement(t){return t.value||""}handleMustacheStatement(t,n={}){const e=this.getExpressionString(t.path),a=n;if(this.collectionStack.length>0)if(e.startsWith("@")){const r=e.split("/");let i=0;const o=r[r.length-1];for(let l=0;l<r.length-1;l++)r[l]===".."&&i++;const u=Math.max(0,this.collectionStack.length-1-i);if(u>=0&&u<this.collectionStack.length){const l=this.collectionStack[u];o==="index"||o==="@index"?(a.collectionId=l,a.variableType="currentIndex"):o==="key"||o==="@key"?(a.collectionId=l,a.variableType="currentKey"):o==="first"||o==="@first"?(a.collectionId=l,a.variableType="isFirst"):o==="last"||o==="@last"?(a.collectionId=l,a.variableType="isLast"):a.path=e}else a.path=e}else{const r=e.split("/");let i=0;for(;r[0]==="..";)i++,r.shift();const o=r.join("/"),u=this.collectionStack.length-1-i;if(u>=0&&u<this.collectionStack.length){const l=this.collectionStack[u];o==="this"?(a.collectionId=l,a.variableType="currentItem"):(a.collectionId=l,a.variableType="currentItem",a.path=o.startsWith("this.")?o.split(".").slice(1).join("."):o)}else a.path=`globalData.${r.join(".")}`}else a.path=e;return`<data-variable data-gjs-data-resolver='${JSON.stringify(a)}'></data-variable>`}handleBlockStatement(t){const n=t.path.original;switch(n){case"if":case"unless":return this.handleConditionalBlock(t,n);case"each":return this.handleEachBlock(t);default:return this.addMessage("warning",`Unsupported block helper: ${n}`,t.loc),this.handleGenericBlock(t)}}handleConditionalBlock(t,n){const r={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:n==="unless"?"isFalsy":"isTruthy"}]},i=this.handleProgram(t.program),o=t.inverse?this.handleProgram(t.inverse):"";return t.params[0].type==="PathExpression"?this.handleMustacheStatement(t.program.body[0],{defaultValue:o}):`
10
+ ${e.generateCollectionEnd()}</${n}>
11
+ `}})},S=(s,t,e)=>{const n=s.Components.getType(t);if(!n){console.warn(`Component type ${t} not found`);return}const{model:a}=n;s.Components.addType(t,{model:{...e,toHTML(r={}){var o;const{exporter:i}=r;return i?i.export?i.export({component:this}):((o=e.toHTML)==null?void 0:o.call(this,r))??"":a.prototype.toHTML.call(this,r)??""}}})},j=(s,t)=>(s.config.optsHtml={...s.config.optsHtml,exporter:new M(t)},A(s),()=>{s.config.optsHtml.exporter=void 0}),D=(s,t)=>{const e=a=>{const{input:r}=a,{contains:i}=t;(!i||r.includes(i))&&(a.input=t.importer.import(r))},n=s.Parser.events.htmlBefore;return s.on(n,e),()=>{s.off(n,e)}},C={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={...C,...{">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},...{contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"}};class U{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(t){const{defaultValue:e}=t,n=this.getFullPath(t);return e?`{{#if ${n}}}{{{${n}}}}{{else}}${e}{{/if}}`:`{{{${n}}}}`}getCollectionStartSyntax(t){const{collectionId:e,dataSource:n}=t,a=n==null?void 0:n.path;let r="";if(t.startIndex!==void 0||t.endIndex!==void 0){const h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?r=` (slice ${a} ${h} ${l})`:r=` (slice ${a} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${r||a}${o}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax(t){if(!t)return"";const e=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:a}=n,r=n.logicalOperator,i=a.map(c=>this._parseCondition(c)).join(" ");return`{{#if ${a.length>1?`(${r} ${i})`:i}}}`}else return`{{#if ${this._parseCondition(e)}}}`}_parseCondition(t){if(!t)return"";const e=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:a}=n,r=n.logicalOperator,i=n.statements.map(o=>this._parseCondition(o)).join(" ");return a.length>1?`(${r} ${i})`:i}else{const a=e.operator,r=this.getHelperId(a),i=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(r,i,o)}}getExpressionStr(t,e,n){return C[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 d.parse(t)}catch(e){if(e instanceof Error&&e.message.includes("Parse error")){const n=e.message.match(/line (\d+)/),a=n?parseInt(n[1]):0,r=e.message.match(/column (\d+)/),i=r?parseInt(r[1]):0;throw new Error(`Handlebars syntax error at line ${a}, column ${i}: ${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),a={...e};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,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,...a]=t.substring(1).split("/"),r=a.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,r,e):this.handleParentReferenceFallback(t,e)}isSpecialIterationVariable(t){return["index","@index","key","@key"].includes(t)}setSpecialVariableResolver(t,e,n){n.collectionId=t;const a={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};n.variableType=a[e]}setCurrentItemResolver(t,e,n){n.collectionId=t,n.variableType="currentItem",e&&(n.path=e)}handleRelativePathReference(t,e){const n=y(t),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(n),i=r.join("."),o=this.collectionStack.length-1-a;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(i,o,e):e.path=r.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(r=>r===t[0]);if(e!==-1)return{parentLevel:this.collectionStack.length-1-e,remainingPathParts:t.slice(1)};let n=0;const a=[...t];for(;a[0]==="..";)n++,a.shift();return{parentLevel:n,remainingPathParts:a}}resolveRelativePath(t,e,n){const a=this.collectionStack[e];n.collectionId=a,n.variableType="currentItem",t!=="this"&&(n.path=t.startsWith("this.")?t.split(".").slice(1).join("."):t)}handleParentReferenceFallback(t,e){const n=y(t),{parentLevel:a,remainingPathParts:r}=this.calculateParentLevel(n),i=r.join("."),o=this.collectionStack.length-1-a;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(i,o,e):e.path=r.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 r={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:e==="unless"?"isFalsy":"isTruthy"}]},i=this.handleProgram(t.program),o=t.inverse?this.handleProgram(t.inverse):"";return`
12
12
  <data-condition data-gjs-data-resolver='${JSON.stringify({condition:r})}'>
13
13
  <data-condition-true-content>${i}</data-condition-true-content>
14
14
  <data-condition-false-content>${o}</data-condition-false-content>
15
15
  </data-condition>
16
- `}handleEachBlock(t){const n=this.getExpressionString(t.params[0]),e=`collection-${Math.random().toString(36).substring(2,10)}`;this.collectionStack.push(e);const a=this.handleProgram(t.program);return this.collectionStack.pop(),`
17
- <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:n},collectionId:e})}'>
16
+ `}handleEachBlock(t){var r,i,o;const e=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:(o=(i=t.program)==null?void 0:i.blockParams)!=null&&o.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(),`
17
+ <data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
18
18
  <data-collection-item>${a}</data-collection-item>
19
19
  </data-collection>
20
- `}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let n="";if(t.attributes)for(const a of t.attributes)a.value.type==="TextNode"?n+=` ${a.name}="${a.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${a.name}`,t.loc),n+=` ${a.name}="${this.getExpressionString(a.value)}"`);let e="";if(t.children)for(const a of t.children)e+=this.astToGrapesJS(a);return`<${t.tag}${n}>${e}</${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 n=this.handleProgram(t.program);return`<!-- Unsupported block: ${t.path.original} -->${n}`}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(e=>`${e.key}=${this.getExpressionString(e.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${t.type}`,t.loc),"")}addMessage(t,n,e){this.messages.push({type:t,message:n,location:e?{line:e.start.line,column:e.start.column}:void 0})}}const q="dataSourceHandlebars",U=p.startup;return w(function(s,t={}){const n=B(s,new D),e=O(s,{contains:"{{",importer:new V});N({editor:s,licenseKey:t.licenseKey,plan:U,pluginName:q,cleanup:()=>{n(),e()}})})});
20
+ `}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let e="";if(t.attributes)for(const a of t.attributes)a.value.type==="TextNode"?e+=` ${a.name}="${a.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${a.name}`,t.loc),e+=` ${a.name}="${this.getExpressionString(a.value)}"`);let n="";if(t.children)for(const a of t.children)n+=this.astToGrapesJS(a);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 y=s=>{if(s==null||s==="")return[];if(s===".")return["this"];if(s===".."||s==="../")return[".."];if(s.startsWith("../")){const i=s.substring(3);return["..",...y(i)]}const t=[];let e=0,n=s.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(i,o,c,h)=>{const l=c!==void 0?c:h||"";return t[e]=l,`__HANDLEBARS_PLACEHOLDER_${e++}__`});n=n.replace(/\//g,".");const a=n.split("."),r=[];for(const i of a){const o=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(i);if(o){const c=parseInt(o[1],10);r.push(t[c])}else i!==""&&r.push(i)}return r},W="dataSourceHandlebars",q=g.startup;return H(function(s,t={}){const e=j(s,new U),n=D(s,{contains:"{{",importer:new V});w({editor:s,licenseKey:t.licenseKey,plan:q,pluginName:W,cleanup:()=>{e(),n()}})})});