Skip to content

Commit 806ae3f

Browse files
committedApr 7, 2023
first commit
0 parents  commit 806ae3f

36 files changed

+2747
-0
lines changed
 

‎.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
package-lock.json
25+
.DS_Store
26+
.idea

‎README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

‎package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "react-grapesjs",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@popperjs/core": "^2.9.3",
7+
"axios": "^0.21.1",
8+
"bootstrap": "^5.1.1",
9+
"chart.js": "^3.8.2",
10+
"grapesjs": "^0.17.22",
11+
"grapesjs-blocks-basic": "^0.1.8",
12+
"grapesjs-blocks-bootstrap4": "^0.2.3",
13+
"grapesjs-plugin-export": "^1.0.7",
14+
"grapesjs-style-bg": "^1.0.5",
15+
"jquery": "^3.6.0",
16+
"react": "^17.0.2",
17+
"react-bootstrap": "^2.0.0-rc.1",
18+
"react-dom": "^17.0.2",
19+
"react-redux": "^7.2.5",
20+
"react-router-dom": "^5.2.0",
21+
"react-scripts": "^5.0.1",
22+
"redux": "^4.1.1",
23+
"redux-devtools-extension": "^2.13.9",
24+
"redux-thunk": "^2.3.0",
25+
"sass": "^1.49.7",
26+
"web-vitals": "^1.1.2"
27+
},
28+
"scripts": {
29+
"start": "react-scripts start",
30+
"build": "react-scripts build",
31+
"test": "react-scripts test",
32+
"eject": "react-scripts eject"
33+
},
34+
"eslintConfig": {
35+
"extends": [
36+
"react-app",
37+
"react-app/jest"
38+
]
39+
},
40+
"browserslist": {
41+
"production": [
42+
">0.2%",
43+
"not dead",
44+
"not op_mini all"
45+
],
46+
"development": [
47+
"last 1 chrome version",
48+
"last 1 firefox version",
49+
"last 1 safari version"
50+
]
51+
}
52+
}

‎public/favicon.ico

3.78 KB
Binary file not shown.

‎public/index.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>React App</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

‎public/logo192.png

5.22 KB
Loading

‎public/logo512.png

9.44 KB
Loading

‎public/manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

‎public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

‎src/App.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { useEffect } from "react";
2+
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
3+
import { useDispatch } from "react-redux";
4+
import Home from "./Home";
5+
import Editor from "./Editor";
6+
import { pageLoad } from "./redux/actions/pageAction";
7+
8+
function App() {
9+
const dispatch = useDispatch();
10+
11+
useEffect(() => {
12+
pageLoad()(dispatch);
13+
}, [dispatch]);
14+
15+
return (
16+
<Router>
17+
<Switch>
18+
<Route exact path="/" component={Home}></Route>
19+
<Route exact path="/editor/:pageId" component={Editor}></Route>
20+
</Switch>
21+
</Router>
22+
);
23+
}
24+
25+
export default App;

‎src/Editor.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, { useEffect, useState } from "react";
2+
import { useParams } from "react-router-dom";
3+
import axios from "axios";
4+
import { useSelector } from "react-redux";
5+
import { API_HOST } from "./api_utils";
6+
import Sidebar from "./components/Sidebar";
7+
import TopNav from "./components/TopNav";
8+
import geditorConfig from "./api_utils/geditor_config";
9+
import PageSection from "./components/PageSection";
10+
11+
const Editor = () => {
12+
const [editor, setEditor] = useState(null);
13+
const [assets, setAssets] = useState([]);
14+
const { pageId } = useParams();
15+
16+
const { pageStore } = useSelector((state) => state);
17+
const { pages } = pageStore;
18+
19+
useEffect(() => {
20+
async function getAllAssets() {
21+
try {
22+
const response = await axios.get(`${API_HOST}assets/`);
23+
setAssets(response.data);
24+
} catch (error) {
25+
setAssets(error.message);
26+
}
27+
}
28+
29+
getAllAssets();
30+
}, []);
31+
32+
useEffect(() => {
33+
const editor = geditorConfig(assets, pageId);
34+
setEditor(editor);
35+
}, [pageId, assets]);
36+
return (
37+
<div className="App">
38+
<div
39+
id="navbar"
40+
className="sidenav d-flex flex-column overflow-scroll position-fixed"
41+
>
42+
<nav className="navbar navbar-light">
43+
<div className="container-fluid">
44+
<span className="navbar-brand mb-0 h3 logo">Code Dexterous</span>
45+
</div>
46+
</nav>
47+
<PageSection pages={pages} />
48+
<Sidebar />
49+
</div>
50+
<div
51+
className="main-content position-relative w-85 start-15"
52+
id="main-content"
53+
>
54+
<TopNav />
55+
<div id="editor"></div>
56+
</div>
57+
</div>
58+
);
59+
};
60+
61+
export default Editor;

‎src/Home.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useState } from "react";
2+
import { Link } from "react-router-dom";
3+
import { useSelector, useDispatch } from "react-redux";
4+
import { createPage } from "./redux/actions/pageAction";
5+
6+
const Home = () => {
7+
const [name, setName] = useState("");
8+
const [isValid, setIsValid] = useState(true);
9+
const dispatch = useDispatch();
10+
11+
const { pageStore } = useSelector((state) => state);
12+
const { pages } = pageStore;
13+
14+
const handleSubmit = async () => {
15+
if (!name) {
16+
setIsValid(false);
17+
return;
18+
}
19+
createPage(name)(dispatch);
20+
};
21+
22+
return (
23+
<div className="container">
24+
<div className="row">
25+
<div className="col-12 mt-5">
26+
<form id="create-page">
27+
<div className="modal-header">
28+
<h5 className="modal-title" id="addPageModalLabel">
29+
Create Page
30+
</h5>
31+
</div>
32+
<div className="modal-body">
33+
<div className="col-auto">
34+
<label htmlFor="name" className="form-label">
35+
Name
36+
</label>
37+
<input
38+
type="text"
39+
className={`form-control form-control-sm ${
40+
isValid ? "" : "is-invalid"
41+
}`}
42+
id="name"
43+
name="name"
44+
placeholder="Name of Page"
45+
value={name}
46+
onChange={(e) => setName(e.target.value)}
47+
/>
48+
{!isValid && (
49+
<div className="invalid-feedback">
50+
Please provide a valid name.
51+
</div>
52+
)}
53+
</div>
54+
</div>
55+
<div className="modal-footer">
56+
<button
57+
type="button"
58+
className="btn btn-secondary btn-sm"
59+
data-bs-dismiss="modal"
60+
>
61+
Clear
62+
</button>
63+
<button
64+
type="button"
65+
className="btn btn-primary btn-sm"
66+
onClick={handleSubmit}
67+
>
68+
Save
69+
</button>
70+
</div>
71+
</form>
72+
</div>
73+
<div className="col-12 my-2">
74+
<table className="table table-bordered table-hover">
75+
<thead>
76+
<tr>
77+
<td>ID</td>
78+
<td>Name</td>
79+
<td>Slug</td>
80+
<td>Action</td>
81+
</tr>
82+
</thead>
83+
<tbody>
84+
{pages
85+
? pages.map((page) => (
86+
<tr key={page._id}>
87+
<td>{page._id}</td>
88+
<td>{page.name}</td>
89+
<td>{page.slug}</td>
90+
<td>
91+
<Link to={`/editor/${page._id}`}>Edit</Link>
92+
</td>
93+
</tr>
94+
))
95+
: "No Page"}
96+
</tbody>
97+
</table>
98+
</div>
99+
</div>
100+
</div>
101+
);
102+
};
103+
104+
export default Home;

‎src/api_utils/geditor_config.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import grapesjs from "grapesjs";
2+
import gjsBlockBasic from "grapesjs-blocks-basic";
3+
import $ from "jquery";
4+
import grapesjsBlockBootstrap from "grapesjs-blocks-bootstrap4";
5+
import grapesjsPluginExport from "grapesjs-plugin-export";
6+
import grapesjsStyleBg from "grapesjs-style-bg";
7+
8+
import {
9+
addEditorCommand,
10+
deviceManager,
11+
layerManager,
12+
panels,
13+
scripts,
14+
selectorManager,
15+
storageSetting,
16+
styleManager,
17+
styles,
18+
toggleSidebar,
19+
traitManager,
20+
} from "./geditor_utils";
21+
import tailwindComponent from "../plugins/tailwind";
22+
import swiperComponent from "../plugins/swiper";
23+
import chartLibComponent from "../plugins/charts";
24+
25+
const geditorConfig = (assets, pageId) => {
26+
$(".panel__devices").html("");
27+
$(".panel__basic-actions").html("");
28+
$(".panel__editor").html("");
29+
$("#blocks").html("");
30+
$("#styles-container").html("");
31+
$("#layers-container").html("");
32+
$("#trait-container").html("");
33+
34+
// Content for Preview
35+
const navbar = $("#navbar");
36+
const mainContent = $("#main-content");
37+
const panelTopBar = $("#main-content > .navbar-light");
38+
39+
const editor = grapesjs.init({
40+
container: "#editor",
41+
blockManager: {
42+
appendTo: "#blocks",
43+
},
44+
styleManager: styleManager,
45+
layerManager: layerManager,
46+
traitManager: traitManager,
47+
selectorManager: selectorManager,
48+
panels: panels,
49+
deviceManager: deviceManager,
50+
assetManager: { assets: assets, upload: false },
51+
storageManager: storageSetting(pageId),
52+
canvas: {
53+
styles: styles,
54+
scripts: scripts,
55+
},
56+
plugins: [
57+
tailwindComponent,
58+
gjsBlockBasic,
59+
swiperComponent,
60+
grapesjsBlockBootstrap,
61+
grapesjsPluginExport,
62+
grapesjsStyleBg,
63+
chartLibComponent,
64+
],
65+
pluginsOpts: {
66+
tailwindComponent: {},
67+
gjsBlockBasic: {},
68+
swiperComponent: {},
69+
grapesjsBlockBootstrap: {},
70+
grapesjsPluginExport: {},
71+
grapesjsStyleBg: {},
72+
chartLibComponent: {},
73+
},
74+
});
75+
76+
addEditorCommand(editor);
77+
editor.on("run:preview", () => {
78+
console.log("It will trigger when we click on preview icon");
79+
// This will be used to hide border
80+
editor.stopCommand("sw-visibility");
81+
// This will hide the sidebar view
82+
navbar.removeClass("sidebar");
83+
// This will make the main-content to be full width
84+
mainContent.removeClass("main-content");
85+
86+
// This will hide top panel where we have added the button
87+
panelTopBar.addClass("d-none");
88+
});
89+
editor.on("stop:preview", () => {
90+
// This event is reverse of the above event.
91+
console.log("It will trigger when we click on cancel preview icon");
92+
editor.runCommand("sw-visibility");
93+
navbar.addClass("sidebar");
94+
mainContent.addClass("main-content");
95+
panelTopBar.removeClass("d-none");
96+
});
97+
editor.on("component:selected", (component) => {
98+
const newTool = {
99+
icon: "fa fa-plus-square",
100+
title: "Check Toolbar",
101+
commandName: "new-tool-cmd",
102+
id: "new-tool",
103+
};
104+
105+
const defaultToolbar = component.get("toolbar");
106+
const checkAlreadyExist = defaultToolbar.find(
107+
(toolbar) => toolbar.command === newTool.commandName
108+
);
109+
if (!checkAlreadyExist) {
110+
defaultToolbar.unshift({
111+
id: newTool.id,
112+
attributes: { class: newTool.icon, title: newTool.title },
113+
command: newTool.commandName,
114+
});
115+
component.set("toolbar", defaultToolbar);
116+
}
117+
});
118+
119+
setTimeout(() => {
120+
let categories = editor.BlockManager.getCategories();
121+
categories.each((category) => category.set("open", false));
122+
}, 1000);
123+
return editor;
124+
};
125+
126+
export default geditorConfig;

‎src/api_utils/geditor_utils.js

+588
Large diffs are not rendered by default.

‎src/api_utils/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const API_HOST = "http://localhost:4000/api/";

‎src/components/PageDetail.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Link } from "react-router-dom";
2+
import axios from "axios";
3+
import { API_HOST } from "../api_utils";
4+
5+
6+
function PageDetail({ page }) {
7+
const { name } = page;
8+
const handleDelete =async (e)=>{
9+
e.preventDefault();
10+
const response = await axios.delete(`${API_HOST}pages/${page._id}`);
11+
console.log(response.status);
12+
if(response.status === 200){
13+
await axios.get(`${API_HOST}pages`);
14+
}
15+
}
16+
return (
17+
<li className="list-group-item d-flex justify-content-between align-items-center">
18+
<Link className="text-decoration-none" to={`/editor/${page._id}`}>
19+
{name}
20+
</Link>
21+
<div>
22+
<button className="btn btn-sm btn-outline-primary">
23+
<i className="fa fa-pencil"></i>
24+
</button>
25+
<button className="btn btn-sm btn-outline-danger" onClick={(e)=>handleDelete(e)}>
26+
<i className="fa fa-trash"></i>
27+
</button>
28+
</div>
29+
</li>
30+
);
31+
}
32+
33+
export default PageDetail;

‎src/components/PageSection.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { useState, useReducer } from "react";
2+
import { useDispatch } from "react-redux";
3+
import { Modal, Button } from "react-bootstrap";
4+
import { createPage } from "../redux/actions/pageAction";
5+
import PageDetail from "./PageDetail";
6+
7+
export default function PageSection({ pages }) {
8+
const [show, setShow] = useReducer((show) => !show, false);
9+
const [name, setName] = useState("");
10+
const [isValid, setIsValid] = useState(true);
11+
const [error, setError] = useState("");
12+
13+
const dispatch = useDispatch();
14+
15+
const handleSubmit = async () => {
16+
if (!name) {
17+
setIsValid(false);
18+
return;
19+
} else {
20+
createPage(name)(dispatch);
21+
closeModal();
22+
}
23+
};
24+
25+
const closeModal = () => {
26+
setName("");
27+
setError("");
28+
setShow();
29+
};
30+
return (
31+
<div className="my-2 d-flex flex-column">
32+
<button
33+
type="button"
34+
className="btn btn-outline-secondary btn-sm mb-2 mx-2"
35+
onClick={() => setShow(!show)}
36+
>
37+
<i className="fa fa-plus"></i>
38+
Add Page
39+
</button>
40+
<form id="create-page">
41+
<Modal
42+
show={show}
43+
onHide={setShow}
44+
backdrop="static"
45+
keyboard={false}
46+
aria-labelledby="contained-modal-title-vcenter"
47+
centered
48+
>
49+
<Modal.Header closeButton>
50+
<Modal.Title>Create Page</Modal.Title>
51+
</Modal.Header>
52+
<Modal.Body>
53+
<div className="col-auto">
54+
<label htmlFor="name" className="form-label">
55+
Name
56+
</label>
57+
<input
58+
type="text"
59+
className={`form-control form-control-sm ${
60+
isValid ? "" : "is-invalid"
61+
}`}
62+
id="name"
63+
name="name"
64+
placeholder="Name of Page"
65+
value={name}
66+
onChange={(e) => setName(e.target.value)}
67+
/>
68+
{!isValid && (
69+
<div className="invalid-feedback">
70+
Please provide a valid name.
71+
</div>
72+
)}
73+
</div>
74+
</Modal.Body>
75+
<Modal.Footer>
76+
<Button variant="secondary" onClick={closeModal}>
77+
Close
78+
</Button>
79+
<Button variant="primary" onClick={handleSubmit}>
80+
Save Changes
81+
</Button>
82+
</Modal.Footer>
83+
</Modal>
84+
</form>
85+
<ul className="list-group pages">
86+
{pages.map((page) => (
87+
<PageDetail page={page} key={page._id} />
88+
))}
89+
</ul>
90+
</div>
91+
);
92+
}

‎src/components/Sidebar.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
function Sidebar() {
2+
return (
3+
<>
4+
<ul className="nav nav-tabs" id="myTab" role="tablist">
5+
<li className="nav-item" role="presentation">
6+
<button
7+
className="nav-link active"
8+
id="block-tab"
9+
data-bs-toggle="tab"
10+
data-bs-target="#block"
11+
type="button"
12+
role="tab"
13+
aria-controls="block"
14+
aria-selected="true"
15+
>
16+
<i className="fa fa-cubes"></i>
17+
</button>
18+
</li>
19+
<li className="nav-item" role="presentation">
20+
<button
21+
className="nav-link"
22+
id="layer-tab"
23+
data-bs-toggle="tab"
24+
data-bs-target="#layer"
25+
type="button"
26+
role="tab"
27+
aria-controls="layer"
28+
aria-selected="false"
29+
>
30+
<i className="fa fa-tasks"></i>
31+
</button>
32+
</li>
33+
<li className="nav-item" role="presentation">
34+
<button
35+
className="nav-link"
36+
id="style-tab"
37+
data-bs-toggle="tab"
38+
data-bs-target="#style"
39+
type="button"
40+
role="tab"
41+
aria-controls="style"
42+
aria-selected="false"
43+
>
44+
<i className="fa fa-paint-brush"></i>
45+
</button>
46+
</li>
47+
<li className="nav-item" role="presentation">
48+
<button
49+
className="nav-link"
50+
id="trait-tab"
51+
data-bs-toggle="tab"
52+
data-bs-target="#trait"
53+
type="button"
54+
role="tab"
55+
aria-controls="trait"
56+
aria-selected="false"
57+
>
58+
<i className="fa fa-cog"></i>
59+
</button>
60+
</li>
61+
</ul>
62+
<div className="tab-content">
63+
<div
64+
className="tab-pane fade show active"
65+
id="block"
66+
role="tabpanel"
67+
aria-labelledby="block-tab"
68+
>
69+
<div id="blocks"></div>
70+
</div>
71+
<div
72+
className="tab-pane fade"
73+
id="layer"
74+
role="tabpanel"
75+
aria-labelledby="layer-tab"
76+
>
77+
<div id="layers-container"></div>
78+
</div>
79+
<div
80+
className="tab-pane fade"
81+
id="style"
82+
role="tabpanel"
83+
aria-labelledby="style-tab"
84+
>
85+
<div id="styles-container"></div>
86+
</div>
87+
<div
88+
className="tab-pane fade"
89+
id="trait"
90+
role="tabpanel"
91+
aria-labelledby="trait-tab"
92+
>
93+
<div id="trait-container"></div>
94+
</div>
95+
</div>
96+
</>
97+
);
98+
}
99+
100+
export default Sidebar;

‎src/components/TopNav.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { toggleSidebar } from "../api_utils/geditor_utils";
2+
3+
function TopNav() {
4+
const handleClick = () => {
5+
toggleSidebar(false);
6+
};
7+
return (
8+
<nav className="navbar navbar-light">
9+
<div className="container">
10+
<button
11+
className="btn btn-sm btn-outline-primary"
12+
onClick={handleClick}
13+
>
14+
<i className="fa fa-bars"></i>
15+
</button>
16+
<div className="panel__devices"></div>
17+
<div className="panel__editor"></div>
18+
<div className="panel__basic-actions"></div>
19+
</div>
20+
</nav>
21+
);
22+
}
23+
24+
export default TopNav;

‎src/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import "grapesjs/dist/css/grapes.min.css";
4+
import "bootstrap";
5+
import App from "./App";
6+
import "./styles/main.scss";
7+
import reportWebVitals from "./reportWebVitals";
8+
import DataProvider from "./redux/store";
9+
10+
ReactDOM.render(
11+
<React.StrictMode>
12+
<DataProvider>
13+
<App />
14+
</DataProvider>
15+
</React.StrictMode>,
16+
document.getElementById("root")
17+
);
18+
19+
reportWebVitals();

‎src/plugins/charts/components.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import LineChart, { LineChartBlock } from "./components/LineChart";
2+
export default (editor, opts = {}) => {
3+
const dc = editor.DomComponents;
4+
const bm = editor.BlockManager;
5+
const { blocks, labels, types, labelChartCategory } = opts;
6+
7+
if (blocks.lineChart) {
8+
LineChartBlock(bm, labelChartCategory, labels.lineChart, types.lineChart);
9+
LineChart(dc, labels.lineChart, types.lineChart, opts);
10+
}
11+
};
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const Chart = require("chart.js");
2+
export const LineChartBlock = (bm, category, label, type) => {
3+
bm.add(type, {
4+
label,
5+
category,
6+
content: `<canvas id="lineChart" data-gjs-type="lineChart"></canvas>`,
7+
});
8+
};
9+
export default (dc, label, type, config) => {
10+
const defaultType = dc.getType("default");
11+
const defaultModel = defaultType.model;
12+
const defaultView = defaultType.view;
13+
dc.addType(type, {
14+
model: {
15+
defaults: {
16+
script: function () {
17+
const initLib = function () {
18+
const labels = [
19+
"January",
20+
"February",
21+
"March",
22+
"April",
23+
"May",
24+
"June",
25+
];
26+
const data = {
27+
labels: labels,
28+
datasets: [
29+
{
30+
label: "My First dataset",
31+
backgroundColor: "rgb(255, 99, 132)",
32+
borderColor: "rgb(255, 99, 132)",
33+
data: [0, 10, 5, 2, 20, 30, 45],
34+
},
35+
],
36+
};
37+
38+
const config = {
39+
type: "line",
40+
data: data,
41+
options: {},
42+
};
43+
44+
const ctx = document.getElementById("lineChart").getContext("2d");
45+
const myChart = new Chart(ctx, config);
46+
};
47+
if (typeof Chart == "undefined") {
48+
const script = document.createElement("script");
49+
script.onload = initLib;
50+
script.src = "https://cdn.jsdelivr.net/npm/chart.js";
51+
document.body.appendChild(script);
52+
} else {
53+
console.log("InitLib");
54+
initLib();
55+
}
56+
},
57+
},
58+
},
59+
isComponent: (el) => {
60+
if (el.getAttribute && el.getAttribute("data-gjs-type") == type) {
61+
return { type };
62+
}
63+
},
64+
view: defaultView.extend({
65+
init({ model }) {},
66+
}),
67+
});
68+
};

‎src/plugins/charts/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import grapesjs from "grapesjs";
2+
import loadComponents from "./components";
3+
4+
export default grapesjs.plugins.add("charts", (editor, opts = {}) => {
5+
let default_blocks = {
6+
lineChart: true,
7+
};
8+
let default_labels = {
9+
lineChart: "Line Chart",
10+
};
11+
let default_types = {
12+
lineChart: "lineChart",
13+
};
14+
15+
let options = {
16+
...{
17+
blocks: default_blocks,
18+
labels: default_labels,
19+
types: default_types,
20+
labelChartCategory: "Charts",
21+
},
22+
...opts,
23+
};
24+
loadComponents(editor, options);
25+
});

‎src/plugins/swiper/blocks.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* eslint-disable import/no-anonymous-default-export */
2+
export default (editor, opts = {}) => {
3+
const bm = editor.BlockManager;
4+
const style = `<style>
5+
.swiper-container {
6+
width: 600px;
7+
height: 300px;
8+
}
9+
.swiper-slide {
10+
text-align: center;
11+
font-size: 18px;
12+
background: #fff;
13+
14+
/* Center slide text vertically */
15+
display: -webkit-box;
16+
display: -ms-flexbox;
17+
display: -webkit-flex;
18+
display: flex;
19+
-webkit-box-pack: center;
20+
-ms-flex-pack: center;
21+
-webkit-justify-content: center;
22+
justify-content: center;
23+
-webkit-box-align: center;
24+
-ms-flex-align: center;
25+
-webkit-align-items: center;
26+
align-items: center;
27+
}
28+
29+
.swiper-slide img {
30+
display: block;
31+
width: 100%;
32+
height: 100%;
33+
object-fit: cover;
34+
}
35+
</style>
36+
`;
37+
bm.add(opts.name, {
38+
label: `
39+
<i class="fa fa-arrows-h"></i>
40+
<div class="gjs-block-label">
41+
${opts.label}
42+
</div>
43+
`,
44+
category: opts.category,
45+
content: `<div class="swiper-container mySwiper">
46+
<div class="swiper-wrapper">
47+
<div class="swiper-slide">Slide 1</div>
48+
<div class="swiper-slide">Slide 2</div>
49+
<div class="swiper-slide">Slide 3</div>
50+
<div class="swiper-slide">Slide 4</div>
51+
<div class="swiper-slide">Slide 5</div>
52+
</div>
53+
54+
<div class="swiper-button-next"></div>
55+
<div class="swiper-button-prev"></div>
56+
<div class="swiper-pagination"></div>
57+
58+
</div> ${style}`,
59+
});
60+
};

‎src/plugins/swiper/components.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* eslint-disable no-undef */
2+
/* eslint-disable import/no-anonymous-default-export */
3+
4+
export default (editor, opts = {}) => {
5+
const dc = editor.DomComponents;
6+
const defaultType = dc.getType("default");
7+
const defaultView = defaultType.view;
8+
9+
dc.addType(opts.name, {
10+
model: {
11+
defaults: {
12+
traits: [
13+
{
14+
type: "checkbox",
15+
name: "dynamicProgress",
16+
label: "Dynamic Progress",
17+
changeProp: 1,
18+
},
19+
{
20+
type: "select",
21+
name: "progressType",
22+
label: "Progress Type",
23+
changeProp: 1,
24+
options: [
25+
{ value: "bullets", name: "Bullets" },
26+
{ value: "fraction", name: "Fraction" },
27+
{ value: "progressbar", name: "Progressbar" },
28+
],
29+
},
30+
],
31+
script: function () {
32+
const dynamicProgress = "{[ dynamicProgress ]}";
33+
const progressType = "{[ progressType ]}";
34+
35+
const initLib = function () {
36+
const swiper = new Swiper(".mySwiper", {
37+
spaceBetween: 30,
38+
centeredSlides: true,
39+
autoplay: {
40+
delay: 2500,
41+
disableOnInteraction: false,
42+
},
43+
pagination: {
44+
el: ".swiper-pagination",
45+
clickable: true,
46+
dynamicBullets: !!dynamicProgress,
47+
type: progressType,
48+
},
49+
navigation: {
50+
nextEl: ".swiper-button-next",
51+
prevEl: ".swiper-button-prev",
52+
},
53+
});
54+
console.log("swiper :>> ", swiper);
55+
};
56+
57+
if (typeof Swiper == "undefined") {
58+
const script = document.createElement("script");
59+
script.onload = initLib;
60+
script.src = "https://unpkg.com/swiper@7/swiper-bundle.min.js";
61+
document.body.appendChild(script);
62+
} else {
63+
initLib();
64+
}
65+
},
66+
},
67+
},
68+
69+
isComponent: (el) => {
70+
if (el.className && el.className.includes("swiper-container")) {
71+
return {
72+
type: opts.name,
73+
};
74+
}
75+
},
76+
77+
view: defaultView.extend({
78+
init({ model }) {
79+
this.listenTo(model, "change:dynamicProgress", this.updateScript);
80+
this.listenTo(model, "change:progressType", this.updateScript);
81+
},
82+
}),
83+
});
84+
};

‎src/plugins/swiper/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import grapesjs from "grapesjs";
2+
import loadComponents from "./components";
3+
import loadBlocks from "./blocks";
4+
5+
export default grapesjs.plugins.add("swiperComponent", (editor, opts = {}) => {
6+
let options = {
7+
label: "Swiper",
8+
name: "cswiper",
9+
category: "Custom",
10+
};
11+
for (let name in options) {
12+
if (!(name in opts)) opts[name] = options[name];
13+
}
14+
15+
loadBlocks(editor, options);
16+
loadComponents(editor, opts);
17+
});

‎src/plugins/tailwind/components.js

+334
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
import {
2+
backgroundAttachment,
3+
backgroundClip,
4+
bgColor,
5+
bgRepeat,
6+
bgSize,
7+
borderColor,
8+
borderRadius,
9+
borderStyle,
10+
borderWidth,
11+
fontVariant,
12+
fontWeight,
13+
letterSpacing,
14+
lineHeight,
15+
tableBorder,
16+
tableLayout,
17+
textAlignment,
18+
textColor,
19+
textDecoration,
20+
textFontSize,
21+
textOpacity,
22+
textOverflow,
23+
textTransformation,
24+
verticalAlign,
25+
wordBreak,
26+
} from "./tailwind_classes";
27+
28+
/* eslint-disable import/no-anonymous-default-export */
29+
export default (editor, opts = {}) => {
30+
const dc = editor.DomComponents;
31+
32+
dc.getTypes().forEach((type) => {
33+
if (type.id === "text" || type.id === "link") {
34+
dc.addType(type.id, {
35+
model: {
36+
defaults: {
37+
traits: [
38+
...type.model.prototype.defaults.traits,
39+
{
40+
type: "class_select",
41+
options: textColor.map((color) => ({
42+
name: color,
43+
value: color,
44+
})),
45+
label: "Text Color",
46+
},
47+
{
48+
type: "class_select",
49+
options: textAlignment.map((color) => ({
50+
name: color,
51+
value: color,
52+
})),
53+
label: "Text Alignment",
54+
},
55+
{
56+
type: "class_select",
57+
options: textOpacity.map((color) => ({
58+
name: color,
59+
value: color,
60+
})),
61+
label: "Text Opacity",
62+
},
63+
{
64+
type: "class_select",
65+
options: textDecoration.map((color) => ({
66+
name: color,
67+
value: color,
68+
})),
69+
label: "Text Decoration",
70+
},
71+
{
72+
type: "class_select",
73+
options: textTransformation.map((color) => ({
74+
name: color,
75+
value: color,
76+
})),
77+
label: "Text Transformation",
78+
},
79+
{
80+
type: "class_select",
81+
options: textOverflow.map((color) => ({
82+
name: color,
83+
value: color,
84+
})),
85+
label: "Text Overflow",
86+
},
87+
{
88+
type: "class_select",
89+
options: textFontSize.map((color) => ({
90+
name: color,
91+
value: color,
92+
})),
93+
label: "Font Size",
94+
},
95+
{
96+
type: "class_select",
97+
options: fontWeight.map((color) => ({
98+
name: color,
99+
value: color,
100+
})),
101+
label: "Font Weight",
102+
},
103+
{
104+
type: "class_select",
105+
options: fontVariant.map((color) => ({
106+
name: color,
107+
value: color,
108+
})),
109+
label: "Font Variant",
110+
},
111+
{
112+
type: "class_select",
113+
options: letterSpacing.map((color) => ({
114+
name: color,
115+
value: color,
116+
})),
117+
label: "Letter Spacing",
118+
},
119+
{
120+
type: "class_select",
121+
options: lineHeight.map((color) => ({
122+
name: color,
123+
value: color,
124+
})),
125+
label: "Line Height",
126+
},
127+
{
128+
type: "class_select",
129+
options: verticalAlign.map((color) => ({
130+
name: color,
131+
value: color,
132+
})),
133+
label: "Vertical Align",
134+
},
135+
{
136+
type: "class_select",
137+
options: wordBreak.map((color) => ({
138+
name: color,
139+
value: color,
140+
})),
141+
label: "Word Break",
142+
},
143+
],
144+
},
145+
},
146+
});
147+
}
148+
149+
if (type.id === "table") {
150+
dc.addType(type.id, {
151+
model: {
152+
defaults: {
153+
traits: [
154+
...type.model.prototype.defaults.traits,
155+
{
156+
type: "class_select",
157+
options: tableBorder.map((color) => ({
158+
name: color,
159+
value: color,
160+
})),
161+
label: "Table Border",
162+
},
163+
{
164+
type: "class_select",
165+
options: tableLayout.map((color) => ({
166+
name: color,
167+
value: color,
168+
})),
169+
label: "Table Layout",
170+
},
171+
],
172+
},
173+
},
174+
});
175+
}
176+
177+
const toolbar = [
178+
{
179+
attributes: {
180+
class: "fa fa-arrow-up",
181+
},
182+
command: (e) => e.runCommand("core:component-exit", { force: 1 }),
183+
},
184+
{
185+
attributes: {
186+
class: "fa fa-arrows gjs-no-touch-actions",
187+
draggable: true,
188+
},
189+
command: "tld-move",
190+
},
191+
192+
{
193+
attributes: {
194+
class: "fa fa-clone",
195+
},
196+
command: "tlb-clone",
197+
},
198+
{
199+
attributes: {
200+
class: "fa fa-trash-o",
201+
},
202+
command: "tlb-delete",
203+
},
204+
{
205+
attributes: {
206+
class: "fa fa-gear",
207+
},
208+
command: (e) => {
209+
console.log("Another way to add toolbar");
210+
alert("Another way to add toolbar");
211+
},
212+
},
213+
];
214+
215+
if (type.id === "svg" || type.id === "svg-in") {
216+
dc.addType(type.id, {
217+
model: {
218+
defaults: {
219+
traits: [
220+
...dc.getType(type.id).model.prototype.defaults.traits,
221+
{
222+
type: "class_select",
223+
options: [{ name: "fill-current", value: "fill-current" }],
224+
label: "Fill",
225+
},
226+
{
227+
type: "class_select",
228+
options: [{ name: "stroke-current", value: "stroke-current" }],
229+
label: "Stroke",
230+
},
231+
{
232+
type: "class_select",
233+
options: [
234+
{ name: "stroke-0", value: "stroke-0" },
235+
{ name: "stroke-1", value: "stroke-1" },
236+
{ name: "stroke-2", value: "stroke-2" },
237+
],
238+
label: "Stroke Width",
239+
},
240+
],
241+
},
242+
},
243+
});
244+
}
245+
246+
let defaultTraits = [];
247+
if (dc.getType(type.id).model.prototype.defaults.traits) {
248+
defaultTraits = dc.getType(type.id).model.prototype.defaults.traits;
249+
}
250+
dc.addType(type.id, {
251+
model: {
252+
defaults: {
253+
toolbar,
254+
traits: [
255+
...defaultTraits,
256+
{
257+
type: "class_select",
258+
options: backgroundAttachment.map((color) => ({
259+
name: color,
260+
value: color,
261+
})),
262+
label: "BG Attachment",
263+
},
264+
{
265+
type: "class_select",
266+
options: backgroundClip.map((color) => ({
267+
name: color,
268+
value: color,
269+
})),
270+
label: "BG Clip",
271+
},
272+
{
273+
type: "class_select",
274+
options: bgColor.map((color) => ({
275+
name: color,
276+
value: color,
277+
})),
278+
label: "BG Color",
279+
},
280+
{
281+
type: "class_select",
282+
options: bgRepeat.map((color) => ({
283+
name: color,
284+
value: color,
285+
})),
286+
label: "BG Repeat",
287+
},
288+
{
289+
type: "class_select",
290+
options: bgSize.map((color) => ({
291+
name: color,
292+
value: color,
293+
})),
294+
label: "BG Size",
295+
},
296+
297+
{
298+
type: "class_select",
299+
options: borderRadius.map((color) => ({
300+
name: color,
301+
value: color,
302+
})),
303+
label: "Border Radius",
304+
},
305+
{
306+
type: "class_select",
307+
options: borderWidth.map((color) => ({
308+
name: color,
309+
value: color,
310+
})),
311+
label: "Border Width",
312+
},
313+
{
314+
type: "class_select",
315+
options: borderColor.map((color) => ({
316+
name: color,
317+
value: color,
318+
})),
319+
label: "Border Color",
320+
},
321+
{
322+
type: "class_select",
323+
options: borderStyle.map((color) => ({
324+
name: color,
325+
value: color,
326+
})),
327+
label: "Border Style",
328+
},
329+
],
330+
},
331+
},
332+
});
333+
});
334+
};

‎src/plugins/tailwind/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import grapesjs from "grapesjs";
2+
import loadComponents from "./components";
3+
import loadTraits from "./traits";
4+
5+
export default grapesjs.plugins.add(
6+
"tailwindComponent",
7+
(editor, opts = {}) => {
8+
let options = {};
9+
for (let name in options) {
10+
if (!(name in opts)) opts[name] = options[name];
11+
}
12+
13+
loadTraits(editor, options);
14+
loadComponents(editor, opts);
15+
}
16+
);
+285
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
export const textColor = [
2+
"text-transparent",
3+
"text-black",
4+
"text-white",
5+
"text-gray-50",
6+
"text-gray-100",
7+
"text-gray-200",
8+
"text-gray-300",
9+
"text-gray-400",
10+
"text-gray-500",
11+
"text-gray-600",
12+
"text-gray-700",
13+
"text-gray-800",
14+
"text-gray-900",
15+
16+
"text-red-50",
17+
"text-red-100",
18+
"text-red-200",
19+
"text-red-300",
20+
"text-red-400",
21+
"text-red-500",
22+
"text-red-600",
23+
"text-red-700",
24+
"text-red-800",
25+
"text-red-900",
26+
27+
"text-yellow-50",
28+
"text-yellow-100",
29+
"text-yellow-200",
30+
"text-yellow-300",
31+
"text-yellow-400",
32+
"text-yellow-500",
33+
"text-yellow-600",
34+
"text-yellow-700",
35+
"text-yellow-800",
36+
"text-yellow-900",
37+
38+
"text-green-50",
39+
"text-green-100",
40+
"text-green-200",
41+
"text-green-300",
42+
"text-green-400",
43+
"text-green-500",
44+
"text-green-600",
45+
"text-green-700",
46+
"text-green-800",
47+
"text-green-900",
48+
49+
"text-blue-50",
50+
"text-blue-100",
51+
"text-blue-200",
52+
"text-blue-300",
53+
"text-blue-400",
54+
"text-blue-500",
55+
"text-blue-600",
56+
"text-blue-700",
57+
"text-blue-800",
58+
"text-blue-900",
59+
60+
"text-indigo-50",
61+
"text-indigo-100",
62+
"text-indigo-200",
63+
"text-indigo-300",
64+
"text-indigo-400",
65+
"text-indigo-500",
66+
"text-indigo-600",
67+
"text-indigo-700",
68+
"text-indigo-800",
69+
"text-indigo-900",
70+
71+
"text-purple-50",
72+
"text-purple-100",
73+
"text-purple-200",
74+
"text-purple-300",
75+
"text-purple-400",
76+
"text-purple-500",
77+
"text-purple-600",
78+
"text-purple-700",
79+
"text-purple-800",
80+
"text-purple-900",
81+
82+
"text-pink-50",
83+
"text-pink-100",
84+
"text-pink-200",
85+
"text-pink-300",
86+
"text-pink-400",
87+
"text-pink-500",
88+
"text-pink-600",
89+
"text-pink-700",
90+
"text-pink-800",
91+
"text-pink-900",
92+
];
93+
94+
export const textAlignment = [
95+
"text-left",
96+
"text-center",
97+
"text-right",
98+
"text-justify",
99+
];
100+
101+
export const textOpacity = [
102+
"text-opacity-0",
103+
"text-opacity-5",
104+
"text-opacity-10",
105+
"text-opacity-20",
106+
"text-opacity-25",
107+
"text-opacity-30",
108+
"text-opacity-40",
109+
"text-opacity-50",
110+
"text-opacity-60",
111+
"text-opacity-70",
112+
"text-opacity-75",
113+
"text-opacity-80",
114+
"text-opacity-90",
115+
"text-opacity-95",
116+
"text-opacity-100",
117+
];
118+
119+
export const textDecoration = ["underline", "line-through", "no-underline"];
120+
121+
export const textTransformation = [
122+
"uppercase",
123+
"lowercase",
124+
"capitalize",
125+
"normal-case",
126+
];
127+
128+
export const textOverflow = ["truncate", "overflow-ellipsis", "overflow-clip"];
129+
130+
export const textFontSize = [
131+
"text-xs",
132+
"text-sm",
133+
"text-base",
134+
"text-lg",
135+
"text-xl",
136+
"text-2xl",
137+
"text-3xl",
138+
"text-4xl",
139+
"text-5xl",
140+
"text-6xl",
141+
"text-7xl",
142+
"text-8xl",
143+
"text-9xl",
144+
];
145+
146+
export const fontWeight = [
147+
"font-thin",
148+
"font-extralight",
149+
"font-light",
150+
"font-normal",
151+
"font-medium",
152+
"font-semibold",
153+
"font-bold",
154+
"font-extrabold",
155+
"font-black",
156+
];
157+
158+
export const fontVariant = [
159+
"normal-nums",
160+
"ordinal",
161+
"slashed-zero",
162+
"lining-nums",
163+
"oldstyle-nums",
164+
"proportional-nums",
165+
"tabular-nums",
166+
"diagonal-fractions",
167+
"stacked-fractions",
168+
];
169+
170+
export const letterSpacing = [
171+
"tracking-tighter",
172+
"tracking-tight",
173+
"tracking-normal",
174+
"tracking-wide",
175+
"tracking-wider",
176+
"tracking-widest",
177+
];
178+
179+
export const lineHeight = [
180+
"leading-3",
181+
"leading-4",
182+
"leading-5",
183+
"leading-6",
184+
"leading-7",
185+
"leading-8",
186+
"leading-9",
187+
"leading-10",
188+
"leading-none",
189+
"leading-tight",
190+
"leading-snug",
191+
"leading-normal",
192+
"leading-relaxed",
193+
"leading-loose",
194+
];
195+
196+
export const verticalAlign = [
197+
"align-baseline",
198+
"align-top",
199+
"align-middle",
200+
"align-bottom",
201+
"align-text-top",
202+
"align-text-bottom",
203+
];
204+
205+
export const wordBreak = ["break-normal", "break-words", "break-all"];
206+
export const tableBorder = ["border-collapse", "border-separate"];
207+
export const tableLayout = ["table-auto", "table-fixed"];
208+
209+
export const backgroundAttachment = ["bg-fixed", "bg-local", "bg-scroll"];
210+
export const backgroundClip = [
211+
"bg-clip-border",
212+
"bg-clip-padding",
213+
"bg-clip-content",
214+
"bg-clip-text",
215+
];
216+
217+
export const bgColor = [
218+
"bg-transparent",
219+
"bg-black",
220+
"bg-white",
221+
"bg-gray-400",
222+
"bg-gray-700",
223+
"bg-red-400",
224+
"bg-red-700",
225+
"bg-yellow-400",
226+
"bg-yellow-700",
227+
"bg-green-400",
228+
"bg-green-700",
229+
"bg-blue-400",
230+
"bg-blue-700",
231+
"bg-indigo-400",
232+
"bg-indigo-700",
233+
"bg-purple-400",
234+
"bg-purple-700",
235+
"bg-pink-400",
236+
"bg-pink-700",
237+
];
238+
239+
export const bgRepeat = [
240+
"bg-repeat",
241+
"bg-no-repeat",
242+
"bg-repeat-x",
243+
"bg-repeat-y",
244+
"bg-repeat-round",
245+
"bg-repeat-space",
246+
];
247+
248+
export const bgSize = ["bg-auto", "bg-cover", "bg-contain"];
249+
250+
export const borderRadius = [
251+
"rounded-none",
252+
"rounded",
253+
"rounded-lg",
254+
"rounded-full",
255+
];
256+
257+
export const borderWidth = [
258+
"border-0",
259+
"border-4",
260+
"border",
261+
"border-t-4",
262+
"border-r-4",
263+
"border-l-4",
264+
"border-b-4",
265+
];
266+
267+
export const borderColor = [
268+
"border-black",
269+
"border-gray-500",
270+
"border-red-500",
271+
"border-yellow-500",
272+
"border-green-500",
273+
"border-blue-500",
274+
"border-indigo-500",
275+
"border-purple-500",
276+
"border-pink-500",
277+
];
278+
279+
export const borderStyle = [
280+
"border-solid",
281+
"border-dashed",
282+
"border-dotted",
283+
"border-double",
284+
"border-none",
285+
];

‎src/plugins/tailwind/traits.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* eslint-disable import/no-anonymous-default-export */
2+
export default (editor, config = {}) => {
3+
const tm = editor.TraitManager;
4+
5+
tm.addType("class_select", {
6+
events: {
7+
change: "onChange",
8+
},
9+
createInput({ trait }) {
10+
const md = this.model;
11+
const opts = md.get("options") || [];
12+
const input = document.createElement("select");
13+
const target_view_el = this.target.view.el;
14+
15+
for (let i = 0; i < opts.length; i++) {
16+
const option = document.createElement("option");
17+
let value = opts[i].value;
18+
if (value === "") {
19+
value = "text-black";
20+
}
21+
option.text = opts[i].name;
22+
option.value = value;
23+
24+
const css = Array.from(target_view_el.classList);
25+
26+
const value_a = value.split(" ");
27+
const intersection = css.filter((x) => value_a.includes(x));
28+
29+
if (intersection.length === value_a.length) {
30+
option.setAttribute("selected", "selected");
31+
}
32+
33+
input.append(option);
34+
}
35+
return input;
36+
},
37+
onUpdate({ elInput, component }) {
38+
const classes = component.getClasses();
39+
const opts = this.model.get("options") || [];
40+
for (let i = 0; i < opts.length; i++) {
41+
let value = opts[i].value;
42+
if (value && classes.includes(value)) {
43+
elInput.value = value;
44+
return;
45+
}
46+
}
47+
elInput.value = "text-black";
48+
},
49+
50+
onEvent({ elInput, component, event }) {
51+
const classes = this.model.get("options").map((opt) => opt.value);
52+
for (let i = 0; i < classes.length; i++) {
53+
if (classes[i].length > 0) {
54+
const classes_i_a = classes[i].split(" ");
55+
for (let j = 0; j < classes_i_a.length; j++) {
56+
if (classes_i_a[j].length > 0) {
57+
component.removeClass(classes_i_a[j]);
58+
}
59+
}
60+
}
61+
}
62+
const value = this.model.get("value");
63+
const elAttributes = component.attributes.attributes;
64+
delete elAttributes[""];
65+
66+
if (value.length > 0 && value !== "text-black") {
67+
const value_a = value.split(" ");
68+
for (let i = 0; i < value_a.length; i++) {
69+
component.addClass(value_a[i]);
70+
}
71+
}
72+
component.em.trigger("component:toggled");
73+
},
74+
});
75+
};

‎src/redux/actions/pageAction.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import axios from "axios";
2+
import { API_HOST } from "../../api_utils";
3+
4+
export const TYPES = {
5+
LIST_PAGE_REQUEST_SEND: "LIST_PAGE_REQUEST_SEND",
6+
LIST_PAGE_REQUEST_ERROR: "LIST_PAGE_REQUEST_ERROR",
7+
LIST_PAGE_REQUEST_SUCCESS: "LIST_PAGE_REQUEST_SUCCESS",
8+
9+
CREATE_PAGE_REQUEST: "CREATE_PAGE_REQUEST",
10+
CREATE_PAGE_ERROR: "CREATE_PAGE_ERROR",
11+
CREATE_PAGE_SUCCESS: "CREATE_PAGE_SUCCESS",
12+
};
13+
14+
export const pageLoad = () => async (dispatch) => {
15+
dispatch({ type: TYPES.LIST_PAGE_REQUEST_SEND });
16+
try {
17+
const response = await axios.get(`${API_HOST}pages/`);
18+
dispatch({ type: TYPES.LIST_PAGE_REQUEST_SUCCESS, data: response.data });
19+
} catch (error) {
20+
dispatch({ type: TYPES.LIST_PAGE_REQUEST_ERROR, error: error });
21+
}
22+
};
23+
24+
export const createPage = (name) => async (dispatch) => {
25+
dispatch({ type: TYPES.CREATE_PAGE_REQUEST });
26+
try {
27+
const response = await axios.post(`${API_HOST}pages/`, { name });
28+
dispatch({ type: TYPES.CREATE_PAGE_SUCCESS, data: response.data });
29+
} catch (error) {
30+
dispatch({ type: TYPES.CREATE_PAGE_ERROR, data: error });
31+
}
32+
};

‎src/redux/reducers/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from "redux";
2+
import pageReducer from "./pageReducer";
3+
4+
export default combineReducers({
5+
pageStore: pageReducer,
6+
});

‎src/redux/reducers/pageReducer.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { TYPES } from "../actions/pageAction";
2+
3+
const {
4+
LIST_PAGE_REQUEST_SEND,
5+
LIST_PAGE_REQUEST_ERROR,
6+
LIST_PAGE_REQUEST_SUCCESS,
7+
8+
CREATE_PAGE_REQUEST,
9+
CREATE_PAGE_ERROR,
10+
CREATE_PAGE_SUCCESS,
11+
} = TYPES;
12+
13+
const initialState = {
14+
listPageLoading: false,
15+
listPageError: "",
16+
pages: [],
17+
createPageError: "",
18+
createPageLoading: false,
19+
};
20+
21+
const pageReducer = (state = initialState, action) => {
22+
switch (action.type) {
23+
case LIST_PAGE_REQUEST_SEND:
24+
return { ...state, listPageLoading: true, listPageError: "" };
25+
case LIST_PAGE_REQUEST_ERROR:
26+
return { ...state, listPageLoading: false, listPageError: action.error };
27+
case LIST_PAGE_REQUEST_SUCCESS:
28+
return {
29+
...state,
30+
listPageLoading: false,
31+
listPageError: "",
32+
pages: action.data,
33+
};
34+
35+
case CREATE_PAGE_REQUEST:
36+
return { ...state, createPageError: "", createPageLoading: true };
37+
case CREATE_PAGE_ERROR:
38+
return {
39+
...state,
40+
createPageError: action.data,
41+
createPageLoading: false,
42+
};
43+
case CREATE_PAGE_SUCCESS:
44+
return { ...state, createPageError: "", createPageLoading: false, pages: [...state.pages, action.data]};
45+
46+
default:
47+
return state;
48+
}
49+
};
50+
51+
export default pageReducer;

‎src/redux/store.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createStore, applyMiddleware } from "redux";
2+
import { Provider } from "react-redux";
3+
import thunk from "redux-thunk";
4+
import { composeWithDevTools } from "redux-devtools-extension";
5+
6+
import rootReducer from "./reducers";
7+
const store = createStore(
8+
rootReducer,
9+
composeWithDevTools(applyMiddleware(thunk))
10+
);
11+
12+
const DataProvider = ({ children }) => {
13+
return <Provider store={store}>{children}</Provider>;
14+
};
15+
16+
export default DataProvider;

‎src/reportWebVitals.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const reportWebVitals = onPerfEntry => {
2+
if (onPerfEntry && onPerfEntry instanceof Function) {
3+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4+
getCLS(onPerfEntry);
5+
getFID(onPerfEntry);
6+
getFCP(onPerfEntry);
7+
getLCP(onPerfEntry);
8+
getTTFB(onPerfEntry);
9+
});
10+
}
11+
};
12+
13+
export default reportWebVitals;

‎src/styles/main.scss

+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
@import "~bootstrap/scss/bootstrap";
2+
3+
body {
4+
margin: 0;
5+
padding: 0;
6+
}
7+
8+
html {
9+
overflow: scroll;
10+
overflow-x: hidden;
11+
-ms-overflow-style: none;
12+
scrollbar-width: none;
13+
}
14+
15+
::-webkit-scrollbar {
16+
display: none;
17+
}
18+
19+
.sidenav {
20+
top: 0;
21+
left: 0;
22+
width: 15%;
23+
height: 100vh;
24+
overflow: scroll;
25+
overflow-x: hidden;
26+
-ms-overflow-style: none;
27+
scrollbar-width: none;
28+
background-color: rgba(255, 255, 255, 0.95);
29+
transition: 0.5s;
30+
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.05);
31+
border: 1px solid rgba(0, 0, 0, 0.3);
32+
.logo {
33+
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
34+
text-transform: uppercase;
35+
font-size: 20px;
36+
font-weight: 700;
37+
}
38+
.pages {
39+
height: 100px;
40+
overflow: scroll;
41+
overflow-x: hidden;
42+
}
43+
}
44+
.w-85 {
45+
width: 85%;
46+
}
47+
.start-15 {
48+
left: 15%;
49+
}
50+
.main-content {
51+
.navbar {
52+
padding: 0;
53+
.container-fluid {
54+
padding: 0;
55+
}
56+
}
57+
58+
#editor {
59+
border: 2px solid rgba(0, 0, 0, 0.3);
60+
}
61+
}
62+
63+
.nav {
64+
justify-content: space-between;
65+
}
66+
.gjs-pn-panel {
67+
position: relative;
68+
}
69+
70+
.gjs-cv-canvas {
71+
width: 100%;
72+
height: 100%;
73+
top: 0;
74+
}
75+
76+
.tab-content {
77+
display: contents;
78+
}
79+
80+
#block {
81+
height: 100%;
82+
#blocks {
83+
height: 100%;
84+
85+
.gjs-blocks-c {
86+
align-items: center;
87+
justify-content: center;
88+
}
89+
.gjs-block {
90+
justify-content: center;
91+
}
92+
}
93+
}
94+
95+
/* Theming */
96+
.gjs-one-bg {
97+
background-color: #fcf6f5ff;
98+
}
99+
100+
.gjs-two-color {
101+
color: #990011ff;
102+
}
103+
104+
.gjs-three-bg {
105+
background-color: #990011ff;
106+
color: #fcf6f5ff;
107+
}
108+
109+
.gjs-four-color,
110+
.gjs-four-color-h:hover {
111+
color: #990011ff;
112+
}
113+
114+
.gjs-pn-btn {
115+
border: 1px solid #990011ff;
116+
}
117+
118+
// Customize Bootstrap CSS
119+
120+
.btn,
121+
.nav-link,
122+
.modal-content,
123+
.form-control {
124+
border-radius: 0 !important;
125+
}
126+
127+
.btn {
128+
.fa {
129+
color: #990011ff;
130+
}
131+
&:hover {
132+
.fa {
133+
color: #fcf6f5ff;
134+
}
135+
}
136+
}
137+
138+
/** Error **/
139+
.error {
140+
.bg-body {
141+
min-height: 150px;
142+
max-height: 150px;
143+
display: flex;
144+
align-items: center;
145+
justify-content: center;
146+
.title {
147+
font-weight: 600;
148+
}
149+
}
150+
.btn {
151+
border-radius: 40px !important;
152+
padding: 15px 20px;
153+
font-size: 14px;
154+
font-weight: 700;
155+
min-width: 150px;
156+
}
157+
}
158+
159+
/** Assets **/
160+
.gjs-am-meta,
161+
.gjs-am-close,
162+
.gjs-am-file-uploader,
163+
.gjs-am-assets-header {
164+
display: none;
165+
}
166+
167+
.gjs-am-assets-cont {
168+
width: 100%;
169+
}
170+
171+
.gjs-am-assets {
172+
justify-content: space-between;
173+
display: flex;
174+
flex-wrap: wrap;
175+
}
176+
177+
.gjs-am-asset-image {
178+
margin-top: 1rem;
179+
margin-bottom: 1rem;
180+
display: contents;
181+
}
182+
183+
.gjs-am-preview-cont {
184+
margin-top: 1rem;
185+
}
186+
.gjs-block-label {
187+
.fa {
188+
font-size: 25px;
189+
}
190+
}
191+
.grp-wrapper {
192+
background-image: url("data:image/png:base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==");
193+
}
194+
.grp-preview {
195+
position: absolute;
196+
top: 0;
197+
left: 0;
198+
width: 100%;
199+
height: 100%;
200+
cursor: crosshair;
201+
}
202+
.grp-handler {
203+
width: 4px;
204+
margin-left: -2px;
205+
user-select: none;
206+
height: 100%;
207+
-webkit-user-select: none;
208+
-moz-user-select: none;
209+
}
210+
211+
.grp-handler-close {
212+
color: rgba(0, 0, 0, 0.4);
213+
border-radius: 0 2px 10px rgba(0, 0, 0, 0.25);
214+
background-color: #fff;
215+
text-align: center;
216+
width: 15px;
217+
height: 15px;
218+
margin-left: -5px;
219+
line-height: 10px;
220+
font-size: 21px;
221+
cursor: pointer;
222+
}
223+
224+
.grp-handler-close {
225+
position: absolute;
226+
top: -17px;
227+
}
228+
229+
.grp-handler-drag {
230+
background-color: rgba(0, 0, 0, 0.5);
231+
cursor: col-resize;
232+
width: 100%;
233+
height: 100%;
234+
}
235+
236+
.grp-handler-selected .grap-handler-drag {
237+
background-color: rgba(255, 255, 255, 0.5);
238+
}
239+
240+
.grp-handler-cp-c {
241+
display: none;
242+
}
243+
244+
.grp-handler-selected .grp-handler-cp-c {
245+
display: block;
246+
}
247+
248+
.grp-handler-cp-wrap {
249+
width: 15px;
250+
height: 15px;
251+
margin-left: -8px;
252+
border: 3px solid #fff;
253+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
254+
overflow: hidden;
255+
border-radius: 100%;
256+
cursor: pointer;
257+
}
258+
259+
.grp-handler-cp-wrap input[type="color"] {
260+
opacity: 0;
261+
cursor: pointer;
262+
}

0 commit comments

Comments
 (0)
Please sign in to comment.