feat(editor): fixed edit strip and message line without layout shift

U2 Task 3 (A6, A14, R-2). A fixed-height strip over the drawing and the
right column replaces the tool line, the sr-only selection tag of the
edit body and TracingBar: lead (name + status, type + detail), notice
(refusal, first geometry issue + n, unmeasured view with its link, no
category, no child view), commands (Fermer le trace, Retirer le dernier
sommet, Annuler le trace). A fixed-height line under the drawing holds
the add buttons and the gesture message: a kept drop says « Point
deplace » with « Defaire » (same store undo as the header), a refused
drop says « Deplacement refuse : ... » as a red alert. 6 s, held by
mouse hover and focus inside, closed by any commit, undo or redo.
trace_pop and Backspace remove the last vertex. The busy « Aller a »
target is the strip's tracing commands. scrollbar-gutter stable, scoped
to the editor. e2e helper expectNoShift (boxes, scroll height, gutter,
client width, layout-shift sum). DraftHeader untouched: no shift seen.

Rewritten assertions (old -> new):
- tab unit « Sélection : point » on annotation-selection-tag -> strip
  detail « Point »
- tab unit tag sr-only, not live -> strip lead outside any live region
- tab unit « 1 sommet posé. » -> « 1 sommet posé » (board 04 wording)
- tab unit D6b tag present / « zone » -> strip detail « Point » /
  « Zone · 3 sommets »
- keep-alive, sections, escape units: tracing-bar -> tracing-commands
- e2e selectionTag helper -> strip title with data-selection; the
  twin's tag is twinSelectionTag (deselect 375 px describe)
- e2e deselect « tag position absolute » (edit) -> strip height 64 px,
  drawing top unchanged; twin Escape test keeps tag 0, properties 0,
  overview visible
- e2e deselect and journey tracing-bar / annotation-selection-tag ->
  tracing-commands / selectionTag
- e2e historyButton scoped to history-buttons (the message's
  « Défaire » has the same accessible name)
This commit is contained in:
bchanot committed 2026-11-17 17:45:41 +01:00
1 parent b2d78f9621
commit 1deb037fac
23 files changed
+1228 -181

No files matched your search

@@ -35,7 +35,7 @@ export interface DrawingState {
const BUSY_TARGET = {
creation: '[data-creation-heading]',
tracing: '[data-testid="tracing-bar"]',
tracing: '[data-testid="tracing-commands"]',
} as const
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
@@ -70,8 +70,8 @@ function showAnnotation(
/**
* « Aller à » an annotation on the drawing: shows its view, selects it, then focuses the
* properties heading once it has rendered. While a creation or a tracing is in progress
* the request is kept: nothing is dispatched (it would drop the work), the panel or bar
* takes the focus and the live region says why.
* the request is kept: nothing is dispatched (it would drop the work), the panel or the
* strip's tracing commands take the focus and the live region says why.
*/
export function useAnnotationRequest(
focus: FocusRequest | undefined,
@@ -0,0 +1,161 @@
import type {
Annotation,
AnatomicalSheetDocument,
ReviewStatus,
SheetView,
} from '@faunosteo/core-wasm/types'
import { annotationName } from '@/components/editor/annotations/AnnotationList'
import type { GlyphName } from '@/components/editor/EditorGlyph'
import type { Locale } from '@/i18n/types'
import { pluralKey } from '../plural'
import type { PendingElement } from './creation'
import type { ToolId, Tracing, UiState } from './uiState'
/** The strip's left part: what is selected or in progress, then its type and detail. */
export interface StripLead {
title: string
status?: ReviewStatus
detail: string
icon: GlyphName
}
export interface LeadContext {
t: (key: string) => string
locale: Locale
/** The sheet cannot be edited now: the detail says so (board 33 E). */
readOnly?: boolean
}
const ICON: Record<Annotation['kind'], GlyphName> = {
point: 'point',
zone: 'zone',
detail_trigger: 'link',
}
/** A count phrase of `key`; `{kind}` is filled too when given. */
function counted(
ctx: LeadContext,
key: string,
count: number,
kind = '',
): string {
return ctx
.t(pluralKey(ctx.locale, key, count))
.replace('{count}', String(count))
.replace('{kind}', () => kind)
}
/** « Point », « Zone · 9 sommets »; « … · fiche en lecture seule » when read-only. */
export function selectionLead(
annotation: Annotation,
views: readonly SheetView[],
ctx: LeadContext,
): StripLead {
const kind = ctx.t(`editor.annotations.kind.${annotation.kind}`)
const geometry = annotation.geometry
const shape =
geometry?.type === 'polygon'
? counted(
ctx,
'editor.annotations.strip.vertices',
geometry.points.length,
kind,
)
: kind
return {
title: annotationName(annotation, views, ctx.locale),
status: annotation.review_status,
detail: ctx.readOnly
? ctx
.t('editor.annotations.strip.read_only')
.replace('{detail}', () => shape)
: shape,
icon: ICON[annotation.kind],
}
}
/** A tracing: « Ajouter une zone » or « Redessiner · {nom} », then the vertices placed. */
function tracingLead(
tracing: Tracing,
replaced: string,
ctx: LeadContext,
): StripLead {
const title =
tracing.target === 'replace'
? ctx
.t('editor.annotations.strip.redraw')
.replace('{name}', () => replaced)
: ctx.t(`editor.annotations.add.${tracing.target}`)
return {
title,
detail: counted(ctx, 'editor.annotations.tracing', tracing.points.length),
icon: tracing.target === 'detail_trigger' ? 'link' : 'zone',
}
}
/** A pending creation, placed or closed, waiting for its properties. */
function pendingLead(pending: PendingElement, ctx: LeadContext): StripLead {
const { geometry } = pending
return {
title: ctx.t(`editor.annotations.new.${pending.kind}`),
detail:
geometry.type === 'polygon'
? counted(
ctx,
'editor.annotations.strip.closed',
geometry.points.length,
)
: ctx.t('editor.annotations.strip.placed'),
icon: ICON[pending.kind],
}
}
const TOOL_LEAD: Record<
ToolId,
{ title: string; detail: string; icon: GlyphName }
> = {
select: {
title: 'editor.annotations.tool.select',
detail: 'editor.annotations.strip.select',
icon: 'select',
},
point: {
title: 'editor.annotations.add.point',
detail: 'editor.annotations.strip.place_point',
icon: 'point',
},
zone: {
title: 'editor.annotations.add.zone',
detail: 'editor.annotations.strip.first_vertex',
icon: 'zone',
},
link: {
title: 'editor.annotations.add.detail_trigger',
detail: 'editor.annotations.strip.first_vertex',
icon: 'link',
},
}
/** What the strip leads with: a creation, then a tracing, then the selection, then the tool. */
export function stripLeadOf(
ui: UiState,
selected: Annotation | undefined,
doc: AnatomicalSheetDocument,
ctx: LeadContext,
): StripLead {
if (ui.pending) return pendingLead(ui.pending, ctx)
if (ui.tracing) {
const replaced = doc.annotations.find(
(a) => a.id === ui.tracing?.annotationId,
)
const name = replaced ? annotationName(replaced, doc.views, ctx.locale) : ''
return tracingLead(ui.tracing, name, ctx)
}
if (selected) return selectionLead(selected, doc.views, ctx)
const lead = TOOL_LEAD[ui.tool]
return {
title: ctx.t(lead.title),
detail: ctx.t(lead.detail),
icon: lead.icon,
}
}
@@ -33,6 +33,7 @@ export type UiAction =
| { type: 'pending_drop' }
| { type: 'trace_start'; target: Tracing['target']; annotationId?: string }
| { type: 'trace_add'; point: Point }
| { type: 'trace_pop' }
| { type: 'trace_cancel' }
| { type: 'hint'; hint: string | null }
| { type: 'filter'; term: string }
@@ -108,6 +109,16 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
},
}
: state
case 'trace_pop':
return state.tracing
? {
...state,
tracing: {
...state.tracing,
points: state.tracing.points.slice(0, -1),
},
}
: state
case 'trace_cancel':
return { ...state, tracing: null, hint: null }
case 'hint':
@@ -0,0 +1,93 @@
import { useEffect, useState, type FocusEvent, type PointerEvent } from 'react'
import { useEditorStore } from '../state/editorStore'
/** A6/A14: how long a message stays (R-2) and how long a hint does (R-1). */
const MESSAGE_MS = 6_000
const HINT_MS = 4_000
/** The document and the history a message was shown on: any change closes it (R-2). */
interface Stamp {
text: string
undo: number
redo: number
}
export interface GestureMessage {
text: string
tone: 'info' | 'error'
/** Offers « Défaire » (a kept gesture); never on a refusal. */
undo: boolean
hint: boolean
stamp: Stamp
}
function currentStamp(): Stamp {
const { documentText, undo, redo } = useEditorStore.getState()
return { text: documentText, undo: undo.length, redo: redo.length }
}
/** The shown message while the document and both history stacks are those it was shown on. */
function useLive(message: GestureMessage | null): GestureMessage | null {
const text = useEditorStore((s) => s.documentText)
const undo = useEditorStore((s) => s.undo.length)
const redo = useEditorStore((s) => s.redo.length)
if (!message) return null
const { stamp } = message
const same = stamp.text === text && stamp.undo === undo && stamp.redo === redo
return same ? message : null
}
/** Hover with a mouse and focus inside hold the message; a touch never does (R-2). */
function useHold() {
const [hovered, setHovered] = useState(false)
const [focused, setFocused] = useState(false)
const handlers = {
onPointerEnter: (event: PointerEvent) => {
if (event.pointerType === 'mouse') setHovered(true)
},
onPointerLeave: () => setHovered(false),
onFocus: () => setFocused(true),
onBlur: (event: FocusEvent<HTMLElement>) => {
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {
setFocused(false)
}
},
}
return { held: hovered || focused, handlers }
}
/**
* The line under the drawing (A14, R-2): « Point déplacé · Défaire » after a gesture, a
* refusal in red, or a hint while nothing else is shown. A message lasts 6 s, held while a
* mouse hovers it or the focus is inside; any commit, undo or redo closes it.
*/
export function useGestureMessage() {
const [shown, setShown] = useState<GestureMessage | null>(null)
const message = useLive(shown)
const { held, handlers } = useHold()
useEffect(() => {
if (!message || held) return
const timer = setTimeout(
() => setShown(null),
message.hint ? HINT_MS : MESSAGE_MS,
)
return () => clearTimeout(timer)
}, [message, held])
const show = (
text: string,
{ undo, tone }: { undo: boolean; tone: GestureMessage['tone'] },
) => setShown({ text, tone, undo, hint: false, stamp: currentStamp() })
const hint = (text: string) => {
if (message) return
setShown({
text,
tone: 'info',
undo: false,
hint: true,
stamp: currentStamp(),
})
}
return { message, show, hint, hold: handlers }
}
export type GestureMessages = ReturnType<typeof useGestureMessage>
@@ -9,6 +9,7 @@ import { updateGeometry, type CommitContext } from './annotationCommit'
import { pendingForClick, type NewKind } from './creation'
import { round2, type Frame, type XY } from './frame'
import type { ToolId, Tracing, UiAction, UiState } from './uiState'
import type { GestureMessages } from './useGestureMessage'
/** A click on the first vertex closes the tracing when within this share of F's span. */
const CLOSE_SHARE = 0.015
@@ -25,6 +26,8 @@ export interface PlacementInput {
frame: Frame | null
doc: AnatomicalSheetDocument
context: CommitContext
/** The line under the drawing: a kept drop says so with « Défaire », a refused one in red. */
message: Pick<GestureMessages, 'show'>
}
const asPoint = (at: XY): Point => [round2(at.x), round2(at.y)]
@@ -62,7 +65,7 @@ export function closingActions(
]
}
/** Tracing with the zone and link tools: vertices, closing, Enter and Escape. */
/** Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. */
function tracingActions(input: PlacementInput) {
const { ui, dispatch, frame } = input
const closeTracing = () =>
@@ -79,6 +82,10 @@ function tracingActions(input: PlacementInput) {
const onTraceKey = (event: KeyboardEvent) => {
if (!ui.tracing) return
if (event.key === 'Enter') closeTracing()
if (event.key === 'Backspace') {
event.preventDefault()
dispatch({ type: 'trace_pop' })
}
if (event.key === 'Escape') {
event.preventDefault()
dispatch({ type: 'trace_cancel' })
@@ -87,14 +94,22 @@ function tracingActions(input: PlacementInput) {
return { closeTracing, trace, onTraceKey }
}
/** A drop commits one update; the hint holds the core's words on a refusal. */
function dropAction(input: PlacementInput) {
/** A drop commits one update; the line under the drawing says it, or the core's refusal. */
function dropAction({ doc, context, message }: PlacementInput) {
return (id: string, geometry: Geometry) => {
const annotation = input.doc.annotations.find((a) => a.id === id)
const annotation = doc.annotations.find((a) => a.id === id)
if (!annotation) return
const result = updateGeometry(annotation, geometry, input.context)
const hint = result.ok ? null : result.messages.join(' ')
input.dispatch({ type: 'hint', hint })
const result = updateGeometry(annotation, geometry, context)
if (result.ok) {
const text = context.t(
`editor.annotations.message.moved.${annotation.kind}`,
)
return message.show(text, { undo: true, tone: 'info' })
}
const text = context
.t('editor.annotations.message.move_refused')
.replace('{text}', () => result.messages.join(' '))
message.show(text, { undo: false, tone: 'error' })
}
}
@@ -122,5 +137,6 @@ export function usePlacement(input: PlacementInput) {
onDrop: dropAction(input),
onTraceKey: tracing.onTraceKey,
closeTracing: tracing.closeTracing,
popVertex: () => dispatch({ type: 'trace_pop' }),
}
}