@grapesjs/studio-sdk-plugins 1.0.19 → 1.0.20-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvasAbsoluteMode/index.cjs.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -0
- package/dist/canvasAbsoluteMode/index.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.es.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.es.js +222 -0
- package/dist/canvasAbsoluteMode/index.umd.js +1 -0
- package/dist/canvasAbsoluteMode/shared.d.ts +3 -0
- package/dist/canvasAbsoluteMode/types.d.ts +3 -0
- package/dist/canvasAbsoluteMode/typesSchema.d.ts +21 -0
- package/dist/canvasAbsoluteMode/utils.d.ts +61 -0
- package/dist/dataSourceEjs/EjsStrategy.d.ts +15 -0
- package/dist/dataSourceEjs/index.cjs.d.ts +3 -0
- package/dist/dataSourceEjs/index.cjs.js +4 -0
- package/dist/dataSourceEjs/index.d.ts +3 -0
- package/dist/dataSourceEjs/index.es.d.ts +3 -0
- package/dist/dataSourceEjs/index.es.js +208 -0
- package/dist/dataSourceEjs/index.umd.js +4 -0
- package/dist/dataSourceEjs/types.d.ts +3 -0
- package/dist/dataSourceHandlebars/HandlebarsStrategy.d.ts +17 -0
- package/dist/dataSourceHandlebars/index.cjs.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.cjs.js +1 -0
- package/dist/dataSourceHandlebars/index.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.es.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.es.js +202 -0
- package/dist/dataSourceHandlebars/index.umd.js +1 -0
- package/dist/dataSourceHandlebars/types.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +10 -10
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +11 -11
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.d.ts +3 -0
- package/dist/index.cjs.js +42 -39
- package/dist/index.d.ts +3 -0
- package/dist/index.es.d.ts +3 -0
- package/dist/index.es.js +2920 -2592
- package/dist/index.umd.js +42 -39
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +10 -10
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/prosemirror/index.cjs.js +1 -1
- package/dist/prosemirror/index.es.js +1 -1
- package/dist/prosemirror/index.umd.js +1 -1
- package/dist/rendererReact/index.cjs.d.ts +3 -0
- package/dist/rendererReact/index.cjs.js +1 -0
- package/dist/rendererReact/index.d.ts +3 -0
- package/dist/rendererReact/index.es.d.ts +3 -0
- package/dist/rendererReact/index.es.js +405 -0
- package/dist/rendererReact/index.umd.js +1 -0
- package/dist/rendererReact/rendererCanvas/RenderCanvasComponent.d.ts +9 -0
- package/dist/rendererReact/rendererCanvas/customRenderer.d.ts +2 -0
- package/dist/rendererReact/rendererCanvas/util.d.ts +9 -0
- package/dist/rendererReact/rendererProject/GrapesJSProject.d.ts +3 -0
- package/dist/rendererReact/rendererProject/RenderProjectComponent.d.ts +12 -0
- package/dist/rendererReact/rendererProject/index.cjs.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.cjs.js +10 -0
- package/dist/rendererReact/rendererProject/index.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.es.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.es.js +446 -0
- package/dist/rendererReact/rendererProject/index.js +10 -0
- package/dist/rendererReact/rendererProject/index.umd.js +10 -0
- package/dist/rendererReact/rendererProject/parser/parser.d.ts +140 -0
- package/dist/rendererReact/rendererProject/types.d.ts +8 -0
- package/dist/rendererReact/rendererProject/util.d.ts +16 -0
- package/dist/rendererReact/shared/types.d.ts +49 -0
- package/dist/rendererReact/shared/util.d.ts +2 -0
- package/dist/rendererReact/types.d.ts +22 -0
- package/dist/rendererReact/typesSchema.d.ts +77 -0
- package/dist/rteTinyMce/index.cjs.js +2 -2
- package/dist/rteTinyMce/index.es.js +18 -18
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +19 -19
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +21 -21
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const W="app.grapesjs.com",Y="app-stage.grapesjs.com",B=[W,Y,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],V="license:check:start",k="license:check:end",H=()=>typeof window<"u",X=({isDev:e,isStage:d})=>`${e?"":`https://${d?Y:W}`}/api`,j=()=>{const e=H()&&window.location.hostname;return!!e&&(B.includes(e)||B.some(d=>e.endsWith(d)))};async function q({path:e,baseApiUrl:d,method:u="GET",headers:i={},params:n,body:s}){const a=`${d||X({isDev:!1,isStage:!1})}${e}`,m={method:u,headers:{"Content-Type":"application/json",...i}};s&&(m.body=JSON.stringify(s));const r=n?new URLSearchParams(n).toString():"",t=r?`?${r}`:"",o=await fetch(`${a}${t}`,m);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o.json()}var L=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(L||{});const $={[L.free]:0,[L.startup]:10,[L.business]:20,[L.enterprise]:30};function F(e){const d=e;return d.init=u=>i=>e(i,u),d}const J=e=>F(e);async function z({editor:e,plan:d,pluginName:u,licenseKey:i,cleanup:n}){let s="",h=!1;const a=j(),m=t=>{console.warn("Cleanup plugin:",u,"Reason:",t),n()},r=(t={})=>{var x;const{error:o,sdkLicense:f}=t,c=(x=t.plan)==null?void 0:x.category;if(!(f||t.license)||o)m(o||"Invalid license");else if(c){const p=$[d],g=$[c];p>g&&m({pluginRequiredPlan:d,licensePlan:c})}};e.on(V,t=>{s=t==null?void 0:t.baseApiUrl,h=!0}),e.on(k,t=>{r(t)}),setTimeout(async()=>{if(!h){if(a)return;if(i){const t=await Q({licenseKey:i,pluginName:u,baseApiUrl:s});t&&r(t)}else m("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:d,pluginName:u,baseApiUrl:i}=e;try{return(await q({baseApiUrl:i,path:`/sdk/${d||"na"}`,method:"POST",params:{d:window.location.hostname,pn:u}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const Z="canvasAbsoluteMode",ee=L.startup;function R({guideMatched:e,canvasView:d}){const u=e.guide.x===void 0?"y":"x";let i=0,n=0,s=0,h=0;const{guide:a,matched:m}=e,r=d.getElBoxRect(a.componentView.el),t=d.getElBoxRect(m.componentView.el),o=r.y,f=r.y+r.height,c=r.x,_=r.x+r.width,x=t.y,p=t.y+t.height,g=t.x,y=t.x+t.width,E=Math.max(0,o-p),l=Math.max(0,x-f),S=Math.max(0,c-y),O=Math.max(0,g-_),T=E>l,b=S>O,D=a.type;return u==="x"&&(D==="l"?(i=c,T?(n=p,s=E):(n=f,s=l)):D==="r"?(i=_,T?(n=p,s=E):(n=f,s=l)):D==="x"&&(i=c-(c-_)/2,T?(n=p,s=E):(n=f,s=l))),u==="y"&&(D==="t"?(n=o,b?(i=y,h=S):(i=_,h=O)):D==="b"?(n=f,b?(i=y,h=S):(i=_,h=O)):D==="y"&&(n=o-(o-f)/2,b?(i=y,h=S):(i=_,h=O))),{axis:u,x:i,y:n,width:h,height:s}}function te({guideMatched:e,component:d,canvasView:u}){const i=e.guide.x===void 0?"x":"y",{guide:n,matched:s}=e,h=n.type,a=s.type,m=u.getElementPos(n.componentView.el).rect,r=u.getElementPos(s.componentView.el).rect;if(i==="x"){const t=m.height,o=r.top,f=r.top+r.height;let c=0;h==="t"?a==="t"?c=o-t:a==="b"?c=f-t:a==="y"&&(c=o-t-(o-f)/2):h==="b"?a==="t"?c=o-t*2:a==="b"?c=f-t*2:a==="y"&&(c=o-t*2-(o-f)/2):h==="y"&&(a==="t"?c=o-t*1.5:a==="b"?c=f-t*1.5:a==="y"&&(c=o-t*1.5-(o-f)/2)),d.addStyle({top:`${c-5}px`},{partial:!0})}if(i==="y"){const t=m.width,o=r.left,f=r.left+r.width;let c=0;h==="l"?a==="l"?c=o:a==="r"?c=f:a==="x"&&(c=o-(o-f)/2):h==="r"?a==="l"?c=o-t:a==="r"?c=f-t:a==="x"&&(c=o-t-(o-f)/2):h==="x"&&(a==="l"?c=o-t/2:a==="r"&&(c=f-t/2)),d.addStyle({left:`${c}px`},{partial:!0})}}function K({snapping:e,editor:d,props:u}){var A,P;const{command:i,guidesMatched:n}=u,s=u.component,h=s.getEl(),a=d.Canvas.getCanvasView(),{x:m,y:r}=e??{x:10,y:10},t=i.opts.event,o=t.clientX,f=t.clientY;if(!s.__lastSnappedPosition){const w=a.getElBoxRect(h),v=o-w.x,C=f-w.y;s.__lastSnappedPosition={left:w.x,top:w.y},s.__dragOffset={x:v,y:C}}const c=((A=s.__dragOffset)==null?void 0:A.x)||0,_=((P=s.__dragOffset)==null?void 0:P.y)||0,x=s.__lastSnappedPosition,p=o-x.left-c,g=f-x.top-_;let y=x.left,E=x.top;const l=n==null?void 0:n[0],S=(l==null?void 0:l.guide.type)==="l",O=(l==null?void 0:l.guide.type)==="x",T=(l==null?void 0:l.guide.type)==="r",b=(l==null?void 0:l.guide.type)==="t",D=(l==null?void 0:l.guide.type)==="b",M=(l==null?void 0:l.guide.type)==="y";if(l){const{x:w,y:v}=R({guideMatched:l,canvasView:a}),C=h.offsetWidth,N=h.offsetHeight;S?y=w:T?y=w-C:O?y=w-C/2:b?E=v:D?E=v-N:M&&(E=v-N/2),s.__lastSnappedGuideMatched=l}else Math.abs(p)>=m&&(y=Math.round((x.left+p)/m)*m,s.__lastSnappedGuideMatched=null),Math.abs(g)>=r&&(E=Math.round((x.top+g)/r)*r,s.__lastSnappedGuideMatched=null);return s.addStyle({left:`${y}px`,top:`${E}px`},{partial:!0}),s.__lastSnappedPosition={left:y,top:E},{x:y,y:E,guideMatched:s.__lastSnappedGuideMatched}}function ne({snapping:e,props:d,editor:u}){const{x:i,y:n}=K({snapping:e,props:d,editor:u}),s=d.component;s.addStyle({left:`${i}px`,top:`${n}px`}),delete s.__lastSnappedPosition,delete s.__lastSnappedGuideMatched}const se="core:component-drag",oe="studio:setDragAbsolute",ie="dmode:start",U="dmode:move",I="dmode:end",G="dragAbsolute",ce="select",ae="hover",le="spacing",de=function(e,d={}){const u=e.Commands.getConfig().defaultOptions??{};u[se]={run:p=>({...p,skipGuidesRender:!0})};const{snapping:i,locking:n}=d,s=!!(i!=null&&i.x||i!=null&&i.y),h=!!(n!=null&&n.x||n!=null&&n.y),{Canvas:a}=e;let m=null;const r=p=>{const{component:g,guidesMatched:y,command:E}=p,l=g.view,S=e.Canvas.getCanvasView(),O=g.getEl();let T=y.map(M=>M.matched.componentEl),b=y.map(M=>R({guideMatched:M,canvasView:S}));if(s){const{guideMatched:M}=K({snapping:i,props:p,editor:e});M?(T=[M.matched.componentEl],b=[R({guideMatched:M,canvasView:S})]):(T=[],b=[])}if(h)if(E.opts.event.shiftKey)if(!m)m=y[0];else{const A=m,P=A.guide.x===void 0?"x":"y";(P==="x"&&(n==null?void 0:n.x)||P==="y"&&(n==null?void 0:n.y))&&(te({guideMatched:A,component:g,canvasView:S}),T=[A.matched.componentEl],b=[R({guideMatched:A,canvasView:S})])}else m=null;const D={id:G,type:G,component:g,componentView:l,originComponent:O,matchedComponents:T,originMatchedDistances:b};a.addSpot(D)},t=({enabled:p})=>{e.runCommand(oe,{enabled:p})},o=({type:p})=>{a.removeSpots({type:p})},f=()=>{o({type:ce}),o({type:ae}),o({type:le})},c=p=>{t({enabled:!0}),r(p),f()},_=p=>{r(p),f()},x=p=>{o({type:G}),s&&ne({snapping:i,props:p,editor:e}),t({enabled:!1})};e.on(ie,p=>{c(p),e.on(U,_);const g=()=>{x(p),e.off(U,_),e.off(I,g)};e.on(I,g)}),z({editor:e,licenseKey:d.licenseKey,plan:ee,pluginName:Z,cleanup:()=>t({enabled:!1})})},fe=J(de);module.exports=fe;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const W = "app.grapesjs.com", Y = "app-stage.grapesjs.com", B = [
|
|
2
|
+
W,
|
|
3
|
+
Y,
|
|
4
|
+
"localhost",
|
|
5
|
+
"127.0.0.1",
|
|
6
|
+
".local-credentialless.webcontainer.io",
|
|
7
|
+
// For stackblitz.com demos
|
|
8
|
+
".local.webcontainer.io",
|
|
9
|
+
// For stackblitz.com demos
|
|
10
|
+
"-sandpack.codesandbox.io"
|
|
11
|
+
// For Sandpack demos
|
|
12
|
+
], V = "license:check:start", k = "license:check:end", H = () => typeof window < "u", X = ({ isDev: e, isStage: d }) => `${e ? "" : `https://${d ? Y : W}`}/api`, j = () => {
|
|
13
|
+
const e = H() && window.location.hostname;
|
|
14
|
+
return !!e && (B.includes(e) || B.some((d) => e.endsWith(d)));
|
|
15
|
+
};
|
|
16
|
+
async function q({
|
|
17
|
+
path: e,
|
|
18
|
+
baseApiUrl: d,
|
|
19
|
+
method: u = "GET",
|
|
20
|
+
headers: i = {},
|
|
21
|
+
params: n,
|
|
22
|
+
body: s
|
|
23
|
+
}) {
|
|
24
|
+
const a = `${d || X({ isDev: !1, isStage: !1 })}${e}`, m = {
|
|
25
|
+
method: u,
|
|
26
|
+
headers: {
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
...i
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
s && (m.body = JSON.stringify(s));
|
|
32
|
+
const r = n ? new URLSearchParams(n).toString() : "", t = r ? `?${r}` : "", o = await fetch(`${a}${t}`, m);
|
|
33
|
+
if (!o.ok)
|
|
34
|
+
throw new Error(`HTTP error! status: ${o.status}`);
|
|
35
|
+
return o.json();
|
|
36
|
+
}
|
|
37
|
+
var L = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(L || {});
|
|
38
|
+
const $ = {
|
|
39
|
+
[L.free]: 0,
|
|
40
|
+
[L.startup]: 10,
|
|
41
|
+
[L.business]: 20,
|
|
42
|
+
[L.enterprise]: 30
|
|
43
|
+
};
|
|
44
|
+
function F(e) {
|
|
45
|
+
const d = e;
|
|
46
|
+
return d.init = (u) => (i) => e(i, u), d;
|
|
47
|
+
}
|
|
48
|
+
const J = (e) => /* @__PURE__ */ F(e);
|
|
49
|
+
async function z({
|
|
50
|
+
editor: e,
|
|
51
|
+
plan: d,
|
|
52
|
+
pluginName: u,
|
|
53
|
+
licenseKey: i,
|
|
54
|
+
cleanup: n
|
|
55
|
+
}) {
|
|
56
|
+
let s = "", h = !1;
|
|
57
|
+
const a = j(), m = (t) => {
|
|
58
|
+
console.warn("Cleanup plugin:", u, "Reason:", t), n();
|
|
59
|
+
}, r = (t = {}) => {
|
|
60
|
+
var x;
|
|
61
|
+
const { error: o, sdkLicense: f } = t, c = (x = t.plan) == null ? void 0 : x.category;
|
|
62
|
+
if (!(f || t.license) || o)
|
|
63
|
+
m(o || "Invalid license");
|
|
64
|
+
else if (c) {
|
|
65
|
+
const p = $[d], g = $[c];
|
|
66
|
+
p > g && m({ pluginRequiredPlan: d, licensePlan: c });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
e.on(V, (t) => {
|
|
70
|
+
s = t == null ? void 0 : t.baseApiUrl, h = !0;
|
|
71
|
+
}), e.on(k, (t) => {
|
|
72
|
+
r(t);
|
|
73
|
+
}), setTimeout(async () => {
|
|
74
|
+
if (!h) {
|
|
75
|
+
if (a) return;
|
|
76
|
+
if (i) {
|
|
77
|
+
const t = await Q({ licenseKey: i, pluginName: u, baseApiUrl: s });
|
|
78
|
+
t && r(t);
|
|
79
|
+
} else
|
|
80
|
+
m("The `licenseKey` option not provided");
|
|
81
|
+
}
|
|
82
|
+
}, 2e3);
|
|
83
|
+
}
|
|
84
|
+
async function Q(e) {
|
|
85
|
+
const { licenseKey: d, pluginName: u, baseApiUrl: i } = e;
|
|
86
|
+
try {
|
|
87
|
+
return (await q({
|
|
88
|
+
baseApiUrl: i,
|
|
89
|
+
path: `/sdk/${d || "na"}`,
|
|
90
|
+
method: "POST",
|
|
91
|
+
params: {
|
|
92
|
+
d: window.location.hostname,
|
|
93
|
+
pn: u
|
|
94
|
+
}
|
|
95
|
+
})).result || {};
|
|
96
|
+
} catch (n) {
|
|
97
|
+
return console.error("Error during SDK license check:", n), !1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const Z = "canvasAbsoluteMode", ee = L.startup;
|
|
101
|
+
function R({
|
|
102
|
+
guideMatched: e,
|
|
103
|
+
canvasView: d
|
|
104
|
+
}) {
|
|
105
|
+
const u = e.guide.x === void 0 ? "y" : "x";
|
|
106
|
+
let i = 0, n = 0, s = 0, h = 0;
|
|
107
|
+
const { guide: a, matched: m } = e, r = d.getElBoxRect(a.componentView.el), t = d.getElBoxRect(m.componentView.el), o = r.y, f = r.y + r.height, c = r.x, _ = r.x + r.width, x = t.y, p = t.y + t.height, g = t.x, y = t.x + t.width, E = Math.max(0, o - p), l = Math.max(0, x - f), S = Math.max(0, c - y), O = Math.max(0, g - _), T = E > l, b = S > O, D = a.type;
|
|
108
|
+
return u === "x" && (D === "l" ? (i = c, T ? (n = p, s = E) : (n = f, s = l)) : D === "r" ? (i = _, T ? (n = p, s = E) : (n = f, s = l)) : D === "x" && (i = c - (c - _) / 2, T ? (n = p, s = E) : (n = f, s = l))), u === "y" && (D === "t" ? (n = o, b ? (i = y, h = S) : (i = _, h = O)) : D === "b" ? (n = f, b ? (i = y, h = S) : (i = _, h = O)) : D === "y" && (n = o - (o - f) / 2, b ? (i = y, h = S) : (i = _, h = O))), { axis: u, x: i, y: n, width: h, height: s };
|
|
109
|
+
}
|
|
110
|
+
function te({
|
|
111
|
+
guideMatched: e,
|
|
112
|
+
component: d,
|
|
113
|
+
canvasView: u
|
|
114
|
+
}) {
|
|
115
|
+
const i = e.guide.x === void 0 ? "x" : "y", { guide: n, matched: s } = e, h = n.type, a = s.type, m = u.getElementPos(n.componentView.el).rect, r = u.getElementPos(s.componentView.el).rect;
|
|
116
|
+
if (i === "x") {
|
|
117
|
+
const t = m.height, o = r.top, f = r.top + r.height;
|
|
118
|
+
let c = 0;
|
|
119
|
+
h === "t" ? a === "t" ? c = o - t : a === "b" ? c = f - t : a === "y" && (c = o - t - (o - f) / 2) : h === "b" ? a === "t" ? c = o - t * 2 : a === "b" ? c = f - t * 2 : a === "y" && (c = o - t * 2 - (o - f) / 2) : h === "y" && (a === "t" ? c = o - t * 1.5 : a === "b" ? c = f - t * 1.5 : a === "y" && (c = o - t * 1.5 - (o - f) / 2)), d.addStyle({ top: `${c - 5}px` }, { partial: !0 });
|
|
120
|
+
}
|
|
121
|
+
if (i === "y") {
|
|
122
|
+
const t = m.width, o = r.left, f = r.left + r.width;
|
|
123
|
+
let c = 0;
|
|
124
|
+
h === "l" ? a === "l" ? c = o : a === "r" ? c = f : a === "x" && (c = o - (o - f) / 2) : h === "r" ? a === "l" ? c = o - t : a === "r" ? c = f - t : a === "x" && (c = o - t - (o - f) / 2) : h === "x" && (a === "l" ? c = o - t / 2 : a === "r" && (c = f - t / 2)), d.addStyle({ left: `${c}px` }, { partial: !0 });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function K({
|
|
128
|
+
snapping: e,
|
|
129
|
+
editor: d,
|
|
130
|
+
props: u
|
|
131
|
+
}) {
|
|
132
|
+
var A, P;
|
|
133
|
+
const { command: i, guidesMatched: n } = u, s = u.component, h = s.getEl(), a = d.Canvas.getCanvasView(), { x: m, y: r } = e ?? { x: 10, y: 10 }, t = i.opts.event, o = t.clientX, f = t.clientY;
|
|
134
|
+
if (!s.__lastSnappedPosition) {
|
|
135
|
+
const w = a.getElBoxRect(h), v = o - w.x, C = f - w.y;
|
|
136
|
+
s.__lastSnappedPosition = { left: w.x, top: w.y }, s.__dragOffset = { x: v, y: C };
|
|
137
|
+
}
|
|
138
|
+
const c = ((A = s.__dragOffset) == null ? void 0 : A.x) || 0, _ = ((P = s.__dragOffset) == null ? void 0 : P.y) || 0, x = s.__lastSnappedPosition, p = o - x.left - c, g = f - x.top - _;
|
|
139
|
+
let y = x.left, E = x.top;
|
|
140
|
+
const l = n == null ? void 0 : n[0], S = (l == null ? void 0 : l.guide.type) === "l", O = (l == null ? void 0 : l.guide.type) === "x", T = (l == null ? void 0 : l.guide.type) === "r", b = (l == null ? void 0 : l.guide.type) === "t", D = (l == null ? void 0 : l.guide.type) === "b", M = (l == null ? void 0 : l.guide.type) === "y";
|
|
141
|
+
if (l) {
|
|
142
|
+
const { x: w, y: v } = R({ guideMatched: l, canvasView: a }), C = h.offsetWidth, N = h.offsetHeight;
|
|
143
|
+
S ? y = w : T ? y = w - C : O ? y = w - C / 2 : b ? E = v : D ? E = v - N : M && (E = v - N / 2), s.__lastSnappedGuideMatched = l;
|
|
144
|
+
} else
|
|
145
|
+
Math.abs(p) >= m && (y = Math.round((x.left + p) / m) * m, s.__lastSnappedGuideMatched = null), Math.abs(g) >= r && (E = Math.round((x.top + g) / r) * r, s.__lastSnappedGuideMatched = null);
|
|
146
|
+
return s.addStyle({ left: `${y}px`, top: `${E}px` }, { partial: !0 }), s.__lastSnappedPosition = { left: y, top: E }, { x: y, y: E, guideMatched: s.__lastSnappedGuideMatched };
|
|
147
|
+
}
|
|
148
|
+
function ne({
|
|
149
|
+
snapping: e,
|
|
150
|
+
props: d,
|
|
151
|
+
editor: u
|
|
152
|
+
}) {
|
|
153
|
+
const { x: i, y: n } = K({ snapping: e, props: d, editor: u }), s = d.component;
|
|
154
|
+
s.addStyle({ left: `${i}px`, top: `${n}px` }), delete s.__lastSnappedPosition, delete s.__lastSnappedGuideMatched;
|
|
155
|
+
}
|
|
156
|
+
const se = "core:component-drag", oe = "studio:setDragAbsolute", ie = "dmode:start", U = "dmode:move", I = "dmode:end", G = "dragAbsolute", ce = "select", ae = "hover", le = "spacing", de = function(e, d = {}) {
|
|
157
|
+
const u = e.Commands.getConfig().defaultOptions ?? {};
|
|
158
|
+
u[se] = {
|
|
159
|
+
run: (p) => ({
|
|
160
|
+
...p,
|
|
161
|
+
skipGuidesRender: !0
|
|
162
|
+
})
|
|
163
|
+
};
|
|
164
|
+
const { snapping: i, locking: n } = d, s = !!(i != null && i.x || i != null && i.y), h = !!(n != null && n.x || n != null && n.y), { Canvas: a } = e;
|
|
165
|
+
let m = null;
|
|
166
|
+
const r = (p) => {
|
|
167
|
+
const { component: g, guidesMatched: y, command: E } = p, l = g.view, S = e.Canvas.getCanvasView(), O = g.getEl();
|
|
168
|
+
let T = y.map((M) => M.matched.componentEl), b = y.map((M) => R({ guideMatched: M, canvasView: S }));
|
|
169
|
+
if (s) {
|
|
170
|
+
const { guideMatched: M } = K({ snapping: i, props: p, editor: e });
|
|
171
|
+
M ? (T = [M.matched.componentEl], b = [R({ guideMatched: M, canvasView: S })]) : (T = [], b = []);
|
|
172
|
+
}
|
|
173
|
+
if (h)
|
|
174
|
+
if (E.opts.event.shiftKey)
|
|
175
|
+
if (!m)
|
|
176
|
+
m = y[0];
|
|
177
|
+
else {
|
|
178
|
+
const A = m, P = A.guide.x === void 0 ? "x" : "y";
|
|
179
|
+
(P === "x" && (n == null ? void 0 : n.x) || P === "y" && (n == null ? void 0 : n.y)) && (te({ guideMatched: A, component: g, canvasView: S }), T = [A.matched.componentEl], b = [R({ guideMatched: A, canvasView: S })]);
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
m = null;
|
|
183
|
+
const D = {
|
|
184
|
+
id: G,
|
|
185
|
+
type: G,
|
|
186
|
+
component: g,
|
|
187
|
+
componentView: l,
|
|
188
|
+
originComponent: O,
|
|
189
|
+
matchedComponents: T,
|
|
190
|
+
originMatchedDistances: b
|
|
191
|
+
};
|
|
192
|
+
a.addSpot(D);
|
|
193
|
+
}, t = ({ enabled: p }) => {
|
|
194
|
+
e.runCommand(oe, { enabled: p });
|
|
195
|
+
}, o = ({ type: p }) => {
|
|
196
|
+
a.removeSpots({ type: p });
|
|
197
|
+
}, f = () => {
|
|
198
|
+
o({ type: ce }), o({ type: ae }), o({ type: le });
|
|
199
|
+
}, c = (p) => {
|
|
200
|
+
t({ enabled: !0 }), r(p), f();
|
|
201
|
+
}, _ = (p) => {
|
|
202
|
+
r(p), f();
|
|
203
|
+
}, x = (p) => {
|
|
204
|
+
o({ type: G }), s && ne({ snapping: i, props: p, editor: e }), t({ enabled: !1 });
|
|
205
|
+
};
|
|
206
|
+
e.on(ie, (p) => {
|
|
207
|
+
c(p), e.on(U, _);
|
|
208
|
+
const g = () => {
|
|
209
|
+
x(p), e.off(U, _), e.off(I, g);
|
|
210
|
+
};
|
|
211
|
+
e.on(I, g);
|
|
212
|
+
}), z({
|
|
213
|
+
editor: e,
|
|
214
|
+
licenseKey: d.licenseKey,
|
|
215
|
+
plan: ee,
|
|
216
|
+
pluginName: Z,
|
|
217
|
+
cleanup: () => t({ enabled: !1 })
|
|
218
|
+
});
|
|
219
|
+
}, fe = J(de);
|
|
220
|
+
export {
|
|
221
|
+
fe as default
|
|
222
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(P,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(P=typeof globalThis<"u"?globalThis:P||self,P.StudioSdkPlugins_canvasAbsoluteMode=v())})(this,function(){"use strict";const P="app.grapesjs.com",v="app-stage.grapesjs.com",$=[P,v,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],K="license:check:start",V="license:check:end",H=()=>typeof window<"u",X=({isDev:e,isStage:d})=>`${e?"":`https://${d?v:P}`}/api`,j=()=>{const e=H()&&window.location.hostname;return!!e&&($.includes(e)||$.some(d=>e.endsWith(d)))};async function q({path:e,baseApiUrl:d,method:h="GET",headers:i={},params:n,body:s}){const a=`${d||X({isDev:!1,isStage:!1})}${e}`,m={method:h,headers:{"Content-Type":"application/json",...i}};s&&(m.body=JSON.stringify(s));const r=n?new URLSearchParams(n).toString():"",t=r?`?${r}`:"",o=await fetch(`${a}${t}`,m);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o.json()}var L=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(L||{});const U={[L.free]:0,[L.startup]:10,[L.business]:20,[L.enterprise]:30};function F(e){const d=e;return d.init=h=>i=>e(i,h),d}const J=e=>F(e);async function z({editor:e,plan:d,pluginName:h,licenseKey:i,cleanup:n}){let s="",u=!1;const a=j(),m=t=>{console.warn("Cleanup plugin:",h,"Reason:",t),n()},r=(t={})=>{var _;const{error:o,sdkLicense:f}=t,c=(_=t.plan)==null?void 0:_.category;if(!(f||t.license)||o)m(o||"Invalid license");else if(c){const p=U[d],g=U[c];p>g&&m({pluginRequiredPlan:d,licensePlan:c})}};e.on(K,t=>{s=t==null?void 0:t.baseApiUrl,u=!0}),e.on(V,t=>{r(t)}),setTimeout(async()=>{if(!u){if(a)return;if(i){const t=await Q({licenseKey:i,pluginName:h,baseApiUrl:s});t&&r(t)}else m("The `licenseKey` option not provided")}},2e3)}async function Q(e){const{licenseKey:d,pluginName:h,baseApiUrl:i}=e;try{return(await q({baseApiUrl:i,path:`/sdk/${d||"na"}`,method:"POST",params:{d:window.location.hostname,pn:h}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}const Z="canvasAbsoluteMode",ee=L.startup;function G({guideMatched:e,canvasView:d}){const h=e.guide.x===void 0?"y":"x";let i=0,n=0,s=0,u=0;const{guide:a,matched:m}=e,r=d.getElBoxRect(a.componentView.el),t=d.getElBoxRect(m.componentView.el),o=r.y,f=r.y+r.height,c=r.x,x=r.x+r.width,_=t.y,p=t.y+t.height,g=t.x,y=t.x+t.width,E=Math.max(0,o-p),l=Math.max(0,_-f),S=Math.max(0,c-y),O=Math.max(0,g-x),T=E>l,b=S>O,M=a.type;return h==="x"&&(M==="l"?(i=c,T?(n=p,s=E):(n=f,s=l)):M==="r"?(i=x,T?(n=p,s=E):(n=f,s=l)):M==="x"&&(i=c-(c-x)/2,T?(n=p,s=E):(n=f,s=l))),h==="y"&&(M==="t"?(n=o,b?(i=y,u=S):(i=x,u=O)):M==="b"?(n=f,b?(i=y,u=S):(i=x,u=O)):M==="y"&&(n=o-(o-f)/2,b?(i=y,u=S):(i=x,u=O))),{axis:h,x:i,y:n,width:u,height:s}}function te({guideMatched:e,component:d,canvasView:h}){const i=e.guide.x===void 0?"x":"y",{guide:n,matched:s}=e,u=n.type,a=s.type,m=h.getElementPos(n.componentView.el).rect,r=h.getElementPos(s.componentView.el).rect;if(i==="x"){const t=m.height,o=r.top,f=r.top+r.height;let c=0;u==="t"?a==="t"?c=o-t:a==="b"?c=f-t:a==="y"&&(c=o-t-(o-f)/2):u==="b"?a==="t"?c=o-t*2:a==="b"?c=f-t*2:a==="y"&&(c=o-t*2-(o-f)/2):u==="y"&&(a==="t"?c=o-t*1.5:a==="b"?c=f-t*1.5:a==="y"&&(c=o-t*1.5-(o-f)/2)),d.addStyle({top:`${c-5}px`},{partial:!0})}if(i==="y"){const t=m.width,o=r.left,f=r.left+r.width;let c=0;u==="l"?a==="l"?c=o:a==="r"?c=f:a==="x"&&(c=o-(o-f)/2):u==="r"?a==="l"?c=o-t:a==="r"?c=f-t:a==="x"&&(c=o-t-(o-f)/2):u==="x"&&(a==="l"?c=o-t/2:a==="r"&&(c=f-t/2)),d.addStyle({left:`${c}px`},{partial:!0})}}function I({snapping:e,editor:d,props:h}){var A,C;const{command:i,guidesMatched:n}=h,s=h.component,u=s.getEl(),a=d.Canvas.getCanvasView(),{x:m,y:r}=e??{x:10,y:10},t=i.opts.event,o=t.clientX,f=t.clientY;if(!s.__lastSnappedPosition){const w=a.getElBoxRect(u),R=o-w.x,N=f-w.y;s.__lastSnappedPosition={left:w.x,top:w.y},s.__dragOffset={x:R,y:N}}const c=((A=s.__dragOffset)==null?void 0:A.x)||0,x=((C=s.__dragOffset)==null?void 0:C.y)||0,_=s.__lastSnappedPosition,p=o-_.left-c,g=f-_.top-x;let y=_.left,E=_.top;const l=n==null?void 0:n[0],S=(l==null?void 0:l.guide.type)==="l",O=(l==null?void 0:l.guide.type)==="x",T=(l==null?void 0:l.guide.type)==="r",b=(l==null?void 0:l.guide.type)==="t",M=(l==null?void 0:l.guide.type)==="b",D=(l==null?void 0:l.guide.type)==="y";if(l){const{x:w,y:R}=G({guideMatched:l,canvasView:a}),N=u.offsetWidth,k=u.offsetHeight;S?y=w:T?y=w-N:O?y=w-N/2:b?E=R:M?E=R-k:D&&(E=R-k/2),s.__lastSnappedGuideMatched=l}else Math.abs(p)>=m&&(y=Math.round((_.left+p)/m)*m,s.__lastSnappedGuideMatched=null),Math.abs(g)>=r&&(E=Math.round((_.top+g)/r)*r,s.__lastSnappedGuideMatched=null);return s.addStyle({left:`${y}px`,top:`${E}px`},{partial:!0}),s.__lastSnappedPosition={left:y,top:E},{x:y,y:E,guideMatched:s.__lastSnappedGuideMatched}}function ne({snapping:e,props:d,editor:h}){const{x:i,y:n}=I({snapping:e,props:d,editor:h}),s=d.component;s.addStyle({left:`${i}px`,top:`${n}px`}),delete s.__lastSnappedPosition,delete s.__lastSnappedGuideMatched}const se="core:component-drag",oe="studio:setDragAbsolute",ie="dmode:start",W="dmode:move",Y="dmode:end",B="dragAbsolute",ce="select",ae="hover",le="spacing";return J(function(e,d={}){const h=e.Commands.getConfig().defaultOptions??{};h[se]={run:p=>({...p,skipGuidesRender:!0})};const{snapping:i,locking:n}=d,s=!!(i!=null&&i.x||i!=null&&i.y),u=!!(n!=null&&n.x||n!=null&&n.y),{Canvas:a}=e;let m=null;const r=p=>{const{component:g,guidesMatched:y,command:E}=p,l=g.view,S=e.Canvas.getCanvasView(),O=g.getEl();let T=y.map(D=>D.matched.componentEl),b=y.map(D=>G({guideMatched:D,canvasView:S}));if(s){const{guideMatched:D}=I({snapping:i,props:p,editor:e});D?(T=[D.matched.componentEl],b=[G({guideMatched:D,canvasView:S})]):(T=[],b=[])}if(u)if(E.opts.event.shiftKey)if(!m)m=y[0];else{const A=m,C=A.guide.x===void 0?"x":"y";(C==="x"&&(n==null?void 0:n.x)||C==="y"&&(n==null?void 0:n.y))&&(te({guideMatched:A,component:g,canvasView:S}),T=[A.matched.componentEl],b=[G({guideMatched:A,canvasView:S})])}else m=null;const M={id:B,type:B,component:g,componentView:l,originComponent:O,matchedComponents:T,originMatchedDistances:b};a.addSpot(M)},t=({enabled:p})=>{e.runCommand(oe,{enabled:p})},o=({type:p})=>{a.removeSpots({type:p})},f=()=>{o({type:ce}),o({type:ae}),o({type:le})},c=p=>{t({enabled:!0}),r(p),f()},x=p=>{r(p),f()},_=p=>{o({type:B}),s&&ne({snapping:i,props:p,editor:e}),t({enabled:!1})};e.on(ie,p=>{c(p),e.on(W,x);const g=()=>{_(p),e.off(W,x),e.off(Y,g)};e.on(Y,g)}),z({editor:e,licenseKey:d.licenseKey,plan:ee,pluginName:Z,cleanup:()=>t({enabled:!1})})})});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SDKPluginOptions } from '../utils';
|
|
2
|
+
export interface CanvasAbsoluteModeOptions extends SDKPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Snapping distance for the grid in pixels.
|
|
5
|
+
* @example
|
|
6
|
+
* { x: 100, y: 50 }
|
|
7
|
+
*/
|
|
8
|
+
snapping?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Locking the grid on the X and Y axis.
|
|
14
|
+
* @example
|
|
15
|
+
* { x: true, y: false }
|
|
16
|
+
*/
|
|
17
|
+
locking?: {
|
|
18
|
+
x: boolean;
|
|
19
|
+
y: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ComponentDragEventProps, Canvas, Component, Editor } from 'grapesjs';
|
|
2
|
+
import { CanvasAbsoluteModeOptions } from './types';
|
|
3
|
+
export type GuideMatched = ComponentDragEventProps['guidesMatched'][number];
|
|
4
|
+
type CanvasView = ReturnType<Canvas['module']['getCanvasView']>;
|
|
5
|
+
/**
|
|
6
|
+
* This function calculates the distances between the origin and matched components.
|
|
7
|
+
* - It returns the coordinates and dimensions of the bounding box for the matched components.
|
|
8
|
+
* - In the case of a vertical guide, it'll return the height, and in the case of a horizontal guide, it'll return the width.
|
|
9
|
+
* - It always returns the x and y coordinates where the distance guide should be placed.
|
|
10
|
+
* - Important to note: canvasView.getElBoxRect is a method that returns the bounding box of an element already calculating the zoon, coordinates, offset, and other calculations.
|
|
11
|
+
*/
|
|
12
|
+
export declare function calculateOriginMatchedDistances({ guideMatched, canvasView }: {
|
|
13
|
+
guideMatched: GuideMatched;
|
|
14
|
+
canvasView: CanvasView;
|
|
15
|
+
}): {
|
|
16
|
+
axis: string;
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* This function handles the locked axis for the component.
|
|
24
|
+
* - It calculates the new position of the component based on the guide and matched components.
|
|
25
|
+
* - It uses the canvasView to get the bounding box of the elements and adjust their positions accordingly.
|
|
26
|
+
* - It also updates the component's position based on the guide matched axis (x or y).
|
|
27
|
+
* - It adds an offset to the top position to adjust the final position of the component.
|
|
28
|
+
* - It returns the new position of the component.
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleLockedAxis({ guideMatched, component, canvasView }: {
|
|
31
|
+
guideMatched: GuideMatched;
|
|
32
|
+
component: Component;
|
|
33
|
+
canvasView: CanvasView;
|
|
34
|
+
}): void;
|
|
35
|
+
/**
|
|
36
|
+
* This function handles the snapping of the component during drag events.
|
|
37
|
+
* - It calculates the new position of the component based on the snapping options and the guides matched.
|
|
38
|
+
* - It uses the canvasView to get the bounding box of the elements and adjust their positions accordingly.
|
|
39
|
+
* - It also updates the component's last snapped position and guide matched properties.
|
|
40
|
+
* - It returns the new position and the guide matched.
|
|
41
|
+
*/
|
|
42
|
+
export declare function handleSnappingDragMove({ snapping, editor, props }: {
|
|
43
|
+
snapping: CanvasAbsoluteModeOptions['snapping'];
|
|
44
|
+
props: ComponentDragEventProps;
|
|
45
|
+
editor: Editor;
|
|
46
|
+
}): {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
guideMatched: any;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* This function handles the end of the snapping drag event.
|
|
53
|
+
* - It updates the component's position based on the last snapped position.
|
|
54
|
+
* - It removes the last snapped position and guide matched properties from the component.
|
|
55
|
+
*/
|
|
56
|
+
export declare function handleSnappingDragEnd({ snapping, props, editor }: {
|
|
57
|
+
snapping: CanvasAbsoluteModeOptions['snapping'];
|
|
58
|
+
props: ComponentDragEventProps;
|
|
59
|
+
editor: Editor;
|
|
60
|
+
}): void;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataVariableResolverProps } from '@studio/editor/src/components/DataVariablePicker';
|
|
2
|
+
import { DataCollectionResolverProps } from '@studio/editor/src/components/public/types/StudioDataCollectionPickerSchema';
|
|
3
|
+
import { ITemplateStrategy } from '@studio/editor/src/plugins/global/templateEngines/types';
|
|
4
|
+
export declare class EjsStrategy implements ITemplateStrategy {
|
|
5
|
+
getHelperId(): undefined;
|
|
6
|
+
getVariableSyntax({ collectionId, variableType, path, defaultValue }: DataVariableResolverProps): string;
|
|
7
|
+
getCollectionStartSyntax(options: DataCollectionResolverProps): string;
|
|
8
|
+
private _sanitizeVariableName;
|
|
9
|
+
getCollectionEndSyntax(): string;
|
|
10
|
+
getConditionalStartSyntax(condition: any): string;
|
|
11
|
+
private _parseCondition;
|
|
12
|
+
private _parseValue;
|
|
13
|
+
getConditionElseSyntax(): string;
|
|
14
|
+
getConditionalEndSyntax(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var u=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(u||{}),$=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))($||{});const y="app.grapesjs.com",x="app-stage.grapesjs.com",b=[y,x,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],v="license:check:start",I="license:check:end",L=()=>typeof window<"u",w=({isDev:e,isStage:t})=>`${e?"":`https://${t?x:y}`}/api`,E=()=>{const e=L()&&window.location.hostname;return!!e&&(b.includes(e)||b.some(t=>e.endsWith(t)))};async function R({path:e,baseApiUrl:t,method:s="GET",headers:r={},params:a,body:i}){const p=`${t||w({isDev:!1,isStage:!1})}${e}`,o={method:s,headers:{"Content-Type":"application/json",...r}};i&&(o.body=JSON.stringify(i));const l=a?new URLSearchParams(a).toString():"",n=l?`?${l}`:"",c=await fetch(`${p}${n}`,o);if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);return c.json()}const h={[u.free]:0,[u.startup]:10,[u.business]:20,[u.enterprise]:30};function _(e){const t=e;return t.init=s=>r=>e(r,s),t}const j=e=>_(e);async function D({editor:e,plan:t,pluginName:s,licenseKey:r,cleanup:a}){let i="",g=!1;const p=E(),o=n=>{console.warn("Cleanup plugin:",s,"Reason:",n),a()},l=(n={})=>{var d;const{error:c,sdkLicense:P}=n,f=(d=n.plan)==null?void 0:d.category;if(!(P||n.license)||c)o(c||"Invalid license");else if(f){const T=h[t],A=h[f];T>A&&o({pluginRequiredPlan:t,licensePlan:f})}};e.on(v,n=>{i=n==null?void 0:n.baseApiUrl,g=!0}),e.on(I,n=>{l(n)}),setTimeout(async()=>{if(!g){if(p)return;if(r){const n=await N({licenseKey:r,pluginName:s,baseApiUrl:i});n&&l(n)}else o("The `licenseKey` option not provided")}},2e3)}async function N(e){const{licenseKey:t,pluginName:s,baseApiUrl:r}=e;try{return(await R({baseApiUrl:r,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}class G{getHelperId(){}getVariableSyntax({collectionId:t,variableType:s,path:r,defaultValue:a}){let i=r;return t&&(i=[this._sanitizeVariableName(t),s,r].filter(Boolean).join(".")),a?`<%= ${i} || \`${a}\` %>`:`<%= ${i} %>`}getCollectionStartSyntax(t){const{collectionId:s,dataSource:r,startIndex:a,endIndex:i}=t,g=(r==null?void 0:r.path)||s||"",p=this._sanitizeVariableName(s);let o="";if(a!==void 0||i!==void 0){const l=a??0,n=i!==void 0?i:"";o=`.slice(${l}${n!==""?`, ${n}`:""})`}return`<% ${g}${o}.forEach(function(currentItem, index, arr) {
|
|
2
|
+
const startIndex = parseInt(${a??0}, 10);
|
|
3
|
+
const endIndex = startIndex + arr.length;
|
|
4
|
+
const ${p}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax(t){return t?t.logicalOperator==="and"||t.logicalOperator==="or"?`<% if (${t.statements.map(r=>this._parseCondition(r)).join(` ${t.logicalOperator} `)}) { %>`:`<% if (${this._parseCondition(t)}) { %>`:""}_parseCondition(t){if(!t)return"";if(t.operator==="and"||t.operator==="or")return`(${t.statements.map(r=>this._parseCondition(r)).join(` ${t.operator} `)})`;{const s=this._parseValue(t.left),r=this._parseValue(t.right);switch(t.operator){case"equals":return`${s} === ${r}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${s} ${t.operator} ${r}`;case"contains":return`${s}?.includes(${r})`;case"startsWith":return`${s}?.startsWith(${r})`;case"endsWith":return`${s}?.endsWith(${r})`;case"equalsIgnoreCase":return`${s}?.toLowerCase() === ${r}?.toLowerCase()`;case"trimEquals":return`${s}?.trim() === ${r}?.trim()`;case"isTruthy":return`!!${s}`;case"isFalsy":return`!${s}`;case"isDefined":return`${s} !== undefined`;case"isNull":return`${s} === null`;case"isUndefined":return`${s} === undefined`;case"isArray":return`Array.isArray(${s})`;case"isObject":return`typeof ${s} === 'object' && ${s} !== null && !Array.isArray(${s})`;case"isString":return`typeof ${s} === 'string'`;case"isNumber":return`typeof ${s} === 'number' && !isNaN(${s})`;case"isBoolean":return`typeof ${s} === 'boolean'`;default:return`${s} ${t.operator} ${r}`}}}_parseValue(t){return typeof t=="object"?this.getVariableSyntax(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}}const O="dataSourceEjs",B=function(e,t={}){const s=({options:a})=>{a.exportConfig.exportPreset==="ejs"&&(a.exportConfig={...a.exportConfig,exportStrategy:new G})},r=`${e.Commands.events.runBeforeCommand}${$.projectFiles}`;e.on(r,s),D({editor:e,licenseKey:t.licenseKey,plan:u.startup,pluginName:O,cleanup:()=>{e.off(r,s)}})},k=j(B);module.exports=k;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var u = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(u || {}), $ = /* @__PURE__ */ ((e) => (e.toastAdd = "studio:toastAdd", e.dialogOpen = "studio:dialogOpen", e.dialogClose = "studio:dialogClose", e.sidebarLeftSet = "studio:sidebarLeft:set", e.sidebarLeftGet = "studio:sidebarLeft:get", e.sidebarLeftToggle = "studio:sidebarLeft:toggle", e.sidebarRightSet = "studio:sidebarRight:set", e.sidebarRightGet = "studio:sidebarRight:get", e.sidebarRightToggle = "studio:sidebarRight:toggle", e.sidebarTopSet = "studio:sidebarTop:set", e.sidebarTopGet = "studio:sidebarTop:get", e.sidebarTopToggle = "studio:sidebarTop:toggle", e.sidebarBottomSet = "studio:sidebarBottom:set", e.sidebarBottomGet = "studio:sidebarBottom:get", e.sidebarBottomToggle = "studio:sidebarBottom:toggle", e.symbolAdd = "studio:symbolAdd", e.symbolDetach = "studio:symbolDetach", e.symbolOverride = "studio:symbolOverride", e.symbolPropagateStyles = "studio:propagateStyles", e.getPagesConfig = "studio:getPagesConfig", e.setPagesConfig = "studio:setPagesConfig", e.getPageSettings = "studio:getPageSettings", e.setPageSettings = "studio:setPageSettings", e.projectFiles = "studio:projectFiles", e.canvasReload = "studio:canvasReload", e.getBlocksPanel = "studio:getBlocksPanel", e.setBlocksPanel = "studio:setBlocksPanel", e.getStateContextMenu = "studio:getStateContextMenu", e.setStateContextMenu = "studio:setStateContextMenu", e.contextMenuComponent = "studio:contextMenuComponent", e.layoutAdd = "studio:layoutAdd", e.layoutRemove = "studio:layoutRemove", e.layoutToggle = "studio:layoutToggle", e.layoutUpdate = "studio:layoutUpdate", e.layoutGet = "studio:layoutGet", e.layoutConfigGet = "studio:layoutConfigGet", e.layoutConfigSet = "studio:layoutConfigSet", e.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.assetProviderGet = "studio:assetProviderGet", e.assetProviderAdd = "studio:assetProviderAdd", e.assetProviderRemove = "studio:assetProviderRemove", e.fontGet = "studio:fontGet", e.fontAdd = "studio:fontAdd", e.fontRemove = "studio:fontRemove", e.fontManagerOpen = "studio:fontManagerOpen", e.menuFontLoad = "studio:menuFontLoad", e.toggleStateDataSource = "studio:toggleStateDataSource", e.getStateDataSource = "studio:getStateDataSource", e.setDragAbsolute = "studio:setDragAbsolute", e))($ || {});
|
|
2
|
+
const y = "app.grapesjs.com", x = "app-stage.grapesjs.com", b = [
|
|
3
|
+
y,
|
|
4
|
+
x,
|
|
5
|
+
"localhost",
|
|
6
|
+
"127.0.0.1",
|
|
7
|
+
".local-credentialless.webcontainer.io",
|
|
8
|
+
// For stackblitz.com demos
|
|
9
|
+
".local.webcontainer.io",
|
|
10
|
+
// For stackblitz.com demos
|
|
11
|
+
"-sandpack.codesandbox.io"
|
|
12
|
+
// For Sandpack demos
|
|
13
|
+
], v = "license:check:start", I = "license:check:end", L = () => typeof window < "u", w = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? x : y}`}/api`, E = () => {
|
|
14
|
+
const e = L() && window.location.hostname;
|
|
15
|
+
return !!e && (b.includes(e) || b.some((t) => e.endsWith(t)));
|
|
16
|
+
};
|
|
17
|
+
async function R({
|
|
18
|
+
path: e,
|
|
19
|
+
baseApiUrl: t,
|
|
20
|
+
method: s = "GET",
|
|
21
|
+
headers: r = {},
|
|
22
|
+
params: a,
|
|
23
|
+
body: o
|
|
24
|
+
}) {
|
|
25
|
+
const p = `${t || w({ isDev: !1, isStage: !1 })}${e}`, i = {
|
|
26
|
+
method: s,
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
...r
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
o && (i.body = JSON.stringify(o));
|
|
33
|
+
const l = a ? new URLSearchParams(a).toString() : "", n = l ? `?${l}` : "", c = await fetch(`${p}${n}`, i);
|
|
34
|
+
if (!c.ok)
|
|
35
|
+
throw new Error(`HTTP error! status: ${c.status}`);
|
|
36
|
+
return c.json();
|
|
37
|
+
}
|
|
38
|
+
const h = {
|
|
39
|
+
[u.free]: 0,
|
|
40
|
+
[u.startup]: 10,
|
|
41
|
+
[u.business]: 20,
|
|
42
|
+
[u.enterprise]: 30
|
|
43
|
+
};
|
|
44
|
+
function _(e) {
|
|
45
|
+
const t = e;
|
|
46
|
+
return t.init = (s) => (r) => e(r, s), t;
|
|
47
|
+
}
|
|
48
|
+
const j = (e) => /* @__PURE__ */ _(e);
|
|
49
|
+
async function D({
|
|
50
|
+
editor: e,
|
|
51
|
+
plan: t,
|
|
52
|
+
pluginName: s,
|
|
53
|
+
licenseKey: r,
|
|
54
|
+
cleanup: a
|
|
55
|
+
}) {
|
|
56
|
+
let o = "", g = !1;
|
|
57
|
+
const p = E(), i = (n) => {
|
|
58
|
+
console.warn("Cleanup plugin:", s, "Reason:", n), a();
|
|
59
|
+
}, l = (n = {}) => {
|
|
60
|
+
var d;
|
|
61
|
+
const { error: c, sdkLicense: P } = n, f = (d = n.plan) == null ? void 0 : d.category;
|
|
62
|
+
if (!(P || n.license) || c)
|
|
63
|
+
i(c || "Invalid license");
|
|
64
|
+
else if (f) {
|
|
65
|
+
const T = h[t], A = h[f];
|
|
66
|
+
T > A && i({ pluginRequiredPlan: t, licensePlan: f });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
e.on(v, (n) => {
|
|
70
|
+
o = n == null ? void 0 : n.baseApiUrl, g = !0;
|
|
71
|
+
}), e.on(I, (n) => {
|
|
72
|
+
l(n);
|
|
73
|
+
}), setTimeout(async () => {
|
|
74
|
+
if (!g) {
|
|
75
|
+
if (p) return;
|
|
76
|
+
if (r) {
|
|
77
|
+
const n = await N({ licenseKey: r, pluginName: s, baseApiUrl: o });
|
|
78
|
+
n && l(n);
|
|
79
|
+
} else
|
|
80
|
+
i("The `licenseKey` option not provided");
|
|
81
|
+
}
|
|
82
|
+
}, 2e3);
|
|
83
|
+
}
|
|
84
|
+
async function N(e) {
|
|
85
|
+
const { licenseKey: t, pluginName: s, baseApiUrl: r } = e;
|
|
86
|
+
try {
|
|
87
|
+
return (await R({
|
|
88
|
+
baseApiUrl: r,
|
|
89
|
+
path: `/sdk/${t || "na"}`,
|
|
90
|
+
method: "POST",
|
|
91
|
+
params: {
|
|
92
|
+
d: window.location.hostname,
|
|
93
|
+
pn: s
|
|
94
|
+
}
|
|
95
|
+
})).result || {};
|
|
96
|
+
} catch (a) {
|
|
97
|
+
return console.error("Error during SDK license check:", a), !1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class G {
|
|
101
|
+
getHelperId() {
|
|
102
|
+
}
|
|
103
|
+
getVariableSyntax({ collectionId: t, variableType: s, path: r, defaultValue: a }) {
|
|
104
|
+
let o = r;
|
|
105
|
+
return t && (o = [this._sanitizeVariableName(t), s, r].filter(Boolean).join(".")), a ? `<%= ${o} || \`${a}\` %>` : `<%= ${o} %>`;
|
|
106
|
+
}
|
|
107
|
+
getCollectionStartSyntax(t) {
|
|
108
|
+
const { collectionId: s, dataSource: r, startIndex: a, endIndex: o } = t, g = (r == null ? void 0 : r.path) || s || "", p = this._sanitizeVariableName(s);
|
|
109
|
+
let i = "";
|
|
110
|
+
if (a !== void 0 || o !== void 0) {
|
|
111
|
+
const l = a ?? 0, n = o !== void 0 ? o : "";
|
|
112
|
+
i = `.slice(${l}${n !== "" ? `, ${n}` : ""})`;
|
|
113
|
+
}
|
|
114
|
+
return `<% ${g}${i}.forEach(function(currentItem, index, arr) {
|
|
115
|
+
const startIndex = parseInt(${a ?? 0}, 10);
|
|
116
|
+
const endIndex = startIndex + arr.length;
|
|
117
|
+
const ${p}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`;
|
|
118
|
+
}
|
|
119
|
+
_sanitizeVariableName(t) {
|
|
120
|
+
return t.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
121
|
+
}
|
|
122
|
+
getCollectionEndSyntax() {
|
|
123
|
+
return "<% }) %>";
|
|
124
|
+
}
|
|
125
|
+
getConditionalStartSyntax(t) {
|
|
126
|
+
return t ? t.logicalOperator === "and" || t.logicalOperator === "or" ? `<% if (${t.statements.map((r) => this._parseCondition(r)).join(` ${t.logicalOperator} `)}) { %>` : `<% if (${this._parseCondition(t)}) { %>` : "";
|
|
127
|
+
}
|
|
128
|
+
_parseCondition(t) {
|
|
129
|
+
if (!t) return "";
|
|
130
|
+
if (t.operator === "and" || t.operator === "or")
|
|
131
|
+
return `(${t.statements.map((r) => this._parseCondition(r)).join(` ${t.operator} `)})`;
|
|
132
|
+
{
|
|
133
|
+
const s = this._parseValue(t.left), r = this._parseValue(t.right);
|
|
134
|
+
switch (t.operator) {
|
|
135
|
+
case "equals":
|
|
136
|
+
return `${s} === ${r}`;
|
|
137
|
+
case ">":
|
|
138
|
+
case "<":
|
|
139
|
+
case ">=":
|
|
140
|
+
case "<=":
|
|
141
|
+
case "=":
|
|
142
|
+
case "!=":
|
|
143
|
+
return `${s} ${t.operator} ${r}`;
|
|
144
|
+
case "contains":
|
|
145
|
+
return `${s}?.includes(${r})`;
|
|
146
|
+
case "startsWith":
|
|
147
|
+
return `${s}?.startsWith(${r})`;
|
|
148
|
+
case "endsWith":
|
|
149
|
+
return `${s}?.endsWith(${r})`;
|
|
150
|
+
case "equalsIgnoreCase":
|
|
151
|
+
return `${s}?.toLowerCase() === ${r}?.toLowerCase()`;
|
|
152
|
+
case "trimEquals":
|
|
153
|
+
return `${s}?.trim() === ${r}?.trim()`;
|
|
154
|
+
case "isTruthy":
|
|
155
|
+
return `!!${s}`;
|
|
156
|
+
case "isFalsy":
|
|
157
|
+
return `!${s}`;
|
|
158
|
+
case "isDefined":
|
|
159
|
+
return `${s} !== undefined`;
|
|
160
|
+
case "isNull":
|
|
161
|
+
return `${s} === null`;
|
|
162
|
+
case "isUndefined":
|
|
163
|
+
return `${s} === undefined`;
|
|
164
|
+
case "isArray":
|
|
165
|
+
return `Array.isArray(${s})`;
|
|
166
|
+
case "isObject":
|
|
167
|
+
return `typeof ${s} === 'object' && ${s} !== null && !Array.isArray(${s})`;
|
|
168
|
+
case "isString":
|
|
169
|
+
return `typeof ${s} === 'string'`;
|
|
170
|
+
case "isNumber":
|
|
171
|
+
return `typeof ${s} === 'number' && !isNaN(${s})`;
|
|
172
|
+
case "isBoolean":
|
|
173
|
+
return `typeof ${s} === 'boolean'`;
|
|
174
|
+
default:
|
|
175
|
+
return `${s} ${t.operator} ${r}`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_parseValue(t) {
|
|
180
|
+
return typeof t == "object" ? this.getVariableSyntax(t) : typeof t == "string" ? `'${t.replace(/'/g, "\\'")}'` : String(t);
|
|
181
|
+
}
|
|
182
|
+
getConditionElseSyntax() {
|
|
183
|
+
return "<% } else { %>";
|
|
184
|
+
}
|
|
185
|
+
getConditionalEndSyntax() {
|
|
186
|
+
return "<% } %>";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const O = "dataSourceEjs", B = function(e, t = {}) {
|
|
190
|
+
const s = ({ options: a }) => {
|
|
191
|
+
a.exportConfig.exportPreset === "ejs" && (a.exportConfig = {
|
|
192
|
+
...a.exportConfig,
|
|
193
|
+
exportStrategy: new G()
|
|
194
|
+
});
|
|
195
|
+
}, r = `${e.Commands.events.runBeforeCommand}${$.projectFiles}`;
|
|
196
|
+
e.on(r, s), D({
|
|
197
|
+
editor: e,
|
|
198
|
+
licenseKey: t.licenseKey,
|
|
199
|
+
plan: u.startup,
|
|
200
|
+
pluginName: O,
|
|
201
|
+
cleanup: () => {
|
|
202
|
+
e.off(r, s);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}, U = j(B);
|
|
206
|
+
export {
|
|
207
|
+
U as default
|
|
208
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(function(o,u){typeof exports=="object"&&typeof module<"u"?module.exports=u():typeof define=="function"&&define.amd?define(u):(o=typeof globalThis<"u"?globalThis:o||self,o.StudioSdkPlugins_dataSourceEjs=u())})(this,function(){"use strict";var o=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(o||{}),u=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(u||{});const h="app.grapesjs.com",b="app-stage.grapesjs.com",y=[h,b,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],P="license:check:start",T="license:check:end",A=()=>typeof window<"u",v=({isDev:e,isStage:t})=>`${e?"":`https://${t?b:h}`}/api`,I=()=>{const e=A()&&window.location.hostname;return!!e&&(y.includes(e)||y.some(t=>e.endsWith(t)))};async function E({path:e,baseApiUrl:t,method:s="GET",headers:r={},params:a,body:i}){const f=`${t||v({isDev:!1,isStage:!1})}${e}`,l={method:s,headers:{"Content-Type":"application/json",...r}};i&&(l.body=JSON.stringify(i));const c=a?new URLSearchParams(a).toString():"",n=c?`?${c}`:"",g=await fetch(`${f}${n}`,l);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const $={[o.free]:0,[o.startup]:10,[o.business]:20,[o.enterprise]:30};function L(e){const t=e;return t.init=s=>r=>e(r,s),t}const w=e=>L(e);async function _({editor:e,plan:t,pluginName:s,licenseKey:r,cleanup:a}){let i="",p=!1;const f=I(),l=n=>{console.warn("Cleanup plugin:",s,"Reason:",n),a()},c=(n={})=>{var x;const{error:g,sdkLicense:N}=n,d=(x=n.plan)==null?void 0:x.category;if(!(N||n.license)||g)l(g||"Invalid license");else if(d){const G=$[t],O=$[d];G>O&&l({pluginRequiredPlan:t,licensePlan:d})}};e.on(P,n=>{i=n==null?void 0:n.baseApiUrl,p=!0}),e.on(T,n=>{c(n)}),setTimeout(async()=>{if(!p){if(f)return;if(r){const n=await j({licenseKey:r,pluginName:s,baseApiUrl:i});n&&c(n)}else l("The `licenseKey` option not provided")}},2e3)}async function j(e){const{licenseKey:t,pluginName:s,baseApiUrl:r}=e;try{return(await E({baseApiUrl:r,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}class R{getHelperId(){}getVariableSyntax({collectionId:t,variableType:s,path:r,defaultValue:a}){let i=r;return t&&(i=[this._sanitizeVariableName(t),s,r].filter(Boolean).join(".")),a?`<%= ${i} || \`${a}\` %>`:`<%= ${i} %>`}getCollectionStartSyntax(t){const{collectionId:s,dataSource:r,startIndex:a,endIndex:i}=t,p=(r==null?void 0:r.path)||s||"",f=this._sanitizeVariableName(s);let l="";if(a!==void 0||i!==void 0){const c=a??0,n=i!==void 0?i:"";l=`.slice(${c}${n!==""?`, ${n}`:""})`}return`<% ${p}${l}.forEach(function(currentItem, index, arr) {
|
|
2
|
+
const startIndex = parseInt(${a??0}, 10);
|
|
3
|
+
const endIndex = startIndex + arr.length;
|
|
4
|
+
const ${f}={ currentItem, currentIndex: startIndex + index, remainingItems: endIndex - (startIndex + index)} %>`}_sanitizeVariableName(t){return t.replace(/[^a-zA-Z0-9_$]/g,"_")}getCollectionEndSyntax(){return"<% }) %>"}getConditionalStartSyntax(t){return t?t.logicalOperator==="and"||t.logicalOperator==="or"?`<% if (${t.statements.map(r=>this._parseCondition(r)).join(` ${t.logicalOperator} `)}) { %>`:`<% if (${this._parseCondition(t)}) { %>`:""}_parseCondition(t){if(!t)return"";if(t.operator==="and"||t.operator==="or")return`(${t.statements.map(r=>this._parseCondition(r)).join(` ${t.operator} `)})`;{const s=this._parseValue(t.left),r=this._parseValue(t.right);switch(t.operator){case"equals":return`${s} === ${r}`;case">":case"<":case">=":case"<=":case"=":case"!=":return`${s} ${t.operator} ${r}`;case"contains":return`${s}?.includes(${r})`;case"startsWith":return`${s}?.startsWith(${r})`;case"endsWith":return`${s}?.endsWith(${r})`;case"equalsIgnoreCase":return`${s}?.toLowerCase() === ${r}?.toLowerCase()`;case"trimEquals":return`${s}?.trim() === ${r}?.trim()`;case"isTruthy":return`!!${s}`;case"isFalsy":return`!${s}`;case"isDefined":return`${s} !== undefined`;case"isNull":return`${s} === null`;case"isUndefined":return`${s} === undefined`;case"isArray":return`Array.isArray(${s})`;case"isObject":return`typeof ${s} === 'object' && ${s} !== null && !Array.isArray(${s})`;case"isString":return`typeof ${s} === 'string'`;case"isNumber":return`typeof ${s} === 'number' && !isNaN(${s})`;case"isBoolean":return`typeof ${s} === 'boolean'`;default:return`${s} ${t.operator} ${r}`}}}_parseValue(t){return typeof t=="object"?this.getVariableSyntax(t):typeof t=="string"?`'${t.replace(/'/g,"\\'")}'`:String(t)}getConditionElseSyntax(){return"<% } else { %>"}getConditionalEndSyntax(){return"<% } %>"}}const D="dataSourceEjs";return w(function(e,t={}){const s=({options:a})=>{a.exportConfig.exportPreset==="ejs"&&(a.exportConfig={...a.exportConfig,exportStrategy:new R})},r=`${e.Commands.events.runBeforeCommand}${u.projectFiles}`;e.on(r,s),_({editor:e,licenseKey:t.licenseKey,plan:o.startup,pluginName:D,cleanup:()=>{e.off(r,s)}})})});
|