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