From 39454a47e6e9c78451cf9ace5ffcff39ca975a0d Mon Sep 17 00:00:00 2001 From: nshenderov Date: Wed, 6 Nov 2024 01:16:42 +0300 Subject: [PATCH] fix: issue when adding media via media library with multiple editor instances, #175 --- admin/src/Input/components/Editor.js | 26 +++++++------------------- admin/src/Input/config/presets.js | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/admin/src/Input/components/Editor.js b/admin/src/Input/components/Editor.js index a6ce02f..866fc26 100644 --- a/admin/src/Input/components/Editor.js +++ b/admin/src/Input/components/Editor.js @@ -20,7 +20,7 @@ export const Editor = ({ disabled = false, presetName, maxLength, - placeholder + placeholder, }) => { const [editorInstance, setEditorInstance] = useState(false); @@ -39,24 +39,12 @@ export const Editor = ({ useEffect(() => { (async () => { - const currentPreset = await getConfiguredPreset( - presetName, - handleToggleMediaLib - ); - - if (placeholder) { - const clonedPreset = { - ...currentPreset, - editorConfig: { - ...currentPreset.editorConfig, - placeholder: placeholder.defaultMessage, - }, - }; - - setPreset(clonedPreset); - } else { - setPreset(currentPreset); - } + const currentPreset = await getConfiguredPreset(presetName, { + toggleMediaLib: handleToggleMediaLib, + strapiFieldPlaceholder: placeholder?.defaultMessage, + }); + + setPreset(currentPreset); })(); }, []); diff --git a/admin/src/Input/config/presets.js b/admin/src/Input/config/presets.js index 7bf38fc..f7e1c91 100644 --- a/admin/src/Input/config/presets.js +++ b/admin/src/Input/config/presets.js @@ -2,17 +2,27 @@ import basePresets from '../presets'; import { setPlugins } from './plugins'; import { setLanguage } from './language'; -export const getConfiguredPreset = async (presetName, toggleMediaLib) => { +export const getConfiguredPreset = async ( + presetName, + { toggleMediaLib, strapiFieldPlaceholder } +) => { const { presets: userPresets, dontMergePresets } = globalThis.SH_CKE_CONFIG || {}; - const preset = dontMergePresets - ? userPresets[presetName] - : basePresets[presetName]; + const preset = + dontMergePresets ? userPresets[presetName] : basePresets[presetName]; - setPlugins(preset.editorConfig, toggleMediaLib); + const clonedPreset = { + ...preset, + editorConfig: { + ...preset.editorConfig, + placeholder: strapiFieldPlaceholder || preset.editorConfig.placeholder, + }, + }; - await setLanguage(preset.editorConfig); + setPlugins(clonedPreset.editorConfig, toggleMediaLib); - return preset; + await setLanguage(clonedPreset.editorConfig); + + return clonedPreset; };