fix(editor): image paste handling

This commit is contained in:
kolaente 2023-11-21 13:23:05 +01:00
parent c3e53970de
commit f45303c2e3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 25 additions and 12 deletions

View File

@ -493,14 +493,20 @@ function setLink() {
onMounted(() => {
internalMode.value = initialMode
document.addEventListener('paste', handleImagePaste)
nextTick(() => {
const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0]
input.addEventListener('paste', handleImagePaste)
})
if (editShortcut !== '') {
document.addEventListener('keydown', setFocusToEditor)
}
})
onBeforeUnmount(() => {
document.removeEventListener('paste', handleImagePaste)
nextTick(() => {
const input = tiptapInstanceRef.value.querySelectorAll('.tiptap__editor')[0].children[0]
input.removeEventListener('paste', handleImagePaste)
})
if (editShortcut !== '') {
document.removeEventListener('keydown', setFocusToEditor)
}
@ -515,6 +521,7 @@ function handleImagePaste(event) {
const image = event.clipboardData.items[0]
if (image.kind === 'file' && image.type.startsWith('image/')) {
console.log('img', image.getAsFile())
uploadAndInsertFiles([image.getAsFile()])
}
}

View File

@ -218,13 +218,19 @@ const actions = computed(() => {
])))
})
function attachmentUpload(
file: File,
onSuccess: (url: string) => void,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onError: (error: string) => void,
) {
return uploadFile(props.taskId, file, onSuccess)
async function attachmentUpload(files: File[] | FileList): (Promise<string[]>) {
const uploadPromises: Promise<string>[] = []
files.forEach((file: File) => {
const promise = new Promise<string>((resolve) => {
uploadFile(props.taskId, file, (uploadedFileUrl: string) => resolve(uploadedFileUrl))
})
uploadPromises.push(promise)
})
return await Promise.all(uploadPromises)
}
const taskCommentService = shallowReactive(new TaskCommentService())