-
-
Notifications
You must be signed in to change notification settings - Fork 607
/
handlers.ts
44 lines (37 loc) · 1.09 KB
/
handlers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import { findEventRange, select, Value } from '@udecode/plate-common';
import { PlateCloudEditor } from './types';
import { uploadFiles } from './uploadFiles';
export const onDropCloud = <V extends Value = Value>(
editor: PlateCloudEditor<V>,
e: React.DragEvent
): boolean => {
const { files } = e.dataTransfer;
if (files.length === 0) return false;
/**
* Without this, the dropped file replaces the page
*/
e.preventDefault();
e.stopPropagation();
/**
* When we drop a file, the selection won't move automatically to the drop
* location. Find the location from the event and upload the files at that
* location.
*/
const at = findEventRange(editor, e);
if (!at) return false;
select(editor, at);
uploadFiles(editor, files);
return true;
};
export const onPasteCloud = <V extends Value = Value>(
editor: PlateCloudEditor<V>,
e: React.ClipboardEvent
): boolean => {
const { files } = e.clipboardData;
if (files.length === 0) return false;
e.preventDefault();
e.stopPropagation();
uploadFiles<V>(editor, files);
return true;
};