@grapesjs/studio-sdk-plugins 1.0.6 → 1.0.7

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.
@@ -0,0 +1,3 @@
1
+ import { ListPagesComponentOptions } from './types';
2
+ declare const _default: import('../utils').PluginWithInit<ListPagesComponentOptions>;
3
+ export default _default;
@@ -0,0 +1,11 @@
1
+ "use strict";require("react");function v(e,s,n){let t,o,i,a,c;const d=s;function g(){const m=Date.now()-a;m<d&&m>=0?t=setTimeout(g,d-m):(t=null,c=e.apply(i,o),i=o=null)}const p=function(){return i=this,o=arguments,a=Date.now(),t||(t=setTimeout(g,d)),c};return p.clear=function(){t&&(clearTimeout(t),t=null)},p.flush=function(){t&&(c=e.apply(i,o),i=o=null,clearTimeout(t),t=null)},p}const V="page://",r="list-pages",u="list-pages-item",l="list-pages-link",D=e=>e.components().reduce((s,n)=>{var a;const t=n.findFirstType(l),o=(a=t==null?void 0:t.attributes.attributes)==null?void 0:a.href,i=o!=null&&o.startsWith(V)?o.replace(V,""):"";if(i&&t){const c=s[i];c?c.push(t):s[i]=[t]}return s},{}),b="app.grapesjs.com",C="app-stage.grapesjs.com",A=[b,C,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],O="license:check:start",$="license:check:end",_=()=>typeof window<"u",x=({isDev:e,isStage:s})=>`${e?"":`https://${s?C:b}`}/api`,R=()=>{const e=_()&&window.location.hostname;return!!e&&(A.includes(e)||A.some(s=>e.endsWith(s)))},W=()=>(_()&&window.location.hostname)===b;var B={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.7",STUDIO_NPM_PACKAGE_VERSION:"1.0.25"};const K=B.NODE_ENV!=="production";async function U({path:e,method:s="GET",headers:n={},body:t}){const i=`${x({isDev:K,isStage:!W()})}${e}`,a={method:s,headers:{"Content-Type":"application/json",...n}};t&&(a.body=JSON.stringify(t));const c=await fetch(i,a);if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);return c.json()}function G(e){const s=e;return s.init=n=>t=>e(t,n),s}const j=e=>G(e);async function F({editor:e,pluginName:s,licenseKey:n,cleanup:t}){let o=!1;const i=R();e.on(O,()=>{o=!0}),e.on($,({sdkLicense:a})=>{a||t()}),setTimeout(async()=>{if(!o){if(i)return;n&&await J({licenseKey:n,pluginName:s})||t()}},2e3)}async function J({licenseKey:e,pluginName:s}){try{const n=await U({path:`/sdk/${e}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:s})}),{license:t}=n.result||{};return!!t}catch(n){return console.error("Error during SDK license check:",n),!1}}const H="gjs-plg-",X="listPagesComponent",f="data-type-role",Y="page_root",Z=e=>s=>s.is(e),q=e=>(s,n)=>n.is(e),T=e=>s=>{var n;return((n=s.getAttribute)==null?void 0:n.call(s,f))===e},z=function(e,s={}){const{Blocks:n,Components:t,Pages:o}=e,{licenseKey:i,block:a={}}=s,c="List Pages",d="List Pages Item",g="Link",p=`${H}${r}`,m=`${H}${l}`,w='<svg viewBox="0 0 24 24"><path d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z"/></svg>',N='<svg viewBox="0 0 24 24"><path d="M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z" /></svg>';t.addType(r,{block:a&&{label:c,media:w,category:"Extra",select:!0,...s.block},isComponent:T(r),model:{defaults:{tagName:"ul",name:c,[Y]:"",classes:p,attributes:{[f]:r},droppable:Z(u),styles:`
2
+ .${p} {
3
+ list-style: none;
4
+ margin: 0;
5
+ padding: 0;
6
+ }
7
+ `},init(){this.syncPageItems=v(this.syncPageItems.bind(this),0),this.listenTo(this.em,o.events.all,this.syncPageItems),this.syncPageItems()},syncPageItems(){if(e.Components.getSymbolInfo(this).isInstance)return;const y=this.em.Pages.getAll(),k=this.components(),M=D(this);y.forEach((E,S)=>{const I=E.id,P=E.getName(),h=M[I];h?h==null||h.forEach(L=>{L.getInnerHTML()!==P&&L.components(P)}):k.add({type:u,components:[{type:l,attributes:{href:`page://${I}`},components:{type:"textnode",content:P}}]},{at:S})})}}}),t.addType(u,{isComponent:T(u),model:{defaults:{name:d,tagName:"li",icon:N,attributes:{[f]:u},components:{type:l},draggable:q(r)}}}),t.addType(l,{extend:"link",isComponent:T(l),model:{defaults:{removable:!1,copyable:!1,delegate:{move:y=>y.closestType(u)},name:g,classes:m,attributes:{[f]:l},components:{type:"textnode",content:"Item"},styles:`
8
+ .${m} {
9
+ text-decoration: none;
10
+ }
11
+ `}}}),F({editor:e,licenseKey:i,pluginName:X,cleanup:()=>{n.remove(r),t.removeType(r)}})},Q=j(z);module.exports=Q;
@@ -0,0 +1,3 @@
1
+ import { ListPagesComponentOptions } from './types';
2
+ declare const _default: import('../utils').PluginWithInit<ListPagesComponentOptions>;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { ListPagesComponentOptions } from './types';
2
+ declare const _default: import('../utils').PluginWithInit<ListPagesComponentOptions>;
3
+ export default _default;
@@ -0,0 +1,204 @@
1
+ import "react";
2
+ function v(e, s, n) {
3
+ let t, o, i, a, c;
4
+ const d = s;
5
+ function g() {
6
+ const m = Date.now() - a;
7
+ m < d && m >= 0 ? t = setTimeout(g, d - m) : (t = null, c = e.apply(i, o), i = o = null);
8
+ }
9
+ const p = function() {
10
+ return i = this, o = arguments, a = Date.now(), t || (t = setTimeout(g, d)), c;
11
+ };
12
+ return p.clear = function() {
13
+ t && (clearTimeout(t), t = null);
14
+ }, p.flush = function() {
15
+ t && (c = e.apply(i, o), i = o = null, clearTimeout(t), t = null);
16
+ }, p;
17
+ }
18
+ const V = "page://", r = "list-pages", u = "list-pages-item", l = "list-pages-link", D = (e) => e.components().reduce(
19
+ (s, n) => {
20
+ var a;
21
+ const t = n.findFirstType(l), o = (a = t == null ? void 0 : t.attributes.attributes) == null ? void 0 : a.href, i = o != null && o.startsWith(V) ? o.replace(V, "") : "";
22
+ if (i && t) {
23
+ const c = s[i];
24
+ c ? c.push(t) : s[i] = [t];
25
+ }
26
+ return s;
27
+ },
28
+ {}
29
+ ), b = "app.grapesjs.com", C = "app-stage.grapesjs.com", A = [
30
+ b,
31
+ C,
32
+ "localhost",
33
+ "127.0.0.1",
34
+ ".local-credentialless.webcontainer.io",
35
+ // For stackblitz.com demos
36
+ ".local.webcontainer.io",
37
+ // For stackblitz.com demos
38
+ "-sandpack.codesandbox.io"
39
+ // For Sandpack demos
40
+ ], O = "license:check:start", $ = "license:check:end", _ = () => typeof window < "u", x = ({ isDev: e, isStage: s }) => `${e ? "" : `https://${s ? C : b}`}/api`, R = () => {
41
+ const e = _() && window.location.hostname;
42
+ return !!e && (A.includes(e) || A.some((s) => e.endsWith(s)));
43
+ }, W = () => (_() && window.location.hostname) === b;
44
+ var B = { NODE_ENV: "production", NPM_PACKAGE_VERSION: "1.0.7", STUDIO_NPM_PACKAGE_VERSION: "1.0.25" };
45
+ const K = B.NODE_ENV !== "production";
46
+ async function U({
47
+ path: e,
48
+ method: s = "GET",
49
+ headers: n = {},
50
+ body: t
51
+ }) {
52
+ const i = `${x({ isDev: K, isStage: !W() })}${e}`, a = {
53
+ method: s,
54
+ headers: {
55
+ "Content-Type": "application/json",
56
+ ...n
57
+ }
58
+ };
59
+ t && (a.body = JSON.stringify(t));
60
+ const c = await fetch(i, a);
61
+ if (!c.ok)
62
+ throw new Error(`HTTP error! status: ${c.status}`);
63
+ return c.json();
64
+ }
65
+ function G(e) {
66
+ const s = e;
67
+ return s.init = (n) => (t) => e(t, n), s;
68
+ }
69
+ const j = (e) => /* @__PURE__ */ G(e);
70
+ async function F({
71
+ editor: e,
72
+ pluginName: s,
73
+ licenseKey: n,
74
+ cleanup: t
75
+ }) {
76
+ let o = !1;
77
+ const i = R();
78
+ e.on(O, () => {
79
+ o = !0;
80
+ }), e.on($, ({ sdkLicense: a }) => {
81
+ a || t();
82
+ }), setTimeout(async () => {
83
+ if (!o) {
84
+ if (i) return;
85
+ n && await J({ licenseKey: n, pluginName: s }) || t();
86
+ }
87
+ }, 2e3);
88
+ }
89
+ async function J({ licenseKey: e, pluginName: s }) {
90
+ try {
91
+ const n = await U({
92
+ path: `/sdk/${e}`,
93
+ method: "POST",
94
+ body: JSON.stringify({
95
+ d: window.location.hostname,
96
+ pn: s
97
+ })
98
+ }), { license: t } = n.result || {};
99
+ return !!t;
100
+ } catch (n) {
101
+ return console.error("Error during SDK license check:", n), !1;
102
+ }
103
+ }
104
+ const H = "gjs-plg-", X = "listPagesComponent", f = "data-type-role", Y = "page_root", Z = (e) => (s) => s.is(e), q = (e) => (s, n) => n.is(e), T = (e) => (s) => {
105
+ var n;
106
+ return ((n = s.getAttribute) == null ? void 0 : n.call(s, f)) === e;
107
+ }, z = function(e, s = {}) {
108
+ const { Blocks: n, Components: t, Pages: o } = e, { licenseKey: i, block: a = {} } = s, c = "List Pages", d = "List Pages Item", g = "Link", p = `${H}${r}`, m = `${H}${l}`, w = '<svg viewBox="0 0 24 24"><path d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z"/></svg>', N = '<svg viewBox="0 0 24 24"><path d="M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z" /></svg>';
109
+ t.addType(r, {
110
+ block: a && {
111
+ label: c,
112
+ media: w,
113
+ category: "Extra",
114
+ select: !0,
115
+ ...s.block
116
+ },
117
+ isComponent: T(r),
118
+ model: {
119
+ defaults: {
120
+ tagName: "ul",
121
+ name: c,
122
+ [Y]: "",
123
+ classes: p,
124
+ attributes: { [f]: r },
125
+ droppable: Z(u),
126
+ styles: `
127
+ .${p} {
128
+ list-style: none;
129
+ margin: 0;
130
+ padding: 0;
131
+ }
132
+ `
133
+ },
134
+ init() {
135
+ this.syncPageItems = v(this.syncPageItems.bind(this), 0), this.listenTo(this.em, o.events.all, this.syncPageItems), this.syncPageItems();
136
+ },
137
+ syncPageItems() {
138
+ if (e.Components.getSymbolInfo(this).isInstance) return;
139
+ const y = this.em.Pages.getAll(), k = this.components(), M = D(this);
140
+ y.forEach((E, S) => {
141
+ const I = E.id, P = E.getName(), h = M[I];
142
+ h ? h == null || h.forEach((L) => {
143
+ L.getInnerHTML() !== P && L.components(P);
144
+ }) : k.add(
145
+ {
146
+ type: u,
147
+ components: [
148
+ {
149
+ type: l,
150
+ attributes: { href: `page://${I}` },
151
+ components: { type: "textnode", content: P }
152
+ }
153
+ ]
154
+ },
155
+ { at: S }
156
+ );
157
+ });
158
+ }
159
+ }
160
+ }), t.addType(u, {
161
+ isComponent: T(u),
162
+ model: {
163
+ defaults: {
164
+ name: d,
165
+ tagName: "li",
166
+ icon: N,
167
+ attributes: { [f]: u },
168
+ components: { type: l },
169
+ draggable: q(r)
170
+ }
171
+ }
172
+ }), t.addType(l, {
173
+ extend: "link",
174
+ isComponent: T(l),
175
+ model: {
176
+ defaults: {
177
+ removable: !1,
178
+ copyable: !1,
179
+ delegate: {
180
+ move: (y) => y.closestType(u)
181
+ },
182
+ name: g,
183
+ classes: m,
184
+ attributes: { [f]: l },
185
+ components: { type: "textnode", content: "Item" },
186
+ styles: `
187
+ .${m} {
188
+ text-decoration: none;
189
+ }
190
+ `
191
+ }
192
+ }
193
+ }), F({
194
+ editor: e,
195
+ licenseKey: i,
196
+ pluginName: X,
197
+ cleanup: () => {
198
+ n.remove(r), t.removeType(r);
199
+ }
200
+ });
201
+ }, tt = j(z);
202
+ export {
203
+ tt as default
204
+ };
@@ -0,0 +1,11 @@
1
+ (function(g,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("react")):typeof define=="function"&&define.amd?define(["react"],p):(g=typeof globalThis<"u"?globalThis:g||self,g.StudioSdkPlugins_listPagesComponent=p())})(this,function(){"use strict";function g(t,s,n){let e,o,i,a,c;const f=s;function y(){const m=Date.now()-a;m<f&&m>=0?e=setTimeout(y,f-m):(e=null,c=t.apply(i,o),i=o=null)}const d=function(){return i=this,o=arguments,a=Date.now(),e||(e=setTimeout(y,f)),c};return d.clear=function(){e&&(clearTimeout(e),e=null)},d.flush=function(){e&&(c=t.apply(i,o),i=o=null,clearTimeout(e),e=null)},d}const p="page://",r="list-pages",u="list-pages-item",l="list-pages-link",w=t=>t.components().reduce((s,n)=>{var a;const e=n.findFirstType(l),o=(a=e==null?void 0:e.attributes.attributes)==null?void 0:a.href,i=o!=null&&o.startsWith(p)?o.replace(p,""):"";if(i&&e){const c=s[i];c?c.push(e):s[i]=[e]}return s},{}),T="app.grapesjs.com",L="app-stage.grapesjs.com",V=[T,L,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],N="license:check:start",M="license:check:end",A=()=>typeof window<"u",S=({isDev:t,isStage:s})=>`${t?"":`https://${s?L:T}`}/api`,v=()=>{const t=A()&&window.location.hostname;return!!t&&(V.includes(t)||V.some(s=>t.endsWith(s)))},D=()=>(A()&&window.location.hostname)===T;var O={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.7",STUDIO_NPM_PACKAGE_VERSION:"1.0.25"};const x=O.NODE_ENV!=="production";async function $({path:t,method:s="GET",headers:n={},body:e}){const i=`${S({isDev:x,isStage:!D()})}${t}`,a={method:s,headers:{"Content-Type":"application/json",...n}};e&&(a.body=JSON.stringify(e));const c=await fetch(i,a);if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);return c.json()}function R(t){const s=t;return s.init=n=>e=>t(e,n),s}const W=t=>R(t);async function B({editor:t,pluginName:s,licenseKey:n,cleanup:e}){let o=!1;const i=v();t.on(N,()=>{o=!0}),t.on(M,({sdkLicense:a})=>{a||e()}),setTimeout(async()=>{if(!o){if(i)return;n&&await K({licenseKey:n,pluginName:s})||e()}},2e3)}async function K({licenseKey:t,pluginName:s}){try{const n=await $({path:`/sdk/${t}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:s})}),{license:e}=n.result||{};return!!e}catch(n){return console.error("Error during SDK license check:",n),!1}}const C="gjs-plg-",U="listPagesComponent",h="data-type-role",j="page_root",G=t=>s=>s.is(t),F=t=>(s,n)=>n.is(t),b=t=>s=>{var n;return((n=s.getAttribute)==null?void 0:n.call(s,h))===t};return W(function(t,s={}){const{Blocks:n,Components:e,Pages:o}=t,{licenseKey:i,block:a={}}=s,c="List Pages",f="List Pages Item",y="Link",d=`${C}${r}`,m=`${C}${l}`,J='<svg viewBox="0 0 24 24"><path d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z"/></svg>',X='<svg viewBox="0 0 24 24"><path d="M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z" /></svg>';e.addType(r,{block:a&&{label:c,media:J,category:"Extra",select:!0,...s.block},isComponent:b(r),model:{defaults:{tagName:"ul",name:c,[j]:"",classes:d,attributes:{[h]:r},droppable:G(u),styles:`
2
+ .${d} {
3
+ list-style: none;
4
+ margin: 0;
5
+ padding: 0;
6
+ }
7
+ `},init(){this.syncPageItems=g(this.syncPageItems.bind(this),0),this.listenTo(this.em,o.events.all,this.syncPageItems),this.syncPageItems()},syncPageItems(){if(t.Components.getSymbolInfo(this).isInstance)return;const E=this.em.Pages.getAll(),Y=this.components(),Z=w(this);E.forEach((H,q)=>{const _=H.id,I=H.getName(),P=Z[_];P?P==null||P.forEach(k=>{k.getInnerHTML()!==I&&k.components(I)}):Y.add({type:u,components:[{type:l,attributes:{href:`page://${_}`},components:{type:"textnode",content:I}}]},{at:q})})}}}),e.addType(u,{isComponent:b(u),model:{defaults:{name:f,tagName:"li",icon:X,attributes:{[h]:u},components:{type:l},draggable:F(r)}}}),e.addType(l,{extend:"link",isComponent:b(l),model:{defaults:{removable:!1,copyable:!1,delegate:{move:E=>E.closestType(u)},name:y,classes:m,attributes:{[h]:l},components:{type:"textnode",content:"Item"},styles:`
8
+ .${m} {
9
+ text-decoration: none;
10
+ }
11
+ `}}}),B({editor:t,licenseKey:i,pluginName:U,cleanup:()=>{n.remove(r),e.removeType(r)}})})});
@@ -0,0 +1,9 @@
1
+ import { SDKPluginOptions } from '../utils';
2
+ export interface ListPagesComponentOptions extends SDKPluginOptions {
3
+ /**
4
+ * Block options for the component. See https://grapesjs.com/docs/api/block.html#properties for more information.
5
+ * @example
6
+ * { category: 'Extra', label: 'My label' }
7
+ */
8
+ block?: object;
9
+ }
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,6 @@
1
+ import { Component } from 'grapesjs';
2
+ export { default as debounce } from '@studio/editor/src/utils/debounce';
3
+ export declare const typeListPages = "list-pages";
4
+ export declare const typeListPagesItem = "list-pages-item";
5
+ export declare const typeListPagesLink = "list-pages-link";
6
+ export declare const getItemLinksByPageId: (listPagesCmp: Component) => Record<string, Component[] | undefined>;