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
@@ -7,7 +7,10 @@ import {
|
||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||
import { commitFocusedField } from '@/editor/focusRequest'
|
||||
import { canRedo, canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||
import { cancelPending } from '@/editor/annotations/workStore'
|
||||
import {
|
||||
cancelPending,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import EditorGlyph from './EditorGlyph'
|
||||
|
||||
@@ -67,6 +70,8 @@ function usePress(
|
||||
left.current = asField(event.relatedTarget) ?? left.current
|
||||
}
|
||||
const onClick = () => {
|
||||
// A12: undo and redo are inactive during a creation (R-13).
|
||||
if (useAnnotationWork.getState().creation) return
|
||||
const field = left.current
|
||||
forget()
|
||||
if (field?.isConnected && field.getAttribute('aria-invalid') === 'true') {
|
||||
@@ -101,6 +106,7 @@ function HistoryButton({
|
||||
const t = useT()
|
||||
const readOnly = useEditorReadOnly()
|
||||
const steppable = useEditorStore(direction === 'undo' ? canUndo : canRedo)
|
||||
const creating = useAnnotationWork((s) => s.creation !== null)
|
||||
const name = t(`editor.history.${direction}_title`)
|
||||
const press = usePress(direction, readOnly, left)
|
||||
return (
|
||||
@@ -108,7 +114,7 @@ function HistoryButton({
|
||||
type="button"
|
||||
aria-label={name}
|
||||
title={`${name} (${t(`editor.history.${direction}_shortcut`)})`}
|
||||
aria-disabled={readOnly || !steppable}
|
||||
aria-disabled={readOnly || !steppable || creating}
|
||||
aria-keyshortcuts={SHORTCUT[direction]}
|
||||
{...press}
|
||||
className={BUTTON}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { useEffect, useRef, type KeyboardEvent, type RefObject } from 'react'
|
||||
import {
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type KeyboardEvent,
|
||||
type PointerEvent,
|
||||
type RefObject,
|
||||
} from 'react'
|
||||
import type { Geometry } from '@faunosteo/core-wasm/types'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
@@ -6,6 +13,7 @@ import { coreFailureMessage } from '@/core/failure'
|
||||
import { useCoreStopped } from '@/core/runtime'
|
||||
import { transformOf } from '@/catalogue/framing'
|
||||
import type { XY } from '@/editor/annotations/frame'
|
||||
import { clientToDrawing } from '@/editor/annotations/gesture'
|
||||
import {
|
||||
useCanvasBuild,
|
||||
type RootAttributes,
|
||||
@@ -23,7 +31,7 @@ import ToolColumn, { type ToolColumnProps } from './ToolColumn'
|
||||
|
||||
type OverlayData = Omit<
|
||||
OverlayProps,
|
||||
'svgRef' | 'viewBox' | 'ratio' | 'dragged'
|
||||
'svgRef' | 'viewBox' | 'ratio' | 'dragged' | 'hover'
|
||||
>
|
||||
|
||||
/** The handle layer's content: the handle and its keys (the layer measures itself). */
|
||||
@@ -37,6 +45,10 @@ export interface AnnotationCanvasProps {
|
||||
viewName: string
|
||||
tool: ToolId
|
||||
selectedId: string | null
|
||||
/** The point tool's next size (A5), shown under a mouse pointer; null: no preview. */
|
||||
previewRadius: number | null
|
||||
/** A creation is in progress: the other markers are dimmed and unselectable (A12). */
|
||||
creating: boolean
|
||||
/** The selected annotation when it can be moved now. */
|
||||
moveTarget: MoveTarget | null
|
||||
overlay: OverlayData
|
||||
@@ -71,6 +83,7 @@ export default function AnnotationCanvas(props: AnnotationCanvasProps) {
|
||||
overlay,
|
||||
viewport,
|
||||
})
|
||||
const preview = usePointPreview(props.previewRadius, overlay)
|
||||
useSelectionMark(build.host, props.selectedId, build.root)
|
||||
useReportRoot(build.root, props.onRoot)
|
||||
return (
|
||||
@@ -85,13 +98,14 @@ export default function AnnotationCanvas(props: AnnotationCanvasProps) {
|
||||
{...props}
|
||||
build={build}
|
||||
viewport={viewport}
|
||||
boxProps={gestures.boxProps}
|
||||
boxProps={withPreview(gestures.boxProps, preview)}
|
||||
layer={{
|
||||
transform: transformOf(gestures.framing.framing),
|
||||
overlay: {
|
||||
...props.overlay,
|
||||
svgRef: overlay,
|
||||
dragged: gestures.drag,
|
||||
hover: preview.hover,
|
||||
},
|
||||
handles: {
|
||||
...props.handles,
|
||||
@@ -105,11 +119,47 @@ export default function AnnotationCanvas(props: AnnotationCanvasProps) {
|
||||
}
|
||||
|
||||
type Build = ReturnType<typeof useCanvasBuild>
|
||||
type BoxProps = ReturnType<typeof useCanvasGestures>['boxProps']
|
||||
type Preview = ReturnType<typeof usePointPreview>
|
||||
|
||||
/**
|
||||
* Board 02 A: with the point tool, the next point follows a mouse pointer over the drawing
|
||||
* at the strip's size. Touch and pen have no hover: nothing is shown for them.
|
||||
*/
|
||||
function usePointPreview(
|
||||
radius: number | null,
|
||||
overlay: RefObject<SVGSVGElement | null>,
|
||||
) {
|
||||
const [at, setAt] = useState<XY | null>(null)
|
||||
const onMove = (event: PointerEvent) => {
|
||||
if (radius === null || event.pointerType !== 'mouse') {
|
||||
if (at !== null) setAt(null)
|
||||
return
|
||||
}
|
||||
const client = { x: event.clientX, y: event.clientY }
|
||||
setAt(clientToDrawing(overlay.current, client))
|
||||
}
|
||||
const hover = radius !== null && at ? { ...at, r: radius } : null
|
||||
return { hover, onMove, onLeave: () => setAt(null) }
|
||||
}
|
||||
|
||||
/** The box's own pointer handlers, then the preview's. */
|
||||
function withPreview(box: BoxProps, preview: Preview) {
|
||||
return {
|
||||
...box,
|
||||
onPointerMove: (event: PointerEvent) => {
|
||||
box.onPointerMove(event)
|
||||
preview.onMove(event)
|
||||
},
|
||||
onPointerLeave: preview.onLeave,
|
||||
}
|
||||
}
|
||||
|
||||
function CanvasBox({
|
||||
viewId,
|
||||
viewName,
|
||||
tool,
|
||||
creating,
|
||||
build,
|
||||
viewport,
|
||||
boxProps,
|
||||
@@ -117,7 +167,7 @@ function CanvasBox({
|
||||
}: AnnotationCanvasProps & {
|
||||
build: Build
|
||||
viewport: RefObject<HTMLDivElement | null>
|
||||
boxProps: ReturnType<typeof useCanvasGestures>['boxProps']
|
||||
boxProps: BoxProps
|
||||
layer: Omit<LayerProps, 'host' | 'root'>
|
||||
}) {
|
||||
const root = build.root?.viewId === viewId ? build.root : null
|
||||
@@ -130,6 +180,7 @@ function CanvasBox({
|
||||
role="group"
|
||||
aria-label={viewName}
|
||||
data-testid="annotation-canvas"
|
||||
data-creating={creating ? '' : undefined}
|
||||
className={`svg-canvas aspect-[4/3] w-full select-none ${cursor} ${FOCUS_RING}`}
|
||||
{...boxProps}
|
||||
>
|
||||
|
||||
@@ -18,29 +18,14 @@ import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import type { Guards } from '@/editor/useEditorNavigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import CreationFields from './CreationFields'
|
||||
import MissingSummary, { focusFirstMissing } from './MissingSummary'
|
||||
|
||||
/** What the form edits: the creation's fields plus « Couleur » (A9), as plain strings. */
|
||||
type Draft = CreationForm & { color: string }
|
||||
|
||||
/** The edit form's ids: never the creation panel's, kept mounted in the hidden edit body. */
|
||||
/** The edit form's ids: never the creation dialog's (`creation-`). */
|
||||
const ID_PREFIX = 'annotation-edit-'
|
||||
|
||||
const FIELD_ID: Record<MissingField, string> = {
|
||||
name_fr: 'fr',
|
||||
name_en: 'en',
|
||||
category: 'category',
|
||||
laterality: 'laterality',
|
||||
opens: 'opens',
|
||||
}
|
||||
|
||||
const FIELD_LABEL: Record<MissingField, string> = {
|
||||
name_fr: 'editor.annotations.name_fr',
|
||||
name_en: 'editor.annotations.name_en',
|
||||
category: 'editor.annotations.category',
|
||||
laterality: 'editor.annotations.laterality',
|
||||
opens: 'editor.annotations.opens',
|
||||
}
|
||||
|
||||
function draftOf(annotation: Annotation): Draft {
|
||||
const link = annotation.kind === 'detail_trigger'
|
||||
return {
|
||||
@@ -158,7 +143,7 @@ function useSave(props: AnnotationEditFormProps, form: FormDraft) {
|
||||
const absent = missingFields(props.annotation.kind, form.draft)
|
||||
setMissing(absent)
|
||||
if (absent.length > 0) {
|
||||
document.getElementById(`${ID_PREFIX}${FIELD_ID[absent[0]!]}`)?.focus()
|
||||
focusFirstMissing(ID_PREFIX, absent)
|
||||
return
|
||||
}
|
||||
if (!form.dirty) return props.onDone(false)
|
||||
@@ -174,21 +159,6 @@ function useSave(props: AnnotationEditFormProps, form: FormDraft) {
|
||||
|
||||
type FormDraft = ReturnType<typeof useFormDraft<Draft>>
|
||||
|
||||
/** « À compléter : Latéralité. »: the missing fields by their labels, in form order. */
|
||||
function MissingSummary({ missing }: { missing: readonly MissingField[] }) {
|
||||
const t = useT()
|
||||
if (missing.length === 0) return null
|
||||
const fields = missing.map((field) => t(FIELD_LABEL[field])).join(', ')
|
||||
return (
|
||||
<p role="alert" className="text-sm text-[var(--color-danger-strong)]">
|
||||
{t('editor.annotations.missing.summary').replace(
|
||||
'{fields}',
|
||||
() => fields,
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* « Modifier » (board 31 C): the creation's fields with « Couleur » on a local draft, one
|
||||
* `update` on « Enregistrer » (none when unchanged), nothing on « Annuler » or a close.
|
||||
|
||||
@@ -16,7 +16,11 @@ export interface OverlayProps {
|
||||
dragged: Geometry | null
|
||||
/** The place the core just refused (red dashes while its message shows). */
|
||||
refused: Geometry | null
|
||||
/** The new shape waiting for its properties (the ghost), in its category's colour (A4). */
|
||||
pending: Geometry | null
|
||||
pendingColour: string
|
||||
/** The point tool's preview under a mouse pointer (none on touch). */
|
||||
hover: { x: number; y: number; r: number } | null
|
||||
tracing: Point[] | null
|
||||
correction: Correction | null
|
||||
/** A redraw runs: the stored outline stays as the old place until the close (06 C). */
|
||||
@@ -94,6 +98,74 @@ function HollowCross({
|
||||
)
|
||||
}
|
||||
|
||||
/** The shape `geometry` with its own style: a ghost's fill and halo, the preview's dashes. */
|
||||
function Shape({
|
||||
geometry,
|
||||
style,
|
||||
}: {
|
||||
geometry: Geometry
|
||||
style: Record<string, string | number | undefined>
|
||||
}) {
|
||||
if (geometry.type === 'circle') {
|
||||
return (
|
||||
<circle cx={geometry.cx} cy={geometry.cy} r={geometry.r} {...style} />
|
||||
)
|
||||
}
|
||||
if (geometry.type === 'polygon') {
|
||||
return <polygon points={geometry.points.join(' ')} {...style} />
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* The new shape before « Créer »: its category's colour, a white halo, accent dashes over
|
||||
* it (docs/ANNOTATION-RENDERING.md « Editor overlay »).
|
||||
*/
|
||||
function Ghost({ geometry, colour }: { geometry: Geometry; colour: string }) {
|
||||
const line = { vectorEffect: 'non-scaling-stroke', fill: 'none' }
|
||||
return (
|
||||
<g data-testid="overlay-ghost" data-colour={colour}>
|
||||
<Shape
|
||||
geometry={geometry}
|
||||
style={{ fill: colour, fillOpacity: 0.45, stroke: 'none' }}
|
||||
/>
|
||||
<Shape
|
||||
geometry={geometry}
|
||||
style={{ ...line, stroke: 'white', strokeWidth: 6 }}
|
||||
/>
|
||||
<Shape
|
||||
geometry={geometry}
|
||||
style={{
|
||||
...line,
|
||||
stroke: 'var(--color-accent)',
|
||||
strokeWidth: 2,
|
||||
strokeDasharray: '6 4',
|
||||
}}
|
||||
/>
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
/** Board 02 A: the next point's size, dashed, with a cross at the pointer. */
|
||||
function HoverPreview({
|
||||
hover,
|
||||
}: {
|
||||
hover: { x: number; y: number; r: number }
|
||||
}) {
|
||||
const { x, y, r } = hover
|
||||
const arm = r / 4
|
||||
const style = { ...STROKE, stroke: 'var(--color-accent)', strokeWidth: 1.5 }
|
||||
return (
|
||||
<g data-testid="overlay-point-preview">
|
||||
<circle cx={x} cy={y} r={r} {...style} strokeDasharray="6 4" />
|
||||
<path
|
||||
d={`M ${x - arm} ${y} H ${x + arm} M ${x} ${y - arm} V ${y + arm}`}
|
||||
{...style}
|
||||
/>
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
function TracingPath({ points, size }: { points: Point[]; size: number }) {
|
||||
if (points.length === 0) return null
|
||||
const shape: Geometry = { type: 'polygon', points }
|
||||
@@ -163,24 +235,19 @@ export default function AnnotationOverlay(props: OverlayProps) {
|
||||
<Vertices geometry={shown} size={size} />
|
||||
</g>
|
||||
)}
|
||||
{pending && (
|
||||
<Outline
|
||||
geometry={pending}
|
||||
dashed={false}
|
||||
colour="var(--color-accent)"
|
||||
/>
|
||||
)}
|
||||
{pending && <Ghost geometry={pending} colour={props.pendingColour} />}
|
||||
{correction && (
|
||||
<>
|
||||
<g data-testid="overlay-correction">
|
||||
<Outline
|
||||
geometry={{ type: 'circle', ...correction.circle }}
|
||||
dashed
|
||||
colour="var(--color-accent)"
|
||||
/>
|
||||
<HollowCross at={correction.click} size={size * 1.5} />
|
||||
</>
|
||||
</g>
|
||||
)}
|
||||
{tracing && <TracingPath points={tracing} size={size} />}
|
||||
{props.hover && <HoverPreview hover={props.hover} />}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -1,26 +1,21 @@
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import type { Correction } from '@/editor/annotations/correction'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/**
|
||||
* The corrected position is never taken silently: the page says where the point would
|
||||
* sit, the overlay shows it with the click marked apart, and only « Utiliser cette
|
||||
* position » inserts it.
|
||||
* The corrected position is never taken silently: the notice says a corrected position
|
||||
* is proposed (no numbers, A8, R-4), the overlay shows it with the click marked apart,
|
||||
* and only « Utiliser cette position » inserts it.
|
||||
*/
|
||||
export default function CorrectionNotice({
|
||||
correction,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
}: {
|
||||
correction: Correction
|
||||
onConfirm: () => void
|
||||
onCancel: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const message = t('editor.annotations.correction')
|
||||
.replace('{x}', String(correction.circle.cx))
|
||||
.replace('{y}', String(correction.circle.cy))
|
||||
return (
|
||||
<Notice tone="info">
|
||||
<div className="space-y-2" data-testid="correction-notice">
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import Button from '@/components/ui/Button'
|
||||
import { askCreation } from '@/editor/annotations/creationAsk'
|
||||
import { backToProperties, popVertex } from '@/editor/annotations/creationWork'
|
||||
import type { Creation } from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import EditorGlyph from '../EditorGlyph'
|
||||
|
||||
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
||||
|
||||
/** The vertices a resumed tracing holds now; null for a point. */
|
||||
const tracedCount = (work: Creation) =>
|
||||
!work.closed && work.pending.geometry.type === 'polygon'
|
||||
? work.pending.geometry.points.length
|
||||
: null
|
||||
|
||||
/**
|
||||
* Board 04 C: the dialog hidden by « Replacer le point » or « Reprendre le tracé ». « Revenir
|
||||
* aux propriétés » shows it again (a tracing closes first, three vertices at least);
|
||||
* « Abandonner » asks first, the shape always exists (A12).
|
||||
*/
|
||||
export default function CreationCommands({ creation }: { creation: Creation }) {
|
||||
const t = useT()
|
||||
const count = tracedCount(creation)
|
||||
return (
|
||||
<div
|
||||
tabIndex={-1}
|
||||
data-testid="creation-commands"
|
||||
data-creation-focus=""
|
||||
className="flex items-center gap-2 outline-none"
|
||||
>
|
||||
<Button
|
||||
data-back-to-properties=""
|
||||
type="button"
|
||||
size="sm"
|
||||
className={COMMAND}
|
||||
disabled={count !== null && count < 3}
|
||||
onClick={() => backToProperties()}
|
||||
>
|
||||
<EditorGlyph name="properties" size={16} />
|
||||
{t('editor.annotations.back_to_properties')}
|
||||
</Button>
|
||||
{count !== null && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className={COMMAND}
|
||||
disabled={count === 0}
|
||||
onClick={popVertex}
|
||||
>
|
||||
{t('editor.annotations.trace_pop')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className={COMMAND}
|
||||
onClick={askCreation}
|
||||
>
|
||||
{t('editor.annotations.creation.discard')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
import { useState, type Dispatch } from 'react'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import Button from '@/components/ui/Button'
|
||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||
import {
|
||||
emptyForm,
|
||||
withGeometry,
|
||||
type CreationForm,
|
||||
type PendingElement,
|
||||
} from '@/editor/annotations/creation'
|
||||
import {
|
||||
confirmAttempt,
|
||||
createAttempt,
|
||||
type Attempt,
|
||||
type CreationInput,
|
||||
} from '@/editor/annotations/creationAttempt'
|
||||
import type { Frame } from '@/editor/annotations/frame'
|
||||
import type { UiAction } from '@/editor/annotations/uiState'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import CorrectionNotice from './CorrectionNotice'
|
||||
import CreationFields from './CreationFields'
|
||||
import GeometryGroup from './GeometryGroup'
|
||||
|
||||
export interface CreationPanelProps {
|
||||
pending: PendingElement
|
||||
viewId: string
|
||||
doc: AnatomicalSheetDocument
|
||||
/** F of the current view; null while it is not measured. */
|
||||
frame: Frame | null
|
||||
dispatch: Dispatch<UiAction>
|
||||
context: CommitContext
|
||||
}
|
||||
|
||||
/** What an attempt leaves on screen: the core's words, or the form's own. */
|
||||
function messagesOf(attempt: Attempt, words: (problem: string) => string) {
|
||||
if (attempt.status === 'refused') return attempt.messages
|
||||
return attempt.status === 'invalid' ? [words(attempt.problem)] : []
|
||||
}
|
||||
|
||||
/**
|
||||
* The typed fields and the outcome of « Créer » / « Utiliser cette position ». The form
|
||||
* survives a change of the pending geometry (a second click): the panel is not remounted.
|
||||
*/
|
||||
function useCreation(props: CreationPanelProps) {
|
||||
const t = useT()
|
||||
const [form, setForm] = useState<CreationForm>(() => emptyForm(props.doc))
|
||||
const [messages, setMessages] = useState<string[]>([])
|
||||
const settle = (attempt: Attempt) => {
|
||||
const { dispatch, pending } = props
|
||||
// shortcut: the general lines `editor.annotations.required.{fields,names}` (R-3 removes
|
||||
// them) stay until Task 7. Upgrade: the creation dialog names each field through
|
||||
// `missingFields` and the `editor.annotations.missing.*` keys, as the edit form does.
|
||||
setMessages(
|
||||
messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)),
|
||||
)
|
||||
if (attempt.status === 'created') {
|
||||
dispatch({ type: 'select', id: attempt.id ?? null })
|
||||
}
|
||||
if (attempt.status === 'correction') {
|
||||
const next = { ...pending, correction: attempt.correction }
|
||||
dispatch({ type: 'pending_update', pending: next })
|
||||
}
|
||||
}
|
||||
const input: CreationInput = props
|
||||
return {
|
||||
form,
|
||||
messages,
|
||||
patch: (change: Partial<CreationForm>) => setForm({ ...form, ...change }),
|
||||
create: () => settle(createAttempt(input, form)),
|
||||
confirm: () => {
|
||||
const { correction } = props.pending
|
||||
if (correction) settle(confirmAttempt(input, form, correction))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* « Nouveau point / Nouvelle zone / Nouvel accès »: the fields the core requires are
|
||||
* collected first, then « Créer » inserts once through `accept` (no default labels).
|
||||
* The geometry stays here, outside the document, until then.
|
||||
*/
|
||||
export default function CreationPanel(props: CreationPanelProps) {
|
||||
const t = useT()
|
||||
const creation = useCreation(props)
|
||||
const { pending, dispatch } = props
|
||||
const title = t(`editor.annotations.new.${pending.kind}`)
|
||||
return (
|
||||
<section
|
||||
aria-label={title}
|
||||
data-testid="annotation-creation"
|
||||
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
||||
>
|
||||
<h3
|
||||
tabIndex={-1}
|
||||
data-creation-heading
|
||||
className="outline-none text-base font-semibold"
|
||||
>
|
||||
{title}
|
||||
</h3>
|
||||
<CreationFields
|
||||
kind={pending.kind}
|
||||
viewId={props.viewId}
|
||||
form={creation.form}
|
||||
doc={props.doc}
|
||||
onChange={creation.patch}
|
||||
/>
|
||||
<GeometryGroup
|
||||
idPrefix="creation"
|
||||
geometry={pending.geometry}
|
||||
locked={false}
|
||||
onApply={(geometry) => {
|
||||
const next = withGeometry(pending, geometry)
|
||||
dispatch({ type: 'pending_update', pending: next })
|
||||
return { ok: true }
|
||||
}}
|
||||
/>
|
||||
{pending.correction && (
|
||||
<CorrectionNotice
|
||||
correction={pending.correction}
|
||||
onConfirm={creation.confirm}
|
||||
onCancel={() =>
|
||||
dispatch({
|
||||
type: 'pending_update',
|
||||
pending: { ...pending, correction: null },
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<Messages messages={creation.messages} />
|
||||
<CreationActions
|
||||
onCreate={creation.create}
|
||||
onCancel={() => dispatch({ type: 'pending_drop' })}
|
||||
/>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function CreationActions({
|
||||
onCreate,
|
||||
onCancel,
|
||||
}: {
|
||||
onCreate: () => void
|
||||
onCancel: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" onClick={onCreate}>
|
||||
{t('editor.annotations.create')}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" onClick={onCancel}>
|
||||
{t('editor.annotations.create_cancel')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Messages({ messages }: { messages: string[] }) {
|
||||
if (messages.length === 0) return null
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
className="space-y-1 text-sm text-[var(--color-danger-strong)]"
|
||||
>
|
||||
{messages.map((message) => (
|
||||
<p key={message}>{message}</p>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,11 +7,14 @@ import ConfirmDialog from '../ConfirmDialog'
|
||||
/**
|
||||
* The drawing guard's question (R-12), mounted with the workspace so it shows whatever
|
||||
* tab is in view: « Continuer » keeps the work, « Abandonner » drops it and makes the move
|
||||
* that was held.
|
||||
* that was held. The creation dialog, when shown, asks it in its own footer instead.
|
||||
*/
|
||||
export default function DrawingGuardDialog() {
|
||||
const t = useT()
|
||||
const question = useAnnotationWork((s) => s.question)
|
||||
// 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,
|
||||
)
|
||||
// The title stays while the dialog closes.
|
||||
const title = useRef('')
|
||||
if (question) title.current = t(`editor.annotations.guard.${question.work}`)
|
||||
|
||||
@@ -7,6 +7,15 @@ import type {
|
||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
||||
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
||||
import {
|
||||
creationTracing,
|
||||
placePending,
|
||||
} from '@/editor/annotations/creationWork'
|
||||
import { useCreationFollow } from '@/editor/annotations/useCreationFollow'
|
||||
import {
|
||||
useAnnotationWork,
|
||||
type Creation,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
||||
import { newPointSize } from '@/editor/annotations/pointSize'
|
||||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
@@ -24,12 +33,13 @@ import {
|
||||
useLayerFollow,
|
||||
type OpenDialog,
|
||||
} from '@/editor/annotations/dialogOpening'
|
||||
import { usePlacement } from '@/editor/annotations/usePlacement'
|
||||
import { creationStart, usePlacement } from '@/editor/annotations/usePlacement'
|
||||
import { useGestureMessage } from '@/editor/annotations/useGestureMessage'
|
||||
import {
|
||||
initialUi,
|
||||
uiReducer,
|
||||
type ToolId,
|
||||
type Tracing,
|
||||
type UiAction,
|
||||
type UiState,
|
||||
} from '@/editor/annotations/uiState'
|
||||
@@ -46,7 +56,6 @@ import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import AnnotationCanvas from './AnnotationCanvas'
|
||||
import { annotationName } from './AnnotationList'
|
||||
import CreationPanel from './CreationPanel'
|
||||
import GestureMessage from './GestureMessage'
|
||||
import KeyboardAdd from './KeyboardAdd'
|
||||
import OverviewPanel from './OverviewPanel'
|
||||
@@ -73,6 +82,10 @@ export interface Scene {
|
||||
/** F of the current view, only while the core measures it and the build is its own. */
|
||||
frame: Frame | null
|
||||
selected: Annotation | undefined
|
||||
/** The creation in progress on this view (A12), the work store's. */
|
||||
creation: Creation | null
|
||||
/** The tracing shown: a redraw's, or the open tracing of a new zone or link. */
|
||||
tracing: Tracing | null
|
||||
setRoot: (root: RootAttributes | null) => void
|
||||
navigate: EditorPlaceProps['navigate']
|
||||
onOpenSection: Props['onOpenSection']
|
||||
@@ -81,9 +94,9 @@ export interface Scene {
|
||||
|
||||
/**
|
||||
* The shown view no longer exists (an undo, a deletion in the views section): the full
|
||||
* reset to the main view drops the pending creation, the tracing and the selection, so
|
||||
* nothing pending is inserted on another view. It fires only for a view absent from the
|
||||
* document, since `view` always returns a new state.
|
||||
* reset to the main view drops the tracing and the selection (a creation on that view is
|
||||
* dropped by `useCreationFollow`), so nothing pending is inserted on another view. It
|
||||
* fires only for a view absent from the document, since `view` always returns a new state.
|
||||
*/
|
||||
function useViewFallback(
|
||||
doc: AnatomicalSheetDocument,
|
||||
@@ -100,11 +113,16 @@ function useViewFallback(
|
||||
}
|
||||
|
||||
/** « Aller à » an annotation: the request, with what it needs of the drawing's state. */
|
||||
/** A fresh tracing reads as a tracing; a placed, closed or resumed shape as a creation. */
|
||||
function busyOf(creation: Creation | null, ui: UiState) {
|
||||
if (creation)
|
||||
return creation.closed || creation.resumed ? 'creation' : 'tracing'
|
||||
return ui.tracing ? 'tracing' : null
|
||||
}
|
||||
|
||||
function useSceneRequest(
|
||||
{ doc, focus, layerId }: Props,
|
||||
ui: UiState,
|
||||
viewId: string,
|
||||
dispatch: Dispatch<UiAction>,
|
||||
{ ui, viewId, dispatch, creation }: SceneCore,
|
||||
) {
|
||||
useViewFallback(doc, ui.viewId, dispatch)
|
||||
const show = (view: string, id: string) => {
|
||||
@@ -114,7 +132,7 @@ function useSceneRequest(
|
||||
useAnnotationRequest(focus, doc, {
|
||||
viewId,
|
||||
selectedId: ui.selectedId,
|
||||
busy: ui.pending ? 'creation' : ui.tracing ? 'tracing' : null,
|
||||
busy: busyOf(creation, ui),
|
||||
show,
|
||||
})
|
||||
useLayerFollow(layerId, doc, {
|
||||
@@ -125,6 +143,13 @@ function useSceneRequest(
|
||||
})
|
||||
}
|
||||
|
||||
interface SceneCore {
|
||||
ui: UiState
|
||||
viewId: string
|
||||
dispatch: Dispatch<UiAction>
|
||||
creation: Creation | null
|
||||
}
|
||||
|
||||
function useScene(props: Props): Scene {
|
||||
const { doc, navigate, onOpenSection, onOpen } = props
|
||||
const [ui, dispatch] = useReducer(uiReducer, initialUi)
|
||||
@@ -132,13 +157,17 @@ function useScene(props: Props): Scene {
|
||||
const viewId = ui.viewId ?? mainViewId(doc)
|
||||
const model = useViewModel(doc, viewId)
|
||||
const own = model.measured && root?.viewId === viewId
|
||||
useSceneRequest(props, ui, viewId, dispatch)
|
||||
const work = useAnnotationWork((s) => s.creation)
|
||||
const creation = work?.viewId === viewId ? work : null
|
||||
useSceneRequest(props, { ui, viewId, dispatch, creation })
|
||||
return {
|
||||
doc,
|
||||
ui,
|
||||
dispatch,
|
||||
viewId,
|
||||
model,
|
||||
creation,
|
||||
tracing: ui.tracing ?? creationTracing(creation, viewId),
|
||||
frame: own ? parseFrame(root.viewBox) : null,
|
||||
selected: model.annotations.find((a) => a.id === ui.selectedId),
|
||||
setRoot,
|
||||
@@ -163,6 +192,7 @@ function useWork(scene: Scene) {
|
||||
const context = useCommitContext()
|
||||
const message = useGestureMessage()
|
||||
const placement = usePlacement({ ...scene, context, message })
|
||||
useCreationFollow({ ...scene, message, t: context.t })
|
||||
const target = movableOf(scene.selected, scene.model, scene.ui.tool)
|
||||
const onDrop = placement.onDrop
|
||||
const edit = usePointEdit({ target, frame: scene.frame, onDrop })
|
||||
@@ -198,11 +228,11 @@ export default function EditableAnnotations(props: Props) {
|
||||
const { asideRef, byDrawing } = useSelectionEscape(
|
||||
selected?.id ?? null,
|
||||
() => scene.dispatch({ type: 'select', id: null }),
|
||||
// A redraw's Escape cancels it at once (R-12); a new tracing keeps its own keys.
|
||||
// A redraw's Escape cancels it at once (R-12); a creation asks (board 32 row 3).
|
||||
visible &&
|
||||
selected !== undefined &&
|
||||
(selected !== undefined || scene.creation !== null) &&
|
||||
(ui.tracing === null || ui.tracing.target === 'replace'),
|
||||
{ editable: true, creating: ui.pending !== null },
|
||||
{ editable: true, creating: scene.creation !== null },
|
||||
)
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
@@ -210,7 +240,7 @@ export default function EditableAnnotations(props: Props) {
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<CanvasColumn scene={scene} work={work} onDeselect={byDrawing} />
|
||||
<aside ref={asideRef} data-annotation-aside="edit">
|
||||
<SidePanel scene={scene} context={work.context} />
|
||||
<SidePanel scene={scene} />
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
@@ -283,8 +313,10 @@ function CanvasStage({
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
// Hidden (the editor is read-only): no drag in flight survives, none is committed.
|
||||
const shown = usePlaceVisible()
|
||||
const { doc, ui, dispatch, model, frame, selected } = scene
|
||||
const { doc, ui, dispatch, model, selected, creation } = scene
|
||||
const handle = useHandle(shown ? work.target : null, doc)
|
||||
// A12: during a creation nothing else is selected or opened from the drawing.
|
||||
const free = creation === null
|
||||
const points = shown ? handledPoints(work.target?.geometry ?? null) : null
|
||||
const zone = points && { annotationId: work.target!.id, points }
|
||||
const view = doc.views.find((v) => v.id === scene.viewId)
|
||||
@@ -296,8 +328,10 @@ function CanvasStage({
|
||||
viewName={view.name[locale]}
|
||||
tool={ui.tool}
|
||||
selectedId={ui.selectedId}
|
||||
previewRadius={previewRadiusOf(scene)}
|
||||
creating={!free}
|
||||
moveTarget={shown ? moveTargetOf(selected, model, ui.tool) : null}
|
||||
overlay={overlayOf(ui, selected, frame, work.message.message?.place)}
|
||||
overlay={overlayOf(scene, work.message.message?.place)}
|
||||
handles={{
|
||||
handle,
|
||||
onKeyDown: work.edit.onHandleKey,
|
||||
@@ -313,48 +347,35 @@ function CanvasStage({
|
||||
linkDisabled: model.children.length === 0,
|
||||
}}
|
||||
onRoot={scene.setRoot}
|
||||
onSelect={(id) => dispatch({ type: 'select', id })}
|
||||
onOpen={(id) => scene.onOpen(id, 'drawing')}
|
||||
onSelect={(id) => free && dispatch({ type: 'select', id })}
|
||||
onOpen={(id) => free && scene.onOpen(id, 'drawing')}
|
||||
onPlace={work.placement.onPlace}
|
||||
onDrop={work.placement.onDrop}
|
||||
onHandle={work.zone.onHandle}
|
||||
onDeselect={onDeselect}
|
||||
onDeselect={() => free && onDeselect()}
|
||||
onTraceKey={work.placement.onTraceKey}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function addAtCentre(
|
||||
kind: NewKind,
|
||||
{ frame, doc, viewId, ui, dispatch }: Scene,
|
||||
) {
|
||||
/** « Ajouter … » (keyboard): the shape at the centre at the A5 size, then its dialog. */
|
||||
function addAtCentre(kind: NewKind, scene: Scene) {
|
||||
const { frame, doc, viewId, ui } = scene
|
||||
if (!frame) return
|
||||
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
||||
dispatch({ type: 'pending_new', pending: keyboardPending(kind, frame, size) })
|
||||
const start = creationStart(scene, 'keyboard')
|
||||
placePending(start, keyboardPending(kind, frame, size))
|
||||
}
|
||||
|
||||
/** The creation panel while an element is pending, else the overview (A3). */
|
||||
function SidePanel({
|
||||
scene,
|
||||
context,
|
||||
}: {
|
||||
scene: Scene
|
||||
context: CommitContext
|
||||
}) {
|
||||
const { doc, ui, dispatch, frame } = scene
|
||||
if (ui.pending) {
|
||||
return (
|
||||
<CreationPanel
|
||||
key={ui.serial}
|
||||
pending={ui.pending}
|
||||
viewId={scene.viewId}
|
||||
doc={doc}
|
||||
frame={frame}
|
||||
dispatch={dispatch}
|
||||
context={context}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/** Board 02 A: the next point's size under a mouse pointer, while the point tool places. */
|
||||
function previewRadiusOf({ ui, frame, doc, viewId, creation }: Scene) {
|
||||
if (ui.tool !== 'point' || !frame || creation?.dialog) return null
|
||||
return newPointSize(doc.annotations, viewId, frame, ui.size)
|
||||
}
|
||||
|
||||
/** The overview, during a selection (A3) and a creation alike: the right column never swaps. */
|
||||
function SidePanel({ scene }: { scene: Scene }) {
|
||||
const { doc, ui, dispatch } = scene
|
||||
return (
|
||||
<OverviewPanel
|
||||
doc={doc}
|
||||
@@ -397,20 +418,27 @@ function movableOf(
|
||||
return moveTargetOf(selected, model, tool) !== null ? selected! : null
|
||||
}
|
||||
|
||||
/** The ghost's fill: the category the form holds (A4), else the accent. */
|
||||
function ghostColour(doc: AnatomicalSheetDocument, creation: Creation | null) {
|
||||
const id = creation?.form.categoryId
|
||||
const category = doc.categories.find((c) => c.id === id)
|
||||
return category?.color ?? 'var(--color-accent)'
|
||||
}
|
||||
|
||||
function overlayOf(
|
||||
ui: UiState,
|
||||
selected: Annotation | undefined,
|
||||
frame: Frame | null,
|
||||
{ ui, selected, frame, creation, tracing, doc }: Scene,
|
||||
refused: Geometry | null | undefined,
|
||||
) {
|
||||
const placed = creation?.closed ? creation.pending : null
|
||||
return {
|
||||
frame,
|
||||
selectedId: selected?.id ?? null,
|
||||
refused: refused ?? null,
|
||||
selected: selected?.geometry ?? null,
|
||||
pending: ui.pending?.geometry ?? null,
|
||||
tracing: ui.tracing?.points ?? null,
|
||||
correction: ui.pending?.correction ?? null,
|
||||
pending: placed?.geometry ?? null,
|
||||
pendingColour: ghostColour(doc, creation),
|
||||
tracing: tracing?.points ?? null,
|
||||
correction: placed?.correction ?? null,
|
||||
redrawing: ui.tracing?.target === 'replace',
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ import type { ReactNode } from 'react'
|
||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||
import type { GestureMessages } from '@/editor/annotations/useGestureMessage'
|
||||
import { canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||
import { cancelPending } from '@/editor/annotations/workStore'
|
||||
import {
|
||||
cancelPending,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
const PILL =
|
||||
@@ -45,6 +48,8 @@ export default function GestureMessage({
|
||||
function Message({ messages }: { messages: GestureMessages }) {
|
||||
const t = useT()
|
||||
const readOnly = useEditorReadOnly()
|
||||
// A12: « Défaire » is hidden during a creation; the message itself stays.
|
||||
const creating = useAnnotationWork((s) => s.creation !== null)
|
||||
const { message, hold } = messages
|
||||
if (!message) return null
|
||||
const error = message.tone === 'error'
|
||||
@@ -65,7 +70,7 @@ function Message({ messages }: { messages: GestureMessages }) {
|
||||
<span className="truncate" title={message.text}>
|
||||
{message.text}
|
||||
</span>
|
||||
{message.undo && !error && (
|
||||
{message.undo && !error && !creating && (
|
||||
<>
|
||||
<span aria-hidden="true">·</span>
|
||||
<button
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useT } from '@/i18n/useT'
|
||||
const KINDS: readonly NewKind[] = ['point', 'zone', 'detail_trigger']
|
||||
|
||||
/**
|
||||
* The keyboard creation path (C7): each button holds a pending element at the centre of
|
||||
* the frame and opens the creation panel; every coordinate is then typed in the fields.
|
||||
* The keyboard creation path (C7): each button places a shape at the centre of the frame
|
||||
* at the A5 size and opens the creation dialog; once created, its handles correct it.
|
||||
*/
|
||||
export default function KeyboardAdd({
|
||||
disabled,
|
||||
@@ -28,6 +28,7 @@ export default function KeyboardAdd({
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
data-add-kind={kind}
|
||||
disabled={disabled || (kind === 'detail_trigger' && linkDisabled)}
|
||||
onClick={() => onAdd(kind)}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { MissingField } from '@/editor/annotations/missingFields'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** Each missing field's input id, after the form's id prefix. */
|
||||
const FIELD_ID: Record<MissingField, string> = {
|
||||
name_fr: 'fr',
|
||||
name_en: 'en',
|
||||
category: 'category',
|
||||
laterality: 'laterality',
|
||||
opens: 'opens',
|
||||
}
|
||||
|
||||
const FIELD_LABEL: Record<MissingField, string> = {
|
||||
name_fr: 'editor.annotations.name_fr',
|
||||
name_en: 'editor.annotations.name_en',
|
||||
category: 'editor.annotations.category',
|
||||
laterality: 'editor.annotations.laterality',
|
||||
opens: 'editor.annotations.opens',
|
||||
}
|
||||
|
||||
/** R-3: the focus goes to the first missing field of the form whose ids start with `prefix`. */
|
||||
export function focusFirstMissing(
|
||||
prefix: string,
|
||||
missing: readonly MissingField[],
|
||||
): void {
|
||||
const first = missing[0]
|
||||
if (first) document.getElementById(`${prefix}${FIELD_ID[first]}`)?.focus()
|
||||
}
|
||||
|
||||
/**
|
||||
* « À compléter : Latéralité. »: the missing fields by their labels, in form order. The
|
||||
* creation dialog and the edit form share it (R-3).
|
||||
*/
|
||||
export default function MissingSummary({
|
||||
missing,
|
||||
}: {
|
||||
missing: readonly MissingField[]
|
||||
}) {
|
||||
const t = useT()
|
||||
if (missing.length === 0) return null
|
||||
const fields = missing.map((field) => t(FIELD_LABEL[field])).join(', ')
|
||||
return (
|
||||
<p role="alert" className="text-sm text-[var(--color-danger-strong)]">
|
||||
{t('editor.annotations.missing.summary').replace(
|
||||
'{fields}',
|
||||
() => fields,
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
@@ -2,9 +2,9 @@ import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import Button from '@/components/ui/Button'
|
||||
import { useDeselect } from '@/editor/annotations/deselect'
|
||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||
import { dropCreation } from '@/editor/annotations/creationWork'
|
||||
import { beginRedraw } from '@/editor/annotations/redraw'
|
||||
import { stripLeadOf } from '@/editor/annotations/stripLead'
|
||||
import type { UiState } from '@/editor/annotations/uiState'
|
||||
import { useGeometryIssues } from '@/editor/annotations/useGeometryIssues'
|
||||
import type { GestureMessage as ShownMessage } from '@/editor/annotations/useGestureMessage'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
@@ -12,6 +12,7 @@ import { targetOfKey } from '@/editor/navigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { Scene, Work } from './EditableAnnotations'
|
||||
import CreationCommands from './CreationCommands'
|
||||
import EditStrip, { type StripNotice } from './EditStrip'
|
||||
import {
|
||||
SelectionPointCommands,
|
||||
@@ -48,9 +49,14 @@ export default function SceneStrip({
|
||||
detail: t('editor.annotations.move.hint'),
|
||||
icon: 'move' as const,
|
||||
}
|
||||
: stripLeadOf(ui, selected, doc, { t, locale, chosenVertex })
|
||||
: stripLeadOf(
|
||||
{ tool: ui.tool, tracing: scene.tracing, creation: scene.creation },
|
||||
selected,
|
||||
doc,
|
||||
{ t, locale, chosenVertex },
|
||||
)
|
||||
const commandsKey = commandsKeyOf(
|
||||
ui,
|
||||
scene,
|
||||
mode !== null,
|
||||
work.target,
|
||||
chosenVertex,
|
||||
@@ -69,12 +75,15 @@ export default function SceneStrip({
|
||||
|
||||
/** One box per set of commands: a wider set never moves an existing box (A14). */
|
||||
function commandsKeyOf(
|
||||
ui: UiState,
|
||||
{ ui, tracing, creation }: Scene,
|
||||
moving: boolean,
|
||||
target: Annotation | null,
|
||||
chosen: number | null,
|
||||
) {
|
||||
if (ui.tracing) return 'tracing'
|
||||
if (creation?.dialog) return 'creation-dialog'
|
||||
if (creation?.resumed)
|
||||
return `creation-${creation.closed ? 'point' : 'trace'}`
|
||||
if (tracing) return 'tracing'
|
||||
if (moving) return 'move'
|
||||
if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}`
|
||||
if (target?.kind === 'point') return 'point'
|
||||
@@ -124,17 +133,25 @@ function SceneCommands({
|
||||
work: Work
|
||||
moving: boolean
|
||||
}) {
|
||||
const { ui, doc, viewId, frame, dispatch, selected } = scene
|
||||
const { ui, doc, viewId, frame, dispatch, selected, creation, tracing } =
|
||||
scene
|
||||
const { byButton } = useDeselect(selected?.id ?? null, () =>
|
||||
dispatch({ type: 'select', id: null }),
|
||||
)
|
||||
if (ui.tracing) {
|
||||
// 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 (tracing) {
|
||||
// « Annuler le tracé » is an explicit cancel: it acts at once (board 04 A).
|
||||
const redraw = tracing.target === 'replace'
|
||||
return (
|
||||
<TracingCommands
|
||||
count={ui.tracing.points.length}
|
||||
count={tracing.points.length}
|
||||
onClose={work.placement.closeTracing}
|
||||
onPop={work.placement.popVertex}
|
||||
onCancel={() => dispatch({ type: 'trace_cancel' })}
|
||||
onCancel={() =>
|
||||
redraw ? dispatch({ type: 'trace_cancel' }) : dropCreation()
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -152,7 +169,7 @@ function SceneCommands({
|
||||
</>
|
||||
)
|
||||
}
|
||||
if (ui.tool !== 'point' || ui.pending || !frame) return null
|
||||
if (ui.tool !== 'point' || creation || !frame) return null
|
||||
return (
|
||||
<ToolSize
|
||||
doc={doc}
|
||||
@@ -187,7 +204,7 @@ function useStripNotice(
|
||||
return { tone: 'error', text: issues[0]!, more: issues.length - 1 }
|
||||
}
|
||||
// R-18: a « + » hidden for its short segment; never in a mode (move, redraw).
|
||||
if (work.insertsHidden && !inMode && !ui.tracing) {
|
||||
if (work.insertsHidden && !inMode && !scene.tracing) {
|
||||
return { tone: 'info', text: t('editor.annotations.strip.zoom_hint') }
|
||||
}
|
||||
if (!model.measured) return unmeasuredNotice(scene, t)
|
||||
|
||||
@@ -26,10 +26,13 @@ function ToolButton({
|
||||
label,
|
||||
pressed,
|
||||
disabled,
|
||||
tool,
|
||||
onClick,
|
||||
}: {
|
||||
glyph: GlyphName
|
||||
label: string
|
||||
/** The tool it chooses: a creation's « Abandonner » gives it the focus back (board 32). */
|
||||
tool?: ToolId
|
||||
pressed?: boolean
|
||||
disabled?: boolean
|
||||
onClick: () => void
|
||||
@@ -40,6 +43,7 @@ function ToolButton({
|
||||
aria-label={label}
|
||||
title={label}
|
||||
aria-pressed={pressed}
|
||||
data-tool={tool}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
className={`${BUTTON} ${
|
||||
@@ -59,6 +63,7 @@ export default function ToolColumn(props: ToolColumnProps) {
|
||||
const tool = (id: ToolId, disabled: boolean) => (
|
||||
<ToolButton
|
||||
glyph={id}
|
||||
tool={id}
|
||||
label={t(`editor.annotations.tool.${id}`)}
|
||||
pressed={props.tool === id}
|
||||
disabled={disabled}
|
||||
|
||||
@@ -58,26 +58,32 @@ function focusWhenOnTop(target: HTMLElement): () => void {
|
||||
return () => watcher.disconnect()
|
||||
}
|
||||
|
||||
/** The question and its answers, when a form asks other words (the creation, R-12). */
|
||||
export interface DiscardWords {
|
||||
title: string
|
||||
keep: string
|
||||
discard: string
|
||||
}
|
||||
|
||||
export default function DiscardConfirm({
|
||||
onKeepTyping,
|
||||
onDiscard,
|
||||
words,
|
||||
}: {
|
||||
onKeepTyping: () => void
|
||||
onDiscard: () => void
|
||||
words?: DiscardWords
|
||||
}) {
|
||||
const t = useT()
|
||||
const title = words?.title ?? t('editor.findings.discard_ask')
|
||||
const keep = useRef<HTMLButtonElement>(null)
|
||||
useEffect(() => {
|
||||
const button = keep.current
|
||||
return button ? focusWhenOnTop(button) : undefined
|
||||
}, [])
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
aria-label={t('editor.findings.discard_ask')}
|
||||
className={BOX}
|
||||
>
|
||||
<p className="text-sm font-medium">{t('editor.findings.discard_ask')}</p>
|
||||
<div role="group" aria-label={title} className={BOX}>
|
||||
<p className="text-sm font-medium">{title}</p>
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Button
|
||||
ref={keep}
|
||||
@@ -85,10 +91,10 @@ export default function DiscardConfirm({
|
||||
variant="secondary"
|
||||
onClick={onKeepTyping}
|
||||
>
|
||||
{t('editor.findings.keep_typing')}
|
||||
{words?.keep ?? t('editor.findings.keep_typing')}
|
||||
</Button>
|
||||
<Button type="button" variant="danger" onClick={onDiscard}>
|
||||
{t('editor.findings.discard')}
|
||||
{words?.discard ?? t('editor.findings.discard')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
|
||||
import AnnotationDialog from '@/components/editor/annotations/AnnotationDialog'
|
||||
import { annotationName } from '@/components/editor/annotations/AnnotationList'
|
||||
import AnnotationReadBody from '@/components/editor/annotations/AnnotationReadBody'
|
||||
import CreationDialog from '@/components/editor/annotations/CreationDialog'
|
||||
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
|
||||
import EditStrip from '@/components/editor/annotations/EditStrip'
|
||||
import OverviewPanel from '@/components/editor/annotations/OverviewPanel'
|
||||
@@ -68,8 +69,9 @@ function SectionPlace({
|
||||
}
|
||||
|
||||
/**
|
||||
* The drawing workspace: edit or read-only body of the same view, and the properties
|
||||
* dialog over both, outside the edit-only part so a read-only flip keeps it (R-14).
|
||||
* The drawing workspace: edit or read-only body of the same view, and the properties and
|
||||
* creation dialogs over both, outside the edit-only part so a read-only flip keeps them
|
||||
* (R-14).
|
||||
*/
|
||||
function DrawingPlace(props: AnnotationsTabProps) {
|
||||
const t = useT()
|
||||
@@ -107,6 +109,9 @@ function DrawingPlace(props: AnnotationsTabProps) {
|
||||
returnFocus={dialog.returnFocus}
|
||||
/>
|
||||
)}
|
||||
{doc && (
|
||||
<CreationDialog doc={doc} readOnly={readOnly} anchor={dialog.anchor} />
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -120,8 +125,8 @@ function SectionBody(props: AnnotationsTabProps & { id: SectionId }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations: the drawing workspace (canvas with its tools, the overview or the creation
|
||||
* panel, the properties dialog), or one of its full-width sections. Read-only, the same
|
||||
* Annotations: the drawing workspace (canvas with its tools, the overview, the properties
|
||||
* and creation dialogs), or one of its full-width sections. Read-only, the same
|
||||
* view is browsable (canvas, list, properties as text) with no tool and no action.
|
||||
* Each section shown so far stays mounted, hidden while another is shown.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user