@grapesjs/studio-sdk-plugins 1.0.14 → 1.0.15-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.
Files changed (65) hide show
  1. package/dist/accordionComponent/components/Accordion.d.ts +4 -0
  2. package/dist/accordionComponent/components/AccordionContent.d.ts +3 -0
  3. package/dist/accordionComponent/components/AccordionGroup.d.ts +4 -0
  4. package/dist/accordionComponent/components/AccordionHeader.d.ts +4 -0
  5. package/dist/accordionComponent/components/AccordionMarker.d.ts +3 -0
  6. package/dist/accordionComponent/index.cjs.d.ts +3 -0
  7. package/dist/accordionComponent/index.cjs.js +39 -0
  8. package/dist/accordionComponent/index.d.ts +3 -0
  9. package/dist/accordionComponent/index.es.d.ts +3 -0
  10. package/dist/accordionComponent/index.es.js +360 -0
  11. package/dist/accordionComponent/index.umd.js +39 -0
  12. package/dist/accordionComponent/types.d.ts +6 -0
  13. package/dist/accordionComponent/typesSchema.d.ts +22 -0
  14. package/dist/accordionComponent/utils.d.ts +22 -0
  15. package/dist/canvasEmptyState/index.cjs.js +1 -1
  16. package/dist/canvasEmptyState/index.es.js +15 -15
  17. package/dist/canvasEmptyState/index.umd.js +1 -1
  18. package/dist/canvasFullSize/index.cjs.js +5 -5
  19. package/dist/canvasFullSize/index.es.js +138 -118
  20. package/dist/canvasFullSize/index.umd.js +5 -5
  21. package/dist/canvasFullSize/typesSchema.d.ts +12 -8
  22. package/dist/flexComponent/blocks.d.ts +3 -0
  23. package/dist/flexComponent/components/FlexColumn.d.ts +4 -0
  24. package/dist/flexComponent/components/FlexRow.d.ts +4 -0
  25. package/dist/flexComponent/handlers.d.ts +19 -0
  26. package/dist/flexComponent/index.cjs.d.ts +3 -0
  27. package/dist/flexComponent/index.cjs.js +33 -0
  28. package/dist/flexComponent/index.d.ts +3 -0
  29. package/dist/flexComponent/index.es.d.ts +3 -0
  30. package/dist/flexComponent/index.es.js +715 -0
  31. package/dist/flexComponent/index.umd.js +33 -0
  32. package/dist/flexComponent/resizeDecorator.d.ts +50 -0
  33. package/dist/flexComponent/spots.d.ts +3 -0
  34. package/dist/flexComponent/types.d.ts +32 -0
  35. package/dist/flexComponent/typesSchema.d.ts +112 -0
  36. package/dist/flexComponent/utils.d.ts +63 -0
  37. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  38. package/dist/googleFontsAssetProvider/index.es.js +128 -91
  39. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  40. package/dist/googleFontsAssetProvider/types.d.ts +7 -2
  41. package/dist/googleFontsAssetProvider/utils.d.ts +5 -0
  42. package/dist/iconifyComponent/index.cjs.js +2 -2
  43. package/dist/iconifyComponent/index.es.js +39 -39
  44. package/dist/iconifyComponent/index.umd.js +2 -2
  45. package/dist/index.cjs.d.ts +2 -0
  46. package/dist/index.cjs.js +105 -35
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.es.d.ts +2 -0
  49. package/dist/index.es.js +6286 -5366
  50. package/dist/index.umd.js +105 -35
  51. package/dist/prosemirror/index.cjs.js +1 -1
  52. package/dist/prosemirror/index.es.js +1 -1
  53. package/dist/prosemirror/index.umd.js +1 -1
  54. package/dist/rteTinyMce/index.cjs.js +1 -1
  55. package/dist/rteTinyMce/index.es.js +28 -28
  56. package/dist/rteTinyMce/index.umd.js +1 -1
  57. package/dist/tableComponent/index.cjs.js +1 -1
  58. package/dist/tableComponent/index.es.js +31 -30
  59. package/dist/tableComponent/index.umd.js +1 -1
  60. package/dist/types.d.ts +3 -1
  61. package/dist/utils.d.ts +4 -0
  62. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  63. package/dist/youtubeAssetProvider/index.es.js +11 -11
  64. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  65. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
1
  import "grapesjs";
2
- var d = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(d || {}), f = /* @__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))(f || {});
3
- const v = "app.grapesjs.com", w = "app-stage.grapesjs.com", y = [
4
- v,
5
- w,
2
+ var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}), b = /* @__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.fontGet = "studio:fontGet", e.fontAdd = "studio:fontAdd", e.fontRemove = "studio:fontRemove", e))(b || {});
3
+ const A = "app.grapesjs.com", T = "app-stage.grapesjs.com", v = [
4
+ A,
5
+ T,
6
6
  "localhost",
7
7
  "127.0.0.1",
8
8
  ".local-credentialless.webcontainer.io",
@@ -11,143 +11,180 @@ const v = "app.grapesjs.com", w = "app-stage.grapesjs.com", y = [
11
11
  // For stackblitz.com demos
12
12
  "-sandpack.codesandbox.io"
13
13
  // For Sandpack demos
14
- ], R = "license:check:start", k = "license:check:end", $ = () => typeof window < "u", x = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? w : v}`}/api`, D = () => {
15
- const e = $() && window.location.hostname;
16
- return !!e && (y.includes(e) || y.some((t) => e.endsWith(t)));
14
+ ], $ = "license:check:start", k = "license:check:end", x = () => typeof window < "u", D = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? T : A}`}/api`, F = () => {
15
+ const e = x() && window.location.hostname;
16
+ return !!e && (v.includes(e) || v.some((t) => e.endsWith(t)));
17
17
  };
18
- async function M({
18
+ async function G({
19
19
  path: e,
20
20
  baseApiUrl: t,
21
- method: s = "GET",
22
- headers: o = {},
23
- params: n,
21
+ method: n = "GET",
22
+ headers: s = {},
23
+ params: o,
24
24
  body: i
25
25
  }) {
26
- const p = `${t || x({ isDev: !1, isStage: !1 })}${e}`, c = {
27
- method: s,
26
+ const l = `${t || D({ isDev: !1, isStage: !1 })}${e}`, c = {
27
+ method: n,
28
28
  headers: {
29
29
  "Content-Type": "application/json",
30
- ...o
30
+ ...s
31
31
  }
32
32
  };
33
33
  i && (c.body = JSON.stringify(i));
34
- const l = n ? new URLSearchParams(n).toString() : "", a = l ? `?${l}` : "", g = await fetch(`${p}${a}`, c);
35
- if (!g.ok)
36
- throw new Error(`HTTP error! status: ${g.status}`);
37
- return g.json();
34
+ const d = o ? new URLSearchParams(o).toString() : "", a = d ? `?${d}` : "", u = await fetch(`${l}${a}`, c);
35
+ if (!u.ok)
36
+ throw new Error(`HTTP error! status: ${u.status}`);
37
+ return u.json();
38
38
  }
39
- const P = {
40
- [d.free]: 0,
41
- [d.startup]: 10,
42
- [d.business]: 20,
43
- [d.enterprise]: 30
39
+ const w = {
40
+ [p.free]: 0,
41
+ [p.startup]: 10,
42
+ [p.business]: 20,
43
+ [p.enterprise]: 30
44
44
  };
45
45
  function O(e) {
46
46
  const t = e;
47
- return t.init = (s) => (o) => e(o, s), t;
47
+ return t.init = (n) => (s) => e(s, n), t;
48
48
  }
49
- const U = (e) => /* @__PURE__ */ O(e);
50
- async function B({
49
+ const M = (e) => /* @__PURE__ */ O(e);
50
+ async function U({
51
51
  editor: e,
52
52
  plan: t,
53
- pluginName: s,
54
- licenseKey: o,
55
- cleanup: n
53
+ pluginName: n,
54
+ licenseKey: s,
55
+ cleanup: o
56
56
  }) {
57
57
  let i = "", r = !1;
58
- const p = D(), c = (a) => {
59
- console.warn("Cleanup plugin:", s, "Reason:", a), n();
60
- }, l = (a = {}) => {
61
- var b;
62
- const { error: g, sdkLicense: L } = a, h = (b = a.plan) == null ? void 0 : b.category;
63
- if (!(L || a.license) || g)
64
- c(g || "Invalid license");
65
- else if (h) {
66
- const A = P[t], F = P[h];
67
- A > F && c({ pluginRequiredPlan: t, licensePlan: h });
58
+ const l = F(), c = (a) => {
59
+ console.warn("Cleanup plugin:", n, "Reason:", a), o();
60
+ }, d = (a = {}) => {
61
+ var P;
62
+ const { error: u, sdkLicense: f } = a, g = (P = a.plan) == null ? void 0 : P.category;
63
+ if (!(f || a.license) || u)
64
+ c(u || "Invalid license");
65
+ else if (g) {
66
+ const L = w[t], R = w[g];
67
+ L > R && c({ pluginRequiredPlan: t, licensePlan: g });
68
68
  }
69
69
  };
70
- e.on(R, (a) => {
70
+ e.on($, (a) => {
71
71
  i = a == null ? void 0 : a.baseApiUrl, r = !0;
72
72
  }), e.on(k, (a) => {
73
- l(a);
73
+ d(a);
74
74
  }), setTimeout(async () => {
75
75
  if (!r) {
76
- if (p) return;
77
- if (o) {
78
- const a = await E({ licenseKey: o, pluginName: s, baseApiUrl: i });
79
- a && l(a);
76
+ if (l) return;
77
+ if (s) {
78
+ const a = await B({ licenseKey: s, pluginName: n, baseApiUrl: i });
79
+ a && d(a);
80
80
  } else
81
81
  c("The `licenseKey` option not provided");
82
82
  }
83
83
  }, 2e3);
84
84
  }
85
- async function E(e) {
86
- const { licenseKey: t, pluginName: s, baseApiUrl: o } = e;
85
+ async function B(e) {
86
+ const { licenseKey: t, pluginName: n, baseApiUrl: s } = e;
87
87
  try {
88
- return (await M({
89
- baseApiUrl: o,
88
+ return (await G({
89
+ baseApiUrl: s,
90
90
  path: `/sdk/${t || "na"}`,
91
91
  method: "POST",
92
92
  params: {
93
93
  d: window.location.hostname,
94
- pn: s
94
+ pn: n
95
95
  }
96
96
  })).result || {};
97
- } catch (n) {
98
- return console.error("Error during SDK license check:", n), !1;
97
+ } catch (o) {
98
+ return console.error("Error during SDK license check:", o), !1;
99
99
  }
100
100
  }
101
- let u;
102
- const G = (e) => {
103
- const t = [];
104
- for (const s of Object.keys(e)) {
105
- let o = e[s];
106
- o && (Array.isArray(o) ? t.push(...o.map((n) => [s, n.toString()])) : (o = o.toString(), t.push([s, o])));
107
- }
108
- return new URLSearchParams(t);
101
+ const E = (e) => {
102
+ const { family: t, menu: n, axes: s } = e, o = !!s, i = Object.assign(
103
+ {},
104
+ ...e.variants.map((r) => {
105
+ var a, u;
106
+ let l, c;
107
+ if (o) {
108
+ const f = s.find((g) => g.tag === "wght");
109
+ if (f) {
110
+ const { start: g, end: y } = f;
111
+ l = `${g} ${y}`;
112
+ }
113
+ }
114
+ return l || (l = ((a = r.match(/\d+/)) == null ? void 0 : a[0]) ?? "400"), c = ((u = r.match(/[a-zA-Z]+/)) == null ? void 0 : u[0]) === "italic" ? "italic" : void 0, {
115
+ [r]: {
116
+ family: t,
117
+ source: e.files[r],
118
+ variant: r,
119
+ options: {
120
+ style: c,
121
+ weight: l
122
+ }
123
+ }
124
+ };
125
+ })
126
+ );
127
+ return {
128
+ family: t,
129
+ menuVariant: {
130
+ family: `assetManagerMenu-${t}`,
131
+ source: n,
132
+ variant: "menu"
133
+ },
134
+ variants: i
135
+ };
109
136
  }, I = (e) => ({
110
137
  id: `${e.family}/${e.version}`,
138
+ type: "font",
111
139
  src: e.menu,
112
140
  name: e.family,
113
- customData: { font: e, needsLoading: !0 }
114
- }), T = (e) => `assetManagerMenu-${e.family}`, W = (e) => {
141
+ customData: { font: E(e), needsLoading: !0 }
142
+ }), m = (e) => {
115
143
  if (e.customData.needsLoading) {
116
144
  e.customData.needsLoading = !1;
117
- const t = e.customData.font, s = new FontFace(T(t), `url(${t.menu})`);
118
- document.fonts.add(s), s.load().catch(() => {
145
+ const { font: t } = e.customData, { family: n, source: s, options: o } = t.menuVariant, i = new FontFace(n, `url("${s}")`, o);
146
+ document.fonts.add(i), i.load().catch(() => {
119
147
  });
120
148
  }
121
- }, N = (e) => {
122
- const { apiKey: t, searchParams: s } = e, o = (n = {}) => {
123
- const i = "https://www.googleapis.com/webfonts/v1/webfonts", r = G(n);
149
+ };
150
+ let h;
151
+ const W = (e) => {
152
+ const t = [];
153
+ for (const n of Object.keys(e)) {
154
+ let s = e[n];
155
+ s && (Array.isArray(s) ? t.push(...s.map((o) => [n, o.toString()])) : (s = s.toString(), t.push([n, s])));
156
+ }
157
+ return new URLSearchParams(t);
158
+ }, j = (e) => {
159
+ const { apiKey: t, searchParams: n } = e, s = (o = {}) => {
160
+ const i = "https://www.googleapis.com/webfonts/v1/webfonts", r = W(o);
124
161
  return `${i}?${r}`;
125
162
  };
126
163
  return {
127
164
  id: "google-fonts",
128
165
  types: ["font"],
129
- label: ({ editor: n }) => n.I18n.t("googleFontsAssetProvider.providerLabel"),
166
+ label: ({ editor: o }) => o.I18n.t("googleFontsAssetProvider.providerLabel"),
130
167
  search: { reloadOnInput: !1 },
131
168
  async onLoad() {
132
- var l;
133
- if (u)
134
- return u;
135
- const n = {
169
+ var d;
170
+ if (h)
171
+ return h;
172
+ const o = {
136
173
  key: t,
137
174
  sort: "alpha",
138
175
  subset: "latin",
139
176
  capability: ["WOFF2", "VF"]
140
- }, i = s == null ? void 0 : s(), r = {
141
- ...n,
177
+ }, i = n == null ? void 0 : n(), r = {
178
+ ...o,
142
179
  ...i
143
- }, c = await (await fetch(o(r))).json();
144
- return (l = c.items) != null && l.length ? (u = c.items.map(I), u) : [];
180
+ }, c = await (await fetch(s(r))).json();
181
+ return (d = c.items) != null && d.length ? (h = c.items.map(I), h) : [];
145
182
  },
146
- itemLayout: (n) => {
147
- const i = u.find((r) => r.id === n.assetProps.id);
148
- return W(i), {
183
+ itemLayout: (o) => {
184
+ const i = h.find((r) => r.id === o.assetProps.id);
185
+ return m(i), {
149
186
  type: "column",
150
- onClick: () => n.onSelect(i),
187
+ onClick: () => o.onSelect(i),
151
188
  htmlAttrs: {
152
189
  title: i.name
153
190
  },
@@ -165,7 +202,7 @@ const G = (e) => {
165
202
  overflow: "hidden",
166
203
  textOverflow: "ellipsis",
167
204
  whiteSpace: "nowrap",
168
- fontFamily: T(i.customData.font),
205
+ fontFamily: i.customData.font.menuVariant.family,
169
206
  fontSize: "24px",
170
207
  paddingLeft: "8px",
171
208
  paddingRight: "8px"
@@ -175,27 +212,27 @@ const G = (e) => {
175
212
  };
176
213
  }
177
214
  };
178
- }, j = {
215
+ }, N = {
179
216
  googleFontsAssetProvider: {
180
217
  searchBtn: "Search on Google Fonts",
181
218
  modalTitle: "Select Font",
182
219
  providerLabel: "Google Fonts"
183
220
  }
184
221
  }, K = "googleFontsAssetProvider", _ = function(e, t) {
185
- const { i18n: s = {} } = t, o = N(t);
186
- e.runCommand(f.assetProviderAdd, { provider: o }), e.I18n.addMessages({
187
- en: j,
188
- ...s
189
- }), B({
222
+ const { i18n: n = {} } = t, s = j(t);
223
+ e.runCommand(b.assetProviderAdd, { provider: s }), e.I18n.addMessages({
224
+ en: N,
225
+ ...n
226
+ }), U({
190
227
  editor: e,
191
228
  licenseKey: t.licenseKey,
192
- plan: d.startup,
229
+ plan: p.startup,
193
230
  pluginName: K,
194
231
  cleanup: () => {
195
- e.runCommand(f.assetProviderRemove, { id: o.id });
232
+ e.runCommand(b.assetProviderRemove, { id: s.id });
196
233
  }
197
234
  });
198
- }, q = U(_);
235
+ }, H = M(_);
199
236
  export {
200
- q as default
237
+ H as default
201
238
  };
@@ -1 +1 @@
1
- (function(a,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("grapesjs")):typeof define=="function"&&define.amd?define(["grapesjs"],g):(a=typeof globalThis<"u"?globalThis:a||self,a.StudioSdkPlugins_googleFontsAssetProvider=g())})(this,function(){"use strict";var a=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(a||{}),g=(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))(g||{});const b="app.grapesjs.com",y="app-stage.grapesjs.com",P=[b,y,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],A="license:check:start",L="license:check:end",F=()=>typeof window<"u",R=({isDev:e,isStage:t})=>`${e?"":`https://${t?y:b}`}/api`,k=()=>{const e=F()&&window.location.hostname;return!!e&&(P.includes(e)||P.some(t=>e.endsWith(t)))};async function x({path:e,baseApiUrl:t,method:s="GET",headers:o={},params:n,body:r}){const f=`${t||R({isDev:!1,isStage:!1})}${e}`,l={method:s,headers:{"Content-Type":"application/json",...o}};r&&(l.body=JSON.stringify(r));const d=n?new URLSearchParams(n).toString():"",i=d?`?${d}`:"",u=await fetch(`${f}${i}`,l);if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.json()}const v={[a.free]:0,[a.startup]:10,[a.business]:20,[a.enterprise]:30};function $(e){const t=e;return t.init=s=>o=>e(o,s),t}const D=e=>$(e);async function M({editor:e,plan:t,pluginName:s,licenseKey:o,cleanup:n}){let r="",c=!1;const f=k(),l=i=>{console.warn("Cleanup plugin:",s,"Reason:",i),n()},d=(i={})=>{var T;const{error:u,sdkLicense:W}=i,h=(T=i.plan)==null?void 0:T.category;if(!(W||i.license)||u)l(u||"Invalid license");else if(h){const N=v[t],_=v[h];N>_&&l({pluginRequiredPlan:t,licensePlan:h})}};e.on(A,i=>{r=i==null?void 0:i.baseApiUrl,c=!0}),e.on(L,i=>{d(i)}),setTimeout(async()=>{if(!c){if(f)return;if(o){const i=await O({licenseKey:o,pluginName:s,baseApiUrl:r});i&&d(i)}else l("The `licenseKey` option not provided")}},2e3)}async function O(e){const{licenseKey:t,pluginName:s,baseApiUrl:o}=e;try{return(await x({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 p;const U=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)},B=e=>({id:`${e.family}/${e.version}`,src:e.menu,name:e.family,customData:{font:e,needsLoading:!0}}),w=e=>`assetManagerMenu-${e.family}`,E=e=>{if(e.customData.needsLoading){e.customData.needsLoading=!1;const t=e.customData.font,s=new FontFace(w(t),`url(${t.menu})`);document.fonts.add(s),s.load().catch(()=>{})}},G=e=>{const{apiKey:t,searchParams:s}=e,o=(n={})=>{const r="https://www.googleapis.com/webfonts/v1/webfonts",c=U(n);return`${r}?${c}`};return{id:"google-fonts",types:["font"],label:({editor:n})=>n.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var d;if(p)return p;const n={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},r=s==null?void 0:s(),c={...n,...r},l=await(await fetch(o(c))).json();return(d=l.items)!=null&&d.length?(p=l.items.map(B),p):[]},itemLayout:n=>{const r=p.find(c=>c.id===n.assetProps.id);return E(r),{type:"column",onClick:()=>n.onSelect(r),htmlAttrs:{title:r.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:r.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:w(r.customData.font),fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},I={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},j="googleFontsAssetProvider";return D(function(e,t){const{i18n:s={}}=t,o=G(t);e.runCommand(g.assetProviderAdd,{provider:o}),e.I18n.addMessages({en:I,...s}),M({editor:e,licenseKey:t.licenseKey,plan:a.startup,pluginName:j,cleanup:()=>{e.runCommand(g.assetProviderRemove,{id:o.id})}})})});
1
+ (function(l,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("grapesjs")):typeof define=="function"&&define.amd?define(["grapesjs"],p):(l=typeof globalThis<"u"?globalThis:l||self,l.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var l=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(l||{}),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.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))(p||{});const y="app.grapesjs.com",P="app-stage.grapesjs.com",v=[y,P,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",R="license:check:end",x=()=>typeof window<"u",k=({isDev:e,isStage:t})=>`${e?"":`https://${t?P:y}`}/api`,$=()=>{const e=x()&&window.location.hostname;return!!e&&(v.includes(e)||v.some(t=>e.endsWith(t)))};async function F({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:o,body:i}){const d=`${t||k({isDev:!1,isStage:!1})}${e}`,c={method:n,headers:{"Content-Type":"application/json",...s}};i&&(c.body=JSON.stringify(i));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${d}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const w={[l.free]:0,[l.startup]:10,[l.business]:20,[l.enterprise]:30};function D(e){const t=e;return t.init=n=>s=>e(s,n),t}const G=e=>D(e);async function O({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:o}){let i="",a=!1;const d=$(),c=r=>{console.warn("Cleanup plugin:",n,"Reason:",r),o()},u=(r={})=>{var T;const{error:g,sdkLicense:b}=r,f=(T=r.plan)==null?void 0:T.category;if(!(b||r.license)||g)c(g||"Invalid license");else if(f){const N=w[t],_=w[f];N>_&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(L,r=>{i=r==null?void 0:r.baseApiUrl,a=!0}),e.on(R,r=>{u(r)}),setTimeout(async()=>{if(!a){if(d)return;if(s){const r=await M({licenseKey:s,pluginName:n,baseApiUrl:i});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function M(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await F({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const U=e=>{const{family:t,menu:n,axes:s}=e,o=!!s,i=Object.assign({},...e.variants.map(a=>{var r,g;let d,c;if(o){const b=s.find(f=>f.tag==="wght");if(b){const{start:f,end:A}=b;d=`${f} ${A}`}}return d||(d=((r=a.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=a.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[a]:{family:t,source:e.files[a],variant:a,options:{style:c,weight:d}}}}));return{family:t,menuVariant:{family:`assetManagerMenu-${t}`,source:n,variant:"menu"},variants:i}},j=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:U(e),needsLoading:!0}}),m=e=>{if(e.customData.needsLoading){e.customData.needsLoading=!1;const{font:t}=e.customData,{family:n,source:s,options:o}=t.menuVariant,i=new FontFace(n,`url("${s}")`,o);document.fonts.add(i),i.load().catch(()=>{})}};let h;const B=e=>{const t=[];for(const n of Object.keys(e)){let s=e[n];s&&(Array.isArray(s)?t.push(...s.map(o=>[n,o.toString()])):(s=s.toString(),t.push([n,s])))}return new URLSearchParams(t)},E=e=>{const{apiKey:t,searchParams:n}=e,s=(o={})=>{const i="https://www.googleapis.com/webfonts/v1/webfonts",a=B(o);return`${i}?${a}`};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"]},i=n==null?void 0:n(),a={...o,...i},c=await(await fetch(s(a))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(j),h):[]},itemLayout:o=>{const i=h.find(a=>a.id===o.assetProps.id);return m(i),{type:"column",onClick:()=>o.onSelect(i),htmlAttrs:{title:i.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:i.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i.customData.font.menuVariant.family,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},I={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},W="googleFontsAssetProvider";return G(function(e,t){const{i18n:n={}}=t,s=E(t);e.runCommand(p.assetProviderAdd,{provider:s}),e.I18n.addMessages({en:I,...n}),O({editor:e,licenseKey:t.licenseKey,plan:l.startup,pluginName:W,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:s.id})}})})});
@@ -1,7 +1,7 @@
1
1
  import { BaseGoogleFontsAssetProviderOptions, BaseGoogleFontsSearchParams } from './typesSchema';
2
2
  export interface GoogleFontsSearchParams extends BaseGoogleFontsSearchParams {
3
3
  }
4
- export interface WebfontFamily {
4
+ export interface GoogleFontFamily {
5
5
  category?: string | undefined;
6
6
  kind: string;
7
7
  family: string;
@@ -13,10 +13,15 @@ export interface WebfontFamily {
13
13
  [variant: string]: string;
14
14
  };
15
15
  menu: string;
16
+ axes: {
17
+ tag: string;
18
+ start: number;
19
+ end: number;
20
+ }[];
16
21
  }
17
22
  export interface GoogleFontsApiResponse {
18
23
  kind: string;
19
- items: WebfontFamily[];
24
+ items: GoogleFontFamily[];
20
25
  }
21
26
  export interface GoogleFontsAssetProviderOptions extends Omit<BaseGoogleFontsAssetProviderOptions, 'searchParams'> {
22
27
  /**
@@ -0,0 +1,5 @@
1
+ import { Font, FontAssetProps } from '../types';
2
+ import { GoogleFontFamily } from './types';
3
+ export declare const toFont: (googleFont: GoogleFontFamily) => Font;
4
+ export declare const toAssetProps: (googleFont: GoogleFontFamily) => FontAssetProps;
5
+ export declare const loadMenuFont: (assetProps: FontAssetProps) => void;
@@ -1,3 +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">
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.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e))(h||{});const H={ratioDefault:!0,tc:!1,cl:!1,cr:!1,bc:!1},w=`<svg viewBox="0 0 24 24">
2
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;
3
+ </svg>`,x="layout-icon-picker",U="icons-layout-",R="icons-list-layout",_="gs-iconify-picker",A="__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 G({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,C());return}}function P(){return{type:"button",label:"Open Icon Picker",name:"onActive",changeProp:!0,command(e){var o;(o=e.getSelected())==null||o.trigger("active")}}}async function W({collectionIds:e,editor:o,component:t}){const n=await G({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:R,type:"column",grow:!0}]}});const r=await $({collectionId:u,editor:o});r&&E({editor:o,collection:r,handleClick:a,collectionId:u})}function F({editor:e,collection:o}){e.em.set(A,o)}function K(e){return e.em.get(A)}function E(e){const{editor:o}=e,t={id:U,layout:Y(e),header:!1,style:{height:"100%"},placer:{type:"static",layoutId:R}};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:`${_}__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}),F({editor:n,collection:s}),E({editor:n,collection:s,handleClick:a,collectionId:r}))}},{type:"inputField",value:"",placeholder:"Search icons inside collection...",editorEvents:{[`change:${A}`]:({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:`${_}__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 C(){return{id:"toast-error-getCollections",header:"Error",content:"Error fetching collections",variant:O.Error}}function z(){return{...C(),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(){W({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:[P()]},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,P(),...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;