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

@@ -0,0 +1,111 @@
import type { ReactNode } from 'react'
import type { StripLead } from '@/editor/annotations/stripLead'
import EditorGlyph from '../EditorGlyph'
import ReviewBadge from './ReviewBadge'
export type { StripLead }
/** The strip's middle: a refusal or a reason, two lines at most. */
export interface StripNotice {
tone: 'error' | 'info'
text: string
/** How many more of the same kind are not shown (« +n »). */
more?: number
link?: { label: string; onClick(): void }
}
/**
* The fixed strip over the drawing and the right column (A6, LRN-131): left, what is
* selected or in progress on two lines; middle, a refusal or a reason; right, the commands.
* Its height never changes, so nothing under it moves when its content does.
*/
export default function EditStrip({
lead,
notice,
commands,
}: {
lead: StripLead
notice: StripNotice | null
commands: ReactNode
}) {
return (
<div
data-testid="edit-strip"
className="flex h-16 items-center gap-3 overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] px-3"
>
<Lead lead={lead} />
<div
data-testid="edit-strip-notice"
role="status"
className="min-w-0 flex-1"
>
{notice && <Notice notice={notice} />}
</div>
<div className="flex shrink-0 items-center gap-2 p-1">{commands}</div>
</div>
)
}
function Lead({ lead }: { lead: StripLead }) {
return (
<div
data-testid="edit-strip-lead"
className="flex min-w-0 max-w-[45%] shrink items-start gap-2"
>
<span className="mt-0.5 shrink-0 text-[var(--color-ink-muted)]">
<EditorGlyph name={lead.icon} size={16} />
</span>
<div className="min-w-0">
<p className="flex min-w-0 items-center gap-2">
<span
data-testid="edit-strip-title"
// Only a selection carries a review status: the e2e suites read it as « selected ».
data-selection={lead.status ? '' : undefined}
className="truncate text-sm font-semibold text-[var(--color-ink)]"
>
{lead.title}
</span>
{lead.status && (
<span className="shrink-0">
<ReviewBadge status={lead.status} />
</span>
)}
</p>
<p
data-testid="edit-strip-detail"
className="truncate text-xs text-[var(--color-ink-muted)]"
>
{lead.detail}
</p>
</div>
</div>
)
}
function Notice({ notice }: { notice: StripNotice }) {
const error = notice.tone === 'error'
return (
<p
role={error ? 'alert' : undefined}
className={`flex min-w-0 items-start gap-1 text-xs ${
error
? 'text-[var(--color-danger-strong)]'
: 'text-[var(--color-ink-muted)]'
}`}
>
<span className="line-clamp-2 min-w-0">{notice.text}</span>
{notice.more !== undefined && notice.more > 0 && (
<span className="shrink-0 font-semibold">+{notice.more}</span>
)}
{notice.link && (
<button
type="button"
className="shrink-0 underline"
onClick={notice.link.onClick}
>
{notice.link.label}
</button>
)}
</p>
)
}
@@ -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>
)
}
@@ -0,0 +1,79 @@
import type { ReactNode } from 'react'
import { useEditorReadOnly } from '@/editor/editingContext'
import type { GestureMessages } from '@/editor/annotations/useGestureMessage'
import { canUndo, useEditorStore } from '@/editor/state/editorStore'
import { useT } from '@/i18n/useT'
// Compact: at 1 280 px the column leaves about 145 px beside the three add buttons.
const PILL =
'inline-flex h-9 max-w-full items-center gap-1.5 rounded-md px-2 text-xs'
/** The header's undo (T15): the same store step, under the same conditions. */
function undoLast(readOnly: boolean): void {
const store = useEditorStore.getState()
if (!readOnly && canUndo(store)) store.undoStep()
}
/**
* The fixed line under the drawing (A14, R-2): the add buttons on the left, the message on
* the right, one line truncated. Its height never changes, so a message showing or leaving
* moves nothing. The status region (polite) is always mounted; a refusal is an alert of its own.
*/
export default function GestureMessage({
messages,
children,
}: {
messages: GestureMessages
children: ReactNode
}) {
return (
<div
data-testid="gesture-line"
className="flex h-11 items-center gap-2 overflow-hidden"
>
<div className="shrink-0">{children}</div>
<div
role="status"
className="flex min-w-0 flex-1 justify-end py-1 pr-0.5"
>
<Message messages={messages} />
</div>
</div>
)
}
function Message({ messages }: { messages: GestureMessages }) {
const t = useT()
const readOnly = useEditorReadOnly()
const { message, hold } = messages
if (!message) return null
const error = message.tone === 'error'
return (
<p
data-testid="gesture-message"
role={error ? 'alert' : undefined}
{...hold}
className={`${PILL} ${
error
? 'bg-[var(--color-danger-strong)] text-white'
: 'bg-[var(--color-ink)] text-[var(--color-bg)]'
}`}
>
<span className="truncate" title={message.text}>
{message.text}
</span>
{message.undo && !error && (
<>
<button
type="button"
aria-label={t('editor.history.undo_title')}
className="shrink-0 font-semibold underline-offset-2 hover:underline"
onClick={() => undoLast(readOnly)}
>
{t('editor.history.undo')}
</button>
</>
)}
</p>
)
}
@@ -21,7 +21,7 @@ export default function KeyboardAdd({
}) {
const t = useT()
return (
<div className="flex flex-wrap gap-2">
<div className="flex flex-nowrap gap-2">
{KINDS.map((kind) => (
<Button
key={kind}
@@ -50,7 +50,7 @@ export interface PropertiesPanelProps {
}
/** What still names this annotation as invalid: never hidden, never shown as valid. */
function useGeometryIssues(id: string): string[] {
export function useGeometryIssues(id: string): string[] {
const state = useEditorStore((s) => s.previewState)
const issues = state ? geometryErrorsById(state).get(id) : undefined
return [...new Set((issues ?? []).map((issue) => issue.message))]
@@ -1,34 +0,0 @@
import Button from '@/components/ui/Button'
import { usePlural } from '@/editor/plural'
import { useT } from '@/i18n/useT'
/** While a zone or link is being traced: close (3 vertices at least) or drop it. */
export default function TracingBar({
count,
onClose,
onCancel,
}: {
count: number
onClose: () => void
onCancel: () => void
}) {
const t = useT()
const plural = usePlural()
return (
<div
tabIndex={-1}
data-testid="tracing-bar"
className="flex flex-wrap items-center gap-2 outline-none"
>
<p className="text-sm text-[var(--color-ink-muted)]">
{plural('editor.annotations.tracing', count)}
</p>
<Button type="button" size="sm" disabled={count < 3} onClick={onClose}>
{t('editor.annotations.trace_close')}
</Button>
<Button type="button" size="sm" variant="ghost" onClick={onCancel}>
{t('editor.annotations.trace_cancel')}
</Button>
</div>
)
}
@@ -35,7 +35,7 @@ export interface DrawingState {
const BUSY_TARGET = {
creation: '[data-creation-heading]',
tracing: '[data-testid="tracing-bar"]',
tracing: '[data-testid="tracing-commands"]',
} as const
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
@@ -70,8 +70,8 @@ function showAnnotation(
/**
* « 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.
* the request is kept: nothing is dispatched (it would drop the work), the panel or the
* strip's tracing commands take the focus and the live region says why.
*/
export function useAnnotationRequest(
focus: FocusRequest | undefined,
@@ -0,0 +1,161 @@
import type {
Annotation,
AnatomicalSheetDocument,
ReviewStatus,
SheetView,
} from '@faunosteo/core-wasm/types'
import { annotationName } from '@/components/editor/annotations/AnnotationList'
import type { GlyphName } from '@/components/editor/EditorGlyph'
import type { Locale } from '@/i18n/types'
import { pluralKey } from '../plural'
import type { PendingElement } from './creation'
import type { ToolId, Tracing, UiState } from './uiState'
/** The strip's left part: what is selected or in progress, then its type and detail. */
export interface StripLead {
title: string
status?: ReviewStatus
detail: string
icon: GlyphName
}
export interface LeadContext {
t: (key: string) => string
locale: Locale
/** The sheet cannot be edited now: the detail says so (board 33 E). */
readOnly?: boolean
}
const ICON: Record<Annotation['kind'], GlyphName> = {
point: 'point',
zone: 'zone',
detail_trigger: 'link',
}
/** A count phrase of `key`; `{kind}` is filled too when given. */
function counted(
ctx: LeadContext,
key: string,
count: number,
kind = '',
): string {
return ctx
.t(pluralKey(ctx.locale, key, count))
.replace('{count}', String(count))
.replace('{kind}', () => kind)
}
/** « Point », « Zone · 9 sommets »; « … · fiche en lecture seule » when read-only. */
export function selectionLead(
annotation: Annotation,
views: readonly SheetView[],
ctx: LeadContext,
): StripLead {
const kind = ctx.t(`editor.annotations.kind.${annotation.kind}`)
const geometry = annotation.geometry
const shape =
geometry?.type === 'polygon'
? counted(
ctx,
'editor.annotations.strip.vertices',
geometry.points.length,
kind,
)
: kind
return {
title: annotationName(annotation, views, ctx.locale),
status: annotation.review_status,
detail: ctx.readOnly
? ctx
.t('editor.annotations.strip.read_only')
.replace('{detail}', () => shape)
: shape,
icon: ICON[annotation.kind],
}
}
/** A tracing: « Ajouter une zone » or « Redessiner · {nom} », then the vertices placed. */
function tracingLead(
tracing: Tracing,
replaced: string,
ctx: LeadContext,
): StripLead {
const title =
tracing.target === 'replace'
? ctx
.t('editor.annotations.strip.redraw')
.replace('{name}', () => replaced)
: ctx.t(`editor.annotations.add.${tracing.target}`)
return {
title,
detail: counted(ctx, 'editor.annotations.tracing', tracing.points.length),
icon: tracing.target === 'detail_trigger' ? 'link' : 'zone',
}
}
/** A pending creation, placed or closed, waiting for its properties. */
function pendingLead(pending: PendingElement, ctx: LeadContext): StripLead {
const { geometry } = pending
return {
title: ctx.t(`editor.annotations.new.${pending.kind}`),
detail:
geometry.type === 'polygon'
? counted(
ctx,
'editor.annotations.strip.closed',
geometry.points.length,
)
: ctx.t('editor.annotations.strip.placed'),
icon: ICON[pending.kind],
}
}
const TOOL_LEAD: Record<
ToolId,
{ title: string; detail: string; icon: GlyphName }
> = {
select: {
title: 'editor.annotations.tool.select',
detail: 'editor.annotations.strip.select',
icon: 'select',
},
point: {
title: 'editor.annotations.add.point',
detail: 'editor.annotations.strip.place_point',
icon: 'point',
},
zone: {
title: 'editor.annotations.add.zone',
detail: 'editor.annotations.strip.first_vertex',
icon: 'zone',
},
link: {
title: 'editor.annotations.add.detail_trigger',
detail: 'editor.annotations.strip.first_vertex',
icon: 'link',
},
}
/** What the strip leads with: a creation, then a tracing, then the selection, then the tool. */
export function stripLeadOf(
ui: UiState,
selected: Annotation | undefined,
doc: AnatomicalSheetDocument,
ctx: LeadContext,
): StripLead {
if (ui.pending) return pendingLead(ui.pending, ctx)
if (ui.tracing) {
const replaced = doc.annotations.find(
(a) => a.id === ui.tracing?.annotationId,
)
const name = replaced ? annotationName(replaced, doc.views, ctx.locale) : ''
return tracingLead(ui.tracing, name, ctx)
}
if (selected) return selectionLead(selected, doc.views, ctx)
const lead = TOOL_LEAD[ui.tool]
return {
title: ctx.t(lead.title),
detail: ctx.t(lead.detail),
icon: lead.icon,
}
}
@@ -33,6 +33,7 @@ export type UiAction =
| { type: 'pending_drop' }
| { type: 'trace_start'; target: Tracing['target']; annotationId?: string }
| { type: 'trace_add'; point: Point }
| { type: 'trace_pop' }
| { type: 'trace_cancel' }
| { type: 'hint'; hint: string | null }
| { type: 'filter'; term: string }
@@ -108,6 +109,16 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
},
}
: state
case 'trace_pop':
return state.tracing
? {
...state,
tracing: {
...state.tracing,
points: state.tracing.points.slice(0, -1),
},
}
: state
case 'trace_cancel':
return { ...state, tracing: null, hint: null }
case 'hint':
@@ -0,0 +1,93 @@
import { useEffect, useState, type FocusEvent, type PointerEvent } from 'react'
import { useEditorStore } from '../state/editorStore'
/** A6/A14: how long a message stays (R-2) and how long a hint does (R-1). */
const MESSAGE_MS = 6_000
const HINT_MS = 4_000
/** The document and the history a message was shown on: any change closes it (R-2). */
interface Stamp {
text: string
undo: number
redo: number
}
export interface GestureMessage {
text: string
tone: 'info' | 'error'
/** Offers « Défaire » (a kept gesture); never on a refusal. */
undo: boolean
hint: boolean
stamp: Stamp
}
function currentStamp(): Stamp {
const { documentText, undo, redo } = useEditorStore.getState()
return { text: documentText, undo: undo.length, redo: redo.length }
}
/** The shown message while the document and both history stacks are those it was shown on. */
function useLive(message: GestureMessage | null): GestureMessage | null {
const text = useEditorStore((s) => s.documentText)
const undo = useEditorStore((s) => s.undo.length)
const redo = useEditorStore((s) => s.redo.length)
if (!message) return null
const { stamp } = message
const same = stamp.text === text && stamp.undo === undo && stamp.redo === redo
return same ? message : null
}
/** Hover with a mouse and focus inside hold the message; a touch never does (R-2). */
function useHold() {
const [hovered, setHovered] = useState(false)
const [focused, setFocused] = useState(false)
const handlers = {
onPointerEnter: (event: PointerEvent) => {
if (event.pointerType === 'mouse') setHovered(true)
},
onPointerLeave: () => setHovered(false),
onFocus: () => setFocused(true),
onBlur: (event: FocusEvent<HTMLElement>) => {
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {
setFocused(false)
}
},
}
return { held: hovered || focused, handlers }
}
/**
* The line under the drawing (A14, R-2): « Point déplacé · Défaire » after a gesture, a
* refusal in red, or a hint while nothing else is shown. A message lasts 6 s, held while a
* mouse hovers it or the focus is inside; any commit, undo or redo closes it.
*/
export function useGestureMessage() {
const [shown, setShown] = useState<GestureMessage | null>(null)
const message = useLive(shown)
const { held, handlers } = useHold()
useEffect(() => {
if (!message || held) return
const timer = setTimeout(
() => setShown(null),
message.hint ? HINT_MS : MESSAGE_MS,
)
return () => clearTimeout(timer)
}, [message, held])
const show = (
text: string,
{ undo, tone }: { undo: boolean; tone: GestureMessage['tone'] },
) => setShown({ text, tone, undo, hint: false, stamp: currentStamp() })
const hint = (text: string) => {
if (message) return
setShown({
text,
tone: 'info',
undo: false,
hint: true,
stamp: currentStamp(),
})
}
return { message, show, hint, hold: handlers }
}
export type GestureMessages = ReturnType<typeof useGestureMessage>
@@ -9,6 +9,7 @@ import { updateGeometry, type CommitContext } from './annotationCommit'
import { pendingForClick, type NewKind } from './creation'
import { round2, type Frame, type XY } from './frame'
import type { ToolId, Tracing, UiAction, UiState } from './uiState'
import type { GestureMessages } from './useGestureMessage'
/** A click on the first vertex closes the tracing when within this share of F's span. */
const CLOSE_SHARE = 0.015
@@ -25,6 +26,8 @@ export interface PlacementInput {
frame: Frame | null
doc: AnatomicalSheetDocument
context: CommitContext
/** The line under the drawing: a kept drop says so with « Défaire », a refused one in red. */
message: Pick<GestureMessages, 'show'>
}
const asPoint = (at: XY): Point => [round2(at.x), round2(at.y)]
@@ -62,7 +65,7 @@ export function closingActions(
]
}
/** Tracing with the zone and link tools: vertices, closing, Enter and Escape. */
/** Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. */
function tracingActions(input: PlacementInput) {
const { ui, dispatch, frame } = input
const closeTracing = () =>
@@ -79,6 +82,10 @@ function tracingActions(input: PlacementInput) {
const onTraceKey = (event: KeyboardEvent) => {
if (!ui.tracing) return
if (event.key === 'Enter') closeTracing()
if (event.key === 'Backspace') {
event.preventDefault()
dispatch({ type: 'trace_pop' })
}
if (event.key === 'Escape') {
event.preventDefault()
dispatch({ type: 'trace_cancel' })
@@ -87,14 +94,22 @@ function tracingActions(input: PlacementInput) {
return { closeTracing, trace, onTraceKey }
}
/** A drop commits one update; the hint holds the core's words on a refusal. */
function dropAction(input: PlacementInput) {
/** A drop commits one update; the line under the drawing says it, or the core's refusal. */
function dropAction({ doc, context, message }: PlacementInput) {
return (id: string, geometry: Geometry) => {
const annotation = input.doc.annotations.find((a) => a.id === id)
const annotation = doc.annotations.find((a) => a.id === id)
if (!annotation) return
const result = updateGeometry(annotation, geometry, input.context)
const hint = result.ok ? null : result.messages.join(' ')
input.dispatch({ type: 'hint', hint })
const result = updateGeometry(annotation, geometry, context)
if (result.ok) {
const text = context.t(
`editor.annotations.message.moved.${annotation.kind}`,
)
return message.show(text, { undo: true, tone: 'info' })
}
const text = context
.t('editor.annotations.message.move_refused')
.replace('{text}', () => result.messages.join(' '))
message.show(text, { undo: false, tone: 'error' })
}
}
@@ -122,5 +137,6 @@ export function usePlacement(input: PlacementInput) {
onDrop: dropAction(input),
onTraceKey: tracing.onTraceKey,
closeTracing: tracing.closeTracing,
popVertex: () => dispatch({ type: 'trace_pop' }),
}
}
+17 -6
View File
@@ -1598,10 +1598,6 @@ export const en: Dict = {
'editor.annotations.tool.point': 'Point',
'editor.annotations.tool.zone': 'Zone',
'editor.annotations.tool.link': 'Link to a detail view',
'editor.annotations.tool_hint.select': 'Tool: select and move · Esc cancels a tracing',
'editor.annotations.tool_hint.point': 'Tool: point · click in the drawing to place a point.',
'editor.annotations.tool_hint.zone': 'Tool: zone · click to place the vertices; Enter or « Close the tracing » finishes, Esc cancels.',
'editor.annotations.tool_hint.link': 'Tool: link to a detail view · trace the outline that opens the view; Enter finishes, Esc cancels.',
'editor.annotations.views': 'Views',
'editor.annotations.unmeasured.hint': 'This drawing cannot be measured: add or fix its illustration (Annotations, Views section) before placing or moving elements.',
'editor.annotations.outside': 'Click inside the drawing.',
@@ -1646,10 +1642,25 @@ export const en: Dict = {
'editor.annotations.list_empty': 'No annotation in this view.',
'editor.annotations.selection': 'Selection: {kind} « {name} »',
'editor.annotations.properties': 'Annotation properties',
'editor.annotations.tracing_one': '{count} vertex placed.',
'editor.annotations.tracing_other': '{count} vertices placed.',
'editor.annotations.tracing_one': '{count} vertex placed',
'editor.annotations.tracing_other': '{count} vertices placed',
'editor.annotations.trace_close': 'Close the tracing',
'editor.annotations.trace_cancel': 'Cancel the tracing',
'editor.annotations.trace_pop': 'Remove last vertex',
'editor.annotations.strip.select': 'Click an annotation to select it',
'editor.annotations.strip.place_point': 'Click in the drawing to place the point',
'editor.annotations.strip.first_vertex': 'Click in the drawing to place the first vertex',
'editor.annotations.strip.vertices_one': '{kind} · {count} vertex',
'editor.annotations.strip.vertices_other': '{kind} · {count} vertices',
'editor.annotations.strip.read_only': '{detail} · read-only sheet',
'editor.annotations.strip.redraw': 'Redraw · {name}',
'editor.annotations.strip.placed': 'Point placed, waiting for its properties',
'editor.annotations.strip.closed_one': 'Tracing closed, {count} vertex, waiting for its properties',
'editor.annotations.strip.closed_other': 'Tracing closed, {count} vertices, waiting for its properties',
'editor.annotations.message.moved.point': 'Point moved',
'editor.annotations.message.moved.zone': 'Zone moved',
'editor.annotations.message.moved.detail_trigger': 'Access moved',
'editor.annotations.message.move_refused': 'Move refused: {text}',
'editor.annotations.replace_polygon': 'Replace with a polygon',
'editor.annotations.no_geometry': 'This annotation has no geometry: trace a polygon to give it one.',
'editor.annotations.path': 'This annotation is a free path: its data cannot be edited here.',
+17 -6
View File
@@ -1628,10 +1628,6 @@ export const fr: Dict = {
'editor.annotations.tool.point': 'Point',
'editor.annotations.tool.zone': 'Zone',
'editor.annotations.tool.link': 'Accès à une vue détaillée',
'editor.annotations.tool_hint.select': 'Outil : sélectionner et déplacer · Échap annule un tracé',
'editor.annotations.tool_hint.point': 'Outil : point · cliquez dans le dessin pour placer un point.',
'editor.annotations.tool_hint.zone': 'Outil : zone · cliquez pour poser les sommets ; Entrée ou « Fermer le tracé » termine, Échap annule.',
'editor.annotations.tool_hint.link': 'Outil : accès à une vue détaillée · tracez le contour qui ouvre la vue ; Entrée termine, Échap annule.',
'editor.annotations.views': 'Vues',
'editor.annotations.unmeasured.hint': "Ce dessin n'est pas mesurable : ajoutez ou corrigez son illustration (Annotations, section Vues) avant de placer ou de déplacer des éléments.",
'editor.annotations.outside': "Cliquez à l'intérieur du dessin.",
@@ -1676,10 +1672,25 @@ export const fr: Dict = {
'editor.annotations.list_empty': 'Aucune annotation dans cette vue.',
'editor.annotations.selection': 'Sélection : {kind} « {name} »',
'editor.annotations.properties': "Propriétés de l'annotation",
'editor.annotations.tracing_one': '{count} sommet posé.',
'editor.annotations.tracing_other': '{count} sommets posés.',
'editor.annotations.tracing_one': '{count} sommet posé',
'editor.annotations.tracing_other': '{count} sommets posés',
'editor.annotations.trace_close': 'Fermer le tracé',
'editor.annotations.trace_cancel': 'Annuler le tracé',
'editor.annotations.trace_pop': 'Retirer le dernier sommet',
'editor.annotations.strip.select': 'Cliquez sur une annotation pour la sélectionner',
'editor.annotations.strip.place_point': 'Cliquez dans le dessin pour placer le point',
'editor.annotations.strip.first_vertex': 'Cliquez dans le dessin pour poser le premier sommet',
'editor.annotations.strip.vertices_one': '{kind} · {count} sommet',
'editor.annotations.strip.vertices_other': '{kind} · {count} sommets',
'editor.annotations.strip.read_only': '{detail} · fiche en lecture seule',
'editor.annotations.strip.redraw': 'Redessiner · {name}',
'editor.annotations.strip.placed': 'Point placé, en attente de ses propriétés',
'editor.annotations.strip.closed_one': 'Tracé fermé, {count} sommet, en attente de ses propriétés',
'editor.annotations.strip.closed_other': 'Tracé fermé, {count} sommets, en attente de ses propriétés',
'editor.annotations.message.moved.point': 'Point déplacé',
'editor.annotations.message.moved.zone': 'Zone déplacée',
'editor.annotations.message.moved.detail_trigger': 'Accès déplacé',
'editor.annotations.message.move_refused': 'Déplacement refusé : {text}',
'editor.annotations.replace_polygon': 'Remplacer par un polygone',
'editor.annotations.no_geometry': "Cette annotation n'a pas de géométrie : tracez un polygone pour lui en donner une.",
'editor.annotations.path': 'Cette annotation est un tracé libre (path) : ses données ne se modifient pas ici.',
+2
View File
@@ -4,6 +4,8 @@
html, body, #root { height: 100%; }
/* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */
html:has(dialog:modal) { overflow: hidden; }
/* The editor keeps its scrollbar width whatever opens or closes (R-2, A14): nothing moves. */
html:has([data-editor-workspace]) { scrollbar-gutter: stable; }
body {
background: var(--color-bg);
color: var(--color-ink);