diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index e7f540c6..20777e30 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -680,7 +680,8 @@ function focusedUnderStrip(page: Page) { } /** - * A window too short for the pinned drawing column (U2 Task 17: pinned from 40.25 rem high): + * A window too short for the pinned drawing column (U2 Task 17: pinned from 40.75 rem, 652 px, + * high below 1 280 px wide, 40.25 rem, 644 px, from there): * the drawing scrolls under the strip as before, and the strip's margin brings a focus out. */ const belowPinnedHeight = (page: Page) => diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index f949591b..3517e64a 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -44,7 +44,9 @@ import { type GestureMessages, } from '@/editor/annotations/useGestureMessage' import { + armedTool, initialUi, + TOOL_OF, uiReducer, type ToolId, type Tracing, @@ -316,7 +318,10 @@ function CanvasColumn({ guarded(() => addAtCentre(kind, scene))()} + onArm={(kind, button) => armFromAdd(kind, button, scene)} /> @@ -445,12 +450,29 @@ function CanvasStage({ ) } +/** + * « Ajouter … » pressed once by pointer: arms the kind's tool, or disarms it when armed + * (owner 2026-11-20). Behind the drawing guard (R-12): a started creation or redraw is asked + * about first, never dropped silently. + */ +function armFromAdd( + kind: NewKind, + button: HTMLElement, + { ui, dispatch }: Scene, +) { + const tool = TOOL_OF[kind] + const next = armedTool(ui) === tool ? 'select' : tool + guardedPress(button, () => + dispatch({ type: 'tool', tool: next, from: 'add' }), + ) +} + /** « Ajouter … » (keyboard): the shape at the centre at the A5 size, then its dialog. */ function addAtCentre(kind: NewKind, scene: Scene) { const { frame, doc, viewId, ui } = scene if (!frame) return const size = newPointSize(doc.annotations, viewId, frame, ui.size) - const start = creationStart(scene, 'keyboard') + const start = creationStart(scene, 'add') placePending(start, keyboardPending(kind, frame, size)) } diff --git a/apps/app/src/components/editor/annotations/KeyboardAdd.tsx b/apps/app/src/components/editor/annotations/KeyboardAdd.tsx index 59c60fe2..c96e48fe 100644 --- a/apps/app/src/components/editor/annotations/KeyboardAdd.tsx +++ b/apps/app/src/components/editor/annotations/KeyboardAdd.tsx @@ -1,25 +1,48 @@ +import type { MouseEvent } from 'react' import Button from '@/components/ui/Button' import type { NewKind } from '@/editor/annotations/creation' +import { TOOL_OF, type ToolId } from '@/editor/annotations/uiState' import { useT } from '@/i18n/useT' const KINDS: readonly NewKind[] = ['point', 'zone', 'detail_trigger'] +/** The armed look of the tool column's pressed tool, border kept so nothing moves (A14). */ +const ARMED = + 'data-armed:border-[var(--color-ink)] data-armed:bg-[var(--color-ink)] data-armed:text-white' /** - * The keyboard creation path (C7): each button places a shape at the centre of the frame - * at the A5 size and opens the creation dialog; once created, its handles correct it. + * The add row (owner trial 2026-11-20): one mouse click or tap (`detail` 1) arms the kind's + * tool, or disarms it when armed, so the shape is placed where the drawing is pressed and its + * dialog opens itself; the second click of a double-click (`detail` 2) changes nothing; Enter + * or Space (`detail` 0) keeps the C7 keyboard path: the shape at the centre of the frame at + * the A5 size, its dialog at once. */ export default function KeyboardAdd({ disabled, linkDisabled, + armed, + announce, onAdd, + onArm, }: { /** No measured frame, or no category: nothing can be placed. */ disabled: boolean /** No detail view directly under this view: no link can be placed. */ linkDisabled: boolean + /** The armed tool (`armedTool`): its button shows pressed. */ + armed: ToolId + /** An add button armed the tool: the region says so to a screen reader. */ + announce: boolean onAdd: (kind: NewKind) => void + onArm: (kind: NewKind, button: HTMLElement) => void }) { const t = useT() + const press = (kind: NewKind) => (event: MouseEvent) => { + if (event.detail === 0) onAdd(kind) + else if (event.detail === 1) onArm(kind, event.currentTarget) + } + const armedKind = announce + ? KINDS.find((k) => TOOL_OF[k] === armed) + : undefined return (
{KINDS.map((kind) => ( @@ -28,13 +51,19 @@ export default function KeyboardAdd({ type="button" variant="secondary" size="sm" + className={`min-h-11 xl:min-h-9 ${ARMED}`} data-add-kind={kind} + data-armed={armed === TOOL_OF[kind] ? '' : undefined} disabled={disabled || (kind === 'detail_trigger' && linkDisabled)} - onClick={() => onAdd(kind)} + onClick={press(kind)} > {t(`editor.annotations.add.${kind}`)} ))} + {/* Always mounted: the region exists before its text (M-3). */} +

+ {armedKind ? t(`editor.annotations.armed.${armedKind}`) : ''} +

) } diff --git a/apps/app/src/editor/annotations/creationAsk.ts b/apps/app/src/editor/annotations/creationAsk.ts index 77ab0ced..5a81151d 100644 --- a/apps/app/src/editor/annotations/creationAsk.ts +++ b/apps/app/src/editor/annotations/creationAsk.ts @@ -1,22 +1,16 @@ import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed' import { visibleElement } from '../focusRequest' import { guardDrawing } from './drawingGuard' -import type { NewKind } from './creation' +import { TOOL_OF } from './uiState' import { useAnnotationWork, type Creation } from './workStore' -const TOOL_OF: Record = { - point: 'point', - zone: 'zone', - detail_trigger: 'link', -} - /** * Where the focus goes once a creation is abandoned (board 32): the tool's button, or the - * keyboard « Ajouter … » button that started it. + * « Ajouter … » button that started it. */ export function creationOpener(work: Creation): HTMLElement | null { const { kind } = work.pending - if (work.origin === 'keyboard') { + if (work.origin === 'add') { return visibleElement(`[data-add-kind="${kind}"]`) } return visibleElement(`[data-tool="${TOOL_OF[kind]}"]`) diff --git a/apps/app/src/editor/annotations/creationWork.ts b/apps/app/src/editor/annotations/creationWork.ts index 3f90ce67..0c9a7784 100644 --- a/apps/app/src/editor/annotations/creationWork.ts +++ b/apps/app/src/editor/annotations/creationWork.ts @@ -49,6 +49,7 @@ export function placePending( ...start, form: same ? kept.form : start.form, resumed: same ? kept.resumed : false, + origin: same ? kept.origin : start.origin, pending, closed: true, dialog: true, diff --git a/apps/app/src/editor/annotations/uiState.ts b/apps/app/src/editor/annotations/uiState.ts index 192952d0..1370b060 100644 --- a/apps/app/src/editor/annotations/uiState.ts +++ b/apps/app/src/editor/annotations/uiState.ts @@ -1,8 +1,16 @@ import type { Point } from '@faunosteo/core-wasm/types' import type { NewKind } from './creation' +import type { Creation } from './workStore' export type ToolId = 'select' | 'point' | 'zone' | 'link' +/** The tool that places each kind of new shape. */ +export const TOOL_OF: Record = { + point: 'point', + zone: 'zone', + detail_trigger: 'link', +} + /** * A tracing in progress: a new zone or link, or a polygon replacing a geometry. Only a * redraw's tracing is the reducer's; a new shape's lives in the creation (work store). @@ -19,6 +27,8 @@ export interface Tracing { export interface UiState { viewId: string | null tool: ToolId + /** What armed the tool: an « Ajouter … » button, or the tool column (focus goes back). */ + armedFrom: Creation['origin'] selectedId: string | null tracing: Tracing | null hint: string | null @@ -30,7 +40,7 @@ export interface UiState { export type UiAction = | { type: 'view'; viewId: string } - | { type: 'tool'; tool: ToolId } + | { type: 'tool'; tool: ToolId; from?: 'add' } | { type: 'select'; id: string | null } /** A redraw's tracing (a new shape's is the creation's, U2 Task 7). */ | { type: 'trace_start'; target: 'replace'; annotationId: string } @@ -45,6 +55,7 @@ export type UiAction = export const initialUi: UiState = { viewId: null, tool: 'select', + armedFrom: 'tool', selectedId: null, tracing: null, hint: null, @@ -56,6 +67,13 @@ export const initialUi: UiState = { const toolAfterTracing = (state: UiState): ToolId => state.tracing?.target === 'replace' ? 'select' : state.tool +/** + * The tool the drawing acts with: a redraw lends the zone tool to its tracing, which is + * not an armed tool (« Ajouter une zone » must not show pressed for it). + */ +export const armedTool = (state: Pick): ToolId => + state.tracing?.target === 'replace' ? 'select' : state.tool + /** The tracing with new points: a refusal of its close no longer applies, nor its message. */ function retraced(state: UiState, points: Point[]): UiState { const tracing = state.tracing! @@ -71,7 +89,13 @@ export function uiReducer(state: UiState, action: UiAction): UiState { case 'view': return { ...initialUi, viewId: action.viewId } case 'tool': - return { ...state, tool: action.tool, tracing: null, hint: null } + return { + ...state, + tool: action.tool, + armedFrom: action.from ?? 'tool', + tracing: null, + hint: null, + } case 'select': return { ...state, diff --git a/apps/app/src/editor/annotations/useCreationFollow.ts b/apps/app/src/editor/annotations/useCreationFollow.ts index 36dcab3c..27421868 100644 --- a/apps/app/src/editor/annotations/useCreationFollow.ts +++ b/apps/app/src/editor/annotations/useCreationFollow.ts @@ -1,19 +1,12 @@ import { useEffect, useRef, type Dispatch } from 'react' import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types' import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed' -import type { NewKind } from './creation' import { dropCreationGone } from './creationWork' import { focusRowOrDrawing } from './deselect' -import type { ToolId, UiAction, UiState } from './uiState' +import { TOOL_OF, type UiAction, type UiState } from './uiState' import type { GestureMessages } from './useGestureMessage' import { useAnnotationWork, type Creation } from './workStore' -const TOOL_OF: Record = { - point: 'point', - zone: 'zone', - detail_trigger: 'link', -} - export interface CreationFollow { doc: AnatomicalSheetDocument ui: UiState diff --git a/apps/app/src/editor/annotations/usePlacement.ts b/apps/app/src/editor/annotations/usePlacement.ts index 17c25223..2e8e5281 100644 --- a/apps/app/src/editor/annotations/usePlacement.ts +++ b/apps/app/src/editor/annotations/usePlacement.ts @@ -7,7 +7,12 @@ import type { } from '@faunosteo/core-wasm/types' import { useT } from '@/i18n/useT' import { updateGeometry, type CommitContext } from './annotationCommit' -import { emptyForm, pendingForClick, type NewKind } from './creation' +import { + emptyForm, + keyboardPending, + pendingForClick, + type NewKind, +} from './creation' import { closeTrace, patchPendingShape, @@ -89,6 +94,23 @@ function popTrace({ tracing, dispatch }: PlacementInput): void { else popVertex() } +/** + * The screen-reader path: Enter on the drawing while an add tool is armed and nothing is + * started places the kind's shape at the centre, as the C7 keyboard path does. + */ +function placeAtCentreOnEnter(input: PlacementInput, event: KeyboardEvent) { + const { ui, frame, doc, viewId } = input + if (event.key !== 'Enter' || ui.tool === 'select' || !frame) return + if (useAnnotationWork.getState().creation) return + event.preventDefault() + const kind = TOOL_TARGET[ui.tool] + const size = newPointSize(doc.annotations, viewId, frame, ui.size) + placePending( + creationStart(input, ui.armedFrom), + keyboardPending(kind, frame, size), + ) +} + /** * Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. A * redraw's tracing is the reducer's; a new shape's is the creation's (A12): its Escape @@ -109,10 +131,14 @@ function tracingActions(input: PlacementInput) { if (tracing && nearFirstVertex(tracing, at, reach)) return closeTracing() if (isRedraw(tracing)) return dispatch({ type: 'trace_add', point: asPoint(at) }) - traceVertex(creationStart(input, 'tool'), TOOL_TARGET[tool], asPoint(at)) + traceVertex( + creationStart(input, input.ui.armedFrom), + TOOL_TARGET[tool], + asPoint(at), + ) } const onTraceKey = (event: KeyboardEvent) => { - if (!tracing) return + if (!tracing) return placeAtCentreOnEnter(input, event) if (event.key === 'Enter') closeTracing() if (event.key === 'Backspace') { event.preventDefault() @@ -218,7 +244,7 @@ export function usePlacement(input: PlacementInput) { const outcome = pendingForClick(frame, at, size) if (outcome.kind === 'pending') { dispatch({ type: 'hint', hint: null }) - return placePending(creationStart(input, 'tool'), outcome.pending) + return placePending(creationStart(input, ui.armedFrom), outcome.pending) } dispatch({ type: 'hint', hint: t('editor.annotations.outside') }) } diff --git a/apps/app/src/editor/annotations/workStore.ts b/apps/app/src/editor/annotations/workStore.ts index 4f10bebb..eb884926 100644 --- a/apps/app/src/editor/annotations/workStore.ts +++ b/apps/app/src/editor/annotations/workStore.ts @@ -29,8 +29,8 @@ export interface Creation { viewId: string /** F of the view when the shape was placed: the point's verdict works from it. */ frame: Frame | null - /** A tool on the drawing, or a keyboard « Ajouter … » (where the focus goes back). */ - origin: 'tool' | 'keyboard' + /** A tool of the column, or an « Ajouter … » button (where the focus goes back). */ + origin: 'tool' | 'add' /** A new zone or link being traced lives here from its first vertex (`closed` false). */ pending: PendingElement closed: boolean diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 99181cb8..b46e9449 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1767,6 +1767,12 @@ export const en: Dict = { 'editor.annotations.add.point': 'Add a point', 'editor.annotations.add.zone': 'Add a zone', 'editor.annotations.add.detail_trigger': 'Add a link', + 'editor.annotations.armed.point': + 'Point tool on: tap or click the drawing where you want it, or press Enter on the drawing to place the point at the centre.', + 'editor.annotations.armed.zone': + 'Zone tool on: place the vertices on the drawing, or press Enter on the drawing to place a zone at the centre.', + 'editor.annotations.armed.detail_trigger': + 'Link tool on: place the vertices on the drawing, or press Enter on the drawing to place a link at the centre.', 'editor.annotations.new.point': 'New point', 'editor.annotations.new.zone': 'New zone', 'editor.annotations.new.detail_trigger': 'New link', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index 45b7d63b..d739419e 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1833,6 +1833,12 @@ export const fr: Dict = { 'editor.annotations.add.point': 'Ajouter un point', 'editor.annotations.add.zone': 'Ajouter une zone', 'editor.annotations.add.detail_trigger': 'Ajouter un accès', + 'editor.annotations.armed.point': + "Outil Point actif : touchez ou cliquez le dessin à l'endroit voulu, ou appuyez sur Entrée dans le dessin pour placer le point au centre.", + 'editor.annotations.armed.zone': + 'Outil Zone actif : posez les sommets sur le dessin, ou appuyez sur Entrée dans le dessin pour placer une zone au centre.', + 'editor.annotations.armed.detail_trigger': + 'Outil Accès actif : posez les sommets sur le dessin, ou appuyez sur Entrée dans le dessin pour placer un accès au centre.', 'editor.annotations.new.point': 'Nouveau point', 'editor.annotations.new.zone': 'Nouvelle zone', 'editor.annotations.new.detail_trigger': 'Nouvel accès', diff --git a/apps/app/src/styles/index.css b/apps/app/src/styles/index.css index 37efc259..422a62fb 100644 --- a/apps/app/src/styles/index.css +++ b/apps/app/src/styles/index.css @@ -63,26 +63,33 @@ body, } /* The drawing column (chips, tools, canvas, add row, message line) is pinned under the strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task - 17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px - tool column beside a capped canvas does not, nothing here applies and nothing is - pinned. The negative bottom margin lets the pinned travel run into the page's bottom - space (workspace gap + main padding): without it, the page's end pushed the column's - top under the strip at 1 180 x 820. */ -@media (min-width: 1024px) and (min-height: 40.25rem) { + 17). Only where the column fits: below 40.75rem (652 px) of window height under 1 280 px + wide, 40.25rem (644 px) from there, the 365 px tool column beside a capped canvas does + not, nothing here applies and nothing is pinned. Under 1 280 px the add row is 44 px + high (a finger target, owner trial 2026-11-20), 8 px more than from 1 280 px. The + negative bottom margin lets the pinned travel run into the page's bottom space + (workspace gap + main padding): without it, the page's end pushed the column's top + under the strip at 1 180 x 820. */ +@media (min-width: 1024px) and (max-width: 1279.98px) and (min-height: 40.75rem), + (min-width: 1280px) and (min-height: 40.25rem) { [data-drawing-column] { + --edit-column-parts: 9.75rem; position: sticky; top: var(--edit-pinned-top); align-self: start; margin-bottom: -3rem; } /* The column fits the window: the 4:3 box's width is capped by the small viewport height - less the pinned top and the column's other parts (one row of chips, the add row, the - line, the gaps: 9.25rem), plus its 2 px border. svh: a toolbar collapsing during a - scroll never resizes the box. Unchanged when the browser window (not the screen) is + less the pinned top and the column's other parts, plus its 2 px border. The parts: + chips 30 + gaps 36 + add row 44 + line 44 + border 2 = 156 px, 9.75rem; from 1 280 px + the add row is 36 px, 148 px, 9.25rem. svh: a toolbar collapsing during a scroll + never resizes the box. Unchanged when the browser window (not the screen) is 1 024 x 768, 1 180 x 820 or 1 280 x 800; smaller in shorter windows (capped below - 672, 789 and 672 px of window height). */ + 680, 797 and 672 px of window height). */ [data-drawing-column] [data-canvas-box] { - max-width: calc((100svh - var(--edit-pinned-top) - 9.25rem) * 4 / 3 + 2px); + max-width: calc( + (100svh - var(--edit-pinned-top) - var(--edit-column-parts)) * 4 / 3 + 2px + ); } /* A pinned control is never under the strip: the strip's margin, larger than the pinned top, made a focus on it scroll the page (Task 14's jump). The bar's margin stays. Same @@ -102,6 +109,11 @@ body, scroll-margin-top: calc(var(--shell-top-bar-height) + 0.5rem); } } +@media (min-width: 1280px) and (min-height: 40.25rem) { + [data-drawing-column] { + --edit-column-parts: 9.25rem; + } +} /* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */ html:has(dialog:modal) { overflow: hidden; diff --git a/apps/app/tests/unit/editor-add-buttons.test.tsx b/apps/app/tests/unit/editor-add-buttons.test.tsx new file mode 100644 index 00000000..d03ee28a --- /dev/null +++ b/apps/app/tests/unit/editor-add-buttons.test.tsx @@ -0,0 +1,302 @@ +/** U2 trial adjustments, Task 6: « Ajouter … » arms its tool on a pointer press. */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { + cleanup, + render, + screen, + waitFor, + within, +} from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import type { Annotation, Point } from '@faunosteo/core-wasm/types' +import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore' +import { en } from '@/i18n/en' +import { fr } from '@/i18n/fr' +import { useLocaleStore } from '@/state/localeStore' +import { drawnText, insert, point } from '../helpers/editorFixtures' +import { LayeredTab } from '../helpers/annotationLayer' +import { + addByKeyboard, + openReady, + pressAt, + resetStore, +} from '../helpers/editorHarness' + +vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) +vi.mock('@faunosteo/supabase', async (orig) => ({ + ...(await orig()), + getSheetVersion: vi.fn(), + downloadSheetDrawing: vi.fn(), + saveSheetDraft: vi.fn(), + getOfficialSheetAdmin: vi.fn(), + submitSheetReview: vi.fn(), +})) + +const props = { + readOnly: false, + navigate: vi.fn(), + reloadSheet: vi.fn(), + section: 'drawing' as const, + visited: ['drawing'] as const, + onOpenSection: vi.fn(), + onBack: vi.fn(), +} + +function stubCtm(): void { + const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 } + Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', { + configurable: true, + value: () => ({ ...identity, inverse: () => identity }), + }) +} + +beforeEach(() => { + useLocaleStore.setState({ locale: 'fr' }) + stubCtm() +}) +afterEach(() => { + cleanup() + resetStore() + resetWork() +}) + +const SQUARE: Point[] = [ + [20, 20], + [80, 20], + [80, 80], + [20, 80], +] +const withZone = () => + insert(drawnText(), { + kind: 'annotation', + value: { + ...(point('zone-a', 0, 0, 1).value as Annotation), + kind: 'zone', + geometry: { type: 'polygon', points: SQUARE }, + name: { fr: 'N', en: 'N' }, + }, + } as never) +const withDetail = () => + insert(drawnText(), { + kind: 'view', + value: { + kind: 'detail', + id: 'view-det', + name: { fr: 'Tête', en: 'Head' }, + svg_asset_id: null, + view_box: { min_x: 10, min_y: 10, width: 80, height: 80 }, + parent_view_id: 'view-main', + }, + } as never) + +async function mount(text = drawnText()) { + await openReady({ text }) + render() + await waitFor(() => + expect(screen.getByRole('button', { name: 'Point' })).toBeEnabled(), + ) + return userEvent.setup() +} + +const canvas = () => screen.getByTestId('annotation-canvas') +const add = (what: 'un point' | 'une zone' | 'un accès') => + screen.getByRole('button', { name: `Ajouter ${what}` }) +const tool = (name: string) => screen.getByRole('button', { name }) +const lead = () => + within(screen.getByTestId('edit-strip')).getByTestId('edit-strip-lead') +const ghost = () => + screen.getByTestId('overlay-ghost').querySelector('circle, polygon')! +const status = () => + add('un point').parentElement!.querySelector('[role="status"]')! +const dialog = (name: string) => screen.findByRole('dialog', { name }) +const noDialog = () => expect(screen.queryByRole('dialog')).toBeNull() + +/** The creation dialog's « Abandonner », then the confirmation inside it. */ +async function abandon(user: ReturnType) { + const shown = screen.getByTestId('annotation-creation') + await user.click(within(shown).getByRole('button', { name: 'Abandonner' })) + const ask = within(shown).getByRole('group', { + name: 'Abandonner la création ?', + }) + await user.click(within(ask).getByRole('button', { name: 'Abandonner' })) +} + +describe('« Ajouter … » pressed by pointer arms its tool', () => { + it('arms the Point tool, says where to click, opens no dialog', async () => { + const user = await mount() + await user.click(add('un point')) + noDialog() + expect(tool('Point')).toHaveAttribute('aria-pressed', 'true') + expect(add('un point')).toHaveAttribute('data-armed') + expect(lead()).toHaveTextContent('Ajouter un point') + expect(lead()).toHaveTextContent( + 'Cliquez dans le dessin pour placer le point', + ) + }) + + it('a click in the drawing places the point there and opens its dialog', async () => { + const user = await mount() + await user.click(add('un point')) + pressAt(canvas(), 30, 40) + await dialog('Nouveau point') + expect(ghost()).toHaveAttribute('cx', '30') + expect(ghost()).toHaveAttribute('cy', '40') + }) + + it('abandoning that creation focuses « Ajouter un point »', async () => { + const user = await mount() + await user.click(add('un point')) + pressAt(canvas(), 30, 40) + await dialog('Nouveau point') + await abandon(user) + await waitFor(() => expect(add('un point')).toHaveFocus()) + }) + + it('« Replacer le point » then a second click keeps the origin', async () => { + const user = await mount() + await user.click(add('un point')) + pressAt(canvas(), 30, 40) + const shown = await dialog('Nouveau point') + await user.click( + within(shown).getByRole('button', { name: 'Replacer le point' }), + ) + await waitFor(noDialog) + pressAt(canvas(), 60, 60) + await dialog('Nouveau point') + expect(ghost()).toHaveAttribute('cx', '60') + await user.click( + within(screen.getByTestId('annotation-creation')).getByRole('button', { + name: 'Replacer le point', + }), + ) + await waitFor(noDialog) + await user.click( + within(screen.getByTestId('edit-strip')).getByRole('button', { + name: 'Abandonner', + }), + ) + const ask = await screen.findByRole('dialog', { + name: 'Abandonner la création ?', + }) + await user.click(within(ask).getByRole('button', { name: 'Abandonner' })) + await waitFor(() => expect(add('un point')).toHaveFocus()) + }) + + it('a second click on the armed button disarms it', async () => { + const user = await mount() + await user.click(add('un point')) + await user.click(add('un point')) + expect(tool('Sélectionner et déplacer')).toHaveAttribute( + 'aria-pressed', + 'true', + ) + expect(add('un point')).not.toHaveAttribute('data-armed') + }) + + it('a started zone asks before the button disarms it', async () => { + const user = await mount() + await user.click(add('une zone')) + pressAt(canvas(), 20, 20) + await user.click(add('une zone')) + const ask = await screen.findByRole('dialog', { + name: 'Abandonner la création ?', + }) + expect(useAnnotationWork.getState().creation).not.toBeNull() + await user.click(within(ask).getByRole('button', { name: 'Continuer' })) + expect(useAnnotationWork.getState().creation).not.toBeNull() + expect(add('une zone')).toHaveAttribute('data-armed') + await user.click(add('une zone')) + await user.click( + within( + await screen.findByRole('dialog', { name: 'Abandonner la création ?' }), + ).getByRole('button', { name: 'Abandonner' }), + ) + expect(useAnnotationWork.getState().creation).toBeNull() + expect(add('une zone')).not.toHaveAttribute('data-armed') + }) + + it('a double-click leaves the tool armed', async () => { + const user = await mount() + await user.dblClick(add('un point')) + expect(add('un point')).toHaveAttribute('data-armed') + expect(tool('Point')).toHaveAttribute('aria-pressed', 'true') + }) +}) + +describe('the keyboard keeps the centre path (C7)', () => { + it('Enter and Space place at the centre with the dialog at once', async () => { + const user = await mount(withDetail()) + await user.click(add('un accès')) + noDialog() + expect(add('un accès')).toHaveAttribute('data-armed') + await user.click(tool('Sélectionner et déplacer')) + await addByKeyboard(user, add('un point')) + await dialog('Nouveau point') + expect(ghost()).toHaveAttribute('cx', '50') + await abandon(user) + await waitFor(() => expect(add('un point')).toHaveFocus()) + add('un accès').focus() + await user.keyboard(' ') + await dialog('Nouvel accès') + }) +}) + +describe('the screen-reader path', () => { + it('announces the armed tool, then Enter in the drawing places at the centre', async () => { + const user = await mount() + expect(status()).toBeEmptyDOMElement() + await user.click(add('un point')) + expect(status()).toHaveTextContent('Outil Point actif') + expect(status()).toHaveTextContent('Entrée dans le dessin') + canvas().focus() + await user.keyboard('{Enter}') + await dialog('Nouveau point') + expect(ghost()).toHaveAttribute('cx', '50') + await abandon(user) + await waitFor(() => expect(add('un point')).toHaveFocus()) + }) + + it('the same for a zone: a centre triangle and its dialog', async () => { + const user = await mount() + await user.click(add('une zone')) + expect(status()).toHaveTextContent('Outil Zone actif') + canvas().focus() + await user.keyboard('{Enter}') + await dialog('Nouvelle zone') + expect(ghost().tagName).toBe('polygon') + await abandon(user) + await waitFor(() => expect(add('une zone')).toHaveFocus()) + }) + + it('with the Select tool, Enter on the drawing creates nothing', async () => { + const user = await mount() + canvas().focus() + await user.keyboard('{Enter}') + noDialog() + expect(useAnnotationWork.getState().creation).toBeNull() + }) +}) + +describe('a redraw lends the zone tool', () => { + it('« Ajouter une zone » is not armed, and arms a NEW zone when pressed', async () => { + const user = await mount(withZone()) + const list = await screen.findByRole('list', { + name: 'Annotations de la vue', + }) + await user.click(within(list).getAllByRole('button')[0]) + await user.click(await screen.findByRole('button', { name: 'Redessiner' })) + expect(add('une zone')).not.toHaveAttribute('data-armed') + await user.click(add('une zone')) + expect(add('une zone')).toHaveAttribute('data-armed') + expect(useAnnotationWork.getState().mode).toBeNull() + expect(lead()).not.toHaveTextContent('Redessiner') + }) +}) + +describe('the dictionaries', () => { + it('carry the three armed announcements in both languages', () => { + for (const dict of [fr, en]) + for (const kind of ['point', 'zone', 'detail_trigger']) + expect(dict[`editor.annotations.armed.${kind}`]).toBeTruthy() + }) +}) diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index 1234d80a..cfa717eb 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -859,8 +859,10 @@ describe('I-3: the click a touch tap synthesises is absorbed', () => { screen.getByRole('button', { name: 'Ajouter un point' }) /** A click at the tap's own place, as the browser synthesises it. */ const clickAtTap = (el: Element) => - fireEvent.click(el, { clientX: 50, clientY: 50 }) - const creation = () => screen.queryByTestId('annotation-creation') + fireEvent.click(el, { clientX: 50, clientY: 50, detail: 1 }) + const armed = () => addPoint().hasAttribute('data-armed') + const pointPressed = () => + screen.getByRole('button', { name: 'Point' }).getAttribute('aria-pressed') it('a touch tap: its click landing elsewhere does nothing; the next click does', async () => { await mount(squareText()) @@ -868,26 +870,31 @@ describe('I-3: the click a touch tap synthesises is absorbed', () => { tapOn(screen.getByTestId('annotation-canvas'), 'touch') expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull() clickAtTap(addPoint()) - expect(creation()).toBeNull() + expect(armed()).toBe(false) + expect(pointPressed()).toBe('false') clickAtTap(addPoint()) - expect(creation()).not.toBeNull() + expect(armed()).toBe(true) + expect(pointPressed()).toBe('true') }) it('a pen tap is absorbed too; a mouse tap never is', async () => { await mount(squareText()) tapOn(screen.getByTestId('annotation-canvas'), 'pen') clickAtTap(addPoint()) - expect(creation()).toBeNull() + expect(armed()).toBe(false) + expect(pointPressed()).toBe('false') tapOn(screen.getByTestId('annotation-canvas'), 'mouse') clickAtTap(addPoint()) - expect(creation()).not.toBeNull() + expect(armed()).toBe(true) + expect(pointPressed()).toBe('true') }) it('a click elsewhere right after a tap goes through', async () => { await mount(squareText()) tapOn(screen.getByTestId('annotation-canvas'), 'touch') - fireEvent.click(addPoint(), { clientX: 300, clientY: 300 }) - expect(creation()).not.toBeNull() + fireEvent.click(addPoint(), { clientX: 300, clientY: 300, detail: 1 }) + expect(armed()).toBe(true) + expect(pointPressed()).toBe('true') }) it('a real click after the double-click window goes through', async () => { @@ -897,7 +904,8 @@ describe('I-3: the click a touch tap synthesises is absorbed', () => { tapOn(screen.getByTestId('annotation-canvas'), 'touch') act(() => void vi.advanceTimersByTime(450)) clickAtTap(addPoint()) - expect(creation()).not.toBeNull() + expect(armed()).toBe(true) + expect(pointPressed()).toBe('true') } finally { vi.useRealTimers() } diff --git a/docs/ANNOTATION-RENDERING.md b/docs/ANNOTATION-RENDERING.md index ac7a4cda..6e0608f1 100644 --- a/docs/ANNOTATION-RENDERING.md +++ b/docs/ANNOTATION-RENDERING.md @@ -255,7 +255,8 @@ the strip is not sticky. The drawing column (U2 Task 17: the view chips, the tools and the canvas box, the add row, the message line; `data-drawing-column`) is pinned under the strip -from 1 024 px wide and 40.25 rem (644 px) high: `sticky` at `--edit-pinned-top` +from 1 024 px wide and 40.75 rem (652 px) high below 1 280 px wide, 40.25 rem (644 px) +high from there: `sticky` at `--edit-pinned-top` (bar + strip + 0.75 rem, the strip's gap), aligned to the start of its grid row, so no part of it ever passes under the strip or the bar while the side panel scrolls past; the side panel still passes under the strip. A bottom margin of @@ -263,20 +264,22 @@ scrolls past; the side panel still passes under the strip. A bottom margin of gap and the main area's padding), else the end of the page pushed the column's top under the strip at 1 180 × 820. So that the column always fits the window, the canvas box (`data-canvas-box`) is capped in width at -`(100svh − --edit-pinned-top − 9.25 rem) × 4/3 + 2 px` (9.25 rem: one row of -chips, one add row, the line and the gaps; 2 px: the box's border), keeping its +`(100svh − --edit-pinned-top − --edit-column-parts) × 4/3 + 2 px` +(`--edit-column-parts`: one row of chips, one add row, the line and the gaps, +9.25 rem from 1 280 px wide where the add row is 36 px high, 9.75 rem below, +where the trial made it 44 px; 2 px: the box's border), keeping its 4:3 ratio: the cap follows the window's small viewport height, never the scroll nor a collapsing browser toolbar. The box is unchanged when the browser window (not the screen) is 1 024 × 768, 1 180 × 820 or 1 280 × 800, and smaller in -shorter windows (capped below 672, 789 and 672 px of window height at those +shorter windows (capped below 680, 797 and 672 px of window height at those widths; a tablet's browser toolbars take their height off the screen's); a capped box sits left, with spare width on its right. The column's focusables carry only the bar's margin there (the strip's margin, larger than the pinned -top, would scroll the page on a focus of a pinned control). The 9.25 rem assumes +top, would scroll the page on a focus of a pinned control). The column parts assume one row of view chips: a sheet whose chips wrap to a second row makes the column about 38 px taller than the cap allows, so where the cap binds the column's top -goes under the strip at the end of the page. Below 644 px of window height the -tool column (365 px) no longer fits beside a capped box: nothing is pinned or +goes under the strip at the end of the page. Below 652 px of window height +(644 px from 1 280 px wide) the tool column (365 px) no longer fits beside a capped box: nothing is pinned or capped, and the drawing scrolls under the strip as before, with the strip's margin on its focusables.