diff --git a/plugins/compact-composer/index.php b/plugins/compact-composer/index.php index b165bddaf8..c04a4e7322 100644 --- a/plugins/compact-composer/index.php +++ b/plugins/compact-composer/index.php @@ -6,7 +6,7 @@ class CompactComposerPlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Compact Composer', AUTHOR = 'Sergey Mosin', URL = 'https://github.com/the-djmaze/snappymail/pull/1466', - VERSION = '1.0.0', + VERSION = '1.0.1', RELEASE = '2024-02-23', REQUIRED = '2.34.0', LICENSE = 'AGPL v3', @@ -14,7 +14,7 @@ class CompactComposerPlugin extends \RainLoop\Plugins\AbstractPlugin public function Init(): void { - $this->addTemplate('templates/PopupsCompose.html'); + $this->addTemplate('templates/PopupsCompactCompose.html'); $this->addCss('css/composer.css'); $this->addJs('js/squire-raw.js'); $this->addJs('js/parsel.js'); diff --git a/plugins/compact-composer/js/CompactComposer.js b/plugins/compact-composer/js/CompactComposer.js index 4a95a6c130..92451a9bf4 100644 --- a/plugins/compact-composer/js/CompactComposer.js +++ b/plugins/compact-composer/js/CompactComposer.js @@ -1,16 +1,47 @@ /* eslint max-len: 0 */ (win => { - addEventListener('rl-view-model.create', e => { - if (e.detail.viewModelTemplateID === 'PopupsCompose') { - // There is a better way to do this probably, - // but we need this for drag and drop to work - e.detail.attachmentsArea = e.detail.bodyArea; - } + const rl = win.rl; + + if (!rl) { + return; + } + + rl.registerWYSIWYG('CompactComposer', (owner, container, onReady) => { + const editor = new CompactComposer(container); + onReady(editor); }); const doc = win.document; - const rl = win.rl; + + // If a user (or admin) selected the CompactComposer we need to + // replace PopupsCompose template with PopupsCompactCompose template. + // -- + // This might break some plugins if they query/change PopupsCompose template + // before this code is called. They should instead listen for + // 'rl-view-model.create' to work properly. + if (rl.settings.get('editorWysiwyg') === 'CompactComposer') { + const compactTemplate = doc.getElementById('PopupsCompactCompose'); + if (!compactTemplate) { + console.error('CompactComposer: PopupsCompactCompose template not found'); + return; + } + const originalTemplate = doc.getElementById('PopupsCompose'); + if (originalTemplate) { + originalTemplate.id = 'PopupsCompose_replaced'; + } else { + console.warn('CompactComposer: PopupsCompose template not found'); + } + compactTemplate.id = 'PopupsCompose'; + + addEventListener('rl-view-model.create', e => { + if (e.detail.viewModelTemplateID === 'PopupsCompose') { + // There is a better way to do this probably, + // but we need this for drag and drop to work + e.detail.attachmentsArea = e.detail.bodyArea; + } + }); + } const removeElements = 'HEAD,LINK,META,NOSCRIPT,SCRIPT,TEMPLATE,TITLE', @@ -956,12 +987,4 @@ } } } - - if (rl) { - rl.registerWYSIWYG('CompactComposer', (owner, container, onReady) => { - const editor = new CompactComposer(container); - onReady(editor); - }); - } - })(window); diff --git a/plugins/compact-composer/templates/PopupsCompose.html b/plugins/compact-composer/templates/PopupsCompactCompose.html similarity index 100% rename from plugins/compact-composer/templates/PopupsCompose.html rename to plugins/compact-composer/templates/PopupsCompactCompose.html