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.
|
||||
*/
|
||||
|
||||
@@ -31,22 +31,7 @@ export interface PendingElement {
|
||||
wantedRadius?: number
|
||||
}
|
||||
|
||||
/** The pending element with a geometry the user typed: C and the proposal lapse with it. */
|
||||
export function withGeometry(
|
||||
pending: PendingElement,
|
||||
geometry: EditableGeometry,
|
||||
): PendingElement {
|
||||
const kept =
|
||||
geometry.type === 'circle' && geometry.r === pending.proposedRadius
|
||||
return {
|
||||
...pending,
|
||||
geometry,
|
||||
correction: null,
|
||||
proposedRadius: kept ? pending.proposedRadius : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** What the creation panel collects (no default labels: names and laterality are typed). */
|
||||
/** What the creation dialog collects (no default labels: names and laterality are typed). */
|
||||
export interface CreationForm {
|
||||
fr: string
|
||||
en: string
|
||||
@@ -107,23 +92,8 @@ export function keyboardPending(
|
||||
return { kind, geometry: { type: 'polygon', points: centreTriangle(frame) } }
|
||||
}
|
||||
|
||||
export type FormProblem = 'names' | 'fields'
|
||||
|
||||
const blank = (value: string) => value.trim() === ''
|
||||
|
||||
/** Input shape only: what the core requires to exist, collected before the insert. */
|
||||
export function formProblem(
|
||||
kind: NewKind,
|
||||
form: CreationForm,
|
||||
): FormProblem | null {
|
||||
if (form.categoryId === '' || form.laterality === '') return 'fields'
|
||||
if (kind === 'detail_trigger') {
|
||||
if (form.opensViewId === '') return 'fields'
|
||||
return blank(form.fr) !== blank(form.en) ? 'names' : null
|
||||
}
|
||||
return blank(form.fr) || blank(form.en) ? 'names' : null
|
||||
}
|
||||
|
||||
const orNull = (value: string): string | null => (blank(value) ? null : value)
|
||||
|
||||
/** The annotation the form and the pending geometry describe, under a given id. */
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed'
|
||||
import { visibleElement } from '../focusRequest'
|
||||
import { guardDrawing } from './drawingGuard'
|
||||
import type { NewKind } from './creation'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
const TOOL_OF: Record<NewKind, string> = {
|
||||
point: 'point',
|
||||
zone: 'zone',
|
||||
detail_trigger: 'link',
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the focus goes once a creation is abandoned (board 32): the tool's button, or the
|
||||
* keyboard « Ajouter … » button that started it.
|
||||
*/
|
||||
export function creationOpener(work: Creation): HTMLElement | null {
|
||||
const { kind } = work.pending
|
||||
if (work.origin === 'keyboard') {
|
||||
return visibleElement(`[data-add-kind="${kind}"]`)
|
||||
}
|
||||
return visibleElement(`[data-tool="${TOOL_OF[kind]}"]`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape or « Abandonner » outside the dialog (a tracing, a point being replaced): the
|
||||
* guard is always armed (A12), « Abandonner la création ? » asks; its « Abandonner »
|
||||
* drops the creation and the focus goes back to what started it.
|
||||
*/
|
||||
export function askCreation(): void {
|
||||
const work = useAnnotationWork.getState().creation
|
||||
if (!work) return
|
||||
guardDrawing(() => landAfterModalsClosed(() => creationOpener(work)?.focus()))
|
||||
}
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
} from './correction'
|
||||
import {
|
||||
annotationOf,
|
||||
formProblem,
|
||||
type CreationForm,
|
||||
type PendingElement,
|
||||
} from './creation'
|
||||
import { defaultRadius, type Frame } from './frame'
|
||||
import type { EditableGeometry } from './geometryEdit'
|
||||
import { missingFields, type MissingField } from './missingFields'
|
||||
|
||||
/** What « Créer » or the confirmation of C works from. */
|
||||
export interface CreationInput {
|
||||
@@ -28,7 +28,10 @@ export interface CreationInput {
|
||||
context: CommitContext
|
||||
}
|
||||
|
||||
export type Attempt = PointAttempt | { status: 'invalid'; problem: string }
|
||||
/** `invalid`: the fields R-3 names as missing, nothing tried. */
|
||||
export type Attempt =
|
||||
| PointAttempt
|
||||
| { status: 'invalid'; missing: MissingField[] }
|
||||
|
||||
/** The insert of the pending element under a given geometry, through `accept`. */
|
||||
function inserterOf(input: CreationInput, form: CreationForm) {
|
||||
@@ -46,8 +49,8 @@ export function createAttempt(
|
||||
form: CreationForm,
|
||||
): Attempt {
|
||||
const { pending, frame } = input
|
||||
const problem = formProblem(pending.kind, form)
|
||||
if (problem) return { status: 'invalid', problem }
|
||||
const missing = missingFields(pending.kind, form)
|
||||
if (missing.length > 0) return { status: 'invalid', missing }
|
||||
const insert = inserterOf(input, form)
|
||||
const { geometry } = pending
|
||||
if (pending.kind === 'point' && geometry.type === 'circle' && frame) {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { Point } from '@faunosteo/core-wasm/types'
|
||||
import type { CreationForm, NewKind, PendingElement } from './creation'
|
||||
import type { Correction } from './correction'
|
||||
import type { Frame } from './frame'
|
||||
import type { Tracing } from './uiState'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
/** Where a creation starts: its view, F, how it began, and the form it starts with. */
|
||||
export interface CreationStart {
|
||||
viewId: string
|
||||
frame: Frame | null
|
||||
origin: Creation['origin']
|
||||
form: CreationForm
|
||||
}
|
||||
|
||||
const creation = () => useAnnotationWork.getState().creation
|
||||
|
||||
function patch(change: Partial<Creation>): void {
|
||||
const current = creation()
|
||||
if (current)
|
||||
useAnnotationWork.setState({ creation: { ...current, ...change } })
|
||||
}
|
||||
|
||||
/**
|
||||
* A placed point or a keyboard shape: the dialog opens (A2). A creation of the same kind
|
||||
* keeps its form (« Replacer le point »: the next click moves the ghost).
|
||||
*/
|
||||
export function placePending(
|
||||
start: CreationStart,
|
||||
pending: PendingElement,
|
||||
): void {
|
||||
const kept = creation()
|
||||
const same = kept !== null && kept.pending.kind === pending.kind
|
||||
useAnnotationWork.setState({
|
||||
creation: {
|
||||
...start,
|
||||
form: same ? kept.form : start.form,
|
||||
resumed: same ? kept.resumed : false,
|
||||
pending,
|
||||
closed: true,
|
||||
dialog: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const polygonOf = (kind: NewKind, points: Point[]): PendingElement => ({
|
||||
kind,
|
||||
geometry: { type: 'polygon', points },
|
||||
})
|
||||
|
||||
/** The open tracing's vertices; none when no tracing of a new shape is open. */
|
||||
const tracedPoints = (work: Creation | null): Point[] | null =>
|
||||
work && !work.closed && work.pending.geometry.type === 'polygon'
|
||||
? work.pending.geometry.points
|
||||
: null
|
||||
|
||||
/** A vertex of a new zone or link: the first one starts the creation (A12). */
|
||||
export function traceVertex(
|
||||
start: CreationStart,
|
||||
kind: NewKind,
|
||||
point: Point,
|
||||
): void {
|
||||
const points = tracedPoints(creation())
|
||||
if (points) return patch({ pending: polygonOf(kind, [...points, point]) })
|
||||
useAnnotationWork.setState({
|
||||
creation: {
|
||||
...start,
|
||||
pending: polygonOf(kind, [point]),
|
||||
closed: false,
|
||||
dialog: false,
|
||||
resumed: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** Backspace or « Retirer le dernier sommet »; a fresh tracing left empty is no creation. */
|
||||
export function popVertex(): void {
|
||||
const work = creation()
|
||||
const points = tracedPoints(work)
|
||||
if (!work || !points) return
|
||||
const left = points.slice(0, -1)
|
||||
if (left.length === 0 && !work.resumed) return dropCreation()
|
||||
patch({ pending: polygonOf(work.pending.kind, left) })
|
||||
}
|
||||
|
||||
/** The tracing closes (three vertices at least): « Nouvelle zone » opens. */
|
||||
export function closeTrace(): boolean {
|
||||
const points = tracedPoints(creation())
|
||||
if (!points || points.length < 3) return false
|
||||
patch({ closed: true, dialog: true })
|
||||
return true
|
||||
}
|
||||
|
||||
/** « Reprendre le tracé »: the dialog hides, the vertices and the form are kept. */
|
||||
export function resumeTrace(): void {
|
||||
patch({ closed: false, dialog: false, resumed: true })
|
||||
}
|
||||
|
||||
/** « Replacer le point »: the dialog hides; the next click moves the ghost. */
|
||||
export function replacePoint(): void {
|
||||
patch({ dialog: false, resumed: true })
|
||||
}
|
||||
|
||||
/** « Revenir aux propriétés »: a resumed tracing closes again, a point shows its dialog. */
|
||||
export function backToProperties(): boolean {
|
||||
const work = creation()
|
||||
if (!work) return false
|
||||
if (work.closed) {
|
||||
patch({ dialog: true })
|
||||
return true
|
||||
}
|
||||
return closeTrace()
|
||||
}
|
||||
|
||||
export function patchForm(change: Partial<CreationForm>): void {
|
||||
const work = creation()
|
||||
if (work) patch({ form: { ...work.form, ...change } })
|
||||
}
|
||||
|
||||
/** Candidate C offered by the core's verdict (C26), or withdrawn. */
|
||||
export function setCorrection(correction: Correction | null): void {
|
||||
const work = creation()
|
||||
if (work) patch({ pending: { ...work.pending, correction } })
|
||||
}
|
||||
|
||||
/** « Abandonner », or a guard's « Abandonner »: nothing of the creation is left. */
|
||||
export function dropCreation(): void {
|
||||
useAnnotationWork.setState({ creation: null })
|
||||
}
|
||||
|
||||
/** « Créer » succeeded: the creation ends, the drawing selects `id` (A7). */
|
||||
export function finishCreation(id: string, kind: NewKind): void {
|
||||
useAnnotationWork.setState({ creation: null, created: { id, kind } })
|
||||
}
|
||||
|
||||
/** The open tracing of a new shape on `viewId`, as the drawing reads a tracing. */
|
||||
export function creationTracing(
|
||||
work: Creation | null,
|
||||
viewId: string,
|
||||
): Tracing | null {
|
||||
const points = tracedPoints(work)
|
||||
if (!work || !points || work.viewId !== viewId) return null
|
||||
return {
|
||||
target: work.pending.kind,
|
||||
annotationId: null,
|
||||
points,
|
||||
refused: false,
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@/editor/focusRequest'
|
||||
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { askCreation } from './creationAsk'
|
||||
import { commitFocusedSeries } from './drawingGuard'
|
||||
import { escapeAction, type EscapeAction } from './escape'
|
||||
import { endMode, useAnnotationWork } from './workStore'
|
||||
@@ -121,8 +122,9 @@ function runEscape(action: EscapeAction, deselect: () => boolean): boolean {
|
||||
else if (action === 'drop_mode') endMode()
|
||||
else if (action === 'unchoose') useAnnotationWork.setState({ chosen: null })
|
||||
else if (action === 'deselect') return deselect()
|
||||
// `ask_creation`: the creation dialog asks (U2 Task 7); nothing here yet.
|
||||
return action !== null && action !== 'ask_creation'
|
||||
// The dialog hidden (a tracing, a point being replaced): « Abandonner la création ? ».
|
||||
else if (action === 'ask_creation') askCreation()
|
||||
return action !== null
|
||||
}
|
||||
|
||||
/** Where Escape applies: the editable body runs the work order; the read-only twin deselects. */
|
||||
|
||||
@@ -28,21 +28,30 @@ function endModeOnly(): void {
|
||||
* (false).
|
||||
*/
|
||||
export function guardDrawing(proceed: () => void): boolean {
|
||||
const work = guardWork(useAnnotationWork.getState())
|
||||
const state = useAnnotationWork.getState()
|
||||
const work = guardWork(state)
|
||||
if (work === null) {
|
||||
commitFocusedSeries()
|
||||
endModeOnly()
|
||||
return true
|
||||
}
|
||||
useAnnotationWork.setState({ question: { work, proceed } })
|
||||
// A question already open keeps its own move (a Back over it is not replayed).
|
||||
if (state.question === null) {
|
||||
useAnnotationWork.setState({ question: { work, proceed } })
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** « Continuer » keeps the work as it is; « Abandonner » drops it and makes the move. */
|
||||
/**
|
||||
* « Continuer » keeps the work as it is; « Abandonner » drops the work the question
|
||||
* named (the mode, or the whole creation) and makes the move.
|
||||
*/
|
||||
export function answerDrawing(discard: boolean): void {
|
||||
const { question } = useAnnotationWork.getState()
|
||||
useAnnotationWork.setState({ question: null })
|
||||
if (!discard || !question) return
|
||||
endMode()
|
||||
if (question.work === 'creation')
|
||||
useAnnotationWork.setState({ creation: null })
|
||||
else endMode()
|
||||
question.proceed()
|
||||
}
|
||||
@@ -35,13 +35,13 @@ export interface DrawingState {
|
||||
}
|
||||
|
||||
const BUSY_TARGET = {
|
||||
creation: '[data-creation-heading]',
|
||||
creation: '[data-creation-focus]',
|
||||
tracing: '[data-testid="tracing-commands"]',
|
||||
} as const
|
||||
|
||||
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
|
||||
|
||||
/** A creation or tracing in progress keeps the request: focus its panel, say why. */
|
||||
/** A creation or tracing in progress keeps the request: focus its dialog or the strip, say why. */
|
||||
function keepBusy(
|
||||
busy: NonNullable<DrawingState['busy']>,
|
||||
announce: (text: string) => void,
|
||||
|
||||
@@ -10,7 +10,8 @@ import type { Locale } from '@/i18n/types'
|
||||
import { pluralKey } from '../plural'
|
||||
import type { PendingElement } from './creation'
|
||||
import { HANDLE_CAP } from './polygonEdit'
|
||||
import type { ToolId, Tracing, UiState } from './uiState'
|
||||
import type { ToolId, Tracing } from './uiState'
|
||||
import type { Creation } from './workStore'
|
||||
|
||||
/** The strip's left part: what is selected or in progress, then its type and detail. */
|
||||
export interface StripLead {
|
||||
@@ -130,6 +131,27 @@ function pendingLead(pending: PendingElement, ctx: LeadContext): StripLead {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A creation whose dialog is shown or was (board 04 C): placed or closed, waiting for its
|
||||
* properties; a point being replaced says where to click; a resumed tracing says the
|
||||
* input is kept. A fresh tracing reads as a tracing.
|
||||
*/
|
||||
function creationLead(work: Creation, ctx: LeadContext): StripLead | null {
|
||||
const { pending } = work
|
||||
const title = ctx.t(`editor.annotations.new.${pending.kind}`)
|
||||
const icon = ICON[pending.kind]
|
||||
if (work.closed && !work.dialog && pending.geometry.type === 'circle') {
|
||||
return {
|
||||
title,
|
||||
detail: ctx.t('editor.annotations.strip.place_point'),
|
||||
icon,
|
||||
}
|
||||
}
|
||||
if (work.closed) return pendingLead(pending, ctx)
|
||||
if (!work.resumed) return null
|
||||
return { title, detail: ctx.t('editor.annotations.strip.resumed'), icon }
|
||||
}
|
||||
|
||||
const TOOL_LEAD: Record<
|
||||
ToolId,
|
||||
{ title: string; detail: string; icon: GlyphName }
|
||||
@@ -156,14 +178,22 @@ const TOOL_LEAD: Record<
|
||||
},
|
||||
}
|
||||
|
||||
/** What the strip reads of the drawing: the tool, the tracing shown, the creation. */
|
||||
export interface LeadState {
|
||||
tool: ToolId
|
||||
tracing: Tracing | null
|
||||
creation?: Creation | null
|
||||
}
|
||||
|
||||
/** What the strip leads with: a creation, then a tracing, then the selection, then the tool. */
|
||||
export function stripLeadOf(
|
||||
ui: UiState,
|
||||
ui: LeadState,
|
||||
selected: Annotation | undefined,
|
||||
doc: AnatomicalSheetDocument,
|
||||
ctx: LeadContext,
|
||||
): StripLead {
|
||||
if (ui.pending) return pendingLead(ui.pending, ctx)
|
||||
const creation = ui.creation ? creationLead(ui.creation, ctx) : null
|
||||
if (creation) return creation
|
||||
if (ui.tracing) {
|
||||
const replaced = doc.annotations.find(
|
||||
(a) => a.id === ui.tracing?.annotationId,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type { Point } from '@faunosteo/core-wasm/types'
|
||||
import type { NewKind, PendingElement } from './creation'
|
||||
import type { NewKind } from './creation'
|
||||
|
||||
export type ToolId = 'select' | 'point' | 'zone' | 'link'
|
||||
|
||||
/** A tracing in progress: a new zone or link, or a polygon replacing a geometry. */
|
||||
/**
|
||||
* A tracing in progress: a new zone or link, or a polygon replacing a geometry. Only a
|
||||
* redraw's tracing is the reducer's; a new shape's lives in the creation (work store).
|
||||
*/
|
||||
export interface Tracing {
|
||||
target: NewKind | 'replace'
|
||||
/** The annotation whose geometry the tracing replaces (target `replace`). */
|
||||
@@ -17,9 +20,6 @@ export interface UiState {
|
||||
viewId: string | null
|
||||
tool: ToolId
|
||||
selectedId: string | null
|
||||
pending: PendingElement | null
|
||||
/** Bumped by every new pending element: keys the creation form's own state. */
|
||||
serial: number
|
||||
tracing: Tracing | null
|
||||
hint: string | null
|
||||
/** The overview's « Filtrer par nom » term: it outlives a selection, not a view. */
|
||||
@@ -32,9 +32,6 @@ export type UiAction =
|
||||
| { type: 'view'; viewId: string }
|
||||
| { type: 'tool'; tool: ToolId }
|
||||
| { type: 'select'; id: string | null }
|
||||
| { type: 'pending_new'; pending: PendingElement }
|
||||
| { type: 'pending_update'; pending: PendingElement }
|
||||
| { type: 'pending_drop' }
|
||||
| { type: 'trace_start'; target: Tracing['target']; annotationId?: string }
|
||||
| { type: 'trace_add'; point: Point }
|
||||
| { type: 'trace_pop' }
|
||||
@@ -48,8 +45,6 @@ export const initialUi: UiState = {
|
||||
viewId: null,
|
||||
tool: 'select',
|
||||
selectedId: null,
|
||||
pending: null,
|
||||
serial: 0,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
filter: '',
|
||||
@@ -88,32 +83,13 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
|
||||
...state,
|
||||
tool: toolAfterTracing(state),
|
||||
selectedId: action.id,
|
||||
pending: null,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
}
|
||||
case 'pending_new':
|
||||
return {
|
||||
...state,
|
||||
pending: action.pending,
|
||||
// A second click with the same kind keeps the typed fields (same panel).
|
||||
serial:
|
||||
state.pending?.kind === action.pending.kind
|
||||
? state.serial
|
||||
: state.serial + 1,
|
||||
selectedId: null,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
}
|
||||
case 'pending_update':
|
||||
return state.pending ? { ...state, pending: action.pending } : state
|
||||
case 'pending_drop':
|
||||
return { ...state, pending: null, hint: null }
|
||||
case 'trace_start':
|
||||
return {
|
||||
...state,
|
||||
tool: TOOL_OF[action.target],
|
||||
pending: null,
|
||||
hint: null,
|
||||
tracing: {
|
||||
target: action.target,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
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 { focusRowOrDrawing } from './deselect'
|
||||
import type { ToolId, UiAction, UiState } from './uiState'
|
||||
import type { GestureMessages } from './useGestureMessage'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
const TOOL_OF: Record<NewKind, ToolId> = {
|
||||
point: 'point',
|
||||
zone: 'zone',
|
||||
detail_trigger: 'link',
|
||||
}
|
||||
|
||||
export interface CreationFollow {
|
||||
doc: AnatomicalSheetDocument
|
||||
ui: UiState
|
||||
dispatch: Dispatch<UiAction>
|
||||
creation: Creation | null
|
||||
message: Pick<GestureMessages, 'show'>
|
||||
t: (key: string) => string
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
function useDrawingFollows({ doc, ui, dispatch, creation }: CreationFollow) {
|
||||
const wanted =
|
||||
creation && !creation.dialog ? TOOL_OF[creation.pending.kind] : null
|
||||
// A placed or closed shape takes the stage; a fresh tracing keeps the selection under
|
||||
// it, as before, so abandoning it gives the selection back.
|
||||
const selected = creation?.closed === true && ui.selectedId !== null
|
||||
const gone =
|
||||
creation !== null && !doc.views.some((v) => v.id === creation.viewId)
|
||||
useEffect(() => {
|
||||
if (wanted && wanted !== ui.tool) dispatch({ type: 'tool', tool: wanted })
|
||||
}, [wanted, ui.tool, dispatch])
|
||||
useEffect(() => {
|
||||
if (selected) dispatch({ type: 'select', id: null })
|
||||
}, [selected, dispatch])
|
||||
useEffect(() => {
|
||||
if (gone) dropCreation()
|
||||
}, [gone])
|
||||
}
|
||||
|
||||
/**
|
||||
* « Créer » succeeded (A7): the tool goes back to « Sélectionner », the new annotation is
|
||||
* selected, the line under the drawing says « Point créé · Défaire » and the focus goes to
|
||||
* its row once the dialog has closed (board 32).
|
||||
*/
|
||||
function useCreatedFollows({ dispatch, message, t }: CreationFollow) {
|
||||
const created = useAnnotationWork((s) => s.created)
|
||||
const latest = useRef({ message, t })
|
||||
latest.current = { message, t }
|
||||
useEffect(() => {
|
||||
if (!created) return
|
||||
useAnnotationWork.setState({ created: null })
|
||||
dispatch({ type: 'tool', tool: 'select' })
|
||||
dispatch({ type: 'select', id: created.id })
|
||||
const text = latest.current.t(
|
||||
`editor.annotations.message.created.${created.kind}`,
|
||||
)
|
||||
latest.current.message.show(text, { undo: true, tone: 'info' })
|
||||
landAfterModalsClosed(() => void focusRowOrDrawing(created.id))
|
||||
}, [created, dispatch])
|
||||
}
|
||||
|
||||
export function useCreationFollow(input: CreationFollow): void {
|
||||
useDrawingFollows(input)
|
||||
useCreatedFollows(input)
|
||||
}
|
||||
@@ -7,7 +7,15 @@ import type {
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { updateGeometry, type CommitContext } from './annotationCommit'
|
||||
import { pendingForClick, type NewKind } from './creation'
|
||||
import { emptyForm, pendingForClick, type NewKind } from './creation'
|
||||
import {
|
||||
closeTrace,
|
||||
placePending,
|
||||
popVertex,
|
||||
traceVertex,
|
||||
type CreationStart,
|
||||
} from './creationWork'
|
||||
import { askCreation } from './creationAsk'
|
||||
import { round2, type Frame, type XY } from './frame'
|
||||
import { newPointSize } from './pointSize'
|
||||
import { endMode, useAnnotationWork } from './workStore'
|
||||
@@ -22,6 +30,8 @@ const TOOL_TARGET: Record<Exclude<ToolId, 'select'>, NewKind> = {
|
||||
|
||||
export interface PlacementInput {
|
||||
ui: UiState
|
||||
/** The tracing shown: a redraw's (the reducer's) or a new shape's (the creation's). */
|
||||
tracing: Tracing | null
|
||||
dispatch: Dispatch<UiAction>
|
||||
frame: Frame | null
|
||||
doc: AnatomicalSheetDocument
|
||||
@@ -64,44 +74,52 @@ function closeRedraw(input: PlacementInput, tracing: Tracing): void {
|
||||
input.message.show(text, { undo: true, tone: 'info' })
|
||||
}
|
||||
|
||||
/** Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. */
|
||||
/** Where a creation on this view starts: F, the origin, a fresh form (A4). */
|
||||
export const creationStart = (
|
||||
{ viewId, frame, doc }: Pick<PlacementInput, 'viewId' | 'frame' | 'doc'>,
|
||||
origin: CreationStart['origin'],
|
||||
): CreationStart => ({ viewId, frame, origin, form: emptyForm(doc) })
|
||||
|
||||
const isRedraw = (tracing: Tracing | null) => tracing?.target === 'replace'
|
||||
|
||||
/**
|
||||
* Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. A
|
||||
* redraw's tracing is the reducer's; a new shape's is the creation's (A12): its Escape
|
||||
* asks « Abandonner la création ? » (board 32 row 3).
|
||||
*/
|
||||
function tracingActions(input: PlacementInput) {
|
||||
const { ui, dispatch } = input
|
||||
const { tracing, dispatch } = input
|
||||
const closeTracing = () => {
|
||||
const tracing = ui.tracing
|
||||
if (!tracing || tracing.points.length < 3) return
|
||||
if (tracing.target === 'replace') return closeRedraw(input, tracing)
|
||||
const pending = {
|
||||
kind: tracing.target,
|
||||
geometry: { type: 'polygon' as const, points: tracing.points },
|
||||
}
|
||||
dispatch({ type: 'pending_new', pending })
|
||||
if (isRedraw(tracing)) return closeRedraw(input, tracing)
|
||||
closeTrace()
|
||||
}
|
||||
const trace = (
|
||||
tool: Exclude<ToolId, 'select' | 'point'>,
|
||||
at: XY,
|
||||
reach: number,
|
||||
) => {
|
||||
if (ui.tracing && nearFirstVertex(ui.tracing, at, reach)) {
|
||||
return closeTracing()
|
||||
}
|
||||
if (!ui.tracing)
|
||||
dispatch({ type: 'trace_start', target: TOOL_TARGET[tool] })
|
||||
dispatch({ type: 'trace_add', point: asPoint(at) })
|
||||
if (tracing && nearFirstVertex(tracing, at, reach)) return closeTracing()
|
||||
if (isRedraw(tracing))
|
||||
return dispatch({ type: 'trace_add', point: asPoint(at) })
|
||||
traceVertex(creationStart(input, 'tool'), TOOL_TARGET[tool], asPoint(at))
|
||||
}
|
||||
const pop = () =>
|
||||
isRedraw(tracing) ? dispatch({ type: 'trace_pop' }) : popVertex()
|
||||
const onTraceKey = (event: KeyboardEvent) => {
|
||||
if (!ui.tracing) return
|
||||
if (!tracing) return
|
||||
if (event.key === 'Enter') closeTracing()
|
||||
if (event.key === 'Backspace') {
|
||||
event.preventDefault()
|
||||
dispatch({ type: 'trace_pop' })
|
||||
pop()
|
||||
}
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault()
|
||||
dispatch({ type: 'trace_cancel' })
|
||||
if (isRedraw(tracing)) dispatch({ type: 'trace_cancel' })
|
||||
else askCreation()
|
||||
}
|
||||
}
|
||||
return { closeTracing, trace, onTraceKey }
|
||||
return { closeTracing, trace, onTraceKey, pop }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +192,8 @@ export function usePlacement(input: PlacementInput) {
|
||||
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
||||
const outcome = pendingForClick(frame, at, size)
|
||||
if (outcome.kind === 'pending') {
|
||||
return dispatch({ type: 'pending_new', pending: outcome.pending })
|
||||
dispatch({ type: 'hint', hint: null })
|
||||
return placePending(creationStart(input, 'tool'), outcome.pending)
|
||||
}
|
||||
dispatch({ type: 'hint', hint: t('editor.annotations.outside') })
|
||||
}
|
||||
@@ -183,6 +202,6 @@ export function usePlacement(input: PlacementInput) {
|
||||
onDrop: dropAction(input),
|
||||
onTraceKey: tracing.onTraceKey,
|
||||
closeTracing: tracing.closeTracing,
|
||||
popVertex: () => dispatch({ type: 'trace_pop' }),
|
||||
popVertex: tracing.pop,
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand'
|
||||
import type { Geometry } from '@faunosteo/core-wasm/types'
|
||||
import type { CreationForm, PendingElement } from './creation'
|
||||
import type { CreationForm, NewKind, PendingElement } from './creation'
|
||||
import type { Frame } from './frame'
|
||||
|
||||
/** A geometry shown but not committed, stamped with the document text it was computed on. */
|
||||
export interface Preview {
|
||||
@@ -14,13 +15,29 @@ export interface Chosen {
|
||||
vertex: number
|
||||
base: string
|
||||
}
|
||||
/**
|
||||
* A creation in progress (A12): the only owner of the new shape and of its form, read by
|
||||
* the drawing and by the creation dialog, which lives outside the edit-only body (R-14).
|
||||
*/
|
||||
export interface Creation {
|
||||
viewId: string
|
||||
/** F of the view when the shape was placed: the point's verdict works from it. */
|
||||
frame: Frame | null
|
||||
/** A tool on the drawing, or a keyboard « Ajouter … » (where the focus goes back). */
|
||||
origin: 'tool' | 'keyboard'
|
||||
/** A new zone or link being traced lives here from its first vertex (`closed` false). */
|
||||
pending: PendingElement
|
||||
closed: boolean
|
||||
form: CreationForm
|
||||
/** The dialog is shown; false while the shape is replaced or the trace resumed. */
|
||||
dialog: boolean
|
||||
/** The dialog was shown once: « Replacer le point » or « Reprendre le tracé » ran. */
|
||||
resumed: boolean
|
||||
}
|
||||
/** The annotation « Créer » just inserted: the drawing selects it and says so (A7). */
|
||||
export interface Created {
|
||||
id: string
|
||||
kind: NewKind
|
||||
}
|
||||
/**
|
||||
* A move mode or a redraw, stamped with the document text it started on; `started` once
|
||||
@@ -42,6 +59,7 @@ export interface DrawingQuestion {
|
||||
}
|
||||
interface Work {
|
||||
creation: Creation | null
|
||||
created: Created | null
|
||||
mode: ModeWork | null
|
||||
preview: Preview | null
|
||||
chosen: Chosen | null
|
||||
@@ -51,6 +69,7 @@ interface Work {
|
||||
}
|
||||
const NO_WORK: Work = {
|
||||
creation: null,
|
||||
created: null,
|
||||
mode: null,
|
||||
preview: null,
|
||||
chosen: null,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
landAfterModalsClosed,
|
||||
} from '@/components/ui/afterModalsClosed'
|
||||
import { guardDrawing } from '../annotations/drawingGuard'
|
||||
import { useAnnotationWork } from '../annotations/workStore'
|
||||
import { focusActiveTab } from '../focusRequest'
|
||||
import { LAYERS_TOP_DOWN } from '../leftDraft'
|
||||
import { citationsOfView, sameView, type EditorView } from '../navigation'
|
||||
@@ -251,6 +252,9 @@ function refusal(
|
||||
const { nav, view } = ctx
|
||||
if (document.querySelector('dialog[open]:not([data-layer])')) {
|
||||
nav.guards.askAll(false)
|
||||
// The creation dialog is such a modal: its « Abandonner la création ? » shows inside.
|
||||
if (useAnnotationWork.getState().creation?.dialog)
|
||||
guardDrawing(() => undefined)
|
||||
return 'modal'
|
||||
}
|
||||
const leaving = leavingLayers(view, entry?.view ?? ctx.defaultView)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect } from 'react'
|
||||
import { cancelPending } from './annotations/workStore'
|
||||
import { cancelPending, useAnnotationWork } from './annotations/workStore'
|
||||
import { isTextField } from './focusRequest'
|
||||
import { useEditorStore } from './state/editorStore'
|
||||
|
||||
@@ -17,6 +17,8 @@ export function useUndoShortcuts(writable: boolean): void {
|
||||
// A text field keeps its own undo; a slider or a checkbox does not (R-13).
|
||||
if (isTextField(event.target)) return
|
||||
if (document.querySelector(MODAL_OPEN)) return
|
||||
// A12: undo is inactive during a creation, its dialog shown or not (R-13).
|
||||
if (useAnnotationWork.getState().creation) return
|
||||
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 'z')
|
||||
return
|
||||
event.preventDefault()
|
||||
|
||||
+476
-268
File diff suppressed because it is too large.
Load diff
+546
-292
File diff suppressed because it is too large.
Load diff
@@ -1,14 +1,24 @@
|
||||
@import 'tailwindcss';
|
||||
@import './tokens.css';
|
||||
|
||||
html, body, #root { height: 100%; }
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
/* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */
|
||||
html:has(dialog:modal) { overflow: hidden; }
|
||||
html:has(dialog:modal) {
|
||||
overflow: hidden;
|
||||
}
|
||||
/* The editor keeps its scrollbar width whatever opens or closes (R-2, A14): nothing moves. */
|
||||
html:has([data-editor-workspace]) { scrollbar-gutter: stable; }
|
||||
html:has([data-editor-workspace]) {
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
/* Nor does the browser's scroll anchoring move it: a side panel growing under a tap at the
|
||||
page's end scrolled the drawing under the finger (U2 Task 5 fix round, A14). */
|
||||
body:has([data-editor-workspace]) { overflow-anchor: none; }
|
||||
body:has([data-editor-workspace]) {
|
||||
overflow-anchor: none;
|
||||
}
|
||||
body {
|
||||
background: var(--color-bg);
|
||||
color: var(--color-ink);
|
||||
@@ -16,9 +26,24 @@ body {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.svg-canvas [data-state='current'] { fill: var(--color-accent) !important; fill-opacity: 0.85 !important; }
|
||||
.svg-canvas [data-anno-id] { cursor: pointer; }
|
||||
.svg-canvas [data-anno-id]:hover { filter: brightness(1.05); }
|
||||
.svg-canvas [data-state='current'] {
|
||||
fill: var(--color-accent) !important;
|
||||
fill-opacity: 0.85 !important;
|
||||
}
|
||||
.svg-canvas [data-anno-id] {
|
||||
cursor: pointer;
|
||||
}
|
||||
.svg-canvas [data-anno-id]:hover {
|
||||
filter: brightness(1.05);
|
||||
}
|
||||
/* A creation in progress (A12): the other markers are dimmed and read as unselectable. */
|
||||
.svg-canvas[data-creating] [data-anno-id] {
|
||||
opacity: 0.35;
|
||||
cursor: crosshair;
|
||||
}
|
||||
.svg-canvas[data-creating] [data-anno-id]:hover {
|
||||
filter: none;
|
||||
}
|
||||
|
||||
.zone-tooltip {
|
||||
position: absolute;
|
||||
@@ -30,7 +55,7 @@ body {
|
||||
white-space: nowrap;
|
||||
background: var(--color-ink);
|
||||
color: var(--color-bg);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,.18);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
|
||||
transition: opacity 120ms ease;
|
||||
z-index: 50;
|
||||
}
|
||||
Reference in new issue
Block a user