@_sh/strapi-plugin-ckeditor 3.0.2 → 4.0.1

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 (180) hide show
  1. package/README.md +19 -31
  2. package/dist/_chunks/index-6GKiz6cY.js +3647 -0
  3. package/dist/_chunks/index-6GKiz6cY.js.map +1 -0
  4. package/dist/_chunks/index-88tSNjQp.mjs +3628 -0
  5. package/dist/_chunks/index-88tSNjQp.mjs.map +1 -0
  6. package/dist/_chunks/index-8de5gkF9.mjs +3628 -0
  7. package/dist/_chunks/index-8de5gkF9.mjs.map +1 -0
  8. package/dist/_chunks/index-AiU03Dmr.js +3647 -0
  9. package/dist/_chunks/index-AiU03Dmr.js.map +1 -0
  10. package/dist/_chunks/index-B-AZlEPV.js +1256 -0
  11. package/dist/_chunks/index-B-AZlEPV.js.map +1 -0
  12. package/dist/_chunks/index-B6H3etpg.mjs +1218 -0
  13. package/dist/_chunks/index-B6H3etpg.mjs.map +1 -0
  14. package/dist/_chunks/index-BDk31lQx.js +1261 -0
  15. package/dist/_chunks/index-BDk31lQx.js.map +1 -0
  16. package/dist/_chunks/index-BK-4ClHX.mjs +3628 -0
  17. package/dist/_chunks/index-BK-4ClHX.mjs.map +1 -0
  18. package/dist/_chunks/index-BMV2FE8e.js +1257 -0
  19. package/dist/_chunks/index-BMV2FE8e.js.map +1 -0
  20. package/dist/_chunks/index-BMsF7dur.mjs +3628 -0
  21. package/dist/_chunks/index-BMsF7dur.mjs.map +1 -0
  22. package/dist/_chunks/index-BOIHTrHJ.js +3647 -0
  23. package/dist/_chunks/index-BOIHTrHJ.js.map +1 -0
  24. package/dist/_chunks/index-BRZDHDl3.mjs +1213 -0
  25. package/dist/_chunks/index-BRZDHDl3.mjs.map +1 -0
  26. package/dist/_chunks/index-BX55VolO.js +3647 -0
  27. package/dist/_chunks/index-BX55VolO.js.map +1 -0
  28. package/dist/_chunks/index-BY10-Cga.mjs +3628 -0
  29. package/dist/_chunks/index-BY10-Cga.mjs.map +1 -0
  30. package/dist/_chunks/index-BZxesXdY.js +1256 -0
  31. package/dist/_chunks/index-BZxesXdY.js.map +1 -0
  32. package/dist/_chunks/index-BlEv36uB.mjs +3628 -0
  33. package/dist/_chunks/index-BlEv36uB.mjs.map +1 -0
  34. package/dist/_chunks/index-BncqbPd9.mjs +1214 -0
  35. package/dist/_chunks/index-BncqbPd9.mjs.map +1 -0
  36. package/dist/_chunks/index-BobGpej6.js +1261 -0
  37. package/dist/_chunks/index-BobGpej6.js.map +1 -0
  38. package/dist/_chunks/index-C8oS3yBE.js +3647 -0
  39. package/dist/_chunks/index-C8oS3yBE.js.map +1 -0
  40. package/dist/_chunks/index-C9I_GZDt.mjs +1213 -0
  41. package/dist/_chunks/index-C9I_GZDt.mjs.map +1 -0
  42. package/dist/_chunks/index-CF-Azguy.mjs +3628 -0
  43. package/dist/_chunks/index-CF-Azguy.mjs.map +1 -0
  44. package/dist/_chunks/index-CFoWn2JU.mjs +1213 -0
  45. package/dist/_chunks/index-CFoWn2JU.mjs.map +1 -0
  46. package/dist/_chunks/index-CFz4k_o3.js +3647 -0
  47. package/dist/_chunks/index-CFz4k_o3.js.map +1 -0
  48. package/dist/_chunks/index-CNmTM2xx.js +1256 -0
  49. package/dist/_chunks/index-CNmTM2xx.js.map +1 -0
  50. package/dist/_chunks/index-COE8JbTB.mjs +3628 -0
  51. package/dist/_chunks/index-COE8JbTB.mjs.map +1 -0
  52. package/dist/_chunks/index-CPar_9LG.mjs +3628 -0
  53. package/dist/_chunks/index-CPar_9LG.mjs.map +1 -0
  54. package/dist/_chunks/index-CUX9tnEj.js +3647 -0
  55. package/dist/_chunks/index-CUX9tnEj.js.map +1 -0
  56. package/dist/_chunks/index-C_IgfuSF.mjs +1218 -0
  57. package/dist/_chunks/index-C_IgfuSF.mjs.map +1 -0
  58. package/dist/_chunks/index-CfK7a1JV.mjs +3628 -0
  59. package/dist/_chunks/index-CfK7a1JV.mjs.map +1 -0
  60. package/dist/_chunks/index-Chvcr1Q8.mjs +1213 -0
  61. package/dist/_chunks/index-Chvcr1Q8.mjs.map +1 -0
  62. package/dist/_chunks/index-Ci-OYPN5.js +1261 -0
  63. package/dist/_chunks/index-Ci-OYPN5.js.map +1 -0
  64. package/dist/_chunks/index-CiyKc7gG.mjs +1218 -0
  65. package/dist/_chunks/index-CiyKc7gG.mjs.map +1 -0
  66. package/dist/_chunks/index-CkSveLKM.js +1256 -0
  67. package/dist/_chunks/index-CkSveLKM.js.map +1 -0
  68. package/dist/_chunks/index-ClOkZMy2.js +1257 -0
  69. package/dist/_chunks/index-ClOkZMy2.js.map +1 -0
  70. package/dist/_chunks/index-CmRSokx-.mjs +3628 -0
  71. package/dist/_chunks/index-CmRSokx-.mjs.map +1 -0
  72. package/dist/_chunks/index-CoLJ0c_K.mjs +3628 -0
  73. package/dist/_chunks/index-CoLJ0c_K.mjs.map +1 -0
  74. package/dist/_chunks/index-Crf1SAxV.js +1256 -0
  75. package/dist/_chunks/index-Crf1SAxV.js.map +1 -0
  76. package/dist/_chunks/index-Cuj1hkXo.js +3647 -0
  77. package/dist/_chunks/index-Cuj1hkXo.js.map +1 -0
  78. package/dist/_chunks/index-CzfnZXVp.mjs +1214 -0
  79. package/dist/_chunks/index-CzfnZXVp.mjs.map +1 -0
  80. package/dist/_chunks/index-D6icTfF7.mjs +1213 -0
  81. package/dist/_chunks/index-D6icTfF7.mjs.map +1 -0
  82. package/dist/_chunks/index-DBSs0Gnl.js +3647 -0
  83. package/dist/_chunks/index-DBSs0Gnl.js.map +1 -0
  84. package/dist/_chunks/index-DDLPHkG8.mjs +3628 -0
  85. package/dist/_chunks/index-DDLPHkG8.mjs.map +1 -0
  86. package/dist/_chunks/index-DEPzWnu9.mjs +1140 -0
  87. package/dist/_chunks/index-DEPzWnu9.mjs.map +1 -0
  88. package/dist/_chunks/index-DGwUX_So.mjs +3628 -0
  89. package/dist/_chunks/index-DGwUX_So.mjs.map +1 -0
  90. package/dist/_chunks/index-DInf_l3P.js +1256 -0
  91. package/dist/_chunks/index-DInf_l3P.js.map +1 -0
  92. package/dist/_chunks/index-DJYtETYy.js +1257 -0
  93. package/dist/_chunks/index-DJYtETYy.js.map +1 -0
  94. package/dist/_chunks/index-DRQ1Oiuk.mjs +1213 -0
  95. package/dist/_chunks/index-DRQ1Oiuk.mjs.map +1 -0
  96. package/dist/_chunks/index-DV-2r9Hy.js +3647 -0
  97. package/dist/_chunks/index-DV-2r9Hy.js.map +1 -0
  98. package/dist/_chunks/index-DW4Jea16.js +3647 -0
  99. package/dist/_chunks/index-DW4Jea16.js.map +1 -0
  100. package/dist/_chunks/index-DXE6Lrtc.js +1256 -0
  101. package/dist/_chunks/index-DXE6Lrtc.js.map +1 -0
  102. package/dist/_chunks/index-DXjWTjxi.mjs +3631 -0
  103. package/dist/_chunks/index-DXjWTjxi.mjs.map +1 -0
  104. package/dist/_chunks/index-Dft0hXXB.js +1161 -0
  105. package/dist/_chunks/index-Dft0hXXB.js.map +1 -0
  106. package/dist/_chunks/index-Dxy-LpJ1.js +3647 -0
  107. package/dist/_chunks/index-Dxy-LpJ1.js.map +1 -0
  108. package/dist/_chunks/index-Dyf9KscK.js +3647 -0
  109. package/dist/_chunks/index-Dyf9KscK.js.map +1 -0
  110. package/dist/_chunks/index-EuuMGGNf.js +3647 -0
  111. package/dist/_chunks/index-EuuMGGNf.js.map +1 -0
  112. package/dist/_chunks/index-G6Uc7lRl.mjs +3628 -0
  113. package/dist/_chunks/index-G6Uc7lRl.mjs.map +1 -0
  114. package/dist/_chunks/index-GPNqedia.js +1261 -0
  115. package/dist/_chunks/index-GPNqedia.js.map +1 -0
  116. package/dist/_chunks/index-NEZx9UPK.js +1261 -0
  117. package/dist/_chunks/index-NEZx9UPK.js.map +1 -0
  118. package/dist/_chunks/index-PZvU_oD7.mjs +1214 -0
  119. package/dist/_chunks/index-PZvU_oD7.mjs.map +1 -0
  120. package/dist/_chunks/index-RE5thGuk.js +3647 -0
  121. package/dist/_chunks/index-RE5thGuk.js.map +1 -0
  122. package/dist/_chunks/index-d1OvLlJZ.mjs +1213 -0
  123. package/dist/_chunks/index-d1OvLlJZ.mjs.map +1 -0
  124. package/dist/_chunks/index-h-Dr31Du.js +3650 -0
  125. package/dist/_chunks/index-h-Dr31Du.js.map +1 -0
  126. package/dist/_chunks/index-hk2wduq_.mjs +3628 -0
  127. package/dist/_chunks/index-hk2wduq_.mjs.map +1 -0
  128. package/dist/_chunks/index-hn4KADGH.mjs +1140 -0
  129. package/dist/_chunks/index-hn4KADGH.mjs.map +1 -0
  130. package/dist/_chunks/index-jZK-hYWE.mjs +1218 -0
  131. package/dist/_chunks/index-jZK-hYWE.mjs.map +1 -0
  132. package/dist/_chunks/index-skWYpmqI.mjs +1218 -0
  133. package/dist/_chunks/index-skWYpmqI.mjs.map +1 -0
  134. package/dist/_chunks/index-uDuIQr5g.js +1161 -0
  135. package/dist/_chunks/index-uDuIQr5g.js.map +1 -0
  136. package/dist/_chunks/index-vi6AKD87.js +3647 -0
  137. package/dist/_chunks/index-vi6AKD87.js.map +1 -0
  138. package/dist/admin/index.js +5 -0
  139. package/dist/admin/index.js.map +1 -0
  140. package/dist/admin/index.mjs +6 -0
  141. package/dist/admin/index.mjs.map +1 -0
  142. package/dist/server/index.js +183 -0
  143. package/dist/server/index.js.map +1 -0
  144. package/dist/server/index.mjs +182 -0
  145. package/dist/server/index.mjs.map +1 -0
  146. package/package.json +53 -24
  147. package/strapi-server.js +2 -2
  148. package/admin/src/CKEditorIcon.js +0 -46
  149. package/admin/src/Input/components/Editor.js +0 -133
  150. package/admin/src/Input/components/MediaLib.js +0 -69
  151. package/admin/src/Input/config/index.js +0 -2
  152. package/admin/src/Input/config/language.js +0 -45
  153. package/admin/src/Input/config/plugins.js +0 -24
  154. package/admin/src/Input/config/presets.js +0 -18
  155. package/admin/src/Input/config/styling.js +0 -30
  156. package/admin/src/Input/index.js +0 -67
  157. package/admin/src/Input/plugins/StrapiMediaLib.js +0 -41
  158. package/admin/src/Input/plugins/StrapiUploadAdapter.js +0 -186
  159. package/admin/src/Input/plugins/index.js +0 -2
  160. package/admin/src/Input/presets/colors.js +0 -122
  161. package/admin/src/Input/presets/default.js +0 -378
  162. package/admin/src/Input/presets/index.js +0 -7
  163. package/admin/src/Input/theme/additional.js +0 -189
  164. package/admin/src/Input/theme/common.js +0 -230
  165. package/admin/src/Input/theme/dark.js +0 -149
  166. package/admin/src/Input/theme/index.js +0 -13
  167. package/admin/src/Input/theme/light.js +0 -144
  168. package/admin/src/index.js +0 -80
  169. package/admin/src/pluginId.js +0 -7
  170. package/admin/src/utils/exportToGlobal.js +0 -8
  171. package/admin/src/utils/getPluginConfig.js +0 -35
  172. package/admin/src/utils/getPresetsOptions.js +0 -38
  173. package/server/controllers/config.js +0 -19
  174. package/server/controllers/index.js +0 -7
  175. package/server/index.js +0 -13
  176. package/server/register.js +0 -11
  177. package/server/routes/index.js +0 -10
  178. package/server/services/config.js +0 -25
  179. package/server/services/index.js +0 -7
  180. package/strapi-admin.js +0 -3
@@ -1,133 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import styled from 'styled-components';
4
- import { CKEditor } from '@ckeditor/ckeditor5-react';
5
- import { ClassicEditor } from 'ckeditor5';
6
- import { Box, Loader } from '@strapi/design-system';
7
- import 'ckeditor5/ckeditor5.css';
8
-
9
- import { MediaLib } from './MediaLib';
10
- import { getConfiguredPreset, GlobalStyling } from '../config';
11
-
12
- const Wrapper = styled('div')`
13
- ${({ styles }) => styles}
14
- `;
15
-
16
- export const Editor = ({
17
- onChange,
18
- name,
19
- value = '',
20
- disabled = false,
21
- presetName,
22
- maxLength,
23
- }) => {
24
- const [editorInstance, setEditorInstance] = useState(false);
25
-
26
- const [mediaLibVisible, setMediaLibVisible] = useState(false);
27
-
28
- const [preset, setPreset] = useState(null);
29
-
30
- const [lengthMax, setLengthMax] = useState(false);
31
-
32
- const wordCounter = useRef(null);
33
-
34
- const handleToggleMediaLib = () => setMediaLibVisible((prev) => !prev);
35
-
36
- const handleCounter = (number) =>
37
- number > maxLength ? setLengthMax(true) : setLengthMax(false);
38
-
39
- useEffect(() => {
40
- (async () => {
41
- const currentPreset = await getConfiguredPreset(
42
- presetName,
43
- handleToggleMediaLib
44
- );
45
- setPreset(currentPreset);
46
- })();
47
- }, []);
48
-
49
- return (
50
- <>
51
- {preset && <GlobalStyling />}
52
- <Wrapper styles={preset?.styles}>
53
- {!preset && (
54
- <LoaderBox hasRadius background="neutral100">
55
- <Loader>Loading...</Loader>
56
- </LoaderBox>
57
- )}
58
- {preset && (
59
- <>
60
- <CKEditor
61
- editor={ClassicEditor}
62
- config={preset.editorConfig}
63
- disabled={disabled}
64
- data={value}
65
- onReady={(editor) => {
66
- if (preset.editorConfig.WordCountPlugin) {
67
- const wordCountPlugin = editor.plugins.get('WordCount');
68
- wordCountPlugin.on('update', (evt, stats) =>
69
- handleCounter(stats.characters)
70
- );
71
- const wordCountWrapper = wordCounter.current;
72
- wordCountWrapper?.appendChild(
73
- wordCountPlugin.wordCountContainer
74
- );
75
- }
76
-
77
- if (editor.plugins.has('ImageUploadEditing')) {
78
- editor.plugins
79
- .get('ImageUploadEditing')
80
- .on('uploadComplete', (evt, { data, imageElement }) =>
81
- editor.model.change((writer) =>
82
- writer.setAttribute('alt', data.alt, imageElement)
83
- )
84
- );
85
- }
86
-
87
- setEditorInstance(editor);
88
- }}
89
- onChange={(event, editor) => {
90
- const data = editor.getData();
91
- onChange({ target: { name, value: data } });
92
- }}
93
- />
94
- <MediaLib
95
- isOpen={mediaLibVisible}
96
- onToggle={handleToggleMediaLib}
97
- editor={editorInstance}
98
- />
99
- {preset.editorConfig.WordCountPlugin && (
100
- <CounterLoaderBox
101
- color={lengthMax ? 'danger500' : 'neutral400'}
102
- ref={wordCounter}
103
- >
104
- {!editorInstance && <Loader small>Loading...</Loader>}
105
- </CounterLoaderBox>
106
- )}
107
- </>
108
- )}
109
- </Wrapper>
110
- </>
111
- );
112
- };
113
-
114
- Editor.propTypes = {
115
- onChange: PropTypes.func.isRequired,
116
- fieldName: PropTypes.string.isRequired,
117
- value: PropTypes.string,
118
- disabled: PropTypes.bool,
119
- };
120
-
121
- const CounterLoaderBox = styled(Box)`
122
- display: flex;
123
- width: 100%;
124
- justify-content: flex-end;
125
- align-items: center;
126
- `;
127
- const LoaderBox = styled(Box)`
128
- display: flex;
129
- height: 200px;
130
- width: 100%;
131
- justify-content: center;
132
- align-items: center;
133
- `;
@@ -1,69 +0,0 @@
1
- import React from 'react';
2
- import { prefixFileUrlWithBackendUrl, useLibrary } from '@strapi/helper-plugin';
3
- import PropTypes from 'prop-types';
4
-
5
- export const MediaLib = ({ isOpen = false, onToggle = () => {}, editor }) => {
6
- const { components } = useLibrary();
7
- const MediaLibraryDialog = components['media-library'];
8
-
9
- const handleChangeAssets = (assets) => {
10
- let newValue = '';
11
-
12
- assets.map(({ name, url, alt, formats, mime, width, height }) => {
13
- if (mime.includes('image')) {
14
- if (formats && globalThis.SH_CKE_UPLOAD_ADAPTER_IS_RESPONSIVE) {
15
- let set = '';
16
- let keys = Object.keys(formats).sort((a, b) => formats[a].width - formats[b].width);
17
- keys.map((k) => (set += prefixFileUrlWithBackendUrl(formats[k].url) +` ${formats[k].width}w,`));
18
- newValue = `<img src="${prefixFileUrlWithBackendUrl(url)}" alt="${alt}" width="${width}" height="${height}" srcset="${set}" />`;
19
- } else {
20
- newValue = `<img src="${prefixFileUrlWithBackendUrl(url)}" alt="${alt}" width="${width}" height="${height}" />`;
21
- }
22
- } else if (mime.includes('video')) {
23
- newValue = `
24
- <video class="video" controls width="500px">
25
- <source src="${prefixFileUrlWithBackendUrl(url)}" type="${mime}" />
26
- </video>`;
27
- } else {
28
- newValue = `<a href="${prefixFileUrlWithBackendUrl(url)}">${name || 'Open document'}</a>`;
29
- }
30
- });
31
-
32
- const viewFragment = editor.data.processor.toView(newValue);
33
- const modelFragment = editor.data.toModel(viewFragment);
34
- editor.model.insertContent(modelFragment);
35
-
36
- onToggle();
37
- };
38
-
39
- const handleSelectAssets = (files) => {
40
- const formattedFiles = files.map((f) => ({
41
- name: f.name,
42
- alt: f.alternativeText || f.name,
43
- url: prefixFileUrlWithBackendUrl(f.url),
44
- mime: f.mime,
45
- formats: f.formats,
46
- width: f.width,
47
- height: f.height,
48
- }));
49
-
50
- handleChangeAssets(formattedFiles);
51
- };
52
-
53
- if (!isOpen) {
54
- return null;
55
- }
56
-
57
- return (
58
- <MediaLibraryDialog
59
- onClose={onToggle}
60
- onSelectAssets={handleSelectAssets}
61
- />
62
- );
63
- };
64
-
65
- MediaLib.propTypes = {
66
- isOpen: PropTypes.bool,
67
- onChange: PropTypes.func,
68
- onToggle: PropTypes.func,
69
- };
@@ -1,2 +0,0 @@
1
- export { getConfiguredPreset } from './presets';
2
- export { GlobalStyling } from './styling';
@@ -1,45 +0,0 @@
1
- import { auth } from '@strapi/helper-plugin';
2
-
3
- const importLang = async (config, language) => {
4
- const translations = await import(
5
- /* webpackMode: "lazy-once" */ `ckeditor5/translations/${language}.js`
6
- ).catch((e) => console.log(e));
7
-
8
- config.translations = translations.default;
9
- };
10
-
11
- const detecti18n = () => {
12
- const urlSearchParams = new URLSearchParams(window.location.search);
13
- const params = Object.fromEntries(urlSearchParams.entries());
14
- const i18n = params['plugins[i18n][locale]'];
15
- return i18n && i18n.split('-')[0];
16
- };
17
-
18
- export const setLanguage = async (config) => {
19
- const i18nLang = detecti18n();
20
- const preferedLanguage = auth.getUserInfo().preferedLanguage || 'en';
21
-
22
- const {
23
- ui = preferedLanguage,
24
- content,
25
- textPartLanguage,
26
- ignorei18n,
27
- } = config.language || {};
28
-
29
- if (i18nLang) {
30
- config.language = {
31
- ui: typeof config.language === 'string' ? config.language : ui,
32
- content: ignorei18n ? content : i18nLang,
33
- textPartLanguage: textPartLanguage,
34
- };
35
- }
36
-
37
- if (!config.language) {
38
- config.language = preferedLanguage;
39
- }
40
-
41
- await importLang(
42
- config,
43
- typeof config.language === 'string' ? config.language : config.language.ui
44
- );
45
- };
@@ -1,24 +0,0 @@
1
- import { auth } from '@strapi/helper-plugin';
2
-
3
- export const setPlugins = (config, toggleMediaLib) => {
4
- const presetPluginNames = config?.plugins
5
- ? [...config.plugins.map((p) => p.pluginName)]
6
- : [];
7
-
8
- if (presetPluginNames.includes('StrapiMediaLib')) {
9
- config.strapiMediaLib = { toggle: toggleMediaLib };
10
- }
11
-
12
- if (presetPluginNames.includes('StrapiUploadAdapter')) {
13
- config.strapiUploadAdapter = {
14
- uploadUrl: `${strapi.backendURL}/upload`,
15
- headers: { Authorization: 'Bearer ' + auth.getToken() },
16
- backendUrl: strapi.backendURL,
17
- responsive: globalThis.SH_CKE_UPLOAD_ADAPTER_IS_RESPONSIVE,
18
- };
19
- }
20
-
21
- if (presetPluginNames.includes('WordCount')) {
22
- config.WordCountPlugin = true;
23
- }
24
- };
@@ -1,18 +0,0 @@
1
- import basePresets from '../presets';
2
- import { setPlugins } from './plugins';
3
- import { setLanguage } from './language';
4
-
5
- export const getConfiguredPreset = async (presetName, toggleMediaLib) => {
6
- const { presets: userPresets, dontMergePresets } =
7
- globalThis.SH_CKE_CONFIG || {};
8
-
9
- const preset = dontMergePresets
10
- ? userPresets[presetName]
11
- : basePresets[presetName];
12
-
13
- setPlugins(preset.editorConfig, toggleMediaLib);
14
-
15
- await setLanguage(preset.editorConfig);
16
-
17
- return preset;
18
- };
@@ -1,30 +0,0 @@
1
- import React from 'react';
2
- import { createGlobalStyle } from 'styled-components';
3
-
4
- import baseTheme from '../theme';
5
-
6
- const GlobalStyle = createGlobalStyle`
7
- ${({ theme }) => theme.common}
8
- ${({ theme, variant }) => theme[variant]}
9
- ${({ theme }) => theme.additional}
10
- `;
11
-
12
- const getSystemColorScheme = () =>
13
- window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
14
- ? 'dark'
15
- : 'light';
16
-
17
- export const GlobalStyling = () => {
18
- const { theme: userTheme, dontMergeTheme } = globalThis.SH_CKE_CONFIG || {};
19
-
20
- const profileTheme = localStorage.getItem('STRAPI_THEME');
21
-
22
- const variant =
23
- profileTheme && profileTheme !== 'system'
24
- ? profileTheme
25
- : getSystemColorScheme();
26
-
27
- const theme = dontMergeTheme ? userTheme : { ...baseTheme, ...userTheme };
28
-
29
- return <GlobalStyle theme={theme} variant={variant} />;
30
- };
@@ -1,67 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useIntl } from 'react-intl';
4
- import {
5
- Field,
6
- FieldHint,
7
- FieldError,
8
- FieldLabel,
9
- } from '@strapi/design-system';
10
- import { Stack } from '@strapi/design-system';
11
-
12
- import { Editor } from './components/Editor';
13
-
14
- const Wysiwyg = React.forwardRef((props, ref) => {
15
- const {
16
- name,
17
- attribute,
18
- onChange,
19
- value,
20
- intlLabel,
21
- labelAction,
22
- disabled,
23
- error,
24
- description,
25
- required,
26
- } = props;
27
- const { formatMessage } = useIntl();
28
- const { preset, maxLengthCharacters, ...options } = attribute.options;
29
-
30
- return (
31
- <Field
32
- name={name}
33
- id={name}
34
- error={error}
35
- required={required}
36
- hint={description && formatMessage(description)}
37
- >
38
- <Stack spacing={1}>
39
- <FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>
40
- <Editor
41
- disabled={disabled}
42
- name={name}
43
- onChange={onChange}
44
- value={value}
45
- presetName={preset}
46
- maxLength={maxLengthCharacters}
47
- />
48
- <FieldHint />
49
- <FieldError />
50
- </Stack>
51
- </Field>
52
- );
53
- });
54
-
55
- Wysiwyg.propTypes = {
56
- intlLabel: PropTypes.object.isRequired,
57
- onChange: PropTypes.func.isRequired,
58
- attribute: PropTypes.object.isRequired,
59
- name: PropTypes.string.isRequired,
60
- description: PropTypes.object,
61
- disabled: PropTypes.bool,
62
- error: PropTypes.string,
63
- labelAction: PropTypes.object,
64
- required: PropTypes.bool,
65
- value: PropTypes.string,
66
- };
67
- export default Wysiwyg;
@@ -1,41 +0,0 @@
1
- import { Plugin, ButtonView } from 'ckeditor5';
2
-
3
- const mediaLibIcon =
4
- '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">' +
5
- '<path fill-rule="evenodd" clip-rule="evenodd" d="M4.3.6a.9.9 0 100 1.8h15.311a.9.9 0 100-1.8H4.301zm17.1 3.7A1.6 1.6' +
6
- ' 0 0123 5.9v15.5a1.6 1.6 0 01-1.6 1.6H2.6A1.601 1.601 0 011 21.4V8 5.915C1 5.03 1.716 4.3 2.6' +
7
- ' 4.3h18.8zM5.032 19.18h14.336l-3.136-3.205-1.792 1.831-4.032-4.12-5.376 5.494zm13.44-8.697c0 ' +
8
- '1.282-.985 2.289-2.24 2.289-1.254 0-2.24-1.007-2.24-2.29 0-1.281.986-2.288 2.24-2.288 1.255 0 2.24 1.007 2.24 2.289z">' +
9
- '</path></svg>';
10
-
11
- export default class StrapiMediaLib extends Plugin {
12
- /**
13
- * Strapi function used to show media library modal.
14
- * Should be provided via connect method before using toggle method.
15
- *
16
- * @type {function|null}
17
- */
18
- strapiToggle = null;
19
-
20
- static get pluginName() {
21
- return 'StrapiMediaLib';
22
- }
23
-
24
- init() {
25
- const editor = this.editor;
26
- const config = editor.config.get('strapiMediaLib');
27
- editor.ui.componentFactory.add('strapiMediaLib', () => {
28
- const button = new ButtonView();
29
-
30
- button.set({
31
- label: 'Media Library',
32
- icon: mediaLibIcon,
33
- tooltip: true,
34
- });
35
-
36
- button.on('execute', config.toggle.bind(this));
37
-
38
- return button;
39
- });
40
- }
41
- }
@@ -1,186 +0,0 @@
1
- import { Plugin, FileRepository } from 'ckeditor5';
2
-
3
- export default class StrapiUploadAdapter extends Plugin {
4
- static get requires() {
5
- return [FileRepository];
6
- }
7
-
8
- static get pluginName() {
9
- return 'StrapiUploadAdapter';
10
- }
11
-
12
- init() {
13
- const options = this.editor.config.get('strapiUploadAdapter');
14
-
15
- if (!options) {
16
- return;
17
- }
18
-
19
- if (!options.uploadUrl) {
20
- console.warn(
21
- 'strapi-upload-adapter-missing-uploadUrl: Missing the "uploadUrl" property in the "strapiUploadAdapter" editor configuration.'
22
- );
23
-
24
- return;
25
- }
26
-
27
- this.editor.plugins.get(FileRepository).createUploadAdapter = (loader) => {
28
- return new Adapter(loader, options);
29
- };
30
- }
31
- }
32
-
33
- /**
34
- * Upload adapter.
35
- *
36
- * @private
37
- */
38
- class Adapter {
39
- /**
40
- * Creates a new adapter instance.
41
- */
42
- constructor(loader, options) {
43
- /**
44
- * FileLoader instance to use during the upload.
45
- */
46
- this.loader = loader;
47
-
48
- /**
49
- * The configuration of the adapter.
50
- */
51
- this.options = options;
52
- }
53
-
54
- /**
55
- * Starts the upload process.
56
- *
57
- * @returns {Promise}
58
- */
59
- upload() {
60
- return this.loader.file.then(
61
- (file) =>
62
- new Promise((resolve, reject) => {
63
- this._initRequest();
64
- this._initListeners(resolve, reject, file);
65
- this._sendRequest(file);
66
- })
67
- );
68
- }
69
-
70
- /**
71
- * Aborts the upload process.
72
- *
73
- * @returns {Promise}
74
- */
75
- abort() {
76
- if (this.xhr) {
77
- this.xhr.abort();
78
- }
79
- }
80
-
81
- /**
82
- * Initializes the `XMLHttpRequest` object using the URL specified as
83
- * `strapiUpload.uploadUrl` in the editor's
84
- * configuration.
85
- *
86
- * @private
87
- */
88
- _initRequest() {
89
- const xhr = (this.xhr = new XMLHttpRequest());
90
-
91
- xhr.open('POST', this.options.uploadUrl, true);
92
- xhr.responseType = 'json';
93
- }
94
-
95
- /**
96
- * Initializes XMLHttpRequest listeners
97
- *
98
- * @private
99
- * @param {Function} resolve Callback function to be called when the request is successful.
100
- * @param {Function} reject Callback function to be called when the request cannot be completed.
101
- * @param {File} file Native File object.
102
- */
103
- _initListeners(resolve, reject, file) {
104
- const xhr = this.xhr;
105
- const loader = this.loader;
106
- const genericErrorText = `Couldn't upload file: ${file.name}.`;
107
-
108
- xhr.addEventListener('error', () => reject(genericErrorText));
109
- xhr.addEventListener('abort', () => reject());
110
- xhr.addEventListener('load', () => {
111
- const response = xhr.response;
112
-
113
- if (!Array.isArray(response) || response.error || response.length !== 1) {
114
- return reject(
115
- response && response.error && response.error.message
116
- ? response.error.message
117
- : genericErrorText
118
- );
119
- }
120
-
121
- const { backendUrl, responsive } = this.options || {};
122
- const { name, url, alternativeText, formats, provider } = response[0];
123
- const defaultUrl = provider !== 'local' ? url : backendUrl + url;
124
-
125
- if (formats && responsive) {
126
- let urls = { default: defaultUrl };
127
- let keys = Object.keys(formats).sort(
128
- (a, b) => formats[a].width - formats[b].width
129
- );
130
- keys.map(
131
- (k) =>
132
- (urls[formats[k].width] =
133
- provider !== 'local' ? url : backendUrl + formats[k].url)
134
- );
135
- resolve({ alt: alternativeText || name, urls: urls });
136
- } else {
137
- resolve(
138
- url
139
- ? {
140
- alt: alternativeText || name,
141
- urls: { default: defaultUrl },
142
- }
143
- : null
144
- );
145
- }
146
- });
147
-
148
- // Upload progress when it is supported.
149
- if (xhr.upload) {
150
- xhr.upload.addEventListener('progress', (evt) => {
151
- if (evt.lengthComputable) {
152
- loader.uploadTotal = evt.total;
153
- loader.uploaded = evt.loaded;
154
- }
155
- });
156
- }
157
- }
158
-
159
- /**
160
- * Prepares the data and sends the request.
161
- *
162
- * @private
163
- * @param {File} file File instance to be uploaded.
164
- */
165
- _sendRequest(file) {
166
- // Set headers if specified.
167
- const headers = this.options.headers || {};
168
-
169
- // Use the withCredentials flag if specified.
170
- const withCredentials = this.options.withCredentials || false;
171
-
172
- for (const headerName of Object.keys(headers)) {
173
- this.xhr.setRequestHeader(headerName, headers[headerName]);
174
- }
175
-
176
- this.xhr.withCredentials = withCredentials;
177
-
178
- // Prepare the form data.
179
- const data = new FormData();
180
-
181
- data.append('files', file);
182
-
183
- // Send the request.
184
- this.xhr.send(data);
185
- }
186
- }
@@ -1,2 +0,0 @@
1
- export { default as StrapiMediaLib } from './StrapiMediaLib';
2
- export { default as StrapiUploadAdapter } from './StrapiUploadAdapter';