Update node content if only pasting a file

This commit is contained in:
Magnus Åhall 2026-06-01 16:28:51 +02:00
parent 7bad7a5ce8
commit 88304b90a4

View file

@ -1,4 +1,4 @@
import { ROOT_NODE, uuidv7, StoreFile } from 'node_store'
import { ROOT_NODE, uuidv7 } from 'node_store'
import { CustomHTMLElement } from './lib/custom_html_element.mjs'
import { MarkedPosition } from './marked_position.mjs'
@ -119,7 +119,7 @@ export class N2PageNodeUI extends CustomHTMLElement {
return this.classList.contains('show-markdown')
}
}// }}}
async pasteHandler(event) {
async pasteHandler(event) {// {{{
const clipboardItems = event.clipboardData?.items
if (!clipboardItems)
return
@ -139,27 +139,16 @@ export class N2PageNodeUI extends CustomHTMLElement {
const [start, end] = [this.elNodeContent.selectionStart, this.elNodeContent.selectionEnd]
this.elNodeContent.setRangeText(`![${file.name}](db://${uuid})`, start, end, 'select');
// Editing the textarea programatically doesn't generate the events it usually gets when edited interactively.
this.node.setContent(this.elNodeContent.value)
break
default:
alert(`Unknown paste type of '${item.kind}'`)
}
}
}
// Example usage: Displaying the image or preparing it for upload
handleImageBlob(blob) {
// 1. Create a local URL to preview it in an <img> tag if needed
const localUrl = URL.createObjectURL(blob)
console.log('Local preview URL:', localUrl)
// 2. Or prepare it for a FormData upload
const formData = new FormData()
formData.append('image', blob, 'pasted-image.png')
// fetch('/upload', { method: 'POST', body: formData })
}
}// }}}
editMarkdown(data) {// {{{
this.showMarkdown(false)
this.elNodeContent.selectionStart = data.position.start