Files
faunosteo/apps/app/src/editor/annotations/uiState.ts
T
bchanot 1deb037fac 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)
2026-11-17 17:45:41 +01:00

130 lines
3.5 KiB
TypeScript

import type { Point } from '@faunosteo/core-wasm/types'
import type { NewKind, PendingElement } from './creation'
export type ToolId = 'select' | 'point' | 'zone' | 'link'
/** A tracing in progress: a new zone or link, or a polygon replacing a geometry. */
export interface Tracing {
target: NewKind | 'replace'
/** The annotation whose geometry the tracing replaces (target `replace`). */
annotationId: string | null
points: Point[]
}
export interface UiState {
viewId: string | null
tool: ToolId
selectedId: string | null
pending: PendingElement | null
/** Bumped by every new pending element: keys the creation form's own state. */
serial: number
tracing: Tracing | null
hint: string | null
/** The overview's « Filtrer par nom » term: it outlives a selection, not a view. */
filter: string
}
export type UiAction =
| { type: 'view'; viewId: string }
| { type: 'tool'; tool: ToolId }
| { type: 'select'; id: string | null }
| { type: 'pending_new'; pending: PendingElement }
| { type: 'pending_update'; pending: PendingElement }
| { 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 }
export const initialUi: UiState = {
viewId: null,
tool: 'select',
selectedId: null,
pending: null,
serial: 0,
tracing: null,
hint: null,
filter: '',
}
const TOOL_OF: Record<Tracing['target'], ToolId> = {
point: 'point',
zone: 'zone',
detail_trigger: 'link',
replace: 'zone',
}
export function uiReducer(state: UiState, action: UiAction): UiState {
switch (action.type) {
case 'view':
return { ...initialUi, viewId: action.viewId }
case 'tool':
return { ...state, tool: action.tool, tracing: null, hint: null }
case 'select':
return {
...state,
selectedId: action.id,
pending: null,
tracing: null,
hint: null,
}
case 'pending_new':
return {
...state,
pending: action.pending,
// A second click with the same kind keeps the typed fields (same panel).
serial:
state.pending?.kind === action.pending.kind
? state.serial
: state.serial + 1,
selectedId: null,
tracing: null,
hint: null,
}
case 'pending_update':
return state.pending ? { ...state, pending: action.pending } : state
case 'pending_drop':
return { ...state, pending: null, hint: null }
case 'trace_start':
return {
...state,
tool: TOOL_OF[action.target],
pending: null,
hint: null,
tracing: {
target: action.target,
annotationId: action.annotationId ?? null,
points: [],
},
}
case 'trace_add':
return state.tracing
? {
...state,
tracing: {
...state.tracing,
points: [...state.tracing.points, action.point],
},
}
: 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':
return { ...state, hint: action.hint }
case 'filter':
return { ...state, filter: action.term }
}
}