@grapesjs/studio-sdk-plugins 1.0.28-rc.2 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/accordionComponent/index.cjs.js +8 -8
  2. package/dist/accordionComponent/index.es.js +71 -69
  3. package/dist/accordionComponent/index.umd.js +6 -6
  4. package/dist/animationComponent/index.cjs.js +3 -3
  5. package/dist/animationComponent/index.es.js +48 -46
  6. package/dist/animationComponent/index.umd.js +3 -3
  7. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  8. package/dist/canvasAbsoluteMode/index.es.js +86 -84
  9. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  10. package/dist/canvasEmptyState/index.cjs.js +1 -1
  11. package/dist/canvasEmptyState/index.es.js +68 -66
  12. package/dist/canvasEmptyState/index.umd.js +1 -1
  13. package/dist/canvasFullSize/index.cjs.js +3 -3
  14. package/dist/canvasFullSize/index.es.js +52 -50
  15. package/dist/canvasFullSize/index.umd.js +7 -7
  16. package/dist/canvasGridMode/index.cjs.js +5 -5
  17. package/dist/canvasGridMode/index.es.js +191 -189
  18. package/dist/canvasGridMode/index.umd.js +2 -2
  19. package/dist/dataSourceEjs/index.cjs.js +3 -3
  20. package/dist/dataSourceEjs/index.es.js +32 -30
  21. package/dist/dataSourceEjs/index.umd.js +3 -3
  22. package/dist/dataSourceHandlebars/index.cjs.js +4 -4
  23. package/dist/dataSourceHandlebars/index.es.js +31 -29
  24. package/dist/dataSourceHandlebars/index.umd.js +2 -2
  25. package/dist/dialogComponent/index.cjs.js +3 -3
  26. package/dist/dialogComponent/index.es.js +32 -30
  27. package/dist/dialogComponent/index.umd.js +4 -4
  28. package/dist/flexComponent/index.cjs.js +6 -6
  29. package/dist/flexComponent/index.es.js +74 -72
  30. package/dist/flexComponent/index.umd.js +7 -7
  31. package/dist/fsLightboxComponent/index.cjs.js +2 -2
  32. package/dist/fsLightboxComponent/index.es.js +40 -38
  33. package/dist/fsLightboxComponent/index.umd.js +2 -2
  34. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  35. package/dist/googleFontsAssetProvider/index.es.js +70 -68
  36. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  37. package/dist/iconifyComponent/index.cjs.js +2 -2
  38. package/dist/iconifyComponent/index.es.js +56 -54
  39. package/dist/iconifyComponent/index.umd.js +2 -2
  40. package/dist/index.cjs.js +43 -43
  41. package/dist/index.es.js +1442 -1440
  42. package/dist/index.umd.js +43 -43
  43. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  44. package/dist/layoutSidebarButtons/index.es.js +29 -27
  45. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  46. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  47. package/dist/lightGalleryComponent/index.es.js +90 -88
  48. package/dist/lightGalleryComponent/index.umd.js +1 -1
  49. package/dist/linkImageComponent/index.cjs.js +2 -2
  50. package/dist/linkImageComponent/index.es.js +20 -18
  51. package/dist/linkImageComponent/index.umd.js +2 -2
  52. package/dist/listPagesComponent/index.cjs.js +4 -4
  53. package/dist/listPagesComponent/index.es.js +42 -40
  54. package/dist/listPagesComponent/index.umd.js +4 -4
  55. package/dist/presetPrintable/index.cjs.js +3 -3
  56. package/dist/presetPrintable/index.es.js +156 -154
  57. package/dist/presetPrintable/index.umd.js +3 -3
  58. package/dist/prosemirror/index.cjs.js +7 -7
  59. package/dist/prosemirror/index.es.js +165 -163
  60. package/dist/prosemirror/index.umd.js +7 -7
  61. package/dist/rendererReact/index.cjs.js +1 -1
  62. package/dist/rendererReact/index.es.js +101 -99
  63. package/dist/rendererReact/index.js +1 -1
  64. package/dist/rendererReact/index.umd.js +1 -1
  65. package/dist/rteTinyMce/index.cjs.js +2 -2
  66. package/dist/rteTinyMce/index.es.js +54 -52
  67. package/dist/rteTinyMce/index.umd.js +2 -2
  68. package/dist/swiperComponent/index.cjs.js +7 -7
  69. package/dist/swiperComponent/index.es.js +60 -58
  70. package/dist/swiperComponent/index.umd.js +9 -9
  71. package/dist/tableComponent/index.cjs.js +1 -1
  72. package/dist/tableComponent/index.es.js +80 -78
  73. package/dist/tableComponent/index.umd.js +1 -1
  74. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  75. package/dist/youtubeAssetProvider/index.es.js +66 -64
  76. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  77. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- (function(x,T){typeof exports=="object"&&typeof module<"u"?module.exports=T():typeof define=="function"&&define.amd?define(T):(x=typeof globalThis<"u"?globalThis:x||self,x.StudioSdkPlugins_canvasGridMode=T())})(this,function(){"use strict";const x="app.grapesjs.com",T="app-stage.grapesjs.com",B=[x,T,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],ot="license:check:start",rt="license:check:end",st=()=>typeof window<"u",at=({isDev:t,isStage:e})=>`${t?"":`https://${e?T:x}`}/api`,it=()=>{const t=st()&&window.location.hostname;return!!t&&(B.includes(t)||B.some(e=>t.endsWith(e)))};function O(t){return typeof t=="function"}async function lt({path:t,baseApiUrl:e,method:r="GET",headers:o={},params:n,body:i}){const l=`${e||at({isDev:!1,isStage:!1})}${t}`,c={method:r,headers:{"Content-Type":"application/json",...o}};i&&(c.body=JSON.stringify(i));const p=n?new URLSearchParams(n).toString():"",a=p?`?${p}`:"",d=await fetch(`${l}${a}`,c);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var R=(t=>(t.free="free",t.startup="startup",t.business="business",t.enterprise="enterprise",t))(R||{});const j={[R.free]:0,[R.startup]:10,[R.business]:20,[R.enterprise]:30};function ct(t){const e=t;return e.init=r=>o=>t(o,r),e}const pt=t=>ct(t);async function dt({editor:t,plan:e,pluginName:r,licenseKey:o,cleanup:n}){let i="",s=!1;const l=it(),c=a=>{console.warn("Cleanup plugin:",r,"Reason:",a),n()},p=(a={})=>{var g;const{error:d,sdkLicense:u}=a,m=(g=a.plan)==null?void 0:g.category;if(!(u||a.license)||d)c(d||"Invalid license");else if(m){const w=j[e],b=j[m];w>b&&c({pluginRequiredPlan:e,licensePlan:m})}};t.on(ot,a=>{i=a==null?void 0:a.baseApiUrl,s=!0}),t.on(rt,a=>{p(a)}),setTimeout(async()=>{if(!s){if(l)return;if(o){const a=await ut({licenseKey:o,pluginName:r,baseApiUrl:i});a&&p(a)}else c("The `licenseKey` option not provided")}},2e3)}async function ut(t){const{licenseKey:e,pluginName:r,baseApiUrl:o}=t;try{return(await lt({baseApiUrl:o,path:`/sdk/${e||"na"}`,method:"POST",params:{d:window.location.hostname,pn:r}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const L="canvasGridMode",mt=R.startup,N="component-grid-mode",A="grid-mode",D="gjs-drag-grid-spot",U=`${D}__grid-item`,q=`${D}__grid-target`,H=`${D}__snapped`,gt=`${D}__container`,ft=()=>{const t="data-gjs-drag-grid-style",e=document,r="var(--gs-theme-cl-cmp-bg1, var(--gjs-color-highlight))",o="var(--gs-theme-cl-cmp-bg2, var(--gjs-color-blue))",n=e.querySelector(`style[${t}]`)||e.createElement("style");n.setAttribute(t,"true"),n.innerHTML=`
1
+ (function(x,T){typeof exports=="object"&&typeof module<"u"?module.exports=T():typeof define=="function"&&define.amd?define(T):(x=typeof globalThis<"u"?globalThis:x||self,x.StudioSdkPlugins_canvasGridMode=T())})(this,function(){"use strict";const x="app.grapesjs.com",T="app-stage.grapesjs.com",j=[x,"app2.grapesjs.com",T,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],ot="license:check:start",rt="license:check:end",st=()=>typeof window<"u",at=({isDev:t,isStage:e})=>`${t?"":`https://${e?T:x}`}/api`,it=()=>{const t=st()&&window.location.hostname;return!!t&&(j.includes(t)||j.some(e=>t.endsWith(e)))};function k(t){return typeof t=="function"}async function lt({path:t,baseApiUrl:e,method:r="GET",headers:o={},params:n,body:i}){const l=`${e||at({isDev:!1,isStage:!1})}${t}`,c={method:r,headers:{"Content-Type":"application/json",...o}};i&&(c.body=JSON.stringify(i));const p=n?new URLSearchParams(n).toString():"",a=p?`?${p}`:"",d=await fetch(`${l}${a}`,c);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var R=(t=>(t.free="free",t.startup="startup",t.business="business",t.enterprise="enterprise",t))(R||{});const B={[R.free]:0,[R.startup]:10,[R.business]:20,[R.enterprise]:30};function ct(t){const e=t;return e.init=r=>o=>t(o,r),e}const pt=t=>ct(t);async function dt({editor:t,plan:e,pluginName:r,licenseKey:o,cleanup:n}){let i="",s=!1;const l=it(),c=a=>{console.warn("Cleanup plugin:",r,"Reason:",a),n()},p=(a={})=>{var g;const{error:d,sdkLicense:u}=a,m=(g=a.plan)==null?void 0:g.category;if(!(u||a.license)||d)c(d||"Invalid license");else if(m){const w=B[e],b=B[m];w>b&&c({pluginRequiredPlan:e,licensePlan:m})}};t.on(ot,a=>{i=a==null?void 0:a.baseApiUrl,s=!0}),t.on(rt,a=>{p(a)}),setTimeout(async()=>{if(!s){if(l)return;if(o){const a=await ut({licenseKey:o,pluginName:r,baseApiUrl:i});a&&p(a)}else c("The `licenseKey` option not provided")}},2e3)}async function ut(t){const{licenseKey:e,pluginName:r,baseApiUrl:o}=t;try{return(await lt({baseApiUrl:o,path:`/sdk/${e||"na"}`,method:"POST",params:{d:window.location.hostname,pn:r}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const N="canvasGridMode",mt=R.startup,L="component-grid-mode",P="grid-mode",D="gjs-drag-grid-spot",U=`${D}__grid-item`,q=`${D}__grid-target`,H=`${D}__snapped`,gt=`${D}__container`,ft=()=>{const t="data-gjs-drag-grid-style",e=document,r="var(--gs-theme-cl-cmp-bg1, var(--gjs-color-highlight))",o="var(--gs-theme-cl-cmp-bg2, var(--gjs-color-blue))",n=e.querySelector(`style[${t}]`)||e.createElement("style");n.setAttribute(t,"true"),n.innerHTML=`
2
2
  .${U} {
3
3
  outline: 2px solid ${o};
4
4
  background: ${r};
@@ -23,4 +23,4 @@
23
23
  outline-offset: -1px;
24
24
  opacity: 0.35;
25
25
  }
26
- `,e.head.appendChild(n)};function Y(t){const{editor:e,type:r}=t,o=bt(e,t.component),n=F(e,o.component);if(!Ct(e,o,n,r))return{target:o,container:n,startScroll:Q(e).scroll,shadowContainerEl:document.createElement("div"),shadowSnappedEl:document.createElement("div"),shadowTargetEl:document.createElement("div"),spot:e.Canvas.addSpot({type:A,component:n.component})}}function K(t){const{editor:e,shadowTargetEl:r,shadowSnappedEl:o,shadowContainerEl:n,spotEl:i,target:s,container:l}=t,{Canvas:c}=e,p=e.config.stylePrefix;i==null||i.appendChild(n),n==null||n.appendChild(r),n==null||n.appendChild(o),yt(n,l),ht(r,s,l),wt(o,s),St(n,l.el),s.el.style.opacity="0";const a=c.getSpots().filter(d=>d.type!==A);e.em.stopDefault({preserveSelected:!0}),c.removeSpots(a),c.startAutoscroll(),c.getBody().classList.add(`${p}is__grabbing`)}function X(t){const{editor:e,shadowSnappedEl:r,shadowContainerEl:o,target:n,cancelled:i}=t,{Canvas:s}=e,l=e.config.stylePrefix,{component:c}=n;if(!i){const p=window.getComputedStyle(r);c.addStyle({"grid-area":p.gridArea,width:"",height:""})}n.el.style.opacity="",o.contains(r)&&(o==null||o.removeChild(r)),e.getModel().runDefault({preserveSelected:1}),s.stopAutoscroll(),s.getBody().classList.remove(`${l}is__grabbing`),s.removeSpots({type:A}),e.select(c)}function yt(t,{rows:e,columns:r}){const o=[];for(let n=0;n<r.length;n++){o[n]=[];for(let i=0;i<e.length;i++){const s=document.createElement("div");s.className=U,s.style.gridArea=`${i+1} / ${n+1}`,o[n][i]=s,t.appendChild(s)}}return o}function ht(t,e,r){return t.className=q,t.style.top=`${e.offset.top-r.offset.top}px`,t.style.left=`${e.offset.left-r.offset.left}px`,t.style.width=`${e.offset.width+e.margin.left+e.margin.right}px`,t.style.height=`${e.offset.height+e.margin.top+e.margin.bottom}px`,t}function wt(t,e){const r=V(e.el,e.computedStyles);return t.className=H,t.style.gridArea=`${r.row.start} / ${r.column.start} / ${r.row.end} / ${r.column.end}`,t}function St(t,e){const r=window.getComputedStyle(e);t.className=gt,t.style.position="relative",t.style.display=r.display,t.style.gap=r.gap,t.style.padding=r.padding,t.style.border=r.border,t.style.gridTemplateColumns=r.gridTemplateColumns,t.style.gridTemplateRows=r.gridTemplateRows}function J(t,e){if(e){if(Array.isArray(e))return[...e].pop()}else return[...t.getSelectedAll()].pop();return e}function bt(t,e){const r=J(t,e),o=r.getEl(),n=window.getComputedStyle(o);return{component:r,el:o,offset:t.Canvas.offset(o),margin:{top:parseFloat(n.marginTop),right:parseFloat(n.marginRight),bottom:parseFloat(n.marginBottom),left:parseFloat(n.marginLeft)},computedStyles:n}}function F(t,e){const r=e.parent(),o=r.getEl(),n=window.getComputedStyle(o);return{component:r,el:o,offset:t.Canvas.offset(o),computedStyles:n,padding:{top:parseFloat(n.paddingTop),right:parseFloat(n.paddingRight),bottom:parseFloat(n.paddingBottom),left:parseFloat(n.paddingLeft)},columns:n.gridTemplateColumns.split(" ").map(s=>parseFloat(s)),rows:n.gridTemplateRows.split(" ").map(s=>parseFloat(s)),gap:{column:parseInt(n.columnGap),row:parseInt(n.rowGap)}}}function E(t,e,r,o,n=1){let i=0;for(let s=e;s<=t.length;s++){if(i+(t[s-1]+o)*n>r)return s;i+=o+t[s-1]}return t.length+1}function Q(t){const{scrollY:e,scrollX:r}=t.Canvas.getWindow();return{scroll:{top:e,left:r}}}function Ct(t,e,r,o){const n=i=>t.em.logWarning(i);return o==="draggable"&&e.component.get(o)===!1?(n(`[${L}] The element is not ${o}`),!0):r.computedStyles.display!=="grid"?(n(`[${L}] The container does not have style display:grid`),!0):!1}function z(t,e,r={}){const o=J(t,e),n=o==null?void 0:o.parent(),i=n==null?void 0:n.getEl();if(!n||!i)return!1;const{enableGrid:s}=r,l=window.getComputedStyle(i).display==="grid";return O(s)?s({component:o,parent:n,isParentGrid:l}):l}const Z=t=>t.split(" ").map(e=>parseFloat(e));function V(t,e){const r=t.ownerDocument.defaultView,o=e||r.getComputedStyle(t),n=o.gridArea.split("/").some(S=>isNaN(parseInt(S.trim()))),i={isComputed:n,raw:o.gridArea};if(!n)return{...i,row:{start:parseInt(o.gridRowStart),end:parseInt(o.gridRowEnd)},column:{start:parseInt(o.gridColumnStart),end:parseInt(o.gridColumnEnd)}};const s=t.parentElement,l=r.getComputedStyle(s),c=parseFloat(l.columnGap)||0,p=parseFloat(l.rowGap)||0,a=Z(l.gridTemplateColumns),d=Z(l.gridTemplateRows),u=parseFloat(l.paddingLeft)||0,m=parseFloat(l.paddingTop)||0,h=s.getBoundingClientRect(),g=t.getBoundingClientRect(),w=(S,C,G,$,_)=>{let M=1,P=$+_;for(let I=0;I<C.length;I++){const k=C[I],nt=P+k;if(S>=P&&S<nt)return M;P=nt+G,M++}return-1},b=w(g.left,a,c,h.left,u),v=w(g.right-1,a,c,h.left,u)+1,y=w(g.top,d,p,h.top,m),f=w(g.bottom-1,d,p,h.top,m)+1;return{...i,row:{start:y,end:f},column:{start:b,end:v}}}function $t(t){t.Commands.add(N,{stop(){},run(e,r,o={}){const n=Y({editor:e,component:o.target,type:"draggable"});if(!n){this.stopCommand();return}const{spot:i,target:s,shadowContainerEl:l,shadowSnappedEl:c,shadowTargetEl:p,startScroll:a}=n;let{container:d}=n,u;new e.Utils.Dragger({doc:s.el.ownerDocument,onStart:()=>{u=setTimeout(()=>{K({editor:e,shadowTargetEl:p,shadowSnappedEl:c,shadowContainerEl:l,spotEl:i.attributes.spotEl,target:s,container:d}),d=F(e,s.component)},10)},onEnd:(h,g,{cancelled:w})=>{clearTimeout(u),X({editor:e,shadowSnappedEl:c,shadowContainerEl:l,target:s,cancelled:w}),this.stopCommand(),e.em.set("_cmpDrag",1)},setPosition:({x:h,y:g})=>{const{scroll:w}=Q(e),{columns:b,rows:v,gap:y,offset:f,padding:S}=d,{offset:C,margin:G}=s,$=C.top-f.top-S.top-G.top+g-a.top+w.top,_=C.left-f.left-S.left-G.left+h-a.left+w.left,M=Math.min(E(b,1,_,y.column,.5),b.length),P=Math.min(E(v,1,$,y.row,.5),v.length),I=Math.min(E(b,M,C.width,y.column)+1,b.length+1),k=Math.min(E(v,P,C.height,y.row)+1,v.length+1);c.style.gridArea=`${P} / ${M} / ${k} / ${I}`,p.style.top=`${$+S.top}px`,p.style.left=`${_+S.left}px`}}).start(o.event)}})}function vt(t,e){const r=Y({editor:t,component:e.component,type:"resizable"});if(!r)return;const{onMove:o,onEnd:n}=e.options||{},{spot:i,target:s,shadowContainerEl:l,shadowSnappedEl:c,shadowTargetEl:p}=r;let{container:a}=r,d="",u;return{onStart:m=>{d=m.target.dataset.gjsHandler||"",u=setTimeout(()=>{K({editor:t,shadowTargetEl:p,shadowSnappedEl:c,shadowContainerEl:l,spotEl:i.attributes.spotEl,target:s,container:a}),a=F(t,s.component)},10),t.trigger("component:resize",{...s,type:"start"})},onEnd:(m,h)=>{const{startDim:g,rectDim:w}=h.resizer,b=JSON.stringify(g)===JSON.stringify(w);clearTimeout(u),X({editor:t,shadowSnappedEl:c,shadowContainerEl:l,target:s,cancelled:b}),n==null||n(m,h)},onMove:(m,h)=>{const g=V(c),w=s.margin.left,b=s.margin.top,v=s.margin.bottom,y=s.margin.right,{w:f,t:S,l:C,h:G}=h.resizer.rectDim,$={t:S-b,l:C-w,h:G+b+v,w:f+w+y};d.endsWith("l")&&(g.column.start=E(a.columns,1,$.l-a.offset.left-a.padding.left,a.gap.column,.5)),d.startsWith("t")&&(g.row.start=E(a.rows,1,$.t-a.offset.top-a.padding.top,a.gap.row,.5)),d.endsWith("r")&&(g.column.end=Math.max(E(a.columns,g.column.start,$.w,a.gap.column,.5),g.column.start+1)),d.startsWith("b")&&(g.row.end=Math.max(E(a.rows,g.row.start,$.h,a.gap.row,.5),g.row.start+1)),c.style.gridArea=`${g.row.start} / ${g.column.start} / ${g.row.end} / ${g.column.end}`,p.style.width=`${$.w}px`,p.style.height=`${$.h}px`,p.style.left=`${$.l-a.offset.left}px`,p.style.top=`${$.t-a.offset.top}px`,o==null||o(m,h)}}}const tt=["px","%","em","rem","vw","vh"],Et=(t,e)=>{const r=t.Styles.getSectors().find(o=>!!o.getProperty(e));return{sector:r,property:r?r.getProperty(e):void 0}},xt=(t,e)=>Et(t,e),Tt=(t,{x:e,y:r,mergable:o}={})=>{const n={property:`${t}-x`,type:"integer",units:tt,...e},i={property:`${t}-y`,type:"integer",units:tt,...r};return{property:t,type:"composite",properties:[n,i],...o&&{fromStyle(s,{name:l,separator:c,property:p}){const[a,d]=p.getProperties(),[u,m]=(s[l]||"").split(c);return{[a.getId()]:s[a.getName()]||u||"",[d.getId()]:s[d.getName()]||m||u||""}},toStyle(s,{name:l,property:c}){const[p,a]=c.getProperties(),d=s[p.getId()],u=s[a.getId()];return{[l]:d===u?d:`${d} ${u}`}}}}},W={display:["grid"]};function Rt(t=""){const e=/^repeat\(\s*(\d+)\s*,\s*(.+)\s*\)$/i,r=/^minmax\(\s*(.+?)\s*,\s*(.+?)\s*\)$/i,o=t.match(e);if(!o)return null;const n=parseInt(o[1],10),i=o[2];let s=i,l=i;const c=i.match(r);return c&&(s=c[1],l=c[2]),{total:n,min:s===l?"":s,max:l}}function Gt(t={}){let e="",r="",o="",n="";const i=g=>g.split("/").map(w=>w.trim()).filter(Boolean),s=t["grid-area"]||"",l=t["grid-column"]||"",c=t["grid-row"]||"",p=i(s),a=i(l),d=i(c),u=p.length,m=a.length,h=d.length;return u===4?(o=p[0],e=p[1],n=p[2],r=p[3]):u===3?(o=p[0],e=p[1],n=p[2]):u===2?(o=p[0],e=p[1]):u===1&&(o=p[0]),m===2?(e=a[0],r=a[1]):m===1&&(e=a[0]),h===2?(o=d[0],n=d[1]):h===1&&(o=d[0]),{columnStart:e,columnEnd:r,rowStart:o,rowEnd:n}}function et(t){const{property:e,label:r}=t,o="1",n="1fr";return{property:e,label:r,type:"composite",requires:W,generic:!0,properties:[{name:" ",property:`${e}-repeat`,type:"number",full:!0,min:1,default:"1"},{label:"Min size",property:`${e}-min`,type:"number",min:0,units:["px","%"],default:"0"},{label:"Max size",property:`${e}-max`,type:"number",min:1,units:["fr","px","%"],default:"1"}],fromStyle(i,s){const{name:l,property:c}=s,[p,a,d]=c.getProperties(),u=i[l],m=Rt(u),h=(m==null?void 0:m.max)??n;return{[p.id]:(m==null?void 0:m.total)??o,[a.id]:(m==null?void 0:m.min)??"",[d.id]:h===n?"":h}},toStyle(i,{name:s,property:l}){const[c,p,a]=l.getProperties(),d=i[c.id],u=i[p.id],m=i[a.id]||n,h=u&&m?`minmax(${u}, ${m})`:m;return{[s]:`repeat(${d||o}, ${h})`}}}}function Pt(t,e){if(!e.styleableGrid)return;const{property:r,...o}=xt(t,"display");if(!r)return;const n=r.getOption("grid"),i=o.sector;n||r.addOption({id:"grid",label:"Grid"}),i.addProperty(et({label:"Columns",property:"grid-template-columns"}),{}),i.addProperty(et({label:"Rows",property:"grid-template-rows"}),{}),i.addProperty({id:"grid-gap",requires:W,...Tt("gap",{x:{id:"grid-row-gap",label:"Row",property:"row-gap",min:0,default:"0"},y:{id:"grid-column-gap",label:"Column",property:"column-gap",min:0,default:"0"},mergable:!0})},{}),i.addProperty({type:"composite",property:"grid-area",label:"Grid area",requiresParent:W,generic:!0,properties:[{label:"Row start",property:"grid-row-start",type:"integer",default:"auto"},{label:"Row end",property:"grid-row-end",type:"integer",default:"auto"},{label:"Column start",property:"grid-column-start",type:"integer",default:"auto"},{label:"Column end",property:"grid-column-end",type:"integer",default:"auto"}],fromStyle(s){const l=Gt(s);return{"grid-column-start":s["grid-column-start"]||l.columnStart,"grid-column-end":s["grid-column-end"]||l.columnEnd,"grid-row-start":s["grid-row-start"]||l.rowStart,"grid-row-end":s["grid-row-end"]||l.rowEnd}},toStyle(s,{name:l}){const c=s["grid-row-start"]||"auto",p=s["grid-row-end"]||"auto",a=s["grid-column-start"]||"auto",d=s["grid-column-end"]||"auto";return{[l]:`${c} / ${a} / ${p} / ${d}`}}},{})}return pt(function(t,e={}){const r={itemResizable:!0,...e},{Canvas:o,Commands:n,Components:i}=t,{itemResizable:s}=r,l=o.events,c=n.events,p=i.events,a=`${c.runBeforeCommand}tlb-move`,d=`${c.runBeforeCommand}resize`;let u;$t(t);const m=({options:y})=>{z(t,y.target,r)&&(t.runCommand(N,{...y}),y.abort=!0)},h=y=>{const{options:f}=y;z(t,f.component,r)&&(f.options=Object.assign(f.options||{},vt(t,f)))},g=()=>{const y=o.getSpots({type:A}).pop();if(!y)return;let f=y.attributes.spotEl;f||(f=document.createElement("div"),f.className=D,y.set({spotEl:f})),Object.entries(y.getStyle()).forEach(([S,C])=>f.style.setProperty(S,C)),u==null||u.appendChild(f)},w=({spot:y})=>{const f=y.attributes.spotEl;y.type!==A||!f||u==null||u.removeChild(f)};if(s){const y=f=>{const S=O(s)?s({component:f}):s;return typeof S=="boolean"?S:{tl:!1,tc:!1,tr:!1,cl:!1,cr:!1,bl:!1,bc:!1,br:!1,...S}};t.on(p.resizeInit,f=>{const{component:S}=f;if(z(t,S,r)){const C=y(S);f.resizable=C}})}const b=[[a,m],[d,h],[l.spot,g],[l.spotRemove,w]];b.forEach(([y,f])=>{t.on(y,f)}),t.onReady(()=>{u=o.getSpotsEl(),ft(),Pt(t,r)});const v=()=>{delete t.Commands.commands[N],b.forEach(([y,f])=>{t.off(y,f)})};dt({editor:t,licenseKey:r.licenseKey,plan:mt,pluginName:L,cleanup:v})})});
26
+ `,e.head.appendChild(n)};function Y(t){const{editor:e,type:r}=t,o=bt(e,t.component),n=F(e,o.component);if(!Ct(e,o,n,r))return{target:o,container:n,startScroll:Q(e).scroll,shadowContainerEl:document.createElement("div"),shadowSnappedEl:document.createElement("div"),shadowTargetEl:document.createElement("div"),spot:e.Canvas.addSpot({type:P,component:n.component})}}function K(t){const{editor:e,shadowTargetEl:r,shadowSnappedEl:o,shadowContainerEl:n,spotEl:i,target:s,container:l}=t,{Canvas:c}=e,p=e.config.stylePrefix;i==null||i.appendChild(n),n==null||n.appendChild(r),n==null||n.appendChild(o),yt(n,l),ht(r,s,l),wt(o,s),St(n,l.el),s.el.style.opacity="0";const a=c.getSpots().filter(d=>d.type!==P);e.em.stopDefault({preserveSelected:!0}),c.removeSpots(a),c.startAutoscroll(),c.getBody().classList.add(`${p}is__grabbing`)}function X(t){const{editor:e,shadowSnappedEl:r,shadowContainerEl:o,target:n,cancelled:i}=t,{Canvas:s}=e,l=e.config.stylePrefix,{component:c}=n;if(!i){const p=window.getComputedStyle(r);c.addStyle({"grid-area":p.gridArea,width:"",height:""})}n.el.style.opacity="",o.contains(r)&&(o==null||o.removeChild(r)),e.getModel().runDefault({preserveSelected:1}),s.stopAutoscroll(),s.getBody().classList.remove(`${l}is__grabbing`),s.removeSpots({type:P}),e.select(c)}function yt(t,{rows:e,columns:r}){const o=[];for(let n=0;n<r.length;n++){o[n]=[];for(let i=0;i<e.length;i++){const s=document.createElement("div");s.className=U,s.style.gridArea=`${i+1} / ${n+1}`,o[n][i]=s,t.appendChild(s)}}return o}function ht(t,e,r){return t.className=q,t.style.top=`${e.offset.top-r.offset.top}px`,t.style.left=`${e.offset.left-r.offset.left}px`,t.style.width=`${e.offset.width+e.margin.left+e.margin.right}px`,t.style.height=`${e.offset.height+e.margin.top+e.margin.bottom}px`,t}function wt(t,e){const r=V(e.el,e.computedStyles);return t.className=H,t.style.gridArea=`${r.row.start} / ${r.column.start} / ${r.row.end} / ${r.column.end}`,t}function St(t,e){const r=window.getComputedStyle(e);t.className=gt,t.style.position="relative",t.style.display=r.display,t.style.gap=r.gap,t.style.padding=r.padding,t.style.border=r.border,t.style.gridTemplateColumns=r.gridTemplateColumns,t.style.gridTemplateRows=r.gridTemplateRows}function J(t,e){if(e){if(Array.isArray(e))return[...e].pop()}else return[...t.getSelectedAll()].pop();return e}function bt(t,e){const r=J(t,e),o=r.getEl(),n=window.getComputedStyle(o);return{component:r,el:o,offset:t.Canvas.offset(o),margin:{top:parseFloat(n.marginTop),right:parseFloat(n.marginRight),bottom:parseFloat(n.marginBottom),left:parseFloat(n.marginLeft)},computedStyles:n}}function F(t,e){const r=e.parent(),o=r.getEl(),n=window.getComputedStyle(o);return{component:r,el:o,offset:t.Canvas.offset(o),computedStyles:n,padding:{top:parseFloat(n.paddingTop),right:parseFloat(n.paddingRight),bottom:parseFloat(n.paddingBottom),left:parseFloat(n.paddingLeft)},columns:n.gridTemplateColumns.split(" ").map(s=>parseFloat(s)),rows:n.gridTemplateRows.split(" ").map(s=>parseFloat(s)),gap:{column:parseInt(n.columnGap),row:parseInt(n.rowGap)}}}function E(t,e,r,o,n=1){let i=0;for(let s=e;s<=t.length;s++){if(i+(t[s-1]+o)*n>r)return s;i+=o+t[s-1]}return t.length+1}function Q(t){const{scrollY:e,scrollX:r}=t.Canvas.getWindow();return{scroll:{top:e,left:r}}}function Ct(t,e,r,o){const n=i=>t.em.logWarning(i);return o==="draggable"&&e.component.get(o)===!1?(n(`[${N}] The element is not ${o}`),!0):r.computedStyles.display!=="grid"?(n(`[${N}] The container does not have style display:grid`),!0):!1}function O(t,e,r={}){const o=J(t,e),n=o==null?void 0:o.parent(),i=n==null?void 0:n.getEl();if(!n||!i)return!1;const{enableGrid:s}=r,l=window.getComputedStyle(i).display==="grid";return k(s)?s({component:o,parent:n,isParentGrid:l}):l}const Z=t=>t.split(" ").map(e=>parseFloat(e));function V(t,e){const r=t.ownerDocument.defaultView,o=e||r.getComputedStyle(t),n=o.gridArea.split("/").some(S=>isNaN(parseInt(S.trim()))),i={isComputed:n,raw:o.gridArea};if(!n)return{...i,row:{start:parseInt(o.gridRowStart),end:parseInt(o.gridRowEnd)},column:{start:parseInt(o.gridColumnStart),end:parseInt(o.gridColumnEnd)}};const s=t.parentElement,l=r.getComputedStyle(s),c=parseFloat(l.columnGap)||0,p=parseFloat(l.rowGap)||0,a=Z(l.gridTemplateColumns),d=Z(l.gridTemplateRows),u=parseFloat(l.paddingLeft)||0,m=parseFloat(l.paddingTop)||0,h=s.getBoundingClientRect(),g=t.getBoundingClientRect(),w=(S,C,G,$,_)=>{let M=1,A=$+_;for(let I=0;I<C.length;I++){const W=C[I],nt=A+W;if(S>=A&&S<nt)return M;A=nt+G,M++}return-1},b=w(g.left,a,c,h.left,u),v=w(g.right-1,a,c,h.left,u)+1,y=w(g.top,d,p,h.top,m),f=w(g.bottom-1,d,p,h.top,m)+1;return{...i,row:{start:y,end:f},column:{start:b,end:v}}}function $t(t){t.Commands.add(L,{stop(){},run(e,r,o={}){const n=Y({editor:e,component:o.target,type:"draggable"});if(!n){this.stopCommand();return}const{spot:i,target:s,shadowContainerEl:l,shadowSnappedEl:c,shadowTargetEl:p,startScroll:a}=n;let{container:d}=n,u;new e.Utils.Dragger({doc:s.el.ownerDocument,onStart:()=>{u=setTimeout(()=>{K({editor:e,shadowTargetEl:p,shadowSnappedEl:c,shadowContainerEl:l,spotEl:i.attributes.spotEl,target:s,container:d}),d=F(e,s.component)},10)},onEnd:(h,g,{cancelled:w})=>{clearTimeout(u),X({editor:e,shadowSnappedEl:c,shadowContainerEl:l,target:s,cancelled:w}),this.stopCommand(),e.em.set("_cmpDrag",1)},setPosition:({x:h,y:g})=>{const{scroll:w}=Q(e),{columns:b,rows:v,gap:y,offset:f,padding:S}=d,{offset:C,margin:G}=s,$=C.top-f.top-S.top-G.top+g-a.top+w.top,_=C.left-f.left-S.left-G.left+h-a.left+w.left,M=Math.min(E(b,1,_,y.column,.5),b.length),A=Math.min(E(v,1,$,y.row,.5),v.length),I=Math.min(E(b,M,C.width,y.column)+1,b.length+1),W=Math.min(E(v,A,C.height,y.row)+1,v.length+1);c.style.gridArea=`${A} / ${M} / ${W} / ${I}`,p.style.top=`${$+S.top}px`,p.style.left=`${_+S.left}px`}}).start(o.event)}})}function vt(t,e){const r=Y({editor:t,component:e.component,type:"resizable"});if(!r)return;const{onMove:o,onEnd:n}=e.options||{},{spot:i,target:s,shadowContainerEl:l,shadowSnappedEl:c,shadowTargetEl:p}=r;let{container:a}=r,d="",u;return{onStart:m=>{d=m.target.dataset.gjsHandler||"",u=setTimeout(()=>{K({editor:t,shadowTargetEl:p,shadowSnappedEl:c,shadowContainerEl:l,spotEl:i.attributes.spotEl,target:s,container:a}),a=F(t,s.component)},10),t.trigger("component:resize",{...s,type:"start"})},onEnd:(m,h)=>{const{startDim:g,rectDim:w}=h.resizer,b=JSON.stringify(g)===JSON.stringify(w);clearTimeout(u),X({editor:t,shadowSnappedEl:c,shadowContainerEl:l,target:s,cancelled:b}),n==null||n(m,h)},onMove:(m,h)=>{const g=V(c),w=s.margin.left,b=s.margin.top,v=s.margin.bottom,y=s.margin.right,{w:f,t:S,l:C,h:G}=h.resizer.rectDim,$={t:S-b,l:C-w,h:G+b+v,w:f+w+y};d.endsWith("l")&&(g.column.start=E(a.columns,1,$.l-a.offset.left-a.padding.left,a.gap.column,.5)),d.startsWith("t")&&(g.row.start=E(a.rows,1,$.t-a.offset.top-a.padding.top,a.gap.row,.5)),d.endsWith("r")&&(g.column.end=Math.max(E(a.columns,g.column.start,$.w,a.gap.column,.5),g.column.start+1)),d.startsWith("b")&&(g.row.end=Math.max(E(a.rows,g.row.start,$.h,a.gap.row,.5),g.row.start+1)),c.style.gridArea=`${g.row.start} / ${g.column.start} / ${g.row.end} / ${g.column.end}`,p.style.width=`${$.w}px`,p.style.height=`${$.h}px`,p.style.left=`${$.l-a.offset.left}px`,p.style.top=`${$.t-a.offset.top}px`,o==null||o(m,h)}}}const tt=["px","%","em","rem","vw","vh"],Et=(t,e)=>{const r=t.Styles.getSectors().find(o=>!!o.getProperty(e));return{sector:r,property:r?r.getProperty(e):void 0}},xt=(t,e)=>Et(t,e),Tt=(t,{x:e,y:r,mergable:o}={})=>{const n={property:`${t}-x`,type:"integer",units:tt,...e},i={property:`${t}-y`,type:"integer",units:tt,...r};return{property:t,type:"composite",properties:[n,i],...o&&{fromStyle(s,{name:l,separator:c,property:p}){const[a,d]=p.getProperties(),[u,m]=(s[l]||"").split(c);return{[a.getId()]:s[a.getName()]||u||"",[d.getId()]:s[d.getName()]||m||u||""}},toStyle(s,{name:l,property:c}){const[p,a]=c.getProperties(),d=s[p.getId()],u=s[a.getId()];return{[l]:d===u?d:`${d} ${u}`}}}}},z={display:["grid"]};function Rt(t=""){const e=/^repeat\(\s*(\d+)\s*,\s*(.+)\s*\)$/i,r=/^minmax\(\s*(.+?)\s*,\s*(.+?)\s*\)$/i,o=t.match(e);if(!o)return null;const n=parseInt(o[1],10),i=o[2];let s=i,l=i;const c=i.match(r);return c&&(s=c[1],l=c[2]),{total:n,min:s===l?"":s,max:l}}function Gt(t={}){let e="",r="",o="",n="";const i=g=>g.split("/").map(w=>w.trim()).filter(Boolean),s=t["grid-area"]||"",l=t["grid-column"]||"",c=t["grid-row"]||"",p=i(s),a=i(l),d=i(c),u=p.length,m=a.length,h=d.length;return u===4?(o=p[0],e=p[1],n=p[2],r=p[3]):u===3?(o=p[0],e=p[1],n=p[2]):u===2?(o=p[0],e=p[1]):u===1&&(o=p[0]),m===2?(e=a[0],r=a[1]):m===1&&(e=a[0]),h===2?(o=d[0],n=d[1]):h===1&&(o=d[0]),{columnStart:e,columnEnd:r,rowStart:o,rowEnd:n}}function et(t){const{property:e,label:r}=t,o="1",n="1fr";return{property:e,label:r,type:"composite",requires:z,generic:!0,properties:[{name:" ",property:`${e}-repeat`,type:"number",full:!0,min:1,default:"1"},{label:"Min size",property:`${e}-min`,type:"number",min:0,units:["px","%"],default:"0"},{label:"Max size",property:`${e}-max`,type:"number",min:1,units:["fr","px","%"],default:"1"}],fromStyle(i,s){const{name:l,property:c}=s,[p,a,d]=c.getProperties(),u=i[l],m=Rt(u),h=(m==null?void 0:m.max)??n;return{[p.id]:(m==null?void 0:m.total)??o,[a.id]:(m==null?void 0:m.min)??"",[d.id]:h===n?"":h}},toStyle(i,{name:s,property:l}){const[c,p,a]=l.getProperties(),d=i[c.id],u=i[p.id],m=i[a.id]||n,h=u&&m?`minmax(${u}, ${m})`:m;return{[s]:`repeat(${d||o}, ${h})`}}}}function At(t,e){if(!e.styleableGrid)return;const{property:r,...o}=xt(t,"display");if(!r)return;const n=r.getOption("grid"),i=o.sector;n||r.addOption({id:"grid",label:"Grid"}),i.addProperty(et({label:"Columns",property:"grid-template-columns"}),{}),i.addProperty(et({label:"Rows",property:"grid-template-rows"}),{}),i.addProperty({id:"grid-gap",requires:z,...Tt("gap",{x:{id:"grid-row-gap",label:"Row",property:"row-gap",min:0,default:"0"},y:{id:"grid-column-gap",label:"Column",property:"column-gap",min:0,default:"0"},mergable:!0})},{}),i.addProperty({type:"composite",property:"grid-area",label:"Grid area",requiresParent:z,generic:!0,properties:[{label:"Row start",property:"grid-row-start",type:"integer",default:"auto"},{label:"Row end",property:"grid-row-end",type:"integer",default:"auto"},{label:"Column start",property:"grid-column-start",type:"integer",default:"auto"},{label:"Column end",property:"grid-column-end",type:"integer",default:"auto"}],fromStyle(s){const l=Gt(s);return{"grid-column-start":s["grid-column-start"]||l.columnStart,"grid-column-end":s["grid-column-end"]||l.columnEnd,"grid-row-start":s["grid-row-start"]||l.rowStart,"grid-row-end":s["grid-row-end"]||l.rowEnd}},toStyle(s,{name:l}){const c=s["grid-row-start"]||"auto",p=s["grid-row-end"]||"auto",a=s["grid-column-start"]||"auto",d=s["grid-column-end"]||"auto";return{[l]:`${c} / ${a} / ${p} / ${d}`}}},{})}return pt(function(t,e={}){const r={itemResizable:!0,...e},{Canvas:o,Commands:n,Components:i}=t,{itemResizable:s}=r,l=o.events,c=n.events,p=i.events,a=`${c.runBeforeCommand}tlb-move`,d=`${c.runBeforeCommand}resize`;let u;$t(t);const m=({options:y})=>{O(t,y.target,r)&&(t.runCommand(L,{...y}),y.abort=!0)},h=y=>{const{options:f}=y;O(t,f.component,r)&&(f.options=Object.assign(f.options||{},vt(t,f)))},g=()=>{const y=o.getSpots({type:P}).pop();if(!y)return;let f=y.attributes.spotEl;f||(f=document.createElement("div"),f.className=D,y.set({spotEl:f})),Object.entries(y.getStyle()).forEach(([S,C])=>f.style.setProperty(S,C)),u==null||u.appendChild(f)},w=({spot:y})=>{const f=y.attributes.spotEl;y.type!==P||!f||u==null||u.removeChild(f)};if(s){const y=f=>{const S=k(s)?s({component:f}):s;return typeof S=="boolean"?S:{tl:!1,tc:!1,tr:!1,cl:!1,cr:!1,bl:!1,bc:!1,br:!1,...S}};t.on(p.resizeInit,f=>{const{component:S}=f;if(O(t,S,r)){const C=y(S);f.resizable=C}})}const b=[[a,m],[d,h],[l.spot,g],[l.spotRemove,w]];b.forEach(([y,f])=>{t.on(y,f)}),t.onReady(()=>{u=o.getSpotsEl(),ft(),At(t,r)});const v=()=>{delete t.Commands.commands[L],b.forEach(([y,f])=>{t.off(y,f)})};dt({editor:t,licenseKey:r.licenseKey,plan:mt,pluginName:N,cleanup:v})})});
@@ -1,7 +1,7 @@
1
- "use strict";const $="app.grapesjs.com",b="app-stage.grapesjs.com",S=[$,b,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",w="license:check:end",P=()=>typeof window<"u",k=({isDev:o,isStage:t})=>`${o?"":`https://${t?b:$}`}/api`,O=()=>{const o=P()&&window.location.hostname;return!!o&&(S.includes(o)||S.some(t=>o.endsWith(t)))};async function L({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const a=`${t||k({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const p=n?new URLSearchParams(n).toString():"",l=p?`?${p}`:"",h=await fetch(`${a}${l}`,c);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);return h.json()}var g=(o=>(o.free="free",o.startup="startup",o.business="business",o.enterprise="enterprise",o))(g||{});const x={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function C(o){const t=o;return t.init=e=>s=>o(s,e),t}const v=o=>C(o);async function N({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=O(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),n()},p=(l={})=>{var u;const{error:h,sdkLicense:d}=l,f=(u=l.plan)==null?void 0:u.category;if(!(d||l.license)||h)c(h||"Invalid license");else if(f){const m=x[t],E=x[f];m>E&&c({pluginRequiredPlan:t,licensePlan:f})}};o.on(I,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),o.on(w,l=>{p(l)}),setTimeout(async()=>{if(!i){if(a)return;if(s){const l=await T({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function T(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await L({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const B=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},M=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),W=(o,t)=>{const e=n=>{const{input:r}=n,{contains:i}=t;(!i||r.includes(i))&&(n.input=t.importer.import(r))},s=o.Parser.events.htmlBefore;return o.on(s,e),()=>{o.off(s,e)}};class A{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,s=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${s}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:s,startIndex:n,endIndex:r}=t,i=(s==null?void 0:s.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const p=n??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
1
+ "use strict";const $="app.grapesjs.com",b="app-stage.grapesjs.com",I="app2.grapesjs.com",w="app-stage2.grapesjs.com",S=[$,I,b,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],P="license:check:start",O="license:check:end",k=()=>typeof window<"u",L=({isDev:o,isStage:t})=>`${o?"":`https://${t?b:$}`}/api`,C=()=>{const o=k()&&window.location.hostname;return!!o&&(S.includes(o)||S.some(t=>o.endsWith(t)))};async function N({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const a=`${t||L({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const p=n?new URLSearchParams(n).toString():"",l=p?`?${p}`:"",h=await fetch(`${a}${l}`,c);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);return h.json()}var g=(o=>(o.free="free",o.startup="startup",o.business="business",o.enterprise="enterprise",o))(g||{});const x={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function v(o){const t=o;return t.init=e=>s=>o(s,e),t}const T=o=>v(o);async function B({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=C(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),n()},p=(l={})=>{var u;const{error:h,sdkLicense:d}=l,f=(u=l.plan)==null?void 0:u.category;if(!(d||l.license)||h)c(h||"Invalid license");else if(f){const m=x[t],E=x[f];m>E&&c({pluginRequiredPlan:t,licensePlan:f})}};o.on(P,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),o.on(O,l=>{p(l)}),setTimeout(async()=>{if(!i){if(a)return;if(s){const l=await A({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function A(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await N({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 M=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},j=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),W=(o,t)=>{const e=n=>{const{input:r}=n,{contains:i}=t;(!i||r.includes(i))&&(n.input=t.importer.import(r))},s=o.Parser.events.htmlBefore;return o.on(s,e),()=>{o.off(s,e)}};class _{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,s=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${s}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:s,startIndex:n,endIndex:r}=t,i=(s==null?void 0:s.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const p=n??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
2
2
  const startIndex = parseInt(${n??0}, 10);
3
3
  const endIndex = startIndex + arr.length;
4
- const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:s}){return(t?[this._sanitizeVariableName(t),s,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(B(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:"^"},j=["===","==","!==","!=","<=",">=","<",">","&&","||"],_={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class F{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let s=0;for(;s<t.length;){const n=t.indexOf("<%",s);if(n===-1){s<t.length&&e.push(this.createAppendLiteral(t.slice(s)));break}n>s&&e.push(this.createAppendLiteral(t.slice(s,n)));const r=t.indexOf("%>",n);if(r===-1)throw new Error("Unclosed EJS tag");const i=t.slice(n+2,r).trim();if(s=r+2,i.startsWith("=")||i.startsWith("-")){const a=i.slice(1).trim();e.push(this.createAppendExpression(a))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const a=this.parseIfStatement(i,t,s);e.push(a),s=a.endPos||s}else if(i.startsWith("for")){const a=this.parseForStatement(i,t,s);e.push(a),s=a.endPos||s}else{const a=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(a){const c=a[1],p=a[2],l=this.parseForEachStatement(c,p,t,s);e.push(l),s=l.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${i}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,s){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const r=this.parseJsExpression(n[1]),{body:i,endPos:a}=this.parseTemplateBlock(e,s);let c=null,p=a;const l=e.indexOf("<%",p);if(l===p){const h=e.indexOf("%>",l);if(h!==-1){const d=e.slice(l+2,h).trim(),f=h+2-l;if(d.startsWith("} else if")){p=l+f;const y=d.substring(d.indexOf("if")).trim(),u=this.parseIfStatement(y,e,p);c={type:"IfStatement",test:u.test,consequent:u.consequent,alternate:u.alternate},p=u.endPos}else if(d.startsWith("} else")){p=l+f;const{body:y,endPos:u}=this.parseTemplateBlock(e,p);c={type:"BlockStatement",body:y},p=u;const m=e.indexOf("<%",p),E=e.indexOf("%>",m);m===p&&e.slice(m+2,E).trim()==="}"&&(p=E+2)}else d==="}"&&(p=l+f)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:i},alternate:c,endPos:p}}parseForStatement(t,e,s){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const r=n[1].split("of");if(r.length!==2)throw new Error("Only for...of loops are supported");const i=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),a=r[1].trim(),{body:c,endPos:p}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:this.parseJsExpression(a)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const l=e.indexOf("<%",p),h=e.indexOf("%>",l);return l===p&&e.slice(l+2,h).trim()==="}"?h+2:p})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:i}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const a=s.indexOf("<%",i),c=s.indexOf("%>",a);return a===i&&s.slice(a+2,c).trim()==="}"?c+2:i})()}}parseTemplateBlock(t,e){const s=[];let n=e;for(;n<t.length;){const r=t.indexOf("<%",n);if(r===-1){n<t.length&&s.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}r>n&&s.push(this.createAppendLiteral(t.slice(n,r)));const i=t.indexOf("%>",r);if(i===-1)throw new Error("Unclosed EJS tag within block");const a=t.slice(r+2,i).trim();if(a==="}"||a.startsWith("} else")){n=r;break}if(n=i+2,a.startsWith("=")||a.startsWith("-")){const c=a.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const c=this.parseIfStatement(a,t,n);s.push(c),n=c.endPos||n}else if(a.startsWith("for")){const c=this.parseForStatement(a,t,n);s.push(c),n=c.endPos||n}else{const c=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const p=c[1],l=c[2],h=this.parseForEachStatement(p,l,t,n);s.push(h),n=h.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${a}`)}}}return{body:s,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of j){const r=t.lastIndexOf(n);if(r>0&&t[r-1]!=="!"&&t[r-1]!=="="&&t[r-1]!=="<"&&t[r-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:_[n],left:this.parseJsExpression(t.slice(0,r).trim()),right:this.parseJsExpression(t.slice(r+n.length).trim())}}const e=t.indexOf("."),s=t.indexOf("[");if(e>0&&(s===-1||e<s)||s>0&&(e===-1||s<e)){const n=e>0&&(s===-1||e<s)?e:s;let r,i,a=!1;if(n===e)r=t.slice(0,e),i={type:"Identifier",name:t.slice(e+1)},a=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const p=t.slice(s+1,c);i=/^(['"]).*\1$/.test(p)||/^-?\d+(\.\d+)?$/.test(p)?this.parseJsExpression(p):{type:"Identifier",name:p},a=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:i,computed:a}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),s=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
4
+ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:s}){return(t?[this._sanitizeVariableName(t),s,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(M(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:"^"},F=["===","==","!==","!=","<=",">=","<",">","&&","||"],U={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class D{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let s=0;for(;s<t.length;){const n=t.indexOf("<%",s);if(n===-1){s<t.length&&e.push(this.createAppendLiteral(t.slice(s)));break}n>s&&e.push(this.createAppendLiteral(t.slice(s,n)));const r=t.indexOf("%>",n);if(r===-1)throw new Error("Unclosed EJS tag");const i=t.slice(n+2,r).trim();if(s=r+2,i.startsWith("=")||i.startsWith("-")){const a=i.slice(1).trim();e.push(this.createAppendExpression(a))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const a=this.parseIfStatement(i,t,s);e.push(a),s=a.endPos||s}else if(i.startsWith("for")){const a=this.parseForStatement(i,t,s);e.push(a),s=a.endPos||s}else{const a=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(a){const c=a[1],p=a[2],l=this.parseForEachStatement(c,p,t,s);e.push(l),s=l.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${i}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,s){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const r=this.parseJsExpression(n[1]),{body:i,endPos:a}=this.parseTemplateBlock(e,s);let c=null,p=a;const l=e.indexOf("<%",p);if(l===p){const h=e.indexOf("%>",l);if(h!==-1){const d=e.slice(l+2,h).trim(),f=h+2-l;if(d.startsWith("} else if")){p=l+f;const y=d.substring(d.indexOf("if")).trim(),u=this.parseIfStatement(y,e,p);c={type:"IfStatement",test:u.test,consequent:u.consequent,alternate:u.alternate},p=u.endPos}else if(d.startsWith("} else")){p=l+f;const{body:y,endPos:u}=this.parseTemplateBlock(e,p);c={type:"BlockStatement",body:y},p=u;const m=e.indexOf("<%",p),E=e.indexOf("%>",m);m===p&&e.slice(m+2,E).trim()==="}"&&(p=E+2)}else d==="}"&&(p=l+f)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:i},alternate:c,endPos:p}}parseForStatement(t,e,s){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const r=n[1].split("of");if(r.length!==2)throw new Error("Only for...of loops are supported");const i=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),a=r[1].trim(),{body:c,endPos:p}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:this.parseJsExpression(a)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const l=e.indexOf("<%",p),h=e.indexOf("%>",l);return l===p&&e.slice(l+2,h).trim()==="}"?h+2:p})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:i}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const a=s.indexOf("<%",i),c=s.indexOf("%>",a);return a===i&&s.slice(a+2,c).trim()==="}"?c+2:i})()}}parseTemplateBlock(t,e){const s=[];let n=e;for(;n<t.length;){const r=t.indexOf("<%",n);if(r===-1){n<t.length&&s.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}r>n&&s.push(this.createAppendLiteral(t.slice(n,r)));const i=t.indexOf("%>",r);if(i===-1)throw new Error("Unclosed EJS tag within block");const a=t.slice(r+2,i).trim();if(a==="}"||a.startsWith("} else")){n=r;break}if(n=i+2,a.startsWith("=")||a.startsWith("-")){const c=a.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const c=this.parseIfStatement(a,t,n);s.push(c),n=c.endPos||n}else if(a.startsWith("for")){const c=this.parseForStatement(a,t,n);s.push(c),n=c.endPos||n}else{const c=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const p=c[1],l=c[2],h=this.parseForEachStatement(p,l,t,n);s.push(h),n=h.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${a}`)}}}return{body:s,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of F){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:U[n],left:this.parseJsExpression(t.slice(0,r).trim()),right:this.parseJsExpression(t.slice(r+n.length).trim())}}const e=t.indexOf("."),s=t.indexOf("[");if(e>0&&(s===-1||e<s)||s>0&&(e===-1||s<e)){const n=e>0&&(s===-1||e<s)?e:s;let r,i,a=!1;if(n===e)r=t.slice(0,e),i={type:"Identifier",name:t.slice(e+1)},a=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const p=t.slice(s+1,c);i=/^(['"]).*\1$/.test(p)||/^-?\d+(\.\d+)?$/.test(p)?this.parseJsExpression(p):{type:"Identifier",name:p},a=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:i,computed:a}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),s=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
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>
@@ -18,4 +18,4 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
18
18
  ${r}
19
19
  </data-collection-item>
20
20
  </data-collection>
21
- `}handleBlockStatement(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const s=this.collectionStack[this.collectionStack.length-1];t.name===s&&(e={collectionId:s,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];let i=t;const a=[];for(;i.type==="MemberExpression";)i.property.type==="Identifier"&&!i.computed?a.unshift(i.property.name):i.property.type==="Literal"&&i.computed?a.unshift(String(i.property.value)):a.unshift(this.getExpressionString(i.property)),i=i.object;if(i.type==="Identifier"&&i.name===r){const c=a.join(".");n={...e,collectionId:r,variableType:"currentItem",path:c}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const s=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${s}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),s="isTruthy";return e.startsWith("!!")?(s="isTruthy",e=e.slice(2)):e.startsWith("!")&&(s="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:s}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),s=this.getConditionExpression(t.right);return`${e} ${t.operator} ${s}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),s=this.getExpressionString(t.property);return t.computed?`${e}[${s}]`:`${e}.${s}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const U="dataSourceEjs",D=g.startup,V=function(o,t={}){const e=M(o,new A),s=W(o,{contains:"<%",importer:new F});N({editor:o,licenseKey:t.licenseKey,plan:D,pluginName:U,cleanup:()=>{e(),s()}})},G=v(V);module.exports=G;
21
+ `}handleBlockStatement(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const s=this.collectionStack[this.collectionStack.length-1];t.name===s&&(e={collectionId:s,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];let i=t;const a=[];for(;i.type==="MemberExpression";)i.property.type==="Identifier"&&!i.computed?a.unshift(i.property.name):i.property.type==="Literal"&&i.computed?a.unshift(String(i.property.value)):a.unshift(this.getExpressionString(i.property)),i=i.object;if(i.type==="Identifier"&&i.name===r){const c=a.join(".");n={...e,collectionId:r,variableType:"currentItem",path:c}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const s=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${s}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),s="isTruthy";return e.startsWith("!!")?(s="isTruthy",e=e.slice(2)):e.startsWith("!")&&(s="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:s}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),s=this.getConditionExpression(t.right);return`${e} ${t.operator} ${s}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),s=this.getExpressionString(t.property);return t.computed?`${e}[${s}]`:`${e}.${s}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const V="dataSourceEjs",G=g.startup,q=function(o,t={}){const e=j(o,new _),s=W(o,{contains:"<%",importer:new D});B({editor:o,licenseKey:t.licenseKey,plan:G,pluginName:V,cleanup:()=>{e(),s()}})},H=T(q);module.exports=H;
@@ -1,6 +1,8 @@
1
- const $ = "app.grapesjs.com", b = "app-stage.grapesjs.com", S = [
1
+ const $ = "app.grapesjs.com", b = "app-stage.grapesjs.com", I = "app2.grapesjs.com", w = "app-stage2.grapesjs.com", S = [
2
2
  $,
3
+ I,
3
4
  b,
5
+ w,
4
6
  "localhost",
5
7
  "127.0.0.1",
6
8
  ".local-credentialless.webcontainer.io",
@@ -9,11 +11,11 @@ const $ = "app.grapesjs.com", b = "app-stage.grapesjs.com", S = [
9
11
  // For stackblitz.com demos
10
12
  "-sandpack.codesandbox.io"
11
13
  // For Sandpack demos
12
- ], I = "license:check:start", w = "license:check:end", P = () => typeof window < "u", k = ({ isDev: o, isStage: t }) => `${o ? "" : `https://${t ? b : $}`}/api`, O = () => {
13
- const o = P() && window.location.hostname;
14
+ ], P = "license:check:start", O = "license:check:end", k = () => typeof window < "u", L = ({ isDev: o, isStage: t }) => `${o ? "" : `https://${t ? b : $}`}/api`, C = () => {
15
+ const o = k() && window.location.hostname;
14
16
  return !!o && (S.includes(o) || S.some((t) => o.endsWith(t)));
15
17
  };
16
- async function L({
18
+ async function N({
17
19
  path: o,
18
20
  baseApiUrl: t,
19
21
  method: e = "GET",
@@ -21,7 +23,7 @@ async function L({
21
23
  params: n,
22
24
  body: r
23
25
  }) {
24
- const a = `${t || k({ isDev: !1, isStage: !1 })}${o}`, c = {
26
+ const a = `${t || L({ isDev: !1, isStage: !1 })}${o}`, c = {
25
27
  method: e,
26
28
  headers: {
27
29
  "Content-Type": "application/json",
@@ -41,12 +43,12 @@ const x = {
41
43
  [g.business]: 20,
42
44
  [g.enterprise]: 30
43
45
  };
44
- function C(o) {
46
+ function v(o) {
45
47
  const t = o;
46
48
  return t.init = (e) => (s) => o(s, e), t;
47
49
  }
48
- const v = (o) => /* @__PURE__ */ C(o);
49
- async function N({
50
+ const T = (o) => /* @__PURE__ */ v(o);
51
+ async function B({
50
52
  editor: o,
51
53
  plan: t,
52
54
  pluginName: e,
@@ -54,7 +56,7 @@ async function N({
54
56
  cleanup: n
55
57
  }) {
56
58
  let r = "", i = !1;
57
- const a = O(), c = (l) => {
59
+ const a = C(), c = (l) => {
58
60
  console.warn("Cleanup plugin:", e, "Reason:", l), n();
59
61
  }, p = (l = {}) => {
60
62
  var u;
@@ -66,25 +68,25 @@ async function N({
66
68
  m > E && c({ pluginRequiredPlan: t, licensePlan: f });
67
69
  }
68
70
  };
69
- o.on(I, (l) => {
71
+ o.on(P, (l) => {
70
72
  r = l == null ? void 0 : l.baseApiUrl, i = !0;
71
- }), o.on(w, (l) => {
73
+ }), o.on(O, (l) => {
72
74
  p(l);
73
75
  }), setTimeout(async () => {
74
76
  if (!i) {
75
77
  if (a) return;
76
78
  if (s) {
77
- const l = await T({ licenseKey: s, pluginName: e, baseApiUrl: r });
79
+ const l = await A({ licenseKey: s, pluginName: e, baseApiUrl: r });
78
80
  l && p(l);
79
81
  } else
80
82
  c("The `licenseKey` option not provided");
81
83
  }
82
84
  }, 2e3);
83
85
  }
84
- async function T(o) {
86
+ async function A(o) {
85
87
  const { licenseKey: t, pluginName: e, baseApiUrl: s } = o;
86
88
  try {
87
- return (await L({
89
+ return (await N({
88
90
  baseApiUrl: s,
89
91
  path: `/sdk/${t || "na"}`,
90
92
  method: "POST",
@@ -97,10 +99,10 @@ async function T(o) {
97
99
  return console.error("Error during SDK license check:", n), !1;
98
100
  }
99
101
  }
100
- const B = (o) => {
102
+ const M = (o) => {
101
103
  const t = o;
102
104
  return t.logicalOperator === "and" || t.logicalOperator === "or";
103
- }, M = (o, t) => (o.config.optsHtml = {
105
+ }, j = (o, t) => (o.config.optsHtml = {
104
106
  ...o.config.optsHtml,
105
107
  exporter: t
106
108
  }, () => {
@@ -114,7 +116,7 @@ const B = (o) => {
114
116
  o.off(s, e);
115
117
  };
116
118
  };
117
- class A {
119
+ class _ {
118
120
  getVariableSyntax({ dataResolver: t }) {
119
121
  const { defaultValue: e } = t, s = this.getFullPath(t), n = e ? ` || \`${e}\`` : "";
120
122
  return `<%= ${s}${n} %>`;
@@ -151,7 +153,7 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
151
153
  }
152
154
  _parseCondition(t) {
153
155
  if (!t) return "";
154
- if (B(t)) {
156
+ if (M(t)) {
155
157
  const e = t.statements.map((r) => this._parseCondition(r)), s = J[t.logicalOperator];
156
158
  let n = e.length > 1 ? `(${e.join(`)${s}(`)})` : e[0];
157
159
  return t.logicalOperator === "xor" && (n = `!!(${n})`), n;
@@ -210,7 +212,7 @@ const J = {
210
212
  and: "&&",
211
213
  or: "||",
212
214
  xor: "^"
213
- }, j = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], _ = {
215
+ }, F = ["===", "==", "!==", "!=", "<=", ">=", "<", ">", "&&", "||"], U = {
214
216
  "===": "=",
215
217
  "==": "=",
216
218
  "!==": "!=",
@@ -222,7 +224,7 @@ const J = {
222
224
  "&&": "&&",
223
225
  "||": "||"
224
226
  };
225
- class F {
227
+ class D {
226
228
  constructor() {
227
229
  this.messages = [], this.collectionStack = [];
228
230
  }
@@ -452,12 +454,12 @@ class F {
452
454
  type: "Literal",
453
455
  value: t === "true"
454
456
  };
455
- for (const n of j) {
457
+ for (const n of F) {
456
458
  const r = t.lastIndexOf(n);
457
459
  if (r > 0 && t[r - 1] !== "!" && t[r - 1] !== "=" && t[r - 1] !== "<" && t[r - 1] !== ">")
458
460
  return {
459
461
  type: n === "&&" || n === "||" ? "LogicalExpression" : "BinaryExpression",
460
- operator: _[n],
462
+ operator: U[n],
461
463
  left: this.parseJsExpression(t.slice(0, r).trim()),
462
464
  right: this.parseJsExpression(t.slice(r + n.length).trim())
463
465
  };
@@ -697,21 +699,21 @@ class F {
697
699
  });
698
700
  }
699
701
  }
700
- const U = "dataSourceEjs", D = g.startup, V = function(o, t = {}) {
701
- const e = M(o, new A()), s = W(o, {
702
+ const V = "dataSourceEjs", G = g.startup, q = function(o, t = {}) {
703
+ const e = j(o, new _()), s = W(o, {
702
704
  contains: "<%",
703
- importer: new F()
705
+ importer: new D()
704
706
  });
705
- N({
707
+ B({
706
708
  editor: o,
707
709
  licenseKey: t.licenseKey,
708
- plan: D,
709
- pluginName: U,
710
+ plan: G,
711
+ pluginName: V,
710
712
  cleanup: () => {
711
713
  e(), s();
712
714
  }
713
715
  });
714
- }, G = v(V);
716
+ }, H = T(q);
715
717
  export {
716
- G as default
718
+ H as default
717
719
  };
@@ -1,7 +1,7 @@
1
- (function(g,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(g=typeof globalThis<"u"?globalThis:g||self,g.StudioSdkPlugins_dataSourceEjs=m())})(this,function(){"use strict";const g="app.grapesjs.com",m="app-stage.grapesjs.com",$=[g,m,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",w="license:check:end",P=()=>typeof window<"u",k=({isDev:o,isStage:t})=>`${o?"":`https://${t?m:g}`}/api`,O=()=>{const o=P()&&window.location.hostname;return!!o&&($.includes(o)||$.some(t=>o.endsWith(t)))};async function L({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const a=`${t||k({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const p=n?new URLSearchParams(n).toString():"",l=p?`?${p}`:"",u=await fetch(`${a}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}var y=(o=>(o.free="free",o.startup="startup",o.business="business",o.enterprise="enterprise",o))(y||{});const b={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function C(o){const t=o;return t.init=e=>s=>o(s,e),t}const T=o=>C(o);async function v({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=O(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),n()},p=(l={})=>{var h;const{error:u,sdkLicense:d}=l,f=(h=l.plan)==null?void 0:h.category;if(!(d||l.license)||u)c(u||"Invalid license");else if(f){const E=b[t],x=b[f];E>x&&c({pluginRequiredPlan:t,licensePlan:f})}};o.on(I,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),o.on(w,l=>{p(l)}),setTimeout(async()=>{if(!i){if(a)return;if(s){const l=await N({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function N(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await L({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const B=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},j=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),M=(o,t)=>{const e=n=>{const{input:r}=n,{contains:i}=t;(!i||r.includes(i))&&(n.input=t.importer.import(r))},s=o.Parser.events.htmlBefore;return o.on(s,e),()=>{o.off(s,e)}};class W{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,s=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${s}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:s,startIndex:n,endIndex:r}=t,i=(s==null?void 0:s.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const p=n??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
1
+ (function(g,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(g=typeof globalThis<"u"?globalThis:g||self,g.StudioSdkPlugins_dataSourceEjs=m())})(this,function(){"use strict";const g="app.grapesjs.com",m="app-stage.grapesjs.com",$=[g,"app2.grapesjs.com",m,"app-stage2.grapesjs.com","localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",w="license:check:end",P=()=>typeof window<"u",O=({isDev:o,isStage:t})=>`${o?"":`https://${t?m:g}`}/api`,k=()=>{const o=P()&&window.location.hostname;return!!o&&($.includes(o)||$.some(t=>o.endsWith(t)))};async function L({path:o,baseApiUrl:t,method:e="GET",headers:s={},params:n,body:r}){const a=`${t||O({isDev:!1,isStage:!1})}${o}`,c={method:e,headers:{"Content-Type":"application/json",...s}};r&&(c.body=JSON.stringify(r));const p=n?new URLSearchParams(n).toString():"",l=p?`?${p}`:"",u=await fetch(`${a}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}var y=(o=>(o.free="free",o.startup="startup",o.business="business",o.enterprise="enterprise",o))(y||{});const b={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function N(o){const t=o;return t.init=e=>s=>o(s,e),t}const T=o=>N(o);async function C({editor:o,plan:t,pluginName:e,licenseKey:s,cleanup:n}){let r="",i=!1;const a=k(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),n()},p=(l={})=>{var h;const{error:u,sdkLicense:d}=l,f=(h=l.plan)==null?void 0:h.category;if(!(d||l.license)||u)c(u||"Invalid license");else if(f){const E=b[t],x=b[f];E>x&&c({pluginRequiredPlan:t,licensePlan:f})}};o.on(I,l=>{r=l==null?void 0:l.baseApiUrl,i=!0}),o.on(w,l=>{p(l)}),setTimeout(async()=>{if(!i){if(a)return;if(s){const l=await v({licenseKey:s,pluginName:e,baseApiUrl:r});l&&p(l)}else c("The `licenseKey` option not provided")}},2e3)}async function v(o){const{licenseKey:t,pluginName:e,baseApiUrl:s}=o;try{return(await L({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const A=o=>{const t=o;return t.logicalOperator==="and"||t.logicalOperator==="or"},M=(o,t)=>(o.config.optsHtml={...o.config.optsHtml,exporter:t},()=>{o.config.optsHtml.exporter=void 0}),B=(o,t)=>{const e=n=>{const{input:r}=n,{contains:i}=t;(!i||r.includes(i))&&(n.input=t.importer.import(r))},s=o.Parser.events.htmlBefore;return o.on(s,e),()=>{o.off(s,e)}};class _{getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,s=this.getFullPath(t),n=e?` || \`${e}\``:"";return`<%= ${s}${n} %>`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:s,startIndex:n,endIndex:r}=t,i=(s==null?void 0:s.path)||e||"",a=this._sanitizeVariableName(e);let c="";if(n!==void 0||r!==void 0){const p=n??0,l=r!==void 0?r:"";c=`.slice(${p}${l!==""?`, ${l}`:""})`}return`<% ${i}${c}.forEach(function(currentItem, index, arr) {
2
2
  const startIndex = parseInt(${n??0}, 10);
3
3
  const endIndex = startIndex + arr.length;
4
- const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:s}){return(t?[this._sanitizeVariableName(t),s,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(B(t)){const e=t.statements.map(r=>this._parseCondition(r)),s=A[t.logicalOperator];let n=e.length>1?`(${e.join(`)${s}(`)})`:e[0];return t.logicalOperator==="xor"&&(n=`!!(${n})`),n}else{const e=this._parseValue(t.left),s=this._parseValue(t.right);switch(t.operator){case"equals":return`${e} === ${s}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${e} ${t.operator} ${s}`;case"contains":return`${e}?.includes(${s})`;case"startsWith":return`${e}?.startsWith(${s})`;case"endsWith":return`${e}?.endsWith(${s})`;case"equalsIgnoreCase":return`${e}?.toLowerCase() === ${s}?.toLowerCase()`;case"trimEquals":return`${e}?.trim() === ${s}?.trim()`;case"isTruthy":return`!!${e}`;case"isFalsy":return`!${e}`;case"isDefined":return`${e} !== undefined`;case"isNull":return`${e} === null`;case"isUndefined":return`${e} === undefined`;case"isArray":return`Array.isArray(${e})`;case"isObject":return`typeof ${e} === 'object' && ${e} !== null && !Array.isArray(${e})`;case"isString":return`typeof ${e} === 'string'`;case"isNumber":return`typeof ${e} === 'number' && !isNaN(${e})`;case"isBoolean":return`typeof ${e} === 'boolean'`;default:return`${e} ${t.operator} ${s}`}}}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}}const A={and:"&&",or:"||",xor:"^"},J=["===","==","!==","!=","<=",">=","<",">","&&","||"],_={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class F{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let s=0;for(;s<t.length;){const n=t.indexOf("<%",s);if(n===-1){s<t.length&&e.push(this.createAppendLiteral(t.slice(s)));break}n>s&&e.push(this.createAppendLiteral(t.slice(s,n)));const r=t.indexOf("%>",n);if(r===-1)throw new Error("Unclosed EJS tag");const i=t.slice(n+2,r).trim();if(s=r+2,i.startsWith("=")||i.startsWith("-")){const a=i.slice(1).trim();e.push(this.createAppendExpression(a))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const a=this.parseIfStatement(i,t,s);e.push(a),s=a.endPos||s}else if(i.startsWith("for")){const a=this.parseForStatement(i,t,s);e.push(a),s=a.endPos||s}else{const a=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(a){const c=a[1],p=a[2],l=this.parseForEachStatement(c,p,t,s);e.push(l),s=l.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${i}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,s){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const r=this.parseJsExpression(n[1]),{body:i,endPos:a}=this.parseTemplateBlock(e,s);let c=null,p=a;const l=e.indexOf("<%",p);if(l===p){const u=e.indexOf("%>",l);if(u!==-1){const d=e.slice(l+2,u).trim(),f=u+2-l;if(d.startsWith("} else if")){p=l+f;const S=d.substring(d.indexOf("if")).trim(),h=this.parseIfStatement(S,e,p);c={type:"IfStatement",test:h.test,consequent:h.consequent,alternate:h.alternate},p=h.endPos}else if(d.startsWith("} else")){p=l+f;const{body:S,endPos:h}=this.parseTemplateBlock(e,p);c={type:"BlockStatement",body:S},p=h;const E=e.indexOf("<%",p),x=e.indexOf("%>",E);E===p&&e.slice(E+2,x).trim()==="}"&&(p=x+2)}else d==="}"&&(p=l+f)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:i},alternate:c,endPos:p}}parseForStatement(t,e,s){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const r=n[1].split("of");if(r.length!==2)throw new Error("Only for...of loops are supported");const i=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),a=r[1].trim(),{body:c,endPos:p}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:this.parseJsExpression(a)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const l=e.indexOf("<%",p),u=e.indexOf("%>",l);return l===p&&e.slice(l+2,u).trim()==="}"?u+2:p})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:i}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const a=s.indexOf("<%",i),c=s.indexOf("%>",a);return a===i&&s.slice(a+2,c).trim()==="}"?c+2:i})()}}parseTemplateBlock(t,e){const s=[];let n=e;for(;n<t.length;){const r=t.indexOf("<%",n);if(r===-1){n<t.length&&s.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}r>n&&s.push(this.createAppendLiteral(t.slice(n,r)));const i=t.indexOf("%>",r);if(i===-1)throw new Error("Unclosed EJS tag within block");const a=t.slice(r+2,i).trim();if(a==="}"||a.startsWith("} else")){n=r;break}if(n=i+2,a.startsWith("=")||a.startsWith("-")){const c=a.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const c=this.parseIfStatement(a,t,n);s.push(c),n=c.endPos||n}else if(a.startsWith("for")){const c=this.parseForStatement(a,t,n);s.push(c),n=c.endPos||n}else{const c=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const p=c[1],l=c[2],u=this.parseForEachStatement(p,l,t,n);s.push(u),n=u.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${a}`)}}}return{body:s,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of J){const r=t.lastIndexOf(n);if(r>0&&t[r-1]!=="!"&&t[r-1]!=="="&&t[r-1]!=="<"&&t[r-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:_[n],left:this.parseJsExpression(t.slice(0,r).trim()),right:this.parseJsExpression(t.slice(r+n.length).trim())}}const e=t.indexOf("."),s=t.indexOf("[");if(e>0&&(s===-1||e<s)||s>0&&(e===-1||s<e)){const n=e>0&&(s===-1||e<s)?e:s;let r,i,a=!1;if(n===e)r=t.slice(0,e),i={type:"Identifier",name:t.slice(e+1)},a=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const p=t.slice(s+1,c);i=/^(['"]).*\1$/.test(p)||/^-?\d+(\.\d+)?$/.test(p)?this.parseJsExpression(p):{type:"Identifier",name:p},a=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:i,computed:a}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),s=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
4
+ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax({dataResolver:t}){return`<% if (${this._parseCondition(t.condition)}) { %>`}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}getFullPath({collectionId:t,path:e,variableType:s}){return(t?[this._sanitizeVariableName(t),s,e].filter(Boolean).join("."):e)||""}_parseCondition(t){if(!t)return"";if(A(t)){const e=t.statements.map(r=>this._parseCondition(r)),s=j[t.logicalOperator];let n=e.length>1?`(${e.join(`)${s}(`)})`:e[0];return t.logicalOperator==="xor"&&(n=`!!(${n})`),n}else{const e=this._parseValue(t.left),s=this._parseValue(t.right);switch(t.operator){case"equals":return`${e} === ${s}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${e} ${t.operator} ${s}`;case"contains":return`${e}?.includes(${s})`;case"startsWith":return`${e}?.startsWith(${s})`;case"endsWith":return`${e}?.endsWith(${s})`;case"equalsIgnoreCase":return`${e}?.toLowerCase() === ${s}?.toLowerCase()`;case"trimEquals":return`${e}?.trim() === ${s}?.trim()`;case"isTruthy":return`!!${e}`;case"isFalsy":return`!${e}`;case"isDefined":return`${e} !== undefined`;case"isNull":return`${e} === null`;case"isUndefined":return`${e} === undefined`;case"isArray":return`Array.isArray(${e})`;case"isObject":return`typeof ${e} === 'object' && ${e} !== null && !Array.isArray(${e})`;case"isString":return`typeof ${e} === 'string'`;case"isNumber":return`typeof ${e} === 'number' && !isNaN(${e})`;case"isBoolean":return`typeof ${e} === 'boolean'`;default:return`${e} ${t.operator} ${s}`}}}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}}const j={and:"&&",or:"||",xor:"^"},W=["===","==","!==","!=","<=",">=","<",">","&&","||"],J={"===":"=","==":"=","!==":"!=","!=":"!=","<=":"<=",">=":">=","<":"<",">":">","&&":"&&","||":"||"};class F{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];try{const e=this.parseEjsTemplate(t);return this.astToGrapesJS(e)}catch(e){return console.error("Error during import:",e),this.addMessage("error",`Error during import: ${e instanceof Error?e.message:String(e)}`),""}}parseEjsTemplate(t){const e=[];let s=0;for(;s<t.length;){const n=t.indexOf("<%",s);if(n===-1){s<t.length&&e.push(this.createAppendLiteral(t.slice(s)));break}n>s&&e.push(this.createAppendLiteral(t.slice(s,n)));const r=t.indexOf("%>",n);if(r===-1)throw new Error("Unclosed EJS tag");const i=t.slice(n+2,r).trim();if(s=r+2,i.startsWith("=")||i.startsWith("-")){const a=i.slice(1).trim();e.push(this.createAppendExpression(a))}else{if(i.startsWith("#"))continue;if(i.startsWith("if")){const a=this.parseIfStatement(i,t,s);e.push(a),s=a.endPos||s}else if(i.startsWith("for")){const a=this.parseForStatement(i,t,s);e.push(a),s=a.endPos||s}else{const a=i.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(a){const c=a[1],p=a[2],l=this.parseForEachStatement(c,p,t,s);e.push(l),s=l.endPos||s}else this.addMessage("info",`Unsupported scriptlet content: ${i}`)}}}return{type:"Program",body:e}}createAppendLiteral(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[{type:"Literal",value:t}]}}}createAppendExpression(t){return{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"__append"},arguments:[this.parseJsExpression(t)]}}}parseIfStatement(t,e,s){const n=t.match(/if\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid if statement syntax");const r=this.parseJsExpression(n[1]),{body:i,endPos:a}=this.parseTemplateBlock(e,s);let c=null,p=a;const l=e.indexOf("<%",p);if(l===p){const u=e.indexOf("%>",l);if(u!==-1){const d=e.slice(l+2,u).trim(),f=u+2-l;if(d.startsWith("} else if")){p=l+f;const S=d.substring(d.indexOf("if")).trim(),h=this.parseIfStatement(S,e,p);c={type:"IfStatement",test:h.test,consequent:h.consequent,alternate:h.alternate},p=h.endPos}else if(d.startsWith("} else")){p=l+f;const{body:S,endPos:h}=this.parseTemplateBlock(e,p);c={type:"BlockStatement",body:S},p=h;const E=e.indexOf("<%",p),x=e.indexOf("%>",E);E===p&&e.slice(E+2,x).trim()==="}"&&(p=x+2)}else d==="}"&&(p=l+f)}}return{type:"IfStatement",test:r,consequent:{type:"BlockStatement",body:i},alternate:c,endPos:p}}parseForStatement(t,e,s){const n=t.match(/for\s*\((.*)\)\s*\{?/);if(!n)throw new Error("Invalid for statement syntax");const r=n[1].split("of");if(r.length!==2)throw new Error("Only for...of loops are supported");const i=r[0].trim().replace(/^let\s+|^const\s+|^var\s+/,""),a=r[1].trim(),{body:c,endPos:p}=this.parseTemplateBlock(e,s);return{type:"ForStatement",init:{type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:i},init:this.parseJsExpression(a)}]},test:null,update:null,body:{type:"BlockStatement",body:c},endPos:(()=>{const l=e.indexOf("<%",p),u=e.indexOf("%>",l);return l===p&&e.slice(l+2,u).trim()==="}"?u+2:p})()}}parseForEachStatement(t,e,s,n){const{body:r,endPos:i}=this.parseTemplateBlock(s,n);return{type:"ForEachStatement",collection:this.parseJsExpression(t),itemIdentifier:{type:"Identifier",name:e},body:{type:"BlockStatement",body:r},endPos:(()=>{const a=s.indexOf("<%",i),c=s.indexOf("%>",a);return a===i&&s.slice(a+2,c).trim()==="}"?c+2:i})()}}parseTemplateBlock(t,e){const s=[];let n=e;for(;n<t.length;){const r=t.indexOf("<%",n);if(r===-1){n<t.length&&s.push(this.createAppendLiteral(t.slice(n))),n=t.length;break}r>n&&s.push(this.createAppendLiteral(t.slice(n,r)));const i=t.indexOf("%>",r);if(i===-1)throw new Error("Unclosed EJS tag within block");const a=t.slice(r+2,i).trim();if(a==="}"||a.startsWith("} else")){n=r;break}if(n=i+2,a.startsWith("=")||a.startsWith("-")){const c=a.slice(1).trim();s.push(this.createAppendExpression(c))}else{if(a.startsWith("#"))continue;if(a.startsWith("if")){const c=this.parseIfStatement(a,t,n);s.push(c),n=c.endPos||n}else if(a.startsWith("for")){const c=this.parseForStatement(a,t,n);s.push(c),n=c.endPos||n}else{const c=a.match(/([\w][\w.-]*[\w])\s*\.\s*forEach\s*\(\s*(\w+)\s*=>\s*\{?/);if(c){const p=c[1],l=c[2],u=this.parseForEachStatement(p,l,t,n);s.push(u),n=u.endPos||n}else this.addMessage("info",`Unsupported scriptlet content within block: ${a}`)}}}return{body:s,endPos:n}}parseJsExpression(t){if(/^(['"]).*\1$/.test(t))return{type:"Literal",value:t.slice(1,-1)};if(/^-?\d+$/.test(t))return{type:"Literal",value:parseInt(t,10)};if(/^-?\d+\.\d+$/.test(t))return{type:"Literal",value:parseFloat(t)};if(t==="true"||t==="false")return{type:"Literal",value:t==="true"};for(const n of W){const r=t.lastIndexOf(n);if(r>0&&t[r-1]!=="!"&&t[r-1]!=="="&&t[r-1]!=="<"&&t[r-1]!==">")return{type:n==="&&"||n==="||"?"LogicalExpression":"BinaryExpression",operator:J[n],left:this.parseJsExpression(t.slice(0,r).trim()),right:this.parseJsExpression(t.slice(r+n.length).trim())}}const e=t.indexOf("."),s=t.indexOf("[");if(e>0&&(s===-1||e<s)||s>0&&(e===-1||s<e)){const n=e>0&&(s===-1||e<s)?e:s;let r,i,a=!1;if(n===e)r=t.slice(0,e),i={type:"Identifier",name:t.slice(e+1)},a=!1;else{r=t.slice(0,s);const c=t.indexOf("]",s);if(c===-1)throw new Error("Unclosed bracket in expression");const p=t.slice(s+1,c);i=/^(['"]).*\1$/.test(p)||/^-?\d+(\.\d+)?$/.test(p)?this.parseJsExpression(p):{type:"Identifier",name:p},a=!0}return{type:"MemberExpression",object:this.parseJsExpression(r),property:i,computed:a}}return{type:"Identifier",name:t}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"VariableDeclaration":return this.handleVariableDeclaration(t);case"ExpressionStatement":return this.handleExpressionStatement(t);case"IfStatement":return this.handleIfStatement(t);case"ForStatement":return this.handleForStatement(t);case"ForEachStatement":return this.handleForEachStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"Literal":return this.handleLiteral(t);case"Identifier":return this.handleIdentifier(t);case"MemberExpression":return this.handleMemberExpression(t);case"BinaryExpression":return this.handleBinaryExpression(t);case"LogicalExpression":return this.handleLogicalExpression(t);case"CallExpression":return this.handleCallExpression(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`),""}}handleProgram(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleVariableDeclaration(t){return""}handleExpressionStatement(t){return t.expression.type==="CallExpression"&&t.expression.callee.type==="Identifier"&&t.expression.callee.name==="__append"&&t.expression.arguments.length>0?this.astToGrapesJS(t.expression.arguments[0]):""}handleIfStatement(t){const e=this.getConditionExpression(t.test),s=this.astToGrapesJS(t.consequent);let n="";return t.alternate&&(n=this.astToGrapesJS(t.alternate)),`
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>
@@ -18,4 +18,4 @@ const ${a}={ currentItem, currentIndex: startIndex + index, remainingItems: endI
18
18
  ${r}
19
19
  </data-collection-item>
20
20
  </data-collection>
21
- `}handleBlockStatement(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const s=this.collectionStack[this.collectionStack.length-1];t.name===s&&(e={collectionId:s,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];let i=t;const a=[];for(;i.type==="MemberExpression";)i.property.type==="Identifier"&&!i.computed?a.unshift(i.property.name):i.property.type==="Literal"&&i.computed?a.unshift(String(i.property.value)):a.unshift(this.getExpressionString(i.property)),i=i.object;if(i.type==="Identifier"&&i.name===r){const c=a.join(".");n={...e,collectionId:r,variableType:"currentItem",path:c}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const s=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${s}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),s="isTruthy";return e.startsWith("!!")?(s="isTruthy",e=e.slice(2)):e.startsWith("!")&&(s="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:s}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),s=this.getConditionExpression(t.right);return`${e} ${t.operator} ${s}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),s=this.getExpressionString(t.property);return t.computed?`${e}[${s}]`:`${e}.${s}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const U="dataSourceEjs",D=y.startup;return T(function(o,t={}){const e=j(o,new W),s=M(o,{contains:"<%",importer:new F});v({editor:o,licenseKey:t.licenseKey,plan:D,pluginName:U,cleanup:()=>{e(),s()}})})});
21
+ `}handleBlockStatement(t){let e="";for(const s of t.body)e+=this.astToGrapesJS(s);return e}handleLiteral(t){return String(t.value??"")}handleIdentifier(t){let e={path:t.name};if(this.collectionStack.length>0){const s=this.collectionStack[this.collectionStack.length-1];t.name===s&&(e={collectionId:s,variableType:"currentItem"})}return`<data-variable data-gjs-data-resolver='${JSON.stringify(e)}'></data-variable>`}handleMemberExpression(t,e={}){let n={path:this.getExpressionString(t),...e};if(this.collectionStack.length>0){const r=this.collectionStack[this.collectionStack.length-1];let i=t;const a=[];for(;i.type==="MemberExpression";)i.property.type==="Identifier"&&!i.computed?a.unshift(i.property.name):i.property.type==="Literal"&&i.computed?a.unshift(String(i.property.value)):a.unshift(this.getExpressionString(i.property)),i=i.object;if(i.type==="Identifier"&&i.name===r){const c=a.join(".");n={...e,collectionId:r,variableType:"currentItem",path:c}}}return`<data-variable data-gjs-data-resolver='${JSON.stringify(n)}'></data-variable>`}handleBinaryExpression(t){return`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleLogicalExpression(t){return t.operator==="||"&&t.right.type==="Literal"?this.handleMemberExpression(t.left,{defaultValue:t.right.value}):`${this.getExpressionString(t.left)} ${t.operator} ${this.getExpressionString(t.right)}`}handleCallExpression(t){var e;if(t.callee.type==="Identifier"&&t.callee.name==="include"){const s=((e=t.arguments[0])==null?void 0:e.type)==="Literal"?String(t.arguments[0].value):"";return this.addMessage("info",`Partial includes are not fully supported: ${s}`),""}return""}getConditionExpression(t){if(t.type==="Identifier")return{logicalOperator:"and",statements:[{left:{type:"data-variable",path:t.name},operator:"isTruthy"}]};if(t.type==="MemberExpression"){let e=this.getExpressionString(t),s="isTruthy";return e.startsWith("!!")?(s="isTruthy",e=e.slice(2)):e.startsWith("!")&&(s="isFalsy",e=e.slice(1)),{logicalOperator:"and",statements:[{left:{type:"data-variable",path:e},operator:s}]}}if(t.type==="BinaryExpression"||t.type==="LogicalExpression"){const e=this.getConditionExpression(t.left),s=this.getConditionExpression(t.right);return`${e} ${t.operator} ${s}`}return t.type==="Literal"?typeof t.value=="string"?`'${t.value}'`:String(t.value??""):this.getExpressionString(t)}getExpressionString(t){switch(t.type){case"Identifier":return t.name;case"Literal":return String(t.value??"");case"MemberExpression":{const e=this.getExpressionString(t.object),s=this.getExpressionString(t.property);return t.computed?`${e}[${s}]`:`${e}.${s}`}case"BinaryExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}case"LogicalExpression":{const e=this.getExpressionString(t.left),s=this.getExpressionString(t.right);return`${e} ${t.operator} ${s}`}default:return this.addMessage("warning",`Unsupported expression type for getExpressionString: ${t.type}`),""}}addMessage(t,e){this.messages.push({type:t,message:e})}}const D="dataSourceEjs",U=y.startup;return T(function(o,t={}){const e=M(o,new _),s=B(o,{contains:"<%",importer:new F});C({editor:o,licenseKey:t.licenseKey,plan:U,pluginName:D,cleanup:()=>{e(),s()}})})});
@@ -1,10 +1,10 @@
1
- "use strict";const C=require("handlebars/dist/cjs/handlebars"),S="app.grapesjs.com",y="app-stage.grapesjs.com",f=[S,y,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],I="license:check:start",k="license:check:end",v=()=>typeof window<"u",N=({isDev:i,isStage:t})=>`${i?"":`https://${t?y:S}`}/api`,_=()=>{const i=v()&&window.location.hostname;return!!i&&(f.includes(i)||f.some(t=>i.endsWith(t)))};async function L({path:i,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:a}){const o=`${t||N({isDev:!1,isStage:!1})}${i}`,c={method:e,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const h=s?new URLSearchParams(s).toString():"",l=h?`?${h}`:"",u=await fetch(`${o}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}var p=(i=>(i.free="free",i.startup="startup",i.business="business",i.enterprise="enterprise",i))(p||{});const P={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function T(i){const t=i;return t.init=e=>n=>i(n,e),t}const w=i=>T(i);async function O({editor:i,plan:t,pluginName:e,licenseKey:n,cleanup:s}){let a="",r=!1;const o=_(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),s()},h=(l={})=>{var g;const{error:u,sdkLicense:b}=l,m=(g=l.plan)==null?void 0:g.category;if(!(b||l.license)||u)c(u||"Invalid license");else if(m){const x=P[t],E=P[m];x>E&&c({pluginRequiredPlan:t,licensePlan:m})}};i.on(I,l=>{a=l==null?void 0:l.baseApiUrl,r=!0}),i.on(k,l=>{h(l)}),setTimeout(async()=>{if(!r){if(o)return;if(n){const l=await A({licenseKey:n,pluginName:e,baseApiUrl:a});l&&h(l)}else c("The `licenseKey` option not provided")}},2e3)}async function A(i){const{licenseKey:t,pluginName:e,baseApiUrl:n}=i;try{return(await L({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(s){return console.error("Error during SDK license check:",s),!1}}const j=(i,t)=>(i.config.optsHtml={...i.config.optsHtml,exporter:t},()=>{i.config.optsHtml.exporter=void 0}),H=(i,t)=>{const e=s=>{const{input:a}=s,{contains:r}=t;(!r||a.includes(r))&&(s.input=t.importer.import(a))},n=i.Parser.events.htmlBefore;return i.on(n,e),()=>{i.off(n,e)}},$={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},M={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},U={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},B={...$,...M,...U};class D{getHelperId(t){return B[t]||t}getFullPath({collectionId:t,path:e}){let n=e;return t&&(n=[this._sanitizeVariableName(t),e].filter(Boolean).join(".")),n||""}getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,n=this.getFullPath(t);return e?`{{#if ${n}}}{{{${n}}}}{{else}}${e}{{/if}}`:`{{{${n}}}}`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:n}=t,s=n==null?void 0:n.path;let a="";if(t.startIndex!==void 0||t.endIndex!==void 0){const h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?a=` (slice ${s} ${h} ${l})`:a=` (slice ${s} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${a||s}${o}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:t}){const e=t.condition;if(!e)return"";const n=e,s=e;if(s.statements&&s.logicalOperator==="and"||s.logicalOperator==="or"){const{statements:a}=s,r=s.logicalOperator,o=a.map(h=>this._parseCondition(h)).join(" ");return`{{#if ${a.length>1?`(${r} ${o})`:o}}}`}else return`{{#if ${this._parseCondition(n)}}}`}_parseCondition(t){if(!t)return"";const e=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:s}=n,a=n.logicalOperator,r=n.statements.map(o=>this._parseCondition(o)).join(" ");return s.length>1?`(${a} ${r})`:r}else{const s=e.operator,a=this.getHelperId(s),r=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(a,r,o)}}getExpressionStr(t,e,n){return $[t]?t==="isTruthy"?e:t==="isFalsy"?`!${e}`:`${t} ${e}`:`(${t} ${e} ${n})`}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class R{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return C.parse(t)}catch(e){if(e instanceof Error&&e.message.includes("Parse error")){const n=e.message.match(/line (\d+)/),s=n?parseInt(n[1]):0,a=e.message.match(/column (\d+)/),r=a?parseInt(a[1]):0;throw new Error(`Handlebars syntax error at line ${s}, column ${r}: ${e.message}`)}throw e}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"ContentStatement":return this.handleContentStatement(t);case"MustacheStatement":return this.handleMustacheStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"PartialStatement":return this.handlePartialStatement(t);case"CommentStatement":return this.handleCommentStatement(t);case"ElementNode":return this.handleElementNode(t);case"TextNode":return this.handleTextNode(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`,t.loc),""}}handleProgram(t){let e="";if(t.body)for(const n of t.body)e+=this.astToGrapesJS(n);return e}handleContentStatement(t){return t.value||""}handleMustacheStatement(t,e={}){const n=this.getExpressionString(t.path),s={...e};return this.collectionStack.length>0?this.processPathWithCollectionContext(n,s):s.path=n,`<data-variable data-gjs-data-resolver='${JSON.stringify(s)}'></data-variable>`}processPathWithCollectionContext(t,e){t.startsWith("@")?this.handleDirectCollectionReference(t,e):this.handleRelativePathReference(t,e)}handleDirectCollectionReference(t,e){if(this.isSpecialIterationVariable(t)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],t,e);return}const[n,...s]=t.substring(1).split("/"),a=s.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,a,e):this.handleParentReferenceFallback(t,e)}isSpecialIterationVariable(t){return["index","@index","key","@key"].includes(t)}setSpecialVariableResolver(t,e,n){n.collectionId=t;const s={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};n.variableType=s[e]}setCurrentItemResolver(t,e,n){n.collectionId=t,n.variableType="currentItem",e&&(n.path=e)}handleRelativePathReference(t,e){const n=d(t),{parentLevel:s,remainingPathParts:a}=this.calculateParentLevel(n),r=a.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=a.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(a=>a===t[0]);if(e!==-1)return{parentLevel:this.collectionStack.length-1-e,remainingPathParts:t.slice(1)};let n=0;const s=[...t];for(;s[0]==="..";)n++,s.shift();return{parentLevel:n,remainingPathParts:s}}resolveRelativePath(t,e,n){const s=this.collectionStack[e];n.collectionId=s,n.variableType="currentItem",t!=="this"&&(n.path=t.startsWith("this.")?t.split(".").slice(1).join("."):t)}handleParentReferenceFallback(t,e){const n=d(t),{parentLevel:s,remainingPathParts:a}=this.calculateParentLevel(n),r=a.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=a.join(".")}handleBlockStatement(t){const e=t.path.original;switch(e){case"if":case"unless":return this.handleConditionalBlock(t,e);case"each":return this.handleEachBlock(t);default:return this.addMessage("warning",`Unsupported block helper: ${e}`,t.loc),this.handleGenericBlock(t)}}handleConditionalBlock(t,e){const a={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:e==="unless"?"isFalsy":"isTruthy"}]},r=this.handleProgram(t.program),o=t.inverse?this.handleProgram(t.inverse):"";return`
2
- <data-condition data-gjs-data-resolver='${JSON.stringify({condition:a})}'>
1
+ "use strict";const I=require("handlebars/dist/cjs/handlebars"),S="app.grapesjs.com",y="app-stage.grapesjs.com",C="app2.grapesjs.com",k="app-stage2.grapesjs.com",f=[S,C,y,k,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],v="license:check:start",N="license:check:end",_=()=>typeof window<"u",T=({isDev:a,isStage:t})=>`${a?"":`https://${t?y:S}`}/api`,L=()=>{const a=_()&&window.location.hostname;return!!a&&(f.includes(a)||f.some(t=>a.endsWith(t)))};async function w({path:a,baseApiUrl:t,method:e="GET",headers:n={},params:s,body:i}){const o=`${t||T({isDev:!1,isStage:!1})}${a}`,c={method:e,headers:{"Content-Type":"application/json",...n}};i&&(c.body=JSON.stringify(i));const h=s?new URLSearchParams(s).toString():"",l=h?`?${h}`:"",u=await fetch(`${o}${l}`,c);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}var p=(a=>(a.free="free",a.startup="startup",a.business="business",a.enterprise="enterprise",a))(p||{});const P={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function O(a){const t=a;return t.init=e=>n=>a(n,e),t}const A=a=>O(a);async function j({editor:a,plan:t,pluginName:e,licenseKey:n,cleanup:s}){let i="",r=!1;const o=L(),c=l=>{console.warn("Cleanup plugin:",e,"Reason:",l),s()},h=(l={})=>{var g;const{error:u,sdkLicense:b}=l,m=(g=l.plan)==null?void 0:g.category;if(!(b||l.license)||u)c(u||"Invalid license");else if(m){const x=P[t],E=P[m];x>E&&c({pluginRequiredPlan:t,licensePlan:m})}};a.on(v,l=>{i=l==null?void 0:l.baseApiUrl,r=!0}),a.on(N,l=>{h(l)}),setTimeout(async()=>{if(!r){if(o)return;if(n){const l=await D({licenseKey:n,pluginName:e,baseApiUrl:i});l&&h(l)}else c("The `licenseKey` option not provided")}},2e3)}async function D(a){const{licenseKey:t,pluginName:e,baseApiUrl:n}=a;try{return(await w({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:e}})).result||{}}catch(s){return console.error("Error during SDK license check:",s),!1}}const M=(a,t)=>(a.config.optsHtml={...a.config.optsHtml,exporter:t},()=>{a.config.optsHtml.exporter=void 0}),H=(a,t)=>{const e=s=>{const{input:i}=s,{contains:r}=t;(!r||i.includes(r))&&(s.input=t.importer.import(i))},n=a.Parser.events.htmlBefore;return a.on(n,e),()=>{a.off(n,e)}},$={equals:"equals",isTruthy:"isTruthy",isFalsy:"isFalsy",isDefined:"isDefined",isNull:"isNull",isUndefined:"isUndefined",isArray:"isArray",isObject:"isObject",isString:"isString",isNumber:"isNumber",isBoolean:"isBoolean",isDefaultValue:"isDefaultValue"},R={">":"numGt","<":"numLt",">=":"numGte","<=":"numLte","=":"numEq","!=":"numNeq"},U={contains:"strContains",startsWith:"strStartsWith",endsWith:"strEndsWith",equalsIgnoreCase:"strEqualsIgnoreCase",trimEquals:"strTrimEquals"},B={...$,...R,...U};class W{getHelperId(t){return B[t]||t}getFullPath({collectionId:t,path:e}){let n=e;return t&&(n=[this._sanitizeVariableName(t),e].filter(Boolean).join(".")),n||""}getVariableSyntax({dataResolver:t}){const{defaultValue:e}=t,n=this.getFullPath(t);return e?`{{#if ${n}}}{{{${n}}}}{{else}}${e}{{/if}}`:`{{{${n}}}}`}getCollectionStartSyntax({dataResolver:t}){const{collectionId:e,dataSource:n}=t,s=n==null?void 0:n.path;let i="";if(t.startIndex!==void 0||t.endIndex!==void 0){const h=t.startIndex??0,l=t.endIndex!==void 0?t.endIndex:"";l!==""?i=` (slice ${s} ${h} ${l})`:i=` (slice ${s} ${h})`}const o=` as |${this._sanitizeVariableName(e)}|`;return`{{#each ${i||s}${o}}}`}getCollectionEndSyntax(){return"{{/each}}"}getConditionalStartSyntax({dataResolver:t}){const e=t.condition;if(!e)return"";const n=e,s=e;if(s.statements&&s.logicalOperator==="and"||s.logicalOperator==="or"){const{statements:i}=s,r=s.logicalOperator,o=i.map(h=>this._parseCondition(h)).join(" ");return`{{#if ${i.length>1?`(${r} ${o})`:o}}}`}else return`{{#if ${this._parseCondition(n)}}}`}_parseCondition(t){if(!t)return"";const e=t,n=t;if(n.statements&&n.logicalOperator==="and"||n.logicalOperator==="or"){const{statements:s}=n,i=n.logicalOperator,r=n.statements.map(o=>this._parseCondition(o)).join(" ");return s.length>1?`(${i} ${r})`:r}else{const s=e.operator,i=this.getHelperId(s),r=this._parseValue(e.left),o=this._parseValue(e.right);return this.getExpressionStr(i,r,o)}}getExpressionStr(t,e,n){return $[t]?t==="isTruthy"?e:t==="isFalsy"?`!${e}`:`${t} ${e}`:`(${t} ${e} ${n})`}_parseValue(t){return typeof t=="object"?this.getFullPath(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getConditionElseSyntax(){return"{{else}}"}getConditionalEndSyntax(){return"{{/if}}"}}class V{constructor(){this.messages=[],this.collectionStack=[]}import(t){this.messages=[],this.collectionStack=[];const e=this.parse(t);return this.astToGrapesJS(e)}parse(t){try{return I.parse(t)}catch(e){if(e instanceof Error&&e.message.includes("Parse error")){const n=e.message.match(/line (\d+)/),s=n?parseInt(n[1]):0,i=e.message.match(/column (\d+)/),r=i?parseInt(i[1]):0;throw new Error(`Handlebars syntax error at line ${s}, column ${r}: ${e.message}`)}throw e}}astToGrapesJS(t){switch(t.type){case"Program":return this.handleProgram(t);case"ContentStatement":return this.handleContentStatement(t);case"MustacheStatement":return this.handleMustacheStatement(t);case"BlockStatement":return this.handleBlockStatement(t);case"PartialStatement":return this.handlePartialStatement(t);case"CommentStatement":return this.handleCommentStatement(t);case"ElementNode":return this.handleElementNode(t);case"TextNode":return this.handleTextNode(t);default:return this.addMessage("warning",`Unsupported node type: ${t.type}`,t.loc),""}}handleProgram(t){let e="";if(t.body)for(const n of t.body)e+=this.astToGrapesJS(n);return e}handleContentStatement(t){return t.value||""}handleMustacheStatement(t,e={}){const n=this.getExpressionString(t.path),s={...e};return this.collectionStack.length>0?this.processPathWithCollectionContext(n,s):s.path=n,`<data-variable data-gjs-data-resolver='${JSON.stringify(s)}'></data-variable>`}processPathWithCollectionContext(t,e){t.startsWith("@")?this.handleDirectCollectionReference(t,e):this.handleRelativePathReference(t,e)}handleDirectCollectionReference(t,e){if(this.isSpecialIterationVariable(t)){this.setSpecialVariableResolver(this.collectionStack[this.collectionStack.length-1],t,e);return}const[n,...s]=t.substring(1).split("/"),i=s.join(".");this.collectionStack.includes(n)?this.setCurrentItemResolver(n,i,e):this.handleParentReferenceFallback(t,e)}isSpecialIterationVariable(t){return["index","@index","key","@key"].includes(t)}setSpecialVariableResolver(t,e,n){n.collectionId=t;const s={index:"currentIndex","@index":"currentIndex",key:"currentKey","@key":"currentKey"};n.variableType=s[e]}setCurrentItemResolver(t,e,n){n.collectionId=t,n.variableType="currentItem",e&&(n.path=e)}handleRelativePathReference(t,e){const n=d(t),{parentLevel:s,remainingPathParts:i}=this.calculateParentLevel(n),r=i.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=i.join(".")}calculateParentLevel(t){const e=this.collectionStack.findLastIndex(i=>i===t[0]);if(e!==-1)return{parentLevel:this.collectionStack.length-1-e,remainingPathParts:t.slice(1)};let n=0;const s=[...t];for(;s[0]==="..";)n++,s.shift();return{parentLevel:n,remainingPathParts:s}}resolveRelativePath(t,e,n){const s=this.collectionStack[e];n.collectionId=s,n.variableType="currentItem",t!=="this"&&(n.path=t.startsWith("this.")?t.split(".").slice(1).join("."):t)}handleParentReferenceFallback(t,e){const n=d(t),{parentLevel:s,remainingPathParts:i}=this.calculateParentLevel(n),r=i.join("."),o=this.collectionStack.length-1-s;o>=0&&o<this.collectionStack.length?this.resolveRelativePath(r,o,e):e.path=i.join(".")}handleBlockStatement(t){const e=t.path.original;switch(e){case"if":case"unless":return this.handleConditionalBlock(t,e);case"each":return this.handleEachBlock(t);default:return this.addMessage("warning",`Unsupported block helper: ${e}`,t.loc),this.handleGenericBlock(t)}}handleConditionalBlock(t,e){const i={logicalOperator:"and",statements:[{left:{type:"data-variable",path:this.getExpressionString(t.params[0])},operator:e==="unless"?"isFalsy":"isTruthy"}]},r=this.handleProgram(t.program),o=t.inverse?this.handleProgram(t.inverse):"";return`
2
+ <data-condition data-gjs-data-resolver='${JSON.stringify({condition:i})}'>
3
3
  <data-condition-true-content>${r}</data-condition-true-content>
4
4
  <data-condition-false-content>${o}</data-condition-false-content>
5
5
  </data-condition>
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(),`
6
+ `}handleEachBlock(t){var i,r,o;const e=this.getExpressionString(t.params[0]);let n;t.params.length>=3&&t.params[1]==="as"&&((i=t.params[2])==null?void 0:i.type)==="PathExpression"?n=t.params[2].original:(o=(r=t.program)==null?void 0:r.blockParams)!=null&&o.length?n=t.program.blockParams[0]:n=`collection-${Math.random().toString(36).substring(2,10)}`,this.collectionStack.push(n);const s=this.handleProgram(t.program);return this.collectionStack.pop(),`
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=i=>{if(i==null||i==="")return[];if(i===".")return["this"];if(i===".."||i==="../")return[".."];if(i.startsWith("../")){const r=i.substring(3);return["..",...d(r)]}const t=[];let e=0,n=i.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(r,o,c,h)=>{const l=c!==void 0?c:h||"";return t[e]=l,`__HANDLEBARS_PLACEHOLDER_${e++}__`});n=n.replace(/\//g,".");const s=n.split("."),a=[];for(const r of s){const o=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);if(o){const c=parseInt(o[1],10);a.push(t[c])}else r!==""&&a.push(r)}return a},W="dataSourceHandlebars",V=p.startup,G=function(i,t={}){const e=j(i,new D),n=H(i,{contains:"{{",importer:new R});O({editor:i,licenseKey:t.licenseKey,plan:V,pluginName:W,cleanup:()=>{e(),n()}})},q=w(G);module.exports=q;
10
+ `}handleCommentStatement(t){return`<!--${t.value}-->`}handleElementNode(t){let e="";if(t.attributes)for(const s of t.attributes)s.value.type==="TextNode"?e+=` ${s.name}="${s.value.chars}"`:(this.addMessage("warning",`Complex attribute values not fully supported: ${s.name}`,t.loc),e+=` ${s.name}="${this.getExpressionString(s.value)}"`);let n="";if(t.children)for(const s of t.children)n+=this.astToGrapesJS(s);return`<${t.tag}${e}>${n}</${t.tag}>`}handleTextNode(t){return t.chars||""}handlePartialStatement(t){return this.addMessage("warning",`Partials are not fully supported: ${t.name.original}`,t.loc),`{{> ${t.name.original}}}`}handleGenericBlock(t){const e=this.handleProgram(t.program);return`<!-- Unsupported block: ${t.path.original} -->${e}`}getExpressionString(t){return t.type==="PathExpression"?t.original:t.type==="StringLiteral"?t.value:t.type==="NumberLiteral"?t.value.toString():t.type==="BooleanLiteral"?t.value?"true":"false":t.type==="SubExpression"?this.getExpressionString(t.params[0]):t.type==="Hash"?`{${t.pairs.map(n=>`${n.key}=${this.getExpressionString(n.value)}`).join(", ")}}`:(this.addMessage("warning",`Complex expression type not fully supported: ${t.type}`,t.loc),"")}addMessage(t,e,n){this.messages.push({type:t,message:e,location:n?{line:n.start.line,column:n.start.column}:void 0})}}const d=a=>{if(a==null||a==="")return[];if(a===".")return["this"];if(a===".."||a==="../")return[".."];if(a.startsWith("../")){const r=a.substring(3);return["..",...d(r)]}const t=[];let e=0,n=a.replace(/\[(?:(['"])(.*?)\1|([^\]]*))\]/g,(r,o,c,h)=>{const l=c!==void 0?c:h||"";return t[e]=l,`__HANDLEBARS_PLACEHOLDER_${e++}__`});n=n.replace(/\//g,".");const s=n.split("."),i=[];for(const r of s){const o=/^__HANDLEBARS_PLACEHOLDER_(\d+)__$/.exec(r);if(o){const c=parseInt(o[1],10);i.push(t[c])}else r!==""&&i.push(r)}return i},G="dataSourceHandlebars",q=p.startup,F=function(a,t={}){const e=M(a,new W),n=H(a,{contains:"{{",importer:new V});j({editor:a,licenseKey:t.licenseKey,plan:q,pluginName:G,cleanup:()=>{e(),n()}})},J=A(F);module.exports=J;