fix(viewer): make chat translation controls compact

This commit is contained in:
coyotte508 2026-09-21 21:53:18 +02:00
commit 44982d6331
4 changed files with 58 additions and 43 deletions

View file

@ -1,6 +1,6 @@
{
"name": "fuji-viewer",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"license": "AGPL-3.0-only",
"type": "module",
@ -11,7 +11,7 @@
"test:tutorial": "node --test src/tutorial/*.spec.ts"
},
"dependencies": {
"@boardgamers/protocol": "0.4.0",
"@boardgamers/protocol": "0.4.2",
"fuji-engine": "workspace:*"
},
"devDependencies": {

View file

@ -1,19 +1,14 @@
<script lang="ts">
import { chatDateSeparators, chatTranslationTitle } from "@boardgamers/protocol/chat";
import {
chatDateSeparators,
chatTranslationTitle,
chatTranslationLabel,
chatTranslationIconPath,
} from "@boardgamers/protocol/chat";
import type { Store } from "./store.svelte";
import { bindChatComposer, bindChatViewport, type ChatSuggestions } from "@boardgamers/protocol/chat/dom";
let { store }: { store: Store } = $props();
const chat = $derived(store.chatState);
const labels = $derived(
chat.translationLabels ?? {
translate: "Translate",
translating: "Translating…",
translated: "Translated",
original: "Show original",
retry: "Retry",
error: "Translation unavailable",
}
);
const dates = $derived(chatDateSeparators(chat.messages));
let composer: HTMLInputElement | undefined = $state();
let list: HTMLDivElement | undefined = $state();
@ -126,24 +121,32 @@
>{/if}
{:else}{segment.text}{/if}
{/each}
{#if message._id && message.type === "text" && chat.translationTarget}
{@const label = chatTranslationLabel(translation, chat.translationLabels)}
<button
type="button"
class="chat-translate"
disabled={!!translation?.pending}
aria-label={label}
aria-pressed={!!translation?.shown}
aria-busy={!!translation?.pending}
title={`${label} (${chatTranslationTitle(translation?.language ?? message.language, chat.translationTarget)})`}
onclick={() => store.chat.toggleTranslation(message._id!)}
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"><path d={chatTranslationIconPath} /></svg
>
</button>
{/if}
</p>
{#if message._id && message.type === "text" && chat.translationTarget}
<button
type="button"
class="chat-translate"
disabled={!!translation?.pending}
title={chatTranslationTitle(translation?.language ?? message.language, chat.translationTarget)}
onclick={() => store.chat.toggleTranslation(message._id!)}
>{translation?.pending
? labels.translating
: translation?.shown
? `${labels.translated} · ${labels.original}`
: translation?.error
? `${labels.error} · ${labels.retry}`
: labels.translate}</button
>
{/if}
</article>
{/each}
</div>
@ -174,19 +177,31 @@
<style>
.chat-translate {
min-height: 24px;
padding: 2px 4px;
margin-left: 4px;
display: inline-flex;
align-items: center;
justify-content: center;
vertical-align: middle;
width: 24px;
height: 24px;
min-height: 0;
padding: 4px;
margin-left: 3px;
border: 0;
border-radius: 3px;
background: transparent;
color: inherit;
font: inherit;
font-size: 11px;
text-decoration: underline;
opacity: 0.55;
cursor: pointer;
}
.chat-translate:hover,
.chat-translate:focus-visible {
opacity: 1;
}
.chat-translate[aria-pressed="true"] {
opacity: 1;
background: #e6c78025;
}
.chat-translate:disabled {
opacity: 0.65;
cursor: wait;
}
.chat-day {

10
pnpm-lock.yaml generated
View file

@ -34,8 +34,8 @@ importers:
packages/viewer:
dependencies:
'@boardgamers/protocol':
specifier: 0.4.0
version: 0.4.0
specifier: 0.4.2
version: 0.4.2
fuji-engine:
specifier: workspace:*
version: link:../engine
@ -61,8 +61,8 @@ importers:
packages:
'@boardgamers/protocol@0.4.0':
resolution: {integrity: sha512-dqrU94QGPZAh7vWhHmu2AHY6bFo7NbNVytb3dyUidou8R6P0FfT3xm0qLR8LbrE4EHEYmm99LajdfTfKmgwEzQ==}
'@boardgamers/protocol@0.4.2':
resolution: {integrity: sha512-dFWwj/uIR8LZuiFSPX++63f4Ivd3cG4JFFWCCObOu6u5RYw5GBT95rcSIiiWRLkBkXWKXgv3awQ/RMrAf+uFDQ==}
'@jridgewell/gen-mapping@0.3.13':
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
@ -631,7 +631,7 @@ packages:
snapshots:
'@boardgamers/protocol@0.4.0':
'@boardgamers/protocol@0.4.2':
dependencies:
zod: 4.6.2

View file

@ -1,5 +1,5 @@
packages:
- packages/*
minimumReleaseAgeExclude:
- "@boardgamers/protocol@0.4.0"
- "@boardgamers/protocol@0.4.0 || 0.4.2"
- "@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3"