Mailspring/app/internal_packages/composer/lib/inline-image-composer-extension.es6

36 lines
1,009 B
Plaintext
Raw Normal View History

import { Actions, ComposerExtension } from 'mailspring-exports';
export default class InlineImageComposerExtension extends ComposerExtension {
static editingActions() {
2017-09-27 02:33:08 +08:00
return [
{
action: Actions.insertAttachmentIntoDraft,
callback: InlineImageComposerExtension._onInsertAttachmentIntoDraft,
},
{
action: Actions.removeAttachment,
callback: InlineImageComposerExtension._onRemovedAttachment,
},
];
}
2017-09-27 02:33:08 +08:00
static _onRemovedAttachment({ editor, actionArg }) {
const file = actionArg;
2017-09-27 02:33:08 +08:00
const el = editor.rootNode.querySelector(`.inline-container-${file.id}`);
if (el) {
el.parentNode.removeChild(el);
}
}
2017-09-27 02:33:08 +08:00
static _onInsertAttachmentIntoDraft({ editor, actionArg }) {
if (editor.headerMessageId === actionArg.headerMessageId) {
return;
}
2017-09-27 02:33:08 +08:00
editor.insertCustomComponent('InlineImageUploadContainer', {
className: `inline-container-${actionArg.fileId}`,
fileId: actionArg.fileId,
2017-09-27 02:33:08 +08:00
});
}
}