@leochen0204/grapesjs-react 2.0.0-react17-rc.0

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/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-current Artur Arseniev (Original work)
4
+ Copyright (c) 2026 Leo Chen (Modifications for React 17 compatibility)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # GrapesJS React
2
+
3
+ > **React 17 compatible fork** optimized for React 17.X projects.
4
+ > Based on the official [GrapesJS React wrapper](https://github.com/GrapesJS/react).
5
+
6
+ A [GrapesJS](https://grapesjs.com) wrapper for React that allows you to build custom and declarative UI for your editor.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ npm i grapesjs @leochen0204/grapesjs-react
12
+ ```
13
+
14
+ ## Compatibility
15
+
16
+ - React v17.X, v18.X, v19.X
17
+ - GrapesJS v0.22.5 or higher
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import grapesjs from 'grapesjs';
23
+ import GjsEditor from '@leochen0204/grapesjs-react';
24
+
25
+ export default function Editor() {
26
+ return (
27
+ <GjsEditor
28
+ grapesjs={grapesjs}
29
+ grapesjsCss="https://unpkg.com/grapesjs/dist/css/grapes.min.css"
30
+ options={{
31
+ height: '100vh',
32
+ storageManager: false,
33
+ }}
34
+ />
35
+ );
36
+ }
37
+ ```
38
+
39
+ For more details, see the [official documentation](https://github.com/GrapesJS/react).
40
+
41
+ ## Credits
42
+
43
+ Based on the official [GrapesJS React wrapper](https://github.com/GrapesJS/react) by the GrapesJS team.
44
+
45
+ ## License
46
+
47
+ MIT
@@ -0,0 +1,44 @@
1
+ import { Asset } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type AssetsState = {
5
+ /**
6
+ * Array of assets.
7
+ */
8
+ assets: Asset[];
9
+ /**
10
+ * Asset types.
11
+ */
12
+ types: string[];
13
+ /**
14
+ * Select asset.
15
+ */
16
+ select: (asset: Asset, complete?: boolean) => void;
17
+ /**
18
+ * Close assets.
19
+ */
20
+ close: () => void;
21
+ /**
22
+ * Asset Manager container.
23
+ */
24
+ Container: PortalContainerResult;
25
+ };
26
+ export type AssetsResultProps = AssetsState & {
27
+ /**
28
+ * Indicates if the Asset Manager is open.
29
+ */
30
+ open: boolean;
31
+ };
32
+ export interface AssetsProviderProps {
33
+ children: (props: AssetsResultProps) => ReactElement<any>;
34
+ }
35
+ export interface AssetsEventProps {
36
+ open: boolean;
37
+ assets: Asset[];
38
+ types: string[];
39
+ select: () => void;
40
+ close: () => void;
41
+ container: HTMLElement;
42
+ }
43
+ declare const _default: (props: AssetsProviderProps) => JSX.Element;
44
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { Block } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type BlocksState = {
5
+ /**
6
+ * Array of blocks.
7
+ */
8
+ blocks: Block[];
9
+ /**
10
+ * Enable drag for a block.
11
+ */
12
+ dragStart: (block: Block, ev?: Event) => void;
13
+ /**
14
+ * Disable drag.
15
+ */
16
+ dragStop: (cancel?: boolean) => void;
17
+ /**
18
+ * Default Block Manager container.
19
+ */
20
+ Container: PortalContainerResult;
21
+ /**
22
+ * Map of blocks by category.
23
+ */
24
+ mapCategoryBlocks: MapCategoryBlocks;
25
+ };
26
+ export type BlocksResultProps = BlocksState;
27
+ export interface BlocksProviderProps {
28
+ children: (props: BlocksResultProps) => ReactElement<any>;
29
+ }
30
+ export interface BlocksEventProps {
31
+ blocks: Block[];
32
+ container: HTMLElement;
33
+ dragStart: (block: Block, ev?: Event) => void;
34
+ drag: (ev: Event) => void;
35
+ dragStop: (cancel?: boolean) => void;
36
+ }
37
+ export type MapCategoryBlocks = Map<string, Block[]>;
38
+ declare const _default: (props: BlocksProviderProps) => JSX.Element;
39
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { HTMLProps } from 'react';
2
+ export default function Canvas({ children, ...rest }: HTMLProps<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { Device } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ export type DevicesState = {
4
+ /**
5
+ * Array of devices.
6
+ */
7
+ devices: Device[];
8
+ /**
9
+ * Selected device id.
10
+ */
11
+ selected: string;
12
+ /**
13
+ * Select new device by id.
14
+ */
15
+ select: (deviceId: string) => void;
16
+ };
17
+ export type DevicesResultProps = DevicesState;
18
+ export interface DevicesProviderProps {
19
+ children: (props: DevicesResultProps) => ReactElement<any>;
20
+ }
21
+ declare const _default: (props: DevicesProviderProps) => JSX.Element;
22
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { JSX } from 'react';
2
+ import { EditorProps } from './EditorInstance';
3
+ declare const _default: (props: EditorProps) => JSX.Element;
4
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { default as gjs, Editor, EditorConfig, ProjectData } from 'grapesjs';
2
+ import { HTMLProps, ReactNode, JSX } from 'react';
3
+ import { PluginTypeToLoad } from './utils/plugins';
4
+ export interface EditorProps extends HTMLProps<HTMLDivElement> {
5
+ grapesjs: string | typeof gjs;
6
+ /**
7
+ * GrapesJS options.
8
+ */
9
+ options?: EditorConfig;
10
+ /**
11
+ * Load GrapesJS CSS file asynchronously from URL.
12
+ * @example 'https://unpkg.com/grapesjs/dist/css/grapes.min.css'
13
+ */
14
+ grapesjsCss?: string;
15
+ /**
16
+ * Array of plugins.
17
+ * Differently from the GrapesJS `plugins` option, this one allows also you to load plugins
18
+ * asynchronously from a CDN URL.
19
+ * @example
20
+ * plugins: [
21
+ * {
22
+ * // The id should be name of the plugin that will be actually loaded
23
+ * id: 'gjs-blocks-basic',
24
+ * src: 'https://unpkg.com/grapesjs-blocks-basic',
25
+ * options: {}
26
+ * }
27
+ * // plugin already loaded in the global scope (eg. loaded via CND in HTML)
28
+ * 'grapesjs-plugin-forms',
29
+ * // plugin as a function
30
+ * myPlugin,
31
+ * ]
32
+ */
33
+ plugins?: PluginTypeToLoad[];
34
+ /**
35
+ * Callback triggered once the editor instance is created.
36
+ */
37
+ onEditor?: (editor: Editor) => void;
38
+ /**
39
+ * Callback triggered once the editor is ready (mounted and loaded data from the Storage).
40
+ */
41
+ onReady?: (editor: Editor) => void;
42
+ /**
43
+ * Callback triggered on each update in the editor project.
44
+ * The updated ProjectData (JSON) is passed as a first argument.
45
+ */
46
+ onUpdate?: (projectData: ProjectData, editor: Editor) => void;
47
+ /**
48
+ * Avoid showing children of the editor until the editor is ready (mounted and loaded data from the Storage).
49
+ */
50
+ waitReady?: boolean | ReactNode;
51
+ }
52
+ declare const _default: (props: EditorProps) => JSX.Element;
53
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const EditorReady: import('react').NamedExoticComponent<object>;
2
+ export default EditorReady;
@@ -0,0 +1,19 @@
1
+ import { Component } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type LayersState = {
5
+ /**
6
+ * Root layer component.
7
+ */
8
+ root?: Component;
9
+ /**
10
+ * Default Layers Manager container.
11
+ */
12
+ Container: PortalContainerResult;
13
+ };
14
+ export type LayersResultProps = LayersState;
15
+ export interface LayersProviderProps {
16
+ children: (props: LayersResultProps) => ReactElement<any>;
17
+ }
18
+ declare const _default: (props: LayersProviderProps) => JSX.Element;
19
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import { ReactElement, JSX } from 'react';
2
+ export interface ModalState {
3
+ /**
4
+ * Modal title
5
+ */
6
+ title: ReactElement<any>;
7
+ /**
8
+ * Modal content
9
+ */
10
+ content: ReactElement<any>;
11
+ /**
12
+ * Modal attributes
13
+ */
14
+ attributes: Record<string, any>;
15
+ /**
16
+ * Callback for closing the modal
17
+ */
18
+ close: () => void;
19
+ }
20
+ export interface ModalResultProps extends ModalState {
21
+ /**
22
+ * Indicates if the modal is open.
23
+ */
24
+ open: boolean;
25
+ }
26
+ export interface ModalProviderProps {
27
+ children: (props: ModalResultProps) => ReactElement<any>;
28
+ }
29
+ export interface ModalEventProps {
30
+ open: boolean;
31
+ title: string | HTMLElement;
32
+ content: string | HTMLElement;
33
+ attributes: Record<string, any>;
34
+ close: () => void;
35
+ }
36
+ declare const _default: (props: ModalProviderProps) => JSX.Element;
37
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { Editor, Page } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ export type PagesState = {
4
+ /**
5
+ * Array of pages.
6
+ */
7
+ pages: Page[];
8
+ /**
9
+ * Selected page.
10
+ */
11
+ selected?: Page;
12
+ /**
13
+ * Select page.
14
+ */
15
+ select: Editor['Pages']['select'];
16
+ /**
17
+ * Add new page.
18
+ */
19
+ add: Editor['Pages']['add'];
20
+ /**
21
+ * Remove page.
22
+ */
23
+ remove: Editor['Pages']['remove'];
24
+ };
25
+ export type PagesResultProps = PagesState;
26
+ export interface PagesProviderProps {
27
+ children: (props: PagesResultProps) => ReactElement<any>;
28
+ }
29
+ declare const _default: (props: PagesProviderProps) => JSX.Element;
30
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import { Selector, State, Editor } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type SelectorsState = {
5
+ /**
6
+ * Array of current selectors.
7
+ */
8
+ selectors: Selector[];
9
+ /**
10
+ * Array of available states.
11
+ */
12
+ states: State[];
13
+ /**
14
+ * Current selected state.
15
+ */
16
+ selectedState: string;
17
+ /**
18
+ * Selector strings of currently selected targets.
19
+ */
20
+ targets: string[];
21
+ /**
22
+ * Add new selector to selected targets.
23
+ */
24
+ addSelector: (...args: Parameters<Editor['Selectors']['addSelected']>) => void;
25
+ /**
26
+ * Remove selector from selected targets.
27
+ */
28
+ removeSelector: (...args: Parameters<Editor['Selectors']['removeSelected']>) => void;
29
+ /**
30
+ * Update current state.
31
+ */
32
+ setState: (...args: Parameters<Editor['Selectors']['setState']>) => void;
33
+ /**
34
+ * Default Selectors container.
35
+ */
36
+ Container: PortalContainerResult;
37
+ };
38
+ export type SelectorsResultProps = SelectorsState;
39
+ export interface SelectorsProviderProps {
40
+ children: (props: SelectorsResultProps) => ReactElement<any>;
41
+ }
42
+ declare const _default: (props: SelectorsProviderProps) => JSX.Element;
43
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { Sector } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type StylesState = {
5
+ /**
6
+ * Array of visible sectors.
7
+ */
8
+ sectors: Sector[];
9
+ /**
10
+ * Default Styles container.
11
+ */
12
+ Container: PortalContainerResult;
13
+ };
14
+ export type StylesResultProps = StylesState;
15
+ export interface StylesProviderProps {
16
+ children: (props: StylesResultProps) => ReactElement<any>;
17
+ }
18
+ declare const _default: (props: StylesProviderProps) => JSX.Element;
19
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { Trait } from 'grapesjs';
2
+ import { ReactElement, JSX } from 'react';
3
+ import { PortalContainerResult } from './utils/react';
4
+ export type TraitsState = {
5
+ /**
6
+ * Current selected traits.
7
+ */
8
+ traits: Trait[];
9
+ /**
10
+ * Default Trait Manager container.
11
+ */
12
+ Container: PortalContainerResult;
13
+ };
14
+ export type TraitsResultProps = TraitsState;
15
+ export interface TraitsProviderProps {
16
+ children: (props: TraitsResultProps) => ReactElement<any>;
17
+ }
18
+ declare const _default: (props: TraitsProviderProps) => JSX.Element;
19
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { PropsWithChildren } from 'react';
2
+ /**
3
+ * Load children once the editor is available
4
+ */
5
+ declare const WithEditor: ({ children }: PropsWithChildren<{}>) => import("react/jsx-runtime").JSX.Element;
6
+ export default WithEditor;
@@ -0,0 +1,24 @@
1
+ import { Editor } from 'grapesjs';
2
+ import { ReactNode } from 'react';
3
+ declare const EditorInstanceContext: import('react').Context<EditorInstanceState | null>;
4
+ export interface EditorInstanceState {
5
+ editor?: Editor;
6
+ setEditor: (editor: Editor) => void;
7
+ }
8
+ export declare const EditorInstanceProvider: ({ children }: {
9
+ children?: ReactNode;
10
+ }) => import("react/jsx-runtime").JSX.Element;
11
+ /**
12
+ * Context used to keep the editor instance once initialized
13
+ */
14
+ export declare const useEditorInstance: () => EditorInstanceState;
15
+ /**
16
+ * Get the current editor instance.
17
+ * @returns Editor
18
+ */
19
+ export declare const useEditor: () => Editor;
20
+ /**
21
+ * Similar to useEditor, but in this case, the editor might be undefined.
22
+ */
23
+ export declare const useEditorMaybe: () => Editor | undefined;
24
+ export default EditorInstanceContext;
@@ -0,0 +1,32 @@
1
+ import { ReactNode } from 'react';
2
+ declare const EditorOptionsContext: import('react').Context<EditorOptionsState | null>;
3
+ export interface EditorOptionsState {
4
+ refCanvas?: HTMLElement;
5
+ customModal?: boolean;
6
+ customAssets?: boolean;
7
+ customStyles?: boolean;
8
+ customBlocks?: boolean;
9
+ customLayers?: boolean;
10
+ customSelectors?: boolean;
11
+ customTraits?: boolean;
12
+ customRte?: boolean;
13
+ ready?: boolean;
14
+ setRefCanvas: (ref: HTMLElement) => void;
15
+ setCustomModal: (value: boolean) => void;
16
+ setCustomAssets: (value: boolean) => void;
17
+ setCustomBlocks: (value: boolean) => void;
18
+ setCustomRte: (value: boolean) => void;
19
+ setCustomStyles: (value: boolean) => void;
20
+ setCustomLayers: (value: boolean) => void;
21
+ setCustomSelectors: (value: boolean) => void;
22
+ setCustomTraits: (value: boolean) => void;
23
+ setReady: (value: boolean) => void;
24
+ }
25
+ export declare const EditorOptionsProvider: ({ children }: {
26
+ children?: ReactNode;
27
+ }) => import("react/jsx-runtime").JSX.Element;
28
+ /**
29
+ * Context used to keep the editor instance once initialized
30
+ */
31
+ export declare const useEditorOptions: () => EditorOptionsState;
32
+ export default EditorOptionsContext;
@@ -0,0 +1,2 @@
1
+ export { EditorInstanceProvider } from './EditorInstance';
2
+ export { EditorOptionsProvider } from './EditorOptions';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),r=require("react"),G=require("react-dom"),_=r.createContext(null),J=({children:e})=>{const[t,c]=r.useState({setEditor:s=>{c(n=>({...n,editor:s}))}});return o.jsx(_.Provider,{value:t,children:e})},m=()=>{const e=r.useContext(_);if(!e)throw new Error("useEditorInstance must be used within EditorInstanceProvider");return e},K=()=>{const{editor:e}=m();if(!e)throw new Error("useEditor used before the load of the editor instance. You can wrap your component in `<WithEditor>` or make use of `useEditorMaybe` hook and ensure the `editor` exists.");return e},D=()=>m().editor,W=r.createContext(null),Q=({children:e})=>{const[t,c]=r.useState(()=>({setRefCanvas(s){c(n=>({...n,refCanvas:s}))},setCustomModal(s){c(n=>({...n,customModal:s}))},setCustomAssets(s){c(n=>({...n,customAssets:s}))},setCustomBlocks(s){c(n=>({...n,customBlocks:s}))},setCustomRte(s){c(n=>({...n,customRte:s}))},setCustomStyles(s){c(n=>({...n,customStyles:s}))},setCustomLayers(s){c(n=>({...n,customLayers:s}))},setCustomSelectors(s){c(n=>({...n,customSelectors:s}))},setCustomTraits(s){c(n=>({...n,customTraits:s}))},setReady(s){c(n=>({...n,ready:s}))}}));return o.jsx(W.Provider,{value:t,children:e})},S=()=>{const e=r.useContext(W);if(!e)throw new Error("useEditorOptions must be used within EditorOptionsProvider");return e};function U(...e){return(Array.isArray(e[0])?e[0]:[...e]).filter(Boolean).join(" ")}function x(e){return typeof e=="function"}function p(){}const q=e=>typeof e=="string",V=async e=>{const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)},N=e=>{const t=q(e)?{id:e,src:e}:e;return new Promise((c,s)=>{const n=document.createElement("script");if(document.querySelector(`script[src="${t.src}"]`))return c(t.id);n.src=t.src,n.onload=()=>c(t.id),n.onerror=()=>s(t.id),document.head.appendChild(n)})},X=e=>{const t=e.map(c=>N(c));return Promise.allSettled(t)},A=e=>function(){const c=r.useRef(null);return r.useEffect(()=>{const{current:s}=c;s&&(q(e)?s.innerHTML=e:s.appendChild(e))},[c.current]),o.jsx("div",{ref:c})},I=new WeakMap;function j(e){if(!e)return()=>o.jsx(o.Fragment,{});const t=I.get(e);if(t)return t;const c=function({children:n}){return G.createPortal(r.createElement("div",null,n),e)};return I.set(e,c),c}const Z=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(!1),[i,a]=r.useState({assets:[],types:[],close:()=>{},select:()=>{},Container:()=>o.jsx(o.Fragment,{})});return r.useEffect(()=>{if(!t)return;const u=t.Assets.events.custom,d=({open:f,assets:v,types:C,select:E,close:l,container:y})=>{f&&a({assets:v,types:C,select:E,close:l,Container:j(y)}),n(f)};return t.on(u,d),()=>{t.off(u,d)}},[t]),r.useEffect(()=>c.setCustomAssets(!0),[]),t?x(e)?e({open:s,...i}):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),tt=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(()=>({blocks:[],dragStart:p,dragStop:p,mapCategoryBlocks:new Map,Container:()=>o.jsx(o.Fragment,{})}));return r.useEffect(()=>{if(!t)return;const i=t.Blocks.events.custom,a=({blocks:u,container:d,dragStart:f,dragStop:v})=>{const C=u.reduce((E,l)=>{const y=l.getCategoryLabel(),P=E.get(y);return P?P.push(l):E.set(y,[l]),E},new Map);n({blocks:u,dragStart:f,dragStop:v,mapCategoryBlocks:C,Container:j(d)})};return t.on(i,a),t.Blocks.__trgCustom(),()=>{t.off(i,a)}},[t]),r.useEffect(()=>c.setCustomBlocks(!0),[]),t?x(e)?e(s):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})});function et({children:e,...t}){const c=S(),s=r.useRef(null);return r.useEffect(()=>{s.current&&c.setRefCanvas(s.current)},[s.current]),o.jsx("div",{...t,ref:s,children:e})}const st=r.memo(function({children:e}){const{editor:t}=m(),[c,s]=r.useState(()=>({devices:[],selected:"",select:p}));return r.useEffect(()=>{if(!t)return;const{Devices:n}=t,i=n.events.all,a=()=>{var u;s({devices:n.getDevices(),selected:(u=n.getSelected())==null?void 0:u.id,select:d=>n.select(d)})};return t.on(i,a),a(),()=>{t.off(i,a)}},[t]),t?x(e)?e(c):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),ot=e=>!!(e&&!Array.isArray(e)&&typeof e=="object");async function nt(e){const t=e.map(({id:a,src:u})=>({id:a,src:u})),c=e.reduce((a,u)=>(a[u.id]=u,a),{}),s=[],n=[];return(await X(t)).forEach(a=>{a.status==="fulfilled"?s.push(c[a.value]):n.push(c[a.reason])}),{loaded:s,failed:n}}const rt=async e=>{const t=[...e],c={};if(t.length){const s={},n=[];if(t.forEach((i,a)=>{ot(i)&&(s[i.id]={index:a},n.push(i))}),n.length){const{loaded:i}=await nt(n);i.forEach(({id:a,options:u})=>{s[a].loaded=!0,c[a]=u||{}})}Object.keys(s).forEach(i=>{const a=s[i];a.loaded?t[a.index]=i:t[a.index]=!1})}return{plugins:t.filter(Boolean),pluginOptions:c}},ct=r.memo(function({children:e,className:t,style:c,options:s={},plugins:n=[],grapesjs:i,grapesjsCss:a,onEditor:u=p,onReady:d,onUpdate:f,waitReady:v,...C}){const{setEditor:E}=m(),l=S(),[y,P]=r.useState(!1),F=r.useRef(null);r.useEffect(()=>{if(!l.ready||!F.current)return;const $=F.current,w=l.refCanvas;let g,T={},b=[];const B=h=>{const z={height:"100%",...s,plugins:[...b,...s.plugins||[]],pluginsOpts:{...s.pluginsOpts,...T},modal:{custom:!!l.customModal,...s.modal},assetManager:{custom:!!l.customAssets,...s.assetManager},styleManager:{custom:!!l.customStyles,...s.styleManager},blockManager:{custom:!!l.customBlocks,...s.blockManager},richTextEditor:{custom:!!l.customRte,...s.richTextEditor},layerManager:{custom:!!l.customLayers,...s.layerManager},traitManager:{custom:!!l.customTraits,...s.traitManager},selectorManager:{custom:!!l.customSelectors,...s.selectorManager},container:w||$,customUI:!!w,...w?{panels:{defaults:[]}}:{}};g=h.init(z),E(g),u(g),f&&g.on("update",()=>{f(g.getProjectData(),g)}),g.onReady(()=>{P(!0),d==null||d(g)})};return(async()=>{a&&await V(a);const h=await rt(n);b=h.plugins,T=h.pluginOptions,typeof i=="string"?(await N(i),B(window.grapesjs)):B(i)})(),()=>g==null?void 0:g.destroy()},[l.ready]);const O=s.height??"100%",k=s.width??"100%",L=U("gjs-editor-wrapper",t),R=v&&!y,M=r.useMemo(()=>({...c,height:O,width:k}),[O,k,c]),Y=r.useMemo(()=>({...M,...R?{opacity:0,width:0,height:0}:{}}),[M,R]);return o.jsxs(o.Fragment,{children:[v&&!y?o.jsx("div",{className:L,style:M,children:v}):null,o.jsx("div",{...C,ref:F,className:L,style:Y,children:e})]})}),at=r.memo(function(){const e=S();return r.useEffect(()=>e.setReady(!0),[]),o.jsx(o.Fragment,{})}),H=r.memo(function({children:t,...c}){return o.jsx(J,{children:o.jsx(Q,{children:o.jsxs(ct,{...c,children:[t,o.jsx(at,{})]})})})}),it=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(()=>({root:void 0,Container:()=>o.jsx(o.Fragment,{})}));return r.useEffect(()=>{if(!t)return;const{Layers:i}=t,a=i.events.custom,u=({container:d})=>{n({root:i.getRoot(),Container:j(d)})};return t.on(a,u),i.__trgCustom({}),()=>{t.off(a,u)}},[t]),r.useEffect(()=>c.setCustomLayers(!0),[]),t?x(e)?e(s):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),ut=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(!1),[i,a]=r.useState({title:o.jsx(o.Fragment,{}),content:o.jsx(o.Fragment,{}),attributes:{},close:p});return r.useEffect(()=>{if(!t)return;const u="modal",d=({open:f,title:v,content:C,close:E,attributes:l})=>{f&&a({title:r.createElement(A(v)),content:r.createElement(A(C)),attributes:l,close:E}),n(f)};return t.on(u,d),()=>{t.off(u,d)}},[t]),r.useEffect(()=>c.setCustomModal(!0),[]),t?typeof e=="function"?e({open:s,...i}):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),dt=r.memo(function({children:e}){const{editor:t}=m(),[c,s]=r.useState(()=>({pages:[],selected:void 0,select:p,add:p,remove:p}));return r.useEffect(()=>{if(!t)return;const{Pages:n}=t,i=n.events.all,a=()=>{s({pages:n.getAll(),selected:n.getSelected(),select:(...u)=>n.select(...u),add:(...u)=>n.add(...u),remove:(...u)=>n.remove(...u)})};return t.on(i,a),a(),()=>{t.off(i,a)}},[t]),t?x(e)?e(c):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),lt=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(()=>({selectors:[],states:[],selectedState:"",targets:[],addSelector:p,removeSelector:p,setState:p,Container:()=>o.jsx(o.Fragment,{})}));return r.useEffect(()=>{if(!t)return;const{Selectors:i}=t,a=i.events.custom,u=({container:d})=>{n({selectors:i.getSelected(),states:i.getStates(),selectedState:i.getState(),targets:i.getSelectedTargets().map(f=>f.getSelectorsString()),addSelector:(...f)=>i.addSelected(...f),removeSelector:(...f)=>i.removeSelected(...f),setState:(...f)=>i.setState(...f),Container:j(d)})};return t.on(a,u),()=>{t.off(a,u)}},[t]),r.useEffect(()=>c.setCustomSelectors(!0),[]),t?x(e)?e(s):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),ft=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(()=>({sectors:[],Container:()=>o.jsx(o.Fragment,{})}));return r.useEffect(()=>{if(!t)return;const{Styles:i}=t,a=i.events.custom,u=({container:d})=>{n({sectors:i.getSectors({visible:!0}),Container:j(d)})};return t.on(a,u),()=>{t.off(a,u)}},[t]),r.useEffect(()=>c.setCustomStyles(!0),[]),t?x(e)?e(s):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),mt=r.memo(function({children:e}){const{editor:t}=m(),c=S(),[s,n]=r.useState(()=>({traits:[],Container:()=>o.jsx(o.Fragment,{})}));return r.useEffect(()=>{if(!t)return;const{Traits:i}=t,a=i.events.custom,u=({container:d})=>{n({traits:i.getCurrent(),Container:j(d)})};return t.on(a,u),i.__trgCustom(),()=>{t.off(a,u)}},[t]),r.useEffect(()=>c.setCustomTraits(!0),[]),t?x(e)?e(s):o.jsx(o.Fragment,{}):o.jsx(o.Fragment,{})}),gt=({children:e})=>D()?o.jsx(o.Fragment,{children:e}):o.jsx(o.Fragment,{});exports.AssetsProvider=Z;exports.BlocksProvider=tt;exports.Canvas=et;exports.DevicesProvider=st;exports.Editor=H;exports.LayersProvider=it;exports.ModalProvider=ut;exports.PagesProvider=dt;exports.SelectorsProvider=lt;exports.StylesProvider=ft;exports.TraitsProvider=mt;exports.WithEditor=gt;exports.default=H;exports.useEditor=K;exports.useEditorMaybe=D;
@@ -0,0 +1,22 @@
1
+ export { default as AssetsProvider } from './AssetsProvider';
2
+ export type { AssetsResultProps } from './AssetsProvider';
3
+ export { default as BlocksProvider } from './BlocksProvider';
4
+ export type { BlocksResultProps } from './BlocksProvider';
5
+ export { default as Canvas } from './Canvas';
6
+ export { default as DevicesProvider } from './DevicesProvider';
7
+ export type { DevicesResultProps } from './DevicesProvider';
8
+ export { default as Editor, default } from './Editor';
9
+ export type * from './EditorInstance';
10
+ export { default as LayersProvider } from './LayersProvider';
11
+ export type { LayersResultProps } from './LayersProvider';
12
+ export { default as ModalProvider } from './ModalProvider';
13
+ export { default as PagesProvider } from './PagesProvider';
14
+ export type { PagesResultProps } from './PagesProvider';
15
+ export { default as SelectorsProvider } from './SelectorsProvider';
16
+ export type { SelectorsResultProps } from './SelectorsProvider';
17
+ export { default as StylesProvider } from './StylesProvider';
18
+ export type { StylesResultProps } from './StylesProvider';
19
+ export { default as TraitsProvider } from './TraitsProvider';
20
+ export type { TraitsResultProps } from './TraitsProvider';
21
+ export { default as WithEditor } from './WithEditor';
22
+ export { useEditor, useEditorMaybe } from './context/EditorInstance';
package/dist/index.js ADDED
@@ -0,0 +1,473 @@
1
+ import { jsx as i, Fragment as u, jsxs as Y } from "react/jsx-runtime";
2
+ import { createContext as $, useState as m, useContext as z, useRef as B, useEffect as l, createElement as b, memo as g, useMemo as N } from "react";
3
+ import { createPortal as Z } from "react-dom";
4
+ const G = $(null), tt = ({ children: e }) => {
5
+ const [t, n] = m({
6
+ setEditor: (o) => {
7
+ n((s) => ({ ...s, editor: o }));
8
+ }
9
+ });
10
+ return /* @__PURE__ */ i(G.Provider, { value: t, children: e });
11
+ }, v = () => {
12
+ const e = z(G);
13
+ if (!e)
14
+ throw new Error("useEditorInstance must be used within EditorInstanceProvider");
15
+ return e;
16
+ }, gt = () => {
17
+ const { editor: e } = v();
18
+ if (!e)
19
+ throw new Error(
20
+ "useEditor used before the load of the editor instance. You can wrap your component in `<WithEditor>` or make use of `useEditorMaybe` hook and ensure the `editor` exists."
21
+ );
22
+ return e;
23
+ }, et = () => v().editor, J = $(null), ot = ({ children: e }) => {
24
+ const [t, n] = m(() => ({
25
+ setRefCanvas(o) {
26
+ n((s) => ({ ...s, refCanvas: o }));
27
+ },
28
+ setCustomModal(o) {
29
+ n((s) => ({ ...s, customModal: o }));
30
+ },
31
+ setCustomAssets(o) {
32
+ n((s) => ({ ...s, customAssets: o }));
33
+ },
34
+ setCustomBlocks(o) {
35
+ n((s) => ({ ...s, customBlocks: o }));
36
+ },
37
+ setCustomRte(o) {
38
+ n((s) => ({ ...s, customRte: o }));
39
+ },
40
+ setCustomStyles(o) {
41
+ n((s) => ({ ...s, customStyles: o }));
42
+ },
43
+ setCustomLayers(o) {
44
+ n((s) => ({ ...s, customLayers: o }));
45
+ },
46
+ setCustomSelectors(o) {
47
+ n((s) => ({ ...s, customSelectors: o }));
48
+ },
49
+ setCustomTraits(o) {
50
+ n((s) => ({ ...s, customTraits: o }));
51
+ },
52
+ setReady(o) {
53
+ n((s) => ({ ...s, ready: o }));
54
+ }
55
+ }));
56
+ return /* @__PURE__ */ i(J.Provider, { value: t, children: e });
57
+ }, y = () => {
58
+ const e = z(J);
59
+ if (!e)
60
+ throw new Error("useEditorOptions must be used within EditorOptionsProvider");
61
+ return e;
62
+ };
63
+ function st(...e) {
64
+ return (Array.isArray(e[0]) ? e[0] : [...e]).filter(Boolean).join(" ");
65
+ }
66
+ function P(e) {
67
+ return typeof e == "function";
68
+ }
69
+ function C() {
70
+ }
71
+ const K = (e) => typeof e == "string", nt = async (e) => {
72
+ const t = document.createElement("link");
73
+ t.href = e, t.rel = "stylesheet", document.head.appendChild(t);
74
+ }, Q = (e) => {
75
+ const t = K(e) ? { id: e, src: e } : e;
76
+ return new Promise((n, o) => {
77
+ const s = document.createElement("script");
78
+ if (document.querySelector(`script[src="${t.src}"]`))
79
+ return n(t.id);
80
+ s.src = t.src, s.onload = () => n(t.id), s.onerror = () => o(t.id), document.head.appendChild(s);
81
+ });
82
+ }, rt = (e) => {
83
+ const t = e.map((n) => Q(n));
84
+ return Promise.allSettled(t);
85
+ }, q = (e) => function() {
86
+ const n = B(null);
87
+ return l(() => {
88
+ const { current: o } = n;
89
+ o && (K(e) ? o.innerHTML = e : o.appendChild(e));
90
+ }, [n.current]), /* @__PURE__ */ i("div", { ref: n });
91
+ }, H = /* @__PURE__ */ new WeakMap();
92
+ function O(e) {
93
+ if (!e)
94
+ return () => /* @__PURE__ */ i(u, {});
95
+ const t = H.get(e);
96
+ if (t)
97
+ return t;
98
+ const n = function({ children: s }) {
99
+ return Z(b("div", null, s), e);
100
+ };
101
+ return H.set(e, n), n;
102
+ }
103
+ const vt = g(function({ children: e }) {
104
+ const { editor: t } = v(), n = y(), [o, s] = m(!1), [c, r] = m({
105
+ assets: [],
106
+ types: [],
107
+ close: () => {
108
+ },
109
+ select: () => {
110
+ },
111
+ Container: () => /* @__PURE__ */ i(u, {})
112
+ });
113
+ return l(() => {
114
+ if (!t)
115
+ return;
116
+ const a = t.Assets.events.custom, d = ({ open: p, assets: E, types: M, select: h, close: f, container: w }) => {
117
+ p && r({
118
+ assets: E,
119
+ types: M,
120
+ select: h,
121
+ close: f,
122
+ Container: O(w)
123
+ }), s(p);
124
+ };
125
+ return t.on(a, d), () => {
126
+ t.off(a, d);
127
+ };
128
+ }, [t]), l(() => n.setCustomAssets(!0), []), t ? P(e) ? e({ open: o, ...c }) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
129
+ }), St = g(function({ children: e }) {
130
+ const { editor: t } = v(), n = y(), [o, s] = m(() => ({
131
+ blocks: [],
132
+ dragStart: C,
133
+ dragStop: C,
134
+ mapCategoryBlocks: /* @__PURE__ */ new Map(),
135
+ Container: () => /* @__PURE__ */ i(u, {})
136
+ }));
137
+ return l(() => {
138
+ if (!t)
139
+ return;
140
+ const c = t.Blocks.events.custom, r = ({ blocks: a, container: d, dragStart: p, dragStop: E }) => {
141
+ const M = a.reduce((h, f) => {
142
+ const w = f.getCategoryLabel(), k = h.get(w);
143
+ return k ? k.push(f) : h.set(w, [f]), h;
144
+ }, /* @__PURE__ */ new Map());
145
+ s({
146
+ blocks: a,
147
+ dragStart: p,
148
+ dragStop: E,
149
+ mapCategoryBlocks: M,
150
+ Container: O(d)
151
+ });
152
+ };
153
+ return t.on(c, r), t.Blocks.__trgCustom(), () => {
154
+ t.off(c, r);
155
+ };
156
+ }, [t]), l(() => n.setCustomBlocks(!0), []), t ? P(e) ? e(o) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
157
+ });
158
+ function Ct({ children: e, ...t }) {
159
+ const n = y(), o = B(null);
160
+ return l(() => {
161
+ o.current && n.setRefCanvas(o.current);
162
+ }, [o.current]), /* @__PURE__ */ i("div", { ...t, ref: o, children: e });
163
+ }
164
+ const yt = g(function({ children: e }) {
165
+ const { editor: t } = v(), [n, o] = m(() => ({
166
+ devices: [],
167
+ selected: "",
168
+ select: C
169
+ }));
170
+ return l(() => {
171
+ if (!t)
172
+ return;
173
+ const { Devices: s } = t, c = s.events.all, r = () => {
174
+ var a;
175
+ o({
176
+ devices: s.getDevices(),
177
+ selected: (a = s.getSelected()) == null ? void 0 : a.id,
178
+ select: (d) => s.select(d)
179
+ });
180
+ };
181
+ return t.on(c, r), r(), () => {
182
+ t.off(c, r);
183
+ };
184
+ }, [t]), t ? P(e) ? e(n) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
185
+ }), ct = (e) => !!(e && !Array.isArray(e) && typeof e == "object");
186
+ async function it(e) {
187
+ const t = e.map(({ id: r, src: a }) => ({ id: r, src: a })), n = e.reduce(
188
+ (r, a) => (r[a.id] = a, r),
189
+ {}
190
+ ), o = [], s = [];
191
+ return (await rt(t)).forEach((r) => {
192
+ r.status === "fulfilled" ? o.push(n[r.value]) : s.push(n[r.reason]);
193
+ }), { loaded: o, failed: s };
194
+ }
195
+ const at = async (e) => {
196
+ const t = [...e], n = {};
197
+ if (t.length) {
198
+ const o = {}, s = [];
199
+ if (t.forEach((c, r) => {
200
+ ct(c) && (o[c.id] = { index: r }, s.push(c));
201
+ }), s.length) {
202
+ const { loaded: c } = await it(s);
203
+ c.forEach(({ id: r, options: a }) => {
204
+ o[r].loaded = !0, n[r] = a || {};
205
+ });
206
+ }
207
+ Object.keys(o).forEach((c) => {
208
+ const r = o[c];
209
+ r.loaded ? t[r.index] = c : t[r.index] = !1;
210
+ });
211
+ }
212
+ return {
213
+ plugins: t.filter(Boolean),
214
+ pluginOptions: n
215
+ };
216
+ }, ut = g(function({
217
+ children: e,
218
+ className: t,
219
+ style: n,
220
+ options: o = {},
221
+ plugins: s = [],
222
+ grapesjs: c,
223
+ grapesjsCss: r,
224
+ onEditor: a = C,
225
+ onReady: d,
226
+ onUpdate: p,
227
+ waitReady: E,
228
+ ...M
229
+ }) {
230
+ const { setEditor: h } = v(), f = y(), [w, k] = m(!1), L = B(null);
231
+ l(() => {
232
+ if (!f.ready || !L.current)
233
+ return;
234
+ const V = L.current, R = f.refCanvas;
235
+ let S, j = {}, D = [];
236
+ const F = (x) => {
237
+ const X = {
238
+ height: "100%",
239
+ ...o,
240
+ plugins: [...D, ...o.plugins || []],
241
+ pluginsOpts: {
242
+ ...o.pluginsOpts,
243
+ ...j
244
+ },
245
+ modal: {
246
+ custom: !!f.customModal,
247
+ ...o.modal
248
+ },
249
+ assetManager: {
250
+ custom: !!f.customAssets,
251
+ ...o.assetManager
252
+ },
253
+ styleManager: {
254
+ custom: !!f.customStyles,
255
+ ...o.styleManager
256
+ },
257
+ blockManager: {
258
+ custom: !!f.customBlocks,
259
+ ...o.blockManager
260
+ },
261
+ richTextEditor: {
262
+ custom: !!f.customRte,
263
+ ...o.richTextEditor
264
+ },
265
+ layerManager: {
266
+ custom: !!f.customLayers,
267
+ ...o.layerManager
268
+ },
269
+ traitManager: {
270
+ custom: !!f.customTraits,
271
+ ...o.traitManager
272
+ },
273
+ selectorManager: {
274
+ custom: !!f.customSelectors,
275
+ ...o.selectorManager
276
+ },
277
+ container: R || V,
278
+ customUI: !!R,
279
+ // Disables all default panels if Canvas is used
280
+ ...R ? {
281
+ panels: { defaults: [] }
282
+ } : {}
283
+ };
284
+ S = x.init(X), h(S), a(S), p && S.on("update", () => {
285
+ p(S.getProjectData(), S);
286
+ }), S.onReady(() => {
287
+ k(!0), d == null || d(S);
288
+ });
289
+ };
290
+ return (async () => {
291
+ r && await nt(r);
292
+ const x = await at(s);
293
+ D = x.plugins, j = x.pluginOptions, typeof c == "string" ? (await Q(c), F(window.grapesjs)) : F(c);
294
+ })(), () => S == null ? void 0 : S.destroy();
295
+ }, [f.ready]);
296
+ const A = o.height ?? "100%", I = o.width ?? "100%", W = st("gjs-editor-wrapper", t), _ = E && !w, T = N(
297
+ () => ({
298
+ ...n,
299
+ height: A,
300
+ width: I
301
+ }),
302
+ [A, I, n]
303
+ ), U = N(
304
+ () => ({
305
+ ...T,
306
+ ..._ ? {
307
+ opacity: 0,
308
+ width: 0,
309
+ height: 0
310
+ } : {}
311
+ }),
312
+ [T, _]
313
+ );
314
+ return /* @__PURE__ */ Y(u, { children: [
315
+ E && !w ? /* @__PURE__ */ i("div", { className: W, style: T, children: E }) : null,
316
+ /* @__PURE__ */ i("div", { ...M, ref: L, className: W, style: U, children: e })
317
+ ] });
318
+ }), dt = g(function() {
319
+ const e = y();
320
+ return l(() => e.setReady(!0), []), /* @__PURE__ */ i(u, {});
321
+ }), Et = g(function({ children: t, ...n }) {
322
+ return /* @__PURE__ */ i(tt, { children: /* @__PURE__ */ i(ot, { children: /* @__PURE__ */ Y(ut, { ...n, children: [
323
+ t,
324
+ /* @__PURE__ */ i(dt, {})
325
+ ] }) }) });
326
+ }), ht = g(function({ children: e }) {
327
+ const { editor: t } = v(), n = y(), [o, s] = m(() => ({
328
+ root: void 0,
329
+ Container: () => /* @__PURE__ */ i(u, {})
330
+ }));
331
+ return l(() => {
332
+ if (!t)
333
+ return;
334
+ const { Layers: c } = t, r = c.events.custom, a = ({ container: d }) => {
335
+ s({
336
+ root: c.getRoot(),
337
+ Container: O(d)
338
+ });
339
+ };
340
+ return t.on(r, a), c.__trgCustom({}), () => {
341
+ t.off(r, a);
342
+ };
343
+ }, [t]), l(() => n.setCustomLayers(!0), []), t ? P(e) ? e(o) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
344
+ }), Pt = g(function({ children: e }) {
345
+ const { editor: t } = v(), n = y(), [o, s] = m(!1), [c, r] = m({
346
+ title: /* @__PURE__ */ i(u, {}),
347
+ content: /* @__PURE__ */ i(u, {}),
348
+ attributes: {},
349
+ close: C
350
+ });
351
+ return l(() => {
352
+ if (!t)
353
+ return;
354
+ const a = "modal", d = ({ open: p, title: E, content: M, close: h, attributes: f }) => {
355
+ p && r({
356
+ title: b(q(E)),
357
+ content: b(q(M)),
358
+ attributes: f,
359
+ close: h
360
+ }), s(p);
361
+ };
362
+ return t.on(a, d), () => {
363
+ t.off(a, d);
364
+ };
365
+ }, [t]), l(() => n.setCustomModal(!0), []), t ? typeof e == "function" ? e({ open: o, ...c }) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
366
+ }), Mt = g(function({ children: e }) {
367
+ const { editor: t } = v(), [n, o] = m(() => ({
368
+ pages: [],
369
+ selected: void 0,
370
+ select: C,
371
+ add: C,
372
+ remove: C
373
+ }));
374
+ return l(() => {
375
+ if (!t)
376
+ return;
377
+ const { Pages: s } = t, c = s.events.all, r = () => {
378
+ o({
379
+ pages: s.getAll(),
380
+ selected: s.getSelected(),
381
+ select: (...a) => s.select(...a),
382
+ add: (...a) => s.add(...a),
383
+ remove: (...a) => s.remove(...a)
384
+ });
385
+ };
386
+ return t.on(c, r), r(), () => {
387
+ t.off(c, r);
388
+ };
389
+ }, [t]), t ? P(e) ? e(n) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
390
+ }), wt = g(function({ children: e }) {
391
+ const { editor: t } = v(), n = y(), [o, s] = m(() => ({
392
+ selectors: [],
393
+ states: [],
394
+ selectedState: "",
395
+ targets: [],
396
+ addSelector: C,
397
+ removeSelector: C,
398
+ setState: C,
399
+ Container: () => /* @__PURE__ */ i(u, {})
400
+ }));
401
+ return l(() => {
402
+ if (!t)
403
+ return;
404
+ const { Selectors: c } = t, r = c.events.custom, a = ({ container: d }) => {
405
+ s({
406
+ selectors: c.getSelected(),
407
+ states: c.getStates(),
408
+ selectedState: c.getState(),
409
+ targets: c.getSelectedTargets().map((p) => p.getSelectorsString()),
410
+ addSelector: (...p) => c.addSelected(...p),
411
+ removeSelector: (...p) => c.removeSelected(...p),
412
+ setState: (...p) => c.setState(...p),
413
+ Container: O(d)
414
+ });
415
+ };
416
+ return t.on(r, a), () => {
417
+ t.off(r, a);
418
+ };
419
+ }, [t]), l(() => n.setCustomSelectors(!0), []), t ? P(e) ? e(o) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
420
+ }), Ot = g(function({ children: e }) {
421
+ const { editor: t } = v(), n = y(), [o, s] = m(() => ({
422
+ sectors: [],
423
+ Container: () => /* @__PURE__ */ i(u, {})
424
+ }));
425
+ return l(() => {
426
+ if (!t)
427
+ return;
428
+ const { Styles: c } = t, r = c.events.custom, a = ({ container: d }) => {
429
+ s({
430
+ sectors: c.getSectors({ visible: !0 }),
431
+ Container: O(d)
432
+ });
433
+ };
434
+ return t.on(r, a), () => {
435
+ t.off(r, a);
436
+ };
437
+ }, [t]), l(() => n.setCustomStyles(!0), []), t ? P(e) ? e(o) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
438
+ }), kt = g(function({ children: e }) {
439
+ const { editor: t } = v(), n = y(), [o, s] = m(() => ({
440
+ traits: [],
441
+ Container: () => /* @__PURE__ */ i(u, {})
442
+ }));
443
+ return l(() => {
444
+ if (!t)
445
+ return;
446
+ const { Traits: c } = t, r = c.events.custom, a = ({ container: d }) => {
447
+ s({
448
+ traits: c.getCurrent(),
449
+ Container: O(d)
450
+ });
451
+ };
452
+ return t.on(r, a), c.__trgCustom(), () => {
453
+ t.off(r, a);
454
+ };
455
+ }, [t]), l(() => n.setCustomTraits(!0), []), t ? P(e) ? e(o) : /* @__PURE__ */ i(u, {}) : /* @__PURE__ */ i(u, {});
456
+ }), xt = ({ children: e }) => et() ? /* @__PURE__ */ i(u, { children: e }) : /* @__PURE__ */ i(u, {});
457
+ export {
458
+ vt as AssetsProvider,
459
+ St as BlocksProvider,
460
+ Ct as Canvas,
461
+ yt as DevicesProvider,
462
+ Et as Editor,
463
+ ht as LayersProvider,
464
+ Pt as ModalProvider,
465
+ Mt as PagesProvider,
466
+ wt as SelectorsProvider,
467
+ Ot as StylesProvider,
468
+ kt as TraitsProvider,
469
+ xt as WithEditor,
470
+ Et as default,
471
+ gt as useEditor,
472
+ et as useEditorMaybe
473
+ };
@@ -0,0 +1,15 @@
1
+ export declare const isDef: (value: any) => boolean;
2
+ export declare const isString: (value: any) => value is string;
3
+ export declare const prevent: (ev?: Event) => void | undefined;
4
+ export declare const stop: (ev?: Event) => void | undefined;
5
+ export declare const loadStyle: (href: string) => Promise<void>;
6
+ type ScriptToLoad = {
7
+ id: string;
8
+ src: string;
9
+ };
10
+ export declare const loadScript: (src: string | ScriptToLoad) => Promise<string>;
11
+ export declare const loadScripts: (scripts: {
12
+ id: string;
13
+ src: string;
14
+ }[]) => Promise<PromiseSettledResult<string>[]>;
15
+ export {};
@@ -0,0 +1,7 @@
1
+ type ClassNameInput = string | number | boolean | null | undefined;
2
+ type ClassNameInputs = ClassNameInput | Array<ClassNameInput>;
3
+ export declare function cx(...inputs: ClassNameInputs[]): string;
4
+ export declare function isFunction(value: any): value is Function;
5
+ export declare function noop(): void;
6
+ export declare function useTraceUpdate(props: Record<string, any>): void;
7
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Plugin, PluginOptions } from 'grapesjs';
2
+ export type GrapesPlugins = string | Plugin<any>;
3
+ export type PluginTypeToLoad = GrapesPlugins | PluginToLoad | false | null | undefined;
4
+ export type PluginToLoad = {
5
+ id: string;
6
+ src: string;
7
+ options?: PluginOptions;
8
+ };
9
+ export declare function loadPlugins(plugins: PluginToLoad[]): Promise<{
10
+ loaded: PluginToLoad[];
11
+ failed: PluginToLoad[];
12
+ }>;
13
+ export declare const initPlugins: (plugins: PluginTypeToLoad[]) => Promise<{
14
+ plugins: GrapesPlugins[];
15
+ pluginOptions: PluginOptions;
16
+ }>;
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ export declare const WrapDom: (el: HTMLElement | string) => () => import("react/jsx-runtime").JSX.Element;
3
+ export interface PortalContainerProps {
4
+ children: ReactNode;
5
+ }
6
+ export type PortalContainerResult = (props: PortalContainerProps) => ReactNode | any;
7
+ export declare function portalContainer(el?: HTMLElement): PortalContainerResult;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@leochen0204/grapesjs-react",
3
+ "version": "2.0.0-react17-rc.0",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org"
6
+ },
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "main": "./dist/index.cjs.js",
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/leochen0204/grapesjs-react.git"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "dev": "tsc && vite build --watch",
26
+ "build": "tsc && vite build",
27
+ "build-watch": "tsc && vite build --watch",
28
+ "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
29
+ "preview": "vite preview"
30
+ },
31
+ "devDependencies": {
32
+ "@types/react": "^17.0.0",
33
+ "@types/react-dom": "^17.0.0",
34
+ "react": "^17.0.2",
35
+ "react-dom": "^17.0.2"
36
+ },
37
+ "peerDependencies": {
38
+ "grapesjs": "^0.22.5",
39
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
40
+ "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
41
+ }
42
+ }