ui(client): add insertHtml for MduiPatchedTextArea
This commit is contained in:
3
client/env.d.ts
vendored
3
client/env.d.ts
vendored
@@ -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>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user