Upload dropped images
This commit is contained in:
parent
bc1ec414de
commit
58e671e640
|
@ -108,10 +108,7 @@ export function useTextEditor(props: {
|
||||||
editor?.setOptions({
|
editor?.setOptions({
|
||||||
editorProps: {
|
editorProps: {
|
||||||
handlePaste(view, event) {
|
handlePaste(view, event) {
|
||||||
const imageFiles = Array.from(event.clipboardData?.files ?? []).filter(
|
const imageFiles = getImages(event.clipboardData)
|
||||||
(file) => file.type.startsWith('image')
|
|
||||||
)
|
|
||||||
|
|
||||||
if (imageFiles.length) {
|
if (imageFiles.length) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
upload.mutate(imageFiles)
|
upload.mutate(imageFiles)
|
||||||
|
@ -126,6 +123,13 @@ export function useTextEditor(props: {
|
||||||
|
|
||||||
return // Otherwise, use default paste handler
|
return // Otherwise, use default paste handler
|
||||||
},
|
},
|
||||||
|
handleDrop(_view, event, _slice, moved) {
|
||||||
|
// if dragged from outside
|
||||||
|
if (!moved) {
|
||||||
|
event.preventDefault()
|
||||||
|
upload.mutate(getImages(event.dataTransfer))
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -136,6 +140,9 @@ export function useTextEditor(props: {
|
||||||
return { editor, upload }
|
return { editor, upload }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getImages = (data: DataTransfer | null) =>
|
||||||
|
Array.from(data?.files ?? []).filter((file) => file.type.startsWith('image'))
|
||||||
|
|
||||||
function isValidIframe(text: string) {
|
function isValidIframe(text: string) {
|
||||||
return /^<iframe.*<\/iframe>$/.test(text)
|
return /^<iframe.*<\/iframe>$/.test(text)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user