feat(editor): vertex handles, insert and remove, zone move, redraw

U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles
(R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip),
the handle cap at 40 (R-7), vertex drag and keys, the move mode on the
zone or the chosen vertex, « Redessiner » as a redraw mode kept in step
with its tracing (R-12 guard, R-13 drop), close radius in CSS px
(R-11). The numeric group leaves the properties panel (D1).

Removed or rewritten assertions (numeric group -> replacement):
- tab « shows its exact stored numbers » (Centre x field) -> the overlay
  selection circle's cx attribute, same exact value.
- tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the
  handle without a step commits nothing, a step + Enter commits once;
  a refused handle drag keeps the stored shape then a drag inside the
  frame repairs it (issues gone); Escape drops a pending series.
- tab C26 « Centre x 15 » -> overlay cx 15.
- tab C32 unmeasured « Centre x as text » -> no handle, no field.
- tab « adds and removes a vertex as part of the whole group » -> « + »
  then « − » on the drawing; « never offers to remove below three » ->
  « − » aria-disabled at 3.
- tab H8 « refused Remplacer drops the tracing » -> keeps it open with
  « Fermeture refusée » (board 33 A); « refused vertex add/remove stay
  non appliqué » -> a refused vertex drag restores the shape exactly.
- tab Désélectionner and D6b (typed Centre x committed, refused, undone)
  x6 and strip « a new commit replaces the message » -> the same with
  the Nom (FR) field (a blank name is the refused value).
- focus-request « Centre x 20 » -> overlay cx 20.
- escape « strip commands keep their Escape » -> a redraw: Escape on the
  strip or the box cancels it (R-12 row 4); kept for a new zone tracing.
- keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab
  when empty, asked once a vertex is placed (R-12).
- e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/
  redo; jitter/drag and Task 4 point reads -> overlay attributes (the
  stored place during the mode -> overlay-old-place); keyboard-only cy
  and vertex x typed -> handle and vertex keys.
- e2e deselect: Centre x typed/refused/committed -> Nom (FR).
- e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes.
- e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter;
  a far typed value + revert -> a far handle drag refused.
- e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
This commit is contained in:
bchanot committed 2026-11-17 20:24:49 +01:00
1 parent ba8e766fe8
commit 6211046537
44 files changed
+3790 -1050

No files matched your search

@@ -1,5 +1,4 @@
import { useEffect, useReducer, useState, type Dispatch } from 'react'
import Button from '@/components/ui/Button'
import type {
AnatomicalSheetDocument,
Annotation,
@@ -12,7 +11,14 @@ import { parseFrame, type Frame } from '@/editor/annotations/frame'
import { newPointSize } from '@/editor/annotations/pointSize'
import { guardDrawing } from '@/editor/annotations/drawingGuard'
import { usePointEdit } from '@/editor/annotations/usePointEdit'
import { endMode, useAnnotationWork } from '@/editor/annotations/workStore'
import { useZoneEdit } from '@/editor/annotations/useZoneEdit'
import { useRedrawFollowsTracing } from '@/editor/annotations/redraw'
import {
useDroppedNotice,
useModeFollowsSelection,
} from '@/editor/annotations/modeEnds'
import { handledPoints } from '@/editor/annotations/zoneEdit'
import { useAnnotationWork } from '@/editor/annotations/workStore'
import { isEditable } from '@/editor/annotations/geometryEdit'
import { useSelectionEscape } from '@/editor/annotations/deselect'
import { usePlacement } from '@/editor/annotations/usePlacement'
@@ -20,7 +26,6 @@ import { stripLeadOf } from '@/editor/annotations/stripLead'
import {
useGestureMessage,
type GestureMessage as ShownMessage,
type GestureMessages,
} from '@/editor/annotations/useGestureMessage'
import {
initialUi,
@@ -49,6 +54,8 @@ import {
} from './PointCommands'
import CreationPanel from './CreationPanel'
import EditStrip, { type StripNotice } from './EditStrip'
import TracingCommands from './TracingCommands'
import ZoneCommands, { moveTitleKey, useChosenVertex } from './ZoneCommands'
import GestureMessage from './GestureMessage'
import KeyboardAdd from './KeyboardAdd'
import OverviewPanel from './OverviewPanel'
@@ -145,59 +152,41 @@ function useCommitContext(): CommitContext {
}
/**
* The tab's work: the commit context, the line under the drawing, the placement and the
* point editing (handle keys, slider, move mode) on the movable selected circle.
* The tab's work: the commit context, the line under the drawing, the placement, the
* editing of the movable selection (point handle keys, slider, move mode) and of a
* polygon's vertices, the redraw kept in step with its tracing.
*/
function useWork(scene: Scene) {
const context = useCommitContext()
const message = useGestureMessage()
const placement = usePlacement({ ...scene, context, message })
const target = circleTargetOf(scene.selected, scene.model, scene.ui.tool)
const edit = usePointEdit({
target,
frame: scene.frame,
onDrop: placement.onDrop,
const target = movableOf(scene.selected, scene.model, scene.ui.tool)
const onDrop = placement.onDrop
const edit = usePointEdit({ target, frame: scene.frame, onDrop })
const polygon = target?.geometry?.type === 'polygon' ? target : null
const zone = useZoneEdit({
...{ target: polygon, frame: scene.frame, onDrop, message },
t: context.t,
confirmMove: edit.confirmMove,
})
const [insertsHidden, setInsertsHidden] = useState(false)
useModeFollowsSelection(scene.ui.selectedId)
useRedrawFollowsTracing(scene.ui.tracing, scene.dispatch)
useDroppedNotice(message)
return { context, message, placement, edit, target }
return {
context,
message,
placement,
edit,
zone,
target,
insertsHidden,
setInsertsHidden,
}
}
type Work = ReturnType<typeof useWork>
/**
* The move mode belongs to the selection: another selection (a list row, a view change)
* ends it. A read-only flip keeps the body and its selection, so it suspends the mode
* instead (R-14).
*/
function useModeFollowsSelection(selectedId: string | null) {
const modeId = useAnnotationWork((s) => s.mode?.annotationId ?? null)
useEffect(() => {
if (modeId === null || modeId === selectedId) return
const { mode } = useAnnotationWork.getState()
endMode()
// Never silent (R-13): a started move that ends this way is said.
if (mode?.started) useAnnotationWork.setState({ dropped: mode.kind })
}, [modeId, selectedId])
}
/**
* R-13: a started mode a change made elsewhere dropped is said on the line, once the body
* is shown (a drop while read-only is said on the way back).
*/
function useDroppedNotice(message: GestureMessages) {
const t = useT()
const visible = usePlaceVisible()
const dropped = useAnnotationWork((s) => s.dropped)
const show = message.show
useEffect(() => {
if (dropped === null || !visible) return
useAnnotationWork.setState({ dropped: null })
const text = t(`editor.annotations.dropped.${dropped}`)
show(text, { undo: false, tone: 'info' })
}, [dropped, visible, show, t])
}
export default function EditableAnnotations(props: Props) {
const scene = useScene(props)
const work = useWork(scene)
@@ -206,7 +195,10 @@ export default function EditableAnnotations(props: Props) {
const { asideRef, byDrawing } = useSelectionEscape(
selected?.id ?? null,
() => scene.dispatch({ type: 'select', id: null }),
visible && selected !== undefined && ui.tracing === null,
// A redraw's Escape cancels it at once (R-12); a new tracing keeps its own keys.
visible &&
selected !== undefined &&
(ui.tracing === null || ui.tracing.target === 'replace'),
{ editable: true, creating: ui.pending !== null },
)
return (
@@ -222,8 +214,6 @@ export default function EditableAnnotations(props: Props) {
)
}
type Placement = ReturnType<typeof usePlacement>
/** A move that drops the drawing's work asks first (R-12): the action runs once allowed. */
const guarded = (action: () => void) => () => {
if (guardDrawing(action)) action()
@@ -265,7 +255,7 @@ function CanvasColumn({
function useHandle(target: Annotation | null, doc: AnatomicalSheetDocument) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
if (!target?.geometry) return null
if (target?.geometry?.type !== 'circle') return null
const name = annotationName(target, doc.views, locale)
const kind = t(`editor.annotations.kind.${target.kind}`)
const label = t('editor.annotations.handle.shape')
@@ -292,6 +282,8 @@ function CanvasStage({
const shown = usePlaceVisible()
const { doc, ui, dispatch, model, frame, selected } = scene
const handle = useHandle(shown ? work.target : null, doc)
const points = shown ? handledPoints(work.target?.geometry ?? null) : null
const zone = points && { annotationId: work.target!.id, points }
const view = doc.views.find((v) => v.id === scene.viewId)
const blocked = !model.measured || doc.categories.length === 0
if (!view) return null
@@ -307,6 +299,9 @@ function CanvasStage({
handle,
onKeyDown: work.edit.onHandleKey,
onBlur: work.edit.onHandleBlur,
zone,
zoneKeys: work.zone,
onInsertsHidden: work.setInsertsHidden,
}}
tools={{
tool: ui.tool,
@@ -318,6 +313,7 @@ function CanvasStage({
onSelect={(id) => dispatch({ type: 'select', id })}
onPlace={work.placement.onPlace}
onDrop={work.placement.onDrop}
onHandle={work.zone.onHandle}
onDeselect={onDeselect}
onTraceKey={work.placement.onTraceKey}
/>
@@ -379,7 +375,6 @@ function SidePanel({
readOnly={false}
geometryLocked={!model.measured}
dispatch={dispatch}
context={context}
navigate={scene.navigate}
// « Tout afficher » leaves the selection: a started move asks first (R-12).
onShowAll={guarded(() => dispatch({ type: 'select', id: null }))}
@@ -399,14 +394,13 @@ function moveTargetOf(
: null
}
/** The selected point or link circle, when it can be moved now (R-9: its handle). */
function circleTargetOf(
/** The selection when it can be moved now: a circle (its handle) or a polygon (R-9). */
function movableOf(
selected: Annotation | undefined,
model: ViewModel,
tool: ToolId,
): Annotation | null {
const movable = moveTargetOf(selected, model, tool) !== null
return movable && selected?.geometry?.type === 'circle' ? selected : null
return moveTargetOf(selected, model, tool) !== null ? selected! : null
}
function overlayOf(
@@ -423,6 +417,7 @@ function overlayOf(
pending: ui.pending?.geometry ?? null,
tracing: ui.tracing?.points ?? null,
correction: ui.pending?.correction ?? null,
redrawing: ui.tracing?.target === 'replace',
}
}
@@ -433,31 +428,47 @@ function overlayOf(
function SceneStrip({ scene, work }: { scene: Scene; work: Work }) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const notice = useStripNotice(scene, work.message.message)
const moving = useAnnotationWork((s) => s.mode?.kind === 'move')
useMoveFocusReturn(moving)
const notice = useStripNotice(scene, work)
const mode = useAnnotationWork((s) =>
s.mode?.kind === 'move' ? s.mode : null,
)
useMoveFocusReturn(mode !== null)
const { ui, selected, doc } = scene
const lead = moving
const chosenVertex = useChosenVertex(selected?.id)
const lead = mode
? {
title: t('editor.annotations.move.point'),
title: t(moveTitleKey(mode, work.target?.kind)),
detail: t('editor.annotations.move.hint'),
icon: 'move' as const,
}
: stripLeadOf(ui, selected, doc, { t, locale })
: stripLeadOf(ui, selected, doc, { t, locale, chosenVertex })
const commandsKey = commandsKeyOf(
ui,
mode !== null,
work.target,
chosenVertex,
)
return (
<EditStrip
lead={lead}
notice={notice}
commands={<SceneCommands scene={scene} work={work} />}
commandsKey={commandsKeyOf(ui, moving, work.target?.kind === 'point')}
commandsKey={commandsKey}
/>
)
}
function commandsKeyOf(ui: UiState, moving: boolean, point: boolean) {
/** One box per set of commands: a wider set never moves an existing box (A14). */
function commandsKeyOf(
ui: UiState,
moving: boolean,
target: Annotation | null,
chosen: number | null,
) {
if (ui.tracing) return 'tracing'
if (moving) return 'move'
return point ? 'point' : `tool-${ui.tool}`
if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}`
return target?.kind === 'point' ? 'point' : `tool-${ui.tool}`
}
/** A tracing's commands, a movable point's, or the Point tool's size (A5). */
@@ -467,11 +478,18 @@ function SceneCommands({ scene, work }: { scene: Scene; work: Work }) {
return (
<TracingCommands
count={ui.tracing.points.length}
placement={work.placement}
onClose={work.placement.closeTracing}
onPop={work.placement.popVertex}
onCancel={() => dispatch({ type: 'trace_cancel' })}
/>
)
}
if (work.target?.geometry?.type === 'polygon') {
const edit = work.edit
return (
<ZoneCommands annotation={work.target} edit={edit} dispatch={dispatch} />
)
}
// A link circle keeps its handle but has no size and no move mode (R-10; no label).
if (work.target?.kind === 'point') {
const props = { doc, viewId, frame, edit: work.edit }
@@ -497,10 +515,12 @@ function SceneCommands({ scene, work }: { scene: Scene; work: Work }) {
*/
function useStripNotice(
scene: Scene,
message: ShownMessage | null,
work: Pick<Work, 'message' | 'insertsHidden'>,
): StripNotice | null {
const t = useT()
const issues = useGeometryIssues(scene.selected?.id ?? '')
const inMode = useAnnotationWork((s) => s.mode !== null)
const message: ShownMessage | null = work.message.message
const { ui, model, doc } = scene
if (ui.hint) return { tone: 'error', text: ui.hint }
if (message?.tone === 'error') {
@@ -509,6 +529,10 @@ function useStripNotice(
if (scene.selected && issues.length > 0) {
return { tone: 'error', text: issues[0]!, more: issues.length - 1 }
}
// R-18: a « + » hidden for its short segment; never in a mode (move, redraw).
if (work.insertsHidden && !inMode && !ui.tracing) {
return { tone: 'info', text: t('editor.annotations.strip.zoom_hint') }
}
if (!model.measured) return unmeasuredNotice(scene, t)
if (doc.categories.length === 0) {
return { tone: 'info', text: t('editor.annotations.no_category') }
@@ -534,54 +558,3 @@ function unmeasuredNotice(
},
}
}
const COMMAND = 'min-h-11 xl:min-h-9'
/** While a zone or link is traced: close (3 vertices at least), take one back, or drop it. */
function TracingCommands({
count,
placement,
onCancel,
}: {
count: number
placement: Placement
onCancel: () => void
}) {
const t = useT()
return (
<div
tabIndex={-1}
data-testid="tracing-commands"
className="flex items-center gap-2 outline-none"
>
<Button
type="button"
size="sm"
className={COMMAND}
disabled={count < 3}
onClick={placement.closeTracing}
>
{t('editor.annotations.trace_close')}
</Button>
<Button
type="button"
size="sm"
variant="secondary"
className={COMMAND}
disabled={count === 0}
onClick={placement.popVertex}
>
{t('editor.annotations.trace_pop')}
</Button>
<Button
type="button"
size="sm"
variant="ghost"
className={COMMAND}
onClick={onCancel}
>
{t('editor.annotations.trace_cancel')}
</Button>
</div>
)
}