fix(editor): slider while replacing, announced drop, review minors

Task 7 fix round 1 (review task-7-review.md).
- Important 1: « Taille » shows beside « Revenir aux propriétés » while
  a point is replaced (still hidden under the modal dialog); it feeds
  the hover preview and the re-placed point (R-10).
- Important 2: a creation whose view leaves the document is dropped
  and said, « Création abandonnée : la fiche a changé. » (dropped:
  'creation', read by useDroppedNotice).
- Minor 3: DrawingGuardDialog leaves a creation question to the
  creation dialog only while that dialog is really on screen
  (creationShown, set by the dialog).
- Minor 7: the dialog's long className strings split into constants.
- Minor 8: dead TOOL_OF removed; trace_start is a redraw's only.

Tests added (no assertion removed): slider while replacing (unit,
RED then GREEN; e2e under expectNoShift at three widths, last strip
command inside the strip); view removed during a creation (RED then
GREEN); question shown by the workspace when the dialog is not on
screen (RED then GREEN); « Abandonner » while read-only; R-13 with a
restored copy during a started move; leaving the route resets the
work (fails with the session reset removed). The unit Back test's
comment is corrected: it does pin the modal branch.
This commit is contained in:
bchanot committed 2026-11-18 00:06:16 +01:00
1 parent fe333c2bbd
commit 837ec9f436
14 files changed
+315 -29

No files matched your search

@@ -1,4 +1,4 @@
import { useRef, useState, type RefObject } from 'react'
import { useEffect, useRef, useState, type RefObject } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import DiscardConfirm from '@/components/editor/findings/DiscardConfirm'
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
@@ -87,6 +87,17 @@ function useCreate(work: Creation, created: { current: boolean }) {
/** « Point placé · Replacer le point », « Zone tracée, 5 sommets · Reprendre le tracé ». */
const GLYPH = { point: 'point', zone: 'zone', detail_trigger: 'link' } as const
/** The dialog's first line (board 02, 04): the shape, then « Replacer » or « Reprendre ». */
const LINE =
'flex flex-wrap items-center gap-x-2 gap-y-1 rounded-lg ' +
'bg-[var(--color-surface-strong)] px-3 py-2 text-sm outline-none'
/** Its link-styled button: the strong accent passes axe's contrast on that background. */
const LINK =
'min-h-11 font-medium text-[var(--color-accent-strong)] underline underline-offset-2 ' +
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] ' +
'disabled:cursor-not-allowed disabled:opacity-40 xl:min-h-0'
/** « Point placé », « Zone tracée, 5 sommets », « Accès tracé, 3 sommets ». */
function useShapeText(pending: Creation['pending']): string {
const t = useT()
@@ -104,18 +115,14 @@ function ShapeLine({ work, readOnly }: { work: Creation; readOnly: boolean }) {
const text = useShapeText(work.pending)
const point = work.pending.kind === 'point'
return (
<div
data-creation-focus=""
tabIndex={-1}
className="flex flex-wrap items-center gap-x-2 gap-y-1 rounded-lg bg-[var(--color-surface-strong)] px-3 py-2 text-sm outline-none"
>
<div data-creation-focus="" tabIndex={-1} className={LINE}>
<EditorGlyph name={GLYPH[work.pending.kind]} size={16} />
<span>{text}</span>
<button
type="button"
disabled={readOnly}
onClick={point ? replacePoint : resumeTrace}
className="min-h-11 font-medium text-[var(--color-accent-strong)] underline underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] disabled:cursor-not-allowed disabled:opacity-40 xl:min-h-0"
className={LINK}
>
{t(`editor.annotations.creation.${point ? 'replace' : 'resume'}`)}
</button>
@@ -244,6 +251,14 @@ function useCreationReturn(work: Creation | null) {
return { created, returnFocus }
}
/** Tells the workspace's guard dialog whether this dialog is on screen (it asks inside). */
function useShownFlag(open: boolean) {
useEffect(() => {
useAnnotationWork.setState({ creationShown: open })
return () => useAnnotationWork.setState({ creationShown: false })
}, [open])
}
/**
* « Nouveau point », « Nouvelle zone », « Nouvel accès » (board 02, 04): a modal without a
* history layer over the right column, mounted outside the edit-only body so a read-only
@@ -255,9 +270,11 @@ export default function CreationDialog(props: CreationDialogProps) {
const visible = usePlaceVisible()
const work = useAnnotationWork((s) => s.creation)
const back = useCreationReturn(work)
const open = visible && work !== null && work.dialog
useShownFlag(open)
return (
<Dialog
open={visible && work !== null && work.dialog}
open={open}
anchor={props.anchor}
veilCloses={false}
title={work ? t(`editor.annotations.new.${work.pending.kind}`) : ''}
@@ -13,7 +13,7 @@ export default function DrawingGuardDialog() {
const t = useT()
// Over a shown creation dialog the question is that dialog's own (R-12, board 31 D).
const question = useAnnotationWork((s) =>
s.question?.work === 'creation' && s.creation?.dialog ? null : s.question,
s.question?.work === 'creation' && s.creationShown ? null : s.question,
)
// The title stays while the dialog closes.
const title = useRef('')
@@ -140,7 +140,24 @@ function SceneCommands({
)
// The dialog shown: its own actions; hidden after it was shown: board 04 C.
if (creation?.dialog) return null
if (creation?.resumed) return <CreationCommands creation={creation} />
if (creation?.resumed) {
// A point being replaced: its size is still chosen here (board 02, R-10).
const replacing = creation.closed && frame
return (
<>
{replacing && (
<ToolSize
doc={doc}
viewId={viewId}
frame={frame}
size={ui.size}
dispatch={dispatch}
/>
)}
<CreationCommands creation={creation} />
</>
)
}
if (tracing) {
// « Annuler le tracé » is an explicit cancel: it acts at once (board 04 A).
const redraw = tracing.target === 'replace'
@@ -139,6 +139,15 @@ export function dropCreation(): void {
useAnnotationWork.setState({ creation: null, question: lapsed() })
}
/** A document change removed the creation's view (R-13): dropped, and said by the tab. */
export function dropCreationGone(): void {
useAnnotationWork.setState({
creation: null,
question: lapsed(),
dropped: 'creation',
})
}
/** « Créer » succeeded: the creation ends, the drawing selects `id` (A7). */
export function finishCreation(id: string, kind: NewKind): void {
useAnnotationWork.setState({
+5 -10
View File
@@ -32,7 +32,8 @@ export type UiAction =
| { type: 'view'; viewId: string }
| { type: 'tool'; tool: ToolId }
| { type: 'select'; id: string | null }
| { type: 'trace_start'; target: Tracing['target']; annotationId?: string }
/** A redraw's tracing (a new shape's is the creation's, U2 Task 7). */
| { type: 'trace_start'; target: 'replace'; annotationId: string }
| { type: 'trace_add'; point: Point }
| { type: 'trace_pop' }
| { type: 'trace_cancel' }
@@ -51,13 +52,6 @@ export const initialUi: UiState = {
size: null,
}
const TOOL_OF: Record<Tracing['target'], ToolId> = {
point: 'point',
zone: 'zone',
detail_trigger: 'link',
replace: 'zone',
}
/** A redraw lends the zone tool to its tracing: whatever ends it gives the select tool back. */
const toolAfterTracing = (state: UiState): ToolId =>
state.tracing?.target === 'replace' ? 'select' : state.tool
@@ -89,11 +83,12 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
case 'trace_start':
return {
...state,
tool: TOOL_OF[action.target],
// A redraw lends the zone tool to its tracing.
tool: 'zone',
hint: null,
tracing: {
target: action.target,
annotationId: action.annotationId ?? null,
annotationId: action.annotationId,
points: [],
refused: false,
},
@@ -2,7 +2,7 @@ import { useEffect, useRef, type Dispatch } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed'
import type { NewKind } from './creation'
import { dropCreation } from './creationWork'
import { dropCreationGone } from './creationWork'
import { focusRowOrDrawing } from './deselect'
import type { ToolId, UiAction, UiState } from './uiState'
import type { GestureMessages } from './useGestureMessage'
@@ -26,7 +26,7 @@ export interface CreationFollow {
/**
* The drawing kept in step with the creation: nothing selected once its shape is placed, its tool
* on while the dialog is hidden (« Replacer le point » places with the point tool, a
* resumed tracing traces), and dropped when its view no longer exists.
* resumed tracing traces), and dropped, said, when its view no longer exists (R-13).
*/
function useDrawingFollows({ doc, ui, dispatch, creation }: CreationFollow) {
const wanted =
@@ -43,7 +43,7 @@ function useDrawingFollows({ doc, ui, dispatch, creation }: CreationFollow) {
if (selected) dispatch({ type: 'select', id: null })
}, [selected, dispatch])
useEffect(() => {
if (gone) dropCreation()
if (gone) dropCreationGone()
}, [gone])
}
+11 -2
View File
@@ -59,16 +59,25 @@ export interface DrawingQuestion {
}
interface Work {
creation: Creation | null
/**
* The creation dialog is really on screen (its place shown): only then does it ask the
* creation's question in its own footer instead of the workspace's dialog.
*/
creationShown: boolean
created: Created | null
mode: ModeWork | null
preview: Preview | null
chosen: Chosen | null
/** A started mode a document change dropped (R-13): the tab says so, then clears it. */
dropped: ModeWork['kind'] | null
/**
* Work a document change dropped (R-13): a started mode, or a creation whose view left the
* document. The tab says so, then clears it.
*/
dropped: ModeWork['kind'] | 'creation' | null
question: DrawingQuestion | null
}
const NO_WORK: Work = {
creation: null,
creationShown: false,
created: null,
mode: null,
preview: null,
+2
View File
@@ -1883,6 +1883,8 @@ export const en: Dict = {
'editor.annotations.dropped.move': 'Move discarded: the sheet changed.',
'editor.annotations.dropped.redraw':
'New tracing discarded: the sheet changed.',
'editor.annotations.dropped.creation':
'Creation discarded: the sheet changed.',
'editor.annotations.replace_polygon': 'Replace with a polygon',
'editor.annotations.no_geometry':
'This annotation has no geometry: trace a polygon to give it one.',
+2
View File
@@ -1953,6 +1953,8 @@ export const fr: Dict = {
'Déplacement abandonné : la fiche a changé.',
'editor.annotations.dropped.redraw':
'Nouveau tracé abandonné : la fiche a changé.',
'editor.annotations.dropped.creation':
'Création abandonnée : la fiche a changé.',
'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.",