@grapesjs/studio-sdk-plugins 1.0.19 → 1.0.20-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvasAbsoluteMode/index.cjs.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -0
- package/dist/canvasAbsoluteMode/index.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.es.d.ts +3 -0
- package/dist/canvasAbsoluteMode/index.es.js +222 -0
- package/dist/canvasAbsoluteMode/index.umd.js +1 -0
- package/dist/canvasAbsoluteMode/shared.d.ts +3 -0
- package/dist/canvasAbsoluteMode/types.d.ts +3 -0
- package/dist/canvasAbsoluteMode/typesSchema.d.ts +21 -0
- package/dist/canvasAbsoluteMode/utils.d.ts +61 -0
- package/dist/dataSourceEjs/EjsStrategy.d.ts +15 -0
- package/dist/dataSourceEjs/index.cjs.d.ts +3 -0
- package/dist/dataSourceEjs/index.cjs.js +4 -0
- package/dist/dataSourceEjs/index.d.ts +3 -0
- package/dist/dataSourceEjs/index.es.d.ts +3 -0
- package/dist/dataSourceEjs/index.es.js +208 -0
- package/dist/dataSourceEjs/index.umd.js +4 -0
- package/dist/dataSourceEjs/types.d.ts +3 -0
- package/dist/dataSourceHandlebars/HandlebarsStrategy.d.ts +17 -0
- package/dist/dataSourceHandlebars/index.cjs.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.cjs.js +1 -0
- package/dist/dataSourceHandlebars/index.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.es.d.ts +3 -0
- package/dist/dataSourceHandlebars/index.es.js +202 -0
- package/dist/dataSourceHandlebars/index.umd.js +1 -0
- package/dist/dataSourceHandlebars/types.d.ts +3 -0
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +10 -10
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +11 -11
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.d.ts +3 -0
- package/dist/index.cjs.js +42 -39
- package/dist/index.d.ts +3 -0
- package/dist/index.es.d.ts +3 -0
- package/dist/index.es.js +2920 -2592
- package/dist/index.umd.js +42 -39
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +10 -10
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/prosemirror/index.cjs.js +1 -1
- package/dist/prosemirror/index.es.js +1 -1
- package/dist/prosemirror/index.umd.js +1 -1
- package/dist/rendererReact/index.cjs.d.ts +3 -0
- package/dist/rendererReact/index.cjs.js +1 -0
- package/dist/rendererReact/index.d.ts +3 -0
- package/dist/rendererReact/index.es.d.ts +3 -0
- package/dist/rendererReact/index.es.js +405 -0
- package/dist/rendererReact/index.umd.js +1 -0
- package/dist/rendererReact/rendererCanvas/RenderCanvasComponent.d.ts +9 -0
- package/dist/rendererReact/rendererCanvas/customRenderer.d.ts +2 -0
- package/dist/rendererReact/rendererCanvas/util.d.ts +9 -0
- package/dist/rendererReact/rendererProject/GrapesJSProject.d.ts +3 -0
- package/dist/rendererReact/rendererProject/RenderProjectComponent.d.ts +12 -0
- package/dist/rendererReact/rendererProject/index.cjs.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.cjs.js +10 -0
- package/dist/rendererReact/rendererProject/index.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.es.d.ts +3 -0
- package/dist/rendererReact/rendererProject/index.es.js +446 -0
- package/dist/rendererReact/rendererProject/index.js +10 -0
- package/dist/rendererReact/rendererProject/index.umd.js +10 -0
- package/dist/rendererReact/rendererProject/parser/parser.d.ts +140 -0
- package/dist/rendererReact/rendererProject/types.d.ts +8 -0
- package/dist/rendererReact/rendererProject/util.d.ts +16 -0
- package/dist/rendererReact/shared/types.d.ts +49 -0
- package/dist/rendererReact/shared/util.d.ts +2 -0
- package/dist/rendererReact/types.d.ts +22 -0
- package/dist/rendererReact/typesSchema.d.ts +77 -0
- package/dist/rteTinyMce/index.cjs.js +2 -2
- package/dist/rteTinyMce/index.es.js +18 -18
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +19 -19
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +21 -21
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("react/jsx-runtime"),h=require("react"),D=require("react-dom/client"),A="app.grapesjs.com",N="app-stage.grapesjs.com",x=[A,N,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],L="license:check:start",O="license:check:end",U=()=>typeof window<"u",j=({isDev:e,isStage:t})=>`${e?"":`https://${t?N:A}`}/api`,W=()=>{const e=U()&&window.location.hostname;return!!e&&(x.includes(e)||x.some(t=>e.endsWith(t)))};async function P({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:i}){const c=`${t||j({isDev:!1,isStage:!1})}${e}`,l={method:n,headers:{"Content-Type":"application/json",...s}};i&&(l.body=JSON.stringify(i));const u=r?new URLSearchParams(r).toString():"",a=u?`?${u}`:"",d=await fetch(`${c}${a}`,l);if(!d.ok)throw new Error(`HTTP error! status: ${d.status}`);return d.json()}var g=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(g||{});const R={[g.free]:0,[g.startup]:10,[g.business]:20,[g.enterprise]:30};function I(e){const t=e;return t.init=n=>s=>e(s,n),t}const K=e=>I(e);async function $({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let i="",o=!1;const c=W(),l=a=>{console.warn("Cleanup plugin:",n,"Reason:",a),r()},u=(a={})=>{var y;const{error:d,sdkLicense:p}=a,f=(y=a.plan)==null?void 0:y.category;if(!(p||a.license)||d)l(d||"Invalid license");else if(f){const w=R[t],v=R[f];w>v&&l({pluginRequiredPlan:t,licensePlan:f})}};e.on(L,a=>{i=a==null?void 0:a.baseApiUrl,o=!0}),e.on(O,a=>{u(a)}),setTimeout(async()=>{if(!o){if(c)return;if(s){const a=await V({licenseKey:s,pluginName:n,baseApiUrl:i});a&&u(a)}else l("The `licenseKey` option not provided")}},2e3)}async function V(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await P({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function E(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const i=s.includes("-")?s.replace(/-([a-z])/g,o=>o[1].toUpperCase()):s;t[i]=r,n=!0}}return n?t:void 0}function M(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),i=n.substring(s+1).trim();if(r&&i){const o=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[o]=i}}}),Object.keys(t).length>0?t:void 0}function q(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return E(e);if(typeof e=="string"){let t=M(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=E(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const i=s.replace(/-([a-z])/g,o=>o[1].toUpperCase());t[i]=r}}}),Object.keys(t).length>0?t:void 0}}}function z(e){return S[e]?S[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function F(e){var s;const t={},n=((s=e.xmlns)==null?void 0:s.includes("svg"))||e.viewBox!==void 0||e.d!==void 0;for(const[r,i]of Object.entries(e))if(r==="style")t.style=q(i);else if(r.startsWith("data-"))t[r]=i;else{const o=z(r);n||J.has(o)||o.startsWith("svg")?t[o]=i:!B.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[`data-${r.toLowerCase()}`]=i:t[o]=i}return t}const B=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),J=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),S={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"};function G(e,t,n){const[s,r]=h.useState();return{connectDom:h.useCallback(o=>{if(!o)return;const c=Q(e,t,o,n);r(c)},[s]),view:s}}function H(e){const[t,n]=h.useState(0);return h.useEffect(()=>{if(!e)return()=>{};const s=()=>n(c=>c+1),{em:r}=e,o=`${r.Components.events.update}:components`;return e.on(o,s),()=>e.off(o,s)},[e]),t}function Q(e,t,n,s){var c;const{em:r,Components:i}=e;let o=t.getView();if((o==null?void 0:o.el)===n)return o;if(!o){const{ComponentView:l}=i,{draggableComponents:u}=i.config,a=t.attributes.type||"default",d=((c=i.getType(a))==null?void 0:c.view)||l,p={draggableComponents:u,frameView:s,em:r},f=d.extend({initComponents(){},_createElement(){return n},render(){return this._ensureElement(),this._setData(),this.renderAttributes(),this.postRender(),this}});o=new f({el:n,config:p,model:t})}return o.el=n,o.render(),o}function X(e,t){const{Components:n}=e,s=r=>{const{id:i,model:o}=r;n.addType(i,{model:{toJSON(...c){const l=o.prototype.toJSON.apply(this,c);return l.tagName=this.tagName,l}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,i])=>{var o;n.addType(r,{isComponent:c=>(c==null?void 0:c.tagName)===r,model:{defaults:{type:r,traits:i.props?i.props():[],...((o=i.model)==null?void 0:o.defaults)||{}}}})})}function T(e){var b;const{component:t,config:n,editor:s,frameView:r,onMount:i,tagName:o}=e,{connectDom:c,view:l}=G(s,t,r),u=H(t);h.useEffect(()=>{if(!l||!i)return;const C=setTimeout(()=>i(l));return()=>clearTimeout(C)},[l]);const a=t.get("type")||"default",d=t.content,p=(b=n.components)==null?void 0:b[a],f=(p==null?void 0:p.component)||o||t.tagName||"div",k=t.components(),y=k.length?k.map(C=>m.jsx(T,{component:C,config:n,editor:s,frameView:r},C.cid)):d,w=F(t.getAttributes()),v=p==null?void 0:p.editorRender;if(v)return m.jsx(v,{props:w,editor:s,component:t,connectDom:c,children:y});if(p!=null&&p.component)return m.jsx("gjs-wrapper",{ref:c,children:m.jsx(f,{...w,children:y})});if(t.isInstanceOf("textnode"))return d;const _=t.isInstanceOf("text")?u:void 0;return h.createElement(f,{...w,ref:c,key:_},t.get("void")?null:y)}const Y=e=>{var i;const{frame:t,window:n,onMount:s}=e,{root:r}=t;try{(i=n.__reactRoot)==null||i.unmount(),n.__reactRoot=void 0;const o=D.createRoot(n.document.body);o.render(m.jsx(Z,{...e,component:r,onMount:s})),n.__reactRoot=o}catch(o){console.error("Error setting up React renderer",o)}return r.getView()};function Z(e){const{editor:t,component:n,window:s,frameView:r,config:i,onMount:o}=e,c=s.document,l=i.wrapper||h.Fragment,u={editorProps:{doc:c,editor:t,frameView:r}},a=i.wrapper?u:{};return m.jsx(l,{...a,children:m.jsx(T,{tagName:"div",component:n,config:i,editor:t,frameView:r,onMount:o})})}const ee="rendererReact",te=function(e,t={}){e.Canvas.config.customRenderer=n=>Y({...n,config:t}),X(e,t),$({editor:e,licenseKey:t.licenseKey,plan:g.startup,pluginName:ee,cleanup:()=>{e.Canvas.config.customRenderer=void 0}})},ne=K(te);module.exports=ne;
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { useState as A, useCallback as L, useEffect as x, createElement as O, Fragment as U } from "react";
|
|
3
|
+
import { createRoot as W } from "react-dom/client";
|
|
4
|
+
const N = "app.grapesjs.com", T = "app-stage.grapesjs.com", b = [
|
|
5
|
+
N,
|
|
6
|
+
T,
|
|
7
|
+
"localhost",
|
|
8
|
+
"127.0.0.1",
|
|
9
|
+
".local-credentialless.webcontainer.io",
|
|
10
|
+
// For stackblitz.com demos
|
|
11
|
+
".local.webcontainer.io",
|
|
12
|
+
// For stackblitz.com demos
|
|
13
|
+
"-sandpack.codesandbox.io"
|
|
14
|
+
// For Sandpack demos
|
|
15
|
+
], P = "license:check:start", I = "license:check:end", K = () => typeof window < "u", j = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? T : N}`}/api`, $ = () => {
|
|
16
|
+
const e = K() && window.location.hostname;
|
|
17
|
+
return !!e && (b.includes(e) || b.some((t) => e.endsWith(t)));
|
|
18
|
+
};
|
|
19
|
+
async function V({
|
|
20
|
+
path: e,
|
|
21
|
+
baseApiUrl: t,
|
|
22
|
+
method: n = "GET",
|
|
23
|
+
headers: s = {},
|
|
24
|
+
params: r,
|
|
25
|
+
body: i
|
|
26
|
+
}) {
|
|
27
|
+
const c = `${t || j({ isDev: !1, isStage: !1 })}${e}`, l = {
|
|
28
|
+
method: n,
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
...s
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
i && (l.body = JSON.stringify(i));
|
|
35
|
+
const u = r ? new URLSearchParams(r).toString() : "", a = u ? `?${u}` : "", d = await fetch(`${c}${a}`, l);
|
|
36
|
+
if (!d.ok)
|
|
37
|
+
throw new Error(`HTTP error! status: ${d.status}`);
|
|
38
|
+
return d.json();
|
|
39
|
+
}
|
|
40
|
+
var y = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(y || {});
|
|
41
|
+
const R = {
|
|
42
|
+
[y.free]: 0,
|
|
43
|
+
[y.startup]: 10,
|
|
44
|
+
[y.business]: 20,
|
|
45
|
+
[y.enterprise]: 30
|
|
46
|
+
};
|
|
47
|
+
function M(e) {
|
|
48
|
+
const t = e;
|
|
49
|
+
return t.init = (n) => (s) => e(s, n), t;
|
|
50
|
+
}
|
|
51
|
+
const z = (e) => /* @__PURE__ */ M(e);
|
|
52
|
+
async function F({
|
|
53
|
+
editor: e,
|
|
54
|
+
plan: t,
|
|
55
|
+
pluginName: n,
|
|
56
|
+
licenseKey: s,
|
|
57
|
+
cleanup: r
|
|
58
|
+
}) {
|
|
59
|
+
let i = "", o = !1;
|
|
60
|
+
const c = $(), l = (a) => {
|
|
61
|
+
console.warn("Cleanup plugin:", n, "Reason:", a), r();
|
|
62
|
+
}, u = (a = {}) => {
|
|
63
|
+
var h;
|
|
64
|
+
const { error: d, sdkLicense: p } = a, f = (h = a.plan) == null ? void 0 : h.category;
|
|
65
|
+
if (!(p || a.license) || d)
|
|
66
|
+
l(d || "Invalid license");
|
|
67
|
+
else if (f) {
|
|
68
|
+
const g = R[t], w = R[f];
|
|
69
|
+
g > w && l({ pluginRequiredPlan: t, licensePlan: f });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
e.on(P, (a) => {
|
|
73
|
+
i = a == null ? void 0 : a.baseApiUrl, o = !0;
|
|
74
|
+
}), e.on(I, (a) => {
|
|
75
|
+
u(a);
|
|
76
|
+
}), setTimeout(async () => {
|
|
77
|
+
if (!o) {
|
|
78
|
+
if (c) return;
|
|
79
|
+
if (s) {
|
|
80
|
+
const a = await B({ licenseKey: s, pluginName: n, baseApiUrl: i });
|
|
81
|
+
a && u(a);
|
|
82
|
+
} else
|
|
83
|
+
l("The `licenseKey` option not provided");
|
|
84
|
+
}
|
|
85
|
+
}, 2e3);
|
|
86
|
+
}
|
|
87
|
+
async function B(e) {
|
|
88
|
+
const { licenseKey: t, pluginName: n, baseApiUrl: s } = e;
|
|
89
|
+
try {
|
|
90
|
+
return (await V({
|
|
91
|
+
baseApiUrl: s,
|
|
92
|
+
path: `/sdk/${t || "na"}`,
|
|
93
|
+
method: "POST",
|
|
94
|
+
params: {
|
|
95
|
+
d: window.location.hostname,
|
|
96
|
+
pn: n
|
|
97
|
+
}
|
|
98
|
+
})).result || {};
|
|
99
|
+
} catch (r) {
|
|
100
|
+
return console.error("Error during SDK license check:", r), !1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function E(e) {
|
|
104
|
+
const t = {};
|
|
105
|
+
let n = !1;
|
|
106
|
+
for (const s in e)
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(e, s)) {
|
|
108
|
+
const r = e[s];
|
|
109
|
+
if (typeof r == "string" || typeof r == "number") {
|
|
110
|
+
const i = s.includes("-") ? s.replace(/-([a-z])/g, (o) => o[1].toUpperCase()) : s;
|
|
111
|
+
t[i] = r, n = !0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return n ? t : void 0;
|
|
115
|
+
}
|
|
116
|
+
function J(e) {
|
|
117
|
+
const t = {};
|
|
118
|
+
return e.split(";").forEach((n) => {
|
|
119
|
+
if (!n.trim()) return;
|
|
120
|
+
const s = n.indexOf(":");
|
|
121
|
+
if (s > 0) {
|
|
122
|
+
const r = n.substring(0, s).trim(), i = n.substring(s + 1).trim();
|
|
123
|
+
if (r && i) {
|
|
124
|
+
const o = r.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
|
|
125
|
+
t[o] = i;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}), Object.keys(t).length > 0 ? t : void 0;
|
|
129
|
+
}
|
|
130
|
+
function q(e) {
|
|
131
|
+
if (e) {
|
|
132
|
+
if (typeof e == "object" && !Array.isArray(e))
|
|
133
|
+
return E(e);
|
|
134
|
+
if (typeof e == "string") {
|
|
135
|
+
let t = J(e);
|
|
136
|
+
if (!t)
|
|
137
|
+
try {
|
|
138
|
+
const n = JSON.parse(e);
|
|
139
|
+
typeof n == "object" && n !== null && !Array.isArray(n) && (t = E(n));
|
|
140
|
+
} catch (n) {
|
|
141
|
+
console.error("Failed to parse style string as JSON", n);
|
|
142
|
+
}
|
|
143
|
+
return t;
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(e)) {
|
|
146
|
+
const t = {};
|
|
147
|
+
return e.forEach((n) => {
|
|
148
|
+
if (typeof n == "object" && n !== null) {
|
|
149
|
+
const s = n.name || n.property, r = n.value;
|
|
150
|
+
if (typeof s == "string" && s && r !== void 0 && r !== "") {
|
|
151
|
+
const i = s.replace(/-([a-z])/g, (o) => o[1].toUpperCase());
|
|
152
|
+
t[i] = r;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}), Object.keys(t).length > 0 ? t : void 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function G(e) {
|
|
160
|
+
return S[e] ? S[e] : e.includes("-") ? e.replace(/-([a-z])/g, (t, n) => n.toUpperCase()) : e;
|
|
161
|
+
}
|
|
162
|
+
function H(e) {
|
|
163
|
+
var s;
|
|
164
|
+
const t = {}, n = ((s = e.xmlns) == null ? void 0 : s.includes("svg")) || e.viewBox !== void 0 || e.d !== void 0;
|
|
165
|
+
for (const [r, i] of Object.entries(e))
|
|
166
|
+
if (r === "style")
|
|
167
|
+
t.style = q(i);
|
|
168
|
+
else if (r.startsWith("data-"))
|
|
169
|
+
t[r] = i;
|
|
170
|
+
else {
|
|
171
|
+
const o = G(r);
|
|
172
|
+
n || X.has(o) || o.startsWith("svg") ? t[o] = i : !Q.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[`data-${r.toLowerCase()}`] = i : t[o] = i;
|
|
173
|
+
}
|
|
174
|
+
return t;
|
|
175
|
+
}
|
|
176
|
+
const Q = /* @__PURE__ */ new Set([
|
|
177
|
+
"className",
|
|
178
|
+
"id",
|
|
179
|
+
"style",
|
|
180
|
+
"href",
|
|
181
|
+
"src",
|
|
182
|
+
"alt",
|
|
183
|
+
"title",
|
|
184
|
+
"target",
|
|
185
|
+
"rel",
|
|
186
|
+
"type",
|
|
187
|
+
"name",
|
|
188
|
+
"value",
|
|
189
|
+
"placeholder",
|
|
190
|
+
"onClick",
|
|
191
|
+
"onChange",
|
|
192
|
+
"onSubmit",
|
|
193
|
+
"onBlur",
|
|
194
|
+
"onFocus",
|
|
195
|
+
"disabled",
|
|
196
|
+
"readOnly",
|
|
197
|
+
"checked",
|
|
198
|
+
"selected",
|
|
199
|
+
"multiple",
|
|
200
|
+
"width",
|
|
201
|
+
"height",
|
|
202
|
+
"maxLength",
|
|
203
|
+
"min",
|
|
204
|
+
"max",
|
|
205
|
+
"step",
|
|
206
|
+
"rows",
|
|
207
|
+
"cols",
|
|
208
|
+
"autoComplete",
|
|
209
|
+
"autoFocus",
|
|
210
|
+
"required",
|
|
211
|
+
"spellCheck",
|
|
212
|
+
"tabIndex",
|
|
213
|
+
"aria-label",
|
|
214
|
+
"aria-labelledby",
|
|
215
|
+
"aria-describedby",
|
|
216
|
+
"role"
|
|
217
|
+
]), X = /* @__PURE__ */ new Set([
|
|
218
|
+
"x",
|
|
219
|
+
"y",
|
|
220
|
+
"d",
|
|
221
|
+
"cx",
|
|
222
|
+
"cy",
|
|
223
|
+
"r",
|
|
224
|
+
"rx",
|
|
225
|
+
"ry",
|
|
226
|
+
"x1",
|
|
227
|
+
"x2",
|
|
228
|
+
"y1",
|
|
229
|
+
"y2",
|
|
230
|
+
"points",
|
|
231
|
+
"fill",
|
|
232
|
+
"stroke",
|
|
233
|
+
"strokeWidth",
|
|
234
|
+
"strokeLinecap",
|
|
235
|
+
"strokeLinejoin",
|
|
236
|
+
"strokeDasharray",
|
|
237
|
+
"strokeOpacity",
|
|
238
|
+
"fillOpacity",
|
|
239
|
+
"fillRule",
|
|
240
|
+
"clipRule",
|
|
241
|
+
"transform",
|
|
242
|
+
"viewBox",
|
|
243
|
+
"preserveAspectRatio",
|
|
244
|
+
"pathLength",
|
|
245
|
+
"vectorEffect",
|
|
246
|
+
"dominantBaseline",
|
|
247
|
+
"alignmentBaseline",
|
|
248
|
+
"textAnchor",
|
|
249
|
+
"fontFamily",
|
|
250
|
+
"fontSize",
|
|
251
|
+
"fontStyle",
|
|
252
|
+
"fontWeight",
|
|
253
|
+
"textDecoration",
|
|
254
|
+
"baselineShift",
|
|
255
|
+
"opacity",
|
|
256
|
+
"mask",
|
|
257
|
+
"clipPath",
|
|
258
|
+
"overflow",
|
|
259
|
+
"pointerEvents"
|
|
260
|
+
]), S = {
|
|
261
|
+
class: "className",
|
|
262
|
+
for: "htmlFor",
|
|
263
|
+
"http-equiv": "httpEquiv",
|
|
264
|
+
"accept-charset": "acceptCharset",
|
|
265
|
+
"stroke-width": "strokeWidth",
|
|
266
|
+
"stroke-linecap": "strokeLinecap",
|
|
267
|
+
"stroke-linejoin": "strokeLinejoin",
|
|
268
|
+
"fill-rule": "fillRule",
|
|
269
|
+
"clip-rule": "clipRule",
|
|
270
|
+
"stroke-miterlimit": "strokeMiterlimit",
|
|
271
|
+
"stroke-dasharray": "strokeDasharray",
|
|
272
|
+
"stroke-opacity": "strokeOpacity",
|
|
273
|
+
"fill-opacity": "fillOpacity",
|
|
274
|
+
"font-family": "fontFamily",
|
|
275
|
+
"font-size": "fontSize",
|
|
276
|
+
"text-anchor": "textAnchor"
|
|
277
|
+
};
|
|
278
|
+
function Y(e, t, n) {
|
|
279
|
+
const [s, r] = A();
|
|
280
|
+
return {
|
|
281
|
+
connectDom: L(
|
|
282
|
+
(o) => {
|
|
283
|
+
if (!o) return;
|
|
284
|
+
const c = ee(e, t, o, n);
|
|
285
|
+
r(c);
|
|
286
|
+
},
|
|
287
|
+
[s]
|
|
288
|
+
),
|
|
289
|
+
view: s
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function Z(e) {
|
|
293
|
+
const [t, n] = A(0);
|
|
294
|
+
return x(() => {
|
|
295
|
+
if (!e) return () => {
|
|
296
|
+
};
|
|
297
|
+
const s = () => n((c) => c + 1), { em: r } = e, o = `${r.Components.events.update}:components`;
|
|
298
|
+
return e.on(o, s), () => e.off(o, s);
|
|
299
|
+
}, [e]), t;
|
|
300
|
+
}
|
|
301
|
+
function ee(e, t, n, s) {
|
|
302
|
+
var c;
|
|
303
|
+
const { em: r, Components: i } = e;
|
|
304
|
+
let o = t.getView();
|
|
305
|
+
if ((o == null ? void 0 : o.el) === n)
|
|
306
|
+
return o;
|
|
307
|
+
if (!o) {
|
|
308
|
+
const { ComponentView: l } = i, { draggableComponents: u } = i.config, a = t.attributes.type || "default", d = ((c = i.getType(a)) == null ? void 0 : c.view) || l, p = { draggableComponents: u, frameView: s, em: r }, f = d.extend({
|
|
309
|
+
initComponents() {
|
|
310
|
+
},
|
|
311
|
+
_createElement() {
|
|
312
|
+
return n;
|
|
313
|
+
},
|
|
314
|
+
render() {
|
|
315
|
+
return this._ensureElement(), this._setData(), this.renderAttributes(), this.postRender(), this;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
o = new f({ el: n, config: p, model: t });
|
|
319
|
+
}
|
|
320
|
+
return o.el = n, o.render(), o;
|
|
321
|
+
}
|
|
322
|
+
function te(e, t) {
|
|
323
|
+
const { Components: n } = e, s = (r) => {
|
|
324
|
+
const { id: i, model: o } = r;
|
|
325
|
+
n.addType(i, {
|
|
326
|
+
model: {
|
|
327
|
+
toJSON(...c) {
|
|
328
|
+
const l = o.prototype.toJSON.apply(this, c);
|
|
329
|
+
return l.tagName = this.tagName, l;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
n.getTypes().forEach(s), e.on("component:type:add", s), Object.entries(t.components || {}).forEach(([r, i]) => {
|
|
335
|
+
var o;
|
|
336
|
+
n.addType(r, {
|
|
337
|
+
isComponent: (c) => (c == null ? void 0 : c.tagName) === r,
|
|
338
|
+
model: {
|
|
339
|
+
defaults: {
|
|
340
|
+
type: r,
|
|
341
|
+
traits: i.props ? i.props() : [],
|
|
342
|
+
...((o = i.model) == null ? void 0 : o.defaults) || {}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function _(e) {
|
|
349
|
+
var k;
|
|
350
|
+
const { component: t, config: n, editor: s, frameView: r, onMount: i, tagName: o } = e, { connectDom: c, view: l } = Y(s, t, r), u = Z(t);
|
|
351
|
+
x(() => {
|
|
352
|
+
if (!l || !i) return;
|
|
353
|
+
const v = setTimeout(() => i(l));
|
|
354
|
+
return () => clearTimeout(v);
|
|
355
|
+
}, [l]);
|
|
356
|
+
const a = t.get("type") || "default", d = t.content, p = (k = n.components) == null ? void 0 : k[a], f = (p == null ? void 0 : p.component) || o || t.tagName || "div", C = t.components(), h = C.length ? C.map((v) => /* @__PURE__ */ m(_, { component: v, config: n, editor: s, frameView: r }, v.cid)) : d, g = H(t.getAttributes()), w = p == null ? void 0 : p.editorRender;
|
|
357
|
+
if (w)
|
|
358
|
+
return /* @__PURE__ */ m(w, { props: g, editor: s, component: t, connectDom: c, children: h });
|
|
359
|
+
if (p != null && p.component)
|
|
360
|
+
return /* @__PURE__ */ m("gjs-wrapper", { ref: c, children: /* @__PURE__ */ m(f, { ...g, children: h }) });
|
|
361
|
+
if (t.isInstanceOf("textnode"))
|
|
362
|
+
return d;
|
|
363
|
+
const D = t.isInstanceOf("text") ? u : void 0;
|
|
364
|
+
return /* @__PURE__ */ O(f, { ...g, ref: c, key: D }, t.get("void") ? null : h);
|
|
365
|
+
}
|
|
366
|
+
const ne = (e) => {
|
|
367
|
+
var i;
|
|
368
|
+
const { frame: t, window: n, onMount: s } = e, { root: r } = t;
|
|
369
|
+
try {
|
|
370
|
+
(i = n.__reactRoot) == null || i.unmount(), n.__reactRoot = void 0;
|
|
371
|
+
const o = W(n.document.body);
|
|
372
|
+
o.render(/* @__PURE__ */ m(oe, { ...e, component: r, onMount: s })), n.__reactRoot = o;
|
|
373
|
+
} catch (o) {
|
|
374
|
+
console.error("Error setting up React renderer", o);
|
|
375
|
+
}
|
|
376
|
+
return r.getView();
|
|
377
|
+
};
|
|
378
|
+
function oe(e) {
|
|
379
|
+
const { editor: t, component: n, window: s, frameView: r, config: i, onMount: o } = e, c = s.document, l = i.wrapper || U, u = { editorProps: { doc: c, editor: t, frameView: r } }, a = i.wrapper ? u : {};
|
|
380
|
+
return /* @__PURE__ */ m(l, { ...a, children: /* @__PURE__ */ m(
|
|
381
|
+
_,
|
|
382
|
+
{
|
|
383
|
+
tagName: "div",
|
|
384
|
+
component: n,
|
|
385
|
+
config: i,
|
|
386
|
+
editor: t,
|
|
387
|
+
frameView: r,
|
|
388
|
+
onMount: o
|
|
389
|
+
}
|
|
390
|
+
) });
|
|
391
|
+
}
|
|
392
|
+
const se = "rendererReact", re = function(e, t = {}) {
|
|
393
|
+
e.Canvas.config.customRenderer = (n) => ne({ ...n, config: t }), te(e, t), F({
|
|
394
|
+
editor: e,
|
|
395
|
+
licenseKey: t.licenseKey,
|
|
396
|
+
plan: y.startup,
|
|
397
|
+
pluginName: se,
|
|
398
|
+
cleanup: () => {
|
|
399
|
+
e.Canvas.config.customRenderer = void 0;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}, le = z(re);
|
|
403
|
+
export {
|
|
404
|
+
le as default
|
|
405
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(p,d){typeof exports=="object"&&typeof module<"u"?module.exports=d(require("react/jsx-runtime"),require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["react/jsx-runtime","react","react-dom/client"],d):(p=typeof globalThis<"u"?globalThis:p||self,p.StudioSdkPlugins_rendererReact=d(p.jsxRuntime,p.React,p.ReactDOMClient))})(this,function(p,d,_){"use strict";const b="app.grapesjs.com",S="app-stage.grapesjs.com",E=[b,S,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],D="license:check:start",O="license:check:end",L=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?S:b}`}/api`,P=()=>{const e=L()&&window.location.hostname;return!!e&&(E.includes(e)||E.some(t=>e.endsWith(t)))};async function W({path:e,baseApiUrl:t,method:n="GET",headers:s={},params:r,body:i}){const c=`${t||U({isDev:!1,isStage:!1})}${e}`,l={method:n,headers:{"Content-Type":"application/json",...s}};i&&(l.body=JSON.stringify(i));const f=r?new URLSearchParams(r).toString():"",a=f?`?${f}`:"",m=await fetch(`${c}${a}`,l);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);return m.json()}var y=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(y||{});const x={[y.free]:0,[y.startup]:10,[y.business]:20,[y.enterprise]:30};function j(e){const t=e;return t.init=n=>s=>e(s,n),t}const I=e=>j(e);async function K({editor:e,plan:t,pluginName:n,licenseKey:s,cleanup:r}){let i="",o=!1;const c=P(),l=a=>{console.warn("Cleanup plugin:",n,"Reason:",a),r()},f=(a={})=>{var g;const{error:m,sdkLicense:u}=a,h=(g=a.plan)==null?void 0:g.category;if(!(u||a.license)||m)l(m||"Invalid license");else if(h){const w=x[t],v=x[h];w>v&&l({pluginRequiredPlan:t,licensePlan:h})}};e.on(D,a=>{i=a==null?void 0:a.baseApiUrl,o=!0}),e.on(O,a=>{f(a)}),setTimeout(async()=>{if(!o){if(c)return;if(s){const a=await $({licenseKey:s,pluginName:n,baseApiUrl:i});a&&f(a)}else l("The `licenseKey` option not provided")}},2e3)}async function $(e){const{licenseKey:t,pluginName:n,baseApiUrl:s}=e;try{return(await W({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:n}})).result||{}}catch(r){return console.error("Error during SDK license check:",r),!1}}function R(e){const t={};let n=!1;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const r=e[s];if(typeof r=="string"||typeof r=="number"){const i=s.includes("-")?s.replace(/-([a-z])/g,o=>o[1].toUpperCase()):s;t[i]=r,n=!0}}return n?t:void 0}function M(e){const t={};return e.split(";").forEach(n=>{if(!n.trim())return;const s=n.indexOf(":");if(s>0){const r=n.substring(0,s).trim(),i=n.substring(s+1).trim();if(r&&i){const o=r.replace(/-([a-z])/g,c=>c[1].toUpperCase());t[o]=i}}}),Object.keys(t).length>0?t:void 0}function V(e){if(e){if(typeof e=="object"&&!Array.isArray(e))return R(e);if(typeof e=="string"){let t=M(e);if(!t)try{const n=JSON.parse(e);typeof n=="object"&&n!==null&&!Array.isArray(n)&&(t=R(n))}catch(n){console.error("Failed to parse style string as JSON",n)}return t}if(Array.isArray(e)){const t={};return e.forEach(n=>{if(typeof n=="object"&&n!==null){const s=n.name||n.property,r=n.value;if(typeof s=="string"&&s&&r!==void 0&&r!==""){const i=s.replace(/-([a-z])/g,o=>o[1].toUpperCase());t[i]=r}}}),Object.keys(t).length>0?t:void 0}}}function q(e){return A[e]?A[e]:e.includes("-")?e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase()):e}function z(e){var s;const t={},n=((s=e.xmlns)==null?void 0:s.includes("svg"))||e.viewBox!==void 0||e.d!==void 0;for(const[r,i]of Object.entries(e))if(r==="style")t.style=V(i);else if(r.startsWith("data-"))t[r]=i;else{const o=q(r);n||B.has(o)||o.startsWith("svg")?t[o]=i:!F.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[`data-${r.toLowerCase()}`]=i:t[o]=i}return t}const F=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),B=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),A={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"};function J(e,t,n){const[s,r]=d.useState();return{connectDom:d.useCallback(o=>{if(!o)return;const c=H(e,t,o,n);r(c)},[s]),view:s}}function G(e){const[t,n]=d.useState(0);return d.useEffect(()=>{if(!e)return()=>{};const s=()=>n(c=>c+1),{em:r}=e,o=`${r.Components.events.update}:components`;return e.on(o,s),()=>e.off(o,s)},[e]),t}function H(e,t,n,s){var c;const{em:r,Components:i}=e;let o=t.getView();if((o==null?void 0:o.el)===n)return o;if(!o){const{ComponentView:l}=i,{draggableComponents:f}=i.config,a=t.attributes.type||"default",m=((c=i.getType(a))==null?void 0:c.view)||l,u={draggableComponents:f,frameView:s,em:r},h=m.extend({initComponents(){},_createElement(){return n},render(){return this._ensureElement(),this._setData(),this.renderAttributes(),this.postRender(),this}});o=new h({el:n,config:u,model:t})}return o.el=n,o.render(),o}function Q(e,t){const{Components:n}=e,s=r=>{const{id:i,model:o}=r;n.addType(i,{model:{toJSON(...c){const l=o.prototype.toJSON.apply(this,c);return l.tagName=this.tagName,l}}})};n.getTypes().forEach(s),e.on("component:type:add",s),Object.entries(t.components||{}).forEach(([r,i])=>{var o;n.addType(r,{isComponent:c=>(c==null?void 0:c.tagName)===r,model:{defaults:{type:r,traits:i.props?i.props():[],...((o=i.model)==null?void 0:o.defaults)||{}}}})})}function N(e){var T;const{component:t,config:n,editor:s,frameView:r,onMount:i,tagName:o}=e,{connectDom:c,view:l}=J(s,t,r),f=G(t);d.useEffect(()=>{if(!l||!i)return;const C=setTimeout(()=>i(l));return()=>clearTimeout(C)},[l]);const a=t.get("type")||"default",m=t.content,u=(T=n.components)==null?void 0:T[a],h=(u==null?void 0:u.component)||o||t.tagName||"div",k=t.components(),g=k.length?k.map(C=>p.jsx(N,{component:C,config:n,editor:s,frameView:r},C.cid)):m,w=z(t.getAttributes()),v=u==null?void 0:u.editorRender;if(v)return p.jsx(v,{props:w,editor:s,component:t,connectDom:c,children:g});if(u!=null&&u.component)return p.jsx("gjs-wrapper",{ref:c,children:p.jsx(h,{...w,children:g})});if(t.isInstanceOf("textnode"))return m;const ee=t.isInstanceOf("text")?f:void 0;return d.createElement(h,{...w,ref:c,key:ee},t.get("void")?null:g)}const X=e=>{var i;const{frame:t,window:n,onMount:s}=e,{root:r}=t;try{(i=n.__reactRoot)==null||i.unmount(),n.__reactRoot=void 0;const o=_.createRoot(n.document.body);o.render(p.jsx(Y,{...e,component:r,onMount:s})),n.__reactRoot=o}catch(o){console.error("Error setting up React renderer",o)}return r.getView()};function Y(e){const{editor:t,component:n,window:s,frameView:r,config:i,onMount:o}=e,c=s.document,l=i.wrapper||d.Fragment,f={editorProps:{doc:c,editor:t,frameView:r}},a=i.wrapper?f:{};return p.jsx(l,{...a,children:p.jsx(N,{tagName:"div",component:n,config:i,editor:t,frameView:r,onMount:o})})}const Z="rendererReact";return I(function(e,t={}){e.Canvas.config.customRenderer=n=>X({...n,config:t}),Q(e,t),K({editor:e,licenseKey:t.licenseKey,plan:y.startup,pluginName:Z,cleanup:()=>{e.Canvas.config.customRenderer=void 0}})})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component, ComponentView } from 'grapesjs';
|
|
2
|
+
import { CustomRendererProps } from '../types';
|
|
3
|
+
export interface RenderCanvasComponentProps extends Pick<CustomRendererProps, 'editor' | 'frameView' | 'config'> {
|
|
4
|
+
tagName?: string;
|
|
5
|
+
component: Component;
|
|
6
|
+
onMount?: (view: ComponentView) => void;
|
|
7
|
+
}
|
|
8
|
+
declare function RenderCanvasComponent(propsCmp: RenderCanvasComponentProps): string | import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default RenderCanvasComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component, ComponentView, Editor } from 'grapesjs';
|
|
2
|
+
import { CustomRendererReactConfig } from '../shared/types';
|
|
3
|
+
export declare function useConnectDom(editor: Editor, component: Component, frameView: unknown): {
|
|
4
|
+
connectDom: (el: HTMLElement) => void;
|
|
5
|
+
view: ComponentView<Component> | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function useComponentUpdate(component: Component): number;
|
|
8
|
+
export declare function bindComponentToElement(editor: Editor, component: Component, el: HTMLElement, frameView: unknown): ComponentView<Component>;
|
|
9
|
+
export declare function registerComponents(editor: Editor, config: CustomRendererReactConfig): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ComponentNode } from './parser/parser';
|
|
3
|
+
import { CustomRendererReactConfig } from '../shared/types';
|
|
4
|
+
interface RenderProjectComponentProps {
|
|
5
|
+
component: ComponentNode;
|
|
6
|
+
config: CustomRendererReactConfig;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
parentId?: string;
|
|
9
|
+
index?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const RenderProjectComponent: (props: RenderProjectComponentProps) => string | import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export default RenderProjectComponent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),S=require("react");function T(s,t,e){const o=s.getId(),a=s.getType(),r=o||void 0;let n;return o?n=o:t?n=`${t}-${e??0}`:a==="head"?n="gjs-head":t==="gjs-head"?n=`${t}-${e??0}`:n=`gjs-${a}`,{key:n,nodeId:r}}const $={noPagesFound:()=>"No pages found in project",pageNotFound:({pageId:s=""})=>`Page not found: ${s}`,noFramesFound:()=>"No frames found in page",missingRootComponent:()=>"Missing root component",componentNotFound:({componentId:s=""})=>`Component not found: ${s}`};function N(s){const t={};let e=!1;for(const o in s)if(Object.prototype.hasOwnProperty.call(s,o)){const a=s[o];if(typeof a=="string"||typeof a=="number"){const r=o.includes("-")?o.replace(/-([a-z])/g,n=>n[1].toUpperCase()):o;t[r]=a,e=!0}}return e?t:void 0}function W(s){const t={};return s.split(";").forEach(e=>{if(!e.trim())return;const o=e.indexOf(":");if(o>0){const a=e.substring(0,o).trim(),r=e.substring(o+1).trim();if(a&&r){const n=a.replace(/-([a-z])/g,l=>l[1].toUpperCase());t[n]=r}}}),Object.keys(t).length>0?t:void 0}function E(s){if(s){if(typeof s=="object"&&!Array.isArray(s))return N(s);if(typeof s=="string"){let t=W(s);if(!t)try{const e=JSON.parse(s);typeof e=="object"&&e!==null&&!Array.isArray(e)&&(t=N(e))}catch(e){console.error("Failed to parse style string as JSON",e)}return t}if(Array.isArray(s)){const t={};return s.forEach(e=>{if(typeof e=="object"&&e!==null){const o=e.name||e.property,a=e.value;if(typeof o=="string"&&o&&a!==void 0&&a!==""){const r=o.replace(/-([a-z])/g,n=>n[1].toUpperCase());t[r]=a}}}),Object.keys(t).length>0?t:void 0}}}function O(s){return R[s]?R[s]:s.includes("-")?s.replace(/-([a-z])/g,(t,e)=>e.toUpperCase()):s}function D(s){var o;const t={},e=((o=s.xmlns)==null?void 0:o.includes("svg"))||s.viewBox!==void 0||s.d!==void 0;for(const[a,r]of Object.entries(s))if(a==="style")t.style=E(r);else if(a.startsWith("data-"))t[a]=r;else{const n=O(a);e||M.has(n)||n.startsWith("svg")?t[n]=r:!I.has(n)&&!n.startsWith("on")&&!n.startsWith("aria-")&&!n.startsWith("data-")?t[`data-${a.toLowerCase()}`]=r:t[n]=r}return t}const I=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),M=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),R={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},x=function s(t){var P;const{component:e,config:o,children:a,parentId:r,index:n}=t;if(!e)return null;const l=e.getType()||"",p=e.getContent();if(l==="textnode")return p;const u=(P=o.components)==null?void 0:P[l],i=(u==null?void 0:u.component)||e.getTagName()||"div",h=e.getAttributes(),{key:f,nodeId:k}=T(e,r,n),b=!!(u!=null&&u.component),C=b?h:D(h);b&&Object.keys(C).forEach(m=>{const g=C[m];typeof g=="string"&&!isNaN(Number(g))&&g.trim()!==""&&(C[m]=Number(g))});const A=e.getComponents(),v=[...A.length?A.map((m,g)=>c.jsx(s,{config:o,component:m,parentId:f,index:g},`${m.getId()}-${g}`)):[p],a],w={...C,...k?{id:k}:{}};return b?c.jsx(i,{...w,children:v},f):S.createElement(i,{...w,key:f},e.isVoid()?null:v)};class j{constructor(t){this.data=t}getId(){var t;return(t=this.data.attributes)==null?void 0:t.id}getType(){return this.data.type||"default"}getTagName(){const t=this.getType();return t==="svg"?"svg":t==="image"?"img":t==="linkBox"||t==="link"?"a":t==="head"?"head":t==="wrapper"?"body":this.data.tagName||""}isVoid(){return this.getTagName()==="img"?!0:!!this.data.void}getAttributes(){const t={...this.data.attributes},e=this.getClasses();e.length&&(t.class=e.join(" "));function o(a,r){return Object.prototype.hasOwnProperty.call(a,r)}return o(t,"id")||(t.id=this.getId()),t}getStyle(){return this.data.style||{}}getContent(){return this.data.content||""}getComponents(){return(this.data.components||[]).map(t=>new j(t))}getHead(){return this.data.head?new j(this.data.head):null}getDocEl(){return this.data.docEl}getClasses(){return(this.data.classes||[]).map(e=>typeof e=="string"?e:e.name)}hasClass(t){return this.getClasses().includes(t)}}class B{constructor(t){this.data=t}getComponent(){return this.data.component?new j(this.data.component):null}getWidth(){return this.data.width||""}getHeight(){return this.data.height||""}}class z{constructor(t){this.data=t}getId(){return this.data.id}getName(){return this.data.name||""}getFrames(){return(this.data.frames||[]).map(t=>new B(t))}}class L{constructor(t){this.assets=t}getAll(){return this.assets}}class q{constructor(t){this.rules=t}getAll(){return this.rules}getRulesByGroup(t){return this.rules.filter(e=>e.group===t)}getWrapperRules(){return this.rules.filter(t=>t.wrapper===1)}getCssAsString(){if(!this.rules||!this.rules.length)return"";const t=r=>{if(!r||!r.selectors||!r.style)return"";let n=r.selectors;if(typeof n=="string")n=[n];else if(!Array.isArray(n))return"";const l=n.map(i=>typeof i=="string"&&!i.startsWith(".")&&!i.startsWith("#")&&!i.startsWith("[")&&!i.startsWith(":")&&!i.startsWith(">")&&!i.startsWith("*")&&!i.startsWith("@")?"."+i:i),p=r.state,u=p?l.map(i=>`${i.trim()}:${p}`).join(", "):l.join(""),d=Object.entries(r.style).map(([i,h])=>` ${i}: ${h};`).join(`
|
|
2
|
+
`);return d?`${u} {
|
|
3
|
+
${d}
|
|
4
|
+
}`:""},e=[],o={};this.rules.forEach(r=>{if(!r||!r.selectors||!r.style)return;const n=r.atRuleType&&r.mediaText?`@${r.atRuleType} ${r.mediaText}`:r.mediaText?`@media ${r.mediaText}`:null;n?(o[n]||(o[n]=[]),o[n].push(r)):e.push(r)});let a=e.map(r=>t(r)).join(`
|
|
5
|
+
`);return Object.keys(o).forEach(r=>{const n=o[r].map(l=>t(l)).join(`
|
|
6
|
+
`);n&&(a+=`
|
|
7
|
+
|
|
8
|
+
${r} {
|
|
9
|
+
${n}
|
|
10
|
+
}`)}),a}}class U{constructor(t){this.symbols=t}getAll(){return this.symbols}}class G{constructor(t){this.list=t}getAll(){return this.list}}class J{constructor(t){this.pages=t.map(e=>new z(e))}getAll(){return this.pages}}class V{constructor(t){this.assetManager=new L(t.assets||[]),this.cssComposer=new q(t.styles||[]),this.pages=new J(t.pages||[]),this.symbols=new U(t.symbols||[]),this.dataSources=new G(t.dataSources||[])}getAssetManager(){return this.assetManager}getCssComposer(){return this.cssComposer}getPages(){return this.pages}getSymbols(){return this.symbols}getDataSources(){return this.dataSources}}function F(s,t){if(s.getId()===t)return s;for(const e of s.getComponents()){const o=F(e,t);if(o)return o}return null}function H(s){var d;const{config:t,root:e,css:o}=s,a=t.wrapper||S.Fragment,r=e.getHead(),n=(d=e.getDocEl)==null?void 0:d.call(e),l=e.getAttributes().doctype||"<!DOCTYPE html>",p=(n==null?void 0:n.tagName)||"html",{skipDocType:u}=t;return c.jsxs(c.Fragment,{children:[u!==void 0&&!u&&l,c.jsxs(p,{children:[c.jsx(x,{component:r,config:t,children:c.jsx("style",{children:`${o}`})}),c.jsx(a,{children:c.jsx(x,{component:e,config:t})})]})]})}function y(s,t){const e=s?typeof s=="function"?s(t):s:"An error occurred";return c.jsx(c.Fragment,{children:c.jsx("html",{children:c.jsx("body",{children:e})})})}const K=({projectJson:s,config:t={},pageId:e,componentId:o})=>{var i;const a=new V(s),r=a.getCssComposer().getCssAsString(),n=a.getPages().getAll(),l={...$,...t.errors};if(!n.length)return y(l.noPagesFound,{projectJson:s});const p=e?n.find(h=>h.getName()===e):n[0];if(!p)return y(l.pageNotFound,{pageId:e});const u=p.getFrames();if(!u.length)return y(l.noFramesFound,{page:p});const d=(i=u[0])==null?void 0:i.getComponent();if(!d)return y(l.missingRootComponent,{frame:u[0]});if(o){const h=F(d,o);if(!h)return y(l.componentNotFound,{componentId:o});if(h){const f=t.wrapper||S.Fragment;return c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`${r}`}),c.jsx(f,{children:c.jsx(x,{component:h,config:t})})]})}return null}return c.jsx(H,{config:t,root:d,css:r})};exports.GrapesJSProject=K;exports.RenderProjectComponent=x;
|