@grapesjs/studio-sdk-plugins 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animationComponent/index.es.js +0 -4
- package/dist/canvasFullSize/index.cjs.js +9 -9
- package/dist/canvasFullSize/index.es.js +156 -136
- package/dist/canvasFullSize/index.umd.js +9 -9
- package/dist/canvasFullSize/utils.d.ts +8 -0
- package/dist/dataSourceEjs/EjsExporter.d.ts +11 -4
- package/dist/dataSourceEjs/index.cjs.js +10 -20
- package/dist/dataSourceEjs/index.es.js +179 -302
- package/dist/dataSourceEjs/index.umd.js +10 -20
- package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +11 -4
- package/dist/dataSourceHandlebars/index.cjs.js +6 -16
- package/dist/dataSourceHandlebars/index.es.js +141 -263
- package/dist/dataSourceHandlebars/index.umd.js +6 -16
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +1 -1
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/index.cjs.js +50 -60
- package/dist/index.es.js +2263 -2370
- package/dist/index.umd.js +57 -67
- package/dist/rendererReact/types.d.ts +1 -2
- package/dist/utilsDataSources.d.ts +4 -24
- package/package.json +2 -2
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
(function(g,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(g=typeof globalThis<"u"?globalThis:g||self,g.StudioSdkPlugins_dataSourceEjs=m())})(this,function(){"use strict";const g="app.grapesjs.com",m="app-stage.grapesjs.com"
|
|
2
|
-
${
|
|
3
|
-
${i.toHTML(t)??""}`),`
|
|
4
|
-
${e.generateConditionalStart(c)}
|
|
5
|
-
${(r==null?void 0:r.toHTML(t))??""}${p}
|
|
6
|
-
${e.generateConditionalEnd()}
|
|
7
|
-
`},resolveCondition(t,e){var s,r;if(!t)return{};if(t.operator==="and"||t.operator==="or")return{operator:t.operator,statements:((r=(s=t.statements)==null?void 0:s.map)==null?void 0:r.call(s,i=>{var a;return((a=this.resolveCondition)==null?void 0:a.call(this,i,e))??{}}))??[]};const n={component:this,getCustomPath:e};return{...t,left:x({...n,value:t.left}),right:x({...n,value:t.right})}}}),I(o,E.collection,{toHTML(t){const e=t.exporter,n=this.tagName,s=this.__attrToString(t),r=this.getDataResolver(),i={...r,dataSource:x({component:this,value:r==null?void 0:r.dataSource,getCustomPath:t==null?void 0:t.getCustomPath})},a=this.components().at(0);return`
|
|
8
|
-
<${n}${s?` ${s}`:""}>${e.generateCollectionStart(i)}
|
|
9
|
-
${(a==null?void 0:a.toHTML(t))??""}
|
|
10
|
-
${e.generateCollectionEnd()}</${n}>
|
|
11
|
-
`}})},I=(o,t,e)=>{const n=o.Components.getType(t);if(!n){console.warn(`Component type ${t} not found`);return}const{model:s}=n;o.Components.addType(t,{model:{...e,toHTML(r={}){var a;const{exporter:i}=r;return i?i.export?i.export({component:this}):((a=e.toHTML)==null?void 0:a.call(this,r))??"":s.prototype.toHTML.call(this,r)??""}}})},J=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},F=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:new j(t)},A(o),()=>{o.config.optsHtml.exporter=void 0}),H=(o,t)=>{const e=s=>{const{input:r}=s,{contains:i}=t;(!i||r.includes(i))&&(s.input=t.importer.import(r))},n=o.Parser.events.htmlBefore;return o.on(n,e),()=>{o.off(n,e)}};class U{getVariableSyntax(t){const{defaultValue:e}=t,n=this.getFullPath(t),s=e?` || \`${e}\``:"";return`<%= ${n}${s} %>`}getCollectionStartSyntax(t){const{collectionId:e,dataSource:n,startIndex:s,endIndex:r}=t,i=(n==null?void 0:n.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(s!==void 0||r!==void 0){const p=s??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
|
|
12
|
-
const startIndex = parseInt(${s??0}, 10);
|
|
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,m,"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",k=({isDev:o,isStage:t})=>`${o?"":`https://${t?m:g}`}/api`,O=()=>{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||k({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 C(o){const t=o;return t.init=e=>s=>o(s,e),t}const T=o=>C(o);async function v({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=O(),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 N({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function N(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 B=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},j=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),M=(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 W{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) {
|
|
2
|
+
const startIndex = parseInt(${n??0}, 10);
|
|
13
3
|
const endIndex = startIndex + arr.length;
|
|
14
|
-
const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax(t){return`<% if (${this._parseCondition(t)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:
|
|
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(B(t)){const e=t.statements.map(r=>this._parseCondition(r)),s=A[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 A={and:"&&",or:"||",xor:"^"},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 J){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:_[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)),`
|
|
15
5
|
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:e})}'>
|
|
16
|
-
<data-condition-true-content>${
|
|
17
|
-
<data-condition-false-content>${
|
|
6
|
+
<data-condition-true-content>${s}</data-condition-true-content>
|
|
7
|
+
<data-condition-false-content>${n}</data-condition-false-content>
|
|
18
8
|
</data-condition>
|
|
19
|
-
`}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
|
|
20
|
-
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:
|
|
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(),`
|
|
10
|
+
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:s},collectionId:r})}'>
|
|
21
11
|
<data-collection-item>
|
|
22
12
|
${i}
|
|
23
13
|
</data-collection-item>
|
|
24
14
|
</data-collection>
|
|
25
|
-
`}handleForEachStatement(t){const e=this.getExpressionString(t.collection),
|
|
26
|
-
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:
|
|
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(),`
|
|
16
|
+
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
|
|
27
17
|
<data-collection-item>
|
|
28
18
|
${r}
|
|
29
19
|
</data-collection-item>
|
|
30
20
|
</data-collection>
|
|
31
|
-
`}handleBlockStatement(t){let e="";for(const
|
|
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 U="dataSourceEjs",D=y.startup;return T(function(o,t={}){const e=j(o,new W),s=M(o,{contains:"<%",importer:new F});v({editor:o,licenseKey:t.licenseKey,plan:D,pluginName:U,cleanup:()=>{e(),s()}})})});
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { Operator } from '@studio/editor/src/components/DataConditionPicker/statementTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { DataCollectionResolverProps, DataVariableResolverProps, IDataSourceExporter } from '@studio/editor/src/typeConfigs/dataSources';
|
|
3
|
+
import { DataConditionResolverProps } from '@studio/editor/src/components/public/StudioDataConditionPicker';
|
|
3
4
|
export declare class HandlebarsExporter implements IDataSourceExporter {
|
|
4
5
|
getHelperId(operator: Operator): string;
|
|
5
6
|
getFullPath({ collectionId, path }: DataVariableResolverProps): string;
|
|
6
|
-
getVariableSyntax(
|
|
7
|
-
|
|
7
|
+
getVariableSyntax({ dataResolver }: {
|
|
8
|
+
dataResolver: DataVariableResolverProps;
|
|
9
|
+
}): string;
|
|
10
|
+
getCollectionStartSyntax({ dataResolver }: {
|
|
11
|
+
dataResolver: DataCollectionResolverProps;
|
|
12
|
+
}): string;
|
|
8
13
|
getCollectionEndSyntax(): string;
|
|
9
|
-
getConditionalStartSyntax(
|
|
14
|
+
getConditionalStartSyntax({ dataResolver }: {
|
|
15
|
+
dataResolver: DataConditionResolverProps;
|
|
16
|
+
}): string;
|
|
10
17
|
private _parseCondition;
|
|
11
18
|
private getExpressionStr;
|
|
12
19
|
private _parseValue;
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
${
|
|
3
|
-
|
|
4
|
-
${e.generateConditionalStart(c)}
|
|
5
|
-
${(s==null?void 0:s.toHTML(t))??""}${h}
|
|
6
|
-
${e.generateConditionalEnd()}
|
|
7
|
-
`},resolveCondition(t,e){var a,s;if(!t)return{};if(t.operator==="and"||t.operator==="or")return{operator:t.operator,statements:((s=(a=t.statements)==null?void 0:a.map)==null?void 0:s.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:g({...n,value:t.left}),right:g({...n,value:t.right})}}}),f(r,p.collection,{toHTML(t){const e=t.exporter,n=this.tagName,a=this.__attrToString(t),s=this.getDataResolver(),i={...s,dataSource:g({component:this,value:s==null?void 0:s.dataSource,getCustomPath:t==null?void 0:t.getCustomPath})},o=this.components().at(0);return`
|
|
8
|
-
<${n}${a?` ${a}`:""}>${e.generateCollectionStart(i)}
|
|
9
|
-
${(o==null?void 0:o.toHTML(t))??""}
|
|
10
|
-
${e.generateCollectionEnd()}</${n}>
|
|
11
|
-
`}})},f=(r,t,e)=>{const n=r.Components.getType(t);if(!n){console.warn(`Component type ${t} not found`);return}const{model:a}=n;r.Components.addType(t,{model:{...e,toHTML(s={}){var o;const{exporter:i}=s;return i?i.export?i.export({component:this}):((o=e.toHTML)==null?void 0:o.call(this,s))??"":a.prototype.toHTML.call(this,s)??""}}})},B=(r,t)=>(r.config.optsHtml={...r.config.optsHtml,exporter:new D(t)},V(r),()=>{r.config.optsHtml.exporter=void 0}),U=(r,t)=>{const e=a=>{const{input:s}=a,{contains:i}=t;(!i||s.includes(i))&&(a.input=t.importer.import(s))},n=r.Parser.events.htmlBefore;return r.on(n,e),()=>{r.off(n,e)}},x={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},W={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},q={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},G={...x,...W,...q};class F{getHelperId(t){return G[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 s="";if(t.startIndex!==void 0||t.endIndex!==void 0){const h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?s=` (slice ${a} ${h} ${l})`:s=` (slice ${a} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${s||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,s=n.logicalOperator,i=a.map(c=>this._parseCondition(c)).join(" ");return`{{#if ${a.length>1?`(${s} ${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,s=n.logicalOperator,i=n.statements.map(o=>this._parseCondition(o)).join(" ");return a.length>1?`(${s} ${i})`:i}else{const a=e.operator,s=this.getHelperId(a),i=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(s,i,o)}}getExpressionStr(t,e,n){return x[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 J{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return L.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,s=e.message.match(/column (\d+)/),i=s?parseInt(s[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("/"),s=a.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,s,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=S(t),{parentLevel:a,remainingPathParts:s}=this.calculateParentLevel(n),i=s.join("."),o=this.collectionStack.length-1-a;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(i,o,e):e.path=s.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(s=>s===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=S(t),{parentLevel:a,remainingPathParts:s}=this.calculateParentLevel(n),i=s.join("."),o=this.collectionStack.length-1-a;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(i,o,e):e.path=s.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 s={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
|
-
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:s})}'>
|
|
13
|
-
<data-condition-true-content>${i}</data-condition-true-content>
|
|
1
|
+
"use strict";const C=require("handlebars/dist/cjs/handlebars"),S="app.grapesjs.com",y="app-stage.grapesjs.com",f=[S,y,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",k="license:check:end",v=()=>typeof window<"u",N=({isDev:i,isStage:t})=>`${i?"":`https://${t?y:S}`}/api`,_=()=>{const i=v()&&window.location.hostname;return!!i&&(f.includes(i)||f.some(t=>i.endsWith(t)))};async function L({path:i,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:a}){const o=`${t||N({isDev:!1,isStage:!1})}${i}`,c={method:e,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));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=(i=>(i.free="free",i.startup="startup",i.business="business",i.enterprise="enterprise",i))(p||{});const P={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function T(i){const t=i;return t.init=e=>n=>i(n,e),t}const w=i=>T(i);async function O({editor:i,plan:t,pluginName:e,licenseKey:n,cleanup:s}){let a="",r=!1;const o=_(),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})}};i.on(I,l=>{a=l==null?void 0:l.baseApiUrl,r=!0}),i.on(k,l=>{h(l)}),setTimeout(async()=>{if(!r){if(o)return;if(n){const l=await A({licenseKey:n,pluginName:e,baseApiUrl:a});l&&h(l)}else c("The `licenseKey` option not provided")}},2e3)}async function A(i){const{licenseKey:t,pluginName:e,baseApiUrl:n}=i;try{return(await L({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 j=(i,t)=>(i.config.optsHtml={...i.config.optsHtml,exporter:t},()=>{i.config.optsHtml.exporter=void 0}),H=(i,t)=>{const e=s=>{const{input:a}=s,{contains:r}=t;(!r||a.includes(r))&&(s.input=t.importer.import(a))},n=i.Parser.events.htmlBefore;return i.on(n,e),()=>{i.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"},M={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},U={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},B={...$,...M,...U};class D{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 a="";if(t.startIndex!==void 0||t.endIndex!==void 0){const h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?a=` (slice ${s} ${h} ${l})`:a=` (slice ${s} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${a||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:a}=s,r=s.logicalOperator,o=a.map(h=>this._parseCondition(h)).join(" ");return`{{#if ${a.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,a=n.logicalOperator,r=n.statements.map(o=>this._parseCondition(o)).join(" ");return s.length>1?`(${a} ${r})`:r}else{const s=e.operator,a=this.getHelperId(s),r=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(a,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 R{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return C.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,a=e.message.match(/column (\d+)/),r=a?parseInt(a[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("/"),a=s.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,a,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:a}=this.calculateParentLevel(n),r=a.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=a.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(a=>a===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:a}=this.calculateParentLevel(n),r=a.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=a.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 a={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`
|
|
2
|
+
<data-condition data-gjs-data-resolver='${JSON.stringify({condition:a})}'>
|
|
3
|
+
<data-condition-true-content>${r}</data-condition-true-content>
|
|
14
4
|
<data-condition-false-content>${o}</data-condition-false-content>
|
|
15
5
|
</data-condition>
|
|
16
|
-
`}handleEachBlock(t){var
|
|
6
|
+
`}handleEachBlock(t){var a,r,o;const e=this.getExpressionString(t.params[0]);let n;t.params.length>=3&&t.params[1]==="as"&&((a=t.params[2])==null?void 0:a.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(),`
|
|
17
7
|
<data-collection data-gjs-data-resolver='${JSON.stringify({dataSource:{type:"data-variable",path:e},collectionId:n})}'>
|
|
18
|
-
<data-collection-item>${
|
|
8
|
+
<data-collection-item>${s}</data-collection-item>
|
|
19
9
|
</data-collection>
|
|
20
|
-
`}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let e="";if(t.attributes)for(const
|
|
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=i=>{if(i==null||i==="")return[];if(i===".")return["this"];if(i===".."||i==="../")return[".."];if(i.startsWith("../")){const r=i.substring(3);return["..",...d(r)]}const t=[];let e=0,n=i.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("."),a=[];for(const r of s){const o=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);if(o){const c=parseInt(o[1],10);a.push(t[c])}else r!==""&&a.push(r)}return a},W="dataSourceHandlebars",V=p.startup,G=function(i,t={}){const e=j(i,new D),n=H(i,{contains:"{{",importer:new R});O({editor:i,licenseKey:t.licenseKey,plan:V,pluginName:W,cleanup:()=>{e(),n()}})},q=w(G);module.exports=q;
|