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:
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>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user