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, closes #175
  • Loading branch information
nshenderov committed Nov 5, 2024
1 parent 217e1fe commit ce46033
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
24 changes: 6 additions & 18 deletions admin/src/components/Input/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@ export const Editor = ({

useEffect(() => {
(async () => {
const currentPreset = await getConfiguredPreset(
presetName,
handleToggleMediaLib
);

if (placeholder) {
const clonedPreset = {
...currentPreset,
editorConfig: {
...currentPreset.editorConfig,
placeholder: placeholder,
},
};

setPreset(clonedPreset);
} else {
setPreset(currentPreset);
}
const currentPreset = await getConfiguredPreset(presetName, {
toggleMediaLib: handleToggleMediaLib,
strapiFieldPlaceholder: placeholder,
});

setPreset(currentPreset);
})();
}, []);

Expand Down
24 changes: 17 additions & 7 deletions admin/src/components/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 ce46033

Please sign in to comment.