ui(client): add insertHtml for MduiPatchedTextArea

This commit is contained in:
CrescentLeaf
2026-01-24 00:11:19 +08:00
parent 01ece27e75
commit 9e3c1c554f
2 changed files with 10 additions and 1 deletions

3
client/env.d.ts vendored
View File

@@ -6,8 +6,9 @@ declare global {
namespace React {
namespace JSX {
interface IntrinsicElements {
'input-element': {
'mdui-patched-textarea': {
'value'?: string
insertHtml: (html: string) => void
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>
}
}

View File

@@ -60,6 +60,9 @@ export default class MduiPatchedTextAreaElement extends HTMLElement {
this._lastValue = this.value || ''
this.dispatchEvent(new Event('change', { bubbles: true }))
}
// 消除 <br> 对 placeholder 的影响
if (this.value == '')
this.value = ''
})
this.inputDiv.addEventListener('paste', (e: ClipboardEvent) => {
e.preventDefault()
@@ -101,6 +104,11 @@ export default class MduiPatchedTextAreaElement extends HTMLElement {
set value(v) {
this.inputDiv && (this.inputDiv.textContent = v)
}
insertHtml(html: string) {
this.inputDiv?.focus()
document.execCommand('insertHTML', false, html)
}
}
customElements.define('mdui-patched-textarea', MduiPatchedTextAreaElement)