Skip to content

Commit

Permalink
Ensure plugins are dynamically loaded in CKEditor 5
Browse files Browse the repository at this point in the history
With the new installation format of CKEditor, plugins are no longer
automatically unwrapped when the editor is instantiated. Instead, we
must explicitly load plugins or `extraPlugins` and provide a reference
to the loaded class.

This change ensures that all required plugins are properly registered
before initialization, preventing missing plugin errors and maintaining
expected functionality.
  • Loading branch information
craigkai committed Feb 4, 2025
1 parent 7fa1c45 commit b4e4a52
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,33 @@ async function ReplaceAllTextareas(elt) {

// Customize shouldNotGroupWhenFull based on textarea width
const initArgs = JSON.parse(JSON.stringify(RT.Config.MessageBoxRichTextInitArguments));
initArgs.toolbar.shouldNotGroupWhenFull = textArea.offsetWidth >= 600 ? true : false;
initArgs.toolbar.shouldNotGroupWhenFull = initArgs.toolbar.shouldNotGroupWhenFull = textArea.offsetWidth >= 600 ? true : false;

// Load core plugins from CKEDITOR
const corePlugins = [];
for (const plugin of initArgs.plugins || []) {
if (CKEDITOR?.[plugin]) {
corePlugins.push(CKEDITOR[plugin]);
} else {
console.error(`Core CKEditor plugin "${plugin}" not found.`);
}
}

// Load extra (third-party) plugins from window
const thirdPartyPlugins = [];
for (const plugin of initArgs.extraPlugins || []) {
if (window[plugin]?.[plugin]) {
thirdPartyPlugins.push(window[plugin][plugin]);
} else {
console.error(`Third-party CKEditor plugin "${plugin}" not found.`);
}
}

// Combine core and third-party plugins
initArgs.plugins = [...corePlugins, ...thirdPartyPlugins];
initArgs.extraPlugins = []; // Clear extraPlugins as they're now included

ClassicEditor
CKEDITOR.ClassicEditor
.create( textArea, initArgs )
.then(editor => {
RT_CKEditor.instances[editor.sourceElement.name] = editor;
Expand Down

0 comments on commit b4e4a52

Please sign in to comment.