feat(editor): creation on the drawing then the creation dialog
U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14). The work store's `creation` owns the new shape, its form, its view and F: a click with the point tool, a closed tracing or a keyboard « Ajouter … » opens « Nouveau point / zone / accès », a modal without a history layer over the right column, mounted beside EditOnly so a read-only flip keeps it (« Créer », « Replacer », « Reprendre » off). A new zone or link is a creation from its first vertex. The ghost takes the form's category colour; the point tool previews under a mouse; the canvas carries data-creating (other markers dimmed, unselectable). « Replacer le point » / « Reprendre le tracé » hide the dialog and keep the form; the strip offers « Revenir aux propriétés », « Retirer le dernier sommet », « Abandonner ». « Créer »: one insert, tool back to « Sélectionner », the new element selected, « Point créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back always ask « Abandonner la création ? » (DiscardConfirm inside the dialog; DrawingGuardDialog elsewhere); answerDrawing drops the creation. Undo, its shortcuts and the line's « Défaire » are inactive during a creation. missingFields replaces formProblem (MissingSummary shared with the edit form); the C26 notice has no numbers. CreationPanel, formProblem, withGeometry and the keys required.fields, required.names and create_cancel are gone; GeometryGroup is imported by RepairDialog only. Removed or rewritten assertions: - tab « holds a point at the frame centre »: « Centre x » = 50 -> the ghost circle cx = 50; plus tool back to Sélectionner, « Point créé », one undo step. - tab « refuses a creation without laterality »: the general line « Choisissez la catégorie et la latéralité » -> only « Choisissez une latéralité. » and « À compléter : Latéralité. », focus on it. - tab « applies the geometry group to a pending zone »: removed (A8, no coordinate field) -> « places a triangle at the centre: the ghost shows it, Créer inserts it »; vertex edits after Créer are the e2e keyboard test. - tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4 text, the notice inside the dialog; cancel test « Centre x » = 0 -> ghost cx = 0. - tab « offers the correction when the core refuses a pending point » (typed cx 98): removed, no typed coordinate is possible; the verdict path stays covered by the C26 click tests and correctionFor units. - tab H5 « a typed radius shows the core issue »: removed (A8); the size refusal is the slider's (Task 4 tests). - tab H6 « a second click moves the pending point »: -> « Replacer le point », then the click moves the ghost, the form kept. - tab H7 « Centre x/y » = 30/50 -> ghost cx/cy. - tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the tracing on Escape » -> Escape asks first (board 32 row 3), Continuer keeps, Abandonner drops; new « Annuler le tracé acts at once ». - keep-alive « a pending creation is kept and focused » and « a tracing … is kept and focused »: the tab now asks first (R-12) -> « Continuer » keeps the tracing / the form, « Abandonner » goes. - sections « its panel takes the focus » -> its dialog's [data-creation-focus] takes it. - no-loss « pending creation with its name » (hidden with the body) -> the dialog stays across the crossing, read-only, Créer off (R-14). - point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9. - e2e editor-annotations keyboard test « numeric position » (cx field 250) -> UX_TESTS Keyboard: zone added, vertex added and removed, moved by the move mode, validated, saved. The « Fermer le tracé » step runs under expectNoShift again (shortcut removed). - e2e editor-geometry C26: the proposed x, y read from the notice text -> from the overlay's correction circle; the R-4 text checked in the dialog. - e2e editor-deselect « Escape cancels the tracing only » -> Escape asks, « Abandonner » cancels it, the selection kept. - e2e editor-shell-crossing « keeps its tool and its pending creation » (field hidden) -> the dialog stays read-only, Créer off, then editable on widening.
This commit is contained in:
1 parent
2d58da7d01
commit
4d2c64f57f
50 files changed
+3050
-1181
No files matched your search
@@ -0,0 +1,281 @@
|
||||
import { 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'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import { creationOpener } from '@/editor/annotations/creationAsk'
|
||||
import {
|
||||
confirmAttempt,
|
||||
createAttempt,
|
||||
type Attempt,
|
||||
} from '@/editor/annotations/creationAttempt'
|
||||
import {
|
||||
dropCreation,
|
||||
finishCreation,
|
||||
patchForm,
|
||||
replacePoint,
|
||||
resumeTrace,
|
||||
setCorrection,
|
||||
} from '@/editor/annotations/creationWork'
|
||||
import { answerDrawing, guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import type { MissingField } from '@/editor/annotations/missingFields'
|
||||
import {
|
||||
useAnnotationWork,
|
||||
type Creation,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { visibleElement } from '@/editor/focusRequest'
|
||||
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
|
||||
import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { pluralKey } from '@/editor/plural'
|
||||
import EditorGlyph from '../EditorGlyph'
|
||||
import CorrectionNotice from './CorrectionNotice'
|
||||
import CreationFields from './CreationFields'
|
||||
import MissingSummary, { focusFirstMissing } from './MissingSummary'
|
||||
|
||||
const ID_PREFIX = 'creation-'
|
||||
|
||||
export interface CreationDialogProps {
|
||||
doc: AnatomicalSheetDocument
|
||||
readOnly: boolean
|
||||
/** The column the dialog sits over (A2); null: centred. */
|
||||
anchor: RefObject<HTMLElement | null>
|
||||
}
|
||||
|
||||
/** What « Créer » left on screen: the fields R-3 names, or the core's refusal. */
|
||||
interface Outcome {
|
||||
missing: MissingField[]
|
||||
messages: string[]
|
||||
}
|
||||
const NONE: Outcome = { missing: [], messages: [] }
|
||||
|
||||
/**
|
||||
* « Créer » and « Utiliser cette position »: one `insertAnnotation` under `accept` (one
|
||||
* undo); a point lets the core's verdict offer C (C26); a success ends the creation.
|
||||
*/
|
||||
function useCreate(work: Creation, created: { current: boolean }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const [outcome, setOutcome] = useState<Outcome>(NONE)
|
||||
const settle = (attempt: Attempt) => {
|
||||
if (attempt.status === 'invalid') {
|
||||
setOutcome({ missing: attempt.missing, messages: [] })
|
||||
return focusFirstMissing(ID_PREFIX, attempt.missing)
|
||||
}
|
||||
setOutcome({
|
||||
missing: [],
|
||||
messages: attempt.status === 'refused' ? attempt.messages : [],
|
||||
})
|
||||
if (attempt.status === 'correction') setCorrection(attempt.correction)
|
||||
if (attempt.status !== 'created') return
|
||||
created.current = true
|
||||
if (attempt.id) finishCreation(attempt.id, work.pending.kind)
|
||||
else dropCreation()
|
||||
}
|
||||
const input = { ...work, context: { t, locale } }
|
||||
return {
|
||||
outcome,
|
||||
create: () => settle(createAttempt(input, work.form)),
|
||||
confirm: () => {
|
||||
const { correction } = work.pending
|
||||
if (correction) settle(confirmAttempt(input, work.form, correction))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** « Point placé · Replacer le point », « Zone tracée, 5 sommets · Reprendre le tracé ». */
|
||||
function ShapeLine({ work, readOnly }: { work: Creation; readOnly: boolean }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { kind, geometry } = work.pending
|
||||
const count = geometry.type === 'polygon' ? geometry.points.length : 0
|
||||
const text =
|
||||
kind === 'point'
|
||||
? t('editor.annotations.creation.placed')
|
||||
: t(
|
||||
pluralKey(
|
||||
locale,
|
||||
`editor.annotations.creation.traced.${kind}`,
|
||||
count,
|
||||
),
|
||||
).replace('{count}', String(count))
|
||||
const point = 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"
|
||||
>
|
||||
<EditorGlyph
|
||||
name={point ? 'point' : kind === 'zone' ? 'zone' : 'link'}
|
||||
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"
|
||||
>
|
||||
{t(`editor.annotations.creation.${point ? 'replace' : 'resume'}`)}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Board 02: « Abandonner » asks first (A12), « Créer » inserts; the question in its place. */
|
||||
function CreationActions({
|
||||
readOnly,
|
||||
onDiscard,
|
||||
}: {
|
||||
readOnly: boolean
|
||||
onDiscard: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const asking = useAnnotationWork((s) => s.question?.work === 'creation')
|
||||
if (asking) {
|
||||
return (
|
||||
<DiscardConfirm
|
||||
words={{
|
||||
title: t('editor.annotations.guard.creation'),
|
||||
keep: t('editor.annotations.guard.continue'),
|
||||
discard: t('editor.annotations.guard.discard'),
|
||||
}}
|
||||
onKeepTyping={() => answerDrawing(false)}
|
||||
onDiscard={() => answerDrawing(true)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Button type="button" variant="ghost" onClick={onDiscard}>
|
||||
{t('editor.annotations.creation.discard')}
|
||||
</Button>
|
||||
<Button type="submit" disabled={readOnly}>
|
||||
{t('editor.annotations.create')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The guard is always armed (A12): ✕, Échap and « Abandonner » ask, even with nothing typed. */
|
||||
const askDiscard = () => guardDrawing(() => undefined)
|
||||
|
||||
function CreationBody({
|
||||
work,
|
||||
doc,
|
||||
readOnly,
|
||||
created,
|
||||
}: {
|
||||
work: Creation
|
||||
doc: AnatomicalSheetDocument
|
||||
readOnly: boolean
|
||||
created: { current: boolean }
|
||||
}) {
|
||||
const creating = useCreate(work, created)
|
||||
const { outcome } = creating
|
||||
return (
|
||||
<form
|
||||
data-testid="annotation-creation"
|
||||
className="space-y-3"
|
||||
noValidate
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault()
|
||||
if (!readOnly) creating.create()
|
||||
}}
|
||||
>
|
||||
{readOnly && <ReadOnlyNotice />}
|
||||
<ShapeLine work={work} readOnly={readOnly} />
|
||||
<CreationFields
|
||||
kind={work.pending.kind}
|
||||
viewId={work.viewId}
|
||||
doc={doc}
|
||||
form={work.form}
|
||||
onChange={patchForm}
|
||||
idPrefix={ID_PREFIX}
|
||||
missing={outcome.missing}
|
||||
readOnly={readOnly}
|
||||
/>
|
||||
{work.pending.correction && (
|
||||
<CorrectionNotice
|
||||
onConfirm={() => !readOnly && creating.confirm()}
|
||||
onCancel={() => setCorrection(null)}
|
||||
/>
|
||||
)}
|
||||
<MissingSummary missing={outcome.missing} />
|
||||
{outcome.messages.length > 0 && (
|
||||
<div
|
||||
role="alert"
|
||||
className="space-y-1 text-sm text-[var(--color-danger-strong)]"
|
||||
>
|
||||
{outcome.messages.map((text) => (
|
||||
<p key={text}>{text}</p>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<CreationActions readOnly={readOnly} onDiscard={askDiscard} />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the focus goes once the dialog closes (board 32): nowhere after « Créer » (the new
|
||||
* row takes it), the strip's « Revenir aux propriétés » while the shape is replaced or
|
||||
* retraced, else what started the creation.
|
||||
*/
|
||||
function useCreationReturn(work: Creation | null) {
|
||||
const last = useRef<Creation | null>(null)
|
||||
const created = useRef(false)
|
||||
// A new creation starts with no « Créer » behind it.
|
||||
if (work && last.current === null) created.current = false
|
||||
last.current = work ?? last.current
|
||||
const returnFocus = () => {
|
||||
const ended = last.current
|
||||
if (useAnnotationWork.getState().creation) {
|
||||
return (
|
||||
visibleElement('[data-back-to-properties]') ??
|
||||
visibleElement(CANVAS_BOX)
|
||||
)
|
||||
}
|
||||
last.current = null
|
||||
if (created.current || !ended) return null
|
||||
return creationOpener(ended)
|
||||
}
|
||||
return { created, returnFocus }
|
||||
}
|
||||
|
||||
/**
|
||||
* « 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
|
||||
* flip keeps it with its form and ghost, « Créer » disabled (R-14). The shape and the
|
||||
* form are the work store's: they outlive « Replacer le point » and « Reprendre le tracé ».
|
||||
*/
|
||||
export default function CreationDialog(props: CreationDialogProps) {
|
||||
const t = useT()
|
||||
const visible = usePlaceVisible()
|
||||
const work = useAnnotationWork((s) => s.creation)
|
||||
const back = useCreationReturn(work)
|
||||
const shown = visible && work !== null && work.dialog
|
||||
const title = work ? t(`editor.annotations.new.${work.pending.kind}`) : ''
|
||||
return (
|
||||
<Dialog
|
||||
open={shown}
|
||||
anchor={props.anchor}
|
||||
veilCloses={false}
|
||||
title={title}
|
||||
returnFocus={back.returnFocus}
|
||||
onClose={() => (askDiscard() ? undefined : 'kept')}
|
||||
>
|
||||
{work && (
|
||||
<CreationBody
|
||||
work={work}
|
||||
doc={props.doc}
|
||||
readOnly={props.readOnly}
|
||||
created={back.created}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user