Allow pasting files in comments

This commit is contained in:
Jason Zimdars
2025-01-31 18:07:12 -06:00
parent c83a6e7e34
commit 6f351b956c
2 changed files with 27 additions and 1 deletions
@@ -11,6 +11,31 @@ export default class extends Controller {
this.cancelTarget?.click()
}
pasteFiles(event) {
const editor = event.target.closest("house-md")
if (!editor) return
const files = event.clipboardData?.files
if (!files?.length) return
event.preventDefault()
for (const file of files) {
const uploadEvent = new CustomEvent("house-md:before-upload", {
bubbles: true,
detail: { file },
cancelable: true
})
if (editor.dispatchEvent(uploadEvent)) {
const upload = document.createElement("house-md-upload")
upload.file = file
upload.uploadsURL = editor.dataset.uploadsUrl
editor.appendChild(upload)
}
}
}
preventAttachment(event) {
event.preventDefault()
}