-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprops.ts
53 lines (51 loc) · 1.6 KB
/
props.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
45
46
47
48
49
50
51
52
53
import type { EditorProps } from '@tiptap/pm/view';
import { startImageUpload } from './plugins/upload-images';
export const TiptapEditorProps: EditorProps = {
attributes: {
class: `prose prose-lg prose-stone dark:prose-invert prose-headings:font-display font-default focus:outline-none max-w-full min-h-[150px] text-muted-foreground p-2`,
},
handleDOMEvents: {
keydown: (_view, event) => {
// prevent default event listeners from firing when slash command is active
if (['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {
const slashCommand = document.querySelector('#slash-command');
if (slashCommand) {
return true;
}
}
},
},
handlePaste: (view, event) => {
if (
event.clipboardData &&
event.clipboardData.files &&
event.clipboardData.files[0]
) {
event.preventDefault();
const file = event.clipboardData.files[0];
const pos = view.state.selection.from;
startImageUpload(file, view, pos);
return true;
}
return false;
},
handleDrop: (view, event, _slice, moved) => {
if (
!moved &&
event.dataTransfer &&
event.dataTransfer.files &&
event.dataTransfer.files[0]
) {
event.preventDefault();
const file = event.dataTransfer.files[0];
const coordinates = view.posAtCoords({
left: event.clientX,
top: event.clientY,
});
// here we deduct 1 from the pos or else the image will create an extra node
startImageUpload(file, view, (coordinates?.pos ?? 0) - 1);
return true;
}
return false;
},
};