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:
1 parent
95b1b7e461
commit
bc2dba7c14
56 files changed
+2419
-699
No files matched your search
@@ -1,10 +1,38 @@
|
||||
import { createContext, useContext, useEffect, useRef } from 'react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import type {
|
||||
AnnotationSection,
|
||||
EditorTarget,
|
||||
FocusRequest,
|
||||
} from './navigation'
|
||||
import type { EditorTabId } from './tabs'
|
||||
|
||||
/** « Aller à … »: the element to show and a serial so each request is consumed once. */
|
||||
export interface FocusRequest {
|
||||
key: ElementKey
|
||||
serial: number
|
||||
export type { FocusRequest }
|
||||
|
||||
/**
|
||||
* What a place did with a request: `found` the element and focused it, `kept` a creation
|
||||
* or tracing in progress instead of jumping, `none` when it holds no such element.
|
||||
*/
|
||||
export type FocusOutcome = 'found' | 'kept' | 'none'
|
||||
|
||||
/** The `data-place` name of the place a target shows. */
|
||||
export type PlaceName =
|
||||
| EditorTabId
|
||||
| `annotations.${AnnotationSection}`
|
||||
| 'references'
|
||||
|
||||
export function placeOf(target: EditorTarget): PlaceName {
|
||||
if (target.place === 'references') return 'references'
|
||||
if (target.tab !== 'annotations') return target.tab
|
||||
return `annotations.${target.section ?? 'drawing'}`
|
||||
}
|
||||
|
||||
/** The request, only when `place` is the one its target names (a hidden place never answers). */
|
||||
export function ownedBy(
|
||||
focus: FocusRequest | undefined,
|
||||
place: PlaceName,
|
||||
): FocusRequest | undefined {
|
||||
return focus && placeOf(focus.target) === place ? focus : undefined
|
||||
}
|
||||
|
||||
/** The attributes that make a row of a list reachable by a focus request. */
|
||||
@@ -19,37 +47,73 @@ export function focusAttrs(key: ElementKey) {
|
||||
export const FOCUS_CLASS =
|
||||
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
|
||||
|
||||
/** The route's answer to a consumed request: it clears it, so a remounted tab never replays. */
|
||||
export const FocusConsumedContext = createContext<(serial: number) => void>(
|
||||
/** The workspace's answer to a handled request: it clears it, so a remount never replays. */
|
||||
export const FocusConsumedContext = createContext<
|
||||
(serial: number, outcome: FocusOutcome) => void
|
||||
>(() => undefined)
|
||||
|
||||
/** Says something to the polite live region of the workspace. */
|
||||
export const AnnounceContext = createContext<(text: string) => void>(
|
||||
() => undefined,
|
||||
)
|
||||
|
||||
/** Runs `apply` once per request, after the tab has rendered, then reports it consumed. */
|
||||
/**
|
||||
* Runs `apply` once per request, after the place has rendered, then reports the outcome.
|
||||
* The workspace passes a request only to the place its target names.
|
||||
*/
|
||||
export function useFocusRequest(
|
||||
focus: FocusRequest | undefined,
|
||||
apply: (key: ElementKey) => void,
|
||||
apply: (target: EditorTarget) => FocusOutcome,
|
||||
): void {
|
||||
const handled = useRef<number | null>(null)
|
||||
const consumed = useContext(FocusConsumedContext)
|
||||
useEffect(() => {
|
||||
if (!focus || handled.current === focus.serial) return
|
||||
handled.current = focus.serial
|
||||
apply(focus.key)
|
||||
consumed(focus.serial)
|
||||
consumed(focus.serial, apply(focus.target))
|
||||
}, [focus, apply, consumed])
|
||||
}
|
||||
|
||||
/** Scrolls to and focuses the row tagged with `key`. */
|
||||
export function focusRow(key: ElementKey): void {
|
||||
/** The first element matching `selector` that no hidden place contains. */
|
||||
export function visibleElement(selector: string): HTMLElement | null {
|
||||
const found = [...document.querySelectorAll<HTMLElement>(selector)]
|
||||
return found.find((element) => !element.closest('[hidden]')) ?? null
|
||||
}
|
||||
|
||||
/** Scrolls to and focuses the visible row tagged with `key`; false when there is none. */
|
||||
export function focusRow(key: ElementKey): boolean {
|
||||
const wanted = JSON.stringify(key)
|
||||
const row = [
|
||||
...document.querySelectorAll<HTMLElement>('[data-focus-key]'),
|
||||
].find((candidate) => candidate.dataset.focusKey === wanted)
|
||||
row?.scrollIntoView?.({ block: 'center' })
|
||||
row?.focus()
|
||||
].find(
|
||||
(candidate) =>
|
||||
candidate.dataset.focusKey === wanted && !candidate.closest('[hidden]'),
|
||||
)
|
||||
if (!row) return false
|
||||
row.scrollIntoView?.({ block: 'center' })
|
||||
row.focus()
|
||||
return true
|
||||
}
|
||||
|
||||
/** Row-based tabs (Général, Vues, Références, Vertèbres): focus the named row. */
|
||||
/** Row-based places (Général, Vues, Catégories, Régions, Références): focus the named row. */
|
||||
export function useRowFocus(focus: FocusRequest | undefined): void {
|
||||
useFocusRequest(focus, focusRow)
|
||||
useFocusRequest(focus, (target) =>
|
||||
target.key && focusRow(target.key) ? 'found' : 'none',
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits the text being typed before a place is left: blurs the focused field, so its
|
||||
* `TextField` commits on blur. Safari and iPadOS do not move the focus to a tapped button,
|
||||
* so the blur is forced rather than assumed.
|
||||
*/
|
||||
export function commitFocusedField(): void {
|
||||
const active = document.activeElement
|
||||
if (
|
||||
active instanceof HTMLInputElement ||
|
||||
active instanceof HTMLTextAreaElement ||
|
||||
active instanceof HTMLSelectElement
|
||||
) {
|
||||
active.blur()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user