fix(studio): shapes named in every language, the align target kept across selections, up and down in a tab grid

This commit is contained in:
Maurice
2026-10-24 09:34:37 +02:00
parent 82bdf62c7b
commit 9695e269e3
38 changed files with 3143 additions and 14 deletions
@@ -20,7 +20,6 @@ import {
Ungroup,
type LucideIcon,
} from 'lucide-react';
import { useState } from 'react';
import { useStudioStore } from '../../store/studioStore';
import '../../styles/studio-panels.css';
@@ -118,7 +117,8 @@ export function StudioArrangeSection({
const copyStyle = useStudioStore((s) => s.copyStyle);
const pasteStyle = useStudioStore((s) => s.pasteStyle);
const keys = useStudioShortcut();
const [chosenTo, setChosenTo] = useState<BookAlignTo | null>(null);
const chosenTo = useStudioStore((s) => s.alignTo);
const setChosenTo = useStudioStore((s) => s.setAlignTo);
if (!spread || !selection.length) return null;
const sel = spread.elements.filter((e) => selection.includes(e.id));
@@ -2,7 +2,7 @@ import { useId, useState } from 'react'
import { Frame, Minus, Quote, Shapes, Spline, Sparkles, Square, Sticker, Type, type LucideIcon } from 'lucide-react'
import type { BookElement, BookPageSetup, BookShapeId } from '@trek/shared'
import { useStudioStore } from '../../store/studioStore'
import { FRAME_SHAPES, HOLED_SHAPES, SHAPE_GROUPS } from './shapes'
import { FRAME_SHAPES, HOLED_SHAPES, SHAPE_GROUPS, shapeName } from './shapes'
import {
BOOK_GRIDS as GRIDS, MAX_SPREAD_ELEMENTS, bookElementId, bookShapeSize, bookGridElements as gridElements,
defaultBookGridBox as defaultGridBox,
@@ -280,7 +280,8 @@ function ShapesTab({ addShape, t }: { addShape: Adders['addShape']; t: (k: strin
key={shape}
className="st-shape-btn is-glyph"
onClick={() => addShape(shape)}
aria-label={shape}
title={shapeName(shape, t)}
aria-label={shapeName(shape, t)}
>
<ShapeGlyph shape={shape} />
</button>
@@ -319,7 +320,8 @@ function FramesTab({ adders, t }: { adders: Adders; t: (k: string) => string })
key={shape}
className="st-shape-btn is-glyph"
onClick={() => adders.addFrame(shape === 'rect' ? null : shape)}
aria-label={shape}
title={shapeName(shape, t)}
aria-label={shapeName(shape, t)}
>
<ShapeGlyph shape={shape} photo />
</button>
@@ -6,7 +6,7 @@ import { fireEvent, render, screen } from '../../../tests/helpers/render';
import { StudioTabPanel, StudioTabs } from './StudioTabs';
/**
* FE-STUDIO-TABS-001 to FE-STUDIO-TABS-004: the tab rows inside Studio's
* FE-STUDIO-TABS-001 to FE-STUDIO-TABS-005: the tab rows inside Studio's
* panels, as a screen reader and a keyboard meet them, and as a long word
* meets them.
*/
@@ -69,6 +69,20 @@ describe('StudioTabs', () => {
expect(three?.tabIndex).toBe(0);
});
it('FE-STUDIO-TABS-005: in a grid of two lines, up and down move to the tab above or below', () => {
render(<Row />);
const [one, two, three] = screen.getAllByRole('tab');
one?.focus();
fireEvent.keyDown(one as HTMLElement, { key: 'ArrowDown' });
expect(document.activeElement).toBe(three);
fireEvent.keyDown(three as HTMLElement, { key: 'ArrowUp' });
expect(document.activeElement).toBe(one);
two?.focus();
// Nothing below the second tab: the focus stays.
fireEvent.keyDown(two as HTMLElement, { key: 'ArrowDown' });
expect(document.activeElement).toBe(two);
});
it('FE-STUDIO-TABS-003: keeps a long word in a cell that breaks it, and the count as plain figures', () => {
const { container } = render(<Row />);
const label = screen.getByText('Klistermärken');
+11 -3
View File
@@ -15,7 +15,8 @@ import { rovingTarget, runsRtl } from './studioRoving';
* label's own colour, quieter than the word, never a pill inside the tab.
*
* The keyboard is the rail's (studioRoving.ts): the arrows move along the row,
* Enter or Space opens the tab.
* Enter or Space opens the tab. In a grid of more than one line, up and down
* move to the tab above or below.
*/
interface StudioTab<T extends string> {
@@ -45,8 +46,15 @@ export function StudioTabs<T extends string>({
columns?: number;
}) {
const buttons = useRef<(HTMLButtonElement | null)[]>([]);
const across = Math.max(1, Math.min(columns, tabs.length));
const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {
const next = rovingTarget(e.key, index, tabs.length, { vertical: false, rtl: runsRtl(e.currentTarget) });
const below = e.key === 'ArrowDown' ? index + across : e.key === 'ArrowUp' ? index - across : null;
const next =
below !== null && across < tabs.length
? below >= 0 && below < tabs.length
? below
: null
: rovingTarget(e.key, index, tabs.length, { vertical: false, rtl: runsRtl(e.currentTarget) });
if (next === null) return;
e.preventDefault();
buttons.current[next]?.focus();
@@ -56,7 +64,7 @@ export function StudioTabs<T extends string>({
className={`st-subtabs ${tabs.some((tab) => tab.icon) ? 'has-icons' : ''}`}
role="tablist"
aria-label={label}
style={{ gridTemplateColumns: `repeat(${Math.max(1, Math.min(columns, tabs.length))}, minmax(0, 1fr))` }}
style={{ gridTemplateColumns: `repeat(${across}, minmax(0, 1fr))` }}
>
{tabs.map((tab, i) => {
const on = tab.id === value;
@@ -4,7 +4,7 @@ import type { ReactNode } from 'react';
import { useStudioStore } from '../../../store/studioStore';
import { PhotoCropExtras, PhotoLookSections } from '../photo/StudioPhotoLook';
import { FRAME_SHAPES } from '../shapes';
import { FRAME_SHAPES, shapeName } from '../shapes';
import { Choice, Line, NumField, Section } from '../StudioControls';
import { EdgeSection } from '../StudioEdgeControls';
import { ShapeGlyph } from '../StudioElementsPanel';
@@ -178,7 +178,8 @@ export function StudioPhotoInspector({
key={sh}
className={`st-mini-shape ${el.mask === sh ? 'is-on' : ''}`}
onClick={() => set({ mask: sh })}
aria-label={sh}
title={shapeName(sh, t)}
aria-label={shapeName(sh, t)}
aria-pressed={el.mask === sh}
>
<ShapeGlyph shape={sh} />
@@ -1,7 +1,7 @@
import type { BookElement, BookShapeElement, BookShapeId, BookTheme } from '@trek/shared';
import type { ReactNode } from 'react';
import { SHAPE_GROUPS } from '../shapes';
import { SHAPE_GROUPS, shapeName } from '../shapes';
import { NumField, Section } from '../StudioControls';
import { EdgeSection } from '../StudioEdgeControls';
import { ShapeGlyph } from '../StudioElementsPanel';
@@ -41,7 +41,8 @@ export function StudioShapeInspector({
key={sh}
className={`st-mini-shape ${el.shape === sh ? 'is-on' : ''}`}
onClick={() => set({ shape: sh })}
aria-label={sh}
title={shapeName(sh, t)}
aria-label={shapeName(sh, t)}
aria-pressed={el.shape === sh}
>
<ShapeGlyph shape={sh} />
+5
View File
@@ -330,3 +330,8 @@ export const HOLED_SHAPES = new Set<BookShapeId>(['gear', 'postmark', 'label-tab
*/
export const SHAPE_GROUPS = BOOK_SHAPE_GROUPS
export const FRAME_SHAPES = BOOK_FRAME_SHAPES
/** A shape's name in the reader's language, for its tooltip and a screen reader. */
export function shapeName(shape: BookShapeId, t: (k: string) => string): string {
return t(`journey.studio.shapeName.${shape}`)
}