mirror of
https://github.com/docmost/docmost.git
synced 2026-05-20 08:34:04 +08:00
feat: enhance editor uploads (#895)
* * multi-file paste support * allow media files (image/videos) to be attachments * insert trailing node if file placeholder is at the end of the editor * fix video align
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { type EditorState, Plugin, PluginKey } from "@tiptap/pm/state";
|
||||
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
||||
import { MediaUploadOptions, UploadFn } from "../media-utils";
|
||||
import { insertTrailingNode, MediaUploadOptions, UploadFn } from "../media-utils";
|
||||
import { IAttachment } from "../types";
|
||||
|
||||
const uploadKey = new PluginKey("image-upload");
|
||||
@@ -69,13 +69,13 @@ export const handleImageUpload =
|
||||
// A fresh object to act as the ID for this upload
|
||||
const id = {};
|
||||
|
||||
// Replace the selection with a placeholder
|
||||
const tr = view.state.tr;
|
||||
if (!tr.selection.empty) tr.deleteSelection();
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => {
|
||||
const tr = view.state.tr;
|
||||
// Replace the selection with a placeholder
|
||||
if (!tr.selection.empty) tr.deleteSelection();
|
||||
|
||||
tr.setMeta(uploadKey, {
|
||||
add: {
|
||||
id,
|
||||
@@ -83,6 +83,8 @@ export const handleImageUpload =
|
||||
src: reader.result,
|
||||
},
|
||||
});
|
||||
|
||||
insertTrailingNode(tr, pos, view);
|
||||
view.dispatch(tr);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user