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

35 lines
966 B
Text
Raw Normal View History

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