Add interface languages and improve themes and workspace controls for 0.1.36
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { onMount, untrack, tick } from 'svelte';
|
||||
import IconButton from '$lib/ui/IconButton.svelte';
|
||||
import Icon from '$lib/ui/Icon.svelte';
|
||||
@@ -9,7 +10,7 @@
|
||||
import { TabSession, type TabStatus } from './tabSession';
|
||||
import { AutoScroll } from './autoScroll';
|
||||
let { initial, onSessionChange, newTab }: { initial: { tabId?: string; profileId?: string; url?: string }; onSessionChange: (value: TabStatus) => void; newTab: (profileId: string, url?: string) => Promise<void> } = $props();
|
||||
let status = $state<TabStatus>({ tabId: '', phase: 'connecting', message: 'Opening browser…' });
|
||||
let status = $state<TabStatus>({ tabId: '', phase: 'connecting', message: $t('Opening browser…') });
|
||||
const connection = new TabSession(request, untrack(() => initial), value => { status = value; onSessionChange(value); });
|
||||
const tabId = $derived(status.tabId);
|
||||
const ready = $derived(status.phase === 'ready');
|
||||
@@ -28,7 +29,7 @@
|
||||
closeMenu?.();
|
||||
const anchor = event.currentTarget as HTMLButtonElement;
|
||||
const rect = anchor.getBoundingClientRect();
|
||||
closeMenu = showActionMenu({ x: rect.left, y: rect.bottom + 4, label: 'Browser profile',
|
||||
closeMenu = showActionMenu({ x: rect.left, y: rect.bottom + 4, label: $t('Browser profile'),
|
||||
items: ($browserState?.profiles || []).map(profile => ({ label: profile.name, radio: true,
|
||||
checked: profile.id === current?.profileId, run: () => void openTab(profile.id) })) }).close;
|
||||
}
|
||||
@@ -92,30 +93,30 @@
|
||||
const edit = (name: string) => () => { void orderedInput('edit', { action: name }); };
|
||||
const items: ActionMenuItem[] = [];
|
||||
if (context.linkURL) items.push(
|
||||
{ label: 'Open link in new tab', icon: 'file-plus', run: () => void newTab(current?.profileId || 'user', context.linkURL) },
|
||||
{ label: 'Open link in default browser', icon: 'external', run: action('openExternal') },
|
||||
{ label: 'Copy link address', icon: 'copy', run: action('copyLink') },
|
||||
{ label: 'Save link as…', icon: 'save', run: action('saveLink') }, { separator: true });
|
||||
{ label: $t('Open link in new tab'), icon: 'file-plus', run: () => void newTab(current?.profileId || 'user', context.linkURL) },
|
||||
{ label: $t('Open link in default browser'), icon: 'external', run: action('openExternal') },
|
||||
{ label: $t('Copy link address'), icon: 'copy', run: action('copyLink') },
|
||||
{ label: $t('Save link as…'), icon: 'save', run: action('saveLink') }, { separator: true });
|
||||
if (context.hasImageContents) items.push(
|
||||
{ label: 'Save image as…', icon: 'save', disabled: !context.srcURL, run: action('saveImage') },
|
||||
{ label: 'Copy image', icon: 'copy', run: action('copyImage') },
|
||||
{ label: 'Copy image address', icon: 'copy', disabled: !context.srcURL, run: action('copyImageAddress') }, { separator: true });
|
||||
{ label: $t('Save image as…'), icon: 'save', disabled: !context.srcURL, run: action('saveImage') },
|
||||
{ label: $t('Copy image'), icon: 'copy', run: action('copyImage') },
|
||||
{ label: $t('Copy image address'), icon: 'copy', disabled: !context.srcURL, run: action('copyImageAddress') }, { separator: true });
|
||||
if (context.isEditable) items.push(
|
||||
{ label: 'Undo', icon: 'undo', shortcut: 'Ctrl+Z', disabled: !context.editFlags.canUndo, run: edit('undo') },
|
||||
{ label: 'Redo', icon: 'redo', shortcut: 'Ctrl+Shift+Z', disabled: !context.editFlags.canRedo, run: edit('redo') }, { separator: true },
|
||||
{ label: 'Cut', icon: 'cut', shortcut: 'Ctrl+X', disabled: !context.editFlags.canCut, run: edit('cut') });
|
||||
if (context.isEditable || context.selectionText) items.push({ label: 'Copy', icon: 'copy', shortcut: 'Ctrl+C', disabled: !context.editFlags.canCopy, run: edit('copy') });
|
||||
{ label: $t('Undo'), icon: 'undo', shortcut: 'Ctrl+Z', disabled: !context.editFlags.canUndo, run: edit('undo') },
|
||||
{ label: $t('Redo'), icon: 'redo', shortcut: 'Ctrl+Shift+Z', disabled: !context.editFlags.canRedo, run: edit('redo') }, { separator: true },
|
||||
{ label: $t('Cut'), icon: 'cut', shortcut: 'Ctrl+X', disabled: !context.editFlags.canCut, run: edit('cut') });
|
||||
if (context.isEditable || context.selectionText) items.push({ label: $t('Copy'), icon: 'copy', shortcut: 'Ctrl+C', disabled: !context.editFlags.canCopy, run: edit('copy') });
|
||||
if (context.isEditable) items.push(
|
||||
{ label: 'Paste', icon: 'paste', shortcut: 'Ctrl+V', disabled: !context.editFlags.canPaste, run: edit('paste') },
|
||||
{ label: 'Paste as plain text', icon: 'paste-text', shortcut: 'Ctrl+Shift+V', disabled: !context.editFlags.canPaste, run: edit('pasteAndMatchStyle') },
|
||||
{ label: 'Select all', icon: 'task', shortcut: 'Ctrl+A', run: edit('selectAll') }, { separator: true });
|
||||
items.push({ label: 'Back', icon: 'arrow-left', disabled: !current?.canBack, run: () => void send('back') },
|
||||
{ label: 'Forward', icon: 'arrow-right', disabled: !current?.canForward, run: () => void send('forward') },
|
||||
{ label: 'Reload', icon: 'refresh', run: () => void send('reload') },
|
||||
{ label: 'Find in page', icon: 'search', shortcut: 'Ctrl+F', run: () => void find() });
|
||||
{ label: $t('Paste'), icon: 'paste', shortcut: 'Ctrl+V', disabled: !context.editFlags.canPaste, run: edit('paste') },
|
||||
{ label: $t('Paste as plain text'), icon: 'paste-text', shortcut: 'Ctrl+Shift+V', disabled: !context.editFlags.canPaste, run: edit('pasteAndMatchStyle') },
|
||||
{ label: $t('Select all'), icon: 'task', shortcut: 'Ctrl+A', run: edit('selectAll') }, { separator: true });
|
||||
items.push({ label: $t('Back'), icon: 'arrow-left', disabled: !current?.canBack, run: () => void send('back') },
|
||||
{ label: $t('Forward'), icon: 'arrow-right', disabled: !current?.canForward, run: () => void send('forward') },
|
||||
{ label: $t('Reload'), icon: 'refresh', run: () => void send('reload') },
|
||||
{ label: $t('Find in page'), icon: 'search', shortcut: 'Ctrl+F', run: () => void find() });
|
||||
const rect = surface.getBoundingClientRect();
|
||||
const menu = showActionMenu({ x: rect.left + context.x * rect.width / width, y: rect.top + context.y * rect.height / height,
|
||||
items, label: 'Browser page actions' });
|
||||
items, label: $t('Browser page actions') });
|
||||
closeMenu = menu.close;
|
||||
}
|
||||
$effect(() => { if (mounted && ready && tabId) untrack(syncSize); });
|
||||
@@ -216,46 +217,46 @@
|
||||
<svelte:document onvisibilitychange={() => { if (document.hidden) { stopScroll(); pageFocus(false); } else if (surface?.contains(document.activeElement)) pageFocus(true); }} />
|
||||
<div class="browser" class:blank data-browser-tab={tabId} data-browser-state={status.phase}>
|
||||
<form class="toolbar" onsubmit={event => { event.preventDefault(); editing = false; void send('navigate', { input: address }); surface.focus(); }}>
|
||||
<IconButton icon="arrow-left" label="Back" disabled={!ready || !current?.canBack} onclick={() => void send('back')} />
|
||||
<IconButton icon="arrow-right" label="Forward" disabled={!ready || !current?.canForward} onclick={() => void send('forward')} />
|
||||
<IconButton icon={current?.loading ? 'stop' : 'refresh'} label={current?.loading ? 'Stop loading' : 'Reload'} disabled={!ready} onclick={() => void send(current?.loading ? 'stop' : 'reload')} />
|
||||
<input bind:this={addressField} bind:value={address} disabled={!ready} onfocus={() => editing = true} onblur={() => editing = false} aria-label="Address or search" placeholder="Search or enter an address" spellcheck="false" autocomplete="off">
|
||||
<IconButton icon="bookmark" label="Bookmark this page" disabled={!ready || !current?.url.startsWith('http')} onclick={() => void send('bookmark')} />
|
||||
<button type="button" class="profile-choice" aria-label="Browser profile" aria-haspopup="menu" disabled={opening} onclick={chooseProfile}>
|
||||
{$browserState?.profiles.find(profile => profile.id === current?.profileId)?.name ?? 'Profile'}<Icon icon="chevron-down" />
|
||||
<IconButton icon="arrow-left" label={$t("Back")} disabled={!ready || !current?.canBack} onclick={() => void send('back')} />
|
||||
<IconButton icon="arrow-right" label={$t("Forward")} disabled={!ready || !current?.canForward} onclick={() => void send('forward')} />
|
||||
<IconButton icon={current?.loading ? 'stop' : 'refresh'} label={current?.loading ? 'Stop loading' : $t('Reload')} disabled={!ready} onclick={() => void send(current?.loading ? 'stop' : 'reload')} />
|
||||
<input bind:this={addressField} bind:value={address} disabled={!ready} onfocus={() => editing = true} onblur={() => editing = false} aria-label={$t("Address or search")} placeholder={$t("Search or enter an address")} spellcheck="false" autocomplete="off">
|
||||
<IconButton icon="bookmark" label={$t("Bookmark this page")} disabled={!ready || !current?.url.startsWith('http')} onclick={() => void send('bookmark')} />
|
||||
<button type="button" class="profile-choice" aria-label={$t("Browser profile")} aria-haspopup="menu" disabled={opening} onclick={chooseProfile}>
|
||||
{$browserState?.profiles.find(profile => profile.id === current?.profileId)?.name ?? $t('Profile')}<Icon icon="chevron-down" />
|
||||
</button>
|
||||
</form>
|
||||
{#if findOpen}
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions (Find controls share the Escape shortcut.) -->
|
||||
<form class="findbar" role="search" aria-label="Find in page" onkeydown={findKey} onsubmit={event => { event.preventDefault(); search(true); }}>
|
||||
<input bind:this={findField} bind:value={findText} aria-label="Find in page" placeholder="Find in page" maxlength="1000" autocomplete="off" spellcheck="false"
|
||||
<form class="findbar" role="search" aria-label={$t("Find in page")} onkeydown={findKey} onsubmit={event => { event.preventDefault(); search(true); }}>
|
||||
<input bind:this={findField} bind:value={findText} aria-label={$t("Find in page")} placeholder={$t("Find in page")} maxlength="1000" autocomplete="off" spellcheck="false"
|
||||
disabled={!ready} oninput={() => { clearTimeout(findTimer); findTimer = setTimeout(() => search(), 120); }}>
|
||||
<span class="find-count" role="status" aria-live="polite">{!findText ? '' : !result || result.pending ? 'Searching…' : result.matches ? `${result.activeMatch} of ${result.matches}` : 'No matches'}</span>
|
||||
<IconButton icon="up" label="Previous match (Shift+Enter)" disabled={!ready || !findText} onclick={() => search(true, false)} />
|
||||
<IconButton icon="down" label="Next match (Enter)" disabled={!ready || !findText} onclick={() => search(true)} />
|
||||
<IconButton icon="close" label="Close find (Escape)" onclick={closeFind} />
|
||||
<IconButton icon="up" label={$t("Previous match (Shift+Enter)")} disabled={!ready || !findText} onclick={() => search(true, false)} />
|
||||
<IconButton icon="down" label={$t("Next match (Enter)")} disabled={!ready || !findText} onclick={() => search(true)} />
|
||||
<IconButton icon="close" label={$t("Close find (Escape)")} onclick={closeFind} />
|
||||
</form>
|
||||
{/if}
|
||||
{#if status.phase === 'connecting'}<p class="status" role="status">{status.message}</p>{/if}
|
||||
{#if ready && status.message}<p class="error" role="alert">{status.message}</p>{/if}
|
||||
{#if status.phase === 'connecting'}<p class="status" role="status">{$t(status.message)}</p>{/if}
|
||||
{#if ready && status.message}<p class="error" role="alert">{$t(status.message)}</p>{/if}
|
||||
{#if status.phase === 'disconnected'}
|
||||
<div class="error" role="alert"><p>{status.message}</p><button class="reconnect" onclick={() => void connection.connect()}>Reconnect</button></div>
|
||||
<div class="error" role="alert"><p>{$t(status.message)}</p><button class="reconnect" onclick={() => void connection.connect()}>{$t("Reconnect")}</button></div>
|
||||
{/if}
|
||||
{#if status.detail}
|
||||
<details class="diagnostics"><summary>Browser error details</summary><dl>
|
||||
<dt>Operation</dt><dd>{status.detail.operation}</dd><dt>Reason</dt><dd>{status.detail.reason}</dd>
|
||||
<dt>Tab</dt><dd>{status.detail.tabId || 'Not created'}</dd><dt>Time</dt><dd>{status.detail.time}</dd>
|
||||
<dt>Browser</dt><dd>Included with RuneStone</dd>
|
||||
<details class="diagnostics"><summary>{$t("Browser error details")}</summary><dl>
|
||||
<dt>{$t("Operation")}</dt><dd>{status.detail.operation}</dd><dt>{$t("Reason")}</dt><dd>{status.detail.reason}</dd>
|
||||
<dt>{$t("Tab")}</dt><dd>{status.detail.tabId || $t('Not created')}</dd><dt>{$t("Time")}</dt><dd>{status.detail.time}</dd>
|
||||
<dt>{$t("Browser")}</dt><dd>{$t("Included with RuneStone")}</dd>
|
||||
</dl></details>
|
||||
{/if}
|
||||
{#if openingError || $pageErrors[tabId]}<p class="error" role="alert">{openingError || $pageErrors[tabId]}</p>{/if}
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (This surface forwards native browser input.) -->
|
||||
<div class="surface" class:autoscroll={!!scrollAnchor} bind:this={surface} role="application" aria-label="Web page" tabindex="0"
|
||||
<div class="surface" class:autoscroll={!!scrollAnchor} bind:this={surface} role="application" aria-label={$t("Web page")} tabindex="0"
|
||||
onmousedown={event => pointer(event, 'mouseDown')} onmouseup={event => pointer(event, 'mouseUp')}
|
||||
onmousemove={event => pointer(event, 'mouseMove')} onwheel={event => pointer(event, 'mouseWheel')}
|
||||
onfocusin={() => pageFocus(true)} onfocusout={event => { if (!surface.contains(event.relatedTarget as Node | null)) pageFocus(false); }}
|
||||
onkeydown={event => key(event, 'keyDown')} onkeyup={event => key(event, 'keyUp')} onblur={stopScroll} onmouseleave={stopScroll} onauxclick={event => event.preventDefault()} oncontextmenu={event => event.preventDefault()}>
|
||||
<textarea class="text-input" bind:this={textInput} aria-label="Web page text input" autocomplete="off" spellcheck="false"
|
||||
<textarea class="text-input" bind:this={textInput} aria-label={$t("Web page text input")} autocomplete="off" spellcheck="false"
|
||||
oncompositionstart={() => composing = true}
|
||||
oncompositionend={event => { composing = false; if (event.data) void orderedInput('insertText', { text: event.data }); textInput.value = ''; }}
|
||||
oninput={() => { if (!composing && textInput.value) { void orderedInput('insertText', { text: textInput.value }); textInput.value = ''; } }}
|
||||
|
||||
Reference in New Issue
Block a user