Update editor, workspace, Git services, appearance, and project guides
This commit is contained in:
@@ -5,7 +5,11 @@
|
||||
</script>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
{#if icon === "settings"}
|
||||
<path d="m9 3-1 3-3 1-2 3 2 2v3l3 2 1 4h5l1-3 3-1 3-4-2-2V8l-3-2-1-3Z" /><circle cx="12" cy="12" r="3" />
|
||||
<path d="M9.5 6 10 3 14 3 14.5 6 15.95 6.83 18.79 5.77 20.79 9.23 18.45 11.17 18.45 12.83 20.79 14.77 18.79 18.23 15.95 17.17 14.5 18 14 21 10 21 9.5 18 8.05 17.17 5.21 18.23 3.21 14.77 5.55 12.83 5.55 11.17 3.21 9.23 5.21 5.77 8.05 6.83Z" /><circle cx="12" cy="12" r="3" />
|
||||
{:else if icon === "sun"}
|
||||
<circle cx="12" cy="12" r="4" /><path d="M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.5 1.5m11 11L19 19M5 19l1.5-1.5m11-11L19 5" />
|
||||
{:else if icon === "git"}
|
||||
{@html actionIcons.git}
|
||||
{:else if icon === "globe"}
|
||||
<circle cx="12" cy="12" r="9" /><ellipse cx="12" cy="12" rx="4" ry="9" /><path d="M3 12h18" />
|
||||
{:else if icon === "arrow-left"}
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
import Icon from "./Icon.svelte";
|
||||
export type IconName =
|
||||
| "globe"
|
||||
| "git"
|
||||
| "arrow-left"
|
||||
| "arrow-right"
|
||||
| "copy"
|
||||
| "stop"
|
||||
| "settings"
|
||||
| "sun"
|
||||
| "help"
|
||||
| "puzzle"
|
||||
| "link"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy, tick } from "svelte";
|
||||
import { tick } from "svelte";
|
||||
import Icon from "./Icon.svelte";
|
||||
import type { IconName } from "./IconButton.svelte";
|
||||
|
||||
@@ -17,19 +17,13 @@
|
||||
let hovered = false;
|
||||
let keyboardFocus = false;
|
||||
let group: HTMLDivElement;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const expansionDelay = 1500;
|
||||
const selected = $derived(Math.max(0, options.findIndex(option => option.value === value)));
|
||||
|
||||
function scheduleExpansion() {
|
||||
clearTimeout(timer);
|
||||
if (!expanded && (hovered || keyboardFocus)) {
|
||||
timer = setTimeout(() => { expanded = true; }, expansionDelay);
|
||||
}
|
||||
if (hovered || keyboardFocus) expanded = true;
|
||||
}
|
||||
|
||||
function collapse() {
|
||||
clearTimeout(timer);
|
||||
expanded = false;
|
||||
}
|
||||
|
||||
@@ -39,7 +33,6 @@
|
||||
}
|
||||
|
||||
async function choose(index: number) {
|
||||
// Cycling should leave a full pause before the targets start moving.
|
||||
scheduleExpansion();
|
||||
const hadFocus = group.contains(document.activeElement);
|
||||
onchange(options[index].value);
|
||||
@@ -50,7 +43,6 @@
|
||||
|
||||
function keydown(event: KeyboardEvent) {
|
||||
keyboardFocus = true;
|
||||
if (event.key === "Enter" || event.key === " ") clearTimeout(timer);
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -59,7 +51,6 @@
|
||||
group.querySelector<HTMLButtonElement>(`[data-value="${value}"]`)?.focus();
|
||||
} else if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
clearTimeout(timer);
|
||||
expanded = true;
|
||||
const index = event.key === "Home" ? 0 : event.key === "End" ? options.length - 1
|
||||
: (selected + (event.key === "ArrowRight" ? 1 : -1) + options.length) % options.length;
|
||||
@@ -67,7 +58,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(() => clearTimeout(timer));
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -107,7 +97,7 @@
|
||||
tabindex={expanded || option.value === value ? 0 : -1}
|
||||
onmouseenter={() => { tooltipDismissed = false; }}
|
||||
onfocus={() => { tooltipDismissed = false; }}
|
||||
onpointerdown={() => { keyboardFocus = false; clearTimeout(timer); }}
|
||||
onpointerdown={() => { keyboardFocus = false; }}
|
||||
onpointerup={scheduleExpansion}
|
||||
onpointercancel={scheduleExpansion}
|
||||
onkeydown={keydown}
|
||||
@@ -127,15 +117,14 @@
|
||||
flex: 0 0 auto;
|
||||
width: calc(var(--segment) * var(--count) + 6px);
|
||||
height: 34px;
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: 8px;
|
||||
transition: width 180ms ease;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--rs-control-radius);
|
||||
}
|
||||
.selection {
|
||||
position: absolute;
|
||||
inset: 2px auto 2px 2px;
|
||||
width: var(--segment);
|
||||
border-radius: 5px;
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: var(--rs-bg-active);
|
||||
transform: translateX(calc(var(--selected) * var(--segment)));
|
||||
transition: transform 180ms ease;
|
||||
@@ -152,14 +141,14 @@
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: transparent;
|
||||
color: var(--rs-text-dim);
|
||||
font-size: 12px;
|
||||
transform: translateX(calc(var(--index) * var(--segment)));
|
||||
transition: transform 180ms ease, opacity 120ms ease;
|
||||
transition: opacity 120ms ease;
|
||||
}
|
||||
button.current { color: var(--rs-accent); }
|
||||
button.current { color: var(--rs-text-strong); }
|
||||
button:hover { color: var(--rs-text-strong); }
|
||||
button.concealed { visibility: hidden; opacity: 0; pointer-events: none; }
|
||||
button:hover, button:focus-visible { z-index: 1; }
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
flex-basis: 40px;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
border-radius: var(--rs-control-radius);
|
||||
}
|
||||
.window-close :global(.icon-btn:hover) { background: #c42b1c; color: white; }
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// Stroke icons share the same 24px grid and weight as IconButton.
|
||||
export const actionIcons = {
|
||||
terminal: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m6 8 4 4-4 4m6 0h6"/>',
|
||||
undo: '<path d="M3 10h11a7 7 0 0 1 0 14" transform="translate(0 -4)"/><path d="m7 2-4 4 4 4"/>',
|
||||
redo: '<path d="M21 6H10a7 7 0 0 0 0 14"/><path d="m17 2 4 4-4 4"/>',
|
||||
git: '<circle cx="7" cy="5" r="2"/><circle cx="7" cy="19" r="2"/><circle cx="17" cy="6" r="2"/><path d="M7 7v10m0-5h4a6 6 0 0 0 6-6"/>',
|
||||
globe: '<circle cx="12" cy="12" r="9"/><ellipse cx="12" cy="12" rx="4" ry="9"/><path d="M3 12h18"/>',
|
||||
puzzle: '<path d="M9 3H4v6a3 3 0 1 1 0 6v5h6a3 3 0 1 1 6 0h4v-6a3 3 0 1 0 0-6V3h-5a3 3 0 1 1-6 0Z"/>',
|
||||
'split-right': '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M12 4v16m3-11 3 3-3 3"/>',
|
||||
|
||||
+18
-13
@@ -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();
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
background: var(--rs-bg-elevated);
|
||||
color: var(--rs-text);
|
||||
box-shadow: var(--rs-menu-shadow);
|
||||
font: 13px/1.4 var(--rs-font-ui);
|
||||
font: var(--rs-menu-font-size)/1.4 var(--rs-font-ui);
|
||||
}
|
||||
|
||||
.rs-menu.table-cell-submenu { z-index: 1001; }
|
||||
|
||||
Reference in New Issue
Block a user