Add completion, browser integration, and workspace improvements

This commit is contained in:
Knotty Wyvern
2026-10-07 11:25:17 -07:00
parent dd9fc64676
commit a8b1defb9d
86 changed files with 3524 additions and 203 deletions
+25 -6
View File
@@ -1,22 +1,28 @@
<script lang="ts">
import PluginManager from "$lib/plugins/PluginManager.svelte";
import BrowserSlot from "$lib/plugins/BrowserSlot.svelte";
import PluginSettings from "$lib/plugins/PluginSettings.svelte";
import { installedPlugins, pluginTools } from "$lib/plugins/external";
import { pluginHost } from "$lib/plugins/registry";
import { onMount, untrack } from "svelte";
import Icon from "$lib/ui/Icon.svelte";
import IconButton, { type IconName } from "$lib/ui/IconButton.svelte";
import { DEFAULT_SETTINGS, MIN_AUTOSAVE_SECONDS, MAX_AUTOSAVE_SECONDS, validAutosaveSeconds, type AppSettings } from "$lib/workspace/settings";
import { version, license } from "../../../package.json";
let { settings, help = false, onSave, onClose }: {
let { settings, help = false, standalone = false, windowError = "", onSave, onClose }: {
settings: AppSettings;
help?: boolean;
standalone?: boolean;
windowError?: string;
onSave: (value: AppSettings) => void;
onClose: () => void;
} = $props();
type Section = "general" | "plugins" | "about";
type Section = string;
const sections: { id: Section; label: string; icon: IconName; keywords: string }[] = [
{ id: "about", label: "Help and about", icon: "help", keywords: "help about version shortcuts keyboard guide" },
{ id: "general", label: "General", icon: "settings", keywords: "auto-save autosave save interval seconds files" },
{ id: "plugins", label: "Plug-ins", icon: "puzzle", keywords: "plugins extensions community" },
{ id: "about", label: "Help and about", icon: "help", keywords: "help about version shortcuts keyboard guide" },
];
let section = $state<Section>(untrack(() => help ? "about" : "general"));
let query = $state("");
@@ -24,8 +30,15 @@
let message = $state("");
let error = $state("");
let dialog: HTMLDialogElement;
const matches = $derived(sections.filter(item => `${item.label} ${item.keywords}`.toLowerCase().includes(query.trim().toLowerCase())));
const browserEnabled = $derived.by(() => { void $pluginHost; return !!pluginHost.get("browser"); });
const pluginSections = $derived($pluginTools.filter(tool => tool.surface === "settings").map(tool => ({
id: `plugin:${tool.owner}:${tool.id}`, owner: tool.owner, view: tool.id,
label: tool.title, icon: "settings" as const,
keywords: `${$installedPlugins.plugins.find(row => row.manifest.id === tool.owner)?.manifest.name ?? tool.owner} settings configuration`,
})));
const matches = $derived([...sections, ...(browserEnabled ? [{ id: "browser" as const, label: "Browser", icon: "globe" as const, keywords: "browser profiles search cookies cache web privacy" }] : []), ...pluginSections].filter(item => `${item.label} ${item.keywords}`.toLowerCase().includes(query.trim().toLowerCase())));
const selected = $derived(matches.find(item => item.id === section) ?? matches[0]);
const selectedPlugin = $derived(pluginSections.find(item => item.id === selected?.id));
$effect(() => { seconds = settings.autosaveSeconds; });
onMount(() => {
@@ -54,7 +67,7 @@
function trapFocus(event: KeyboardEvent) {
if (event.target instanceof Element && event.target.closest("dialog") !== dialog) return;
if (event.key !== "Tab") return;
const controls = [...dialog.querySelectorAll<HTMLElement>("button:not(:disabled), input:not(:disabled), summary")]
const controls = [...dialog.querySelectorAll<HTMLElement>("button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), a[href], summary, [tabindex]:not([tabindex='-1'])")]
.filter(element => element.getClientRects().length > 0);
const first = controls[0], last = controls.at(-1);
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last?.focus(); }
@@ -62,7 +75,7 @@
}
</script>
<dialog bind:this={dialog} class:help aria-labelledby="settings-title" onkeydown={trapFocus} oncancel={event => { if (event.target === dialog) { event.preventDefault(); onClose(); } }}>
<dialog bind:this={dialog} class:help class:standalone aria-labelledby="settings-title" onkeydown={trapFocus} oncancel={event => { if (event.target === dialog) { event.preventDefault(); onClose(); } }}>
<header>
<h1 id="settings-title">{help ? "Help and about" : "Settings"}</h1>
<IconButton icon="close" label={help ? "Close help" : "Close settings"} onclick={onClose} />
@@ -81,6 +94,7 @@
</aside>
{/if}
<div class="content">
{#if windowError}<p class="error" role="alert">{windowError}</p>{/if}
{#if !selected}
<h2>No settings found</h2>
<p>Try “save”, “plug-ins”, or “help”.</p>
@@ -105,6 +119,10 @@
<p class="saved" role="status">{message}</p>
{:else if selected.id === "plugins"}
<PluginManager />
{:else if selected.id === "browser"}
<BrowserSlot kind="settings" />
{:else if selectedPlugin}
{#key selectedPlugin.id}<PluginSettings owner={selectedPlugin.owner} id={selectedPlugin.view} />{/key}
{:else}
<div class="brand"><img src="/runestone.svg" alt="" width="88" height="88" /><h2>RuneStone</h2><p>Version {version}</p></div>
<div class="card help-card">
@@ -121,6 +139,7 @@
<style>
dialog { width: min(920px, calc(100vw - 32px)); height: min(650px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; background: var(--rs-bg); color: var(--rs-text); border: 1px solid var(--rs-border); border-radius: 12px; box-shadow: 0 24px 80px #0008; overflow: hidden; }
dialog::backdrop { background: #0008; }
dialog.standalone { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
dialog.help { width: min(650px, calc(100vw - 32px)); }
header { height: 48px; padding: 0 14px 0 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rs-border); background: var(--rs-bg-elevated); }
h1 { font-size: 14px; font-weight: 600; margin: 0; }