Update editor, themes, menus, backgrounds, and release tooling
This commit is contained in:
@@ -7,6 +7,14 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
|
||||
const opened: { button: HTMLButtonElement; panel: HTMLElement }[] = [];
|
||||
if (label.startsWith("Terminal")) root.style.width = "min(430px, calc(100vw - 16px))";
|
||||
const submenus = new Map<HTMLButtonElement, HTMLElement>();
|
||||
function focusRow(button?: HTMLButtonElement) {
|
||||
if (!button) return;
|
||||
button.focus({ preventScroll: true });
|
||||
const panel = button.parentElement!;
|
||||
const row = button.getBoundingClientRect(), bounds = panel.getBoundingClientRect();
|
||||
if (row.top < bounds.top) panel.scrollTop -= bounds.top - row.top;
|
||||
else if (row.bottom > bounds.bottom) panel.scrollTop += row.bottom - bounds.bottom;
|
||||
}
|
||||
function hideSubmenu(parent: HTMLElement = root) {
|
||||
const keep = parent === root ? 0 : opened.findIndex(entry => entry.panel === parent) + 1;
|
||||
for (const { button, panel } of opened.splice(keep)) { panel.hidden = true; button.setAttribute("aria-expanded", "false"); }
|
||||
@@ -20,7 +28,7 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
|
||||
if (!opened.some(entry => entry.panel === panel)) { hideSubmenu(button.parentElement!); opened.push({ button, panel }); }
|
||||
panel.hidden = false; button.setAttribute("aria-expanded", "true");
|
||||
positionSubmenu(button, panel);
|
||||
if (focus) panel.querySelector<HTMLButtonElement>("button:not(:disabled)")?.focus({ preventScroll: true });
|
||||
if (focus) focusRow(panel.querySelector<HTMLButtonElement>("button:not(:disabled)") ?? undefined);
|
||||
}
|
||||
function populate(panel: HTMLElement, entries: ActionMenuItem[]) {
|
||||
const hasIcons = entries.some(item => !("separator" in item) && (!!item.icon || (item.checked !== undefined && !item.radio)));
|
||||
@@ -64,17 +72,17 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
|
||||
const focused = document.activeElement as HTMLButtonElement, panel = focused.parentElement || root;
|
||||
const buttons = [...panel.querySelectorAll<HTMLButtonElement>(":scope > button:not(:disabled)")], index = buttons.indexOf(focused);
|
||||
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
|
||||
event.preventDefault(); buttons[event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length]?.focus();
|
||||
event.preventDefault(); focusRow(buttons[event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length]);
|
||||
}
|
||||
if (event.key === "ArrowRight" && submenus.has(focused)) { event.preventDefault(); reveal(focused, submenus.get(focused)!, true); }
|
||||
const entry = opened.find(entry => entry.panel === panel);
|
||||
if (event.key === "ArrowLeft" && entry) { event.preventDefault(); hideSubmenu(entry.button.parentElement!); entry.button.focus(); }
|
||||
if (event.key === "ArrowLeft" && entry) { event.preventDefault(); hideSubmenu(entry.button.parentElement!); focusRow(entry.button); }
|
||||
});
|
||||
root.addEventListener("scroll", () => { for (const { button, panel } of opened) positionSubmenu(button, panel); }, true);
|
||||
parent.append(root);
|
||||
root.style.left = `${Math.max(8, Math.min(x, innerWidth - root.offsetWidth - 8))}px`;
|
||||
root.style.top = `${Math.max(8, Math.min(y, innerHeight - root.offsetHeight - 8))}px`;
|
||||
(root.querySelector<HTMLButtonElement>(':scope > button[role="menuitemradio"][aria-checked="true"]:not(:disabled)')
|
||||
?? root.querySelector<HTMLButtonElement>(":scope > button:not(:disabled)"))?.focus();
|
||||
?? root.querySelector<HTMLButtonElement>(":scope > button:not(:disabled)"))?.focus({ preventScroll: true });
|
||||
return root;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user