Files
RuneStone/src/lib/plugins/PluginAccessMenu.svelte
T
Knotty Wyvern 9fc1490988 Make menus and hover fills translucent over a background image
With a background image, menus use the surface transparency of Appearance
(82% by default) instead of at least 92%, and they keep the blur.
Hovered rows and controls in the work area, hovered menu rows, and the
workspace button use the new --rs-hover-bg token. With an image, it is a
6% veil of the strong text color. The image stays visible, and the hover
shows over light and dark image areas. Without an image, nothing changes.

Silver Serpent dim text is now #c2c6cc. It keeps 4.5:1 contrast on a
hovered row over a white image.

UI-061 replaces the image rule of UI-043. Card 05b9bfa1.
2026-10-30 13:38:47 -07:00

52 lines
3.9 KiB
Svelte

<script lang="ts">
import { t } from "$lib/i18n";
import { untrack } from "svelte";
import Icon from "$lib/ui/Icon.svelte";
import { attachTooltip } from "$lib/ui/tooltip";
import ContextMenu from "$lib/layout/ContextMenu.svelte";
import type { MenuItem } from "$lib/layout/menuTypes";
import { installedPlugins, isBuiltInModule, pluginTools, pluginNavigation, openPluginView, runPluginCommand } from "./external";
import { featureOfOwner } from "$lib/features/catalog";
// `side` places the menu below the button (the header) or at its right (the left ribbon).
let { surface, compact = false, side = "bottom" }: { surface: "commands" | "open"; compact?: boolean; side?: "bottom" | "right" } = $props();
let anchor = $state<HTMLButtonElement>();
let position = $state<{ x: number; y: number } | null>(null);
let error = $state("");
let pointerWasOpen = false;
const label = $derived(surface === "open" ? $t("Plug-in views") : $t("Commands"));
function tooltip(node: HTMLElement) { return { destroy: attachTooltip(node, () => compact ? label : "") }; }
const tools = $derived($pluginTools.filter(tool => tool.surface === surface
&& !isBuiltInModule(tool.owner) && !featureOfOwner(tool.owner)
&& !(surface === "open" && tool.kind === "view" && $pluginNavigation.some(item => item.owner === tool.owner && item.id === tool.id && item.placement === "sidebar"))));
const signature = $derived(JSON.stringify([tools, $installedPlugins.plugins.map(row => [row.manifest.id, row.manifest.name])]));
const items: MenuItem[] = $derived.by(() => { void signature; return untrack(() => tools.map(tool => ({
kind: "action" as const,
label: `${tool.title} · ${$installedPlugins.plugins.find(row => row.manifest.id === tool.owner)?.manifest.name ?? tool.owner}`,
icon: tool.icon === "list" ? "bullet" as const : tool.icon ?? (tool.kind === "command" && surface === "commands" ? "code" as const : "plus" as const),
run: () => {
error = "";
if (tool.kind === "view") openPluginView(tool.owner, tool.id);
else void runPluginCommand(tool.owner, tool.id).catch(reason => error = String(reason));
},
}))); });
</script>
{#if tools.length}
<button class="access-button" class:compact class:ribbon={side === "right"} bind:this={anchor} use:tooltip aria-label={label} aria-haspopup="menu" aria-expanded={position !== null}
onpointerdown={() => pointerWasOpen = position !== null}
onclick={event => { const close = event.detail > 0 ? pointerWasOpen : position !== null; const bounds = anchor!.getBoundingClientRect(); position = close ? null : side === "right" ? { x: bounds.right + 4, y: bounds.top } : { x: bounds.left, y: bounds.bottom + 4 }; }}>
<Icon icon={surface === "open" ? "puzzle" : "code"} />{#if !compact}<span>{label}</span>{/if}
</button>
{/if}
{#if position && tools.length}<ContextMenu {...position} {items} {label} onClose={() => position = null} />{/if}
{#if error}<p class="error" role="alert">{error}<button onclick={() => error = ""}>{$t("Dismiss")}</button></p>{/if}
<style>
.access-button { display: flex; align-items: center; gap: 6px; white-space: nowrap; min-height: 32px; padding: 5px 8px; border: 0; border-radius: var(--rs-control-radius); background: transparent; color: var(--rs-text); }
.access-button:hover, .access-button[aria-expanded="true"] { background: var(--rs-hover-bg); }
.access-button:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: -2px; }
.access-button.compact { position: relative; width: 28px; height: 28px; min-height: 28px; padding: 5px; }
.access-button.ribbon { justify-content: center; width: 32px; height: 32px; min-height: 32px; padding: 0; }
.error { position: fixed; top: 48px; right: 12px; z-index: 60; max-width: 420px; padding: 12px; background: var(--rs-bg); color: var(--rs-error); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
</style>