mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-15 17:53:44 +08:00
35 lines
1,009 B
JavaScript
35 lines
1,009 B
JavaScript
import { Actions, ComposerExtension } from 'mailspring-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,
|
|
});
|
|
}
|
|
}
|