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

@@ -1,4 +1,5 @@
import { useEffect, useReducer, useState, type Dispatch } from 'react'
import Button from '@/components/ui/Button'
import type {
AnatomicalSheetDocument,
Annotation,
@@ -10,6 +11,11 @@ import { parseFrame, type Frame } from '@/editor/annotations/frame'
import { isEditable } from '@/editor/annotations/geometryEdit'
import { useSelectionEscape } from '@/editor/annotations/deselect'
import { usePlacement } from '@/editor/annotations/usePlacement'
import { stripLeadOf } from '@/editor/annotations/stripLead'
import {
useGestureMessage,
type GestureMessages,
} from '@/editor/annotations/useGestureMessage'
import {
initialUi,
uiReducer,
@@ -23,19 +29,18 @@ import {
useViewModel,
type ViewModel,
} from '@/editor/annotations/useViewModel'
import type { AnnotationSection } from '@/editor/navigation'
import { targetOfKey, type AnnotationSection } from '@/editor/navigation'
import { usePlaceVisible } from '@/lib/placeVisibility'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import AnnotationCanvas from './AnnotationCanvas'
import { annotationName } from './AnnotationList'
import CreationPanel from './CreationPanel'
import EditStrip, { type StripNotice } from './EditStrip'
import GestureMessage from './GestureMessage'
import KeyboardAdd from './KeyboardAdd'
import OverviewPanel from './OverviewPanel'
import PropertiesPanel, { UnmeasuredHint } from './PropertiesPanel'
import SelectionTag from './SelectionTag'
import TracingBar from './TracingBar'
import PropertiesPanel, { useGeometryIssues } from './PropertiesPanel'
import ViewSwitcher from './ViewSwitcher'
interface Props {
@@ -127,10 +132,17 @@ function useCommitContext(): CommitContext {
return { t, locale }
}
/** The tab's work: the commit context, the line under the drawing and the placement. */
function useWork(scene: Scene) {
const context = useCommitContext()
const message = useGestureMessage()
const placement = usePlacement({ ...scene, context, message })
return { context, message, placement }
}
export default function EditableAnnotations(props: Props) {
const scene = useScene(props)
const context = useCommitContext()
const placement = usePlacement({ ...scene, context })
const { context, message, placement } = useWork(scene)
const { ui, selected } = scene
const visible = usePlaceVisible()
const { asideRef, byDrawing } = useSelectionEscape(
@@ -139,15 +151,19 @@ export default function EditableAnnotations(props: Props) {
visible && selected !== undefined && ui.tracing === null && !ui.pending,
)
return (
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
<CanvasColumn
scene={scene}
placement={placement}
onDeselect={byDrawing}
/>
<aside ref={asideRef}>
<SidePanel scene={scene} context={context} />
</aside>
<div className="space-y-3">
<SceneStrip scene={scene} placement={placement} />
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
<CanvasColumn
scene={scene}
placement={placement}
message={message}
onDeselect={byDrawing}
/>
<aside ref={asideRef}>
<SidePanel scene={scene} context={context} />
</aside>
</div>
</div>
)
}
@@ -157,13 +173,15 @@ type Placement = ReturnType<typeof usePlacement>
function CanvasColumn({
scene,
placement,
message,
onDeselect,
}: {
scene: Scene
placement: Placement
message: GestureMessages
onDeselect: () => void
}) {
const { doc, ui, dispatch, model, selected } = scene
const { doc, dispatch, model } = scene
const noCategory = doc.categories.length === 0
return (
<div className="min-w-0 space-y-3">
@@ -172,52 +190,22 @@ function CanvasColumn({
current={scene.viewId}
onSelect={(id) => dispatch({ type: 'view', viewId: id })}
/>
<ToolNotes
tool={ui.tool}
hint={ui.hint}
model={model}
noCategory={noCategory}
viewId={scene.viewId}
navigate={scene.navigate}
/>
{selected && <TagOf annotation={selected} doc={doc} />}
<CanvasStage
scene={scene}
placement={placement}
onDeselect={onDeselect}
/>
{ui.tracing && (
<TracingBar
count={ui.tracing.points.length}
onClose={placement.closeTracing}
onCancel={() => dispatch({ type: 'trace_cancel' })}
<GestureMessage messages={message}>
<KeyboardAdd
disabled={!model.measured || noCategory || scene.frame === null}
linkDisabled={model.children.length === 0}
onAdd={(kind) => addAtCentre(kind, scene.frame, dispatch)}
/>
)}
<KeyboardAdd
disabled={!model.measured || noCategory || scene.frame === null}
linkDisabled={model.children.length === 0}
onAdd={(kind) => addAtCentre(kind, scene.frame, dispatch)}
/>
</GestureMessage>
</div>
)
}
function TagOf({
annotation,
doc,
}: {
annotation: Annotation
doc: AnatomicalSheetDocument
}) {
const locale = useLocaleStore((s) => s.locale)
return (
<SelectionTag
kind={annotation.kind}
name={annotationName(annotation, doc.views, locale)}
/>
)
}
function CanvasStage({
scene,
placement,
@@ -344,37 +332,120 @@ function overlayOf(
}
}
/** The tool line and the reasons a tool cannot be used now. */
function ToolNotes({
tool,
hint,
model,
noCategory,
viewId,
navigate,
/** The strip of the edit body: the lead of the scene, its notice, the tracing commands. */
function SceneStrip({
scene,
placement,
}: {
tool: ToolId
hint: string | null
model: ViewModel
noCategory: boolean
viewId: string
navigate: EditorPlaceProps['navigate']
scene: Scene
placement: Placement
}) {
const t = useT()
const linkBlocked = tool === 'link' && model.children.length === 0
const locale = useLocaleStore((s) => s.locale)
const notice = useStripNotice(scene)
const { ui, selected, doc } = scene
return (
<div className="space-y-1 text-sm text-[var(--color-ink-muted)]">
<p>{t(`editor.annotations.tool_hint.${tool}`)}</p>
{!model.measured && (
<UnmeasuredHint navigate={navigate} viewId={viewId} />
)}
{noCategory && <p>{t('editor.annotations.no_category')}</p>}
{linkBlocked && <p>{t('editor.annotations.no_child_view')}</p>}
{hint && (
<p role="alert" className="text-[var(--color-danger-strong)]">
{hint}
</p>
)}
<EditStrip
lead={stripLeadOf(ui, selected, doc, { t, locale })}
notice={notice}
commands={
ui.tracing && (
<TracingCommands
count={ui.tracing.points.length}
placement={placement}
onCancel={() => scene.dispatch({ type: 'trace_cancel' })}
/>
)
}
/>
)
}
/**
* The strip's middle, first match wins: a refusal, the selection's geometry issues (the
* first, then « +n »), then why a tool cannot be used now.
*/
function useStripNotice(scene: Scene): StripNotice | null {
const t = useT()
const issues = useGeometryIssues(scene.selected?.id ?? '')
const { ui, model, doc } = scene
if (ui.hint) return { tone: 'error', text: ui.hint }
if (scene.selected && issues.length > 0) {
return { tone: 'error', text: issues[0]!, more: issues.length - 1 }
}
if (!model.measured) return unmeasuredNotice(scene, t)
if (doc.categories.length === 0) {
return { tone: 'info', text: t('editor.annotations.no_category') }
}
if (ui.tool === 'link' && model.children.length === 0) {
return { tone: 'info', text: t('editor.annotations.no_child_view') }
}
return null
}
/** Points to the views section, on the view whose drawing cannot be measured. */
function unmeasuredNotice(
scene: Scene,
t: (key: string) => string,
): StripNotice {
const target = targetOfKey({ kind: 'view', id: scene.viewId })
return {
tone: 'info',
text: t('editor.annotations.unmeasured.hint'),
link: {
label: t('editor.place.views'),
onClick: () => scene.navigate(target),
},
}
}
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>
)
}