chore(memory): journal — feat Placer au centre, plan + contract

This commit is contained in:
bchanot committed 2026-11-21 13:03:29 +01:00
1 parent 922bd50a5b
commit a81b6564e3
3 files changed
+71

No files matched your search

+1
View File
@@ -591,3 +591,4 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp
## 2026-11-21 ## 2026-11-21
- Refaire hold e2e :370 root-caused: test missed settleScroll after scrollIntoView (late scroll closes bubble by design); fixed e9f750e4, proven by instrumented runs. Owner: criterion 32 mockup V1-V6 validated, wants visual check before code. - Refaire hold e2e :370 root-caused: test missed settleScroll after scrollIntoView (late scroll closes bubble by design); fixed e9f750e4, proven by instrumented runs. Owner: criterion 32 mockup V1-V6 validated, wants visual check before code.
- « Placer au centre » shipped 922bd50a in add row (owner moved it from strip after challenge found 5 selection breaks); shared placeAtCentre; verifier CONFORME after 2 ECARTS (test gaps). Chips row: owner approved code.
@@ -0,0 +1,34 @@
# CONTRACT — place-at-centre-command
- date: 2026-11-21 | flow: feat | branch: feature/v1-2-anatomical-sheets
- status: active
- run-base: f05f3fa0
## REQUEST (verbatim — IMMUTABLE)
3. ACCESSIBILITÉ
Je valide l'ajout d'une commande explicite « Placer au centre » lorsqu'un outil de création est armé.
Elle doit permettre à un utilisateur de lecteur d'écran de créer une annotation sans devoir manipuler directement le schéma.
Réutilise autant que possible les mécanismes de création existants.
## CLARIFICATIONS
Q: Why / A: the drawing reacts to pointer events only (`usePressGesture.ts`), so an assistive-technology bare click on the drawing does nothing (LRN-147); only Enter on the focused drawing places at the centre today.
Q: Where does the command sit? / A: [delegated, 2026-11-21] in the edit strip's commands, where the armed tool's own commands live (the Point tool's size today): shown when a creation tool (point, zone, link) is armed with no selection, no creation and no tracing, after the Point tool's size control; label « Placer au centre » / « Place at the centre ».
Q: A selection is kept after « Créer » (useCreationFollow) and the strip shows the selection first: the command would be hidden from the second annotation on. What does arming do? / A: [gated 2026-11-21] arming a creation tool (point, zone, link; tool column or « Ajouter … » button) deselects the annotation; the strip then shows the tool, its size and « Placer au centre ». Undo untouched.
Q: Consequence: arming deselects would stop « abandoning a creation gives the selection back » (editor-deselect.spec.ts:268-283) / A: [gated 2026-11-21] the selection is kept and memorised: while a creation tool is armed the strip shows the tool, its size and « Placer au centre » instead of the selection's lead and commands; abandoning the creation or going back to « Sélectionner » without creating shows the selection again; a successful « Créer » selects the new annotation (as today). Supersedes « arming deselects » above.
Q: Strip placement broke selection behaviours (abandon, selection while armed, Escape: 5 cases found by the confirmation challenge) / A: [gated 2026-11-21] the command sits in the « Ajouter … » row under the drawing, in a slot reserved so nothing moves, shown while a creation tool is armed and nothing is in progress; the strip and the selection stay exactly as today. Supersedes the strip placement and both selection answers above (they become moot).
Q: Scope deviation / A: 8 files (feat limit 5): two dictionaries, one shared helper in EditableAnnotations (addAtCentre onto the shared function) and the reducer; accepted by the orchestrator as a minor, recorded.
Q: Out of this run / A: docs/design/v1-2-6-u2-chips/* is the criterion 32 mockup, a separate task; not part of this feature.
Q: `model.measured` guard / A: code fact (no decision): `frame` is `own ? parseFrame(root.viewBox) : null` with `own = model.measured && root?.viewId === viewId` (EditableAnnotations.tsx:170, :182), so an unmeasured view always has a null frame; the frame test covers both guards.
## ACCEPTANCE CRITERIA
1. The « Ajouter … » row under the drawing holds a fourth slot, « Placer au centre » (fr) / « Place at the centre » (en), reserved at all times (no layout shift when it appears); it is visible and operable only while a creation tool (point, zone, link; armed from the tool column or an « Ajouter … » button) is armed, no creation and no tracing are in progress, the frame is built (`frame !== null`, `model.measured`), a category exists, and for the link tool the view has a detail view under it; otherwise it is invisible and out of the focus order and the accessibility tree. The strip and the selection behave exactly as before.
2. Activating it by any means (mouse, touch, Enter, Space, a click with `detail` 0 or ≥ 1) places the armed kind's shape at the centre of the frame at the A5 size and opens its creation dialog: one shared placement function used by the command, Enter on the drawing and the add buttons' keyboard path (`addAtCentre` delegates to it); it clears a stale strip hint first; « Abandonner » returns the focus by the existing `creationOpener` rule (origin from `armedFrom`).
3. The armed announcement strings (`editor.annotations.armed.*`, fr and en) name « Placer au centre » and where it is (below the drawing); the polite status announces the armed tool whichever control armed it, and only while the command is available (empty during a creation or a tracing).
4. Unit tests prove 1-3 and fail on the pre-change code; existing Enter-on-drawing and add-button tests stay green.
5. A browser test (its own) at 1 024, 1 180 and 1 280 px: arming Point from « Ajouter un point » shows the command, the four buttons stay on one line (same top), `expectNoShift` holds around the arm press; pressing the command opens « Nouveau point »; at 1 280 px a `dblclick` on the command leaves the dialog open with no « Abandonner la création ? » question.
6. `pnpm typecheck`, `pnpm lint`, `pnpm test:run` green; on the sandbox, every shell spec that arms a tool passes: editor-annotations, editor-deselect, editor-shell-crossing, editor-touch, editor-journey, editor-geometry (failures only among the 13 known by name).
## FILE SCOPE
apps/app/src/components/editor/annotations/{KeyboardAdd,EditableAnnotations}.tsx; apps/app/src/editor/annotations/usePlacement.ts; apps/app/src/i18n/{fr,en}.ts; apps/app/tests/unit/editor-add-buttons.test.tsx (and any unit test asserting the old armed wording); apps/app/e2e/shell/editor-annotations.spec.ts.
@@ -0,0 +1,36 @@
# « Placer au centre » command — plan (rev 3: in the « Ajouter … » row, owner 2026-11-21)
Contract: `.claude/tasks/contracts/2026-11-21-place-at-centre-command-0900.md` (criteria 1-6). Repo `/home/bchanot/Documents/faunosteo-v1-2`, branch feature/v1-2-anatomical-sheets (commit in place). The strip (SceneStrip, stripLead) and the selection are NOT touched.
## Approach
1. ONE placement function. `apps/app/src/editor/annotations/usePlacement.ts`: export
`placeAtCentre(scene: Pick<PlacementInput, 'ui' | 'frame' | 'doc' | 'viewId' | 'dispatch'>, kind: NewKind, origin: Creation['origin']): void` = return if no `frame` or a creation exists (`useAnnotationWork.getState().creation`); `scene.dispatch({ type: 'hint', hint: null })`; `placePending(creationStart(scene, origin), keyboardPending(kind, frame, newPointSize(doc.annotations, viewId, frame, ui.size)))`. No tool check inside (the add buttons' keyboard path runs with « Sélectionner »).
- `placeAtCentreOnEnter(input, event)` keeps its key / modifier / `ui.tool === 'select'` / frame / creation guards, then `event.preventDefault()` and `placeAtCentre(input, TOOL_TARGET[ui.tool], ui.armedFrom)`; fix its docstring (no longer « the » screen-reader path).
- `apps/app/src/components/editor/annotations/EditableAnnotations.tsx` `addAtCentre(kind, scene)` becomes `placeAtCentre(scene, kind, 'add')` (keep its `guarded()` call site); drop imports that become unused; un-export `creationStart` if nothing outside usePlacement uses it.
2. The command in the add row. `apps/app/src/components/editor/annotations/KeyboardAdd.tsx`: new prop `centre: (() => void) | null`. After the three add buttons, always render a fourth `Button` (`type="button" variant="secondary" size="sm" className="min-h-11 xl:min-h-9"`, `data-place-centre=""`, label `t('editor.annotations.place_centre')`, `onClick={() => centre?.()}` for every `detail`). When `centre` is null the button carries `className` `invisible` (CSS visibility hidden: keeps its box, leaves the focus order and the accessibility tree) and `aria-hidden` is not needed; when non-null it is visible. Its box is therefore always reserved (no shift when it appears).
`EditableAnnotations.tsx` computes `centre` (a small function next to `armFromAdd`): non-null only when `armedTool(scene.ui) !== 'select'` (a redraw's lent tool excluded), `scene.creation === null`, `scene.ui.tracing === null`, `scene.frame !== null`, `model.measured`, `doc.categories.length > 0`, and not (`ui.tool === 'link'` && `model.children.length === 0`); value `() => placeAtCentre(scene, TOOL_TARGET[ui.tool], ui.armedFrom)` (export `TOOL_TARGET` from usePlacement or map with `TOOL_OF` inverse — reuse one existing map, no third copy).
3. Announcement. KeyboardAdd's polite status: `announce` becomes « a creation tool is armed and `centre !== null` » (any source; empty during a creation or a tracing). Strings (`apps/app/src/i18n/fr.ts`, `en.ts`): new key `editor.annotations.place_centre` fr « Placer au centre », en « Place at the centre »; the armed strings become:
- fr point « Outil Point actif : touchez ou cliquez sur le dessin à l'endroit voulu, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même). »
- fr zone « Outil Zone actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même). »
- fr detail_trigger « Outil Accès actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même). »
- en (button names in “…” as en.ts does): « Point tool on: tap or click the drawing where you want it, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same). »; zone « Zone tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same). »; link « Link tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same). »
## Tests (RED first where new)
`apps/app/tests/unit/editor-add-buttons.test.tsx`, describe « Placer au centre »:
1. Point armed from the tool column: the command is visible and reachable (`getByRole('button', { name: 'Placer au centre' })`); « Sélectionner » → not in the accessibility tree (`queryByRole` null) but its element still in the DOM with the `invisible` class.
2. `user.click` it → « Nouveau point » dialog at once, ghost at the frame centre; « Abandonner » → focus on the column's « Point ». Armed by pointer from « Ajouter une zone », the command → zone dialog with the centre triangle; « Abandonner » → focus on « Ajouter une zone ».
3. Focus + `{Enter}`; focus + `{ }`; `fireEvent.click` (detail 0) → the dialog each time (fresh renders).
4. Not available during a creation (dialog shown; « Replacer le point » with the dialog hidden) nor a tracing (one zone vertex): no role button.
5. Not available when creation is impossible: link tool with no detail view under the view; a document without categories.
6. A stale hint is cleared by the command (an off-frame drawing press shows the « outside » hint first).
7. Cross-kind: Zone armed from the column, Enter on « Ajouter un point » → « Nouveau point ».
8. Status: armed from the column → it reads the armed text (contains « Placer au centre »); keyboard « Ajouter un point » then « Replacer le point » → the status stays empty.
9. With a selected annotation and the Point tool armed: the command is available and the strip still shows the selection's lead (unchanged behaviour).
Update existing assertions of the old armed wording (keep their intent).
`apps/app/e2e/shell/editor-annotations.spec.ts`: a new test at 1 024, 1 180 and 1 280 px: `click` « Ajouter un point »; `[data-place-centre]` visible; the four add-row buttons share one top (one line); `expectNoShift` around the arm press; press the command → « Nouveau point » visible. At 1 280 px only, a second run: arm, `dblclick` the command → the dialog stays open and no « Abandonner la création ? » question. If the four buttons do not fit on one line at a width, report it (DONE_WITH_CONCERNS) with the measured widths: do not change the layout to hide it.
## Gates
`pnpm typecheck` then `pnpm lint` (sequential: lint runs out of memory beside another heavy process), `pnpm test:run`. Shell (controller): e2e/shell/{editor-annotations,editor-deselect,editor-shell-crossing,editor-touch,editor-journey,editor-geometry}.spec.ts, full paths, `--workers=2`.
## Disposition
Honors LRN-147, BDR-124 (add buttons' pointer-arms / keyboard-centre unchanged; cross-kind test), A14 (reserved slot), BDR-113 (Escape untouched). Strip and selection untouched (owner 2026-11-21).