- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions. - Add Settings → Features and the features settings section. - Add features_legacy. It reads the old plugin packages and changes nothing. - Move Git from the plugin into src/lib/features/git/, on host internals. - Remove api.git, the git contribution key, and the SDK Git types. - Add pnpm check:features. It fails when a feature module loads at start. - Update the tests, the menu inventory, the docs, and UI-055.
52 lines
3.9 KiB
Svelte
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-bg-active); }
|
|
.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>
|