Skip to content

Commit 57594a3

Browse files
committed
fix: load plugins up front
1 parent 3b40d72 commit 57594a3

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/packages/tiny-mce/components/input-tiny-mce/input-tiny-mce.element.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
5252
@property({ attribute: false })
5353
configuration?: UmbPropertyEditorConfigCollection;
5454

55+
#plugins: Array<ClassConstructor<UmbTinyMcePluginBase> | undefined> = [];
5556
#editorRef?: Editor | null = null;
5657
#stylesheetRepository = new UmbStylesheetDetailRepository(this);
5758
#umbStylesheetRuleManager = new UmbStylesheetRuleManager();
@@ -86,11 +87,10 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
8687
this.#loadEditor();
8788
}
8889

89-
#plugins: Promise<ClassConstructor<UmbTinyMcePluginBase> | undefined>[] = [];
9090
async #loadEditor() {
91-
this.observe(umbExtensionsRegistry.byType('tinyMcePlugin'), (manifests) => {
91+
this.observe(umbExtensionsRegistry.byType('tinyMcePlugin'), async (manifests) => {
9292
this.#plugins.length = 0;
93-
this.#plugins = this.#loadPlugins(manifests);
93+
this.#plugins = await this.#loadPlugins(manifests);
9494

9595
let config: RawEditorOptions = {};
9696
manifests.forEach((manifest) => {
@@ -115,14 +115,14 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
115115
* setup method, the asynchronous nature means the editor is loaded before
116116
* the plugins are ready and so are not associated with the editor.
117117
*/
118-
#loadPlugins(manifests: Array<ManifestTinyMcePlugin>) {
118+
async #loadPlugins(manifests: Array<ManifestTinyMcePlugin>) {
119119
const promises = [];
120120
for (const manifest of manifests) {
121121
if (manifest.js) {
122-
promises.push(loadManifestApi(manifest.js));
122+
promises.push(await loadManifestApi(manifest.js));
123123
}
124124
if (manifest.api) {
125-
promises.push(loadManifestApi(manifest.api));
125+
promises.push(await loadManifestApi(manifest.api));
126126
}
127127
}
128128
return promises;
@@ -241,19 +241,18 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
241241
setup: (editor) => this.#editorSetup(editor),
242242
target: this._editorElement,
243243
paste_data_images: false,
244+
language: this.#getLanguage(),
244245

245246
// Extend with configuration options
246247
...configurationOptions,
247248

248249
// Extend with additional configuration options
249-
...additionalConfig,
250+
//...additionalConfig, // TODO: Deep merge
250251
};
251252

252-
config.language = this.#getLanguage();
253+
console.log('tried to set config', additionalConfig);
253254

254-
if (this.#editorRef) {
255-
this.#editorRef.destroy();
256-
}
255+
this.#editorRef?.destroy();
257256

258257
const editors = await renderEditor(config).catch((error) => {
259258
console.error('Failed to render TinyMCE', error);
@@ -281,7 +280,7 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
281280
return languageMatch;
282281
}
283282

284-
async #editorSetup(editor: Editor) {
283+
#editorSetup(editor: Editor) {
285284
editor.suffix = '.min';
286285

287286
// define keyboard shortcuts
@@ -327,18 +326,16 @@ export class UmbInputTinyMceElement extends UUIFormControlMixin(UmbLitElement, '
327326
});
328327
});
329328

330-
// instantiate plugins
331-
// to ensure they are available before setting up the editor.
329+
// instantiate plugins to ensure they are available before setting up the editor.
332330
// Plugins require a reference to the current editor as a param, so can not
333331
// be instantiated until we have an editor
334-
this.#plugins.forEach(async (plugin) => {
335-
const pluginConstructor = await plugin;
336-
if (pluginConstructor) {
332+
for (const plugin of this.#plugins) {
333+
if (plugin) {
337334
// [v15]: This might be improved by changing to `createExtensionApi` and avoiding the `#loadPlugins` method altogether, but that would require a breaking change
338335
// because that function sends the UmbControllerHost as the first argument, which is not the case here.
339-
new pluginConstructor({ host: this, editor });
336+
new plugin({ host: this, editor });
340337
}
341-
});
338+
}
342339
}
343340

344341
#onInit(editor: Editor) {

0 commit comments

Comments
 (0)