fix(editor): message line lifecycle, own row, sound no-shift check
Task 3 review, fix round 1. - The gesture message closes for good on any document or history change (store subscription): undo then redo no longer revives it. - Hover and focus hold only the message they were taken on: after « Défaire » the next message expires. - An accepted drop clears the strip's refusal hint again. - Controller ruling: the message has its own fixed row under the add buttons, column width; a refused gesture's full text also shows in the strip notice (red, aria-hidden copy of the row's alert). - expectNoShift: native requestAnimationFrame kept before page.clock (keepNativeFrames), every part box asserted non-null, message row measured; the e2e checks the message is not truncated. No assertion removed; the refused-drop unit test gains the strip copy.
This commit is contained in:
1 parent
1deb037fac
commit
7a45f1d885
9 files changed
+198
-49
No files matched your search
@@ -12,6 +12,8 @@ export interface StripNotice {
|
||||
/** How many more of the same kind are not shown (« +n »). */
|
||||
more?: number
|
||||
link?: { label: string; onClick(): void }
|
||||
/** Already announced elsewhere (the gesture line's alert): shown, not announced twice. */
|
||||
quiet?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +88,8 @@ function Notice({ notice }: { notice: StripNotice }) {
|
||||
const error = notice.tone === 'error'
|
||||
return (
|
||||
<p
|
||||
role={error ? 'alert' : undefined}
|
||||
role={error && !notice.quiet ? 'alert' : undefined}
|
||||
aria-hidden={notice.quiet || undefined}
|
||||
className={`flex min-w-0 items-start gap-1 text-xs ${
|
||||
error
|
||||
? 'text-[var(--color-danger-strong)]'
|
||||
|
||||
@@ -14,6 +14,7 @@ import { usePlacement } from '@/editor/annotations/usePlacement'
|
||||
import { stripLeadOf } from '@/editor/annotations/stripLead'
|
||||
import {
|
||||
useGestureMessage,
|
||||
type GestureMessage as ShownMessage,
|
||||
type GestureMessages,
|
||||
} from '@/editor/annotations/useGestureMessage'
|
||||
import {
|
||||
@@ -152,7 +153,7 @@ export default function EditableAnnotations(props: Props) {
|
||||
)
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<SceneStrip scene={scene} placement={placement} />
|
||||
<SceneStrip scene={scene} placement={placement} message={message} />
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<CanvasColumn
|
||||
scene={scene}
|
||||
@@ -336,13 +337,15 @@ function overlayOf(
|
||||
function SceneStrip({
|
||||
scene,
|
||||
placement,
|
||||
message,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
message: GestureMessages
|
||||
}) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const notice = useStripNotice(scene)
|
||||
const notice = useStripNotice(scene, message.message)
|
||||
const { ui, selected, doc } = scene
|
||||
return (
|
||||
<EditStrip
|
||||
@@ -362,14 +365,21 @@ function SceneStrip({
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* The strip's middle, first match wins: a refusal (the strip's own, then a refused gesture
|
||||
* whose line under the drawing may be cut short: its full text here, A6), the selection's
|
||||
* geometry issues (the first, then « +n »), then why a tool cannot be used now.
|
||||
*/
|
||||
function useStripNotice(scene: Scene): StripNotice | null {
|
||||
function useStripNotice(
|
||||
scene: Scene,
|
||||
message: ShownMessage | null,
|
||||
): 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 (message?.tone === 'error') {
|
||||
return { tone: 'error', text: message.text, quiet: true }
|
||||
}
|
||||
if (scene.selected && issues.length > 0) {
|
||||
return { tone: 'error', text: issues[0]!, more: issues.length - 1 }
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ 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'
|
||||
'inline-flex h-9 max-w-full items-center gap-2 rounded-md px-3 text-sm'
|
||||
|
||||
/** The header's undo (T15): the same store step, under the same conditions. */
|
||||
function undoLast(readOnly: boolean): void {
|
||||
@@ -15,9 +14,10 @@ function undoLast(readOnly: boolean): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Under the drawing (A14, R-2): the add buttons, then the message on a row of its own, the
|
||||
* drawing column's full width, one line truncated. The row is always there at a fixed
|
||||
* height, so a message showing or leaving moves nothing. The status region (polite) is
|
||||
* always mounted; a refusal is an alert of its own (its full text is also in the strip).
|
||||
*/
|
||||
export default function GestureMessage({
|
||||
messages,
|
||||
@@ -27,18 +27,16 @@ export default function GestureMessage({
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-testid="gesture-line"
|
||||
className="flex h-11 items-center gap-2 overflow-hidden"
|
||||
>
|
||||
<div className="shrink-0">{children}</div>
|
||||
<>
|
||||
{children}
|
||||
<div
|
||||
data-testid="gesture-line"
|
||||
role="status"
|
||||
className="flex min-w-0 flex-1 justify-end py-1 pr-0.5"
|
||||
className="flex h-11 items-center justify-end overflow-hidden px-1"
|
||||
>
|
||||
<Message messages={messages} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -64,6 +62,7 @@ function Message({ messages }: { messages: GestureMessages }) {
|
||||
</span>
|
||||
{message.undo && !error && (
|
||||
<>
|
||||
<span aria-hidden="true">·</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('editor.history.undo_title')}
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function KeyboardAdd({
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex flex-nowrap gap-2">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{KINDS.map((kind) => (
|
||||
<Button
|
||||
key={kind}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { useEffect, useState, type FocusEvent, type PointerEvent } from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
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). */
|
||||
@@ -26,34 +32,49 @@ function currentStamp(): Stamp {
|
||||
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
|
||||
const sameStamp = (a: Stamp, b: Stamp) =>
|
||||
a.text === b.text && a.undo === b.undo && a.redo === b.redo
|
||||
|
||||
/**
|
||||
* Any change of the document or of either history stack closes the shown message for
|
||||
* good: an undo then a redo restores the same stamp, which must not bring it back (R-2).
|
||||
*/
|
||||
function useCloseOnChange(close: (now: Stamp) => void): void {
|
||||
useEffect(
|
||||
() =>
|
||||
useEditorStore.subscribe((state, before) => {
|
||||
const changed =
|
||||
state.documentText !== before.documentText ||
|
||||
state.undo.length !== before.undo.length ||
|
||||
state.redo.length !== before.redo.length
|
||||
if (changed) close(currentStamp())
|
||||
}),
|
||||
[close],
|
||||
)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
/**
|
||||
* Hover with a mouse and focus inside hold the message; a touch never does (R-2). The hold
|
||||
* belongs to the message it was taken on: a message that closes (« Défaire » pressed, the
|
||||
* pill unmounted without pointerleave or blur) leaves no hold on the next one.
|
||||
*/
|
||||
function useHold(message: GestureMessage | null) {
|
||||
const [hovered, setHovered] = useState<GestureMessage | null>(null)
|
||||
const [focused, setFocused] = useState<GestureMessage | null>(null)
|
||||
const handlers = {
|
||||
onPointerEnter: (event: PointerEvent) => {
|
||||
if (event.pointerType === 'mouse') setHovered(true)
|
||||
if (event.pointerType === 'mouse') setHovered(message)
|
||||
},
|
||||
onPointerLeave: () => setHovered(false),
|
||||
onFocus: () => setFocused(true),
|
||||
onPointerLeave: () => setHovered(null),
|
||||
onFocus: () => setFocused(message),
|
||||
onBlur: (event: FocusEvent<HTMLElement>) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {
|
||||
setFocused(false)
|
||||
setFocused(null)
|
||||
}
|
||||
},
|
||||
}
|
||||
return { held: hovered || focused, handlers }
|
||||
const held = message !== null && (hovered === message || focused === message)
|
||||
return { held, handlers }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,9 +83,17 @@ function useHold() {
|
||||
* 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()
|
||||
const [message, setShown] = useState<GestureMessage | null>(null)
|
||||
const { held, handlers } = useHold(message)
|
||||
// A message shown after its own commit carries that commit's stamp: it stays.
|
||||
const close = useCallback(
|
||||
(now: Stamp) =>
|
||||
setShown((shown) =>
|
||||
shown && sameStamp(shown.stamp, now) ? shown : null,
|
||||
),
|
||||
[],
|
||||
)
|
||||
useCloseOnChange(close)
|
||||
useEffect(() => {
|
||||
if (!message || held) return
|
||||
const timer = setTimeout(
|
||||
|
||||
@@ -95,12 +95,14 @@ function tracingActions(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) {
|
||||
function dropAction({ doc, context, message, dispatch }: PlacementInput) {
|
||||
return (id: string, geometry: Geometry) => {
|
||||
const annotation = doc.annotations.find((a) => a.id === id)
|
||||
if (!annotation) return
|
||||
const result = updateGeometry(annotation, geometry, context)
|
||||
if (result.ok) {
|
||||
// A kept move ends any refusal the strip still shows.
|
||||
dispatch({ type: 'hint', hint: null })
|
||||
const text = context.t(
|
||||
`editor.annotations.message.moved.${annotation.kind}`,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user