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

35 lines
960 B
Plaintext
Raw Normal View History

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