Update node content if only pasting a file
This commit is contained in:
parent
7bad7a5ce8
commit
88304b90a4
1 changed files with 6 additions and 17 deletions
|
|
@ -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 { CustomHTMLElement } from './lib/custom_html_element.mjs'
|
||||||
import { MarkedPosition } from './marked_position.mjs'
|
import { MarkedPosition } from './marked_position.mjs'
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ export class N2PageNodeUI extends CustomHTMLElement {
|
||||||
return this.classList.contains('show-markdown')
|
return this.classList.contains('show-markdown')
|
||||||
}
|
}
|
||||||
}// }}}
|
}// }}}
|
||||||
async pasteHandler(event) {
|
async pasteHandler(event) {// {{{
|
||||||
const clipboardItems = event.clipboardData?.items
|
const clipboardItems = event.clipboardData?.items
|
||||||
if (!clipboardItems)
|
if (!clipboardItems)
|
||||||
return
|
return
|
||||||
|
|
@ -139,27 +139,16 @@ export class N2PageNodeUI extends CustomHTMLElement {
|
||||||
const [start, end] = [this.elNodeContent.selectionStart, this.elNodeContent.selectionEnd]
|
const [start, end] = [this.elNodeContent.selectionStart, this.elNodeContent.selectionEnd]
|
||||||
this.elNodeContent.setRangeText(``, start, end, 'select');
|
this.elNodeContent.setRangeText(``, 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
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
alert(`Unknown paste type of '${item.kind}'`)
|
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) {// {{{
|
editMarkdown(data) {// {{{
|
||||||
this.showMarkdown(false)
|
this.showMarkdown(false)
|
||||||
this.elNodeContent.selectionStart = data.position.start
|
this.elNodeContent.selectionStart = data.position.start
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue