ui/src/i18n: en.json (20 flat dotted keys) and t(key, params?) with
{name} interpolation; a missing key warns in dev and returns the key.
All template text, title/aria-label attributes, notices and frontend
error texts go through t. ESLint vue/no-bare-strings-in-template is an
error. Catalog tests: interpolation, missing key, every t() key exists,
no unused keys. Engine messages stay English (G14). Docs updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
232 lines
5.8 KiB
Vue
232 lines
5.8 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* A tool window docked on the left side of the main window: a header with
|
|
* the title and a hide button, the content slot, and a splitter on the right
|
|
* edge to resize it. When hidden, a narrow stripe with a button brings it
|
|
* back.
|
|
*
|
|
* The splitter is dragged with the pointer or moved with Left/Right (Shift
|
|
* for larger steps) when focused. Width and visibility are view state of this
|
|
* component, emitted through `v-model:width` and `v-model:open`.
|
|
*/
|
|
import { PanelLeftClose, PanelLeftOpen } from "@lucide/vue";
|
|
import { computed } from "vue";
|
|
import { t } from "../../i18n";
|
|
|
|
/** Props of the tool window. */
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
/** Title shown in the header and as the accessible name. */
|
|
title: string;
|
|
/** Width in CSS pixels. */
|
|
width?: number;
|
|
/** Smallest width the splitter allows. */
|
|
minWidth?: number;
|
|
/** Largest width the splitter allows. */
|
|
maxWidth?: number;
|
|
/** Whether the window is shown (true) or collapsed to its stripe. */
|
|
open?: boolean;
|
|
}>(),
|
|
{ width: 260, minWidth: 140, maxWidth: 640, open: true },
|
|
);
|
|
|
|
/** Events of the tool window. */
|
|
const emit = defineEmits<{
|
|
/** New width after a resize. */
|
|
"update:width": [width: number];
|
|
/** New visibility after hide or show. */
|
|
"update:open": [open: boolean];
|
|
}>();
|
|
|
|
/** Inline style carrying the current width. */
|
|
const style = computed(() => ({ width: `${String(props.width)}px` }));
|
|
|
|
/**
|
|
* Emits a width clamped to the allowed range.
|
|
*
|
|
* @param width - the wanted width.
|
|
*/
|
|
function setWidth(width: number): void {
|
|
emit("update:width", Math.round(Math.min(props.maxWidth, Math.max(props.minWidth, width))));
|
|
}
|
|
|
|
/**
|
|
* Starts a pointer drag on the splitter.
|
|
*
|
|
* @param event - the pointer-down event.
|
|
*/
|
|
function onSplitterDown(event: PointerEvent): void {
|
|
const target = event.currentTarget;
|
|
if (!(target instanceof HTMLElement)) {
|
|
return;
|
|
}
|
|
const startX = event.clientX;
|
|
const startWidth = props.width;
|
|
target.setPointerCapture(event.pointerId);
|
|
const move = (e: PointerEvent): void => {
|
|
setWidth(startWidth + e.clientX - startX);
|
|
};
|
|
const up = (e: PointerEvent): void => {
|
|
target.releasePointerCapture(e.pointerId);
|
|
target.removeEventListener("pointermove", move);
|
|
target.removeEventListener("pointerup", up);
|
|
};
|
|
target.addEventListener("pointermove", move);
|
|
target.addEventListener("pointerup", up);
|
|
}
|
|
|
|
/**
|
|
* Resizes with the keyboard when the splitter has focus.
|
|
*
|
|
* @param event - the key event.
|
|
*/
|
|
function onSplitterKey(event: KeyboardEvent): void {
|
|
const step = event.shiftKey ? 48 : 12;
|
|
if (event.key === "ArrowLeft") {
|
|
setWidth(props.width - step);
|
|
} else if (event.key === "ArrowRight") {
|
|
setWidth(props.width + step);
|
|
} else {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<aside
|
|
v-if="open"
|
|
class="tool-window"
|
|
:style="style"
|
|
:aria-label="title"
|
|
data-test="tool-window"
|
|
>
|
|
<header class="tool-window__header">
|
|
<span class="tool-window__title">{{ title }}</span>
|
|
<button
|
|
type="button"
|
|
class="tool-window__button"
|
|
:title="t('common.toolWindow.hide', { title })"
|
|
:aria-label="t('common.toolWindow.hide', { title })"
|
|
data-test="tool-window-hide"
|
|
@click="emit('update:open', false)"
|
|
>
|
|
<PanelLeftClose :size="16" />
|
|
</button>
|
|
</header>
|
|
<div class="tool-window__body">
|
|
<slot />
|
|
</div>
|
|
<div
|
|
class="tool-window__splitter"
|
|
role="separator"
|
|
aria-orientation="vertical"
|
|
tabindex="0"
|
|
:aria-valuenow="width"
|
|
:aria-valuemin="minWidth"
|
|
:aria-valuemax="maxWidth"
|
|
:aria-label="t('common.toolWindow.resize', { title })"
|
|
data-test="tool-window-splitter"
|
|
@pointerdown="onSplitterDown"
|
|
@keydown="onSplitterKey"
|
|
/>
|
|
</aside>
|
|
<div
|
|
v-else
|
|
class="tool-window-stripe"
|
|
data-test="tool-window-stripe"
|
|
>
|
|
<button
|
|
type="button"
|
|
class="tool-window__button"
|
|
:title="t('common.toolWindow.show', { title })"
|
|
:aria-label="t('common.toolWindow.show', { title })"
|
|
data-test="tool-window-show"
|
|
@click="emit('update:open', true)"
|
|
>
|
|
<PanelLeftOpen :size="16" />
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.tool-window {
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: none;
|
|
min-height: 0;
|
|
background: var(--lt-bg);
|
|
border-right: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.tool-window__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
height: var(--lt-header-height, 28px);
|
|
padding: 0 var(--lt-space-s, 4px) 0 var(--lt-space-m, 8px);
|
|
border-bottom: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.tool-window__title {
|
|
font-weight: 600;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.tool-window__body {
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
|
|
.tool-window__button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: var(--lt-space-xs, 2px);
|
|
color: var(--lt-fg-muted);
|
|
background: transparent;
|
|
border: none;
|
|
border-radius: var(--lt-radius, 4px);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.tool-window__button:hover {
|
|
color: var(--lt-fg);
|
|
background: color-mix(in srgb, var(--lt-fg) 8%, transparent);
|
|
}
|
|
|
|
.tool-window__button:focus-visible {
|
|
outline: 2px solid var(--lt-accent);
|
|
}
|
|
|
|
.tool-window__splitter {
|
|
position: absolute;
|
|
top: 0;
|
|
right: -3px;
|
|
bottom: 0;
|
|
width: 6px;
|
|
cursor: col-resize;
|
|
z-index: 1;
|
|
}
|
|
|
|
.tool-window__splitter:hover,
|
|
.tool-window__splitter:focus-visible {
|
|
outline: none;
|
|
background: color-mix(in srgb, var(--lt-accent) 50%, transparent);
|
|
}
|
|
|
|
.tool-window-stripe {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
flex: none;
|
|
padding: var(--lt-space-s, 4px) var(--lt-space-xs, 2px);
|
|
background: var(--lt-bg);
|
|
border-right: 1px solid var(--lt-border);
|
|
}
|
|
</style>
|