2021-10-27 15:23:28 +05:30
|
|
|
import { Extension } from '@tiptap/core';
|
|
|
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
|
|
import { handleFileEvent } from '../services/upload_helpers';
|
|
|
|
|
|
|
|
export default Extension.create({
|
|
|
|
name: 'attachment',
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
addOptions() {
|
|
|
|
return {
|
|
|
|
uploadsPath: null,
|
|
|
|
renderMarkdown: null,
|
|
|
|
};
|
2021-10-27 15:23:28 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
|
|
|
uploadAttachment: ({ file }) => () => {
|
|
|
|
const { uploadsPath, renderMarkdown } = this.options;
|
|
|
|
|
|
|
|
return handleFileEvent({ file, uploadsPath, renderMarkdown, editor: this.editor });
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
addProseMirrorPlugins() {
|
|
|
|
const { editor } = this;
|
|
|
|
|
|
|
|
return [
|
|
|
|
new Plugin({
|
|
|
|
key: new PluginKey('attachment'),
|
|
|
|
props: {
|
|
|
|
handlePaste: (_, event) => {
|
|
|
|
const { uploadsPath, renderMarkdown } = this.options;
|
|
|
|
|
|
|
|
return handleFileEvent({
|
|
|
|
editor,
|
|
|
|
file: event.clipboardData.files[0],
|
|
|
|
uploadsPath,
|
|
|
|
renderMarkdown,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleDrop: (_, event) => {
|
|
|
|
const { uploadsPath, renderMarkdown } = this.options;
|
|
|
|
|
|
|
|
return handleFileEvent({
|
|
|
|
editor,
|
|
|
|
file: event.dataTransfer.files[0],
|
|
|
|
uploadsPath,
|
|
|
|
renderMarkdown,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
});
|