@_sh/strapi-plugin-ckeditor 4.0.11 → 5.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 +586 -575
- package/dist/_chunks/Field-8Nh0dMSc.mjs +574 -0
- package/dist/_chunks/Field-BKtrDFjh.js +598 -0
- package/dist/_chunks/index-CNalXcwy.mjs +1330 -0
- package/dist/_chunks/index-DO2vqIdx.js +1350 -0
- package/dist/admin/index.js +11 -4
- package/dist/admin/index.mjs +10 -4
- package/dist/admin/src/components/CKEReact.d.ts +6 -0
- package/dist/admin/src/components/CKEditorIcon.d.ts +1 -0
- package/dist/admin/src/components/Editor.d.ts +1 -0
- package/dist/admin/src/components/EditorLayout.d.ts +4 -0
- package/dist/admin/src/components/EditorProvider.d.ts +20 -0
- package/dist/admin/src/components/Field.d.ts +20 -0
- package/dist/admin/src/components/GlobalStyling.d.ts +4 -0
- package/dist/admin/src/components/MediaLib.d.ts +9 -0
- package/dist/admin/src/config/htmlPreset.d.ts +2 -0
- package/dist/admin/src/config/index.d.ts +5 -0
- package/dist/admin/src/config/language.d.ts +15 -0
- package/dist/admin/src/config/markdownPreset.d.ts +2 -0
- package/dist/admin/src/config/pluginConfig.d.ts +23 -0
- package/dist/admin/src/config/types.d.ts +123 -0
- package/dist/admin/src/exports.d.ts +9 -0
- package/dist/admin/src/index.d.ts +6 -0
- package/dist/admin/src/plugins/StrapiMediaLib.d.ts +15 -0
- package/dist/admin/src/plugins/StrapiUploadAdapter.d.ts +12 -0
- package/dist/admin/src/plugins/index.d.ts +2 -0
- package/dist/admin/src/theme/additional.d.ts +1 -0
- package/dist/admin/src/theme/colors.d.ts +1 -0
- package/dist/admin/src/theme/common.d.ts +1 -0
- package/dist/admin/src/theme/dark.d.ts +1 -0
- package/dist/admin/src/theme/index.d.ts +2 -0
- package/dist/admin/src/theme/light.d.ts +1 -0
- package/dist/admin/src/utils/index.d.ts +4 -0
- package/dist/admin/src/utils/isImageResponsive.d.ts +3 -0
- package/dist/admin/src/utils/localStorage.d.ts +3 -0
- package/dist/admin/src/utils/pluginId.d.ts +1 -0
- package/dist/admin/src/utils/prefixWithBackendUrl.d.ts +1 -0
- package/dist/server/index.js +61 -119
- package/dist/server/index.mjs +61 -117
- package/dist/server/src/index.d.ts +7 -0
- package/package.json +50 -22
- package/dist/_chunks/index-5LGZsCS3.mjs +0 -1125
- package/dist/_chunks/index-5LGZsCS3.mjs.map +0 -1
- package/dist/_chunks/index-B5HkOicq.mjs +0 -3530
- package/dist/_chunks/index-B5HkOicq.mjs.map +0 -1
- package/dist/_chunks/index-BOqpyEaD.js +0 -1150
- package/dist/_chunks/index-BOqpyEaD.js.map +0 -1
- package/dist/_chunks/index-BQ7yqvCN.mjs +0 -1124
- package/dist/_chunks/index-BQ7yqvCN.mjs.map +0 -1
- package/dist/_chunks/index-BZP-quaN.mjs +0 -3530
- package/dist/_chunks/index-BZP-quaN.mjs.map +0 -1
- package/dist/_chunks/index-BZZiYjTp.mjs +0 -3530
- package/dist/_chunks/index-BZZiYjTp.mjs.map +0 -1
- package/dist/_chunks/index-Be-t5n4r.mjs +0 -1125
- package/dist/_chunks/index-Be-t5n4r.mjs.map +0 -1
- package/dist/_chunks/index-BiOS6ItS.js +0 -1150
- package/dist/_chunks/index-BiOS6ItS.js.map +0 -1
- package/dist/_chunks/index-C4BPSFZt.mjs +0 -3530
- package/dist/_chunks/index-C4BPSFZt.mjs.map +0 -1
- package/dist/_chunks/index-CFskHjqL.js +0 -3548
- package/dist/_chunks/index-CFskHjqL.js.map +0 -1
- package/dist/_chunks/index-CPBrnTwd.mjs +0 -1124
- package/dist/_chunks/index-CPBrnTwd.mjs.map +0 -1
- package/dist/_chunks/index-CRK4zk5I.js +0 -3548
- package/dist/_chunks/index-CRK4zk5I.js.map +0 -1
- package/dist/_chunks/index-CUmwBN9O.js +0 -1151
- package/dist/_chunks/index-CUmwBN9O.js.map +0 -1
- package/dist/_chunks/index-CaYpAgjX.js +0 -1151
- package/dist/_chunks/index-CaYpAgjX.js.map +0 -1
- package/dist/_chunks/index-pRK2Er3w.js +0 -3548
- package/dist/_chunks/index-pRK2Er3w.js.map +0 -1
- package/dist/_chunks/index-uYy-Myyv.js +0 -3548
- package/dist/_chunks/index-uYy-Myyv.js.map +0 -1
- package/dist/admin/index.js.map +0 -1
- package/dist/admin/index.mjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/README.md
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/
|
|
2
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-head.png"/>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<h1 align="center">
|
|
5
|
+
<h1 align="center">Strapi ➕ CKEditor</h1>
|
|
6
6
|
|
|
7
|
-
<p align="center">Integrates CKEditor 5 into your Strapi project as a fully customizable custom field. (
|
|
7
|
+
<p align="center">Integrates CKEditor 5 into your Strapi project as a fully customizable custom field. (Community edition)</p>
|
|
8
8
|
|
|
9
9
|
## 👋 Get Started
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Usage](#usage)
|
|
14
|
+
- [Configuration](#configuration)
|
|
15
|
+
- [Contributing](#contributing)
|
|
16
|
+
- [Migration](#migration)
|
|
17
|
+
- [Requirements](#requirements)
|
|
18
18
|
|
|
19
19
|
## <a id="features"></a>✨ Features
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
- **Extensive configuration**
|
|
22
|
+
- **Media Library integration**
|
|
23
|
+
- **Dark theme support**
|
|
24
|
+
- **Fullscreen expansion**
|
|
25
|
+
- **Responsive images support**
|
|
26
|
+
- **Automatic UI translations**
|
|
27
|
+
- **i18n support**
|
|
28
|
+
- **Self-Hosted**
|
|
28
29
|
|
|
29
30
|
<p align="right">
|
|
30
31
|
<a href="https://www.buymeacoffee.com/nshenderov" target="_blank">
|
|
31
|
-
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px
|
|
32
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px; width: 217px;" >
|
|
32
33
|
</a>
|
|
33
34
|
</p>
|
|
34
35
|
|
|
35
|
-
|
|
36
36
|
## <a id="installation"></a>🔧 Installation
|
|
37
37
|
|
|
38
|
+
**Strapi v5:**
|
|
38
39
|
|
|
39
40
|
Add the package to your Strapi application:
|
|
40
41
|
|
|
@@ -42,683 +43,693 @@ Add the package to your Strapi application:
|
|
|
42
43
|
yarn add @_sh/strapi-plugin-ckeditor
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
For Strapi v4:
|
|
46
|
-
```bash
|
|
47
|
-
yarn add @_sh/strapi-plugin-ckeditor@strapi-v4-latest
|
|
48
|
-
```
|
|
49
|
-
|
|
50
46
|
Then, build the app:
|
|
51
47
|
|
|
52
48
|
```bash
|
|
53
49
|
yarn build
|
|
54
50
|
```
|
|
55
51
|
|
|
52
|
+
**Strapi v4:**
|
|
53
|
+
|
|
54
|
+
Version 3 of the plugin will remain available for Strapi v4 until March 2026.
|
|
55
|
+
Refer to the [**v3 installation guide**](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/3.x.x/README.md#installation)
|
|
56
|
+
for setup instructions.
|
|
57
|
+
|
|
58
|
+
> Note: Version 3 receives only essential bug fixes. The configuration process and available
|
|
59
|
+
> features in version 3 differ significantly from the latest plugin versions.
|
|
60
|
+
|
|
56
61
|
## <a id="usage"></a>✍️ Usage
|
|
57
62
|
|
|
63
|
+
The field can be fould in the Content-Type Builder under the `CUSTOM` tab:
|
|
64
|
+
|
|
58
65
|
<p align="center">
|
|
59
|
-
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/usage-guide.
|
|
66
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-usage-guide-2.png" width="700" />
|
|
60
67
|
</p>
|
|
61
68
|
|
|
69
|
+
**Presets**
|
|
70
|
+
|
|
71
|
+
A preset is a set of settings that define the editor's features and appearence. You
|
|
72
|
+
can specify a dedicated preset for each field. The available presets can be customized through the
|
|
73
|
+
[configuration](#configuration).
|
|
74
|
+
|
|
75
|
+
<p align="center">
|
|
76
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-usage-guide-3.png" width="700" />
|
|
77
|
+
</p>
|
|
78
|
+
|
|
79
|
+
The plugin provides two presets out of the box: `Default HTML editor` and `Default Markdown editor`,
|
|
80
|
+
each has different output format: HTML and Markdown, respectively. Both presets include
|
|
81
|
+
an extensive set of non-premium CKEditor plugins.
|
|
82
|
+
|
|
62
83
|
<details>
|
|
63
|
-
<summary
|
|
64
|
-
|
|
84
|
+
<summary>Default HTML editor:</summary>
|
|
85
|
+
|
|
86
|
+
<p align="center">
|
|
87
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-def-html-dark.png" width="700" />
|
|
88
|
+
</p>
|
|
89
|
+
|
|
90
|
+
<p align="center">
|
|
91
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-def-html-light.png" width="700" />
|
|
92
|
+
</p>
|
|
93
|
+
|
|
65
94
|
<p align="center">
|
|
66
|
-
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/
|
|
95
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-def-html-light-full.png" width="700" />
|
|
67
96
|
</p>
|
|
68
97
|
|
|
69
98
|
</details>
|
|
70
99
|
|
|
71
|
-
|
|
100
|
+
<details>
|
|
101
|
+
<summary>Default Markdown editor:</summary>
|
|
72
102
|
|
|
103
|
+
<p align="center">
|
|
104
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-def-mrk-dark.png" width="700" />
|
|
105
|
+
</p>
|
|
73
106
|
|
|
74
|
-
>
|
|
75
|
-
|
|
76
|
-
>
|
|
107
|
+
<p align="center">
|
|
108
|
+
<img src="https://raw.githubusercontent.com/nshenderov/strapi-plugin-ckeditor/master/assets/v5-def-mrk-light.png" width="700" />
|
|
109
|
+
</p>
|
|
77
110
|
|
|
78
|
-
|
|
111
|
+
</details>
|
|
79
112
|
|
|
80
|
-
|
|
113
|
+
**Responsive images**
|
|
81
114
|
|
|
82
|
-
The plugin
|
|
115
|
+
The plugin generates `srcset` attribute for inserted images if the image has any `formats` other than `thumbnail`.
|
|
83
116
|
|
|
84
|
-
|
|
117
|
+
**UI language**: If you don't specify the UI language in the editor configuration, the plugin will
|
|
118
|
+
default to the Strapi admin's preferred language. If no preference is set, English will be used as a fallback.
|
|
85
119
|
|
|
86
|
-
|
|
120
|
+
**Content language**: i18n for the editor's content language can be enabled by checking the
|
|
121
|
+
`Enable localization for this field` option in the Advanced Settings tab.
|
|
87
122
|
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
dontMergePresets:bool,
|
|
91
|
-
dontMergeTheme:bool,
|
|
92
|
-
presets:{
|
|
93
|
-
default:{
|
|
94
|
-
field:{...},
|
|
95
|
-
styles:string,
|
|
96
|
-
editorConfig:{...},
|
|
97
|
-
},
|
|
98
|
-
...
|
|
99
|
-
},
|
|
100
|
-
theme:{
|
|
101
|
-
common:string,
|
|
102
|
-
light:string,
|
|
103
|
-
dark:string,
|
|
104
|
-
additional:string,
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
```
|
|
123
|
+
## <a id="configuration"></a>⚙️ Configuration
|
|
108
124
|
|
|
109
|
-
|
|
125
|
+
The plugin configuration must be defined on the front-end. The plugin provides a `setPluginConfig`
|
|
126
|
+
function, which accepts a plugin configuration (`PluginConfig`) that can include an array of presets
|
|
127
|
+
and a theme object:
|
|
110
128
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
3. `editorConfig (object)` The CKEditor configuration.
|
|
129
|
+
```ts
|
|
130
|
+
import { setPluginConfig } from '@_sh/strapi-plugin-ckeditor';
|
|
114
131
|
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
function setPluginConfig(pluginConfig: {
|
|
133
|
+
presets: Preset[] | undefined;
|
|
134
|
+
theme: Theme | undefined;
|
|
135
|
+
}): void;
|
|
136
|
+
```
|
|
117
137
|
|
|
118
|
-
|
|
119
|
-
2. `light (string)` Styles applied to the editor when Strapi is in light mode.
|
|
120
|
-
3. `dark (string)` Styles applied to the editor when Strapi is in dark mode.
|
|
121
|
-
4. `additional (string)` Additional styles to further enhance the editors appearance.
|
|
138
|
+
**Key points:**
|
|
122
139
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
140
|
+
- The function must be invoked before the admin panel's bootstrap lifecycle function. The general recommendation is to call it inside the admin panel's register lifecycle function.
|
|
141
|
+
- Provided properties will overwrite the default configuration values.
|
|
142
|
+
- The configuration becomes immutable after the first invocation, preventing further modifications.
|
|
126
143
|
|
|
127
|
-
|
|
128
|
-
2. `dontMergeTheme (bool)`
|
|
144
|
+
**Plugin configuration object** includes optional `presets` and `theme` properties:
|
|
129
145
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
146
|
+
```ts
|
|
147
|
+
type PluginConfig = {
|
|
148
|
+
/**
|
|
149
|
+
* Presets are sets of settings that define the editor's features and appearance.
|
|
150
|
+
*/
|
|
151
|
+
presets?: Preset[];
|
|
152
|
+
/**
|
|
153
|
+
* Styles applied globally to every editor instance.
|
|
154
|
+
*/
|
|
155
|
+
theme?: Theme;
|
|
156
|
+
};
|
|
157
|
+
```
|
|
133
158
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
159
|
+
`presets` is an array of objects of type `Preset`. Each preset includes the following properties:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
type Preset = {
|
|
163
|
+
/**
|
|
164
|
+
* Preset name, displayed in the schema.
|
|
165
|
+
*/
|
|
166
|
+
name: string;
|
|
167
|
+
/**
|
|
168
|
+
* Preset description, displayed in the Content-Type Builder.
|
|
169
|
+
*/
|
|
170
|
+
description: string;
|
|
171
|
+
/**
|
|
172
|
+
* CKEditor configuration object.
|
|
173
|
+
*
|
|
174
|
+
* @see {@link https://ckeditor.com/docs/ckeditor5/latest/getting-started/setup/configuration.html | CKEditor documentation}
|
|
175
|
+
*/
|
|
176
|
+
editorConfig: EditorConfig;
|
|
177
|
+
/**
|
|
178
|
+
* Additional styles applied to the editor instance after the theme styles.
|
|
179
|
+
*/
|
|
180
|
+
styles?: EditorStyles;
|
|
181
|
+
};
|
|
140
182
|
```
|
|
141
|
-
The language determination follows this logic:
|
|
142
183
|
|
|
143
|
-
|
|
144
|
-
|
|
184
|
+
`theme` object defines a plugin CSS styles applied to every editor instance. It includes the
|
|
185
|
+
following properties:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
/**
|
|
189
|
+
* The `common` styles are applied first, followed by `light` or `dark` styles
|
|
190
|
+
* according to the preferences, and finally `additional` styles.
|
|
191
|
+
*/
|
|
192
|
+
type Theme = {
|
|
193
|
+
/**
|
|
194
|
+
* Core styles.
|
|
195
|
+
*/
|
|
196
|
+
common?: EditorStyles;
|
|
197
|
+
/**
|
|
198
|
+
* Styles apllied in light mode.
|
|
199
|
+
*/
|
|
200
|
+
light?: EditorStyles;
|
|
201
|
+
/**
|
|
202
|
+
* Styles apllied in dark mode.
|
|
203
|
+
*/
|
|
204
|
+
dark?: EditorStyles;
|
|
205
|
+
/**
|
|
206
|
+
* Additional styles that complement the theme.
|
|
207
|
+
*/
|
|
208
|
+
additional?: EditorStyles;
|
|
209
|
+
};
|
|
210
|
+
```
|
|
145
211
|
|
|
146
|
-
|
|
147
|
-
|
|
212
|
+
```ts
|
|
213
|
+
/**
|
|
214
|
+
* Represents styles that can be applied to an editor instance.
|
|
215
|
+
* Can be a plain CSS string or an array of interpolations for dynamic styling.
|
|
216
|
+
*/
|
|
217
|
+
export type EditorStyles = string | Interpolation<object>[];
|
|
218
|
+
```
|
|
148
219
|
|
|
149
|
-
|
|
220
|
+
**Default presets and theme**
|
|
150
221
|
|
|
151
|
-
|
|
222
|
+
To simplify the process of defining a new preset, the plugin exports default presets and
|
|
223
|
+
a default theme, which can be used as a base in custom configurations:
|
|
152
224
|
|
|
153
|
-
|
|
154
|
-
|
|
225
|
+
```ts
|
|
226
|
+
import {
|
|
227
|
+
defaultTheme,
|
|
228
|
+
defaultHtmlPreset,
|
|
229
|
+
defaultMarkdownPreset,
|
|
230
|
+
} from '@_sh/strapi-plugin-ckeditor';
|
|
231
|
+
```
|
|
155
232
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
metadatas: {
|
|
164
|
-
intlLabel: {
|
|
165
|
-
id: "ckeditor.preset.markdown.label",
|
|
166
|
-
defaultMessage: "Markdown output",
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
editorConfig:{
|
|
171
|
-
placeholder: 'Markdown editor',
|
|
172
|
-
plugins: [
|
|
173
|
-
globalThis.SH_CKE.Essentials,
|
|
174
|
-
globalThis.SH_CKE.Autoformat,
|
|
175
|
-
globalThis.SH_CKE.BlockQuote,
|
|
176
|
-
globalThis.SH_CKE.Bold,
|
|
177
|
-
globalThis.SH_CKE.Heading,
|
|
178
|
-
globalThis.SH_CKE.Image,
|
|
179
|
-
globalThis.SH_CKE.ImageCaption,
|
|
180
|
-
globalThis.SH_CKE.ImageStyle,
|
|
181
|
-
globalThis.SH_CKE.ImageToolbar,
|
|
182
|
-
globalThis.SH_CKE.ImageUpload,
|
|
183
|
-
globalThis.SH_CKE.Indent,
|
|
184
|
-
globalThis.SH_CKE.Italic,
|
|
185
|
-
globalThis.SH_CKE.Link,
|
|
186
|
-
globalThis.SH_CKE.List,
|
|
187
|
-
globalThis.SH_CKE.MediaEmbed,
|
|
188
|
-
globalThis.SH_CKE.Paragraph,
|
|
189
|
-
globalThis.SH_CKE.Table,
|
|
190
|
-
globalThis.SH_CKE.TableToolbar,
|
|
191
|
-
globalThis.SH_CKE.SourceEditing,
|
|
192
|
-
globalThis.SH_CKE.StrapiMediaLib,
|
|
193
|
-
globalThis.SH_CKE.StrapiUploadAdapter,
|
|
194
|
-
globalThis.SH_CKE.Markdown,
|
|
195
|
-
globalThis.SH_CKE.Code,
|
|
196
|
-
globalThis.SH_CKE.CodeBlock,
|
|
197
|
-
globalThis.SH_CKE.TodoList,
|
|
198
|
-
globalThis.SH_CKE.Strikethrough,
|
|
199
|
-
globalThis.SH_CKE.HorizontalLine
|
|
200
|
-
],
|
|
201
|
-
toolbar: {
|
|
202
|
-
items: [
|
|
203
|
-
'heading',
|
|
204
|
-
'|',
|
|
205
|
-
'bold',
|
|
206
|
-
'italic',
|
|
207
|
-
'strikethrough',
|
|
208
|
-
'link',
|
|
209
|
-
'|',
|
|
210
|
-
'bulletedList',
|
|
211
|
-
'numberedList',
|
|
212
|
-
'todoList',
|
|
213
|
-
'|',
|
|
214
|
-
'code',
|
|
215
|
-
'codeBlock',
|
|
216
|
-
'|',
|
|
217
|
-
'uploadImage',
|
|
218
|
-
'strapiMediaLib',
|
|
219
|
-
'blockQuote',
|
|
220
|
-
'horizontalLine',
|
|
221
|
-
'-',
|
|
222
|
-
'sourceEditing',
|
|
223
|
-
'|',
|
|
224
|
-
'outdent',
|
|
225
|
-
'indent',
|
|
226
|
-
'|',
|
|
227
|
-
'undo',
|
|
228
|
-
'redo'
|
|
229
|
-
],
|
|
230
|
-
shouldNotGroupWhenFull: true
|
|
231
|
-
},
|
|
232
|
-
image: {
|
|
233
|
-
toolbar: [ 'imageStyle:inline', 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ]
|
|
234
|
-
},
|
|
235
|
-
codeBlock: {
|
|
236
|
-
languages: [
|
|
237
|
-
{ language: 'css', label: 'CSS' },
|
|
238
|
-
{ language: 'html', label: 'HTML' },
|
|
239
|
-
{ language: 'javascript', label: 'JavaScript' },
|
|
240
|
-
{ language: 'php', label: 'PHP' }
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
}
|
|
246
|
-
})
|
|
233
|
+
**Integration with Strapi's Media Library**
|
|
234
|
+
|
|
235
|
+
To integrate CKEditor with the Strapi's Media Library, the plugin provides two CKEditor plugins
|
|
236
|
+
that can be included in your presets without additional configuration:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
import { StrapiMediaLib, StrapiUploadAdapter } from '@_sh/strapi-plugin-ckeditor';
|
|
247
240
|
```
|
|
248
241
|
|
|
249
|
-
|
|
242
|
+
**Available type definitions**
|
|
250
243
|
|
|
251
|
-
|
|
244
|
+
The following type definitions are available for use:
|
|
252
245
|
|
|
253
|
-
|
|
246
|
+
```ts
|
|
247
|
+
import type {
|
|
248
|
+
PluginConfig,
|
|
249
|
+
Preset,
|
|
250
|
+
EditorConfig,
|
|
251
|
+
Theme,
|
|
252
|
+
EditorStyles,
|
|
253
|
+
} from '@_sh/strapi-plugin-ckeditor';
|
|
254
|
+
```
|
|
254
255
|
|
|
255
256
|
<details>
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
max-height: 400px;
|
|
273
|
-
}
|
|
274
|
-
.ck.ck-content.ck-editor__editable.ck-rounded-corners.ck-editor__editable_inline.ck-focused{
|
|
275
|
-
min-height: 400px;
|
|
276
|
-
max-height: 1700px;
|
|
277
|
-
}
|
|
278
|
-
`,
|
|
279
|
-
editorConfig:{
|
|
280
|
-
plugins: [
|
|
281
|
-
globalThis.SH_CKE.Bold,
|
|
282
|
-
globalThis.SH_CKE.Italic,
|
|
283
|
-
globalThis.SH_CKE.Essentials,
|
|
284
|
-
globalThis.SH_CKE.Heading,
|
|
285
|
-
globalThis.SH_CKE.Image,
|
|
286
|
-
globalThis.SH_CKE.ImageCaption,
|
|
287
|
-
globalThis.SH_CKE.ImageStyle,
|
|
288
|
-
globalThis.SH_CKE.ImageToolbar,
|
|
289
|
-
globalThis.SH_CKE.Link,
|
|
290
|
-
globalThis.SH_CKE.List,
|
|
291
|
-
globalThis.SH_CKE.Paragraph,
|
|
292
|
-
globalThis.SH_CKE.StrapiMediaLib,
|
|
293
|
-
globalThis.SH_CKE.StrapiUploadAdapter,
|
|
294
|
-
],
|
|
295
|
-
toolbar: [
|
|
296
|
-
'heading',
|
|
297
|
-
'|',
|
|
298
|
-
'bold', 'italic', 'link', 'bulletedList', 'numberedList',
|
|
299
|
-
'|',
|
|
300
|
-
'strapiMediaLib', 'insertTable',
|
|
301
|
-
'|',
|
|
302
|
-
'undo', 'redo'
|
|
303
|
-
]
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
})
|
|
257
|
+
<summary>Type definitions</summary>
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
/**
|
|
261
|
+
* Plugin configuration object.
|
|
262
|
+
*/
|
|
263
|
+
export type PluginConfig = {
|
|
264
|
+
/**
|
|
265
|
+
* Presets are sets of settings that define the editor's features and appearance.
|
|
266
|
+
*/
|
|
267
|
+
presets?: Preset[];
|
|
268
|
+
/**
|
|
269
|
+
* Styles applied globally to every editor instance.
|
|
270
|
+
*/
|
|
271
|
+
theme?: Theme;
|
|
272
|
+
};
|
|
308
273
|
```
|
|
309
274
|
|
|
310
|
-
|
|
275
|
+
```ts
|
|
276
|
+
/**
|
|
277
|
+
* Preset is a set of settings that define the editor's features and appearance.
|
|
278
|
+
*/
|
|
279
|
+
export type Preset = {
|
|
280
|
+
/**
|
|
281
|
+
* Preset name, displayed in the schema.
|
|
282
|
+
*/
|
|
283
|
+
name: string;
|
|
284
|
+
/**
|
|
285
|
+
* Preset description, displayed in the Content-Type Builder.
|
|
286
|
+
*/
|
|
287
|
+
description: string;
|
|
288
|
+
/**
|
|
289
|
+
* Additional styles applied to the editor instance after the theme styles.
|
|
290
|
+
*/
|
|
291
|
+
styles?: EditorStyles;
|
|
292
|
+
/**
|
|
293
|
+
* CKEditor configuration object.
|
|
294
|
+
*
|
|
295
|
+
* @see {@link https://ckeditor.com/docs/ckeditor5/latest/getting-started/setup/configuration.html | CKEditor documentation}
|
|
296
|
+
*/
|
|
297
|
+
editorConfig: EditorConfig;
|
|
298
|
+
};
|
|
299
|
+
```
|
|
311
300
|
|
|
312
|
-
|
|
301
|
+
```ts
|
|
302
|
+
/**
|
|
303
|
+
* CKEditor configuration object.
|
|
304
|
+
*
|
|
305
|
+
* @see {@link https://ckeditor.com/docs/ckeditor5/latest/getting-started/setup/configuration.html | CKEditor documentation}
|
|
306
|
+
*/
|
|
307
|
+
export type EditorConfig = CKE5EditorConfig;
|
|
308
|
+
```
|
|
313
309
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
310
|
+
```ts
|
|
311
|
+
/**
|
|
312
|
+
* Styles applied globally to every editor instance.
|
|
313
|
+
*
|
|
314
|
+
* @remarks
|
|
315
|
+
*
|
|
316
|
+
* The `common` styles are applied first, followed by `light` or `dark` styles
|
|
317
|
+
* according to the preferences, and finally `additional` styles.
|
|
318
|
+
*/
|
|
319
|
+
export type Theme = {
|
|
320
|
+
/**
|
|
321
|
+
* Core styles.
|
|
322
|
+
*/
|
|
323
|
+
common?: EditorStyles;
|
|
324
|
+
/**
|
|
325
|
+
* Styles apllied in light mode.
|
|
326
|
+
*/
|
|
327
|
+
light?: EditorStyles;
|
|
328
|
+
/**
|
|
329
|
+
* Styles apllied in dark mode.
|
|
330
|
+
*/
|
|
331
|
+
dark?: EditorStyles;
|
|
332
|
+
/**
|
|
333
|
+
* Additional styles that complement the theme.
|
|
334
|
+
*/
|
|
335
|
+
additional?: EditorStyles;
|
|
336
|
+
};
|
|
337
|
+
```
|
|
317
338
|
|
|
318
|
-
|
|
339
|
+
```ts
|
|
340
|
+
/**
|
|
341
|
+
* Represents styles that can be applied to an editor instance.
|
|
342
|
+
* Can be a plain CSS string or an array of interpolations for dynamic styling.
|
|
343
|
+
*/
|
|
344
|
+
export type EditorStyles = string | Interpolation<object>[];
|
|
345
|
+
```
|
|
319
346
|
|
|
320
|
-
|
|
347
|
+
</details>
|
|
321
348
|
|
|
322
|
-
|
|
349
|
+
### Configuration examples:
|
|
323
350
|
|
|
324
|
-
|
|
351
|
+
<details>
|
|
352
|
+
<summary>Adding a new preset [JS]</summary>
|
|
325
353
|
|
|
326
354
|
```js
|
|
327
|
-
//
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
// src/admin/app.js
|
|
356
|
+
|
|
357
|
+
import {
|
|
358
|
+
Bold,
|
|
359
|
+
Italic,
|
|
360
|
+
Essentials,
|
|
361
|
+
Heading,
|
|
362
|
+
Image,
|
|
363
|
+
ImageCaption,
|
|
364
|
+
ImageStyle,
|
|
365
|
+
ImageToolbar,
|
|
366
|
+
ImageUpload,
|
|
367
|
+
Link,
|
|
368
|
+
List,
|
|
369
|
+
Paragraph,
|
|
370
|
+
} from 'ckeditor5';
|
|
371
|
+
|
|
372
|
+
import { setPluginConfig, StrapiMediaLib, StrapiUploadAdapter } from '@_sh/strapi-plugin-ckeditor';
|
|
373
|
+
|
|
374
|
+
const myCustomPreset = {
|
|
375
|
+
name: 'myCustomPreset',
|
|
376
|
+
description: 'myCustomPreset description',
|
|
377
|
+
editorConfig: {
|
|
378
|
+
licenseKey: 'GPL',
|
|
379
|
+
plugins: [
|
|
380
|
+
Bold,
|
|
381
|
+
Italic,
|
|
382
|
+
Essentials,
|
|
383
|
+
Heading,
|
|
384
|
+
Image,
|
|
385
|
+
ImageCaption,
|
|
386
|
+
ImageStyle,
|
|
387
|
+
ImageToolbar,
|
|
388
|
+
ImageUpload,
|
|
389
|
+
Link,
|
|
390
|
+
List,
|
|
391
|
+
Paragraph,
|
|
392
|
+
StrapiMediaLib,
|
|
393
|
+
StrapiUploadAdapter,
|
|
394
|
+
],
|
|
395
|
+
toolbar: [
|
|
396
|
+
'heading',
|
|
397
|
+
'|',
|
|
398
|
+
'bold',
|
|
399
|
+
'italic',
|
|
400
|
+
'link',
|
|
401
|
+
'bulletedList',
|
|
402
|
+
'numberedList',
|
|
403
|
+
'|',
|
|
404
|
+
'strapiMediaLib',
|
|
405
|
+
'|',
|
|
406
|
+
'undo',
|
|
407
|
+
'redo',
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
};
|
|
362
411
|
|
|
363
|
-
|
|
412
|
+
const myConfig = {
|
|
413
|
+
/**
|
|
414
|
+
* Note: Since the provided `presets` include only `myCustomPreset`
|
|
415
|
+
* this configuration will overwrite default presets.
|
|
416
|
+
*/
|
|
417
|
+
presets: [myCustomPreset],
|
|
418
|
+
};
|
|
364
419
|
|
|
365
|
-
|
|
366
|
-
|
|
420
|
+
export default {
|
|
421
|
+
register() {
|
|
422
|
+
setPluginConfig(myConfig);
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
```
|
|
367
426
|
|
|
368
|
-
|
|
427
|
+
</details>
|
|
369
428
|
|
|
370
|
-
|
|
429
|
+
<details>
|
|
430
|
+
<summary>Adding a new preset [TS]</summary>
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
// src/admin/app.tsx
|
|
434
|
+
|
|
435
|
+
import {
|
|
436
|
+
Bold,
|
|
437
|
+
Italic,
|
|
438
|
+
Essentials,
|
|
439
|
+
Heading,
|
|
440
|
+
Image,
|
|
441
|
+
ImageCaption,
|
|
442
|
+
ImageStyle,
|
|
443
|
+
ImageToolbar,
|
|
444
|
+
ImageUpload,
|
|
445
|
+
Link,
|
|
446
|
+
List,
|
|
447
|
+
Paragraph,
|
|
448
|
+
} from 'ckeditor5';
|
|
449
|
+
|
|
450
|
+
import {
|
|
451
|
+
type PluginConfig,
|
|
452
|
+
type Preset,
|
|
453
|
+
setPluginConfig,
|
|
454
|
+
StrapiMediaLib,
|
|
455
|
+
StrapiUploadAdapter,
|
|
456
|
+
} from '@_sh/strapi-plugin-ckeditor';
|
|
457
|
+
|
|
458
|
+
const myCustomPreset: Preset = {
|
|
459
|
+
name: 'myCustomPreset',
|
|
460
|
+
description: 'myCustomPreset description',
|
|
461
|
+
editorConfig: {
|
|
462
|
+
licenseKey: 'GPL',
|
|
463
|
+
plugins: [
|
|
464
|
+
Bold,
|
|
465
|
+
Italic,
|
|
466
|
+
Essentials,
|
|
467
|
+
Heading,
|
|
468
|
+
Image,
|
|
469
|
+
ImageCaption,
|
|
470
|
+
ImageStyle,
|
|
471
|
+
ImageToolbar,
|
|
472
|
+
ImageUpload,
|
|
473
|
+
Link,
|
|
474
|
+
List,
|
|
475
|
+
Paragraph,
|
|
476
|
+
StrapiMediaLib,
|
|
477
|
+
StrapiUploadAdapter,
|
|
478
|
+
],
|
|
479
|
+
toolbar: [
|
|
480
|
+
'heading',
|
|
481
|
+
'|',
|
|
482
|
+
'bold',
|
|
483
|
+
'italic',
|
|
484
|
+
'link',
|
|
485
|
+
'bulletedList',
|
|
486
|
+
'numberedList',
|
|
487
|
+
'|',
|
|
488
|
+
'strapiMediaLib',
|
|
489
|
+
'|',
|
|
490
|
+
'undo',
|
|
491
|
+
'redo',
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
};
|
|
371
495
|
|
|
372
|
-
const
|
|
496
|
+
const myConfig: PluginConfig = {
|
|
497
|
+
/**
|
|
498
|
+
* Note that since provided `presets` includes only `myCustomPreset`
|
|
499
|
+
* this configuration will overwrite default presets.
|
|
500
|
+
*/
|
|
501
|
+
presets: [myCustomPreset],
|
|
502
|
+
};
|
|
373
503
|
|
|
374
504
|
export default {
|
|
375
|
-
|
|
376
|
-
|
|
505
|
+
register() {
|
|
506
|
+
setPluginConfig(myConfig);
|
|
507
|
+
},
|
|
377
508
|
};
|
|
378
|
-
|
|
379
509
|
```
|
|
380
510
|
|
|
381
|
-
|
|
511
|
+
</details>
|
|
382
512
|
|
|
383
513
|
<details>
|
|
384
|
-
<summary
|
|
514
|
+
<summary>Default presets modification [TS]</summary>
|
|
515
|
+
|
|
516
|
+
```ts
|
|
517
|
+
// src/admin/app.tsx
|
|
518
|
+
|
|
519
|
+
import { css } from 'styled-components';
|
|
520
|
+
|
|
521
|
+
import {
|
|
522
|
+
type PluginConfig,
|
|
523
|
+
type Preset,
|
|
524
|
+
setPluginConfig,
|
|
525
|
+
defaultHtmlPreset,
|
|
526
|
+
defaultMarkdownPreset,
|
|
527
|
+
} from '@_sh/strapi-plugin-ckeditor';
|
|
528
|
+
|
|
529
|
+
const defaultHtml: Preset = {
|
|
530
|
+
...defaultHtmlPreset,
|
|
531
|
+
description: 'Modified default HTML editor',
|
|
532
|
+
styles: `
|
|
533
|
+
.ck {
|
|
534
|
+
color: red;
|
|
535
|
+
}
|
|
536
|
+
`,
|
|
537
|
+
editorConfig: {
|
|
538
|
+
...defaultHtmlPreset.editorConfig,
|
|
539
|
+
placeholder: 'Modified default HTML editor',
|
|
540
|
+
toolbar: [
|
|
541
|
+
'heading',
|
|
542
|
+
'|',
|
|
543
|
+
'bold',
|
|
544
|
+
'italic',
|
|
545
|
+
'link',
|
|
546
|
+
'bulletedList',
|
|
547
|
+
'numberedList',
|
|
548
|
+
'|',
|
|
549
|
+
'strapiMediaLib',
|
|
550
|
+
'insertTable',
|
|
551
|
+
'|',
|
|
552
|
+
'undo',
|
|
553
|
+
'redo',
|
|
554
|
+
],
|
|
555
|
+
},
|
|
556
|
+
};
|
|
385
557
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
globalThis.SH_CKE.ImageCaption,
|
|
412
|
-
globalThis.SH_CKE.ImageStyle,
|
|
413
|
-
globalThis.SH_CKE.ImageToolbar,
|
|
414
|
-
globalThis.SH_CKE.ImageUpload,
|
|
415
|
-
globalThis.SH_CKE.Indent,
|
|
416
|
-
globalThis.SH_CKE.Link,
|
|
417
|
-
globalThis.SH_CKE.List,
|
|
418
|
-
globalThis.SH_CKE.Paragraph,
|
|
419
|
-
globalThis.SH_CKE.PasteFromOffice,
|
|
420
|
-
globalThis.SH_CKE.Table,
|
|
421
|
-
globalThis.SH_CKE.TableToolbar,
|
|
422
|
-
globalThis.SH_CKE.TableColumnResize,
|
|
423
|
-
globalThis.SH_CKE.TableCaption,
|
|
424
|
-
globalThis.SH_CKE.StrapiMediaLib,
|
|
425
|
-
globalThis.SH_CKE.StrapiUploadAdapter,
|
|
426
|
-
],
|
|
427
|
-
toolbar: [
|
|
428
|
-
'timestamp',
|
|
429
|
-
'heading',
|
|
430
|
-
'|',
|
|
431
|
-
'bold', 'italic', 'link', 'bulletedList', 'numberedList',
|
|
432
|
-
'|',
|
|
433
|
-
'strapiMediaLib', 'insertTable',
|
|
434
|
-
'|',
|
|
435
|
-
'undo', 'redo'
|
|
436
|
-
],
|
|
437
|
-
|
|
438
|
-
// ...
|
|
439
|
-
}
|
|
440
|
-
},
|
|
441
|
-
}
|
|
442
|
-
})
|
|
558
|
+
const defaultMarkdown: Preset = {
|
|
559
|
+
...defaultMarkdownPreset,
|
|
560
|
+
description: 'Modified default Markdown editor',
|
|
561
|
+
styles: `
|
|
562
|
+
.ck {
|
|
563
|
+
--ck-editor-max-width: 1500px;
|
|
564
|
+
--ck-editor-min-height: 700px;
|
|
565
|
+
--ck-editor-max-height: 700px;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.ck.ck-editor__main {
|
|
569
|
+
border: 3px dashed ${({ theme }) => theme.colors.warning500};
|
|
570
|
+
}
|
|
571
|
+
`,
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
const myConfig: PluginConfig = {
|
|
575
|
+
presets: [defaultHtml, defaultMarkdown],
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
export default {
|
|
579
|
+
register() {
|
|
580
|
+
setPluginConfig(myConfig);
|
|
581
|
+
},
|
|
582
|
+
};
|
|
443
583
|
```
|
|
444
584
|
|
|
445
|
-
</details>
|
|
585
|
+
</details>
|
|
446
586
|
|
|
587
|
+
<details>
|
|
588
|
+
<summary>Modifying theme [TS]</summary>
|
|
589
|
+
|
|
590
|
+
```ts
|
|
591
|
+
// src/admin/app.tsx
|
|
592
|
+
|
|
593
|
+
import { css } from 'styled-components';
|
|
594
|
+
|
|
595
|
+
import { type PluginConfig, setPluginConfig, defaultTheme } from '@_sh/strapi-plugin-ckeditor';
|
|
596
|
+
|
|
597
|
+
const myConfig: PluginConfig = {
|
|
598
|
+
theme: {
|
|
599
|
+
...defaultTheme,
|
|
600
|
+
additional: css`
|
|
601
|
+
.ck {
|
|
602
|
+
--ck-editor-max-width: 1500px;
|
|
603
|
+
--ck-editor-min-height: 700px;
|
|
604
|
+
--ck-editor-max-height: 700px;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
.ck.ck-editor__main {
|
|
608
|
+
border: 3px dashed ${({ theme }) => theme.colors.warning500};
|
|
609
|
+
}
|
|
610
|
+
`,
|
|
611
|
+
},
|
|
612
|
+
};
|
|
447
613
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
614
|
+
export default {
|
|
615
|
+
register() {
|
|
616
|
+
setPluginConfig(myConfig);
|
|
617
|
+
},
|
|
618
|
+
};
|
|
451
619
|
```
|
|
452
620
|
|
|
453
|
-
|
|
621
|
+
</details>
|
|
454
622
|
|
|
455
623
|
<details>
|
|
456
|
-
<summary
|
|
624
|
+
<summary>Adding Timestamp plugin [JS]</summary>
|
|
457
625
|
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
class Timestamp extends globalThis.SH_CKE.Plugin {
|
|
461
|
-
init() {
|
|
462
|
-
const editor = this.editor;
|
|
463
|
-
// The button must be registered among the UI components of the editor
|
|
464
|
-
// to be displayed in the toolbar.
|
|
465
|
-
editor.ui.componentFactory.add("timestamp", () => {
|
|
466
|
-
// The button will be an instance of ButtonView.
|
|
467
|
-
const button = new globalThis.SH_CKE.ButtonView();
|
|
468
|
-
|
|
469
|
-
button.set({
|
|
470
|
-
label: "Timestamp",
|
|
471
|
-
withText: true,
|
|
472
|
-
});
|
|
626
|
+
```ts
|
|
627
|
+
// src/admin/app.js
|
|
473
628
|
|
|
474
|
-
|
|
475
|
-
button.on("execute", () => {
|
|
476
|
-
const now = new Date();
|
|
629
|
+
import { Plugin, ButtonView } from 'ckeditor5';
|
|
477
630
|
|
|
478
|
-
|
|
479
|
-
editor.model.change((writer) => {
|
|
480
|
-
// Insert the text at the user's current position.
|
|
481
|
-
editor.model.insertContent(writer.createText(now.toString()));
|
|
482
|
-
});
|
|
483
|
-
});
|
|
631
|
+
import { setPluginConfig, defaultHtmlPreset } from '@_sh/strapi-plugin-ckeditor';
|
|
484
632
|
|
|
485
|
-
|
|
633
|
+
class Timestamp extends Plugin {
|
|
634
|
+
init() {
|
|
635
|
+
const editor = this.editor;
|
|
636
|
+
editor.ui.componentFactory.add('timestamp', () => {
|
|
637
|
+
const button = new ButtonView();
|
|
638
|
+
button.set({
|
|
639
|
+
label: 'timestamp',
|
|
640
|
+
withText: true,
|
|
486
641
|
});
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
value: "myCustomPreset",
|
|
496
|
-
metadatas: {
|
|
497
|
-
intlLabel: {
|
|
498
|
-
id: "ckeditor5.preset.myCustomPreset.label",
|
|
499
|
-
defaultMessage: "My custom preset",
|
|
500
|
-
},
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
editorConfig:{
|
|
504
|
-
plugins: [
|
|
505
|
-
Timestamp,
|
|
506
|
-
globalThis.SH_CKE.Autoformat,
|
|
507
|
-
globalThis.SH_CKE.Bold,
|
|
508
|
-
globalThis.SH_CKE.Italic,
|
|
509
|
-
globalThis.SH_CKE.Essentials,
|
|
510
|
-
globalThis.SH_CKE.Heading,
|
|
511
|
-
globalThis.SH_CKE.Image,
|
|
512
|
-
globalThis.SH_CKE.ImageCaption,
|
|
513
|
-
globalThis.SH_CKE.ImageStyle,
|
|
514
|
-
globalThis.SH_CKE.ImageToolbar,
|
|
515
|
-
globalThis.SH_CKE.ImageUpload,
|
|
516
|
-
globalThis.SH_CKE.Indent,
|
|
517
|
-
globalThis.SH_CKE.Link,
|
|
518
|
-
globalThis.SH_CKE.List,
|
|
519
|
-
globalThis.SH_CKE.Paragraph,
|
|
520
|
-
globalThis.SH_CKE.PasteFromOffice,
|
|
521
|
-
globalThis.SH_CKE.Table,
|
|
522
|
-
globalThis.SH_CKE.TableToolbar,
|
|
523
|
-
globalThis.SH_CKE.TableColumnResize,
|
|
524
|
-
globalThis.SH_CKE.TableCaption,
|
|
525
|
-
globalThis.SH_CKE.StrapiMediaLib,
|
|
526
|
-
globalThis.SH_CKE.StrapiUploadAdapter,
|
|
527
|
-
],
|
|
528
|
-
toolbar: [
|
|
529
|
-
'timestamp',
|
|
530
|
-
'heading',
|
|
531
|
-
'|',
|
|
532
|
-
'bold', 'italic', 'link', 'bulletedList', 'numberedList',
|
|
533
|
-
'|',
|
|
534
|
-
'strapiMediaLib', 'insertTable',
|
|
535
|
-
'|',
|
|
536
|
-
'undo', 'redo'
|
|
537
|
-
],
|
|
538
|
-
|
|
539
|
-
...
|
|
540
|
-
}
|
|
541
|
-
},
|
|
642
|
+
button.on('execute', () => {
|
|
643
|
+
const now = new Date();
|
|
644
|
+
editor.model.change(writer => {
|
|
645
|
+
editor.model.insertContent(writer.createText(now.toString()));
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
return button;
|
|
649
|
+
});
|
|
542
650
|
}
|
|
543
651
|
}
|
|
652
|
+
|
|
653
|
+
export default {
|
|
654
|
+
register() {
|
|
655
|
+
defaultHtmlPreset.editorConfig.plugins.push(Timestamp);
|
|
656
|
+
defaultHtmlPreset.editorConfig.toolbar.unshift('timestamp');
|
|
657
|
+
setPluginConfig({ presets: [defaultHtmlPreset] });
|
|
658
|
+
},
|
|
659
|
+
};
|
|
544
660
|
```
|
|
545
661
|
|
|
546
|
-
</details>
|
|
662
|
+
</details>
|
|
547
663
|
|
|
664
|
+
<br />
|
|
548
665
|
|
|
666
|
+
📂 Default HTML preset: [**admin/src/config/htmlPreset.ts**](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/master/admin/src/config/htmlPreset.ts)
|
|
549
667
|
|
|
550
|
-
|
|
668
|
+
📂 Default Markdown preset: [**admin/src/config/markdownPreset.ts**](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/master/admin/src/config/markdownPreset.ts)
|
|
551
669
|
|
|
670
|
+
📂 Default theme: [**admin/src/theme**](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/master/admin/src/theme)
|
|
552
671
|
|
|
553
|
-
|
|
672
|
+
> 📌 It is highly recommended to explore [**the official CKEditor5 documentation**](https://ckeditor.com/docs/ckeditor5/latest/getting-started/setup/configuration.html).
|
|
554
673
|
|
|
555
|
-
|
|
674
|
+
> 💡 To display content from external sources, such as images or videos, in your admin panel,
|
|
675
|
+
> you need to configure your `middlewares.js` file.
|
|
676
|
+
> [**Check the documentation for details.**](https://docs.strapi.io/dev-docs/configurations/middlewares#security)
|
|
556
677
|
|
|
557
|
-
|
|
678
|
+
## <a id="contributing"></a>🛠 Contributing
|
|
558
679
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
```
|
|
562
|
-
Navigate to the downloaded folder:
|
|
680
|
+
Feel free to [fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
|
|
681
|
+
and open a pull request, any help is appreciated.
|
|
563
682
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
683
|
+
Follow these steps to set up a plugin development environment:
|
|
684
|
+
|
|
685
|
+
1. Clone the repository.
|
|
686
|
+
|
|
687
|
+
2. Read [the Strapi Plugin SDK documentation](https://docs.strapi.io/dev-docs/plugins/development/create-a-plugin#linking-the-plugin-to-your-project).
|
|
567
688
|
|
|
568
|
-
|
|
689
|
+
3. Navigate to the cloned plugin folder and install dependencies, run:
|
|
569
690
|
|
|
570
691
|
```bash
|
|
571
692
|
yarn install
|
|
572
693
|
```
|
|
573
694
|
|
|
574
|
-
Link the plugin to your project:
|
|
695
|
+
4. Link the plugin to your project:
|
|
575
696
|
|
|
576
|
-
In the plugin
|
|
577
|
-
```bash
|
|
578
|
-
yarn watch:link
|
|
579
|
-
```
|
|
697
|
+
- In the plugin folder, run:
|
|
580
698
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
699
|
+
```bash
|
|
700
|
+
yarn watch:link
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
- Open a new terminal, navigate to your Strapi project directory, and run:
|
|
585
704
|
|
|
586
|
-
|
|
705
|
+
```bash
|
|
706
|
+
yarn dlx yalc add --link @_sh/strapi-plugin-ckeditor && yarn install
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
5. Rebuild the project and start the server:
|
|
587
710
|
|
|
588
711
|
```bash
|
|
589
712
|
yarn build
|
|
590
713
|
yarn develop
|
|
591
714
|
```
|
|
592
715
|
|
|
593
|
-
|
|
594
716
|
## <a id="migration"></a>✈️ Migration
|
|
595
717
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
- The new version introduces support for Strapi v5 and is incompatible with Strapi v4. You will need to update your Strapi project to version 5 before upgrading.
|
|
599
|
-
|
|
600
|
-
- The plugin development process has changed. Please refer to the updated contribution guide for more information.
|
|
601
|
-
|
|
602
|
-
### From v2 to v3
|
|
603
|
-
|
|
604
|
-
- The default editor configurations (toolbar, toolbarBalloon, blockBalloon) have been removed and now there is only one preset by default. You will need to update your fields in the Content-Type Builder.
|
|
605
|
-
|
|
606
|
-
- Config file extension has changed from `.txt` to `.js` or `.ts`
|
|
607
|
-
- Configuration object properties have been renamed:
|
|
608
|
-
- `configsOverwrite` -> `dontMergePresets`
|
|
609
|
-
- `themeOverwrite` -> `dontMergeTheme`
|
|
610
|
-
- `configs` -> `presets`
|
|
611
|
-
- From v3 instead of globalThis.CKEditorConfig = {..}, the config file must define a function called CKEConfig that returns the configuration object.
|
|
612
|
-
|
|
613
|
-
Example of the new configuration file:
|
|
614
|
-
|
|
615
|
-
<details>
|
|
616
|
-
<summary><b>ckeditor.js</b></summary>
|
|
617
|
-
|
|
618
|
-
```js
|
|
619
|
-
const CKEConfig = () => ({
|
|
620
|
-
presets:{
|
|
621
|
-
myCustomPreset:{
|
|
622
|
-
field: {
|
|
623
|
-
key: "myCustomPreset",
|
|
624
|
-
value: "myCustomPreset",
|
|
625
|
-
metadatas: {
|
|
626
|
-
intlLabel: {
|
|
627
|
-
id: "ckeditor5.preset.myCustomPreset.label",
|
|
628
|
-
defaultMessage: "My custom preset",
|
|
629
|
-
},
|
|
630
|
-
},
|
|
631
|
-
},
|
|
632
|
-
editorConfig:{
|
|
633
|
-
plugins: [
|
|
634
|
-
globalThis.SH_CKE.Autoformat,
|
|
635
|
-
globalThis.SH_CKE.Bold,
|
|
636
|
-
globalThis.SH_CKE.Italic,
|
|
637
|
-
globalThis.SH_CKE.Essentials,
|
|
638
|
-
globalThis.SH_CKE.Heading,
|
|
639
|
-
globalThis.SH_CKE.Image,
|
|
640
|
-
globalThis.SH_CKE.ImageCaption,
|
|
641
|
-
globalThis.SH_CKE.ImageStyle,
|
|
642
|
-
globalThis.SH_CKE.ImageToolbar,
|
|
643
|
-
globalThis.SH_CKE.ImageUpload,
|
|
644
|
-
globalThis.SH_CKE.Indent,
|
|
645
|
-
globalThis.SH_CKE.Link,
|
|
646
|
-
globalThis.SH_CKE.List,
|
|
647
|
-
globalThis.SH_CKE.Paragraph,
|
|
648
|
-
globalThis.SH_CKE.PasteFromOffice,
|
|
649
|
-
globalThis.SH_CKE.Table,
|
|
650
|
-
globalThis.SH_CKE.TableToolbar,
|
|
651
|
-
globalThis.SH_CKE.TableColumnResize,
|
|
652
|
-
globalThis.SH_CKE.TableCaption,
|
|
653
|
-
globalThis.SH_CKE.StrapiMediaLib,
|
|
654
|
-
globalThis.SH_CKE.StrapiUploadAdapter,
|
|
655
|
-
],
|
|
656
|
-
toolbar: [
|
|
657
|
-
'heading',
|
|
658
|
-
'|',
|
|
659
|
-
'bold', 'italic', 'link', 'bulletedList', 'numberedList',
|
|
660
|
-
'|',
|
|
661
|
-
'strapiMediaLib', 'insertTable',
|
|
662
|
-
'|',
|
|
663
|
-
'undo', 'redo'
|
|
664
|
-
],
|
|
665
|
-
heading: {
|
|
666
|
-
options: [
|
|
667
|
-
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
668
|
-
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
669
|
-
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
670
|
-
{ model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
|
|
671
|
-
{ model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
|
|
672
|
-
]
|
|
673
|
-
},
|
|
674
|
-
image: {
|
|
675
|
-
toolbar: [
|
|
676
|
-
'imageStyle:inline',
|
|
677
|
-
'imageStyle:block',
|
|
678
|
-
'imageStyle:side',
|
|
679
|
-
'|',
|
|
680
|
-
'toggleImageCaption',
|
|
681
|
-
'imageTextAlternative'
|
|
682
|
-
]
|
|
683
|
-
},
|
|
684
|
-
table: {
|
|
685
|
-
contentToolbar: [
|
|
686
|
-
'tableColumn',
|
|
687
|
-
'tableRow',
|
|
688
|
-
'mergeTableCells',
|
|
689
|
-
'|',
|
|
690
|
-
'toggleTableCaption'
|
|
691
|
-
]
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
})
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
</details>
|
|
700
|
-
|
|
701
|
-
### From v1 to v2
|
|
702
|
-
|
|
703
|
-
- You will need to update Strapi to version v4.4.x for plugin v2.0.x, or to v4.13.0+ for v2.1.x.
|
|
704
|
-
|
|
705
|
-
- Starting with v2, the plugin uses the Custom Field API, so you'll need to manually update your schema.
|
|
706
|
-
|
|
707
|
-
- The plugin configuration should be defined in /config/ckeditor.txt from v2 onward. [Please refer to the v2 configuration guide for details.](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/e782475f54b8a50a04f55275c89ef5bf61a15745/README.md?plain=1#L54)
|
|
718
|
+
To upgrade to the latest version, follow the dedicated [migration guide](https://github.com/nshenderov/strapi-plugin-ckeditor/blob/master/MIGRATION.md)
|
|
719
|
+
for detailed instructions.
|
|
708
720
|
|
|
709
721
|
## <a id="requirements"></a>⚠️ Requirements
|
|
710
722
|
|
|
711
|
-
|
|
712
|
-
**v4.x.x**
|
|
723
|
+
**v5.x.x**
|
|
713
724
|
|
|
714
725
|
Strapi **>= 5.0.0**
|
|
715
726
|
|
|
716
|
-
Node **>= 18.0.0 <=
|
|
727
|
+
Node **>= 18.0.0 <= 22.x.x**
|
|
717
728
|
|
|
718
|
-
|
|
729
|
+
---
|
|
719
730
|
|
|
720
731
|
**v3.x.x**
|
|
721
732
|
|
|
722
733
|
Strapi **>= 4.13.0 < 5.0.0**
|
|
723
734
|
|
|
724
|
-
Node **>= 18.0.0 <= 20.x.x**
|
|
735
|
+
Node **>= 18.0.0 <= 20.x.x**
|