mirror of
https://github.com/docmost/docmost.git
synced 2026-05-21 01:04:39 +08:00
fix: Drag & drop, paste upload
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
onSyncedParameters,
|
onSyncedParameters,
|
||||||
} from "@hocuspocus/provider";
|
} from "@hocuspocus/provider";
|
||||||
import {
|
import {
|
||||||
|
Editor,
|
||||||
EditorContent,
|
EditorContent,
|
||||||
EditorProvider,
|
EditorProvider,
|
||||||
useEditor,
|
useEditor,
|
||||||
@@ -79,7 +80,7 @@ export default function PageEditor({
|
|||||||
}: PageEditorProps) {
|
}: PageEditorProps) {
|
||||||
const collaborationURL = useCollaborationUrl();
|
const collaborationURL = useCollaborationUrl();
|
||||||
const isComponentMounted = useRef(false);
|
const isComponentMounted = useRef(false);
|
||||||
const editorCreated = useRef(false);
|
const editorRef = useRef<Editor | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isComponentMounted.current = true;
|
isComponentMounted.current = true;
|
||||||
@@ -104,8 +105,8 @@ export default function PageEditor({
|
|||||||
const userPageEditMode =
|
const userPageEditMode =
|
||||||
currentUser?.user?.settings?.preferences?.pageEditMode ?? PageEditMode.Edit;
|
currentUser?.user?.settings?.preferences?.pageEditMode ?? PageEditMode.Edit;
|
||||||
const canScroll = useCallback(
|
const canScroll = useCallback(
|
||||||
() => isComponentMounted.current && editorCreated.current,
|
() => Boolean(isComponentMounted.current && editorRef.current),
|
||||||
[isComponentMounted, editorCreated],
|
[isComponentMounted],
|
||||||
);
|
);
|
||||||
const { handleScrollTo } = useEditorScroll({ canScroll });
|
const { handleScrollTo } = useEditorScroll({ canScroll });
|
||||||
// Providers only created once per pageId
|
// Providers only created once per pageId
|
||||||
@@ -253,10 +254,21 @@ export default function PageEditor({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
handlePaste: (_view, event) =>
|
handlePaste: (_view, event) => {
|
||||||
handlePaste(editor, event, pageId, currentUser?.user.id),
|
if (!editorRef.current) return false;
|
||||||
handleDrop: (_view, event, _slice, moved) =>
|
|
||||||
handleFileDrop(editor, event, moved, pageId),
|
return handlePaste(
|
||||||
|
editorRef.current,
|
||||||
|
event,
|
||||||
|
pageId,
|
||||||
|
currentUser?.user.id,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
handleDrop: (_view, event, _slice, moved) => {
|
||||||
|
if (!editorRef.current) return false;
|
||||||
|
|
||||||
|
return handleFileDrop(editorRef.current, event, moved, pageId);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
onCreate({ editor }) {
|
onCreate({ editor }) {
|
||||||
if (editor) {
|
if (editor) {
|
||||||
@@ -265,7 +277,7 @@ export default function PageEditor({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
editor.storage.pageId = pageId;
|
editor.storage.pageId = pageId;
|
||||||
handleScrollTo(editor);
|
handleScrollTo(editor);
|
||||||
editorCreated.current = true;
|
editorRef.current = editor;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUpdate({ editor }) {
|
onUpdate({ editor }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user