Update editor, workspace, Git services, appearance, and project guides

This commit is contained in:
Knotty Wyvern
2026-10-11 09:41:16 -07:00
parent a8b1defb9d
commit 909894b9c8
153 changed files with 7967 additions and 775 deletions
+18 -13
View File
@@ -1,21 +1,24 @@
import { actionIcon, type ActionIcon } from "./actionIcons";
export type ActionMenuItem = { label: string; icon?: ActionIcon; shortcut?: string; run?: () => void; children?: ActionMenuItem[]; disabled?: boolean; title?: string } | { separator: true };
export type ActionMenuItem = { label: string; icon?: ActionIcon; shortcut?: string; run?: () => void; children?: ActionMenuItem[]; disabled?: boolean; checked?: boolean; radio?: boolean; title?: string } | { separator: true };
export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClose: () => void, label = "Table actions") {
export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClose: () => void, label = "Table actions", parent: HTMLElement = document.body) {
const root = document.createElement("div"); root.className = "rs-menu table-cell-menu"; root.setAttribute("role", "menu"); root.setAttribute("aria-label", label);
let opened: HTMLElement | undefined, owner: HTMLButtonElement | undefined;
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 hideSubmenu() { if (opened) opened.hidden = true; owner?.setAttribute("aria-expanded", "false"); opened = undefined; owner = undefined; }
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"); }
}
function positionSubmenu(button: HTMLButtonElement, panel: HTMLElement) {
const rect = button.getBoundingClientRect(), size = panel.getBoundingClientRect(), main = root.getBoundingClientRect();
const rect = button.getBoundingClientRect(), size = panel.getBoundingClientRect(), main = button.parentElement!.getBoundingClientRect();
panel.style.left = `${Math.max(8, main.right + size.width < innerWidth - 8 ? main.right - 2 : main.left - size.width + 2)}px`;
panel.style.top = `${Math.max(8, Math.min(rect.top - 5, innerHeight - size.height - 8))}px`;
}
function reveal(button: HTMLButtonElement, panel: HTMLElement, focus = false) {
if (opened !== panel) hideSubmenu();
opened = panel; owner = button; panel.hidden = false; button.setAttribute("aria-expanded", "true");
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 });
}
@@ -23,9 +26,10 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
for (const item of entries) {
if ("separator" in item) { const hr = document.createElement("hr"); hr.setAttribute("role", "separator"); panel.append(hr); continue; }
const button = document.createElement("button"); button.type = "button"; button.setAttribute("role", "menuitem"); button.disabled = !!item.disabled;
if (item.checked !== undefined) { button.setAttribute("role", item.radio ? "menuitemradio" : "menuitemcheckbox"); button.setAttribute("aria-checked", String(item.checked)); }
if (item.title) button.title = item.title;
const label = document.createElement("span"); label.className = "action-label"; label.textContent = item.label;
const icon = item.icon ? actionIcon(item.icon) : document.createElement("span");
const icon = item.checked ? actionIcon("task") : item.icon ? actionIcon(item.icon) : document.createElement("span");
icon.classList.add("action-icon"); icon.setAttribute("aria-hidden", "true");
button.append(icon, label); panel.append(button);
if (item.shortcut) { const shortcut = document.createElement("span"); shortcut.textContent = item.shortcut; shortcut.style.cssText = "margin-left:auto;color:var(--rs-text-dim);font-size:12px;white-space:nowrap"; button.append(shortcut); }
@@ -37,7 +41,7 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
button.addEventListener("mousemove", () => { if (!button.disabled) reveal(button, submenu); });
button.addEventListener("click", () => reveal(button, submenu, true));
} else {
if (panel === root) button.addEventListener("mousemove", hideSubmenu);
button.addEventListener("mousemove", () => hideSubmenu(panel));
button.addEventListener("click", event => { event.stopPropagation(); item.run?.(); });
}
}
@@ -46,7 +50,7 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
root.addEventListener("mousedown", event => { event.preventDefault(); event.stopPropagation(); });
root.addEventListener("focusin", event => {
const button = event.target as HTMLElement;
if (button.parentElement === root && button !== owner) hideSubmenu();
if (!opened.some(entry => entry.button === button) && button.parentElement) hideSubmenu(button.parentElement);
});
root.addEventListener("keydown", event => {
event.stopPropagation();
@@ -57,10 +61,11 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos
event.preventDefault(); buttons[event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length]?.focus();
}
if (event.key === "ArrowRight" && submenus.has(focused)) { event.preventDefault(); reveal(focused, submenus.get(focused)!, true); }
if (event.key === "ArrowLeft" && opened?.contains(focused)) { event.preventDefault(); const previous = owner; hideSubmenu(); previous?.focus(); }
const entry = opened.find(entry => entry.panel === panel);
if (event.key === "ArrowLeft" && entry) { event.preventDefault(); hideSubmenu(entry.button.parentElement!); entry.button.focus(); }
});
root.addEventListener("scroll", event => { if (event.target === root && opened && owner) positionSubmenu(owner, opened); });
document.body.append(root);
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:not(:disabled)")?.focus();