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,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>
|
||||
Reference in new issue
Block a user