feat(editor): four tabs, Annotations sections, references from the header

U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.

R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
  Références clicked -> no « Plus »; below 640 px five others -> Général,
  Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
  header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
  VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
  target place/section/key (vertebrae tab -> annotations/regions); consumed
  context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
  (key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
  no_category text « (onglet Général) » -> « (Annotations, section
  Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
  CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
  references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
  ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
  + place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
  (edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
  showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
  label « general tab » -> « categories section »; tab Références ->
  openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
  Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
  tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
  openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry

Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
This commit is contained in:
bchanot committed 2026-11-06 20:25:35 +01:00
1 parent 95b1b7e461
commit bc2dba7c14
56 files changed
+2419 -699

No files matched your search

+67 -6
View File
@@ -1,20 +1,81 @@
import { useContext, useEffect, useRef } from 'react'
import type {
AnatomicalSheetDocument,
ElementKey,
} from '@faunosteo/core-wasm/types'
import {
AnnounceContext,
useFocusRequest,
visibleElement,
type FocusRequest,
} from '../focusRequest'
import { useT } from '@/i18n/useT'
/** What « Aller à … » seeds in the Annotations tab: a view, and maybe an annotation. */
/** What « Aller à … » seeds on the drawing: the view and the annotation a key names. */
export function annotationFocus(
doc: AnatomicalSheetDocument,
key: ElementKey,
): { viewId: string; annotationId: string | null } | null {
if (key.kind === 'view') {
const view = doc.views.find((v) => v.id === key.id)
return view ? { viewId: view.id, annotationId: null } : null
}
): { viewId: string; annotationId: string } | null {
if (key.kind !== 'annotation') return null
const annotation = doc.annotations.find((a) => a.id === key.id)
return annotation
? { viewId: annotation.view_id, annotationId: annotation.id }
: null
}
/** What the request needs to know of the drawing, and the one thing it may do to it. */
export interface DrawingState {
viewId: string
selectedId: string | null
/** A creation or a tracing in progress: the request is kept, not served. */
busy: 'creation' | 'tracing' | null
show: (viewId: string, annotationId: string) => void
}
const BUSY_TARGET = {
creation: '[data-creation-heading]',
tracing: '[data-testid="tracing-bar"]',
} as const
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
/**
* « 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.
*/
export function useAnnotationRequest(
focus: FocusRequest | undefined,
doc: AnatomicalSheetDocument,
drawing: DrawingState,
): void {
const t = useT()
const announce = useContext(AnnounceContext)
const awaiting = useRef<string | null>(null)
useFocusRequest(focus, (target) => {
const found = target.key ? annotationFocus(doc, target.key) : null
if (!found) return 'none'
if (drawing.busy) {
announce(t(`editor.live.${drawing.busy}_kept`))
focusFirst(BUSY_TARGET[drawing.busy])
return 'kept'
}
const same =
drawing.selectedId === found.annotationId &&
drawing.viewId === found.viewId
if (same) focusFirst('[data-properties-heading]')
else {
awaiting.current = found.annotationId
drawing.show(found.viewId, found.annotationId)
}
return 'found'
})
useEffect(() => {
if (awaiting.current === null || drawing.selectedId !== awaiting.current) {
return
}
awaiting.current = null
focusFirst('[data-properties-heading]')
})
}
@@ -0,0 +1,26 @@
import { useMemo } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
/**
* What the overview panel counts, read once per parsed document: the annotations of each
* view and the vertebral regions. A display count, no rule: no core call, no network.
*/
export interface OverviewCounts {
annotationsByView: ReadonlyMap<string, number>
regions: number
}
export function overviewCounts(doc: AnatomicalSheetDocument): OverviewCounts {
const annotationsByView = new Map<string, number>()
for (const annotation of doc.annotations) {
const count = annotationsByView.get(annotation.view_id) ?? 0
annotationsByView.set(annotation.view_id, count + 1)
}
return { annotationsByView, regions: doc.vertebral_config.regions.length }
}
export function useOverviewCounts(
doc: AnatomicalSheetDocument,
): OverviewCounts {
return useMemo(() => overviewCounts(doc), [doc])
}
+81 -17
View File
@@ -1,10 +1,38 @@
import { createContext, useContext, useEffect, useRef } from 'react'
import type { ElementKey } from '@faunosteo/core-wasm/types'
import type {
AnnotationSection,
EditorTarget,
FocusRequest,
} from './navigation'
import type { EditorTabId } from './tabs'
/** « Aller à … »: the element to show and a serial so each request is consumed once. */
export interface FocusRequest {
key: ElementKey
serial: number
export type { FocusRequest }
/**
* What a place did with a request: `found` the element and focused it, `kept` a creation
* or tracing in progress instead of jumping, `none` when it holds no such element.
*/
export type FocusOutcome = 'found' | 'kept' | 'none'
/** The `data-place` name of the place a target shows. */
export type PlaceName =
| EditorTabId
| `annotations.${AnnotationSection}`
| 'references'
export function placeOf(target: EditorTarget): PlaceName {
if (target.place === 'references') return 'references'
if (target.tab !== 'annotations') return target.tab
return `annotations.${target.section ?? 'drawing'}`
}
/** The request, only when `place` is the one its target names (a hidden place never answers). */
export function ownedBy(
focus: FocusRequest | undefined,
place: PlaceName,
): FocusRequest | undefined {
return focus && placeOf(focus.target) === place ? focus : undefined
}
/** The attributes that make a row of a list reachable by a focus request. */
@@ -19,37 +47,73 @@ export function focusAttrs(key: ElementKey) {
export const FOCUS_CLASS =
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
/** The route's answer to a consumed request: it clears it, so a remounted tab never replays. */
export const FocusConsumedContext = createContext<(serial: number) => void>(
/** The workspace's answer to a handled request: it clears it, so a remount never replays. */
export const FocusConsumedContext = createContext<
(serial: number, outcome: FocusOutcome) => void
>(() => undefined)
/** Says something to the polite live region of the workspace. */
export const AnnounceContext = createContext<(text: string) => void>(
() => undefined,
)
/** Runs `apply` once per request, after the tab has rendered, then reports it consumed. */
/**
* Runs `apply` once per request, after the place has rendered, then reports the outcome.
* The workspace passes a request only to the place its target names.
*/
export function useFocusRequest(
focus: FocusRequest | undefined,
apply: (key: ElementKey) => void,
apply: (target: EditorTarget) => FocusOutcome,
): void {
const handled = useRef<number | null>(null)
const consumed = useContext(FocusConsumedContext)
useEffect(() => {
if (!focus || handled.current === focus.serial) return
handled.current = focus.serial
apply(focus.key)
consumed(focus.serial)
consumed(focus.serial, apply(focus.target))
}, [focus, apply, consumed])
}
/** Scrolls to and focuses the row tagged with `key`. */
export function focusRow(key: ElementKey): void {
/** The first element matching `selector` that no hidden place contains. */
export function visibleElement(selector: string): HTMLElement | null {
const found = [...document.querySelectorAll<HTMLElement>(selector)]
return found.find((element) => !element.closest('[hidden]')) ?? null
}
/** Scrolls to and focuses the visible row tagged with `key`; false when there is none. */
export function focusRow(key: ElementKey): boolean {
const wanted = JSON.stringify(key)
const row = [
...document.querySelectorAll<HTMLElement>('[data-focus-key]'),
].find((candidate) => candidate.dataset.focusKey === wanted)
row?.scrollIntoView?.({ block: 'center' })
row?.focus()
].find(
(candidate) =>
candidate.dataset.focusKey === wanted && !candidate.closest('[hidden]'),
)
if (!row) return false
row.scrollIntoView?.({ block: 'center' })
row.focus()
return true
}
/** Row-based tabs (Général, Vues, Références, Vertèbres): focus the named row. */
/** Row-based places (Général, Vues, Catégories, Régions, Références): focus the named row. */
export function useRowFocus(focus: FocusRequest | undefined): void {
useFocusRequest(focus, focusRow)
useFocusRequest(focus, (target) =>
target.key && focusRow(target.key) ? 'found' : 'none',
)
}
/**
* Commits the text being typed before a place is left: blurs the focused field, so its
* `TextField` commits on blur. Safari and iPadOS do not move the focus to a tapped button,
* so the blur is forced rather than assumed.
*/
export function commitFocusedField(): void {
const active = document.activeElement
if (
active instanceof HTMLInputElement ||
active instanceof HTMLTextAreaElement ||
active instanceof HTMLSelectElement
) {
active.blur()
}
}
+15 -13
View File
@@ -1,15 +1,12 @@
import type { ElementKey, PreviewState } from '@faunosteo/core-wasm/types'
import type { FocusRequest } from './focusRequest'
import type { PreviewState } from '@faunosteo/core-wasm/types'
import type { EditorTarget, FocusRequest } from './navigation'
import { unmeasuredViews } from './issues'
import type { TabTier } from './useViewport'
export const EDITOR_TABS = [
'general',
'views',
'annotations',
'findings',
'references',
'vertebrae',
'verification',
] as const
export type EditorTabId = (typeof EDITOR_TABS)[number]
@@ -17,7 +14,7 @@ export type EditorTabId = (typeof EDITOR_TABS)[number]
/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */
const SHOWN: Record<TabTier, readonly EditorTabId[]> = {
wide: EDITOR_TABS,
medium: ['general', 'annotations', 'findings', 'verification'],
medium: EDITOR_TABS,
small: ['annotations', 'verification'],
}
@@ -40,16 +37,21 @@ export function initialTab(state: PreviewState, tier: TabTier): EditorTabId {
return SHOWN[tier].includes(wanted) ? wanted : 'annotations'
}
/** Props of every tab body (Lots F-J fill them): read-only flag, tab jump, sheet reload. */
export interface EditorTabProps {
/** Props of every place (tab body, Annotations section, references panel). */
export interface EditorPlaceProps {
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
readOnly: boolean
/** « Aller à … » and any link between tabs. */
onSelectTab: (tab: EditorTabId) => void
/** « Aller à … » with an element: the tab seeds its own selection from it once. */
/** « Aller à … » and any link between places; `opener` takes the focus back on return. */
navigate: (target: EditorTarget, opener?: HTMLElement | null) => void
/** « Aller à … » with an element: the place seeds its own selection from it once. */
focus?: FocusRequest
/** Switches tab and asks it to show the element. */
onGoTo?: (tab: EditorTabId, key: ElementKey) => void
/** Reads the sheet's overview again (after a submission: the round freezes the draft). */
reloadSheet: () => void
}
export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}`
export const panelDomId = (tab: EditorTabId) => `editor-panel-${tab}`
/** The « Plus » disclosure button, focused when the active tab sits under it. */
export const MORE_BUTTON_ID = 'editor-tabs-more-button'
/** The header button that toggles the references panel. */
export const REFERENCES_BUTTON_ID = 'editor-references-button'
+246
View File
@@ -0,0 +1,246 @@
import {
useCallback,
useEffect,
useReducer,
useRef,
useState,
type Dispatch,
type RefObject,
} from 'react'
import type { ElementKey } from '@faunosteo/core-wasm/types'
import { useT } from '@/i18n/useT'
import {
commitFocusedField,
placeOf,
visibleElement,
type FocusOutcome,
type PlaceName,
} from './focusRequest'
import {
initialNavigation,
navigationReducer,
type AnnotationSection,
type EditorTarget,
type NavigationAction,
type NavigationState,
} from './navigation'
import {
MORE_BUTTON_ID,
REFERENCES_BUTTON_ID,
tabDomId,
type EditorTabId,
} from './tabs'
type MoveKind =
| 'go_to'
| 'section'
| 'back'
| 'references'
| 'references_closed'
/** A programmatic move: a new object per move, so the effect after it runs once. */
interface Move {
kind: MoveKind
}
type Opener = HTMLElement | null | undefined
export interface EditorNavigation {
state: NavigationState
/** The polite live region's text; a repeat alternates a trailing no-break space. */
live: string
navigate: (target: EditorTarget, opener?: Opener) => void
selectTab: (tab: EditorTabId) => void
openSection: (section: AnnotationSection, opener?: Opener) => void
backToDrawing: () => void
openReferences: (citedBy: ElementKey | null, opener?: Opener) => void
closeReferences: () => void
consumed: (serial: number, outcome: FocusOutcome) => void
announce: (text: string) => void
}
const isShown = (element: HTMLElement | null): boolean =>
element !== null && element.isConnected && !element.closest('[hidden]')
const headingOf = (place: PlaceName) =>
visibleElement(`[data-place="${place}"] [data-place-heading]`)
const CANVAS_BOX =
'[data-place="annotations.drawing"] [role="group"][tabindex="0"]'
/** The tab's button, or « Plus » while the tab sits in the closed list. */
const tabButton = (tab: EditorTabId) =>
document.getElementById(tabDomId(tab)) ??
document.getElementById(MORE_BUTTON_ID)
/** The place the shown tab and section name. */
function shownPlace(state: NavigationState): PlaceName {
return state.tab === 'annotations'
? `annotations.${state.section}`
: state.tab
}
/** The text the live region says for a move to `target`. */
function useMoveText(): (target: EditorTarget) => string {
const t = useT()
return useCallback(
(target) => {
if (target.place === 'references') return t('editor.place.references')
const tab = t(`editor.tab.${target.tab}`)
if (!target.section) return tab
return `${tab} · ${t(`editor.place.${target.section}`)}`
},
[t],
)
}
function useLiveRegion() {
const [live, setLive] = useState('')
const announce = useCallback((text: string) => {
setLive((previous) => (previous === text ? `${text} ` : text))
}, [])
return { live, announce }
}
interface Openers {
references: RefObject<HTMLElement | null>
section: RefObject<HTMLElement | null>
}
/** The commands of the workspace: each commits the typed text, then moves. */
function useMoves(
dispatch: Dispatch<NavigationAction>,
announce: (text: string) => void,
openers: Openers,
) {
const t = useT()
const moveText = useMoveText()
const [move, setMove] = useState<Move | null>(null)
const go = useCallback(
(action: NavigationAction, kind: MoveKind, text: string) => {
commitFocusedField()
announce(text)
dispatch(action)
setMove({ kind })
},
[announce, dispatch],
)
const navigate = useCallback(
(target: EditorTarget, opener?: Opener) => {
if (target.place === 'references') {
openers.references.current = opener ?? null
}
go({ type: 'go_to', target }, 'go_to', moveText(target))
},
[go, moveText, openers],
)
const openSection = useCallback(
(section: AnnotationSection, opener?: Opener) => {
openers.section.current = opener ?? null
const text = `${t('editor.tab.annotations')} · ${t(`editor.place.${section}`)}`
go({ type: 'open_section', section }, 'section', text)
},
[go, openers, t],
)
const backToDrawing = useCallback(() => {
const text = `${t('editor.tab.annotations')} · ${t('editor.place.drawing')}`
go({ type: 'back_to_drawing' }, 'back', text)
}, [go, t])
const openReferences = useCallback(
(citedBy: ElementKey | null, opener?: Opener) => {
openers.references.current = opener ?? null
const action = { type: 'open_references', citedBy } as const
go(action, 'references', t('editor.place.references'))
},
[go, openers, t],
)
const closeReferences = useCallback(() => {
const text = t('editor.live.references_closed')
go({ type: 'close_references' }, 'references_closed', text)
}, [go, t])
return {
move,
navigate,
openSection,
backToDrawing,
openReferences,
closeReferences,
}
}
/** « Retour au dessin »: the entry that opened the section, else the canvas box. */
function backTarget(opener: HTMLElement | null): HTMLElement | null {
if (opener && isShown(opener)) return opener
const entry = opener?.dataset.sectionEntry
const again = entry && visibleElement(`[data-section-entry="${entry}"]`)
return again || visibleElement(CANVAS_BOX)
}
/** Where the focus lands after a programmatic move; never `body`. */
function landingOf(move: Move, state: NavigationState): HTMLElement | null {
if (move.kind === 'references') return headingOf('references')
const place = state.focus ? placeOf(state.focus.target) : shownPlace(state)
return headingOf(place) ?? tabButton(state.tab)
}
/**
* After each move: a request an element answered is done; else (no owner answered, or
* the move had no request) the focus goes to the heading or the tab button.
*/
function useMoveFocus(
move: Move | null,
state: NavigationState,
outcomes: RefObject<Map<number, FocusOutcome>>,
dispatch: Dispatch<NavigationAction>,
openers: Openers,
) {
const handled = useRef<Move | null>(null)
useEffect(() => {
if (!move || handled.current === move) return
handled.current = move
if (move.kind === 'references_closed') {
const opener = openers.references.current
const target =
opener && isShown(opener)
? opener
: document.getElementById(REFERENCES_BUTTON_ID)
target?.focus()
return
}
const serial = state.focus?.serial
if (move.kind === 'go_to' && serial !== undefined) {
const outcome = outcomes.current.get(serial)
outcomes.current.delete(serial)
if (outcome === 'found' || outcome === 'kept') return
dispatch({ type: 'focus_consumed', serial })
}
if (move.kind === 'back') backTarget(openers.section.current)?.focus()
else landingOf(move, state)?.focus()
}, [move, state, outcomes, dispatch, openers])
}
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
const [state, dispatch] = useReducer(
navigationReducer,
initialTab,
initialNavigation,
)
const { live, announce } = useLiveRegion()
const outcomes = useRef(new Map<number, FocusOutcome>())
const openers = useRef<Openers>({
references: { current: null },
section: { current: null },
}).current
const moves = useMoves(dispatch, announce, openers)
const consumed = useCallback((serial: number, outcome: FocusOutcome) => {
outcomes.current.set(serial, outcome)
dispatch({ type: 'focus_consumed', serial })
}, [])
const selectTab = useCallback((tab: EditorTabId) => {
commitFocusedField()
dispatch({ type: 'select_tab', tab })
}, [])
useMoveFocus(moves.move, state, outcomes, dispatch, openers)
return { state, live, selectTab, consumed, announce, ...moves }
}
+38 -19
View File
@@ -6,7 +6,7 @@ import type {
} from '@faunosteo/core-wasm/types'
import type { Locale } from '@/i18n/types'
import { elementLabel } from './sheetDocument'
import type { EditorTabId } from './tabs'
import { targetOfKey, type EditorTarget } from './navigation'
/** The server's cap on the document text (contract §12.2), shown beside the measure. */
export const DOCUMENT_BYTES_CAP = 2_097_152
@@ -61,24 +61,26 @@ export function splitIssues(report: SheetReport): {
}
}
const ROOT_TAB: Record<string, EditorTabId> = {
views: 'views',
annotations: 'annotations',
finding_zones: 'findings',
categories: 'general',
references: 'references',
}
const REGION_PATH = /^vertebral_config\.regions\[(\d+)\]/
const ROOT_PATH = /^(\w+)\[(\d+)\]/
export interface IssueTarget {
tab: EditorTabId
/** The element the path names, when it resolves in the document. */
key: ElementKey | null
/** Its label. */
/** The place to show, carrying the element when the path resolves in the document. */
target: EditorTarget
/** The element's label, when it resolves. */
name: string | null
}
/** One key per list a path root names: `targetOfKey` is the only key-to-place table. */
const ROOT_SAMPLE: Record<string, ElementKey> = {
views: { kind: 'view', id: '' },
annotations: { kind: 'annotation', id: '' },
finding_zones: { kind: 'zone', id: '' },
categories: { kind: 'category', id: '' },
references: { kind: 'reference', id: '' },
}
const REGION_SAMPLE: ElementKey = { kind: 'region', code: '' }
type Kind = 'view' | 'annotation' | 'category' | 'zone' | 'reference'
const ROOT_KIND: Record<string, Kind> = {
views: 'view',
@@ -127,22 +129,39 @@ function keyOf(doc: AnatomicalSheetDocument, path: string): ElementKey | null {
return { kind: ROOT_KIND[match[1]], id: item.id } as ElementKey
}
function tabOf(path: string): EditorTabId | null {
if (REGION_PATH.test(path)) return 'vertebrae'
const placeAlone = (sample: ElementKey): EditorTarget => ({
...targetOfKey(sample),
key: null,
})
/** The place a path root names, without an element (the key does not resolve). */
function rootPlace(path: string): EditorTarget | null {
if (REGION_PATH.test(path)) return placeAlone(REGION_SAMPLE)
const root = ROOT_PATH.exec(path)?.[1]
return root ? (ROOT_TAB[root] ?? null) : null
const sample = root ? ROOT_SAMPLE[root] : undefined
return sample ? placeAlone(sample) : null
}
/** The tab and element an issue path names (« Aller à … »); null when it names none. */
/** The place and element an issue path names (« Aller à … »); null when it names none. */
export function issueTarget(
doc: AnatomicalSheetDocument,
path: string,
locale: Locale,
): IssueTarget | null {
const tab = tabOf(path)
if (!tab) return null
const place = rootPlace(path)
if (!place) return null
const key = keyOf(doc, path)
return { tab, key, name: key ? elementLabel(doc, key, locale) : null }
if (!key) return { target: place, name: null }
return { target: targetOfKey(key), name: elementLabel(doc, key, locale) }
}
/** The i18n key of the name of the place a target shows. */
export function placeKey(target: EditorTarget): string {
if (target.place === 'references') return 'editor.place.references'
if (target.section && target.section !== 'drawing') {
return `editor.place.${target.section}`
}
return `editor.tab.${target.tab}`
}
/** « 2 097 152 » with plain spaces, as the plan words the size. */