@kookaat/strapi-plugin-tinymce 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/stale.yml +17 -0
- package/README.md +177 -0
- package/admin/src/api/settings.js +14 -0
- package/admin/src/components/Editor/index.js +74 -0
- package/admin/src/components/Initializer/index.js +26 -0
- package/admin/src/components/MediaLib/index.js +43 -0
- package/admin/src/components/PluginIcon/index.js +12 -0
- package/admin/src/components/Wysiwyg/index.js +122 -0
- package/admin/src/index.js +69 -0
- package/admin/src/pages/App/index.js +25 -0
- package/admin/src/pages/HomePage/index.js +7 -0
- package/admin/src/pages/Settings/index.js +134 -0
- package/admin/src/permissions.js +11 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/translations/cs.json +10 -0
- package/admin/src/translations/en.json +10 -0
- package/admin/src/translations/sk.json +10 -0
- package/admin/src/utils/axiosInstance.js +40 -0
- package/admin/src/utils/get-trad.js +5 -0
- package/admin/src/utils/index.js +2 -0
- package/package.json +35 -0
- package/server/bootstrap.js +19 -0
- package/server/config/index.js +6 -0
- package/server/content-types/index.js +3 -0
- package/server/controllers/config.js +12 -0
- package/server/controllers/index.js +9 -0
- package/server/controllers/settings.js +30 -0
- package/server/destroy.js +5 -0
- package/server/index.js +25 -0
- package/server/middlewares/index.js +3 -0
- package/server/policies/index.js +3 -0
- package/server/register.js +5 -0
- package/server/routes/config.js +13 -0
- package/server/routes/index.js +7 -0
- package/server/routes/settings.js +23 -0
- package/server/services/config.js +9 -0
- package/server/services/index.js +9 -0
- package/server/services/settings.js +36 -0
- package/strapi-admin.js +3 -0
- package/strapi-server.js +3 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
|
2
|
+
daysUntilStale: 30
|
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
|
4
|
+
daysUntilClose: 7
|
|
5
|
+
# Issues with these labels will never be considered stale
|
|
6
|
+
exemptLabels:
|
|
7
|
+
- pinned
|
|
8
|
+
- security
|
|
9
|
+
# Label to use when marking an issue as stale
|
|
10
|
+
staleLabel: wontfix
|
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
+
markComment: >
|
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
|
15
|
+
for your contributions.
|
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
+
closeComment: false
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<h1 align="center">Strapi plugin TinyMCE</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">Replaces the default Strapi WYSIWYG editor with a customized build of TinyMCE editor.</p>
|
|
4
|
+
|
|
5
|
+
## 👋 Intro
|
|
6
|
+
|
|
7
|
+
* [Features](#features)
|
|
8
|
+
* [Installation](#installation)
|
|
9
|
+
* [Configuration](#configuration)
|
|
10
|
+
* [Requirements](#requirements)
|
|
11
|
+
|
|
12
|
+
## <a id="features"></a>✨ Key features
|
|
13
|
+
|
|
14
|
+
* **Anchor:** Add an anchor/bookmark button to the toolbar that inserts an anchor at the editor’s cursor insertion point.
|
|
15
|
+
* **Autolink:** Create hyperlinks automatically when a user inputs a valid and complete URL.
|
|
16
|
+
* **Autoresize:** Resize the editor automatically to the content inside it, and prevent the editor from expanding infinitely.
|
|
17
|
+
* **Code:** Add a toolbar button that allows a user to edit the HTML code hidden by the WYSIWYG view.
|
|
18
|
+
* **Code sample:** Insert and embed syntax color highlighted code snippets into the editable area.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
And much more ! [List of all features](https://www.tiny.cloud/tinymce/features/).
|
|
22
|
+
|
|
23
|
+
## <a id="installation"></a>🔧 Installation
|
|
24
|
+
|
|
25
|
+
Inside your Strapi app, add the package:
|
|
26
|
+
|
|
27
|
+
With `npm`:
|
|
28
|
+
```bash
|
|
29
|
+
npm install @sklinet/strapi-plugin-tinymce
|
|
30
|
+
```
|
|
31
|
+
With `yarn`:
|
|
32
|
+
```bash
|
|
33
|
+
yarn add @sklinet/strapi-plugin-tinymce
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
In `config/plugins.js` file add:
|
|
37
|
+
```js
|
|
38
|
+
tinymce:{
|
|
39
|
+
enabled:true
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If you do not yet have this file, then create and add:
|
|
44
|
+
```js
|
|
45
|
+
module.exports = () => ({
|
|
46
|
+
tinymce:{
|
|
47
|
+
enabled:true
|
|
48
|
+
};
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You will also have to update strapi::security middleware in your middlewares.js file in config folder.
|
|
53
|
+
If you didn't update this file yet, then replace "strapi::security" with following code (object)
|
|
54
|
+
```js
|
|
55
|
+
//middlewares.js
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
name: "strapi::security",
|
|
59
|
+
config: {
|
|
60
|
+
contentSecurityPolicy: {
|
|
61
|
+
useDefaults: true,
|
|
62
|
+
directives: {
|
|
63
|
+
"script-src": ["'self'", "*.tinymce.com", "*.tiny.cloud", "https:"],
|
|
64
|
+
"connect-src": ["'self'", "*.tinymce.com", "*.tiny.cloud", "blob:", "*.strapi.io"],
|
|
65
|
+
"img-src": [
|
|
66
|
+
"'self'",
|
|
67
|
+
"*.tinymce.com",
|
|
68
|
+
"*.tiny.cloud",
|
|
69
|
+
"data:",
|
|
70
|
+
"blob:",
|
|
71
|
+
"dl.airtable.com",
|
|
72
|
+
"strapi.io",
|
|
73
|
+
"s3.amazonaws.com",
|
|
74
|
+
"cdn.jsdelivr.net",
|
|
75
|
+
],
|
|
76
|
+
"style-src": [
|
|
77
|
+
"'self'",
|
|
78
|
+
"'unsafe-inline'",
|
|
79
|
+
"*.tinymce.com",
|
|
80
|
+
"*.tiny.cloud",
|
|
81
|
+
],
|
|
82
|
+
"font-src": ["'self'", "*.tinymce.com", "*.tiny.cloud"],
|
|
83
|
+
},
|
|
84
|
+
upgradeInsecureRequests: null,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Then run build:
|
|
91
|
+
```bash
|
|
92
|
+
npm run build
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
or
|
|
96
|
+
```bash
|
|
97
|
+
yarn build
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**After starting your project please add API key for your TinyMCE editor in admin panel in settings/tinymce/configuration**
|
|
101
|
+
|
|
102
|
+
If TinyMCE editor doesn't appear in your richtext field, please check your console for any hints, you might have incorrectly set your middlewares.
|
|
103
|
+
|
|
104
|
+
## <a id="configuration"></a>⚙️ Configuration
|
|
105
|
+
TinyMCE outputFormat should be defined in `config.editor`, and init object should be defined in `config.editor.editorConfig` field in `plugins.js` file.
|
|
106
|
+
|
|
107
|
+
**⚠️ `plugins.js` not `plugin.js` ⚠️**
|
|
108
|
+
|
|
109
|
+
**`plugins.js` file should be placed in `config` folder.**
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
Learn more about configuration from [official documentation](https://www.tiny.cloud/docs/tinymce/6/).
|
|
113
|
+
|
|
114
|
+
**Default configuration:**
|
|
115
|
+
```js
|
|
116
|
+
// plugins.js
|
|
117
|
+
module.exports = ({ env }) => ({
|
|
118
|
+
tinymce: {
|
|
119
|
+
enabled: true,
|
|
120
|
+
config: {
|
|
121
|
+
editor: {
|
|
122
|
+
outputFormat: "html",
|
|
123
|
+
editorConfig: {
|
|
124
|
+
language: "sk",
|
|
125
|
+
height: 500,
|
|
126
|
+
menubar: false,
|
|
127
|
+
extended_valid_elements: "span, img, small",
|
|
128
|
+
forced_root_block: "",
|
|
129
|
+
convert_urls: false,
|
|
130
|
+
entity_encoding: "raw",
|
|
131
|
+
plugins:
|
|
132
|
+
"advlist autolink lists link image charmap preview anchor \
|
|
133
|
+
searchreplace visualblocks code fullscreen table emoticons nonbreaking \
|
|
134
|
+
insertdatetime media table code help wordcount",
|
|
135
|
+
toolbar:
|
|
136
|
+
"undo redo | styles | bold italic forecolor backcolor | \
|
|
137
|
+
alignleft aligncenter alignright alignjustify | \
|
|
138
|
+
media table emoticons visualblocks code|\
|
|
139
|
+
nonbreaking bullist numlist outdent indent | removeformat | help",
|
|
140
|
+
style_formats: [
|
|
141
|
+
{
|
|
142
|
+
title: "Headings",
|
|
143
|
+
items: [
|
|
144
|
+
{ title: "h1", block: "h1" },
|
|
145
|
+
{ title: "h2", block: "h2" },
|
|
146
|
+
{ title: "h3", block: "h3" },
|
|
147
|
+
{ title: "h4", block: "h4" },
|
|
148
|
+
{ title: "h5", block: "h5" },
|
|
149
|
+
{ title: "h6", block: "h6" },
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
{
|
|
154
|
+
title: "Text",
|
|
155
|
+
items: [
|
|
156
|
+
{ title: "Paragraph", block: "p" },
|
|
157
|
+
{
|
|
158
|
+
title: "Paragraph with small letters",
|
|
159
|
+
block: "small",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## <a id="requirements"></a>⚠️ Requirements
|
|
173
|
+
Strapi **v4.x.x+**
|
|
174
|
+
|
|
175
|
+
Node **14 - 16**
|
|
176
|
+
|
|
177
|
+
Tested on **v4.3.4**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { axiosInstance } from "../utils";
|
|
2
|
+
|
|
3
|
+
const taskRequests = {
|
|
4
|
+
getSettings: async () => {
|
|
5
|
+
const data = await axiosInstance.get(`/tinymce/settings`);
|
|
6
|
+
return data;
|
|
7
|
+
},
|
|
8
|
+
setSettings: async (data) => {
|
|
9
|
+
return await axiosInstance.post(`/tinymce/settings`, {
|
|
10
|
+
apiKey: data,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default taskRequests;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { Editor } from "@tinymce/tinymce-react";
|
|
4
|
+
import { request } from "@strapi/helper-plugin";
|
|
5
|
+
import pluginId from "../../pluginId";
|
|
6
|
+
import taskRequests from "../../api/settings";
|
|
7
|
+
import { prefixFileUrlWithBackendUrl } from "@strapi/helper-plugin";
|
|
8
|
+
|
|
9
|
+
const TinyEditor = ({ onChange, name, value }) => {
|
|
10
|
+
const [pluginConfig, setPluginConfig] = useState();
|
|
11
|
+
const [apiKey, setApiKey] = useState("");
|
|
12
|
+
const [loading, setLoading] = useState(true);
|
|
13
|
+
const uploadUrl = `${prefixFileUrlWithBackendUrl("/api/upload")}`;
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const getApiKey = async () => {
|
|
17
|
+
const data = await taskRequests.getSettings();
|
|
18
|
+
if (data) {
|
|
19
|
+
return setApiKey(data.data.apiKey);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const getPluginConfig = async () => {
|
|
23
|
+
const editor = await request(`/${pluginId}/config/editor`, {
|
|
24
|
+
method: "GET",
|
|
25
|
+
});
|
|
26
|
+
if (editor) {
|
|
27
|
+
setPluginConfig(editor);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
getApiKey().then(() => {
|
|
31
|
+
setLoading(false)
|
|
32
|
+
});
|
|
33
|
+
getPluginConfig();
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
!loading && pluginConfig ?
|
|
38
|
+
<Editor
|
|
39
|
+
apiKey={apiKey || ""}
|
|
40
|
+
value={value}
|
|
41
|
+
tagName={name}
|
|
42
|
+
onEditorChange={(editorContent) => {
|
|
43
|
+
onChange({ target: { name, value: editorContent } });
|
|
44
|
+
}}
|
|
45
|
+
outputFormat={pluginConfig?.outputFormat || "html"}
|
|
46
|
+
init={{
|
|
47
|
+
...pluginConfig?.editorConfig,
|
|
48
|
+
images_upload_handler: async (blobInfo) => {
|
|
49
|
+
const formData = new FormData();
|
|
50
|
+
formData.append("files", blobInfo.blob());
|
|
51
|
+
const response = await fetch(uploadUrl, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: "Bearer ",
|
|
55
|
+
},
|
|
56
|
+
body: formData,
|
|
57
|
+
})
|
|
58
|
+
.then((response) => response.json())
|
|
59
|
+
.catch(function (err) {
|
|
60
|
+
console.log("error:", err);
|
|
61
|
+
});
|
|
62
|
+
return response?.[0]?.url || '';
|
|
63
|
+
},
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
: <></>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
TinyEditor.propTypes = {
|
|
70
|
+
onChange: PropTypes.func.isRequired,
|
|
71
|
+
name: PropTypes.string.isRequired,
|
|
72
|
+
value: PropTypes.string,
|
|
73
|
+
};
|
|
74
|
+
export default TinyEditor;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Initializer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useEffect, useRef } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import pluginId from '../../pluginId';
|
|
10
|
+
|
|
11
|
+
const Initializer = ({ setPlugin }) => {
|
|
12
|
+
const ref = useRef();
|
|
13
|
+
ref.current = setPlugin;
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
ref.current(pluginId);
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
Initializer.propTypes = {
|
|
23
|
+
setPlugin: PropTypes.func.isRequired,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default Initializer;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { prefixFileUrlWithBackendUrl, useLibrary } from "@strapi/helper-plugin";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
|
|
5
|
+
const MediaLib = ({ isOpen, onChange, onToggle }) => {
|
|
6
|
+
const { components } = useLibrary();
|
|
7
|
+
const MediaLibraryDialog = components["media-library"];
|
|
8
|
+
|
|
9
|
+
const handleSelectAssets = (files) => {
|
|
10
|
+
const formattedFiles = files.map((f) => ({
|
|
11
|
+
alt: f.alternativeText || f.name,
|
|
12
|
+
url: prefixFileUrlWithBackendUrl(f.url),
|
|
13
|
+
mime: f.mime,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
onChange(formattedFiles);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (!isOpen) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<MediaLibraryDialog
|
|
25
|
+
onClose={onToggle}
|
|
26
|
+
onSelectAssets={handleSelectAssets}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
MediaLib.defaultProps = {
|
|
32
|
+
isOpen: false,
|
|
33
|
+
onChange: () => {},
|
|
34
|
+
onToggle: () => {},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
MediaLib.propTypes = {
|
|
38
|
+
isOpen: PropTypes.bool,
|
|
39
|
+
onChange: PropTypes.func,
|
|
40
|
+
onToggle: PropTypes.func,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default MediaLib;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { Stack } from "@strapi/design-system/Stack";
|
|
4
|
+
import { Box } from "@strapi/design-system/Box";
|
|
5
|
+
import { Button } from "@strapi/design-system/Button";
|
|
6
|
+
import { Typography } from "@strapi/design-system/Typography";
|
|
7
|
+
import Landscape from "@strapi/icons/Landscape";
|
|
8
|
+
import MediaLib from "../MediaLib";
|
|
9
|
+
import Editor from "../Editor";
|
|
10
|
+
import { useIntl } from "react-intl";
|
|
11
|
+
|
|
12
|
+
const Wysiwyg = ({
|
|
13
|
+
name,
|
|
14
|
+
onChange,
|
|
15
|
+
value,
|
|
16
|
+
intlLabel,
|
|
17
|
+
disabled,
|
|
18
|
+
error,
|
|
19
|
+
description,
|
|
20
|
+
required,
|
|
21
|
+
}) => {
|
|
22
|
+
const { formatMessage } = useIntl();
|
|
23
|
+
const [mediaLibVisible, setMediaLibVisible] = useState(false);
|
|
24
|
+
|
|
25
|
+
const handleToggleMediaLib = () => setMediaLibVisible((prev) => !prev);
|
|
26
|
+
|
|
27
|
+
const handleChangeAssets = (assets) => {
|
|
28
|
+
let newValue = value ? value : "";
|
|
29
|
+
|
|
30
|
+
assets.map((asset) => {
|
|
31
|
+
if (asset.mime.includes("image")) {
|
|
32
|
+
const imgTag = `<p><img src="${asset.url}" alt="${asset.alt}"></img></p>`;
|
|
33
|
+
newValue = `${newValue}${imgTag}`;
|
|
34
|
+
}
|
|
35
|
+
if (asset.mime.includes("video")) {
|
|
36
|
+
const videoTag = `<video><source src="${asset.url}" alt="${asset.alt}"</source></video>`;
|
|
37
|
+
newValue = `${newValue}${videoTag}`;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
onChange({ target: { name, value: newValue } });
|
|
42
|
+
handleToggleMediaLib();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
<Stack size={1}>
|
|
48
|
+
<Box>
|
|
49
|
+
<Typography variant="pi" fontWeight="bold">
|
|
50
|
+
{formatMessage(intlLabel)}
|
|
51
|
+
</Typography>
|
|
52
|
+
{required && (
|
|
53
|
+
<Typography
|
|
54
|
+
variant="pi"
|
|
55
|
+
fontWeight="bold"
|
|
56
|
+
textColor="danger600"
|
|
57
|
+
>
|
|
58
|
+
*
|
|
59
|
+
</Typography>
|
|
60
|
+
)}
|
|
61
|
+
</Box>
|
|
62
|
+
<Button
|
|
63
|
+
startIcon={<Landscape />}
|
|
64
|
+
variant="secondary"
|
|
65
|
+
fullWidth
|
|
66
|
+
onClick={handleToggleMediaLib}
|
|
67
|
+
>
|
|
68
|
+
Media library
|
|
69
|
+
</Button>
|
|
70
|
+
<Editor
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
name={name}
|
|
73
|
+
onChange={onChange}
|
|
74
|
+
value={value}
|
|
75
|
+
/>
|
|
76
|
+
{error && (
|
|
77
|
+
<Typography variant="pi" textColor="danger600">
|
|
78
|
+
{formatMessage({ id: error, defaultMessage: error })}
|
|
79
|
+
</Typography>
|
|
80
|
+
)}
|
|
81
|
+
{description && (
|
|
82
|
+
<Typography variant="pi">
|
|
83
|
+
{formatMessage(description)}
|
|
84
|
+
</Typography>
|
|
85
|
+
)}
|
|
86
|
+
</Stack>
|
|
87
|
+
<MediaLib
|
|
88
|
+
isOpen={mediaLibVisible}
|
|
89
|
+
onChange={handleChangeAssets}
|
|
90
|
+
onToggle={handleToggleMediaLib}
|
|
91
|
+
/>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
Wysiwyg.defaultProps = {
|
|
97
|
+
description: "",
|
|
98
|
+
disabled: false,
|
|
99
|
+
error: undefined,
|
|
100
|
+
intlLabel: "",
|
|
101
|
+
required: false,
|
|
102
|
+
value: "",
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
Wysiwyg.propTypes = {
|
|
106
|
+
description: PropTypes.shape({
|
|
107
|
+
id: PropTypes.string,
|
|
108
|
+
defaultMessage: PropTypes.string,
|
|
109
|
+
}),
|
|
110
|
+
disabled: PropTypes.bool,
|
|
111
|
+
error: PropTypes.string,
|
|
112
|
+
intlLabel: PropTypes.shape({
|
|
113
|
+
id: PropTypes.string,
|
|
114
|
+
defaultMessage: PropTypes.string,
|
|
115
|
+
}),
|
|
116
|
+
name: PropTypes.string.isRequired,
|
|
117
|
+
onChange: PropTypes.func.isRequired,
|
|
118
|
+
required: PropTypes.bool,
|
|
119
|
+
value: PropTypes.string,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default Wysiwyg;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { prefixPluginTranslations } from "@strapi/helper-plugin";
|
|
2
|
+
import pluginPkg from "../../package.json";
|
|
3
|
+
import pluginId from "./pluginId";
|
|
4
|
+
import Initializer from "./components/Initializer";
|
|
5
|
+
import Wysiwyg from "./components/Wysiwyg";
|
|
6
|
+
import { getTrad } from "./utils";
|
|
7
|
+
import pluginPermissions from "./permissions";
|
|
8
|
+
|
|
9
|
+
const name = pluginPkg.strapi.name;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
register(app) {
|
|
13
|
+
app.addFields({ type: "wysiwyg", Component: Wysiwyg });
|
|
14
|
+
app.createSettingSection(
|
|
15
|
+
{
|
|
16
|
+
id: pluginId,
|
|
17
|
+
intlLabel: {
|
|
18
|
+
id: `${pluginId}.plugin.name`,
|
|
19
|
+
defaultMessage: "TinyMCE",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
intlLabel: {
|
|
25
|
+
id: getTrad("settings.page-title"),
|
|
26
|
+
defaultMessage: "Configuration",
|
|
27
|
+
},
|
|
28
|
+
id: "settings",
|
|
29
|
+
to: `/settings/${pluginId}`,
|
|
30
|
+
Component: async () => {
|
|
31
|
+
return import("./pages/Settings");
|
|
32
|
+
},
|
|
33
|
+
permissions: pluginPermissions["settings"],
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
);
|
|
37
|
+
app.registerPlugin({
|
|
38
|
+
id: pluginId,
|
|
39
|
+
initializer: Initializer,
|
|
40
|
+
isReady: false,
|
|
41
|
+
name,
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
bootstrap(app) {},
|
|
46
|
+
async registerTrads({ locales }) {
|
|
47
|
+
const importedTrads = await Promise.all(
|
|
48
|
+
locales.map((locale) => {
|
|
49
|
+
return import(
|
|
50
|
+
/* webpackChunkName: "translation-[request]" */ `./translations/${locale}.json`
|
|
51
|
+
)
|
|
52
|
+
.then(({ default: data }) => {
|
|
53
|
+
return {
|
|
54
|
+
data: prefixPluginTranslations(data, pluginId),
|
|
55
|
+
locale,
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
.catch(() => {
|
|
59
|
+
return {
|
|
60
|
+
data: {},
|
|
61
|
+
locale,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return Promise.resolve(importedTrads);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* This component is the skeleton around the actual pages, and should only
|
|
4
|
+
* contain code that should be seen on all pages. (e.g. navigation bar)
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { Switch, Route } from 'react-router-dom';
|
|
10
|
+
import { NotFound } from '@strapi/helper-plugin';
|
|
11
|
+
import pluginId from '../../pluginId';
|
|
12
|
+
import HomePage from '../HomePage';
|
|
13
|
+
|
|
14
|
+
const App = () => {
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<Switch>
|
|
18
|
+
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
|
|
19
|
+
<Route component={NotFound} />
|
|
20
|
+
</Switch>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default App;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { useNotification, LoadingIndicatorPage } from "@strapi/helper-plugin";
|
|
3
|
+
import { Box } from "@strapi/design-system/Box";
|
|
4
|
+
import { Stack } from "@strapi/design-system/Stack";
|
|
5
|
+
import { Button } from "@strapi/design-system/Button";
|
|
6
|
+
import { Grid, GridItem } from "@strapi/design-system/Grid";
|
|
7
|
+
import { HeaderLayout } from "@strapi/design-system/Layout";
|
|
8
|
+
import { ContentLayout } from "@strapi/design-system/Layout";
|
|
9
|
+
import { Typography } from "@strapi/design-system/Typography";
|
|
10
|
+
import { useIntl } from "react-intl";
|
|
11
|
+
import { getTrad } from "../../utils";
|
|
12
|
+
import { TextInput } from "@strapi/design-system/TextInput";
|
|
13
|
+
import Check from "@strapi/icons/Check";
|
|
14
|
+
import taskRequests from "../../api/settings";
|
|
15
|
+
|
|
16
|
+
const Settings = () => {
|
|
17
|
+
const toggleNotification = useNotification();
|
|
18
|
+
const { formatMessage } = useIntl();
|
|
19
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
20
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
21
|
+
const [currentApiKey, setCurrentApiKey] = useState("");
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setIsLoading(true);
|
|
25
|
+
const getApiKey = async () => {
|
|
26
|
+
const data = await taskRequests.getSettings();
|
|
27
|
+
if (data) {
|
|
28
|
+
setIsLoading(false);
|
|
29
|
+
return setCurrentApiKey(data.data.apiKey);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
getApiKey();
|
|
33
|
+
}, [setCurrentApiKey]);
|
|
34
|
+
|
|
35
|
+
const handleSubmit = async () => {
|
|
36
|
+
setIsSaving(true);
|
|
37
|
+
await taskRequests.setSettings(currentApiKey);
|
|
38
|
+
setIsSaving(false);
|
|
39
|
+
toggleNotification({
|
|
40
|
+
type: "success",
|
|
41
|
+
message: formatMessage({
|
|
42
|
+
id: getTrad("settings.success-message"),
|
|
43
|
+
defaultMessage: "Settings successfully updated",
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleChange = (e) => {
|
|
49
|
+
setCurrentApiKey(() => e.target.value);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<HeaderLayout
|
|
55
|
+
id="title"
|
|
56
|
+
title={formatMessage({
|
|
57
|
+
id: getTrad("settings.title"),
|
|
58
|
+
defaultMessage: "TinyMCE",
|
|
59
|
+
})}
|
|
60
|
+
subtitle={formatMessage({
|
|
61
|
+
id: getTrad("settings.subtitle"),
|
|
62
|
+
defaultMessage:
|
|
63
|
+
"Manage the settings of your TinyMCE plugin",
|
|
64
|
+
})}
|
|
65
|
+
primaryAction={
|
|
66
|
+
isLoading ? (
|
|
67
|
+
<></>
|
|
68
|
+
) : (
|
|
69
|
+
<Button
|
|
70
|
+
onClick={handleSubmit}
|
|
71
|
+
startIcon={<Check />}
|
|
72
|
+
size="L"
|
|
73
|
+
disabled={isSaving}
|
|
74
|
+
loading={isSaving}
|
|
75
|
+
>
|
|
76
|
+
{formatMessage({
|
|
77
|
+
id: getTrad("settings.save-button"),
|
|
78
|
+
defaultMessage: "Save",
|
|
79
|
+
})}
|
|
80
|
+
</Button>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
></HeaderLayout>
|
|
84
|
+
{isLoading ? (
|
|
85
|
+
<LoadingIndicatorPage />
|
|
86
|
+
) : (
|
|
87
|
+
<ContentLayout>
|
|
88
|
+
<Box
|
|
89
|
+
background="neutral0"
|
|
90
|
+
hasRadius
|
|
91
|
+
shadow="filterShadow"
|
|
92
|
+
paddingTop={6}
|
|
93
|
+
paddingBottom={6}
|
|
94
|
+
paddingLeft={7}
|
|
95
|
+
paddingRight={7}
|
|
96
|
+
>
|
|
97
|
+
<Stack size={3}>
|
|
98
|
+
<Typography>
|
|
99
|
+
{formatMessage({
|
|
100
|
+
id: getTrad("settings.content-title"),
|
|
101
|
+
defaultMessage:
|
|
102
|
+
"Set your API key for TinyMCE editor.",
|
|
103
|
+
})}
|
|
104
|
+
</Typography>
|
|
105
|
+
<Grid gap={6}>
|
|
106
|
+
<GridItem col={8} s={18}>
|
|
107
|
+
<TextInput
|
|
108
|
+
id="api-key"
|
|
109
|
+
name="key"
|
|
110
|
+
onChange={handleChange}
|
|
111
|
+
label={formatMessage({
|
|
112
|
+
id: getTrad("settings.input-title"),
|
|
113
|
+
defaultMessage: "API key",
|
|
114
|
+
})}
|
|
115
|
+
value={currentApiKey}
|
|
116
|
+
placeholder={formatMessage({
|
|
117
|
+
id: getTrad(
|
|
118
|
+
"settings.input-placeholder"
|
|
119
|
+
),
|
|
120
|
+
defaultMessage:
|
|
121
|
+
"ex: ADASFNASF46564SAD",
|
|
122
|
+
})}
|
|
123
|
+
/>
|
|
124
|
+
</GridItem>
|
|
125
|
+
</Grid>
|
|
126
|
+
</Stack>
|
|
127
|
+
</Box>
|
|
128
|
+
</ContentLayout>
|
|
129
|
+
)}
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default Settings;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const pluginPermissions = {
|
|
2
|
+
// This permission regards the main component (App) and is used to tell
|
|
3
|
+
// If the plugin link should be displayed in the menu
|
|
4
|
+
// And also if the plugin is accessible. This use case is found when a user types the url of the
|
|
5
|
+
// plugin directly in the browser
|
|
6
|
+
'menu-link': [{ action: 'plugin::tinymce.menu-link', subject: null }],
|
|
7
|
+
settings: [{ action: 'plugin::tinymce.settings.read', subject: null }],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default pluginPermissions;
|
|
11
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"settings.title": "TinyMCE",
|
|
3
|
+
"settings.subtitle": "Úprava nastavení pluginu TinyMCE",
|
|
4
|
+
"settings.content-title": "Nastavení klíče API pro editor TinyMCE.",
|
|
5
|
+
"settings.save-button": "Uložit",
|
|
6
|
+
"settings.input-title": "API klíč",
|
|
7
|
+
"settings.input-placeholder": "např. eegrtg8464asnbvvvfasd46486asldaeerer45888areettzh",
|
|
8
|
+
"settings.success-message": "Nastavení bylo úspěšně uloženo.",
|
|
9
|
+
"settings.page-title": "Konfigurace"
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"settings.title": "TinyMCE",
|
|
3
|
+
"settings.subtitle": "Edit settings of your TinyMCE plugin",
|
|
4
|
+
"settings.content-title": "Set API key for TinyMCE editor.",
|
|
5
|
+
"settings.save-button": "Save",
|
|
6
|
+
"settings.input-title": "API key",
|
|
7
|
+
"settings.input-placeholder": "ex. eegrtg8464asnbvvvfasd46486asldaeerer45888areettzh",
|
|
8
|
+
"settings.success-message": "Settings successfully updated",
|
|
9
|
+
"settings.page-title": "Configuration"
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"settings.title": "TinyMCE",
|
|
3
|
+
"settings.subtitle": "Upravte nastavenia vášho TinyMCE pluginu",
|
|
4
|
+
"settings.content-title": "Nastavte API kľúč pre TinyMCE editor.",
|
|
5
|
+
"settings.save-button": "Uložiť",
|
|
6
|
+
"settings.input-title": "API kľúč",
|
|
7
|
+
"settings.input-placeholder": "napr. eegrtg8464asnbvvvfasd46486asldaeerer45888areettzh",
|
|
8
|
+
"settings.success-message": "Nastavenia boli úspešne uložené.",
|
|
9
|
+
"settings.page-title": "Konfigurácia"
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* axios with a custom config.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import { auth } from '@strapi/helper-plugin';
|
|
7
|
+
|
|
8
|
+
const instance = axios.create({
|
|
9
|
+
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
instance.interceptors.request.use(
|
|
13
|
+
async config => {
|
|
14
|
+
config.headers = {
|
|
15
|
+
Authorization: `Bearer ${auth.getToken()}`,
|
|
16
|
+
Accept: 'application/json',
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return config;
|
|
21
|
+
},
|
|
22
|
+
error => {
|
|
23
|
+
Promise.reject(error);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
instance.interceptors.response.use(
|
|
28
|
+
response => response,
|
|
29
|
+
error => {
|
|
30
|
+
// whatever you want to do with the error
|
|
31
|
+
if (error.response?.status === 401) {
|
|
32
|
+
auth.clearAppStorage();
|
|
33
|
+
window.location.reload();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export default instance;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kookaat/strapi-plugin-tinymce",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Replaces the default Strapi WYSIWYG editor with a customized build of TinyMCE editor.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"keywords": [
|
|
7
|
+
"strapi",
|
|
8
|
+
"tiinymce",
|
|
9
|
+
"tinymce 6",
|
|
10
|
+
"wysiwyg",
|
|
11
|
+
"rich text",
|
|
12
|
+
"editor"
|
|
13
|
+
],
|
|
14
|
+
"strapi": {
|
|
15
|
+
"displayName": "TinyMCE",
|
|
16
|
+
"name": "tinymce",
|
|
17
|
+
"description": "Replaces the default Strapi WYSIWYG editor with a customized build of TinyMCE editor.",
|
|
18
|
+
"kind": "plugin"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@tinymce/tinymce-react": "4.3.2"
|
|
22
|
+
},
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "M.Hossein Zendehpey (forked from SKLINET s.r.o.)",
|
|
25
|
+
"url": "https://github.com/mhzendehpey"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"url": "git+https://github.com/mhzendehpey/strapi-plugin-tinymce"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=14.19.1 <=20.x.x",
|
|
32
|
+
"npm": ">=6.0.0"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT"
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = async ({ strapi }) => {
|
|
4
|
+
const actions = [
|
|
5
|
+
{
|
|
6
|
+
section: "plugins",
|
|
7
|
+
displayName: "Access the plugin settings",
|
|
8
|
+
uid: "settings.read",
|
|
9
|
+
pluginName: "tinymce",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
section: "plugins",
|
|
13
|
+
displayName: "Menu link to plugin settings",
|
|
14
|
+
uid: "menu-link",
|
|
15
|
+
pluginName: "tinymce",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
|
19
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
getSettings: async (ctx) => {
|
|
5
|
+
try {
|
|
6
|
+
ctx.body = await strapi
|
|
7
|
+
.plugin("tinymce")
|
|
8
|
+
.service("settings")
|
|
9
|
+
.getSettings();
|
|
10
|
+
} catch (err) {
|
|
11
|
+
ctx.body = err;
|
|
12
|
+
ctx.throw(500, err);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
setSettings: async (ctx) => {
|
|
16
|
+
const { body } = ctx.request;
|
|
17
|
+
try {
|
|
18
|
+
await strapi
|
|
19
|
+
.plugin("tinymce")
|
|
20
|
+
.service("settings")
|
|
21
|
+
.setSettings(body);
|
|
22
|
+
ctx.body = await strapi
|
|
23
|
+
.plugin("tinymce")
|
|
24
|
+
.service("settings")
|
|
25
|
+
.getSettings();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
ctx.throw(500, err);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
package/server/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const register = require('./register');
|
|
4
|
+
const bootstrap = require('./bootstrap');
|
|
5
|
+
const destroy = require('./destroy');
|
|
6
|
+
const config = require('./config');
|
|
7
|
+
const contentTypes = require('./content-types');
|
|
8
|
+
const controllers = require('./controllers');
|
|
9
|
+
const routes = require('./routes');
|
|
10
|
+
const middlewares = require('./middlewares');
|
|
11
|
+
const policies = require('./policies');
|
|
12
|
+
const services = require('./services');
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
register,
|
|
16
|
+
bootstrap,
|
|
17
|
+
destroy,
|
|
18
|
+
config,
|
|
19
|
+
controllers,
|
|
20
|
+
routes,
|
|
21
|
+
services,
|
|
22
|
+
contentTypes,
|
|
23
|
+
policies,
|
|
24
|
+
middlewares,
|
|
25
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
type: "admin",
|
|
3
|
+
routes: [
|
|
4
|
+
{
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: "/settings",
|
|
7
|
+
handler: "settings.getSettings",
|
|
8
|
+
config: {
|
|
9
|
+
policies: [],
|
|
10
|
+
auth: false,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
method: "POST",
|
|
15
|
+
path: "/settings",
|
|
16
|
+
handler: "settings.setSettings",
|
|
17
|
+
config: {
|
|
18
|
+
policies: [],
|
|
19
|
+
auth: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function getPluginStore() {
|
|
4
|
+
return strapi.store({
|
|
5
|
+
environment: "",
|
|
6
|
+
type: "plugin",
|
|
7
|
+
name: "tinymce",
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async function createDefaultConfig() {
|
|
11
|
+
const pluginStore = getPluginStore();
|
|
12
|
+
const value = {
|
|
13
|
+
apiKey: "",
|
|
14
|
+
};
|
|
15
|
+
await pluginStore.set({ key: "settings", value });
|
|
16
|
+
return pluginStore.get({ key: "settings" });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = () => {
|
|
20
|
+
return {
|
|
21
|
+
async getSettings() {
|
|
22
|
+
const pluginStore = getPluginStore();
|
|
23
|
+
let config = await pluginStore.get({ key: "settings" });
|
|
24
|
+
if (!config) {
|
|
25
|
+
config = await createDefaultConfig();
|
|
26
|
+
}
|
|
27
|
+
return config;
|
|
28
|
+
},
|
|
29
|
+
async setSettings(settings) {
|
|
30
|
+
const value = settings;
|
|
31
|
+
const pluginStore = getPluginStore();
|
|
32
|
+
await pluginStore.set({ key: "settings", value });
|
|
33
|
+
return pluginStore.get({ key: "settings" });
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
package/strapi-admin.js
ADDED
package/strapi-server.js
ADDED