@grapesjs/studio-sdk-plugins 1.0.13 → 1.0.14-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/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/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 +1 -0
- package/dist/index.cjs.js +27 -27
- package/dist/index.d.ts +1 -0
- package/dist/index.es.d.ts +1 -0
- package/dist/index.es.js +3017 -2940
- package/dist/index.umd.js +22 -22
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +116 -99
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/locale/en.d.ts +8 -0
- package/dist/youtubeAssetProvider/types.d.ts +8 -193
- package/dist/youtubeAssetProvider/typesSchema.d.ts +199 -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,3 @@
|
|
|
1
|
+
"use strict";require("grapesjs");var L=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(L||{}),O=(e=>(e.Info="info",e.Error="error",e.Success="success",e.Warning="warning",e))(O||{}),h=(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))(h||{});const H={ratioDefault:!0,tc:!1,cl:!1,cr:!1,bc:!1},w=`<svg viewBox="0 0 24 24">
|
|
2
|
+
<path d="M19 0H9C7.9 0 7 .9 7 2V18C7 19.1 7.9 20 9 20H19C20.1 20 21 19.1 21 18V2C21 .9 20.1 0 19 0M19 18H9V2H19V18M3 4V22C3 23.1 3.9 24 5 24H17V22H5V4H3M14 5L11 10L14 15L17 10L14 5Z" />
|
|
3
|
+
</svg>`,x="layout-icon-picker",U="icons-layout-",C="icons-list-layout",R="gs-iconify-picker",P="__iconify_collection",B="https://api.iconify.design",I=new Map;let T;const D=({collectionId:e})=>`https://cdn.jsdelivr.net/npm/@iconify-json/${e}@latest/icons.json`;async function _({collectionId:e,editor:o}){try{if(I.has(e))return I.get(e);const t=await fetch(D({collectionId:e}));if(!t.ok)throw new Error(`Failed to fetch collection: ${t.statusText}`);const n=await t.json();return I.set(e,n),n}catch(t){console.error("Error fetching collection",t),o.runCommand(h.toastAdd,z());return}}async function W({collectionIds:e,editor:o}){try{if(T)return T;const t=e?`?prefixes=${e.join(",")}`:"",n=await fetch(`${B}/collections${t}`);if(!n.ok)throw new Error(`Failed to fetch collections: ${n.statusText}`);return T=await n.json(),T}catch(t){console.error("Error fetching collections",t),o.runCommand(h.toastAdd,$());return}}function A(){return{type:"button",label:"Open Icon Picker",name:"onActive",changeProp:!0,command(e){var o;(o=e.getSelected())==null||o.trigger("active")}}}async function F({collectionIds:e,editor:o,component:t}){const n=await W({collectionIds:e,editor:o});if(!n)return;const a=({icon:s,collectionId:c,iconId:i})=>{t.components(s),t.set({collectionId:c,iconId:i})},d=Object.entries(n).map(([s,c])=>({id:s,...c})).sort((s,c)=>s.name.localeCompare(c.name)),u=t.get("collectionId")??d[0].id;o.runCommand(h.layoutToggle,{id:x,placer:{type:"dialog",size:"l",title:"Select Icon"},header:!1,layout:{type:"column",style:{height:500,gap:10},children:[V({collectionsList:d,collectionId:u,editor:o,handleClick:a}),{id:C,type:"column",grow:!0}]}});const r=await _({collectionId:u,editor:o});r&&E({editor:o,collection:r,handleClick:a,collectionId:u})}function G({editor:e,collection:o}){e.em.set(P,o)}function K(e){return e.em.get(P)}function E(e){const{editor:o}=e,t={id:U,layout:Y(e),header:!1,style:{height:"100%"},placer:{type:"static",layoutId:C}};o.runCommand(h.layoutRemove,{id:t.id,force:!0}),setTimeout(()=>o.runCommand(h.layoutAdd,t),10)}function V(e){const{collectionsList:o,collectionId:t,editor:n,handleClick:a}=e,d=o.map(({id:u,name:r,total:s})=>({id:u,label:`${r} (${s})`})).sort((u,r)=>u.label.localeCompare(r.label));return{type:"column",style:{gap:10},className:`${R}__header`,children:[{type:"selectField",value:t,options:d,emptyState:"Select an icon collection",onChange:async({setState:u,value:r})=>{const s=await _({collectionId:r,editor:n});s&&(u({value:r}),G({editor:n,collection:s}),E({editor:n,collection:s,handleClick:a,collectionId:r}))}},{type:"inputField",value:"",placeholder:"Search icons inside collection...",editorEvents:{[`change:${P}`]:({setState:u})=>u({value:""})},onInput:({setState:u,value:r,editor:s})=>{const c=K(s);if(!c)return;const i=Object.fromEntries(Object.entries(c.icons).filter(([g])=>g.includes(r)));u({value:r}),E({editor:s,collection:c,handleClick:a,collectionId:r,collectionFiltered:{...c,icons:i}})}}]}}function Y({collection:e,collectionFiltered:o,handleClick:t}){const{height:n=24,width:a=24,icons:d,prefix:u}=o||e,r=Object.entries(d).map(([s,{body:c}])=>({name:s,body:c}),{});return{type:"column",className:`${R}__content`,style:{height:"100%"},children:{type:"virtualList",items:r,itemLayout:({item:s})=>[{type:"custom",render:c=>{const{editor:i,addEl:g,removeEl:f}=c,l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("xmlns","http://www.w3.org/2000/svg"),l.innerHTML=s.body,l.setAttribute("viewBox",`0 0 ${a} ${n}`);const{cssWidth:p,cssHeight:y}=q(a,n);l.style.cssText=`width: ${p}px; height: ${y}px; cursor: pointer;`,l.addEventListener("mouseover",()=>{l.style.border="2px solid currentColor",l.style.borderRadius="4px",l.style.padding="4px"}),l.addEventListener("mouseout",()=>{l.style.border="none"});const b=()=>{const v=l.cloneNode(!0);v.removeAttribute("style");const j=v.outerHTML;t({icon:j,collectionId:u,iconId:s.name}),i==null||i.runCommand(h.layoutRemove,{id:x})};return l.addEventListener("click",b),g(l),()=>{l.removeEventListener("click",b),f(l)}}}]}}}function q(e,o){const t=e/o;let n=48,a=48;return t>1?a=48/t:t<1&&(n=48*t),{cssWidth:n,cssHeight:a}}function $(){return{id:"toast-error-getCollections",header:"Error",content:"Error fetching collections",variant:O.Error}}function z(){return{...$(),id:"toast-error-getCollection",content:"Error fetching collection"}}const M="app.grapesjs.com",N="app-stage.grapesjs.com",k=[M,N,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],J="license:check:start",X="license:check:end",Z=()=>typeof window<"u",Q=({isDev:e,isStage:o})=>`${e?"":`https://${o?N:M}`}/api`,S=()=>{const e=Z()&&window.location.hostname;return!!e&&(k.includes(e)||k.some(o=>e.endsWith(o)))};async function ee({path:e,baseApiUrl:o,method:t="GET",headers:n={},params:a,body:d}){const r=`${o||Q({isDev:!1,isStage:!1})}${e}`,s={method:t,headers:{"Content-Type":"application/json",...n}};d&&(s.body=JSON.stringify(d));const c=a?new URLSearchParams(a).toString():"",i=c?`?${c}`:"",g=await fetch(`${r}${i}`,s);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const m={[L.free]:0,[L.startup]:10,[L.business]:20,[L.enterprise]:30};function te(e){const o=e;return o.init=t=>n=>e(n,t),o}const oe=e=>te(e);async function ne({editor:e,plan:o,pluginName:t,licenseKey:n,cleanup:a}){let d="",u=!1;const r=S(),s=i=>{console.warn("Cleanup plugin:",t,"Reason:",i),a()},c=(i={})=>{var y;const{error:g,sdkLicense:f}=i,l=(y=i.plan)==null?void 0:y.category;if(!(f||i.license)||g)s(g||"Invalid license");else if(l){const b=m[o],v=m[l];b>v&&s({pluginRequiredPlan:o,licensePlan:l})}};e.on(J,i=>{d=i==null?void 0:i.baseApiUrl,u=!0}),e.on(X,i=>{c(i)}),setTimeout(async()=>{if(!u){if(r)return;if(n){const i=await se({licenseKey:n,pluginName:t,baseApiUrl:d});i&&c(i)}else s("The `licenseKey` option not provided")}},2e3)}async function se(e){const{licenseKey:o,pluginName:t,baseApiUrl:n}=e;try{return(await ee({baseApiUrl:n,path:`/sdk/${o||"na"}`,method:"POST",params:{d:window.location.hostname,pn:t}})).result||{}}catch(a){return console.error("Error during SDK license check:",a),!1}}const ie=(e,o)=>{var t;return!!((t=e==null?void 0:e.hasAttribute)!=null&&t.call(e,o))},ce="iconifyComponent",re=function(e,o={}){var l;const{Components:t,Blocks:n}=e,{collections:a,extendIconComponent:d=!0,licenseKey:u,block:r={}}=o,s="icon",c="iconify",i="Iconify",g="data-type-iconify",f={events:()=>({dblclick:"onActive"}),onActive(){F({collectionIds:a,editor:e,component:this.model})}};if(t.addType(c,{block:r&&{label:i,media:w,content:{type:c},category:"Extra",activate:!0,...r},isComponent:p=>ie(p,g),model:{defaults:{name:i,icon:w,droppable:!1,attributes:{[g]:!0},resizable:H,components:w,style:{width:"50px",height:"50px"},traits:[A()]},init(){this.listenTo(this.components(),"change add",this.disableLayers),this.disableLayers()},disableLayers(){this.components().forEach(p=>p.set({layerable:!1,locked:!0}))}},view:f}),d){const p=(l=t.getType(s))==null?void 0:l.model,[y,b,...v]=p.getDefaults().traits;t.addType(s,{model:{defaults:{traits:[y,b,A(),...v]}},view:f})}ne({editor:e,licenseKey:u,plan:L.startup,pluginName:ce,cleanup:()=>{n.remove(c),t.removeType(c)}})},le=oe(re);module.exports=le;
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import "grapesjs";
|
|
2
|
+
var L = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(L || {}), O = /* @__PURE__ */ ((e) => (e.Info = "info", e.Error = "error", e.Success = "success", e.Warning = "warning", e))(O || {}), h = /* @__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.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.assetProviderGet = "studio:assetProviderGet", e.assetProviderAdd = "studio:assetProviderAdd", e.assetProviderRemove = "studio:assetProviderRemove", e))(h || {});
|
|
3
|
+
const H = { ratioDefault: !0, tc: !1, cl: !1, cr: !1, bc: !1 }, w = `<svg viewBox="0 0 24 24">
|
|
4
|
+
<path d="M19 0H9C7.9 0 7 .9 7 2V18C7 19.1 7.9 20 9 20H19C20.1 20 21 19.1 21 18V2C21 .9 20.1 0 19 0M19 18H9V2H19V18M3 4V22C3 23.1 3.9 24 5 24H17V22H5V4H3M14 5L11 10L14 15L17 10L14 5Z" />
|
|
5
|
+
</svg>`, x = "layout-icon-picker", U = "icons-layout-", C = "icons-list-layout", R = "gs-iconify-picker", P = "__iconify_collection", B = "https://api.iconify.design", I = /* @__PURE__ */ new Map();
|
|
6
|
+
let T;
|
|
7
|
+
const D = ({ collectionId: e }) => `https://cdn.jsdelivr.net/npm/@iconify-json/${e}@latest/icons.json`;
|
|
8
|
+
async function _({ collectionId: e, editor: o }) {
|
|
9
|
+
try {
|
|
10
|
+
if (I.has(e)) return I.get(e);
|
|
11
|
+
const t = await fetch(D({ collectionId: e }));
|
|
12
|
+
if (!t.ok) throw new Error(`Failed to fetch collection: ${t.statusText}`);
|
|
13
|
+
const n = await t.json();
|
|
14
|
+
return I.set(e, n), n;
|
|
15
|
+
} catch (t) {
|
|
16
|
+
console.error("Error fetching collection", t), o.runCommand(h.toastAdd, q());
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function W({ collectionIds: e, editor: o }) {
|
|
21
|
+
try {
|
|
22
|
+
if (T) return T;
|
|
23
|
+
const t = e ? `?prefixes=${e.join(",")}` : "", n = await fetch(`${B}/collections${t}`);
|
|
24
|
+
if (!n.ok) throw new Error(`Failed to fetch collections: ${n.statusText}`);
|
|
25
|
+
return T = await n.json(), T;
|
|
26
|
+
} catch (t) {
|
|
27
|
+
console.error("Error fetching collections", t), o.runCommand(h.toastAdd, $());
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function m() {
|
|
32
|
+
return {
|
|
33
|
+
type: "button",
|
|
34
|
+
label: "Open Icon Picker",
|
|
35
|
+
name: "onActive",
|
|
36
|
+
changeProp: !0,
|
|
37
|
+
command(e) {
|
|
38
|
+
var o;
|
|
39
|
+
(o = e.getSelected()) == null || o.trigger("active");
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function F({ collectionIds: e, editor: o, component: t }) {
|
|
44
|
+
const n = await W({ collectionIds: e, editor: o });
|
|
45
|
+
if (!n) return;
|
|
46
|
+
const a = ({ icon: s, collectionId: c, iconId: i }) => {
|
|
47
|
+
t.components(s), t.set({ collectionId: c, iconId: i });
|
|
48
|
+
}, d = Object.entries(n).map(([s, c]) => ({ id: s, ...c })).sort((s, c) => s.name.localeCompare(c.name)), u = t.get("collectionId") ?? d[0].id;
|
|
49
|
+
o.runCommand(h.layoutToggle, {
|
|
50
|
+
id: x,
|
|
51
|
+
placer: { type: "dialog", size: "l", title: "Select Icon" },
|
|
52
|
+
header: !1,
|
|
53
|
+
layout: {
|
|
54
|
+
type: "column",
|
|
55
|
+
style: { height: 500, gap: 10 },
|
|
56
|
+
children: [
|
|
57
|
+
V({
|
|
58
|
+
collectionsList: d,
|
|
59
|
+
collectionId: u,
|
|
60
|
+
editor: o,
|
|
61
|
+
handleClick: a
|
|
62
|
+
}),
|
|
63
|
+
{ id: C, type: "column", grow: !0 }
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const r = await _({ collectionId: u, editor: o });
|
|
68
|
+
r && E({
|
|
69
|
+
editor: o,
|
|
70
|
+
collection: r,
|
|
71
|
+
handleClick: a,
|
|
72
|
+
collectionId: u
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function G({ editor: e, collection: o }) {
|
|
76
|
+
e.em.set(P, o);
|
|
77
|
+
}
|
|
78
|
+
function K(e) {
|
|
79
|
+
return e.em.get(P);
|
|
80
|
+
}
|
|
81
|
+
function E(e) {
|
|
82
|
+
const { editor: o } = e, t = {
|
|
83
|
+
id: U,
|
|
84
|
+
layout: Y(e),
|
|
85
|
+
header: !1,
|
|
86
|
+
style: { height: "100%" },
|
|
87
|
+
placer: { type: "static", layoutId: C }
|
|
88
|
+
};
|
|
89
|
+
o.runCommand(h.layoutRemove, { id: t.id, force: !0 }), setTimeout(() => o.runCommand(h.layoutAdd, t), 10);
|
|
90
|
+
}
|
|
91
|
+
function V(e) {
|
|
92
|
+
const { collectionsList: o, collectionId: t, editor: n, handleClick: a } = e, d = o.map(({ id: u, name: r, total: s }) => ({ id: u, label: `${r} (${s})` })).sort((u, r) => u.label.localeCompare(r.label));
|
|
93
|
+
return {
|
|
94
|
+
type: "column",
|
|
95
|
+
style: { gap: 10 },
|
|
96
|
+
className: `${R}__header`,
|
|
97
|
+
children: [
|
|
98
|
+
{
|
|
99
|
+
type: "selectField",
|
|
100
|
+
value: t,
|
|
101
|
+
options: d,
|
|
102
|
+
emptyState: "Select an icon collection",
|
|
103
|
+
onChange: async ({ setState: u, value: r }) => {
|
|
104
|
+
const s = await _({ collectionId: r, editor: n });
|
|
105
|
+
s && (u({ value: r }), G({ editor: n, collection: s }), E({
|
|
106
|
+
editor: n,
|
|
107
|
+
collection: s,
|
|
108
|
+
handleClick: a,
|
|
109
|
+
collectionId: r
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: "inputField",
|
|
115
|
+
value: "",
|
|
116
|
+
placeholder: "Search icons inside collection...",
|
|
117
|
+
editorEvents: {
|
|
118
|
+
[`change:${P}`]: ({ setState: u }) => u({ value: "" })
|
|
119
|
+
},
|
|
120
|
+
onInput: ({ setState: u, value: r, editor: s }) => {
|
|
121
|
+
const c = K(s);
|
|
122
|
+
if (!c) return;
|
|
123
|
+
const i = Object.fromEntries(
|
|
124
|
+
Object.entries(c.icons).filter(([g]) => g.includes(r))
|
|
125
|
+
);
|
|
126
|
+
u({ value: r }), E({
|
|
127
|
+
editor: s,
|
|
128
|
+
collection: c,
|
|
129
|
+
handleClick: a,
|
|
130
|
+
collectionId: r,
|
|
131
|
+
collectionFiltered: { ...c, icons: i }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function Y({
|
|
139
|
+
collection: e,
|
|
140
|
+
collectionFiltered: o,
|
|
141
|
+
handleClick: t
|
|
142
|
+
}) {
|
|
143
|
+
const { height: n = 24, width: a = 24, icons: d, prefix: u } = o || e, r = Object.entries(d).map(([s, { body: c }]) => ({ name: s, body: c }), {});
|
|
144
|
+
return {
|
|
145
|
+
type: "column",
|
|
146
|
+
className: `${R}__content`,
|
|
147
|
+
style: { height: "100%" },
|
|
148
|
+
children: {
|
|
149
|
+
type: "virtualList",
|
|
150
|
+
items: r,
|
|
151
|
+
itemLayout: ({ item: s }) => [
|
|
152
|
+
{
|
|
153
|
+
type: "custom",
|
|
154
|
+
render: (c) => {
|
|
155
|
+
const { editor: i, addEl: g, removeEl: f } = c, l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
156
|
+
l.setAttribute("xmlns", "http://www.w3.org/2000/svg"), l.innerHTML = s.body, l.setAttribute("viewBox", `0 0 ${a} ${n}`);
|
|
157
|
+
const { cssWidth: p, cssHeight: y } = z(a, n);
|
|
158
|
+
l.style.cssText = `width: ${p}px; height: ${y}px; cursor: pointer;`, l.addEventListener("mouseover", () => {
|
|
159
|
+
l.style.border = "2px solid currentColor", l.style.borderRadius = "4px", l.style.padding = "4px";
|
|
160
|
+
}), l.addEventListener("mouseout", () => {
|
|
161
|
+
l.style.border = "none";
|
|
162
|
+
});
|
|
163
|
+
const b = () => {
|
|
164
|
+
const v = l.cloneNode(!0);
|
|
165
|
+
v.removeAttribute("style");
|
|
166
|
+
const j = v.outerHTML;
|
|
167
|
+
t({ icon: j, collectionId: u, iconId: s.name }), i == null || i.runCommand(h.layoutRemove, { id: x });
|
|
168
|
+
};
|
|
169
|
+
return l.addEventListener("click", b), g(l), () => {
|
|
170
|
+
l.removeEventListener("click", b), f(l);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function z(e, o) {
|
|
179
|
+
const t = e / o;
|
|
180
|
+
let n = 48, a = 48;
|
|
181
|
+
return t > 1 ? a = 48 / t : t < 1 && (n = 48 * t), { cssWidth: n, cssHeight: a };
|
|
182
|
+
}
|
|
183
|
+
function $() {
|
|
184
|
+
return {
|
|
185
|
+
id: "toast-error-getCollections",
|
|
186
|
+
header: "Error",
|
|
187
|
+
content: "Error fetching collections",
|
|
188
|
+
variant: O.Error
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function q() {
|
|
192
|
+
return {
|
|
193
|
+
...$(),
|
|
194
|
+
id: "toast-error-getCollection",
|
|
195
|
+
content: "Error fetching collection"
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const M = "app.grapesjs.com", N = "app-stage.grapesjs.com", A = [
|
|
199
|
+
M,
|
|
200
|
+
N,
|
|
201
|
+
"localhost",
|
|
202
|
+
"127.0.0.1",
|
|
203
|
+
".local-credentialless.webcontainer.io",
|
|
204
|
+
// For stackblitz.com demos
|
|
205
|
+
".local.webcontainer.io",
|
|
206
|
+
// For stackblitz.com demos
|
|
207
|
+
"-sandpack.codesandbox.io"
|
|
208
|
+
// For Sandpack demos
|
|
209
|
+
], J = "license:check:start", X = "license:check:end", Z = () => typeof window < "u", Q = ({ isDev: e, isStage: o }) => `${e ? "" : `https://${o ? N : M}`}/api`, S = () => {
|
|
210
|
+
const e = Z() && window.location.hostname;
|
|
211
|
+
return !!e && (A.includes(e) || A.some((o) => e.endsWith(o)));
|
|
212
|
+
};
|
|
213
|
+
async function ee({
|
|
214
|
+
path: e,
|
|
215
|
+
baseApiUrl: o,
|
|
216
|
+
method: t = "GET",
|
|
217
|
+
headers: n = {},
|
|
218
|
+
params: a,
|
|
219
|
+
body: d
|
|
220
|
+
}) {
|
|
221
|
+
const r = `${o || Q({ isDev: !1, isStage: !1 })}${e}`, s = {
|
|
222
|
+
method: t,
|
|
223
|
+
headers: {
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
...n
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
d && (s.body = JSON.stringify(d));
|
|
229
|
+
const c = a ? new URLSearchParams(a).toString() : "", i = c ? `?${c}` : "", g = await fetch(`${r}${i}`, s);
|
|
230
|
+
if (!g.ok)
|
|
231
|
+
throw new Error(`HTTP error! status: ${g.status}`);
|
|
232
|
+
return g.json();
|
|
233
|
+
}
|
|
234
|
+
const k = {
|
|
235
|
+
[L.free]: 0,
|
|
236
|
+
[L.startup]: 10,
|
|
237
|
+
[L.business]: 20,
|
|
238
|
+
[L.enterprise]: 30
|
|
239
|
+
};
|
|
240
|
+
function te(e) {
|
|
241
|
+
const o = e;
|
|
242
|
+
return o.init = (t) => (n) => e(n, t), o;
|
|
243
|
+
}
|
|
244
|
+
const oe = (e) => /* @__PURE__ */ te(e);
|
|
245
|
+
async function ne({
|
|
246
|
+
editor: e,
|
|
247
|
+
plan: o,
|
|
248
|
+
pluginName: t,
|
|
249
|
+
licenseKey: n,
|
|
250
|
+
cleanup: a
|
|
251
|
+
}) {
|
|
252
|
+
let d = "", u = !1;
|
|
253
|
+
const r = S(), s = (i) => {
|
|
254
|
+
console.warn("Cleanup plugin:", t, "Reason:", i), a();
|
|
255
|
+
}, c = (i = {}) => {
|
|
256
|
+
var y;
|
|
257
|
+
const { error: g, sdkLicense: f } = i, l = (y = i.plan) == null ? void 0 : y.category;
|
|
258
|
+
if (!(f || i.license) || g)
|
|
259
|
+
s(g || "Invalid license");
|
|
260
|
+
else if (l) {
|
|
261
|
+
const b = k[o], v = k[l];
|
|
262
|
+
b > v && s({ pluginRequiredPlan: o, licensePlan: l });
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
e.on(J, (i) => {
|
|
266
|
+
d = i == null ? void 0 : i.baseApiUrl, u = !0;
|
|
267
|
+
}), e.on(X, (i) => {
|
|
268
|
+
c(i);
|
|
269
|
+
}), setTimeout(async () => {
|
|
270
|
+
if (!u) {
|
|
271
|
+
if (r) return;
|
|
272
|
+
if (n) {
|
|
273
|
+
const i = await se({ licenseKey: n, pluginName: t, baseApiUrl: d });
|
|
274
|
+
i && c(i);
|
|
275
|
+
} else
|
|
276
|
+
s("The `licenseKey` option not provided");
|
|
277
|
+
}
|
|
278
|
+
}, 2e3);
|
|
279
|
+
}
|
|
280
|
+
async function se(e) {
|
|
281
|
+
const { licenseKey: o, pluginName: t, baseApiUrl: n } = e;
|
|
282
|
+
try {
|
|
283
|
+
return (await ee({
|
|
284
|
+
baseApiUrl: n,
|
|
285
|
+
path: `/sdk/${o || "na"}`,
|
|
286
|
+
method: "POST",
|
|
287
|
+
params: {
|
|
288
|
+
d: window.location.hostname,
|
|
289
|
+
pn: t
|
|
290
|
+
}
|
|
291
|
+
})).result || {};
|
|
292
|
+
} catch (a) {
|
|
293
|
+
return console.error("Error during SDK license check:", a), !1;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const ie = (e, o) => {
|
|
297
|
+
var t;
|
|
298
|
+
return !!((t = e == null ? void 0 : e.hasAttribute) != null && t.call(e, o));
|
|
299
|
+
}, ce = "iconifyComponent", re = function(e, o = {}) {
|
|
300
|
+
var l;
|
|
301
|
+
const { Components: t, Blocks: n } = e, { collections: a, extendIconComponent: d = !0, licenseKey: u, block: r = {} } = o, s = "icon", c = "iconify", i = "Iconify", g = "data-type-iconify", f = {
|
|
302
|
+
events: () => ({
|
|
303
|
+
dblclick: "onActive"
|
|
304
|
+
}),
|
|
305
|
+
onActive() {
|
|
306
|
+
F({ collectionIds: a, editor: e, component: this.model });
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
if (t.addType(c, {
|
|
310
|
+
block: r && {
|
|
311
|
+
label: i,
|
|
312
|
+
media: w,
|
|
313
|
+
content: { type: c },
|
|
314
|
+
category: "Extra",
|
|
315
|
+
activate: !0,
|
|
316
|
+
...r
|
|
317
|
+
},
|
|
318
|
+
isComponent: (p) => ie(p, g),
|
|
319
|
+
model: {
|
|
320
|
+
defaults: {
|
|
321
|
+
name: i,
|
|
322
|
+
icon: w,
|
|
323
|
+
droppable: !1,
|
|
324
|
+
attributes: { [g]: !0 },
|
|
325
|
+
resizable: H,
|
|
326
|
+
components: w,
|
|
327
|
+
style: { width: "50px", height: "50px" },
|
|
328
|
+
traits: [m()]
|
|
329
|
+
},
|
|
330
|
+
init() {
|
|
331
|
+
this.listenTo(this.components(), "change add", this.disableLayers), this.disableLayers();
|
|
332
|
+
},
|
|
333
|
+
disableLayers() {
|
|
334
|
+
this.components().forEach((p) => p.set({ layerable: !1, locked: !0 }));
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
view: f
|
|
338
|
+
}), d) {
|
|
339
|
+
const p = (l = t.getType(s)) == null ? void 0 : l.model, [y, b, ...v] = p.getDefaults().traits;
|
|
340
|
+
t.addType(s, {
|
|
341
|
+
model: {
|
|
342
|
+
defaults: {
|
|
343
|
+
traits: [y, b, m(), ...v]
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
view: f
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
ne({
|
|
350
|
+
editor: e,
|
|
351
|
+
licenseKey: u,
|
|
352
|
+
plan: L.startup,
|
|
353
|
+
pluginName: ce,
|
|
354
|
+
cleanup: () => {
|
|
355
|
+
n.remove(c), t.removeType(c);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}, ae = oe(re);
|
|
359
|
+
export {
|
|
360
|
+
ae as default
|
|
361
|
+
};
|