feat(editor): point handle, size slider with core minimum, move mode

HandleLayer: its own svg over the overlay, not aria-hidden; the selected
point (or link circle) gets a focusable « Point {nom} » handle whose hit
circle (data-handle) the press machine reads, sized in CSS px under zoom
(R-9, read once from any-pointer: coarse). The Task 2 stand-in (the
selected marker as its own handle) is removed.

Keys on the handle: arrows step 0.5 % of the frame (Shift x10) as a
stamped series, Enter or blur commit once, Escape drops it (R-11, R-13).
SizeSlider in the strip for a selected point and for the Point tool (A5):
the view's sizes as ticks, the core minimum as a red mark, snap 8 px,
arrows 1 %, Page Up/Down next size, one commit on release, Enter or blur;
a refusal restores the size and draws the refused place in red dashes.
« Déplacer le point » opens the move mode (board 06 B): drag anywhere or
four arrows move a preview only, clicks select nothing, « Valider la
position » commits once, « Annuler » and Escape restore; the focus comes
back to the button. Escape follows board 32 (escapeAction). The overlay
reads the preview from the work store and draws the old place in grey
dashes. Ctrl+Z now also works from a slider (not a text field).

Rewritten assertions:
- editor-annotations-tab « a finger drags the selected point »:
  drag(marker('anno-a')) -> drag(pointHandle()), same expected geometry.
- editor-geometry.spec « a point inherited out of its frame is repaired
  through the geometry group » (cx/cy typed 200) -> « ... repaired with
  the move mode »: a partial move refused and restored (cx 110, issue
  kept), then a move inside kept (issue gone, fewer errors).
This commit is contained in:
bchanot committed 2026-11-17 18:50:29 +01:00
1 parent 2882821661
commit 91e94952f0
23 files changed
+1679 -149

No files matched your search

@@ -0,0 +1,99 @@
import type { KeyboardEvent } from 'react'
import type { Annotation, Geometry } from '@faunosteo/core-wasm/types'
import { useEditorStore } from '../state/editorStore'
import { moveStep, type Frame } from './frame'
import type { GeometryChange } from './usePlacement'
import { takeMove, takePreview, stepSelection } from './previewCommit'
import { endMode, startMove, useAnnotationWork } from './workStore'
type Drop = (id: string, geometry: Geometry, change?: GeometryChange) => void
export interface PointEditInput {
/** The selection when it can be moved now (a circle: a point or a link). */
target: Annotation | null
frame: Frame | null
onDrop: Drop
}
export type Direction = 'left' | 'up' | 'down' | 'right'
const DELTA: Record<Direction, [number, number]> = {
left: [-1, 0],
up: [0, -1],
down: [0, 1],
right: [1, 0],
}
const KEY_DIRECTION: Record<string, Direction> = {
ArrowLeft: 'left',
ArrowUp: 'up',
ArrowDown: 'down',
ArrowRight: 'right',
}
/** One step (R-11) of the target, into the move mode or a keyboard series. */
function step(input: PointEditInput, direction: Direction, big: boolean) {
const { target, frame } = input
if (!target?.geometry || !frame) return
const size = moveStep(frame, big)
const [x, y] = DELTA[direction]
stepSelection(target.id, target.geometry, { x: x * size, y: y * size })
}
/** The commits of the pending work: each takes its preview, fresh only (R-13). */
function commits(onDrop: Drop) {
const keys = () => {
const preview = takePreview('keys')
if (preview) onDrop(preview.annotationId, preview.geometry)
}
const size = () => {
const preview = takePreview('size')
if (preview) onDrop(preview.annotationId, preview.geometry, 'size')
}
const move = () => {
const preview = takeMove()
if (preview) onDrop(preview.annotationId, preview.geometry)
}
return { keys, size, move }
}
const inMoveMode = () => useAnnotationWork.getState().mode?.kind === 'move'
/** The point handle's keys: arrows step (Shift ×10), Enter commits the series or the mode. */
function handleKeys(input: PointEditInput, commit: ReturnType<typeof commits>) {
return (event: KeyboardEvent) => {
const direction = KEY_DIRECTION[event.key]
if (direction) {
event.preventDefault()
return step(input, direction, event.shiftKey)
}
if (event.key !== 'Enter') return
event.preventDefault()
if (inMoveMode()) commit.move()
else commit.keys()
}
}
/**
* Point editing (R-10 to R-13): the handle's keyboard series (one commit on Enter or
* blur), the size slider's commit, and the move mode (« Déplacer le point », its arrows,
* « Valider la position » committing once, « Annuler »).
*/
export function usePointEdit(input: PointEditInput) {
const commit = commits(input.onDrop)
return {
onHandleKey: handleKeys(input, commit),
// BDR-050: leaving the handle commits its series; a move mode waits for « Valider ».
onHandleBlur: () => commit.keys(),
commitSize: commit.size,
startMove: () => {
if (!input.target) return
startMove(input.target.id, useEditorStore.getState().documentText)
},
stepMove: (direction: Direction) => step(input, direction, false),
confirmMove: commit.move,
cancelMove: endMode,
}
}
export type PointEdit = ReturnType<typeof usePointEdit>