The formula engine, the rendered results, and the formula help now come from src/lib/formulas/. The editor and the renderer call this module directly. The tableFormulas contribution type is removed. - Add the tableFormulas general setting (default on) and a switch in Settings > General. When it is off, formulas show as source text. - Do not load an installed runestone.table-formulas package. Settings > Plug-ins marks it as included with RuneStone and tells the user that it can be removed. The user's files stay in place. - Translate the formula help and the error descriptions into French, Japanese, and Simplified Chinese. - Port the plugin unit tests. Test the setting and use a test-only contribution for the generic plugin lifecycle tests. - Smoke tests load only Terminal. The formula and lifecycle tests use the built-in feature and its setting. - Remove scripts/buildPlugins.mjs, the build:plugins script, and the plugin-packages requirement of the smoke runner. - Remove RuneStone_Table_Formulas from the menu audit scope. It had no menu surfaces. - Update the README, the user guides, and the developer references.
248 lines
19 KiB
Svelte
248 lines
19 KiB
Svelte
<script lang="ts">
|
||
import { t, locale, LANGUAGES, setLocale } from "$lib/i18n";
|
||
import { showActionMenu } from "$lib/ui/managedActionMenu";
|
||
import { onDestroy } from "svelte";
|
||
import PluginManager from "$lib/plugins/PluginManager.svelte";
|
||
import AppearanceSettings from "$lib/theme/AppearanceSettings.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, type Snippet } 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 { license } from "../../../package.json";
|
||
import { appVersion as version } from "../appVersion";
|
||
|
||
let { settings, help = false, standalone = false, windowError = "", windowControls, onSave, onClose }: {
|
||
settings: AppSettings;
|
||
help?: boolean;
|
||
standalone?: boolean;
|
||
windowError?: string;
|
||
windowControls?: Snippet;
|
||
onSave: (value: AppSettings) => void | Promise<void>;
|
||
onClose: () => void;
|
||
} = $props();
|
||
let closeLanguage = () => {};
|
||
onDestroy(() => closeLanguage());
|
||
function languagePicker(event: MouseEvent) {
|
||
closeLanguage();
|
||
const anchor = event.currentTarget as HTMLButtonElement;
|
||
const bounds = anchor.getBoundingClientRect();
|
||
closeLanguage = showActionMenu({ x: bounds.left, y: bounds.bottom + 4, label: $t("Language"), parent: dialog,
|
||
items: LANGUAGES.map(item => ({ label: item.name, radio: true, checked: $locale === item.id,
|
||
run: () => {
|
||
const failed = () => { error = $t("Could not save language settings."); message = ""; };
|
||
try { setLocale(item.id).catch(failed); error = ""; message = $t("Changes saved."); } catch { failed(); }
|
||
} })) }).close;
|
||
}
|
||
type Section = string;
|
||
const sections: { id: Section; label: string; icon: IconName; keywords: string }[] = $derived([
|
||
{ id: "about", label: $t("Help and about"), icon: "help", keywords: "help about version shortcuts keyboard guide" },
|
||
{ id: "general", label: $t("General"), icon: "settings", keywords: "auto-save autosave save interval seconds files language français 日本語 简体中文 tables table formulas calculate" },
|
||
{ id: "appearance", label: $t("Appearance"), icon: "sun", keywords: "theme colors light dark Claude Sakura Harvest Moon Crimson Pilot Silver Serpent" },
|
||
{ id: "plugins", label: $t("Plug-ins"), icon: "puzzle", keywords: "plugins extensions community" },
|
||
]);
|
||
let section = $state<Section>(untrack(() => help ? "about" : "general"));
|
||
let query = $state("");
|
||
let seconds = $state<number | undefined>(untrack(() => settings.autosaveSeconds));
|
||
let message = $state("");
|
||
let error = $state("");
|
||
let dialog: HTMLDialogElement;
|
||
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: $t("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(() => {
|
||
const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||
dialog.showModal();
|
||
return () => { dialog.close(); previous?.focus(); };
|
||
});
|
||
|
||
function apply(value: AppSettings) {
|
||
error = "";
|
||
const failed = () => { error = $t("Could not save these settings. Your previous settings still apply. Try again."); message = ""; };
|
||
try { Promise.resolve(onSave(value)).catch(failed); message = $t("Changes saved."); }
|
||
catch { failed(); }
|
||
}
|
||
|
||
function changeInterval() {
|
||
if (!validAutosaveSeconds(seconds)) {
|
||
error = $t("Choose a whole number from 1 to 300 seconds.");
|
||
message = "";
|
||
return;
|
||
}
|
||
apply({ ...settings, autosaveSeconds: seconds });
|
||
}
|
||
|
||
function select(next: Section) { section = next; error = ""; message = ""; seconds = settings.autosaveSeconds; }
|
||
|
||
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), 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(); }
|
||
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus(); }
|
||
}
|
||
</script>
|
||
|
||
<dialog bind:this={dialog} class:help class:standalone aria-labelledby="settings-title" onkeydown={trapFocus} oncancel={event => { if (event.target === dialog) { event.preventDefault(); onClose(); } }}>
|
||
<header class:window-header={!!windowControls} data-tauri-drag-region={windowControls ? true : undefined}>
|
||
<h1 id="settings-title" data-tauri-drag-region={windowControls ? true : undefined}>{help ? $t("Help and about") : $t("Settings")}</h1>
|
||
{#if windowControls}
|
||
{@render windowControls()}
|
||
{:else}
|
||
<IconButton icon="close" label={help ? $t("Close help") : $t("Close settings")} onclick={onClose} />
|
||
{/if}
|
||
</header>
|
||
<div class="body">
|
||
{#if !help}
|
||
<aside>
|
||
<label class="search"><Icon icon="search" /><input aria-label={$t("Search settings")} placeholder={$t("Search settings…")} bind:value={query} /></label>
|
||
<p class="nav-heading">{$t("Preferences")}</p>
|
||
<nav aria-label={$t("Settings categories")}>
|
||
{#each matches as item}
|
||
<button class:active={selected?.id === item.id} aria-current={selected?.id === item.id ? "page" : undefined} onclick={() => select(item.id)}><Icon icon={item.icon} />{item.label}</button>
|
||
{/each}
|
||
</nav>
|
||
<p class="scope">{$t("For all workspaces on this device.")}</p>
|
||
</aside>
|
||
{/if}
|
||
<div class="content">
|
||
{#if windowError}<p class="error" role="alert">{windowError}</p>{/if}
|
||
{#if !selected}
|
||
<h2>{$t("No settings found")}</h2>
|
||
<p>{$t("Try “save”, “plug-ins”, or “help”.")}</p>
|
||
<button class="text-button" onclick={() => query = ""}>{$t("Clear search")}</button>
|
||
{:else if selected.id === "general"}
|
||
<h2>{$t("General")}</h2>
|
||
<p class="intro">{$t("Choose how RuneStone saves your work.")}</p>
|
||
<h3>{$t('Language')}</h3>
|
||
<div class="card"><div class="setting-row language-row"><div><label for="language-picker">{$t('Display language')}</label><p>{$t('Choose the language for RuneStone controls.')}</p></div><button id="language-picker" class="text-button language-picker" aria-haspopup="menu" onclick={languagePicker}><Icon icon="globe" />{LANGUAGES.find(item => item.id === $locale)?.name}<Icon icon="chevron-down" /></button></div></div>
|
||
<h3>{$t("Tables")}</h3>
|
||
<div class="card">
|
||
<div class="setting-row">
|
||
<div><label for="table-formulas">{$t("Table formulas")}</label><p id="table-formulas-description">{$t("Calculate table cells that start with =. When this is off, formulas show as text.")}</p></div>
|
||
<input id="table-formulas" class="switch" type="checkbox" role="switch" aria-describedby="table-formulas-description" checked={settings.tableFormulas} onchange={event => apply({ ...settings, tableFormulas: event.currentTarget.checked })} />
|
||
</div>
|
||
</div>
|
||
<h3>{$t("Files")}</h3>
|
||
<div class="card">
|
||
<div class="setting-row">
|
||
<div><label for="show-internal-folder">{$t("Show .runestone folder")}</label><p id="internal-folder-description">{$t("Show workspace settings and plugin data in the file tree.")}</p></div>
|
||
<input id="show-internal-folder" class="switch" type="checkbox" role="switch" aria-describedby="internal-folder-description" checked={settings.showInternalFolder} onchange={event => apply({ ...settings, showInternalFolder: event.currentTarget.checked })} />
|
||
</div>
|
||
<div class="setting-row">
|
||
<div><label for="autosave-enabled">{$t("Auto-save")}</label><p id="autosave-description">{$t("Save changed notes and scripts, including background tabs.")}</p></div>
|
||
<input id="autosave-enabled" class="switch" type="checkbox" role="switch" aria-describedby="autosave-description" checked={settings.autosaveEnabled} onchange={event => { apply({ ...settings, autosaveEnabled: event.currentTarget.checked }); event.currentTarget.checked = settings.autosaveEnabled; }} />
|
||
</div>
|
||
<div class="setting-row">
|
||
<div><label for="autosave-seconds">{$t("Auto-save interval")}</label><p id="interval-description">{$t("Time between saves, even while you type. Choose 1–300 seconds.")}</p></div>
|
||
<div class="interval"><input id="autosave-seconds" type="number" min={MIN_AUTOSAVE_SECONDS} max={MAX_AUTOSAVE_SECONDS} step="1" required disabled={!settings.autosaveEnabled} aria-describedby="interval-description" aria-invalid={!!error} bind:value={seconds} onchange={changeInterval} /><span>{$t("seconds")}</span></div>
|
||
</div>
|
||
</div>
|
||
<p class="note">{settings.autosaveEnabled ? $t("Only changed files are saved.") : $t("Auto-save is off. Use Ctrl+S to save your changes.")} {$t("Disk conflicts keep your edits for review.")}</p>
|
||
<div class="section-footer"><button class="text-button" onclick={() => { seconds = DEFAULT_SETTINGS.autosaveSeconds; apply({ ...DEFAULT_SETTINGS }); }}>{$t("Restore defaults")}</button><span>{$t("Default: every 5 seconds")}</span></div>
|
||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||
<p class="saved" role="status">{message}</p>
|
||
{:else if selected.id === "appearance"}
|
||
<AppearanceSettings />
|
||
{: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>{$t("Version {version}", { version })}</p></div>
|
||
<div class="card help-card">
|
||
<details><summary><Icon icon="book-open" /> {$t("Get started")}</summary><div class="help-copy"><p>{$t("Use the folder button to open a workspace or create one. Your notes and scripts stay as ordinary files on disk.")}</p><p>{$t("Use the + beside the tabs for a new tab. Press Ctrl+N to create a file, or Ctrl+P to find one.")}</p><p>{$t("Press Ctrl+E to switch between writing and source editing. Use the terminal button to work with a shell beside your files.")}</p></div></details>
|
||
<details><summary><Icon icon="save" /> {$t("Save your work")}</summary><div class="help-copy"><p>{$t("Auto-save saves changed files at the interval in Settings → General. Ctrl+S saves the active file immediately.")}</p><p>{$t("If another app changes a file, RuneStone keeps your edits and offers both versions for review.")}</p></div></details>
|
||
<details><summary><Icon icon="code" /> {$t("Keyboard shortcuts")}</summary><dl><div><dt>{$t("Open a workspace")}</dt><dd><kbd>Ctrl+O</kbd></dd></div><div><dt>{$t("Find a file")}</dt><dd><kbd>Ctrl+P</kbd></dd></div><div><dt>{$t("Save the active file")}</dt><dd><kbd>Ctrl+S</kbd></dd></div><div><dt>{$t("Search the workspace")}</dt><dd><kbd>Ctrl+Shift+F</kbd></dd></div><div><dt>{$t("Open settings")}</dt><dd><kbd>Ctrl+,</kbd></dd></div><div><dt>{$t("Help and about")}</dt><dd><kbd>F1</kbd></dd></div></dl></details>
|
||
</div>
|
||
<p class="about-note">{$t("RuneStone is under development. Maintained by kwyvern-gh.")}</p>
|
||
{/if}
|
||
</div>
|
||
</div>
|
||
</dialog>
|
||
|
||
<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: var(--rs-titlebar-height); padding: 0 4px 0 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rs-border); background: var(--rs-bg-elevated); }
|
||
header.window-header { padding-right: 0; user-select: none; }
|
||
h1 { font-size: 13px; font-weight: 600; margin: 0; }
|
||
.body { display: flex; height: calc(100% - var(--rs-titlebar-height)); min-height: 0; }
|
||
aside { width: 220px; flex-shrink: 0; padding: 12px 8px; background: var(--rs-bg-elevated); border-right: 1px solid var(--rs-border); display: flex; flex-direction: column; overflow: auto; }
|
||
.search { display: flex; gap: var(--rs-settings-gap); align-items: center; min-height: var(--rs-settings-control-height); background: var(--rs-bg-active); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); padding: 4px 8px; color: var(--rs-text-dim); }
|
||
.search:focus-within { outline: 2px solid var(--rs-accent); }
|
||
.search input { width: 100%; min-width: 0; border: 0; padding: 0; outline: none; background: transparent; color: var(--rs-text); }
|
||
.nav-heading { margin: 16px 8px 6px; font-size: 11px; color: var(--rs-text-dim); }
|
||
nav { display: flex; flex-direction: column; gap: 2px; }
|
||
nav button { display: flex; align-items: center; gap: var(--rs-settings-gap); width: 100%; min-height: var(--rs-settings-control-height); padding: 5px 8px; border: 0; border-radius: var(--rs-control-radius); background: transparent; text-align: left; }
|
||
nav button:hover { background: var(--rs-bg-active); }
|
||
nav button.active { background: var(--rs-item-selection-bg); box-shadow: inset 0 0 0 var(--rs-item-selection-width) var(--rs-item-selection-border); border-radius: var(--rs-item-selection-radius); }
|
||
.scope { margin: auto 10px 0; padding-top: 24px; color: var(--rs-text-dim); font-size: 12px; }
|
||
.content { padding: 20px 24px; flex: 1; min-width: 0; min-height: 0; overflow-y: auto; }
|
||
h2 { margin: 0; font-size: var(--rs-settings-heading-size); font-weight: 600; color: var(--rs-text-strong); }
|
||
h3 { margin: var(--rs-settings-section-gap) 0 8px; font-size: 13px; font-weight: 600; }
|
||
p { color: var(--rs-text-dim); line-height: 1.45; }
|
||
.intro { margin: 6px 0 var(--rs-settings-section-gap); }
|
||
.card { padding: 0 12px; background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: var(--rs-settings-row-padding) 0; }
|
||
.setting-row > div:first-child { min-width: 0; }
|
||
.setting-row + .setting-row { border-top: 1px solid var(--rs-border); }
|
||
.setting-row label { font-weight: 500; }
|
||
.setting-row p { margin: 3px 0 0; font-size: var(--rs-settings-description-size); }
|
||
.language-row { flex-wrap: wrap; }
|
||
.language-picker { display:flex; align-items:center; gap:var(--rs-settings-gap); max-width:100%; }
|
||
.switch { appearance: none; width: 38px; height: 22px; flex: 0 0 38px; margin: 0; border-radius: 20px; background: var(--rs-bg-active); border: 1px solid var(--rs-text-dim); cursor: pointer; }
|
||
.switch::before { content: ""; display: block; width: 16px; height: 16px; margin: 2px; background: var(--rs-text); border-radius: 50%; transition: transform .12s; }
|
||
.switch:checked { background: var(--rs-accent); border-color: var(--rs-accent); }
|
||
.switch:checked::before { transform: translateX(16px); background: var(--rs-bg); }
|
||
.interval { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; font-size: 11px; color: var(--rs-text-dim); }
|
||
.interval input { width: 72px; min-height: var(--rs-settings-control-height); padding: 4px 6px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); font-size: 13px; }
|
||
.interval input:disabled { opacity: .45; }
|
||
.note, .section-footer, .about-note { font-size: 12px; }
|
||
.note { margin: 10px 0 var(--rs-settings-section-gap); }
|
||
.section-footer { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; color: var(--rs-text-dim); }
|
||
.text-button { min-height: var(--rs-settings-control-height); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg-elevated); padding: 4px 8px; color: var(--rs-text); }
|
||
.text-button:hover { background: var(--rs-bg-active); }
|
||
.saved { font-size: 12px; color: var(--rs-ok); min-height: 20px; }
|
||
.error { color: var(--rs-error); }
|
||
.brand { text-align: center; margin-bottom: 26px; }
|
||
.brand h2 { font-size: 28px; margin-top: 4px; }
|
||
.brand p { margin: 6px 0; font-size: 12px; }
|
||
.help-card details + details { border-top: 1px solid var(--rs-border); }
|
||
summary { display: flex; align-items: center; gap: 12px; padding: 18px 0; cursor: pointer; list-style: none; border-radius: var(--rs-control-radius); }
|
||
summary::after { content: "+"; margin-left: auto; color: var(--rs-text-dim); }
|
||
details[open] summary::after { content: "−"; }
|
||
.help-copy, dl { margin: 0 0 18px 28px; font-size: 12px; }
|
||
.help-copy p:first-child { margin-top: 0; }
|
||
dl div { display: flex; justify-content: space-between; gap: 12px; margin: 10px 0; }
|
||
dd { margin: 0; }
|
||
kbd { font-family: var(--rs-font-mono); color: var(--rs-text-dim); }
|
||
.about-note { text-align: center; margin: 20px 0 0; }
|
||
@media (max-width: 660px) {
|
||
.body { flex-direction: column; }
|
||
aside { width: 100%; max-height: 40%; padding: 8px; border-right: 0; border-bottom: 1px solid var(--rs-border); flex-shrink: 0; }
|
||
nav { flex-direction: row; flex-wrap: wrap; margin-top: 6px; }
|
||
nav button { width: auto; flex: 1 1 auto; padding: 5px 8px; gap: 6px; }
|
||
.nav-heading, .scope { display: none; }
|
||
.content { padding: 16px 12px; }
|
||
.setting-row { gap: 14px; }
|
||
}
|
||
</style>
|