feat(editor): four tabs, Annotations sections, references from the header

U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.

R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
  Références clicked -> no « Plus »; below 640 px five others -> Général,
  Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
  header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
  VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
  target place/section/key (vertebrae tab -> annotations/regions); consumed
  context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
  (key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
  no_category text « (onglet Général) » -> « (Annotations, section
  Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
  CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
  references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
  ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
  + place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
  (edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
  showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
  label « general tab » -> « categories section »; tab Références ->
  openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
  Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
  tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
  openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry

Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
This commit is contained in:
bchanot committed 2026-11-06 20:25:35 +01:00
1 parent 95b1b7e461
commit bc2dba7c14
56 files changed
+2419 -699

No files matched your search

+13 -82
View File
@@ -2,40 +2,14 @@ import { useState } from 'react'
import { Link } from 'react-router-dom'
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
import Badge from '@/components/ui/Badge'
import Button from '@/components/ui/Button'
import Icon from '@/components/ui/Icon'
import Notice from '@/components/ui/Notice'
import { localized } from '@/admin/labels'
import { loadFailureMessage } from '@/editor/messages'
import type { EditorMode } from '@/editor/mode'
import { useEditorStore } from '@/editor/state/editorStore'
import { usePageHeading } from '@/app/usePageHeading'
import { useLocaleStore } from '@/state/localeStore'
import { useT } from '@/i18n/useT'
import ConfirmDialog from './ConfirmDialog'
type Translate = ReturnType<typeof useT>
interface Status {
copyIssue: 'cap' | 'quota' | null
saving: boolean
unsaved: boolean
revision: number
}
/** Board 04's line; only the copy failures replace it (the copy is temporary, this tab's). */
function statusText(t: Translate, status: Status): string {
if (status.copyIssue !== null)
return t(`editor.draft.status.copy_${status.copyIssue}`)
if (status.saving) return t('editor.draft.status.saving')
const revision = t('editor.draft.status.revision').replace(
'{revision}',
String(status.revision),
)
return status.unsaved
? `${revision} · ${t('editor.draft.status.unsaved')}`
: revision
}
import HeaderActions from './HeaderActions'
/** Breadcrumb of board 04: Administration › Fiches officielles › the sheet › the draft. */
function Breadcrumb({
@@ -71,42 +45,27 @@ function Breadcrumb({
}
/**
* The draft's header: title and badges, the revision line with the unsaved state, and in
* edit mode « Annuler les modifications » (confirmed) and « Enregistrer ». « Annuler les
* modifications » is the store's `discardChanges`; with an older base it reloads.
* The draft's header: breadcrumb, title and badges, then the actions (references, the
* save line, « Abandonner les modifications » and « Enregistrer » in edit mode).
*/
export default function DraftHeader({
sheet,
mode,
referencesOpen,
onToggleReferences,
}: {
sheet: OfficialSheetAdmin
mode: EditorMode
referencesOpen: boolean
onToggleReferences: (opener: HTMLElement) => void
}) {
const t = useT()
const heading = usePageHeading()
const unsaved = useEditorStore((s) => s.unsaved)
const saving = useEditorStore((s) => s.saving)
const blocked = useEditorStore((s) => s.recovery !== 'none')
const revision = useEditorStore((s) => s.savedRevision)
const copyIssue = useEditorStore((s) => s.copyIssue)
const [asking, setAsking] = useState(false)
const [failure, setFailure] = useState<string | null>(null)
const title = t('editor.draft.title').replace(
'{number}',
String(sheet.draft_version?.version_number ?? ''),
)
const discard = async () => {
setAsking(false)
const result = await useEditorStore
.getState()
.discardChanges({ confirmed: true })
setFailure(
!result.ok && result.reason === 'load'
? loadFailureMessage(t, result.failure)
: null,
)
}
return (
<header className="space-y-3">
<Breadcrumb sheet={sheet} title={title} />
@@ -126,42 +85,14 @@ export default function DraftHeader({
{t('editor.draft.read_only')}
</Badge>
)}
<p
role="status"
className="ml-auto text-sm text-[var(--color-ink-muted)]"
>
{statusText(t, { copyIssue, saving, unsaved, revision })}
</p>
{mode === 'edit' && (
<div className="flex flex-wrap gap-2">
<Button
type="button"
variant="secondary"
disabled={!unsaved || saving || blocked}
onClick={() => setAsking(true)}
>
{t('editor.draft.discard')}
</Button>
<Button
type="button"
disabled={!unsaved || saving || blocked}
onClick={() => void useEditorStore.getState().save()}
>
{t('common.save')}
</Button>
</div>
)}
<HeaderActions
editable={mode === 'edit'}
referencesOpen={referencesOpen}
onToggleReferences={onToggleReferences}
onFailure={setFailure}
/>
</div>
{failure && <Notice tone="error">{failure}</Notice>}
<ConfirmDialog
open={asking}
title={t('editor.draft.discard')}
body={t('editor.draft.discard_ask')}
confirmLabel={t('editor.draft.discard_confirm')}
cancelLabel={t('common.cancel')}
onConfirm={() => void discard()}
onCancel={() => setAsking(false)}
/>
</header>
)
}
@@ -1,28 +1,53 @@
import type { ComponentType } from 'react'
import type { EditorTabId, EditorTabProps } from '@/editor/tabs'
import type { AnnotationSection } from '@/editor/navigation'
import {
panelDomId,
type EditorPlaceProps,
type EditorTabId,
} from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import AnnotationsTab from './tabs/AnnotationsTab'
import FindingsTab from './tabs/FindingsTab'
import GeneralTab from './tabs/GeneralTab'
import ReferencesTab from './tabs/ReferencesTab'
import VerificationTab from './tabs/VerificationTab'
import VertebraeTab from './tabs/VertebraeTab'
import ViewsTab from './tabs/ViewsTab'
/** One component per tab (Lots F-J fill them); only the active one is mounted. */
const BODIES: Record<EditorTabId, ComponentType<EditorTabProps>> = {
const BODIES: Record<
Exclude<EditorTabId, 'annotations'>,
ComponentType<EditorPlaceProps>
> = {
general: GeneralTab,
views: ViewsTab,
annotations: AnnotationsTab,
findings: FindingsTab,
references: ReferencesTab,
vertebrae: VertebraeTab,
verification: VerificationTab,
}
export default function EditorTabBody({
tab,
...props
}: EditorTabProps & { tab: EditorTabId }) {
const Body = BODIES[tab]
return <Body {...props} />
/** What only the Annotations tab needs beyond the common place props. */
export interface AnnotationNav {
section: AnnotationSection
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
onBack: () => void
}
interface Props extends EditorPlaceProps {
tab: EditorTabId
annotations: AnnotationNav
}
/** The panel of the active tab; a place unmounts when left (kept alive in Lot B2). */
export default function EditorTabBody({ tab, annotations, ...props }: Props) {
const t = useT()
const Body = tab === 'annotations' ? null : BODIES[tab]
return (
<div
id={panelDomId(tab)}
role="tabpanel"
aria-label={t(`editor.tab.${tab}`)}
data-place={Body ? tab : undefined}
>
{Body ? (
<Body {...props} />
) : (
<AnnotationsTab {...props} {...annotations} />
)}
</div>
)
}
+95 -65
View File
@@ -1,12 +1,16 @@
import { useState, type KeyboardEvent } from 'react'
import { useEditorStore } from '@/editor/state/editorStore'
import { tabsFor, type EditorTabId } from '@/editor/tabs'
import { usePlural } from '@/editor/plural'
import {
MORE_BUTTON_ID,
panelDomId,
tabDomId,
tabsFor,
type EditorTabId,
} from '@/editor/tabs'
import type { TabTier } from '@/editor/useViewport'
import { useT } from '@/i18n/useT'
export const PANEL_ID = 'editor-panel'
export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}`
const BASE =
'min-h-11 whitespace-nowrap border-b-2 px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
const ACTIVE =
@@ -14,8 +18,9 @@ const ACTIVE =
const IDLE =
'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]'
/** The blocking-error count on the Vérification tab; absent at zero. */
/** The blocking-error count on the Vérification tab, as text; absent at zero. */
function ErrorCount({ tab }: { tab: EditorTabId }) {
const plural = usePlural()
const count = useEditorStore(
(s) =>
s.previewState?.report.issues.filter((i) => i.severity === 'error')
@@ -23,35 +28,24 @@ function ErrorCount({ tab }: { tab: EditorTabId }) {
)
if (tab !== 'verification' || count === 0) return null
return (
<span
aria-hidden="true"
className="ml-2 rounded-md bg-red-50 px-1.5 text-xs text-red-700"
>
{count}
</span>
<>
{' '}
<span className="ml-1 rounded-md bg-red-50 px-1.5 text-xs text-red-700">
{plural('editor.tab.errors', count)}
</span>
</>
)
}
interface EditorTabsProps {
interface TabListProps {
shown: readonly EditorTabId[]
active: EditorTabId
tier: TabTier
onSelect: (tab: EditorTabId) => void
}
/**
* The draft's tabs (boards 04 and 05): all seven wide, the static lists of 640 px and over
* and below it narrow, with « Plus » opening a disclosure of the others (no measurement).
*/
export default function EditorTabs({
active,
tier,
onSelect,
}: EditorTabsProps) {
/** The tablist proper: the shown tabs only, arrows move between them. */
function TabList({ shown, active, onSelect }: TabListProps) {
const t = useT()
const { shown, more } = tabsFor(tier)
const [open, setOpen] = useState(false)
const moreActive = more.includes(active)
const onKeyDown = (event: KeyboardEvent) => {
const at = shown.indexOf(active)
const step =
@@ -62,53 +56,63 @@ export default function EditorTabs({
onSelect(next)
document.getElementById(tabDomId(next))?.focus()
}
return (
<div
role="tablist"
aria-label={t('editor.tab.list')}
onKeyDown={onKeyDown}
className="flex gap-1"
>
{shown.map((tab) => (
<button
key={tab}
id={tabDomId(tab)}
type="button"
role="tab"
aria-selected={tab === active}
aria-controls={panelDomId(tab)}
tabIndex={tab === active ? 0 : -1}
onClick={() => onSelect(tab)}
className={`-mb-px ${BASE} ${tab === active ? ACTIVE : IDLE}`}
>
{t(`editor.tab.${tab}`)}
<ErrorCount tab={tab} />
</button>
))}
</div>
)
}
interface MoreTabsProps {
more: readonly EditorTabId[]
active: EditorTabId
onSelect: (tab: EditorTabId) => void
}
/** Below 640 px: « Plus » and its disclosure of the tabs that do not fit. */
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
const t = useT()
const [open, setOpen] = useState(false)
const pick = (tab: EditorTabId) => {
onSelect(tab)
setOpen(false)
}
return (
<div>
<div className="flex items-end gap-1 overflow-x-auto border-b border-[var(--color-border)]">
<div
role="tablist"
aria-label={t('editor.tab.list')}
onKeyDown={onKeyDown}
className="flex gap-1"
>
{shown.map((tab) => (
<button
key={tab}
id={tabDomId(tab)}
type="button"
role="tab"
aria-selected={tab === active}
aria-controls={PANEL_ID}
tabIndex={tab === active ? 0 : -1}
onClick={() => onSelect(tab)}
className={`-mb-px ${BASE} ${tab === active ? ACTIVE : IDLE}`}
>
{t(`editor.tab.${tab}`)}
<ErrorCount tab={tab} />
</button>
))}
</div>
{more.length > 0 && (
<button
type="button"
aria-expanded={open}
aria-controls="editor-tabs-more"
onClick={() => setOpen((value) => !value)}
className={`-mb-px ${BASE} ${moreActive ? ACTIVE : IDLE}`}
>
{t('editor.tab.more')}
</button>
)}
</div>
<>
<button
id={MORE_BUTTON_ID}
type="button"
aria-expanded={open}
aria-controls="editor-tabs-more"
onClick={() => setOpen((value) => !value)}
className={`-mb-px ${BASE} ${more.includes(active) ? ACTIVE : IDLE}`}
>
{t('editor.tab.more')}
</button>
{open && (
<ul
id="editor-tabs-more"
className="flex flex-wrap gap-1 border-b border-[var(--color-border)] py-1"
className="order-last flex w-full flex-wrap gap-1 border-t border-[var(--color-border)] py-1"
>
{more.map((tab) => (
<li key={tab}>
@@ -126,6 +130,32 @@ export default function EditorTabs({
))}
</ul>
)}
</>
)
}
interface EditorTabsProps {
active: EditorTabId
tier: TabTier
onSelect: (tab: EditorTabId) => void
}
/**
* The draft's tab row (boards 04 and 05): the four tabs from 640 px, Annotations and
* Vérification below it with « Plus » opening a disclosure of the others (no measurement).
*/
export default function EditorTabs({
active,
tier,
onSelect,
}: EditorTabsProps) {
const { shown, more } = tabsFor(tier)
return (
<div className="flex flex-wrap items-end gap-1 border-b border-[var(--color-border)]">
<TabList shown={shown} active={active} onSelect={onSelect} />
{more.length > 0 && (
<MoreTabs more={more} active={active} onSelect={onSelect} />
)}
</div>
)
}
@@ -0,0 +1,115 @@
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
import Notice from '@/components/ui/Notice'
import {
AnnounceContext,
FocusConsumedContext,
ownedBy,
type PlaceName,
} from '@/editor/focusRequest'
import { saveFailureMessage } from '@/editor/messages'
import type { EditorMode } from '@/editor/mode'
import type { NavigationState } from '@/editor/navigation'
import { useEditorStore } from '@/editor/state/editorStore'
import { initialTab } from '@/editor/tabs'
import { useEditorNavigation } from '@/editor/useEditorNavigation'
import type { TabTier } from '@/editor/useViewport'
import { useT } from '@/i18n/useT'
import ConflictDialog from './ConflictDialog'
import CopyIssueNotice from './CopyIssueNotice'
import DraftHeader from './DraftHeader'
import EditorTabBody from './EditorTabBody'
import EditorTabs from './EditorTabs'
import ModeNotice from './ModeNotice'
import RecoveryNotice from './RecoveryNotice'
import ReferencesPanel from './references/ReferencesPanel'
interface Props {
sheet: OfficialSheetAdmin
mode: EditorMode
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
readOnly: boolean
tier: TabTier
reloadSheet: () => void
}
/** A refused save under the header, phrased from the closed kind and the copy's real flag. */
function SaveFailureNotice() {
const t = useT()
const failure = useEditorStore((s) => s.saveFailure)
const unsaved = useEditorStore((s) => s.unsaved)
const copyWritten = useEditorStore((s) => s.copyWritten)
const conflictOpen = useEditorStore((s) => s.conflict !== null)
if (failure === null || (failure === 'draft_conflict' && conflictOpen))
return null
return (
<Notice tone="error">
{saveFailureMessage(t, failure, { unsaved, copyWritten })}
</Notice>
)
}
/** The `data-place` the shown tab and section name. */
function shownPlace({ tab, section }: NavigationState): PlaceName {
return tab === 'annotations' ? `annotations.${section}` : tab
}
/**
* The draft page once the version is ready: header, notices, tab row, the references
* panel and the shown place. Owns the navigation state, so the first tab is known at
* mount (`initialTab`) and later edits never move the user off their tab.
*/
export default function EditorWorkspace(props: Props) {
const { sheet, mode, readOnly, tier, reloadSheet } = props
const previewState = useEditorStore((s) => s.previewState)
const nav = useEditorNavigation(
previewState ? initialTab(previewState, tier) : 'annotations',
)
const { state } = nav
const toggleReferences = (opener: HTMLElement) =>
state.references.open
? nav.closeReferences()
: nav.openReferences(null, opener)
return (
<div className="space-y-4">
<DraftHeader
sheet={sheet}
mode={mode}
referencesOpen={state.references.open}
onToggleReferences={toggleReferences}
/>
<ModeNotice mode={mode} sheet={sheet} />
<SaveFailureNotice />
<RecoveryNotice />
<CopyIssueNotice />
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
<FocusConsumedContext value={nav.consumed}>
<AnnounceContext value={nav.announce}>
{state.referencesMounted && (
<ReferencesPanel
readOnly={readOnly}
focus={ownedBy(state.focus, 'references')}
open={state.references.open}
onClose={nav.closeReferences}
/>
)}
<EditorTabBody
tab={state.tab}
readOnly={readOnly}
navigate={nav.navigate}
focus={ownedBy(state.focus, shownPlace(state))}
reloadSheet={reloadSheet}
annotations={{
section: state.section,
onOpenSection: nav.openSection,
onBack: nav.backToDrawing,
}}
/>
</AnnounceContext>
</FocusConsumedContext>
<p aria-live="polite" className="sr-only">
{nav.live}
</p>
<ConflictDialog />
</div>
)
}
@@ -0,0 +1,106 @@
import { useState } from 'react'
import Button from '@/components/ui/Button'
import Icon from '@/components/ui/Icon'
import { loadFailureMessage } from '@/editor/messages'
import { useEditorStore } from '@/editor/state/editorStore'
import { REFERENCES_BUTTON_ID } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import ConfirmDialog from './ConfirmDialog'
import SaveLine from './SaveLine'
interface Props {
/** Edit mode: « Abandonner » and « Enregistrer » are offered. */
editable: boolean
referencesOpen: boolean
onToggleReferences: (opener: HTMLElement) => void
/** A failed reload after a discard, worded for the notice under the header. */
onFailure: (message: string | null) => void
}
/** « Abandonner les modifications »: asks first, then the store reloads the server draft. */
function DiscardButton({ onFailure }: Pick<Props, 'onFailure'>) {
const t = useT()
const unsaved = useEditorStore((s) => s.unsaved)
const saving = useEditorStore((s) => s.saving)
const blocked = useEditorStore((s) => s.recovery !== 'none')
const [asking, setAsking] = useState(false)
const discard = async () => {
setAsking(false)
const result = await useEditorStore
.getState()
.discardChanges({ confirmed: true })
onFailure(
!result.ok && result.reason === 'load'
? loadFailureMessage(t, result.failure)
: null,
)
}
return (
<>
<Button
type="button"
variant="secondary"
disabled={!unsaved || saving || blocked}
onClick={() => setAsking(true)}
>
{t('editor.draft.discard')}
</Button>
<ConfirmDialog
open={asking}
title={t('editor.draft.discard')}
body={t('editor.draft.discard_ask')}
confirmLabel={t('editor.draft.discard_confirm')}
cancelLabel={t('common.cancel')}
onConfirm={() => void discard()}
onCancel={() => setAsking(false)}
/>
</>
)
}
function SaveButton() {
const t = useT()
const unsaved = useEditorStore((s) => s.unsaved)
const saving = useEditorStore((s) => s.saving)
const blocked = useEditorStore((s) => s.recovery !== 'none')
return (
<Button
type="button"
disabled={!unsaved || saving || blocked}
onClick={() => void useEditorStore.getState().save()}
>
{t('common.save')}
</Button>
)
}
/** The right group of the header: references, the save line, discard and save. */
export default function HeaderActions(props: Props) {
const t = useT()
return (
<div className="ml-auto flex flex-wrap items-center gap-2">
<Button
id={REFERENCES_BUTTON_ID}
type="button"
variant="secondary"
aria-expanded={props.referencesOpen}
aria-controls="editor-references-panel"
onClick={(event) => props.onToggleReferences(event.currentTarget)}
>
<Icon name="book" size={16} className="mr-2" />
{t('editor.references.open')}
</Button>
<span
aria-hidden="true"
className="hidden h-6 w-px bg-[var(--color-border)] sm:block"
/>
<SaveLine />
{props.editable && (
<>
<DiscardButton onFailure={props.onFailure} />
<SaveButton />
</>
)}
</div>
)
}
@@ -0,0 +1,39 @@
import { useEditorStore } from '@/editor/state/editorStore'
import { useT } from '@/i18n/useT'
type Translate = ReturnType<typeof useT>
interface Status {
copyIssue: 'cap' | 'quota' | null
saving: boolean
unsaved: boolean
revision: number
}
/** Board 04's line; only the copy failures replace it (the copy is temporary, this tab's). */
function statusText(t: Translate, status: Status): string {
if (status.copyIssue !== null)
return t(`editor.draft.status.copy_${status.copyIssue}`)
if (status.saving) return t('editor.draft.status.saving')
const revision = t('editor.draft.status.revision').replace(
'{revision}',
String(status.revision),
)
return status.unsaved
? `${revision} · ${t('editor.draft.status.unsaved')}`
: revision
}
/** The revision line with its unsaved state, announced politely when it changes. */
export default function SaveLine() {
const t = useT()
const unsaved = useEditorStore((s) => s.unsaved)
const saving = useEditorStore((s) => s.saving)
const revision = useEditorStore((s) => s.savedRevision)
const copyIssue = useEditorStore((s) => s.copyIssue)
return (
<p role="status" className="text-sm text-[var(--color-ink-muted)]">
{statusText(t, { copyIssue, saving, unsaved, revision })}
</p>
)
}
@@ -87,7 +87,13 @@ export default function CreationPanel(props: CreationPanelProps) {
data-testid="annotation-creation"
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
>
<h3 className="text-base font-semibold">{title}</h3>
<h3
tabIndex={-1}
data-creation-heading
className="outline-none text-base font-semibold"
>
{title}
</h3>
<CreationFields
kind={pending.kind}
viewId={props.viewId}
@@ -1,10 +1,10 @@
import { useReducer, useState, type Dispatch } from 'react'
import { useEffect, useReducer, useState, type Dispatch } from 'react'
import type {
AnatomicalSheetDocument,
Annotation,
} from '@faunosteo/core-wasm/types'
import type { CommitContext } from '@/editor/annotations/annotationCommit'
import { annotationFocus } from '@/editor/annotations/focusTarget'
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
import { parseFrame, type Frame } from '@/editor/annotations/frame'
import { isEditable } from '@/editor/annotations/geometryEdit'
@@ -22,14 +22,15 @@ import {
useViewModel,
type ViewModel,
} from '@/editor/annotations/useViewModel'
import { useFocusRequest } from '@/editor/focusRequest'
import type { EditorTabProps } from '@/editor/tabs'
import type { AnnotationSection } from '@/editor/navigation'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import AnnotationCanvas from './AnnotationCanvas'
import AnnotationList, { annotationName } from './AnnotationList'
import CreationPanel from './CreationPanel'
import KeyboardAdd from './KeyboardAdd'
import OverviewPanel from './OverviewPanel'
import PropertiesPanel, { UnmeasuredHint } from './PropertiesPanel'
import SelectionTag from './SelectionTag'
import TracingBar from './TracingBar'
@@ -37,8 +38,9 @@ import ViewSwitcher from './ViewSwitcher'
interface Props {
doc: AnatomicalSheetDocument
onSelectTab: EditorTabProps['onSelectTab']
focus: EditorTabProps['focus']
navigate: EditorPlaceProps['navigate']
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
focus: EditorPlaceProps['focus']
}
/** What both columns read: the tab's state, the view, its frame and its selection. */
@@ -52,21 +54,46 @@ interface Scene {
frame: Frame | null
selected: Annotation | undefined
setRoot: (root: RootAttributes | null) => void
onSelectTab: EditorTabProps['onSelectTab']
navigate: EditorPlaceProps['navigate']
onOpenSection: Props['onOpenSection']
}
function useScene({ doc, onSelectTab, focus }: Props): 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.
*/
function useViewFallback(
doc: AnatomicalSheetDocument,
shown: string | null,
dispatch: Dispatch<UiAction>,
) {
useEffect(() => {
if (shown === null || doc.views.some((view) => view.id === shown)) return
const main = mainViewId(doc)
if (doc.views.some((view) => view.id === main)) {
dispatch({ type: 'view', viewId: main })
}
}, [doc, shown, dispatch])
}
function useScene({ doc, navigate, onOpenSection, focus }: Props): Scene {
const [ui, dispatch] = useReducer(uiReducer, initialUi)
useFocusRequest(focus, (key) => {
const target = annotationFocus(doc, key)
if (!target) return
dispatch({ type: 'view', viewId: target.viewId })
dispatch({ type: 'select', id: target.annotationId })
})
const [root, setRoot] = useState<RootAttributes | null>(null)
const viewId = ui.viewId ?? mainViewId(doc)
const model = useViewModel(doc, viewId)
const own = model.measured && root?.viewId === viewId
useViewFallback(doc, ui.viewId, dispatch)
useAnnotationRequest(focus, doc, {
viewId,
selectedId: ui.selectedId,
busy: ui.pending ? 'creation' : ui.tracing ? 'tracing' : null,
show: (view, id) => {
dispatch({ type: 'view', viewId: view })
dispatch({ type: 'select', id })
},
})
return {
doc,
ui,
@@ -76,7 +103,8 @@ function useScene({ doc, onSelectTab, focus }: Props): Scene {
frame: own ? parseFrame(root.viewBox) : null,
selected: model.annotations.find((a) => a.id === ui.selectedId),
setRoot,
onSelectTab,
navigate,
onOpenSection,
}
}
@@ -123,7 +151,8 @@ function CanvasColumn({
hint={ui.hint}
model={model}
noCategory={noCategory}
onSelectTab={scene.onSelectTab}
viewId={scene.viewId}
navigate={scene.navigate}
/>
{selected && <TagOf annotation={selected} doc={doc} />}
<CanvasStage scene={scene} placement={placement} />
@@ -217,7 +246,6 @@ function SidePanel({
scene: Scene
context: CommitContext
}) {
const t = useT()
const { doc, ui, dispatch, model, frame, selected } = scene
if (ui.pending) {
return (
@@ -234,9 +262,13 @@ function SidePanel({
}
if (!selected) {
return (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.annotations.select_hint')}
</p>
<OverviewPanel
doc={doc}
viewId={scene.viewId}
readOnly={false}
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
onOpenSection={scene.onOpenSection}
/>
)
}
return (
@@ -248,7 +280,7 @@ function SidePanel({
geometryLocked={!model.measured}
dispatch={dispatch}
context={context}
onSelectTab={scene.onSelectTab}
navigate={scene.navigate}
/>
)
}
@@ -284,20 +316,24 @@ function ToolNotes({
hint,
model,
noCategory,
onSelectTab,
viewId,
navigate,
}: {
tool: ToolId
hint: string | null
model: ViewModel
noCategory: boolean
onSelectTab: EditorTabProps['onSelectTab']
viewId: string
navigate: EditorPlaceProps['navigate']
}) {
const t = useT()
const linkBlocked = tool === 'link' && model.children.length === 0
return (
<div className="space-y-1 text-sm text-[var(--color-ink-muted)]">
<p>{t(`editor.annotations.tool_hint.${tool}`)}</p>
{!model.measured && <UnmeasuredHint onSelectTab={onSelectTab} />}
{!model.measured && (
<UnmeasuredHint navigate={navigate} viewId={viewId} />
)}
{noCategory && <p>{t('editor.annotations.no_category')}</p>}
{linkBlocked && <p>{t('editor.annotations.no_child_view')}</p>}
{hint && (
@@ -0,0 +1,190 @@
import type {
AnatomicalSheetDocument,
SheetView,
} from '@faunosteo/core-wasm/types'
import { useOverviewCounts } from '@/editor/annotations/overview'
import type { AnnotationSection } from '@/editor/navigation'
import { usePlural } from '@/editor/plural'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
const CARD = 'space-y-2 rounded-xl border border-[var(--color-border)] p-4'
const TITLE = 'text-sm font-semibold'
const ROW =
'flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
const ENTRY =
'inline-flex min-h-11 items-center rounded-lg border border-[var(--color-border)] px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
export interface OverviewPanelProps {
doc: AnatomicalSheetDocument
/** The view the canvas shows. */
viewId: string
/** Read-only modes only consult: the entries read « Voir … ». */
readOnly: boolean
onSelectView: (viewId: string) => void
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
}
function SectionEntry({
section,
label,
onOpen,
}: {
section: AnnotationSection
label: string
onOpen: OverviewPanelProps['onOpenSection']
}) {
return (
<button
type="button"
data-section-entry={section}
onClick={(event) => onOpen(section, event.currentTarget)}
className={ENTRY}
>
{label}
</button>
)
}
function ViewRow({
view,
current,
count,
onSelect,
}: {
view: SheetView
current: boolean
count: number
onSelect: () => void
}) {
const t = useT()
const plural = usePlural()
const locale = useLocaleStore((s) => s.locale)
return (
<li>
<button
type="button"
aria-current={current}
onClick={onSelect}
className={`${ROW} ${current ? 'bg-[var(--color-surface-strong)]' : ''}`}
>
<span className="min-w-0">
<span className="block truncate font-medium">
{view.name[locale]}
</span>
<span className="text-[var(--color-ink-muted)]">
{t(
view.kind === 'main'
? 'editor.overview.view_main'
: 'editor.overview.view_detail',
)}
</span>
</span>
<span className="shrink-0 text-[var(--color-ink-muted)]">
{plural('editor.overview.annotations', count)}
</span>
</button>
</li>
)
}
function ViewsCard(props: OverviewPanelProps) {
const t = useT()
const { doc, viewId, readOnly, onSelectView, onOpenSection } = props
const counts = useOverviewCounts(doc)
return (
<section aria-labelledby="overview-views" className={CARD}>
<h3 id="overview-views" className={TITLE}>
{t('editor.overview.views')}
</h3>
<ul>
{doc.views.map((view) => (
<ViewRow
key={view.id}
view={view}
current={view.id === viewId}
count={counts.annotationsByView.get(view.id) ?? 0}
onSelect={() => onSelectView(view.id)}
/>
))}
</ul>
<SectionEntry
section="views"
label={t(
readOnly
? 'editor.overview.see_views'
: 'editor.overview.manage_views',
)}
onOpen={onOpenSection}
/>
</section>
)
}
function CategoriesCard(props: OverviewPanelProps) {
const t = useT()
const plural = usePlural()
const locale = useLocaleStore((s) => s.locale)
const { doc, readOnly, onOpenSection } = props
const counts = useOverviewCounts(doc)
return (
<section aria-labelledby="overview-categories" className={CARD}>
<h3 id="overview-categories" className={TITLE}>
{t('editor.overview.categories')}
</h3>
{doc.categories.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.overview.categories_empty')}
</p>
)}
<ul className="flex flex-wrap gap-2">
{doc.categories.map((category) => (
<li
key={category.id}
className="inline-flex items-center gap-2 rounded-full border border-[var(--color-border)] px-3 py-1 text-sm"
>
<span
aria-hidden="true"
className="size-3 rounded-full border border-[var(--color-border)]"
style={{ backgroundColor: category.color ?? undefined }}
/>
{category.name[locale]}
</li>
))}
</ul>
<div className="flex flex-wrap gap-2">
<SectionEntry
section="categories"
label={t(
readOnly
? 'editor.overview.see_categories'
: 'editor.overview.edit_categories',
)}
onOpen={onOpenSection}
/>
{/* T17 / BDR-102: no vertebra role exists before U6, so this entry is always shown. */}
<SectionEntry
section="regions"
label={plural('editor.overview.regions', counts.regions)}
onOpen={onOpenSection}
/>
</div>
</section>
)
}
/** Board 01's overview: the views and the categories, with the entries to their sections. */
export default function OverviewPanel(props: OverviewPanelProps) {
const t = useT()
return (
<div
role="region"
aria-label={t('editor.overview.label')}
data-testid="annotation-overview"
className="space-y-3"
>
<ViewsCard {...props} />
<CategoriesCard {...props} />
</div>
)
}
@@ -15,7 +15,8 @@ import {
import { isEditable } from '@/editor/annotations/geometryEdit'
import type { UiAction } from '@/editor/annotations/uiState'
import { geometryErrorsById } from '@/editor/issues'
import type { EditorTabId } from '@/editor/tabs'
import { targetOfKey } from '@/editor/navigation'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useEditCommand } from '@/editor/useEditCommand'
import { useEditorStore } from '@/editor/state/editorStore'
import { useT } from '@/i18n/useT'
@@ -35,7 +36,7 @@ export interface PropertiesPanelProps {
geometryLocked: boolean
dispatch: Dispatch<UiAction>
context: CommitContext
onSelectTab: (tab: EditorTabId) => void
navigate: EditorPlaceProps['navigate']
}
/** What still names this annotation as invalid: never hidden, never shown as valid. */
@@ -58,7 +59,11 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
>
<header className="flex items-start justify-between gap-2">
<h3 className="text-base font-semibold">
<h3
tabIndex={-1}
data-properties-heading
className="outline-none text-base font-semibold"
>
{t(`editor.annotations.kind.${annotation.kind}`)}
</h3>
<ReviewBadge status={annotation.review_status} />
@@ -83,7 +88,9 @@ function GeometrySection(props: PropertiesPanelProps) {
const { geometry } = annotation
return (
<div className="space-y-2">
{geometryLocked && !readOnly && <UnmeasuredHint {...props} />}
{geometryLocked && !readOnly && (
<UnmeasuredHint navigate={props.navigate} viewId={annotation.view_id} />
)}
{isEditable(geometry) ? (
<GeometryGroup
key={annotation.id}
@@ -156,9 +163,11 @@ function GeometryIssues({ id }: { id: string }) {
)
}
/** Points to the views section, on the view whose drawing cannot be measured. */
export function UnmeasuredHint({
onSelectTab,
}: Pick<PropertiesPanelProps, 'onSelectTab'>) {
navigate,
viewId,
}: Pick<PropertiesPanelProps, 'navigate'> & { viewId: string }) {
const t = useT()
return (
<p className="text-sm text-[var(--color-ink-muted)]">
@@ -166,9 +175,14 @@ export function UnmeasuredHint({
<button
type="button"
className="underline"
onClick={() => onSelectTab('views')}
onClick={(event) =>
navigate(
targetOfKey({ kind: 'view', id: viewId }),
event.currentTarget,
)
}
>
{t('editor.tab.views')}
{t('editor.place.views')}
</button>
</p>
)
@@ -15,7 +15,11 @@ export default function TracingBar({
const t = useT()
const plural = usePlural()
return (
<div className="flex flex-wrap items-center gap-2">
<div
tabIndex={-1}
data-testid="tracing-bar"
className="flex flex-wrap items-center gap-2 outline-none"
>
<p className="text-sm text-[var(--color-ink-muted)]">
{plural('editor.annotations.tracing', count)}
</p>
@@ -0,0 +1,51 @@
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import Button from '@/components/ui/Button'
import type { FocusRequest } from '@/editor/focusRequest'
import type { AnnotationSection as SectionId } from '@/editor/navigation'
import { useT } from '@/i18n/useT'
import { ANNOTATION_SECTION_BODIES } from './registry'
interface Props {
section: Exclude<SectionId, 'drawing'>
doc: AnatomicalSheetDocument
readOnly: boolean
focus?: FocusRequest
onBack: () => void
}
/**
* A full-width Annotations section: « Retour au dessin » first, then its heading, then
* the body. The registry names the body, so a section is replaced without touching this
* frame or the navigation.
*/
export default function AnnotationSection({
section,
doc,
readOnly,
focus,
onBack,
}: Props) {
const t = useT()
const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section]
const headingId = `annotation-section-${section}-title`
return (
<section
data-place={`annotations.${section}`}
aria-labelledby={headingId}
className="space-y-4"
>
<Button type="button" variant="secondary" size="sm" onClick={onBack}>
{t('editor.section.back')}
</Button>
<h2
id={headingId}
tabIndex={-1}
data-place-heading
className="outline-none text-xl font-semibold"
>
{t(titleKey)}
</h2>
<Body doc={doc} readOnly={readOnly} focus={focus} />
</section>
)
}
@@ -5,13 +5,19 @@ import DeleteDialog, {
import RegionForm from '@/components/editor/vertebrae/RegionForm'
import RegionRow from '@/components/editor/vertebrae/RegionRow'
import { useRowFocus } from '@/editor/focusRequest'
import type { SectionBodyProps } from './registry'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
/** Vertèbres: the vertebral regions (code, names, count, optional range), ordered. */
export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
/**
* Annotations, section Régions vertébrales: the regions (code, names, count, optional
* range), ordered. The level-1 editor, until the vertebra role replaces it (U6).
*/
export default function RegionsSection({
readOnly,
focus,
}: Pick<SectionBodyProps, 'readOnly' | 'focus'>) {
const t = useT()
useRowFocus(focus)
const locale = useLocaleStore((s) => s.locale)
@@ -19,11 +25,7 @@ export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const regions = doc?.vertebral_config.regions ?? []
return (
<section
data-testid="editor-tab-vertebrae"
aria-label={t('editor.tab.vertebrae')}
className="min-h-24 space-y-3"
>
<div data-testid="editor-section-regions" className="min-h-24 space-y-3">
{doc && regions.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.vertebra.empty')}
@@ -48,6 +50,6 @@ export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
</ul>
{doc && !readOnly && <RegionForm />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
</div>
)
}
@@ -6,16 +6,19 @@ import DetailViewForm from '@/components/editor/views/DetailViewForm'
import DetailViewRow from '@/components/editor/views/DetailViewRow'
import MainViewCard from '@/components/editor/views/MainViewCard'
import { useRowFocus } from '@/editor/focusRequest'
import type { SectionBodyProps } from './registry'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
/**
* Vues et illustrations: the main view and its drawing, the detail views (parent, own
* drawing or crop), the upload of a drawing and the frame changes it brings.
* Annotations, section Vues: the main view and its drawing, the detail views (parent,
* own drawing or crop), the upload of a drawing and the frame changes it brings.
*/
export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
export default function ViewsSection({
readOnly,
focus,
}: Pick<SectionBodyProps, 'readOnly' | 'focus'>) {
const t = useT()
useRowFocus(focus)
const locale = useLocaleStore((s) => s.locale)
@@ -26,11 +29,7 @@ export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
const main = views.find((view) => view.kind === 'main')
const details = views.filter((view) => view.kind === 'detail')
return (
<section
data-testid="editor-tab-views"
aria-label={t('editor.tab.views')}
className="min-h-24 space-y-4"
>
<div data-testid="editor-section-views" className="min-h-24 space-y-4">
{main?.kind === 'main' && (
<MainViewCard view={main} readOnly={readOnly} />
)}
@@ -64,6 +63,6 @@ export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
</ul>
{doc && !readOnly && <DetailViewForm views={views} />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
</div>
)
}
@@ -0,0 +1,29 @@
import type { ComponentType } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import CategoriesSection from '@/components/editor/general/CategoriesSection'
import type { FocusRequest } from '@/editor/focusRequest'
import type { AnnotationSection } from '@/editor/navigation'
import RegionsSection from './RegionsSection'
import ViewsSection from './ViewsSection'
/** What every section body receives from its frame. */
export interface SectionBodyProps {
doc: AnatomicalSheetDocument
readOnly: boolean
focus?: FocusRequest
}
type SectionName = Exclude<AnnotationSection, 'drawing'>
/**
* The one place later steps edit: U3 replaces `categories`, U4 replaces `views`, U6 adds
* the vertebra-role path and removes `regions` once the role exists.
*/
export const ANNOTATION_SECTION_BODIES: Record<
SectionName,
{ titleKey: string; Body: ComponentType<SectionBodyProps> }
> = {
views: { titleKey: 'editor.place.views', Body: ViewsSection },
categories: { titleKey: 'editor.place.categories', Body: CategoriesSection },
regions: { titleKey: 'editor.place.regions', Body: RegionsSection },
}
@@ -12,6 +12,8 @@ export interface FindingTreeProps {
onToggle: (id: string, open: boolean) => void
/** Moves focus to this item (after a deletion); null leaves focus alone. */
focusId: { id: string } | null
/** Called once the request has been applied, so it never replays on a later visit. */
onFocused: () => void
}
/**
@@ -23,14 +25,17 @@ export default function FindingTree(props: FindingTreeProps) {
const t = useT()
const refs = useRef(new Map<string, HTMLElement>())
const focusAfter = useRef<string | null>(null)
const { visible, selectedId, expanded, onSelect, onToggle, focusId } = props
const { visible, selectedId, expanded, onSelect, onToggle } = props
const { focusId, onFocused } = props
useEffect(() => {
if (focusAfter.current) refs.current.get(focusAfter.current)?.focus()
focusAfter.current = null
})
useEffect(() => {
if (focusId) refs.current.get(focusId.id)?.focus()
}, [focusId])
if (!focusId) return
refs.current.get(focusId.id)?.focus()
onFocused()
}, [focusId, onFocused])
const current = visible.find((item) => item.id === selectedId) ?? visible[0]
const onKeyDown = (event: KeyboardEvent, item: FindingItem) => {
const move = keyMove(visible, item, expanded, event.key)
@@ -9,7 +9,8 @@ import TextField from '@/components/editor/fields/TextField'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
import { FOCUS_CLASS, focusAttrs, useRowFocus } from '@/editor/focusRequest'
import type { FocusRequest } from '@/editor/navigation'
import { isBlank, nullable } from '@/editor/sheetDocument'
import { useEditCommand } from '@/editor/useEditCommand'
import type { Locale } from '@/i18n/types'
@@ -22,11 +23,14 @@ const CARD = 'rounded-lg border border-[var(--color-border)] p-3'
export default function CategoriesSection({
doc,
readOnly,
focus,
}: {
doc: AnatomicalSheetDocument
readOnly: boolean
focus?: FocusRequest
}) {
const t = useT()
useRowFocus(focus)
const locale = useLocaleStore((s) => s.locale)
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
return (
@@ -0,0 +1,93 @@
import { useState, type KeyboardEvent } from 'react'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
import ReferenceForm from '@/components/editor/references/ReferenceForm'
import ReferenceRow from '@/components/editor/references/ReferenceRow'
import Icon from '@/components/ui/Icon'
import { useRowFocus } from '@/editor/focusRequest'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
interface Props extends Pick<EditorPlaceProps, 'readOnly' | 'focus'> {
open: boolean
onClose: () => void
}
/**
* The references side panel, minimal until Lot D: the sheet's bibliography, cited by id
* from the findings, opened by the header button. Not a dialog: it keeps the page usable.
* Mounted at the first opening and kept (hidden) afterwards.
*/
export default function ReferencesPanel({
readOnly,
focus,
open,
onClose,
}: Props) {
const t = useT()
useRowFocus(focus)
const doc = useSheetDocument()
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const references = doc?.references ?? []
const onKeyDown = (event: KeyboardEvent) => {
if (event.key !== 'Escape' || event.defaultPrevented) return
event.stopPropagation()
onClose()
}
return (
<section
id="editor-references-panel"
data-place="references"
data-testid="editor-references-panel"
aria-labelledby="editor-references-title"
hidden={!open}
onKeyDown={onKeyDown}
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
>
<div className="flex items-center justify-between gap-2">
<h2
id="editor-references-title"
tabIndex={-1}
data-place-heading
className="outline-none text-xl font-semibold"
>
{t('editor.place.references')}
</h2>
<button
type="button"
aria-label={t('editor.references.close')}
onClick={onClose}
className="inline-flex min-h-11 min-w-11 items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
>
<Icon name="close" size={18} />
</button>
</div>
{doc && references.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.reference.empty')}
</p>
)}
<ul className="space-y-3">
{references.map((reference, index) => (
<ReferenceRow
key={reference.id}
reference={reference}
index={index}
count={references.length}
readOnly={readOnly}
onDelete={() =>
setDeleting({
key: { kind: 'reference', id: reference.id },
label: reference.citation,
})
}
/>
))}
</ul>
{doc && !readOnly && <ReferenceForm />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
)
}
@@ -1,74 +1,112 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
import AnnotationList, {
annotationName,
} from '@/components/editor/annotations/AnnotationList'
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
import OverviewPanel from '@/components/editor/annotations/OverviewPanel'
import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
import AnnotationSection from '@/components/editor/annotations/sections/AnnotationSection'
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
import SelectionTag from '@/components/editor/annotations/SelectionTag'
import { annotationFocus } from '@/editor/annotations/focusTarget'
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
import { useFocusRequest } from '@/editor/focusRequest'
import type { AnnotationSection as SectionId } from '@/editor/navigation'
import { useSheetDocument } from '@/editor/sheetDocument'
import { useEditorStore } from '@/editor/state/editorStore'
import type { EditorTabProps } from '@/editor/tabs'
import type { EditorPlaceProps } from '@/editor/tabs'
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
onOpenSection: (section: SectionId, opener: HTMLElement) => void
onBack: () => void
}
/**
* Annotations: the canvas with its tools, the list of the view, the creation and
* properties panels. Read-only, the same view is browsable (canvas, list, properties as
* text) with no tool and no action.
* Annotations: the drawing workspace (canvas with its tools, the overview or the
* properties and creation panels), 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.
*/
export default function AnnotationsTab(props: EditorTabProps) {
export default function AnnotationsTab(props: AnnotationsTabProps) {
const t = useT()
const doc = useSheetDocument()
const preview = useEditorStore((s) => s.preview)
const { section, readOnly, focus, navigate, onOpenSection, onBack } = props
if (section !== 'drawing') {
if (!doc) return null
return (
<AnnotationSection
section={section}
doc={doc}
readOnly={readOnly}
focus={focus}
onBack={onBack}
/>
)
}
const body = { doc, navigate, onOpenSection, focus }
return (
<section
data-place="annotations.drawing"
data-testid="editor-tab-annotations"
aria-label={t('editor.tab.annotations')}
className="min-h-24 space-y-3"
>
{doc && preview && props.readOnly && (
<ReadOnlyAnnotations
doc={doc}
onSelectTab={props.onSelectTab}
focus={props.focus}
/>
{doc && preview && readOnly && (
<ReadOnlyAnnotations {...body} doc={doc} />
)}
{doc && preview && !props.readOnly && (
<EditableAnnotations
doc={doc}
onSelectTab={props.onSelectTab}
focus={props.focus}
/>
{doc && preview && !readOnly && (
<EditableAnnotations {...body} doc={doc} />
)}
</section>
)
}
/** 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])
}
function ReadOnlyAnnotations({
doc,
onSelectTab,
navigate,
onOpenSection,
focus,
}: {
doc: AnatomicalSheetDocument
onSelectTab: EditorTabProps['onSelectTab']
focus: EditorTabProps['focus']
navigate: EditorPlaceProps['navigate']
onOpenSection: AnnotationsTabProps['onOpenSection']
focus: EditorPlaceProps['focus']
}) {
const locale = useLocaleStore((s) => s.locale)
const preview = useEditorStore((s) => s.preview)
const handleVersion = useEditorStore((s) => s.handleVersion)
const [viewId, setViewId] = useState(mainViewId(doc))
const [selectedId, setSelectedId] = useState<string | null>(null)
useFocusRequest(focus, (key) => {
const target = annotationFocus(doc, key)
if (!target) return
setViewId(target.viewId)
setSelectedId(target.annotationId)
useViewFallback(doc, viewId, setViewId, setSelectedId)
useAnnotationRequest(focus, doc, {
viewId,
selectedId,
busy: null,
show: (view, id) => {
setViewId(view)
setSelectedId(id)
},
})
const model = useViewModel(doc, viewId)
const view = doc.views.find((v) => v.id === viewId)
@@ -106,7 +144,7 @@ function ReadOnlyAnnotations({
onSelect={setSelectedId}
/>
</div>
{selected && (
{selected ? (
<PropertiesPanel
key={selected.id}
annotation={selected}
@@ -115,7 +153,18 @@ function ReadOnlyAnnotations({
geometryLocked={!model.measured}
dispatch={() => undefined}
context={{ t: (key) => key, locale }}
onSelectTab={onSelectTab}
navigate={navigate}
/>
) : (
<OverviewPanel
doc={doc}
viewId={viewId}
readOnly
onSelectView={(id) => {
setViewId(id)
setSelectedId(null)
}}
onOpenSection={onOpenSection}
/>
)}
</div>
@@ -1,4 +1,4 @@
import { useMemo, useState } from 'react'
import { useCallback, useMemo, useState } from 'react'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
@@ -20,7 +20,7 @@ import {
import { useFocusRequest } from '@/editor/focusRequest'
import { useEditorStore } from '@/editor/state/editorStore'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
@@ -34,18 +34,41 @@ function currentItems(): FindingItem[] {
}
}
/** Constats: the tree zones → categories → nodes, edited one command at a time. */
export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
const t = useT()
/** The deletion flow: the target, the item to select after it, and the focus left behind. */
function useFindingDeletion(
items: readonly FindingItem[],
selectedId: string | null,
select: (id: string | null) => void,
focusItem: (id: string | null) => void,
) {
const locale = useLocaleStore((s) => s.locale)
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const [fallback, setFallback] = useState<string | null>(null)
const askDelete = (item: FindingItem) => {
setFallback(fallbackAfterRemoval(items, item))
setDeleting({ key: item.key, label: item.name[locale] })
}
const closeDelete = () => {
setDeleting(null)
const gone = !currentItems().some((item) => item.id === selectedId)
if (gone) {
select(fallback)
focusItem(fallback)
}
}
return { deleting, askDelete, closeDelete }
}
/** Constats: the tree zones → categories → nodes, edited one command at a time. */
export default function FindingsTab({ readOnly, focus }: EditorPlaceProps) {
const t = useT()
const doc = useSheetDocument()
const [selectedId, setSelectedId] = useState<string | null>(null)
const [expanded, setExpanded] = useState<ReadonlySet<string>>(new Set())
const [seeded, setSeeded] = useState(false)
const [pending, setPending] = useState<PendingFinding | null>(null)
const [fallback, setFallback] = useState<string | null>(null)
const [focusId, setFocusId] = useState<{ id: string } | null>(null)
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const clearFocusId = useCallback(() => setFocusId(null), [])
const items = useMemo(() => (doc ? buildItems(doc) : []), [doc])
if (doc && !seeded) {
setSeeded(true)
@@ -65,12 +88,13 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
return next
})
}
useFocusRequest(focus, (key) => {
const found = itemForKey(items, key)
if (!found) return
useFocusRequest(focus, (target) => {
const found = target.key && itemForKey(items, target.key)
if (!found) return 'none'
setExpanded((prev) => new Set([...prev, ...found.ancestors]))
setSelectedId(found.item.id)
setFocusId({ id: found.item.id })
return 'found'
})
const created = (id: string, parent: FindingItem | null) => {
if (!pending) return
@@ -78,18 +102,12 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
setSelectedId(createdItemId(pending.kind, parent, id))
setPending(null)
}
const askDelete = (item: FindingItem) => {
setFallback(fallbackAfterRemoval(items, item))
setDeleting({ key: item.key, label: item.name[locale] })
}
const closeDelete = () => {
setDeleting(null)
const gone = !currentItems().some((item) => item.id === selectedId)
if (gone) {
setSelectedId(fallback)
setFocusId(fallback ? { id: fallback } : null)
}
}
const { deleting, askDelete, closeDelete } = useFindingDeletion(
items,
selectedId,
setSelectedId,
(id) => setFocusId(id ? { id } : null),
)
return (
<section
data-testid="editor-tab-findings"
@@ -122,6 +140,7 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
onSelect={setSelectedId}
onToggle={toggle}
focusId={focusId}
onFocused={clearFocusId}
/>
{selected && (
<FindingDetail
@@ -1,13 +1,12 @@
import AttributionSection from '@/components/editor/general/AttributionSection'
import CategoriesSection from '@/components/editor/general/CategoriesSection'
import TextsSection from '@/components/editor/general/TextsSection'
import { useRowFocus } from '@/editor/focusRequest'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
/** Général: the sheet's texts, attribution and annotation categories. */
export default function GeneralTab({ readOnly, focus }: EditorTabProps) {
/** Général: the sheet's texts and attribution. */
export default function GeneralTab({ readOnly, focus }: EditorPlaceProps) {
const t = useT()
useRowFocus(focus)
const doc = useSheetDocument()
@@ -21,7 +20,6 @@ export default function GeneralTab({ readOnly, focus }: EditorTabProps) {
<>
<TextsSection doc={doc} readOnly={readOnly} />
<AttributionSection doc={doc} readOnly={readOnly} />
<CategoriesSection doc={doc} readOnly={readOnly} />
</>
)}
</section>
@@ -1,51 +0,0 @@
import { useState } from 'react'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
import ReferenceForm from '@/components/editor/references/ReferenceForm'
import ReferenceRow from '@/components/editor/references/ReferenceRow'
import { useRowFocus } from '@/editor/focusRequest'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
/** Références: the sheet's bibliography, cited by id from the findings. */
export default function ReferencesTab({ readOnly, focus }: EditorTabProps) {
const t = useT()
useRowFocus(focus)
const doc = useSheetDocument()
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const references = doc?.references ?? []
return (
<section
data-testid="editor-tab-references"
aria-label={t('editor.tab.references')}
className="min-h-24 space-y-3"
>
{doc && references.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.reference.empty')}
</p>
)}
<ul className="space-y-3">
{references.map((reference, index) => (
<ReferenceRow
key={reference.id}
reference={reference}
index={index}
count={references.length}
readOnly={readOnly}
onDelete={() =>
setDeleting({
key: { kind: 'reference', id: reference.id },
label: reference.citation,
})
}
/>
))}
</ul>
{doc && !readOnly && <ReferenceForm />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
)
}
@@ -13,23 +13,16 @@ import VerificationSummary from '@/components/editor/verification/VerificationSu
import Notice from '@/components/ui/Notice'
import { useEditorStore } from '@/editor/state/editorStore'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import type { EditorPlaceProps } from '@/editor/tabs'
import { splitIssues } from '@/editor/verification'
import { useT } from '@/i18n/useT'
interface PanelProps extends EditorTabProps {
interface PanelProps extends EditorPlaceProps {
report: SheetReport
doc: AnatomicalSheetDocument
}
function Panel({
report,
doc,
readOnly,
onSelectTab,
onGoTo,
reloadSheet,
}: PanelProps) {
function Panel({ report, doc, readOnly, navigate, reloadSheet }: PanelProps) {
const t = useT()
const { errors, warnings } = splitIssues(report)
const { to_confirm } = report.completeness.statuses
@@ -43,25 +36,13 @@ function Panel({
{errors.length + warnings.length === 0 && (
<Notice tone="success">{t('editor.verification.none')}</Notice>
)}
<IssueList
issues={errors}
tone="error"
doc={doc}
onSelectTab={onSelectTab}
onGoTo={onGoTo}
/>
<IssueList issues={errors} tone="error" doc={doc} navigate={navigate} />
{warnings.length > 0 && (
<h3 className="text-sm font-medium">
{t('editor.verification.warnings_title')}
</h3>
)}
<IssueList
issues={warnings}
tone="info"
doc={doc}
onSelectTab={onSelectTab}
onGoTo={onGoTo}
/>
<IssueList issues={warnings} tone="info" doc={doc} navigate={navigate} />
{to_confirm > 0 && (
<Notice tone="info">{t('editor.verification.to_confirm_info')}</Notice>
)}
@@ -76,7 +57,7 @@ function Panel({
}
/** Vérification: the in-page check of the draft (not the server's verdict) and its submission. */
export default function VerificationTab(props: EditorTabProps) {
export default function VerificationTab(props: EditorPlaceProps) {
const t = useT()
const report = useEditorStore((s) => s.previewState?.report)
const doc = useSheetDocument()
@@ -1,12 +1,11 @@
import type {
AnatomicalSheetDocument,
ElementKey,
SheetIssue,
} from '@faunosteo/core-wasm/types'
import Button from '@/components/ui/Button'
import Notice from '@/components/ui/Notice'
import { issueMessageKey, issueTarget } from '@/editor/verification'
import type { EditorTabId } from '@/editor/tabs'
import { issueMessageKey, issueTarget, placeKey } from '@/editor/verification'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
@@ -14,8 +13,7 @@ interface IssueListProps {
issues: readonly SheetIssue[]
tone: 'error' | 'info'
doc: AnatomicalSheetDocument
onSelectTab: (tab: EditorTabId) => void
onGoTo?: (tab: EditorTabId, key: ElementKey) => void
navigate: EditorPlaceProps['navigate']
}
/** One notice per issue: the page's own message, the element's name, « Aller à … ». */
@@ -23,8 +21,7 @@ export default function IssueList({
issues,
tone,
doc,
onSelectTab,
onGoTo,
navigate,
}: IssueListProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
@@ -47,15 +44,13 @@ export default function IssueList({
size="sm"
variant="secondary"
className="mt-2"
onClick={() =>
target.key && onGoTo
? onGoTo(target.tab, target.key)
: onSelectTab(target.tab)
onClick={(event) =>
navigate(target.target, event.currentTarget)
}
>
{t('editor.verification.goto').replace(
'{tab}',
target.name ?? t(`editor.tab.${target.tab}`),
target.name ?? t(placeKey(target.target)),
)}
</Button>
)}