Skip to content

Commit

Permalink
fix: use compact template in non-destructive way (do not replace the …
Browse files Browse the repository at this point in the history
…PopupsCompose template if a different wysiwyg is used)
  • Loading branch information
SergeyMosin committed Mar 1, 2024
1 parent 6169f60 commit d6acf55
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions plugins/compact-composer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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',
DESCRIPTION = 'WYSIWYG editor with a compact toolbar';

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');
Expand Down
53 changes: 38 additions & 15 deletions plugins/compact-composer/js/CompactComposer.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -956,12 +987,4 @@
}
}
}

if (rl) {
rl.registerWYSIWYG('CompactComposer', (owner, container, onReady) => {
const editor = new CompactComposer(container);
onReady(editor);
});
}

})(window);

0 comments on commit d6acf55

Please sign in to comment.