@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.
@@ -1,20 +1,10 @@
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
- ${(o==null?void 0:o.toHTML(t))??""}
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
- <data-condition data-gjs-data-resolver='${JSON.stringify({condition:r})}'>
13
- <data-condition-true-content>${i}</data-condition-true-content>
1
+ (function(h,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):(h=typeof globalThis<"u"?globalThis:h||self,h.StudioSdkPlugins_dataSourceHandlebars=p(h.Handlebars))})(this,function(h){"use strict";const p="app.grapesjs.com",P="app-stage.grapesjs.com",S=[p,P,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],x="license:check:start",E="license:check:end",I=()=>typeof window<"u",C=({isDev:i,isStage:t})=>`${i?"":`https://${t?P:p}`}/api`,k=()=>{const i=I()&&window.location.hostname;return!!i&&(S.includes(i)||S.some(t=>i.endsWith(t)))};async function N({path:i,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:a}){const o=`${t||C({isDev:!1,isStage:!1})}${i}`,c={method:e,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=s?new URLSearchParams(s).toString():"",l=u?`?${u}`:"",m=await fetch(`${o}${l}`,c);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);return m.json()}var d=(i=>(i.free="free",i.startup="startup",i.business="business",i.enterprise="enterprise",i))(d||{});const y={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function v(i){const t=i;return t.init=e=>n=>i(n,e),t}const T=i=>v(i);async function _({editor:i,plan:t,pluginName:e,licenseKey:n,cleanup:s}){let a="",r=!1;const o=k(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),s()},u=(l={})=>{var $;const{error:m,sdkLicense:U}=l,g=($=l.plan)==null?void 0:$.category;if(!(U||l.license)||m)c(m||"Invalid license");else if(g){const B=y[t],D=y[g];B>D&&c({pluginRequiredPlan:t,licensePlan:g})}};i.on(x,l=>{a=l==null?void 0:l.baseApiUrl,r=!0}),i.on(E,l=>{u(l)}),setTimeout(async()=>{if(!r){if(o)return;if(n){const l=await L({licenseKey:n,pluginName:e,baseApiUrl:a});l&&u(l)}else c("The `licenseKey` option not provided")}},2e3)}async function L(i){const{licenseKey:t,pluginName:e,baseApiUrl:n}=i;try{return(await N({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 w=(i,t)=>(i.config.optsHtml={...i.config.optsHtml,exporter:t},()=>{i.config.optsHtml.exporter=void 0}),O=(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)}},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"},A={...b,...{">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},...{contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"}};class j{getHelperId(t){return A[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 u=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?a=` (slice ${s} ${u} ${l})`:a=` (slice ${s} ${u})`}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(u=>this._parseCondition(u)).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 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 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 h.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=f(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=f(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 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(),`
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>${a}</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 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()}})})});
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 f=i=>{if(i==null||i==="")return[];if(i===".")return["this"];if(i===".."||i==="../")return[".."];if(i.startsWith("../")){const r=i.substring(3);return["..",...f(r)]}const t=[];let e=0,n=i.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(r,o,c,u)=>{const l=c!==void 0?c:u||"";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},H="dataSourceHandlebars",M=d.startup;return T(function(i,t={}){const e=w(i,new j),n=O(i,{contains:"{{",importer:new R});_({editor:i,licenseKey:t.licenseKey,plan:M,pluginName:H,cleanup:()=>{e(),n()}})})});
@@ -1 +1 @@
1
- "use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),y=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(y||{});const x="app.grapesjs.com",R="app-stage.grapesjs.com",w=[x,R,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],k="license:check:start",$="license:check:end",I=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?R:x}`}/api`,E=()=>{const e=I()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function M({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||U({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function j(e){const t=e;return t.init=s=>n=>e(n,s),t}const B=e=>j(e);async function N({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=E(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var A;const{error:g,sdkLicense:f}=r,d=(A=r.plan)==null?void 0:A.category;if(!(f||r.license)||g)c(g||"Invalid license");else if(d){const G=L[t],O=L[d];G>O&&c({pluginRequiredPlan:t,licensePlan:d})}};e.on(k,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on($,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await W({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function W(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await M({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const b=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${b(e)}"`:b(e),F=(e,t,s)=>({family:e,variant:t,...s}),D=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:b(e),menuVariant:s&&F(v(`menuFont-${b(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},T=(e,t)=>{var l;const s=D(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=b(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},S=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const f=n.find(d=>d.tag==="wght");if(f){const{start:d,end:P}=f;l=`${d} ${P}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return D(t,{menuVariant:{source:s},variants:a})},_=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:S(e),needsLoading:!0}}),K=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,T(t)):T(t,!0)};let h;const V=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},H=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=V(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(h)return h;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(_),h):[]},itemLayout:o=>{const a=h.find(l=>l.id===o.assetProps.id),i=K(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},z={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},q="googleFontsAssetProvider",J=p.startup,Q=function(e,t){const{i18n:s={}}=t,n=H(t);e.runCommand(y.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:z,...s}),N({editor:e,licenseKey:t.licenseKey,plan:J,pluginName:q,cleanup:()=>{e.runCommand(y.assetProviderRemove,{id:n.id})}})},Z=B(Q);module.exports=Z;
1
+ "use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),y=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(y||{});const x="app.grapesjs.com",R="app-stage.grapesjs.com",w=[x,R,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],k="license:check:start",$="license:check:end",I=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?R:x}`}/api`,E=()=>{const e=I()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function M({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||U({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function j(e){const t=e;return t.init=s=>n=>e(n,s),t}const B=e=>j(e);async function N({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=E(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var A;const{error:g,sdkLicense:f}=r,d=(A=r.plan)==null?void 0:A.category;if(!(f||r.license)||g)c(g||"Invalid license");else if(d){const G=L[t],O=L[d];G>O&&c({pluginRequiredPlan:t,licensePlan:d})}};e.on(k,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on($,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await W({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function W(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await M({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const b=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`'${b(e)}'`:b(e),F=(e,t,s)=>({family:e,variant:t,...s}),D=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:b(e),menuVariant:s&&F(v(`menuFont-${b(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},T=(e,t)=>{var l;const s=D(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=b(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},S=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const f=n.find(d=>d.tag==="wght");if(f){const{start:d,end:P}=f;l=`${d} ${P}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return D(t,{menuVariant:{source:s},variants:a})},_=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:S(e),needsLoading:!0}}),K=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,T(t)):T(t,!0)};let h;const V=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},H=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=V(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(h)return h;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(_),h):[]},itemLayout:o=>{const a=h.find(l=>l.id===o.assetProps.id),i=K(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},z={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},q="googleFontsAssetProvider",J=p.startup,Q=function(e,t){const{i18n:s={}}=t,n=H(t);e.runCommand(y.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:z,...s}),N({editor:e,licenseKey:t.licenseKey,plan:J,pluginName:q,cleanup:()=>{e.runCommand(y.assetProviderRemove,{id:n.id})}})},Z=B(Q);module.exports=Z;
@@ -97,7 +97,7 @@ async function W(e) {
97
97
  return console.error("Error during SDK license check:", o), !1;
98
98
  }
99
99
  }
100
- const b = (e) => e.replaceAll('"', "").replaceAll("'", ""), v = (e) => e.includes(",") ? e : /\s/.test(e) ? `"${b(e)}"` : b(e), F = (e, t, s) => ({ family: e, variant: t, ...s }), D = (e, t) => {
100
+ const b = (e) => e.replaceAll('"', "").replaceAll("'", ""), v = (e) => e.includes(",") ? e : /\s/.test(e) ? `'${b(e)}'` : b(e), F = (e, t, s) => ({ family: e, variant: t, ...s }), D = (e, t) => {
101
101
  e = v(e);
102
102
  const { menuVariant: s, variants: n } = t;
103
103
  return {
@@ -1 +1 @@
1
- (function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),p=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(p||{});const P="app.grapesjs.com",A="app-stage.grapesjs.com",w=[P,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],G="license:check:start",k="license:check:end",O=()=>typeof window<"u",$=({isDev:e,isStage:t})=>`${e?"":`https://${t?A:P}`}/api`,I=()=>{const e=O()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function U({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||$({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function E(e){const t=e;return t.init=s=>n=>e(n,s),t}const M=e=>E(e);async function j({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=I(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var D;const{error:g,sdkLicense:y}=r,f=(D=r.plan)==null?void 0:D.category;if(!(y||r.license)||g)c(g||"Invalid license");else if(f){const q=L[t],J=L[f];q>J&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(G,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(k,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await B({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function B(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await U({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const h=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${h(e)}"`:h(e),F=(e,t,s)=>({family:e,variant:t,...s}),T=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:h(e),menuVariant:s&&F(v(`menuFont-${h(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},x=(e,t)=>{var l;const s=T(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=h(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},N=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const y=n.find(f=>f.tag==="wght");if(y){const{start:f,end:R}=y;l=`${f} ${R}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return T(t,{menuVariant:{source:s},variants:a})},S=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:N(e),needsLoading:!0}}),W=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,x(t)):x(t,!0)};let b;const _=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},K=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=_(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(b)return b;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(b=c.items.map(S),b):[]},itemLayout:o=>{const a=b.find(l=>l.id===o.assetProps.id),i=W(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},V={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},H="googleFontsAssetProvider",z=d.startup;return M(function(e,t){const{i18n:s={}}=t,n=K(t);e.runCommand(p.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:V,...s}),j({editor:e,licenseKey:t.licenseKey,plan:z,pluginName:H,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:n.id})}})})});
1
+ (function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),p=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(p||{});const P="app.grapesjs.com",A="app-stage.grapesjs.com",w=[P,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],G="license:check:start",k="license:check:end",O=()=>typeof window<"u",$=({isDev:e,isStage:t})=>`${e?"":`https://${t?A:P}`}/api`,I=()=>{const e=O()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function U({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||$({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function E(e){const t=e;return t.init=s=>n=>e(n,s),t}const M=e=>E(e);async function j({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=I(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var D;const{error:g,sdkLicense:y}=r,f=(D=r.plan)==null?void 0:D.category;if(!(y||r.license)||g)c(g||"Invalid license");else if(f){const q=L[t],J=L[f];q>J&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(G,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(k,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await B({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function B(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await U({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const h=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`'${h(e)}'`:h(e),F=(e,t,s)=>({family:e,variant:t,...s}),T=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:h(e),menuVariant:s&&F(v(`menuFont-${h(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},x=(e,t)=>{var l;const s=T(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=h(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},N=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const y=n.find(f=>f.tag==="wght");if(y){const{start:f,end:R}=y;l=`${f} ${R}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return T(t,{menuVariant:{source:s},variants:a})},S=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:N(e),needsLoading:!0}}),W=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,x(t)):x(t,!0)};let b;const _=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},K=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=_(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(b)return b;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(b=c.items.map(S),b):[]},itemLayout:o=>{const a=b.find(l=>l.id===o.assetProps.id),i=W(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},V={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},H="googleFontsAssetProvider",z=d.startup;return M(function(e,t){const{i18n:s={}}=t,n=K(t);e.runCommand(p.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:V,...s}),j({editor:e,licenseKey:t.licenseKey,plan:z,pluginName:H,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:n.id})}})})});