From ff6f87a16aa9e63c3ad7e1b06a8b897577d8a10b Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 13 Jun 2021 18:13:57 +0200 Subject: [PATCH] Fix conflicts in RTE with multiple editor instances #3475 --- src/dom_components/view/ComponentTextView.js | 4 ++-- src/rich_text_editor/index.js | 12 +++++++----- src/rich_text_editor/model/RichTextEditor.js | 16 ++++++++-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/dom_components/view/ComponentTextView.js b/src/dom_components/view/ComponentTextView.js index 1bf796879..f47aa558e 100644 --- a/src/dom_components/view/ComponentTextView.js +++ b/src/dom_components/view/ComponentTextView.js @@ -28,7 +28,7 @@ export default ComponentView.extend({ * Enable element content editing * @private * */ - onActive(e) { + async onActive(e) { const { rte, em } = this; // We place this before stopPropagation in case of nested @@ -45,7 +45,7 @@ export default ComponentView.extend({ if (rte) { try { - this.activeRte = rte.enable(this, this.activeRte); + this.activeRte = await rte.enable(this, this.activeRte); } catch (err) { em.logError(err); } diff --git a/src/rich_text_editor/index.js b/src/rich_text_editor/index.js index 453e0d003..8d6daaccb 100644 --- a/src/rich_text_editor/index.js +++ b/src/rich_text_editor/index.js @@ -289,25 +289,27 @@ export default () => { * @param {Object} rte The instance of already defined RTE * @private * */ - enable(view, rte) { + async enable(view, rte) { lastEl = view.el; + const { customRte } = this; const canvas = config.em.get('Canvas'); const em = config.em; const el = view.getChildrenContainer(); - const customRte = this.customRte; lastElPos = canvas.getElementPos(lastEl); toolbar.style.display = ''; - rte = customRte ? customRte.enable(el, rte) : this.initRte(el).enable(); + const rteInst = await (customRte + ? customRte.enable(el, rte) + : this.initRte(el).enable()); if (em) { setTimeout(this.updatePosition.bind(this), 0); em.off(eventsUp, this.updatePosition, this); em.on(eventsUp, this.updatePosition, this); - em.trigger('rte:enable', view, rte); + em.trigger('rte:enable', view, rteInst); } - return rte; + return rteInst; }, /** diff --git a/src/rich_text_editor/model/RichTextEditor.js b/src/rich_text_editor/model/RichTextEditor.js index df58d2367..35dbf97fb 100644 --- a/src/rich_text_editor/model/RichTextEditor.js +++ b/src/rich_text_editor/model/RichTextEditor.js @@ -80,18 +80,18 @@ export default class RichTextEditor { this.setEl(el); this.updateActiveActions = this.updateActiveActions.bind(this); - const settAct = settings.actions || []; - settAct.forEach((action, i) => { + const acts = (settings.actions || []).map(action => { + let result = action; if (typeof action === 'string') { - action = defActions[action]; + result = { ...defActions[action] }; } else if (defActions[action.name]) { - action = { ...defActions[action.name], ...action }; + result = { ...defActions[action.name], ...action }; } - settAct[i] = action; + return result; }); - const actions = settAct.length - ? settAct - : Object.keys(defActions).map(action => defActions[action]); + const actions = acts.length + ? acts + : Object.keys(defActions).map(a => defActions[a]); settings.classes = { ...{