Skip to content

Commit

Permalink
fix: issue when adding media via media library with multiple editor i…
Browse files Browse the repository at this point in the history
…nstances, #175
  • Loading branch information
nshenderov committed Nov 5, 2024
1 parent 4ef7b0f commit 39454a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
26 changes: 7 additions & 19 deletions admin/src/Input/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Editor = ({
disabled = false,
presetName,
maxLength,
placeholder
placeholder,
}) => {
const [editorInstance, setEditorInstance] = useState(false);

Expand All @@ -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);
})();
}, []);

Expand Down
24 changes: 17 additions & 7 deletions admin/src/Input/config/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 39454a4

Please sign in to comment.