feat(editor): contextual citations panel of a finding (board 25)
The panel opens only from a finding's « {n} références » trigger: 34 rem
at most, never wider than the room, a scrim, slide in 180 ms and out
140 ms (motion/react; none under reduced motion, callbacks still fire).
It lists the finding's references as tiles with « Modifier », « Retirer
de ce constat » (one « Défaire » restores it and the review status) and
« Aller à »; dangling ids read « Référence introuvable »; zero left
reads « Ce constat ne cite plus aucune référence. ». « Tout afficher
dans l'onglet Références » resets search and sort, keeps open tiles and
edits. Every close (✕, Escape outside fields, scrim, tab, « Aller à »,
« Tout afficher », element gone) records one pending move applied
after the exit, page inert until then; focus back to the trigger, else
the active tab button. A refused draft cancels a user close; a forced
close drops it and announces « Saisie non appliquée : {field} ». Places
keeps a permanent dvh min-height; the panel fits the visible viewport
at every scroll position, document size unchanged.
Gates: typecheck, lint, test:run (app 1488), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (admin and editor-equine excluded):
117 passed / 107 skipped / 0 failed, rerun after the fix rounds: 118
passed / 108 skipped / 0 failed; layout spec 13 passed after round 2;
full-row guard: no pre-existing row changed in any table. Known limit:
landscape 667 x 375 at scroll 0 leaves ~13 px of panel (the trigger is
below the fold there).
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-panel.test.tsx (whole file) | R2.1 interim-panel tests, synchronous closes | rewritten: 39 tests (opening, motion, close matrix in both modes, exit, Retirer, P22'', library + history) |
| same, opening | heading `Références` focused right after the click | heading `Références citées` focused after the enter (`waitFor`), `aria-expanded` only after click |
| same | chip `references-filter-chip` « Citées par « Node A » (2) » | REMOVED (REVUE: path line + count line « 2 références citées par ce constat ») |
| same | `listitem` cards « Citée 2 fois » | tiles (`ul > li`) with the same counts, in the finding's order |
| same | field id `#panel-reference-0-ref-a-citation` present at once | tile opened + « Modifier » first (tiles since R2.2) |
| same | « Tout afficher (3) », sync | « Tout afficher dans l'onglet Références », after exit, heading focus asserted |
| same | Escape / ✕ / scrim / tab / vanish: sync null panel | all `await closed()` + `document.activeElement` checks, `describe.each` normal / reduced motion |
| same | « makes the tab panels inert while open, header usable » | split: inert page + inert panel until the exit ends then lifted; « Défaire / Refaire usable »; the `Enregistrer` enabled check dropped (covered by the focus-moved-off test) |
| same | Ctrl+Z test on an always-open field | open tile + Modifier first |
| same | read-only: no Supprimer, no textbox | open tile: no Modifier, no Retirer, no textbox |
| same | P6 under « Plus »: sync | in the close matrix, awaited |
| editor-escape.test.tsx (2 tests) | `expect(citations()).toBeNull()` right after Escape | `await waitFor(...)`; trigger `aria-expanded` false after exit |
| editor-keep-alive.test.tsx | « Escape in a citations panel field commits the text before the panel closes » | REPLACED by « Escape in a field of a panel tile neither closes nor commits » (A5, P27) |
| same | scrim click closes the panel after committing, sync, id on a closed tile | tile opened in edit first, close awaited, commit asserted before the exit |
| editor-focus-request.test.tsx | `ReferenceLibrary` with `resetSignal`; `ownedBy(ref,'citations')` undefined | `ReferencesTab` (+ `reloadSheet`); the `'citations'` assertion removed with the type |
| editor-references-tab / -view.test.tsx | `ReferenceLibrary`, `resetSignal` | `ReferencesTab`, `libraryReset` (+ `reloadSheet`) |
| e2e support `openCitations` | waited for the panel visible | also waits for the heading focus (slide over) |
New unit coverage: editor-citations-exit.test.tsx (hook, fake timers), editor-findings (aria-expanded per finding),
`useDecisionsOpen` gate, panel file (Retirer + status + one undo, P20 chain, zero state, dangling id, P4 reset, P6 after undo,
P22'' four paths, reduced motion, inert/exit, second close, tab replace, focus-moved-off).
## i18n (FR / EN)
Added: `editor.references.panel_title` Références citées / Cited references; `panel_count_one|other` « {count} référence citée par
ce constat » / « {count} références citées par ce constat » and « {count} reference cited by this finding » / « … references … »;
`panel_show_all` Tout afficher dans l'onglet Références / Show all in the References tab; `panel_empty` Ce constat ne cite plus
aucune référence. / This finding no longer cites any reference.; `remove_citation` Retirer de ce constat / Remove from this finding;
`this_finding` ce constat / this finding; `missing` Référence introuvable / Reference not found; `draft_dropped`
Saisie non appliquée : {field} / Entry not applied: {field}.
Changed: none. Removed: `editor.references.cited_by` (« Citées par « {name} » ({count}) » / « Cited by « {name} » ({count}) »),
`editor.references.show_all` (« Tout afficher ({count}) » / « Show all ({count}) »). R10 grep over src, tests and e2e including
editor-equine: no reader left. `editor-equine` has no panel reference: « updated, not run » (nothing to update). The three
provisional FR labels are exactly as listed in the brief; `…` = the refused field's label.
This commit is contained in:
1 parent
3baac4dbb5
commit
8db6f4287f
38 files changed
+2524
-705
No files matched your search
@@ -102,8 +102,8 @@ export function useSelectionEscape(
|
||||
) {
|
||||
const asideRef = useRef<HTMLElement>(null)
|
||||
const deselect = useDeselect(id, clear)
|
||||
const referencesOpen = useContext(ReferencesOpenContext)
|
||||
useEscapeDeselect(active && !referencesOpen, (event) =>
|
||||
const citationsOf = useContext(ReferencesOpenContext)
|
||||
useEscapeDeselect(active && citationsOf === null, (event) =>
|
||||
deselect.byKey(asideRef.current?.contains(event.target as Node) ?? false),
|
||||
)
|
||||
return { asideRef, byDrawing: deselect.byDrawing }
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { createContext, useContext, useState } from 'react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
|
||||
/** The editor cannot be edited now (route rule: mode, recovery, store not in step). */
|
||||
export const ReadOnlyContext = createContext(false)
|
||||
|
||||
/** The citations panel is open: a place beside it is not where a modal may open. */
|
||||
export const ReferencesOpenContext = createContext(false)
|
||||
/**
|
||||
* The finding whose citations panel is open, null when none. Set from the opening to the
|
||||
* end of the exit animation: a place beside the panel is not where a modal may open, and
|
||||
* only that finding's trigger reads « expanded ».
|
||||
*/
|
||||
export const ReferencesOpenContext = createContext<ElementKey | null>(null)
|
||||
|
||||
export function useEditorReadOnly(): boolean {
|
||||
return useContext(ReadOnlyContext)
|
||||
@@ -18,9 +23,9 @@ export function useEditorReadOnly(): boolean {
|
||||
*/
|
||||
export function useDecisionsOpen(): boolean {
|
||||
const readOnly = useContext(ReadOnlyContext)
|
||||
const referencesOpen = useContext(ReferencesOpenContext)
|
||||
const citationsOf = useContext(ReferencesOpenContext)
|
||||
const visible = usePlaceVisible()
|
||||
return !readOnly && visible && !referencesOpen
|
||||
return !readOnly && visible && citationsOf === null
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -262,6 +262,6 @@ export function itemForKey(
|
||||
return { item, ancestors }
|
||||
}
|
||||
|
||||
function sameKey(a: ElementKey, b: ElementKey): boolean {
|
||||
export function sameKey(a: ElementKey, b: ElementKey): boolean {
|
||||
return JSON.stringify(a) === JSON.stringify(b)
|
||||
}
|
||||
@@ -15,14 +15,8 @@ export type { FocusRequest }
|
||||
*/
|
||||
export type FocusOutcome = 'found' | 'kept' | 'none'
|
||||
|
||||
/**
|
||||
* The `data-place` name of a place. `citations` (the panel) is no navigation target: it
|
||||
* is a name only for its heading and its focus scope.
|
||||
*/
|
||||
export type PlaceName =
|
||||
| EditorTabId
|
||||
| `annotations.${AnnotationSection}`
|
||||
| 'citations'
|
||||
/** The `data-place` name of a place a request can name (the citations panel is none). */
|
||||
export type PlaceName = EditorTabId | `annotations.${AnnotationSection}`
|
||||
|
||||
export function placeOf(target: EditorTarget): PlaceName {
|
||||
if (target.tab !== 'annotations') return target.tab
|
||||
|
||||
@@ -32,16 +32,3 @@ export function referenceMatches(reference: Reference, query: string): boolean {
|
||||
(field) => folded(field).includes(term),
|
||||
)
|
||||
}
|
||||
|
||||
/** The references to list: those the finding cites (when filtered) that match the query. */
|
||||
export function visibleReferences(
|
||||
references: readonly Reference[],
|
||||
cited: readonly string[] | null,
|
||||
query: string,
|
||||
): Reference[] {
|
||||
return references.filter(
|
||||
(reference) =>
|
||||
(cited === null || cited.includes(reference.id)) &&
|
||||
referenceMatches(reference, query),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
LocalizedText,
|
||||
Reference,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { buildItems, itemForKey } from '@/editor/findings/tree'
|
||||
|
||||
/**
|
||||
* One citation of the finding, in the order it lists them. A reference the sheet no
|
||||
* longer holds is kept as a row of its own (`reference` null), so the count, the list and
|
||||
* the trigger all describe the same ids (P30). `index` tells two entries of one id apart.
|
||||
*/
|
||||
export interface CitationEntry {
|
||||
id: string
|
||||
index: number
|
||||
reference: Reference | null
|
||||
}
|
||||
|
||||
export function citationEntries(
|
||||
references: readonly Reference[],
|
||||
ids: readonly string[],
|
||||
): CitationEntry[] {
|
||||
return ids.map((id, index) => ({
|
||||
id,
|
||||
index,
|
||||
reference: references.find((candidate) => candidate.id === id) ?? null,
|
||||
}))
|
||||
}
|
||||
|
||||
/** The zone and the families above a finding, then the finding itself, outermost first. */
|
||||
export function findingPath(
|
||||
doc: AnatomicalSheetDocument,
|
||||
key: ElementKey,
|
||||
): LocalizedText[] {
|
||||
const items = buildItems(doc)
|
||||
const found = itemForKey(items, key)
|
||||
if (!found) return []
|
||||
const names = found.ancestors.map(
|
||||
(id) => items.find((item) => item.id === id)?.name,
|
||||
)
|
||||
return [...names.reverse(), found.item.name].filter(
|
||||
(name): name is LocalizedText => name !== undefined,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import type { NavigationAction } from './navigation'
|
||||
|
||||
/** Panel motion (board 25): enter decelerates, the shorter exit accelerates (P9). */
|
||||
export const PANEL_ENTER_S = 0.18
|
||||
export const PANEL_EXIT_S = 0.14
|
||||
|
||||
/** The exit plus a margin: past it, a callback that never came is applied by the timer. */
|
||||
const FALLBACK_MS = PANEL_EXIT_S * 1000 + 100
|
||||
|
||||
export type PendingKind =
|
||||
| 'go_to'
|
||||
| 'citations_closed'
|
||||
| 'show_all'
|
||||
| 'tab_selected'
|
||||
|
||||
/** The one move a close records: applied when the exit is over (P9). */
|
||||
export interface PendingClose {
|
||||
action: NavigationAction
|
||||
kind: PendingKind
|
||||
text: string
|
||||
/** Said before `text`: a draft dropped by a forced close. It survives a replacement. */
|
||||
note?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The close of the citations panel as a two-step move (P9, P28): `record` starts the exit
|
||||
* (the page stays inert, the panel is inert too); `complete` runs once, from the panel's
|
||||
* `onExitComplete` or from a one-shot timer when that never fires, and hands the pending
|
||||
* move to `apply`. A second close is a no-op; a tab choice replaces the pending move.
|
||||
*/
|
||||
export function useCitationsExit(apply: (move: PendingClose) => void) {
|
||||
const [exiting, setExiting] = useState(false)
|
||||
const pending = useRef<PendingClose | null>(null)
|
||||
const timer = useRef<number | undefined>(undefined)
|
||||
const complete = useCallback(() => {
|
||||
const move = pending.current
|
||||
if (move === null) return
|
||||
pending.current = null
|
||||
window.clearTimeout(timer.current)
|
||||
setExiting(false)
|
||||
apply(move)
|
||||
}, [apply])
|
||||
const record = useCallback(
|
||||
(move: PendingClose) => {
|
||||
if (pending.current !== null) {
|
||||
if (move.kind !== 'tab_selected') return
|
||||
const note = pending.current.note ?? move.note
|
||||
pending.current = note ? { ...move, note } : move
|
||||
return
|
||||
}
|
||||
pending.current = move
|
||||
setExiting(true)
|
||||
timer.current = window.setTimeout(complete, FALLBACK_MS)
|
||||
},
|
||||
[complete],
|
||||
)
|
||||
const busy = useCallback(() => pending.current !== null, [])
|
||||
useEffect(() => () => window.clearTimeout(timer.current), [])
|
||||
return { exiting, record, complete, busy }
|
||||
}
|
||||
@@ -27,21 +27,34 @@ import {
|
||||
type NavigationState,
|
||||
} from './navigation'
|
||||
import { MORE_BUTTON_ID, tabDomId, type EditorTabId } from './tabs'
|
||||
import {
|
||||
useCitationsExit,
|
||||
type PendingClose,
|
||||
type PendingKind,
|
||||
} from './useCitationsExit'
|
||||
|
||||
type MoveKind =
|
||||
| 'go_to'
|
||||
| 'section'
|
||||
| 'back'
|
||||
| 'citations'
|
||||
| 'citations_closed'
|
||||
| 'show_all'
|
||||
| 'tab_selected'
|
||||
type MoveKind = PendingKind | 'section' | 'back'
|
||||
|
||||
/** A programmatic move: a new object per move, so the effect after it runs once. */
|
||||
/**
|
||||
* A programmatic move: a new object per move, so the effect after it runs once.
|
||||
* `afterExit`: it is the pending move of a closed panel, so a focus the user already
|
||||
* placed elsewhere during the exit is left alone (P28).
|
||||
*/
|
||||
interface Move {
|
||||
kind: MoveKind
|
||||
afterExit?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* The panel's answer before a close (P22''): `allowed` false cancels a user close. A forced
|
||||
* close always goes ahead; `note` (a draft dropped) is said with the close.
|
||||
*/
|
||||
export interface LeaveAnswer {
|
||||
allowed: boolean
|
||||
note?: string
|
||||
}
|
||||
export type CanLeave = (forced: boolean) => LeaveAnswer
|
||||
|
||||
type Opener = HTMLElement | null | undefined
|
||||
|
||||
export interface EditorNavigation {
|
||||
@@ -54,10 +67,18 @@ export interface EditorNavigation {
|
||||
backToDrawing: () => void
|
||||
/** Opens the citations panel of a finding node; any other key is ignored. */
|
||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||
/** Every close (✕, Escape, scrim, element gone): the focus goes to P6's fallbacks. */
|
||||
/** A user close (✕, Escape, scrim): the panel exits, then the focus goes to P6's fallbacks. */
|
||||
closeCitations: () => void
|
||||
/** The finding vanished: the same close, never refused (a refused draft is dropped, said aloud). */
|
||||
dropCitations: () => void
|
||||
/** « Tout afficher dans l'onglet Références »: panel closed, tab shown, library reset. */
|
||||
showAllReferences: () => void
|
||||
/** The panel is playing its exit: the state still holds it, the page stays inert. */
|
||||
exiting: boolean
|
||||
/** The panel's `onExitComplete`: applies the pending move. */
|
||||
exitComplete: () => void
|
||||
/** The panel hands its `canLeave` over while it is mounted (P22''). */
|
||||
registerCanLeave: (guard: CanLeave | null) => void
|
||||
consumed: (serial: number, outcome: FocusOutcome) => void
|
||||
announce: (text: string) => void
|
||||
}
|
||||
@@ -113,10 +134,21 @@ interface Openers {
|
||||
|
||||
type Go = (action: NavigationAction, kind: MoveKind, text: string) => void
|
||||
|
||||
/** The one way to move: commit the typed text, announce, dispatch, record the move. */
|
||||
/**
|
||||
* The one way to move: commit the typed text, announce, dispatch, record the move.
|
||||
* `finish` is the same without the commit, for the move a closed panel recorded.
|
||||
*/
|
||||
function useGo(dispatch: Dispatch<NavigationAction>) {
|
||||
const { live, announce } = useLiveRegion()
|
||||
const [move, setMove] = useState<Move | null>(null)
|
||||
const finish = useCallback(
|
||||
(move: PendingClose) => {
|
||||
announce(move.note ? `${move.note}. ${move.text}` : move.text)
|
||||
dispatch(move.action)
|
||||
setMove({ kind: move.kind, afterExit: true })
|
||||
},
|
||||
[announce, dispatch],
|
||||
)
|
||||
const go: Go = useCallback(
|
||||
(action, kind, text) => {
|
||||
commitFocusedField()
|
||||
@@ -126,7 +158,7 @@ function useGo(dispatch: Dispatch<NavigationAction>) {
|
||||
},
|
||||
[announce, dispatch],
|
||||
)
|
||||
return { move, go, live, announce }
|
||||
return { move, go, finish, live, announce }
|
||||
}
|
||||
|
||||
/** Tab and section moves: « Aller à », a section entry, « Retour au dessin ». */
|
||||
@@ -154,33 +186,92 @@ function useSectionMoves(go: Go, openers: Openers) {
|
||||
return { navigate, openSection, backToDrawing }
|
||||
}
|
||||
|
||||
/** The citations panel moves: open from a finding, close, « Tout afficher ». */
|
||||
function useCitationsMoves(go: Go, openers: Openers) {
|
||||
/** What the panel's moves need of the hook: its state, the exit and the leave check. */
|
||||
interface PanelContext {
|
||||
open: boolean
|
||||
go: Go
|
||||
openers: Openers
|
||||
dispatch: Dispatch<NavigationAction>
|
||||
announce: (text: string) => void
|
||||
exit: ReturnType<typeof useCitationsExit>
|
||||
canLeave: RefObject<CanLeave | null>
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a close of the panel. A user close asks the panel first (P22''): a refused
|
||||
* draft cancels it. While an exit is playing, a close is a no-op (a tab choice replaces
|
||||
* the pending move) and asks nothing: the draft was settled by the first close.
|
||||
*/
|
||||
function useRequestClose(ctx: PanelContext) {
|
||||
const { open, exit, canLeave } = ctx
|
||||
const { busy, record } = exit
|
||||
return useCallback(
|
||||
(move: PendingClose, forced: boolean) => {
|
||||
if (!open) return
|
||||
if (busy()) return record(move)
|
||||
commitFocusedField()
|
||||
const { allowed, note } = canLeave.current?.(forced) ?? { allowed: true }
|
||||
if (!allowed) return
|
||||
record(note ? { ...move, note } : move)
|
||||
},
|
||||
[open, busy, record, canLeave],
|
||||
)
|
||||
}
|
||||
|
||||
/** Opens the panel of a finding node: no move is recorded, the panel focuses itself. */
|
||||
function useOpenCitations(ctx: PanelContext) {
|
||||
const t = useT()
|
||||
const openCitations = useCallback(
|
||||
const { openers, dispatch, announce } = ctx
|
||||
return useCallback(
|
||||
(citedBy: ElementKey, opener?: Opener) => {
|
||||
if (!isFindingNode(citedBy)) return
|
||||
commitFocusedField()
|
||||
openers.citations.current = opener ?? null
|
||||
openers.citedBy.current = citedBy
|
||||
const action = { type: 'open_citations', citedBy } as const
|
||||
go(action, 'citations', t('editor.place.references'))
|
||||
announce(t('editor.place.references'))
|
||||
dispatch({ type: 'open_citations', citedBy })
|
||||
},
|
||||
[go, openers, t],
|
||||
[openers, dispatch, announce, t],
|
||||
)
|
||||
const closeCitations = useCallback(() => {
|
||||
const text = t('editor.live.references_closed')
|
||||
go({ type: 'close_citations' }, 'citations_closed', text)
|
||||
}, [go, t])
|
||||
const showAllReferences = useCallback(
|
||||
() =>
|
||||
go(
|
||||
{ type: 'show_all_references' },
|
||||
'show_all',
|
||||
t('editor.tab.references'),
|
||||
),
|
||||
[go, t],
|
||||
}
|
||||
|
||||
/** The closes of the panel: ✕ / Escape / scrim, the vanished finding, « Tout afficher », « Aller à ». */
|
||||
function useCloseMoves(ctx: PanelContext) {
|
||||
const t = useT()
|
||||
const moveText = useMoveText()
|
||||
const { open, go } = ctx
|
||||
const request = useRequestClose(ctx)
|
||||
const closing = useCallback(
|
||||
(forced: boolean) => {
|
||||
const text = t('editor.live.references_closed')
|
||||
request(
|
||||
{ action: { type: 'close_citations' }, kind: 'citations_closed', text },
|
||||
forced,
|
||||
)
|
||||
},
|
||||
[request, t],
|
||||
)
|
||||
return { openCitations, closeCitations, showAllReferences }
|
||||
// With no panel open there is nothing to exit: the tab shows at once.
|
||||
const showAllReferences = useCallback(() => {
|
||||
const action = { type: 'show_all_references' } as const
|
||||
const text = t('editor.tab.references')
|
||||
if (!open) return go(action, 'show_all', text)
|
||||
request({ action, kind: 'show_all', text }, false)
|
||||
}, [open, go, request, t])
|
||||
const navigate = useCallback(
|
||||
(target: EditorTarget) => {
|
||||
const action = { type: 'go_to', target } as const
|
||||
request({ action, kind: 'go_to', text: moveText(target) }, false)
|
||||
},
|
||||
[request, moveText],
|
||||
)
|
||||
return {
|
||||
closeCitations: useCallback(() => closing(false), [closing]),
|
||||
dropCitations: useCallback(() => closing(true), [closing]),
|
||||
showAllReferences,
|
||||
navigate,
|
||||
request,
|
||||
}
|
||||
}
|
||||
|
||||
/** « Retour au dessin »: the entry that opened the section, else the canvas box. */
|
||||
@@ -212,9 +303,18 @@ function focusAfterClose(openers: Openers) {
|
||||
if (!focusHeld(triggerOf(openers))) focusActiveTab()
|
||||
}
|
||||
|
||||
/** Nothing the user chose holds the focus: `body`, or what the closing panel still has. */
|
||||
function focusIsFree(): boolean {
|
||||
const active = document.activeElement
|
||||
return (
|
||||
active === null ||
|
||||
active === document.body ||
|
||||
active.closest('[data-place="citations"]') !== null
|
||||
)
|
||||
}
|
||||
|
||||
/** Where the focus lands after a programmatic move; never `body`. */
|
||||
function landingOf(move: Move, state: NavigationState): HTMLElement | null {
|
||||
if (move.kind === 'citations') return headingOf('citations')
|
||||
if (move.kind === 'show_all') {
|
||||
return headingOf('references') ?? tabButton(state.tab)
|
||||
}
|
||||
@@ -238,10 +338,6 @@ function useMoveFocus(
|
||||
useEffect(() => {
|
||||
if (!move || handled.current === move) return
|
||||
handled.current = move
|
||||
if (move.kind === 'citations_closed') {
|
||||
focusAfterClose(openers)
|
||||
return
|
||||
}
|
||||
const serial = state.focus?.serial
|
||||
if (move.kind === 'go_to' && serial !== undefined) {
|
||||
const outcome = outcomes.current.get(serial)
|
||||
@@ -249,7 +345,9 @@ function useMoveFocus(
|
||||
if (outcome === 'found' || outcome === 'kept') return
|
||||
dispatch({ type: 'focus_consumed', serial })
|
||||
}
|
||||
if (move.kind === 'back') backTarget(openers.section.current)?.focus()
|
||||
if (move.afterExit && !focusIsFree()) return
|
||||
if (move.kind === 'citations_closed') focusAfterClose(openers)
|
||||
else if (move.kind === 'back') backTarget(openers.section.current)?.focus()
|
||||
else landingOf(move, state)?.focus()
|
||||
}, [move, state, outcomes, dispatch, openers])
|
||||
}
|
||||
@@ -269,7 +367,7 @@ function useReceipts(dispatch: Dispatch<NavigationAction>) {
|
||||
|
||||
/** A tab choice; with the citations panel open it closes and the new tab takes the focus. */
|
||||
function useTabSelect(
|
||||
go: Go,
|
||||
request: ReturnType<typeof useCloseMoves>['request'],
|
||||
dispatch: Dispatch<NavigationAction>,
|
||||
open: boolean,
|
||||
) {
|
||||
@@ -277,11 +375,14 @@ function useTabSelect(
|
||||
return useCallback(
|
||||
(tab: EditorTabId) => {
|
||||
const action = { type: 'select_tab', tab } as const
|
||||
if (open) return go(action, 'tab_selected', t(`editor.tab.${tab}`))
|
||||
if (open) {
|
||||
const text = t(`editor.tab.${tab}`)
|
||||
return request({ action, kind: 'tab_selected', text }, false)
|
||||
}
|
||||
commitFocusedField()
|
||||
dispatch(action)
|
||||
},
|
||||
[go, dispatch, open, t],
|
||||
[request, dispatch, open, t],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -292,21 +393,39 @@ export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
|
||||
initialTab,
|
||||
initialNavigation,
|
||||
)
|
||||
const { move, go, live, announce } = useGo(dispatch)
|
||||
const { move, go, finish, live, announce } = useGo(dispatch)
|
||||
const openers = useRef<Openers>({
|
||||
citations: { current: null },
|
||||
citedBy: { current: null },
|
||||
section: { current: null },
|
||||
}).current
|
||||
const canLeave = useRef<CanLeave | null>(null)
|
||||
const exit = useCitationsExit(finish)
|
||||
const registerCanLeave = useCallback((guard: CanLeave | null) => {
|
||||
canLeave.current = guard
|
||||
}, [])
|
||||
const open = state.citationsOf !== null
|
||||
const receipts = useReceipts(dispatch)
|
||||
useMoveFocus(move, state, receipts.outcomes, dispatch, openers)
|
||||
const sections = useSectionMoves(go, openers)
|
||||
const ctx = { open, go, openers, dispatch, announce, exit, canLeave }
|
||||
const openCitations = useOpenCitations(ctx)
|
||||
const panel = useCloseMoves(ctx)
|
||||
return {
|
||||
state,
|
||||
live,
|
||||
announce,
|
||||
consumed: receipts.consumed,
|
||||
selectTab: useTabSelect(go, dispatch, state.citationsOf !== null),
|
||||
...useSectionMoves(go, openers),
|
||||
...useCitationsMoves(go, openers),
|
||||
selectTab: useTabSelect(panel.request, dispatch, open),
|
||||
openSection: sections.openSection,
|
||||
backToDrawing: sections.backToDrawing,
|
||||
navigate: open ? panel.navigate : sections.navigate,
|
||||
openCitations,
|
||||
closeCitations: panel.closeCitations,
|
||||
dropCitations: panel.dropCitations,
|
||||
showAllReferences: panel.showAllReferences,
|
||||
exiting: exit.exiting,
|
||||
exitComplete: exit.complete,
|
||||
registerCanLeave,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user