import { $el } from "../../scripts/ui.js"; 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.text-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.p-dialog-mask.p-overlay-mask.p-overlay-mask-enter", { parent: document.body, style: { position: "fixed", height: "100%", width: "100%", left: "0px", top: "0px", display: "flex", justifyContent: "center", alignItems: "center", pointerEvents: "auto", zIndex: "1000" }, onclick: (e) => { if (e.target === dialog_mask) { owner.close(); } } // data-pc-section="mask" }); const header_actions = $el("div.p-dialog-header-actions", { // [TODO] // data-pc-section="headeractions" } ); const close_button = $el("button.p-button.p-component.p-button-icon-only.p-button-secondary.p-button-rounded.p-button-text.p-dialog-close-button", { parent: header_actions, type: "button", ariaLabel: "Close", onclick: () => owner.close(), // "data-pc-name": "pcclosebutton", // "data-p-disabled": "false", // "data-p-severity": "secondary", // "data-pc-group-section": "headericon", // "data-pc-extend": "button", // "data-pc-section": "root", // [FIXME] Not sure how to do most of the SVG using $el innerHTML: ' ' } ); const dialog_header = $el("div.p-dialog-header", [ $el("div", [ $el("div", { id: "cm-manager", }, [ $el("h2.px-4", [ $el(iconClass, { style: { "font-size": "1.25rem", "margin-right": ".5rem" } }), $el("span", { textContent: title }) ]) ] ) ]), header_actions ] ); const contentFrame = $el("div.p-dialog-content", {}, normalizeContent(content)); const manager_dialog = $el("div.p-dialog.p-component.global-dialog", { id: dialogId, parent: dialog_mask, style: { 'display': 'flex', 'flex-direction': 'column', 'pointer-events': 'auto', 'margin': '0px', }, role: 'dialog', ariaModal: 'true', // [TODO] // ariaLabbelledby: 'cm-title', // maximized: 'false', // data-pc-name: 'dialog', // data-pc-section: 'root', // data-pd-focustrap: 'true' }, [ dialog_header, contentFrame ] ); const hidden_accessible = $el("span.p-hidden-accessible.p-hidden-focusable", { parent: manager_dialog, tabindex: "0", role: "presentation", ariaHidden: "true", "data-p-hidden-accessible": "true", "data-p-hidden-focusable": "true", "data-pc-section": "firstfocusableelement" }); return dialog_mask; } export function buildGuiFrameCustomHeader(dialogId, customHeader, content, owner) { const dialog_mask = $el("div.p-dialog-mask.p-overlay-mask.p-overlay-mask-enter", { parent: document.body, style: { position: "fixed", height: "100%", width: "100%", left: "0px", top: "0px", display: "flex", justifyContent: "center", alignItems: "center", pointerEvents: "auto", zIndex: "1000" }, onclick: (e) => { if (e.target === dialog_mask) { owner.close(); } } // data-pc-section="mask" }); const header_actions = $el("div.p-dialog-header-actions", { // [TODO] // data-pc-section="headeractions" } ); const close_button = $el("button.p-button.p-component.p-button-icon-only.p-button-secondary.p-button-rounded.p-button-text.p-dialog-close-button", { parent: header_actions, type: "button", ariaLabel: "Close", onclick: () => owner.close(), // "data-pc-name": "pcclosebutton", // "data-p-disabled": "false", // "data-p-severity": "secondary", // "data-pc-group-section": "headericon", // "data-pc-extend": "button", // "data-pc-section": "root", // [FIXME] Not sure how to do most of the SVG using $el innerHTML: ' ' } ); const _customHeader = normalizeContent(customHeader); const dialog_header = $el("div.p-dialog-header", [ $el("div", [ $el("div", { id: "cm-manager", }, Array.isArray(_customHeader) ? _customHeader : [_customHeader] ) ]), header_actions ] ); const contentFrame = $el("div.p-dialog-content", {}, normalizeContent(content)); const manager_dialog = $el("div.p-dialog.p-component.global-dialog", { id: dialogId, parent: dialog_mask, style: { 'display': 'flex', 'flex-direction': 'column', 'pointer-events': 'auto', 'margin': '0px', }, role: 'dialog', ariaModal: 'true', // [TODO] // ariaLabbelledby: 'cm-title', // maximized: 'false', // data-pc-name: 'dialog', // data-pc-section: 'root', // data-pd-focustrap: 'true' }, [ dialog_header, contentFrame ] ); const hidden_accessible = $el("span.p-hidden-accessible.p-hidden-focusable", { parent: manager_dialog, tabindex: "0", role: "presentation", ariaHidden: "true", "data-p-hidden-accessible": "true", "data-p-hidden-focusable": "true", "data-pc-section": "firstfocusableelement" }); return dialog_mask; }