Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 5b37c17

Browse files
committed
🌵 Added the ability to configure add-ons
1 parent 66a2b12 commit 5b37c17

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

README.md

100644100755
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ For the plugin to work correctly, you need to give Public and Authenticated role
5252

5353
<br>
5454

55+
## ⚙️ How to customize editor (optional)
56+
57+
If you want to change the look of the editor or remove unused add-ons, you can add a custom Editor.js configuration to override the default settings:
58+
59+
1. Go to your Strapi folder
60+
2. Copy template config file [`node_modules/strapi-plugin-react-editorjs/admin/src/config/customTools.js`](admin/src/config/customTools.js) to `extensions/react-editorjs/admin/src/config`
61+
3. Set up `extensions/react-editorjs/admin/src/config/customTools.js`
62+
4. Rebuild Strapi
63+
64+
```bash
65+
yarn run build
66+
# or
67+
npm run build
68+
```
69+
### Please note that the add-ons are configured for Strapi, be careful when changing the configuration.
70+
71+
<br>
72+
5573
## 👨🏻‍🏭 Developing
5674

5775
1. [Personality Tool](https://github.com/editor-js/personality)

admin/src/components/editorjs/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useState, useCallback } from 'react';
22
import PropTypes from 'prop-types';
33
import EditorJs from 'react-editor-js';
4-
import EditorTools from './tools';
4+
import requiredTools from './requiredTools';
5+
import customTools from '../../config/customTools';
56

67
import MediaLibAdapter from '../medialib/adapter'
78
import MediaLibComponent from '../medialib/component';
@@ -54,7 +55,7 @@ const Editor = ({ onChange, name, value }) => {
5455
onChange({target: {name, value: JSON.stringify(newData)}})
5556
}
5657
}}
57-
tools={{...EditorTools, ...customImageTool}}
58+
tools={{...requiredTools, ...customTools, ...customImageTool}}
5859
instanceRef={instance => setEditorInstance(instance)}
5960
/>
6061
</div>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import PluginId from '../../pluginId'
2+
3+
// Plugins for Editor.js
4+
import Image from '@editorjs/image'
5+
6+
const requiredTools = {
7+
image: {
8+
class: Image,
9+
config: {
10+
field: "files.image",
11+
additionalRequestData: {
12+
data: JSON.stringify({})
13+
},
14+
additionalRequestHeaders: {
15+
"Authorization": `Bearer ${JSON.parse(sessionStorage.getItem("jwtToken"))}`
16+
},
17+
endpoints: {
18+
byUrl: `/${PluginId}/image/byUrl`,
19+
},
20+
uploader: {
21+
async uploadByFile(file) {
22+
const formData = new FormData();
23+
formData.append("data", JSON.stringify({}));
24+
formData.append("files.image", file);
25+
26+
const {data} = await axios.post(`/${PluginId}/image/byFile`, formData, {
27+
headers: {
28+
"Authorization": `Bearer ${JSON.parse(sessionStorage.getItem("jwtToken"))}`
29+
}
30+
});
31+
32+
return data
33+
},
34+
}
35+
}
36+
}
37+
}
38+
39+
export default requiredTools

admin/src/components/editorjs/tools.js renamed to admin/src/config/customTools.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import PluginId from '../../pluginId'
1+
import PluginId from '../pluginId'
22

3-
// Plugins for Editor.js
43
import Embed from '@editorjs/embed'
54
import Table from '@editorjs/table'
65
import List from '@editorjs/list'
76
import Warning from '@editorjs/warning'
87
import Code from '@editorjs/code'
98
import Link from '@editorjs/link'
10-
import Image from '@editorjs/image'
119
import Raw from '@editorjs/raw'
1210
import Header from '@editorjs/header'
1311
import Quote from '@editorjs/quote'
@@ -16,7 +14,7 @@ import CheckList from '@editorjs/checklist'
1614
import Delimiter from '@editorjs/delimiter'
1715
import InlineCode from '@editorjs/inline-code'
1816

19-
const editorTools = {
17+
const customTools = {
2018
embed: Embed,
2119
table: {
2220
class: Table,
@@ -41,36 +39,6 @@ const editorTools = {
4139
endpoint: `/${PluginId}/link`,
4240
},
4341
},
44-
image: {
45-
class: Image,
46-
config: {
47-
field: "files.image",
48-
additionalRequestData: {
49-
data: JSON.stringify({})
50-
},
51-
additionalRequestHeaders: {
52-
"Authorization": `Bearer ${JSON.parse(sessionStorage.getItem("jwtToken"))}`
53-
},
54-
endpoints: {
55-
byUrl: `/${PluginId}/image/byUrl`,
56-
},
57-
uploader: {
58-
async uploadByFile(file) {
59-
const formData = new FormData();
60-
formData.append("data", JSON.stringify({}));
61-
formData.append("files.image", file);
62-
63-
const {data} = await axios.post(`/${PluginId}/image/byFile`, formData, {
64-
headers: {
65-
"Authorization": `Bearer ${JSON.parse(sessionStorage.getItem("jwtToken"))}`
66-
}
67-
});
68-
69-
return data
70-
},
71-
}
72-
}
73-
},
7442
raw: {
7543
class: Raw,
7644
inlineToolbar: true,
@@ -99,4 +67,4 @@ const editorTools = {
9967
inlineCode: InlineCode,
10068
}
10169

102-
export default editorTools
70+
export default customTools

0 commit comments

Comments
 (0)