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.
358 lines
12 KiB
TypeScript
358 lines
12 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import type {
|
|
AnatomicalSheetDocument,
|
|
Annotation,
|
|
} from '@faunosteo/core-wasm/types'
|
|
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'
|
|
import AnnotationSection from '@/components/editor/annotations/sections/AnnotationSection'
|
|
import SelectionCommands from '@/components/editor/annotations/SelectionCommands'
|
|
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
|
|
import SelectionTag from '@/components/editor/annotations/SelectionTag'
|
|
import EditOnly from '@/components/editor/EditOnly'
|
|
import KeptPlace from '@/components/editor/KeptPlace'
|
|
import Button from '@/components/ui/Button'
|
|
import { ownedBy } from '@/editor/focusRequest'
|
|
import { useDeselect, useSelectionEscape } from '@/editor/annotations/deselect'
|
|
import {
|
|
useDialogOpening,
|
|
useLayerFollow,
|
|
type OpenDialog,
|
|
} from '@/editor/annotations/dialogOpening'
|
|
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
|
import { selectionLead } from '@/editor/annotations/stripLead'
|
|
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
|
|
import type { AnnotationSection as SectionId } from '@/editor/navigation'
|
|
import { usePlaceVisible } from '@/lib/placeVisibility'
|
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
import { useEditorStore } from '@/editor/state/editorStore'
|
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
|
import { useEditWidth } from '@/editor/useViewport'
|
|
import { useT } from '@/i18n/useT'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
|
|
export interface AnnotationsTabProps extends EditorPlaceProps {
|
|
/** The section shown: the drawing workspace, or a full-width section. */
|
|
section: SectionId
|
|
/** The sections shown at least once: each stays mounted. */
|
|
visited: readonly SectionId[]
|
|
onOpenSection: (section: SectionId, opener: HTMLElement) => void
|
|
onBack: () => void
|
|
}
|
|
|
|
/** A full-width section, once the document is loaded. */
|
|
function SectionPlace({
|
|
section,
|
|
readOnly,
|
|
focus,
|
|
onBack,
|
|
}: Pick<AnnotationsTabProps, 'readOnly' | 'focus' | 'onBack'> & {
|
|
section: Exclude<SectionId, 'drawing'>
|
|
}) {
|
|
const doc = useSheetDocument()
|
|
if (!doc) return null
|
|
return (
|
|
<AnnotationSection
|
|
section={section}
|
|
doc={doc}
|
|
readOnly={readOnly}
|
|
focus={focus}
|
|
onBack={onBack}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
const doc = useSheetDocument()
|
|
const preview = useEditorStore((s) => s.preview)
|
|
const { readOnly, navigate, onOpenSection, focus, annotationLayer } = props
|
|
const dialog = useDialogOpening(annotationLayer, readOnly)
|
|
const layerId = annotationLayer?.view?.id ?? null
|
|
const body = { navigate, onOpenSection, onOpen: dialog.open, layerId }
|
|
const ready = doc && preview
|
|
return (
|
|
<section
|
|
data-testid="editor-tab-annotations"
|
|
aria-label={t('editor.tab.annotations')}
|
|
className="min-h-24 space-y-3"
|
|
>
|
|
{ready && readOnly && (
|
|
<ReadOnlyAnnotations {...body} focus={focus} doc={doc} />
|
|
)}
|
|
{ready && (
|
|
<EditOnly readOnly={readOnly}>
|
|
<EditableAnnotations
|
|
{...body}
|
|
focus={readOnly ? undefined : focus}
|
|
doc={doc}
|
|
/>
|
|
</EditOnly>
|
|
)}
|
|
{doc && annotationLayer && (
|
|
<AnnotationDialog
|
|
layer={annotationLayer}
|
|
doc={doc}
|
|
readOnly={readOnly}
|
|
anchor={dialog.anchor}
|
|
returnFocus={dialog.returnFocus}
|
|
/>
|
|
)}
|
|
{doc && (
|
|
<CreationDialog doc={doc} readOnly={readOnly} anchor={dialog.anchor} />
|
|
)}
|
|
</section>
|
|
)
|
|
}
|
|
|
|
/** One kept section: the drawing workspace or a full-width section. */
|
|
function SectionBody(props: AnnotationsTabProps & { id: SectionId }) {
|
|
const { id, ...rest } = props
|
|
const focus = ownedBy(props.focus, `annotations.${id}`)
|
|
if (id === 'drawing') return <DrawingPlace {...rest} focus={focus} />
|
|
return <SectionPlace {...rest} section={id} focus={focus} />
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export default function AnnotationsTab(props: AnnotationsTabProps) {
|
|
return (
|
|
<>
|
|
{props.visited.map((id) => (
|
|
<KeptPlace
|
|
key={id}
|
|
name={`annotations.${id}`}
|
|
visible={id === props.section}
|
|
>
|
|
<SectionBody {...props} id={id} />
|
|
</KeptPlace>
|
|
))}
|
|
</>
|
|
)
|
|
}
|
|
|
|
/** The shown view is gone (an undo elsewhere): back to the main view, selection cleared. */
|
|
function useViewFallback(
|
|
doc: AnatomicalSheetDocument,
|
|
shown: string,
|
|
setViewId: (id: string) => void,
|
|
setSelectedId: (id: string | null) => void,
|
|
) {
|
|
useEffect(() => {
|
|
if (doc.views.some((view) => view.id === shown)) return
|
|
const main = mainViewId(doc)
|
|
if (!doc.views.some((view) => view.id === main)) return
|
|
setViewId(main)
|
|
setSelectedId(null)
|
|
}, [doc, shown, setViewId, setSelectedId])
|
|
}
|
|
|
|
/** What both read-only layouts get of the twin. */
|
|
interface TwinProps {
|
|
doc: AnatomicalSheetDocument
|
|
onOpenSection: AnnotationsTabProps['onOpenSection']
|
|
focus: EditorPlaceProps['focus']
|
|
onOpen: OpenDialog
|
|
layerId: string | null
|
|
}
|
|
|
|
/** The twin's selection, view and filter, kept in step with requests and the layer. */
|
|
function useTwinState({ doc, focus, layerId }: TwinProps) {
|
|
const [viewId, setViewId] = useState(mainViewId(doc))
|
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
|
const [filter, setFilter] = useState('')
|
|
useViewFallback(doc, viewId, setViewId, setSelectedId)
|
|
const show = (view: string, id: string) => {
|
|
setViewId(view)
|
|
setSelectedId(id)
|
|
}
|
|
useAnnotationRequest(focus, doc, { viewId, selectedId, busy: null, show })
|
|
const clear = () => setSelectedId(null)
|
|
useLayerFollow(layerId, doc, { viewId, selectedId, show, clear })
|
|
// A view of its own has its own list: the filter and the selection start over.
|
|
const showView = (id: string) => {
|
|
setViewId(id)
|
|
setSelectedId(null)
|
|
setFilter('')
|
|
}
|
|
return { viewId, selectedId, setSelectedId, filter, setFilter, showView }
|
|
}
|
|
|
|
/**
|
|
* The read-only strip at 1 024 px and wider (R-16, board 33 E): the selection with
|
|
* « fiche en lecture seule », then « Propriétés » and « Désélectionner »; nothing else.
|
|
*/
|
|
function ReadOnlyStrip({
|
|
selected,
|
|
doc,
|
|
onProperties,
|
|
onDeselect,
|
|
}: {
|
|
selected: Annotation | undefined
|
|
doc: AnatomicalSheetDocument
|
|
onProperties: () => void
|
|
onDeselect: () => void
|
|
}) {
|
|
const t = useT()
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const lead = selected
|
|
? selectionLead(selected, doc.views, { t, locale, readOnly: true })
|
|
: {
|
|
title: t('editor.annotations.strip.select'),
|
|
detail: '',
|
|
icon: 'select' as const,
|
|
}
|
|
return (
|
|
<EditStrip
|
|
lead={lead}
|
|
notice={null}
|
|
commandsKey={selected ? 'selected' : 'none'}
|
|
commands={
|
|
selected && (
|
|
<SelectionCommands
|
|
onProperties={onProperties}
|
|
onDeselect={onDeselect}
|
|
/>
|
|
)
|
|
}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Below 1 024 px (boards 14 and 16): the selection read inline in the stacked column. */
|
|
function InlineRead({
|
|
annotation,
|
|
doc,
|
|
onDeselect,
|
|
}: {
|
|
annotation: Annotation
|
|
doc: AnatomicalSheetDocument
|
|
onDeselect: () => void
|
|
}) {
|
|
const t = useT()
|
|
return (
|
|
<section
|
|
aria-label={t('editor.annotations.properties')}
|
|
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
|
>
|
|
<Button
|
|
type="button"
|
|
variant="secondary"
|
|
size="sm"
|
|
className="min-h-11"
|
|
onClick={onDeselect}
|
|
>
|
|
{t('editor.annotations.deselect')}
|
|
</Button>
|
|
<AnnotationReadBody annotation={annotation} doc={doc} />
|
|
</section>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* The read-only body shares the tab with the kept (hidden) edit body: whatever both
|
|
* render takes this prefix here, so no id repeats in the page.
|
|
*/
|
|
const READ_ONLY_IDS = 'ro-'
|
|
|
|
/**
|
|
* The read-only body: the same view browsable, nothing editable. At 1 024 px and wider
|
|
* the strip and the properties dialog as in the edit body, read-only (R-16); below, the
|
|
* read body inline.
|
|
*/
|
|
function ReadOnlyAnnotations(props: TwinProps) {
|
|
const { doc, onOpen } = props
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const preview = useEditorStore((s) => s.preview)
|
|
const handleVersion = useEditorStore((s) => s.handleVersion)
|
|
const wide = useEditWidth()
|
|
const twin = useTwinState(props)
|
|
const { viewId, selectedId, setSelectedId } = twin
|
|
const model = useViewModel(doc, viewId)
|
|
const view = doc.views.find((v) => v.id === viewId)
|
|
const selected = model.annotations.find((a) => a.id === selectedId)
|
|
const visible = usePlaceVisible()
|
|
const clear = () => setSelectedId(null)
|
|
const active = visible && selected !== undefined
|
|
const { asideRef, byDrawing } = useSelectionEscape(
|
|
selected?.id ?? null,
|
|
clear,
|
|
active,
|
|
)
|
|
const { byButton } = useDeselect(selected?.id ?? null, clear)
|
|
// A1: a second click (or the second of a double click) on the selection opens it.
|
|
const pick = (id: string) =>
|
|
wide && id === selectedId ? onOpen(id, 'drawing') : setSelectedId(id)
|
|
if (!preview || !view) return null
|
|
return (
|
|
<div className="space-y-3">
|
|
{wide && (
|
|
<ReadOnlyStrip
|
|
selected={selected}
|
|
doc={doc}
|
|
onProperties={() => selected && onOpen(selected.id, 'button')}
|
|
onDeselect={byButton}
|
|
/>
|
|
)}
|
|
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
|
<div className="min-w-0 space-y-3">
|
|
<ViewSwitcher
|
|
views={doc.views}
|
|
current={viewId}
|
|
onSelect={twin.showView}
|
|
/>
|
|
{selected && (
|
|
<SelectionTag
|
|
kind={selected.kind}
|
|
name={annotationName(selected, doc.views, locale)}
|
|
/>
|
|
)}
|
|
<CatalogueCanvas
|
|
key={handleVersion}
|
|
preview={preview}
|
|
viewId={viewId}
|
|
viewName={view.name[locale]}
|
|
selectedId={selectedId}
|
|
onAnnotation={pick}
|
|
onEmpty={byDrawing}
|
|
/>
|
|
</div>
|
|
<aside ref={asideRef} data-annotation-aside="read">
|
|
{!wide && selected ? (
|
|
<InlineRead annotation={selected} doc={doc} onDeselect={byButton} />
|
|
) : (
|
|
<OverviewPanel
|
|
doc={doc}
|
|
viewId={viewId}
|
|
idPrefix={READ_ONLY_IDS}
|
|
readOnly
|
|
filter={twin.filter}
|
|
onFilter={twin.setFilter}
|
|
onSelectView={twin.showView}
|
|
selectedId={selectedId}
|
|
onSelectAnnotation={setSelectedId}
|
|
onOpenAnnotation={(id) => onOpen(id, 'drawing')}
|
|
onOpenSection={props.onOpenSection}
|
|
/>
|
|
)}
|
|
</aside>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|