import { $el } from "../../scripts/ui.js";
import { loadCss } from "./common.js";
loadCss("./comfyui-gui-builder.css");
function normalizeContent(content) {
const tmp = document.createElement('div');
if (typeof content === 'string') {
tmp.innerHTML = content;
return Array.from(tmp.childNodes);
}
if (content instanceof Node) {
return content;
}
return content;
}
export function createSettingsCombo(label, content) {
const settingItem = $el("div.setting-item", {}, [
$el("div.flex.flex-row.items-center.gap-2",[
$el("div.form-label.flex.grow.items-center", [
$el("span.cm-ui-muted", { textContent: label },)
]),
$el("div.form-input.flex.justify-end",
[content]
)
]
)
]);
return settingItem;
}
export function buildGuiFrame(dialogId, title, iconClass, content, owner) {
const dialog_mask = $el("div.cm-ui-overlay.fixed.inset-0.flex.items-center.justify-center", {
parent: document.body,
onclick: (e) => {
if (e.target === dialog_mask) {
owner.close();
}
}
});
const header_actions = $el("div.flex.items-center");
$el("button.cm-ui-button.cm-ui-close", {
parent: header_actions,
type: "button",
ariaLabel: "Close",
onclick: () => owner.close(),
innerHTML: ''
}
);
const dialog_header = $el("div.cm-ui-header.flex.items-center.justify-between.gap-2",
[
$el("div", [
$el("div",
{
id: "frame-title-container",
},
[
$el("h2.px-4", [
$el(iconClass, {
style: {
"font-size": "1.25rem",
"margin-right": ".5rem"
}
}),
$el("span", { textContent: title })
])
]
)
]),
header_actions
]
);
const contentFrame = $el("div.cm-ui-content.min-h-0", {}, normalizeContent(content));
$el("div.cm-ui-dialog.global-dialog.flex.flex-col", {
id: dialogId,
parent: dialog_mask,
style: {
'display': 'flex',
'flex-direction': 'column',
'pointer-events': 'auto',
'margin': '0px',
},
role: 'dialog',
ariaModal: 'true',
},
[ dialog_header, contentFrame ]
);
return dialog_mask;
}
export function buildGuiFrameCustomHeader(dialogId, customHeader, content, owner) {
const dialog_mask = $el("div.cm-ui-overlay.fixed.inset-0.flex.items-center.justify-center", {
parent: document.body,
onclick: (e) => {
if (e.target === dialog_mask) {
owner.close();
}
}
});
const header_actions = $el("div.flex.items-center");
$el("button.cm-ui-button.cm-ui-close", {
parent: header_actions,
type: "button",
ariaLabel: "Close",
onclick: () => owner.close(),
innerHTML: ''
}
);
const _customHeader = normalizeContent(customHeader);
const dialog_header = $el("div.cm-ui-header.flex.items-center.justify-between.gap-2",
[
$el("div", [
$el("div",
{
id: "frame-title-container",
},
Array.isArray(_customHeader) ? _customHeader : [_customHeader]
)
]),
header_actions
]
);
const contentFrame = $el("div.cm-ui-content.min-h-0", {}, normalizeContent(content));
$el("div.cm-ui-dialog.global-dialog.flex.flex-col", {
id: dialogId,
parent: dialog_mask,
style: {
'display': 'flex',
'flex-direction': 'column',
'pointer-events': 'auto',
'margin': '0px',
},
role: 'dialog',
ariaModal: 'true',
},
[ dialog_header, contentFrame ]
);
return dialog_mask;
}