feat(editor): references side panel with filter, search and counts

Non-modal panel in a relative container after the tab row (scrim over the
tab panels, which are inert while it is open). Chip "Citées par" opened
from a finding's Citations block, "Tout afficher (N)", accent- and
case-insensitive search on citation, DOI and URL, "citée n fois" per card
(citationCounts, memoised TS read; the core stays the authority for
refused deletions). Up/down only without filter or search. "Aller à" a
reference clears a hiding search then focuses the card.

Rewritten assertions (R-24): editor-shell "the references panel keeps its
form text and no id repeats" closes the panel before reaching the inert
tab panels. Added: Chromium clickability at 1 024 and 1 280 px (top and
scrolled), editor-structures count and search, unit
editor-references-panel, editor-citations, navigation clear_cited_by.
This commit is contained in:
bchanot committed 2026-11-08 17:33:26 +01:00
1 parent cf9c300c80
commit ab51ea764d
19 files changed
+891 -85

No files matched your search

+3
View File
@@ -44,6 +44,7 @@ export type NavigationAction =
| { type: 'back_to_drawing' }
| { type: 'open_references'; citedBy: ElementKey | null }
| { type: 'close_references' }
| { type: 'clear_cited_by' }
| { type: 'go_to'; target: EditorTarget }
| { type: 'focus_consumed'; serial: number }
@@ -146,6 +147,8 @@ export function navigationReducer(
return openReferences(state, action.citedBy)
case 'close_references':
return { ...state, references: { open: false, citedBy: null } }
case 'clear_cited_by':
return { ...state, references: { ...state.references, citedBy: null } }
case 'go_to':
return goTo(state, action.target)
case 'focus_consumed':
@@ -0,0 +1,25 @@
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import { buildItems } from '@/editor/findings/tree'
const memo = new WeakMap<AnatomicalSheetDocument, ReadonlyMap<string, number>>()
/**
* How many findings (categories and nodes, at any depth) cite each reference. A display
* count read from the document, no rule: the core's `sheet.dependents` stays the authority
* for a refused deletion. Memoised on the parsed document.
*/
export function citationCounts(
doc: AnatomicalSheetDocument,
): ReadonlyMap<string, number> {
const known = memo.get(doc)
if (known) return known
const counts = new Map<string, number>()
for (const { element } of buildItems(doc)) {
if (element.kind === 'zone') continue
for (const id of element.value.reference_ids) {
counts.set(id, (counts.get(id) ?? 0) + 1)
}
}
memo.set(doc, counts)
return counts
}
+47
View File
@@ -0,0 +1,47 @@
import type {
AnatomicalSheetDocument,
ElementKey,
Reference,
} from '@faunosteo/core-wasm/types'
import { folded } from '@/catalogue/useCatalogue'
import {
buildItems,
itemForKey,
type FindingItem,
} from '@/editor/findings/tree'
/** The finding a filter names, read from the current document; null once it is gone. */
export function citingFinding(
doc: AnatomicalSheetDocument,
key: ElementKey | null,
): FindingItem | null {
if (key === null) return null
return itemForKey(buildItems(doc), key)?.item ?? null
}
/** The ids a finding cites; a zone cites none. */
export function citedIds(item: FindingItem): readonly string[] {
return item.element.kind === 'zone' ? [] : item.element.value.reference_ids
}
/** Case- and accent-insensitive match on the citation, the DOI and the URL. */
export function referenceMatches(reference: Reference, query: string): boolean {
const term = folded(query.trim())
if (term === '') return true
return [reference.citation, reference.doi ?? '', reference.url ?? ''].some(
(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),
)
}
+13 -3
View File
@@ -55,6 +55,8 @@ export interface EditorNavigation {
backToDrawing: () => void
openReferences: (citedBy: ElementKey | null, opener?: Opener) => void
closeReferences: () => void
/** « Tout afficher »: drops the finding filter; no move, no announcement. */
showAllReferences: () => void
consumed: (serial: number, outcome: FocusOutcome) => void
announce: (text: string) => void
}
@@ -155,7 +157,11 @@ function useSectionMoves(go: Go, openers: Openers) {
}
/** The references panel moves: open (optionally filtered) and close. */
function useReferenceMoves(go: Go, openers: Openers) {
function useReferenceMoves(
go: Go,
openers: Openers,
dispatch: Dispatch<NavigationAction>,
) {
const t = useT()
const openReferences = useCallback(
(citedBy: ElementKey | null, opener?: Opener) => {
@@ -169,7 +175,11 @@ function useReferenceMoves(go: Go, openers: Openers) {
const text = t('editor.live.references_closed')
go({ type: 'close_references' }, 'references_closed', text)
}, [go, t])
return { openReferences, closeReferences }
const showAllReferences = useCallback(
() => dispatch({ type: 'clear_cited_by' }),
[dispatch],
)
return { openReferences, closeReferences, showAllReferences }
}
/** « Retour au dessin »: the entry that opened the section, else the canvas box. */
@@ -265,6 +275,6 @@ export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
consumed: receipts.consumed,
selectTab: receipts.selectTab,
...useSectionMoves(go, openers),
...useReferenceMoves(go, openers),
...useReferenceMoves(go, openers, dispatch),
}
}