Add interface languages and improve themes and workspace controls for 0.1.36
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { t, tr } from "$lib/i18n";
|
||||
import { tick } from "svelte";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import { pickWorkspaceFolder, workspaceRecent } from "$lib/workspace/api";
|
||||
import { attachTooltip } from "$lib/ui/tooltip";
|
||||
import { pickWorkspaceFolder, workspaceRecent, workspaceForget } from "$lib/workspace/api";
|
||||
|
||||
let { currentRoot, anchor, onOpen }: {
|
||||
currentRoot?: string; anchor?: HTMLElement;
|
||||
@@ -19,21 +21,26 @@
|
||||
let parent = $state("");
|
||||
let returnFocus: HTMLElement | null = null;
|
||||
const folderName = (path: string) => path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
|
||||
const destination = $derived(parent ? `${parent.replace(/[\\/]+$/, "")}${parent.includes("\\") ? "\\" : "/"}${name.trim()}` : "Choose where to create your workspace.");
|
||||
const removeTooltip = (node: HTMLElement) => ({ destroy: attachTooltip(node, () => tr("Remove from recent workspaces")) });
|
||||
const destination = $derived(parent ? `${parent.replace(/[\\/]+$/, "")}${parent.includes("\\") ? "\\" : "/"}${name.trim()}` : $t("Choose where to create your workspace."));
|
||||
|
||||
export async function show() {
|
||||
if (busy || creating) return;
|
||||
if (menu.matches(":popover-open")) { menu.hidePopover(); return; }
|
||||
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
error = ""; loading = true;
|
||||
const keyboard = anchor?.matches(":focus-visible") ?? false;
|
||||
menu.showPopover();
|
||||
position();
|
||||
menu.querySelector<HTMLButtonElement>("button")?.focus();
|
||||
menu.focus();
|
||||
try { recent = await workspaceRecent(); }
|
||||
catch (err) { error = `Could not load recent workspaces: ${String(err)}`; }
|
||||
catch (err) { error = tr("Could not load recent workspaces: {error}", { error: String(err) }); }
|
||||
finally { loading = false; }
|
||||
await tick();
|
||||
if (menu.matches(":popover-open")) { position(); menu.querySelector<HTMLButtonElement>("button")?.focus(); }
|
||||
if (menu.matches(":popover-open")) {
|
||||
position();
|
||||
if (keyboard) (menu.querySelector<HTMLButtonElement>('button[aria-current="true"]') ?? menu.querySelector<HTMLButtonElement>("button"))?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function position() {
|
||||
@@ -44,12 +51,25 @@
|
||||
|
||||
function close() { menu.hidePopover(); returnFocus?.focus(); }
|
||||
|
||||
async function forget(path: string) {
|
||||
if (busy) return;
|
||||
busy = true; error = "";
|
||||
const index = recent.indexOf(path);
|
||||
try { recent = await workspaceForget(path); }
|
||||
catch (err) { error = tr("Could not remove workspace from recent workspaces: {error}", { error: String(err) }); }
|
||||
finally { busy = false; }
|
||||
await tick();
|
||||
position();
|
||||
const rows = menu.querySelectorAll<HTMLButtonElement>(".workspace-row");
|
||||
(rows[Math.min(index, rows.length - 1)] ?? menu.querySelector<HTMLButtonElement>("footer button"))?.focus();
|
||||
}
|
||||
|
||||
async function open(path: string) {
|
||||
if (busy) return;
|
||||
if (path === currentRoot) { close(); return; }
|
||||
busy = true; error = "";
|
||||
try { if (await onOpen(path)) close(); }
|
||||
catch (err) { error = `Could not open workspace: ${String(err)}`; }
|
||||
catch (err) { error = tr("Could not open workspace: {error}", { error: String(err) }); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
|
||||
@@ -70,7 +90,7 @@
|
||||
function cancel() { if (!busy) { creating = false; returnFocus?.focus(); } }
|
||||
async function chooseLocation() {
|
||||
busy = true; error = "";
|
||||
try { const path = await pickWorkspaceFolder("Choose a location for the new workspace"); if (path) parent = path; }
|
||||
try { const path = await pickWorkspaceFolder(tr("Choose a location for the new workspace")); if (path) parent = path; }
|
||||
catch (err) { error = String(err); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
@@ -93,38 +113,41 @@
|
||||
</script>
|
||||
|
||||
<svelte:window onresize={() => { if (menu?.matches(":popover-open")) position(); }} />
|
||||
<div bind:this={menu} popover="auto" class="workspace-menu rs-picker" role="dialog" aria-label="Workspaces" tabindex="-1" onkeydown={navigate}>
|
||||
<h2>Recent workspaces</h2>
|
||||
<div bind:this={menu} popover="auto" class="workspace-menu rs-picker" role="dialog" aria-label={$t("Workspaces")} tabindex="-1" onkeydown={navigate}>
|
||||
<h2>{$t("Recent workspaces")}</h2>
|
||||
<div class="recent" aria-busy={loading || busy}>
|
||||
{#if loading}<p>Loading workspaces…</p>
|
||||
{:else if !recent.length}<p>No recent workspaces yet.</p>{/if}
|
||||
{#each recent as path}
|
||||
{#if loading}<p>{$t("Loading workspaces…")}</p>
|
||||
{:else if !recent.length}<p>{$t("No recent workspaces yet.")}</p>{/if}
|
||||
{#each recent as path (path)}
|
||||
<div class="workspace-entry">
|
||||
<button class="workspace-row rs-picker-row" aria-current={path === currentRoot ? "true" : undefined} disabled={busy} onclick={() => open(path)}>
|
||||
<span class="rs-picker-icon"><Icon icon="folder-open" /></span>
|
||||
<span class="details"><span>{folderName(path)}</span><small>{path}</small></span>
|
||||
{#if path === currentRoot}<span class="current-label">Current</span>{/if}
|
||||
{#if path === currentRoot}<span class="current-label">{$t("Current")}</span>{/if}
|
||||
</button>
|
||||
<button class="workspace-remove rs-picker-row" aria-label={$t("Remove {path} from recent workspaces", { path })} use:removeTooltip disabled={busy} onclick={() => forget(path)}><Icon icon="close" /></button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<footer>
|
||||
<button class="rs-picker-row" disabled={busy} onclick={newWorkspace}><span class="rs-picker-icon"><Icon icon="folder-plus" /></span> New workspace…</button>
|
||||
<button class="rs-picker-row" disabled={busy} onclick={browse}><span class="rs-picker-icon"><Icon icon="folder-open" /></span> Open another folder…</button>
|
||||
<button class="rs-picker-row" disabled={busy} onclick={newWorkspace}><span class="rs-picker-icon"><Icon icon="folder-plus" /></span> {$t("New workspace…")}</button>
|
||||
<button class="rs-picker-row" disabled={busy} onclick={browse}><span class="rs-picker-icon"><Icon icon="folder-open" /></span> {$t("Open another folder…")}</button>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
{#if creating}
|
||||
<dialog bind:this={dialog} aria-labelledby="new-workspace-title" oncancel={(event) => { event.preventDefault(); cancel(); }}>
|
||||
<form onsubmit={(event) => { event.preventDefault(); void create(); }}>
|
||||
<h2 id="new-workspace-title"><Icon icon="folder-plus" /> New workspace</h2>
|
||||
<p>Create a folder for your notes and files, then open it in a new window.</p>
|
||||
<label for="workspace-name">Workspace name</label>
|
||||
<input id="workspace-name" bind:this={input} bind:value={name} oninput={() => error = ""} placeholder="My workspace" autocomplete="off" required disabled={busy} />
|
||||
<div class="location-label"><label for="workspace-location">Location</label><button type="button" disabled={busy} onclick={chooseLocation}><Icon icon="folder-open" /> Browse…</button></div>
|
||||
<input id="workspace-location" value={parent} readonly placeholder="Choose a parent folder" />
|
||||
<small class="destination">{parent ? "Will create: " : ""}{destination}</small>
|
||||
<h2 id="new-workspace-title"><Icon icon="folder-plus" /> {$t("New workspace")}</h2>
|
||||
<p>{$t("Create a folder for your notes and files, then open it in a new window.")}</p>
|
||||
<label for="workspace-name">{$t("Workspace name")}</label>
|
||||
<input id="workspace-name" bind:this={input} bind:value={name} oninput={() => error = ""} placeholder={$t("My workspace")} autocomplete="off" required disabled={busy} />
|
||||
<div class="location-label"><label for="workspace-location">{$t("Location")}</label><button type="button" disabled={busy} onclick={chooseLocation}><Icon icon="folder-open" /> {$t("Browse…")}</button></div>
|
||||
<input id="workspace-location" value={parent} readonly placeholder={$t("Choose a parent folder")} />
|
||||
<small class="destination">{parent ? $t("Will create: {path}", { path: destination }) : destination}</small>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<div class="actions"><button type="button" disabled={busy} onclick={cancel}>Cancel</button><button class="primary" type="submit" disabled={busy || !name.trim() || !parent}>{busy ? "Please wait…" : "Create workspace"}</button></div>
|
||||
<div class="actions"><button type="button" disabled={busy} onclick={cancel}>{$t("Cancel")}</button><button class="primary" type="submit" disabled={busy || !name.trim() || !parent}>{busy ? $t("Please wait…") : $t("Create workspace")}</button></div>
|
||||
</form>
|
||||
</dialog>
|
||||
{/if}
|
||||
@@ -140,6 +163,9 @@
|
||||
form button:focus-visible, input:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: -2px; }
|
||||
form button:disabled { opacity: .5; }
|
||||
.workspace-row, footer button { width: 100%; }
|
||||
.workspace-entry { display: flex; align-items: stretch; }
|
||||
.workspace-entry .workspace-row { flex: 1; min-width: 0; }
|
||||
.workspace-entry .workspace-remove { width: 30px; flex: 0 0 30px; justify-content: center; padding-inline: 0; }
|
||||
.details { min-width: 0; display: flex; flex: 1; flex-direction: column; gap: 3px; }
|
||||
small { font-size: 11px; color: var(--rs-text-dim); overflow-wrap: anywhere; }
|
||||
.current-label { font-size: 11px; color: var(--rs-accent); }
|
||||
|
||||
Reference in New Issue
Block a user