@_sh/strapi-plugin-ckeditor 3.0.4 → 3.0.6

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.
@@ -20,6 +20,7 @@ export const Editor = ({
20
20
  disabled = false,
21
21
  presetName,
22
22
  maxLength,
23
+ placeholder
23
24
  }) => {
24
25
  const [editorInstance, setEditorInstance] = useState(false);
25
26
 
@@ -42,7 +43,20 @@ export const Editor = ({
42
43
  presetName,
43
44
  handleToggleMediaLib
44
45
  );
45
- setPreset(currentPreset);
46
+
47
+ if (placeholder) {
48
+ const clonedPreset = {
49
+ ...currentPreset,
50
+ editorConfig: {
51
+ ...currentPreset.editorConfig,
52
+ placeholder: placeholder.defaultMessage,
53
+ },
54
+ };
55
+
56
+ setPreset(clonedPreset);
57
+ } else {
58
+ setPreset(currentPreset);
59
+ }
46
60
  })();
47
61
  }, []);
48
62
 
@@ -17,29 +17,26 @@ const detecti18n = () => {
17
17
 
18
18
  export const setLanguage = async (config) => {
19
19
  const i18nLang = detecti18n();
20
+
20
21
  const preferedLanguage = auth.getUserInfo().preferedLanguage || 'en';
21
22
 
22
23
  const {
23
- ui = preferedLanguage,
24
- content,
24
+ ui = config.language && typeof config.language === 'string' ?
25
+ config.language
26
+ : preferedLanguage,
25
27
  textPartLanguage,
26
28
  ignorei18n,
27
29
  } = config.language || {};
28
30
 
29
- if (i18nLang) {
31
+ if (i18nLang && !ignorei18n) {
30
32
  config.language = {
31
- ui: typeof config.language === 'string' ? config.language : ui,
32
- content: ignorei18n ? content : i18nLang,
33
+ ui: ui,
34
+ content: i18nLang,
33
35
  textPartLanguage: textPartLanguage,
34
36
  };
35
37
  }
36
38
 
37
- if (!config.language) {
38
- config.language = preferedLanguage;
39
+ if (ui !== 'en') {
40
+ await importLang(config, ui);
39
41
  }
40
-
41
- await importLang(
42
- config,
43
- typeof config.language === 'string' ? config.language : ui
44
- );
45
42
  };
@@ -14,7 +14,7 @@ const getSystemColorScheme = () =>
14
14
  ? 'dark'
15
15
  : 'light';
16
16
 
17
- export const GlobalStyling = () => {
17
+ const GlobalStyling = () => {
18
18
  const { theme: userTheme, dontMergeTheme } = globalThis.SH_CKE_CONFIG || {};
19
19
 
20
20
  const profileTheme = localStorage.getItem('STRAPI_THEME');
@@ -28,3 +28,7 @@ export const GlobalStyling = () => {
28
28
 
29
29
  return <GlobalStyle theme={theme} variant={variant} />;
30
30
  };
31
+
32
+ const MemoizedGlobalStyling = React.memo(GlobalStyling);
33
+
34
+ export { MemoizedGlobalStyling as GlobalStyling };
@@ -11,19 +11,19 @@ import { Stack } from '@strapi/design-system';
11
11
 
12
12
  import { Editor } from './components/Editor';
13
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;
14
+ const Wysiwyg = ({
15
+ name,
16
+ attribute,
17
+ onChange,
18
+ value,
19
+ intlLabel,
20
+ labelAction,
21
+ disabled,
22
+ error,
23
+ description,
24
+ required,
25
+ placeholder,
26
+ }) => {
27
27
  const { formatMessage } = useIntl();
28
28
  const { preset, maxLengthCharacters, ...options } = attribute.options;
29
29
 
@@ -44,13 +44,14 @@ const Wysiwyg = React.forwardRef((props, ref) => {
44
44
  value={value}
45
45
  presetName={preset}
46
46
  maxLength={maxLengthCharacters}
47
+ placeholder={placeholder}
47
48
  />
48
49
  <FieldHint />
49
50
  <FieldError />
50
51
  </Stack>
51
52
  </Field>
52
53
  );
53
- });
54
+ };
54
55
 
55
56
  Wysiwyg.propTypes = {
56
57
  intlLabel: PropTypes.object.isRequired,
@@ -63,5 +64,9 @@ Wysiwyg.propTypes = {
63
64
  labelAction: PropTypes.object,
64
65
  required: PropTypes.bool,
65
66
  value: PropTypes.string,
67
+ placeholder: PropTypes.object,
66
68
  };
67
- export default Wysiwyg;
69
+
70
+ const MemoizedWysiwyg = React.memo(Wysiwyg);
71
+
72
+ export default MemoizedWysiwyg;
@@ -227,4 +227,9 @@ export const common = css`
227
227
  }
228
228
  }
229
229
  }
230
+
231
+ .ck.ck-editor__editable > .ck-placeholder::before {
232
+ color: var(--ck-color-editor-base-text);
233
+ opacity: 0.65;
234
+ }
230
235
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_sh/strapi-plugin-ckeditor",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Integrates CKEditor 5 into your Strapi project as a fully customizable custom field. (Unofficial integration)",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,25 +1,43 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- const fs = require("fs");
3
+ const fs = require('fs');
4
4
 
5
5
  module.exports = ({ strapi }) => {
6
+ const readConfigFile = () => {
7
+ const appDir = process.cwd();
8
+ const isTSProject = fs.existsSync(`${appDir}/dist`);
9
+ const envName = process.env.NODE_ENV;
10
+
11
+ const cfgDir = isTSProject ? `${appDir}/dist/config` : `${appDir}/config`;
12
+ const cfgFileName = 'ckeditor.js';
13
+
14
+ const envFilePath = `${cfgDir}/env/${envName}/${cfgFileName}`;
15
+ const baseFilePath = `${cfgDir}/${cfgFileName}`;
16
+
17
+ if (fs.existsSync(envFilePath)) {
18
+ return fs.readFileSync(envFilePath, 'utf8');
19
+ } else if (fs.existsSync(baseFilePath)) {
20
+ return fs.readFileSync(baseFilePath, 'utf8');
21
+ } else {
22
+ return null;
23
+ }
24
+ };
25
+
26
+ const trimConfig = (str) => {
27
+ for (const func of ['const CKEConfig', 'function CKEConfig']) {
28
+ const idx = str.indexOf(func);
29
+ if (idx >= 0) {
30
+ return str.substring(idx) + `\nglobalThis.SH_CKE_CONFIG = CKEConfig()`;
31
+ }
32
+ }
33
+ };
34
+
6
35
  return {
7
36
  getConfig() {
8
- const appDir = process.cwd();
9
-
10
- const fileName = "ckeditor";
11
-
12
- for (const ext of ["js", "ts"]) {
13
- const filePath = `${appDir}/config/${fileName}.${ext}`;
14
- if (fs.existsSync(filePath)) {
15
- return (
16
- fs.readFileSync(filePath, "utf8") +
17
- `\nglobalThis.SH_CKE_CONFIG = CKEConfig()`
18
- );
19
- }
20
- }
37
+ const configFileContent = readConfigFile();
38
+ const config = configFileContent && trimConfig(configFileContent);
21
39
 
22
- return `globalThis.SH_CKE_CONFIG = null`;
40
+ return config || `globalThis.SH_CKE_CONFIG = null`;
23
41
  },
24
42
  };
25
43
  };