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:
Philip Okugbe
2025-03-15 18:27:26 +00:00
committed by GitHub
parent 573457403e
commit 21c3ad0ecc
8 changed files with 123 additions and 44 deletions

View File

@ -1,6 +1,10 @@
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("video-upload");
@ -70,12 +74,13 @@ export const handleVideoUpload =
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;
if (!tr.selection.empty) tr.deleteSelection();
tr.setMeta(uploadKey, {
add: {
id,
@ -83,6 +88,8 @@ export const handleVideoUpload =
src: reader.result,
},
});
insertTrailingNode(tr, pos, view);
view.dispatch(tr);
};