@_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
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, useState, useEffect, useMemo, useContext, useRef, useCallback } from "react";
|
|
3
|
+
import { Flex, IconButton, Box, Portal, FocusTrap, Field as Field$1, Loader } from "@strapi/design-system";
|
|
4
|
+
import { styled, css, createGlobalStyle } from "styled-components";
|
|
5
|
+
import { useStrapiApp, useField } from "@strapi/strapi/admin";
|
|
6
|
+
import { ClassicEditor } from "ckeditor5";
|
|
7
|
+
import { CKEditor } from "@ckeditor/ckeditor5-react";
|
|
8
|
+
import "ckeditor5/ckeditor5.css";
|
|
9
|
+
import { g as getPluginConfig, p as prefixFileUrlWithBackendUrl, i as isImageResponsive } from "./index-CNalXcwy.mjs";
|
|
10
|
+
import { Collapse, Expand } from "@strapi/icons";
|
|
11
|
+
const STORAGE_KEYS = {
|
|
12
|
+
TOKEN: "jwtToken",
|
|
13
|
+
PREFERED_LANGUAGE: "strapi-admin-language",
|
|
14
|
+
PROFILE_THEME: "STRAPI_THEME"
|
|
15
|
+
};
|
|
16
|
+
function getStoredToken() {
|
|
17
|
+
const token = localStorage.getItem(STORAGE_KEYS.TOKEN) ?? sessionStorage.getItem(STORAGE_KEYS.TOKEN);
|
|
18
|
+
if (typeof token === "string") {
|
|
19
|
+
return JSON.parse(token);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function getPreferedLanguage() {
|
|
24
|
+
const language = localStorage.getItem(STORAGE_KEYS.PREFERED_LANGUAGE)?.replace(/^"|"$/g, "") || "en";
|
|
25
|
+
return language;
|
|
26
|
+
}
|
|
27
|
+
function getProfileTheme() {
|
|
28
|
+
const theme = localStorage.getItem(STORAGE_KEYS.PROFILE_THEME);
|
|
29
|
+
return theme;
|
|
30
|
+
}
|
|
31
|
+
const TRANSLATIONS = {};
|
|
32
|
+
async function setUpLanguage(config, isFieldLocalized) {
|
|
33
|
+
if (typeof config.language !== "object") {
|
|
34
|
+
config.language = {
|
|
35
|
+
ui: config.language,
|
|
36
|
+
content: config.language,
|
|
37
|
+
textPartLanguage: void 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
config.language.ui ||= getPreferedLanguage();
|
|
41
|
+
if (isFieldLocalized) {
|
|
42
|
+
config.language.content = detecti18n();
|
|
43
|
+
}
|
|
44
|
+
if (config.language.ui !== "en") {
|
|
45
|
+
await importLang(config, config.language.ui);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function importLang(config, language) {
|
|
49
|
+
if (TRANSLATIONS[language]) {
|
|
50
|
+
config.translations = TRANSLATIONS[language];
|
|
51
|
+
} else if (translationImports[language]) {
|
|
52
|
+
const translation = await translationImports[language]();
|
|
53
|
+
TRANSLATIONS[language] = translation.default;
|
|
54
|
+
config.translations = translation.default;
|
|
55
|
+
} else {
|
|
56
|
+
console.warn(`CKEditor: no translation found for language: ${language}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function detecti18n() {
|
|
60
|
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
61
|
+
const params = Object.fromEntries(urlSearchParams.entries());
|
|
62
|
+
const i18n = params["plugins[i18n][locale]"];
|
|
63
|
+
return i18n && i18n.split("-")[0];
|
|
64
|
+
}
|
|
65
|
+
const translationImports = {
|
|
66
|
+
af: () => import("ckeditor5/translations/af.js"),
|
|
67
|
+
ar: () => import("ckeditor5/translations/ar.js"),
|
|
68
|
+
ast: () => import("ckeditor5/translations/ast.js"),
|
|
69
|
+
az: () => import("ckeditor5/translations/az.js"),
|
|
70
|
+
bg: () => import("ckeditor5/translations/bg.js"),
|
|
71
|
+
bn: () => import("ckeditor5/translations/bn.js"),
|
|
72
|
+
bs: () => import("ckeditor5/translations/bs.js"),
|
|
73
|
+
ca: () => import("ckeditor5/translations/ca.js"),
|
|
74
|
+
cs: () => import("ckeditor5/translations/cs.js"),
|
|
75
|
+
da: () => import("ckeditor5/translations/da.js"),
|
|
76
|
+
"de-ch": () => import("ckeditor5/translations/de-ch.js"),
|
|
77
|
+
de: () => import("ckeditor5/translations/de.js"),
|
|
78
|
+
el: () => import("ckeditor5/translations/el.js"),
|
|
79
|
+
"en-au": () => import("ckeditor5/translations/en-au.js"),
|
|
80
|
+
"en-gb": () => import("ckeditor5/translations/en-gb.js"),
|
|
81
|
+
en: () => import("ckeditor5/translations/en.js"),
|
|
82
|
+
eo: () => import("ckeditor5/translations/eo.js"),
|
|
83
|
+
"es-co": () => import("ckeditor5/translations/es-co.js"),
|
|
84
|
+
es: () => import("ckeditor5/translations/es.js"),
|
|
85
|
+
et: () => import("ckeditor5/translations/et.js"),
|
|
86
|
+
eu: () => import("ckeditor5/translations/eu.js"),
|
|
87
|
+
fa: () => import("ckeditor5/translations/fa.js"),
|
|
88
|
+
fi: () => import("ckeditor5/translations/fi.js"),
|
|
89
|
+
fr: () => import("ckeditor5/translations/fr.js"),
|
|
90
|
+
gl: () => import("ckeditor5/translations/gl.js"),
|
|
91
|
+
gu: () => import("ckeditor5/translations/gu.js"),
|
|
92
|
+
he: () => import("ckeditor5/translations/he.js"),
|
|
93
|
+
hi: () => import("ckeditor5/translations/hi.js"),
|
|
94
|
+
hr: () => import("ckeditor5/translations/hr.js"),
|
|
95
|
+
hu: () => import("ckeditor5/translations/hu.js"),
|
|
96
|
+
hy: () => import("ckeditor5/translations/hy.js"),
|
|
97
|
+
id: () => import("ckeditor5/translations/id.js"),
|
|
98
|
+
it: () => import("ckeditor5/translations/it.js"),
|
|
99
|
+
ja: () => import("ckeditor5/translations/ja.js"),
|
|
100
|
+
jv: () => import("ckeditor5/translations/jv.js"),
|
|
101
|
+
kk: () => import("ckeditor5/translations/kk.js"),
|
|
102
|
+
km: () => import("ckeditor5/translations/km.js"),
|
|
103
|
+
kn: () => import("ckeditor5/translations/kn.js"),
|
|
104
|
+
ko: () => import("ckeditor5/translations/ko.js"),
|
|
105
|
+
ku: () => import("ckeditor5/translations/ku.js"),
|
|
106
|
+
lt: () => import("ckeditor5/translations/lt.js"),
|
|
107
|
+
lv: () => import("ckeditor5/translations/lv.js"),
|
|
108
|
+
ms: () => import("ckeditor5/translations/ms.js"),
|
|
109
|
+
nb: () => import("ckeditor5/translations/nb.js"),
|
|
110
|
+
ne: () => import("ckeditor5/translations/ne.js"),
|
|
111
|
+
nl: () => import("ckeditor5/translations/nl.js"),
|
|
112
|
+
no: () => import("ckeditor5/translations/no.js"),
|
|
113
|
+
oc: () => import("ckeditor5/translations/oc.js"),
|
|
114
|
+
pl: () => import("ckeditor5/translations/pl.js"),
|
|
115
|
+
"pt-br": () => import("ckeditor5/translations/pt-br.js"),
|
|
116
|
+
pt: () => import("ckeditor5/translations/pt.js"),
|
|
117
|
+
ro: () => import("ckeditor5/translations/ro.js"),
|
|
118
|
+
ru: () => import("ckeditor5/translations/ru.js"),
|
|
119
|
+
si: () => import("ckeditor5/translations/si.js"),
|
|
120
|
+
sk: () => import("ckeditor5/translations/sk.js"),
|
|
121
|
+
sl: () => import("ckeditor5/translations/sl.js"),
|
|
122
|
+
sq: () => import("ckeditor5/translations/sq.js"),
|
|
123
|
+
sr: () => import("ckeditor5/translations/sr.js"),
|
|
124
|
+
"sr-latn": () => import("ckeditor5/translations/sr-latn.js"),
|
|
125
|
+
sv: () => import("ckeditor5/translations/sv.js"),
|
|
126
|
+
th: () => import("ckeditor5/translations/th.js"),
|
|
127
|
+
ti: () => import("ckeditor5/translations/ti.js"),
|
|
128
|
+
tk: () => import("ckeditor5/translations/tk.js"),
|
|
129
|
+
tr: () => import("ckeditor5/translations/tr.js"),
|
|
130
|
+
tt: () => import("ckeditor5/translations/tt.js"),
|
|
131
|
+
ug: () => import("ckeditor5/translations/ug.js"),
|
|
132
|
+
uk: () => import("ckeditor5/translations/uk.js"),
|
|
133
|
+
ur: () => import("ckeditor5/translations/ur.js"),
|
|
134
|
+
uz: () => import("ckeditor5/translations/uz.js"),
|
|
135
|
+
vi: () => import("ckeditor5/translations/vi.js"),
|
|
136
|
+
"zh-cn": () => import("ckeditor5/translations/zh-cn.js"),
|
|
137
|
+
zh: () => import("ckeditor5/translations/zh.js")
|
|
138
|
+
};
|
|
139
|
+
const EditorContext = createContext(null);
|
|
140
|
+
function useEditorContext() {
|
|
141
|
+
const context = useContext(EditorContext);
|
|
142
|
+
if (!context) throw Error("useEditorAttributes can only be used inside EditorProvider");
|
|
143
|
+
return context;
|
|
144
|
+
}
|
|
145
|
+
function EditorProvider({
|
|
146
|
+
name,
|
|
147
|
+
disabled,
|
|
148
|
+
error,
|
|
149
|
+
placeholder,
|
|
150
|
+
hint,
|
|
151
|
+
label,
|
|
152
|
+
labelAction,
|
|
153
|
+
required,
|
|
154
|
+
presetName,
|
|
155
|
+
wordsLimit,
|
|
156
|
+
charsLimit,
|
|
157
|
+
children,
|
|
158
|
+
isFieldLocalized
|
|
159
|
+
}) {
|
|
160
|
+
const [preset, setPreset] = useState(null);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
(async () => {
|
|
163
|
+
const { presets } = getPluginConfig();
|
|
164
|
+
const currentPreset = clonePreset(presets[presetName]);
|
|
165
|
+
await setUpLanguage(currentPreset.editorConfig, isFieldLocalized);
|
|
166
|
+
if (placeholder) {
|
|
167
|
+
currentPreset.editorConfig.placeholder = placeholder;
|
|
168
|
+
}
|
|
169
|
+
setPreset(currentPreset);
|
|
170
|
+
})();
|
|
171
|
+
}, [presetName, placeholder, isFieldLocalized]);
|
|
172
|
+
const EditorContextValue = useMemo(
|
|
173
|
+
() => ({
|
|
174
|
+
name,
|
|
175
|
+
disabled,
|
|
176
|
+
placeholder,
|
|
177
|
+
hint,
|
|
178
|
+
label,
|
|
179
|
+
labelAction,
|
|
180
|
+
required,
|
|
181
|
+
presetName,
|
|
182
|
+
preset,
|
|
183
|
+
error,
|
|
184
|
+
wordsLimit,
|
|
185
|
+
charsLimit,
|
|
186
|
+
isFieldLocalized
|
|
187
|
+
}),
|
|
188
|
+
[
|
|
189
|
+
name,
|
|
190
|
+
disabled,
|
|
191
|
+
placeholder,
|
|
192
|
+
hint,
|
|
193
|
+
label,
|
|
194
|
+
labelAction,
|
|
195
|
+
required,
|
|
196
|
+
presetName,
|
|
197
|
+
wordsLimit,
|
|
198
|
+
charsLimit,
|
|
199
|
+
preset,
|
|
200
|
+
error,
|
|
201
|
+
isFieldLocalized
|
|
202
|
+
]
|
|
203
|
+
);
|
|
204
|
+
return /* @__PURE__ */ jsx(EditorContext.Provider, { value: EditorContextValue, children });
|
|
205
|
+
}
|
|
206
|
+
function clonePreset(preset) {
|
|
207
|
+
const clonedPreset = {
|
|
208
|
+
...preset,
|
|
209
|
+
editorConfig: {
|
|
210
|
+
...preset.editorConfig
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
Object.entries(clonedPreset.editorConfig).forEach(([key, val]) => {
|
|
214
|
+
if (val && typeof val === "object" && Object.getPrototypeOf(val) === Object.prototype) {
|
|
215
|
+
clonedPreset.editorConfig[key] = { ...val };
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return clonedPreset;
|
|
219
|
+
}
|
|
220
|
+
function MediaLib({ isOpen = false, toggle, handleChangeAssets }) {
|
|
221
|
+
const components = useStrapiApp("MediaLib", (state) => state.components);
|
|
222
|
+
const MediaLibraryDialog = components["media-library"];
|
|
223
|
+
function handleSelectAssets(files) {
|
|
224
|
+
const formattedFiles = files.map((f) => ({
|
|
225
|
+
name: f.name,
|
|
226
|
+
alt: f.alternativeText || f.name,
|
|
227
|
+
url: prefixFileUrlWithBackendUrl(f.url),
|
|
228
|
+
mime: f.mime,
|
|
229
|
+
formats: f.formats,
|
|
230
|
+
width: f.width,
|
|
231
|
+
height: f.height
|
|
232
|
+
}));
|
|
233
|
+
const newElems = getNewElems(formattedFiles);
|
|
234
|
+
handleChangeAssets(newElems);
|
|
235
|
+
}
|
|
236
|
+
function getNewElems(assets) {
|
|
237
|
+
let newElems = "";
|
|
238
|
+
assets.forEach(({ name, url, alt, formats, mime, width, height }) => {
|
|
239
|
+
if (mime.includes("image")) {
|
|
240
|
+
if (formats && isImageResponsive(formats)) {
|
|
241
|
+
const set = formSrcSet(formats);
|
|
242
|
+
newElems += `<img src="${url}" alt="${alt}" width="${width}" height="${height}" srcset="${set}" />`;
|
|
243
|
+
} else {
|
|
244
|
+
newElems += `<img src="${url}" alt="${alt}" width="${width}" height="${height}" />`;
|
|
245
|
+
}
|
|
246
|
+
} else if (mime.includes("video")) {
|
|
247
|
+
newElems += `
|
|
248
|
+
<video class="video" controls width="500px">
|
|
249
|
+
<source src="${url}" type="${mime}" />
|
|
250
|
+
</video>`;
|
|
251
|
+
} else {
|
|
252
|
+
newElems += `<a href="${url}">${name || "Open document"}</a>`;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return newElems;
|
|
256
|
+
}
|
|
257
|
+
function formSrcSet(formats) {
|
|
258
|
+
let set = "";
|
|
259
|
+
const keys = Object.keys(formats).sort((a, b) => formats[a].width - formats[b].width);
|
|
260
|
+
keys.forEach((k) => {
|
|
261
|
+
set += `${prefixFileUrlWithBackendUrl(formats[k].url)} ${formats[k].width}w,`;
|
|
262
|
+
});
|
|
263
|
+
return set;
|
|
264
|
+
}
|
|
265
|
+
if (!isOpen) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsx(MediaLibraryDialog, { onClose: toggle, onSelectAssets: handleSelectAssets });
|
|
269
|
+
}
|
|
270
|
+
const MemoizedMediaLib = React.memo(MediaLib);
|
|
271
|
+
function CKEReact() {
|
|
272
|
+
const [mediaLibVisible, setMediaLibVisible] = useState(false);
|
|
273
|
+
const [editorInstance, setEditorInstance] = useState(null);
|
|
274
|
+
const [isWordsMax, setIsWordsMax] = useState(false);
|
|
275
|
+
const [isCharsMax, setIsCharsMax] = useState(false);
|
|
276
|
+
const { name, disabled, preset, wordsLimit, charsLimit } = useEditorContext();
|
|
277
|
+
const { onChange: fieldOnChange, value: fieldValue } = useField(name);
|
|
278
|
+
const wordCounterRef = useRef(null);
|
|
279
|
+
const onEditorReady = (editor) => {
|
|
280
|
+
setUpPlugins(editor);
|
|
281
|
+
setEditorInstance(editor);
|
|
282
|
+
};
|
|
283
|
+
const onEditorChange = (_e, editor) => {
|
|
284
|
+
const data = editor.getData();
|
|
285
|
+
fieldOnChange(name, data);
|
|
286
|
+
};
|
|
287
|
+
const toggleMediaLib = useCallback(() => setMediaLibVisible((prev) => !prev), [setMediaLibVisible]);
|
|
288
|
+
const handleChangeAssets = useCallback(
|
|
289
|
+
(newElems) => {
|
|
290
|
+
if (!editorInstance) {
|
|
291
|
+
throw new Error("CKEditor: Editor instance is not initialized");
|
|
292
|
+
}
|
|
293
|
+
const viewFragment = editorInstance.data.processor.toView(newElems);
|
|
294
|
+
const modelFragment = editorInstance.data.toModel(viewFragment);
|
|
295
|
+
editorInstance?.model.insertContent(modelFragment);
|
|
296
|
+
toggleMediaLib();
|
|
297
|
+
},
|
|
298
|
+
[toggleMediaLib, editorInstance]
|
|
299
|
+
);
|
|
300
|
+
if (!preset) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
304
|
+
/* @__PURE__ */ jsx(
|
|
305
|
+
CKEditor,
|
|
306
|
+
{
|
|
307
|
+
editor: ClassicEditor,
|
|
308
|
+
config: preset.editorConfig,
|
|
309
|
+
disabled,
|
|
310
|
+
data: fieldValue ?? "",
|
|
311
|
+
onReady: onEditorReady,
|
|
312
|
+
onChange: onEditorChange
|
|
313
|
+
}
|
|
314
|
+
),
|
|
315
|
+
/* @__PURE__ */ jsx(WordCounter, { ref: wordCounterRef, $isWordsMax: isWordsMax, $isCharsMax: isCharsMax }),
|
|
316
|
+
/* @__PURE__ */ jsx(
|
|
317
|
+
MemoizedMediaLib,
|
|
318
|
+
{
|
|
319
|
+
isOpen: mediaLibVisible,
|
|
320
|
+
toggle: toggleMediaLib,
|
|
321
|
+
handleChangeAssets
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
] });
|
|
325
|
+
function setUpPlugins(editor) {
|
|
326
|
+
const pluginsToSetup = {
|
|
327
|
+
WordCount: setUpWordCount,
|
|
328
|
+
ImageUploadEditing: setUpImageUploadEditing,
|
|
329
|
+
StrapiMediaLib: setUpStrapiMediaLib,
|
|
330
|
+
StrapiUploadAdapter: setUpStrapiUploadAdapter
|
|
331
|
+
};
|
|
332
|
+
Object.entries(pluginsToSetup).forEach(([pluginName, setUpFn]) => {
|
|
333
|
+
if (editor.plugins.has(pluginName)) {
|
|
334
|
+
try {
|
|
335
|
+
setUpFn(editor);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
console.error(`CKEditor: Error setting up ${pluginName} plugin `, err);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function setUpWordCount(editor) {
|
|
343
|
+
const wordCountPlugin = editor.plugins.get("WordCount");
|
|
344
|
+
if (wordsLimit || charsLimit) {
|
|
345
|
+
wordCountPlugin.on("update", (_e, stats) => validateInputLength(stats));
|
|
346
|
+
const { words, characters } = wordCountPlugin;
|
|
347
|
+
validateInputLength({ words, characters });
|
|
348
|
+
}
|
|
349
|
+
wordCounterRef.current?.appendChild(wordCountPlugin.wordCountContainer);
|
|
350
|
+
}
|
|
351
|
+
function setUpImageUploadEditing(editor) {
|
|
352
|
+
const imageUploadEditingPlugin = editor.plugins.get("ImageUploadEditing");
|
|
353
|
+
const setAltAttribute = (_e, { data, imageElement }) => {
|
|
354
|
+
editor.model.change((writer) => {
|
|
355
|
+
writer.setAttribute("alt", data.alt, imageElement);
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
imageUploadEditingPlugin.on("uploadComplete", setAltAttribute);
|
|
359
|
+
}
|
|
360
|
+
function setUpStrapiMediaLib(editor) {
|
|
361
|
+
const strapiMediaLibPlugin = editor.plugins.get("StrapiMediaLib");
|
|
362
|
+
strapiMediaLibPlugin.connect(toggleMediaLib);
|
|
363
|
+
}
|
|
364
|
+
function setUpStrapiUploadAdapter(editor) {
|
|
365
|
+
const StrapiUploadAdapterPlugin = editor.plugins.get(
|
|
366
|
+
"StrapiUploadAdapter"
|
|
367
|
+
);
|
|
368
|
+
const token = getStoredToken();
|
|
369
|
+
const config = {
|
|
370
|
+
uploadUrl: prefixFileUrlWithBackendUrl("/upload"),
|
|
371
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
372
|
+
};
|
|
373
|
+
StrapiUploadAdapterPlugin.initAdapter(config);
|
|
374
|
+
}
|
|
375
|
+
function validateInputLength(stats) {
|
|
376
|
+
if (wordsLimit) {
|
|
377
|
+
setIsWordsMax(stats.words > wordsLimit);
|
|
378
|
+
}
|
|
379
|
+
if (charsLimit) {
|
|
380
|
+
setIsCharsMax(stats.characters > charsLimit);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const WordCounter = styled(Flex)`
|
|
385
|
+
${({ theme, $isWordsMax, $isCharsMax }) => css`
|
|
386
|
+
.ck-word-count__words {
|
|
387
|
+
color: ${$isWordsMax ? theme.colors.danger600 : theme.colors.neutral400};
|
|
388
|
+
}
|
|
389
|
+
.ck-word-count__characters {
|
|
390
|
+
color: ${$isCharsMax ? theme.colors.danger600 : theme.colors.neutral400};
|
|
391
|
+
}
|
|
392
|
+
`}
|
|
393
|
+
`;
|
|
394
|
+
function EditorLayout({ children }) {
|
|
395
|
+
const { error, preset } = useEditorContext();
|
|
396
|
+
const [isExpandedMode, setIsExpandedMode] = useState(false);
|
|
397
|
+
const handleToggleExpand = () => setIsExpandedMode(true);
|
|
398
|
+
const handleOnCollapse = () => setIsExpandedMode(false);
|
|
399
|
+
useEffect(() => {
|
|
400
|
+
if (isExpandedMode) {
|
|
401
|
+
document.body.classList.add("lock-body-scroll");
|
|
402
|
+
}
|
|
403
|
+
return () => {
|
|
404
|
+
document.body.classList.remove("lock-body-scroll");
|
|
405
|
+
};
|
|
406
|
+
}, [isExpandedMode]);
|
|
407
|
+
if (isExpandedMode) {
|
|
408
|
+
return /* @__PURE__ */ jsx(Portal, { role: "dialog", "aria-modal": false, children: /* @__PURE__ */ jsx(FocusTrap, { onEscape: handleOnCollapse, children: /* @__PURE__ */ jsx(
|
|
409
|
+
Backdrop,
|
|
410
|
+
{
|
|
411
|
+
position: "fixed",
|
|
412
|
+
top: 0,
|
|
413
|
+
left: 0,
|
|
414
|
+
right: 0,
|
|
415
|
+
bottom: 0,
|
|
416
|
+
zIndex: 4,
|
|
417
|
+
justifyContent: "center",
|
|
418
|
+
onClick: handleOnCollapse,
|
|
419
|
+
children: /* @__PURE__ */ jsx(
|
|
420
|
+
FullScreenBox,
|
|
421
|
+
{
|
|
422
|
+
background: "neutral100",
|
|
423
|
+
hasRadius: true,
|
|
424
|
+
shadow: "popupShadow",
|
|
425
|
+
overflow: "hidden",
|
|
426
|
+
width: "90%",
|
|
427
|
+
height: "90%",
|
|
428
|
+
onClick: (e) => e.stopPropagation(),
|
|
429
|
+
position: "relative",
|
|
430
|
+
children: /* @__PURE__ */ jsx(Flex, { height: "100%", alignItems: "flex-start", direction: "column", children: /* @__PURE__ */ jsxs(
|
|
431
|
+
EditorWrapper,
|
|
432
|
+
{
|
|
433
|
+
$presetStyles: preset?.styles,
|
|
434
|
+
$isExpanded: isExpandedMode,
|
|
435
|
+
$hasError: Boolean(error),
|
|
436
|
+
className: "ck-editor__expanded",
|
|
437
|
+
children: [
|
|
438
|
+
children,
|
|
439
|
+
/* @__PURE__ */ jsx(CollapseButton, { label: "Collapse", onClick: handleOnCollapse, children: /* @__PURE__ */ jsx(Collapse, {}) })
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
) })
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
) }) });
|
|
447
|
+
}
|
|
448
|
+
return /* @__PURE__ */ jsxs(
|
|
449
|
+
EditorWrapper,
|
|
450
|
+
{
|
|
451
|
+
$presetStyles: preset?.styles,
|
|
452
|
+
$isExpanded: isExpandedMode,
|
|
453
|
+
$hasError: Boolean(error),
|
|
454
|
+
children: [
|
|
455
|
+
children,
|
|
456
|
+
/* @__PURE__ */ jsx(ExpandButton, { label: "Expand", onClick: handleToggleExpand, children: /* @__PURE__ */ jsx(Expand, {}) })
|
|
457
|
+
]
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
const EditorWrapper = styled("div")`
|
|
462
|
+
position: relative;
|
|
463
|
+
width: 100%;
|
|
464
|
+
|
|
465
|
+
${({ $presetStyles, theme, $hasError = false, $isExpanded }) => css`
|
|
466
|
+
height: ${$isExpanded ? "100%" : "auto"};
|
|
467
|
+
border-radius: ${theme.borderRadius};
|
|
468
|
+
outline: none;
|
|
469
|
+
box-shadow: 0;
|
|
470
|
+
transition-property: border-color, box-shadow, fill;
|
|
471
|
+
transition-duration: 0.2s;
|
|
472
|
+
border: 1px solid ${$hasError ? theme.colors.danger600 : theme.colors.neutral200};
|
|
473
|
+
border-radius: ${theme.borderRadius};
|
|
474
|
+
|
|
475
|
+
&:focus-within {
|
|
476
|
+
border: 1px solid ${$isExpanded ? theme.colors.neutral200 : theme.colors.primary600};
|
|
477
|
+
border-color: ${$hasError && theme.colors.danger600};
|
|
478
|
+
box-shadow: ${$hasError ? theme.colors.danger600 : theme.colors.primary600} 0px 0px 0px 2px;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
${$presetStyles}
|
|
482
|
+
`}
|
|
483
|
+
`;
|
|
484
|
+
const Backdrop = styled(Flex)`
|
|
485
|
+
background: ${({ theme }) => `${theme.colors.neutral800}1F`};
|
|
486
|
+
`;
|
|
487
|
+
const ExpandButton = styled(IconButton)`
|
|
488
|
+
position: absolute;
|
|
489
|
+
bottom: 1.4rem;
|
|
490
|
+
right: 1.2rem;
|
|
491
|
+
z-index: 2;
|
|
492
|
+
`;
|
|
493
|
+
const CollapseButton = styled(IconButton)`
|
|
494
|
+
position: absolute;
|
|
495
|
+
bottom: 2.5rem;
|
|
496
|
+
right: 1.2rem;
|
|
497
|
+
z-index: 2;
|
|
498
|
+
`;
|
|
499
|
+
const FullScreenBox = styled(Box)`
|
|
500
|
+
max-width: var(--ck-editor-full-screen-box-max-width);
|
|
501
|
+
`;
|
|
502
|
+
const GlobalStyle = createGlobalStyle`
|
|
503
|
+
${({ $editortTheme, $variant }) => $editortTheme && css`
|
|
504
|
+
${$editortTheme.common}
|
|
505
|
+
${$editortTheme[$variant]}
|
|
506
|
+
${$editortTheme.additional}
|
|
507
|
+
`}
|
|
508
|
+
`;
|
|
509
|
+
const getSystemColorScheme = () => window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
510
|
+
function GlobalStyling() {
|
|
511
|
+
const { theme } = getPluginConfig();
|
|
512
|
+
const profileTheme = getProfileTheme();
|
|
513
|
+
const variant = profileTheme && profileTheme !== "system" ? profileTheme : getSystemColorScheme();
|
|
514
|
+
return /* @__PURE__ */ jsx(GlobalStyle, { $editortTheme: theme, $variant: variant });
|
|
515
|
+
}
|
|
516
|
+
const MemoizedGlobalStyling = React.memo(GlobalStyling);
|
|
517
|
+
function Editor() {
|
|
518
|
+
const { name, hint, required, labelAction, label, error, preset } = useEditorContext();
|
|
519
|
+
return /* @__PURE__ */ jsx(Field$1.Root, { id: name, name, error, hint, required, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
520
|
+
/* @__PURE__ */ jsx(Field$1.Label, { action: labelAction, children: label }),
|
|
521
|
+
preset ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
522
|
+
/* @__PURE__ */ jsx(MemoizedGlobalStyling, {}),
|
|
523
|
+
/* @__PURE__ */ jsx(EditorLayout, { children: /* @__PURE__ */ jsx(CKEReact, {}) })
|
|
524
|
+
] }) : /* @__PURE__ */ jsx(LoaderBox, { hasRadius: true, background: "neutral100", children: /* @__PURE__ */ jsx(Loader, { children: "Loading..." }) }),
|
|
525
|
+
/* @__PURE__ */ jsx(Field$1.Hint, {}),
|
|
526
|
+
/* @__PURE__ */ jsx(Field$1.Error, {})
|
|
527
|
+
] }) });
|
|
528
|
+
}
|
|
529
|
+
const LoaderBox = styled(Box)`
|
|
530
|
+
display: flex;
|
|
531
|
+
justify-content: center;
|
|
532
|
+
align-items: center;
|
|
533
|
+
height: 200px;
|
|
534
|
+
width: 100%;
|
|
535
|
+
`;
|
|
536
|
+
function Field({
|
|
537
|
+
name,
|
|
538
|
+
hint,
|
|
539
|
+
error,
|
|
540
|
+
placeholder,
|
|
541
|
+
label,
|
|
542
|
+
attribute,
|
|
543
|
+
labelAction = null,
|
|
544
|
+
disabled = false,
|
|
545
|
+
required = false
|
|
546
|
+
}) {
|
|
547
|
+
const { preset, maxLengthWords, maxLengthCharacters } = attribute.options;
|
|
548
|
+
const isFieldLocalized = attribute?.pluginOptions?.i18n?.localized ?? false;
|
|
549
|
+
return /* @__PURE__ */ jsx(
|
|
550
|
+
EditorProvider,
|
|
551
|
+
{
|
|
552
|
+
name,
|
|
553
|
+
error,
|
|
554
|
+
disabled,
|
|
555
|
+
required,
|
|
556
|
+
placeholder,
|
|
557
|
+
hint,
|
|
558
|
+
label,
|
|
559
|
+
labelAction,
|
|
560
|
+
presetName: preset,
|
|
561
|
+
wordsLimit: maxLengthWords,
|
|
562
|
+
charsLimit: maxLengthCharacters,
|
|
563
|
+
isFieldLocalized,
|
|
564
|
+
children: /* @__PURE__ */ jsx(Editor, {})
|
|
565
|
+
}
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
function compare(oldProps, newProps) {
|
|
569
|
+
return oldProps.error === newProps.error && oldProps.labelAction === newProps.labelAction;
|
|
570
|
+
}
|
|
571
|
+
const MemoizedField = React.memo(Field, compare);
|
|
572
|
+
export {
|
|
573
|
+
MemoizedField as Field
|
|
574
|
+
};
|