@grapesjs/studio-sdk-plugins 1.0.14-rc.0 → 1.0.14-rc.2
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/canvasEmptyState/index.cjs.d.ts +3 -0
- package/dist/canvasEmptyState/index.cjs.js +1 -0
- package/dist/canvasEmptyState/index.d.ts +3 -0
- package/dist/canvasEmptyState/index.es.d.ts +3 -0
- package/dist/canvasEmptyState/index.es.js +166 -0
- package/dist/canvasEmptyState/index.umd.js +1 -0
- package/dist/canvasEmptyState/types.d.ts +3 -0
- package/dist/canvasEmptyState/typesSchema.d.ts +44 -0
- package/dist/canvasFullSize/index.cjs.d.ts +3 -0
- package/dist/canvasFullSize/index.cjs.js +5 -0
- package/dist/canvasFullSize/index.d.ts +3 -0
- package/dist/canvasFullSize/index.es.d.ts +3 -0
- package/dist/canvasFullSize/index.es.js +180 -0
- package/dist/canvasFullSize/index.umd.js +5 -0
- package/dist/canvasFullSize/types.d.ts +3 -0
- package/dist/canvasFullSize/typesSchema.d.ts +27 -0
- package/dist/googleFontsAssetProvider/assetProviders/googleFonts.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.cjs.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -0
- package/dist/googleFontsAssetProvider/index.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.es.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.es.js +201 -0
- package/dist/googleFontsAssetProvider/index.umd.js +1 -0
- package/dist/googleFontsAssetProvider/locale/en.d.ts +8 -0
- package/dist/googleFontsAssetProvider/types.d.ts +26 -0
- package/dist/googleFontsAssetProvider/typesSchema.d.ts +86 -0
- package/dist/iconifyComponent/index.cjs.d.ts +3 -0
- package/dist/iconifyComponent/index.cjs.js +3 -0
- package/dist/iconifyComponent/index.es.d.ts +3 -0
- package/dist/iconifyComponent/index.es.js +361 -0
- package/dist/iconifyComponent/index.umd.js +3 -0
- package/dist/index.cjs.d.ts +3 -0
- package/dist/index.cjs.js +29 -25
- package/dist/index.d.ts +3 -0
- package/dist/index.es.d.ts +3 -0
- package/dist/index.es.js +5614 -5388
- package/dist/index.umd.js +31 -27
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +113 -107
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/locale/en.d.ts +1 -0
- package/dist/youtubeAssetProvider/types.d.ts +8 -196
- package/dist/youtubeAssetProvider/typesSchema.d.ts +200 -0
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";require("grapesjs");const I="app.grapesjs.com",M="app-stage.grapesjs.com",W=[I,M,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",N="license:check:end",D=()=>typeof window<"u",P=({isDev:e,isStage:t})=>`${e?"":`https://${t?M:I}`}/api`,R=()=>{const e=D()&&window.location.hostname;return!!e&&(W.includes(e)||W.some(t=>e.endsWith(t)))};function _(e){return typeof e=="function"}async function K({path:e,baseApiUrl:t,method:a="GET",headers:o={},params:i,body:u}){const v=`${t||P({isDev:!1,isStage:!1})}${e}`,p={method:a,headers:{"Content-Type":"application/json",...o}};u&&(p.body=JSON.stringify(u));const d=i?new URLSearchParams(i).toString():"",s=d?`?${d}`:"",c=await fetch(`${v}${s}`,p);if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);return c.json()}var w=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(w||{});const A={[w.free]:0,[w.startup]:10,[w.business]:20,[w.enterprise]:30};function O(e){const t=e;return t.init=a=>o=>e(o,a),t}const j=e=>O(e);async function q({editor:e,plan:t,pluginName:a,licenseKey:o,cleanup:i}){let u="",h=!1;const v=R(),p=s=>{console.warn("Cleanup plugin:",a,"Reason:",s),i()},d=(s={})=>{var C;const{error:c,sdkLicense:E}=s,y=(C=s.plan)==null?void 0:C.category;if(!(E||s.license)||c)p(c||"Invalid license");else if(y){const b=A[t],L=A[y];b>L&&p({pluginRequiredPlan:t,licensePlan:y})}};e.on($,s=>{u=s==null?void 0:s.baseApiUrl,h=!0}),e.on(N,s=>{d(s)}),setTimeout(async()=>{if(!h){if(v)return;if(o){const s=await x({licenseKey:o,pluginName:a,baseApiUrl:u});s&&d(s)}else p("The `licenseKey` option not provided")}},2e3)}async function x(e){const{licenseKey:t,pluginName:a,baseApiUrl:o}=e;try{return(await K({baseApiUrl:o,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:a}})).result||{}}catch(i){return console.error("Error during SDK license check:",i),!1}}const F="canvasEmptyState",G=function(e,t={}){const a=new WeakMap,o=new WeakMap,i=new WeakMap,u=new Set,h=new WeakMap,v={emptyStates:[],...t},p=(n,r)=>{let m=!1;const{isValid:f}=r;return Array.isArray(f)?m=f.some(l=>n.is(l)):_(f)?m=f({component:n,editor:e}):m=n.is(f),m},d=n=>{const r=a.get(n);a.delete(n),r==null||r()},s=n=>{n.views.forEach(r=>d(r)),i.delete(n)},c=n=>{if(!(!n||u.has(n)))try{u.add(n);const r=n.components().length>0,m=i.get(n);if(r&&m)s(n);else if(!r&&!m){const f=h.has(n)?h.get(n):v.emptyStates.find(l=>p(n,l));if(h.set(n,f),!f)return;n.views.forEach(l=>{const S=f.render({editor:e,component:n,componentView:l,mount:g=>{o.set(l,g),i.set(n,!0);const k=l.getChildrenContainer();k==null||k.appendChild(g)},unmount:()=>d(l)});a.set(l,()=>{S==null||S();const g=o.get(l);g==null||g.remove()})})}}finally{u.delete(n)}},E=n=>{i.has(n)&&s(n)},y=({model:n})=>{c(n.getComponent())},T=e.Components.events,C=`${T.update}:components`,b="component:mount",L=e.Canvas.events.frameLoadBody,U=T.removed||T.remove;e.on(C,c),e.on(b,c),e.on(U,E),e.on(L,y),q({editor:e,licenseKey:v.licenseKey,plan:w.startup,pluginName:F,cleanup:()=>{e.off(C,c),e.off(b,c),e.off(U,E),e.off(L,y)}})},H=j(G);module.exports=H;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import "grapesjs";
|
|
2
|
+
const I = "app.grapesjs.com", M = "app-stage.grapesjs.com", W = [
|
|
3
|
+
I,
|
|
4
|
+
M,
|
|
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
|
+
], $ = "license:check:start", N = "license:check:end", D = () => typeof window < "u", P = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? M : I}`}/api`, R = () => {
|
|
14
|
+
const e = D() && window.location.hostname;
|
|
15
|
+
return !!e && (W.includes(e) || W.some((t) => e.endsWith(t)));
|
|
16
|
+
};
|
|
17
|
+
function _(e) {
|
|
18
|
+
return typeof e == "function";
|
|
19
|
+
}
|
|
20
|
+
async function K({
|
|
21
|
+
path: e,
|
|
22
|
+
baseApiUrl: t,
|
|
23
|
+
method: a = "GET",
|
|
24
|
+
headers: o = {},
|
|
25
|
+
params: i,
|
|
26
|
+
body: u
|
|
27
|
+
}) {
|
|
28
|
+
const v = `${t || P({ isDev: !1, isStage: !1 })}${e}`, p = {
|
|
29
|
+
method: a,
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
...o
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
u && (p.body = JSON.stringify(u));
|
|
36
|
+
const d = i ? new URLSearchParams(i).toString() : "", s = d ? `?${d}` : "", c = await fetch(`${v}${s}`, p);
|
|
37
|
+
if (!c.ok)
|
|
38
|
+
throw new Error(`HTTP error! status: ${c.status}`);
|
|
39
|
+
return c.json();
|
|
40
|
+
}
|
|
41
|
+
var w = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(w || {});
|
|
42
|
+
const A = {
|
|
43
|
+
[w.free]: 0,
|
|
44
|
+
[w.startup]: 10,
|
|
45
|
+
[w.business]: 20,
|
|
46
|
+
[w.enterprise]: 30
|
|
47
|
+
};
|
|
48
|
+
function O(e) {
|
|
49
|
+
const t = e;
|
|
50
|
+
return t.init = (a) => (o) => e(o, a), t;
|
|
51
|
+
}
|
|
52
|
+
const j = (e) => /* @__PURE__ */ O(e);
|
|
53
|
+
async function x({
|
|
54
|
+
editor: e,
|
|
55
|
+
plan: t,
|
|
56
|
+
pluginName: a,
|
|
57
|
+
licenseKey: o,
|
|
58
|
+
cleanup: i
|
|
59
|
+
}) {
|
|
60
|
+
let u = "", h = !1;
|
|
61
|
+
const v = R(), p = (s) => {
|
|
62
|
+
console.warn("Cleanup plugin:", a, "Reason:", s), i();
|
|
63
|
+
}, d = (s = {}) => {
|
|
64
|
+
var C;
|
|
65
|
+
const { error: c, sdkLicense: E } = s, y = (C = s.plan) == null ? void 0 : C.category;
|
|
66
|
+
if (!(E || s.license) || c)
|
|
67
|
+
p(c || "Invalid license");
|
|
68
|
+
else if (y) {
|
|
69
|
+
const b = A[t], L = A[y];
|
|
70
|
+
b > L && p({ pluginRequiredPlan: t, licensePlan: y });
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
e.on($, (s) => {
|
|
74
|
+
u = s == null ? void 0 : s.baseApiUrl, h = !0;
|
|
75
|
+
}), e.on(N, (s) => {
|
|
76
|
+
d(s);
|
|
77
|
+
}), setTimeout(async () => {
|
|
78
|
+
if (!h) {
|
|
79
|
+
if (v) return;
|
|
80
|
+
if (o) {
|
|
81
|
+
const s = await F({ licenseKey: o, pluginName: a, baseApiUrl: u });
|
|
82
|
+
s && d(s);
|
|
83
|
+
} else
|
|
84
|
+
p("The `licenseKey` option not provided");
|
|
85
|
+
}
|
|
86
|
+
}, 2e3);
|
|
87
|
+
}
|
|
88
|
+
async function F(e) {
|
|
89
|
+
const { licenseKey: t, pluginName: a, baseApiUrl: o } = e;
|
|
90
|
+
try {
|
|
91
|
+
return (await K({
|
|
92
|
+
baseApiUrl: o,
|
|
93
|
+
path: `/sdk/${t || "na"}`,
|
|
94
|
+
method: "POST",
|
|
95
|
+
params: {
|
|
96
|
+
d: window.location.hostname,
|
|
97
|
+
pn: a
|
|
98
|
+
}
|
|
99
|
+
})).result || {};
|
|
100
|
+
} catch (i) {
|
|
101
|
+
return console.error("Error during SDK license check:", i), !1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const G = "canvasEmptyState", H = function(e, t = {}) {
|
|
105
|
+
const a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new WeakMap(), v = {
|
|
106
|
+
emptyStates: [],
|
|
107
|
+
...t
|
|
108
|
+
}, p = (n, r) => {
|
|
109
|
+
let m = !1;
|
|
110
|
+
const { isValid: f } = r;
|
|
111
|
+
return Array.isArray(f) ? m = f.some((l) => n.is(l)) : _(f) ? m = f({ component: n, editor: e }) : m = n.is(f), m;
|
|
112
|
+
}, d = (n) => {
|
|
113
|
+
const r = a.get(n);
|
|
114
|
+
a.delete(n), r == null || r();
|
|
115
|
+
}, s = (n) => {
|
|
116
|
+
n.views.forEach((r) => d(r)), i.delete(n);
|
|
117
|
+
}, c = (n) => {
|
|
118
|
+
if (!(!n || u.has(n)))
|
|
119
|
+
try {
|
|
120
|
+
u.add(n);
|
|
121
|
+
const r = n.components().length > 0, m = i.get(n);
|
|
122
|
+
if (r && m)
|
|
123
|
+
s(n);
|
|
124
|
+
else if (!r && !m) {
|
|
125
|
+
const f = h.has(n) ? h.get(n) : v.emptyStates.find((l) => p(n, l));
|
|
126
|
+
if (h.set(n, f), !f) return;
|
|
127
|
+
n.views.forEach((l) => {
|
|
128
|
+
const S = f.render({
|
|
129
|
+
editor: e,
|
|
130
|
+
component: n,
|
|
131
|
+
componentView: l,
|
|
132
|
+
mount: (g) => {
|
|
133
|
+
o.set(l, g), i.set(n, !0);
|
|
134
|
+
const k = l.getChildrenContainer();
|
|
135
|
+
k == null || k.appendChild(g);
|
|
136
|
+
},
|
|
137
|
+
unmount: () => d(l)
|
|
138
|
+
});
|
|
139
|
+
a.set(l, () => {
|
|
140
|
+
S == null || S();
|
|
141
|
+
const g = o.get(l);
|
|
142
|
+
g == null || g.remove();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
} finally {
|
|
147
|
+
u.delete(n);
|
|
148
|
+
}
|
|
149
|
+
}, E = (n) => {
|
|
150
|
+
i.has(n) && s(n);
|
|
151
|
+
}, y = ({ model: n }) => {
|
|
152
|
+
c(n.getComponent());
|
|
153
|
+
}, T = e.Components.events, C = `${T.update}:components`, b = "component:mount", L = e.Canvas.events.frameLoadBody, U = T.removed || T.remove;
|
|
154
|
+
e.on(C, c), e.on(b, c), e.on(U, E), e.on(L, y), x({
|
|
155
|
+
editor: e,
|
|
156
|
+
licenseKey: v.licenseKey,
|
|
157
|
+
plan: w.startup,
|
|
158
|
+
pluginName: G,
|
|
159
|
+
cleanup: () => {
|
|
160
|
+
e.off(C, c), e.off(b, c), e.off(U, E), e.off(L, y);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}, B = j(H);
|
|
164
|
+
export {
|
|
165
|
+
B as default
|
|
166
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(y,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("grapesjs")):typeof define=="function"&&define.amd?define(["grapesjs"],g):(y=typeof globalThis<"u"?globalThis:y||self,y.StudioSdkPlugins_canvasEmptyState=g())})(this,function(){"use strict";const y="app.grapesjs.com",g="app-stage.grapesjs.com",A=[y,g,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",N="license:check:end",P=()=>typeof window<"u",D=({isDev:e,isStage:t})=>`${e?"":`https://${t?g:y}`}/api`,_=()=>{const e=P()&&window.location.hostname;return!!e&&(A.includes(e)||A.some(t=>e.endsWith(t)))};function j(e){return typeof e=="function"}async function R({path:e,baseApiUrl:t,method:o="GET",headers:a={},params:i,body:u}){const w=`${t||D({isDev:!1,isStage:!1})}${e}`,p={method:o,headers:{"Content-Type":"application/json",...a}};u&&(p.body=JSON.stringify(u));const d=i?new URLSearchParams(i).toString():"",s=d?`?${d}`:"",c=await fetch(`${w}${s}`,p);if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);return c.json()}var v=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(v||{});const I={[v.free]:0,[v.startup]:10,[v.business]:20,[v.enterprise]:30};function K(e){const t=e;return t.init=o=>a=>e(a,o),t}const x=e=>K(e);async function O({editor:e,plan:t,pluginName:o,licenseKey:a,cleanup:i}){let u="",h=!1;const w=_(),p=s=>{console.warn("Cleanup plugin:",o,"Reason:",s),i()},d=(s={})=>{var S;const{error:c,sdkLicense:T}=s,C=(S=s.plan)==null?void 0:S.category;if(!(T||s.license)||c)p(c||"Invalid license");else if(C){const L=I[t],k=I[C];L>k&&p({pluginRequiredPlan:t,licensePlan:C})}};e.on($,s=>{u=s==null?void 0:s.baseApiUrl,h=!0}),e.on(N,s=>{d(s)}),setTimeout(async()=>{if(!h){if(w)return;if(a){const s=await q({licenseKey:a,pluginName:o,baseApiUrl:u});s&&d(s)}else p("The `licenseKey` option not provided")}},2e3)}async function q(e){const{licenseKey:t,pluginName:o,baseApiUrl:a}=e;try{return(await R({baseApiUrl:a,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:o}})).result||{}}catch(i){return console.error("Error during SDK license check:",i),!1}}const F="canvasEmptyState";return x(function(e,t={}){const o=new WeakMap,a=new WeakMap,i=new WeakMap,u=new Set,h=new WeakMap,w={emptyStates:[],...t},p=(n,r)=>{let m=!1;const{isValid:f}=r;return Array.isArray(f)?m=f.some(l=>n.is(l)):j(f)?m=f({component:n,editor:e}):m=n.is(f),m},d=n=>{const r=o.get(n);o.delete(n),r==null||r()},s=n=>{n.views.forEach(r=>d(r)),i.delete(n)},c=n=>{if(!(!n||u.has(n)))try{u.add(n);const r=n.components().length>0,m=i.get(n);if(r&&m)s(n);else if(!r&&!m){const f=h.has(n)?h.get(n):w.emptyStates.find(l=>p(n,l));if(h.set(n,f),!f)return;n.views.forEach(l=>{const U=f.render({editor:e,component:n,componentView:l,mount:E=>{a.set(l,E),i.set(n,!0);const W=l.getChildrenContainer();W==null||W.appendChild(E)},unmount:()=>d(l)});o.set(l,()=>{U==null||U();const E=a.get(l);E==null||E.remove()})})}}finally{u.delete(n)}},T=n=>{i.has(n)&&s(n)},C=({model:n})=>{c(n.getComponent())},b=e.Components.events,S=`${b.update}:components`,L="component:mount",k=e.Canvas.events.frameLoadBody,M=b.removed||b.remove;e.on(S,c),e.on(L,c),e.on(M,T),e.on(k,C),O({editor:e,licenseKey:w.licenseKey,plan:v.startup,pluginName:F,cleanup:()=>{e.off(S,c),e.off(L,c),e.off(M,T),e.off(k,C)}})})});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Editor, Component, ComponentView } from 'grapesjs';
|
|
2
|
+
import { SDKPluginOptions } from '../utils';
|
|
3
|
+
export interface CanvasEmptyStateOptions extends SDKPluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Empty state types to render.
|
|
6
|
+
* @examples
|
|
7
|
+
* [
|
|
8
|
+
* {
|
|
9
|
+
* isValid: 'componentA',// check for valid componet type, as a string...
|
|
10
|
+
* isValid: ['componentA', 'componentB'], // ...as an array of component types...
|
|
11
|
+
* isValid: ({ component }) => component.is('componentA'), // ...or as a function
|
|
12
|
+
* // Render function to run when the component is empty
|
|
13
|
+
* render: ({ editor, component, mount, unmount }) => {
|
|
14
|
+
* const container = document.createElement('div');
|
|
15
|
+
* // ...
|
|
16
|
+
* window.addEventListener('someGlobalEvent', onSomeEvent);
|
|
17
|
+
* mount(container);
|
|
18
|
+
* // Clean up function
|
|
19
|
+
* return () => {
|
|
20
|
+
* unmount(container);
|
|
21
|
+
* window.removeEventListener('someGlobalEvent', onSomeEvent);
|
|
22
|
+
* }
|
|
23
|
+
* },
|
|
24
|
+
* }
|
|
25
|
+
* ]
|
|
26
|
+
*/
|
|
27
|
+
emptyStates?: EmptyStateProps[];
|
|
28
|
+
}
|
|
29
|
+
export interface EmptyStateProps {
|
|
30
|
+
isValid: string | string[] | ((props: {
|
|
31
|
+
component: Component;
|
|
32
|
+
editor: Editor;
|
|
33
|
+
}) => boolean);
|
|
34
|
+
render: (props: EmptyStateRenderProps) => void | CleanUpFn;
|
|
35
|
+
}
|
|
36
|
+
type CleanUpFn = () => void;
|
|
37
|
+
interface EmptyStateRenderProps {
|
|
38
|
+
editor: Editor;
|
|
39
|
+
component: Component;
|
|
40
|
+
componentView: ComponentView;
|
|
41
|
+
mount: (el: HTMLElement) => void;
|
|
42
|
+
unmount: (el: HTMLElement) => void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";require("grapesjs");function L(e,o,s){let t,i,a,f,m;const l=o;function p(){const r=Date.now()-f;r<l&&r>=0?t=setTimeout(p,l-r):(t=null,m=e.apply(a,i),a=i=null)}const n=function(){return a=this,i=arguments,f=Date.now(),t||(t=setTimeout(p,l)),m};return n.clear=function(){t&&(clearTimeout(t),t=null)},n.flush=function(){t&&(m=e.apply(a,i),a=i=null,clearTimeout(t),t=null)},n}const $="app.grapesjs.com",D="app-stage.grapesjs.com",C=[$,D,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],O="license:check:start",x="license:check:end",A=()=>typeof window<"u",I=({isDev:e,isStage:o})=>`${e?"":`https://${o?D:$}`}/api`,k=()=>{const e=A()&&window.location.hostname;return!!e&&(C.includes(e)||C.some(o=>e.endsWith(o)))};async function H({path:e,baseApiUrl:o,method:s="GET",headers:t={},params:i,body:a}){const m=`${o||I({isDev:!1,isStage:!1})}${e}`,l={method:s,headers:{"Content-Type":"application/json",...t}};a&&(l.body=JSON.stringify(a));const p=i?new URLSearchParams(i).toString():"",n=p?`?${p}`:"",r=await fetch(`${m}${n}`,l);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return r.json()}var w=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(w||{});const S={[w.free]:0,[w.startup]:10,[w.business]:20,[w.enterprise]:30};function M(e){const o=e;return o.init=s=>t=>e(t,s),o}const N=e=>M(e);async function U({editor:e,plan:o,pluginName:s,licenseKey:t,cleanup:i}){let a="",f=!1;const m=k(),l=n=>{console.warn("Cleanup plugin:",s,"Reason:",n),i()},p=(n={})=>{var d;const{error:r,sdkLicense:c}=n,u=(d=n.plan)==null?void 0:d.category;if(!(c||n.license)||r)l(r||"Invalid license");else if(u){const b=S[o],g=S[u];b>g&&l({pluginRequiredPlan:o,licensePlan:u})}};e.on(O,n=>{a=n==null?void 0:n.baseApiUrl,f=!0}),e.on(x,n=>{p(n)}),setTimeout(async()=>{if(!f){if(m)return;if(t){const n=await W({licenseKey:t,pluginName:s,baseApiUrl:a});n&&p(n)}else l("The `licenseKey` option not provided")}},2e3)}async function W(e){const{licenseKey:o,pluginName:s,baseApiUrl:t}=e;try{return(await H({baseApiUrl:t,path:`/sdk/${o||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(i){return console.error("Error during SDK license check:",i),!1}}const R="canvasFullSize",_=function(e,o={}){const{Canvas:s,Commands:t}=e,i={deviceMaxWidth:1200,deviceMinHeigth:500,deviceBorderRadius:5,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,...o},{canvasOffsetY:a,canvasOffsetX:f,canvasTransition:m,deviceMaxWidth:l,deviceMinHeigth:p,deviceBorderRadius:n}=i;s.getConfig().scrollableCanvas=!0,e.Devices.getAll().map(c=>{!c.get("width")&&c.set("width",`${l}px`),!c.get("height")&&c.set("height","auto"),!c.get("minHeight")&&c.set("minHeight",`${p}px`)});const r=()=>{const c="data-gs-plg-full-size",u=document.querySelector(`style[${c}]`),h=u||document.createElement("style"),d=s.getZoomMultiplier();h.setAttribute(c,"true"),h.innerHTML=`
|
|
2
|
+
.gjs-frame-wrapper { transition: none !important; }
|
|
3
|
+
.gjs-frame-wrapper__bottom { height: ${a*d}px }
|
|
4
|
+
.gjs-frame { border-radius: ${n}px }
|
|
5
|
+
`,!u&&document.body.appendChild(h)};e.onReady(()=>{const c=s.getSpotsEl(),u=s.getElement(),h=s.getFramesEl();u.style.overflowX="hidden",h.style.transition=`transform ${m}s`,r();const d=()=>c.style.display="none",b=()=>c.style.display="",g=L(()=>{const v={x:f,y:a};s.getCanvasView().clearOff(),s.fitViewport({zoom:y=>y>100?100:y,ignoreHeight:!0,gap:v}),r(),setTimeout(()=>{var y,T;e.em.destroyed||((T=(y=e.getSelected())==null?void 0:y.getEl())==null||T.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),b())},310)},100),E=new ResizeObserver(()=>{d(),g()});E.observe(u.parentElement),e.on(e.Devices.events.select,()=>{d(),g()}),e.on(s.events.zoom,(v={})=>{v.options&&v.options.from!=="fitViewport"&&s.fitViewport({zoom:s.getZoom(),ignoreHeight:!0,gap:{x:f,y:a}})}),e.on(`${t.events.stopCommand}core:preview`,()=>{u.style.overflowX="hidden",u.style.overflowY="auto"}),e.on(e.events.destroy,()=>{E.disconnect(),g.clear()}),g()}),U({editor:e,licenseKey:i.licenseKey,plan:w.startup,pluginName:R,cleanup:()=>{}})},z=N(_);module.exports=z;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import "grapesjs";
|
|
2
|
+
function L(e, o, s) {
|
|
3
|
+
let t, i, a, f, m;
|
|
4
|
+
const l = o;
|
|
5
|
+
function p() {
|
|
6
|
+
const r = Date.now() - f;
|
|
7
|
+
r < l && r >= 0 ? t = setTimeout(p, l - r) : (t = null, m = e.apply(a, i), a = i = null);
|
|
8
|
+
}
|
|
9
|
+
const n = function() {
|
|
10
|
+
return a = this, i = arguments, f = Date.now(), t || (t = setTimeout(p, l)), m;
|
|
11
|
+
};
|
|
12
|
+
return n.clear = function() {
|
|
13
|
+
t && (clearTimeout(t), t = null);
|
|
14
|
+
}, n.flush = function() {
|
|
15
|
+
t && (m = e.apply(a, i), a = i = null, clearTimeout(t), t = null);
|
|
16
|
+
}, n;
|
|
17
|
+
}
|
|
18
|
+
const $ = "app.grapesjs.com", D = "app-stage.grapesjs.com", C = [
|
|
19
|
+
$,
|
|
20
|
+
D,
|
|
21
|
+
"localhost",
|
|
22
|
+
"127.0.0.1",
|
|
23
|
+
".local-credentialless.webcontainer.io",
|
|
24
|
+
// For stackblitz.com demos
|
|
25
|
+
".local.webcontainer.io",
|
|
26
|
+
// For stackblitz.com demos
|
|
27
|
+
"-sandpack.codesandbox.io"
|
|
28
|
+
// For Sandpack demos
|
|
29
|
+
], O = "license:check:start", x = "license:check:end", A = () => typeof window < "u", I = ({ isDev: e, isStage: o }) => `${e ? "" : `https://${o ? D : $}`}/api`, k = () => {
|
|
30
|
+
const e = A() && window.location.hostname;
|
|
31
|
+
return !!e && (C.includes(e) || C.some((o) => e.endsWith(o)));
|
|
32
|
+
};
|
|
33
|
+
async function H({
|
|
34
|
+
path: e,
|
|
35
|
+
baseApiUrl: o,
|
|
36
|
+
method: s = "GET",
|
|
37
|
+
headers: t = {},
|
|
38
|
+
params: i,
|
|
39
|
+
body: a
|
|
40
|
+
}) {
|
|
41
|
+
const m = `${o || I({ isDev: !1, isStage: !1 })}${e}`, l = {
|
|
42
|
+
method: s,
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
...t
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
a && (l.body = JSON.stringify(a));
|
|
49
|
+
const p = i ? new URLSearchParams(i).toString() : "", n = p ? `?${p}` : "", r = await fetch(`${m}${n}`, l);
|
|
50
|
+
if (!r.ok)
|
|
51
|
+
throw new Error(`HTTP error! status: ${r.status}`);
|
|
52
|
+
return r.json();
|
|
53
|
+
}
|
|
54
|
+
var w = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(w || {});
|
|
55
|
+
const S = {
|
|
56
|
+
[w.free]: 0,
|
|
57
|
+
[w.startup]: 10,
|
|
58
|
+
[w.business]: 20,
|
|
59
|
+
[w.enterprise]: 30
|
|
60
|
+
};
|
|
61
|
+
function M(e) {
|
|
62
|
+
const o = e;
|
|
63
|
+
return o.init = (s) => (t) => e(t, s), o;
|
|
64
|
+
}
|
|
65
|
+
const N = (e) => /* @__PURE__ */ M(e);
|
|
66
|
+
async function U({
|
|
67
|
+
editor: e,
|
|
68
|
+
plan: o,
|
|
69
|
+
pluginName: s,
|
|
70
|
+
licenseKey: t,
|
|
71
|
+
cleanup: i
|
|
72
|
+
}) {
|
|
73
|
+
let a = "", f = !1;
|
|
74
|
+
const m = k(), l = (n) => {
|
|
75
|
+
console.warn("Cleanup plugin:", s, "Reason:", n), i();
|
|
76
|
+
}, p = (n = {}) => {
|
|
77
|
+
var d;
|
|
78
|
+
const { error: r, sdkLicense: c } = n, u = (d = n.plan) == null ? void 0 : d.category;
|
|
79
|
+
if (!(c || n.license) || r)
|
|
80
|
+
l(r || "Invalid license");
|
|
81
|
+
else if (u) {
|
|
82
|
+
const b = S[o], g = S[u];
|
|
83
|
+
b > g && l({ pluginRequiredPlan: o, licensePlan: u });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
e.on(O, (n) => {
|
|
87
|
+
a = n == null ? void 0 : n.baseApiUrl, f = !0;
|
|
88
|
+
}), e.on(x, (n) => {
|
|
89
|
+
p(n);
|
|
90
|
+
}), setTimeout(async () => {
|
|
91
|
+
if (!f) {
|
|
92
|
+
if (m) return;
|
|
93
|
+
if (t) {
|
|
94
|
+
const n = await W({ licenseKey: t, pluginName: s, baseApiUrl: a });
|
|
95
|
+
n && p(n);
|
|
96
|
+
} else
|
|
97
|
+
l("The `licenseKey` option not provided");
|
|
98
|
+
}
|
|
99
|
+
}, 2e3);
|
|
100
|
+
}
|
|
101
|
+
async function W(e) {
|
|
102
|
+
const { licenseKey: o, pluginName: s, baseApiUrl: t } = e;
|
|
103
|
+
try {
|
|
104
|
+
return (await H({
|
|
105
|
+
baseApiUrl: t,
|
|
106
|
+
path: `/sdk/${o || "na"}`,
|
|
107
|
+
method: "POST",
|
|
108
|
+
params: {
|
|
109
|
+
d: window.location.hostname,
|
|
110
|
+
pn: s
|
|
111
|
+
}
|
|
112
|
+
})).result || {};
|
|
113
|
+
} catch (i) {
|
|
114
|
+
return console.error("Error during SDK license check:", i), !1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const R = "canvasFullSize", _ = function(e, o = {}) {
|
|
118
|
+
const { Canvas: s, Commands: t } = e, i = {
|
|
119
|
+
deviceMaxWidth: 1200,
|
|
120
|
+
deviceMinHeigth: 500,
|
|
121
|
+
deviceBorderRadius: 5,
|
|
122
|
+
canvasOffsetY: 30,
|
|
123
|
+
canvasOffsetX: 50,
|
|
124
|
+
canvasTransition: 0.3,
|
|
125
|
+
...o
|
|
126
|
+
}, { canvasOffsetY: a, canvasOffsetX: f, canvasTransition: m, deviceMaxWidth: l, deviceMinHeigth: p, deviceBorderRadius: n } = i;
|
|
127
|
+
s.getConfig().scrollableCanvas = !0, e.Devices.getAll().map((c) => {
|
|
128
|
+
!c.get("width") && c.set("width", `${l}px`), !c.get("height") && c.set("height", "auto"), !c.get("minHeight") && c.set("minHeight", `${p}px`);
|
|
129
|
+
});
|
|
130
|
+
const r = () => {
|
|
131
|
+
const c = "data-gs-plg-full-size", u = document.querySelector(`style[${c}]`), h = u || document.createElement("style"), d = s.getZoomMultiplier();
|
|
132
|
+
h.setAttribute(c, "true"), h.innerHTML = `
|
|
133
|
+
.gjs-frame-wrapper { transition: none !important; }
|
|
134
|
+
.gjs-frame-wrapper__bottom { height: ${a * d}px }
|
|
135
|
+
.gjs-frame { border-radius: ${n}px }
|
|
136
|
+
`, !u && document.body.appendChild(h);
|
|
137
|
+
};
|
|
138
|
+
e.onReady(() => {
|
|
139
|
+
const c = s.getSpotsEl(), u = s.getElement(), h = s.getFramesEl();
|
|
140
|
+
u.style.overflowX = "hidden", h.style.transition = `transform ${m}s`, r();
|
|
141
|
+
const d = () => c.style.display = "none", b = () => c.style.display = "", g = L(() => {
|
|
142
|
+
const v = { x: f, y: a };
|
|
143
|
+
s.getCanvasView().clearOff(), s.fitViewport({
|
|
144
|
+
// @ts-expect-error not yet available
|
|
145
|
+
zoom: (y) => y > 100 ? 100 : y,
|
|
146
|
+
ignoreHeight: !0,
|
|
147
|
+
gap: v
|
|
148
|
+
}), r(), setTimeout(() => {
|
|
149
|
+
var y, T;
|
|
150
|
+
e.em.destroyed || ((T = (y = e.getSelected()) == null ? void 0 : y.getEl()) == null || T.scrollIntoView({ block: "nearest" }), e.refresh({ tools: !0 }), b());
|
|
151
|
+
}, 310);
|
|
152
|
+
}, 100), E = new ResizeObserver(() => {
|
|
153
|
+
d(), g();
|
|
154
|
+
});
|
|
155
|
+
E.observe(u.parentElement), e.on(e.Devices.events.select, () => {
|
|
156
|
+
d(), g();
|
|
157
|
+
}), e.on(s.events.zoom, (v = {}) => {
|
|
158
|
+
v.options && v.options.from !== "fitViewport" && s.fitViewport({
|
|
159
|
+
// @ts-expect-error not yet available
|
|
160
|
+
zoom: s.getZoom(),
|
|
161
|
+
ignoreHeight: !0,
|
|
162
|
+
gap: { x: f, y: a }
|
|
163
|
+
});
|
|
164
|
+
}), e.on(`${t.events.stopCommand}core:preview`, () => {
|
|
165
|
+
u.style.overflowX = "hidden", u.style.overflowY = "auto";
|
|
166
|
+
}), e.on(e.events.destroy, () => {
|
|
167
|
+
E.disconnect(), g.clear();
|
|
168
|
+
}), g();
|
|
169
|
+
}), U({
|
|
170
|
+
editor: e,
|
|
171
|
+
licenseKey: i.licenseKey,
|
|
172
|
+
plan: w.startup,
|
|
173
|
+
pluginName: R,
|
|
174
|
+
cleanup: () => {
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}, j = N(_);
|
|
178
|
+
export {
|
|
179
|
+
j as default
|
|
180
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
(function(v,h){typeof exports=="object"&&typeof module<"u"?module.exports=h(require("grapesjs")):typeof define=="function"&&define.amd?define(["grapesjs"],h):(v=typeof globalThis<"u"?globalThis:v||self,v.StudioSdkPlugins_canvasFullSize=h())})(this,function(){"use strict";function v(e,o,s){let t,i,a,f,d;const l=o;function p(){const r=Date.now()-f;r<l&&r>=0?t=setTimeout(p,l-r):(t=null,d=e.apply(a,i),a=i=null)}const n=function(){return a=this,i=arguments,f=Date.now(),t||(t=setTimeout(p,l)),d};return n.clear=function(){t&&(clearTimeout(t),t=null)},n.flush=function(){t&&(d=e.apply(a,i),a=i=null,clearTimeout(t),t=null)},n}const h="app.grapesjs.com",S="app-stage.grapesjs.com",C=[h,S,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",O="license:check:end",k=()=>typeof window<"u",A=({isDev:e,isStage:o})=>`${e?"":`https://${o?S:h}`}/api`,I=()=>{const e=k()&&window.location.hostname;return!!e&&(C.includes(e)||C.some(o=>e.endsWith(o)))};async function j({path:e,baseApiUrl:o,method:s="GET",headers:t={},params:i,body:a}){const d=`${o||A({isDev:!1,isStage:!1})}${e}`,l={method:s,headers:{"Content-Type":"application/json",...t}};a&&(l.body=JSON.stringify(a));const p=i?new URLSearchParams(i).toString():"",n=p?`?${p}`:"",r=await fetch(`${d}${n}`,l);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return r.json()}var g=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(g||{});const $={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function H(e){const o=e;return o.init=s=>t=>e(t,s),o}const M=e=>H(e);async function N({editor:e,plan:o,pluginName:s,licenseKey:t,cleanup:i}){let a="",f=!1;const d=I(),l=n=>{console.warn("Cleanup plugin:",s,"Reason:",n),i()},p=(n={})=>{var m;const{error:r,sdkLicense:c}=n,u=(m=n.plan)==null?void 0:m.category;if(!(c||n.license)||r)l(r||"Invalid license");else if(u){const T=$[o],w=$[u];T>w&&l({pluginRequiredPlan:o,licensePlan:u})}};e.on(L,n=>{a=n==null?void 0:n.baseApiUrl,f=!0}),e.on(O,n=>{p(n)}),setTimeout(async()=>{if(!f){if(d)return;if(t){const n=await U({licenseKey:t,pluginName:s,baseApiUrl:a});n&&p(n)}else l("The `licenseKey` option not provided")}},2e3)}async function U(e){const{licenseKey:o,pluginName:s,baseApiUrl:t}=e;try{return(await j({baseApiUrl:t,path:`/sdk/${o||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(i){return console.error("Error during SDK license check:",i),!1}}const W="canvasFullSize";return M(function(e,o={}){const{Canvas:s,Commands:t}=e,i={deviceMaxWidth:1200,deviceMinHeigth:500,deviceBorderRadius:5,canvasOffsetY:30,canvasOffsetX:50,canvasTransition:.3,...o},{canvasOffsetY:a,canvasOffsetX:f,canvasTransition:d,deviceMaxWidth:l,deviceMinHeigth:p,deviceBorderRadius:n}=i;s.getConfig().scrollableCanvas=!0,e.Devices.getAll().map(c=>{!c.get("width")&&c.set("width",`${l}px`),!c.get("height")&&c.set("height","auto"),!c.get("minHeight")&&c.set("minHeight",`${p}px`)});const r=()=>{const c="data-gs-plg-full-size",u=document.querySelector(`style[${c}]`),y=u||document.createElement("style"),m=s.getZoomMultiplier();y.setAttribute(c,"true"),y.innerHTML=`
|
|
2
|
+
.gjs-frame-wrapper { transition: none !important; }
|
|
3
|
+
.gjs-frame-wrapper__bottom { height: ${a*m}px }
|
|
4
|
+
.gjs-frame { border-radius: ${n}px }
|
|
5
|
+
`,!u&&document.body.appendChild(y)};e.onReady(()=>{const c=s.getSpotsEl(),u=s.getElement(),y=s.getFramesEl();u.style.overflowX="hidden",y.style.transition=`transform ${d}s`,r();const m=()=>c.style.display="none",T=()=>c.style.display="",w=v(()=>{const E={x:f,y:a};s.getCanvasView().clearOff(),s.fitViewport({zoom:b=>b>100?100:b,ignoreHeight:!0,gap:E}),r(),setTimeout(()=>{var b,D;e.em.destroyed||((D=(b=e.getSelected())==null?void 0:b.getEl())==null||D.scrollIntoView({block:"nearest"}),e.refresh({tools:!0}),T())},310)},100),x=new ResizeObserver(()=>{m(),w()});x.observe(u.parentElement),e.on(e.Devices.events.select,()=>{m(),w()}),e.on(s.events.zoom,(E={})=>{E.options&&E.options.from!=="fitViewport"&&s.fitViewport({zoom:s.getZoom(),ignoreHeight:!0,gap:{x:f,y:a}})}),e.on(`${t.events.stopCommand}core:preview`,()=>{u.style.overflowX="hidden",u.style.overflowY="auto"}),e.on(e.events.destroy,()=>{x.disconnect(),w.clear()}),w()}),N({editor:e,licenseKey:i.licenseKey,plan:g.startup,pluginName:W,cleanup:()=>{}})})});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SDKPluginOptions } from '../utils';
|
|
2
|
+
export interface CanvasFullSizeOptions extends SDKPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* @default 30
|
|
5
|
+
*/
|
|
6
|
+
canvasOffsetY?: number;
|
|
7
|
+
/**
|
|
8
|
+
* @default 50
|
|
9
|
+
*/
|
|
10
|
+
canvasOffsetX?: number;
|
|
11
|
+
/**
|
|
12
|
+
* @default 0.3
|
|
13
|
+
*/
|
|
14
|
+
canvasTransition?: number;
|
|
15
|
+
/**
|
|
16
|
+
* @default 1200
|
|
17
|
+
*/
|
|
18
|
+
deviceMaxWidth?: number;
|
|
19
|
+
/**
|
|
20
|
+
* @default 1200
|
|
21
|
+
*/
|
|
22
|
+
deviceMinHeigth?: number;
|
|
23
|
+
/**
|
|
24
|
+
* @default 5
|
|
25
|
+
*/
|
|
26
|
+
deviceBorderRadius?: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";require("grapesjs");var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),f=(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.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e))(f||{});const v="app.grapesjs.com",w="app-stage.grapesjs.com",y=[v,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],R="license:check:start",k="license:check:end",$=()=>typeof window<"u",x=({isDev:e,isStage:t})=>`${e?"":`https://${t?w:v}`}/api`,D=()=>{const e=$()&&window.location.hostname;return!!e&&(y.includes(e)||y.some(t=>e.endsWith(t)))};async function M({path:e,baseApiUrl:t,method:s="GET",headers:o={},params:n,body:a}){const p=`${t||x({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...o}};a&&(c.body=JSON.stringify(a));const l=n?new URLSearchParams(n).toString():"",i=l?`?${l}`:"",g=await fetch(`${p}${i}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const P={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function O(e){const t=e;return t.init=s=>o=>e(o,s),t}const U=e=>O(e);async function B({editor:e,plan:t,pluginName:s,licenseKey:o,cleanup:n}){let a="",r=!1;const p=D(),c=i=>{console.warn("Cleanup plugin:",s,"Reason:",i),n()},l=(i={})=>{var b;const{error:g,sdkLicense:L}=i,h=(b=i.plan)==null?void 0:b.category;if(!(L||i.license)||g)c(g||"Invalid license");else if(h){const A=P[t],F=P[h];A>F&&c({pluginRequiredPlan:t,licensePlan:h})}};e.on(R,i=>{a=i==null?void 0:i.baseApiUrl,r=!0}),e.on(k,i=>{l(i)}),setTimeout(async()=>{if(!r){if(p)return;if(o){const i=await E({licenseKey:o,pluginName:s,baseApiUrl:a});i&&l(i)}else c("The `licenseKey` option not provided")}},2e3)}async function E(e){const{licenseKey:t,pluginName:s,baseApiUrl:o}=e;try{return(await M({baseApiUrl:o,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(n){return console.error("Error during SDK license check:",n),!1}}let u;const G=e=>{const t=[];for(const s of Object.keys(e)){let o=e[s];o&&(Array.isArray(o)?t.push(...o.map(n=>[s,n.toString()])):(o=o.toString(),t.push([s,o])))}return new URLSearchParams(t)},I=e=>({id:`${e.family}/${e.version}`,src:e.menu,name:e.family,customData:{font:e,needsLoading:!0}}),T=e=>`assetManagerMenu-${e.family}`,W=e=>{if(e.customData.needsLoading){e.customData.needsLoading=!1;const t=e.customData.font,s=new FontFace(T(t),`url(${t.menu})`);document.fonts.add(s),s.load().catch(()=>{})}},N=e=>{const{apiKey:t,searchParams:s}=e,o=(n={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",r=G(n);return`${a}?${r}`};return{id:"google-fonts",types:["font"],label:({editor:n})=>n.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var l;if(u)return u;const n={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),r={...n,...a},c=await(await fetch(o(r))).json();return(l=c.items)!=null&&l.length?(u=c.items.map(I),u):[]},itemLayout:n=>{const a=u.find(r=>r.id===n.assetProps.id);return W(a),{type:"column",onClick:()=>n.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:T(a.customData.font),fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},j={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},K="googleFontsAssetProvider",_=function(e,t){const{i18n:s={}}=t,o=N(t);e.runCommand(f.assetProviderAdd,{provider:o}),e.I18n.addMessages({en:j,...s}),B({editor:e,licenseKey:t.licenseKey,plan:d.startup,pluginName:K,cleanup:()=>{e.runCommand(f.assetProviderRemove,{id:o.id})}})},q=U(_);module.exports=q;
|