@_sh/strapi-plugin-ckeditor 2.0.3 → 2.0.4

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.
Files changed (34) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +448 -448
  3. package/admin/src/components/CKEditorIcon.js +45 -45
  4. package/admin/src/components/Input/CKEditor/configs/base.js +627 -627
  5. package/admin/src/components/Input/CKEditor/configs/blockBaloon.js +25 -25
  6. package/admin/src/components/Input/CKEditor/configs/index.js +11 -11
  7. package/admin/src/components/Input/CKEditor/configs/toolbar.js +17 -17
  8. package/admin/src/components/Input/CKEditor/configs/toolbarBaloon.js +17 -17
  9. package/admin/src/components/Input/CKEditor/configuration.js +165 -165
  10. package/admin/src/components/Input/CKEditor/index.js +119 -119
  11. package/admin/src/components/Input/CKEditor/plugins/StrapiMediaLib.js +43 -43
  12. package/admin/src/components/Input/CKEditor/plugins/StrapiUploadAdapter.js +204 -203
  13. package/admin/src/components/Input/CKEditor/plugins/index.js +1 -1
  14. package/admin/src/components/Input/CKEditor/styling.js +16 -16
  15. package/admin/src/components/Input/CKEditor/theme/additional.js +212 -212
  16. package/admin/src/components/Input/CKEditor/theme/common.js +232 -232
  17. package/admin/src/components/Input/CKEditor/theme/dark.js +144 -144
  18. package/admin/src/components/Input/CKEditor/theme/index.js +12 -12
  19. package/admin/src/components/Input/CKEditor/theme/light.js +135 -135
  20. package/admin/src/components/Input/MediaLib/index.js +78 -78
  21. package/admin/src/components/Input/index.js +47 -47
  22. package/admin/src/index.js +109 -109
  23. package/admin/src/utils/getEditorConfig.js +37 -37
  24. package/admin/src/utils/pluginId.js +4 -4
  25. package/package.json +86 -86
  26. package/server/controllers/config.js +16 -16
  27. package/server/controllers/index.js +7 -7
  28. package/server/index.js +13 -13
  29. package/server/register.js +11 -11
  30. package/server/routes/index.js +15 -15
  31. package/server/services/config.js +19 -19
  32. package/server/services/index.js +7 -7
  33. package/strapi-admin.js +3 -3
  34. package/strapi-server.js +3 -3
@@ -1,203 +1,204 @@
1
- const Plugin = window.CKEditor5.core.Plugin;
2
- const FileRepository = window.CKEditor5.upload.FileRepository;
3
-
4
- /**
5
- * Similar to Simple upload adapter but customized for Strapi.
6
- * Inspired by https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-upload/src/adapters/simpleuploadadapter.js
7
- */
8
- export default class StrapiUploadAdapter extends Plugin {
9
- /**
10
- * @inheritDoc
11
- */
12
- static get requires() {
13
- return [FileRepository];
14
- }
15
-
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName() {
20
- return "StrapiUploadAdapter";
21
- }
22
-
23
- /**
24
- * @inheritDoc
25
- */
26
- init() {
27
-
28
- // backendUrl
29
- // uploadUrl
30
- // headers
31
- // responsive
32
-
33
- const options = this.editor.config.get("strapiUploadAdapter");
34
-
35
- if (!options) {
36
- return;
37
- }
38
-
39
- if (!options.uploadUrl) {
40
- console.warn(
41
- 'strapi-upload-adapter-missing-uploadUrl: Missing the "uploadUrl" property in the "strapiUploadAdapter" editor configuration.'
42
- );
43
-
44
- return;
45
- }
46
-
47
- this.editor.plugins.get(FileRepository).createUploadAdapter = (loader) => {
48
- return new Adapter(loader, options);
49
- };
50
- }
51
- }
52
-
53
- /**
54
- * Upload adapter.
55
- *
56
- * @private
57
- */
58
- class Adapter {
59
- /**
60
- * Creates a new adapter instance.
61
- */
62
- constructor(loader, options) {
63
- /**
64
- * FileLoader instance to use during the upload.
65
- *
66
- */
67
- this.loader = loader;
68
-
69
- /**
70
- * The configuration of the adapter.
71
- *
72
- */
73
- this.options = options;
74
- }
75
-
76
- /**
77
- * Starts the upload process.
78
- *
79
- * @returns {Promise}
80
- */
81
- upload() {
82
- return this.loader.file.then(
83
- (file) =>
84
- new Promise((resolve, reject) => {
85
- this._initRequest();
86
- this._initListeners(resolve, reject, file);
87
- this._sendRequest(file);
88
- })
89
- );
90
- }
91
-
92
- /**
93
- * Aborts the upload process.
94
- *
95
- * @returns {Promise}
96
- */
97
- abort() {
98
- if (this.xhr) {
99
- this.xhr.abort();
100
- }
101
- }
102
-
103
- /**
104
- * Initializes the `XMLHttpRequest` object using the URL specified as
105
- * `strapiUpload.uploadUrl` in the editor's
106
- * configuration.
107
- *
108
- * @private
109
- */
110
- _initRequest() {
111
- const xhr = (this.xhr = new XMLHttpRequest());
112
-
113
- xhr.open("POST", this.options.uploadUrl, true);
114
- xhr.responseType = "json";
115
- }
116
-
117
- /**
118
- * Initializes XMLHttpRequest listeners
119
- *
120
- * @private
121
- * @param {Function} resolve Callback function to be called when the request is successful.
122
- * @param {Function} reject Callback function to be called when the request cannot be completed.
123
- * @param {File} file Native File object.
124
- */
125
- _initListeners(resolve, reject, file) {
126
- const xhr = this.xhr;
127
- const loader = this.loader;
128
- const genericErrorText = `Couldn't upload file: ${file.name}.`;
129
-
130
- xhr.addEventListener("error", () => reject(genericErrorText));
131
- xhr.addEventListener("abort", () => reject());
132
- xhr.addEventListener("load", () => {
133
- const response = xhr.response;
134
-
135
- if (!Array.isArray(response) || response.error || response.length !== 1) {
136
- return reject(
137
- response && response.error && response.error.message
138
- ? response.error.message
139
- : genericErrorText
140
- );
141
- }
142
-
143
-
144
- const { backendUrl, responsive } = this.options || {};
145
-
146
- if (response[0].formats && responsive) {
147
- const { name, url, alternativeText, formats } = response[0];
148
- let urls = { default: backendUrl + url };
149
- let keys = Object.keys(formats).sort((a, b) => formats[a].width - formats[b].width);
150
- keys.map((k) => (urls[formats[k].width] = backendUrl + formats[k].url));
151
- resolve({ alt: alternativeText || name, urls: urls });
152
- } else {
153
- resolve(
154
- response[0].url
155
- ? {
156
- alt: response[0].alternativeText || response[0].name,
157
- urls: { default: backendUrl + response[0].url },
158
- }
159
- : null
160
- );
161
- }
162
- });
163
-
164
- // Upload progress when it is supported.
165
- /* istanbul ignore else */
166
- if (xhr.upload) {
167
- xhr.upload.addEventListener("progress", (evt) => {
168
- if (evt.lengthComputable) {
169
- loader.uploadTotal = evt.total;
170
- loader.uploaded = evt.loaded;
171
- }
172
- });
173
- }
174
- }
175
-
176
- /**
177
- * Prepares the data and sends the request.
178
- *
179
- * @private
180
- * @param {File} file File instance to be uploaded.
181
- */
182
- _sendRequest(file) {
183
- // Set headers if specified.
184
- const headers = this.options.headers || {};
185
-
186
- // Use the withCredentials flag if specified.
187
- const withCredentials = this.options.withCredentials || false;
188
-
189
- for (const headerName of Object.keys(headers)) {
190
- this.xhr.setRequestHeader(headerName, headers[headerName]);
191
- }
192
-
193
- this.xhr.withCredentials = withCredentials;
194
-
195
- // Prepare the form data.
196
- const data = new FormData();
197
-
198
- data.append("files", file);
199
-
200
- // Send the request.
201
- this.xhr.send(data);
202
- }
203
- }
1
+ const Plugin = window.CKEditor5.core.Plugin;
2
+ const FileRepository = window.CKEditor5.upload.FileRepository;
3
+
4
+ /**
5
+ * Similar to Simple upload adapter but customized for Strapi.
6
+ * Inspired by https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-upload/src/adapters/simpleuploadadapter.js
7
+ */
8
+ export default class StrapiUploadAdapter extends Plugin {
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ static get requires() {
13
+ return [FileRepository];
14
+ }
15
+
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName() {
20
+ return "StrapiUploadAdapter";
21
+ }
22
+
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ init() {
27
+ // backendUrl
28
+ // uploadUrl
29
+ // headers
30
+ // responsive
31
+
32
+ const options = this.editor.config.get("strapiUploadAdapter");
33
+
34
+ if (!options) {
35
+ return;
36
+ }
37
+
38
+ if (!options.uploadUrl) {
39
+ console.warn(
40
+ 'strapi-upload-adapter-missing-uploadUrl: Missing the "uploadUrl" property in the "strapiUploadAdapter" editor configuration.'
41
+ );
42
+
43
+ return;
44
+ }
45
+
46
+ this.editor.plugins.get(FileRepository).createUploadAdapter = (loader) => {
47
+ return new Adapter(loader, options);
48
+ };
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Upload adapter.
54
+ *
55
+ * @private
56
+ */
57
+ class Adapter {
58
+ /**
59
+ * Creates a new adapter instance.
60
+ */
61
+ constructor(loader, options) {
62
+ /**
63
+ * FileLoader instance to use during the upload.
64
+ *
65
+ */
66
+ this.loader = loader;
67
+
68
+ /**
69
+ * The configuration of the adapter.
70
+ *
71
+ */
72
+ this.options = options;
73
+ }
74
+
75
+ /**
76
+ * Starts the upload process.
77
+ *
78
+ * @returns {Promise}
79
+ */
80
+ upload() {
81
+ return this.loader.file.then(
82
+ (file) =>
83
+ new Promise((resolve, reject) => {
84
+ this._initRequest();
85
+ this._initListeners(resolve, reject, file);
86
+ this._sendRequest(file);
87
+ })
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Aborts the upload process.
93
+ *
94
+ * @returns {Promise}
95
+ */
96
+ abort() {
97
+ if (this.xhr) {
98
+ this.xhr.abort();
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Initializes the `XMLHttpRequest` object using the URL specified as
104
+ * `strapiUpload.uploadUrl` in the editor's
105
+ * configuration.
106
+ *
107
+ * @private
108
+ */
109
+ _initRequest() {
110
+ const xhr = (this.xhr = new XMLHttpRequest());
111
+
112
+ xhr.open("POST", this.options.uploadUrl, true);
113
+ xhr.responseType = "json";
114
+ }
115
+
116
+ /**
117
+ * Initializes XMLHttpRequest listeners
118
+ *
119
+ * @private
120
+ * @param {Function} resolve Callback function to be called when the request is successful.
121
+ * @param {Function} reject Callback function to be called when the request cannot be completed.
122
+ * @param {File} file Native File object.
123
+ */
124
+ _initListeners(resolve, reject, file) {
125
+ const xhr = this.xhr;
126
+ const loader = this.loader;
127
+ const genericErrorText = `Couldn't upload file: ${file.name}.`;
128
+
129
+ xhr.addEventListener("error", () => reject(genericErrorText));
130
+ xhr.addEventListener("abort", () => reject());
131
+ xhr.addEventListener("load", () => {
132
+ const response = xhr.response;
133
+
134
+ if (!Array.isArray(response) || response.error || response.length !== 1) {
135
+ return reject(
136
+ response && response.error && response.error.message
137
+ ? response.error.message
138
+ : genericErrorText
139
+ );
140
+ }
141
+
142
+ const { backendUrl, responsive } = this.options || {};
143
+ const { name, url, alternativeText, formats, provider } = response[0];
144
+ const defaultUrl = provider !== "local" ? url : backendUrl + url;
145
+
146
+ if (formats && responsive) {
147
+ let urls = { default: defaultUrl };
148
+ let keys = Object.keys(formats).sort(
149
+ (a, b) => formats[a].width - formats[b].width
150
+ );
151
+ keys.map((k) => (urls[formats[k].width] = backendUrl + formats[k].url));
152
+ resolve({ alt: alternativeText || name, urls: urls });
153
+ } else {
154
+ resolve(
155
+ url
156
+ ? {
157
+ alt: alternativeText || name,
158
+ urls: { default: defaultUrl },
159
+ }
160
+ : null
161
+ );
162
+ }
163
+ });
164
+
165
+ // Upload progress when it is supported.
166
+ /* istanbul ignore else */
167
+ if (xhr.upload) {
168
+ xhr.upload.addEventListener("progress", (evt) => {
169
+ if (evt.lengthComputable) {
170
+ loader.uploadTotal = evt.total;
171
+ loader.uploaded = evt.loaded;
172
+ }
173
+ });
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Prepares the data and sends the request.
179
+ *
180
+ * @private
181
+ * @param {File} file File instance to be uploaded.
182
+ */
183
+ _sendRequest(file) {
184
+ // Set headers if specified.
185
+ const headers = this.options.headers || {};
186
+
187
+ // Use the withCredentials flag if specified.
188
+ const withCredentials = this.options.withCredentials || false;
189
+
190
+ for (const headerName of Object.keys(headers)) {
191
+ this.xhr.setRequestHeader(headerName, headers[headerName]);
192
+ }
193
+
194
+ this.xhr.withCredentials = withCredentials;
195
+
196
+ // Prepare the form data.
197
+ const data = new FormData();
198
+
199
+ data.append("files", file);
200
+
201
+ // Send the request.
202
+ this.xhr.send(data);
203
+ }
204
+ }
@@ -1,2 +1,2 @@
1
- export { default as StrapiMediaLib } from './StrapiMediaLib';
1
+ export { default as StrapiMediaLib } from './StrapiMediaLib';
2
2
  export { default as StrapiUploadAdapter } from './StrapiUploadAdapter';
@@ -1,16 +1,16 @@
1
- import baseTheme from "./theme";
2
- import { createGlobalStyle } from "styled-components";
3
-
4
- export const getGlobalStyling = () => {
5
-
6
- const variant = localStorage.getItem("STRAPI_THEME") || "light";
7
- const { theme: userTheme, themeOverwrite: overwrite } = globalThis.CKEditorConfig || {};
8
-
9
- const theme = overwrite ? userTheme : { ...baseTheme, ...userTheme};
10
-
11
- return createGlobalStyle`
12
- ${theme.common}
13
- ${theme[variant]}
14
- ${theme.additional}
15
- `;
16
- }
1
+ import baseTheme from "./theme";
2
+ import { createGlobalStyle } from "styled-components";
3
+
4
+ export const getGlobalStyling = () => {
5
+
6
+ const variant = localStorage.getItem("STRAPI_THEME") || "light";
7
+ const { theme: userTheme, themeOverwrite: overwrite } = globalThis.CKEditorConfig || {};
8
+
9
+ const theme = overwrite ? userTheme : { ...baseTheme, ...userTheme};
10
+
11
+ return createGlobalStyle`
12
+ ${theme.common}
13
+ ${theme[variant]}
14
+ ${theme.additional}
15
+ `;
16
+ }