mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
34 lines
966 B
JavaScript
34 lines
966 B
JavaScript
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,
|
|
})
|
|
}
|
|
}
|