Phase 5-4. - The workspace button sits at the left end of the header. It shows the workspace name and opens the workspace list below it. - The left ribbon is always present: plugin views at the top, Help and Settings at the bottom. The left pane footer is gone. - Tabs keep 120 pixels and scroll. Fades show tabs out of view, and a list button names all tabs, with pinned and unsaved marks. The active tab now scrolls into view with its close button. - A drag area of 120 pixels follows the tabs. In a narrow header, the tabs shrink first, and the drag area keeps at least 48 pixels. - Caption buttons are square, 46 pixels wide, and full height. When the pointer rests on maximize, the new window_snap_layouts command opens Snap Layouts with Win+Z for the focused window. - macOS keeps its native traffic lights: tauri.macos.conf.json and the runtime window builders use an overlay title bar. Title bars leave --rs-titlebar-inset-start free for the traffic lights. - 3 new catalog rows and 1 removed row, in French, Japanese, and Simplified Chinese. - Docs: UI-050, the user guide, and ui-design.md. Tests: the new layout/titleBar. Tests that used the left pane footer, the rounded caption buttons, the 600-pixel theme editor pane, or a ribbon of no width now follow the new layout.
188 lines
10 KiB
Svelte
188 lines
10 KiB
Svelte
<script lang="ts">
|
|
import { t, tr } from "$lib/i18n";
|
|
import { tick } from "svelte";
|
|
import Icon from "$lib/ui/Icon.svelte";
|
|
import { attachTooltip } from "$lib/ui/tooltip";
|
|
import { pickWorkspaceFolder, workspaceRecent, workspaceForget } from "$lib/workspace/api";
|
|
|
|
let { currentRoot, anchor, onOpen }: {
|
|
currentRoot?: string; anchor?: HTMLElement;
|
|
onOpen: (path: string, name?: string) => Promise<boolean>;
|
|
} = $props();
|
|
let menu: HTMLDivElement;
|
|
let dialog: HTMLDialogElement | undefined = $state();
|
|
let input: HTMLInputElement | undefined = $state();
|
|
let recent = $state<string[]>([]);
|
|
let loading = $state(false);
|
|
let busy = $state(false);
|
|
let error = $state("");
|
|
let creating = $state(false);
|
|
let name = $state("");
|
|
let parent = $state("");
|
|
let returnFocus: HTMLElement | null = null;
|
|
const folderName = (path: string) => path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
|
|
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.focus();
|
|
try { recent = await workspaceRecent(); }
|
|
catch (err) { error = tr("Could not load recent workspaces: {error}", { error: String(err) }); }
|
|
finally { loading = false; }
|
|
await tick();
|
|
if (menu.matches(":popover-open")) {
|
|
position();
|
|
if (keyboard) (menu.querySelector<HTMLButtonElement>('button[aria-current="true"]') ?? menu.querySelector<HTMLButtonElement>("button"))?.focus();
|
|
}
|
|
}
|
|
|
|
function position() {
|
|
const rect = anchor?.getBoundingClientRect();
|
|
menu.style.left = `${Math.max(8, Math.min(rect?.left ?? (innerWidth - menu.offsetWidth) / 2, innerWidth - menu.offsetWidth - 8))}px`;
|
|
// The list opens below an anchor in the title bar, and above an anchor lower in the window.
|
|
const below = rect ? rect.bottom + 4 : (innerHeight - menu.offsetHeight) / 2;
|
|
const top = rect && rect.top > innerHeight / 2 ? rect.top - menu.offsetHeight - 8 : below;
|
|
menu.style.top = `${Math.max(8, Math.min(top, innerHeight - menu.offsetHeight - 8))}px`;
|
|
}
|
|
|
|
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 = tr("Could not open workspace: {error}", { error: String(err) }); }
|
|
finally { busy = false; }
|
|
}
|
|
|
|
async function browse() {
|
|
if (busy) return;
|
|
busy = true; error = "";
|
|
try {
|
|
const path = await pickWorkspaceFolder();
|
|
if (path && await onOpen(path)) close();
|
|
} catch (err) { error = String(err); }
|
|
finally { busy = false; }
|
|
}
|
|
|
|
async function newWorkspace() {
|
|
menu.hidePopover(); error = ""; name = ""; parent = ""; creating = true;
|
|
await tick(); dialog?.showModal(); input?.focus();
|
|
}
|
|
function cancel() { if (!busy) { creating = false; returnFocus?.focus(); } }
|
|
async function chooseLocation() {
|
|
busy = true; error = "";
|
|
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; }
|
|
}
|
|
async function create() {
|
|
if (busy || !name.trim() || !parent) return;
|
|
busy = true; error = "";
|
|
try { if (await onOpen(parent, name.trim())) { creating = false; returnFocus?.focus(); } }
|
|
catch (err) { error = String(err); }
|
|
finally { busy = false; }
|
|
}
|
|
function navigate(event: KeyboardEvent) {
|
|
if (event.key === "Escape") { event.preventDefault(); close(); return; }
|
|
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
|
event.preventDefault();
|
|
const buttons = [...menu.querySelectorAll<HTMLButtonElement>("button:not(:disabled)")];
|
|
const index = buttons.indexOf(document.activeElement as HTMLButtonElement);
|
|
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length;
|
|
buttons[next]?.focus();
|
|
}
|
|
</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={$t("Workspaces")} tabindex="-1" onkeydown={navigate}>
|
|
<h2>{$t("Recent workspaces")}</h2>
|
|
<div class="recent" aria-busy={loading || busy}>
|
|
{#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">{$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> {$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" /> {$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}>{$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}
|
|
|
|
<style>
|
|
dialog { background: var(--rs-bg-elevated); color: var(--rs-text); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); box-shadow: 0 12px 36px #0006; }
|
|
.workspace-menu { position: fixed; inset: auto; margin: 0; width: min(380px, calc(100vw - 16px)); }
|
|
h2 { font-size: 14px; font-weight: 600; margin: 0; padding: 9px 10px; display: flex; align-items: center; gap: 8px; }
|
|
p { font-size: 13px; color: var(--rs-text-dim); margin: 8px 10px; }
|
|
.recent { max-height: min(360px, 45vh); overflow: auto; }
|
|
form button { display: flex; align-items: center; gap: 10px; background: transparent; border: 1px solid transparent; border-radius: var(--rs-control-radius); padding: 9px 10px; color: var(--rs-text); text-align: left; }
|
|
form button:hover { background: var(--rs-bg-active); }
|
|
form button:focus-visible, input:focus-visible { outline: 2px solid var(--rs-focus); 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); }
|
|
footer { border-top: 1px solid var(--rs-border); margin-top: 6px; padding-top: 6px; }
|
|
dialog { width: min(480px, calc(100vw - 32px)); padding: 22px; }
|
|
dialog::backdrop { background: var(--rs-scrim); }
|
|
form { display: flex; flex-direction: column; gap: 12px; }
|
|
form h2, form p { padding: 0; margin: 0; }
|
|
form label { font-size: 13px; }
|
|
input { width: 100%; background: var(--rs-bg); color: var(--rs-text); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); padding: 10px; }
|
|
.location-label, .actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
form button { border-color: var(--rs-border); background: var(--rs-bg-active); }
|
|
.actions { justify-content: flex-end; margin-top: 8px; }
|
|
.primary { border-color: var(--rs-accent); }
|
|
.error { color: var(--rs-error); overflow-wrap: anywhere; }
|
|
</style>
|