2024-01-08 22:06:44 +00:00
|
|
|
import { $el } from "../ui.js";
|
|
|
|
|
2024-06-25 10:49:25 +00:00
|
|
|
export class ComfyDialog extends EventTarget {
|
|
|
|
#buttons;
|
|
|
|
|
|
|
|
constructor(type = "div", buttons = null) {
|
|
|
|
super();
|
|
|
|
this.#buttons = buttons;
|
|
|
|
this.element = $el(type + ".comfy-modal", { parent: document.body }, [
|
2024-01-08 22:06:44 +00:00
|
|
|
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
createButtons() {
|
2024-06-25 10:49:25 +00:00
|
|
|
return (
|
|
|
|
this.#buttons ?? [
|
|
|
|
$el("button", {
|
|
|
|
type: "button",
|
|
|
|
textContent: "Close",
|
|
|
|
onclick: () => this.close(),
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
);
|
2024-01-08 22:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.element.style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
show(html) {
|
|
|
|
if (typeof html === "string") {
|
|
|
|
this.textElement.innerHTML = html;
|
|
|
|
} else {
|
2024-06-25 10:49:25 +00:00
|
|
|
this.textElement.replaceChildren(...(html instanceof Array ? html : [html]));
|
2024-01-08 22:06:44 +00:00
|
|
|
}
|
|
|
|
this.element.style.display = "flex";
|
|
|
|
}
|
|
|
|
}
|