@_sh/strapi-plugin-ckeditor 1.1.3 → 2.0.0
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/README.md +353 -897
- package/admin/src/components/CKEditorIcon.js +46 -0
- package/admin/src/components/Input/CKEditor/configs/base.js +628 -0
- package/admin/src/components/Input/CKEditor/configs/blockBaloon.js +25 -0
- package/admin/src/components/Input/CKEditor/configs/index.js +11 -0
- package/admin/src/components/Input/CKEditor/configs/toolbar.js +17 -0
- package/admin/src/components/Input/CKEditor/configs/toolbarBaloon.js +17 -0
- package/admin/src/components/Input/CKEditor/configuration.js +166 -0
- package/admin/src/components/Input/CKEditor/index.js +120 -0
- package/admin/src/components/Input/CKEditor/plugins/StrapiMediaLib.js +43 -0
- package/admin/src/components/Input/CKEditor/plugins/StrapiUploadAdapter.js +203 -0
- package/admin/src/components/Input/CKEditor/plugins/index.js +2 -0
- package/admin/src/components/Input/CKEditor/styling.js +16 -0
- package/admin/src/components/Input/CKEditor/theme/additional.js +167 -0
- package/admin/src/components/Input/CKEditor/theme/common.js +277 -0
- package/admin/src/components/Input/CKEditor/theme/dark.js +144 -0
- package/admin/src/components/Input/CKEditor/theme/index.js +13 -0
- package/admin/src/components/Input/CKEditor/theme/light.js +135 -0
- package/admin/src/components/Input/MediaLib/index.js +79 -0
- package/admin/src/components/Input/index.js +48 -0
- package/admin/src/index.js +107 -15
- package/admin/src/utils/getEditorConfig.js +37 -0
- package/admin/src/utils/pluginId.js +5 -0
- package/package.json +43 -7
- package/server/controllers/config.js +8 -12
- package/server/index.js +1 -1
- package/server/register.js +7 -1
- package/server/routes/index.js +5 -6
- package/server/services/config.js +5 -12
- package/admin/src/components/CKEditor/build/ckeditor.js +0 -7
- package/admin/src/components/CKEditor/build/ckeditor.js.map +0 -1
- package/admin/src/components/CKEditor/build/translations/af.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ar.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ast.js +0 -1
- package/admin/src/components/CKEditor/build/translations/az.js +0 -1
- package/admin/src/components/CKEditor/build/translations/bg.js +0 -1
- package/admin/src/components/CKEditor/build/translations/bn.js +0 -1
- package/admin/src/components/CKEditor/build/translations/bs.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ca.js +0 -1
- package/admin/src/components/CKEditor/build/translations/cs.js +0 -1
- package/admin/src/components/CKEditor/build/translations/da.js +0 -1
- package/admin/src/components/CKEditor/build/translations/de-ch.js +0 -1
- package/admin/src/components/CKEditor/build/translations/de.js +0 -1
- package/admin/src/components/CKEditor/build/translations/el.js +0 -1
- package/admin/src/components/CKEditor/build/translations/en-au.js +0 -1
- package/admin/src/components/CKEditor/build/translations/en-gb.js +0 -1
- package/admin/src/components/CKEditor/build/translations/eo.js +0 -1
- package/admin/src/components/CKEditor/build/translations/es.js +0 -1
- package/admin/src/components/CKEditor/build/translations/et.js +0 -1
- package/admin/src/components/CKEditor/build/translations/eu.js +0 -1
- package/admin/src/components/CKEditor/build/translations/fa.js +0 -1
- package/admin/src/components/CKEditor/build/translations/fi.js +0 -1
- package/admin/src/components/CKEditor/build/translations/fr.js +0 -1
- package/admin/src/components/CKEditor/build/translations/gl.js +0 -1
- package/admin/src/components/CKEditor/build/translations/gu.js +0 -1
- package/admin/src/components/CKEditor/build/translations/he.js +0 -1
- package/admin/src/components/CKEditor/build/translations/hi.js +0 -1
- package/admin/src/components/CKEditor/build/translations/hr.js +0 -1
- package/admin/src/components/CKEditor/build/translations/hu.js +0 -1
- package/admin/src/components/CKEditor/build/translations/id.js +0 -1
- package/admin/src/components/CKEditor/build/translations/it.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ja.js +0 -1
- package/admin/src/components/CKEditor/build/translations/jv.js +0 -1
- package/admin/src/components/CKEditor/build/translations/kk.js +0 -1
- package/admin/src/components/CKEditor/build/translations/km.js +0 -1
- package/admin/src/components/CKEditor/build/translations/kn.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ko.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ku.js +0 -1
- package/admin/src/components/CKEditor/build/translations/lt.js +0 -1
- package/admin/src/components/CKEditor/build/translations/lv.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ms.js +0 -1
- package/admin/src/components/CKEditor/build/translations/nb.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ne.js +0 -1
- package/admin/src/components/CKEditor/build/translations/nl.js +0 -1
- package/admin/src/components/CKEditor/build/translations/no.js +0 -1
- package/admin/src/components/CKEditor/build/translations/oc.js +0 -1
- package/admin/src/components/CKEditor/build/translations/pl.js +0 -1
- package/admin/src/components/CKEditor/build/translations/pt-br.js +0 -1
- package/admin/src/components/CKEditor/build/translations/pt.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ro.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ru.js +0 -1
- package/admin/src/components/CKEditor/build/translations/si.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sk.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sl.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sq.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sr-latn.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sr.js +0 -1
- package/admin/src/components/CKEditor/build/translations/sv.js +0 -1
- package/admin/src/components/CKEditor/build/translations/th.js +0 -1
- package/admin/src/components/CKEditor/build/translations/tk.js +0 -1
- package/admin/src/components/CKEditor/build/translations/tr.js +0 -1
- package/admin/src/components/CKEditor/build/translations/tt.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ug.js +0 -1
- package/admin/src/components/CKEditor/build/translations/uk.js +0 -1
- package/admin/src/components/CKEditor/build/translations/ur.js +0 -1
- package/admin/src/components/CKEditor/build/translations/uz.js +0 -1
- package/admin/src/components/CKEditor/build/translations/vi.js +0 -1
- package/admin/src/components/CKEditor/build/translations/zh-cn.js +0 -1
- package/admin/src/components/CKEditor/build/translations/zh.js +0 -1
- package/admin/src/components/CKEditor/index.js +0 -247
- package/admin/src/components/CKEditor/styles.js +0 -511
- package/admin/src/components/CKEditor/theme.js +0 -313
- package/admin/src/components/Initializer/index.js +0 -26
- package/admin/src/components/MediaLib/index.js +0 -44
- package/admin/src/components/Wysiwyg/index.js +0 -77
- package/admin/src/pages/App/index.js +0 -25
- package/admin/src/pages/HomePage/index.js +0 -20
- package/admin/src/pluginId.js +0 -6
- package/admin/src/translations/en.json +0 -1
- package/admin/src/translations/fr.json +0 -1
- package/admin/src/utils/axiosInstance.js +0 -40
- package/admin/src/utils/getTrad.js +0 -5
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { css } from "styled-components";
|
|
2
|
+
|
|
3
|
+
export const light = css`
|
|
4
|
+
:root {
|
|
5
|
+
--ck-color-focus-outer-shadow: rgba(77, 115, 255, 0.2) !important;
|
|
6
|
+
--ck-color-focus-disabled-shadow: #e4e3ff !important;
|
|
7
|
+
--ck-focus-ring: 1px solid rgb(73, 69, 255) !important;
|
|
8
|
+
--ck-color-button-default-hover-background: #F0F0FF !important;
|
|
9
|
+
|
|
10
|
+
.ck .ck-color-picker-save {
|
|
11
|
+
& > svg {
|
|
12
|
+
stroke: #7b79ff !important;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ck {
|
|
18
|
+
--ck-scroll-track-background: rgb(242, 242, 242);
|
|
19
|
+
--ck-scroll-thumb-background: rgb(236, 236, 236);
|
|
20
|
+
--ck-scroll-thumb-border-color: #cdcdf8;
|
|
21
|
+
--ck-scroll-thumb-hover-background: #f0f0ff;
|
|
22
|
+
--ck-scroll-thumb-active-background: #d9d8ff;
|
|
23
|
+
|
|
24
|
+
--ck-color-editor-base-text: #001234;
|
|
25
|
+
/* Overrides the border radius setting in the theme. */
|
|
26
|
+
--ck-border-radius: 4px;
|
|
27
|
+
|
|
28
|
+
/* Helper variables to avoid duplication in the colors. */
|
|
29
|
+
--ck-color-base-border: #dcdce4;
|
|
30
|
+
--ck-color-base-background: #ffffff;
|
|
31
|
+
--ck-custom-background: #ffffff;
|
|
32
|
+
--ck-custom-foreground: #dedede;
|
|
33
|
+
--ck-custom-border: #dcdce4;
|
|
34
|
+
--ck-custom-white: hsl(0, 0%, 100%);
|
|
35
|
+
|
|
36
|
+
--ck-color-base-focus: #bbbaf1;
|
|
37
|
+
--ck-color-base-active: #f0f0ff;
|
|
38
|
+
--ck-color-base-active-focus: #e2e2fd;
|
|
39
|
+
/* -- Overrides generic colors. ------------------------------------------------------------- */
|
|
40
|
+
|
|
41
|
+
--ck-color-base-foreground: var(--ck-custom-background);
|
|
42
|
+
|
|
43
|
+
--ck-color-focus-border: rgb(73, 69, 255);
|
|
44
|
+
|
|
45
|
+
--ck-color-text: #32324d;
|
|
46
|
+
--ck-color-shadow-drop: hsla(250, 31%, 80%, 0.1);
|
|
47
|
+
--ck-color-shadow-inner: hsla(250, 31%, 80%, 0.1);
|
|
48
|
+
|
|
49
|
+
/* -- Overrides the default .ck-button class colors. ---------------------------------------- */
|
|
50
|
+
|
|
51
|
+
--ck-color-button-default-background: var(--ck-custom-background);
|
|
52
|
+
--ck-color-button-default-hover-background: #f0f0ff;
|
|
53
|
+
--ck-color-button-default-active-background: #f6f6f9;
|
|
54
|
+
--ck-color-button-default-active-shadow: #dedefb;
|
|
55
|
+
--ck-color-button-default-disabled-background: var(--ck-custom-background);
|
|
56
|
+
|
|
57
|
+
--ck-color-button-on-color: rgb(73, 69, 255);
|
|
58
|
+
--ck-color-button-on-background: #f0f0ff;
|
|
59
|
+
--ck-color-button-on-hover-background: #e6e9fc;
|
|
60
|
+
--ck-color-button-on-active-background: #f6f6f9;
|
|
61
|
+
--ck-color-button-on-active-shadow: #cdcdf8;
|
|
62
|
+
--ck-color-button-on-disabled-background: var(--ck-custom-foreground);
|
|
63
|
+
|
|
64
|
+
--ck-color-button-action-background: hsl(168, 76%, 42%);
|
|
65
|
+
--ck-color-button-action-hover-background: hsl(168, 76%, 38%);
|
|
66
|
+
--ck-color-button-action-active-background: hsl(168, 76%, 36%);
|
|
67
|
+
--ck-color-button-action-active-shadow: hsl(168, 75%, 34%);
|
|
68
|
+
--ck-color-button-action-disabled-background: hsl(168, 76%, 42%);
|
|
69
|
+
--ck-color-button-action-text: var(--ck-custom-white);
|
|
70
|
+
|
|
71
|
+
--ck-color-button-save: hsl(120, 100%, 46%);
|
|
72
|
+
--ck-color-button-cancel: hsl(15, 100%, 56%);
|
|
73
|
+
|
|
74
|
+
/* -- Overrides the default .ck-dropdown class colors. -------------------------------------- */
|
|
75
|
+
|
|
76
|
+
--ck-color-dropdown-panel-background: var(--ck-custom-background);
|
|
77
|
+
--ck-color-dropdown-panel-border: var(--ck-custom-foreground);
|
|
78
|
+
|
|
79
|
+
/* -- Overrides the default .ck-splitbutton class colors. ----------------------------------- */
|
|
80
|
+
|
|
81
|
+
--ck-color-split-button-hover-background: var(--ck-color-button-default-hover-background);
|
|
82
|
+
--ck-color-split-button-hover-border: var(--ck-custom-foreground);
|
|
83
|
+
|
|
84
|
+
/* -- Overrides the default .ck-input class colors. ----------------------------------------- */
|
|
85
|
+
|
|
86
|
+
--ck-color-input-background: var(--ck-custom-background);
|
|
87
|
+
--ck-color-input-border: hsl(257, 3%, 43%);
|
|
88
|
+
--ck-color-input-text: hsl(0, 0%, 98%);
|
|
89
|
+
--ck-color-input-disabled-background: hsl(0, 0%, 97%);
|
|
90
|
+
--ck-color-input-disabled-border: rgb(214, 214, 214);
|
|
91
|
+
--ck-color-input-disabled-text: hsl(0, 0%, 78%);
|
|
92
|
+
|
|
93
|
+
/* -- Overrides the default .ck-labeled-field-view class colors. ---------------------------- */
|
|
94
|
+
|
|
95
|
+
--ck-color-labeled-field-label-background: var(--ck-custom-background);
|
|
96
|
+
|
|
97
|
+
/* -- Overrides the default .ck-list class colors. ------------------------------------------ */
|
|
98
|
+
|
|
99
|
+
--ck-color-list-background: var(--ck-custom-background);
|
|
100
|
+
--ck-color-list-button-hover-background: #f4f4fb;
|
|
101
|
+
--ck-color-list-button-on-background: var(--ck-color-base-active);
|
|
102
|
+
--ck-color-list-button-on-background-focus: var(--ck-color-base-active-focus);
|
|
103
|
+
--ck-color-list-button-on-text: #271fe2;
|
|
104
|
+
|
|
105
|
+
/* -- Overrides the default .ck-balloon-panel class colors. --------------------------------- */
|
|
106
|
+
|
|
107
|
+
--ck-color-panel-background: var(--ck-custom-background);
|
|
108
|
+
--ck-color-panel-border: var(--ck-custom-border);
|
|
109
|
+
|
|
110
|
+
/* -- Overrides the default .ck-toolbar class colors. --------------------------------------- */
|
|
111
|
+
|
|
112
|
+
--ck-color-toolbar-background: var(--ck-custom-background);
|
|
113
|
+
--ck-color-toolbar-border: var(--ck-custom-border);
|
|
114
|
+
|
|
115
|
+
/* -- Overrides the default .ck-tooltip class colors. --------------------------------------- */
|
|
116
|
+
|
|
117
|
+
--ck-color-tooltip-background: #3a3955;
|
|
118
|
+
--ck-color-tooltip-text: hsl(0, 0%, 93%);
|
|
119
|
+
|
|
120
|
+
/* -- Overrides the default colors used by the ckeditor5-image package. --------------------- */
|
|
121
|
+
|
|
122
|
+
--ck-color-image-caption-background: hsl(0, 0%, 97%);
|
|
123
|
+
--ck-color-image-caption-text: hsl(0, 0%, 20%);
|
|
124
|
+
|
|
125
|
+
/* -- Overrides the default colors used by the ckeditor5-widget package. -------------------- */
|
|
126
|
+
|
|
127
|
+
--ck-color-widget-blurred-border: #cfcffa;
|
|
128
|
+
--ck-color-widget-hover-border: #c9c9e4;
|
|
129
|
+
--ck-color-widget-editable-focus-background: var(--ck-custom-white);
|
|
130
|
+
|
|
131
|
+
/* -- Overrides the default colors used by the ckeditor5-link package. ---------------------- */
|
|
132
|
+
|
|
133
|
+
--ck-color-link-default: hsl(209, 89%, 33%);
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
@@ -0,0 +1,79 @@
|
|
|
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, editor, uploadConfig: { responsiveDimensions } }) => {
|
|
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}) => {
|
|
13
|
+
|
|
14
|
+
if (mime.includes("image")) {
|
|
15
|
+
|
|
16
|
+
if (formats && responsiveDimensions) {
|
|
17
|
+
let set = "";
|
|
18
|
+
let keys = Object.keys(formats).sort((a, b) => formats[a].width - formats[b].width );
|
|
19
|
+
keys.map((k) => set += prefixFileUrlWithBackendUrl(formats[k].url) + ` ${formats[k].width}w,`);
|
|
20
|
+
newValue += `<img src="${url}" alt="${alt}" width="${formats[keys[keys.length-1]].width}px" srcset="${set}" />`;
|
|
21
|
+
} else {
|
|
22
|
+
newValue += `<img src="${url}" alt="${alt}" />`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} else if (mime.includes("application/pdf")) {
|
|
26
|
+
|
|
27
|
+
newValue = `<a href="${prefixFileUrlWithBackendUrl(url)}" download="${name}">${name || 'Download PDF'}</a>`;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
// Handle videos and other type of files by adding some code
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const viewFragment = editor.data.processor.toView( newValue );
|
|
34
|
+
const modelFragment = editor.data.toModel( viewFragment );
|
|
35
|
+
editor.model.insertContent( modelFragment );
|
|
36
|
+
|
|
37
|
+
onToggle();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleSelectAssets = (files) => {
|
|
41
|
+
const formattedFiles = files.map((f) => ({
|
|
42
|
+
name: f.name,
|
|
43
|
+
alt: f.alternativeText || f.name,
|
|
44
|
+
url: prefixFileUrlWithBackendUrl(f.url),
|
|
45
|
+
mime: f.mime,
|
|
46
|
+
formats: f.formats
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
handleChangeAssets(formattedFiles);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (!isOpen) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<MediaLibraryDialog
|
|
61
|
+
onClose={onToggle}
|
|
62
|
+
onSelectAssets={handleSelectAssets}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
MediaLib.defaultProps = {
|
|
68
|
+
isOpen: false,
|
|
69
|
+
onChange: () => {},
|
|
70
|
+
onToggle: () => {},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
MediaLib.propTypes = {
|
|
74
|
+
isOpen: PropTypes.bool,
|
|
75
|
+
onChange: PropTypes.func,
|
|
76
|
+
onToggle: PropTypes.func,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default MediaLib;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import {default as CKEditor} from "./CKEditor";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import { Field, FieldHint, FieldError, FieldLabel } from "@strapi/design-system/Field";
|
|
6
|
+
import { Stack } from "@strapi/design-system/Stack";
|
|
7
|
+
|
|
8
|
+
const Wysiwyg = ({ name, attribute, onChange, value, intlLabel, labelAction, disabled, error, description, required }) => {
|
|
9
|
+
const { formatMessage } = useIntl();
|
|
10
|
+
const { preset, maxLengthCharacters, ...options } = attribute.options;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Field name={name} id={name} error={error} hint={description && formatMessage(description)}>
|
|
14
|
+
<Stack spacing={1}>
|
|
15
|
+
<FieldLabel action={labelAction} required={required}>
|
|
16
|
+
{formatMessage(intlLabel)}
|
|
17
|
+
</FieldLabel>
|
|
18
|
+
<CKEditor disabled={disabled} name={name} onChange={onChange} value={value} preset={preset} maxLength={maxLengthCharacters}/>
|
|
19
|
+
<FieldHint />
|
|
20
|
+
<FieldError />
|
|
21
|
+
</Stack>
|
|
22
|
+
</Field>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Wysiwyg.defaultProps = {
|
|
28
|
+
description: null,
|
|
29
|
+
disabled: false,
|
|
30
|
+
error: null,
|
|
31
|
+
labelAction: null,
|
|
32
|
+
required: false,
|
|
33
|
+
value: "",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Wysiwyg.propTypes = {
|
|
37
|
+
intlLabel: PropTypes.object.isRequired,
|
|
38
|
+
onChange: PropTypes.func.isRequired,
|
|
39
|
+
attribute: PropTypes.object.isRequired,
|
|
40
|
+
name: PropTypes.string.isRequired,
|
|
41
|
+
description: PropTypes.object,
|
|
42
|
+
disabled: PropTypes.bool,
|
|
43
|
+
error: PropTypes.string,
|
|
44
|
+
labelAction: PropTypes.object,
|
|
45
|
+
required: PropTypes.bool,
|
|
46
|
+
value: PropTypes.string,
|
|
47
|
+
};
|
|
48
|
+
export default Wysiwyg;
|
package/admin/src/index.js
CHANGED
|
@@ -1,18 +1,110 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import pluginId from "./pluginId";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as yup from "yup";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import baseConfigs from "./components/Input/CKEditor/configs";
|
|
5
|
+
import getEditorConfig from "./utils/getEditorConfig";
|
|
6
|
+
import CKEditorIcon from "./components/CKEditorIcon";
|
|
7
|
+
import pluginId from "./utils/pluginId";
|
|
6
8
|
|
|
7
9
|
export default {
|
|
8
|
-
register(app) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
async register(app) {
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
configs: userConfigs = baseConfigs,
|
|
14
|
+
configsOverwrite: overwrite
|
|
15
|
+
} = await getEditorConfig() || {};
|
|
16
|
+
|
|
17
|
+
const setOptions = () => {
|
|
18
|
+
|
|
19
|
+
let configs = {};
|
|
20
|
+
|
|
21
|
+
if (overwrite) {
|
|
22
|
+
configs = userConfigs;
|
|
23
|
+
} else {
|
|
24
|
+
configs = baseConfigs;
|
|
25
|
+
if (userConfigs) {
|
|
26
|
+
Object.keys(userConfigs).map(cfgName=>{
|
|
27
|
+
if(baseConfigs.hasOwnProperty(cfgName))
|
|
28
|
+
configs[cfgName].field = { ...baseConfigs[cfgName].field, ...userConfigs[cfgName].field };
|
|
29
|
+
else configs[cfgName] = userConfigs[cfgName];
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const options = [...Object.keys(configs).map(configName=>configs[configName].field)];
|
|
35
|
+
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
app.customFields.register({
|
|
40
|
+
name: "CKEditor",
|
|
41
|
+
type: "richtext",
|
|
42
|
+
pluginId: pluginId,
|
|
43
|
+
icon: CKEditorIcon,
|
|
44
|
+
intlLabel: {
|
|
45
|
+
id: pluginId + ".label",
|
|
46
|
+
defaultMessage: "CKEditor 5",
|
|
47
|
+
},
|
|
48
|
+
intlDescription: {
|
|
49
|
+
id: pluginId + ".description",
|
|
50
|
+
defaultMessage: "The rich text editor for every use case",
|
|
51
|
+
},
|
|
52
|
+
components: {
|
|
53
|
+
Input: async () => import("./components/Input"),
|
|
54
|
+
},
|
|
55
|
+
options: {
|
|
56
|
+
base: [
|
|
57
|
+
{
|
|
58
|
+
intlLabel: {
|
|
59
|
+
id: pluginId + ".preset.label",
|
|
60
|
+
defaultMessage: "Choose editor version",
|
|
61
|
+
},
|
|
62
|
+
description: {
|
|
63
|
+
id: pluginId + ".preset.description",
|
|
64
|
+
defaultMessage: " ",
|
|
65
|
+
},
|
|
66
|
+
name: "options.preset",
|
|
67
|
+
type: "select",
|
|
68
|
+
options: setOptions(),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
advanced: [
|
|
72
|
+
{
|
|
73
|
+
sectionTitle: null,
|
|
74
|
+
items: [
|
|
75
|
+
{
|
|
76
|
+
name: "required",
|
|
77
|
+
type: "checkbox",
|
|
78
|
+
intlLabel: {
|
|
79
|
+
id: pluginId + ".required.label",
|
|
80
|
+
defaultMessage: "Required field",
|
|
81
|
+
},
|
|
82
|
+
description: {
|
|
83
|
+
id: pluginId + "required.description",
|
|
84
|
+
defaultMessage:
|
|
85
|
+
"You won't be able to create an entry if this field is empty",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "options.maxLengthCharacters",
|
|
90
|
+
type: "checkbox-with-number-field",
|
|
91
|
+
intlLabel: {
|
|
92
|
+
id: pluginId + ".maxLength.label",
|
|
93
|
+
defaultMessage: "Maximum length (characters)",
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
validator: (args) => ({
|
|
101
|
+
preset: yup.string().required({
|
|
102
|
+
id: pluginId + ".preset.error.required",
|
|
103
|
+
defaultMessage: "Editor preset is required",
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import pluginId from "./pluginId";
|
|
2
|
+
|
|
3
|
+
const insertConfigScript = () => {
|
|
4
|
+
const url =
|
|
5
|
+
strapi.backendURL !== "/"
|
|
6
|
+
? `${strapi.backendURL}/${pluginId}/ckeditor-config`
|
|
7
|
+
: `/${pluginId}/ckeditor-config`;
|
|
8
|
+
|
|
9
|
+
var script = document.createElement("script");
|
|
10
|
+
script.id = "ckeditor-config";
|
|
11
|
+
script.src = url;
|
|
12
|
+
document.body.appendChild(script);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const waitForConfigToInitialize = async () => {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
(function checkConfigLoaded() {
|
|
18
|
+
if (typeof globalThis.CKEditorConfig !== "undefined") {
|
|
19
|
+
resolve(globalThis.CKEditorConfig);
|
|
20
|
+
} else setTimeout(checkConfigLoaded, 5);
|
|
21
|
+
})();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getEditorConfig = async () => {
|
|
26
|
+
// raw config/ckeditor.[js|ts] file
|
|
27
|
+
// Can be used with non-JSON serializable properties
|
|
28
|
+
insertConfigScript();
|
|
29
|
+
const configFromScript = await waitForConfigToInitialize();
|
|
30
|
+
if (configFromScript) {
|
|
31
|
+
return configFromScript;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default getEditorConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@_sh/strapi-plugin-ckeditor",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Integrates CKEditor 5 into your Strapi project as a fully customizable custom field. (Unofficial integration)",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
7
7
|
"strapi",
|
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
"editor"
|
|
14
14
|
],
|
|
15
15
|
"strapi": {
|
|
16
|
-
"
|
|
17
|
-
"name": "ckeditor",
|
|
16
|
+
"name": "ckeditor5",
|
|
18
17
|
"displayName": "CKEditor 5",
|
|
19
|
-
"description": "
|
|
18
|
+
"description": "Integrates CKEditor 5 into your Strapi project as a fully customizable custom field. (Unofficial integration)",
|
|
20
19
|
"kind": "plugin"
|
|
21
20
|
},
|
|
22
21
|
"files": [
|
|
@@ -26,10 +25,47 @@
|
|
|
26
25
|
"strapi-server.js"
|
|
27
26
|
],
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"
|
|
28
|
+
"ckeditor5": "^36.0.0",
|
|
29
|
+
"@ckeditor/ckeditor5-react": "^5.0.6",
|
|
30
|
+
"@ckeditor/ckeditor5-alignment": "^36.0.0",
|
|
31
|
+
"@ckeditor/ckeditor5-autoformat": "^36.0.0",
|
|
32
|
+
"@ckeditor/ckeditor5-autosave": "^36.0.0",
|
|
33
|
+
"@ckeditor/ckeditor5-basic-styles": "^36.0.0",
|
|
34
|
+
"@ckeditor/ckeditor5-block-quote": "^36.0.0",
|
|
35
|
+
"@ckeditor/ckeditor5-style": "^36.0.0",
|
|
36
|
+
"@ckeditor/ckeditor5-code-block": "^36.0.0",
|
|
37
|
+
"@ckeditor/ckeditor5-easy-image": "^36.0.0",
|
|
38
|
+
"@ckeditor/ckeditor5-editor-classic": "^36.0.0",
|
|
39
|
+
"@ckeditor/ckeditor5-essentials": "^36.0.0",
|
|
40
|
+
"@ckeditor/ckeditor5-find-and-replace": "^36.0.0",
|
|
41
|
+
"@ckeditor/ckeditor5-heading": "^36.0.0",
|
|
42
|
+
"@ckeditor/ckeditor5-highlight": "^36.0.0",
|
|
43
|
+
"@ckeditor/ckeditor5-horizontal-line": "^36.0.0",
|
|
44
|
+
"@ckeditor/ckeditor5-html-embed": "^36.0.0",
|
|
45
|
+
"@ckeditor/ckeditor5-html-support": "^36.0.0",
|
|
46
|
+
"@ckeditor/ckeditor5-image": "^36.0.0",
|
|
47
|
+
"@ckeditor/ckeditor5-indent": "^36.0.0",
|
|
48
|
+
"@ckeditor/ckeditor5-language": "^36.0.0",
|
|
49
|
+
"@ckeditor/ckeditor5-link": "^36.0.0",
|
|
50
|
+
"@ckeditor/ckeditor5-list": "^36.0.0",
|
|
51
|
+
"@ckeditor/ckeditor5-mention": "^36.0.0",
|
|
52
|
+
"@ckeditor/ckeditor5-media-embed": "^36.0.0",
|
|
53
|
+
"@ckeditor/ckeditor5-page-break": "^36.0.0",
|
|
54
|
+
"@ckeditor/ckeditor5-paragraph": "^36.0.0",
|
|
55
|
+
"@ckeditor/ckeditor5-paste-from-office": "^36.0.0",
|
|
56
|
+
"@ckeditor/ckeditor5-remove-format": "^36.0.0",
|
|
57
|
+
"@ckeditor/ckeditor5-special-characters": "^36.0.0",
|
|
58
|
+
"@ckeditor/ckeditor5-source-editing": "^36.0.0",
|
|
59
|
+
"@ckeditor/ckeditor5-table": "^36.0.0",
|
|
60
|
+
"@ckeditor/ckeditor5-theme-lark": "^36.0.0",
|
|
61
|
+
"@ckeditor/ckeditor5-typing": "^36.0.0",
|
|
62
|
+
"@ckeditor/ckeditor5-upload": "^36.0.0",
|
|
63
|
+
"@ckeditor/ckeditor5-word-count": "^36.0.0",
|
|
64
|
+
"sanitize-html": "^2.8.1",
|
|
65
|
+
"@_sh/ckeditor5-font-with-picker": "^0.0.1"
|
|
30
66
|
},
|
|
31
67
|
"peerDependencies": {
|
|
32
|
-
"@strapi/strapi": "^4.
|
|
68
|
+
"@strapi/strapi": "^4.4.0"
|
|
33
69
|
},
|
|
34
70
|
"author": {
|
|
35
71
|
"name": "nshenderov"
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const pluginId = require("../../admin/src/utils/pluginId");
|
|
4
|
+
|
|
3
5
|
module.exports = {
|
|
4
|
-
getConfig: async (ctx) => {
|
|
5
|
-
const { configKey } = ctx.params;
|
|
6
|
-
if(configKey === 'uploadcfg'){
|
|
7
|
-
const uploadConfig = await strapi.plugin('ckeditor').service('config').getUploadConfig('upload').getSettings();
|
|
8
|
-
ctx.send(uploadConfig);
|
|
9
|
-
}else{
|
|
10
|
-
const config = await strapi.plugin('ckeditor').service('config').getConfig(configKey);
|
|
11
|
-
ctx.send(config);
|
|
12
|
-
}
|
|
13
6
|
|
|
7
|
+
getUploadConfig: async (ctx) => {
|
|
8
|
+
const uploadConfig = await strapi.plugin(pluginId).service('config').getUploadConfig('upload').getSettings();
|
|
9
|
+
ctx.send(uploadConfig);
|
|
14
10
|
},
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
const config = await strapi.plugin(
|
|
18
|
-
ctx.type = '
|
|
12
|
+
getCKEditorConfig: async (ctx) => {
|
|
13
|
+
const config = await strapi.plugin(pluginId).service('config').getCKEditorConfig();
|
|
14
|
+
ctx.type = 'text/javascript';
|
|
19
15
|
ctx.send(config);
|
|
20
16
|
}
|
|
21
17
|
};
|
package/server/index.js
CHANGED
package/server/register.js
CHANGED
package/server/routes/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
module.exports = [
|
|
2
2
|
{
|
|
3
3
|
method: 'GET',
|
|
4
|
-
path: '/config
|
|
5
|
-
handler: 'config.
|
|
6
|
-
config: {policies: []},
|
|
4
|
+
path: '/config/upload',
|
|
5
|
+
handler: 'config.getUploadConfig',
|
|
7
6
|
},
|
|
8
7
|
{
|
|
9
8
|
method: 'GET',
|
|
10
|
-
path: '/
|
|
11
|
-
handler: 'config.
|
|
9
|
+
path: '/ckeditor-config',
|
|
10
|
+
handler: 'config.getCKEditorConfig',
|
|
12
11
|
config: {
|
|
13
|
-
auth: false
|
|
12
|
+
auth: false
|
|
14
13
|
},
|
|
15
14
|
}
|
|
16
15
|
];
|
|
@@ -2,27 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* config.js configuration service
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
5
|
module.exports = ({ strapi }) => {
|
|
10
6
|
return {
|
|
11
|
-
|
|
12
|
-
return strapi.plugin('
|
|
7
|
+
getUploadConfig(name) {
|
|
8
|
+
return strapi.plugin('upload').service(name) ?? {};
|
|
13
9
|
},
|
|
14
|
-
|
|
10
|
+
getCKEditorConfig() {
|
|
15
11
|
const appDir = process.cwd();
|
|
16
12
|
const isTSProject = fs.existsSync(`${appDir}/dist`);
|
|
17
13
|
const jsDir = isTSProject ? `${appDir}/dist` : appDir;
|
|
18
14
|
|
|
19
|
-
const filename = `${jsDir}/config/ckeditor.
|
|
15
|
+
const filename = `${jsDir}/config/ckeditor.txt`;
|
|
20
16
|
return fs.existsSync(filename)
|
|
21
17
|
? fs.readFileSync(filename)
|
|
22
|
-
: 'globalThis.
|
|
23
|
-
},
|
|
24
|
-
getUploadConfig(name) {
|
|
25
|
-
return strapi.plugin('upload').service(name) ?? {};
|
|
18
|
+
: 'globalThis.CKEditorConfig = null'
|
|
26
19
|
},
|
|
27
20
|
};
|
|
28
21
|
};
|