@grapesjs/studio-sdk-plugins 1.0.20 → 1.0.21-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.js +1 -1
- package/dist/canvasAbsoluteMode/index.es.js +173 -149
- package/dist/canvasAbsoluteMode/index.umd.js +1 -1
- package/dist/canvasAbsoluteMode/types.d.ts +7 -1
- package/dist/canvasAbsoluteMode/typesSchema.d.ts +22 -3
- package/dist/canvasAbsoluteMode/utils.d.ts +5 -0
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +124 -109
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/googleFontsAssetProvider/utils.d.ts +3 -2
- package/dist/index.cjs.js +53 -53
- package/dist/index.es.js +3178 -3142
- package/dist/index.umd.js +55 -55
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),
|
|
1
|
+
"use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),y=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(y||{});const R="app.grapesjs.com",x="app-stage.grapesjs.com",A=[R,x,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",G="license:check:end",I=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?x:R}`}/api`,M=()=>{const e=I()&&window.location.hostname;return!!e&&(A.includes(e)||A.some(t=>e.endsWith(t)))};async function j({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||U({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function B(e){const t=e;return t.init=s=>n=>e(n,s),t}const E=e=>B(e);async function W({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=M(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var w;const{error:g,sdkLicense:f}=r,d=(w=r.plan)==null?void 0:w.category;if(!(f||r.license)||g)c(g||"Invalid license");else if(d){const O=L[t],k=L[d];O>k&&c({pluginRequiredPlan:t,licensePlan:d})}};e.on($,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(G,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await N({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function N(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await j({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const b=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${b(e)}"`:b(e),F=(e,t,s)=>({family:e,variant:t,...s}),D=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:b(e),menuVariant:s&&F(v(`menuFont-${b(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},T=(e,t)=>{var l;const s=D(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=b(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},K=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const f=n.find(d=>d.tag==="wght");if(f){const{start:d,end:P}=f;l=`${d} ${P}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return D(t,{menuVariant:{source:s},variants:a})},V=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:K(e),needsLoading:!0}}),_=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,T(t)):T(t,!0)};let h;const H=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},z=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=H(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(h)return h;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(V),h):[]},itemLayout:o=>{const a=h.find(l=>l.id===o.assetProps.id),i=_(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},q={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},J="googleFontsAssetProvider",Q=function(e,t){const{i18n:s={}}=t,n=z(t);e.runCommand(y.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:q,...s}),W({editor:e,licenseKey:t.licenseKey,plan:p.startup,pluginName:J,cleanup:()=>{e.runCommand(y.assetProviderRemove,{id:n.id})}})},Z=E(Q);module.exports=Z;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}),
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}), y = /* @__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))(y || {});
|
|
2
|
+
const R = "app.grapesjs.com", x = "app-stage.grapesjs.com", A = [
|
|
3
|
+
R,
|
|
4
|
+
x,
|
|
5
5
|
"localhost",
|
|
6
6
|
"127.0.0.1",
|
|
7
7
|
".local-credentialless.webcontainer.io",
|
|
@@ -10,162 +10,177 @@ const L = "app.grapesjs.com", T = "app-stage.grapesjs.com", P = [
|
|
|
10
10
|
// For stackblitz.com demos
|
|
11
11
|
"-sandpack.codesandbox.io"
|
|
12
12
|
// For Sandpack demos
|
|
13
|
-
],
|
|
14
|
-
const e =
|
|
15
|
-
return !!e && (
|
|
13
|
+
], $ = "license:check:start", G = "license:check:end", I = () => typeof window < "u", U = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? x : R}`}/api`, M = () => {
|
|
14
|
+
const e = I() && window.location.hostname;
|
|
15
|
+
return !!e && (A.includes(e) || A.some((t) => e.endsWith(t)));
|
|
16
16
|
};
|
|
17
|
-
async function
|
|
17
|
+
async function j({
|
|
18
18
|
path: e,
|
|
19
19
|
baseApiUrl: t,
|
|
20
|
-
method:
|
|
21
|
-
headers:
|
|
20
|
+
method: s = "GET",
|
|
21
|
+
headers: n = {},
|
|
22
22
|
params: o,
|
|
23
|
-
body:
|
|
23
|
+
body: r
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
26
|
-
method:
|
|
25
|
+
const l = `${t || U({ isDev: !1, isStage: !1 })}${e}`, c = {
|
|
26
|
+
method: s,
|
|
27
27
|
headers: {
|
|
28
28
|
"Content-Type": "application/json",
|
|
29
|
-
...
|
|
29
|
+
...n
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
const u = o ? new URLSearchParams(o).toString() : "",
|
|
32
|
+
r && (c.body = JSON.stringify(r));
|
|
33
|
+
const u = o ? new URLSearchParams(o).toString() : "", a = u ? `?${u}` : "", g = await fetch(`${l}${a}`, c);
|
|
34
34
|
if (!g.ok)
|
|
35
35
|
throw new Error(`HTTP error! status: ${g.status}`);
|
|
36
36
|
return g.json();
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const L = {
|
|
39
39
|
[p.free]: 0,
|
|
40
40
|
[p.startup]: 10,
|
|
41
41
|
[p.business]: 20,
|
|
42
42
|
[p.enterprise]: 30
|
|
43
43
|
};
|
|
44
|
-
function
|
|
44
|
+
function B(e) {
|
|
45
45
|
const t = e;
|
|
46
|
-
return t.init = (
|
|
46
|
+
return t.init = (s) => (n) => e(n, s), t;
|
|
47
47
|
}
|
|
48
|
-
const
|
|
49
|
-
async function
|
|
48
|
+
const E = (e) => /* @__PURE__ */ B(e);
|
|
49
|
+
async function W({
|
|
50
50
|
editor: e,
|
|
51
51
|
plan: t,
|
|
52
|
-
pluginName:
|
|
53
|
-
licenseKey:
|
|
52
|
+
pluginName: s,
|
|
53
|
+
licenseKey: n,
|
|
54
54
|
cleanup: o
|
|
55
55
|
}) {
|
|
56
|
-
let
|
|
57
|
-
const
|
|
58
|
-
console.warn("Cleanup plugin:",
|
|
59
|
-
}, u = (
|
|
60
|
-
var
|
|
61
|
-
const { error: g, sdkLicense: f } =
|
|
62
|
-
if (!(f ||
|
|
63
|
-
|
|
56
|
+
let r = "", i = !1;
|
|
57
|
+
const l = M(), c = (a) => {
|
|
58
|
+
console.warn("Cleanup plugin:", s, "Reason:", a), o();
|
|
59
|
+
}, u = (a = {}) => {
|
|
60
|
+
var w;
|
|
61
|
+
const { error: g, sdkLicense: f } = a, d = (w = a.plan) == null ? void 0 : w.category;
|
|
62
|
+
if (!(f || a.license) || g)
|
|
63
|
+
c(g || "Invalid license");
|
|
64
64
|
else if (d) {
|
|
65
|
-
const
|
|
66
|
-
|
|
65
|
+
const O = L[t], k = L[d];
|
|
66
|
+
O > k && c({ pluginRequiredPlan: t, licensePlan: d });
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
-
e.on(
|
|
70
|
-
|
|
71
|
-
}), e.on(
|
|
72
|
-
u(
|
|
69
|
+
e.on($, (a) => {
|
|
70
|
+
r = a == null ? void 0 : a.baseApiUrl, i = !0;
|
|
71
|
+
}), e.on(G, (a) => {
|
|
72
|
+
u(a);
|
|
73
73
|
}), setTimeout(async () => {
|
|
74
|
-
if (!
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
|
|
74
|
+
if (!i) {
|
|
75
|
+
if (l) return;
|
|
76
|
+
if (n) {
|
|
77
|
+
const a = await N({ licenseKey: n, pluginName: s, baseApiUrl: r });
|
|
78
|
+
a && u(a);
|
|
79
79
|
} else
|
|
80
|
-
|
|
80
|
+
c("The `licenseKey` option not provided");
|
|
81
81
|
}
|
|
82
82
|
}, 2e3);
|
|
83
83
|
}
|
|
84
|
-
async function
|
|
85
|
-
const { licenseKey: t, pluginName:
|
|
84
|
+
async function N(e) {
|
|
85
|
+
const { licenseKey: t, pluginName: s, baseApiUrl: n } = e;
|
|
86
86
|
try {
|
|
87
|
-
return (await
|
|
88
|
-
baseApiUrl:
|
|
87
|
+
return (await j({
|
|
88
|
+
baseApiUrl: n,
|
|
89
89
|
path: `/sdk/${t || "na"}`,
|
|
90
90
|
method: "POST",
|
|
91
91
|
params: {
|
|
92
92
|
d: window.location.hostname,
|
|
93
|
-
pn:
|
|
93
|
+
pn: s
|
|
94
94
|
}
|
|
95
95
|
})).result || {};
|
|
96
96
|
} catch (o) {
|
|
97
97
|
return console.error("Error during SDK license check:", o), !1;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
100
|
+
const b = (e) => e.replaceAll('"', "").replaceAll("'", ""), v = (e) => e.includes(",") ? e : /\s/.test(e) ? `"${b(e)}"` : b(e), F = (e, t, s) => ({ family: e, variant: t, ...s }), D = (e, t) => {
|
|
101
|
+
e = v(e);
|
|
102
|
+
const { menuVariant: s, variants: n } = t;
|
|
103
|
+
return {
|
|
104
|
+
family: e,
|
|
105
|
+
familyLabel: b(e),
|
|
106
|
+
menuVariant: s && F(
|
|
107
|
+
v(`menuFont-${b(e)}`),
|
|
108
|
+
"regular",
|
|
109
|
+
s
|
|
110
|
+
),
|
|
111
|
+
variants: Object.assign(
|
|
112
|
+
{},
|
|
113
|
+
...Object.entries(n).map(([o, r]) => ({
|
|
114
|
+
[o]: F(e, o, r)
|
|
115
|
+
}))
|
|
116
|
+
)
|
|
117
|
+
};
|
|
118
|
+
}, T = (e, t) => {
|
|
119
|
+
var l;
|
|
120
|
+
const s = D(e.family, e), n = s.menuVariant ?? ((l = Object.values(s.variants)) == null ? void 0 : l[0]);
|
|
103
121
|
if (!n)
|
|
104
122
|
return "Arial, Helvetica, sans-serif";
|
|
105
|
-
const {
|
|
123
|
+
const { source: o, descriptors: r } = n, i = b(n.family);
|
|
106
124
|
if (!t) {
|
|
107
|
-
const c = new FontFace(
|
|
125
|
+
const c = new FontFace(i, `url("${o}")`, r), u = Array.from(document.fonts.values()).filter((a) => a.family === i);
|
|
126
|
+
for (const a of u)
|
|
127
|
+
document.fonts.delete(a);
|
|
108
128
|
document.fonts.add(c), c.load().catch(() => {
|
|
109
129
|
});
|
|
110
130
|
}
|
|
111
|
-
return
|
|
112
|
-
},
|
|
113
|
-
const { family: t, menu:
|
|
131
|
+
return v(i);
|
|
132
|
+
}, K = (e) => {
|
|
133
|
+
const { family: t, menu: s, axes: n } = e, o = !!n, r = Object.assign(
|
|
114
134
|
{},
|
|
115
|
-
...e.variants.map((
|
|
116
|
-
var
|
|
117
|
-
let
|
|
135
|
+
...e.variants.map((i) => {
|
|
136
|
+
var a, g;
|
|
137
|
+
let l, c;
|
|
118
138
|
if (o) {
|
|
119
|
-
const f =
|
|
139
|
+
const f = n.find((d) => d.tag === "wght");
|
|
120
140
|
if (f) {
|
|
121
|
-
const { start: d, end:
|
|
122
|
-
|
|
141
|
+
const { start: d, end: P } = f;
|
|
142
|
+
l = `${d} ${P}`;
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
|
-
return
|
|
126
|
-
[
|
|
127
|
-
|
|
128
|
-
source: e.files[r],
|
|
129
|
-
variant: r,
|
|
145
|
+
return l || (l = ((a = i.match(/\d+/)) == null ? void 0 : a[0]) ?? "400"), c = ((g = i.match(/[a-zA-Z]+/)) == null ? void 0 : g[0]) === "italic" ? "italic" : void 0, {
|
|
146
|
+
[i]: {
|
|
147
|
+
source: e.files[i],
|
|
130
148
|
descriptors: {
|
|
131
|
-
style:
|
|
132
|
-
weight:
|
|
149
|
+
style: c,
|
|
150
|
+
weight: l
|
|
133
151
|
}
|
|
134
152
|
}
|
|
135
153
|
};
|
|
136
154
|
})
|
|
137
155
|
);
|
|
138
|
-
return {
|
|
139
|
-
family: t,
|
|
156
|
+
return D(t, {
|
|
140
157
|
menuVariant: {
|
|
141
|
-
|
|
142
|
-
source: n,
|
|
143
|
-
variant: "menu"
|
|
158
|
+
source: s
|
|
144
159
|
},
|
|
145
|
-
variants:
|
|
146
|
-
};
|
|
147
|
-
},
|
|
160
|
+
variants: r
|
|
161
|
+
});
|
|
162
|
+
}, V = (e) => ({
|
|
148
163
|
id: `${e.family}/${e.version}`,
|
|
149
164
|
type: "font",
|
|
150
165
|
src: e.menu,
|
|
151
166
|
name: e.family,
|
|
152
|
-
customData: { font:
|
|
153
|
-
}),
|
|
167
|
+
customData: { font: K(e), needsLoading: !0 }
|
|
168
|
+
}), _ = (e) => {
|
|
154
169
|
const { font: t } = e.customData;
|
|
155
|
-
return e.customData.needsLoading ? (e.customData.needsLoading = !1,
|
|
170
|
+
return e.customData.needsLoading ? (e.customData.needsLoading = !1, T(t)) : T(t, !0);
|
|
156
171
|
};
|
|
157
172
|
let h;
|
|
158
|
-
const
|
|
173
|
+
const H = (e) => {
|
|
159
174
|
const t = [];
|
|
160
|
-
for (const
|
|
161
|
-
let
|
|
162
|
-
|
|
175
|
+
for (const s of Object.keys(e)) {
|
|
176
|
+
let n = e[s];
|
|
177
|
+
n && (Array.isArray(n) ? t.push(...n.map((o) => [s, o.toString()])) : (n = n.toString(), t.push([s, n])));
|
|
163
178
|
}
|
|
164
179
|
return new URLSearchParams(t);
|
|
165
|
-
},
|
|
166
|
-
const { apiKey: t, searchParams:
|
|
167
|
-
const
|
|
168
|
-
return `${
|
|
180
|
+
}, z = (e) => {
|
|
181
|
+
const { apiKey: t, searchParams: s } = e, n = (o = {}) => {
|
|
182
|
+
const r = "https://www.googleapis.com/webfonts/v1/webfonts", i = H(o);
|
|
183
|
+
return `${r}?${i}`;
|
|
169
184
|
};
|
|
170
185
|
return {
|
|
171
186
|
id: "google-fonts",
|
|
@@ -181,19 +196,19 @@ const N = (e) => {
|
|
|
181
196
|
sort: "alpha",
|
|
182
197
|
subset: "latin",
|
|
183
198
|
capability: ["WOFF2", "VF"]
|
|
184
|
-
},
|
|
199
|
+
}, r = s == null ? void 0 : s(), i = {
|
|
185
200
|
...o,
|
|
186
|
-
...
|
|
187
|
-
},
|
|
188
|
-
return (u =
|
|
201
|
+
...r
|
|
202
|
+
}, c = await (await fetch(n(i))).json();
|
|
203
|
+
return (u = c.items) != null && u.length ? (h = c.items.map(V), h) : [];
|
|
189
204
|
},
|
|
190
205
|
itemLayout: (o) => {
|
|
191
|
-
const
|
|
206
|
+
const r = h.find((l) => l.id === o.assetProps.id), i = _(r);
|
|
192
207
|
return {
|
|
193
208
|
type: "column",
|
|
194
|
-
onClick: () => o.onSelect(
|
|
209
|
+
onClick: () => o.onSelect(r),
|
|
195
210
|
htmlAttrs: {
|
|
196
|
-
title:
|
|
211
|
+
title: r.name
|
|
197
212
|
},
|
|
198
213
|
style: {
|
|
199
214
|
borderWidth: "1px",
|
|
@@ -204,12 +219,12 @@ const N = (e) => {
|
|
|
204
219
|
children: [
|
|
205
220
|
{
|
|
206
221
|
type: "text",
|
|
207
|
-
content:
|
|
222
|
+
content: r.name,
|
|
208
223
|
style: {
|
|
209
224
|
overflow: "hidden",
|
|
210
225
|
textOverflow: "ellipsis",
|
|
211
226
|
whiteSpace: "nowrap",
|
|
212
|
-
fontFamily:
|
|
227
|
+
fontFamily: i,
|
|
213
228
|
fontSize: "24px",
|
|
214
229
|
paddingLeft: "8px",
|
|
215
230
|
paddingRight: "8px"
|
|
@@ -217,7 +232,7 @@ const N = (e) => {
|
|
|
217
232
|
},
|
|
218
233
|
{
|
|
219
234
|
type: "text",
|
|
220
|
-
content:
|
|
235
|
+
content: r.name,
|
|
221
236
|
style: {
|
|
222
237
|
overflow: "hidden",
|
|
223
238
|
textOverflow: "ellipsis",
|
|
@@ -231,27 +246,27 @@ const N = (e) => {
|
|
|
231
246
|
};
|
|
232
247
|
}
|
|
233
248
|
};
|
|
234
|
-
},
|
|
249
|
+
}, q = {
|
|
235
250
|
googleFontsAssetProvider: {
|
|
236
251
|
searchBtn: "Search on Google Fonts",
|
|
237
252
|
modalTitle: "Select Font",
|
|
238
253
|
providerLabel: "Google Fonts"
|
|
239
254
|
}
|
|
240
|
-
},
|
|
241
|
-
const { i18n:
|
|
242
|
-
e.runCommand(
|
|
243
|
-
en:
|
|
244
|
-
...
|
|
245
|
-
}),
|
|
255
|
+
}, J = "googleFontsAssetProvider", Q = function(e, t) {
|
|
256
|
+
const { i18n: s = {} } = t, n = z(t);
|
|
257
|
+
e.runCommand(y.assetProviderAdd, { provider: n }), e.I18n.addMessages({
|
|
258
|
+
en: q,
|
|
259
|
+
...s
|
|
260
|
+
}), W({
|
|
246
261
|
editor: e,
|
|
247
262
|
licenseKey: t.licenseKey,
|
|
248
263
|
plan: p.startup,
|
|
249
|
-
pluginName:
|
|
264
|
+
pluginName: J,
|
|
250
265
|
cleanup: () => {
|
|
251
|
-
e.runCommand(
|
|
266
|
+
e.runCommand(y.assetProviderRemove, { id: n.id });
|
|
252
267
|
}
|
|
253
268
|
});
|
|
254
|
-
},
|
|
269
|
+
}, Z = E(Q);
|
|
255
270
|
export {
|
|
256
|
-
|
|
271
|
+
Z as default
|
|
257
272
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),p=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(p||{});const P="app.grapesjs.com",A="app-stage.grapesjs.com",w=[P,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],D="license:check:start",O="license:check:end",$=()=>typeof window<"u",G=({isDev:e,isStage:t})=>`${e?"":`https://${t?A:P}`}/api`,I=()=>{const e=$()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function U({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||G({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const F={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function M(e){const t=e;return t.init=s=>n=>e(n,s),t}const j=e=>M(e);async function B({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=I(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var k;const{error:g,sdkLicense:y}=r,f=(k=r.plan)==null?void 0:k.category;if(!(y||r.license)||g)c(g||"Invalid license");else if(f){const q=F[t],S=F[f];q>S&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(D,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(O,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await E({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function E(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await U({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const h=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${h(e)}"`:h(e),L=(e,t,s)=>({family:e,variant:t,...s}),T=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:h(e),menuVariant:s&&L(v(`menuFont-${h(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:L(e,o,a)})))}},x=(e,t)=>{var l;const s=T(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=h(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},W=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const y=n.find(f=>f.tag==="wght");if(y){const{start:f,end:R}=y;l=`${f} ${R}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return T(t,{menuVariant:{source:s},variants:a})},N=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:W(e),needsLoading:!0}}),_=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,x(t)):x(t,!0)};let b;const K=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},V=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=K(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(b)return b;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(b=c.items.map(N),b):[]},itemLayout:o=>{const a=b.find(l=>l.id===o.assetProps.id),i=_(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},H={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},z="googleFontsAssetProvider";return j(function(e,t){const{i18n:s={}}=t,n=V(t);e.runCommand(p.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:H,...s}),B({editor:e,licenseKey:t.licenseKey,plan:d.startup,pluginName:z,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:n.id})}})})});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InternalFont } from '@studio/editor/src/types';
|
|
2
|
+
import { FontAssetProps } from '../types';
|
|
2
3
|
import { GoogleFontFamily } from './types';
|
|
3
|
-
export declare const toFont: (googleFont: GoogleFontFamily) =>
|
|
4
|
+
export declare const toFont: (googleFont: GoogleFontFamily) => InternalFont;
|
|
4
5
|
export declare const toAssetProps: (googleFont: GoogleFontFamily) => FontAssetProps;
|
|
5
6
|
export declare const loadMenuFontAsset: (assetProps: FontAssetProps) => string;
|