mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 08:30:06 +00:00
ComfyDialog: - Type constructor buttons parameter as HTMLButtonElement[] | null - Type show method parameter as string | HTMLElement | HTMLElement[] - Use definite assignment for textElement ComfyAsyncDialog: - Make class generic with DialogAction<T> type - Type resolve function, show/showModal return types - Fix button creation with proper HTMLButtonElement cast - Add generic static prompt method ManageGroupDialog: - Update show method signature to match base class - Extract nodeType from parameter for string comparisons
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { $el } from '../ui'
|
|
|
|
export class ComfyDialog<
|
|
T extends HTMLElement = HTMLElement
|
|
> extends EventTarget {
|
|
element: T
|
|
textElement!: HTMLElement
|
|
#buttons: HTMLButtonElement[] | null
|
|
|
|
constructor(type = 'div', buttons: HTMLButtonElement[] | null = null) {
|
|
super()
|
|
this.#buttons = buttons
|
|
this.element = $el(type + '.comfy-modal', { parent: document.body }, [
|
|
$el('div.comfy-modal-content', [
|
|
$el('p', { $: (p) => (this.textElement = p) }),
|
|
...this.createButtons()
|
|
])
|
|
]) as T
|
|
}
|
|
|
|
createButtons() {
|
|
return (
|
|
this.#buttons ?? [
|
|
$el('button', {
|
|
type: 'button',
|
|
textContent: 'Close',
|
|
onclick: () => this.close()
|
|
})
|
|
]
|
|
)
|
|
}
|
|
|
|
close() {
|
|
this.element.style.display = 'none'
|
|
}
|
|
|
|
show(html: string | HTMLElement | HTMLElement[]): void {
|
|
if (typeof html === 'string') {
|
|
this.textElement.innerHTML = html
|
|
} else {
|
|
this.textElement.replaceChildren(
|
|
...(html instanceof Array ? html : [html])
|
|
)
|
|
}
|
|
this.element.style.display = 'flex'
|
|
}
|
|
}
|